a = b c . . . 1 C ONTENT Intro & motivation, getting started - - PowerPoint PPT Presentation

a b c
SMART_READER_LITE
LIVE PREVIEW

a = b c . . . 1 C ONTENT Intro & motivation, getting started - - PowerPoint PPT Presentation

NICTA Advanced Course Theorem Proving Principles, Techniques, Applications a = b c . . . 1 C ONTENT Intro & motivation, getting started with Isabelle Foundations & Principles Lambda Calculus Higher Order Logic,


slide-1
SLIDE 1

NICTA Advanced Course Theorem Proving Principles, Techniques, Applications

a = b ≤ c ≤ . . .

1

slide-2
SLIDE 2

CONTENT

➜ Intro & motivation, getting started with Isabelle ➜ Foundations & Principles

  • Lambda Calculus
  • Higher Order Logic, natural deduction
  • Term rewriting

➜ Proof & Specification Techniques

  • Inductively defined sets, rule induction
  • Datatypes, recursion, induction
  • More recursion, Calculational reasoning
  • Hoare logic, proofs about programs
  • Locales, Presentation

CONTENT 2

slide-3
SLIDE 3

LAST WEEK

➜ Constructive Logic & Curry-Howard-Isomorphism

LAST WEEK 3

slide-4
SLIDE 4

LAST WEEK

➜ Constructive Logic & Curry-Howard-Isomorphism ➜ The Coq System

LAST WEEK 3-A

slide-5
SLIDE 5

LAST WEEK

➜ Constructive Logic & Curry-Howard-Isomorphism ➜ The Coq System ➜ The HOL4 system

LAST WEEK 3-B

slide-6
SLIDE 6

LAST WEEK

➜ Constructive Logic & Curry-Howard-Isomorphism ➜ The Coq System ➜ The HOL4 system ➜ Before that: datatypes, recursion, induction

LAST WEEK 3-C

slide-7
SLIDE 7

GENERAL RECURSION

The Choice

GENERAL RECURSION 4

slide-8
SLIDE 8

GENERAL RECURSION

The Choice

➜ Limited expressiveness, automatic termination

  • primrec

GENERAL RECURSION 4-A

slide-9
SLIDE 9

GENERAL RECURSION

The Choice

➜ Limited expressiveness, automatic termination

  • primrec

➜ High expressiveness, prove termination manually

  • recdef

GENERAL RECURSION 4-B

slide-10
SLIDE 10

RECDEF — EXAMPLES

consts sep :: ”’a × ’a list ⇒ ’a list” recdef sep ”measure (λ(a, xs). size xs)” ”sep (a, x # y # zs) = x # a # sep (a, y # zs)” ”sep (a, xs) = xs”

RECDEF — EXAMPLES

5

slide-11
SLIDE 11

RECDEF — EXAMPLES

consts sep :: ”’a × ’a list ⇒ ’a list” recdef sep ”measure (λ(a, xs). size xs)” ”sep (a, x # y # zs) = x # a # sep (a, y # zs)” ”sep (a, xs) = xs” consts ack :: ”nat × nat ⇒ nat” recdef ack ”measure (λm. m) <*lex*> measure (λn. n)” ”ack (0, n) = Suc n” ”ack (Suc m, 0) = ack (m, 1)” ”ack (Suc m, Suc n) = ack (m, ack (Suc m, n))”

RECDEF — EXAMPLES

5-A

slide-12
SLIDE 12

RECDEF

➜ The definiton:

  • one parameter
  • free pattern matching, order of rules important
  • termination relation

(measure sufficient for most cases)

RECDEF

6

slide-13
SLIDE 13

RECDEF

➜ The definiton:

  • one parameter
  • free pattern matching, order of rules important
  • termination relation

(measure sufficient for most cases) ➜ Termination relation:

  • must decrease for each recursive call
  • must be well founded

RECDEF

6-A

slide-14
SLIDE 14

RECDEF

➜ The definiton:

  • one parameter
  • free pattern matching, order of rules important
  • termination relation

(measure sufficient for most cases) ➜ Termination relation:

  • must decrease for each recursive call
  • must be well founded

➜ Generates own induction principle

RECDEF

6-B

slide-15
SLIDE 15

RECDEF — INDUCTION PRINCIPLE

➜ Each recdef definition induces an induction principle

RECDEF — INDUCTION PRINCIPLE

7

slide-16
SLIDE 16

RECDEF — INDUCTION PRINCIPLE

➜ Each recdef definition induces an induction principle ➜ For each equation: show that the property holds for the lhs provided it holds for each recursive call on the rhs

RECDEF — INDUCTION PRINCIPLE

7-A

slide-17
SLIDE 17

RECDEF — INDUCTION PRINCIPLE

➜ Each recdef definition induces an induction principle ➜ For each equation: show that the property holds for the lhs provided it holds for each recursive call on the rhs ➜ Example sep.induct: [ [ V a. P a []; V a w. P a [w] V a x y zs. P a (y#zs) = ⇒ P a (x#y#zs); ] ] = ⇒ P a xs

RECDEF — INDUCTION PRINCIPLE

7-B

slide-18
SLIDE 18

TERMINATION

Isabelle tries to prove termination automatically

➜ For most functions and termination relations this works.

TERMINATION 8

slide-19
SLIDE 19

TERMINATION

Isabelle tries to prove termination automatically

➜ For most functions and termination relations this works. ➜ Sometimes not

TERMINATION 8-A

slide-20
SLIDE 20

TERMINATION

Isabelle tries to prove termination automatically

➜ For most functions and termination relations this works. ➜ Sometimes not ⇒ error message with unsolved subgoal

TERMINATION 8-B

slide-21
SLIDE 21

TERMINATION

Isabelle tries to prove termination automatically

➜ For most functions and termination relations this works. ➜ Sometimes not ⇒ error message with unsolved subgoal ➜ You can give hints (additional lemmas) to the recdef package: recdef quicksort ”measure length” quicksort [] = [] quicksort (x#xs) = quicksort [y ∈ xs.y ≤ x]@[x]@ quicksort [y ∈ xs.x < y] (hints recdef simp: less Suc eq le)

TERMINATION 8-C

slide-22
SLIDE 22

TERMINATION

Isabelle tries to prove termination automatically

➜ For most functions and termination relations this works. ➜ Sometimes not ⇒ error message with unsolved subgoal ➜ You can give hints (additional lemmas) to the recdef package: recdef quicksort ”measure length” quicksort [] = [] quicksort (x#xs) = quicksort [y ∈ xs.y ≤ x]@[x]@ quicksort [y ∈ xs.x < y] (hints recdef simp: less Suc eq le)

For exploration:

➜ allow failing termination proof

TERMINATION 8-D

slide-23
SLIDE 23

TERMINATION

Isabelle tries to prove termination automatically

➜ For most functions and termination relations this works. ➜ Sometimes not ⇒ error message with unsolved subgoal ➜ You can give hints (additional lemmas) to the recdef package: recdef quicksort ”measure length” quicksort [] = [] quicksort (x#xs) = quicksort [y ∈ xs.y ≤ x]@[x]@ quicksort [y ∈ xs.x < y] (hints recdef simp: less Suc eq le)

For exploration:

➜ allow failing termination proof ➜ recdef (permissive) quicksort ”measure length”

TERMINATION 8-E

slide-24
SLIDE 24

TERMINATION

Isabelle tries to prove termination automatically

➜ For most functions and termination relations this works. ➜ Sometimes not ⇒ error message with unsolved subgoal ➜ You can give hints (additional lemmas) to the recdef package: recdef quicksort ”measure length” quicksort [] = [] quicksort (x#xs) = quicksort [y ∈ xs.y ≤ x]@[x]@ quicksort [y ∈ xs.x < y] (hints recdef simp: less Suc eq le)

For exploration:

➜ allow failing termination proof ➜ recdef (permissive) quicksort ”measure length” ➜ termination conditions as assumption in simp and induct rules

TERMINATION 8-F

slide-25
SLIDE 25

DEMO

9

slide-26
SLIDE 26

HOW DOES RECDEF WORK?

We need: general recursion operator

HOW DOES RECDEF WORK? 10

slide-27
SLIDE 27

HOW DOES RECDEF WORK?

We need: general recursion operator something like: rec F = F (rec F)

HOW DOES RECDEF WORK? 10-A

slide-28
SLIDE 28

HOW DOES RECDEF WORK?

We need: general recursion operator something like: rec F = F (rec F)

(F stands for the recursion equations)

Example:

HOW DOES RECDEF WORK? 10-B

slide-29
SLIDE 29

HOW DOES RECDEF WORK?

We need: general recursion operator something like: rec F = F (rec F)

(F stands for the recursion equations)

Example:

➜ recursion equations: f = 0 f (Suc n) = fn

HOW DOES RECDEF WORK? 10-C

slide-30
SLIDE 30

HOW DOES RECDEF WORK?

We need: general recursion operator something like: rec F = F (rec F)

(F stands for the recursion equations)

Example:

➜ recursion equations: f = 0 f (Suc n) = fn ➜ as one λ-term: f = λn′. case n′ of 0 ⇒ 0 | Suc n ⇒ f n

HOW DOES RECDEF WORK? 10-D

slide-31
SLIDE 31

HOW DOES RECDEF WORK?

We need: general recursion operator something like: rec F = F (rec F)

(F stands for the recursion equations)

Example:

➜ recursion equations: f = 0 f (Suc n) = fn ➜ as one λ-term: f = λn′. case n′ of 0 ⇒ 0 | Suc n ⇒ f n ➜ functor: F = λf. λn′. case n′ of 0 ⇒ 0 | Suc n ⇒ f n

HOW DOES RECDEF WORK? 10-E

slide-32
SLIDE 32

HOW DOES RECDEF WORK?

We need: general recursion operator something like: rec F = F (rec F)

(F stands for the recursion equations)

Example:

➜ recursion equations: f = 0 f (Suc n) = fn ➜ as one λ-term: f = λn′. case n′ of 0 ⇒ 0 | Suc n ⇒ f n ➜ functor: F = λf. λn′. case n′ of 0 ⇒ 0 | Suc n ⇒ f n ➜ rec :: ((α ⇒ β) ⇒ (α ⇒ β)) ⇒ (α ⇒ β) like above cannot exist in HOL (only total functions) ➜ But ’guarded’ form possible: wfrec :: (α × α) set ⇒ ((α ⇒ β) ⇒ (α ⇒ β)) ⇒ (α ⇒ β) ➜ (α × α) set a well founded order, decreasing with execution

HOW DOES RECDEF WORK? 10-F

slide-33
SLIDE 33

HOW DOES RECDEF WORK?

Why rec F = F (rec F)?

HOW DOES RECDEF WORK? 11

slide-34
SLIDE 34

HOW DOES RECDEF WORK?

Why rec F = F (rec F)? Because we want the recursion equations to hold. Example: F ≡ λg. λn′. case n′ of 0 ⇒ 0 | Suc n ⇒ g n f ≡ rec F

HOW DOES RECDEF WORK? 11-A

slide-35
SLIDE 35

HOW DOES RECDEF WORK?

Why rec F = F (rec F)? Because we want the recursion equations to hold. Example: F ≡ λg. λn′. case n′ of 0 ⇒ 0 | Suc n ⇒ g n f ≡ rec F f 0 = rec F 0

HOW DOES RECDEF WORK? 11-B

slide-36
SLIDE 36

HOW DOES RECDEF WORK?

Why rec F = F (rec F)? Because we want the recursion equations to hold. Example: F ≡ λg. λn′. case n′ of 0 ⇒ 0 | Suc n ⇒ g n f ≡ rec F f 0 = rec F 0 . . . = F (rec F) 0

HOW DOES RECDEF WORK? 11-C

slide-37
SLIDE 37

HOW DOES RECDEF WORK?

Why rec F = F (rec F)? Because we want the recursion equations to hold. Example: F ≡ λg. λn′. case n′ of 0 ⇒ 0 | Suc n ⇒ g n f ≡ rec F f 0 = rec F 0 . . . = F (rec F) 0 . . . = (λg. λn′. case n′ of 0 ⇒ 0| Suc n ⇒ g n) (rec F) 0

HOW DOES RECDEF WORK? 11-D

slide-38
SLIDE 38

HOW DOES RECDEF WORK?

Why rec F = F (rec F)? Because we want the recursion equations to hold. Example: F ≡ λg. λn′. case n′ of 0 ⇒ 0 | Suc n ⇒ g n f ≡ rec F f 0 = rec F 0 . . . = F (rec F) 0 . . . = (λg. λn′. case n′ of 0 ⇒ 0| Suc n ⇒ g n) (rec F) 0 . . . = (case 0 of 0 ⇒ 0 | Suc n ⇒ rec F n)

HOW DOES RECDEF WORK? 11-E

slide-39
SLIDE 39

HOW DOES RECDEF WORK?

Why rec F = F (rec F)? Because we want the recursion equations to hold. Example: F ≡ λg. λn′. case n′ of 0 ⇒ 0 | Suc n ⇒ g n f ≡ rec F f 0 = rec F 0 . . . = F (rec F) 0 . . . = (λg. λn′. case n′ of 0 ⇒ 0| Suc n ⇒ g n) (rec F) 0 . . . = (case 0 of 0 ⇒ 0 | Suc n ⇒ rec F n) . . . =

HOW DOES RECDEF WORK? 11-F

slide-40
SLIDE 40

WELL FOUNDED ORDERS

Definition <r is well founded if well founded induction holds wf r ≡ ∀P. (∀x. (∀y <r x.P y) − → P x) − → (∀x. P x)

WELL FOUNDED ORDERS 12

slide-41
SLIDE 41

WELL FOUNDED ORDERS

Definition <r is well founded if well founded induction holds wf r ≡ ∀P. (∀x. (∀y <r x.P y) − → P x) − → (∀x. P x) Well founded induction rule: wf r

  • x. (∀y <r x.Py) =

⇒ Px Pa

WELL FOUNDED ORDERS 12-A

slide-42
SLIDE 42

WELL FOUNDED ORDERS

Definition <r is well founded if well founded induction holds wf r ≡ ∀P. (∀x. (∀y <r x.P y) − → P x) − → (∀x. P x) Well founded induction rule: wf r

  • x. (∀y <r x.Py) =

⇒ Px Pa Alternative definition (equivalent): there are no infi nite descending chains, or (equivalent): every nonempty set has a minimal element wrt <r min r Q x ≡ ∀y ∈ Q. y <r x wf r = (∀Q = {}. ∃m ∈ Q. min r Q m)

WELL FOUNDED ORDERS 12-B

slide-43
SLIDE 43

WELL FOUNDED ORDERS: EXAMPLES

➜ < on I N is well founded well founded induction = complete induction

WELL FOUNDED ORDERS: EXAMPLES 13

slide-44
SLIDE 44

WELL FOUNDED ORDERS: EXAMPLES

➜ < on I N is well founded well founded induction = complete induction ➜ > and ≤ on I N are not well founded

WELL FOUNDED ORDERS: EXAMPLES 13-A

slide-45
SLIDE 45

WELL FOUNDED ORDERS: EXAMPLES

➜ < on I N is well founded well founded induction = complete induction ➜ > and ≤ on I N are not well founded ➜ x <r y = x dvd y ∧ x = 1 on I N is well founded the minimal elements are the prime numbers

WELL FOUNDED ORDERS: EXAMPLES 13-B

slide-46
SLIDE 46

WELL FOUNDED ORDERS: EXAMPLES

➜ < on I N is well founded well founded induction = complete induction ➜ > and ≤ on I N are not well founded ➜ x <r y = x dvd y ∧ x = 1 on I N is well founded the minimal elements are the prime numbers ➜ (a, b) <r (x, y) = a <1 x ∨ a = x ∧ b <1 y is well founded if <1 and <2 are

WELL FOUNDED ORDERS: EXAMPLES 13-C

slide-47
SLIDE 47

WELL FOUNDED ORDERS: EXAMPLES

➜ < on I N is well founded well founded induction = complete induction ➜ > and ≤ on I N are not well founded ➜ x <r y = x dvd y ∧ x = 1 on I N is well founded the minimal elements are the prime numbers ➜ (a, b) <r (x, y) = a <1 x ∨ a = x ∧ b <1 y is well founded if <1 and <2 are ➜ A <r B = A ⊂ B ∧ finite B is well founded

WELL FOUNDED ORDERS: EXAMPLES 13-D

slide-48
SLIDE 48

WELL FOUNDED ORDERS: EXAMPLES

➜ < on I N is well founded well founded induction = complete induction ➜ > and ≤ on I N are not well founded ➜ x <r y = x dvd y ∧ x = 1 on I N is well founded the minimal elements are the prime numbers ➜ (a, b) <r (x, y) = a <1 x ∨ a = x ∧ b <1 y is well founded if <1 and <2 are ➜ A <r B = A ⊂ B ∧ finite B is well founded ➜ ⊆ and ⊂ in general are not well founded

More about well founded relations: Term Rewriting and All That

WELL FOUNDED ORDERS: EXAMPLES 13-E

slide-49
SLIDE 49

THE RECURSION OPERATOR

Back to recursion: rec F = F (rec F) not possible Idea:

THE RECURSION OPERATOR 14

slide-50
SLIDE 50

THE RECURSION OPERATOR

Back to recursion: rec F = F (rec F) not possible Idea: have wfrec R F where R is well founded

THE RECURSION OPERATOR 14-A

slide-51
SLIDE 51

THE RECURSION OPERATOR

Back to recursion: rec F = F (rec F) not possible Idea: have wfrec R F where R is well founded Cut:

➜ only do recursion if parameter decreases wrt R ➜ otherwise: abort

THE RECURSION OPERATOR 14-B

slide-52
SLIDE 52

THE RECURSION OPERATOR

Back to recursion: rec F = F (rec F) not possible Idea: have wfrec R F where R is well founded Cut:

➜ only do recursion if parameter decreases wrt R ➜ otherwise: abort ➜ arbitrary :: α cut :: (α ⇒ β) ⇒ (α × α) set ⇒ α ⇒ (α ⇒ β) cut G R x ≡ λy. if (y, x) ∈ R then G y else arbitrary

THE RECURSION OPERATOR 14-C

slide-53
SLIDE 53

THE RECURSION OPERATOR

Back to recursion: rec F = F (rec F) not possible Idea: have wfrec R F where R is well founded Cut:

➜ only do recursion if parameter decreases wrt R ➜ otherwise: abort ➜ arbitrary :: α cut :: (α ⇒ β) ⇒ (α × α) set ⇒ α ⇒ (α ⇒ β) cut G R x ≡ λy. if (y, x) ∈ R then G y else arbitrary

wf R = ⇒ wfrec R F x = F (cut (wfrec R F) R x) x

THE RECURSION OPERATOR 14-D

slide-54
SLIDE 54

THE RECURSION OPERATOR

Admissible recursion

➜ recursive call for x only depends on parameters y <R x ➜ describes exactly one function if R is well founded

THE RECURSION OPERATOR 15

slide-55
SLIDE 55

THE RECURSION OPERATOR

Admissible recursion

➜ recursive call for x only depends on parameters y <R x ➜ describes exactly one function if R is well founded adm wf R F ≡ ∀f g x. (∀z. (z, x) ∈ R − → f z = g z) − → F f x = F g x

THE RECURSION OPERATOR 15-A

slide-56
SLIDE 56

THE RECURSION OPERATOR

Admissible recursion

➜ recursive call for x only depends on parameters y <R x ➜ describes exactly one function if R is well founded adm wf R F ≡ ∀f g x. (∀z. (z, x) ∈ R − → f z = g z) − → F f x = F g x

Definition of wf rec: again fi rst by induction, then by epsilon (x, ) ∈ wfrec rel R F

THE RECURSION OPERATOR 15-B

slide-57
SLIDE 57

THE RECURSION OPERATOR

Admissible recursion

➜ recursive call for x only depends on parameters y <R x ➜ describes exactly one function if R is well founded adm wf R F ≡ ∀f g x. (∀z. (z, x) ∈ R − → f z = g z) − → F f x = F g x

Definition of wf rec: again fi rst by induction, then by epsilon (x, F g x) ∈ wfrec rel R F

THE RECURSION OPERATOR 15-C

slide-58
SLIDE 58

THE RECURSION OPERATOR

Admissible recursion

➜ recursive call for x only depends on parameters y <R x ➜ describes exactly one function if R is well founded adm wf R F ≡ ∀f g x. (∀z. (z, x) ∈ R − → f z = g z) − → F f x = F g x

Definition of wf rec: again fi rst by induction, then by epsilon ∀z. (z, x) ∈ R − → (z, g z) ∈ wfrec rel R F (x, F g x) ∈ wfrec rel R F

THE RECURSION OPERATOR 15-D

slide-59
SLIDE 59

THE RECURSION OPERATOR

Admissible recursion

➜ recursive call for x only depends on parameters y <R x ➜ describes exactly one function if R is well founded adm wf R F ≡ ∀f g x. (∀z. (z, x) ∈ R − → f z = g z) − → F f x = F g x

Definition of wf rec: again fi rst by induction, then by epsilon ∀z. (z, x) ∈ R − → (z, g z) ∈ wfrec rel R F (x, F g x) ∈ wfrec rel R F wfrec R F x ≡ THE y. (x, y) ∈ wfrec rel R (λf x. F (cut f R x) x)

More: John Harrison, Inductive definitions: automation and application

THE RECURSION OPERATOR 15-E

slide-60
SLIDE 60

DEMO

16

slide-61
SLIDE 61

CALCULATIONAL REASONING

17

slide-62
SLIDE 62

THE GOAL

x · x−1 = 1 · (x · x−1) . . . = 1 · x · x−1 . . . = (x−1)−1 · x−1 · x · x−1 . . . = (x−1)−1 · (x−1 · x) · x−1 . . . = (x−1)−1 · 1 · x−1 . . . = (x−1)−1 · (1 · x−1) . . . = (x−1)−1 · x−1 . . . = 1

THE GOAL 18

slide-63
SLIDE 63

THE GOAL

x · x−1 = 1 · (x · x−1) . . . = 1 · x · x−1 . . . = (x−1)−1 · x−1 · x · x−1 . . . = (x−1)−1 · (x−1 · x) · x−1 . . . = (x−1)−1 · 1 · x−1 . . . = (x−1)−1 · (1 · x−1) . . . = (x−1)−1 · x−1 . . . = 1 Can we do this in Isabelle?

THE GOAL 18-A

slide-64
SLIDE 64

THE GOAL

x · x−1 = 1 · (x · x−1) . . . = 1 · x · x−1 . . . = (x−1)−1 · x−1 · x · x−1 . . . = (x−1)−1 · (x−1 · x) · x−1 . . . = (x−1)−1 · 1 · x−1 . . . = (x−1)−1 · (1 · x−1) . . . = (x−1)−1 · x−1 . . . = 1 Can we do this in Isabelle?

➜ Simplifier: too eager

THE GOAL 18-B

slide-65
SLIDE 65

THE GOAL

x · x−1 = 1 · (x · x−1) . . . = 1 · x · x−1 . . . = (x−1)−1 · x−1 · x · x−1 . . . = (x−1)−1 · (x−1 · x) · x−1 . . . = (x−1)−1 · 1 · x−1 . . . = (x−1)−1 · (1 · x−1) . . . = (x−1)−1 · x−1 . . . = 1 Can we do this in Isabelle?

➜ Simplifier: too eager ➜ Manual: difficult in apply stile

THE GOAL 18-C

slide-66
SLIDE 66

THE GOAL

x · x−1 = 1 · (x · x−1) . . . = 1 · x · x−1 . . . = (x−1)−1 · x−1 · x · x−1 . . . = (x−1)−1 · (x−1 · x) · x−1 . . . = (x−1)−1 · 1 · x−1 . . . = (x−1)−1 · (1 · x−1) . . . = (x−1)−1 · x−1 . . . = 1 Can we do this in Isabelle?

➜ Simplifier: too eager ➜ Manual: difficult in apply stile ➜ Isar: with the methods we know, too verbose

THE GOAL 18-D

slide-67
SLIDE 67

CHAINS OF EQUATIONS

The Problem a = b . . . = c . . . = d shows a = d by transitivity of =

CHAINS OF EQUATIONS 19

slide-68
SLIDE 68

CHAINS OF EQUATIONS

The Problem a = b . . . = c . . . = d shows a = d by transitivity of = Each step usually nontrivial (requires own subproof)

CHAINS OF EQUATIONS 19-A

slide-69
SLIDE 69

CHAINS OF EQUATIONS

The Problem a = b . . . = c . . . = d shows a = d by transitivity of = Each step usually nontrivial (requires own subproof) Solution in Isar:

➜ Keywords also and finally to delimit steps

CHAINS OF EQUATIONS 19-B

slide-70
SLIDE 70

CHAINS OF EQUATIONS

The Problem a = b . . . = c . . . = d shows a = d by transitivity of = Each step usually nontrivial (requires own subproof) Solution in Isar:

➜ Keywords also and finally to delimit steps ➜ . . . : predefined schematic term variable, refers to right hand side of last expression

CHAINS OF EQUATIONS 19-C

slide-71
SLIDE 71

CHAINS OF EQUATIONS

The Problem a = b . . . = c . . . = d shows a = d by transitivity of = Each step usually nontrivial (requires own subproof) Solution in Isar:

➜ Keywords also and finally to delimit steps ➜ . . . : predefined schematic term variable, refers to right hand side of last expression ➜ Automatic use of transitivity rules to connect steps

CHAINS OF EQUATIONS 19-D

slide-72
SLIDE 72

ALSO/FINALLY

have ”t0 = t1” [proof] also

ALSO/FINALLY

20

slide-73
SLIDE 73

ALSO/FINALLY

have ”t0 = t1” [proof] calculation register also ”t0 = t1”

ALSO/FINALLY

20-A

slide-74
SLIDE 74

ALSO/FINALLY

have ”t0 = t1” [proof] calculation register also ”t0 = t1” have ”. . . = t2” [proof]

ALSO/FINALLY

20-B

slide-75
SLIDE 75

ALSO/FINALLY

have ”t0 = t1” [proof] calculation register also ”t0 = t1” have ”. . . = t2” [proof] also ”t0 = t2”

ALSO/FINALLY

20-C

slide-76
SLIDE 76

ALSO/FINALLY

have ”t0 = t1” [proof] calculation register also ”t0 = t1” have ”. . . = t2” [proof] also ”t0 = t2” . . . . . . also ”t0 = tn−1”

ALSO/FINALLY

20-D

slide-77
SLIDE 77

ALSO/FINALLY

have ”t0 = t1” [proof] calculation register also ”t0 = t1” have ”. . . = t2” [proof] also ”t0 = t2” . . . . . . also ”t0 = tn−1” have ”· · · = tn” [proof]

ALSO/FINALLY

20-E

slide-78
SLIDE 78

ALSO/FINALLY

have ”t0 = t1” [proof] calculation register also ”t0 = t1” have ”. . . = t2” [proof] also ”t0 = t2” . . . . . . also ”t0 = tn−1” have ”· · · = tn” [proof] finally t0 = tn

ALSO/FINALLY

20-F

slide-79
SLIDE 79

ALSO/FINALLY

have ”t0 = t1” [proof] calculation register also ”t0 = t1” have ”. . . = t2” [proof] also ”t0 = t2” . . . . . . also ”t0 = tn−1” have ”· · · = tn” [proof] finally t0 = tn show P —’fi nally’ pipes fact ”t0 = tn” into the proof

ALSO/FINALLY

20-G

slide-80
SLIDE 80

MORE ABOUT ALSO

➜ Works for all combinations of =, ≤ and <.

MORE ABOUT ALSO 21

slide-81
SLIDE 81

MORE ABOUT ALSO

➜ Works for all combinations of =, ≤ and <. ➜ Uses all rules declared as [trans].

MORE ABOUT ALSO 21-A

slide-82
SLIDE 82

MORE ABOUT ALSO

➜ Works for all combinations of =, ≤ and <. ➜ Uses all rules declared as [trans]. ➜ To view all combinations in Proof General: Isabelle/Isar → Show me → Transitivity rules

MORE ABOUT ALSO 21-B

slide-83
SLIDE 83

DESIGING [TRANS] RULES

calculation = ”l1 ⊙ r1” have ”. . . ⊙ r2” [proof] also ⇐ =

DESIGING [TRANS] RULES 22

slide-84
SLIDE 84

DESIGING [TRANS] RULES

calculation = ”l1 ⊙ r1” have ”. . . ⊙ r2” [proof] also ⇐ =

Anatomy of a [trans] rule:

➜ Usual form: plain transitivity [ [l1 ⊙ r1; r1 ⊙ r2] ] = ⇒ l1 ⊙ r2

DESIGING [TRANS] RULES 22-A

slide-85
SLIDE 85

DESIGING [TRANS] RULES

calculation = ”l1 ⊙ r1” have ”. . . ⊙ r2” [proof] also ⇐ =

Anatomy of a [trans] rule:

➜ Usual form: plain transitivity [ [l1 ⊙ r1; r1 ⊙ r2] ] = ⇒ l1 ⊙ r2 ➜ More general form: [ [P l1 r1; Q r1 r2; A] ] = ⇒ C l1 r2

Examples:

DESIGING [TRANS] RULES 22-B

slide-86
SLIDE 86

DESIGING [TRANS] RULES

calculation = ”l1 ⊙ r1” have ”. . . ⊙ r2” [proof] also ⇐ =

Anatomy of a [trans] rule:

➜ Usual form: plain transitivity [ [l1 ⊙ r1; r1 ⊙ r2] ] = ⇒ l1 ⊙ r2 ➜ More general form: [ [P l1 r1; Q r1 r2; A] ] = ⇒ C l1 r2

Examples:

➜ pure transitivity: [ [a = b; b = c] ] = ⇒ a = c

DESIGING [TRANS] RULES 22-C

slide-87
SLIDE 87

DESIGING [TRANS] RULES

calculation = ”l1 ⊙ r1” have ”. . . ⊙ r2” [proof] also ⇐ =

Anatomy of a [trans] rule:

➜ Usual form: plain transitivity [ [l1 ⊙ r1; r1 ⊙ r2] ] = ⇒ l1 ⊙ r2 ➜ More general form: [ [P l1 r1; Q r1 r2; A] ] = ⇒ C l1 r2

Examples:

➜ pure transitivity: [ [a = b; b = c] ] = ⇒ a = c ➜ mixed: [ [a ≤ b; b < c] ] = ⇒ a < c

DESIGING [TRANS] RULES 22-D

slide-88
SLIDE 88

DESIGING [TRANS] RULES

calculation = ”l1 ⊙ r1” have ”. . . ⊙ r2” [proof] also ⇐ =

Anatomy of a [trans] rule:

➜ Usual form: plain transitivity [ [l1 ⊙ r1; r1 ⊙ r2] ] = ⇒ l1 ⊙ r2 ➜ More general form: [ [P l1 r1; Q r1 r2; A] ] = ⇒ C l1 r2

Examples:

➜ pure transitivity: [ [a = b; b = c] ] = ⇒ a = c ➜ mixed: [ [a ≤ b; b < c] ] = ⇒ a < c ➜ substitution: [ [P a; a = b] ] = ⇒ P b

DESIGING [TRANS] RULES 22-E

slide-89
SLIDE 89

DESIGING [TRANS] RULES

calculation = ”l1 ⊙ r1” have ”. . . ⊙ r2” [proof] also ⇐ =

Anatomy of a [trans] rule:

➜ Usual form: plain transitivity [ [l1 ⊙ r1; r1 ⊙ r2] ] = ⇒ l1 ⊙ r2 ➜ More general form: [ [P l1 r1; Q r1 r2; A] ] = ⇒ C l1 r2

Examples:

➜ pure transitivity: [ [a = b; b = c] ] = ⇒ a = c ➜ mixed: [ [a ≤ b; b < c] ] = ⇒ a < c ➜ substitution: [ [P a; a = b] ] = ⇒ P b ➜ antisymmetry: [ [a < b; b < a] ] = ⇒ P

DESIGING [TRANS] RULES 22-F

slide-90
SLIDE 90

DESIGING [TRANS] RULES

calculation = ”l1 ⊙ r1” have ”. . . ⊙ r2” [proof] also ⇐ =

Anatomy of a [trans] rule:

➜ Usual form: plain transitivity [ [l1 ⊙ r1; r1 ⊙ r2] ] = ⇒ l1 ⊙ r2 ➜ More general form: [ [P l1 r1; Q r1 r2; A] ] = ⇒ C l1 r2

Examples:

➜ pure transitivity: [ [a = b; b = c] ] = ⇒ a = c ➜ mixed: [ [a ≤ b; b < c] ] = ⇒ a < c ➜ substitution: [ [P a; a = b] ] = ⇒ P b ➜ antisymmetry: [ [a < b; b < a] ] = ⇒ P ➜ monotonicity: [ [a = f b; b < c; V x y. x < y = ⇒ f x < f y] ] = ⇒ a < f c

DESIGING [TRANS] RULES 22-G

slide-91
SLIDE 91

DEMO

23

slide-92
SLIDE 92

WE HAVE SEEN TODAY ...

➜ Recdef ➜ More induction ➜ Well founded orders ➜ Well founded recursion ➜ Calculations: also/finally ➜ [trans]-rules

WE HAVE SEEN TODAY ... 24

slide-93
SLIDE 93

EXERCISES

➜ Define a predicate sorted over lists ➜ Show that sorted (quicksort xs) holds ➜ Look at http://isabelle.in.tum.de/library/HOL/ Wellfounded_Recursion.html ➜ Show that in groups, the left-one is also a right-one: x · 1 = x (you can use the right inv lemma from the demo) ➜ Take an algebra textbook and formalize a simple theorem over groups in Isabelle.

EXERCISES 25