Professional Documents
Culture Documents
Lecture 1
Some Notations
2N Paths
Dijkstra’s Ga e
Lecture 2
A Three Ball Game
Mathematical Model
(2 black out, 1 black in) b-2+1, w b-1, w
f(b,w) = (2 white out, 1 black in) b+1, w-2
(1 of each out, 1 white in) b-1, w-1+1 b-1, w
Propositional Calculus
• A compound proposition that is always true, irrespective of the truth values of the comprising
propositions, is called a tautology.
pp
• The propositions p and q are called logically equivalent if p q is tautology.
• It is written as ,
pq
• For example: (p q) p q
Distributivity of Associativity of
• and over or • , , and
• or over and
• or over Commutativity of
• over and • , , and
• over or De orga ’s law
• over • Implication
• over • if and only if
Lecture 3
• A is a knight: A
• A eats his hat: H
• If I am a k ight the I ll eat hat: A H
• We have seen that (X S) therefore (A A H)
• Objective is to logically deduce H
T T T
F T T
T F F
F F T
A AH A (A H)
T T T
F T F
T F F
F T F
A H AH A (A H)
T T T T
F T T F
T F F F
F F T F
p q [p]
_______ q
p and q _________
pq
Introduction
Elimination
p q
_______ _______ p pq
p or q p or q _________
q
Elimination
Elimination
p and q p and q
________ _________ p not p false
p q _______ ______
false p
2. Assume X
Use Elimination Rules to break No. 1 down into 5 premises
3. (W and A) E
4. (not A) I
5. (not W) M
6. not E
7. X not (I or M)
Now application of elimination on 2 and 7 derives another simple proposition
2. Assume X
7. X not (I or M)
8. not (I or M)
Now proving I or M will result in a contradiction
We will now analyze W
9. Assume not W
10. M (from 5 and 9)
11. I or M (from 10 - introduction)
12. Assume W
13. Assume A
14. W and A (12 and 13)
15. E (3 and 14)
16. false (6 and 15)
17. I or M (16)
Lecture 4
A G A↔G A (A ↔ G)
T T T T
F T F T
T F F F
F F T F
Associativity of Equivalence
• ABC
can be evaluated as
(A B) C
or
A (B C)
ABC
A B C AB (A B) C
F F F T F
F F T T T
F T F F T
F T T F F
T F F F T
T F T F F
T T F T F
T T T T T
Full Adder
• a 1; A
• b 1; B
• c 1; C
• d 1; D
• D (A B C)
Properties of equivalence
• constant true
true p p
true = (p p)
(true p) = p
ppqprq
pppqqr
true p true r
pr
Replace the term which is repeated odd number of times by a single occurrence of the term and any
terms which is repeated an even number of times by removing all occurrences.
• A is a knight A
• A says I am a knight. A
AA
• Since this is always true, no meaningful conclusion can be made.
• A is a knight A
• B is a knight B
• A says I am the same type as B AB
AAB
B
Lecture 5
Negation
• p p false
• p (p false)
• (p p) false
• p p q p r q
• p p p q q r
• true p false r
• pr
• There are two natives A and B. A says, B is a knight is the same as I am a knave.
• What can you determine about A and B?
• A s state e t is: BA
• So, we have: ABA
AAB
false B
B
A?
Golden Rule
• pqpqpq
Implication
• pqppq
• pqqpq
• If I am a knight, B is a knight
• AB
• AAB
• AAAB
• AB
• Three of the inhabitants – A, B, and C – were standing together in a garden. A stranger passed
by and asked A, Are you a knight or a knave? A answered but the stranger could not
understand. The stranger then asked B, What did A say? . B replied, A said that he is a knave .
At this point, the third C, said, Do t believe B; he is l i g! What are A, B, and C?
• B s state e t is: A A
• C s state e t is: B
• So, we have:
(B A A) (C B)
B (C B)
( B C) ( B B)
( B C) B
BC
Lecture 6
Conditional Correctness:
• {P} S {Q}
where
P = initial state
S = set of statements
Q = final state
Express the conditional correctness of S
Weakest Precondition:
• Wp( z := x, z y) x
• Wp( t := x, t x0) x = x0
• Wp( i := i+1, i n ) i<n
• Wp( i := 0, i = 0 ) true ~least restrictive, i.e. true for all values
• Wp( i := 0, i = 1 ) false ~impossible
• Wp( x := e, Q(x)) Q(e)
X will have a value which e had before executing statement
Q(e) denotes the predicate obtained by substituting e for all free occurrences of x in the
predicate Q.
Lecture 7
Example:
• {x = x0 and y = y0}
t := x ; x := y ; y := t ;
• {y = x0 and x = y0}
• { x = x0 and y = y0} t := x { t = x0 and y = y0}
• { t = x0 and y = y0}
• x := y ; y :=t
• {y = x0 and x = y0}
• { t = x0 and y = y0} x := y { t = x0 and x = y0}
• { t = x0 and x = y0} y := t { y = x0 and x = y0}
P→Q Q→R
{Q} S {R} {P} S {R}
{P} S {R} {P} S {R}
Verification:
• Invariant
Something which is unchanging
Key to the proofs for programs containing loops (iteration or recursion)
Lecture 8
A Classical Problem:
Question: Can you completely cover the chessboard with these dominoes without partially using a
domino? If so how, if not, prove that you cannot.
• if i <= j then
m := i;
else
m := j;
• ia d j a d = i or =j
ELSE PART
• (i > j)
m = j;
• (m = i or m = j a d ja d j
• i>j a d j = i or j = j a d j i a d j j
• i>j a d true a d j i a d true
• i>j a d j i
• (i>j)
IF PART
• (i <= j)
m = i;
• = i or = j a d ia d i
• i j a d i = i or i = j a d i i a d i j
• i j a d true a d true a d i j
• i j a d i j
• i j
Lecture 9
Loop Invariants:
• s = 0;
for i := 1 to n do
s = s + a[i];
Lecture 10
Verification of Functions
• Specification of a system as a set of functions where the internal state is hidden.
• Each function is specified as a set of pre and post conditions.
• Pre-condition must hold if the post-condition is to be true.
Example – minimum
• function min (X: in INTEGER_ARRAY) return INTEGER
Pre: True
Post: j i X First .. X Last : i X = X j and
i i X First .. X Last : i X X i a d X = X