Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark...

53
 Interactive Formal Verification Review (1-7) Tjark Weber Computer Laboratory University of Cambridge

Transcript of Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark...

Page 1: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Interactive Formal VerificationReview (1­7)

Tjark WeberComputer Laboratory

University of Cambridge

Page 2: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Isabelle Theories

theory T imports Main A B

begin

end

Page 3: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Isabelle Theories

theory T imports Main A B

begin

end

Name of the theory

Page 4: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Isabelle Theories

theory T imports Main A B

begin

end

Names of existing theories

Name of the theory

Page 5: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Isabelle Theories

theory T imports Main A B

begin

end

Names of existing theoriesMain: contains all of Isabelle/HOL

Name of the theory

Page 6: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Defining Types

● typedecl ('a,'b) t

Page 7: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Defining Types

● typedecl ('a,'b) tIntroduces an unspecified type

Page 8: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Defining Types

● typedecl ('a,'b) tIntroduces an unspecified type

Optional: type arguments

Page 9: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Defining Types

● typedecl ('a,'b) t

● type_synonym 'a multiset = "'a => nat"

Introduces an unspecified type

Optional: type arguments

Page 10: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Defining Types

● typedecl ('a,'b) t

● type_synonym 'a multiset = "'a => nat"

Introduces a new name for an existing type

Optional: type arguments

Introduces an unspecified type

Page 11: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Defining Types

● typedecl ('a,'b) t

● type_synonym 'a multiset = "'a => nat"

● datatype 'a list = Nil | Cons 'a "'a list"

Optional: type arguments

Introduces an unspecified type

Introduces a new name for an existing type

Page 12: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Defining Types

● typedecl ('a,'b) t

● type_synonym 'a multiset = "'a => nat"

● datatype 'a list = Nil | Cons 'a "'a list"

Optional: type arguments

Defines an inductive datatype

Introduces an unspecified type

Introduces a new name for an existing type

Page 13: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Defining Types

● typedecl ('a,'b) t

● type_synonym 'a multiset = "'a => nat"

● datatype 'a list = Nil | Cons 'a "'a list"

Optional: type arguments

Defines an inductive datatype

Constructor names and argument types

Introduces an unspecified type

Introduces a new name for an existing type

Page 14: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Defining Constants

● definition even :: "nat => bool" where "even n = (∃k. n = 2*k)"

Page 15: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Defining Constants

● definition even :: "nat => bool" where "even n = (∃k. n = 2*k)"

For non-recursive definitions

Page 16: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Defining Constants

● definition even :: "nat => bool" where "even n = (∃k. n = 2*k)"

For non-recursive definitions Optional: the constant's type

Page 17: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Defining Constants

● definition even :: "nat => bool" where "even n = (∃k. n = 2*k)"

For non-recursive definitions Optional: the constant's type

Provides a lemma: even_def

Page 18: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Defining Constants

● definition even :: "nat => bool" where "even n = (∃k. n = 2*k)"

● fun even' where "even' 0 = True"| "even' (Suc 0) = False"| "even' n = even' (n-2)"

For non-recursive definitions Optional: the constant's type

Provides a lemma: even_def

Page 19: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Defining Constants

● definition even :: "nat => bool" where "even n = (∃k. n = 2*k)"

● fun even' where "even' 0 = True"| "even' (Suc 0) = False"| "even' n = even' (n-2)"

For non-recursive definitions Optional: the constant's type

Provides a lemma: even_defFor recursive functions

Page 20: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Defining Constants

● definition even :: "nat => bool" where "even n = (∃k. n = 2*k)"

● fun even' where "even' 0 = True"| "even' (Suc 0) = False"| "even' n = even' (n-2)"

For non-recursive definitions Optional: the constant's type

Provides a lemma: even_def

Provides even'.simps and even'.induct

For recursive functions

Page 21: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Defining Constants

● inductive_set tclfor R :: "('a*'a) set"where "(x,y):R ==> (x,y):tcl R"| "(x,y):tcl R ==> (y,z):tcl R ==> (x,z):tcl R"

Page 22: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Defining Constants

● inductive_set tclfor R :: "('a*'a) set"where "(x,y):R ==> (x,y):tcl R"| "(x,y):tcl R ==> (y,z):tcl R ==> (x,z):tcl R"

For inductive sets

Page 23: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Defining Constants

● inductive_set tclfor R :: "('a*'a) set"where "(x,y):R ==> (x,y):tcl R"| "(x,y):tcl R ==> (y,z):tcl R ==> (x,z):tcl R"

For inductive sets Optional: the constant's type

Page 24: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Defining Constants

● inductive_set tclfor R :: "('a*'a) set"where "(x,y):R ==> (x,y):tcl R"| "(x,y):tcl R ==> (y,z):tcl R ==> (x,z):tcl R"

For inductive sets

Parameters (types are optional again)

Optional: the constant's type

Page 25: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Defining Constants

● inductive_set tclfor R :: "('a*'a) set"where "(x,y):R ==> (x,y):tcl R"| "(x,y):tcl R ==> (y,z):tcl R ==> (x,z):tcl R"

For inductive sets

Provides tcl.cases, tcl.induct,tcl.intros and tcl.simps

Optional: the constant's type

Parameters (types are optional again)

Page 26: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Theorems and Proofs

● lemma add_com [simp]: "x+y = y+x"● apply method● done● by method● oops● sorry

Page 27: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Theorems and Proofs

● lemma add_com [simp]: "x+y = y+x"● apply method● done● by method● oops● sorry

Starts a proof

Page 28: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Theorems and Proofs

● lemma add_com [simp]: "x+y = y+x"● apply method● done● by method● oops● sorry

Starts a proofOptional: a name and attributes

Page 29: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Theorems and Proofs

● lemma add_com [simp]: "x+y = y+x"● apply method● done● by method● oops● sorry

Starts a proofOptional: a name and attributes

Modifies some subgoal(s)

Page 30: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Theorems and Proofs

● lemma add_com [simp]: "x+y = y+x"● apply method● done● by method● oops● sorry

Starts a proofOptional: a name and attributes

Modifies some subgoal(s)

Finishes a proof

Page 31: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Theorems and Proofs

● lemma add_com [simp]: "x+y = y+x"● apply method● done● by method● oops● sorry

Starts a proofOptional: a name and attributes

Modifies some subgoal(s)

Finishes a proof

Finishes a proof in a single step

Page 32: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Theorems and Proofs

● lemma add_com [simp]: "x+y = y+x"● apply method● done● by method● oops● sorry

Starts a proofOptional: a name and attributes

Modifies some subgoal(s)

Finishes a proof

Finishes a proof in a single step

Aborts a proof attempt

Page 33: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Theorems and Proofs

● lemma add_com [simp]: "x+y = y+x"● apply method● done● by method● oops● sorry

Starts a proofOptional: a name and attributes

Modifies some subgoal(s)

Finishes a proof

Finishes a proof in a single step

Aborts a proof attempt

Finishes a proof (cheating!)

Page 34: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Automated Proof Methods

● (induct x y arbitrary: z rule: r.induct)● (simp add: l1 del: l2)● (auto simp add: l1 intro: l2)● (blast intro: l1 elim: l2)● arith● (metis l1 l2 l3)● sledgehammer

Page 35: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Automated Proof Methods

● (induct x y arbitrary: z rule: r.induct)● (simp add: l1 del: l2)● (auto simp add: l1 intro: l2)● (blast intro: l1 elim: l2)● arith● (metis l1 l2 l3)● sledgehammer

Induction

Page 36: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Automated Proof Methods

● (induct x y arbitrary: z rule: r.induct)● (simp add: l1 del: l2)● (auto simp add: l1 intro: l2)● (blast intro: l1 elim: l2)● arith● (metis l1 l2 l3)● sledgehammer

Induction

Simplification

Page 37: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Automated Proof Methods

● (induct x y arbitrary: z rule: r.induct)● (simp add: l1 del: l2)● (auto simp add: l1 intro: l2)● (blast intro: l1 elim: l2)● arith● (metis l1 l2 l3)● sledgehammer

Induction

Simplification

Simplification and some logic

Page 38: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Automated Proof Methods

● (induct x y arbitrary: z rule: r.induct)● (simp add: l1 del: l2)● (auto simp add: l1 intro: l2)● (blast intro: l1 elim: l2)● arith● (metis l1 l2 l3)● sledgehammer

Induction

Simplification

Simplification and some logic

Good for sets and quantifiers

Page 39: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Automated Proof Methods

● (induct x y arbitrary: z rule: r.induct)● (simp add: l1 del: l2)● (auto simp add: l1 intro: l2)● (blast intro: l1 elim: l2)● arith● (metis l1 l2 l3)● sledgehammer

Induction

Simplification

Simplification and some logic

Good for sets and quantifiers

Good for arithmetic goals

Page 40: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Automated Proof Methods

● (induct x y arbitrary: z rule: r.induct)● (simp add: l1 del: l2)● (auto simp add: l1 intro: l2)● (blast intro: l1 elim: l2)● arith● (metis l1 l2 l3)● sledgehammer

Induction

Simplification

Simplification and some logic

Good for sets and quantifiers

Powerful first-order prover

Good for arithmetic goals

Page 41: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Automated Proof Methods

● (induct x y arbitrary: z rule: r.induct)● (simp add: l1 del: l2)● (auto simp add: l1 intro: l2)● (blast intro: l1 elim: l2)● arith● (metis l1 l2 l3)● sledgehammer

Induction

Simplification

Simplification and some logic

Good for sets and quantifiers

Powerful first-order prover

Good for arithmetic goals

Finds lemmas for metis

Page 42: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Basic Methods for Rulesthm: "[| P1; ...; Pn |] ==> Q"

● (rule thm)● (erule thm)● (drule thm)● (frule thm)

● (rule_tac x="..." and y="..." in thm)

Page 43: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Basic Methods for Rulesthm: "[| P1; ...; Pn |] ==> Q"

● (rule thm)● (erule thm)● (drule thm)● (frule thm)

● (rule_tac x="..." and y="..." in thm)

Unifies Q with the conclusion

Page 44: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Basic Methods for Rulesthm: "[| P1; ...; Pn |] ==> Q"

● (rule thm)● (erule thm)● (drule thm)● (frule thm)

● (rule_tac x="..." and y="..." in thm)

Unifies Q with the conclusion

Unifies Q; unifies P1 with some assumption

Page 45: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Basic Methods for Rulesthm: "[| P1; ...; Pn |] ==> Q"

● (rule thm)● (erule thm)● (drule thm)● (frule thm)

● (rule_tac x="..." and y="..." in thm)

Unifies Q with the conclusion

Unifies Q; unifies P1 with some assumption

Unifies P1 with some assumption

Page 46: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Basic Methods for Rulesthm: "[| P1; ...; Pn |] ==> Q"

● (rule thm)● (erule thm)● (drule thm)● (frule thm)

● (rule_tac x="..." and y="..." in thm)

Unifies Q with the conclusion

Unifies Q; unifies P1 with some assumption

Unifies P1 with some assumption

Like drule, but does not delete the assumption

Page 47: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Basic Methods for Rulesthm: "[| P1; ...; Pn |] ==> Q"

● (rule thm)● (erule thm)● (drule thm)● (frule thm)

● (rule_tac x="..." and y="..." in thm)

Unifies Q with the conclusion

Unifies Q; unifies P1 with some assumption

Unifies P1 with some assumption

Manual instantiation of variables

Like drule, but does not delete the assumption

Page 48: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Insiders' Tips

● term "..."● thm name● Find theorems● Isabelle > Settings > Display ...● Isabelle > Show me ...

Page 49: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Insiders' Tips

● term "..."● thm name● Find theorems● Isabelle > Settings > Display ...● Isabelle > Show me ...

Prints a term (with its type)

Page 50: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Insiders' Tips

● term "..."● thm name● Find theorems● Isabelle > Settings > Display ...● Isabelle > Show me ...

Prints a term (with its type)

Prints a specific theorem

Page 51: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Insiders' Tips

● term "..."● thm name● Find theorems● Isabelle > Settings > Display ...● Isabelle > Show me ...

Prints a term (with its type)

Prints a specific theorem

Search for theorems by pattern

Page 52: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Insiders' Tips

● term "..."● thm name● Find theorems● Isabelle > Settings > Display ...● Isabelle > Show me ...

Prints a term (with its type)

Prints a specific theorem

Search for theorems by pattern

Show types, sorts etc.

Page 53: Interactive Formal Verification Review (17) 1-7.pdfInteractive Formal Verification Review (17) Tjark Weber Computer Laboratory University of Cambridge

   

Insiders' Tips

● term "..."● thm name● Find theorems● Isabelle > Settings > Display ...● Isabelle > Show me ...

Prints a term (with its type)

Prints a specific theorem

Search for theorems by pattern

Show types, sorts etc.

Show all commands, all methods etc.