CS 1502 Formal Methods in Computer Science
-
Upload
brianna-meyer -
Category
Documents
-
view
33 -
download
1
description
Transcript of CS 1502 Formal Methods in Computer Science
![Page 1: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/1.jpg)
11
CS 1502 Formal Methods in CS 1502 Formal Methods in Computer ScienceComputer Science
Lecture Notes 12Lecture Notes 12
Variables and QuantifiersVariables and Quantifiers
![Page 2: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/2.jpg)
22
VariablesVariables
A A variablevariable is a placeholder for a name in a is a placeholder for a name in a sentencesentence
FOL gives us an infinite number of FOL gives us an infinite number of variablesvariables
Tarski’s World/Fitch/Boole gives us only Tarski’s World/Fitch/Boole gives us only uu, , vv, , ww, , xx, , yy, and , and zz as variables as variables
![Page 3: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/3.jpg)
33
Atomic wffsAtomic wffs
Cube(b)Cube(b)
Cube(x)Cube(x)
LeftOf(c,y)LeftOf(c,y)
Between(z,b,d)Between(z,b,d)
Larger(x,y)Larger(x,y)
![Page 4: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/4.jpg)
44
VariablesVariables
Cube(b) Cube(b) Cube(d) Cube(d) The truth of this sentence is determined by the truth-The truth of this sentence is determined by the truth-
values of Cube(b) and Cube(d) values of Cube(b) and Cube(d) ..
Cube(x) Cube(x) Cube(d) Cube(d) Cube(x) is neither true nor false, since x is a Cube(x) is neither true nor false, since x is a placeholder for the name of an object. x is said to be placeholder for the name of an object. x is said to be
free or unbound. free or unbound.
sentence
not asentence
![Page 5: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/5.jpg)
55
Forming wffForming wff
If If PP is wff then so is is wff then so is PP..
If If PP11, P, P22, … , P, … , Pnn are wffs then so is are wffs then so is (P(P1 1 P P2 2 … … P Pnn).).
If If PP11, P, P22, … , P, … , Pnn are wffs then so is are wffs then so is (P(P1 1 P P2 2 … … P Pnn).).
If If PP and and QQ are wffs, so is are wffs, so is (P (P Q). Q).
If If PP and and QQ are wffs, so is are wffs, so is (P (P Q). Q).
If If P P is a wff and is a wff and vv is a variable, then is a variable, then v v PP is a wff. Every is a wff. Every occurrence of occurrence of vv is said to be is said to be bound.bound.
If If P P is a wff and is a wff and vv is a variable, then is a variable, then v v PP is a wff. Every is a wff. Every occurrence of occurrence of vv is said to be bound. is said to be bound.
![Page 6: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/6.jpg)
66
SentencesSentences
A sentence is a A sentence is a well-formed formulawell-formed formula with with no unbound (free) variables.no unbound (free) variables.
The The scopescope of a quantifier is defined as of a quantifier is defined as those variables that fall under the those variables that fall under the quantifier’s influence quantifier’s influence as indicated by the as indicated by the enclosing parentheses.enclosing parentheses.
![Page 7: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/7.jpg)
77
Which are Sentences?Which are Sentences?
x LeftOf(x, x LeftOf(x, yy))
x (Cube(x) x (Cube(x) Large( Large(xx))))
x (Small(x) x (Small(x) Tet( Tet(yy))))
x (Cube(c) x (Cube(c) SameRow(x, c)) SameRow(x, c))
![Page 8: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/8.jpg)
88
Satisfaction Satisfaction (diff meaning!)(diff meaning!) of a wff of a wff
Let Let S(x)S(x) be a wff with free variable be a wff with free variable xx. . Object Object b b is said to satisfy is said to satisfy S(x)S(x) if and only if if and only if S(b)S(b) is a true sentence. EG, is a true sentence. EG, b b satisfies satisfies Cube(x).Cube(x).
![Page 9: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/9.jpg)
99
Semantics of QuantifiersSemantics of Quantifiers
x S(x) is true if and only if there is at least x S(x) is true if and only if there is at least one object that satisfies S(x). one object that satisfies S(x).
x S(x) is true if and only if every object x S(x) is true if and only if every object satisfies S(x).satisfies S(x).
The truth-value is determined withrespect to a domain of discourse
(or world, or universe)
![Page 10: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/10.jpg)
1010
ExampleExample
Universe = {2, 5, 17, 93, 67}Universe = {2, 5, 17, 93, 67}
x Prime(x)
x RightmostDigitIsPrime(x)
x Prime(x)
x RightmostDigitIsPrime(x)
![Page 11: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/11.jpg)
1111
Some Tetrahedron is to the left of c.
a is to the left of every Cube.
Some Cube is to the left of c.
Every Cube is in back of c.
C is supposed to be back one square – as it is on the next slide
![Page 12: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/12.jpg)
1212
![Page 13: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/13.jpg)
1313
Aristotelian FormsAristotelian Forms
All P’s are Q’sAll P’s are Q’s
x [P(x) Q(x)]
Q
+ P
![Page 14: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/14.jpg)
1414
Aristotelian FormsAristotelian Forms
Some P’s are Q’sSome P’s are Q’s
x [P(x) Q(x)]
Q P +
![Page 15: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/15.jpg)
1515
Aristotelian FormsAristotelian Forms
No P’s are Q’sNo P’s are Q’s
x [P(x) Q(x)]
Q
+ P
![Page 16: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/16.jpg)
1616
Aristotelian FormsAristotelian Forms
Some P’s are not Q’sSome P’s are not Q’s
x [P(x) Q(x)]
Q+ P
![Page 17: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/17.jpg)
1717
TranslationTranslation
x (Tet(x) x (Tet(x) LeftOf(x, c)) LeftOf(x, c))
x (Tet(x) x (Tet(x) Large(x) Large(x) LeftOf(x, c)) LeftOf(x, c))
x [Cube(x) x [Cube(x) BackOf(x, c)] BackOf(x, c)]
x [(Small(x) x [(Small(x) Cube(x)) Cube(x)) BackOf(x, c)] BackOf(x, c)]
Some Tet is to the left of c.
Every cube is in back of c.
Some large Tet is to the left of c.
Every small cube is in back of c.
![Page 18: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/18.jpg)
1818
TranslationTranslation
all x (Student(x) all x (Student(x) Smart(x)). Smart(x)).
““Every student is smart.’’Every student is smart.’’
““Pick anything at all. Either it’s not a Pick anything at all. Either it’s not a student or it’s smart (or both!)” student or it’s smart (or both!)”
““Pick anything at all. It cannot be a Pick anything at all. It cannot be a student who is not smart.”student who is not smart.”
““Pick anything at all. If it’s a student, it’s Pick anything at all. If it’s a student, it’s smart.” smart.”
![Page 19: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/19.jpg)
1919
What’s wrong with this What’s wrong with this translation?translation?
““Every student is smart”Every student is smart”
Bad translation:Bad translation:
all x (Student(x) ^ Smart(x))all x (Student(x) ^ Smart(x))
Good translation:Good translation:
all x (Student(x) all x (Student(x) Smart(x)) Smart(x))
![Page 20: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/20.jpg)
2020
What’s wrong with this What’s wrong with this translation?translation?
““Some student is smart”Some student is smart”
Bad translation:Bad translation:
exists x (student(x) exists x (student(x) smart(x)) smart(x))
Good translation:Good translation:
exists x (student(x) ^ smart(x))exists x (student(x) ^ smart(x))
![Page 21: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/21.jpg)
2121
TranslationTranslation
x and x and
x and x and
![Page 22: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/22.jpg)
2222
Quantifiers and FunctionsQuantifiers and Functions
Everyone is taller than Max’s father.Everyone is taller than Max’s father.
Someone’s father is taller than Max.Someone’s father is taller than Max.
e is the leftmost object in the row of e is the leftmost object in the row of something.something.
x (Person(x) ^ ~(x = father(max))) Taller(x, father(max))
x (Person(x) ^ Taller(father(x), Max))
x (lm(x) = e)
![Page 23: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/23.jpg)
2323
Quantifiers can make things interestingQuantifiers can make things interesting……
Which are valid?Which are valid? 1. all x (Student(x) Smart(x))2. all x (Student(x))
3. all x (Smart(x))
1. all x (Student(x))2. all x (Smart(x))
3. all x (Student(x) ^ Smart(x))
1. exist x (Student(x) Smart(x))2. exist x (Student(x))
3. exist x (Smart(x))
1. exist x (Student(x))2. exist x (Smart(x))
3. exist x (Student(x) ^ Smart(x))
Yup!
Nope!
Yup!
Nope!
![Page 24: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/24.jpg)
2424
Quantifiers and TautologyQuantifiers and Tautology
When is a sentence involving quantifiers a When is a sentence involving quantifiers a tautology?tautology?
Example: Example: x Cube(x) x Cube(x) x x Cube(x)Cube(x)
Example: Example: x Small(x) x Small(x) x Small(x)x Small(x)
No!
Yes!
![Page 25: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/25.jpg)
2525
Tautologies and QuantifiersTautologies and Quantifiers
One way to arrive at tautologies is to One way to arrive at tautologies is to substitute complex sentences into known substitute complex sentences into known tautologiestautologies
P v ~PP v ~P is a tautology. Thus, so is: is a tautology. Thus, so is:
(all x (Doctor(x) (all x (Doctor(x) Rich(x))) v Rich(x))) v
~(all x (Doctor(x) ~(all x (Doctor(x) Rich(x))) Rich(x)))
![Page 26: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/26.jpg)
2626
Truth-Functional Form AlgorithmTruth-Functional Form Algorithm
Start at the beginning of sentence S and Start at the beginning of sentence S and proceed to the right. proceed to the right. If you encounter a If you encounter a quantifier, underline thequantifier, underline the quantifier and the stuff quantifier and the stuff in its scope.in its scope. If you encounter anIf you encounter an atomic atomic sentence simply underline it.sentence simply underline it. When you come to When you come to the end of an underline assign a letter (A, B, C, the end of an underline assign a letter (A, B, C, …). …). If anIf an underlined sentence is identical to a underlined sentence is identical to a previous one (character for character), use the previous one (character for character), use the samesame letter.letter. If the sentence formed from the If the sentence formed from the letters is a tautology, then the original is too.letters is a tautology, then the original is too.
Note: Note: Small(a)Small(a) is not the same as is not the same as Small(b).Small(b). Similarly, Similarly, Small(x)Small(x) is not the same as is not the same as Small(y).Small(y).
![Page 27: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/27.jpg)
2727
When is a sentence a When is a sentence a tautology?tautology?
A quantified sentence S is a tautology if and A quantified sentence S is a tautology if and only if its truth-functional form is a tautology.only if its truth-functional form is a tautology.
Example:Example:
(exist y (P(y) v R(y)) (exist y (P(y) v R(y)) all x (P(x) ^ Q(x))) all x (P(x) ^ Q(x))) (~all x (P(x) ^ Q(x)) (~all x (P(x) ^ Q(x)) ~exist y (P(y) v R(y))) ~exist y (P(y) v R(y)))
TFF: (A B) (~B ~A) Tautology? Yes
![Page 28: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/28.jpg)
2828
Another ExampleAnother Example
x Cube(x) x Cube(x) x x Cube(x)Cube(x)
A B
Since A B is not a tautology, then neither is the sentence above.
![Page 29: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/29.jpg)
2929
Another ExampleAnother Example
x Cube(x) x Cube(x) [[x Cube(x)]x Cube(x)]
A A
Since A A is a tautology, then so is the sentence above.
![Page 30: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/30.jpg)
3030
Another ExampleAnother Example
(Tet(d) (Tet(d) x Small(x)) x Small(x)) ( (Tet(d) Tet(d) y Small(y)) y Small(y))
A B A C
(A B) (A C)
![Page 31: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/31.jpg)
3131
![Page 32: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/32.jpg)
3232
Tautological Valid?Tautological Valid?
Is the following argument valid or invalid?Is the following argument valid or invalid?
x Cube(x)x Small(x)x (Cube(x) Small(x))
Not tautologically valid!!!In fact, it is not logically valid.
ABC
![Page 33: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/33.jpg)
3333
Tautological Valid?Tautological Valid?
Is the following argument valid or invalid?Is the following argument valid or invalid?
x Cube(x) x Small(x) x Cube(x) x Small(x)
Is tautologically valid!!!A BAB
![Page 34: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/34.jpg)
3434
NoteNote
An argument that is not tautologically valid An argument that is not tautologically valid may still be logically valid. In this case, we may still be logically valid. In this case, we cannot recognize it is valid by checking all cannot recognize it is valid by checking all the rows of the truth table.the rows of the truth table.
![Page 35: CS 1502 Formal Methods in Computer Science](https://reader036.fdocuments.us/reader036/viewer/2022062321/56813054550346895d960638/html5/thumbnails/35.jpg)
3535
Tautological Valid?Tautological Valid?
Is the following argument valid or invalid?Is the following argument valid or invalid?
x [Cube(x) Small(x)]x Cube(x) x Small(x)
Is not tautologically valid.It is logically valid!
A BC