Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Problem with SWI Prolog
Hi,

I have a doubt in logic to prolog (SWI Prolog).

the problem with the predicates (p,q,r,z) is:

if p then q.
or r or not q.
p.
if p then z
not z

Prove f.

In prolog:

q :- p.
????? How can we represent that expression?
p.
z :- p.
z :- fail,!.   Is this correct????

Thank you very much for your help!!!

Rui Silva



Report this thread to moderator Post Follow-up to this message
Old Post
RuiSilva
06-06-05 01:57 PM


Re: Problem with SWI Prolog
In message <42a40966$0$8843$a729d347@news.telepac.pt>, RuiSilva
<msmr@netcabo.pt> writes
>Hi,
>
>I have a doubt in logic to prolog (SWI Prolog).

( all this is the same for all Prolog systems, not only SWI Prolog )

>the problem with the predicates (p,q,r,z) is:

( those are not predicates, they are atoms )

>if p then q.
>or r or not q.
>p.
>if p then z
>not z
>
>Prove f.
>
>In prolog:

>if p then q.
can be written as
q :- p.

>or r or not q.
means, I think, "either r or not q", which could be written as
r :- q.

>p.
can be written as
p.

>if p then z
can be written as
z :- p.

>not z
Cannot be written directly in Prolog.

>Prove f.
could be written as ?- f.

If you want to represent logical deductions, using "facts" like "not z",
you can't do it directly in Prolog.  But if you want to write some code
to handle such facts and use them to make deductions, Prolog is a good
language to write it in.

Nick
--
Nick Wedd    nick@maproom.co.uk

Report this thread to moderator Post Follow-up to this message
Old Post
Nick Wedd
06-06-05 08:58 PM


Re: Problem with SWI Prolog

RuiSilva wrote:
> Hi,
>
> I have a doubt in logic to prolog (SWI Prolog).
>
> the problem with the predicates (p,q,r,z) is:
>
> if p then q.
> or r or not q.
> p.
> if p then z
> not z
>
> Prove f.
>
> In prolog:
>
> q :- p.
> ????? How can we represent that expression?
> p.
> z :- p.
> z :- fail,!.   Is this correct????
>
> Thank you very much for your help!!!
>
> Rui Silva


'if p then q' can be expressed as:

p :- q.

'if p then q or r or not q'      can be expressed as:

p :-
(    q
;    r
;    not(q)
).

Note that this assumes that the predicate 'q' is suitably defined
elsewhere.

Also 'not(z)' is not explictly defined; in Prolog 'z' is defined and
then Prolog is capable of deciding if 'not(z)' is true or false.

Finally to prove 'f', one simply asked Prolog to compute the following:

f.


Hope this helps,

-Mike Goodrich


Report this thread to moderator Post Follow-up to this message
Old Post
goodrich_ms@yahoo.com
06-06-05 08:58 PM


Re: Problem with SWI Prolog
goodrich_ms@yahoo.com writes:


> 'if p then q' can be expressed as:
>
> p :- q.

You have it backwards.

Report this thread to moderator Post Follow-up to this message
Old Post
Torkel Franzen
06-06-05 08:58 PM


Re: Problem with SWI Prolog
oops, you are right.


Report this thread to moderator Post Follow-up to this message
Old Post
goodrich_ms@yahoo.com
06-06-05 08:58 PM


Re: Problem with SWI Prolog
Well I pretty much botched the whole post, sorry.


As was pointed out,  I have this backwards; as written what I have is:

q->p   (if q then p)

Also the second one makes no sense, since it would always be true (q ^
~q)

And so Prolog clauses are witten with the consequent stated in the head
and the antecedents in the body.

So consider

p -> q    'p implies q' or 'if p then q':

Prolog:
q :- p           % literally 'q if p'

r V s V ~q  -> p    'if [r or s or not(q)] then p'

Prolog:

p :-
(    r
;    s
;    not(q)
).                      % literally 'p if r or s or not(q)'


And so on.

-mg


Report this thread to moderator Post Follow-up to this message
Old Post
goodrich_ms@yahoo.com
06-06-05 08:58 PM


Re: Problem with SWI Prolog
your reading as if-then-else is "almost right".
It is often used, yet not totally precise. Actually you read Prolog
clauses

p:-q.
p:-r.

better as "p is defined as q or r".
When p is a not recursive it is equivalent with the reading

"p if and only if q or r".

This is because Prolog includes the Closed World Assumption in its
inference process.
By this reading it follows that Prolog can derive that p is false if
both q and r are false.

If it was classical First Order Logic implication, Prolog should be
able to derive that p is true if q and r are false (because from false
anything can follow...), which is not the case.

In case of negation and recursion, the if and only if reading/inference
breaks down and yields non-intuitive answers. (e.g. Prolog loops.) The
better declarative reading for the neck symbol ":-" is  "is defined
by", and which can be given a precise mathematical formal semantics.
[See papers by M. Denecker on inductive definitions for technical
reading on this]

If you try a "Prolog with better declarative readings and formal
semantics" try any of the answer set programming systems or abductive
reasoning systems (DLV,sModels,Asystem,... see the website of the
Workgroup on Answer Set Programming (WASP))

best regards,

Bert

ps. The confusion between "Classical FOL" and "Prolog view on FOL" can
lead to heated debates, in which people defend their view on "logic" as
the right one, but fail to understand that they are talking about a
different logic.  (see deductive databases track in this newsgroup) By
this again: Prolog is not FOL and FOL is not Prolog.


Report this thread to moderator Post Follow-up to this message
Old Post
Bert.VanNuffelen+google@cs.kuleuven.ac.be
06-08-05 01:58 PM


Re: Problem with SWI Prolog
Bert.VanNuffelen+google@cs.kuleuven.ac.be writes:

> If it was classical First Order Logic implication, Prolog should be
> able to derive that p is true if q and r are false (because from false
> anything can follow...),

p is not a logical consequence of "p if and only if q or r",
"not-r", "not-q".

> In case of negation and recursion, the if and only if reading/inference
> breaks down and yields non-intuitive answers.

The use of the completion in interpreting a Prolog program works
just as well with recursive as with non-recursive clauses. What
"breakdown" do you have in mind?

Report this thread to moderator Post Follow-up to this message
Old Post
Torkel Franzen
06-08-05 01:58 PM


Re: Problem with SWI Prolog
Hi,

Lets explain it by the classical transitive closure example.

ancestor(X,Y):- parent(X,Y).
ancestor(X,Y):- ancestor(X,Z), ancestor(Z,Y).

You intend to write the transitive closure of the parent relation which
is a finite relation for a acyclic graph. Every person can construct
that without any problem.
However Prolog goes into an infinite loop. Even more, the completion
semantics have models for the ancestor relation that are not the
transitive closure. Hence,  Prolog and the completion semantics break
down the relation between our intentions of the program and what we
actually get by Prolog.

This is *very* unnatural behavior in the context that one tried
(tries?) to sell Prolog as a "declarative specification language: write
what you intend and the system will do the reasoning for you".
In the case of the transitive closure it is clearly not the case.
(Negation makes it even worse.)

On the completion:

The FOL theory

{p <-> q or r}  has  the  models {p,q,r} {p,q},{p,r} and {}

The FOL theory
{p<- q, p<-r} has the models {r,p,q} {q,p}, {r,p}, {} and {p}

The last model is due to the fact that if q and r are false you didn't
restrict the value of p.

As you pointed out, indeed p is not a logical consequence of any of
these FOL theories. because there is each time one model that does not
contain p.

Bert


Report this thread to moderator Post Follow-up to this message
Old Post
Bert.VanNuffelen+google@cs.kuleuven.ac.be
06-08-05 01:58 PM


Re: Problem with SWI Prolog
Bert.VanNuffelen+google@cs.kuleuven.ac.be writes:

> However Prolog goes into an infinite loop.

Prolog will loop in non-recursive cases as well. A logical interpretation
of Prolog programs only guarantees that *if* Prolog produces a
solution, the corresponding statement is a logical consequence of the
program.

Report this thread to moderator Post Follow-up to this message
Old Post
Torkel Franzen
06-08-05 01:58 PM


Sponsored Links




Last Thread Next Thread Next
Pages (2): [1] 2 »
Search this forum -> 
Post New Thread

Prolog archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:44 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.