prolog get syntax error when increase stack size - prolog

Trying to solve the puzzle task with prolog and got some problems.
1002 Stack Overflow. Re-configure with Setup if necessary.
So, I've tried to increase stack size in setup and run program again.
But it causes the other error: Syntax error on line...
The error line is line with operator "not" in predicate.
Here is my code:
domains
age = integer
childname,ffood,fear = string
child = child(childname,age,ffood,fear)
children = child*
predicates
solve
name(child,childname)
fear(child,fear)
age(child,age)
ffood(child,ffood)
keys(children)
solution(children)
elder(child)
member(children,child)
structure(children)
clauses
member([X|_],X).
member([_|SP],X):-member(SP,X).
name(child(A,_,_,_),A).
age(child(_,A,_,_),A).
ffood(child(_,_,A,_),A).
fear(child(_,_,_,A),A).
structure([child("Dima",_,_,_),child("Kate",_,_,_),child("Misha",_,_,_),child("Sveta",_,_,_),child("Ura",_,_,_)]).
elder(child(_,A,_,_)):-A=7;A=8.
solve:-structure(Children),keys(Children),solution(Children).
keys(Struct):-
member(Struct,child(_,4,_,_)),
member(Struct,child(_,5,_,_)),
member(Struct,child(_,6,_,_),
member(Struct,child(_,7,_,_),
member(Struct,child(_,8,_,_)),
member(Struct,child(_,_,"Banana",_),
member(Struct,child(_,_,"Icecream",_),
member(Struct,child(_,_,"Pizza",_),
member(Struct,child(_,_,"Pasta",_),
member(Struct,child(_,_,"Chocolate",_),
member(Struct,child(_,_,_,"Thunderstorm"),
member(Struct,child(_,_,_,"Spiders"),
member(Struct,child(_,_,_,"Ghosts"),
member(Struct,child(_,_,_,"Dogs"),
member(Struct,child(_,_,_,"Darkness"),
member(Struct,Child1),
name(Child1,"Kate"),
elder(Child1),
not(fear(Child1,"Darkness")),
not(ffood(Child1,"Chocolate")),
member(Struct,Child2),
name(Child2,"Sveta"),
elder(Child2),
not(fear(Child2,"Darkness")),
not(ffood(Child2,"Chocolate")),
ffood(Child2,"Pizza"),
not(fear(Child2,"Spiders")),
member(Struct,Child3),
age(Child3,5),
fear(Child3,"Ghosts"),
member(Struct,Child4),
age(Child4,6),
fear(Child4,"Thunderstorm"),
not(ffood(Child4,"Chocolate")),
not(ffood(Child4,"Pasta")),
member(Struct,Child5),
age(Child5,4),
ffood(Child5,"Banana"),
member(Struct,Child6),
age(Child6,8),
not(fear(Child6,"Dogs")),
member(Struct,Child7),
name(Child7,"Dima"),
not(age(Child7,5)),
not(fear(Child7,"Darkness")),
not(fear(Child7,"Spiders")),
not(ffood(Child7,"Banana")),
member(Struct,Child8),
name(Child8,"Misha"),
not(fear(Child8,"Darkness")),
not(fear(Child8,"Spiders")),
not(ffood(Child8,"Banana")).
solution (Children):-
write ("Solve:"), write (Children).
goal
solve.
Found strange this prolog behavior... maybe somebody had the same problem?

I tried to reformat your code with SWI-Prolog:
keys(Struct):-
member(Struct,child(_,4,_,_)),
member(Struct,child(_,5,_,_)),
member(Struct,child(_,6,_,_),
member(Struct,child(_,7,_,_),
member(Struct,child(_,8,_,_)),
member(Struct,child(_,_,"Banana",_),
...
seems you're missing some parenthesis...
after the obvious correction, I get
?- solve.
Solve:[child(Dima,6,Icecream,Thunderstorm),child(Kate,8,Pasta,Spiders),child(Misha,5,Chocolate,Ghosts),child(Sveta,7,Pizza,Dogs),child(Ura,4,Banana,Darkness)]
true .

Related

Problem with building an expert system in prolog

I keep getting syntax errors while compiling this code in prolog. I'm new to programming so I don't quite understand. Can someone please help me debug where I went wrong? The expert system was meant to classify animals with vertebrates and invertebrates. This is the code I currently have:
:-dynamic known/3
top_goal(X):-animal(X).
%Animals and their classifications
animal(lion):-
type(vertebrate),
color(brown).
animal(bee):-
type(invertebrate),
color(yellow).
animal(crickets):-
type(invertebrate),
color(green).
%background information about vertebrates and invertebrates.
animal(vertebrate):-
vertebral_column(present),
nerve_cord(dorsal_and_hollow),
skeleton(internal),
heart(located_on_right_side),
haemoglobin(present_in_red_blood_cells).
animal(invertebrate):-
vertebral_column(absent),
skeleton(external),
heart(located_on_dorsal_side),
haemoglobin(dissolved_in_plasma).
%Ask rules
animal(X):-ask(type,X).
animal(X):-ask(color,X).
animal(X):-ask(sound,X).
ask(A,V):-
write(A:V),%ask user
write('?:'),
read(Y),%get the answer
asserta(known(Y,A,V),%remember it
Y==yes.%succeed or fail
solve:-
retractall(known(_,_,)),
top_goal(X),
write('The animal is '),write(X),nl.
solve:-
write('This animal is unknown '),nl.
You have some typos.
ask(A,V):-
write(A:V),%ask user
write('?:'),
read(Y),%get the answer
asserta(known(Y,A,V)), %remember it ***missing ')'
Y==yes.%succeed or fail
and here
solve:-
retractall(known(_,_,_)), % *** missing _
top_goal(X),
write('The animal is '),write(X),nl.
Then some codes are missing: color/1, haemoglobin/1, heart/1,
nerve_cord/1, skeleton/1, top_goal/1, type/1, vertebral_column/1.

How to repair error in Einstein Zebra in prolog >

I have a problem with zebra puzzle.
rightOf(A,B,(B,A,_,_,_)).
rightOf(A,B,(_,B,A,_,_)).
rightOf(A,B,(_,_,B,A,_)).
rightOf(A,B,(_,_,_,B,A)).
middleHouse(A,(_,_,A,_,_)).
firstHouse(A,(A,_,_,_,_)).
nextTo(A,B,(A,B,_,_,_)).
nextTo(A,B,(_,A,B,_,_)).
nextTo(A,B,(_,_,A,B,_)).
nextTo(A,B,(_,_,_,A,B)).
nextTo(A,B,(B,A,_,_,_)).
nextTo(A,B,(_,B,A,_,_)).
nextTo(A,B,(_,_,B,A,_)).
nextTo(A,B,(_,_,_,B,A)).
house[Nationality,Pet,Sport,Drinks,Colour].
zebra_owner(Owner) :-
houses(Houses),
exists(house(Owner,zebra,_,_,_), Houses).
length(5,Houses),
exists(house(british,_,_,_,red),Houses),
exists(house(spanish,dog,_,_,_),Houses),
exists(house(_,_,_,coffe,green),Houses),
exists(house(ukrainian,_,_,tea,_),Houses),
rightOf(house(_,_,_,_,green),house(_,_,_,_,ivory),Houses),
exists(house(_,snail,tennis,_,_),Houses),
exists(house(_,_,chess,_,yellow),Houses),
middleHouse(house(_,_,_,mlik,_),Houses),
firstHouse(house(norwegian,_,_,_,_),Houses),
nextTo(house(_,_,rugby,_,_),house(_,fox,_,_,_),Houses),
nextTo(house(_,_,chess,_,_),house(_,horse,_,_,_),Houses),
exists(house(_,_,volleyball,orangejuice,_),Houses),
exists(house(japanese,_,_,_,_),Houses),
nextTo(house(norwegian,_,_,_,_),house(_,_,_,_,blue),Houses),
nextTo(house(_,_,_,tea,_),house(_,_,_,milo,_),Houses),
exists(house(zebra_owner,zebra,_,_,_),Houses).
Under
house[Nationality,Pet,Smokes,Drinks,Colour].
I see the error: Singleton variables: house[Nationality,Pet,Smokes,Drinks,Colour].
And when I write ?- zebra_owner(Owner)
I see the error: procedure 'houses(A)' does not exist. Reachable from:zebra_owner(A).`
You cannot write
house[Nationality,Pet,Sport,Drinks,Colour].
that's non-existent syntax.
To express that predicate house/1 is valid for list [Nationality,Pet,Sport,Drinks,Colour], write:
house([Nationality,Pet,Sport,Drinks,Colour]).
You also must pay attention to predicate naming: houses/1 is not house/1. Predicate houses/1 is defined nowhere (the error message is wrong, it should really say predicate houses/1 is undeclared).

how to solve the error in this prolog code

What is wrong in this code
frequency(f1).
frequency(f2).
frequency(f3).
allocation(z1,z2,z3,z4,z5,z6,z7,z8) :-
frequency(z1), frequency(z2), frequency(z3), frequency(z4), frequency(z5), frequency(z6), frequency(z7), frequency(z8),
z1\==z2, z1\==z3, z2\==z4, z2\==z3, z3\==z4, z3\==z6, z4\==z5, z4\==z6, z4\==z7, z6\==z7, z6\==z8.
?- allocation(f1,f2,f3,f1,f2,f3,f2,f3).
syntax error: . or operator expected after expression
The following code highlighting should make it clear why the goal allocation(f1,f2,f3,f1,f2,f3,f2,f3) cannot succeed:
allocation(Z1,Z2,Z3,Z4,Z5,Z6,Z7,Z8) :-
dif(Z1,Z2), dif(Z1,Z3),
dif(Z2,Z3), dif(Z2,Z4),
dif(Z3,Z4), dif(Z3,Z6),
dif(Z4,Z5), dif(Z4,Z6), dif(Z4,Z7),
dif(Z6,Z7), dif(Z6,Z8),
maplist(frequency, [Z1,Z2,Z3,Z4,Z5,Z6,Z7,Z8]).
Note the use of dif/2 instead of (\==)/2 in the code above?
prolog-dif preserves logical-purity, for easier debugging!

Prolog syntax error: illegal start of term

So I'm trying to test my the predicate reduce/4 defined as following:
:- op(20,xfy,?=).
reduce(R,X ?=Y,P,Q) :-
R=rename,
regle(X ?=Y,R),
length(P,N),
trouve(Y,P,N,M),
remove(N,M,P,Q).
but i keep getting this error:
?- reduce(rename,X ?= Y,[?=(X,Y),?=(f(a),g(Z)),?=(X,a)],Q].
ERROR: Syntax error: Illegal start of term
ERROR: reduce(rename,X ?= Y,[?=(X,Y),?=(f(a),g(Z)),?=(X,a)],
ERROR: ** here **
ERROR: Q] .
I'm new to Prolog so maybe it is something stupid.
You use ] instead of ) to close the bracket of reduce
reduce(rename,X ?= Y,[?=(X,Y),?=(f(a),g(Z)),?=(X,a)],Q].
% ^open ^close
You can fix this with:
?- reduce(rename,X ?= Y,[?=(X,Y),?=(f(a),g(Z)),?=(X,a)],Q).
I cannot validate if this solves your problem, because you did not provide a definition for regle/2, etc. But the fact that I get a semantic error, seems to solve the syntax error nevertheless.

source_sink error in prolog using rdf_load

I want to load rdf url from this rule:
getActorFilms(Actor_Name,Films):-
my_replace(Actor_Name, ' ', '_', Correct_Syntax_Of_Actor_Name),
string_concat('http://dbpedia.org/data/',Correct_Syntax_Of_Actor_Name, URL_TO_LOAD),
string_concat(URL_TO_LOAD,'.rdf',RDF_URL),
rdf_load(RDF_URL),
rdf(Films, 'http://dbpedia.org/ontology/starring', Object)
.
when the input is e.g. for an example 'Hugh Jackman'
it tells the error:
ERROR: [Thread pdt_console_client_0_Default Process] source_sink `http://dbpedia.org/data/Hugh_Jackman.rdf' does not exist
I'm really concerned about the ` character between http and source_sink
I think it should be '
although the url is correct, so what to do with that error?
You should pass an atom to rdf_load, not a string. This behavior (the misleading error message, not accepting a string) is probably a bug.
This works for me:
?- use_module(library('semweb/rdf_db')).
true.
?- use_module(library('semweb/rdf_http_plugin')).
true.
?- rdf_load('http://dbpedia.org/data/Hugh_Jackman.rdf').
% Parsed "http://dbpedia.org/data/Hugh_Jackman.rdf" in 0.02 sec; 371 triples
true.
?- string_to_atom(S, 'http://dbpedia.org/data/Hugh_Jackman.rdf'), rdf_load(S).
ERROR: source_sink `http://dbpedia.org/data/Hugh_Jackman.rdf' does not exist
I hope this solves your problem.

Resources