Encoding this logic sentence in Prolog: G ↔ ~Provable(x) - prolog

http://www.swi-prolog.org/pldoc/man?predicate=%5C%2B/1
How would the above expression be encoded in Prolog?
Here it is in English for all the people that know Prolog
by do not know predicate logic:
G has the same truth value as its own unprovability.
Would every translation of the above logic expression always fail an occurs check?
http://www.swi-prolog.org/pldoc/man?predicate=unify_with_occurs_check/2

Related

Why does this expression not unifiy

I have defined the following knowledge base:
leaf(_).
tree(X) :- leaf(X).
and was expecting the query:
leaf(X) = tree(X).
to return true ., because any leaf should per definition be a tree.
Unfortunately activating trace doesn't yield any useful results.
Here is a link to this minimal example if you'd like to play around with it.
Short answer: you here check if the term leaf(X) can be unified with tree(X). Since these are terms that consist out of different functors, this will fail.
The tree/1 and leaf/1 in your statement leaf(X) = tree(X) are not the predicates. What you basically here have written is:
=(leaf(X), tree(X))
So you call the (=)/2 predicate, with leaf(X) and tree(X) terms.
Now in Prolog two terms are unifiable if:
these are the same atom; or
it is a term with the same functor and arity, and the arguments are elementwise unifiable.
Since the functor leaf/1 is not equal to the functor tree/1, this means that leaf(X) and tree(X) can not be equal.
Even if we would define a predicate with the intent of checking if two predicates are semantically the same, this would fail. Here you basically aim to solve the Equivalence problem, which is undecidable. This means that one, in general, can not construct an algorithm that verifies if two Turing machines decide the same language. Prolog is a Turing complete language, we basically can translate any predicate in a Turing machine and vice versa. So that means that we can not calculate if two predicates accept the same input.

How can you translate prolog rules and query into first order logic?

I am trying to understand how to translate the prolog rule
brother(g(x), g(y)) :- brother(x,y).
brother(n,n).
to first order logic.
is ∀x,y(brother(x,y) -> brother(g(x), g(y)) a correct answer?
No, the answer is not correct.
First, decide whether x, y and n in the Prolog program are actually meant to be logical variables. In that case, you need to change the program: A Prolog variable begins with an uppercase letter or underscore. So, suppose you change the program to:
brother(g(X), g(Y)) :- brother(X, Y).
brother(N, N).
Then the translation you give is still not sufficient to capture the declarative meaning of this logic program.
For example, using just the implication you give, can you derive a single statement that actually holds?

How would I represent the following prolog statement in predicate logic?

How would you transform the following prolog statement to predicate logic?
hates(amy, X).
Using LaTeX's \forall to denote the universal quantifier, the meaning of hates(amy,x). is:
\forall x hates(amy,x)
In general, Prolog variables that occur in a program are universally quantified and Prolog variables that occur in a query are existentially quantified. For instance ?- hates(amy,x). would be represented by \exists x hates(amy,x) in FOL.

Horn Clause to prolog

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
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).

How to express universal quantifier in the body of a datalog rule?

I want to use universal quantifier in the body of a predicate rule, i.e., something like
A(x,y) <- ∀B(x,a), C(y,a).
It means that only if for each a from C(y, a), B(x,a) always has x to match (x,a), then A(x,y) is true.
Since in Datalog, every variable bounded in rule body is existential quantifier by default, the a would be an existential quantifier too. What should I do to express universal quantifier in the body of a predicate rule?
Thank you.
P.S. The Datalog engine I am using is logicblox.
The basic idea is to use the logical axiom
∀x φ(x) ⇔ ¬∃x ¬φ(x)
to put your rules in a form where only existential quantifiers are required (along with negation). Intuitively, this usually means computing the complement of your answer first, and then computing its complement to produce the final answer.
For example, suppose you are given a graph G(V,E) and you want to find the vertices which are adjacent to all others in the graph. If universal quantification were allowed in a Datalog rule body, you might write something like
Q(x) <- ∀y E(x,y).
To write this without the universal quantifier, you first compute the vertices which are not adjacent to all others
NQ(x) <- V(x), V(y), !E(x,y).
then return its complement as the answer
Q(x) <- V(x), !NQ(x).
The same kind of trick can be used in SQL, which also lacks universal quantifiers.

Resources