Propositional Logic: Semantics Alice Gao Lecture 4, September 19, - - PowerPoint PPT Presentation

β–Ά
propositional logic semantics
SMART_READER_LITE
LIVE PREVIEW

Propositional Logic: Semantics Alice Gao Lecture 4, September 19, - - PowerPoint PPT Presentation

Propositional Logic: Semantics Alice Gao Lecture 4, September 19, 2017 Semantics 1/56 Announcements Semantics 2/56 The roadmap of propositional logic Semantics 3/56 FCC spectrum auction an application of propositional spectrums to


slide-1
SLIDE 1

Propositional Logic: Semantics

Alice Gao

Lecture 4, September 19, 2017

Semantics 1/56

slide-2
SLIDE 2

Announcements

Semantics 2/56

slide-3
SLIDE 3

The roadmap of propositional logic

Semantics 3/56

slide-4
SLIDE 4

FCC spectrum auction β€” an application of propositional logic

To repurpose radio spectrums 2 auctions:

  • one to buy back spectrums from broadcasters
  • the other to sell spectrums to telecoms

A computational problem in the buy back auction: If I pay these broadcasters to go ofg air, could I repackage the spectrums and sell to telecoms? Could I lower your price and still manage to get useful spectrums to sell to telecoms? The problem comes down to, how many satisfjability problems can I solve in a very short amount of time? (determine that a formula is satisfjable or determine that it is unsatisfjable.) Talk by Kevin Leyton-Brown https://www.youtube.com/watch?v=u1-jJOivP70

Semantics 4/56

slide-5
SLIDE 5

Learning goals

By the end of this lecture, you should be able to

  • Evaluate the truth value of a formula
  • Defjne a (truth) valuation.
  • Determine the truth value of a formula by using truth tables.
  • Determine the truth value of a formula by using valuation trees.
  • Determine and prove whether a formula has a particular property
  • Defjne tautology, contradiction, and satisfjable formula.
  • Compare and contrast the three properties (tautology, contradiction,

and satisfjable formula).

  • Prove whether a formula is a tautology, a contradiction, or satisfjable,

using a truth table and/or a valuation tree.

  • Describe strategies to prove whether a formula is a tautology, a

contradiction or a satisfjable formula.

Semantics 5/56

slide-6
SLIDE 6

The meaning of well-formed formulas

To interpret a formula, we have to give meanings to the propositional variables and the connectives. A propositional variable has no intrinsic meaning; it gets a meaning via a valuation. A (truth) valuation is a function 𝑒 ∢ 𝒬 ↦ {F, T} from the set of all proposition variables 𝒬 to {F, T}. It assigns true/false to every propositional variable. Two notations: 𝑒(π‘ž) and π‘žπ‘’ both denote the truth value of π‘ž under the truth valuation 𝑒.

Semantics 6/56

slide-7
SLIDE 7

Truth tables for connectives

The unary connective Β¬: 𝛽 (¬𝛽) T F F T The binary connectives ∧, ∨, β†’, and ↔: 𝛽 𝛾 (𝛽 ∧ 𝛾) (𝛽 ∨ 𝛾) (𝛽 β†’ 𝛾) (𝛽 ↔ 𝛾) F F F F T T F T F T T F T F F T F F T T T T T T

Semantics 7/56

slide-8
SLIDE 8

Truth value of a formula

Fix a truth valuation 𝑒. Every formula 𝛽 has a value under 𝑒, denoted 𝛽𝑒, determined as follows.

  • 1. π‘žπ‘’ = 𝑒(π‘ž).
  • 2. (¬𝛽)𝑒 = { T

if 𝛽𝑒 = F F if 𝛽𝑒 = T

  • 3. (𝛽 ∧ 𝛾)𝑒 = { T

if 𝛽𝑒 = 𝛾𝑒 = T F

  • therwise
  • 4. (𝛽 ∨ 𝛾)𝑒 = { T

if 𝛽𝑒 = T or 𝛾𝑒 = T F

  • therwise
  • 5. (𝛽 β†’ 𝛾)𝑒 = { T

if 𝛽𝑒 = F or 𝛾𝑒 = T F

  • therwise
  • 6. (𝛽 ↔ 𝛾)𝑒 = { T

if 𝛽𝑒 = 𝛾𝑒 F

  • therwise

Semantics 8/56

slide-9
SLIDE 9

Evaluating a formula using a truth table

Example. The truth table of ((π‘ž ∨ π‘Ÿ) β†’ (π‘Ÿ ∧ 𝑠)). π‘ž π‘Ÿ 𝑠 (π‘ž ∨ π‘Ÿ) (π‘Ÿ ∧ 𝑠) ((π‘ž ∨ π‘Ÿ) β†’ (π‘Ÿ ∧ 𝑠)) F F F F F T F F T F F T F T F T F F F T T T T T T F F T F F T F T T F F T T F T F F T T T T T T

Semantics 9/56

slide-10
SLIDE 10

Evaluating a formula using a truth table

Build the truth table of ((π‘ž β†’ (Β¬π‘Ÿ)) β†’ (π‘Ÿ ∨ (Β¬π‘ž))).

Semantics 10/56

slide-11
SLIDE 11

Understanding the disjunction and the biconditional

𝛽 𝛾 (𝛽 ∨ 𝛾) Exclusive OR Biconditional F F F F T F T T T F T F T T F T T T F T

  • What is the difgerence between an inclusive OR (the disjunction) and

an exclusive OR?

  • What is the relationship between the exclusive OR and the

biconditional?

Semantics 11/56

slide-12
SLIDE 12

Understanding the conditional β†’

Assume that proposition π‘ž defjned below is true. π‘ž: If Alice is rich, she will pay your tuition. If Alice is rich, will she pay your tuition?

  • a. Yes
  • b. No
  • c. Maybe

If Alice is not rich, will she pay your tuition?

  • a. Yes
  • b. No
  • c. Maybe

Semantics 12/56

slide-13
SLIDE 13

Understanding the conditional β†’

Alice is rich Alice will pay your tuition. If Alice is rich, she will pay your tuition. F F T F T T T F F T T T

  • Suppose that the implication is a promise that I made. How can you

show that I broke my promise?

  • If the premise is false, is the statement true or false? (Will the

statement ever be contradicted?)

  • When the conclusion is true, is the statement true or false?
  • When the premise is true, how does the truth value of the statement

compare to the truth value of the conclusion?

  • Convert π‘ž β†’ π‘Ÿ into a logically equivalent formula which only uses the

connectives ∧, ∨ and ¬. Does this alternative formula make sense?

Semantics 13/56

slide-14
SLIDE 14

Another example of structural induction

Theorem: Fix a truth valuation 𝑒. Every formula 𝛽 has a value 𝛽𝑒 in {F, T}. Proof: The property for 𝑆(𝛽) is β€œπ›½ has a value 𝛽𝑒 in {F, T}”.

  • 1. If 𝛽 is a propositional variable, then 𝑒 assigns it a value of T or F (by

the defjnition of a truth valuation).

  • 2. If 𝛽 has a value in {F, T}, then (¬𝛽) also does, as shown by the truth

table of (¬𝛽).

  • 3. If 𝛽 and 𝛾 each has a value in {F, T}, then (𝛽 ⋆ 𝛾) also does for every

binary connective ⋆, as shown by the corresponding truth tables. By the principle of structural induction, every formula has a value. By the unique readability of formulas, we have proved that a formula has

  • nly one truth value under any truth valuation 𝑒. QED

Semantics 14/56

slide-15
SLIDE 15

Tautology, Contradiction, Satisfjable

A formula 𝛽 is a tautology if and only if for every truth valuation 𝑒, 𝛽𝑒 = T. A formula 𝛽 is a contradiction if and only if for every truth valuation 𝑒, 𝛽𝑒 = F. A formula 𝛽 is satisfjable if and only if there exists a truth valuation 𝑒 such that 𝛽𝑒 = T.

Semantics Properties of formulas 15/56

slide-16
SLIDE 16

Relationships among the properties

Divide the set of all formulas into 3 mutually exclusive and exhaustive sets. We know two things about these sets:

  • A formula is in set 1 if and only if the formula is true in every row of

the formula’s truth table.

  • A formula is in set 3 if and only if it is a contradiction.

Which of the following statements is true?

  • a. In set 3, every formula is false in every row of the formula’s truth table.
  • b. In set 2, every formula is true in at least one row and false in at least
  • ne row of the formula’s truth table.
  • c. Sets 2 and 3 contain exactly the set of satisfjable formulas.
  • d. Two of (a), (b), and (c) are true.
  • e. All of (a), (b), and (c) are true.

Semantics Properties of formulas 16/56

slide-17
SLIDE 17

Examples

  • 1. ((((π‘ž ∧ π‘Ÿ) β†’ (¬𝑠)) ∧ (π‘ž β†’ π‘Ÿ)) β†’ (π‘ž β†’ (¬𝑠)))
  • 2. ((((π‘ž ∧ π‘Ÿ) β†’ 𝑠) ∧ (π‘ž β†’ π‘Ÿ)) β†’ (π‘ž β†’ 𝑠))
  • 3. (π‘ž ∨ π‘Ÿ) ↔ ((π‘ž ∧ (Β¬π‘Ÿ) ∨ ((Β¬π‘ž) ∧ π‘Ÿ))
  • 4. (π‘ž ∧ (Β¬π‘ž))

Semantics Properties of formulas 17/56

slide-18
SLIDE 18

How to determine the properties of a formula

  • Truth table
  • Valuation tree
  • Reasoning

Semantics Properties of formulas 18/56

slide-19
SLIDE 19

Valuation Tree

Rather than fjll out an entire truth table, we can analyze what happens if we plug in a truth value for one variable.

Β¬T F Β¬F T π‘ž ∧ T π‘ž π‘ž ∧ F F π‘ž ∧ π‘ž π‘ž π‘ž ∨ T T π‘ž ∨ F π‘ž π‘ž ∨ π‘ž π‘ž π‘ž β†’ T T π‘ž β†’ F Β¬π‘ž T β†’ π‘ž π‘ž F β†’ π‘ž T π‘ž β†’ π‘ž T

We can evaluate a formula by using these rules to construct a valuation tree.

Semantics Properties of formulas 19/56

slide-20
SLIDE 20

Example of a valuation tree

Example. Show that (((π‘ž ∧ π‘Ÿ) β†’ (¬𝑠)) ∧ (π‘ž β†’ π‘Ÿ)) β†’ (π‘ž β†’ (¬𝑠))) is a tautology by using a valuation tree. Suppose 𝑒(π‘ž) = T. We put T in for π‘ž: (((T ∧ π‘Ÿ) β†’ (¬𝑠)) ∧ (T β†’ π‘Ÿ)) β†’ (T β†’ (¬𝑠)) . Based on the truth tables for the connectives, the formula becomes (((π‘Ÿ β†’ (¬𝑠)) ∧ π‘Ÿ) β†’ (¬𝑠)). If 𝑒(π‘Ÿ) = T, this yields ((¬𝑠) β†’ (¬𝑠)) and then T. (Check!). If 𝑒(π‘Ÿ) = F, it yields (F β†’ (¬𝑠)) and then T. (Check!). Suppose 𝑒(π‘ž) = F. We get (((F ∧ π‘Ÿ) β†’ (¬𝑠)) ∧ (F β†’ π‘Ÿ)) β†’ (F β†’ (¬𝑠)) , Simplifjcation yields ((F β†’ (¬𝑠)) ∧ T) β†’ T and eventually T. Thus every valuation makes the formula true, as required.

Semantics Properties of formulas 20/56

slide-21
SLIDE 21

Reasoning about the properties

I found a valuation for which the formula is true. Does the formula have each property below?

  • Tautology

YES NO MAYBE

  • Contradiction

YES NO MAYBE

  • Satisfjable

YES NO MAYBE I found a valuation for which the formula is false. Does the formula have each property below?

  • Tautology

YES NO MAYBE

  • Contradiction

YES NO MAYBE

  • Satisfjable

YES NO MAYBE

Semantics Properties of formulas 21/56

slide-22
SLIDE 22

Examples

  • 1. ((((π‘ž ∧ π‘Ÿ) β†’ (¬𝑠)) ∧ (π‘ž β†’ π‘Ÿ)) β†’ (π‘ž β†’ (¬𝑠)))
  • 2. ((((π‘ž ∧ π‘Ÿ) β†’ 𝑠) ∧ (π‘ž β†’ π‘Ÿ)) β†’ (π‘ž β†’ 𝑠))
  • 3. (π‘ž ∨ π‘Ÿ) ↔ ((π‘ž ∧ (Β¬π‘Ÿ)) ∨ ((Β¬π‘ž) ∧ π‘Ÿ))
  • 4. (π‘ž ∧ (Β¬π‘ž))

Semantics Properties of formulas 22/56

slide-23
SLIDE 23

A logic puzzle

Each of the four cards has a number on one side and a color on the other

  • side. How many cards do you have to turn over to test whether this

statement is true: β€œif a card has an even number on one side, then its

  • pposite side is red”?

Your answer is (a) 0 (b) 1 (c) 2 (d) 3 (e) 4.

Semantics Equivalence 23/56

slide-24
SLIDE 24

Propositional Logic: Semantics

Alice Gao

Lecture 5, September 21, 2017

Semantics Equivalence 24/56

slide-25
SLIDE 25

Announcements

Semantics Equivalence 25/56

slide-26
SLIDE 26

Clickers

  • What are they for? Active learning, engagement
  • Why do you ask us to answer twice? Peer instruction
  • If you choose to be here, please participate!

Semantics Equivalence 26/56

slide-27
SLIDE 27

Outline for today

  • How can we prove that two formulas have the same meaning?

(Logical equivalence)

  • Which set of connectives is suffjcient to express all possible formulas?

(Adequate set of connectives)

Semantics Equivalence 27/56

slide-28
SLIDE 28

Learning goals

Logical equivalence of formulas:

  • Prove that the logical equivalence of formulas using truth tables

and/or logical identities.

  • Describe strategies to prove logical equivalence using logical identities.
  • Translate a condition in a block of code into a propositional logic

formula.

  • Simplify code using truth tables and logical identities.
  • Determine whether a piece of code is live or dead using truth tables

and logical identities. Adequate set of connectives:

  • Prove that a set of connectives is an adequate set for propositional

logic by using truth tables and logical identities.

  • Prove that a set of connectives is not an adequate set for

propositional logic.

Semantics Equivalence 28/56

slide-29
SLIDE 29

Defjnition of logical equivalence

Two formulas 𝛽 and 𝛾 are logically equivalent if and only if they have the same value under any valuation.

  • 𝛽𝑒 = 𝛾𝑒, for every valuation 𝑒.
  • 𝛽 and 𝛾 must have the same fjnal column in their truth tables.
  • (𝛽 ↔ 𝛾) is a tautology.

Semantics Equivalence 29/56

slide-30
SLIDE 30

Why do we care about logical equivalence?

  • Will I lose marks if I provide a solution that is syntactically difgerent

but logically equivalent to the provided solution?

  • Do these two circuits behave the same way?
  • Do these two pieces of code fragments behave the same way?

Semantics Equivalence 30/56

slide-31
SLIDE 31

You already know one way of proving logical equivalent. What is it? Theorem: (((Β¬π‘ž) ∧ π‘Ÿ) ∨ π‘ž) ≑ (π‘ž ∨ π‘Ÿ).

Semantics Equivalence 31/56

slide-32
SLIDE 32

Logical Identities

Commutativity (𝛽 ∧ 𝛾) ≑ (𝛾 ∧ 𝛽) (𝛽 ∨ 𝛾) ≑ (𝛾 ∨ 𝛽) Associativity (𝛽 ∧ (𝛾 ∧ 𝛿)) ≑ ((𝛽 ∧ 𝛾) ∧ 𝛿) (𝛽 ∨ (𝛾 ∨ 𝛿)) ≑ ((𝛽 ∨ 𝛾) ∨ 𝛿) Distributivity (𝛽 ∨ (𝛾 ∧ 𝛿)) ≑ ((𝛽 ∨ 𝛾) ∧ (𝛽 ∨ 𝛿)) (𝛽 ∧ (𝛾 ∨ 𝛿)) ≑ ((𝛽 ∧ 𝛾) ∨ (𝛽 ∧ 𝛿)) Idempotence (𝛽 ∨ 𝛽) ≑ 𝛽 (𝛽 ∧ 𝛽) ≑ 𝛽 Double Negation (Β¬(¬𝛽)) ≑ 𝛽 De Morgan’s Laws (Β¬(𝛽 ∧ 𝛾)) ≑ ((¬𝛽) ∨ (¬𝛾)) (Β¬(𝛽 ∨ 𝛾)) ≑ ((¬𝛽) ∧ (¬𝛾))

Semantics Equivalence 32/56

slide-33
SLIDE 33

Logical Identities, cont’d

Simplifjcation I (Absorbtion) (𝛽 ∧ T) ≑ 𝛽 (𝛽 ∨ T) ≑ T (𝛽 ∧ F) ≑ F (𝛽 ∨ F) ≑ 𝛽 Simplifjcation II (𝛽 ∨ (𝛽 ∧ 𝛾)) ≑ 𝛽 (𝛽 ∧ (𝛽 ∨ 𝛾)) ≑ 𝛽 Implication (𝛽 β†’ 𝛾) ≑ ((¬𝛽) ∨ 𝛾) Contrapositive (𝛽 β†’ 𝛾) ≑ ((¬𝛾) β†’ (¬𝛽)) Equivalence (𝛽 ↔ 𝛾) ≑ ((𝛽 β†’ 𝛾) ∧ (𝛾 β†’ 𝛽)) Excluded Middle (𝛽 ∨ (¬𝛽)) ≑ T Contradiction (𝛽 ∧ (¬𝛽)) ≑ F

Semantics Equivalence 33/56

slide-34
SLIDE 34

A logical equivalence proof

Theorem: (((Β¬π‘ž) ∧ π‘Ÿ) ∨ π‘ž) ≑ (π‘ž ∨ π‘Ÿ). Proof: (((Β¬π‘ž) ∧ π‘Ÿ) ∨ π‘ž) ≑ (((Β¬π‘ž) ∨ π‘ž) ∧ (π‘Ÿ ∨ π‘ž)) Distributivity ... to be fjlled in ... ≑ (π‘Ÿ ∨ π‘ž) Simplifjcation I ≑ (π‘ž ∨ π‘Ÿ) Commutativity QED

Semantics Equivalence 34/56

slide-35
SLIDE 35

A logical equivalence proof

What is missing from the proof?

  • a. (π‘Ÿ ∨ π‘ž)
  • b. (F ∧ (π‘Ÿ ∨ π‘ž))
  • c. (π‘Ÿ ∧ (π‘Ÿ ∨ π‘ž))
  • d. None of these, but I know what it is.
  • e. None of these, and there’s not enough information to tell.

Theorem: (((Β¬π‘ž) ∧ π‘Ÿ) ∨ π‘ž) ≑ (π‘ž ∨ π‘Ÿ). Proof: (((Β¬π‘ž) ∧ π‘Ÿ) ∨ π‘ž) ≑ (((Β¬π‘ž) ∨ π‘ž) ∧ (π‘Ÿ ∨ π‘ž)) Distributivity ... to be fjlled in ... ≑ (π‘Ÿ ∨ π‘ž) Simplifjcation I ≑ (π‘ž ∨ π‘Ÿ) Commutativity QED

Semantics Equivalence 35/56

slide-36
SLIDE 36

A practice problem

”If it is sunny, I will play golf, provided that I am relaxed.” 𝑑: it is sunny. 𝑕: I will play golf. 𝑠: I am relaxed. A few translations:

  • 1. (𝑑 β†’ (𝑠 β†’ 𝑕))
  • 2. (𝑠 β†’ (𝑑 β†’ 𝑕))
  • 3. ((𝑑 ∧ 𝑠) β†’ 𝑕)

Theorem: (𝑠 β†’ (𝑑 β†’ 𝑕)) ≑ ((𝑑 ∧ 𝑠) β†’ 𝑕). Proof: ... to be fjlled in ... QED

Semantics Equivalence 36/56

slide-37
SLIDE 37

How do you prove non-equivalence?

”If it snows then I won’t go to class, but I will do my assignment.” 𝑑: it snows. 𝑑: I will go to class. 𝑏: I will do my assignment. 2 possible translations:

  • 1. ((𝑑 β†’ (¬𝑑)) ∧ 𝑏)
  • 2. (𝑑 β†’ ((¬𝑑) ∧ 𝑏))

Theorem: ((𝑑 β†’ (¬𝑑)) ∧ 𝑏) and (𝑑 β†’ ((¬𝑑) ∧ 𝑏)) are not logically equivalent. Which valuation 𝑒 can we use to prove this theorem?

  • a. 𝑑𝑒 = F, (¬𝑑)𝑒 = F, 𝑏𝑒 = F
  • b. 𝑑𝑒 = F, (¬𝑑)𝑒 = T, 𝑏𝑒 = F
  • c. 𝑑𝑒 = T, (¬𝑑)𝑒 = T, 𝑏𝑒 = T
  • d. Two of these.
  • e. All of these.

Semantics Equivalence 37/56

slide-38
SLIDE 38

Collected Wisdom

  • Try getting rid of β†’ and ↔.
  • Try moving negations inward. Β¬(π‘ž ∨ π‘Ÿ) ≑ (Β¬π‘ž) ∧ (Β¬π‘Ÿ).
  • Work from the more complex side fjrst, BUT
  • Switch to difgerent strategies/sides when you get stuck.
  • In the end, write the proof in clean β€œone-side-to-the-other” form and

double-check steps.

Semantics Equivalence 38/56

slide-39
SLIDE 39

A piece of pseudo code

if ( (input > 0) or (not output) ) { if ( not (output and (queuelength < 100) ) ) { 𝑄1 } else if ( output and (not (queuelength < 100)) ) { 𝑄2 } else { 𝑄3 } } else { 𝑄4 } When does each piece of code get executed? Let 𝑗: input > 0, 𝑣:

  • utput,

π‘Ÿ: queuelength < 100.

Semantics Conditional Code 39/56

slide-40
SLIDE 40

Simplifying the piece of pseudo code

if ( i or (not u) ) { if ( not (u and q) ) { 𝑄1 } else if ( u and (not q) ) { 𝑄2 } else { 𝑄3 } } else { 𝑄4 } Which one of the following is incorrect?

  • a. 𝑄1 is executed when (𝑗 ∨ (¬𝑣)) ∧ (Β¬(𝑣 ∧ π‘Ÿ)) is true.
  • b. 𝑄2 is executed when (𝑗 ∨ (¬𝑣)) ∧ (𝑣 ∧ (Β¬π‘Ÿ)) is true.
  • c. 𝑄3 is executed when ((𝑗 ∨ (¬𝑣)) ∧ (𝑣 ∧ π‘Ÿ)) ∧ ((¬𝑣) ∨ π‘Ÿ) is true.
  • d. 𝑄4 is executed when 𝑗 is false and 𝑣 is true.
  • e. All of them are correct.

Semantics Conditional Code 40/56

slide-41
SLIDE 41

A Code Example, cont’d

𝑗 𝑣 π‘Ÿ (𝑗 ∨ (¬𝑣)) (Β¬(𝑣 ∧ π‘Ÿ)) (𝑣 ∧ (Β¬π‘Ÿ)) T T T T F F 𝑄3 T T F T T 𝑄1 T F T T T 𝑄1 T F F T T 𝑄1 F T T F 𝑄4 F T F F 𝑄4 F F T T T 𝑄1 F F F T T 𝑄1

Semantics Conditional Code 41/56

slide-42
SLIDE 42

Finding Dead Code

Prove that 𝑄2 is dead code. That is, the conditions leading to 𝑄2 is logically equivalent to F. (((𝑗 ∨ (¬𝑣)) ∧ (Β¬(Β¬(𝑣 ∧ π‘Ÿ)))) ∧ (𝑣 ∧ (Β¬π‘Ÿ))) ... to be fjlled in ... ≑ F Simplifying the above condition to F will necessarily use the following logical identities.

  • a. Simplifjcation I
  • b. Excluded Middle
  • c. Contradiction
  • d. Two of the above
  • e. All of the above

Semantics Conditional Code 42/56

slide-43
SLIDE 43

Finding Live Code

Prove that 𝑄3 is live code. That is, the conditions leading to 𝑄3 is satisfjable. Theorem: ((𝑗 ∨ (¬𝑣)) ∧ ((Β¬(Β¬(𝑣 ∧ π‘Ÿ))) ∧ (Β¬(𝑣 ∧ (Β¬π‘Ÿ))))) ≑ ((𝑗 ∧ 𝑣) ∧ π‘Ÿ) Proof: ((𝑗 ∨ (¬𝑣)) ∧ ((Β¬(Β¬(𝑣 ∧ π‘Ÿ))) ∧ (Β¬(𝑣 ∧ (Β¬π‘Ÿ))))) ... to be fjlled in ... ≑ ((𝑗 ∧ 𝑣) ∧ π‘Ÿ) QED

Semantics Conditional Code 43/56

slide-44
SLIDE 44

Two pieces of code: Are they equivalent?

Fragment 1: if ( i or (not u) ) { if ( not (u and q) ) { 𝑄1 } else if ( u and (not q) ) { 𝑄2 } else { 𝑄3 } } else { 𝑄4 } Fragment 2: if ( (i and u) and q ) { 𝑄3 } else if ( (not i) and u ) { 𝑄4 } else { 𝑄1 }

Semantics Conditional Code 44/56

slide-45
SLIDE 45

Simplifying Code

To prove that the two fragments are equivalent, show that each block of code 𝑄1, 𝑄2, 𝑄3, and 𝑄4 is executed under equivalent conditions. Block Fragment 1 Fragment 2 𝑄1 (𝑗 ∨ (¬𝑣)) ∧ (Β¬(𝑣 ∧ π‘Ÿ)) (Β¬(𝑗 ∧ 𝑣 ∧ π‘Ÿ)) ∧ (Β¬((¬𝑗) ∧ 𝑣)) 𝑄2 (𝑗 ∨ (¬𝑣)) ∧ (Β¬(Β¬(𝑣 ∧ π‘Ÿ))) F ∧ (𝑣 ∧ (Β¬π‘Ÿ)) 𝑄3 (𝑗 ∨ (¬𝑣)) ∧ (Β¬(Β¬(𝑣 ∧ π‘Ÿ))) (𝑗 ∧ 𝑣 ∧ π‘Ÿ) ∧ (Β¬(𝑣 ∧ (Β¬π‘Ÿ))) 𝑄4 (Β¬(𝑗 ∨ (¬𝑣))) (Β¬(𝑗 ∧ 𝑣 ∧ π‘Ÿ)) ∧ ((¬𝑗) ∧ 𝑣)

Semantics Conditional Code 45/56

slide-46
SLIDE 46

The solution to the last logic puzzle

Each of the four cards has a number on one side and a color on the other

  • side. How many cards do you have to turn over to test whether this

statement is true: β€œif a card has an even number on one side, then its

  • pposite side is red”?

Solution: You need to turn over 2 cards. If a card has an even number on

  • ne side, then you need to check that its opposite side is red. Also, if a

card is NOT red, you need to check that its opposite side has an ODD number (this is the contrapositive of the given statement). Thus, you need to turn over the second card from the left and the fjrst card from the right.

Semantics Conditional Code 46/56

slide-47
SLIDE 47

Another logic puzzle

A very special island is inhabited only by knights and knaves. Knights always tell the truth, and knaves always lie. You meet three inhabitants: Alice, Rex and Bob. Alice says, β€œRex is a knave.” Rex says, β€œit’s false that Bob is a knave.” Bob claims, β€œI am a knight or Alice is a knight.” Can you determine who is a knight and who is a knave?

Semantics Conditional Code 47/56

slide-48
SLIDE 48

Adequate sets of connectives

Semantics Adequate Sets of Connectives 48/56

slide-49
SLIDE 49

Learning goals

  • Prove that a set of connectives is an adequate set for propositional

logic by using truth tables and logical identities.

  • Prove that a set of connectives is not an adequate set for

propositional logic.

Semantics Adequate Sets of Connectives 49/56

slide-50
SLIDE 50

Some questions fjrst

  • We started propositional logic by learning these connectives Β¬, ∧, ∨,

β†’ and ↔.

  • Why did we learn these connectives?
  • Using these connectives, can we express every propositional logic

formula that we ever want to write?

  • Are there any connectives in this set that are not necessary?
  • Are there other connectives that we could defjne and use? Is there

another set of connectives that we should have studied instead?

Semantics Adequate Sets of Connectives 50/56

slide-51
SLIDE 51

Some answers

Is every connective we learned necessary? Nope! Recall that 𝑦 β†’ 𝑧 ≑ (¬𝑦) ∨ 𝑧. We don’t need β†’ at all. (We say that β†’ is defjnable in terms of Β¬ and ∨.) Are there other connectives that we could defjne and use? Yep! Let’s take a look.

Semantics Adequate Sets of Connectives 51/56

slide-52
SLIDE 52

Adequate Sets of Connectives

Which set of connectives is suffjcient to express every possible propositional formula? This is called an adequate set of connectives. Any other connective connective is defjnable in terms of the ones in such a set. Theorem 1. {∧, ∨, Β¬} is an adequate set of connectives. Theorem 2. Each of the sets {∧, Β¬}, {∨, Β¬}, and {β†’, Β¬} is adequate. Theorem 3. The set {∧, ∨} is not an adequate set of connectives.

Semantics Adequate Sets of Connectives 52/56

slide-53
SLIDE 53

An adequate set to start with

Theorem 1. {∧, ∨, ¬} is an adequate set of connectives. Hint: use truth tables. How many people know a way to prove this theorem?

Semantics Adequate Sets of Connectives 53/56

slide-54
SLIDE 54

A reduction problem

Theorem 1. {∧, ∨, Β¬} is an adequate set of connectives. Now we can assume that theorem 1 holds. Theorem 2. Each of the sets {∧, Β¬}, {∨, Β¬}, and {β†’, Β¬} is adequate. By Theorem 1, the set {∧, ∨, Β¬} is adequate. To prove that {∧, Β¬} is adequate, we need to show that ∨ is defjnable in terms of ∧ and Β¬. To prove that {∨, Β¬} is adequate, we need to show that ∧ is defjnable in terms of ∨ and Β¬. To prove that {β†’, Β¬} is adequate, we need to show that each of ∨ and ∧ is defjnable in terms of β†’ and Β¬.

Semantics Adequate Sets of Connectives 54/56

slide-55
SLIDE 55

A non-adequate set

Theorem 3. The set {∧, ∨} is not an adequate set of connectives. Consider any formula which uses only ∧ and ∨ as connectives. Assume that every variable in the formula is true. What is the truth value of the formula?

  • a. Always true
  • b. Always false
  • c. Sometimes true and sometimes false
  • d. Not enough information to tell

Semantics Adequate Sets of Connectives 55/56

slide-56
SLIDE 56

A non-adequate set

Theorem 3. The set {∧, ∨} is not an adequate set of connectives. Lemma: For any formula which uses only ∧ and ∨ as connectives, if every variable in the formula is true, then the formula is true. This lemma means that it is impossible to negate a formula using only ∧ and ∨. We can prove the lemma using structural induction.

Semantics Adequate Sets of Connectives 56/56