Você está na página 1de 46

Propositional Logic

CITS2211 Discrete Structures


Propositions

Unit coordinator: Arran Stewart

1 / 46
Propositional Logic

Highlights

This lecture will address the following questions:


1. What is a proposition?
2. How are propositions combined?
3. How are propositions related to natural language and things in
the real world such as computer programs?
4. How is the truth or falsity of a proposition decided?

2 / 46
Propositional Logic

Reading

Mathematics for Computer Science:


Introduction
Chapter 1, Section 1.1
Chapter 3, Section 3.1
Chapter 3, Section 3.2

3 / 46
Propositional Logic

Why study propositional logic

English language has many ambiguities. This is tolerable in


normal conversation but not if we wish to formulate precise
ideas.
Propositions and logical connectives arise all the time in
computer programs. For example, in conditional statements or
loops.
Computer programs themselves can be reasoned about using
logic. It is possible (although difficult) to prove a program is
correct.
Leading CPU chip manufacturers now routinely prove chip
correctness to avoid mistakes like the notorious Intel division
bug in the 1990s.

4 / 46
Propositional Logic

Propositional Logic

5 / 46
Propositional Logic

Propositional Logic

The first topic in cits2211 is logic.


Logic is the study of correct and incorrect reasoning.1
We study it to understand what makes good reasoning good, and
what makes bad reasoning bad.

1
David Sanson
6 / 46
Propositional Logic

Example

You have 4 cards. Each card has a number on one side and a letter
on the other. If the cards are dealt so that you can see
K 5 2 J

– then which cards would you have to turn over, to test the rule that
if there’s a J on one side then there’s a 5 on the other side? Give
reasons for your answer.

7 / 46
Propositional Logic

Example2

One rabbit saw six elephants while going to the river. Every
elephant saw two monkeys going towards the river. Every monkey
holds one parrot in their hands. How many animals are going
towards the river?

2
Sara L Uckelman,
http://community.dur.ac.uk/s.l.uckelman/slides/teachersconf042017.pdf
8 / 46
Propositional Logic

Propositions

Definition: A proposition is a statement that is either true or false.


Examples:
All men are mortal
The earth is flat
1+1=2
The evergreen forests of Canada comprise spruce, pine and fir
trees.

9 / 46
Propositional Logic

Connectives

We can combine simple propositions (shown in blue) into more


complex ones using connectives (show in dark green).
Examples:
The earth is not flat (not F)
The earth is flat or I am mad (F or M)
The earth is flat but I am mad (F or M)
Your money or your life (M or L, but be aware this really
means M xor L)
If all men are mortal and all Greeks are men then all Greeks
are mortal (if MX and GM then GX)
If this is Tuesday, then I must be mad.

10 / 46
Propositional Logic

Connectives (cont’d)

It is raining today and today is winter. (R and W)


It is raining despite the season being winter. (R and W)
If I can afford it then I will buy it (A implies B)
I will buy it if I can afford it (A implies B)
I will buy it when I can afford it (A implies B)
I can afford it only if I buy it (A implies B)

11 / 46
Propositional Logic

Connectives (cont’d)
The connectives we will use for propositional logic are:

not ¬
and ∧
or ∨
implies (if–then) →
iff (if and only if) ↔

The meaning of these operators can be defined using a truth table.


Other names you might see for “implies/if–then” are “the conditional”,
“the material conditional”, or “material implication”
Other names you might see for “iff” are “the biconditional” or “the
material biconditional”

12 / 46
Propositional Logic

Connectives (cont’d)

P Q P∧Q P Q P∨Q
P ¬P T T T T
T F T F T F
F T F T F T
F F F F

13 / 46
Propositional Logic

Connectives (cont’d)

P Q P∧Q P Q P∨Q
P ¬P T T T T T T
T F T F F T F T
F T F T F F T T
F F F F F F

14 / 46
Propositional Logic

Connectives (cont’d)

P Q P→Q P Q P↔Q
T T T T
T F T F
F T F T
F F F F

15 / 46
Propositional Logic

Connectives (cont’d)

P Q P→Q P Q P↔Q
T T T T T T
T F F T F F
F T T F T F
F F T F F T

16 / 46
Propositional Logic

Implication

When is an implication true?


According to the truth table we have seen, it’s true exactly
when the if-part is false or the then-part is true.
P Q P→Q
T T T
T F F
F T T
F F T

17 / 46
Propositional Logic

Implication (cont’d)

But that doesn’t sound quite like what we mean when we say
‘If A, then B’. Why is it this way?
One way to think about implication is to think about how
you’d disprove a statement of the form ‘If A, then B’.
If someone asserted that ‘If you wash your car, it always rains’,
you could disprove this by pointing out a circumstance where
someone washed their car and it didn’t rain –
i.e. the if-part is true, and the then-part is false.
And that corresponds to the one row in the truth table that
comes out false.
If you wash your car and it doesn’t rain, then it’s certainly not
true that ‘If you wash your car, it always rains’.
In every other situation, we can’t disprove that ‘If P, then Q’ –
so we regard it as true.
18 / 46
Propositional Logic

Implication (cont’d)

Alternatively – ask yourself, if you wanted to give ‘if. . . then’ a


meaning as a connective in our propositional language – what
possible other meaning could you give it?
None of the other possible truth tables seem satisfactory, so we
use this one.
(This ‘truth-functional’ interpretation of ‘if. . . then’ statements
was invented by Gottlob Frege in 1879.)
In more complex languages, perhaps a meaning of ‘if..then’ can
be got that is closer to the natural language meaning; but in
propositional logic, this is the one we use.

19 / 46
Propositional Logic

Implication examples

What are the truth values of the following statements?


If pigs can oink then the sky is blue
If the sky is blue then the sky is red
If pigs can fly then the sky is red
If pigs can fly then the sky is blue

20 / 46
Propositional Logic

Implication examples

If pigs can oink then the sky is blue – true


If the sky is blue then the sky is red – false
If pigs can fly then the sky is red – true
If pigs can fly then the sky is blue – true

21 / 46
Propositional Logic

Formal languages

Propositional logic is a formal language


A formal language consists of
1. A set of permitted symbols; its alphabet or vocabulary
2. Rules defining the ways those symbols can be put together (to
form things we often call sentences or formulas – its syntax
3. A description of what correctly written sentences or formulas
mean; this is the language’s semantics.

22 / 46
Propositional Logic

The language of propositional logic

Let us consider the formal language of propositional logic.


Alphabet. The alphabet of propositional logic consists of
symbols used to denote propositions, called identifiers. For
example, P, Q and R. It includes parentheses “(” and “)” as
punctuation symbols. And it includes the propositional
connectives ¬, ∨, ∧, →, ↔.

23 / 46
Propositional Logic

The language of propositional logic – syntax

Syntax. The syntax of propositional logic is defined by the


following Rules for construction of well formed formulae (wff),
which represent Propositions: An identifier is a proposition. If
φ and ψ are propositions then so are ¬ φ, φ ∧ ψ, φ ∨ ψ,
φ → ψ and φ ↔ ψ. Note that arbitrarily complex propositions
can be built recursively using these rules.
φ and ψ here represent some arbitrary proposition – the syntax
rules just tell us that given anything we already know is a
proposition, we can construct more complex propositions.

24 / 46
Propositional Logic

The language of propositional logic – semantics

Now for the semantics.


Identifiers. We use identifiers to represent propositions that are
primitive – that contain no connectives, and can’t be broken
down any further.
And we may assign truth values to each identifier – like a
lookup table, mapping each identifier to either ‘true’ or ‘false’.

25 / 46
Propositional Logic

Semantics

So we could model the following little hypothetical world:


The identifier P represents the proposition “The Rock (Dwayne
Johnson) is real”. We give this the value true.
The identifier Q represents the proposition “Santa Claus is real”.
We give this the value true, too.
The identifier R represents the proposition “Tommy Lee Jones
is younger than 60”. We’ll give this the value false.

We could show this in abbreviated form as:


P Q R
T T F

26 / 46
Propositional Logic

The language of propositional logic (cont’d)

Connectives. The semantics for the connectives are exactly


what we showed in the truth tables. If we know the truth
values of the sub-parts of a sentence, and we have the
truth-table for the connective that joins them, then we can
assign a truth-value to the sentence as a whole.

27 / 46
Propositional Logic

Well-formed formulas – examples

Which of the following are wff of propositional logic ? Why ?

+ P ∨Q

¬∧Q

P ∧ Q ∨ R ¬(S ∧ ¬P)

P ↔ ¬P

→P Q

*→Q

28 / 46
Propositional Logic

Precedence rules

Brackets can be used to resolve ambiguity. But too many brackets


can be hard to read, so we use the following precedence of symbols:
B rackets
N egation
C onjunction
D isjunction
I mplication
E quivalence

29 / 46
Propositional Logic

Precedence cont’d

Add (redundant!) brackets to the following formula to show how it


is interpreted under the operator precedence rules.

¬P ∧ Q → ¬S ∧ ¬T ↔ ¬V ∨ W

30 / 46
Propositional Logic

Truth Tables

Truth Tables

31 / 46
Propositional Logic

Truth Tables

Truth Tables

The following section of the lecture will address the following


questions:
1. How to use truth tables to evaluate compound propositions
2. Introduce some common rules of propositional logic
3. How to identify tautologies and equivalences

32 / 46
Propositional Logic

Truth Tables

Equivalence
Two propositions are equivalent if they have the same truth value for all possible
values of their identifiers.

Here are some commonly used propositional equivalences. Each can be derived from a
truth table (exercise).

Expression Equivalent To Name of Rule


P ∨Q Q∨P Commutativity
P ∧Q Q∧P
(P ∨ Q) ∨ R P ∨ (Q ∨ R) Associativity
(P ∧ Q) ∧ R P ∧ (Q ∧ R)
P ∧ (Q ∨ R) (P ∧ Q) ∨ (P ∧ R) Distributivity
P ∨ (Q ∧ R) (P ∨ Q) ∧ (P ∨ R)
¬(P ∨ Q) ¬P ∧ ¬Q De Morgan’s laws
¬(P ∧ Q) ¬P ∨ ¬Q
P→Q ¬P ∨ Q Implication
P→Q ¬Q → ¬P Contrapositive
P ∨ ¬P T Excluded Middle
P ¬(¬P) Double negation
P ∧T P And Absorption

33 / 46
Propositional Logic

Truth Tables

Example - De Morgan’s laws

Derive De Morgan’s law ¬(P ∨ Q) equivalent to ¬P ∧ ¬Q using a


truth table.

LHS RHS
P Q P ∨Q ¬(P ∨ Q) ¬P ¬Q ¬P ∧ ¬Q LHS ↔ RHS
T T
T F
F T
F F

34 / 46
Propositional Logic

Truth Tables

Example - contrapositive law

Example: Derive the contrapositive law using a truth table.

LHS RHS
P Q P→Q ¬Q ¬P ¬Q → ¬P LHS ↔ RHS
T T
T F
F T
F F

35 / 46
Propositional Logic

Truth Tables

Propositional Logic in Programs

Propositional logic is used in computer programs.


Example: Use propositional logic to simplify this statement:
if ( x > 0 || ( x <= 0 && y > 100 ) )
return true;
else
return false;

36 / 46
Propositional Logic

Truth Tables

Types of propositions

Propositions can be classified into the following categories:


tautologies;
contradictions; and
contingent propositions.

37 / 46
Propositional Logic

Truth Tables

Tautologies

Definition: A tautology is a compound proposition which is


true under all possible assignments of truth values to its atomic
propositions.
Example: Show that P ∨ ¬P is a tautology.

38 / 46
Propositional Logic

Truth Tables

Contradictions

Definition: A contradiction is a compound proposition which is


false under all possible assignments of truth values to its
atomic propositions.
Example: Show that P ∧ ¬P is a contradiction.

39 / 46
Propositional Logic

Truth Tables

Contingency

Definition: A contingent proposition is one which is neither a


tautology nor a contradiction.
Example: Show that P → ¬P is a contingent proposition.
Tautologies and contradictions will be true or false
(respectively) regardless of the truth-values of their atomic
propositions.
Contingent propositions, on the other hand, will be sometimes
true, sometimes false, depending on what the truth values are.
Tautologies and contradictions can be thought of as necessarily
true and necessarily false.
But contingent propositions aren’t either.

40 / 46
Propositional Logic

Truth Tables

Logical equivalence

When are two propositions logically equivalent?


That is, when do they have the same “meaning”?
Definition: Two propositions φ and ψ are logically equivalent if
and only if φ ↔ ψ is a tautology.
Example: Show that P → Q is logically equivalent to ¬P ∨ Q

41 / 46
Propositional Logic

Truth Tables

Logical equivalence (cont’d)

You may also see equivalence written as ≡.


Not that equivalence isn’t part of the language of propositional
logic; it’s a statement about the meaning of two formulas (and
it asserts that they have the same meaning).

42 / 46
Propositional Logic

Truth Tables

Logical equivalence (cont’d)

A practical use of equivalence is that you can always substitute


a formula with a logically equivalent one, and know that you’ve
preserved the meaning.
We’ve seen that we can show logical equivalence of two
formulas, φ and ψ, by constructing the truth table of φ ↔ ψ.
But often it is easier to prove two formulas are equivalent by
modifying one side or the other (using equivalences we already
know), until both sides are the same.

43 / 46
Propositional Logic

Truth Tables

Axioms of Propositional Logic (1)

Expression Equivalent To Name of Rule


P ∨Q Q∨P Commutativity
P ∧Q Q∧P
(P ∨ Q) ∨ R P ∨ (Q ∨ R) Associativity
(P ∧ Q) ∧ R P ∧ (Q ∧ R)
P ∧ (Q ∨ R) (P ∧ Q) ∨ (P ∧ R) Distributivity
P ∨ (Q ∧ R) (P ∨ Q) ∧ (P ∨ R)
¬(P ∧ Q) ¬P ∨ ¬Q De Morgan
¬(P ∨ Q) ¬P ∧ ¬Q
¬¬P P Double Negation
P ∨ ¬P T Excluded Middle
P ∧ ¬P F Contradiction

44 / 46
Propositional Logic

Truth Tables

Axioms of Propositional Logic (2)

Expression Equivalent To Name of Rule


P→Q ¬P ∨ Q Implication
P↔Q (P → Q) ∧ (Q → P) Equivalence
P ∨ (P ∧ Q) P Or Absorption
P ∨P P
P ∨T T
P ∨F P
P ∧ (P ∨ Q) P And Absorption
P ∧P P
P ∧T P
P ∧F F
P P Identity

45 / 46
Propositional Logic

Truth Tables

Axioms of Propositional Logic (3)

The table of rules on the previous two pages (axioms) can be used
to derive all tautologies.
A more minimal axiomatisation was discovered by Edward Vermilye
Huntington in 1933.

Expression Equivalent To Name of Rule


P ∨Q Q∨P Commutativity
(P ∨ Q) ∨ R P ∨ (Q ∨ R) Associativity
¬(¬P ∨ Q) ∨ ¬(¬P ∨ ¬Q) P Huntington axiom

But note that these axioms are not very convenient for writing
proofs. So you are recommended to use a wider range of laws.

46 / 46

Você também pode gostar