Home > Archive > Prolog > February 2006 > problem: how to translate predicate logic sentences to Prolog?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
problem: how to translate predicate logic sentences to Prolog?
|
|
| j.vanloon-ab@fontys.nl 2006-01-31, 7:58 am |
| given these 2 sentences in predicate logic:
1. for all Car: color(Car, blue) -> not owner(tim, Car) // tim doesnot
have a blue car
2. color ( auto4, blue) // auto4 is a blue car
with modus ponens I can conclude:
3. not owner(tim, auto4) // tim doesnot have auto4
How can I make a corresponding Prolog program ( translating 1. and 2.
in Prolog) to derive fact 3.?
greetings
jeu van loon
| |
| Markus Triska 2006-01-31, 7:02 pm |
| Hi!
j.vanloon-ab@fontys.nl wrote:
>
> How can I make a corresponding Prolog program ( translating 1. and 2.
> in Prolog) to derive fact 3.?
You can use constraint handling rules:
:- use_module(library(chr)).
:- chr_constraint color/2, not_owner/2.
color(Car, blue) ==> not_owner(tim, Car).
Now, you can query:
?- color(auto4, blue).
color(auto4, blue)
not_owner(tim, auto4)
Yes
All the best,
Markus.
| |
| Tom Breton 2006-01-31, 9:57 pm |
| "j.vanloon-ab@fontys.nl" <j.vanloon-ab@fontys.nl> writes:
> given these 2 sentences in predicate logic:
> 1. for all Car: color(Car, blue) -> not owner(tim, Car) // tim doesnot
> have a blue car
Is Car of some particular type? "for all" suggests not, but the
naming suggests yes.
> 2. color ( auto4, blue) // auto4 is a blue car
>
> with modus ponens I can conclude:
> 3. not owner(tim, auto4) // tim doesnot have auto4
>
> How can I make a corresponding Prolog program ( translating 1. and 2.
> in Prolog) to derive fact 3.?
Are you free to use the closed-world assumption or not? Ie, can you
deduce "tim does not have auto4" just because you can't prove that
"tim has auto4"?
It sounds like you are not, but Prolog uses the CWA.
If so, it's more a question of what you want to do with queries about
people other than tim and cars other than blue. Letting all
unmentioned cases succeed (Ie, treating other people as owning all
cars and tim as owning all cars other than blue and all objects as
possible cars and possible people), it's straightforward:
%%1
owner(Person, Car) :-
Person \= tim
;
\+ color(Car, blue).
%%2
color(auto4, blue).
3 ?- owner(tim,auto4).
No
--
Tom Breton, the calm-eyed visionary
| |
| Alexei A. Morozov 2006-02-02, 7:04 pm |
| Hi Jeu,
Well, if your question is theoretical one, you could see the book: W.
F. Clocksin and C. S. Melish. Programming in Prolog. Springer-Verlag,
1987. There are detailed instructions and an algorithm of translation
of arbitrary logic rules into the Prolog notation (see chapter 10).
If your question is practical one, you could see the last build of the
Actor Prolog language, where the algorithm from the Clocksin Melish
book is adopted.
Please investigate the following example:
A_PROLOG\EXAMPLES\FOR_RUSSIANS\STUDENTS\
TRANSLATE.A
The educational distribution pack of the Actor Prolog language you can
get for free:
http://www.cplire.ru/Lab144/start/setup1.exe
Best regards,
Alexei
http://www.cplire.ru/Lab144/start/index.html
| |
| Walter 2006-02-02, 7:04 pm |
| You should read some (more) of the basic theory. There is a lot of substance
pointed to by your question.
Prolog has only "definite clauses", eg: "A is true if B and C are true".
You can't prove things like "not A" except under certain assumptions, such
as a failure to prove A true means that A is false.
Hence you will various techniques to get to something resembling FOL in
specific applications,
and various extensions to Prolog to handle specific cases.
In Logic Programming, there are lots of variations.
Some like Prolog fall on the Programming end of the spectrum in that you
have immediate control over the algorithm used.
Others (notably various constraint extensions and the "rules" engines) fall
more towards the Logic end and can apply in specific environments. But you
don't have direct control over the algorithm.
Sorry I didn't give you a piece of code to use in your class.
Walter
<j.vanloon-ab@fontys.nl> wrote in message
news:1138711210.464470.171550@g47g2000cwa.googlegroups.com...
> given these 2 sentences in predicate logic:
> 1. for all Car: color(Car, blue) -> not owner(tim, Car) // tim doesnot
> have a blue car
> 2. color ( auto4, blue) // auto4 is a blue car
>
> with modus ponens I can conclude:
> 3. not owner(tim, auto4) // tim doesnot have auto4
>
> How can I make a corresponding Prolog program ( translating 1. and 2.
> in Prolog) to derive fact 3.?
>
> greetings
> jeu van loon
>
| |
| Ricardo Nuno 2006-02-14, 7:01 pm |
| you can use this two rules
color(car,blue).
color(auto4,blue). % auto4 is a blue car
not_owner(tim,car).
colours(X,Z):-color(X,Y),color(Z,Y),X\=Z.
not_tim(X):-colours(X,Z),not_owner(tim,Z).
|
|
|
|
|