discrete mathematics - electrical, computer & energy...

24
Discrete Mathematics Jeremy Siek Spring 2010 Jeremy Siek Discrete Mathematics 1 / 24

Upload: others

Post on 18-Oct-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Discrete Mathematics - Electrical, Computer & Energy ...ecee.colorado.edu/~siek/ecen3703/spring10/lecture3.pdf · Discrete Mathematics Jeremy Siek Spring 2010 Jeremy Siek Discrete

Discrete Mathematics

Jeremy Siek

Spring 2010

Jeremy Siek Discrete Mathematics 1 / 24

Page 2: Discrete Mathematics - Electrical, Computer & Energy ...ecee.colorado.edu/~siek/ecen3703/spring10/lecture3.pdf · Discrete Mathematics Jeremy Siek Spring 2010 Jeremy Siek Discrete

Outline of Lecture 3

1. Proofs and Isabelle

2. Proof Strategy, Forward and Backwards Reasoning

3. Making Mistakes

Jeremy Siek Discrete Mathematics 2 / 24

Page 3: Discrete Mathematics - Electrical, Computer & Energy ...ecee.colorado.edu/~siek/ecen3703/spring10/lecture3.pdf · Discrete Mathematics Jeremy Siek Spring 2010 Jeremy Siek Discrete

Theorems and Proofs

I In the context of propositional logic, a theorem is just a tautology.I In this course, we’ll be writing theorems and their proofs in the

Isabelle/Isar proof language.I Here’s the syntax for a theorem in Isabelle/Isar.

theorem "P"proof -

step 1step 2...step n

qedI Each step applies an inference rule to establish the truth of some

proposition.

Jeremy Siek Discrete Mathematics 3 / 24

Page 4: Discrete Mathematics - Electrical, Computer & Energy ...ecee.colorado.edu/~siek/ecen3703/spring10/lecture3.pdf · Discrete Mathematics Jeremy Siek Spring 2010 Jeremy Siek Discrete

Inference Rules

I When applying inference rules, use the keyword have to establishintermediate truths and use the keyword show to conclude thesurrounding theorem or sub-proof.

I Most inference rules can be categorized as either an introductionor elimination rule.

I Introduction rules are for creating bigger propositions.I Elimination rules are for using propositions.I We write “Li proves P ” if there is a preceeding step or assumption

in the proof that is labeled Li and whose proposition is P .

Jeremy Siek Discrete Mathematics 4 / 24

Page 5: Discrete Mathematics - Electrical, Computer & Energy ...ecee.colorado.edu/~siek/ecen3703/spring10/lecture3.pdf · Discrete Mathematics Jeremy Siek Spring 2010 Jeremy Siek Discrete

Introduction Rules

And If Li proves P and Lj proves Q, then write

from Li Lj have Lk: "P ∧ Q" ..

Or (1) If Li proves P , then write

from Li have Lk: "P ∨ Q" ..

Or (2) If Li proves Q, then write

from Li have Lk: "P ∨ Q" ..

Implies

have Lk: "P −→ Q"proof

assume Li: "P"...· · · show "Q" · · ·

qed

Jeremy Siek Discrete Mathematics 5 / 24

Page 6: Discrete Mathematics - Electrical, Computer & Energy ...ecee.colorado.edu/~siek/ecen3703/spring10/lecture3.pdf · Discrete Mathematics Jeremy Siek Spring 2010 Jeremy Siek Discrete

Introduction Rules, cont’d

Not have Lk: "¬ P"proof

assume Li: "P"...· · · show "False" · · ·

qed

Hint: The Appendix of our text Isabelle/HOL – A Proof Assistant forHigher-Order Logic lists the logical connectives, such as −→ and ¬, andfor each of them gives two ways to input them as ASCI text. If youuse Emacs (or XEmacs) to edit your Isabelle files, then the x-symbolpackage can be used to display the logic connectives in their traditionalform.

Jeremy Siek Discrete Mathematics 6 / 24

Page 7: Discrete Mathematics - Electrical, Computer & Energy ...ecee.colorado.edu/~siek/ecen3703/spring10/lecture3.pdf · Discrete Mathematics Jeremy Siek Spring 2010 Jeremy Siek Discrete

Using Assumptions

I Sometimes the thing you need to prove is already an assumption.In this case your job is really easy!

I If Li proves P , write

from Li have "P" .

Jeremy Siek Discrete Mathematics 7 / 24

Page 8: Discrete Mathematics - Electrical, Computer & Energy ...ecee.colorado.edu/~siek/ecen3703/spring10/lecture3.pdf · Discrete Mathematics Jeremy Siek Spring 2010 Jeremy Siek Discrete

Example Proof

theorem "p −→ p"

proof -

show "p −→ p"

proofassume 1: "p"

from 1 show "p" .qed

qed

Instead of proof -, you can apply the introduction ruleright away.

theorem "p −→ p"

proofassume 1: "p"

from 1 show "p" .qed

Jeremy Siek Discrete Mathematics 8 / 24

Page 9: Discrete Mathematics - Electrical, Computer & Energy ...ecee.colorado.edu/~siek/ecen3703/spring10/lecture3.pdf · Discrete Mathematics Jeremy Siek Spring 2010 Jeremy Siek Discrete

Exercise

theorem "p −→ (p ∧ p)"

Jeremy Siek Discrete Mathematics 9 / 24

Page 10: Discrete Mathematics - Electrical, Computer & Energy ...ecee.colorado.edu/~siek/ecen3703/spring10/lecture3.pdf · Discrete Mathematics Jeremy Siek Spring 2010 Jeremy Siek Discrete

Solution

theorem "p −→ (p ∧ p)"

proofassume 1: "p"

from 1 1 show "p ∧ p" ..qed

Jeremy Siek Discrete Mathematics 10 / 24

Page 11: Discrete Mathematics - Electrical, Computer & Energy ...ecee.colorado.edu/~siek/ecen3703/spring10/lecture3.pdf · Discrete Mathematics Jeremy Siek Spring 2010 Jeremy Siek Discrete

Elimination Rules

And (1) If Li proves P ∧Q, then write

from Li have Lk: "P" ..

And (2) If Li proves P ∧Q, then write

from Li have Lk: "Q" ..

Or If Li proves P ∨Q, then write

note Li

moreover { assume Lj: "P"...· · · have "R" · · ·} moreover { assume Lm: "Q"...· · · have "R" · · ·} ultimately have Lk: "R" ..

Jeremy Siek Discrete Mathematics 11 / 24

Page 12: Discrete Mathematics - Electrical, Computer & Energy ...ecee.colorado.edu/~siek/ecen3703/spring10/lecture3.pdf · Discrete Mathematics Jeremy Siek Spring 2010 Jeremy Siek Discrete

Elimination Rules, cont’d

Implies If Li proves P −→ Q and Lj proves P , then write

from Li Lj have Lk: "Q" ..

(This rule is known as modus ponens.)

Not If Li proves ¬P and Lj proves P , then write

from Li Lj have Lk: "Q" ..

False If Li proves False, then write

from Li have Lk: "P" ..

Jeremy Siek Discrete Mathematics 12 / 24

Page 13: Discrete Mathematics - Electrical, Computer & Energy ...ecee.colorado.edu/~siek/ecen3703/spring10/lecture3.pdf · Discrete Mathematics Jeremy Siek Spring 2010 Jeremy Siek Discrete

Example Proof

theorem "(p ∧ q) −→ (p ∨ q)"

proofassume 1: "p ∧ q"

from 1 have 2: "p" ..from 2 show "p ∨ q" ..

qed

Jeremy Siek Discrete Mathematics 13 / 24

Page 14: Discrete Mathematics - Electrical, Computer & Energy ...ecee.colorado.edu/~siek/ecen3703/spring10/lecture3.pdf · Discrete Mathematics Jeremy Siek Spring 2010 Jeremy Siek Discrete

Another Proof

theorem "(p ∨ q) ∧ (p −→ r) ∧ (q −→ r) −→ r"

proofassume 1: "(p ∨ q) ∧ (p −→ r) ∧ (q −→ r)"

from 1 have 2: "p ∨ q" ..from 1 have 3: "(p −→ r) ∧ (q −→ r)" ..from 3 have 4: "p −→ r" ..from 3 have 5: "q −→ r" ..note 2

moreover { assume 6: "p"

from 4 6 have "r" ..} moreover { assume 7: "q"

from 5 7 have "r" ..} ultimately show "r" ..

qed

Jeremy Siek Discrete Mathematics 14 / 24

Page 15: Discrete Mathematics - Electrical, Computer & Energy ...ecee.colorado.edu/~siek/ecen3703/spring10/lecture3.pdf · Discrete Mathematics Jeremy Siek Spring 2010 Jeremy Siek Discrete

Exercise

theorem "(p −→ q) ∧ (q −→ r) −→ (p −→ r)"

Jeremy Siek Discrete Mathematics 15 / 24

Page 16: Discrete Mathematics - Electrical, Computer & Energy ...ecee.colorado.edu/~siek/ecen3703/spring10/lecture3.pdf · Discrete Mathematics Jeremy Siek Spring 2010 Jeremy Siek Discrete

Solution

theorem "(p −→ q) ∧ (q −→ r) −→ (p −→ r)"

proofassume 1: "(p −→ q) ∧ (q −→ r)"

from 1 have 2: "p −→ q" ..from 1 have 3: "q −→ r" ..show "p −→ r"

proofassume 4: "p"

from 2 4 have 5: "q" ..from 3 5 show "r" ..

qedqed

Jeremy Siek Discrete Mathematics 16 / 24

Page 17: Discrete Mathematics - Electrical, Computer & Energy ...ecee.colorado.edu/~siek/ecen3703/spring10/lecture3.pdf · Discrete Mathematics Jeremy Siek Spring 2010 Jeremy Siek Discrete

Forward and Backwards Reasoning

And-Intro (forward) If Li proves P and Lj proves Q, then write

from Li Lj have Lk: "P ∧ Q" ..

And-Intro (backwards)

have Lk: "P ∧ Q"proof

...· · · show "P" · · ·

next...· · · show "Q" · · ·

qed

Jeremy Siek Discrete Mathematics 17 / 24

Page 18: Discrete Mathematics - Electrical, Computer & Energy ...ecee.colorado.edu/~siek/ecen3703/spring10/lecture3.pdf · Discrete Mathematics Jeremy Siek Spring 2010 Jeremy Siek Discrete

Forward and Backwards Reasoning, cont’d

Or-Intro (1) (forwards) If Li proves P , then write

from Li have Lk: "P ∨ Q" ..

Or-Intro (1) (backwards)

have Lk: "P ∨ Q"proof (rule disjI1)

...· · · show "P" · · ·

qed

Jeremy Siek Discrete Mathematics 18 / 24

Page 19: Discrete Mathematics - Electrical, Computer & Energy ...ecee.colorado.edu/~siek/ecen3703/spring10/lecture3.pdf · Discrete Mathematics Jeremy Siek Spring 2010 Jeremy Siek Discrete

Forward and Backwards Reasoning, cont’d

Or-Intro (2) (forwards) If Li proves Q, then write

from Li have Lk: "P ∨ Q" ..

Or-Intro (2) (backwards)

have Lk: "P ∨ Q"proof (rule disjI2)

...· · · show "Q" · · ·

qed

Jeremy Siek Discrete Mathematics 19 / 24

Page 20: Discrete Mathematics - Electrical, Computer & Energy ...ecee.colorado.edu/~siek/ecen3703/spring10/lecture3.pdf · Discrete Mathematics Jeremy Siek Spring 2010 Jeremy Siek Discrete

Strategy

I Let the proposition you’re trying to prove guide your proof.I Find the top-most logical connective.I Apply the introduction rule, backwards, for that connective.I Keep doing that until what you need to prove no longer contains

any logical connectives.I Then work forwards from your assumptions (using elimination

rules) until you’ve proved what you need.

ConclusionAssumption

BackwardsReasoning

ForwardsReasoning

Assumption

Jeremy Siek Discrete Mathematics 20 / 24

Page 21: Discrete Mathematics - Electrical, Computer & Energy ...ecee.colorado.edu/~siek/ecen3703/spring10/lecture3.pdf · Discrete Mathematics Jeremy Siek Spring 2010 Jeremy Siek Discrete

Making Mistakes

I To err is human.I Isabelle will catch your mistakes.I Unfortunately, Isabelle is bad at describing your mistake.I Consider the following attempted proof

theorem "p −→ (p ∧ p)"

proof -

show "p −→ (p ∧ p)"

proofassume 1: "p"

from 1 show "p ∧ p"

I When Isabelle gets to from 1 show "p ∧ p" (adding .. at theend), it gives the following response:

Failed to finish proofAt command "..".

Jeremy Siek Discrete Mathematics 21 / 24

Page 22: Discrete Mathematics - Electrical, Computer & Energy ...ecee.colorado.edu/~siek/ecen3703/spring10/lecture3.pdf · Discrete Mathematics Jeremy Siek Spring 2010 Jeremy Siek Discrete

Making Mistakes, cont’d

I In this case, the mistake was a missing label in the from clause.Conjuction introduction requires two premises, not one. Here’sthe fix:

theorem "p −→ (p ∧ p)"

proof -

show "p −→ (p ∧ p)"

proofassume 1: "p"

from 1 1 show "p ∧ p" ..qed

qed

I When Isablle says “no”, double check the inference rule. If thatdoesn’t work, get a classmate to look at it. If that doesn’t work,email the instructor with the minimal Isabelle file that exhibitsyour problem.

Jeremy Siek Discrete Mathematics 22 / 24

Page 23: Discrete Mathematics - Electrical, Computer & Energy ...ecee.colorado.edu/~siek/ecen3703/spring10/lecture3.pdf · Discrete Mathematics Jeremy Siek Spring 2010 Jeremy Siek Discrete

Making Mistakes, cont’d

I Here’s another proof with a typo:

theorem "p −→ p"proof

assume 1: "p"from 1 show "q" .

qedI Isabelle responds with:

Local statement will fail to refine any pending goal

Failed attempt to solve goal by exported rule:

(p) =⇒ qAt command "show".

I The problem here is that the proposition in the show "q", doesnot match what we are trying to prove, which is p.

Jeremy Siek Discrete Mathematics 23 / 24

Page 24: Discrete Mathematics - Electrical, Computer & Energy ...ecee.colorado.edu/~siek/ecen3703/spring10/lecture3.pdf · Discrete Mathematics Jeremy Siek Spring 2010 Jeremy Siek Discrete

Stuff to Rememeber

I How to write Isabelle/Isar proofs of tautologies in PropositionalLogic.

I The introduction and elimination rules.I Forwards and backwards reasoning.

Jeremy Siek Discrete Mathematics 24 / 24