LECTURE 7: PROPOSITIONAL LOGIC (1) Software Engineering Mike Wooldridge
Lecture 7 Software Engineering
1 What is a Logic?
•When most people say ‘logic’, they meaneither propositional logic or first-orderpredicate logic.
• However, the precise definition is quitebroad, and literally hundreds of logicshave been studied by philosophers,computer scientists and mathematicians.
• Any ‘formal system’ can be considered alogic if it has:
– a well-defined syntax;– a well-defined semantics; and– a well-defined proof-theory.
Mike Wooldridge 1
Lecture 7 Software Engineering
• The syntax of a logic defines thesyntactically acceptable objects of thelanguage, which are properly calledwell-formed formulae (wff). (We shall justcall them formulae.)
• The semantics of a logic associate eachformula with a meaning.
• The proof theory is concerned withmanipulating formulae according tocertain rules.
Mike Wooldridge 2
Lecture 7 Software Engineering
2 Propositional Logic
• The simplest, and most abstract logic wecan study is called propositional logic.
• Definition: A proposition is a statementthat can be either true or false; it must beone or the other, and it cannot be both.
• EXAMPLES. The following arepropositions:
– the reactor is on;– the wing-flaps are up;– John Major is prime minister.
whereas the following are not:
– are you going out somewhere?– 2+3
Mike Wooldridge 3
Lecture 7 Software Engineering
• It is possible to determine whether anygiven statement is a proposition byprefixing it with:
It is true that . . .
and seeing whether the result makesgrammatical sense.
•We now define atomic propositions.Intuitively, these are the set of smallestpropositions.
• Definition: An atomic proposition is onewhose truth or falsity does not depend onthe truth or falsity of any otherproposition.
• So all the above propositions are atomic.
Mike Wooldridge 4
Lecture 7 Software Engineering
• Now, rather than write out propositions infull, we will abbreviate them by usingpropositional variables.
• It is standard practice to use thelower-case roman letters
p, q, r, . . .
to stand for propositions.
• If we do this, we must define what wemean by writing something like:
Let p be John Major is prime Minister.
• Another alternative is to write somethinglike reactor is on, so that the interpretationof the propositional variable becomesobvious.
Mike Wooldridge 5
Lecture 7 Software Engineering
2.1 The Connectives
• Now, the study of atomic propositions ispretty boring. We therefore now introducea number of connectives which will allowus to build up complex propositions.
• The connectives we introduce are:
∧ and (& or .)∨ or (| or +)¬ not (∼)⇒ implies (⊃ or→)⇔ iff
• (Some books use other notations; these aregiven in parentheses.)
Mike Wooldridge 6
Lecture 7 Software Engineering
And
• Any two propositions can be combined toform a third proposition called theconjunction of the original propositions.
• Definition: If p and q are arbitrarypropositions, then the conjunction of p andq is written
p ∧ q
and will be true iff both p and q are true.
Mike Wooldridge 7
Lecture 7 Software Engineering
•We can summarise the operation of ∧ in atruth table. The idea of a truth table forsome formula is that it describes thebehaviour of a formula under all possibleinterpretations of the primitivepropositions the are included in theformula.
• If there are n different atomic propositionsin some formula, then there are 2n differentlines in the truth table for that formula.(This is because each proposition can takeone 1 of 2 values — true or false.)
• Let us write T for truth, and F for falsity.Then the truth table for p ∧ q is:
p q p ∧ qF F FF T FT F FT T T
Mike Wooldridge 8
Lecture 7 Software Engineering
Or
• Any two propositions can be combined bythe word ‘or’ to form a third propositioncalled the disjunction of the originals.
• Definition: If p and q are arbitrarypropositions, then the disjunction of p andq is written
p ∨ q
and will be true iff either p is true, or q istrue, or both p and q are true.
Mike Wooldridge 9
Lecture 7 Software Engineering
• The operation of ∨ is summarised in thefollowing truth table:
p q p ∨ qF F FF T TT F TT T T
Mike Wooldridge 10
Lecture 7 Software Engineering
If. . . Then. . .
•Many statements, particularly inmathematics, are of the form:
if p is true then q is true.
Another way of saying the same thing is towrite:
p implies q.
• In propositional logic, we have aconnective that combines two propositionsinto a new proposition called theconditional, or implication of the originals,that attempts to capture the sense of sucha statement.
Mike Wooldridge 11
Lecture 7 Software Engineering
• Definition: If p and q are arbitrarypropositions, then the conditional of p and qis written
p⇒ q
and will be true iff either p is false or q istrue.
• The truth table for⇒ is:p q p⇒ qF F TF T TT F FT T T
Mike Wooldridge 12
Lecture 7 Software Engineering
• The⇒ operator is the hardest tounderstand of the operators we haveconsidered so far, and yet it is extremelyimportant.
• If you find it difficult to understand, justremember that the p⇒ q means ‘if p istrue, then q is true’.If p is false, then we don’t care about q, andby default, make p⇒ q evaluate to T inthis case.
• Terminology: if φ is the formula p⇒ q,then p is the antecedent of φ and q is theconsequent.
Mike Wooldridge 13
Lecture 7 Software Engineering
Iff
• Another common form of statement inmaths is:
p is true if, and only if, q is true.
• The sense of such statements is capturedusing the biconditional operator.
• Definition: If p and q are arbitrarypropositions, then the biconditional of pand q is written:
p⇔ q
and will be true iff either:
1. p and q are both true; or2. p and q are both false.
Mike Wooldridge 14
Lecture 7 Software Engineering
• The truth table for⇔ is:p q p⇔ qF F TF T FT F FT T T
• If p⇔ q is true, then p and q are said to belogically equivalent. They will be true underexactly the same circumstances.
Mike Wooldridge 15
Lecture 7 Software Engineering
Not
• All of the connectives we have consideredso far have been binary: they have takentwo arguments.
• The final connective we consider here isunary. It only takes one argument.
• Any proposition can be prefixed by theword ‘not’ to form a second propositioncalled the negation of the original.
• Definition: If p is an arbitrary propositionthen the negation of p is written
¬p
and will be true iff p is false.
• Truth table for ¬:p ¬pF TT F
Mike Wooldridge 16
Lecture 7 Software Engineering
Comments
•We can nest complex formulae as deeply aswe want.
•We can use parentheses i.e., ),(, todisambiguate formulae.
• EXAMPLES. If p, q, r, s and t are atomicpropositions, then all of the following areformulae:
p ∧ q⇒ rp ∧ (q⇒ r)
(p ∧ (q⇒ r)) ∨ s((p ∧ (q⇒ r)) ∨ s) ∧ t
whereas none of the following is:
p ∧p ∧ q)
p¬
Mike Wooldridge 17
Lecture 7 Software Engineering
3 Tautologies & Consistency
• Given a particular formula, can you tell ifit is true or not?
• No — you usually need to know the truthvalues of the component atomicpropositions in order to be able to tellwhether a formula is true.
• Definition: A valuation is a function whichassigns a truth value to each primitiveproposition.
• In Modula-2, we might write:
PROCEDURE Val(p : AtomicProp):BOOLEAN;
• Given a valuation, we can say for anyformula whether it is true or false.
Mike Wooldridge 18
Lecture 7 Software Engineering
• EXAMPLE. Suppose we have a valuationv, such that:
v(p) = Fv(q) = Tv(r) = F
Then we truth value of (p ∨ q)⇒ r isevaluated by:
(v(p) ∨ v(q))⇒ v(r) (1)= (F ∨ T)⇒ F (2)
= T ⇒ F (3)= F (4)
Line (3) is justified since we know thatF ∨ T = T.Line (4) is justified since T ⇒ F = F.If you can’t see this, look at the truth tablesfor ∨ and⇒.
Mike Wooldridge 19
Lecture 7 Software Engineering
•When we consider formulae in terms ofinterpretations, it turns out that some haveinteresting properties.
• Definition:
1. A formula is a tautology iff it is trueunder every valuation;
2. A formula is consistent iff it is trueunder at least one valuation;
3. A formula is inconsistent iff it is notmade true under any valuation.
• Now, each line in the truth table of aformula correponds to a valuation.
• So, we can use truth tables to determinewhether or not formulae are tautologies.
Mike Wooldridge 20