Jump to content
  • Advertisement
Sign in to follow this  

Prolog Execution

This topic is 4548 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

When dealing with prolog statements as a single system, how should we think about the connection between the statement: disjunction or conjunction.. What I mean is that if we have a system S which is a set of statements si... The consequent program that system S represents is: 1 s1 and s2 and ... sn or 2 s1 or s2 or ... sn or is it something else? [Edited by - arithma on July 2, 2006 1:22:35 PM]

Share this post

Link to post
Share on other sites
I'm not sure what you mean.

Given a query, Prolog will try to find every combination of arguments which will fulfill the necessary goals.


Intuitively, you could interpret this as "a is a vowel AND e is a vowel AND...", and in a way, that would be correct, but it's actually an OR relationship, because if you ask Prolog


X = a;
X = e;
X = i;
X = o;
X = u;

This asks Prolog "give me a binding for X so that vowel(X) is true". vowel(X) is true when "X = a OR X = e OR X = i OR X = o OR X = u", so Prolog will return each of these possibilities as solutions.

If it had been a conjunction, you'd write

vowel(X) :-
X = a,
X = e,
X = i,
X = o,
X = u.

but there's no X which fulfills all these conditions.

If this doesn't help you, could you give a more concrete example, e.g. some Prolog code or a problem you want solved?

Share this post

Link to post
Share on other sites
After thinking about it, I believe it is a conjunction as you speculated. And your example was right on the spot.

It couldn't have been a disjunction since that way it cannot be sure whether any of them would be true. If it were, then your first program is equivalent to the other one :)

I solved this ambiguity by thinking about prolog statements as if they were equations (which in essence they really are) and deciding what should the *junction be if I wanted to solve it.

As to what I was trying to do: Me is trying to make an execution engine for a language like prolog... selfdestructive pun intended.

Follow up Questions
Why doesn't prolog contain a complement [not] operator? Are they not necessary? What if I discard the Closed-Universe Assumption and what would that imply on the design of this engine? Any ideas about introducing some uncertainity into a prolog-like execution engine, the value UNKNOWN maybe?

Share this post

Link to post
Share on other sites
Prolog does contain a not operator: \+.

range(A, B, []) :-
A > B.
range(A, B, [A | Rest]) :-
A =< B,
A2 is A + 1,
range(A2, B, Rest).

factor(Num, Factor) :-
Half is Num // 2,
range(2, Half, Range),
member(Factor, Range),
Num mod Factor =:= 0.

prime(Num) :-
\+ factor(Num, _).

Be careful with it though: if Prolog finds one set of bindings for which the operand is false, it succeeds. It means "there is one set of bindings for which this does not succeed", not "there exist no bindings for which it succeeds".

Share this post

Link to post
Share on other sites
Creating a Prolog-interpreter in Prolog is relatively simple, so creating a Prolog-extension should not be hard.

As for the Closed Universe Assumption, I have no idea. AFAIK, it doesn't make much of a difference: if Prolog says "No", I'd just interpret as "Maybe".

exec(G) :-
write('Maybe some more, maybe not...'),

I guess it could make a difference if you'd extend Prolog so that you could define "negative clauses"... anyway, I'm not a logic expert, so any further comments would only be an ignorant's wild guesses.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!