prolog

prolog dcg restriction

不想你离开。 提交于 2021-02-07 13:23:36
问题 I would like to use DCGs as a generator. As of now, the syntax is s-->a,b. a-->[]. a-->a,c. c-->[t1]. c-->[t2]. b-->[t3]. b-->[t4]. I would like to generate all s where the length of a is < someNumber . Using ?- phrase(a,X),length(X,Y),Y<4. i can get all a with less than 4 items. However, when all combinations are exhausted, the system (SWI-Prolog 6.2.5) seems to stall. Sometimes ago, a similar question was asked here. However, being new to Prolog i am not able to make it work with the

Game Tree modulo Symmetry in Prolog

人走茶凉 提交于 2021-02-05 09:34:48
问题 Lets work out a game tree for Tic-Tac-Toe. How would one compute this result in Prolog: Taking the 8 symmetries into account, and assuming computer (X) starts and plays deterministic, then only 49 table entries are needed! 1 entry for empty board 5 entries for 2 pieces 21 entries for 4 pieces 18 entries for 6 pieces 4 entries for 8 pieces https://stackoverflow.com/a/61298546/502187 回答1: It's a vague question with an incorrect premise: assuming computer (X) starts and plays deterministic OK 5

Why after pressing semicolon program is back in deep recursion?

强颜欢笑 提交于 2021-02-04 07:34:28
问题 I'm trying to understand the semicolon functionality. I have this code: del(X,[X|Rest],Rest). del(X,[Y|Tail],[Y|Rest]) :- del(X,Tail,Rest). permutation([],[]). permutation(L,[X|P]) :- del(X,L,L1), permutation(L1,P). It's the simple predicate to show all permutations of given list. I used the built-in graphical debugger in SWI-Prolog because I wanted to understand how it works and I understand for the first case which returns the list given in argument. Here is the diagram which I made for

Why after pressing semicolon program is back in deep recursion?

青春壹個敷衍的年華 提交于 2021-02-04 07:34:25
问题 I'm trying to understand the semicolon functionality. I have this code: del(X,[X|Rest],Rest). del(X,[Y|Tail],[Y|Rest]) :- del(X,Tail,Rest). permutation([],[]). permutation(L,[X|P]) :- del(X,L,L1), permutation(L1,P). It's the simple predicate to show all permutations of given list. I used the built-in graphical debugger in SWI-Prolog because I wanted to understand how it works and I understand for the first case which returns the list given in argument. Here is the diagram which I made for

Why after pressing semicolon program is back in deep recursion?

拈花ヽ惹草 提交于 2021-02-04 07:34:11
问题 I'm trying to understand the semicolon functionality. I have this code: del(X,[X|Rest],Rest). del(X,[Y|Tail],[Y|Rest]) :- del(X,Tail,Rest). permutation([],[]). permutation(L,[X|P]) :- del(X,L,L1), permutation(L1,P). It's the simple predicate to show all permutations of given list. I used the built-in graphical debugger in SWI-Prolog because I wanted to understand how it works and I understand for the first case which returns the list given in argument. Here is the diagram which I made for

Is pure Prolog Turing-complete, and if so, why can't it implement list intersection?

∥☆過路亽.° 提交于 2021-02-04 04:58:19
问题 The Wikipedia section on this topic is a mess. It states: Pure Prolog is based on a subset of first-order predicate logic, Horn clauses, which is Turing-complete. Turing completeness of Prolog can be shown by using it to simulate a Turing machine: (emphasis added) And then it goes on to show code that uses things that are not Horn clauses ( ! and once ): turing(Tape0, Tape) :- perform(q0, [], Ls, Tape0, Rs), reverse(Ls, Ls1), append(Ls1, Rs, Tape). perform(qf, Ls, Ls, Rs, Rs) :- !. perform(Q0

Is pure Prolog Turing-complete, and if so, why can't it implement list intersection?

喜夏-厌秋 提交于 2021-02-04 04:56:57
问题 The Wikipedia section on this topic is a mess. It states: Pure Prolog is based on a subset of first-order predicate logic, Horn clauses, which is Turing-complete. Turing completeness of Prolog can be shown by using it to simulate a Turing machine: (emphasis added) And then it goes on to show code that uses things that are not Horn clauses ( ! and once ): turing(Tape0, Tape) :- perform(q0, [], Ls, Tape0, Rs), reverse(Ls, Ls1), append(Ls1, Rs, Tape). perform(qf, Ls, Ls, Rs, Rs) :- !. perform(Q0

Is pure Prolog Turing-complete, and if so, why can't it implement list intersection?

与世无争的帅哥 提交于 2021-02-04 04:56:29
问题 The Wikipedia section on this topic is a mess. It states: Pure Prolog is based on a subset of first-order predicate logic, Horn clauses, which is Turing-complete. Turing completeness of Prolog can be shown by using it to simulate a Turing machine: (emphasis added) And then it goes on to show code that uses things that are not Horn clauses ( ! and once ): turing(Tape0, Tape) :- perform(q0, [], Ls, Tape0, Rs), reverse(Ls, Ls1), append(Ls1, Rs, Tape). perform(qf, Ls, Ls, Rs, Rs) :- !. perform(Q0

How to get the first letter of each word enter by user

╄→尐↘猪︶ㄣ 提交于 2021-01-29 17:21:09
问题 Here are the details of my code name:-read(X),write('Name : '),write(X),nameCode(X). nameCode(X):-nl, write('Name Code : '). I would like to take the first 3 letters from each word and display it . What should be added to my code? Furthermore, the result i get only allows me to enter a single name from user. When i attempt to enter several names(peter jane mary) in the query, it display a syntax message as below | ?- name. |: peter jane mary. * Syntax Error Below are the results of what i

Can maplist([X]>>(test(X,Xs)) see variable in outer in scope?

做~自己de王妃 提交于 2021-01-29 15:52:55
问题 ?- maplist([X]>>(member(X,[1,2])), [1,2]). true but: ?- X2s=[1,2], X1s=[1,2], maplist([X]>>(member(X,X1s)), X2s). X1s = X2s, X2s = [1, 2] X1s is not grounded, despite being grounded. Here a notebook testing it: https://swish.swi-prolog.org/p/ungrounded%20in%20map.swinb What's up with that? 回答1: Do not get confused by the SWI-Prolog variable-name-aliasing ?- debug(foo),X2s=[1,2], X1s=[1,2], maplist([X]>>(debug(foo,"Testing ~q",[X]),member(X,X1s)),X2s). Warning: foo: no matching debug topic