prolog

A tuprolog syntax error.Syntax error at/before line -1

末鹿安然 提交于 2020-01-07 02:27:07
问题 I am new to prolog. I have a .pl file consulting normally on swi-prolog, but when I consult it on tu-prolog, crazy things always happen. Here are parts of my codes. :- dynamic(assignopT/6). :- multifile(assignopT/6). assignopT(30246,30244,30210,30247,+,30248). When I consulted it on tu-prolog,it said syntax error at/before line 12219,which is the third line above. It work all right on swi-prolog. Then I thought maybe there is something wrong with +, so I changed it to this. assignopT(30246

IF Statement in Prolog - Conditional

99封情书 提交于 2020-01-06 15:01:13
问题 I have just completed passing some variables down to another method and matching them to facts. I now want to add some security in the form of an if statement. I am hoping to check to see the variable inputted by the user is valid (this is in the form of a number) An example of this is shown in the code below, basically a user chooses an option between 1 and 10, if the user inputs an invalid option (ie 11) I want the method to print out "invalid choice" and repeat the method. My question: How

Code in Prolog generate all structurally distinct full binary trees with n node

China☆狼群 提交于 2020-01-06 08:07:14
问题 generate all structurally distinct full binary trees with n leaves in Prolog. The problem is given the number of leaves, output all distinct full binary trees. 'Full' here means any internal node must have two children, left and right. 回答1: To build all the trees through backtracking: full_tree(Leaves, [LTree, RTree]):- Leaves > 1, TLeaves is Leaves-1, between(1, TLeaves, LLeaves), RLeaves is Leaves-LLeaves, full_tree(LLeaves, LTree), full_tree(RLeaves, RTree). full_tree(1, '.'). This

Replacing atom with corresponding value from a list in Prolog

本小妞迷上赌 提交于 2020-01-06 07:14:30
问题 I have the following code. I pass in an atom as the first argument a list of equalities as the second argument, and I want to return the value of the atom according to the list of equalities. evaluator(Id,VariablesIn,Answer):- exp_symbols(Id,VariablesIn,Answer). exp_symbols(Id, VariablesIn, VariablesOut) :- VariablesIn =.. [F|Args], ( member(F=V, Id) -> G = V ; G = F ), maplist(exp_symbols(Id), Args, ArgsSWithSym), VariablesOut =.. [G|ArgsSWithSym]. When I call evaluator(a,[a=2,b=3],Answer).

Connected metro stations in prolog

青春壹個敷衍的年華 提交于 2020-01-06 06:56:37
问题 I have this problem of connected stations connected(ataba,naguib). connected(naguib,sadat). connected(sadat,opera). connected(opera,dokki). and i should show the full path taken by the metro, from a source station to a destination path(ataba,dokki,Z). Z = [[ataba, naguib], [naguib, sadat], [sadat, opera], [opera, dokki]] . i tried to do this : addlast(X,[],[X]). addlast(X,[H|T],[H,NewT]):- addlast(X,T,NewT). path(X,Y,L) :- connected(X,Y),addlast([X|Y],L,R). path(X,Y,L):- connected(X,Z),

Need help understanding Prolog append/3 and inverse/2 and trace output

萝らか妹 提交于 2020-01-06 06:09:30
问题 This is the question find value A. inverse([],[]). inverse([H|T],D) :- inverse(T,Z), append(Z,[H],D). append([],X,X). append([X|L],M,[X|N]) :- append(L,M,N). This is the answer: Plese help me to understand this! 回答1: The images of the Prolog code you posted show some unusual or very old Prolog, in particular for list the use of [H:T] is now done as [H|T] , notice the change from : to | , and <= is more common as :- . To understand the Prolog code it is easier to start from the bottom up. I

How to use user input in prolog to search

有些话、适合烂在心里 提交于 2020-01-06 05:50:29
问题 hello i want to be able to get the user input then store it and use in in my code. body(mercury, 36, small, none, none). body(venus, 67, small, atmosphere, none). body(earth, 93, small, atmosphere, none). body(moon, 93, small, none, none). body(mars, 141, small, atmosphere, none). body(jupiter, 489, large, atmosphere, rings). miles(Body,Miles):-write('Enter the Goal State:'),nl, read(X),nl, body(Body, Miles, _, _, _); Miles > X. 回答1: i switched to GNU prolog firstly which helped. miles(Body

Expand a query into a list in prolog

笑着哭i 提交于 2020-01-06 05:27:08
问题 How to expand a query into a list? f(a,b). f(a,c). d(a.d). expand(f(a,X), Out) -----> Out=[b,c,d] 回答1: Use bagof/3 or setof/3. E.g.: ?- bagof(X, (X = 1; X = 2), L). L = [1,2] yes In your case that would be ?- bagof(X, f(a,X), Out). 来源: https://stackoverflow.com/questions/1445490/expand-a-query-into-a-list-in-prolog

prolog all binary numbers

a 夏天 提交于 2020-01-06 03:59:05
问题 i need a predicate that will produce all the binary number of N digits . For instance the predicate binary(2,L) will return L = [[0, 0], [0, 1], [1, 0], [1, 1]] . please do not use findall .... 回答1: Once you have a list representing all the numbers with N bits, generating all the numbers of N+1 bits is just a matter of unfolding every N-number [a,b,c,...] into two N+1-numbers: [0,a,b,c,...] and [1,a,b,c,...] . Update : unfold([], []). unfold([H|T], [[0|H], [1|H]|L]) :- unfold(T, L). bn(N, L)

How to write it in skolem form?(Prolog)

大憨熊 提交于 2020-01-06 03:53:07
问题 Translate the following formula into a horn formula in Skolem form: ∀w¬∀x∃z(H(w)∧(¬G(x,x)∨¬H(z))) it's translated from german to english, how to write it in horn form and then in skolem form, i didn't find anything on internet...plz help me 回答1: I will always use the satisfiability preserving version of skolemization, i.e. the one where those are replaced which would become existential quantifiers when moved to the head of the formula. To make life a bit simpler, let's push the negations to