prolog

minimum in list of lists in prolog

断了今生、忘了曾经 提交于 2021-01-03 22:28:37
问题 hello i have a list like this: [[3,[a,b,c,d]],[2,[a,b,d]],[5,[d,e,f]]] list of lists... i want to find the minimum number on inner list in this case i want to return D=2 and L=[a,b,d] i tried this code: minway([[N|L]],N,L). minway([[M|L1]|L2],D,_):- M<D, minway(L2,M,L1). minway([[M|_]|L2],D,L):- M>=D, minway(L2,D,L). but i got error: </2: Arguments are not sufficiently instantiated Exception: (8) minway([[3,[a,b,c,d]],[2,[a,b,d]],[5,[d,e,f]]], _G7777, _G7778) ? creep for this run sentence:

minimum in list of lists in prolog

亡梦爱人 提交于 2021-01-03 22:27:14
问题 hello i have a list like this: [[3,[a,b,c,d]],[2,[a,b,d]],[5,[d,e,f]]] list of lists... i want to find the minimum number on inner list in this case i want to return D=2 and L=[a,b,d] i tried this code: minway([[N|L]],N,L). minway([[M|L1]|L2],D,_):- M<D, minway(L2,M,L1). minway([[M|_]|L2],D,L):- M>=D, minway(L2,D,L). but i got error: </2: Arguments are not sufficiently instantiated Exception: (8) minway([[3,[a,b,c,d]],[2,[a,b,d]],[5,[d,e,f]]], _G7777, _G7778) ? creep for this run sentence:

Pure Prolog Scheme Quine

依然范特西╮ 提交于 2021-01-03 06:42:45
问题 There is this paper: William E. Byrd, Eric Holk, Daniel P. Friedman, 2012 miniKanren, Live and Untagged Quine Generation via Relational Interpreters http://webyrd.net/quines/quines.pdf Which uses logic programming to find a Scheme Quine. The Scheme subset that is consider here does not only contain lambda abstraction and application, but also a little list processing by the following reduction, already translated to Prolog: [quote,X] ~~> X [] ~~> [] [cons,X,Y] ~~> [A|B], for X ~~> A and Y ~~>

Pure Prolog Scheme Quine

柔情痞子 提交于 2021-01-03 06:40:14
问题 There is this paper: William E. Byrd, Eric Holk, Daniel P. Friedman, 2012 miniKanren, Live and Untagged Quine Generation via Relational Interpreters http://webyrd.net/quines/quines.pdf Which uses logic programming to find a Scheme Quine. The Scheme subset that is consider here does not only contain lambda abstraction and application, but also a little list processing by the following reduction, already translated to Prolog: [quote,X] ~~> X [] ~~> [] [cons,X,Y] ~~> [A|B], for X ~~> A and Y ~~>

NU-Prolog's and Gödel's logical and sound `if-then-else` extension

女生的网名这么多〃 提交于 2021-01-03 06:28:16
问题 A paper about mercury says the following: The if-then-else and negation constructs in most variants of Prolog are non-logical and unsound: they can cause the system to compute answers which are inconsistent with the program viewed as a logical theory. Some existing logic programming systems such as NU-Prolog and Gödel provide logical and sound replacements for these Prolog constructs . Unfortunately, these systems enforce safety via runtime groundness checks. This effect can increase the

NU-Prolog's and Gödel's logical and sound `if-then-else` extension

╄→尐↘猪︶ㄣ 提交于 2021-01-03 06:28:06
问题 A paper about mercury says the following: The if-then-else and negation constructs in most variants of Prolog are non-logical and unsound: they can cause the system to compute answers which are inconsistent with the program viewed as a logical theory. Some existing logic programming systems such as NU-Prolog and Gödel provide logical and sound replacements for these Prolog constructs . Unfortunately, these systems enforce safety via runtime groundness checks. This effect can increase the

Prolog - Chain rule for Step Siblings

Deadly 提交于 2021-01-01 10:11:58
问题 I am a newbie to Prolog, and have a question regarding programming a "chain rule" for step-siblings that share a "common parent". In my program, I am assuming that the existence of the parent(X,Y) fact that asserts that X is a parent of Y. I need a rule chain(X,Y,L): if X is an ancestor of Y, then L is the list containing X, Y and all ancestors of Y who are also descendants of X, listed in descending order of age ( oldest first ). In other words, my list should contain all the people that

Defining “let expressions” in Prolog

强颜欢笑 提交于 2020-12-30 17:43:13
问题 In many functional programming languages, it is possible to "redefine" local variables using a let expression: let example = let a = 1 in let a = a+1 in a + 1 I couldn't find a built-in Prolog predicate for this purpose, so I tried to define a let expression in this way: :- initialization(main). :- set_prolog_flag(double_quotes, chars). replace(Subterm0, Subterm, Term0, Term) :- ( Term0 == Subterm0 -> Term = Subterm ; var(Term0) -> Term = Term0 ; Term0 =.. [F|Args0], maplist(replace(Subterm0

Defining “let expressions” in Prolog

醉酒当歌 提交于 2020-12-30 17:27:51
问题 In many functional programming languages, it is possible to "redefine" local variables using a let expression: let example = let a = 1 in let a = a+1 in a + 1 I couldn't find a built-in Prolog predicate for this purpose, so I tried to define a let expression in this way: :- initialization(main). :- set_prolog_flag(double_quotes, chars). replace(Subterm0, Subterm, Term0, Term) :- ( Term0 == Subterm0 -> Term = Subterm ; var(Term0) -> Term = Term0 ; Term0 =.. [F|Args0], maplist(replace(Subterm0

Defining “let expressions” in Prolog

本小妞迷上赌 提交于 2020-12-30 17:25:05
问题 In many functional programming languages, it is possible to "redefine" local variables using a let expression: let example = let a = 1 in let a = a+1 in a + 1 I couldn't find a built-in Prolog predicate for this purpose, so I tried to define a let expression in this way: :- initialization(main). :- set_prolog_flag(double_quotes, chars). replace(Subterm0, Subterm, Term0, Term) :- ( Term0 == Subterm0 -> Term = Subterm ; var(Term0) -> Term = Term0 ; Term0 =.. [F|Args0], maplist(replace(Subterm0