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

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

Related

Translate English sentence into predicated wff

I have a school assignment that needs to translate the English sentence into predicate logic.
The question is "Every fruit that is an apple is not a mango."
The domain is the whole world, and M(x) means x is a mango, A(x) means x is an apple, F(x) means x is a fruit.
The answer I came up with is "(∀x)[F(x)∧(A(x)⟶[M(x)]′)] " But there is someone who answers it like below.
"(∀x)[F(x)⟶(A(x)⟶[M(x)]′)]"
Will the second answer be a valid translation for the sentence "Every fruit that is an apple is not a mango."?
Both are correct. You're essentially asking if:
A -> (B -> C)
is equivalent to:
(A /\ B) -> C
And if you tabulate the truth tables, you'll see that these two propositions are always equivalent.

Converting first-order logic to CNF without exponential blowup

When attempting to solve logic problems on a computer, it is usual to first convert them to CNF, because the best solving algorithms expect CNF as input.
For propositional logic, the textbook rules for this conversion are simple, but if you apply them as is, the result is one of the very rare cases where a program encounters double exponential resource consumption without being specifically constructed to do so:
a <=> (b <=> (c <=> ...))
with N variables, generates 2^2^N clauses, one exponential blowup in the conversion of equivalence to AND/OR, and another in the distribution of OR into AND.
The solution to this is to rename subterms. If we rewrite the above as something like
r <=> (c <=> ...)
a <=> (b <=> r)
where r is a fresh symbol that is being defined to be equal to a subterm - in general, we may need O(N) such symbols - the exponential blowups can be avoided.
Unfortunately, this runs into a problem when we try to extend it to first-order logic. Using TPTP notation where ? means 'there exists' and variables begin with capital letters, consider
a <=> ?[X]:p(X)
Admittedly this case is simple enough that there is no actual need to rename the subterm, but it's necessary to use a simple case for illustration, so suppose we are using an algorithm that just automatically renames arguments of the equivalence operator; the point generalizes to more complex cases.
If we try the above trick and rename the ? subterm, we get
r <=> ?[X]:p(X)
Existential variables are converted to Skolem symbols, so that ends up as
r <=> p(s)
The original formula then expands to
(~a | r) & (a | ~r)
Which is by construction equivalent to
(~a | p(s)) & (a | ~p(s))
But this is not correct! Suppose we had not done the renaming, but just expanded the original formula as it was, we would get
(~a | ?[X]:p(X)) & (a | ~?[X]:p(X))
(~a | ?[X]:p(X)) & (a | ![X]:~p(X))
(~a | p(s)) & (a | ~p(X))
which is critically different from the version we got with the renaming.
The problem is that equivalence needs both the positive and negative versions of each argument, but applying negation to terms that contain universal or existential quantifiers, structurally changes those terms; you cannot just encapsulate them in a definition, then apply the negation to the defined symbol.
The upshot of this is that when you have equivalence and the arguments may contain such quantifiers, you actually need to recur through each argument twice, once for the positive version, once for the negative. This suffices to bring back the existential blowup we hoped to avoid by doing the renaming. As far as I can see, this problem is not caused by the way a particular algorithm works, but by the nature of the task.
So my question:
Given an input formula that may contain arbitrary nesting of equivalence and quantifiers, is there any algorithm that will correctly turn this to CNF with a polynomial rather than exponential number of clauses?
As you observed, an existential such as ∃X.p(X) is not in fact equivalent to a Skolemized expression p(S). Its negation ¬∃X.p(X) is not equivalent to ¬p(S), but to ∀Y.¬p(Y).
Possible approaches that avoid the exponential blow-up:
Convert existentials such as ∃X.p(X) to universals such as ¬∀Y.p(Y), or vice versa, so you have a canonical form. Skolemize at a later step.
Remember when you convert that your p(S) is a Skolemized existential, and that its negation is ∀Y.¬p(Y).
Define terms equivalent to universals and existentials, such that a represents ∀Y.p(Y) and ¬a then represents ¬∀Y.p(Y), or equivalently, ∃X.¬p(X).
Use the symmetry of Boolean duals, so that the same transformations apply with AND and OR swapped, De Morgan’s Laws, and the equivalence between existentials and negated universals, to restore the symmetry between the expansions of r and ~r. The negations in the conversion between universals and existentials and in De Morgan's Laws cancel each other out, and the duality of switching AND and OR means you can re-use the result on the left to generate the one on the right mechanically again?
Given that you need to support ALL and NOT ALL statements anyway, this should not create any new problems. Just canonicalize and use the same approach you would for a universal.
If you’re solving by converting to SAT, your terms can represent universals, too. So, in your example, you’re trying to replace a with r, but you can still use ~a, equivalent to the negative universal.
In your expressions. you’d still use (~a | r) & (a | ~r), but expand ~r to its correct rather than the incorrect value. That example is trivial, since that’s just ~a, but you’d normally define r as equivalent to a more complex transformation, and in that case you need to remember what both r and ~r represent. It is not really a simple mechanical transformation of the Skolemized expression.
In this example, I’m not sure why it’s a problem that (~a | r) & (a | ~r) is equivalent to (~a | r) & (a | ~a), which simplifies to (~a | r). That’s not going to give you exponential blow-up? When you translate back to first-order predicate logic, make the correct translation.
Update
Thanks for clarifying what the problem was in chat. As I currently think I understand it, what you have is an equivalence with a left and a right side, which contains other nested equivalences, and you want to expand both the equivalence and its negation. The problem is that, because the negation does not have symmetrical form, you need to recurse twice for each nested equivalence in the tree, once when expanding the equivalence and once when expanding its negation?
You should define a transformation that generates the negative expansion from the positive expansion in linear time, and divide-and-conquer the expressions containing nested equivalences using that. This seems to be what you were after with the ~p(S) transformation.
To do this, you recall that ¬∃X.p(X) is equivalent to ∀X.¬p(X), and vice versa. Then if you’ve expanded p(x) into normal form as conjunctions and disjunctions, De Morgan’s Laws lets you turn an expression like ¬(a ∨ ¬b) into ¬a ∧ b. The inner ¬ on the quantifier transformation and the outer ¬ on the De Morgan transformation cancel each other out. Finally, the dual of any Boolean equivalence remains valid when you replace each ∨ and ∧ with the other and any atom a or ¬a with its inverse.
So, while I might be making an error, especially at 1 AM, it looks to me like what you want is the dual transformation that substitutes:
An outer ∃ for ∀ and vice versa
∧ for ∨ and vice versa
Each term t with ¬t and vice versa
Apply this to the expansion of the positive equivalence to generate the negative dual in time proportional to its length, without further recursion.

Translate sentence into FOL expression, confused about constants and quantifiers

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.

Prolog: Understanding logic flow

I was reading Learn Prolog Now! and I'm confused about their use of logic and I was hoping someone can clarify the ambiguity of arguments in rules.
For example, on Chapter 1, knowledge base 4 they reference the following rule:
loves(vincent,mia).
They then provide a query:
loves(marsellus,X), woman(X).
and then the make the English statement:
"Now, remember that , means "and", so this query says: is there any individual X such that Marsellus loves X and X is a woman ?"
The key word being, Marsellus loves X.
This is worded in a way that makes me think there is some "logic" tied to the arrangement of arguments, such as to say,
Is it true that loves(vincent,mia). "logically" means:
vincent loves mia?
BUT is it false that
mia loves vincent?
That's what I originally thought but then on Chapter 3, example 2: Descendant they have the following example of:
child(bridget,caroline).
Then the English statement: "That is, Caroline is a child of Bridget"
But if #1 above is true (vincent loves mia), then shouldn't this be read as Bridget is a child of Caroline?
Or does the order of arguments not matter and it's your additional programming that will determine the logic of the arguments?
loves(X, Y) intuitively would mean X loves Y but not Y loves X. But as a programmer, you could assume it's symmetrical. It just wouldn't be as intuitive. It just depends upon how you choose to define it. Prolog Now chose the most intuitive meaning, so loves(X, Y) means X loves Y, but not Y loves X.
Whether child(X, Y) means X is a child of Y or Y is a child of X is up to the programmer. child used by itself as the name of the fact/predicate in this context is a bit ambiguous here (it's not a verb and isn't part of a phrase) and you just have to roll with whatever the Prolog Now site chose as their meaning. When you view the functor as a verb, the arguments are interpreted left to right as expected. So, better, would be to use child_of(X, Y) to mean X is a child of Y so that it's clearer.
Prolog as a language wouldn't care whether you define love(X,Y) as X loves Y or Y loves X. It's probably just a convention that we tend to follow in first order logic.
As to why we'd choose the ordering convention we usually follow, It's probably because the predicate defines a relation between two terms. So the order would depend on how you define the relation.
A predicate r(a,b) means that (a,b) is in the relation r:A->B.
The way i would clear my doubts of the case you've given in the question is:
loves(a,?) ? should anything which a loves. And
child(a,?) ? should be anything which is a child of a.
It would depend on how you define the relation 'child'.
As far as i know ( which isn't far ), There's no hard rule in logic that stops you from defining predicates the way you want. You could define love(X,Y) as 'X loves Y' or 'X is loved by Y' as long as you're consistent.

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.

Resources