Reputation: 1459
At the needs of my HW at uni I need to transform some Horn clauses to Prolog but I cannot figure out how to do it. I found out some guides but they describe how to do it with only one fact. So can you give me a brief example on how to do it?
Eg John is beautiful and rich
we can transform it at: not (Beautiful(John)) ^ not(Rich(John)) which is a Horn clause right? So how this can be translated it Prolog?
another example Everyone loves somebody. Horn clause: ∀X∃YLoves(X,Y) how can this be implemented in Prolog?
Thx in advance
Upvotes: 3
Views: 2970
Reputation: 681
For the first question you have
john :- beautiful, rich.
Or having something like:
beautiful(john).
rich(john).
with the query:
beautiful(X),rich(X).
Basically every rule in prolog is a horn clause. By definition, a Logic Program is a program, comprising of Horn clauses. In prolog when you have a rule that is declared as:
a1(X):-a2(X),a3(X),...,an(X)
is a horn clause because it is translated as:
a1 or not a2 or not a3 or ... or not an
So for your second question: In prolog the universal quantifier is implied when you define a rule so it does not affect the prolog clause. So you need to negate your sentence so you can transform the existential quantifier to a universal one. So, you have:
∀X∃YLoves(X,Y)
then you negate:
∀X ∀Y false <- Loves(X,Y))
which translates into:
:- loves(X,Y).
Upvotes: 1