94
COMP4161: Advanced Topics in Software Verification HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au

HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

COMP4161: Advanced Topics in Software Verification

HOLGerwin Klein, June Andronick, Ramana Kumar

S2/2016

data61.csiro.au

Page 2: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Content

Ü Intro & motivation, getting started [1]

Ü Foundations & Principles

• Lambda Calculus, natural deduction [1,2]

• Higher Order Logic [3a]

• Term rewriting [4]

Ü Proof & Specification Techniques

• Inductively defined sets, rule induction [5]

• Datatypes, recursion, induction [6, 7]

• Hoare logic, proofs about programs, C verification [8b,9]

• (mid-semester break)

• Writing Automated Proof Methods [10]

• Isar, codegen, typeclasses, locales [11c ,12]

aa1 due; ba2 due; ca3 due

2 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 3: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Defining Higher Order Logic

Page 4: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

What is Higher Order Logic?

Ü Propositional Logic:• no quantifiers• all variables have type bool

4 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 5: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

What is Higher Order Logic?

Ü Propositional Logic:• no quantifiers• all variables have type bool

Ü First Order Logic:

• quantification over values, but not over functions and predicates,• terms and formulas syntactically distinct

4 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 6: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

What is Higher Order Logic?

Ü Propositional Logic:• no quantifiers• all variables have type bool

Ü First Order Logic:

• quantification over values, but not over functions and predicates,• terms and formulas syntactically distinct

Ü Higher Order Logic:

• quantification over everything, including predicates• consistency by types• formula = term of type bool• definition built on λ→ with certain default types and constants

4 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 7: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Defining Higher Order Logic

Default types:

bool ⇒ ind

Default Constants:

−→ :: bool ⇒ bool ⇒ bool= :: α⇒ α⇒ boolε :: (α⇒ bool)⇒ α

5 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 8: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Defining Higher Order Logic

Default types:

bool

⇒ ind

Default Constants:

−→ :: bool ⇒ bool ⇒ bool= :: α⇒ α⇒ boolε :: (α⇒ bool)⇒ α

5 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 9: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Defining Higher Order Logic

Default types:

bool ⇒

ind

Default Constants:

−→ :: bool ⇒ bool ⇒ bool= :: α⇒ α⇒ boolε :: (α⇒ bool)⇒ α

5 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 10: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Defining Higher Order Logic

Default types:

bool ⇒ ind

Default Constants:

−→ :: bool ⇒ bool ⇒ bool= :: α⇒ α⇒ boolε :: (α⇒ bool)⇒ α

5 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 11: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Defining Higher Order Logic

Default types:

bool ⇒ ind

Ü bool sometimes called o

Ü ⇒ sometimes called fun

Default Constants:

−→ :: bool ⇒ bool ⇒ bool= :: α⇒ α⇒ boolε :: (α⇒ bool)⇒ α

5 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 12: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Defining Higher Order Logic

Default types:

bool ⇒ ind

Ü bool sometimes called o

Ü ⇒ sometimes called fun

Default Constants:

−→ :: bool ⇒ bool ⇒ bool= :: α⇒ α⇒ boolε :: (α⇒ bool)⇒ α

5 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 13: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Defining Higher Order Logic

Default types:

bool ⇒ ind

Ü bool sometimes called o

Ü ⇒ sometimes called fun

Default Constants:

−→ :: bool ⇒ bool ⇒ bool

= :: α⇒ α⇒ boolε :: (α⇒ bool)⇒ α

5 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 14: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Defining Higher Order Logic

Default types:

bool ⇒ ind

Ü bool sometimes called o

Ü ⇒ sometimes called fun

Default Constants:

−→ :: bool ⇒ bool ⇒ bool= :: α⇒ α⇒ bool

ε :: (α⇒ bool)⇒ α

5 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 15: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Defining Higher Order Logic

Default types:

bool ⇒ ind

Ü bool sometimes called o

Ü ⇒ sometimes called fun

Default Constants:

−→ :: bool ⇒ bool ⇒ bool= :: α⇒ α⇒ boolε :: (α⇒ bool)⇒ α

5 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 16: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Higher Order Abstract Syntax

Problem: Define syntax for binders like ∀, ∃, ε

6 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 17: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Higher Order Abstract Syntax

Problem: Define syntax for binders like ∀, ∃, ε

One approach: ∀ :: var ⇒ term⇒ boolDrawback: need to think about substitution, α conversion again.

6 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 18: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Higher Order Abstract Syntax

Problem: Define syntax for binders like ∀, ∃, ε

One approach: ∀ :: var ⇒ term⇒ boolDrawback: need to think about substitution, α conversion again.

But: Already have binder, substitution, α conversion in meta logic

λ

6 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 19: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Higher Order Abstract Syntax

Problem: Define syntax for binders like ∀, ∃, ε

One approach: ∀ :: var ⇒ term⇒ boolDrawback: need to think about substitution, α conversion again.

But: Already have binder, substitution, α conversion in meta logic

λSo: Use λ to encode all other binders.

6 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 20: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Higher Order Abstract Syntax

Example:ALL :: (α⇒ bool)⇒ bool

HOAS usual syntax

ALL (λx . x = 2) ∀x . x = 2ALL P ∀x . P x

Isabelle can translate usual binder syntax into HOAS.

7 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 21: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Higher Order Abstract Syntax

Example:ALL :: (α⇒ bool)⇒ bool

HOAS usual syntax

ALL (λx . x = 2)

∀x . x = 2ALL P ∀x . P x

Isabelle can translate usual binder syntax into HOAS.

7 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 22: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Higher Order Abstract Syntax

Example:ALL :: (α⇒ bool)⇒ bool

HOAS usual syntax

ALL (λx . x = 2) ∀x . x = 2

ALL P ∀x . P x

Isabelle can translate usual binder syntax into HOAS.

7 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 23: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Higher Order Abstract Syntax

Example:ALL :: (α⇒ bool)⇒ bool

HOAS usual syntax

ALL (λx . x = 2) ∀x . x = 2ALL P

∀x . P x

Isabelle can translate usual binder syntax into HOAS.

7 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 24: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Higher Order Abstract Syntax

Example:ALL :: (α⇒ bool)⇒ bool

HOAS usual syntax

ALL (λx . x = 2) ∀x . x = 2ALL P ∀x . P x

Isabelle can translate usual binder syntax into HOAS.

7 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 25: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Higher Order Abstract Syntax

Example:ALL :: (α⇒ bool)⇒ bool

HOAS usual syntax

ALL (λx . x = 2) ∀x . x = 2ALL P ∀x . P x

Isabelle can translate usual binder syntax into HOAS.

7 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 26: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Side Track: Syntax Declarationsin Isabelle

Ü mixfix:consts drvbl :: ct ⇒ ct ⇒ fm⇒ bool (” , ` ”)Legal syntax now: Γ,Π ` F

More in Isabelle/Isar Reference Manual (7.2)

8 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 27: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Side Track: Syntax Declarationsin Isabelle

Ü mixfix:consts drvbl :: ct ⇒ ct ⇒ fm⇒ bool (” , ` ”)Legal syntax now: Γ,Π ` F

Ü priorities:pattern can be annotated with priorities to indicate binding strengthExample: drvbl :: ct ⇒ ct ⇒ fm⇒ bool (” , ` ” [30, 0, 20] 60)

More in Isabelle/Isar Reference Manual (7.2)

8 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 28: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Side Track: Syntax Declarationsin Isabelle

Ü mixfix:consts drvbl :: ct ⇒ ct ⇒ fm⇒ bool (” , ` ”)Legal syntax now: Γ,Π ` F

Ü priorities:pattern can be annotated with priorities to indicate binding strengthExample: drvbl :: ct ⇒ ct ⇒ fm⇒ bool (” , ` ” [30, 0, 20] 60)

Ü infixl/infixr: short form for left/right associative binary operatorsExample: or :: bool ⇒ bool ⇒ bool (infixr ” ∨ ” 30)

More in Isabelle/Isar Reference Manual (7.2)

8 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 29: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Side Track: Syntax Declarationsin Isabelle

Ü mixfix:consts drvbl :: ct ⇒ ct ⇒ fm⇒ bool (” , ` ”)Legal syntax now: Γ,Π ` F

Ü priorities:pattern can be annotated with priorities to indicate binding strengthExample: drvbl :: ct ⇒ ct ⇒ fm⇒ bool (” , ` ” [30, 0, 20] 60)

Ü infixl/infixr: short form for left/right associative binary operatorsExample: or :: bool ⇒ bool ⇒ bool (infixr ” ∨ ” 30)

Ü binders: declaration must be of the formc :: (τ1 ⇒ τ2)⇒ τ3 (binder ”B” < p >)B x . P x translated into c P (and vice versa)Example ALL :: (α⇒ bool)⇒ bool (binder ”∀” 10)

More in Isabelle/Isar Reference Manual (7.2)

8 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 30: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Side Track: Syntax Declarationsin Isabelle

Ü mixfix:consts drvbl :: ct ⇒ ct ⇒ fm⇒ bool (” , ` ”)Legal syntax now: Γ,Π ` F

Ü priorities:pattern can be annotated with priorities to indicate binding strengthExample: drvbl :: ct ⇒ ct ⇒ fm⇒ bool (” , ` ” [30, 0, 20] 60)

Ü infixl/infixr: short form for left/right associative binary operatorsExample: or :: bool ⇒ bool ⇒ bool (infixr ” ∨ ” 30)

Ü binders: declaration must be of the formc :: (τ1 ⇒ τ2)⇒ τ3 (binder ”B” < p >)B x . P x translated into c P (and vice versa)Example ALL :: (α⇒ bool)⇒ bool (binder ”∀” 10)

More in Isabelle/Isar Reference Manual (7.2)

8 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 31: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Back to HOL

Base: bool , ⇒, ind =, −→, ε

And the rest is

definitions:

True

(λx :: bool . x) = (λx . x)All P

P = (λx . True)Ex P

∀Q. (∀x . P x −→ Q) −→ QFalse

∀P. P¬P

P −→ FalseP ∧ Q

∀R. (P −→ Q −→ R) −→ RP ∨ Q

∀R. (P −→ R) −→ (Q −→ R) −→ RIf P x y

SOME z . (P = True −→ z = x) ∧ (P = False −→ z = y)inj f

∀x y . f x = f y −→ x = ysurj f

∀y . ∃x . y = f x

9 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 32: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Back to HOL

Base: bool , ⇒, ind =, −→, ε

And the rest is definitions:

True ≡

(λx :: bool . x) = (λx . x)

All P ≡

P = (λx . True)

Ex P ≡

∀Q. (∀x . P x −→ Q) −→ Q

False ≡

∀P. P

¬P ≡

P −→ False

P ∧ Q ≡

∀R. (P −→ Q −→ R) −→ R

P ∨ Q ≡

∀R. (P −→ R) −→ (Q −→ R) −→ R

If P x y ≡

SOME z . (P = True −→ z = x) ∧ (P = False −→ z = y)

inj f ≡

∀x y . f x = f y −→ x = y

surj f ≡

∀y . ∃x . y = f x

9 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 33: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Back to HOL

Base: bool , ⇒, ind =, −→, ε

And the rest is definitions:

True ≡ (λx :: bool . x) = (λx . x)All P ≡

P = (λx . True)

Ex P ≡

∀Q. (∀x . P x −→ Q) −→ Q

False ≡

∀P. P

¬P ≡

P −→ False

P ∧ Q ≡

∀R. (P −→ Q −→ R) −→ R

P ∨ Q ≡

∀R. (P −→ R) −→ (Q −→ R) −→ R

If P x y ≡

SOME z . (P = True −→ z = x) ∧ (P = False −→ z = y)

inj f ≡

∀x y . f x = f y −→ x = y

surj f ≡

∀y . ∃x . y = f x

9 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 34: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Back to HOL

Base: bool , ⇒, ind =, −→, ε

And the rest is definitions:

True ≡ (λx :: bool . x) = (λx . x)All P ≡ P = (λx . True)Ex P ≡

∀Q. (∀x . P x −→ Q) −→ Q

False ≡

∀P. P

¬P ≡

P −→ False

P ∧ Q ≡

∀R. (P −→ Q −→ R) −→ R

P ∨ Q ≡

∀R. (P −→ R) −→ (Q −→ R) −→ R

If P x y ≡

SOME z . (P = True −→ z = x) ∧ (P = False −→ z = y)

inj f ≡

∀x y . f x = f y −→ x = y

surj f ≡

∀y . ∃x . y = f x

9 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 35: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Back to HOL

Base: bool , ⇒, ind =, −→, ε

And the rest is definitions:

True ≡ (λx :: bool . x) = (λx . x)All P ≡ P = (λx . True)Ex P ≡ ∀Q. (∀x . P x −→ Q) −→ QFalse ≡ ∀P. P¬P ≡ P −→ FalseP ∧ Q ≡ ∀R. (P −→ Q −→ R) −→ RP ∨ Q ≡ ∀R. (P −→ R) −→ (Q −→ R) −→ RIf P x y ≡ SOME z . (P = True −→ z = x) ∧ (P = False −→ z = y)inj f ≡ ∀x y . f x = f y −→ x = ysurj f ≡ ∀y . ∃x . y = f x

9 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 36: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

The Axioms of HOL

t = t refls = t P s

P tsubst

∧x . f x = g x

(λx . f x) = (λx . g x)ext

10 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 37: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

The Axioms of HOL

t = t refls = t P s

P tsubst

∧x . f x = g x

(λx . f x) = (λx . g x)ext

P =⇒ QP −→ Q

impIP −→ Q P

Qmp

10 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 38: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

The Axioms of HOL

t = t refls = t P s

P tsubst

∧x . f x = g x

(λx . f x) = (λx . g x)ext

P =⇒ QP −→ Q

impIP −→ Q P

Qmp

(P −→ Q) −→ (Q −→ P) −→ (P = Q)iff

10 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 39: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

The Axioms of HOL

t = t refls = t P s

P tsubst

∧x . f x = g x

(λx . f x) = (λx . g x)ext

P =⇒ QP −→ Q

impIP −→ Q P

Qmp

(P −→ Q) −→ (Q −→ P) −→ (P = Q)iff

P = True ∨ P = FalseTrue or False

10 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 40: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

The Axioms of HOL

t = t refls = t P s

P tsubst

∧x . f x = g x

(λx . f x) = (λx . g x)ext

P =⇒ QP −→ Q

impIP −→ Q P

Qmp

(P −→ Q) −→ (Q −→ P) −→ (P = Q)iff

P = True ∨ P = FalseTrue or False

P ?xP (SOME x . P x)

someI

10 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 41: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

The Axioms of HOL

t = t refls = t P s

P tsubst

∧x . f x = g x

(λx . f x) = (λx . g x)ext

P =⇒ QP −→ Q

impIP −→ Q P

Qmp

(P −→ Q) −→ (Q −→ P) −→ (P = Q)iff

P = True ∨ P = FalseTrue or False

P ?xP (SOME x . P x)

someI

∃f :: ind ⇒ ind . inj f ∧ ¬surj finfty

10 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 42: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

That’s it.

Ü 3 basic constants

Ü 3 basic types

Ü 9 axioms

With this you can define and derive all the rest.

11 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 43: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

That’s it.

Ü 3 basic constants

Ü 3 basic types

Ü 9 axioms

With this you can define and derive all the rest.

11 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 44: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

That’s it.

Ü 3 basic constants

Ü 3 basic types

Ü 9 axioms

With this you can define and derive all the rest.

Isabelle knows 2 more axioms:

x = yx ≡ y eq reflection (THE x . x = a) = a

the eq trivial

11 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 45: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Demo: The Definitions inIsabelle

Page 46: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Deriving Proof Rules

In the following, we will

Ü look at the definitions in more detail

Ü derive the traditional proof rules from the axioms in Isabelle

proves: [[ < prop >1; < prop >2; . . . ]] =⇒ < prop >

13 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 47: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Deriving Proof Rules

In the following, we will

Ü look at the definitions in more detail

Ü derive the traditional proof rules from the axioms in Isabelle

proves: [[ < prop >1; < prop >2; . . . ]] =⇒ < prop >

13 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 48: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Deriving Proof Rules

In the following, we will

Ü look at the definitions in more detail

Ü derive the traditional proof rules from the axioms in Isabelle

proves: [[ < prop >1; < prop >2; . . . ]] =⇒ < prop >

13 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 49: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Deriving Proof Rules

In the following, we will

Ü look at the definitions in more detail

Ü derive the traditional proof rules from the axioms in Isabelle

Convenient for deriving rules: named assumptions in lemmas

lemma [name :]assumes [name1 :] “< prop >1”assumes [name2 :] “< prop >2”...shows “< prop >” < proof >

proves: [[ < prop >1; < prop >2; . . . ]] =⇒ < prop >

13 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 50: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Deriving Proof Rules

In the following, we will

Ü look at the definitions in more detail

Ü derive the traditional proof rules from the axioms in Isabelle

Convenient for deriving rules: named assumptions in lemmas

lemma [name :]assumes [name1 :] “< prop >1”assumes [name2 :] “< prop >2”...shows “< prop >” < proof >

proves: [[ < prop >1; < prop >2; . . . ]] =⇒ < prop >

13 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 51: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

True

consts True :: boolTrue ≡ (λx :: bool . x) = (λx . x)

Intuition:right hand side is always true

14 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 52: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

True

consts True :: boolTrue ≡ (λx :: bool . x) = (λx . x)

Intuition:right hand side is always true

Proof Rules:

TrueTrueI

Proof:

(λx :: bool . x) = (λx . x)refl

Trueunfold True def

14 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 53: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Demo

Page 54: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Universal Quantifier

consts ALL :: (α⇒ bool)⇒ boolALL P ≡ P = (λx . True)

Intuition:

Ü ALL P is Higher Order Abstract Syntax for ∀x . P x .

Ü P is a function that takes an x and yields a truth value.

Ü ALL P should be true iff P yields true for all x , i.e.if it is equivalent to the function λx . True.

16 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 55: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Universal Quantifier

consts ALL :: (α⇒ bool)⇒ boolALL P ≡ P = (λx . True)

Intuition:

Ü ALL P is Higher Order Abstract Syntax for ∀x . P x .

Ü P is a function that takes an x and yields a truth value.

Ü ALL P should be true iff P yields true for all x , i.e.if it is equivalent to the function λx . True.

16 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 56: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Universal Quantifier

consts ALL :: (α⇒ bool)⇒ boolALL P ≡ P = (λx . True)

Intuition:

Ü ALL P is Higher Order Abstract Syntax for ∀x . P x .

Ü P is a function that takes an x and yields a truth value.

Ü ALL P should be true iff P yields true for all x , i.e.if it is equivalent to the function λx . True.

16 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 57: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Universal Quantifier

consts ALL :: (α⇒ bool)⇒ boolALL P ≡ P = (λx . True)

Intuition:

Ü ALL P is Higher Order Abstract Syntax for ∀x . P x .

Ü P is a function that takes an x and yields a truth value.

Ü ALL P should be true iff P yields true for all x , i.e.if it is equivalent to the function λx . True.

16 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 58: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Universal Quantifier

consts ALL :: (α⇒ bool)⇒ boolALL P ≡ P = (λx . True)

Intuition:

Ü ALL P is Higher Order Abstract Syntax for ∀x . P x .

Ü P is a function that takes an x and yields a truth value.

Ü ALL P should be true iff P yields true for all x , i.e.if it is equivalent to the function λx . True.

Proof Rules: ∧x . P x

∀x . P xallI

∀x . P x P ?x =⇒ RR

allE

Proof: Isabelle Demo

16 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 59: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

False

consts False :: boolFalse ≡ ∀P.P

Intuition:Everything can be derived from False.

17 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 60: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

False

consts False :: boolFalse ≡ ∀P.P

Intuition:Everything can be derived from False.

17 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 61: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

False

consts False :: boolFalse ≡ ∀P.P

Intuition:Everything can be derived from False.

Proof Rules:FalseP

FalseETrue 6= False

Proof: Isabelle Demo

17 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 62: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Negation

consts Not :: bool ⇒ bool (¬ )¬P ≡ P −→ False

Intuition:Try P = True and P = False and the traditional truth table for −→.

18 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 63: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Negation

consts Not :: bool ⇒ bool (¬ )¬P ≡ P −→ False

Intuition:Try P = True and P = False and the traditional truth table for −→.

18 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 64: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Negation

consts Not :: bool ⇒ bool (¬ )¬P ≡ P −→ False

Intuition:Try P = True and P = False and the traditional truth table for −→.

Proof Rules:A =⇒ False¬A notI

¬A AP

notE

Proof: Isabelle Demo

18 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 65: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Existential Quantifier

consts EX :: (α⇒ bool)⇒ boolEX P ≡ ∀Q. (∀x . P x −→ Q) −→ Q

Intuition:

Ü EX P is HOAS for ∃x . P x . (like ∀)

Ü Right hand side is characterization of ∃ with ∀ and −→Ü Note that inner ∀ binds wide: (∀x . P x −→ Q)

Ü Remember lemma from last time: (∀x . P x −→ Q) = ((∃x . P x) −→ Q)

19 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 66: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Existential Quantifier

consts EX :: (α⇒ bool)⇒ boolEX P ≡ ∀Q. (∀x . P x −→ Q) −→ Q

Intuition:

Ü EX P is HOAS for ∃x . P x . (like ∀)

Ü Right hand side is characterization of ∃ with ∀ and −→Ü Note that inner ∀ binds wide: (∀x . P x −→ Q)

Ü Remember lemma from last time: (∀x . P x −→ Q) = ((∃x . P x) −→ Q)

19 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 67: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Existential Quantifier

consts EX :: (α⇒ bool)⇒ boolEX P ≡ ∀Q. (∀x . P x −→ Q) −→ Q

Intuition:

Ü EX P is HOAS for ∃x . P x . (like ∀)

Ü Right hand side is characterization of ∃ with ∀ and −→

Ü Note that inner ∀ binds wide: (∀x . P x −→ Q)

Ü Remember lemma from last time: (∀x . P x −→ Q) = ((∃x . P x) −→ Q)

19 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 68: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Existential Quantifier

consts EX :: (α⇒ bool)⇒ boolEX P ≡ ∀Q. (∀x . P x −→ Q) −→ Q

Intuition:

Ü EX P is HOAS for ∃x . P x . (like ∀)

Ü Right hand side is characterization of ∃ with ∀ and −→Ü Note that inner ∀ binds wide: (∀x . P x −→ Q)

Ü Remember lemma from last time: (∀x . P x −→ Q) = ((∃x . P x) −→ Q)

19 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 69: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Existential Quantifier

consts EX :: (α⇒ bool)⇒ boolEX P ≡ ∀Q. (∀x . P x −→ Q) −→ Q

Intuition:

Ü EX P is HOAS for ∃x . P x . (like ∀)

Ü Right hand side is characterization of ∃ with ∀ and −→Ü Note that inner ∀ binds wide: (∀x . P x −→ Q)

Ü Remember lemma from last time: (∀x . P x −→ Q) = ((∃x . P x) −→ Q)

19 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 70: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Existential Quantifier

consts EX :: (α⇒ bool)⇒ boolEX P ≡ ∀Q. (∀x . P x −→ Q) −→ Q

Intuition:

Ü EX P is HOAS for ∃x . P x . (like ∀)

Ü Right hand side is characterization of ∃ with ∀ and −→Ü Note that inner ∀ binds wide: (∀x . P x −→ Q)

Ü Remember lemma from last time: (∀x . P x −→ Q) = ((∃x . P x) −→ Q)

Proof Rules:P ?x∃x . P x

exI∃x . P x

∧x . P x =⇒ R

RexE

Proof: Isabelle Demo

19 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 71: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Conjunction

consts And :: bool ⇒ bool ⇒ bool ( ∧ )P ∧ Q ≡ ∀R. (P −→ Q −→ R) −→ R

Intuition:

Ü Mirrors proof rules for ∧Ü Try truth table for P, Q, and R

20 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 72: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Conjunction

consts And :: bool ⇒ bool ⇒ bool ( ∧ )P ∧ Q ≡ ∀R. (P −→ Q −→ R) −→ R

Intuition:

Ü Mirrors proof rules for ∧

Ü Try truth table for P, Q, and R

20 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 73: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Conjunction

consts And :: bool ⇒ bool ⇒ bool ( ∧ )P ∧ Q ≡ ∀R. (P −→ Q −→ R) −→ R

Intuition:

Ü Mirrors proof rules for ∧Ü Try truth table for P, Q, and R

20 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 74: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Conjunction

consts And :: bool ⇒ bool ⇒ bool ( ∧ )P ∧ Q ≡ ∀R. (P −→ Q −→ R) −→ R

Intuition:

Ü Mirrors proof rules for ∧Ü Try truth table for P, Q, and R

Proof Rules:

A BA ∧ B

conjIA ∧ B [[A;B]] =⇒ C

CconjE

Proof: Isabelle Demo

20 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 75: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Disjunction

consts Or :: bool ⇒ bool ⇒ bool ( ∨ )P ∨ Q ≡ ∀R. (P −→ R) −→ (Q −→ R) −→ R

Intuition:

Ü Mirrors proof rules for ∨ (case distinction)

Ü Try truth table for P, Q, and R

21 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 76: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Disjunction

consts Or :: bool ⇒ bool ⇒ bool ( ∨ )P ∨ Q ≡ ∀R. (P −→ R) −→ (Q −→ R) −→ R

Intuition:

Ü Mirrors proof rules for ∨ (case distinction)

Ü Try truth table for P, Q, and R

21 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 77: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Disjunction

consts Or :: bool ⇒ bool ⇒ bool ( ∨ )P ∨ Q ≡ ∀R. (P −→ R) −→ (Q −→ R) −→ R

Intuition:

Ü Mirrors proof rules for ∨ (case distinction)

Ü Try truth table for P, Q, and R

21 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 78: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Disjunction

consts Or :: bool ⇒ bool ⇒ bool ( ∨ )P ∨ Q ≡ ∀R. (P −→ R) −→ (Q −→ R) −→ R

Intuition:

Ü Mirrors proof rules for ∨ (case distinction)

Ü Try truth table for P, Q, and R

Proof Rules:

AA ∨ B

BA ∨ B

disjI1/2 A ∨ B A =⇒ C B =⇒ CC

disjE

Proof: Isabelle Demo

21 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 79: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

If-Then-Else

consts If :: bool ⇒ α⇒ α⇒ α (if then else )If P x y ≡ SOME z . (P = True −→ z = x) ∧ (P = False −→ z = y)

Intuition:

Ü for P = True, right hand side collapses to SOME z . z = x

Ü for P = False, right hand side collapses to SOME z . z = y

22 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 80: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

If-Then-Else

consts If :: bool ⇒ α⇒ α⇒ α (if then else )If P x y ≡ SOME z . (P = True −→ z = x) ∧ (P = False −→ z = y)

Intuition:

Ü for P = True, right hand side collapses to SOME z . z = x

Ü for P = False, right hand side collapses to SOME z . z = y

22 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 81: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

If-Then-Else

consts If :: bool ⇒ α⇒ α⇒ α (if then else )If P x y ≡ SOME z . (P = True −→ z = x) ∧ (P = False −→ z = y)

Intuition:

Ü for P = True, right hand side collapses to SOME z . z = x

Ü for P = False, right hand side collapses to SOME z . z = y

22 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 82: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

If-Then-Else

consts If :: bool ⇒ α⇒ α⇒ α (if then else )If P x y ≡ SOME z . (P = True −→ z = x) ∧ (P = False −→ z = y)

Intuition:

Ü for P = True, right hand side collapses to SOME z . z = x

Ü for P = False, right hand side collapses to SOME z . z = y

Proof Rules:

if True then s else t = sifTrue

if False then s else t = tifFalse

Proof: Isabelle Demo

22 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 83: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

That was HOL

Page 84: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

More on Automation

Last time: safe and unsafe, heuristics: use safe before unsafe

This can be automated

24 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 85: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

More on Automation

Last time: safe and unsafe, heuristics: use safe before unsafe

This can be automated

24 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 86: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

More on Automation

Last time: safe and unsafe, heuristics: use safe before unsafe

This can be automated

24 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 87: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

More on Automation

Last time: safe and unsafe, heuristics: use safe before unsafe

This can be automated

Syntax:[<kind>!] for safe rules (<kind> one of intro, elim, dest)[<kind>] for unsafe rules

24 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 88: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

More on Automation

Last time: safe and unsafe, heuristics: use safe before unsafe

This can be automated

Syntax:[<kind>!] for safe rules (<kind> one of intro, elim, dest)[<kind>] for unsafe rules

Application (roughly):do safe rules first, search/backtrack on unsafe rules only

24 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 89: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

More on Automation

Last time: safe and unsafe, heuristics: use safe before unsafe

This can be automated

Syntax:[<kind>!] for safe rules (<kind> one of intro, elim, dest)[<kind>] for unsafe rules

Application (roughly):do safe rules first, search/backtrack on unsafe rules only

Example:declare attribute globally declare conjI [intro!] allE [elim]remove attribute gloablly declare allE [rule del]use locally apply (blast intro: someI)delete locally apply (blast del: conjI)

24 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 90: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

Demo: Automation

Page 91: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

We have learned today ...

Ü Defining HOL

Ü Higher Order Abstract Syntax

Ü Deriving proof rules

Ü More automation

26 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 92: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

We have learned today ...

Ü Defining HOL

Ü Higher Order Abstract Syntax

Ü Deriving proof rules

Ü More automation

26 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 93: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

We have learned today ...

Ü Defining HOL

Ü Higher Order Abstract Syntax

Ü Deriving proof rules

Ü More automation

26 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 94: HOL - cse.unsw.edu.aucs4161/16s2/week03B_anim.pdf · HOL Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au. Content Ü Intro & motivation, getting started [1] Ü

We have learned today ...

Ü Defining HOL

Ü Higher Order Abstract Syntax

Ü Deriving proof rules

Ü More automation

26 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License