Translate sentence into FOL expression, confused about constants and quantifiers - first-order-logic

Translate the following statements into FOL sentances
1) Alex likes John
Likes(alex, john) - I know this is correct
2) Each person is either a man or woman
AxAy( man(x) v woman(y) )
EDIT: Is this better??: Az(Person(z) -> man(x) v woman(y))
OR EDIT: Is this better??: Ax(Person(x) -> man(x) v woman(x))
3) No one is both man and woman
Ex( (man(x) ^ ¬woman(x)) v (¬man(x) ^ woman(x)) )
4) Alex likes a man who likes a woman
AxEy(Likes( man(x), woman(y) ) -> Likes(alex, man(x) ))
Thanks
Here is a screenshot of the background info
EDIT: For number 3, I have found this online
"The exclusive disjunction of p and q asserts that either p is true or q is true but not both. The natural, but long-winded, way to express exclusive disjunction, then, is (p | q) & ~(p & q)."
If this can apply, then I assume the correct answer is Ax( (man(x) v woman(x)) ^ ¬(man(x) & woman(x)) )
But now I am getting confused as to how 2 and 3 are different...

Hey I just wanted to know if these were correct
1. Testing the Correctness of Translation
One of the ways to test if a first order sentence agrees with an informal specification is to use a model.
To perform a test you need:
To determine how many relations are there in your first order sentence and list them. This list would play the role of the logical signature of your model.
Now take a set of individuals large enough to have all interesting combinations of properties assigned to at least one individual.
Assign the properties to individuals according to your understanding of the meaning of relations in your first order sentence.
Finally for each universally quantified variable try different assignments of individuals to variables and check if the property holds.
Consider one of the examples from the post.
Informal specification: Alex likes a man who likes a woman
We have
one constant symbol: Alex
two unary relations: Man(x) and Woman(x)
a binary relation: Likes(x,y)
1.1 Structure No. 1
Now consider a structure where we have an individual for Alex, an individual for a man who is not Alex, and an individual for a woman who is not Alex.
Let's start with three: p1, p2, p3.
Alex is p1
Man(p2)
Woman(p3)
Woman(p1)
Likes (p2,p3)
Likes (p1,p2)
The informal specification says that Alex likes someone who is a Man and Likes someone else who is a Woman. Our model satisfies this specification.
Now consider the following statement taken from the OP:
AxEy(Likes( man(x), woman(y) ) -> Likes(alex, man(x) ))
This statement is from a different language. Here man(x) and woman(y) are unary functions instead of unary relations, so we cannot check this sentence.
I would not speculate any further on the subject of woman(y) or man(x) being a function (Pun intended). Instead I would consider a different sentence.
AxEy(Man(x) & Woman(y) & Likes( x, y ) -> Likes(alex, x ))
Let's see what happens if x=p2 and y=p1. In our model the premise
Man(p2) & Woman(p3) & Likes( p2, p3 )
holds, and the conclusion
Likes(p1,p2)
also holds, therefore the formula is true under this variable assignment.
1.2 Structure No. 2
Now consider a different model. This time with four individuals: p1,p2,p3,p4.
Alex is p1
Man(p2)
Man(p4)
Woman(p3)
Woman(p1)
Likes (p2,p3)
Likes (p1,p2)
Likes (p4,p3)
This model also satisfies our informal specification as Alex likes p2 who is a Man and likes p3 who is a Woman.
Consider the assignment x=p4 and y=p3.
Once again the premise holds in our model
Man(p4) & Woman(p3) & Likes( p4, p3 )
however the conclusion
Likes(p1,p4)
does not hold in our model. Since x is universally quantified this might be a problem as the formula does not hold under this assignment, however y is under an existential quantifier. Let's see if we can find an assignment for y that would turn our formula into a true statement with x=p4.
This is indeed possible. Let y=p2.
Man(p4) & Woman(p2) & Likes( p4, p2 )
does not hold, therefore the formula
Man(p4) & Woman(p2) & Likes( p4, p2 ) -> Likes(p1,p4)
is true. This sounds better yet to satisfy the formula we took an assignment that is far from the intended meaning of the informal specification. The original specification clearly was not speaking about a man who likes another man. So we are not done yet.
1.3 Structure No. 3
Consider a model with just two individuals: p1 and p2.
Alex is p1
Man(p2)
Woman(p1)
The informal specification does not hold in this model, so our sentence also should be false. There are four possible assignments of variables
x=p1,y=p2
x=p1,y=p1
x=p2,y=p1
x=p2,y=p2
Since Like(x,y) is always false in our model, the premise fails therefore according to the rules of implication, the formula is true. So our sentence is also true in a model where it should not hold. Once again, our first-order formalization does not hold against the informal specification.
This seems to be a very complex process that we have taken to test the translation. It assumes a certain skill of finding counterexamples and always keeping in mind the intended meaning of the informal specification.
2. How to Come up with a Correct Translation
Let's look back at our informal specification
Informal specification: Alex likes a man who likes a woman
and reformulate it in a way that is easier to translate
There exists a man whom Alex likes, and this man likes some woman
There are two parts in this sentence connected with an and
Ex (Man(x) & Likes(Alex,x))
Ey (Woman(y) & Likes(x,y))
So we have
Ex (Man(x) & Likes(Alex,x) & Ey (Woman(y) & Likes(x,y))).
You like prenex normal forms where all quantifiers are collected in one quantifier prefix. We can apply logical equivalence to get
ExEy (Man(x) & Likes(Alex,x) & Woman(y) & Likes(x,y)).
Now let's check if this statement agrees with the specification in each of the structures from the previous section.
2.1 Structure 1
Since the variables are existentially quantified and the specification holds, we need to find only one satisfying assignment for the formula.
Consider
Alex is p1
x = p2
y = p3
The conjunction holds under this assignment.
2.2 Structure 2
The same assignment as in the previous subsection can be used. In fact
Structure 1 is an substructure of Structure 2. For an existentially quantified statement we know that if it is true in a substructure, it is also true in the whole structure.
2.3 Structure 3
Since there is no pair of elements (x,y) such that Likes(x,y) in our structure, the conjunction
Man(x) & Likes(Alex,x) & Woman(y) & Likes(x,y)
cannot be true, so the statement is false. We also know that Structure 3 does not satisfy our informal specification, so our formula has passed our tests.
Our testing procedure is by no means complete. However it gives us some assurance that the translation is indeed correct.

Related

What is the difference between Well-formed formula and a preposition in propositional logic

What is the exact difference between Well-formed formula and a proposition in propositional logic?
There's really not much given about Wff in my book.
My book says: "Propositions are also called sentences or statements. Another term formulae or well-formed formulae also refer to the same. That is, we may also call Well formed formula to refer to a proposition". Does that mean they both are the exact same thing?
Proposition: A statement which is true or false, easy for people to read but hard to manipulate using logical equivalences
WFF: An accurate logical statement which is true or false, there should be an official rigorus definition in your textbook. There are 4 rules they must follow. Harder for humans to read but much more precise and easier to manipulate
Example:
Proposition : All men are mortal
WFF: Let P be the set of people, M(x) denote x is a man and S(x)
denote x is mortal Then for all x in P M(x) -> S(x)
It is most likely that there is a typo in the book. In the quote Propositions are also called sentences or statements. Another term formulae or well-formed formulae also refer to the same. That is, we may also call Well formed formula to refer to a preposition, the word "preposition" should be "proposition".
Proposition :- A statement which is either true or false,but not both.
Propositional Form (necessary to understand Well Formed Formula) :- An assertion which contains at least one propositional variable.
Well Formed Formula :-A propositional form satisfying the following rules and any Wff(Well Formed Formula) can be derived using these rules:-
If P is a propositional variable then it is a wff.
If P is a propositional variable,then ~P is a wff.
If P and Q are two wffs then,(A and B),(A or B),(A implies B),(A is equivalent to B) are all wffs.

why the order of quantifiers are important? how the order is determined?

I want to know why the order of quantifiers are important in a logic formula?
When I read books about logic programming, such points are mentioned, but did not say why.
Is there any one could explain with some examples?
Also, how can we determine order of quantifiers from a given logic formula?
Thanks in advance!
You would be well advised to read a book about first-order logic before the books about
logic programming.
Consider the true statement:
1. Everybody has a mother
Let's formalize it in FOL. To keep it simple, we'll say
that the universe of discourse is the set of people, i.e.
our individual variables x, y, z... range over people. Then
1 becomes:
1F. (x)(Ey)Mother(y,x)
which we can read as: For every person x there exists
some person y such that y is the mother of x.
Now let's swap the order of the universal quantifier (x) and existential
quantifier (Ey):
2F. (Ey)(x)Mother(y,x)
That reads: There is some person y such that for every person x,
y is the mother of x. Or in plain English:
2. There is somebody who is the mother of everybody
You see that swapping the quantifiers changes the meaning of the statement,
taking us from the true statement 1 to the false statement 2. Indeed, to the absurdly false statement
2, which entails that somebody is their own mother.
That's why the order of quantifiers matters.
how can we determine order of quantifiers from a given logic formula?
Well, in 1F and 2F, for example, all the variables are already bound by quantifiers,
so there's nothing to determine. The order of the quantifiers is what you see,
left to right.
Suppose one of the variables was free (not bound), e.g.
3F. (Ey)Mother(y,x)
You might read that as: There is someone who is the mother of x, for variable person x.
But this formula really doesn't express any statement. It expresses a unary predicate of persons, the predicate Someone is the mother of x. If you free up the remaining variable:
4F. Mother(x,y)
then you have the binary predicate, or relation: x is the mother of y.
A formula with 1,2,...,n free variables expresses a unary, binary,...,n-ary predicate.
Given a predicate, you can make a statement by binding free variables with quantifiers and/or substituting individual constants for the free variables. From 4F you can make:
(x)(y)Mother(x,y) (Everybody is everybody's mother)
(Ex)(y)Mother(x,y) (Somebody is everybody's mother)
(Ex)(Ey)Mother(x,y) (Somebody is somebody's mother)
(x)Mother(x,Arnold) (Everybody is the mother of Arnold)
(x)Mother(Bernice,x) (Bernice is the mother of everybody)
Mother(Arnold,Bernice) (Arnold is the mother of Bernice)
...
...
and so on ad nauseam.
What this should make clear is that if a formula has free variables, and therefore expresses
a predicate, the formula as such does not imply any particular way of quantifying
the free variables, or that they should be quantified at all.

Flattening quantification over relations

I have a Relation f defined as f: A -> B × C. I would like to write a firsr-order formula to constrain this relation to be a bijective function from A to B × C?
To be more precise, I would like the first order counter part of the following formula (actually conjunction of the three):
∀a: A, ∃! bc : B × C, f(a)=bc -- f is function
∀a1,a2: A, f(a1)=f(a2) → a1=a2 -- f is injective
∀(b, c) : B × C, ∃ a : A, f(a)=bc -- f is surjective
As you see the above formulae are in Higher Order Logic as I quantified over the relations. What is the first-order logic equivalent of these formulae if it is ever possible?
PS:
This is more general (math) question, rather than being more specific to any theorem prover, but for getting help from these communities --as I think there are mature understanding of mathematics in these communities-- I put the theorem provers tag on this question.
(Update: Someone's unhappy with my answer, and SO gets me fired up in general, so I say what I want here, and will probably delete it later, I suppose.
I understand that SO is not a place for debates and soapboxes. On the other hand, the OP, qartal, whom I assume is the unhappy one, wants to apply the answer from math.stackexchange.com, where ZFC sets dominates, to a question here which is tagged, at this moment, with isabelle and logic.
First, notation is important, and sloppy notation can result in a question that's ambiguous to the point of being meaningless.
Second, having a B.S. in math, I have full appreciation for the logic of ZFC sets, so I have full appreciation for math.stackexchange.com.
I make the argument here that the answer given on math.stackexchange.com, linked to below, is wrong in the context of Isabelle/HOL. (First hmmm, me making claims under ill-defined circumstances can be annoying to people.)
If I'm wrong, and someone teaches me something, the situation here will be redeemed.
The answerer says this:
First of all in logic B x C is just another set.
There's not just one logic. My immediate reaction when I see the symbol x is to think of a type, not a set. Consider this, which kind of looks like your f: A -> BxC:
definition foo :: "nat => int × real" where "foo x = (x,x)"
I guess I should be prolific in going back and forth between sets and types, and reading minds, but I did learn something by entering this term:
term "B × C" (* shows it's of type "('a × 'b) set" *)
Feeling paranoid, I did this to see if had fallen into a major gotcha:
term "f : A -> B × C"
It gives a syntax error. Here I am, getting all pedantic, and our discussion is ill-defined because the notation is ill-defined.
The crux: the formula in the other answer is not first-order in this context
(Another hmmm, after writing what I say below, I'm full circle. Saying things about stuff when the context of the stuff is ill-defined.)
Context is everything. The context of the other site is generally ZFC sets. Here, it's HOL. That answerer says to assume these for his formula, wich I give below:
Ax is true iff x∈A
Bx is true iff x∈B×C
Rxy is true iff f(x)=y
Syntax. No one has defined it here, but the tag here is isabelle, so I take it to mean that I can substitute the left-hand side of the iff for the right-hand side.
Also, the expression x ∈ A is what would be in the formula in a typical set theory textbook, not Rxy. Therefore, for the answerer's formula to have meaning, I can rightfully insert f(x) = y into it.
This then is why I did a lot of hedging in my first answer. The variable f cannot be in the formula. If it's in the formula, then it's a free variable which is implicitly quantified. Here's the formula in Isar syntax:
term "∀x. (Ax --> (∃y. By ∧ Rxy ∧ (∀z. (Bz ∧ Rxz) --> y = z)))"
Here it is with the substitutions:
∀x. (x∈A --> (∃y. y∈B×C ∧ f(x)=y ∧ (∀z. (z∈B×C ∧ f(x)=z) --> y = z)))
In HOL, f(x) = f x, and so f is implicitly, universally quantified. If this is the case, then it's not first-order.
Really, I should dig deep to recall what I was taught, that f(x)=y means:
(x,f(x)) = (x,y) which means we have to have (x,y)∈(A, B×C)
which finally gets me:
∀x. (x∈A -->
(∃y. y∈B×C ∧ (x,y)∈(A,B×C) ∧ (∀z. (z∈B×C ∧ (x,z)∈(A,B×C)) --> y = z)))
Finally, I guess it turns out that in the context of math.stackexchange.com, it's 100% on.
Am I the only one who feels compulsive about questioning what this means in the context of Isabelle/HOL? I don't accept that everything here is defined well enough to show that it's first order.
Really, qartal, your notation should be specific to a particular logic.
First answer
With Isabelle, I answer the question based on my interpretation of your
f: A -> B x C, which I take as a ZFC set, in particular a subset of the
Cartesian product A x (B x C)
You're sort of mixing notation from the two logics, that of ZFC
sets and that of HOL. Consequently, I might be off on what I think you're
asking.
You don't define your relation, so I keep things simple.
I define a simple ZFC function, and prove the first
part of your first condition, that f is a function. The second part would be
proving uniqueness. It can be seen that f satisfies that, so once a
formula for uniqueness is stated correctly, auto might easily prove it.
Please notice that the
theorem is a first-order formula. The characters ! and ? are ASCII
equivalents for \<forall> and \<exists>.
(Clarifications must abound when
working with HOL. It's first-order logic if the variables are atomic. In this
case, the type of variables are numeral. The basic concept is there. That
I'm wrong in some detail is highly likely.)
definition "A = {1,2}"
definition "B = A"
definition "C = A"
definition "f = {(1,(1,1)), (2,(1,1))}"
theorem
"!a. a \<in> A --> (? z. z \<in> (B × C) & (a,z) \<in> f)"
by(auto simp add: A_def B_def C_def f_def)
(To completely give you an example of what you asked for, I would have to redefine my function so its bijective. Little examples can take a ton of work.)
That's the basic idea, and the rest of proving that f is a function will
follow that basic pattern.
If there's a problem, it's that your f is a ZFC set function/relation, and
the logical infrastructure of Isabelle/HOL is set up for functions as a type.
Functions as ordered pairs, ZFC style, can be formalized in Isabelle/HOL, but
it hasn't been done in a reasonably complete way.
Generalizing it all is where the work would be. For a particular relation, as
I defined above, I can limit myself to first-order formulas, if I ignore that
the foundation, Isabelle/HOL, is, of course, higher-order logic.

First-order predicate calculus, am I doing this right?

This is the statement:
All birds can fly except for penguins and ostriches or unless they
have a broken wing.
Here is my attempt:
∀x birds(x)→ fly(x)^((birds(x, penguins)^birds(x,
ostriches))˅broken(wing)→¬fly(x))
is my attempt correct?
how do we present "except" in predicate logic?
thanks
On understanding "except" ...
When we say "A except B" we normally mean that A and B are mutually exclusive. Either A is the case or B is the case but not both.
If you think in terms of sets then
All birds can fly except for penguins and ostriches or unless they have a broken wing
could be re-written as
In the universe of birds, there are exactly two distinct sets -- one in which every member of the set can fly and the other in which you find penguins and ostriches and birds with broken wings.
(In passing, note the way the words "and" and "or" in English often need to be adjusted in a symbolic expression.)
Birds
+-----------+------------+
| | |
| Fly | Exceptions |
| | |
+-----------+------------+
Representing mutual exclusion in predicate logic is most easily handled by exclusive-or (XOR). We want to say fly XOR exceptions.
In systems that allow quantifiers to limit the universe of discourse, we could write:
∀x∊birds (fly(x) XOR (penguin(x) v ostrich(x) v brokenWing(x)))
If quantifiers are unlimited, then:
∀x (bird(x) → (fly(x) XOR (penguin(x) v ostrich(x) v brokenWing(x))))
And if XOR is not in the set of allowed operators, then you might have to use the equivalence:
p XOR q ≡ ((p v q) & -(p & q))
There are a couple of other implications hiding in the English sentence that are not fully expressed in the suggestions above.
The sentence in predicate logic allows the case that there are
no birds, whereas the English sentence probably implies that there is
at least one bird.
"A except B" in English normally implies that there are at
least some instances of the exception. Not only is there at least one
bird, but there is at least one penguin that cannot fly. That could
be added to the predicate sentence via appropriate use of existential
quantifiers.
"A except B" in English nearly always
implies that A is the most common case and B is the exception. In the
absence of other evidence, we would assume A. In the universe of
birds, most can fly and only the listed exceptions cannot fly. There
is no easy construct in predicate logic to capture the sense of a
majority case.
No, your attempt is incorrect. It says that all birds fly and also some birds don't fly, so it's a contradiction. Also note that broken(wing) doesn't mention x at all.
As a hint, it should look like
∀x (bird(x) ^ ¬<conditions under which birds don't fly>) → fly(x)
There is a "prolog" tag to your question. In Prolog it can be:
fly(X, WingCondition) :-
bird(X),
X \= penguin,
X \= ostrich,
WingCondition \= broken.
So all birds and not birds that are penguins, ostriches and birds with broken wings can fly
∀x (birds(x) ^ ¬ (birds(x, penguins) ^ birds(x, ostriches) ^ broken_wing(x))) → fly(x))
or this maybe
∀x (birds(x) ^ ¬ (birds(x, penguins) ^ birds(x, ostriches) ^ birds(x,broken_wing))) → fly(x))

Herbrand universe and Least herbrand Model

I read the question asked in Herbrand universe, Herbrand Base and Herbrand Model of binary tree (prolog) and the answers given, but I have a slightly different question more like a confirmation and hopefully my confusion will be clarified.
Let P be a program such that we have the following facts and rule:
q(a, g(b)).
q(b, g(b)).
q(X, g(X)) :- q(X, g(g(g(X)))).
From the above program, the Herbrand Universe
Up = {a, b, g(a), g(b), q(a, g(a)), q(a, g(b)), q(b, g(a)), q(b, g(b)), g(g(a)), g(g(b))...e.t.c}
Herbrand base:
Bp = {q(s, t) | s, t E Up}
Now come to my question(forgive me for my ignorance), i included q(a, g(a)) as an element in my Herbrand Universe but from the fact, it states q(a, g(b)). Does that mean that q(a, g(a)) does not suppose to be there?
Also since the Herbrand models are subset of the Herbrand base, how do i determine the least Herbrand model by induction?
Note: I have done a lot of research on this, and some parts are well clear to me but still i have this doubt in me thats why i want to seek the communities opinion. Thank you.
From having the fact q(a,g(b)) you cannot conclude whether or not q(a,g(a)) is in the model. You will have to generate the model first.
For determining the model, start with the facts {q(a,g(b)), q(b,g(b))} and now try to apply your rules to extend it. In your case, however, there is no way to match the right-hand side of the rule q(X,g(X)) :- q(X,g(g(g(X)))). to above facts. Therefore, you are done.
Now imagine the rule
q(a,g(Y)) :- q(b,Y).
This rule could be used to extend our set. In fact, the instance
q(a,g(g(b))) :- q(b,g(b)).
is used: If q(b,g(b)) is present, conclude q(a,g(g(b))). Note that we are using here the rule right-to-left. So we obtain
{q(a,g(b)), q(b,g(b)), q(a,g(g(b)))}
thereby reaching a fixpoint.
Now take as another example you suggested the rule
q(X, g(g(g(X)))) :- q(X, g(X)).
Which permits (I will no longer show the instantiated rule) to generate in one step:
{q(a,g(b)), q(b,g(b)), q(a,g(g(g(b)))), q(b, g(g(g(b))))}
But this is not the end, since, again, the rule can be applied to produce even more! In fact, you have now an infinite model!
{g(a,gn+1(b)), g(b, gn+1(b))}
This right-to-left reading is often very helpful when you are trying to understand recursive rules in Prolog. The top-down reading (left-to-right) is often quite difficult, in particular, since you have to take into account backtracking and general unification.
Concerning your question:
"Also since the Herbrand models are subset of the Herbrand base, how do i determine the least Herbrand model by induction?"
If you have a set P of horn clauses, the definite program, then you can define
a program operator:
T_P(M) := { H S | S is ground substitution, (H :- B) in P and B S in M }
The least model is:
inf(P) := intersect { M | M |= P }
Please note that not all models of a definite program are fixpoints of the
program operator. For example the full herbrand model is always a model of
the program P, which shows that definite programs are always consistent, but
it is not necessarily a fixpoint.
On the other hand each fixpoint of the program operator is a model of the
definite program. Namely if you have T_P(M) = M, then one can conclude
M |= P. So that after some further mathematical reasoning(*) one finds that
the least fixpoint is also the least model:
lfp(T_P) = inf(P)
But we need some further considerations so that we can say that we can determine
the least model by a kind of computation. Namely one easily observes that the
program operator is contiguous, i.e. preserves infinite unions of chains, since
horn clauses do not have forall quantifiers in their body:
union_i T_P(M_i) = T_P(union_i M_i)
So that again after some further mathematical reasoning(*) one finds that we can
compute the least fixpoint via iteration, witch can be used for simple
induction. Every element of the least model has a simple derivation of finite
depth:
union_i T_P^i({}) = lpf(T_P)
Bye
(*)
Most likely you find further hints on the exact mathematical reasoning
needed in this book, but unfortunately I can't recall which sections
are relevant:
Foundations of Logic Programming, John Wylie Lloyd, 1984
http://www.amazon.de/Foundations-Programming-Computation-Artificial-Intelligence/dp/3642968287

Resources