Download - Isabelle/HOL | Higher-Order Logic · Isabelle/HOL | Higher-Order Logic April 15, 2020 Contents 1 The basis of Higher-Order Logic31 1.1 Primitive logic. . . . . . . . . . . . . . .

Transcript
  • Isabelle/HOL — Higher-Order Logic

    April 15, 2020

    Contents

    1 The basis of Higher-Order Logic 311.1 Primitive logic . . . . . . . . . . . . . . . . . . . . . . . . . . 32

    1.1.1 Core syntax . . . . . . . . . . . . . . . . . . . . . . . . 321.1.2 Defined connectives and quantifiers . . . . . . . . . . . 321.1.3 Additional concrete syntax . . . . . . . . . . . . . . . 331.1.4 Axioms and basic definitions . . . . . . . . . . . . . . 34

    1.2 Fundamental rules . . . . . . . . . . . . . . . . . . . . . . . . 351.2.1 Equality . . . . . . . . . . . . . . . . . . . . . . . . . . 351.2.2 Congruence rules for application . . . . . . . . . . . . 361.2.3 Equality of booleans – iff . . . . . . . . . . . . . . . . 361.2.4 True (1) . . . . . . . . . . . . . . . . . . . . . . . . . . 371.2.5 Universal quantifier (1) . . . . . . . . . . . . . . . . . 371.2.6 False . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371.2.7 Negation . . . . . . . . . . . . . . . . . . . . . . . . . 381.2.8 Implication . . . . . . . . . . . . . . . . . . . . . . . . 381.2.9 Disjunction (1) . . . . . . . . . . . . . . . . . . . . . . 391.2.10 Derivation of iffI . . . . . . . . . . . . . . . . . . . . . 391.2.11 True (2) . . . . . . . . . . . . . . . . . . . . . . . . . . 401.2.12 Universal quantifier (2) . . . . . . . . . . . . . . . . . 401.2.13 Existential quantifier . . . . . . . . . . . . . . . . . . . 401.2.14 Conjunction . . . . . . . . . . . . . . . . . . . . . . . . 401.2.15 Disjunction (2) . . . . . . . . . . . . . . . . . . . . . . 411.2.16 Classical logic . . . . . . . . . . . . . . . . . . . . . . . 411.2.17 Unique existence . . . . . . . . . . . . . . . . . . . . . 421.2.18 Classical intro rules for disjunction and existential quan-

    tifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . 421.2.19 Intuitionistic Reasoning . . . . . . . . . . . . . . . . . 431.2.20 Atomizing meta-level connectives . . . . . . . . . . . . 441.2.21 Atomizing elimination rules . . . . . . . . . . . . . . . 45

    1.3 Package setup . . . . . . . . . . . . . . . . . . . . . . . . . . . 461.3.1 Sledgehammer setup . . . . . . . . . . . . . . . . . . . 46

    1

  • 2

    1.3.2 Classical Reasoner setup . . . . . . . . . . . . . . . . . 461.3.3 THE: definite description operator . . . . . . . . . . . 481.3.4 Simplifier . . . . . . . . . . . . . . . . . . . . . . . . . 491.3.5 Generic cases and induction . . . . . . . . . . . . . . . 591.3.6 Coherent logic . . . . . . . . . . . . . . . . . . . . . . 621.3.7 Reorienting equalities . . . . . . . . . . . . . . . . . . 62

    1.4 Other simple lemmas and lemma duplicates . . . . . . . . . . 631.5 Basic ML bindings . . . . . . . . . . . . . . . . . . . . . . . . 64

    2 NO-MATCH simproc 662.1 Code generator setup . . . . . . . . . . . . . . . . . . . . . . . 67

    2.1.1 Generic code generator preprocessor setup . . . . . . . 672.1.2 Equality . . . . . . . . . . . . . . . . . . . . . . . . . . 682.1.3 Generic code generator foundation . . . . . . . . . . . 682.1.4 Generic code generator target languages . . . . . . . . 702.1.5 Evaluation and normalization by evaluation . . . . . . 71

    2.2 Counterexample Search Units . . . . . . . . . . . . . . . . . . 722.2.1 Quickcheck . . . . . . . . . . . . . . . . . . . . . . . . 722.2.2 Nitpick setup . . . . . . . . . . . . . . . . . . . . . . . 72

    2.3 Preprocessing for the predicate compiler . . . . . . . . . . . . 722.4 Legacy tactics and ML bindings . . . . . . . . . . . . . . . . . 72

    3 Abstract orderings 733.1 Abstract ordering . . . . . . . . . . . . . . . . . . . . . . . . . 733.2 Syntactic orders . . . . . . . . . . . . . . . . . . . . . . . . . . 753.3 Quasi orders . . . . . . . . . . . . . . . . . . . . . . . . . . . . 763.4 Partial orders . . . . . . . . . . . . . . . . . . . . . . . . . . . 773.5 Linear (total) orders . . . . . . . . . . . . . . . . . . . . . . . 803.6 Reasoning tools setup . . . . . . . . . . . . . . . . . . . . . . 823.7 Bounded quantifiers . . . . . . . . . . . . . . . . . . . . . . . 873.8 Transitivity reasoning . . . . . . . . . . . . . . . . . . . . . . 893.9 Monotonicity . . . . . . . . . . . . . . . . . . . . . . . . . . . 953.10 min and max – fundamental . . . . . . . . . . . . . . . . . . . 983.11 (Unique) top and bottom elements . . . . . . . . . . . . . . . 983.12 Dense orders . . . . . . . . . . . . . . . . . . . . . . . . . . . 1003.13 Wellorders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1023.14 Order on bool . . . . . . . . . . . . . . . . . . . . . . . . . . . 1033.15 Order on - ⇒ - . . . . . . . . . . . . . . . . . . . . . . . . . . 1043.16 Order on unary and binary predicates . . . . . . . . . . . . . 1063.17 Name duplicates . . . . . . . . . . . . . . . . . . . . . . . . . 107

  • 3

    4 Groups, also combined with orderings 1084.1 Dynamic facts . . . . . . . . . . . . . . . . . . . . . . . . . . . 1084.2 Abstract structures . . . . . . . . . . . . . . . . . . . . . . . . 1084.3 Generic operations . . . . . . . . . . . . . . . . . . . . . . . . 1114.4 Semigroups and Monoids . . . . . . . . . . . . . . . . . . . . 1124.5 Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1164.6 (Partially) Ordered Groups . . . . . . . . . . . . . . . . . . . 1204.7 Support for reasoning about signs . . . . . . . . . . . . . . . . 1224.8 Canonically ordered monoids . . . . . . . . . . . . . . . . . . 1354.9 Tools setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138

    5 Abstract lattices 1385.1 Abstract semilattice . . . . . . . . . . . . . . . . . . . . . . . 1395.2 Syntactic infimum and supremum operations . . . . . . . . . 1415.3 Concrete lattices . . . . . . . . . . . . . . . . . . . . . . . . . 142

    5.3.1 Intro and elim rules . . . . . . . . . . . . . . . . . . . 1425.3.2 Equational laws . . . . . . . . . . . . . . . . . . . . . . 1435.3.3 Strict order . . . . . . . . . . . . . . . . . . . . . . . . 146

    5.4 Distributive lattices . . . . . . . . . . . . . . . . . . . . . . . 1475.5 Bounded lattices and boolean algebras . . . . . . . . . . . . . 1475.6 min/max as special case of lattice . . . . . . . . . . . . . . . 1535.7 Uniqueness of inf and sup . . . . . . . . . . . . . . . . . . . . 1555.8 Lattice on bool . . . . . . . . . . . . . . . . . . . . . . . . . . 1555.9 Lattice on - ⇒ - . . . . . . . . . . . . . . . . . . . . . . . . . 1565.10 Lattice on unary and binary predicates . . . . . . . . . . . . . 157

    6 Set theory for higher-order logic 1586.1 Sets as predicates . . . . . . . . . . . . . . . . . . . . . . . . . 1586.2 Subsets and bounded quantifiers . . . . . . . . . . . . . . . . 1616.3 Basic operations . . . . . . . . . . . . . . . . . . . . . . . . . 167

    6.3.1 Subsets . . . . . . . . . . . . . . . . . . . . . . . . . . 1676.3.2 Equality . . . . . . . . . . . . . . . . . . . . . . . . . . 1686.3.3 The empty set . . . . . . . . . . . . . . . . . . . . . . 1686.3.4 The universal set – UNIV . . . . . . . . . . . . . . . . 1696.3.5 The Powerset operator – Pow . . . . . . . . . . . . . . 1706.3.6 Set complement . . . . . . . . . . . . . . . . . . . . . . 1706.3.7 Binary intersection . . . . . . . . . . . . . . . . . . . . 1716.3.8 Binary union . . . . . . . . . . . . . . . . . . . . . . . 1716.3.9 Set difference . . . . . . . . . . . . . . . . . . . . . . . 1726.3.10 Augmenting a set – insert . . . . . . . . . . . . . . . . 1726.3.11 Singletons, using insert . . . . . . . . . . . . . . . . . 1736.3.12 Image of a set under a function . . . . . . . . . . . . . 1756.3.13 Some rules with if . . . . . . . . . . . . . . . . . . . . 177

    6.4 Further operations and lemmas . . . . . . . . . . . . . . . . . 178

  • 4

    6.4.1 The “proper subset” relation . . . . . . . . . . . . . . 1786.4.2 Derived rules involving subsets. . . . . . . . . . . . . . 1796.4.3 Equalities involving union, intersection, inclusion, etc. 1806.4.4 Monotonicity of various operations . . . . . . . . . . . 1906.4.5 Inverse image of a function . . . . . . . . . . . . . . . 1916.4.6 Singleton sets . . . . . . . . . . . . . . . . . . . . . . . 1926.4.7 Getting the contents of a singleton set . . . . . . . . . 1936.4.8 Least value operator . . . . . . . . . . . . . . . . . . . 1936.4.9 Monad operation . . . . . . . . . . . . . . . . . . . . . 1946.4.10 Operations for execution . . . . . . . . . . . . . . . . . 194

    7 HOL type definitions 198

    8 Notions about functions 2008.1 The Identity Function id . . . . . . . . . . . . . . . . . . . . . 2018.2 The Composition Operator f ◦ g . . . . . . . . . . . . . . . . 2018.3 The Forward Composition Operator fcomp . . . . . . . . . . 2028.4 Mapping functions . . . . . . . . . . . . . . . . . . . . . . . . 2038.5 Injectivity and Bijectivity . . . . . . . . . . . . . . . . . . . . 2038.6 Function Updating . . . . . . . . . . . . . . . . . . . . . . . . 2148.7 override-on . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2168.8 swap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2168.9 Inversion of injective functions . . . . . . . . . . . . . . . . . 2188.10 Cantor’s Paradox . . . . . . . . . . . . . . . . . . . . . . . . . 2198.11 Monotonic functions over a set . . . . . . . . . . . . . . . . . 2198.12 Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221

    8.12.1 Proof tools . . . . . . . . . . . . . . . . . . . . . . . . 2218.12.2 Functorial structure of types . . . . . . . . . . . . . . 221

    9 Complete lattices 2229.1 Syntactic infimum and supremum operations . . . . . . . . . 2229.2 Abstract complete lattices . . . . . . . . . . . . . . . . . . . . 2239.3 Complete lattice on bool . . . . . . . . . . . . . . . . . . . . . 2349.4 Complete lattice on - ⇒ - . . . . . . . . . . . . . . . . . . . . 2359.5 Complete lattice on unary and binary predicates . . . . . . . 2369.6 Complete lattice on - set . . . . . . . . . . . . . . . . . . . . . 237

    9.6.1 Inter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2389.6.2 Intersections of families . . . . . . . . . . . . . . . . . 2399.6.3 Union . . . . . . . . . . . . . . . . . . . . . . . . . . . 2419.6.4 Unions of families . . . . . . . . . . . . . . . . . . . . 2429.6.5 Distributive laws . . . . . . . . . . . . . . . . . . . . . 245

    9.7 Injections and bijections . . . . . . . . . . . . . . . . . . . . . 2469.7.1 Complement . . . . . . . . . . . . . . . . . . . . . . . 2489.7.2 Miniscoping and maxiscoping . . . . . . . . . . . . . . 248

  • 5

    10 Wrapping Existing Freely Generated Type’s Constructors 250

    11 Knaster-Tarski Fixpoint Theorem and inductive definitions25111.1 Least fixed points . . . . . . . . . . . . . . . . . . . . . . . . . 25111.2 General induction rules for least fixed points . . . . . . . . . . 25211.3 Greatest fixed points . . . . . . . . . . . . . . . . . . . . . . . 25311.4 Coinduction rules for greatest fixed points . . . . . . . . . . . 25411.5 Even Stronger Coinduction Rule, by Martin Coen . . . . . . 25611.6 Rules for fixed point calculus . . . . . . . . . . . . . . . . . . 25711.7 Inductive predicates and sets . . . . . . . . . . . . . . . . . . 25911.8 The Schroeder-Bernstein Theorem . . . . . . . . . . . . . . . 25911.9 Inductive datatypes and primitive recursion . . . . . . . . . . 261

    12 Cartesian products 26112.1 bool is a datatype . . . . . . . . . . . . . . . . . . . . . . . . . 26212.2 The unit type . . . . . . . . . . . . . . . . . . . . . . . . . . . 26212.3 The product type . . . . . . . . . . . . . . . . . . . . . . . . . 265

    12.3.1 Type definition . . . . . . . . . . . . . . . . . . . . . . 26512.3.2 Tuple syntax . . . . . . . . . . . . . . . . . . . . . . . 26712.3.3 Code generator setup . . . . . . . . . . . . . . . . . . 26912.3.4 Fundamental operations and properties . . . . . . . . 26912.3.5 Derived operations . . . . . . . . . . . . . . . . . . . . 276

    12.4 Simproc for rewriting a set comprehension into a pointfreeexpression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286

    12.5 Lemmas about disjointness . . . . . . . . . . . . . . . . . . . 28712.6 Inductively defined sets . . . . . . . . . . . . . . . . . . . . . 28712.7 Legacy theorem bindings and duplicates . . . . . . . . . . . . 288

    13 The Disjoint Sum of Two Types 28813.1 Construction of the sum type and its basic abstract operations28813.2 Projections . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29113.3 The Disjoint Sum of Sets . . . . . . . . . . . . . . . . . . . . 292

    14 Rings 29314.1 Semirings and rings . . . . . . . . . . . . . . . . . . . . . . . . 29314.2 Abstract divisibility . . . . . . . . . . . . . . . . . . . . . . . 29514.3 Towards integral domains . . . . . . . . . . . . . . . . . . . . 30114.4 (Partial) Division . . . . . . . . . . . . . . . . . . . . . . . . . 30614.5 Quotient and remainder in integral domains . . . . . . . . . . 32814.6 Interlude: basic tool support for algebraic and arithmetic cal-

    culations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33014.7 Ordered semirings and rings . . . . . . . . . . . . . . . . . . . 33014.8 Dioids . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347

  • 6

    15 Natural numbers 34715.1 Type ind . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34715.2 Type nat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34815.3 Arithmetic operators . . . . . . . . . . . . . . . . . . . . . . . 351

    15.3.1 Addition . . . . . . . . . . . . . . . . . . . . . . . . . . 35315.3.2 Difference . . . . . . . . . . . . . . . . . . . . . . . . . 35415.3.3 Multiplication . . . . . . . . . . . . . . . . . . . . . . . 354

    15.4 Orders on nat . . . . . . . . . . . . . . . . . . . . . . . . . . . 35515.4.1 Operation definition . . . . . . . . . . . . . . . . . . . 35515.4.2 Introduction properties . . . . . . . . . . . . . . . . . 35715.4.3 Elimination properties . . . . . . . . . . . . . . . . . . 35815.4.4 Inductive (?) properties . . . . . . . . . . . . . . . . . 35815.4.5 Monotonicity of Addition . . . . . . . . . . . . . . . . 36215.4.6 min and max . . . . . . . . . . . . . . . . . . . . . . . 36515.4.7 Additional theorems about (≤) . . . . . . . . . . . . . 36615.4.8 More results about difference . . . . . . . . . . . . . . 37215.4.9 Monotonicity of multiplication . . . . . . . . . . . . . 374

    15.5 Natural operation of natural numbers on functions . . . . . . 37615.6 Kleene iteration . . . . . . . . . . . . . . . . . . . . . . . . . . 37815.7 Embedding of the naturals into any semiring-1 : of-nat . . . . 38015.8 The set of natural numbers . . . . . . . . . . . . . . . . . . . 38415.9 Further arithmetic facts concerning the natural numbers . . . 386

    15.9.1 Greatest operator . . . . . . . . . . . . . . . . . . . . . 39315.10Monotonicity of funpow . . . . . . . . . . . . . . . . . . . . . 39415.11The divides relation on nat . . . . . . . . . . . . . . . . . . . 39415.12Aliasses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39615.13Size of a datatype value . . . . . . . . . . . . . . . . . . . . . 39815.14Code module namespace . . . . . . . . . . . . . . . . . . . . . 398

    16 Fields 39816.1 Division rings . . . . . . . . . . . . . . . . . . . . . . . . . . . 39916.2 Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40516.3 Ordered fields . . . . . . . . . . . . . . . . . . . . . . . . . . . 410

    17 Finite sets 42517.1 Predicate for finite sets . . . . . . . . . . . . . . . . . . . . . . 425

    17.1.1 Choice principles . . . . . . . . . . . . . . . . . . . . . 42617.1.2 Finite sets are the images of initial segments of natural

    numbers . . . . . . . . . . . . . . . . . . . . . . . . . . 42717.2 Finiteness and common set operations . . . . . . . . . . . . . 42817.3 Further induction rules on finite sets . . . . . . . . . . . . . . 43617.4 Class finite . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43917.5 A basic fold functional for finite sets . . . . . . . . . . . . . . 440

    17.5.1 From fold-graph to fold . . . . . . . . . . . . . . . . . 441

  • 7

    17.5.2 Liftings to comp-fun-commute etc. . . . . . . . . . . . 44617.5.3 Expressing set operations via fold . . . . . . . . . . . 447

    17.6 Locales as mini-packages for fold operations . . . . . . . . . . 45117.6.1 The natural case . . . . . . . . . . . . . . . . . . . . . 45117.6.2 With idempotency . . . . . . . . . . . . . . . . . . . . 452

    17.7 Finite cardinality . . . . . . . . . . . . . . . . . . . . . . . . . 45217.7.1 Cardinality of image . . . . . . . . . . . . . . . . . . . 46317.7.2 Pigeonhole Principles . . . . . . . . . . . . . . . . . . 46417.7.3 Cardinality of sums . . . . . . . . . . . . . . . . . . . 46517.7.4 Relating injectivity and surjectivity . . . . . . . . . . 466

    17.8 Infinite Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46817.9 The finite powerset operator . . . . . . . . . . . . . . . . . . . 470

    18 Relations – as sets of pairs, and binary predicates 47118.1 Fundamental . . . . . . . . . . . . . . . . . . . . . . . . . . . 472

    18.1.1 Relations as sets of pairs . . . . . . . . . . . . . . . . . 47218.1.2 Conversions between set and predicate relations . . . . 472

    18.2 Properties of relations . . . . . . . . . . . . . . . . . . . . . . 47418.2.1 Reflexivity . . . . . . . . . . . . . . . . . . . . . . . . 47418.2.2 Irreflexivity . . . . . . . . . . . . . . . . . . . . . . . . 47618.2.3 Asymmetry . . . . . . . . . . . . . . . . . . . . . . . . 47618.2.4 Symmetry . . . . . . . . . . . . . . . . . . . . . . . . . 47618.2.5 Antisymmetry . . . . . . . . . . . . . . . . . . . . . . 47718.2.6 Transitivity . . . . . . . . . . . . . . . . . . . . . . . . 47818.2.7 Totality . . . . . . . . . . . . . . . . . . . . . . . . . . 48018.2.8 Single valued relations . . . . . . . . . . . . . . . . . . 481

    18.3 Relation operations . . . . . . . . . . . . . . . . . . . . . . . . 48218.3.1 The identity relation . . . . . . . . . . . . . . . . . . . 48218.3.2 Diagonal: identity over a set . . . . . . . . . . . . . . 48218.3.3 Composition . . . . . . . . . . . . . . . . . . . . . . . 48318.3.4 Converse . . . . . . . . . . . . . . . . . . . . . . . . . 48518.3.5 Domain, range and field . . . . . . . . . . . . . . . . . 48918.3.6 Image of a set under a relation . . . . . . . . . . . . . 49218.3.7 Inverse image . . . . . . . . . . . . . . . . . . . . . . . 49418.3.8 Powerset . . . . . . . . . . . . . . . . . . . . . . . . . . 49418.3.9 Expressing relation operations via Finite-Set .fold . . . 494

    19 Reflexive and Transitive closure of a relation 49619.1 Reflexive closure . . . . . . . . . . . . . . . . . . . . . . . . . 49719.2 Reflexive-transitive closure . . . . . . . . . . . . . . . . . . . . 49819.3 Transitive closure . . . . . . . . . . . . . . . . . . . . . . . . . 50319.4 Symmetric closure . . . . . . . . . . . . . . . . . . . . . . . . 51119.5 The power operation on relations . . . . . . . . . . . . . . . . 51119.6 Bounded transitive closure . . . . . . . . . . . . . . . . . . . . 520

  • 8

    19.7 Acyclic relations . . . . . . . . . . . . . . . . . . . . . . . . . 52119.8 Setup of transitivity reasoner . . . . . . . . . . . . . . . . . . 522

    20 Well-founded Recursion 52420.1 Basic Definitions . . . . . . . . . . . . . . . . . . . . . . . . . 52420.2 Basic Results . . . . . . . . . . . . . . . . . . . . . . . . . . . 525

    20.2.1 Minimal-element characterization of well-foundedness 52620.2.2 Well-foundedness of transitive closure . . . . . . . . . 52620.2.3 Well-foundedness of image . . . . . . . . . . . . . . . . 529

    20.3 Well-Foundedness Results for Unions . . . . . . . . . . . . . . 52920.4 Well-Foundedness of Composition . . . . . . . . . . . . . . . . 53220.5 Acyclic relations . . . . . . . . . . . . . . . . . . . . . . . . . 533

    20.5.1 Wellfoundedness of finite acyclic relations . . . . . . . 53420.6 nat is well-founded . . . . . . . . . . . . . . . . . . . . . . . . 53420.7 Accessible Part . . . . . . . . . . . . . . . . . . . . . . . . . . 53520.8 Tools for building wellfounded relations . . . . . . . . . . . . 538

    20.8.1 Lexicographic combinations . . . . . . . . . . . . . . . 53820.8.2 Bounded increase must terminate . . . . . . . . . . . . 542

    21 Well-Founded Recursion Combinator 54321.0.1 Well-founded recursion via genuine fixpoints . . . . . . 544

    21.1 Wellfoundedness of same-fst . . . . . . . . . . . . . . . . . . . 544

    22 Orders as Relations 54522.1 Orders on a set . . . . . . . . . . . . . . . . . . . . . . . . . . 54522.2 Orders on the field . . . . . . . . . . . . . . . . . . . . . . . . 54622.3 Relations given by a predicate and the field . . . . . . . . . . 54822.4 Orders on a type . . . . . . . . . . . . . . . . . . . . . . . . . 54822.5 Order-like relations . . . . . . . . . . . . . . . . . . . . . . . . 549

    22.5.1 Auxiliaries . . . . . . . . . . . . . . . . . . . . . . . . 54922.5.2 The upper and lower bounds operators . . . . . . . . . 550

    22.6 Variations on Well-Founded Relations . . . . . . . . . . . . . 55322.6.1 Characterizations of well-foundedness . . . . . . . . . 55322.6.2 Characterizations of well-foundedness . . . . . . . . . 555

    23 Hilbert’s Epsilon-Operator and the Axiom of Choice 55723.1 Hilbert’s epsilon . . . . . . . . . . . . . . . . . . . . . . . . . 55723.2 Hilbert’s Epsilon-operator . . . . . . . . . . . . . . . . . . . . 55723.3 Axiom of Choice, Proved Using the Description Operator . . 55823.4 Function Inverse . . . . . . . . . . . . . . . . . . . . . . . . . 55923.5 Other Consequences of Hilbert’s Epsilon . . . . . . . . . . . . 56823.6 An aside: bounded accessible part . . . . . . . . . . . . . . . 57023.7 More on injections, bijections, and inverses . . . . . . . . . . 57223.8 Specification package – Hilbertized version . . . . . . . . . . . 575

  • 9

    23.9 Complete Distributive Lattices – Properties depending onHilbert Choice . . . . . . . . . . . . . . . . . . . . . . . . . . 575

    24 Zorn’s Lemma 58324.1 Zorn’s Lemma for the Subset Relation . . . . . . . . . . . . . 584

    24.1.1 Results that do not require an order . . . . . . . . . . 58424.1.2 Hausdorff’s Maximum Principle . . . . . . . . . . . . . 59024.1.3 Results for the proper subset relation . . . . . . . . . 59024.1.4 Zorn’s lemma . . . . . . . . . . . . . . . . . . . . . . . 591

    24.2 Zorn’s Lemma for Partial Orders . . . . . . . . . . . . . . . . 59224.3 Other variants of Zorn’s Lemma . . . . . . . . . . . . . . . . 59324.4 The Well Ordering Theorem . . . . . . . . . . . . . . . . . . . 596

    25 Well-Order Relations as Needed by Bounded Natural Func-tors 60225.1 Auxiliaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60325.2 Well-founded induction and recursion adapted to non-strict

    well-order relations . . . . . . . . . . . . . . . . . . . . . . . . 60325.3 The notions of maximum, minimum, supremum, successor

    and order filter . . . . . . . . . . . . . . . . . . . . . . . . . . 60425.3.1 Properties of max2 . . . . . . . . . . . . . . . . . . . . 60525.3.2 Existence and uniqueness for isMinim and well-definedness

    of minim . . . . . . . . . . . . . . . . . . . . . . . . . 60625.3.3 Properties of minim . . . . . . . . . . . . . . . . . . . 60725.3.4 Properties of successor . . . . . . . . . . . . . . . . . . 60825.3.5 Properties of order filters . . . . . . . . . . . . . . . . 61025.3.6 Other properties . . . . . . . . . . . . . . . . . . . . . 612

    26 Well-Order Embeddings as Needed by Bounded NaturalFunctors 61426.1 Auxiliaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61426.2 (Well-order) embeddings, strict embeddings, isomorphisms

    and order-compatible functions . . . . . . . . . . . . . . . . . 61526.3 Given any two well-orders, one can be embedded in the other 62326.4 Uniqueness of embeddings . . . . . . . . . . . . . . . . . . . . 62926.5 More properties of embeddings, strict embeddings and iso-

    morphisms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631

    27 Constructions on Wellorders as Needed by Bounded NaturalFunctors 63627.1 Restriction to a set . . . . . . . . . . . . . . . . . . . . . . . . 63627.2 Order filters versus restrictions and embeddings . . . . . . . . 63827.3 The strict inclusion on proper ofilters is well-founded . . . . . 64127.4 Ordering the well-orders by existence of embeddings . . . . . 642

  • 10

    27.5

  • 11

    36.4 Clausification helper . . . . . . . . . . . . . . . . . . . . . . . 75036.5 Skolemization helpers . . . . . . . . . . . . . . . . . . . . . . 75136.6 Meson package . . . . . . . . . . . . . . . . . . . . . . . . . . 751

    37 Automatic Theorem Provers (ATPs) 75137.1 ATP problems and proofs . . . . . . . . . . . . . . . . . . . . 75237.2 Higher-order reasoning helpers . . . . . . . . . . . . . . . . . 75237.3 Basic connection between ATPs and HOL . . . . . . . . . . . 754

    38 Metis Proof Method 75438.1 Literal selection and lambda-lifting helpers . . . . . . . . . . 75438.2 Metis package . . . . . . . . . . . . . . . . . . . . . . . . . . . 755

    39 Generic theorem transfer using relations 75539.1 Relator for function space . . . . . . . . . . . . . . . . . . . . 75539.2 Transfer method . . . . . . . . . . . . . . . . . . . . . . . . . 75639.3 Predicates on relations, i.e. “class constraints” . . . . . . . . 75739.4 Properties of relators . . . . . . . . . . . . . . . . . . . . . . . 76139.5 Transfer rules . . . . . . . . . . . . . . . . . . . . . . . . . . . 76339.6 of-bool and of-nat . . . . . . . . . . . . . . . . . . . . . . . . 768

    40 Binary Numerals 76940.1 The num type . . . . . . . . . . . . . . . . . . . . . . . . . . . 76940.2 Numeral operations . . . . . . . . . . . . . . . . . . . . . . . . 77040.3 Binary numerals . . . . . . . . . . . . . . . . . . . . . . . . . 77340.4 Class-specific numeral rules . . . . . . . . . . . . . . . . . . . 775

    40.4.1 Structures with addition: class numeral . . . . . . . . 77540.4.2 Structures with negation: class neg-numeral . . . . . . 77640.4.3 Structures with multiplication: class semiring-numeral 77940.4.4 Structures with a zero: class semiring-1 . . . . . . . . 77940.4.5 Equality: class semiring-char-0 . . . . . . . . . . . . . 78040.4.6 Comparisons: class linordered-nonzero-semiring . . . . 78140.4.7 Multiplication and negation: class ring-1 . . . . . . . 78340.4.8 Equality using iszero for rings with non-zero charac-

    teristic . . . . . . . . . . . . . . . . . . . . . . . . . . . 78340.4.9 Equality and negation: class ring-char-0 . . . . . . . . 78440.4.10 Structures with negation and order: class linordered-idom78640.4.11 Natural numbers . . . . . . . . . . . . . . . . . . . . . 788

    40.5 Particular lemmas concerning 2 :: ′a . . . . . . . . . . . . . . . 79140.6 Numeral equations as default simplification rules . . . . . . . 791

    40.6.1 Special Simplification for Constants . . . . . . . . . . 79240.6.2 Optional Simplification Rules Involving Constants . . 793

    40.7 Setting up simprocs . . . . . . . . . . . . . . . . . . . . . . . 794

  • 12

    40.7.1 Simplification of arithmetic operations on integer con-stants . . . . . . . . . . . . . . . . . . . . . . . . . . . 795

    40.7.2 Simplification of arithmetic when nested to the right . 79640.8 Code module namespace . . . . . . . . . . . . . . . . . . . . . 79740.9 Printing of evaluated natural numbers as numerals . . . . . . 797

    41 Exponentiation 79741.1 Powers for Arbitrary Monoids . . . . . . . . . . . . . . . . . . 79741.2 Exponentiation on ordered types . . . . . . . . . . . . . . . . 80641.3 Miscellaneous rules . . . . . . . . . . . . . . . . . . . . . . . . 81441.4 Exponentiation for the Natural Numbers . . . . . . . . . . . . 815

    41.4.1 Cardinality of the Powerset . . . . . . . . . . . . . . . 81741.5 Code generator tweak . . . . . . . . . . . . . . . . . . . . . . 818

    42 Big sum and product over finite (non-empty) sets 81842.1 Generic monoid operation over a set . . . . . . . . . . . . . . 818

    42.1.1 Standard sum or product indexed by a finite set . . . 81842.1.2 HOL Light variant: sum/product indexed by the non-

    neutral subset . . . . . . . . . . . . . . . . . . . . . . . 82942.2 Generalized summation over a set . . . . . . . . . . . . . . . . 831

    42.2.1 Properties in more restricted classes of structures . . . 83242.2.2 Cardinality as special case of sum . . . . . . . . . . . 84142.2.3 Cardinality of products . . . . . . . . . . . . . . . . . 845

    42.3 Generalized product over a set . . . . . . . . . . . . . . . . . 84542.3.1 Properties in more restricted classes of structures . . . 846

    43 Equivalence Relations in Higher-Order Set Theory 85243.1 Equivalence relations – set version . . . . . . . . . . . . . . . 85243.2 Equivalence classes . . . . . . . . . . . . . . . . . . . . . . . . 85343.3 Quotients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85443.4 Refinement of one equivalence relation WRT another . . . . . 85543.5 Defining unary operations upon equivalence classes . . . . . . 85643.6 Defining binary operations upon equivalence classes . . . . . 85743.7 Quotients and finiteness . . . . . . . . . . . . . . . . . . . . . 85843.8 Projection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85943.9 Equivalence relations – predicate version . . . . . . . . . . . . 86043.10Equivalence closure . . . . . . . . . . . . . . . . . . . . . . . . 862

    44 Lifting package 86444.1 Function map . . . . . . . . . . . . . . . . . . . . . . . . . . . 86444.2 Quotient Predicate . . . . . . . . . . . . . . . . . . . . . . . . 86544.3 Quotient composition . . . . . . . . . . . . . . . . . . . . . . 86844.4 Respects predicate . . . . . . . . . . . . . . . . . . . . . . . . 86844.5 Domains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 874

  • 13

    44.6 ML setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 875

    45 Definition of Quotient Types 87645.1 Quotient Predicate . . . . . . . . . . . . . . . . . . . . . . . . 87645.2 lemmas for regularisation of ball and bex . . . . . . . . . . . 88045.3 Bounded abstraction . . . . . . . . . . . . . . . . . . . . . . . 88245.4 Bex1-rel quantifier . . . . . . . . . . . . . . . . . . . . . . . . 88445.5 Various respects and preserve lemmas . . . . . . . . . . . . . 88445.6 Quotient composition . . . . . . . . . . . . . . . . . . . . . . 88745.7 Quotient3 to Quotient . . . . . . . . . . . . . . . . . . . . . . 88845.8 ML setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88945.9 Methods / Interface . . . . . . . . . . . . . . . . . . . . . . . 890

    46 Lifting of BNFs 891

    47 Chain-complete partial orders and their fixpoints 89447.1 Monotone functions . . . . . . . . . . . . . . . . . . . . . . . 89447.2 Chains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89547.3 Chain-complete partial orders . . . . . . . . . . . . . . . . . . 89547.4 Transfinite iteration of a function . . . . . . . . . . . . . . . . 89647.5 Fixpoint combinator . . . . . . . . . . . . . . . . . . . . . . . 89747.6 Fixpoint induction . . . . . . . . . . . . . . . . . . . . . . . . 898

    48 Datatype option 90248.0.1 Operations . . . . . . . . . . . . . . . . . . . . . . . . 903

    48.1 Transfer rules for the Transfer package . . . . . . . . . . . . . 90848.1.1 Interaction with finite sets . . . . . . . . . . . . . . . . 90948.1.2 Code generator setup . . . . . . . . . . . . . . . . . . 909

    49 Partial Function Definitions 91049.1 Axiomatic setup . . . . . . . . . . . . . . . . . . . . . . . . . 91149.2 Flat interpretation: tailrec and option . . . . . . . . . . . . . 914

    50 Reconstructing external resolution proofs for propositionallogic 920

    51 Function Definitions and Termination Proofs 92051.1 Definitions with default value . . . . . . . . . . . . . . . . . . 92051.2 Measure functions . . . . . . . . . . . . . . . . . . . . . . . . 92251.3 Congruence rules . . . . . . . . . . . . . . . . . . . . . . . . . 92351.4 Simp rules for termination proofs . . . . . . . . . . . . . . . . 92351.5 Decomposition . . . . . . . . . . . . . . . . . . . . . . . . . . 92351.6 Reduction pairs . . . . . . . . . . . . . . . . . . . . . . . . . . 92351.7 Concrete orders for SCNP termination proofs . . . . . . . . . 92451.8 Yet another induction principle on the natural numbers . . . 926

  • 14

    51.9 Tool setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 926

    52 The Integers as Equivalence Classes over Pairs of NaturalNumbers 92652.1 Definition of integers as a quotient type . . . . . . . . . . . . 92752.2 Integers form a commutative ring . . . . . . . . . . . . . . . . 92752.3 Integers are totally ordered . . . . . . . . . . . . . . . . . . . 92852.4 Ordering properties of arithmetic operations . . . . . . . . . . 92952.5 Embedding of the Integers into any ring-1 : of-int . . . . . . . 93052.6 Magnitude of an Integer, as a Natural Number: nat . . . . . 93652.7 Lemmas about the Function of-nat and Orderings . . . . . . 94052.8 Cases and induction . . . . . . . . . . . . . . . . . . . . . . . 941

    52.8.1 Binary comparisons . . . . . . . . . . . . . . . . . . . 94352.8.2 Comparisons, for Ordered Rings . . . . . . . . . . . . 943

    52.9 The Set of Integers . . . . . . . . . . . . . . . . . . . . . . . . 94452.10sum and prod . . . . . . . . . . . . . . . . . . . . . . . . . . . 94852.11Setting up simplification procedures . . . . . . . . . . . . . . 94852.12More Inequality Reasoning . . . . . . . . . . . . . . . . . . . 94952.13The functions nat and int . . . . . . . . . . . . . . . . . . . . 95052.14Induction principles for int . . . . . . . . . . . . . . . . . . . 95252.15Intermediate value theorems . . . . . . . . . . . . . . . . . . . 95552.16Products and 1, by T. M. Rasmussen . . . . . . . . . . . . . . 95552.17The divides relation . . . . . . . . . . . . . . . . . . . . . . . 95652.18Finiteness of intervals . . . . . . . . . . . . . . . . . . . . . . 96152.19Configuration of the code generator . . . . . . . . . . . . . . . 96152.20Duplicates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 964

    53 Big infimum (minimum) and supremum (maximum) overfinite (non-empty) sets 96553.1 Generic lattice operations over a set . . . . . . . . . . . . . . 965

    53.1.1 Without neutral element . . . . . . . . . . . . . . . . . 96553.1.2 With neutral element . . . . . . . . . . . . . . . . . . 968

    53.2 Lattice operations on finite sets . . . . . . . . . . . . . . . . . 97153.3 Infimum and Supremum over non-empty sets . . . . . . . . . 97153.4 Minimum and Maximum over non-empty sets . . . . . . . . . 97453.5 Arg Min . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98353.6 Arg Max . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 985

    54 Division in euclidean (semi)rings 98654.1 Euclidean (semi)rings with explicit division and remainder . . 98654.2 Euclidean (semi)rings with cancel rules . . . . . . . . . . . . . 99054.3 Uniquely determined division . . . . . . . . . . . . . . . . . . 99854.4 Euclidean division on nat . . . . . . . . . . . . . . . . . . . . 100354.5 Euclidean division on int . . . . . . . . . . . . . . . . . . . . 1016

  • 15

    54.6 Special case: euclidean rings containing the natural numbers 102254.7 Code generation . . . . . . . . . . . . . . . . . . . . . . . . . 1028

    55 Parity in rings and semirings 102855.1 Ring structures with parity and even/odd predicates . . . . . 102855.2 Special case: euclidean rings containing the natural numbers 103255.3 Instance for nat . . . . . . . . . . . . . . . . . . . . . . . . . . 103455.4 Parity and powers . . . . . . . . . . . . . . . . . . . . . . . . 103755.5 Instance for int . . . . . . . . . . . . . . . . . . . . . . . . . . 104155.6 Abstract bit structures . . . . . . . . . . . . . . . . . . . . . . 1041

    56 More on quotient and remainder 106056.1 More on division . . . . . . . . . . . . . . . . . . . . . . . . . 1060

    56.1.1 General Properties of div and mod . . . . . . . . . . . 106356.1.2 Laws for div and mod with Unary Minus . . . . . . . 106456.1.3 Monotonicity in the First Argument (Dividend) . . . . 106556.1.4 Monotonicity in the Second Argument (Divisor) . . . 106556.1.5 Splitting Rules for div and mod . . . . . . . . . . . . . 106756.1.6 Computing div and mod with shifting . . . . . . . . . 106856.1.7 Quotients of Signs . . . . . . . . . . . . . . . . . . . . 106956.1.8 Further properties . . . . . . . . . . . . . . . . . . . . 1071

    56.2 Numeral division with a pragmatic type class . . . . . . . . . 107456.2.1 Dedicated simproc for calculation . . . . . . . . . . . . 108356.2.2 Code generation . . . . . . . . . . . . . . . . . . . . . 1084

    56.3 Lemmas of doubtful value . . . . . . . . . . . . . . . . . . . . 1085

    57 Combination and Cancellation Simprocs for Numeral Ex-pressions 1086

    58 Semiring normalization 1092

    59 Groebner bases 109659.1 Groebner Bases . . . . . . . . . . . . . . . . . . . . . . . . . . 1096

    60 Set intervals 109760.1 Various equivalences . . . . . . . . . . . . . . . . . . . . . . . 109960.2 Logical Equivalences for Set Inclusion and Equality . . . . . . 110060.3 Two-sided intervals . . . . . . . . . . . . . . . . . . . . . . . . 1101

    60.3.1 Emptyness, singletons, subset . . . . . . . . . . . . . . 110260.4 Infinite intervals . . . . . . . . . . . . . . . . . . . . . . . . . 1108

    60.4.1 Intersection . . . . . . . . . . . . . . . . . . . . . . . . 111060.5 Intervals of natural numbers . . . . . . . . . . . . . . . . . . . 1111

    60.5.1 The Constant lessThan . . . . . . . . . . . . . . . . . 111160.5.2 The Constant greaterThan . . . . . . . . . . . . . . . 111260.5.3 The Constant atLeast . . . . . . . . . . . . . . . . . . 1112

  • 16

    60.5.4 The Constant atMost . . . . . . . . . . . . . . . . . . 111260.5.5 The Constant atLeastLessThan . . . . . . . . . . . . . 111360.5.6 The Constant atLeastAtMost . . . . . . . . . . . . . . 111360.5.7 Intervals of nats with Suc . . . . . . . . . . . . . . . . 111460.5.8 Intervals and numerals . . . . . . . . . . . . . . . . . . 111460.5.9 Image . . . . . . . . . . . . . . . . . . . . . . . . . . . 111560.5.10 Finiteness . . . . . . . . . . . . . . . . . . . . . . . . . 112160.5.11 Proving Inclusions and Equalities between Unions . . 112360.5.12 Cardinality . . . . . . . . . . . . . . . . . . . . . . . . 1124

    60.6 Intervals of integers . . . . . . . . . . . . . . . . . . . . . . . . 112660.6.1 Finiteness . . . . . . . . . . . . . . . . . . . . . . . . . 112760.6.2 Cardinality . . . . . . . . . . . . . . . . . . . . . . . . 1127

    60.7 Lemmas useful with the summation operator sum . . . . . . . 112960.7.1 Disjoint Unions . . . . . . . . . . . . . . . . . . . . . . 112960.7.2 Disjoint Intersections . . . . . . . . . . . . . . . . . . . 113060.7.3 Some Differences . . . . . . . . . . . . . . . . . . . . . 113160.7.4 Some Subset Conditions . . . . . . . . . . . . . . . . . 1131

    60.8 Generic big monoid operation over intervals . . . . . . . . . . 113160.9 Summation indexed over intervals . . . . . . . . . . . . . . . . 1134

    60.9.1 Shifting bounds . . . . . . . . . . . . . . . . . . . . . . 114060.9.2 Telescoping . . . . . . . . . . . . . . . . . . . . . . . . 114160.9.3 The formula for geometric sums . . . . . . . . . . . . . 114260.9.4 Geometric progressions . . . . . . . . . . . . . . . . . 114460.9.5 The formulae for arithmetic sums . . . . . . . . . . . . 114460.9.6 Division remainder . . . . . . . . . . . . . . . . . . . . 1146

    60.10Products indexed over intervals . . . . . . . . . . . . . . . . . 114760.11Efficient folding over intervals . . . . . . . . . . . . . . . . . . 1148

    61 Decision Procedure for Presburger Arithmetic 114961.1 The −∞ and +∞ Properties . . . . . . . . . . . . . . . . . . 114961.2 The A and B sets . . . . . . . . . . . . . . . . . . . . . . . . . 115061.3 Cooper’s Theorem −∞ and +∞ Version . . . . . . . . . . . . 1153

    61.3.1 First some trivial facts about periodic sets or predicates115361.3.2 The −∞ Version . . . . . . . . . . . . . . . . . . . . . 115461.3.3 The +∞ Version . . . . . . . . . . . . . . . . . . . . . 1155

    61.4 Nice facts about division by 4 :: ′a . . . . . . . . . . . . . . . . 116061.5 Try0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1160

    62 Bindings to Satisfiability Modulo Theories (SMT) solversbased on SMT-LIB 2 116062.1 A skolemization tactic and proof method . . . . . . . . . . . . 116062.2 Triggers for quantifier instantiation . . . . . . . . . . . . . . . 116162.3 Higher-order encoding . . . . . . . . . . . . . . . . . . . . . . 116262.4 Normalization . . . . . . . . . . . . . . . . . . . . . . . . . . . 1162

  • 17

    62.5 Integer division and modulo for Z3 . . . . . . . . . . . . . . . 116362.6 Extra theorems for veriT reconstruction . . . . . . . . . . . . 116462.7 Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116662.8 Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . 116662.9 General configuration options . . . . . . . . . . . . . . . . . . 116762.10Certificates . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116762.11Tracing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116862.12Schematic rules for Z3 proof reconstruction . . . . . . . . . . 1168

    63 Sledgehammer: Isabelle–ATP Linkup 1171

    64 Numeric types for code generation onto target language nu-merals only 117164.1 Type of target language integers . . . . . . . . . . . . . . . . 117264.2 Code theorems for target language integers . . . . . . . . . . 117964.3 Serializer setup for target language integers . . . . . . . . . . 118664.4 Type of target language naturals . . . . . . . . . . . . . . . . 118864.5 Inductive representation of target language naturals . . . . . 119464.6 Code refinement for target language naturals . . . . . . . . . 1194

    65 Setup for Lifting/Transfer for the set type 119765.1 Relator and predicator properties . . . . . . . . . . . . . . . . 119765.2 Quotient theorem for the Lifting package . . . . . . . . . . . 119865.3 Transfer rules for the Transfer package . . . . . . . . . . . . . 1199

    65.3.1 Unconditional transfer rules . . . . . . . . . . . . . . . 119965.3.2 Rules requiring bi-unique, bi-total or right-total rela-

    tions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1200

    66 The datatype of finite lists 120366.1 Basic list processing functions . . . . . . . . . . . . . . . . . . 1204

    66.1.1 List comprehension . . . . . . . . . . . . . . . . . . . . 121166.1.2 [] and (#) . . . . . . . . . . . . . . . . . . . . . . . . . 121966.1.3 length . . . . . . . . . . . . . . . . . . . . . . . . . . . 122066.1.4 @ – append . . . . . . . . . . . . . . . . . . . . . . . . 122366.1.5 map . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122666.1.6 rev . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122866.1.7 set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123066.1.8 filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123366.1.9 List partitioning . . . . . . . . . . . . . . . . . . . . . 123666.1.10 concat . . . . . . . . . . . . . . . . . . . . . . . . . . . 123766.1.11 (!) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123866.1.12 list-update . . . . . . . . . . . . . . . . . . . . . . . . . 124166.1.13 last and butlast . . . . . . . . . . . . . . . . . . . . . . 124366.1.14 take and drop . . . . . . . . . . . . . . . . . . . . . . . 1245

  • 18

    66.1.15 takeWhile and dropWhile . . . . . . . . . . . . . . . . 125166.1.16 zip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125566.1.17 list-all2 . . . . . . . . . . . . . . . . . . . . . . . . . . 126166.1.18 List .product and product-lists . . . . . . . . . . . . . . 126466.1.19 fold with natural argument order . . . . . . . . . . . . 126566.1.20 Fold variants: foldr and foldl . . . . . . . . . . . . . . 126866.1.21 upt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126966.1.22 upto: interval-list on int . . . . . . . . . . . . . . . . . 127266.1.23 distinct and remdups and remdups-adj . . . . . . . . . 127366.1.24 insert . . . . . . . . . . . . . . . . . . . . . . . . . . . 128566.1.25 List .union . . . . . . . . . . . . . . . . . . . . . . . . . 128566.1.26 find . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128566.1.27 count-list . . . . . . . . . . . . . . . . . . . . . . . . . 128666.1.28 List .extract . . . . . . . . . . . . . . . . . . . . . . . . 128666.1.29 remove1 . . . . . . . . . . . . . . . . . . . . . . . . . . 128766.1.30 removeAll . . . . . . . . . . . . . . . . . . . . . . . . . 128866.1.31 replicate . . . . . . . . . . . . . . . . . . . . . . . . . . 128966.1.32 enumerate . . . . . . . . . . . . . . . . . . . . . . . . . 129366.1.33 rotate1 and rotate . . . . . . . . . . . . . . . . . . . . 129466.1.34 nths — a generalization of (!) to sets . . . . . . . . . . 129666.1.35 subseqs and List .n-lists . . . . . . . . . . . . . . . . . 129966.1.36 splice . . . . . . . . . . . . . . . . . . . . . . . . . . . 130066.1.37 shuffles . . . . . . . . . . . . . . . . . . . . . . . . . . 130066.1.38 Transpose . . . . . . . . . . . . . . . . . . . . . . . . . 130366.1.39 min and arg-min . . . . . . . . . . . . . . . . . . . . . 130666.1.40 (In)finiteness . . . . . . . . . . . . . . . . . . . . . . . 1306

    66.2 Sorting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130966.2.1 sorted-wrt . . . . . . . . . . . . . . . . . . . . . . . . . 130966.2.2 sorted . . . . . . . . . . . . . . . . . . . . . . . . . . . 131066.2.3 Sorting functions . . . . . . . . . . . . . . . . . . . . . 131466.2.4 transpose on sorted lists . . . . . . . . . . . . . . . . . 131966.2.5 sorted-list-of-set . . . . . . . . . . . . . . . . . . . . . 132266.2.6 lists: the list-forming operator over sets . . . . . . . . 132466.2.7 Inductive definition for membership . . . . . . . . . . 132566.2.8 Lists as Cartesian products . . . . . . . . . . . . . . . 1325

    66.3 Relations on Lists . . . . . . . . . . . . . . . . . . . . . . . . 132666.3.1 Length Lexicographic Ordering . . . . . . . . . . . . . 132666.3.2 Lexicographic Ordering . . . . . . . . . . . . . . . . . 133066.3.3 Lexicographic combination of measure functions . . . 133766.3.4 Lifting Relations to Lists: one element . . . . . . . . . 133766.3.5 Lifting Relations to Lists: all elements . . . . . . . . . 1340

    66.4 Size function . . . . . . . . . . . . . . . . . . . . . . . . . . . 134366.5 Monad operation . . . . . . . . . . . . . . . . . . . . . . . . . 134366.6 Code generation . . . . . . . . . . . . . . . . . . . . . . . . . 1344

  • 19

    66.6.1 Counterparts for set-related operations . . . . . . . . . 134466.6.2 Optimizing by rewriting . . . . . . . . . . . . . . . . . 134866.6.3 Pretty lists . . . . . . . . . . . . . . . . . . . . . . . . 135166.6.4 Use convenient predefined operations . . . . . . . . . . 135266.6.5 Implementation of sets by lists . . . . . . . . . . . . . 1353

    66.7 Setup for Lifting/Transfer . . . . . . . . . . . . . . . . . . . . 135566.7.1 Transfer rules for the Transfer package . . . . . . . . . 1355

    67 Sum and product over lists 136067.1 List summation . . . . . . . . . . . . . . . . . . . . . . . . . . 136167.2 Further facts about List .n-lists . . . . . . . . . . . . . . . . . 136767.3 Tools setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136767.4 List product . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1368

    68 A HOL random engine 136968.1 Auxiliary functions . . . . . . . . . . . . . . . . . . . . . . . . 136968.2 Random seeds . . . . . . . . . . . . . . . . . . . . . . . . . . . 136968.3 Base selectors . . . . . . . . . . . . . . . . . . . . . . . . . . . 137068.4 ML interface . . . . . . . . . . . . . . . . . . . . . . . . . . . 1372

    69 Maps 137369.1 empty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137469.2 map-upd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137469.3 map-of . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137569.4 map-option related . . . . . . . . . . . . . . . . . . . . . . . . 137869.5 map-comp related . . . . . . . . . . . . . . . . . . . . . . . . . 137869.6 ++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137969.7 restrict-map . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138069.8 map-upds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138169.9 dom . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138369.10ran . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138569.11map-le . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138769.12Various . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1388

    70 Finite types as explicit enumerations 139070.1 Class enum . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139070.2 Implementations using enum . . . . . . . . . . . . . . . . . . 1391

    70.2.1 Unbounded operations and quantifiers . . . . . . . . . 139170.2.2 An executable choice operator . . . . . . . . . . . . . 139170.2.3 Equality and order on functions . . . . . . . . . . . . . 139270.2.4 Operations on relations . . . . . . . . . . . . . . . . . 139370.2.5 Bounded accessible part . . . . . . . . . . . . . . . . . 1393

    70.3 Default instances for enum . . . . . . . . . . . . . . . . . . . 139570.4 Small finite types . . . . . . . . . . . . . . . . . . . . . . . . . 1400

  • 20

    70.5 Closing up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1414

    71 Character and string types 141471.1 Strings as list of bytes . . . . . . . . . . . . . . . . . . . . . . 1414

    71.1.1 Bytes as datatype . . . . . . . . . . . . . . . . . . . . 141471.2 Strings as dedicated type for target language code generation 1423

    71.2.1 Logical specification . . . . . . . . . . . . . . . . . . . 142371.2.2 Syntactic representation . . . . . . . . . . . . . . . . . 142471.2.3 Operations . . . . . . . . . . . . . . . . . . . . . . . . 142571.2.4 Executable conversions . . . . . . . . . . . . . . . . . . 142771.2.5 Technical code generation setup . . . . . . . . . . . . . 142871.2.6 Code generation utility . . . . . . . . . . . . . . . . . 143171.2.7 Finally . . . . . . . . . . . . . . . . . . . . . . . . . . . 1431

    72 Reflecting Pure types into HOL 1431

    73 Predicates as enumerations 143373.1 The type of predicate enumerations (a monad) . . . . . . . . 143373.2 Emptiness check and definite choice . . . . . . . . . . . . . . 143773.3 Derived operations . . . . . . . . . . . . . . . . . . . . . . . . 144073.4 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 1442

    74 Lazy sequences 144874.1 Type of lazy sequences . . . . . . . . . . . . . . . . . . . . . . 144874.2 Code setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145274.3 Generator Sequences . . . . . . . . . . . . . . . . . . . . . . . 1453

    74.3.1 General lazy sequence operation . . . . . . . . . . . . 145374.3.2 Small lazy typeclasses . . . . . . . . . . . . . . . . . . 1453

    74.4 With Hit Bound Value . . . . . . . . . . . . . . . . . . . . . . 1454

    75 Depth-Limited Sequences with failure element 145575.1 Depth-Limited Sequence . . . . . . . . . . . . . . . . . . . . . 145575.2 Positive Depth-Limited Sequence . . . . . . . . . . . . . . . . 145775.3 Negative Depth-Limited Sequence . . . . . . . . . . . . . . . 145875.4 Negation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1459

    76 Term evaluation using the generic code generator 146076.1 Term representation . . . . . . . . . . . . . . . . . . . . . . . 1460

    76.1.1 Terms and class term-of . . . . . . . . . . . . . . . . . 146076.1.2 Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . 1461

    76.2 Tools setup and evaluation . . . . . . . . . . . . . . . . . . . 146176.3 Dedicated term-of instances . . . . . . . . . . . . . . . . . . . 146276.4 Generic reification . . . . . . . . . . . . . . . . . . . . . . . . 146376.5 Diagnostic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1463

  • 21

    77 A simple counterexample generator performing random test-ing 146377.1 Catching Match exceptions . . . . . . . . . . . . . . . . . . . 146377.2 The random class . . . . . . . . . . . . . . . . . . . . . . . . . 146377.3 Fundamental and numeric types . . . . . . . . . . . . . . . . 146377.4 Complex generators . . . . . . . . . . . . . . . . . . . . . . . 146677.5 Deriving random generators for datatypes . . . . . . . . . . . 146777.6 Code setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1467

    78 The Random-Predicate Monad 1468

    79 Various kind of sequences inside the random monad 1469

    80 A simple counterexample generator performing exhaustivetesting 147380.1 Basic operations for exhaustive generators . . . . . . . . . . . 147380.2 Exhaustive generator type classes . . . . . . . . . . . . . . . . 1473

    80.2.1 A smarter enumeration scheme for functions over fi-nite datatypes . . . . . . . . . . . . . . . . . . . . . . 1479

    80.3 Bounded universal quantifiers . . . . . . . . . . . . . . . . . . 148680.4 Fast exhaustive combinators . . . . . . . . . . . . . . . . . . . 148680.5 Continuation passing style functions as plus monad . . . . . . 148680.6 Defining generators for any first-order data type . . . . . . . 148880.7 Defining generators for abstract types . . . . . . . . . . . . . 1488

    81 A compiler for predicates defined by introduction rules 148981.1 Set membership as a generator predicate . . . . . . . . . . . . 1489

    82 Counterexample generator performing narrowing-based test-ing 149182.1 Counterexample generator . . . . . . . . . . . . . . . . . . . . 1491

    82.1.1 Code generation setup . . . . . . . . . . . . . . . . . . 149182.1.2 Narrowing’s deep representation of types and terms . 149282.1.3 From narrowing’s deep representation of terms to HOL.Code-Evaluation’s

    terms . . . . . . . . . . . . . . . . . . . . . . . . . . . 149282.1.4 Auxilary functions for Narrowing . . . . . . . . . . . . 149282.1.5 Narrowing’s basic operations . . . . . . . . . . . . . . 149382.1.6 Narrowing generator type class . . . . . . . . . . . . . 149482.1.7 class is-testable . . . . . . . . . . . . . . . . . . . . . . 149482.1.8 Defining a simple datatype to represent functions in

    an incomplete and redundant way . . . . . . . . . . . 149582.1.9 Setting up the counterexample generator . . . . . . . 1495

    82.2 Narrowing for sets . . . . . . . . . . . . . . . . . . . . . . . . 149682.3 Narrowing for integers . . . . . . . . . . . . . . . . . . . . . . 1496

  • 22

    82.4 The find-unused-assms command . . . . . . . . . . . . . . . . 149882.5 Closing up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1498

    83 Program extraction for HOL 149883.1 Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149883.2 Type of extracted program . . . . . . . . . . . . . . . . . . . 149983.3 Realizability . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150083.4 Computational content of basic inference rules . . . . . . . . 1501

    84 Extensible records with structural subtyping 150684.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150784.2 Operators and lemmas for types isomorphic to tuples . . . . . 150884.3 Logical infrastructure for records . . . . . . . . . . . . . . . . 150884.4 Concrete record syntax . . . . . . . . . . . . . . . . . . . . . . 151584.5 Record package . . . . . . . . . . . . . . . . . . . . . . . . . . 1515

    85 Greatest common divisor and least common multiple 151685.1 Abstract bounded quasi semilattices as common foundation . 151685.2 Abstract GCD and LCM . . . . . . . . . . . . . . . . . . . . . 151885.3 An aside: GCD and LCM on finite sets for incomplete gcd

    rings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153785.4 Coprimality . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154085.5 GCD and LCM for multiplicative normalisation functions . . 154985.6 GCD and LCM on nat and int . . . . . . . . . . . . . . . . . 155085.7 Bezout’s theorem . . . . . . . . . . . . . . . . . . . . . . . . . 155985.8 LCM properties on nat and int . . . . . . . . . . . . . . . . . 156485.9 The complete divisibility lattice on nat and int . . . . . . . . 1565

    85.9.1 Setwise GCD and LCM for integers . . . . . . . . . . 156885.10GCD and LCM on integer . . . . . . . . . . . . . . . . . . . . 1570

    86 Nitpick: Yet Another Counterexample Generator for Is-abelle/HOL 1572

    87 Greatest Fixpoint (Codatatype) Operation on Bounded Nat-ural Functors 157787.1 Equivalence relations, quotients, and Hilbert’s choice . . . . . 1582

    88 Filters on predicates 158388.1 Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1584

    88.1.1 Eventually . . . . . . . . . . . . . . . . . . . . . . . . 158488.2 Frequently as dual to eventually . . . . . . . . . . . . . . . . 1586

    88.2.1 Finer-than relation . . . . . . . . . . . . . . . . . . . . 158988.2.2 Map function for filters . . . . . . . . . . . . . . . . . 159588.2.3 Contravariant map function for filters . . . . . . . . . 159688.2.4 Standard filters . . . . . . . . . . . . . . . . . . . . . . 1598

  • 23

    88.2.5 Order filters . . . . . . . . . . . . . . . . . . . . . . . . 160088.3 Sequentially . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160288.4 Increasing finite subsets . . . . . . . . . . . . . . . . . . . . . 160388.5 The cofinite filter . . . . . . . . . . . . . . . . . . . . . . . . . 1604

    88.5.1 Product of filters . . . . . . . . . . . . . . . . . . . . . 160588.6 Limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161088.7 Limits to at-top and at-bot . . . . . . . . . . . . . . . . . . . 161388.8 Setup ′a filter for lifting and transfer . . . . . . . . . . . . . . 1616

    89 Conditionally-complete Lattices 1627

    90 Factorial Function, Rising Factorials 164390.1 Factorial Function . . . . . . . . . . . . . . . . . . . . . . . . 164390.2 Pochhammer’s symbol: generalized rising factorial . . . . . . 164790.3 Misc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1652

    91 Binomial Coefficients and Binomial Theorem 165291.1 Binomial coefficients . . . . . . . . . . . . . . . . . . . . . . . 165391.2 The binomial theorem (courtesy of Tobias Nipkow): . . . . . 165691.3 Generalized binomial coefficients . . . . . . . . . . . . . . . . 1659

    91.3.1 Summation on the upper index . . . . . . . . . . . . . 167091.4 More on Binomial Coefficients . . . . . . . . . . . . . . . . . . 167691.5 Executable code . . . . . . . . . . . . . . . . . . . . . . . . . 1681

    92 Main HOL 1682

    93 Archimedean Fields, Floor and Ceiling Functions 168393.1 Class of Archimedean fields . . . . . . . . . . . . . . . . . . . 168593.2 Existence and uniqueness of floor function . . . . . . . . . . . 168693.3 Floor function . . . . . . . . . . . . . . . . . . . . . . . . . . . 168793.4 Ceiling function . . . . . . . . . . . . . . . . . . . . . . . . . . 1693

    93.4.1 Ceiling with numerals. . . . . . . . . . . . . . . . . . . 169493.4.2 Addition and subtraction of integers. . . . . . . . . . . 1695

    93.5 Negation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169793.6 Natural numbers . . . . . . . . . . . . . . . . . . . . . . . . . 169793.7 Frac Function . . . . . . . . . . . . . . . . . . . . . . . . . . . 169793.8 Rounding to the nearest integer . . . . . . . . . . . . . . . . . 1699

    94 Rational numbers 170094.1 Rational numbers as quotient . . . . . . . . . . . . . . . . . . 1701

    94.1.1 Construction of the type of rational numbers . . . . . 170194.1.2 Representation and basic operations . . . . . . . . . . 170194.1.3 Function normalize . . . . . . . . . . . . . . . . . . . . 170694.1.4 Various . . . . . . . . . . . . . . . . . . . . . . . . . . 170994.1.5 The ordered field of rational numbers . . . . . . . . . 1709

  • 24

    94.1.6 Rationals are an Archimedean field . . . . . . . . . . . 171394.2 Linear arithmetic setup . . . . . . . . . . . . . . . . . . . . . 171494.3 Embedding from Rationals to other Fields . . . . . . . . . . . 171494.4 The Set of Rational Numbers . . . . . . . . . . . . . . . . . . 171794.5 Implementation of rational numbers as pairs of integers . . . 171994.6 Setup for Nitpick . . . . . . . . . . . . . . . . . . . . . . . . . 172394.7 Float syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172494.8 Hiding implementation details . . . . . . . . . . . . . . . . . . 1724

    95 Development of the Reals using Cauchy Sequences 172595.1 Preliminary lemmas . . . . . . . . . . . . . . . . . . . . . . . 172595.2 Sequences that converge to zero . . . . . . . . . . . . . . . . . 172695.3 Cauchy sequences . . . . . . . . . . . . . . . . . . . . . . . . . 172795.4 Equivalence relation on Cauchy sequences . . . . . . . . . . . 173295.5 The field of real numbers . . . . . . . . . . . . . . . . . . . . 173295.6 Positive reals . . . . . . . . . . . . . . . . . . . . . . . . . . . 173595.7 Completeness . . . . . . . . . . . . . . . . . . . . . . . . . . . 173895.8 Supremum of a set of reals . . . . . . . . . . . . . . . . . . . . 174395.9 Hiding implementation details . . . . . . . . . . . . . . . . . . 174495.10More Lemmas . . . . . . . . . . . . . . . . . . . . . . . . . . . 174495.11Embedding numbers into the Reals . . . . . . . . . . . . . . . 174495.12Embedding the Naturals into the Reals . . . . . . . . . . . . 174695.13The Archimedean Property of the Reals . . . . . . . . . . . . 174795.14Rationals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174795.15Density of the Rational Reals in the Reals . . . . . . . . . . . 175095.16Numerals and Arithmetic . . . . . . . . . . . . . . . . . . . . 175095.17Simprules combining x + y and 0 . . . . . . . . . . . . . . . 175095.18Lemmas about powers . . . . . . . . . . . . . . . . . . . . . . 175195.19Density of the Reals . . . . . . . . . . . . . . . . . . . . . . . 175195.20Archimedean properties and useful consequences . . . . . . . 175195.21Floor and Ceiling Functions from the Reals to the Integers . 175395.22Exponentiation with floor . . . . . . . . . . . . . . . . . . . . 175695.23Implementation of rational real numbers . . . . . . . . . . . . 175795.24Setup for Nitpick . . . . . . . . . . . . . . . . . . . . . . . . . 175995.25Setup for SMT . . . . . . . . . . . . . . . . . . . . . . . . . . 176095.26Setup for Argo . . . . . . . . . . . . . . . . . . . . . . . . . . 1760

    96 Topological Spaces 176096.1 Topological space . . . . . . . . . . . . . . . . . . . . . . . . . 176096.2 Hausdorff and other separation properties . . . . . . . . . . . 176396.3 Generators for toplogies . . . . . . . . . . . . . . . . . . . . . 176596.4 Order topologies . . . . . . . . . . . . . . . . . . . . . . . . . 176596.5 Setup some topologies . . . . . . . . . . . . . . . . . . . . . . 1768

    96.5.1 Boolean is an order topology . . . . . . . . . . . . . . 1768

  • 25

    96.5.2 Topological filters . . . . . . . . . . . . . . . . . . . . 177096.5.3 Tendsto . . . . . . . . . . . . . . . . . . . . . . . . . . 177596.5.4 Rules about Lim . . . . . . . . . . . . . . . . . . . . . 1782

    96.6 Limits on sequences . . . . . . . . . . . . . . . . . . . . . . . 178496.7 Monotone sequences and subsequences . . . . . . . . . . . . . 1784

    96.7.1 Definition of subsequence. . . . . . . . . . . . . . . . . 178596.7.2 Subsequence (alternative definition, (e.g. Hoskins) . . 178696.7.3 Increasing and Decreasing Series . . . . . . . . . . . . 1792

    96.8 First countable topologies . . . . . . . . . . . . . . . . . . . . 179296.9 Function limit at a point . . . . . . . . . . . . . . . . . . . . . 1796

    96.9.1 Relation of LIM and LIMSEQ . . . . . . . . . . . . . 179896.10Continuity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1801

    96.10.1 Continuity on a set . . . . . . . . . . . . . . . . . . . . 180196.10.2 Continuity at a point . . . . . . . . . . . . . . . . . . 180696.10.3 Open-cover compactness . . . . . . . . . . . . . . . . . 1810

    96.11Finite intersection property . . . . . . . . . . . . . . . . . . . 181296.12Connectedness . . . . . . . . . . . . . . . . . . . . . . . . . . 1816

    97 Linear Continuum Topologies 182197.1 Intermediate Value Theorem . . . . . . . . . . . . . . . . . . 182497.2 Uniform spaces . . . . . . . . . . . . . . . . . . . . . . . . . . 1829

    97.2.1 Totally bounded sets . . . . . . . . . . . . . . . . . . . 183097.2.2 Cauchy filter . . . . . . . . . . . . . . . . . . . . . . . 183197.2.3 Uniformly continuous functions . . . . . . . . . . . . . 1833

    98 Product Topology 183498.1 Product is a topological space . . . . . . . . . . . . . . . . . . 1834

    98.1.1 Continuity of operations . . . . . . . . . . . . . . . . . 183698.1.2 Connectedness of products . . . . . . . . . . . . . . . 183898.1.3 Separation axioms . . . . . . . . . . . . . . . . . . . . 1839

    98.2 A generic notion of the convex, affine, conic hull, or closed”hull”. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1841

    99 Modules 184399.1 Locale for additive functions . . . . . . . . . . . . . . . . . . . 1843

    100Subspace 1845

    101Span: subspace generated by a set 1846

    102Dependent and independent sets 1850

    103Representation of a vector on a specific basis 1853

    104Vector Spaces 1863

  • 26

    105Vector Spaces and Algebras over the Reals 1899105.1Real vector spaces . . . . . . . . . . . . . . . . . . . . . . . . 1899105.2Embedding of the Reals into any real-algebra-1 : of-real . . . 1904105.3The Set of Real Numbers . . . . . . . . . . . . . . . . . . . . 1906105.4Ordered real vector spaces . . . . . . . . . . . . . . . . . . . . 1908105.5Real normed vector spaces . . . . . . . . . . . . . . . . . . . . 1913105.6Metric spaces . . . . . . . . . . . . . . . . . . . . . . . . . . . 1921105.7Class instances for real numbers . . . . . . . . . . . . . . . . 1925105.8Extra type constraints . . . . . . . . . . . . . . . . . . . . . . 1926105.9Sign function . . . . . . . . . . . . . . . . . . . . . . . . . . . 1927105.10Bounded Linear and Bilinear Operators . . . . . . . . . . . . 1928105.11Filters and Limits on Metric Space . . . . . . . . . . . . . . . 1935

    105.11.1Limits of Sequences . . . . . . . . . . . . . . . . . . . 1937105.11.2Limits of Functions . . . . . . . . . . . . . . . . . . . . 1938

    105.12Complete metric spaces . . . . . . . . . . . . . . . . . . . . . 1939105.13Cauchy sequences . . . . . . . . . . . . . . . . . . . . . . . . . 1939

    105.13.1Cauchy Sequences are Convergent . . . . . . . . . . . 1944105.14The set of real numbers is a complete metric space . . . . . . 1945

    106Limits on Real Vector Spaces 1948106.1Filter going to infinity norm . . . . . . . . . . . . . . . . . . . 1948

    106.1.1 Boundedness . . . . . . . . . . . . . . . . . . . . . . . 1949106.1.2 Bounded Sequences . . . . . . . . . . . . . . . . . . . 1950106.1.3 A Few More Equivalence Theorems for Boundedness . 1952106.1.4 Upper Bounds and Lubs of Bounded Sequences . . . . 1953106.1.5 Polynomal function extremal theorem, from HOL Light1955

    106.2Convergence to Zero . . . . . . . . . . . . . . . . . . . . . . . 1957106.2.1 Distance and norms . . . . . . . . . . . . . . . . . . . 1960

    106.3Topological Monoid . . . . . . . . . . . . . . . . . . . . . . . . 1962106.3.1 Topological group . . . . . . . . . . . . . . . . . . . . 1963106.3.2 Linear operators and multiplication . . . . . . . . . . 1965106.3.3 Inverse and division . . . . . . . . . . . . . . . . . . . 1971

    106.4Relate at, at-left and at-right . . . . . . . . . . . . . . . . . . 1978106.5Floor and Ceiling . . . . . . . . . . . . . . . . . . . . . . . . . 1990106.6Limits of Sequences . . . . . . . . . . . . . . . . . . . . . . . . 1991106.7Convergence on sequences . . . . . . . . . . . . . . . . . . . . 1995106.8Power Sequences . . . . . . . . . . . . . . . . . . . . . . . . . 2000106.9Limits of Functions . . . . . . . . . . . . . . . . . . . . . . . . 2001106.10Continuity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2003106.11Uniform Continuity . . . . . . . . . . . . . . . . . . . . . . . . 2005106.12Nested Intervals and Bisection – Needed for Compactness . . 2006106.13Boundedness of continuous functions . . . . . . . . . . . . . . 2009

  • 27

    107Infinite Series 2013107.1Definition of infinite summability . . . . . . . . . . . . . . . . 2013107.2Infinite summability on topological monoids . . . . . . . . . . 2014107.3Infinite summability on ordered, topological monoids . . . . . 2017107.4Infinite summability on topological monoids . . . . . . . . . . 2019107.5Infinite summability on real normed vector spaces . . . . . . 2020107.6Infinite summability on real normed algebras . . . . . . . . . 2024107.7Infinite summability on real normed fields . . . . . . . . . . . 2024107.8Telescoping . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2026107.9Infinite summability on Banach spaces . . . . . . . . . . . . . 2027107.10The Ratio Test . . . . . . . . . . . . . . . . . . . . . . . . . . 2029107.11Cauchy Product Formula . . . . . . . . . . . . . . . . . . . . 2031107.12Series on reals . . . . . . . . . . . . . . . . . . . . . . . . . . . 2033

    108Differentiation 2040108.1Frechet derivative . . . . . . . . . . . . . . . . . . . . . . . . . 2040

    108.1.1 Limit transformation for derivatives . . . . . . . . . . 2045108.2Continuity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2046108.3Composition . . . . . . . . . . . . . . . . . . . . . . . . . . . 2047108.4Uniqueness . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2052108.5Differentiability predicate . . . . . . . . . . . . . . . . . . . . 2053108.6Vector derivative . . . . . . . . . . . . . . . . . . . . . . . . . 2056108.7Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2059108.8Local extrema . . . . . . . . . . . . . . . . . . . . . . . . . . . 2065108.9Rolle’s Theorem . . . . . . . . . . . . . . . . . . . . . . . . . 2068108.10Mean Value Theorem . . . . . . . . . . . . . . . . . . . . . . . 2071

    108.10.1A function is constant if its derivative is 0 over aninterval. . . . . . . . . . . . . . . . . . . . . . . . . . . 2073

    108.10.2A function with positive derivative is increasing . . . . 2075108.11Generalized Mean Value Theorem . . . . . . . . . . . . . . . 2079108.12L’Hopitals rule . . . . . . . . . . . . . . . . . . . . . . . . . . 2081

    109Nth Roots of Real Numbers 2089109.1Existence of Nth Root . . . . . . . . . . . . . . . . . . . . . . 2089109.2Nth Root . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2090109.3Square Root . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2097109.4Square Root of Sum of Squares . . . . . . . . . . . . . . . . . 2101

    110Power Series, Transcendental Functions etc. 2106110.1More facts about binomial coefficients . . . . . . . . . . . . . 2107110.2Properties of Power Series . . . . . . . . . . . . . . . . . . . . 2110110.3Alternating series test / Leibniz formula . . . . . . . . . . . . 2114110.4Term-by-Term Differentiability of Power Series . . . . . . . . 2118

  • 28

    110.5The Derivative of a Power Series Has the Same Radius ofConvergence . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2123

    110.6Derivability of power series . . . . . . . . . . . . . . . . . . . 2127110.7Exponential Function . . . . . . . . . . . . . . . . . . . . . . 2133

    110.7.1 Properties of the Exponential Function . . . . . . . . 2135110.7.2 Properties of the Exponential Function on Reals . . . 2138

    110.8Natural Logarithm . . . . . . . . . . . . . . . . . . . . . . . . 2141110.8.1 A couple of simple bounds . . . . . . . . . . . . . . . . 2155

    110.9The general logarithm . . . . . . . . . . . . . . . . . . . . . . 2156110.10Sine and Cosine . . . . . . . . . . . . . . . . . . . . . . . . . . 2172110.11Properties of Sine and Cosine . . . . . . . . . . . . . . . . . . 2176110.12Deriving the Addition Formulas . . . . . . . . . . . . . . . . . 2177110.13The Constant Pi . . . . . . . . . . . . . . . . . . . . . . . . . 2182110.14More Corollaries about Sine and Cosine . . . . . . . . . . . . 2196110.15Tangent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2200110.16Cotangent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2208110.17Inverse Trigonometric Functions . . . . . . . . . . . . . . . . 2209110.18Prove Totality of the Trigonometric Functions . . . . . . . . . 2217110.19Machin’s formula . . . . . . . . . . . . . . . . . . . . . . . . . 2221110.20Introducing the inverse tangent power series . . . . . . . . . . 2223110.21Existence of Polar Coordinates . . . . . . . . . . . . . . . . . 2233110.22Basics about polynomial functions: products, extremal be-

    haviour and root counts . . . . . . . . . . . . . . . . . . . . . 2234110.23Hyperbolic functions . . . . . . . . . . . . . . . . . . . . . . . 2240

    110.23.1More specific properties of the real functions . . . . . 2245110.23.2Limits . . . . . . . . . . . . . . . . . . . . . . . . . . . 2250110.23.3Properties of the inverse hyperbolic functions . . . . . 2251

    110.24Simprocs for root and power literals . . . . . . . . . . . . . . 2257

    111Complex Numbers: Rectangular and Polar Representations2261111.1Addition and Subtraction . . . . . . . . . . . . . . . . . . . . 2262111.2Multiplication and Division . . . . . . . . . . . . . . . . . . . 2262111.3Scalar Multiplication . . . . . . . . . . . . . . . . . . . . . . . 2263111.4Numerals, Arithmetic, and Embedding from R . . . . . . . . 2264111.5The Complex Number i . . . . . . . . . . . . . . . . . . . . . 2266111.6Vector Norm . . . . . . . . . . . . . . . . . . . . . . . . . . . 2267111.7Absolute value . . . . . . . . . . . . . . . . . . . . . . . . . . 2270111.8Completeness of the Complexes . . . . . . . . . . . . . . . . . 2270111.9Complex Conjugation . . . . . . . . . . . . . . . . . . . . . . 2272111.10Basic Lemmas . . . . . . . . . . . . . . . . . . . . . . . . . . . 2275111.11Polar Form for Complex Numbers . . . . . . . . . . . . . . . 2277

    111.11.1cos θ + i sin θ . . . . . . . . . . . . . . . . . . . . . . . 2277111.11.2r(cos θ + i sin θ) . . . . . . . . . . . . . . . . . . . . . . 2279111.11.3Complex exponential . . . . . . . . . . . . . . . . . . . 2279

  • 29

    111.11.4Complex argument . . . . . . . . . . . . . . . . . . . . 2281111.12Complex n-th roots . . . . . . . . . . . . . . . . . . . . . . . . 2282111.13Square root of complex numbers . . . . . . . . . . . . . . . . 2286

    112MacLaurin and Taylor Series 2288112.1Maclaurin’s Theorem with Lagrange Form of Remainder . . . 2289112.2More Convenient ”Bidirectional” Version. . . . . . . . . . . . 2293112.3Version for Exponential Function . . . . . . . . . . . . . . . . 2295112.4Version for Sine Function . . . . . . . . . . . . . . . . . . . . 2296112.5Maclaurin Expansion for Cosine Function . . . . . . . . . . . 2297

    113Taylor series 2300

    114Comprehensive Complex Theory 2303

  • 30

    ATP

    Archimedean_Field

    Argo

    BNF_Cardinal_Arithmetic

    BNF_Cardinal_Order_Relation

    BNF_Composition

    BNF_Def

    BNF_Fixpoint_Base

    BNF_Greatest_Fixpoint

    BNF_Least_Fixpoint

    BNF_Wellorder_Constructions

    BNF_Wellorder_Embedding

    BNF_Wellorder_Relation

    Basic_BNF_LFPs

    Basic_BNFs

    Binomial

    Code_Evaluation

    Code_Numeral

    Complete_Lattices

    Complete_Partial_Order

    Complex

    Complex_Main

    Conditionally_Complete_Lattices

    Ctr_Sugar

    Deriv

    Divides

    Enum

    Equiv_Relations

    Euclidean_Division

    Extraction

    Factorial

    Fields

    Filter

    Finite_Set

    Fun

    Fun_Def

    Fun_Def_Base

    GCD

    Groebner_Basis

    Groups

    Groups_Big

    Groups_List

    HOL

    Hilbert_Choice

    Hull

    Inductive

    Inequalities

    Int

    Lattices

    Lattices_Big

    Lazy_Sequence

    Lifting

    Lifting_Set

    Limited_Sequence

    Limits

    List

    MacLaurin

    Main

    Map

    Meson

    Metis

    Modules

    Nat

    Nitpick

    NthRoot

    Num

    Numeral_Simprocs

    Nunchaku

    Option

    Order_Relation

    Orderings

    Parity

    Partial_Function

    Power

    Predicate

    Predicate_Compile

    Presburger

    Product_Type

    Quickcheck_Exhaustive Quickcheck_Narrowing

    Quickcheck_Random

    Quotient

    Random

    Random_Pred

    Random_Sequence

    Rat

    Real

    Real_Vector_Spaces

    Record

    Relation

    Rings

    SAT

    SMT

    Semiring_Normalization

    Series

    Set

    Set_Interval

    Sledgehammer

    String

    Sum_Type

    Topological_Spaces

    Transcendental

    Transfer

    Transitive_Closure

    Typedef

    Typerep

    Vector_Spaces

    Wellfounded

    Wfrec

    Zorn

    [Pure]

    [Tools]

  • THEORY “HOL” 31

    1 The basis of Higher-Order Logic

    theory HOLimports Pure Tools.Code-Generatorkeywords

    try solve-direct quickcheck print-coercions print-clasetprint-induct-rules :: diag and

    quickcheck-params :: thy-declbegin

    ML-file 〈∼∼/src/Tools/misc-legacy .ML〉

    ML-file 〈∼∼/src/Tools/try .ML〉

    ML-file 〈∼∼/src/Tools/quickcheck .ML〉

    ML-file 〈∼∼/src/Tools/solve-direct .ML〉

    ML-file 〈∼∼/src/Tools/IsaPlanner/zipper .ML〉

    ML-file 〈∼∼/src/Tools/IsaPlanner/isand .ML〉

    ML-file 〈∼∼/src/Tools/IsaPlanner/rw-inst .ML〉

    ML-file 〈∼∼/src/Provers/hypsubst .ML〉

    ML-file 〈∼∼/src/Provers/splitter .ML〉

    ML-file 〈∼∼/src/Provers/classical .ML〉

    ML-file 〈∼∼/src/Provers/blast .ML〉

    ML-file 〈∼∼/src/Provers/clasimp.ML〉

    ML-file 〈∼∼/src/Tools/eqsubst .ML〉

    ML-file 〈∼∼/src/Provers/quantifier1 .ML〉

    ML-file 〈∼∼/src/Tools/atomize-elim.ML〉

    ML-file 〈∼∼/src/Tools/cong-tac.ML〉

    ML-file 〈∼∼/src/Tools/intuitionistic.ML〉 setup 〈Intuitionistic.method-setup bind-ing 〈iprover 〉〉

    ML-file 〈∼∼/src/Tools/project-rule.ML〉

    ML-file 〈∼∼/src/Tools/subtyping .ML〉

    ML-file 〈∼∼/src/Tools/case-product .ML〉

    ML 〈Plugin-Name.declare-setup binding 〈extraction〉〉

    ML 〈

    Plugin-Name.declare-setup binding 〈quickcheck-random〉;Plugin-Name.declare-setup binding 〈quickcheck-exhaustive〉;Plugin-Name.declare-setup binding 〈quickcheck-bounded-forall 〉;Plugin-Name.declare-setup binding 〈quickcheck-full-exhaustive〉;Plugin-Name.declare-setup binding 〈quickcheck-narrowing〉;

    ML 〈

    Plugin-Name.define-setup binding 〈quickcheck 〉

    [plugin 〈quickcheck-exhaustive〉,plugin 〈quickcheck-random〉,plugin 〈quickcheck-bounded-forall 〉,plugin 〈quickcheck-full-exhaustive〉,plugin 〈quickcheck-narrowing〉]

  • THEORY “HOL” 32

    1.1 Primitive logic

    The definition of the logic is based on Mike Gordon’s technical report [2]that describes the first implementation of HOL. However, there are a numberof differences. In particular, we start with the definite description operatorand introduce Hilbert’s ε operator only much later. Moreover, axiom (P−→ Q) −→ (Q −→ P) −→ (P = Q) is derived from the other axioms.The fact that this axiom is derivable was first noticed by Bruno Barras (forMike Gordon’s line of HOL systems) and later independently by AlexanderMaletzky (for Isabelle/HOL).

    1.1.1 Core syntax

    setup 〈Axclass.class-axiomatization (binding 〈type〉, [])〉

    default-sort typesetup 〈Object-Logic.add-base-sort sort 〈type〉〉

    setup 〈Proofterm.set-preproc (Proof-Rewrite-Rules.standard-preproc [])〉

    axiomatization where fun-arity : OFCLASS ( ′a ⇒ ′b, type-class)instance fun :: (type, type) type by (rule fun-arity)

    axiomatization where itself-arity : OFCLASS ( ′a itself , type-class)instance itself :: (type) type by (rule itself-arity)

    typedecl bool

    judgment Trueprop :: bool ⇒ prop ((-) 5 )

    axiomatization implies :: [bool , bool ] ⇒ bool (infixr −→ 25 )and eq :: [ ′a, ′a] ⇒ booland The :: ( ′a ⇒ bool) ⇒ ′a

    notation (input)eq (infixl = 50 )

    notation (output)eq (infix = 50 )

    The input syntax for eq is more permissive than the output syntax becauseof the large amount of material that relies on infixl.

    1.1.2 Defined connectives and quantifiers

    definition True :: boolwhere True ≡ ((λx ::bool . x ) = (λx . x ))

  • THEORY “HOL” 33

    definition All :: ( ′a ⇒ bool) ⇒ bool (binder ∀ 10 )where All P ≡ (P = (λx . True))

    definition Ex :: ( ′a ⇒ bool) ⇒ bool (binder ∃ 10 )where Ex P ≡ ∀Q . (∀ x . P x −→ Q) −→ Q

    definition False :: boolwhere False ≡ (∀P . P)

    definition Not :: bool ⇒ bool (¬ - [40 ] 40 )where not-def : ¬ P ≡ P −→ False

    definition conj :: [bool , bool ] ⇒ bool (infixr ∧ 35 )where and-def : P ∧ Q ≡ ∀R. (P −→ Q −→ R) −→ R

    definition disj :: [bool , bool ] ⇒ bool (infixr ∨ 30 )where or-def : P ∨ Q ≡ ∀R. (P −→ R) −→ (Q −→ R) −→ R

    definition Ex1 :: ( ′a ⇒ bool) ⇒ boolwhere Ex1 P ≡ ∃ x . P x ∧ (∀ y . P y −→ y = x )

    1.1.3 Additional concrete syntax

    syntax (ASCII )-Ex1 :: pttrn ⇒ bool ⇒ bool ((3EX ! -./ -) [0 , 10 ] 10 )

    syntax (input)-Ex1 :: pttrn ⇒ bool ⇒ bool ((3? ! -./ -) [0 , 10 ] 10 )

    syntax -Ex1 :: pttrn ⇒ bool ⇒ bool ((3∃ !-./ -) [0 , 10 ] 10 )translations ∃ !x . P CONST Ex1 (λx . P)

    print-translation 〈

    [Syntax-Trans.preserve-binder-abs-tr ′ const-syntax 〈Ex1 〉 syntax-const 〈-Ex1 〉]〉 — to avoid eta-contraction of body

    syntax-Not-Ex :: idts ⇒ bool ⇒ bool ((3@ -./ -) [0 , 10 ] 10 )-Not-Ex1 :: pttrn ⇒ bool ⇒ bool ((3@ !-./ -) [0 , 10 ] 10 )

    translations@ x . P ¬ (∃ x . P)@ !x . P ¬ (∃ !x . P)

    abbreviation not-equal :: [ ′a, ′a] ⇒ bool (infix 6= 50 )where x 6= y ≡ ¬ (x = y)

    notation (ASCII )Not (∼ - [40 ] 40 ) andconj (infixr & 35 ) and

  • THEORY “HOL” 34

    disj (infixr | 30 ) andimplies (infixr −−> 25 ) andnot-equal (infix ∼= 50 )

    abbreviation (iff )iff :: [bool , bool ] ⇒ bool (infixr ←→ 25 )where A ←→ B ≡ A = B

    syntax -The :: [pttrn, bool ] ⇒ ′a ((3THE -./ -) [0 , 10 ] 10 )translations THE x . P CONST The (λx . P)print-translation 〈

    [(const-syntax 〈The〉, fn - => fn [Abs abs] =>let val (x , t) = Syntax-Trans.atomic-abs-tr ′ absin Syntax .const syntax-const 〈-The〉 $ x $ t end)]

    〉 — To avoid eta-contraction of body

    nonterminal letbinds and letbindsyntax

    -bind :: [pttrn, ′a] ⇒ letbind ((2- =/ -) 10 ):: letbind ⇒ letbinds (-)

    -binds :: [letbind , letbinds] ⇒ letbinds (-;/ -)-Let :: [letbinds, ′a] ⇒ ′a ((let (-)/ in (-)) [0 , 10 ] 10 )

    nonterminal case-syn and cases-synsyntax

    -case-syntax :: [ ′a, cases-syn] ⇒ ′b ((case - of / -) 10 )-case1 :: [ ′a, ′b] ⇒ case-syn ((2- ⇒/ -) 10 ):: case-syn ⇒ cases-syn (-)

    -case2 :: [case-syn, cases-syn] ⇒ cases-syn (-/ | -)syntax (ASCII )

    -case1 :: [ ′a, ′b] ⇒ case-syn ((2- =>/ -) 10 )

    notation (ASCII )All (binder ALL 10 ) andEx (binder EX 10 )

    notation (input)All (binder ! 10 ) andEx (binder ? 10 )

    1.1.4 Axioms and basic definitions

    axiomatization whererefl : t = (t :: ′a) andsubst : s = t =⇒ P s =⇒ P t andext : (

    ∧x :: ′a. (f x :: ′b) = g x ) =⇒ (λx . f x ) = (λx . g x )

    — Extensionality is built into the meta-logic, and this rule expresses a relatedproperty. It is an eta-expanded version of the traditional rule, and similar to theABS rule of HOL and

  • THEORY “HOL” 35

    the-eq-trivial : (THE x . x = a) = (a:: ′a)

    axiomatization whereimpI : (P =⇒ Q) =⇒ P −→ Q andmp: [[P −→ Q ; P ]] =⇒ Q and

    True-or-False: (P = True) ∨ (P = False)

    definition If :: bool ⇒ ′a ⇒ ′a ⇒ ′a ((if (-)/ then (-)/ else (-)) [0 , 0 , 10 ] 10 )where If P x y ≡ (THE z :: ′a. (P = True −→ z = x ) ∧ (P = False −→ z = y))

    definition Let :: ′a ⇒ ( ′a ⇒ ′b) ⇒ ′bwhere Let s f ≡ f s

    translations-Let (-binds b bs) e -Let b (-Let bs e)let x = a in e CONST Let a (λx . e)

    axiomatization undefined :: ′a

    class default = fixes default :: ′a

    1.2 Fundamental rules

    1.2.1 Equality

    lemma sym: s = t =⇒ t = sby (erule subst) (rule refl)

    lemma ssubst : t = s =⇒ P s =⇒ P tby (drule sym) (erule subst)

    lemma trans: [[r = s; s = t ]] =⇒ r = tby (erule subst)

    lemma trans-sym [Pure.elim? ]: r = s =⇒ t = s =⇒ r = tby (rule trans [OF - sym])

    lemma meta-eq-to-obj-eq :assumes A ≡ Bshows A = Bunfolding assms by (rule refl)

    Useful with erule for proving equalities from known equalities.

    lemma box-equals: [[a = b; a = c; b = d ]] =⇒ c = dapply (rule trans)apply (rule trans)apply (rule sym)apply assumption+

  • THEORY “HOL” 36

    done

    For calculational reasoning:

    lemma forw-subst : a = b =⇒ P b =⇒ P aby (rule ssubst)

    lemma back-subst : P a =⇒ a = b =⇒ P bby (rule subst)

    1.2.2 Congruence rules for application

    Similar to AP-THM in Gordon’s HOL.

    lemma fun-cong : (f :: ′a ⇒ ′b) = g =⇒ f x = g xapply (erule subst)apply (rule refl)done

    Similar to AP-TERM in Gordon’s HOL and FOL’s subst-context.

    lemma arg-cong : x = y =⇒ f x = f yapply (erule subst)apply (rule refl)done

    lemma arg-cong2 : [[a = b; c = d ]] =⇒ f a c = f b dapply (erule ssubst)+apply (rule refl)done

    lemma cong : [[f = g ; (x :: ′a) = y ]] =⇒ f x = g yapply (erule subst)+apply (rule refl)done

    ML 〈fun cong-tac ctxt = Cong-Tac.cong-tac ctxt @{thm cong}〉

    1.2.3 Equality of booleans – iff

    lemma iffD2 : [[P = Q ; Q ]] =⇒ Pby (erule ssubst)

    lemma rev-iffD2 : [[Q ; P = Q ]] =⇒ Pby (erule iffD2 )

    lemma iffD1 : Q = P =⇒ Q =⇒ Pby (drule sym) (rule iffD2 )

    lemma rev-iffD1 : Q =⇒ Q = P =⇒ Pby (drule sym) (rule rev-iffD2 )

  • THEORY “HOL” 37

    lemma iffE :assumes major : P = Q

    and minor : [[P −→ Q ; Q −→ P ]] =⇒ Rshows Rby (iprover intro: minor impI major [THEN iffD2 ] major [THEN iffD1 ])

    1.2.4 True (1)

    lemma TrueI : Trueunfolding True-def by (rule refl)

    lemma eqTrueE : P = True =⇒ Pby (erule iffD2 ) (rule TrueI )

    1.2.5 Universal quantifier (1)

    lemma spec: ∀ x :: ′a. P x =⇒ P xapply (unfold All-def )apply (rule eqTrueE )apply (erule fun-cong)done

    lemma allE :assumes major : ∀ x . P x

    and minor : P x =⇒ Rshows Rby (iprover intro: minor major [THEN spec])

    lemma all-dupE :assumes major : ∀ x . P x

    and minor : [[P x ; ∀ x . P x ]] =⇒ Rshows Rby (iprover intro: minor major major [THEN spec])

    1.2.6 False

    Depends upon spec; it is impossible to do propositional logic before quanti-fiers!

    lemma FalseE : False =⇒ Papply (unfold False-def )apply (erule spec)done

    lemma False-neq-True: False = True =⇒ Pby (erule eqTrueE [THEN FalseE ])

  • THEORY “HOL” 38

    1.2.7 Negation

    lemma notI :assumes P =⇒ Falseshows ¬ Papply (unfold not-def )apply (iprover intro: impI assms)done

    lemma False-not-True: False 6= Trueapply (rule notI )apply (erule False-neq-True)done

    lemma True-not-False: True 6= Falseapply (rule notI )apply (drule sym)apply (erule False-neq-True)done

    lemma notE : [[¬ P ; P ]] =⇒ Rapply (unfold not-def )apply (erule mp [THEN FalseE ])apply assumptiondone

    lemma notI2 : (P =⇒ ¬ Pa) =⇒ (P =⇒ Pa) =⇒ ¬ Pby (erule notE [THEN notI ]) (erule meta-mp)

    1.2.8 Implication

    lemma impE :assumes P −→ Q P Q =⇒ Rshows Rby (iprover intro: assms mp)

    R