EE1J2 - Slide 1 EE1J2 – Discrete Maths Lecture 3 Syntax of Propositional Logic Parse trees revised...

Post on 19-Dec-2015

220 views 0 download

Transcript of EE1J2 - Slide 1 EE1J2 – Discrete Maths Lecture 3 Syntax of Propositional Logic Parse trees revised...

EE1J2 - Slide 1

EE1J2 – Discrete Maths Lecture 3

Syntax of Propositional Logic Parse trees revised Construction of parse trees Semantics of propositional logic – truth tables Truth tables for complex formulae Tautologies, contradictory and satisfiable

formulae, logical equivalence, logical consequence

EE1J2 - Slide 2

Parse Tree for “the cat devoured the tiny mouse”

The cat devoured the tiny mouse

DET ADJ NOUN

DET NOUN VERB NP

NP VP

S

EE1J2 - Slide 3

Syntax of Propositional Logic The formal language of propositional logic

is much much simpler than NL The valid sentences of propositional logic

are called formulae (or, well-formed formulae

First stage is to define the basic symbols of the language

EE1J2 - Slide 4

Name Symbol Description

Propositional variables

p, q, r, p0,

p1, p2,…

‘atomic propositions’, not amenable to further analysis

negation not

conjunction and

disjunction or

implication if…then…

Contradiction

Brackets (, )

Symbols of Propositional Logic

EE1J2 - Slide 5

Formal Language Definition of Propositional Logic

1. Each propositional variable is a formula, and contradiction is a formula

2. If f and g are formulae then (f), f, fg, fg, fg are also formulae

3. A sequence of symbols is a formula if and only if it can be derived using 1 and 2

EE1J2 - Slide 6

Parsing in Propositional Logic Consider

S = ((p (q r)) ((p (q))((q) ( r)))) To tell whether or not this is a well-formed

formula in Propositional Logic we need to find a parse

First note that S can be written as

S

EE1J2 - Slide 7

Parsing in PL (continued)

S = ((p (q r)) ((p (q))((q) ( r))))

1. S , where:

= (p (q r))

= ((p (q))((q) ( r)))

2. Next note that p and q r

3. Finally, ,

where p and q

and , q and r

EE1J2 - Slide 8

Parse Tree forS = ((p (q r)) ((p (q))((q) ( r))))

q r pp

q q r

S

(p (q r)) (p (q))((q) ( r))

(q r) (p (q))((q) ( r))

(q)(q) (r)

EE1J2 - Slide 9

Parse Tree forS = ((p (q r)) ((p (q))((q) ( r))))

q r pp

q q r

EE1J2 - Slide 10

Construction of a Parse Tree

Once brackets have been inserted, parse tree can normally be constructed

Alternatively, apply the following procedure:

EE1J2 - Slide 11

Constuction of Parse Tree

1. Number the brackets

(1 (2 p (3 q r)4 )5 (6 (7 p (8 q)9 )10

(11 (12 q)13 (14 r)15 )16 )17)18

2. Draw an initial ‘dummy node’

EE1J2 - Slide 12

Construction of Parse Tree

2. Suppose we are at a particular node in the

tree

1. Move to the right to the next bracket

2. If ‘(‘ , form a new downward edge to the right

of any existing children. Go to the new node

at the end of the new edge.

3. If ‘)’, backtrack to the previous node

EE1J2 - Slide 13

Construction of a Parse Tree

1 1

2

1

2

3

1

2

3,4

1

2,5

3,4

1

2,5

3,4

6

1

2,5

3,4

6

7

And so on….See Truss, example 2.1 for the complete construction

(1 (2 p (3 q r)4 )5 (6 (7 p (8 q)9 )10

(11 (12 q)13 (14 r)15 )16 )17)18

EE1J2 - Slide 14

Example (from last lecture)

(a c p m) ((m a) p) ((l p) (a m))

First add brackets to remove ambiguity:

(((a l) p ) m) (((m a) p) ((l p) (a m)))

EE1J2 - Slide 15

Semantics of Propositional Logic The truth (T) or falsehood (F) of a formula

in propositional logic can be determined once the truth values of the atomic formulae are known

A truth table shows the truth values of a complex formula given all possible combinations of truth values of its atomic formulae

EE1J2 - Slide 16

Truth Table for

Truth table for

p p

T F

F T

EE1J2 - Slide 17

Truth Tables for , , and Truth tables for , , and

p q p q p q p q

T T T T T

T F F T F

F T F T T

F F F F T

EE1J2 - Slide 18

Truth Table for ‘’ The truth table for the ‘’ symbol needs some

thought [Truss, p 54]. If q is true and p is true, then the assertion p q is

intuitively true If q is false and p is true, then the assertion p q

is intuitively false For the two cases where p is false, the argument is

that the implication “if p then q” is true by default, since if p is false then no further action is required

EE1J2 - Slide 19

Truth Table for a Complex Formula

Consider the formula (pq)((pq)q) Extract all of the possible sub-formulae

pq pq(pq)q(pq)( (pq)q)

Construct a truth table, with columns for p and q, and each of the complex ‘sub’-formulae listed above

EE1J2 - Slide 20

Truth Table for a Complex Formula

Truth table for (pq)((pq)q)

p q pq pq (pq)q (pq)( (pq)q)

T T T T T T

T F T F F F

F T T F T T

F F F F F T

EE1J2 - Slide 21

‘Abbreviated’ truth tables As number of atomic propositions increases,

number of rows in table increases As complexity of formula increases, number of

columns in the truth table increases Tables become cumbersome Solution to second problem is ‘abbreviated’ truth

tables Display truth value for a sub-formula under the last

connective used in its formation

EE1J2 - Slide 22

Abbreviated truth table (1)

Abbreviated truth table for (pq)((pq)q)

(p q) ((p q) q)

T   T   T   T   T

T   F   T   F   F

F   T   F   T   T

F   F   F   F   F

EE1J2 - Slide 23

Abbreviated truth table (2)

Abbreviated truth table for (pq)((pq)q)

(p q) ((p q) q)

T T T   T T T   T

T T F   T F F   F

F T T   F F T   T

F F F   F F F   F

EE1J2 - Slide 24

Abbreviated truth table (3)

Abbreviated truth table for (pq)((pq)q)

(p q) ((p q) q)

T T T T T T T T T

T T F F T F F F F

F T T T F F T T T

F F F T F F F F F

EE1J2 - Slide 25

Second ExampleAbbreviated truth table for ((p(qr))((p)(rq))

((p (q r)) (( p) (r q))

T T T T T T F T F T T T

T F T F F F F T F F T T

T T F T T T F T F T F F

T T F T F T F T F F T F

F F T T T T T F T T T T

F F T F F T T F T F T T

F F F T T F T F F T F F

F F F T F T T F T F T F

EE1J2 - Slide 26

Some special formulae Tautologies Contradictory formulae Satisfiable formulae Logically equivalent formulae Logical consequence

EE1J2 - Slide 27

Tautologies A formula f which is true for all possible

truth values of its atomic propositions is called a tautology, (or said to be valid)

If f is a tautology, write ⊨f Example: the formula

(p q) ((p) (q))

is a tautology

EE1J2 - Slide 28

Truth table for tautology (pq)((p)(q))

Truth table for (p q)((p) (q))

(p q) (( p) ( q))

T T T T T F T F F T

T F F T F F T T T F

F F T T F T F T F T

F F F T F T F T T F

EE1J2 - Slide 29

Contradictory and Satisfiable Formulae Let f be a formula, then

f is contradictory if it is false for all assignments of truth values to its atomic propositions

f is satisfiable if it is true for at least one assignment of truth values to its atomic propositions

EE1J2 - Slide 30

Consequences… It follows that:

f is contradictory if and only if f is a tautology,

f is satisfiable if and only if it is not contradictory

EE1J2 - Slide 31

Logical Equivalence Two formulae f and g are logically

equivalent if they have the same truth table

EE1J2 - Slide 32

Logical Consequence Let be a set of formulae and f a formula

f is a logical consequence of if for any assignment of truth values to atomic propositions for which all of the members of true, f is also true

If f is a logical consequence of , write ⊨f Note: this is consistent with ⊨f when f is a tautology

This is important! It is the basis of formalisation of arguments

EE1J2 - Slide 33

Summary of Lecture 3 Parse trees revised Construction of parse trees Semantics of propositional logic – truth tables Truth tables for complex formulae, abbreviated

truth tables Tautologies, contradictory and satisfiable

formulae, logical equivalence, logical consequence