prolog

Uses cases of closure expansion, how about library(reif)?

时光毁灭记忆、已成空白 提交于 2021-01-29 12:42:06
问题 It seems that SWI-Prolog offers closure expansion. Most likely Jekejeke Prolog 1.4.7 will provide closure expansion as well. We can for example define: goal_expansion(println(X), (write(X), nl)). test :- call(println,'Hello World!'). And it will expand println/0 in the first argument of call/2, which has meta specifier closure index 1. Could we use this to make extensible expansion for library(reif)? This code here rather looks that it cannot work with arbitrary conditions, the predicate

Prolog - Recursive append to list returning false

牧云@^-^@ 提交于 2021-01-29 06:16:43
问题 Title says it all, but here we are again. Trying to append recursively to a list in Prolog, and while I have previously gotten it to work by having "temporary buffers" (via nb_setval/nb_getval) I'd like to learn how to, in a slightly more appropriate way, recursively append to lists. I've understood Prolog works all around bindings and once something is bound it's difficult to manipulate it, so initially I sat with this, but I've understood why that does not quite work: recursiveAppend([], _)

Different query results in prolog

帅比萌擦擦* 提交于 2021-01-29 04:30:31
问题 I have a question in prolog. Here is the Knowledge Base. loves(vincent,mia). loves(marcellus,mia). loves(pumpkin,honey_bunny). loves(honey_bunny,pumpkin). jealous(X,Y) :- loves(X,Z), loves(Y,Z). This is from "Learn Prolog Now" book. Now if I make a query ?- jealous(marcellus,W). it returns that W = vincent but if I give the query ?- jealous(vincent,W). the return result is W=vincent So this means that vincent is jealous of himself but marcellus is not jealous of himself. Why is the answer

Different query results in prolog

隐身守侯 提交于 2021-01-29 04:22:06
问题 I have a question in prolog. Here is the Knowledge Base. loves(vincent,mia). loves(marcellus,mia). loves(pumpkin,honey_bunny). loves(honey_bunny,pumpkin). jealous(X,Y) :- loves(X,Z), loves(Y,Z). This is from "Learn Prolog Now" book. Now if I make a query ?- jealous(marcellus,W). it returns that W = vincent but if I give the query ?- jealous(vincent,W). the return result is W=vincent So this means that vincent is jealous of himself but marcellus is not jealous of himself. Why is the answer

Prolog understanding setof/3 with ^ markings [duplicate]

微笑、不失礼 提交于 2021-01-29 02:37:09
问题 This question already has answers here : What is the Prolog operator `^` (“caret”)? (4 answers) Closed 10 months ago . Could someone explain to me what this is doing? (\+ setof((P1,C),P^R^Bag,PS) -> ... otherwise ->... I have read the documentation of setof; my understanding is that the thrid argument gets unified with the facts. However, I can't make sense of the code snippet above. The full snippet is: solve_task_bt(go(Target),Agenda,ClosedSet,F,G,NewPos,RR,BackPath) :- Agenda = [Current

swi-prolog print multiple variables

自作多情 提交于 2021-01-28 22:20:50
问题 I want to print multiple variables in swi-prolog, currently I am writing in this way: writeln('child link : '), writeln(LINK_CHILD), writeln('rule - four'), writeln(REND_PARENTI), writeln(REND_CHILDI) so every variable gets printed on new line, I could not figure out way to print them in single line. I appreciate any help 回答1: You can either use write instead of writeln , or even better, use format: ?- format("~a~n~a:~a~n", [x, y, z]). x y:z true. Or, for your case, something like: format(

How to stop the recursion in prolog, once the desired value is returned?

若如初见. 提交于 2021-01-28 19:51:02
问题 The .pl file that I am consulting looks like this spouse(eddard_stark,catelyn_stark). spouse(X,Y):-spouse(Y,X). What I fundamentally wanted program here was that if 'Eddard is spouse of Catelyn' then 'Catelyn is spouse of Eddard'. But when I query spouse(eddard_stark, X). this goes into an endless recursive return of catelyn_stark . I am not sure how to stop recursion in Prolog once desired output is reached. Also if you think of any alternate solution for this problem please mention it, I

How can I get my maze program to create and print two route-lists to the console?

戏子无情 提交于 2021-01-28 11:27:19
问题 link(entry, a). link(a, b). link(b, c). link(c, d). link(d, e). link(b, e). link(e, f). link(f, c). link(f, exit). route(1, 2) :- member(1, [entry,a,b,c,d,e,f,exit]), member(2, [entry,a,b,e,f,exit]). route(X, Z, [entry,a,b,c,d,e,f,exit]) :- route(X, Z,[R],[entry,a,b,c,d,e,f,exit]). route(X, Z, [exit,f,e,d,c,b,a,entry], [entry,a,b,c,d,e,f,exit]) :- reverse(X, Y, [exit,f,e,d,c,b,a,entry], [entry,a,b,c,d,e,f,exit]), route(Y, Z), write(X). Despite hours of reading, I am struggling to understand

Can Prolog Facts be used for Adversarial Search?

眉间皱痕 提交于 2021-01-28 11:23:42
问题 One can search the full tic tac toe game tree, using only fail fast optimization of negation as failure, in less that 100ms. Thats what this solution does using a holistic representation of the game state as a single Prolog term: ?- time((init(X), best(X, x, _))). % 92,055 inferences, 0.031 CPU in 0.031 seconds (99% CPU, 2984342 Lips) false. The above solution uses a single term for the board, here is an example from the code: init([[-, -, -], [-, -, -], [-, -, -]]). Are there any Prolog

Prolog do predicate for all pairs in List?

删除回忆录丶 提交于 2021-01-28 08:50:20
问题 I have a set of possibilities in a Prolog script and want to find the largest set, where a particular predicate applied to all pairs of the list evaluates true. A simplified example would be a set of people, and you want to find the largest group where all of them are mutual friends. So, given: % Four-way friend CIRCLE link(tom, bill). link(bill, dick). link(dick, joe). link(joe, tom). % Four-way friend WEB link(jill, sally). link(sally, beth). link(beth, sue). link(sue, jill). link(jill,