programming and proving in isabelle hol
play

Programming and Proving in Isabelle/HOL e HOL l l e b a s - PDF document

Tobias Nipkow Programming and Proving in Isabelle/HOL e HOL l l e b a s I = February 17, 2016 Contents Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1


  1. Tobias Nipkow Programming and Proving in Isabelle/HOL e HOL l l e b a ∀ s I = α λ β → February 17, 2016

  2. Contents Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1 Programming and Proving . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 2 2.1 Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 2.2 Types bool , nat and list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.3 Type and Function Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 2.4 Induction Heuristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 2.5 Simplification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 3 Logic and Proof Beyond Equality . . . . . . . . . . . . . . . . . . . . . . . . . . 25 3.1 Formulas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 3.2 Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 3.3 Proof Automation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 3.4 Single Step Proofs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 3.5 Inductive Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 Isar: A Language for Structured Proofs . . . . . . . . . . . . . . . . . . . . 41 4 4.1 Isar by Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 4.2 Proof Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 4.3 Streamlining Proofs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 4.4 Case Analysis and Induction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

  3. 1 Introduction Isabelle is a generic system for implementing logical formalisms, and Isa- belle/HOL is the specialization of Isabelle for HOL, which abbreviates Higher- Order Logic. We introduce HOL step by step following the equation HOL = Functional Programming + Logic . We assume that the reader is used to logical and set-theoretic notation and is familiar with the basic concepts of functional programming. Chapter 2 introduces HOL as a functional programming language and ex- plains how to write simple inductive proofs of mostly equational properties of recursive functions. Chapter 3 introduces the rest of HOL: the language of formulas beyond equality, automatic proof tools, single-step proofs, and in- ductive definitions, an essential specification construct. Chapter 4 introduces Isar, Isabelle’s language for writing structured proofs. This introduction to the core of Isabelle is intentionally concrete and example-based: we concentrate on examples that illustrate the typical cases without explaining the general case if it can be inferred from the examples. We cover the essentials (from a functional programming point of view) as quickly and compactly as possible. For a comprehensive treatment of all things Isabelle we recommend the Isabelle/Isar Reference Manual [6], which comes with the Isabelle distribu- tion. The tutorial by Nipkow, Paulson and Wenzel [5] (in its updated version that comes with the Isabelle distribution) is still recommended for the wealth of examples and material, but its proof style is outdated. In particular it does not cover the structured proof language Isar. If you want to apply what you have learned about Isabelle we recommend you download and read the book Concrete Semantics [4], a guided tour of the wonderful world of programming langage semantics formalised in Isabelle. In fact, Programming and Proving in Isabelle/HOL constitutes part I of

  4. 2 1 Introduction Concrete Semantics. The web pages for Concrete Semantics also provide a set of L A T EX-based slides and Isabelle demo files for teaching Programming and Proving in Isabelle/HOL . Acknowledgements I wish to thank the following people for their comments on this document: Florian Haftmann, Peter Johnson, René Thiemann, Sean Seefried, Christian Sternagel and Carl Witty.

  5. 2 Programming and Proving This chapter introduces HOL as a functional programming language and shows how to prove properties of functional programs by induction. 2.1 Basics 2.1.1 Types, Terms and Formulas HOL is a typed logic whose type system resembles that of functional pro- gramming languages. Thus there are base types, in particular bool , the type of truth values, nat , the type of natural numbers ( N ), and int , the type of mathematical integers ( Z ). type constructors, in particular list , the type of lists, and set , the type of sets. Type constructors are written postfix, i.e., after their arguments. For example, nat list is the type of lists whose elements are natural numbers. function types, denoted by ⇒ . type variables, denoted by ′ a , ′ b , etc., like in ML. Note that ′ a ⇒ ′ b list means ′ a ⇒ ( ′ b list ) , not ( ′ a ⇒ ′ b ) list : postfix type constructors have precedence over ⇒ . Terms are formed as in functional programming by applying functions to arguments. If f is a function of type τ 1 ⇒ τ 2 and t is a term of type τ 1 then f t is a term of type τ 2 . We write t :: τ to mean that term t has type τ . There are many predefined infix symbols like + and � . The name of the cor- responding binary function is op + , not just + . That is, x + y is nice surface syntax (“syntactic sugar”) for op + x y . HOL also supports some basic constructs from functional programming:

  6. 4 2 Programming and Proving ( if b then t 1 else t 2 ) ( let x = t in u ) ( case t of pat 1 ⇒ t 1 | . . . | pat n ⇒ t n ) The above three constructs must always be enclosed in parentheses if they occur inside other constructs. Terms may also contain λ -abstractions. For example, λ x . x is the identity function. Formulas are terms of type bool . There are the basic constants True and False and the usual logical connectives (in decreasing order of precedence): ¬ , ∧ , ∨ , − → . Equality is available in the form of the infix function = of type ′ a ⇒ ′ a ⇒ bool . It also works for formulas, where it means “if and only if”. Quantifiers are written ∀ x . P and ∃ x . P . Isabelle automatically computes the type of each variable in a term. This is called type inference . Despite type inference, it is sometimes necessary to attach an explicit type constraint (or type annotation ) to a variable or term. The syntax is t :: τ as in m + ( n :: nat ) . Type constraints may be needed to disambiguate terms involving overloaded functions such as + . Finally there are the universal quantifier � and the implication = ⇒ . They are part of the Isabelle framework, not the logic HOL. Logically, they agree with their HOL counterparts ∀ and − → , but operationally they behave dif- ferently. This will become clearer as we go along. Right-arrows of all kinds always associate to the right. In particular, the formula A 1 = ⇒ A 2 = ⇒ A 3 means A 1 = ⇒ ( A 2 = ⇒ A 3 ) . The (Isabelle-specific 1 ) notation [ [ A 1 ; . . . ; A n ] ] = ⇒ A is short for the iterated implication A 1 = ⇒ . . . = ⇒ A n = ⇒ A . Sometimes we also employ inference rule notation: A 1 . . . A n A 2.1.2 Theories Roughly speaking, a theory is a named collection of types, functions, and theorems, much like a module in a programming language. All Isabelle text needs to go into a theory. The general format of a theory T is theory T imports T 1 . . . T n begin definitions, theorems and proofs end 1 To display implications in this style in Isabelle/jEdit you need to set Plugins > Plugin Options > Isabelle/General > Print Mode to “ brackets ” and restart.

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend