Archive of Formal Proofs https://www.isa-afp.org The Archive of Formal Proofs is a collection of proof libraries, examples, and larger scientific developments, mechanically checked in the theorem prover Isabelle. 21 Jun 2017 00:00:00 +0000 Propositional Proof Systems https://www.isa-afp.org/entries/Propositional_Proof_Systems.shtml https://www.isa-afp.org/entries/Propositional_Proof_Systems.shtml Julius Michaelis, Tobias Nipkow 21 Jun 2017 00:00:00 +0000 We formalize a range of proof systems for classical propositional logic (sequent calculus, natural deduction, Hilbert systems, resolution) and prove the most important meta-theoretic results about semantics and proofs: compactness, soundness, completeness, translations between proof systems, cut-elimination, interpolation and model existence. Partial Semigroups and Convolution Algebras https://www.isa-afp.org/entries/PSemigroupsConvolution.shtml https://www.isa-afp.org/entries/PSemigroupsConvolution.shtml Brijesh Dongol, Victor B. F. Gomes, Ian J. Hayes, Georg Struth 13 Jun 2017 00:00:00 +0000 Partial Semigroups are relevant to the foundations of quantum mechanics and combinatorics as well as to interval and separation logics. Convolution algebras can be understood either as algebras of generalised binary modalities over ternary Kripke frames, in particular over partial semigroups, or as algebras of quantale-valued functions which are equipped with a convolution-style operation of multiplication that is parametrised by a ternary relation. Convolution algebras provide algebraic semantics for various substructural logics, including categorial, relevance and linear logics, for separation logic and for interval logics; they cover quantitative and qualitative applications. These mathematical components for partial semigroups and convolution algebras provide uniform foundations from which models of computation based on relations, program traces or pomsets, and verification components for separation or interval temporal logics can be built with little effort. Buffon's Needle Problem https://www.isa-afp.org/entries/Buffons_Needle.shtml https://www.isa-afp.org/entries/Buffons_Needle.shtml Manuel Eberl 06 Jun 2017 00:00:00 +0000 In the 18th century, Georges-Louis Leclerc, Comte de Buffon posed and later solved the following problem, which is often called the first problem ever solved in geometric probability: Given a floor divided into vertical strips of the same width, what is the probability that a needle thrown onto the floor randomly will cross two strips? This entry formally defines the problem in the case where the needle's position is chosen uniformly at random in a single strip around the origin (which is equivalent to larger arrangements due to symmetry). It then provides proofs of the simple solution in the case where the needle's length is no greater than the width of the strips and the more complicated solution in the opposite case. Formalizing Push-Relabel Algorithms https://www.isa-afp.org/entries/Prpu_Maxflow.shtml https://www.isa-afp.org/entries/Prpu_Maxflow.shtml Peter Lammich, S. Reza Sefidgar 01 Jun 2017 00:00:00 +0000 We present a formalization of push-relabel algorithms for computing the maximum flow in a network. We start with Goldberg's et al.~generic push-relabel algorithm, for which we show correctness and the time complexity bound of O(V^2E). We then derive the relabel-to-front and FIFO implementation. Using stepwise refinement techniques, we derive an efficient verified implementation. Our formal proof of the abstract algorithms closely follows a standard textbook proof. It is accessible even without being an expert in Isabelle/HOL, the interactive theorem prover used for the formalization. Flow Networks and the Min-Cut-Max-Flow Theorem https://www.isa-afp.org/entries/Flow_Networks.shtml https://www.isa-afp.org/entries/Flow_Networks.shtml Peter Lammich, S. Reza Sefidgar 01 Jun 2017 00:00:00 +0000 We present a formalization of flow networks and the Min-Cut-Max-Flow theorem. Our formal proof closely follows a standard textbook proof, and is accessible even without being an expert in Isabelle/HOL, the interactive theorem prover used for the formalization. Optics https://www.isa-afp.org/entries/Optics.shtml https://www.isa-afp.org/entries/Optics.shtml Simon Foster, Frank Zeyda 25 May 2017 00:00:00 +0000 Lenses provide an abstract interface for manipulating data types through spatially-separated views. They are defined abstractly in terms of two functions, <em>get</em>, the return a value from the source type, and <em>put</em> that updates the value. We mechanise the underlying theory of lenses, in terms of an algebraic hierarchy of lenses, including well-behaved and very well-behaved lenses, each lens class being characterised by a set of lens laws. We also mechanise a lens algebra in Isabelle that enables their composition and comparison, so as to allow construction of complex lenses. This is accompanied by a large library of algebraic laws. Moreover we also show how the lens classes can be applied by instantiating them with a number of Isabelle data types. Developing Security Protocols by Refinement https://www.isa-afp.org/entries/Security_Protocol_Refinement.shtml https://www.isa-afp.org/entries/Security_Protocol_Refinement.shtml Christoph Sprenger, Ivano Somaini 24 May 2017 00:00:00 +0000 We propose a development method for security protocols based on stepwise refinement. Our refinement strategy transforms abstract security goals into protocols that are secure when operating over an insecure channel controlled by a Dolev-Yao-style intruder. As intermediate levels of abstraction, we employ messageless guard protocols and channel protocols communicating over channels with security properties. These abstractions provide insights on why protocols are secure and foster the development of families of protocols sharing common structure and properties. We have implemented our method in Isabelle/HOL and used it to develop different entity authentication and key establishment protocols, including realistic features such as key confirmation, replay caches, and encrypted tickets. Our development highlights that guard protocols and channel protocols provide fundamental abstractions for bridging the gap between security properties and standard protocol descriptions based on cryptographic messages. It also shows that our refinement approach scales to protocols of nontrivial size and complexity. Dictionary Construction https://www.isa-afp.org/entries/Dict_Construction.shtml https://www.isa-afp.org/entries/Dict_Construction.shtml Lars Hupel 24 May 2017 00:00:00 +0000 Isabelle's code generator natively supports type classes. For targets that do not have language support for classes and instances, it performs the well-known dictionary translation, as described by Haftmann and Nipkow. This translation happens outside the logic, i.e., there is no guarantee that it is correct, besides the pen-and-paper proof. This work implements a certified dictionary translation that produces new class-free constants and derives equality theorems. The Floyd-Warshall Algorithm for Shortest Paths https://www.isa-afp.org/entries/Floyd_Warshall.shtml https://www.isa-afp.org/entries/Floyd_Warshall.shtml Simon Wimmer, Peter Lammich 08 May 2017 00:00:00 +0000 The Floyd-Warshall algorithm [Flo62, Roy59, War62] is a classic dynamic programming algorithm to compute the length of all shortest paths between any two vertices in a graph (i.e. to solve the all-pairs shortest path problem, or APSP for short). Given a representation of the graph as a matrix of weights M, it computes another matrix M' which represents a graph with the same path lengths and contains the length of the shortest path between any two vertices i and j. This is only possible if the graph does not contain any negative cycles. However, in this case the Floyd-Warshall algorithm will detect the situation by calculating a negative diagonal entry. This entry includes a formalization of the algorithm and of these key properties. The algorithm is refined to an efficient imperative version using the Imperative Refinement Framework. Probabilistic while loop https://www.isa-afp.org/entries/Probabilistic_While.shtml https://www.isa-afp.org/entries/Probabilistic_While.shtml Andreas Lochbihler 05 May 2017 00:00:00 +0000 This AFP entry defines a probabilistic while operator based on sub-probability mass functions and formalises zero-one laws and variant rules for probabilistic loop termination. As applications, we implement probabilistic algorithms for the Bernoulli, geometric and arbitrary uniform distributions that only use fair coin flips, and prove them correct and terminating with probability 1. Effect polymorphism in higher-order logic https://www.isa-afp.org/entries/Monomorphic_Monad.shtml https://www.isa-afp.org/entries/Monomorphic_Monad.shtml Andreas Lochbihler 05 May 2017 00:00:00 +0000 The notion of a monad cannot be expressed within higher-order logic (HOL) due to type system restrictions. We show that if a monad is used with values of only one type, this notion can be formalised in HOL. Based on this idea, we develop a library of effect specifications and implementations of monads and monad transformers. Hence, we can abstract over the concrete monad in HOL definitions and thus use the same definition for different (combinations of) effects. We illustrate the usefulness of effect polymorphism with a monadic interpreter for a simple language. Monad normalisation https://www.isa-afp.org/entries/Monad_Normalisation.shtml https://www.isa-afp.org/entries/Monad_Normalisation.shtml Joshua Schneider, Manuel Eberl, Andreas Lochbihler 05 May 2017 00:00:00 +0000 The usual monad laws can directly be used as rewrite rules for Isabelle’s simplifier to normalise monadic HOL terms and decide equivalences. In a commutative monad, however, the commutativity law is a higher-order permutative rewrite rule that makes the simplifier loop. This AFP entry implements a simproc that normalises monadic expressions in commutative monads using ordered rewriting. The simproc can also permute computations across control operators like if and case. Game-based cryptography in HOL https://www.isa-afp.org/entries/Game_Based_Crypto.shtml https://www.isa-afp.org/entries/Game_Based_Crypto.shtml Andreas Lochbihler, S. Reza Sefidgar, Bhargav Bhatt 05 May 2017 00:00:00 +0000 <p>In this AFP entry, we show how to specify game-based cryptographic security notions and formally prove secure several cryptographic constructions from the literature using the CryptHOL framework. Among others, we formalise the notions of a random oracle, a pseudo-random function, an unpredictable function, and of encryption schemes that are indistinguishable under chosen plaintext and/or ciphertext attacks. We prove the random-permutation/random-function switching lemma, security of the Elgamal and hashed Elgamal public-key encryption scheme and correctness and security of several constructions with pseudo-random functions. </p><p>Our proofs follow the game-hopping style advocated by Shoup and Bellare and Rogaway, from which most of the examples have been taken. We generalise some of their results such that they can be reused in other proofs. Thanks to CryptHOL's integration with Isabelle's parametricity infrastructure, many simple hops are easily justified using the theory of representation independence.</p> CryptHOL https://www.isa-afp.org/entries/CryptHOL.shtml https://www.isa-afp.org/entries/CryptHOL.shtml Andreas Lochbihler 05 May 2017 00:00:00 +0000 <p>CryptHOL provides a framework for formalising cryptographic arguments in Isabelle/HOL. It shallowly embeds a probabilistic functional programming language in higher order logic. The language features monadic sequencing, recursion, random sampling, failures and failure handling, and black-box access to oracles. Oracles are probabilistic functions which maintain hidden state between different invocations. All operators are defined in the new semantic domain of generative probabilistic values, a codatatype. We derive proof rules for the operators and establish a connection with the theory of relational parametricity. Thus, the resuting proofs are trustworthy and comprehensible, and the framework is extensible and widely applicable. </p><p> The framework is used in the accompanying AFP entry "Game-based Cryptography in HOL". There, we show-case our framework by formalizing different game-based proofs from the literature. This formalisation continues the work described in the author's ESOP 2016 paper.</p> Monoidal Categories https://www.isa-afp.org/entries/MonoidalCategory.shtml https://www.isa-afp.org/entries/MonoidalCategory.shtml Eugene W. Stark 04 May 2017 00:00:00 +0000 Building on the formalization of basic category theory set out in the author's previous AFP article, the present article formalizes some basic aspects of the theory of monoidal categories. Among the notions defined here are monoidal category, monoidal functor, and equivalence of monoidal categories. The main theorems formalized are MacLane's coherence theorem and the constructions of the free monoidal category and free strict monoidal category generated by a given category. The coherence theorem is proved syntactically, using a structurally recursive approach to reduction of terms that might have some novel aspects. We also give proofs of some results given by Etingof et al, which may prove useful in a formal setting. In particular, we show that the left and right unitors need not be taken as given data in the definition of monoidal category, nor does the definition of monoidal functor need to take as given a specific isomorphism expressing the preservation of the unit object. Our definitions of monoidal category and monoidal functor are stated so as to take advantage of the economy afforded by these facts. Types, Tableaus and Gödel’s God in Isabelle/HOL https://www.isa-afp.org/entries/Types_Tableaus_and_Goedels_God.shtml https://www.isa-afp.org/entries/Types_Tableaus_and_Goedels_God.shtml David Fuenmayor, Christoph Benzmüller 01 May 2017 00:00:00 +0000 A computer-formalisation of the essential parts of Fitting's textbook "Types, Tableaus and Gödel's God" in Isabelle/HOL is presented. In particular, Fitting's (and Anderson's) variant of the ontological argument is verified and confirmed. This variant avoids the modal collapse, which has been criticised as an undesirable side-effect of Kurt Gödel's (and Dana Scott's) versions of the ontological argument. Fitting's work is employing an intensional higher-order modal logic, which we shallowly embed here in classical higher-order logic. We then utilize the embedded logic for the formalisation of Fitting's argument. (See also the earlier AFP entry ``Gödel's God in Isabelle/HOL''.) Local Lexing https://www.isa-afp.org/entries/LocalLexing.shtml https://www.isa-afp.org/entries/LocalLexing.shtml Steven Obua 28 Apr 2017 00:00:00 +0000 This formalisation accompanies the paper <a href="https://arxiv.org/abs/1702.03277">Local Lexing</a> which introduces a novel parsing concept of the same name. The paper also gives a high-level algorithm for local lexing as an extension of Earley's algorithm. This formalisation proves the algorithm to be correct with respect to its local lexing semantics. As a special case, this formalisation thus also contains a proof of the correctness of Earley's algorithm. The paper contains a short outline of how this formalisation is organised. Constructor Functions https://www.isa-afp.org/entries/Constructor_Funs.shtml https://www.isa-afp.org/entries/Constructor_Funs.shtml Lars Hupel 19 Apr 2017 00:00:00 +0000 Isabelle's code generator performs various adaptations for target languages. Among others, constructor applications have to be fully saturated. That means that for constructor calls occuring as arguments to higher-order functions, synthetic lambdas have to be inserted. This entry provides tooling to avoid this construction altogether by introducing constructor functions. Lazifying case constants https://www.isa-afp.org/entries/Lazy_Case.shtml https://www.isa-afp.org/entries/Lazy_Case.shtml Lars Hupel 18 Apr 2017 00:00:00 +0000 Isabelle's code generator performs various adaptations for target languages. Among others, case statements are printed as match expressions. Internally, this is a sophisticated procedure, because in HOL, case statements are represented as nested calls to the case combinators as generated by the datatype package. Furthermore, the procedure relies on laziness of match expressions in the target language, i.e., that branches guarded by patterns that fail to match are not evaluated. Similarly, <tt>if-then-else</tt> is printed to the corresponding construct in the target language. This entry provides tooling to replace these special cases in the code generator by ignoring these target language features, instead printing case expressions and <tt>if-then-else</tt> as functions. Subresultants https://www.isa-afp.org/entries/Subresultants.shtml https://www.isa-afp.org/entries/Subresultants.shtml Sebastiaan Joosten, René Thiemann, Akihisa Yamada 06 Apr 2017 00:00:00 +0000 We formalize the theory of subresultants and the subresultant polynomial remainder sequence as described by Brown and Traub. As a result, we obtain efficient certified algorithms for computing the resultant and the greatest common divisor of polynomials. Expected Shape of Random Binary Search Trees https://www.isa-afp.org/entries/Random_BSTs.shtml https://www.isa-afp.org/entries/Random_BSTs.shtml Manuel Eberl 04 Apr 2017 00:00:00 +0000 <p>This entry contains proofs for the textbook results about the distributions of the height and internal path length of random binary search trees (BSTs), i.&thinsp;e. BSTs that are formed by taking an empty BST and inserting elements from a fixed set in random order.</p> <p>In particular, we prove a logarithmic upper bound on the expected height and the <em>Θ(n log n)</em> closed-form solution for the expected internal path length in terms of the harmonic numbers. We also show how the internal path length relates to the average-case cost of a lookup in a BST.</p> The number of comparisons in QuickSort https://www.isa-afp.org/entries/Quick_Sort_Cost.shtml https://www.isa-afp.org/entries/Quick_Sort_Cost.shtml Manuel Eberl 15 Mar 2017 00:00:00 +0000 <p>We give a formal proof of the well-known results about the number of comparisons performed by two variants of QuickSort: first, the expected number of comparisons of randomised QuickSort (i.&thinsp;e.&nbsp;QuickSort with random pivot choice) is <em>2&thinsp;(n+1)&thinsp;H<sub>n</sub> - 4&thinsp;n</em>, which is asymptotically equivalent to <em>2&thinsp;n ln n</em>; second, the number of comparisons performed by the classic non-randomised QuickSort has the same distribution in the average case as the randomised one.</p> Lower bound on comparison-based sorting algorithms https://www.isa-afp.org/entries/Comparison_Sort_Lower_Bound.shtml https://www.isa-afp.org/entries/Comparison_Sort_Lower_Bound.shtml Manuel Eberl 15 Mar 2017 00:00:00 +0000 <p>This article contains a formal proof of the well-known fact that number of comparisons that a comparison-based sorting algorithm needs to perform to sort a list of length <em>n</em> is at least <em>log<sub>2</sub>&nbsp;(n!)</em> in the worst case, i.&thinsp;e.&nbsp;<em>Ω(n log n)</em>.</p> <p>For this purpose, a shallow embedding for comparison-based sorting algorithms is defined: a sorting algorithm is a recursive datatype containing either a HOL function or a query of a comparison oracle with a continuation containing the remaining computation. This makes it possible to force the algorithm to use only comparisons and to track the number of comparisons made.</p> The Euler–MacLaurin Formula https://www.isa-afp.org/entries/Euler_MacLaurin.shtml https://www.isa-afp.org/entries/Euler_MacLaurin.shtml Manuel Eberl 10 Mar 2017 00:00:00 +0000 <p>The Euler-MacLaurin formula relates the value of a discrete sum to that of the corresponding integral in terms of the derivatives at the borders of the summation and a remainder term. Since the remainder term is often very small as the summation bounds grow, this can be used to compute asymptotic expansions for sums.</p> <p>This entry contains a proof of this formula for functions from the reals to an arbitrary Banach space. Two variants of the formula are given: the standard textbook version and a variant outlined in <em>Concrete Mathematics</em> that is more useful for deriving asymptotic estimates.</p> <p>As example applications, we use that formula to derive the full asymptotic expansion of the harmonic numbers and the sum of inverse squares.</p> The Group Law for Elliptic Curves https://www.isa-afp.org/entries/Elliptic_Curves_Group_Law.shtml https://www.isa-afp.org/entries/Elliptic_Curves_Group_Law.shtml Stefan Berghofer 28 Feb 2017 00:00:00 +0000 We prove the group law for elliptic curves in Weierstrass form over fields of characteristic greater than 2. In addition to affine coordinates, we also formalize projective coordinates, which allow for more efficient computations. By specializing the abstract formalization to prime fields, we can apply the curve operations to parameters used in standard security protocols. Menger's Theorem https://www.isa-afp.org/entries/Menger.shtml https://www.isa-afp.org/entries/Menger.shtml Christoph Dittmann 26 Feb 2017 00:00:00 +0000 We present a formalization of Menger's Theorem for directed and undirected graphs in Isabelle/HOL. This well-known result shows that if two non-adjacent distinct vertices u, v in a directed graph have no separator smaller than n, then there exist n internally vertex-disjoint paths from u to v. The version for undirected graphs follows immediately because undirected graphs are a special case of directed graphs. Differential Dynamic Logic https://www.isa-afp.org/entries/Differential_Dynamic_Logic.shtml https://www.isa-afp.org/entries/Differential_Dynamic_Logic.shtml Brandon Bohrer 13 Feb 2017 00:00:00 +0000 We formalize differential dynamic logic, a logic for proving properties of hybrid systems. The proof calculus in this formalization is based on the uniform substitution principle. We show it is sound with respect to our denotational semantics, which provides increased confidence in the correctness of the KeYmaera X theorem prover based on this calculus. As an application, we include a proof term checker embedded in Isabelle/HOL with several example proofs. Published in: Brandon Bohrer, Vincent Rahli, Ivana Vukotic, Marcus Völp, André Platzer: Formally verified differential dynamic logic. CPP 2017. Abstract Soundness https://www.isa-afp.org/entries/Abstract_Soundness.shtml https://www.isa-afp.org/entries/Abstract_Soundness.shtml Jasmin Christian Blanchette, Andrei Popescu, Dmitriy Traytel 10 Feb 2017 00:00:00 +0000 A formalized coinductive account of the abstract development of Brotherston, Gorogiannis, and Petersen [APLAS 2012], in a slightly more general form since we work with arbitrary infinite proofs, which may be acyclic. This work is described in detail in an article by the authors, published in 2017 in the <em>Journal of Automated Reasoning</em>. The abstract proof can be instantiated for various formalisms, including first-order logic with inductive predicates. Stone Relation Algebras https://www.isa-afp.org/entries/Stone_Relation_Algebras.shtml https://www.isa-afp.org/entries/Stone_Relation_Algebras.shtml Walter Guttmann 07 Feb 2017 00:00:00 +0000 We develop Stone relation algebras, which generalise relation algebras by replacing the underlying Boolean algebra structure with a Stone algebra. We show that finite matrices over extended real numbers form an instance. As a consequence, relation-algebraic concepts and methods can be used for reasoning about weighted graphs. We also develop a fixpoint calculus and apply it to compare different definitions of reflexive-transitive closures in semirings. Refining Authenticated Key Agreement with Strong Adversaries https://www.isa-afp.org/entries/Key_Agreement_Strong_Adversaries.shtml https://www.isa-afp.org/entries/Key_Agreement_Strong_Adversaries.shtml Joseph Lallemand, Christoph Sprenger 31 Jan 2017 00:00:00 +0000 We develop a family of key agreement protocols that are correct by construction. Our work substantially extends prior work on developing security protocols by refinement. First, we strengthen the adversary by allowing him to compromise different resources of protocol participants, such as their long-term keys or their session keys. This enables the systematic development of protocols that ensure strong properties such as perfect forward secrecy. Second, we broaden the class of protocols supported to include those with non-atomic keys and equationally defined cryptographic operators. We use these extensions to develop key agreement protocols including signed Diffie-Hellman and the core of IKEv1 and SKEME.