English to First order Logic - artificial-intelligence

I was doing one of the exercises from Artificial Intelligence modern Approach book.
Here was the question : Convert English to FOL
Politicians can fool some of the people all of the time, and they can fool all of the people
some of the time, but they can’t fool all of the people all of the time.
And, here is the answer given to it.
∀ x Politician(x) ⇒
(∃ y ∀ t Person(y) ∧ Fools(x, y, t)) ∧
(∃ t ∀ y Person(y) ⇒ Fools(x, y, t)) ∧
¬(∀ t ∀ y Person(y) ⇒ Fools(x, y, t))
My doubt is.
We normally use Implication with Universal Quantifier, but here they used
(∃ y ∀ t Person(y) ∧ Fools(x, y, t))
for this part of question - can fool some of the people all of the time
isn't this wrong?
But, in the second case
they can fool all of the people some of the time
they used implication.
I am confused for what should be the order for Existential and Universal Quantifiers.
Can someone clear my doubt?
Thank you.

We normally use Implication with Universal Quantifier
You have noticed a pattern, but it is not a rule, e.g.
There is always somebody worse off than yourself.
which your text book would formalize as:
∀t ∃x x is a person ∧ x is worse of than yourself at t
In a case like this, the conjunction that bothers you is necessitated
just by the fact that the implied Universe of Discourse (the range of
the variables) is all-encompassing - it is literally "everything" - so we're
obliged to state that x is a person, as well as being worse of than
yourself. In natural language the UoD is almost always
restricted by the context of speech, or by explicitly restricting pronouns,
such as somebody. It would be more natural in this case to restrict the UoD to
people and formalize simply as:
∀t ∃p p is worse of than yourself at t
Isn't this wrong?
You are referring to:
∃ y ∀ t Person(y) ∧ Fools(x, y, t)
Yes, it is wrong. This says:
There is something y such that, at any time t, y is a person and y is
fooled by x at t.
But when we say that a politician can fool some of the people all the time,
and all of the people some of the time, we don't actually mean there exists any
particular person who is perpetually fooled by our politician. Clearly,
we don't even mean to imply there is any particular fool whose life spans the whole political life of any given politician, and an artificial intelligence that drew that inference would be a flop. We actually mean that, all of the time, there are some people who are fooled by our politician, and some of the time, everybody is fooled by our politician. That is:
∀ t ∃ y Person(y) ∧ Fools(x, y, t)
and:
∃ t ∀ y Person(y) ⇒ Fools(x, y, t)
This example makes the important point that to formalize intelligently a statement
or argument expressed in a natural language you need to formalize what it means,
in its context, and not simply "what it looks like". x fools some of the people
all of the time looks like your text book's version:
∃ y ∀ t Person(y) ∧ Fools(x, y, t)
because "some" is mentioned before "all". But natural languages rate quanitificational
precision very low, and the mainstream of proficient English speakers do not think
this proverb means what the text book says. (I'm sure even the authors of the
book would agree, if it were brought to their notice.)
So you are right to be bothered by the ordering of existential and universal
quantifiers.
∀ y ∃ x F(x,y)
says:
For anything y, there is something x such that F(x,y)
and:
∃ x ∀ y F(x,y)
says:
There is something x such that, for anything y, F(x,y)
and they are not usually interchangeable. Compare (with UoD = people):
Everyone has a mother
∀ x ∃ y Mother(y,x)
and
∃ y ∀ x Mother(y,x)
Someone is the mother of everyone.

Related

How to decide whether this query in domain relational calculus is domain-independent?

I am trying to understand whether the following query is domain-independent:
{t : ∀x ∀y ( (x≠y ∧ R(t,x) ∧ T(t,y)) → S(x,y) )
I think that this query is domain-independent because the left side of → forces it to be in every domain. Is that so?
I guess → is intended as material implication.
Then we can convert the predicate in the given query, using Boolean algebra equivalences:
p → q == ¬p ∨ q -- so need to negate the LHS of implication
¬(p1 ∧ p2) == ¬p1 ∨ ¬p2 -- note the LHS of the given implication is a conjunction
¬(x ≠ y) == x = y
Then (omitting superfluous parens):
( (x≠y ∧ R(t,x) ∧ T(t,y)) → S(x,y) )
==
( x=y ∨ ¬R(t,x) ∨ ¬T(t,y) ∨ S(x,y) )
Observations:
The disjunct x=y is Domain Dependent: x, y are universally quantified, the equality test doesn't require them to be drawn from any relation.
The disjuncts ¬R(t,x) and ¬T(t,y) are negations of relation membership, so are Domain Dependent.
S(x,y) is a relation membership, so is Domain Independent -- but since it's only one of the disjuncts, it doesn't rescue the overall query.
Conclusion: the query overall is Domain Dependent.
(I can't tell what "forces it [what?] to be in every domain" is trying to say.)
At that link to Boolean Algebra, note what it says about Material Implication aka Material Conditional (I've changed the variable names to reflect the workings here.):
But if p is false, then the value of q can be ignored;
In other words, if the LHS expression is false, membership in S(x,y) can be ignored, so S(x,y) fails to constrain x,y. Then that t appears only in R(t,x) and T(t,y) is no help in constraining t: both those appearances are on LHS of the implication.
Edit: 'fails to constrain' here means fails to limit x,y or t to range over values appearing in tuples in ground relations.

BCNF and 4NF property

I read a statement "Relation R in BCNF with at-least one simple candidate key is also in 4NF"
I don't think that it is always true but I am not able to prove it.
Can someone please help ?
The statement is true and this is the sketch of the proof taken from the paper "Simple Conditions for Guaranteeing Higher Normal Forms in Relational Databases", by C.J.Date and R.Fagin, ACM TODS, Vol.17, No. 3, Sep. 1992.
A relation is in 4NF if, for every nontrivial multivalued dependency X →→ Y in F+, X is a superkey for R. So, if a relation is in BCNF, but not in 4NF, then there must exists a nontrivial multivalued dependency (MVD) X →→ Y such that X is not the key. We will show that this is in contradiction with the fact that the relation is in BCNF and has a candidate key K constituted by a unique attribute (simple candidate key).
Consider the fact that, in a relation R(T), when we have a nontrivial MVD X →→ Y, (assuming, without loss of generality that X and Y are disjoint), then also the MVD dependency X →→ Z must hold in the same relation, with Z = T - X - Y (that is Z are all the other attributes of the relation). We can now prove that each candidate key must contain at least an attribute of Z and an attribute of Y (so it must contain at least 2 attributes!).
Since we have X →→ Y and X →→ Z, and X is not a candidate key, assume that the hypothesis is false, that is that there is a candidate K which does not contain a member of Y (and for symmetry, neither a member of Z). But, since K is a key, we have that K → Y, with K and Y disjoint.
Now, there is an inference rule that says that, in general, if V →→ W and U → W, where U and W are disjoint, then V → W.
Applying this rule to our case, since X →→ Y, and K → Y, we can say that X → Y. But this is a contradiction, since we have said that R is in BCNF, and X is not a candidate key.
In other words, if a relation is not in 4NF, than each key must have at least 2 attributes.
And given the initial hypothesis, that we have a relation in BCNF with at least a simple candidate key, for the previous lemma, the relation must be in 4NF (otherwise every key should be constituted by at least 2 attributes!).

Multi-Valued Dependencies?

I am having some trouble understanding Multi-Valued Dependencies. The definition being: A multivalued dependency exists when there are at least 3 attributes (like X,Y and Z) in a relation and for value of X there is a well defined set of values of Y and a well defined set of values of Z. However, the set of values of Y is independent of set Z and vice versa.
Suppose we have a relation R(A,B,C,D,E) that satisfies the MVD's
A →→ B and B →→ D
How does MVD play into A->B and B->D here? Honestly I'm not sure I really understand the definition after looking at example problems.
If R contains the tuples (0,1,2,3,4) and (0,5,6,7,8), what other tuples must
necessarily be in R? Identify one such tuple in the list below.
a) (0,5,2,3,8)
b) (0,5,6,3,8)
c) (0,5,6,7,4)
d) (0,1,6,3,4)
I would have thought AB is 0,1 and 0,5 and BD is 1,3 and 5,7. None of the answers have 0,1,3,5,7.
MVDs (multi-valued dependencies) have nothing to do with "at least 3 attributes". (You seem to be quoting the Wikipedia article but that informal definition is partly wrong and partly unintelligible.) You need to read and think through a clear, precise and correct definition. (Which you were probably given.)
MVD X ↠ Y mentions two subsets of the set S of all attributes, X & Y. There are lots of ways to define when a MVD holds in a relation but the simplest to state & envisage is probably that the two projections XY and X(S-Y) join to the original relation. Which also mentions a third subset, S-Y. Which is what the (binary) JD (join dependency) {XY, X(S-Y)} says.
Wikipedia (although that article is a mess):
A decomposition of R into (X, Y) and (X, R−Y) is a lossless-join decomposition if and only if X ↠ Y holds in R.
From this answer:
MVDs always come in pairs. Suppose MVD X ↠ Y holds in a relation with attributes S, normalized to components XY & X(S-Y). Notice that S-XY is the set of non-X non-Y attributes, and X(S-Y) = X(S-XY). Then there is also an MVD X ↠ S-XY, normalized to components X(S-XY) & X(S-(S-XY)), ie X(S-XY) & XY, ie X(S-Y) & XY. Why? Notice that both MVDs give the same component pair. Ie both MVDs describe the same condition, that S = XY JOIN X(S-XY). So when an MVD holds, that partner holds too. We can write the condition expressed by each of the MVDs using the special explicit & symmetrical notation X ↠ Y | S-XY.
For R =
A,B,C,D,E
0,1,2,3,4
0,5,6,7,8
...
A ↠ B tells us that the following join to R:
A,B A,C,D,E
0,1 0,2,3,4
0,5 0,6,7,8
... ...
so R has at least
A,B,C,D,E
0,1,2,3,4
0,1,6,7,8
0,5,2,3,4
0,5,6,7,8
of which two are given and two are new but not choices.
B ↠ D tells us that the following join to R:
B,D A,B,C,E
1,3 0,1,2,4
5,7 0,5,6,8
... ...
so R has at least
A,B,C,D,E
0,1,2,3,4
0,5,6,7,8
which we already know.
So we don't yet know whether any of the choices are in R. But we do now know R is
A,B,C,D,E
0,1,2,3,4
0,1,6,7,8
0,5,2,3,4
0,5,6,7,8
...
Repeating, A ↠ B adds no new tuples but B ↠ D now gives this join:
B,D A,B,C,E
1,3 0,1,2,4
1,7 0,1,6,8
5,3 0,5,2,4
5,7 0,5,6,8
... ...
And one of the tuples in that join is choice b) (0,5,6,3,8).
The way the question is phrased, they are probably expecting you to use a definition that they will have given you that is like another two in Wikipedia. One says that α ↠ β holds in R when
[...] if we denote by (x, y, z) the tuple having values for α, β, R − α − β collectively equal to x, y, z, then whenever the tuples (a, b, c) and (a, d, e) exist in r, the tuples (a, b, e) and (a, d, c) should also exist in r.
(The only sense in which this gives the "formal" definition "in more simple words" is that this is also a definition. Because this isn't actually paraphrasing it, because this uses R − α − β whereas it uses R − β.)
By applying this rule to repeatedly generate further tuples for R starting from the given ones, we end up generating b) (0,5,6,3,8) much as we did above.
PS I would normally suggest that you review the (unsound) reasoning that led you to expect "AB is 0,1 and 0,5 and BD is 1,3 and 5,7" (whatever that means) or "0,1,3,5,7". But the "definition" you give (from Wikipedia) doesn't make any sense. So I suggest that you consider what you were doing with it.

What does the perm_invK lemma in Ssreflect prove?

The following code is from perm.v in the Ssreflect Coq library.
I want to know what this result is.
Lemma perm_invK s : cancel (fun x => iinv (perm_onto s x)) s.
Proof. by move=> x /=; rewrite f_iinv. Qed.
Definitions in Ssreflect can involve lots of concepts, and sometimes it is hard to understand what is actually going on. Let's analyze this by parts.
iinv (defined in fintype.v) has type
iinv : forall (T : finType) (T' : eqType) (f : T -> T')
(A : pred T) (y : T'),
y \in [seq f x | x in A] -> T
What this does is to invert any function f : T -> T' whose restriction to a subdomain A \subset T is surjective on T'. Put in other words, if you give me an y that is in the list of results of applying f to all elements of A, then I can find you an x \in A such that f x = y. Notice that this relies crucially on the fact that T is a finite type and that T' has decidable equality. The correctness of iinv is stated in lemma f_iinv, which is used above.
perm_onto has type codom s =i predT, where s is some permutation defined on a finite type T. This is saying, as its name implies, that s is surjective (which is obvious, since it is injective, by the definition of permutations in perm.v, and by the fact that the domain and codomain are the same). Thus, fun x => iinv (perm_onto s x) is a function that maps an element x to an element y such that s y = x. In other words, its the inverse of s. perm_invK is simply stating that this function is indeed the inverse (to be more precise, it is saying that it is the left inverse of s).
The definition that is actually useful, however, is perm_inv, which appears right below. What it does is that it packages fun x => iinv (perm_onto s x) with its proof of correctness perm_invK to define an element of perm_inv s of type {perm T} such that perm_inv s * s = s * perm_inv s = 1. Thus, you can view it as saying that the type {perm T} is closed under inverses, which allows you to use a lot of the ssr machinery for e.g. finite groups and monoids.

What's a good way to store this relation so I can answer queries of this form efficiently?

Excuse me if I get a little mathy for a second:
I have two sets, X and Y, and a many-to-many relation ℜ ⊆ X✗Y.
For all x ∈ X, let xℜ = { y | (x,y) ∈ ℜ } ⊆ Y, the subset of Y associated with x by ℜ.
For all y ∈ Y, let ℜy = { x | (x,y) ∈ ℜ } ⊆ X, the subset of X associated with y by ℜ.
Define a query as a set of subsets of Y, Q ⊆ ℘(Y).
Let the image of the query be the union of the subsets in Q:image(Q) = Uq∈Q q
Say an element of X x satisifies a query Q if for all q ∈ Q, q ∩ xℜ ≠ ∅, that is if all subsets in Q overlap with the subset of Y associated with x.
Define evidence of satisfaction of an element x of a query Q such that:evidence(x,Q) = xℜ ∩ image(Q)
That is, the parts of Y that are associated with x and were used to match some part of Q. This could be used to verify whether x satisfies Q.
My question is how should I store my relation ℜ so that I can efficiently report which x∈X satisfy queries, and preferably report evidence of satisfaction?
The relation isn't overly huge, as csv it's only about 6GB. I've got a couple ideas, neither of which I'm particularly happy with:
I could store { (x, xℜ) | ∀ x∈X } just in a flat file, then do O(|X||Q||Y|) work checking each x to see if it satisfies the query. This could be parallelized, but feels wrong.
I could store ℜ in a DB table indexed on Y, retrieve { (y, ℜy) | ∀ y∈image(Q) }, then invert it to get { (x, evidence(x,Q)) | ∀ x s.t. evidence(x,Q) ≠ ∅ }, then check just that to find the x that satisfy Q and the evidence. This seems a little better, but I feel like inverting it myself might be doing something I could ask my RDBMS to do.
How could I be doing this better?
I think #2 is the way to go. Also, if Q can be represented in CNF you can use several queries plus INTERSECT to get the RDBMS to do some of the heavy lifting. (Similarly with DNF and UNION.)
This also looks a bit a you want a "inverse index", which some RDBMS have support for. X = set of documents, Y = set of words, q = set of words matching the glob "a*c".
HTH

Resources