comp9020 lecture 2 session 2, 2016 propositional and ...cs9020/16s2/lec/lec02.pdf · revision: 1.1...
Post on 09-Jul-2020
1 Views
Preview:
TRANSCRIPT
COMP9020 Lecture 2Session 2, 2016
Propositional and Predicate LogicSAT, ∀, ∃
Revision: 1.1
1
Overview
validity, satisfiability and entailment
logical equivalences
predicate logic, quantifiers
proof methods
2
Satisfiability
Definition
A formula is satisfiable, if it evaluates to T for some assignment oftruth value to its basic propositions.
Example
A B ¬(A⇒ B)
F F FF T FT F TT T F
3
Formally. . .
we can define a relationship “|=” between truth value assignmentsπ and formulae φ.
π |= p iff π(p) = T
π |= ¬φ iff π 6|= φ
π |= φ ∧ ψ iff π |= φ and π |= ψ
π |= φ ∨ ψ iff π |= φ or π |= ψ
π |= φ⇒ ψ iff whenever π |= φ then π |= ψ
π |= φ⇔ ψ iff (π |= φ if, and only if π |= ψ)
φ is satisfiable iff there exists a π such that π |= φ.
4
Applications: Constraint Satisfaction Problems
These are problems such as timetabling, activity planning, etc.Many can be understood as showing that a formula is satisfiable.
Example
You are planning a party, but your friends are a bit touchy aboutwho will be there.
1 If John comes, he will get very hostile if Sarah is there.
2 Sarah will only come if Kim will be there also.
3 Kim says she will not come unless John does.
Who can you invite without making someone unhappy?
5
Translation to logic: let J, (S ,K ) represent “John (Sarah, Kim)comes to the party”. Then the constraints are:
1 J ⇒ ¬S2 S ⇒ K
3 K ⇒ J
Thus, for a successful party to be possible, we want the formulaφ = (J ⇒ ¬S) ∧ (S ⇒ K ) ∧ (K ⇒ J) to be satisfiable.Truth values for J, S ,K making this true are called satisfyingassignments.
6
We figure out where the conjuncts are false, below. (so blank = T)J K S J ⇒ ¬S S ⇒ K K ⇒ J φ
F F FF F T F FF T F F FF T T F FT F FT F T F F FT T FT T T F F
Conclusion: a party satisfying the constraints can be held. Invitenobody, or invite John only, or invite Kim and John.
7
Validity, Entailment, Arguments
An argument consists of a set of declarative sentences calledpremises and a declarative sentence called the conclusion.
Example
Premises: Frank took the Ford or the Toyota.If Frank took the Ford he will be late.Frank is not late.
Conclusion: Frank took the Toyota
8
An argument is valid if the conclusions are true whenever all thepremises are true. Thus: if we believe the premises, we should alsobelieve the conclusion.(Note: we don’t care what happens when one of the premises isfalse.)Other ways of saying the same thing:
The conclusion logically follows from the premises.
The conclusion is a logical consequence of the premises.
The premises entail the conclusion.
9
The previous argument is valid.
Example
Premises: Frank took the Ford or the Toyota.If Frank took the Ford he will be late.Frank is late.
Conclusion: Frank took the Ford.
is invalid. Why?
How to do this systematically?
10
For arguments in propositional logic, we can capture validity asfollows:Let φ1, . . . , φn and φ be formulae of propositional logic.Draw a truth table with columns for each of the Booleanpropositions, each of the φ1, . . . , φn and φ.The argument with premises φ1, . . . , φn and conclusion φ is valid ifin every row of the truth table where φ1, . . . , φn are all true, φ isalso true.Notation: φ1, . . . , φn |= φ, which abbreviates |= φ1 ∧ . . . ∧ φn ⇒ φ.That way, it’s a special case of the general definition of validity:φ is valid iff π |= φ, for all π.
11
(we mark only true locations (blank = F))Frd Toy Late Frd ∨ Toy Frd⇒ Late ¬Late Toy
F F F T TF F T TF T F T T T TF T T T T TT F F T TT F T T TT T F T T TT T T T T T
(This shows Frd ∨ Toy, Frd⇒ Late, ¬Late |= Toy)
12
The following row shows Frd ∨ Toy, Frd⇒ Late, Late 6|= FrdFrd Toy Late Frd ∨ Toy Frd⇒ Late Late Frd
F T T T T T F
13
Validity of formulae
Recall: a formula φ is valid, or a tautology, denoted |= φ, if itevaluates to T for all assignments of truth value to its basicpropositions.
Example
A B (A⇒ B)⇒ (¬B ⇒ ¬A)
F F TF T TT F TT T T
14
Validity, Equivalence and Entailment
Theorem
The following are equivalent:
φ1, . . . φn |= ψ
|= (φ1 ∧ . . . ∧ φn)⇒ ψ
|= φ1 ⇒ (φ2 ⇒ . . . (φn ⇒ ψ) . . .)
15
Applications:Reasoning about Requirements/Specifications
Suppose a set of English language requirements R for asoftware/hardware system can be formalised by a set of formulae{φ1, . . . φn}.Suppose C is a statement formalised by a formula ψ. Then
1 The requirements cannot be implemented if φ1 ∧ . . . ∧ φn isnot satisfiable.
2 If φ1, . . . φn |= ψ then every correct implementation of therequirements R will be such that C is always true in theresulting system.
3 If φ1, . . . φn−1 |= φn, then the condition φn of the specificationis redundant and need not be stated in the specification.
16
Example
Requirements R: A burglar alarm system for a house is to operateas follows. The alarm should not sound unless the system has beenarmed or there is a fire. If the system has been armed and a dooris disturbed, the alarm should ring. Irrespective of whether thesystem has been armed, the alarm should go off when there is afire.Conclusion C : If the alarm is ringing and there is no fire, then thesystem must have been armed.Questions
1 Will every system correctly implementing requirements Rsatisfy C?
2 Is the final sentence of the requirements redundant?
17
Expressing the requirements as formulas of propositional logic,with
S = the alarm sounds = the alarm rings
A = the system is armed
D = a door is disturbed
F = there is a fire
we getRequirements:
1 S ⇒ (A ∨ F )
2 (A ∧ D)⇒ S
3 F ⇒ S
Conclusion: (S ∧ ¬F )⇒ A
18
The questions correspond to
1 Does S ⇒ (A ∨ F ), (A ∧D)⇒ S , F ⇒ S |= (S ∧ ¬F )⇒ A?
2 Does (S ⇒ (A ∨ F )), (A ∧ D)⇒ S |= F ⇒ S ?
Answers: exercise
19
Terminology and rules
A literal is an expression p or ¬p where p is a propositionalatom.
An expression is in CNF (conjunctive normal form) if it hasthe form ∧
i∈ICi
where I is a finite set and each clause Ci is a disjunction ofliterals e.g. p ∨ q ∨ ¬r .
Expression is in DNF (disjunctive normal form) if it has theform ∨
i∈ICi
where I is a finite set and each clause Ci is a conjunction ofliterals e.g. p ∧ q ∧ ¬r .
20
CNF and DNF are named after their top level operators; no deepernesting of ∧ or ∨ is permitted.Sometimes e.g. in EE people use different notation:
us EEconstants T, F 1, 0propositional atoms p, q, . . . p, q, . . .conjunction p ∧ q p · q or pqdisjunction p ∨ q p + qnegation ¬p p′ or p
or worse, mix the two.
NB
An expression is in a given form irrespective of the notation usedto present it. For example p + q + r is the purely algebraic/EEnotation, while purely logical would be p ∨ q ∨ ¬r . However, usinga mixed notation is often more vivid.
21
We can assume in every clause (disjunct for the CNF,conjunct for the DNF) any given variable (literal) appears onlyonce; preferably, no literal and its negation together.
x + x = x , xx = xxx = 0, x + x = 1x · 0 = 0, x · 1 = x , x + 0 = x , x + 1 = 1
A preferred form for an expression is DNF, with as few termsas possible. In deriving such minimal simplifications the twobasic rules are
x + xy ⇔ x absorptionxy + xy ⇔ x combining the opposites
22
Theorem
For every formula φ of propositional logic, there exists a logicallyequivalent formula in CNF and a logically equivalent formula inDNF.
Proof.
we show how to apply the logical equivalences already introducedto convert any given formula to an equivalent one in CNF, DNF issimilar.
23
Step 1: Eliminate ⇒
Using the ruleA⇒ B ≡ ¬A ∨ B
we may eliminate all occurrences of ⇒.
Examples
p ⇒ ((q ⇒ r) ∨ ¬s)⇔ p ⇒ ((¬q ∨ r) ∨ ¬s)
⇔ ¬p ∨ ((¬q ∨ r) ∨ ¬s)
24
Step 2: Push negations down
Using De Morgan’s Laws and the double negation rule
¬(A ∨ B)⇔ ¬A ∧ ¬B¬(A ∧ B)⇔ ¬A ∨ ¬B
¬¬A⇔ A
we push negations down towards the atoms until we obtain aformula that is formed from literals using only ∧ and ∨.
25
Example
¬(¬p ∧ (q ∨ ¬(r ∧ s)))⇔ ¬¬p ∨ ¬(q ∨ ¬(r ∧ s)))
⇔ p ∨ (¬q ∧ ¬¬(r ∧ s))
⇔ p ∨ (¬q ∧ (r ∧ s))
26
Step 3: Use distribution to convert to CNF
Using the distribution rules
A ∨ (B1 ∧ . . . ∧ Bn)⇔ (A ∨ B1) ∧ . . . ∧ (A ∨ Bn)
(B1 ∧ . . . ∧ Bn) ∨ A⇔ (B1 ∨ A) ∧ . . . ∧ (Bn ∨ A)
we obtain a CNF formula.
Example
(p ∧ q) ∨ (p ∧ ¬q)⇔ ((p ∧ q) ∨ p) ∧ ((p ∧ q) ∨ ¬q)
⇔ ((p ∨ p) ∧ (q ∨ p)) ∧ ((p ∨ ¬q) ∧ (q ∨ ¬q))
27
Canonical Form DNF
Given a Boolean expression E , we can construct an equivalentDNF Ednf from the lines of the truth table where E is true:Given an assignment π of 0, 1 to variables x1 . . . xn, define theliteral
`i =
{xi if π(xi ) = 1
xi if π(xi ) = 0
and a product tπ = `1 · `2 · . . . · `n.Then
Ednf =∑
E(π)=1
tπ
28
Example
If π(x) = 1 and π(y) = 0 then tπ = xy .If E has truth table
x y E
0 0 10 1 01 0 11 1 1
Then
Ednf = x y + xy + xy
Note that this can be simplified to
y + x
29
Proof Rules and MethodsProof of the Contrapositive
We want to prove A⇒ B.To prove it, we show ¬B ⇒ ¬A and invoke the equivalence(A⇒ B)⇔ (¬B ⇒ ¬A).
Example
If m, n ∈ N and m + n ≥ 73 then m ≥ 37 or n ≥ 37.
Proof.
Let m, n ∈ N. We begin with the negation of the right-hand-sideand derive the negation of the left-hand-side.
¬(m ≥ 37 ∨ n ≥ 37)⇔ m < 37 ∧ n < 37
⇔ m ≤ 36 ∧ n ≤ 36
⇒ m + n ≤ 72
⇔ m + n < 73
30
Proof by Contradiction
We want to prove A.To prove it, we assume ¬A, and derive both B and ¬B for someproposition B.(Hard part: working out what B should be.)
Examples√
2 is irrational.There are infinitely many primes.
31
Proof by Cases
We want to prove that A. To prove it, we find a set of casesB1,B2, . . . ,Bn such that
1 B1 ∨ . . . ∨ Bn, and
2 Bi ⇒ A for each i = 1..n.
(Hard Part: working out what the Bi should be.)(Comment: often n = 2 and B2 = ¬B1, so B1 ∨ B2 = B1 ∨ ¬B1
holds trivially.)
Example
|x + y | ≤ |x |+ |y | for all x , y ∈ R.Recall:
|x | =
{x if x ≥ 0−x if x < 0
32
Substitution
Substitution is the process of replacing every occurrence of somesymbol Q by an expression α in some expression P. We writeP[α/Q ].
Examples
(x2 + 7y = 2xz)[3/x ] = 32 + 7y = 2 · 3 · z(x2 + 7y = 2xz)[2k+3/x ] = (2k + 3)2 + 7y = 2 · (2k + 3) · z
33
We can substitute logical expressions for logical variables:
Example
((A ∧ B)⇒ A)[P∧Q/A] = ((P ∧ Q) ∧ B)⇒ (P ∧ Q)
34
Substitution Rules
(a) If we substitute an expression for all occurrences of a logicalvariable in a tautology then the result is still a tautology.If |= φ then |= φ[α/P ].
Example
|= P ⇒ (P ∨ Q), so
|= (A ∨ B)⇒ ((A ∨ B) ∨ Q)
35
(b) If a logical formula φ contains a formula α, and we replace (anoccurrence of) α by a logically equivalent formula β, then theresult is logically equivalent to φ.
If α⇔ β then φ(α)⇔ φ(β).
Example
P ⇒ Q ⇔ ¬P ∨ Q, so
Q ⇒ (P ⇒ Q)⇔ Q ⇒ (¬P ∨ Q)
36
Quantifiers
We’ve made quite a few statements of the kind
“If there exists a satisfying assignment. . . ”
or
“Every natural number greater than 2. . . ”
without formally capturing these quantitative aspects.Notation: ∀ means “for all” and ∃ means “there exist(s)”
Example
Goldbach’s conjecture
∀n ∈ 2N (n > 2⇒ ∃p, q ∈ N (p, q ∈ Primes ∧ n = p + q))
37
Back to Validity and Satisfiability
φ is valid iff ∀π (π |= φ).φ is satisfiable iff ∃π (π |= φ).
(We left the domain of π unspecified since it’s clear from thecontext. Computers often don’t understand that well.)
38
top related