diff --git a/metadata/metadata b/metadata/metadata --- a/metadata/metadata +++ b/metadata/metadata @@ -1,10405 +1,10443 @@ [Arith_Prog_Rel_Primes] title = Arithmetic progressions and relative primes author = José Manuel Rodríguez Caballero topic = Mathematics/Number theory date = 2020-02-01 notify = jose.manuel.rodriguez.caballero@ut.ee abstract = This article provides a formalization of the solution obtained by the author of the Problem “ARITHMETIC PROGRESSIONS” from the Putnam exam problems of 2002. The statement of the problem is as follows: For which integers n > 1 does the set of positive integers less than and relatively prime to n constitute an arithmetic progression? [Banach_Steinhaus] title = Banach-Steinhaus Theorem author = Dominique Unruh , Jose Manuel Rodriguez Caballero topic = Mathematics/Analysis date = 2020-05-02 notify = jose.manuel.rodriguez.caballero@ut.ee, unruh@ut.ee abstract = We formalize in Isabelle/HOL a result due to S. Banach and H. Steinhaus known as the Banach-Steinhaus theorem or Uniform boundedness principle: a pointwise-bounded family of continuous linear operators from a Banach space to a normed space is uniformly bounded. Our approach is an adaptation to Isabelle/HOL of a proof due to A. Sokal. [Complex_Geometry] title = Complex Geometry author = Filip Marić , Danijela Simić topic = Mathematics/Geometry date = 2019-12-16 notify = danijela@matf.bg.ac.rs, filip@matf.bg.ac.rs, boutry@unistra.fr abstract = A formalization of geometry of complex numbers is presented. Fundamental objects that are investigated are the complex plane extended by a single infinite point, its objects (points, lines and circles), and groups of transformations that act on them (e.g., inversions and Möbius transformations). Most objects are defined algebraically, but correspondence with classical geometric definitions is shown. [Poincare_Disc] title = Poincaré Disc Model author = Danijela Simić , Filip Marić , Pierre Boutry topic = Mathematics/Geometry date = 2019-12-16 notify = danijela@matf.bg.ac.rs, filip@matf.bg.ac.rs, boutry@unistra.fr abstract = We describe formalization of the Poincaré disc model of hyperbolic geometry within the Isabelle/HOL proof assistant. The model is defined within the extended complex plane (one dimensional complex projectives space ℂP1), formalized in the AFP entry “Complex Geometry”. Points, lines, congruence of pairs of points, betweenness of triples of points, circles, and isometries are defined within the model. It is shown that the model satisfies all Tarski's axioms except the Euclid's axiom. It is shown that it satisfies its negation and the limiting parallels axiom (which proves it to be a model of hyperbolic geometry). [Fourier] title = Fourier Series author = Lawrence C Paulson topic = Mathematics/Analysis date = 2019-09-06 notify = lp15@cam.ac.uk abstract = This development formalises the square integrable functions over the reals and the basics of Fourier series. It culminates with a proof that every well-behaved periodic function can be approximated by a Fourier series. The material is ported from HOL Light: https://github.com/jrh13/hol-light/blob/master/100/fourier.ml [Generic_Deriving] title = Deriving generic class instances for datatypes author = Jonas Rädle , Lars Hupel topic = Computer science/Data structures date = 2018-11-06 notify = jonas.raedle@gmail.com abstract =

We provide a framework for automatically deriving instances for generic type classes. Our approach is inspired by Haskell's generic-deriving package and Scala's shapeless library. In addition to generating the code for type class functions, we also attempt to automatically prove type class laws for these instances. As of now, however, some manual proofs are still required for recursive datatypes.

Note: There are already articles in the AFP that provide automatic instantiation for a number of classes. Concretely, Deriving allows the automatic instantiation of comparators, linear orders, equality, and hashing. Show instantiates a Haskell-style show class.

Our approach works for arbitrary classes (with some Isabelle/HOL overhead for each class), but a smaller set of datatypes.

[Partial_Order_Reduction] title = Partial Order Reduction author = Julian Brunner topic = Computer science/Automata and formal languages date = 2018-06-05 notify = brunnerj@in.tum.de abstract = This entry provides a formalization of the abstract theory of ample set partial order reduction. The formalization includes transition systems with actions, trace theory, as well as basics on finite, infinite, and lazy sequences. We also provide a basic framework for static analysis on concurrent systems with respect to the ample set condition. [CakeML] title = CakeML author = Lars Hupel , Yu Zhang <> contributors = Johannes Åman Pohjola <> topic = Computer science/Programming languages/Language definitions date = 2018-03-12 notify = hupel@in.tum.de abstract = CakeML is a functional programming language with a proven-correct compiler and runtime system. This entry contains an unofficial version of the CakeML semantics that has been exported from the Lem specifications to Isabelle. Additionally, there are some hand-written theory files that adapt the exported code to Isabelle and port proofs from the HOL4 formalization, e.g. termination and equivalence proofs. [CakeML_Codegen] title = A Verified Code Generator from Isabelle/HOL to CakeML author = Lars Hupel topic = Computer science/Programming languages/Compiling, Logic/Rewriting date = 2019-07-08 notify = lars@hupel.info abstract = This entry contains the formalization that accompanies my PhD thesis (see https://lars.hupel.info/research/codegen/). I develop a verified compilation toolchain from executable specifications in Isabelle/HOL to CakeML abstract syntax trees. This improves over the state-of-the-art in Isabelle by providing a trustworthy procedure for code generation. [DiscretePricing] title = Pricing in discrete financial models author = Mnacho Echenim topic = Mathematics/Probability theory, Mathematics/Games and economics date = 2018-07-16 notify = mnacho.echenim@univ-grenoble-alpes.fr abstract = We have formalized the computation of fair prices for derivative products in discrete financial models. As an application, we derive a way to compute fair prices of derivative products in the Cox-Ross-Rubinstein model of a financial market, thus completing the work that was presented in this paper. extra-history = Change history: [2019-05-12]: Renamed discr_mkt predicate to stk_strict_subs and got rid of predicate A for a more natural definition of the type discrete_market; renamed basic quantity processes for coherent notation; renamed value_process into val_process and closing_value_process to cls_val_process; relaxed hypothesis of lemma CRR_market_fair_price. Added functions to price some basic options. (revision 0b813a1a833f)
[Pell] title = Pell's Equation author = Manuel Eberl topic = Mathematics/Number theory date = 2018-06-23 notify = eberlm@in.tum.de abstract =

This article gives the basic theory of Pell's equation x2 = 1 + Dy2, where D ∈ ℕ is a parameter and x, y are integer variables.

The main result that is proven is the following: If D is not a perfect square, then there exists a fundamental solution (x0, y0) that is not the trivial solution (1, 0) and which generates all other solutions (x, y) in the sense that there exists some n ∈ ℕ such that |x| + |y| √D = (x0 + y0 √D)n. This also implies that the set of solutions is infinite, and it gives us an explicit and executable characterisation of all the solutions.

Based on this, simple executable algorithms for computing the fundamental solution and the infinite sequence of all non-negative solutions are also provided.

[WebAssembly] title = WebAssembly author = Conrad Watt topic = Computer science/Programming languages/Language definitions date = 2018-04-29 notify = caw77@cam.ac.uk abstract = This is a mechanised specification of the WebAssembly language, drawn mainly from the previously published paper formalisation of Haas et al. Also included is a full proof of soundness of the type system, together with a verified type checker and interpreter. We include only a partial procedure for the extraction of the type checker and interpreter here. For more details, please see our paper in CPP 2018. [Knuth_Morris_Pratt] title = The string search algorithm by Knuth, Morris and Pratt author = Fabian Hellauer , Peter Lammich topic = Computer science/Algorithms date = 2017-12-18 notify = hellauer@in.tum.de, lammich@in.tum.de abstract = The Knuth-Morris-Pratt algorithm is often used to show that the problem of finding a string s in a text t can be solved deterministically in O(|s| + |t|) time. We use the Isabelle Refinement Framework to formulate and verify the algorithm. Via refinement, we apply some optimisations and finally use the Sepref tool to obtain executable code in Imperative/HOL. [Minkowskis_Theorem] title = Minkowski's Theorem author = Manuel Eberl topic = Mathematics/Geometry, Mathematics/Number theory date = 2017-07-13 notify = eberlm@in.tum.de abstract =

Minkowski's theorem relates a subset of ℝn, the Lebesgue measure, and the integer lattice ℤn: It states that any convex subset of ℝn with volume greater than 2n contains at least one lattice point from ℤn\{0}, i. e. a non-zero point with integer coefficients.

A related theorem which directly implies this is Blichfeldt's theorem, which states that any subset of ℝn with a volume greater than 1 contains two different points whose difference vector has integer components.

The entry contains a proof of both theorems.

[Name_Carrying_Type_Inference] title = Verified Metatheory and Type Inference for a Name-Carrying Simply-Typed Lambda Calculus author = Michael Rawson topic = Computer science/Programming languages/Type systems date = 2017-07-09 notify = mr644@cam.ac.uk, michaelrawson76@gmail.com abstract = I formalise a Church-style simply-typed \(\lambda\)-calculus, extended with pairs, a unit value, and projection functions, and show some metatheory of the calculus, such as the subject reduction property. Particular attention is paid to the treatment of names in the calculus. A nominal style of binding is used, but I use a manual approach over Nominal Isabelle in order to extract an executable type inference algorithm. More information can be found in my undergraduate dissertation. [Propositional_Proof_Systems] title = Propositional Proof Systems author = Julius Michaelis , Tobias Nipkow topic = Logic/Proof theory date = 2017-06-21 notify = maintainafpppt@liftm.de abstract = 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. [Optics] title = Optics author = Simon Foster , Frank Zeyda topic = Computer science/Functional programming, Mathematics/Algebra date = 2017-05-25 notify = simon.foster@york.ac.uk abstract = Lenses provide an abstract interface for manipulating data types through spatially-separated views. They are defined abstractly in terms of two functions, get, the return a value from the source type, and put 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. extra-history = Change history: [2020-03-02]: Added partial bijective and symmetric lenses. Improved alphabet command generating additional lenses and results. Several additional lens relations, including observational equivalence. Additional theorems throughout. Adaptations for Isabelle 2020. (revision 44e2e5c) [2021-01-27] Addition of new theorems throughout, particularly for prisms. New "chantype" command allows the definition of an algebraic datatype with generated prisms. New "dataspace" command allows the definition of a local-based state space, including lenses and prisms. Addition of various examples for the above. (revision 89cf045a) [Game_Based_Crypto] title = Game-based cryptography in HOL author = Andreas Lochbihler , S. Reza Sefidgar <>, Bhargav Bhatt topic = Computer science/Security/Cryptography date = 2017-05-05 notify = mail@andreas-lochbihler.de abstract =

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.

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.

extra-history = Change history: [2018-09-28]: added the CryptHOL tutorial for game-based cryptography (revision 489a395764ae) [Multi_Party_Computation] title = Multi-Party Computation author = David Aspinall , David Butler topic = Computer science/Security date = 2019-05-09 notify = dbutler@turing.ac.uk abstract = We use CryptHOL to consider Multi-Party Computation (MPC) protocols. MPC was first considered by Yao in 1983 and recent advances in efficiency and an increased demand mean it is now deployed in the real world. Security is considered using the real/ideal world paradigm. We first define security in the semi-honest security setting where parties are assumed not to deviate from the protocol transcript. In this setting we prove multiple Oblivious Transfer (OT) protocols secure and then show security for the gates of the GMW protocol. We then define malicious security, this is a stronger notion of security where parties are assumed to be fully corrupted by an adversary. In this setting we again consider OT, as it is a fundamental building block of almost all MPC protocols. [Sigma_Commit_Crypto] title = Sigma Protocols and Commitment Schemes author = David Butler , Andreas Lochbihler topic = Computer science/Security/Cryptography date = 2019-10-07 notify = dbutler@turing.ac.uk abstract = We use CryptHOL to formalise commitment schemes and Sigma-protocols. Both are widely used fundamental two party cryptographic primitives. Security for commitment schemes is considered using game-based definitions whereas the security of Sigma-protocols is considered using both the game-based and simulation-based security paradigms. In this work, we first define security for both primitives and then prove secure multiple case studies: the Schnorr, Chaum-Pedersen and Okamoto Sigma-protocols as well as a construction that allows for compound (AND and OR statements) Sigma-protocols and the Pedersen and Rivest commitment schemes. We also prove that commitment schemes can be constructed from Sigma-protocols. We formalise this proof at an abstract level, only assuming the existence of a Sigma-protocol; consequently, the instantiations of this result for the concrete Sigma-protocols we consider come for free. [CryptHOL] title = CryptHOL author = Andreas Lochbihler topic = Computer science/Security/Cryptography, Computer science/Functional programming, Mathematics/Probability theory date = 2017-05-05 notify = mail@andreas-lochbihler.de abstract =

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.

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.

[Constructive_Cryptography] title = Constructive Cryptography in HOL author = Andreas Lochbihler , S. Reza Sefidgar<> topic = Computer science/Security/Cryptography, Mathematics/Probability theory date = 2018-12-17 notify = mail@andreas-lochbihler.de, reza.sefidgar@inf.ethz.ch abstract = Inspired by Abstract Cryptography, we extend CryptHOL, a framework for formalizing game-based proofs, with an abstract model of Random Systems and provide proof rules about their composition and equality. This foundation facilitates the formalization of Constructive Cryptography proofs, where the security of a cryptographic scheme is realized as a special form of construction in which a complex random system is built from simpler ones. This is a first step towards a fully-featured compositional framework, similar to Universal Composability framework, that supports formalization of simulation-based proofs. [Probabilistic_While] title = Probabilistic while loop author = Andreas Lochbihler topic = Computer science/Functional programming, Mathematics/Probability theory, Computer science/Algorithms date = 2017-05-05 notify = mail@andreas-lochbihler.de abstract = 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. extra-history = Change history: [2018-02-02]: Added a proof that probabilistic conditioning can be implemented by repeated sampling. (revision 305867c4e911)
[Monad_Normalisation] title = Monad normalisation author = Joshua Schneider <>, Manuel Eberl , Andreas Lochbihler topic = Tools, Computer science/Functional programming, Logic/Rewriting date = 2017-05-05 notify = mail@andreas-lochbihler.de abstract = 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. [Monomorphic_Monad] title = Effect polymorphism in higher-order logic author = Andreas Lochbihler topic = Computer science/Functional programming date = 2017-05-05 notify = mail@andreas-lochbihler.de abstract = 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. extra-history = Change history: [2018-02-15]: added further specifications and implementations of non-determinism; more examples (revision bc5399eea78e)
[Constructor_Funs] title = Constructor Functions author = Lars Hupel topic = Tools date = 2017-04-19 notify = hupel@in.tum.de abstract = 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. [Lazy_Case] title = Lazifying case constants author = Lars Hupel topic = Tools date = 2017-04-18 notify = hupel@in.tum.de abstract = 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, if-then-else 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 if-then-else as functions. [Dict_Construction] title = Dictionary Construction author = Lars Hupel topic = Tools date = 2017-05-24 notify = hupel@in.tum.de abstract = 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. [Higher_Order_Terms] title = An Algebra for Higher-Order Terms author = Lars Hupel contributors = Yu Zhang <> topic = Computer science/Programming languages/Lambda calculi date = 2019-01-15 notify = lars@hupel.info abstract = In this formalization, I introduce a higher-order term algebra, generalizing the notions of free variables, matching, and substitution. The need arose from the work on a verified compiler from Isabelle to CakeML. Terms can be thought of as consisting of a generic (free variables, constants, application) and a specific part. As example applications, this entry provides instantiations for de-Bruijn terms, terms with named variables, and Blanchette’s λ-free higher-order terms. Furthermore, I implement translation functions between de-Bruijn terms and named terms and prove their correctness. [Subresultants] title = Subresultants author = Sebastiaan Joosten , René Thiemann , Akihisa Yamada topic = Mathematics/Algebra date = 2017-04-06 notify = rene.thiemann@uibk.ac.at abstract = 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. [Comparison_Sort_Lower_Bound] title = Lower bound on comparison-based sorting algorithms author = Manuel Eberl topic = Computer science/Algorithms date = 2017-03-15 notify = eberlm@in.tum.de abstract =

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 n is at least log2 (n!) in the worst case, i. e. Ω(n log n).

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.

[Quick_Sort_Cost] title = The number of comparisons in QuickSort author = Manuel Eberl topic = Computer science/Algorithms date = 2017-03-15 notify = eberlm@in.tum.de abstract =

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. e. QuickSort with random pivot choice) is 2 (n+1) Hn - 4 n, which is asymptotically equivalent to 2 n ln n; second, the number of comparisons performed by the classic non-randomised QuickSort has the same distribution in the average case as the randomised one.

[Random_BSTs] title = Expected Shape of Random Binary Search Trees author = Manuel Eberl topic = Computer science/Data structures date = 2017-04-04 notify = eberlm@in.tum.de abstract =

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. e. BSTs that are formed by taking an empty BST and inserting elements from a fixed set in random order.

In particular, we prove a logarithmic upper bound on the expected height and the Θ(n log n) 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.

[Randomised_BSTs] title = Randomised Binary Search Trees author = Manuel Eberl topic = Computer science/Data structures date = 2018-10-19 notify = eberlm@in.tum.de abstract =

This work is a formalisation of the Randomised Binary Search Trees introduced by Martínez and Roura, including definitions and correctness proofs.

Like randomised treaps, they are a probabilistic data structure that behaves exactly as if elements were inserted into a non-balancing BST in random order. However, unlike treaps, they only use discrete probability distributions, but their use of randomness is more complicated.

[E_Transcendental] title = The Transcendence of e author = Manuel Eberl topic = Mathematics/Analysis, Mathematics/Number theory date = 2017-01-12 notify = eberlm@in.tum.de abstract =

This work contains a proof that Euler's number e is transcendental. The proof follows the standard approach of assuming that e is algebraic and then using a specific integer polynomial to derive two inconsistent bounds, leading to a contradiction.

This kind of approach can be found in many different sources; this formalisation mostly follows a PlanetMath article by Roger Lipsett.

[Pi_Transcendental] title = The Transcendence of π author = Manuel Eberl topic = Mathematics/Number theory date = 2018-09-28 notify = eberlm@in.tum.de abstract =

This entry shows the transcendence of π based on the classic proof using the fundamental theorem of symmetric polynomials first given by von Lindemann in 1882, but the formalisation mostly follows the version by Niven. The proof reuses much of the machinery developed in the AFP entry on the transcendence of e.

[Hermite_Lindemann] title = The Hermite–Lindemann–Weierstraß Transcendence Theorem author = Manuel Eberl topic = Mathematics/Number theory date = 2021-03-03 notify = eberlm@in.tum.de abstract =

This article provides a formalisation of the Hermite-Lindemann-Weierstraß Theorem (also known as simply Hermite-Lindemann or Lindemann-Weierstraß). This theorem is one of the crowning achievements of 19th century number theory.

The theorem states that if $\alpha_1, \ldots, \alpha_n\in\mathbb{C}$ are algebraic numbers that are linearly independent over $\mathbb{Z}$, then $e^{\alpha_1},\ldots,e^{\alpha_n}$ are algebraically independent over $\mathbb{Q}$.

Like the previous formalisation in Coq by Bernard, I proceeded by formalising Baker's version of the theorem and proof and then deriving the original one from that. Baker's version states that for any algebraic numbers $\beta_1, \ldots, \beta_n\in\mathbb{C}$ and distinct algebraic numbers $\alpha_i, \ldots, \alpha_n\in\mathbb{C}$, we have $\beta_1 e^{\alpha_1} + \ldots + \beta_n e^{\alpha_n} = 0$ if and only if all the $\beta_i$ are zero.

This has a number of direct corollaries, e.g.:

  • $e$ and $\pi$ are transcendental
  • $e^z$, $\sin z$, $\tan z$, etc. are transcendental for algebraic $z\in\mathbb{C}\setminus\{0\}$
  • $\ln z$ is transcendental for algebraic $z\in\mathbb{C}\setminus\{0, 1\}$
[DFS_Framework] title = A Framework for Verifying Depth-First Search Algorithms author = Peter Lammich , René Neumann notify = lammich@in.tum.de date = 2016-07-05 topic = Computer science/Algorithms/Graph abstract =

This entry presents a framework for the modular verification of DFS-based algorithms, which is described in our [CPP-2015] paper. It provides a generic DFS algorithm framework, that can be parameterized with user-defined actions on certain events (e.g. discovery of new node). It comes with an extensible library of invariants, which can be used to derive invariants of a specific parameterization. Using refinement techniques, efficient implementations of the algorithms can easily be derived. Here, the framework comes with templates for a recursive and a tail-recursive implementation, and also with several templates for implementing the data structures required by the DFS algorithm. Finally, this entry contains a set of re-usable DFS-based algorithms, which illustrate the application of the framework.

[CPP-2015] Peter Lammich, René Neumann: A Framework for Verifying Depth-First Search Algorithms. CPP 2015: 137-146

[Flow_Networks] title = Flow Networks and the Min-Cut-Max-Flow Theorem author = Peter Lammich , S. Reza Sefidgar <> topic = Mathematics/Graph theory date = 2017-06-01 notify = lammich@in.tum.de abstract = 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. [Prpu_Maxflow] title = Formalizing Push-Relabel Algorithms author = Peter Lammich , S. Reza Sefidgar <> topic = Computer science/Algorithms/Graph, Mathematics/Graph theory date = 2017-06-01 notify = lammich@in.tum.de abstract = 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. [Buildings] title = Chamber Complexes, Coxeter Systems, and Buildings author = Jeremy Sylvestre notify = jeremy.sylvestre@ualberta.ca date = 2016-07-01 topic = Mathematics/Algebra, Mathematics/Geometry abstract = We provide a basic formal framework for the theory of chamber complexes and Coxeter systems, and for buildings as thick chamber complexes endowed with a system of apartments. Along the way, we develop some of the general theory of abstract simplicial complexes and of groups (relying on the group_add class for the basics), including free groups and group presentations, and their universal properties. The main results verified are that the deletion condition is both necessary and sufficient for a group with a set of generators of order two to be a Coxeter system, and that the apartments in a (thick) building are all uniformly Coxeter. [Algebraic_VCs] title = Program Construction and Verification Components Based on Kleene Algebra author = Victor B. F. Gomes , Georg Struth notify = victor.gomes@cl.cam.ac.uk, g.struth@sheffield.ac.uk date = 2016-06-18 topic = Mathematics/Algebra abstract = Variants of Kleene algebra support program construction and verification by algebraic reasoning. This entry provides a verification component for Hoare logic based on Kleene algebra with tests, verification components for weakest preconditions and strongest postconditions based on Kleene algebra with domain and a component for step-wise refinement based on refinement Kleene algebra with tests. In addition to these components for the partial correctness of while programs, a verification component for total correctness based on divergence Kleene algebras and one for (partial correctness) of recursive programs based on domain quantales are provided. Finally we have integrated memory models for programs with pointers and a program trace semantics into the weakest precondition component. [C2KA_DistributedSystems] title = Communicating Concurrent Kleene Algebra for Distributed Systems Specification author = Maxime Buyse , Jason Jaskolka topic = Computer science/Automata and formal languages, Mathematics/Algebra date = 2019-08-06 notify = maxime.buyse@polytechnique.edu, jason.jaskolka@carleton.ca abstract = Communicating Concurrent Kleene Algebra (C²KA) is a mathematical framework for capturing the communicating and concurrent behaviour of agents in distributed systems. It extends Hoare et al.'s Concurrent Kleene Algebra (CKA) with communication actions through the notions of stimuli and shared environments. C²KA has applications in studying system-level properties of distributed systems such as safety, security, and reliability. In this work, we formalize results about C²KA and its application for distributed systems specification. We first formalize the stimulus structure and behaviour structure (CKA). Next, we combine them to formalize C²KA and its properties. Then, we formalize notions and properties related to the topology of distributed systems and the potential for communication via stimuli and via shared environments of agents, all within the algebraic setting of C²KA. [Card_Equiv_Relations] title = Cardinality of Equivalence Relations author = Lukas Bulwahn notify = lukas.bulwahn@gmail.com date = 2016-05-24 topic = Mathematics/Combinatorics abstract = This entry provides formulae for counting the number of equivalence relations and partial equivalence relations over a finite carrier set with given cardinality. To count the number of equivalence relations, we provide bijections between equivalence relations and set partitions, and then transfer the main results of the two AFP entries, Cardinality of Set Partitions and Spivey's Generalized Recurrence for Bell Numbers, to theorems on equivalence relations. To count the number of partial equivalence relations, we observe that counting partial equivalence relations over a set A is equivalent to counting all equivalence relations over all subsets of the set A. From this observation and the results on equivalence relations, we show that the cardinality of partial equivalence relations over a finite set of cardinality n is equal to the n+1-th Bell number. [Twelvefold_Way] title = The Twelvefold Way author = Lukas Bulwahn topic = Mathematics/Combinatorics date = 2016-12-29 notify = lukas.bulwahn@gmail.com abstract = This entry provides all cardinality theorems of the Twelvefold Way. The Twelvefold Way systematically classifies twelve related combinatorial problems concerning two finite sets, which include counting permutations, combinations, multisets, set partitions and number partitions. This development builds upon the existing formal developments with cardinality theorems for those structures. It provides twelve bijections from the various structures to different equivalence classes on finite functions, and hence, proves cardinality formulae for these equivalence classes on finite functions. [Chord_Segments] title = Intersecting Chords Theorem author = Lukas Bulwahn notify = lukas.bulwahn@gmail.com date = 2016-10-11 topic = Mathematics/Geometry abstract = This entry provides a geometric proof of the intersecting chords theorem. The theorem states that when two chords intersect each other inside a circle, the products of their segments are equal. After a short review of existing proofs in the literature, I decided to use a proof approach that employs reasoning about lengths of line segments, the orthogonality of two lines and the Pythagoras Law. Hence, one can understand the formalized proof easily with the knowledge of a few general geometric facts that are commonly taught in high-school. This theorem is the 55th theorem of the Top 100 Theorems list. [Category3] title = Category Theory with Adjunctions and Limits author = Eugene W. Stark notify = stark@cs.stonybrook.edu date = 2016-06-26 topic = Mathematics/Category theory abstract =

This article attempts to develop a usable framework for doing category theory in Isabelle/HOL. Our point of view, which to some extent differs from that of the previous AFP articles on the subject, is to try to explore how category theory can be done efficaciously within HOL, rather than trying to match exactly the way things are done using a traditional approach. To this end, we define the notion of category in an "object-free" style, in which a category is represented by a single partial composition operation on arrows. This way of defining categories provides some advantages in the context of HOL, including the ability to avoid the use of records and the possibility of defining functors and natural transformations simply as certain functions on arrows, rather than as composite objects. We define various constructions associated with the basic notions, including: dual category, product category, functor category, discrete category, free category, functor composition, and horizontal and vertical composite of natural transformations. A "set category" locale is defined that axiomatizes the notion "category of all sets at a type and all functions between them," and a fairly extensive set of properties of set categories is derived from the locale assumptions. The notion of a set category is used to prove the Yoneda Lemma in a general setting of a category equipped with a "hom embedding," which maps arrows of the category to the "universe" of the set category. We also give a treatment of adjunctions, defining adjunctions via left and right adjoint functors, natural bijections between hom-sets, and unit and counit natural transformations, and showing the equivalence of these definitions. We also develop the theory of limits, including representations of functors, diagrams and cones, and diagonal functors. We show that right adjoint functors preserve limits, and that limits can be constructed via products and equalizers. We characterize the conditions under which limits exist in a set category. We also examine the case of limits in a functor category, ultimately culminating in a proof that the Yoneda embedding preserves limits.

Revisions made subsequent to the first version of this article added material on equivalence of categories, cartesian categories, categories with pullbacks, categories with finite limits, and cartesian closed categories. A construction was given of the category of hereditarily finite sets and functions between them, and it was shown that this category is cartesian closed.

extra-history = Change history: [2018-05-29]: Revised axioms for the category locale. Introduced notation for composition and "in hom". (revision 8318366d4575)
[2020-02-15]: Move ConcreteCategory.thy from Bicategory to Category3 and use it systematically. Make other minor improvements throughout. (revision a51840d36867)
[2020-07-10]: Added new material, mostly centered around cartesian categories. (revision 06640f317a79)
[2020-11-04]: Minor modifications and extensions made in conjunction with the addition of new material to Bicategory. (revision 472cb2268826)
[MonoidalCategory] title = Monoidal Categories author = Eugene W. Stark topic = Mathematics/Category theory date = 2017-05-04 notify = stark@cs.stonybrook.edu abstract =

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.

Revisions made subsequent to the first version of this article added material on cartesian monoidal categories; showing that the underlying category of a cartesian monoidal category is a cartesian category, and that every cartesian category extends to a cartesian monoidal category.

extra-history = Change history: [2017-05-18]: Integrated material from MonoidalCategory/Category3Adapter into Category3/ and deleted adapter. (revision 015543cdd069)
[2018-05-29]: Modifications required due to 'Category3' changes. Introduced notation for "in hom". (revision 8318366d4575)
[2020-02-15]: Cosmetic improvements. (revision a51840d36867)
[2020-07-10]: Added new material on cartesian monoidal categories. (revision 06640f317a79)
[Card_Multisets] title = Cardinality of Multisets author = Lukas Bulwahn notify = lukas.bulwahn@gmail.com date = 2016-06-26 topic = Mathematics/Combinatorics abstract =

This entry provides three lemmas to count the number of multisets of a given size and finite carrier set. The first lemma provides a cardinality formula assuming that the multiset's elements are chosen from the given carrier set. The latter two lemmas provide formulas assuming that the multiset's elements also cover the given carrier set, i.e., each element of the carrier set occurs in the multiset at least once.

The proof of the first lemma uses the argument of the recurrence relation for counting multisets. The proof of the second lemma is straightforward, and the proof of the third lemma is easily obtained using the first cardinality lemma. A challenge for the formalization is the derivation of the required induction rule, which is a special combination of the induction rules for finite sets and natural numbers. The induction rule is derived by defining a suitable inductive predicate and transforming the predicate's induction rule.

[Posix-Lexing] title = POSIX Lexing with Derivatives of Regular Expressions author = Fahad Ausaf , Roy Dyckhoff , Christian Urban notify = christian.urban@kcl.ac.uk date = 2016-05-24 topic = Computer science/Automata and formal languages abstract = Brzozowski introduced the notion of derivatives for regular expressions. They can be used for a very simple regular expression matching algorithm. Sulzmann and Lu cleverly extended this algorithm in order to deal with POSIX matching, which is the underlying disambiguation strategy for regular expressions needed in lexers. In this entry we give our inductive definition of what a POSIX value is and show (i) that such a value is unique (for given regular expression and string being matched) and (ii) that Sulzmann and Lu's algorithm always generates such a value (provided that the regular expression matches the string). We also prove the correctness of an optimised version of the POSIX matching algorithm. [LocalLexing] title = Local Lexing author = Steven Obua topic = Computer science/Automata and formal languages date = 2017-04-28 notify = steven@recursivemind.com abstract = This formalisation accompanies the paper Local Lexing 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. [MFMC_Countable] title = A Formal Proof of the Max-Flow Min-Cut Theorem for Countable Networks author = Andreas Lochbihler date = 2016-05-09 topic = Mathematics/Graph theory abstract = This article formalises a proof of the maximum-flow minimal-cut theorem for networks with countably many edges. A network is a directed graph with non-negative real-valued edge labels and two dedicated vertices, the source and the sink. A flow in a network assigns non-negative real numbers to the edges such that for all vertices except for the source and the sink, the sum of values on incoming edges equals the sum of values on outgoing edges. A cut is a subset of the vertices which contains the source, but not the sink. Our theorem states that in every network, there is a flow and a cut such that the flow saturates all the edges going out of the cut and is zero on all the incoming edges. The proof is based on the paper The Max-Flow Min-Cut theorem for countable networks by Aharoni et al. Additionally, we prove a characterisation of the lifting operation for relations on discrete probability distributions, which leads to a concise proof of its distributivity over relation composition. notify = mail@andreas-lochbihler.de extra-history = Change history: [2017-09-06]: derive characterisation for the lifting operations on discrete distributions from finite version of the max-flow min-cut theorem (revision a7a198f5bab0)
[2020-12-19]: simpler proof of linkability for bounded unhindered bipartite webs, leading to a simpler proof for networks with bounded out-capacities (revision 93ca33f4d915)
[Liouville_Numbers] title = Liouville numbers author = Manuel Eberl date = 2015-12-28 topic = Mathematics/Analysis, Mathematics/Number theory abstract =

Liouville numbers are a class of transcendental numbers that can be approximated particularly well with rational numbers. Historically, they were the first numbers whose transcendence was proven.

In this entry, we define the concept of Liouville numbers as well as the standard construction to obtain Liouville numbers (including Liouville's constant) and we prove their most important properties: irrationality and transcendence.

The proof is very elementary and requires only standard arithmetic, the Mean Value Theorem for polynomials, and the boundedness of polynomials on compact intervals.

notify = eberlm@in.tum.de [Triangle] title = Basic Geometric Properties of Triangles author = Manuel Eberl date = 2015-12-28 topic = Mathematics/Geometry abstract =

This entry contains a definition of angles between vectors and between three points. Building on this, we prove basic geometric properties of triangles, such as the Isosceles Triangle Theorem, the Law of Sines and the Law of Cosines, that the sum of the angles of a triangle is π, and the congruence theorems for triangles.

The definitions and proofs were developed following those by John Harrison in HOL Light. However, due to Isabelle's type class system, all definitions and theorems in the Isabelle formalisation hold for all real inner product spaces.

notify = eberlm@in.tum.de [Prime_Harmonic_Series] title = The Divergence of the Prime Harmonic Series author = Manuel Eberl date = 2015-12-28 topic = Mathematics/Number theory abstract =

In this work, we prove the lower bound ln(H_n) - ln(5/3) for the partial sum of the Prime Harmonic series and, based on this, the divergence of the Prime Harmonic Series ∑[p prime] · 1/p.

The proof relies on the unique squarefree decomposition of natural numbers. This is similar to Euler's original proof (which was highly informal and morally questionable). Its advantage over proofs by contradiction, like the famous one by Paul Erdős, is that it provides a relatively good lower bound for the partial sums.

notify = eberlm@in.tum.de [Descartes_Sign_Rule] title = Descartes' Rule of Signs author = Manuel Eberl date = 2015-12-28 topic = Mathematics/Analysis abstract =

Descartes' Rule of Signs relates the number of positive real roots of a polynomial with the number of sign changes in its coefficient sequence.

Our proof follows the simple inductive proof given by Rob Arthan, which was also used by John Harrison in his HOL Light formalisation. We proved most of the lemmas for arbitrary linearly-ordered integrity domains (e.g. integers, rationals, reals); the main result, however, requires the intermediate value theorem and was therefore only proven for real polynomials.

notify = eberlm@in.tum.de [Euler_MacLaurin] title = The Euler–MacLaurin Formula author = Manuel Eberl topic = Mathematics/Analysis date = 2017-03-10 notify = eberlm@in.tum.de abstract =

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.

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 Concrete Mathematics that is more useful for deriving asymptotic estimates.

As example applications, we use that formula to derive the full asymptotic expansion of the harmonic numbers and the sum of inverse squares.

[Card_Partitions] title = Cardinality of Set Partitions author = Lukas Bulwahn date = 2015-12-12 topic = Mathematics/Combinatorics abstract = The theory's main theorem states that the cardinality of set partitions of size k on a carrier set of size n is expressed by Stirling numbers of the second kind. In Isabelle, Stirling numbers of the second kind are defined in the AFP entry `Discrete Summation` through their well-known recurrence relation. The main theorem relates them to the alternative definition as cardinality of set partitions. The proof follows the simple and short explanation in Richard P. Stanley's `Enumerative Combinatorics: Volume 1` and Wikipedia, and unravels the full details and implicit reasoning steps of these explanations. notify = lukas.bulwahn@gmail.com [Card_Number_Partitions] title = Cardinality of Number Partitions author = Lukas Bulwahn date = 2016-01-14 topic = Mathematics/Combinatorics abstract = This entry provides a basic library for number partitions, defines the two-argument partition function through its recurrence relation and relates this partition function to the cardinality of number partitions. The main proof shows that the recursively-defined partition function with arguments n and k equals the cardinality of number partitions of n with exactly k parts. The combinatorial proof follows the proof sketch of Theorem 2.4.1 in Mazur's textbook `Combinatorics: A Guided Tour`. This entry can serve as starting point for various more intrinsic properties about number partitions, the partition function and related recurrence relations. notify = lukas.bulwahn@gmail.com [Multirelations] title = Binary Multirelations author = Hitoshi Furusawa , Georg Struth date = 2015-06-11 topic = Mathematics/Algebra abstract = Binary multirelations associate elements of a set with its subsets; hence they are binary relations from a set to its power set. Applications include alternating automata, models and logics for games, program semantics with dual demonic and angelic nondeterministic choices and concurrent dynamic logics. This proof document supports an arXiv article that formalises the basic algebra of multirelations and proposes axiom systems for them, ranging from weak bi-monoids to weak bi-quantales. notify = [Noninterference_Generic_Unwinding] title = The Generic Unwinding Theorem for CSP Noninterference Security author = Pasquale Noce date = 2015-06-11 topic = Computer science/Security, Computer science/Concurrency/Process calculi abstract =

The classical definition of noninterference security for a deterministic state machine with outputs requires to consider the outputs produced by machine actions after any trace, i.e. any indefinitely long sequence of actions, of the machine. In order to render the verification of the security of such a machine more straightforward, there is a need of some sufficient condition for security such that just individual actions, rather than unbounded sequences of actions, have to be considered.

By extending previous results applying to transitive noninterference policies, Rushby has proven an unwinding theorem that provides a sufficient condition of this kind in the general case of a possibly intransitive policy. This condition has to be satisfied by a generic function mapping security domains into equivalence relations over machine states.

An analogous problem arises for CSP noninterference security, whose definition requires to consider any possible future, i.e. any indefinitely long sequence of subsequent events and any indefinitely large set of refused events associated to that sequence, for each process trace.

This paper provides a sufficient condition for CSP noninterference security, which indeed requires to just consider individual accepted and refused events and applies to the general case of a possibly intransitive policy. This condition follows Rushby's one for classical noninterference security, and has to be satisfied by a generic function mapping security domains into equivalence relations over process traces; hence its name, Generic Unwinding Theorem. Variants of this theorem applying to deterministic processes and trace set processes are also proven. Finally, the sufficient condition for security expressed by the theorem is shown not to be a necessary condition as well, viz. there exists a secure process such that no domain-relation map satisfying the condition exists.

notify = [Noninterference_Ipurge_Unwinding] title = The Ipurge Unwinding Theorem for CSP Noninterference Security author = Pasquale Noce date = 2015-06-11 topic = Computer science/Security abstract =

The definition of noninterference security for Communicating Sequential Processes requires to consider any possible future, i.e. any indefinitely long sequence of subsequent events and any indefinitely large set of refused events associated to that sequence, for each process trace. In order to render the verification of the security of a process more straightforward, there is a need of some sufficient condition for security such that just individual accepted and refused events, rather than unbounded sequences and sets of events, have to be considered.

Of course, if such a sufficient condition were necessary as well, it would be even more valuable, since it would permit to prove not only that a process is secure by verifying that the condition holds, but also that a process is not secure by verifying that the condition fails to hold.

This paper provides a necessary and sufficient condition for CSP noninterference security, which indeed requires to just consider individual accepted and refused events and applies to the general case of a possibly intransitive policy. This condition follows Rushby's output consistency for deterministic state machines with outputs, and has to be satisfied by a specific function mapping security domains into equivalence relations over process traces. The definition of this function makes use of an intransitive purge function following Rushby's one; hence the name given to the condition, Ipurge Unwinding Theorem.

Furthermore, in accordance with Hoare's formal definition of deterministic processes, it is shown that a process is deterministic just in case it is a trace set process, i.e. it may be identified by means of a trace set alone, matching the set of its traces, in place of a failures-divergences pair. Then, variants of the Ipurge Unwinding Theorem are proven for deterministic processes and trace set processes.

notify = [Relational_Method] title = The Relational Method with Message Anonymity for the Verification of Cryptographic Protocols author = Pasquale Noce topic = Computer science/Security date = 2020-12-05 notify = pasquale.noce.lavoro@gmail.com abstract = This paper introduces a new method for the formal verification of cryptographic protocols, the relational method, derived from Paulson's inductive method by means of some enhancements aimed at streamlining formal definitions and proofs, specially for protocols using public key cryptography. Moreover, this paper proposes a method to formalize a further security property, message anonymity, in addition to message confidentiality and authenticity. The relational method, including message anonymity, is then applied to the verification of a sample authentication protocol, comprising Password Authenticated Connection Establishment (PACE) with Chip Authentication Mapping followed by the explicit verification of an additional password over the PACE secure channel. [List_Interleaving] title = Reasoning about Lists via List Interleaving author = Pasquale Noce date = 2015-06-11 topic = Computer science/Data structures abstract =

Among the various mathematical tools introduced in his outstanding work on Communicating Sequential Processes, Hoare has defined "interleaves" as the predicate satisfied by any three lists such that the first list may be split into sublists alternately extracted from the other two ones, whatever is the criterion for extracting an item from either one list or the other in each step.

This paper enriches Hoare's definition by identifying such criterion with the truth value of a predicate taking as inputs the head and the tail of the first list. This enhanced "interleaves" predicate turns out to permit the proof of equalities between lists without the need of an induction. Some rules that allow to infer "interleaves" statements without induction, particularly applying to the addition or removal of a prefix to the input lists, are also proven. Finally, a stronger version of the predicate, named "Interleaves", is shown to fulfil further rules applying to the addition or removal of a suffix to the input lists.

notify = [Residuated_Lattices] title = Residuated Lattices author = Victor B. F. Gomes , Georg Struth date = 2015-04-15 topic = Mathematics/Algebra abstract = The theory of residuated lattices, first proposed by Ward and Dilworth, is formalised in Isabelle/HOL. This includes concepts of residuated functions; their adjoints and conjugates. It also contains necessary and sufficient conditions for the existence of these operations in an arbitrary lattice. The mathematical components for residuated lattices are linked to the AFP entry for relation algebra. In particular, we prove Jonsson and Tsinakis conditions for a residuated boolean algebra to form a relation algebra. notify = g.struth@sheffield.ac.uk [ConcurrentGC] title = Relaxing Safely: Verified On-the-Fly Garbage Collection for x86-TSO author = Peter Gammie , Tony Hosking , Kai Engelhardt <> date = 2015-04-13 topic = Computer science/Algorithms/Concurrent abstract =

We use ConcurrentIMP to model Schism, a state-of-the-art real-time garbage collection scheme for weak memory, and show that it is safe on x86-TSO.

This development accompanies the PLDI 2015 paper of the same name.

notify = peteg42@gmail.com [List_Update] title = Analysis of List Update Algorithms author = Maximilian P.L. Haslbeck , Tobias Nipkow date = 2016-02-17 topic = Computer science/Algorithms/Online abstract =

These theories formalize the quantitative analysis of a number of classical algorithms for the list update problem: 2-competitiveness of move-to-front, the lower bound of 2 for the competitiveness of deterministic list update algorithms and 1.6-competitiveness of the randomized COMB algorithm, the best randomized list update algorithm known to date. The material is based on the first two chapters of Online Computation and Competitive Analysis by Borodin and El-Yaniv.

For an informal description see the FSTTCS 2016 publication Verified Analysis of List Update Algorithms by Haslbeck and Nipkow.

notify = nipkow@in.tum.de [ConcurrentIMP] title = Concurrent IMP author = Peter Gammie date = 2015-04-13 topic = Computer science/Programming languages/Logics abstract = ConcurrentIMP extends the small imperative language IMP with control non-determinism and constructs for synchronous message passing. notify = peteg42@gmail.com [TortoiseHare] title = The Tortoise and Hare Algorithm author = Peter Gammie date = 2015-11-18 topic = Computer science/Algorithms abstract = We formalize the Tortoise and Hare cycle-finding algorithm ascribed to Floyd by Knuth, and an improved version due to Brent. notify = peteg42@gmail.com [UPF] title = The Unified Policy Framework (UPF) author = Achim D. Brucker , Lukas Brügger , Burkhart Wolff date = 2014-11-28 topic = Computer science/Security abstract = We present the Unified Policy Framework (UPF), a generic framework for modelling security (access-control) policies. UPF emphasizes the view that a policy is a policy decision function that grants or denies access to resources, permissions, etc. In other words, instead of modelling the relations of permitted or prohibited requests directly, we model the concrete function that implements the policy decision point in a system. In more detail, UPF is based on the following four principles: 1) Functional representation of policies, 2) No conflicts are possible, 3) Three-valued decision type (allow, deny, undefined), 4) Output type not containing the decision only. notify = adbrucker@0x5f.org, wolff@lri.fr, lukas.a.bruegger@gmail.com [UPF_Firewall] title = Formal Network Models and Their Application to Firewall Policies author = Achim D. Brucker , Lukas Brügger<>, Burkhart Wolff topic = Computer science/Security, Computer science/Networks date = 2017-01-08 notify = adbrucker@0x5f.org abstract = We present a formal model of network protocols and their application to modeling firewall policies. The formalization is based on the Unified Policy Framework (UPF). The formalization was originally developed with for generating test cases for testing the security configuration actual firewall and router (middle-boxes) using HOL-TestGen. Our work focuses on modeling application level protocols on top of tcp/ip. [AODV] title = Loop freedom of the (untimed) AODV routing protocol author = Timothy Bourke , Peter Höfner date = 2014-10-23 topic = Computer science/Concurrency/Process calculi abstract =

The Ad hoc On-demand Distance Vector (AODV) routing protocol allows the nodes in a Mobile Ad hoc Network (MANET) or a Wireless Mesh Network (WMN) to know where to forward data packets. Such a protocol is ‘loop free’ if it never leads to routing decisions that forward packets in circles.

This development mechanises an existing pen-and-paper proof of loop freedom of AODV. The protocol is modelled in the Algebra of Wireless Networks (AWN), which is the subject of an earlier paper and AFP mechanization. The proof relies on a novel compositional approach for lifting invariants to networks of nodes.

We exploit the mechanization to analyse several variants of AODV and show that Isabelle/HOL can re-establish most proof obligations automatically and identify exactly the steps that are no longer valid.

notify = tim@tbrk.org [Show] title = Haskell's Show Class in Isabelle/HOL author = Christian Sternagel , René Thiemann date = 2014-07-29 topic = Computer science/Functional programming license = LGPL abstract = We implemented a type class for "to-string" functions, similar to Haskell's Show class. Moreover, we provide instantiations for Isabelle/HOL's standard types like bool, prod, sum, nats, ints, and rats. It is further possible, to automatically derive show functions for arbitrary user defined datatypes similar to Haskell's "deriving Show". extra-history = Change history: [2015-03-11]: Adapted development to new-style (BNF-based) datatypes.
[2015-04-10]: Moved development for old-style datatypes into subdirectory "Old_Datatype".
notify = christian.sternagel@uibk.ac.at, rene.thiemann@uibk.ac.at [Certification_Monads] title = Certification Monads author = Christian Sternagel , René Thiemann date = 2014-10-03 topic = Computer science/Functional programming abstract = This entry provides several monads intended for the development of stand-alone certifiers via code generation from Isabelle/HOL. More specifically, there are three flavors of error monads (the sum type, for the case where all monadic functions are total; an instance of the former, the so called check monad, yielding either success without any further information or an error message; as well as a variant of the sum type that accommodates partial functions by providing an explicit bottom element) and a parser monad built on top. All of this monads are heavily used in the IsaFoR/CeTA project which thus provides many examples of their usage. notify = c.sternagel@gmail.com, rene.thiemann@uibk.ac.at [CISC-Kernel] title = Formal Specification of a Generic Separation Kernel author = Freek Verbeek , Sergey Tverdyshev , Oto Havle , Holger Blasum , Bruno Langenstein , Werner Stephan , Yakoub Nemouchi , Abderrahmane Feliachi , Burkhart Wolff , Julien Schmaltz date = 2014-07-18 topic = Computer science/Security abstract =

Intransitive noninterference has been a widely studied topic in the last few decades. Several well-established methodologies apply interactive theorem proving to formulate a noninterference theorem over abstract academic models. In joint work with several industrial and academic partners throughout Europe, we are helping in the certification process of PikeOS, an industrial separation kernel developed at SYSGO. In this process, established theories could not be applied. We present a new generic model of separation kernels and a new theory of intransitive noninterference. The model is rich in detail, making it suitable for formal verification of realistic and industrial systems such as PikeOS. Using a refinement-based theorem proving approach, we ensure that proofs remain manageable.

This document corresponds to the deliverable D31.1 of the EURO-MILS Project http://www.euromils.eu.

notify = [pGCL] title = pGCL for Isabelle author = David Cock date = 2014-07-13 topic = Computer science/Programming languages/Language definitions abstract =

pGCL is both a programming language and a specification language that incorporates both probabilistic and nondeterministic choice, in a unified manner. Program verification is by refinement or annotation (or both), using either Hoare triples, or weakest-precondition entailment, in the style of GCL.

This package provides both a shallow embedding of the language primitives, and an annotation and refinement framework. The generated document includes a brief tutorial.

notify = [Noninterference_CSP] title = Noninterference Security in Communicating Sequential Processes author = Pasquale Noce date = 2014-05-23 topic = Computer science/Security abstract =

An extension of classical noninterference security for deterministic state machines, as introduced by Goguen and Meseguer and elegantly formalized by Rushby, to nondeterministic systems should satisfy two fundamental requirements: it should be based on a mathematically precise theory of nondeterminism, and should be equivalent to (or at least not weaker than) the classical notion in the degenerate deterministic case.

This paper proposes a definition of noninterference security applying to Hoare's Communicating Sequential Processes (CSP) in the general case of a possibly intransitive noninterference policy, and proves the equivalence of this security property to classical noninterference security for processes representing deterministic state machines.

Furthermore, McCullough's generalized noninterference security is shown to be weaker than both the proposed notion of CSP noninterference security for a generic process, and classical noninterference security for processes representing deterministic state machines. This renders CSP noninterference security preferable as an extension of classical noninterference security to nondeterministic systems.

notify = pasquale.noce.lavoro@gmail.com [Floyd_Warshall] title = The Floyd-Warshall Algorithm for Shortest Paths author = Simon Wimmer , Peter Lammich topic = Computer science/Algorithms/Graph date = 2017-05-08 notify = wimmers@in.tum.de abstract = 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. [Roy_Floyd_Warshall] title = Transitive closure according to Roy-Floyd-Warshall author = Makarius Wenzel <> date = 2014-05-23 topic = Computer science/Algorithms/Graph abstract = This formulation of the Roy-Floyd-Warshall algorithm for the transitive closure bypasses matrices and arrays, but uses a more direct mathematical model with adjacency functions for immediate predecessors and successors. This can be implemented efficiently in functional programming languages and is particularly adequate for sparse relations. notify = [GPU_Kernel_PL] title = Syntax and semantics of a GPU kernel programming language author = John Wickerson date = 2014-04-03 topic = Computer science/Programming languages/Language definitions abstract = This document accompanies the article "The Design and Implementation of a Verification Technique for GPU Kernels" by Adam Betts, Nathan Chong, Alastair F. Donaldson, Jeroen Ketema, Shaz Qadeer, Paul Thomson and John Wickerson. It formalises all of the definitions provided in Sections 3 and 4 of the article. notify = [AWN] title = Mechanization of the Algebra for Wireless Networks (AWN) author = Timothy Bourke date = 2014-03-08 topic = Computer science/Concurrency/Process calculi abstract =

AWN is a process algebra developed for modelling and analysing protocols for Mobile Ad hoc Networks (MANETs) and Wireless Mesh Networks (WMNs). AWN models comprise five distinct layers: sequential processes, local parallel compositions, nodes, partial networks, and complete networks.

This development mechanises the original operational semantics of AWN and introduces a variant 'open' operational semantics that enables the compositional statement and proof of invariants across distinct network nodes. It supports labels (for weakening invariants) and (abstract) data state manipulations. A framework for compositional invariant proofs is developed, including a tactic (inv_cterms) for inductive invariant proofs of sequential processes, lifting rules for the open versions of the higher layers, and a rule for transferring lifted properties back to the standard semantics. A notion of 'control terms' reduces proof obligations to the subset of subterms that act directly (in contrast to operators for combining terms and joining processes).

notify = tim@tbrk.org [Selection_Heap_Sort] title = Verification of Selection and Heap Sort Using Locales author = Danijela Petrovic date = 2014-02-11 topic = Computer science/Algorithms abstract = Stepwise program refinement techniques can be used to simplify program verification. Programs are better understood since their main properties are clearly stated, and verification of rather complex algorithms is reduced to proving simple statements connecting successive program specifications. Additionally, it is easy to analyze similar algorithms and to compare their properties within a single formalization. Usually, formal analysis is not done in educational setting due to complexity of verification and a lack of tools and procedures to make comparison easy. Verification of an algorithm should not only give correctness proof, but also better understanding of an algorithm. If the verification is based on small step program refinement, it can become simple enough to be demonstrated within the university-level computer science curriculum. In this paper we demonstrate this and give a formal analysis of two well known algorithms (Selection Sort and Heap Sort) using proof assistant Isabelle/HOL and program refinement techniques. notify = [Real_Impl] title = Implementing field extensions of the form Q[sqrt(b)] author = René Thiemann date = 2014-02-06 license = LGPL topic = Mathematics/Analysis abstract = We apply data refinement to implement the real numbers, where we support all numbers in the field extension Q[sqrt(b)], i.e., all numbers of the form p + q * sqrt(b) for rational numbers p and q and some fixed natural number b. To this end, we also developed algorithms to precisely compute roots of a rational number, and to perform a factorization of natural numbers which eliminates duplicate prime factors.

Our results have been used to certify termination proofs which involve polynomial interpretations over the reals. extra-history = Change history: [2014-07-11]: Moved NthRoot_Impl to Sqrt-Babylonian. notify = rene.thiemann@uibk.ac.at [ShortestPath] title = An Axiomatic Characterization of the Single-Source Shortest Path Problem author = Christine Rizkallah date = 2013-05-22 topic = Mathematics/Graph theory abstract = This theory is split into two sections. In the first section, we give a formal proof that a well-known axiomatic characterization of the single-source shortest path problem is correct. Namely, we prove that in a directed graph with a non-negative cost function on the edges the single-source shortest path function is the only function that satisfies a set of four axioms. In the second section, we give a formal proof of the correctness of an axiomatic characterization of the single-source shortest path problem for directed graphs with general cost functions. The axioms here are more involved because we have to account for potential negative cycles in the graph. The axioms are summarized in three Isabelle locales. notify = [Launchbury] title = The Correctness of Launchbury's Natural Semantics for Lazy Evaluation author = Joachim Breitner date = 2013-01-31 topic = Computer science/Programming languages/Lambda calculi, Computer science/Semantics abstract = In his seminal paper "Natural Semantics for Lazy Evaluation", John Launchbury proves his semantics correct with respect to a denotational semantics, and outlines an adequacy proof. We have formalized both semantics and machine-checked the correctness proof, clarifying some details. Furthermore, we provide a new and more direct adequacy proof that does not require intermediate operational semantics. extra-history = Change history: [2014-05-24]: Added the proof of adequacy, as well as simplified and improved the existing proofs. Adjusted abstract accordingly. [2015-03-16]: Booleans and if-then-else added to syntax and semantics, making this entry suitable to be used by the entry "Call_Arity". notify = [Call_Arity] title = The Safety of Call Arity author = Joachim Breitner date = 2015-02-20 topic = Computer science/Programming languages/Transformations abstract = We formalize the Call Arity analysis, as implemented in GHC, and prove both functional correctness and, more interestingly, safety (i.e. the transformation does not increase allocation).

We use syntax and the denotational semantics from the entry "Launchbury", where we formalized Launchbury's natural semantics for lazy evaluation.

The functional correctness of Call Arity is proved with regard to that denotational semantics. The operational properties are shown with regard to a small-step semantics akin to Sestoft's mark 1 machine, which we prove to be equivalent to Launchbury's semantics.

We use Christian Urban's Nominal2 package to define our terms and make use of Brian Huffman's HOLCF package for the domain-theoretical aspects of the development. extra-history = Change history: [2015-03-16]: This entry now builds on top of the Launchbury entry, and the equivalency proof of the natural and the small-step semantics was added. notify = [CCS] title = CCS in nominal logic author = Jesper Bengtson date = 2012-05-29 topic = Computer science/Concurrency/Process calculi abstract = We formalise a large portion of CCS as described in Milner's book 'Communication and Concurrency' using the nominal datatype package in Isabelle. Our results include many of the standard theorems of bisimulation equivalence and congruence, for both weak and strong versions. One main goal of this formalisation is to keep the machine-checked proofs as close to their pen-and-paper counterpart as possible.

This entry is described in detail in Bengtson's thesis. notify = [Pi_Calculus] title = The pi-calculus in nominal logic author = Jesper Bengtson date = 2012-05-29 topic = Computer science/Concurrency/Process calculi abstract = We formalise the pi-calculus using the nominal datatype package, based on ideas from the nominal logic by Pitts et al., and demonstrate an implementation in Isabelle/HOL. The purpose is to derive powerful induction rules for the semantics in order to conduct machine checkable proofs, closely following the intuitive arguments found in manual proofs. In this way we have covered many of the standard theorems of bisimulation equivalence and congruence, both late and early, and both strong and weak in a uniform manner. We thus provide one of the most extensive formalisations of a the pi-calculus ever done inside a theorem prover.

A significant gain in our formulation is that agents are identified up to alpha-equivalence, thereby greatly reducing the arguments about bound names. This is a normal strategy for manual proofs about the pi-calculus, but that kind of hand waving has previously been difficult to incorporate smoothly in an interactive theorem prover. We show how the nominal logic formalism and its support in Isabelle accomplishes this and thus significantly reduces the tedium of conducting completely formal proofs. This improves on previous work using weak higher order abstract syntax since we do not need extra assumptions to filter out exotic terms and can keep all arguments within a familiar first-order logic.

This entry is described in detail in Bengtson's thesis. notify = [Psi_Calculi] title = Psi-calculi in Isabelle author = Jesper Bengtson date = 2012-05-29 topic = Computer science/Concurrency/Process calculi abstract = Psi-calculi are extensions of the pi-calculus, accommodating arbitrary nominal datatypes to represent not only data but also communication channels, assertions and conditions, giving it an expressive power beyond the applied pi-calculus and the concurrent constraint pi-calculus.

We have formalised psi-calculi in the interactive theorem prover Isabelle using its nominal datatype package. One distinctive feature is that the framework needs to treat binding sequences, as opposed to single binders, in an efficient way. While different methods for formalising single binder calculi have been proposed over the last decades, representations for such binding sequences are not very well explored.

The main effort in the formalisation is to keep the machine checked proofs as close to their pen-and-paper counterparts as possible. This includes treating all binding sequences as atomic elements, and creating custom induction and inversion rules that to remove the bulk of manual alpha-conversions.

This entry is described in detail in Bengtson's thesis. notify = [Encodability_Process_Calculi] title = Analysing and Comparing Encodability Criteria for Process Calculi author = Kirstin Peters , Rob van Glabbeek date = 2015-08-10 topic = Computer science/Concurrency/Process calculi abstract = Encodings or the proof of their absence are the main way to compare process calculi. To analyse the quality of encodings and to rule out trivial or meaningless encodings, they are augmented with quality criteria. There exists a bunch of different criteria and different variants of criteria in order to reason in different settings. This leads to incomparable results. Moreover it is not always clear whether the criteria used to obtain a result in a particular setting do indeed fit to this setting. We show how to formally reason about and compare encodability criteria by mapping them on requirements on a relation between source and target terms that is induced by the encoding function. In particular we analyse the common criteria full abstraction, operational correspondence, divergence reflection, success sensitiveness, and respect of barbs; e.g. we analyse the exact nature of the simulation relation (coupled simulation versus bisimulation) that is induced by different variants of operational correspondence. This way we reduce the problem of analysing or comparing encodability criteria to the better understood problem of comparing relations on processes. notify = kirstin.peters@tu-berlin.de [Circus] title = Isabelle/Circus author = Abderrahmane Feliachi , Burkhart Wolff , Marie-Claude Gaudel contributors = Makarius Wenzel date = 2012-05-27 topic = Computer science/Concurrency/Process calculi, Computer science/System description languages abstract = The Circus specification language combines elements for complex data and behavior specifications, using an integration of Z and CSP with a refinement calculus. Its semantics is based on Hoare and He's Unifying Theories of Programming (UTP). Isabelle/Circus is a formalization of the UTP and the Circus language in Isabelle/HOL. It contains proof rules and tactic support that allows for proofs of refinement for Circus processes (involving both data and behavioral aspects).

The Isabelle/Circus environment supports a syntax for the semantic definitions which is close to textbook presentations of Circus. This article contains an extended version of corresponding VSTTE Paper together with the complete formal development of its underlying commented theories. extra-history = Change history: [2014-06-05]: More polishing, shorter proofs, added Circus syntax, added Makarius Wenzel as contributor. notify = [Dijkstra_Shortest_Path] title = Dijkstra's Shortest Path Algorithm author = Benedikt Nordhoff , Peter Lammich topic = Computer science/Algorithms/Graph date = 2012-01-30 abstract = We implement and prove correct Dijkstra's algorithm for the single source shortest path problem, conceived in 1956 by E. Dijkstra. The algorithm is implemented using the data refinement framework for monadic, nondeterministic programs. An efficient implementation is derived using data structures from the Isabelle Collection Framework. notify = lammich@in.tum.de [Refine_Monadic] title = Refinement for Monadic Programs author = Peter Lammich topic = Computer science/Programming languages/Logics date = 2012-01-30 abstract = We provide a framework for program and data refinement in Isabelle/HOL. The framework is based on a nondeterminism-monad with assertions, i.e., the monad carries a set of results or an assertion failure. Recursion is expressed by fixed points. For convenience, we also provide while and foreach combinators.

The framework provides tools to automatize canonical tasks, such as verification condition generation, finding appropriate data refinement relations, and refine an executable program to a form that is accepted by the Isabelle/HOL code generator.

This submission comes with a collection of examples and a user-guide, illustrating the usage of the framework. extra-history = Change history: [2012-04-23] Introduced ordered FOREACH loops
[2012-06] New features: REC_rule_arb and RECT_rule_arb allow for generalizing over variables. prepare_code_thms - command extracts code equations for recursion combinators.
[2012-07] New example: Nested DFS for emptiness check of Buchi-automata with witness.
New feature: fo_rule method to apply resolution using first-order matching. Useful for arg_conf, fun_cong.
[2012-08] Adaptation to ICF v2.
[2012-10-05] Adaptations to include support for Automatic Refinement Framework.
[2013-09] This entry now depends on Automatic Refinement
[2014-06] New feature: vc_solve method to solve verification conditions. Maintenace changes: VCG-rules for nfoldli, improved setup for FOREACH-loops.
[2014-07] Now defining recursion via flat domain. Dropped many single-valued prerequisites. Changed notion of data refinement. In single-valued case, this matches the old notion. In non-single valued case, the new notion allows for more convenient rules. In particular, the new definitions allow for projecting away ghost variables as a refinement step.
[2014-11] New features: le-or-fail relation (leof), modular reasoning about loop invariants. notify = lammich@in.tum.de [Refine_Imperative_HOL] title = The Imperative Refinement Framework author = Peter Lammich notify = lammich@in.tum.de date = 2016-08-08 topic = Computer science/Programming languages/Transformations,Computer science/Data structures abstract = We present the Imperative Refinement Framework (IRF), a tool that supports a stepwise refinement based approach to imperative programs. This entry is based on the material we presented in [ITP-2015, CPP-2016]. It uses the Monadic Refinement Framework as a frontend for the specification of the abstract programs, and Imperative/HOL as a backend to generate executable imperative programs. The IRF comes with tool support to synthesize imperative programs from more abstract, functional ones, using efficient imperative implementations for the abstract data structures. This entry also includes the Imperative Isabelle Collection Framework (IICF), which provides a library of re-usable imperative collection data structures. Moreover, this entry contains a quickstart guide and a reference manual, which provide an introduction to using the IRF for Isabelle/HOL experts. It also provids a collection of (partly commented) practical examples, some highlights being Dijkstra's Algorithm, Nested-DFS, and a generic worklist algorithm with subsumption. Finally, this entry contains benchmark scripts that compare the runtime of some examples against reference implementations of the algorithms in Java and C++. [ITP-2015] Peter Lammich: Refinement to Imperative/HOL. ITP 2015: 253--269 [CPP-2016] Peter Lammich: Refinement based verification of imperative data structures. CPP 2016: 27--36 [Automatic_Refinement] title = Automatic Data Refinement author = Peter Lammich topic = Computer science/Programming languages/Logics date = 2013-10-02 abstract = We present the Autoref tool for Isabelle/HOL, which automatically refines algorithms specified over abstract concepts like maps and sets to algorithms over concrete implementations like red-black-trees, and produces a refinement theorem. It is based on ideas borrowed from relational parametricity due to Reynolds and Wadler. The tool allows for rapid prototyping of verified, executable algorithms. Moreover, it can be configured to fine-tune the result to the user~s needs. Our tool is able to automatically instantiate generic algorithms, which greatly simplifies the implementation of executable data structures.

This AFP-entry provides the basic tool, which is then used by the Refinement and Collection Framework to provide automatic data refinement for the nondeterminism monad and various collection datastructures. notify = lammich@in.tum.de [EdmondsKarp_Maxflow] title = Formalizing the Edmonds-Karp Algorithm author = Peter Lammich , S. Reza Sefidgar<> notify = lammich@in.tum.de date = 2016-08-12 topic = Computer science/Algorithms/Graph abstract = We present a formalization of the Ford-Fulkerson method for computing the maximum flow in a network. 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. We then use stepwise refinement to obtain the Edmonds-Karp algorithm, and formally prove a bound on its complexity. Further refinement yields a verified implementation, whose execution time compares well to an unverified reference implementation in Java. This entry is based on our ITP-2016 paper with the same title. [VerifyThis2018] title = VerifyThis 2018 - Polished Isabelle Solutions author = Peter Lammich , Simon Wimmer topic = Computer science/Algorithms date = 2018-04-27 notify = lammich@in.tum.de abstract = VerifyThis 2018 was a program verification competition associated with ETAPS 2018. It was the 7th event in the VerifyThis competition series. In this entry, we present polished and completed versions of our solutions that we created during the competition. [PseudoHoops] title = Pseudo Hoops author = George Georgescu <>, Laurentiu Leustean <>, Viorel Preoteasa topic = Mathematics/Algebra date = 2011-09-22 abstract = Pseudo-hoops are algebraic structures introduced by B. Bosbach under the name of complementary semigroups. In this formalization we prove some properties of pseudo-hoops and we define the basic concepts of filter and normal filter. The lattice of normal filters is isomorphic with the lattice of congruences of a pseudo-hoop. We also study some important classes of pseudo-hoops. Bounded Wajsberg pseudo-hoops are equivalent to pseudo-Wajsberg algebras and bounded basic pseudo-hoops are equivalent to pseudo-BL algebras. Some examples of pseudo-hoops are given in the last section of the formalization. notify = viorel.preoteasa@aalto.fi [MonoBoolTranAlgebra] title = Algebra of Monotonic Boolean Transformers author = Viorel Preoteasa topic = Computer science/Programming languages/Logics date = 2011-09-22 abstract = Algebras of imperative programming languages have been successful in reasoning about programs. In general an algebra of programs is an algebraic structure with programs as elements and with program compositions (sequential composition, choice, skip) as algebra operations. Various versions of these algebras were introduced to model partial correctness, total correctness, refinement, demonic choice, and other aspects. We formalize here an algebra which can be used to model total correctness, refinement, demonic and angelic choice. The basic model of this algebra are monotonic Boolean transformers (monotonic functions from a Boolean algebra to itself). notify = viorel.preoteasa@aalto.fi [LatticeProperties] title = Lattice Properties author = Viorel Preoteasa topic = Mathematics/Order date = 2011-09-22 abstract = This formalization introduces and collects some algebraic structures based on lattices and complete lattices for use in other developments. The structures introduced are modular, and lattice ordered groups. In addition to the results proved for the new lattices, this formalization also introduces theorems about latices and complete lattices in general. extra-history = Change history: [2012-01-05]: Removed the theory about distributive complete lattices which is in the standard library now. Added a theory about well founded and transitive relations and a result about fixpoints in complete lattices and well founded relations. Moved the results about conjunctive and disjunctive functions to a new theory. Removed the syntactic classes for inf and sup which are in the standard library now. notify = viorel.preoteasa@aalto.fi [Impossible_Geometry] title = Proving the Impossibility of Trisecting an Angle and Doubling the Cube author = Ralph Romanos , Lawrence C. Paulson topic = Mathematics/Algebra, Mathematics/Geometry date = 2012-08-05 abstract = Squaring the circle, doubling the cube and trisecting an angle, using a compass and straightedge alone, are classic unsolved problems first posed by the ancient Greeks. All three problems were proved to be impossible in the 19th century. The following document presents the proof of the impossibility of solving the latter two problems using Isabelle/HOL, following a proof by Carrega. The proof uses elementary methods: no Galois theory or field extensions. The set of points constructible using a compass and straightedge is defined inductively. Radical expressions, which involve only square roots and arithmetic of rational numbers, are defined, and we find that all constructive points have radical coordinates. Finally, doubling the cube and trisecting certain angles requires solving certain cubic equations that can be proved to have no rational roots. The Isabelle proofs require a great many detailed calculations. notify = ralph.romanos@student.ecp.fr, lp15@cam.ac.uk [IP_Addresses] title = IP Addresses author = Cornelius Diekmann , Julius Michaelis , Lars Hupel notify = diekmann@net.in.tum.de date = 2016-06-28 topic = Computer science/Networks abstract = This entry contains a definition of IP addresses and a library to work with them. Generic IP addresses are modeled as machine words of arbitrary length. Derived from this generic definition, IPv4 addresses are 32bit machine words, IPv6 addresses are 128bit words. Additionally, IPv4 addresses can be represented in dot-decimal notation and IPv6 addresses in (compressed) colon-separated notation. We support toString functions and parsers for both notations. Sets of IP addresses can be represented with a netmask (e.g. 192.168.0.0/255.255.0.0) or in CIDR notation (e.g. 192.168.0.0/16). To provide executable code for set operations on IP address ranges, the library includes a datatype to work on arbitrary intervals of machine words. [Simple_Firewall] title = Simple Firewall author = Cornelius Diekmann , Julius Michaelis , Maximilian Haslbeck notify = diekmann@net.in.tum.de, max.haslbeck@gmx.de date = 2016-08-24 topic = Computer science/Networks abstract = We present a simple model of a firewall. The firewall can accept or drop a packet and can match on interfaces, IP addresses, protocol, and ports. It was designed to feature nice mathematical properties: The type of match expressions was carefully crafted such that the conjunction of two match expressions is only one match expression. This model is too simplistic to mirror all aspects of the real world. In the upcoming entry "Iptables Semantics", we will translate the Linux firewall iptables to this model. For a fixed service (e.g. ssh, http), we provide an algorithm to compute an overview of the firewall's filtering behavior. The algorithm computes minimal service matrices, i.e. graphs which partition the complete IPv4 and IPv6 address space and visualize the allowed accesses between partitions. For a detailed description, see Verified iptables Firewall Analysis, IFIP Networking 2016. [Iptables_Semantics] title = Iptables Semantics author = Cornelius Diekmann , Lars Hupel notify = diekmann@net.in.tum.de, hupel@in.tum.de date = 2016-09-09 topic = Computer science/Networks abstract = We present a big step semantics of the filtering behavior of the Linux/netfilter iptables firewall. We provide algorithms to simplify complex iptables rulests to a simple firewall model (c.f. AFP entry Simple_Firewall) and to verify spoofing protection of a ruleset. Internally, we embed our semantics into ternary logic, ultimately supporting every iptables match condition by abstracting over unknowns. Using this AFP entry and all entries it depends on, we created an easy-to-use, stand-alone haskell tool called fffuu. The tool does not require any input —except for the iptables-save dump of the analyzed firewall— and presents interesting results about the user's ruleset. Real-Word firewall errors have been uncovered, and the correctness of rulesets has been proved, with the help of our tool. [Routing] title = Routing author = Julius Michaelis , Cornelius Diekmann notify = afp@liftm.de date = 2016-08-31 topic = Computer science/Networks abstract = This entry contains definitions for routing with routing tables/longest prefix matching. A routing table entry is modelled as a record of a prefix match, a metric, an output port, and an optional next hop. A routing table is a list of entries, sorted by prefix length and metric. Additionally, a parser and serializer for the output of the ip-route command, a function to create a relation from output port to corresponding destination IP space, and a model of a Linux-style router are included. [KBPs] title = Knowledge-based programs author = Peter Gammie topic = Computer science/Automata and formal languages date = 2011-05-17 abstract = Knowledge-based programs (KBPs) are a formalism for directly relating agents' knowledge and behaviour. Here we present a general scheme for compiling KBPs to executable automata with a proof of correctness in Isabelle/HOL. We develop the algorithm top-down, using Isabelle's locale mechanism to structure these proofs, and show that two classic examples can be synthesised using Isabelle's code generator. extra-history = Change history: [2012-03-06]: Add some more views and revive the code generation. notify = kleing@cse.unsw.edu.au [Tarskis_Geometry] title = The independence of Tarski's Euclidean axiom author = T. J. M. Makarios topic = Mathematics/Geometry date = 2012-10-30 abstract = Tarski's axioms of plane geometry are formalized and, using the standard real Cartesian model, shown to be consistent. A substantial theory of the projective plane is developed. Building on this theory, the Klein-Beltrami model of the hyperbolic plane is defined and shown to satisfy all of Tarski's axioms except his Euclidean axiom; thus Tarski's Euclidean axiom is shown to be independent of his other axioms of plane geometry.

An earlier version of this work was the subject of the author's MSc thesis, which contains natural-language explanations of some of the more interesting proofs. notify = tjm1983@gmail.com [IsaGeoCoq] title = Tarski's Parallel Postulate implies the 5th Postulate of Euclid, the Postulate of Playfair and the original Parallel Postulate of Euclid author = Roland Coghetto topic = Mathematics/Geometry license = LGPL date = 2021-01-31 notify = roland_coghetto@hotmail.com abstract =

The GeoCoq library contains a formalization of geometry using the Coq proof assistant. It contains both proofs about the foundations of geometry and high-level proofs in the same style as in high school. We port a part of the GeoCoq 2.4.0 library to Isabelle/HOL: more precisely, the files Chap02.v to Chap13_3.v, suma.v as well as the associated definitions and some useful files for the demonstration of certain parallel postulates. The synthetic approach of the demonstrations is directly inspired by those contained in GeoCoq. The names of the lemmas and theorems used are kept as far as possible as well as the definitions.

It should be noted that T.J.M. Makarios has done some proofs in Tarski's Geometry. It uses a definition that does not quite coincide with the definition used in Geocoq and here. Furthermore, corresponding definitions in the Poincaré Disc Model development are not identical to those defined in GeoCoq.

In the last part, it is formalized that, in the neutral/absolute space, the axiom of the parallels of Tarski's system implies the Playfair axiom, the 5th postulate of Euclid and Euclid's original parallel postulate. These proofs, which are not constructive, are directly inspired by Pierre Boutry, Charly Gries, Julien Narboux and Pascal Schreck.

[General-Triangle] title = The General Triangle Is Unique author = Joachim Breitner topic = Mathematics/Geometry date = 2011-04-01 abstract = Some acute-angled triangles are special, e.g. right-angled or isoscele triangles. Some are not of this kind, but, without measuring angles, look as if they were. In that sense, there is exactly one general triangle. This well-known fact is proven here formally. notify = mail@joachim-breitner.de [LightweightJava] title = Lightweight Java author = Rok Strniša , Matthew Parkinson topic = Computer science/Programming languages/Language definitions date = 2011-02-07 abstract = A fully-formalized and extensible minimal imperative fragment of Java. notify = rok@strnisa.com [Lower_Semicontinuous] title = Lower Semicontinuous Functions author = Bogdan Grechuk topic = Mathematics/Analysis date = 2011-01-08 abstract = We define the notions of lower and upper semicontinuity for functions from a metric space to the extended real line. We prove that a function is both lower and upper semicontinuous if and only if it is continuous. We also give several equivalent characterizations of lower semicontinuity. In particular, we prove that a function is lower semicontinuous if and only if its epigraph is a closed set. Also, we introduce the notion of the lower semicontinuous hull of an arbitrary function and prove its basic properties. notify = hoelzl@in.tum.de [RIPEMD-160-SPARK] title = RIPEMD-160 author = Fabian Immler topic = Computer science/Programming languages/Static analysis date = 2011-01-10 abstract = This work presents a verification of an implementation in SPARK/ADA of the cryptographic hash-function RIPEMD-160. A functional specification of RIPEMD-160 is given in Isabelle/HOL. Proofs for the verification conditions generated by the static-analysis toolset of SPARK certify the functional correctness of the implementation. extra-history = Change history: [2015-11-09]: Entry is now obsolete, moved to Isabelle distribution. notify = immler@in.tum.de [Regular-Sets] title = Regular Sets and Expressions author = Alexander Krauss , Tobias Nipkow contributors = Manuel Eberl topic = Computer science/Automata and formal languages date = 2010-05-12 abstract = This is a library of constructions on regular expressions and languages. It provides the operations of concatenation, Kleene star and derivative on languages. Regular expressions and their meaning are defined. An executable equivalence checker for regular expressions is verified; it does not need automata but works directly on regular expressions. By mapping regular expressions to binary relations, an automatic and complete proof method for (in)equalities of binary relations over union, concatenation and (reflexive) transitive closure is obtained.

Extended regular expressions with complement and intersection are also defined and an equivalence checker is provided. extra-history = Change history: [2011-08-26]: Christian Urban added a theory about derivatives and partial derivatives of regular expressions
[2012-05-10]: Tobias Nipkow added extended regular expressions
[2012-05-10]: Tobias Nipkow added equivalence checking with partial derivatives notify = nipkow@in.tum.de, krauss@in.tum.de, christian.urban@kcl.ac.uk [Regex_Equivalence] title = Unified Decision Procedures for Regular Expression Equivalence author = Tobias Nipkow , Dmitriy Traytel topic = Computer science/Automata and formal languages date = 2014-01-30 abstract = We formalize a unified framework for verified decision procedures for regular expression equivalence. Five recently published formalizations of such decision procedures (three based on derivatives, two on marked regular expressions) can be obtained as instances of the framework. We discover that the two approaches based on marked regular expressions, which were previously thought to be the same, are different, and one seems to produce uniformly smaller automata. The common framework makes it possible to compare the performance of the different decision procedures in a meaningful way. The formalization is described in a paper of the same name presented at Interactive Theorem Proving 2014. notify = nipkow@in.tum.de, traytel@in.tum.de [MSO_Regex_Equivalence] title = Decision Procedures for MSO on Words Based on Derivatives of Regular Expressions author = Dmitriy Traytel , Tobias Nipkow topic = Computer science/Automata and formal languages, Logic/General logic/Decidability of theories date = 2014-06-12 abstract = Monadic second-order logic on finite words (MSO) is a decidable yet expressive logic into which many decision problems can be encoded. Since MSO formulas correspond to regular languages, equivalence of MSO formulas can be reduced to the equivalence of some regular structures (e.g. automata). We verify an executable decision procedure for MSO formulas that is not based on automata but on regular expressions.

Decision procedures for regular expression equivalence have been formalized before, usually based on Brzozowski derivatives. Yet, for a straightforward embedding of MSO formulas into regular expressions an extension of regular expressions with a projection operation is required. We prove total correctness and completeness of an equivalence checker for regular expressions extended in that way. We also define a language-preserving translation of formulas into regular expressions with respect to two different semantics of MSO.

The formalization is described in this ICFP 2013 functional pearl. notify = traytel@in.tum.de, nipkow@in.tum.de [Formula_Derivatives] title = Derivatives of Logical Formulas author = Dmitriy Traytel topic = Computer science/Automata and formal languages, Logic/General logic/Decidability of theories date = 2015-05-28 abstract = We formalize new decision procedures for WS1S, M2L(Str), and Presburger Arithmetics. Formulas of these logics denote regular languages. Unlike traditional decision procedures, we do not translate formulas into automata (nor into regular expressions), at least not explicitly. Instead we devise notions of derivatives (inspired by Brzozowski derivatives for regular expressions) that operate on formulas directly and compute a syntactic bisimulation using these derivatives. The treatment of Boolean connectives and quantifiers is uniform for all mentioned logics and is abstracted into a locale. This locale is then instantiated by different atomic formulas and their derivatives (which may differ even for the same logic under different encodings of interpretations as formal words).

The WS1S instance is described in the draft paper A Coalgebraic Decision Procedure for WS1S by the author. notify = traytel@in.tum.de [Myhill-Nerode] title = The Myhill-Nerode Theorem Based on Regular Expressions author = Chunhan Wu <>, Xingyuan Zhang <>, Christian Urban contributors = Manuel Eberl topic = Computer science/Automata and formal languages date = 2011-08-26 abstract = There are many proofs of the Myhill-Nerode theorem using automata. In this library we give a proof entirely based on regular expressions, since regularity of languages can be conveniently defined using regular expressions (it is more painful in HOL to define regularity in terms of automata). We prove the first direction of the Myhill-Nerode theorem by solving equational systems that involve regular expressions. For the second direction we give two proofs: one using tagging-functions and another using partial derivatives. We also establish various closure properties of regular languages. Most details of the theories are described in our ITP 2011 paper. notify = christian.urban@kcl.ac.uk [Universal_Turing_Machine] title = Universal Turing Machine author = Jian Xu<>, Xingyuan Zhang<>, Christian Urban , Sebastiaan J. C. Joosten topic = Logic/Computability, Computer science/Automata and formal languages date = 2019-02-08 notify = sjcjoosten@gmail.com, christian.urban@kcl.ac.uk abstract = We formalise results from computability theory: recursive functions, undecidability of the halting problem, and the existence of a universal Turing machine. This formalisation is the AFP entry corresponding to the paper Mechanising Turing Machines and Computability Theory in Isabelle/HOL, ITP 2013. [CYK] title = A formalisation of the Cocke-Younger-Kasami algorithm author = Maksym Bortin date = 2016-04-27 topic = Computer science/Algorithms, Computer science/Automata and formal languages abstract = The theory provides a formalisation of the Cocke-Younger-Kasami algorithm (CYK for short), an approach to solving the word problem for context-free languages. CYK decides if a word is in the languages generated by a context-free grammar in Chomsky normal form. The formalized algorithm is executable. notify = maksym.bortin@nicta.com.au [Boolean_Expression_Checkers] title = Boolean Expression Checkers author = Tobias Nipkow date = 2014-06-08 topic = Computer science/Algorithms, Logic/General logic/Mechanization of proofs abstract = This entry provides executable checkers for the following properties of boolean expressions: satisfiability, tautology and equivalence. Internally, the checkers operate on binary decision trees and are reasonably efficient (for purely functional algorithms). extra-history = Change history: [2015-09-23]: Salomon Sickert added an interface that does not require the usage of the Boolean formula datatype. Furthermore the general Mapping type is used instead of an association list. notify = nipkow@in.tum.de [Presburger-Automata] title = Formalizing the Logic-Automaton Connection author = Stefan Berghofer , Markus Reiter <> date = 2009-12-03 topic = Computer science/Automata and formal languages, Logic/General logic/Decidability of theories abstract = This work presents a formalization of a library for automata on bit strings. It forms the basis of a reflection-based decision procedure for Presburger arithmetic, which is efficiently executable thanks to Isabelle's code generator. With this work, we therefore provide a mechanized proof of a well-known connection between logic and automata theory. The formalization is also described in a publication [TPHOLs 2009]. notify = berghofe@in.tum.de [Functional-Automata] title = Functional Automata author = Tobias Nipkow date = 2004-03-30 topic = Computer science/Automata and formal languages abstract = This theory defines deterministic and nondeterministic automata in a functional representation: the transition function/relation and the finality predicate are just functions. Hence the state space may be infinite. It is shown how to convert regular expressions into such automata. A scanner (generator) is implemented with the help of functional automata: the scanner chops the input up into longest recognized substrings. Finally we also show how to convert a certain subclass of functional automata (essentially the finite deterministic ones) into regular sets. notify = nipkow@in.tum.de [Statecharts] title = Formalizing Statecharts using Hierarchical Automata author = Steffen Helke , Florian Kammüller topic = Computer science/Automata and formal languages date = 2010-08-08 abstract = We formalize in Isabelle/HOL the abtract syntax and a synchronous step semantics for the specification language Statecharts. The formalization is based on Hierarchical Automata which allow a structural decomposition of Statecharts into Sequential Automata. To support the composition of Statecharts, we introduce calculating operators to construct a Hierarchical Automaton in a stepwise manner. Furthermore, we present a complete semantics of Statecharts including a theory of data spaces, which enables the modelling of racing effects. We also adapt CTL for Statecharts to build a bridge for future combinations with model checking. However the main motivation of this work is to provide a sound and complete basis for reasoning on Statecharts. As a central meta theorem we prove that the well-formedness of a Statechart is preserved by the semantics. notify = nipkow@in.tum.de [Stuttering_Equivalence] title = Stuttering Equivalence author = Stephan Merz topic = Computer science/Automata and formal languages date = 2012-05-07 abstract =

Two omega-sequences are stuttering equivalent if they differ only by finite repetitions of elements. Stuttering equivalence is a fundamental concept in the theory of concurrent and distributed systems. Notably, Lamport argues that refinement notions for such systems should be insensitive to finite stuttering. Peled and Wilke showed that all PLTL (propositional linear-time temporal logic) properties that are insensitive to stuttering equivalence can be expressed without the next-time operator. Stuttering equivalence is also important for certain verification techniques such as partial-order reduction for model checking.

We formalize stuttering equivalence in Isabelle/HOL. Our development relies on the notion of stuttering sampling functions that may skip blocks of identical sequence elements. We also encode PLTL and prove the theorem due to Peled and Wilke.

extra-history = Change history: [2013-01-31]: Added encoding of PLTL and proved Peled and Wilke's theorem. Adjusted abstract accordingly. notify = Stephan.Merz@loria.fr [Coinductive_Languages] title = A Codatatype of Formal Languages author = Dmitriy Traytel topic = Computer science/Automata and formal languages date = 2013-11-15 abstract =

We define formal languages as a codataype of infinite trees branching over the alphabet. Each node in such a tree indicates whether the path to this node constitutes a word inside or outside of the language. This codatatype is isormorphic to the set of lists representation of languages, but caters for definitions by corecursion and proofs by coinduction.

Regular operations on languages are then defined by primitive corecursion. A difficulty arises here, since the standard definitions of concatenation and iteration from the coalgebraic literature are not primitively corecursive-they require guardedness up-to union/concatenation. Without support for up-to corecursion, these operation must be defined as a composition of primitive ones (and proved being equal to the standard definitions). As an exercise in coinduction we also prove the axioms of Kleene algebra for the defined regular operations.

Furthermore, a language for context-free grammars given by productions in Greibach normal form and an initial nonterminal is constructed by primitive corecursion, yielding an executable decision procedure for the word problem without further ado.

notify = traytel@in.tum.de [Tree-Automata] title = Tree Automata author = Peter Lammich date = 2009-11-25 topic = Computer science/Automata and formal languages abstract = This work presents a machine-checked tree automata library for Standard-ML, OCaml and Haskell. The algorithms are efficient by using appropriate data structures like RB-trees. The available algorithms for non-deterministic automata include membership query, reduction, intersection, union, and emptiness check with computation of a witness for non-emptiness. The executable algorithms are derived from less-concrete, non-executable algorithms using data-refinement techniques. The concrete data structures are from the Isabelle Collections Framework. Moreover, this work contains a formalization of the class of tree-regular languages and its closure properties under set operations. notify = peter.lammich@uni-muenster.de, nipkow@in.tum.de [Depth-First-Search] title = Depth First Search author = Toshiaki Nishihara <>, Yasuhiko Minamide <> date = 2004-06-24 topic = Computer science/Algorithms/Graph abstract = Depth-first search of a graph is formalized with recdef. It is shown that it visits all of the reachable nodes from a given list of nodes. Executable ML code of depth-first search is obtained using the code generation feature of Isabelle/HOL. notify = lp15@cam.ac.uk, krauss@in.tum.de [FFT] title = Fast Fourier Transform author = Clemens Ballarin date = 2005-10-12 topic = Computer science/Algorithms/Mathematical abstract = We formalise a functional implementation of the FFT algorithm over the complex numbers, and its inverse. Both are shown equivalent to the usual definitions of these operations through Vandermonde matrices. They are also shown to be inverse to each other, more precisely, that composition of the inverse and the transformation yield the identity up to a scalar. notify = ballarin@in.tum.de [Gauss-Jordan-Elim-Fun] title = Gauss-Jordan Elimination for Matrices Represented as Functions author = Tobias Nipkow date = 2011-08-19 topic = Computer science/Algorithms/Mathematical, Mathematics/Algebra abstract = This theory provides a compact formulation of Gauss-Jordan elimination for matrices represented as functions. Its distinctive feature is succinctness. It is not meant for large computations. notify = nipkow@in.tum.de [UpDown_Scheme] title = Verification of the UpDown Scheme author = Johannes Hölzl date = 2015-01-28 topic = Computer science/Algorithms/Mathematical abstract = The UpDown scheme is a recursive scheme used to compute the stiffness matrix on a special form of sparse grids. Usually, when discretizing a Euclidean space of dimension d we need O(n^d) points, for n points along each dimension. Sparse grids are a hierarchical representation where the number of points is reduced to O(n * log(n)^d). One disadvantage of such sparse grids is that the algorithm now operate recursively in the dimensions and levels of the sparse grid.

The UpDown scheme allows us to compute the stiffness matrix on such a sparse grid. The stiffness matrix represents the influence of each representation function on the L^2 scalar product. For a detailed description see Dirk Pflüger's PhD thesis. This formalization was developed as an interdisciplinary project (IDP) at the Technische Universität München. notify = hoelzl@in.tum.de [GraphMarkingIBP] title = Verification of the Deutsch-Schorr-Waite Graph Marking Algorithm using Data Refinement author = Viorel Preoteasa , Ralph-Johan Back date = 2010-05-28 topic = Computer science/Algorithms/Graph abstract = The verification of the Deutsch-Schorr-Waite graph marking algorithm is used as a benchmark in many formalizations of pointer programs. The main purpose of this mechanization is to show how data refinement of invariant based programs can be used in verifying practical algorithms. The verification starts with an abstract algorithm working on a graph given by a relation next on nodes. Gradually the abstract program is refined into Deutsch-Schorr-Waite graph marking algorithm where only one bit per graph node of additional memory is used for marking. extra-history = Change history: [2012-01-05]: Updated for the new definition of data refinement and the new syntax for demonic and angelic update statements notify = viorel.preoteasa@aalto.fi [Efficient-Mergesort] title = Efficient Mergesort topic = Computer science/Algorithms date = 2011-11-09 author = Christian Sternagel abstract = We provide a formalization of the mergesort algorithm as used in GHC's Data.List module, proving correctness and stability. Furthermore, experimental data suggests that generated (Haskell-)code for this algorithm is much faster than for previous algorithms available in the Isabelle distribution. extra-history = Change history: [2012-10-24]: Added reference to journal article.
[2018-09-17]: Added theory Efficient_Mergesort that works exclusively with the mutual induction schemas generated by the function package.
[2018-09-19]: Added theory Mergesort_Complexity that proves an upper bound on the number of comparisons that are required by mergesort.
[2018-09-19]: Theory Efficient_Mergesort replaces theory Efficient_Sort but keeping the old name Efficient_Sort. [2020-11-20]: Additional theory Natural_Mergesort that developes an efficient mergesort algorithm without key-functions for educational purposes. notify = c.sternagel@gmail.com [SATSolverVerification] title = Formal Verification of Modern SAT Solvers author = Filip Marić date = 2008-07-23 topic = Computer science/Algorithms abstract = This document contains formal correctness proofs of modern SAT solvers. Following (Krstic et al, 2007) and (Nieuwenhuis et al., 2006), solvers are described using state-transition systems. Several different SAT solver descriptions are given and their partial correctness and termination is proved. These include:

  • a solver based on classical DPLL procedure (using only a backtrack-search with unit propagation),
  • a very general solver with backjumping and learning (similar to the description given in (Nieuwenhuis et al., 2006)), and
  • a solver with a specific conflict analysis algorithm (similar to the description given in (Krstic et al., 2007)).
Within the SAT solver correctness proofs, a large number of lemmas about propositional logic and CNF formulae are proved. This theory is self-contained and could be used for further exploring of properties of CNF based SAT algorithms. notify = [Transitive-Closure] title = Executable Transitive Closures of Finite Relations topic = Computer science/Algorithms/Graph date = 2011-03-14 author = Christian Sternagel , René Thiemann license = LGPL abstract = We provide a generic work-list algorithm to compute the transitive closure of finite relations where only successors of newly detected states are generated. This algorithm is then instantiated for lists over arbitrary carriers and red black trees (which are faster but require a linear order on the carrier), respectively. Our formalization was performed as part of the IsaFoR/CeTA project where reflexive transitive closures of large tree automata have to be computed. extra-history = Change history: [2014-09-04] added example simprocs in Finite_Transitive_Closure_Simprocs notify = c.sternagel@gmail.com, rene.thiemann@uibk.ac.at [Transitive-Closure-II] title = Executable Transitive Closures topic = Computer science/Algorithms/Graph date = 2012-02-29 author = René Thiemann license = LGPL abstract =

We provide a generic work-list algorithm to compute the (reflexive-)transitive closure of relations where only successors of newly detected states are generated. In contrast to our previous work, the relations do not have to be finite, but each element must only have finitely many (indirect) successors. Moreover, a subsumption relation can be used instead of pure equality. An executable variant of the algorithm is available where the generic operations are instantiated with list operations.

This formalization was performed as part of the IsaFoR/CeTA project, and it has been used to certify size-change termination proofs where large transitive closures have to be computed.

notify = rene.thiemann@uibk.ac.at [MuchAdoAboutTwo] title = Much Ado About Two author = Sascha Böhme date = 2007-11-06 topic = Computer science/Algorithms abstract = This article is an Isabelle formalisation of a paper with the same title. In a similar way as Knuth's 0-1-principle for sorting algorithms, that paper develops a 0-1-2-principle for parallel prefix computations. notify = boehmes@in.tum.de [DiskPaxos] title = Proving the Correctness of Disk Paxos date = 2005-06-22 author = Mauro Jaskelioff , Stephan Merz topic = Computer science/Algorithms/Distributed abstract = Disk Paxos is an algorithm for building arbitrary fault-tolerant distributed systems. The specification of Disk Paxos has been proved correct informally and tested using the TLC model checker, but up to now, it has never been fully formally verified. In this work we have formally verified its correctness using the Isabelle theorem prover and the HOL logic system, showing that Isabelle is a practical tool for verifying properties of TLA+ specifications. notify = kleing@cse.unsw.edu.au [GenClock] title = Formalization of a Generalized Protocol for Clock Synchronization author = Alwen Tiu date = 2005-06-24 topic = Computer science/Algorithms/Distributed abstract = We formalize the generalized Byzantine fault-tolerant clock synchronization protocol of Schneider. This protocol abstracts from particular algorithms or implementations for clock synchronization. This abstraction includes several assumptions on the behaviors of physical clocks and on general properties of concrete algorithms/implementations. Based on these assumptions the correctness of the protocol is proved by Schneider. His proof was later verified by Shankar using the theorem prover EHDM (precursor to PVS). Our formalization in Isabelle/HOL is based on Shankar's formalization. notify = kleing@cse.unsw.edu.au [ClockSynchInst] title = Instances of Schneider's generalized protocol of clock synchronization author = Damián Barsotti date = 2006-03-15 topic = Computer science/Algorithms/Distributed abstract = F. B. Schneider ("Understanding protocols for Byzantine clock synchronization") generalizes a number of protocols for Byzantine fault-tolerant clock synchronization and presents a uniform proof for their correctness. In Schneider's schema, each processor maintains a local clock by periodically adjusting each value to one computed by a convergence function applied to the readings of all the clocks. Then, correctness of an algorithm, i.e. that the readings of two clocks at any time are within a fixed bound of each other, is based upon some conditions on the convergence function. To prove that a particular clock synchronization algorithm is correct it suffices to show that the convergence function used by the algorithm meets Schneider's conditions. Using the theorem prover Isabelle, we formalize the proofs that the convergence functions of two algorithms, namely, the Interactive Convergence Algorithm (ICA) of Lamport and Melliar-Smith and the Fault-tolerant Midpoint algorithm of Lundelius-Lynch, meet Schneider's conditions. Furthermore, we experiment on handling some parts of the proofs with fully automatic tools like ICS and CVC-lite. These theories are part of a joint work with Alwen Tiu and Leonor P. Nieto "Verification of Clock Synchronization Algorithms: Experiments on a combination of deductive tools" in proceedings of AVOCS 2005. In this work the correctness of Schneider schema was also verified using Isabelle (entry GenClock in AFP). notify = kleing@cse.unsw.edu.au [Heard_Of] title = Verifying Fault-Tolerant Distributed Algorithms in the Heard-Of Model date = 2012-07-27 author = Henri Debrat , Stephan Merz topic = Computer science/Algorithms/Distributed abstract = Distributed computing is inherently based on replication, promising increased tolerance to failures of individual computing nodes or communication channels. Realizing this promise, however, involves quite subtle algorithmic mechanisms, and requires precise statements about the kinds and numbers of faults that an algorithm tolerates (such as process crashes, communication faults or corrupted values). The landmark theorem due to Fischer, Lynch, and Paterson shows that it is impossible to achieve Consensus among N asynchronously communicating nodes in the presence of even a single permanent failure. Existing solutions must rely on assumptions of "partial synchrony".

Indeed, there have been numerous misunderstandings on what exactly a given algorithm is supposed to realize in what kinds of environments. Moreover, the abundance of subtly different computational models complicates comparisons between different algorithms. Charron-Bost and Schiper introduced the Heard-Of model for representing algorithms and failure assumptions in a uniform framework, simplifying comparisons between algorithms.

In this contribution, we represent the Heard-Of model in Isabelle/HOL. We define two semantics of runs of algorithms with different unit of atomicity and relate these through a reduction theorem that allows us to verify algorithms in the coarse-grained semantics (where proofs are easier) and infer their correctness for the fine-grained one (which corresponds to actual executions). We instantiate the framework by verifying six Consensus algorithms that differ in the underlying algorithmic mechanisms and the kinds of faults they tolerate. notify = Stephan.Merz@loria.fr [Consensus_Refined] title = Consensus Refined date = 2015-03-18 author = Ognjen Maric <>, Christoph Sprenger topic = Computer science/Algorithms/Distributed abstract = Algorithms for solving the consensus problem are fundamental to distributed computing. Despite their brevity, their ability to operate in concurrent, asynchronous and failure-prone environments comes at the cost of complex and subtle behaviors. Accordingly, understanding how they work and proving their correctness is a non-trivial endeavor where abstraction is immensely helpful. Moreover, research on consensus has yielded a large number of algorithms, many of which appear to share common algorithmic ideas. A natural question is whether and how these similarities can be distilled and described in a precise, unified way. In this work, we combine stepwise refinement and lockstep models to provide an abstract and unified view of a sizeable family of consensus algorithms. Our models provide insights into the design choices underlying the different algorithms, and classify them based on those choices. notify = sprenger@inf.ethz.ch [Key_Agreement_Strong_Adversaries] title = Refining Authenticated Key Agreement with Strong Adversaries author = Joseph Lallemand , Christoph Sprenger topic = Computer science/Security license = LGPL date = 2017-01-31 notify = joseph.lallemand@loria.fr, sprenger@inf.ethz.ch abstract = 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. [Security_Protocol_Refinement] title = Developing Security Protocols by Refinement author = Christoph Sprenger , Ivano Somaini<> topic = Computer science/Security license = LGPL date = 2017-05-24 notify = sprenger@inf.ethz.ch abstract = 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. [Abortable_Linearizable_Modules] title = Abortable Linearizable Modules author = Rachid Guerraoui , Viktor Kuncak , Giuliano Losa date = 2012-03-01 topic = Computer science/Algorithms/Distributed abstract = We define the Abortable Linearizable Module automaton (ALM for short) and prove its key composition property using the IOA theory of HOLCF. The ALM is at the heart of the Speculative Linearizability framework. This framework simplifies devising correct speculative algorithms by enabling their decomposition into independent modules that can be analyzed and proved correct in isolation. It is particularly useful when working in a distributed environment, where the need to tolerate faults and asynchrony has made current monolithic protocols so intricate that it is no longer tractable to check their correctness. Our theory contains a typical example of a refinement proof in the I/O-automata framework of Lynch and Tuttle. notify = giuliano@losa.fr, nipkow@in.tum.de [Amortized_Complexity] title = Amortized Complexity Verified author = Tobias Nipkow date = 2014-07-07 topic = Computer science/Data structures abstract = A framework for the analysis of the amortized complexity of functional data structures is formalized in Isabelle/HOL and applied to a number of standard examples and to the folowing non-trivial ones: skew heaps, splay trees, splay heaps and pairing heaps.

A preliminary version of this work (without pairing heaps) is described in a paper published in the proceedings of the conference on Interactive Theorem Proving ITP 2015. An extended version of this publication is available here. extra-history = Change history: [2015-03-17]: Added pairing heaps by Hauke Brinkop.
[2016-07-12]: Moved splay heaps from here to Splay_Tree
[2016-07-14]: Moved pairing heaps from here to the new Pairing_Heap notify = nipkow@in.tum.de [Dynamic_Tables] title = Parameterized Dynamic Tables author = Tobias Nipkow date = 2015-06-07 topic = Computer science/Data structures abstract = This article formalizes the amortized analysis of dynamic tables parameterized with their minimal and maximal load factors and the expansion and contraction factors.

A full description is found in a companion paper. notify = nipkow@in.tum.de [AVL-Trees] title = AVL Trees author = Tobias Nipkow , Cornelia Pusch <> date = 2004-03-19 topic = Computer science/Data structures abstract = Two formalizations of AVL trees with room for extensions. The first formalization is monolithic and shorter, the second one in two stages, longer and a bit simpler. The final implementation is the same. If you are interested in developing this further, please contact gerwin.klein@nicta.com.au. extra-history = Change history: [2011-04-11]: Ondrej Kuncar added delete function notify = kleing@cse.unsw.edu.au [BDD] title = BDD Normalisation author = Veronika Ortner <>, Norbert Schirmer <> date = 2008-02-29 topic = Computer science/Data structures abstract = We present the verification of the normalisation of a binary decision diagram (BDD). The normalisation follows the original algorithm presented by Bryant in 1986 and transforms an ordered BDD in a reduced, ordered and shared BDD. The verification is based on Hoare logics. notify = kleing@cse.unsw.edu.au, norbert.schirmer@web.de [BinarySearchTree] title = Binary Search Trees author = Viktor Kuncak date = 2004-04-05 topic = Computer science/Data structures abstract = The correctness is shown of binary search tree operations (lookup, insert and remove) implementing a set. Two versions are given, for both structured and linear (tactic-style) proofs. An implementation of integer-indexed maps is also verified. notify = lp15@cam.ac.uk [Splay_Tree] title = Splay Tree author = Tobias Nipkow notify = nipkow@in.tum.de date = 2014-08-12 topic = Computer science/Data structures abstract = Splay trees are self-adjusting binary search trees which were invented by Sleator and Tarjan [JACM 1985]. This entry provides executable and verified functional splay trees as well as the related splay heaps (due to Okasaki).

The amortized complexity of splay trees and heaps is analyzed in the AFP entry Amortized Complexity. extra-history = Change history: [2016-07-12]: Moved splay heaps here from Amortized_Complexity [Root_Balanced_Tree] title = Root-Balanced Tree author = Tobias Nipkow notify = nipkow@in.tum.de date = 2017-08-20 topic = Computer science/Data structures abstract =

Andersson introduced general balanced trees, search trees based on the design principle of partial rebuilding: perform update operations naively until the tree becomes too unbalanced, at which point a whole subtree is rebalanced. This article defines and analyzes a functional version of general balanced trees, which we call root-balanced trees. Using a lightweight model of execution time, amortized logarithmic complexity is verified in the theorem prover Isabelle.

This is the Isabelle formalization of the material decribed in the APLAS 2017 article Verified Root-Balanced Trees by the same author, which also presents experimental results that show competitiveness of root-balanced with AVL and red-black trees.

[Skew_Heap] title = Skew Heap author = Tobias Nipkow date = 2014-08-13 topic = Computer science/Data structures abstract = Skew heaps are an amazingly simple and lightweight implementation of priority queues. They were invented by Sleator and Tarjan [SIAM 1986] and have logarithmic amortized complexity. This entry provides executable and verified functional skew heaps.

The amortized complexity of skew heaps is analyzed in the AFP entry Amortized Complexity. notify = nipkow@in.tum.de [Pairing_Heap] title = Pairing Heap author = Hauke Brinkop , Tobias Nipkow date = 2016-07-14 topic = Computer science/Data structures abstract = This library defines three different versions of pairing heaps: a functional version of the original design based on binary trees [Fredman et al. 1986], the version by Okasaki [1998] and a modified version of the latter that is free of structural invariants.

The amortized complexity of pairing heaps is analyzed in the AFP article Amortized Complexity. extra-0 = Origin: This library was extracted from Amortized Complexity and extended. notify = nipkow@in.tum.de [Priority_Queue_Braun] title = Priority Queues Based on Braun Trees author = Tobias Nipkow date = 2014-09-04 topic = Computer science/Data structures abstract = This entry verifies priority queues based on Braun trees. Insertion and deletion take logarithmic time and preserve the balanced nature of Braun trees. Two implementations of deletion are provided. notify = nipkow@in.tum.de extra-history = Change history: [2019-12-16]: Added theory Priority_Queue_Braun2 with second version of del_min [Binomial-Queues] title = Functional Binomial Queues author = René Neumann date = 2010-10-28 topic = Computer science/Data structures abstract = Priority queues are an important data structure and efficient implementations of them are crucial. We implement a functional variant of binomial queues in Isabelle/HOL and show its functional correctness. A verification against an abstract reference specification of priority queues has also been attempted, but could not be achieved to the full extent. notify = florian.haftmann@informatik.tu-muenchen.de [Binomial-Heaps] title = Binomial Heaps and Skew Binomial Heaps author = Rene Meis , Finn Nielsen , Peter Lammich date = 2010-10-28 topic = Computer science/Data structures abstract = We implement and prove correct binomial heaps and skew binomial heaps. Both are data-structures for priority queues. While binomial heaps have logarithmic findMin, deleteMin, insert, and meld operations, skew binomial heaps have constant time findMin, insert, and meld operations, and only the deleteMin-operation is logarithmic. This is achieved by using skew links to avoid cascading linking on insert-operations, and data-structural bootstrapping to get constant-time findMin and meld operations. Our implementation follows the paper by Brodal and Okasaki. notify = peter.lammich@uni-muenster.de [Finger-Trees] title = Finger Trees author = Benedikt Nordhoff , Stefan Körner , Peter Lammich date = 2010-10-28 topic = Computer science/Data structures abstract = We implement and prove correct 2-3 finger trees. Finger trees are a general purpose data structure, that can be used to efficiently implement other data structures, such as priority queues. Intuitively, a finger tree is an annotated sequence, where the annotations are elements of a monoid. Apart from operations to access the ends of the sequence, the main operation is to split the sequence at the point where a monotone predicate over the sum of the left part of the sequence becomes true for the first time. The implementation follows the paper of Hinze and Paterson. The code generator can be used to get efficient, verified code. notify = peter.lammich@uni-muenster.de [Trie] title = Trie author = Andreas Lochbihler , Tobias Nipkow date = 2015-03-30 topic = Computer science/Data structures abstract = This article formalizes the ``trie'' data structure invented by Fredkin [CACM 1960]. It also provides a specialization where the entries in the trie are lists. extra-0 = Origin: This article was extracted from existing articles by the authors. notify = nipkow@in.tum.de [FinFun] title = Code Generation for Functions as Data author = Andreas Lochbihler date = 2009-05-06 topic = Computer science/Data structures abstract = FinFuns are total functions that are constant except for a finite set of points, i.e. a generalisation of finite maps. They are formalised as a new type in Isabelle/HOL such that the code generator can handle equality tests and quantification on FinFuns. On the code output level, FinFuns are explicitly represented by constant functions and pointwise updates, similarly to associative lists. Inside the logic, they behave like ordinary functions with extensionality. Via the update/constant pattern, a recursion combinator and an induction rule for FinFuns allow for defining and reasoning about operators on FinFun that are also executable. extra-history = Change history: [2010-08-13]: new concept domain of a FinFun as a FinFun (revision 34b3517cbc09)
[2010-11-04]: new conversion function from FinFun to list of elements in the domain (revision 0c167102e6ed)
[2012-03-07]: replace sets as FinFuns by predicates as FinFuns because the set type constructor has been reintroduced (revision b7aa87989f3a) notify = nipkow@in.tum.de [Collections] title = Collections Framework author = Peter Lammich contributors = Andreas Lochbihler , Thomas Tuerk <> date = 2009-11-25 topic = Computer science/Data structures abstract = This development provides an efficient, extensible, machine checked collections framework. The library adopts the concepts of interface, implementation and generic algorithm from object-oriented programming and implements them in Isabelle/HOL. The framework features the use of data refinement techniques to refine an abstract specification (using high-level concepts like sets) to a more concrete implementation (using collection datastructures, like red-black-trees). The code-generator of Isabelle/HOL can be used to generate efficient code. extra-history = Change history: [2010-10-08]: New Interfaces: OrderedSet, OrderedMap, List. Fifo now implements list-interface: Function names changed: put/get --> enqueue/dequeue. New Implementations: ArrayList, ArrayHashMap, ArrayHashSet, TrieMap, TrieSet. Invariant-free datastructures: Invariant implicitely hidden in typedef. Record-interfaces: All operations of an interface encapsulated as record. Examples moved to examples subdirectory.
[2010-12-01]: New Interfaces: Priority Queues, Annotated Lists. Implemented by finger trees, (skew) binomial queues.
[2011-10-10]: SetSpec: Added operations: sng, isSng, bexists, size_abort, diff, filter, iterate_rule_insertP MapSpec: Added operations: sng, isSng, iterate_rule_insertP, bexists, size, size_abort, restrict, map_image_filter, map_value_image_filter Some maintenance changes
[2012-04-25]: New iterator foundation by Tuerk. Various maintenance changes.
[2012-08]: Collections V2. New features: Polymorphic iterators. Generic algorithm instantiation where required. Naming scheme changed from xx_opname to xx.opname. A compatibility file CollectionsV1 tries to simplify porting of existing theories, by providing old naming scheme and the old monomorphic iterator locales.
[2013-09]: Added Generic Collection Framework based on Autoref. The GenCF provides: Arbitrary nesting, full integration with Autoref.
[2014-06]: Maintenace changes to GenCF: Optimized inj_image on list_set. op_set_cart (Cartesian product). big-Union operation. atLeastLessThan - operation ({a..<b})
notify = lammich@in.tum.de [Containers] title = Light-weight Containers author = Andreas Lochbihler contributors = René Thiemann date = 2013-04-15 topic = Computer science/Data structures abstract = This development provides a framework for container types like sets and maps such that generated code implements these containers with different (efficient) data structures. Thanks to type classes and refinement during code generation, this light-weight approach can seamlessly replace Isabelle's default setup for code generation. Heuristics automatically pick one of the available data structures depending on the type of elements to be stored, but users can also choose on their own. The extensible design permits to add more implementations at any time.

To support arbitrary nesting of sets, we define a linear order on sets based on a linear order of the elements and provide efficient implementations. It even allows to compare complements with non-complements. extra-history = Change history: [2013-07-11]: add pretty printing for sets (revision 7f3f52c5f5fa)
[2013-09-20]: provide generators for canonical type class instantiations (revision 159f4401f4a8 by René Thiemann)
[2014-07-08]: add support for going from partial functions to mappings (revision 7a6fc957e8ed)
[2018-03-05]: add two application examples: depth-first search and 2SAT (revision e5e1a1da2411) notify = mail@andreas-lochbihler.de [FileRefinement] title = File Refinement author = Karen Zee , Viktor Kuncak date = 2004-12-09 topic = Computer science/Data structures abstract = These theories illustrates the verification of basic file operations (file creation, file read and file write) in the Isabelle theorem prover. We describe a file at two levels of abstraction: an abstract file represented as a resizable array, and a concrete file represented using data blocks. notify = kkz@mit.edu [Datatype_Order_Generator] title = Generating linear orders for datatypes author = René Thiemann date = 2012-08-07 topic = Computer science/Data structures abstract = We provide a framework for registering automatic methods to derive class instances of datatypes, as it is possible using Haskell's ``deriving Ord, Show, ...'' feature.

We further implemented such automatic methods to derive (linear) orders or hash-functions which are required in the Isabelle Collection Framework. Moreover, for the tactic of Huffman and Krauss to show that a datatype is countable, we implemented a wrapper so that this tactic becomes accessible in our framework.

Our formalization was performed as part of the IsaFoR/CeTA project. With our new tactic we could completely remove tedious proofs for linear orders of two datatypes.

This development is aimed at datatypes generated by the "old_datatype" command. notify = rene.thiemann@uibk.ac.at [Deriving] title = Deriving class instances for datatypes author = Christian Sternagel , René Thiemann date = 2015-03-11 topic = Computer science/Data structures abstract =

We provide a framework for registering automatic methods to derive class instances of datatypes, as it is possible using Haskell's ``deriving Ord, Show, ...'' feature.

We further implemented such automatic methods to derive comparators, linear orders, parametrizable equality functions, and hash-functions which are required in the Isabelle Collection Framework and the Container Framework. Moreover, for the tactic of Blanchette to show that a datatype is countable, we implemented a wrapper so that this tactic becomes accessible in our framework. All of the generators are based on the infrastructure that is provided by the BNF-based datatype package.

Our formalization was performed as part of the IsaFoR/CeTA project. With our new tactics we could remove several tedious proofs for (conditional) linear orders, and conditional equality operators within IsaFoR and the Container Framework.

notify = rene.thiemann@uibk.ac.at [List-Index] title = List Index date = 2010-02-20 author = Tobias Nipkow topic = Computer science/Data structures abstract = This theory provides functions for finding the index of an element in a list, by predicate and by value. notify = nipkow@in.tum.de [List-Infinite] title = Infinite Lists date = 2011-02-23 author = David Trachtenherz <> topic = Computer science/Data structures abstract = We introduce a theory of infinite lists in HOL formalized as functions over naturals (folder ListInf, theories ListInf and ListInf_Prefix). It also provides additional results for finite lists (theory ListInf/List2), natural numbers (folder CommonArith, esp. division/modulo, naturals with infinity), sets (folder CommonSet, esp. cutting/truncating sets, traversing sets of naturals). notify = nipkow@in.tum.de [Matrix] title = Executable Matrix Operations on Matrices of Arbitrary Dimensions topic = Computer science/Data structures date = 2010-06-17 author = Christian Sternagel , René Thiemann license = LGPL abstract = We provide the operations of matrix addition, multiplication, transposition, and matrix comparisons as executable functions over ordered semirings. Moreover, it is proven that strongly normalizing (monotone) orders can be lifted to strongly normalizing (monotone) orders over matrices. We further show that the standard semirings over the naturals, integers, and rationals, as well as the arctic semirings satisfy the axioms that are required by our matrix theory. Our formalization is part of the CeTA system which contains several termination techniques. The provided theories have been essential to formalize matrix-interpretations and arctic interpretations. extra-history = Change history: [2010-09-17]: Moved theory on arbitrary (ordered) semirings to Abstract Rewriting. notify = rene.thiemann@uibk.ac.at, christian.sternagel@uibk.ac.at [Matrix_Tensor] title = Tensor Product of Matrices topic = Computer science/Data structures, Mathematics/Algebra date = 2016-01-18 author = T.V.H. Prathamesh abstract = In this work, the Kronecker tensor product of matrices and the proofs of some of its properties are formalized. Properties which have been formalized include associativity of the tensor product and the mixed-product property. notify = prathamesh@imsc.res.in [Huffman] title = The Textbook Proof of Huffman's Algorithm author = Jasmin Christian Blanchette date = 2008-10-15 topic = Computer science/Data structures abstract = Huffman's algorithm is a procedure for constructing a binary tree with minimum weighted path length. This report presents a formal proof of the correctness of Huffman's algorithm written using Isabelle/HOL. Our proof closely follows the sketches found in standard algorithms textbooks, uncovering a few snags in the process. Another distinguishing feature of our formalization is the use of custom induction rules to help Isabelle's automatic tactics, leading to very short proofs for most of the lemmas. notify = jasmin.blanchette@gmail.com [Partial_Function_MR] title = Mutually Recursive Partial Functions author = René Thiemann topic = Computer science/Functional programming date = 2014-02-18 license = LGPL abstract = We provide a wrapper around the partial-function command that supports mutual recursion. notify = rene.thiemann@uibk.ac.at [Lifting_Definition_Option] title = Lifting Definition Option author = René Thiemann topic = Computer science/Functional programming date = 2014-10-13 license = LGPL abstract = We implemented a command that can be used to easily generate elements of a restricted type {x :: 'a. P x}, provided the definition is of the form f ys = (if check ys then Some(generate ys :: 'a) else None) where ys is a list of variables y1 ... yn and check ys ==> P(generate ys) can be proved.

In principle, such a definition is also directly possible using the lift_definition command. However, then this definition will not be suitable for code-generation. To this end, we automated a more complex construction of Joachim Breitner which is amenable for code-generation, and where the test check ys will only be performed once. In the automation, one auxiliary type is created, and Isabelle's lifting- and transfer-package is invoked several times. notify = rene.thiemann@uibk.ac.at [Coinductive] title = Coinductive topic = Computer science/Functional programming author = Andreas Lochbihler contributors = Johannes Hölzl date = 2010-02-12 abstract = This article collects formalisations of general-purpose coinductive data types and sets. Currently, it contains coinductive natural numbers, coinductive lists, i.e. lazy lists or streams, infinite streams, coinductive terminated lists, coinductive resumptions, a library of operations on coinductive lists, and a version of König's lemma as an application for coinductive lists.
The initial theory was contributed by Paulson and Wenzel. Extensions and other coinductive formalisations of general interest are welcome. extra-history = Change history: [2010-06-10]: coinductive lists: setup for quotient package (revision 015574f3bf3c)
[2010-06-28]: new codatatype terminated lazy lists (revision e12de475c558)
[2010-08-04]: terminated lazy lists: setup for quotient package; more lemmas (revision 6ead626f1d01)
[2010-08-17]: Koenig's lemma as an example application for coinductive lists (revision f81ce373fa96)
[2011-02-01]: lazy implementation of coinductive (terminated) lists for the code generator (revision 6034973dce83)
[2011-07-20]: new codatatype resumption (revision 811364c776c7)
[2012-06-27]: new codatatype stream with operations (with contributions by Peter Gammie) (revision dd789a56473c)
[2013-03-13]: construct codatatypes with the BNF package and adjust the definitions and proofs, setup for lifting and transfer packages (revision f593eda5b2c0)
[2013-09-20]: stream theory uses type and operations from HOL/BNF/Examples/Stream (revision 692809b2b262)
[2014-04-03]: ccpo structure on codatatypes used to define ldrop, ldropWhile, lfilter, lconcat as least fixpoint; ccpo topology on coinductive lists contributed by Johannes Hölzl; added examples (revision 23cd8156bd42)
notify = mail@andreas-lochbihler.de [Stream-Fusion] title = Stream Fusion author = Brian Huffman topic = Computer science/Functional programming date = 2009-04-29 abstract = Stream Fusion is a system for removing intermediate list structures from Haskell programs; it consists of a Haskell library along with several compiler rewrite rules. (The library is available online.)

These theories contain a formalization of much of the Stream Fusion library in HOLCF. Lazy list and stream types are defined, along with coercions between the two types, as well as an equivalence relation for streams that generate the same list. List and stream versions of map, filter, foldr, enumFromTo, append, zipWith, and concatMap are defined, and the stream versions are shown to respect stream equivalence. notify = brianh@cs.pdx.edu [Tycon] title = Type Constructor Classes and Monad Transformers author = Brian Huffman date = 2012-06-26 topic = Computer science/Functional programming abstract = These theories contain a formalization of first class type constructors and axiomatic constructor classes for HOLCF. This work is described in detail in the ICFP 2012 paper Formal Verification of Monad Transformers by the author. The formalization is a revised and updated version of earlier joint work with Matthews and White.

Based on the hierarchy of type classes in Haskell, we define classes for functors, monads, monad-plus, etc. Each one includes all the standard laws as axioms. We also provide a new user command, tycondef, for defining new type constructors in HOLCF. Using tycondef, we instantiate the type class hierarchy with various monads and monad transformers. notify = huffman@in.tum.de [CoreC++] title = CoreC++ author = Daniel Wasserrab date = 2006-05-15 topic = Computer science/Programming languages/Language definitions abstract = We present an operational semantics and type safety proof for multiple inheritance in C++. The semantics models the behavior of method calls, field accesses, and two forms of casts in C++ class hierarchies. For explanations see the OOPSLA 2006 paper by Wasserrab, Nipkow, Snelting and Tip. notify = nipkow@in.tum.de [FeatherweightJava] title = A Theory of Featherweight Java in Isabelle/HOL author = J. Nathan Foster , Dimitrios Vytiniotis date = 2006-03-31 topic = Computer science/Programming languages/Language definitions abstract = We formalize the type system, small-step operational semantics, and type soundness proof for Featherweight Java, a simple object calculus, in Isabelle/HOL. notify = kleing@cse.unsw.edu.au [Jinja] title = Jinja is not Java author = Gerwin Klein , Tobias Nipkow date = 2005-06-01 topic = Computer science/Programming languages/Language definitions abstract = We introduce Jinja, a Java-like programming language with a formal semantics designed to exhibit core features of the Java language architecture. Jinja is a compromise between realism of the language and tractability and clarity of the formal semantics. The following aspects are formalised: a big and a small step operational semantics for Jinja and a proof of their equivalence; a type system and a definite initialisation analysis; a type safety proof of the small step semantics; a virtual machine (JVM), its operational semantics and its type system; a type safety proof for the JVM; a bytecode verifier, i.e. data flow analyser for the JVM; a correctness proof of the bytecode verifier w.r.t. the type system; a compiler and a proof that it preserves semantics and well-typedness. The emphasis of this work is not on particular language features but on providing a unified model of the source language, the virtual machine and the compiler. The whole development has been carried out in the theorem prover Isabelle/HOL. notify = kleing@cse.unsw.edu.au, nipkow@in.tum.de [JinjaThreads] title = Jinja with Threads author = Andreas Lochbihler date = 2007-12-03 topic = Computer science/Programming languages/Language definitions abstract = We extend the Jinja source code semantics by Klein and Nipkow with Java-style arrays and threads. Concurrency is captured in a generic framework semantics for adding concurrency through interleaving to a sequential semantics, which features dynamic thread creation, inter-thread communication via shared memory, lock synchronisation and joins. Also, threads can suspend themselves and be notified by others. We instantiate the framework with the adapted versions of both Jinja source and byte code and show type safety for the multithreaded case. Equally, the compiler from source to byte code is extended, for which we prove weak bisimilarity between the source code small step semantics and the defensive Jinja virtual machine. On top of this, we formalise the JMM and show the DRF guarantee and consistency. For description of the different parts, see Lochbihler's papers at FOOL 2008, ESOP 2010, ITP 2011, and ESOP 2012. extra-history = Change history: [2008-04-23]: added bytecode formalisation with arrays and threads, added thread joins (revision f74a8be156a7)
[2009-04-27]: added verified compiler from source code to bytecode; encapsulate native methods in separate semantics (revision e4f26541e58a)
[2009-11-30]: extended compiler correctness proof to infinite and deadlocking computations (revision e50282397435)
[2010-06-08]: added thread interruption; new abstract memory model with sequential consistency as implementation (revision 0cb9e8dbd78d)
[2010-06-28]: new thread interruption model (revision c0440d0a1177)
[2010-10-15]: preliminary version of the Java memory model for source code (revision 02fee0ef3ca2)
[2010-12-16]: improved version of the Java memory model, also for bytecode executable scheduler for source code semantics (revision 1f41c1842f5a)
[2011-02-02]: simplified code generator setup new random scheduler (revision 3059dafd013f)
[2011-07-21]: new interruption model, generalized JMM proof of DRF guarantee, allow class Object to declare methods and fields, simplified subtyping relation, corrected division and modulo implementation (revision 46e4181ed142)
[2012-02-16]: added example programs (revision bf0b06c8913d)
[2012-11-21]: type safety proof for the Java memory model, allow spurious wake-ups (revision 76063d860ae0)
[2013-05-16]: support for non-deterministic memory allocators (revision cc3344a49ced)
[2017-10-20]: add an atomic compare-and-swap operation for volatile fields (revision a6189b1d6b30)
notify = mail@andreas-lochbihler.de [Locally-Nameless-Sigma] title = Locally Nameless Sigma Calculus author = Ludovic Henrio , Florian Kammüller , Bianca Lutz , Henry Sudhof date = 2010-04-30 topic = Computer science/Programming languages/Language definitions abstract = We present a Theory of Objects based on the original functional sigma-calculus by Abadi and Cardelli but with an additional parameter to methods. We prove confluence of the operational semantics following the outline of Nipkow's proof of confluence for the lambda-calculus reusing his theory Commutation, a generic diamond lemma reduction. We furthermore formalize a simple type system for our sigma-calculus including a proof of type safety. The entire development uses the concept of Locally Nameless representation for binders. We reuse an earlier proof of confluence for a simpler sigma-calculus based on de Bruijn indices and lists to represent objects. notify = nipkow@in.tum.de [Attack_Trees] title = Attack Trees in Isabelle for GDPR compliance of IoT healthcare systems author = Florian Kammueller topic = Computer science/Security date = 2020-04-27 notify = florian.kammuller@gmail.com abstract = In this article, we present a proof theory for Attack Trees. Attack Trees are a well established and useful model for the construction of attacks on systems since they allow a stepwise exploration of high level attacks in application scenarios. Using the expressiveness of Higher Order Logic in Isabelle, we develop a generic theory of Attack Trees with a state-based semantics based on Kripke structures and CTL. The resulting framework allows mechanically supported logic analysis of the meta-theory of the proof calculus of Attack Trees and at the same time the developed proof theory enables application to case studies. A central correctness and completeness result proved in Isabelle establishes a connection between the notion of Attack Tree validity and CTL. The application is illustrated on the example of a healthcare IoT system and GDPR compliance verification. [AutoFocus-Stream] title = AutoFocus Stream Processing for Single-Clocking and Multi-Clocking Semantics author = David Trachtenherz <> date = 2011-02-23 topic = Computer science/Programming languages/Language definitions abstract = We formalize the AutoFocus Semantics (a time-synchronous subset of the Focus formalism) as stream processing functions on finite and infinite message streams represented as finite/infinite lists. The formalization comprises both the conventional single-clocking semantics (uniform global clock for all components and communications channels) and its extension to multi-clocking semantics (internal execution clocking of a component may be a multiple of the external communication clocking). The semantics is defined by generic stream processing functions making it suitable for simulation/code generation in Isabelle/HOL. Furthermore, a number of AutoFocus semantics properties are formalized using definitions from the IntervalLogic theories. notify = nipkow@in.tum.de [FocusStreamsCaseStudies] title = Stream Processing Components: Isabelle/HOL Formalisation and Case Studies author = Maria Spichkova date = 2013-11-14 topic = Computer science/Programming languages/Language definitions abstract = This set of theories presents an Isabelle/HOL formalisation of stream processing components introduced in Focus, a framework for formal specification and development of interactive systems. This is an extended and updated version of the formalisation, which was elaborated within the methodology "Focus on Isabelle". In addition, we also applied the formalisation on three case studies that cover different application areas: process control (Steam Boiler System), data transmission (FlexRay communication protocol), memory and processing components (Automotive-Gateway System). notify = lp15@cam.ac.uk, maria.spichkova@rmit.edu.au [Isabelle_Meta_Model] title = A Meta-Model for the Isabelle API author = Frédéric Tuong , Burkhart Wolff date = 2015-09-16 topic = Computer science/Programming languages/Language definitions abstract = We represent a theory of (a fragment of) Isabelle/HOL in Isabelle/HOL. The purpose of this exercise is to write packages for domain-specific specifications such as class models, B-machines, ..., and generally speaking, any domain-specific languages whose abstract syntax can be defined by a HOL "datatype". On this basis, the Isabelle code-generator can then be used to generate code for global context transformations as well as tactic code.

Consequently the package is geared towards parsing, printing and code-generation to the Isabelle API. It is at the moment not sufficiently rich for doing meta theory on Isabelle itself. Extensions in this direction are possible though.

Moreover, the chosen fragment is fairly rudimentary. However it should be easily adapted to one's needs if a package is written on top of it. The supported API contains types, terms, transformation of global context like definitions and data-type declarations as well as infrastructure for Isar-setups.

This theory is drawn from the Featherweight OCL project where it is used to construct a package for object-oriented data-type theories generated from UML class diagrams. The Featherweight OCL, for example, allows for both the direct execution of compiled tactic code by the Isabelle API as well as the generation of ".thy"-files for debugging purposes.

Gained experience from this project shows that the compiled code is sufficiently efficient for practical purposes while being based on a formal model on which properties of the package can be proven such as termination of certain transformations, correctness, etc. notify = tuong@users.gforge.inria.fr, wolff@lri.fr [Clean] title = Clean - An Abstract Imperative Programming Language and its Theory author = Frédéric Tuong , Burkhart Wolff topic = Computer science/Programming languages, Computer science/Semantics date = 2019-10-04 notify = wolff@lri.fr, ftuong@lri.fr abstract = Clean is based on a simple, abstract execution model for an imperative target language. “Abstract” is understood in contrast to “Concrete Semantics”; alternatively, the term “shallow-style embedding” could be used. It strives for a type-safe notion of program-variables, an incremental construction of the typed state-space, support of incremental verification, and open-world extensibility of new type definitions being intertwined with the program definitions. Clean is based on a “no-frills” state-exception monad with the usual definitions of bind and unit for the compositional glue of state-based computations. Clean offers conditionals and loops supporting C-like control-flow operators such as break and return. The state-space construction is based on the extensible record package. Direct recursion of procedures is supported. Clean’s design strives for extreme simplicity. It is geared towards symbolic execution and proven correct verification tools. The underlying libraries of this package, however, deliberately restrict themselves to the most elementary infrastructure for these tasks. The package is intended to serve as demonstrator semantic backend for Isabelle/C, or for the test-generation techniques. [PCF] title = Logical Relations for PCF author = Peter Gammie date = 2012-07-01 topic = Computer science/Programming languages/Lambda calculi abstract = We apply Andy Pitts's methods of defining relations over domains to several classical results in the literature. We show that the Y combinator coincides with the domain-theoretic fixpoint operator, that parallel-or and the Plotkin existential are not definable in PCF, that the continuation semantics for PCF coincides with the direct semantics, and that our domain-theoretic semantics for PCF is adequate for reasoning about contextual equivalence in an operational semantics. Our version of PCF is untyped and has both strict and non-strict function abstractions. The development is carried out in HOLCF. notify = peteg42@gmail.com [POPLmark-deBruijn] title = POPLmark Challenge Via de Bruijn Indices author = Stefan Berghofer date = 2007-08-02 topic = Computer science/Programming languages/Lambda calculi abstract = We present a solution to the POPLmark challenge designed by Aydemir et al., which has as a goal the formalization of the meta-theory of System F<:. The formalization is carried out in the theorem prover Isabelle/HOL using an encoding based on de Bruijn indices. We start with a relatively simple formalization covering only the basic features of System F<:, and explain how it can be extended to also cover records and more advanced binding constructs. notify = berghofe@in.tum.de [Lam-ml-Normalization] title = Strong Normalization of Moggis's Computational Metalanguage author = Christian Doczkal date = 2010-08-29 topic = Computer science/Programming languages/Lambda calculi abstract = Handling variable binding is one of the main difficulties in formal proofs. In this context, Moggi's computational metalanguage serves as an interesting case study. It features monadic types and a commuting conversion rule that rearranges the binding structure. Lindley and Stark have given an elegant proof of strong normalization for this calculus. The key construction in their proof is a notion of relational TT-lifting, using stacks of elimination contexts to obtain a Girard-Tait style logical relation. I give a formalization of their proof in Isabelle/HOL-Nominal with a particular emphasis on the treatment of bound variables. notify = doczkal@ps.uni-saarland.de, nipkow@in.tum.de [MiniML] title = Mini ML author = Wolfgang Naraschewski <>, Tobias Nipkow date = 2004-03-19 topic = Computer science/Programming languages/Type systems abstract = This theory defines the type inference rules and the type inference algorithm W for MiniML (simply-typed lambda terms with let) due to Milner. It proves the soundness and completeness of W w.r.t. the rules. notify = kleing@cse.unsw.edu.au [Simpl] title = A Sequential Imperative Programming Language Syntax, Semantics, Hoare Logics and Verification Environment author = Norbert Schirmer <> date = 2008-02-29 topic = Computer science/Programming languages/Language definitions, Computer science/Programming languages/Logics license = LGPL abstract = We present the theory of Simpl, a sequential imperative programming language. We introduce its syntax, its semantics (big and small-step operational semantics) and Hoare logics for both partial as well as total correctness. We prove soundness and completeness of the Hoare logic. We integrate and automate the Hoare logic in Isabelle/HOL to obtain a practically usable verification environment for imperative programs. Simpl is independent of a concrete programming language but expressive enough to cover all common language features: mutually recursive procedures, abrupt termination and exceptions, runtime faults, local and global variables, pointers and heap, expressions with side effects, pointers to procedures, partial application and closures, dynamic method invocation and also unbounded nondeterminism. notify = kleing@cse.unsw.edu.au, norbert.schirmer@web.de [Separation_Algebra] title = Separation Algebra author = Gerwin Klein , Rafal Kolanski , Andrew Boyton date = 2012-05-11 topic = Computer science/Programming languages/Logics license = BSD abstract = We present a generic type class implementation of separation algebra for Isabelle/HOL as well as lemmas and generic tactics which can be used directly for any instantiation of the type class.

The ex directory contains example instantiations that include structures such as a heap or virtual memory.

The abstract separation algebra is based upon "Abstract Separation Logic" by Calcagno et al. These theories are also the basis of the ITP 2012 rough diamond "Mechanised Separation Algebra" by the authors.

The aim of this work is to support and significantly reduce the effort for future separation logic developments in Isabelle/HOL by factoring out the part of separation logic that can be treated abstractly once and for all. This includes developing typical default rule sets for reasoning as well as automated tactic support for separation logic. notify = kleing@cse.unsw.edu.au, rafal.kolanski@nicta.com.au [Separation_Logic_Imperative_HOL] title = A Separation Logic Framework for Imperative HOL author = Peter Lammich , Rene Meis date = 2012-11-14 topic = Computer science/Programming languages/Logics license = BSD abstract = We provide a framework for separation-logic based correctness proofs of Imperative HOL programs. Our framework comes with a set of proof methods to automate canonical tasks such as verification condition generation and frame inference. Moreover, we provide a set of examples that show the applicability of our framework. The examples include algorithms on lists, hash-tables, and union-find trees. We also provide abstract interfaces for lists, maps, and sets, that allow to develop generic imperative algorithms and use data-refinement techniques.
As we target Imperative HOL, our programs can be translated to efficiently executable code in various target languages, including ML, OCaml, Haskell, and Scala. notify = lammich@in.tum.de [Inductive_Confidentiality] title = Inductive Study of Confidentiality author = Giampaolo Bella date = 2012-05-02 topic = Computer science/Security abstract = This document contains the full theory files accompanying article Inductive Study of Confidentiality --- for Everyone in Formal Aspects of Computing. They aim at an illustrative and didactic presentation of the Inductive Method of protocol analysis, focusing on the treatment of one of the main goals of security protocols: confidentiality against a threat model. The treatment of confidentiality, which in fact forms a key aspect of all protocol analysis tools, has been found cryptic by many learners of the Inductive Method, hence the motivation for this work. The theory files in this document guide the reader step by step towards design and proof of significant confidentiality theorems. These are developed against two threat models, the standard Dolev-Yao and a more audacious one, the General Attacker, which turns out to be particularly useful also for teaching purposes. notify = giamp@dmi.unict.it [Possibilistic_Noninterference] title = Possibilistic Noninterference author = Andrei Popescu , Johannes Hölzl date = 2012-09-10 topic = Computer science/Security, Computer science/Programming languages/Type systems abstract = We formalize a wide variety of Volpano/Smith-style noninterference notions for a while language with parallel composition. We systematize and classify these notions according to compositionality w.r.t. the language constructs. Compositionality yields sound syntactic criteria (a.k.a. type systems) in a uniform way.

An article about these proofs is published in the proceedings of the conference Certified Programs and Proofs 2012. notify = hoelzl@in.tum.de [SIFUM_Type_Systems] title = A Formalization of Assumptions and Guarantees for Compositional Noninterference author = Sylvia Grewe , Heiko Mantel , Daniel Schoepe date = 2014-04-23 topic = Computer science/Security, Computer science/Programming languages/Type systems abstract = Research in information-flow security aims at developing methods to identify undesired information leaks within programs from private (high) sources to public (low) sinks. For a concurrent system, it is desirable to have compositional analysis methods that allow for analyzing each thread independently and that nevertheless guarantee that the parallel composition of successfully analyzed threads satisfies a global security guarantee. However, such a compositional analysis should not be overly pessimistic about what an environment might do with shared resources. Otherwise, the analysis will reject many intuitively secure programs.

The paper "Assumptions and Guarantees for Compositional Noninterference" by Mantel et. al. presents one solution for this problem: an approach for compositionally reasoning about non-interference in concurrent programs via rely-guarantee-style reasoning. We present an Isabelle/HOL formalization of the concepts and proofs of this approach. notify = [Dependent_SIFUM_Type_Systems] title = A Dependent Security Type System for Concurrent Imperative Programs author = Toby Murray , Robert Sison<>, Edward Pierzchalski<>, Christine Rizkallah notify = toby.murray@unimelb.edu.au date = 2016-06-25 topic = Computer science/Security, Computer science/Programming languages/Type systems abstract = The paper "Compositional Verification and Refinement of Concurrent Value-Dependent Noninterference" by Murray et. al. (CSF 2016) presents a dependent security type system for compositionally verifying a value-dependent noninterference property, defined in (Murray, PLAS 2015), for concurrent programs. This development formalises that security definition, the type system and its soundness proof, and demonstrates its application on some small examples. It was derived from the SIFUM_Type_Systems AFP entry, by Sylvia Grewe, Heiko Mantel and Daniel Schoepe, and whose structure it inherits. extra-history = Change history: [2016-08-19]: Removed unused "stop" parameter and "stop_no_eval" assumption from the sifum_security locale. (revision dbc482d36372) [2016-09-27]: Added security locale support for the imposition of requirements on the initial memory. (revision cce4ceb74ddb) [Dependent_SIFUM_Refinement] title = Compositional Security-Preserving Refinement for Concurrent Imperative Programs author = Toby Murray , Robert Sison<>, Edward Pierzchalski<>, Christine Rizkallah notify = toby.murray@unimelb.edu.au date = 2016-06-28 topic = Computer science/Security abstract = The paper "Compositional Verification and Refinement of Concurrent Value-Dependent Noninterference" by Murray et. al. (CSF 2016) presents a compositional theory of refinement for a value-dependent noninterference property, defined in (Murray, PLAS 2015), for concurrent programs. This development formalises that refinement theory, and demonstrates its application on some small examples. extra-history = Change history: [2016-08-19]: Removed unused "stop" parameters from the sifum_refinement locale. (revision dbc482d36372) [2016-09-02]: TobyM extended "simple" refinement theory to be usable for all bisimulations. (revision 547f31c25f60) [Relational-Incorrectness-Logic] title = An Under-Approximate Relational Logic author = Toby Murray topic = Computer science/Programming languages/Logics, Computer science/Security date = 2020-03-12 notify = toby.murray@unimelb.edu.au abstract = Recently, authors have proposed under-approximate logics for reasoning about programs. So far, all such logics have been confined to reasoning about individual program behaviours. Yet there exist many over-approximate relational logics for reasoning about pairs of programs and relating their behaviours. We present the first under-approximate relational logic, for the simple imperative language IMP. We prove our logic is both sound and complete. Additionally, we show how reasoning in this logic can be decomposed into non-relational reasoning in an under-approximate Hoare logic, mirroring Beringer’s result for over-approximate relational logics. We illustrate the application of our logic on some small examples in which we provably demonstrate the presence of insecurity. [Strong_Security] title = A Formalization of Strong Security author = Sylvia Grewe , Alexander Lux , Heiko Mantel , Jens Sauer date = 2014-04-23 topic = Computer science/Security, Computer science/Programming languages/Type systems abstract = Research in information-flow security aims at developing methods to identify undesired information leaks within programs from private sources to public sinks. Noninterference captures this intuition. Strong security from Sabelfeld and Sands formalizes noninterference for concurrent systems.

We present an Isabelle/HOL formalization of strong security for arbitrary security lattices (Sabelfeld and Sands use a two-element security lattice in the original publication). The formalization includes compositionality proofs for strong security and a soundness proof for a security type system that checks strong security for programs in a simple while language with dynamic thread creation.

Our formalization of the security type system is abstract in the language for expressions and in the semantic side conditions for expressions. It can easily be instantiated with different syntactic approximations for these side conditions. The soundness proof of such an instantiation boils down to showing that these syntactic approximations imply the semantic side conditions. notify = [WHATandWHERE_Security] title = A Formalization of Declassification with WHAT-and-WHERE-Security author = Sylvia Grewe , Alexander Lux , Heiko Mantel , Jens Sauer date = 2014-04-23 topic = Computer science/Security, Computer science/Programming languages/Type systems abstract = Research in information-flow security aims at developing methods to identify undesired information leaks within programs from private sources to public sinks. Noninterference captures this intuition by requiring that no information whatsoever flows from private sources to public sinks. However, in practice this definition is often too strict: Depending on the intuitive desired security policy, the controlled declassification of certain private information (WHAT) at certain points in the program (WHERE) might not result in an undesired information leak.

We present an Isabelle/HOL formalization of such a security property for controlled declassification, namely WHAT&WHERE-security from "Scheduler-Independent Declassification" by Lux, Mantel, and Perner. The formalization includes compositionality proofs for and a soundness proof for a security type system that checks for programs in a simple while language with dynamic thread creation.

Our formalization of the security type system is abstract in the language for expressions and in the semantic side conditions for expressions. It can easily be instantiated with different syntactic approximations for these side conditions. The soundness proof of such an instantiation boils down to showing that these syntactic approximations imply the semantic side conditions.

This Isabelle/HOL formalization uses theories from the entry Strong Security. notify = [VolpanoSmith] title = A Correctness Proof for the Volpano/Smith Security Typing System author = Gregor Snelting , Daniel Wasserrab date = 2008-09-02 topic = Computer science/Programming languages/Type systems, Computer science/Security abstract = The Volpano/Smith/Irvine security type systems requires that variables are annotated as high (secret) or low (public), and provides typing rules which guarantee that secret values cannot leak to public output ports. This property of a program is called confidentiality. For a simple while-language without threads, our proof shows that typeability in the Volpano/Smith system guarantees noninterference. Noninterference means that if two initial states for program execution are low-equivalent, then the final states are low-equivalent as well. This indeed implies that secret values cannot leak to public ports. The proof defines an abstract syntax and operational semantics for programs, formalizes noninterference, and then proceeds by rule induction on the operational semantics. The mathematically most intricate part is the treatment of implicit flows. Note that the Volpano/Smith system is not flow-sensitive and thus quite unprecise, resulting in false alarms. However, due to the correctness property, all potential breaks of confidentiality are discovered. notify = [Abstract-Hoare-Logics] title = Abstract Hoare Logics author = Tobias Nipkow date = 2006-08-08 topic = Computer science/Programming languages/Logics abstract = These therories describe Hoare logics for a number of imperative language constructs, from while-loops to mutually recursive procedures. Both partial and total correctness are treated. In particular a proof system for total correctness of recursive procedures in the presence of unbounded nondeterminism is presented. notify = nipkow@in.tum.de [Stone_Algebras] title = Stone Algebras author = Walter Guttmann notify = walter.guttmann@canterbury.ac.nz date = 2016-09-06 topic = Mathematics/Order abstract = A range of algebras between lattices and Boolean algebras generalise the notion of a complement. We develop a hierarchy of these pseudo-complemented algebras that includes Stone algebras. Independently of this theory we study filters based on partial orders. Both theories are combined to prove Chen and Grätzer's construction theorem for Stone algebras. The latter involves extensive reasoning about algebraic structures in addition to reasoning in algebraic structures. [Kleene_Algebra] title = Kleene Algebra author = Alasdair Armstrong <>, Georg Struth , Tjark Weber date = 2013-01-15 topic = Computer science/Programming languages/Logics, Computer science/Automata and formal languages, Mathematics/Algebra abstract = These files contain a formalisation of variants of Kleene algebras and their most important models as axiomatic type classes in Isabelle/HOL. Kleene algebras are foundational structures in computing with applications ranging from automata and language theory to computational modeling, program construction and verification.

We start with formalising dioids, which are additively idempotent semirings, and expand them by axiomatisations of the Kleene star for finite iteration and an omega operation for infinite iteration. We show that powersets over a given monoid, (regular) languages, sets of paths in a graph, sets of computation traces, binary relations and formal power series form Kleene algebras, and consider further models based on lattices, max-plus semirings and min-plus semirings. We also demonstrate that dioids are closed under the formation of matrices (proofs for Kleene algebras remain to be completed).

On the one hand we have aimed at a reference formalisation of variants of Kleene algebras that covers a wide range of variants and the core theorems in a structured and modular way and provides readable proofs at text book level. On the other hand, we intend to use this algebraic hierarchy and its models as a generic algebraic middle-layer from which programming applications can quickly be explored, implemented and verified. notify = g.struth@sheffield.ac.uk, tjark.weber@it.uu.se [KAT_and_DRA] title = Kleene Algebra with Tests and Demonic Refinement Algebras author = Alasdair Armstrong <>, Victor B. F. Gomes , Georg Struth date = 2014-01-23 topic = Computer science/Programming languages/Logics, Computer science/Automata and formal languages, Mathematics/Algebra abstract = We formalise Kleene algebra with tests (KAT) and demonic refinement algebra (DRA) in Isabelle/HOL. KAT is relevant for program verification and correctness proofs in the partial correctness setting. While DRA targets similar applications in the context of total correctness. Our formalisation contains the two most important models of these algebras: binary relations in the case of KAT and predicate transformers in the case of DRA. In addition, we derive the inference rules for Hoare logic in KAT and its relational model and present a simple formally verified program verification tool prototype based on the algebraic approach. notify = g.struth@dcs.shef.ac.uk [KAD] title = Kleene Algebras with Domain author = Victor B. F. Gomes , Walter Guttmann , Peter Höfner , Georg Struth , Tjark Weber date = 2016-04-12 topic = Computer science/Programming languages/Logics, Computer science/Automata and formal languages, Mathematics/Algebra abstract = Kleene algebras with domain are Kleene algebras endowed with an operation that maps each element of the algebra to its domain of definition (or its complement) in abstract fashion. They form a simple algebraic basis for Hoare logics, dynamic logics or predicate transformer semantics. We formalise a modular hierarchy of algebras with domain and antidomain (domain complement) operations in Isabelle/HOL that ranges from domain and antidomain semigroups to modal Kleene algebras and divergence Kleene algebras. We link these algebras with models of binary relations and program traces. We include some examples from modal logics, termination and program analysis. notify = walter.guttman@canterbury.ac.nz, g.struth@sheffield.ac.uk, tjark.weber@it.uu.se [Regular_Algebras] title = Regular Algebras author = Simon Foster , Georg Struth date = 2014-05-21 topic = Computer science/Automata and formal languages, Mathematics/Algebra abstract = Regular algebras axiomatise the equational theory of regular expressions as induced by regular language identity. We use Isabelle/HOL for a detailed systematic study of regular algebras given by Boffa, Conway, Kozen and Salomaa. We investigate the relationships between these classes, formalise a soundness proof for the smallest class (Salomaa's) and obtain completeness of the largest one (Boffa's) relative to a deep result by Krob. In addition we provide a large collection of regular identities in the general setting of Boffa's axiom. Our regular algebra hierarchy is orthogonal to the Kleene algebra hierarchy in the Archive of Formal Proofs; we have not aimed at an integration for pragmatic reasons. notify = simon.foster@york.ac.uk, g.struth@sheffield.ac.uk [BytecodeLogicJmlTypes] title = A Bytecode Logic for JML and Types author = Lennart Beringer <>, Martin Hofmann date = 2008-12-12 topic = Computer science/Programming languages/Logics abstract = This document contains the Isabelle/HOL sources underlying the paper A bytecode logic for JML and types by Beringer and Hofmann, updated to Isabelle 2008. We present a program logic for a subset of sequential Java bytecode that is suitable for representing both, features found in high-level specification language JML as well as interpretations of high-level type systems. To this end, we introduce a fine-grained collection of assertions, including strong invariants, local annotations and VDM-reminiscent partial-correctness specifications. Thanks to a goal-oriented structure and interpretation of judgements, verification may proceed without recourse to an additional control flow analysis. The suitability for interpreting intensional type systems is illustrated by the proof-carrying-code style encoding of a type system for a first-order functional language which guarantees a constant upper bound on the number of objects allocated throughout an execution, be the execution terminating or non-terminating. Like the published paper, the formal development is restricted to a comparatively small subset of the JVML, lacking (among other features) exceptions, arrays, virtual methods, and static fields. This shortcoming has been overcome meanwhile, as our paper has formed the basis of the Mobius base logic, a program logic for the full sequential fragment of the JVML. Indeed, the present formalisation formed the basis of a subsequent formalisation of the Mobius base logic in the proof assistant Coq, which includes a proof of soundness with respect to the Bicolano operational semantics by Pichardie. notify = [DataRefinementIBP] title = Semantics and Data Refinement of Invariant Based Programs author = Viorel Preoteasa , Ralph-Johan Back date = 2010-05-28 topic = Computer science/Programming languages/Logics abstract = The invariant based programming is a technique of constructing correct programs by first identifying the basic situations (pre- and post-conditions and invariants) that can occur during the execution of the program, and then defining the transitions and proving that they preserve the invariants. Data refinement is a technique of building correct programs working on concrete datatypes as refinements of more abstract programs. In the theories presented here we formalize the predicate transformer semantics for invariant based programs and their data refinement. extra-history = Change history: [2012-01-05]: Moved some general complete lattice properties to the AFP entry Lattice Properties. Changed the definition of the data refinement relation to be more general and updated all corresponding theorems. Added new syntax for demonic and angelic update statements. notify = viorel.preoteasa@aalto.fi [RefinementReactive] title = Formalization of Refinement Calculus for Reactive Systems author = Viorel Preoteasa date = 2014-10-08 topic = Computer science/Programming languages/Logics abstract = We present a formalization of refinement calculus for reactive systems. Refinement calculus is based on monotonic predicate transformers (monotonic functions from sets of post-states to sets of pre-states), and it is a powerful formalism for reasoning about imperative programs. We model reactive systems as monotonic property transformers that transform sets of output infinite sequences into sets of input infinite sequences. Within this semantics we can model refinement of reactive systems, (unbounded) angelic and demonic nondeterminism, sequential composition, and other semantic properties. We can model systems that may fail for some inputs, and we can model compatibility of systems. We can specify systems that have liveness properties using linear temporal logic, and we can refine system specifications into systems based on symbolic transitions systems, suitable for implementations. notify = viorel.preoteasa@aalto.fi [SIFPL] title = Secure information flow and program logics author = Lennart Beringer <>, Martin Hofmann date = 2008-11-10 topic = Computer science/Programming languages/Logics, Computer science/Security abstract = We present interpretations of type systems for secure information flow in Hoare logic, complementing previous encodings in relational program logics. We first treat the imperative language IMP, extended by a simple procedure call mechanism. For this language we consider base-line non-interference in the style of Volpano et al. and the flow-sensitive type system by Hunt and Sands. In both cases, we show how typing derivations may be used to automatically generate proofs in the program logic that certify the absence of illicit flows. We then add instructions for object creation and manipulation, and derive appropriate proof rules for base-line non-interference. As a consequence of our work, standard verification technology may be used for verifying that a concrete program satisfies the non-interference property.

The present proof development represents an update of the formalisation underlying our paper [CSF 2007] and is intended to resolve any ambiguities that may be present in the paper. notify = lennart.beringer@ifi.lmu.de [TLA] title = A Definitional Encoding of TLA* in Isabelle/HOL author = Gudmund Grov , Stephan Merz date = 2011-11-19 topic = Computer science/Programming languages/Logics abstract = We mechanise the logic TLA* [Merz 1999], an extension of Lamport's Temporal Logic of Actions (TLA) [Lamport 1994] for specifying and reasoning about concurrent and reactive systems. Aiming at a framework for mechanising] the verification of TLA (or TLA*) specifications, this contribution reuses some elements from a previous axiomatic encoding of TLA in Isabelle/HOL by the second author [Merz 1998], which has been part of the Isabelle distribution. In contrast to that previous work, we give here a shallow, definitional embedding, with the following highlights:

  • a theory of infinite sequences, including a formalisation of the concepts of stuttering invariance central to TLA and TLA*;
  • a definition of the semantics of TLA*, which extends TLA by a mutually-recursive definition of formulas and pre-formulas, generalising TLA action formulas;
  • a substantial set of derived proof rules, including the TLA* axioms and Lamport's proof rules for system verification;
  • a set of examples illustrating the usage of Isabelle/TLA* for reasoning about systems.
Note that this work is unrelated to the ongoing development of a proof system for the specification language TLA+, which includes an encoding of TLA+ as a new Isabelle object logic [Chaudhuri et al 2010]. notify = ggrov@inf.ed.ac.uk [Compiling-Exceptions-Correctly] title = Compiling Exceptions Correctly author = Tobias Nipkow date = 2004-07-09 topic = Computer science/Programming languages/Compiling abstract = An exception compilation scheme that dynamically creates and removes exception handler entries on the stack. A formalization of an article of the same name by Hutton and Wright. notify = nipkow@in.tum.de [NormByEval] title = Normalization by Evaluation author = Klaus Aehlig , Tobias Nipkow date = 2008-02-18 topic = Computer science/Programming languages/Compiling abstract = This article formalizes normalization by evaluation as implemented in Isabelle. Lambda calculus plus term rewriting is compiled into a functional program with pattern matching. It is proved that the result of a successful evaluation is a) correct, i.e. equivalent to the input, and b) in normal form. notify = nipkow@in.tum.de [Program-Conflict-Analysis] title = Formalization of Conflict Analysis of Programs with Procedures, Thread Creation, and Monitors topic = Computer science/Programming languages/Static analysis author = Peter Lammich , Markus Müller-Olm date = 2007-12-14 abstract = In this work we formally verify the soundness and precision of a static program analysis that detects conflicts (e. g. data races) in programs with procedures, thread creation and monitors with the Isabelle theorem prover. As common in static program analysis, our program model abstracts guarded branching by nondeterministic branching, but completely interprets the call-/return behavior of procedures, synchronization by monitors, and thread creation. The analysis is based on the observation that all conflicts already occur in a class of particularly restricted schedules. These restricted schedules are suited to constraint-system-based program analysis. The formalization is based upon a flowgraph-based program model with an operational semantics as reference point. notify = peter.lammich@uni-muenster.de [Shivers-CFA] title = Shivers' Control Flow Analysis topic = Computer science/Programming languages/Static analysis author = Joachim Breitner date = 2010-11-16 abstract = In his dissertation, Olin Shivers introduces a concept of control flow graphs for functional languages, provides an algorithm to statically derive a safe approximation of the control flow graph and proves this algorithm correct. In this research project, Shivers' algorithms and proofs are formalized in the HOLCF extension of HOL. notify = mail@joachim-breitner.de, nipkow@in.tum.de [Slicing] title = Towards Certified Slicing author = Daniel Wasserrab date = 2008-09-16 topic = Computer science/Programming languages/Static analysis abstract = Slicing is a widely-used technique with applications in e.g. compiler technology and software security. Thus verification of algorithms in these areas is often based on the correctness of slicing, which should ideally be proven independent of concrete programming languages and with the help of well-known verifying techniques such as proof assistants. As a first step in this direction, this contribution presents a framework for dynamic and static intraprocedural slicing based on control flow and program dependence graphs. Abstracting from concrete syntax we base the framework on a graph representation of the program fulfilling certain structural and well-formedness properties.

The formalization consists of the basic framework (in subdirectory Basic/), the correctness proof for dynamic slicing (in subdirectory Dynamic/), the correctness proof for static intraprocedural slicing (in subdirectory StaticIntra/) and instantiations of the framework with a simple While language (in subdirectory While/) and the sophisticated object-oriented bytecode language of Jinja (in subdirectory JinjaVM/). For more information on the framework, see the TPHOLS 2008 paper by Wasserrab and Lochbihler and the PLAS 2009 paper by Wasserrab et al. notify = [HRB-Slicing] title = Backing up Slicing: Verifying the Interprocedural Two-Phase Horwitz-Reps-Binkley Slicer author = Daniel Wasserrab date = 2009-11-13 topic = Computer science/Programming languages/Static analysis abstract = After verifying dynamic and static interprocedural slicing, we present a modular framework for static interprocedural slicing. To this end, we formalized the standard two-phase slicer from Horwitz, Reps and Binkley (see their TOPLAS 12(1) 1990 paper) together with summary edges as presented by Reps et al. (see FSE 1994). The framework is again modular in the programming language by using an abstract CFG, defined via structural and well-formedness properties. Using a weak simulation between the original and sliced graph, we were able to prove the correctness of static interprocedural slicing. We also instantiate our framework with a simple While language with procedures. This shows that the chosen abstractions are indeed valid. notify = nipkow@in.tum.de [WorkerWrapper] title = The Worker/Wrapper Transformation author = Peter Gammie date = 2009-10-30 topic = Computer science/Programming languages/Transformations abstract = Gill and Hutton formalise the worker/wrapper transformation, building on the work of Launchbury and Peyton-Jones who developed it as a way of changing the type at which a recursive function operates. This development establishes the soundness of the technique and several examples of its use. notify = peteg42@gmail.com, nipkow@in.tum.de [JiveDataStoreModel] title = Jive Data and Store Model author = Nicole Rauch , Norbert Schirmer <> date = 2005-06-20 license = LGPL topic = Computer science/Programming languages/Misc abstract = This document presents the formalization of an object-oriented data and store model in Isabelle/HOL. This model is being used in the Java Interactive Verification Environment, Jive. notify = kleing@cse.unsw.edu.au, schirmer@in.tum.de [HotelKeyCards] title = Hotel Key Card System author = Tobias Nipkow date = 2006-09-09 topic = Computer science/Security abstract = Two models of an electronic hotel key card system are contrasted: a state based and a trace based one. Both are defined, verified, and proved equivalent in the theorem prover Isabelle/HOL. It is shown that if a guest follows a certain safety policy regarding her key cards, she can be sure that nobody but her can enter her room. notify = nipkow@in.tum.de [RSAPSS] title = SHA1, RSA, PSS and more author = Christina Lindenberg <>, Kai Wirt <> date = 2005-05-02 topic = Computer science/Security/Cryptography abstract = Formal verification is getting more and more important in computer science. However the state of the art formal verification methods in cryptography are very rudimentary. These theories are one step to provide a tool box allowing the use of formal methods in every aspect of cryptography. Moreover we present a proof of concept for the feasibility of verification techniques to a standard signature algorithm. notify = nipkow@in.tum.de [InformationFlowSlicing] title = Information Flow Noninterference via Slicing author = Daniel Wasserrab date = 2010-03-23 topic = Computer science/Security abstract =

In this contribution, we show how correctness proofs for intra- and interprocedural slicing can be used to prove that slicing is able to guarantee information flow noninterference. Moreover, we also illustrate how to lift the control flow graphs of the respective frameworks such that they fulfil the additional assumptions needed in the noninterference proofs. A detailed description of the intraprocedural proof and its interplay with the slicing framework can be found in the PLAS'09 paper by Wasserrab et al.

This entry contains the part for intra-procedural slicing. See entry InformationFlowSlicing_Inter for the inter-procedural part.

extra-history = Change history: [2016-06-10]: The original entry InformationFlowSlicing contained both the inter- and intra-procedural case was split into two for easier maintenance. notify = [InformationFlowSlicing_Inter] title = Inter-Procedural Information Flow Noninterference via Slicing author = Daniel Wasserrab date = 2010-03-23 topic = Computer science/Security abstract =

In this contribution, we show how correctness proofs for intra- and interprocedural slicing can be used to prove that slicing is able to guarantee information flow noninterference. Moreover, we also illustrate how to lift the control flow graphs of the respective frameworks such that they fulfil the additional assumptions needed in the noninterference proofs. A detailed description of the intraprocedural proof and its interplay with the slicing framework can be found in the PLAS'09 paper by Wasserrab et al.

This entry contains the part for inter-procedural slicing. See entry InformationFlowSlicing for the intra-procedural part.

extra-history = Change history: [2016-06-10]: The original entry InformationFlowSlicing contained both the inter- and intra-procedural case was split into two for easier maintenance. notify = [ComponentDependencies] title = Formalisation and Analysis of Component Dependencies author = Maria Spichkova date = 2014-04-28 topic = Computer science/System description languages abstract = This set of theories presents a formalisation in Isabelle/HOL of data dependencies between components. The approach allows to analyse system structure oriented towards efficient checking of system: it aims at elaborating for a concrete system, which parts of the system are necessary to check a given property. notify = maria.spichkova@rmit.edu.au [Verified-Prover] title = A Mechanically Verified, Efficient, Sound and Complete Theorem Prover For First Order Logic author = Tom Ridge <> date = 2004-09-28 topic = Logic/General logic/Mechanization of proofs abstract = Soundness and completeness for a system of first order logic are formally proved, building on James Margetson's formalization of work by Wainer and Wallen. The completeness proofs naturally suggest an algorithm to derive proofs. This algorithm, which can be implemented tail recursively, is formalized in Isabelle/HOL. The algorithm can be executed via the rewriting tactics of Isabelle. Alternatively, the definitions can be exported to OCaml, yielding a directly executable program. notify = lp15@cam.ac.uk [Completeness] title = Completeness theorem author = James Margetson <>, Tom Ridge <> date = 2004-09-20 topic = Logic/Proof theory abstract = The completeness of first-order logic is proved, following the first five pages of Wainer and Wallen's chapter of the book Proof Theory by Aczel et al., CUP, 1992. Their presentation of formulas allows the proofs to use symmetry arguments. Margetson formalized this theorem by early 2000. The Isar conversion is thanks to Tom Ridge. A paper describing the formalization is available [pdf]. notify = lp15@cam.ac.uk [Ordinal] title = Countable Ordinals author = Brian Huffman date = 2005-11-11 topic = Logic/Set theory abstract = This development defines a well-ordered type of countable ordinals. It includes notions of continuous and normal functions, recursively defined functions over ordinals, least fixed-points, and derivatives. Much of ordinal arithmetic is formalized, including exponentials and logarithms. The development concludes with formalizations of Cantor Normal Form and Veblen hierarchies over normal functions. notify = lcp@cl.cam.ac.uk [Ordinals_and_Cardinals] title = Ordinals and Cardinals author = Andrei Popescu date = 2009-09-01 topic = Logic/Set theory abstract = We develop a basic theory of ordinals and cardinals in Isabelle/HOL, up to the point where some cardinality facts relevant for the ``working mathematician" become available. Unlike in set theory, here we do not have at hand canonical notions of ordinal and cardinal. Therefore, here an ordinal is merely a well-order relation and a cardinal is an ordinal minim w.r.t. order embedding on its field. extra-history = Change history: [2012-09-25]: This entry has been discontinued because it is now part of the Isabelle distribution. notify = uuomul@yahoo.com, nipkow@in.tum.de [FOL-Fitting] title = First-Order Logic According to Fitting author = Stefan Berghofer contributors = Asta Halkjær From date = 2007-08-02 topic = Logic/General logic/Classical first-order logic abstract = We present a formalization of parts of Melvin Fitting's book "First-Order Logic and Automated Theorem Proving". The formalization covers the syntax of first-order logic, its semantics, the model existence theorem, a natural deduction proof calculus together with a proof of correctness and completeness, as well as the Löwenheim-Skolem theorem. extra-history = Change history: [2018-07-21]: Proved completeness theorem for open formulas. Proofs are now written in the declarative style. Enumeration of pairs and datatypes is automated using the Countable theory. notify = berghofe@in.tum.de [Epistemic_Logic] title = Epistemic Logic author = Asta Halkjær From topic = Logic/General logic/Logics of knowledge and belief date = 2018-10-29 notify = ahfrom@dtu.dk abstract = This work is a formalization of epistemic logic with countably many agents. It includes proofs of soundness and completeness for the axiom system K. The completeness proof is based on the textbook "Reasoning About Knowledge" by Fagin, Halpern, Moses and Vardi (MIT Press 1995). [SequentInvertibility] title = Invertibility in Sequent Calculi author = Peter Chapman <> date = 2009-08-28 topic = Logic/Proof theory license = LGPL abstract = The invertibility of the rules of a sequent calculus is important for guiding proof search and can be used in some formalised proofs of Cut admissibility. We present sufficient conditions for when a rule is invertible with respect to a calculus. We illustrate the conditions with examples. It must be noted we give purely syntactic criteria; no guarantees are given as to the suitability of the rules. notify = pc@cs.st-andrews.ac.uk, nipkow@in.tum.de [LinearQuantifierElim] title = Quantifier Elimination for Linear Arithmetic author = Tobias Nipkow date = 2008-01-11 topic = Logic/General logic/Decidability of theories abstract = This article formalizes quantifier elimination procedures for dense linear orders, linear real arithmetic and Presburger arithmetic. In each case both a DNF-based non-elementary algorithm and one or more (doubly) exponential NNF-based algorithms are formalized, including the well-known algorithms by Ferrante and Rackoff and by Cooper. The NNF-based algorithms for dense linear orders are new but based on Ferrante and Rackoff and on an algorithm by Loos and Weisspfenning which simulates infenitesimals. All algorithms are directly executable. In particular, they yield reflective quantifier elimination procedures for HOL itself. The formalization makes heavy use of locales and is therefore highly modular. notify = nipkow@in.tum.de [Nat-Interval-Logic] title = Interval Temporal Logic on Natural Numbers author = David Trachtenherz <> date = 2011-02-23 topic = Logic/General logic/Temporal logic abstract = We introduce a theory of temporal logic operators using sets of natural numbers as time domain, formalized in a shallow embedding manner. The theory comprises special natural intervals (theory IL_Interval: open and closed intervals, continuous and modulo intervals, interval traversing results), operators for shifting intervals to left/right on the number axis as well as expanding/contracting intervals by constant factors (theory IL_IntervalOperators.thy), and ultimately definitions and results for unary and binary temporal operators on arbitrary natural sets (theory IL_TemporalOperators). notify = nipkow@in.tum.de [Recursion-Theory-I] title = Recursion Theory I author = Michael Nedzelsky <> date = 2008-04-05 topic = Logic/Computability abstract = This document presents the formalization of introductory material from recursion theory --- definitions and basic properties of primitive recursive functions, Cantor pairing function and computably enumerable sets (including a proof of existence of a one-complete computably enumerable set and a proof of the Rice's theorem). notify = MichaelNedzelsky@yandex.ru [Free-Boolean-Algebra] topic = Logic/General logic/Classical propositional logic title = Free Boolean Algebra author = Brian Huffman date = 2010-03-29 abstract = This theory defines a type constructor representing the free Boolean algebra over a set of generators. Values of type (α)formula represent propositional formulas with uninterpreted variables from type α, ordered by implication. In addition to all the standard Boolean algebra operations, the library also provides a function for building homomorphisms to any other Boolean algebra type. notify = brianh@cs.pdx.edu [Sort_Encodings] title = Sound and Complete Sort Encodings for First-Order Logic author = Jasmin Christian Blanchette , Andrei Popescu date = 2013-06-27 topic = Logic/General logic/Mechanization of proofs abstract = This is a formalization of the soundness and completeness properties for various efficient encodings of sorts in unsorted first-order logic used by Isabelle's Sledgehammer tool.

Essentially, the encodings proceed as follows: a many-sorted problem is decorated with (as few as possible) tags or guards that make the problem monotonic; then sorts can be soundly erased.

The development employs a formalization of many-sorted first-order logic in clausal form (clauses, structures and the basic properties of the satisfaction relation), which could be of interest as the starting point for other formalizations of first-order logic metatheory. notify = uuomul@yahoo.com [Lambda_Free_RPOs] title = Formalization of Recursive Path Orders for Lambda-Free Higher-Order Terms author = Jasmin Christian Blanchette , Uwe Waldmann , Daniel Wand date = 2016-09-23 topic = Logic/Rewriting abstract = This Isabelle/HOL formalization defines recursive path orders (RPOs) for higher-order terms without lambda-abstraction and proves many useful properties about them. The main order fully coincides with the standard RPO on first-order terms also in the presence of currying, distinguishing it from previous work. An optimized variant is formalized as well. It appears promising as the basis of a higher-order superposition calculus. notify = jasmin.blanchette@gmail.com [Lambda_Free_KBOs] title = Formalization of Knuth–Bendix Orders for Lambda-Free Higher-Order Terms author = Heiko Becker , Jasmin Christian Blanchette , Uwe Waldmann , Daniel Wand date = 2016-11-12 topic = Logic/Rewriting abstract = This Isabelle/HOL formalization defines Knuth–Bendix orders for higher-order terms without lambda-abstraction and proves many useful properties about them. The main order fully coincides with the standard transfinite KBO with subterm coefficients on first-order terms. It appears promising as the basis of a higher-order superposition calculus. notify = jasmin.blanchette@gmail.com [Lambda_Free_EPO] title = Formalization of the Embedding Path Order for Lambda-Free Higher-Order Terms author = Alexander Bentkamp topic = Logic/Rewriting date = 2018-10-19 notify = a.bentkamp@vu.nl abstract = This Isabelle/HOL formalization defines the Embedding Path Order (EPO) for higher-order terms without lambda-abstraction and proves many useful properties about it. In contrast to the lambda-free recursive path orders, it does not fully coincide with RPO on first-order terms, but it is compatible with arbitrary higher-order contexts. [Nested_Multisets_Ordinals] title = Formalization of Nested Multisets, Hereditary Multisets, and Syntactic Ordinals author = Jasmin Christian Blanchette , Mathias Fleury , Dmitriy Traytel date = 2016-11-12 topic = Logic/Rewriting abstract = This Isabelle/HOL formalization introduces a nested multiset datatype and defines Dershowitz and Manna's nested multiset order. The order is proved well founded and linear. By removing one constructor, we transform the nested multisets into hereditary multisets. These are isomorphic to the syntactic ordinals—the ordinals can be recursively expressed in Cantor normal form. Addition, subtraction, multiplication, and linear orders are provided on this type. notify = jasmin.blanchette@gmail.com [Abstract-Rewriting] title = Abstract Rewriting topic = Logic/Rewriting date = 2010-06-14 author = Christian Sternagel , René Thiemann license = LGPL abstract = We present an Isabelle formalization of abstract rewriting (see, e.g., the book by Baader and Nipkow). First, we define standard relations like joinability, meetability, conversion, etc. Then, we formalize important properties of abstract rewrite systems, e.g., confluence and strong normalization. Our main concern is on strong normalization, since this formalization is the basis of CeTA (which is mainly about strong normalization of term rewrite systems). Hence lemmas involving strong normalization constitute by far the biggest part of this theory. One of those is Newman's lemma. extra-history = Change history: [2010-09-17]: Added theories defining several (ordered) semirings related to strong normalization and giving some standard instances.
[2013-10-16]: Generalized delta-orders from rationals to Archimedean fields. notify = christian.sternagel@uibk.ac.at, rene.thiemann@uibk.ac.at [First_Order_Terms] title = First-Order Terms author = Christian Sternagel , René Thiemann topic = Logic/Rewriting, Computer science/Algorithms license = LGPL date = 2018-02-06 notify = c.sternagel@gmail.com, rene.thiemann@uibk.ac.at abstract = We formalize basic results on first-order terms, including matching and a first-order unification algorithm, as well as well-foundedness of the subsumption order. This entry is part of the Isabelle Formalization of Rewriting IsaFoR, where first-order terms are omni-present: the unification algorithm is used to certify several confluence and termination techniques, like critical-pair computation and dependency graph approximations; and the subsumption order is a crucial ingredient for completion. [Free-Groups] title = Free Groups author = Joachim Breitner date = 2010-06-24 topic = Mathematics/Algebra abstract = Free Groups are, in a sense, the most generic kind of group. They are defined over a set of generators with no additional relations in between them. They play an important role in the definition of group presentations and in other fields. This theory provides the definition of Free Group as the set of fully canceled words in the generators. The universal property is proven, as well as some isomorphisms results about Free Groups. extra-history = Change history: [2011-12-11]: Added the Ping Pong Lemma. notify = [CofGroups] title = An Example of a Cofinitary Group in Isabelle/HOL author = Bart Kastermans date = 2009-08-04 topic = Mathematics/Algebra abstract = We formalize the usual proof that the group generated by the function k -> k + 1 on the integers gives rise to a cofinitary group. notify = nipkow@in.tum.de [Group-Ring-Module] title = Groups, Rings and Modules author = Hidetsune Kobayashi <>, L. Chen <>, H. Murao <> date = 2004-05-18 topic = Mathematics/Algebra abstract = The theory of groups, rings and modules is developed to a great depth. Group theory results include Zassenhaus's theorem and the Jordan-Hoelder theorem. The ring theory development includes ideals, quotient rings and the Chinese remainder theorem. The module development includes the Nakayama lemma, exact sequences and Tensor products. notify = lp15@cam.ac.uk [Robbins-Conjecture] title = A Complete Proof of the Robbins Conjecture author = Matthew Wampler-Doty <> date = 2010-05-22 topic = Mathematics/Algebra abstract = This document gives a formalization of the proof of the Robbins conjecture, following A. Mann, A Complete Proof of the Robbins Conjecture, 2003. notify = nipkow@in.tum.de [Valuation] title = Fundamental Properties of Valuation Theory and Hensel's Lemma author = Hidetsune Kobayashi <> date = 2007-08-08 topic = Mathematics/Algebra abstract = Convergence with respect to a valuation is discussed as convergence of a Cauchy sequence. Cauchy sequences of polynomials are defined. They are used to formalize Hensel's lemma. notify = lp15@cam.ac.uk [Rank_Nullity_Theorem] title = Rank-Nullity Theorem in Linear Algebra author = Jose Divasón , Jesús Aransay topic = Mathematics/Algebra date = 2013-01-16 abstract = In this contribution, we present some formalizations based on the HOL-Multivariate-Analysis session of Isabelle. Firstly, a generalization of several theorems of such library are presented. Secondly, some definitions and proofs involving Linear Algebra and the four fundamental subspaces of a matrix are shown. Finally, we present a proof of the result known in Linear Algebra as the ``Rank-Nullity Theorem'', which states that, given any linear map f from a finite dimensional vector space V to a vector space W, then the dimension of V is equal to the dimension of the kernel of f (which is a subspace of V) and the dimension of the range of f (which is a subspace of W). The proof presented here is based on the one given by Sheldon Axler in his book Linear Algebra Done Right. As a corollary of the previous theorem, and taking advantage of the relationship between linear maps and matrices, we prove that, for every matrix A (which has associated a linear map between finite dimensional vector spaces), the sum of its null space and its column space (which is equal to the range of the linear map) is equal to the number of columns of A. extra-history = Change history: [2014-07-14]: Added some generalizations that allow us to formalize the Rank-Nullity Theorem over finite dimensional vector spaces, instead of over the more particular euclidean spaces. Updated abstract. notify = jose.divasonm@unirioja.es, jesus-maria.aransay@unirioja.es [Affine_Arithmetic] title = Affine Arithmetic author = Fabian Immler date = 2014-02-07 topic = Mathematics/Analysis abstract = We give a formalization of affine forms as abstract representations of zonotopes. We provide affine operations as well as overapproximations of some non-affine operations like multiplication and division. Expressions involving those operations can automatically be turned into (executable) functions approximating the original expression in affine arithmetic. extra-history = Change history: [2015-01-31]: added algorithm for zonotope/hyperplane intersection
[2017-09-20]: linear approximations for all symbols from the floatarith data type notify = immler@in.tum.de [Laplace_Transform] title = Laplace Transform author = Fabian Immler topic = Mathematics/Analysis date = 2019-08-14 notify = fimmler@cs.cmu.edu abstract = This entry formalizes the Laplace transform and concrete Laplace transforms for arithmetic functions, frequency shift, integration and (higher) differentiation in the time domain. It proves Lerch's lemma and uniqueness of the Laplace transform for continuous functions. In order to formalize the foundational assumptions, this entry contains a formalization of piecewise continuous functions and functions of exponential order. [Cauchy] title = Cauchy's Mean Theorem and the Cauchy-Schwarz Inequality author = Benjamin Porter <> date = 2006-03-14 topic = Mathematics/Analysis abstract = This document presents the mechanised proofs of two popular theorems attributed to Augustin Louis Cauchy - Cauchy's Mean Theorem and the Cauchy-Schwarz Inequality. notify = kleing@cse.unsw.edu.au [Integration] title = Integration theory and random variables author = Stefan Richter date = 2004-11-19 topic = Mathematics/Analysis abstract = Lebesgue-style integration plays a major role in advanced probability. We formalize concepts of elementary measure theory, real-valued random variables as Borel-measurable functions, and a stepwise inductive definition of the integral itself. All proofs are carried out in human readable style using the Isar language. extra-note = Note: This article is of historical interest only. Lebesgue-style integration and probability theory are now available as part of the Isabelle/HOL distribution (directory Probability). notify = richter@informatik.rwth-aachen.de, nipkow@in.tum.de, hoelzl@in.tum.de [Ordinary_Differential_Equations] title = Ordinary Differential Equations author = Fabian Immler , Johannes Hölzl topic = Mathematics/Analysis date = 2012-04-26 abstract =

Session Ordinary-Differential-Equations formalizes ordinary differential equations (ODEs) and initial value problems. This work comprises proofs for local and global existence of unique solutions (Picard-Lindelöf theorem). Moreover, it contains a formalization of the (continuous or even differentiable) dependency of the flow on initial conditions as the flow of ODEs.

Not in the generated document are the following sessions:

  • HOL-ODE-Numerics: Rigorous numerical algorithms for computing enclosures of solutions based on Runge-Kutta methods and affine arithmetic. Reachability analysis with splitting and reduction at hyperplanes.
  • HOL-ODE-Examples: Applications of the numerical algorithms to concrete systems of ODEs.
  • Lorenz_C0, Lorenz_C1: Verified algorithms for checking C1-information according to Tucker's proof, computation of C0-information.

extra-history = Change history: [2014-02-13]: added an implementation of the Euler method based on affine arithmetic
[2016-04-14]: added flow and variational equation
[2016-08-03]: numerical algorithms for reachability analysis (using second-order Runge-Kutta methods, splitting, and reduction) implemented using Lammich's framework for automatic refinement
[2017-09-20]: added Poincare map and propagation of variational equation in reachability analysis, verified algorithms for C1-information and computations for C0-information of the Lorenz attractor. notify = immler@in.tum.de, hoelzl@in.tum.de [Polynomials] title = Executable Multivariate Polynomials author = Christian Sternagel , René Thiemann , Alexander Maletzky , Fabian Immler , Florian Haftmann , Andreas Lochbihler , Alexander Bentkamp date = 2010-08-10 topic = Mathematics/Analysis, Mathematics/Algebra, Computer science/Algorithms/Mathematical license = LGPL abstract = We define multivariate polynomials over arbitrary (ordered) semirings in combination with (executable) operations like addition, multiplication, and substitution. We also define (weak) monotonicity of polynomials and comparison of polynomials where we provide standard estimations like absolute positiveness or the more recent approach of Neurauter, Zankl, and Middeldorp. Moreover, it is proven that strongly normalizing (monotone) orders can be lifted to strongly normalizing (monotone) orders over polynomials. Our formalization was performed as part of the IsaFoR/CeTA-system which contains several termination techniques. The provided theories have been essential to formalize polynomial interpretations.

This formalization also contains an abstract representation as coefficient functions with finite support and a type of power-products. If this type is ordered by a linear (term) ordering, various additional notions, such as leading power-product, leading coefficient etc., are introduced as well. Furthermore, a lot of generic properties of, and functions on, multivariate polynomials are formalized, including the substitution and evaluation homomorphisms, embeddings of polynomial rings into larger rings (i.e. with one additional indeterminate), homogenization and dehomogenization of polynomials, and the canonical isomorphism between R[X,Y] and R[X][Y]. extra-history = Change history: [2010-09-17]: Moved theories on arbitrary (ordered) semirings to Abstract Rewriting.
[2016-10-28]: Added abstract representation of polynomials and authors Maletzky/Immler.
[2018-01-23]: Added authors Haftmann, Lochbihler after incorporating their formalization of multivariate polynomials based on Polynomial mappings. Moved material from Bentkamp's entry "Deep Learning".
[2019-04-18]: Added material about polynomials whose power-products are represented themselves by polynomial mappings. notify = rene.thiemann@uibk.ac.at, christian.sternagel@uibk.ac.at, alexander.maletzky@risc.jku.at, immler@in.tum.de [Sqrt_Babylonian] title = Computing N-th Roots using the Babylonian Method author = René Thiemann date = 2013-01-03 topic = Mathematics/Analysis license = LGPL abstract = We implement the Babylonian method to compute n-th roots of numbers. We provide precise algorithms for naturals, integers and rationals, and offer an approximation algorithm for square roots over linear ordered fields. Moreover, there are precise algorithms to compute the floor and the ceiling of n-th roots. extra-history = Change history: [2013-10-16]: Added algorithms to compute floor and ceiling of sqrt of integers. [2014-07-11]: Moved NthRoot_Impl from Real-Impl to this entry. notify = rene.thiemann@uibk.ac.at [Sturm_Sequences] title = Sturm's Theorem author = Manuel Eberl date = 2014-01-11 topic = Mathematics/Analysis abstract = Sturm's Theorem states that polynomial sequences with certain properties, so-called Sturm sequences, can be used to count the number of real roots of a real polynomial. This work contains a proof of Sturm's Theorem and code for constructing Sturm sequences efficiently. It also provides the “sturm” proof method, which can decide certain statements about the roots of real polynomials, such as “the polynomial P has exactly n roots in the interval I” or “P(x) > Q(x) for all x ∈ ℝ”. notify = eberlm@in.tum.de [Sturm_Tarski] title = The Sturm-Tarski Theorem author = Wenda Li date = 2014-09-19 topic = Mathematics/Analysis abstract = We have formalized the Sturm-Tarski theorem (also referred as the Tarski theorem), which generalizes Sturm's theorem. Sturm's theorem is usually used as a way to count distinct real roots, while the Sturm-Tarksi theorem forms the basis for Tarski's classic quantifier elimination for real closed field. notify = wl302@cam.ac.uk [Markov_Models] title = Markov Models author = Johannes Hölzl , Tobias Nipkow date = 2012-01-03 topic = Mathematics/Probability theory, Computer science/Automata and formal languages abstract = This is a formalization of Markov models in Isabelle/HOL. It builds on Isabelle's probability theory. The available models are currently Discrete-Time Markov Chains and a extensions of them with rewards.

As application of these models we formalize probabilistic model checking of pCTL formulas, analysis of IPv4 address allocation in ZeroConf and an analysis of the anonymity of the Crowds protocol. See here for the corresponding paper. notify = hoelzl@in.tum.de [Probabilistic_System_Zoo] title = A Zoo of Probabilistic Systems author = Johannes Hölzl , Andreas Lochbihler , Dmitriy Traytel date = 2015-05-27 topic = Computer science/Automata and formal languages abstract = Numerous models of probabilistic systems are studied in the literature. Coalgebra has been used to classify them into system types and compare their expressiveness. We formalize the resulting hierarchy of probabilistic system types by modeling the semantics of the different systems as codatatypes. This approach yields simple and concise proofs, as bisimilarity coincides with equality for codatatypes.

This work is described in detail in the ITP 2015 publication by the authors. notify = traytel@in.tum.de [Density_Compiler] title = A Verified Compiler for Probability Density Functions author = Manuel Eberl , Johannes Hölzl , Tobias Nipkow date = 2014-10-09 topic = Mathematics/Probability theory, Computer science/Programming languages/Compiling abstract = Bhat et al. [TACAS 2013] developed an inductive compiler that computes density functions for probability spaces described by programs in a probabilistic functional language. In this work, we implement such a compiler for a modified version of this language within the theorem prover Isabelle and give a formal proof of its soundness w.r.t. the semantics of the source and target language. Together with Isabelle's code generation for inductive predicates, this yields a fully verified, executable density compiler. The proof is done in two steps: First, an abstract compiler working with abstract functions modelled directly in the theorem prover's logic is defined and proved sound. Then, this compiler is refined to a concrete version that returns a target-language expression.

An article with the same title and authors is published in the proceedings of ESOP 2015. A detailed presentation of this work can be found in the first author's master's thesis. notify = hoelzl@in.tum.de [CAVA_Automata] title = The CAVA Automata Library author = Peter Lammich date = 2014-05-28 topic = Computer science/Automata and formal languages abstract = We report on the graph and automata library that is used in the fully verified LTL model checker CAVA. As most components of CAVA use some type of graphs or automata, a common automata library simplifies assembly of the components and reduces redundancy.

The CAVA Automata Library provides a hierarchy of graph and automata classes, together with some standard algorithms. Its object oriented design allows for sharing of algorithms, theorems, and implementations between its classes, and also simplifies extensions of the library. Moreover, it is integrated into the Automatic Refinement Framework, supporting automatic refinement of the abstract automata types to efficient data structures.

Note that the CAVA Automata Library is work in progress. Currently, it is very specifically tailored towards the requirements of the CAVA model checker. Nevertheless, the formalization techniques presented here allow an extension of the library to a wider scope. Moreover, they are not limited to graph libraries, but apply to class hierarchies in general.

The CAVA Automata Library is described in the paper: Peter Lammich, The CAVA Automata Library, Isabelle Workshop 2014. notify = lammich@in.tum.de [LTL] title = Linear Temporal Logic author = Salomon Sickert contributors = Benedikt Seidl date = 2016-03-01 topic = Logic/General logic/Temporal logic, Computer science/Automata and formal languages abstract = This theory provides a formalisation of linear temporal logic (LTL) and unifies previous formalisations within the AFP. This entry establishes syntax and semantics for this logic and decouples it from existing entries, yielding a common environment for theories reasoning about LTL. Furthermore a parser written in SML and an executable simplifier are provided. extra-history = Change history: [2019-03-12]: Support for additional operators, implementation of common equivalence relations, definition of syntactic fragments of LTL and the minimal disjunctive normal form.
notify = sickert@in.tum.de [LTL_to_GBA] title = Converting Linear-Time Temporal Logic to Generalized Büchi Automata author = Alexander Schimpf , Peter Lammich date = 2014-05-28 topic = Computer science/Automata and formal languages abstract = We formalize linear-time temporal logic (LTL) and the algorithm by Gerth et al. to convert LTL formulas to generalized Büchi automata. We also formalize some syntactic rewrite rules that can be applied to optimize the LTL formula before conversion. Moreover, we integrate the Stuttering Equivalence AFP-Entry by Stefan Merz, adapting the lemma that next-free LTL formula cannot distinguish between stuttering equivalent runs to our setting.

We use the Isabelle Refinement and Collection framework, as well as the Autoref tool, to obtain a refined version of our algorithm, from which efficiently executable code can be extracted. notify = lammich@in.tum.de [Gabow_SCC] title = Verified Efficient Implementation of Gabow's Strongly Connected Components Algorithm author = Peter Lammich date = 2014-05-28 topic = Computer science/Algorithms/Graph, Mathematics/Graph theory abstract = We present an Isabelle/HOL formalization of Gabow's algorithm for finding the strongly connected components of a directed graph. Using data refinement techniques, we extract efficient code that performs comparable to a reference implementation in Java. Our style of formalization allows for re-using large parts of the proofs when defining variants of the algorithm. We demonstrate this by verifying an algorithm for the emptiness check of generalized Büchi automata, re-using most of the existing proofs. notify = lammich@in.tum.de [Promela] title = Promela Formalization author = René Neumann date = 2014-05-28 topic = Computer science/System description languages abstract = We present an executable formalization of the language Promela, the description language for models of the model checker SPIN. This formalization is part of the work for a completely verified model checker (CAVA), but also serves as a useful (and executable!) description of the semantics of the language itself, something that is currently missing. The formalization uses three steps: It takes an abstract syntax tree generated from an SML parser, removes syntactic sugar and enriches it with type information. This further gets translated into a transition system, on which the semantic engine (read: successor function) operates. notify = [CAVA_LTL_Modelchecker] title = A Fully Verified Executable LTL Model Checker author = Javier Esparza , Peter Lammich , René Neumann , Tobias Nipkow , Alexander Schimpf , Jan-Georg Smaus date = 2014-05-28 topic = Computer science/Automata and formal languages abstract = We present an LTL model checker whose code has been completely verified using the Isabelle theorem prover. The checker consists of over 4000 lines of ML code. The code is produced using the Isabelle Refinement Framework, which allows us to split its correctness proof into (1) the proof of an abstract version of the checker, consisting of a few hundred lines of ``formalized pseudocode'', and (2) a verified refinement step in which mathematical sets and other abstract structures are replaced by implementations of efficient structures like red-black trees and functional arrays. This leads to a checker that, while still slower than unverified checkers, can already be used as a trusted reference implementation against which advanced implementations can be tested.

An early version of this model checker is described in the CAV 2013 paper with the same title. notify = lammich@in.tum.de [Fermat3_4] title = Fermat's Last Theorem for Exponents 3 and 4 and the Parametrisation of Pythagorean Triples author = Roelof Oosterhuis <> date = 2007-08-12 topic = Mathematics/Number theory abstract = This document presents the mechanised proofs of

  • Fermat's Last Theorem for exponents 3 and 4 and
  • the parametrisation of Pythagorean Triples.
notify = nipkow@in.tum.de, roelofoosterhuis@gmail.com [Perfect-Number-Thm] title = Perfect Number Theorem author = Mark Ijbema date = 2009-11-22 topic = Mathematics/Number theory abstract = These theories present the mechanised proof of the Perfect Number Theorem. notify = nipkow@in.tum.de [SumSquares] title = Sums of Two and Four Squares author = Roelof Oosterhuis <> date = 2007-08-12 topic = Mathematics/Number theory abstract = This document presents the mechanised proofs of the following results:
  • any prime number of the form 4m+1 can be written as the sum of two squares;
  • any natural number can be written as the sum of four squares
notify = nipkow@in.tum.de, roelofoosterhuis@gmail.com [Lehmer] title = Lehmer's Theorem author = Simon Wimmer , Lars Noschinski date = 2013-07-22 topic = Mathematics/Number theory abstract = In 1927, Lehmer presented criterions for primality, based on the converse of Fermat's litte theorem. This work formalizes the second criterion from Lehmer's paper, a necessary and sufficient condition for primality.

As a side product we formalize some properties of Euler's phi-function, the notion of the order of an element of a group, and the cyclicity of the multiplicative group of a finite field. notify = noschinl@gmail.com, simon.wimmer@tum.de [Pratt_Certificate] title = Pratt's Primality Certificates author = Simon Wimmer , Lars Noschinski date = 2013-07-22 topic = Mathematics/Number theory abstract = In 1975, Pratt introduced a proof system for certifying primes. He showed that a number p is prime iff a primality certificate for p exists. By showing a logarithmic upper bound on the length of the certificates in size of the prime number, he concluded that the decision problem for prime numbers is in NP. This work formalizes soundness and completeness of Pratt's proof system as well as an upper bound for the size of the certificate. notify = noschinl@gmail.com, simon.wimmer@tum.de [Monad_Memo_DP] title = Monadification, Memoization and Dynamic Programming author = Simon Wimmer , Shuwei Hu , Tobias Nipkow topic = Computer science/Programming languages/Transformations, Computer science/Algorithms, Computer science/Functional programming date = 2018-05-22 notify = wimmers@in.tum.de abstract = We present a lightweight framework for the automatic verified (functional or imperative) memoization of recursive functions. Our tool can turn a pure Isabelle/HOL function definition into a monadified version in a state monad or the Imperative HOL heap monad, and prove a correspondence theorem. We provide a variety of memory implementations for the two types of monads. A number of simple techniques allow us to achieve bottom-up computation and space-efficient memoization. The framework’s utility is demonstrated on a number of representative dynamic programming problems. A detailed description of our work can be found in the accompanying paper [2]. [Probabilistic_Timed_Automata] title = Probabilistic Timed Automata author = Simon Wimmer , Johannes Hölzl topic = Mathematics/Probability theory, Computer science/Automata and formal languages date = 2018-05-24 notify = wimmers@in.tum.de, hoelzl@in.tum.de abstract = We present a formalization of probabilistic timed automata (PTA) for which we try to follow the formula MDP + TA = PTA as far as possible: our work starts from our existing formalizations of Markov decision processes (MDP) and timed automata (TA) and combines them modularly. We prove the fundamental result for probabilistic timed automata: the region construction that is known from timed automata carries over to the probabilistic setting. In particular, this allows us to prove that minimum and maximum reachability probabilities can be computed via a reduction to MDP model checking, including the case where one wants to disregard unrealizable behavior. Further information can be found in our ITP paper [2]. [Hidden_Markov_Models] title = Hidden Markov Models author = Simon Wimmer topic = Mathematics/Probability theory, Computer science/Algorithms date = 2018-05-25 notify = wimmers@in.tum.de abstract = This entry contains a formalization of hidden Markov models [3] based on Johannes Hölzl's formalization of discrete time Markov chains [1]. The basic definitions are provided and the correctness of two main (dynamic programming) algorithms for hidden Markov models is proved: the forward algorithm for computing the likelihood of an observed sequence, and the Viterbi algorithm for decoding the most probable hidden state sequence. The Viterbi algorithm is made executable including memoization. Hidden markov models have various applications in natural language processing. For an introduction see Jurafsky and Martin [2]. [ArrowImpossibilityGS] title = Arrow and Gibbard-Satterthwaite author = Tobias Nipkow date = 2008-09-01 topic = Mathematics/Games and economics abstract = This article formalizes two proofs of Arrow's impossibility theorem due to Geanakoplos and derives the Gibbard-Satterthwaite theorem as a corollary. One formalization is based on utility functions, the other one on strict partial orders.

An article about these proofs is found here. notify = nipkow@in.tum.de [SenSocialChoice] title = Some classical results in Social Choice Theory author = Peter Gammie date = 2008-11-09 topic = Mathematics/Games and economics abstract = Drawing on Sen's landmark work "Collective Choice and Social Welfare" (1970), this development proves Arrow's General Possibility Theorem, Sen's Liberal Paradox and May's Theorem in a general setting. The goal was to make precise the classical statements and proofs of these results, and to provide a foundation for more recent results such as the Gibbard-Satterthwaite and Duggan-Schwartz theorems. notify = nipkow@in.tum.de [Vickrey_Clarke_Groves] title = VCG - Combinatorial Vickrey-Clarke-Groves Auctions author = Marco B. Caminati <>, Manfred Kerber , Christoph Lange, Colin Rowat date = 2015-04-30 topic = Mathematics/Games and economics abstract = A VCG auction (named after their inventors Vickrey, Clarke, and Groves) is a generalization of the single-good, second price Vickrey auction to the case of a combinatorial auction (multiple goods, from which any participant can bid on each possible combination). We formalize in this entry VCG auctions, including tie-breaking and prove that the functions for the allocation and the price determination are well-defined. Furthermore we show that the allocation function allocates goods only to participants, only goods in the auction are allocated, and no good is allocated twice. We also show that the price function is non-negative. These properties also hold for the automatically extracted Scala code. notify = mnfrd.krbr@gmail.com [Topology] title = Topology author = Stefan Friedrich <> date = 2004-04-26 topic = Mathematics/Topology abstract = This entry contains two theories. The first, Topology, develops the basic notions of general topology. The second, which can be viewed as a demonstration of the first, is called LList_Topology. It develops the topology of lazy lists. notify = lcp@cl.cam.ac.uk [Knot_Theory] title = Knot Theory author = T.V.H. Prathamesh date = 2016-01-20 topic = Mathematics/Topology abstract = This work contains a formalization of some topics in knot theory. The concepts that were formalized include definitions of tangles, links, framed links and link/tangle equivalence. The formalization is based on a formulation of links in terms of tangles. We further construct and prove the invariance of the Bracket polynomial. Bracket polynomial is an invariant of framed links closely linked to the Jones polynomial. This is perhaps the first attempt to formalize any aspect of knot theory in an interactive proof assistant. notify = prathamesh@imsc.res.in [Graph_Theory] title = Graph Theory author = Lars Noschinski date = 2013-04-28 topic = Mathematics/Graph theory abstract = This development provides a formalization of directed graphs, supporting (labelled) multi-edges and infinite graphs. A polymorphic edge type allows edges to be treated as pairs of vertices, if multi-edges are not required. Formalized properties are i.a. walks (and related concepts), connectedness and subgraphs and basic properties of isomorphisms.

This formalization is used to prove characterizations of Euler Trails, Shortest Paths and Kuratowski subgraphs. notify = noschinl@gmail.com [Planarity_Certificates] title = Planarity Certificates author = Lars Noschinski date = 2015-11-11 topic = Mathematics/Graph theory abstract = This development provides a formalization of planarity based on combinatorial maps and proves that Kuratowski's theorem implies combinatorial planarity. Moreover, it contains verified implementations of programs checking certificates for planarity (i.e., a combinatorial map) or non-planarity (i.e., a Kuratowski subgraph). notify = noschinl@gmail.com [Max-Card-Matching] title = Maximum Cardinality Matching author = Christine Rizkallah date = 2011-07-21 topic = Mathematics/Graph theory abstract =

A matching in a graph G is a subset M of the edges of G such that no two share an endpoint. A matching has maximum cardinality if its cardinality is at least as large as that of any other matching. An odd-set cover OSC of a graph G is a labeling of the nodes of G with integers such that every edge of G is either incident to a node labeled 1 or connects two nodes labeled with the same number i ≥ 2.

This article proves Edmonds theorem:
Let M be a matching in a graph G and let OSC be an odd-set cover of G. For any i ≥ 0, let n(i) be the number of nodes labeled i. If |M| = n(1) + ∑i ≥ 2(n(i) div 2), then M is a maximum cardinality matching.

notify = nipkow@in.tum.de [Girth_Chromatic] title = A Probabilistic Proof of the Girth-Chromatic Number Theorem author = Lars Noschinski date = 2012-02-06 topic = Mathematics/Graph theory abstract = This works presents a formalization of the Girth-Chromatic number theorem in graph theory, stating that graphs with arbitrarily large girth and chromatic number exist. The proof uses the theory of Random Graphs to prove the existence with probabilistic arguments. notify = noschinl@gmail.com [Random_Graph_Subgraph_Threshold] title = Properties of Random Graphs -- Subgraph Containment author = Lars Hupel date = 2014-02-13 topic = Mathematics/Graph theory, Mathematics/Probability theory abstract = Random graphs are graphs with a fixed number of vertices, where each edge is present with a fixed probability. We are interested in the probability that a random graph contains a certain pattern, for example a cycle or a clique. A very high edge probability gives rise to perhaps too many edges (which degrades performance for many algorithms), whereas a low edge probability might result in a disconnected graph. We prove a theorem about a threshold probability such that a higher edge probability will asymptotically almost surely produce a random graph with the desired subgraph. notify = hupel@in.tum.de [Flyspeck-Tame] title = Flyspeck I: Tame Graphs author = Gertrud Bauer <>, Tobias Nipkow date = 2006-05-22 topic = Mathematics/Graph theory abstract = These theories present the verified enumeration of tame plane graphs as defined by Thomas C. Hales in his proof of the Kepler Conjecture in his book Dense Sphere Packings. A Blueprint for Formal Proofs. [CUP 2012]. The values of the constants in the definition of tameness are identical to those in the Flyspeck project. The IJCAR 2006 paper by Nipkow, Bauer and Schultz refers to the original version of Hales' proof, the ITP 2011 paper by Nipkow refers to the Blueprint version of the proof. extra-history = Change history: [2010-11-02]: modified theories to reflect the modified definition of tameness in Hales' revised proof.
[2014-07-03]: modified constants in def of tameness and Archive according to the final state of the Flyspeck proof. notify = nipkow@in.tum.de [Well_Quasi_Orders] title = Well-Quasi-Orders author = Christian Sternagel date = 2012-04-13 topic = Mathematics/Combinatorics abstract = Based on Isabelle/HOL's type class for preorders, we introduce a type class for well-quasi-orders (wqo) which is characterized by the absence of "bad" sequences (our proofs are along the lines of the proof of Nash-Williams, from which we also borrow terminology). Our main results are instantiations for the product type, the list type, and a type of finite trees, which (almost) directly follow from our proofs of (1) Dickson's Lemma, (2) Higman's Lemma, and (3) Kruskal's Tree Theorem. More concretely:
  • If the sets A and B are wqo then their Cartesian product is wqo.
  • If the set A is wqo then the set of finite lists over A is wqo.
  • If the set A is wqo then the set of finite trees over A is wqo.
The research was funded by the Austrian Science Fund (FWF): J3202. extra-history = Change history: [2012-06-11]: Added Kruskal's Tree Theorem.
[2012-12-19]: New variant of Kruskal's tree theorem for terms (as opposed to variadic terms, i.e., trees), plus finite version of the tree theorem as corollary.
[2013-05-16]: Simplified construction of minimal bad sequences.
[2014-07-09]: Simplified proofs of Higman's lemma and Kruskal's tree theorem, based on homogeneous sequences.
[2016-01-03]: An alternative proof of Higman's lemma by open induction.
[2017-06-08]: Proved (classical) equivalence to inductive definition of almost-full relations according to the ITP 2012 paper "Stop When You Are Almost-Full" by Vytiniotis, Coquand, and Wahlstedt. notify = c.sternagel@gmail.com [Marriage] title = Hall's Marriage Theorem author = Dongchen Jiang , Tobias Nipkow date = 2010-12-17 topic = Mathematics/Combinatorics abstract = Two proofs of Hall's Marriage Theorem: one due to Halmos and Vaughan, one due to Rado. extra-history = Change history: [2011-09-09]: Added Rado's proof notify = nipkow@in.tum.de [Bondy] title = Bondy's Theorem author = Jeremy Avigad , Stefan Hetzl date = 2012-10-27 topic = Mathematics/Combinatorics abstract = A proof of Bondy's theorem following B. Bollabas, Combinatorics, 1986, Cambridge University Press. notify = avigad@cmu.edu, hetzl@logic.at [Ramsey-Infinite] title = Ramsey's theorem, infinitary version author = Tom Ridge <> date = 2004-09-20 topic = Mathematics/Combinatorics abstract = This formalization of Ramsey's theorem (infinitary version) is taken from Boolos and Jeffrey, Computability and Logic, 3rd edition, Chapter 26. It differs slightly from the text by assuming a slightly stronger hypothesis. In particular, the induction hypothesis is stronger, holding for any infinite subset of the naturals. This avoids the rather peculiar mapping argument between kj and aikj on p.263, which is unnecessary and slightly mars this really beautiful result. notify = lp15@cam.ac.uk [Derangements] title = Derangements Formula author = Lukas Bulwahn date = 2015-06-27 topic = Mathematics/Combinatorics abstract = The Derangements Formula describes the number of fixpoint-free permutations as a closed formula. This theorem is the 88th theorem in a list of the ``Top 100 Mathematical Theorems''. notify = lukas.bulwahn@gmail.com [Euler_Partition] title = Euler's Partition Theorem author = Lukas Bulwahn date = 2015-11-19 topic = Mathematics/Combinatorics abstract = Euler's Partition Theorem states that the number of partitions with only distinct parts is equal to the number of partitions with only odd parts. The combinatorial proof follows John Harrison's HOL Light formalization. This theorem is the 45th theorem of the Top 100 Theorems list. notify = lukas.bulwahn@gmail.com [Discrete_Summation] title = Discrete Summation author = Florian Haftmann contributors = Amine Chaieb <> date = 2014-04-13 topic = Mathematics/Combinatorics abstract = These theories introduce basic concepts and proofs about discrete summation: shifts, formal summation, falling factorials and stirling numbers. As proof of concept, a simple summation conversion is provided. notify = florian.haftmann@informatik.tu-muenchen.de [Open_Induction] title = Open Induction author = Mizuhito Ogawa <>, Christian Sternagel date = 2012-11-02 topic = Mathematics/Combinatorics abstract = A proof of the open induction schema based on J.-C. Raoult, Proving open properties by induction, Information Processing Letters 29, 1988, pp.19-23.

This research was supported by the Austrian Science Fund (FWF): J3202.

notify = c.sternagel@gmail.com [Category] title = Category Theory to Yoneda's Lemma author = Greg O'Keefe date = 2005-04-21 topic = Mathematics/Category theory license = LGPL abstract = This development proves Yoneda's lemma and aims to be readable by humans. It only defines what is needed for the lemma: categories, functors and natural transformations. Limits, adjunctions and other important concepts are not included. extra-history = Change history: [2010-04-23]: The definition of the constant equinumerous was slightly too weak in the original submission and has been fixed in revision 8c2b5b3c995f. notify = lcp@cl.cam.ac.uk [Category2] title = Category Theory author = Alexander Katovsky date = 2010-06-20 topic = Mathematics/Category theory abstract = This article presents a development of Category Theory in Isabelle/HOL. A Category is defined using records and locales. Functors and Natural Transformations are also defined. The main result that has been formalized is that the Yoneda functor is a full and faithful embedding. We also formalize the completeness of many sorted monadic equational logic. Extensive use is made of the HOLZF theory in both cases. For an informal description see here [pdf]. notify = alexander.katovsky@cantab.net [FunWithFunctions] title = Fun With Functions author = Tobias Nipkow date = 2008-08-26 topic = Mathematics/Misc abstract = This is a collection of cute puzzles of the form ``Show that if a function satisfies the following constraints, it must be ...'' Please add further examples to this collection! notify = nipkow@in.tum.de [FunWithTilings] title = Fun With Tilings author = Tobias Nipkow , Lawrence C. Paulson date = 2008-11-07 topic = Mathematics/Misc abstract = Tilings are defined inductively. It is shown that one form of mutilated chess board cannot be tiled with dominoes, while another one can be tiled with L-shaped tiles. Please add further fun examples of this kind! notify = nipkow@in.tum.de [Lazy-Lists-II] title = Lazy Lists II author = Stefan Friedrich <> date = 2004-04-26 topic = Computer science/Data structures abstract = This theory contains some useful extensions to the LList (lazy list) theory by Larry Paulson, including finite, infinite, and positive llists over an alphabet, as well as the new constants take and drop and the prefix order of llists. Finally, the notions of safety and liveness in the sense of Alpern and Schneider (1985) are defined. notify = lcp@cl.cam.ac.uk [Ribbon_Proofs] title = Ribbon Proofs author = John Wickerson <> date = 2013-01-19 topic = Computer science/Programming languages/Logics abstract = This document concerns the theory of ribbon proofs: a diagrammatic proof system, based on separation logic, for verifying program correctness. We include the syntax, proof rules, and soundness results for two alternative formalisations of ribbon proofs.

Compared to traditional proof outlines, ribbon proofs emphasise the structure of a proof, so are intelligible and pedagogical. Because they contain less redundancy than proof outlines, and allow each proof step to be checked locally, they may be more scalable. Where proof outlines are cumbersome to modify, ribbon proofs can be visually manoeuvred to yield proofs of variant programs. notify = [Koenigsberg_Friendship] title = The Königsberg Bridge Problem and the Friendship Theorem author = Wenda Li date = 2013-07-19 topic = Mathematics/Graph theory abstract = This development provides a formalization of undirected graphs and simple graphs, which are based on Benedikt Nordhoff and Peter Lammich's simple formalization of labelled directed graphs in the archive. Then, with our formalization of graphs, we show both necessary and sufficient conditions for Eulerian trails and circuits as well as the fact that the Königsberg Bridge Problem does not have a solution. In addition, we show the Friendship Theorem in simple graphs. notify = [Tree_Decomposition] title = Tree Decomposition author = Christoph Dittmann notify = date = 2016-05-31 topic = Mathematics/Graph theory abstract = We formalize tree decompositions and tree width in Isabelle/HOL, proving that trees have treewidth 1. We also show that every edge of a tree decomposition is a separation of the underlying graph. As an application of this theorem we prove that complete graphs of size n have treewidth n-1. [Menger] title = Menger's Theorem author = Christoph Dittmann topic = Mathematics/Graph theory date = 2017-02-26 notify = isabelle@christoph-d.de abstract = 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. [IEEE_Floating_Point] title = A Formal Model of IEEE Floating Point Arithmetic author = Lei Yu contributors = Fabian Hellauer , Fabian Immler date = 2013-07-27 topic = Computer science/Data structures abstract = This development provides a formal model of IEEE-754 floating-point arithmetic. This formalization, including formal specification of the standard and proofs of important properties of floating-point arithmetic, forms the foundation for verifying programs with floating-point computation. There is also a code generation setup for floats so that we can execute programs using this formalization in functional programming languages. notify = lp15@cam.ac.uk, immler@in.tum.de extra-history = Change history: [2017-09-25]: Added conversions from and to software floating point numbers (by Fabian Hellauer and Fabian Immler).
[2018-02-05]: 'Modernized' representation following the formalization in HOL4: former "float_format" and predicate "is_valid" is now encoded in a type "('e, 'f) float" where 'e and 'f encode the size of exponent and fraction. [Native_Word] title = Native Word author = Andreas Lochbihler contributors = Peter Lammich date = 2013-09-17 topic = Computer science/Data structures abstract = This entry makes machine words and machine arithmetic available for code generation from Isabelle/HOL. It provides a common abstraction that hides the differences between the different target languages. The code generator maps these operations to the APIs of the target languages. Apart from that, we extend the available bit operations on types int and integer, and map them to the operations in the target languages. extra-history = Change history: [2013-11-06]: added conversion function between native words and characters (revision fd23d9a7fe3a)
[2014-03-31]: added words of default size in the target language (by Peter Lammich) (revision 25caf5065833)
[2014-10-06]: proper test setup with compilation and execution of tests in all target languages (revision 5d7a1c9ae047)
[2017-09-02]: added 64-bit words (revision c89f86244e3c)
[2018-07-15]: added cast operators for default-size words (revision fc1f1fb8dd30)
notify = mail@andreas-lochbihler.de [XML] title = XML author = Christian Sternagel , René Thiemann date = 2014-10-03 topic = Computer science/Functional programming, Computer science/Data structures abstract = This entry provides an XML library for Isabelle/HOL. This includes parsing and pretty printing of XML trees as well as combinators for transforming XML trees into arbitrary user-defined data. The main contribution of this entry is an interface (fit for code generation) that allows for communication between verified programs formalized in Isabelle/HOL and the outside world via XML. This library was developed as part of the IsaFoR/CeTA project to which we refer for examples of its usage. notify = c.sternagel@gmail.com, rene.thiemann@uibk.ac.at [HereditarilyFinite] title = The Hereditarily Finite Sets author = Lawrence C. Paulson date = 2013-11-17 topic = Logic/Set theory abstract = The theory of hereditarily finite sets is formalised, following the development of Swierczkowski. An HF set is a finite collection of other HF sets; they enjoy an induction principle and satisfy all the axioms of ZF set theory apart from the axiom of infinity, which is negated. All constructions that are possible in ZF set theory (Cartesian products, disjoint sums, natural numbers, functions) without using infinite sets are possible here. The definition of addition for the HF sets follows Kirby. This development forms the foundation for the Isabelle proof of Gödel's incompleteness theorems, which has been formalised separately. extra-history = Change history: [2015-02-23]: Added the theory "Finitary" defining the class of types that can be embedded in hf, including int, char, option, list, etc. notify = lp15@cam.ac.uk [Incompleteness] title = Gödel's Incompleteness Theorems author = Lawrence C. Paulson date = 2013-11-17 topic = Logic/Proof theory abstract = Gödel's two incompleteness theorems are formalised, following a careful presentation by Swierczkowski, in the theory of hereditarily finite sets. This represents the first ever machine-assisted proof of the second incompleteness theorem. Compared with traditional formalisations using Peano arithmetic (see e.g. Boolos), coding is simpler, with no need to formalise the notion of multiplication (let alone that of a prime number) in the formalised calculus upon which the theorem is based. However, other technical problems had to be solved in order to complete the argument. notify = lp15@cam.ac.uk [Finite_Automata_HF] title = Finite Automata in Hereditarily Finite Set Theory author = Lawrence C. Paulson date = 2015-02-05 topic = Computer science/Automata and formal languages abstract = Finite Automata, both deterministic and non-deterministic, for regular languages. The Myhill-Nerode Theorem. Closure under intersection, concatenation, etc. Regular expressions define regular languages. Closure under reversal; the powerset construction mapping NFAs to DFAs. Left and right languages; minimal DFAs. Brzozowski's minimization algorithm. Uniqueness up to isomorphism of minimal DFAs. notify = lp15@cam.ac.uk [Decreasing-Diagrams] title = Decreasing Diagrams author = Harald Zankl license = LGPL date = 2013-11-01 topic = Logic/Rewriting abstract = This theory contains a formalization of decreasing diagrams showing that any locally decreasing abstract rewrite system is confluent. We consider the valley (van Oostrom, TCS 1994) and the conversion version (van Oostrom, RTA 2008) and closely follow the original proofs. As an application we prove Newman's lemma. notify = Harald.Zankl@uibk.ac.at [Decreasing-Diagrams-II] title = Decreasing Diagrams II author = Bertram Felgenhauer license = LGPL date = 2015-08-20 topic = Logic/Rewriting abstract = This theory formalizes the commutation version of decreasing diagrams for Church-Rosser modulo. The proof follows Felgenhauer and van Oostrom (RTA 2013). The theory also provides important specializations, in particular van Oostrom’s conversion version (TCS 2008) of decreasing diagrams. notify = bertram.felgenhauer@uibk.ac.at [GoedelGod] title = Gödel's God in Isabelle/HOL author = Christoph Benzmüller , Bruno Woltzenlogel Paleo date = 2013-11-12 topic = Logic/Philosophical aspects abstract = Dana Scott's version of Gödel's proof of God's existence is formalized in quantified modal logic KB (QML KB). QML KB is modeled as a fragment of classical higher-order logic (HOL); thus, the formalization is essentially a formalization in HOL. notify = lp15@cam.ac.uk, c.benzmueller@fu-berlin.de [Types_Tableaus_and_Goedels_God] title = Types, Tableaus and Gödel’s God in Isabelle/HOL author = David Fuenmayor , Christoph Benzmüller topic = Logic/Philosophical aspects date = 2017-05-01 notify = davfuenmayor@gmail.com, c.benzmueller@gmail.com abstract = 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''.) [GewirthPGCProof] title = Formalisation and Evaluation of Alan Gewirth's Proof for the Principle of Generic Consistency in Isabelle/HOL author = David Fuenmayor , Christoph Benzmüller topic = Logic/Philosophical aspects date = 2018-10-30 notify = davfuenmayor@gmail.com, c.benzmueller@gmail.com abstract = An ambitious ethical theory ---Alan Gewirth's "Principle of Generic Consistency"--- is encoded and analysed in Isabelle/HOL. Gewirth's theory has stirred much attention in philosophy and ethics and has been proposed as a potential means to bound the impact of artificial general intelligence. extra-history = Change history: [2019-04-09]: added proof for a stronger variant of the PGC and examplary inferences (revision 88182cb0a2f6)
[Lowe_Ontological_Argument] title = Computer-assisted Reconstruction and Assessment of E. J. Lowe's Modal Ontological Argument author = David Fuenmayor , Christoph Benzmüller topic = Logic/Philosophical aspects date = 2017-09-21 notify = davfuenmayor@gmail.com, c.benzmueller@gmail.com abstract = Computers may help us to understand --not just verify-- philosophical arguments. By utilizing modern proof assistants in an iterative interpretive process, we can reconstruct and assess an argument by fully formal means. Through the mechanization of a variant of St. Anselm's ontological argument by E. J. Lowe, which is a paradigmatic example of a natural-language argument with strong ties to metaphysics and religion, we offer an ideal showcase for our computer-assisted interpretive method. [AnselmGod] title = Anselm's God in Isabelle/HOL author = Ben Blumson topic = Logic/Philosophical aspects date = 2017-09-06 notify = benblumson@gmail.com abstract = Paul Oppenheimer and Edward Zalta's formalisation of Anselm's ontological argument for the existence of God is automated by embedding a free logic for definite descriptions within Isabelle/HOL. [Tail_Recursive_Functions] title = A General Method for the Proof of Theorems on Tail-recursive Functions author = Pasquale Noce date = 2013-12-01 topic = Computer science/Functional programming abstract =

Tail-recursive function definitions are sometimes more straightforward than alternatives, but proving theorems on them may be roundabout because of the peculiar form of the resulting recursion induction rules.

This paper describes a proof method that provides a general solution to this problem by means of suitable invariants over inductive sets, and illustrates the application of such method by examining two case studies.

notify = pasquale.noce.lavoro@gmail.com [CryptoBasedCompositionalProperties] title = Compositional Properties of Crypto-Based Components author = Maria Spichkova date = 2014-01-11 topic = Computer science/Security abstract = This paper presents an Isabelle/HOL set of theories which allows the specification of crypto-based components and the verification of their composition properties wrt. cryptographic aspects. We introduce a formalisation of the security property of data secrecy, the corresponding definitions and proofs. Please note that here we import the Isabelle/HOL theory ListExtras.thy, presented in the AFP entry FocusStreamsCaseStudies-AFP. notify = maria.spichkova@rmit.edu.au [Featherweight_OCL] title = Featherweight OCL: A Proposal for a Machine-Checked Formal Semantics for OCL 2.5 author = Achim D. Brucker , Frédéric Tuong , Burkhart Wolff date = 2014-01-16 topic = Computer science/System description languages abstract = The Unified Modeling Language (UML) is one of the few modeling languages that is widely used in industry. While UML is mostly known as diagrammatic modeling language (e.g., visualizing class models), it is complemented by a textual language, called Object Constraint Language (OCL). The current version of OCL is based on a four-valued logic that turns UML into a formal language. Any type comprises the elements "invalid" and "null" which are propagated as strict and non-strict, respectively. Unfortunately, the former semi-formal semantics of this specification language, captured in the "Annex A" of the OCL standard, leads to different interpretations of corner cases. We formalize the core of OCL: denotational definitions, a logical calculus and operational rules that allow for the execution of OCL expressions by a mixture of term rewriting and code compilation. Our formalization reveals several inconsistencies and contradictions in the current version of the OCL standard. Overall, this document is intended to provide the basis for a machine-checked text "Annex A" of the OCL standard targeting at tool implementors. extra-history = Change history: [2015-10-13]: afp-devel@ea3b38fc54d6 and hol-testgen@12148
   Update of Featherweight OCL including a change in the abstract.
[2014-01-16]: afp-devel@9091ce05cb20 and hol-testgen@10241
   New Entry: Featherweight OCL notify = brucker@spamfence.net, tuong@users.gforge.inria.fr, wolff@lri.fr [Relation_Algebra] title = Relation Algebra author = Alasdair Armstrong <>, Simon Foster , Georg Struth , Tjark Weber date = 2014-01-25 topic = Mathematics/Algebra abstract = Tarski's algebra of binary relations is formalised along the lines of the standard textbooks of Maddux and Schmidt and Ströhlein. This includes relation-algebraic concepts such as subidentities, vectors and a domain operation as well as various notions associated to functions. Relation algebras are also expanded by a reflexive transitive closure operation, and they are linked with Kleene algebras and models of binary relations and Boolean matrices. notify = g.struth@sheffield.ac.uk, tjark.weber@it.uu.se [PSemigroupsConvolution] title = Partial Semigroups and Convolution Algebras author = Brijesh Dongol , Victor B. F. Gomes , Ian J. Hayes , Georg Struth topic = Mathematics/Algebra date = 2017-06-13 notify = g.struth@sheffield.ac.uk, victor.gomes@cl.cam.ac.uk abstract = 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. [Secondary_Sylow] title = Secondary Sylow Theorems author = Jakob von Raumer date = 2014-01-28 topic = Mathematics/Algebra abstract = These theories extend the existing proof of the first Sylow theorem (written by Florian Kammueller and L. C. Paulson) by what are often called the second, third and fourth Sylow theorems. These theorems state propositions about the number of Sylow p-subgroups of a group and the fact that they are conjugate to each other. The proofs make use of an implementation of group actions and their properties. notify = psxjv4@nottingham.ac.uk [Jordan_Hoelder] title = The Jordan-Hölder Theorem author = Jakob von Raumer date = 2014-09-09 topic = Mathematics/Algebra abstract = This submission contains theories that lead to a formalization of the proof of the Jordan-Hölder theorem about composition series of finite groups. The theories formalize the notions of isomorphism classes of groups, simple groups, normal series, composition series, maximal normal subgroups. Furthermore, they provide proofs of the second isomorphism theorem for groups, the characterization theorem for maximal normal subgroups as well as many useful lemmas about normal subgroups and factor groups. The proof is inspired by course notes of Stuart Rankin. notify = psxjv4@nottingham.ac.uk [Cayley_Hamilton] title = The Cayley-Hamilton Theorem author = Stephan Adelsberger , Stefan Hetzl , Florian Pollak date = 2014-09-15 topic = Mathematics/Algebra abstract = This document contains a proof of the Cayley-Hamilton theorem based on the development of matrices in HOL/Multivariate Analysis. notify = stvienna@gmail.com [Probabilistic_Noninterference] title = Probabilistic Noninterference author = Andrei Popescu , Johannes Hölzl date = 2014-03-11 topic = Computer science/Security abstract = We formalize a probabilistic noninterference for a multi-threaded language with uniform scheduling, where probabilistic behaviour comes from both the scheduler and the individual threads. We define notions probabilistic noninterference in two variants: resumption-based and trace-based. For the resumption-based notions, we prove compositionality w.r.t. the language constructs and establish sound type-system-like syntactic criteria. This is a formalization of the mathematical development presented at CPP 2013 and CALCO 2013. It is the probabilistic variant of the Possibilistic Noninterference AFP entry. notify = hoelzl@in.tum.de [HyperCTL] title = A shallow embedding of HyperCTL* author = Markus N. Rabe , Peter Lammich , Andrei Popescu date = 2014-04-16 topic = Computer science/Security, Logic/General logic/Temporal logic abstract = We formalize HyperCTL*, a temporal logic for expressing security properties. We first define a shallow embedding of HyperCTL*, within which we prove inductive and coinductive rules for the operators. Then we show that a HyperCTL* formula captures Goguen-Meseguer noninterference, a landmark information flow property. We also define a deep embedding and connect it to the shallow embedding by a denotational semantics, for which we prove sanity w.r.t. dependence on the free variables. Finally, we show that under some finiteness assumptions about the model, noninterference is given by a (finitary) syntactic formula. notify = uuomul@yahoo.com [Bounded_Deducibility_Security] title = Bounded-Deducibility Security author = Andrei Popescu , Peter Lammich date = 2014-04-22 topic = Computer science/Security abstract = This is a formalization of bounded-deducibility security (BD security), a flexible notion of information-flow security applicable to arbitrary input-output automata. It generalizes Sutherland's classic notion of nondeducibility by factoring in declassification bounds and trigger, whereas nondeducibility states that, in a system, information cannot flow between specified sources and sinks, BD security indicates upper bounds for the flow and triggers under which these upper bounds are no longer guaranteed. notify = uuomul@yahoo.com, lammich@in.tum.de [Network_Security_Policy_Verification] title = Network Security Policy Verification author = Cornelius Diekmann date = 2014-07-04 topic = Computer science/Security abstract = We present a unified theory for verifying network security policies. A security policy is represented as directed graph. To check high-level security goals, security invariants over the policy are expressed. We cover monotonic security invariants, i.e. prohibiting more does not harm security. We provide the following contributions for the security invariant theory.
  • Secure auto-completion of scenario-specific knowledge, which eases usability.
  • Security violations can be repaired by tightening the policy iff the security invariants hold for the deny-all policy.
  • An algorithm to compute a security policy.
  • A formalization of stateful connection semantics in network security mechanisms.
  • An algorithm to compute a secure stateful implementation of a policy.
  • An executable implementation of all the theory.
  • Examples, ranging from an aircraft cabin data network to the analysis of a large real-world firewall.
  • More examples: A fully automated translation of high-level security goals to both firewall and SDN configurations (see Examples/Distributed_WebApp.thy).
For a detailed description, see extra-history = Change history: [2015-04-14]: Added Distributed WebApp example and improved graphviz visualization (revision 4dde08ca2ab8)
notify = diekmann@net.in.tum.de [Abstract_Completeness] title = Abstract Completeness author = Jasmin Christian Blanchette , Andrei Popescu , Dmitriy Traytel date = 2014-04-16 topic = Logic/Proof theory abstract = A formalization of an abstract property of possibly infinite derivation trees (modeled by a codatatype), representing the core of a proof (in Beth/Hintikka style) of the first-order logic completeness theorem, independent of the concrete syntax or inference rules. This work is described in detail in the IJCAR 2014 publication by the authors. The abstract proof can be instantiated for a wide range of Gentzen and tableau systems as well as various flavors of FOL---e.g., with or without predicates, equality, or sorts. Here, we give only a toy example instantiation with classical propositional logic. A more serious instance---many-sorted FOL with equality---is described elsewhere [Blanchette and Popescu, FroCoS 2013]. notify = traytel@in.tum.de [Pop_Refinement] title = Pop-Refinement author = Alessandro Coglio date = 2014-07-03 topic = Computer science/Programming languages/Misc abstract = Pop-refinement is an approach to stepwise refinement, carried out inside an interactive theorem prover by constructing a monotonically decreasing sequence of predicates over deeply embedded target programs. The sequence starts with a predicate that characterizes the possible implementations, and ends with a predicate that characterizes a unique program in explicit syntactic form. Pop-refinement enables more requirements (e.g. program-level and non-functional) to be captured in the initial specification and preserved through refinement. Security requirements expressed as hyperproperties (i.e. predicates over sets of traces) are always preserved by pop-refinement, unlike the popular notion of refinement as trace set inclusion. Two simple examples in Isabelle/HOL are presented, featuring program-level requirements, non-functional requirements, and hyperproperties. notify = coglio@kestrel.edu [VectorSpace] title = Vector Spaces author = Holden Lee date = 2014-08-29 topic = Mathematics/Algebra abstract = This formalisation of basic linear algebra is based completely on locales, building off HOL-Algebra. It includes basic definitions: linear combinations, span, linear independence; linear transformations; interpretation of function spaces as vector spaces; the direct sum of vector spaces, sum of subspaces; the replacement theorem; existence of bases in finite-dimensional; vector spaces, definition of dimension; the rank-nullity theorem. Some concepts are actually defined and proved for modules as they also apply there. Infinite-dimensional vector spaces are supported, but dimension is only supported for finite-dimensional vector spaces. The proofs are standard; the proofs of the replacement theorem and rank-nullity theorem roughly follow the presentation in Linear Algebra by Friedberg, Insel, and Spence. The rank-nullity theorem generalises the existing development in the Archive of Formal Proof (originally using type classes, now using a mix of type classes and locales). notify = holdenl@princeton.edu [Special_Function_Bounds] title = Real-Valued Special Functions: Upper and Lower Bounds author = Lawrence C. Paulson date = 2014-08-29 topic = Mathematics/Analysis abstract = This development proves upper and lower bounds for several familiar real-valued functions. For sin, cos, exp and sqrt, it defines and verifies infinite families of upper and lower bounds, mostly based on Taylor series expansions. For arctan, ln and exp, it verifies a finite collection of upper and lower bounds, originally obtained from the functions' continued fraction expansions using the computer algebra system Maple. A common theme in these proofs is to take the difference between a function and its approximation, which should be zero at one point, and then consider the sign of the derivative. The immediate purpose of this development is to verify axioms used by MetiTarski, an automatic theorem prover for real-valued special functions. Crucial to MetiTarski's operation is the provision of upper and lower bounds for each function of interest. notify = lp15@cam.ac.uk [Landau_Symbols] title = Landau Symbols author = Manuel Eberl date = 2015-07-14 topic = Mathematics/Analysis abstract = This entry provides Landau symbols to describe and reason about the asymptotic growth of functions for sufficiently large inputs. A number of simplification procedures are provided for additional convenience: cancelling of dominated terms in sums under a Landau symbol, cancelling of common factors in products, and a decision procedure for Landau expressions containing products of powers of functions like x, ln(x), ln(ln(x)) etc. notify = eberlm@in.tum.de [Error_Function] title = The Error Function author = Manuel Eberl topic = Mathematics/Analysis date = 2018-02-06 notify = eberlm@in.tum.de abstract =

This entry provides the definitions and basic properties of the complex and real error function erf and the complementary error function erfc. Additionally, it gives their full asymptotic expansions.

[Akra_Bazzi] title = The Akra-Bazzi theorem and the Master theorem author = Manuel Eberl date = 2015-07-14 topic = Mathematics/Analysis abstract = This article contains a formalisation of the Akra-Bazzi method based on a proof by Leighton. It is a generalisation of the well-known Master Theorem for analysing the complexity of Divide & Conquer algorithms. We also include a generalised version of the Master theorem based on the Akra-Bazzi theorem, which is easier to apply than the Akra-Bazzi theorem itself.

Some proof methods that facilitate applying the Master theorem are also included. For a more detailed explanation of the formalisation and the proof methods, see the accompanying paper (publication forthcoming). notify = eberlm@in.tum.de [Dirichlet_Series] title = Dirichlet Series author = Manuel Eberl topic = Mathematics/Number theory date = 2017-10-12 notify = eberlm@in.tum.de abstract = This entry is a formalisation of much of Chapters 2, 3, and 11 of Apostol's “Introduction to Analytic Number Theory”. This includes:

  • Definitions and basic properties for several number-theoretic functions (Euler's φ, Möbius μ, Liouville's λ, the divisor function σ, von Mangoldt's Λ)
  • Executable code for most of these functions, the most efficient implementations using the factoring algorithm by Thiemann et al.
  • Dirichlet products and formal Dirichlet series
  • Analytic results connecting convergent formal Dirichlet series to complex functions
  • Euler product expansions
  • Asymptotic estimates of number-theoretic functions including the density of squarefree integers and the average number of divisors of a natural number
These results are useful as a basis for developing more number-theoretic results, such as the Prime Number Theorem. [Gauss_Sums] title = Gauss Sums and the Pólya–Vinogradov Inequality author = Rodrigo Raya , Manuel Eberl topic = Mathematics/Number theory date = 2019-12-10 notify = manuel.eberl@tum.de abstract =

This article provides a full formalisation of Chapter 8 of Apostol's Introduction to Analytic Number Theory. Subjects that are covered are:

  • periodic arithmetic functions and their finite Fourier series
  • (generalised) Ramanujan sums
  • Gauss sums and separable characters
  • induced moduli and primitive characters
  • the Pólya—Vinogradov inequality
[Zeta_Function] title = The Hurwitz and Riemann ζ Functions author = Manuel Eberl topic = Mathematics/Number theory, Mathematics/Analysis date = 2017-10-12 notify = eberlm@in.tum.de abstract =

This entry builds upon the results about formal and analytic Dirichlet series to define the Hurwitz ζ function ζ(a,s) and, based on that, the Riemann ζ function ζ(s). This is done by first defining them for ℜ(z) > 1 and then successively extending the domain to the left using the Euler–MacLaurin formula.

Apart from the most basic facts such as analyticity, the following results are provided:

  • the Stieltjes constants and the Laurent expansion of ζ(s) at s = 1
  • the non-vanishing of ζ(s) for ℜ(z) ≥ 1
  • the relationship between ζ(a,s) and Γ
  • the special values at negative integers and positive even integers
  • Hurwitz's formula and the reflection formula for ζ(s)
  • the Hadjicostas–Chapman formula

The entry also contains Euler's analytic proof of the infinitude of primes, based on the fact that ζ(s) has a pole at s = 1.

[Linear_Recurrences] title = Linear Recurrences author = Manuel Eberl topic = Mathematics/Analysis date = 2017-10-12 notify = eberlm@in.tum.de abstract =

Linear recurrences with constant coefficients are an interesting class of recurrence equations that can be solved explicitly. The most famous example are certainly the Fibonacci numbers with the equation f(n) = f(n-1) + f(n - 2) and the quite non-obvious closed form (φn - (-φ)-n) / √5 where φ is the golden ratio.

In this work, I build on existing tools in Isabelle – such as formal power series and polynomial factorisation algorithms – to develop a theory of these recurrences and derive a fully executable solver for them that can be exported to programming languages like Haskell.

[Lambert_W] title = The Lambert W Function on the Reals author = Manuel Eberl topic = Mathematics/Analysis date = 2020-04-24 notify = eberlm@in.tum.de abstract =

The Lambert W function is a multi-valued function defined as the inverse function of xx ex. Besides numerous applications in combinatorics, physics, and engineering, it also frequently occurs when solving equations containing both ex and x, or both x and log x.

This article provides a definition of the two real-valued branches W0(x) and W-1(x) and proves various properties such as basic identities and inequalities, monotonicity, differentiability, asymptotic expansions, and the MacLaurin series of W0(x) at x = 0.

[Cartan_FP] title = The Cartan Fixed Point Theorems author = Lawrence C. Paulson date = 2016-03-08 topic = Mathematics/Analysis abstract = The Cartan fixed point theorems concern the group of holomorphic automorphisms on a connected open set of Cn. Ciolli et al. have formalised the one-dimensional case of these theorems in HOL Light. This entry contains their proofs, ported to Isabelle/HOL. Thus it addresses the authors' remark that "it would be important to write a formal proof in a language that can be read by both humans and machines". notify = lp15@cam.ac.uk [Gauss_Jordan] title = Gauss-Jordan Algorithm and Its Applications author = Jose Divasón , Jesús Aransay topic = Computer science/Algorithms/Mathematical date = 2014-09-03 abstract = The Gauss-Jordan algorithm states that any matrix over a field can be transformed by means of elementary row operations to a matrix in reduced row echelon form. The formalization is based on the Rank Nullity Theorem entry of the AFP and on the HOL-Multivariate-Analysis session of Isabelle, where matrices are represented as functions over finite types. We have set up the code generator to make this representation executable. In order to improve the performance, a refinement to immutable arrays has been carried out. We have formalized some of the applications of the Gauss-Jordan algorithm. Thanks to this development, the following facts can be computed over matrices whose elements belong to a field: Ranks, Determinants, Inverses, Bases and dimensions and Solutions of systems of linear equations. Code can be exported to SML and Haskell. notify = jose.divasonm@unirioja.es, jesus-maria.aransay@unirioja.es [Echelon_Form] title = Echelon Form author = Jose Divasón , Jesús Aransay topic = Computer science/Algorithms/Mathematical, Mathematics/Algebra date = 2015-02-12 abstract = We formalize an algorithm to compute the Echelon Form of a matrix. We have proved its existence over Bézout domains and made it executable over Euclidean domains, such as the integer ring and the univariate polynomials over a field. This allows us to compute determinants, inverses and characteristic polynomials of matrices. The work is based on the HOL-Multivariate Analysis library, and on both the Gauss-Jordan and Cayley-Hamilton AFP entries. As a by-product, some algebraic structures have been implemented (principal ideal domains, Bézout domains...). The algorithm has been refined to immutable arrays and code can be generated to functional languages as well. notify = jose.divasonm@unirioja.es, jesus-maria.aransay@unirioja.es [QR_Decomposition] title = QR Decomposition author = Jose Divasón , Jesús Aransay topic = Computer science/Algorithms/Mathematical, Mathematics/Algebra date = 2015-02-12 abstract = QR decomposition is an algorithm to decompose a real matrix A into the product of two other matrices Q and R, where Q is orthogonal and R is invertible and upper triangular. The algorithm is useful for the least squares problem; i.e., the computation of the best approximation of an unsolvable system of linear equations. As a side-product, the Gram-Schmidt process has also been formalized. A refinement using immutable arrays is presented as well. The development relies, among others, on the AFP entry "Implementing field extensions of the form Q[sqrt(b)]" by René Thiemann, which allows execution of the algorithm using symbolic computations. Verified code can be generated and executed using floats as well. extra-history = Change history: [2015-06-18]: The second part of the Fundamental Theorem of Linear Algebra has been generalized to more general inner product spaces. notify = jose.divasonm@unirioja.es, jesus-maria.aransay@unirioja.es [Hermite] title = Hermite Normal Form author = Jose Divasón , Jesús Aransay topic = Computer science/Algorithms/Mathematical, Mathematics/Algebra date = 2015-07-07 abstract = Hermite Normal Form is a canonical matrix analogue of Reduced Echelon Form, but involving matrices over more general rings. In this work we formalise an algorithm to compute the Hermite Normal Form of a matrix by means of elementary row operations, taking advantage of the Echelon Form AFP entry. We have proven the correctness of such an algorithm and refined it to immutable arrays. Furthermore, we have also formalised the uniqueness of the Hermite Normal Form of a matrix. Code can be exported and some examples of execution involving integer matrices and polynomial matrices are presented as well. notify = jose.divasonm@unirioja.es, jesus-maria.aransay@unirioja.es [Imperative_Insertion_Sort] title = Imperative Insertion Sort author = Christian Sternagel date = 2014-09-25 topic = Computer science/Algorithms abstract = The insertion sort algorithm of Cormen et al. (Introduction to Algorithms) is expressed in Imperative HOL and proved to be correct and terminating. For this purpose we also provide a theory about imperative loop constructs with accompanying induction/invariant rules for proving partial and total correctness. Furthermore, the formalized algorithm is fit for code generation. notify = lp15@cam.ac.uk [Stream_Fusion_Code] title = Stream Fusion in HOL with Code Generation author = Andreas Lochbihler , Alexandra Maximova date = 2014-10-10 topic = Computer science/Functional programming abstract = Stream Fusion is a system for removing intermediate list data structures from functional programs, in particular Haskell. This entry adapts stream fusion to Isabelle/HOL and its code generator. We define stream types for finite and possibly infinite lists and stream versions for most of the fusible list functions in the theories List and Coinductive_List, and prove them correct with respect to the conversion functions between lists and streams. The Stream Fusion transformation itself is implemented as a simproc in the preprocessor of the code generator. [Brian Huffman's AFP entry formalises stream fusion in HOLCF for the domain of lazy lists to prove the GHC compiler rewrite rules correct. In contrast, this work enables Isabelle's code generator to perform stream fusion itself. To that end, it covers both finite and coinductive lists from the HOL library and the Coinductive entry. The fusible list functions require specification and proof principles different from Huffman's.] notify = mail@andreas-lochbihler.de [Case_Labeling] title = Generating Cases from Labeled Subgoals author = Lars Noschinski date = 2015-07-21 topic = Tools, Computer science/Programming languages/Misc abstract = Isabelle/Isar provides named cases to structure proofs. This article contains an implementation of a proof method casify, which can be used to easily extend proof tools with support for named cases. Such a proof tool must produce labeled subgoals, which are then interpreted by casify.

As examples, this work contains verification condition generators producing named cases for three languages: The Hoare language from HOL/Library, a monadic language for computations with failure (inspired by the AutoCorres tool), and a language of conditional expressions. These VCGs are demonstrated by a number of example programs. notify = noschinl@gmail.com [DPT-SAT-Solver] title = A Fast SAT Solver for Isabelle in Standard ML topic = Tools author = Armin Heller <> date = 2009-12-09 abstract = This contribution contains a fast SAT solver for Isabelle written in Standard ML. By loading the theory DPT_SAT_Solver, the SAT solver installs itself (under the name ``dptsat'') and certain Isabelle tools like Refute will start using it automatically. This is a port of the DPT (Decision Procedure Toolkit) SAT Solver written in OCaml. notify = jasmin.blanchette@gmail.com [Rep_Fin_Groups] title = Representations of Finite Groups topic = Mathematics/Algebra author = Jeremy Sylvestre date = 2015-08-12 abstract = We provide a formal framework for the theory of representations of finite groups, as modules over the group ring. Along the way, we develop the general theory of groups (relying on the group_add class for the basics), modules, and vector spaces, to the extent required for theory of group representations. We then provide formal proofs of several important introductory theorems in the subject, including Maschke's theorem, Schur's lemma, and Frobenius reciprocity. We also prove that every irreducible representation is isomorphic to a submodule of the group ring, leading to the fact that for a finite group there are only finitely many isomorphism classes of irreducible representations. In all of this, no restriction is made on the characteristic of the ring or field of scalars until the definition of a group representation, and then the only restriction made is that the characteristic must not divide the order of the group. notify = jsylvest@ualberta.ca [Noninterference_Inductive_Unwinding] title = The Inductive Unwinding Theorem for CSP Noninterference Security topic = Computer science/Security author = Pasquale Noce date = 2015-08-18 abstract =

The necessary and sufficient condition for CSP noninterference security stated by the Ipurge Unwinding Theorem is expressed in terms of a pair of event lists varying over the set of process traces. This does not render it suitable for the subsequent application of rule induction in the case of a process defined inductively, since rule induction may rather be applied to a single variable ranging over an inductively defined set.

Starting from the Ipurge Unwinding Theorem, this paper derives a necessary and sufficient condition for CSP noninterference security that involves a single event list varying over the set of process traces, and is thus suitable for rule induction; hence its name, Inductive Unwinding Theorem. Similarly to the Ipurge Unwinding Theorem, the new theorem only requires to consider individual accepted and refused events for each process trace, and applies to the general case of a possibly intransitive noninterference policy. Specific variants of this theorem are additionally proven for deterministic processes and trace set processes.

notify = pasquale.noce.lavoro@gmail.com [Password_Authentication_Protocol] title = Verification of a Diffie-Hellman Password-based Authentication Protocol by Extending the Inductive Method author = Pasquale Noce topic = Computer science/Security date = 2017-01-03 notify = pasquale.noce.lavoro@gmail.com abstract = This paper constructs a formal model of a Diffie-Hellman password-based authentication protocol between a user and a smart card, and proves its security. The protocol provides for the dispatch of the user's password to the smart card on a secure messaging channel established by means of Password Authenticated Connection Establishment (PACE), where the mapping method being used is Chip Authentication Mapping. By applying and suitably extending Paulson's Inductive Method, this paper proves that the protocol establishes trustworthy secure messaging channels, preserves the secrecy of users' passwords, and provides an effective mutual authentication service. What is more, these security properties turn out to hold independently of the secrecy of the PACE authentication key. [Jordan_Normal_Form] title = Matrices, Jordan Normal Forms, and Spectral Radius Theory topic = Mathematics/Algebra author = René Thiemann , Akihisa Yamada contributors = Alexander Bentkamp date = 2015-08-21 abstract =

Matrix interpretations are useful as measure functions in termination proving. In order to use these interpretations also for complexity analysis, the growth rate of matrix powers has to examined. Here, we formalized a central result of spectral radius theory, namely that the growth rate is polynomially bounded if and only if the spectral radius of a matrix is at most one.

To formally prove this result we first studied the growth rates of matrices in Jordan normal form, and prove the result that every complex matrix has a Jordan normal form using a constructive prove via Schur decomposition.

The whole development is based on a new abstract type for matrices, which is also executable by a suitable setup of the code generator. It completely subsumes our former AFP-entry on executable matrices, and its main advantage is its close connection to the HMA-representation which allowed us to easily adapt existing proofs on determinants.

All the results have been applied to improve CeTA, our certifier to validate termination and complexity proof certificates.

extra-history = Change history: [2016-01-07]: Added Schur-decomposition, Gram-Schmidt orthogonalization, uniqueness of Jordan normal forms
[2018-04-17]: Integrated lemmas from deep-learning AFP-entry of Alexander Bentkamp notify = rene.thiemann@uibk.ac.at, ayamada@trs.cm.is.nagoya-u.ac.jp [LTL_to_DRA] title = Converting Linear Temporal Logic to Deterministic (Generalized) Rabin Automata topic = Computer science/Automata and formal languages author = Salomon Sickert date = 2015-09-04 abstract = Recently, Javier Esparza and Jan Kretinsky proposed a new method directly translating linear temporal logic (LTL) formulas to deterministic (generalized) Rabin automata. Compared to the existing approaches of constructing a non-deterministic Buechi-automaton in the first step and then applying a determinization procedure (e.g. some variant of Safra's construction) in a second step, this new approach preservers a relation between the formula and the states of the resulting automaton. While the old approach produced a monolithic structure, the new method is compositional. Furthermore, in some cases the resulting automata are much smaller than the automata generated by existing approaches. In order to ensure the correctness of the construction, this entry contains a complete formalisation and verification of the translation. Furthermore from this basis executable code is generated. extra-history = Change history: [2015-09-23]: Enable code export for the eager unfolding optimisation and reduce running time of the generated tool. Moreover, add support for the mlton SML compiler.
[2016-03-24]: Make use of the LTL entry and include the simplifier. notify = sickert@in.tum.de [Timed_Automata] title = Timed Automata author = Simon Wimmer date = 2016-03-08 topic = Computer science/Automata and formal languages abstract = Timed automata are a widely used formalism for modeling real-time systems, which is employed in a class of successful model checkers such as UPPAAL [LPY97], HyTech [HHWt97] or Kronos [Yov97]. This work formalizes the theory for the subclass of diagonal-free timed automata, which is sufficient to model many interesting problems. We first define the basic concepts and semantics of diagonal-free timed automata. Based on this, we prove two types of decidability results for the language emptiness problem. The first is the classic result of Alur and Dill [AD90, AD94], which uses a finite partitioning of the state space into so-called `regions`. Our second result focuses on an approach based on `Difference Bound Matrices (DBMs)`, which is practically used by model checkers. We prove the correctness of the basic forward analysis operations on DBMs. One of these operations is the Floyd-Warshall algorithm for the all-pairs shortest paths problem. To obtain a finite search space, a widening operation has to be used for this kind of analysis. We use Patricia Bouyer's [Bou04] approach to prove that this widening operation is correct in the sense that DBM-based forward analysis in combination with the widening operation also decides language emptiness. The interesting property of this proof is that the first decidability result is reused to obtain the second one. notify = wimmers@in.tum.de [Parity_Game] title = Positional Determinacy of Parity Games author = Christoph Dittmann date = 2015-11-02 topic = Mathematics/Games and economics, Mathematics/Graph theory abstract = We present a formalization of parity games (a two-player game on directed graphs) and a proof of their positional determinacy in Isabelle/HOL. This proof works for both finite and infinite games. notify = [Ergodic_Theory] title = Ergodic Theory author = Sebastien Gouezel contributors = Manuel Eberl date = 2015-12-01 topic = Mathematics/Probability theory abstract = Ergodic theory is the branch of mathematics that studies the behaviour of measure preserving transformations, in finite or infinite measure. It interacts both with probability theory (mainly through measure theory) and with geometry as a lot of interesting examples are from geometric origin. We implement the first definitions and theorems of ergodic theory, including notably Poicaré recurrence theorem for finite measure preserving systems (together with the notion of conservativity in general), induced maps, Kac's theorem, Birkhoff theorem (arguably the most important theorem in ergodic theory), and variations around it such as conservativity of the corresponding skew product, or Atkinson lemma. notify = sebastien.gouezel@univ-rennes1.fr, hoelzl@in.tum.de [Latin_Square] title = Latin Square author = Alexander Bentkamp date = 2015-12-02 topic = Mathematics/Combinatorics abstract = A Latin Square is a n x n table filled with integers from 1 to n where each number appears exactly once in each row and each column. A Latin Rectangle is a partially filled n x n table with r filled rows and n-r empty rows, such that each number appears at most once in each row and each column. The main result of this theory is that any Latin Rectangle can be completed to a Latin Square. notify = bentkamp@gmail.com [Deep_Learning] title = Expressiveness of Deep Learning author = Alexander Bentkamp date = 2016-11-10 topic = Computer science/Machine learning, Mathematics/Analysis abstract = Deep learning has had a profound impact on computer science in recent years, with applications to search engines, image recognition and language processing, bioinformatics, and more. Recently, Cohen et al. provided theoretical evidence for the superiority of deep learning over shallow learning. This formalization of their work simplifies and generalizes the original proof, while working around the limitations of the Isabelle type system. To support the formalization, I developed reusable libraries of formalized mathematics, including results about the matrix rank, the Lebesgue measure, and multivariate polynomials, as well as a library for tensor analysis. notify = bentkamp@gmail.com [Inductive_Inference] title = Some classical results in inductive inference of recursive functions author = Frank J. Balbach topic = Logic/Computability, Computer science/Machine learning date = 2020-08-31 notify = frank-balbach@gmx.de abstract =

This entry formalizes some classical concepts and results from inductive inference of recursive functions. In the basic setting a partial recursive function ("strategy") must identify ("learn") all functions from a set ("class") of recursive functions. To that end the strategy receives more and more values $f(0), f(1), f(2), \ldots$ of some function $f$ from the given class and in turn outputs descriptions of partial recursive functions, for example, Gödel numbers. The strategy is considered successful if the sequence of outputs ("hypotheses") converges to a description of $f$. A class of functions learnable in this sense is called "learnable in the limit". The set of all these classes is denoted by LIM.

Other types of inference considered are finite learning (FIN), behaviorally correct learning in the limit (BC), and some variants of LIM with restrictions on the hypotheses: total learning (TOTAL), consistent learning (CONS), and class-preserving learning (CP). The main results formalized are the proper inclusions $\mathrm{FIN} \subset \mathrm{CP} \subset \mathrm{TOTAL} \subset \mathrm{CONS} \subset \mathrm{LIM} \subset \mathrm{BC} \subset 2^{\mathcal{R}}$, where $\mathcal{R}$ is the set of all total recursive functions. Further results show that for all these inference types except CONS, strategies can be assumed to be total recursive functions; that all inference types but CP are closed under the subset relation between classes; and that no inference type is closed under the union of classes.

The above is based on a formalization of recursive functions heavily inspired by the Universal Turing Machine entry by Xu et al., but different in that it models partial functions with codomain nat option. The formalization contains a construction of a universal partial recursive function, without resorting to Turing machines, introduces decidability and recursive enumerability, and proves some standard results: existence of a Kleene normal form, the s-m-n theorem, Rice's theorem, and assorted fixed-point theorems (recursion theorems) by Kleene, Rogers, and Smullyan.

[Applicative_Lifting] title = Applicative Lifting author = Andreas Lochbihler , Joshua Schneider <> date = 2015-12-22 topic = Computer science/Functional programming abstract = Applicative functors augment computations with effects by lifting function application to types which model the effects. As the structure of the computation cannot depend on the effects, applicative expressions can be analysed statically. This allows us to lift universally quantified equations to the effectful types, as observed by Hinze. Thus, equational reasoning over effectful computations can be reduced to pure types.

This entry provides a package for registering applicative functors and two proof methods for lifting of equations over applicative functors. The first method normalises applicative expressions according to the laws of applicative functors. This way, equations whose two sides contain the same list of variables can be lifted to every applicative functor.

To lift larger classes of equations, the second method exploits a number of additional properties (e.g., commutativity of effects) provided the properties have been declared for the concrete applicative functor at hand upon registration.

We declare several types from the Isabelle library as applicative functors and illustrate the use of the methods with two examples: the lifting of the arithmetic type class hierarchy to streams and the verification of a relabelling function on binary trees. We also formalise and verify the normalisation algorithm used by the first proof method.

extra-history = Change history: [2016-03-03]: added formalisation of lifting with combinators
[2016-06-10]: implemented automatic derivation of lifted combinator reductions; support arbitrary lifted relations using relators; improved compatibility with locale interpretation (revision ec336f354f37)
notify = mail@andreas-lochbihler.de [Stern_Brocot] title = The Stern-Brocot Tree author = Peter Gammie , Andreas Lochbihler date = 2015-12-22 topic = Mathematics/Number theory abstract = The Stern-Brocot tree contains all rational numbers exactly once and in their lowest terms. We formalise the Stern-Brocot tree as a coinductive tree using recursive and iterative specifications, which we have proven equivalent, and show that it indeed contains all the numbers as stated. Following Hinze, we prove that the Stern-Brocot tree can be linearised looplessly into Stern's diatonic sequence (also known as Dijkstra's fusc function) and that it is a permutation of the Bird tree.

The reasoning stays at an abstract level by appealing to the uniqueness of solutions of guarded recursive equations and lifting algebraic laws point-wise to trees and streams using applicative functors.

notify = mail@andreas-lochbihler.de [Algebraic_Numbers] title = Algebraic Numbers in Isabelle/HOL topic = Mathematics/Algebra author = René Thiemann , Akihisa Yamada , Sebastiaan Joosten contributors = Manuel Eberl date = 2015-12-22 abstract = Based on existing libraries for matrices, factorization of rational polynomials, and Sturm's theorem, we formalized algebraic numbers in Isabelle/HOL. Our development serves as an implementation for real and complex numbers, and it admits to compute roots and completely factorize real and complex polynomials, provided that all coefficients are rational numbers. Moreover, we provide two implementations to display algebraic numbers, an injective and expensive one, or a faster but approximative version.

To this end, we mechanized several results on resultants, which also required us to prove that polynomials over a unique factorization domain form again a unique factorization domain.

extra-history = Change history: [2016-01-29]: Split off Polynomial Interpolation and Polynomial Factorization
[2017-04-16]: Use certified Berlekamp-Zassenhaus factorization, use subresultant algorithm for computing resultants, improved bisection algorithm notify = rene.thiemann@uibk.ac.at, ayamada@trs.cm.is.nagoya-u.ac.jp, sebastiaan.joosten@uibk.ac.at [Polynomial_Interpolation] title = Polynomial Interpolation topic = Mathematics/Algebra author = René Thiemann , Akihisa Yamada date = 2016-01-29 abstract = We formalized three algorithms for polynomial interpolation over arbitrary fields: Lagrange's explicit expression, the recursive algorithm of Neville and Aitken, and the Newton interpolation in combination with an efficient implementation of divided differences. Variants of these algorithms for integer polynomials are also available, where sometimes the interpolation can fail; e.g., there is no linear integer polynomial p such that p(0) = 0 and p(2) = 1. Moreover, for the Newton interpolation for integer polynomials, we proved that all intermediate results that are computed during the algorithm must be integers. This admits an early failure detection in the implementation. Finally, we proved the uniqueness of polynomial interpolation.

The development also contains improved code equations to speed up the division of integers in target languages. notify = rene.thiemann@uibk.ac.at, ayamada@trs.cm.is.nagoya-u.ac.jp [Polynomial_Factorization] title = Polynomial Factorization topic = Mathematics/Algebra author = René Thiemann , Akihisa Yamada date = 2016-01-29 abstract = Based on existing libraries for polynomial interpolation and matrices, we formalized several factorization algorithms for polynomials, including Kronecker's algorithm for integer polynomials, Yun's square-free factorization algorithm for field polynomials, and Berlekamp's algorithm for polynomials over finite fields. By combining the last one with Hensel's lifting, we derive an efficient factorization algorithm for the integer polynomials, which is then lifted for rational polynomials by mechanizing Gauss' lemma. Finally, we assembled a combined factorization algorithm for rational polynomials, which combines all the mentioned algorithms and additionally uses the explicit formula for roots of quadratic polynomials and a rational root test.

As side products, we developed division algorithms for polynomials over integral domains, as well as primality-testing and prime-factorization algorithms for integers. notify = rene.thiemann@uibk.ac.at, ayamada@trs.cm.is.nagoya-u.ac.jp [Perron_Frobenius] title = Perron-Frobenius Theorem for Spectral Radius Analysis author = Jose Divasón , Ondřej Kunčar , René Thiemann , Akihisa Yamada notify = rene.thiemann@uibk.ac.at date = 2016-05-20 topic = Mathematics/Algebra abstract =

The spectral radius of a matrix A is the maximum norm of all eigenvalues of A. In previous work we already formalized that for a complex matrix A, the values in An grow polynomially in n if and only if the spectral radius is at most one. One problem with the above characterization is the determination of all complex eigenvalues. In case A contains only non-negative real values, a simplification is possible with the help of the Perron–Frobenius theorem, which tells us that it suffices to consider only the real eigenvalues of A, i.e., applying Sturm's method can decide the polynomial growth of An.

We formalize the Perron–Frobenius theorem based on a proof via Brouwer's fixpoint theorem, which is available in the HOL multivariate analysis (HMA) library. Since the results on the spectral radius is based on matrices in the Jordan normal form (JNF) library, we further develop a connection which allows us to easily transfer theorems between HMA and JNF. With this connection we derive the combined result: if A is a non-negative real matrix, and no real eigenvalue of A is strictly larger than one, then An is polynomially bounded in n.

extra-history = Change history: [2017-10-18]: added Perron-Frobenius theorem for irreducible matrices with generalization (revision bda1f1ce8a1c)
[2018-05-17]: prove conjecture of CPP'18 paper: Jordan blocks of spectral radius have maximum size (revision ffdb3794e5d5) [Stochastic_Matrices] title = Stochastic Matrices and the Perron-Frobenius Theorem author = René Thiemann topic = Mathematics/Algebra, Computer science/Automata and formal languages date = 2017-11-22 notify = rene.thiemann@uibk.ac.at abstract = Stochastic matrices are a convenient way to model discrete-time and finite state Markov chains. The Perron–Frobenius theorem tells us something about the existence and uniqueness of non-negative eigenvectors of a stochastic matrix. In this entry, we formalize stochastic matrices, link the formalization to the existing AFP-entry on Markov chains, and apply the Perron–Frobenius theorem to prove that stationary distributions always exist, and they are unique if the stochastic matrix is irreducible. [Formal_SSA] title = Verified Construction of Static Single Assignment Form author = Sebastian Ullrich , Denis Lohner date = 2016-02-05 topic = Computer science/Algorithms, Computer science/Programming languages/Transformations abstract =

We define a functional variant of the static single assignment (SSA) form construction algorithm described by Braun et al., which combines simplicity and efficiency. The definition is based on a general, abstract control flow graph representation using Isabelle locales.

We prove that the algorithm's output is semantically equivalent to the input according to a small-step semantics, and that it is in minimal SSA form for the common special case of reducible inputs. We then show the satisfiability of the locale assumptions by giving instantiations for a simple While language.

Furthermore, we use a generic instantiation based on typedefs in order to extract OCaml code and replace the unverified SSA construction algorithm of the CompCertSSA project with it.

A more detailed description of the verified SSA construction can be found in the paper Verified Construction of Static Single Assignment Form, CC 2016.

notify = denis.lohner@kit.edu [Minimal_SSA] title = Minimal Static Single Assignment Form author = Max Wagner , Denis Lohner topic = Computer science/Programming languages/Transformations date = 2017-01-17 notify = denis.lohner@kit.edu abstract =

This formalization is an extension to "Verified Construction of Static Single Assignment Form". In their work, the authors have shown that Braun et al.'s static single assignment (SSA) construction algorithm produces minimal SSA form for input programs with a reducible control flow graph (CFG). However Braun et al. also proposed an extension to their algorithm that they claim produces minimal SSA form even for irreducible CFGs.
In this formalization we support that claim by giving a mechanized proof.

As the extension of Braun et al.'s algorithm aims for removing so-called redundant strongly connected components of phi functions, we show that this suffices to guarantee minimality according to Cytron et al..

[PropResPI] title = Propositional Resolution and Prime Implicates Generation author = Nicolas Peltier notify = Nicolas.Peltier@imag.fr date = 2016-03-11 topic = Logic/General logic/Mechanization of proofs abstract = We provide formal proofs in Isabelle-HOL (using mostly structured Isar proofs) of the soundness and completeness of the Resolution rule in propositional logic. The completeness proofs take into account the usual redundancy elimination rules (tautology elimination and subsumption), and several refinements of the Resolution rule are considered: ordered resolution (with selection functions), positive and negative resolution, semantic resolution and unit resolution (the latter refinement is complete only for clause sets that are Horn- renamable). We also define a concrete procedure for computing saturated sets and establish its soundness and completeness. The clause sets are not assumed to be finite, so that the results can be applied to formulas obtained by grounding sets of first-order clauses (however, a total ordering among atoms is assumed to be given). Next, we show that the unrestricted Resolution rule is deductive- complete, in the sense that it is able to generate all (prime) implicates of any set of propositional clauses (i.e., all entailment- minimal, non-valid, clausal consequences of the considered set). The generation of prime implicates is an important problem, with many applications in artificial intelligence and verification (for abductive reasoning, knowledge compilation, diagnosis, debugging etc.). We also show that implicates can be computed in an incremental way, by fixing an ordering among all the atoms in the considered sets and resolving upon these atoms one by one in the considered order (with no backtracking). This feature is critical for the efficient computation of prime implicates. Building on these results, we provide a procedure for computing such implicates and establish its soundness and completeness. [SuperCalc] title = A Variant of the Superposition Calculus author = Nicolas Peltier notify = Nicolas.Peltier@imag.fr date = 2016-09-06 topic = Logic/Proof theory abstract = We provide a formalization of a variant of the superposition calculus, together with formal proofs of soundness and refutational completeness (w.r.t. the usual redundancy criteria based on clause ordering). This version of the calculus uses all the standard restrictions of the superposition rules, together with the following refinement, inspired by the basic superposition calculus: each clause is associated with a set of terms which are assumed to be in normal form -- thus any application of the replacement rule on these terms is blocked. The set is initially empty and terms may be added or removed at each inference step. The set of terms that are assumed to be in normal form includes any term introduced by previous unifiers as well as any term occurring in the parent clauses at a position that is smaller (according to some given ordering on positions) than a previously replaced term. The standard superposition calculus corresponds to the case where the set of irreducible terms is always empty. [Nominal2] title = Nominal 2 author = Christian Urban , Stefan Berghofer , Cezary Kaliszyk date = 2013-02-21 topic = Tools abstract =

Dealing with binders, renaming of bound variables, capture-avoiding substitution, etc., is very often a major problem in formal proofs, especially in proofs by structural and rule induction. Nominal Isabelle is designed to make such proofs easy to formalise: it provides an infrastructure for declaring nominal datatypes (that is alpha-equivalence classes) and for defining functions over them by structural recursion. It also provides induction principles that have Barendregt’s variable convention already built in.

This entry can be used as a more advanced replacement for HOL/Nominal in the Isabelle distribution.

notify = christian.urban@kcl.ac.uk [First_Welfare_Theorem] title = Microeconomics and the First Welfare Theorem author = Julian Parsert , Cezary Kaliszyk topic = Mathematics/Games and economics license = LGPL date = 2017-09-01 notify = julian.parsert@uibk.ac.at, cezary.kaliszyk@uibk.ac.at abstract = Economic activity has always been a fundamental part of society. Due to modern day politics, economic theory has gained even more influence on our lives. Thus we want models and theories to be as precise as possible. This can be achieved using certification with the help of formal proof technology. Hence we will use Isabelle/HOL to construct two economic models, that of the the pure exchange economy and a version of the Arrow-Debreu Model. We will prove that the First Theorem of Welfare Economics holds within both. The theorem is the mathematical formulation of Adam Smith's famous invisible hand and states that a group of self-interested and rational actors will eventually achieve an efficient allocation of goods and services. extra-history = Change history: [2018-06-17]: Added some lemmas and a theory file, also introduced Microeconomics folder.
[Noninterference_Sequential_Composition] title = Conservation of CSP Noninterference Security under Sequential Composition author = Pasquale Noce date = 2016-04-26 topic = Computer science/Security, Computer science/Concurrency/Process calculi abstract =

In his outstanding work on Communicating Sequential Processes, Hoare has defined two fundamental binary operations allowing to compose the input processes into another, typically more complex, process: sequential composition and concurrent composition. Particularly, the output of the former operation is a process that initially behaves like the first operand, and then like the second operand once the execution of the first one has terminated successfully, as long as it does.

This paper formalizes Hoare's definition of sequential composition and proves, in the general case of a possibly intransitive policy, that CSP noninterference security is conserved under this operation, provided that successful termination cannot be affected by confidential events and cannot occur as an alternative to other events in the traces of the first operand. Both of these assumptions are shown, by means of counterexamples, to be necessary for the theorem to hold.

notify = pasquale.noce.lavoro@gmail.com [Noninterference_Concurrent_Composition] title = Conservation of CSP Noninterference Security under Concurrent Composition author = Pasquale Noce notify = pasquale.noce.lavoro@gmail.com date = 2016-06-13 topic = Computer science/Security, Computer science/Concurrency/Process calculi abstract =

In his outstanding work on Communicating Sequential Processes, Hoare has defined two fundamental binary operations allowing to compose the input processes into another, typically more complex, process: sequential composition and concurrent composition. Particularly, the output of the latter operation is a process in which any event not shared by both operands can occur whenever the operand that admits the event can engage in it, whereas any event shared by both operands can occur just in case both can engage in it.

This paper formalizes Hoare's definition of concurrent composition and proves, in the general case of a possibly intransitive policy, that CSP noninterference security is conserved under this operation. This result, along with the previous analogous one concerning sequential composition, enables the construction of more and more complex processes enforcing noninterference security by composing, sequentially or concurrently, simpler secure processes, whose security can in turn be proven using either the definition of security, or unwinding theorems.

[ROBDD] title = Algorithms for Reduced Ordered Binary Decision Diagrams author = Julius Michaelis , Maximilian Haslbeck , Peter Lammich , Lars Hupel date = 2016-04-27 topic = Computer science/Algorithms, Computer science/Data structures abstract = We present a verified and executable implementation of ROBDDs in Isabelle/HOL. Our implementation relates pointer-based computation in the Heap monad to operations on an abstract definition of boolean functions. Internally, we implemented the if-then-else combinator in a recursive fashion, following the Shannon decomposition of the argument functions. The implementation mixes and adapts known techniques and is built with efficiency in mind. notify = bdd@liftm.de, haslbecm@in.tum.de [No_FTL_observers] title = No Faster-Than-Light Observers author = Mike Stannett , István Németi date = 2016-04-28 topic = Mathematics/Physics abstract = We provide a formal proof within First Order Relativity Theory that no observer can travel faster than the speed of light. Originally reported in Stannett & Németi (2014) "Using Isabelle/HOL to verify first-order relativity theory", Journal of Automated Reasoning 52(4), pp. 361-378. notify = m.stannett@sheffield.ac.uk [Groebner_Bases] title = Gröbner Bases Theory author = Fabian Immler , Alexander Maletzky date = 2016-05-02 topic = Mathematics/Algebra, Computer science/Algorithms/Mathematical abstract = This formalization is concerned with the theory of Gröbner bases in (commutative) multivariate polynomial rings over fields, originally developed by Buchberger in his 1965 PhD thesis. Apart from the statement and proof of the main theorem of the theory, the formalization also implements Buchberger's algorithm for actually computing Gröbner bases as a tail-recursive function, thus allowing to effectively decide ideal membership in finitely generated polynomial ideals. Furthermore, all functions can be executed on a concrete representation of multivariate polynomials as association lists. extra-history = Change history: [2019-04-18]: Specialized Gröbner bases to less abstract representation of polynomials, where power-products are represented as polynomial mappings.
notify = alexander.maletzky@risc.jku.at [Nullstellensatz] title = Hilbert's Nullstellensatz author = Alexander Maletzky topic = Mathematics/Algebra, Mathematics/Geometry date = 2019-06-16 notify = alexander.maletzky@risc-software.at abstract = This entry formalizes Hilbert's Nullstellensatz, an important theorem in algebraic geometry that can be viewed as the generalization of the Fundamental Theorem of Algebra to multivariate polynomials: If a set of (multivariate) polynomials over an algebraically closed field has no common zero, then the ideal it generates is the entire polynomial ring. The formalization proves several equivalent versions of this celebrated theorem: the weak Nullstellensatz, the strong Nullstellensatz (connecting algebraic varieties and radical ideals), and the field-theoretic Nullstellensatz. The formalization follows Chapter 4.1. of Ideals, Varieties, and Algorithms by Cox, Little and O'Shea. [Bell_Numbers_Spivey] title = Spivey's Generalized Recurrence for Bell Numbers author = Lukas Bulwahn date = 2016-05-04 topic = Mathematics/Combinatorics abstract = This entry defines the Bell numbers as the cardinality of set partitions for a carrier set of given size, and derives Spivey's generalized recurrence relation for Bell numbers following his elegant and intuitive combinatorial proof.

As the set construction for the combinatorial proof requires construction of three intermediate structures, the main difficulty of the formalization is handling the overall combinatorial argument in a structured way. The introduced proof structure allows us to compose the combinatorial argument from its subparts, and supports to keep track how the detailed proof steps are related to the overall argument. To obtain this structure, this entry uses set monad notation for the set construction's definition, introduces suitable predicates and rules, and follows a repeating structure in its Isar proof. notify = lukas.bulwahn@gmail.com [Randomised_Social_Choice] title = Randomised Social Choice Theory author = Manuel Eberl date = 2016-05-05 topic = Mathematics/Games and economics abstract = This work contains a formalisation of basic Randomised Social Choice, including Stochastic Dominance and Social Decision Schemes (SDSs) along with some of their most important properties (Anonymity, Neutrality, ex-post- and SD-Efficiency, SD-Strategy-Proofness) and two particular SDSs – Random Dictatorship and Random Serial Dictatorship (with proofs of the properties that they satisfy). Many important properties of these concepts are also proven – such as the two equivalent characterisations of Stochastic Dominance and the fact that SD-efficiency of a lottery only depends on the support. The entry also provides convenient commands to define Preference Profiles, prove their well-formedness, and automatically derive restrictions that sufficiently nice SDSs need to satisfy on the defined profiles. Currently, the formalisation focuses on weak preferences and Stochastic Dominance, but it should be easy to extend it to other domains – such as strict preferences – or other lottery extensions – such as Bilinear Dominance or Pairwise Comparison. notify = eberlm@in.tum.de [SDS_Impossibility] title = The Incompatibility of SD-Efficiency and SD-Strategy-Proofness author = Manuel Eberl date = 2016-05-04 topic = Mathematics/Games and economics abstract = This formalisation contains the proof that there is no anonymous and neutral Social Decision Scheme for at least four voters and alternatives that fulfils both SD-Efficiency and SD-Strategy- Proofness. The proof is a fully structured and quasi-human-redable one. It was derived from the (unstructured) SMT proof of the case for exactly four voters and alternatives by Brandl et al. Their proof relies on an unverified translation of the original problem to SMT, and the proof that lifts the argument for exactly four voters and alternatives to the general case is also not machine-checked. In this Isabelle proof, on the other hand, all of these steps are fully proven and machine-checked. This is particularly important seeing as a previously published informal proof of a weaker statement contained a mistake in precisely this lifting step. notify = eberlm@in.tum.de [Median_Of_Medians_Selection] title = The Median-of-Medians Selection Algorithm author = Manuel Eberl topic = Computer science/Algorithms date = 2017-12-21 notify = eberlm@in.tum.de abstract =

This entry provides an executable functional implementation of the Median-of-Medians algorithm for selecting the k-th smallest element of an unsorted list deterministically in linear time. The size bounds for the recursive call that lead to the linear upper bound on the run-time of the algorithm are also proven.

[Mason_Stothers] title = The Mason–Stothers Theorem author = Manuel Eberl topic = Mathematics/Algebra date = 2017-12-21 notify = eberlm@in.tum.de abstract =

This article provides a formalisation of Snyder’s simple and elegant proof of the Mason–Stothers theorem, which is the polynomial analogue of the famous abc Conjecture for integers. Remarkably, Snyder found this very elegant proof when he was still a high-school student.

In short, the statement of the theorem is that three non-zero coprime polynomials A, B, C over a field which sum to 0 and do not all have vanishing derivatives fulfil max{deg(A), deg(B), deg(C)} < deg(rad(ABC)) where the rad(P) denotes the radical of P, i. e. the product of all unique irreducible factors of P.

This theorem also implies a kind of polynomial analogue of Fermat’s Last Theorem for polynomials: except for trivial cases, An + Bn + Cn = 0 implies n ≤ 2 for coprime polynomials A, B, C over a field.

[FLP] title = A Constructive Proof for FLP author = Benjamin Bisping , Paul-David Brodmann , Tim Jungnickel , Christina Rickmann , Henning Seidler , Anke Stüber , Arno Wilhelm-Weidner , Kirstin Peters , Uwe Nestmann date = 2016-05-18 topic = Computer science/Concurrency abstract = The impossibility of distributed consensus with one faulty process is a result with important consequences for real world distributed systems e.g., commits in replicated databases. Since proofs are not immune to faults and even plausible proofs with a profound formalism can conclude wrong results, we validate the fundamental result named FLP after Fischer, Lynch and Paterson. We present a formalization of distributed systems and the aforementioned consensus problem. Our proof is based on Hagen Völzer's paper "A constructive proof for FLP". In addition to the enhanced confidence in the validity of Völzer's proof, we contribute the missing gaps to show the correctness in Isabelle/HOL. We clarify the proof details and even prove fairness of the infinite execution that contradicts consensus. Our Isabelle formalization can also be reused for further proofs of properties of distributed systems. notify = henning.seidler@mailbox.tu-berlin.de [IMAP-CRDT] title = The IMAP CmRDT author = Tim Jungnickel , Lennart Oldenburg <>, Matthias Loibl <> topic = Computer science/Algorithms/Distributed, Computer science/Data structures date = 2017-11-09 notify = tim.jungnickel@tu-berlin.de abstract = We provide our Isabelle/HOL formalization of a Conflict-free Replicated Datatype for Internet Message Access Protocol commands. We show that Strong Eventual Consistency (SEC) is guaranteed by proving the commutativity of concurrent operations. We base our formalization on the recently proposed "framework for establishing Strong Eventual Consistency for Conflict-free Replicated Datatypes" (AFP.CRDT) from Gomes et al. Hence, we provide an additional example of how the recently proposed framework can be used to design and prove CRDTs. [Incredible_Proof_Machine] title = The meta theory of the Incredible Proof Machine author = Joachim Breitner , Denis Lohner date = 2016-05-20 topic = Logic/Proof theory abstract = The Incredible Proof Machine is an interactive visual theorem prover which represents proofs as port graphs. We model this proof representation in Isabelle, and prove that it is just as powerful as natural deduction. notify = mail@joachim-breitner.de [Word_Lib] title = Finite Machine Word Library author = Joel Beeren<>, Matthew Fernandez<>, Xin Gao<>, Gerwin Klein , Rafal Kolanski<>, Japheth Lim<>, Corey Lewis<>, Daniel Matichuk<>, Thomas Sewell<> notify = kleing@unsw.edu.au date = 2016-06-09 topic = Computer science/Data structures abstract = This entry contains an extension to the Isabelle library for fixed-width machine words. In particular, the entry adds quickcheck setup for words, printing as hexadecimals, additional operations, reasoning about alignment, signed words, enumerations of words, normalisation of word numerals, and an extensive library of properties about generic fixed-width words, as well as an instantiation of many of these to the commonly used 32 and 64-bit bases. [Catalan_Numbers] title = Catalan Numbers author = Manuel Eberl notify = eberlm@in.tum.de date = 2016-06-21 topic = Mathematics/Combinatorics abstract =

In this work, we define the Catalan numbers Cn and prove several equivalent definitions (including some closed-form formulae). We also show one of their applications (counting the number of binary trees of size n), prove the asymptotic growth approximation Cn ∼ 4n / (√π · n1.5), and provide reasonably efficient executable code to compute them.

The derivation of the closed-form formulae uses algebraic manipulations of the ordinary generating function of the Catalan numbers, and the asymptotic approximation is then done using generalised binomial coefficients and the Gamma function. Thanks to these highly non-elementary mathematical tools, the proofs are very short and simple.

[Fisher_Yates] title = Fisher–Yates shuffle author = Manuel Eberl notify = eberlm@in.tum.de date = 2016-09-30 topic = Computer science/Algorithms abstract =

This work defines and proves the correctness of the Fisher–Yates algorithm for shuffling – i.e. producing a random permutation – of a list. The algorithm proceeds by traversing the list and in each step swapping the current element with a random element from the remaining list.

[Bertrands_Postulate] title = Bertrand's postulate author = Julian Biendarra<>, Manuel Eberl contributors = Lawrence C. Paulson topic = Mathematics/Number theory date = 2017-01-17 notify = eberlm@in.tum.de abstract =

Bertrand's postulate is an early result on the distribution of prime numbers: For every positive integer n, there exists a prime number that lies strictly between n and 2n. The proof is ported from John Harrison's formalisation in HOL Light. It proceeds by first showing that the property is true for all n greater than or equal to 600 and then showing that it also holds for all n below 600 by case distinction.

[Rewriting_Z] title = The Z Property author = Bertram Felgenhauer<>, Julian Nagele<>, Vincent van Oostrom<>, Christian Sternagel notify = bertram.felgenhauer@uibk.ac.at, julian.nagele@uibk.ac.at, c.sternagel@gmail.com date = 2016-06-30 topic = Logic/Rewriting abstract = We formalize the Z property introduced by Dehornoy and van Oostrom. First we show that for any abstract rewrite system, Z implies confluence. Then we give two examples of proofs using Z: confluence of lambda-calculus with respect to beta-reduction and confluence of combinatory logic. [Resolution_FOL] title = The Resolution Calculus for First-Order Logic author = Anders Schlichtkrull notify = andschl@dtu.dk date = 2016-06-30 topic = Logic/General logic/Mechanization of proofs abstract = This theory is a formalization of the resolution calculus for first-order logic. It is proven sound and complete. The soundness proof uses the substitution lemma, which shows a correspondence between substitutions and updates to an environment. The completeness proof uses semantic trees, i.e. trees whose paths are partial Herbrand interpretations. It employs Herbrand's theorem in a formulation which states that an unsatisfiable set of clauses has a finite closed semantic tree. It also uses the lifting lemma which lifts resolution derivation steps from the ground world up to the first-order world. The theory is presented in a paper in the Journal of Automated Reasoning [Sch18] which extends a paper presented at the International Conference on Interactive Theorem Proving [Sch16]. An earlier version was presented in an MSc thesis [Sch15]. The formalization mostly follows textbooks by Ben-Ari [BA12], Chang and Lee [CL73], and Leitsch [Lei97]. The theory is part of the IsaFoL project [IsaFoL].

[Sch18] Anders Schlichtkrull. "Formalization of the Resolution Calculus for First-Order Logic". Journal of Automated Reasoning, 2018.
[Sch16] Anders Schlichtkrull. "Formalization of the Resolution Calculus for First-Order Logic". In: ITP 2016. Vol. 9807. LNCS. Springer, 2016.
[Sch15] Anders Schlichtkrull. "Formalization of Resolution Calculus in Isabelle". https://people.compute.dtu.dk/andschl/Thesis.pdf. MSc thesis. Technical University of Denmark, 2015.
[BA12] Mordechai Ben-Ari. Mathematical Logic for Computer Science. 3rd. Springer, 2012.
[CL73] Chin-Liang Chang and Richard Char-Tung Lee. Symbolic Logic and Mechanical Theorem Proving. 1st. Academic Press, Inc., 1973.
[Lei97] Alexander Leitsch. The Resolution Calculus. Texts in theoretical computer science. Springer, 1997.
[IsaFoL] IsaFoL authors. IsaFoL: Isabelle Formalization of Logic. https://bitbucket.org/jasmin_blanchette/isafol. extra-history = Change history: [2018-01-24]: added several new versions of the soundness and completeness theorems as described in the paper [Sch18].
[2018-03-20]: added a concrete instance of the unification and completeness theorems using the First-Order Terms AFP-entry from IsaFoR as described in the papers [Sch16] and [Sch18]. [Surprise_Paradox] title = Surprise Paradox author = Joachim Breitner notify = mail@joachim-breitner.de date = 2016-07-17 topic = Logic/Proof theory abstract = In 1964, Fitch showed that the paradox of the surprise hanging can be resolved by showing that the judge’s verdict is inconsistent. His formalization builds on Gödel’s coding of provability. In this theory, we reproduce his proof in Isabelle, building on Paulson’s formalisation of Gödel’s incompleteness theorems. [Ptolemys_Theorem] title = Ptolemy's Theorem author = Lukas Bulwahn notify = lukas.bulwahn@gmail.com date = 2016-08-07 topic = Mathematics/Geometry abstract = This entry provides an analytic proof to Ptolemy's Theorem using polar form transformation and trigonometric identities. In this formalization, we use ideas from John Harrison's HOL Light formalization and the proof sketch on the Wikipedia entry of Ptolemy's Theorem. This theorem is the 95th theorem of the Top 100 Theorems list. [Falling_Factorial_Sum] title = The Falling Factorial of a Sum author = Lukas Bulwahn topic = Mathematics/Combinatorics date = 2017-12-22 notify = lukas.bulwahn@gmail.com abstract = This entry shows that the falling factorial of a sum can be computed with an expression using binomial coefficients and the falling factorial of its summands. The entry provides three different proofs: a combinatorial proof, an induction proof and an algebraic proof using the Vandermonde identity. The three formalizations try to follow their informal presentations from a Mathematics Stack Exchange page as close as possible. The induction and algebraic formalization end up to be very close to their informal presentation, whereas the combinatorial proof first requires the introduction of list interleavings, and significant more detail than its informal presentation. [InfPathElimination] title = Infeasible Paths Elimination by Symbolic Execution Techniques: Proof of Correctness and Preservation of Paths author = Romain Aissat<>, Frederic Voisin<>, Burkhart Wolff notify = wolff@lri.fr date = 2016-08-18 topic = Computer science/Programming languages/Static analysis abstract = TRACER is a tool for verifying safety properties of sequential C programs. TRACER attempts at building a finite symbolic execution graph which over-approximates the set of all concrete reachable states and the set of feasible paths. We present an abstract framework for TRACER and similar CEGAR-like systems. The framework provides 1) a graph- transformation based method for reducing the feasible paths in control-flow graphs, 2) a model for symbolic execution, subsumption, predicate abstraction and invariant generation. In this framework we formally prove two key properties: correct construction of the symbolic states and preservation of feasible paths. The framework focuses on core operations, leaving to concrete prototypes to “fit in” heuristics for combining them. The accompanying paper (published in ITP 2016) can be found at https://www.lri.fr/∼wolff/papers/conf/2016-itp-InfPathsNSE.pdf. [Stirling_Formula] title = Stirling's formula author = Manuel Eberl notify = eberlm@in.tum.de date = 2016-09-01 topic = Mathematics/Analysis abstract =

This work contains a proof of Stirling's formula both for the factorial $n! \sim \sqrt{2\pi n} (n/e)^n$ on natural numbers and the real Gamma function $\Gamma(x)\sim \sqrt{2\pi/x} (x/e)^x$. The proof is based on work by Graham Jameson.

This is then extended to the full asymptotic expansion $$\log\Gamma(z) = \big(z - \tfrac{1}{2}\big)\log z - z + \tfrac{1}{2}\log(2\pi) + \sum_{k=1}^{n-1} \frac{B_{k+1}}{k(k+1)} z^{-k}\\ {} - \frac{1}{n} \int_0^\infty B_n([t])(t + z)^{-n}\,\text{d}t$$ uniformly for all complex $z\neq 0$ in the cone $\text{arg}(z)\leq \alpha$ for any $\alpha\in(0,\pi)$, with which the above asymptotic relation for Γ is also extended to complex arguments.

[Lp] title = Lp spaces author = Sebastien Gouezel notify = sebastien.gouezel@univ-rennes1.fr date = 2016-10-05 topic = Mathematics/Analysis abstract = Lp is the space of functions whose p-th power is integrable. It is one of the most fundamental Banach spaces that is used in analysis and probability. We develop a framework for function spaces, and then implement the Lp spaces in this framework using the existing integration theory in Isabelle/HOL. Our development contains most fundamental properties of Lp spaces, notably the Hölder and Minkowski inequalities, completeness of Lp, duality, stability under almost sure convergence, multiplication of functions in Lp and Lq, stability under conditional expectation. [Berlekamp_Zassenhaus] title = The Factorization Algorithm of Berlekamp and Zassenhaus author = Jose Divasón , Sebastiaan Joosten , René Thiemann , Akihisa Yamada notify = rene.thiemann@uibk.ac.at date = 2016-10-14 topic = Mathematics/Algebra abstract =

We formalize the Berlekamp-Zassenhaus algorithm for factoring square-free integer polynomials in Isabelle/HOL. We further adapt an existing formalization of Yun’s square-free factorization algorithm to integer polynomials, and thus provide an efficient and certified factorization algorithm for arbitrary univariate polynomials.

The algorithm first performs a factorization in the prime field GF(p) and then performs computations in the integer ring modulo p^k, where both p and k are determined at runtime. Since a natural modeling of these structures via dependent types is not possible in Isabelle/HOL, we formalize the whole algorithm using Isabelle’s recent addition of local type definitions.

Through experiments we verify that our algorithm factors polynomials of degree 100 within seconds.

[Allen_Calculus] title = Allen's Interval Calculus author = Fadoua Ghourabi <> notify = fadouaghourabi@gmail.com date = 2016-09-29 topic = Logic/General logic/Temporal logic, Mathematics/Order abstract = Allen’s interval calculus is a qualitative temporal representation of time events. Allen introduced 13 binary relations that describe all the possible arrangements between two events, i.e. intervals with non-zero finite length. The compositions are pertinent to reasoning about knowledge of time. In particular, a consistency problem of relation constraints is commonly solved with a guideline from these compositions. We formalize the relations together with an axiomatic system. We proof the validity of the 169 compositions of these relations. We also define nests as the sets of intervals that share a meeting point. We prove that nests give the ordering properties of points without introducing a new datatype for points. [1] J.F. Allen. Maintaining Knowledge about Temporal Intervals. In Commun. ACM, volume 26, pages 832–843, 1983. [2] J. F. Allen and P. J. Hayes. A Common-sense Theory of Time. In Proceedings of the 9th International Joint Conference on Artificial Intelligence (IJCAI’85), pages 528–531, 1985. [Source_Coding_Theorem] title = Source Coding Theorem author = Quentin Hibon , Lawrence C. Paulson notify = qh225@cl.cam.ac.uk date = 2016-10-19 topic = Mathematics/Probability theory abstract = This document contains a proof of the necessary condition on the code rate of a source code, namely that this code rate is bounded by the entropy of the source. This represents one half of Shannon's source coding theorem, which is itself an equivalence. [Buffons_Needle] title = Buffon's Needle Problem author = Manuel Eberl topic = Mathematics/Probability theory, Mathematics/Geometry date = 2017-06-06 notify = eberlm@in.tum.de abstract = 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. [SPARCv8] title = A formal model for the SPARCv8 ISA and a proof of non-interference for the LEON3 processor author = Zhe Hou , David Sanan , Alwen Tiu , Yang Liu notify = zhe.hou@ntu.edu.sg, sanan@ntu.edu.sg date = 2016-10-19 topic = Computer science/Security, Computer science/Hardware abstract = We formalise the SPARCv8 instruction set architecture (ISA) which is used in processors such as LEON3. Our formalisation can be specialised to any SPARCv8 CPU, here we use LEON3 as a running example. Our model covers the operational semantics for all the instructions in the integer unit of the SPARCv8 architecture and it supports Isabelle code export, which effectively turns the Isabelle model into a SPARCv8 CPU simulator. We prove the language-based non-interference property for the LEON3 processor. Our model is based on deterministic monad, which is a modified version of the non-deterministic monad from NICTA/l4v. [Separata] title = Separata: Isabelle tactics for Separation Algebra author = Zhe Hou , David Sanan , Alwen Tiu , Rajeev Gore , Ranald Clouston notify = zhe.hou@ntu.edu.sg date = 2016-11-16 topic = Computer science/Programming languages/Logics, Tools abstract = We bring the labelled sequent calculus $LS_{PASL}$ for propositional abstract separation logic to Isabelle. The tactics given here are directly applied on an extension of the Separation Algebra in the AFP. In addition to the cancellative separation algebra, we further consider some useful properties in the heap model of separation logic, such as indivisible unit, disjointness, and cross-split. The tactics are essentially a proof search procedure for the calculus $LS_{PASL}$. We wrap the tactics in an Isabelle method called separata, and give a few examples of separation logic formulae which are provable by separata. [LOFT] title = LOFT — Verified Migration of Linux Firewalls to SDN author = Julius Michaelis , Cornelius Diekmann notify = isabelleopenflow@liftm.de date = 2016-10-21 topic = Computer science/Networks abstract = We present LOFT — Linux firewall OpenFlow Translator, a system that transforms the main routing table and FORWARD chain of iptables of a Linux-based firewall into a set of static OpenFlow rules. Our implementation is verified against a model of a simplified Linux-based router and we can directly show how much of the original functionality is preserved. [Stable_Matching] title = Stable Matching author = Peter Gammie notify = peteg42@gmail.com date = 2016-10-24 topic = Mathematics/Games and economics abstract = We mechanize proofs of several results from the matching with contracts literature, which generalize those of the classical two-sided matching scenarios that go by the name of stable marriage. Our focus is on game theoretic issues. Along the way we develop executable algorithms for computing optimal stable matches. [Modal_Logics_for_NTS] title = Modal Logics for Nominal Transition Systems author = Tjark Weber , Lars-Henrik Eriksson , Joachim Parrow , Johannes Borgström , Ramunas Gutkovas notify = tjark.weber@it.uu.se date = 2016-10-25 topic = Computer science/Concurrency/Process calculi, Logic/General logic/Modal logic abstract = We formalize a uniform semantic substrate for a wide variety of process calculi where states and action labels can be from arbitrary nominal sets. A Hennessy-Milner logic for these systems is defined, and proved adequate for bisimulation equivalence. A main novelty is the construction of an infinitary nominal data type to model formulas with (finitely supported) infinite conjunctions and actions that may contain binding names. The logic is generalized to treat different bisimulation variants such as early, late and open in a systematic way. extra-history = Change history: [2017-01-29]: Formalization of weak bisimilarity added (revision c87cc2057d9c) [Abs_Int_ITP2012] title = Abstract Interpretation of Annotated Commands author = Tobias Nipkow notify = nipkow@in.tum.de date = 2016-11-23 topic = Computer science/Programming languages/Static analysis abstract = This is the Isabelle formalization of the material decribed in the eponymous ITP 2012 paper. It develops a generic abstract interpreter for a while-language, including widening and narrowing. The collecting semantics and the abstract interpreter operate on annotated commands: the program is represented as a syntax tree with the semantic information directly embedded, without auxiliary labels. The aim of the formalization is simplicity, not efficiency or precision. This is motivated by the inclusion of the material in a theorem prover based course on semantics. A similar (but more polished) development is covered in the book Concrete Semantics. [Complx] title = COMPLX: A Verification Framework for Concurrent Imperative Programs author = Sidney Amani<>, June Andronick<>, Maksym Bortin<>, Corey Lewis<>, Christine Rizkallah<>, Joseph Tuong<> notify = sidney.amani@data61.csiro.au, corey.lewis@data61.csiro.au date = 2016-11-29 topic = Computer science/Programming languages/Logics, Computer science/Programming languages/Language definitions abstract = We propose a concurrency reasoning framework for imperative programs, based on the Owicki-Gries (OG) foundational shared-variable concurrency method. Our framework combines the approaches of Hoare-Parallel, a formalisation of OG in Isabelle/HOL for a simple while-language, and Simpl, a generic imperative language embedded in Isabelle/HOL, allowing formal reasoning on C programs. We define the Complx language, extending the syntax and semantics of Simpl with support for parallel composition and synchronisation. We additionally define an OG logic, which we prove sound w.r.t. the semantics, and a verification condition generator, both supporting involved low-level imperative constructs such as function calls and abrupt termination. We illustrate our framework on an example that features exceptions, guards and function calls. We aim to then target concurrent operating systems, such as the interruptible eChronos embedded operating system for which we already have a model-level OG proof using Hoare-Parallel. extra-history = Change history: [2017-01-13]: Improve VCG for nested parallels and sequential sections (revision 30739dbc3dcb) [Paraconsistency] title = Paraconsistency author = Anders Schlichtkrull , Jørgen Villadsen topic = Logic/General logic/Paraconsistent logics date = 2016-12-07 notify = andschl@dtu.dk, jovi@dtu.dk abstract = Paraconsistency is about handling inconsistency in a coherent way. In classical and intuitionistic logic everything follows from an inconsistent theory. A paraconsistent logic avoids the explosion. Quite a few applications in computer science and engineering are discussed in the Intelligent Systems Reference Library Volume 110: Towards Paraconsistent Engineering (Springer 2016). We formalize a paraconsistent many-valued logic that we motivated and described in a special issue on logical approaches to paraconsistency (Journal of Applied Non-Classical Logics 2005). We limit ourselves to the propositional fragment of the higher-order logic. The logic is based on so-called key equalities and has a countably infinite number of truth values. We prove theorems in the logic using the definition of validity. We verify truth tables and also counterexamples for non-theorems. We prove meta-theorems about the logic and finally we investigate a case study. [Proof_Strategy_Language] title = Proof Strategy Language author = Yutaka Nagashima<> topic = Tools date = 2016-12-20 notify = Yutaka.Nagashima@data61.csiro.au abstract = Isabelle includes various automatic tools for finding proofs under certain conditions. However, for each conjecture, knowing which automation to use, and how to tweak its parameters, is currently labour intensive. We have developed a language, PSL, designed to capture high level proof strategies. PSL offloads the construction of human-readable fast-to-replay proof scripts to automatic search, making use of search-time information about each conjecture. Our preliminary evaluations show that PSL reduces the labour cost of interactive theorem proving. This submission contains the implementation of PSL and an example theory file, Example.thy, showing how to write poof strategies in PSL. [Concurrent_Ref_Alg] title = Concurrent Refinement Algebra and Rely Quotients author = Julian Fell , Ian J. Hayes , Andrius Velykis topic = Computer science/Concurrency date = 2016-12-30 notify = Ian.Hayes@itee.uq.edu.au abstract = The concurrent refinement algebra developed here is designed to provide a foundation for rely/guarantee reasoning about concurrent programs. The algebra builds on a complete lattice of commands by providing sequential composition, parallel composition and a novel weak conjunction operator. The weak conjunction operator coincides with the lattice supremum providing its arguments are non-aborting, but aborts if either of its arguments do. Weak conjunction provides an abstract version of a guarantee condition as a guarantee process. We distinguish between models that distribute sequential composition over non-deterministic choice from the left (referred to as being conjunctive in the refinement calculus literature) and those that don't. Least and greatest fixed points of monotone functions are provided to allow recursion and iteration operators to be added to the language. Additional iteration laws are available for conjunctive models. The rely quotient of processes c and i is the process that, if executed in parallel with i implements c. It represents an abstract version of a rely condition generalised to a process. [FOL_Harrison] title = First-Order Logic According to Harrison author = Alexander Birch Jensen , Anders Schlichtkrull , Jørgen Villadsen topic = Logic/General logic/Mechanization of proofs date = 2017-01-01 notify = aleje@dtu.dk, andschl@dtu.dk, jovi@dtu.dk abstract =

We present a certified declarative first-order prover with equality based on John Harrison's Handbook of Practical Logic and Automated Reasoning, Cambridge University Press, 2009. ML code reflection is used such that the entire prover can be executed within Isabelle as a very simple interactive proof assistant. As examples we consider Pelletier's problems 1-46.

Reference: Programming and Verifying a Declarative First-Order Prover in Isabelle/HOL. Alexander Birch Jensen, John Bruntse Larsen, Anders Schlichtkrull & Jørgen Villadsen. AI Communications 31:281-299 2018. https://content.iospress.com/articles/ai-communications/aic764

See also: Students' Proof Assistant (SPA). https://github.com/logic-tools/spa

extra-history = Change history: [2018-07-21]: Proof of Pelletier's problem 34 (Andrews's Challenge) thanks to Asta Halkjær From. [Bernoulli] title = Bernoulli Numbers author = Lukas Bulwahn, Manuel Eberl topic = Mathematics/Analysis, Mathematics/Number theory date = 2017-01-24 notify = eberlm@in.tum.de abstract =

Bernoulli numbers were first discovered in the closed-form expansion of the sum 1m + 2m + … + nm for a fixed m and appear in many other places. This entry provides three different definitions for them: a recursive one, an explicit one, and one through their exponential generating function.

In addition, we prove some basic facts, e.g. their relation to sums of powers of integers and that all odd Bernoulli numbers except the first are zero, and some advanced facts like their relationship to the Riemann zeta function on positive even integers.

We also prove the correctness of the Akiyama–Tanigawa algorithm for computing Bernoulli numbers with reasonable efficiency, and we define the periodic Bernoulli polynomials (which appear e.g. in the Euler–MacLaurin summation formula and the expansion of the log-Gamma function) and prove their basic properties.

[Stone_Relation_Algebras] title = Stone Relation Algebras author = Walter Guttmann topic = Mathematics/Algebra date = 2017-02-07 notify = walter.guttmann@canterbury.ac.nz abstract = 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. [Stone_Kleene_Relation_Algebras] title = Stone-Kleene Relation Algebras author = Walter Guttmann topic = Mathematics/Algebra date = 2017-07-06 notify = walter.guttmann@canterbury.ac.nz abstract = We develop Stone-Kleene relation algebras, which expand Stone relation algebras with a Kleene star operation to describe reachability in weighted graphs. Many properties of the Kleene star arise as a special case of a more general theory of iteration based on Conway semirings extended by simulation axioms. This includes several theorems representing complex program transformations. We formally prove the correctness of Conway's automata-based construction of the Kleene star of a matrix. We prove numerous results useful for reasoning about weighted graphs. [Abstract_Soundness] title = Abstract Soundness author = Jasmin Christian Blanchette , Andrei Popescu , Dmitriy Traytel topic = Logic/Proof theory date = 2017-02-10 notify = jasmin.blanchette@gmail.com abstract = 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 Journal of Automated Reasoning. The abstract proof can be instantiated for various formalisms, including first-order logic with inductive predicates. [Differential_Dynamic_Logic] title = Differential Dynamic Logic author = Brandon Bohrer topic = Logic/General logic/Modal logic, Computer science/Programming languages/Logics date = 2017-02-13 notify = bbohrer@cs.cmu.edu abstract = 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. [Syntax_Independent_Logic] title = Syntax-Independent Logic Infrastructure author = Andrei Popescu , Dmitriy Traytel topic = Logic/Proof theory date = 2020-09-16 notify = a.popescu@sheffield.ac.uk, traytel@di.ku.dk abstract = We formalize a notion of logic whose terms and formulas are kept abstract. In particular, logical connectives, substitution, free variables, and provability are not defined, but characterized by their general properties as locale assumptions. Based on this abstract characterization, we develop further reusable reasoning infrastructure. For example, we define parallel substitution (along with proving its characterizing theorems) from single-point substitution. Similarly, we develop a natural deduction style proof system starting from the abstract Hilbert-style one. These one-time efforts benefit different concrete logics satisfying our locales' assumptions. We instantiate the syntax-independent logic infrastructure to Robinson arithmetic (also known as Q) in the AFP entry Robinson_Arithmetic and to hereditarily finite set theory in the AFP entries Goedel_HFSet_Semantic and Goedel_HFSet_Semanticless, which are part of our formalization of Gödel's Incompleteness Theorems described in our CADE-27 paper A Formally Verified Abstract Account of Gödel's Incompleteness Theorems. [Goedel_Incompleteness] title = An Abstract Formalization of Gödel's Incompleteness Theorems author = Andrei Popescu , Dmitriy Traytel topic = Logic/Proof theory date = 2020-09-16 notify = a.popescu@sheffield.ac.uk, traytel@di.ku.dk abstract = We present an abstract formalization of Gödel's incompleteness theorems. We analyze sufficient conditions for the theorems' applicability to a partially specified logic. Our abstract perspective enables a comparison between alternative approaches from the literature. These include Rosser's variation of the first theorem, Jeroslow's variation of the second theorem, and the Swierczkowski–Paulson semantics-based approach. This AFP entry is the main entry point to the results described in our CADE-27 paper A Formally Verified Abstract Account of Gödel's Incompleteness Theorems. As part of our abstract formalization's validation, we instantiate our locales twice in the separate AFP entries Goedel_HFSet_Semantic and Goedel_HFSet_Semanticless. [Goedel_HFSet_Semantic] title = From Abstract to Concrete Gödel's Incompleteness Theorems—Part I author = Andrei Popescu , Dmitriy Traytel topic = Logic/Proof theory date = 2020-09-16 notify = a.popescu@sheffield.ac.uk, traytel@di.ku.dk abstract = We validate an abstract formulation of Gödel's First and Second Incompleteness Theorems from a separate AFP entry by instantiating them to the case of finite sound extensions of the Hereditarily Finite (HF) Set theory, i.e., FOL theories extending the HF Set theory with a finite set of axioms that are sound in the standard model. The concrete results had been previously formalised in an AFP entry by Larry Paulson; our instantiation reuses the infrastructure developed in that entry. [Goedel_HFSet_Semanticless] title = From Abstract to Concrete Gödel's Incompleteness Theorems—Part II author = Andrei Popescu , Dmitriy Traytel topic = Logic/Proof theory date = 2020-09-16 notify = a.popescu@sheffield.ac.uk, traytel@di.ku.dk abstract = We validate an abstract formulation of Gödel's Second Incompleteness Theorem from a separate AFP entry by instantiating it to the case of finite consistent extensions of the Hereditarily Finite (HF) Set theory, i.e., consistent FOL theories extending the HF Set theory with a finite set of axioms. The instantiation draws heavily on infrastructure previously developed by Larry Paulson in his direct formalisation of the concrete result. It strengthens Paulson's formalization of Gödel's Second from that entry by not assuming soundness, and in fact not relying on any notion of model or semantic interpretation. The strengthening was obtained by first replacing some of Paulson’s semantic arguments with proofs within his HF calculus, and then plugging in some of Paulson's (modified) lemmas to instantiate our soundness-free Gödel's Second locale. [Robinson_Arithmetic] title = Robinson Arithmetic author = Andrei Popescu , Dmitriy Traytel topic = Logic/Proof theory date = 2020-09-16 notify = a.popescu@sheffield.ac.uk, traytel@di.ku.dk abstract = We instantiate our syntax-independent logic infrastructure developed in a separate AFP entry to the FOL theory of Robinson arithmetic (also known as Q). The latter was formalised using Nominal Isabelle by adapting Larry Paulson’s formalization of the Hereditarily Finite Set theory. [Elliptic_Curves_Group_Law] title = The Group Law for Elliptic Curves author = Stefan Berghofer topic = Computer science/Security/Cryptography date = 2017-02-28 notify = berghofe@in.tum.de abstract = 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. [Example-Submission] title = Example Submission author = Gerwin Klein topic = Mathematics/Analysis, Mathematics/Number theory date = 2004-02-25 notify = kleing@cse.unsw.edu.au abstract =

This is an example submission to the Archive of Formal Proofs. It shows submission requirements and explains the structure of a simple typical submission.

Note that you can use HTML tags and LaTeX formulae like $\sum_{n=1}^\infty \frac{1}{n^2} = \frac{\pi^2}{6}$ in the abstract. Display formulae like $$ \int_0^1 x^{-x}\,\text{d}x = \sum_{n=1}^\infty n^{-n}$$ are also possible. Please read the submission guidelines before using this.

extra-no-index = no-index: true [CRDT] title = A framework for establishing Strong Eventual Consistency for Conflict-free Replicated Datatypes author = Victor B. F. Gomes , Martin Kleppmann, Dominic P. Mulligan, Alastair R. Beresford topic = Computer science/Algorithms/Distributed, Computer science/Data structures date = 2017-07-07 notify = vb358@cam.ac.uk, dominic.p.mulligan@googlemail.com abstract = In this work, we focus on the correctness of Conflict-free Replicated Data Types (CRDTs), a class of algorithm that provides strong eventual consistency guarantees for replicated data. We develop a modular and reusable framework for verifying the correctness of CRDT algorithms. We avoid correctness issues that have dogged previous mechanised proofs in this area by including a network model in our formalisation, and proving that our theorems hold in all possible network behaviours. Our axiomatic network model is a standard abstraction that accurately reflects the behaviour of real-world computer networks. Moreover, we identify an abstract convergence theorem, a property of order relations, which provides a formal definition of strong eventual consistency. We then obtain the first machine-checked correctness theorems for three concrete CRDTs: the Replicated Growable Array, the Observed-Remove Set, and an Increment-Decrement Counter. [HOLCF-Prelude] title = HOLCF-Prelude author = Joachim Breitner, Brian Huffman<>, Neil Mitchell<>, Christian Sternagel topic = Computer science/Functional programming date = 2017-07-15 notify = c.sternagel@gmail.com, joachim@cis.upenn.edu, hupel@in.tum.de abstract = The Isabelle/HOLCF-Prelude is a formalization of a large part of Haskell's standard prelude in Isabelle/HOLCF. We use it to prove the correctness of the Eratosthenes' Sieve, in its self-referential implementation commonly used to showcase Haskell's laziness; prove correctness of GHC's "fold/build" rule and related rewrite rules; and certify a number of hints suggested by HLint. [Decl_Sem_Fun_PL] title = Declarative Semantics for Functional Languages author = Jeremy Siek topic = Computer science/Programming languages date = 2017-07-21 notify = jsiek@indiana.edu abstract = We present a semantics for an applied call-by-value lambda-calculus that is compositional, extensional, and elementary. We present four different views of the semantics: 1) as a relational (big-step) semantics that is not operational but instead declarative, 2) as a denotational semantics that does not use domain theory, 3) as a non-deterministic interpreter, and 4) as a variant of the intersection type systems of the Torino group. We prove that the semantics is correct by showing that it is sound and complete with respect to operational semantics on programs and that is sound with respect to contextual equivalence. We have not yet investigated whether it is fully abstract. We demonstrate that this approach to semantics is useful with three case studies. First, we use the semantics to prove correctness of a compiler optimization that inlines function application. Second, we adapt the semantics to the polymorphic lambda-calculus extended with general recursion and prove semantic type soundness. Third, we adapt the semantics to the call-by-value lambda-calculus with mutable references.
The paper that accompanies these Isabelle theories is available on arXiv. [DynamicArchitectures] title = Dynamic Architectures author = Diego Marmsoler topic = Computer science/System description languages date = 2017-07-28 notify = diego.marmsoler@tum.de abstract = The architecture of a system describes the system's overall organization into components and connections between those components. With the emergence of mobile computing, dynamic architectures have become increasingly important. In such architectures, components may appear or disappear, and connections may change over time. In the following we mechanize a theory of dynamic architectures and verify the soundness of a corresponding calculus. Therefore, we first formalize the notion of configuration traces as a model for dynamic architectures. Then, the behavior of single components is formalized in terms of behavior traces and an operator is introduced and studied to extract the behavior of a single component out of a given configuration trace. Then, behavior trace assertions are introduced as a temporal specification technique to specify behavior of components. Reasoning about component behavior in a dynamic context is formalized in terms of a calculus for dynamic architectures. Finally, the soundness of the calculus is verified by introducing an alternative interpretation for behavior trace assertions over configuration traces and proving the rules of the calculus. Since projection may lead to finite as well as infinite behavior traces, they are formalized in terms of coinductive lists. Thus, our theory is based on Lochbihler's formalization of coinductive lists. The theory may be applied to verify properties for dynamic architectures. extra-history = Change history: [2018-06-07]: adding logical operators to specify configuration traces (revision 09178f08f050)
[Stewart_Apollonius] title = Stewart's Theorem and Apollonius' Theorem author = Lukas Bulwahn topic = Mathematics/Geometry date = 2017-07-31 notify = lukas.bulwahn@gmail.com abstract = This entry formalizes the two geometric theorems, Stewart's and Apollonius' theorem. Stewart's Theorem relates the length of a triangle's cevian to the lengths of the triangle's two sides. Apollonius' Theorem is a specialisation of Stewart's theorem, restricting the cevian to be the median. The proof applies the law of cosines, some basic geometric facts about triangles and then simply transforms the terms algebraically to yield the conjectured relation. The formalization in Isabelle can closely follow the informal proofs described in the Wikipedia articles of those two theorems. [LambdaMu] title = The LambdaMu-calculus author = Cristina Matache , Victor B. F. Gomes , Dominic P. Mulligan topic = Computer science/Programming languages/Lambda calculi, Logic/General logic/Lambda calculus date = 2017-08-16 notify = victorborgesfg@gmail.com, dominic.p.mulligan@googlemail.com abstract = The propositions-as-types correspondence is ordinarily presented as linking the metatheory of typed λ-calculi and the proof theory of intuitionistic logic. Griffin observed that this correspondence could be extended to classical logic through the use of control operators. This observation set off a flurry of further research, leading to the development of Parigots λμ-calculus. In this work, we formalise λμ- calculus in Isabelle/HOL and prove several metatheoretical properties such as type preservation and progress. [Orbit_Stabiliser] title = Orbit-Stabiliser Theorem with Application to Rotational Symmetries author = Jonas Rädle topic = Mathematics/Algebra date = 2017-08-20 notify = jonas.raedle@tum.de abstract = The Orbit-Stabiliser theorem is a basic result in the algebra of groups that factors the order of a group into the sizes of its orbits and stabilisers. We formalize the notion of a group action and the related concepts of orbits and stabilisers. This allows us to prove the orbit-stabiliser theorem. In the second part of this work, we formalize the tetrahedral group and use the orbit-stabiliser theorem to prove that there are twelve (orientation-preserving) rotations of the tetrahedron. [PLM] title = Representation and Partial Automation of the Principia Logico-Metaphysica in Isabelle/HOL author = Daniel Kirchner topic = Logic/Philosophical aspects date = 2017-09-17 notify = daniel@ekpyron.org abstract =

We present an embedding of the second-order fragment of the Theory of Abstract Objects as described in Edward Zalta's upcoming work Principia Logico-Metaphysica (PLM) in the automated reasoning framework Isabelle/HOL. The Theory of Abstract Objects is a metaphysical theory that reifies property patterns, as they for example occur in the abstract reasoning of mathematics, as abstract objects and provides an axiomatic framework that allows to reason about these objects. It thereby serves as a fundamental metaphysical theory that can be used to axiomatize and describe a wide range of philosophical objects, such as Platonic forms or Leibniz' concepts, and has the ambition to function as a foundational theory of mathematics. The target theory of our embedding as described in chapters 7-9 of PLM employs a modal relational type theory as logical foundation for which a representation in functional type theory is known to be challenging.

Nevertheless we arrive at a functioning representation of the theory in the functional logic of Isabelle/HOL based on a semantical representation of an Aczel-model of the theory. Based on this representation we construct an implementation of the deductive system of PLM which allows to automatically and interactively find and verify theorems of PLM.

Our work thereby supports the concept of shallow semantical embeddings of logical systems in HOL as a universal tool for logical reasoning as promoted by Christoph Benzmüller.

The most notable result of the presented work is the discovery of a previously unknown paradox in the formulation of the Theory of Abstract Objects. The embedding of the theory in Isabelle/HOL played a vital part in this discovery. Furthermore it was possible to immediately offer several options to modify the theory to guarantee its consistency. Thereby our work could provide a significant contribution to the development of a proper grounding for object theory.

[KD_Tree] title = Multidimensional Binary Search Trees author = Martin Rau<> topic = Computer science/Data structures date = 2019-05-30 notify = martin.rau@tum.de, mrtnrau@googlemail.com abstract = This entry provides a formalization of multidimensional binary trees, also known as k-d trees. It includes a balanced build algorithm as well as the nearest neighbor algorithm and the range search algorithm. It is based on the papers Multidimensional binary search trees used for associative searching and An Algorithm for Finding Best Matches in Logarithmic Expected Time. extra-history = Change history: [2020-15-04]: Change representation of k-dimensional points from 'list' to HOL-Analysis.Finite_Cartesian_Product 'vec'. Update proofs to incorporate HOL-Analysis 'dist' and 'cbox' primitives. [Closest_Pair_Points] title = Closest Pair of Points Algorithms author = Martin Rau , Tobias Nipkow topic = Computer science/Algorithms/Geometry date = 2020-01-13 notify = martin.rau@tum.de, nipkow@in.tum.de abstract = This entry provides two related verified divide-and-conquer algorithms solving the fundamental Closest Pair of Points problem in Computational Geometry. Functional correctness and the optimal running time of O(n log n) are proved. Executable code is generated which is empirically competitive with handwritten reference implementations. extra-history = Change history: [2020-14-04]: Incorporate Time_Monad of the AFP entry Root_Balanced_Tree. [Approximation_Algorithms] title = Verified Approximation Algorithms author = Robin Eßmann , Tobias Nipkow , Simon Robillard topic = Computer science/Algorithms/Approximation date = 2020-01-16 notify = nipkow@in.tum.de abstract = We present the first formal verification of approximation algorithms for NP-complete optimization problems: vertex cover, set cover, independent set, load balancing, and bin packing. The proofs correct incompletenesses in existing proofs and improve the approximation ratio in one case. A detailed description of our work has been published in the proceedings of IJCAR 2020. [Diophantine_Eqns_Lin_Hom] title = Homogeneous Linear Diophantine Equations author = Florian Messner , Julian Parsert , Jonas Schöpf , Christian Sternagel topic = Computer science/Algorithms/Mathematical, Mathematics/Number theory, Tools license = LGPL date = 2017-10-14 notify = c.sternagel@gmail.com, julian.parsert@gmail.com abstract = We formalize the theory of homogeneous linear diophantine equations, focusing on two main results: (1) an abstract characterization of minimal complete sets of solutions, and (2) an algorithm computing them. Both, the characterization and the algorithm are based on previous work by Huet. Our starting point is a simple but inefficient variant of Huet's lexicographic algorithm incorporating improved bounds due to Clausen and Fortenbacher. We proceed by proving its soundness and completeness. Finally, we employ code equations to obtain a reasonably efficient implementation. Thus, we provide a formally verified solver for homogeneous linear diophantine equations. [Winding_Number_Eval] title = Evaluate Winding Numbers through Cauchy Indices author = Wenda Li topic = Mathematics/Analysis date = 2017-10-17 notify = wl302@cam.ac.uk, liwenda1990@hotmail.com abstract = In complex analysis, the winding number measures the number of times a path (counterclockwise) winds around a point, while the Cauchy index can approximate how the path winds. This entry provides a formalisation of the Cauchy index, which is then shown to be related to the winding number. In addition, this entry also offers a tactic that enables users to evaluate the winding number by calculating Cauchy indices. [Count_Complex_Roots] title = Count the Number of Complex Roots author = Wenda Li topic = Mathematics/Analysis date = 2017-10-17 notify = wl302@cam.ac.uk, liwenda1990@hotmail.com abstract = Based on evaluating Cauchy indices through remainder sequences, this entry provides an effective procedure to count the number of complex roots (with multiplicity) of a polynomial within a rectangle box or a half-plane. Potential applications of this entry include certified complex root isolation (of a polynomial) and testing the Routh-Hurwitz stability criterion (i.e., to check whether all the roots of some characteristic polynomial have negative real parts). [Buchi_Complementation] title = Büchi Complementation author = Julian Brunner topic = Computer science/Automata and formal languages date = 2017-10-19 notify = brunnerj@in.tum.de abstract = This entry provides a verified implementation of rank-based Büchi Complementation. The verification is done in three steps:
  1. Definition of odd rankings and proof that an automaton rejects a word iff there exists an odd ranking for it.
  2. Definition of the complement automaton and proof that it accepts exactly those words for which there is an odd ranking.
  3. Verified implementation of the complement automaton using the Isabelle Collections Framework.
[Transition_Systems_and_Automata] title = Transition Systems and Automata author = Julian Brunner topic = Computer science/Automata and formal languages date = 2017-10-19 notify = brunnerj@in.tum.de abstract = This entry provides a very abstract theory of transition systems that can be instantiated to express various types of automata. A transition system is typically instantiated by providing a set of initial states, a predicate for enabled transitions, and a transition execution function. From this, it defines the concepts of finite and infinite paths as well as the set of reachable states, among other things. Many useful theorems, from basic path manipulation rules to coinduction and run construction rules, are proven in this abstract transition system context. The library comes with instantiations for DFAs, NFAs, and Büchi automata. [Kuratowski_Closure_Complement] title = The Kuratowski Closure-Complement Theorem author = Peter Gammie , Gianpaolo Gioiosa<> topic = Mathematics/Topology date = 2017-10-26 notify = peteg42@gmail.com abstract = We discuss a topological curiosity discovered by Kuratowski (1922): the fact that the number of distinct operators on a topological space generated by compositions of closure and complement never exceeds 14, and is exactly 14 in the case of R. In addition, we prove a theorem due to Chagrov (1982) that classifies topological spaces according to the number of such operators they support. [Hybrid_Multi_Lane_Spatial_Logic] title = Hybrid Multi-Lane Spatial Logic author = Sven Linker topic = Logic/General logic/Modal logic date = 2017-11-06 notify = s.linker@liverpool.ac.uk abstract = We present a semantic embedding of a spatio-temporal multi-modal logic, specifically defined to reason about motorway traffic, into Isabelle/HOL. The semantic model is an abstraction of a motorway, emphasising local spatial properties, and parameterised by the types of sensors deployed in the vehicles. We use the logic to define controller constraints to ensure safety, i.e., the absence of collisions on the motorway. After proving safety with a restrictive definition of sensors, we relax these assumptions and show how to amend the controller constraints to still guarantee safety. [Dirichlet_L] title = Dirichlet L-Functions and Dirichlet's Theorem author = Manuel Eberl topic = Mathematics/Number theory, Mathematics/Algebra date = 2017-12-21 notify = eberlm@in.tum.de abstract =

This article provides a formalisation of Dirichlet characters and Dirichlet L-functions including proofs of their basic properties – most notably their analyticity, their areas of convergence, and their non-vanishing for ℜ(s) ≥ 1. All of this is built in a very high-level style using Dirichlet series. The proof of the non-vanishing follows a very short and elegant proof by Newman, which we attempt to reproduce faithfully in a similar level of abstraction in Isabelle.

This also leads to a relatively short proof of Dirichlet’s Theorem, which states that, if h and n are coprime, there are infinitely many primes p with ph (mod n).

[Symmetric_Polynomials] title = Symmetric Polynomials author = Manuel Eberl topic = Mathematics/Algebra date = 2018-09-25 notify = eberlm@in.tum.de abstract =

A symmetric polynomial is a polynomial in variables X1,…,Xn that does not discriminate between its variables, i. e. it is invariant under any permutation of them. These polynomials are important in the study of the relationship between the coefficients of a univariate polynomial and its roots in its algebraic closure.

This article provides a definition of symmetric polynomials and the elementary symmetric polynomials e1,…,en and proofs of their basic properties, including three notable ones:

  • Vieta's formula, which gives an explicit expression for the k-th coefficient of a univariate monic polynomial in terms of its roots x1,…,xn, namely ck = (-1)n-k en-k(x1,…,xn).
  • Second, the Fundamental Theorem of Symmetric Polynomials, which states that any symmetric polynomial is itself a uniquely determined polynomial combination of the elementary symmetric polynomials.
  • Third, as a corollary of the previous two, that given a polynomial over some ring R, any symmetric polynomial combination of its roots is also in R even when the roots are not.

Both the symmetry property itself and the witness for the Fundamental Theorem are executable.

[Taylor_Models] title = Taylor Models author = Christoph Traut<>, Fabian Immler topic = Computer science/Algorithms/Mathematical, Computer science/Data structures, Mathematics/Analysis, Mathematics/Algebra date = 2018-01-08 notify = immler@in.tum.de abstract = We present a formally verified implementation of multivariate Taylor models. Taylor models are a form of rigorous polynomial approximation, consisting of an approximation polynomial based on Taylor expansions, combined with a rigorous bound on the approximation error. Taylor models were introduced as a tool to mitigate the dependency problem of interval arithmetic. Our implementation automatically computes Taylor models for the class of elementary functions, expressed by composition of arithmetic operations and basic functions like exp, sin, or square root. [Green] title = An Isabelle/HOL formalisation of Green's Theorem author = Mohammad Abdulaziz , Lawrence C. Paulson topic = Mathematics/Analysis date = 2018-01-11 notify = mohammad.abdulaziz8@gmail.com, lp15@cam.ac.uk abstract = We formalise a statement of Green’s theorem—the first formalisation to our knowledge—in Isabelle/HOL. The theorem statement that we formalise is enough for most applications, especially in physics and engineering. Our formalisation is made possible by a novel proof that avoids the ubiquitous line integral cancellation argument. This eliminates the need to formalise orientations and region boundaries explicitly with respect to the outwards-pointing normal vector. Instead we appeal to a homological argument about equivalences between paths. [AI_Planning_Languages_Semantics] title = AI Planning Languages Semantics author = Mohammad Abdulaziz , Peter Lammich topic = Computer science/Artificial intelligence date = 2020-10-29 notify = mohammad.abdulaziz8@gmail.com abstract = This is an Isabelle/HOL formalisation of the semantics of the multi-valued planning tasks language that is used by the planning system Fast-Downward, the STRIPS fragment of the Planning Domain Definition Language (PDDL), and the STRIPS soundness meta-theory developed by Vladimir Lifschitz. It also contains formally verified checkers for checking the well-formedness of problems specified in either language as well the correctness of potential solutions. The formalisation in this entry was described in an earlier publication. [Verified_SAT_Based_AI_Planning] title = Verified SAT-Based AI Planning author = Mohammad Abdulaziz , Friedrich Kurz <> topic = Computer science/Artificial intelligence date = 2020-10-29 notify = mohammad.abdulaziz8@gmail.com abstract = We present an executable formally verified SAT encoding of classical AI planning that is based on the encodings by Kautz and Selman and the one by Rintanen et al. The encoding was experimentally tested and shown to be usable for reasonably sized standard AI planning benchmarks. We also use it as a reference to test a state-of-the-art SAT-based planner, showing that it sometimes falsely claims that problems have no solutions of certain lengths. The formalisation in this submission was described in an independent publication. [Gromov_Hyperbolicity] title = Gromov Hyperbolicity author = Sebastien Gouezel<> topic = Mathematics/Geometry date = 2018-01-16 notify = sebastien.gouezel@univ-rennes1.fr abstract = A geodesic metric space is Gromov hyperbolic if all its geodesic triangles are thin, i.e., every side is contained in a fixed thickening of the two other sides. While this definition looks innocuous, it has proved extremely important and versatile in modern geometry since its introduction by Gromov. We formalize the basic classical properties of Gromov hyperbolic spaces, notably the Morse lemma asserting that quasigeodesics are close to geodesics, the invariance of hyperbolicity under quasi-isometries, we define and study the Gromov boundary and its associated distance, and prove that a quasi-isometry between Gromov hyperbolic spaces extends to a homeomorphism of the boundaries. We also prove a less classical theorem, by Bonk and Schramm, asserting that a Gromov hyperbolic space embeds isometrically in a geodesic Gromov-hyperbolic space. As the original proof uses a transfinite sequence of Cauchy completions, this is an interesting formalization exercise. Along the way, we introduce basic material on isometries, quasi-isometries, Lipschitz maps, geodesic spaces, the Hausdorff distance, the Cauchy completion of a metric space, and the exponential on extended real numbers. [Ordered_Resolution_Prover] title = Formalization of Bachmair and Ganzinger's Ordered Resolution Prover author = Anders Schlichtkrull , Jasmin Christian Blanchette , Dmitriy Traytel , Uwe Waldmann topic = Logic/General logic/Mechanization of proofs date = 2018-01-18 notify = andschl@dtu.dk, j.c.blanchette@vu.nl abstract = This Isabelle/HOL formalization covers Sections 2 to 4 of Bachmair and Ganzinger's "Resolution Theorem Proving" chapter in the Handbook of Automated Reasoning. This includes soundness and completeness of unordered and ordered variants of ground resolution with and without literal selection, the standard redundancy criterion, a general framework for refutational theorem proving, and soundness and completeness of an abstract first-order prover. [Chandy_Lamport] title = A Formal Proof of The Chandy--Lamport Distributed Snapshot Algorithm author = Ben Fiedler , Dmitriy Traytel topic = Computer science/Algorithms/Distributed date = 2020-07-21 notify = ben.fiedler@inf.ethz.ch, traytel@inf.ethz.ch abstract = We provide a suitable distributed system model and implementation of the Chandy--Lamport distributed snapshot algorithm [ACM Transactions on Computer Systems, 3, 63-75, 1985]. Our main result is a formal termination and correctness proof of the Chandy--Lamport algorithm and its use in stable property detection. [BNF_Operations] title = Operations on Bounded Natural Functors author = Jasmin Christian Blanchette , Andrei Popescu , Dmitriy Traytel topic = Tools date = 2017-12-19 notify = jasmin.blanchette@gmail.com,uuomul@yahoo.com,traytel@inf.ethz.ch abstract = This entry formalizes the closure property of bounded natural functors (BNFs) under seven operations. These operations and the corresponding proofs constitute the core of Isabelle's (co)datatype package. To be close to the implemented tactics, the proofs are deliberately formulated as detailed apply scripts. The (co)datatypes together with (co)induction principles and (co)recursors are byproducts of the fixpoint operations LFP and GFP. Composition of BNFs is subdivided into four simpler operations: Compose, Kill, Lift, and Permute. The N2M operation provides mutual (co)induction principles and (co)recursors for nested (co)datatypes. [LLL_Basis_Reduction] title = A verified LLL algorithm author = Ralph Bottesch <>, Jose Divasón , Maximilian Haslbeck , Sebastiaan Joosten , René Thiemann , Akihisa Yamada<> topic = Computer science/Algorithms/Mathematical, Mathematics/Algebra date = 2018-02-02 notify = ralph.bottesch@uibk.ac.at, jose.divason@unirioja.es, maximilian.haslbeck@uibk.ac.at, s.j.c.joosten@utwente.nl, rene.thiemann@uibk.ac.at, ayamada@trs.cm.is.nagoya-u.ac.jp abstract = The Lenstra-Lenstra-Lovász basis reduction algorithm, also known as LLL algorithm, is an algorithm to find a basis with short, nearly orthogonal vectors of an integer lattice. Thereby, it can also be seen as an approximation to solve the shortest vector problem (SVP), which is an NP-hard problem, where the approximation quality solely depends on the dimension of the lattice, but not the lattice itself. The algorithm also possesses many applications in diverse fields of computer science, from cryptanalysis to number theory, but it is specially well-known since it was used to implement the first polynomial-time algorithm to factor polynomials. In this work we present the first mechanized soundness proof of the LLL algorithm to compute short vectors in lattices. The formalization follows a textbook by von zur Gathen and Gerhard. extra-history = Change history: [2018-04-16]: Integrated formal complexity bounds (Haslbeck, Thiemann) [2018-05-25]: Integrated much faster LLL implementation based on integer arithmetic (Bottesch, Haslbeck, Thiemann) [LLL_Factorization] title = A verified factorization algorithm for integer polynomials with polynomial complexity author = Jose Divasón , Sebastiaan Joosten , René Thiemann , Akihisa Yamada topic = Mathematics/Algebra date = 2018-02-06 notify = jose.divason@unirioja.es, s.j.c.joosten@utwente.nl, rene.thiemann@uibk.ac.at, ayamada@trs.cm.is.nagoya-u.ac.jp abstract = Short vectors in lattices and factors of integer polynomials are related. Each factor of an integer polynomial belongs to a certain lattice. When factoring polynomials, the condition that we are looking for an irreducible polynomial means that we must look for a small element in a lattice, which can be done by a basis reduction algorithm. In this development we formalize this connection and thereby one main application of the LLL basis reduction algorithm: an algorithm to factor square-free integer polynomials which runs in polynomial time. The work is based on our previous Berlekamp–Zassenhaus development, where the exponential reconstruction phase has been replaced by the polynomial-time basis reduction algorithm. Thanks to this formalization we found a serious flaw in a textbook. [Treaps] title = Treaps author = Maximilian Haslbeck , Manuel Eberl , Tobias Nipkow topic = Computer science/Data structures date = 2018-02-06 notify = eberlm@in.tum.de abstract =

A Treap is a binary tree whose nodes contain pairs consisting of some payload and an associated priority. It must have the search-tree property w.r.t. the payloads and the heap property w.r.t. the priorities. Treaps are an interesting data structure that is related to binary search trees (BSTs) in the following way: if one forgets all the priorities of a treap, the resulting BST is exactly the same as if one had inserted the elements into an empty BST in order of ascending priority. This means that a treap behaves like a BST where we can pretend the elements were inserted in a different order from the one in which they were actually inserted.

In particular, by choosing these priorities at random upon insertion of an element, we can pretend that we inserted the elements in random order, so that the shape of the resulting tree is that of a random BST no matter in what order we insert the elements. This is the main result of this formalisation.

[Skip_Lists] title = Skip Lists author = Max W. Haslbeck , Manuel Eberl topic = Computer science/Data structures date = 2020-01-09 notify = max.haslbeck@gmx.de abstract =

Skip lists are sorted linked lists enhanced with shortcuts and are an alternative to binary search trees. A skip lists consists of multiple levels of sorted linked lists where a list on level n is a subsequence of the list on level n − 1. In the ideal case, elements are skipped in such a way that a lookup in a skip lists takes O(log n) time. In a randomised skip list the skipped elements are choosen randomly.

This entry contains formalized proofs of the textbook results about the expected height and the expected length of a search path in a randomised skip list.

[Mersenne_Primes] title = Mersenne primes and the Lucas–Lehmer test author = Manuel Eberl topic = Mathematics/Number theory date = 2020-01-17 notify = eberlm@in.tum.de abstract =

This article provides formal proofs of basic properties of Mersenne numbers, i. e. numbers of the form 2n - 1, and especially of Mersenne primes.

In particular, an efficient, verified, and executable version of the Lucas–Lehmer test is developed. This test decides primality for Mersenne numbers in time polynomial in n.

[Hoare_Time] title = Hoare Logics for Time Bounds author = Maximilian P. L. Haslbeck , Tobias Nipkow topic = Computer science/Programming languages/Logics date = 2018-02-26 notify = haslbema@in.tum.de abstract = We study three different Hoare logics for reasoning about time bounds of imperative programs and formalize them in Isabelle/HOL: a classical Hoare like logic due to Nielson, a logic with potentials due to Carbonneaux et al. and a separation logic following work by Atkey, Chaguérand and Pottier. These logics are formally shown to be sound and complete. Verification condition generators are developed and are shown sound and complete too. We also consider variants of the systems where we abstract from multiplicative constants in the running time bounds, thus supporting a big-O style of reasoning. Finally we compare the expressive power of the three systems. [Architectural_Design_Patterns] title = A Theory of Architectural Design Patterns author = Diego Marmsoler topic = Computer science/System description languages date = 2018-03-01 notify = diego.marmsoler@tum.de abstract = The following document formalizes and verifies several architectural design patterns. Each pattern specification is formalized in terms of a locale where the locale assumptions correspond to the assumptions which a pattern poses on an architecture. Thus, pattern specifications may build on top of each other by interpreting the corresponding locale. A pattern is verified using the framework provided by the AFP entry Dynamic Architectures. Currently, the document consists of formalizations of 4 different patterns: the singleton, the publisher subscriber, the blackboard pattern, and the blockchain pattern. Thereby, the publisher component of the publisher subscriber pattern is modeled as an instance of the singleton pattern and the blackboard pattern is modeled as an instance of the publisher subscriber pattern. In general, this entry provides the first steps towards an overall theory of architectural design patterns. extra-history = Change history: [2018-05-25]: changing the major assumption for blockchain architectures from alternative minings to relative mining frequencies (revision 5043c5c71685)
[2019-04-08]: adapting the terminology: honest instead of trusted, dishonest instead of untrusted (revision 7af3431a22ae) [Weight_Balanced_Trees] title = Weight-Balanced Trees author = Tobias Nipkow , Stefan Dirix<> topic = Computer science/Data structures date = 2018-03-13 notify = nipkow@in.tum.de abstract = This theory provides a verified implementation of weight-balanced trees following the work of Hirai and Yamamoto who proved that all parameters in a certain range are valid, i.e. guarantee that insertion and deletion preserve weight-balance. Instead of a general theorem we provide parameterized proofs of preservation of the invariant that work for many (all?) valid parameters. [Fishburn_Impossibility] title = The Incompatibility of Fishburn-Strategyproofness and Pareto-Efficiency author = Felix Brandt , Manuel Eberl , Christian Saile , Christian Stricker topic = Mathematics/Games and economics date = 2018-03-22 notify = eberlm@in.tum.de abstract =

This formalisation contains the proof that there is no anonymous Social Choice Function for at least three agents and alternatives that fulfils both Pareto-Efficiency and Fishburn-Strategyproofness. It was derived from a proof of Brandt et al., which relies on an unverified translation of a fixed finite instance of the original problem to SAT. This Isabelle proof contains a machine-checked version of both the statement for exactly three agents and alternatives and the lifting to the general case.

[BNF_CC] title = Bounded Natural Functors with Covariance and Contravariance author = Andreas Lochbihler , Joshua Schneider topic = Computer science/Functional programming, Tools date = 2018-04-24 notify = mail@andreas-lochbihler.de, joshua.schneider@inf.ethz.ch abstract = Bounded natural functors (BNFs) provide a modular framework for the construction of (co)datatypes in higher-order logic. Their functorial operations, the mapper and relator, are restricted to a subset of the parameters, namely those where recursion can take place. For certain applications, such as free theorems, data refinement, quotients, and generalised rewriting, it is desirable that these operations do not ignore the other parameters. In this article, we formalise the generalisation BNFCC that extends the mapper and relator to covariant and contravariant parameters. We show that
  1. BNFCCs are closed under functor composition and least and greatest fixpoints,
  2. subtypes inherit the BNFCC structure under conditions that generalise those for the BNF case, and
  3. BNFCCs preserve quotients under mild conditions.
These proofs are carried out for abstract BNFCCs similar to the AFP entry BNF Operations. In addition, we apply the BNFCC theory to several concrete functors. [Modular_Assembly_Kit_Security] title = An Isabelle/HOL Formalization of the Modular Assembly Kit for Security Properties author = Oliver Bračevac , Richard Gay , Sylvia Grewe , Heiko Mantel , Henning Sudbrock , Markus Tasch topic = Computer science/Security date = 2018-05-07 notify = tasch@mais.informatik.tu-darmstadt.de abstract = The "Modular Assembly Kit for Security Properties" (MAKS) is a framework for both the definition and verification of possibilistic information-flow security properties at the specification-level. MAKS supports the uniform representation of a wide range of possibilistic information-flow properties and provides support for the verification of such properties via unwinding results and compositionality results. We provide a formalization of this framework in Isabelle/HOL. [AxiomaticCategoryTheory] title = Axiom Systems for Category Theory in Free Logic author = Christoph Benzmüller , Dana Scott topic = Mathematics/Category theory date = 2018-05-23 notify = c.benzmueller@gmail.com abstract = This document provides a concise overview on the core results of our previous work on the exploration of axioms systems for category theory. Extending the previous studies (http://arxiv.org/abs/1609.01493) we include one further axiomatic theory in our experiments. This additional theory has been suggested by Mac Lane in 1948. We show that the axioms proposed by Mac Lane are equivalent to the ones we studied before, which includes an axioms set suggested by Scott in the 1970s and another axioms set proposed by Freyd and Scedrov in 1990, which we slightly modified to remedy a minor technical issue. [OpSets] title = OpSets: Sequential Specifications for Replicated Datatypes author = Martin Kleppmann , Victor B. F. Gomes , Dominic P. Mulligan , Alastair R. Beresford topic = Computer science/Algorithms/Distributed, Computer science/Data structures date = 2018-05-10 notify = vb358@cam.ac.uk abstract = We introduce OpSets, an executable framework for specifying and reasoning about the semantics of replicated datatypes that provide eventual consistency in a distributed system, and for mechanically verifying algorithms that implement these datatypes. Our approach is simple but expressive, allowing us to succinctly specify a variety of abstract datatypes, including maps, sets, lists, text, graphs, trees, and registers. Our datatypes are also composable, enabling the construction of complex data structures. To demonstrate the utility of OpSets for analysing replication algorithms, we highlight an important correctness property for collaborative text editing that has traditionally been overlooked; algorithms that do not satisfy this property can exhibit awkward interleaving of text. We use OpSets to specify this correctness property and prove that although one existing replication algorithm satisfies this property, several other published algorithms do not. [Irrationality_J_Hancl] title = Irrational Rapidly Convergent Series author = Angeliki Koutsoukou-Argyraki , Wenda Li topic = Mathematics/Number theory, Mathematics/Analysis date = 2018-05-23 notify = ak2110@cam.ac.uk, wl302@cam.ac.uk abstract = We formalize with Isabelle/HOL a proof of a theorem by J. Hancl asserting the irrationality of the sum of a series consisting of rational numbers, built up by sequences that fulfill certain properties. Even though the criterion is a number theoretic result, the proof makes use only of analytical arguments. We also formalize a corollary of the theorem for a specific series fulfilling the assumptions of the theorem. [Optimal_BST] title = Optimal Binary Search Trees author = Tobias Nipkow , Dániel Somogyi <> topic = Computer science/Algorithms, Computer science/Data structures date = 2018-05-27 notify = nipkow@in.tum.de abstract = This article formalizes recursive algorithms for the construction of optimal binary search trees given fixed access frequencies. We follow Knuth (1971), Yao (1980) and Mehlhorn (1984). The algorithms are memoized with the help of the AFP article Monadification, Memoization and Dynamic Programming, thus yielding dynamic programming algorithms. [Projective_Geometry] title = Projective Geometry author = Anthony Bordg topic = Mathematics/Geometry date = 2018-06-14 notify = apdb3@cam.ac.uk abstract = We formalize the basics of projective geometry. In particular, we give a proof of the so-called Hessenberg's theorem in projective plane geometry. We also provide a proof of the so-called Desargues's theorem based on an axiomatization of (higher) projective space geometry using the notion of rank of a matroid. This last approach allows to handle incidence relations in an homogeneous way dealing only with points and without the need of talking explicitly about lines, planes or any higher entity. [Localization_Ring] title = The Localization of a Commutative Ring author = Anthony Bordg topic = Mathematics/Algebra date = 2018-06-14 notify = apdb3@cam.ac.uk abstract = We formalize the localization of a commutative ring R with respect to a multiplicative subset (i.e. a submonoid of R seen as a multiplicative monoid). This localization is itself a commutative ring and we build the natural homomorphism of rings from R to its localization. [Minsky_Machines] title = Minsky Machines author = Bertram Felgenhauer<> topic = Logic/Computability date = 2018-08-14 notify = int-e@gmx.de abstract =

We formalize undecidablity results for Minsky machines. To this end, we also formalize recursive inseparability.

We start by proving that Minsky machines can compute arbitrary primitive recursive and recursive functions. We then show that there is a deterministic Minsky machine with one argument and two final states such that the set of inputs that are accepted in one state is recursively inseparable from the set of inputs that are accepted in the other state.

As a corollary, the set of Minsky configurations that reach the first state but not the second recursively inseparable from the set of Minsky configurations that reach the second state but not the first. In particular both these sets are undecidable.

We do not prove that recursive functions can simulate Minsky machines.

[Neumann_Morgenstern_Utility] title = Von-Neumann-Morgenstern Utility Theorem author = Julian Parsert, Cezary Kaliszyk topic = Mathematics/Games and economics license = LGPL date = 2018-07-04 notify = julian.parsert@uibk.ac.at, cezary.kaliszyk@uibk.ac.at abstract = Utility functions form an essential part of game theory and economics. In order to guarantee the existence of utility functions most of the time sufficient properties are assumed in an axiomatic manner. One famous and very common set of such assumptions is that of expected utility theory. Here, the rationality, continuity, and independence of preferences is assumed. The von-Neumann-Morgenstern Utility theorem shows that these assumptions are necessary and sufficient for an expected utility function to exists. This theorem was proven by Neumann and Morgenstern in ``Theory of Games and Economic Behavior'' which is regarded as one of the most influential works in game theory. The formalization includes formal definitions of the underlying concepts including continuity and independence of preferences. [Simplex] title = An Incremental Simplex Algorithm with Unsatisfiable Core Generation author = Filip Marić , Mirko Spasić , René Thiemann topic = Computer science/Algorithms/Optimization date = 2018-08-24 notify = rene.thiemann@uibk.ac.at abstract = We present an Isabelle/HOL formalization and total correctness proof for the incremental version of the Simplex algorithm which is used in most state-of-the-art SMT solvers. It supports extraction of satisfying assignments, extraction of minimal unsatisfiable cores, incremental assertion of constraints and backtracking. The formalization relies on stepwise program refinement, starting from a simple specification, going through a number of refinement steps, and ending up in a fully executable functional implementation. Symmetries present in the algorithm are handled with special care. [Budan_Fourier] title = The Budan-Fourier Theorem and Counting Real Roots with Multiplicity author = Wenda Li topic = Mathematics/Analysis date = 2018-09-02 notify = wl302@cam.ac.uk, liwenda1990@hotmail.com abstract = This entry is mainly about counting and approximating real roots (of a polynomial) with multiplicity. We have first formalised the Budan-Fourier theorem: given a polynomial with real coefficients, we can calculate sign variations on Fourier sequences to over-approximate the number of real roots (counting multiplicity) within an interval. When all roots are known to be real, the over-approximation becomes tight: we can utilise this theorem to count real roots exactly. It is also worth noting that Descartes' rule of sign is a direct consequence of the Budan-Fourier theorem, and has been included in this entry. In addition, we have extended previous formalised Sturm's theorem to count real roots with multiplicity, while the original Sturm's theorem only counts distinct real roots. Compared to the Budan-Fourier theorem, our extended Sturm's theorem always counts roots exactly but may suffer from greater computational cost. [Quaternions] title = Quaternions author = Lawrence C. Paulson topic = Mathematics/Algebra, Mathematics/Geometry date = 2018-09-05 notify = lp15@cam.ac.uk abstract = This theory is inspired by the HOL Light development of quaternions, but follows its own route. Quaternions are developed coinductively, as in the existing formalisation of the complex numbers. Quaternions are quickly shown to belong to the type classes of real normed division algebras and real inner product spaces. And therefore they inherit a great body of facts involving algebraic laws, limits, continuity, etc., which must be proved explicitly in the HOL Light version. The development concludes with the geometric interpretation of the product of imaginary quaternions. [Octonions] title = Octonions author = Angeliki Koutsoukou-Argyraki topic = Mathematics/Algebra, Mathematics/Geometry date = 2018-09-14 notify = ak2110@cam.ac.uk abstract = We develop the basic theory of Octonions, including various identities and properties of the octonions and of the octonionic product, a description of 7D isometries and representations of orthogonal transformations. To this end we first develop the theory of the vector cross product in 7 dimensions. The development of the theory of Octonions is inspired by that of the theory of Quaternions by Lawrence Paulson. However, we do not work within the type class real_algebra_1 because the octonionic product is not associative. [Aggregation_Algebras] title = Aggregation Algebras author = Walter Guttmann topic = Mathematics/Algebra date = 2018-09-15 notify = walter.guttmann@canterbury.ac.nz abstract = We develop algebras for aggregation and minimisation for weight matrices and for edge weights in graphs. We verify the correctness of Prim's and Kruskal's minimum spanning tree algorithms based on these algebras. We also show numerous instances of these algebras based on linearly ordered commutative semigroups. [Prime_Number_Theorem] title = The Prime Number Theorem author = Manuel Eberl , Lawrence C. Paulson topic = Mathematics/Number theory date = 2018-09-19 notify = eberlm@in.tum.de abstract =

This article provides a short proof of the Prime Number Theorem in several equivalent forms, most notably π(x) ~ x/ln x where π(x) is the number of primes no larger than x. It also defines other basic number-theoretic functions related to primes like Chebyshev's functions ϑ and ψ and the “n-th prime number” function pn. We also show various bounds and relationship between these functions are shown. Lastly, we derive Mertens' First and Second Theorem, i. e. ∑px ln p/p = ln x + O(1) and ∑px 1/p = ln ln x + M + O(1/ln x). We also give explicit bounds for the remainder terms.

The proof of the Prime Number Theorem builds on a library of Dirichlet series and analytic combinatorics. We essentially follow the presentation by Newman. The core part of the proof is a Tauberian theorem for Dirichlet series, which is proven using complex analysis and then used to strengthen Mertens' First Theorem to ∑px ln p/p = ln x + c + o(1).

A variant of this proof has been formalised before by Harrison in HOL Light, and formalisations of Selberg's elementary proof exist both by Avigad et al. in Isabelle and by Carneiro in Metamath. The advantage of the analytic proof is that, while it requires more powerful mathematical tools, it is considerably shorter and clearer. This article attempts to provide a short and clear formalisation of all components of that proof using the full range of mathematical machinery available in Isabelle, staying as close as possible to Newman's simple paper proof.

[Signature_Groebner] title = Signature-Based Gröbner Basis Algorithms author = Alexander Maletzky topic = Mathematics/Algebra, Computer science/Algorithms/Mathematical date = 2018-09-20 notify = alexander.maletzky@risc.jku.at abstract =

This article formalizes signature-based algorithms for computing Gröbner bases. Such algorithms are, in general, superior to other algorithms in terms of efficiency, and have not been formalized in any proof assistant so far. The present development is both generic, in the sense that most known variants of signature-based algorithms are covered by it, and effectively executable on concrete input thanks to Isabelle's code generator. Sample computations of benchmark problems show that the verified implementation of signature-based algorithms indeed outperforms the existing implementation of Buchberger's algorithm in Isabelle/HOL.

Besides total correctness of the algorithms, the article also proves that under certain conditions they a-priori detect and avoid all useless zero-reductions, and always return 'minimal' (in some sense) Gröbner bases if an input parameter is chosen in the right way.

The formalization follows the recent survey article by Eder and Faugère.

[Factored_Transition_System_Bounding] title = Upper Bounding Diameters of State Spaces of Factored Transition Systems author = Friedrich Kurz <>, Mohammad Abdulaziz topic = Computer science/Automata and formal languages, Mathematics/Graph theory date = 2018-10-12 notify = friedrich.kurz@tum.de, mohammad.abdulaziz@in.tum.de abstract = A completeness threshold is required to guarantee the completeness of planning as satisfiability, and bounded model checking of safety properties. One valid completeness threshold is the diameter of the underlying transition system. The diameter is the maximum element in the set of lengths of all shortest paths between pairs of states. The diameter is not calculated exactly in our setting, where the transition system is succinctly described using a (propositionally) factored representation. Rather, an upper bound on the diameter is calculated compositionally, by bounding the diameters of small abstract subsystems, and then composing those. We port a HOL4 formalisation of a compositional algorithm for computing a relatively tight upper bound on the system diameter. This compositional algorithm exploits acyclicity in the state space to achieve compositionality, and it was introduced by Abdulaziz et. al. The formalisation that we port is described as a part of another paper by Abdulaziz et. al. As a part of this porting we developed a libray about transition systems, which shall be of use in future related mechanisation efforts. [Smooth_Manifolds] title = Smooth Manifolds author = Fabian Immler , Bohua Zhan topic = Mathematics/Analysis, Mathematics/Topology date = 2018-10-22 notify = immler@in.tum.de, bzhan@ios.ac.cn abstract = We formalize the definition and basic properties of smooth manifolds in Isabelle/HOL. Concepts covered include partition of unity, tangent and cotangent spaces, and the fundamental theorem of path integrals. We also examine some concrete manifolds such as spheres and projective spaces. The formalization makes extensive use of the analysis and linear algebra libraries in Isabelle/HOL, in particular its “types-to-sets” mechanism. [Matroids] title = Matroids author = Jonas Keinholz<> topic = Mathematics/Combinatorics date = 2018-11-16 notify = eberlm@in.tum.de abstract =

This article defines the combinatorial structures known as Independence Systems and Matroids and provides basic concepts and theorems related to them. These structures play an important role in combinatorial optimisation, e. g. greedy algorithms such as Kruskal's algorithm. The development is based on Oxley's `What is a Matroid?'.

[Graph_Saturation] title = Graph Saturation author = Sebastiaan J. C. Joosten<> topic = Logic/Rewriting, Mathematics/Graph theory date = 2018-11-23 notify = sjcjoosten@gmail.com abstract = This is an Isabelle/HOL formalisation of graph saturation, closely following a paper by the author on graph saturation. Nine out of ten lemmas of the original paper are proven in this formalisation. The formalisation additionally includes two theorems that show the main premise of the paper: that consistency and entailment are decided through graph saturation. This formalisation does not give executable code, and it did not implement any of the optimisations suggested in the paper. [Functional_Ordered_Resolution_Prover] title = A Verified Functional Implementation of Bachmair and Ganzinger's Ordered Resolution Prover author = Anders Schlichtkrull , Jasmin Christian Blanchette , Dmitriy Traytel topic = Logic/General logic/Mechanization of proofs date = 2018-11-23 notify = andschl@dtu.dk,j.c.blanchette@vu.nl,traytel@inf.ethz.ch abstract = This Isabelle/HOL formalization refines the abstract ordered resolution prover presented in Section 4.3 of Bachmair and Ganzinger's "Resolution Theorem Proving" chapter in the Handbook of Automated Reasoning. The result is a functional implementation of a first-order prover. [Auto2_HOL] title = Auto2 Prover author = Bohua Zhan topic = Tools date = 2018-11-20 notify = bzhan@ios.ac.cn abstract = Auto2 is a saturation-based heuristic prover for higher-order logic, implemented as a tactic in Isabelle. This entry contains the instantiation of auto2 for Isabelle/HOL, along with two basic examples: solutions to some of the Pelletier’s problems, and elementary number theory of primes. [Order_Lattice_Props] title = Properties of Orderings and Lattices author = Georg Struth topic = Mathematics/Order date = 2018-12-11 notify = g.struth@sheffield.ac.uk abstract = These components add further fundamental order and lattice-theoretic concepts and properties to Isabelle's libraries. They follow by and large the introductory sections of the Compendium of Continuous Lattices, covering directed and filtered sets, down-closed and up-closed sets, ideals and filters, Galois connections, closure and co-closure operators. Some emphasis is on duality and morphisms between structures, as in the Compendium. To this end, three ad-hoc approaches to duality are compared. [Quantales] title = Quantales author = Georg Struth topic = Mathematics/Algebra date = 2018-12-11 notify = g.struth@sheffield.ac.uk abstract = These mathematical components formalise basic properties of quantales, together with some important models, constructions, and concepts, including quantic nuclei and conuclei. [Transformer_Semantics] title = Transformer Semantics author = Georg Struth topic = Mathematics/Algebra, Computer science/Semantics date = 2018-12-11 notify = g.struth@sheffield.ac.uk abstract = These mathematical components formalise predicate transformer semantics for programs, yet currently only for partial correctness and in the absence of faults. A first part for isotone (or monotone), Sup-preserving and Inf-preserving transformers follows Back and von Wright's approach, with additional emphasis on the quantalic structure of algebras of transformers. The second part develops Sup-preserving and Inf-preserving predicate transformers from the powerset monad, via its Kleisli category and Eilenberg-Moore algebras, with emphasis on adjunctions and dualities, as well as isomorphisms between relations, state transformers and predicate transformers. [Concurrent_Revisions] title = Formalization of Concurrent Revisions author = Roy Overbeek topic = Computer science/Concurrency date = 2018-12-25 notify = Roy.Overbeek@cwi.nl abstract = Concurrent revisions is a concurrency control model developed by Microsoft Research. It has many interesting properties that distinguish it from other well-known models such as transactional memory. One of these properties is determinacy: programs written within the model always produce the same outcome, independent of scheduling activity. The concurrent revisions model has an operational semantics, with an informal proof of determinacy. This document contains an Isabelle/HOL formalization of this semantics and the proof of determinacy. [Core_DOM] title = A Formal Model of the Document Object Model author = Achim D. Brucker , Michael Herzberg topic = Computer science/Data structures date = 2018-12-26 notify = adbrucker@0x5f.org abstract = In this AFP entry, we formalize the core of the Document Object Model (DOM). At its core, the DOM defines a tree-like data structure for representing documents in general and HTML documents in particular. It is the heart of any modern web browser. Formalizing the key concepts of the DOM is a prerequisite for the formal reasoning over client-side JavaScript programs and for the analysis of security concepts in modern web browsers. We present a formalization of the core DOM, with focus on the node-tree and the operations defined on node-trees, in Isabelle/HOL. We use the formalization to verify the functional correctness of the most important functions defined in the DOM standard. Moreover, our formalization is 1) extensible, i.e., can be extended without the need of re-proving already proven properties and 2) executable, i.e., we can generate executable code from our specification. [Core_SC_DOM] title = The Safely Composable DOM author = Achim D. Brucker , Michael Herzberg topic = Computer science/Data structures date = 2020-09-28 notify = adbrucker@0x5f.org, mail@michael-herzberg.de abstract = In this AFP entry, we formalize the core of the Safely Composable Document Object Model (SC DOM). The SC DOM improve the standard DOM (as formalized in the AFP entry "Core DOM") by strengthening the tree boundaries set by shadow roots: in the SC DOM, the shadow root is a sub-class of the document class (instead of a base class). This modifications also results in changes to some API methods (e.g., getOwnerDocument) to return the nearest shadow root rather than the document root. As a result, many API methods that, when called on a node inside a shadow tree, would previously ``break out'' and return or modify nodes that are possibly outside the shadow tree, now stay within its boundaries. This change in behavior makes programs that operate on shadow trees more predictable for the developer and allows them to make more assumptions about other code accessing the DOM. [Shadow_SC_DOM] title = A Formal Model of the Safely Composable Document Object Model with Shadow Roots author = Achim D. Brucker , Michael Herzberg topic = Computer science/Data structures date = 2020-09-28 notify = adbrucker@0x5f.org, mail@michael-herzberg.de abstract = In this AFP entry, we extend our formalization of the safely composable DOM with Shadow Roots. This is a proposal for Shadow Roots with stricter safety guarantess than the standard compliant formalization (see "Shadow DOM"). Shadow Roots are a recent proposal of the web community to support a component-based development approach for client-side web applications. Shadow roots are a significant extension to the DOM standard and, as web standards are condemned to be backward compatible, such extensions often result in complex specification that may contain unwanted subtleties that can be detected by a formalization. Our Isabelle/HOL formalization is, in the sense of object-orientation, an extension of our formalization of the core DOM and enjoys the same basic properties, i.e., it is extensible, i.e., can be extended without the need of re-proving already proven properties and executable, i.e., we can generate executable code from our specification. We exploit the executability to show that our formalization complies to the official standard of the W3C, respectively, the WHATWG. [SC_DOM_Components] title = A Formalization of Safely Composable Web Components author = Achim D. Brucker , Michael Herzberg topic = Computer science/Data structures date = 2020-09-28 notify = adbrucker@0x5f.org, mail@michael-herzberg.de abstract = While the (safely composable) DOM with shadow trees provide the technical basis for defining web components, it does neither defines the concept of web components nor specifies the safety properties that web components should guarantee. Consequently, the standard also does not discuss how or even if the methods for modifying the DOM respect component boundaries. In AFP entry, we present a formally verified model of safely composable web components and define safety properties which ensure that different web components can only interact with each other using well-defined interfaces. Moreover, our verification of the application programming interface (API) of the DOM revealed numerous invariants that implementations of the DOM API need to preserve to ensure the integrity of components. In comparison to the strict standard compliance formalization of Web Components in the AFP entry "DOM_Components", the notion of components in this entry (based on "SC_DOM" and "Shadow_SC_DOM") provides much stronger safety guarantees. [Store_Buffer_Reduction] title = A Reduction Theorem for Store Buffers author = Ernie Cohen , Norbert Schirmer topic = Computer science/Concurrency date = 2019-01-07 notify = norbert.schirmer@web.de abstract = When verifying a concurrent program, it is usual to assume that memory is sequentially consistent. However, most modern multiprocessors depend on store buffering for efficiency, and provide native sequential consistency only at a substantial performance penalty. To regain sequential consistency, a programmer has to follow an appropriate programming discipline. However, naïve disciplines, such as protecting all shared accesses with locks, are not flexible enough for building high-performance multiprocessor software. We present a new discipline for concurrent programming under TSO (total store order, with store buffer forwarding). It does not depend on concurrency primitives, such as locks. Instead, threads use ghost operations to acquire and release ownership of memory addresses. A thread can write to an address only if no other thread owns it, and can read from an address only if it owns it or it is shared and the thread has flushed its store buffer since it last wrote to an address it did not own. This discipline covers both coarse-grained concurrency (where data is protected by locks) as well as fine-grained concurrency (where atomic operations race to memory). We formalize this discipline in Isabelle/HOL, and prove that if every execution of a program in a system without store buffers follows the discipline, then every execution of the program with store buffers is sequentially consistent. Thus, we can show sequential consistency under TSO by ordinary assertional reasoning about the program, without having to consider store buffers at all. [IMP2] title = IMP2 – Simple Program Verification in Isabelle/HOL author = Peter Lammich , Simon Wimmer topic = Computer science/Programming languages/Logics, Computer science/Algorithms date = 2019-01-15 notify = lammich@in.tum.de abstract = IMP2 is a simple imperative language together with Isabelle tooling to create a program verification environment in Isabelle/HOL. The tools include a C-like syntax, a verification condition generator, and Isabelle commands for the specification of programs. The framework is modular, i.e., it allows easy reuse of already proved programs within larger programs. This entry comes with a quickstart guide and a large collection of examples, spanning basic algorithms with simple proofs to more advanced algorithms and proof techniques like data refinement. Some highlights from the examples are:
  • Bisection Square Root,
  • Extended Euclid,
  • Exponentiation by Squaring,
  • Binary Search,
  • Insertion Sort,
  • Quicksort,
  • Depth First Search.
The abstract syntax and semantics are very simple and well-documented. They are suitable to be used in a course, as extension to the IMP language which comes with the Isabelle distribution. While this entry is limited to a simple imperative language, the ideas could be extended to more sophisticated languages. [Farkas] title = Farkas' Lemma and Motzkin's Transposition Theorem author = Ralph Bottesch , Max W. Haslbeck , René Thiemann topic = Mathematics/Algebra date = 2019-01-17 notify = rene.thiemann@uibk.ac.at abstract = We formalize a proof of Motzkin's transposition theorem and Farkas' lemma in Isabelle/HOL. Our proof is based on the formalization of the simplex algorithm which, given a set of linear constraints, either returns a satisfying assignment to the problem or detects unsatisfiability. By reusing facts about the simplex algorithm we show that a set of linear constraints is unsatisfiable if and only if there is a linear combination of the constraints which evaluates to a trivially unsatisfiable inequality. [Auto2_Imperative_HOL] title = Verifying Imperative Programs using Auto2 author = Bohua Zhan topic = Computer science/Algorithms, Computer science/Data structures date = 2018-12-21 notify = bzhan@ios.ac.cn abstract = This entry contains the application of auto2 to verifying functional and imperative programs. Algorithms and data structures that are verified include linked lists, binary search trees, red-black trees, interval trees, priority queue, quicksort, union-find, Dijkstra's algorithm, and a sweep-line algorithm for detecting rectangle intersection. The imperative verification is based on Imperative HOL and its separation logic framework. A major goal of this work is to set up automation in order to reduce the length of proof that the user needs to provide, both for verifying functional programs and for working with separation logic. [UTP] title = Isabelle/UTP: Mechanised Theory Engineering for Unifying Theories of Programming author = Simon Foster , Frank Zeyda<>, Yakoub Nemouchi , Pedro Ribeiro<>, Burkhart Wolff topic = Computer science/Programming languages/Logics date = 2019-02-01 notify = simon.foster@york.ac.uk abstract = Isabelle/UTP is a mechanised theory engineering toolkit based on Hoare and He’s Unifying Theories of Programming (UTP). UTP enables the creation of denotational, algebraic, and operational semantics for different programming languages using an alphabetised relational calculus. We provide a semantic embedding of the alphabetised relational calculus in Isabelle/HOL, including new type definitions, relational constructors, automated proof tactics, and accompanying algebraic laws. Isabelle/UTP can be used to both capture laws of programming for different languages, and put these fundamental theorems to work in the creation of associated verification tools, using calculi like Hoare logics. This document describes the relational core of the UTP in Isabelle/HOL. [HOL-CSP] title = HOL-CSP Version 2.0 author = Safouan Taha , Lina Ye , Burkhart Wolff topic = Computer science/Concurrency/Process calculi, Computer science/Semantics date = 2019-04-26 notify = wolff@lri.fr abstract = This is a complete formalization of the work of Hoare and Roscoe on the denotational semantics of the Failure/Divergence Model of CSP. It follows essentially the presentation of CSP in Roscoe’s Book ”Theory and Practice of Concurrency” [8] and the semantic details in a joint Paper of Roscoe and Brooks ”An improved failures model for communicating processes". The present work is based on a prior formalization attempt, called HOL-CSP 1.0, done in 1997 by H. Tej and B. Wolff with the Isabelle proof technology available at that time. This work revealed minor, but omnipresent foundational errors in key concepts like the process invariant. The present version HOL-CSP profits from substantially improved libraries (notably HOLCF), improved automated proof techniques, and structured proof techniques in Isar and is substantially shorter but more complete. [Probabilistic_Prime_Tests] title = Probabilistic Primality Testing author = Daniel Stüwe<>, Manuel Eberl topic = Mathematics/Number theory date = 2019-02-11 notify = eberlm@in.tum.de abstract =

The most efficient known primality tests are probabilistic in the sense that they use randomness and may, with some probability, mistakenly classify a composite number as prime – but never a prime number as composite. Examples of this are the Miller–Rabin test, the Solovay–Strassen test, and (in most cases) Fermat's test.

This entry defines these three tests and proves their correctness. It also develops some of the number-theoretic foundations, such as Carmichael numbers and the Jacobi symbol with an efficient executable algorithm to compute it.

[Kruskal] title = Kruskal's Algorithm for Minimum Spanning Forest author = Maximilian P.L. Haslbeck , Peter Lammich , Julian Biendarra<> topic = Computer science/Algorithms/Graph date = 2019-02-14 notify = haslbema@in.tum.de, lammich@in.tum.de abstract = This Isabelle/HOL formalization defines a greedy algorithm for finding a minimum weight basis on a weighted matroid and proves its correctness. This algorithm is an abstract version of Kruskal's algorithm. We interpret the abstract algorithm for the cycle matroid (i.e. forests in a graph) and refine it to imperative executable code using an efficient union-find data structure. Our formalization can be instantiated for different graph representations. We provide instantiations for undirected graphs and symmetric directed graphs. [List_Inversions] title = The Inversions of a List author = Manuel Eberl topic = Computer science/Algorithms date = 2019-02-01 notify = eberlm@in.tum.de abstract =

This entry defines the set of inversions of a list, i.e. the pairs of indices that violate sortedness. It also proves the correctness of the well-known O(n log n) divide-and-conquer algorithm to compute the number of inversions.

[Prime_Distribution_Elementary] title = Elementary Facts About the Distribution of Primes author = Manuel Eberl topic = Mathematics/Number theory date = 2019-02-21 notify = eberlm@in.tum.de abstract =

This entry is a formalisation of Chapter 4 (and parts of Chapter 3) of Apostol's Introduction to Analytic Number Theory. The main topics that are addressed are properties of the distribution of prime numbers that can be shown in an elementary way (i. e. without the Prime Number Theorem), the various equivalent forms of the PNT (which imply each other in elementary ways), and consequences that follow from the PNT in elementary ways. The latter include, most notably, asymptotic bounds for the number of distinct prime factors of n, the divisor function d(n), Euler's totient function φ(n), and lcm(1,…,n).

[Safe_OCL] title = Safe OCL author = Denis Nikiforov <> topic = Computer science/Programming languages/Language definitions license = LGPL date = 2019-03-09 notify = denis.nikif@gmail.com abstract =

The theory is a formalization of the OCL type system, its abstract syntax and expression typing rules. The theory does not define a concrete syntax and a semantics. In contrast to Featherweight OCL, it is based on a deep embedding approach. The type system is defined from scratch, it is not based on the Isabelle HOL type system.

The Safe OCL distincts nullable and non-nullable types. Also the theory gives a formal definition of safe navigation operations. The Safe OCL typing rules are much stricter than rules given in the OCL specification. It allows one to catch more errors on a type checking phase.

The type theory presented is four-layered: classes, basic types, generic types, errorable types. We introduce the following new types: non-nullable types (T[1]), nullable types (T[?]), OclSuper. OclSuper is a supertype of all other types (basic types, collections, tuples). This type allows us to define a total supremum function, so types form an upper semilattice. It allows us to define rich expression typing rules in an elegant manner.

The Preliminaries Chapter of the theory defines a number of helper lemmas for transitive closures and tuples. It defines also a generic object model independent from OCL. It allows one to use the theory as a reference for formalization of analogous languages.

[QHLProver] title = Quantum Hoare Logic author = Junyi Liu<>, Bohua Zhan , Shuling Wang<>, Shenggang Ying<>, Tao Liu<>, Yangjia Li<>, Mingsheng Ying<>, Naijun Zhan<> topic = Computer science/Programming languages/Logics, Computer science/Semantics date = 2019-03-24 notify = bzhan@ios.ac.cn abstract = We formalize quantum Hoare logic as given in [1]. In particular, we specify the syntax and denotational semantics of a simple model of quantum programs. Then, we write down the rules of quantum Hoare logic for partial correctness, and show the soundness and completeness of the resulting proof system. As an application, we verify the correctness of Grover’s algorithm. [Transcendence_Series_Hancl_Rucki] title = The Transcendence of Certain Infinite Series author = Angeliki Koutsoukou-Argyraki , Wenda Li topic = Mathematics/Analysis, Mathematics/Number theory date = 2019-03-27 notify = wl302@cam.ac.uk, ak2110@cam.ac.uk abstract = We formalize the proofs of two transcendence criteria by J. Hančl and P. Rucki that assert the transcendence of the sums of certain infinite series built up by sequences that fulfil certain properties. Both proofs make use of Roth's celebrated theorem on diophantine approximations to algebraic numbers from 1955 which we implement as an assumption without having formalised its proof. [Binding_Syntax_Theory] title = A General Theory of Syntax with Bindings author = Lorenzo Gheri , Andrei Popescu topic = Computer science/Programming languages/Lambda calculi, Computer science/Functional programming, Logic/General logic/Mechanization of proofs date = 2019-04-06 notify = a.popescu@mdx.ac.uk, lor.gheri@gmail.com abstract = We formalize a theory of syntax with bindings that has been developed and refined over the last decade to support several large formalization efforts. Terms are defined for an arbitrary number of constructors of varying numbers of inputs, quotiented to alpha-equivalence and sorted according to a binding signature. The theory includes many properties of the standard operators on terms: substitution, swapping and freshness. It also includes bindings-aware induction and recursion principles and support for semantic interpretation. This work has been presented in the ITP 2017 paper “A Formalized General Theory of Syntax with Bindings”. [LTL_Master_Theorem] title = A Compositional and Unified Translation of LTL into ω-Automata author = Benedikt Seidl , Salomon Sickert topic = Computer science/Automata and formal languages date = 2019-04-16 notify = benedikt.seidl@tum.de, s.sickert@tum.de abstract = We present a formalisation of the unified translation approach of linear temporal logic (LTL) into ω-automata from [1]. This approach decomposes LTL formulas into ``simple'' languages and allows a clear separation of concerns: first, we formalise the purely logical result yielding this decomposition; second, we instantiate this generic theory to obtain a construction for deterministic (state-based) Rabin automata (DRA). We extract from this particular instantiation an executable tool translating LTL to DRAs. To the best of our knowledge this is the first verified translation from LTL to DRAs that is proven to be double exponential in the worst case which asymptotically matches the known lower bound.

[1] Javier Esparza, Jan Kretínský, Salomon Sickert. One Theorem to Rule Them All: A Unified Translation of LTL into ω-Automata. LICS 2018 [LambdaAuth] title = Formalization of Generic Authenticated Data Structures author = Matthias Brun<>, Dmitriy Traytel topic = Computer science/Security, Computer science/Programming languages/Lambda calculi date = 2019-05-14 notify = traytel@inf.ethz.ch abstract = Authenticated data structures are a technique for outsourcing data storage and maintenance to an untrusted server. The server is required to produce an efficiently checkable and cryptographically secure proof that it carried out precisely the requested computation. Miller et al. introduced λ• (pronounced lambda auth)—a functional programming language with a built-in primitive authentication construct, which supports a wide range of user-specified authenticated data structures while guaranteeing certain correctness and security properties for all well-typed programs. We formalize λ• and prove its correctness and security properties. With Isabelle's help, we uncover and repair several mistakes in the informal proofs and lemma statements. Our findings are summarized in a paper draft. [IMP2_Binary_Heap] title = Binary Heaps for IMP2 author = Simon Griebel<> topic = Computer science/Data structures, Computer science/Algorithms date = 2019-06-13 notify = s.griebel@tum.de abstract = In this submission array-based binary minimum heaps are formalized. The correctness of the following heap operations is proved: insert, get-min, delete-min and make-heap. These are then used to verify an in-place heapsort. The formalization is based on IMP2, an imperative program verification framework implemented in Isabelle/HOL. The verified heap functions are iterative versions of the partly recursive functions found in "Algorithms and Data Structures – The Basic Toolbox" by K. Mehlhorn and P. Sanders and "Introduction to Algorithms" by T. H. Cormen, C. E. Leiserson, R. L. Rivest and C. Stein. [Groebner_Macaulay] title = Gröbner Bases, Macaulay Matrices and Dubé's Degree Bounds author = Alexander Maletzky topic = Mathematics/Algebra date = 2019-06-15 notify = alexander.maletzky@risc.jku.at abstract = This entry formalizes the connection between Gröbner bases and Macaulay matrices (sometimes also referred to as `generalized Sylvester matrices'). In particular, it contains a method for computing Gröbner bases, which proceeds by first constructing some Macaulay matrix of the initial set of polynomials, then row-reducing this matrix, and finally converting the result back into a set of polynomials. The output is shown to be a Gröbner basis if the Macaulay matrix constructed in the first step is sufficiently large. In order to obtain concrete upper bounds on the size of the matrix (and hence turn the method into an effectively executable algorithm), Dubé's degree bounds on Gröbner bases are utilized; consequently, they are also part of the formalization. [Linear_Inequalities] title = Linear Inequalities author = Ralph Bottesch , Alban Reynaud <>, René Thiemann topic = Mathematics/Algebra date = 2019-06-21 notify = rene.thiemann@uibk.ac.at abstract = We formalize results about linear inqualities, mainly from Schrijver's book. The main results are the proof of the fundamental theorem on linear inequalities, Farkas' lemma, Carathéodory's theorem, the Farkas-Minkowsky-Weyl theorem, the decomposition theorem of polyhedra, and Meyer's result that the integer hull of a polyhedron is a polyhedron itself. Several theorems include bounds on the appearing numbers, and in particular we provide an a-priori bound on mixed-integer solutions of linear inequalities. [Linear_Programming] title = Linear Programming author = Julian Parsert , Cezary Kaliszyk topic = Mathematics/Algebra date = 2019-08-06 notify = julian.parsert@gmail.com, cezary.kaliszyk@uibk.ac.at abstract = We use the previous formalization of the general simplex algorithm to formulate an algorithm for solving linear programs. We encode the linear programs using only linear constraints. Solving these constraints also solves the original linear program. This algorithm is proven to be sound by applying the weak duality theorem which is also part of this formalization. [Differential_Game_Logic] title = Differential Game Logic author = André Platzer topic = Computer science/Programming languages/Logics date = 2019-06-03 notify = aplatzer@cs.cmu.edu abstract = This formalization provides differential game logic (dGL), a logic for proving properties of hybrid game. In addition to the syntax and semantics, it formalizes a uniform substitution calculus for dGL. Church's uniform substitutions substitute a term or formula for a function or predicate symbol everywhere. The uniform substitutions for dGL also substitute hybrid games for a game symbol everywhere. We prove soundness of one-pass uniform substitutions and the axioms of differential game logic with respect to their denotational semantics. One-pass uniform substitutions are faster by postponing soundness-critical admissibility checks with a linear pass homomorphic application and regain soundness by a variable condition at the replacements. The formalization is based on prior non-mechanized soundness proofs for dGL. [Complete_Non_Orders] title = Complete Non-Orders and Fixed Points author = Akihisa Yamada , Jérémy Dubut topic = Mathematics/Order date = 2019-06-27 notify = akihisayamada@nii.ac.jp, dubut@nii.ac.jp abstract = We develop an Isabelle/HOL library of order-theoretic concepts, such as various completeness conditions and fixed-point theorems. We keep our formalization as general as possible: we reprove several well-known results about complete orders, often without any properties of ordering, thus complete non-orders. In particular, we generalize the Knaster–Tarski theorem so that we ensure the existence of a quasi-fixed point of monotone maps over complete non-orders, and show that the set of quasi-fixed points is complete under a mild condition—attractivity—which is implied by either antisymmetry or transitivity. This result generalizes and strengthens a result by Stauti and Maaden. Finally, we recover Kleene’s fixed-point theorem for omega-complete non-orders, again using attractivity to prove that Kleene’s fixed points are least quasi-fixed points. [Priority_Search_Trees] title = Priority Search Trees author = Peter Lammich , Tobias Nipkow topic = Computer science/Data structures date = 2019-06-25 notify = lammich@in.tum.de abstract = We present a new, purely functional, simple and efficient data structure combining a search tree and a priority queue, which we call a priority search tree. The salient feature of priority search trees is that they offer a decrease-key operation, something that is missing from other simple, purely functional priority queue implementations. Priority search trees can be implemented on top of any search tree. This entry does the implementation for red-black trees. This entry formalizes the first part of our ITP-2019 proof pearl Purely Functional, Simple and Efficient Priority Search Trees and Applications to Prim and Dijkstra. [Prim_Dijkstra_Simple] title = Purely Functional, Simple, and Efficient Implementation of Prim and Dijkstra author = Peter Lammich , Tobias Nipkow topic = Computer science/Algorithms/Graph date = 2019-06-25 notify = lammich@in.tum.de abstract = We verify purely functional, simple and efficient implementations of Prim's and Dijkstra's algorithms. This constitutes the first verification of an executable and even efficient version of Prim's algorithm. This entry formalizes the second part of our ITP-2019 proof pearl Purely Functional, Simple and Efficient Priority Search Trees and Applications to Prim and Dijkstra. [MFOTL_Monitor] title = Formalization of a Monitoring Algorithm for Metric First-Order Temporal Logic author = Joshua Schneider , Dmitriy Traytel topic = Computer science/Algorithms, Logic/General logic/Temporal logic, Computer science/Automata and formal languages date = 2019-07-04 notify = joshua.schneider@inf.ethz.ch, traytel@inf.ethz.ch abstract = A monitor is a runtime verification tool that solves the following problem: Given a stream of time-stamped events and a policy formulated in a specification language, decide whether the policy is satisfied at every point in the stream. We verify the correctness of an executable monitor for specifications given as formulas in metric first-order temporal logic (MFOTL), an expressive extension of linear temporal logic with real-time constraints and first-order quantification. The verified monitor implements a simplified variant of the algorithm used in the efficient MonPoly monitoring tool. The formalization is presented in a RV 2019 paper, which also compares the output of the verified monitor to that of other monitoring tools on randomly generated inputs. This case study revealed several errors in the optimized but unverified tools. extra-history = Change history: [2020-08-13]: added the formalization of the abstract slicing framework and joint data slicer (revision b1639ed541b7)
[FOL_Seq_Calc1] title = A Sequent Calculus for First-Order Logic author = Asta Halkjær From contributors = Alexander Birch Jensen , Anders Schlichtkrull , Jørgen Villadsen topic = Logic/Proof theory date = 2019-07-18 notify = ahfrom@dtu.dk abstract = This work formalizes soundness and completeness of a one-sided sequent calculus for first-order logic. The completeness is shown via a translation from a complete semantic tableau calculus, the proof of which is based on the First-Order Logic According to Fitting theory. The calculi and proof techniques are taken from Ben-Ari's Mathematical Logic for Computer Science. [Szpilrajn] title = Order Extension and Szpilrajn's Extension Theorem author = Peter Zeller , Lukas Stevens topic = Mathematics/Order date = 2019-07-27 notify = p_zeller@cs.uni-kl.de abstract = This entry is concerned with the principle of order extension, i.e. the extension of an order relation to a total order relation. To this end, we prove a more general version of Szpilrajn's extension theorem employing terminology from the book "Consistency, Choice, and Rationality" by Bossert and Suzumura. We also formalize theorem 2.7 of their book. extra-history = Change history: [2021-03-22]: (by Lukas Stevens) generalise Szpilrajn's extension theorem and add material from the book "Consistency, Choice, and Rationality" [TESL_Language] title = A Formal Development of a Polychronous Polytimed Coordination Language author = Hai Nguyen Van , Frédéric Boulanger , Burkhart Wolff topic = Computer science/System description languages, Computer science/Semantics, Computer science/Concurrency date = 2019-07-30 notify = frederic.boulanger@centralesupelec.fr, burkhart.wolff@lri.fr abstract = The design of complex systems involves different formalisms for modeling their different parts or aspects. The global model of a system may therefore consist of a coordination of concurrent sub-models that use different paradigms. We develop here a theory for a language used to specify the timed coordination of such heterogeneous subsystems by addressing the following issues:

  • the behavior of the sub-systems is observed only at a series of discrete instants,
  • events may occur in different sub-systems at unrelated times, leading to polychronous systems, which do not necessarily have a common base clock,
  • coordination between subsystems involves causality, so the occurrence of an event may enforce the occurrence of other events, possibly after a certain duration has elapsed or an event has occurred a given number of times,
  • the domain of time (discrete, rational, continuous...) may be different in the subsystems, leading to polytimed systems,
  • the time frames of different sub-systems may be related (for instance, time in a GPS satellite and in a GPS receiver on Earth are related although they are not the same).
Firstly, a denotational semantics of the language is defined. Then, in order to be able to incrementally check the behavior of systems, an operational semantics is given, with proofs of progress, soundness and completeness with regard to the denotational semantics. These proofs are made according to a setup that can scale up when new operators are added to the language. In order for specifications to be composed in a clean way, the language should be invariant by stuttering (i.e., adding observation instants at which nothing happens). The proof of this invariance is also given. [Stellar_Quorums] title = Stellar Quorum Systems author = Giuliano Losa topic = Computer science/Algorithms/Distributed date = 2019-08-01 notify = giuliano@galois.com abstract = We formalize the static properties of personal Byzantine quorum systems (PBQSs) and Stellar quorum systems, as described in the paper ``Stellar Consensus by Reduction'' (to appear at DISC 2019). [IMO2019] title = Selected Problems from the International Mathematical Olympiad 2019 author = Manuel Eberl topic = Mathematics/Misc date = 2019-08-05 notify = eberlm@in.tum.de abstract =

This entry contains formalisations of the answers to three of the six problem of the International Mathematical Olympiad 2019, namely Q1, Q4, and Q5.

The reason why these problems were chosen is that they are particularly amenable to formalisation: they can be solved with minimal use of libraries. The remaining three concern geometry and graph theory, which, in the author's opinion, are more difficult to formalise resp. require a more complex library.

[Adaptive_State_Counting] title = Formalisation of an Adaptive State Counting Algorithm author = Robert Sachtleben topic = Computer science/Automata and formal languages, Computer science/Algorithms date = 2019-08-16 notify = rob_sac@uni-bremen.de abstract = This entry provides a formalisation of a refinement of an adaptive state counting algorithm, used to test for reduction between finite state machines. The algorithm has been originally presented by Hierons in the paper Testing from a Non-Deterministic Finite State Machine Using Adaptive State Counting. Definitions for finite state machines and adaptive test cases are given and many useful theorems are derived from these. The algorithm is formalised using mutually recursive functions, for which it is proven that the generated test suite is sufficient to test for reduction against finite state machines of a certain fault domain. Additionally, the algorithm is specified in a simple WHILE-language and its correctness is shown using Hoare-logic. [Jacobson_Basic_Algebra] title = A Case Study in Basic Algebra author = Clemens Ballarin topic = Mathematics/Algebra date = 2019-08-30 notify = ballarin@in.tum.de abstract = The focus of this case study is re-use in abstract algebra. It contains locale-based formalisations of selected parts of set, group and ring theory from Jacobson's Basic Algebra leading to the respective fundamental homomorphism theorems. The study is not intended as a library base for abstract algebra. It rather explores an approach towards abstract algebra in Isabelle. [Hybrid_Systems_VCs] title = Verification Components for Hybrid Systems author = Jonathan Julian Huerta y Munive <> topic = Mathematics/Algebra, Mathematics/Analysis date = 2019-09-10 notify = jjhuertaymunive1@sheffield.ac.uk, jonjulian23@gmail.com abstract = These components formalise a semantic framework for the deductive verification of hybrid systems. They support reasoning about continuous evolutions of hybrid programs in the style of differential dynamics logic. Vector fields or flows model these evolutions, and their verification is done with invariants for the former or orbits for the latter. Laws of modal Kleene algebra or categorical predicate transformers implement the verification condition generation. Examples show the approach at work. extra-history = Change history: [2020-12-13]: added components based on Kleene algebras with tests. These implement differential Hoare logic (dH) and a Morgan-style differential refinement calculus (dR) for verification of hybrid programs. [Generic_Join] title = Formalization of Multiway-Join Algorithms author = Thibault Dardinier<> topic = Computer science/Algorithms date = 2019-09-16 notify = tdardini@student.ethz.ch, traytel@inf.ethz.ch abstract = Worst-case optimal multiway-join algorithms are recent seminal achievement of the database community. These algorithms compute the natural join of multiple relational databases and improve in the worst case over traditional query plan optimizations of nested binary joins. In 2014, Ngo, Ré, and Rudra gave a unified presentation of different multi-way join algorithms. We formalized and proved correct their "Generic Join" algorithm and extended it to support negative joins. [Aristotles_Assertoric_Syllogistic] title = Aristotle's Assertoric Syllogistic author = Angeliki Koutsoukou-Argyraki topic = Logic/Philosophical aspects date = 2019-10-08 notify = ak2110@cam.ac.uk abstract = We formalise with Isabelle/HOL some basic elements of Aristotle's assertoric syllogistic following the article from the Stanford Encyclopedia of Philosophy by Robin Smith. To this end, we use a set theoretic formulation (covering both individual and general predication). In particular, we formalise the deductions in the Figures and after that we present Aristotle's metatheoretical observation that all deductions in the Figures can in fact be reduced to either Barbara or Celarent. As the formal proofs prove to be straightforward, the interest of this entry lies in illustrating the functionality of Isabelle and high efficiency of Sledgehammer for simple exercises in philosophy. [VerifyThis2019] title = VerifyThis 2019 -- Polished Isabelle Solutions author = Peter Lammich<>, Simon Wimmer topic = Computer science/Algorithms date = 2019-10-16 notify = lammich@in.tum.de, wimmers@in.tum.de abstract = VerifyThis 2019 (http://www.pm.inf.ethz.ch/research/verifythis.html) was a program verification competition associated with ETAPS 2019. It was the 8th event in the VerifyThis competition series. In this entry, we present polished and completed versions of our solutions that we created during the competition. [ZFC_in_HOL] title = Zermelo Fraenkel Set Theory in Higher-Order Logic author = Lawrence C. Paulson topic = Logic/Set theory date = 2019-10-24 notify = lp15@cam.ac.uk abstract =

This entry is a new formalisation of ZFC set theory in Isabelle/HOL. It is logically equivalent to Obua's HOLZF; the point is to have the closest possible integration with the rest of Isabelle/HOL, minimising the amount of new notations and exploiting type classes.

There is a type V of sets and a function elts :: V => V set mapping a set to its elements. Classes simply have type V set, and a predicate identifies the small classes: those that correspond to actual sets. Type classes connected with orders and lattices are used to minimise the amount of new notation for concepts such as the subset relation, union and intersection. Basic concepts — Cartesian products, disjoint sums, natural numbers, functions, etc. — are formalised.

More advanced set-theoretic concepts, such as transfinite induction, ordinals, cardinals and the transitive closure of a set, are also provided. The definition of addition and multiplication for general sets (not just ordinals) follows Kirby.

The theory provides two type classes with the aim of facilitating developments that combine V with other Isabelle/HOL types: embeddable, the class of types that can be injected into V (including V itself as well as V*V, etc.), and small, the class of types that correspond to some ZF set.

extra-history = Change history: [2020-01-28]: Generalisation of the "small" predicate and order types to arbitrary sets; ordinal exponentiation; introduction of the coercion ord_of_nat :: "nat => V"; numerous new lemmas. (revision 6081d5be8d08) [Interval_Arithmetic_Word32] title = Interval Arithmetic on 32-bit Words author = Brandon Bohrer topic = Computer science/Data structures date = 2019-11-27 notify = bjbohrer@gmail.com, bbohrer@cs.cmu.edu abstract = Interval_Arithmetic implements conservative interval arithmetic computations, then uses this interval arithmetic to implement a simple programming language where all terms have 32-bit signed word values, with explicit infinities for terms outside the representable bounds. Our target use case is interpreters for languages that must have a well-understood low-level behavior. We include a formalization of bounded-length strings which are used for the identifiers of our language. Bounded-length identifiers are useful in some applications, for example the Differential_Dynamic_Logic article, where a Euclidean space indexed by identifiers demands that identifiers are finitely many. [Generalized_Counting_Sort] title = An Efficient Generalization of Counting Sort for Large, possibly Infinite Key Ranges author = Pasquale Noce topic = Computer science/Algorithms, Computer science/Functional programming date = 2019-12-04 notify = pasquale.noce.lavoro@gmail.com abstract = Counting sort is a well-known algorithm that sorts objects of any kind mapped to integer keys, or else to keys in one-to-one correspondence with some subset of the integers (e.g. alphabet letters). However, it is suitable for direct use, viz. not just as a subroutine of another sorting algorithm (e.g. radix sort), only if the key range is not significantly larger than the number of the objects to be sorted. This paper describes a tail-recursive generalization of counting sort making use of a bounded number of counters, suitable for direct use in case of a large, or even infinite key range of any kind, subject to the only constraint of being a subset of an arbitrary linear order. After performing a pen-and-paper analysis of how such algorithm has to be designed to maximize its efficiency, this paper formalizes the resulting generalized counting sort (GCsort) algorithm and then formally proves its correctness properties, namely that (a) the counters' number is maximized never exceeding the fixed upper bound, (b) objects are conserved, (c) objects get sorted, and (d) the algorithm is stable. [Poincare_Bendixson] title = The Poincaré-Bendixson Theorem author = Fabian Immler , Yong Kiam Tan topic = Mathematics/Analysis date = 2019-12-18 notify = fimmler@cs.cmu.edu, yongkiat@cs.cmu.edu abstract = The Poincaré-Bendixson theorem is a classical result in the study of (continuous) dynamical systems. Colloquially, it restricts the possible behaviors of planar dynamical systems: such systems cannot be chaotic. In practice, it is a useful tool for proving the existence of (limiting) periodic behavior in planar systems. The theorem is an interesting and challenging benchmark for formalized mathematics because proofs in the literature rely on geometric sketches and only hint at symmetric cases. It also requires a substantial background of mathematical theories, e.g., the Jordan curve theorem, real analysis, ordinary differential equations, and limiting (long-term) behavior of dynamical systems. [Isabelle_C] title = Isabelle/C author = Frédéric Tuong , Burkhart Wolff topic = Computer science/Programming languages/Language definitions, Computer science/Semantics, Tools date = 2019-10-22 notify = tuong@users.gforge.inria.fr, wolff@lri.fr abstract = We present a framework for C code in C11 syntax deeply integrated into the Isabelle/PIDE development environment. Our framework provides an abstract interface for verification back-ends to be plugged-in independently. Thus, various techniques such as deductive program verification or white-box testing can be applied to the same source, which is part of an integrated PIDE document model. Semantic back-ends are free to choose the supported C fragment and its semantics. In particular, they can differ on the chosen memory model or the specification mechanism for framing conditions. Our framework supports semantic annotations of C sources in the form of comments. Annotations serve to locally control back-end settings, and can express the term focus to which an annotation refers. Both the logical and the syntactic context are available when semantic annotations are evaluated. As a consequence, a formula in an annotation can refer both to HOL or C variables. Our approach demonstrates the degree of maturity and expressive power the Isabelle/PIDE sub-system has achieved in recent years. Our integration technique employs Lex and Yacc style grammars to ensure efficient deterministic parsing. This is the core-module of Isabelle/C; the AFP package for Clean and Clean_wrapper as well as AutoCorres and AutoCorres_wrapper (available via git) are applications of this front-end. [Zeta_3_Irrational] title = The Irrationality of ζ(3) author = Manuel Eberl topic = Mathematics/Number theory date = 2019-12-27 notify = manuel.eberl@tum.de abstract =

This article provides a formalisation of Beukers's straightforward analytic proof that ζ(3) is irrational. This was first proven by Apéry (which is why this result is also often called ‘Apéry's Theorem’) using a more algebraic approach. This formalisation follows Filaseta's presentation of Beukers's proof.

[Hybrid_Logic] title = Formalizing a Seligman-Style Tableau System for Hybrid Logic author = Asta Halkjær From topic = Logic/General logic/Modal logic date = 2019-12-20 notify = ahfrom@dtu.dk abstract = This work is a formalization of soundness and completeness proofs for a Seligman-style tableau system for hybrid logic. The completeness result is obtained via a synthetic approach using maximally consistent sets of tableau blocks. The formalization differs from previous work in a few ways. First, to avoid the need to backtrack in the construction of a tableau, the formalized system has no unnamed initial segment, and therefore no Name rule. Second, I show that the full Bridge rule is admissible in the system. Third, I start from rules restricted to only extend the branch with new formulas, including only witnessing diamonds that are not already witnessed, and show that the unrestricted rules are admissible. Similarly, I start from simpler versions of the @-rules and show that these are sufficient. The GoTo rule is restricted using a notion of potential such that each application consumes potential and potential is earned through applications of the remaining rules. I show that if a branch can be closed then it can be closed starting from a single unit. Finally, Nom is restricted by a fixed set of allowed nominals. The resulting system should be terminating. extra-history = Change history: [2020-06-03]: The fully restricted system has been shown complete by updating the synthetic completeness proof. [Bicategory] title = Bicategories author = Eugene W. Stark topic = Mathematics/Category theory date = 2020-01-06 notify = stark@cs.stonybrook.edu abstract =

Taking as a starting point the author's previous work on developing aspects of category theory in Isabelle/HOL, this article gives a compatible formalization of the notion of "bicategory" and develops a framework within which formal proofs of facts about bicategories can be given. The framework includes a number of basic results, including the Coherence Theorem, the Strictness Theorem, pseudofunctors and biequivalence, and facts about internal equivalences and adjunctions in a bicategory. As a driving application and demonstration of the utility of the framework, it is used to give a formal proof of a theorem, due to Carboni, Kasangian, and Street, that characterizes up to biequivalence the bicategories of spans in a category with pullbacks. The formalization effort necessitated the filling-in of many details that were not evident from the brief presentation in the original paper, as well as identifying a few minor corrections along the way.

Revisions made subsequent to the first version of this article added additional material on pseudofunctors, pseudonatural transformations, modifications, and equivalence of bicategories; the main thrust being to give a proof that a pseudofunctor is a biequivalence if and only if it can be extended to an equivalence of bicategories.

extra-history = Change history: [2020-02-15]: Move ConcreteCategory.thy from Bicategory to Category3 and use it systematically. Make other minor improvements throughout. (revision a51840d36867)
[2020-11-04]: Added new material on equivalence of bicategories, with associated changes. (revision 472cb2268826)
[Subset_Boolean_Algebras] title = A Hierarchy of Algebras for Boolean Subsets author = Walter Guttmann , Bernhard Möller topic = Mathematics/Algebra date = 2020-01-31 notify = walter.guttmann@canterbury.ac.nz abstract = We present a collection of axiom systems for the construction of Boolean subalgebras of larger overall algebras. The subalgebras are defined as the range of a complement-like operation on a semilattice. This technique has been used, for example, with the antidomain operation, dynamic negation and Stone algebras. We present a common ground for these constructions based on a new equational axiomatisation of Boolean algebras. [Goodstein_Lambda] title = Implementing the Goodstein Function in λ-Calculus author = Bertram Felgenhauer topic = Logic/Rewriting date = 2020-02-21 notify = int-e@gmx.de abstract = In this formalization, we develop an implementation of the Goodstein function G in plain λ-calculus, linked to a concise, self-contained specification. The implementation works on a Church-encoded representation of countable ordinals. The initial conversion to hereditary base 2 is not covered, but the material is sufficient to compute the particular value G(16), and easily extends to other fixed arguments. [VeriComp] title = A Generic Framework for Verified Compilers author = Martin Desharnais topic = Computer science/Programming languages/Compiling date = 2020-02-10 notify = martin.desharnais@unibw.de abstract = This is a generic framework for formalizing compiler transformations. It leverages Isabelle/HOL’s locales to abstract over concrete languages and transformations. It states common definitions for language semantics, program behaviours, forward and backward simulations, and compilers. We provide generic operations, such as simulation and compiler composition, and prove general (partial) correctness theorems, resulting in reusable proof components. [Hello_World] title = Hello World author = Cornelius Diekmann , Lars Hupel topic = Computer science/Functional programming date = 2020-03-07 notify = diekmann@net.in.tum.de abstract = In this article, we present a formalization of the well-known "Hello, World!" code, including a formal framework for reasoning about IO. Our model is inspired by the handling of IO in Haskell. We start by formalizing the 🌍 and embrace the IO monad afterwards. Then we present a sample main :: IO (), followed by its proof of correctness. [WOOT_Strong_Eventual_Consistency] title = Strong Eventual Consistency of the Collaborative Editing Framework WOOT author = Emin Karayel , Edgar Gonzàlez topic = Computer science/Algorithms/Distributed date = 2020-03-25 notify = eminkarayel@google.com, edgargip@google.com, me@eminkarayel.de abstract = Commutative Replicated Data Types (CRDTs) are a promising new class of data structures for large-scale shared mutable content in applications that only require eventual consistency. The WithOut Operational Transforms (WOOT) framework is a CRDT for collaborative text editing introduced by Oster et al. (CSCW 2006) for which the eventual consistency property was verified only for a bounded model to date. We contribute a formal proof for WOOTs strong eventual consistency. [Furstenberg_Topology] title = Furstenberg's topology and his proof of the infinitude of primes author = Manuel Eberl topic = Mathematics/Number theory date = 2020-03-22 notify = manuel.eberl@tum.de abstract =

This article gives a formal version of Furstenberg's topological proof of the infinitude of primes. He defines a topology on the integers based on arithmetic progressions (or, equivalently, residue classes). Using some fairly obvious properties of this topology, the infinitude of primes is then easily obtained.

Apart from this, this topology is also fairly ‘nice’ in general: it is second countable, metrizable, and perfect. All of these (well-known) facts are formally proven, including an explicit metric for the topology given by Zulfeqarr.

[Saturation_Framework] title = A Comprehensive Framework for Saturation Theorem Proving author = Sophie Tourret topic = Logic/General logic/Mechanization of proofs date = 2020-04-09 notify = stourret@mpi-inf.mpg.de abstract = This Isabelle/HOL formalization is the companion of the technical report “A comprehensive framework for saturation theorem proving”, itself companion of the eponym IJCAR 2020 paper, written by Uwe Waldmann, Sophie Tourret, Simon Robillard and Jasmin Blanchette. It verifies a framework for formal refutational completeness proofs of abstract provers that implement saturation calculi, such as ordered resolution or superposition, and allows to model entire prover architectures in such a way that the static refutational completeness of a calculus immediately implies the dynamic refutational completeness of a prover implementing the calculus using a variant of the given clause loop. The technical report “A comprehensive framework for saturation theorem proving” is available on the Matryoshka website. The names of the Isabelle lemmas and theorems corresponding to the results in the report are indicated in the margin of the report. [Saturation_Framework_Extensions] title = Extensions to the Comprehensive Framework for Saturation Theorem Proving author = Jasmin Blanchette , Sophie Tourret topic = Logic/General logic/Mechanization of proofs date = 2020-08-25 notify = jasmin.blanchette@gmail.com abstract = This Isabelle/HOL formalization extends the AFP entry Saturation_Framework with the following contributions:
  • an application of the framework to prove Bachmair and Ganzinger's resolution prover RP refutationally complete, which was formalized in a more ad hoc fashion by Schlichtkrull et al. in the AFP entry Ordered_Resultion_Prover;
  • generalizations of various basic concepts formalized by Schlichtkrull et al., which were needed to verify RP and could be useful to formalize other calculi, such as superposition;
  • alternative proofs of fairness (and hence saturation and ultimately refutational completeness) for the given clause procedures GC and LGC, based on invariance.
[MFODL_Monitor_Optimized] title = Formalization of an Optimized Monitoring Algorithm for Metric First-Order Dynamic Logic with Aggregations author = Thibault Dardinier<>, Lukas Heimes<>, Martin Raszyk , Joshua Schneider , Dmitriy Traytel topic = Computer science/Algorithms, Logic/General logic/Modal logic, Computer science/Automata and formal languages date = 2020-04-09 notify = martin.raszyk@inf.ethz.ch, joshua.schneider@inf.ethz.ch, traytel@inf.ethz.ch abstract = A monitor is a runtime verification tool that solves the following problem: Given a stream of time-stamped events and a policy formulated in a specification language, decide whether the policy is satisfied at every point in the stream. We verify the correctness of an executable monitor for specifications given as formulas in metric first-order dynamic logic (MFODL), which combines the features of metric first-order temporal logic (MFOTL) and metric dynamic logic. Thus, MFODL supports real-time constraints, first-order parameters, and regular expressions. Additionally, the monitor supports aggregation operations such as count and sum. This formalization, which is described in a forthcoming paper at IJCAR 2020, significantly extends previous work on a verified monitor for MFOTL. Apart from the addition of regular expressions and aggregations, we implemented multi-way joins and a specialized sliding window algorithm to further optimize the monitor. [Sliding_Window_Algorithm] title = Formalization of an Algorithm for Greedily Computing Associative Aggregations on Sliding Windows author = Lukas Heimes<>, Dmitriy Traytel , Joshua Schneider<> topic = Computer science/Algorithms date = 2020-04-10 notify = heimesl@student.ethz.ch, traytel@inf.ethz.ch, joshua.schneider@inf.ethz.ch abstract = Basin et al.'s sliding window algorithm (SWA) is an algorithm for combining the elements of subsequences of a sequence with an associative operator. It is greedy and minimizes the number of operator applications. We formalize the algorithm and verify its functional correctness. We extend the algorithm with additional operations and provide an alternative interface to the slide operation that does not require the entire input sequence. [Lucas_Theorem] title = Lucas's Theorem author = Chelsea Edmonds topic = Mathematics/Number theory date = 2020-04-07 notify = cle47@cam.ac.uk abstract = This work presents a formalisation of a generating function proof for Lucas's theorem. We first outline extensions to the existing Formal Power Series (FPS) library, including an equivalence relation for coefficients modulo n, an alternate binomial theorem statement, and a formalised proof of the Freshman's dream (mod p) lemma. The second part of the work presents the formal proof of Lucas's Theorem. Working backwards, the formalisation first proves a well known corollary of the theorem which is easier to formalise, and then applies induction to prove the original theorem statement. The proof of the corollary aims to provide a good example of a formalised generating function equivalence proof using the FPS library. The final theorem statement is intended to be integrated into the formalised proof of Hilbert's 10th Problem. [ADS_Functor] title = Authenticated Data Structures As Functors author = Andreas Lochbihler , Ognjen Marić topic = Computer science/Data structures date = 2020-04-16 notify = andreas.lochbihler@digitalasset.com, mail@andreas-lochbihler.de abstract = Authenticated data structures allow several systems to convince each other that they are referring to the same data structure, even if each of them knows only a part of the data structure. Using inclusion proofs, knowledgeable systems can selectively share their knowledge with other systems and the latter can verify the authenticity of what is being shared. In this article, we show how to modularly define authenticated data structures, their inclusion proofs, and operations thereon as datatypes in Isabelle/HOL, using a shallow embedding. Modularity allows us to construct complicated trees from reusable building blocks, which we call Merkle functors. Merkle functors include sums, products, and function spaces and are closed under composition and least fixpoints. As a practical application, we model the hierarchical transactions of Canton, a practical interoperability protocol for distributed ledgers, as authenticated data structures. This is a first step towards formalizing the Canton protocol and verifying its integrity and security guarantees. [Power_Sum_Polynomials] title = Power Sum Polynomials author = Manuel Eberl topic = Mathematics/Algebra date = 2020-04-24 notify = eberlm@in.tum.de abstract =

This article provides a formalisation of the symmetric multivariate polynomials known as power sum polynomials. These are of the form pn(X1,…, Xk) = X1n + … + Xkn. A formal proof of the Girard–Newton Theorem is also given. This theorem relates the power sum polynomials to the elementary symmetric polynomials sk in the form of a recurrence relation (-1)k k sk = ∑i∈[0,k) (-1)i si pk-i .

As an application, this is then used to solve a generalised form of a puzzle given as an exercise in Dummit and Foote's Abstract Algebra: For k complex unknowns x1, …, xk, define pj := x1j + … + xkj. Then for each vector a ∈ ℂk, show that there is exactly one solution to the system p1 = a1, …, pk = ak up to permutation of the xi and determine the value of pi for i>k.

[Formal_Puiseux_Series] title = Formal Puiseux Series author = Manuel Eberl topic = Mathematics/Algebra date = 2021-02-17 notify = eberlm@in.tum.de abstract =

Formal Puiseux series are generalisations of formal power series and formal Laurent series that also allow for fractional exponents. They have the following general form: \[\sum_{i=N}^\infty a_{i/d} X^{i/d}\] where N is an integer and d is a positive integer.

This entry defines these series including their basic algebraic properties. Furthermore, it proves the Newton–Puiseux Theorem, namely that the Puiseux series over an algebraically closed field of characteristic 0 are also algebraically closed.

[Gaussian_Integers] title = Gaussian Integers author = Manuel Eberl topic = Mathematics/Number theory date = 2020-04-24 notify = eberlm@in.tum.de abstract =

The Gaussian integers are the subring ℤ[i] of the complex numbers, i. e. the ring of all complex numbers with integral real and imaginary part. This article provides a definition of this ring as well as proofs of various basic properties, such as that they form a Euclidean ring and a full classification of their primes. An executable (albeit not very efficient) factorisation algorithm is also provided.

Lastly, this Gaussian integer formalisation is used in two short applications:

  1. The characterisation of all positive integers that can be written as sums of two squares
  2. Euclid's formula for primitive Pythagorean triples

While elementary proofs for both of these are already available in the AFP, the theory of Gaussian integers provides more concise proofs and a more high-level view.

[Forcing] title = Formalization of Forcing in Isabelle/ZF author = Emmanuel Gunther , Miguel Pagano , Pedro Sánchez Terraf topic = Logic/Set theory date = 2020-05-06 notify = gunther@famaf.unc.edu.ar, pagano@famaf.unc.edu.ar, sterraf@famaf.unc.edu.ar abstract = We formalize the theory of forcing in the set theory framework of Isabelle/ZF. Under the assumption of the existence of a countable transitive model of ZFC, we construct a proper generic extension and show that the latter also satisfies ZFC. [Delta_System_Lemma] title = Cofinality and the Delta System Lemma author = Pedro Sánchez Terraf topic = Mathematics/Combinatorics, Logic/Set theory date = 2020-12-27 notify = sterraf@famaf.unc.edu.ar abstract = We formalize the basic results on cofinality of linearly ordered sets and ordinals and Šanin’s Lemma for uncountable families of finite sets. This last result is used to prove the countable chain condition for Cohen posets. We work in the set theory framework of Isabelle/ZF, using the Axiom of Choice as needed. [Recursion-Addition] title = Recursion Theorem in ZF author = Georgy Dunaev topic = Logic/Set theory date = 2020-05-11 notify = georgedunaev@gmail.com abstract = This document contains a proof of the recursion theorem. This is a mechanization of the proof of the recursion theorem from the text Introduction to Set Theory, by Karel Hrbacek and Thomas Jech. This implementation may be used as the basis for a model of Peano arithmetic in ZF. While recursion and the natural numbers are already available in Isabelle/ZF, this clean development is much easier to follow. [LTL_Normal_Form] title = An Efficient Normalisation Procedure for Linear Temporal Logic: Isabelle/HOL Formalisation author = Salomon Sickert topic = Computer science/Automata and formal languages, Logic/General logic/Temporal logic date = 2020-05-08 notify = s.sickert@tum.de abstract = In the mid 80s, Lichtenstein, Pnueli, and Zuck proved a classical theorem stating that every formula of Past LTL (the extension of LTL with past operators) is equivalent to a formula of the form $\bigwedge_{i=1}^n \mathbf{G}\mathbf{F} \varphi_i \vee \mathbf{F}\mathbf{G} \psi_i$, where $\varphi_i$ and $\psi_i$ contain only past operators. Some years later, Chang, Manna, and Pnueli built on this result to derive a similar normal form for LTL. Both normalisation procedures have a non-elementary worst-case blow-up, and follow an involved path from formulas to counter-free automata to star-free regular expressions and back to formulas. We improve on both points. We present an executable formalisation of a direct and purely syntactic normalisation procedure for LTL yielding a normal form, comparable to the one by Chang, Manna, and Pnueli, that has only a single exponential blow-up. [Matrices_for_ODEs] title = Matrices for ODEs author = Jonathan Julian Huerta y Munive topic = Mathematics/Analysis, Mathematics/Algebra date = 2020-04-19 notify = jonjulian23@gmail.com abstract = Our theories formalise various matrix properties that serve to establish existence, uniqueness and characterisation of the solution to affine systems of ordinary differential equations (ODEs). In particular, we formalise the operator and maximum norm of matrices. Then we use them to prove that square matrices form a Banach space, and in this setting, we show an instance of Picard-Lindelöf’s theorem for affine systems of ODEs. Finally, we use this formalisation to verify three simple hybrid programs. [Irrational_Series_Erdos_Straus] title = Irrationality Criteria for Series by Erdős and Straus author = Angeliki Koutsoukou-Argyraki , Wenda Li topic = Mathematics/Number theory, Mathematics/Analysis date = 2020-05-12 notify = ak2110@cam.ac.uk, wl302@cam.ac.uk, liwenda1990@hotmail.com abstract = We formalise certain irrationality criteria for infinite series of the form: \[\sum_{n=1}^\infty \frac{b_n}{\prod_{i=1}^n a_i} \] where $\{b_n\}$ is a sequence of integers and $\{a_n\}$ a sequence of positive integers with $a_n >1$ for all large n. The results are due to P. Erdős and E. G. Straus [1]. In particular, we formalise Theorem 2.1, Corollary 2.10 and Theorem 3.1. The latter is an application of Theorem 2.1 involving the prime numbers. [Knuth_Bendix_Order] title = A Formalization of Knuth–Bendix Orders author = Christian Sternagel , René Thiemann topic = Logic/Rewriting date = 2020-05-13 notify = c.sternagel@gmail.com, rene.thiemann@uibk.ac.at abstract = We define a generalized version of Knuth–Bendix orders, including subterm coefficient functions. For these orders we formalize several properties such as strong normalization, the subterm property, closure properties under substitutions and contexts, as well as ground totality. [Stateful_Protocol_Composition_and_Typing] title = Stateful Protocol Composition and Typing author = Andreas V. Hess , Sebastian Mödersheim , Achim D. Brucker topic = Computer science/Security date = 2020-04-08 notify = avhe@dtu.dk, andreasvhess@gmail.com, samo@dtu.dk, brucker@spamfence.net, andschl@dtu.dk abstract = We provide in this AFP entry several relative soundness results for security protocols. In particular, we prove typing and compositionality results for stateful protocols (i.e., protocols with mutable state that may span several sessions), and that focuses on reachability properties. Such results are useful to simplify protocol verification by reducing it to a simpler problem: Typing results give conditions under which it is safe to verify a protocol in a typed model where only "well-typed" attacks can occur whereas compositionality results allow us to verify a composed protocol by only verifying the component protocols in isolation. The conditions on the protocols under which the results hold are furthermore syntactic in nature allowing for full automation. The foundation presented here is used in another entry to provide fully automated and formalized security proofs of stateful protocols. [Automated_Stateful_Protocol_Verification] title = Automated Stateful Protocol Verification author = Andreas V. Hess , Sebastian Mödersheim , Achim D. Brucker , Anders Schlichtkrull topic = Computer science/Security, Tools date = 2020-04-08 notify = avhe@dtu.dk, andreasvhess@gmail.com, samo@dtu.dk, brucker@spamfence.net, andschl@dtu.dk abstract = In protocol verification we observe a wide spectrum from fully automated methods to interactive theorem proving with proof assistants like Isabelle/HOL. In this AFP entry, we present a fully-automated approach for verifying stateful security protocols, i.e., protocols with mutable state that may span several sessions. The approach supports reachability goals like secrecy and authentication. We also include a simple user-friendly transaction-based protocol specification language that is embedded into Isabelle. [Smith_Normal_Form] title = A verified algorithm for computing the Smith normal form of a matrix author = Jose Divasón topic = Mathematics/Algebra, Computer science/Algorithms/Mathematical date = 2020-05-23 notify = jose.divason@unirioja.es abstract = This work presents a formal proof in Isabelle/HOL of an algorithm to transform a matrix into its Smith normal form, a canonical matrix form, in a general setting: the algorithm is parameterized by operations to prove its existence over elementary divisor rings, while execution is guaranteed over Euclidean domains. We also provide a formal proof on some results about the generality of this algorithm as well as the uniqueness of the Smith normal form. Since Isabelle/HOL does not feature dependent types, the development is carried out switching conveniently between two different existing libraries: the Hermite normal form (based on HOL Analysis) and the Jordan normal form AFP entries. This permits to reuse results from both developments and it is done by means of the lifting and transfer package together with the use of local type definitions. [Nash_Williams] title = The Nash-Williams Partition Theorem author = Lawrence C. Paulson topic = Mathematics/Combinatorics date = 2020-05-16 notify = lp15@cam.ac.uk abstract = In 1965, Nash-Williams discovered a generalisation of the infinite form of Ramsey's theorem. Where the latter concerns infinite sets of n-element sets for some fixed n, the Nash-Williams theorem concerns infinite sets of finite sets (or lists) subject to a “no initial segment” condition. The present formalisation follows a monograph on Ramsey Spaces by Todorčević. [Safe_Distance] title = A Formally Verified Checker of the Safe Distance Traffic Rules for Autonomous Vehicles author = Albert Rizaldi , Fabian Immler topic = Computer science/Algorithms/Mathematical, Mathematics/Physics date = 2020-06-01 notify = albert.rizaldi@ntu.edu.sg, fimmler@andrew.cmu.edu, martin.rau@tum.de abstract = The Vienna Convention on Road Traffic defines the safe distance traffic rules informally. This could make autonomous vehicle liable for safe-distance-related accidents because there is no clear definition of how large a safe distance is. We provide a formally proven prescriptive definition of a safe distance, and checkers which can decide whether an autonomous vehicle is obeying the safe distance rule. Not only does our work apply to the domain of law, but it also serves as a specification for autonomous vehicle manufacturers and for online verification of path planners. [Relational_Paths] title = Relational Characterisations of Paths author = Walter Guttmann , Peter Höfner topic = Mathematics/Graph theory date = 2020-07-13 notify = walter.guttmann@canterbury.ac.nz, peter@hoefner-online.de abstract = Binary relations are one of the standard ways to encode, characterise and reason about graphs. Relation algebras provide equational axioms for a large fragment of the calculus of binary relations. Although relations are standard tools in many areas of mathematics and computing, researchers usually fall back to point-wise reasoning when it comes to arguments about paths in a graph. We present a purely algebraic way to specify different kinds of paths in Kleene relation algebras, which are relation algebras equipped with an operation for reflexive transitive closure. We study the relationship between paths with a designated root vertex and paths without such a vertex. Since we stay in first-order logic this development helps with mechanising proofs. To demonstrate the applicability of the algebraic framework we verify the correctness of three basic graph algorithms. [Amicable_Numbers] title = Amicable Numbers author = Angeliki Koutsoukou-Argyraki topic = Mathematics/Number theory date = 2020-08-04 notify = ak2110@cam.ac.uk abstract = This is a formalisation of Amicable Numbers, involving some relevant material including Euler's sigma function, some relevant definitions, results and examples as well as rules such as Thābit ibn Qurra's Rule, Euler's Rule, te Riele's Rule and Borho's Rule with breeders. [Ordinal_Partitions] title = Ordinal Partitions author = Lawrence C. Paulson topic = Mathematics/Combinatorics, Logic/Set theory date = 2020-08-03 notify = lp15@cam.ac.uk abstract = The theory of partition relations concerns generalisations of Ramsey's theorem. For any ordinal $\alpha$, write $\alpha \to (\alpha, m)^2$ if for each function $f$ from unordered pairs of elements of $\alpha$ into $\{0,1\}$, either there is a subset $X\subseteq \alpha$ order-isomorphic to $\alpha$ such that $f\{x,y\}=0$ for all $\{x,y\}\subseteq X$, or there is an $m$ element set $Y\subseteq \alpha$ such that $f\{x,y\}=1$ for all $\{x,y\}\subseteq Y$. (In both cases, with $\{x,y\}$ we require $x\not=y$.) In particular, the infinite Ramsey theorem can be written in this notation as $\omega \to (\omega, \omega)^2$, or if we restrict $m$ to the positive integers as above, then $\omega \to (\omega, m)^2$ for all $m$. This entry formalises Larson's proof of $\omega^\omega \to (\omega^\omega, m)^2$ along with a similar proof of a result due to Specker: $\omega^2 \to (\omega^2, m)^2$. Also proved is a necessary result by Erdős and Milner: $\omega^{1+\alpha\cdot n} \to (\omega^{1+\alpha}, 2^n)^2$. [Relational_Disjoint_Set_Forests] title = Relational Disjoint-Set Forests author = Walter Guttmann topic = Computer science/Data structures date = 2020-08-26 notify = walter.guttmann@canterbury.ac.nz abstract = We give a simple relation-algebraic semantics of read and write operations on associative arrays. The array operations seamlessly integrate with assignments in the Hoare-logic library. Using relation algebras and Kleene algebras we verify the correctness of an array-based implementation of disjoint-set forests with a naive union operation and a find operation with path compression. [PAC_Checker] title = Practical Algebraic Calculus Checker author = Mathias Fleury , Daniela Kaufmann topic = Computer science/Algorithms date = 2020-08-31 notify = mathias.fleury@jku.at abstract = Generating and checking proof certificates is important to increase the trust in automated reasoning tools. In recent years formal verification using computer algebra became more important and is heavily used in automated circuit verification. An existing proof format which covers algebraic reasoning and allows efficient proof checking is the practical algebraic calculus (PAC). In this development, we present the verified checker Pastèque that is obtained by synthesis via the Refinement Framework. This is the formalization going with our FMCAD'20 tool presentation. [BirdKMP] title = Putting the `K' into Bird's derivation of Knuth-Morris-Pratt string matching author = Peter Gammie topic = Computer science/Functional programming date = 2020-08-25 notify = peteg42@gmail.com abstract = Richard Bird and collaborators have proposed a derivation of an intricate cyclic program that implements the Morris-Pratt string matching algorithm. Here we provide a proof of total correctness for Bird's derivation and complete it by adding Knuth's optimisation. [Extended_Finite_State_Machines] title = A Formal Model of Extended Finite State Machines author = Michael Foster , Achim D. Brucker , Ramsay G. Taylor , John Derrick topic = Computer science/Automata and formal languages date = 2020-09-07 notify = jmafoster1@sheffield.ac.uk, adbrucker@0x5f.org abstract = In this AFP entry, we provide a formalisation of extended finite state machines (EFSMs) where models are represented as finite sets of transitions between states. EFSMs execute traces to produce observable outputs. We also define various simulation and equality metrics for EFSMs in terms of traces and prove their strengths in relation to each other. Another key contribution is a framework of function definitions such that LTL properties can be phrased over EFSMs. Finally, we provide a simple example case study in the form of a drinks machine. [Extended_Finite_State_Machine_Inference] title = Inference of Extended Finite State Machines author = Michael Foster , Achim D. Brucker , Ramsay G. Taylor , John Derrick topic = Computer science/Automata and formal languages date = 2020-09-07 notify = jmafoster1@sheffield.ac.uk, adbrucker@0x5f.org abstract = In this AFP entry, we provide a formal implementation of a state-merging technique to infer extended finite state machines (EFSMs), complete with output and update functions, from black-box traces. In particular, we define the subsumption in context relation as a means of determining whether one transition is able to account for the behaviour of another. Building on this, we define the direct subsumption relation, which lifts the subsumption in context relation to EFSM level such that we can use it to determine whether it is safe to merge a given pair of transitions. Key proofs include the conditions necessary for subsumption to occur and that subsumption and direct subsumption are preorder relations. We also provide a number of different heuristics which can be used to abstract away concrete values into registers so that more states and transitions can be merged and provide proofs of the various conditions which must hold for these abstractions to subsume their ungeneralised counterparts. A Code Generator setup to create executable Scala code is also defined. [Physical_Quantities] title = A Sound Type System for Physical Quantities, Units, and Measurements author = Simon Foster , Burkhart Wolff topic = Mathematics/Physics, Computer science/Programming languages/Type systems date = 2020-10-20 notify = simon.foster@york.ac.uk, wolff@lri.fr abstract = The present Isabelle theory builds a formal model for both the International System of Quantities (ISQ) and the International System of Units (SI), which are both fundamental for physics and engineering. Both the ISQ and the SI are deeply integrated into Isabelle's type system. Quantities are parameterised by dimension types, which correspond to base vectors, and thus only quantities of the same dimension can be equated. Since the underlying "algebra of quantities" induces congruences on quantity and SI types, specific tactic support is developed to capture these. Our construction is validated by a test-set of known equivalences between both quantities and SI units. Moreover, the presented theory can be used for type-safe conversions between the SI system and others, like the British Imperial System (BIS). [Shadow_DOM] title = A Formal Model of the Document Object Model with Shadow Roots author = Achim D. Brucker , Michael Herzberg topic = Computer science/Data structures date = 2020-09-28 notify = adbrucker@0x5f.org, mail@michael-herzberg.de abstract = In this AFP entry, we extend our formalization of the core DOM with Shadow Roots. Shadow roots are a recent proposal of the web community to support a component-based development approach for client-side web applications. Shadow roots are a significant extension to the DOM standard and, as web standards are condemned to be backward compatible, such extensions often result in complex specification that may contain unwanted subtleties that can be detected by a formalization. Our Isabelle/HOL formalization is, in the sense of object-orientation, an extension of our formalization of the core DOM and enjoys the same basic properties, i.e., it is extensible, i.e., can be extended without the need of re-proving already proven properties and executable, i.e., we can generate executable code from our specification. We exploit the executability to show that our formalization complies to the official standard of the W3C, respectively, the WHATWG. [DOM_Components] title = A Formalization of Web Components author = Achim D. Brucker , Michael Herzberg topic = Computer science/Data structures date = 2020-09-28 notify = adbrucker@0x5f.org, mail@michael-herzberg.de abstract = While the DOM with shadow trees provide the technical basis for defining web components, the DOM standard neither defines the concept of web components nor specifies the safety properties that web components should guarantee. Consequently, the standard also does not discuss how or even if the methods for modifying the DOM respect component boundaries. In AFP entry, we present a formally verified model of web components and define safety properties which ensure that different web components can only interact with each other using well-defined interfaces. Moreover, our verification of the application programming interface (API) of the DOM revealed numerous invariants that implementations of the DOM API need to preserve to ensure the integrity of components. [Interpreter_Optimizations] title = Inline Caching and Unboxing Optimization for Interpreters author = Martin Desharnais topic = Computer science/Programming languages/Misc date = 2020-12-07 notify = martin.desharnais@unibw.de abstract = This Isabelle/HOL formalization builds on the VeriComp entry of the Archive of Formal Proofs to provide the following contributions:
  • an operational semantics for a realistic virtual machine (Std) for dynamically typed programming languages;
  • the formalization of an inline caching optimization (Inca), a proof of bisimulation with (Std), and a compilation function;
  • the formalization of an unboxing optimization (Ubx), a proof of bisimulation with (Inca), and a simple compilation function.
This formalization was described in the CPP 2021 paper Towards Efficient and Verified Virtual Machines for Dynamic Languages [Isabelle_Marries_Dirac] title = Isabelle Marries Dirac: a Library for Quantum Computation and Quantum Information author = Anthony Bordg , Hanna Lachnitt, Yijun He topic = Computer science/Algorithms/Quantum computing, Mathematics/Physics/Quantum information date = 2020-11-22 notify = apdb3@cam.ac.uk, lachnitt@stanford.edu abstract = This work is an effort to formalise some quantum algorithms and results in quantum information theory. Formal methods being critical for the safety and security of algorithms and protocols, we foresee their widespread use for quantum computing in the future. We have developed a large library for quantum computing in Isabelle based on a matrix representation for quantum circuits, successfully formalising the no-cloning theorem, quantum teleportation, Deutsch's algorithm, the Deutsch-Jozsa algorithm and the quantum Prisoner's Dilemma. [Projective_Measurements] title = Quantum projective measurements and the CHSH inequality author = Mnacho Echenim topic = Computer science/Algorithms/Quantum computing, Mathematics/Physics/Quantum information date = 2021-03-03 notify = mnacho.echenim@univ-grenoble-alpes.fr abstract = This work contains a formalization of quantum projective measurements, also known as von Neumann measurements, which are based on elements of spectral theory. We also formalized the CHSH inequality, an inequality involving expectations in a probability space that is violated by quantum measurements, thus proving that quantum mechanics cannot be modeled with an underlying local hidden-variable theory. [Finite-Map-Extras] title = Finite Map Extras author = Javier Díaz topic = Computer science/Data structures date = 2020-10-12 notify = javier.diaz.manzi@gmail.com abstract = This entry includes useful syntactic sugar, new operators and functions, and their associated lemmas for finite maps which currently are not present in the standard Finite_Map theory. [Relational_Minimum_Spanning_Trees] title = Relational Minimum Spanning Tree Algorithms author = Walter Guttmann , Nicolas Robinson-O'Brien<> topic = Computer science/Algorithms/Graph date = 2020-12-08 notify = walter.guttmann@canterbury.ac.nz abstract = We verify the correctness of Prim's, Kruskal's and Borůvka's minimum spanning tree algorithms based on algebras for aggregation and minimisation. [Topological_Semantics] title = Topological semantics for paraconsistent and paracomplete logics author = David Fuenmayor topic = Logic/General logic date = 2020-12-17 notify = davfuenmayor@gmail.com abstract = We introduce a generalized topological semantics for paraconsistent and paracomplete logics by drawing upon early works on topological Boolean algebras (cf. works by Kuratowski, Zarycki, McKinsey & Tarski, etc.). In particular, this work exemplarily illustrates the shallow semantical embeddings approach (SSE) employing the proof assistant Isabelle/HOL. By means of the SSE technique we can effectively harness theorem provers, model finders and 'hammers' for reasoning with quantified non-classical logics. [CSP_RefTK] title = The HOL-CSP Refinement Toolkit author = Safouan Taha , Burkhart Wolff , Lina Ye topic = Computer science/Concurrency/Process calculi, Computer science/Semantics date = 2020-11-19 notify = wolff@lri.fr abstract = We use a formal development for CSP, called HOL-CSP2.0, to analyse a family of refinement notions, comprising classic and new ones. This analysis enables to derive a number of properties that allow to deepen the understanding of these notions, in particular with respect to specification decomposition principles for the case of infinite sets of events. The established relations between the refinement relations help to clarify some obscure points in the CSP literature, but also provide a weapon for shorter refinement proofs. Furthermore, we provide a framework for state-normalisation allowing to formally reason on parameterised process architectures. As a result, we have a modern environment for formal proofs of concurrent systems that allow for the combination of general infinite processes with locally finite ones in a logically safe way. We demonstrate these verification-techniques for classical, generalised examples: The CopyBuffer for arbitrary data and the Dijkstra's Dining Philosopher Problem of arbitrary size. [Hood_Melville_Queue] title = Hood-Melville Queue author = Alejandro Gómez-Londoño topic = Computer science/Data structures date = 2021-01-18 notify = nipkow@in.tum.de abstract = This is a verified implementation of a constant time queue. The original design is due to Hood and Melville. This formalization follows the presentation in Purely Functional Data Structuresby Okasaki. [JinjaDCI] title = JinjaDCI: a Java semantics with dynamic class initialization author = Susannah Mansky topic = Computer science/Programming languages/Language definitions date = 2021-01-11 notify = sjohnsn2@illinois.edu, susannahej@gmail.com abstract = We extend Jinja to include static fields, methods, and instructions, and dynamic class initialization, based on the Java SE 8 specification. This includes extension of definitions and proofs. This work is partially described in Mansky and Gunter's paper at CPP 2019 and Mansky's doctoral thesis (UIUC, 2020). [Blue_Eyes] title = Solution to the xkcd Blue Eyes puzzle author = Jakub Kądziołka topic = Logic/General logic/Logics of knowledge and belief date = 2021-01-30 notify = kuba@kadziolka.net abstract = In a puzzle published by Randall Munroe, perfect logicians forbidden from communicating are stranded on an island, and may only leave once they have figured out their own eye color. We present a method of modeling the behavior of perfect logicians and formalize a solution of the puzzle. [Laws_of_Large_Numbers] title = The Laws of Large Numbers author = Manuel Eberl topic = Mathematics/Probability theory date = 2021-02-10 notify = eberlm@in.tum.de abstract =

The Law of Large Numbers states that, informally, if one performs a random experiment $X$ many times and takes the average of the results, that average will be very close to the expected value $E[X]$.

More formally, let $(X_i)_{i\in\mathbb{N}}$ be a sequence of independently identically distributed random variables whose expected value $E[X_1]$ exists. Denote the running average of $X_1, \ldots, X_n$ as $\overline{X}_n$. Then:

  • The Weak Law of Large Numbers states that $\overline{X}_{n} \longrightarrow E[X_1]$ in probability for $n\to\infty$, i.e. $\mathcal{P}(|\overline{X}_{n} - E[X_1]| > \varepsilon) \longrightarrow 0$ as $n\to\infty$ for any $\varepsilon > 0$.
  • The Strong Law of Large Numbers states that $\overline{X}_{n} \longrightarrow E[X_1]$ almost surely for $n\to\infty$, i.e. $\mathcal{P}(\overline{X}_{n} \longrightarrow E[X_1]) = 1$.

In this entry, I formally prove the strong law and from it the weak law. The approach used for the proof of the strong law is a particularly quick and slick one based on ergodic theory, which was formalised by Gouëzel in another AFP entry.

[BTree] title = A Verified Imperative Implementation of B-Trees author = Niels Mündler topic = Computer science/Data structures date = 2021-02-24 notify = n.muendler@tum.de abstract = In this work, we use the interactive theorem prover Isabelle/HOL to verify an imperative implementation of the classical B-tree data structure invented by Bayer and McCreight [ACM 1970]. The implementation supports set membership and insertion queries with efficient binary search for intra-node navigation. This is accomplished by first specifying the structure abstractly in the functional modeling language HOL and proving functional correctness. Using manual refinement, we derive an imperative implementation in Imperative/HOL. We show the validity of this refinement using the separation logic utilities from the Isabelle Refinement Framework . The code can be exported to the programming languages SML and Scala. We examine the runtime of all operations indirectly by reproducing results of the logarithmic relationship between height and the number of nodes. The results are discussed in greater detail in the corresponding Bachelor's Thesis. [Sunflowers] title = The Sunflower Lemma of Erdős and Rado author = René Thiemann topic = Mathematics/Combinatorics date = 2021-02-25 notify = rene.thiemann@uibk.ac.at abstract = We formally define sunflowers and provide a formalization of the sunflower lemma of Erdős and Rado: whenever a set of size-k-sets has a larger cardinality than (r - 1)k · k!, then it contains a sunflower of cardinality r. [Mereology] title = Mereology author = Ben Blumson topic = Logic/Philosophical aspects date = 2021-03-01 notify = benblumson@gmail.com abstract = We use Isabelle/HOL to verify elementary theorems and alternative axiomatizations of classical extensional mereology. [Modular_arithmetic_LLL_and_HNF_algorithms] title = Two algorithms based on modular arithmetic: lattice basis reduction and Hermite normal form computation author = Ralph Bottesch <>, Jose Divasón , René Thiemann topic = Computer science/Algorithms/Mathematical date = 2021-03-12 notify = rene.thiemann@uibk.ac.at abstract = We verify two algorithms for which modular arithmetic plays an essential role: Storjohann's variant of the LLL lattice basis reduction algorithm and Kopparty's algorithm for computing the Hermite normal form of a matrix. To do this, we also formalize some facts about the modulo operation with symmetric range. Our implementations are based on the original papers, but are otherwise efficient. For basis reduction we formalize two versions: one that includes all of the optimizations/heuristics from Storjohann's paper, and one excluding a heuristic that we observed to often decrease efficiency. We also provide a fast, self-contained certifier for basis reduction, based on the efficient Hermite normal form algorithm. +[Constructive_Cryptography_CM] +title = Constructive Cryptography in HOL: the Communication Modeling Aspect +author = Andreas Lochbihler , S. Reza Sefidgar <> +topic = Computer science/Security/Cryptography, Mathematics/Probability theory +date = 2021-03-17 +notify = mail@andreas-lochbihler.de, reza.sefidgar@inf.ethz.ch +abstract = + Constructive Cryptography (CC) [ICS + 2011, TOSCA + 2011, TCC + 2016] introduces an abstract approach to composable security + statements that allows one to focus on a particular aspect of security + proofs at a time. Instead of proving the properties of concrete + systems, CC studies system classes, i.e., the shared behavior of + similar systems, and their transformations. Modeling of systems + communication plays a crucial role in composability and reusability of + security statements; yet, this aspect has not been studied in any of + the existing CC results. We extend our previous CC formalization + [Constructive_Cryptography, + CSF + 2019] with a new semantic domain called Fused Resource + Templates (FRT) that abstracts over the systems communication patterns + in CC proofs. This widens the scope of cryptography proof + formalizations in the CryptHOL library [CryptHOL, + ESOP + 2016, J + Cryptol 2020]. This formalization is described in Abstract + Modeling of Systems Communication in Constructive Cryptography using + CryptHOL. + + diff --git a/thys/Constructive_Cryptography_CM/Asymptotic_Security.thy b/thys/Constructive_Cryptography_CM/Asymptotic_Security.thy new file mode 100644 --- /dev/null +++ b/thys/Constructive_Cryptography_CM/Asymptotic_Security.thy @@ -0,0 +1,181 @@ +theory Asymptotic_Security imports Concrete_Security begin + +section \Asymptotic security definition\ + +locale constructive_security_obsf' = + fixes real_resource :: "security \ ('a + 'e, 'b + 'f) resource" + and ideal_resource :: "security \ ('c + 'e, 'd + 'f) resource" + and sim :: "security \ ('a, 'b, 'c, 'd) converter" + and \_real :: "security \ ('a, 'b) \" + and \_ideal :: "security \ ('c, 'd) \" + and \_common :: "security \ ('e, 'f) \" + and \ :: "security \ ('a + 'e, 'b + 'f) distinguisher_obsf" + assumes constructive_security_aux_obsf: "\\. + constructive_security_aux_obsf (real_resource \) (ideal_resource \) (sim \) (\_real \) (\_ideal \) (\_common \) 0" + and adv: "\ \\. exception_\ (\_real \ \\<^sub>\ \_common \) \g \ \ \ \ + \ negligible (\\. advantage (\ \) (obsf_resource (sim \ |\<^sub>= 1\<^sub>C \ ideal_resource \)) (obsf_resource (real_resource \)))" +begin + +sublocale constructive_security_aux_obsf + "real_resource \" + "ideal_resource \" + "sim \" + "\_real \" + "\_ideal \" + "\_common \" + "0" + for \ by(rule constructive_security_aux_obsf) + +lemma constructive_security_obsf'D: + "constructive_security_obsf (real_resource \) (ideal_resource \) (sim \) (\_real \) (\_ideal \) (\_common \) (\ \) + (advantage (\ \) (obsf_resource (sim \ |\<^sub>= 1\<^sub>C \ ideal_resource \)) (obsf_resource (real_resource \)))" + by(rule constructive_security_obsf_refl) + +end + +lemma constructive_security_obsf'I: + assumes "\\. constructive_security_obsf (real_resource \) (ideal_resource \) (sim \) (\_real \) (\_ideal \) (\_common \) (\ \) (adv \)" + and "(\\. exception_\ (\_real \ \\<^sub>\ \_common \) \g \ \ \) \ negligible adv" + shows "constructive_security_obsf' real_resource ideal_resource sim \_real \_ideal \_common \" +proof - + interpret constructive_security_obsf + "real_resource \" + "ideal_resource \" + "sim \" + "\_real \" + "\_ideal \" + "\_common \" + "\ \" + "adv \" + for \ by fact + show ?thesis + proof + show "negligible (\\. advantage (\ \) (obsf_resource (sim \ |\<^sub>= 1\<^sub>C \ ideal_resource \)) (obsf_resource (real_resource \)))" + if "\\. exception_\ (\_real \ \\<^sub>\ \_common \) \g \ \ \" using assms(2)[OF that] + by(rule negligible_mono)(auto intro!: eventuallyI landau_o.big_mono simp add: advantage_nonneg adv_nonneg adv[OF that]) + qed(rule WT_intro pfinite_intro order_refl)+ +qed + +lemma constructive_security_obsf'_into_constructive_security: + assumes "\\ :: security \ ('a + 'b, 'c + 'd) distinguisher_obsf. + \ \\. interaction_bounded_by (\_. True) (\ \) (bound \); + \\. lossless \ plossless_gpv (exception_\ (\_real \ \\<^sub>\ \_common \)) (\ \) \ + \ constructive_security_obsf' real_resource ideal_resource sim \_real \_ideal \_common \" + and correct: "\cnv. \\. (\\. \_ideal \ \\<^sub>\ \_common \ \g \ \ \) \ + (\\. interaction_any_bounded_by (\ \) (bound \)) \ + (\\. lossless \ plossless_gpv (\_ideal \ \\<^sub>\ \_common \) (\ \)) \ + (\\. wiring (\_ideal \) (\_real \) (cnv \) (w \)) \ + Negligible.negligible (\\. advantage (\ \) (ideal_resource \) (cnv \ |\<^sub>= 1\<^sub>C \ real_resource \))" + shows "constructive_security real_resource ideal_resource sim \_real \_ideal \_common bound lossless w" +proof + interpret constructive_security_obsf' real_resource ideal_resource sim \_real \_ideal \_common \\_. Done undefined\ + by(rule assms) simp_all + show "\_real \ \\<^sub>\ \_common \ \res real_resource \ \" + and "\_ideal \ \\<^sub>\ \_common \ \res ideal_resource \ \" + and "\_real \, \_ideal \ \\<^sub>C sim \ \" for \ by(rule WT_intro)+ + + show "\cnv. \\. (\\. \_ideal \ \\<^sub>\ \_common \ \g \ \ \) \ + (\\. interaction_any_bounded_by (\ \) (bound \)) \ + (\\. lossless \ plossless_gpv (\_ideal \ \\<^sub>\ \_common \) (\ \)) \ + (\\. wiring (\_ideal \) (\_real \) (cnv \) (w \)) \ + Negligible.negligible (\\. advantage (\ \) (ideal_resource \) (cnv \ |\<^sub>= 1\<^sub>C \ real_resource \))" + by fact +next + fix \ :: "security \ ('a + 'b, 'c + 'd) distinguisher" + assume WT_adv [WT_intro]: "\\. \_real \ \\<^sub>\ \_common \ \g \ \ \" + and bound [interaction_bound]: "\\. interaction_any_bounded_by (\ \) (bound \)" + and lossless: "\\. lossless \ plossless_gpv (\_real \ \\<^sub>\ \_common \) (\ \)" + let ?\ = "\\. obsf_distinguisher (\ \)" + interpret constructive_security_obsf' real_resource ideal_resource sim \_real \_ideal \_common ?\ + proof(rule assms) + show "interaction_any_bounded_by (?\ \) (bound \)" for \ by(rule interaction_bound)+ + show "plossless_gpv (exception_\ (\_real \ \\<^sub>\ \_common \)) (?\ \)" if lossless for \ + using WT_adv[of \] lossless that by(simp) + qed + have "negligible (\\. advantage (?\ \) (obsf_resource (sim \ |\<^sub>= 1\<^sub>C \ ideal_resource \)) (obsf_resource (real_resource \)))" + by(rule adv)(rule WT_intro)+ + then show "negligible (\\. advantage (\ \) (sim \ |\<^sub>= 1\<^sub>C \ ideal_resource \) (real_resource \))" + unfolding advantage_obsf_distinguisher . +qed + +subsection \Composition theorems\ + +theorem constructive_security_obsf'_composability: + fixes real + assumes "constructive_security_obsf' middle ideal sim_inner \_middle \_inner \_common (\\. absorb (\ \) (obsf_converter (sim_outer \ |\<^sub>= 1\<^sub>C)))" + assumes "constructive_security_obsf' real middle sim_outer \_real \_middle \_common \" + shows "constructive_security_obsf' real ideal (\\. sim_outer \ \ sim_inner \) \_real \_inner \_common \" +proof(rule constructive_security_obsf'I) + let ?\ = "\\. absorb (\ \) (obsf_converter (sim_outer \ |\<^sub>= 1\<^sub>C))" + interpret inner: constructive_security_obsf' middle ideal sim_inner \_middle \_inner \_common ?\ by fact + interpret outer: constructive_security_obsf' real middle sim_outer \_real \_middle \_common \ by fact + + let ?adv1 = "\\. advantage (?\ \) (obsf_resource (sim_inner \ |\<^sub>= 1\<^sub>C \ ideal \)) (obsf_resource (middle \))" + let ?adv2 = "\\. advantage (\ \) (obsf_resource (sim_outer \ |\<^sub>= 1\<^sub>C \ middle \)) (obsf_resource (real \))" + let ?adv = "\\. ?adv1 \ + ?adv2 \" + show "constructive_security_obsf (real \) (ideal \) (sim_outer \ \ sim_inner \) (\_real \) (\_inner \) (\_common \) (\ \) (?adv \)" for \ + using inner.constructive_security_obsf'D outer.constructive_security_obsf'D + by(rule constructive_security_obsf_composability) + assume [WT_intro]: "exception_\ (\_real \ \\<^sub>\ \_common \) \g \ \ \" for \ + have "negligible ?adv1" by(rule inner.adv)(rule WT_intro)+ + also have "negligible ?adv2" by(rule outer.adv)(rule WT_intro)+ + finally (negligible_plus) show "negligible ?adv" . +qed + +theorem constructive_security_obsf'_lifting: (* TODO: generalize! *) + assumes sec: "constructive_security_obsf' real_resource ideal_resource sim \_real \_ideal \_common (\\. absorb (\ \) (obsf_converter (1\<^sub>C |\<^sub>= conv \)))" + assumes WT_conv [WT_intro]: "\\. \_common' \, \_common \ \\<^sub>C conv \ \" + and pfinite [pfinite_intro]: "\\. pfinite_converter (\_common' \) (\_common \) (conv \)" + shows "constructive_security_obsf' + (\\. 1\<^sub>C |\<^sub>= conv \ \ real_resource \) (\\. 1\<^sub>C |\<^sub>= conv \ \ ideal_resource \) sim + \_real \_ideal \_common' \" +proof(rule constructive_security_obsf'I) + let ?\ = "\\. absorb (\ \) (obsf_converter (1\<^sub>C |\<^sub>= conv \))" + interpret constructive_security_obsf' real_resource ideal_resource sim \_real \_ideal \_common ?\ by fact + let ?adv = "\\. advantage (?\ \) (obsf_resource (sim \ |\<^sub>= 1\<^sub>C \ ideal_resource \)) (obsf_resource (real_resource \))" + + fix \ :: security + show "constructive_security_obsf (1\<^sub>C |\<^sub>= conv \ \ real_resource \) (1\<^sub>C |\<^sub>= conv \ \ ideal_resource \) (sim \) + (\_real \) (\_ideal \) (\_common' \) (\ \) + (?adv \)" + using constructive_security_obsf.constructive_security_aux_obsf[OF constructive_security_obsf'D] + constructive_security_obsf.constructive_security_sim_obsf[OF constructive_security_obsf'D] + by(rule constructive_security_obsf_lifting_usr)(rule WT_intro pfinite_intro)+ + show "negligible ?adv" if [WT_intro]: "\\. exception_\ (\_real \ \\<^sub>\ \_common' \) \g \ \ \" + by(rule adv)(rule WT_intro)+ +qed + +theorem constructive_security_obsf'_trivial: + fixes res + assumes [WT_intro]: "\\. \ \ \\<^sub>\ \_common \ \res res \ \" + shows "constructive_security_obsf' res res (\_. 1\<^sub>C) \ \ \_common \" +proof(rule constructive_security_obsf'I) + show "constructive_security_obsf (res \) (res \) 1\<^sub>C (\ \) (\ \) (\_common \) (\ \) 0" for \ + using assms by(rule constructive_security_obsf_trivial) +qed simp + +theorem parallel_constructive_security_obsf': + assumes "constructive_security_obsf' real1 ideal1 sim1 \_real1 \_inner1 \_common1 (\\. absorb (\ \) (obsf_converter (parallel_wiring \ parallel_converter 1\<^sub>C (converter_of_resource (sim2 \ |\<^sub>= 1\<^sub>C \ ideal2 \)))))" + (is "constructive_security_obsf' _ _ _ _ _ _ ?\1") + assumes "constructive_security_obsf' real2 ideal2 sim2 \_real2 \_inner2 \_common2 (\\. absorb (\ \) (obsf_converter (parallel_wiring \ parallel_converter (converter_of_resource (real1 \)) 1\<^sub>C)))" + (is "constructive_security_obsf' _ _ _ _ _ _ ?\2") + shows "constructive_security_obsf' (\\. parallel_wiring \ real1 \ \ real2 \) (\\. parallel_wiring \ ideal1 \ \ ideal2 \) (\\. sim1 \ |\<^sub>= sim2 \) + (\\. \_real1 \ \\<^sub>\ \_real2 \) (\\. \_inner1 \ \\<^sub>\ \_inner2 \) (\\. \_common1 \ \\<^sub>\ \_common2 \) \" +proof(rule constructive_security_obsf'I) + interpret sec1: constructive_security_obsf' real1 ideal1 sim1 \_real1 \_inner1 \_common1 ?\1 by fact + interpret sec2: constructive_security_obsf' real2 ideal2 sim2 \_real2 \_inner2 \_common2 ?\2 by fact + let ?adv1 = "\\. advantage (?\1 \) (obsf_resource (sim1 \ |\<^sub>= 1\<^sub>C \ ideal1 \)) (obsf_resource (real1 \))" + let ?adv2 = "\\. advantage (?\2 \) (obsf_resource (sim2 \ |\<^sub>= 1\<^sub>C \ ideal2 \)) (obsf_resource (real2 \))" + let ?adv = "\\. ?adv1 \ + ?adv2 \" + show "constructive_security_obsf (parallel_wiring \ real1 \ \ real2 \) (parallel_wiring \ ideal1 \ \ ideal2 \) + (sim1 \ |\<^sub>= sim2 \) (\_real1 \ \\<^sub>\ \_real2 \) (\_inner1 \ \\<^sub>\ \_inner2 \) (\_common1 \ \\<^sub>\ \_common2 \) (\ \) + (?adv \)" for \ + using sec1.constructive_security_obsf'D sec2.constructive_security_obsf'D + by(rule parallel_constructive_security_obsf) + assume [WT_intro]: "exception_\ ((\_real1 \ \\<^sub>\ \_real2 \) \\<^sub>\ (\_common1 \ \\<^sub>\ \_common2 \)) \g \ \ \" for \ + have "negligible ?adv1" by(rule sec1.adv)(rule WT_intro)+ + also have "negligible ?adv2" by(rule sec2.adv)(rule WT_intro)+ + finally (negligible_plus) show "negligible ?adv" . +qed + +end \ No newline at end of file diff --git a/thys/Constructive_Cryptography_CM/Concrete_Security.thy b/thys/Constructive_Cryptography_CM/Concrete_Security.thy new file mode 100644 --- /dev/null +++ b/thys/Constructive_Cryptography_CM/Concrete_Security.thy @@ -0,0 +1,482 @@ +theory Concrete_Security +imports + Observe_Failure + Construction_Utility +begin + +section \Concrete security definition\ + +locale constructive_security_aux_obsf = + fixes real_resource :: "('a + 'e, 'b + 'f) resource" + and ideal_resource :: "('c + 'e, 'd + 'f) resource" + and sim :: "('a, 'b, 'c, 'd) converter" + and \_real :: "('a, 'b) \" + and \_ideal :: "('c, 'd) \" + and \_common :: "('e, 'f) \" + and adv :: real + assumes WT_real [WT_intro]: "\_real \\<^sub>\ \_common \res real_resource \" + and WT_ideal [WT_intro]: "\_ideal \\<^sub>\ \_common \res ideal_resource \" + and WT_sim [WT_intro]: "\_real, \_ideal \\<^sub>C sim \" + and pfinite_sim [pfinite_intro]: "pfinite_converter \_real \_ideal sim" + and adv_nonneg: "0 \ adv" + +locale constructive_security_sim_obsf = + fixes real_resource :: "('a + 'e, 'b + 'f) resource" + and ideal_resource :: "('c + 'e, 'd + 'f) resource" + and sim :: "('a, 'b, 'c, 'd) converter" + and \_real :: "('a, 'b) \" + and \_common :: "('e, 'f) \" + and \ :: "('a + 'e, 'b + 'f) distinguisher_obsf" + and adv :: real + assumes adv: "\ exception_\ (\_real \\<^sub>\ \_common) \g \ \ \ + \ advantage \ (obsf_resource (sim |\<^sub>= 1\<^sub>C \ ideal_resource)) (obsf_resource (real_resource)) \ adv" + +locale constructive_security_obsf = constructive_security_aux_obsf real_resource ideal_resource sim \_real \_ideal \_common adv + + constructive_security_sim_obsf real_resource ideal_resource sim \_real \_common \ adv + for real_resource :: "('a + 'e, 'b + 'f) resource" + and ideal_resource :: "('c + 'e, 'd + 'f) resource" + and sim :: "('a, 'b, 'c, 'd) converter" + and \_real :: "('a, 'b) \" + and \_ideal :: "('c, 'd) \" + and \_common :: "('e, 'f) \" + and \ :: "('a + 'e, 'b + 'f) distinguisher_obsf" + and adv :: real +begin + +lemma constructive_security_aux_obsf: "constructive_security_aux_obsf real_resource ideal_resource sim \_real \_ideal \_common adv" .. +lemma constructive_security_sim_obsf: "constructive_security_sim_obsf real_resource ideal_resource sim \_real \_common \ adv" .. + +end + +context constructive_security_aux_obsf begin + +lemma constructive_security_obsf_refl: + "constructive_security_obsf real_resource ideal_resource sim \_real \_ideal \_common \ + (advantage \ (obsf_resource (sim |\<^sub>= 1\<^sub>C \ ideal_resource)) (obsf_resource (real_resource)))" + by unfold_locales(simp_all add: advantage_def WT_intro pfinite_intro) + +end + +lemma constructive_security_obsf_absorb_cong: + assumes sec: "constructive_security_obsf real_resource ideal_resource sim \_real \_ideal \_common (absorb \ cnv) adv" + and [WT_intro]: "exception_\ \, exception_\ (\_real \\<^sub>\ \_common) \\<^sub>C cnv \" "exception_\ \, exception_\ (\_real \\<^sub>\ \_common) \\<^sub>C cnv' \" "exception_\ \ \g \ \" + and cong: "exception_\ \, exception_\ (\_real \\<^sub>\ \_common) \\<^sub>C cnv \ cnv'" + shows "constructive_security_obsf real_resource ideal_resource sim \_real \_ideal \_common (absorb \ cnv') adv" +proof - + interpret constructive_security_obsf real_resource ideal_resource sim \_real \_ideal \_common "absorb \ cnv" adv by fact + show ?thesis + proof + have "connect_obsf \ (cnv' \ obsf_resource (sim |\<^sub>= 1\<^sub>C \ ideal_resource)) = connect_obsf \ (cnv \ obsf_resource (sim |\<^sub>= 1\<^sub>C \ ideal_resource))" + "connect_obsf \ (cnv' \ obsf_resource real_resource) = connect_obsf \ (cnv \ obsf_resource real_resource)" + by(rule connect_eq_resource_cong eq_\_attach_on' WT_intro cong[symmetric] order_refl)+ + then have "advantage (absorb \ cnv') (obsf_resource (sim |\<^sub>= 1\<^sub>C \ ideal_resource)) (obsf_resource real_resource) = + advantage (absorb \ cnv) (obsf_resource (sim |\<^sub>= 1\<^sub>C \ ideal_resource)) (obsf_resource real_resource)" + unfolding advantage_def distinguish_attach[symmetric] by simp + also have "\ \ adv" by(rule adv)(rule WT_intro)+ + finally show "advantage (absorb \ cnv') (obsf_resource (sim |\<^sub>= 1\<^sub>C \ ideal_resource)) (obsf_resource real_resource) \ adv" . + qed +qed + +lemma constructive_security_obsf_sim_cong: + assumes sec: "constructive_security_obsf real_resource ideal_resource sim \_real \_ideal \_common \ adv" + and cong: "\_real, \_ideal \\<^sub>C sim \ sim'" + and pfinite [pfinite_intro]: "pfinite_converter \_real \_ideal sim'" (* This could probably be derived from cong and sec.pfinite_sim *) + shows "constructive_security_obsf real_resource ideal_resource sim' \_real \_ideal \_common \ adv" +proof + interpret constructive_security_obsf real_resource ideal_resource sim \_real \_ideal \_common \ adv by fact + show "\_real \\<^sub>\ \_common \res real_resource \" "\_ideal \\<^sub>\ \_common \res ideal_resource \" by(rule WT_intro)+ + from cong show [WT_intro]: "\_real, \_ideal \\<^sub>C sim' \" by(rule eq_\_converterD_WT1)(rule WT_intro) + show "pfinite_converter \_real \_ideal sim'" by fact + show "0 \ adv" by(rule adv_nonneg) + + assume WT [WT_intro]: "exception_\ (\_real \\<^sub>\ \_common) \g \ \" + have "connect_obsf \ (obsf_resource (sim' |\<^sub>= 1\<^sub>C \ ideal_resource)) = connect_obsf \ (obsf_resource (sim |\<^sub>= 1\<^sub>C \ ideal_resource))" + by(rule connect_eq_resource_cong WT_intro obsf_resource_eq_\_cong eq_\_attach_on' parallel_converter2_eq_\_cong cong[symmetric] eq_\_converter_reflI | simp)+ + with adv[OF WT] + show "advantage \ (obsf_resource (sim' |\<^sub>= 1\<^sub>C \ ideal_resource)) (obsf_resource real_resource) \ adv" + unfolding advantage_def by simp +qed + +lemma constructive_security_obsfI_core_rest [locale_witness]: + assumes "constructive_security_aux_obsf real_resource ideal_resource sim \_real \_ideal (\_common_core \\<^sub>\ \_common_rest) adv" + and adv: "\ exception_\ (\_real \\<^sub>\ (\_common_core \\<^sub>\ \_common_rest)) \g \ \ \ + \ advantage \ (obsf_resource (sim |\<^sub>= (1\<^sub>C |\<^sub>= 1\<^sub>C) \ ideal_resource)) (obsf_resource (real_resource)) \ adv" + shows "constructive_security_obsf real_resource ideal_resource sim \_real \_ideal (\_common_core \\<^sub>\ \_common_rest) \ adv" +proof - + interpret constructive_security_aux_obsf real_resource ideal_resource sim \_real \_ideal "\_common_core \\<^sub>\ \_common_rest" by fact + show ?thesis + proof + assume A [WT_intro]: "exception_\ (\_real \\<^sub>\ (\_common_core \\<^sub>\ \_common_rest)) \g \ \" + hence outs: "outs_gpv (exception_\ (\_real \\<^sub>\ (\_common_core \\<^sub>\ \_common_rest))) \ \ outs_\ (\_real \\<^sub>\ (\_common_core \\<^sub>\ \_common_rest))" + unfolding WT_gpv_iff_outs_gpv by simp + have "connect_obsf \ (obsf_resource (sim |\<^sub>= 1\<^sub>C \ ideal_resource)) = connect_obsf \ (obsf_resource (sim |\<^sub>= 1\<^sub>C |\<^sub>= 1\<^sub>C \ ideal_resource))" + by(rule connect_cong_trace trace_eq_obsf_resourceI eq_resource_on_imp_trace_eq eq_\_attach_on')+ + (rule WT_intro parallel_converter2_eq_\_cong eq_\_converter_reflI parallel_converter2_id_id[symmetric] order_refl outs)+ + then show "advantage \ (obsf_resource (sim |\<^sub>= 1\<^sub>C \ ideal_resource)) (obsf_resource real_resource) \ adv" + using adv[OF A] by(simp add: advantage_def) + qed +qed + +subsection \Composition theorems\ + +theorem constructive_security_obsf_composability: + fixes real + assumes "constructive_security_obsf middle ideal sim_inner \_middle \_inner \_common (absorb \ (obsf_converter (sim_outer |\<^sub>= 1\<^sub>C))) adv1" + assumes "constructive_security_obsf real middle sim_outer \_real \_middle \_common \ adv2" + shows "constructive_security_obsf real ideal (sim_outer \ sim_inner) \_real \_inner \_common \ (adv1 + adv2)" +proof + let ?\ = "absorb \ (obsf_converter (sim_outer |\<^sub>= 1\<^sub>C))" + interpret inner: constructive_security_obsf middle ideal sim_inner \_middle \_inner \_common ?\ adv1 by fact + interpret outer: constructive_security_obsf real middle sim_outer \_real \_middle \_common \ adv2 by fact + + show "\_real \\<^sub>\ \_common \res real \" + and "\_inner \\<^sub>\ \_common \res ideal \" + and "\_real, \_inner \\<^sub>C sim_outer \ sim_inner \" by(rule WT_intro)+ + show "pfinite_converter \_real \_inner (sim_outer \ sim_inner)" by(rule pfinite_intro WT_intro)+ + show "0 \ adv1 + adv2" using inner.adv_nonneg outer.adv_nonneg by simp + + assume WT_adv[WT_intro]: "exception_\ (\_real \\<^sub>\ \_common) \g \ \" + have eq1: "connect_obsf (absorb \ (obsf_converter (sim_outer |\<^sub>= 1\<^sub>C))) (obsf_resource (sim_inner |\<^sub>= 1\<^sub>C \ ideal)) = + connect_obsf \ (obsf_resource (sim_outer \ sim_inner |\<^sub>= 1\<^sub>C \ ideal))" + unfolding distinguish_attach[symmetric] + apply(rule connect_eq_resource_cong) + apply(rule WT_intro) + apply(simp del: outs_plus_\ add: parallel_converter2_comp1_out attach_compose) + apply(rule obsf_attach) + apply(rule pfinite_intro WT_intro)+ + done + have eq2: "connect_obsf (absorb \ (obsf_converter (sim_outer |\<^sub>= 1\<^sub>C))) (obsf_resource middle) = + connect_obsf \ (obsf_resource (sim_outer |\<^sub>= 1\<^sub>C \ middle))" + unfolding distinguish_attach[symmetric] + apply(rule connect_eq_resource_cong) + apply(rule WT_intro) + apply(simp del: outs_plus_\ add: parallel_converter2_comp1_out attach_compose) + apply(rule obsf_attach) + apply(rule pfinite_intro WT_intro)+ + done + + have "advantage ?\ (obsf_resource (sim_inner |\<^sub>= 1\<^sub>C \ ideal)) (obsf_resource middle) \ adv1" + by(rule inner.adv)(rule WT_intro)+ + moreover have "advantage \ (obsf_resource (sim_outer |\<^sub>= 1\<^sub>C \ middle)) (obsf_resource real) \ adv2" + by(rule outer.adv)(rule WT_intro)+ + ultimately + show "advantage \ (obsf_resource (sim_outer \ sim_inner |\<^sub>= 1\<^sub>C \ ideal)) (obsf_resource real) \ adv1 + adv2" + by(auto simp add: advantage_def eq1 eq2 abs_diff_triangle_ineq2) +qed + +theorem constructive_security_obsf_lifting: + assumes sec: "constructive_security_aux_obsf real_resource ideal_resource sim \_real \_ideal \_common adv" + and sec2: "exception_\ (\_real' \\<^sub>\ \_common') \g \ \ + \ constructive_security_sim_obsf real_resource ideal_resource sim \_real \_common (absorb \ (obsf_converter (w_adv_real |\<^sub>= w_usr))) adv" + (is "_ \ constructive_security_sim_obsf _ _ _ _ _ ?\ _") + assumes WT_usr [WT_intro]: "\_common', \_common \\<^sub>C w_usr \" + and pfinite [pfinite_intro]: "pfinite_converter \_common' \_common w_usr" + and WT_adv_real [WT_intro]: "\_real', \_real \\<^sub>C w_adv_real \" + and WT_w_adv_ideal [WT_intro]: "\_ideal', \_ideal \\<^sub>C w_adv_ideal \" + and WT_adv_ideal_inv [WT_intro]: "\_ideal, \_ideal' \\<^sub>C w_adv_ideal_inv \" + and ideal_inverse: "\_ideal, \_ideal \\<^sub>C w_adv_ideal_inv \ w_adv_ideal \ 1\<^sub>C" + and pfinite_real [pfinite_intro]: "pfinite_converter \_real' \_real w_adv_real" + and pfinite_ideal [pfinite_intro]: "pfinite_converter \_ideal \_ideal' w_adv_ideal_inv" + shows "constructive_security_obsf (w_adv_real |\<^sub>= w_usr \ real_resource) (w_adv_ideal |\<^sub>= w_usr \ ideal_resource) (w_adv_real \ sim \ w_adv_ideal_inv) \_real' \_ideal' \_common' \ adv" + (is "constructive_security_obsf ?real ?ideal ?sim ?\_real ?\_ideal _ _ _") +proof + interpret constructive_security_aux_obsf real_resource ideal_resource sim \_real \_ideal \_common by fact + show "\_real' \\<^sub>\ \_common' \res ?real \" + and "\_ideal' \\<^sub>\ \_common' \res ?ideal \" + and "\_real', \_ideal' \\<^sub>C ?sim \" by(rule WT_intro)+ + show "pfinite_converter \_real' \_ideal' ?sim" by(rule pfinite_intro WT_intro)+ + show "0 \ adv" by(rule adv_nonneg) + + assume WT_adv [WT_intro]: "exception_\ (\_real' \\<^sub>\ \_common') \g \ \" + then interpret constructive_security_sim_obsf real_resource ideal_resource sim \_real \_common ?\ adv by(rule sec2) + + have *: "advantage ?\ (obsf_resource (sim |\<^sub>= 1\<^sub>C \ ideal_resource)) (obsf_resource real_resource) \ adv" + by(rule adv)(rule WT_intro)+ + + have ideal: "connect_obsf ?\ (obsf_resource (sim |\<^sub>= 1\<^sub>C \ ideal_resource)) = + connect_obsf \ (obsf_resource (?sim |\<^sub>= 1\<^sub>C \ ?ideal))" + unfolding distinguish_attach[symmetric] + apply(rule connect_eq_resource_cong) + apply(rule WT_intro) + apply(simp del: outs_plus_\) + apply(rule eq_resource_on_trans[OF obsf_attach]) + apply(rule pfinite_intro WT_intro)+ + apply(rule obsf_resource_eq_\_cong) + apply(fold attach_compose) + apply(unfold comp_converter_parallel2) + apply(rule eq_\_attach_on') + apply(rule WT_intro) + apply(rule parallel_converter2_eq_\_cong) + apply(unfold comp_converter_assoc) + apply(rule eq_\_comp_cong) + apply(rule eq_\_converter_reflI; rule WT_intro) + apply(rule eq_\_converter_trans[rotated]) + apply(rule eq_\_comp_cong) + apply(rule eq_\_converter_reflI; rule WT_intro) + apply(rule ideal_inverse[symmetric]) + apply(unfold comp_converter_id_right comp_converter_id_left) + apply(rule eq_\_converter_reflI; rule WT_intro)+ + apply simp + apply(rule WT_intro)+ + done + have real: "connect_obsf ?\ (obsf_resource real_resource) = connect_obsf \ (obsf_resource ?real)" + unfolding distinguish_attach[symmetric] + apply(rule connect_eq_resource_cong) + apply(rule WT_intro) + apply(simp del: outs_plus_\) + apply(rule obsf_attach) + apply(rule pfinite_intro WT_intro)+ + done + show "advantage \ (obsf_resource ((?sim |\<^sub>= 1\<^sub>C) \ ?ideal)) (obsf_resource ?real) \ adv" using * + unfolding advantage_def ideal[symmetric] real[symmetric] . +qed + +corollary constructive_security_obsf_lifting_: + assumes sec: "constructive_security_obsf real_resource ideal_resource sim \_real \_ideal \_common (absorb \ (obsf_converter (w_adv_real |\<^sub>= w_usr))) adv" + assumes WT_usr [WT_intro]: "\_common', \_common \\<^sub>C w_usr \" + and pfinite [pfinite_intro]: "pfinite_converter \_common' \_common w_usr" + and WT_adv_real [WT_intro]: "\_real', \_real \\<^sub>C w_adv_real \" + and WT_w_adv_ideal [WT_intro]: "\_ideal', \_ideal \\<^sub>C w_adv_ideal \" + and WT_adv_ideal_inv [WT_intro]: "\_ideal, \_ideal' \\<^sub>C w_adv_ideal_inv \" + and ideal_inverse: "\_ideal, \_ideal \\<^sub>C w_adv_ideal_inv \ w_adv_ideal \ 1\<^sub>C" + and pfinite_real [pfinite_intro]: "pfinite_converter \_real' \_real w_adv_real" + and pfinite_ideal [pfinite_intro]: "pfinite_converter \_ideal \_ideal' w_adv_ideal_inv" + shows "constructive_security_obsf (w_adv_real |\<^sub>= w_usr \ real_resource) (w_adv_ideal |\<^sub>= w_usr \ ideal_resource) (w_adv_real \ sim \ w_adv_ideal_inv) \_real' \_ideal' \_common' \ adv" +proof - + interpret constructive_security_obsf real_resource ideal_resource sim \_real \_ideal \_common "absorb \ (obsf_converter (w_adv_real |\<^sub>= w_usr))" adv by fact + from constructive_security_aux_obsf constructive_security_sim_obsf assms(2-) + show ?thesis by(rule constructive_security_obsf_lifting) +qed + +theorem constructive_security_obsf_lifting_usr: + assumes sec: "constructive_security_aux_obsf real_resource ideal_resource sim \_real \_ideal \_common adv" + and sec2: "exception_\ (\_real \\<^sub>\ \_common') \g \ \ + \ constructive_security_sim_obsf real_resource ideal_resource sim \_real \_common (absorb \ (obsf_converter (1\<^sub>C |\<^sub>= conv))) adv" + and WT_conv [WT_intro]: "\_common', \_common \\<^sub>C conv \" + and pfinite [pfinite_intro]: "pfinite_converter \_common' \_common conv" + shows "constructive_security_obsf (1\<^sub>C |\<^sub>= conv \ real_resource) (1\<^sub>C |\<^sub>= conv \ ideal_resource) sim \_real \_ideal \_common' \ adv" + by(rule constructive_security_obsf_lifting[OF sec sec2, where ?w_adv_ideal="1\<^sub>C" and ?w_adv_ideal_inv="1\<^sub>C", simplified comp_converter_id_left comp_converter_id_right]) + (rule WT_intro pfinite_intro id_converter_eq_self order_refl | assumption)+ + +theorem constructive_security_obsf_lifting2: + assumes sec: "constructive_security_aux_obsf real_resource ideal_resource sim (\_real1 \\<^sub>\ \_real2) (\_ideal1 \\<^sub>\ \_ideal2) \_common adv" + and sec2: "exception_\ ((\_real1 \\<^sub>\ \_real2) \\<^sub>\ \_common') \g \ \ + \ constructive_security_sim_obsf real_resource ideal_resource sim (\_real1 \\<^sub>\ \_real2) \_common (absorb \ (obsf_converter ((1\<^sub>C |\<^sub>= 1\<^sub>C) |\<^sub>= conv))) adv" + assumes WT_conv [WT_intro]: "\_common', \_common \\<^sub>C conv \" + and pfinite [pfinite_intro]: "pfinite_converter \_common' \_common conv" + shows "constructive_security_obsf ((1\<^sub>C |\<^sub>= 1\<^sub>C) |\<^sub>= conv \ real_resource) ((1\<^sub>C |\<^sub>= 1\<^sub>C) |\<^sub>= conv \ ideal_resource) sim (\_real1 \\<^sub>\ \_real2) (\_ideal1 \\<^sub>\ \_ideal2) \_common' \ adv" + (is "constructive_security_obsf ?real ?ideal _ ?\_real ?\_ideal _ _ _") +proof - + interpret constructive_security_aux_obsf real_resource ideal_resource sim "\_real1 \\<^sub>\ \_real2" "\_ideal1 \\<^sub>\ \_ideal2" \_common adv by fact + have sim [unfolded comp_converter_id_left]: "\_real1 \\<^sub>\ \_real2,\_ideal1 \\<^sub>\ \_ideal2 \\<^sub>C (1\<^sub>C |\<^sub>= 1\<^sub>C) \ sim \ 1\<^sub>C \ sim" + by(rule eq_\_comp_cong)(rule parallel_converter2_id_id eq_\_converter_reflI WT_intro)+ + show ?thesis + apply(rule constructive_security_obsf_sim_cong) + apply(rule constructive_security_obsf_lifting[OF sec sec2, where ?w_adv_ideal="1\<^sub>C |\<^sub>= 1\<^sub>C" and ?w_adv_ideal_inv="1\<^sub>C", unfolded comp_converter_id_left comp_converter_id_right]) + apply(assumption|rule WT_intro sim pfinite_intro parallel_converter2_id_id)+ + done +qed + +theorem constructive_security_obsf_trivial: + fixes res + assumes [WT_intro]: "\ \\<^sub>\ \_common \res res \" + shows "constructive_security_obsf res res 1\<^sub>C \ \ \_common \ 0" +proof + show "\ \\<^sub>\ \_common \res res \" and "\, \ \\<^sub>C 1\<^sub>C \" by(rule WT_intro)+ + show "pfinite_converter \ \ 1\<^sub>C" by(rule pfinite_intro) + + assume WT [WT_intro]: "exception_\ (\ \\<^sub>\ \_common) \g \ \" + have "connect_obsf \ (obsf_resource (1\<^sub>C |\<^sub>= 1\<^sub>C \ res)) = connect_obsf \ (obsf_resource (1\<^sub>C \ res))" + by(rule connect_eq_resource_cong[OF WT])(fastforce intro: WT_intro eq_\_attach_on' obsf_resource_eq_\_cong parallel_converter2_id_id)+ + then show "advantage \ (obsf_resource (1\<^sub>C |\<^sub>= 1\<^sub>C \ res)) (obsf_resource res) \ 0" + unfolding advantage_def by simp +qed simp + +lemma parallel_constructive_security_aux_obsf [locale_witness]: + assumes "constructive_security_aux_obsf real1 ideal1 sim1 \_real1 \_inner1 \_common1 adv1" + assumes "constructive_security_aux_obsf real2 ideal2 sim2 \_real2 \_inner2 \_common2 adv2" + shows "constructive_security_aux_obsf (parallel_wiring \ real1 \ real2) (parallel_wiring \ ideal1 \ ideal2) (sim1 |\<^sub>= sim2) + (\_real1 \\<^sub>\ \_real2) (\_inner1 \\<^sub>\ \_inner2) (\_common1 \\<^sub>\ \_common2) + (adv1 + adv2)" +proof + interpret sec1: constructive_security_aux_obsf real1 ideal1 sim1 \_real1 \_inner1 \_common1 adv1 by fact + interpret sec2: constructive_security_aux_obsf real2 ideal2 sim2 \_real2 \_inner2 \_common2 adv2 by fact + + show "(\_real1 \\<^sub>\ \_real2) \\<^sub>\ (\_common1 \\<^sub>\ \_common2) \res parallel_wiring \ real1 \ real2 \" + and "(\_inner1 \\<^sub>\ \_inner2) \\<^sub>\ (\_common1 \\<^sub>\ \_common2) \res parallel_wiring \ ideal1 \ ideal2 \" + and "\_real1 \\<^sub>\ \_real2, \_inner1 \\<^sub>\ \_inner2 \\<^sub>C sim1 |\<^sub>= sim2 \" by(rule WT_intro)+ + show "pfinite_converter (\_real1 \\<^sub>\ \_real2) (\_inner1 \\<^sub>\ \_inner2) (sim1 |\<^sub>= sim2)" by(rule pfinite_intro)+ + show "0 \ adv1 + adv2" using sec1.adv_nonneg sec2.adv_nonneg by simp +qed + +theorem parallel_constructive_security_obsf: + assumes "constructive_security_obsf real1 ideal1 sim1 \_real1 \_inner1 \_common1 (absorb \ (obsf_converter (parallel_wiring \ parallel_converter 1\<^sub>C (converter_of_resource (sim2 |\<^sub>= 1\<^sub>C \ ideal2))))) adv1" + (is "constructive_security_obsf _ _ _ _ _ _ ?\1 _") + assumes "constructive_security_obsf real2 ideal2 sim2 \_real2 \_inner2 \_common2 (absorb \ (obsf_converter (parallel_wiring \ parallel_converter (converter_of_resource real1) 1\<^sub>C))) adv2" + (is "constructive_security_obsf _ _ _ _ _ _ ?\2 _") + shows "constructive_security_obsf (parallel_wiring \ real1 \ real2) (parallel_wiring \ ideal1 \ ideal2) (sim1 |\<^sub>= sim2) + (\_real1 \\<^sub>\ \_real2) (\_inner1 \\<^sub>\ \_inner2) (\_common1 \\<^sub>\ \_common2) + \ (adv1 + adv2)" +proof - + interpret sec1: constructive_security_obsf real1 ideal1 sim1 \_real1 \_inner1 \_common1 ?\1 adv1 by fact + interpret sec2: constructive_security_obsf real2 ideal2 sim2 \_real2 \_inner2 \_common2 ?\2 adv2 by fact + + show ?thesis + proof + assume WT [WT_intro]: "exception_\ ((\_real1 \\<^sub>\ \_real2) \\<^sub>\ (\_common1 \\<^sub>\ \_common2)) \g \ \" + + have **: "outs_\ ((\_real1 \\<^sub>\ \_real2) \\<^sub>\ (\_common1 \\<^sub>\ \_common2)) \\<^sub>R + ((1\<^sub>C |\<^sub>= sim2) |\<^sub>= 1\<^sub>C |\<^sub>= 1\<^sub>C) \ parallel_wiring \ real1 \ ideal2 \ + parallel_wiring \ (converter_of_resource real1 |\<^sub>\ 1\<^sub>C) \ sim2 |\<^sub>= 1\<^sub>C \ ideal2" + unfolding comp_parallel_wiring + by(rule eq_resource_on_trans, rule eq_\_attach_on[where conv'="parallel_wiring \ (1\<^sub>C |\<^sub>= sim2 |\<^sub>= 1\<^sub>C)"] + , (rule WT_intro)+, rule eq_\_comp_cong, rule eq_\_converter_mono) + (auto simp add: le_\_def attach_compose attach_parallel2 attach_converter_of_resource_conv_parallel_resource + intro: WT_intro parallel_converter2_eq_\_cong parallel_converter2_id_id eq_\_converter_reflI) + + have ideal2: + "connect_obsf ?\2 (obsf_resource (sim2 |\<^sub>= 1\<^sub>C \ ideal2)) = + connect_obsf \ (obsf_resource ((1\<^sub>C |\<^sub>= sim2) |\<^sub>= (1\<^sub>C |\<^sub>= 1\<^sub>C) \ parallel_wiring \ real1 \ ideal2))" + unfolding distinguish_attach[symmetric] + apply(rule connect_eq_resource_cong) + apply(rule WT_intro) + apply(simp del: outs_plus_\) + apply(rule eq_resource_on_trans[OF obsf_attach]) + apply(rule pfinite_intro WT_intro)+ + apply(rule obsf_resource_eq_\_cong) + apply(rule eq_resource_on_sym) + apply(subst attach_compose[symmetric]) + apply(rule **) + apply(rule WT_intro)+ + done + + have real2: "connect_obsf ?\2 (obsf_resource real2) = connect_obsf \ (obsf_resource (parallel_wiring \ real1 \ real2))" + unfolding distinguish_attach[symmetric] + apply(rule connect_eq_resource_cong) + apply(rule WT_intro) + apply(simp del: outs_plus_\) + apply(rule eq_resource_on_trans[OF obsf_attach]) + apply(rule pfinite_intro WT_intro)+ + apply(rule obsf_resource_eq_\_cong) + apply(rule eq_resource_on_sym) + by(simp add: attach_compose attach_converter_of_resource_conv_parallel_resource)(rule WT_intro)+ + + have adv2: "advantage \ + (obsf_resource ((1\<^sub>C |\<^sub>= sim2) |\<^sub>= (1\<^sub>C |\<^sub>= 1\<^sub>C) \ parallel_wiring \ real1 \ ideal2)) + (obsf_resource (parallel_wiring \ real1 \ real2)) \ adv2" + unfolding advantage_def ideal2[symmetric] real2[symmetric] by(rule sec2.adv[unfolded advantage_def])(rule WT_intro)+ + + have ideal1: + "connect_obsf ?\1 (obsf_resource (sim1 |\<^sub>= 1\<^sub>C \ ideal1)) = + connect_obsf \ (obsf_resource ((sim1 |\<^sub>= sim2) |\<^sub>= (1\<^sub>C |\<^sub>= 1\<^sub>C) \ parallel_wiring \ ideal1 \ ideal2))" + proof - + have *:"((outs_\ \_real1 <+> outs_\ \_real2) <+> outs_\ \_common1 <+> outs_\ \_common2) \\<^sub>R + (sim1 |\<^sub>= sim2) |\<^sub>= (1\<^sub>C |\<^sub>= 1\<^sub>C) \ parallel_wiring \ ideal1 \ ideal2 \ + parallel_wiring \ (1\<^sub>C |\<^sub>\ converter_of_resource (sim2 |\<^sub>= 1\<^sub>C \ ideal2)) \ sim1 |\<^sub>= 1\<^sub>C \ ideal1" + by(auto simp add: le_\_def comp_parallel_wiring' attach_compose attach_parallel2 attach_converter_of_resource_conv_parallel_resource2 intro: WT_intro) + show ?thesis + unfolding distinguish_attach[symmetric] + apply(rule connect_eq_resource_cong) + apply(rule WT_intro) + apply(simp del: outs_plus_\) + apply(rule eq_resource_on_trans[OF obsf_attach]) + apply(rule pfinite_intro WT_intro)+ + apply(rule obsf_resource_eq_\_cong) + apply(rule eq_resource_on_sym) + by(simp add: *, (rule WT_intro)+) + qed + + have real1: "connect_obsf ?\1 (obsf_resource real1) = connect_obsf \ (obsf_resource ((1\<^sub>C |\<^sub>= sim2) |\<^sub>= (1\<^sub>C |\<^sub>= 1\<^sub>C) \ parallel_wiring \ real1 \ ideal2))" + proof - + have *: "outs_\ ((\_real1 \\<^sub>\ \_real2) \\<^sub>\ (\_common1 \\<^sub>\ \_common2)) \\<^sub>R + parallel_wiring \ ((1\<^sub>C |\<^sub>= 1\<^sub>C) |\<^sub>= sim2 |\<^sub>= 1\<^sub>C) \ real1 \ ideal2 \ + parallel_wiring \ (1\<^sub>C |\<^sub>\ converter_of_resource (sim2 |\<^sub>= 1\<^sub>C \ ideal2 )) \ real1" + by(rule eq_resource_on_trans, rule eq_\_attach_on[where conv'="parallel_wiring \ (1\<^sub>C |\<^sub>= sim2 |\<^sub>= 1\<^sub>C)"] + , (rule WT_intro)+, rule eq_\_comp_cong, rule eq_\_converter_mono) + (auto simp add: le_\_def attach_compose attach_converter_of_resource_conv_parallel_resource2 attach_parallel2 + intro: WT_intro parallel_converter2_eq_\_cong parallel_converter2_id_id eq_\_converter_reflI) + + show ?thesis + unfolding distinguish_attach[symmetric] + apply(rule connect_eq_resource_cong) + apply(rule WT_intro) + apply(simp del: outs_plus_\) + apply(rule eq_resource_on_trans[OF obsf_attach]) + apply(rule pfinite_intro WT_intro)+ + apply(rule obsf_resource_eq_\_cong) + apply(rule eq_resource_on_sym) + apply(fold attach_compose) + apply(subst comp_parallel_wiring) + apply(rule *) + apply(rule WT_intro)+ + done + qed + + have adv1: "advantage \ + (obsf_resource ((sim1 |\<^sub>= sim2) |\<^sub>= (1\<^sub>C |\<^sub>= 1\<^sub>C) \ parallel_wiring \ ideal1 \ ideal2)) + (obsf_resource ((1\<^sub>C |\<^sub>= sim2) |\<^sub>= (1\<^sub>C |\<^sub>= 1\<^sub>C) \ parallel_wiring \ real1 \ ideal2)) \ adv1" + unfolding advantage_def ideal1[symmetric] real1[symmetric] by(rule sec1.adv[unfolded advantage_def])(rule WT_intro)+ + + from adv1 adv2 show "advantage \ (obsf_resource ((sim1 |\<^sub>= sim2) |\<^sub>= (1\<^sub>C |\<^sub>= 1\<^sub>C) \ parallel_wiring \ ideal1 \ ideal2)) + (obsf_resource (parallel_wiring \ real1 \ real2)) \ adv1 + adv2" + by(auto simp add: advantage_def) + qed +qed + +theorem parallel_constructive_security_obsf_fuse: + assumes 1: "constructive_security_obsf real1 ideal1 sim1 (\_real1_core \\<^sub>\ \_real1_rest) (\_ideal1_core \\<^sub>\ \_ideal1_rest) (\_common1_core \\<^sub>\ \_common1_rest) (absorb \ (obsf_converter (fused_wiring \ parallel_converter 1\<^sub>C (converter_of_resource (sim2 |\<^sub>= 1\<^sub>C \ ideal2))))) adv1" + (is "constructive_security_obsf _ _ _ ?\_real1 ?\_ideal1 ?\_common1 ?\1 _") + assumes 2: "constructive_security_obsf real2 ideal2 sim2 (\_real2_core \\<^sub>\ \_real2_rest) (\_ideal2_core \\<^sub>\ \_ideal2_rest) (\_common2_core \\<^sub>\ \_common2_rest) (absorb \ (obsf_converter (fused_wiring \ parallel_converter (converter_of_resource real1) 1\<^sub>C))) adv2" + (is "constructive_security_obsf _ _ _ ?\_real2 ?\_ideal2 ?\_common2 ?\2 _") + shows "constructive_security_obsf (fused_wiring \ real1 \ real2) (fused_wiring \ ideal1 \ ideal2) + (parallel_wiring \ (sim1 |\<^sub>= sim2) \ parallel_wiring) + ((\_real1_core \\<^sub>\ \_real2_core) \\<^sub>\ (\_real1_rest \\<^sub>\ \_real2_rest)) + ((\_ideal1_core \\<^sub>\ \_ideal2_core) \\<^sub>\ (\_ideal1_rest \\<^sub>\ \_ideal2_rest)) + ((\_common1_core \\<^sub>\ \_common2_core) \\<^sub>\ (\_common1_rest \\<^sub>\ \_common2_rest)) + \ (adv1 + adv2)" +proof - + interpret sec1: constructive_security_obsf real1 ideal1 sim1 ?\_real1 ?\_ideal1 ?\_common1 ?\1 adv1 by fact + interpret sec2: constructive_security_obsf real2 ideal2 sim2 ?\_real2 ?\_ideal2 ?\_common2 ?\2 adv2 by fact + + have aux1: "constructive_security_aux_obsf real1 ideal1 sim1 ?\_real1 ?\_ideal1 ?\_common1 adv1" .. + have aux2: "constructive_security_aux_obsf real2 ideal2 sim2 ?\_real2 ?\_ideal2 ?\_common2 adv2" .. + + have sim: "constructive_security_sim_obsf (parallel_wiring \ real1 \ real2) (parallel_wiring \ ideal1 \ ideal2) (sim1 |\<^sub>= sim2) + (?\_real1 \\<^sub>\ ?\_real2) (?\_common1 \\<^sub>\ ?\_common2) + (absorb \ (obsf_converter (parallel_wiring |\<^sub>= parallel_wiring))) + (adv1 + adv2)" + if [WT_intro]: "exception_\ (((\_real1_core \\<^sub>\ \_real2_core) \\<^sub>\ (\_real1_rest \\<^sub>\ \_real2_rest)) \\<^sub>\ ((\_common1_core \\<^sub>\ \_common2_core) \\<^sub>\ (\_common1_rest \\<^sub>\ \_common2_rest))) \g \ \" + proof - + interpret constructive_security_obsf + "parallel_wiring \ real1 \ real2" + "parallel_wiring \ ideal1 \ ideal2" + "sim1 |\<^sub>= sim2" + "?\_real1 \\<^sub>\ ?\_real2" "?\_ideal1 \\<^sub>\ ?\_ideal2" "?\_common1 \\<^sub>\ ?\_common2" + "absorb \ (obsf_converter (parallel_wiring |\<^sub>= parallel_wiring))" + "adv1 + adv2" + apply(rule parallel_constructive_security_obsf) + apply(fold absorb_comp_converter) + apply(rule constructive_security_obsf_absorb_cong[OF 1]) + apply(rule WT_intro)+ + apply(unfold fused_wiring_def comp_converter_assoc) + apply(rule obsf_comp_converter) + apply(rule WT_intro pfinite_intro)+ + apply(rule constructive_security_obsf_absorb_cong[OF 2]) + apply(rule WT_intro)+ + apply(subst fused_wiring_def) + apply(unfold comp_converter_assoc) + apply(rule obsf_comp_converter) + apply(rule WT_intro pfinite_intro wiring_intro parallel_wiring_inverse)+ + done + show ?thesis .. + qed + show ?thesis + unfolding fused_wiring_def attach_compose + apply(rule constructive_security_obsf_lifting[where w_adv_ideal_inv=parallel_wiring]) + apply(rule parallel_constructive_security_aux_obsf[OF aux1 aux2]) + apply(erule sim) + apply(rule WT_intro pfinite_intro parallel_wiring_inverse)+ + done +qed + +end \ No newline at end of file diff --git a/thys/Constructive_Cryptography_CM/Construction_Utility.thy b/thys/Constructive_Cryptography_CM/Construction_Utility.thy new file mode 100644 --- /dev/null +++ b/thys/Constructive_Cryptography_CM/Construction_Utility.thy @@ -0,0 +1,452 @@ +theory Construction_Utility + imports + Fused_Resource + State_Isomorphism +begin + +\ \Dummy converters that return a constant value on their external interface\ + +primcorec + ldummy_converter :: "('a \ 'b) \ ('i_cnv, 'o_cnv, 'i_res, 'o_res) converter \ + ('a + 'i_cnv, 'b + 'o_cnv, 'i_res, 'o_res) converter" + where + "run_converter (ldummy_converter f conv) = (\inp. case inp of + Inl x \ map_gpv (map_prod Inl (\_. ldummy_converter f conv)) id (Done (f x, ())) + | Inr x \ map_gpv (map_prod Inr (\c. ldummy_converter f c)) id (run_converter conv x))" + +primcorec + rdummy_converter :: "('a \ 'b) \ ('i_cnv, 'o_cnv, 'i_res, 'o_res) converter \ + ('i_cnv + 'a, 'o_cnv + 'b, 'i_res, 'o_res) converter" + where + "run_converter (rdummy_converter f conv) = (\inp. case inp of + Inl x \ map_gpv (map_prod Inl (\c. rdummy_converter f c)) id (run_converter conv x) + | Inr x \ map_gpv (map_prod Inr (\_. rdummy_converter f conv)) id (Done (f x, ())))" + +lemma ldummy_converter_of_callee: + "ldummy_converter f (converter_of_callee callee state) = + converter_of_callee (\s q. case_sum (\ql. Done (Inl (f ql), s)) (\qr. map_gpv (map_prod Inr id) id (callee s qr)) q) state" + apply (coinduction arbitrary: callee state) + apply(clarsimp intro!:rel_funI split!:sum.splits) + subgoal by blast + apply (simp add: gpv.rel_map map_prod_def split_def) + by (rule gpv.rel_mono_strong0[of "(=)" "(=)"]) (auto simp add: gpv.rel_eq) + +lemma rdummy_converter_of_callee: + "rdummy_converter f (converter_of_callee callee state) = + converter_of_callee (\s q. case_sum (\ql. map_gpv (map_prod Inl id) id (callee s ql)) (\qr. Done (Inr (f qr), s)) q) state" + apply (coinduction arbitrary: callee state) + apply(clarsimp intro!:rel_funI split!:sum.splits) + defer + subgoal by blast + apply (simp add: gpv.rel_map map_prod_def split_def) + by (rule gpv.rel_mono_strong0[of "(=)" "(=)"]) (auto simp add: gpv.rel_eq) + + + +\ \Commonly used wirings\ + +context + fixes + cnv1 :: "('icnv_usr1, 'ocnv_usr1, 'iusr1_res1 + 'iusr1_res2, 'ousr1_res1 + 'ousr1_res2) converter" and + cnv2 :: "('icnv_usr2, 'ocnv_usr2, 'iusr2_res1 + 'iusr2_res2, 'ousr2_res1 + 'ousr2_res2) converter" +begin + +\ \c1r22: a converter that has 1 interface and sends queries to two resources, + where the first and second resources have 2 and 2 interfaces respectively\ + +definition + wiring_c1r22_c1r22 :: "('icnv_usr1 + 'icnv_usr2, 'ocnv_usr1 + 'ocnv_usr2, + ('iusr1_res1 + 'iusr2_res1) + 'iusr1_res2 + 'iusr2_res2, + ('ousr1_res1 + 'ousr2_res1) + 'ousr1_res2 + 'ousr2_res2) converter" + where + "wiring_c1r22_c1r22 \ (cnv1 |\<^sub>= cnv2) \ parallel_wiring" + +end + + +\ \Special wiring converters used for the parallel composition of Fused resources\ + +definition + fused_wiring :: " + ((('iadv_core1 + 'iadv_core2) + ('iadv_rest1 + 'iadv_rest2)) + + (('iusr_core1 + 'iusr_core2) + ('iusr_rest1 + 'iusr_rest2)), + (('oadv_core1 + 'oadv_core2) + ('oadv_rest1 + 'oadv_rest2)) + + (('ousr_core1 + 'ousr_core2) + ('ousr_rest1 + 'ousr_rest2)), + (('iadv_core1 + 'iadv_rest1) + ('iusr_core1 + 'iusr_rest1)) + + (('iadv_core2 + 'iadv_rest2) + ('iusr_core2 + 'iusr_rest2)), + (('oadv_core1 + 'oadv_rest1) + ('ousr_core1 + 'ousr_rest1)) + + (('oadv_core2 + 'oadv_rest2) + ('ousr_core2 + 'ousr_rest2))) converter" + where + "fused_wiring \ (parallel_wiring |\<^sub>= parallel_wiring) \ parallel_wiring" + +definition + fused_wiring\<^sub>w + where + "fused_wiring\<^sub>w \ (parallel_wiring\<^sub>w |\<^sub>w parallel_wiring\<^sub>w) \\<^sub>w parallel_wiring\<^sub>w" + +schematic_goal + wiring_fused_wiring[wiring_intro]: "wiring ?\1 ?\2 fused_wiring fused_wiring\<^sub>w" + unfolding fused_wiring_def fused_wiring\<^sub>w_def + by(rule wiring_intro)+ + +schematic_goal WT_fused_wiring [WT_intro]: "?\1, ?\2 \\<^sub>C fused_wiring \" + unfolding fused_wiring_def + by(rule WT_intro)+ + + + +\ \Commonlu used attachments\ + +context + fixes + cnv1 :: "('icnv_usr1, 'ocnv_usr1, 'iusr1_core1 + 'iusr1_core2, 'ousr1_core1 + 'ousr1_core2) converter" and + cnv2 :: "('icnv_usr2, 'ocnv_usr2, 'iusr2_core1 + 'iusr2_core2, 'ousr2_core1 + 'ousr2_core2) converter" and + res1 :: "(('iadv_core1 + 'iadv_rest1) + ('iusr1_core1 + 'iusr2_core1) + 'iusr_rest1, + ('oadv_core1 + 'oadv_rest1) + ('ousr1_core1 + 'ousr2_core1) + 'ousr_rest1) resource" and + res2 :: "(('iadv_core2 + 'iadv_rest2) + ('iusr1_core2 + 'iusr2_core2) + 'iusr_rest2, + ('oadv_core2 + 'oadv_rest2) + ('ousr1_core2 + 'ousr2_core2) + 'ousr_rest2) resource" +begin + +\ \Attachement of two c1f22 ('f' instead of 'r' to indicate Fused Resources) converters + to two 2-interface Fused Resources, the results will be a new 2-interface Fused Resource\ + +definition + attach_c1f22_c1f22 :: "((('iadv_core1 + 'iadv_core2) + 'iadv_rest1 + 'iadv_rest2) + ('icnv_usr1 + 'icnv_usr2) + 'iusr_rest1 + 'iusr_rest2, + (('oadv_core1 + 'oadv_core2) + 'oadv_rest1 + 'oadv_rest2) + ('ocnv_usr1 + 'ocnv_usr2) + 'ousr_rest1 + 'ousr_rest2) resource" + where + "attach_c1f22_c1f22 = (((1\<^sub>C |\<^sub>= 1\<^sub>C) |\<^sub>= ((wiring_c1r22_c1r22 cnv1 cnv2) |\<^sub>= 1\<^sub>C)) \ fused_wiring) \ (res1 \ res2)" +end + + +\ \Properties of Converters attaching to Fused resources\ +context + fixes + core1 :: "('s_core1, 'e1, 'iadv_core1, 'iusr_core1, 'oadv_core1, 'ousr_core1) core" and + core2 :: "('s_core2, 'e2, 'iadv_core2, 'iusr_core2, 'oadv_core2, 'ousr_core2) core" and + rest1 :: "('s_rest1, 'e1, 'iadv_rest1, 'iusr_rest1, 'oadv_rest1, 'ousr_rest1, 'm1) rest_scheme" and + rest2 :: "('s_rest2, 'e2, 'iadv_rest2, 'iusr_rest2, 'oadv_rest2, 'ousr_rest2, 'm2) rest_scheme" +begin + +lemma parallel_oracle_fuse: + "apply_wiring fused_wiring\<^sub>w (parallel_oracle (fused_resource.fuse core1 rest1) (fused_resource.fuse core2 rest2)) = + apply_state_iso parallel_state_iso (fused_resource.fuse (parallel_core core1 core2) (parallel_rest rest1 rest2))" + supply fused_resource.fuse.simps[simp] + apply(rule ext)+ + apply(clarsimp simp add: fused_wiring\<^sub>w_def apply_state_iso_def parallel_state_iso_def parallel_wiring\<^sub>w_def) + apply(simp add: apply_wiring_def comp_wiring_def parallel2_wiring_def lassocr\<^sub>w_def swap_lassocr\<^sub>w_def rassocl\<^sub>w_def swap\<^sub>w_def) + subgoal for s_core1 s_rest1 s_core2 s_rest2 i + apply(cases "(parallel_rest rest1 rest2, ((s_core1, s_core2), (s_rest1, s_rest2)), i)" rule: fused_resource.fuse.cases) + apply(auto split!: sum.splits) + subgoal for iadv_core + by (cases iadv_core) (auto simp add: map_spmf_bind_spmf bind_map_spmf intro!: bind_spmf_cong split!: sum.splits) + subgoal for iadv_rest + by (cases iadv_rest) (auto simp add: parallel_handler_left parallel_handler_right foldl_spmf_pair_left + parallel_eoracle_def foldl_spmf_pair_right split_beta o_def map_spmf_bind_spmf bind_map_spmf) + subgoal for iusr_core + by (cases iusr_core) (auto simp add: map_spmf_bind_spmf bind_map_spmf intro!: bind_spmf_cong split!: sum.splits) + subgoal for iusr_rest + by (cases iusr_rest) (auto simp add: parallel_handler_left parallel_handler_right foldl_spmf_pair_left + parallel_eoracle_def foldl_spmf_pair_right split_beta o_def map_spmf_bind_spmf bind_map_spmf) + done + done +end + +lemma attach_callee_fuse: + "attach_callee ((cnv_adv_core \\<^sub>I cnv_adv_rest) \\<^sub>I cnv_usr_core \\<^sub>I cnv_usr_rest) (fused_resource.fuse core rest) = + apply_state_iso iso_trisplit (fused_resource.fuse (attach_core cnv_adv_core cnv_usr_core core) (attach_rest cnv_adv_rest cnv_usr_rest f_init rest))" + (is "?lhs = ?rhs") +proof(intro ext; clarify) + note fused_resource.fuse.simps [simp] + let ?tri = "\(((s11, s12), s13), (s21, s22), s23). (((s11, s21), s12, s22), s13, s23)" + fix q :: "('g + 'h) + 'i + 'j" + consider (ACore) qac where "q = Inl (Inl qac)" + | (ARest) qar where "q = Inl (Inr qar)" + | (UCore) quc where "q = Inr (Inl quc)" + | (URest) qur where "q = Inr (Inr qur)" + using fuse_callee.cases by blast + then show "?lhs (((sac, sar), (suc, sur)), (sc, sr)) q = ?rhs (((sac, sar), (suc, sur)), (sc, sr)) q" + for sac sar suc sur sc sr + proof cases + case ACore + have "map_spmf rprodl (exec_gpv (fused_resource.fuse core rest) + (left_gpv (map_gpv (map_prod Inl (\s1'. (s1', suc, sur))) id (left_gpv (map_gpv (map_prod Inl (\s1'. (s1', sar))) id (cnv_adv_core sac qac))))) + (sc, sr)) = + (map_spmf (map_prod (Inl \ Inl) (?tri \ prod.swap \ Pair ((sar, sur), sr))) + (map_spmf (\((oadv, s_adv'), s_core'). (oadv, (s_adv', suc), s_core')) + (exec_gpv (cfunc_adv core) (cnv_adv_core sac qac) sc)))" + proof(induction arbitrary: sc cnv_adv_core rule: exec_gpv_fixp_parallel_induct) + case adm show ?case by simp + case bottom show ?case by simp + case (step execl execr) + show ?case + apply(clarsimp simp add: gpv.map_sel map_bind_spmf bind_map_spmf intro!: bind_spmf_cong[OF refl] split!: generat.split) + apply(subst step.IH[unfolded id_def]) + apply(simp add: spmf.map_comp o_def) + done + qed + then show ?thesis using ACore + by(simp add: apply_state_iso_def iso_trisplit_def map_spmf_conv_bind_spmf[symmetric] spmf.map_comp o_def split_def) + next + case ARest + have "bind_spmf (foldl_spmf (cpoke core) (return_spmf sc) es) (\sc'. + map_spmf rprodl (exec_gpv (fused_resource.fuse core rest) + (left_gpv (map_gpv (map_prod Inl (\s1'. (s1', suc, sur))) id (right_gpv (map_gpv (map_prod Inr (Pair sac)) id (cnv_adv_rest sar qar))))) + (sc', sr))) = + bind_spmf + (exec_gpv (\(s, es) q. map_spmf (\((out, e), s'). (out, s', es @ e)) (rfunc_adv rest s q)) (cnv_adv_rest sar qar) (sr, es)) + (map_spmf (map_prod id ?tri) \ + ((\((o_rfunc, e_lst), s_rfunc). map_spmf (\s_notify. (Inl (Inr o_rfunc), s_notify, s_rfunc)) + (map_spmf (Pair (sac, suc)) (foldl_spmf (cpoke core) (return_spmf sc) e_lst))) \ + (\((oadv, s_adv'), s_rest', es). ((oadv, es), (s_adv', sur), s_rest'))))" + for es + proof(induction arbitrary: sc sr es cnv_adv_rest rule: exec_gpv_fixp_parallel_induct) + case adm then show ?case by simp + case bottom then show ?case by simp + case (step execl execr) + show ?case + apply(clarsimp simp add: gpv.map_sel map_bind_spmf bind_map_spmf) + apply(subst bind_commute_spmf) + apply(clarsimp simp add: gpv.map_sel map_bind_spmf bind_map_spmf spmf.map_comp o_def map_spmf_conv_bind_spmf[symmetric] intro!: bind_spmf_cong[OF refl] split!: generat.split) + apply(subst bind_commute_spmf) + apply(clarsimp simp add: gpv.map_sel map_bind_spmf bind_map_spmf spmf.map_comp o_def map_spmf_conv_bind_spmf[symmetric] intro!: bind_spmf_cong[OF refl] split!: generat.split) + apply(simp add: bind_spmf_assoc[symmetric] bind_foldl_spmf_return foldl_spmf_append[symmetric] del: bind_spmf_assoc ) + apply(subst step.IH[unfolded id_def]) + apply(simp add: split_def o_def spmf.map_comp) + done + qed + from this[of "[]"] + show ?thesis using ARest + by(simp add: apply_state_iso_def iso_trisplit_def map_bind_spmf bind_map_spmf map_spmf_conv_bind_spmf[symmetric] foldl_spmf_pair_right) + next + case UCore + have "map_spmf rprodl (exec_gpv (fused_resource.fuse core rest) + (right_gpv (map_gpv (map_prod Inr (Pair (sac, sar))) id (left_gpv (map_gpv (map_prod Inl (\s1'. (s1', sur))) id (cnv_usr_core suc quc))))) + (sc, sr)) = + (map_spmf (map_prod (Inr \ Inl) (?tri \ prod.swap \ Pair ((sar, sur), sr))) + (map_spmf (\((ousr, s_usr'), s_core'). (ousr, (sac, s_usr'), s_core')) + (exec_gpv (cfunc_usr core) (cnv_usr_core suc quc) sc)))" + proof(induction arbitrary: sc cnv_usr_core rule: exec_gpv_fixp_parallel_induct) + case adm show ?case by simp + case bottom show ?case by simp + case (step execl execr) + show ?case + apply(clarsimp simp add: gpv.map_sel map_bind_spmf bind_map_spmf intro!: bind_spmf_cong[OF refl] split!: generat.split) + apply(subst step.IH[unfolded id_def]) + apply(simp add: spmf.map_comp o_def) + done + qed + then show ?thesis using UCore + by(simp add: apply_state_iso_def iso_trisplit_def map_spmf_conv_bind_spmf[symmetric] spmf.map_comp o_def split_def) + next + case URest + have "bind_spmf (foldl_spmf (cpoke core) (return_spmf sc) es) (\sc'. + map_spmf rprodl (exec_gpv (fused_resource.fuse core rest) + (right_gpv (map_gpv (map_prod Inr (Pair (sac, sar))) id (right_gpv (map_gpv (map_prod Inr (Pair suc)) id (cnv_usr_rest sur qur))))) + (sc', sr))) = + bind_spmf + (exec_gpv (\(s, es) q. map_spmf (\((out, e), s'). (out, s', es @ e)) (rfunc_usr rest s q)) (cnv_usr_rest sur qur) (sr, es)) + (map_spmf (map_prod id ?tri) \ + ((\((o_rfunc, e_lst), s_rfunc). map_spmf (\s_notify. (Inr (Inr o_rfunc), s_notify, s_rfunc)) + (map_spmf (Pair (sac, suc)) (foldl_spmf (cpoke core) (return_spmf sc) e_lst))) \ + (\((ousr, s_usr'), s_rest', es). ((ousr, es), (sar, s_usr'), s_rest'))))" + for es + proof(induction arbitrary: sc sr es cnv_usr_rest rule: exec_gpv_fixp_parallel_induct) + case adm then show ?case by simp + case bottom then show ?case by simp + case (step execl execr) + show ?case + apply(clarsimp simp add: gpv.map_sel map_bind_spmf bind_map_spmf) + apply(subst bind_commute_spmf) + apply(clarsimp simp add: gpv.map_sel map_bind_spmf bind_map_spmf spmf.map_comp o_def map_spmf_conv_bind_spmf[symmetric] intro!: bind_spmf_cong[OF refl] split!: generat.split) + apply(subst bind_commute_spmf) + apply(clarsimp simp add: gpv.map_sel map_bind_spmf bind_map_spmf spmf.map_comp o_def map_spmf_conv_bind_spmf[symmetric] intro!: bind_spmf_cong[OF refl] split!: generat.split) + apply(simp add: bind_spmf_assoc[symmetric] bind_foldl_spmf_return foldl_spmf_append[symmetric] del: bind_spmf_assoc ) + apply(subst step.IH[unfolded id_def]) + apply(simp add: split_def o_def spmf.map_comp) + done + qed + from this[of "[]"] show ?thesis using URest + by(simp add: apply_state_iso_def iso_trisplit_def map_bind_spmf bind_map_spmf map_spmf_conv_bind_spmf[symmetric] foldl_spmf_pair_right) + qed +qed + +lemma attach_parallel_fuse': + "(CNV cnv_adv_core s_a_c |\<^sub>= CNV cnv_adv_rest s_a_r) |\<^sub>= (CNV cnv_usr_core s_u_c |\<^sub>= CNV cnv_usr_rest s_u_r) \ + RES (fused_resource.fuse core rest) (s_r_c, s_r_r) = + RES (fused_resource.fuse (attach_core cnv_adv_core cnv_usr_core core) (attach_rest cnv_adv_rest cnv_usr_rest f_init rest)) (((s_a_c, s_u_c), s_r_c), ((s_a_r, s_u_r), s_r_r))" + apply(fold conv_callee_parallel) + apply(unfold attach_CNV_RES) + apply(subst attach_callee_fuse) + apply(subst resource_of_oracle_state_iso) + apply simp + apply(simp add: iso_trisplit_def) + done + + +\ \Moving event translators from rest to the core\ + +context + fixes + einit :: 's_event and + etran :: "('s_event, 'ievent, 'oevent list) oracle'" and + rest :: "('s_rest, 'ievent, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest) rest_wstate" and + core :: "('s_core, 'oevent, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core" +begin + +primcorec + translate_rest :: "('s_event \ 's_rest, 'oevent, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest) rest_wstate" + where + "rinit translate_rest = (einit, rinit rest)" + | "rfunc_adv translate_rest = translate_eoracle etran (extend_state_oracle (rfunc_adv rest))" + | "rfunc_usr translate_rest = translate_eoracle etran (extend_state_oracle (rfunc_usr rest))" + +primcorec + translate_core :: "('s_event \ 's_core, 'ievent, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core" + where + "cpoke translate_core = (\(s_event, s_core) event. + bind_spmf (etran s_event event) (\(events, s_event'). + map_spmf (\s_core'. (s_event', s_core')) (foldl_spmf (cpoke core) (return_spmf s_core) events)))" + | "cfunc_adv translate_core = extend_state_oracle (cfunc_adv core)" + | "cfunc_usr translate_core = extend_state_oracle (cfunc_usr core)" + + +lemma WT_translate_rest [WT_intro]: + assumes "WT_rest \_adv \_usr I_rest rest" + shows "WT_rest \_adv \_usr (pred_prod (\_. True) I_rest) translate_rest" + by(rule WT_rest.intros)(auto simp add: translate_eoracle_def simp add: WT_restD_rinit[OF assms] dest!: WT_restD(1,2)[OF assms]) + + +lemma fused_resource_move_translate: + "fused_resource.fuse core translate_rest = apply_state_iso iso_swapar (fused_resource.fuse translate_core rest)" +proof - + note [simp] = exec_gpv_bind spmf.map_comp o_def map_bind_spmf bind_map_spmf bind_spmf_const + + show ?thesis + apply (rule ext) + apply (rule ext) + subgoal for s query + apply (cases s) + subgoal for s_core s_event s_rest + apply (cases query) + subgoal for q_adv + apply (cases q_adv) + subgoal for q_acore + by (simp add: apply_state_iso_def iso_swapar_def fused_resource.fuse.simps split_def map_prod_def) + subgoal for q_arest + apply (simp add: apply_state_iso_def iso_swapar_def fused_resource.fuse.simps) + apply (simp add: translate_eoracle_def split_def) + apply(rule bind_spmf_cong[OF refl]) + apply(subst foldl_spmf_chain[simplified split_def]) + by simp + done + subgoal for q_usr + apply (cases q_usr) + subgoal for q_ucore + by (simp add: apply_state_iso_def iso_swapar_def fused_resource.fuse.simps split_def map_prod_def) + subgoal for q_urest + apply (simp add: apply_state_iso_def iso_swapar_def fused_resource.fuse.simps) + apply (simp add: translate_eoracle_def split_def) + apply(rule bind_spmf_cong[OF refl]) + apply(subst foldl_spmf_chain[simplified split_def]) + by simp + done + done + done + done +qed + + + +end + + +\ \Moving interfaces between rest and core\ + +lemma + fuse_ishift_core_to_rest: + assumes "cpoke core' = (\s. case_sum (\q. fn s q) (cpoke core s))" + and "cfunc_adv core = cfunc_adv core'" + and "cfunc_usr core = cfunc_usr core' \\<^sub>O (\s i. map_spmf (Pair (h_out i)) (fn s i))" + and "rfunc_adv rest' = (\s q. map_spmf (apfst (apsnd (map Inr))) (rfunc_adv rest s q))" + and "rfunc_usr rest' = plus_eoracle (\s i. return_spmf ((h_out i, [i]), s)) (rfunc_usr rest)" + shows "fused_resource.fuse core rest = apply_wiring (1\<^sub>w |\<^sub>w lassocr\<^sub>w) (fused_resource.fuse core' rest')" (is "?L = ?R") +proof - + note [simp] = fused_resource.fuse.simps apply_wiring_def lassocr\<^sub>w_def parallel2_wiring_def + plus_eoracle_def map_spmf_conv_bind_spmf map_prod_def map_fun_def split_def o_def + + have "?L s q = ?R s q" for s q + apply (cases q; cases s) + subgoal for q_adv + by (cases q_adv) (simp_all add: assms(1, 2, 4)) + subgoal for q_usr + apply (cases q_usr) + subgoal for q_usr_core + apply (cases q_usr_core) + subgoal for q_nrm + by (simp add: assms(3)) + by (simp add: assms(1, 3, 5)) + by (simp add: assms(1, 5)) + done + + then show ?thesis + by blast +qed + + +lemma move_simulator_interface: + defines "x_ifunc \ (\ifunc core (se, sc) q. do { + ((out, es), se') \ ifunc se q; + sc' \ foldl_spmf (cpoke core) (return_spmf sc) es; + return_spmf (out, se', sc') })" + assumes "cpoke core' = cpoke (translate_core etran core)" + and "cfunc_adv core' = \(cfunc_adv core) \\<^sub>O x_ifunc ifunc core" + and "cfunc_usr core' = cfunc_usr (translate_core etran core)" + and "rinit rest = (einit, rinit rest')" + and "rfunc_adv rest = (\s q. case q of + Inl ql \ map_spmf (apfst (map_prod Inl id)) ((ifunc\) s ql) + | Inr qr \ map_spmf (apfst (map_prod Inr id)) ((translate_eoracle etran (\(rfunc_adv rest'))) s qr))" + and "rfunc_usr rest = translate_eoracle etran (\(rfunc_usr rest'))" + shows "fused_resource.fuse core rest = apply_wiring (rassocl\<^sub>w |\<^sub>w (id, id)) + (apply_state_iso (rprodl o (apfst prod.swap), (apfst prod.swap) o lprodr) + (fused_resource.fuse core' rest'))" + (is "?L = ?R") +proof - + note [simp] = fused_resource.fuse.simps apply_wiring_def rassocl\<^sub>w_def parallel2_wiring_def apply_state_iso_def + exec_gpv_bind spmf.map_comp map_bind_spmf bind_map_spmf bind_spmf_const o_def split_def + + have "?L (sc, st, sr) q = ?R (sc, st, sr) q" for sc st sr q + apply (simp add: map_fun_def map_prod_def prod.swap_def apfst_def lprodr_def rprodl_def id_def) + using assms apply (cases q) + subgoal for q_adv + apply (cases q_adv) + subgoal for q_adv_core + by (simp add: map_prod_def) + subgoal for q_adv_rest + apply (cases q_adv_rest) + subgoal for q_adv_rest_ifunc + by simp + subgoal for q_adv_rest_etran + apply (simp add: translate_eoracle_def) + apply(rule bind_spmf_cong[OF refl]) + apply(subst foldl_spmf_chain[simplified split_def]) + by simp + done + done + subgoal for q_usr + apply (cases q_usr) + subgoal for q_usr_core + by (simp add: map_prod_def) + subgoal for q_usr_rest + apply (simp add: translate_eoracle_def extend_state_oracle_def) + apply(rule bind_spmf_cong[OF refl]) + apply(subst foldl_spmf_chain[simplified split_def]) + by simp + done + done + + then show ?thesis + by force +qed + + +end diff --git a/thys/Constructive_Cryptography_CM/Constructions/DH_OTP.thy b/thys/Constructive_Cryptography_CM/Constructions/DH_OTP.thy new file mode 100644 --- /dev/null +++ b/thys/Constructive_Cryptography_CM/Constructions/DH_OTP.thy @@ -0,0 +1,102 @@ +theory DH_OTP imports + One_Time_Pad + Diffie_Hellman_CC +begin + +text \ + We need both a group structure and a boolean algebra. + Unfortunately, records allow only one extension slot, so we can't have just a single + structure with both operations. +\ + +context diffie_hellman begin + +lemma WT_ideal_rest [WT_intro]: + assumes WT_auth1_rest [WT_intro]: "WT_rest \_adv_rest1 \_usr_rest1 I_auth1_rest auth1_rest" + and WT_auth2_rest [WT_intro]: "WT_rest \_adv_rest2 \_usr_rest2 I_auth2_rest auth2_rest" + shows "WT_rest (\_full \\<^sub>\ (\_adv_rest1 \\<^sub>\ \_adv_rest2)) ((\_full \\<^sub>\ \_full) \\<^sub>\ (\_usr_rest1 \\<^sub>\ \_usr_rest2)) + (\(_, s). pred_prod I_auth1_rest I_auth2_rest s) (ideal_rest auth1_rest auth2_rest)" + apply(rule WT_rest.intros) + subgoal + by(auto 4 4 split: sum.splits simp add: translate_eoracle_def parallel_eoracle_def dest: assms[THEN WT_restD_rfunc_adv]) + subgoal + apply(auto 4 4 split: sum.splits simp add: translate_eoracle_def parallel_eoracle_def plus_eoracle_def dest: assms[THEN WT_restD_rfunc_usr]) + apply(simp add: map_sum_def split: sum.splits) + done + subgoal by(simp add: assms[THEN WT_restD_rinit]) +done + +end + + +locale dh_otp = dh: diffie_hellman \ + otp: one_time_pad \ + for \ :: "'grp cyclic_group" + and \ :: "'grp boolean_algebra" + + assumes carrier_\_\: "carrier \ = carrier \" +begin + +theorem secure: + assumes "WT_rest \_adv_resta \_usr_resta I_auth_rest auth_rest" + and "WT_rest \_adv_rest1 \_usr_rest1 I_auth1_rest auth1_rest" + and "WT_rest \_adv_rest2 \_usr_rest2 I_auth2_rest auth2_rest" + shows + "constructive_security_obsf + (1\<^sub>C |\<^sub>= wiring_c1r22_c1r22 (CNV otp.enc_callee ()) (CNV otp.dec_callee ()) |\<^sub>= 1\<^sub>C \ + fused_wiring \ diffie_hellman.real_resource \ auth1_rest auth2_rest \ dh.auth.resource auth_rest) + (otp.sec.resource (otp.ideal_rest (dh.ideal_rest auth1_rest auth2_rest) auth_rest)) + ((1\<^sub>C \ + (parallel_wiring \ ((let sim = CNV dh.sim_callee None in (sim |\<^sub>= 1\<^sub>C) \ lassocr\<^sub>C) |\<^sub>= 1\<^sub>C) \ parallel_wiring) \ + 1\<^sub>C) \ + (otp.sim |\<^sub>= 1\<^sub>C)) + ((((\_full \\<^sub>\ (\_full \\<^sub>\ \_uniform (otp.sec.Inp_Fedit ` carrier \) UNIV)) \\<^sub>\ + (\_full \\<^sub>\ (\_full \\<^sub>\ \_uniform (otp.sec.Inp_Fedit ` carrier \) UNIV))) \\<^sub>\ + (\_full \\<^sub>\ (\_full \\<^sub>\ \_uniform (otp.sec.Inp_Fedit ` carrier \) UNIV))) \\<^sub>\ + ((\_adv_rest1 \\<^sub>\ \_adv_rest2) \\<^sub>\ \_adv_resta)) + ((\_full \\<^sub>\ (\_full \\<^sub>\ \_uniform (otp.sec.Inp_Fedit ` carrier \) UNIV)) \\<^sub>\ + ((\_full \\<^sub>\ (\_adv_rest1 \\<^sub>\ \_adv_rest2)) \\<^sub>\ \_adv_resta)) + ((\_uniform (otp.sec.Inp_Send ` carrier \) UNIV \\<^sub>\ \_uniform UNIV (otp.sec.Out_Recv ` carrier \)) \\<^sub>\ + (((\_full \\<^sub>\ \_full) \\<^sub>\ (\_usr_rest1 \\<^sub>\ \_usr_rest2)) \\<^sub>\ \_usr_resta)) + \ (0 + (ddh.advantage \ + (diffie_hellman.DH_adversary \ auth1_rest auth2_rest + (absorb + (absorb \ + (obsf_converter (1\<^sub>C |\<^sub>= wiring_c1r22_c1r22 (CNV otp.enc_callee ()) (CNV otp.dec_callee ()) |\<^sub>= 1\<^sub>C))) + (obsf_converter + (fused_wiring \ (1\<^sub>C |\<^sub>\ converter_of_resource (1\<^sub>C |\<^sub>= 1\<^sub>C \ dh.auth.resource auth_rest)))))) + + 0))" + using assms apply - + apply(rule constructive_security_obsf_composability) + apply(rule otp.secure) + apply(rule WT_intro, assumption+) + unfolding otp.real_resource_def attach_c1f22_c1f22_def[abs_def] attach_compose + apply(rule constructive_security_obsf_lifting_[where w_adv_real="1\<^sub>C" and w_adv_ideal_inv="1\<^sub>C"]) + apply(rule parallel_constructive_security_obsf_fuse) + apply(fold carrier_\_\)[1] + apply(rule dh.secure, assumption, assumption, rule constructive_security_obsf_trivial) + defer + defer + defer + apply(rule WT_intro)+ + apply(simp add: comp_converter_id_left) + apply(rule parallel_converter2_id_id pfinite_intro wiring_intro)+ + apply(rule WT_intro|assumption)+ + apply simp + apply(unfold wiring_c1r22_c1r22_def) + apply(rule WT_intro)+ + apply(fold carrier_\_\)[1] + apply(rule WT_intro)+ + + apply(rule pfinite_intro) + apply(rule pfinite_intro) + apply(rule pfinite_intro) + apply(rule pfinite_intro) + apply(rule pfinite_intro) + apply(unfold carrier_\_\) + apply(rule pfinite_intro) + apply(rule WT_intro)+ + apply(rule pfinite_intro) + done + +end + +end \ No newline at end of file diff --git a/thys/Constructive_Cryptography_CM/Constructions/Diffie_Hellman_CC.thy b/thys/Constructive_Cryptography_CM/Constructions/Diffie_Hellman_CC.thy new file mode 100644 --- /dev/null +++ b/thys/Constructive_Cryptography_CM/Constructions/Diffie_Hellman_CC.thy @@ -0,0 +1,2368 @@ +theory Diffie_Hellman_CC + imports + Game_Based_Crypto.Diffie_Hellman + "../Asymptotic_Security" + "../Construction_Utility" + "../Specifications/Key" + "../Specifications/Channel" +begin + +hide_const (open) Resumption.Pause Monomorphic_Monad.Pause Monomorphic_Monad.Done + +no_notation Sublist.parallel (infixl "\" 50) +no_notation plus_oracle (infix "\\<^sub>O" 500) + + +section \Diffie-Hellman construction\ + +locale diffie_hellman = + auth: ideal_channel "id :: 'grp \ 'grp" False + + key: ideal_key "carrier \" + + cyclic_group \ + for + \ :: "'grp cyclic_group" (structure) +begin + + +subsection \Defining user callees\ + +datatype 'grp' cstate = CState_Void | CState_Half nat | CState_Full "nat \ 'grp'" + +datatype icnv_alice = Inp_Activation_Alice +datatype icnv_bob = Iact_Activation_Bob + +datatype ocnv_alice = Out_Activation_Alice +datatype ocnv_bob = Out_Activation_Bob + +fun alice_callee :: "'grp cstate \ key.iusr_alice + icnv_alice + \ (('grp key.ousr_alice + ocnv_alice) \ 'grp cstate, 'grp auth.iusr_alice + auth.iusr_bob, auth.ousr_alice + 'grp auth.ousr_bob) gpv" + where + "alice_callee CState_Void (Inr _) = do { + x \ lift_spmf (sample_uniform (order \)); + let msg = \<^bold>g [^] x; + Pause + (Inl (auth.Inp_Send msg)) + (\rsp. case rsp of + Inl _ \ Done (Inr Out_Activation_Alice, CState_Half x) + | Inr _ \ Fail) }" + | "alice_callee (CState_Half x) (Inl _) = + Pause + (Inr auth.Inp_Recv) + (\rsp. case rsp of + Inl _ \ Fail + | Inr msg \ case msg of + auth.Out_Recv gy \ + let key = gy [^] x in + Done (Inl (key.Out_Alice key), CState_Full (x, key)))" + | "alice_callee (CState_Full (x, key)) (Inl _) = Done (Inl (key.Out_Alice key), CState_Full (x, key))" + | "alice_callee _ _ = Fail" + +fun bob_callee :: "'grp cstate \ key.iusr_bob + icnv_bob + \ (('grp key.ousr_bob + ocnv_bob) \ 'grp cstate, auth.iusr_bob + 'grp auth.iusr_alice, 'grp auth.ousr_bob + auth.ousr_alice) gpv" + where + "bob_callee CState_Void (Inr _) = do { + y \ lift_spmf (sample_uniform (order \)); + let msg = \<^bold>g [^] y; + Pause + (Inr (auth.Inp_Send msg)) + (\rsp. case rsp of + Inl _ \ Fail + | Inr _ \ Done (Inr Out_Activation_Bob, CState_Half y)) }" + | "bob_callee (CState_Half y) (Inl _) = + Pause + (Inl auth.Inp_Recv) + (\rsp. case rsp of + Inl msg \ case msg of + auth.Out_Recv gx \ + let k = gx [^] y in + Done (Inl (key.Out_Bob k), CState_Full (y, k)) + | Inr _ \ Fail)" + | "bob_callee (CState_Full (y, key)) (Inl _) = Done (Inl (key.Out_Bob key), CState_Full (y, key))" + | "bob_callee _ _ = Fail" + + +subsection \Defining adversary callee\ +(* +astate_rbase \ ranmed to \ asate_chann +datatype astate_chann = AState_Available | AState_Unavailable +type_synonym 'grp' astate_lbase = "('grp' \ 'grp') option" +type_synonym 'grp' astate_single = "'grp' astate_lbase \ astate_rbase"*) +type_synonym 'grp' astate = "('grp' \ 'grp') option" + +type_synonym 'grp' isim = "'grp' auth.iadv + 'grp' auth.iadv" +datatype osim = Out_Simulator + +fun sim_callee_base :: "(('grp \ 'grp) \ 'grp ) \ ('grp astate, 'grp auth.iadv, 'grp auth.oadv) oracle'" + where + "sim_callee_base _ _ (Inl _) = return_pmf None" + | "sim_callee_base pick gpair_opt (Inr (Inl _)) = do { + sample \ do { + x \ sample_uniform (order \); + y \ sample_uniform (order \); + return_spmf (\<^bold>g [^] x, \<^bold>g [^] y) }; + let sample' = case_option sample id gpair_opt; + return_spmf (Inr (Inl (auth.Out_Look (pick sample'))), Some sample') }" + | "sim_callee_base _ gpair_opt (Inr (Inr _ )) = return_spmf (Inr (Inr auth.Out_Fedit), gpair_opt)" + +fun sim_callee :: "'grp astate \ 'grp auth.iadv + 'grp auth.iadv + \ (('grp auth.oadv + 'grp auth.oadv) \ 'grp astate, key.iadv + 'grp isim, key.oadv + osim) gpv" + where + "sim_callee s_gpair query = + (let handle = (\gpair_pick wrap_out q_split. do { + _ \ Pause (Inr query) Done; + (out, s_gpair') \ lift_spmf (sim_callee_base gpair_pick s_gpair q_split); + Done (wrap_out out, s_gpair') }) in + case_sum (handle fst Inl) (handle snd Inr) query)" + +subsection \Defining event-translator\ + +datatype estate_base = EState_Void | EState_Store | EState_Collect +type_synonym estate = "bool \ (estate_base \ auth.s_shell) \ estate_base \ auth.s_shell" + +definition einit :: estate + where + "einit \ (False, (EState_Void, {}), EState_Void, {})" + +definition eleak :: "(estate, key.event, 'grp isim, osim) eoracle" + where + "eleak \ (\(s_flg, (s_event1, s_shell1), s_event2, s_shell2) query. + let handle_arg1 = (\s q. case (s, q) of (EState_Store, Some (Inr (Inr _))) \ (True, EState_Collect) | (s', _) \ (False, s')) in + let handle_arg2 = (\s q D. case (s, q) of (EState_Store, Inr _) \ D | _ \ return_pmf None) in + let (is_ch1, s_event1') = handle_arg1 s_event1 (case_sum Some (\_. None) query) in + let (is_ch2, s_event2') = handle_arg1 s_event2 (case_sum (\_. None) Some query) in + let check_pst1 = is_ch1 \ s_event2' \ EState_Void \ auth.Bob \ s_shell1 \ auth.Alice \ s_shell2 in + let check_pst2 = is_ch2 \ s_event1' \ EState_Void \ auth.Alice \ s_shell1 \ auth.Bob \ s_shell2 in + let e_pstfix1 = if check_pst1 then [key.Event_Shell key.Bob] else [] in + let e_pstfix2 = if check_pst2 then [key.Event_Shell key.Alice] else [] in + let e_prefix = if \s_flg then [key.Event_Kernel] else [] in + let (s_flg', event) = if is_ch2 \ is_ch1 then (True, e_prefix @ e_pstfix1 @ e_pstfix2) else (s_flg, []) in + let result_base = return_spmf ((Out_Simulator, event), s_flg', (s_event1', s_shell1), s_event2', s_shell2) in + case_sum (handle_arg2 s_event1) (handle_arg2 s_event2) query result_base)" + +fun etran_base :: "(key.party \ key.party \ key.party \ key.party) + \ (estate, auth.event, key.event list) oracle'" + where + "etran_base mod_event (s_flg, (s_event1, s_shell1), s_event2, s_shell2) (auth.Event_Shell party) = + (let party_dual = auth.case_party (auth.Bob) (auth.Alice) party in + let epair = auth.case_party prod.swap id party (key.Bob, key.Alice) in + let (s_event_eq, s_event_neq) = auth.case_party prod.swap id party (s_event1, s_event2) in + let check = party_dual \ s_shell2 \ s_event_eq = EState_Collect \ s_event_neq \ EState_Void in + let event = if check then [key.Event_Shell ((fst o mod_event) epair)] else [] in + let s_shell1' = insert party s_shell1 in + if party \ s_shell1 then + return_pmf None + else + return_spmf (event, s_flg, (s_event1, s_shell1'), s_event2, s_shell2))" + +fun etran :: "(estate, (icnv_alice + icnv_bob) + auth.event + auth.event, key.event list) oracle'" + where + "etran (s_flg, (EState_Void, s_shell1), s_event2, s_shell2) (Inl (Inl _)) = + (let check = (s_event2 = EState_Collect \ auth.Alice \ s_shell1 \ auth.Bob \ s_shell2) in + let event = if check then [key.Event_Shell key.Alice] else [] in + let state = (s_flg, (EState_Store, s_shell1), s_event2, s_shell2) in + if auth.Alice \ s_shell1 then return_spmf (event, state) else return_pmf None)" + | "etran (s_flg, (s_event1, s_shell1), EState_Void, s_shell2) (Inl (Inr _)) = + (let check = (s_event1 = EState_Collect \ auth.Bob \ s_shell1 \ auth.Alice \ s_shell2) in + let event = if check then [key.Event_Shell key.Bob] else [] in + let state = (s_flg, (s_event1, s_shell1), EState_Store, s_shell2) in + if auth.Alice \ s_shell2 then return_spmf (event, state) else return_pmf None)" + | "etran state (Inr query) = + (let handle = (\mod_s mod_e q. do { + (evt, state') \ etran_base mod_e (mod_s state) q; + return_spmf (evt, mod_s state') }) in + case_sum (handle id id) (handle (apsnd prod.swap) prod.swap) query)" + | "etran _ _ = return_pmf None" + + +subsection \Defining Ideal and Real constructions\ + +context + fixes + auth1_rest :: "('auth1_s_rest, auth.event, 'auth1_iadv_rest, 'auth1_iusr_rest, 'auth1_oadv_rest, 'auth1_ousr_rest) rest_wstate" and + auth2_rest :: "('auth2_s_rest, auth.event, 'auth2_iadv_rest, 'auth2_iusr_rest, 'auth2_oadv_rest, 'auth2_ousr_rest) rest_wstate" +begin + +primcorec ideal_core_alt + where + "cpoke ideal_core_alt = cpoke (translate_core etran key.core)" + | "cfunc_adv ideal_core_alt = \(cfunc_adv key.core) \\<^sub>O (\(se, sc) q. do { + ((out, es), se') \ eleak se q; + sc' \ foldl_spmf (cpoke key.core) (return_spmf sc) es; + return_spmf (out, se', sc') })" + | "cfunc_usr ideal_core_alt = cfunc_usr (translate_core etran key.core)" + +primcorec ideal_rest_alt + where + "rinit ideal_rest_alt = rinit (parallel_rest auth1_rest auth2_rest)" + | "rfunc_adv ideal_rest_alt = (\s q. map_spmf (apfst (apsnd (map Inr))) (rfunc_adv (parallel_rest auth1_rest auth2_rest) s q))" + | "rfunc_usr ideal_rest_alt = ( + let handle = map_sum (\_ :: icnv_alice. Out_Activation_Alice) (\_ :: icnv_bob. Out_Activation_Bob) in + plus_eoracle (\s q. return_spmf ((handle q, [q]), s)) (rfunc_usr (parallel_rest auth1_rest auth2_rest)))" + +primcorec ideal_rest + where + "rinit ideal_rest = (einit, rinit ideal_rest_alt)" + | "rfunc_adv ideal_rest = (\s q. case q of + Inl ql \ map_spmf (apfst (map_prod Inl id)) (eleak\ s ql) + | Inr qr \ map_spmf (apfst (map_prod Inr id)) (translate_eoracle etran \(rfunc_adv ideal_rest_alt) s qr))" + | "rfunc_usr ideal_rest = translate_eoracle etran \(rfunc_usr ideal_rest_alt)" + +definition ideal_resource + where + "ideal_resource \ + (let sim = CNV sim_callee None in + attach ((sim |\<^sub>= 1\<^sub>C ) \ lassocr\<^sub>C |\<^sub>= 1\<^sub>C |\<^sub>= 1\<^sub>C) (key.resource ideal_rest))" + +definition real_resource + where + "real_resource \ + (let dh_wiring = parallel_wiring \ (CNV alice_callee CState_Void |\<^sub>= CNV bob_callee CState_Void) \ parallel_wiring \ (1\<^sub>C |\<^sub>= swap\<^sub>C) in + attach (((1\<^sub>C |\<^sub>= 1\<^sub>C) |\<^sub>= rassocl\<^sub>C \ (dh_wiring |\<^sub>= 1\<^sub>C)) \ fused_wiring) ((auth.resource auth1_rest) \ (auth.resource auth2_rest)))" + + +subsection \Wiring and simplifying the Ideal construction\ + +abbreviation basic_rest_sinit + where + "basic_rest_sinit \ (((), ()), rinit auth1_rest, rinit auth2_rest)" + +primcorec basic_rest :: "((unit \ unit) \ _, _, _, _, _, _, _) rest_scheme" + where + "rinit basic_rest = (rinit auth1_rest, rinit auth2_rest)" + | "rfunc_adv basic_rest = \(parallel_eoracle (rfunc_adv auth1_rest) (rfunc_adv auth2_rest))" + | "rfunc_usr basic_rest = \(parallel_eoracle (rfunc_usr auth1_rest) (rfunc_usr auth2_rest))" + +definition ideal_s_core' :: "('grp astate \ _) \ _ \ 'grp key.state" + where + "ideal_s_core' \ ((None, ()), einit, key.PState_Store, {})" + +definition ideal_s_rest' + where + "ideal_s_rest' \ basic_rest_sinit" + +primcorec ideal_core' + where + "cpoke ideal_core' = (\(s_cnv, s_event, s_core) event. do { + (events, s_event') \ (etran s_event event); + s_core' \ foldl_spmf key.poke (return_spmf s_core) events; + return_spmf (s_cnv, s_event', s_core') })" + | "cfunc_adv ideal_core' = (\((s_sim, _), s_event_core) q. + map_spmf + (\((out, s_sim'), s_event_core'). (out, (s_sim', ()), s_event_core')) + (exec_gpv + (\key.iface_adv \\<^sub>O (\(se, sc) isim. do { + ((out, es), se') \ eleak se isim; + sc' \ foldl_spmf (cpoke key.core) (return_spmf sc) es; + return_spmf (out, se', sc') })) + (sim_callee s_sim q) s_event_core))" + | "cfunc_usr ideal_core' = (\(s_cnv, s_core) q. + map_spmf (\(out, s_core'). (out, s_cnv, s_core')) (\key.iface_usr s_core q))" + +primcorec ideal_rest' + where + "rinit ideal_rest' = rinit basic_rest" + | "rfunc_adv ideal_rest' = (\s q. map_spmf (apfst (apsnd (map Inr))) (rfunc_adv basic_rest s q))" + | "rfunc_usr ideal_rest' = ( + let handle = map_sum (\_ :: icnv_alice. Out_Activation_Alice) (\_ :: icnv_bob. Out_Activation_Bob) in + plus_eoracle (\s q. return_spmf ((handle q, [q]), s)) (rfunc_usr basic_rest))" + + +subsubsection \The ideal attachment lemma\ + +context +begin + +lemma ideal_resource_shift_interface: "key.resource ideal_rest = RES + (apply_wiring (rassocl\<^sub>w |\<^sub>w (id, id)) (fused_resource.fuse ideal_core_alt ideal_rest_alt)) + ((einit, key.PState_Store, {}), rinit ideal_rest_alt)" +proof - + have "state_iso (rprodl \ apfst prod.swap, apfst prod.swap \ lprodr)" + by(simp add: state_iso_def rprodl_def lprodr_def apfst_def; unfold_locales; simp add: split_def) + + note f1= resource_of_oracle_state_iso[OF this] + + have f2: "key.fuse ideal_rest = apply_state_iso (rprodl \ apfst prod.swap, apfst prod.swap \ lprodr) + (apply_wiring (rassocl\<^sub>w |\<^sub>w (id, id)) (fused_resource.fuse ideal_core_alt ideal_rest_alt))" + by (rule move_simulator_interface[unfolded apply_wiring_state_iso_assoc, where etran=etran and ifunc=eleak and einit=einit and + core=key.core and rest=ideal_rest and core'=ideal_core_alt and rest'=ideal_rest_alt]) simp_all + + show ?thesis + unfolding key.resource_def + by (subst f2, subst f1) simp +qed + +private lemma ideal_resource_alt_def: "ideal_resource = + (let sim = CNV sim_callee None in + let s_init = ((einit, key.PState_Store, {}), rinit ideal_rest_alt) in + attach ((sim |\<^sub>= 1\<^sub>C) |\<^sub>= 1\<^sub>C |\<^sub>= 1\<^sub>C) (RES (fused_resource.fuse ideal_core_alt ideal_rest_alt) s_init))" +proof - + note ideal_resource_shift_interface + moreover have "sim = CNV sim_callee None \ + (sim |\<^sub>= 1\<^sub>C) \ lassocr\<^sub>C |\<^sub>= 1\<^sub>C |\<^sub>= 1\<^sub>C \ RES (apply_wiring (rassocl\<^sub>w |\<^sub>w (id, id)) (fused_resource.fuse ideal_core_alt ideal_rest_alt)) s = + (sim |\<^sub>= 1\<^sub>C) |\<^sub>= 1\<^sub>C |\<^sub>= 1\<^sub>C \ RES (fused_resource.fuse ideal_core_alt ideal_rest_alt) s" (is "?L \ ?R") for sim s + proof - + have fact1: "\_full, \_full \\<^sub>\ \_full \\<^sub>C CNV sim_callee s \" for s + apply(subst WT_converter_of_callee) + apply (rule WT_gpv_\_mono) + apply (rule WT_gpv_full) + apply (rule \_full_le_plus_\) + apply(rule order_refl) + apply(rule order_refl) + by (simp_all add: ) + + have fact2: "(\_full \\<^sub>\ (\_full \\<^sub>\ \_full)) \\<^sub>\ (\_full \\<^sub>\ \_full) \c + apply_wiring (rassocl\<^sub>w |\<^sub>w (id, id)) (fused_resource.fuse ideal_core_alt ideal_rest_alt) s \" for s + apply (rule WT_calleeI) + subgoal for call + apply (cases s, cases call) + apply (rename_tac [!] x) + apply (case_tac [!] x) + apply (rename_tac [2] y) + apply (case_tac [2] y) + by (auto simp add: apply_wiring_def rassocl\<^sub>w_def parallel2_wiring_def fused_resource.fuse.simps) + done + + note [simp] = spmf.map_comp map_bind_spmf bind_map_spmf bind_spmf_const o_def + + assume ?L + then show ?R + apply simp + apply (subst (1 2) conv_callee_parallel_id_right[symmetric, where s'="()"]) + apply(subst eq_resource_on_UNIV_iff[symmetric]) + apply (subst eq_resource_on_trans) + apply (rule eq_\_attach_on') + defer + apply (rule parallel_converter2_eq_\_cong) + apply (rule comp_converter_of_callee_wiring) + apply (rule wiring_lassocr) + apply (subst conv_callee_parallel_id_right) + apply(rule WT_intro)+ + apply (rule fact1) + apply(rule WT_intro)+ + apply (rule eq_\_converter_reflI) + apply(rule WT_intro)+ + defer + apply (subst (1 2 3 4) converter_of_callee_id_oracle[symmetric, where s="()"]) + apply (subst conv_callee_parallel[symmetric])+ + apply (subst (1 2) attach_CNV_RES) + subgoal + apply (rule eq_resource_on_resource_of_oracleI[where S="(=)"]) + defer + apply simp + apply (rule rel_funI)+ + apply (simp add: prod.rel_eq eq_on_def) + subgoal for s' s q' q + apply (cases s; cases q) + apply (rename_tac [!] x) + apply (case_tac [!] x) + apply (rename_tac [!] y) + apply (case_tac [4] y) + apply (auto simp add: apply_wiring_def parallel2_wiring_def attach_wiring_right_def + rassocl\<^sub>w_def lassocr\<^sub>w_def map_fun_def map_prod_def split_def) + subgoal for s_flg _ _ _ _ _ _ _ _ _ q + apply (case_tac "(s_flg, q)" rule: sim_callee.cases) + apply (simp_all add: split_def split!: sum.split if_splits cong: if_cong) + by (rule rel_spmf_bindI'[where A="(=)"], simp, clarsimp split!: sum.split if_splits + simp add: split_def map_gpv_conv_bind[symmetric] map_lift_spmf map'_lift_spmf)+ + by (simp add: spmf_rel_eq map_fun_def id_oracle_def split_def; + rule bind_spmf_cong[OF refl], clarsimp split!: sum.split if_splits + simp add: split_def map_gpv_conv_bind[symmetric] map_lift_spmf map'_lift_spmf)+ + done + apply simp + apply (rule WT_resource_of_oracle[OF fact2]) + by simp + qed + + ultimately show ?thesis + unfolding ideal_resource_def by simp +qed + +lemma attach_ideal: "ideal_resource = RES (fused_resource.fuse ideal_core' ideal_rest') (ideal_s_core', ideal_s_rest')" +proof - + + have fact1: "ideal_rest' = attach_rest 1\<^sub>I 1\<^sub>I id ideal_rest_alt" (is "?L = ?R") + proof - + note [simp] = spmf.map_comp map_bind_spmf bind_map_spmf bind_spmf_const o_def + + have "rinit ?L = rinit ?R" + by simp + + moreover have "rfunc_adv ?L = rfunc_adv ?R" + unfolding attach_rest_id_oracle_adv + by (simp add: extend_state_oracle_def split_def map_spmf_conv_bind_spmf) + + moreover have "rfunc_usr ?L = rfunc_usr ?R" + unfolding attach_rest_id_oracle_usr + apply (rule ext)+ + subgoal for s q by (cases q) (simp_all add: split_def extend_state_oracle_def plus_eoracle_def) + done + + ultimately show ?thesis + by (coinduction) simp + qed + + have fact2: "ideal_core' = attach_core sim_callee 1\<^sub>I ideal_core_alt" (is "?L = ?R") + proof - + + have "cpoke ?L = cpoke ?R" + by (simp add: split_def map_spmf_conv_bind_spmf) + + moreover have "cfunc_adv ?L = cfunc_adv ?R" + unfolding attach_core_def + by (simp add: split_def) + + moreover have "cfunc_usr ?L = cfunc_usr ?R" + unfolding attach_core_id_oracle_usr + by simp + + ultimately show ?thesis + by (coinduction) simp + qed + + show ?thesis + unfolding ideal_resource_alt_def Let_def + apply(subst (1 2 3) converter_of_callee_id_oracle[symmetric, of "()"]) + apply(subst attach_parallel_fuse') + by (simp add: fact1 fact2 ideal_s_core'_def ideal_s_rest'_def) +qed + +end + + +subsection \Wiring and simplifying the Real construction\ + +definition real_s_core' :: "(_ \ 'grp cstate \ 'grp cstate) \ 'grp auth.state \ 'grp auth.state" + where + "real_s_core' \ (((), CState_Void, CState_Void), (auth.State_Void, {}), (auth.State_Void, {}))" + +definition real_s_rest' + where + "real_s_rest' \ basic_rest_sinit" + +primcorec real_core' :: "((unit \ _) \ _, _, _, _, _, _) core" + where + "cpoke real_core' = (\(s_advusr, s_core) event. + map_spmf (Pair s_advusr) (parallel_handler auth.poke auth.poke s_core event))" + | "cfunc_adv real_core' = \(auth.iface_adv \\<^sub>O auth.iface_adv)" + | "cfunc_usr real_core' = (\((s_adv, s_usr), s_core) iusr. + let handle_req = lsumr \ map_sum id (rsuml \ map_sum swap_sum id \ lsumr) \ rsuml in + let handle_ret = lsumr \ (map_sum id (rsuml \ (map_sum swap_sum id \ lsumr)) \ rsuml) \ map_sum id swap_sum in + let handle_inp = map_sum id swap_sum \ (lsumr \ map_sum id (rsuml \ map_sum swap_sum id \ lsumr) \ rsuml) in + let handle_out = apfst (lsumr \ (map_sum id (rsuml \ (map_sum swap_sum id \ lsumr)) \ rsuml)) in + map_spmf + (\((ousr, s_usr'), s_core'). (ousr, (s_adv, s_usr'), s_core')) + (exec_gpv + (auth.iface_usr \\<^sub>O auth.iface_usr) + (map_gpv' + handle_out handle_inp handle_ret + ((alice_callee \\<^sub>I bob_callee) s_usr (handle_req iusr))) + s_core))" + +definition real_rest' :: "((unit \ unit) \ _, _, _, _, _, _, _) rest_scheme" + where + "real_rest' \ basic_rest" + + +subsubsection \The real attachment lemma\ + +lemma attach_real: "real_resource = 1\<^sub>C |\<^sub>= rassocl\<^sub>C \ RES (fused_resource.fuse real_core' real_rest') (real_s_core', real_s_rest')" +proof - + + have att_core: "real_core' = attach_core 1\<^sub>I + (attach_wiring parallel_wiring\<^sub>w + (attach_wiring_right (parallel_wiring\<^sub>w \\<^sub>w (id, id) |\<^sub>w swap\<^sub>w) (alice_callee \\<^sub>I bob_callee))) + (parallel_core auth.core auth.core)" (is "?L = ?R") + proof - + + have "cpoke ?L = cpoke ?R" + by simp + + moreover have "cfunc_adv ?L = cfunc_adv ?R" + unfolding attach_core_id_oracle_adv + by (simp add: extend_state_oracle_def) + + moreover have "cfunc_usr ?L = cfunc_usr ?R" + unfolding parallel_wiring\<^sub>w_def swap_lassocr\<^sub>w_def swap\<^sub>w_def lassocr\<^sub>w_def rassocl\<^sub>w_def + apply (simp add: parallel2_wiring_simps comp_wiring_simps) + apply (simp add: attach_wiring_simps attach_wiring_right_simps) + by (simp add: map_gpv_conv_map_gpv' map_gpv'_comp apfst_def) + + ultimately show ?thesis + by (coinduction) blast + qed + + have att_rest: "real_rest' = attach_rest 1\<^sub>I 1\<^sub>I id (parallel_rest auth1_rest auth2_rest)" (is "?L = ?R") + proof - + have "rinit ?L = rinit ?R" + unfolding real_rest'_def + by simp + + moreover have "rfunc_adv ?L = rfunc_adv ?R" + unfolding real_rest'_def attach_rest_id_oracle_adv + by (simp add: extend_state_oracle_def) + + moreover have "rfunc_usr ?L = rfunc_usr ?R" + unfolding real_rest'_def attach_rest_id_oracle_usr + by (simp add: extend_state_oracle_def) + + ultimately show ?thesis + by (coinduction) blast + qed + + have fact1: " + (\_full \\<^sub>\ \_full) \\<^sub>\ (\_full \\<^sub>\ \_full), (\_full \\<^sub>\ \_full) \\<^sub>\ (\_full \\<^sub>\ \_full) \\<^sub>C + CNV (alice_callee \\<^sub>I bob_callee) (CState_Void, CState_Void) \" + apply(subst conv_callee_parallel) + apply(rule WT_intro) + apply (rule WT_converter_of_callee[where \="\_full \\<^sub>\ \_full" and \'="\_full \\<^sub>\ \_full"]) + apply (rule WT_gpv_\_mono) + apply (rule WT_gpv_full) + apply (rule \_full_le_plus_\) + apply(rule order_refl) + apply(rule order_refl) + subgoal for s q + apply (cases s; cases q) + apply (auto simp add: Let_def split!: cstate.splits if_splits auth.ousr_bob.splits) + by (metis auth.ousr_bob.exhaust range_eqI) + apply (rule WT_converter_of_callee[where \="\_full \\<^sub>\ \_full" and \'="\_full \\<^sub>\ \_full"]) + apply (rule WT_gpv_\_mono) + apply (rule WT_gpv_full) + apply (rule \_full_le_plus_\) + apply(rule order_refl) + apply(rule order_refl) + subgoal for s q + apply (cases s; cases q) + apply (auto simp add: Let_def split!: cstate.splits if_splits auth.ousr_bob.splits) + by (metis auth.ousr_bob.exhaust range_eqI) + done + + + have fact2: " + (\_full \\<^sub>\ \_full) \\<^sub>\ (\_full \\<^sub>\ \_full),(\_full \\<^sub>\ \_full) \\<^sub>\ (\_full \\<^sub>\ \_full) \\<^sub>C + CNV (alice_callee \\<^sub>I bob_callee) (CState_Void, CState_Void) \ parallel_wiring \ (1\<^sub>C |\<^sub>= swap\<^sub>C) \" + apply(rule WT_intro) + apply (rule fact1) + apply(rule WT_intro)+ + done + + have fact3: " + (\_full \\<^sub>\ \_full) \\<^sub>\ (\_full \\<^sub>\ \_full),(\_full \\<^sub>\ \_full) \\<^sub>\ (\_full \\<^sub>\ \_full) \\<^sub>C + CNV (alice_callee \\<^sub>I bob_callee) (CState_Void, CState_Void) \ parallel_wiring \ (1\<^sub>C |\<^sub>= swap\<^sub>C) \ + CNV (attach_wiring_right (parallel_wiring\<^sub>w \\<^sub>w (id, id) |\<^sub>w swap\<^sub>w) (alice_callee \\<^sub>I bob_callee)) (CState_Void, CState_Void)" + apply (rule comp_converter_of_callee_wiring) + apply(rule wiring_intro)+ + apply(rule fact1) + done + + have fact4: " + (\_full \\<^sub>\ \_full) \\<^sub>\ (\_full \\<^sub>\ \_full),(\_full \\<^sub>\ \_full) \\<^sub>\ (\_full \\<^sub>\ \_full) \\<^sub>C + parallel_wiring \ CNV (alice_callee \\<^sub>I bob_callee) (CState_Void, CState_Void) \ parallel_wiring \ (1\<^sub>C |\<^sub>= swap\<^sub>C) \ + CNV (attach_wiring parallel_wiring\<^sub>w (attach_wiring_right (parallel_wiring\<^sub>w \\<^sub>w (id, id) |\<^sub>w swap\<^sub>w) (alice_callee \\<^sub>I bob_callee))) (CState_Void, CState_Void)" + apply (rule eq_\_converter_trans) + apply (rule eq_\_comp_cong) + apply(rule eq_\_converter_reflI) + apply(rule WT_intro) + apply (rule fact3) + apply (rule comp_wiring_converter_of_callee) + apply (rule wiring_intro) + apply (subst eq_\_converterD_WT[OF fact3, simplified fact2, symmetric]) + by blast + + show ?thesis + unfolding real_resource_def auth.resource_def + apply (subst resource_of_parallel_oracle[symmetric]) + apply (subst attach_compose) + apply(subst attach_wiring_resource_of_oracle) + apply (rule wiring_intro) + apply (rule WT_resource_of_oracle[where \="((\_full \\<^sub>\ \_full) \\<^sub>\ (\_full \\<^sub>\ \_full)) \\<^sub>\ ((\_full \\<^sub>\ \_full) \\<^sub>\ (\_full \\<^sub>\ \_full))"]) + subgoal for _ s + apply (rule WT_calleeI) + apply (cases s) + apply(case_tac call) + apply(rename_tac [!] x) + apply(case_tac [!] x) + apply(rename_tac [!] y) + apply(case_tac [!] y) + apply(auto simp add: fused_resource.fuse.simps) + done + apply simp + subgoal + apply (subst parallel_oracle_fuse) + apply(subst resource_of_oracle_state_iso) + apply simp + apply(simp add: parallel_state_iso_def) + apply(subst parallel_converter2_comp2_out) + apply(subst conv_callee_parallel[symmetric]) + apply(subst eq_resource_on_UNIV_iff[symmetric]) + apply(rule eq_resource_on_trans) + apply(rule eq_\_attach_on') + prefer 2 + apply (rule eq_\_comp_cong) + apply(rule eq_\_converter_reflI) + apply(rule WT_intro)+ + apply(rule parallel_converter2_eq_\_cong) + apply(rule eq_\_converter_reflI) + apply(rule WT_intro)+ + apply(rule parallel_converter2_eq_\_cong) + prefer 2 + apply(rule eq_\_converter_reflI) + apply(rule WT_intro)+ + apply(rule fact4) + prefer 3 + apply(subst attach_compose) + apply(fold converter_of_callee_id_oracle[where s="()"]) + apply(subst attach_parallel_fuse'[where f_init=id]) + apply(unfold converter_of_callee_id_oracle) + apply(subst eq_resource_on_UNIV_iff) + subgoal by (simp add: att_core[symmetric] att_rest[symmetric] real_s_core'_def real_s_rest'_def) + apply (rule WT_resource_of_oracle[where \="(\_full \\<^sub>\ \_full) \\<^sub>\ (((\_full \\<^sub>\ \_full) \\<^sub>\ (\_full \\<^sub>\ \_full)) \\<^sub>\ (\_full \\<^sub>\ \_full))"]) + subgoal for s + apply (rule WT_calleeI) + apply (cases s) + apply(case_tac call) + apply(rename_tac [!] x) + apply(case_tac [!] x) + apply(rename_tac [!] y) + apply(case_tac [!] y) + apply(rename_tac [5-6] z) + apply (case_tac [5-6] z) + apply (auto simp add: fused_resource.fuse.simps parallel_eoracle_def) + done + apply simp + done + done +qed + + +subsection \A lazy construction and its DH reduction\ + + +subsubsection \Defining a lazy construction with an inlined sampler\ + +\ \"sample triple" and "basic core" states\ +type_synonym 'grp' st_state = "('grp' \ 'grp' \ 'grp') option" +type_synonym 'grp' bc_state = "('grp' st_state \ 'grp' cstate \ 'grp' cstate) \ 'grp' auth.state \ 'grp' auth.state" + +context + fixes sample_triple :: "('grp \ 'grp \ 'grp) spmf" +begin + +abbreviation basic_core_sinit :: "'grp bc_state" + where + "basic_core_sinit \ ((None, CState_Void, CState_Void), (auth.State_Void, {}), auth.State_Void, {})" + +fun basic_core_helper_base :: "('grp bc_state, unit, unit) oracle'" + where + "basic_core_helper_base ((s_key, CState_Void, s_cnv2), (auth.State_Void, parties1), s_auth2) _ = + (if auth.Alice \ parties1 + then return_spmf ((), (s_key, CState_Half 0, s_cnv2), (auth.State_Store \, parties1), s_auth2) + else return_pmf None)" + | "basic_core_helper_base _ _ = return_pmf None" + +definition basic_core_helper :: "('grp bc_state, icnv_alice + icnv_bob) handler" + where + "basic_core_helper \ (\state query. + let handle = \((sk, (sc1, sc2)), sa1, sa2). ((sk, (sc2, sc1)), sa2, sa1) in + let func = \h_s f s. map_spmf (h_s o snd) (f (h_s s) ()) in + let func_alc = func id basic_core_helper_base in + let func_bob = func handle basic_core_helper_base in + case_sum (\_. func_alc state) (\_. func_bob state) query)" + +fun basic_core_oracle_adv :: " unit + unit \ ('grp st_state \ 'grp auth.state, 'grp auth.iadv, 'grp auth.oadv) oracle'" + where + "basic_core_oracle_adv sel (None, auth.State_Store _, parties) (Inr (Inl _)) = do { + (gxy, gx, gy) \ sample_triple; + let out = case_sum (\_. gx) (\_. gy) sel; + return_spmf (Inr (Inl (auth.Out_Look out)), Some (gxy, gx, gy), auth.State_Store \, parties) + }" + | "basic_core_oracle_adv sel (Some dhs, auth.State_Store _, parties) (Inr (Inl _)) = + (case dhs of (gxy, gx, gy) \ + let out = case_sum (\_. gx) (\_. gy) sel in + return_spmf (Inr (Inl (auth.Out_Look out)), Some dhs, auth.State_Store \, parties))" + | "basic_core_oracle_adv _ (s_key, auth.State_Store _, parties) (Inr (Inr _)) = + return_spmf (Inr (Inr auth.Out_Fedit), s_key, auth.State_Collect \, parties)" + | "basic_core_oracle_adv _ _ _ = return_pmf None" + + +fun basic_core_oracle_usr_base :: "('grp bc_state, unit, 'grp) oracle'" + where + "basic_core_oracle_usr_base ((s_key, CState_Half _, s_cnv2), s_auth1, auth.State_Collect _, parties2) _ = + (let h_state = \k. ((Some k, CState_Full (0, \), s_cnv2), s_auth1, auth.State_Collected, parties2) in + if auth.Bob \ parties2 then + (case s_key of + None \ do { + (gxy, gx, gy) \ sample_triple; + return_spmf (gxy, h_state (gxy, gx, gy)) } + | Some (gxy, gx, gy) \ return_spmf (gxy, h_state (gxy, gx, gy))) + else return_pmf None)" + | "basic_core_oracle_usr_base ((Some dhs, CState_Full _, s_cnv2), s_auth1, auth.State_Collected, parties2) _ = + (case dhs of (gxy, gx, gy) \ + return_spmf (gxy, (Some dhs, CState_Full (0, \), s_cnv2), s_auth1, auth.State_Collected, parties2))" + | "basic_core_oracle_usr_base _ _ = return_pmf None" + +definition basic_core_oracle_usr :: "(_, key.iusr_alice + key.iusr_bob, _) oracle'" + where + "basic_core_oracle_usr \ (\state query. + let handle = \((sk, (sc1, sc2)), sa1, sa2). ((sk, (sc2, sc1)), sa2, sa1) in + let func = \h_o h_s f s. map_spmf (map_prod h_o h_s) (f (h_s s) ()) in + let func_alc = func (Inl o key.Out_Alice) id basic_core_oracle_usr_base in + let func_bob = func (Inr o key.Out_Bob) handle basic_core_oracle_usr_base in + case_sum (\_. func_alc state) (\_. func_bob state) query)" + +primcorec basic_core + where + "cpoke basic_core = (\(s_other, s_core) event. + map_spmf (Pair s_other) (parallel_handler auth.poke auth.poke s_core event))" + | "cfunc_adv basic_core = (\((s_key, s_cnv), s_auth1, s_auth2) iadv. + let handle = (\sel s_init h_out h_state query. + map_spmf + (\(out, (s_key', s_auth')). (h_out out, (s_key', s_cnv), h_state s_auth' s_auth1 s_auth2)) + (basic_core_oracle_adv sel (s_key, s_init) query)) in + case_sum (handle (Inl ()) s_auth1 Inl (\x y z. (x, z))) (handle (Inr ()) s_auth2 Inr (\x y z. (y, x))) iadv)" + | "cfunc_usr basic_core = + (let handle = map_sum (\_. Out_Activation_Alice) (\_. Out_Activation_Bob) in + basic_core_oracle_usr \\<^sub>O (\s q. map_spmf (Pair (handle q)) (basic_core_helper s q)))" + +primcorec lazy_core + where + "cpoke lazy_core = (\s. case_sum (\q. basic_core_helper s q) (cpoke basic_core s))" + | "cfunc_adv lazy_core = cfunc_adv basic_core " + | "cfunc_usr lazy_core = basic_core_oracle_usr" + +definition lazy_rest + where + "lazy_rest \ ideal_rest'" + +end + + +subsubsection \Defining a lazy construction with an external sampler\ + +context +begin + +private type_synonym ('grp', 'iadv_rest', 'iusr_rest') dh_inp = " + (('grp' auth.iadv + 'grp' auth.iadv) + 'iadv_rest') + (key.iusr_alice + key.iusr_bob) + (icnv_alice + icnv_bob) + 'iusr_rest'" + +private type_synonym ('grp', 'oadv_rest', 'ousr_rest') dh_out = " + (('grp' auth.oadv + 'grp' auth.oadv) + 'oadv_rest') + ('grp' key.ousr_alice + 'grp' key.ousr_bob) + (ocnv_alice + ocnv_bob) + 'ousr_rest'" + +fun interceptor_base_look :: " unit + unit \ 'grp st_state \ 'grp auth.state + \ ('grp auth.oadv_look \ 'grp st_state, unit, 'grp \ 'grp \ 'grp) gpv" + where + "interceptor_base_look sel (None, auth.State_Store _, parties) = do { + (gxy, gx, gy) \ Pause () Done; + let out = case_sum (\_. gx) (\_. gy) sel; + Done (auth.Out_Look out, Some (gxy, gx, gy)) }" + | "interceptor_base_look sel (Some dhs, auth.State_Store _, parties) = ( + case dhs of (gxy, gx, gy) \ + let out = case_sum (\_. gx) (\_. gy) sel in + Done (auth.Out_Look out, Some (gxy, gx, gy)))" + | "interceptor_base_look _ _ = Fail" + +fun interceptor_base_recv :: "'grp bc_state \ ('grp \ 'grp bc_state, unit, 'grp \ 'grp \ 'grp) gpv" + where + "interceptor_base_recv ((s_key, CState_Half _, s_cnv2), s_auth1, auth.State_Collect _, parties2) = ( + let h_state = \k. ((Some k, CState_Full (0, \), s_cnv2), s_auth1, auth.State_Collected, parties2) in + if auth.Bob \ parties2 then + case s_key of + None \ do { + (gxy, gx, gy) \ Pause () Done; + Done (gxy, h_state (gxy, gx, gy)) } + | Some (gxy, gx, gy) \ Done (gxy, h_state (gxy, gx, gy)) + else + Fail)" + | "interceptor_base_recv ((Some dhs, CState_Full _, s_cnv2), s_auth1, auth.State_Collected, parties2) = ( + case dhs of (gxy, gx, gy) \ + Done (gxy, (Some dhs, CState_Full (0, \), s_cnv2), s_auth1, auth.State_Collected, parties2))" + | "interceptor_base_recv _ = Fail" + +fun interceptor :: " _ \ (_, _, _) dh_inp \ (('grp, _, _) dh_out \ _, unit, 'grp \ 'grp \ 'grp) gpv" + where + "interceptor (sc, sr) (Inl (Inl (q))) = ( + let select_s = (case sc of ((sk, _), sa1, sa2) \ case_sum (\_. (sk, sa1)) (\_. (sk, sa2))) in + let handle_s = (\x. case sc of ((sk, (sc1, sc2)), sa1, sa2) \ ((x, (sc1, sc2)), sa1, sa2)) in + let func_look = (\sel h_o. do { + (o_look, dhs) \ interceptor_base_look (sel ()) (select_s (sel ())) ; + Done (Inl (Inl (h_o (Inr (Inl o_look)))), handle_s dhs, sr) }) in + let func_dfe = do { + (out, sc') \ lift_spmf (cfunc_adv (lazy_core undefined) sc q); + Done (Inl (Inl out), sc', sr) } in + case q of + (Inl (Inr (Inl _))) \ func_look Inl Inl + | (Inr (Inr (Inl _))) \ func_look Inr Inr + | _ \ func_dfe)" + | "interceptor (sc, sr) (Inl (Inr (q))) = do { + ((out, es), sr') \ lift_spmf (rfunc_adv lazy_rest sr q); + sc' \ lift_spmf (foldl_spmf (\a e. cpoke (lazy_core undefined) a e) (return_spmf sc) es); + Done (Inl (Inr out), (sc', sr')) }" + | "interceptor (sc, sr) (Inr (Inl (q))) = ( + let handle = \((sk, (sc1, sc2)), sa1, sa2). ((sk, (sc2, sc1)), sa2, sa1) in + let func_recv = (\h_o h_s. do { + (o_recv, sc') \ interceptor_base_recv (h_s sc); + Done (Inr (Inl (h_o o_recv)), h_s sc', sr) }) in + case_sum (\_. func_recv (Inl o key.Out_Alice) id) (\_. func_recv (Inr o key.Out_Bob) handle) q)" + | "interceptor (sc, sr) (Inr (Inr (q))) = do { + ((out, es), sr') \ lift_spmf (rfunc_usr lazy_rest sr q); + sc' \ lift_spmf (foldl_spmf (\a e. cpoke (lazy_core undefined) a e) (return_spmf sc) es); + Done (Inr (Inr out), (sc', sr')) }" + +end + + +subsubsection \Reduction to Diffie-Hellman game\ + +definition DH0_sample :: "('grp \ 'grp \ 'grp) spmf" + where + "DH0_sample = do { + x \ sample_uniform (order \); + y \ sample_uniform (order \); + return_spmf ((\<^bold>g [^] x) [^] y, \<^bold>g [^] x, \<^bold>g [^] y) }" + +definition DH1_sample :: "('grp \ 'grp \ 'grp) spmf" + where + "DH1_sample = do { + x \ sample_uniform (order \); + y \ sample_uniform (order \); + z \ sample_uniform (order \); + return_spmf (\<^bold>g [^] z, \<^bold>g [^] x, \<^bold>g [^] y) }" + +lemma lossless_DH0_sample [simp]: "lossless_spmf DH0_sample" + by (auto simp add: DH0_sample_def sample_uniform_def intro: order_gt_0) + +lemma lossless_DH1_sample [simp]: "lossless_spmf DH1_sample" + by (auto simp add: DH1_sample_def sample_uniform_def intro: order_gt_0) + +definition DH_adversary_curry :: "('grp \ 'grp \ 'grp \ bool spmf) \ 'grp \ 'grp \ 'grp \ bool spmf" + where + "DH_adversary_curry \ (\A x y z. bind_spmf (return_spmf (z, x, y)) A)" + +definition DH_adversary + where + "DH_adversary D \ DH_adversary_curry (\xyz. + run_gpv (obsf_oracle (obsf_oracle (\(tpl, s) q. map_spmf (apsnd (Pair tpl) \ fst) (exec_gpv (\_ _. return_spmf (tpl, ())) (interceptor s q) ())))) + (obsf_distinguisher D) (OK (OK (xyz, basic_core_sinit, basic_rest_sinit))))" + +context +begin + +private abbreviation "S_ic_asm s_cnv1 s_cnv2 s_krn1 s_krn2 \ + let s_cnvs = {CState_Void} \ {CState_Half 0} \ {CState_Full (0, \)} in + let s_krns = {auth.State_Void} \ {auth.State_Store \} \ {auth.State_Collect \} \ {auth.State_Collected} in + s_cnv1 \ s_cnvs \ s_cnv2 \ s_cnvs \ s_krn1 \ s_krns \ s_krn2 \ s_krns" + +private inductive S_ic :: "('grp \ 'grp \ 'grp) spmf \ ('grp bc_state \ (unit \ unit) \ 'auth1_s_rest \ 'auth2_s_rest) spmf \ + (('grp \ 'grp \ 'grp) \ 'grp bc_state \ (unit \ unit) \ 'auth1_s_rest \ 'auth2_s_rest) spmf \ bool" + for \ :: "('grp \ 'grp \ 'grp) spmf" where + "S_ic \ (return_spmf (((None, s_cnv1, s_cnv2), (s_krn1, s_act1), s_krn2, s_act2), ((), ()), s_rest1, s_rest2)) + (map_spmf (\x. (x, (((None, s_cnv1, s_cnv2), (s_krn1, s_act1), s_krn2, s_act2), ((), ()), s_rest1, s_rest2))) \)" + if "S_ic_asm s_cnv1 s_cnv2 s_krn1 s_krn2" + | "S_ic \ (return_spmf (((Some x, s_cnv1, s_cnv2), (s_krn1, s_act1), s_krn2, s_act2), ((), ()), s_rest1, s_rest2)) + (return_spmf (x, (((Some x, s_cnv1, s_cnv2), (s_krn1, s_act1), s_krn2, s_act2), ((), ()), s_rest1, s_rest2)))" + if "S_ic_asm s_cnv1 s_cnv2 s_krn1 s_krn2" + +private lemma trace_eq_intercept: + defines "outs_adv \ ((UNIV <+> UNIV <+> UNIV) <+> UNIV <+> UNIV <+> UNIV) <+> UNIV <+> UNIV" + and "outs_usr \ (UNIV <+> UNIV) <+> (UNIV <+> UNIV) <+> UNIV <+> UNIV" + assumes "lossless_spmf sample_triple" + shows "trace_callee_eq (fused_resource.fuse (lazy_core sample_triple) lazy_rest) + (\(tpl, s) q. map_spmf (apsnd (Pair tpl) \ fst) (exec_gpv (\_ _. return_spmf (tpl, ())) (interceptor s q) ())) + (outs_adv <+> outs_usr) + (return_spmf (basic_core_sinit, basic_rest_sinit)) (pair_spmf sample_triple (return_spmf (basic_core_sinit, basic_rest_sinit)))" + (is "trace_callee_eq ?L ?R ?OI ?sl ?sr") +proof - + have auth_poke_alt[simplified split_def Let_def]: + "auth.poke = (\(sl, sr) q. let p = auth.case_event id q in + map_spmf (Pair sl) (if p \ sr then return_pmf None else return_spmf (insert p sr)))" + by (rule ext)+ (simp add: split_def Let_def split!: auth.event.splits) + + note S_ic_cases = S_ic.cases[where \=sample_triple, simplified] + note S_ic_intros = S_ic.intros[where \=sample_triple, simplified] + + note [simp] = assms(3)[unfolded lossless_spmf_def] mk_lossless_lossless[OF assms(3)] + fused_resource.fuse.simps lazy_rest_def basic_core_oracle_usr_def basic_core_helper_def + exec_gpv_bind spmf.map_comp map_bind_spmf bind_map_spmf bind_spmf_const o_def Let_def split_def + extend_state_oracle_def plus_eoracle_def parallel_eoracle_def map_fun_def + + have "trace_callee_eq ?L ?R ?OI ?sl ?sr" + unfolding assms(1,2) apply (rule trace'_eqI_sim_upto[where S="S_ic sample_triple"]) + subgoal Init_OK + by (simp add: map_spmf_conv_bind_spmf[symmetric] pair_spmf_alt_def S_ic_intros) + subgoal Out_OK for sl sr q + apply (cases q) + subgoal for q_adv + apply (cases q_adv) + subgoal for q_adv_core + apply (cases q_adv_core) + subgoal for q_acore1 + apply (cases q_acore1) + subgoal for q_drop by (erule S_ic_cases) simp_all + subgoal for q_lfe + apply (cases q_lfe) + subgoal for q_look + apply (erule S_ic_cases) + subgoal for s_cnv1 s_cnv2 s_krn1 s_krn2 s_act1 s_act2 s_rest1 s_rest2 + by (simp, case_tac "(Inl (), (None, s_krn1, s_act1))" rule: interceptor_base_look.cases) auto + subgoal for s_cnv1 s_cnv2 s_krn1 s_krn2 x s_act1 s_act2 s_rest1 s_rest2 + by (simp, case_tac "(Inl (), (Some x, s_krn1, s_act1))" rule: interceptor_base_look.cases) auto + done + subgoal for q_fedit + apply (erule S_ic_cases) + subgoal for s_cnv1 s_cnv2 s_krn1 s_krn2 s_act1 s_act2 s_rest1 s_rest2 + by (simp, case_tac "(Inl (), (None, s_krn1, s_act1), Inr (Inr q_fedit))" rule: basic_core_oracle_adv.cases) simp_all + subgoal for s_cnv1 s_cnv2 s_krn1 s_krn2 x s_act1 s_act2 s_rest1 s_rest2 + by (simp, case_tac "(Inl (), (Some x, s_krn1, s_act1), Inr (Inr q_fedit))" rule: basic_core_oracle_adv.cases) simp_all + done + done + done + subgoal for q_acore2 + apply (cases q_acore2) + subgoal for q_drop by (erule S_ic_cases) simp_all + subgoal for q_lfe + apply (cases q_lfe) + subgoal for q_look + apply (erule S_ic_cases) + subgoal for s_cnv1 s_cnv2 s_krn1 s_krn2 s_act1 s_act2 s_rest1 s_rest2 + by (simp, case_tac "(Inr (), (None, s_krn2, s_act2))" rule: interceptor_base_look.cases) auto + subgoal for s_cnv1 s_cnv2 s_krn1 s_krn2 x s_act1 s_act2 s_rest1 s_rest2 + by (simp, case_tac "(Inr (), (Some x, s_krn2, s_act2))" rule: interceptor_base_look.cases) auto + done + subgoal for q_fedit + apply (erule S_ic_cases) + subgoal for s_cnv1 s_cnv2 s_krn1 s_krn2 s_act1 s_act2 s_rest1 s_rest2 + by (simp, case_tac "(Inr (), (None, s_krn2, s_act2), Inr (Inr q_fedit))" rule: basic_core_oracle_adv.cases) simp_all + subgoal for s_cnv1 s_cnv2 s_krn1 s_krn2 x s_act1 s_act2 s_rest1 s_rest2 + by (simp, case_tac "(Inr (), (Some x, s_krn2, s_act2), Inr (Inr q_fedit))" rule: basic_core_oracle_adv.cases) simp_all + done + done + done + done + subgoal for q_adv_rest + apply (cases q_adv_rest) + subgoal for q_arest1 by (erule S_ic_cases) simp_all + subgoal for q_arest2 by (erule S_ic_cases) simp_all + done + done + subgoal for q_usr + apply (cases q_usr) + subgoal for q_usr_core + apply (cases q_usr_core) + subgoal for q_alice + apply (erule S_ic_cases) + subgoal for s_cnv1 s_cnv2 s_krn1 s_krn2 s_act1 s_act2 s_rest1 s_rest2 + by (simp, case_tac "(((None, s_cnv1, s_cnv2), (s_krn1, s_act1), s_krn2, s_act2), ())" rule: basic_core_oracle_usr_base.cases) (auto split: option.splits) + subgoal for s_cnv1 s_cnv2 s_krn1 s_krn2 x s_act1 s_act2 s_rest1 s_rest2 + by (simp, case_tac "(((Some x, s_cnv1, s_cnv2), (s_krn1, s_act1), s_krn2, s_act2), ())" rule: basic_core_oracle_usr_base.cases) (auto split: option.splits) + done + subgoal for q_bob + apply (erule S_ic_cases) + subgoal for s_cnv1 s_cnv2 s_krn1 s_krn2 s_act1 s_act2 s_rest1 s_rest2 + by (simp, case_tac "(((None, s_cnv2, s_cnv1), (s_krn2, s_act2), s_krn1, s_act1), ())" rule: basic_core_oracle_usr_base.cases) (auto split: option.splits) + subgoal for s_cnv1 s_cnv2 s_krn1 s_krn2 x s_act1 s_act2 s_rest1 s_rest2 + by (simp, case_tac "(((Some x, s_cnv2, s_cnv1), (s_krn2, s_act2), s_krn1, s_act1), ())" rule: basic_core_oracle_usr_base.cases) (auto split: option.splits) + done + done + subgoal for q_usr_rest + apply (cases q_usr_rest) + subgoal for q_act + apply (cases q_act) + subgoal for a_alice by (erule S_ic_cases) simp_all + subgoal for a_bob by (erule S_ic_cases) simp_all + done + subgoal for q_urest + apply (cases q_urest) + subgoal for q_urest1 by (erule S_ic_cases) simp_all + subgoal for q_urest2 by (erule S_ic_cases) simp_all + done + done + done + done + subgoal State_OK for sl sr q + apply (cases q) + subgoal for q_adv + apply (cases q_adv) + subgoal for q_adv_core + apply (cases q_adv_core) + subgoal for q_acore1 + apply (cases q_acore1) + subgoal for q_drop by (erule S_ic_cases) simp_all + subgoal for q_lfe + apply (cases q_lfe) + subgoal for q_look + apply (erule S_ic_cases) + subgoal for s_cnv1 s_cnv2 s_krn1 s_krn2 s_act1 s_act2 s_rest1 s_rest2 + apply (simp, case_tac "(Inl (), (None, s_krn1, s_act1))" rule: interceptor_base_look.cases) + apply (simp_all add: map_spmf_conv_bind_spmf[symmetric]) + by (auto simp add: map_spmf_conv_bind_spmf[symmetric] cond_spmf_fst_def vimage_def intro!: trace_eq_simcl_map S_ic_intros) + subgoal for s_cnv1 s_cnv2 s_krn1 s_krn2 x s_act1 s_act2 s_rest1 s_rest2 + apply (simp, case_tac "(Inl (), (Some x, s_krn1, s_act1))" rule: interceptor_base_look.cases) + by (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro!: S_ic_intros) + done + subgoal for q_fedit + apply (erule S_ic_cases) + subgoal for s_cnv1 s_cnv2 s_krn1 s_krn2 s_act1 s_act2 s_rest1 s_rest2 + by (simp, case_tac "(Inl (), (None, s_krn1, s_act1), Inr (Inr q_fedit))" rule: basic_core_oracle_adv.cases) + (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro!: trace_eq_simcl.base S_ic_intros) + subgoal for s_cnv1 s_cnv2 s_krn1 s_krn2 x s_act1 s_act2 s_rest1 s_rest2 + by (simp, case_tac "(Inl (), (Some x, s_krn1, s_act1), Inr (Inr q_fedit))" rule: basic_core_oracle_adv.cases) + (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro!: trace_eq_simcl.base S_ic_intros) + done + done + done + subgoal for q_acore2 + apply (cases q_acore2) + subgoal for q_drop by (erule S_ic_cases) simp_all + subgoal for q_lfe + apply (cases q_lfe) + subgoal for q_look + apply (erule S_ic_cases) + subgoal for s_cnv1 s_cnv2 s_krn1 s_krn2 s_act1 s_act2 s_rest1 s_rest2 + apply (simp, case_tac "(Inr (), (None, s_krn2, s_act2))" rule: interceptor_base_look.cases) + apply (simp_all add: map_spmf_conv_bind_spmf[symmetric]) + by (auto simp add: map_spmf_conv_bind_spmf[symmetric] cond_spmf_fst_def vimage_def intro!: trace_eq_simcl_map S_ic_intros) + subgoal for s_cnv1 s_cnv2 s_krn1 s_krn2 x s_act1 s_act2 s_rest1 s_rest2 + apply (simp, case_tac "(Inr (), (Some x, s_krn2, s_act2))" rule: interceptor_base_look.cases) + by (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro!: S_ic_intros) + done + subgoal for q_fedit + apply (erule S_ic_cases) + subgoal for s_cnv1 s_cnv2 s_krn1 s_krn2 s_act1 s_act2 s_rest1 s_rest2 + by (simp, case_tac "(Inr (), (None, s_krn2, s_act2), Inr (Inr q_fedit))" rule: basic_core_oracle_adv.cases) + (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro!: trace_eq_simcl.base S_ic_intros) + subgoal for s_cnv1 s_cnv2 s_krn1 s_krn2 x s_act1 s_act2 s_rest1 s_rest2 + by (simp, case_tac "(Inr (), (Some x, s_krn2, s_act2), Inr (Inr q_fedit))" rule: basic_core_oracle_adv.cases) + (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro!: trace_eq_simcl.base S_ic_intros) + done + done + done + done + subgoal for q_adv_rest + apply (cases q_adv_rest) + subgoal for q_urest1 + apply (erule S_ic_cases) + subgoal + apply clarsimp + apply (subst bind_commute_spmf) + apply (subst (2) bind_commute_spmf) + apply (subst (1 2) cond_spmf_fst_bind) + apply (subst (1 2) cond_spmf_fst_bind) + apply (clarsimp intro!: trace_eq_simcl_bind simp add: auth_poke_alt set_scale_spmf split: if_split_asm) + apply (subst (asm) (1 2 3 4) foldl_spmf_helper2[where acc="return_spmf _" and q="\(_, (_, x), _). x" + and p="\(a, (b, _), d). (a, b, d)" and f="\(a, b, d) c. (a, (b, c), d)", simplified]) + by (clarsimp simp add: map_spmf_conv_bind_spmf[symmetric] intro!: trace_eq_simcl.base S_ic_intros) + subgoal + apply clarsimp + apply (subst (1 2) cond_spmf_fst_bind) + apply (subst (1 2) cond_spmf_fst_bind) + apply (clarsimp intro!: trace_eq_simcl_bind simp add: auth_poke_alt set_scale_spmf split: if_split_asm) + apply (subst (asm) (1 2 3 4) foldl_spmf_helper2[where acc="return_spmf _" and q="\(_, (_, x), _). x" + and p="\(a, (b, _), d). (a, b, d)" and f="\(a, b, d) c. (a, (b, c), d)", simplified]) + by (clarsimp simp add: map_spmf_conv_bind_spmf[symmetric] intro!: S_ic_intros) + done + subgoal for q_urest2 + apply (erule S_ic_cases) + subgoal + apply clarsimp + apply (subst bind_commute_spmf) + apply (subst (2) bind_commute_spmf) + apply (subst (1 2) cond_spmf_fst_bind) + apply (subst (1 2) cond_spmf_fst_bind) + apply (clarsimp intro!: trace_eq_simcl_bind simp add: auth_poke_alt set_scale_spmf split: if_split_asm) + apply (subst (asm) (1 2 3 4) foldl_spmf_helper2[where acc="return_spmf _" and q="\(_, _, _, x). x" + and p="\(a, b, c, _). (a, b, c)" and f="\(a, b, c) d. (a, b, c, d)", simplified]) + by (clarsimp simp add: map_spmf_conv_bind_spmf[symmetric] intro!: trace_eq_simcl.base S_ic_intros) + subgoal + apply clarsimp + apply (subst (1 2) cond_spmf_fst_bind) + apply (subst (1 2) cond_spmf_fst_bind) + apply (clarsimp intro!: trace_eq_simcl_bind simp add: auth_poke_alt set_scale_spmf split: if_split_asm) + apply (subst (asm) (1 2 3 4) foldl_spmf_helper2[where acc="return_spmf _" and q="\(_, _, _, x). x" + and p="\(a, b, c, _). (a, b, c)" and f="\(a, b, c) d. (a, b, c, d)", simplified]) + by (clarsimp simp add: map_spmf_conv_bind_spmf[symmetric] intro!: S_ic_intros) + done + done + done + subgoal for q_usr + apply (cases q_usr) + subgoal for q_usr_core + apply (cases q_usr_core) + subgoal for q_alice + apply (erule S_ic_cases) + subgoal for s_cnv1 s_cnv2 s_krn1 s_krn2 s_act1 s_act2 s_rest1 s_rest2 + apply (simp, case_tac "(((None, s_cnv1, s_cnv2), (s_krn1, s_act1), s_krn2, s_act2), ())" rule: basic_core_oracle_usr_base.cases) + proof (goal_cases) + case (1 s_key _ s_cnv2 s_auth1 _ parties2 _) + then show ?case by (auto simp add: map_spmf_conv_bind_spmf[symmetric] cond_spmf_fst_def vimage_def intro!: trace_eq_simcl_map S_ic_intros) + qed (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro!: trace_eq_simcl.base S_ic_intros) + subgoal for s_cnv1 s_cnv2 s_krn1 s_krn2 x s_act1 s_act2 s_rest1 s_rest2 + apply (simp, case_tac "(((Some x, s_cnv1, s_cnv2), (s_krn1, s_act1), s_krn2, s_act2), ())" rule: basic_core_oracle_usr_base.cases) + by (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro!: trace_eq_simcl.base S_ic_intros) + done + subgoal for q_bob + apply (erule S_ic_cases) + subgoal for s_cnv1 s_cnv2 s_krn1 s_krn2 s_act1 s_act2 s_rest1 s_rest2 + apply (simp, case_tac "(((None, s_cnv2, s_cnv1), (s_krn2, s_act2), s_krn1, s_act1), ())" rule: basic_core_oracle_usr_base.cases) + proof (goal_cases) + case (1 s_key _ s_cnv2 s_auth1 _ parties2 _) + then show ?case by (auto simp add: map_spmf_conv_bind_spmf[symmetric] cond_spmf_fst_def vimage_def intro!: trace_eq_simcl_map S_ic_intros) + qed (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro!: trace_eq_simcl.base S_ic_intros) + subgoal for s_cnv1 s_cnv2 s_krn1 s_krn2 x s_act1 s_act2 s_rest1 s_rest2 + apply (simp, case_tac "(((Some x, s_cnv2, s_cnv1), (s_krn2, s_act2), s_krn1, s_act1), ())" rule: basic_core_oracle_usr_base.cases) + by (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro!: trace_eq_simcl.base S_ic_intros) + done + done + subgoal for q_usr_rest + apply (cases q_usr_rest) + subgoal for q_act + apply (cases q_act) + subgoal for a_alice + apply (erule S_ic_cases) + subgoal for s_cnv1 s_cnv2 s_krn1 s_krn2 s_act1 s_act2 s_rest1 s_rest2 + apply (simp, case_tac "(((None, s_cnv1, s_cnv2), (s_krn1, s_act1), s_krn2, s_act2), ())" rule: basic_core_helper_base.cases) + by (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro!: trace_eq_simcl.base S_ic_intros) + subgoal for s_cnv1 s_cnv2 s_krn1 s_krn2 x s_act1 s_act2 s_rest1 s_rest2 + apply (simp, case_tac "(((Some x, s_cnv1, s_cnv2), (s_krn1, s_act1), s_krn2, s_act2), ())" rule: basic_core_helper_base.cases) + by (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro!: trace_eq_simcl.base S_ic_intros) + done + subgoal for a_bob + apply (erule S_ic_cases) + subgoal for s_cnv1 s_cnv2 s_krn1 s_krn2 s_act1 s_act2 s_rest1 s_rest2 + apply (simp, case_tac "(((None, s_cnv2, s_cnv1), (s_krn2, s_act2), s_krn1, s_act1), ())" rule: basic_core_helper_base.cases) + by (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro!: trace_eq_simcl.base S_ic_intros) + subgoal for s_cnv1 s_cnv2 s_krn1 s_krn2 x s_act1 s_act2 s_rest1 s_rest2 + apply (simp, case_tac "(((Some x, s_cnv2, s_cnv1), (s_krn2, s_act2), s_krn1, s_act1), ())" rule: basic_core_helper_base.cases) + by (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro!: trace_eq_simcl.base S_ic_intros) + done + done + subgoal for q_urest + apply (cases q_urest) + subgoal for q_urest1 + apply (erule S_ic_cases) + subgoal + apply clarsimp + apply (subst bind_commute_spmf) + apply (subst (2) bind_commute_spmf) + apply (subst (1 2) cond_spmf_fst_bind) + apply (subst (1 2) cond_spmf_fst_bind) + apply (clarsimp intro!: trace_eq_simcl_bind simp add: auth_poke_alt set_scale_spmf split: if_split_asm) + apply (subst (asm) (1 2 3 4) foldl_spmf_helper2[where acc="return_spmf _" and q="\(_, (_, x), _). x" + and p="\(a, (b, _), d). (a, b, d)" and f="\(a, b, d) c. (a, (b, c), d)", simplified]) + by (clarsimp simp add: map_spmf_conv_bind_spmf[symmetric] intro!: trace_eq_simcl.base S_ic_intros) + subgoal + apply clarsimp + apply (subst (1 2) cond_spmf_fst_bind) + apply (subst (1 2) cond_spmf_fst_bind) + apply (clarsimp intro!: trace_eq_simcl_bind simp add: auth_poke_alt set_scale_spmf split: if_split_asm) + apply (subst (asm) (1 2 3 4) foldl_spmf_helper2[where acc="return_spmf _" and q="\(_, (_, x), _). x" + and p="\(a, (b, _), d). (a, b, d)" and f="\(a, b, d) c. (a, (b, c), d)", simplified]) + by (clarsimp simp add: map_spmf_conv_bind_spmf[symmetric] intro!: S_ic_intros) + done + subgoal for q_urest2 + apply (erule S_ic_cases) + subgoal + apply clarsimp + apply (subst bind_commute_spmf) + apply (subst (2) bind_commute_spmf) + apply (subst (1 2) cond_spmf_fst_bind) + apply (subst (1 2) cond_spmf_fst_bind) + apply (clarsimp intro!: trace_eq_simcl_bind simp add: auth_poke_alt set_scale_spmf split: if_split_asm) + apply (subst (asm) (1 2 3 4) foldl_spmf_helper2[where acc="return_spmf _" and q="\(_, _, _, x). x" + and p="\(a, b, c, _). (a, b, c)" and f="\(a, b, c) d. (a, b, c, d)", simplified]) + by (clarsimp simp add: map_spmf_conv_bind_spmf[symmetric] intro!: trace_eq_simcl.base S_ic_intros) + subgoal + apply clarsimp + apply (subst (1 2) cond_spmf_fst_bind) + apply (subst (1 2) cond_spmf_fst_bind) + apply (clarsimp intro!: trace_eq_simcl_bind simp add: auth_poke_alt set_scale_spmf split: if_split_asm) + apply (subst (asm) (1 2 3 4) foldl_spmf_helper2[where acc="return_spmf _" and q="\(_, _, _, x). x" + and p="\(a, b, c, _). (a, b, c)" and f="\(a, b, c) d. (a, b, c, d)", simplified]) + by (clarsimp simp add: map_spmf_conv_bind_spmf[symmetric] intro!: S_ic_intros) + done + done + done + done + done + done + + then show ?thesis by simp +qed + +private abbreviation "dummy x \ TRY map_spmf OK x ELSE return_spmf Fault" + +lemma reduction: "advantage D (obsf_resource (RES (fused_resource.fuse (lazy_core DH1_sample) lazy_rest) (basic_core_sinit, basic_rest_sinit))) + (obsf_resource (RES (fused_resource.fuse (lazy_core DH0_sample) lazy_rest) (basic_core_sinit, basic_rest_sinit))) = ddh.advantage \ (DH_adversary D)" +proof - + have fact1: "bind_spmf (DH0_sample) A = do { + x \ sample_uniform (order \); + y \ sample_uniform (order \); + (DH_adversary_curry A) (\<^bold>g [^] x) (\<^bold>g [^] y) (\<^bold>g [^] (x * y)) + }" for A by (simp add: DH0_sample_def DH_adversary_curry_def nat_pow_pow) + + have fact2: "bind_spmf DH1_sample A = do { + x \ sample_uniform (order \); + y \ sample_uniform (order \); + z \ sample_uniform (order \); + (DH_adversary_curry A) (\<^bold>g [^] x) (\<^bold>g [^] y) (\<^bold>g [^] (z)) + }" for A by (simp add: DH1_sample_def DH_adversary_curry_def) + + { + fix sample_triple :: "('grp \ 'grp \ 'grp) spmf" + assume *: "lossless_spmf sample_triple" + define s_init where "s_init \ (basic_core_sinit, basic_rest_sinit)" + have [unfolded s_init_def, simp]: "dummy (dummy (return_spmf s_init)) = return_spmf (OK (OK s_init))" by auto + have [unfolded s_init_def, simp]: "dummy (dummy (pair_spmf sample_triple (return_spmf s_init))) = + map_spmf (OK \ OK) (pair_spmf sample_triple (return_spmf s_init))" + using * by (simp add: o_def map_spmf_conv_bind_spmf pair_spmf_alt_def) + + have "connect D (RES (obsf_oracle (obsf_oracle (fused_resource.fuse (lazy_core sample_triple) lazy_rest))) (OK (OK (basic_core_sinit, basic_rest_sinit)))) = + bind_spmf (map_spmf (OK o OK) (pair_spmf sample_triple (return_spmf (basic_core_sinit, basic_rest_sinit)))) + (run_gpv (obsf_oracle (obsf_oracle (\(tpl, s) q. map_spmf ((apsnd (Pair tpl)) o fst) (exec_gpv (\_ _. return_spmf (tpl, ())) (interceptor s q) ())))) D)" for D + apply (simp add: connect_def exec_gpv_resource_of_oracle spmf.map_comp) + apply (subst return_bind_spmf[where x="OK (OK (basic_core_sinit, basic_rest_sinit))", symmetric]) + apply (rule trace_callee_eq_run_gpv[where ?I1.0="(\_. True)" and ?I2.0="(\_. True)" and \=\_full and A=UNIV]) + subgoal by (rule trace_eq_intercept[OF *, THEN trace_callee_eq_obsf_oracleI, THEN trace_callee_eq_obsf_oracleI, simplified]) + by (simp_all add: * pair_spmf_alt_def) + } note detach_sampler = this + + show ?thesis + unfolding advantage_def + apply (subst (1 2) spmf_obsf_distinguisher_obsf_resource_True[symmetric]) + apply (subst (1 2) obsf_resource_of_oracle)+ + by (simp add: detach_sampler pair_spmf_alt_def bind_map_spmf fact1 fact2) + (simp add: ddh.advantage_def ddh.ddh_0_def ddh.ddh_1_def DH_adversary_def) +qed + +end + + +subsection \Proving the trace-equivalence of simplified Ideal and Lazy constructions\ + +context +begin + +private abbreviation "isample_nat \ sample_uniform (order \)" +private abbreviation "isample_key \ spmf_of_set (carrier \)" +private abbreviation "isample_pair_nn \ pair_spmf isample_nat isample_nat" +private abbreviation "isample_pair_nk \ pair_spmf isample_nat isample_key" + +private inductive S_il :: "(('grp astate \ unit) \ estate \ 'grp key.state) spmf \ 'grp bc_state spmf \ bool" + where +\ \(Auth1 =a)@(Auth2 =0)\ + sil_0_0: "S_il (return_spmf ((None, ()), (False, (EState_Void, s_act1), EState_Void, s_act2), key.PState_Store, {})) + (return_spmf ((None, CState_Void, CState_Void), (auth.State_Void, s_act1), auth.State_Void, s_act2))" +\ \../(Auth1 =a)@(Auth2 =0) \# wl\ + | sil_1_0: "S_il (return_spmf ((None, ()), (False, (EState_Store, s_act1), EState_Void, s_act2), key.PState_Store, {})) + (return_spmf ((None, CState_Half 0, CState_Void), (auth.State_Store \, s_act1), auth.State_Void, s_act2))" + if "auth.Alice \ s_act1" + | sil_2_0: "S_il (map_spmf (\k. ((None, ()), (True, (EState_Collect, s_act1), EState_Void, s_act2), key.State_Store k, {})) isample_key) + (return_spmf ((None, CState_Half 0, CState_Void), (auth.State_Collect \, s_act1), auth.State_Void, s_act2))" + if "auth.Alice \ s_act1" +\ \../(Auth1 =a)@(Auth2 =0) \# look\ + | sil_1'_0: "S_il (map_spmf (\y. ((Some (\<^bold>g [^] x, \<^bold>g [^] y), ()), (False, (EState_Store, s_act1), EState_Void, s_act2), key.PState_Store, {})) isample_nat) + (map_spmf (\yz. ((Some (\<^bold>g [^] snd yz, \<^bold>g [^] (x :: nat), \<^bold>g [^] fst yz), CState_Half 0, CState_Void), (auth.State_Store \, s_act1), auth.State_Void, s_act2)) isample_pair_nn)" + if "auth.Alice \ s_act1" + | sil_2'_0: "S_il (map_spmf (\yk. ((Some (\<^bold>g [^] x, \<^bold>g [^] fst yk), ()), (True, (EState_Collect, s_act1), EState_Void, s_act2), key.State_Store (snd yk), {})) isample_pair_nk) + (map_spmf (\yz. ((Some (\<^bold>g [^] snd yz, \<^bold>g [^] (x :: nat), \<^bold>g [^] fst yz), CState_Half 0, CState_Void), (auth.State_Collect \, s_act1), auth.State_Void, s_act2)) isample_pair_nn)" + if "auth.Alice \ s_act1" +\ \(Auth1 =a)@(Auth2 =1)\ + | sil_0_1: "S_il (return_spmf ((None, ()), (False, (EState_Void, s_act1), EState_Store, s_act2), key.PState_Store, {})) + (return_spmf ((None, CState_Void, CState_Half 0), (auth.State_Void, s_act1), auth.State_Store \, s_act2))" + if "auth.Alice \ s_act2" +\ \../(Auth1 =a)@(Auth2 =1) \# wl\ + | sil_1_1: "S_il (return_spmf ((None, ()), (False, (EState_Store, s_act1), EState_Store, s_act2), key.PState_Store, {})) + (return_spmf ((None, CState_Half 0, CState_Half 0), (auth.State_Store \, s_act1), auth.State_Store \, s_act2))" + if "auth.Alice \ s_act1" and "auth.Alice \ s_act2" + | sil_2_1: "S_il (map_spmf (\k. ((None, ()), (True, (EState_Collect, s_act1), EState_Store, s_act2), key.State_Store k, s_actk)) isample_key) + (return_spmf ((None, CState_Half 0, CState_Half 0), (auth.State_Collect \, s_act1), auth.State_Store \, s_act2))" + if "auth.Alice \ s_act1" and "auth.Alice \ s_act2" and "key.Alice \ s_actk" and "auth.Bob \ s_act1 \ key.Bob \ s_actk" + | sil_3_1: "S_il (return_spmf ((None, ()), (True, (EState_Collect, s_act1), EState_Store, s_act2), key.State_Store k, s_actk)) + (map_spmf (\xy. ((Some (\<^bold>g [^] (z :: nat), \<^bold>g [^] fst xy, \<^bold>g [^] snd xy), CState_Half 0, CState_Full (0, \)), (auth.State_Collected, s_act1), auth.State_Store \, s_act2)) isample_pair_nn)" + if "auth.Alice \ s_act1" and "auth.Alice \ s_act2" and "key.Alice \ s_actk" and "auth.Bob \ s_act1" and "key.Bob \ s_actk" and "k = \<^bold>g [^] z" +\ \../(Auth1 =a)@(Auth2 =1) \# look\ + | sil_1c_1c: "S_il (return_spmf ((Some (\<^bold>g [^] x, \<^bold>g [^] y), ()), (False, (EState_Store, s_act1), EState_Store, s_act2), key.PState_Store, {})) + (map_spmf (\z. ((Some (\<^bold>g [^] z, \<^bold>g [^] (x :: nat), \<^bold>g [^] (y :: nat)), CState_Half 0, CState_Half 0), (auth.State_Store \, s_act1), auth.State_Store \, s_act2)) isample_nat)" + if "auth.Alice \ s_act1" and "auth.Alice \ s_act2" + | sil_2c_1c: "S_il (return_spmf ((Some (\<^bold>g [^] x, \<^bold>g [^] y), ()), (True, (EState_Collect, s_act1), EState_Store, s_act2), key.State_Store k, s_actk)) + (return_spmf ((Some (\<^bold>g [^] z, \<^bold>g [^] (x :: nat), \<^bold>g [^] (y :: nat)), CState_Half 0, CState_Half 0), (auth.State_Collect \, s_act1), auth.State_Store \, s_act2))" + if "auth.Alice \ s_act1" and "auth.Alice \ s_act2" and "key.Alice \ s_actk" and "auth.Bob \ s_act1 \ key.Bob \ s_actk" and "k = \<^bold>g [^] z" and "z \ set_spmf isample_nat" + | sil_3c_1c: "S_il (return_spmf ((Some (\<^bold>g [^] x, \<^bold>g [^] y), ()), (True, (EState_Collect, s_act1), EState_Store, s_act2), key.State_Store k, s_actk)) + (return_spmf ((Some (\<^bold>g [^] (z :: nat), \<^bold>g [^] (x :: nat), \<^bold>g [^] (y :: nat)), CState_Half 0, CState_Full (0, \)), (auth.State_Collected, s_act1), auth.State_Store \, s_act2))" + if "auth.Alice \ s_act1" and "auth.Alice \ s_act2" and "key.Alice \ s_actk" and "auth.Bob \ s_act1" and "key.Bob \ s_actk" and "k = \<^bold>g [^] z" +\ \(Auth1 =a)@(Auth2 =2)\ + | sil_0_2: "S_il (map_spmf (\k. ((None, ()), (True, (EState_Void, s_act1), EState_Collect, s_act2), key.State_Store k, {})) isample_key) + (return_spmf ((None, CState_Void, CState_Half 0), (auth.State_Void, s_act1), auth.State_Collect \, s_act2))" + if "auth.Alice \ s_act2" +\ \../(Auth1 =a)@(Auth2 =2) \# wl\ + | sil_1_2: "S_il (map_spmf (\k. ((None, ()), (True, (EState_Store, s_act1), EState_Collect, s_act2), key.State_Store k, s_actk)) isample_key) + (return_spmf ((None, CState_Half 0, CState_Half 0), (auth.State_Store \, s_act1), auth.State_Collect \, s_act2))" + if "auth.Alice \ s_act1" and "auth.Alice \ s_act2" and "auth.Bob \ s_act2 \ key.Alice \ s_actk" and "key.Bob \ s_actk" + | sil_2_2: "S_il (map_spmf (\k. ((None, ()), (True, (EState_Collect, s_act1), EState_Collect, s_act2), key.State_Store k, s_actk)) isample_key) + (return_spmf ((None, CState_Half 0, CState_Half 0), (auth.State_Collect \, s_act1), auth.State_Collect \, s_act2))" + if "auth.Alice \ s_act1" and "auth.Alice \ s_act2" and "auth.Bob \ s_act2 \ key.Alice \ s_actk" and "auth.Bob \ s_act1 \ key.Bob \ s_actk" + | sil_3_2: "S_il (return_spmf ((None, ()), (True, (EState_Collect, s_act1), EState_Collect, s_act2), key.State_Store k, s_actk)) + (map_spmf (\xy. ((Some (\<^bold>g [^] (z :: nat), \<^bold>g [^] fst xy, \<^bold>g [^] snd xy), CState_Half 0, CState_Full (0, \)), (auth.State_Collected, s_act1), auth.State_Collect \, s_act2)) isample_pair_nn)" + if "auth.Alice \ s_act1" and "auth.Alice \ s_act2" and "auth.Bob \ s_act2 \ key.Alice \ s_actk" and "auth.Bob \ s_act1" and "key.Bob \ s_actk" and "k = \<^bold>g [^] z" +\ \../(Auth1 =a)@(Auth2 =2) \# look\ + | sil_1c_2c: "S_il (return_spmf ((Some (\<^bold>g [^] x, \<^bold>g [^] y), ()), (True, (EState_Store, s_act1), EState_Collect, s_act2), key.State_Store k, s_actk)) + (return_spmf ((Some (\<^bold>g [^] z, \<^bold>g [^] (x :: nat), \<^bold>g [^] (y :: nat)), CState_Half 0, CState_Half 0), (auth.State_Store \, s_act1), auth.State_Collect \, s_act2))" + if "auth.Alice \ s_act1" and "auth.Alice \ s_act2" and "auth.Bob \ s_act2 \ key.Alice \ s_actk" and "key.Bob \ s_actk" and "k = \<^bold>g [^] z" and "z \ set_spmf isample_nat" + | sil_2c_2c: "S_il (return_spmf ((Some (\<^bold>g [^] x, \<^bold>g [^] y), ()), (True, (EState_Collect, s_act1), EState_Collect, s_act2), key.State_Store k, s_actk)) + (return_spmf ((Some (\<^bold>g [^] z, \<^bold>g [^] (x :: nat), \<^bold>g [^] (y :: nat)), CState_Half 0, CState_Half 0), (auth.State_Collect \, s_act1), auth.State_Collect \, s_act2))" + if "auth.Alice \ s_act1" and "auth.Alice \ s_act2" and "auth.Bob \ s_act2 \ key.Alice \ s_actk" and "auth.Bob \ s_act1 \ key.Bob \ s_actk" and "k = \<^bold>g [^] z" and "z \ set_spmf isample_nat" + | sil_3c_2c: "S_il (return_spmf ((Some (\<^bold>g [^] x, \<^bold>g [^] y), ()), (True, (EState_Collect, s_act1), EState_Collect, s_act2), key.State_Store k, s_actk)) + (return_spmf ((Some (\<^bold>g [^] (z :: nat), \<^bold>g [^] (x :: nat), \<^bold>g [^] (y :: nat)), CState_Half 0, CState_Full (0, \)), (auth.State_Collected, s_act1), auth.State_Collect \, s_act2))" + if "auth.Alice \ s_act1" and "auth.Alice \ s_act2" and "auth.Bob \ s_act2 \ key.Alice \ s_actk" and "auth.Bob \ s_act1" and "key.Bob \ s_actk" and "k = \<^bold>g [^] z" +\ \(Auth1 =a)@(Auth2 =3)\ +\ \../(Auth1 =a)@(Auth2 =3) \# wl\ + | sil_1_3: "S_il (return_spmf ((None, ()), (True, (EState_Store, s_act1), EState_Collect, s_act2), key.State_Store k, s_actk)) + (map_spmf (\xy. ((Some (\<^bold>g [^] (z :: nat), \<^bold>g [^] fst xy, \<^bold>g [^] snd xy), CState_Full (0, \), CState_Half 0), (auth.State_Store \, s_act1), auth.State_Collected, s_act2)) isample_pair_nn)" + if "auth.Alice \ s_act1" and "auth.Alice \ s_act2" and "auth.Bob \ s_act2" and "key.Alice \ s_actk" and "key.Bob \ s_actk" and "k = \<^bold>g [^] z" + | sil_2_3: "S_il (return_spmf ((None, ()), (True, (EState_Collect, s_act1), EState_Collect, s_act2), key.State_Store k, s_actk)) + (map_spmf (\xy. ((Some (\<^bold>g [^] (z :: nat), \<^bold>g [^] fst xy, \<^bold>g [^] snd xy), CState_Full (0, \), CState_Half 0), (auth.State_Collect \, s_act1), auth.State_Collected, s_act2)) isample_pair_nn)" + if "auth.Alice \ s_act1" and "auth.Alice \ s_act2" and "auth.Bob \ s_act2" and "key.Alice \ s_actk" and "auth.Bob \ s_act1 \ key.Bob \ s_actk" and "k = \<^bold>g [^] z" + | sil_3_3: "S_il (return_spmf ((None, ()), (True, (EState_Collect, s_act1), EState_Collect, s_act2), key.State_Store k, s_actk)) + (map_spmf (\xy. ((Some (\<^bold>g [^] (z :: nat), \<^bold>g [^] fst xy, \<^bold>g [^] snd xy), CState_Full (0, \), CState_Full (0, \)), (auth.State_Collected, s_act1), auth.State_Collected, s_act2)) isample_pair_nn)" + if "auth.Alice \ s_act1" and "auth.Alice \ s_act2" and "auth.Bob \ s_act2" and "key.Alice \ s_actk" and "auth.Bob \ s_act1" and "key.Bob \ s_actk" and "k = \<^bold>g [^] z" +\ \../(Auth1 =a)@(Auth2 =3) \# look\ + | sil_1c_3c: "S_il (return_spmf ((Some (\<^bold>g [^] x, \<^bold>g [^] y), ()), (True, (EState_Store, s_act1), EState_Collect, s_act2), key.State_Store k, s_actk)) + (return_spmf ((Some (\<^bold>g [^] (z :: nat), \<^bold>g [^] (x :: nat), \<^bold>g [^] (y :: nat)), CState_Full (0, \), CState_Half 0), (auth.State_Store \, s_act1), auth.State_Collected, s_act2))" + if "auth.Alice \ s_act1" and "auth.Alice \ s_act2" and "auth.Bob \ s_act2" and "key.Alice \ s_actk" and "key.Bob \ s_actk" and "k = \<^bold>g [^] z" + | sil_2c_3c: "S_il (return_spmf ((Some (\<^bold>g [^] x, \<^bold>g [^] y), ()), (True, (EState_Collect, s_act1), EState_Collect, s_act2), key.State_Store k, s_actk)) + (return_spmf ((Some (\<^bold>g [^] (z :: nat), \<^bold>g [^] (x :: nat), \<^bold>g [^] (y :: nat)), CState_Full (0, \), CState_Half 0), (auth.State_Collect \, s_act1), auth.State_Collected, s_act2))" + if "auth.Alice \ s_act1" and "auth.Alice \ s_act2" and "auth.Bob \ s_act2" and "key.Alice \ s_actk" and "auth.Bob \ s_act1 \ key.Bob \ s_actk" and "k = \<^bold>g [^] z" + | sil_3c_3c: "S_il (return_spmf ((Some (\<^bold>g [^] x, \<^bold>g [^] y), ()), (True, (EState_Collect, s_act1), EState_Collect, s_act2), key.State_Store k, s_actk)) + (return_spmf ((Some (\<^bold>g [^] (z :: nat), \<^bold>g [^] (x :: nat), \<^bold>g [^] (y :: nat)), CState_Full (0, \), CState_Full (0, \)), (auth.State_Collected, s_act1), auth.State_Collected, s_act2))" + if "auth.Alice \ s_act1" and "auth.Alice \ s_act2" and "auth.Bob \ s_act2" and "key.Alice \ s_actk" and "auth.Bob \ s_act1" and "key.Bob \ s_actk" and "k = \<^bold>g [^] z" +\ \(Auth1 =a)@(Auth2 =1')\ + | sil_0_1': "S_il (map_spmf (\x. ((Some (\<^bold>g [^] x, \<^bold>g [^] y), ()), (False, (EState_Void, s_act1), EState_Store, s_act2), key.PState_Store, {})) isample_nat) + (map_spmf (\xz. ((Some (\<^bold>g [^] snd xz, \<^bold>g [^] fst xz, \<^bold>g [^] (y :: nat)), CState_Void, CState_Half 0), (auth.State_Void, s_act1), auth.State_Store \, s_act2)) isample_pair_nn)" + if "auth.Alice \ s_act2" +\ \(Auth1 =a)@(Auth2 =2')\ + | sil_0_2': "S_il (map_spmf (\xk. ((Some (\<^bold>g [^] fst xk, \<^bold>g [^] y), ()), (True, (EState_Void, s_act1), EState_Collect, s_act2), key.State_Store (snd xk), {})) isample_pair_nk) + (map_spmf (\xz. ((Some (\<^bold>g [^] snd xz, \<^bold>g [^] fst xz, \<^bold>g [^] (y :: nat)), CState_Void, CState_Half 0), (auth.State_Void, s_act1), auth.State_Collect \, s_act2)) isample_pair_nn)" + if "auth.Alice \ s_act2" + +private lemma trac_eq_core_il: "trace_core_eq ideal_core' (lazy_core DH1_sample) + ((UNIV <+> UNIV) <+> UNIV <+> UNIV) ((UNIV <+> UNIV <+> UNIV) <+> UNIV <+> UNIV <+> UNIV) (UNIV <+> UNIV) + (return_spmf ideal_s_core') (return_spmf basic_core_sinit)" +proof - + have isample_key_conv_nat[simplified map_spmf_conv_bind_spmf]: + "map_spmf f isample_key = map_spmf (\x. f (\<^bold>g [^] x)) isample_nat" for f + unfolding sample_uniform_def carrier_conv_generator + by (simp add: map_spmf_of_set_inj_on[OF inj_on_generator, symmetric] spmf.map_comp o_def) + + have [simp]: "weight_spmf isample_nat = 1" + by (simp add: finite_carrier order_gt_0_iff_finite) + + have [simp]: "weight_spmf isample_key = 1" + by (simp add: carrier_not_empty cyclic_group.finite_carrier cyclic_group_axioms) + + have [simp]: "mk_lossless isample_nat = isample_nat" + by (simp add: mk_lossless_def) + + have [simp]: "mk_lossless isample_pair_nn = isample_pair_nn" + by (simp add: mk_lossless_def) + + have [simp]: "mk_lossless isample_pair_nk = isample_pair_nk" + by (simp add: mk_lossless_def) + + note [simp] = basic_core_helper_def basic_core_oracle_usr_def eleak_def DH1_sample_def + Let_def split_def exec_gpv_bind spmf.map_comp o_def map_bind_spmf bind_map_spmf bind_spmf_const + + show ?thesis + apply (rule trace_core_eq_simI_upto[where S=S_il]) + subgoal Init_OK + by (simp add: ideal_s_core'_def einit_def sil_0_0) + subgoal POut_OK for sl sr query + apply (cases query) + subgoal for e_usrs + apply (cases e_usrs) + subgoal for e_alice by (erule S_il.cases) (auto simp add: map_spmf_conv_bind_spmf[symmetric]) + subgoal for e_bob by (erule S_il.cases) (auto simp add: map_spmf_conv_bind_spmf[symmetric]) + done + subgoal for e_chns + apply (cases e_chns) + subgoal for e_chn1 + apply (cases e_chn1) + subgoal for e_shell + apply (cases e_shell) + subgoal a_alice by (erule S_il.cases) (auto simp add: map_spmf_conv_bind_spmf[symmetric]) + subgoal a_bob by (erule S_il.cases) (auto simp add: map_spmf_conv_bind_spmf[symmetric]) + done + done + subgoal for e_chn2 + apply (cases e_chn2) + subgoal for e_shell + apply (cases e_shell) + subgoal a_alice by (erule S_il.cases) (auto simp add: map_spmf_conv_bind_spmf[symmetric]) + subgoal a_bob by (erule S_il.cases) (auto simp add: map_spmf_conv_bind_spmf[symmetric]) + done + done + done + done + subgoal PState_OK for sl sr query + apply (cases query) + subgoal for e_usrs + apply (cases e_usrs) + subgoal for e_alice + proof (erule S_il.cases, goal_cases) + case (26 s_act2 y s_act1) \ \Corresponds to @{thm [source] sil_0_1'}\ + then show ?case + apply (clarsimp simp add: map_spmf_conv_bind_spmf[symmetric]) + apply (simp add: pair_spmf_alt_def map_spmf_conv_bind_spmf) + apply (rule trace_eq_simcl_bindI) + by (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro: S_il.intros) + next + case (27 s_act2 y s_act1) \ \Corresponds to @{thm [source] sil_0_2'}\ + then show ?case + apply (clarsimp simp add: pair_spmf_alt_def isample_key_conv_nat) + apply (simp add: bind_bind_conv_pair_spmf) + by (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro!: S_il.intros trace_eq_simcl_map) + qed (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro: S_il.intros trace_eq_simcl.base) + subgoal for e_bob + proof (erule S_il.cases, goal_cases) + case (4 s_act1 x s_act2) \ \Corresponds to @{thm [source] sil_1'_0}\ + then show ?case + apply (clarsimp simp add: map_spmf_conv_bind_spmf[symmetric]) + apply (simp add: pair_spmf_alt_def map_spmf_conv_bind_spmf) + apply (rule trace_eq_simcl_bindI) + by (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro: S_il.intros) + next + case (5 s_act1 x s_act2) \ \Corresponds to @{thm [source] sil_2'_0}\ + then show ?case + apply (clarsimp simp add: pair_spmf_alt_def isample_key_conv_nat) + apply (simp add: bind_bind_conv_pair_spmf) + by (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro!: S_il.intros trace_eq_simcl_map) + qed (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro: S_il.intros trace_eq_simcl.base) + done + subgoal for e_chns + apply (cases e_chns) + subgoal for e_auth1 + apply (cases e_auth1) + subgoal for e_shell + apply (cases e_shell) + subgoal a_alice by (erule S_il.cases) (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro: S_il.intros trace_eq_simcl.base) + subgoal a_bob by (erule S_il.cases) (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro: S_il.intros trace_eq_simcl.base) + done + done + subgoal for e_auth2 + apply (cases e_auth2) + subgoal for e_shell + apply (cases e_shell) + subgoal a_alice by (erule S_il.cases) (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro: S_il.intros trace_eq_simcl.base) + subgoal a_bob by (erule S_il.cases) (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro: S_il.intros trace_eq_simcl.base) + done + done + done + done + subgoal AOut_OK for sl sr query + apply (cases query) + subgoal for q_auth1 + apply (cases q_auth1) + subgoal for q_drop by (erule S_il.cases) (auto simp add: map_spmf_conv_bind_spmf[symmetric]) + subgoal for q_lfe + apply (cases q_lfe) + subgoal for q_look by (erule S_il.cases) (simp_all del: bind_spmf_const add: pair_spmf_alt_def, clarsimp+) + subgoal for q_fedit by (erule S_il.cases) (simp_all del: bind_spmf_const add: pair_spmf_alt_def, clarsimp+) + done + done + subgoal for q_auth2 + apply (cases q_auth2) + subgoal for q_drop by (erule S_il.cases) (auto simp add: map_spmf_conv_bind_spmf[symmetric]) + subgoal for q_lfe + apply (cases q_lfe) + subgoal for q_look by (erule S_il.cases) (simp_all del: bind_spmf_const add: pair_spmf_alt_def, clarsimp+) + subgoal for q_fedit by (erule S_il.cases) (simp_all del: bind_spmf_const add: pair_spmf_alt_def, clarsimp+) + done + done + done + subgoal AState_OK for sl sr query + apply (cases query) + subgoal for q_auth1 + apply (cases q_auth1) + subgoal for q_drop by (erule S_il.cases) auto + subgoal for q_lfe + apply (cases q_lfe) + subgoal for q_look + proof (erule S_il.cases, goal_cases) + case (2 s_act1 s_act2) \ \Corresponds to @{thm [source] sil_1_0}\ + then show ?case + apply simp + apply (subst (1 2 3) bind_bind_conv_pair_spmf) + apply (clarsimp simp add: map_spmf_conv_bind_spmf[symmetric]) + apply (subst (1 2) cond_spmf_fst_pair_spmf1[unfolded map_prod_def split_def]) + by (auto intro: trace_eq_simcl_bindI S_il.intros) + next + case (7 s_act1 s_act2) \ \Corresponds to @{thm [source] sil_1_1}\ + then show ?case + apply simp + apply (subst (1 2 3) bind_bind_conv_pair_spmf) + apply (clarsimp simp add: map_spmf_conv_bind_spmf[symmetric]) + apply (subst (1 2) cond_spmf_fst_pair_spmf1[unfolded map_prod_def split_def]) + apply(subst (1 2) cond_spmf_fst_map_Pair1; simp add: inj_on_def) + apply (subst (1 2) inv_into_f_f) + apply (simp_all add: inj_on_def map_spmf_conv_bind_spmf pair_spmf_alt_def isample_key_conv_nat) + apply (rule trace_eq_simcl_bindI) + by (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro: S_il.intros) + next + case (14 s_act1 s_act2 s_actk) \ \Corresponds to @{thm [source] sil_1_2}\ + then show ?case + apply clarsimp + apply (subst bind_commute_spmf, subst (2) bind_commute_spmf) + apply (subst (1 2 3 4) bind_bind_conv_pair_spmf) + apply (clarsimp simp add: map_spmf_conv_bind_spmf[symmetric]) + apply (subst (1 2) cond_spmf_fst_pair_spmf1[unfolded map_prod_def split_def]) + apply(subst (1 2) cond_spmf_fst_map_Pair1; simp add: inj_on_def) + apply (subst (1 2) inv_into_f_f) + apply (simp_all add: inj_on_def map_spmf_conv_bind_spmf pair_spmf_alt_def isample_key_conv_nat) + apply (subst (1 2) bind_bind_conv_pair_spmf) + by (auto intro!: trace_eq_simcl_bindI S_il.intros) + next + case (20 s_act1 s_act2 s_actk k z) \ \Corresponds to @{thm [source] sil_1_3}\ + then show ?case + apply simp + apply (subst bind_bind_conv_pair_spmf) + apply (clarsimp simp add: map_spmf_conv_bind_spmf[symmetric]) + apply (subst (1 2) cond_spmf_fst_pair_spmf1[unfolded map_prod_def split_def]) + apply(subst (1 2) cond_spmf_fst_map_Pair1; simp add: inj_on_def) + apply (subst (1 2) inv_into_f_f) + apply (simp_all add: inj_on_def map_spmf_conv_bind_spmf) + by (auto intro!: trace_eq_simcl_bindI S_il.intros) + qed (auto simp add: map_spmf_conv_bind_spmf, + auto simp add: map_spmf_conv_bind_spmf[symmetric] intro: S_il.intros trace_eq_simcl.base) + subgoal for q_fedit + proof (erule S_il.cases, goal_cases) + case (4 s_act1 x s_act2) \ \Corresponds to @{thm [source] sil_1'_0}\ + then show ?case + apply simp + apply (subst bind_bind_conv_pair_spmf) + apply (clarsimp simp add: map_spmf_conv_bind_spmf[symmetric]) + by (auto intro: S_il.intros trace_eq_simcl.base) + next + case (10 s_act1 s_act2 x y) \ \Corresponds to @{thm [source] sil_1c_1c}\ + then show ?case + apply (clarsimp simp add: pair_spmf_alt_def isample_key_conv_nat) + apply (simp add: map_spmf_conv_bind_spmf[symmetric]) + by (auto intro!: trace_eq_simcl_map S_il.intros) + qed (auto simp add: map_spmf_conv_bind_spmf[symmetric], + auto intro: S_il.intros trace_eq_simcl.base trace_eq_simcl_map) + done + done + subgoal for q_auth2 + apply (cases q_auth2) + subgoal for q_drop by (erule S_il.cases) auto + subgoal for q_lfe + apply (cases q_lfe) + subgoal for q_look + proof (erule S_il.cases, goal_cases) + case (6 s_act2 s_act1) \ \Corresponds to @{thm [source] sil_0_1}\ + then show ?case + apply clarsimp + apply (subst (1 2) bind_commute_spmf) + apply (subst (1 3) bind_bind_conv_pair_spmf) + apply (subst bind_bind_conv_pair_spmf) + apply (clarsimp simp add: map_spmf_conv_bind_spmf[symmetric]) + apply (subst (1 2) cond_spmf_fst_pair_spmf1[unfolded map_prod_def split_def]) + by (auto intro: trace_eq_simcl_bindI S_il.intros) + next + case (7 s_act1 s_act2) \ \Corresponds to @{thm [source] sil_1_1}\ + then show ?case + apply clarsimp + apply (subst (1 2) bind_commute_spmf) + apply (subst (1 3) bind_bind_conv_pair_spmf) + apply (subst bind_bind_conv_pair_spmf) + apply (clarsimp simp add: map_spmf_conv_bind_spmf[symmetric]) + apply (subst (1 2) cond_spmf_fst_pair_spmf1[unfolded map_prod_def split_def]) + apply(subst (1 2) cond_spmf_fst_map_Pair1; simp add: inj_on_def) + apply (subst (1 2) inv_into_f_f) + apply (simp_all add: inj_on_def map_spmf_conv_bind_spmf) + apply (subst pair_spmf_alt_def) + apply (subst bind_spmf_assoc) + apply (rule trace_eq_simcl_bindI) + by (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro: S_il.intros) + next + case (8 s_act1 s_act2 s_actk) \ \Corresponds to @{thm [source] sil_2_1}\ + then show ?case + apply clarsimp + apply (subst (2) bind_commute_spmf, subst (1 3) bind_commute_spmf) + apply (subst (2) bind_commute_spmf) + apply (subst (2 4) bind_bind_conv_pair_spmf) + apply (clarsimp simp add: bind_bind_conv_pair_spmf) + apply (clarsimp simp add: map_spmf_conv_bind_spmf[symmetric]) + apply (subst (1 2) cond_spmf_fst_pair_spmf1[unfolded map_prod_def split_def]) + apply(subst (1 2) cond_spmf_fst_map_Pair1; simp add: inj_on_def) + apply (subst (1 2) inv_into_f_f) + apply (simp_all add: inj_on_def map_spmf_conv_bind_spmf) + apply (simp add: pair_spmf_alt_def isample_key_conv_nat) + apply (subst (1 2) bind_bind_conv_pair_spmf) + by (auto intro!: trace_eq_simcl_bindI S_il.intros) + next + case (9 s_act1 s_act2 s_actk k z) \ \Corresponds to @{thm [source] sil_3_1}\ + then show ?case + apply (clarsimp simp del: bind_spmf_const simp add: pair_spmf_alt_def) + apply (subst (1 2) bind_commute_spmf) + apply (subst (1 2) bind_bind_conv_pair_spmf) + apply (clarsimp simp add: map_spmf_conv_bind_spmf[symmetric]) + apply (subst (1 2) cond_spmf_fst_pair_spmf1[unfolded map_prod_def split_def]) + apply(subst (1 2) cond_spmf_fst_map_Pair1; simp add: inj_on_def) + apply (subst (1 2) inv_into_f_f) + apply (simp_all add: inj_on_def map_spmf_conv_bind_spmf) + by (auto intro: trace_eq_simcl_bindI S_il.intros) + qed (auto simp del: bind_spmf_const simp add: map_spmf_conv_bind_spmf, + auto simp add: map_spmf_conv_bind_spmf[symmetric] intro: S_il.intros trace_eq_simcl.base) + subgoal for q_fedit + proof (erule S_il.cases, goal_cases) + case (10 s_act1 s_act2 x y) \ \Corresponds to @{thm [source] sil_1c_1c}\ + then show ?case + apply simp + apply (clarsimp simp add: map_spmf_conv_bind_spmf pair_spmf_alt_def isample_key_conv_nat) + apply (clarsimp simp add: map_spmf_conv_bind_spmf[symmetric]) + by (auto intro!: S_il.intros trace_eq_simcl_map) + next + case (26 s_act2 y s_act1) \ \Corresponds to @{thm [source] sil_0_1'}\ + then show ?case + apply simp + apply (subst bind_bind_conv_pair_spmf) + apply (clarsimp simp add: map_spmf_conv_bind_spmf[symmetric]) + by (auto intro: S_il.intros trace_eq_simcl.base) + qed (auto simp add: map_spmf_conv_bind_spmf[symmetric], + auto intro: S_il.intros trace_eq_simcl.base trace_eq_simcl_map) + done + done + done + subgoal UOut_OK for sl sr query + apply (cases query) + subgoal for q_alice + apply (erule S_il.cases) + by (auto simp add: pair_spmf_alt_def isample_key_conv_nat) + subgoal for q_bob + apply (erule S_il.cases) + by (auto simp add: pair_spmf_alt_def isample_key_conv_nat) + done + subgoal UState_OK for sl sr query + apply (cases query) + subgoal for q_alice + proof (erule S_il.cases, goal_cases) + case (14 s_act1 s_act2 s_actk) \ \Corresponds to @{thm [source] sil_1_2}\ + then show ?case + apply (clarsimp) + apply (subst (2) bind_commute_spmf, subst bind_commute_spmf) + apply (subst bind_bind_conv_pair_spmf, subst bind_bind_conv_pair_spmf) + apply (clarsimp simp add: map_spmf_conv_bind_spmf[symmetric]) + apply (subst cond_spmf_fst_pair_spmf1[unfolded map_prod_def split_def]) + apply(subst (1 2) cond_spmf_fst_map_Pair1; simp add: inj_on_def) + apply(subst (1 2) inv_into_f_f) + by (auto simp add: inj_on_def intro: S_il.intros trace_eq_simcl.base) + next + case (15 s_act1 s_act2 s_actk) \ \Corresponds to @{thm [source] sil_2_2}\ + then show ?case + apply (clarsimp) + apply (subst (2) bind_commute_spmf, subst bind_commute_spmf) + apply (subst bind_bind_conv_pair_spmf, subst bind_bind_conv_pair_spmf) + apply (clarsimp simp add: map_spmf_conv_bind_spmf[symmetric]) + apply (subst cond_spmf_fst_pair_spmf1[unfolded map_prod_def split_def]) + apply(subst (1 2) cond_spmf_fst_map_Pair1; simp add: inj_on_def) + apply(subst (1 2) inv_into_f_f) + by (auto simp add: inj_on_def intro: S_il.intros trace_eq_simcl.base) + qed (auto simp add: map_spmf_conv_bind_spmf[symmetric], + auto intro: S_il.intros trace_eq_simcl.base trace_eq_simcl_map) + subgoal for q_bob + proof (erule S_il.cases, goal_cases) + case (8 s_act1 s_act2 s_actk) \ \Corresponds to @{thm [source] sil_2_1}\ + then show ?case + apply clarsimp + apply (subst (2) bind_commute_spmf, subst bind_commute_spmf) + apply (subst (2) bind_bind_conv_pair_spmf, subst bind_bind_conv_pair_spmf) + apply (clarsimp simp add: map_spmf_conv_bind_spmf[symmetric]) + apply (subst cond_spmf_fst_pair_spmf1[unfolded map_prod_def split_def]) + apply (subst (1 2) cond_spmf_fst_map_Pair1; simp add: inj_on_def) + apply (subst (1 2) inv_into_f_f) + by (auto simp add: inj_on_def intro: S_il.intros trace_eq_simcl.base) + next + case (15 s_act1 s_act2 s_actk) \ \Corresponds to @{thm [source] sil_2_2}\ + then show ?case + apply clarsimp + apply (subst (2) bind_commute_spmf, subst bind_commute_spmf) + apply (subst (2) bind_bind_conv_pair_spmf, subst bind_bind_conv_pair_spmf) + apply (clarsimp simp add: map_spmf_conv_bind_spmf[symmetric]) + apply (subst cond_spmf_fst_pair_spmf1[unfolded map_prod_def split_def]) + apply (subst (1 2) cond_spmf_fst_map_Pair1; simp add: inj_on_def) + apply (subst (1 2) inv_into_f_f) + by (auto simp add: inj_on_def intro: S_il.intros trace_eq_simcl.base) + qed(auto simp add: map_spmf_conv_bind_spmf[symmetric], + auto intro: S_il.intros trace_eq_simcl.base trace_eq_simcl_map) + done + done +qed + +lemma connect_ideal: "connect D (obsf_resource ideal_resource) = + connect D (obsf_resource (RES (fused_resource.fuse (lazy_core DH1_sample) lazy_rest) (basic_core_sinit, basic_rest_sinit)))" +proof - + have fact1: "trace_rest_eq ideal_rest' ideal_rest' UNIV UNIV s s" for s + by (rule rel_rest'_into_trace_rest_eq[where S="(=)" and M="(=)"]) (simp_all add: eq_onp_def rel_rest'_eq) + + have fact2: "\_full \\<^sub>\ \_full \c callee_of_rest ideal_rest' s \" for s + by (rule WT_calleeI) (cases s, case_tac call, rename_tac [!] x, case_tac [!] x, auto) + + have fact3: "\_full \\<^sub>\ (\_full \\<^sub>\ \_full) \c callee_of_core ideal_core' s \" for s + by (rule WT_calleeI) (cases s, case_tac call, rename_tac [!] x, case_tac [!] x, auto) + + have fact4: "\_full \\<^sub>\ (\_full \\<^sub>\ \_full) \c callee_of_core (lazy_core xyz) s \" for xyz s + by (rule WT_calleeI) (cases s, case_tac call, rename_tac [!] x, case_tac [!] x, auto) + + show ?thesis + apply (rule connect_cong_trace[where A="UNIV" and \=\_full]) + apply (rule trace_eq_obsf_resourceI) + subgoal + apply (simp add: attach_ideal) + apply (rule fuse_trace_eq[where \E=\_full and \CA=\_full and \CU=\_full and \RA=\_full and \RU=\_full, simplified]) + by (simp_all add: ideal_s_rest'_def lazy_rest_def trac_eq_core_il[simplified] fact1 fact2 fact3 fact4) + by (simp_all add: attach_ideal) +qed + + +end + + +subsection \Proving the trace-equivalence of simplified Real and Lazy constructions\ + +context +begin + +private abbreviation "rsample_nat \ sample_uniform (order \)" +private abbreviation "rsample_pair_nn \ pair_spmf rsample_nat rsample_nat" + +private inductive S_rl :: "((unit \ 'grp cstate \ 'grp cstate) \ 'grp auth.state \ 'grp auth.state) spmf + \ (('grp st_state \ 'grp cstate \ 'grp cstate) \ 'grp auth.state \ 'grp auth.state) spmf \ bool" + where +\ \(Auth1 =a)@(Auth2 =0)\ + srl_0_0: "S_rl (return_spmf (((), CState_Void, CState_Void), (auth.State_Void, s_act1), auth.State_Void, s_act2)) + (return_spmf ((None, CState_Void, CState_Void), (auth.State_Void, s_act1), (auth.State_Void, s_act2)))" +\ \../(Auth1 =a)@(Auth2 =0) \# wl\ + | srl_1_0: "S_rl (map_spmf (\x. (((), CState_Half x, CState_Void), (auth.State_Store (\<^bold>g [^] x), s_act1), auth.State_Void, s_act2)) rsample_nat) + (return_spmf ((None, CState_Half 0, CState_Void), (auth.State_Store \, s_act1), auth.State_Void, s_act2))" + | srl_2_0: "S_rl (map_spmf (\x. (((), CState_Half x, CState_Void), (auth.State_Collect (\<^bold>g [^] x), s_act1), auth.State_Void, s_act2)) rsample_nat) + (return_spmf ((None, CState_Half 0, CState_Void), (auth.State_Collect \, s_act1), auth.State_Void, s_act2))" +\ \../(Auth1 =a)@(Auth2 =0) \# look\ + | srl_1'_0: "S_rl (return_spmf (((), CState_Half x, CState_Void), (auth.State_Store (\<^bold>g [^] x), s_act1), auth.State_Void, s_act2)) + (map_spmf (\y. ((Some ((\<^bold>g [^] x) [^] y, \<^bold>g [^] x, \<^bold>g [^] y), CState_Half 0, CState_Void), (auth.State_Store \, s_act1), auth.State_Void, s_act2)) rsample_nat)" + | srl_2'_0: "S_rl (return_spmf (((), CState_Half x, CState_Void), (auth.State_Collect (\<^bold>g [^] x), s_act1), auth.State_Void, s_act2)) + (map_spmf (\y. ((Some ((\<^bold>g [^] x) [^] y, \<^bold>g [^] x, \<^bold>g [^] y), CState_Half 0, CState_Void), (auth.State_Collect \, s_act1), auth.State_Void, s_act2)) rsample_nat)" +\ \(Auth1 =a)@(Auth2 =1)\ + | srl_0_1: "S_rl (map_spmf (\y. (((), CState_Void, CState_Half y), (auth.State_Void, s_act1), auth.State_Store (\<^bold>g [^] y), s_act2)) rsample_nat) + (return_spmf ((None, CState_Void, CState_Half 0), (auth.State_Void, s_act1), auth.State_Store \, s_act2))" +\ \../(Auth1 =a)@(Auth2 =1) \# wl\ + | srl_1_1: "S_rl (map_spmf (\yx. (((), CState_Half (snd yx), CState_Half (fst yx)), (auth.State_Store (\<^bold>g [^] snd yx), s_act1), auth.State_Store (\<^bold>g [^] fst yx), s_act2)) rsample_pair_nn) + (return_spmf ((None, CState_Half 0, CState_Half 0), (auth.State_Store \, s_act1), auth.State_Store \, s_act2))" + | srl_2_1: "S_rl (map_spmf (\yx. (((), CState_Half (snd yx), CState_Half (fst yx)), (auth.State_Collect (\<^bold>g [^] snd yx), s_act1), auth.State_Store (\<^bold>g [^] fst yx), s_act2)) rsample_pair_nn) + (return_spmf ((None, CState_Half 0, CState_Half 0), (auth.State_Collect \, s_act1), auth.State_Store \, s_act2))" +\ \../(Auth1 =a)@(Auth2 =1) \# look\ + | srl_1c_1c: "S_rl (return_spmf (((), CState_Half x, CState_Half y), (auth.State_Store (\<^bold>g [^] x), s_act1), auth.State_Store (\<^bold>g [^] y), s_act2)) + (return_spmf ((Some ((\<^bold>g [^] x) [^] y, \<^bold>g [^] x, \<^bold>g [^] y), CState_Half 0, CState_Half 0), (auth.State_Store \, s_act1), auth.State_Store \, s_act2))" + | srl_2c_1c: "S_rl (return_spmf (((), CState_Half x, CState_Half y), (auth.State_Collect (\<^bold>g [^] x), s_act1), auth.State_Store (\<^bold>g [^] y), s_act2)) + (return_spmf ((Some ((\<^bold>g [^] x) [^] y, \<^bold>g [^] x, \<^bold>g [^] y), CState_Half 0, CState_Half 0), (auth.State_Collect \, s_act1), auth.State_Store \, s_act2))" + | srl_3c_1c: "S_rl (return_spmf (((), CState_Half x, CState_Full (y, z)), (auth.State_Collected, s_act1), auth.State_Store (\<^bold>g [^] y), s_act2)) + (return_spmf ((Some (z, \<^bold>g [^] x, \<^bold>g [^] y), CState_Half 0, CState_Full (0, \)), (auth.State_Collected, s_act1), auth.State_Store \, s_act2))" + if "z = (\<^bold>g [^] x) [^] y" +\ \(Auth1 =a)@(Auth2 =2)\ + | srl_0_2: "S_rl (map_spmf (\y. (((), CState_Void, CState_Half y), (auth.State_Void, s_act1), auth.State_Collect (\<^bold>g [^] y), s_act2)) rsample_nat) + (return_spmf ((None, CState_Void, CState_Half 0), (auth.State_Void, s_act1), auth.State_Collect \, s_act2))" +\ \../(Auth1 =a)@(Auth2 =2) \# wl\ + | srl_1_2: "S_rl (map_spmf (\yx. (((), CState_Half (snd yx), CState_Half (fst yx)), (auth.State_Store (\<^bold>g [^] snd yx), s_act1), auth.State_Collect (\<^bold>g [^] fst yx), s_act2)) rsample_pair_nn) + (return_spmf ((None, CState_Half 0, CState_Half 0), (auth.State_Store \, s_act1), auth.State_Collect \, s_act2))" + | srl_2_2: "S_rl (map_spmf (\yx. (((), CState_Half (snd yx), CState_Half (fst yx)), (auth.State_Collect (\<^bold>g [^] snd yx), s_act1), auth.State_Collect (\<^bold>g [^] fst yx), s_act2)) rsample_pair_nn) + (return_spmf ((None, CState_Half 0, CState_Half 0), (auth.State_Collect \, s_act1), auth.State_Collect \, s_act2))" +\ \../(Auth1 =a)@(Auth2 =2) \# look\ + | srl_1c_2c: "S_rl (return_spmf (((), CState_Half x, CState_Half y), (auth.State_Store (\<^bold>g [^] x), s_act1), auth.State_Collect (\<^bold>g [^] y), s_act2)) + (return_spmf ((Some ((\<^bold>g [^] x) [^] y, \<^bold>g [^] x, \<^bold>g [^] y), CState_Half 0, CState_Half 0), (auth.State_Store \, s_act1), auth.State_Collect \, s_act2))" + | srl_2c_2c: "S_rl (return_spmf (((), CState_Half x, CState_Half y), (auth.State_Collect (\<^bold>g [^] x), s_act1), auth.State_Collect (\<^bold>g [^] y), s_act2)) + (return_spmf ((Some ((\<^bold>g [^] x) [^] y, \<^bold>g [^] x, \<^bold>g [^] y), CState_Half 0, CState_Half 0), (auth.State_Collect \, s_act1), auth.State_Collect \, s_act2))" + | srl_3c_2c: "S_rl (return_spmf (((), CState_Half x, CState_Full (y, z)), (auth.State_Collected, s_act1), auth.State_Collect (\<^bold>g [^] y), s_act2)) + (return_spmf ((Some (z, \<^bold>g [^] x, \<^bold>g [^] y), CState_Half 0, CState_Full (0, \)), (auth.State_Collected, s_act1), auth.State_Collect \, s_act2))" + if "z = (\<^bold>g [^] x) [^] y" +\ \(Auth1 =a)@(Auth2 =3)\ + | srl_1c_3c: "S_rl (return_spmf (((), CState_Full (x, z), CState_Half y), (auth.State_Store (\<^bold>g [^] x), s_act1), auth.State_Collected, s_act2)) + (return_spmf ((Some (z, \<^bold>g [^] x, \<^bold>g [^] y), CState_Full (0, \), CState_Half 0), (auth.State_Store \, s_act1), auth.State_Collected, s_act2))" + if "z = (\<^bold>g [^] y) [^] x" + | srl_2c_3c: "S_rl (return_spmf (((), CState_Full (x, z), CState_Half y), (auth.State_Collect (\<^bold>g [^] x), s_act1), auth.State_Collected, s_act2)) + (return_spmf ((Some (z, \<^bold>g [^] x, \<^bold>g [^] y), CState_Full (0, \), CState_Half 0), (auth.State_Collect \, s_act1), auth.State_Collected, s_act2))" + if "z = (\<^bold>g [^] y) [^] x" + | srl_3c_3c: "S_rl (return_spmf (((), CState_Full (x, z), CState_Full (y, z)), (auth.State_Collected, s_act1), auth.State_Collected, s_act2)) + (return_spmf ((Some (z, \<^bold>g [^] x, \<^bold>g [^] y), CState_Full (0, \), CState_Full (0, \)), (auth.State_Collected, s_act1), auth.State_Collected, s_act2))" + if "z = (\<^bold>g [^] y) [^] x" +\ \(Auth1 =0)@(Auth2 =1')\ + | srl_0_1': "S_rl (return_spmf (((), CState_Void, CState_Half y), (auth.State_Void, s_act1), auth.State_Store (\<^bold>g [^] y), s_act2)) + (map_spmf (\x. ((Some ((\<^bold>g [^] x) [^] y, \<^bold>g [^] x, \<^bold>g [^] y), CState_Void, CState_Half 0), (auth.State_Void, s_act1), auth.State_Store \, s_act2)) rsample_nat)" +\ \(Auth1 =0)@(Auth2 =2')\ + | srl_0_2': "S_rl (return_spmf (((), CState_Void, CState_Half y), (auth.State_Void, s_act1), auth.State_Collect (\<^bold>g [^] y), s_act2)) + (map_spmf (\x. ((Some ((\<^bold>g [^] x) [^] y, \<^bold>g [^] x, \<^bold>g [^] y), CState_Void, CState_Half 0), (auth.State_Void, s_act1), auth.State_Collect \, s_act2)) rsample_nat)" + + +private lemma trac_eq_core_rl: "trace_core_eq real_core' (basic_core DH0_sample) + (UNIV <+> UNIV) ((UNIV <+> UNIV <+> UNIV) <+> UNIV <+> UNIV <+> UNIV) ((UNIV <+> UNIV) <+> UNIV <+> UNIV) + (return_spmf real_s_core') (return_spmf basic_core_sinit)" +proof - + have power_commute: "(\<^bold>g [^] x) [^] (y :: nat) = (\<^bold>g [^] y) [^] (x :: nat)" for x y + by (simp add: nat_pow_pow mult.commute) + + have [simp]: "weight_spmf rsample_nat = 1" + by (simp add: finite_carrier order_gt_0_iff_finite) + + have [simp]: "mk_lossless rsample_nat = rsample_nat" + by (simp add: mk_lossless_def) + + have [simp]: "mk_lossless rsample_pair_nn = rsample_pair_nn" + by (simp add: mk_lossless_def) + + note [simp] = basic_core_oracle_usr_def basic_core_helper_def + exec_gpv_bind spmf.map_comp map_bind_spmf bind_map_spmf bind_spmf_const o_def Let_def split_def + + show ?thesis + apply (rule trace_core_eq_simI_upto[where S=S_rl]) + subgoal Init_OK + by (simp add: real_s_core'_def srl_0_0) + subgoal POut_OK for s_l s_r query + apply (cases query) + subgoal for e_auth1 by (cases e_auth1; erule S_rl.cases; auto simp add: map_spmf_conv_bind_spmf[symmetric] split!: if_splits) + subgoal for e_auth2 by (cases e_auth2; erule S_rl.cases; auto simp add: map_spmf_conv_bind_spmf[symmetric] split!: if_splits) + done + subgoal PState_OK for s_l s_r query + apply (cases query) + subgoal for e_auth1 by(cases e_auth1; erule S_rl.cases; auto simp add: map_spmf_conv_bind_spmf[symmetric] split!: if_splits intro: S_rl.intros trace_eq_simcl.base) + subgoal for e_auth2 by (cases e_auth2; erule S_rl.cases; auto simp add: map_spmf_conv_bind_spmf[symmetric] split!: if_splits intro: S_rl.intros trace_eq_simcl.base) + done + subgoal AOut_OK for sl sr q + apply (cases q) + subgoal for q_auth1 + apply (cases q_auth1) + subgoal for q_drop by (erule S_rl.cases; simp) + subgoal for q_lfe + apply (cases q_lfe) + subgoal for q_look by(erule S_rl.cases; auto simp add: DH0_sample_def pair_spmf_alt_def) + subgoal for q_fedit by (cases q_fedit; erule S_rl.cases; auto simp add: DH0_sample_def pair_spmf_alt_def) + done + done + subgoal for q_auth2 + apply (cases q_auth2) + subgoal for q_drop by (erule S_rl.cases; simp) + subgoal for q_lfe + apply (cases q_lfe) + subgoal for q_look by(erule S_rl.cases; auto simp add: DH0_sample_def pair_spmf_alt_def) + subgoal for q_fedit by (cases q_fedit; erule S_rl.cases; auto simp add: DH0_sample_def pair_spmf_alt_def) + done + done + done + subgoal AState_OK for sl sr q s1 s2 s1' s2' oa + apply (cases q) + subgoal for q_auth1 + apply (cases q_auth1) + subgoal for q_drop by (erule S_rl.cases; simp) + subgoal for q_lfe + apply (cases q_lfe) + subgoal for q_look + proof (erule S_rl.cases, goal_cases) + case (2 s_act1 s_act2) \ \Corresponds to @{thm [source] srl_1_0}\ + then show ?case + apply(cases s1') + apply (clarsimp simp add: DH0_sample_def) + apply(simp add: bind_bind_conv_pair_spmf) + apply(simp add: map_spmf_conv_bind_spmf[symmetric]) + apply (subst cond_spmf_fst_pair_spmf1[unfolded map_prod_def split_def]) + apply(simp) + apply(subst (1 2) cond_spmf_fst_map_Pair1; simp add: inj_on_def) + by(subst (1 2 3 4) inv_into_f_f; simp add: inj_on_def trace_eq_simcl.base S_rl.intros) + next + case (4 x s_act1 s_act2) \ \Corresponds to @{thm [source] srl_1'_0}\ + then show ?case + by(auto simp add: DH0_sample_def map_spmf_conv_bind_spmf[symmetric] intro!: trace_eq_simcl.base S_rl.intros) + next + case (7 s_act1 s_act2) \ \Corresponds to @{thm [source] srl_1_1}\ + then show ?case + apply(clarsimp simp add: DH0_sample_def pair_spmf_alt_def) + apply(subst bind_commute_spmf) + apply(simp add: bind_bind_conv_pair_spmf) + apply(simp add: map_spmf_conv_bind_spmf[symmetric]) + apply (subst (1 2) cond_spmf_fst_pair_spmf1[unfolded map_prod_def split_def]) + apply(simp) + apply(subst (1 2) cond_spmf_fst_map_Pair1; simp add: inj_on_def) + by (subst (1 2 3 4) inv_into_f_f; simp add: inj_on_def trace_eq_simcl_map S_rl.intros) + next + case (13 s_act1 s_act2) \ \Corresponds to @{thm [source] srl_1_2}\ + then show ?case + apply(clarsimp simp add: DH0_sample_def pair_spmf_alt_def) + apply(subst bind_commute_spmf) + apply(simp add: bind_bind_conv_pair_spmf) + apply(simp add: map_spmf_conv_bind_spmf[symmetric]) + apply (subst (1 2) cond_spmf_fst_pair_spmf1[unfolded map_prod_def split_def]) + apply(simp) + apply(subst (1 2) cond_spmf_fst_map_Pair1; simp add: inj_on_def) + by(subst (1 2 3 4) inv_into_f_f; simp add: inj_on_def trace_eq_simcl_map S_rl.intros) + qed (auto intro: S_rl.intros) + subgoal for q_fedit + apply (cases q_fedit) + by (erule S_rl.cases, goal_cases) (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro!: trace_eq_simcl.base intro: S_rl.intros) + done + done + subgoal for q_auth2 + apply (cases q_auth2) + subgoal for q_drop by (erule S_rl.cases; simp) + subgoal for q_lfe + apply (cases q_lfe) + subgoal for q_look + proof (erule S_rl.cases, goal_cases) + case (6 s_act1 s_act2) \ \Corresponds to @{thm [source] srl_0_1}\ + then show ?case + apply(clarsimp simp add: DH0_sample_def) + apply(subst bind_commute_spmf) + apply(simp add: bind_bind_conv_pair_spmf) + apply(simp add: map_spmf_conv_bind_spmf[symmetric]) + apply(subst cond_spmf_fst_pair_spmf1[simplified map_prod_def split_def]) + apply(simp) + apply(subst (1 2) cond_spmf_fst_map_Pair1; simp add: inj_on_def) + by(subst (1 2 3 4) inv_into_f_f; simp add: inj_on_def trace_eq_simcl.base S_rl.intros) + next + case (7 s_act1 s_act2) \ \Corresponds to @{thm [source] srl_1_1}\ + then show ?case + apply(clarsimp simp add: DH0_sample_def) + apply(subst bind_commute_spmf) + apply(simp add: bind_bind_conv_pair_spmf) + apply(simp add: map_spmf_conv_bind_spmf[symmetric]) + apply(subst (1 2) cond_spmf_fst_pair_spmf1[simplified map_prod_def split_def]) + apply(simp) + apply(subst (1 2) cond_spmf_fst_map_Pair1; simp add: inj_on_def) + by(subst (1 2 3 4) inv_into_f_f; simp add: inj_on_def trace_eq_simcl_map S_rl.intros) + next + case (8 s_act1 s_act2) \ \Corresponds to @{thm [source] srl_2_1}\ + then show ?case + apply(clarsimp simp add: DH0_sample_def) + apply(subst bind_commute_spmf) + apply(simp add: bind_bind_conv_pair_spmf) + apply(simp add: map_spmf_conv_bind_spmf[symmetric]) + apply(subst (1 2) cond_spmf_fst_pair_spmf1[simplified map_prod_def split_def]) + apply(simp) + apply(subst (1 2) cond_spmf_fst_map_Pair1; simp add: inj_on_def) + by(subst (1 2 3 4) inv_into_f_f; simp add: inj_on_def trace_eq_simcl_map S_rl.intros) + next + case (21 y s_act1 s_act2) \ \Corresponds to @{thm [source] srl_0_1'}\ + then show ?case + by(auto simp add: map_spmf_conv_bind_spmf[symmetric] intro!: trace_eq_simcl.base intro: S_rl.intros) + qed (auto intro: S_rl.intros) + subgoal for q_fedit + apply (cases q_fedit) + by (erule S_rl.cases, goal_cases) (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro!: trace_eq_simcl.base intro: S_rl.intros) + done + done + done + subgoal UOut_OK for sl sr q + apply (cases q) + subgoal for q_usr + apply (cases q_usr) + subgoal for q_alice by (erule S_rl.cases; simp add: DH0_sample_def pair_spmf_alt_def power_commute) + subgoal for q_bob by (erule S_rl.cases; auto simp add: bind_bind_conv_pair_spmf apfst_def DH0_sample_def power_commute split!: if_split) + done + subgoal for q_act + apply (cases q_act) + subgoal for q_alice + by (erule S_rl.cases; auto simp add: left_gpv_bind_gpv exec_gpv_parallel_oracle_left map_gpv_bind_gpv gpv.map_id map_gpv'_bind_gpv map'_lift_spmf intro!: bind_spmf_cong) + subgoal for q_bob + by (erule S_rl.cases; auto simp add: right_gpv_bind_gpv exec_gpv_parallel_oracle_right map_gpv_bind_gpv gpv.map_id map_gpv'_bind_gpv map'_lift_spmf intro!: bind_spmf_cong) + done + done + subgoal UState_OK for sl sr q + apply (cases q) + subgoal for q_usr + apply (cases q_usr) + subgoal for q_alice + proof (erule S_rl.cases, goal_cases) + case (13 s_act1 s_act2) \ \Corresponds to @{thm [source] srl_1_2}\ + then show ?case + apply(clarsimp simp add: DH0_sample_def pair_spmf_alt_def) + apply(subst (1) bind_commute_spmf) + apply(simp add: bind_bind_conv_pair_spmf) + apply(subst (1 2) cond_spmf_fst_bind) + by (auto simp add: power_commute intro!: trace_eq_simcl_bind S_rl.intros) + next + case (14 s_act1 s_act2) \ \Corresponds to @{thm [source] srl_2_2}\ + then show ?case + apply(clarsimp simp add: DH0_sample_def pair_spmf_alt_def) + apply(subst (1) bind_commute_spmf) + apply(simp add: bind_bind_conv_pair_spmf) + apply(subst (1 2) cond_spmf_fst_bind) + by (auto simp add: power_commute intro!: trace_eq_simcl_bind S_rl.intros) + qed (auto intro: S_rl.intros) + subgoal for q_bob + proof (erule S_rl.cases, goal_cases) + case (8 s_act1 s_act2) \ \Corresponds to @{thm [source] srl_2_1}\ + then show ?case + apply(clarsimp simp add: DH0_sample_def) + apply(subst bind_commute_spmf) + apply(simp add: bind_bind_conv_pair_spmf power_commute) + apply(subst (1 2) cond_spmf_fst_bind) + by (auto simp add: power_commute intro!: trace_eq_simcl_bind S_rl.intros) + next + case (14 s_act1 s_act2) \ \Corresponds to @{thm [source] srl_2_2}\ + then show ?case + apply(clarsimp simp add: DH0_sample_def) + apply(subst bind_commute_spmf) + apply(simp add: bind_bind_conv_pair_spmf power_commute) + apply(subst (1 2) cond_spmf_fst_bind) + by (auto simp add: power_commute intro!: trace_eq_simcl_bind S_rl.intros) + qed (auto simp add: power_commute intro: S_rl.intros) + done + subgoal for q_act + apply (cases q_act) + subgoal for a_alice + proof (erule S_rl.cases, goal_cases) + case (1 s_act1 s_act2) \ \Corresponds to @{thm [source] srl_0_0}\ + then show ?case + apply (simp add: left_gpv_bind_gpv pair_spmf_alt_def map_gpv_bind_gpv gpv.map_id map_gpv'_bind_gpv map'_lift_spmf split!: if_splits) + by (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro: trace_eq_simcl.base S_rl.intros) + next + case (6 s_act1 s_act2) \ \Corresponds to @{thm [source] srl_0_1}\ + then show ?case + apply (simp add: left_gpv_bind_gpv pair_spmf_alt_def map_gpv_bind_gpv gpv.map_id map_gpv'_bind_gpv map'_lift_spmf split!: if_splits) + apply (subst bind_bind_conv_pair_spmf) + by (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro: trace_eq_simcl.base S_rl.intros) + next + case (12 s_act1 s_act2) \ \Corresponds to @{thm [source] srl_0_2}\ + then show ?case + apply (simp add: left_gpv_bind_gpv pair_spmf_alt_def map_gpv_bind_gpv gpv.map_id map_gpv'_bind_gpv map'_lift_spmf split!: if_splits) + apply (subst bind_bind_conv_pair_spmf) + by (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro: trace_eq_simcl.base S_rl.intros) + next + case (21 y s_act1 s_act2) \ \Corresponds to @{thm [source] srl_0_2'}\ + then show ?case + apply (simp add: left_gpv_bind_gpv pair_spmf_alt_def map_gpv_bind_gpv gpv.map_id map_gpv'_bind_gpv map'_lift_spmf split!: if_splits) + by (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro: trace_eq_simcl_map S_rl.intros) + next + case (22 y s_act1 s_act2) \ \Corresponds to @{thm [source] srl_0_1'}\ + then show ?case + apply (simp add: left_gpv_bind_gpv pair_spmf_alt_def map_gpv_bind_gpv gpv.map_id map_gpv'_bind_gpv map'_lift_spmf split!: if_splits) + by (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro: trace_eq_simcl_map S_rl.intros) + qed (simp_all split!: if_splits) + subgoal for a_bob + proof (erule S_rl.cases, goal_cases) + case (1 s_act1 s_act2) \ \Corresponds to @{thm [source] srl_0_0}\ + then show ?case + apply(clarsimp simp add: right_gpv_bind_gpv pair_spmf_alt_def map_gpv_bind_gpv gpv.map_id map_gpv'_bind_gpv map'_lift_spmf split!: if_splits) + by (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro: trace_eq_simcl.base S_rl.intros) + next + case (2 s_act1 s_act2) \ \Corresponds to @{thm [source] srl_1_0}\ + then show ?case + apply(clarsimp simp add: right_gpv_bind_gpv pair_spmf_alt_def map_gpv_bind_gpv gpv.map_id map_gpv'_bind_gpv map'_lift_spmf split!: if_splits) + apply (subst bind_commute_spmf, subst bind_bind_conv_pair_spmf) + by (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro: trace_eq_simcl.base S_rl.intros) + next + case (3 s_act1 s_act2) \ \Corresponds to @{thm [source] srl_2_0}\ + then show ?case + apply(clarsimp simp add: right_gpv_bind_gpv pair_spmf_alt_def map_gpv_bind_gpv gpv.map_id map_gpv'_bind_gpv map'_lift_spmf split!: if_splits) + apply (subst bind_commute_spmf, subst bind_bind_conv_pair_spmf) + by (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro: trace_eq_simcl.base S_rl.intros) + next + case (4 x s_act1 s_act2) \ \Corresponds to @{thm [source] srl_1'_0}\ + then show ?case + apply(clarsimp simp add: right_gpv_bind_gpv pair_spmf_alt_def map_gpv_bind_gpv gpv.map_id map_gpv'_bind_gpv map'_lift_spmf split!: if_splits) + by (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro: trace_eq_simcl_map S_rl.intros) + next + case (5 x s_act1 s_act2) \ \Corresponds to @{thm [source] srl_2'_0}\ + then show ?case + apply(clarsimp simp add: right_gpv_bind_gpv pair_spmf_alt_def map_gpv_bind_gpv gpv.map_id map_gpv'_bind_gpv map'_lift_spmf split!: if_splits) + by (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro: trace_eq_simcl_map S_rl.intros) + qed (simp_all split!: if_splits) + done + done + done +qed + +lemma trace_eq_fuse_rl: "UNIV \\<^sub>R 1\<^sub>C |\<^sub>= rassocl\<^sub>C \ RES (fused_resource.fuse real_core' real_rest') (real_s_core', real_s_rest') + \ RES (fused_resource.fuse (lazy_core DH0_sample) lazy_rest) (basic_core_sinit, basic_rest_sinit)" +proof - + have fact1: "UNIV \\<^sub>R 1\<^sub>C |\<^sub>= rassocl\<^sub>C \ RES (fused_resource.fuse (basic_core DH0_sample) basic_rest) (basic_core_sinit, basic_rest_sinit) \ + RES (fused_resource.fuse (lazy_core DH0_sample) lazy_rest) (basic_core_sinit, basic_rest_sinit)" + proof - + have [simp]: "\_full \\<^sub>\ ((\_full \\<^sub>\ \_full) \\<^sub>\ \_full) \res RES (fused_resource.fuse (basic_core DH0_sample) basic_rest) (basic_core_sinit, basic_rest_sinit) \" for s + apply (rule WT_resource_of_oracle, rule WT_calleeI) + by (case_tac call, rename_tac [!] x, case_tac [!] x, rename_tac [!] y, case_tac [!] y) + (auto simp add: fused_resource.fuse.simps parallel_eoracle_def) + + note [simp] = exec_gpv_bind spmf.map_comp o_def map_bind_spmf bind_map_spmf bind_spmf_const + + show ?thesis + apply(subst attach_wiring_resource_of_oracle) + apply(rule wiring_parallel_converter2 wiring_id_converter[where \=\_full] wiring_rassocl[of \_full \_full \_full])+ + apply simp_all + apply (rule eq_resource_on_resource_of_oracleI[where S="(=)"]) + apply(simp_all add: eq_on_def relator_eq) + apply(rule ext)+ + apply(subst fuse_ishift_core_to_rest[where core="basic_core DH0_sample" and rest=basic_rest and core'="lazy_core DH0_sample" and + rest'=lazy_rest and fn=basic_core_helper and h_out="map_sum (\_. Out_Activation_Alice) (\_. Out_Activation_Bob)", simplified]) + apply (simp_all add: lazy_rest_def) + apply(fold apply_comp_wiring) + by (simp add: comp_wiring_def parallel2_wiring_def split_def sum.map_comp lassocr\<^sub>w_def rassocl\<^sub>w_def id_def[symmetric] sum.map_id) + qed + + have fact2: "UNIV \\<^sub>R 1\<^sub>C |\<^sub>= rassocl\<^sub>C \ RES (fused_resource.fuse real_core' real_rest') (real_s_core', real_s_rest') \ + 1\<^sub>C |\<^sub>= rassocl\<^sub>C \ RES (fused_resource.fuse (basic_core DH0_sample) basic_rest) (basic_core_sinit, basic_rest_sinit)" + (is "_ \\<^sub>R _ \ RES ?L ?s_l \ _ \ RES ?R ?s_r") proof - + have [simp]: "trace_rest_eq basic_rest basic_rest UNIV UNIV s s" for s + by (rule rel_rest'_into_trace_rest_eq[where S="(=)" and M="(=)"]) (simp_all add: eq_onp_def rel_rest'_eq) + have [simp]: "\_full \\<^sub>\ \_full \c callee_of_rest basic_rest s \" for s + unfolding callee_of_core_def by (rule WT_calleeI) (cases s, case_tac call, rename_tac [!] x, case_tac [!] x, auto) + have [simp]: "\_full \\<^sub>\ (\_full \\<^sub>\ \_full) \c callee_of_core (basic_core DH0_sample) s \" for s + unfolding callee_of_core_def by (rule WT_calleeI) (cases s, case_tac call, rename_tac [!] x, case_tac [!] x, auto) + have [simp]: "\_full \\<^sub>\ (\_full \\<^sub>\ \_full) \c callee_of_core real_core' s \" for s + unfolding callee_of_core_def by (rule WT_calleeI) (cases s, case_tac call, rename_tac [!] x, case_tac [!] x, auto) + + have loc[simplified]: "((UNIV <+> UNIV) <+> UNIV <+> UNIV) \\<^sub>C ?L(?s_l) \ ?R(?s_r)" + by (rule fuse_trace_eq[where \E=\_full and \CA=\_full and \CU=\_full and \RA=\_full and \RU=\_full, simplified outs_plus_\ outs_\_full]) + (simp_all add: real_rest'_def real_s_rest'_def trac_eq_core_rl[simplified]) + + show ?thesis + apply (rule attach_trace_eq'[where \=\_full and \'=\_full, simplified outs_plus_\ outs_\_full]) + apply (subst trace_eq'_resource_of_oracle, rule loc[simplified]) + by (simp_all add: WT_converter_\_full) + qed + + show ?thesis using fact2[simplified eq_resource_on_UNIV_D[OF fact1]] by blast +qed + +lemma connect_real: "connect D (obsf_resource real_resource) = connect D (obsf_resource (RES (fused_resource.fuse (lazy_core DH0_sample) lazy_rest) (basic_core_sinit, basic_rest_sinit)))" +proof - + have [simp]: "\_full \res real_resource \" + proof - + have [simp]: "\_full \\<^sub>\ ((\_full \\<^sub>\ \_full) \\<^sub>\ \_full) \res RES (fused_resource.fuse real_core' real_rest') (real_s_core', real_s_rest') \" + apply (rule WT_resource_of_oracle) + apply (rule WT_calleeI) + subgoal for s q + apply (cases s, cases q, rename_tac [!] x, case_tac [!] x) + prefer 3 + subgoal for s_cnv_core _ _ _ _ y + apply (cases s_cnv_core, rename_tac s_cnvs s_auth1 s_kern2 s_shell2) + apply (case_tac s_auth1, rename_tac s_kern1 s_shell1) + apply (case_tac s_cnvs, rename_tac su s_cnv1 s_cnv2) + apply (cases y, rename_tac [!] z, case_tac [!] z, rename_tac [!] query) + apply (auto simp add: fused_resource.fuse.simps split_def apfst_def) + apply(case_tac "(s_cnv1, Inl query)" rule: alice_callee.cases; auto split!: sum.splits auth.ousr_bob.splits simp add: Let_def o_def) + apply(case_tac "(s_cnv2, Inl query)" rule: bob_callee.cases; auto split!: sum.splits auth.ousr_bob.splits simp add: Let_def o_def) + apply(case_tac "(s_cnv1, Inr query)" rule: alice_callee.cases; auto split!: sum.splits + simp add: Let_def o_def map_gpv_bind_gpv left_gpv_bind_gpv map_gpv'_bind_gpv exec_gpv_bind) + apply(case_tac "(s_cnv2, Inr query)" rule: bob_callee.cases; auto split!: sum.splits + simp add: Let_def o_def map_gpv_bind_gpv right_gpv_bind_gpv map_gpv'_bind_gpv exec_gpv_bind) + done + by (auto simp add: fused_resource.fuse.simps) + done + + show ?thesis + unfolding attach_real + apply (rule WT_resource_attach[where \'="\_full \\<^sub>\ ((\_full \\<^sub>\ \_full) \\<^sub>\ \_full)"]) + apply (rule WT_converter_mono[of "\_full \\<^sub>\ (\_full \\<^sub>\ (\_full \\<^sub>\ \_full))" "\_full \\<^sub>\ ((\_full \\<^sub>\ \_full) \\<^sub>\ \_full)"]) + apply (rule WT_converter_parallel_converter2) + apply (rule WT_intro)+ + by (simp_all add: \_full_le_plus_\) + qed + + show ?thesis + using trace_eq_obsf_resourceI[OF trace_eq_fuse_rl, folded attach_real] + by (rule connect_cong_trace[where A="UNIV" and \=\_full]) + (auto intro!: WT_obsf_resource[where \=\_full, simplified exception_\_full]) +qed + +end + +end + +end + +subsection \Concrete security\ + +context diffie_hellman begin + +context + fixes + auth1_rest :: "('auth1_s_rest, auth.event, 'auth1_iadv_rest, 'auth1_iusr_rest, 'auth1_oadv_rest, 'auth1_ousr_rest) rest_wstate" and + auth2_rest :: "('auth2_s_rest, auth.event, 'auth2_iadv_rest, 'auth2_iusr_rest, 'auth2_oadv_rest, 'auth2_ousr_rest) rest_wstate" and + \_adv_rest1 and \_adv_rest2 and \_usr_rest1 and \_usr_rest2 and I_auth1_rest and I_auth2_rest + assumes + WT_auth1_rest [WT_intro]: "WT_rest \_adv_rest1 \_usr_rest1 I_auth1_rest auth1_rest" and + WT_auth2_rest [WT_intro]: "WT_rest \_adv_rest2 \_usr_rest2 I_auth2_rest auth2_rest" +begin + +theorem secure: + defines "\_real \ ((\_full \\<^sub>\ (\_full \\<^sub>\ \_uniform (auth.Inp_Fedit ` (carrier \)) UNIV)) \\<^sub>\ (\_full \\<^sub>\ (\_full \\<^sub>\ \_uniform (auth.Inp_Fedit ` (carrier \)) UNIV))) \\<^sub>\ (\_adv_rest1 \\<^sub>\ \_adv_rest2)" + and "\_common \ (\_uniform UNIV (key.Out_Alice ` carrier \) \\<^sub>\ \_uniform UNIV (key.Out_Bob ` carrier \)) \\<^sub>\ ((\_full \\<^sub>\ \_full) \\<^sub>\ (\_usr_rest1 \\<^sub>\ \_usr_rest2))" + and "\_ideal \ \_full \\<^sub>\ (\_full \\<^sub>\ (\_adv_rest1 \\<^sub>\ \_adv_rest2))" + shows "constructive_security_obsf + (real_resource TYPE(_) TYPE(_) auth1_rest auth2_rest) + (key.resource (ideal_rest auth1_rest auth2_rest)) + (let sim = CNV sim_callee None in ((sim |\<^sub>= 1\<^sub>C ) \ lassocr\<^sub>C)) + \_real \_ideal \_common \ + (ddh.advantage \ (DH_adversary TYPE(_) TYPE(_) auth1_rest auth2_rest \))" +proof + let ?sim = "(let sim = CNV sim_callee None in ((sim |\<^sub>= 1\<^sub>C ) \ lassocr\<^sub>C))" + + have *[WT_intro]: "(\_full \\<^sub>\ (\_full \\<^sub>\ \_uniform (auth.Inp_Fedit ` carrier \) UNIV)) \\<^sub>\ + (\_full \\<^sub>\ (\_full \\<^sub>\ \_uniform (auth.Inp_Fedit ` carrier \) UNIV)), \_full \\<^sub>\ \_full \\<^sub>C CNV sim_callee s \" for s + apply (rule WT_converter_of_callee, simp_all) + apply (rename_tac s q r s', case_tac "(s, q)" rule: sim_callee.cases) + by (auto split: if_splits option.splits) + + show "\_real \\<^sub>\ \_common \res real_resource TYPE(_) TYPE(_) auth1_rest auth2_rest \" + proof - + have [WT_intro]: "\_uniform UNIV (key.Out_Alice ` carrier \) \\<^sub>\ \_full, \_uniform (auth.Inp_Send ` carrier \) UNIV \\<^sub>\ \_uniform UNIV (auth.Out_Recv ` carrier \) \\<^sub>C CNV alice_callee CState_Void \" + apply (rule WT_converter_of_callee_invar[where I="pred_cstate (\x. x \ carrier \)"]) + subgoal for s q by (cases "(s, q)" rule: alice_callee.cases) (auto simp add: Let_def split: auth.ousr_bob.splits) + subgoal for s q by (cases "(s, q)" rule: alice_callee.cases) (auto split: if_split_asm auth.ousr_bob.splits simp add: Let_def) + subgoal by simp + done + + have [WT_intro]: "\_uniform UNIV (key.Out_Bob ` carrier \) \\<^sub>\ \_full, \_uniform UNIV (auth.Out_Recv ` carrier \) \\<^sub>\ \_uniform (auth.Inp_Send ` carrier \) UNIV \\<^sub>C CNV bob_callee CState_Void \" + apply (rule WT_converter_of_callee_invar[where I="pred_cstate (\x. x \ carrier \)"]) + subgoal for s q by (cases "(s, q)" rule: bob_callee.cases) (auto simp add: Let_def split: auth.ousr_bob.splits) + subgoal for s q by (cases "(s, q)" rule: bob_callee.cases) (auto simp add: Let_def split: auth.ousr_bob.splits) + subgoal by simp + done + + show ?thesis + unfolding \_real_def \_common_def real_resource_def Let_def fused_wiring_def + by (rule WT_intro)+ + qed + + show "\_ideal \\<^sub>\ \_common \res key.resource (ideal_rest auth1_rest auth2_rest) \" + unfolding \_ideal_def \_common_def key.resource_def + apply(rule callee_invariant_on.WT_resource_of_oracle[where I="\((kernel, _), _, s12). key.set_s_kernel kernel \ carrier \ \ pred_prod I_auth1_rest I_auth2_rest s12"]; (simp add: WT_restD[OF WT_auth1_rest] WT_restD[OF WT_auth2_rest])?) + apply unfold_locales + subgoal for s q + apply (cases "(ideal_rest auth1_rest auth2_rest, s, q)" rule: key.fuse.cases; clarsimp split: if_split_asm) + apply (auto simp add: translate_eoracle_def parallel_eoracle_def plus_eoracle_def) + apply(auto dest: WT_restD_rfunc_adv[OF WT_auth1_rest] WT_restD_rfunc_adv[OF WT_auth2_rest] + WT_restD_rfunc_usr[OF WT_auth1_rest] WT_restD_rfunc_usr[OF WT_auth2_rest] key.foldl_poke_invar) + apply(auto dest!: key.foldl_poke_invar split: plus_oracle_split_asm) + done + subgoal for s + apply(rule WT_calleeI) + subgoal for x y s' + apply(auto simp add: translate_eoracle_def parallel_eoracle_def plus_eoracle_def) + apply(auto dest: WT_restD_rfunc_adv[OF WT_auth1_rest] WT_restD_rfunc_adv[OF WT_auth2_rest] + WT_restD_rfunc_usr[OF WT_auth1_rest] WT_restD_rfunc_usr[OF WT_auth2_rest] split: if_split_asm) + apply(case_tac xa) + apply auto + done + done + done + + show "\_real, \_ideal \\<^sub>C ?sim \" + unfolding \_real_def \_ideal_def Let_def + by(rule WT_intro)+ + + show "pfinite_converter \_real \_ideal ?sim" + proof - + have [pfinite_intro]:"pfinite_converter ((\_full \\<^sub>\ (\_full \\<^sub>\ \_uniform (auth.Inp_Fedit ` carrier \) UNIV)) \\<^sub>\ + (\_full \\<^sub>\ (\_full \\<^sub>\ \_uniform (auth.Inp_Fedit ` carrier \) UNIV))) (\_full \\<^sub>\ \_full) (CNV sim_callee s)" for s + apply(rule raw_converter_invariant.pfinite_converter_of_callee[where I="\_. True"], simp_all) + subgoal + apply (unfold_locales, simp_all) + subgoal for s1 s2 + apply (case_tac "(s1, s2)" rule: sim_callee.cases) + by (auto simp add: id_def split!: sum.splits if_splits option.splits) + done + subgoal for s2 s1 by (case_tac "(s1, s2)" rule: sim_callee.cases) auto + done + + show ?thesis + unfolding \_real_def \_ideal_def Let_def + by (rule pfinite_intro | rule WT_intro)+ + qed + + show "0 \ ddh.advantage \ (diffie_hellman.DH_adversary \ auth1_rest auth2_rest \)" + by(simp add: ddh.advantage_def) + + assume WT [WT_intro]: "exception_\ (\_real \\<^sub>\ \_common) \g \ \" + show "advantage \ (obsf_resource (?sim |\<^sub>= 1\<^sub>C \ key.resource (ideal_rest auth1_rest auth2_rest))) (obsf_resource (real_resource TYPE(_) TYPE(_) auth1_rest auth2_rest)) \ ddh.advantage \ (diffie_hellman.DH_adversary \ auth1_rest auth2_rest \)" + proof - + have id_split[unfolded Let_def]: "connect \ (obsf_resource (?sim |\<^sub>= 1\<^sub>C \ key.resource (ideal_rest auth1_rest auth2_rest))) = + connect \ (obsf_resource (?sim |\<^sub>= (1\<^sub>C |\<^sub>= 1\<^sub>C) \ key.resource (ideal_rest auth1_rest auth2_rest)))" (is "connect _ ?L = connect _ ?R") + proof - + note [unfolded \_ideal_def, WT_intro] = \\_real, \_ideal \\<^sub>C ?sim \\ + note [unfolded \_ideal_def, WT_intro] = \\_ideal \\<^sub>\ \_common \res key.resource (ideal_rest auth1_rest auth2_rest) \\ + + have [WT_intro]: "WT_rest (\_full \\<^sub>\ (\_adv_rest1 \\<^sub>\ \_adv_rest2)) (\_full \\<^sub>\ (\_usr_rest1 \\<^sub>\ \_usr_rest2)) (\(_, s12). pred_prod I_auth1_rest I_auth2_rest s12) + (ideal_rest auth1_rest auth2_rest)" + apply (rule WT_rest.intros; simp) + subgoal for s q + apply (cases s, case_tac q, rename_tac [2] x, case_tac [2] x) + apply (auto simp add: translate_eoracle_def parallel_eoracle_def) + using WT_restD_rfunc_adv[OF WT_auth1_rest] WT_restD_rfunc_adv[OF WT_auth2_rest] by fastforce+ + subgoal for s q + apply (cases s, case_tac q, rename_tac [2] x, case_tac [2] x) + apply (auto simp add: translate_eoracle_def parallel_eoracle_def plus_eoracle_def) + using WT_restD_rfunc_usr[OF WT_auth1_rest] WT_restD_rfunc_usr[OF WT_auth2_rest] by fastforce+ + subgoal by(simp add: WT_restD[OF WT_auth1_rest] WT_restD[OF WT_auth2_rest]) + done + + have *: "outs_\ (exception_\ (\_real \\<^sub>\ \_common)) \\<^sub>R ?L \ ?R" + apply (rule obsf_resource_eq_\_cong) + apply (rule eq_\_attach_on') + apply (rule WT_intro | simp)+ + apply(rule parallel_converter2_eq_\_cong) + apply(rule eq_\_converter_reflI) + apply (rule \\_real, \_ideal \\<^sub>C ?sim \\[unfolded assms Let_def]) + apply (rule eq_\_converter_sym) + apply (rule parallel_converter2_id_id) + by (auto simp add: \_real_def \_common_def) + + show ?thesis + by (rule * connect_eq_resource_cong WT_intro)+ + qed + + show ?thesis + unfolding advantage_def Let_def id_split + unfolding Let_def connect_real connect_ideal[unfolded ideal_resource_def Let_def] reduction[unfolded advantage_def] .. + qed +qed + +end + +end + +subsection \Asymptotic security\ + +locale diffie_hellman' = + fixes \ :: "security \ 'grp cyclic_group" + assumes diffie_hellman [locale_witness]: "\\. diffie_hellman (\ \)" +begin + +sublocale diffie_hellman "\ \" for \ .. + +definition real_resource' where "real_resource' rest1 rest2 \ = real_resource TYPE(_) TYPE(_) \ (rest1 \) (rest2 \)" +definition ideal_resource' where "ideal_resource' rest1 rest2 \ = key.resource \ (ideal_rest (rest1 \) (rest2 \))" +definition sim' where "sim' \ = (let sim = CNV (sim_callee \) None in ((sim |\<^sub>= 1\<^sub>C ) \ lassocr\<^sub>C))" + +context + fixes + auth1_rest :: "nat \ ('auth1_s_rest, auth.event, 'auth1_iadv_rest, 'auth1_iusr_rest, 'auth1_oadv_rest, 'auth1_ousr_rest) rest_wstate" and + auth2_rest :: "nat \ ('auth2_s_rest, auth.event, 'auth2_iadv_rest, 'auth2_iusr_rest, 'auth2_oadv_rest, 'auth2_ousr_rest) rest_wstate" and + \_adv_rest1 and \_adv_rest2 and \_usr_rest1 and \_usr_rest2 and I_auth1_rest and I_auth2_rest + assumes + WT_auth1_rest: "\\. WT_rest (\_adv_rest1 \) (\_usr_rest1 \) (I_auth1_rest \) (auth1_rest \)" and + WT_auth2_rest: "\\. WT_rest (\_adv_rest2 \) (\_usr_rest2 \) (I_auth2_rest \) (auth2_rest \)" +begin + +theorem secure: + defines "\_real \ \\. ((\_full \\<^sub>\ (\_full \\<^sub>\ \_uniform (auth.Inp_Fedit ` (carrier (\ \))) UNIV)) \\<^sub>\ (\_full \\<^sub>\ (\_full \\<^sub>\ \_uniform (auth.Inp_Fedit ` (carrier (\ \))) UNIV))) \\<^sub>\ (\_adv_rest1 \ \\<^sub>\ \_adv_rest2 \)" + and "\_common \ \\. (\_uniform UNIV (key.Out_Alice ` carrier (\ \)) \\<^sub>\ \_uniform UNIV (key.Out_Bob ` carrier (\ \))) \\<^sub>\ ((\_full \\<^sub>\ \_full) \\<^sub>\ (\_usr_rest1 \ \\<^sub>\ \_usr_rest2 \))" + and "\_ideal \ \\. \_full \\<^sub>\ (\_full \\<^sub>\ (\_adv_rest1 \ \\<^sub>\ \_adv_rest2 \))" +assumes DDH: "negligible (\\. ddh.advantage (\ \) (DH_adversary TYPE(_) TYPE(_) \ (auth1_rest \) (auth2_rest \) (\ \)))" + shows "constructive_security_obsf' (real_resource' auth1_rest auth2_rest) (ideal_resource' auth1_rest auth2_rest) sim' \_real \_ideal \_common \" +proof(rule constructive_security_obsf'I) + show "constructive_security_obsf (real_resource' auth1_rest auth2_rest \) + (ideal_resource' auth1_rest auth2_rest \) (sim' \) (\_real \) (\_ideal \) (\_common \) + (\ \) (ddh.advantage (\ \) (DH_adversary TYPE(_) TYPE(_) \ (auth1_rest \) (auth2_rest \) (\ \)))" for \ + unfolding real_resource'_def ideal_resource'_def sim'_def \_real_def \_common_def \_ideal_def + by(rule secure)(rule WT_auth1_rest WT_auth2_rest)+ +qed(rule DDH) + +end + +end + +end \ No newline at end of file diff --git a/thys/Constructive_Cryptography_CM/Constructions/One_Time_Pad.thy b/thys/Constructive_Cryptography_CM/Constructions/One_Time_Pad.thy new file mode 100644 --- /dev/null +++ b/thys/Constructive_Cryptography_CM/Constructions/One_Time_Pad.thy @@ -0,0 +1,911 @@ +theory One_Time_Pad + imports + Sigma_Commit_Crypto.Xor + "../Asymptotic_Security" + "../Construction_Utility" + "../Specifications/Key" + "../Specifications/Channel" +begin + +section \One-time-pad construction\ + +locale one_time_pad = + key: ideal_key "carrier \" + + auth: ideal_channel "id :: 'msg \ 'msg" False + + sec: ideal_channel "\_ :: 'msg. carrier \" False + + boolean_algebra \ + for + \ :: "('msg, 'more) boolean_algebra_scheme" (structure) + + assumes + nempty_carrier: "carrier \ \ {}" and + finite_carrier: "finite (carrier \)" +begin + + +subsection \Defining user callees\ + +definition enc_callee :: " unit \ 'msg sec.iusr_alice + \ (sec.ousr_alice \ unit, key.iusr_alice + 'msg sec.iusr_alice, 'msg key.ousr_alice + auth.ousr_alice) gpv" + where + "enc_callee \ stateless_callee (\inp. case inp of sec.Inp_Send msg \ + if msg \ carrier \ then + Pause + (Inl key.Inp_Alice) + (\kout. case projl kout of key.Out_Alice key \ + let cipher = key \ msg in + Pause (Inr (auth.Inp_Send cipher)) (\_. Done sec.Out_Send)) + else + Fail)" + +definition dec_callee :: " unit \ sec.iusr_bob + \ ('msg sec.ousr_bob \ unit, key.iusr_bob + auth.iusr_bob, 'msg key.ousr_bob + 'msg auth.ousr_bob) gpv" + where + "dec_callee \ stateless_callee (\_. + Pause + (Inr auth.Inp_Recv) + (\cout. case cout of + Inr (auth.Out_Recv cipher) \ + Pause + (Inl key.Inp_Bob) + (\kout. case projl kout of key.Out_Bob key \ + Done (sec.Out_Recv (key \ cipher))) + | _ \ Fail))" + + +subsection \Defining adversary converter\ + +type_synonym 'msg' astate = "'msg' option" + +definition look_callee :: "'msg astate \ sec.iadv_look + \ ('msg sec.oadv_look \ 'msg astate, sec.iadv_look, 'msg set sec.oadv_look) gpv" + where + "look_callee \ \state inp. + Pause + sec.Inp_Look + (\cout. case cout of + sec.Out_Look msg_set \ + (case state of + None \ do { + msg \ lift_spmf (spmf_of_set (msg_set)); + Done (auth.Out_Look msg, Some msg) } + | Some msg \ Done (auth.Out_Look msg, Some msg)))" + +definition sim :: " + (key.iadv + auth.iadv_drop + auth.iadv_look + 'msg auth.iadv_fedit, + key.oadv + auth.oadv_drop + 'msg auth.oadv_look + auth.oadv_fedit, + sec.iadv_drop + sec.iadv_look + 'msg sec.iadv_fedit, + sec.oadv_drop + 'msg set sec.oadv_look + sec.oadv_fedit) converter" + where + "sim \ + let look_converter = converter_of_callee look_callee None in + ldummy_converter (\_. key.Out_Adversary) (1\<^sub>C |\<^sub>= look_converter |\<^sub>= 1\<^sub>C)" + + +subsection \Defining event-translator\ + +type_synonym estate = "bool \ (key.party + auth.party) set" + +abbreviation einit :: estate + where + "einit \ (False, {})" + +definition sec_party_of_key_party :: "key.party \ sec.party" + where + "sec_party_of_key_party \ key.case_party sec.Alice sec.Bob" + +abbreviation etran_base_helper :: "estate \ key.party + auth.party \ sec.event list" + where + "etran_base_helper \ (\(s_flg, s_kap) item. + let sp_of = case_sum sec_party_of_key_party id in + let se_of = (\chk out. if s_flg \ chk then [out] else []) in + let chk_alice = Inl key.Alice \ s_kap \ Inr auth.Alice \ s_kap in + let chk_bob = Inl key.Bob \ s_kap \ Inr auth.Bob \ s_kap in + sec.case_party + (se_of chk_alice (sec.Event_Shell sec.Alice)) + (se_of chk_bob (sec.Event_Shell sec.Bob)) + (sp_of item))" + +abbreviation etran_base :: "(estate, key.party + auth.party, sec.event list) oracle'" + where + "etran_base \ (\(s_flg, s_kap) item. + let s_kap' = insert item s_kap in + let event = etran_base_helper (s_flg, s_kap') item in + if item \ s_kap then return_spmf (event, s_flg, s_kap') else return_pmf None)" + +fun etran :: "(estate, key.event + auth.event, sec.event list) oracle'" + where + "etran state (Inl (key.Event_Shell party)) = etran_base state (Inl party)" + | "etran (False, s_kap) (Inl key.Event_Kernel) = + (let check_alice = Inl key.Alice \ s_kap \ Inr auth.Alice \ s_kap in + let check_bob = Inl key.Bob \ s_kap \ Inr auth.Bob \ s_kap in + let e_alice = if check_alice then [sec.Event_Shell sec.Alice] else [] in + let e_bob = if check_bob then [sec.Event_Shell sec.Bob] else [] in + return_spmf (e_alice @ e_bob, True, s_kap))" + | "etran state (Inr (auth.Event_Shell party)) = etran_base state (Inr party)" + | "etran _ _ = return_pmf None" + + +subsubsection \Basic lemmas for automated handling of @{term sec_party_of_key_party}\ + +lemma sec_party_of_key_party_simps [simp]: + "sec_party_of_key_party key.Alice = sec.Alice" + "sec_party_of_key_party key.Bob = sec.Bob" + by(simp_all add: sec_party_of_key_party_def) + +lemma sec_party_of_key_party_eq_simps [simp]: + "sec_party_of_key_party p = sec.Alice \ p = key.Alice" + "sec_party_of_key_party p = sec.Bob \ p = key.Bob" + by(simp_all add: sec_party_of_key_party_def split: key.party.split) + +lemma key_case_party_collapse [simp]: "key.case_party x x p = x" + by(simp split: key.party.split) + +lemma sec_case_party_collapse [simp]: "sec.case_party x x p = x" + by(simp split: sec.party.split) + +lemma Alice_in_sec_party_of_key_party [simp]: + "sec.Alice \ sec_party_of_key_party ` P \ key.Alice \ P" + by(auto simp add: sec_party_of_key_party_def split: key.party.splits) + +lemma Bob_in_sec_party_of_key_party [simp]: + "sec.Bob \ sec_party_of_key_party ` P \ key.Bob \ P" + by(auto simp add: sec_party_of_key_party_def split: key.party.splits) + +lemma case_sec_party_of_key_party [simp]: "sec.case_party a b (sec_party_of_key_party x) = key.case_party a b x" + by(simp add: sec_party_of_key_party_def split: sec.party.split key.party.split) + + +subsection \Defining Ideal and Real constructions\ + +context + fixes + key_rest :: "('key_s_rest, key.event, 'key_iadv_rest, 'key_iusr_rest, 'key_oadv_rest, 'key_ousr_rest) rest_wstate" and + auth_rest :: "('auth_s_rest, auth.event, 'auth_iadv_rest, 'auth_iusr_rest, 'auth_oadv_rest, 'auth_ousr_rest) rest_wstate" +begin + +definition ideal_rest + where + "ideal_rest \ translate_rest einit etran (parallel_rest key_rest auth_rest)" + +definition ideal_resource + where + "ideal_resource \ (sim |\<^sub>= 1\<^sub>C) |\<^sub>= 1\<^sub>C |\<^sub>= 1\<^sub>C \ (sec.resource ideal_rest)" + +definition real_resource + where + "real_resource \ attach_c1f22_c1f22 (CNV enc_callee ()) (CNV dec_callee ()) (key.resource key_rest) (auth.resource auth_rest)" + + +subsection \Wiring and simplifying the Ideal construction\ + +definition ideal_s_core' :: "((_ \ 'msg astate \ _) \ _) \ estate \ 'msg sec.state" + where + "ideal_s_core' \ ((((), None, ()), ()), (False, {}), sec.State_Void, {})" + +definition ideal_s_rest' :: "_ \ 'key_s_rest \ 'auth_s_rest" + where + "ideal_s_rest' \ (((), ()), rinit key_rest, rinit auth_rest)" + +primcorec ideal_core' :: "(((unit \ _ \ unit) \ unit) \ _, _, key.iadv + _, _, _, _) core" + where + "cpoke ideal_core' = (\(s_advusr, s_event, s_core) event. do { + (events, s_event') \ (etran s_event event); + s_core' \ foldl_spmf sec.poke (return_spmf s_core) events; + return_spmf (s_advusr, s_event', s_core') + })" + | "cfunc_adv ideal_core' = (\((s_adv, s_usr), s_core) iadv. + let handle_l = (\_. Done (Inl key.Out_Adversary, s_adv)) in + let handle_r = (\qr. map_gpv (map_prod Inr id) id ((1\<^sub>I \\<^sub>I look_callee \\<^sub>I 1\<^sub>I) s_adv qr)) in + map_spmf + (\((oadv, s_adv'), s_core'). (oadv, (s_adv', s_usr), s_core')) + (exec_gpv \sec.iface_adv (case_sum handle_l handle_r iadv) s_core))" + | "cfunc_usr ideal_core' = \\sec.iface_usr" + +primcorec ideal_rest' :: "((unit \ unit) \ _, _, _, _, _, _, _) rest_scheme" + where + "rinit ideal_rest' = (((), ()), rinit key_rest, rinit auth_rest)" + | "rfunc_adv ideal_rest' = \(parallel_eoracle (rfunc_adv key_rest) (rfunc_adv auth_rest))" + | "rfunc_usr ideal_rest' = \(parallel_eoracle (rfunc_usr key_rest) (rfunc_usr auth_rest))" + + +subsubsection \The ideal attachment lemma\ + +lemma attach_ideal: "ideal_resource = RES (fused_resource.fuse ideal_core' ideal_rest') (ideal_s_core', ideal_s_rest')" +proof - + + have fact1: "ideal_rest' = attach_rest 1\<^sub>I 1\<^sub>I (Pair ((), ())) (parallel_rest key_rest auth_rest)" (is "?L = ?R") + proof - + + have "rinit ?L = rinit ?R" + by simp + + moreover have "rfunc_adv ?L = rfunc_adv ?R" + unfolding attach_rest_id_oracle_adv parallel_eoracle_def + by (simp add: extend_state_oracle_def) + + moreover have "rfunc_usr ?L = rfunc_usr ?R" + unfolding attach_rest_id_oracle_usr parallel_eoracle_def + by (simp add: extend_state_oracle_def) + + ultimately show ?thesis + by (coinduction) blast + qed + + have fact2: "ideal_core' = + (let handle_l = (\s ql. Generative_Probabilistic_Value.Done (Inl key.Out_Adversary, s)) in + let handle_r = (\s qr. map_gpv (map_prod Inr id) id ((1\<^sub>I \\<^sub>I look_callee \\<^sub>I 1\<^sub>I) s qr)) in + let tcore = translate_core etran sec.core in + attach_core (\s. case_sum (handle_l s) (handle_r s)) 1\<^sub>I tcore)" (is "?L = ?R") + proof - + + have "cpoke ?L = cpoke ?R" + by (simp add: split_def map_spmf_conv_bind_spmf) + + moreover have "cfunc_adv ?L = cfunc_adv ?R" + unfolding attach_core_def + by (simp add: split_def) + + moreover have "cfunc_usr ?L = cfunc_usr ?R" + unfolding Let_def attach_core_id_oracle_usr + by (clarsimp simp add: extend_state_oracle_def[symmetric]) + + ultimately show ?thesis + by (coinduction) blast + qed + + show ?thesis + unfolding ideal_resource_def sec.resource_def sim_def ideal_rest_def ideal_s_core'_def ideal_s_rest'_def + apply(simp add: conv_callee_parallel_id_right[symmetric, where s'="()"]) + apply(simp add: conv_callee_parallel_id_left[symmetric, where s="()"]) + apply(simp add: ldummy_converter_of_callee) + apply(subst fused_resource_move_translate[of _ einit etran]) + apply(simp add: resource_of_oracle_state_iso) + apply(simp add: iso_swapar_def split_beta ideal_rest_def) + apply(subst (1 2 3) converter_of_callee_id_oracle[symmetric, of "()"]) + apply(subst attach_parallel_fuse'[where f_init="Pair ((), ())"]) + apply(simp add: fact1[symmetric] fact2[symmetric, simplified Let_def]) + done +qed + +subsection \Wiring and simplifying the Real construction\ + +definition real_s_core' :: "_ \ 'msg key.state \ 'msg auth.state" + where + "real_s_core' \ (((), (), ()), (key.PState_Store, {}), (auth.State_Void, {}))" + +definition real_s_rest' + where + "real_s_rest' \ ideal_s_rest'" + +primcorec real_core' :: "((unit \ _) \ _, _, _, _, _, _) core" + where + "cpoke real_core' = (\(s_advusr, s_core) event. + map_spmf (Pair s_advusr) (parallel_handler key.poke auth.poke s_core event))" + | "cfunc_adv real_core' = \(key.iface_adv \\<^sub>O auth.iface_adv)" + | "cfunc_usr real_core' = (\((s_adv, s_usr), s_core) iusr. + let handle_req = lsumr \ map_sum id (rsuml \ map_sum swap_sum id \ lsumr) \ rsuml in + let handle_ret = lsumr \ (map_sum id (rsuml \ (map_sum swap_sum id \ lsumr)) \ rsuml) in + map_spmf + (\((ousr, s_usr'), s_core'). (ousr, (s_adv, s_usr'), s_core')) + (exec_gpv + (key.iface_usr \\<^sub>O auth.iface_usr) + (map_gpv' id handle_req handle_ret ((enc_callee \\<^sub>I dec_callee) s_usr iusr)) s_core))" + +definition real_rest' + where + "real_rest' \ ideal_rest'" + + +subsubsection \The real attachment lemma\ + +private lemma WT_callee_real1: "((\_full \\<^sub>\ \_full) \\<^sub>\ (\_full \\<^sub>\ \_full)) \\<^sub>\ ((\_full \\<^sub>\ \_full) \\<^sub>\ (\_full \\<^sub>\ \_full)) \c + (key.fuse key_rest \\<^sub>O auth.fuse auth_rest) s \" + apply(rule WT_calleeI) + apply(cases s) + apply(case_tac call) + apply(rename_tac [!] x) + apply(case_tac [!] x) + apply(rename_tac [!] y) + apply(case_tac [!] y) + by(auto simp add: fused_resource.fuse.simps) + +private lemma WT_callee_real2: "(\_full \\<^sub>\ \_full) \\<^sub>\ (((\_full \\<^sub>\ \_full) \\<^sub>\ (\_full \\<^sub>\ \_full)) \\<^sub>\ \_full) \c + fused_resource.fuse (parallel_core key.core auth.core) (parallel_rest key_rest auth_rest) s \" + apply(rule WT_calleeI) + apply(cases s) + apply(case_tac call) + apply(rename_tac [!] x) + apply(case_tac [!] x) + apply(rename_tac [!] y) + apply(case_tac [!] y) + apply(rename_tac [5] z) + apply(rename_tac [6] z) + apply(case_tac [5] z) + apply(case_tac [7] z) + by(auto simp add: fused_resource.fuse.simps) + + +lemma attach_real: "real_resource = RES (fused_resource.fuse real_core' real_rest') (real_s_core', real_s_rest')" +proof - + + have fact1: "real_core' = attach_core 1\<^sub>I (attach_wiring_right parallel_wiring\<^sub>w (enc_callee \\<^sub>I dec_callee)) + (parallel_core key.core auth.core) " (is "?L = ?R") + proof- + + have "cpoke ?L = cpoke ?R" + by simp + + moreover have "cfunc_adv ?L = cfunc_adv ?R" + unfolding attach_core_id_oracle_adv + by (simp add: extend_state_oracle_def) + + moreover have "cfunc_usr ?L = cfunc_usr ?R" + unfolding parallel_wiring\<^sub>w_def swap_lassocr\<^sub>w_def swap\<^sub>w_def lassocr\<^sub>w_def rassocl\<^sub>w_def + by (simp add: attach_wiring_right_simps parallel2_wiring_simps comp_wiring_simps) + + ultimately show ?thesis + by (coinduction) blast + qed + + have fact2: "real_rest' = attach_rest 1\<^sub>I 1\<^sub>I (Pair ((), ())) (parallel_rest key_rest auth_rest) " (is "?L = ?R") + proof - + have "rinit ?L = rinit ?R" + unfolding real_rest'_def ideal_rest'_def + by simp + + moreover have "rfunc_adv ?L = rfunc_adv ?R" + unfolding real_rest'_def ideal_rest'_def attach_rest_id_oracle_adv + by (simp add: extend_state_oracle_def) + + moreover have "rfunc_usr ?L = rfunc_usr ?R" + unfolding real_rest'_def ideal_rest'_def attach_rest_id_oracle_usr + by (simp add: extend_state_oracle_def) + + ultimately show ?thesis + by (coinduction) blast + qed + + show ?thesis + unfolding real_resource_def attach_c1f22_c1f22_def wiring_c1r22_c1r22_def key.resource_def auth.resource_def + apply(subst resource_of_parallel_oracle[symmetric]) + apply(subst attach_compose) + apply(subst attach_wiring_resource_of_oracle) + apply(rule wiring_intro) + apply (rule WT_resource_of_oracle[OF WT_callee_real1]) + apply simp + subgoal + apply(subst parallel_oracle_fuse) + apply(subst resource_of_oracle_state_iso) + apply simp + apply(simp add: parallel_state_iso_def) + apply(subst conv_callee_parallel[symmetric]) + apply(subst eq_resource_on_UNIV_iff[symmetric]) + apply(rule eq_resource_on_trans) + apply(rule eq_\_attach_on') + apply (rule WT_resource_of_oracle[OF WT_callee_real2]) + apply(rule parallel_converter2_eq_\_cong) + apply(rule eq_\_converter_reflI) + apply(rule WT_intro)+ + apply(rule parallel_converter2_eq_\_cong) + apply(rule comp_converter_of_callee_wiring) + apply(rule wiring_intro) + apply(subst conv_callee_parallel) + apply(rule WT_intro) + apply (rule WT_converter_of_callee[where \=\_full and \'="\_full \\<^sub>\ \_full"]) + apply (rule WT_gpv_\_mono) + apply (rule WT_gpv_full) + apply (rule \_full_le_plus_\) + apply(rule order_refl) + apply(rule order_refl) + apply (clarsimp simp add: enc_callee_def stateless_callee_def split!: sec.iusr_alice.splits key.ousr_alice.splits) + apply (rule WT_converter_of_callee[where \=\_full and \'="\_full \\<^sub>\ \_full"]) + apply (rule WT_gpv_\_mono) + apply (rule WT_gpv_full) + apply (rule \_full_le_plus_\) + apply(rule order_refl) + apply(rule order_refl) + apply (clarsimp simp add: enc_callee_def stateless_callee_def split!: sec.iusr_alice.splits key.ousr_alice.splits) + apply(subst id_converter_eq_self) + apply(rule order_refl) + apply simp + apply simp + apply(subst eq_resource_on_UNIV_iff) + apply(subst (1 2 3) converter_of_callee_id_oracle[symmetric, of "()"]) + apply(subst attach_parallel_fuse') + apply(simp add: fact1 fact2 real_s_core'_def real_s_rest'_def ideal_s_rest'_def) + done + done +qed + + +subsection \Proving the trace-equivalence of simplified Ideal and Real constructions\ + +context +begin + + +subsubsection \Proving the trace-equivalence of cores\ + +private abbreviation + "a_I \ \(x, y). ((((), x, ()), ()), y)" + +private abbreviation + "a_R \ \x. (((), (), ()), x)" + +abbreviation + "asm_act \ (\flg pset_sec pset_key pset_auth pset_union. + pset_union = pset_key <+> pset_auth \ + (flg \ pset_sec = sec_party_of_key_party ` pset_key \ pset_auth))" + +private inductive S :: "(((_ \ 'msg option \ _) \ _) \ estate \ 'msg sec.state) spmf + \ (_ \ 'msg key.state \ 'msg auth.state) spmf \ bool" + where +\ \(Auth =a)@(Key =0)\ + s_0_0: "S (return_spmf (a_I (None, (False, s_act_ka), sec.State_Void, s_act_s))) + (return_spmf (a_R ((key.PState_Store, s_act_k), auth.State_Void, s_act_a)))" + if "asm_act False s_act_s s_act_k s_act_a s_act_ka" and "s_act_s = {}" +\ \(Auth =a)@(Key =1)\ + | s_0_1: "S (return_spmf (a_I (None, (True, s_act_ka), sec.State_Void, s_act))) + (map_spmf (\key. a_R ((key.State_Store key, s_act_k), auth.State_Void, s_act_a)) (spmf_of_set (carrier \)))" + if "asm_act True s_act s_act_k s_act_a s_act_ka" +\ \../(Auth =a)@(Key =1) \# wl\ + | s_1_1: "S (return_spmf (a_I (None, (True ,s_act_ka), sec.State_Store msg, s_act_s))) + (map_spmf (\key. a_R ((key.State_Store key, s_act_k), auth.State_Store (key \ msg), s_act_a)) (spmf_of_set (carrier \)))" + if "asm_act True s_act_s s_act_k s_act_a s_act_ka" and "key.Alice \ s_act_k" and "auth.Alice \ s_act_a" and "msg \ carrier \" + | s_2_1: "S (return_spmf (a_I (None, (True ,s_act_ka), sec.State_Collect msg, s_act_s))) + (map_spmf (\key. a_R ((key.State_Store key, s_act_k), auth.State_Collect (key \ msg), s_act_a)) (spmf_of_set (carrier \)))" + if "asm_act True s_act_s s_act_k s_act_a s_act_ka" and "key.Alice \ s_act_k" and "auth.Alice \ s_act_a" and "msg \ carrier \" + | s_3_1: "S (return_spmf (a_I (None, (True ,s_act_ka), sec.State_Collected, s_act_s))) + (map_spmf (\key. a_R ((key.State_Store key, s_act_k), auth.State_Collected, s_act_a)) (spmf_of_set (carrier \)))" + if "asm_act True s_act_s s_act_k s_act_a s_act_ka" and "s_act_k = {key.Alice, key.Bob}" and "s_act_a = {auth.Alice, auth.Bob}" +\ \../(Auth =a)@(Key =1) \# look\ + | s_1'_1: "S (return_spmf (a_I (Some (key \ msg), (True ,s_act_ka), sec.State_Store msg, s_act_s))) + (return_spmf (a_R ((key.State_Store key, s_act_k), auth.State_Store (key \ msg), s_act_a)))" + if "asm_act True s_act_s s_act_k s_act_a s_act_ka" and "key.Alice \ s_act_k" and "auth.Alice \ s_act_a" and "msg \ carrier \" and "key \ carrier \" + | s_2'_1: "S (return_spmf (a_I (Some (key \ msg), (True ,s_act_ka), sec.State_Collect msg, s_act_s))) + (return_spmf (a_R ((key.State_Store key, s_act_k), auth.State_Collect (key \ msg), s_act_a)))" + if "asm_act True s_act_s s_act_k s_act_a s_act_ka" and "key.Alice \ s_act_k" and "auth.Alice \ s_act_a" and "msg \ carrier \" and "key \ carrier \" + | s_3'_1: "S (return_spmf (a_I (Some (key \ msg), (True ,s_act_ka), sec.State_Collected, s_act_s))) + (return_spmf (a_R ((key.State_Store key, s_act_k), auth.State_Collected, s_act_a)))" + if "asm_act True s_act_s s_act_k s_act_a s_act_ka" and "s_act_k = {key.Alice, key.Bob}" and "s_act_a = {auth.Alice, auth.Bob}" and "msg \ carrier \" and "key \ carrier \" + +private lemma trace_eq_core: "trace_core_eq ideal_core' real_core' + UNIV (UNIV <+> UNIV <+> UNIV <+> (auth.Inp_Fedit ` carrier \)) ((sec.Inp_Send ` carrier \) <+> UNIV) + (return_spmf ideal_s_core') (return_spmf real_s_core')" +proof - + + have inj_xor: "\msg \ carrier \ ; x \ carrier \; y \ carrier \; x \ msg = y \ msg\ \ x = y" for msg x y + by (metis (no_types, hide_lams) local.xor_ac(2) local.xor_left_inverse) + + note [simp] = enc_callee_def dec_callee_def look_callee_def nempty_carrier finite_carrier + exec_gpv_bind spmf.map_comp map_bind_spmf bind_map_spmf bind_spmf_const o_def Let_def + + show ?thesis + apply (rule trace_core_eq_simI_upto[where S=S]) + subgoal Init_OK + by (simp add: ideal_s_core'_def real_s_core'_def S.simps) + subgoal POut_OK for s_i s_r query + apply (cases query) + subgoal for e_key + apply (cases e_key) + subgoal for e_shell by (erule S.cases) (auto simp add: map_spmf_conv_bind_spmf[symmetric] split: key.party.splits) + subgoal e_kernel by (erule S.cases) (auto simp add: map_spmf_conv_bind_spmf[symmetric]) + done + subgoal for e_auth + apply (cases e_auth) + subgoal for e_shell + by (erule S.cases) (auto simp add: map_spmf_conv_bind_spmf[symmetric] split:auth.party.splits) + done + done + subgoal PState_OK for s_i s_r query + apply (cases query) + subgoal for e_key + apply (cases e_key) + subgoal for e_shell by (erule S.cases) (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro!: trace_eq_simcl.base S.intros[simplified] split: key.party.splits) + subgoal e_kernel by (erule S.cases) (auto simp add: map_spmf_conv_bind_spmf[symmetric] sec_party_of_key_party_def intro!: trace_eq_simcl.base S.intros[simplified] split: key.party.splits) + done + subgoal for e_auth + apply (cases e_auth) + subgoal for e_shell by (erule S.cases) (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro!: trace_eq_simcl.base S.intros[simplified] split:auth.party.splits) + done + done + subgoal AOut_OK for s_i s_r query + apply (cases query) + subgoal for q_key by (erule S.cases) simp_all + subgoal for q_auth + apply (cases q_auth) + subgoal for q_auth_drop by (erule S.cases) (simp_all add: id_oracle_def) + subgoal for q_auth_lfe + apply (cases q_auth_lfe) + subgoal for q_auth_look + proof (erule S.cases, goal_cases) + case (3 s_act_s s_act_k s_act_a s_act_ka msg) \ \Corresponds to @{thm [source] s_1_1}\ + then show ?case + apply(simp add: exec_gpv_extend_state_oracle exec_gpv_map_gpv_id exec_gpv_plus_oracle_right exec_gpv_plus_oracle_left) + apply (subst one_time_pad[symmetric, of "msg"]) + apply (simp_all add: xor_comm) + apply (rule bind_spmf_cong[OF HOL.refl]) + by (simp add: xor_comm) + qed simp_all + subgoal for q_auth_fedit by (erule S.cases) (auto simp add: id_oracle_def split:auth.iadv_fedit.split) + done + done + done + subgoal AState_OK for s_i s_r query + apply (cases query) + subgoal for q_key by (erule S.cases) (auto simp add: map_spmf_conv_bind_spmf[symmetric] intro!: trace_eq_simcl.base S.intros[simplified]) + subgoal for q_auth + apply (cases q_auth) + subgoal for q_auth_drop by (erule S.cases) (auto simp add: id_oracle_def) + subgoal for q_auth_lfe + apply (cases q_auth_lfe) + subgoal for q_auth_look + proof (erule S.cases, goal_cases) + case (3 s_act_s s_act_k s_act_a s_act_ka msg) \ \Corresponds to @{thm [source] s_1_1}\ + then show ?case + apply(simp add: exec_gpv_extend_state_oracle exec_gpv_map_gpv_id exec_gpv_plus_oracle_right exec_gpv_plus_oracle_left) + apply (clarsimp simp add: map_spmf_conv_bind_spmf[symmetric]) + apply (subst (1 2) cond_spmf_fst_map_Pair1; clarsimp simp add: set_spmf_of_set inj_on_def intro: inj_xor) + apply (rule inj_xor, simp_all) + apply(subst (1 2 3) inv_into_f_f) + by (auto simp add: S.simps inj_on_def intro: inj_xor) + qed (auto intro!: trace_eq_simcl.base S.intros[simplified]) + subgoal for q_auth_fedit by (erule S.cases) (auto simp add: map_spmf_conv_bind_spmf[symmetric] id_oracle_def intro!: trace_eq_simcl.base S.intros[simplified]) + done + done + done + subgoal UOut_OK for s_i s_r query + apply (cases query) + subgoal for q_alice + proof (erule S.cases, goal_cases) + case (2 s_act_s s_act_k s_act_a s_act_ka) \ \Corresponds to @{thm [source] s_0_1}\ + then show ?case + apply (cases "auth.Alice \ s_act_a"; cases "key.Alice \ s_act_k") + apply (simp_all add: stateless_callee_def split_def split!: auth.iusr_alice.split) + done + qed (simp_all add: stateless_callee_def split: auth.iusr_alice.split) + subgoal for q_bob + proof (erule S.cases, goal_cases) + case (4 s_act_s s_act_k s_act_a s_act_ka msg) \ \Corresponds to @{thm [source] s_2_1}\ + then show ?case + apply (cases "sec.Bob \ s_act_s") + subgoal + apply (clarsimp simp add: stateless_callee_def) + apply (simp add: spmf_rel_eq[symmetric]) + apply (rule rel_spmf_bindI2) + by simp_all + subgoal by (cases "sec.Bob \ s_act_a") (clarsimp simp add: stateless_callee_def)+ + done + qed (simp_all add: stateless_callee_def) + done + subgoal UState_OK for s_i s_r query + apply (cases query) + subgoal for q_alice + proof (erule S.cases, goal_cases) + case (2 s_act s_act_k s_act_a s_act_ka) \ \Corresponds to @{thm [source] s_0_1}\ + then show ?case + apply (cases "auth.Alice \ s_act_a"; cases "key.Alice \ s_act_k") + subgoal + apply (clarsimp simp add: map_spmf_conv_bind_spmf[symmetric] stateless_callee_def split_def split!: auth.iusr_alice.split if_splits) + apply(rule trace_eq_simcl.base) + apply (rule S.intros(3)[simplified]) + by simp_all + by (clarsimp simp add: map_spmf_conv_bind_spmf[symmetric] stateless_callee_def split_def split: auth.iusr_alice.split)+ + qed (auto simp add: stateless_callee_def split: auth.iusr_alice.split_asm) + subgoal for q_bob + proof (erule S.cases, goal_cases) + case (4 s_act_s s_act_k s_act_a s_act_ka msg) \ \Corresponds to @{thm [source] s_2_1}\ + then show ?case + apply (cases "sec.Bob \ s_act_s") + subgoal + apply (clarsimp simp add: stateless_callee_def map_spmf_conv_bind_spmf[symmetric]) + apply (subst map_spmf_of_set_inj_on) + apply (simp_all add: inj_on_def) + apply (subst map_spmf_of_set_inj_on[symmetric]) + apply (simp add: inj_on_def) + apply clarsimp + apply(rule trace_eq_simcl.base) + apply (rule S.intros(5)[simplified]) + apply (simp_all split: sec.party.splits ) + by auto + subgoal by (clarsimp simp add: stateless_callee_def split: if_splits) + done + next + case (7 s_act_s s_act_k s_act_a s_act_ka msg key) \ \Corresponds to @{thm [source] s_2'_1}\ + then show ?case + apply (cases "sec.Bob \ s_act_s") + subgoal + apply (clarsimp simp add: stateless_callee_def map_spmf_conv_bind_spmf[symmetric]) + apply (rule S.intros(8)[simplified]) + apply simp_all + by auto + subgoal by (clarsimp simp add: stateless_callee_def split: if_splits) + done + qed (auto simp add: stateless_callee_def split: auth.iusr_alice.split_asm) + done + done +qed + + +subsubsection \Proving the trace equivalence of fused cores and rests\ + +private definition \_adv_core :: "(key.iadv + 'msg auth.iadv, key.oadv + 'msg auth.oadv) \" + where "\_adv_core \ \_full \\<^sub>\ (\_full \\<^sub>\ (\_full \\<^sub>\ \_uniform (sec.Inp_Fedit ` (carrier \)) UNIV))" + +private definition \_usr_core :: "('msg sec.iusr, 'msg sec.ousr) \" + where "\_usr_core \ \_uniform (sec.Inp_Send ` (carrier \)) UNIV \\<^sub>\ \_uniform UNIV (sec.Out_Recv ` carrier \)" + +private definition invar_ideal' :: "((_ \ 'msg astate \ _) \ _) \ estate \ 'msg sec.state \ bool" + where "invar_ideal' = pred_prod (pred_prod (pred_prod (\_. True) (pred_prod (pred_option (\x. x \ carrier \)) (\_. True))) (\_. True)) (pred_prod (\_. True) (pred_prod (sec.pred_s_kernel (\x. x \ carrier \)) (\_. True)))" + +private definition invar_real' :: "_ \ ('msg key.s_kernel \ _) \ 'msg sec.s_kernel \ _ \ bool" + where "invar_real' = pred_prod (\_. True) (pred_prod (pred_prod (key.pred_s_kernel (\x. x \ carrier \)) (\_. True)) (pred_prod (sec.pred_s_kernel (\x. x \ carrier \)) (\_. True)))" + +lemma invar_ideal_s_core' [simp]: "invar_ideal' ideal_s_core'" + by(simp add: invar_ideal'_def ideal_s_core'_def) + +lemma invar_real_s_core' [simp]: "invar_real' real_s_core'" + by(simp add: invar_real'_def real_s_core'_def) + +lemma WT_ideal_core' [WT_intro]: "WT_core \_adv_core \_usr_core invar_ideal' ideal_core'" + apply(rule WT_core.intros) + apply + (auto split!: sum.splits option.splits if_split_asm simp add: \_adv_core_def \_usr_core_def exec_gpv_map_gpv_id exec_gpv_extend_state_oracle exec_gpv_plus_oracle_left exec_gpv_plus_oracle_right invar_ideal'_def sec.in_set_spmf_iface_drop sec.in_set_spmf_iface_look sec.in_set_spmf_iface_fedit sec.in_set_spmf_iface_alice sec.in_set_spmf_iface_bob id_oracle_def look_callee_def exec_gpv_bind set_spmf_of_set sec.poke_alt_def foldl_spmf_pair_right) + done + +lemma WT_ideal_rest' [WT_intro]: + assumes "WT_rest \_adv_restk \_usr_restk I_key_rest key_rest" + and "WT_rest \_adv_resta \_usr_resta I_auth_rest auth_rest" + shows "WT_rest (\_adv_restk \\<^sub>\ \_adv_resta) (\_usr_restk \\<^sub>\ \_usr_resta) (\(_, s_rest). pred_prod I_key_rest I_auth_rest s_rest) ideal_rest'" + by(rule WT_rest.intros)(fastforce simp add: fused_resource.fuse.simps parallel_eoracle_def dest: WT_restD_rfunc_adv[OF assms(1)] WT_restD_rfunc_adv[OF assms(2)] WT_restD_rfunc_usr[OF assms(1)] WT_restD_rfunc_usr[OF assms(2)] simp add: assms[THEN WT_restD_rinit])+ + + +lemma WT_real_core' [WT_intro]: "WT_core \_adv_core \_usr_core invar_real' real_core'" + apply(rule WT_core.intros) + apply(auto simp add: \_adv_core_def \_usr_core_def enc_callee_def dec_callee_def + stateless_callee_def Let_def exec_gpv_extend_state_oracle exec_gpv_map_gpv' exec_gpv_plus_oracle_left exec_gpv_plus_oracle_right + invar_real'_def in_set_spmf_parallel_handler key.in_set_spmf_poke sec.poke_alt_def auth.in_set_spmf_iface_look auth.in_set_spmf_iface_fedit + sec.in_set_spmf_iface_alice sec.in_set_spmf_iface_bob + split!: key.ousr_alice.splits key.ousr_bob.splits auth.ousr_alice.splits auth.ousr_bob.splits sum.splits if_split_asm) + done + +private lemma trace_eq_sec: + fixes \_adv_restk \_adv_resta \_usr_restk \_usr_resta + defines "outs_adv \ (UNIV <+> UNIV <+> UNIV <+> sec.Inp_Fedit ` carrier \) <+> outs_\ (\_adv_restk \\<^sub>\ \_adv_resta)" + and "outs_usr \ (sec.Inp_Send ` carrier \ <+> UNIV) <+> outs_\ (\_usr_restk \\<^sub>\ \_usr_resta)" + assumes WT_key [WT_intro]: "WT_rest \_adv_restk \_usr_restk I_key_rest key_rest" + and WT_auth [WT_intro]: "WT_rest \_adv_resta \_usr_resta I_auth_rest auth_rest" + shows "(outs_adv <+> outs_usr) \\<^sub>C fused_resource.fuse ideal_core' ideal_rest' ((ideal_s_core', ideal_s_rest')) \ + fused_resource.fuse real_core' real_rest' ((real_s_core', real_s_rest'))" +proof - + define e\_adv_rest :: "(_, _ \ (key.event + auth.event) list) \" + where "e\_adv_rest \ map_\ id (case_sum (map_prod Inl (map Inl)) (map_prod Inr (map Inr))) (e\ \_adv_restk \\<^sub>\ e\ \_adv_resta)" + define e\_usr_rest :: "(_, _ \ (key.event + auth.event) list) \" + where "e\_usr_rest \ map_\ id (case_sum (map_prod Inl (map Inl)) (map_prod Inr (map Inr))) (e\ \_usr_restk \\<^sub>\ e\ \_usr_resta)" + + note I_defs = \_adv_core_def \_usr_core_def + note eI_defs = e\_adv_rest_def e\_usr_rest_def + + have fact1[unfolded outs_plus_\]: + "trace_rest_eq ideal_rest' ideal_rest' (outs_\ (\_adv_restk \\<^sub>\ \_adv_resta)) (outs_\ (\_usr_restk \\<^sub>\ \_usr_resta)) s s" for s + apply(rule rel_rest'_into_trace_rest_eq[where S="(=)" and M="(=)", unfolded eq_onp_def], simp_all) + apply(fold relator_eq) + apply(rule rel_rest'_mono[THEN predicate2D, rotated -1, OF HOL.refl[of ideal_rest', folded relator_eq]]) + by auto + + have fact2 [unfolded eI_defs]: "callee_invariant_on (callee_of_rest ideal_rest') (\(_, s_rest). pred_prod I_key_rest I_auth_rest s_rest) (e\_adv_rest \\<^sub>\ e\_usr_rest)" + apply unfold_locales + subgoal for s x y s' + apply(cases "(snd s, x)" rule: parallel_oracle.cases) + apply(auto 4 3 simp add: parallel_eoracle_def eI_defs split!: sum.splits dest: WT_restD(1,2)[OF WT_key] WT_restD(1,2)[OF WT_auth]) + done + subgoal for s + apply(fastforce intro!: WT_calleeI simp add: parallel_eoracle_def eI_defs image_image dest: WT_restD(1,2)[OF WT_key] WT_restD(1,2)[OF WT_auth] intro: rev_image_eqI) + done + done + + have fact3[unfolded I_defs]: "callee_invariant_on (callee_of_core ideal_core') invar_ideal' (\_full \\<^sub>\ (\_adv_core \\<^sub>\ \_usr_core))" + by(rule WT_intro)+ + + have fact4[unfolded I_defs]: "callee_invariant_on (callee_of_core real_core') invar_real' (\_full \\<^sub>\ (\_adv_core \\<^sub>\ \_usr_core))" + by(rule WT_intro)+ + + note nempty_carrier[simp] + show ?thesis using WT_key[THEN WT_restD_rinit] WT_auth[THEN WT_restD_rinit] + apply (simp add: real_rest'_def real_s_rest'_def assms(1, 2)) + thm fuse_trace_eq[where \E=\_full and \CA=\_adv_core and \CU=\_usr_core and \RA=e\_adv_rest and \RU=e\_usr_rest,unfolded eI_defs \_adv_core_def \_usr_core_def,simplified] + apply (rule fuse_trace_eq[where \E=\_full and \CA=\_adv_core and \CU=\_usr_core and \RA=e\_adv_rest and \RU=e\_usr_rest + and ?IR1.0 = "\(_, s_rest). pred_prod I_key_rest I_auth_rest s_rest" + and ?IR2.0 = "\(_, s_rest). pred_prod I_key_rest I_auth_rest s_rest" + and ?IC1.0 = invar_ideal' and ?IC2.0=invar_real', + unfolded eI_defs \_adv_core_def \_usr_core_def, simplified]) + by (simp_all add: trace_eq_core fact1 fact2 fact3 fact4 ideal_s_rest'_def) +qed + + +subsubsection \Simplifying the final resource by moving the interfaces from core to rest\ + + +lemma connect[unfolded \_adv_core_def \_usr_core_def]: + fixes \_adv_restk \_adv_resta \_usr_restk \_usr_resta + defines "\ \ (\_adv_core \\<^sub>\ (\_adv_restk \\<^sub>\ \_adv_resta)) \\<^sub>\ (\_usr_core \\<^sub>\ (\_usr_restk \\<^sub>\ \_usr_resta))" + assumes [WT_intro]: "WT_rest \_adv_restk \_usr_restk I_key_rest key_rest" + and [WT_intro]: "WT_rest \_adv_resta \_usr_resta I_auth_rest auth_rest" + and "exception_\ \ \g D \" + shows "connect D (obsf_resource ideal_resource) = connect D (obsf_resource real_resource)" +proof - + note I_defs = \_adv_core_def \_usr_core_def + + have fact1: "\ \res RES (fused_resource.fuse ideal_core' ideal_rest') s \" + if "pred_prod I_key_rest I_auth_rest (snd (snd s))" "invar_ideal' (fst s)" + for s + unfolding assms(1) + apply(rule callee_invariant_on.WT_resource_of_oracle[where I="pred_prod invar_ideal' (\(_, s_rest). pred_prod I_key_rest I_auth_rest s_rest)"]) + subgoal by(rule fused_resource.callee_invariant_on_fuse)(rule WT_intro)+ + subgoal using that by(cases s)(simp) + done + + have fact2: "\ \res RES (fused_resource.fuse real_core' real_rest') s \" + if "pred_prod I_key_rest I_auth_rest (snd (snd s))" "invar_real' (fst s)" + for s + unfolding real_rest'_def assms(1) + apply(rule callee_invariant_on.WT_resource_of_oracle[where I="pred_prod invar_real' (\(_, s_rest). pred_prod I_key_rest I_auth_rest s_rest)"]) + subgoal by(rule fused_resource.callee_invariant_on_fuse)(rule WT_intro)+ + subgoal using that by(cases s)(simp) + done + + show ?thesis + unfolding attach_ideal attach_real + apply (rule connect_cong_trace[where \="exception_\ \"]) + apply (rule trace_eq_obsf_resourceI, subst trace_eq'_resource_of_oracle) + apply (rule trace_eq_sec[OF assms(2) assms(3)]) + subgoal by (rule assms(4)) + subgoal using WT_gpv_outs_gpv[OF assms(4)] by(simp add: I_defs assms(1) nempty_carrier) + subgoal using assms(2,3)[THEN WT_restD_rinit] by (intro WT_obsf_resource)(rule fact1; simp add: ideal_s_rest'_def) + subgoal using assms(2,3)[THEN WT_restD_rinit] by (intro WT_obsf_resource)(rule fact2; simp add: real_s_rest'_def ideal_s_rest'_def) + done +qed + +end + +end + + +end + + +subsection \Concrete security\ + +context one_time_pad begin + +lemma WT_enc_callee [WT_intro]: + "\_uniform (sec.Inp_Send ` carrier \) UNIV, \_uniform UNIV (key.Out_Alice ` carrier \) \\<^sub>\ \_uniform (sec.Inp_Send ` carrier \) UNIV \\<^sub>C CNV enc_callee () \" + by (rule WT_converter_of_callee) (auto 4 3 simp add: enc_callee_def stateless_callee_def image_def split!: key.ousr_alice.split) + +lemma WT_dec_callee [WT_intro]: + "\_uniform UNIV (sec.Out_Recv ` carrier \), \_uniform UNIV (key.Out_Bob ` carrier \) \\<^sub>\ \_uniform UNIV (sec.Out_Recv ` carrier \) \\<^sub>C CNV dec_callee () \" + by(rule WT_converter_of_callee)(auto simp add: dec_callee_def stateless_callee_def split!: sec.ousr_bob.splits) + +lemma pfinite_enc_callee [pfinite_intro]: + "pfinite_converter (\_uniform (sec.Inp_Send ` carrier \) UNIV) (\_uniform UNIV (key.Out_Alice ` carrier \) \\<^sub>\ \_uniform (sec.Inp_Send ` carrier \) UNIV) (CNV enc_callee ())" + apply(rule raw_converter_invariant.pfinite_converter_of_callee[where I="\_. True"]) + subgoal by unfold_locales(auto simp add: enc_callee_def stateless_callee_def) + subgoal by(auto simp add: enc_callee_def stateless_callee_def) + subgoal by simp + done + +lemma pfinite_dec_callee [pfinite_intro]: + "pfinite_converter (\_uniform UNIV (sec.Out_Recv ` carrier \)) (\_uniform UNIV (key.Out_Bob ` carrier \) \\<^sub>\ \_uniform UNIV (sec.Out_Recv ` carrier \)) (CNV dec_callee ())" + apply(rule raw_converter_invariant.pfinite_converter_of_callee[where I="\_. True"]) + subgoal by unfold_locales(auto simp add: dec_callee_def stateless_callee_def) + subgoal by(auto simp add: dec_callee_def stateless_callee_def) + subgoal by simp + done + +context + fixes + key_rest :: "('key_s_rest, key.event, 'key_iadv_rest, 'key_iusr_rest, 'key_oadv_rest, 'key_ousr_rest) rest_wstate" and + auth_rest :: "('auth_s_rest, auth.event, 'auth_iadv_rest, 'auth_iusr_rest, 'auth_oadv_rest, 'auth_ousr_rest) rest_wstate" and + \_adv_restk and \_adv_resta and \_usr_restk and \_usr_resta and I_key_rest and I_auth_rest + assumes + WT_key_rest [WT_intro]: "WT_rest \_adv_restk \_usr_restk I_key_rest key_rest" and + WT_auth_rest [WT_intro]: "WT_rest \_adv_resta \_usr_resta I_auth_rest auth_rest" +begin + +theorem secure: + defines "\_real \ ((\_full \\<^sub>\ (\_full \\<^sub>\ (\_full \\<^sub>\ \_uniform (sec.Inp_Fedit ` (carrier \)) UNIV))) \\<^sub>\ (\_adv_restk \\<^sub>\ \_adv_resta))" + and "\_common_core \ \_uniform (sec.Inp_Send ` (carrier \)) UNIV \\<^sub>\ \_uniform UNIV (sec.Out_Recv ` carrier \)" + and "\_common_rest \ \_usr_restk \\<^sub>\ \_usr_resta" + and "\_ideal \ (\_full \\<^sub>\ (\_full \\<^sub>\ \_uniform (sec.Inp_Fedit ` (carrier \)) UNIV)) \\<^sub>\ (\_adv_restk \\<^sub>\ \_adv_resta)" + shows "constructive_security_obsf (real_resource TYPE(_) TYPE(_) key_rest auth_rest) (sec.resource (ideal_rest key_rest auth_rest)) (sim |\<^sub>= 1\<^sub>C) \_real \_ideal (\_common_core \\<^sub>\ \_common_rest) \ 0" +proof + let ?\_common = "\_common_core \\<^sub>\ \_common_rest" + show "\_real \\<^sub>\ ?\_common \res real_resource TYPE(_) TYPE(_) key_rest auth_rest \" + unfolding \_real_def \_common_core_def \_common_rest_def real_resource_def attach_c1f22_c1f22_def wiring_c1r22_c1r22_def fused_wiring_def + by(rule WT_intro | simp )+ + + show [WT_intro]: "\_ideal \\<^sub>\ ?\_common \res sec.resource (ideal_rest key_rest auth_rest) \" + unfolding \_common_core_def \_common_rest_def \_ideal_def ideal_rest_def + by(rule WT_intro)+ simp + + show [WT_intro]: "\_real, \_ideal \\<^sub>C sim |\<^sub>= 1\<^sub>C \" + unfolding \_real_def \_ideal_def + apply(rule WT_intro)+ + subgoal + unfolding sim_def Let_def look_callee_def + apply (fold conv_callee_parallel_id_right[where s'="()"]) + apply (fold conv_callee_parallel_id_left[where s="()"]) + apply (subst ldummy_converter_of_callee) + apply (rule WT_converter_of_callee) + by (auto simp add: id_oracle_def map_gpv_conv_bind[symmetric] map_lift_spmf + split: auth.oadv_look.split option.split ) + by (rule WT_intro) + + show "pfinite_converter \_real \_ideal (sim |\<^sub>= 1\<^sub>C)" + unfolding \_real_def \_ideal_def + apply(rule pfinite_intro)+ + subgoal + unfolding sim_def Let_def look_callee_def + apply (fold conv_callee_parallel_id_right[where s'="()"]) + apply (fold conv_callee_parallel_id_left[where s="()"]) + apply (subst ldummy_converter_of_callee) + apply(rule raw_converter_invariant.pfinite_converter_of_callee[where I="\_. True"]) + subgoal + by unfold_locales (auto split!: sum.split sec.oadv_look.split option.split + simp add: left_gpv_map id_oracle_def intro!: WT_intro WT_gpv_right_gpv WT_gpv_left_gpv) + by (auto split!: sum.splits sec.oadv_look.splits option.splits) + by (rule pfinite_intro) + + assume WT [WT_intro]: "exception_\ (\_real \\<^sub>\ ?\_common) \g \ \" + show "advantage \ (obsf_resource ((sim |\<^sub>= 1\<^sub>C) |\<^sub>= (1\<^sub>C |\<^sub>= 1\<^sub>C) \ sec.resource (ideal_rest key_rest auth_rest))) + (obsf_resource (real_resource TYPE(_) TYPE(_) key_rest auth_rest)) \ 0" + using connect[OF WT_key_rest, OF WT_auth_rest, OF WT[unfolded assms(1, 2, 3)]] + unfolding advantage_def by (simp add: ideal_resource_def) +qed simp + +end + +end + + +subsection \Asymptotic security\ + +locale one_time_pad' = + fixes \ :: "security \ ('msg, 'more) boolean_algebra_scheme" + assumes one_time_pad [locale_witness]: "\\. one_time_pad (\ \)" +begin + +sublocale one_time_pad "\ \" for \ .. + +definition real_resource' where "real_resource' rest1 rest2 \ = real_resource TYPE(_) TYPE(_) \ (rest1 \) (rest2 \)" +definition ideal_resource' where "ideal_resource' rest1 rest2 \ = sec.resource \ (ideal_rest (rest1 \) (rest2 \))" +definition sim' where "sim' \ = (sim |\<^sub>= 1\<^sub>C)" + +context + fixes + key_rest :: "nat \ ('key_s_rest, key.event, 'key_iadv_rest, 'key_iusr_rest, 'key_oadv_rest, 'key_ousr_rest) rest_wstate" and + auth_rest :: "nat \ ('auth_s_rest, auth.event, 'auth_iadv_rest, 'auth_iusr_rest, 'auth_oadv_rest, 'auth_ousr_rest) rest_wstate" and + \_adv_restk and \_adv_resta and \_usr_restk and \_usr_resta and I_key_rest and I_auth_rest + assumes + WT_key_res: "\\. WT_rest (\_adv_restk \) (\_usr_restk \) (I_key_rest \) (key_rest \)" and + WT_auth_rest: "\\. WT_rest (\_adv_resta \) (\_usr_resta \) (I_auth_rest \) (auth_rest \)" +begin + +theorem secure': + defines "\_real \ \\. ((\_full \\<^sub>\ (\_full \\<^sub>\ (\_full \\<^sub>\ \_uniform (sec.Inp_Fedit ` (carrier (\ \))) UNIV))) \\<^sub>\ (\_adv_restk \ \\<^sub>\ \_adv_resta \))" + and "\_common \ \\. ((\_uniform (sec.Inp_Send ` (carrier (\ \))) UNIV \\<^sub>\ \_uniform UNIV (sec.Out_Recv ` carrier (\ \))) \\<^sub>\ (\_usr_restk \ \\<^sub>\ \_usr_resta \))" + and "\_ideal \ \\. (\_full \\<^sub>\ (\_full \\<^sub>\ \_uniform (sec.Inp_Fedit ` (carrier (\ \))) UNIV)) \\<^sub>\ (\_adv_restk \ \\<^sub>\ \_adv_resta \)" + shows "constructive_security_obsf' (real_resource' key_rest auth_rest) (ideal_resource' key_rest auth_rest) sim' \_real \_ideal \_common \" +proof(rule constructive_security_obsf'I) + show "constructive_security_obsf (real_resource' key_rest auth_rest \) (ideal_resource' key_rest auth_rest \) + (sim' \) (\_real \) (\_ideal \) (\_common \) (\ \) 0" for \ + unfolding real_resource'_def ideal_resource'_def sim'_def \_real_def \_common_def \_ideal_def + by(rule secure)(rule WT_key_res WT_auth_rest)+ +qed simp + +end + + +end + +end diff --git a/thys/Constructive_Cryptography_CM/Fold_Spmf.thy b/thys/Constructive_Cryptography_CM/Fold_Spmf.thy new file mode 100644 --- /dev/null +++ b/thys/Constructive_Cryptography_CM/Fold_Spmf.thy @@ -0,0 +1,200 @@ +theory Fold_Spmf + imports + More_CC +begin + +primrec (transfer) + foldl_spmf :: "('b \ 'a \ 'b spmf) \ 'b spmf \ 'a list \ 'b spmf" + where + foldl_spmf_Nil: "foldl_spmf f p [] = p" + | foldl_spmf_Cons: "foldl_spmf f p (x # xs) = foldl_spmf f (bind_spmf p (\a. f a x)) xs" + +lemma foldl_spmf_return_pmf_None [simp]: + "foldl_spmf f (return_pmf None) xs = return_pmf None" + by(induction xs) simp_all + +lemma foldl_spmf_bind_spmf: "foldl_spmf f (bind_spmf p g) xs = bind_spmf p (\a. foldl_spmf f (g a) xs)" + by(induction xs arbitrary: g) simp_all + +lemma bind_foldl_spmf_return: + "bind_spmf p (\x. foldl_spmf f (return_spmf x) xs) = foldl_spmf f p xs" + by(simp add: foldl_spmf_bind_spmf[symmetric]) + +lemma foldl_spmf_map [simp]: "foldl_spmf f p (map g xs) = foldl_spmf (map_fun id (map_fun g id) f) p xs" + by(induction xs arbitrary: p) simp_all + + +lemma foldl_spmf_identity [simp]: "foldl_spmf (\s x. return_spmf s) p xs = p" + by(induction xs arbitrary: p) simp_all + +lemma foldl_spmf_conv_foldl: + "foldl_spmf (\s x. return_spmf (f s x)) p xs = map_spmf (\s. foldl f s xs) p" + by(induction xs arbitrary: p)(simp_all add: map_spmf_conv_bind_spmf[symmetric] spmf.map_comp o_def) + +lemma foldl_spmf_Cons': + "foldl_spmf f (return_spmf a) (x # xs) = bind_spmf (f a x) (\a'. foldl_spmf f (return_spmf a') xs)" + by(simp add: bind_foldl_spmf_return) + +lemma foldl_spmf_append: "foldl_spmf f p (xs @ ys) = foldl_spmf f (foldl_spmf f p xs) ys" + by(induction xs arbitrary: p) simp_all + +lemma + foldl_spmf_helper: + assumes "\x. h (f x) = x" + assumes "\x. f (h x) = x" + shows "foldl_spmf (\a e. map_spmf h (g (f a) e)) acc es = + map_spmf h (foldl_spmf g (map_spmf f acc) es)" + using assms proof (induction es arbitrary: acc) + case (Cons a es) + then show ?case + by (simp add: spmf.map_comp map_bind_spmf bind_map_spmf o_def) +qed (simp add: map_spmf_conv_bind_spmf) + +lemma + foldl_spmf_helper2: + assumes "\x y. p (f x y) = x" + assumes "\x y. q (f x y) = y" + assumes "\x. f (p x) (q x) = x" + shows "foldl_spmf (\a e. map_spmf (f (p a)) (g (q a) e)) acc es = + bind_spmf acc (\acc'. map_spmf (f (p acc')) (foldl_spmf g (return_spmf (q acc')) es))" + proof (induction es arbitrary: acc) + note [simp] = spmf.map_comp map_bind_spmf bind_map_spmf o_def + case (Cons e es) + then show ?case + apply (simp add: map_spmf_conv_bind_spmf assms) + apply (subst bind_spmf_assoc[symmetric]) + by (simp add: bind_foldl_spmf_return) +qed (simp add: assms(3)) + +lemma foldl_pair_constl: "foldl (\s e. map_prod (\_. c) (\r. f r e) s) (c, sr) l = + Pair c (foldl (\s e. f s e) sr l)" + by (induction l arbitrary: sr) (auto simp add: map_prod_def split_def) + +lemma foldl_spmf_pair_left: + "foldl_spmf (\(l, r) e. map_spmf (\l'. (l', r)) (f l e)) (return_spmf (l, r)) es = + map_spmf (\l'. (l', r)) (foldl_spmf f (return_spmf l) es)" + apply (induction es arbitrary: l) + apply simp_all + apply (subst (2) map_spmf_conv_bind_spmf) + apply (subst foldl_spmf_bind_spmf) + apply (subst (2) bind_foldl_spmf_return[symmetric]) + by (simp add: map_spmf_conv_bind_spmf) + +lemma foldl_spmf_pair_left2: + "foldl_spmf (\(l, _) e. map_spmf (\l'. (l', c')) (f l e)) (return_spmf (l, c)) es = + map_spmf (\l'. (l', if es = [] then c else c')) (foldl_spmf f (return_spmf l) es)" + apply (induction es arbitrary: l c c') + apply simp_all + apply (subst (2) map_spmf_conv_bind_spmf) + apply (subst foldl_spmf_bind_spmf) + apply (subst (2) bind_foldl_spmf_return[symmetric]) + by (simp add: map_spmf_conv_bind_spmf) + +lemma foldl_pair_constr: "foldl (\s e. map_prod (\l. f l e) (\_. c) s) (sl, c) l = + Pair (foldl (\s e. f s e) sl l) c" + by (induction l arbitrary: sl) (auto simp add: map_prod_def split_def) + +lemma foldl_spmf_pair_right: + "foldl_spmf (\(l, r) e. map_spmf (\r'. (l, r')) (f r e)) (return_spmf (l, r)) es = + map_spmf (\r'. (l, r')) (foldl_spmf f (return_spmf r) es)" + apply (induction es arbitrary: r) + apply simp_all + apply (subst (2) map_spmf_conv_bind_spmf) + apply (subst foldl_spmf_bind_spmf) + apply (subst (2) bind_foldl_spmf_return[symmetric]) + by (simp add: map_spmf_conv_bind_spmf) + +lemma foldl_spmf_pair_right2: + "foldl_spmf (\(_, r) e. map_spmf (\r'. (c', r')) (f r e)) (return_spmf (c, r)) es = + map_spmf (\r'. (if es = [] then c else c', r')) (foldl_spmf f (return_spmf r) es)" + apply (induction es arbitrary: r c c') + apply simp_all + apply (subst (2) map_spmf_conv_bind_spmf) + apply (subst foldl_spmf_bind_spmf) + apply (subst (2) bind_foldl_spmf_return[symmetric]) + by (auto simp add: map_spmf_conv_bind_spmf split_def) + +lemma foldl_spmf_pair_right3: + "foldl_spmf (\(l, r) e. map_spmf (Pair (g e)) (f r e)) (return_spmf (l, r)) es = + map_spmf (Pair (if es = [] then l else g (last es))) (foldl_spmf f (return_spmf r) es)" + apply (induction es arbitrary: r l) + apply simp_all + apply (subst (2) map_spmf_conv_bind_spmf) + apply (subst foldl_spmf_bind_spmf) + apply (subst (2) bind_foldl_spmf_return[symmetric]) + by (clarsimp simp add: split_def map_bind_spmf o_def) + +lemma foldl_pullout: "bind_spmf f (\x. bind_spmf (foldl_spmf g init (events x)) (\y. h x y)) = + bind_spmf (bind_spmf f (\x. foldl_spmf (\(l, r) e. map_spmf (Pair l) (g r e)) (map_spmf (Pair x) init) (events x))) + (\(x, y). h x y)" for f g h init events + apply (simp add: foldl_spmf_helper2[where f=Pair and p=fst and q=snd, simplified] split_def) + apply (clarsimp simp add: map_spmf_conv_bind_spmf) + by (subst bind_spmf_assoc[symmetric]) (auto simp add: bind_foldl_spmf_return) + +lemma bind_foldl_spmf_pair_append: " + bind_spmf + (foldl_spmf (\(x, y) e. map_spmf (apfst ((@) x)) (f y e)) (return_spmf (a @ c, b)) es) + (\(x, y). g x y) = + bind_spmf + (foldl_spmf (\(x, y) e. map_spmf (apfst ((@) x)) (f y e)) (return_spmf (c, b)) es) + (\(x, y). g (a @ x) y)" + apply (induction es arbitrary: c b) + apply (simp_all add: split_def map_spmf_conv_bind_spmf apfst_def map_prod_def) + apply (subst (1 2) foldl_spmf_bind_spmf) + by simp + +lemma foldl_spmf_chain: " +(foldl_spmf (\(oevents, s_event) event. map_spmf (map_prod ((@) oevents) id) (fff s_event event)) (return_spmf ([], s_event)) ievents) + \ (\(oevents, s_event'). foldl_spmf ggg (return_spmf s_core) oevents + \ (\s_core'. return_spmf (f s_core' s_event'))) = +foldl_spmf (\(s_event, s_core) event. fff s_event event \ (\(oevents, s_event'). + map_spmf (Pair s_event') (foldl_spmf ggg (return_spmf s_core) oevents))) (return_spmf (s_event, s_core)) ievents + \ (\(s_event', s_core'). return_spmf (f s_core' s_event'))" +proof (induction ievents arbitrary: s_event s_core) + case Nil + show ?case by simp +next + case (Cons e es) + + show ?case + apply (subst (1 2) foldl_spmf_Cons') + apply (simp add: split_def) + apply (subst map_spmf_conv_bind_spmf) + apply simp + apply (rule bind_spmf_cong[OF refl]) + apply (subst (2) map_spmf_conv_bind_spmf) + apply simp + apply (subst Cons.IH[symmetric, simplified split_def]) + apply (subst bind_commute_spmf) + apply (subst (2) map_spmf_conv_bind_spmf[symmetric]) + apply (subst map_bind_spmf[symmetric, simplified o_def]) + apply (subst (1) foldl_spmf_bind_spmf[symmetric]) + apply (subst (3) map_spmf_conv_bind_spmf) + apply (simp add: foldl_spmf_append[symmetric] map_prod_def split_def) + subgoal for x + apply (cases x) + subgoal for a b + apply (simp add: split_def) + apply (subst bind_foldl_spmf_pair_append[where c="[]" and a=a and b=b and es=es, simplified apfst_def map_prod_def append_Nil2 split_def id_def]) + by simp + done + done +qed + + +\ \pauses\ +primrec pauses :: "'a list \ (unit, 'a, 'b) gpv" where + "pauses [] = Done ()" +| "pauses (x # xs) = Pause x (\_. pauses xs)" + +lemma WT_gpv_pauses [WT_intro]: + "\ \g pauses xs \" if "set xs \ outs_\ \" + using that by(induction xs) auto + +lemma exec_gpv_pauses: + "exec_gpv callee (pauses xs) s = + map_spmf (Pair ()) (foldl_spmf (map_fun id (map_fun id (map_spmf snd)) callee) (return_spmf s) xs)" + by(induction xs arbitrary: s)(simp_all add: split_def foldl_spmf_Cons' map_bind_spmf bind_map_spmf o_def del: foldl_spmf_Cons) + + +end \ No newline at end of file diff --git a/thys/Constructive_Cryptography_CM/Fused_Resource.thy b/thys/Constructive_Cryptography_CM/Fused_Resource.thy new file mode 100644 --- /dev/null +++ b/thys/Constructive_Cryptography_CM/Fused_Resource.thy @@ -0,0 +1,1721 @@ +theory Fused_Resource imports + Fold_Spmf +begin + +(* TODO: move these somewhere *) +context includes \.lifting begin +lift_definition e\ :: "('a, 'b) \ \ ('a, 'b \ 'c) \" is "\\ x. \ x \ UNIV" . + +lemma outs_\_e\[simp]: "outs_\ (e\ \) = outs_\ \" + by transfer simp + +lemma responses_\_e\ [simp]: "responses_\ (e\ \) x = responses_\ \ x \ UNIV" + by transfer simp + +lemma e\_map_\: "e\ (map_\ f g \) = map_\ f (apfst g) (e\ \)" + by transfer(auto simp add: fun_eq_iff intro: rev_image_eqI) + +lemma e\_inverse [simp]: "map_\ id fst (e\ \) = \" + by transfer auto +end +lifting_update \.lifting +lifting_forget \.lifting + + +section \Fused Resource\ + +subsection \Event Oracles -- they generate events\ + +type_synonym + ('state, 'event, 'input, 'output) eoracle = "('state, 'input, 'output \ 'event list) oracle'" + +definition + parallel_eoracle :: " + ('s1, 'e1, 'i1, 'o1) eoracle \ ('s2, 'e2, 'i2, 'o2) eoracle \ + ('s1 \ 's2, 'e1 + 'e2, 'i1 + 'i2, 'o1 + 'o2) eoracle" + where + "parallel_eoracle eoracle1 eoracle2 state \ + comp + (map_spmf + (map_prod + (case_sum + (map_prod Inl (map Inl)) + (map_prod Inr (map Inr))) + id)) + (parallel_oracle eoracle1 eoracle2 state)" + +definition + plus_eoracle :: " + ('s, 'e1, 'i1, 'o1) eoracle \ ('s, 'e2, 'i2, 'o2) eoracle \ + ('s, 'e1 + 'e2, 'i1 + 'i2, 'o1 + 'o2) eoracle" + where + "plus_eoracle eoracle1 eoracle2 state \ + comp + (map_spmf + (map_prod + (case_sum + (map_prod Inl (map Inl)) + (map_prod Inr (map Inr))) + id)) + (plus_oracle eoracle1 eoracle2 state)" + +definition + translate_eoracle :: " + ('s_event, 'e1, 'e2 list) oracle' \ ('s_event \ 's, 'e1, 'i, 'o) eoracle \ + ('s_event \ 's, 'e2, 'i, 'o) eoracle" + where + "translate_eoracle translator eoracle state inp \ + bind_spmf + (eoracle state inp) + (\((out, e_in), s). + let conc = (\(es, st) e. map_spmf (map_prod ((@) es) id) (translator st e)) in do { + (e_out, s_event) \ foldl_spmf conc (return_spmf ([], fst s)) e_in; + return_spmf ((out, e_out), s_event, snd s) + })" + + +subsection \Event Handlers -- they absorb (and silently handle) events\ + +type_synonym + ('state, 'event) handler = "'state \ 'event \ 'state spmf" + +fun + parallel_handler :: "('s1, 'e1) handler \ ('s2, 'e2) handler \ ('s1 \ 's2, 'e1 + 'e2) handler" + where + "parallel_handler left _ s (Inl e1) = map_spmf (\s1'. (s1', snd s)) (left (fst s) e1)" + | "parallel_handler _ right s (Inr e2) = map_spmf (\s2'. (fst s, s2')) (right (snd s) e2)" + +definition + plus_handler :: "('s, 'e1) handler \ ('s, 'e2) handler \ ('s, 'e1 + 'e2) handler" + where + "plus_handler left right s \ case_sum (left s) (right s)" + +lemma parallel_handler_left: + "map_fun id (map_fun Inl id) (parallel_handler left right) = + (\(s_l, s_r) q. map_spmf (\s_l'. (s_l', s_r)) (left s_l q))" + by force + +lemma parallel_handler_right: + "map_fun id (map_fun Inr id) (parallel_handler left right) = + (\(s_l, s_r) q. map_spmf (\s_r'. (s_l, s_r')) (right s_r q))" + by force + +lemma in_set_spmf_parallel_handler: + "s' \ set_spmf (parallel_handler left right s x) \ + (case x of Inl e \ fst s' \ set_spmf (left (fst s) e) \ snd s' = snd s + | Inr e \ snd s' \ set_spmf (right (snd s) e) \ fst s' = fst s)" + by(cases s; cases s'; auto split: sum.split) + +subsection \Fused Resource Construction\ + +codatatype + ('s_core, 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core = + Core + (cpoke: "('s_core, 'event) handler") + (cfunc_adv: "('s_core, 'iadv_core, 'oadv_core) oracle'") + (cfunc_usr: "('s_core, 'iusr_core, 'ousr_core) oracle'") + +declare core.sel_transfer[transfer_rule del] +declare core.ctr_transfer[transfer_rule del] +declare core.case_transfer[transfer_rule del] + +context + includes lifting_syntax +begin + +inductive + rel_core':: " + ('s_core \ 's_core' \ bool) \ + ('event \ 'event' \ bool) \ + ('iadv_core \ 'iadv_core' \ bool) \ + ('iusr_core \ 'iusr_core' \ bool) \ + ('oadv_core \ 'oadv_core' \ bool) \ + ('ousr_core \ 'ousr_core' \ bool) \ + ('s_core, 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core \ + ('s_core', 'event', 'iadv_core', 'iusr_core', 'oadv_core', 'ousr_core') core \ bool" + for S E IA IU OA OU + where "rel_core' S E IA IU OA OU (Core cpoke cfunc_adv cfunc_usr) (Core cpoke' cfunc_adv' cfunc_usr')" + if + "(S ===> E ===> rel_spmf S) cpoke cpoke'" and + "(S ===> IA ===> rel_spmf (rel_prod OA S)) cfunc_adv cfunc_adv'" and + "(S ===> IU ===> rel_spmf (rel_prod OU S)) cfunc_usr cfunc_usr'" + for cpoke cfunc_adv cfunc_usr + +inductive_simps + rel_core'_simps [simp]: + "rel_core' S E IA IU OA OU (Core cpoke' cfunc_adv' cfunc_usr') (Core cpoke'' cfunc_adv'' cfunc_usr'')" + +lemma + rel_core'_eq [relator_eq]: + "rel_core' (=) (=) (=) (=) (=) (=) = (=)" + apply(intro ext) + subgoal for x y by(cases x; cases y)(auto simp add: fun_eq_iff rel_fun_def relator_eq) + done + +lemma + rel_core'_mono [relator_mono]: + "rel_core' S E IA IU OA OU \ rel_core' S E' IA' IU' OA' OU'" + if "E' \ E" "IA' \ IA" "IU' \ IU" "OA \ OA'" "OU \ OU'" + apply(rule predicate2I) + subgoal for x y + apply(cases x; cases y; clarsimp; intro conjI) + apply(erule rel_fun_mono rel_spmf_mono prod.rel_mono[THEN predicate2D, rotated -1] | + rule impI that order_refl | erule that[THEN predicate2D] | erule rel_spmf_mono | assumption)+ + done + done + +lemma + cpoke_parametric [transfer_rule]: + "(rel_core' S E IA IU OA OU ===> S ===> E ===> rel_spmf S) cpoke cpoke" + by(rule rel_funI; erule rel_core'.cases; simp) + +lemma + cfunc_adv_parametric [transfer_rule]: + "(rel_core' S E IA IU OA OU ===> S ===> IA ===> rel_spmf (rel_prod OA S)) cfunc_adv cfunc_adv" + by(rule rel_funI; erule rel_core'.cases; simp) + +lemma + cfunc_usr_parametric [transfer_rule]: + "(rel_core' S E IA IU OA OU ===> S ===> IU ===> rel_spmf (rel_prod OU S)) cfunc_usr cfunc_usr" + by(rule rel_funI; erule rel_core'.cases; simp) + +lemma + Core_parametric [transfer_rule]: + "((S ===> E ===> rel_spmf S) ===> (S ===> IA ===> rel_spmf (rel_prod OA S)) ===> (S ===> IU ===> rel_spmf (rel_prod OU S)) + ===> rel_core' S E IA IU OA OU) Core Core" + by(rule rel_funI)+ simp + +lemma + case_core_parametric [transfer_rule]: + "(((S ===> E ===> rel_spmf S) ===> + (S ===> IA ===> rel_spmf (rel_prod OA S)) ===> + (S ===> IU ===> rel_spmf (rel_prod OU S)) ===> X) ===> + rel_core' S E IA IU OA OU ===> X) case_core case_core" + by(rule rel_funI)+(auto 4 4 split: core.split dest: rel_funD) + +lemma + corec_core_parametric [transfer_rule]: + "((X ===> S ===> E ===> rel_spmf S) ===> + (X ===> S ===> IA ===> rel_spmf (rel_prod OA S)) ===> + (X ===> S ===> IU ===> rel_spmf (rel_prod OU S)) ===> + X ===> rel_core' S E IA IU OA OU) corec_core corec_core" + by(rule rel_funI)+(auto simp add: core.corec dest: rel_funD) + +primcorec map_core' :: + "('event' \ 'event) \ + ('iadv_core' \ 'iadv_core) \ + ('iusr_core' \ 'iusr_core) \ + ('oadv_core \ 'oadv_core') \ + ('ousr_core \ 'ousr_core') \ + ('s_core, 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core \ + ('s_core, 'event', 'iadv_core', 'iusr_core', 'oadv_core', 'ousr_core') core" + where + "cpoke (map_core' e ia iu oa ou core) = (id ---> e ---> id) (cpoke core)" +| "cfunc_adv (map_core' e ia iu oa ou core) = (id ---> ia ---> map_spmf (map_prod oa id)) (cfunc_adv core)" +| "cfunc_usr (map_core' e ia iu oa ou core) = (id ---> iu ---> map_spmf (map_prod ou id)) (cfunc_usr core)" + +lemmas map_core'_simps [simp] = map_core'.ctr[where core="Core _ _ _", simplified] + +parametric_constant map_core'_parametric[transfer_rule]: map_core'_def + +lemma core'_rel_Grp: + "rel_core' (=) (BNF_Def.Grp UNIV e)\\ (BNF_Def.Grp UNIV ia)\\ (BNF_Def.Grp UNIV iu)\\ (BNF_Def.Grp UNIV oa) (BNF_Def.Grp UNIV ou) + = BNF_Def.Grp UNIV (map_core' e ia iu oa ou)" + apply(intro ext) + subgoal for x y + apply(cases x; cases y; clarsimp) + apply(subst (2 4 6) eq_alt_conversep) + apply(subst (2 3 4) eq_alt) + apply(simp add: pmf.rel_Grp option.rel_Grp prod.rel_Grp rel_fun_conversep_grp_grp) + apply(auto simp add: Grp_def spmf.map_id[abs_def] id_def[symmetric]) + done + done + +end + +inductive WT_core :: "('iadv, 'oadv) \ \ ('iusr, 'ousr) \ \ ('s \ bool) \ ('s, 'event, 'iadv, 'iusr, 'oadv, 'ousr) core \ bool" + for \_adv \_usr I core where + "WT_core \_adv \_usr I core" if + "\s e s'. \ s' \ set_spmf (cpoke core s e); I s \ \ I s'" + "\s x y s'. \ (y, s') \ set_spmf (cfunc_adv core s x); x \ outs_\ \_adv; I s \ \ y \ responses_\ \_adv x \ I s'" + "\s x y s'. \ (y, s') \ set_spmf (cfunc_usr core s x); x \ outs_\ \_usr; I s \ \ y \ responses_\ \_usr x \ I s'" + +lemma WT_coreD: + assumes "WT_core \_adv \_usr I core" + shows WT_coreD_cpoke: "\s e s'. \ s' \ set_spmf (cpoke core s e); I s \ \ I s'" + and WT_coreD_cfunc_adv: "\s x y s'. \ (y, s') \ set_spmf (cfunc_adv core s x); x \ outs_\ \_adv; I s \ \ y \ responses_\ \_adv x \ I s'" + and WT_coreD_cfund_usr: "\s x y s'. \ (y, s') \ set_spmf (cfunc_usr core s x); x \ outs_\ \_usr; I s \ \ y \ responses_\ \_usr x \ I s'" + using assms by(auto elim!: WT_core.cases) + +lemma WT_coreD_foldl_spmf_cpoke: + assumes "WT_core \_adv \_usr I core" + and "s' \ set_spmf (foldl_spmf (cpoke core) p es)" + and "\s \ set_spmf p. I s" + shows "I s'" + using assms(2, 3) + by(induction es arbitrary: p)(fastforce dest: WT_coreD_cpoke[OF assms(1)] simp add: bind_UNION)+ + +lemma WT_core_trivial: + assumes adv: "\s. \_adv \c cfunc_adv core s \" + and usr: "\s. \_usr \c cfunc_usr core s \" + shows "WT_core \_adv \_usr (\_. True) core" + by(rule WT_core.intros)(auto dest: assms[THEN WT_calleeD]) + +codatatype + ('s_rest, 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'more) rest_scheme = + Rest + (rinit: "'more") + (rfunc_adv: "('s_rest, 'event, 'iadv_rest, 'oadv_rest) eoracle") + (rfunc_usr: "('s_rest, 'event, 'iusr_rest, 'ousr_rest) eoracle") + +declare rest_scheme.sel_transfer[transfer_rule del] +declare rest_scheme.ctr_transfer[transfer_rule del] +declare rest_scheme.case_transfer[transfer_rule del] + +context + includes lifting_syntax +begin + +inductive + rel_rest':: " + ('s_rest \ 's_rest' \ bool) \ + ('event \ 'event' \ bool) \ + ('iadv_rest \ 'iadv_rest' \ bool) \ + ('iusr_rest \ 'iusr_rest' \ bool) \ + ('oadv_rest \ 'oadv_rest' \ bool) \ + ('ousr_rest \ 'ousr_rest' \ bool) \ + ('more \ 'more' \ bool) \ + ('s_rest, 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'more) rest_scheme \ + ('s_rest', 'event', 'iadv_rest', 'iusr_rest', 'oadv_rest', 'ousr_rest', 'more') rest_scheme \ bool" + for S E IA IU OA OU M + where "rel_rest' S E IA IU OA OU M (Rest rinit rfunc_adv rfunc_usr) (Rest rinit' rfunc_adv' rfunc_usr')" + if + "M rinit rinit'" and + "(S ===> IA ===> rel_spmf (rel_prod (rel_prod OA (list_all2 E)) S)) rfunc_adv rfunc_adv'" and + "(S ===> IU ===> rel_spmf (rel_prod (rel_prod OU (list_all2 E)) S)) rfunc_usr rfunc_usr'" + for rinit rfunc_adv rfunc_usr + +inductive_simps + rel_rest'_simps [simp]: + "rel_rest' S E IA IU OA OU M (Rest rinit' rfunc_adv' rfunc_usr') (Rest rinit'' rfunc_adv'' rfunc_usr'')" + +lemma + rel_rest'_eq [relator_eq]: + "rel_rest' (=) (=) (=) (=) (=) (=) (=) = (=)" + apply(intro ext) + subgoal for x y by(cases x; cases y)(auto simp add: fun_eq_iff rel_fun_def relator_eq) + done + +lemma + rel_rest'_mono [relator_mono]: + "rel_rest' S E IA IU OA OU M \ rel_rest' S E' IA' IU' OA' OU' M'" + if "E \ E'" "IA' \ IA" "IU' \ IU" "OA \ OA'" "OU \ OU'" "M \ M'" + apply(rule predicate2I) + subgoal for x y + apply(cases x; cases y; clarsimp; intro conjI) + apply(erule rel_fun_mono rel_spmf_mono prod.rel_mono[THEN predicate2D, rotated -1] | + rule impI that order_refl prod.rel_mono list.rel_mono | erule that[THEN predicate2D] | erule rel_spmf_mono | assumption)+ + done + done + +lemma rel_rest'_sel: "rel_rest' S E IA IU OA OU M rest1 rest2" + if "M (rinit rest1) (rinit rest2)" + and "(S ===> IA ===> rel_spmf (rel_prod (rel_prod OA (list_all2 E)) S)) (rfunc_adv rest1) (rfunc_adv rest2)" + and "(S ===> IU ===> rel_spmf (rel_prod (rel_prod OU (list_all2 E)) S)) (rfunc_usr rest1) (rfunc_usr rest2)" + using that by(cases rest1; cases rest2) simp + +lemma rinit_parametric [transfer_rule]: "(rel_rest' S E IA IU OA OU M ===> M) rinit rinit" + by(rule rel_funI; erule rel_rest'.cases; simp) + +lemma rfunc_adv_parametric [transfer_rule]: + "(rel_rest' S E IA IU OA OU M ===> S ===> IA ===> rel_spmf (rel_prod (rel_prod OA (list_all2 E)) S)) rfunc_adv rfunc_adv" + by(rule rel_funI; erule rel_rest'.cases; simp) + +lemma rfunc_usr_parametric [transfer_rule]: + "(rel_rest' S E IA IU OA OU M ===> S ===> IU ===> rel_spmf (rel_prod (rel_prod OU (list_all2 E)) S)) rfunc_usr rfunc_usr" + by(rule rel_funI; erule rel_rest'.cases; simp) + +lemma Rest_parametric [transfer_rule]: + "(M ===> (S ===> IA ===> rel_spmf (rel_prod (rel_prod OA (list_all2 E)) S)) + ===> (S ===> IU ===> rel_spmf (rel_prod (rel_prod OU (list_all2 E)) S)) + ===> rel_rest' S E IA IU OA OU M) Rest Rest" + by(rule rel_funI)+ simp + +lemma case_rest_scheme_parametric [transfer_rule]: + "((M ===> + (S ===> IA ===> rel_spmf (rel_prod (rel_prod OA (list_all2 E)) S)) ===> + (S ===> IU ===> rel_spmf (rel_prod (rel_prod OU (list_all2 E)) S)) ===> X) ===> + rel_rest' S E IA IU OA OU M ===> X) case_rest_scheme case_rest_scheme" + by(rule rel_funI)+(auto 4 4 split: rest_scheme.split dest: rel_funD) + +lemma corec_rest_scheme_parametric [transfer_rule]: + "((X ===> M) ===> + (X ===> S ===> IA ===> rel_spmf (rel_prod (rel_prod OA (list_all2 E)) S)) ===> + (X ===> S ===> IU ===> rel_spmf (rel_prod (rel_prod OU (list_all2 E)) S)) ===> + X ===> rel_rest' S E IA IU OA OU M) corec_rest_scheme corec_rest_scheme" + by(rule rel_funI)+(auto simp add: rest_scheme.corec dest: rel_funD) + +primcorec map_rest' :: + "('event \ 'event') \ + ('iadv_rest' \ 'iadv_rest) \ + ('iusr_rest' \ 'iusr_rest) \ + ('oadv_rest \ 'oadv_rest') \ + ('ousr_rest \ 'ousr_rest') \ + ('more \ 'more') \ + ('s_rest, 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'more) rest_scheme \ + ('s_rest, 'event', 'iadv_rest', 'iusr_rest', 'oadv_rest', 'ousr_rest', 'more') rest_scheme" + where + "rinit (map_rest' e ia iu oa ou m rest) = m (rinit rest)" +| "rfunc_adv (map_rest' e ia iu oa ou m rest) = + (id ---> ia ---> map_spmf (map_prod (map_prod oa (map e)) id)) (rfunc_adv rest)" +| "rfunc_usr (map_rest' e ia iu oa ou m rest) = + (id ---> iu ---> map_spmf (map_prod (map_prod ou (map e)) id)) (rfunc_usr rest)" + +lemmas map_rest'_simps [simp] = map_rest'.ctr[where rest="Rest _ _ _", simplified] + +parametric_constant map_rest'_parametric[transfer_rule]: map_rest'_def + +lemma rest'_rel_Grp: + "rel_rest' (=) (BNF_Def.Grp UNIV e) (BNF_Def.Grp UNIV ia)\\ (BNF_Def.Grp UNIV iu)\\ (BNF_Def.Grp UNIV oa) (BNF_Def.Grp UNIV ou) (BNF_Def.Grp UNIV m) + = BNF_Def.Grp UNIV (map_rest' e ia iu oa ou m)" + apply(intro ext) + subgoal for x y + apply(cases x; cases y; clarsimp) + apply(subst (2 4) eq_alt_conversep) + apply(subst (2 3) eq_alt) + apply(simp add: pmf.rel_Grp list.rel_Grp option.rel_Grp prod.rel_Grp rel_fun_conversep_grp_grp) + apply(auto simp add: Grp_def spmf.map_id[abs_def] id_def[symmetric]) + done + done + +end + +type_synonym + ('s_rest, 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest) rest_wstate = + "('s_rest, 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 's_rest) rest_scheme" + +inductive WT_rest :: "('iadv, 'oadv) \ \ ('iusr, 'ousr) \ \ ('s \ bool) \ ('s, 'event, 'iadv, 'iusr, 'oadv, 'ousr) rest_wstate \ bool" + for \_adv \_usr I rest where + "WT_rest \_adv \_usr I rest" if + "\s x y es s'. \ ((y, es), s') \ set_spmf (rfunc_adv rest s x); x \ outs_\ \_adv; I s \ \ y \ responses_\ \_adv x \ I s'" + "\s x y es s'. \ ((y, es), s') \ set_spmf (rfunc_usr rest s x); x \ outs_\ \_usr; I s \ \ y \ responses_\ \_usr x \ I s'" + "I (rinit rest)" + +lemma WT_restD: + assumes "WT_rest \_adv \_usr I rest" + shows WT_restD_rfunc_adv: "\s x y es s'. \ ((y, es), s') \ set_spmf (rfunc_adv rest s x); x \ outs_\ \_adv; I s \ \ y \ responses_\ \_adv x \ I s'" + and WT_restD_rfunc_usr: "\s x y es s'. \ ((y, es), s') \ set_spmf (rfunc_usr rest s x); x \ outs_\ \_usr; I s \ \ y \ responses_\ \_usr x \ I s'" + and WT_restD_rinit: "I (rinit rest)" + using assms by(auto elim!: WT_rest.cases) + +abbreviation + fuse_cfunc :: " + ('o \ 'x) \ ('s_core, 'i, 'o) oracle' \ ('s_core \ 's_rest, 'i , 'x) oracle'" + where + "fuse_cfunc redirect cfunc state inp \ do { + let handle = map_prod redirect (prod.swap o Pair (snd state)); + (os_cfunc :: 'o \ 's_core) \ cfunc (fst state) inp; + return_spmf (handle os_cfunc) + }" + +abbreviation + fuse_rfunc :: " + ('o \ 'x) \ ('s_rest, 'e, 'i, 'o) eoracle \ ('s_core, 'e) handler \ + ('s_core \ 's_rest, 'i , 'x) oracle'" + where + "fuse_rfunc redirect rfunc notify state inp \ + bind_spmf + (rfunc (snd state) inp) + (\((o_rfunc, e_lst), s_rfunc). + bind_spmf + (foldl_spmf notify (return_spmf (fst state)) e_lst) + (\s_notify. return_spmf (redirect o_rfunc, s_notify, s_rfunc))) + " + + +locale fused_resource = + fixes + core :: "('s_core, 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core" and + core_init :: 's_core +begin + +fun + fuse :: " + ('s_rest, 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'm) rest_scheme \ + ('s_core \ 's_rest, + ('iadv_core + 'iadv_rest) + ('iusr_core + 'iusr_rest), + ('oadv_core + 'oadv_rest) + ('ousr_core + 'ousr_rest)) oracle'" + where + "fuse rest state (Inl (Inl iadv_core)) = + fuse_cfunc (Inl o Inl) (cfunc_adv core) state iadv_core" + | "fuse rest state (Inl (Inr iadv_rest)) = + fuse_rfunc (Inl o Inr) (rfunc_adv rest) (cpoke core) state iadv_rest" + | "fuse rest state (Inr (Inl iusr_core)) = + fuse_cfunc (Inr o Inl) (cfunc_usr core) state iusr_core" + | "fuse rest state (Inr (Inr iusr_rest)) = + fuse_rfunc (Inr o Inr) (rfunc_usr rest) (cpoke core) state iusr_rest" + +case_of_simps fuse_case: fused_resource.fuse.simps + +lemma callee_invariant_on_fuse: + assumes "WT_core \_adv_core \_usr_core I_core core" + and "WT_rest \_adv_rest \_usr_rest I_rest rest" + shows "callee_invariant_on (fuse rest) (pred_prod I_core I_rest) ((\_adv_core \\<^sub>\ \_adv_rest) \\<^sub>\ (\_usr_core \\<^sub>\ \_usr_rest))" +proof(unfold_locales, goal_cases) + case (1 s x y s') + then show ?case using assms + by(cases s; cases s')(auto 4 4 dest: WT_restD WT_coreD WT_coreD_foldl_spmf_cpoke) +next + case (2 s) + show ?case + apply(rule WT_calleeI) + subgoal for x y s' using 2 assms + by (cases "(rest, s, x)" rule: fuse.cases) (auto simp add: pred_prod_beta dest: WT_restD WT_coreD ) + done +qed + +definition + resource :: " + ('s_rest, 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest) rest_wstate \ + (('iadv_core + 'iadv_rest) + ('iusr_core + 'iusr_rest), + ('oadv_core + 'oadv_rest) + ('ousr_core + 'ousr_rest)) resource" + where + "resource rest = resource_of_oracle (fuse rest) (core_init, rinit rest)" + +lemma WT_resource [WT_intro]: + assumes "WT_core \_adv_core \_usr_core I_core core" + and "WT_rest \_adv_rest \_usr_rest I_rest rest" + and "I_core core_init" + shows "(\_adv_core \\<^sub>\ \_adv_rest) \\<^sub>\ (\_usr_core \\<^sub>\ \_usr_rest) \res resource rest \" +proof - + interpret callee_invariant_on "fuse rest" "pred_prod I_core I_rest" "(\_adv_core \\<^sub>\ \_adv_rest) \\<^sub>\ (\_usr_core \\<^sub>\ \_usr_rest)" + using assms(1,2) by(rule callee_invariant_on_fuse) + show ?thesis unfolding resource_def + by(rule WT_resource_of_oracle)(simp add: assms(3) WT_restD_rinit[OF assms(2)]) +qed + +end + +parametric_constant + fuse_parametric [transfer_rule]: fused_resource.fuse_case + +subsection \More helpful construction functions\ + +context + fixes + core1 :: "('s_core1, 'event1, 'iadv_core1, 'iusr_core1, 'oadv_core1, 'ousr_core1) core" and + core2 :: "('s_core2, 'event2, 'iadv_core2, 'iusr_core2, 'oadv_core2, 'ousr_core2) core" +begin + +primcorec parallel_core :: " + ('s_core1 \ 's_core2, 'event1 + 'event2, + 'iadv_core1 + 'iadv_core2, 'iusr_core1 + 'iusr_core2, + 'oadv_core1 + 'oadv_core2, 'ousr_core1 + 'ousr_core2) core" + where + "cpoke parallel_core = parallel_handler (cpoke core1) (cpoke core2)" + | "cfunc_adv parallel_core = parallel_oracle (cfunc_adv core1) (cfunc_adv core2)" + | "cfunc_usr parallel_core = parallel_oracle (cfunc_usr core1) (cfunc_usr core2)" + +end + + +context + fixes + cnv_adv :: "'s_adv \ 'iadv \ ('oadv \ 's_adv, 'iadv_core, 'oadv_core) gpv" and + cnv_usr :: "'s_usr \ 'iusr \ ('ousr \ 's_usr, 'iusr_core, 'ousr_core) gpv" and + core :: "('s_core, 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core" +begin + +primcorec + attach_core :: "(('s_adv \ 's_usr) \ 's_core, 'event, 'iadv, 'iusr, 'oadv, 'ousr) core" + where + "cpoke attach_core = (\(s_advusr, s_core) event. + map_spmf (\s_core'. (s_advusr, s_core')) (cpoke core s_core event))" + | "cfunc_adv attach_core = (\((s_adv, s_usr), s_core) iadv. + map_spmf + (\((oadv, s_adv'), s_core'). (oadv, ((s_adv', s_usr), s_core'))) + (exec_gpv (cfunc_adv core) (cnv_adv s_adv iadv) s_core))" + | "cfunc_usr attach_core = (\((s_adv, s_usr), s_core) iusr. + map_spmf + (\((ousr, s_usr'), s_core'). (ousr, ((s_adv, s_usr'), s_core'))) + (exec_gpv (cfunc_usr core) (cnv_usr s_usr iusr) s_core))" + +end + + +lemma + attach_core_id_oracle_adv: "cfunc_adv (attach_core 1\<^sub>I cnv core) = + (\(s_cnv, s_core) q. map_spmf (\(out, s_core'). (out, s_cnv, s_core')) (cfunc_adv core s_core q))" + by(simp add: id_oracle_def split_def map_spmf_conv_bind_spmf) + +lemma + attach_core_id_oracle_usr: "cfunc_usr (attach_core cnv 1\<^sub>I core) = + (\(s_cnv, s_core) q. map_spmf (\(out, s_core'). (out, s_cnv, s_core')) (cfunc_usr core s_core q))" + by(simp add: id_oracle_def split_def map_spmf_conv_bind_spmf) + + +context + fixes + rest1 :: "('s_rest1, 'event1, 'iadv_rest1, 'iusr_rest1, 'oadv_rest1, 'ousr_rest1, 'more1) rest_scheme" and + rest2 :: "('s_rest2, 'event2, 'iadv_rest2, 'iusr_rest2, 'oadv_rest2, 'ousr_rest2, 'more2) rest_scheme" +begin + +primcorec parallel_rest :: " + ('s_rest1 \ 's_rest2, 'event1 + 'event2, 'iadv_rest1 + 'iadv_rest2, 'iusr_rest1 + 'iusr_rest2, + 'oadv_rest1 + 'oadv_rest2, 'ousr_rest1 + 'ousr_rest2, 'more1 \ 'more2) rest_scheme" + where + "rinit parallel_rest = (rinit rest1, rinit rest2)" + | "rfunc_adv parallel_rest = parallel_eoracle (rfunc_adv rest1) (rfunc_adv rest2)" + | "rfunc_usr parallel_rest = parallel_eoracle (rfunc_usr rest1) (rfunc_usr rest2)" + +end + +lemma WT_parallel_rest [WT_intro]: + "WT_rest (\_adv1 \\<^sub>\ \_adv2) (\_usr1 \\<^sub>\ \_usr2) (pred_prod I1 I2) (parallel_rest rest1 rest2)" + if "WT_rest \_adv1 \_usr1 I1 rest1" + and "WT_rest \_adv2 \_usr2 I2 rest2" + by(rule WT_rest.intros) + (auto 4 3 simp add: parallel_eoracle_def simp add: that[THEN WT_restD_rinit] dest: that[THEN WT_restD_rfunc_adv] that[THEN WT_restD_rfunc_usr]) + +context + fixes + cnv_adv :: "'s_adv \ 'iadv \ ('oadv \ 's_adv, 'iadv_rest, 'oadv_rest) gpv" and + cnv_usr :: "'s_usr \ 'iusr \ ('ousr \ 's_usr, 'iusr_rest, 'ousr_rest) gpv" and + f_init :: "'more \ 'more'" and + rest :: "('s_rest, 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'more) rest_scheme" +begin + +primcorec + attach_rest :: " + (('s_adv \ 's_usr) \ 's_rest, 'event, 'iadv, 'iusr, 'oadv, 'ousr, 'more') rest_scheme" + where + "rinit attach_rest = f_init (rinit rest)" + | "rfunc_adv attach_rest = (\((s_adv, s_usr), s_rest) iadv. + let orc_of = \orc (s, es) q. map_spmf (\ ((out, e), s'). (out, s', es @ e)) (orc s q) in + let eorc_of = \((oadv, s_adv'), (s_rest', es)). ((oadv, es), ((s_adv', s_usr), s_rest')) in + map_spmf eorc_of (exec_gpv (orc_of (rfunc_adv rest)) (cnv_adv s_adv iadv) (s_rest, [])))" + | "rfunc_usr attach_rest = (\((s_adv, s_usr), s_rest) iusr. + let orc_of = \orc (s, es) q. map_spmf (\ ((out, e), s'). (out, s', es @ e)) (orc s q) in + let eorc_of = \((ousr, s_usr'), (s_rest', es)). ((ousr, es), ((s_adv, s_usr'), s_rest')) in + map_spmf eorc_of (exec_gpv (orc_of (rfunc_usr rest)) (cnv_usr s_usr iusr) (s_rest, [])))" + +end + + +lemma + attach_rest_id_oracle_adv: "rfunc_adv (attach_rest 1\<^sub>I cnv f_init rest) = + (\(s_cnv, s_core) q. map_spmf (\(out, s_core'). (out, s_cnv, s_core')) (rfunc_adv rest s_core q))" + by(simp add: id_oracle_def split_def map_spmf_conv_bind_spmf fun_eq_iff) + +lemma + attach_rest_id_oracle_usr: "rfunc_usr (attach_rest cnv 1\<^sub>I f_init rest) = + (\(s_cnv, s_core) q. map_spmf (\(out, s_core'). (out, s_cnv, s_core')) (rfunc_usr rest s_core q))" + by(simp add: id_oracle_def split_def map_spmf_conv_bind_spmf) + + + +section \Traces\ + +type_synonym ('event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) trace_core = + "('event + 'iadv_core \ 'oadv_core + 'iusr_core \ 'ousr_core) list + \ ('event \ real) + \ ('iadv_core \ 'oadv_core spmf) + \ ('iusr_core \ 'ousr_core spmf)" + +context + fixes core :: "('s_core, 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core" +begin + +primrec trace_core' :: "'s_core spmf \ ('event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) trace_core" where + "trace_core' S [] = + (\e. weight_spmf' (bind_spmf S (\s. cpoke core s e)), + \ia. bind_spmf S (\s. map_spmf fst (cfunc_adv core s ia)), + \iu. bind_spmf S (\s. map_spmf fst (cfunc_usr core s iu)))" +| "trace_core' S (obs # tr) = (case obs of + Inl e \ trace_core' (mk_lossless (bind_spmf S (\s. cpoke core s e))) tr + | Inr (Inl (ia, oa)) \ trace_core' (cond_spmf_fst (bind_spmf S (\s. cfunc_adv core s ia)) oa) tr + | Inr (Inr (iu, ou)) \ trace_core' (cond_spmf_fst (bind_spmf S (\s. cfunc_usr core s iu)) ou) tr + )" + +end + +declare trace_core'.simps [simp del] +case_of_simps trace_core'_unfold: trace_core'.simps[unfolded weight_spmf'_def] +simps_of_case trace_core'_simps [simp]: trace_core'_unfold + +context includes lifting_syntax begin + +lemma trace_core'_parametric [transfer_rule]: + "(rel_core' S E IA IU (=) (=) ===> + rel_spmf S ===> + list_all2 (rel_sum E (rel_sum (rel_prod IA (=)) (rel_prod IU (=)))) ===> + rel_prod (E ===> (=)) (rel_prod (IA ===> (=)) (IU ===> (=)))) + trace_core' trace_core'" + unfolding trace_core'_def by transfer_prover + +definition trace_core_eq + :: "('s_core, 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core + \ ('s_core', 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core + \ 'event set \ 'iadv_core set \ 'iusr_core set + \ 's_core spmf \ 's_core' spmf \ bool" where + "trace_core_eq core1 core2 E IA IU p q \ + (\tr. set tr \ E <+> (IA \ UNIV) <+> (IU \ UNIV) \ + rel_prod (eq_onp (\e. e \ E) ===> (=)) (rel_prod (eq_onp (\ia. ia \ IA) ===> (=)) (eq_onp (\iu. iu \ IU) ===> (=))) + (trace_core' core1 p tr) (trace_core' core2 q tr))" + +end + +lemma trace_core_eqD: + assumes "trace_core_eq core1 core2 E IA IU p q" + and "set tr \ E <+> (IA \ UNIV) <+> (IU \ UNIV)" + shows trace_core_eqD_cpoke: + "e \ E \ fst (trace_core' core1 p tr) e = fst (trace_core' core2 q tr) e" + and trace_core_eqD_cfunc_adv: + "ia \ IA \ fst (snd (trace_core' core1 p tr)) ia = fst (snd (trace_core' core2 q tr)) ia" + and trace_core_eqD_cfunc_usr: + "iu \ IU \ snd (snd (trace_core' core1 p tr)) iu = snd (snd (trace_core' core2 q tr)) iu" + using assms by(auto simp add: trace_core_eq_def rel_fun_def eq_onp_def rel_prod_sel) + +lemma trace_core_eqI: + assumes "\tr e. \ set tr \ E <+> (IA \ UNIV) <+> (IU \ UNIV); e \ E \ + \ fst (trace_core' core1 p tr) e = fst (trace_core' core2 q tr) e" + and "\tr ia. \ set tr \ E <+> (IA \ UNIV) <+> (IU \ UNIV); ia \ IA \ + \ fst (snd (trace_core' core1 p tr)) ia = fst (snd (trace_core' core2 q tr)) ia" + and "\tr iu. \ set tr \ E <+> (IA \ UNIV) <+> (IU \ UNIV); iu \ IU \ + \ snd (snd (trace_core' core1 p tr)) iu = snd (snd (trace_core' core2 q tr)) iu" + shows "trace_core_eq core1 core2 E IA IU p q" + using assms by(auto simp add: trace_core_eq_def rel_fun_def eq_onp_def rel_prod_sel) + +lemma trace_core_return_pmf_None [simp]: + "trace_core' core (return_pmf None) tr = (\_. 0, \_. return_pmf None, \_. return_pmf None)" + by(induction tr)(simp_all add: trace_core'.simps split: sum.split) + +lemma rel_core'_into_trace_core_eq: "trace_core_eq core core' E IA IU p q" + if "rel_core' S (eq_onp (\e. e \ E)) (eq_onp (\ia. ia \ IA)) (eq_onp (\iu. iu \ IU)) (=) (=) core core'" + "rel_spmf S p q" + using trace_core'_parametric[THEN rel_funD, THEN rel_funD, OF that] + unfolding trace_core_eq_def + apply(intro strip) + subgoal for tr + apply(simp add: eq_onp_True[symmetric] prod.rel_eq_onp sum.rel_eq_onp list.rel_eq_onp) + apply(auto 4 3 simp add: eq_onp_def list_all_iff dest: rel_funD[where x=tr and y=tr]) + done + done + +lemma trace_core_eq_simI: + fixes core1 :: "('s_core, 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core" + and core2 :: "('s_core', 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core" + and S :: "'s_core spmf \ 's_core' spmf \ bool" + assumes start: "S p q" + and step_cpoke: "\p q e. \ S p q; e \ E \ \ + weight_spmf (bind_spmf p (\s. cpoke core1 s e)) = weight_spmf (bind_spmf q (\s. cpoke core2 s e))" + and sim_cpoke: "\p q e. \ S p q; e \ E \ \ + S (mk_lossless (bind_spmf p (\s. cpoke core1 s e))) (mk_lossless (bind_spmf q (\s. cpoke core2 s e)))" + and step_cfunc_adv: "\p q ia. \ S p q; ia \ IA \ \ + bind_spmf p (\s1. map_spmf fst (cfunc_adv core1 s1 ia)) = bind_spmf q (\s2. map_spmf fst (cfunc_adv core2 s2 ia))" + and sim_cfunc_adv: "\p q ia s1 s2 s1' s2' oa. \ S p q; ia \ IA; + s1 \ set_spmf p; s2 \ set_spmf q; (oa, s1') \ set_spmf (cfunc_adv core1 s1 ia); (oa, s2') \ set_spmf (cfunc_adv core2 s2 ia) \ + \ S (cond_spmf_fst (bind_spmf p (\s1. cfunc_adv core1 s1 ia)) oa) (cond_spmf_fst (bind_spmf q (\s2. cfunc_adv core2 s2 ia)) oa)" + and step_cfunc_usr: "\p q iu. \ S p q; iu \ IU \ \ + bind_spmf p (\s1. map_spmf fst (cfunc_usr core1 s1 iu)) = bind_spmf q (\s2. map_spmf fst (cfunc_usr core2 s2 iu))" + and sim_cfunc_usr: "\p q iu s1 s2 s1' s2' ou. \ S p q; iu \ IU; + s1 \ set_spmf p; s2 \ set_spmf q; (ou, s1') \ set_spmf (cfunc_usr core1 s1 iu); (ou, s2') \ set_spmf (cfunc_usr core2 s2 iu) \ + \ S (cond_spmf_fst (bind_spmf p (\s1. cfunc_usr core1 s1 iu)) ou) (cond_spmf_fst (bind_spmf q (\s2. cfunc_usr core2 s2 iu)) ou)" + shows "trace_core_eq core1 core2 E IA IU p q" +proof(rule trace_core_eqI) + fix tr :: " ('event + 'iadv_core \ 'oadv_core + 'iusr_core \ 'ousr_core) list" + assume "set tr \ E <+> IA \ UNIV <+> IU \ UNIV" + then have "(\e\E. fst (trace_core' core1 p tr) e = fst (trace_core' core2 q tr) e) \ + (\ia\IA. fst (snd (trace_core' core1 p tr)) ia = fst (snd (trace_core' core2 q tr)) ia) \ + (\iu\IU. snd (snd (trace_core' core1 p tr)) iu = snd (snd (trace_core' core2 q tr)) iu)" + using start + proof(induction tr arbitrary: p q) + case Nil + then show ?case by(simp add: step_cpoke step_cfunc_adv step_cfunc_usr) + next + case (Cons a tr) + from Cons.prems(1) have tr: "set tr \ E <+> IA \ UNIV <+> IU \ UNIV" by simp + from Cons.prems(1) + consider (cpoke) e where "a = Inl e" "e \ E" + | (cfunc_adv) ia oa where "a = Inr (Inl (ia, oa))" "ia \ IA" + | (cfunc_usr) iu ou where "a = Inr (Inr (iu, ou))" "iu \ IU" by auto + then show ?case + proof cases + case cpoke + then show ?thesis using tr Cons.prems(2) by(auto simp add: sim_cpoke intro!: Cons.IH) + next + case cfunc_adv + let ?p = "bind_spmf p (\s1. cfunc_adv core1 s1 ia)" + let ?q = "bind_spmf q (\s2. cfunc_adv core2 s2 ia)" + show ?thesis + proof(cases "oa \ fst ` set_spmf ?p") + case True + with step_cfunc_adv[OF Cons.prems(2) cfunc_adv(2), THEN arg_cong[where f=set_spmf]] + have "oa \ fst ` set_spmf ?q" + unfolding set_map_spmf[symmetric] by(simp only: map_bind_spmf o_def) + then show ?thesis using True Cons.prems cfunc_adv + by(clarsimp)(rule Cons.IH; blast intro: sim_cfunc_adv) + next + case False + hence "cond_spmf_fst ?p oa = return_pmf None" by simp + moreover + from step_cfunc_adv[OF Cons.prems(2) cfunc_adv(2), THEN arg_cong[where f=set_spmf]] False + have oa': "oa \ fst ` set_spmf ?q" + unfolding set_map_spmf[symmetric] by(simp only: map_bind_spmf o_def) simp + hence "cond_spmf_fst ?q oa = return_pmf None" by simp + ultimately show ?thesis using cfunc_adv by(simp del: cond_spmf_fst_eq_return_None) + qed + next + case cfunc_usr + let ?p = "bind_spmf p (\s1. cfunc_usr core1 s1 iu)" + let ?q = "bind_spmf q (\s2. cfunc_usr core2 s2 iu)" + show ?thesis + proof(cases "ou \ fst ` set_spmf ?p") + case True + with step_cfunc_usr[OF Cons.prems(2) cfunc_usr(2), THEN arg_cong[where f=set_spmf]] + have "ou \ fst ` set_spmf ?q" + unfolding set_map_spmf[symmetric] by(simp only: map_bind_spmf o_def) + then show ?thesis using True Cons.prems cfunc_usr + by(clarsimp)(rule Cons.IH; blast intro: sim_cfunc_usr) + next + case False + hence "cond_spmf_fst ?p ou = return_pmf None" by simp + moreover + from step_cfunc_usr[OF Cons.prems(2) cfunc_usr(2), THEN arg_cong[where f=set_spmf]] False + have oa': "ou \ fst ` set_spmf ?q" + unfolding set_map_spmf[symmetric] by(simp only: map_bind_spmf o_def) simp + hence "cond_spmf_fst ?q ou = return_pmf None" by simp + ultimately show ?thesis using cfunc_usr by(simp del: cond_spmf_fst_eq_return_None) + qed + qed + qed + then show "e \ E \ fst (trace_core' core1 p tr) e = fst (trace_core' core2 q tr) e" + and "ia \ IA \ fst (snd (trace_core' core1 p tr)) ia = fst (snd (trace_core' core2 q tr)) ia" + and "iu \ IU \ snd (snd (trace_core' core1 p tr)) iu = snd (snd (trace_core' core2 q tr)) iu" + for e ia iu by blast+ +qed + +context + fixes core :: "('s_core, 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core" +begin + +fun trace_core_aux + :: "'s_core spmf \ ('event + 'iadv_core \ 'oadv_core + 'iusr_core \ 'ousr_core) list \ 's_core spmf" where + "trace_core_aux p [] = p" +| "trace_core_aux p (Inl e # tr) = trace_core_aux (mk_lossless (bind_spmf p (\s. cpoke core s e))) tr" +| "trace_core_aux p (Inr (Inl (ia, oa)) # tr) = trace_core_aux (cond_spmf_fst (bind_spmf p (\s. cfunc_adv core s ia)) oa) tr" +| "trace_core_aux p (Inr (Inr (iu, ou)) # tr) = trace_core_aux (cond_spmf_fst (bind_spmf p (\s. cfunc_usr core s iu)) ou) tr" + +end + +lemma trace_core_conv_trace_core_aux: + "trace_core' core p tr = + (\e. weight_spmf (bind_spmf (trace_core_aux core p tr) (\s. cpoke core s e)), + \ia. bind_spmf (trace_core_aux core p tr) (\s. map_spmf fst (cfunc_adv core s ia)), + \iu. bind_spmf (trace_core_aux core p tr) (\s. map_spmf fst (cfunc_usr core s iu)))" + by(induction p tr rule: trace_core_aux.induct) simp_all + +lemma trace_core_aux_append: + "trace_core_aux core p (tr @ tr') = trace_core_aux core (trace_core_aux core p tr) tr'" + by(induction p tr rule: trace_core_aux.induct) auto + +inductive trace_core_closure + :: "('s_core, 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core + \ ('s_core', 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core + \ 'event set \ 'iadv_core set \ 'iusr_core set + \ 's_core spmf \ 's_core' spmf \ 's_core spmf \ 's_core' spmf \ bool" + for core1 core2 E IA IU p q where + "trace_core_closure core1 core2 E IA IU p q (trace_core_aux core1 p tr) (trace_core_aux core2 q tr)" + if "set tr \ E <+> IA \ UNIV <+> IU \ UNIV" + +lemma trace_core_closure_start: "trace_core_closure core1 core2 E IA IU p q p q" + by(simp add: trace_core_closure.simps exI[where x="[]"]) + +lemma trace_core_closure_step: + assumes "trace_core_eq core1 core2 E IA IU p q" + and "trace_core_closure core1 core2 E IA IU p q p' q'" + shows trace_core_closure_step_cpoke: + "e \ E \ weight_spmf (bind_spmf p' (\s. cpoke core1 s e)) = weight_spmf (bind_spmf q' (\s. cpoke core2 s e))" + (is "PROP ?thesis1") + and trace_core_closure_step_cfunc_adv: + "ia \ IA \ bind_spmf p' (\s1. map_spmf fst (cfunc_adv core1 s1 ia)) = bind_spmf q' (\s2. map_spmf fst (cfunc_adv core2 s2 ia))" + (is "PROP ?thesis2") + and trace_core_closure_step_cfunc_usr: + "iu \ IU \ bind_spmf p' (\s1. map_spmf fst (cfunc_usr core1 s1 iu)) = bind_spmf q' (\s2. map_spmf fst (cfunc_usr core2 s2 iu))" + (is "PROP ?thesis3") +proof - + from assms(2) obtain tr where p: "p' = trace_core_aux core1 p tr" + and q: "q' = trace_core_aux core2 q tr" + and tr: "set tr \ E <+> IA \ UNIV <+> IU \ UNIV" by cases + from trace_core_eqD[OF assms(1) tr] p q + show "PROP ?thesis1" and "PROP ?thesis2" "PROP ?thesis3" + by(simp_all add: trace_core_conv_trace_core_aux) +qed + +lemma trace_core_closure_sim: + fixes core1 core2 E IA IU p q + defines "S \ trace_core_closure core1 core2 E IA IU p q" + assumes "S p' q'" + shows trace_core_closure_sim_cpoke: + "e \ E \ S (mk_lossless (bind_spmf p' (\s. cpoke core1 s e))) (mk_lossless (bind_spmf q' (\s. cpoke core2 s e)))" + (is "PROP ?thesis1") + and trace_core_closure_sim_cfunc_adv: "ia \ IA + \ S (cond_spmf_fst (bind_spmf p' (\s1. cfunc_adv core1 s1 ia)) oa) + (cond_spmf_fst (bind_spmf q' (\s2. cfunc_adv core2 s2 ia)) oa)" + (is "PROP ?thesis2") + and trace_core_closure_sim_cfunc_usr: "iu \ IU + \ S (cond_spmf_fst (bind_spmf p' (\s1. cfunc_usr core1 s1 iu)) ou) + (cond_spmf_fst (bind_spmf q' (\s2. cfunc_usr core2 s2 iu)) ou)" + (is "PROP ?thesis3") +proof - + from assms(2) obtain tr where p: "p' = trace_core_aux core1 p tr" + and q: "q' = trace_core_aux core2 q tr" + and tr: "set tr \ E <+> IA \ UNIV <+> IU \ UNIV" unfolding S_def by cases + show "PROP ?thesis1" using p q tr + by(auto simp add: S_def trace_core_closure.simps trace_core_aux_append intro!: exI[where x="tr @ [Inl _]"]) + show "PROP ?thesis2" using p q tr + by(auto simp add: S_def trace_core_closure.simps trace_core_aux_append intro!: exI[where x="tr @ [Inr (Inl (_, _))]"]) + show "PROP ?thesis3" using p q tr + by(auto simp add: S_def trace_core_closure.simps trace_core_aux_append intro!: exI[where x="tr @ [Inr (Inr (_, _))]"]) +qed + +proposition trace_core_eq_complete: + assumes "trace_core_eq core1 core2 E IA IU p q" + obtains S + where "S p q" + and "\p q e. \ S p q; e \ E \ \ + weight_spmf (bind_spmf p (\s. cpoke core1 s e)) = weight_spmf (bind_spmf q (\s. cpoke core2 s e))" + and "\p q e. \ S p q; e \ E \ \ + S (mk_lossless (bind_spmf p (\s. cpoke core1 s e))) (mk_lossless (bind_spmf q (\s. cpoke core2 s e)))" + and "\p q ia. \ S p q; ia \ IA \ \ + bind_spmf p (\s1. map_spmf fst (cfunc_adv core1 s1 ia)) = bind_spmf q (\s2. map_spmf fst (cfunc_adv core2 s2 ia))" + and "\p q ia oa. \ S p q; ia \ IA \ + \ S (cond_spmf_fst (bind_spmf p (\s1. cfunc_adv core1 s1 ia)) oa) (cond_spmf_fst (bind_spmf q (\s2. cfunc_adv core2 s2 ia)) oa)" + and "\p q iu. \ S p q; iu \ IU \ \ + bind_spmf p (\s1. map_spmf fst (cfunc_usr core1 s1 iu)) = bind_spmf q (\s2. map_spmf fst (cfunc_usr core2 s2 iu))" + and "\p q iu ou. \ S p q; iu \ IU \ + \ S (cond_spmf_fst (bind_spmf p (\s1. cfunc_usr core1 s1 iu)) ou) (cond_spmf_fst (bind_spmf q (\s2. cfunc_usr core2 s2 iu)) ou)" +proof - + show thesis + by(rule that[where S="trace_core_closure core1 core2 E IA IU p q"]) + (auto intro: trace_core_closure_start trace_core_closure_step[OF assms] trace_core_closure_sim (* trace_core_closure_weight[OF assms] *)) +qed + + + +type_synonym ('event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest) trace_rest = + "('iadv_rest \ 'oadv_rest \ 'event list + 'iusr_rest \ 'ousr_rest \ 'event list) list + \ ('iadv_rest \ ('oadv_rest \ 'event list) spmf) + \ ('iusr_rest \ ('ousr_rest \ 'event list) spmf)" + +context + fixes rest :: "('s_rest, 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'more) rest_scheme" +begin + +primrec trace_rest' :: "'s_rest spmf \ ('event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest) trace_rest" where + "trace_rest' S [] = + (\ia. bind_spmf S (\s. map_spmf fst (rfunc_adv rest s ia)), + \iu. bind_spmf S (\s. map_spmf fst (rfunc_usr rest s iu)))" +| "trace_rest' S (obs # tr) = (case obs of + Inl (ia, oa) \ trace_rest' (cond_spmf_fst (bind_spmf S (\s. rfunc_adv rest s ia)) oa) tr + | Inr (iu, ou) \ trace_rest' (cond_spmf_fst (bind_spmf S (\s. rfunc_usr rest s iu)) ou) tr)" + +end + +declare trace_rest'.simps [simp del] +case_of_simps trace_rest'_unfold: trace_rest'.simps +simps_of_case trace_rest'_simps [simp]: trace_rest'_unfold + +context includes lifting_syntax begin + +lemma trace_rest'_parametric [transfer_rule]: + "(rel_rest' S (=) IA IU (=) (=) M ===> rel_spmf S ===> + list_all2 (rel_sum (rel_prod IA (=)) (rel_prod IU (=))) ===> + rel_prod (IA ===> (=)) (IU ===> (=))) + trace_rest' trace_rest'" + unfolding trace_rest'_def by transfer_prover + +definition trace_rest_eq + :: "('s_rest, 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'more1) rest_scheme + \ ('s_rest', 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'more2) rest_scheme + \ 'iadv_rest set \ 'iusr_rest set + \ 's_rest spmf \ 's_rest' spmf \ bool" where + "trace_rest_eq rest1 rest2 IA IU p q \ + (\tr. set tr \ (IA \ UNIV) <+> (IU \ UNIV) \ + rel_prod (eq_onp (\ia. ia \ IA) ===> (=)) (eq_onp (\iu. iu \ IU) ===> (=)) + (trace_rest' rest1 p tr) (trace_rest' rest2 q tr))" + +end + +lemma trace_rest_eqD: + assumes "trace_rest_eq rest1 rest2 IA IU p q" + and "set tr \ (IA \ UNIV) <+> (IU \ UNIV)" + shows trace_rest_eqD_rfunc_adv: + "ia \ IA \ fst (trace_rest' rest1 p tr) ia = fst (trace_rest' rest2 q tr) ia" + and trace_rest_eqD_rfunc_usr: + "iu \ IU \ snd (trace_rest' rest1 p tr) iu = snd (trace_rest' rest2 q tr) iu" + using assms by(auto simp add: trace_rest_eq_def rel_fun_def rel_prod_sel eq_onp_def) + +lemma trace_rest_eqI: + assumes "\tr ia. \ set tr \ (IA \ UNIV) <+> (IU \ UNIV); ia \ IA \ + \ fst (trace_rest' rest1 p tr) ia = fst (trace_rest' rest2 q tr) ia" + and "\tr iu. \ set tr \ (IA \ UNIV) <+> (IU \ UNIV); iu \ IU \ + \ snd (trace_rest' rest1 p tr) iu = snd (trace_rest' rest2 q tr) iu" + shows "trace_rest_eq rest1 rest2 IA IU p q" + using assms by(auto simp add: trace_rest_eq_def rel_fun_def eq_onp_def rel_prod_sel) + +lemma trace_rest_return_pmf_None [simp]: + "trace_rest' rest (return_pmf None) tr = (\_. return_pmf None, \_. return_pmf None)" + by(induction tr)(simp_all add: trace_rest'.simps split: sum.split) + +lemma rel_rest'_into_trace_rest_eq: "trace_rest_eq rest rest' IA IU p q" + if "rel_rest' S (=) (eq_onp (\ia. ia \ IA)) (eq_onp (\iu. iu \ IU)) (=) (=) M rest rest'" + "rel_spmf S p q" + using trace_rest'_parametric[THEN rel_funD, THEN rel_funD, OF that] + unfolding trace_rest_eq_def + apply(intro strip) + subgoal for tr + apply(simp add: eq_onp_True[symmetric] prod.rel_eq_onp sum.rel_eq_onp list.rel_eq_onp) + apply(auto 4 3 simp add: eq_onp_def list_all_iff dest: rel_funD[where x=tr and y=tr]) + done + done + +lemma trace_rest_eq_simI: + fixes rest1 :: "('s_rest, 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'more) rest_scheme" + and rest2 :: "('s_rest', 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'more) rest_scheme" + and S :: "'s_rest spmf \ 's_rest' spmf \ bool" + assumes start: "S p q" + and step_rfunc_adv: "\p q ia. \ S p q; ia \ IA \ \ + bind_spmf p (\s1. map_spmf fst (rfunc_adv rest1 s1 ia)) = bind_spmf q (\s2. map_spmf fst (rfunc_adv rest2 s2 ia))" + and sim_rfunc_adv: "\p q ia s1 s2 s1' s2' oa. \ S p q; ia \ IA; + s1 \ set_spmf p; s2 \ set_spmf q; (oa, s1') \ set_spmf (rfunc_adv rest1 s1 ia); (oa, s2') \ set_spmf (rfunc_adv rest2 s2 ia) \ + \ S (cond_spmf_fst (bind_spmf p (\s1. rfunc_adv rest1 s1 ia)) oa) (cond_spmf_fst (bind_spmf q (\s2. rfunc_adv rest2 s2 ia)) oa)" + and step_rfunc_usr: "\p q iu. \ S p q; iu \ IU \ \ + bind_spmf p (\s1. map_spmf fst (rfunc_usr rest1 s1 iu)) = bind_spmf q (\s2. map_spmf fst (rfunc_usr rest2 s2 iu))" + and sim_rfunc_usr: "\p q iu s1 s2 s1' s2' ou. \ S p q; iu \ IU; + s1 \ set_spmf p; s2 \ set_spmf q; (ou, s1') \ set_spmf (rfunc_usr rest1 s1 iu); (ou, s2') \ set_spmf (rfunc_usr rest2 s2 iu) \ + \ S (cond_spmf_fst (bind_spmf p (\s1. rfunc_usr rest1 s1 iu)) ou) (cond_spmf_fst (bind_spmf q (\s2. rfunc_usr rest2 s2 iu)) ou)" + shows "trace_rest_eq rest1 rest2 IA IU p q" +proof(rule trace_rest_eqI) + fix tr :: "('iadv_rest \ 'oadv_rest \ 'event list + 'iusr_rest \ 'ousr_rest \ 'event list) list" + assume "set tr \ IA \ UNIV <+> IU \ UNIV" + then have "(\ia\IA. fst (trace_rest' rest1 p tr) ia = fst (trace_rest' rest2 q tr) ia) \ + (\iu\IU. snd (trace_rest' rest1 p tr) iu = snd (trace_rest' rest2 q tr) iu)" + using start + proof(induction tr arbitrary: p q) + case Nil + then show ?case by(simp add: step_rfunc_adv step_rfunc_usr) + next + case (Cons a tr) + from Cons.prems(1) have tr: "set tr \ IA \ UNIV <+> IU \ UNIV" by simp + from Cons.prems(1) + consider (rfunc_adv) ia oa where "a = Inl (ia, oa)" "ia \ IA" + | (rfunc_usr) iu ou where "a = Inr (iu, ou)" "iu \ IU" by auto + then show ?case + proof cases + case rfunc_adv + let ?p = "bind_spmf p (\s1. rfunc_adv rest1 s1 ia)" + let ?q = "bind_spmf q (\s2. rfunc_adv rest2 s2 ia)" + show ?thesis + proof(cases "oa \ fst ` set_spmf ?p") + case True + with step_rfunc_adv[OF Cons.prems(2) rfunc_adv(2), THEN arg_cong[where f=set_spmf]] + have "oa \ fst ` set_spmf ?q" + unfolding set_map_spmf[symmetric] by(simp only: map_bind_spmf o_def) + then show ?thesis using True Cons.prems rfunc_adv + by(clarsimp)(rule Cons.IH; blast intro: sim_rfunc_adv) + next + case False + hence "cond_spmf_fst ?p oa = return_pmf None" by simp + moreover + from step_rfunc_adv[OF Cons.prems(2) rfunc_adv(2), THEN arg_cong[where f=set_spmf]] False + have oa': "oa \ fst ` set_spmf ?q" + unfolding set_map_spmf[symmetric] by(simp only: map_bind_spmf o_def) simp + hence "cond_spmf_fst ?q oa = return_pmf None" by simp + ultimately show ?thesis using rfunc_adv by(simp del: cond_spmf_fst_eq_return_None) + qed + next + case rfunc_usr + let ?p = "bind_spmf p (\s1. rfunc_usr rest1 s1 iu)" + let ?q = "bind_spmf q (\s2. rfunc_usr rest2 s2 iu)" + show ?thesis + proof(cases "ou \ fst ` set_spmf ?p") + case True + with step_rfunc_usr[OF Cons.prems(2) rfunc_usr(2), THEN arg_cong[where f=set_spmf]] + have "ou \ fst ` set_spmf ?q" + unfolding set_map_spmf[symmetric] by(simp only: map_bind_spmf o_def) + then show ?thesis using True Cons.prems rfunc_usr + by(clarsimp)(rule Cons.IH; blast intro: sim_rfunc_usr) + next + case False + hence "cond_spmf_fst ?p ou = return_pmf None" by simp + moreover + from step_rfunc_usr[OF Cons.prems(2) rfunc_usr(2), THEN arg_cong[where f=set_spmf]] False + have oa': "ou \ fst ` set_spmf ?q" + unfolding set_map_spmf[symmetric] by(simp only: map_bind_spmf o_def) simp + hence "cond_spmf_fst ?q ou = return_pmf None" by simp + ultimately show ?thesis using rfunc_usr by(simp del: cond_spmf_fst_eq_return_None) + qed + qed + qed + then show "ia \ IA \ fst (trace_rest' rest1 p tr) ia = fst (trace_rest' rest2 q tr) ia" + and "iu \ IU \ snd (trace_rest' rest1 p tr) iu = snd (trace_rest' rest2 q tr) iu" + for ia iu by blast+ +qed + +context + fixes rest :: "('s_rest, 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'more) rest_scheme" +begin + +fun trace_rest_aux + :: "'s_rest spmf \ ('iadv_rest \ 'oadv_rest \ 'event list + 'iusr_rest \ 'ousr_rest \ 'event list) list \ 's_rest spmf" where + "trace_rest_aux p [] = p" +| "trace_rest_aux p (Inl (ia, oaes) # tr) = trace_rest_aux (cond_spmf_fst (bind_spmf p (\s. rfunc_adv rest s ia)) oaes) tr" +| "trace_rest_aux p (Inr (iu, oues) # tr) = trace_rest_aux (cond_spmf_fst (bind_spmf p (\s. rfunc_usr rest s iu)) oues) tr" + +end + +lemma trace_rest_conv_trace_rest_aux: + "trace_rest' rest p tr = + (\ia. bind_spmf (trace_rest_aux rest p tr) (\s. map_spmf fst (rfunc_adv rest s ia)), + \iu. bind_spmf (trace_rest_aux rest p tr) (\s. map_spmf fst (rfunc_usr rest s iu)))" + by(induction p tr rule: trace_rest_aux.induct) simp_all + +lemma trace_rest_aux_append: + "trace_rest_aux rest p (tr @ tr') = trace_rest_aux rest (trace_rest_aux rest p tr) tr'" + by(induction p tr rule: trace_rest_aux.induct) auto + +inductive trace_rest_closure + :: "('s_rest, 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'more) rest_scheme + \ ('s_rest', 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'more') rest_scheme + \ 'iadv_rest set \ 'iusr_rest set + \ 's_rest spmf \ 's_rest' spmf \ 's_rest spmf \ 's_rest' spmf \ bool" + for rest1 rest2 IA IU p q where + "trace_rest_closure rest1 rest2 IA IU p q (trace_rest_aux rest1 p tr) (trace_rest_aux rest2 q tr)" + if "set tr \ IA \ UNIV <+> IU \ UNIV" + +lemma trace_rest_closure_start: "trace_rest_closure rest1 rest2 IA IU p q p q" + by(simp add: trace_rest_closure.simps exI[where x="[]"]) + +lemma trace_rest_closure_step: + assumes "trace_rest_eq rest1 rest2 IA IU p q" + and "trace_rest_closure rest1 rest2 IA IU p q p' q'" + shows trace_rest_closure_step_rfunc_adv: + "ia \ IA \ bind_spmf p' (\s1. map_spmf fst (rfunc_adv rest1 s1 ia)) = bind_spmf q' (\s2. map_spmf fst (rfunc_adv rest2 s2 ia))" + (is "PROP ?thesis1") + and trace_rest_closure_step_rfunc_usr: + "iu \ IU \ bind_spmf p' (\s1. map_spmf fst (rfunc_usr rest1 s1 iu)) = bind_spmf q' (\s2. map_spmf fst (rfunc_usr rest2 s2 iu))" + (is "PROP ?thesis2") +proof - + from assms(2) obtain tr where p: "p' = trace_rest_aux rest1 p tr" + and q: "q' = trace_rest_aux rest2 q tr" + and tr: "set tr \ IA \ UNIV <+> IU \ UNIV" by cases + from trace_rest_eqD[OF assms(1) tr] p q + show "PROP ?thesis1" and "PROP ?thesis2" + by(simp_all add: trace_rest_conv_trace_rest_aux) +qed + +lemma trace_rest_closure_sim: + fixes rest1 rest2 IA IU p q + defines "S \ trace_rest_closure rest1 rest2 IA IU p q" + assumes "S p' q'" + shows trace_rest_closure_sim_rfunc_adv: "ia \ IA + \ S (cond_spmf_fst (bind_spmf p' (\s1. rfunc_adv rest1 s1 ia)) oa) + (cond_spmf_fst (bind_spmf q' (\s2. rfunc_adv rest2 s2 ia)) oa)" + (is "PROP ?thesis1") + and trace_rest_closure_sim_rfunc_usr: "iu \ IU + \ S (cond_spmf_fst (bind_spmf p' (\s1. rfunc_usr rest1 s1 iu)) ou) + (cond_spmf_fst (bind_spmf q' (\s2. rfunc_usr rest2 s2 iu)) ou)" + (is "PROP ?thesis2") +proof - + from assms(2) obtain tr where p: "p' = trace_rest_aux rest1 p tr" + and q: "q' = trace_rest_aux rest2 q tr" + and tr: "set tr \ IA \ UNIV <+> IU \ UNIV" unfolding S_def by cases + show "PROP ?thesis1" using p q tr + by(auto simp add: S_def trace_rest_closure.simps trace_rest_aux_append intro!: exI[where x="tr @ [Inl (_, _)]"]) + show "PROP ?thesis2" using p q tr + by(auto simp add: S_def trace_rest_closure.simps trace_rest_aux_append intro!: exI[where x="tr @ [Inr (_, _)]"]) +qed + +proposition trace_rest_eq_complete: + assumes "trace_rest_eq rest1 rest2 IA IU p q" + obtains S + where "S p q" + and "\p q ia. \ S p q; ia \ IA \ \ + bind_spmf p (\s1. map_spmf fst (rfunc_adv rest1 s1 ia)) = bind_spmf q (\s2. map_spmf fst (rfunc_adv rest2 s2 ia))" + and "\p q ia oa. \ S p q; ia \ IA \ + \ S (cond_spmf_fst (bind_spmf p (\s1. rfunc_adv rest1 s1 ia)) oa) (cond_spmf_fst (bind_spmf q (\s2. rfunc_adv rest2 s2 ia)) oa)" + and "\p q iu. \ S p q; iu \ IU \ \ + bind_spmf p (\s1. map_spmf fst (rfunc_usr rest1 s1 iu)) = bind_spmf q (\s2. map_spmf fst (rfunc_usr rest2 s2 iu))" + and "\p q iu ou. \ S p q; iu \ IU \ + \ S (cond_spmf_fst (bind_spmf p (\s1. rfunc_usr rest1 s1 iu)) ou) (cond_spmf_fst (bind_spmf q (\s2. rfunc_usr rest2 s2 iu)) ou)" +proof - + show thesis + by(rule that[where S="trace_rest_closure rest1 rest2 IA IU p q"]) + (auto intro: trace_rest_closure_start trace_rest_closure_step[OF assms] trace_rest_closure_sim (* trace_rest_closure_weight[OF assms] *)) +qed + +definition callee_of_core + :: "('s_core, 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core + \ ('s_core, 'event + 'iadv_core + 'iusr_core, unit + 'oadv_core + 'ousr_core) oracle'" where + "callee_of_core core = + map_fun id (map_fun id (map_spmf (Pair ()))) (cpoke core) \\<^sub>O cfunc_adv core \\<^sub>O cfunc_usr core" + +lemma callee_of_core_simps [simp]: + "callee_of_core core s (Inl e) = map_spmf (Pair (Inl ())) (cpoke core s e)" + "callee_of_core core s (Inr (Inl iadv_core)) = map_spmf (apfst (Inr \ Inl)) (cfunc_adv core s iadv_core)" + "callee_of_core core s (Inr (Inr iusr_core)) = map_spmf (apfst (Inr \ Inr)) (cfunc_usr core s iusr_core)" + by(simp_all add: callee_of_core_def spmf.map_comp o_def apfst_def prod.map_comp id_def) + +lemma WT_callee_of_core [WT_intro]: + assumes WT: "WT_core \_adv \_usr I core" + and I: "I s" + shows "\_full \\<^sub>\ (\_adv \\<^sub>\ \_usr) \c callee_of_core core s \" + apply(rule WT_calleeI) + subgoal for x y s' using I WT_coreD[OF WT] + by(auto simp add: callee_of_core_def plus_oracle_def split!: sum.splits) + done + +lemma WT_core_callee_invariant_on [WT_intro]: + assumes WT: "WT_core \_adv \_usr I core" + shows "callee_invariant_on (callee_of_core core) I (\_full \\<^sub>\ (\_adv \\<^sub>\ \_usr))" + apply unfold_locales + subgoal for s x y s' by(auto simp add: callee_of_core_def plus_oracle_def split!: sum.splits dest: WT_coreD[OF assms]) + subgoal by(rule WT_callee_of_core[OF WT]) + done + +definition callee_of_rest + :: "('s_rest, 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'more) rest_scheme + \ ('s_rest, 'iadv_rest + 'iusr_rest, 'oadv_rest \ 'event list + 'ousr_rest \ 'event list) oracle'" where + "callee_of_rest rest = rfunc_adv rest \\<^sub>O rfunc_usr rest" + +lemma callee_of_rest_simps [simp]: + "callee_of_rest rest s (Inl iadv_rest) = map_spmf (apfst Inl) (rfunc_adv rest s iadv_rest)" + "callee_of_rest rest s (Inr iusr_rest) = map_spmf (apfst Inr) (rfunc_usr rest s iusr_rest)" + by(simp_all add: callee_of_rest_def) + +lemma WT_callee_of_rest [WT_intro]: + assumes WT: "WT_rest \_adv \_usr I rest" + and I: "I s" + shows "e\ \_adv \\<^sub>\ e\ \_usr \c callee_of_rest rest s \" + apply(rule WT_calleeI) + subgoal for x y s' using I WT_restD[OF WT] + by(auto simp add: callee_of_core_def plus_oracle_def split!: sum.splits) + done + +fun fuse_callee + :: "('iadv_core + 'iadv_rest) + ('iusr_core + 'iusr_rest) \ + (('oadv_core + 'oadv_rest) + ('ousr_core + 'ousr_rest), + ('event + 'iadv_core + 'iusr_core) + ('iadv_rest + 'iusr_rest), + (unit + 'oadv_core + 'ousr_core) + ('oadv_rest \ 'event list + 'ousr_rest \ 'event list)) gpv" + where + "fuse_callee (Inl (Inl iadv_core)) = Pause (Inl (Inr (Inl iadv_core))) (\x. case x of + Inl (Inr (Inl oadv_core)) \ Done (Inl (Inl oadv_core)) + | _ \ Fail)" +| "fuse_callee (Inl (Inr iadv_rest)) = Pause (Inr (Inl iadv_rest)) (\x. case x of + Inr (Inl (oadv_rest, es)) \ bind_gpv (pauses (map (Inl \ Inl) es)) (\_. Done (Inl (Inr oadv_rest))) + | _ \ Fail)" +| "fuse_callee (Inr (Inl iusr_core)) = Pause (Inl (Inr (Inr iusr_core))) (\x. case x of + Inl (Inr (Inr oadv_core)) \ Done (Inr (Inl oadv_core)))" +| "fuse_callee (Inr (Inr iusr_rest)) = Pause (Inr (Inr iusr_rest)) (\x. case x of + Inr (Inr (ousr_rest, es)) \ bind_gpv (pauses (map (Inl \ Inl) es)) (\_. Done (Inr (Inr ousr_rest))))" + +case_of_simps fuse_callee_case: fuse_callee.simps + +(* parametric_constant fuse_callee_parametric [transfer_rule]: fuse_callee_case *) + +definition fuse_converter + :: "(('iadv_core + 'iadv_rest) + ('iusr_core + 'iusr_rest), + ('oadv_core + 'oadv_rest) + ('ousr_core + 'ousr_rest), + ('event + 'iadv_core + 'iusr_core) + ('iadv_rest + 'iusr_rest), + (unit + 'oadv_core + 'ousr_core) + ('oadv_rest \ 'event list + 'ousr_rest \ 'event list)) converter" + where + "fuse_converter = converter_of_callee (stateless_callee fuse_callee) ()" + +lemma fuse_converter: + "resource_of_oracle (fused_resource.fuse core rest) (s_core, s_rest) = + fuse_converter \ (resource_of_oracle (callee_of_core core) s_core \ resource_of_oracle (callee_of_rest rest) s_rest)" + unfolding fuse_converter_def resource_of_parallel_oracle[symmetric] attach_CNV_RES attach_stateless_callee resource_of_oracle_extend_state_oracle +proof(rule arg_cong2[where f=resource_of_oracle]; clarsimp simp add: fun_eq_iff) + interpret fused_resource core core_init for core_init . + have "foldl_spmf (map_fun id (map_fun (Inl \ Inl) id) (map_fun id (map_fun id (map_spmf snd)) (callee_of_core core \\<^sub>O callee_of_rest rest))) (return_spmf (s_core, s_rest)) xs + = map_spmf (\s_core. (s_core, s_rest)) (foldl_spmf (cpoke core) (return_spmf s_core) xs)" for s_core s_rest xs + by(induction xs arbitrary: s_core) + (simp_all add: spmf.map_comp foldl_spmf_Cons' map_bind_spmf bind_map_spmf o_def del: foldl_spmf_Cons) + then show "fuse rest (s_core, s_rest) q = exec_gpv (callee_of_core core \\<^sub>O callee_of_rest rest) (fuse_callee q) (s_core, s_rest)" + for s_core s_rest q + by(cases q rule: fuse_callee.cases; clarsimp simp add: map_bind_spmf bind_map_spmf exec_gpv_bind exec_gpv_pauses intro!: bind_spmf_cong[OF refl]; simp add: map_spmf_conv_bind_spmf[symmetric]) +qed + +lemma trace_eq_callee_of_coreI: + "trace_callee_eq (callee_of_core core1) (callee_of_core core2) (E <+> IA <+> IU) p q" + if "trace_core_eq core1 core2 E IA IU p q" +proof - + from that obtain S_core + where core_start: "S_core p q" + and step_cpoke: "\p q e. S_core p q \ e \ E + \ weight_spmf (bind_spmf p (\s. cpoke core1 s e)) = weight_spmf (bind_spmf q (\s. cpoke core2 s e))" + and sim_cpoke: "\p q e. S_core p q \ e \ E + \ S_core (mk_lossless (bind_spmf p (\s. cpoke core1 s e))) (mk_lossless (bind_spmf q (\s. cpoke core2 s e)))" + and step_cfunc_adv: "\p q ia. \ S_core p q; ia \ IA \ + \ bind_spmf p (\s1. map_spmf fst (cfunc_adv core1 s1 ia)) = bind_spmf q (\s2. map_spmf fst (cfunc_adv core2 s2 ia))" + and sim_cfunc_adv: "\p q ia oa. \ S_core p q; ia \ IA \ \ + S_core (cond_spmf_fst (bind_spmf p (\s1. cfunc_adv core1 s1 ia)) oa) + (cond_spmf_fst (bind_spmf q (\s2. cfunc_adv core2 s2 ia)) oa)" + and step_cfunc_usr: "\p q iu. \ S_core p q; iu \ IU \ + \ bind_spmf p (\s1. map_spmf fst (cfunc_usr core1 s1 iu)) = bind_spmf q (\s2. map_spmf fst (cfunc_usr core2 s2 iu))" + and sim_cfunc_usr: "\p q iu ou. \ S_core p q; iu \ IU \ \ + S_core (cond_spmf_fst (bind_spmf p (\s1. cfunc_usr core1 s1 iu)) ou) + (cond_spmf_fst (bind_spmf q (\s2. cfunc_usr core2 s2 iu)) ou)" + by(rule trace_core_eq_complete) blast + + show ?thesis using core_start + proof(coinduct rule: trace'_eqI_sim[consumes 1, case_names step sim]) + case (step p q a) + then consider (cpoke) e where "a = Inl e" "e \ E" + | (cfunc_adv) ia where "a = Inr (Inl ia)" "ia \ IA" + | (cfunc_usr) iu where "a = Inr (Inr iu)" "iu \ IU" by auto + then show ?case + proof cases + case cpoke + with step_cpoke[OF step(1), of e] show ?thesis + by(simp add: spmf.map_comp o_def map_spmf_const weight_bind_spmf) + (auto intro!: spmf_eqI simp add: spmf_bind spmf_scale_spmf max_def min_absorb2 weight_spmf_le_1) + next + case cfunc_adv + with step_cfunc_adv[OF step(1) cfunc_adv(2)] show ?thesis + by(simp add: spmf.map_comp)(simp add: spmf.map_comp[symmetric] map_bind_spmf[unfolded o_def, symmetric]) + next + case cfunc_usr + with step_cfunc_usr[OF step(1) cfunc_usr(2)] show ?thesis + by(simp add: spmf.map_comp)(simp add: spmf.map_comp[symmetric] map_bind_spmf[unfolded o_def, symmetric]) + qed + next + case (sim p q a res b s') + then consider (cpoke) e where "a = Inl e" "e \ E" + | (cfunc_adv) ia where "a = Inr (Inl ia)" "ia \ IA" + | (cfunc_usr) iu where "a = Inr (Inr iu)" "iu \ IU" by auto + then show ?case + proof cases + case cpoke + with sim_cpoke[OF sim(1) , of e] sim show ?thesis + by(clarsimp simp add: map_bind_spmf[unfolded o_def, symmetric]) + next + case cfunc_adv + with sim_cfunc_adv[OF sim(1) cfunc_adv(2)] sim show ?thesis + apply(clarsimp simp add: map_bind_spmf[unfolded o_def, symmetric] apfst_def map_prod_def) + apply(subst (1 2) cond_spmf_fst_map_prod_inj) + apply(simp_all add: o_def[symmetric] inj_compose del: o_apply) + done + next + case cfunc_usr + with sim_cfunc_usr[OF sim(1) cfunc_usr(2)] sim show ?thesis + apply(clarsimp simp add: map_bind_spmf[unfolded o_def, symmetric] apfst_def map_prod_def) + apply(subst (1 2) cond_spmf_fst_map_prod_inj) + apply(simp_all add: o_def[symmetric] inj_compose del: o_apply) + done + qed + qed +qed + +lemma trace_eq_callee_of_restI: + "trace_callee_eq (callee_of_rest rest1) (callee_of_rest rest2) (IA <+> IU) p q" + if "trace_rest_eq rest1 rest2 IA IU p q" +proof - + from that obtain S_rest + where rest_start: "S_rest p q" + and step_rfunc_adv: "\p q ia. \ S_rest p q; ia \ IA \ + \ bind_spmf p (\s1. map_spmf fst (rfunc_adv rest1 s1 ia)) = bind_spmf q (\s2. map_spmf fst (rfunc_adv rest2 s2 ia))" + and sim_rfunc_adv: "\p q ia oa. \ S_rest p q; ia \ IA \ \ + S_rest (cond_spmf_fst (bind_spmf p (\s1. rfunc_adv rest1 s1 ia)) oa) + (cond_spmf_fst (bind_spmf q (\s2. rfunc_adv rest2 s2 ia)) oa)" + and step_rfunc_usr: "\p q iu. \ S_rest p q; iu \ IU \ + \ bind_spmf p (\s1. map_spmf fst (rfunc_usr rest1 s1 iu)) = bind_spmf q (\s2. map_spmf fst (rfunc_usr rest2 s2 iu))" + and sim_rfunc_usr: "\p q iu ou. \ S_rest p q; iu \ IU \ \ + S_rest (cond_spmf_fst (bind_spmf p (\s1. rfunc_usr rest1 s1 iu)) ou) + (cond_spmf_fst (bind_spmf q (\s2. rfunc_usr rest2 s2 iu)) ou)" + by(rule trace_rest_eq_complete) blast + + show ?thesis using rest_start + proof(coinduct rule: trace'_eqI_sim[consumes 1, case_names step sim]) + case (step p q a) + then consider (rfunc_adv) ia where "a = Inl ia" "ia \ IA" + | (rfunc_usr) iu where "a = Inr iu" "iu \ IU" by auto + then show ?case + proof cases + case rfunc_adv + with step_rfunc_adv[OF step(1) rfunc_adv(2)] show ?thesis + by(simp add: spmf.map_comp)(simp add: spmf.map_comp[symmetric] map_bind_spmf[unfolded o_def, symmetric]) + next + case rfunc_usr + with step_rfunc_usr[OF step(1) rfunc_usr(2)] show ?thesis + by(simp add: spmf.map_comp)(simp add: spmf.map_comp[symmetric] map_bind_spmf[unfolded o_def, symmetric]) + qed + next + case (sim p q a res b s') + then consider (rfunc_adv) ia where "a = Inl ia" "ia \ IA" + | (rfunc_usr) iu where "a = Inr iu" "iu \ IU" by auto + then show ?case + proof cases + case rfunc_adv + with sim_rfunc_adv[OF sim(1) rfunc_adv(2)] sim show ?thesis + by(clarsimp simp add: map_bind_spmf[unfolded o_def, symmetric] apfst_def map_prod_def) + (subst (1 2) cond_spmf_fst_map_prod_inj; simp) + next + case rfunc_usr + with sim_rfunc_usr[OF sim(1) rfunc_usr(2)] sim show ?thesis + by(clarsimp simp add: map_bind_spmf[unfolded o_def, symmetric] apfst_def map_prod_def) + (subst (1 2) cond_spmf_fst_map_prod_inj; simp) + qed + qed +qed + +lemma trace_callee_resource_of_oracle: + "trace_callee run_resource (map_spmf (resource_of_oracle callee) p) = trace_callee callee p" + (is "?lhs = ?rhs") +proof(intro ext) + show "?lhs tr x = ?rhs tr x" for tr x + proof(induction tr arbitrary: p) + case Nil show ?case by(simp add: bind_map_spmf o_def spmf.map_comp) + next + case (Cons a tr) + obtain y z where a [simp]: "a = (y, z)" by(cases a) + have "trace_callee run_resource (map_spmf (RES callee) p) (a # tr) x = + trace_callee run_resource (cond_spmf_fst (map_spmf (\(x, y). (x, RES callee y)) (p \ (\x. (callee x y)))) z) tr x" + by(clarsimp simp add: bind_map_spmf o_def map_prod_def map_bind_spmf) + also have "\ = trace_callee run_resource (map_spmf (RES callee) (cond_spmf_fst (p \ (\x. (callee x y))) z)) tr x" + by(subst cond_spmf_fst_map_prod_inj) simp_all + finally show ?case using Cons.IH by simp + qed +qed + +lemma trace_callee_resource_of_oracle': + "trace_callee run_resource (return_spmf (resource_of_oracle callee s)) = trace_callee callee (return_spmf s)" + using trace_callee_resource_of_oracle[where p="return_spmf s"] + by simp + +lemma trace_eq_resource_of_oracle: + "trace_eq A (map_spmf (resource_of_oracle callee1) p) (map_spmf (resource_of_oracle callee2) q) = + trace_callee_eq callee1 callee2 A p q" + unfolding trace_callee_eq_def trace_callee_resource_of_oracle by(rule refl) + +lemma WT_fuse_converter [WT_intro]: + "(\AC \\<^sub>\ map_\ id fst \AR) \\<^sub>\ (\UC \\<^sub>\ map_\ id fst \UR), (\E \\<^sub>\ (\AC \\<^sub>\ \UC)) \\<^sub>\ (\AR \\<^sub>\ \UR) \\<^sub>C fuse_converter \" + if "\x. \(y, es)\responses_\ \AR x. set es \ outs_\ \E" "\x. \(y, es)\responses_\ \UR x. set es \ outs_\ \E" + unfolding fuse_converter_def using that + by(intro WT_converter_of_callee) + (fastforce simp add: stateless_callee_def image_image intro: rev_image_eqI intro!: WT_gpv_pauses split: if_split_asm)+ + +theorem fuse_trace_eq: + fixes core1 :: "('s_core, 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core" + and core2 :: "('s_core', 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core" + and rest1 :: "('s_rest, 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'more1) rest_scheme" + and rest2 :: "('s_rest', 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'more2) rest_scheme" + assumes core: "trace_core_eq core1 core2 (outs_\ \E) (outs_\ \CA) (outs_\ \CU) (return_spmf s_core) (return_spmf s_core')" + and rest: "trace_rest_eq rest1 rest2 (outs_\ \RA) (outs_\ \RU) (return_spmf s_rest) (return_spmf s_rest')" + and IC1: "callee_invariant_on (callee_of_core core1) IC1 (\E \\<^sub>\ (\CA \\<^sub>\ \CU))" "IC1 s_core" + and IC2: "callee_invariant_on (callee_of_core core2) IC2 (\E \\<^sub>\ (\CA \\<^sub>\ \CU))" "IC2 s_core'" + and IR1: "callee_invariant_on (callee_of_rest rest1) IR1 (\RA \\<^sub>\ \RU)" "IR1 s_rest" + and IR2: "callee_invariant_on (callee_of_rest rest2) IR2 (\RA \\<^sub>\ \RU)" "IR2 s_rest'" + and E1 [WT_intro]: "\x. \(y, es)\responses_\ \RA x. set es \ outs_\ \E" + and E2 [WT_intro]: "\x. \(y, es)\responses_\ \RU x. set es \ outs_\ \E" + shows "trace_callee_eq (fused_resource.fuse core1 rest1) (fused_resource.fuse core2 rest2) + ((outs_\ \CA <+> outs_\ \RA) <+> (outs_\ \CU <+> outs_\ \RU)) (return_spmf (s_core, s_rest)) (return_spmf (s_core', s_rest'))" +proof - + let ?\C = "\E \\<^sub>\ (\CA \\<^sub>\ \CU)" + let ?\R = "\RA \\<^sub>\ \RU" + let ?\' = "?\C \\<^sub>\ ?\R" + let ?\ = "(\CA \\<^sub>\ map_\ id fst \RA) \\<^sub>\ (\CU \\<^sub>\ map_\ id fst \RU)" + + interpret fuse1: fused_resource core1 s1 for s1 . + interpret fuse2: fused_resource core2 s2 for s2 . + interpret IC1: callee_invariant_on "callee_of_core core1" IC1 ?\C by fact + interpret IC2: callee_invariant_on "callee_of_core core2" IC2 ?\C by fact + interpret IR1: callee_invariant_on "callee_of_rest rest1" IR1 ?\R by fact + interpret IR2: callee_invariant_on "callee_of_rest rest2" IR2 ?\R by fact + + from core have "outs_\ ?\C \\<^sub>C callee_of_core core1(s_core) \ callee_of_core core2(s_core')" + by(simp add: trace_eq_callee_of_coreI) + hence "outs_\ ?\C \\<^sub>R RES (callee_of_core core1) s_core \ RES (callee_of_core core2) s_core'" by simp + moreover have "outs_\ ?\R \\<^sub>C callee_of_rest rest1(s_rest) \ callee_of_rest rest2(s_rest')" using rest + by(simp add: trace_eq_callee_of_restI) + hence "outs_\ ?\R \\<^sub>R RES (callee_of_rest rest1) s_rest \ RES (callee_of_rest rest2) s_rest'" by simp + ultimately have "outs_\ ?\' \\<^sub>R + RES (callee_of_core core1) s_core \ RES (callee_of_rest rest1) s_rest \ + RES (callee_of_core core2) s_core' \ RES (callee_of_rest rest2) s_rest'" + by(simp add: trace_eq'_parallel_resource) + hence "outs_\ ?\ \\<^sub>R fuse_converter \ (RES (callee_of_core core1) s_core \ RES (callee_of_rest rest1) s_rest) \ + fuse_converter \ (RES (callee_of_core core2) s_core' \ RES (callee_of_rest rest2) s_rest')" + by(rule attach_trace_eq')(intro WT_intro IC1.WT_resource_of_oracle IC1 IC2.WT_resource_of_oracle IC2 IR1.WT_resource_of_oracle IR1 IR2.WT_resource_of_oracle IR2)+ + hence "trace_eq' (outs_\ ?\) (resource_of_oracle (fuse1.fuse rest1) (s_core, s_rest)) (resource_of_oracle (fuse2.fuse rest2) (s_core', s_rest'))" + unfolding fuse_converter by simp + then show ?thesis by simp +qed + + +inductive trace_eq_simcl :: "('s1 spmf \ 's2 spmf \ bool) \ 's1 spmf \ 's2 spmf \ bool" + for S where + base: "trace_eq_simcl S p q" if "S p q" for p q +| bind_nat: "trace_eq_simcl S (bind_spmf p f) (bind_spmf p g)" +if "\x :: nat. x \ set_spmf p \ S (f x) (g x)" + +lemma trace_eq_simcl_bindI [intro?]: "trace_eq_simcl S (bind_spmf p f) (bind_spmf p g)" + if "\x. x \ set_spmf p \ S (f x) (g x)" + by(subst (1 2) bind_spmf_to_nat_on[symmetric])(auto intro!: trace_eq_simcl.bind_nat simp add: that) + +lemma trace_eq_simcl_bind: "trace_eq_simcl S (bind_spmf p f) (bind_spmf p g)" + if *: "\x :: 'a. x \ set_spmf p \ trace_eq_simcl S (f x) (g x)" +proof - + obtain P :: "'a \ nat spmf" and F G where + **: "\x. x \ set_spmf p \ f x = bind_spmf (P x) (F x) \ g x = bind_spmf (P x) (G x) \ (\y\set_spmf (P x). S (F x y) (G x y))" + apply(atomize_elim) + apply(subst choice_iff[symmetric])+ + apply(fastforce dest!: * elim!: trace_eq_simcl.cases intro: exI[where x="return_spmf _"]) + done + have "bind_spmf p f = bind_spmf (bind_spmf p (\x. map_spmf (Pair x) (P x))) (\(x, y). F x y)" + by(simp add: bind_map_spmf o_def ** cong: bind_spmf_cong) + moreover have "bind_spmf p g = bind_spmf (bind_spmf p (\x. map_spmf (Pair x) (P x))) (\(x, y). G x y)" + by(simp add: bind_map_spmf o_def ** cong: bind_spmf_cong) + ultimately show ?thesis by(simp only:)(rule trace_eq_simcl_bindI; clarsimp simp add: **) +qed + +lemma trace_eq_simcl_bind1_scale: "trace_eq_simcl S (bind_spmf p f) (scale_spmf (weight_spmf p) q)" + if "\x\set_spmf p. trace_eq_simcl S (f x) q" +proof - + have "trace_eq_simcl S (bind_spmf p f) (bind_spmf p (\_. q))" + by(rule trace_eq_simcl_bind)(simp add: that) + thus ?thesis by(simp add: bind_spmf_const) +qed + +lemma trace_eq_simcl_bind1: "trace_eq_simcl S (bind_spmf p f) q" + if "\x\set_spmf p. trace_eq_simcl S (f x) q" "lossless_spmf p" + using trace_eq_simcl_bind1_scale[OF that(1)] that(2) by(simp add: lossless_weight_spmfD) + +lemma trace_eq_simcl_bind2_scale: "trace_eq_simcl S (scale_spmf (weight_spmf q) p) (bind_spmf q f)" + if "\x\set_spmf q. trace_eq_simcl S p (f x)" +proof - + have "trace_eq_simcl S (bind_spmf q (\_. p)) (bind_spmf q f)" + by(rule trace_eq_simcl_bind)(simp add: that) + thus ?thesis by(simp add: bind_spmf_const) +qed + +lemma trace_eq_simcl_bind2: "trace_eq_simcl S p (bind_spmf q f)" + if "\x\set_spmf q. trace_eq_simcl S p (f x)" "lossless_spmf q" + using trace_eq_simcl_bind2_scale[OF that(1)] that(2) by(simp add: lossless_weight_spmfD) + +lemma trace_eq_simcl_return_pmf_None [simp, intro!]: "trace_eq_simcl S (return_pmf None) (return_pmf None)" + for S :: "'s1 spmf \ 's2 spmf \ bool" +proof - + have "trace_eq_simcl S (bind_spmf (return_pmf None) (undefined :: nat \ 's1 spmf)) (bind_spmf (return_pmf None) (undefined :: nat \ 's2 spmf))" + by(rule trace_eq_simcl_bindI) simp + then show ?thesis by simp +qed + +lemma trace_eq_simcl_map: "trace_eq_simcl S (map_spmf f p) (map_spmf g p)" + if "\x\set_spmf p. S (return_spmf (f x)) (return_spmf (g x))" + unfolding map_spmf_conv_bind_spmf + by(rule trace_eq_simcl_bindI)(simp add: that) + +lemma trace_eq_simcl_map1: "trace_eq_simcl S (map_spmf f p) q" + if "\x\set_spmf p. trace_eq_simcl S (return_spmf (f x)) q" "lossless_spmf p" + unfolding map_spmf_conv_bind_spmf + by(rule trace_eq_simcl_bind1)(simp_all add: that) + +lemma trace_eq_simcl_map2: "trace_eq_simcl S p (map_spmf f q)" + if "\x\set_spmf q. trace_eq_simcl S p (return_spmf (f x))" "lossless_spmf q" + unfolding map_spmf_conv_bind_spmf + by(rule trace_eq_simcl_bind2)(simp_all add: that) + +lemma trace_eq_simcl_return_spmf [simp]: "trace_eq_simcl S (return_spmf x) (return_spmf y) \ S (return_spmf x) (return_spmf y)" + apply(rule iffI) + subgoal by(erule trace_eq_simcl.cases; clarsimp dest!: sym[where s="return_spmf _"])(auto 4 4 simp add: bind_eq_return_spmf dest!: lossless_spmfD_set_spmf_nonempty) + by(simp add: trace_eq_simcl.base) + +lemma trace_eq_simcl_callee: + fixes callee1 :: "('a, 'b, 's1) callee" and callee2 :: "('a, 'b, 's2) callee" + assumes step: "\p q a. \ S p q; a \ A \ \ + bind_spmf p (\s. map_spmf fst (callee1 s a)) = bind_spmf q (\s. map_spmf fst (callee2 s a))" + and sim: "\p q a res b s'. \ S p q; a \ A; res \ set_spmf q; (b, s') \ set_spmf (callee2 res a) \ + \ trace_eq_simcl S (cond_spmf_fst (bind_spmf p (\s. callee1 s a)) b) + (cond_spmf_fst (bind_spmf q (\s. callee2 s a)) b)" + and start: "trace_eq_simcl S p q" and a: "a \ A" + shows trace_eq_simcl_callee_step: "bind_spmf p (\s. map_spmf fst (callee1 s a)) = bind_spmf q (\s. map_spmf fst (callee2 s a))" (is "?step") + and trace_eq_simcl_callee_sim: "\res b s'. \ res \ set_spmf q; (b, s') \ set_spmf (callee2 res a) \ + \ trace_eq_simcl S (cond_spmf_fst (bind_spmf p (\s. callee1 s a)) b) + (cond_spmf_fst (bind_spmf q (\s. callee2 s a)) b)" (is "\res b s'. \ ?res res; ?b res b s' \ \ ?sim res b s'") +proof - + show eq: ?step using start a by cases(auto intro!: bind_spmf_cong intro: step) + show "?sim res b s'" if "?res res" "?b res b s'" for res b s' using start + proof cases + case base then show ?thesis using a that by(rule sim) + next + case (bind_nat X f g) + let ?Y = "cond_bind_spmf_fst X (\y. map_spmf fst (bind_spmf (f y) (\s. callee1 s a))) b" + let ?Y' = "cond_bind_spmf_fst X (\y. map_spmf fst (bind_spmf (g y) (\s. callee2 s a))) b" + have "cond_spmf_fst (bind_spmf p (\s. callee1 s a)) b = bind_spmf ?Y (\x. cond_spmf_fst (bind_spmf (f x) (\s. callee1 s a)) b)" + unfolding bind_nat by(simp add: cond_spmf_fst_bind o_def) + moreover have "cond_spmf_fst (bind_spmf q (\s. callee2 s a)) b = bind_spmf ?Y' (\x. cond_spmf_fst (bind_spmf (g x) (\s. callee2 s a)) b)" + unfolding bind_nat by(simp add: cond_spmf_fst_bind o_def) + moreover have "?Y = ?Y'" using bind_nat eq + by(intro spmf_eqI)(fastforce simp add: map_bind_spmf o_def spmf_eq_0_set_spmf dest: step[OF _ a]) + ultimately + show "trace_eq_simcl S (cond_spmf_fst (bind_spmf p (\s. callee1 s a)) b) + (cond_spmf_fst (bind_spmf q (\s. callee2 s a)) b)" using bind_nat a + by(simp)(rule trace_eq_simcl_bind; auto intro!: sim simp add: bind_UNION) + qed +qed + +proposition trace'_eqI_sim_upto: + fixes callee1 :: "('a, 'b, 's1) callee" and callee2 :: "('a, 'b, 's2) callee" + assumes start: "S p q" + and step: "\p q a. \ S p q; a \ A \ \ + bind_spmf p (\s. map_spmf fst (callee1 s a)) = bind_spmf q (\s. map_spmf fst (callee2 s a))" + and sim: "\p q a res b s'. \ S p q; a \ A; res \ set_spmf q; (b, s') \ set_spmf (callee2 res a) \ + \ trace_eq_simcl S (cond_spmf_fst (bind_spmf p (\s. callee1 s a)) b) + (cond_spmf_fst (bind_spmf q (\s. callee2 s a)) b)" + shows "trace_callee_eq callee1 callee2 A p q" +proof - + let ?S = "trace_eq_simcl S" + from start have "?S p q" by(rule trace_eq_simcl.base) + then show ?thesis by(rule trace'_eqI_sim)(rule trace_eq_simcl_callee[OF step sim]; assumption)+ +qed + +lemma trace_core_eq_simI_upto: + fixes core1 :: "('s_core, 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core" + and core2 :: "('s_core', 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core" + and S :: "'s_core spmf \ 's_core' spmf \ bool" + assumes start: "S p q" + and step_cpoke: "\p q e. \ S p q; e \ E \ \ + weight_spmf (bind_spmf p (\s. cpoke core1 s e)) = weight_spmf (bind_spmf q (\s. cpoke core2 s e))" + and sim_cpoke: "\p q e. \ S p q; e \ E \ \ + trace_eq_simcl S (mk_lossless (bind_spmf p (\s. cpoke core1 s e))) (mk_lossless (bind_spmf q (\s. cpoke core2 s e)))" + and step_cfunc_adv: "\p q ia. \ S p q; ia \ IA \ \ + bind_spmf p (\s1. map_spmf fst (cfunc_adv core1 s1 ia)) = bind_spmf q (\s2. map_spmf fst (cfunc_adv core2 s2 ia))" + and sim_cfunc_adv: "\p q ia s1 s2 s1' s2' oa. \ S p q; ia \ IA; + s1 \ set_spmf p; s2 \ set_spmf q; (oa, s1') \ set_spmf (cfunc_adv core1 s1 ia); (oa, s2') \ set_spmf (cfunc_adv core2 s2 ia) \ + \ trace_eq_simcl S (cond_spmf_fst (bind_spmf p (\s1. cfunc_adv core1 s1 ia)) oa) (cond_spmf_fst (bind_spmf q (\s2. cfunc_adv core2 s2 ia)) oa)" + and step_cfunc_usr: "\p q iu. \ S p q; iu \ IU \ \ + bind_spmf p (\s1. map_spmf fst (cfunc_usr core1 s1 iu)) = bind_spmf q (\s2. map_spmf fst (cfunc_usr core2 s2 iu))" + and sim_cfunc_usr: "\p q iu s1 s2 s1' s2' ou. \ S p q; iu \ IU; + s1 \ set_spmf p; s2 \ set_spmf q; (ou, s1') \ set_spmf (cfunc_usr core1 s1 iu); (ou, s2') \ set_spmf (cfunc_usr core2 s2 iu) \ + \ trace_eq_simcl S (cond_spmf_fst (bind_spmf p (\s1. cfunc_usr core1 s1 iu)) ou) (cond_spmf_fst (bind_spmf q (\s2. cfunc_usr core2 s2 iu)) ou)" + shows "trace_core_eq core1 core2 E IA IU p q" +proof - + let ?S = "trace_eq_simcl S" + from start have "?S p q" by(rule trace_eq_simcl.base) + then show ?thesis + proof(rule trace_core_eq_simI, goal_cases Step_cpoke Sim_cpoke Step_cfunc_adv Sim_cfunc_adv Step_cfunc_usr Sim_cfunc_usr) + { case (Step_cpoke p q e) + then show ?case using step_cpoke + by cases(auto simp add: weight_bind_spmf o_def intro!: Bochner_Integration.integral_cong_AE) } + note eq = this + + case (Sim_cpoke p q e) then show ?case + proof cases + case base then show ?thesis using Sim_cpoke(2) by(rule sim_cpoke) + next + case (bind_nat X f g) + then have "cond_bind_spmf X (\y. f y \ (\s. cpoke core1 s e)) UNIV = cond_bind_spmf X (\y. g y \ (\s. cpoke core2 s e)) UNIV" + using eq[OF Sim_cpoke] step_cpoke Sim_cpoke + by(intro spmf_eqI)(simp add: weight_spmf_def measure_spmf_zero_iff bind_UNION spmf_eq_0_set_spmf) + then show ?thesis using bind_nat Sim_cpoke sim_cpoke + by(auto simp add: cond_bind_spmf cond_spmf_UNIV[symmetric] simp del: cond_spmf_UNIV intro: trace_eq_simcl_bind) + qed + next + { case (Step_cfunc_adv p q ia) + then show ?case using step_cfunc_adv by cases(auto intro!: bind_spmf_cong) } + note eq = this + + case (Sim_cfunc_adv p q ia s1 s2 s1' s2' oa) then show ?case + proof cases + case base then show ?thesis using Sim_cfunc_adv(2-) by(rule sim_cfunc_adv) + next + case (bind_nat X f g) + then have "cond_bind_spmf_fst X (\y. map_spmf fst (f y \ (\s1. cfunc_adv core1 s1 ia))) oa = + cond_bind_spmf_fst X (\y. map_spmf fst (g y \ (\s2. cfunc_adv core2 s2 ia))) oa" + using eq[OF Sim_cfunc_adv(1,2)] + by(intro spmf_eqI)(fastforce simp add: map_bind_spmf o_def spmf_eq_0_set_spmf dest: step_cfunc_adv[OF _ Sim_cfunc_adv(2)]) + then show ?thesis using bind_nat(3-) Sim_cfunc_adv(1-2) + unfolding bind_nat(1,2) bind_spmf_assoc + apply(subst (1 2) cond_spmf_fst_bind) + apply(simp add: o_def) + apply(rule trace_eq_simcl_bind) + apply clarsimp + apply(frule step_cfunc_adv[OF bind_nat(3) Sim_cfunc_adv(2), THEN arg_cong[where f="set_spmf"], THEN equalityD2]) + apply(clarsimp simp add: o_def bind_UNION) + apply(drule subsetD) + apply fastforce + apply(auto intro: sim_cfunc_adv) + done + qed + next + { case (Step_cfunc_usr p q iu) + then show ?case using step_cfunc_usr by cases(auto intro!: bind_spmf_cong) } + note eq = this + + case (Sim_cfunc_usr p q iu s1 s2 s1' s2' ou) then show ?case + proof cases + case base then show ?thesis using Sim_cfunc_usr(2-) by(rule sim_cfunc_usr) + next + case (bind_nat X f g) + then have "cond_bind_spmf_fst X (\y. map_spmf fst (f y \ (\s1. cfunc_usr core1 s1 iu))) ou = + cond_bind_spmf_fst X (\y. map_spmf fst (g y \ (\s2. cfunc_usr core2 s2 iu))) ou" + using eq[OF Sim_cfunc_usr(1,2)] + by(intro spmf_eqI)(fastforce simp add: map_bind_spmf o_def spmf_eq_0_set_spmf dest: step_cfunc_usr[OF _ Sim_cfunc_usr(2)]) + then show ?thesis using bind_nat(3-) Sim_cfunc_usr(1-2) + unfolding bind_nat(1,2) bind_spmf_assoc + apply(subst (1 2) cond_spmf_fst_bind) + apply(simp add: o_def) + apply(rule trace_eq_simcl_bind) + apply clarsimp + apply(frule step_cfunc_usr[OF bind_nat(3) Sim_cfunc_usr(2), THEN arg_cong[where f="set_spmf"], THEN equalityD2]) + apply(clarsimp simp add: o_def bind_UNION) + apply(drule subsetD) + apply fastforce + apply(auto intro: sim_cfunc_usr) + done + qed + qed +qed + + + +context + fixes core :: "('s_core, 'event1 + 'event2, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core" + and rest :: "('s_rest, 'event2, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'more) rest_scheme" +begin + +primcorec core_with_rest :: + "('s_core \ 's_rest, 'event1, 'iadv_core + 'iadv_rest, 'iusr_core + 'iusr_rest, 'oadv_core + 'oadv_rest, 'ousr_core + 'ousr_rest) core" + where + "cpoke core_with_rest = (\(s_core, s_rest) e. map_spmf (\s_core'. (s_core', s_rest)) (cpoke core s_core (Inl e)))" + | "cfunc_adv core_with_rest = (\(s_core, s_rest) iadv. case iadv of + Inl iadv_core \ map_spmf (\(oadv_core, s_core'). (Inl oadv_core, (s_core', s_rest))) (cfunc_adv core s_core iadv_core) + | Inr iadv_rest \ + bind_spmf (rfunc_adv rest s_rest iadv_rest) (\((oadv_rest, es), s_rest'). + map_spmf (\s_core'. (Inr oadv_rest, (s_core', s_rest'))) (foldl_spmf (cpoke core) (return_spmf s_core) (map Inr es))))" + | "cfunc_usr core_with_rest = (\(s_core, s_rest) iusr. case iusr of + Inl iusr_core \ map_spmf (\(ousr_core, s_core'). (Inl ousr_core, (s_core', s_rest))) (cfunc_usr core s_core iusr_core) + | Inr iusr_rest \ + bind_spmf (rfunc_usr rest s_rest iusr_rest) (\((ousr_rest, es), s_rest'). + map_spmf (\s_core'. (Inr ousr_rest, (s_core', s_rest'))) (foldl_spmf (cpoke core) (return_spmf s_core) (map Inr es))))" + +end + +lemma fuse_core_with_rest: + fixes core :: "('s_core, 'event1 + 'event2, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core" + and rest1 :: "('s_rest1, 'event1, 'iadv_rest1, 'iusr_rest1, 'oadv_rest1, 'ousr_rest1, 'more1) rest_scheme" + and rest2 :: "('s_rest2, 'event2, 'iadv_rest2, 'iusr_rest2, 'oadv_rest2, 'ousr_rest2, 'more2) rest_scheme" + shows + "fused_resource.fuse core (parallel_rest rest1 rest2) (s_core, (s_rest1, s_rest2)) = + map_fun (map_sum (lsumr \ map_sum id swap_sum) (lsumr \ map_sum id swap_sum)) (map_spmf (map_prod (map_sum (map_sum id swap_sum \ rsuml) (map_sum id swap_sum \ rsuml)) (map_prod id prod.swap \ rprodl))) + (fused_resource.fuse (core_with_rest core rest2) rest1 ((s_core, s_rest2), s_rest1))" + apply(rule ext) + subgoal for x + apply(cases "(parallel_rest rest1 rest2, (s_core, (s_rest1, s_rest2)), x)" rule: fused_resource.fuse.cases) + apply(auto simp add: fused_resource.fuse.simps map_bind_spmf bind_map_spmf map_prod_def split_def o_def parallel_eoracle_def parallel_oracle_def split!: sum.split intro!: bind_spmf_cong) + apply(subst foldl_spmf_pair_left[simplified split_def]; simp add: map_fun_def o_def bind_map_spmf)+ + done + done + +end \ No newline at end of file diff --git a/thys/Constructive_Cryptography_CM/Goodies.thy b/thys/Constructive_Cryptography_CM/Goodies.thy new file mode 100644 --- /dev/null +++ b/thys/Constructive_Cryptography_CM/Goodies.thy @@ -0,0 +1,44 @@ +theory Goodies + imports + Main +begin + +primrec + inits :: "'a list \ 'a list list" + where + "inits [] = []" + | "inits (x # xs) = [x] # map ((#) x) (inits xs)" + +definition + inits_self :: "'a list \ ('a list \ 'a) list" + where + "inits_self xs = zip ([] # inits xs) xs" + +lemma inits_map: "inits (map f xs) = map (map f) (inits xs)" + by(induction xs) simp_all + +lemma inits_append [simp]: "inits (xs @ ys) = inits xs @ map ((@) xs) (inits ys)" + by(induction xs) (simp_all) + +lemma inits_self_simps [simp]: + "inits_self [] = []" + "inits_self (x # xs) = ([], x) # map (apfst ((#) x)) (inits_self xs)" + by(simp_all add: inits_self_def apfst_def map_prod_def zip_map1[symmetric]) + +lemma inits_self_map: "inits_self (map f xs) = map (map_prod (map f) f) (inits_self xs)" + by(induction xs) (simp_all add: apfst_def prod.map_comp o_def) + +lemma in_set_inits_self: "(ys, z) \ set (inits_self xs) \ (\zs. xs = ys @ z # zs)" + by(induction xs arbitrary: ys z)(auto simp add: Cons_eq_append_conv apfst_def map_prod_def) + +lemma foldl_append: "foldl (\s e. s @ [e]) s l = s @ l" + by (induction l arbitrary: s) auto + +lemma foldl_insert: "foldl (\A x. insert (f x) A) A xs = A \ (f ` set xs)" + by(induction xs arbitrary: A) simp_all + +lemma foldl_concat_prodl: "foldl (\(l, r) x. (l @ g r x, f r x)) (l, r) xs = + (l @ concat (map (\(ys, x). g (foldl f r ys) x) (inits_self xs)), foldl f r xs)" + by(induction xs arbitrary: l r) (simp_all add: split_def o_def) + +end \ No newline at end of file diff --git a/thys/Constructive_Cryptography_CM/More_CC.thy b/thys/Constructive_Cryptography_CM/More_CC.thy new file mode 100644 --- /dev/null +++ b/thys/Constructive_Cryptography_CM/More_CC.thy @@ -0,0 +1,2214 @@ +theory More_CC imports + Constructive_Cryptography.Constructive_Cryptography +begin + +section \Material for Isabelle library\ + +lemma eq_alt_conversep: "(=) = (BNF_Def.Grp UNIV id)\\" + by(simp add: Grp_def fun_eq_iff) + +parametric_constant + swap_parametric [transfer_rule]: prod.swap_def + +lemma Sigma_parametric [transfer_rule]: includes lifting_syntax shows + "(rel_set A ===> (A ===> rel_set B) ===> rel_set (rel_prod A B)) Sigma Sigma" + unfolding Sigma_def by transfer_prover + +lemma empty_eq_Plus [simp]: "{} = A <+> B \ A = {} \ B = {}" + by auto + +lemma insert_Inl_Plus [simp]: "insert (Inl x) (A <+> B) = insert x A <+> B" by auto + +lemma insert_Inr_Plus [simp]: "insert (Inr x) (A <+> B) = A <+> insert x B" by auto + +lemma map_sum_image_Plus [simp]: "map_sum f g ` (A <+> B) = f ` A <+> g ` B" + by(auto intro: rev_image_eqI) + +lemma Plus_subset_Plus_iff [simp]: "A <+> B \ C <+> D \ A \ C \ B \ D" + by auto + +lemma map_sum_eq_Inl_iff: "map_sum f g x = Inl y \ (\x'. x = Inl x' \ y = f x')" + by(cases x) auto + +lemma map_sum_eq_Inr_iff: "map_sum f g x = Inr y \ (\x'. x = Inr x' \ y = g x')" + by(cases x) auto + +lemma surj_map_sum: "surj (map_sum f g)" if "surj f" "surj g" + apply(safe; simp) + subgoal for x using that + by(cases x)(auto 4 3 intro: image_eqI[where x="Inl _"] image_eqI[where x="Inr _"]) + done + +lemma bij_map_sumI [simp]: "bij (map_sum f g)" if "bij f" "bij g" + using that by(clarsimp simp add: bij_def sum.inj_map surj_map_sum) + +lemma inv_map_sum [simp]: + "\ bij f; bij g \ \ inv_into UNIV (map_sum f g) = map_sum (inv_into UNIV f) (inv_into UNIV g)" + by(rule inj_imp_inv_eq)(simp_all add: sum.map_comp sum.inj_map bij_def surj_iff sum.map_id) + + +context conditionally_complete_lattice begin + +lemma admissible_le1I: + "ccpo.admissible lub ord (\x. f x \ y)" + if "cont lub ord Sup (\) f" + by(rule ccpo.admissibleI)(auto simp add: that[THEN contD] intro!: cSUP_least) + +lemma admissible_le1_mcont [cont_intro]: + "ccpo.admissible lub ord (\x. f x \ y)" if "mcont lub ord Sup (\) f" + using that by(simp add: admissible_le1I mcont_def) + +end + +lemma eq_alt_conversep2: "(=) = ((BNF_Def.Grp UNIV id)\\)\\" + by(auto simp add: Grp_def fun_eq_iff) + +lemma nn_integral_indicator_singleton1 [simp]: + assumes [measurable]: "{y} \ sets M" + shows "(\\<^sup>+x. indicator {y} x * f x \M) = emeasure M {y} * f y" + by(simp add: mult.commute) + +lemma nn_integral_indicator_singleton1' [simp]: + assumes "{y} \ sets M" + shows "(\\<^sup>+x. indicator {x} y * f x \M) = emeasure M {y} * f y" + by(subst nn_integral_indicator_singleton1[symmetric, OF assms])(rule nn_integral_cong; simp split: split_indicator) + +subsection \Probabilities\ + +lemma pmf_eq_1_iff: "pmf p x = 1 \ p = return_pmf x" (is "?lhs = ?rhs") +proof(rule iffI) + assume ?lhs + have "pmf p i = 0" if "x \ i" for i + proof(rule antisym) + have "pmf p i + 1 \ pmf p i + pmf p x" using \?lhs\ by simp + also have "\ = measure (measure_pmf p) {i, x}" using that + by(subst measure_pmf.finite_measure_eq_sum_singleton)(simp_all add: pmf.rep_eq) + also have "\ \ 1" by(rule measure_pmf.subprob_measure_le_1) + finally show "pmf p i \ 0" by simp + qed(rule pmf_nonneg) + then show ?rhs if ?lhs + by(intro pmf_eqI)(auto simp add: that split: split_indicator) +qed simp + +lemma measure_spmf_cong: "measure (measure_spmf p) A = measure (measure_spmf p) B" + if "A \ set_spmf p = B \ set_spmf p" +proof - + have "measure (measure_spmf p) A = measure (measure_spmf p) (A \ set_spmf p) + measure (measure_spmf p) (A - set_spmf p)" + by(subst measure_spmf.finite_measure_Union[symmetric])(auto intro: arg_cong2[where f=measure]) + also have "measure (measure_spmf p) (A - set_spmf p) = 0" by(simp add: measure_spmf_zero_iff) + also have "0 = measure (measure_spmf p) (B - set_spmf p)" by(simp add: measure_spmf_zero_iff) + also have "measure (measure_spmf p) (A \ set_spmf p) + \ = measure (measure_spmf p) B" + unfolding that by(subst measure_spmf.finite_measure_Union[symmetric])(auto intro: arg_cong2[where f=measure]) + finally show ?thesis . +qed + +definition weight_spmf' where "weight_spmf' = weight_spmf" +lemma weight_spmf'_parametric [transfer_rule]: "rel_fun (rel_spmf A) (=) weight_spmf' weight_spmf'" + unfolding weight_spmf'_def by(rule weight_spmf_parametric) + +lemma bind_spmf_to_nat_on: + "bind_spmf (map_spmf (to_nat_on (set_spmf p)) p) (\n. f (from_nat_into (set_spmf p) n)) = bind_spmf p f" + by(simp add: bind_map_spmf cong: bind_spmf_cong) + +lemma try_cond_spmf_fst: + "try_spmf (cond_spmf_fst p x) q = (if x \ fst ` set_spmf p then cond_spmf_fst p x else q)" + by (metis cond_spmf_fst_eq_return_None lossless_cond_spmf_fst try_spmf_lossless try_spmf_return_None) + +lemma measure_try_spmf: + "measure (measure_spmf (try_spmf p q)) A = measure (measure_spmf p) A + pmf p None * measure (measure_spmf q) A" +proof - + have "emeasure (measure_spmf (try_spmf p q)) A = emeasure (measure_spmf p) A + pmf p None * emeasure (measure_spmf q) A" + by(fold nn_integral_spmf)(simp add: spmf_try_spmf nn_integral_add ennreal_mult' nn_integral_cmult) + then show ?thesis by(simp add: measure_spmf.emeasure_eq_measure ennreal_mult'[symmetric] ennreal_plus[symmetric] del: ennreal_plus) +qed + +lemma rel_spmf_OO_trans_strong: + "\ rel_spmf R p q; rel_spmf S q r \ \ rel_spmf (R OO eq_onp (\x. x \ set_spmf q) OO S) p r" + by(auto intro: rel_spmf_OO_trans rel_spmf_reflI simp add: eq_onp_def) + +lemma mcont2mcont_spmf [cont_intro]: + "mcont lub ord Sup (\) (\p. spmf (f p) x)" + if "mcont lub ord lub_spmf (ord_spmf (=)) f" + using that unfolding mcont_def + apply safe + subgoal by(rule monotone2monotone, rule monotone_spmf; simp) + apply(rule contI) + apply(subst contD[where f=f and luba=lub]; simp) + apply(subst cont_spmf[THEN contD]) + apply(erule (2) chain_imageI[OF _ monotoneD]) + apply simp + apply(simp add: image_image) + done + +lemma ord_spmf_try_spmf2: "ord_spmf R p (try_spmf p q)" if "rel_spmf R p p" +proof - + have "ord_spmf R (bind_pmf p return_pmf) (try_spmf p q)" unfolding try_spmf_def + by(rule rel_pmf_bindI[where R="rel_option R"]) + (use that in \auto simp add: rel_pmf_return_pmf1 elim!: option.rel_cases\) + then show ?thesis by(simp add: bind_return_pmf') +qed + +lemma ord_spmf_lossless_spmfD1: + assumes "ord_spmf R p q" + and "lossless_spmf p" + shows "rel_spmf R p q" + by (metis (no_types, lifting) assms lossless_iff_set_pmf_None option.simps(11) ord_option.cases pmf.rel_mono_strong) + +lemma restrict_spmf_mono: + "ord_spmf (=) p q \ ord_spmf (=) (p \ A) (q \ A)" + by(auto simp add: restrict_spmf_def pmf.rel_map elim!: pmf.rel_mono_strong elim: ord_option.cases) + +lemma restrict_lub_spmf: + assumes chain: "Complete_Partial_Order.chain (ord_spmf (=)) Y" + shows "restrict_spmf (lub_spmf Y) A = lub_spmf ((\p. restrict_spmf p A) ` Y)" (is "?lhs = ?rhs") +proof(cases "Y = {}") + case Y: False + have chain': "Complete_Partial_Order.chain (ord_spmf (=)) ((\p. p \ A) ` Y)" + using chain by(rule chain_imageI)(auto intro: restrict_spmf_mono) + show ?thesis by(rule spmf_eqI)(simp add: spmf_lub_spmf[OF chain'] Y image_image spmf_restrict_spmf spmf_lub_spmf[OF chain]) +qed simp + +lemma mono2mono_restrict_spmf [THEN spmf.mono2mono]: + shows monotone_restrict_spmf: "monotone (ord_spmf (=)) (ord_spmf (=)) (\p. p \ A)" + by(rule monotoneI)(rule restrict_spmf_mono) + +lemma mcont2mcont_restrict_spmf [THEN spmf.mcont2mcont, cont_intro]: + shows mcont_restrict_spmf: "mcont lub_spmf (ord_spmf (=)) lub_spmf (ord_spmf (=)) (\p. restrict_spmf p A)" + using monotone_restrict_spmf by(rule mcontI)(simp add: contI restrict_lub_spmf) + +lemma ord_spmf_case_option: "ord_spmf R (case x of None \ a | Some y \ b y) (case x of None \ a' | Some y \ b' y)" + if "ord_spmf R a a'" "\y. ord_spmf R (b y) (b' y)" using that by(cases x) auto + +lemma ord_spmf_map_spmfI: "ord_spmf (=) (map_spmf f p) (map_spmf f q)" if "ord_spmf (=) p q" + using that by(auto simp add: pmf.rel_map elim!: pmf.rel_mono_strong ord_option.cases) + +subsubsection \Conditional probabilities\ + +lemma mk_lossless_cond_spmf [simp]: "mk_lossless (cond_spmf p A) = cond_spmf p A" + by(simp add: cond_spmf_alt) + +context + fixes p :: "'a pmf" + and f :: "'a \ 'b pmf" + and A :: "'b set" + and F :: "'a \ real" + defines "F \ \x. pmf p x * measure (measure_pmf (f x)) A / measure (measure_pmf (bind_pmf p f)) A" +begin + +definition cond_bind_pmf :: "'a pmf" where "cond_bind_pmf = embed_pmf F" + +lemma cond_bind_pmf_nonneg: "F x \ 0" + by(simp add: F_def) + +context assumes defined: "A \ (\x\set_pmf p. set_pmf (f x)) \ {}" begin + +private lemma nonzero: "measure (measure_pmf (bind_pmf p f)) A > 0" + using defined by(auto 4 3 intro: measure_pmf_posI) + +lemma cond_bind_pmf_prob: "(\\<^sup>+ x. F x \count_space UNIV) = 1" +proof - + have nonzero': "(\\<^sup>+ x. ennreal (pmf p x) * ennreal (measure_pmf.prob (f x) A) \count_space UNIV) \ 0" + using defined by(auto simp add: nn_integral_0_iff_AE AE_count_space pmf_eq_0_set_pmf measure_pmf_zero_iff) + have finite: "(\\<^sup>+ x. ennreal (pmf p x) * ennreal (measure_pmf.prob (f x) A) \count_space UNIV) < \" (is "?lhs < _") + proof(rule order.strict_trans1) + show "?lhs \ (\\<^sup>+ x. ennreal (pmf p x) * 1 \count_space UNIV)" + by(rule nn_integral_mono)(simp add: mult_left_le) + show "\ < \" by(simp add: nn_integral_pmf_eq_1) + qed + have "(\\<^sup>+ x. F x \count_space UNIV) = + (\\<^sup>+ x. ennreal (pmf p x * measure_pmf.prob (f x) A)) / emeasure (measure_pmf (bind_pmf p f)) A" + using nonzero unfolding F_def measure_pmf.emeasure_eq_measure + by(simp add: divide_ennreal[symmetric] divide_ennreal_def nn_integral_multc) + also have "\ = 1" unfolding emeasure_bind_pmf + by(simp add: measure_pmf.emeasure_eq_measure nn_integral_measure_pmf ennreal_mult' nonzero' finite) + finally show ?thesis . +qed + +lemma pmf_cond_bind_pmf: "pmf cond_bind_pmf x = F x" + unfolding cond_bind_pmf_def by(rule pmf_embed_pmf[OF cond_bind_pmf_nonneg cond_bind_pmf_prob]) + +lemma set_cond_bind_pmf: "set_pmf cond_bind_pmf = {x\set_pmf p. set_pmf (f x) \ A \ {}}" + unfolding cond_bind_pmf_def + by(subst set_embed_pmf[OF cond_bind_pmf_nonneg cond_bind_pmf_prob]) + (auto simp add: F_def pmf_eq_0_set_pmf measure_pmf_zero_iff) + +lemma cond_bind_pmf: "cond_pmf (bind_pmf p f) A = bind_pmf cond_bind_pmf (\x. cond_pmf (f x) A)" + (is "?lhs = ?rhs") +proof(rule pmf_eqI) + fix i + have "ennreal (pmf ?lhs i) = ennreal (pmf ?rhs i)" + proof(cases "i \ A") + case True + have "ennreal (pmf ?lhs i) = (\\<^sup>+ x. ennreal (pmf p x) * ennreal (pmf (f x) i) / ennreal (measure_pmf.prob (p \ f) A) \count_space UNIV)" + using True defined + by(simp add: pmf_cond bind_UNION Int_commute divide_ennreal[symmetric] nonzero ennreal_pmf_bind) + (simp add: divide_ennreal_def nn_integral_multc[symmetric] nn_integral_measure_pmf) + also have "\ = (\\<^sup>+ x. ennreal (F x) * ennreal (pmf (cond_pmf (f x) A) i) \count_space UNIV)" + using True nonzero + apply(intro nn_integral_cong) + subgoal for x + by(clarsimp simp add: F_def ennreal_mult'[symmetric] divide_ennreal) + (cases "measure_pmf.prob (f x) A = 0"; auto simp add: pmf_cond pmf_eq_0_set_pmf measure_pmf_zero_iff) + done + also have "\ = ennreal (pmf ?rhs i)" + by(simp add: ennreal_pmf_bind nn_integral_measure_pmf pmf_cond_bind_pmf) + finally show ?thesis . + next + case False + then show ?thesis using defined + by(simp add: pmf_cond bind_UNION Int_commute pmf_eq_0_set_pmf set_cond_bind_pmf) + qed + then show "pmf ?lhs i = pmf ?rhs i" by simp +qed + +end + +end + + +lemma cond_spmf_try1: + "cond_spmf (try_spmf p q) A = cond_spmf p A" if "set_spmf q \ A = {}" + apply(rule spmf_eqI) + using that + apply(auto simp add: spmf_try_spmf measure_try_spmf measure_spmf_zero_iff) + apply(subst (2) spmf_eq_0_set_spmf[THEN iffD2]) + apply blast + apply simp + apply(simp add: measure_try_spmf measure_spmf_zero_iff) + done + +lemma cond_spmf_cong: "cond_spmf p A = cond_spmf p B" if "A \ set_spmf p = B \ set_spmf p" + apply(rule spmf_eqI) + using that by(auto simp add: measure_spmf_zero_iff spmf_eq_0_set_spmf measure_spmf_cong[OF that]) + +lemma cond_spmf_pair_spmf: + "cond_spmf (pair_spmf p q) (A \ B) = pair_spmf (cond_spmf p A) (cond_spmf q B)" (is "?lhs = ?rhs") +proof(rule spmf_eqI) + show "spmf ?lhs i = spmf ?rhs i" for i + proof(cases i) + case i [simp]: (Pair a b) + then show ?thesis by(simp add: measure_pair_spmf_times) + qed +qed + +lemma cond_spmf_pair_spmf1: + "cond_spmf_fst (map_spmf (\((x, s'), y). (f x, s', y)) (pair_spmf p q)) x = + pair_spmf (cond_spmf_fst (map_spmf (\(x, s'). (f x, s')) p) x) q" (is "?lhs = ?rhs") + if "lossless_spmf q" +proof - + have "?lhs = map_spmf (\((_, s'), y). (s', y)) (cond_spmf (pair_spmf p q) ((\((x, s'), y). (f x, s', y)) -` ({x} \ UNIV)))" + by(simp add: cond_spmf_fst_def spmf.map_comp o_def split_def) + also have "((\((x, s'), y). (f x, s', y)) -` ({x} \ UNIV)) = ((\(x, y). (f x, y)) -` ({x} \ UNIV)) \ UNIV" + by(auto) + also have "map_spmf (\((_, s'), y). (s', y)) (cond_spmf (pair_spmf p q) \) = ?rhs" + by(simp add: cond_spmf_fst_def cond_spmf_pair_spmf that spmf.map_comp pair_map_spmf1 apfst_def map_prod_def split_def) + finally show ?thesis . +qed + +lemma try_cond_spmf: "try_spmf (cond_spmf p A) q = (if set_spmf p \ A \ {} then cond_spmf p A else q)" + apply(clarsimp simp add: cond_spmf_def lossless_iff_set_pmf_None intro!: try_spmf_lossless) + apply(subst (asm) set_cond_pmf) + apply(auto simp add: in_set_spmf) + done + +lemma cond_spmf_try2: + "cond_spmf (try_spmf p q) A = (if lossless_spmf p then return_pmf None else cond_spmf q A)" if "set_spmf p \ A = {}" + apply(rule spmf_eqI) + using that + apply(auto simp add: spmf_try_spmf measure_try_spmf measure_spmf_zero_iff lossless_iff_pmf_None) + apply(subst spmf_eq_0_set_spmf[THEN iffD2]) + apply blast + apply(simp add: measure_spmf_zero_iff[THEN iffD2]) + done + + +definition cond_bind_spmf :: "'a spmf \ ('a \ 'b spmf) \ 'b set \ 'a spmf" where + "cond_bind_spmf p f A = + (if \x\set_spmf p. set_spmf (f x) \ A \ {} then + cond_bind_pmf p (\x. case x of None \ return_pmf None | Some x \ f x) (Some ` A) + else return_pmf None)" + +context begin + +private lemma defined: "\ y \ set_spmf (f x); y \ A; x \ set_spmf p \ + \ Some ` A \ (\x\set_pmf p. set_pmf (case x of None \ return_pmf None | Some x \ f x)) \ {}" + by(fastforce simp add: in_set_spmf bind_spmf_def) + +lemma spmf_cond_bind_spmf [simp]: + "spmf (cond_bind_spmf p f A) x = spmf p x * measure (measure_spmf (f x)) A / measure (measure_spmf (bind_spmf p f)) A" + by(clarsimp simp add: cond_bind_spmf_def measure_spmf_zero_iff bind_UNION pmf_cond_bind_pmf defined split!: if_split) + (fastforce simp add: in_set_spmf bind_spmf_def measure_measure_spmf_conv_measure_pmf)+ + +lemma set_cond_bind_spmf [simp]: + "set_spmf (cond_bind_spmf p f A) = {x\set_spmf p. set_spmf (f x) \ A \ {}}" + by(clarsimp simp add: cond_bind_spmf_def set_spmf_def bind_UNION) + (subst set_cond_bind_pmf; fastforce simp add: measure_measure_spmf_conv_measure_pmf) + +lemma cond_bind_spmf: "cond_spmf (bind_spmf p f) A = bind_spmf (cond_bind_spmf p f A) (\x. cond_spmf (f x) A)" + by(auto simp add: cond_spmf_def bind_UNION cond_bind_spmf_def split!: if_splits) + (fastforce split: option.splits simp add: cond_bind_pmf set_cond_bind_pmf defined in_set_spmf bind_spmf_def intro!: bind_pmf_cong[OF refl]) + +end + +lemma cond_spmf_fst_parametric [transfer_rule]: includes lifting_syntax shows + "(rel_spmf (rel_prod (=) B) ===> (=) ===> rel_spmf B) cond_spmf_fst cond_spmf_fst" + apply(rule rel_funI)+ + apply(clarsimp simp add: cond_spmf_fst_def spmf_rel_map elim!: rel_spmfE) + subgoal for x pq + by(subst (1 2) cond_spmf_cong[where B="fst -` ({x} \ UNIV) \ snd -` ({x} \ UNIV)"]) + (fastforce intro: rel_spmf_reflI)+ + done + +lemma cond_spmf_fst_map_prod: + "cond_spmf_fst (map_spmf (\(x, y). (f x, g x y)) p) (f x) = map_spmf (g x) (cond_spmf_fst p x)" + if "inj_on f (insert x (fst ` set_spmf p))" +proof - + have "cond_spmf p ((\(x, y). (f x, g x y)) -` ({f x} \ UNIV)) = cond_spmf p (((\(x, y). (f x, g x y)) -` ({f x} \ UNIV)) \ set_spmf p)" + by(rule cond_spmf_cong) simp + also have "((\(x, y). (f x, g x y)) -` ({f x} \ UNIV)) \ set_spmf p = ({x} \ UNIV) \ set_spmf p" + using that by(auto 4 3 dest: inj_onD intro: rev_image_eqI) + also have "cond_spmf p \ = cond_spmf p ({x} \ UNIV)" + by(rule cond_spmf_cong) simp + finally show ?thesis + by(auto simp add: cond_spmf_fst_def spmf.map_comp o_def split_def intro: map_spmf_cong) +qed + +lemma cond_spmf_fst_map_prod_inj: + "cond_spmf_fst (map_spmf (\(x, y). (f x, g x y)) p) (f x) = map_spmf (g x) (cond_spmf_fst p x)" + if "inj f" + apply(rule cond_spmf_fst_map_prod) + using that by(simp add: inj_on_def) + +definition cond_bind_spmf_fst :: "'a spmf \ ('a \ 'b spmf) \ 'b \ 'a spmf" where + "cond_bind_spmf_fst p f x = cond_bind_spmf p (map_spmf (\b. (b, ())) \ f) ({x} \ UNIV)" + +lemma cond_bind_spmf_fst_map_spmf_fst: + "cond_bind_spmf_fst p (map_spmf fst \ f) x = cond_bind_spmf p f ({x} \ UNIV)" (is "?lhs = ?rhs") +proof - + have [simp]: "(\x. (fst x, ())) -` ({x} \ UNIV) = {x} \ UNIV" by auto + have "?lhs = cond_bind_spmf p (\x. map_spmf (\x. (fst x, ())) (f x)) ({x} \ UNIV)" + by(simp add: cond_bind_spmf_fst_def spmf.map_comp o_def) + also have "\ = ?rhs" by(rule spmf_eqI)(simp add: measure_map_spmf map_bind_spmf[unfolded o_def, symmetric]) + finally show ?thesis . +qed + +lemma cond_spmf_fst_bind: "cond_spmf_fst (bind_spmf p f) x = + bind_spmf (cond_bind_spmf_fst p (map_spmf fst \ f) x) (\y. cond_spmf_fst (f y) x)" + by(simp add: cond_spmf_fst_def cond_bind_spmf map_bind_spmf cond_bind_spmf_fst_map_spmf_fst)(simp add: o_def) + +lemma spmf_cond_bind_spmf_fst [simp]: + "spmf (cond_bind_spmf_fst p f x) i = spmf p i * spmf (f i) x / spmf (bind_spmf p f) x" + by(simp add: cond_bind_spmf_fst_def) + (auto simp add: spmf_conv_measure_spmf measure_map_spmf map_bind_spmf[symmetric] intro!: arg_cong2[where f="(/)"] arg_cong2[where f="(*)"] arg_cong2[where f="measure"]) + +lemma set_cond_bind_spmf_fst [simp]: + "set_spmf (cond_bind_spmf_fst p f x) = {y \ set_spmf p. x \ set_spmf (f y)}" + by(auto simp add: cond_bind_spmf_fst_def intro: rev_image_eqI) + +lemma map_cond_spmf_fst: "map_spmf f (cond_spmf_fst p x) = cond_spmf_fst (map_spmf (apsnd f) p) x" + by(auto simp add: cond_spmf_fst_def spmf.map_comp intro!: map_spmf_cong arg_cong2[where f="cond_spmf"]) + +lemma cond_spmf_fst_try1: + "cond_spmf_fst (try_spmf p q) x = cond_spmf_fst p x" if "x \ fst ` set_spmf q" + using that + apply(simp add: cond_spmf_fst_def) + apply(subst cond_spmf_try1) + apply(auto intro: rev_image_eqI) + done + +lemma cond_spmf_fst_try2: + "cond_spmf_fst (try_spmf p q) x = (if lossless_spmf p then return_pmf None else cond_spmf_fst q x)" if "x \ fst ` set_spmf p" + using that + apply(simp add: cond_spmf_fst_def split!: if_split) + apply (metis cond_spmf_fst_def cond_spmf_fst_eq_return_None) + by (metis cond_spmf_fst_def cond_spmf_try2 lossless_cond_spmf lossless_cond_spmf_fst lossless_map_spmf) + +lemma cond_spmf_fst_map_inj: + "cond_spmf_fst (map_spmf (apfst f) p) (f x) = cond_spmf_fst p x" if "inj f" + by(auto simp add: cond_spmf_fst_def spmf.map_comp intro!: map_spmf_cong arg_cong2[where f=cond_spmf] dest: injD[OF that]) + +lemma cond_spmf_fst_pair_spmf1: + "cond_spmf_fst (map_spmf (\(x, y). (f x, g x y)) (pair_spmf p q)) a = + bind_spmf (cond_spmf_fst (map_spmf (\x. (f x, x)) p) a) (\x. map_spmf (g x) (mk_lossless q))" (is "?lhs = ?rhs") +proof - + have "(\(x, y). (f x, g x y)) -` ({a} \ UNIV) = f -` {a} \ UNIV" by(auto) + moreover have "(\x. (f x, x)) -` ({a} \ UNIV) = f -` {a}" by auto + ultimately show ?thesis + by(simp add: cond_spmf_fst_def spmf.map_comp o_def split_beta cond_spmf_pair_spmf) + (simp add: pair_spmf_alt_def map_bind_spmf o_def map_spmf_conv_bind_spmf) +qed + +lemma cond_spmf_fst_return_spmf': + "cond_spmf_fst (return_spmf (x, y)) z = (if x = z then return_spmf y else return_pmf None)" + by(simp add: cond_spmf_fst_def) + + + + + + +section \Material for CryptHOL\ + +lemma left_gpv_lift_spmf [simp]: "left_gpv (lift_spmf p) = lift_spmf p" + by(rule gpv.expand)(simp add: spmf.map_comp o_def) + +lemma right_gpv_lift_spmf [simp]: "right_gpv (lift_spmf p) = lift_spmf p" + by(rule gpv.expand)(simp add: spmf.map_comp o_def) + +lemma map'_lift_spmf: "map_gpv' f g h (lift_spmf p) = lift_spmf (map_spmf f p)" + by(rule gpv.expand)(simp add: gpv.map_sel spmf.map_comp o_def) + +lemma in_set_sample_uniform [simp]: "x \ set_spmf (sample_uniform n) \ x < n" + by(simp add: sample_uniform_def) + +lemma (in cyclic_group) inj_on_generator_iff [simp]: "\ x < order G; y < order G \ \ \<^bold>g [^] x = \<^bold>g [^] y \ x = y" + using inj_on_generator by(auto simp add: inj_on_def) + +lemma map_\_bot [simp]: "map_\ f g \ = \" + unfolding bot_\_def map_\_\_uniform by simp + +lemma map_\_Inr_plus [simp]: "map_\ Inr f (\1 \\<^sub>\ \2) = map_\ id (f \ Inr) \2" + by(rule \_eqI) auto + +lemma interaction_bound_map_gpv'_le: + defines "ib \ interaction_bound" + shows "interaction_bound consider (map_gpv' f g h gpv) \ ib (consider \ g) gpv" +proof(induction arbitrary: gpv rule: interaction_bound_fixp_induct) + case adm show ?case by simp + case bottom show ?case by simp + case (step interaction_bound') + show ?case unfolding ib_def + by(subst interaction_bound.simps) + (auto simp add: image_comp ib_def split: generat.split intro!: SUP_mono rev_bexI step.IH[unfolded ib_def]) +qed + +lemma interaction_bounded_by_map_gpv' [interaction_bound]: + assumes "interaction_bounded_by (consider \ g) gpv n" + shows "interaction_bounded_by consider (map_gpv' f g h gpv) n" + using assms interaction_bound_map_gpv'_le[of "consider" f g h gpv] by(simp add: interaction_bounded_by.simps) + +lemma map_gpv'_bind_gpv: + "map_gpv' f g h (bind_gpv gpv F) = bind_gpv (map_gpv' id g h gpv) (\x. map_gpv' f g h (F x))" + by(coinduction arbitrary: gpv rule: gpv.coinduct_strong) + (auto simp del: bind_gpv_sel' simp add: bind_gpv.sel spmf_rel_map bind_map_spmf generat.rel_map rel_fun_def intro!: rel_spmf_bind_reflI rel_spmf_reflI generat.rel_refl_strong split!: generat.split) + +lemma exec_gpv_map_gpv': + "exec_gpv callee (map_gpv' f g h gpv) s = + map_spmf (map_prod f id) (exec_gpv (map_fun id (map_fun g (map_spmf (map_prod h id))) callee) gpv s)" + using exec_gpv_parametric'[ + where S="(=)" and CALL="BNF_Def.Grp UNIV g" and R="conversep (BNF_Def.Grp UNIV h)" and A="BNF_Def.Grp UNIV f", + unfolded rel_gpv''_Grp, simplified] + apply(subst (asm) (2) conversep_eq[symmetric]) + apply(subst (asm) prod.rel_conversep) + apply(subst (asm) (2 4) eq_alt) + apply(subst (asm) prod.rel_Grp) + apply simp + apply(subst (asm) spmf_rel_conversep) + apply(subst (asm) option.rel_Grp) + apply(subst (asm) pmf.rel_Grp) + apply simp + apply(subst (asm) prod.rel_Grp) + apply simp + apply(subst (asm) (1 3) conversep_conversep[symmetric]) + apply(subst (asm) rel_fun_conversep) + apply(subst (asm) rel_fun_Grp) + apply(subst (asm) rel_fun_conversep) + apply simp + apply(simp add: option.rel_Grp pmf.rel_Grp fun.rel_Grp) + apply(simp add: rel_fun_def BNF_Def.Grp_def o_def map_fun_def) + apply(erule allE)+ + apply(drule fun_cong) + apply(erule trans) + apply simp + done + +lemma colossless_gpv_sub_gpvs: + assumes "colossless_gpv \ gpv" "gpv' \ sub_gpvs \ gpv" + shows "colossless_gpv \ gpv'" +using assms(2,1) by(induction)(auto dest: colossless_gpvD) + +lemma pfinite_gpv_sub_gpvs: + assumes "pfinite_gpv \ gpv" "gpv' \ sub_gpvs \ gpv" "\ \g gpv \" + shows "pfinite_gpv \ gpv'" + using assms(2,1,3) by(induction)(auto dest: pfinite_gpv_ContD WT_gpvD) + +lemma pfinite_gpv_id_oracle [simp]: "pfinite_gpv \ (id_oracle s x)" if "x \ outs_\ \" + by(simp add: id_oracle_def pgen_lossless_gpv_PauseI[OF that]) + +subsection \@{term try_gpv}\ + +lemma plossless_gpv_try_gpvI: + assumes "pfinite_gpv \ gpv" + and "\ colossless_gpv \ gpv \ plossless_gpv \ gpv'" + shows "plossless_gpv \ (TRY gpv ELSE gpv')" + using assms unfolding pgen_lossless_gpv_def + by(cases "colossless_gpv \ gpv")(simp cong: expectation_gpv_cong_fail, simp) + +lemma WT_gpv_try_gpvI [WT_intro]: + assumes "\ \g gpv \" + and "\ colossless_gpv \ gpv \ \ \g gpv' \" + shows "\ \g try_gpv gpv gpv' \" + using assms by(coinduction arbitrary: gpv)(auto 4 4 dest: WT_gpvD colossless_gpvD split: if_split_asm) + +lemma (in callee_invariant_on) exec_gpv_try_gpv: + fixes exec_gpv1 + defines "exec_gpv1 \ exec_gpv" + assumes WT: "\ \g gpv \" + and pfinite: "pfinite_gpv \ gpv" + and I: "I s" + and f: "\s. I s \ f (x, s) = z" + and lossless: "\s x. \x \ outs_\ \; I s\ \ lossless_spmf (callee s x)" + shows "map_spmf f (exec_gpv callee (try_gpv gpv (Done x)) s) = + try_spmf (map_spmf f (exec_gpv1 callee gpv s)) (return_spmf z)" + (is "?lhs = ?rhs") +proof - + note [[show_variants]] + have le: "ord_spmf (=) ?lhs ?rhs" using WT I + proof(induction arbitrary: gpv s rule: exec_gpv_fixp_induct) + case adm show ?case by simp + case bottom show ?case by simp + case (step exec_gpv') + show ?case using step.prems unfolding exec_gpv1_def + apply(subst exec_gpv.simps) + apply(simp add: map_spmf_bind_spmf) + apply(subst (1 2) try_spmf_def) + apply(simp add: map_bind_pmf bind_spmf_pmf_assoc o_def) + apply(simp add: bind_spmf_def bind_map_pmf bind_assoc_pmf) + apply(rule rel_pmf_bindI[where R="eq_onp (\x. x \ set_pmf (the_gpv gpv))"]) + apply(rule pmf.rel_refl_strong) + apply(simp add: eq_onp_def) + apply(clarsimp split!: option.split generat.split simp add: bind_return_pmf f map_spmf_bind_spmf o_def eq_onp_def) + apply(simp add: bind_spmf_def bind_assoc_pmf) + subgoal for out c + apply(rule rel_pmf_bindI[where R="eq_onp (\x. x \ set_pmf (callee s out))"]) + apply(rule pmf.rel_refl_strong) + apply(simp add: eq_onp_def) + apply(clarsimp split!: option.split simp add: eq_onp_def) + apply(simp add: in_set_spmf[symmetric]) + apply(rule spmf.leq_trans) + apply(rule step.IH) + apply(frule (1) WT_gpvD) + apply(erule (1) WT_gpvD) + apply(drule WT_callee) + apply(erule (2) WT_calleeD) + apply(frule (1) WT_gpvD) + apply(erule (2) callee_invariant) + apply(simp add: try_spmf_def exec_gpv1_def) + done + done + qed + + have "lossless_spmf ?lhs" + apply simp + apply(rule plossless_exec_gpv) + apply(rule plossless_gpv_try_gpvI) + apply(rule pfinite) + apply simp + apply(rule WT_gpv_try_gpvI) + apply(simp add: WT) + apply simp + apply(simp add: lossless) + apply(simp add: I) + done + from ord_spmf_lossless_spmfD1[OF le this] show ?thesis by(simp add: spmf_rel_eq) +qed + +lemma try_gpv_bind_gen_lossless': \ \generalises @{thm try_gpv_bind_gen_lossless}\ + assumes lossless: "gen_lossless_gpv b \ gpv" + and WT1: "\ \g gpv \" + and WT2: "\ \g gpv' \" + and WTf: "\x. x \ results_gpv \ gpv \ \ \g f x \" + shows "eq_\_gpv (=) \ (TRY bind_gpv gpv f ELSE gpv') (bind_gpv gpv (\x. TRY f x ELSE gpv'))" + using lossless WT1 WTf +proof(coinduction arbitrary: gpv) + case (eq_\_gpv gpv) + note [simp] = spmf_rel_map generat.rel_map map_spmf_bind_spmf + and [intro!] = rel_spmf_reflI rel_generat_reflI rel_funI + show ?case using gen_lossless_gpvD[OF eq_\_gpv(1)] WT_gpvD[OF eq_\_gpv(2)] WT_gpvD[OF WT2] WT_gpvD[OF eq_\_gpv(3)[rule_format, OF results_gpv.Pure]] WT2 + apply(auto simp del: bind_gpv_sel' simp add: bind_gpv.sel try_spmf_bind_spmf_lossless generat.map_comp o_def intro!: rel_spmf_bind_reflI rel_spmf_try_spmf split!: generat.split) + apply(auto 4 4 intro!: eq_\_gpv(3)[rule_format] eq_\_gpv_reflI eq_\_generat_reflI intro: results_gpv.IO WT_intro) + done +qed + +\ \We instantiate the parameter @{term b} such that it can be used as a conditional simp rule.\ +lemmas try_gpv_bind_lossless' = try_gpv_bind_gen_lossless'[where b=False] + and try_gpv_bind_colossless' = try_gpv_bind_gen_lossless'[where b=True] + +lemma try_gpv_bind_gpv: + "try_gpv (bind_gpv gpv f) gpv' = + bind_gpv (try_gpv (map_gpv Some id gpv) (Done None)) (\x. case x of None \ gpv' | Some x' \ try_gpv (f x') gpv')" + by(coinduction arbitrary: gpv rule: gpv.coinduct_strong) + (auto simp add: rel_fun_def generat.rel_map bind_return_pmf spmf_rel_map map_bind_spmf o_def bind_gpv.sel bind_map_spmf try_spmf_def bind_spmf_def spmf.map_comp bind_map_pmf bind_assoc_pmf gpv.map_sel simp del: bind_gpv_sel' intro!: rel_pmf_bind_reflI generat.rel_refl_strong rel_spmf_reflI split!: option.split generat.split) + +lemma bind_gpv_try_gpv_map_Some: + "bind_gpv (try_gpv (map_gpv Some id gpv) (Done None)) (\x. case x of None \ Fail | Some y \ f y) = + bind_gpv gpv f" + by(coinduction arbitrary: gpv rule: gpv.coinduct_strong) + (auto simp add: bind_gpv.sel map_bind_spmf bind_map_spmf try_spmf_def bind_spmf_def spmf_rel_map bind_map_pmf gpv.map_sel bind_assoc_pmf bind_return_pmf generat.rel_map rel_fun_def simp del: bind_gpv_sel' intro!: rel_pmf_bind_reflI rel_spmf_reflI generat.rel_refl_strong split!: option.split generat.split) + +lemma try_gpv_left_gpv: + assumes "\ \g gpv \" and WT2: "\ \g gpv' \" + shows "eq_\_gpv (=) (\ \\<^sub>\ \') (try_gpv (left_gpv gpv) (left_gpv gpv')) (left_gpv (try_gpv gpv gpv'))" + using assms(1) + apply(coinduction arbitrary: gpv) + apply(auto simp add: map_try_spmf spmf.map_comp o_def generat.map_comp spmf_rel_map intro!: rel_spmf_try_spmf rel_spmf_reflI) + subgoal for gpv generat by(cases generat)(auto dest: WT_gpvD) + subgoal for gpv generat using WT2 + by(cases generat)(auto 4 4 dest: WT_gpvD intro!: eq_\_gpv_reflI WT_gpv_left_gpv) + done + +lemma try_gpv_right_gpv: + assumes "\' \g gpv \" and WT2: "\' \g gpv' \" + shows "eq_\_gpv (=) (\ \\<^sub>\ \') (try_gpv (right_gpv gpv) (right_gpv gpv')) (right_gpv (try_gpv gpv gpv'))" + using assms(1) + apply(coinduction arbitrary: gpv) + apply(auto simp add: map_try_spmf spmf.map_comp o_def generat.map_comp spmf_rel_map intro!: rel_spmf_try_spmf rel_spmf_reflI) + subgoal for gpv generat by(cases generat)(auto dest: WT_gpvD) + subgoal for gpv generat using WT2 + by(cases generat)(auto 4 4 dest: WT_gpvD intro!: eq_\_gpv_reflI WT_gpv_right_gpv) + done + +lemma bind_try_Done_Fail: "bind_gpv (TRY gpv ELSE Done x) f = bind_gpv gpv f" if "f x = Fail" + apply(coinduction arbitrary: gpv rule: gpv.coinduct_strong) + apply(auto simp del: bind_gpv_sel' simp add: bind_gpv.sel map_bind_spmf bind_map_spmf try_spmf_def bind_spmf_def map_bind_pmf bind_assoc_pmf bind_map_pmf bind_return_pmf spmf.map_comp o_def that rel_fun_def intro!: rel_pmf_bind_reflI rel_spmf_reflI generat.rel_refl_strong split!: option.split generat.split) + done + + +lemma inline_map_gpv': + "inline callee (map_gpv' f g h gpv) s = + map_gpv (apfst f) id (inline (map_fun id (map_fun g (map_gpv (apfst h) id)) callee) gpv s)" + using inline_parametric'[where S="(=)" and C="BNF_Def.Grp UNIV g" and R="conversep (BNF_Def.Grp UNIV h)" and A="BNF_Def.Grp UNIV f" and C'="(=)" and R'="(=)"] + apply(subst (asm) (2 3 8) eq_alt_conversep) + apply(subst (asm) (1 3 4 5) eq_alt) + apply(subst (asm) (1) eq_alt_conversep2) + apply(unfold prod.rel_conversep rel_gpv''_conversep prod.rel_Grp rel_gpv''_Grp) + apply(force simp add: rel_fun_def Grp_def map_gpv_conv_map_gpv' map_fun_def[abs_def] o_def apfst_def) + done + +lemma interaction_bound_try_gpv: + fixes "consider" defines "ib \ interaction_bound consider" + shows "interaction_bound consider (try_gpv gpv gpv') \ ib gpv + ib gpv'" +proof(induction arbitrary: gpv gpv' rule: interaction_bound_fixp_induct) + case adm show ?case by simp + case bottom show ?case by simp + case (step interaction_bound') + show ?case unfolding ib_def + apply(clarsimp simp add: generat.map_comp image_image o_def case_map_generat cong del: generat.case_cong split!: if_split generat.split intro!: SUP_least) + subgoal + apply(subst interaction_bound.simps) + apply simp + apply(subst Sup_image_eadd1[symmetric]) + apply clarsimp + apply(rule SUP_upper2) + apply(rule rev_image_eqI) + apply simp + apply simp + apply(simp add: iadd_Suc) + apply(subst Sup_image_eadd1[symmetric]) + apply simp + apply(rule SUP_mono) + apply simp + apply(rule exI) + apply(rule step.IH[unfolded ib_def]) + done + subgoal + apply(subst interaction_bound.simps) + apply simp + apply(subst Sup_image_eadd1[symmetric]) + apply clarsimp + apply(rule SUP_upper2) + apply(rule rev_image_eqI) + apply simp + apply simp + apply(subst Sup_image_eadd1[symmetric]) + apply simp + apply(rule SUP_upper2) + apply(rule rev_image_eqI) + apply simp + apply simp + apply(rule step.IH[unfolded ib_def]) + done + subgoal + apply(subst interaction_bound.simps) + apply simp + apply(subst Sup_image_eadd1[symmetric]) + apply clarsimp + apply(rule SUP_upper2) + apply(rule rev_image_eqI) + apply simp + apply simp + apply(simp add: iadd_Suc) + apply(subst Sup_image_eadd1[symmetric]) + apply simp + apply(rule SUP_mono) + apply simp + apply(rule exI) + apply(rule step.IH[unfolded ib_def]) + done + subgoal + apply(subst interaction_bound.simps) + apply simp + apply(subst Sup_image_eadd1[symmetric]) + apply clarsimp + apply(rule SUP_upper2) + apply(rule rev_image_eqI) + apply simp + apply simp + apply(subst Sup_image_eadd1[symmetric]) + apply simp + apply(rule SUP_upper2) + apply(rule rev_image_eqI) + apply simp + apply simp + apply(rule step.IH[unfolded ib_def]) + done + subgoal + apply(subst (2) interaction_bound.simps) + apply simp + apply(subst Sup_image_eadd2[symmetric]) + apply clarsimp + apply simp + apply(rule SUP_upper2) + apply(rule rev_image_eqI) + apply simp + apply simp + apply(simp add: iadd_Suc_right) + apply(subst Sup_image_eadd2[symmetric]) + apply clarsimp + apply(rule SUP_mono) + apply clarsimp + apply(rule exI) + apply(rule order_trans) + apply(rule step.hyps) + apply(rule enat_le_plus_same) + done + subgoal + apply(subst (2) interaction_bound.simps) + apply simp + apply(subst Sup_image_eadd2[symmetric]) + apply clarsimp + apply simp + apply(rule SUP_upper2) + apply(rule rev_image_eqI) + apply simp + apply simp + apply(subst Sup_image_eadd2[symmetric]) + apply clarsimp + apply(rule SUP_upper2) + apply(rule imageI) + apply simp + apply(rule order_trans) + apply(rule step.hyps) + apply(rule enat_le_plus_same) + done + done +qed + +lemma interaction_bounded_by_try_gpv [interaction_bound]: + "interaction_bounded_by consider (try_gpv gpv1 gpv2) (bound1 + bound2)" + if "interaction_bounded_by consider gpv1 bound1" "interaction_bounded_by consider gpv2 bound2" + using that interaction_bound_try_gpv[of "consider" gpv1 gpv2] + by(simp add: interaction_bounded_by.simps)(meson add_left_mono_trans add_right_mono le_left_mono) + + +subsection \term \gpv_stop\\ + +lemma interaction_bounded_by_gpv_stop [interaction_bound]: + assumes "interaction_bounded_by consider gpv n" + shows "interaction_bounded_by consider (gpv_stop gpv) n" + using assms by(simp add: interaction_bounded_by.simps) + +context includes \.lifting begin + +lift_definition stop_\ :: "('a, 'b) \ \ ('a, 'b option) \" is + "\resp x. if (resp x = {}) then {} else insert None (Some ` resp x)" . + +lemma outs_stop_\ [simp]: "outs_\ (stop_\ \) = outs_\ \" + by transfer auto + +lemma responses_stop_\ [simp]: + "responses_\ (stop_\ \) x = (if x \ outs_\ \ then insert None (Some ` responses_\ \ x) else {})" + by transfer auto + +lemma stop_\_full [simp]: "stop_\ \_full = \_full" + by transfer(auto simp add: fun_eq_iff notin_range_Some) + +lemma stop_\_uniform [simp]: + "stop_\ (\_uniform A B) = (if B = {} then \ else \_uniform A (insert None (Some ` B)))" + unfolding bot_\_def by transfer(simp add: fun_eq_iff) + +lifting_update \.lifting +lifting_forget \.lifting + +end + +lemma stop_\_bot [simp]: "stop_\ \ = \" + by(simp only: bot_\_def stop_\_uniform)(simp) + +lemma WT_gpv_stop [simp, WT_intro]: "stop_\ \ \g gpv_stop gpv \" if "\ \g gpv \" + using that by(coinduction arbitrary: gpv)(auto 4 3 dest: WT_gpvD) + +lemma expectation_gpv_stop: + fixes fail and gpv :: "('a, 'b, 'c) gpv" + assumes WT: "\ \g gpv \" + and fail: "fail \ c" + shows "expectation_gpv fail (stop_\ \) (\_. c) (gpv_stop gpv) = expectation_gpv fail \ (\_. c) gpv" (is "?lhs = ?rhs") +proof(rule antisym) + show "expectation_gpv fail (stop_\ \) (\_. c) (gpv_stop gpv) \ expectation_gpv fail \ (\_. c) gpv" + using WT + proof(induction arbitrary: gpv rule: parallel_fixp_induct_1_1[OF complete_lattice_partial_function_definitions complete_lattice_partial_function_definitions expectation_gpv.mono expectation_gpv.mono expectation_gpv_def expectation_gpv_def, case_names adm bottom step]) + case adm show ?case by simp + case bottom show ?case by simp + case (step f g) + then show ?case + apply(simp add: pmf_map_spmf_None measure_spmf_return_spmf nn_integral_return) + apply(rule disjI2 nn_integral_mono_AE)+ + apply(auto split!: generat.split simp add: image_image dest: WT_gpvD intro!: le_infI2 INF_mono) + done + qed + + define stop :: "('a option, 'b, 'c option) gpv \ _" where "stop = expectation_gpv fail (stop_\ \) (\_. c)" + show "?rhs \ stop (gpv_stop gpv)" using WT + proof(induction arbitrary: gpv rule: expectation_gpv_fixp_induct) + case adm show ?case by simp + case bottom show ?case by simp + case (step expectation_gpv') + have "expectation_gpv' gpv' \ c" if "\ \g gpv' \" for gpv' + using expectation_gpv_const_le[of \ gpv' fail c] fail step.hyps(1)[of gpv'] that + by(simp add: max_def split: if_split_asm) + then show ?case using step unfolding stop_def + apply(subst expectation_gpv.simps) + apply(simp add: pmf_map_spmf_None) + apply(rule disjI2 nn_integral_mono_AE)+ + apply(clarsimp split!: generat.split simp add: image_image) + subgoal by(auto 4 3 simp add: in_outs_\_iff_responses_\ dest: WT_gpv_ContD intro: INF_lower2) + subgoal by(auto intro!: INF_mono rev_bexI dest: WT_gpvD) + done + qed +qed + +lemma pgen_lossless_gpv_stop: + fixes fail and gpv :: "('a, 'b, 'c) gpv" + assumes WT: "\ \g gpv \" + and fail: "fail \ 1" + shows "pgen_lossless_gpv fail (stop_\ \) (gpv_stop gpv) = pgen_lossless_gpv fail \ gpv" + by(simp add: pgen_lossless_gpv_def expectation_gpv_stop assms) + +lemma pfinite_gpv_stop [simp]: + "pfinite_gpv (stop_\ \) (gpv_stop gpv) \ pfinite_gpv \ gpv" if "\ \g gpv \" + using that by(simp add: pgen_lossless_gpv_stop) + +lemma plossless_gpv_stop [simp]: + "plossless_gpv (stop_\ \) (gpv_stop gpv) \ plossless_gpv \ gpv" if "\ \g gpv \" + using that by(simp add: pgen_lossless_gpv_stop) + +lemma results_gpv_stop_SomeD: "Some x \ results_gpv (stop_\ \) (gpv_stop gpv) \ x \ results_gpv \ gpv" + by(induction gpv'\"gpv_stop gpv" arbitrary: gpv rule: results_gpv.induct) + (auto 4 3 intro: results_gpv.intros split: if_split_asm) + +lemma Some_in_results'_gpv_gpv_stopD: "Some xy \ results'_gpv (gpv_stop gpv) \ xy \ results'_gpv gpv" + unfolding results_gpv_\_full[symmetric] + by(rule results_gpv_stop_SomeD) simp + +subsection \term \exception_\\\ + +datatype 's exception = Fault | OK (ok: 's) + +lemma inj_on_OK [simp]: "inj_on OK A" + by(auto simp add: inj_on_def) + +function join_exception :: "'a exception \ 'b exception \ ('a \ 'b) exception" where + "join_exception Fault _ = Fault" +| "join_exception _ Fault = Fault" +| "join_exception (OK a) (OK b) = OK (a, b)" + by pat_completeness auto +termination by lexicographic_order + +primrec merge_exception :: "'a exception + 'b exception \ ('a + 'b) exception" where + "merge_exception (Inl x) = map_exception Inl x" +| "merge_exception (Inr y) = map_exception Inr y" + +fun option_of_exception :: "'a exception \ 'a option" where + "option_of_exception Fault = None" +| "option_of_exception (OK x) = Some x" + +fun exception_of_option :: "'a option \ 'a exception" where + "exception_of_option None = Fault" +| "exception_of_option (Some x) = OK x" + + +lemma option_of_exception_exception_of_option [simp]: "option_of_exception (exception_of_option x) = x" + by(cases x) simp_all + +lemma exception_of_option_option_of_exception [simp]: "exception_of_option (option_of_exception x) = x" + by(cases x) simp_all + +lemma case_exception_of_option [simp]: "case_exception f g (exception_of_option x) = case_option f g x" + by(simp split: exception.split option.split) + +lemma case_option_of_exception [simp]: "case_option f g (option_of_exception x) = case_exception f g x" + by(simp split: exception.split option.split) + +lemma surj_exception_of_option [simp]: "surj exception_of_option" + by(rule surjI[where f="option_of_exception"])(simp) + +lemma surj_option_of_exception [simp]: "surj option_of_exception" + by(rule surjI[where f="exception_of_option"])(simp) + +lemma case_map_exception [simp]: "case_exception f g (map_exception h x) = case_exception f (g \ h) x" + by(simp split: exception.split) + +definition exception_\ :: "('a, 'b) \ \ ('a, 'b exception) \" where + "exception_\ \ = map_\ id exception_of_option (stop_\ \)" + +lemma outs_exception_\ [simp]: "outs_\ (exception_\ \) = outs_\ \" + by(simp add: exception_\_def) + +lemma responses_exception_\ [simp]: + "responses_\ (exception_\ \) x = (if x \ outs_\ \ then insert Fault (OK ` responses_\ \ x) else {})" + by(simp add: exception_\_def image_image) + +lemma map_\_full [simp]: "map_\ f g \_full = \_uniform UNIV (range g)" + unfolding \_uniform_UNIV[symmetric] map_\_\_uniform by simp + +lemma exception_\_full [simp]: "exception_\ \_full = \_full" + unfolding exception_\_def by simp + +lemma exception_\_uniform [simp]: + "exception_\ (\_uniform A B) = (if B = {} then \ else \_uniform A (insert Fault (OK ` B)))" + by(simp add: exception_\_def image_image) + +lemma option_of_exception_\ [simp]: "map_\ id option_of_exception (exception_\ \) = stop_\ \" + by(simp add: exception_\_def o_def id_def[symmetric]) + +lemma exception_of_option_\ [simp]: "map_\ id exception_of_option (stop_\ \) = exception_\ \" + by(simp add: exception_\_def) + +subsection \inline\ + +context raw_converter_invariant begin + +context + fixes gpv :: "('a, 'call, 'ret) gpv" + assumes gpv: "plossless_gpv \ gpv" "\ \g gpv \" +begin + +lemma lossless_spmf_inline1: + assumes lossless: "\s x. \ x \ outs_\ \; I s \ \ lossless_spmf (the_gpv (callee s x))" + and I: "I s" + shows "lossless_spmf (inline1 callee gpv s)" +proof - + have "1 = expectation_gpv 0 \ (\_. 1) gpv" using gpv by(simp add: pgen_lossless_gpv_def) + also have "\ \ weight_spmf (inline1 callee gpv s)" using gpv(2) I + proof(induction arbitrary: gpv s rule: expectation_gpv_fixp_induct) + case adm show ?case by simp + case bottom show ?case by simp + case (step expectation_gpv') + { fix out c + assume IO: "IO out c \ set_spmf (the_gpv gpv)" + with step.prems have out: "out \ outs_\ \" by(auto dest: WT_gpvD) + from out[unfolded in_outs_\_iff_responses_\] obtain input where input: "input \ responses_\ \ out" by auto + from out have "(\r\responses_\ \ out. expectation_gpv' (c r)) = \\<^sup>+ x. (\r\responses_\ \ out. expectation_gpv' (c r)) \measure_spmf (the_gpv (callee s out))" + using lossless \I s\ by(simp add: lossless_spmf_def measure_spmf.emeasure_eq_measure) + also have "\ \ \\<^sup>+ generat. (case generat of Pure (r, s') \ weight_spmf (inline1 callee (c r) s') | _ \ 1) \measure_spmf (the_gpv (callee s out))" + apply(intro nn_integral_mono_AE) + apply(clarsimp split!: generat.split) + subgoal Pure + apply(rule INF_lower2) + apply(fastforce dest: results_callee[OF out \I s\, THEN subsetD, OF results_gpv.Pure]) + apply(rule step.IH) + apply(fastforce intro: WT_gpvD[OF step.prems(1) IO] dest: results_callee[OF out \I s\, THEN subsetD, OF results_gpv.Pure]) + apply(fastforce dest: results_callee[OF out \I s\, THEN subsetD, OF results_gpv.Pure]) + done + subgoal IO + apply(rule INF_lower2[OF input]) + apply(rule order_trans) + apply(rule step.hyps) + apply(rule order_trans) + apply(rule expectation_gpv_const_le) + apply(rule WT_gpvD[OF step.prems(1) IO]) + apply(simp_all add: input) + done + done + finally have "(\r\responses_\ \ out. expectation_gpv' (c r)) \ \" . } + then show ?case using step.prems + apply(subst inline1.simps) + apply(simp add: measure_spmf.emeasure_eq_measure[symmetric]) + apply(simp add: measure_spmf_bind) + apply(subst emeasure_bind[where N="count_space UNIV"]) + apply(simp add: space_measure_spmf) + apply(simp add: o_def) + apply(simp) + apply(rule nn_integral_mono_AE) + apply(clarsimp split!: generat.split simp add: measure_spmf_return_spmf space_measure_spmf) + apply(simp add: measure_spmf_bind) + apply(subst emeasure_bind[where N="count_space UNIV"]) + apply(simp add: space_measure_spmf) + apply(simp add: o_def) + apply(simp) + apply (simp add: measure_spmf.emeasure_eq_measure) + apply(subst generat.case_distrib[where h="\x. measure (measure_spmf x) _"]) + apply(simp add: split_def measure_spmf_return_spmf space_measure_spmf measure_return cong del: generat.case_cong) + done + qed + finally show ?thesis using weight_spmf_le_1[of "inline1 callee gpv s"] by(simp add: lossless_spmf_def) +qed + +end + +end + +lemma (in raw_converter_invariant) inline1_try_gpv: + defines "inline1' \ inline1" + assumes WT: "\ \g gpv \" + and pfinite: "pfinite_gpv \ gpv" + and f: "\s. I s \ f (x, s) = z" + and lossless: "\s x. \ x \ outs_\ \; I s \ \ colossless_gpv \' (callee s x)" + and I: "I s" + shows "map_spmf (map_sum f id) (inline1 callee (try_gpv gpv (Done x)) s) = + try_spmf (map_spmf (map_sum f (\(out, c, rpv). (out, c, \input. try_gpv (rpv input) (Done x)))) (inline1' callee gpv s)) (return_spmf (Inl z))" + (is "?lhs = ?rhs") +proof - + have le: "ord_spmf (=) ?lhs ?rhs" using WT I + proof(induction arbitrary: gpv s rule: inline1_fixp_induct) + case adm show ?case by simp + case bottom show ?case by simp + case (step inline1'') + show ?case using step.prems unfolding inline1'_def + apply(subst inline1.simps) + apply(simp add: bind_map_spmf map_bind_spmf o_def) + apply(simp add: try_spmf_def) + apply(subst bind_spmf_pmf_assoc) + apply(simp add: bind_map_pmf) + apply(subst (3) bind_spmf_def) + apply(simp add: bind_assoc_pmf) + apply(rule rel_pmf_bindI[where R="eq_onp (\x. x \ set_pmf (the_gpv gpv))"]) + apply(rule pmf.rel_refl_strong) + apply(simp add: eq_onp_def) + apply(clarsimp simp add: eq_onp_def bind_return_pmf f split!: option.split generat.split) + subgoal for out c + apply(simp add: in_set_spmf[symmetric] bind_map_pmf map_bind_spmf) + apply(subst option.case_distrib[where h=return_pmf, symmetric, abs_def]) + apply(fold map_pmf_def) + apply(simp add: bind_spmf_def map_bind_pmf) + apply(rule rel_pmf_bindI[where R="eq_onp (\x. x \ set_pmf (the_gpv (callee s out)))"]) + apply(rule pmf.rel_refl_strong) + apply(simp add: eq_onp_def) + apply(simp add: in_set_spmf[symmetric] bind_map_pmf map_bind_spmf eq_onp_def split!: option.split generat.split) + apply(rule spmf.leq_trans) + apply(rule step.IH[unfolded inline1'_def]) + subgoal + by(auto dest: results_callee[THEN subsetD, OF _ _ results_gpv.Pure, rotated -1] WT_gpvD) + subgoal + by(auto dest: results_callee[THEN subsetD, OF _ _ results_gpv.Pure, rotated -1] WT_gpvD) + apply(simp add: try_spmf_def) + apply(subst option.case_distrib[where h=return_pmf, symmetric, abs_def]) + apply(fold map_pmf_def) + apply simp + done + done + qed + have "lossless_spmf ?lhs" using I + apply simp + apply(rule lossless_spmf_inline1) + apply(rule plossless_gpv_try_gpvI) + apply(rule pfinite) + apply simp + apply(rule WT_gpv_try_gpvI) + apply(rule WT) + apply simp + apply(rule colossless_gpv_lossless_spmfD[OF lossless]) + apply simp_all + done + from ord_spmf_lossless_spmfD1[OF le this] show ?thesis by(simp add: spmf_rel_eq) +qed + +lemma (in raw_converter_invariant) inline_try_gpv: + assumes WT: "\ \g gpv \" + and pfinite: "pfinite_gpv \ gpv" + and f: "\s. I s \ f (x, s) = z" + and lossless: "\s x. \ x \ outs_\ \; I s \ \ colossless_gpv \' (callee s x)" + and I: "I s" + shows "eq_\_gpv (=) \' (map_gpv f id (inline callee (try_gpv gpv (Done x)) s)) (try_gpv (map_gpv f id (inline callee gpv s)) (Done z))" + (is "eq_\_gpv _ _ ?lhs ?rhs") + using WT pfinite I +proof(coinduction arbitrary: gpv s rule: eq_\_gpv_coinduct_bind) + case (eq_\_gpv gpv s) + show "?case TYPE(('ret \ 's) option) TYPE(('ret \ 's) option)" (is "rel_spmf (eq_\_generat _ _ ?X) ?lhs ?rhs") + proof - + have "?lhs = map_spmf + (\x. case x of Inl rs \ Pure rs | Inr (out, oracle, rpv) \ IO out (\input. + map_gpv f id (bind_gpv (try_gpv (map_gpv Some id (oracle input)) (Done None)) (\xy. case xy of None \ Fail | Some (x, y) \ inline callee (rpv x) y)))) + (map_spmf (map_sum f id) (inline1 callee (TRY gpv ELSE Done x) s))" + (is "_ = map_spmf ?f ?lhs2") + by(auto simp add: gpv.map_sel inline_sel spmf.map_comp o_def bind_gpv_try_gpv_map_Some intro!: map_spmf_cong[OF refl] split: sum.split) + also from eq_\_gpv + have "?lhs2 = TRY map_spmf (map_sum f (\(out, c, rpv). (out, c, \input. TRY rpv input ELSE Done x))) (inline1 callee gpv s) ELSE return_spmf (Inl z)" + by(intro inline1_try_gpv)(auto intro: f lossless) + also have "\ = map_spmf (\y. case y of None \ Inl z | Some x' \ map_sum f (\(out, c, rpv). (out, c, \input. try_gpv (rpv input) (Done x))) x') + (try_spmf (map_spmf Some (inline1 callee gpv s)) (return_spmf None))" + (is "_ = ?lhs3") by(simp add: map_try_spmf spmf.map_comp o_def) + also have "?rhs = map_spmf (\y. case y of None \ Pure z | Some (Inl x) \ Pure (f x) + | Some (Inr (out, oracle, rpv)) \ IO out (\input. try_gpv (map_gpv f id (bind_gpv (oracle input) (\(x, y). inline callee (rpv x) y))) (Done z))) + (try_spmf (map_spmf Some (inline1 callee gpv s)) (return_spmf None))" + by(auto simp add: gpv.map_sel inline_sel spmf.map_comp o_def generat.map_comp spmf_rel_map map_try_spmf intro!: try_spmf_cong map_spmf_cong split: sum.split) + moreover have "rel_spmf (eq_\_generat (=) \' ?X) (map_spmf ?f ?lhs3) \" + apply(clarsimp simp add: gpv.map_sel inline_sel spmf.map_comp o_def generat.map_comp spmf_rel_map intro!: rel_spmf_reflI) + apply(erule disjE) + subgoal + apply(clarsimp split!: generat.split sum.split simp add: map_gpv_id_bind_gpv) + apply(subst (3) try_gpv_bind_gpv) + apply(rule conjI) + apply(erule WT_gpv_inline1[OF _ eq_\_gpv(1,3)]) + apply(rule strip)+ + apply(rule disjI2)+ + subgoal for out rpv rpv' input + apply(rule exI) + apply(rule exI) + apply(rule exI[where x="\x y. x = y \ y \ results_gpv \' (TRY map_gpv Some id (rpv input) ELSE Done None)"]) + apply(rule exI conjI refl)+ + apply(rule eq_\_gpv_reflI) + apply(simp add: eq_onp_def) + apply(rule WT_intro) + apply simp + apply(erule (1) WT_gpv_inline1[OF _ eq_\_gpv(1,3)]) + apply simp + apply(rule rel_funI) + apply(clarsimp simp add: eq_onp_def split: if_split_asm) + subgoal + apply(rule exI conjI refl)+ + apply(drule (2) WT_gpv_inline1(3)[OF _ eq_\_gpv(1,3)]) + apply simp + apply(frule (2) WT_gpv_inline1(3)[OF _ eq_\_gpv(1,3)]) + apply(drule (2) inline1_in_sub_gpvs[OF _ _ _ eq_\_gpv(1,3)]) + apply clarsimp + apply(erule pfinite_gpv_sub_gpvs[OF eq_\_gpv(2) _ eq_\_gpv(1)]) + done + subgoal + apply(erule disjE; clarsimp) + apply(rule exI conjI refl)+ + apply(drule (2) WT_gpv_inline1(3)[OF _ eq_\_gpv(1,3)]) + apply simp + apply(frule (2) WT_gpv_inline1(3)[OF _ eq_\_gpv(1,3)]) + apply(drule (2) inline1_in_sub_gpvs[OF _ _ _ eq_\_gpv(1,3)]) + apply clarsimp + apply(erule pfinite_gpv_sub_gpvs[OF eq_\_gpv(2) _ eq_\_gpv(1)]) + apply(erule notE) + apply(drule inline1_in_sub_gpvs_callee[OF _ eq_\_gpv(1,3)]) + apply clarify + apply(drule (1) bspec) + apply(erule colossless_gpv_sub_gpvs[rotated]) + apply(rule lossless; simp) + done + done + done + subgoal by(clarsimp split: if_split_asm) + done + ultimately show ?thesis by(simp only:) + qed +qed + + +definition cr_prod2 :: "'a \ ('b \ 'c \ bool) \ 'b \ 'a \ 'c \ bool" where + "cr_prod2 x A = (\b (a, c). A b c \ x = a)" + +lemma cr_prod2_simps [simp]: "cr_prod2 x A a (b, c) \ A a c \ x = b" +by(simp add: cr_prod2_def) + +lemma cr_prod2I: "A a b \ cr_prod2 x A a (x, b)" by simp + +lemma cr_prod2_Grp: "cr_prod2 x (BNF_Def.Grp A f) = BNF_Def.Grp A (\b. (x, f b))" +by(auto simp add: Grp_def fun_eq_iff) + +(* A stronger version of the existing extend_state_oracle_transfer *) +lemma extend_state_oracle_transfer': includes lifting_syntax shows + "((S ===> C ===> rel_spmf (rel_prod R S)) ===> cr_prod2 s S ===> C ===> rel_spmf (rel_prod R (cr_prod2 s S))) (\oracle. oracle) extend_state_oracle" +unfolding extend_state_oracle_def[abs_def] +apply(rule rel_funI)+ +apply clarsimp +apply(drule (1) rel_funD)+ +apply(auto simp add: spmf_rel_map split_def dest: rel_funD intro: rel_spmf_mono) +done + +(* @Reza: This is a proof based on parametricity, + using the relation cr_prod2 s (=) to fix the first component of the extended callee state to s *) + +lemma exec_gpv_extend_state_oracle: + "exec_gpv (extend_state_oracle callee) gpv (s, s') = + map_spmf (\(x, s''). (x, (s, s''))) (exec_gpv callee gpv s')" + using exec_gpv_parametric'[THEN rel_funD, OF extend_state_oracle_transfer'[THEN rel_funD], of "(=)" "(=)" "(=)" callee callee "(=)" s] + unfolding relator_eq rel_gpv''_eq + apply(clarsimp simp add: rel_fun_def) + apply(unfold eq_alt cr_prod2_Grp prod.rel_Grp option.rel_Grp pmf.rel_Grp) + apply(simp add: Grp_def map_prod_def) + apply(blast intro: sym) + done + + + + + +section \Material for Constructive Crypto\ + +lemma WT_resource_\_uniform_UNIV [simp]: "\_uniform A UNIV \res res \" + by(coinduction arbitrary: res) auto + +lemma WT_converter_of_callee_invar: + assumes WT: "\s q. \ q \ outs_\ \; I s \ \ \' \g callee s q \" + and res: "\s q r s'. \ (r, s') \ results_gpv \' (callee s q); q \ outs_\ \; I s \ \ r \ responses_\ \ q \ I s'" + and I: "I s" + shows "\, \' \\<^sub>C converter_of_callee callee s \" + using I by(coinduction arbitrary: s)(auto simp add: WT res) + +lemma eq_\_gpv_eq_OO: + assumes "eq_\_gpv (=) \ gpv gpv'" "eq_\_gpv A \ gpv' gpv''" + shows "eq_\_gpv A \ gpv gpv''" + using eq_\_gpv_relcompp[THEN fun_cong, THEN fun_cong, THEN iffD2, OF relcomppI, OF assms] + by(simp add: eq_OO) + +lemma eq_\_gpv_eq_OO2: + assumes "eq_\_gpv (=) \ gpv'' gpv'" "eq_\_gpv A \ gpv gpv'" + shows "eq_\_gpv A \ gpv gpv''" + using eq_\_gpv_relcompp[where A'="conversep (=)", THEN fun_cong, THEN fun_cong, THEN iffD2, OF relcomppI, OF assms(2)] assms(1) + unfolding eq_\_gpv_conversep by(simp add: OO_eq) + +lemma eq_\_gpv_try_gpv_cong: + assumes "eq_\_gpv A \ gpv1 gpv1'" + and "eq_\_gpv A \ gpv2 gpv2'" + shows "eq_\_gpv A \ (try_gpv gpv1 gpv2) (try_gpv gpv1' gpv2')" + using assms(1) + apply(coinduction arbitrary: gpv1 gpv1') + using assms(2) + apply(fastforce simp add: spmf_rel_map intro!: rel_spmf_try_spmf dest: eq_\_gpvD elim!: rel_spmf_mono_strong eq_\_generat.cases) + done + +lemma eq_\_gpv_map_gpv': + assumes "eq_\_gpv (BNF_Def.vimage2p f f' A) (map_\ g h \) gpv1 gpv2" + shows "eq_\_gpv A \ (map_gpv' f g h gpv1) (map_gpv' f' g h gpv2)" + using assms +proof(coinduction arbitrary: gpv1 gpv2) + case eq_\_gpv + from this[THEN eq_\_gpvD] show ?case + apply(simp add: spmf_rel_map) + apply(erule rel_spmf_mono) + apply(auto 4 4 simp add: BNF_Def.vimage2p_def elim!: eq_\_generat.cases) + done +qed + +lemma eq_\_converter_map_converter: + assumes "map_\ (inv_into UNIV f) (inv_into UNIV g) \, map_\ f' g' \' \\<^sub>C conv1 \ conv2" + and "inj f" "surj g" + shows "\, \' \\<^sub>C map_converter f g f' g' conv1 \ map_converter f g f' g' conv2" + using assms(1) +proof(coinduction arbitrary: conv1 conv2) + case eq_\_converter + from this(2) have "f q \ outs_\ (map_\ (inv_into UNIV f) (inv_into UNIV g) \)" using assms(2) by simp + from eq_\_converter(1)[THEN eq_\_converterD, OF this] show ?case using assms(2,3) + apply simp + apply(rule eq_\_gpv_map_gpv') + apply(simp add: BNF_Def.vimage2p_def prod.rel_map) + apply(erule eq_\_gpv_mono') + apply(auto 4 4 simp add: eq_onp_def surj_f_inv_f) + done +qed + +lemma resource_of_oracle_run_resource: "resource_of_oracle run_resource res = res" + by(coinduction arbitrary: res)(auto simp add: rel_fun_def spmf_rel_map intro!: rel_spmf_reflI) + +lemma connect_map_gpv': + "connect (map_gpv' f g h adv) res = map_spmf f (connect adv (map_resource g h res))" + unfolding connect_def + by(subst (3) resource_of_oracle_run_resource[symmetric]) + (simp add: exec_gpv_map_gpv' map_resource_resource_of_oracle spmf.map_comp exec_gpv_resource_of_oracle) + +primcorec fail_resource :: "('a, 'b) resource" where + "run_resource fail_resource = (\_. return_pmf None)" + +lemma WT_fail_resource [WT_intro]: "\ \res fail_resource \" + by(rule WT_resourceI) simp + +context fixes y :: "'b" begin + +primcorec const_resource :: "('a, 'b) resource" where + "run_resource const_resource = (\_. map_spmf (map_prod id (\_. const_resource)) (return_spmf (y, ())))" + +end + +lemma const_resource_sel [simp]: "run_resource (const_resource y) = (\_. return_spmf (y, const_resource y))" + by simp + +declare const_resource.sel [simp del] + +lemma lossless_const_resource [simp]: "lossless_resource \ (const_resource y)" + by(coinduction) simp + +lemma WT_const_resource [simp]: + "\ \res const_resource y \ \ (\x\outs_\ \. y \ responses_\ \ x)" (is "?lhs \ ?rhs") +proof(intro iffI ballI) + show "y \ responses_\ \ x" if ?lhs and "x \ outs_\ \" for x using WT_resourceD[OF that] by auto + show ?lhs if ?rhs using that by(coinduction)(auto) +qed + +context fixes y :: "'b" begin + +primcorec const_converter :: "('a, 'b, 'c, 'd) converter" where + "run_converter const_converter = (\_. map_gpv (map_prod id (\_. const_converter)) id (Done (y, ())))" + +end + +lemma const_converter_sel [simp]: "run_converter (const_converter y) = (\_. Done (y, const_converter y))" + by simp + +lemma attach_const_converter [simp]: "attach (const_converter y) res = const_resource y" + by(coinduction)(simp add: rel_fun_def) + +declare const_converter.sel [simp del] + +lemma comp_const_converter [simp]: "comp_converter (const_converter x) conv = const_converter x" + by(coinduction)(simp add: rel_fun_def) + +lemma interaction_bounded_const_converter [simp, interaction_bound]: + "interaction_any_bounded_converter (const_converter Fault) bound" + by(coinduction) simp + + +primcorec merge_exception_converter :: "('a, ('b + 'c) exception, 'a, 'b exception + 'c exception) converter" where + "run_converter merge_exception_converter = + (\x. map_gpv (map_prod id (\conv. case conv of None \ merge_exception_converter | Some conv' \ conv')) id ( + Pause x (\y. Done (case merge_exception y of Fault \ (Fault, Some (const_converter Fault)) + | OK y' \ (OK y', None)))))" + +lemma merge_exception_converter_sel [simp]: + "run_converter merge_exception_converter x = + Pause x (\y. Done (case merge_exception y of Fault \ (Fault, const_converter Fault) | OK y' \ (OK y', merge_exception_converter)))" + by(simp add: o_def fun_eq_iff split: exception.split) + +declare merge_exception_converter.sel[simp del] + +lemma plossless_const_converter[simp]: "plossless_converter \ \' (const_converter x)" + by(coinduction) auto + +lemma plossless_merge_exception_converter [simp]: + "plossless_converter (exception_\ (\ \\<^sub>\ \')) (exception_\ \ \\<^sub>\ exception_\ \') merge_exception_converter" + by(coinduction) auto + +lemma WT_const_converter [WT_intro, simp]: + "\, \' \\<^sub>C const_converter x \" if "\q \ outs_\ \. x \ responses_\ \ q" + by(coinduction)(auto simp add: that) + +lemma WT_merge_exception_converter [WT_intro, simp]: + "exception_\ (\1' \\<^sub>\ \2'), exception_\ \1' \\<^sub>\ exception_\ \2' \\<^sub>C merge_exception_converter \" + by(coinduction) auto + +lemma inline_left_gpv_merge_exception_converter: + "bind_gpv (inline run_converter (map_gpv' id id option_of_exception (gpv_stop (left_gpv gpv))) merge_exception_converter) (\(x, conv'). case x of None \ Fail | Some x' \ Done (x, conv')) = + bind_gpv (left_gpv (map_gpv' id id option_of_exception (gpv_stop gpv))) (\x. case x of None \ Fail | Some x' \ Done (x, merge_exception_converter))" + apply(coinduction arbitrary: gpv rule: gpv.coinduct_strong) + apply(simp add: bind_gpv.sel inline_sel map_bind_spmf bind_map_spmf del: bind_gpv_sel') + apply(subst inline1_unfold) + apply(clarsimp simp add: bind_map_spmf intro!: rel_spmf_bind_reflI simp add: generat.map_comp case_map_generat o_def split!: generat.split intro!: rel_funI) + subgoal for gpv out c input by(cases input; auto split!: exception.split) + done + +lemma inline_right_gpv_merge_exception_converter: + "bind_gpv (inline run_converter (map_gpv' id id option_of_exception (gpv_stop (right_gpv gpv))) merge_exception_converter) (\(x, conv'). case x of None \ Fail | Some x' \ Done (x, conv')) = + bind_gpv (right_gpv (map_gpv' id id option_of_exception (gpv_stop gpv))) (\x. case x of None \ Fail | Some x' \ Done (x, merge_exception_converter))" + apply(coinduction arbitrary: gpv rule: gpv.coinduct_strong) + apply(simp add: bind_gpv.sel inline_sel map_bind_spmf bind_map_spmf del: bind_gpv_sel') + apply(subst inline1_unfold) + apply(clarsimp simp add: bind_map_spmf intro!: rel_spmf_bind_reflI simp add: generat.map_comp case_map_generat o_def split!: generat.split intro!: rel_funI) + subgoal for gpv out c input by(cases input; auto split!: exception.split) + done + +subsection \@{theory Constructive_Cryptography.Wiring}\ + +abbreviation (input) + id_wiring :: "('a, 'b, 'a, 'b) wiring" ("1\<^sub>w") + where + "id_wiring \ (id, id)" + +definition + swap_lassocr\<^sub>w :: "('a + 'b + 'c, 'd + 'e + 'f, 'b + 'a + 'c, 'e + 'd + 'f) wiring" + where + "swap_lassocr\<^sub>w \ rassocl\<^sub>w \\<^sub>w ((swap\<^sub>w |\<^sub>w 1\<^sub>w) \\<^sub>w lassocr\<^sub>w)" + +schematic_goal + wiring_swap_lassocr[wiring_intro]: "wiring ?\1 ?\2 swap_lassocr swap_lassocr\<^sub>w" + unfolding swap_lassocr_def swap_lassocr\<^sub>w_def + by(rule wiring_intro)+ + +definition + parallel_wiring\<^sub>w :: "(('a + 'b) + ('c + 'd), ('e + 'f) + ('g + 'h), + ('a + 'c) + ('b + 'd), ('e + 'g) + ('f + 'h)) wiring" + where + "parallel_wiring\<^sub>w \ lassocr\<^sub>w \\<^sub>w ((1\<^sub>w |\<^sub>w swap_lassocr\<^sub>w) \\<^sub>w rassocl\<^sub>w)" + +schematic_goal + wiring_parallel_wiring[wiring_intro]: "wiring ?\1 ?\2 parallel_wiring parallel_wiring\<^sub>w" + unfolding parallel_wiring_def parallel_wiring\<^sub>w_def + by(rule wiring_intro)+ + + +lemma lassocr_inverse: "rassocl\<^sub>C \ lassocr\<^sub>C = 1\<^sub>C" + unfolding rassocl\<^sub>C_def lassocr\<^sub>C_def + apply(simp add: comp_converter_map1_out comp_converter_map_converter2 comp_converter_id_right) + apply(subst map_converter_id_move_right) + apply(simp add: o_def id_def[symmetric]) + done + +lemma rassocl_inverse: "lassocr\<^sub>C \ rassocl\<^sub>C = 1\<^sub>C" + unfolding rassocl\<^sub>C_def lassocr\<^sub>C_def + apply(simp add: comp_converter_map1_out comp_converter_map_converter2 comp_converter_id_right) + apply(subst map_converter_id_move_right) + apply(simp add: o_def id_def[symmetric]) + done + +lemma swap_sum_swap_sum [simp]: "swap_sum (swap_sum x) = x" + by(cases x) simp_all + +lemma inj_on_lsumr [simp]: "inj_on lsumr A" + by(auto simp add: inj_on_def elim: lsumr.elims) + +lemma inj_on_rsuml [simp]: "inj_on rsuml A" + by(auto simp add: inj_on_def elim: rsuml.elims) + +lemma bij_lsumr [simp]: "bij lsumr" + by(rule o_bij[where g=rsuml]) auto + +lemma bij_swap_sum [simp]: "bij swap_sum" + by(rule o_bij[where g=swap_sum]) auto + +lemma bij_rsuml [simp]: "bij rsuml" + by(rule o_bij[where g=lsumr]) auto + +lemma bij_lassocr_swap_sum [simp]: "bij lassocr_swap_sum" + unfolding lassocr_swap_sum_def + by(simp add: bij_comp) + +lemma inj_lassocr_swap_sum [simp]: "inj lassocr_swap_sum" + by(simp add: bij_is_inj) + +lemma inv_rsuml [simp]: "inv_into UNIV rsuml = lsumr" + by(rule inj_imp_inv_eq) auto + +lemma inv_lsumr [simp]: "inv_into UNIV lsumr = rsuml" + by(rule inj_imp_inv_eq) auto + +lemma lassocr_swap_sum_inverse [simp]: "lassocr_swap_sum (lassocr_swap_sum x) = x" + by(simp add: lassocr_swap_sum_def sum.map_comp o_def id_def[symmetric] sum.map_id) + +lemma inv_lassocr_swap_sum [simp]: "inv_into UNIV lassocr_swap_sum = lassocr_swap_sum" + by(rule inj_imp_inv_eq)(simp_all add: sum.map_comp sum.inj_map bij_def surj_iff sum.map_id) + +lemma swap_inverse: "swap\<^sub>C \ swap\<^sub>C = 1\<^sub>C" + unfolding swap\<^sub>C_def + apply(simp add: comp_converter_map1_out comp_converter_map_converter2 comp_converter_id_right) + apply(subst map_converter_id_move_right) + apply(simp add: o_def id_def[symmetric]) + done + +lemma swap_lassocr_inverse: "\1 \\<^sub>\ (\2 \\<^sub>\ \3), \1 \\<^sub>\ (\2 \\<^sub>\ \3) \\<^sub>C swap_lassocr \ swap_lassocr \ 1\<^sub>C" + (is "?\,_ \\<^sub>C ?lhs \ _") +proof - + have "?lhs = (rassocl\<^sub>C \ (swap\<^sub>C |\<^sub>= 1\<^sub>C)) \ (lassocr\<^sub>C \ rassocl\<^sub>C) \ ((swap\<^sub>C |\<^sub>= 1\<^sub>C) \ lassocr\<^sub>C)" + by(simp add: swap_lassocr_def comp_converter_assoc) + also have "\ = rassocl\<^sub>C \ ((swap\<^sub>C \ swap\<^sub>C) |\<^sub>= 1\<^sub>C) \ lassocr\<^sub>C" + unfolding rassocl_inverse comp_converter_id_left + by(simp add: parallel_converter2_comp1_out comp_converter_assoc) + also have "?\,?\ \\<^sub>C \ \ rassocl\<^sub>C \ 1\<^sub>C \ lassocr\<^sub>C" unfolding swap_inverse + by(rule eq_\_converter_reflI eq_\_comp_cong WT_intro parallel_converter2_id_id)+ + also have "rassocl\<^sub>C \ 1\<^sub>C \ lassocr\<^sub>C = 1\<^sub>C" by(simp add: comp_converter_id_left lassocr_inverse) + finally show ?thesis . +qed + +lemma parallel_wiring_inverse: + "(\1 \\<^sub>\ \2) \\<^sub>\ (\3 \\<^sub>\ \4),(\1 \\<^sub>\ \2) \\<^sub>\ (\3 \\<^sub>\ \4) \\<^sub>C parallel_wiring \ parallel_wiring \ 1\<^sub>C" + (is "?\, _ \\<^sub>C ?lhs \ _") +proof - + have "?lhs = (lassocr\<^sub>C \ (1\<^sub>C |\<^sub>= swap_lassocr)) \ (rassocl\<^sub>C \ lassocr\<^sub>C) \ ((1\<^sub>C |\<^sub>= swap_lassocr) \ rassocl\<^sub>C)" + by(simp add: parallel_wiring_def comp_converter_assoc) + also have "\ = (lassocr\<^sub>C \ (1\<^sub>C |\<^sub>= swap_lassocr)) \ (1\<^sub>C |\<^sub>= swap_lassocr) \ rassocl\<^sub>C" + by(simp add: lassocr_inverse comp_converter_id_left) + also have "\ = lassocr\<^sub>C \ (1\<^sub>C |\<^sub>= (swap_lassocr \ swap_lassocr)) \ rassocl\<^sub>C" + by(simp add: parallel_converter2_comp2_out comp_converter_assoc) + also have "?\,?\ \\<^sub>C \ \ lassocr\<^sub>C \ (1\<^sub>C |\<^sub>= 1\<^sub>C) \ rassocl\<^sub>C" + by(rule eq_\_converter_reflI eq_\_comp_cong parallel_converter2_eq_\_cong WT_intro swap_lassocr_inverse)+ + also have "?\,?\ \\<^sub>C lassocr\<^sub>C \ (1\<^sub>C |\<^sub>= 1\<^sub>C) \ rassocl\<^sub>C \ lassocr\<^sub>C \ 1\<^sub>C \ rassocl\<^sub>C" + by(rule eq_\_converter_reflI eq_\_comp_cong parallel_converter2_id_id WT_intro)+ + also have "lassocr\<^sub>C \ 1\<^sub>C \ rassocl\<^sub>C = 1\<^sub>C" by(simp add: comp_converter_id_left rassocl_inverse) + finally show ?thesis . +qed + +\ \ Analogous to @{term \attach_wiring\} in Wiring.thy\ +definition + attach_wiring_right :: " + ('a, 'b, 'c, 'd) wiring \ + ('s \ 'e \ ('f \ 's, 'a, 'b) gpv) \ ('s \ 'e \ ('f \ 's, 'c, 'd) gpv)" + where + "attach_wiring_right = (\(f, g). map_fun id (map_fun id (map_gpv' id f g)))" + +lemma + attach_wiring_right_simps: + "attach_wiring_right (f, g) = map_fun id (map_fun id (map_gpv' id f g))" + by(simp add: attach_wiring_right_def) + +lemma + comp_converter_of_callee_wiring: + assumes wiring: "wiring \2 \3 conv w" + and WT: "\1, \2 \\<^sub>C CNV callee s \" + shows "\1, \3 \\<^sub>C CNV callee s \ conv \ CNV (attach_wiring_right w callee) s" + using wiring +proof cases + case (wiring f g) + from _ wiring(2) have "\1,\3 \\<^sub>C CNV callee s \ conv \ CNV callee s \ map_converter id id f g 1\<^sub>C" + by(rule eq_\_comp_cong)(rule eq_\_converter_reflI[OF WT]) + also have "CNV callee s \ map_converter id id f g 1\<^sub>C = map_converter id id f g (CNV callee s)" + by(subst comp_converter_map_converter2)(simp add: comp_converter_id_right) + also have "\ = CNV (attach_wiring_right w callee) s" + by(simp add: map_converter_of_callee attach_wiring_right_simps wiring(1) prod.map_id0) + finally show ?thesis . +qed + +lemma attach_wiring_right_comp_wiring: + "attach_wiring_right (w1 \\<^sub>w w2) callee = attach_wiring_right w2 (attach_wiring_right w1 callee)" + by(simp add: attach_wiring_right_def comp_wiring_def split_def map_fun_def o_def map_gpv'_comp id_def fun_eq_iff) + +lemma attach_wiring_comp_wiring: + "attach_wiring (w1 \\<^sub>w w2) callee = attach_wiring w1 (attach_wiring w2 callee)" + unfolding attach_wiring_def comp_wiring_def + by (simp add: split_def map_fun_def o_def map_gpv_conv_map_gpv' map_gpv'_comp id_def map_prod_def) + + + + +subsection \Probabilistic finite converter\ + +coinductive pfinite_converter :: "('a, 'b) \ \ ('c, 'd) \ \ ('a, 'b, 'c, 'd) converter \ bool" + for \ \' where + pfinite_converterI: "pfinite_converter \ \' conv" if + "\a. a \ outs_\ \ \ pfinite_gpv \' (run_converter conv a)" + "\a b conv'. \ a \ outs_\ \; (b, conv') \ results_gpv \' (run_converter conv a) \ \ pfinite_converter \ \' conv'" + +lemma pfinite_converter_coinduct[consumes 1, case_names pfinite_converter, case_conclusion pfinite_converter pfinite step, coinduct pred: pfinite_converter]: + assumes "X conv" + and step: "\conv a. \ X conv; a \ outs_\ \ \ \ pfinite_gpv \' (run_converter conv a) \ + (\(b, conv') \ results_gpv \' (run_converter conv a). X conv' \ pfinite_converter \ \' conv')" + shows "pfinite_converter \ \' conv" + using assms(1) by(rule pfinite_converter.coinduct)(auto dest: step) + +lemma pfinite_converterD: + "\ pfinite_converter \ \' conv; a \ outs_\ \ \ + \ pfinite_gpv \' (run_converter conv a) \ + (\(b, conv') \ results_gpv \' (run_converter conv a). pfinite_converter \ \' conv')" + by(auto elim: pfinite_converter.cases) + +lemma pfinite_converter_bot1 [simp]: "pfinite_converter bot \ conv" + by(rule pfinite_converterI) auto + +lemma pfinite_converter_mono: + assumes *: "pfinite_converter \1 \2 conv" + and le: "outs_\ \1' \ outs_\ \1" "\2 \ \2'" + and WT: "\1, \2 \\<^sub>C conv \" + shows "pfinite_converter \1' \2' conv" + using * WT + apply(coinduction arbitrary: conv) + apply(drule pfinite_converterD) + apply(erule le(1)[THEN subsetD]) + apply(drule WT_converterD') + apply(erule le(1)[THEN subsetD]) + using le(2)[THEN responses_\_mono] + by(auto intro: pfinite_gpv_mono[OF _ le(2)] results_gpv_mono[OF le(2), THEN subsetD] dest: bspec) + +context raw_converter_invariant begin +lemma pfinite_converter_of_callee: + assumes step: "\x s. \ x \ outs_\ \; I s \ \ pfinite_gpv \' (callee s x)" + and I: "I s" + shows "pfinite_converter \ \' (converter_of_callee callee s)" + using I + by(coinduction arbitrary: s)(auto 4 3 simp add: step dest: results_callee) +end + +lemma raw_converter_invariant_run_pfinite_converter: + "raw_converter_invariant \ \' run_converter (\conv. pfinite_converter \ \' conv \ \,\' \\<^sub>C conv \)" + by(unfold_locales)(auto dest: WT_converterD pfinite_converterD) + +interpretation run_pfinite_converter: raw_converter_invariant + \ \' run_converter "\conv. pfinite_converter \ \' conv \ \,\' \\<^sub>C conv \" for \ \' + by(rule raw_converter_invariant_run_pfinite_converter) + +named_theorems pfinite_intro "Introduction rules for probabilistic finiteness" + +lemma pfinite_id_converter [pfinite_intro]: "pfinite_converter \ \ id_converter" + by(coinduction) simp + +lemma pfinite_fail_converter [pfinite_intro]: "pfinite_converter \ \' fail_converter" + by coinduction simp + +lemma pfinite_parallel_converter2 [pfinite_intro]: + "pfinite_converter (\1 \\<^sub>\ \2) (\1' \\<^sub>\ \2') (conv1 |\<^sub>= conv2)" + if "pfinite_converter \1 \1' conv1" "pfinite_converter \2 \2' conv2" + using that by(coinduction arbitrary: conv1 conv2)(fastforce dest: pfinite_converterD) + +context raw_converter_invariant begin + +lemma expectation_gpv_1_le_inline: + defines "expectation_gpv2 \ expectation_gpv 1 \'" + assumes callee: "\s x. \ x \ outs_\ \; I s \ \ pfinite_gpv \' (callee s x)" + and WT_gpv: "\ \g gpv \" + and I: "I s" + and f_le_1: "\x. f x \ 1" + shows "expectation_gpv 1 \ f gpv \ expectation_gpv2 (\(x, s). f x) (inline callee gpv s)" + using WT_gpv I +proof(induction arbitrary: gpv s rule: expectation_gpv_fixp_induct) + case adm show ?case by simp + case bottom show ?case by simp + case (step expectation_gpv') + have "(\\<^sup>+ x. (case x of Pure a \ f a | IO out c \ \r\responses_\ \ out. expectation_gpv' (c r)) \measure_spmf (the_gpv gpv)) + 1 * ennreal (pmf (the_gpv gpv) None) = + (\\<^sup>+ x. pmf (the_gpv gpv) x * (case x of Some (Pure a) \ f a | Some (IO out c) \ \r\responses_\ \ out. expectation_gpv' (c r) | None \ 1))" + apply(simp add: nn_integral_measure_spmf_conv_measure_pmf nn_integral_restrict_space nn_integral_measure_pmf) + apply(subst (2) nn_integral_disjoint_pair_countspace[where B="range Some" and C="{None}", simplified, folded UNIV_option_conv, simplified]) + apply(auto simp add: mult.commute intro!: nn_integral_cong split: split_indicator) + done + also have "\ \ (\\<^sup>+ x. pmf (the_gpv gpv) x * (case x of None \ 1 | Some (Pure a) \ f a | Some (IO out c) \ + (\\<^sup>+ x. ennreal (pmf (the_gpv (callee s out) \ case_generat (\(x, y). inline1 callee (c x) y) (\out rpv'. return_spmf (Inr (out, rpv', c)))) x) * + (case x of None \ 1 | Some (Inl (a, s)) \ f a + | Some (Inr (r, rpv, rpv')) \ \x\responses_\ \' r. expectation_gpv 1 \' (\(x, s'). expectation_gpv 1 \' (\(x, s). f x) (inline callee (rpv' x) s')) (rpv x)))))" + (is "nn_integral _ ?lhs \ nn_integral _ ?rhs") + proof(rule nn_integral_mono) + fix x :: "('a, 'call, ('a, 'call, 'ret) rpv) generat option" + consider (None) "x = None" | (Pure) a where "x = Some (Pure a)" + | (IO) out c where "x = Some (IO out c)" "IO out c \ set_spmf (the_gpv gpv)" + | (outside) out c where "x = Some (IO out c)" "IO out c \ set_spmf (the_gpv gpv)" + by (metis dest_IO.elims not_None_eq) + then show "?lhs x \ ?rhs x" + proof cases + case None then show ?thesis by simp + next + case Pure then show ?thesis by simp + next + case (IO out c) + with step.prems have out: "out \ outs_\ \" by(auto dest: WT_gpvD) + then obtain response where resp: "response \ responses_\ \ out" unfolding in_outs_\_iff_responses_\ by blast + with out step.prems IO have WT_resp [WT_intro]: "\ \g c response \" by(auto dest: WT_gpvD) + have exp_resp: "expectation_gpv' (c response) \ 1" + using step.hyps[of "c response"] expectation_gpv_mono[of 1 1 f "\_. 1" \ "c response"] expectation_gpv_const_le[OF WT_resp, of 1 1] + by(simp add: le_fun_def f_le_1) + + have "(\r\responses_\ \ out. expectation_gpv' (c r)) = + (\\<^sup>+ generat. (\r\responses_\ \ out. expectation_gpv' (c r)) \measure_spmf (the_gpv (callee s out))) + + (\r\responses_\ \ out. expectation_gpv' (c r)) * (1 - ennreal (weight_spmf (the_gpv (callee s out))))" + by(simp add: measure_spmf.emeasure_eq_measure add_mult_distrib2[symmetric] semiring_class.distrib_left[symmetric] add_diff_inverse_ennreal weight_spmf_le_1) + also have "\ \ (\\<^sup>+ generat. (\r\responses_\ \ out. expectation_gpv' (c r)) \measure_spmf (the_gpv (callee s out))) + + 1 * ennreal (pmf (the_gpv (callee s out)) None)" unfolding pmf_None_eq_weight_spmf + by(intro add_mono mult_mono order_refl INF_lower2[OF resp])(auto simp add: ennreal_minus[symmetric] weight_spmf_le_1 exp_resp) + also have "\ = (\\<^sup>+ z. ennreal (pmf (the_gpv (callee s out)) z) * (case z of None \ 1 | Some generat \ (\r\responses_\ \ out. expectation_gpv' (c r))))" + apply(simp add: nn_integral_measure_spmf_conv_measure_pmf nn_integral_restrict_space nn_integral_measure_pmf del: nn_integral_const) + apply(subst (2) nn_integral_disjoint_pair_countspace[where B="range Some" and C="{None}", simplified, folded UNIV_option_conv, simplified]) + apply(auto simp add: mult.commute intro!: nn_integral_cong split: split_indicator) + done + also have "\ \ (\\<^sup>+ z. ennreal (pmf (the_gpv (callee s out)) z) * + (case z of None \ 1 | Some (IO out' rpv') \ \x\responses_\ \' out'. expectation_gpv 1 \' (\(x, s'). expectation_gpv 1 \' (\(x, s). f x) (inline callee (c x) s')) (rpv' x) + | Some (Pure (r, s')) \ (\\<^sup>+ x. ennreal (pmf (inline1 callee (c r) s') x) * (case x of None \ 1 | Some (Inl (a, s)) \ f a | Some (Inr (out', rpv, rpv')) \ + \x\responses_\ \' out'. expectation_gpv 1 \' (\(x, s'). expectation_gpv 1 \' (\(x, s). f x) (inline callee (rpv' x) s')) (rpv x)))))" + (is "nn_integral _ ?lhs2 \ nn_integral _ ?rhs2") + proof(intro nn_integral_mono) + fix z :: "('ret \ 's, 'call', ('ret \ 's, 'call', 'ret') rpv) generat option" + consider (None) "z = None" | (Pure) x' s' where "z = Some (Pure (x', s'))" "Pure (x', s') \ set_spmf (the_gpv (callee s out))" + | (IO') out' c' where "z = Some (IO out' c')" "IO out' c' \ set_spmf (the_gpv (callee s out))" + | (outside) generat where "z = Some generat" "generat \ set_spmf (the_gpv (callee s out))" + by (metis dest_IO.elims not_Some_eq old.prod.exhaust) + then show "?lhs2 z \ ?rhs2 z" + proof cases + case None then show ?thesis by simp + next + case Pure + hence "(x', s') \ results_gpv \' (callee s out)" by(simp add: results_gpv.Pure) + with results_callee step.prems out have x: "x' \ responses_\ \ out" and s': "I s'" by auto + with IO out step.prems have WT_c [WT_intro]: "\ \g c x' \" by(auto dest: WT_gpvD) + from x have "(INF r\responses_\ \ out. expectation_gpv' (c r)) \ expectation_gpv' (c x')" by(rule INF_lower) + also have "\ \ expectation_gpv2 (\(x, s). f x) (inline callee (c x') s')" using WT_c s' by(rule step.IH) + also have "\ = \\<^sup>+ xx. (case xx of Inl (x, _) \ f x + | Inr (out', callee', rpv) \ INF r'\responses_\ \' out'. expectation_gpv 1 \' (\(r, s'). expectation_gpv 1 \' (\(x, s). f x) (inline callee (rpv r) s')) (callee' r')) + \measure_spmf (inline1 callee (c x') s') + ennreal (pmf (the_gpv (inline callee (c x') s')) None)" + unfolding expectation_gpv2_def + by(subst expectation_gpv.simps)(auto simp add: inline_sel split_def o_def intro!: nn_integral_cong split: generat.split sum.split) + also have "\ = (\\<^sup>+ xx. ennreal (pmf (inline1 callee (c x') s') xx) * (case xx of None \ 1 | Some (Inl (x, _)) \ f x + | Some (Inr (out', callee', rpv)) \ INF r'\responses_\ \' out'. expectation_gpv 1 \' (\(r, s'). expectation_gpv 1 \' (\(x, s). f x) (inline callee (rpv r) s')) (callee' r')))" + apply(subst inline_sel) + apply(simp add: nn_integral_measure_spmf_conv_measure_pmf nn_integral_restrict_space nn_integral_measure_pmf pmf_map_spmf_None del: nn_integral_const) + apply(subst (2) nn_integral_disjoint_pair_countspace[where B="range Some" and C="{None}", simplified, folded UNIV_option_conv, simplified]) + apply(auto simp add: mult.commute intro!: nn_integral_cong split: split_indicator) + done + finally show ?thesis using Pure by(simp add: mult_mono) + next + case IO' + then have out': "out' \ outs_\ \'" using WT_callee out step.prems by(auto dest: WT_gpvD) + have "(INF r\responses_\ \ out. expectation_gpv' (c r)) \ min (INF (r, s')\(\r'\responses_\ \' out'. results_gpv \' (c' r')). expectation_gpv' (c r)) 1" + using IO' results_callee[OF out, of s] step.prems by(intro INF_mono min.boundedI)(auto intro: results_gpv.IO intro!: INF_lower2[OF resp] exp_resp) + also have "\ \ (INF r'\responses_\ \' out'. min (INF (r, s')\results_gpv \' (c' r'). expectation_gpv' (c r)) 1)" + using resp out' unfolding inf_min[symmetric] in_outs_\_iff_responses_\ + by(subst INF_inf_const2)(auto simp add: INF_UNION) + also have "\ \ (INF r'\responses_\ \' out'. expectation_gpv 1 \' (\(r', s'). expectation_gpv 1 \' (\(x, s). f x) (inline callee (c r') s')) (c' r'))" + (is "_ \ (INF r'\_. ?r r')") + proof(rule INF_mono, rule bexI) + fix r' + assume r': "r' \ responses_\ \' out'" + have fin: "pfinite_gpv \' (c' r')" using callee[OF out, of s] IO' r' WT_callee[OF out, of s] step.prems by(auto dest: pfinite_gpv_ContD) + have "min (INF (r, s')\results_gpv \' (c' r'). expectation_gpv' (c r)) 1 \ min (INF (r, s')\results_gpv \' (c' r'). expectation_gpv2 (\(x, s). f x) (inline callee (c r) s')) 1" + using IO IO' step.prems out results_callee[OF out, of s] r' + by(intro min.mono)(auto intro!: INF_mono rev_bexI step.IH dest: WT_gpv_ContD intro: results_gpv.IO) + also have "\ \ ?r r'" unfolding expectation_gpv2_def using fin by(rule pfinite_INF_le_expectation_gpv) + finally show "min (INF (r, s')\results_gpv \' (c' r'). expectation_gpv' (c r)) 1 \ \" . + qed + finally show ?thesis using IO' by(simp add: mult_mono) + next + case outside then show ?thesis by(simp add: in_set_spmf_iff_spmf) + qed + qed + also have "\ = (\\<^sup>+ z. \\<^sup>+ x. + ennreal (pmf (the_gpv (callee s out)) z) * + ennreal (pmf (case z of None \ return_pmf None | Some (Pure (x, xb)) \ inline1 callee (c x) xb | Some (IO out rpv') \ return_spmf (Inr (out, rpv', c))) x) * + (case x of None \ 1 | Some (Inl (a, s)) \ f a | Some (Inr (out, rpv, rpv')) \ \x\responses_\ \' out. + expectation_gpv 1 \' (\(x, s'). expectation_gpv 1 \' (\(x, s). f x) (inline callee (rpv' x) s')) (rpv x)))" + (is "\ = (\\<^sup>+ z. \\<^sup>+ x. ?f x z)") + by(auto intro!: nn_integral_cong split!: option.split generat.split simp add: mult.assoc nn_integral_cmult ennreal_indicator) + also have "(\\<^sup>+ z. \\<^sup>+ x. ?f x z) = (\\<^sup>+ x. \\<^sup>+ z. ?f x z)" + by(subst nn_integral_fst_count_space[where f="case_prod _", simplified])(simp add: nn_integral_snd_count_space[symmetric]) + also have "\ = (\\<^sup>+ x. + ennreal (pmf (the_gpv (callee s out) \ case_generat (\(x, y). inline1 callee (c x) y) (\out rpv'. return_spmf (Inr (out, rpv', c)))) x) * + (case x of None \ 1 | Some (Inl (a, s)) \ f a | Some (Inr (r, rpv, rpv')) \ + \x\responses_\ \' r. expectation_gpv 1 \' (\(x, s'). expectation_gpv 1 \' (\(x, s). f x) (inline callee (rpv' x) s')) (rpv x)))" + by(simp add: bind_spmf_def ennreal_pmf_bind nn_integral_multc[symmetric] nn_integral_measure_pmf) + finally show ?thesis using IO by(auto intro!: mult_mono) + next + case outside then show ?thesis by(simp add: in_set_spmf_iff_spmf) + qed + qed + also have "\ = (\\<^sup>+ y. \\<^sup>+ x. + ennreal (pmf (the_gpv gpv) y) * + ennreal (case y of None \ pmf (return_pmf None) x | Some (Pure xa) \ pmf (return_spmf (Inl (xa, s))) x + | Some (IO out rpv) \ + pmf (bind_spmf (the_gpv (callee s out)) (\generat' \ case generat' of Pure (x, y) \ inline1 callee (rpv x) y | IO out rpv' \ return_spmf (Inr (out, rpv', rpv)))) x) * + (case x of None \ 1 | Some (Inl (a, s)) \ f a + | Some (Inr (out, rpv, rpv')) \ \x\responses_\ \' out. expectation_gpv 1 \' (\(x, s'). expectation_gpv 1 \' (\(x, s). f x) (inline callee (rpv' x) s')) (rpv x)))" + (is "_ = (\\<^sup>+ y. \\<^sup>+ x. ?f x y)") + by(auto intro!: nn_integral_cong split!: option.split generat.split simp add: nn_integral_cmult mult.assoc ennreal_indicator) + also have "(\\<^sup>+ y. \\<^sup>+ x. ?f x y) = (\\<^sup>+ x. \\<^sup>+ y. ?f x y)" + by(subst nn_integral_fst_count_space[where f="case_prod _", simplified])(simp add: nn_integral_snd_count_space[symmetric]) + also have "\ = (\\<^sup>+ x. (pmf (inline1 callee gpv s) x) * (case x of None \ 1 | Some (Inl (a, s)) \ f a | + Some (Inr (out, rpv, rpv')) \ \x\responses_\ \' out. expectation_gpv 1 \' (\(x, s'). expectation_gpv 1 \' (\(x, s). f x) (inline callee (rpv' x) s')) (rpv x)))" + by(rewrite in "_ = \" inline1.simps) + (auto simp add: bind_spmf_def ennreal_pmf_bind nn_integral_multc[symmetric] nn_integral_measure_pmf intro!: nn_integral_cong split: option.split generat.split) + also have "\ = (\\<^sup>+ res. (case res of Inl (a, s) \ f a + | Inr (out, rpv, rpv') \ \x\responses_\ \' out. expectation_gpv 1 \' (\(x, s'). expectation_gpv 1 \' (\(x, s). f x) (inline callee (rpv' x) s')) (rpv x)) + \measure_spmf (inline1 callee gpv s) + + ennreal (pmf (inline1 callee gpv s) None))" + apply(simp add: nn_integral_measure_spmf_conv_measure_pmf nn_integral_restrict_space nn_integral_measure_pmf) + apply(subst nn_integral_disjoint_pair_countspace[where B="range Some" and C="{None}", simplified, folded UNIV_option_conv, simplified]) + apply(auto simp add: mult.commute intro!: nn_integral_cong split: split_indicator) + done + also have "\ = expectation_gpv2 (\(x, s). f x) (inline callee gpv s)" unfolding expectation_gpv2_def + by(rewrite in "_ = \" expectation_gpv.simps, subst (1 2) inline_sel) + (simp add: o_def pmf_map_spmf_None sum.case_distrib[where h="case_generat _ _"] split_def cong: sum.case_cong) + finally show ?case . +qed + +lemma pfinite_inline: + assumes fin: "pfinite_gpv \ gpv" + and WT: "\ \g gpv \" + and callee: "\s x. \ x \ outs_\ \; I s \ \ pfinite_gpv \' (callee s x)" + and I: "I s" + shows "pfinite_gpv \' (inline callee gpv s)" +unfolding pgen_lossless_gpv_def +proof(rule antisym) + have WT': "\' \g inline callee gpv s \" using WT I by(rule WT_gpv_inline_invar) + from expectation_gpv_const_le[OF WT', of 1 1] + show "expectation_gpv 1 \' (\_. 1) (inline callee gpv s) \ 1" by(simp add: max_def) + + have "1 = expectation_gpv 1 \ (\_. 1) gpv" using fin by(simp add: pgen_lossless_gpv_def) + also have "\ \ expectation_gpv 1 \' (\_. 1) (inline callee gpv s)" + by(rule expectation_gpv_1_le_inline[unfolded split_def]; rule callee I WT WT_callee order_refl) + finally show "1 \ \" . +qed + +end + +lemma pfinite_comp_converter [pfinite_intro]: + "pfinite_converter \1 \3 (conv1 \ conv2)" + if "pfinite_converter \1 \2 conv1" "pfinite_converter \2 \3 conv2" "\1,\2 \\<^sub>C conv1 \" "\2,\3 \\<^sub>C conv2 \" + using that +proof(coinduction arbitrary: conv1 conv2) + case pfinite_converter + have conv1: "pfinite_gpv \2 (run_converter conv1 a)" + using pfinite_converter(1, 5) by(simp add: pfinite_converterD) + have conv2: "\2 \g run_converter conv1 a \" + using pfinite_converter(3, 5) by(simp add: WT_converterD) + have ?pfinite using pfinite_converter(2,4,5) + by(auto intro!:run_pfinite_converter.pfinite_inline[OF conv1] dest: pfinite_converterD intro: conv2) + moreover have ?step (is "\(b, conv')\?res. ?P b conv' \ _") + proof(clarify) + fix b conv'' + assume "(b, conv'') \ ?res" + then obtain conv1' conv2' where [simp]: "conv'' = comp_converter conv1' conv2'" + and inline: "((b, conv1'), conv2') \ results_gpv \3 (inline run_converter (run_converter conv1 a) conv2)" + by auto + from run_pfinite_converter.results_gpv_inline[OF inline conv2] pfinite_converter(2,4) + have run: "(b, conv1') \ results_gpv \2 (run_converter conv1 a)" + and *: "pfinite_converter \2 \3 conv2'" "\2, \3 \\<^sub>C conv2' \" by auto + with WT_converterD(2)[OF pfinite_converter(3,5) run] pfinite_converterD[THEN conjunct2, rule_format, OF pfinite_converter(1,5) run] + show "?P b conv''" by auto + qed + ultimately show ?case .. +qed + +lemma pfinite_map_converter [pfinite_intro]: + "pfinite_converter \ \' (map_converter f g f' g' conv)" if + *: "pfinite_converter (map_\ (inv_into UNIV f) (inv_into UNIV g) \) (map_\ f' g' \') conv" + and f: "inj f" and g: "surj g" + using * +proof(coinduction arbitrary: conv) + case (pfinite_converter a conv) + with f have a: "inv_into UNIV f (f a) \ outs_\ \" by simp + with pfinite_converterD[OF \pfinite_converter _ _ conv\, of "f a"] have "?pfinite" by simp + moreover have ?step + proof(safe) + fix r conv' + assume "(r, conv') \ results_gpv \' (run_converter (map_converter f g f' g' conv) a)" + then obtain r' conv'' + where results: "(r', conv'') \ results_gpv (map_\ f' g' \') (run_converter conv (f a))" + and r: "r = g r'" + and conv': "conv' = map_converter f g f' g' conv''" + by auto + from pfinite_converterD[OF \pfinite_converter _ _ conv\, THEN conjunct2, rule_format, OF _ results] a r conv' + show "\conv. conv' = map_converter f g f' g' conv \ + pfinite_converter (map_\ (inv_into UNIV f) (inv_into UNIV g) \) (map_\ f' g' \') conv" + by auto + qed + ultimately show ?case .. +qed + +lemma pfinite_lassocr\<^sub>C [pfinite_intro]: "pfinite_converter ((\1 \\<^sub>\ \2) \\<^sub>\ \3) (\1 \\<^sub>\ (\2 \\<^sub>\ \3)) lassocr\<^sub>C" + by(coinduction)(auto simp add: lassocr\<^sub>C_def) + +lemma pfinite_rassocl\<^sub>C [pfinite_intro]: "pfinite_converter (\1 \\<^sub>\ (\2 \\<^sub>\ \3)) ((\1 \\<^sub>\ \2) \\<^sub>\ \3) rassocl\<^sub>C" + by(coinduction)(auto simp add: rassocl\<^sub>C_def) + +lemma pfinite_swap\<^sub>C [pfinite_intro]: "pfinite_converter (\1 \\<^sub>\ \2) (\2 \\<^sub>\ \1) swap\<^sub>C" + by(coinduction)(auto simp add: swap\<^sub>C_def) + +lemma pfinite_swap_lassocr [pfinite_intro]: "pfinite_converter (\1 \\<^sub>\ (\2 \\<^sub>\ \3)) (\2 \\<^sub>\ (\1 \\<^sub>\ \3)) swap_lassocr" + unfolding swap_lassocr_def by(rule pfinite_intro WT_intro)+ + +lemma pfinite_swap_rassocl [pfinite_intro]: "pfinite_converter ((\1 \\<^sub>\ \2) \\<^sub>\ \3) ((\1 \\<^sub>\ \3) \\<^sub>\ \2) swap_rassocl" + unfolding swap_rassocl_def by(rule pfinite_intro WT_intro)+ + +lemma pfinite_parallel_wiring [pfinite_intro]: + "pfinite_converter ((\1 \\<^sub>\ \2) \\<^sub>\ (\3 \\<^sub>\ \4)) ((\1 \\<^sub>\ \3) \\<^sub>\ (\2 \\<^sub>\ \4)) parallel_wiring" + unfolding parallel_wiring_def by(rule pfinite_intro WT_intro)+ + +lemma pfinite_parallel_converter [pfinite_intro]: + "pfinite_converter (\1 \\<^sub>\ \2) \3 (conv1 |\<^sub>\ conv2)" + if "pfinite_converter \1 \3 conv1" and "pfinite_converter \2 \3 conv2" + using that by(coinduction arbitrary: conv1 conv2)(fastforce dest: pfinite_converterD) + +lemma pfinite_converter_of_resource [simp, pfinite_intro]: "pfinite_converter \1 \2 (converter_of_resource res)" + by(coinduction arbitrary: res) auto + +subsection \colossless converter\ + +coinductive colossless_converter :: "('a, 'b) \ \ ('c, 'd) \ \ ('a, 'b, 'c, 'd) converter \ bool" + for \ \' where + colossless_converterI: + "colossless_converter \ \' conv" if + "\a. a \ outs_\ \ \ colossless_gpv \' (run_converter conv a)" + "\a b conv'. \ a \ outs_\ \; (b, conv') \ results_gpv \' (run_converter conv a) \ \ colossless_converter \ \' conv'" + +lemma colossless_converter_coinduct[consumes 1, case_names colossless_converter, case_conclusion colossless_converter plossless step, coinduct pred: colossless_converter]: + assumes "X conv" + and step: "\conv a. \ X conv; a \ outs_\ \ \ \ colossless_gpv \' (run_converter conv a) \ + (\(b, conv') \ results_gpv \' (run_converter conv a). X conv' \ colossless_converter \ \' conv')" + shows "colossless_converter \ \' conv" + using assms(1) by(rule colossless_converter.coinduct)(auto dest: step) + +lemma colossless_converterD: + "\ colossless_converter \ \' conv; a \ outs_\ \ \ + \ colossless_gpv \' (run_converter conv a) \ + (\(b, conv') \ results_gpv \' (run_converter conv a). colossless_converter \ \' conv')" + by(auto elim: colossless_converter.cases) + +lemma colossless_converter_bot1 [simp]: "colossless_converter bot \ conv" + by(rule colossless_converterI) auto + +lemma raw_converter_invariant_run_colossless_converter: "raw_converter_invariant \ \' run_converter (\conv. colossless_converter \ \' conv \ \,\' \\<^sub>C conv \)" + by(unfold_locales)(auto dest: WT_converterD colossless_converterD) + +interpretation run_colossless_converter: raw_converter_invariant + \ \' run_converter "\conv. colossless_converter \ \' conv \ \,\' \\<^sub>C conv \" for \ \' + by(rule raw_converter_invariant_run_colossless_converter) + +lemma colossless_const_converter [simp]: "colossless_converter \ \' (const_converter x)" + by(coinduction)(auto) + +subsection \trace equivalence\ + +lemma distinguish_trace_eq: (* generalized from Distinguisher.thy *) + assumes distinguish: "\distinguisher. \ \g distinguisher \ \ connect distinguisher res = connect distinguisher res'" + shows "outs_\ \ \\<^sub>R res \ res'" + using assms by(rule distinguish_trace_eq)(auto intro: WT_fail_resource) + +lemma attach_trace_eq': + assumes eq: "outs_\ \ \\<^sub>R res1 \ res2" + and WT1 [WT_intro]: "\ \res res1 \" + and WT2 [WT_intro]: "\ \res res2 \" + and WT_conv [WT_intro]: "\',\ \\<^sub>C conv \" + shows "outs_\ \' \\<^sub>R conv \ res1 \ conv \ res2" +proof(rule distinguish_trace_eq) + fix \ :: "('c, 'd) distinguisher" + assume [WT_intro]: "\' \g \ \" + have "connect (absorb \ conv) res1 = connect (absorb \ conv) res2" using eq + by(rule connect_cong_trace)(rule WT_intro | fold WT_gpv_iff_outs_gpv)+ + then show "connect \ (conv \ res1) = connect \ (conv \ res2)" by(simp add: distinguish_attach) +qed + +lemma trace_callee_eq_trans [trans]: + "\ trace_callee_eq callee1 callee2 A p q; trace_callee_eq callee2 callee3 A q r \ + \ trace_callee_eq callee1 callee3 A p r" + by(simp add: trace_callee_eq_def) + +lemma trace_eq'_parallel_resource: + fixes res1 :: "('a, 'b) resource" and res2 :: "('c, 'd) resource" + assumes 1: "trace_eq' A res1 res1'" + and 2: "trace_eq' B res2 res2'" + shows "trace_eq' (A <+> B) (res1 \ res2) (res1' \ res2')" +proof - + let ?\ = "\_uniform A (UNIV :: 'b set) \\<^sub>\ \_uniform B (UNIV :: 'd set)" + have "trace_eq' (outs_\ ?\) (res1 \ res2) (res1' \ res2)" + apply(subst (1 2) attach_converter_of_resource_conv_parallel_resource2[symmetric]) + apply(rule attach_trace_eq'[where ?\ = "\_uniform A UNIV"]; auto simp add: 1 intro: WT_intro WT_resource_\_uniform_UNIV) + done + also have "trace_eq' (outs_\ ?\) (res1' \ res2) (res1' \ res2')" + apply(subst (1 2) attach_converter_of_resource_conv_parallel_resource[symmetric]) + apply(rule attach_trace_eq'[where ?\ = "\_uniform B UNIV"]; auto simp add: 2 intro: WT_intro WT_resource_\_uniform_UNIV) + done + finally show ?thesis by simp +qed + +proposition trace_callee_eq_coinduct [consumes 1, case_names step sim]: (* stronger version of trace'_eq_simI *) + fixes callee1 :: "('a, 'b, 's1) callee" and callee2 :: "('a, 'b, 's2) callee" + assumes start: "S p q" + and step: "\p q a. \ S p q; a \ A \ \ + bind_spmf p (\s. map_spmf fst (callee1 s a)) = bind_spmf q (\s. map_spmf fst (callee2 s a))" + and sim: "\p q a res res' b s'' s'. \ S p q; a \ A; res \ set_spmf p; (b, s'') \ set_spmf (callee1 res a); res' \ set_spmf q; (b, s') \ set_spmf (callee2 res' a) \ + \ S (cond_spmf_fst (bind_spmf p (\s. callee1 s a)) b) + (cond_spmf_fst (bind_spmf q (\s. callee2 s a)) b)" + shows "trace_callee_eq callee1 callee2 A p q" +proof(rule trace_callee_eqI) + fix xs :: "('a \ 'b) list" and z + assume xs: "set xs \ A \ UNIV" and z: "z \ A" + + from start show "trace_callee callee1 p xs z = trace_callee callee2 q xs z" using xs + proof(induction xs arbitrary: p q) + case Nil + then show ?case using z by(simp add: step) + next + case (Cons xy xs) + obtain x y where xy [simp]: "xy = (x, y)" by(cases xy) + have "trace_callee callee1 p (xy # xs) z = + trace_callee callee1 (cond_spmf_fst (bind_spmf p (\s. callee1 s x)) y) xs z" + by(simp add: bind_map_spmf split_def o_def) + also have "\ = trace_callee callee2 (cond_spmf_fst (bind_spmf q (\s. callee2 s x)) y) xs z" + proof(cases "\s \ set_spmf q. \s'. (y, s') \ set_spmf (callee2 s x)") + case True + then obtain s s' where ss': "s \ set_spmf q" "(y, s') \ set_spmf (callee2 s x)" by blast + from Cons have "x \ A" by simp + from ss' step[THEN arg_cong[where f="set_spmf"], OF \S p q\ this] obtain ss ss' + where "ss \ set_spmf p" "(y, ss') \ set_spmf (callee1 ss x)" + by(clarsimp simp add: bind_UNION) force + from sim[OF \S p q\ _ this ss'] show ?thesis using Cons.prems by (auto intro: Cons.IH) + next + case False + then have "cond_spmf_fst (bind_spmf q (\s. callee2 s x)) y = return_pmf None" + by(auto simp add: bind_eq_return_pmf_None) + moreover from step[OF \S p q\, of x, THEN arg_cong[where f=set_spmf], THEN eq_refl] Cons.prems False + have "cond_spmf_fst (bind_spmf p (\s. callee1 s x)) y = return_pmf None" + by(clarsimp simp add: bind_eq_return_pmf_None)(rule ccontr; fastforce) + ultimately show ?thesis by(simp del: cond_spmf_fst_eq_return_None) + qed + also have "\ = trace_callee callee2 q (xy # xs) z" + by(simp add: split_def o_def) + finally show ?case . + qed +qed + +proposition trace_callee_eq_coinduct_strong [consumes 1, case_names step sim, case_conclusion step lhs rhs, case_conclusion sim sim eq]: + fixes callee1 :: "('a, 'b, 's1) callee" and callee2 :: "('a, 'b, 's2) callee" + assumes start: "S p q" + and step: "\p q a. \ S p q; a \ A \ \ + bind_spmf p (\s. map_spmf fst (callee1 s a)) = bind_spmf q (\s. map_spmf fst (callee2 s a))" + and sim: "\p q a res res' b s'' s'. \ S p q; a \ A; res \ set_spmf p; (b, s'') \ set_spmf (callee1 res a); res' \ set_spmf q; (b, s') \ set_spmf (callee2 res' a) \ + \ S (cond_spmf_fst (bind_spmf p (\s. callee1 s a)) b) + (cond_spmf_fst (bind_spmf q (\s. callee2 s a)) b) \ + trace_callee_eq callee1 callee2 A (cond_spmf_fst (bind_spmf p (\s. callee1 s a)) b) (cond_spmf_fst (bind_spmf q (\s. callee2 s a)) b)" + shows "trace_callee_eq callee1 callee2 A p q" +proof - + from start have "S p q \ trace_callee_eq callee1 callee2 A p q" by simp + thus ?thesis + apply(rule trace_callee_eq_coinduct) + apply(erule disjE) + apply(erule (1) step) + apply(drule trace_callee_eqD[where xs="[]"]; simp) + apply(erule disjE) + apply(erule (5) sim) + apply(rule disjI2) + apply(rule trace_callee_eqI) + apply(drule trace_callee_eqD[where xs="(_, _) # _"]) + apply simp_all + done +qed + +lemma trace_callee_return_pmf_None [simp]: + "trace_callee_eq callee1 callee2 A (return_pmf None) (return_pmf None)" + by(rule trace_callee_eqI) simp + +lemma trace_callee_eq_sym [sym]: "trace_callee_eq callee1 callee2 A p q \ trace_callee_eq callee2 callee1 A q p" + by(simp add: trace_callee_eq_def) + +lemma eq_resource_on_imp_trace_eq: "A \\<^sub>R res1 \ res2" if "A \\<^sub>R res1 \ res2" +proof - + have "outs_\ (\_uniform A UNIV :: ('a, 'b) \) \\<^sub>R res1 \ res2" using that + by -(rule distinguish_trace_eq[OF connect_eq_resource_cong], simp+) + thus ?thesis by simp +qed + +lemma advantage_nonneg: "0 \ advantage \ res1 res2" + by(simp add: advantage_def) + +lemma comp_converter_of_resource_conv_parallel_converter: + "(converter_of_resource res |\<^sub>\ 1\<^sub>C) \ conv = converter_of_resource res |\<^sub>\ conv" + by(coinduction arbitrary: res conv) + (auto 4 3 simp add: rel_fun_def gpv.map_comp map_lift_spmf spmf_rel_map split_def map_gpv_conv_bind[symmetric] id_def[symmetric] gpv.rel_map split!: sum.split intro!: rel_spmf_reflI gpv.rel_refl_strong) + +lemma comp_converter_of_resource_conv_parallel_converter2: + "(1\<^sub>C |\<^sub>\ converter_of_resource res) \ conv = conv |\<^sub>\ converter_of_resource res" + by(coinduction arbitrary: res conv) + (auto 4 3 simp add: rel_fun_def gpv.map_comp map_lift_spmf spmf_rel_map split_def map_gpv_conv_bind[symmetric] id_def[symmetric] gpv.rel_map split!: sum.split intro!: rel_spmf_reflI gpv.rel_refl_strong) + +lemma parallel_converter_map_converter: + "map_converter f g f' g' conv1 |\<^sub>\ map_converter f'' g'' f' g' conv2 = + map_converter (map_sum f f'') (map_sum g g'') f' g' (conv1 |\<^sub>\ conv2)" + using parallel_callee_parametric[ + where A="conversep (BNF_Def.Grp UNIV f)" and B="BNF_Def.Grp UNIV g" and C="BNF_Def.Grp UNIV f'" and R="conversep (BNF_Def.Grp UNIV g')" and A'="conversep (BNF_Def.Grp UNIV f'')" and B'="BNF_Def.Grp UNIV g''", + unfolded rel_converter_Grp sum.rel_conversep sum.rel_Grp, + simplified, + unfolded rel_converter_Grp] + by(simp add: rel_fun_def Grp_def) + +lemma map_converter_parallel_converter_out2: + "conv1 |\<^sub>\ map_converter f g id id conv2 = map_converter (map_sum id f) (map_sum id g) id id (conv1 |\<^sub>\ conv2)" + by(rule parallel_converter_map_converter[where f=id and g=id and f'=id and g'=id, simplified]) + +lemma parallel_converter_assoc2: + "parallel_converter conv1 (parallel_converter conv2 conv3) = + map_converter lsumr rsuml id id (parallel_converter (parallel_converter conv1 conv2) conv3)" + by(coinduction arbitrary: conv1 conv2 conv3) + (auto 4 5 intro!: rel_funI gpv.rel_refl_strong split: sum.split simp add: gpv.rel_map map_gpv'_id map_gpv_conv_map_gpv'[symmetric]) + +lemma parallel_converter_of_resource: + "converter_of_resource res1 |\<^sub>\ converter_of_resource res2 = converter_of_resource (res1 \ res2)" + by(coinduction arbitrary: res1 res2) + (auto 4 3 simp add: rel_fun_def map_lift_spmf spmf_rel_map intro!: rel_spmf_reflI split!: sum.split) + +lemma map_Inr_parallel_converter: + "map_converter Inr f g h (conv1 |\<^sub>\ conv2) = map_converter id (f \ Inr) g h conv2" + (is "?lhs = ?rhs") +proof - + have "?lhs = map_converter Inr f id id (map_converter id id g h conv1 |\<^sub>\ map_converter id id g h conv2)" + by(simp add: parallel_converter_map_converter sum.map_id0) + also have "map_converter Inr f id id (conv1 |\<^sub>\ conv2) = map_converter id (f \ Inr) id id conv2" for conv1 conv2 + by(coinduction arbitrary: conv2) + (auto simp add: rel_fun_def map_gpv_conv_map_gpv'[symmetric] gpv.rel_map intro!: gpv.rel_refl_strong) + also have "map_converter id (f \ Inr) id id (map_converter id id g h conv2) = ?rhs" by simp + finally show ?thesis . +qed + +lemma map_Inl_parallel_converter: + "map_converter Inl f g h (conv1 |\<^sub>\ conv2) = map_converter id (f \ Inl) g h conv1" + (is "?lhs = ?rhs") +proof - + have "?lhs = map_converter Inl f id id (map_converter id id g h conv1 |\<^sub>\ map_converter id id g h conv2)" + by(simp add: parallel_converter_map_converter sum.map_id0) + also have "map_converter Inl f id id (conv1 |\<^sub>\ conv2) = map_converter id (f \ Inl) id id conv1" for conv1 conv2 + by(coinduction arbitrary: conv1) + (auto simp add: rel_fun_def map_gpv_conv_map_gpv'[symmetric] gpv.rel_map intro!: gpv.rel_refl_strong) + also have "map_converter id (f \ Inl) id id (map_converter id id g h conv1) = ?rhs" by simp + finally show ?thesis . +qed + +lemma left_interface_parallel_converter: + "left_interface (conv1 |\<^sub>\ conv2) = left_interface conv1 |\<^sub>\ left_interface conv2" + by(coinduction arbitrary: conv1 conv2) + (auto 4 3 split!: sum.split simp add: rel_fun_def gpv.rel_map left_gpv_map[where h=id] sum.map_id0 intro!: gpv.rel_refl_strong) + +lemma right_interface_parallel_converter: + "right_interface (conv1 |\<^sub>\ conv2) = right_interface conv1 |\<^sub>\ right_interface conv2" + by(coinduction arbitrary: conv1 conv2) + (auto 4 3 split!: sum.split simp add: rel_fun_def gpv.rel_map right_gpv_map[where h=id] sum.map_id0 intro!: gpv.rel_refl_strong) + +lemma left_interface_converter_of_resource [simp]: + "left_interface (converter_of_resource res) = converter_of_resource res" + by(coinduction arbitrary: res)(auto simp add: rel_fun_def map_lift_spmf spmf_rel_map intro!: rel_spmf_reflI) + +lemma right_interface_converter_of_resource [simp]: + "right_interface (converter_of_resource res) = converter_of_resource res" + by(coinduction arbitrary: res)(auto simp add: rel_fun_def map_lift_spmf spmf_rel_map intro!: rel_spmf_reflI) + +lemma parallel_converter_swap: "map_converter swap_sum swap_sum id id (conv1 |\<^sub>\ conv2) = conv2 |\<^sub>\ conv1" + by(coinduction arbitrary: conv1 conv2) + (auto 4 3 split!: sum.split simp add: rel_fun_def map_gpv_conv_map_gpv'[symmetric] gpv.rel_map intro!: gpv.rel_refl_strong) + +lemma eq_\_converter_map_converter': + assumes "\'', map_\ f' g' \' \\<^sub>C conv1 \ conv2" + and "f ` outs_\ \ \ outs_\ \''" + and "\q\outs_\ \. g ` responses_\ \'' (f q) \ responses_\ \ q" + shows "\, \' \\<^sub>C map_converter f g f' g' conv1 \ map_converter f g f' g' conv2" + using assms(1) +proof(coinduction arbitrary: conv1 conv2) + case eq_\_converter + from this(2) have "f q \ outs_\ \''" using assms(2) by auto + from eq_\_converter(1)[THEN eq_\_converterD, OF this] eq_\_converter(2) + show ?case + apply simp + apply(rule eq_\_gpv_map_gpv') + apply(simp add: BNF_Def.vimage2p_def prod.rel_map) + apply(erule eq_\_gpv_mono') + using assms(3) + apply(auto 4 4 simp add: eq_onp_def) + done +qed + +lemma parallel_converter_eq_\_cong: + "\ \1, \ \\<^sub>C conv1 \ conv1'; \2, \ \\<^sub>C conv2 \ conv2' \ + \ \1 \\<^sub>\ \2, \ \\<^sub>C parallel_converter conv1 conv2 \ parallel_converter conv1' conv2'" + by(coinduction arbitrary: conv1 conv2 conv1' conv2') + (fastforce dest: eq_\_converterD elim!: eq_\_gpv_mono' simp add: eq_onp_def) + +\ \Helper lemmas for simplyfing @{term exec_gpv}\ +lemma + exec_gpv_parallel_oracle_right: + "exec_gpv (oracle1 \\<^sub>O oracle2) (right_gpv gpv) s = exec_gpv (\oracle2) gpv s" + unfolding spmf_rel_eq[symmetric] + apply (rule rel_spmf_mono) + by (rule exec_gpv_parametric'[where S="(=)" and A="(=)" and CALL="\l r. l = Inr r" and R="\l r. l = Inr r" , THEN rel_funD, THEN rel_funD, THEN rel_funD ]) + (auto simp add: prod.rel_eq extend_state_oracle_def parallel_oracle_def split_def + spmf_rel_map1 spmf_rel_map2 map_prod_def rel_spmf_reflI right_gpv_Inr_transfer intro!:rel_funI) + +lemma + exec_gpv_parallel_oracle_left: + "exec_gpv (oracle1 \\<^sub>O oracle2) (left_gpv gpv) s = exec_gpv (oracle1\) gpv s" (is "?L = ?R") + unfolding spmf_rel_eq[symmetric] + apply (rule rel_spmf_mono) + by (rule exec_gpv_parametric'[where S="(=)" and A="(=)" and CALL="\l r. l = Inl r" and R="\l r. l = Inl r" , THEN rel_funD, THEN rel_funD, THEN rel_funD ]) + (auto simp add: prod.rel_eq extend_state_oracle2_def parallel_oracle_def split_def + spmf_rel_map1 spmf_rel_map2 map_prod_def rel_spmf_reflI left_gpv_Inl_transfer intro!:rel_funI) + +end \ No newline at end of file diff --git a/thys/Constructive_Cryptography_CM/Observe_Failure.thy b/thys/Constructive_Cryptography_CM/Observe_Failure.thy new file mode 100644 --- /dev/null +++ b/thys/Constructive_Cryptography_CM/Observe_Failure.thy @@ -0,0 +1,579 @@ +theory Observe_Failure imports + More_CC +begin + +declare [[show_variants]] + +context fixes "oracle" :: "('s, 'in, 'out) oracle'" begin + +fun obsf_oracle :: "('s exception, 'in, 'out exception) oracle'" where + "obsf_oracle Fault x = return_spmf (Fault, Fault)" +| "obsf_oracle (OK s) x = TRY map_spmf (map_prod OK OK) (oracle s x) ELSE return_spmf (Fault, Fault)" + +end + +type_synonym ('a, 'b) resource_obsf = "('a, 'b exception) resource" + +translations + (type) "('a, 'b) resource_obsf" <= (type) "('a, 'b exception) resource" + +primcorec obsf_resource :: "('in, 'out) resource \ ('in, 'out) resource_obsf" where + "run_resource (obsf_resource res) = (\x. + map_spmf (map_prod id obsf_resource) + (map_spmf (map_prod id (\resF. case resF of OK res' \ res' | Fault \ fail_resource)) + (TRY map_spmf (map_prod OK OK) (run_resource res x) ELSE return_spmf (Fault, Fault))))" + +lemma obsf_resource_sel: + "run_resource (obsf_resource res) x = + map_spmf (map_prod id (\resF. obsf_resource (case resF of OK res' \ res' | Fault \ fail_resource))) + (TRY map_spmf (map_prod OK OK) (run_resource res x) ELSE return_spmf (Fault, Fault))" + by(simp add: spmf.map_comp prod.map_comp o_def id_def) + +declare obsf_resource.simps [simp del] + +lemma obsf_resource_exception [simp]: "obsf_resource fail_resource = const_resource Fault" + by coinduction(simp add: rel_fun_def obsf_resource_sel) + +lemma obsf_resource_sel2 [simp]: + "run_resource (obsf_resource res) x = + try_spmf (map_spmf (map_prod OK obsf_resource) (run_resource res x)) (return_spmf (Fault, const_resource Fault))" + by(simp add: map_try_spmf spmf.map_comp o_def prod.map_comp obsf_resource_sel) + +lemma lossless_obsf_resource [simp]: "lossless_resource \ (obsf_resource res)" + by(coinduction arbitrary: res) auto + +lemma WT_obsf_resource [WT_intro, simp]: "exception_\ \ \res obsf_resource res \" if "\ \res res \" + using that by(coinduction arbitrary: res)(auto dest: WT_resourceD split: if_split_asm) + + +type_synonym ('a, 'b) distinguisher_obsf = "(bool, 'a, 'b exception) gpv" + +translations + (type) "('a, 'b) distinguisher_obsf" <= (type) "(bool, 'a, 'b exception) gpv" + +abbreviation connect_obsf :: "('a, 'b) distinguisher_obsf \ ('a, 'b) resource_obsf \ bool spmf" where + "connect_obsf == connect" + +definition obsf_distinguisher :: "('a, 'b) distinguisher \ ('a, 'b) distinguisher_obsf" where + "obsf_distinguisher \ = map_gpv' (\x. x = Some True) id option_of_exception (gpv_stop \)" + +lemma WT_obsf_distinguisher [WT_intro]: + "exception_\ \ \g obsf_distinguisher \ \" if [WT_intro]: "\ \g \ \" + unfolding obsf_distinguisher_def by(rule WT_intro|simp)+ + +lemma interaction_bounded_by_obsf_distinguisher [interaction_bound]: + "interaction_bounded_by consider (obsf_distinguisher \) bound" + if [interaction_bound]: "interaction_bounded_by consider \ bound" + unfolding obsf_distinguisher_def by(rule interaction_bound|simp)+ + +lemma plossless_obsf_distinguisher [simp]: + "plossless_gpv (exception_\ \) (obsf_distinguisher \)" + if "plossless_gpv \ \" "\ \g \ \" + using that unfolding obsf_distinguisher_def by(simp) + + +type_synonym ('a, 'b, 'c, 'd) converter_obsf = "('a, 'b exception, 'c, 'd exception) converter" + +translations + (type) "('a, 'b, 'c, 'd) converter_obsf" <= (type) "('a, 'b exception, 'c, 'd exception) converter" + +primcorec obsf_converter :: "('a, 'b, 'c, 'd) converter \ ('a, 'b, 'c, 'd) converter_obsf" where + "run_converter (obsf_converter conv) = (\x. + map_gpv (map_prod id obsf_converter) id + (map_gpv (\convF. case convF of Fault \ (Fault, fail_converter) | OK (a, conv') \ (OK a, conv')) id + (try_gpv (map_gpv' exception_of_option id option_of_exception (gpv_stop (run_converter conv x))) (Done Fault))))" + +lemma obsf_converter_exception [simp]: "obsf_converter fail_converter = const_converter Fault" + by(coinduction)(simp add: rel_fun_def) + +lemma obsf_converter_sel [simp]: + "run_converter (obsf_converter conv) x = + TRY map_gpv' (\y. case y of None \ (Fault, const_converter Fault) | Some(x, conv') \ (OK x, obsf_converter conv')) id option_of_exception + (gpv_stop (run_converter conv x)) + ELSE Done (Fault, const_converter Fault)" + by(simp add: map_try_gpv) + (simp add: map_gpv_conv_map_gpv' map_gpv'_comp o_def option.case_distrib[where h="map_prod _ _"] split_def id_def cong del: option.case_cong) + +declare obsf_converter.sel [simp del] + +lemma exec_gpv_obsf_resource: + defines "exec_gpv1 \ exec_gpv" + and "exec_gpv2 \ exec_gpv" + shows + "exec_gpv1 run_resource (map_gpv' id id option_of_exception (gpv_stop gpv)) (obsf_resource res) \ {(Some x, y)|x y. True} = + map_spmf (map_prod Some obsf_resource) (exec_gpv2 run_resource gpv res)" + (is "?lhs = ?rhs") +proof(rule spmf.leq_antisym) + show "ord_spmf (=) ?lhs ?rhs" unfolding exec_gpv1_def + proof(induction arbitrary: gpv res rule: exec_gpv_fixp_induct_strong) + case adm show ?case by simp + case bottom show ?case by simp + case (step exec_gpv') + show ?case unfolding exec_gpv2_def + apply(subst exec_gpv.simps) + apply(clarsimp simp add: map_bind_spmf bind_map_spmf restrict_bind_spmf o_def try_spmf_def intro!: ord_spmf_bind_reflI split!: generat.split) + apply(clarsimp simp add: bind_map_pmf bind_spmf_def bind_assoc_pmf bind_return_pmf spmf.leq_trans[OF restrict_spmf_mono, OF step.hyps] id_def step.IH[simplified, simplified id_def exec_gpv2_def] intro!: rel_pmf_bind_reflI split!: option.split) + done + qed + + show "ord_spmf (=) ?rhs ?lhs" unfolding exec_gpv2_def + proof(induction arbitrary: gpv res rule: exec_gpv_fixp_induct) + case adm show ?case by simp + case bottom show ?case by simp + case (step exec_gpv') + show ?case unfolding exec_gpv1_def + apply(subst exec_gpv.simps) + apply(clarsimp simp add: bind_map_spmf map_bind_spmf restrict_bind_spmf o_def try_spmf_def intro!: ord_spmf_bind_reflI split!: generat.split) + apply(clarsimp simp add: bind_spmf_def bind_assoc_pmf bind_map_pmf map_bind_pmf bind_return_pmf id_def step.IH[simplified, simplified id_def exec_gpv1_def] intro!: rel_pmf_bind_reflI split!: option.split) + done + qed +qed + +lemma obsf_attach: + assumes pfinite: "pfinite_converter \ \' conv" + and WT: "\, \' \\<^sub>C conv \" + and WT_resource: "\' \res res \" + shows "outs_\ \ \\<^sub>R attach (obsf_converter conv) (obsf_resource res) \ obsf_resource (attach conv res)" + using assms +proof(coinduction arbitrary: conv res) + case (eq_resource_on out conv res) + then show ?case (is "rel_spmf ?X ?lhs ?rhs") + proof - + have "?lhs = map_spmf (\((b, conv'), res'). (b, conv' \ res')) + (exec_gpv run_resource + (TRY map_gpv' (case_option (Fault, const_converter Fault) (\(x, conv'). (OK x, obsf_converter conv'))) id option_of_exception (gpv_stop (run_converter conv out)) ELSE Done (Fault, const_converter Fault)) + (obsf_resource res))" + (is "_ = map_spmf ?attach (exec_gpv _ (TRY ?gpv ELSE _) _)") by(clarsimp) + also have "\ = TRY map_spmf ?attach (exec_gpv run_resource ?gpv (obsf_resource res)) ELSE return_spmf (Fault, const_resource Fault)" + by(rule run_lossless_resource.exec_gpv_try_gpv[where \="exception_\ \'"]) + (use eq_resource_on in \auto intro!: WT_gpv_map_gpv' WT_gpv_stop pfinite_gpv_stop[THEN iffD2] dest: WT_converterD pfinite_converterD lossless_resourceD\) + also have "\ = TRY map_spmf (\(rc, res'). case rc of None \ (Fault, const_resource Fault) | Some (x, conv') \ (OK x, obsf_converter conv' \ res')) + ((exec_gpv run_resource (map_gpv' id id option_of_exception (gpv_stop (run_converter conv out))) (obsf_resource res)) \ {(Some x, y)|x y. True}) + ELSE return_spmf (Fault, const_resource Fault)" (is "_ = TRY map_spmf ?f _ ELSE ?z") + by(subst map_gpv'_id12)(clarsimp simp add: map_gpv'_map_gpv_swap exec_gpv_map_gpv_id try_spmf_def restrict_spmf_def bind_map_pmf intro!: bind_pmf_cong[OF refl] split: option.split) + also have "\ = TRY map_spmf ?f (map_spmf (map_prod Some obsf_resource) (exec_gpv run_resource (run_converter conv out) res)) ELSE ?z" + by(simp only: exec_gpv_obsf_resource) + also have "rel_spmf ?X \ ?rhs" using eq_resource_on + by(auto simp add: spmf.map_comp o_def spmf_rel_map intro!: rel_spmf_try_spmf rel_spmf_reflI) + (auto intro!: exI dest: run_resource.in_set_spmf_exec_gpv_into_results_gpv WT_converterD pfinite_converterD run_resource.exec_gpv_invariant) + finally show ?case . + qed +qed + + +lemma colossless_obsf_converter [simp]: + "colossless_converter (exception_\ \) \' (obsf_converter conv)" + by(coinduction arbitrary: conv)(auto split: option.split_asm) + + +lemma WT_obsf_converter [WT_intro]: + "exception_\ \, exception_\ \' \\<^sub>C obsf_converter conv \" if "\, \' \\<^sub>C conv \" + using that + by(coinduction arbitrary: conv)(auto 4 3 dest: WT_converterD results_gpv_stop_SomeD split!: option.splits intro!: WT_intro) + +lemma inline1_gpv_stop_obsf_converter: + defines "inline1a \ inline1" + and "inline1b \ inline1" + shows "bind_spmf (inline1a run_converter (map_gpv' id id option_of_exception (gpv_stop gpv)) (obsf_converter conv)) + (\xy. case xy of Inl (None, conv') \ return_pmf None | Inl (Some x, conv') \ return_spmf (Inl (x, conv')) | Inr y \ return_spmf (Inr y)) = + map_spmf (map_sum (apsnd obsf_converter) + (apsnd (map_prod (\rpv input. case input of Fault \ Done (Fault, const_converter Fault) | OK input' \ + map_gpv' (\res. case res of None \ (Fault, const_converter Fault) | Some (x, conv') \ (OK x, obsf_converter conv')) id option_of_exception (try_gpv (gpv_stop (rpv input')) (Done None))) + (\rpv input. case input of Fault \ Done None | OK input' \ map_gpv' id id option_of_exception (gpv_stop (rpv input')))))) + (inline1b run_converter gpv conv)" + (is "?lhs = ?rhs") +proof(rule spmf.leq_antisym) + show "ord_spmf (=) ?lhs ?rhs" unfolding inline1a_def + proof(induction arbitrary: gpv conv rule: inline1_fixp_induct_strong) + case adm show ?case by simp + case bottom show ?case by simp + case (step inline1') + show ?case unfolding inline1b_def + apply(subst inline1_unfold) + apply(clarsimp simp add: map_spmf_bind_spmf bind_map_spmf spmf.map_comp o_def generat.map_comp intro!: ord_spmf_bind_reflI split!: generat.split) + apply(clarsimp simp add: bind_spmf_def try_spmf_def bind_assoc_pmf bind_map_pmf bind_return_pmf intro!: rel_pmf_bind_reflI split!: option.split) + subgoal unfolding bind_spmf_def[symmetric] + by(rule ord_spmf_bindI[OF step.hyps, THEN spmf.leq_trans]) + (auto split!: option.split intro!: ord_spmf_bindI[OF step.hyps, THEN spmf.leq_trans] ord_spmf_reflI) + subgoal unfolding bind_spmf_def[symmetric] + by(clarsimp simp add: in_set_spmf[symmetric] inline1b_def split!: generat.split intro!: step.IH[THEN spmf.leq_trans]) + (auto simp add: fun_eq_iff map'_try_gpv split: exception.split) + done + qed + + show "ord_spmf (=) ?rhs ?lhs" unfolding inline1b_def + proof(induction arbitrary: gpv conv rule: inline1_fixp_induct_strong) + case adm show ?case by simp + case bottom show ?case by simp + case (step inline1') + show ?case unfolding inline1a_def + apply(subst inline1_unfold) + apply(clarsimp simp add: map_spmf_bind_spmf bind_map_spmf spmf.map_comp o_def generat.map_comp intro!: ord_spmf_bind_reflI split!: generat.split) + apply(clarsimp simp add: bind_spmf_def try_spmf_def bind_assoc_pmf bind_map_pmf bind_return_pmf intro!: rel_pmf_bind_reflI split!: option.split) + apply(clarsimp simp add: bind_spmf_def[symmetric] in_set_spmf[symmetric] inline1a_def id_def[symmetric] split!: generat.split intro!: step.IH[THEN spmf.leq_trans]) + apply(auto simp add: fun_eq_iff map'_try_gpv split: exception.split) + done + qed +qed + +lemma inline_gpv_stop_obsf_converter: + "bind_gpv (inline run_converter (map_gpv' id id option_of_exception (gpv_stop gpv)) (obsf_converter conv)) (\(x, conv'). case x of None \ Fail | Some x' \ Done (x, conv')) = + bind_gpv (map_gpv' id id option_of_exception (gpv_stop (inline run_converter gpv conv))) (\x. case x of None \ Fail | Some (x', conv) \ Done (Some x', obsf_converter conv))" +proof(coinduction arbitrary: gpv conv rule: gpv_coinduct_bind) + case (Eq_gpv gpv conv) + show "?case TYPE('c \ ('b, 'c, 'd, 'e) converter) TYPE('c \ ('b, 'c, 'd, 'e) converter)" (is "rel_spmf ?X ?lhs ?rhs") + proof - + have "?lhs = map_spmf (\xyz. case xyz of Inl (x, conv) \ Pure (Some x, conv) | Inr (out, rpv, rpv') \ IO out (\input. bind_gpv (bind_gpv (rpv input) (\(x, y). inline run_converter (rpv' x) y)) (\(x, conv'). case x of None \ Fail | Some x' \ Done (x, conv')))) + (bind_spmf (inline1 run_converter (map_gpv' id id option_of_exception (gpv_stop gpv)) (obsf_converter conv)) + (\xy. case xy of Inl (None, conv') \ return_pmf None | Inl (Some x, conv') \ return_spmf (Inl (x, conv')) | Inr y \ return_spmf (Inr y)))" + (is "_ = map_spmf ?f _") + by(auto simp del: bind_gpv_sel' simp add: bind_gpv.sel map_bind_spmf inline_sel bind_map_spmf o_def intro!: bind_spmf_cong[OF refl] split!: sum.split option.split) + also have "\ = map_spmf ?f (map_spmf (map_sum (apsnd obsf_converter) (apsnd (map_prod (\rpv. case_exception (Done (Fault, const_converter Fault)) + (\input'. map_gpv' (case_option (Fault, const_converter Fault) (\(x, conv'). (OK x, obsf_converter conv'))) id option_of_exception (TRY gpv_stop (rpv input') ELSE Done None))) + (\rpv. case_exception (Done None) (\input'. map_gpv' id id option_of_exception (gpv_stop (rpv input'))))))) + (inline1 run_converter gpv conv))" + by(simp only: inline1_gpv_stop_obsf_converter) + also have "\ = bind_spmf (inline1 run_converter gpv conv) (\y. return_spmf (?f (map_sum (apsnd obsf_converter) + (apsnd (map_prod (\rpv. case_exception (Done (Fault, const_converter Fault)) (\input'. map_gpv' (case_option (Fault, const_converter Fault) (\(x, conv'). (OK x, obsf_converter conv'))) id option_of_exception (TRY gpv_stop (rpv input') ELSE Done None))) + (\rpv. case_exception (Done None) (\input'. map_gpv' id id option_of_exception (gpv_stop (rpv input')))))) + y)))" + by(simp add: map_spmf_conv_bind_spmf) + also have "rel_spmf ?X \ (bind_spmf (inline1 run_converter gpv conv) + (\x. map_spmf (map_generat id id ((\) (case_sum id (\r. bind_gpv r (case_option Fail (\(x', conv). Done (Some x', obsf_converter conv))))))) + (case map_generat id id (map_fun option_of_exception (map_gpv' id id option_of_exception)) + (map_generat Some id (\rpv. case_option (Done None) (\input'. gpv_stop (rpv input'))) + (case x of Inl x \ Pure x + | Inr (out, oracle, rpv) \ IO out (\input. bind_gpv (oracle input) (\(x, y). inline run_converter (rpv x) y)))) of + Pure x \ + map_spmf (map_generat id id ((\) Inl)) (the_gpv (case x of None \ Fail | Some (x', conv) \ Done (Some x', obsf_converter conv))) + | IO out c \ return_spmf (IO out (\input. Inr (c input))))))" + (is "rel_spmf _ _ ?rhs2" is "rel_spmf _ (bind_spmf _ ?L) (bind_spmf _ ?R)") + proof(rule rel_spmf_bind_reflI) + fix x :: "'a \ ('b, 'c, 'd, 'e) converter + 'd \ ('c \ ('b, 'c, 'd, 'e) converter, 'd, 'e) rpv \ ('a, 'b, 'c) rpv" + assume x: "x \ set_spmf (inline1 run_converter gpv conv)" + consider (Inl) a conv' where "x = Inl (a, conv')" | (Inr) out rpv rpv' where "x = Inr (out, rpv, rpv')" by(cases x) auto + then show "rel_spmf ?X (?L x) (?R x)" + proof cases + case Inr + have "\(gpv2 :: ('c \ ('b, 'c, 'd, 'e) converter, 'd, 'e exception) gpv) (gpv2' :: ('c \ ('b, 'c, 'd, 'e) converter, 'd, 'e exception) gpv) f f'. + bind_gpv (map_gpv' (case_option (Fault, const_converter Fault) (\p. (OK (fst p), obsf_converter (snd p)))) id option_of_exception (TRY gpv_stop (rpv input) ELSE Done None)) + (\x. case fst x of Fault \ Fail | OK xa \ bind_gpv (inline run_converter (map_gpv' id id option_of_exception (gpv_stop (rpv' xa))) (snd x)) (\p. case fst p of None \ Fail | Some x' \ Done (Some x', snd p))) = + bind_gpv gpv2 f \ + bind_gpv (map_gpv' id id option_of_exception (gpv_stop (rpv input))) (case_option Fail (\x. bind_gpv (map_gpv' id id option_of_exception (gpv_stop (inline run_converter (rpv' (fst x)) (snd x)))) (case_option Fail (\p. Done (Some (fst p), obsf_converter (snd p)))))) = + bind_gpv gpv2' f' \ + rel_gpv (\x y. \gpv conv. f x = bind_gpv (inline run_converter (map_gpv' id id option_of_exception (gpv_stop gpv)) (obsf_converter conv)) (\p. case fst p of None \ Fail | Some x' \ Done (Some x', snd p)) \ + f' y = bind_gpv (map_gpv' id id option_of_exception (gpv_stop (inline run_converter gpv conv))) (case_option Fail (\p. Done (Some (fst p), obsf_converter (snd p))))) + (=) gpv2 gpv2'" + (is "\gpv2 gpv2' f f'. ?lhs1 input = _ \ ?rhs1 input = _ \ rel_gpv (?X f f') _ _ _") for input + proof(intro exI conjI) + let ?gpv2 = "bind_gpv (map_gpv' id id option_of_exception (TRY gpv_stop (rpv input) ELSE Done None)) (\x. case x of None \ Fail | Some x \ Done x)" + let ?gpv2' = "bind_gpv (map_gpv' id id option_of_exception (gpv_stop (rpv input))) (\x. case x of None \ Fail | Some x \ Done x)" + let ?f = "\x. bind_gpv (inline run_converter (map_gpv' id id option_of_exception (gpv_stop (rpv' (fst x)))) (obsf_converter (snd x))) (\p. case fst p of None \ Fail | Some x' \ Done (Some x', snd p))" + let ?f' = "\x. bind_gpv (map_gpv' id id option_of_exception (gpv_stop (inline run_converter (rpv' (fst x)) (snd x)))) (case_option Fail (\p. Done (Some (fst p), obsf_converter (snd p))))" + show "?lhs1 input = bind_gpv ?gpv2 ?f" + by(subst map_gpv'_id12[THEN trans, OF map_gpv'_map_gpv_swap]) + (auto simp add: bind_map_gpv o_def bind_gpv_assoc intro!: bind_gpv_cong split!: option.split) + show "?rhs1 input = bind_gpv ?gpv2' ?f'" + by(auto simp add: bind_gpv_assoc id_def[symmetric] intro!: bind_gpv_cong split!: option.split) + show "rel_gpv (?X ?f ?f') (=) ?gpv2 ?gpv2'" using Inr x + by(auto simp add: map'_try_gpv id_def[symmetric] bind_try_Done_Fail intro: gpv.rel_refl_strong) + qed + then show ?thesis using Inr + by(clarsimp split!: sum.split exception.split simp add: rel_fun_def bind_gpv_assoc split_def map_gpv'_bind_gpv exception.case_distrib[where h="\x. bind_gpv (inline _ x _) _"] option.case_distrib[where h="\x. bind_gpv (map_gpv' _ _ _ x) _"] cong: exception.case_cong option.case_cong) + qed simp + qed + moreover have "?rhs2 = ?rhs" + by(simp del: bind_gpv_sel' add: bind_gpv.sel map_bind_spmf inline_sel bind_map_spmf o_def) + ultimately show ?thesis by(simp only:) + qed +qed + +lemma obsf_comp_converter: + assumes WT: "\, \' \\<^sub>C conv1 \" "\', \'' \\<^sub>C conv2 \" + and pfinite1: "pfinite_converter \ \' conv1" + shows "exception_\ \, exception_\ \'' \\<^sub>C obsf_converter (comp_converter conv1 conv2) \ comp_converter (obsf_converter conv1) (obsf_converter conv2)" + using WT pfinite1 supply eq_\_gpv_map_gpv[simp del] +proof(coinduction arbitrary: conv1 conv2) + case eq_\_converter + show ?case (is "eq_\_gpv ?X _ ?lhs ?rhs") + proof - + have "eq_\_gpv (=) (exception_\ \'') ?rhs (TRY map_gpv (\((b, conv1'), conv2'). (b, conv1' \ conv2')) id + (inline run_converter + (map_gpv' + (case_option (Fault, const_converter Fault) + (\(x, conv'). (OK x, obsf_converter conv'))) + id option_of_exception (gpv_stop (run_converter conv1 q))) + (obsf_converter conv2)) ELSE Done (Fault, const_converter Fault))" + (is "eq_\_gpv _ _ _ ?rhs2" is "eq_\_gpv _ _ _ (try_gpv (map_gpv ?f _ ?inline) ?else)") + using eq_\_converter + apply simp + apply(rule run_colossless_converter.inline_try_gpv[where \="exception_\ \'"]) + apply(auto intro!: WT_intro pfinite_gpv_stop[THEN iffD2] dest: WT_converterD pfinite_converterD colossless_converterD) + done + term "bind_gpv (inline run_converter (map_gpv' id id option_of_exception (gpv_stop (run_converter conv1 q))) (obsf_converter conv2)) + (\(x, conv'). case x of None \ Fail | Some x' \ Done (x, conv'))" + + also have "?rhs2 = try_gpv (map_gpv ?f id + (map_gpv (\(xo, conv'). case xo of None \ ((Fault, const_converter Fault), conv') | Some (x, conv) \ ((OK x, obsf_converter conv), conv')) id + (bind_gpv (inline run_converter (map_gpv' id id option_of_exception (gpv_stop (run_converter conv1 q))) (obsf_converter conv2)) + (\(x, conv'). case x of None \ Fail | Some x' \ Done (x, conv'))))) + ?else" + apply(simp add: map_gpv_bind_gpv gpv.map_id) + apply(subst try_gpv_bind_gpv) + apply(simp add: split_def option.case_distrib[where h="map_gpv _ _"] option.case_distrib[where h="fst"] option.case_distrib[where h="\x. try_gpv x _"] cong del: option.case_cong) + apply(subst option.case_distrib[where h=Done, symmetric, abs_def])+ + apply(fold map_gpv_conv_bind) + apply(simp add: map_try_gpv gpv.map_comp o_def) + apply(rule try_gpv_cong) + apply(subst map_gpv'_id12) + apply(subst map_gpv'_map_gpv_swap) + apply(simp add: inline_map_gpv gpv.map_comp id_def[symmetric]) + apply(rule gpv.map_cong[OF refl]) + apply(auto split: option.split) + done + also have "\ = try_gpv (map_gpv ?f id + (map_gpv (\(xo, conv'). case xo of None \ ((Fault, const_converter Fault), conv') | Some (x, conv) \ ((OK x, obsf_converter conv), conv')) id +(bind_gpv + (map_gpv' id id option_of_exception + (gpv_stop (inline run_converter (run_converter conv1 q) conv2))) + (case_option Fail + (\(x', conv). + Done + (Some x', + obsf_converter + conv)))))) ?else" + by(simp only: inline_gpv_stop_obsf_converter) + also have "eq_\_gpv ?X (exception_\ \'') ?lhs \" using eq_\_converter + apply simp + apply(simp add: map_gpv_bind_gpv gpv.map_id) + apply(subst try_gpv_bind_gpv) + apply(simp add: split_def option.case_distrib[where h="map_gpv _ _"] option.case_distrib[where h="fst"] option.case_distrib[where h="\x. try_gpv x _"] cong del: option.case_cong) + apply(subst option.case_distrib[where h=Done, symmetric, abs_def])+ + apply(fold map_gpv_conv_bind) + apply(simp add: map_try_gpv gpv.map_comp o_def) + apply(rule eq_\_gpv_try_gpv_cong) + apply(subst map_gpv'_id12) + apply(subst map_gpv'_map_gpv_swap) + apply(simp add: eq_\_gpv_map_gpv id_def[symmetric]) + apply(subst map_gpv_conv_map_gpv') + apply(subst gpv_stop_map') + apply(subst option.map_id0) + apply(subst map_gpv_conv_map_gpv'[symmetric]) + apply(subst map_gpv'_map_gpv_swap) + apply(simp add: eq_\_gpv_map_gpv id_def[symmetric]) + apply(rule eq_\_gpv_reflI) + apply(clarsimp split!: option.split simp add: eq_onp_def) + apply(erule notE) + apply(rule eq_\_converter_reflI) + apply simp + apply(drule results_gpv_stop_SomeD) + apply(rule conjI) + apply(rule imageI) + apply(drule run_converter.results_gpv_inline) + apply(erule (1) WT_converterD) + apply simp + apply clarsimp + apply(drule (2) WT_converterD_results) + apply simp + apply(rule disjI1) + apply(rule exI conjI refl)+ + apply(drule run_converter.results_gpv_inline) + apply(erule (1) WT_converterD) + apply simp + apply clarsimp + apply(drule (2) WT_converterD_results) + apply simp + apply(drule run_converter.results_gpv_inline) + apply(erule (1) WT_converterD) + apply simp + apply clarsimp + apply(drule (1) pfinite_converterD) + apply blast + apply(rule WT_intro run_converter.WT_gpv_inline_invar|simp)+ + apply(erule (1) WT_converterD) + apply simp + apply(simp add: eq_onp_def) + apply(rule disjI2) + apply(rule eq_\_converter_reflI) + apply simp + done + finally (eq_\_gpv_eq_OO2) show ?thesis . + qed +qed + +lemma resource_of_obsf_oracle_Fault [simp]: + "resource_of_oracle (obsf_oracle oracle) Fault = const_resource Fault" + by(coinduction)(auto simp add: rel_fun_def) + +lemma obsf_resource_of_oracle [simp]: + "obsf_resource (resource_of_oracle oracle s) = resource_of_oracle (obsf_oracle oracle) (OK s)" + by(coinduction arbitrary: s rule: resource.coinduct_strong) + (auto 4 3 simp add: rel_fun_def map_try_spmf spmf_rel_map intro!: rel_spmf_try_spmf rel_spmf_reflI) + +lemma trace_callee_eq_obsf_Fault [simp]: "A \\<^sub>C obsf_oracle callee1(Fault) \ obsf_oracle callee2(Fault)" + by(coinduction rule: trace_callee_eq_coinduct) auto + +lemma obsf_resource_eq_\_cong: "A \\<^sub>R obsf_resource res1 \ obsf_resource res2" if "A \\<^sub>R res1 \ res2" + using that by(coinduction arbitrary: res1 res2)(fastforce intro!: rel_spmf_try_spmf simp add: spmf_rel_map elim!: rel_spmf_mono dest: eq_resource_onD) + +lemma trace_callee_eq_obsf_oracleI: + assumes "trace_callee_eq callee1 callee2 A p q" + shows "trace_callee_eq (obsf_oracle callee1) (obsf_oracle callee2) A (try_spmf (map_spmf OK p) (return_spmf Fault)) (try_spmf (map_spmf OK q) (return_spmf Fault))" + using assms +proof(coinduction arbitrary: p q rule: trace_callee_eq_coinduct_strong) + case (step z p q) + have "?lhs = map_pmf (\x. case x of None \ Some Fault | Some y \ Some (OK y)) (bind_spmf p (\s'. map_spmf fst (callee1 s' z)))" + by(auto simp add: bind_spmf_def try_spmf_def bind_assoc_pmf map_bind_pmf bind_map_pmf bind_return_pmf option.case_distrib[where h="map_pmf _"] option.case_distrib[where h=return_pmf, symmetric, abs_def] map_pmf_def[symmetric] pmf.map_comp o_def intro!: bind_pmf_cong[OF refl] pmf.map_cong[OF refl] split: option.split) + also have "bind_spmf p (\s'. map_spmf fst (callee1 s' z)) = bind_spmf q (\s'. map_spmf fst (callee2 s' z))" + using step(1)[THEN trace_callee_eqD[where xs="[]" and x=z]] step(2) by simp + also have "map_pmf (\x. case x of None \ Some Fault | Some y \ Some (OK y)) \ = ?rhs" + by(auto simp add: bind_spmf_def try_spmf_def bind_assoc_pmf map_bind_pmf bind_map_pmf bind_return_pmf option.case_distrib[where h="map_pmf _"] option.case_distrib[where h=return_pmf, symmetric, abs_def] map_pmf_def[symmetric] pmf.map_comp o_def intro!: bind_pmf_cong[OF refl] pmf.map_cong[OF refl] split: option.split) + finally show ?case . +next + case (sim x s1 s2 ye s1' s2' p q) + have eq1: "bind_spmf (try_spmf (map_spmf OK p) (return_spmf Fault)) (\s. obsf_oracle callee1 s x) = + try_spmf (bind_spmf p (\s. map_spmf (map_prod OK OK) (callee1 s x))) (return_spmf (Fault, Fault))" + by(auto simp add: bind_spmf_def try_spmf_def bind_assoc_pmf bind_map_pmf bind_return_pmf intro!: bind_pmf_cong[OF refl] split: option.split) + have eq2: "bind_spmf (try_spmf (map_spmf OK q) (return_spmf Fault)) (\s. obsf_oracle callee2 s x) = + try_spmf (bind_spmf q (\s. map_spmf (map_prod OK OK) (callee2 s x))) (return_spmf (Fault, Fault))" + by(auto simp add: bind_spmf_def try_spmf_def bind_assoc_pmf bind_map_pmf bind_return_pmf intro!: bind_pmf_cong[OF refl] split: option.split) + + show ?case + proof(cases ye) + case [simp]: Fault + have "lossless_spmf (bind_spmf p (\s. map_spmf (map_prod OK OK) (callee1 s x))) \ lossless_spmf (bind_spmf q (\s. map_spmf (map_prod OK OK) (callee2 s x)))" + using sim(1)[THEN trace_callee_eqD[where xs="[]" and x=x], THEN arg_cong[where f="lossless_spmf"]] sim(2) by simp + then have "?eq" by(simp add: eq1 eq2)(subst (1 2) cond_spmf_fst_try2, auto) + then show ?thesis .. + next + case [simp]: (OK y) + have eq3: "fst ` set_spmf (bind_spmf p (\s. callee1 s x)) = fst ` set_spmf (bind_spmf q (\s. callee2 s x))" + using trace_callee_eqD[OF sim(1) _ sim(2), where xs="[]", THEN arg_cong[where f="set_spmf"]] + by(auto simp add: bind_UNION image_UN del: equalityI) + show ?thesis + proof(cases "y \ fst ` set_spmf (bind_spmf p (\s. callee1 s x))") + case True + have eq4: "cond_spmf_fst (bind_spmf p (\s. map_spmf (apfst OK) (callee1 s x))) (OK y) = cond_spmf_fst (bind_spmf p (\s. callee1 s x)) y" + "cond_spmf_fst (bind_spmf q (\s. map_spmf (apfst OK) (callee2 s x))) (OK y) = cond_spmf_fst (bind_spmf q (\s. callee2 s x)) y" + by(fold map_bind_spmf[unfolded o_def])(simp_all add: cond_spmf_fst_map_inj) + have ?sim + unfolding eq1 eq2 + apply(subst (1 2) cond_spmf_fst_try1) + apply simp + apply simp + apply(rule exI[where x="cond_spmf_fst (bind_spmf p (\s. map_spmf (apfst OK) (callee1 s x))) ye"]) + apply(rule exI[where x="cond_spmf_fst (bind_spmf q (\s. map_spmf (apfst OK) (callee2 s x))) ye"]) + apply(subst (1 2) try_spmf_lossless) + subgoal using True unfolding eq3 by(auto simp add: bind_UNION image_UN intro!: rev_bexI rev_image_eqI) + subgoal using True by(auto simp add: bind_UNION image_UN intro!: rev_bexI rev_image_eqI) + apply(simp add: map_cond_spmf_fst map_bind_spmf o_def spmf.map_comp map_prod_def split_def) + apply(simp add: eq4) + apply(rule trace_callee_eqI) + subgoal for xs z + using sim(1)[THEN trace_callee_eqD[where xs="(x, y) # xs" and x=z]] sim(2) + apply simp + done + done + then show ?thesis .. + next + case False + with eq3 have "y \ fst ` set_spmf (bind_spmf q (\s. callee2 s x))" by auto + with False have ?eq + apply simp + apply(subst (1 2) cond_spmf_fst_eq_return_None[THEN iffD2]) + apply(auto simp add: bind_UNION split: if_split_asm intro: rev_image_eqI) + done + then show ?thesis .. + qed + qed +qed + +lemma trace_callee_eq'_obsf_resourceI: + assumes " A \\<^sub>C callee1(s) \ callee2(s')" + shows "A \\<^sub>C obsf_oracle callee1(OK s) \ obsf_oracle callee2(OK s')" + using assms[THEN trace_callee_eq_obsf_oracleI] by simp + +lemma trace_eq_obsf_resourceI: + assumes "A \\<^sub>R res1 \ res2" + shows "A \\<^sub>R obsf_resource res1 \ obsf_resource res2" + using assms + apply(subst (2 4) resource_of_oracle_run_resource[symmetric]) + apply(subst (asm) (1 2) resource_of_oracle_run_resource[symmetric]) + apply(drule trace_callee_eq'_obsf_resourceI) + apply simp + apply(simp add: resource_of_oracle_run_resource) + done + +lemma spmf_run_obsf_oracle_obsf_distinguisher [rule_format]: + defines "eg1 \ exec_gpv" and "eg2 \ exec_gpv" shows + "spmf (map_spmf fst (eg1 (obsf_oracle oracle) (obsf_distinguisher gpv) (OK s))) True = + spmf (map_spmf fst (eg2 oracle gpv s)) True" + (is "?lhs = ?rhs") +proof(rule antisym) + show "?lhs \ ?rhs" unfolding eg1_def + proof(induction arbitrary: gpv s rule: exec_gpv_fixp_induct_strong) + case adm show ?case by simp + case bottom show ?case by simp + case (step exec_gpv') + show ?case unfolding eg2_def + apply(subst exec_gpv.simps) + apply(clarsimp simp add: obsf_distinguisher_def bind_map_spmf map_bind_spmf o_def) + apply(subst (1 2) spmf_bind) + apply(rule Bochner_Integration.integral_mono) + apply(rule measure_spmf.integrable_const_bound[where B=1]; simp add: pmf_le_1) + apply(rule measure_spmf.integrable_const_bound[where B=1]; simp add: pmf_le_1) + apply(clarsimp split: generat.split simp add: map_bind_spmf o_def) + apply(simp add: try_spmf_def bind_spmf_pmf_assoc bind_map_pmf) + apply(simp add: bind_spmf_def) + apply(subst (1 2) pmf_bind) + apply(rule Bochner_Integration.integral_mono) + apply(rule measure_pmf.integrable_const_bound[where B=1]; simp add: pmf_le_1) + apply(rule measure_pmf.integrable_const_bound[where B=1]; simp add: pmf_le_1) + apply(clarsimp split!: option.split simp add: bind_return_pmf) + apply(rule antisym) + apply(rule order_trans) + apply(rule step.hyps[THEN ord_spmf_map_spmfI, THEN ord_spmf_eq_leD]) + apply simp + apply(simp) + apply(rule step.IH[unfolded eg2_def obsf_distinguisher_def]) + done + qed + + show "?rhs \ ?lhs" unfolding eg2_def + proof(induction arbitrary: gpv s rule: exec_gpv_fixp_induct_strong) + case adm show ?case by simp + case bottom show ?case by simp + case (step exec_gpv') + show ?case unfolding eg1_def + apply(subst exec_gpv.simps) + apply(clarsimp simp add: obsf_distinguisher_def bind_map_spmf map_bind_spmf o_def) + apply(subst (1 2) spmf_bind) + apply(rule Bochner_Integration.integral_mono) + apply(rule measure_spmf.integrable_const_bound[where B=1]; simp add: pmf_le_1) + apply(rule measure_spmf.integrable_const_bound[where B=1]; simp add: pmf_le_1) + apply(clarsimp split: generat.split simp add: map_bind_spmf o_def) + apply(simp add: try_spmf_def bind_spmf_pmf_assoc bind_map_pmf) + apply(simp add: bind_spmf_def) + apply(subst (1 2) pmf_bind) + apply(rule Bochner_Integration.integral_mono) + apply(rule measure_pmf.integrable_const_bound[where B=1]; simp add: pmf_le_1) + apply(rule measure_pmf.integrable_const_bound[where B=1]; simp add: pmf_le_1) + apply(clarsimp split!: option.split simp add: bind_return_pmf) + apply(rule step.IH[unfolded eg1_def obsf_distinguisher_def]) + done + qed +qed + +lemma spmf_obsf_distinguisher_obsf_resource_True: + "spmf (connect_obsf (obsf_distinguisher \) (obsf_resource res)) True = spmf (connect \ res) True" + unfolding connect_def + apply(subst (2) resource_of_oracle_run_resource[symmetric]) + apply(simp add: exec_gpv_resource_of_oracle spmf.map_comp spmf_run_obsf_oracle_obsf_distinguisher) + done + +lemma advantage_obsf_distinguisher: + "advantage (obsf_distinguisher \) (obsf_resource ideal_resource) (obsf_resource real_resource) = + advantage \ ideal_resource real_resource" + unfolding advantage_def by(simp add: spmf_obsf_distinguisher_obsf_resource_True) + +end diff --git a/thys/Constructive_Cryptography_CM/ROOT b/thys/Constructive_Cryptography_CM/ROOT new file mode 100644 --- /dev/null +++ b/thys/Constructive_Cryptography_CM/ROOT @@ -0,0 +1,15 @@ +chapter AFP + +session Constructive_Cryptography_CM (AFP) = Constructive_Cryptography + + options [timeout = 1500] + sessions + "Game_Based_Crypto" + "Sigma_Commit_Crypto" + directories + "Constructions" + "Specifications" + theories + "Constructions/DH_OTP" + document_files + "root.tex" + "root.bib" diff --git a/thys/Constructive_Cryptography_CM/Specifications/Channel.thy b/thys/Constructive_Cryptography_CM/Specifications/Channel.thy new file mode 100644 --- /dev/null +++ b/thys/Constructive_Cryptography_CM/Specifications/Channel.thy @@ -0,0 +1,183 @@ +theory Channel + imports + "../Fused_Resource" +begin + +section \Channel specification\ + +locale ideal_channel = + fixes + (*TODO: decide to either include or exlude this fixation, + - if it is not included, then the types must be manually stated whenever channel locale is imported (c.f. OTP and DH) + - also, the WT_intro rules for channel will have an unspecified valid_messages*) + (* valid_messages :: "'msg set" and*) + leak :: "'msg \ 'leak" and + editable :: bool +begin + + +subsection \Data-types for Parties, State, Events, Input, and Output\ + +datatype party = Alice | Bob + +type_synonym s_shell = "party set" +datatype 'msg' s_kernel = State_Void | State_Store 'msg' | State_Collect 'msg' | State_Collected +type_synonym 'msg' state = "'msg' s_kernel \ s_shell" + +datatype event = Event_Shell party + +datatype iadv_drop = Inp_Drop +datatype iadv_look = Inp_Look +datatype 'msg' iadv_fedit = Inp_Fedit 'msg' +type_synonym 'msg' iadv = "iadv_drop + iadv_look + 'msg' iadv_fedit" + +datatype 'msg' iusr_alice = Inp_Send 'msg' +datatype iusr_bob = Inp_Recv +type_synonym 'msg' iusr = "'msg' iusr_alice + iusr_bob" + +datatype oadv_drop = Out_Drop +datatype 'leak' oadv_look = Out_Look 'leak' +datatype oadv_fedit = Out_Fedit +type_synonym 'leak' oadv = "oadv_drop + 'leak' oadv_look + oadv_fedit" + +datatype ousr_alice = Out_Send +datatype 'msg' ousr_bob = Out_Recv 'msg' +type_synonym 'msg' ousr = "ousr_alice + 'msg' ousr_bob" + + +subsubsection \Basic lemmas for automated handling of party sets (i.e. @{text s_shell})\ + +lemma Alice_neq_iff [simp]: "Alice \ x \ x = Bob" + by(cases x) simp_all + +lemma neq_Alice_iff [simp]: "x \ Alice \ x = Bob" + by(cases x) simp_all + +lemma Bob_neq_iff [simp]: "Bob \ x \ x = Alice" + by(cases x) simp_all + +lemma neq_Bob_iff [simp]: "x \ Bob \ x = Alice" + by(cases x) simp_all + +lemma Alice_in_iff_nonempty: "Alice \ A \ A \ {}" if "Bob \ A" + using that by(auto)(metis (full_types) party.exhaust) + +lemma Bob_in_iff_nonempty: "Bob \ A \ A \ {}" if "Alice \ A" + using that by(auto)(metis (full_types) party.exhaust) + + +subsection \Defining the event handler\ + +fun poke :: "('msg state, event) handler" + where + "poke (s_kernel, parties) (Event_Shell party) = + (if party \ parties then + return_pmf None + else + return_spmf (s_kernel, insert party parties))" + +lemma poke_alt_def: + "poke = (\(s, ps) e. map_spmf (Pair s) (case e of Event_Shell party \ if party \ ps then return_pmf None else return_spmf (insert party ps)))" + by(simp add: fun_eq_iff split: event.split) + +subsection \Defining the adversary interfaces\ + +fun iface_drop :: "('msg state, iadv_drop, oadv_drop) oracle'" + where + "iface_drop _ _ = return_pmf None" + +fun iface_look :: "('msg state, iadv_look, 'leak oadv_look) oracle'" + where + "iface_look (State_Store msg, parties) _ = + return_spmf (Out_Look (leak msg), State_Store msg, parties)" + | "iface_look _ _ = return_pmf None" + +fun iface_fedit :: "('msg state, 'msg iadv_fedit, oadv_fedit) oracle'" + where + "iface_fedit (State_Store msg, parties) (Inp_Fedit msg') = + (if editable then + return_spmf (Out_Fedit, State_Collect msg', parties) + else + return_spmf (Out_Fedit, State_Collect msg, parties))" + | "iface_fedit _ _ = return_pmf None" + +abbreviation iface_adv :: "('msg state, 'msg iadv, 'leak oadv) oracle'" + where + "iface_adv \ plus_oracle iface_drop (plus_oracle iface_look iface_fedit)" + +lemma in_set_spmf_iface_drop: "ys' \ set_spmf (iface_drop s x) \ False" + by simp + +lemma in_set_spmf_iface_look: "ys' \ set_spmf (iface_look s x) \ + (\msg parties. s = (State_Store msg, parties) \ ys' = (Out_Look (leak msg), State_Store msg, parties))" + by(cases "(s, x)" rule: iface_look.cases) simp_all + +lemma in_set_spmf_iface_fedit: "ys' \ set_spmf (iface_fedit s x) \ + (\msg parties msg'. s = (State_Store msg, parties) \ x = (Inp_Fedit msg') \ + ys' = (if editable then (Out_Fedit, State_Collect msg', parties) else (Out_Fedit, State_Collect msg, parties)))" + by(cases "(s, x)" rule: iface_fedit.cases) simp_all + +subsection \Defining the user interfaces\ + +fun iface_alice :: "('msg state, 'msg iusr_alice, ousr_alice) oracle'" + where + "iface_alice (State_Void, parties) (Inp_Send msg) = + (if Alice \ parties then + return_spmf (Out_Send, State_Store msg, parties) + else + return_pmf None)" + | "iface_alice _ _ = return_pmf None" + +fun iface_bob :: "('msg state, iusr_bob, 'msg ousr_bob) oracle'" + where + "iface_bob (State_Collect msg, parties) _ = + (if Bob \ parties then + return_spmf (Out_Recv msg, State_Collected, parties) + else + return_pmf None)" + | "iface_bob _ _ = return_pmf None" + +abbreviation iface_usr :: "('msg state, 'msg iusr, 'msg ousr) oracle'" + where + "iface_usr \ plus_oracle iface_alice iface_bob" + +lemma in_set_spmf_iface_alice: "ys' \ set_spmf (iface_alice s x) \ + (\parties msg. s = (State_Void, parties) \ x = Inp_Send msg \ Alice \ parties \ ys' = (Out_Send, State_Store msg, parties))" + by(cases "(s, x)" rule: iface_alice.cases) simp_all + +lemma in_set_spmf_iface_bob: "ys' \ set_spmf (iface_bob s x) \ + (\msg parties. s = (State_Collect msg, parties) \ Bob \ parties \ ys' = (Out_Recv msg, State_Collected, parties))" + by(cases "(s, x)" rule: iface_bob.cases) simp_all + +subsection \Defining the Fused Resource\ + +primcorec core :: "('msg state, event, 'msg iadv, 'msg iusr, 'leak oadv, 'msg ousr) core" + where + "cpoke core = poke" + | "cfunc_adv core = iface_adv" + | "cfunc_usr core = iface_usr" + +sublocale fused_resource core "(State_Void, {})" . + + +subsubsection \Lemma showing that the resulting resource is well-typed\ + +lemma WT_core [WT_intro]: + "WT_core (\_full \\<^sub>\ (\_full \\<^sub>\ \_uniform (Inp_Fedit ` valid_messages) UNIV)) (\_uniform (Inp_Send ` valid_messages) UNIV \\<^sub>\ (\_uniform UNIV (Out_Recv ` valid_messages))) + (pred_prod (pred_s_kernel (\msg. msg \ valid_messages)) (\_. True)) core" + apply(rule WT_core.intros) + subgoal for s e s' by(cases "(s, e)" rule: poke.cases)(auto split: if_split_asm) + subgoal for s x y s' by(cases "(s, projl (projr x))" rule: iface_look.cases)(auto split: if_split_asm) + subgoal for s x y s' by(cases "(s, projl x)" rule: iface_alice.cases)(auto split: if_split_asm) + done + +lemma WT_fuse [WT_intro]: + assumes [WT_intro]: "WT_rest \_adv_rest \_usr_rest I_rest rest" + shows "((\_full \\<^sub>\ (\_full \\<^sub>\ \_uniform (Inp_Fedit ` valid_messages) UNIV)) \\<^sub>\ \_adv_rest) \\<^sub>\ + ((\_uniform (Inp_Send ` valid_messages) UNIV \\<^sub>\ \_uniform UNIV (Out_Recv ` valid_messages)) \\<^sub>\ \_usr_rest) \res resource rest \" + by(rule WT_intro)+ simp + + +end + +end diff --git a/thys/Constructive_Cryptography_CM/Specifications/Key.thy b/thys/Constructive_Cryptography_CM/Specifications/Key.thy new file mode 100644 --- /dev/null +++ b/thys/Constructive_Cryptography_CM/Specifications/Key.thy @@ -0,0 +1,151 @@ +theory Key + imports + "../Fused_Resource" +begin + + +section \Key specification\ + +locale ideal_key = + fixes valid_keys :: "'key set" +begin + +subsection \Data-types for Parties, State, Events, Input, and Output\ + +datatype party = Alice | Bob + +type_synonym s_shell = "party set" +datatype 'key' s_kernel = PState_Store | State_Store 'key' +type_synonym 'key' state = "'key' s_kernel \ s_shell" + +datatype event = Event_Shell party | Event_Kernel + +datatype iadv = Inp_Adversary + +datatype iusr_alice = Inp_Alice +datatype iusr_bob = Inp_Bob +type_synonym iusr = "iusr_alice + iusr_bob" + +datatype oadv = Out_Adversary + +datatype 'key' ousr_alice = Out_Alice 'key' +datatype 'key' ousr_bob = Out_Bob 'key' +type_synonym 'key' ousr = "'key' ousr_alice + 'key' ousr_bob" + + +subsubsection \Basic lemmas for automated handling of party sets (i.e. @{text s_shell})\ + +lemma Alice_neq_iff [simp]: "Alice \ x \ x = Bob" + by(cases x) simp_all + +lemma neq_Alice_iff [simp]: "x \ Alice \ x = Bob" + by(cases x) simp_all + +lemma Bob_neq_iff [simp]: "Bob \ x \ x = Alice" + by(cases x) simp_all + +lemma neq_Bob_iff [simp]: "x \ Bob \ x = Alice" + by(cases x) simp_all + +lemma Alice_in_iff_nonempty: "Alice \ A \ A \ {}" if "Bob \ A" + using that by(auto)(metis (full_types) party.exhaust) + +lemma Bob_in_iff_nonempty: "Bob \ A \ A \ {}" if "Alice \ A" + using that by(auto)(metis (full_types) party.exhaust) + + +subsection \Defining the event handler\ + +fun poke :: "('key state, event) handler" + where + "poke (s_kernel, parties) (Event_Shell party) = + (if party \ parties then + return_pmf None + else + return_spmf (s_kernel, insert party parties))" + | "poke (PState_Store, s_shell) (Event_Kernel) = do { + key \ spmf_of_set valid_keys; + return_spmf (State_Store key, s_shell) } " + | "poke _ _ = return_pmf None" + +lemma in_set_spmf_poke: + "s' \ set_spmf (poke s x) \ + (\s_kernel parties party. s = (s_kernel, parties) \ x = Event_Shell party \ party \ parties \ s' = (s_kernel, insert party parties)) \ + (\s_shell key. s = (PState_Store, s_shell) \ x = Event_Kernel \ key \ valid_keys \ finite valid_keys \ s' = (State_Store key, s_shell))" + by(cases "(s, x)" rule: poke.cases)(auto simp add: set_spmf_of_set) + +lemma foldl_poke_invar: + "\ (s_kernel', parties') \ set_spmf (foldl_spmf poke p events); \(s_kernel, parties)\set_spmf p. set_s_kernel s_kernel \ valid_keys \ + \ set_s_kernel s_kernel' \ valid_keys" + by(induction events arbitrary: parties' rule: rev_induct) + (auto 4 3 simp add: split_def foldl_spmf_append in_set_spmf_poke dest: bspec) + +subsection \Defining the adversary interface\ + +fun iface_adv :: "('key state, iadv, oadv) oracle'" + where + "iface_adv state _ = return_spmf (Out_Adversary, state)" + + +subsection \Defining the user interfaces\ + +context +begin + +private fun iface_usr_func :: "party \ _ \ _ \ 'inp \ ('wrap_key \ 'key state) spmf" + where + "iface_usr_func party wrap (State_Store key, parties) inp = + (if party \ parties then + return_spmf (wrap key, State_Store key, parties) + else + return_pmf None)" + | "iface_usr_func _ _ _ _ = return_pmf None" + +abbreviation iface_alice :: "('key state, iusr_alice, 'key ousr_alice) oracle'" + where + "iface_alice \ iface_usr_func Alice Out_Alice" + +abbreviation iface_bob :: "('key state, iusr_bob, 'key ousr_bob) oracle'" + where + "iface_bob \ iface_usr_func Bob Out_Bob" + +abbreviation iface_usr :: "('key state, iusr, 'key ousr) oracle'" + where + "iface_usr \ plus_oracle iface_alice iface_bob" + +lemma in_set_iface_usr_func [simp]: + "x \ set_spmf (iface_usr_func party wrap state inp) \ + (\key parties. state = (State_Store key, parties) \ party \ parties \ x = (wrap key, State_Store key, parties))" + by(cases "(party, wrap, state, inp)" rule: iface_usr_func.cases) auto + +end + + +subsection \Defining the Fuse Resource\ + +primcorec core :: "('key state, event, iadv, iusr, oadv,'key ousr) core" + where + "cpoke core = poke" + | "cfunc_adv core = iface_adv" + | "cfunc_usr core = iface_usr" + +sublocale fused_resource core "(PState_Store, {})" . + + +subsubsection \Lemma showing that the resulting resource is well-typed\ + +lemma WT_core [WT_intro]: + "WT_core \_full (\_uniform UNIV (Out_Alice ` valid_keys) \\<^sub>\ \_uniform UNIV (Out_Bob ` valid_keys)) + (pred_prod (pred_s_kernel (\key. key \ valid_keys)) (\_. True)) core" + apply (rule WT_core.intros) + subgoal for s e s' by(cases "(s, e)" rule: poke.cases)(auto split: if_split_asm simp add: set_spmf_of_set) + by auto + +lemma WT_fuse [WT_intro]: + assumes [WT_intro]: "WT_rest \_adv_rest \_usr_rest I_rest rest" + shows "(\_full \\<^sub>\ \_adv_rest) \\<^sub>\ ((\_uniform UNIV (Out_Alice ` valid_keys) \\<^sub>\ \_uniform UNIV (Out_Bob ` valid_keys)) \\<^sub>\ \_usr_rest) \res resource rest \" + by(rule WT_intro)+ simp + +end + +end diff --git a/thys/Constructive_Cryptography_CM/State_Isomorphism.thy b/thys/Constructive_Cryptography_CM/State_Isomorphism.thy new file mode 100644 --- /dev/null +++ b/thys/Constructive_Cryptography_CM/State_Isomorphism.thy @@ -0,0 +1,89 @@ +theory State_Isomorphism + imports + More_CC +begin + + +section \State Isomorphism\ + +type_synonym + ('a, 'b) state_iso = "('a \ 'b) \ ('b \ 'a)" + +definition + state_iso :: "('a, 'b) state_iso \ bool" + where + "state_iso \ (\(f, g). type_definition f g UNIV)" + +definition + apply_state_iso :: " ('s1, 's2) state_iso \ ('s1, 'i, 'o) oracle' \ ('s2, 'i, 'o) oracle'" + where + "apply_state_iso \ (\(f, g). map_fun g (map_fun id (map_spmf (map_prod id f))))" + +lemma apply_state_iso_id: "apply_state_iso (id, id) = id" + by (auto simp add: apply_state_iso_def map_prod.id spmf.map_id0 map_fun_id) + +lemma apply_state_iso_compose: "apply_state_iso si1 (apply_state_iso si2 oracle) = + apply_state_iso (map_prod (\f. f o (fst si2)) ((o) (snd si2)) si1) oracle" + unfolding apply_state_iso_def + by (auto simp add: split_def id_def o_def map_prod_def map_fun_def map_spmf_conv_bind_spmf) + +lemma apply_wiring_state_iso_assoc: + "apply_wiring wr (apply_state_iso si oracle) = apply_state_iso si (apply_wiring wr oracle)" + unfolding apply_state_iso_def apply_wiring_def + by (auto simp add: split_def id_def o_def map_prod_def map_fun_def map_spmf_conv_bind_spmf) + +lemma + resource_of_oracle_state_iso: + assumes "state_iso fg" + shows "resource_of_oracle (apply_state_iso fg oracle) s = resource_of_oracle oracle (snd fg s)" +proof - + have [simp]: "snd fg (fst fg x) = x" for x + using assms by(simp add: state_iso_def split_beta type_definition.Rep_inverse) + show ?thesis + by(coinduction arbitrary: s) + (auto 4 3 simp add: rel_fun_def spmf_rel_map apply_state_iso_def split_def intro!: rel_spmf_reflI) +qed + + +subsection \Parallel State Isomorphism\ + +definition + parallel_state_iso :: " (('s_core1 \ 's_core2) \ ('s_rest1 \ 's_rest2), + ('s_core1 \ 's_rest1) \ ('s_core2 \ 's_rest2)) state_iso" + where + "parallel_state_iso = + (\((s11, s12), (s21, s22)). ((s11, s21), (s12, s22)), + \((s11, s21), (s12, s22)). ((s11, s12), (s21, s22)))" + +lemma + state_iso_parallel_state_iso [simp]: "state_iso parallel_state_iso" + by (auto simp add: type_definition_def state_iso_def parallel_state_iso_def) + + + +subsection \Trisplit State Isomorphism\ + +definition + iso_trisplit + where + "iso_trisplit = + (\(((s11, s12), s13), (s21, s22), s23). (((s11, s21), s12, s22), s13, s23), + \(((s11, s21), s12, s22), s13, s23). (((s11, s12), s13), (s21, s22), s23))" + +lemma + state_iso_fuse_par [simp]: "state_iso iso_trisplit" + by(simp add: state_iso_def iso_trisplit_def; unfold_locales; simp add: split_def) + + +subsection \Assocl-Swap State Isomorphism\ + +definition + iso_swapar + where + "iso_swapar = (\((sm, s1), s2). (s1, sm, s2), \(s1, sm, s2). ((sm, s1), s2))" + +lemma + state_iso_swapar [simp]: "state_iso iso_swapar" + by(simp add: state_iso_def iso_swapar_def; unfold_locales; simp add: split_def) + +end \ No newline at end of file diff --git a/thys/Constructive_Cryptography_CM/document/root.bib b/thys/Constructive_Cryptography_CM/document/root.bib new file mode 100644 --- /dev/null +++ b/thys/Constructive_Cryptography_CM/document/root.bib @@ -0,0 +1,87 @@ +@InProceedings{Maurer2011, + author = {Ueli Maurer and Renato Renner}, + title = {Abstract Cryptography}, + booktitle = {Innovations in Computer Science ({ICS} 2010), Proceedings}, + year = {2011}, + pages = {1--21}, + publisher = {Tsinghua University Press}, +} + +@InProceedings{Maurer2011a, + author = {Ueli Maurer}, + title = {Constructive Cryptography - {A} New Paradigm for Security Definitions and Proofs}, + booktitle = {Theory of Security and Applications - Joint Workshop ({TOSCA} 2011), Revised Selected Papers}, + year = {2011}, + volume = {6993}, + series = {LNCS}, + pages = {33--56}, + publisher = {Springer} +} + +@InProceedings{Maurer2016, + author = {Ueli Maurer and + Renato Renner}, + title = {From Indifferentiability to Constructive Cryptography (and Back)}, + booktitle = {Theory of Cryptography Conference ({TCC} 2016), Proceedings, Part {I}}, + year = {2016}, + volume = {9985}, + series = {LNCS}, + pages = {3--24}, + publisher = {Springer} +} + +@InProceedings{Lochbihler2016, + author = {Andreas Lochbihler}, + title = {Probabilistic Functions and Cryptographic Oracles in Higher Order Logic}, + booktitle = {European Symposium on Programming ({ESOP} 2016), Proceedings}, + year = {2016}, + volume = {9632}, + series = {LNCS}, + pages = {503--531}, + publisher = {Springer}, +} + +@Article{Lochbihler2017, + author = {Andreas Lochbihler}, + title = {{CryptHOL}}, + journal = {Archive of Formal Proofs}, + year = 2017, + note = {~\url{https://isa-afp.org/entries/CryptHOL.html}, + Formal proof development}, +} + +@Article{Lochbihler2018, + author = {Andreas Lochbihler and S. Reza Sefidgar}, + title = {Constructive Cryptography in {HOL}}, + journal = {Archive of Formal Proofs}, + year = 2018, + note = {~\url{https://isa-afp.org/entries/Constructive_Cryptography.html}, + Formal proof development}, +} + +@InProceedings{Lochbihler2019, + author = {Andreas Lochbihler and S. Reza Sefidgar and David Basin and Ueli Maurer}, + title = {Formalizing Constructive Cryptography using CryptHOL}, + booktitle = {Computer Security Foundations Symposium ({CSF} 2019), Proceedings}, + year = {2019}, + pages = {152--166}, + publisher = {{IEEE}}, +} + +@Article{Basin2020, + author = {David A. Basin and Andreas Lochbihler and S. Reza Sefidgar}, + title = {{CryptHOL}: Game-based Proofs in Higher-order Logic}, + journal = {Journal of Cryptology}, + year = {2020}, + volume = {33}, + number = {2}, + pages = {494--566}, +} + + +@Article{Basin2021, + author = {David A. Basin and Andreas Lochbihler and Ueli Maurer and S. Reza Sefidgar}, + title = {Abstract Modeling of Systems Communication in Constructive Cryptography using {CryptHOL}}, + year = {2021}, + note = {~\url{http://www.andreas-lochbihler.de/pub/basin2021.pdf}, Draft paper} +} \ No newline at end of file diff --git a/thys/Constructive_Cryptography_CM/document/root.tex b/thys/Constructive_Cryptography_CM/document/root.tex new file mode 100644 --- /dev/null +++ b/thys/Constructive_Cryptography_CM/document/root.tex @@ -0,0 +1,58 @@ +\documentclass[11pt,a4paper]{article} +\usepackage{isabelle,isabellesym} +\usepackage{amssymb,amsmath} +\usepackage[english]{babel} +\usepackage[only,bigsqcap]{stmaryrd} +\usepackage{wasysym} +\usepackage{booktabs} + +% this should be the last package used +\usepackage{pdfsetup} + +% urls in roman style, theory text in math-similar italics +\urlstyle{rm} +\isabellestyle{it} + +\begin{document} + +\title{Constructive Cryptography in HOL: the Communication Modeling Aspect} +\author{Andreas Lochbihler and S. Reza Sefidgar} +\maketitle + +\begin{abstract} +Constructive Cryptography (CC)~\cite{Maurer2011, Maurer2011a, Maurer2016} +introduces an abstract approach to composable security statements that allows one +to focus on a particular aspect of security proofs at a time. +Instead of proving the properties of concrete systems, CC studies system +classes, i.e., the shared behavior of similar systems, and their transformations. + +Modeling of systems communication plays a crucial role in composability and +reusability of security statements; yet, this aspect has not been studied +in any of the existing CC results. We extend our previous CC formalization~\cite{Lochbihler2018,Lochbihler2019} +with a new semantic domain called Fused Resource Templates (FRT) that abstracts over +the systems communication patterns in CC proofs. This widens the scope of cryptography proof +formalizations in the {CryptHOL} library~\cite{Lochbihler2017,Lochbihler2016,Basin2020}. + +This formalization is described in~\cite{Basin2021}. +\end{abstract} + +\tableofcontents + +\clearpage + +% sane default for proof documents +\parindent 0pt\parskip 0.5ex + +% generated text of all theories +\input{session} + +% optional bibliography +\bibliographystyle{abbrv} +\bibliography{root} + +\end{document} + +%%% Local Variables: +%%% mode: latex +%%% TeX-master: t +%%% End: diff --git a/thys/Nash_Williams/Nash_Extras.thy b/thys/Nash_Williams/Nash_Extras.thy --- a/thys/Nash_Williams/Nash_Extras.thy +++ b/thys/Nash_Williams/Nash_Extras.thy @@ -1,55 +1,55 @@ section \The Pointwise Less-Than Relation Between Two Sets\ theory Nash_Extras imports "HOL-Library.Ramsey" "HOL-Library.Countable_Set" begin -definition less_sets :: "['a::order set, 'a::order set] \ bool" where - "less_sets A B \ \x\A. \y\B. x < y" - -lemma less_setsD: "\less_sets A B; a \ A; b \ B\ \ a < b" - by (auto simp: less_sets_def) +definition less_sets :: "['a::order set, 'a::order set] \ bool" (infixr "\" 50) + where "A \ B \ \x\A. \y\B. x < y" -lemma less_sets_irrefl [simp]: "less_sets A A \ A = {}" - by (auto simp: less_sets_def) - -lemma less_sets_trans: "\less_sets A B; less_sets B C; B \ {}\ \ less_sets A C" - unfolding less_sets_def using less_trans by blast - -lemma less_sets_weaken1: "\less_sets A' B; A \ A'\ \ less_sets A B" +lemma less_setsD: "\A \ B; a \ A; b \ B\ \ a < b" by (auto simp: less_sets_def) -lemma less_sets_weaken2: "\less_sets A B'; B \ B'\ \ less_sets A B" +lemma less_sets_irrefl [simp]: "A \ A \ A = {}" by (auto simp: less_sets_def) -lemma less_sets_imp_disjnt: "less_sets A B \ disjnt A B" +lemma less_sets_trans: "\A \ B; B \ C; B \ {}\ \ A \ C" + unfolding less_sets_def using less_trans by blast + +lemma less_sets_weaken1: "\A' \ B; A \ A'\ \ A \ B" + by (auto simp: less_sets_def) + +lemma less_sets_weaken2: "\A \ B'; B \ B'\ \ A \ B" + by (auto simp: less_sets_def) + +lemma less_sets_imp_disjnt: "A \ B \ disjnt A B" by (auto simp: less_sets_def disjnt_def) -lemma less_sets_UN1: "less_sets (\\) B \ (\A\\. less_sets A B)" +lemma less_sets_UN1: "less_sets (\\) B \ (\A\\. A \ B)" by (auto simp: less_sets_def) -lemma less_sets_UN2: "less_sets A (\ \) \ (\B\\. less_sets A B)" +lemma less_sets_UN2: "less_sets A (\ \) \ (\B\\. A \ B)" by (auto simp: less_sets_def) -lemma less_sets_Un1: "less_sets (A \ A') B \ less_sets A B \ less_sets A' B" +lemma less_sets_Un1: "less_sets (A \ A') B \ A \ B \ A' \ B" by (auto simp: less_sets_def) -lemma less_sets_Un2: "less_sets A (B \ B') \ less_sets A B \ less_sets A B'" +lemma less_sets_Un2: "less_sets A (B \ B') \ A \ B \ A \ B'" by (auto simp: less_sets_def) lemma strict_sorted_imp_less_sets: - "strict_sorted (as @ bs) \ less_sets (list.set as) (list.set bs)" + "strict_sorted (as @ bs) \ (list.set as) \ (list.set bs)" by (simp add: less_sets_def sorted_wrt_append strict_sorted_sorted_wrt) lemma Sup_nat_less_sets_singleton: fixes n::nat assumes "Sup T < n" "finite T" shows "less_sets T {n}" using assms Max_less_iff by (auto simp: Sup_nat_def less_sets_def split: if_split_asm) end diff --git a/thys/Nash_Williams/Nash_Williams.thy b/thys/Nash_Williams/Nash_Williams.thy --- a/thys/Nash_Williams/Nash_Williams.thy +++ b/thys/Nash_Williams/Nash_Williams.thy @@ -1,843 +1,820 @@ section \The Nash-Williams Theorem\ -text \Following S. Todorčević, \emph{Introduction to Ramsey Spaces}, +text \Following S. Todorčević, \emph{Introduction to Ramsey Spaces}, Princeton University Press (2010), 11--12.\ theory Nash_Williams - imports Nash_Extras + imports Nash_Extras begin lemma finite_nat_Int_greaterThan_iff: fixes N :: "nat set" shows "finite (N \ {n<..}) \ finite N" apply (simp add: finite_nat_iff_bounded subset_iff) by (metis dual_order.strict_trans2 nat_less_le not_less_eq) subsection \Initial segments\ definition init_segment :: "nat set \ nat set \ bool" - where "init_segment S T \ \S'. T = S \ S' \ less_sets S S'" + where "init_segment S T \ \S'. T = S \ S' \ S \ S'" lemma init_segment_subset: "init_segment S T \ S \ T" by (auto simp: init_segment_def) lemma init_segment_refl: "init_segment S S" by (metis empty_iff init_segment_def less_sets_def sup_bot.right_neutral) lemma init_segment_antisym: "\init_segment S T; init_segment T S\ \ S=T" by (auto simp: init_segment_def) lemma init_segment_trans: "\init_segment S T; init_segment T U\ \ init_segment S U" unfolding init_segment_def by (meson UnE Un_assoc Un_upper1 less_sets_def less_sets_weaken1) lemma init_segment_empty2 [iff]: "init_segment S {} \ S={}" by (auto simp: init_segment_def less_sets_def) -lemma init_segment_Un: "less_sets S S' \ init_segment S (S \ S')" +lemma init_segment_Un: "S \ S' \ init_segment S (S \ S')" by (auto simp: init_segment_def less_sets_def) lemma init_segment_iff: shows "init_segment S T \ S=T \ (\m \ T. S = {n \ T. n < m})" (is "?lhs=?rhs") proof assume ?lhs - then obtain S' where S': "T = S \ S'" "less_sets S S'" + then obtain S' where S': "T = S \ S'" "S \ S'" by (meson init_segment_def) then have "S \ T" by auto then have eq: "S' = T-S" using S' by (auto simp: less_sets_def) show ?rhs proof (cases "T \ S") case True with \S \ T\ show ?rhs by blast next case False then have "Inf S' \ T" by (metis Diff_eq_empty_iff Diff_iff Inf_nat_def1 eq) moreover have "\x. x \ S \ x < Inf S'" using S' False by (auto simp: less_sets_def intro!: Inf_nat_def1) moreover have "{n \ T. n < Inf S'} \ S" using Inf_nat_def eq not_less_Least by fastforce ultimately show ?rhs using \S \ T\ by blast qed next assume ?rhs then show ?lhs proof (elim disjE bexE) assume "S = T" then show "init_segment S T" using init_segment_refl by blast next fix m assume m: "m \ T" "S = {n \ T. n < m}" then have "T = S \ {n \ T. m \ n}" by auto - moreover have "less_sets S {n \ T. m \ n}" + moreover have "S \ {n \ T. m \ n}" using m by (auto simp: less_sets_def) ultimately show "init_segment S T" using init_segment_Un by force qed qed lemma init_segment_empty [iff]: "init_segment {} S" by (auto simp: init_segment_def less_sets_def) - lemma init_segment_insert_iff: - assumes Sn: "less_sets S {n}" and TS: "\x. x \ T-S \ n\x" + assumes Sn: "S \ {n}" and TS: "\x. x \ T-S \ n\x" shows "init_segment (insert n S) T \ init_segment S T \ n \ T" -proof +proof assume "init_segment (insert n S) T" then have "init_segment ({n} \ S) T" by auto then show "init_segment S T \ n \ T" by (metis Sn Un_iff init_segment_def init_segment_trans insertI1 sup_commute) next assume rhs: "init_segment S T \ n \ T" - then obtain R where R: "T = S \ R" "less_sets S R" + then obtain R where R: "T = S \ R" "S \ R" by (auto simp: init_segment_def less_sets_def) - then have "S\R = insert n (S \ (R-{n})) \ less_sets (insert n S) (R-{n})" + then have "S\R = insert n (S \ (R-{n})) \ insert n S \ R-{n}" unfolding less_sets_def using rhs TS nat_less_le by auto then show "init_segment (insert n S) T" using R init_segment_Un by force qed lemma init_segment_insert: - assumes "init_segment S T" and T: "less_sets T {n}" + assumes "init_segment S T" and T: "T \ {n}" shows "init_segment S (insert n T)" proof (cases "T={}") - case True - then show ?thesis - using assms(1) by blast -next case False - obtain S' where S': "T = S \ S'" "less_sets S S'" + obtain S' where S': "T = S \ S'" "S \ S'" by (meson assms init_segment_def) - then have "insert n T = S \ (insert n S')" "less_sets S (insert n S')" + then have "insert n T = S \ (insert n S')" "S \ (insert n S')" using T False by (auto simp: less_sets_def) then show ?thesis using init_segment_Un by presburger -qed +qed (use assms in auto) subsection \Definitions and basic properties\ definition Ramsey :: "[nat set set, nat] \ bool" where "Ramsey \ r \ \f \ \ \ {..M. infinite M \ (\N i. N \ M \ infinite N \ i (\ji \ f -` {j} \ \ \ Pow N = {}))" definition thin_set :: "nat set set \ bool" where "thin_set \ \ \ \ Collect finite \ (\S\\. \T\\. init_segment S T \ S=T)" definition comparables :: "nat set \ nat set \ nat set set" where "comparables S M \ {T. finite T \ (init_segment T S \ init_segment S T \ T-S \ M)}" lemma comparables_iff: "T \ comparables S M \ finite T \ (init_segment T S \ init_segment S T \ T \ S \ M)" by (auto simp: comparables_def init_segment_def) lemma comparables_subset: "\(comparables S M) \ S \ M" by (auto simp: comparables_def init_segment_def) lemma comparables_empty [simp]: "comparables {} M = Fpow M" by (auto simp: comparables_def Fpow_def) lemma comparables_mono: "N \ M \ comparables S N \ comparables S M" by (auto simp: comparables_def) definition "rejects \ S M \ comparables S M \ \ = {}" abbreviation accepts where "accepts \ S M \ \ rejects \ S M" definition strongly_accepts where "strongly_accepts \ S M \ (\N\M. rejects \ S N \ finite N)" definition decides where "decides \ S M \ rejects \ S M \ strongly_accepts \ S M" definition decides_subsets where "decides_subsets \ M \ \T. T \ M \ finite T \ decides \ T M" lemma strongly_accepts_imp_accepts: "\strongly_accepts \ S M; infinite M\ \ accepts \ S M" unfolding strongly_accepts_def by blast lemma rejects_trivial: "\rejects \ S M; thin_set \; init_segment F S; F \ \\ \ False" unfolding rejects_def thin_set_def using comparables_iff by blast lemma rejects_subset: "\rejects \ S M; N \ M\ \ rejects \ S N" by (fastforce simp add: rejects_def comparables_def) lemma strongly_accepts_subset: "\strongly_accepts \ S M; N \ M\ \ strongly_accepts \ S N" by (auto simp: strongly_accepts_def) lemma decides_subset: "\decides \ S M; N \ M\ \ decides \ S N" unfolding decides_def using rejects_subset strongly_accepts_subset by blast lemma decides_subsets_subset: "\decides_subsets \ M; N \ M\ \ decides_subsets \ N" by (meson decides_subset decides_subsets_def subset_trans) lemma rejects_empty [simp]: "rejects \ {} M \ Fpow M \ \ = {}" by (auto simp: rejects_def comparables_def Fpow_def) lemma strongly_accepts_empty [simp]: "strongly_accepts \ {} M \ (\N\M. Fpow N \ \ = {} \ finite N)" by (simp add: strongly_accepts_def Fpow_def disjoint_iff) lemma ex_infinite_decides_1: assumes "infinite M" obtains N where "N \ M" "infinite N" "decides \ S N" by (meson assms decides_def order_refl strongly_accepts_def) proposition ex_infinite_decides_finite: assumes "infinite M" "finite S" obtains N where "N \ M" "infinite N" "\T. T \ S \ decides \ T N" proof - have "finite (Pow S)" by (simp add: \finite S\) then obtain f :: "nat \ nat set" where f: "f ` {..< card (Pow S)} = Pow S" by (metis bij_betw_imp_surj_on [OF bij_betw_from_nat_into_finite]) obtain M0 where M0: "infinite M0" "M0 \ M" "decides \ (f 0) M0" by (meson \infinite M\ ex_infinite_decides_1) define F where "F \ rec_nat M0 (\n N. @N'. N' \ N \ infinite N' \ decides \ (f (Suc n)) N')" have P_Suc: "F (Suc n) = (@N'. N' \ F n \ infinite N' \ decides \ (f (Suc n)) N')" for n by (auto simp: F_def) have *: "infinite (F n) \ decides \ (f n) (F n) \ F n \ M" for n proof (induction n) case 0 with \infinite M\ show ?case by (auto simp: F_def M0) next case (Suc n) let ?\ = "\N'. N' \ F n \ infinite N' \ decides \ (f (Suc n)) N'" have "\N'. ?\ N'" by (meson Suc ex_infinite_decides_1 subset_trans) then have "Eps ?\ \ F n \ infinite (Eps ?\) \ decides \ (f (Suc n)) (Eps ?\)" by (rule someI_ex) with Suc.IH show ?case by (auto simp: P_Suc) qed then have telescope: "F (Suc n) \ F n" for n unfolding P_Suc by (metis (no_types, lifting) ex_infinite_decides_1 someI_ex) let ?N = "\n M" by (metis "*" INF_lower2 Pow_iff f imageE order_refl) next have eq: "(\n\m. F n) = F m" for m by (induction m) (use telescope in \auto simp: atMost_Suc\) then show "infinite ?N" by (metis "*" Suc_le_D Suc_le_eq finite_subset le_INF_iff lessThan_Suc_atMost lessThan_iff) next fix T assume "T \ S" then obtain m where "f m = T" "m < card (Pow S)" using f by (blast elim: equalityE) - then have "decides \ T (F m)" - using "*" by blast - show "decides \ T ?N" - by (meson INT_lower \decides \ T (F m)\ \m < card (Pow S)\ decides_subset lessThan_iff) + then show "decides \ T ?N" + by (metis "*" INT_lower decides_subset lessThan_iff) qed qed lemma sorted_wrt_subset: "\X \ list.set l; sorted_wrt (\) l\ \ hd l \ X" by (induction l) auto text \Todorčević's Lemma 1.18\ proposition ex_infinite_decides_subsets: assumes "thin_set \" "infinite M" obtains N where "N \ M" "infinite N" "decides_subsets \ N" proof - obtain M0 where M0: "infinite M0" "M0 \ M" "decides \ {} M0" by (meson \infinite M\ ex_infinite_decides_1) define decides_all where "decides_all \ \S N. \T \ S. decides \ T N" define \ where "\ \ \NL N. N \ hd NL \ Inf N > Inf (hd NL) \ infinite N \ decides_all (List.set (map Inf NL)) N" have "\N. \ NL N" if "infinite (hd NL)" for NL proof - obtain N where N: "N \ hd NL \ infinite N \ decides_all (List.set (map Inf NL)) N" unfolding \_def decides_all_def by (metis List.finite_set ex_infinite_decides_finite \infinite (hd NL)\) then have "Inf (N \ {Inf (hd NL)<..}) > Inf (hd NL)" by (metis Inf_nat_def1 Int_iff finite.emptyI finite_nat_Int_greaterThan_iff greaterThan_iff) then show ?thesis unfolding \_def decides_all_def by (meson Int_lower1 N decides_all_def decides_subset finite_nat_Int_greaterThan_iff subset_trans) qed then have \_Eps: "\ NL (Eps (\ NL))" if "infinite (hd NL)" for NL by (simp add: someI_ex that) define F where "F \ rec_nat [M0] (\n NL. (Eps (\ NL)) # NL)" have F_simps [simp]: "F 0 = [M0]" "F (Suc n) = Eps (\ (F n)) # F n" for n by (auto simp: F_def) have F: "F n \ [] \ sorted_wrt (\) (F n) \ list.set (F n) \ Collect infinite \ list.set (F n) \ Pow M" for n proof (induction n) case 0 then show ?case by (simp add: M0) next case (Suc n) then have *: "\ (F n) (Eps (\ (F n)))" using \_Eps hd_in_set by blast show ?case proof (intro conjI) show "sorted_wrt (\) (F (Suc n))" using subset_trans [OF _ sorted_wrt_subset] Suc.IH \_def "*" by auto show "list.set (F (Suc n)) \ {S. infinite S}" using "*" \_def Suc.IH by force show "list.set (F (Suc n)) \ Pow M" using "*" Suc.IH \_def hd_in_set by force qed auto qed have \F: "\ (F n) (Eps (\ (F n)))" for n using F \_Eps hd_in_set by blast then have decides: "decides_all (List.set (map Inf (F n))) (Eps (\ (F n)))" for n using \_def by blast have Eps_subset_hd: "Eps (\ (F n)) \ hd (F n) " for n using \F \_def by blast have "List.set (map Inf (F n)) \ List.set (map Inf (F (Suc n)))" for n by auto then have map_Inf_subset: "m \ n \ List.set (map Inf (F m)) \ List.set (map Inf (F n))" for m n by (rule order_class.lift_Suc_mono_le) auto define mmap where "mmap \ \n. Inf (hd (F (Suc n)))" have "mmap n < mmap (Suc n)" for n by (metis F_simps(2) \F \_def list.sel(1) mmap_def) then have "strict_mono mmap" by (simp add: lift_Suc_mono_less strict_mono_def) then have "inj mmap" by (simp add: strict_mono_imp_inj_on) have finite_F_bound: "\n. S \ List.set (map Inf (F n))" if S: "S \ range mmap" "finite S" for S proof - obtain K where "finite K" "S \ mmap ` K" by (metis S finite_subset_image order_refl) show ?thesis proof have "mmap ` K \ list.set (map Inf (F (Suc (Max K))))" unfolding mmap_def image_subset_iff by (metis F Max_ge \finite K\ hd_in_set imageI map_Inf_subset not_less_eq_eq set_map subsetD) with S show "S \ list.set (map Inf (F (Suc (Max K))))" using \S \ mmap ` K\ by auto qed qed have "Eps (\ (F (Suc n))) \ Eps (\ (F n))" for n by (metis F_simps(2) \F \_def list.sel(1)) then have Eps_\_decreasing: "m \ n \ Eps (\ (F n)) \ Eps (\ (F m))" for m n by (rule order_class.lift_Suc_antimono_le) have hd_Suc_eq_Eps: "hd (F (Suc n)) = Eps (\ (F n))" for n by simp have Inf_hd_in_hd: "Inf (hd (F n)) \ hd (F n)" for n by (metis Inf_nat_def1 \F \_def finite.emptyI rev_finite_subset) then have Inf_hd_in_Eps: "Inf (hd (F m)) \ Eps (\ (F n))" if "m>n" for m n by (metis Eps_\_decreasing Nat.lessE leD mmap_def not_less_eq_eq subsetD that hd_Suc_eq_Eps) then have image_mmap_subset_hd_F: "mmap ` {n..} \ hd (F (Suc n))" for n by (metis hd_Suc_eq_Eps atLeast_iff image_subsetI le_imp_less_Suc mmap_def) have "list.set (F k) \ list.set (F n)" if "k \ n" for k n by (rule order_class.lift_Suc_mono_le) (use that in auto) then have hd_F_in_F: "hd (F k) \ list.set (F n)" if "k \ n" for k n by (meson F hd_in_set subsetD that) show thesis proof show infinite_mm: "infinite (range mmap)" using \inj mmap\ range_inj_infinite by blast show "range mmap \ M" using Eps_subset_hd \M0 \ M\ image_mmap_subset_hd_F by fastforce show "decides_subsets \ (range mmap)" unfolding decides_subsets_def proof (intro strip) fix S assume "S \ range mmap" "finite S" define n where "n \ LEAST n. S \ List.set (map Inf (F n))" have "\n. S \ List.set (map Inf (F n))" using \S \ range mmap\ \finite S\ finite_F_bound by blast then have S: "S \ List.set (map Inf (F n))" and minS: "\m. m \ S \ List.set (map Inf (F m))" unfolding n_def by (meson LeastI_ex not_less_Least)+ have decides_Fn: "decides \ S (Eps (\ (F n)))" using S decides decides_all_def by blast show "decides \ S (range mmap)" proof (cases "n=0") case True then show ?thesis by (metis image_mmap_subset_hd_F decides_Fn decides_subset hd_Suc_eq_Eps atLeast_0) next case False - have notin_map_Inf: "x \ List.set (map Inf (F n))" if "less_sets S {x}" for x + have notin_map_Inf: "x \ List.set (map Inf (F n))" if "S \ {x}" for x proof clarsimp fix T assume "x = Inf T" and "T \ list.set (F n)" - with that have ls: "less_sets S {Inf T}" + with that have ls: "S \ {Inf T}" by auto have "S \ List.set (map Inf (F j))" if T: "T \ list.set (F (Suc j))" for j proof clarsimp fix x assume "x \ S" then have "x < Inf T" using less_setsD ls by blast then have "x \ T" using Inf_nat_def not_less_Least by auto obtain k where k: "x = mmap k" using \S \ range mmap\ \x \ S\ by blast with T \x < Inf T\ have "k < j" by (metis Eps_\_decreasing F Inf_hd_in_hd hd_Suc_eq_Eps \x \ T\ mmap_def not_le sorted_wrt_subset subsetD) then have "Eps (\ (F k)) \ list.set (F j)" by (metis Suc_leI hd_Suc_eq_Eps hd_F_in_F) then show "x \ Inf ` list.set (F j)" by (auto simp: k image_iff mmap_def) qed then obtain m where "m List.set (map Inf (F m))" using \n \ 0\ by (metis \T \ list.set (F n)\ lessI less_Suc_eq_0_disj) then show False using minS by blast qed - have Inf_hd_F: "Inf (hd (F m)) \ Eps (\ (F n))" if "less_sets S {Inf (hd (F m))}" for m + have Inf_hd_F: "Inf (hd (F m)) \ Eps (\ (F n))" if "S \ {Inf (hd (F m))}" for m by (metis Inf_hd_in_Eps hd_F_in_F notin_map_Inf imageI leI set_map that) - have less_S: "less_sets S {Inf (hd (F m))}" + have less_S: "S \ {Inf (hd (F m))}" if "init_segment S T" "Inf (hd (F m)) \ T" "Inf (hd (F m)) \ S" for T m using \finite S\ that by (auto simp: init_segment_iff less_sets_def) consider "rejects \ S (Eps (\ (F n)))" | "strongly_accepts \ S (Eps (\ (F n)))" using decides_Fn by (auto simp: decides_def) then show ?thesis proof cases case 1 have "rejects \ S (range mmap)" proof (clarsimp simp: rejects_def disjoint_iff) fix X assume "X \ comparables S (range mmap)" and "X \ \" moreover have "\x X. \X \ \; init_segment S X; x \ X; x \ S; x \ range mmap\ \ x \ Eps (\ (F n))" using less_S Inf_hd_F mmap_def by blast ultimately have "X \ comparables S (Eps (\ (F n)))" by (auto simp: comparables_def disjoint_iff subset_iff) with 1 \X \ \\ show False by (auto simp: rejects_def) qed then show ?thesis by (auto simp: decides_def) next case 2 have False if "N \ range mmap" and "rejects \ S N" and "infinite N" for N proof - have "N = mmap ` {n..} \ N \ mmap ` {.. N" using in_mono that(1) by fastforce then have "infinite (mmap ` {n..} \ N)" by (metis finite_Int finite_Un finite_imageI finite_lessThan that(3)) moreover have "rejects \ S (mmap ` {n..} \ N)" using rejects_subset \rejects \ S N\ by fastforce moreover have "mmap ` {n..} \ N \Eps (\ (F n))" using image_mmap_subset_hd_F by fastforce ultimately show ?thesis using 2 by (auto simp: strongly_accepts_def) qed with 2 have "strongly_accepts \ S (range mmap)" by (auto simp: strongly_accepts_def) then show ?thesis by (auto simp: decides_def) qed qed qed qed qed text \Todorčević's Lemma 1.19\ proposition strongly_accepts_1_19: assumes acc: "strongly_accepts \ S M" and "thin_set \" "infinite M" "S \ M" "finite S" and dsM: "decides_subsets \ M" shows "finite {n \ M. \ strongly_accepts \ (insert n S) M}" proof (rule ccontr) define N where "N = {n \ M. rejects \ (insert n S) M} \ {Sup S<..}" have "N \ M" and N: "\n. n \ N \ n \ M \ rejects \ (insert n S) M \ n > Sup S" by (auto simp: N_def) assume "\ ?thesis" moreover have "{n \ M. \ strongly_accepts \ (insert n S) M} = {n \ M. rejects \ (insert n S) M}" using dsM \finite S\ \infinite M\ \S \ M\ unfolding decides_subsets_def by (meson decides_def finite.insertI insert_subset strongly_accepts_imp_accepts) ultimately have "infinite {n \ M. rejects \ (insert n S) M}" by simp then have "infinite N" by (simp add: N_def finite_nat_Int_greaterThan_iff) then have "accepts \ S N" using acc strongly_accepts_def \N \ M\ by blast then obtain T where T: "T \ comparables S N" "T \ \" and TSN: "T \ S \ N" unfolding rejects_def using comparables_iff init_segment_subset by fastforce then consider "init_segment T S" | "init_segment S T" "S\T" by (auto simp: comparables_def) then show False proof cases case 1 then have "init_segment T (insert n S)" if "n \ N" for n by (meson Sup_nat_less_sets_singleton N \finite S\ init_segment_insert that) with \infinite N\ \thin_set \\ \T \ \\ show False by (meson N infinite_nat_iff_unbounded rejects_trivial) next let ?n = "Min (T-S)" case 2 then have "?n \ N" by (metis Diff_partition Diff_subset_conv Min_in T(1) TSN comparables_iff finite_Diff init_segment_subset subsetD sup_bot.right_neutral) then have "rejects \ (insert ?n S) N" using rejects_subset \N \ M\ by (auto simp: N_def) then have \
: "\ init_segment T (insert ?n S) \ (\ init_segment (insert ?n S) T \ insert ?n S = T)" using T Diff_partition TSN \Min (T - S) \ N\ \finite S\ unfolding rejects_def comparables_iff disjoint_iff by auto then have T_nS: "T \ insert ?n S" proof (elim conjE disjE) assume "\ init_segment T (insert ?n S)" "\ init_segment (insert ?n S) T" - moreover have "less_sets S {Min (T - S)}" + moreover have "S \ {Min (T - S)}" using Sup_nat_less_sets_singleton N \Min (T - S) \ N\ assms(5) by blast moreover have "finite (T - S)" using T comparables_iff by blast ultimately show ?thesis using \init_segment S T\ Min_in init_segment_insert_iff by auto qed auto have non_TS: "\ init_segment T S" by (meson Sup_nat_less_sets_singleton N \?n \ N\ \\ init_segment T (insert (?n) S) \ (\ init_segment (insert (?n) S) T \ insert (?n) S = T)\ assms(5) init_segment_insert) consider (ST) "S \ T" | (TS) "T \ S" using 2 init_segment_subset by blast then show False proof cases case ST with \
show ?thesis using 2 T(1) \T \ insert (?n) S\ comparables_iff init_segment_iff by auto next case TS then show ?thesis proof - have "\ init_segment T S" by (meson Sup_nat_less_sets_singleton N \?n \ N\ \
assms(5) init_segment_insert) then show ?thesis using 2 TS init_segment_subset by fastforce qed qed qed qed text \Much work is needed for this slight strengthening of the previous result!\ proposition strongly_accepts_1_19_plus: assumes "thin_set \" "infinite M" and dsM: "decides_subsets \ M" obtains N where "N \ M" "infinite N" - "\S n. \S \ N; finite S; strongly_accepts \ S N; n \ N; less_sets S {n}\ + "\S n. \S \ N; finite S; strongly_accepts \ S N; n \ N; S \ {n}\ \ strongly_accepts \ (insert n S) N" proof - define insert_closed where "insert_closed \ \NL N. \T \ Inf ` set NL. \n \ N. strongly_accepts \ T ((Inf ` set NL) \ hd NL) \ - less_sets T {n} \ strongly_accepts \ (insert n T) ((Inf ` set NL) \ hd NL)" + T \ {n} \ strongly_accepts \ (insert n T) ((Inf ` set NL) \ hd NL)" define \ where "\ \ \NL N. N \ hd NL \ Inf N > Inf (hd NL) \ infinite N \ insert_closed NL N" have "\N. \ NL N" if NL: "infinite (hd NL)" "Inf ` set NL \ hd NL \ M" for NL proof - let ?m = "Inf ` set NL" let ?M = "?m \ hd NL" define P where "P \ \S. {n \ ?M. \ strongly_accepts \ (insert n S) ?M}" have "\k. P S \ {..k}" if "S \ Inf ` set NL" "strongly_accepts \ S ?M" for S proof - have "finite (P S)" unfolding P_def proof (rule strongly_accepts_1_19) show "decides_subsets \ ?M" using NL(2) decides_subsets_subset dsM by blast show "finite S" using finite_surj that(1) by blast qed (use that NL assms in auto) then show ?thesis by (simp add: finite_nat_iff_bounded_le) qed then obtain f where f: "\S. \S \ Inf ` set NL; strongly_accepts \ S ?M\ \ P S \ {..f S}" by metis define m where "m \ Max (insert (Inf (hd NL)) (f ` Pow (Inf ` set NL)))" have \
: "strongly_accepts \ (insert n S) ?M" if S: "S \ Inf ` set NL" "strongly_accepts \ S ?M" and n: "n \ hd NL \ {m<..}" for S n proof - have "f S \ m" unfolding m_def using that(1) by auto then show ?thesis using f [OF S] n unfolding P_def by auto qed have "\ NL (hd NL \ {m<..})" unfolding \_def proof (intro conjI) have "Inf (hd NL) \ m" by (simp add: m_def) then show "Inf (hd NL) < Inf (hd NL \ {m<..})" by (metis Inf_nat_def1 Int_iff finite.emptyI finite_nat_Int_greaterThan_iff greaterThan_iff le_less_trans that(1)) show "infinite (hd NL \ {m<..})" by (simp add: finite_nat_Int_greaterThan_iff that(1)) show "insert_closed NL (hd NL \ {m<..})" by (auto intro: \
simp: insert_closed_def) qed auto then show ?thesis .. qed then have \_Eps: "\ NL (Eps (\ NL))" if "infinite (hd NL)" "Inf ` set NL \ hd NL \ M" for NL by (meson someI_ex that) define F where "F \ rec_nat [M] (\n NL. (Eps (\ NL)) # NL)" have F_simps [simp]: "F 0 = [M]" "F (Suc n) = Eps (\ (F n)) # F n" for n by (auto simp: F_def) have InfM: "Inf M \ M" by (metis Inf_nat_def1 assms(2) finite.emptyI) have F: "F n \ [] \ sorted_wrt (\) (F n) \ list.set (F n) \ Collect infinite \ set (F n) \ Pow M \ Inf ` list.set (F n) \ M" for n proof (induction n) - case 0 - then show ?case - by (auto simp: InfM \infinite M\) - next case (Suc n) have "hd (F n) \ M" by (meson Pow_iff Suc.IH hd_in_set subsetD) then have 1: "Ball (list.set (F n)) ((\) (Eps (\ (F n))))" using order_trans [OF _ sorted_wrt_subset] by (metis Suc.IH Un_subset_iff \_Eps \_def hd_in_set mem_Collect_eq subsetD) have 2: "infinite (Eps (\ (F n)))" by (metis Ball_Collect Pow_iff Suc.IH Un_subset_iff \_Eps \_def hd_in_set subset_iff) have 3: "Eps (\ (F n)) \ M" by (meson Pow_iff Suc.IH 1 hd_in_set subset_iff) have "Inf (Eps (\ (F n))) \ M" by (metis 2 3 Inf_nat_def1 finite.simps in_mono) with 1 2 3 show ?case using Suc by simp - qed + qed (auto simp: InfM \infinite M\) have \F: "\ (F n) (Eps (\ (F n)))" for n by (metis Ball_Collect F Pow_iff Un_subset_iff \_Eps hd_in_set subset_code(1)) then have insert_closed: "insert_closed (F n) (Eps (\ (F n)))" for n using \_def by blast - have Eps_subset_hd: "Eps (\ (F n)) \ hd (F n) " for n + have Eps_subset_hd: "Eps (\ (F n)) \ hd (F n)" for n using \F \_def by blast define mmap where "mmap \ \n. Inf (hd (F (Suc n)))" have "mmap n < mmap (Suc n)" for n by (metis F_simps(2) \F \_def list.sel(1) mmap_def) then have "strict_mono mmap" by (simp add: lift_Suc_mono_less strict_mono_def) then have "inj mmap" by (simp add: strict_mono_imp_inj_on) have "Eps (\ (F (Suc n))) \ Eps (\ (F n))" for n by (metis F_simps(2) \F \_def list.sel(1)) then have Eps_\_decreasing: "m \ n \ Eps (\ (F n)) \ Eps (\ (F m))" for m n by (rule order_class.lift_Suc_antimono_le) have hd_Suc_eq_Eps: "hd (F (Suc n)) = Eps (\ (F n))" for n by simp have "Inf (hd (F n)) \ hd (F n)" for n - by (metis Inf_nat_def1 \F \_def finite.emptyI rev_finite_subset) + by (metis Inf_nat_def1 \F \_def finite.emptyI finite_subset) then have Inf_hd_in_Eps: "Inf (hd (F m)) \ Eps (\ (F n))" if "m>n" for m n by (metis Eps_\_decreasing Nat.lessE hd_Suc_eq_Eps less_imp_le_nat subsetD that) then have image_mmap_subset_hd_F: "mmap ` {n..} \ hd (F (Suc n))" for n by (metis hd_Suc_eq_Eps atLeast_iff image_subsetI le_imp_less_Suc mmap_def) have "list.set (F k) \ list.set (F n)" if "k \ n" for k n by (rule order_class.lift_Suc_mono_le) (use that in auto) then have hd_F_in_F: "hd (F k) \ list.set (F n)" if "k \ n" for k n by (meson F hd_in_set subsetD that) show ?thesis proof show infinite_mm: "infinite (range mmap)" using \inj mmap\ range_inj_infinite by blast show "range mmap \ M" using Eps_subset_hd image_mmap_subset_hd_F by fastforce next fix S a assume "S \ range mmap" "finite S" and acc: "strongly_accepts \ S (range mmap)" - and a: "a \ range mmap" and Sn: "less_sets S {a}" + and a: "a \ range mmap" and Sn: "S \ {a}" then obtain n where n: "a = mmap n" by auto define N where "N \ LEAST n. S \ mmap ` {..n. S \ mmap ` {..S \ range mmap\ \finite S\ finite_nat_iff_bounded finite_subset_image image_mono) then have S: "S \ mmap ` {..m. m \ S \ mmap ` {.. Inf ` list.set (F n) \ hd (F n)" for n proof (induction n) case 0 then show ?case using Eps_subset_hd image_mmap_subset_hd_F by fastforce next case (Suc n) then show ?case by clarsimp (metis Inf_hd_in_Eps hd_F_in_F image_iff leI mmap_def) qed have subM: "(Inf ` list.set (F N) \ hd (F N)) \ M" by (meson F PowD hd_in_set subsetD sup.boundedI) have "strongly_accepts \ (insert a S) (Inf ` list.set (F N) \ hd (F N))" proof (rule insert_closed [unfolded insert_closed_def, rule_format]) have "mmap ` {.. Inf ` list.set (F N)" using Suc_leI hd_F_in_F by (fastforce simp: mmap_def le_eq_less_or_eq) with S show Ssub: "S \ Inf ` list.set (F N)" by auto have "S \ mmap ` {..strict_mono mmap\ strict_mono_less by (fastforce simp: less_sets_def n image_iff subset_iff Bex_def) with leI minS have "n\N" by blast then show "a \ Eps (\ (F N))" using image_mmap_subset_hd_F n by fastforce show "strongly_accepts \ S (Inf ` list.set (F N) \ hd (F N))" proof (rule ccontr) assume "\ strongly_accepts \ S (Inf ` list.set (F N) \ hd (F N))" then have "rejects \ S (Inf ` list.set (F N) \ hd (F N))" using dsM subM unfolding decides_subsets_def by (meson F Ssub \finite S\ decides_def decides_subset subset_trans) moreover have "accepts \ S (range mmap)" using \inj mmap\ acc range_inj_infinite strongly_accepts_imp_accepts by blast ultimately show False by (meson range_mmap_subset rejects_subset) qed - show "less_sets S {a}" - by (auto simp: Sn) - qed + qed (auto simp: Sn) then show "strongly_accepts \ (insert a S) (range mmap)" using range_mmap_subset strongly_accepts_subset by auto qed qed subsection \Main Theorem\ text\Weirdly, the assumption @{term "f ` \ \ {..<2}"} is not used here; it's perhaps unnecessary due to the particular way that @{term Ramsey} is defined. It's only needed for @{term "r > 2"}\ theorem Nash_Williams_2: assumes "thin_set \" shows "Ramsey \ 2" unfolding Ramsey_def proof clarify fix f :: "nat set \ nat" and M :: "nat set" assume "infinite M" let ?\ = "\i. f -` {i} \ \" have fin\: "\X. X \ \ \ finite X" using assms thin_set_def by auto have thin: "thin_set (?\ i)" for i using assms thin_set_def by auto obtain N where "N \ M" "infinite N" and N: "decides_subsets (?\ 0) N" using \infinite M\ ex_infinite_decides_subsets thin by blast then consider "rejects (?\ 0) {} N" | "strongly_accepts (?\ 0) {} N" unfolding decides_def decides_subsets_def by blast then show "\N i. N \ M \ infinite N \ i<2 \ (\j<2. j \ i \ f -` {j} \ \ \ Pow N = {})" proof cases case 1 then have "?\ 0 \ Pow N = {}" unfolding rejects_def disjoint_iff by (metis IntD2 PowD comparables_iff fin\ init_segment_empty sup_bot.left_neutral) then show ?thesis using \N \ M\ \infinite N\ less_2_cases_iff by auto next case 2 then have \
: "\P. \P\N; \S. \S \ P; finite S\ \ S \ (?\ 0)\ \ finite P" by (auto simp: Fpow_def disjoint_iff) obtain P where "P \ N" "infinite P" and P: - "\S n. \S \ P; finite S; strongly_accepts (?\ 0) S P; n \ P; less_sets S {n}\ + "\S n. \S \ P; finite S; strongly_accepts (?\ 0) S P; n \ P; S \ {n}\ \ strongly_accepts (?\ 0) (insert n S) P" using strongly_accepts_1_19_plus [OF thin \infinite N\ N] by blast have "?\ 1 \ Pow P = {}" proof (clarsimp simp: disjoint_iff) fix T assume T: "f T = Suc 0" "T \ \" and "T \ P" then have "finite T" using fin\ by blast moreover have "strongly_accepts (?\ 0) S P" if "finite S" "S \ P" for S using that proof (induction "card S" arbitrary: S) case (Suc n) then have Seq: "S = insert (Sup S) (S - {Sup S})" using Sup_nat_def Max_eq_iff by fastforce then have "card (S - {Sup S}) = n" using Suc card_Diff_singleton by fastforce then have sacc: "strongly_accepts (?\ 0) (S - {Sup S}) P" using Suc by blast have "S \ {}" using Suc.hyps(2) by auto - have "less_sets (S - {Sup S}) {Sup S}" - using Suc.prems(1) finite_Sup_less_iff nat_neq_iff by (auto simp: less_sets_def) + have "S - {Sup S} \ {Sup S}" + by (simp add: Suc.prems(1) Sup_nat_def \S \ {}\ dual_order.strict_iff_order less_sets_def) then have "strongly_accepts (?\ 0) (insert (Sup S) (S - {Sup S})) P" by (metis P Seq Suc.prems finite_Diff insert_subset sacc) then show ?case using Seq by auto qed (use 2 \P \ N\ in auto) ultimately have "\x\comparables T P. f x = 0 \ x \ \" unfolding strongly_accepts_def rejects_def disjoint_iff by (metis \T \ P\ \infinite P\ IntE order_refl vimage_singleton_eq) then show False using T assms thin_set_def comparables_def by force qed then show ?thesis by (metis One_nat_def \N \ M\ \P \ N\ \infinite P\ less_2_cases_iff subset_trans) qed qed theorem Nash_Williams: assumes \: "thin_set \" "r > 0" shows "Ramsey \ r" using \r > 0\ proof (induction r) case (Suc r) show ?case proof (cases "r<2") case True - then consider "Suc r = 1" | "Suc r = 2" - by linarith then show ?thesis - proof cases - case 1 with \ show ?thesis by (auto simp: Ramsey_def) - next - case 2 with \ show ?thesis by (metis Nash_Williams_2) - qed + by (metis Nash_Williams_2 One_nat_def Ramsey_def assms(1) less_2_cases less_one numeral_2_eq_2 order_refl) next case False with Suc.IH have Ram: "Ramsey \ r" by auto have "r \ 2" by (simp add: False leI) show ?thesis unfolding Ramsey_def proof clarify fix f and M :: "nat set" assume fim: "f \ \ \ {.. \x. if f x = r then r-1 else f x" have gim: "g \ \ \ {.. M" "infinite N" "ij. \jj\ \ g -` {j} \ \ \ Pow N = {}" using Ram \infinite M\ by (metis Ramsey_def) show "\N i. N \ M \ infinite N \ i < Suc r \ (\j i \ f -` {j} \ \ \ Pow N = {})" proof (cases "i \ \ Pow N = {}" if "j < Suc r" "i \ j" for j using \N \ M\ \infinite N\ \i i that apply (clarsimp simp add: disjoint_iff g_def less_Suc_eq) by (metis True diff_less less_nat_zero_code nat_neq_iff zero_less_one) then show ?thesis - apply (rule_tac x=N in exI) - apply (rule_tac x=i in exI) - by (simp add: \N \ M\ \i < r\ \infinite N\ less_SucI) + by (metis \N \ M\ \infinite N\ less_Suc_eq) next case False then have "i = r-1" using \i by linarith then have null: "f -` {j} \ \ \ Pow N = {}" if "ji < r\ by (auto simp: g_def disjoint_iff split: if_split_asm) define h where "h \ \x. if f x = r then 0 else f x" have him: "h \ \ \ {..i by (force simp: h_def) then obtain P j where "P \ N" "infinite P" "jkk \ h -` {k} \ \ \ Pow P = {}" by (metis Ramsey_def Ram \infinite N\) - show ?thesis + have "\i. \j i \ f -` {j} \ \ \ Pow P = {}" proof (cases "j=0") case True then show ?thesis - apply (rule_tac x=P in exI) apply (rule_tac x=r in exI) - using null [of 0] \r \ 2\ \P \ N\ \N \ M\ j \infinite P\ - by (force simp: h_def disjoint_iff less_Suc_eq intro: subset_trans) + using null [of 0] \r \ 2\ \P \ N\ j by (force simp: h_def disjoint_iff less_Suc_eq) next case False then show ?thesis - apply (rule_tac x=P in exI) apply (rule_tac x=j in exI) - using j \P \ N\ \N \ M\ \j < r\ \infinite P\ False - by (auto simp: h_def less_Suc_eq disjoint_iff intro: less_trans) + using j \j < r\ by (auto simp: h_def less_Suc_eq disjoint_iff intro: less_trans) qed + then show ?thesis + by (metis Suc.prems \N \ M\ \P \ N\ \infinite P\ subset_trans) qed qed qed qed auto end diff --git a/thys/Ordinal_Partitions/Omega_Omega.thy b/thys/Ordinal_Partitions/Omega_Omega.thy --- a/thys/Ordinal_Partitions/Omega_Omega.thy +++ b/thys/Ordinal_Partitions/Omega_Omega.thy @@ -1,4568 +1,4569 @@ section \An ordinal partition theorem by Jean A. Larson\ text \Jean A. Larson, A short proof of a partition theorem for the ordinal $\omega^\omega$. \emph{Annals of Mathematical Logic}, 6:129–145, 1973.\ theory Omega_Omega imports "HOL-Library.Product_Lexorder" Erdos_Milner begin abbreviation "list_of \ sorted_list_of_set" subsection \Cantor normal form for ordinals below @{term "\\\"}\ text \Unlike @{term Cantor_sum}, there is no list of ordinal exponents, which are instead taken as consecutive. We obtain an order-isomorphism between @{term "\\\"} and increasing lists of natural numbers (ordered lexicographically).\ fun omega_sum_aux where Nil: "omega_sum_aux 0 _ = 0" | Suc: "omega_sum_aux (Suc n) [] = 0" | Cons: "omega_sum_aux (Suc n) (m#ms) = (\\n) * (ord_of_nat m) + omega_sum_aux n ms" abbreviation omega_sum where "omega_sum ms \ omega_sum_aux (length ms) ms" text \A normal expansion has no leading zeroes\ primrec normal:: "nat list \ bool" where normal_0: "normal [] = True" | normal_Suc: "normal (m#ms) = (m > 0)" lemma omega_sum_0_iff [simp]: "normal ns \ omega_sum ns = 0 \ ns = []" by (induction ns) auto lemma Ord_omega_sum_aux [simp]: "Ord (omega_sum_aux k ms)" by (induction rule: omega_sum_aux.induct) auto lemma Ord_omega_sum: "Ord (omega_sum ms)" by simp lemma omega_sum_less_\\ [intro]: "omega_sum ms < \\\" proof (induction ms) case Nil then show ?case by (auto simp: zero_less_Limit) next case (Cons m ms) have "\ \ (length ms) * ord_of_nat m \ elts (\ \ Suc (length ms))" using Ord_mem_iff_lt by auto then have "\\(length ms) * ord_of_nat m \ elts (\\\)" using Ord_ord_of_nat oexp_mono_le omega_nonzero ord_of_nat_le_omega by blast with Cons show ?case by (auto simp: mult_succ OrdmemD oexp_less indecomposableD indecomposable_\_power) qed lemma omega_sum_aux_less: "omega_sum_aux k ms < \ \ k" proof (induction rule: omega_sum_aux.induct) case (3 n m ms) have " \\n * ord_of_nat m + \\n < \\n * \" by (metis Ord_ord_of_nat \_power_succ_gtr mult_succ oexp_succ ord_of_nat.simps(2)) with 3 show ?case using dual_order.strict_trans by force qed auto lemma omega_sum_less: "omega_sum ms < \ \ (length ms)" by (rule omega_sum_aux_less) lemma omega_sum_ge: "m \ 0 \ \ \ (length ms) \ omega_sum (m#ms)" apply clarsimp by (metis Ord_ord_of_nat add_le_cancel_left0 le_mult Nat.neq0_conv ord_of_eq_0_iff vsubsetD) lemma omega_sum_length_less: assumes "length ms < length ns" "normal ns" shows "omega_sum ms < omega_sum ns" proof (cases ns) case Nil then show ?thesis using assms by auto next case (Cons n ns') have "\ \ length ms \ \ \ length ns'" using assms local.Cons by (simp add: oexp_mono_le) then have "\ omega_sum (n#ns') \ omega_sum ms" using omega_sum_ge [of n ns'] omega_sum_less [of ms] \normal ns\ local.Cons by auto then show ?thesis by (metis Ord_linear2 Ord_omega_sum local.Cons) qed lemma omega_sum_length_leD: assumes "omega_sum ms \ omega_sum ns" "normal ms" shows "length ms \ length ns" by (meson assms leD leI omega_sum_length_less) lemma omega_sum_less_eqlen_iff_cases [simp]: assumes "length ms = length ns" shows "omega_sum (m#ms) < omega_sum (n#ns) \ m m=n \ omega_sum ms < omega_sum ns" (is "?lhs = ?rhs") proof assume L: ?lhs have "\ Suc n < Suc m" using omega_sum_less [of ms] omega_sum_less [of ns] L assms mult_nat_less_add_less by fastforce then have "m\n" by auto with L assms show ?rhs by auto next assume ?rhs then show ?lhs by (auto simp: mult_nat_less_add_less omega_sum_aux_less assms) qed lemma omega_sum_lex_less_iff_cases: "((length ms, omega_sum (m#ms)), (length ns, omega_sum (n#ns))) \ less_than <*lex*> VWF \ length ms < length ns \ length ms = length ns \ m m=n \ ((length ms, omega_sum ms), (length ns, omega_sum ns)) \ less_than <*lex*> VWF" using omega_sum_less_eqlen_iff_cases by force lemma omega_sum_less_iff_cases: assumes "m > 0" "n > 0" shows "omega_sum (m#ms) < omega_sum (n#ns) \ length ms < length ns \ length ms = length ns \ m length ms = length ns \ m=n \ omega_sum ms < omega_sum ns" (is "?lhs = ?rhs") proof assume L: ?lhs then have "length ms \ length ns" using omega_sum_length_leD [OF less_imp_le [OF L]] by (simp add: \m > 0\) moreover have "m\n" if "length ms = length ns" using L omega_sum_less_eqlen_iff_cases that by auto ultimately show ?rhs using L by auto next assume ?rhs moreover have "omega_sum (m # ms) < omega_sum (n # ns)" if "length ms < length ns" using that by (metis Suc_mono \n > 0\ length_Cons normal_Suc omega_sum_length_less) ultimately show ?lhs using omega_sum_less_eqlen_iff_cases by force qed lemma omega_sum_less_iff: "((length ms, omega_sum ms), (length ns, omega_sum ns)) \ less_than <*lex*> VWF \ (ms,ns) \ lenlex less_than" proof (induction ms arbitrary: ns) case Nil then show ?case by auto next case (Cons m ms) then show ?case proof (induction ns) case (Cons n ns') show ?case using omega_sum_lex_less_iff_cases [of ms m ns' n] Cons.prems by (simp add: Cons_lenlex_iff lenlex_length order.not_eq_order_implies_strict nat_less_le) qed auto qed lemma eq_omega_sum_less_iff: assumes "length ms = length ns" shows "(omega_sum ms, omega_sum ns) \ VWF \ (ms,ns) \ lenlex less_than" by (metis assms in_lex_prod less_not_refl less_than_iff omega_sum_less_iff) lemma eq_omega_sum_eq_iff: assumes "length ms = length ns" shows "omega_sum ms = omega_sum ns \ ms=ns" proof assume "omega_sum ms = omega_sum ns" then have "(omega_sum ms, omega_sum ns) \ VWF" "(omega_sum ns, omega_sum ms) \ VWF" by auto then obtain "(ms,ns) \ lenlex less_than" "(ns,ms) \ lenlex less_than" using assms eq_omega_sum_less_iff by metis moreover have "total (lenlex less_than)" by (simp add: total_lenlex total_less_than) ultimately show "ms=ns" by (meson UNIV_I total_on_def) qed auto lemma inj_omega_sum: "inj_on omega_sum {l. length l = n}" unfolding inj_on_def using eq_omega_sum_eq_iff by fastforce lemma Ex_omega_sum: "\ \ elts (\\n) \ \ns. \ = omega_sum ns \ length ns = n" proof (induction n arbitrary: \) case 0 then show ?case by (rule_tac x="[]" in exI) auto next case (Suc n) then obtain k::nat where k: "\ \ elts (\ \ n * k)" and kmin: "\k'. k' \ \ elts (\ \ n * k')" by (metis Ord_ord_of_nat elts_mult_\E oexp_succ ord_of_nat.simps(2)) show ?case proof (cases k) case (Suc k') then obtain \ where \: "\ = (\ \ n * k') + \" by (metis lessI mult_succ ord_of_nat.simps(2) k kmin mem_plus_V_E) then have \in: "\ \ elts (\ \ n)" using Suc k mult_succ by auto then obtain ns where ns: "\ = omega_sum ns" and len: "length ns = n" using Suc.IH by auto moreover have "omega_sum ns < \\n" using OrdmemD ns \in by auto ultimately show ?thesis by (rule_tac x="k'#ns" in exI) (simp add: \) qed (use k in auto) qed lemma omega_sum_drop [simp]: "omega_sum (dropWhile (\n. n=0) ns) = omega_sum ns" by (induction ns) auto lemma normal_drop [simp]: "normal (dropWhile (\n. n=0) ns)" by (induction ns) auto lemma omega_sum_\\: assumes "\ \ elts (\\\)" obtains ns where "\ = omega_sum ns" "normal ns" proof - obtain ms where "\ = omega_sum ms" using assms Ex_omega_sum by (auto simp: oexp_Limit elts_\) show thesis proof show "\ = omega_sum (dropWhile (\n. n=0) ms)" by (simp add: \\ = omega_sum ms\) show "normal (dropWhile (\n. n=0) ms)" by auto qed qed definition Cantor_\\ :: "V \ nat list" - where "Cantor_\\ \ \x. @ns. x = omega_sum ns \ normal ns" + where "Cantor_\\ \ \x. SOME ns. x = omega_sum ns \ normal ns" lemma assumes "\ \ elts (\\\)" shows Cantor_\\: "omega_sum (Cantor_\\ \) = \" and normal_Cantor_\\: "normal (Cantor_\\ \)" by (metis (mono_tags, lifting) Cantor_\\_def assms omega_sum_\\ someI)+ subsection \Larson's set $W(n)$\ definition WW :: "nat list set" where "WW \ {l. strict_sorted l}" fun into_WW :: "nat \ nat list \ nat list" where "into_WW k [] = []" | "into_WW k (n#ns) = (k+n) # into_WW (Suc (k+n)) ns" fun from_WW :: "nat \ nat list \ nat list" where "from_WW k [] = []" | "from_WW k (n#ns) = (n - k) # from_WW (Suc n) ns" lemma from_into_WW [simp]: "from_WW k (into_WW k ns) = ns" by (induction ns arbitrary: k) auto lemma inj_into_WW: "inj (into_WW k)" by (metis from_into_WW injI) lemma into_from_WW_aux: "\strict_sorted ns; \n\list.set ns. k \ n\ \ into_WW k (from_WW k ns) = ns" by (induction ns arbitrary: k) (auto simp: Suc_leI) lemma into_from_WW [simp]: "strict_sorted ns \ into_WW 0 (from_WW 0 ns) = ns" by (simp add: into_from_WW_aux) lemma into_WW_imp_ge: "y \ List.set (into_WW x ns) \ x \ y" by (induction ns arbitrary: x) fastforce+ lemma strict_sorted_into_WW: "strict_sorted (into_WW x ns)" by (induction ns arbitrary: x) (auto simp: dest: into_WW_imp_ge) lemma length_into_WW: "length (into_WW x ns) = length ns" by (induction ns arbitrary: x) auto lemma WW_eq_range_into: "WW = range (into_WW 0)" by (metis (mono_tags, hide_lams) WW_def equalityI image_subset_iff into_from_WW mem_Collect_eq rangeI strict_sorted_into_WW subset_iff) lemma into_WW_lenlex_iff: "(into_WW k ms, into_WW k ns) \ lenlex less_than \ (ms, ns) \ lenlex less_than" proof (induction ms arbitrary: ns k) case Nil then show ?case by simp (metis length_0_conv length_into_WW) next case (Cons m ms) then show ?case by (induction ns) (auto simp: Cons_lenlex_iff length_into_WW) qed lemma wf_llt [simp]: "wf (lenlex less_than)" by blast lemma trans_llt [simp]: "trans (lenlex less_than)" by blast lemma total_llt [simp]: "total_on A (lenlex less_than)" by (meson UNIV_I total_lenlex total_less_than total_on_def) lemma omega_sum_1_less: assumes "(ms,ns) \ lenlex less_than" shows "omega_sum (1#ms) < omega_sum (1#ns)" proof - have "omega_sum (1#ms) < omega_sum (1#ns)" if "length ms < length ns" using omega_sum_less_iff_cases that zero_less_one by blast then show ?thesis using assms by (auto simp: mult_succ simp flip: omega_sum_less_iff) qed lemma ordertype_WW_1: "ordertype WW (lenlex less_than) \ ordertype UNIV (lenlex less_than)" by (rule ordertype_mono) auto lemma ordertype_WW_2: "ordertype UNIV (lenlex less_than) \ \\\" proof (rule ordertype_inc_le_Ord) show "range (\ms. omega_sum (1#ms)) \ elts (\\\)" by (meson Ord_\ Ord_mem_iff_lt Ord_oexp Ord_omega_sum image_subset_iff omega_sum_less_\\) qed (use omega_sum_1_less in auto) lemma ordertype_WW_3: "\\\ \ ordertype WW (lenlex less_than)" proof - define \ where "\ \ into_WW 0 \ Cantor_\\" have \\: "\\\ = tp (elts (\\\))" by simp also have "\ \ ordertype WW (lenlex less_than)" proof (rule ordertype_inc_le) fix \ \ assume \: "\ \ elts (\\\)" and \: "\ \ elts (\\\)" and "(\, \) \ VWF" then obtain *: "Ord \" "Ord \" "\<\" by (metis Ord_in_Ord Ord_ordertype VWF_iff_Ord_less \\) then have "length (Cantor_\\ \) \ length (Cantor_\\ \)" using \ \ by (simp add: Cantor_\\ normal_Cantor_\\ omega_sum_length_leD) with \ \ * have "(Cantor_\\ \, Cantor_\\ \) \ lenlex less_than" by (auto simp: Cantor_\\ simp flip: omega_sum_less_iff) then show "(\ \, \ \) \ lenlex less_than" by (simp add: \_def into_WW_lenlex_iff) next show "\ ` elts (\\\) \ WW" by (auto simp: \_def WW_def strict_sorted_into_WW) qed auto finally show "\\\ \ ordertype WW (lenlex less_than)" . qed lemma ordertype_WW: "ordertype WW (lenlex less_than) = \\\" and ordertype_UNIV_\\: "ordertype UNIV (lenlex less_than) = \\\" using ordertype_WW_1 ordertype_WW_2 ordertype_WW_3 by auto lemma ordertype_\\: fixes F :: "nat \ nat list set" assumes "\j::nat. ordertype (F j) (lenlex less_than) = \\j" shows "ordertype (\j. F j) (lenlex less_than) = \\\" proof (rule antisym) show "ordertype (\ (range F)) (lenlex less_than) \ \ \ \" by (metis ordertype_UNIV_\\ ordertype_mono small top_greatest trans_llt wf_llt) have "\n. \ \ ord_of_nat n \ ordertype (\ (range F)) (lenlex less_than)" by (metis TC_small Union_upper assms ordertype_mono rangeI trans_llt wf_llt) then show "\ \ \ \ ordertype (\ (range F)) (lenlex less_than)" by (auto simp: oexp_\_Limit ZFC_in_HOL.SUP_le_iff elts_\) qed definition WW_seg :: "nat \ nat list set" where "WW_seg n \ {l \ WW. length l = n}" lemma WW_seg_subset_WW: "WW_seg n \ WW" by (auto simp: WW_seg_def) lemma WW_eq_UN_WW_seg: "WW = (\ n. WW_seg n)" by (auto simp: WW_seg_def) lemma ordertype_list_seg: "ordertype {l. length l = n} (lenlex less_than) = \\n" proof - have "bij_betw omega_sum {l. length l = n} (elts (\\n))" unfolding WW_seg_def bij_betw_def by (auto simp: inj_omega_sum Ord_mem_iff_lt omega_sum_less dest: Ex_omega_sum) then show ?thesis by (force simp: ordertype_eq_iff simp flip: eq_omega_sum_less_iff) qed lemma ordertype_WW_seg: "ordertype (WW_seg n) (lenlex less_than) = \\n" (is "ordertype ?W ?R = \\n") proof - have "ordertype {l. length l = n} ?R = ordertype ?W ?R" proof (subst ordertype_eq_ordertype) show "\f. bij_betw f {l. length l = n} ?W \ (\x\{l. length l = n}. \y\{l. length l = n}. ((f x, f y) \ lenlex less_than) = ((x, y) \ lenlex less_than))" proof (intro exI conjI) have "inj_on (into_WW 0) {l. length l = n}" by (metis from_into_WW inj_onI) then show "bij_betw (into_WW 0) {l. length l = n} ?W" by (auto simp: bij_betw_def WW_seg_def WW_eq_range_into length_into_WW) qed (simp add: into_WW_lenlex_iff) qed auto then show ?thesis using ordertype_list_seg by auto qed subsection \Definitions required for the lemmas\ subsubsection \Larson's "$<$"-relation on ordered lists\ instantiation list :: (ord)ord begin definition "xs < ys \ xs \ [] \ ys \ [] \ last xs < hd ys" for xs ys :: "'a list" definition "xs \ ys \ xs < ys \ xs = ys" for xs ys :: "'a list" instance by standard end lemma less_Nil [simp]: "xs < []" "[] < xs" by (auto simp: less_list_def) lemma less_sets_imp_list_less: - assumes "less_sets (list.set xs) (list.set ys)" + assumes "list.set xs \ list.set ys" shows "xs < ys" by (metis assms last_in_set less_list_def less_sets_def list.set_sel(1)) lemma less_sets_imp_sorted_list_of_set: - assumes "less_sets A B" "finite A" "finite B" + assumes "A \ B" "finite A" "finite B" shows "list_of A < list_of B" by (simp add: assms less_sets_imp_list_less) lemma sorted_list_of_set_imp_less_sets: assumes "xs < ys" "sorted xs" "sorted ys" - shows "less_sets (list.set xs) (list.set ys)" + shows "list.set xs \ list.set ys" using assms sorted_hd_le sorted_le_last by (force simp: less_list_def less_sets_def intro: order.trans) lemma less_list_iff_less_sets: assumes "sorted xs" "sorted ys" - shows "xs < ys \ less_sets (list.set xs) (list.set ys)" + shows "xs < ys \ list.set xs \ list.set ys" using assms sorted_hd_le sorted_le_last by (force simp: less_list_def less_sets_def intro: order.trans) lemma sorted_trans: assumes "xs < ys" "ys < zs" "sorted ys" "ys \ []" shows "xs < zs" using assms unfolding less_list_def by (metis dual_order.strict_trans last_in_set leD neqE sorted_hd_le) lemma strict_sorted_imp_append_less: assumes "strict_sorted (xs @ ys)" shows "xs < ys" using assms by (simp add: less_list_def sorted_wrt_append strict_sorted_sorted_wrt) lemma strict_sorted_append_iff: "strict_sorted (xs @ ys) \ xs < ys \ strict_sorted xs \ strict_sorted ys" (is "?lhs = ?rhs") proof assume ?lhs then show ?rhs by (auto simp: sorted_wrt_append strict_sorted_sorted_wrt less_list_def) next assume R: ?rhs then have "\x y. \x \ list.set xs; y \ list.set ys\ \ x < y" using less_setsD sorted_list_of_set_imp_less_sets strict_sorted_imp_sorted by blast with R show ?lhs by (auto simp: sorted_wrt_append strict_sorted_sorted_wrt) qed lemma singleton_less_list_iff: "sorted xs \ [n] < xs \ {..n} \ list.set xs = {}" apply (simp add: less_list_def set_eq_iff) by (metis empty_iff less_le_trans list.set(1) list.set_sel(1) not_le sorted_hd_le) lemma less_last_iff: "xs@[x] < ys \ [x] < ys" by (simp add: less_list_def) lemma less_Cons_iff: "NO_MATCH [] ys \ xs < y#ys \ xs < [y]" by (simp add: less_list_def) lemma less_hd_imp_less: "xs < [hd ys] \ xs < ys" by (simp add: less_list_def) lemma last_less_imp_less: "[last xs] < ys \ xs < ys" by (simp add: less_list_def) lemma strict_sorted_concat_I: assumes "\x. x \ list.set xs \ strict_sorted x" "\n. Suc n < length xs \ xs!n < xs!Suc n" assumes "xs \ lists (- {[]})" shows "strict_sorted (concat xs)" using assms proof (induction xs) case (Cons x xs) then have "x < concat xs" apply (simp add: less_list_def) by (metis Compl_iff hd_concat insertI1 length_greater_0_conv length_pos_if_in_set list.sel(1) lists.cases nth_Cons_0) with Cons show ?case by (force simp: strict_sorted_append_iff) qed auto subsection \Nash Williams for lists\ subsubsection \Thin sets of lists\ inductive initial_segment :: "'a list \ 'a list \ bool" where "initial_segment xs (xs@ys)" -definition thin where "thin A \ \ (\x y. x \ A \ y \ A \ x \ y \ initial_segment x y)" +definition thin :: "'a list set \ bool" + where "thin A \ \ (\x y. x \ A \ y \ A \ x \ y \ initial_segment x y)" lemma initial_segment_ne: assumes "initial_segment xs ys" "xs \ []" shows "ys \ [] \ hd ys = hd xs" using assms by (auto elim!: initial_segment.cases) lemma take_initial_segment: assumes "initial_segment xs ys" "k \ length xs" shows "take k xs = take k ys" by (metis append_eq_conv_conj assms initial_segment.cases min_def take_take) lemma initial_segment_length_eq: assumes "initial_segment xs ys" "length xs = length ys" shows "xs = ys" using assms initial_segment.cases by fastforce lemma initial_segment_Nil [simp]: "initial_segment [] ys" by (simp add: initial_segment.simps) lemma initial_segment_Cons [simp]: "initial_segment (x#xs) (y#ys) \ x=y \ initial_segment xs ys" by (metis append_Cons initial_segment.simps list.inject) lemma init_segment_iff_initial_segment: assumes "strict_sorted xs" "strict_sorted ys" shows "init_segment (list.set xs) (list.set ys) \ initial_segment xs ys" (is "?lhs = ?rhs") proof assume ?lhs - then obtain S' where S': "list.set ys = list.set xs \ S'" "less_sets (list.set xs) S'" + then obtain S' where S': "list.set ys = list.set xs \ S'" "list.set xs \ S'" by (auto simp: init_segment_def) then have "finite S'" by (metis List.finite_set finite_Un) have "ys = xs @ list_of S'" using S' \strict_sorted xs\ proof (induction xs) case Nil with \strict_sorted ys\ show ?case by auto next case (Cons a xs) with \finite S'\ have "ys = a # xs @ list_of S'" by (metis List.finite_set \finite S'\ append_Cons assms(2) sorted_list_of_set_Un sorted_list_of_set_set_of) then show ?case by (auto simp: Cons) qed then show ?rhs using initial_segment.intros by blast next assume ?rhs then show ?lhs proof cases case (1 ys) with assms(2) show ?thesis using sorted_list_of_set_imp_less_sets strict_sorted_imp_sorted by (auto simp: init_segment_def strict_sorted_append_iff) qed qed theorem Nash_Williams_WW: fixes h :: "nat list \ nat" assumes "infinite M" and h: "h ` {l \ A. List.set l \ M} \ {..<2}" and "thin A" "A \ WW" obtains i N where "i < 2" "infinite N" "N \ M" "h ` {l \ A. List.set l \ N} \ {i}" proof - define AM where "AM \ {l \ A. List.set l \ M}" have "thin_set (list.set ` A)" using \thin A\ \A \ WW\ unfolding thin_def thin_set_def WW_def by (auto simp: subset_iff init_segment_iff_initial_segment) then have "thin_set (list.set ` AM)" by (simp add: AM_def image_subset_iff thin_set_def) then have "Ramsey (list.set ` AM) 2" using Nash_Williams_2 by metis moreover have "(h \ list_of) \ list.set ` AM \ {..<2}" unfolding AM_def proof clarsimp fix l assume "l \ A" "list.set l \ M" then have "strict_sorted l" using WW_def \A \ WW\ by blast then show "h (list_of (list.set l)) < 2" using h \l \ A\ \list.set l \ M\ by auto qed ultimately obtain N i where N: "N \ M" "infinite N" "i<2" and "\j. \j<2; i\j\ \ (h \ list_of) -` {j} \ (list.set ` AM) \ Pow N = {}" unfolding Ramsey_def by (metis \infinite M\) then have N_disjoint: "(h \ list_of) -` {1-i} \ (list.set ` AM) \ Pow N = {}" by (metis One_nat_def diff_less_Suc not_less_eq numeral_2_eq_2 zero_less_diff) have "h ` {l \ A. list.set l \ N} \ {i}" proof clarify fix l assume "l \ A" and "list.set l \ N" then have "h l < 2" using h \N \ M\ by force with \i<2\ have "h l \ Suc 0 - i \ h l = i" by (auto simp: eval_nat_numeral less_Suc_eq) moreover have "strict_sorted l" using \A \ WW\ \l \ A\ unfolding WW_def by blast moreover have "h (list_of (list.set l)) = 1 - i \ \ (list.set l \ N)" using N_disjoint \N \ M\ \l \ A\ by (auto simp: AM_def) ultimately show "h l = i" using N \N \ M\ \l \ A\ \list.set l \ N\ by (auto simp: vimage_def set_eq_iff AM_def WW_def subset_iff) qed then show thesis using that \i<2\ N by auto qed subsection \Specialised functions on lists\ lemma mem_lists_non_Nil: "xss \ lists (- {[]}) \ (\x \ list.set xss. x \ [])" by auto fun acc_lengths :: "nat \ 'a list list \ nat list" where "acc_lengths acc [] = []" | "acc_lengths acc (l#ls) = (acc + length l) # acc_lengths (acc + length l) ls" lemma length_acc_lengths [simp]: "length (acc_lengths acc ls) = length ls" by (induction ls arbitrary: acc) auto lemma acc_lengths_eq_Nil_iff [simp]: "acc_lengths acc ls = [] \ ls = []" by (metis length_0_conv length_acc_lengths) lemma set_acc_lengths: assumes "ls \ lists (- {[]})" shows "list.set (acc_lengths acc ls) \ {acc<..}" using assms by (induction ls rule: acc_lengths.induct) fastforce+ text \Useful because @{text acc_lengths.simps} will later be deleted from the simpset.\ lemma hd_acc_lengths [simp]: "hd (acc_lengths acc (l#ls)) = acc + length l" by simp lemma last_acc_lengths [simp]: "ls \ [] \ last (acc_lengths acc ls) = acc + sum_list (map length ls)" by (induction acc ls rule: acc_lengths.induct) auto lemma nth_acc_lengths [simp]: "\ls \ []; k < length ls\ \ acc_lengths acc ls ! k = acc + sum_list (map length (take (Suc k) ls))" by (induction acc ls arbitrary: k rule: acc_lengths.induct) (fastforce simp: less_Suc_eq nth_Cons')+ lemma acc_lengths_plus: "acc_lengths (m+n) as = map ((+)m) (acc_lengths n as)" by (induction n as arbitrary: m rule: acc_lengths.induct) (auto simp: add.assoc) lemma acc_lengths_shift: "NO_MATCH 0 acc \ acc_lengths acc as = map ((+)acc) (acc_lengths 0 as)" by (metis acc_lengths_plus add.comm_neutral) lemma length_concat_acc_lengths: "ls \ [] \ k + length (concat ls) \ list.set (acc_lengths k ls)" by (metis acc_lengths_eq_Nil_iff last_acc_lengths last_in_set length_concat) lemma strict_sorted_acc_lengths: assumes "ls \ lists (- {[]})" shows "strict_sorted (acc_lengths acc ls)" using assms proof (induction ls rule: acc_lengths.induct) case (2 acc l ls) then have "strict_sorted (acc_lengths (acc + length l) ls)" using "2" by auto then show ?case using set_acc_lengths "2.prems" by auto qed auto lemma acc_lengths_append: "acc_lengths acc (xs @ ys) = acc_lengths acc xs @ acc_lengths (acc + sum_list (map length xs)) ys" by (induction acc xs rule: acc_lengths.induct) (auto simp: add.assoc) declare acc_lengths.simps [simp del] lemma length_concat_ge: assumes "as \ lists (- {[]})" shows "length (concat as) \ length as" using assms proof (induction as) case (Cons a as) then have "length a \ Suc 0" "\l. l \ list.set as \ length l \ Suc 0" by (auto simp: Suc_leI) then show ?case using Cons.IH by force qed auto fun interact :: "'a list list \ 'a list list \ 'a list" where "interact [] ys = concat ys" | "interact xs [] = concat xs" | "interact (x#xs) (y#ys) = x @ y @ interact xs ys" lemma (in monoid_add) length_interact: "length (interact xs ys) = sum_list (map length xs) + sum_list (map length ys)" by (induction rule: interact.induct) (auto simp: length_concat) lemma length_interact_ge: assumes "xs \ lists (- {[]})" "ys \ lists (- {[]})" shows "length (interact xs ys) \ length xs + length ys" by (metis mem_lists_non_Nil add_mono assms length_concat length_concat_ge length_interact) lemma set_interact [simp]: shows "list.set (interact xs ys) = list.set (concat xs) \ list.set (concat ys)" by (induction rule: interact.induct) auto lemma interact_eq_Nil_iff [simp]: assumes "xs \ lists (- {[]})" "ys \ lists (- {[]})" shows "interact xs ys = [] \ xs=[] \ ys=[]" using length_interact_ge [OF assms] by fastforce lemma interact_sing [simp]: "interact [x] ys = x @ concat ys" by (metis (no_types) concat.simps(2) interact.simps neq_Nil_conv) lemma hd_interact: "\xs \ []; hd xs \ []\ \ hd (interact xs ys) = hd (hd xs)" by (metis concat.simps(2) hd_append2 interact.simps(2) interact.simps(3) list.exhaust list.sel(1)) lemma acc_lengths_concat_injective: assumes "concat as' = concat as" "acc_lengths n as' = acc_lengths n as" shows "as' = as" using assms proof (induction as arbitrary: n as') case Nil then show ?case by (metis acc_lengths_eq_Nil_iff) next case (Cons a as) then obtain a' bs where "as' = a'#bs" by (metis Suc_length_conv length_acc_lengths) with Cons show ?case by (simp add: acc_lengths.simps) qed lemma acc_lengths_interact_injective: assumes "interact as' bs' = interact as bs" "acc_lengths a as' = acc_lengths a as" "acc_lengths b bs' = acc_lengths b bs" shows "as' = as \ bs' = bs" using assms proof (induction as bs arbitrary: a b as' bs' rule: interact.induct) case (1 cs) then have "as' = []" by (metis acc_lengths_eq_Nil_iff) with 1 show ?case using acc_lengths_concat_injective by auto next case (2 c cs) then show ?case by (metis acc_lengths_concat_injective acc_lengths_eq_Nil_iff interact.simps(2) list.exhaust) next case (3 x xs y ys) then obtain a' us b' vs where "as' = a'#us" "bs' = b'#vs" by (metis length_Suc_conv length_acc_lengths) with 3 show ?case by (auto simp: acc_lengths.simps) qed lemma strict_sorted_interact_I: assumes "length ys \ length xs" "length xs \ Suc (length ys)" "\x. x \ list.set xs \ strict_sorted x" "\y. y \ list.set ys \ strict_sorted y" "\n. n < length ys \ xs!n < ys!n" "\n. Suc n < length xs \ ys!n < xs!Suc n" assumes "xs \ lists (- {[]})" "ys \ lists (- {[]})" shows "strict_sorted (interact xs ys)" using assms proof (induction rule: interact.induct) case (3 x xs y ys) then have "x < y" by force+ moreover have "strict_sorted (interact xs ys)" using 3 by simp (metis Suc_less_eq nth_Cons_Suc) moreover have "y < interact xs ys" proof (clarsimp simp add: less_list_def) assume "y \ []" and ne: "interact xs ys \ []" then show "last y < hd (interact xs ys)" using 3 apply simp by (metis dual_order.strict_trans1 hd_interact length_greater_0_conv less_list_def list.sel(1) lists.simps mem_lists_non_Nil nth_Cons' nth_mem) qed ultimately show ?case using 3 by (simp add: strict_sorted_append_iff less_list_def) qed auto subsection \Forms and interactions\ subsubsection \Forms\ inductive Form_Body :: "[nat, nat, nat list, nat list, nat list] \ bool" where "Form_Body ka kb xs ys zs" if "length xs < length ys" "xs = concat (a#as)" "ys = concat (b#bs)" "a#as \ lists (- {[]})" "b#bs \ lists (- {[]})" "length (a#as) = ka" "length (b#bs) = kb" "c = acc_lengths 0 (a#as)" "d = acc_lengths 0 (b#bs)" "zs = concat [c, a, d, b] @ interact as bs" "strict_sorted zs" inductive Form :: "[nat, nat list set] \ bool" where "Form 0 {xs,ys}" if "length xs = length ys" "xs \ ys" | "Form (2*k-1) {xs,ys}" if "Form_Body k k xs ys zs" "k > 0" | "Form (2*k) {xs,ys}" if "Form_Body (Suc k) k xs ys zs" "k > 0" inductive_cases Form_0_cases_raw: "Form 0 u" lemma Form_elim_upair: assumes "Form l U" obtains xs ys where "xs \ ys" "U = {xs,ys}" "length xs \ length ys" using assms by (elim Form.cases Form_Body.cases; metis dual_order.order_iff_strict less_not_refl) lemma Form_Body_WW: assumes "Form_Body ka kb xs ys zs" shows "zs \ WW" by (rule Form_Body.cases [OF assms]) (auto simp: WW_def) lemma Form_Body_nonempty: assumes "Form_Body ka kb xs ys zs" shows "length zs > 0" by (rule Form_Body.cases [OF assms]) auto lemma Form_Body_length: assumes "Form_Body ka kb xs ys zs" shows "length xs < length ys" using Form_Body.cases assms by blast lemma form_cases: fixes l::nat obtains (zero) "l = 0" | (nz) ka kb where "l = ka+kb - 1" "0 < kb" "kb \ ka" "ka \ Suc kb" proof - have "l = 0 \ (\ka kb. l = ka+kb - 1 \ 0 < kb \ kb \ ka \ ka \ Suc kb)" by presburger then show thesis using nz zero by blast qed subsubsection \Interactions\ lemma interact: assumes "Form l U" "l>0" obtains ka kb xs ys zs where "l = ka+kb - 1" "U = {xs,ys}" "Form_Body ka kb xs ys zs" "0 < kb" "kb \ ka" "ka \ Suc kb" using form_cases [of l] proof cases case zero then show ?thesis using Form_0_cases_raw assms that(1) by auto next case (nz ka kb) obtain xs ys where xys: "xs \ ys" "U = {xs,ys}" "length xs \ length ys" using Form_elim_upair assms by blast show ?thesis proof (cases "ka = kb") case True show ?thesis using Form.cases [OF \Form l U\] proof cases case (2 k xs' ys' zs') then have "xs' = xs \ ys' = ys" by (metis Form_Body_length Set.doubleton_eq_iff leD xys(2) xys(3)) moreover have "k = ka" using 2 True nz by presburger ultimately show ?thesis using 2 True nz(1) nz(4) that xys(1) by blast qed (use True nz in \presburger+\) next case False show ?thesis using Form.cases [OF \Form l U\] proof cases case (3 k xs' ys' zs') then have "xs' = xs \ ys' = ys" by (metis Form_Body_length Set.doubleton_eq_iff leD xys(2) xys(3)) moreover have "k = kb" using 3 False nz by linarith ultimately show ?thesis using 3 False nz \xs \ ys\ by (metis le_SucE le_antisym that) qed (use False nz in \presburger+\) qed qed definition inter_scheme :: "nat \ nat list set \ nat list" - where "inter_scheme l U \ @zs. \k xs ys. l > 0 - \ (l = 2*k-1 \ U = {xs,ys} \ Form_Body k k xs ys zs - \ l = 2*k \ U = {xs,ys} \ Form_Body (Suc k) k xs ys zs)" + where "inter_scheme l U \ + SOME zs. \k xs ys. l > 0 \ + (l = 2*k-1 \ U = {xs,ys} \ Form_Body k k xs ys zs + \ l = 2*k \ U = {xs,ys} \ Form_Body (Suc k) k xs ys zs)" lemma inter_scheme: assumes "Form l U" "l>0" obtains ka kb xs ys where "l = ka+kb - 1" "U = {xs,ys}" "Form_Body ka kb xs ys (inter_scheme l U)" "0 < kb" "kb \ ka" "ka \ Suc kb" using interact [OF \Form l U\] proof cases case 1 with \l > 0\ show ?case by auto next case (2 ka kb xs ys zs) then have \
: "\ka kb zs. \ Form_Body ka kb ys xs zs" using Form_Body_length less_asym' by blast have "Form_Body ka kb xs ys (inter_scheme l U)" proof (cases "ka = kb") case True with 2 have l: "\k. l \ k * 2" by presburger have [simp]: "\k. kb + kb - Suc 0 = k * 2 - Suc 0 \ k=kb" by auto show ?thesis unfolding inter_scheme_def using 2 l True by (auto simp add: \
\l > 0\ Set.doubleton_eq_iff conj_disj_distribR ex_disj_distrib algebra_simps some_eq_ex) next case False with 2 have l: "\k. l \ k * 2 - Suc 0" and [simp]: "ka = Suc kb" by presburger+ have [simp]: "\k. kb + kb = k * 2 \ k=kb" by auto show ?thesis unfolding inter_scheme_def using 2 l False by (auto simp add: \
\l > 0\ Set.doubleton_eq_iff conj_disj_distribR ex_disj_distrib algebra_simps some_eq_ex) qed then show ?thesis by (simp add: 2 that) qed lemma inter_scheme_simple: assumes "Form l U" "l>0" shows "inter_scheme l U \ WW \ length (inter_scheme l U) > 0" using inter_scheme [OF assms] by (meson Form_Body_WW Form_Body_nonempty) lemma inter_scheme_strict_sorted: assumes "Form l U" "l>0" shows "strict_sorted (inter_scheme l U)" using inter_scheme_simple [OF assms] by (auto simp: WW_def) subsubsection \Injectivity of interactions\ proposition inter_scheme_injective: assumes "Form l U" "Form l U'" "l > 0" and eq: "inter_scheme l U' = inter_scheme l U" shows "U' = U" proof - obtain ka kb xs ys where l: "l = ka+kb - 1" and U: "U = {xs,ys}" and FB: "Form_Body ka kb xs ys (inter_scheme l U)" and "0 < kb" "kb \ ka" "ka \ Suc kb" using assms inter_scheme by blast then obtain a as b bs c d where xs: "xs = concat (a#as)" and ys: "ys = concat (b#bs)" and len: "length (a#as) = ka" "length (b#bs) = kb" and c: "c = acc_lengths 0 (a#as)" and d: "d = acc_lengths 0 (b#bs)" and Ueq: "inter_scheme l U = concat [c, a, d, b] @ interact as bs" by (auto simp: Form_Body.simps) obtain ka' kb' xs' ys' where l': "l = ka'+kb' - 1" and U': "U' = {xs',ys'}" and FB': "Form_Body ka' kb' xs' ys' (inter_scheme l U')" and "0 < kb'" "kb' \ ka'" "ka' \ Suc kb'" using assms inter_scheme by blast then obtain a' as' b' bs' c' d' where xs': "xs' = concat (a'#as')" and ys': "ys' = concat (b'#bs')" and len': "length (a'#as') = ka'" "length (b'#bs') = kb'" and c': "c' = acc_lengths 0 (a'#as')" and d': "d' = acc_lengths 0 (b'#bs')" and Ueq': "inter_scheme l U' = concat [c', a', d', b'] @ interact as' bs'" using Form_Body.simps by auto have [simp]: "ka' = ka \ kb' = kb" using \l > 0\ l l' \ka \ Suc kb\ \ka' \ Suc kb'\ \kb \ ka\ \kb' \ ka'\ le_SucE le_antisym mult_2 by linarith have [simp]: "length c = length c'" "length d = length d'" using c c' d d' len' len by auto have c_off: "c' = c" "a' @ d' @ b' @ interact as' bs' = a @ d @ b @ interact as bs" using eq by (auto simp: Ueq Ueq') then have len_a: "length a' = length a" by (metis acc_lengths.simps(2) add.left_neutral c c' nth_Cons_0) with c_off have \
: "a' = a" "d' = d" "b' @ interact as' bs' = b @ interact as bs" by auto then have "length (interact as' bs') = length (interact as bs)" by (metis acc_lengths.simps(2) add_left_cancel append_eq_append_conv d d' list.inject) with \
have "b' = b" "interact as' bs' = interact as bs" by auto moreover have "acc_lengths 0 as' = acc_lengths 0 as" using \a' = a\ \c' = c\ by (simp add: c' c acc_lengths.simps acc_lengths_shift) moreover have "acc_lengths 0 bs' = acc_lengths 0 bs" using \b' = b\ \d' = d\ by (simp add: d' d acc_lengths.simps acc_lengths_shift) ultimately have "as' = as \ bs' = bs" using acc_lengths_interact_injective by blast then show ?thesis by (simp add: \a' = a\ U U' \b' = b\ xs xs' ys ys') qed lemma strict_sorted_interact_imp_concat: "strict_sorted (interact as bs) \ strict_sorted (concat as) \ strict_sorted (concat bs)" proof (induction as bs rule: interact.induct) case (3 x xs y ys) show ?case proof (cases x) case Nil show ?thesis proof (cases y) case Nil then show ?thesis using "3" strict_sorted_append_iff by (auto simp: \x = []\) next case (Cons a list) with Nil 3 show ?thesis apply (simp add: strict_sorted_append_iff) by (metis (no_types, lifting) Un_iff set_interact sorted_wrt_append strict_sorted_append_iff strict_sorted_sorted_wrt) qed next case (Cons a list) have \
: "sorted_wrt (<) ((a # list) @ y @ interact xs ys)" by (metis (no_types) "3.prems" interact.simps(3) local.Cons strict_sorted_sorted_wrt) then have "list = [] \ concat xs = [] \ last list < hd (concat xs)" by (metis (full_types) Un_iff hd_in_set last_ConsR last_in_set list.simps(3) set_append set_interact sorted_wrt_append) then have "list < concat xs" using less_list_def by blast have "list < y" by (metis \
append.assoc last.simps less_list_def list.distinct(1) strict_sorted_append_iff strict_sorted_sorted_wrt) note Cons1 = Cons show ?thesis proof (cases y) case Nil then show ?thesis using 3 by (simp add: sorted_wrt_append strict_sorted_sorted_wrt) next case (Cons a' list') have "strict_sorted (list' @ concat ys)" apply (simp add: strict_sorted_sorted_wrt) by (metis "3.IH" "\
" Un_iff append_Cons local.Cons set_interact sorted_wrt_append strict_sorted.simps(2) strict_sorted_sorted_wrt) moreover have "y < concat ys" by (metis "\
" Un_iff hd_in_set last_in_set less_list_def set_interact sorted_wrt_append) ultimately show ?thesis using 3 \list < concat xs\ by (auto simp: Cons1 strict_sorted_append_iff) qed qed qed auto lemma strict_sorted_interact_hd: "\strict_sorted (interact cs ds); cs \ []; ds \ []; hd cs \ []; hd ds \ []\ \ hd (hd cs) < hd (hd ds)" by (metis Nil_is_append_conv hd_append2 hd_in_set interact.simps(3) list.exhaust_sel sorted_wrt_append strict_sorted_sorted_wrt) text \the lengths of the two lists can differ by one\ proposition interaction_scheme_unique_aux: assumes eq: "concat as = concat as'" and ys': "concat bs = concat bs'" and ne: "as \ lists (- {[]})" "bs \ lists (- {[]})" and ss_zs: "strict_sorted (interact as bs)" and "length bs \ length as" "length as \ Suc (length bs)" and ne': "as' \ lists (- {[]})" "bs' \ lists (- {[]})" and ss_zs': "strict_sorted (interact as' bs')" and "length bs' \ length as'" "length as' \ Suc (length bs')" and "length as = length as'" "length bs = length bs'" shows "as = as' \ bs = bs'" using assms proof (induction "length as" arbitrary: as bs as' bs') case 0 then show ?case by auto next case (Suc k) show ?case proof (cases k) case 0 then have "length as = Suc 0" using Suc.hyps(2) by auto then obtain a a' where "as = [a]" "as' = [a']" by (metis \length as = length as'\ length_0_conv length_Suc_conv) with 0 show ?thesis using Suc.prems apply (simp add: le_Suc_eq) by (metis concat.simps length_0_conv length_Suc_conv self_append_conv) next case (Suc k') then obtain a cs b ds where eq: "as = a#cs" "bs = b#ds" using Suc.prems by (metis Suc.hyps(2) le0 list.exhaust list.size(3) not_less_eq_eq) have "length as' \ 0" using Suc.hyps(2) Suc.prems(1) Suc.prems(3) interact_eq_Nil_iff by auto then obtain a' cs' b' ds' where eq': "as' = a'#cs'" "bs' = b'#ds'" by (metis Suc.prems(14) eq(2) length_0_conv list.exhaust) obtain k: "k = length cs" "k \ Suc (length ds)" using eq \Suc k = length as\ \length bs \ length as\ \length as \ Suc (length bs)\ by auto case (Suc k') obtain [simp]: "b \ []" "b' \ []" "a \ []" "a' \ []" using Suc.prems by (simp add: eq eq') then have "hd b' = hd b" using Suc.prems(2) by (metis concat.simps(2) eq'(2) eq(2) hd_append2) have ss_ab: "strict_sorted (concat as)" "strict_sorted (concat bs)" using strict_sorted_interact_imp_concat Suc.prems(5) by blast+ have "a < b" by (metis eq Suc.prems(5) append.assoc interact.simps(3) strict_sorted_append_iff) have sw_ab: "sorted_wrt (<) (a @ b @ interact cs ds)" by (metis Suc.prems(5) eq interact.simps(3) strict_sorted_sorted_wrt) then have "hd b \ list.set (concat cs)" by (metis Un_iff \b \ []\ list.set_sel(1) not_less_iff_gr_or_eq set_interact sorted_wrt_append) have "b < concat cs" using eq \strict_sorted (interact as bs)\ apply (simp add: strict_sorted_append_iff) by (metis Un_iff sw_ab last_in_set less_list_def list.set_sel(1) set_interact sorted_wrt_append) have "strict_sorted (a @ concat cs)" using eq(1) ss_ab(1) by force then have b_cs: "strict_sorted (b @ concat cs)" by (metis \b < concat cs\ strict_sorted_append_iff strict_sorted_sorted_wrt sw_ab) have "list.set a = list.set (concat as) \ {..< hd b}" proof - have "x \ list.set a" if "x < hd b" and "l \ list.set cs" and "x \ list.set l" for x l using b_cs sorted_hd_le strict_sorted_imp_sorted that by fastforce then show ?thesis using \b \ []\ sw_ab by (force simp: strict_sorted_append_iff sorted_wrt_append eq) qed moreover have ss_ab': "strict_sorted (concat as')" "strict_sorted (concat bs')" using strict_sorted_interact_imp_concat Suc.prems(10) by blast+ have "a' < b'" by (metis eq' Suc.prems(10) append.assoc interact.simps(3) strict_sorted_append_iff) have sw_ab': "sorted_wrt (<) (a' @ b' @ interact cs' ds')" by (metis Suc.prems(10) eq' interact.simps(3) strict_sorted_sorted_wrt) then have "hd b' \ list.set (concat cs')" by (metis Un_iff \b' \ []\ list.set_sel(1) not_less_iff_gr_or_eq set_interact sorted_wrt_append) have "b' < concat cs'" using eq' \strict_sorted (interact as' bs')\ apply (simp add: strict_sorted_append_iff) by (metis Un_iff last_in_set less_list_def list.set_sel(1) set_interact sorted_wrt_append sw_ab') have "strict_sorted (a' @ concat cs')" using eq'(1) ss_ab'(1) by force then have b_cs': "strict_sorted (b' @ concat cs')" using \b' < concat cs'\ eq'(2) ss_ab'(2) strict_sorted_append_iff by auto have "list.set a' = list.set (concat as') \ {..< hd b'}" proof - have "x \ list.set a'" if "x < hd b'" and "l \ list.set cs'" and "x \ list.set l" for x l using b_cs' sorted_hd_le strict_sorted_imp_sorted that by fastforce then show ?thesis using \b' \ []\ sw_ab' by (force simp: strict_sorted_append_iff sorted_wrt_append eq') qed ultimately have "a=a'" by (metis Suc.prems(1) \hd b' = hd b\ sorted_wrt_append strict_sorted_equal strict_sorted_sorted_wrt sw_ab sw_ab') moreover have ccat_cs_cs': "concat cs = concat cs'" using Suc.prems(1) \a = a'\ eq'(1) eq(1) by fastforce have "b=b'" proof (cases "ds = [] \ ds' = []") case True then show ?thesis using Suc.prems(14) Suc.prems(2) eq'(2) eq(2) by auto next case False then have "ds \ []" "ds' \ []" by auto have "strict_sorted b" by (metis Suc.prems(2) concat.simps(2) eq(2) ss_ab'(2) strict_sorted_append_iff) moreover have "cs \ []" using k local.Suc by auto then obtain "hd cs \ []" "hd ds \ []" using Suc.prems(3) Suc.prems(4) eq list.set_sel(1) by (simp add: \ds \ []\ mem_lists_non_Nil) then have "concat cs \ []" using \cs \ []\ hd_in_set by auto have "hd (concat cs) < hd (concat ds)" using strict_sorted_interact_hd by (metis \cs \ []\ \ds \ []\ \hd cs \ []\ \hd ds \ []\ hd_concat strict_sorted_append_iff strict_sorted_sorted_wrt sw_ab) then have "list.set b = list.set (concat bs) \ {..< hd (concat cs)}" using ss_ab apply (auto simp: strict_sorted_append_iff eq) apply (metis \b < concat cs\ \concat cs \ []\ hd_in_set sorted_wrt_append strict_sorted_append_iff strict_sorted_sorted_wrt) by (metis strict_sorted_iff UN_I dual_order.strict_trans2 order.asym set_concat sorted_hd_le) moreover have "cs' \ []" using k local.Suc \concat cs \ []\ ccat_cs_cs' by auto then obtain "hd cs' \ []" "hd ds' \ []" using Suc.prems(8,9) \ds' \ []\ eq'(1) eq'(2) list.set_sel(1) by auto then have "concat cs' \ []" using \cs' \ []\ hd_in_set by auto have "hd (concat cs') < hd (concat ds')" using strict_sorted_interact_hd by (metis \cs' \ []\ \ds' \ []\ \hd cs' \ []\ \hd ds' \ []\ hd_concat strict_sorted_append_iff strict_sorted_sorted_wrt sw_ab') then have "list.set b' = list.set (concat bs') \ {..< hd (concat cs')}" using ss_ab' apply (auto simp: strict_sorted_append_iff eq') apply (meson strict_sorted_iff \b' < concat cs'\ \b' \ []\ \concat cs' \ []\ dual_order.strict_trans2 less_list_def sorted_le_last) by (metis strict_sorted_iff UN_I dual_order.strict_trans2 order.asym set_concat sorted_hd_le) ultimately show "b = b'" by (metis Suc.prems(2) ccat_cs_cs' strict_sorted_append_iff strict_sorted_equal strict_sorted_sorted_wrt sw_ab') qed moreover have "cs = cs' \ ds = ds'" proof (rule Suc.hyps) show "k = length cs" using eq Suc.hyps(2) by auto[1] show "concat ds = concat ds'" using Suc.prems(2) \b = b'\ eq'(2) eq(2) by auto show "strict_sorted (interact cs ds)" using eq Suc.prems(5) strict_sorted_append_iff by auto show "length ds \ length cs" "length cs \ Suc (length ds)" using eq Suc.hyps(2) Suc.prems(6) k by auto show "strict_sorted (interact cs' ds')" using eq' Suc.prems(10) strict_sorted_append_iff by auto show "length cs = length cs'" using Suc.hyps(2) Suc.prems(13) eq'(1) k(1) by force qed (use ccat_cs_cs' eq eq' Suc.prems in auto) ultimately show ?thesis by (simp add: \a = a'\ \b = b'\ eq eq') qed qed proposition Form_Body_unique: assumes "Form_Body ka kb xs ys zs" "Form_Body ka kb xs ys zs'" and "kb \ ka" "ka \ Suc kb" shows "zs' = zs" proof - obtain a as b bs c d where xs: "xs = concat (a#as)" and ys: "ys = concat (b#bs)" and ne: "a#as \ lists (- {[]})" "b#bs \ lists (- {[]})" and len: "length (a#as) = ka" "length (b#bs) = kb" and c: "c = acc_lengths 0 (a#as)" and d: "d = acc_lengths 0 (b#bs)" and Ueq: "zs = concat [c, a, d, b] @ interact as bs" and ss_zs: "strict_sorted zs" using Form_Body.cases [OF assms(1)] by (metis (no_types)) obtain a' as' b' bs' c' d' where xs': "xs = concat (a'#as')" and ys': "ys = concat (b'#bs')" and ne': "a'#as' \ lists (- {[]})" "b'#bs' \ lists (- {[]})" and len': "length (a'#as') = ka" "length (b'#bs') = kb" and c': "c' = acc_lengths 0 (a'#as')" and d': "d' = acc_lengths 0 (b'#bs')" and Ueq': "zs' = concat [c', a', d', b'] @ interact as' bs'" and ss_zs': "strict_sorted zs'" using Form_Body.cases [OF assms(2)] by (metis (no_types)) have [simp]: "length c = length c'" "length d = length d'" using c c' d d' len' len by auto have "a < b" using ss_zs apply (simp add: Ueq strict_sorted_append_iff) by (metis strict_sorted_iff append.assoc d length_0_conv length_acc_lengths list.distinct(1) strict_sorted_append_iff sorted_trans) have "a' < b'" using ss_zs' apply (simp add: Ueq' strict_sorted_append_iff) by (metis strict_sorted_iff append.assoc d' length_0_conv length_acc_lengths list.distinct(1) strict_sorted_append_iff sorted_trans) have "a#as = a'#as' \ b#bs = b'#bs'" proof (rule interaction_scheme_unique_aux) show "concat (a # as) = concat (a' # as')" using xs xs' by blast show "concat (b # bs) = concat (b' # bs')" using ys ys' by blast show "a # as \ lists (- {[]})" "b # bs \ lists (- {[]})" using ne by auto show "strict_sorted (interact (a # as) (b # bs))" using ss_zs \a < b\ apply (simp add: Ueq strict_sorted_append_iff) by (metis strict_sorted_iff append.assoc append.left_neutral strict_sorted_append_iff sorted_trans) show "length (b # bs) \ length (a # as)" "length (b' # bs') \ length (a' # as')" using \kb \ ka\ len len' by auto show "length (a # as) \ Suc (length (b # bs))" using \ka \ Suc kb\ len by linarith then show "length (a' # as') \ Suc (length (b' # bs'))" using len len' by fastforce show "a' # as' \ lists (- {[]})" "b' # bs' \ lists (- {[]})" using ne' by auto show "strict_sorted (interact (a' # as') (b' # bs'))" using ss_zs' \a' < b'\ apply (simp add: Ueq' strict_sorted_append_iff) by (metis strict_sorted_iff append.assoc append.left_neutral strict_sorted_append_iff sorted_trans) show "length (a # as) = length (a' # as')" using len'(1) len(1) by blast show "length (b # bs) = length (b' # bs')" using len'(2) len(2) by blast qed then show ?thesis using Ueq Ueq' c c' d d' by blast qed lemma Form_Body_imp_inter_scheme: assumes "Form_Body ka kb xs ys zs" and "0 < kb" "kb \ ka" "ka \ Suc kb" shows "zs = inter_scheme ((ka+kb) - Suc 0) {xs,ys}" proof - have "length xs < length ys" by (meson Form_Body_length assms(1)) have [simp]: "a + a = b + b \ a=b" "a + a - Suc 0 = b + b - Suc 0 \ a=b" for a b::nat by auto show ?thesis proof (cases "ka = kb") case True show ?thesis unfolding inter_scheme_def apply (rule some_equality [symmetric]) using assms True mult_2 not_gr0 one_is_add apply fastforce using assms \length xs < length ys\ apply (auto simp: True mult_2 Set.doubleton_eq_iff Form_Body_unique dest: Form_Body_length) by presburger next case False then have eq: "ka = Suc kb" using assms by linarith show ?thesis unfolding inter_scheme_def apply (rule some_equality [symmetric]) using assms False mult_2 one_is_add eq apply fastforce using assms \length xs < length ys\ apply (auto simp: eq mult_2 Set.doubleton_eq_iff Form_Body_unique dest: Form_Body_length) by presburger qed qed subsection \For Lemma 3.8 AND PROBABLY 3.7\ definition grab :: "nat set \ nat \ nat set \ nat set" where "grab N n \ (N \ enumerate N ` {.. {enumerate N n..})" lemma grab_0 [simp]: "grab N 0 = ({}, N)" by (fastforce simp add: grab_def enumerate_0 Least_le) lemma less_sets_grab: - "infinite N \ less_sets (fst (grab N n)) (snd (grab N n))" + "infinite N \ fst (grab N n) \ snd (grab N n)" by (auto simp: grab_def less_sets_def intro: enumerate_mono less_le_trans) lemma finite_grab [iff]: "finite (fst (grab N n))" by (simp add: grab_def) lemma card_grab [simp]: assumes "infinite N" shows "card (fst (grab N n)) = n" proof - have "N \ enumerate N ` {.. N" using grab_def range_enum by fastforce lemma snd_grab_subset: "snd (grab N n) \ N" by (auto simp: grab_def) lemma grab_Un_eq: assumes "infinite N" shows "fst (grab N n) \ snd (grab N n) = N" proof show "N \ fst (grab N n) \ snd (grab N n)" unfolding grab_def using assms enumerate_Ex le_less_linear strict_mono_enum strict_mono_less by fastforce qed (simp add: grab_def) lemma finite_grab_iff [simp]: "finite (snd (grab N n)) \ finite N" by (metis finite_grab grab_Un_eq infinite_Un infinite_super snd_grab_subset) lemma grab_eqD: "\grab N n = (A,M); infinite N\ - \ less_sets A M \ finite A \ card A = n \ infinite M \ A \ N \ M \ N" + \ A \ M \ finite A \ card A = n \ infinite M \ A \ N \ M \ N" using card_grab grab_def less_sets_grab finite_grab_iff by auto -lemma less_sets_fst_grab: "less_sets A N \ less_sets A (fst (grab N n))" +lemma less_sets_fst_grab: "A \ N \ A \ fst (grab N n)" by (simp add: fst_grab_subset less_sets_weaken2) text\Possibly redundant, given @{term grab}\ definition nxt where "nxt \ \N. \n::nat. N \ {n<..}" lemma infinite_nxtN: "infinite N \ infinite (nxt N n)" by (simp add: infinite_nat_greaterThan nxt_def) lemma nxt_subset: "nxt N n \ N" unfolding nxt_def by blast lemma nxt_subset_greaterThan: "m \ n \ nxt N n \ {m<..}" by (auto simp: nxt_def) lemma nxt_subset_atLeast: "m \ n \ nxt N n \ {m..}" by (auto simp: nxt_def) lemma enum_nxt_ge: "infinite N \ a \ enum (nxt N a) n" by (simp add: atLeast_le_enum infinite_nxtN nxt_subset_atLeast) lemma inj_enum_nxt: "infinite N \ inj_on (enum (nxt N a)) A" by (simp add: infinite_nxtN strict_mono_enum strict_mono_imp_inj_on) subsection \Larson's Lemma 3.11\ text \Again from Jean A. Larson, A short proof of a partition theorem for the ordinal $\omega^\omega$. \emph{Annals of Mathematical Logic}, 6:129–145, 1973.\ lemma lemma_3_11: assumes "l > 0" shows "thin (inter_scheme l ` {U. Form l U})" using form_cases [of l] proof cases case zero then show ?thesis using assms by auto next case (nz ka kb) show ?thesis unfolding thin_def proof clarify fix U U' assume ne: "inter_scheme l U \ inter_scheme l U'" and init: "initial_segment (inter_scheme l U) (inter_scheme l U')" assume "Form l U" then obtain kp kq xs ys where "l = kp+kq - 1" "U = {xs,ys}" and U: "Form_Body kp kq xs ys (inter_scheme l U)" and "0 < kq" "kq \ kp" "kp \ Suc kq" using assms inter_scheme by blast then have "kp = ka \ kq = kb" using nz by linarith then obtain a as b bs c d where xs: "xs = concat (a#as)" and ys: "ys = concat (b#bs)" and len: "length (a#as) = ka" "length (b#bs) = kb" and c: "c = acc_lengths 0 (a#as)" and d: "d = acc_lengths 0 (b#bs)" and Ueq: "inter_scheme l U = concat [c, a, d, b] @ interact as bs" using U by (auto simp: Form_Body.simps) assume "Form l U'" then obtain kp' kq' xs' ys' where "l = kp'+kq' - 1" "U' = {xs',ys'}" and U': "Form_Body kp' kq' xs' ys' (inter_scheme l U')" and "0 < kq'" "kq' \ kp'" "kp' \ Suc kq'" using assms inter_scheme by blast then have "kp' = ka \ kq' = kb" using nz by linarith then obtain a' as' b' bs' c' d' where xs': "xs' = concat (a'#as')" and ys': "ys' = concat (b'#bs')" and len': "length (a'#as') = ka" "length (b'#bs') = kb" and c': "c' = acc_lengths 0 (a'#as')" and d': "d' = acc_lengths 0 (b'#bs')" and Ueq': "inter_scheme l U' = concat [c', a', d', b'] @ interact as' bs'" using U' by (auto simp: Form_Body.simps) have [simp]: "length bs' = length bs" "length as' = length as" using len len' by auto have "inter_scheme l U \ []" "inter_scheme l U' \ []" using Form_Body_nonempty U U' by auto define u1 where "u1 \ hd (inter_scheme l U)" have u1_eq': "u1 = hd (inter_scheme l U')" using \inter_scheme l U \ []\ init u1_def initial_segment_ne by fastforce have au1: "u1 = length a" by (simp add: u1_def Ueq c acc_lengths.simps) have au1': "u1 = length a'" by (simp add: u1_eq' Ueq' c' acc_lengths.simps) have len_eqk: "length c' = ka" "length d' = kb" "length c' = ka" "length d' = kb" using c d len c' d' len' by auto have take: "take (ka + u1 + kb) (c @ a @ d @ l) = c @ a @ d" "take (ka + u1 + kb) (c' @ a' @ d' @ l) = c' @ a' @ d'" for l using c d c' d' len by (simp_all add: flip: au1 au1') have leU: "ka + u1 + kb \ length (inter_scheme l U)" using c d len by (simp add: au1 Ueq) then have "take (ka + u1 + kb) (inter_scheme l U) = take (ka + u1 + kb) (inter_scheme l U')" using take_initial_segment init by blast then have \
: "c @ a @ d = c' @ a' @ d'" by (metis Ueq Ueq' append.assoc concat.simps(2) take) have "length (inter_scheme l U) = ka + (c @ a @ d)!(ka-1) + kb + last d" by (simp add: Ueq c d length_interact nth_append flip: len) moreover have "length (inter_scheme l U') = ka + (c' @ a' @ d')!(ka-1) + kb + last d'" by (simp add: Ueq' c' d' length_interact nth_append flip: len') moreover have "last d = last d'" using "\
" c d d' len'(1) len_eqk(1) by auto ultimately have "length (inter_scheme l U) = length (inter_scheme l U')" by (simp add: \
) then show False using init initial_segment_length_eq ne by blast qed qed subsection \Larson's Lemma 3.6\ proposition lemma_3_6: fixes g :: "nat list set \ nat" assumes g: "g \ [WW]\<^bsup>2\<^esup> \ {0,1}" obtains N j where "infinite N" and "\k u. \k > 0; u \ [WW]\<^bsup>2\<^esup>; Form k u; [enum N k] < inter_scheme k u; List.set (inter_scheme k u) \ N\ \ g u = j k" proof - define \ where "\ \ \m::nat. \M. infinite M \ m < Inf M" define \ where "\ \ \l m n::nat. \M N j. n > m \ N \ M \ n \ M \ (\U. Form l U \ U \ WW \ [n] < inter_scheme l U \ list.set (inter_scheme l U) \ N \ g U = j)" { fix l m::nat and M :: "nat set" assume "l > 0" "\ m M" let ?A = "inter_scheme l ` {U \ [WW]\<^bsup>2\<^esup>. Form l U}" define h where "h \ \zs. g (inv_into {U \ [WW]\<^bsup>2\<^esup>. Form l U} (inter_scheme l) zs)" have "thin ?A" using \l > 0\ lemma_3_11 by (simp add: thin_def) moreover have "?A \ WW" using inter_scheme_simple \0 < l\ by blast moreover have "h ` {l \ ?A. List.set l \ M} \ {..<2}" using g inv_into_into[of concl: "{U \ [WW]\<^bsup>2\<^esup>. Form l U}" "inter_scheme l"] by (force simp: h_def Pi_iff) ultimately obtain j N where "j < 2" "infinite N" "N \ M" and hj: "h ` {l \ ?A. List.set l \ N} \ {j}" using \\ m M\ unfolding \_def by (blast intro: Nash_Williams_WW [of M]) define n where "n \ Inf N" have "n > m" using \\ m M\ \infinite N\ unfolding n_def \_def Inf_nat_def infinite_nat_iff_unbounded by (metis LeastI_ex \N \ M\ le_less_trans not_less not_less_Least subsetD) have "g U = j" if "Form l U" "U \ WW" "[n] < inter_scheme l U" "list.set (inter_scheme l U) \ N - {n}" for U proof - obtain xs ys where xys: "xs \ ys" "U = {xs,ys}" using Form_elim_upair \Form l U\ by blast moreover have "inj_on (inter_scheme l) {U \ [WW]\<^bsup>2\<^esup>. Form l U}" by (metis (mono_tags, lifting) inter_scheme_injective \0 < l\ inj_onI mem_Collect_eq) moreover have "g (inv_into {U \ [WW]\<^bsup>2\<^esup>. Form l U} (inter_scheme l) (inter_scheme l U)) = j" using hj that xys apply (simp add: h_def image_subset_iff image_iff) by (metis (no_types, lifting) Diff_subset doubleton_in_nsets_2 dual_order.trans) ultimately show ?thesis using that by auto qed moreover have "n < Inf (N - {n})" unfolding n_def by (metis Diff_iff Inf_nat_def Inf_nat_def1 \infinite N\ finite.emptyI infinite_remove linorder_neqE_nat not_less_Least singletonI) moreover have "n \ M" by (metis Inf_nat_def1 \N \ M\ \infinite N\ finite.emptyI n_def subsetD) ultimately have "\ n (N - {n}) \ \ l m n M (N - {n}) j" using \\ m M\ \infinite N\ \N \ M\ \n > m\ by (auto simp: \_def \_def) then have "\n N j. \ n N \ \ l m n M N j" by blast } note * = this have base: "\ 0 {0<..}" unfolding \_def by (metis infinite_Ioi Inf_nat_def1 greaterThan_iff greaterThan_non_empty) have step: "Ex (\(n,N,j). \ n N \ \ l m n M N j)" if "\ m M" "l > 0" for m M l using * [of l m M] that by (auto simp: \_def) define G where "G \ \l m M. @(n,N,j). \ n N \ \ (Suc l) m n M N j" have G\: "(\(n,N,j). \ n N) (G l m M)" and G\: "(\(n,N,j). \ (Suc l) m n M N j) (G l m M)" if "\ m M" for l m M using step [OF that, of "Suc l"] by (force simp: G_def dest: some_eq_imp)+ have G_increasing: "(\(n,N,j). n > m \ N \ M \ n \ M) (G l m M)" if "\ m M" for l m M using G\ [OF that, of l] that by (simp add: \_def split: prod.split_asm) define H where "H \ rec_nat (0,{0<..},0) (\l (m,M,j). G l m M)" have H_simps: "H 0 = (0,{0<..},0)" "\l. H (Suc l) = (case H l of (m,M,j) \ G l m M)" by (simp_all add: H_def) have H\: "(\(n,N,j). \ n N) (H l)" for l proof (induction l) case 0 with base show ?case by (auto simp: H_simps) next case (Suc l) with G\ show ?case by (force simp: H_simps split: prod.split prod.split_asm) qed define \ where "\ \ (\l. case H l of (n,M,j) \ n)" have H_inc: "\ l \ l" for l proof (induction l) case 0 then show ?case by auto next case (Suc l) then show ?case using H\ G_increasing [of "\ l"] apply (auto simp: H_simps \_def split: prod.split prod.split_asm) by (metis (mono_tags, lifting) Suc_leI Suc_le_mono case_prod_conv dual_order.trans) qed let ?N = "range \" define j where "j \ \l. case H l of (n,M,j) \ j" have H_increasing_Suc: "(case H k of (n, N, j') \ N) \ (case H (Suc k) of (n, N, j') \ insert n N)" for k using H\ [of k] by (force simp: H_simps split: prod.split dest: G_increasing [where l=k]) have H_increasing_superset: "(case H k of (n, N, j') \ N) \ (case H (n+k) of (n, N, j') \ N)" for k n proof (induction n arbitrary:) case (Suc n) then show ?case using H_increasing_Suc [of "n+k"] by (auto split: prod.split_asm) qed auto then have H_increasing_less: "(case H k of (n, N, j') \ N) \ (case H l of (n, N, j') \ insert n N)" if "k k < \ (Suc k)" for k using H\ [of k] unfolding \_def by (auto simp: H_simps split: prod.split dest: G_increasing [where l=k]) then have strict_mono_\: "strict_mono \" by (simp add: strict_mono_Suc_iff) then have enum_N: "enum ?N = \" by (metis enum_works nat_infinite_iff range_strict_mono_ext) have **: "?N \ {n<..} \ N'" if H: "H k = (n, N', j)" for n N' k j proof clarify fix l assume "n < \ l" then have False if "l \ k" using that strict_monoD [OF strict_mono_\, of l k ] H by (force simp: \_def) then have "k < l" using not_less by blast then obtain M j where Mj: "H l = (\ l,M,j)" unfolding \_def by (metis (mono_tags, lifting) case_prod_conv old.prod.exhaust) then show "\ l \ N'" using that H_increasing_less [OF \k] Mj by auto qed show thesis proof show "infinite (?N::nat set)" using H_inc infinite_nat_iff_unbounded_le by auto next fix l U assume "0 < l" and U: "U \ [WW]\<^bsup>2\<^esup>" and interU: "[enum ?N l] < inter_scheme l U" "Form l U" and sub: "list.set (inter_scheme l U) \ ?N" obtain k where k: "l = Suc k" using \0 < l\ gr0_conv_Suc by blast have "U \ WW" using U by (auto simp: nsets_def) moreover have "g U = v" if "H k = (m, M, j0)" and "G k m M = (n, N', v)" for m M j0 n N' v proof - have n: "\ (Suc k) = n" using that by (simp add: \_def H_simps) have "{..enum (range \) l} \ list.set (inter_scheme l U) = {}" using inter_scheme_strict_sorted \0 < l\ interU singleton_less_list_iff strict_sorted_iff by blast then have "list.set (inter_scheme (Suc k) U) \ N'" using that sub ** [of "Suc k" n N' v] Suc_le_eq not_less_eq_eq by (fastforce simp add: k n enum_N H_simps) then show ?thesis using that interU \U \ WW\ G\ [of m M k] H\ [of k] by (auto simp: \_def k enum_N H_simps n) qed ultimately show "g U = j l" by (auto simp: k j_def H_simps split: prod.split) qed qed subsection \Larson's Lemma 3.7\ subsubsection \Preliminaries\ text \Analogous to @{thm [source] ordered_nsets_2_eq}, but without type classes\ lemma total_order_nsets_2_eq: assumes tot: "total_on A r" and irr: "irrefl r" shows "nsets A 2 = {{x,y} | x y. x \ A \ y \ A \ (x,y) \ r}" (is "_ = ?rhs") proof show "nsets A 2 \ ?rhs" unfolding numeral_nat apply (clarsimp simp add: nsets_def card_Suc_eq Set.doubleton_eq_iff not_less) by (metis tot total_on_def) show "?rhs \ nsets A 2" using irr unfolding numeral_nat by (force simp: nsets_def card_Suc_eq irrefl_def) qed lemma lenlex_nsets_2_eq: "nsets A 2 = {{x,y} | x y. x \ A \ y \ A \ (x,y) \ lenlex less_than}" using total_order_nsets_2_eq by (simp add: total_order_nsets_2_eq irrefl_def) lemma sum_sorted_list_of_set_map: "finite I \ sum_list (map f (list_of I)) = sum f I" proof (induction "card I" arbitrary: I) case 0 then show ?case by auto next case (Suc n I) then have [simp]: "I \ {}" by auto moreover have "sum_list (map f (list_of (I - {Min I}))) = sum f (I - {Min I})" using Suc by auto ultimately show ?case using Suc.prems sum.remove [of I "Min I" f] by (simp add: sorted_list_of_set_nonempty Suc) qed lemma sorted_list_of_set_UN_eq_concat: assumes I: "strict_mono_sets I f" "finite I" and fin: "\i. finite (f i)" shows "list_of (\i \ I. f i) = concat (map (list_of \ f) (list_of I))" using I proof (induction "card I" arbitrary: I) case 0 then have "I={}" by auto then show ?case by auto next case (Suc n I) then have "I \ {}" and Iexp: "I = insert (Min I) (I - {Min I})" using Min_in Suc.hyps(2) Suc.prems(2) by fastforce+ have IH: "list_of (\ (f ` (I - {Min I}))) = concat (map (list_of \ f) (list_of (I - {Min I})))" using Suc by (metis DiffE Min_in \I \ {}\ card_Diff_singleton diff_Suc_1 finite_Diff strict_mono_sets_def) have "list_of (\ (f ` I)) = list_of (\ (f ` (insert (Min I) (I - {Min I}))))" using Iexp by auto also have "\ = list_of (f (Min I) \ \ (f ` (I - {Min I})))" by (metis Union_image_insert) also have "\ = list_of (f (Min I)) @ list_of (\ (f ` (I - {Min I})))" proof (rule sorted_list_of_set_Un) - show "less_sets (f (Min I)) (\ (f ` (I - {Min I})))" + show "f (Min I) \ \ (f ` (I - {Min I}))" using Suc.prems \I \ {}\ strict_mono_less_sets_Min by blast show "finite (\ (f ` (I - {Min I})))" by (simp add: \finite I\ fin) qed (use fin in auto) also have "\ = list_of (f (Min I)) @ concat (map (list_of \ f) (list_of (I - {Min I})))" using IH by metis also have "\ = concat (map (list_of \ f) (list_of I))" by (simp add: Suc.prems(2) \I \ {}\ sorted_list_of_set_nonempty) finally show ?case . qed subsubsection \Lemma 3.7 of Jean A. Larson, ibid.\ text \Possibly should be redone using grab\ proposition lemma_3_7: assumes "infinite N" "l > 0" obtains M where "M \ [WW]\<^bsup>m\<^esup>" "\U. U \ [M]\<^bsup>2\<^esup> \ Form l U \ List.set (inter_scheme l U) \ N" proof (cases "m < 2") case True obtain w where w: "w \ WW" using WW_def strict_sorted_into_WW by auto define M where "M \ if m=0 then {} else {w}" have M: "M \ [WW]\<^bsup>m\<^esup>" using True by (auto simp: M_def nsets_def w) have [simp]: "[M]\<^bsup>2\<^esup> = {}" using True by (auto simp: M_def nsets_def w dest: subset_singletonD) show ?thesis using M that by fastforce next case False then have "m \ 2" by auto have nonz: "(enum N \ Suc) i > 0" for i using assms(1) le_enumerate less_le_trans by fastforce note infinite_nxtN [OF \infinite N\, iff] have [simp]: "{n<.. \k. rec_nat ((enum N \ Suc) ` {..r D. enum (nxt N (enum (nxt N (Max D)) (Inf D - Suc 0))) ` {.. Suc) ` {.. Suc) {..infinite N\ DF_simps card_image infinite_nxtN strict_mono_enum strict_mono_imp_inj_on) qed have DF_ne: "DF k i \ {}" for i k by (metis card_DF card_lessThan lessThan_empty_iff nat.simps(3)) have DF_N: "DF k i \ N \ {0<..}" for i k proof (induction i) case 0 then show ?case using \infinite N\ range_enum nonz by (auto simp: DF_simps) next case (Suc i) then show ?case unfolding DF_simps image_subset_iff using infinite_nxtN [OF \infinite N\] by (metis Int_iff enumerate_in_set greaterThan_iff not_gr0 not_less0 nxt_def) qed then have DF_gt0: "0 < Inf (DF k i)" for i k using DF_ne Inf_nat_def1 by blast have finite_DF: "finite (DF k i)" for i k by (induction i) (auto simp: DF_simps) have sm_enum_DF: "strict_mono_on (enum (DF k i)) {..k}" for k i by (metis card_DF enum_works_finite finite_DF lessThan_Suc_atMost) - have DF_Suc: "less_sets (DF k i) (DF k (Suc i))" for i k + have DF_Suc: "DF k i \ DF k (Suc i)" for i k unfolding less_sets_def by (force simp: finite_DF DF_simps intro!: greaterThan_less_enum nxt_subset_greaterThan atLeast_le_enum nxt_subset_atLeast infinite_nxtN [OF \infinite N\]) - have DF_DF: "less_sets (DF k i) (DF k j)" if "i DF k j" if "i \k i. enum (nxt N (Max (DF k i))) ` {.. {}" for i k by (auto simp: AF_def lessThan_empty_iff DF_gt0) have finite_AF [simp]: "finite (AF k i)" for i k by (simp add: AF_def) have card_AF: "card (AF k i) = \ (DF k i)" for k i by (simp add: AF_def \infinite N\ card_image inj_enum_nxt) - have DF_AF: "less_sets (DF k i) (AF k i)" for i k + have DF_AF: "DF k i \ AF k i" for i k unfolding less_sets_def AF_def by (simp add: finite_DF \infinite N\ greaterThan_less_enum nxt_subset_greaterThan) - have AF_DF_Suc: "less_sets (AF k i) (DF k (Suc i))" for i k + have AF_DF_Suc: "AF k i \ DF k (Suc i)" for i k apply (clarsimp simp: DF_simps less_sets_def AF_def) using strict_monoD [OF strict_mono_enum] by (metis DF_gt0 Suc_pred assms(1) dual_order.order_iff_strict greaterThan_less_enum infinite_nxtN linorder_neqE_nat not_less_eq nxt_subset_greaterThan) - have AF_DF: "less_sets (AF k p) (DF k q)" if "p DF k q" if "p AF k (Suc i)" for i k using AF_DF_Suc DF_AF DF_ne less_sets_trans by blast then have sm_AF: "strict_mono_sets UNIV (AF k)" for k by (simp add: AF_ne less_sets_imp_strict_mono_sets) define del where "del \ \k i j. enum (DF k i) j - enum (DF k i) (j - Suc 0)" define QF where "QF k \ wfrec pair_less (\f (j,i). if j=0 then AF k i else let r = (if i=0 then f (j-1,m-1) else f (j,i-1)) in enum (nxt N (Suc (Max r))) ` {..< del k (if j=k then m - Suc i else i) j})" for k note cut_apply [simp] have finite_QF [simp]: "finite (QF k p)" for p k using wf_pair_less proof (induction p rule: wf_induct_rule) case (less p) then show ?case by (simp add: def_wfrec [OF QF_def, of k p] split: prod.split) qed have del_gt_0: "\j < Suc k; 0 < j\ \ 0 < del k i j" for i j k by (simp add: card_DF del_def finite_DF) have QF_ne [simp]: "QF k (j,i) \ {}" if j: "j < Suc k" for j i k using wf_pair_less j proof (induction "(j,i)" rule: wf_induct_rule) case less then show ?case by (auto simp: def_wfrec [OF QF_def, of k "(j,i)"] AF_ne lessThan_empty_iff del_gt_0) qed have QF_0 [simp]: "QF k (0,i) = AF k i" for i k by (simp add: def_wfrec [OF QF_def]) have QF_Suc: "QF k (Suc j,0) = enum (nxt N (Suc (Max (QF k (j, m - Suc 0))))) ` {..< del k (if Suc j = k then m - 1 else 0) (Suc j)}" for j k apply (simp add: def_wfrec [OF QF_def, of k "(Suc j,0)"]) apply (simp add: pair_less_def cut_def) done have QF_Suc_Suc: "QF k (Suc j, Suc i) = enum (nxt N (Suc (Max (QF k (Suc j, i))))) ` {..< del k (if Suc j = k then m - Suc(Suc i) else Suc i) (Suc j)}" for i j k by (simp add: def_wfrec [OF QF_def, of k "(Suc j,Suc i)"]) - have less_QF1: "less_sets (QF k (j, m - Suc 0)) (QF k (Suc j,0))" for j k + have less_QF1: "QF k (j, m - Suc 0) \ QF k (Suc j,0)" for j k by (auto simp: def_wfrec [OF QF_def, of k "(Suc j,0)"] pair_lessI1 \infinite N\ enum_nxt_ge intro!: less_sets_weaken2 [OF less_sets_Suc_Max]) - have less_QF2: "less_sets (QF k (j,i)) (QF k (j, Suc i))" for j i k + have less_QF2: "QF k (j,i) \ QF k (j, Suc i)" for j i k by (auto simp: def_wfrec [OF QF_def, of k "(j, Suc i)"] pair_lessI2 \infinite N\ enum_nxt_ge intro: less_sets_weaken2 [OF less_sets_Suc_Max] strict_mono_setsD [OF sm_AF]) - have less_QF_same: "less_sets (QF k (j,i')) (QF k (j,i))" + have less_QF_same: "QF k (j,i') \ QF k (j,i)" if "i' < i" "j \ k" for i' i j k proof (rule strict_mono_setsD [OF less_sets_imp_strict_mono_sets [of "\i. QF k (j,i)"]]) - show "less_sets (QF k (j, i)) (QF k (j, Suc i))" for i + show "QF k (j, i) \ QF k (j, Suc i)" for i by (simp add: less_QF2) show "QF k (j, i) \ {}" if "0 < i" for i using that by (simp add: \j \ k\ le_imp_less_Suc) qed (use that in auto) - have less_QF_step: "less_sets (QF k (j - Suc 0, i')) (QF k (j,i))" + have less_QF_step: "QF k (j - Suc 0, i') \ QF k (j,i)" if "0 < j" "j \ k" "i' < m" for j i' i k proof - - have less_QF1': "less_sets (QF k (j - Suc 0, m - Suc 0)) (QF k (j,0))" if "j > 0" for j + have less_QF1': "QF k (j - Suc 0, m - Suc 0) \ QF k (j,0)" if "j > 0" for j by (metis less_QF1 that Suc_pred) - have \
: "less_sets (QF k (j - Suc 0, i')) (QF k (j,0))" + have \
: "QF k (j - Suc 0, i') \ QF k (j,0)" proof (cases "i' = m - Suc 0") case True then show ?thesis using less_QF1' \0 < j\ by blast next case False show ?thesis using False that less_sets_trans [OF less_QF_same less_QF1' QF_ne] by auto qed then show ?thesis by (metis QF_ne less_QF_same less_Suc_eq_le less_sets_trans \j \ k\ zero_less_iff_neq_zero) qed - have less_QF: "less_sets (QF k (j',i')) (QF k (j,i))" + have less_QF: "QF k (j',i') \ QF k (j,i)" if j: "j' < j" "j \ k" and i: "i' < m" "i < m" for j' j i' i k using j proof (induction "j-j'" arbitrary: j) case 0 then show ?case by auto next case (Suc d) then have eq: "d = (j - Suc 0) - j'" by linarith show ?case proof (cases "j' < j - Suc 0") case True - then have "less_sets (QF k (j', i')) (QF k (j - Suc 0, i))" + then have "QF k (j', i') \ QF k (j - Suc 0, i)" using Suc eq by auto then show ?thesis by (rule less_sets_trans [OF _ less_QF_step QF_ne]) (use Suc i in auto) next case False then have "j' = j - Suc 0" using \j' < j\ by linarith then show ?thesis using Suc.hyps \j \ k\ less_QF_step i by auto qed qed have sm_QF: "strict_mono_sets ({..k} \ {.. {..k} \ {.. {..k} \ {..: "p = (j',i')" "q = (j,i)" "i' < m" "i < m" "j' \ k" "j \ k" using surj_pair [of p] surj_pair [of q] by blast with \p < q\ have "j' < j \ j' = j \ i' < i" by auto - then show "less_sets (QF k p) (QF k q)" + then show "QF k p \ QF k q" proof (elim conjE disjE) assume "j' < j" - show "less_sets (QF k p) (QF k q)" + show "QF k p \ QF k q" by (simp add: \
\j' < j\ less_QF that) qed (use \
in \simp add: that less_QF_same\) qed then have sm_QF1: "strict_mono_sets {..j. QF k (j,i))" if "i ka" "ka \ k" for ka k i proof - have "{.. {..k}" by (metis lessThan_Suc_atMost lessThan_subset_iff \Suc k \ ka\) then show ?thesis by (simp add: less_QF strict_mono_sets_def subset_iff that) qed have disjoint_QF: "i'=i \ j'=j" if "\ disjnt (QF k (j', i')) (QF k (j,i))" "j' \ k" "j \ k" "i' < m" "i < m" for i' i j' j k using that strict_mono_sets_imp_disjoint [OF sm_QF] by (force simp: pairwise_def) have card_QF: "card (QF k (j,i)) = (if j=0 then \ (DF k i) else del k (if j = k then m - Suc i else i) j)" for i k j proof (cases j) case 0 then show ?thesis by (simp add: AF_def card_image \infinite N\ inj_enum_nxt) next case (Suc j') show ?thesis by (cases i; simp add: Suc QF_Suc QF_Suc_Suc card_image \infinite N\ inj_enum_nxt) qed have AF_non_Nil: "list_of (AF k i) \ []" for k i by (simp add: AF_ne) have QF_non_Nil: "list_of (QF k (j,i)) \ []" if "j < Suc k" for i j k by (simp add: that) have AF_subset_N: "AF k i \ N" for i k unfolding AF_def image_subset_iff using nxt_subset enumerate_in_set infinite_nxtN \infinite N\ by blast have QF_subset_N: "QF k (j,i) \ N" for i j k proof (induction j) case 0 with AF_subset_N show ?case by auto next case (Suc j) show ?case by (cases i) (use nxt_subset enumerate_in_set in \(force simp: QF_Suc QF_Suc_Suc)+\) qed obtain ka k where "k>0" and kka: "k \ ka" "ka \ Suc k" "l = ((ka+k) - Suc 0)" by (metis One_nat_def assms(2) diff_add_inverse form_cases le0 le_refl) then have "ka > 0" using dual_order.strict_trans1 by blast have ka_k_or_Suc: "ka = k \ ka = Suc k" using kka by linarith have lessThan_k: "{..0" for k::nat using that by auto then have sorted_list_of_set_k: "list_of {..0" for k::nat using sorted_list_of_set_insert_cons [of concl: 0 "{0<.. \j i. if j = k then QF k (j, m - Suc i) else QF k (j,i)" have RF_subset_N: "RF j i \ N" if "i0 < k\ by auto have disjoint_RF: "i'=i \ j'=j" if "\ disjnt (RF j' i') (RF j i)" "j' \ k" "j \ k" "i' < m" "i < m" for i' i j' j using disjoint_QF that by (auto simp: RF_def split: if_split_asm dest: disjoint_QF) have sum_card_RF [simp]: "(\j\n. card (RF j i)) = enum (DF k i) n" if "n \ k" "i < m" for i n using that proof (induction n) case 0 then show ?case using DF_ne [of k i] finite_DF [of k i] \k>0\ by (simp add: RF_def AF_def card_image \infinite N\ inj_enum_nxt enum_0_eq_Inf_finite) next case (Suc n) then have "enum (DF k i) 0 \ enum (DF k i) n \ enum (DF k i) n \ enum (DF k i) (Suc n)" using sm_enum_DF [of k i] apply (simp add: strict_mono_on_def) by (metis Suc_leD dual_order.order_iff_strict le0) with Suc show ?case by (auto simp: RF_def card_QF del_def) qed have DF_in_N: "enum (DF k i) j \ N" if "j \ k" for i j using DF_N [of k i] card_DF finite_enumerate_in_set finite_DF that by (metis inf.boundedE le_imp_less_Suc subsetD) have Inf_DF_N: "\(DF k p) \ N" for k p using DF_N DF_ne Inf_nat_def1 by blast have RF_in_N: "(\j\n. card (RF j i)) \ N" if "n \ k" "i < m" for i n by (auto simp: DF_in_N that) have "ka - Suc 0 \ k" using kka(2) by linarith then have sum_card_RF' [simp]: "(\j0 < ka\ lessThan_Suc_atMost that) have enum_DF_le_iff [simp]: "enum (DF k i) j \ enum (DF k i') j \ i \ i'" (is "?lhs = _") if "j \ k" for i' i j k proof show "i \ i'" if ?lhs proof - have "enum (DF k i) j \ DF k i" by (simp add: card_DF finite_enumerate_in_set finite_DF le_imp_less_Suc \j \ k\) moreover have "enum (DF k i') j \ DF k i'" by (simp add: \j \ k\ card_DF finite_enumerate_in_set finite_DF le_imp_less_Suc that) ultimately have "enum (DF k i') j < enum (DF k i) j" if "i' < i" using sm_DF [of k] by (meson UNIV_I less_sets_def strict_mono_setsD that) then show ?thesis using not_less that by blast qed show ?lhs if "i \ i'" using sm_DF [of k] that \j \ k\ card_DF finite_enumerate_in_set finite_DF le_eq_less_or_eq by (force simp: strict_mono_sets_def less_sets_def finite_enumerate_in_set) qed then have enum_DF_eq_iff[simp]: "enum (DF k i) j = enum (DF k i') j \ i = i'" if "j \ k" for i' i j k by (metis le_antisym order_refl that) have enum_DF_less_iff [simp]: "enum (DF k i) j < enum (DF k i') j \ i < i'" if "j \ k" for i' i j k by (meson enum_DF_le_iff not_less that) have card_AF_sum: "card (AF k i) + (\j\{0<..k > 0\ \k \ ka\ \ka \ Suc k\ by (simp add: lessThan_k RF_0 flip: sum_card_RF') have sorted_list_of_set_iff [simp]: "list_of {0<.. k = Suc 0" if "k>0" for k::nat proof - have "list_of {0<.. {0<.. \ k = Suc 0" using \k > 0\ atLeastSucLessThan_greaterThanLessThan by fastforce finally show ?thesis . qed show thesis \\proof of main result\ proof have inj: "inj_on (\i. list_of (\jjjjj RF 0 x" using AF_ne QF_0 \0 < k\ Inf_nat_def1 \k \ ka\ by (force simp: RF_def) with eq \ka > 0\ obtain j' where "j' < ka" "n \ RF j' y" by blast then show ?thesis using disjoint_QF [of k 0 x j'] n \x < m\ \y < m\ \ka \ Suc k\ \0 < k\ by (force simp: RF_def disjnt_iff simp del: QF_0 split: if_split_asm) qed qed define M where "M \ (\i. list_of (\jk \ ka\ card_image inj) moreover have "M \ WW" by (force simp: M_def WW_def) ultimately show "M \ [WW]\<^bsup>m\<^esup>" by (simp add: nsets_def) have sm_RF: "strict_mono_sets {..j. RF j i)" if "i []" if "j < Suc k" for i j using that by (simp add: RF_def) - have less_RF_same: "less_sets (RF j i') (RF j i)" + have less_RF_same: "RF j i' \ RF j i" if "i' < i" "j < k" for i' i j using that by (simp add: less_QF_same RF_def) - have less_RF_same_k: "less_sets (RF k i') (RF k i)" \\reversed version for @{term k}\ + have less_RF_same_k: "RF k i' \ RF k i" \\reversed version for @{term k}\ if "i < i'" "i' < m" for i' i using that by (simp add: less_QF_same RF_def) show "Form l U \ list.set (inter_scheme l U) \ N" if "U \ [M]\<^bsup>2\<^esup>" for U proof - from that obtain x y where "U = {x,y}" "x \ M" "y \ M" and xy: "(x,y) \ lenlex less_than" by (auto simp: lenlex_nsets_2_eq) let ?R = "\p. list_of \ (\j. RF j p)" obtain p q where x: "x = list_of (\jjx \ M\ \y \ M\ by (auto simp: M_def) then have pq: "pk \ ka\ \ka \ Suc k\ lexl_not_refl [OF irrefl_less_than] by (auto simp: lenlex_def sm_RF sorted_list_of_set_UN_lessThan length_concat sum_sorted_list_of_set_map) moreover have xc: "x = concat (map (?R p) (list_of {..k \ ka\ \ka \ Suc k\ \p < m\ sm_RF) have yc: "y = concat (map (?R q) (list_of {..k \ ka\ \ka \ Suc k\ \q < m\ sm_RF) have enum_DF_AF: "enum (DF k p) (ka - Suc 0) < hd (list_of (AF k p))" for p proof (rule less_setsD [OF DF_AF]) show "enum (DF k p) (ka - Suc 0) \ DF k p" using \ka \ Suc k\ card_DF finite_DF by (auto simp: finite_enumerate_in_set) show "hd (list_of (AF k p)) \ AF k p" using AF_non_Nil finite_AF hd_in_set set_sorted_list_of_set by blast qed - have less_RF_RF: "less_sets (RF n p) (RF n q)" if "n < k" for n + have less_RF_RF: "RF n p \ RF n q" if "n < k" for n using that \p by (simp add: less_RF_same) - have less_RF_Suc: "less_sets (RF n q) (RF (Suc n) q)" if "n < k" for n + have less_RF_Suc: "RF n q \ RF (Suc n) q" if "n < k" for n using \q < m\ that by (auto simp: RF_def less_QF) - have less_RF_k: "less_sets (RF k q) (RF k p)" + have less_RF_k: "RF k q \ RF k p" using \q < m\ less_RF_same_k \p by blast - have less_RF_k_ka: "less_sets (RF (k - Suc 0) p) (RF (ka - Suc 0) q)" + have less_RF_k_ka: "RF (k - Suc 0) p \ RF (ka - Suc 0) q" using ka_k_or_Suc less_RF_RF by (metis One_nat_def RF_def \0 < k\ \ka - Suc 0 \ k\ \p < m\ diff_Suc_1 diff_Suc_less less_QF_step) have Inf_DF_eq_enum: "\ (DF k i) = enum (DF k i) 0" for k i by (simp add: Inf_nat_def enumerate_0) have Inf_DF_less: "\ (DF k i') < \ (DF k i)" if "i'x. x \ AF k i \ \ (DF k i') < x" if "i'\i" for i' i using less_setsD [OF DF_AF] DF_ne that by (metis Inf_DF_less Inf_nat_def1 dual_order.order_iff_strict dual_order.strict_trans) show ?thesis proof (cases "k=1") case True with kka consider "ka=1" | "ka=2" by linarith then show ?thesis proof cases case 1 define zs where "zs = card (AF 1 p) # list_of (AF 1 p) @ card (AF 1 q) # list_of (AF 1 q)" have zs: "Form_Body ka k x y zs" proof (intro that exI conjI Form_Body.intros [OF \length x < length y\]) show "x = concat ([list_of (AF k p)])" "y = concat ([list_of (AF k q)])" by (simp_all add: x y 1 lessThan_Suc RF_0) - have "less_sets (AF k p) (insert (\ (DF k q)) (AF k q))" + have "AF k p \ insert (\ (DF k q)) (AF k q)" by (metis AF_DF DF_ne Inf_nat_def1 RF_0 \0 < k\ insert_iff less_RF_RF less_sets_def pq(1)) then have "strict_sorted (list_of (AF k p) @ \ (DF k q) # list_of (AF k q))" by (auto simp: strict_sorted_append_iff intro: less_sets_imp_list_less AF_Inf_DF_less) moreover have "\x. x \ AF k q \ \ (DF k p) < x" by (meson AF_Inf_DF_less less_imp_le_nat \p < q\) ultimately show "strict_sorted zs" using \p < q\ True Inf_DF_less DF_AF DF_ne apply (auto simp: zs_def less_sets_def card_AF AF_Inf_DF_less) by (meson Inf_nat_def1) qed (auto simp: \k=1\ \ka=1\ acc_lengths.simps zs_def AF_ne) have zs_N: "list.set zs \ N" using AF_subset_N by (auto simp: zs_def card_AF Inf_DF_N \k=1\) show ?thesis proof have "l = 1" using kka \k=1\ \ka=1\ by auto have "Form (2*1-1) {x,y}" using "1" Form.intros(2) True zs by fastforce then show "Form l U" by (simp add: \U = {x,y}\ \l = 1\) show "list.set (inter_scheme l U) \ N" using kka zs zs_N \k=1\ Form_Body_imp_inter_scheme by (fastforce simp add: \U = {x,y}\) qed next case 2 note True [simp] note 2 [simp] have [simp]: "{0<..<2} = {Suc 0}" by auto have enum_DF1_eq: "enum (DF (Suc 0) i) (Suc 0) = card (AF (Suc 0) i) + card (RF (Suc 0) i)" if "i < m" for i using card_AF_sum that by simp have card_RF: "card (RF (Suc 0) i) = enum (DF (Suc 0) i) (Suc 0) - enum (DF (Suc 0) i) 0" if "i < m" for i using that by (auto simp: RF_def card_QF del_def) have list_of_AF_RF: "list_of (AF (Suc 0) q \ RF (Suc 0) q) = list_of (AF (Suc 0) q) @ list_of (RF (Suc 0) q)" using RF_def \q < m\ less_QF_step by (fastforce intro!: sorted_list_of_set_Un) define zs where "zs = card (AF 1 p) # (card (AF 1 p) + card (RF 1 p)) # list_of (AF 1 p) @ (card (AF 1 q) + card (RF 1 q)) # list_of (AF 1 q) @ list_of (RF 1 q) @ list_of (RF 1 p)" have zs: "Form_Body ka k x y zs" proof (intro that exI conjI Form_Body.intros [OF \length x < length y\]) have "x = list_of (RF 0 p \ RF (Suc 0) p)" by (simp add: x eval_nat_numeral lessThan_Suc RF_0 Un_commute) also have "\ = list_of (RF 0 p) @ list_of (RF (Suc 0) p)" using RF_def True \p < m\ less_QF_step by (subst sorted_list_of_set_Un) (fastforce+) finally show "x = concat ([list_of (AF 1 p),list_of (RF 1 p)])" by (simp add: RF_0) show "y = concat [list_of (RF 1 q \ AF 1 q)]" by (simp add: y eval_nat_numeral lessThan_Suc RF_0) show "zs = concat [[card (AF 1 p), card (AF 1 p) + card (RF 1 p)], list_of (AF 1 p), [card (AF 1 q) + card (RF 1 q)], list_of (RF 1 q \ AF 1 q)] @ interact [list_of (RF 1 p)] []" using list_of_AF_RF by (simp add: zs_def Un_commute) show "strict_sorted zs" proof (simp add: \p \q \p zs_def strict_sorted_append_iff, intro conjI strip) show "0 < card (RF (Suc 0) p)" using \p by (simp add: card_RF card_DF finite_DF) show "card (AF (Suc 0) p) < card (AF (Suc 0) q) + card (RF (Suc 0) q)" using \p \q by (simp add: Inf_DF_less card_AF trans_less_add1) show "card (AF (Suc 0) p) < x" if "x \ AF (Suc 0) p \ (AF (Suc 0) q \ (RF (Suc 0) q \ RF (Suc 0) p))" for x using that apply (simp add: card_AF) by (metis AF_ne DF_AF DF_ne less_RF_RF less_RF_Suc less_RF_k Inf_nat_def1 One_nat_def RF_0 RF_non_Nil True finite_RF lessI less_setsD less_sets_trans sorted_list_of_set_eq_Nil_iff) show "card (AF (Suc 0) p) + card (RF (Suc 0) p) < card (AF (Suc 0) q) + card (RF (Suc 0) q)" using \p < q\ \p < m\ \q < m\ by (metis enum_DF1_eq enum_DF_less_iff le_refl) show "card (AF (Suc 0) p) + card (RF (Suc 0) p) < x" if "x \ AF (Suc 0) p \ (AF (Suc 0) q \ (RF (Suc 0) q \ RF (Suc 0) p))" for x using that \p < m\ apply (simp add: flip: enum_DF1_eq) by (metis AF_ne DF_AF less_RF_RF less_RF_Suc less_RF_k One_nat_def RF_0 RF_non_Nil Suc_mono True \0 < k\ card_DF finite_enumerate_in_set finite_DF less_setsD less_sets_trans sorted_list_of_set_empty) have "list_of (AF (Suc 0) p) < list_of {enum (DF (Suc 0) q) (Suc 0)}" proof (rule less_sets_imp_sorted_list_of_set) - show "less_sets (AF (Suc 0) p) {enum (DF (Suc 0) q) (Suc 0)}" + show "AF (Suc 0) p \ {enum (DF (Suc 0) q) (Suc 0)}" by (metis (no_types, lifting) AF_DF DF_ne Inf_nat_def1 \q < m\ card_AF enum_DF1_eq less_setsD less_sets_singleton2 pq(1) trans_less_add1) qed auto then show "list_of (AF (Suc 0) p) < (card (AF (Suc 0) q) + card (RF (Suc 0) q)) # list_of (AF (Suc 0) q) @ list_of (RF (Suc 0) q) @ list_of (RF (Suc 0) p)" using \q < m\ by (simp add: less_list_def enum_DF1_eq) show "card (AF (Suc 0) q) + card (RF (Suc 0) q) < x" if "x \ AF (Suc 0) q \ (RF (Suc 0) q \ RF (Suc 0) p)" for x using that \q < m\ apply (simp flip: enum_DF1_eq) by (metis AF_ne DF_AF less_RF_Suc less_RF_k One_nat_def RF_0 RF_non_Nil True card_DF finite_enumerate_in_set finite_DF finite_RF lessI less_setsD less_sets_trans sorted_list_of_set_eq_Nil_iff) have "list_of (AF (Suc 0) q) < list_of (RF (Suc 0) q)" proof (rule less_sets_imp_sorted_list_of_set) - show "less_sets (AF (Suc 0) q) (RF (Suc 0) q)" + show "AF (Suc 0) q \ RF (Suc 0) q" by (metis less_RF_Suc One_nat_def RF_0 True \0 < k\) qed auto then show "list_of (AF (Suc 0) q) < list_of (RF (Suc 0) q) @ list_of (RF (Suc 0) p)" using RF_non_Nil by (auto simp: less_list_def) show "list_of (RF (Suc 0) q) < list_of (RF (Suc 0) p)" proof (rule less_sets_imp_sorted_list_of_set) - show "less_sets (RF (Suc 0) q) (RF (Suc 0) p)" + show "RF (Suc 0) q \ RF (Suc 0) p" by (metis less_RF_k One_nat_def True) qed auto qed show "[list_of (AF 1 p), list_of (RF 1 p)] \ lists (- {[]})" using RF_non_Nil \0 < k\ by (auto simp: acc_lengths.simps zs_def AF_ne) show "[card (AF 1 q) + card (RF 1 q)] = acc_lengths 0 [list_of (RF 1 q \ AF 1 q)]" using list_of_AF_RF by (auto simp: acc_lengths.simps zs_def AF_ne sup_commute) qed (auto simp: acc_lengths.simps zs_def AF_ne) have zs_N: "list.set zs \ N" using \p < m\ \q < m\ DF_in_N enum_DF1_eq [symmetric] by (auto simp: zs_def card_AF AF_subset_N RF_subset_N Inf_DF_N) show ?thesis proof have "Form (2*1) {x,y}" by (metis "2" Form.simps Suc_1 True zero_less_one zs) with kka show "Form l U" by (simp add: \U = {x,y}\) show "list.set (inter_scheme l U) \ N" using kka zs zs_N \k=1\ Form_Body_imp_inter_scheme by (fastforce simp add: \U = {x, y}\) qed qed next case False then have "k \ 2" "ka \ 2" using kka \k>0\ by auto then have k_minus_1 [simp]: "Suc (k - Suc (Suc 0)) = k - Suc 0" by auto define PP where "PP \ map (?R p) (list_of {0<.. map (?R q) (list_of {0<.. RF (ka-1) q)])" let ?INT = "interact PP QQ" \\No separate sets A and B as in the text, but instead we treat both cases as once\ have [simp]: "length PP = ka - 1" by (simp add: PP_def) have [simp]: "length QQ = k - 1" using \k \ 2\ by (simp add: QQ_def) have PP_n: "PP ! n = list_of (RF (Suc n) p)" if "n < ka-1" for n using that kka by (auto simp: PP_def nth_sorted_list_of_set_greaterThanLessThan) have QQ_n: "QQ ! n = (if n < k - Suc (Suc 0) then list_of (RF (Suc n) q) else list_of (RF (k - Suc 0) q \ RF (ka - Suc 0) q))" if "n < k-1" for n using that kka by (auto simp: QQ_def nth_append nth_sorted_list_of_set_greaterThanLessThan) have QQ_n_same: "QQ ! n = list_of (RF (Suc n) q)" if "n < k - Suc 0" "k=ka" for n using that kka Suc_diff_Suc by (fastforce simp add: QQ_def nth_append nth_sorted_list_of_set_greaterThanLessThan) have split_nat_interval: "{0<.. 2" for n using that by auto have split_list_interval: "list_of{0<.. 2" for n proof (intro sorted_list_of_set_unique [THEN iffD1] conjI) have "list_of {0<..n \ 2\ in auto) have list_of_RF_Un: "list_of (RF (k - Suc 0) q \ RF k q) = list_of (RF (k - Suc 0) q) @ list_of (RF k q)" by (metis less_RF_Suc Suc_pred \0 < k\ diff_Suc_less finite_RF sorted_list_of_set_Un) have card_AF_sum_QQ: "card (AF k q) + sum_list (map length QQ) = (\j RF k q = {}" using less_RF_Suc [of "k - Suc 0"] \k > 0\ by (auto simp: less_sets_def) then have "card (RF (k - Suc 0) q \ RF k q) = card (RF (k - Suc 0) q) + card (RF k q)" by (simp add: card_Un_disjoint) then show ?thesis using \k\2\ \q < m\ apply (simp add: QQ_def True flip: RF_0) apply (simp add: lessThan_k split_nat_interval sum_sorted_list_of_set_map) done next case False with kka have "ka=k" by linarith with \k\2\ show ?thesis by (simp add: QQ_def lessThan_k split_nat_interval sum_sorted_list_of_set_map flip: RF_0) qed define LENS where "LENS \ \i. acc_lengths 0 (list_of (AF k i) # map (?R i) (list_of {0<.. N" if "i < m" for i proof - have eq: "(list_of (AF k i) # map (?R i) (list_of {0<..0 < ka\ sorted_list_of_set_k by auto let ?f = "rec_nat [card (AF k i)] (\n r. r @ [(\j\Suc n. card (RF j i))])" have f: "acc_lengths 0 (map (?R i) (list_of {..v})) = ?f v" for v by (induction v) (auto simp: RF_0 acc_lengths.simps acc_lengths_append sum_sorted_list_of_set_map) have 3: "list.set (?f v) \ N" if "v \ k" for v using that proof (induction v) case 0 have "card (AF k i) \ N" by (metis DF_N DF_ne Inf_nat_def1 Int_subset_iff card_AF subsetD) with 0 show ?case by simp next case (Suc v) then have "enum (DF k i) (Suc v) \ N" by (metis DF_N Int_subset_iff card_DF finite_enumerate_in_set finite_DF in_mono le_imp_less_Suc) with Suc \i < m\ show ?case by (simp del: sum.atMost_Suc) qed show ?thesis unfolding LENS_def by (metis "3" Suc_pred \0 < ka\ \ka - Suc 0 \ k\ eq f lessThan_Suc_atMost) qed define LENS_QQ where "LENS_QQ \ acc_lengths 0 (list_of (AF k q) # QQ)" have LENS_QQ_subset: "list.set LENS_QQ \ list.set (LENS q)" proof (cases "ka = Suc k") case True with \k \ 2\ show ?thesis unfolding QQ_def LENS_QQ_def LENS_def by (auto simp: list_of_RF_Un split_list_interval acc_lengths.simps acc_lengths_append) next case False then have "ka=k" using kka by linarith with \k \ 2\ show ?thesis by (simp add: QQ_def LENS_QQ_def LENS_def split_list_interval) qed have ss_INT: "strict_sorted ?INT" proof (rule strict_sorted_interact_I) fix n assume "n < length QQ" then have n: "n < k-1" by simp have "n = k - Suc (Suc 0)" if "\ n < k - Suc (Suc 0)" using n that by linarith with \p n show "PP ! n < QQ ! n" using \0 < k\ \k \ ka\ \ka \ Suc k\ \p n by (auto simp: PP_n QQ_n less_RF_same less_sets_imp_sorted_list_of_set less_sets_Un2 less_RF_RF less_RF_k_ka) next fix n have V: "\Suc n < ka - Suc 0\ \ list_of (RF (Suc n) q) < list_of (RF (Suc (Suc n)) p)" for n by (smt One_nat_def RF_def Suc_leI \ka - Suc 0 \ k\ \q < m\ diff_Suc_1 finite_RF less_QF_step less_le_trans less_sets_imp_sorted_list_of_set nat_neq_iff zero_less_Suc) - have "less_sets (RF (k - Suc 0) q) (RF k p)" + have "RF (k - Suc 0) q \ RF k p" by (metis less_RF_Suc less_RF_k RF_non_Nil Suc_pred \0 < k\ finite_RF lessI less_sets_trans sorted_list_of_set_eq_Nil_iff) - with kka have "less_sets (RF (k - Suc 0) q \ RF (ka - Suc 0) q) (RF k p)" + with kka have "RF (k - Suc 0) q \ RF (ka - Suc 0) q \ RF k p" by (metis less_RF_k One_nat_def less_sets_Un1 antisym_conv2 diff_Suc_1 le_less_Suc_eq) then have VI: "list_of (RF (k - Suc 0) q \ RF (ka - Suc 0) q) < list_of (RF k p)" by (rule less_sets_imp_sorted_list_of_set) auto assume "Suc n < length PP" with \ka \ Suc k\ VI show "QQ ! n < PP ! Suc n" apply (auto simp: PP_n QQ_n less_RF_same less_sets_imp_sorted_list_of_set less_sets_Un1 less_sets_Un2 less_RF_RF less_RF_k_ka V) by (metis One_nat_def Suc_less_eq Suc_pred \0 < k\ diff_Suc_1 k_minus_1 ka_k_or_Suc less_SucE) next show "PP \ lists (- {[]})" using RF_non_Nil kka by (clarsimp simp: PP_def) (metis RF_non_Nil less_le_trans) show "QQ \ lists (- {[]})" using RF_non_Nil kka by (clarsimp simp: QQ_def) (metis RF_non_Nil Suc_pred \0 < k\ less_SucI) qed (use kka PP_def QQ_def in auto) then have ss_QQ: "strict_sorted (concat QQ)" using strict_sorted_interact_imp_concat by blast obtain zs where zs: "Form_Body ka k x y zs" and zs_N: "list.set zs \ N" proof (intro that exI conjI Form_Body.intros [OF \length x < length y\]) show "x = concat (list_of (AF k p) # PP)" using \ka > 0\ by (simp add: PP_def RF_0 xc sorted_list_of_set_k) let ?YR = "(map (list_of \ (\j. RF j q)) (list_of {0<..ka - Suc 0 \ k\ add.left_neutral finite_RF less_le_trans less_sets_imp_sorted_list_of_set nth_sorted_list_of_set_greaterThanLessThan) next show "?YR \ lists (- {[]})" using RF_non_Nil \ka \ Suc k\ by (auto simp: mem_lists_non_Nil) qed auto show "list.set (concat ?YR) = list.set (concat QQ)" using ka_k_or_Suc proof assume "ka = k" then show "list.set (concat (map (list_of \ (\j. RF j q)) (list_of {0<..k\2\ by simp (simp add: split_nat_interval QQ_def) next assume "ka = Suc k" then show "list.set (concat (map (list_of \ (\j. RF j q)) (list_of {0<..k\2\ by simp (auto simp: QQ_def split_nat_interval) qed qed then show "y = concat (list_of (AF k q) # QQ)" using \ka > 0\ by (simp add: RF_0 yc sorted_list_of_set_k) show "list_of (AF k p) # PP \ lists (- {[]})" "list_of (AF k q) # QQ \ lists (- {[]})" using RF_non_Nil kka by (auto simp: AF_ne PP_def QQ_def eq_commute [of "[]"]) show "list.set ((LENS p @ list_of (AF k p) @ LENS_QQ @ list_of (AF k q) @ ?INT)) \ N" using AF_subset_N RF_subset_N LENS_subset_N \p < m\ \q < m\ LENS_QQ_subset by (auto simp: subset_iff PP_def QQ_def) show "length (list_of (AF k p) # PP) = ka" "length (list_of (AF k q) # QQ) = k" using \0 < ka\ \0 < k\ by auto show "LENS p = acc_lengths 0 (list_of (AF k p) # PP)" by (auto simp: LENS_def PP_def) show "strict_sorted (LENS p @ list_of (AF k p) @ LENS_QQ @ list_of (AF k q) @ ?INT)" unfolding strict_sorted_append_iff proof (intro conjI ss_INT) show "LENS p < list_of (AF k p) @ LENS_QQ @ list_of (AF k q) @ ?INT" using AF_non_Nil [of k p] \k \ ka\ \ka \ Suc k\ \p < m\ card_AF_sum enum_DF_AF by (simp add: enum_DF_AF less_list_def card_AF_sum LENS_def sum_sorted_list_of_set_map) show "strict_sorted (LENS p)" unfolding LENS_def by (rule strict_sorted_acc_lengths) (use RF_non_Nil AF_non_Nil kka in \auto simp: in_lists_conv_set\) show "strict_sorted LENS_QQ" unfolding LENS_QQ_def QQ_def by (rule strict_sorted_acc_lengths) (use RF_non_Nil AF_non_Nil kka in \auto simp: in_lists_conv_set\) have last_AF_DF: "last (list_of (AF k p)) < \ (DF k q)" using AF_DF [OF \p < q\, of k] AF_non_Nil [of k p] DF_ne [of k q] by (metis Inf_nat_def1 finite_AF last_in_set less_sets_def set_sorted_list_of_set) then show "list_of (AF k p) < LENS_QQ @ list_of (AF k q) @ ?INT" by (simp add: less_list_def card_AF LENS_QQ_def) show "LENS_QQ < list_of (AF k q) @ ?INT" using AF_non_Nil [of k q] \q < m\ card_AF_sum enum_DF_AF card_AF_sum_QQ by (auto simp: less_list_def AF_ne hd_append card_AF_sum LENS_QQ_def) show "list_of (AF k q) < ?INT" proof - - have "less_sets (AF k q) (RF (Suc 0) p)" + have "AF k q \ RF (Suc 0) p" using \0 < k\ \p < m\ \q < m\ by (simp add: RF_def less_QF flip: QF_0) then have "last (list_of (AF k q)) < hd (list_of (RF (Suc 0) p))" proof (rule less_setsD) show "last (list_of (AF k q)) \ AF k q" using AF_non_Nil finite_AF last_in_set set_sorted_list_of_set by blast show "hd (list_of (RF (Suc 0) p)) \ RF (Suc 0) p" by (metis RF_non_Nil Suc_mono \0 < k\ finite_RF hd_in_set set_sorted_list_of_set) qed with \k > 0\ \ka \ 2\ RF_non_Nil show ?thesis by (simp add: hd_interact less_list_def sorted_list_of_set_greaterThanLessThan PP_def QQ_def) qed qed auto qed (auto simp: LENS_QQ_def) show ?thesis proof (cases "ka = k") case True then have "l = 2*k - 1" by (simp add: kka(3) mult_2) then show ?thesis by (metis Form.intros(2) Form_Body_imp_inter_scheme True \0 < k\ \U = {x, y}\ kka zs zs_N) next case False then have "l = 2*k" using kka by linarith then show ?thesis by (metis False Form.intros(3) Form_Body_imp_inter_scheme \0 < k\ \U = {x, y}\ antisym kka le_SucE zs zs_N) qed qed qed qed qed subsection \Larson's Lemma 3.8\ subsubsection \Primitives needed for the inductive construction of @{term b}\ definition IJ where "IJ \ \k. Sigma {..k} (\j::nat. {.. IJ k \ (\j i. u = (j,i) \ i j\k)" by (auto simp: IJ_def) lemma finite_IJ: "finite (IJ k)" by (auto simp: IJ_def) fun prev where "prev 0 0 = None" | "prev (Suc 0) 0 = None" | "prev (Suc j) 0 = Some (j, j - Suc 0)" | "prev j (Suc i) = Some (j,i)" lemma prev_eq_None_iff: "prev j i = None \ j \ Suc 0 \ i = 0" by (auto simp: le_Suc_eq elim: prev.elims) lemma prev_pair_less: "prev j i = Some ji' \ (ji', (j,i)) \ pair_less" by (auto simp: pair_lessI1 elim: prev.elims) lemma prev_Some_less: "\prev j i = Some (j',i'); i \ j\ \ i' < j'" by (auto elim: prev.elims) lemma prev_maximal: "\prev j i = Some (j',i'); (ji'', (j,i)) \ pair_less; ji'' \ IJ k\ \ (ji'', (j',i')) \ pair_less \ ji'' = (j',i')" by (force simp: IJ_def pair_less_def elim: prev.elims) lemma pair_less_prev: assumes "(u, (j,i)) \ pair_less" "u \ IJ k" shows "prev j i = Some u \ (\x. (u, x) \ pair_less \ prev j i = Some x)" proof (cases "prev j i") case None show ?thesis proof (cases u) case (Pair j' i') then show ?thesis using assms None by (simp add: prev_eq_None_iff pair_less_def IJ_def) qed next case (Some a) then show ?thesis by (metis assms prev_maximal prod.exhaust_sel) qed subsubsection \Special primitives for the ordertype proof\ definition USigma :: "'a set set \ ('a set \ 'a set) \ 'a set set" where "USigma \ B \ \X\\. \y\B X. {insert y X}" definition usplit where "usplit f A \ f (A - {Max A}) (Max A)" lemma USigma_empty [simp]: "USigma {} B = {}" by (auto simp: USigma_def) lemma USigma_iff: - assumes "\I j. I \ \ \ less_sets I (J I) \ finite I" + assumes "\I j. I \ \ \ I \ J I \ finite I" shows "x \ USigma \ J \ usplit (\I j. I\\ \ j\J I \ x = insert j I) x" proof - have [simp]: "\I j. \I \ \; j \ J I\ \ Max (insert j I) = j" by (meson Max_insert2 assms less_imp_le less_sets_def) show ?thesis proof - have "I - {j} \ \" if "I \ \" "j \ J I" for I j using that by (metis Diff_empty Diff_insert0 assms less_irrefl less_sets_def) moreover have "j \ J (I - {j})" if "I \ \" "j \ J I" for I j using that by (metis Diff_empty Diff_insert0 assms less_irrefl less_setsD) moreover have "\I\\. \j\J I. x = insert j I" if "x - {Max x} \ \" and "Max x \ J (x - {Max x})" "x \ {}" using that by (metis Max_in assms infinite_remove insert_Diff) ultimately show ?thesis by (auto simp: USigma_def usplit_def) qed qed lemma ordertype_append_image_IJ: assumes lenB [simp]: "\i j. i \ \ \ j \ J i \ length (B j) = c" and AB: "\i j. i \ \ \ j \ J i \ A i < B j" - and IJ: "\i. i \ \ \ less_sets i (J i) \ finite i" + and IJ: "\i. i \ \ \ i \ J i \ finite i" and \: "\i. i \ \ \ ordertype (B ` J i) (lenlex less_than) = \" and A: "inj_on A \" shows "ordertype (usplit (\i j. A i @ B j) ` USigma \ J) (lenlex less_than) = \ * ordertype (A ` \) (lenlex less_than)" (is "ordertype ?AB ?R = _ * ?\") proof (cases "\ = {}") next case False have "Ord \" using \ False wf_Ord_ordertype by fastforce show ?thesis proof (subst ordertype_eq_iff) define split where "split \ \l::nat list. (take (length l - c) l, (drop (length l - c) l))" have oB: "ordermap (B ` J i) ?R (B j) \ \" if \i \ \\ \j \ J i\ for i j using \ less_TC_iff that by fastforce then show "Ord (\ * ?\)" by (intro \Ord \\ wf_Ord_ordertype Ord_mult; simp) define f where "f \ \u. let (x,y) = split u in let i = inv_into \ A x in \ * ordermap (A`\) ?R x + ordermap (B`J i) ?R y" have inv_into_IA [simp]: "inv_into \ A (A i) = i" if "i \ \" for i by (simp add: A that) show "\f. bij_betw f ?AB (elts (\ * ?\)) \ (\x\?AB. \y\?AB. (f x < f y) = ((x, y) \ ?R))" unfolding bij_betw_def proof (intro exI conjI strip) show "inj_on f ?AB" proof (clarsimp simp: f_def inj_on_def split_def USigma_iff IJ usplit_def) fix x y assume \
: "\ * ordermap (A ` \) ?R (A (x - {Max x})) + ordermap (B ` J (x - {Max x})) ?R (B (Max x)) = \ * ordermap (A ` \) ?R (A (y - {Max y})) + ordermap (B ` J (y - {Max y})) ?R (B (Max y))" and x: "x - {Max x} \ \" and y: "y - {Max y} \ \" and mx: "Max x \ J (x - {Max x})" and "x = insert (Max x) x" and my: "Max y \ J (y - {Max y})" have "ordermap (A`\) ?R (A (x - {Max x})) = ordermap (A`\) ?R (A (y - {Max y}))" and B_eq: "ordermap (B ` J (x - {Max x})) ?R (B (Max x)) = ordermap (B ` J (y - {Max y})) ?R (B (Max y))" using mult_cancellation_lemma [OF \
] oB mx my x y by blast+ then have "A (x - {Max x}) = A (y - {Max y})" using x y by auto then have "x - {Max x} = y - {Max y}" by (metis x y inv_into_IA) then show "A (x - {Max x}) = A (y - {Max y}) \ B (Max x) = B (Max y)" using B_eq mx my by auto qed show "f ` ?AB = elts (\ * ?\)" proof show "f ` ?AB \ elts (\ * ?\)" using \Ord \\ apply (clarsimp simp add: f_def split_def USigma_iff IJ usplit_def) by (metis Ord_mem_iff_less_TC TC_small add_mult_less image_eqI oB ordermap_in_ordertype trans_llt wf_Ord_ordertype wf_llt) show "elts (\ * ?\) \ f ` ?AB" proof (clarsimp simp: f_def split_def image_iff USigma_iff IJ usplit_def Bex_def elim!: elts_multE split: prod.split) fix \ \ assume \: "\ \ elts \" and \: "\ \ elts ?\" have "\ \ ordermap (A ` \) (lenlex less_than) ` A ` \" by (meson \ ordermap_surj subset_iff) then obtain i where "i \ \" and yv: "\ = ordermap (A`\) ?R (A i)" by blast have "\ \ ordermap (B ` J i) (lenlex less_than) ` B ` J i" by (metis (no_types) \ \ \i \ \\ in_mono ordermap_surj) then obtain j where "j \ J i" and xu: "\ = ordermap (B`J i) ?R (B j)" by blast then have mji: "Max (insert j i) = j" by (meson IJ Max_insert2 \i \ \\ less_imp_le less_sets_def) have [simp]: "i - {j} = i" using IJ \i \ \\ \j \ J i\ less_setsD by fastforce show "\l. (\K. K - {Max K} \ \ \ Max K \ J (K - {Max K}) \ K = insert (Max K) K \ l = A (K - {Max K}) @ B (Max K)) \ \ * \ + \ = \ * ordermap (A ` \) ?R (take (length l - c) l) + ordermap (B ` J (inv_into \ A (take (length l - c) l))) ?R (drop (length l - c) l)" proof (intro conjI exI) let ?ji = "insert j i" show "A i @ B j = A (?ji - {Max ?ji}) @ B (Max ?ji)" by (auto simp: mji) qed (use \i \ \\ \j \ J i\ mji xu yv in auto) qed qed next fix p q assume "p \ ?AB" and "q \ ?AB" then obtain x y where peq: "p = A (x - {Max x}) @ B (Max x)" and qeq: "q = A (y - {Max y}) @ B (Max y)" and x: "x - {Max x} \ \" and y: "y - {Max y} \ \" and mx: "Max x \ J (x - {Max x})" and my: "Max y \ J (y - {Max y})" by (auto simp: USigma_iff IJ usplit_def) let ?mx = "x - {Max x}" let ?my = "y - {Max y}" show "(f p < f q) \ ((p, q) \ ?R)" proof assume "f p < f q" then consider "ordermap (A`\) ?R (A (x - {Max x})) < ordermap (A`\) ?R (A (y - {Max y}))" | "ordermap (A`\) ?R (A (x - {Max x})) = ordermap (A`\) ?R (A (y - {Max y}))" "ordermap (B`J (x - {Max x})) ?R (B (Max x)) < ordermap (B`J (y - {Max y})) ?R (B (Max y))" using x y mx my by (auto dest: mult_cancellation_less simp: f_def split_def peq qeq oB) then have "(A ?mx @ B (Max x), A ?my @ B (Max y)) \ ?R" proof cases case 1 then have "(A ?mx, A ?my) \ ?R" using x y by (force simp: Ord_mem_iff_lt intro: converse_ordermap_mono) then show ?thesis using x y mx my lenB lenlex_append1 by blast next case 2 then have "A ?mx = A ?my" using \?my \ \\ \?mx \ \\ by auto then have eq: "?mx = ?my" by (metis \?my \ \\ \?mx \ \\ inv_into_IA) then have "(B (Max x), B (Max y)) \ ?R" using mx my 2 by (force simp: Ord_mem_iff_lt intro: converse_ordermap_mono) with 2 show ?thesis by (simp add: eq irrefl_less_than) qed then show "(p,q) \ ?R" by (simp add: peq qeq f_def split_def sorted_list_of_set_Un AB) next assume pqR: "(p,q) \ ?R" then have \
: "(A ?mx @ B (Max x), A ?my @ B (Max y)) \ ?R" using peq qeq by blast then consider "(A ?mx, A ?my) \ ?R" | "A ?mx = A ?my \ (B (Max x), B (Max y)) \ ?R" proof (cases "(A ?mx, A ?my) \ ?R") case False have False if "(A ?my, A ?mx) \ ?R" by (metis \?my \ \\ \?mx \ \\ "\
" \(Max y) \ J ?my\ \(Max x) \ J ?mx\ lenB lenlex_append1 omega_sum_1_less order.asym that) then have "A ?mx = A ?my" by (meson False UNIV_I total_llt total_on_def) then show ?thesis using "\
" irrefl_less_than that(2) by auto qed (use that in blast) then have "\ * ordermap (A`\) ?R (A ?mx) + ordermap (B`J ?mx) ?R (B (Max x)) < \ * ordermap (A`\) ?R (A ?my) + ordermap (B`J ?my) ?R (B (Max y))" proof cases case 1 show ?thesis proof (rule add_mult_less_add_mult) show "ordermap (A`\) (lenlex less_than) (A ?mx) < ordermap (A`\) (lenlex less_than) (A ?my)" by (simp add: "1" \?my \ \\ \?mx \ \\ ordermap_mono_less) show "Ord (ordertype (A`\) ?R)" using wf_Ord_ordertype by blast+ show "ordermap (B ` J ?mx) ?R (B (Max x)) \ elts \" using Ord_less_TC_mem \Ord \\ \?mx \ \\ \(Max x) \ J ?mx\ oB by blast show "ordermap (B ` J ?my) ?R (B (Max y)) \ elts \" using Ord_less_TC_mem \Ord \\ \?my \ \\ \(Max y) \ J ?my\ oB by blast qed (use \?my \ \\ \?mx \ \\ \Ord \\ in auto) next case 2 with \?mx \ \\ show ?thesis using \(Max y) \ J ?my\ \(Max x) \ J ?mx\ ordermap_mono_less by (metis (no_types, hide_lams) Kirby.add_less_cancel_left TC_small image_iff inv_into_IA trans_llt wf_llt y) qed then show "f p < f q" using \?my \ \\ \?mx \ \\ \(Max y) \ J ?my\ \(Max x) \ J ?mx\ by (auto simp: peq qeq f_def split_def AB) qed qed qed auto qed auto subsubsection \The final part of 3.8, where two sequences are merged\ inductive merge :: "[nat list list,nat list list,nat list list,nat list list] \ bool" where NullNull: "merge [] [] [] []" | Null: "as \ [] \ merge as [] [concat as] []" | App: "\as1 \ []; bs1 \ []; concat as1 < concat bs1; concat bs1 < concat as2; merge as2 bs2 as bs\ \ merge (as1@as2) (bs1@bs2) (concat as1 # as) (concat bs1 # bs)" inductive_simps Null1 [simp]: "merge [] bs us vs" inductive_simps Null2 [simp]: "merge as [] us vs" lemma merge_single: "\concat as < concat bs; concat as \ []; concat bs \ []\ \ merge as bs [concat as] [concat bs]" using merge.App [of as bs "[]" "[]"] by (fastforce simp add: less_list_def) lemma merge_length1_nonempty: assumes "merge as bs us vs" "as \ lists (- {[]})" shows "us \ lists (- {[]})" using assms by induction (auto simp: mem_lists_non_Nil) lemma merge_length2_nonempty: assumes "merge as bs us vs" "bs \ lists (- {[]})" shows "vs \ lists (- {[]})" using assms by induction (auto simp: mem_lists_non_Nil) lemma merge_length1_gt_0: assumes "merge as bs us vs" "as \ []" shows "length us > 0" using assms by induction auto lemma merge_length_le: assumes "merge as bs us vs" shows "length vs \ length us" using assms by induction auto lemma merge_length_le_Suc: assumes "merge as bs us vs" shows "length us \ Suc (length vs)" using assms by induction auto lemma merge_length_less2: assumes "merge as bs us vs" shows "length vs \ length as" using assms proof induction case (App as1 bs1 as2 bs2 as bs) then show ?case by simp (metis One_nat_def Suc_eq_plus1 Suc_leI add.commute add_mono length_greater_0_conv) qed auto lemma merge_preserves: assumes "merge as bs us vs" shows "concat as = concat us \ concat bs = concat vs" using assms by induction auto lemma merge_interact: assumes "merge as bs us vs" "strict_sorted (concat as)" "strict_sorted (concat bs)" "bs \ lists (- {[]})" shows "strict_sorted (interact us vs)" using assms proof induction case (App as1 bs1 as2 bs2 as bs) then have "concat bs1 < concat bs" "concat bs1 < concat as" and xx: "concat bs1 \ []" using merge_preserves strict_sorted_append_iff by fastforce+ then have "concat bs1 < interact as bs" using App apply (simp add: less_list_def del: concat_eq_Nil_conv) by (metis (full_types) Un_iff \concat bs1 < concat as\ \concat bs1 < concat bs\ last_in_set list.set_sel(1) set_interact sorted_wrt_append strict_sorted_append_iff strict_sorted_interact_imp_concat strict_sorted_sorted_wrt xx) with App show ?case apply (simp add: strict_sorted_append_iff del: concat_eq_Nil_conv) by (metis hd_append2 less_list_def xx) qed auto lemma acc_lengths_merge1: assumes "merge as bs us vs" shows "list.set (acc_lengths k us) \ list.set (acc_lengths k as)" using assms proof (induction arbitrary: k) case (App as1 bs1 as2 bs2 as bs) then show ?case apply (simp add: acc_lengths_append acc_lengths.simps strict_sorted_append_iff length_concat_acc_lengths) by (simp add: le_supI2 length_concat) qed (auto simp: acc_lengths.simps length_concat_acc_lengths) lemma acc_lengths_merge2: assumes "merge as bs us vs" shows "list.set (acc_lengths k vs) \ list.set (acc_lengths k bs)" using assms proof (induction arbitrary: k) case (App as1 bs1 as2 bs2 as bs) then show ?case apply (simp add: acc_lengths_append acc_lengths.simps strict_sorted_append_iff length_concat_acc_lengths) by (simp add: le_supI2 length_concat) qed (auto simp: acc_lengths.simps length_concat_acc_lengths) lemma length_hd_le_concat: assumes "as \ []" shows "length (hd as) \ length (concat as)" by (metis (no_types) add.commute assms concat.simps(2) le_add2 length_append list.exhaust_sel) lemma length_hd_merge2: assumes "merge as bs us vs" shows "length (hd bs) \ length (hd vs)" using assms by induction (auto simp: length_hd_le_concat) lemma merge_less_sets_hd: assumes "merge as bs us vs" "strict_sorted (concat as)" "strict_sorted (concat bs)" "bs \ lists (- {[]})" - shows "less_sets (list.set (hd us)) (list.set (concat vs))" + shows "list.set (hd us) \ list.set (concat vs)" using assms proof induction case (App as1 bs1 as2 bs2 as bs) - then have \
: "less_sets (list.set (concat bs1)) (list.set (concat bs2))" + then have \
: "list.set (concat bs1) \ list.set (concat bs2)" by (force simp: dest: strict_sorted_imp_less_sets)+ - have *: "less_sets (list.set (concat as1)) (list.set (concat bs1))" + have *: "list.set (concat as1) \ list.set (concat bs1)" using App by (metis concat_append strict_sorted_append_iff strict_sorted_imp_less_sets) - then have "less_sets (list.set (concat as1)) (list.set (concat bs))" + then have "list.set (concat as1) \ list.set (concat bs)" using App \
less_sets_trans merge_preserves by (metis List.set_empty append_in_lists_conv le_zero_eq length_concat_ge length_greater_0_conv list.size(3)) with * App.hyps show ?case by (fastforce simp add: less_sets_UN1 less_sets_UN2 less_sets_Un2) qed auto lemma set_takeWhile: assumes "strict_sorted (concat as)" "as \ lists (- {[]})" shows "list.set (takeWhile (\x. x < y) as) = {x \ list.set as. x < y}" using assms proof (induction as) case (Cons a as) have *: "a < y" if a: "a < concat as" "strict_sorted a" "strict_sorted (concat as)" "x < y" "x \ []" "x \ list.set as" for x proof - have "last x \ list.set (concat as)" using set_concat that(5) that(6) by fastforce then have "last a < hd (concat as)" using Cons.prems that by (auto simp: less_list_def) also have "\ \ hd y" if "y \ []" using that a by (meson \last x \ list.set (concat as)\ dual_order.strict_trans less_list_def not_le sorted_hd_le strict_sorted_imp_sorted) finally show ?thesis by (simp add: less_list_def) qed then show ?case using Cons by (auto simp: strict_sorted_append_iff) qed auto proposition merge_exists: assumes "strict_sorted (concat as)" "strict_sorted (concat bs)" "as \ lists (- {[]})" "bs \ lists (- {[]})" "hd as < hd bs" "as \ []" "bs \ []" and disj: "\a b. \a \ list.set as; b \ list.set bs\ \ a bus vs. merge as bs us vs" using assms proof (induction "length as + length bs" arbitrary: as bs rule: less_induct) case (less as bs) obtain as1 as2 bs1 bs2 where A: "as1 \ []" "bs1 \ []" "concat as1 < concat bs1" "concat bs1 < concat as2" and B: "as = as1@as2" "bs = bs1@bs2" and C: "bs2 = [] \ (as2 \ [] \ hd as2 < hd bs2)" proof define as1 where "as1 \ takeWhile (\x. x < hd bs) as" define as2 where "as2 \ dropWhile (\x. x < hd bs) as" define bs1 where "bs1 \ if as2=[] then bs else takeWhile (\x. x < hd as2) bs" define bs2 where "bs2 \ if as2=[] then [] else dropWhile (\x. x < hd as2) bs" have as1: "as1 = takeWhile (\x. last x < hd (hd bs)) as" using less.prems by (auto simp: as1_def less_list_def cong: takeWhile_cong) have as2: "as2 = dropWhile (\x. last x < hd (hd bs)) as" using less.prems by (auto simp: as2_def less_list_def cong: dropWhile_cong) have hd_as2: "as2 \ [] \ \ hd as2 < hd bs" using as2_def hd_dropWhile by metis have hd_bs2: "bs2 \ [] \ \ hd bs2 < hd as2" using bs2_def hd_dropWhile by metis show "as1 \ []" by (simp add: as1_def less.prems takeWhile_eq_Nil_iff) show "bs1 \ []" by (metis as2 bs1_def hd_as2 hd_in_set less.prems(7) less.prems(8) set_dropWhileD takeWhile_eq_Nil_iff) show "bs2 = [] \ (as2 \ [] \ hd as2 < hd bs2)" by (metis as2_def bs2_def hd_bs2 less.prems(8) list.set_sel(1) set_dropWhileD) - have AB: "less_sets (list.set A) (list.set B)" + have AB: "list.set A \ list.set B" if "A \ list.set as1" "B \ list.set bs" for A B proof - have "A \ list.set as" using that by (metis as1 set_takeWhileD) then have "sorted A" by (metis concat.simps(2) concat_append less.prems(1) sorted_append split_list_last strict_sorted_imp_sorted) moreover have "sorted (hd bs)" by (metis concat.simps(2) hd_Cons_tl less.prems(2) less.prems(7) strict_sorted_append_iff strict_sorted_imp_sorted) ultimately show ?thesis using that apply (clarsimp simp add: as1_def less.prems set_takeWhile less_list_iff_less_sets less_sets_def) by (smt UN_I dual_order.strict_trans2 hd_concat less.prems(2) less.prems(4) less.prems(7) list.set_sel(1) mem_lists_non_Nil not_le set_concat sorted_hd_le strict_sorted_imp_sorted) qed show "as = as1@as2" by (simp add: as1_def as2_def) show "bs = bs1@bs2" by (simp add: bs1_def bs2_def) - have "less_sets (list.set (concat as1)) (list.set (concat bs1))" + have "list.set (concat as1) \ list.set (concat bs1)" using AB set_takeWhileD by (fastforce simp add: as1_def bs1_def less_sets_UN1 less_sets_UN2) then show "concat as1 < concat bs1" by (rule less_sets_imp_list_less) - have "less_sets (list.set (concat bs1)) (list.set (concat as2))" if "as2 \ []" + have "list.set (concat bs1) \ list.set (concat as2)" if "as2 \ []" proof (clarsimp simp add: bs1_def less_sets_UN1 less_sets_UN2 set_takeWhile less.prems) fix A B assume "A \ list.set as2" "B \ list.set bs" "B < hd as2" - with that show "less_sets (list.set B) (list.set A)" + with that show "list.set B \ list.set A" using hd_as2 less.prems(1,2) apply (clarsimp simp add: less_sets_def less_list_def) apply (auto simp: as2_def) apply (simp flip: as2_def) by (metis UN_I \as = as1 @ as2\ concat.simps(2) concat_append dual_order.strict_trans2 hd_concat in_set_conv_decomp_last not_le set_concat sorted_hd_le sorted_le_last sorted_sorted_wrt sorted_wrt_append strict_sorted_imp_sorted that) qed then show "concat bs1 < concat as2" by (simp add: bs1_def less_sets_imp_list_less) qed obtain cs ds where "merge as2 bs2 cs ds" proof (cases "as2 = [] \ bs2 = []") case True then show thesis using that C NullNull Null by metis next have \: "length as2 + length bs2 < length as + length bs" by (simp add: A B) case False moreover have "strict_sorted (concat as2)" "strict_sorted (concat bs2)" "as2 \ lists (- {[]})" "bs2 \ lists (- {[]})" "\a b. \a \ list.set as2; b \ list.set bs2\ \ a < b \ b < a" using B less.prems strict_sorted_append_iff by auto ultimately show ?thesis using C less.hyps [OF \] False that by force qed then obtain cs where "merge (as1 @ as2) (bs1 @ bs2) (concat as1 # cs) (concat bs1 # ds)" using A merge.App by blast then show ?case using B by blast qed subsubsection \Actual proof of lemma 3.8\ text \Lemma 3.8 of Jean A. Larson, ibid.\ proposition lemma_3_8: assumes "infinite N" obtains X where "X \ WW" "ordertype X (lenlex less_than) = \\\" "\u. u \ [X]\<^bsup>2\<^esup> \ \l. Form l u \ (l > 0 \ [enum N l] < inter_scheme l u \ List.set (inter_scheme l u) \ N)" proof - let ?LL = "lenlex less_than" define bf where "bf \ \M q. wfrec pair_less (\f (j,i). let R = (case prev j i of None \ M | Some u \ snd (f u)) in grab R (q j i))" have bf_rec: "bf M q (j,i) = (let R = (case prev j i of None \ M | Some u \ snd (bf M q u)) in grab R (q j i))" for M q j i by (subst (1) bf_def) (simp add: Let_def wfrec bf_def cut_apply prev_pair_less cong: conj_cong split: option.split) have infinite_bf [simp]: "infinite (snd (bf M q u)) = infinite M" for M q u using wf_pair_less proof (induction u rule: wf_induct_rule) case (less u) then show ?case proof (cases u) case (Pair j i) with less.IH prev_pair_less show ?thesis by (auto simp: bf_rec [of M q j i] split: option.split) qed qed - have bf_less_sets: "less_sets (fst (bf M q ij)) (snd (bf M q ij))" if "infinite M" for M q ij + have bf_less_sets: "fst (bf M q ij) \ snd (bf M q ij)" if "infinite M" for M q ij using wf_pair_less proof (induction ij rule: wf_induct_rule) case (less u) then show ?case proof (cases u) case (Pair j i) with less_sets_grab show ?thesis by (simp add: bf_rec [of M q j i] less.IH prev_pair_less that split: option.split) qed qed have bf_subset: "fst (bf M q u) \ M \ snd (bf M q u) \ M" for M q u using wf_pair_less proof (induction u rule: wf_induct_rule) case (less u) show ?case proof (cases u) case (Pair j i) then show ?thesis apply (simp add: bf_rec [of M q j i] that split: option.split) using fst_grab_subset less.IH prev_pair_less snd_grab_subset by blast qed qed have card_fst_bf: "finite (fst (bf M q (j,i))) \ card (fst (bf M q (j,i))) = q j i" if "infinite M" for M q j i by (simp add: that bf_rec [of M q j i] split: option.split) have bf_cong: "bf M q u = bf M q' u" if "snd u \ fst u" and eq: "\y x. \x\y; y\fst u\ \ q' y x = q y x" for M q q' u using wf_pair_less that proof (induction u rule: wf_induct_rule) case (less u) show ?case proof (cases u) case (Pair j i) with less.prems show ?thesis proof (clarsimp simp add: bf_rec [of M _ j i] split: option.split) fix j' i' assume *: "prev j i = Some (j',i')" then have **: "((j', i'), u) \ pair_less" by (simp add: Pair prev_pair_less) moreover have "i' < j'" using Pair less.prems by (simp add: prev_Some_less [OF *]) moreover have "\x y. \x \ y; y \ j'\ \ q' y x = q y x" using ** less.prems by (auto simp: pair_less_def Pair) ultimately show "grab (snd (bf M q (j',i'))) (q j i) = grab (snd (bf M q' (j',i'))) (q j i)" using less.IH by auto qed qed qed define ediff where "ediff \ \D:: nat \ nat set. \j i. enum (D j) (Suc i) - enum (D j) i" define F where "F \ \l (dl,a0::nat set,b0::nat \ nat \ nat set,M). let (d,Md) = grab (nxt M (enum N (Suc (2 * Suc l)))) (Suc l) in let (a,Ma) = grab Md (Min d) in let Gb = bf Ma (ediff (dl(l := d))) in let dl' = dl(l := d) in (dl', a, fst \ Gb, snd (Gb(l, l-1)))" define DF where "DF \ rec_nat (\i\{..<0}. {}, {}, \p. {}, N) F" have DF_simps: "DF 0 = (\i\{..<0}. {}, {}, \p. {}, N)" "DF (Suc l) = F l (DF l)" for l by (auto simp: DF_def) note cut_apply [simp] have inf [rule_format]: "\dl al bl L. DF l = (dl,al,bl,L) \ infinite L" for l by (induction l) (auto simp: DF_simps F_def Let_def grab_eqD infinite_nxtN assms split: prod.split) define \ where "\ \ \(dl, a, b :: nat \ nat \ nat set, M::nat set). \l::nat. - less_sets (dl l) a \ finite a \ dl l \ {} \ a \ {} \ - (\j\l. card (dl j) = Suc j) \ less_sets a (\(range b)) \ range b \ Collect finite \ - a \ N \ \(range b) \ N \ infinite M \ less_sets (b(l,l-1)) M \ + dl l \ a \ finite a \ dl l \ {} \ a \ {} \ + (\j\l. card (dl j) = Suc j) \ a \ \(range b) \ range b \ Collect finite \ + a \ N \ \(range b) \ N \ infinite M \ b(l,l-1) \ M \ M \ N" have \_DF: "\ (DF (Suc l)) l" for l proof (induction l) case 0 show ?case using assms apply (clarsimp simp add: bf_rec F_def DF_simps \_def split: prod.split) apply (drule grab_eqD, blast dest: grab_eqD infinite_nxtN)+ apply (auto simp: less_sets_UN2 less_sets_grab card_fst_bf elim!: less_sets_weaken2) apply (metis Min_in card_eq_0_iff greaterThan_iff le_inf_iff less_nat_zero_code n_not_Suc_n nxt_def subsetD) using nxt_subset snd_grab_subset bf_subset by blast+ next case (Suc l) then show ?case using assms unfolding Let_def DF_simps(2)[of "Suc l"] F_def \_def apply (clarsimp simp add: bf_rec DF_simps split: prod.split) apply (drule grab_eqD, metis grab_eqD infinite_nxtN)+ apply (safe, simp_all add: less_sets_UN2 less_sets_grab card_fst_bf) apply (meson less_sets_weaken2) apply (metis (no_types, hide_lams) IntE Min_in card.empty greaterThan_iff leD not_less_eq_eq nxt_def subsetD zero_less_Suc) apply (meson bf_subset less_sets_weaken2) apply (meson nxt_subset subset_eq) apply (meson bf_subset nxt_subset subset_eq) using bf_rec infinite_bf apply force using bf_less_sets bf_rec apply force by (metis bf_rec bf_subset nxt_subset subsetD) qed define d where "d \ \k. let (dk,ak,bk,M) = DF(Suc k) in dk k" define a where "a \ \k. let (dk,ak,bk,M) = DF(Suc k) in ak" define b where "b \ \k. let (dk,ak,bk,M) = DF(Suc k) in bk" define M where "M \ \k. let (dk,ak,bk,M) = DF k in M" have infinite_M [simp]: "infinite (M k)" for k by (auto simp: M_def inf split: prod.split) have M_Suc_subset: "M (Suc k) \ M k" for k apply (clarsimp simp add: Let_def M_def F_def DF_simps split: prod.split) apply (drule grab_eqD, blast dest: infinite_nxtN local.inf)+ using bf_subset nxt_subset by blast have Inf_M_Suc_ge: "Inf (M k) \ Inf (M (Suc k))" for k by (simp add: M_Suc_subset cInf_superset_mono infinite_imp_nonempty) have Inf_M_telescoping: "{Inf (M k)..} \ {Inf (M k')..}" if "k'\k" for k k' using that by (induction "k-k'")(auto simp: Inf_M_Suc_ge M_Suc_subset cInf_superset_mono infinite_imp_nonempty lift_Suc_antimono_le) have d_eq: "d k = fst (grab (nxt (M k) (enum N (Suc (2 * Suc k)))) (Suc k))" for k by (simp add: d_def M_def Let_def DF_simps F_def split: prod.split) then have finite_d [simp]: "finite (d k)" for k by simp then have d_ne [simp]: "d k \ {}" for k by (metis card.empty card_grab d_eq infinite_M infinite_nxtN nat.distinct(1)) have a_eq: "\M. a k = fst (grab M (Min (d k))) \ infinite M" for k apply (simp add: a_def d_def M_def Let_def DF_simps F_def split: prod.split) by (metis fst_conv grab_eqD infinite_nxtN local.inf) then have card_a: "card (a k) = Inf (d k)" for k by (metis cInf_eq_Min card_grab d_ne finite_d) have d_eq_dl: "d k = dl k" if "(dl,a,b,P) = DF l" "k < l" for k l dl a b P using that by (induction l arbitrary: dl a b P) (simp_all add: d_def DF_simps F_def Let_def split: prod.split_asm prod.split) have card_d [simp]: "card (d k) = Suc k" for k by (auto simp: d_eq infinite_nxtN) have d_ne [simp]: "d j \ {}" and a_ne [simp]: "a j \ {}" and finite_d [simp]: "finite (d j)" and finite_a [simp]: "finite (a j)" for j using \_DF [of "j"] by (auto simp: \_def a_def d_def split: prod.split_asm) - have da: "less_sets (d k) (a k)" for k + have da: "d k \ a k" for k using \_DF [of "k"] by (simp add: \_def a_def d_def split: prod.split_asm) - have ab_same: "less_sets (a k) (\(range(b k)))" for k + have ab_same: "a k \ \(range(b k))" for k using \_DF [of "k"] by (simp add: \_def a_def b_def M_def split: prod.split_asm) have snd_bf_subset: "snd (bf M r (j,i)) \ snd (bf M r (j',i'))" if ji: "((j',i'), (j,i)) \ pair_less" "(j',i') \ IJ k" for M r k j i j' i' using wf_pair_less ji proof (induction rule: wf_induct_rule [where a= "(j,i)"]) case (less u) show ?case proof (cases u) case (Pair j i) then consider "prev j i = Some (j', i')" | x where "((j', i'), x) \ pair_less" "prev j i = Some x" using less.prems pair_less_prev by blast then show ?thesis proof cases case 1 then show ?thesis by (simp add: Pair bf_rec snd_grab_subset) next case 2 then have "snd (bf M r x) \ snd (bf M r (j', i'))" by (simp add: Pair less.IH prev_pair_less that(2)) moreover have "snd (bf M r u) \ snd (bf M r x)" by (simp add: 2 Pair bf_rec snd_grab_subset) ultimately show ?thesis by auto qed qed qed - have less_bf: "less_sets (fst (bf M r (j',i'))) (fst (bf M r (j,i)))" + have less_bf: "fst (bf M r (j',i')) \ fst (bf M r (j,i))" if ji: "((j',i'), (j,i)) \ pair_less" "(j',i') \ IJ k" and "infinite M" for M r k j i j' i' proof - consider "prev j i = Some (j', i')" | j'' i'' where "((j', i'), (j'',i'')) \ pair_less" "prev j i = Some (j'',i'')" by (metis pair_less_prev ji prod.exhaust_sel) then show ?thesis proof cases case 1 then show ?thesis using bf_less_sets bf_rec infinite_bf less_sets_fst_grab \infinite M\ by auto next case 2 - then have "less_sets (fst (bf M r (j',i'))) (snd (bf M r (j'',i'')))" + then have "fst (bf M r (j',i')) \ snd (bf M r (j'',i''))" by (meson bf_less_sets snd_bf_subset less_sets_weaken2 that) with 2 show ?thesis using bf_rec infinite_bf less_sets_fst_grab \infinite M\ by auto qed qed - have aM: "less_sets (a k) (M (Suc k))" for k + have aM: "a k \ M (Suc k)" for k apply (clarsimp simp add: a_def M_def DF_simps F_def Let_def split: prod.split) by (meson bf_subset grab_eqD infinite_nxtN less_sets_weaken2 local.inf) - then have "less_sets (a k) (a (Suc k))" for k + then have "a k \ a (Suc k)" for k by (metis IntE card_d card.empty d_eq da fst_grab_subset less_sets_trans less_sets_weaken2 nat.distinct(1) nxt_def subsetI) - then have aa: "less_sets (a j) (a k)" if "j a k" if "jk" for k k' j i + then have ab: "a k' \ b k (j,i)" if "k'\k" for k k' j i by (metis a_ne ab_same le_less less_sets_UN2 less_sets_trans rangeI that) - have db: "less_sets (d j) (b k (j,i))" if "j\k" for k j i + have db: "d j \ b k (j,i)" if "j\k" for k j i by (meson a_ne ab da less_sets_trans that) - have bMkk: "less_sets (b k (k,k-1)) (M (Suc k))" for k + have bMkk: "b k (k,k-1) \ M (Suc k)" for k using \_DF [of k] by (simp add: \_def b_def d_def M_def split: prod.split_asm) have b: "\P \ M k. infinite P \ (\j i. i\j \ j\k \ b k (j,i) = fst (bf P (ediff d) (j,i)))" for k proof (clarsimp simp: b_def DF_simps F_def Let_def split: prod.split) fix a a' d' dl bb P M' M'' assume gr: "grab M'' (Min d') = (a', M')" "grab (nxt P (enum N (Suc (Suc (Suc (2 * k)))))) (Suc k) = (d', M'')" and DF: "DF k = (dl, a, bb, P)" have deq: "d j = (if j = k then d' else dl j)" if "j\k" for j proof (cases "j < k") case True then show ?thesis by (metis DF d_eq_dl less_not_refl) next case False then show ?thesis using that DF gr by (auto simp: d_def DF_simps F_def Let_def split: prod.split) qed have "M' \ P" by (metis gr in_mono nxt_subset snd_conv snd_grab_subset subsetI) also have "P \ M k" using DF by (simp add: M_def) finally have "M' \ M k" . moreover have "infinite M'" using DF by (metis (mono_tags) finite_grab_iff gr infinite_nxtN local.inf snd_conv) moreover have "ediff (dl(k := d')) j i = ediff d j i" if "j\k" for j i by (simp add: deq that ediff_def) then have "bf M' (ediff (dl(k := d'))) (j,i) = bf M' (ediff d) (j,i)" if "i \ j" "j\k" for j i using bf_cong that by fastforce ultimately show "\P\M k. infinite P \ (\j i. i \ j \ j \ k \ fst (bf M' (ediff (dl(k := d'))) (j,i)) = fst (bf P (ediff d) (j,i)))" by auto qed have card_b: "card (b k (j,i)) = enum (d j) (Suc i) - enum (d j) i" if "j\k" for k j i \\there's a short proof of this from the previous result but it would need @{term"i\j"}\ proof (clarsimp simp: b_def DF_simps F_def Let_def split: prod.split) fix dl and a a' d':: "nat set" and bb M M' M'' assume gr: "grab M'' (Min d') = (a', M')" "grab (nxt M (enum N (Suc (Suc (Suc (2 * k)))))) (Suc k) = (d',M'')" and DF: "DF k = (dl, a, bb, M)" have "d j = (if j = k then d' else dl j)" proof (cases "j < k") case True then show ?thesis by (metis DF d_eq_dl less_not_refl) next case False then show ?thesis using that DF gr by (auto simp: d_def DF_simps F_def Let_def split: prod.split) qed then show "card (fst (bf M' (ediff (dl(k := d'))) (j,i))) = enum (d j) (Suc i) - enum (d j) i" using DF gr card_fst_bf grab_eqD infinite_nxtN local.inf ediff_def by auto qed have card_b_pos: "card (b k (j,i)) > 0" if "i < j" "j\k" for k j i by (simp add: card_b that finite_enumerate_step) have b_ne [simp]: "b k (j,i) \ {}" if "i < j" "j\k" for k j i using card_b_pos [OF that] less_imp_neq by fastforce+ have card_b_finite [simp]: "finite (b k u)" for k u using \_DF [of k] by (fastforce simp add: \_def b_def) - have bM: "less_sets (b k (j,i)) (M (Suc k))" if "ik" for i j k + have bM: "b k (j,i) \ M (Suc k)" if "ik" for i j k proof - obtain M' where "M' \ M k" "infinite M'" and bk: "\j i. i\j \ j\k \ b k (j,i) = fst (bf M' (ediff d) (j,i))" using b by (metis (no_types, lifting)) show ?thesis proof (cases "j=k \ i = k-1") case False show ?thesis proof (rule less_sets_trans [OF _ bMkk]) - show "less_sets (b k (j,i)) (b k (k, k - 1))" + show "b k (j,i) \ b k (k, k - 1)" using that \infinite M'\ False by (force simp: bk pair_less_def IJ_def intro: less_bf) show "b k (k, k - 1) \ {}" using b_ne that by auto qed qed (use bMkk in auto) qed have b_InfM: "\ (range (b k)) \ {\(M k)..}" for k proof (clarsimp simp add: \_def b_def M_def DF_simps F_def Let_def split: prod.split) fix r dl :: "nat \ nat set" and a b and d' a' M'' M' P :: "nat set" and x j' i' :: nat assume gr: "grab M'' (Min d') = (a', M')" "grab (nxt P (enum N (Suc (Suc (Suc (2 * k)))))) (Suc k) = (d', M'')" and DF: "DF k = (dl, a, b, P)" and x: "x \ fst (bf M' (ediff (dl(k := d'))) (j', i'))" have "infinite P" using DF local.inf by blast then have "M' \ P" by (meson gr grab_eqD infinite_nxtN nxt_subset order.trans) with bf_subset show "\ P \ (x::nat)" using Inf_nat_def x le_less_linear not_less_Least by fastforce qed - have b_Inf_M_Suc: "less_sets (b k (j,i)) {Inf(M (Suc k))}" if "ik" for k j i + have b_Inf_M_Suc: "b k (j,i) \ {Inf(M (Suc k))}" if "ik" for k j i using bMkk [of k] that by (metis Inf_nat_def1 bM finite.emptyI infinite_M less_setsD less_sets_singleton2) - have bb_same: "less_sets (b k (j',i')) (b k (j,i))" + have bb_same: "b k (j',i') \ b k (j,i)" if "((j',i'), (j,i)) \ pair_less" "(j',i') \ IJ k" for k j i j' i' using that unfolding b_def DF_simps F_def Let_def by (auto simp: less_bf grab_eqD infinite_nxtN local.inf split: prod.split) - have bb: "less_sets (b k' (j',i')) (b k (j,i))" + have bb: "b k' (j',i') \ b k (j,i)" if j: "i' < j'" "j'\k'" and k: "k' {Inf(M (Suc k'))}" using Suc_lessD b_Inf_M_Suc nat_less_le j by blast have "b k (j,i) \ {\(M k)..}" by (rule order_trans [OF _ b_InfM]) auto also have "\ \ {Inf(M (Suc k'))..}" using Inf_M_telescoping k by auto finally show "b k (j,i) \ {Inf(M (Suc k'))..}" . qed have M_subset_N: "M k \ N" for k proof (cases k) case (Suc k') with \_DF [of k'] show ?thesis by (auto simp: M_def Let_def \_def split: prod.split) qed (auto simp: M_def DF_simps) have a_subset_N: "a k \ N" for k using \_DF [of k] by (simp add: a_def \_def split: prod.split prod.split_asm) have d_subset_N: "d k \ N" for k using M_subset_N [of k] d_eq fst_grab_subset nxt_subset by blast have b_subset_N: "b k (j,i) \ N" for k j i using \_DF [of k] by (force simp: b_def \_def) define \:: "[nat,nat] \ nat set set" where "\ \ \j0 j. nsets {j0<..} j" have \_finite: "K \ \ j0 j \ finite K" for K j0 j by (simp add: \_def nsets_def) have \_card: "K \ \ j0 j \ card K = j" for K j0 j by (simp add: \_def nsets_def) have \_enum: "j0 < enum K i" if "K \ \ j0 j" "i < card K" for K j0 j i using that by (auto simp: \_def nsets_def finite_enumerate_in_set subset_eq) have \_0 [simp]: "\ k 0 = {{}}" for k by (auto simp: \_def) have \_Suc: "\ j0 (Suc j) = USigma (\ j0 j) (\K. {Max (insert j0 K)<..})" (is "?lhs = ?rhs") for j j0 proof show "\ j0 (Suc j) \ USigma (\ j0 j) (\K. {Max (insert j0 K)<..})" unfolding \_def nsets_def USigma_def proof clarsimp fix K assume K: "K \ {j0<..}" "finite K" "card K = Suc j" then obtain i where "Max (insert j0 (K - {Max K})) < i" "K = insert i (K - {Max K})" apply (simp add: subset_iff) by (metis Diff_iff Max.coboundedI Max_in card_0_eq insert_Diff insert_iff le_neq_implies_less nat.distinct(1)) then show "\L\{j0<..}. finite L \ card L = j \ (\i\{Max (insert j0 L)<..}. K = insert i L)" using K by (metis Max_in card_Diff_singleton_if card_gt_0_iff diff_Suc_1 finite_Diff greaterThan_iff insert_subset zero_less_Suc) qed show "?rhs \ \ j0 (Suc j)" by (force simp: \_def nsets_def USigma_def) qed define BB where "BB \ \j0 j K. list_of (a j0 \ (\i \j. BB j j ` \ j j" have less_list_of: "BB j i K < list_of (b l (j,i))" if K: "K \ \ j i" "\j\K. j < l" and "i \ j" "j \ l" for j i K l unfolding BB_def proof (rule less_sets_imp_sorted_list_of_set) - have "\i. i < card K \ less_sets (b (enum K i) (j,i)) (b l (j, card K))" + have "\i. i < card K \ b (enum K i) (j,i) \ b l (j, card K)" using that by (metis \_card \_enum \_finite bb finite_enumerate_in_set nat_less_le less_le_trans) - then show "less_sets (a j \ (\i_def nsets_def + then show "a j \ (\i b l (j,i)" + using that unfolding \_def nsets_def by (auto simp: less_sets_Un1 less_sets_UN1 ab finite_enumerate_in_set subset_eq) qed auto have BB_Suc: "BB j0 (Suc j) K = usplit (\L k. BB j0 j L @ list_of (b k (j0, j))) K" if j: "j \ j0" and K: "K \ \ j0 (Suc j)" for j0 j K \\towards the ordertype proof\ proof - have Kj: "K \ {j0<..}" and [simp]: "finite K" and cardK: "card K = Suc j" using K by (auto simp: \_def nsets_def) have KMK: "K - {Max K} \ \ j0 j" using that by (simp add: \_Suc USigma_iff \_finite less_sets_def usplit_def) have "j0 < Max K" by (metis Kj Max_in cardK card_gt_0_iff greaterThan_iff subsetD zero_less_Suc) have MaxK: "Max K = enum K j" proof (rule Max_eqI) show "enum K j \ K" by (simp add: cardK finite_enumerate_in_set) show "k \ enum K j" if "k \ K" for k using that K by (metis \finite K\ cardK enum_obtain_index_finite finite_enumerate_mono leI less_Suc_eq less_asym) qed auto have ene: "i enum (K - {enum K j}) i = enum K i" for i using finite_enumerate_Diff_singleton [OF \finite K\] by (simp add: cardK) have "BB j0 (Suc j) K = list_of ((a j0 \ (\x b (enum K j) (j0, j))" by (simp add: BB_def lessThan_Suc Un_ac) also have "\ = list_of ((a j0 \ (\i b (enum K j) (j0, j)" if "i enum K i" using that K by (metis \_enum cardK less_SucI less_imp_le_nat) show "enum K i < enum K j" by (simp add: cardK finite_enumerate_mono that) qed - moreover have "less_sets (a j0) (b (enum K j) (j0, j))" + moreover have "a j0 \ b (enum K j) (j0, j)" using MaxK \j0 < Max K\ ab by auto - ultimately show "less_sets (a j0 \ (\x (\x b (enum K j) (j0, j)" by (simp add: less_sets_Un1 less_sets_UN1) qed (auto simp: finite_UnI) also have "\ = BB j0 j (K - {Max K}) @ list_of (b (Max K) (j0, j))" by (simp add: BB_def MaxK ene) also have "\ = usplit (\L k. BB j0 j L @ list_of (b k (j0, j))) K" by (simp add: usplit_def) finally show ?thesis . qed have enum_d_0: "enum (d j) 0 = Inf (d j)" for j using enum_0_eq_Inf_finite by auto have Inf_b_less: "\(b k' (j',i')) < \(b k (j,i))" if j: "i' < j'" "i < j" "j'\k'" "j\k" and k: "k' (b k (k, k-1)) \ k-1" if "k>0" for k using that proof (induction k) case (Suc k) show ?case proof (cases "k=0") case False have "\ (b k (k, k - Suc 0)) < \ (b (Suc k) (Suc k, k))" using False Inf_b_less by auto with False Suc show ?thesis by simp qed auto qed auto have b_ge: "\ (b k (j,i)) \ k-1" if k: "k>0" "k \ j" and "j > i" for k j i using k proof (induction k) case (Suc k) show ?case proof (cases "j \ k") case True have "\ (b k (j,i)) < \ (b (Suc k) (j,i))" using \j > i\ Suc True by (force intro: Inf_b_less) then show ?thesis using Suc.IH True by linarith next case False then have "j = Suc k" using Suc.prems(2) by linarith with \i < j\ have "i < Suc k" by fastforce moreover have "\ \ (b (Suc k) (j,i)) < \ (b (Suc k) (j,i))" by fastforce ultimately have "\ Suc (\ (b (Suc k) (j,i))) < Suc k" by (metis Inf_b_less \j = Suc k\ b_ge_k diff_Suc_1 leD le_refl lessI zero_less_Suc) then show ?thesis by simp qed qed auto have hd_b: "hd (list_of (b k (j,i))) = \ (b k (j,i))" if "i < j" "j \ k" for k j i using that by (simp add: hd_list_of cInf_eq_Min) have b_disjoint_less: "b (enum K i) (j0, i) \ b (enum K i') (j0, i') = {}" if K: "K \ {j0<..}" "finite K" "card K \ j0" "i' < j" "i < i'" "j \ j0" for i i' j j0 K proof (intro bb less_sets_imp_disjnt [unfolded disjnt_def]) show "i < j0" using that by linarith then show "j0 \ enum K i" by (meson K finite_enumerate_in_set greaterThan_iff less_imp_le_nat less_le_trans subsetD) show "enum K i < enum K i'" using K \j \ j0\ that by auto qed have b_disjoint: "b (enum K i) (j0, i) \ b (enum K i') (j0, i') = {}" if K: "K \ {j0<..}" "finite K" "card K \ j0" "i < j" "i' < j" "i \ i'" "j \ j0" for i i' j j0 K using that b_disjoint_less inf_commute neq_iff by metis have ot\: "ordertype ((\k. list_of (b k (j,i))) ` {Max (insert j K)<..}) ?LL = \" (is "?lhs = _") if K: "K \ \ j i" "j > i" for j i K proof - have Sucj: "Suc (Max (insert j K)) \ j" using \_finite that(1) le_Suc_eq by auto let ?N = "{Inf(b k (j,i))| k. Max (insert j K) < k}" have infN: "infinite ?N" proof (clarsimp simp add: infinite_nat_iff_unbounded_le) fix m show "\n\m. \k. n = \ (b k (j,i)) \ Max (insert j K) < k" using b_ge [of _ j i] \j > i\ Sucj by (metis (no_types, lifting) diff_Suc_1 le_SucI le_trans less_Suc_eq_le nat_le_linear zero_less_Suc) qed have [simp]: "Max (insert j K) < k \ j < k \ (\a\K. a < k)" for k using that by (auto simp: \_finite) have "?lhs = ordertype ?N less_than" proof (intro ordertype_eqI strip) have "list_of (b k (j,i)) = list_of (b k' (j,i))" if "j \ k" "j \ k'" "hd (list_of (b k (j,i))) = hd (list_of (b k' (j,i)))" for k k' by (metis Inf_b_less \i < j\ hd_b nat_less_le not_le that) moreover have "\k' j' i'. hd (list_of (b k (j,i))) = \ (b k' (j', i')) \ i' < j' \ j' \ k'" if "j \ k" for k using that \i < j\ hd_b less_imp_le_nat by blast moreover have "\k'. hd (list_of (b k (j,i))) = \ (b k' (j,i)) \ j < k' \ (\a\K. a < k')" if "j < k" "\a\K. a < k" for k using that K hd_b less_imp_le_nat by blast moreover have "\ (b k (j,i)) \ hd ` (\k. list_of (b k (j,i))) ` {Max (insert j K)<..}" if "j < k" "\a\K. a < k" for k using that K by (auto simp: hd_b image_iff) ultimately show "bij_betw hd ((\k. list_of (b k (j,i))) ` {Max (insert j K)<..}) {\ (b k (j,i)) |k. Max (insert j K) < k}" by (auto simp: bij_betw_def inj_on_def) next fix ms ns assume "ms \ (\k. list_of (b k (j,i))) ` {Max (insert j K)<..}" and "ns \ (\k. list_of (b k (j,i))) ` {Max (insert j K)<..}" with that obtain k k' where ms: "ms = list_of (b k (j,i))" and ns: "ns = list_of (b k' (j,i))" and "j < k" "j < k'" and lt_k: "\a\K. a < k" and lt_k': "\a\K. a < k'" by (auto simp: \_finite) then have len_eq [simp]: "length ns = length ms" by (simp add: card_b) have nz: "length ns \ 0" using b_ne \i < j\ \j < k'\ ns by auto show "(hd ms, hd ns) \ less_than \ (ms, ns) \ ?LL" proof assume "(hd ms, hd ns) \ less_than" then show "(ms, ns) \ ?LL" using that nz by (fastforce simp add: lenlex_def \_finite card_b intro: hd_lex) next assume \
: "(ms, ns) \ ?LL" then have "(list_of (b k' (j,i)), list_of (b k (j,i))) \ ?LL" using less_asym ms ns omega_sum_1_less by blast then show "(hd ms, hd ns) \ less_than" using \j < k\ \j < k'\ Inf_b_less [of i j i j] ms ns by (metis Cons_lenlex_iff \
len_eq b_ne card_b_finite diff_Suc_1 hd_Cons_tl hd_b length_Cons less_or_eq_imp_le less_than_iff linorder_neqE_nat sorted_list_of_set_eq_Nil_iff that(2)) qed qed auto also have "\ = \" using infN ordertype_nat_\ by blast finally show ?thesis . qed have ot\j: "ordertype (BB j0 j ` \ j0 j) ?LL = \\j" if "j \ j0" for j j0 using that proof (induction j) case 0 then show ?case by (auto simp: XX_def) next case (Suc j) then have ih: "ordertype (BB j0 j ` \ j0 j) ?LL = \ \ j" by simp have "j \ j0" by (simp add: Suc.prems Suc_leD) have inj_BB: "inj_on (BB j0 j) ([{j0<..}]\<^bsup>j\<^esup>)" proof (clarsimp simp: inj_on_def BB_def nsets_def subset_iff sorted_list_of_set_Un less_sets_UN2) fix X Y assume X [rule_format]: "\t. t \ X \ j0 < t" and Y [rule_format]: "\t. t \ Y \ j0 < t" and "finite X" and jeq: "j = card X" and "finite Y" and "card Y = card X" and eq: "list_of (a j0 \ (\i (\in. \n < card X\ \ j0 \ enum X n" using X \finite X\ finite_enumerate_in_set less_imp_le_nat by blast have enumY: "\n. \n < card X\ \ j0 \ enum Y n" by (simp add: Y \card Y = card X\ \finite Y\ finite_enumerate_in_set less_imp_le_nat) have smX: "strict_mono_sets {..i. b (enum X i) (j0, i))" and smY: "strict_mono_sets {..i. b (enum Y i) (j0, i))" using Suc.prems \card Y = card X\ \finite X\ \finite Y\ bb enumX enumY jeq by (auto simp: strict_mono_sets_def) have len_eq: "length ms = length ns" if "(ms, ns) \ list.set (zip (map (list_of \ (\i. b (enum X i) (j0,i))) (list_of {.. (\i. b (enum Y i) (j0,i))) (list_of {.. card X" for ms ns n using that by (induction n rule: nat.induct) (auto simp: card_b enumX enumY) have "concat (map (list_of \ (\i. b (enum X i) (j0, i))) (list_of {.. (\i. b (enum Y i) (j0, i))) (list_of {.. (\i. b (enum X i) (j0, i))) (list_of {.. (\i. b (enum Y i) (j0, i))) (list_of {.. (b (enum X i) (j0,i))" "Inf (b (enum Y i) (j0,i)) \ (b (enum Y i) (j0,i))" "i < j0" using Inf_nat_def1 Suc.prems b_ne enumX enumY jeq that by auto ultimately show ?thesis by (metis Inf_b_less enumX enumY leI nat_less_le that) qed then show "X = Y" by (simp add: \card Y = card X\ \finite X\ \finite Y\ finite_enum_ext) qed have BB_Suc': "BB j0 (Suc j) X = usplit (\L k. BB j0 j L @ list_of (b k (j0, j))) X" if "X \ USigma (\ j0 j) (\K. {Max (insert j0 K)<..})" for X using that by (simp add: USigma_iff \_finite less_sets_def usplit_def \_Suc BB_Suc \j \ j0\) have "ordertype (BB j0 (Suc j) ` \ j0 (Suc j)) ?LL = ordertype (usplit (\L k. BB j0 j L @ list_of (b k (j0, j))) ` USigma (\ j0 j) (\K. {Max (insert j0 K)<..})) ?LL" by (simp add: BB_Suc' \_Suc) also have "\ = \ * ordertype (BB j0 j ` \ j0 j) ?LL" proof (rule ordertype_append_image_IJ) fix L k assume "L \ \ j0 j" and "k \ {Max (insert j0 L)<..}" then have "j0 < k" and L: "\a. a \ L \ a < k" by (simp_all add: \_finite) then show "BB j0 j L < list_of (b k (j0, j))" by (simp add: \L \ \ j0 j\ \j \ j0\ \_finite less_list_of) next show "inj_on (BB j0 j) (\ j0 j)" by (simp add: \_def inj_BB) next fix L assume L: "L \ \ j0 j" - then show "less_sets L {Max (insert j0 L)<..} \ finite L" + then show "L \ {Max (insert j0 L)<..} \ finite L" by (metis \_finite atLeast_Suc_greaterThan finite_insert less_sets_Suc_Max less_sets_weaken1 subset_insertI) show "ordertype ((\i. list_of (b i (j0, j))) ` {Max (insert j0 L)<..}) ?LL = \" using L Suc.prems Suc_le_lessD ot\ by blast qed (auto simp: \_finite card_b) also have "\ = \ \ ord_of_nat (Suc j)" by (metis ih One_nat_def Ord_\ Ord_ord_of_nat oexp_1_right oexp_add one_V_def ord_of_nat.simps(1) ord_of_nat.simps(2) ord_of_nat_add plus_1_eq_Suc) finally show ?case . qed define seqs where "seqs \ \j0 j K. list_of (a j0) # (map (list_of \ (\i. b (enum K i) (j0,i))) (list_of {.. lists (- {[]})" if K: "K \ \ j0 j" and "j \ j0" for K j j0 proof - have j0: "\i. i < card K \ j0 \ enum K i" and le_j0: "card K \ j0" using finite_enumerate_in_set that unfolding \_def nsets_def by fastforce+ show "BB j0 j K = concat (seqs j0 j K)" using that unfolding BB_def \_def nsets_def seqs_def by (fastforce simp: j0 ab bb less_sets_UN2 sorted_list_of_set_Un strict_mono_sets_def sorted_list_of_set_UN_lessThan) have "b (enum K i) (j0, i) \ {}" if "i < card K" for i using j0 le_j0 less_le_trans that by simp moreover have "card K = j" using K \_card by blast ultimately show "seqs j0 j K \ lists (- {[]})" by (clarsimp simp: seqs_def) (metis card_b_finite sorted_list_of_set_eq_Nil_iff) qed have BB_decomp: "\cs. BB j0 j K = concat cs \ cs \ lists (- {[]})" if K: "K \ \ j0 j" and "j \ j0" for K j j0 using BB_eq_concat_seqs seqs_ne K that(2) by blast have a_subset_M: "a k \ M k" for k apply (clarsimp simp: a_def M_def DF_simps F_def Let_def split: prod.split_asm) by (metis (no_types) fst_conv fst_grab_subset nxt_subset snd_conv snd_grab_subset subsetD) - have ba_Suc: "less_sets (b k (j,i)) (a (Suc k))" if "i < j" "j \ k" for i j k + have ba_Suc: "b k (j,i) \ a (Suc k)" if "i < j" "j \ k" for i j k by (meson a_subset_M bM less_sets_weaken2 nat_less_le that(1) that(2)) - have ba: "less_sets (b k (j,i)) (a r)" if "i < j" "j \ k" "k < r" for i j k r + have ba: "b k (j,i) \ a r" if "i < j" "j \ k" "k < r" for i j k r by (metis Suc_lessI a_ne aa ba_Suc less_sets_trans that) have disjnt_ba: "disjnt (b k (j,i)) (a r)" if "i < j" "j \ k" for i j k r proof (cases "k < r") case True then show ?thesis by (simp add: ba less_sets_imp_disjnt that) next case False then show ?thesis proof - - have "less_sets (a r) (b k (j,i))" + have "a r \ b k (j,i)" by (metis False a_ne aa ab_same less_linear less_sets_UN2 less_sets_trans rangeI) then show ?thesis using disjnt_sym less_sets_imp_disjnt by blast qed qed have bb_disjnt: "disjnt (b k (j,i)) (b l (r,q))" if "q < r" "i < j" "j \ k" "r \ l" "j < r" for i j q r k l proof (cases "k=l") case True with that show ?thesis by (force simp: pair_less_def IJ_def intro: bb_same less_sets_imp_disjnt) next case False with that show ?thesis by (metis bb less_sets_imp_disjnt disjnt_sym nat_neq_iff) qed have sum_card_b: "(\i {j0<..}" "finite K" "card K \ j0" and "j \ j0" for j0 j K using \j \ j0\ proof (induction j) case 0 then show ?case by auto next case (Suc j) have dis: "disjnt (b (enum K j) (j0, j)) (\ii < j\ b_disjoint_less disjnt_def disjnt_sym less_Suc_eq that) qed have j0_less: "j0 < enum K j" by (meson Suc.prems Suc_le_lessD finite_enumerate_in_set greaterThan_iff less_le_trans subsetD K) have "(\ii = card (b (enum K j) (j0, j)) + enum (d j0) j - enum (d j0) 0" using \Suc j \ j0\ by (simp add: Suc.IH split: nat_diff_split) also have "\ = enum (d j0) (Suc j) - enum (d j0) 0" using j0_less apply (simp add: card_b split: nat_diff_split) by (metis Suc.prems card_d finite_d finite_enumerate_step le_imp_less_Suc less_asym) finally show ?case . qed have card_UN_b: "card (\i {j0<..}" "finite K" "card K \ j0" and "j \ j0" for j0 j K using that by (simp add: card_UN_disjoint sum_card_b b_disjoint) have len_BB: "length (BB j j K) = enum (d j) j" if K: "K \ \ j j" and "j \ j" for j K proof - have dis_ab: "\i. i < j \ disjnt (a j) (b (enum K i) (j,i))" using K \_card \_enum ab less_sets_imp_disjnt nat_less_le by blast show ?thesis using K unfolding BB_def \_def nsets_def by (simp add: card_UN_b card_Un_disjnt dis_ab card_a cInf_le_finite finite_enumerate_in_set enum_0_eq_Inf_finite) qed - have "less_sets (d k) (d (Suc k))" for k + have "d k \ d (Suc k)" for k by (metis aM a_ne d_eq da less_sets_fst_grab less_sets_trans less_sets_weaken2 nxt_subset) - then have dd: "less_sets (d k') (d k)" if "k' < k" for k' k + then have dd: "d k' \ d k" if "k' < k" for k' k by (meson UNIV_I d_ne less_sets_imp_strict_mono_sets strict_mono_sets_def that) show thesis proof show "(\ (range XX)) \ WW" by (auto simp: XX_def BB_def WW_def) show "ordertype (\ (range XX)) (?LL) = \ \ \" using ot\j by (simp add: XX_def ordertype_\\) next fix U assume U: "U \ [\ (range XX)]\<^bsup>2\<^esup>" then obtain x y where Ueq: "U = {x,y}" and len_xy: "length x \ length y" by (auto simp: lenlex_nsets_2_eq lenlex_length) show "\l. Form l U \ (0 < l \ [enum N l] < inter_scheme l U \ list.set (inter_scheme l U) \ N)" proof (cases "length x = length y") case True then show ?thesis using Form.intros(1) U Ueq by fastforce next case False then have xy: "length x < length y" using len_xy by auto obtain j r K L where K: "K \ \ j j" and xeq: "x = BB j j K" and ne: "BB j j K \ BB r r L" and L: "L \ \ r r" and yeq: "y = BB r r L" using U by (auto simp: Ueq XX_def) then have "length x = enum (d j) j" "length y = enum (d r) r" by (auto simp: len_BB) then have "j < r" using xy dd by (metis card_d finite_enumerate_in_set finite_d lessI less_asym less_setsD linorder_neqE_nat) - then have aj_ar: "less_sets (a j) (a r)" + then have aj_ar: "a j \ a r" using aa by auto have Ksub: "K \ {j<..}" and "finite K" "card K \ j" using K by (auto simp: \_def nsets_def) have Lsub: "L \ {r<..}" and "finite L" "card L \ r" using L by (auto simp: \_def nsets_def) have enumK: "enum K i > j" if "i < j" for i using K \_card \_enum that by blast have enumL: "enum L i > r" if "i < r" for i using L \_card \_enum that by blast have "list.set (acc_lengths w (seqs j0 j K)) \ (+) w ` d j0" if K: "K \ {j0<..}" "finite K" "card K \ j0" and "j \ j0" for j0 j K w using \j \ j0\ proof (induction j arbitrary: w) case 0 then show ?case by (simp add: seqs_def acc_lengths.simps Inf_nat_def1 card_a) next case (Suc j) let ?db = "\ (d j0) + ((\i d j0" using Suc.prems finite_enumerate_in_set by (auto simp: finite_enumerate_in_set) moreover have "list.set (acc_lengths w (seqs j0 j K)) \ (+) w ` d j0" by (simp add: Suc Suc_leD) then have "list.set (acc_lengths (w + \ (d j0)) (map (list_of \ (\i. b (enum K i) (j0,i))) (list_of {.. (+) w ` d j0" by (simp add: seqs_def acc_lengths.simps card_a subset_insertI) ultimately show ?case by (simp add: seqs_def acc_lengths.simps acc_lengths_append image_iff Inf_nat_def1 sum_sorted_list_of_set_map card_a) qed then have acc_lengths_subset_d: "list.set (acc_lengths 0 (seqs j0 j K)) \ d j0" if K: "K \ {j0<..}" "finite K" "card K \ j0" and "j \ j0" for j0 j K by (metis image_add_0 that) have "strict_sorted x" "strict_sorted y" by (auto simp: xeq yeq BB_def) have disjnt_xy: "disjnt (list.set x) (list.set y)" proof - have "disjnt (a j) (a r)" using \j < r\ aa less_sets_imp_disjnt by blast moreover have "disjnt (b (enum K i) (j,i)) (a r)" if "i < j" for i by (simp add: disjnt_ba enumK less_imp_le_nat that) moreover have "disjnt (a j) (b (enum L q) (r,q))" if "q < r" for q by (meson disjnt_ba disjnt_sym enumL less_imp_le_nat that) moreover have "disjnt (b (enum K i) (j,i)) (b (enum L q) (r,q))" if "i < j" "q < r" for i q by (meson \j < r\ bb_disjnt enumK enumL less_imp_le that) ultimately show ?thesis by (simp add: xeq yeq BB_def) qed have "\us vs. merge (seqs j j K) (seqs r r L) us vs" proof (rule merge_exists) show "strict_sorted (concat (seqs j j K))" using BB_eq_concat_seqs K \strict_sorted x\ xeq by auto show "strict_sorted (concat (seqs r r L))" using BB_eq_concat_seqs L \strict_sorted y\ yeq by auto show "seqs j j K \ lists (- {[]})" "seqs r r L \ lists (- {[]})" by (auto simp: K L seqs_ne) show "hd (seqs j j K) < hd (seqs r r L)" by (simp add: aj_ar less_sets_imp_list_less seqs_def) show "seqs j j K \ []" "seqs r r L \ []" using seqs_def by blast+ - have less_bb: "less_sets (b (enum K i) (j,i)) (b (enum L p) (r, p))" - if neg: "\ less_sets (b (enum L p) (r, p)) (b (enum K i) (j,i))" and "i < j" "p < r" + have less_bb: "b (enum K i) (j,i) \ b (enum L p) (r, p)" + if neg: "\ b (enum L p) (r, p) \ b (enum K i) (j,i)" and "i < j" "p < r" for i p proof (cases "enum K i" "enum L p" rule: linorder_cases) case less then show ?thesis by (simp add: bb enumK less_imp_le_nat \i < j\) next case equal then show ?thesis using \j < r\ enumK \i < j\ by (force simp: IJ_iff pair_less_def intro: bb_same) next case greater then show ?thesis using bb enumL less_imp_le_nat neg \p < r\ by blast qed show "u < v \ v < u" if "u \ list.set (seqs j j K)" and "v \ list.set (seqs r r L)" for u v using that enumK enumL apply (auto simp: seqs_def aj_ar intro!: less_bb less_sets_imp_list_less) apply (meson ab ba less_imp_le_nat not_le)+ done qed then obtain uus vvs where merge: "merge (seqs j j K) (seqs r r L) uus vvs" by metis then have "uus \ []" using merge_length1_gt_0 by (auto simp: seqs_def) then obtain u1 us where us: "u1#us = uus" by (metis neq_Nil_conv) define ku where "ku \ length (u1#us)" define ps where "ps \ acc_lengths 0 (u1#us)" have us_ne: "u1#us \ lists (- {[]})" using merge_length1_nonempty seqs_ne us merge us K by auto have xu_eq: "x = concat (u1#us)" using BB_eq_concat_seqs K merge merge_preserves us xeq by auto then have "strict_sorted u1" using \strict_sorted x\ strict_sorted_append_iff by auto have u_sub: "list.set ps \ list.set (acc_lengths 0 (seqs j j K))" using acc_lengths_merge1 merge ps_def us by blast have "vvs \ []" using merge BB_eq_concat_seqs L merge_preserves xy yeq by auto then obtain v1 vs where vs: "v1#vs = vvs" by (metis neq_Nil_conv) define kv where "kv \ length (v1#vs)" define qs where "qs \ acc_lengths 0 (v1#vs)" have vs_ne: "v1#vs \ lists (- {[]})" using L merge merge_length2_nonempty seqs_ne vs by auto have yv_eq: "y = concat (v1#vs)" using BB_eq_concat_seqs L merge merge_preserves vs yeq by auto then have "strict_sorted v1" using \strict_sorted y\ strict_sorted_append_iff by auto have v_sub: "list.set qs \ list.set (acc_lengths 0 (seqs r r L))" using acc_lengths_merge2 merge qs_def vs by blast have ss_concat_jj: "strict_sorted (concat (seqs j j K))" using BB_eq_concat_seqs K \strict_sorted x\ xeq by auto then obtain k: "0 < kv" "kv \ ku" "ku \ Suc kv" "kv \ Suc j" using us vs merge_length_le merge_length_le_Suc merge_length_less2 merge unfolding ku_def kv_def by fastforce define zs where "zs \ concat [ps,u1,qs,v1] @ interact us vs" have ss: "strict_sorted zs" proof - have ssp: "strict_sorted ps" unfolding ps_def by (meson strict_sorted_acc_lengths us_ne) have ssq: "strict_sorted qs" unfolding qs_def by (meson strict_sorted_acc_lengths vs_ne) - have "less_sets (d j) (list.set x)" + have "d j \ list.set x" using da [of j] db [of j] K \_card \_enum nat_less_le by (auto simp: xeq BB_def less_sets_Un2 less_sets_UN2) then have ac_x: "acc_lengths 0 (seqs j j K) < x" by (meson Ksub \finite K\ \j \ card K\ acc_lengths_subset_d dual_order.refl less_sets_imp_list_less less_sets_weaken1) then have "ps < u1" - by (metis K Ksub UnI1 \_card \finite K\ \j \ card K\ \less_sets (d j) (list.set x)\ acc_lengths_subset_d concat.simps(2) empty_iff empty_set hd_append2 less_list_def less_sets_imp_list_less less_sets_weaken1 list.set_sel(1) set_append u_sub xu_eq) - - have "less_sets (d r) (list.set y)" + by (metis K Ksub UnI1 \_card \finite K\ \j \ card K\ \d j \ list.set x\ acc_lengths_subset_d concat.simps(2) empty_iff empty_set hd_append2 less_list_def less_sets_imp_list_less less_sets_weaken1 list.set_sel(1) set_append u_sub xu_eq) + + have "d r \ list.set y" using da [of r] db [of r] L \_card \_enum nat_less_le by (auto simp: yeq BB_def less_sets_Un2 less_sets_UN2) then have "acc_lengths 0 (seqs r r L) < y" by (meson Lsub \finite L\ \r \ card L\ acc_lengths_subset_d dual_order.refl less_sets_imp_list_less less_sets_weaken1) then have "qs < v1" - by (metis L Lsub UnI1 \_card \finite L\ \r \ card L\ \less_sets (d r) (list.set y)\ acc_lengths_subset_d concat.simps(2) empty_iff empty_set hd_append2 less_list_def less_sets_imp_list_less less_sets_weaken1 list.set_sel(1) set_append v_sub yv_eq) + by (metis L Lsub UnI1 \_card \finite L\ \r \ card L\ \d r \ list.set y\ acc_lengths_subset_d concat.simps(2) empty_iff empty_set hd_append2 less_list_def less_sets_imp_list_less less_sets_weaken1 list.set_sel(1) set_append v_sub yv_eq) have carda_v1: "card (a r) \ length v1" using length_hd_merge2 [OF merge] unfolding vs [symmetric] by (simp add: seqs_def) - have ab_enumK: "\i. i < j \ less_sets (a j) (b (enum K i) (j,i))" + have ab_enumK: "\i. i < j \ a j \ b (enum K i) (j,i)" by (meson ab enumK le_trans less_imp_le_nat) - have ab_enumL: "\q. q < r \ less_sets (a j) (b (enum L q) (r,q))" + have ab_enumL: "\q. q < r \ a j \ b (enum L q) (r,q)" by (meson \j < r\ ab enumL le_trans less_imp_le_nat) - then have ay: "less_sets (a j) (list.set y)" + then have ay: "a j \ list.set y" by (auto simp: yeq BB_def less_sets_Un2 less_sets_UN2 aj_ar) have disjnt_hd_last_K_y: "disjnt {hd l..last l} (list.set y)" if l: "l \ list.set (seqs j j K)" for l proof (clarsimp simp add: yeq BB_def disjnt_iff Ball_def, intro conjI strip) fix u assume u: "u \ last l" and "hd l \ u" with l consider "u \ last (list_of (a j))" "hd (list_of (a j)) \ u" | i where "i last (list_of (b (enum K i) (j,i)))" "hd (list_of (b (enum K i) (j,i))) \ u" by (force simp: seqs_def) note l_cases = this then show "u \ a r" proof cases case 1 then show ?thesis by (metis a_ne aj_ar finite_a last_in_set leD less_setsD set_sorted_list_of_set sorted_list_of_set_eq_Nil_iff) next case 2 then show ?thesis by (metis enumK ab ba Inf_nat_def1 b_ne card_b_finite hd_b last_in_set less_asym less_setsD not_le set_sorted_list_of_set sorted_list_of_set_eq_Nil_iff) qed fix q assume "q < r" show "u \ b (enum L q) (r,q)" using l_cases proof cases case 1 then show ?thesis by (metis \q < r\ a_ne ab_enumL finite_a last_in_set leD less_setsD set_sorted_list_of_set sorted_list_of_set_eq_Nil_iff) next case 2 show ?thesis proof (cases "enum K i = enum L q") case True then show ?thesis using 2 bb_same [of concl: "enum L q" j i r q] \j < r\ apply (simp add: IJ_def pair_less_def less_sets_def) by (metis enumK b_ne card_b_finite last_in_set leD less_imp_le_nat set_sorted_list_of_set sorted_list_of_set_eq_Nil_iff) next case False with 2 bb enumK enumL show ?thesis unfolding less_sets_def by (metis \q < r\ b_ne card_b_finite last_in_set leD less_imp_le_nat list.set_sel(1) nat_neq_iff set_sorted_list_of_set sorted_list_of_set_eq_Nil_iff) qed qed qed - have u1_y: "less_sets (list.set u1) (list.set y)" + have u1_y: "list.set u1 \ list.set y" using vs yv_eq L \strict_sorted y\ merge merge_less_sets_hd merge_preserves seqs_ne ss_concat_jj us by fastforce have u1_subset_seqs: "list.set u1 \ list.set (concat (seqs j j K))" using merge_preserves [OF merge] us by auto - have "less_sets (b k (j,i)) (d (Suc k))" if "j\k" "i d (Suc k)" if "j\k" "ik" "i d k'" if "j\k" "i d (Suc k)" for k by (metis aM d_eq less_sets_fst_grab less_sets_weaken2 nxt_subset) - then have ad: "less_sets (a k) (d k')" if "k d k'" if "k list.set u1" for n proof - obtain l where l: "l \ list.set (seqs j j K)" and n: "n \ list.set l" using n u1_subset_seqs by auto then consider "l = list_of (a j)" | i where "l = list_of (b (enum K i) (j,i))" "i < j" by (force simp: seqs_def) then show ?thesis proof cases case 1 then show ?thesis by (metis Inf_nat_def1 \j < r\ ad d_ne finite_a less_setsD n set_sorted_list_of_set) next case 2 then have "Min (b (enum K i) (j,i)) \ n" using n by (simp add: less_list_def disjnt_iff less_sets_def) also have f8: "n < hd y" using less_setsD that u1_y by (metis gr_implies_not0 list.set_sel(1) list.size(3) xy) finally have "l < y" using 2 disjnt_hd_last_K_y [OF l] u1_y apply (simp add: less_list_def disjnt_iff) by (metis card_b_finite hd_list_of leI less_imp_le_nat list.set_sel(1)) moreover have "last (list_of (b (enum K i) (j,i))) < hd (list_of (a r))" using \l < y\ L n by (auto simp: 2yeq BB_eq_concat_seqs seqs_def less_list_def) then have "enum K i < r" by (metis "2"(1) a_ne ab card_b_finite empty_iff finite.emptyI finite_a last_in_set leI less_asym less_setsD list.set_sel(1) n set_sorted_list_of_set) moreover have "j \ enum K i" by (simp add: "2"(2) enumK less_imp_le_nat) ultimately show ?thesis using 2 n bd [of j "enum K i" i r] Inf_nat_def1 less_setsD by force qed qed then have "last u1 < Inf (d r)" using \uus \ []\ us_ne by auto also have "\ \ length v1" using card_a carda_v1 by auto finally have "last u1 < length v1" . then have "u1 < qs" by (simp add: qs_def acc_lengths.simps less_list_def) have "strict_sorted (interact (u1#us) (v1#vs))" using L \strict_sorted x\ \strict_sorted y\ merge merge_interact merge_preserves seqs_ne us vs xu_eq yv_eq by auto then have "strict_sorted (interact us vs)" "v1 < interact us vs" by (auto simp: strict_sorted_append_iff) moreover have "ps < u1 @ qs @ v1 @ interact us vs" using \ps < u1\ us_ne unfolding less_list_def by auto moreover have "u1 < qs @ v1 @ interact us vs" by (metis \u1 < qs\ \vvs \ []\ acc_lengths_eq_Nil_iff hd_append less_list_def qs_def vs) moreover have "qs < v1 @ interact us vs" using \qs < v1\ us_ne \last u1 < length v1\ vs_ne by (auto simp: less_list_def) ultimately show ?thesis by (simp add: zs_def strict_sorted_append_iff ssp ssq \strict_sorted u1\ \strict_sorted v1\) qed have ps_subset_d: "list.set ps \ d j" using K Ksub \_card \finite K\ acc_lengths_subset_d u_sub by blast have ps_less_u1: "ps < u1" proof - have "hd u1 = hd x" using us_ne by (auto simp: xu_eq) then have "hd u1 \ a j" by (simp add: xeq BB_eq_concat_seqs K seqs_def hd_append hd_list_of) - then have "less_sets (list.set ps) {hd u1}" + then have "list.set ps \ {hd u1}" by (metis da ps_subset_d less_sets_def singletonD subset_iff) then show ?thesis by (metis less_hd_imp_less list.set(2) empty_set less_sets_imp_list_less) qed have qs_subset_d: "list.set qs \ d r" using L Lsub \_card \finite L\ acc_lengths_subset_d v_sub by blast have qs_less_v1: "qs < v1" proof - have "hd v1 = hd y" using vs_ne by (auto simp: yv_eq) then have "hd v1 \ a r" by (simp add: yeq BB_eq_concat_seqs L seqs_def hd_append hd_list_of) - then have "less_sets (list.set qs) {hd v1}" + then have "list.set qs \ {hd v1}" by (metis da qs_subset_d less_sets_def singletonD subset_iff) then show ?thesis by (metis less_hd_imp_less list.set(2) empty_set less_sets_imp_list_less) qed have FB: "Form_Body ku kv x y zs" unfolding Form_Body.simps using ku_def kv_def ps_def qs_def ss us_ne vs_ne xu_eq xy yv_eq zs_def by blast then have "zs = (inter_scheme ((ku+kv) - Suc 0) {x,y})" by (simp add: Form_Body_imp_inter_scheme k) obtain l where "l \ 2 * (Suc j)" and l: "Form l U" and zs_eq_interact: "zs = inter_scheme l {x,y}" proof show "ku+kv-1 \ 2 * (Suc j)" using k by auto show "Form (ku+kv-1) U" proof (cases "ku=kv") case True then show ?thesis using FB Form.simps Ueq \0 < kv\ by (auto simp: mult_2) next case False then have "ku = Suc kv" using k by auto then show ?thesis using FB Form.simps Ueq \0 < kv\ by auto qed show "zs = inter_scheme (ku + kv - 1) {x, y}" using Form_Body_imp_inter_scheme by (simp add: FB k) qed then have "enum N l \ enum N (Suc (2 * Suc j))" by (simp add: assms less_imp_le_nat) also have "\ < Min (d j)" by (metis Min_in card_0_eq card_d d_eq finite_d fst_grab_subset greaterThan_iff in_mono le_inf_iff nxt_def old.nat.distinct(2)) - finally have ls: "less_sets {enum N l} (d j)" + finally have ls: "{enum N l} \ d j" by simp have "l > 0" by (metis l False Form_0_cases_raw Set.doubleton_eq_iff Ueq gr0I) show ?thesis unfolding Ueq proof (intro exI conjI impI) have zs_subset: "list.set zs \ list.set (acc_lengths 0 (seqs j j K)) \ list.set (acc_lengths 0 (seqs r r L)) \ list.set x \ list.set y" using u_sub v_sub by (auto simp: zs_def xu_eq yv_eq) also have "\ \ N" proof (simp, intro conjI) show "list.set (acc_lengths 0 (seqs j j K)) \ N" using d_subset_N Ksub \finite K\ \j \ card K\ acc_lengths_subset_d by blast show "list.set (acc_lengths 0 (seqs r r L)) \ N" using d_subset_N Lsub \finite L\ \r \ card L\ acc_lengths_subset_d by blast show "list.set x \ N" "list.set y \ N" by (simp_all add: xeq yeq BB_def a_subset_N UN_least b_subset_N) qed finally show "list.set (inter_scheme l {x, y}) \ N" using zs_eq_interact by blast have "[enum N l] < ps" using ps_subset_d ls by (metis empty_set less_sets_imp_list_less less_sets_weaken2 list.simps(15)) then show "[enum N l] < inter_scheme l {x, y}" by (simp add: zs_def less_list_def ps_def flip: zs_eq_interact) qed (use Ueq l in blast) qed qed qed subsection \The main partition theorem for @{term "\\\"}\ definition iso_ll where "iso_ll A B \ iso (lenlex less_than \ (A\A)) (lenlex less_than \ (B\B))" corollary ordertype_eq_ordertype_iso_ll: assumes "Field (Restr (lenlex less_than) A) = A" "Field (Restr (lenlex less_than) B) = B" shows "(ordertype A (lenlex less_than) = ordertype B (lenlex less_than)) \ (\f. iso_ll A B f)" proof - have "total_on A (lenlex less_than) \ total_on B (lenlex less_than)" by (meson UNIV_I total_lenlex total_on_def total_on_less_than) then show ?thesis by (simp add: assms wf_lenlex lenlex_transI iso_ll_def ordertype_eq_ordertype_iso_Restr) qed theorem partition_\\_aux: assumes "\ \ elts \" shows "partn_lst (lenlex less_than) WW [\\\,\] 2" (is "partn_lst ?R WW [\\\,\] 2") proof (cases "\ \ 1") case True then show ?thesis using strict_sorted_into_WW unfolding WW_def by (auto intro!: partn_lst_triv1[where i=1]) next case False obtain m where m: "\ = ord_of_nat m" using assms elts_\ by auto then have "m>1" using False by auto show ?thesis unfolding partn_lst_def proof clarsimp fix f assume f: "f \ [WW]\<^bsup>2\<^esup> \ {..: "?P0 \ ?P1" proof (rule disjCI) assume not1: "\ ?P1" have "\W'. ordertype W' ?R = \\n \ f ` [W']\<^bsup>2\<^esup> \ {0} \ W' \ WW_seg (n*m)" for n::nat proof - have fnm: "f \ [WW_seg (n*m)]\<^bsup>2\<^esup> \ {..\n, ord_of_nat m] 2" using ordertype_WW_seg [of "n*m"] by (simp add: partn_lst_VWF_imp_partn_lst [OF Theorem_3_2]) show ?thesis using partn_lst_E [OF * fnm, simplified] by (metis (no_types, hide_lams) One_nat_def Suc_1 WW_seg_subset_WW order.trans less_2_cases m not1 nth_Cons' nth_Cons_Suc) qed then obtain W':: "nat \ nat list set" where otW': "\n. ordertype (W' n) ?R = \\n" and f_W': "\n. f ` [W' n]\<^bsup>2\<^esup> \ {0}" and seg_W': "\n. W' n \ WW_seg (n*m)" by metis define WW' where "WW' \ (\n. W' n)" have "WW' \ WW" using seg_W' WW_seg_subset_WW by (force simp: WW'_def) with f have f': "f \ [WW']\<^bsup>2\<^esup> \ {..\\" proof (rule antisym) have "ordertype WW' ?R \ ordertype WW ?R" by (simp add: \WW' \ WW\ lenlex_transI ordertype_mono wf_lenlex) with ordertype_WW show "ordertype WW' ?R \ \ \ \" by simp have "\ \ n \ ordertype (\ (range W')) ?R" for n::nat by (metis TC_small UNIV_I UN_I otW' lenlex_transI ordertype_mono subsetI trans_less_than wf_lenlex wf_less_than) then show "\ \ \ \ ordertype WW' ?R" by (auto simp: elts_\ oexp_Limit ZFC_in_HOL.SUP_le_iff WW'_def) qed have FR_WW: "Field (Restr (lenlex less_than) WW) = WW" by (simp add: Limit_omega_oexp Limit_ordertype_imp_Field_Restr ordertype_WW) have FR_WW': "Field (Restr (lenlex less_than) WW') = WW'" by (simp add: Limit_omega_oexp Limit_ordertype_imp_Field_Restr ot') have FR_W: "Field (Restr (lenlex less_than) (WW_seg n)) = WW_seg n" if "n>0" for n by (simp add: Limit_omega_oexp ordertype_WW_seg that Limit_ordertype_imp_Field_Restr) have FR_W': "Field (Restr (lenlex less_than) (W' n)) = W' n" if "n>0" for n by (simp add: Limit_omega_oexp otW' that Limit_ordertype_imp_Field_Restr) have "\h. iso_ll (WW_seg n) (W' n) h" if "n>0" for n proof (subst ordertype_eq_ordertype_iso_ll [symmetric]) show "ordertype (WW_seg n) (lenlex less_than) = ordertype (W' n) (lenlex less_than)" by (simp add: ordertype_WW_seg otW') qed (auto simp: FR_W FR_W' that) then obtain h_seg where h_seg: "\n. n > 0 \ iso_ll (WW_seg n) (W' n) (h_seg n)" by metis define h where "h \ \l. if l=[] then [] else h_seg (length l) l" have bij_h_seg: "\n. n > 0 \ bij_betw (h_seg n) (WW_seg n) (W' n)" using h_seg by (simp add: iso_ll_def iso_iff2 FR_W FR_W') have len_h_seg: "length (h_seg (length l) l) = length l * m" if "length l > 0" "l \ WW" for l using bij_betwE [OF bij_h_seg] seg_W' that by (simp add: WW_seg_def subset_iff) have hlen: "length (h x) = length (h y) \ length x = length y" if "x \ WW" "y \ WW" for x y using that \1 < m\ h_def len_h_seg by force have h: "iso_ll WW WW' h" unfolding iso_ll_def iso_iff2 FR_WW FR_WW' proof (intro conjI strip) have W'_ne: "W' n \ {}" for n using otW' [of n] by auto then have "[] \ WW'" using seg_W' [of 0] by (auto simp: WW'_def WW_seg_def) let ?g = "\l. if l=[] then l else inv_into (WW_seg (length l div m)) (h_seg (length l div m)) l" have h_seg_iff: "\n a b. \a \ WW_seg n; b \ WW_seg n; n>0\ \ (a, b) \ lenlex less_than \ (h_seg n a, h_seg n b) \ lenlex less_than \ h_seg n a \ W' n \ h_seg n b \ W' n" using h_seg by (auto simp: iso_ll_def iso_iff2 FR_W FR_W') show "bij_betw h WW WW'" unfolding bij_betw_iff_bijections proof (intro exI conjI ballI) fix l assume "l \ WW" then have l: "l \ WW_seg (length l)" by (simp add: WW_seg_def) have "h l \ W' (length l)" proof (cases "l=[]") case True with seg_W' [of 0] W'_ne show ?thesis by (auto simp: WW_seg_def h_def) next case False then show ?thesis using bij_betwE bij_h_seg h_def l by fastforce qed show "h l \ WW'" using WW'_def \h l \ W' (length l)\ by blast show "?g (h l) = l" proof (cases "l=[]") case False then have "length l > 0" by auto then have "h_seg (length l) l \ []" using \1 < m\ \l \ WW\ len_h_seg by fastforce with \1 < m\ show ?thesis apply (simp add: h_def len_h_seg \l \ WW\) by (meson \0 < length l\ bij_betw_inv_into_left bij_h_seg l) qed (auto simp: h_def) next fix l assume "l \ WW'" then have l: "l \ W' (length l div m)" using WW_seg_def \1 < m\ seg_W' by (fastforce simp: WW'_def) show "?g l \ WW" proof (cases "l=[]") case False then have "l \ W' 0" using WW_seg_def seg_W' by fastforce with l have "inv_into (WW_seg (length l div m)) (h_seg (length l div m)) l \ WW_seg (length l div m)" by (metis Nat.neq0_conv bij_betwE bij_betw_inv_into bij_h_seg) then show ?thesis using False WW_seg_subset_WW by auto qed (auto simp: WW_def) show "h (?g l) = l" proof (cases "l=[]") case False then have "0 < length l div m" using WW_seg_def l seg_W' by fastforce then have "inv_into (WW_seg (length l div m)) (h_seg (length l div m)) l \ WW_seg (length l div m)" by (metis bij_betw_imp_surj_on bij_h_seg inv_into_into l) then show ?thesis using bij_h_seg [of "length l div m"] WW_seg_def \0 < length l div m\ bij_betw_inv_into_right l by (fastforce simp add: h_def) qed (auto simp: h_def) qed fix a b assume "a \ WW" "b \ WW" show "(a, b) \ Restr (lenlex less_than) WW \ (h a, h b) \ Restr (lenlex less_than) WW'" (is "?lhs = ?rhs") proof assume L: ?lhs then consider "length a < length b" | "length a = length b" "(a, b) \ lex less_than" by (auto simp: lenlex_conv) then show ?rhs proof cases case 1 then have "length (h a) < length (h b)" using \1 < m\ \a \ WW\ \b \ WW\ h_def len_h_seg by auto then have "(h a, h b) \ lenlex less_than" by (auto simp: lenlex_conv) then show ?thesis using \a \ WW\ \b \ WW\ \bij_betw h WW WW'\ bij_betwE by fastforce next case 2 then have ab: "a \ WW_seg (length a)" "b \ WW_seg (length a)" using \a \ WW\ \b \ WW\ by (auto simp: WW_seg_def) have "length (h a) = length (h b)" using 2 \a \ WW\ \b \ WW\ h_def len_h_seg by force moreover have "(a, b) \ lenlex less_than" using L by blast then have "(h_seg (length a) a, h_seg (length a) b) \ lenlex less_than" using 2 ab h_seg_iff by blast ultimately show ?thesis using 2 \a \ WW\ \b \ WW\ \bij_betw h WW WW'\ bij_betwE h_def by fastforce qed next assume R: ?rhs then have R': "(h a, h b) \ lenlex less_than" by blast then consider "length a < length b" | "length a = length b" "(h a, h b) \ lex less_than" using \a \ WW\ \b \ WW\ \m > 1\ by (auto simp: lenlex_conv h_def len_h_seg split: if_split_asm) then show ?lhs proof cases case 1 then have "(a, b) \ lenlex less_than" using omega_sum_less_iff by auto then show ?thesis by (simp add: \a \ WW\ \b \ WW\) next case 2 then have ab: "a \ WW_seg (length a)" "b \ WW_seg (length a)" using \a \ WW\ \b \ WW\ by (auto simp: WW_seg_def) then have "(a, b) \ lenlex less_than" using bij_betwE [OF bij_h_seg] \a \ WW\ \b \ WW\ R' 2 by (simp add: h_def h_seg_iff split: if_split_asm) then show ?thesis using \a \ WW\ \b \ WW\ by blast qed qed qed let ?fh = "f \ image h" have "bij_betw h WW WW'" using h unfolding iso_ll_def iso_iff2 by (fastforce simp: FR_WW FR_WW') moreover have "{.. [WW]\<^bsup>2\<^esup> \ {0,1}" unfolding Pi_iff using bij_betwE f' bij_betw_nsets by (metis PiE comp_apply) have "f{x,y} = 0" if "x \ WW'" "y \ WW'" "length x = length y" "x \ y" for x y proof - obtain p q where "x \ W' p" and "y \ W' q" using WW'_def \x \ WW'\ \y \ WW'\ by blast then obtain n where "{x,y} \ [W' n]\<^bsup>2\<^esup>" using seg_W' \1 < m\ \length x = length y\ \x \ y\ by (auto simp: WW'_def WW_seg_def subset_iff) then show "f{x,y} = 0" using f_W' by blast qed then have fh_eq_0_eqlen: "?fh{x,y} = 0" if "x \ WW" "y \ WW" "length x = length y" "x \ y" for x y using \bij_betw h WW WW'\ that hlen by (simp add: bij_betw_iff_bijections) metis have m_f_0: "\x\[M]\<^bsup>2\<^esup>. f x = 0" if "M \ WW" "card M = m" for M proof - have "finite M" using False m that by auto with not1 [simplified, rule_format, of M] f show ?thesis using that \1 < m\ apply (simp add: Pi_iff image_subset_iff finite_ordertype_eq_card m) by (metis less_2_cases nsets_mono numeral_2_eq_2 subset_iff) qed have m_fh_0: "\x\[M]\<^bsup>2\<^esup>. ?fh x = 0" if "M \ WW" "card M = m" for M proof - have "h ` M \ WW" using \WW' \ WW\ \bij_betw h WW WW'\ bij_betwE that(1) by fastforce moreover have "card (h ` M) = m" by (metis \bij_betw h WW WW'\ bij_betw_def bij_betw_subset card_image that) ultimately have "\x \ [h ` M]\<^bsup>2\<^esup>. f x = 0" by (metis m_f_0) then obtain Y where "f (h ` Y) = 0" "finite Y" "card Y = 2" "Y \ M" apply (simp add: nsets_def subset_image_iff) by (metis \M \ WW\ \bij_betw h WW WW'\ bij_betw_def card_image card.infinite inj_on_subset zero_neq_numeral) then show ?thesis by (auto simp: nsets_def) qed obtain N j where "infinite N" and N: "\k u. \k > 0; u \ [WW]\<^bsup>2\<^esup>; Form k u; [enum N k] < inter_scheme k u; List.set (inter_scheme k u) \ N\ \ ?fh u = j k" using lemma_3_6 [OF fh] by blast have infN': "infinite (enum N ` {k<..})" for k by (simp add: \infinite N\ enum_works finite_image_iff infinite_Ioi strict_mono_imp_inj_on) have j_0: "j k = 0" if "k>0" for k proof - obtain M where M: "M \ [WW]\<^bsup>m\<^esup>" and MF: "\u. u \ [M]\<^bsup>2\<^esup> \ Form k u" and Mi: "\u. u \ [M]\<^bsup>2\<^esup> \ List.set (inter_scheme k u) \ enum N ` {k<..}" using lemma_3_7 [OF infN' \k > 0\] by metis obtain u where u: "u \ [M]\<^bsup>2\<^esup>" "?fh u = 0" using m_fh_0 [of M] M [unfolded nsets_def] by force moreover have \
: "Form k u" "List.set (inter_scheme k u) \ enum N ` {k<..}" by (simp_all add: MF Mi \u \ [M]\<^bsup>2\<^esup>\) moreover have "u \ [WW]\<^bsup>2\<^esup>" using M u by (auto simp: nsets_def) moreover have "enum N ` {k<..} \ N" using \infinite N\ range_enum by auto moreover have "[enum N k] < inter_scheme k u" using inter_scheme [of k u] strict_mono_enum [OF \infinite N\] \
apply (auto simp: less_list_def subset_image_iff subset_eq Bex_def image_iff) by (metis hd_in_set strict_mono_def) ultimately show ?thesis using N that by auto qed obtain X where "X \ WW" and otX: "ordertype X (lenlex less_than) = \\\" and X: "\u. u \ [X]\<^bsup>2\<^esup> \ \l. Form l u \ (l > 0 \ [enum N l] < inter_scheme l u \ List.set (inter_scheme l u) \ N)" using lemma_3_8 [OF \infinite N\] ot' by blast have 0: "?fh ` [X]\<^bsup>2\<^esup> \ {0}" proof clarsimp fix u assume u: "u \ [X]\<^bsup>2\<^esup>" obtain l where "Form l u" and l: "l > 0 \ [enum N l] < inter_scheme l u \ List.set (inter_scheme l u) \ N" using u X by blast have "?fh u = 0" proof (cases "l > 0") case False then have "l = 0" by blast then show ?thesis by (metis Form_0_cases_raw \Form l u\ \X \ WW\ doubleton_in_nsets_2 fh_eq_0_eqlen subset_iff u) next case True then obtain "[enum N l] < inter_scheme l u" "List.set (inter_scheme l u) \ N" "j l = 0" using Nat.neq0_conv j_0 l by blast with True show ?thesis using \X \ WW\ N inter_scheme \Form l u\ doubleton_in_nsets_2 u by (auto simp: nsets_def) qed then show "f (h ` u) = 0" by auto qed show ?P0 proof (intro exI conjI) show "h ` X \ WW" using \WW' \ WW\ \X \ WW\ \bij_betw h WW WW'\ bij_betw_imp_surj_on by fastforce show "ordertype (h ` X) (lenlex less_than) = \ \ \" proof (subst ordertype_inc_eq) show "(h x, h y) \ lenlex less_than" if "x \ X" "y \ X" "(x, y) \ lenlex less_than" for x y using that h \X \ WW\ by (auto simp: FR_WW FR_WW' iso_iff2 iso_ll_def) qed (use otX in auto) show "f ` [h ` X]\<^bsup>2\<^esup> \ {0}" proof (clarsimp simp: image_subset_iff nsets_def) fix Y assume "Y \ h ` X" and "finite Y" and "card Y = 2" have "inv_into WW h ` Y \ X" using \X \ WW\ \Y \ h ` X\ \bij_betw h WW WW'\ bij_betw_inv_into_LEFT by blast moreover have "finite (inv_into WW h ` Y)" using \finite Y\ by blast moreover have "card (inv_into WW h ` Y) = 2" by (metis \X \ WW\ \Y \ h ` X\ \card Y = 2\ card_image inj_on_inv_into subset_image_iff subset_trans) ultimately have "f (h ` inv_into WW h ` Y) = 0" using 0 by (auto simp: image_subset_iff nsets_def) then show "f Y = 0" by (metis \X \ WW\ \Y \ h ` X\ image_inv_into_cancel image_mono order_trans) qed qed qed then show "\iH\WW. ordertype H ?R = [\\\, \] ! i \ f ` [H]\<^bsup>2\<^esup> \ {i}" by (metis One_nat_def lessI nth_Cons_0 nth_Cons_Suc zero_less_Suc) qed qed text \Theorem 3.1 of Jean A. Larson, ibid.\ theorem partition_\\: "\ \ elts \ \ partn_lst_VWF (\\\) [\\\,\] 2" using partn_lst_imp_partn_lst_VWF_eq [OF partition_\\_aux] ordertype_WW by auto end diff --git a/thys/Ordinal_Partitions/Partitions.thy b/thys/Ordinal_Partitions/Partitions.thy --- a/thys/Ordinal_Partitions/Partitions.thy +++ b/thys/Ordinal_Partitions/Partitions.thy @@ -1,938 +1,938 @@ section \Ordinal Partitions\ text \Material from Jean A. Larson, A short proof of a partition theorem for the ordinal $\omega^\omega$. \emph{Annals of Mathematical Logic}, 6:129–-145, 1973. Also from ``Partition Relations'' by A. Hajnal and J. A. Larson, in \emph{Handbook of Set Theory}, edited by Matthew Foreman and Akihiro Kanamori (Springer, 2010).\ theory Partitions imports Library_Additions "ZFC_in_HOL.ZFC_Typeclasses" "ZFC_in_HOL.Cantor_NF" begin abbreviation tp :: "V set \ V" where "tp A \ ordertype A VWF" subsection \Ordinal Partitions: Definitions\ definition partn_lst :: "[('a \ 'a) set, 'a set, V list, nat] \ bool" - where "partn_lst r B \ n \ \f \ nsets B n \ {..}. + where "partn_lst r B \ n \ \f \ [B]\<^bsup>n\<^esup> \ {..}. \i < length \. \H. H \ B \ ordertype H r = (\!i) \ f ` (nsets H n) \ {i}" abbreviation partn_lst_VWF :: "V \ V list \ nat \ bool" where "partn_lst_VWF \ \ partn_lst VWF (elts \)" lemma partn_lst_E: assumes "partn_lst r B \ n" "f \ nsets B n \ {.." obtains i H where "i < l" "H \ B" "ordertype H r = \!i" "f ` (nsets H n) \ {i}" using assms by (auto simp: partn_lst_def) lemma partn_lst_VWF_nontriv: assumes "partn_lst_VWF \ \ n" "l = length \" "Ord \" "l > 0" obtains i where "i < l" "\!i \ \" proof - have "{.. {}" by (simp add: \l > 0\ lessThan_empty_iff) then obtain f where "f \ nsets (elts \) n \ {.. elts \" and eq: "tp H = \!i" using assms by (metis partn_lst_E) then have "\!i \ \" by (metis \H \ elts \\ \Ord \\ eq ordertype_le_Ord) then show thesis using \i < l\ that by auto qed lemma partn_lst_triv0: assumes "\!i = 0" "i < length \" "n \ 0" shows "partn_lst r B \ n" by (metis partn_lst_def assms bot_least image_empty nsets_empty_iff ordertype_empty) lemma partn_lst_triv1: assumes "\!i \ 1" "i < length \" "n > 1" "B \ {}" "wf r" shows "partn_lst r B \ n" unfolding partn_lst_def proof clarsimp obtain \ where "\ \ B" "\ \ []" using assms mem_0_Ord by fastforce have 01: "\!i = 0 \ \!i = 1" using assms by (fastforce simp: one_V_def) fix f assume f: "f \ [B]\<^bsup>n\<^esup> \ {..}" with assms have "ordertype {\} r = 1 \ f ` [{\}]\<^bsup>n\<^esup> \ {i}" "ordertype {} r = 0 \ f ` [{}]\<^bsup>n\<^esup> \ {i}" by (auto simp: one_V_def ordertype_insert nsets_eq_empty) with assms 01 show "\i. \H\B. ordertype H r = \ ! i \ f ` [H]\<^bsup>n\<^esup> \ {i}" using \\ \ B\ by auto qed lemma partn_lst_two_swap: assumes "partn_lst r B [x,y] n" shows "partn_lst r B [y,x] n" proof - { fix f :: "'a set \ nat" assume f: "f \ [B]\<^bsup>n\<^esup> \ {..<2}" then have f': "(\i. 1 - i) \ f \ [B]\<^bsup>n\<^esup> \ {..<2}" by (auto simp: Pi_def) obtain i H where "i<2" "H \ B" "ordertype H r = ([x,y]!i)" "((\i. 1 - i) \ f) ` (nsets H n) \ {i}" by (auto intro: partn_lst_E [OF assms f']) moreover have "f x = Suc 0" if "Suc 0 \ f x" "x\[H]\<^bsup>n\<^esup>" for x using f that \H \ B\ nsets_mono by (fastforce simp: Pi_iff) ultimately have "ordertype H r = [y,x] ! (1-i) \ f ` [H]\<^bsup>n\<^esup> \ {1-i}" by (force simp: eval_nat_numeral less_Suc_eq) then have "\i H. i<2 \ H\B \ ordertype H r = [y,x] ! i \ f ` [H]\<^bsup>n\<^esup> \ {i}" by (metis Suc_1 \H \ B\ diff_less_Suc) } then show ?thesis by (auto simp: partn_lst_def eval_nat_numeral) qed lemma partn_lst_greater_resource: assumes M: "partn_lst r B \ n" and "B \ C" shows "partn_lst r C \ n" proof (clarsimp simp: partn_lst_def) fix f assume "f \ [C]\<^bsup>n\<^esup> \ {..}" then have "f \ [B]\<^bsup>n\<^esup> \ {..}" by (metis \B \ C\ part_fn_def part_fn_subset) then obtain i H where "i < length \" and "H \ B" "ordertype H r = (\!i)" and "f ` nsets H n \ {i}" using M partn_lst_def by metis then show "\i. \H\C. ordertype H r = \ ! i \ f ` [H]\<^bsup>n\<^esup> \ {i}" using \B \ C\ by blast qed lemma partn_lst_less: assumes M: "partn_lst r B \ n" and eq: "length \' = length \" and "List.set \' \ ON" and le: "\i. i < length \ \ \'!i \ \!i " and r: "wf r" "trans r" "total_on B r" and "small B" shows "partn_lst r B \' n" proof (clarsimp simp: partn_lst_def) fix f assume "f \ [B]\<^bsup>n\<^esup> \ {..'}" then obtain i H where "i < length \" and "H \ B" "small H" and H: "ordertype H r = (\!i)" and fi: "f ` nsets H n \ {i}" using assms by (auto simp: partn_lst_def smaller_than_small) then have bij: "bij_betw (ordermap H r) H (elts (\!i))" using ordermap_bij [of r H] by (smt assms(8) in_mono r(1) r(3) smaller_than_small total_on_def) define H' where "H' = inv_into H (ordermap H r) ` (elts (\'!i))" have "H' \ H" using bij \i < length \\ bij_betw_imp_surj_on le by (force simp: H'_def image_subset_iff intro: inv_into_into) moreover have ot: "ordertype H' r = (\'!i)" proof (subst ordertype_eq_iff) show "Ord (\' ! i)" using assms by (simp add: \i < length \\ subset_eq) show "small H'" by (simp add: H'_def) show "\f. bij_betw f H' (elts (\' ! i)) \ (\x\H'. \y\H'. (f x < f y) = ((x, y) \ r))" proof (intro exI conjI ballI) show "bij_betw (ordermap H r) H' (elts (\' ! i))" using \H' \ H\ by (metis H'_def \i < length \\ bij bij_betw_inv_into_RIGHT bij_betw_subset le less_eq_V_def) show "(ordermap H r x < ordermap H r y) = ((x, y) \ r)" if "x \ H'" "y \ H'" for x y proof (intro iffI ordermap_mono_less) assume "ordermap H r x < ordermap H r y" then show "(x, y) \ r" by (metis \H \ B\ assms(8) calculation in_mono leD ordermap_mono_le r smaller_than_small that total_on_def) qed (use assms that \H' \ H\ \small H\ in auto) qed show "total_on H' r" using r by (meson \H \ B\ \H' \ H\ subsetD total_on_def) qed (use r in auto) ultimately show "\i'. \H\B. ordertype H r = \' ! i \ f ` [H]\<^bsup>n\<^esup> \ {i}" using \H \ B\ \i < length \\ fi assms by (metis image_mono nsets_mono subset_trans) qed text \Holds because no $n$-sets exist!\ lemma partn_lst_VWF_degenerate: assumes "k < n" shows "partn_lst_VWF \ (ord_of_nat k # \s) n" proof (clarsimp simp: partn_lst_def) fix f :: "V set \ nat" have "[elts (ord_of_nat k)]\<^bsup>n\<^esup> = {}" by (simp add: nsets_eq_empty assms finite_Ord_omega) then have "f ` [elts (ord_of_nat k)]\<^bsup>n\<^esup> \ {0}" by auto then show "\i < Suc (length \s). \H\elts \. tp H = (ord_of_nat k # \s) ! i \ f ` [H]\<^bsup>n\<^esup> \ {i}" using assms ordertype_eq_Ord [of "ord_of_nat k"] elts_ord_of_nat less_Suc_eq_0_disj by fastforce qed lemma partn_lst_VWF_\_2: assumes "Ord \" shows "partn_lst_VWF (\ \ (1+\)) [2, \ \ (1+\)] 2" (is "partn_lst_VWF ?\ _ _") proof (clarsimp simp: partn_lst_def) fix f assume f: "f \ [elts ?\]\<^bsup>2\<^esup> \ {..iH\elts ?\. tp H = [2, ?\] ! i \ f ` [H]\<^bsup>2\<^esup> \ {i}" proof (cases "\x \ elts ?\. \y \ elts ?\. x \ y \ f{x,y} = 0") case True then obtain x y where "x \ elts ?\" "y \ elts ?\" "x \ y" "f {x, y} = 0" by auto then have "{x,y} \ elts ?\" "tp {x,y} = 2" "f ` [{x, y}]\<^bsup>2\<^esup> \ {0}" by auto (simp add: eval_nat_numeral ordertype_VWF_finite_nat) with \x \ y\ show ?thesis by (metis nth_Cons_0 zero_less_Suc) next case False with f have "\x\elts ?\. \y\elts ?\. x \ y \ f {x, y} = 1" unfolding Pi_iff using lessThan_Suc by force then have "tp (elts ?\) = ?\" "f ` [elts ?\]\<^bsup>2\<^esup> \ {Suc 0}" by (auto simp: assms nsets_2_eq) then show ?thesis by (metis lessI nth_Cons_0 nth_Cons_Suc subsetI) qed qed subsection \Relating partition properties on @{term VWF} to the general case\ text \Two very similar proofs here!\ lemma partn_lst_imp_partn_lst_VWF_eq: assumes part: "partn_lst r U \ n" and \: "ordertype U r = \" "small U" and r: "wf r" "trans r" "total_on U r" shows "partn_lst_VWF \ \ n" unfolding partn_lst_def proof clarsimp fix f assume f: "f \ [elts \]\<^bsup>n\<^esup> \ {..}" define cv where "cv \ \X. ordermap U r ` X" have bij: "bij_betw (ordermap U r) U (elts \)" using ordermap_bij [of "r" U] assms by blast then have bij_cv: "bij_betw cv ([U]\<^bsup>n\<^esup>) ([elts \]\<^bsup>n\<^esup>)" using bij_betw_nsets cv_def by blast then have func: "f \ cv \ [U]\<^bsup>n\<^esup> \ {..}" and "inj_on (ordermap U r) U" using bij bij_betw_def bij_betw_apply f by fastforce+ then have cv_part: "\\x\[X]\<^bsup>n\<^esup>. f (cv x) = i; X \ U; a \ [cv X]\<^bsup>n\<^esup>\ \ f a = i" for a X i n by (force simp: cv_def nsets_def subset_image_iff inj_on_subset finite_image_iff card_image) have ot_eq [simp]: "tp (cv X) = ordertype X r" if "X \ U" for X unfolding cv_def proof (rule ordertype_inc_eq) fix u v assume "u \ X" "v \ X" and "(u,v) \ r" with that have "ordermap U r u < ordermap U r v" by (simp add: assms ordermap_mono_less subset_eq) then show "(ordermap U r u, ordermap U r v) \ VWF" by (simp add: r) next show "total_on X r" using that r by (auto simp: total_on_def) show "small X" by (meson \small U\ smaller_than_small that) qed (use assms in auto) obtain X i where "X \ U" and X: "ordertype X r = \!i" "(f \ cv) ` [X]\<^bsup>n\<^esup> \ {i}" and "i < length \" using part func by (auto simp: partn_lst_def) show "\i < length \. \H\elts \. tp H = \!i \ f ` [H]\<^bsup>n\<^esup> \ {i}" proof (intro exI conjI) show "i < length \" by (simp add: \i < length \\) show "cv X \ elts \" using \X \ U\ bij bij_betw_imp_surj_on cv_def by blast show "tp (cv X) = \ ! i" by (simp add: X(1) \X \ U\) show "f ` [cv X]\<^bsup>n\<^esup> \ {i}" using X \X \ U\ cv_part unfolding image_subset_iff cv_def by (metis comp_apply insertCI singletonD) qed qed lemma partn_lst_imp_partn_lst_VWF: assumes part: "partn_lst r U \ n" and \: "ordertype U r \ \" "small U" and r: "wf r" "trans r" "total_on U r" shows "partn_lst_VWF \ \ n" by (metis assms less_eq_V_def partn_lst_imp_partn_lst_VWF_eq partn_lst_greater_resource) lemma partn_lst_VWF_imp_partn_lst_eq: assumes part: "partn_lst_VWF \ \ n" and \: "ordertype U r = \" "small U" and r: "wf r" "trans r" "total_on U r" shows "partn_lst r U \ n" unfolding partn_lst_def proof clarsimp fix f assume f: "f \ [U]\<^bsup>n\<^esup> \ {..}" define cv where "cv \ \X. inv_into U (ordermap U r) ` X" have bij: "bij_betw (ordermap U r) U (elts \)" using ordermap_bij [of "r" U] assms by blast then have bij_cv: "bij_betw cv ([elts \]\<^bsup>n\<^esup>) ([U]\<^bsup>n\<^esup>)" using bij_betw_nsets bij_betw_inv_into unfolding cv_def by blast then have func: "f \ cv \ [elts \]\<^bsup>n\<^esup> \ {..}" using bij_betw_apply f by fastforce have "inj_on (ordermap U r) U" using bij bij_betw_def by blast then have cv_part: "\\x\[X]\<^bsup>n\<^esup>. f (cv x) = i; X \ elts \; a \ [cv X]\<^bsup>n\<^esup>\ \ f a = i" for a X i n apply ( simp add: cv_def nsets_def subset_image_iff inj_on_subset finite_image_iff card_image) by (metis bij bij_betw_def card_image inj_on_finite inj_on_inv_into subset_eq) have ot_eq [simp]: "ordertype (cv X) r = tp X" if "X \ elts \" for X unfolding cv_def proof (rule ordertype_inc_eq) show "small X" using down that by auto show "(inv_into U (ordermap U r) x, inv_into U (ordermap U r) y) \ r" if "x \ X" "y \ X" and "(x,y) \ VWF" for x y proof - have xy: "x \ ordermap U r ` U" "y \ ordermap U r ` U" using \X \ elts \\ \x \ X\ \y \ X\ bij bij_betw_imp_surj_on by blast+ then have eq: "ordermap U r (inv_into U (ordermap U r) x) = x" "ordermap U r (inv_into U (ordermap U r) y) = y" by (meson f_inv_into_f)+ then have "y \ elts x" by (metis (no_types) VWF_non_refl mem_imp_VWF that(3) trans_VWF trans_def) then show ?thesis by (metis (no_types) VWF_non_refl xy eq assms(3) inv_into_into ordermap_mono r(1) r(3) that(3) total_on_def) qed qed (use r in auto) obtain X i where "X \ elts \" and X: "tp X = \!i" "(f \ cv) ` [X]\<^bsup>n\<^esup> \ {i}" and "i < length \" using part func by (auto simp: partn_lst_def) show "\i < length \. \H\U. ordertype H r = \!i \ f ` [H]\<^bsup>n\<^esup> \ {i}" proof (intro exI conjI) show "i < length \" by (simp add: \i < length \\) show "cv X \ U" using \X \ elts \\ bij bij_betw_imp_surj_on bij_betw_inv_into cv_def by blast show "ordertype (cv X) r = \ ! i" by (simp add: X(1) \X \ elts \\) show "f ` [cv X]\<^bsup>n\<^esup> \ {i}" using X \X \ elts \\ cv_part unfolding image_subset_iff cv_def by (metis comp_apply insertCI singletonD) qed qed corollary partn_lst_VWF_imp_partn_lst: assumes "partn_lst_VWF \ \ n" and \: "ordertype U r \ \" "small U" "wf r" "trans r" "total_on U r" shows "partn_lst r U \ n" by (metis assms less_eq_V_def partn_lst_VWF_imp_partn_lst_eq partn_lst_greater_resource) subsection \Simple consequences of the definitions\ text \A restatement of the infinite Ramsey theorem using partition notation\ lemma Ramsey_partn: "partn_lst_VWF \ [\,\] 2" proof (clarsimp simp: partn_lst_def) fix f assume "f \ [elts \]\<^bsup>2\<^esup> \ {..x\elts \. \y\elts \. x \ y \ f {x, y} < 2" by (auto simp: nsets_def eval_nat_numeral) obtain H i where H: "H \ elts \" and "infinite H" and t: "i < Suc (Suc 0)" and teq: "\x\H. \y\H. x \ y \ f {x, y} = i" using Ramsey2 [OF infinite_\ *] by (auto simp: eval_nat_numeral) then have "tp H = [\, \] ! i" using less_2_cases eval_nat_numeral ordertype_infinite_\ by force moreover have "f ` {N. N \ H \ finite N \ card N = 2} \ {i}" by (force simp: teq card_2_iff) ultimately have "f ` [H]\<^bsup>2\<^esup> \ {i}" by (metis (no_types) nsets_def numeral_2_eq_2) then show "\iH\elts \. tp H = [\,\] ! i \ f ` [H]\<^bsup>2\<^esup> \ {i}" using H \tp H = [\, \] ! i\ t by blast qed text \This is the counterexample sketched in Hajnal and Larson, section 9.1.\ proposition omega_basic_counterexample: assumes "Ord \" shows "\ partn_lst_VWF \ [succ (vcard \), \] 2" proof - obtain \ where fun\: "\ \ elts \ \ elts (vcard \)" and inj\: "inj_on \ (elts \)" using inj_into_vcard by auto have Ord\: "Ord (\ x)" if "x \ elts \" for x using Ord_in_Ord fun\ that by fastforce define f where "f A \ @i::nat. \x y. A = {x,y} \ x < y \ (\ x < \ y \ i=0 \ \ y < \ x \ i=1)" for A have f_Pi: "f \ [elts \]\<^bsup>2\<^esup> \ {.. [elts \]\<^bsup>2\<^esup>" then obtain x y where xy: "x \ elts \" "y \ elts \" "x < y" and A: "A = {x,y}" apply (clarsimp simp: nsets_2_eq) by (metis Ord_in_Ord Ord_linear_lt assms insert_commute) consider "\ x < \ y" | "\ y < \ x" by (metis Ord\ Ord_linear_lt inj\ inj_onD less_imp_not_eq2 xy) then show "f A \ {..x < y\ A exE_some [OF _ f_def]) qed have fiff: "\ x < \ y \ i=0 \ \ y < \ x \ i=1" if f: "f {x,y} = i" and xy: "x \ elts \" "y \ elts \" "x x < \ y" | "\ y < \ x" using xy by (metis Ord\ Ord_linear_lt inj\ inj_onD less_V_def) then show ?thesis proof cases case 1 then have "f{x,y} = 0" using \x by (force simp: f_def Set.doubleton_eq_iff) then show ?thesis using "1" f by auto next case 2 then have "f{x,y} = 1" using \x by (force simp: f_def Set.doubleton_eq_iff) then show ?thesis using "2" f by auto qed qed have False if eq: "tp H = succ (vcard \)" and H: "H \ elts \" and 0: "\A. A \ [H]\<^bsup>2\<^esup> \ f A = 0" for H proof - have [simp]: "small H" using H down by auto have OH: "Ord x" if "x \ H" for x using H Ord_in_Ord \Ord \\ that by blast have \: "\ x < \ y" if "x\H" "y\H" "x ` H \ elts (vcard \)" using H fun\ by auto have "tp H = tp (\ ` H)" proof (rule ordertype_VWF_inc_eq [symmetric]) show "\ ` H \ ON" using H Ord\ by blast qed (auto simp: \ OH subsetI) also have "\ \ vcard \" by (simp add: H sub_vcard assms ordertype_le_Ord) finally show False by (simp add: eq succ_le_iff) qed moreover have False if eq: "tp H = \" and H: "H \ elts \" and 1: "\A. A \ [H]\<^bsup>2\<^esup> \ f A = Suc 0" for H proof - have [simp]: "small H" using H down by auto define \ where "\ \ inv_into H (ordermap H VWF) \ ord_of_nat" have bij: "bij_betw (ordermap H VWF) H (elts \)" by (metis ordermap_bij \small H\ eq total_on_VWF wf_VWF) then have "bij_betw (inv_into H (ordermap H VWF)) (elts \) H" by (simp add: bij_betw_inv_into) then have \: "bij_betw \ UNIV H" unfolding \_def by (metis \_def bij_betw_comp_iff2 bij_betw_def elts_of_set inf inj_ord_of_nat order_refl) have Ord\: "Ord (\ k)" for k by (meson H Ord_in_Ord UNIV_I \ assms bij_betw_apply subsetD) obtain k where k: "((\ \ \)(Suc k), (\ \ \) k) \ VWF" using wf_VWF wf_iff_no_infinite_down_chain by blast have \: "\ y < \ x" if "x\H" "y\H" "x (Suc k) \ \ k" proof - have "(\ (Suc k), \ k) \ VWF \ \ (Suc k) = \ k" using that Ord\ Ord_mem_iff_lt by auto then have "ordermap H VWF (\ (Suc k)) \ ordermap H VWF (\ k)" by (metis \ \small H\ bij_betw_imp_surj_on ordermap_mono_le rangeI trans_VWF wf_VWF) moreover have "ordermap H VWF (\ (Suc k)) = succ (ord_of_nat k)" unfolding \_def using bij bij_betw_inv_into_right by force moreover have "ordermap H VWF (\ k) = ord_of_nat k" apply (simp add: \_def) by (meson bij bij_betw_inv_into_right ord_of_nat_\) ultimately have "succ (ord_of_nat k) \ ord_of_nat k" by simp then show False by (simp add: less_eq_V_def) qed then have "\ k < \ (Suc k)" by (metis Ord\ Ord_linear_lt dual_order.strict_implies_order eq_refl) then have "(\ \ \)(Suc k) < (\ \ \)k" using \ \ bij_betw_apply by force then show False using k apply (simp add: subset_iff) by (metis H Ord\ UNIV_I VWF_iff_Ord_less \ bij_betw_imp_surj_on image_subset_iff) qed ultimately show ?thesis apply (simp add: partn_lst_def image_subset_iff) by (metis f_Pi less_2_cases nth_Cons_0 nth_Cons_Suc numeral_2_eq_2) qed subsection \Specker's theorem\ definition form_split :: "[nat,nat,nat,nat,nat] \ bool" where "form_split a b c d i \ a \ c \ (i=0 \ a b c i=1 \ a c b i=2 \ a c d i=3 \ a=c \ b\d)" definition form :: "[(nat*nat)set, nat] \ bool" where "form u i \ \a b c d. u = {(a,b),(c,d)} \ form_split a b c d i" definition scheme :: "[(nat*nat)set] \ nat set" where "scheme u \ fst ` u \ snd ` u" definition UU :: "(nat*nat) set" where "UU \ {(a,b). a < b}" lemma ordertype_UNIV_\2: "ordertype UNIV pair_less = \\2" using ordertype_Times [of concl: UNIV UNIV less_than less_than] by (simp add: total_less_than pair_less_def ordertype_nat_\ numeral_2_eq_2) lemma ordertype_UU_ge_\2: "ordertype UNIV pair_less \ ordertype UU pair_less" proof (rule ordertype_inc_le) define \ where "\ \ \(m,n). (m, Suc (m+n))" show "(\ (x::nat \ nat), \ y) \ pair_less" if "(x, y) \ pair_less" for x y using that by (auto simp: \_def pair_less_def split: prod.split) show "range \ \ UU" by (auto simp: \_def UU_def) qed auto lemma ordertype_UU_\2: "ordertype UU pair_less = \\2" by (metis eq_iff ordertype_UNIV_\2 ordertype_UU_ge_\2 ordertype_mono small top_greatest trans_pair_less wf_pair_less) text \Lemma 2.3 of Jean A. Larson, A short proof of a partition theorem for the ordinal $\omega^\omega$. \emph{Annals of Mathematical Logic}, 6:129–-145, 1973.\ lemma lemma_2_3: fixes f :: "(nat \ nat) set \ nat" assumes "f \ [UU]\<^bsup>2\<^esup> \ {..k u. \k < 4; u \ [UU]\<^bsup>2\<^esup>; form u k; scheme u \ N\ \ f u = js!k" proof - have f_less2: "f {p,q} < Suc (Suc 0)" if "p \ q" "p \ UU" "q \ UU" for p q proof - have "{p,q} \ [UU]\<^bsup>2\<^esup>" using that by (simp add: nsets_def) then show ?thesis using assms by (simp add: Pi_iff) qed define f0 where "f0 \ (\A::nat set. THE x. \a b c d. A = {a,b,c,d} \ a b c x = f {(a,b),(c,d)})" have f0: "f0 {a,b,c,d} = f {(a,b),(c,d)}" if "a [X]\<^bsup>4\<^esup>" using that by (auto simp: nsets_def) then obtain a b c d where "X = {a,b,c,d} \ a b cN t. infinite N \ t < Suc (Suc 0) \ (\X. X \ N \ finite X \ card X = 4 \ f0 X = t)" using Ramsey [of UNIV 4 f0 2] by (simp add: eval_nat_numeral) then obtain N0 j0 where "infinite N0" and j0: "j0 < Suc (Suc 0)" and N0: "\A. A \ [N0]\<^bsup>4\<^esup> \ f0 A = j0" by (auto simp: nsets_def) define f1 where "f1 \ (\A::nat set. THE x. \a b c d. A = {a,b,c,d} \ a b c x = f {(a,c),(b,d)})" have f1: "f1 {a,b,c,d} = f {(a,c),(b,d)}" if "a [X]\<^bsup>4\<^esup>" using that by (auto simp: nsets_def) then obtain a b c d where "X = {a,b,c,d} \ a b cN t. N \ N0 \ infinite N \ t < Suc (Suc 0) \ (\X. X \ N \ finite X \ card X = 4 \ f1 X = t)" using \infinite N0\ Ramsey [of N0 4 f1 2] by (simp add: eval_nat_numeral) then obtain N1 j1 where "N1 \ N0" "infinite N1" and j1: "j1 < Suc (Suc 0)" and N1: "\A. A \ [N1]\<^bsup>4\<^esup> \ f1 A = j1" by (auto simp: nsets_def) define f2 where "f2 \ (\A::nat set. THE x. \a b c d. A = {a,b,c,d} \ a b c x = f {(a,d),(b,c)})" have f2: "f2 {a,b,c,d} = f {(a,d),(b,c)}" if "a [X]\<^bsup>4\<^esup>" using that by (auto simp: nsets_def) then obtain a b c d where "X = {a,b,c,d} \ a b cN t. N \ N1 \ infinite N \ t < Suc (Suc 0) \ (\X. X \ N \ finite X \ card X = 4 \ f2 X = t)" using \infinite N1\ Ramsey [of N1 4 f2 2] by (simp add: eval_nat_numeral) then obtain N2 j2 where "N2 \ N1" "infinite N2" and j2: "j2 < Suc (Suc 0)" and N2: "\A. A \ [N2]\<^bsup>4\<^esup> \ f2 A = j2" by (auto simp: nsets_def) define f3 where "f3 \ (\A::nat set. THE x. \a b c. A = {a,b,c} \ a b x = f {(a,b),(a,c)})" have f3: "f3 {a,b,c} = f {(a,b),(a,c)}" if "a [X]\<^bsup>3\<^esup>" using that by (auto simp: nsets_def) then obtain a b c where "X = {a,b,c} \ a bN t. N \ N2 \ infinite N \ t < Suc (Suc 0) \ (\X. X \ N \ finite X \ card X = 3 \ f3 X = t)" using \infinite N2\ Ramsey [of N2 3 f3 2] by (simp add: eval_nat_numeral) then obtain N3 j3 where "N3 \ N2" "infinite N3" and j3: "j3 < Suc (Suc 0)" and N3: "\A. A \ [N3]\<^bsup>3\<^esup> \ f3 A = j3" by (auto simp: nsets_def) show thesis proof fix k u assume "k < 4" and u: "form u k" "scheme u \ N3" and UU: "u \ [UU]\<^bsup>2\<^esup>" then consider (0) "k=0" | (1) "k=1" | (2) "k=2" | (3) "k=3" by linarith then show "f u = [j0,j1,j2,j3] ! k" proof cases case 0 have "N3 \ N0" using \N1 \ N0\ \N2 \ N1\ \N3 \ N2\ by auto then show ?thesis using u 0 apply (auto simp: form_def form_split_def scheme_def simp flip: f0) apply (force simp: nsets_def intro: N0) done next case 1 have "N3 \ N1" using \N2 \ N1\ \N3 \ N2\ by auto then show ?thesis using u 1 apply (auto simp: form_def form_split_def scheme_def simp flip: f1) apply (force simp: nsets_def intro: N1) done next case 2 then show ?thesis using u \N3 \ N2\ apply (auto simp: form_def form_split_def scheme_def nsets_def simp flip: f2) apply (force simp: nsets_def intro: N2) done next case 3 { fix a b d assume "{(a, b), (a, d)} \ [UU]\<^bsup>2\<^esup>" and *: "a \ N3" "b \ N3" "d \ N3" "b \ d" then have "ainfinite N3\) qed text \Lemma 2.4 of Jean A. Larson, ibid.\ lemma lemma_2_4: assumes "infinite N" "k < 4" obtains M where "M \ [UU]\<^bsup>m\<^esup>" "\u. u \ [M]\<^bsup>2\<^esup> \ form u k" "\u. u \ [M]\<^bsup>2\<^esup> \ scheme u \ N" proof - obtain f:: "nat \ nat" where "bij_betw f UNIV N" "strict_mono f" using assms by (meson bij_enumerate enumerate_mono strict_monoI) then have iff[simp]: "f x = f y \ x=y" "f x < f y \ x N" for x using bij_betw_apply [OF \bij_betw f UNIV N\] by blast define M0 where "M0 = (\i. (f(2*i), f(Suc(2*i)))) ` {..i. (f i, f(m+i))) ` {..i. (f i, f(2*m-i))) ` {..i. (f 0, f (Suc i))) ` {..i. (f (2 * i), f (Suc (2 * i)))) {.. [UU]\<^bsup>m\<^esup>" by (simp add: M0_def nsets_def card_image UU_def image_subset_iff) next fix u assume u: "(u::(nat \ nat) set) \ [M0]\<^bsup>2\<^esup>" then obtain x y where "u = {x,y}" "x \ y" "x \ M0" "y \ M0" by (auto simp: nsets_2_eq) then obtain i j where "i f (2 * j)" by (simp add: \i less_imp_le_nat) ultimately show "form u k" apply (simp add: 0 form_def form_split_def nsets_def) apply (rule_tac x="f (2 * i)" in exI) apply (rule_tac x="f (Suc (2 * i))" in exI) apply (rule_tac x="f (2 * j)" in exI) apply (rule_tac x="f (Suc (2 * j))" in exI) apply auto done show "scheme u \ N" using ueq by (auto simp: scheme_def) qed next case 1 show ?thesis proof have "inj_on (\i. (f i, f(m+i))) {.. [UU]\<^bsup>m\<^esup>" by (simp add: M1_def nsets_def card_image UU_def image_subset_iff) next fix u assume u: "(u::(nat \ nat) set) \ [M1]\<^bsup>2\<^esup>" then obtain x y where "u = {x,y}" "x \ y" "x \ M1" "y \ M1" by (auto simp: nsets_2_eq) then obtain i j where "i N" using ueq by (auto simp: scheme_def) qed next case 2 show ?thesis proof have "inj_on (\i. (f i, f(2*m-i))) {.. [UU]\<^bsup>m\<^esup>" by (auto simp: M2_def nsets_def card_image UU_def image_subset_iff) next fix u assume u: "(u::(nat \ nat) set) \ [M2]\<^bsup>2\<^esup>" then obtain x y where "u = {x,y}" "x \ y" "x \ M2" "y \ M2" by (auto simp: nsets_2_eq) then obtain i j where "i N" using ueq by (auto simp: scheme_def) qed next case 3 show ?thesis proof have "inj_on (\i. (f 0, f (Suc i))) {.. [UU]\<^bsup>m\<^esup>" by (auto simp: M3_def nsets_def card_image UU_def image_subset_iff) next fix u assume u: "(u::(nat \ nat) set) \ [M3]\<^bsup>2\<^esup>" then obtain x y where "u = {x,y}" "x \ y" "x \ M3" "y \ M3" by (auto simp: nsets_2_eq) then obtain i j where "i N" using ueq by (auto simp: scheme_def) qed qed qed text \Lemma 2.5 of Jean A. Larson, ibid.\ lemma lemma_2_5: assumes "infinite N" obtains X where "X \ UU" "ordertype X pair_less = \\2" "\u. u \ [X]\<^bsup>2\<^esup> \ (\k<4. form u k) \ scheme u \ N" proof - obtain C where dis: "pairwise (\i j. disjnt (C i) (C j)) UNIV" and N: "(\i. C i) \ N" and infC: "\i::nat. infinite (C i)" using assms infinite_infinite_partition by blast then have "\\::nat \ nat. inj \ \ range \ = C i \ strict_mono \" for i by (metis bij_betw_imp_inj_on bij_betw_imp_surj_on bij_enumerate enumerate_mono infC strict_mono_def) then obtain \:: "[nat,nat] \ nat" where \: "\i. inj (\ i) \ range (\ i) = C i \ strict_mono (\ i)" by metis then have \_in_C [simp]: "\ i j \ C i' \ i'=i" for i i' j using dis by (fastforce simp: pairwise_def disjnt_def) have less_iff [simp]: "\ i j' < \ i j \ j' < j" for i j' j by (simp add: \ strict_mono_less) let ?a = "\ 0" define X where "X \ {(?a i, b) | i b. ?a i < b \ b \ C (Suc i)}" show thesis proof show "X \ UU" by (auto simp: X_def UU_def) show "ordertype X pair_less = \\2" proof (rule antisym) have "ordertype X pair_less \ ordertype UU pair_less" by (simp add: \X \ UU\ ordertype_mono) then show "ordertype X pair_less \ \\2" using ordertype_UU_\2 by auto define \ where "\ \ \(i,j::nat). (?a i, \ (Suc i) (?a j))" have "\i j. i < j \ \ 0 i < \ (Suc i) (\ 0 j)" by (meson \ le_less_trans less_iff strict_mono_imp_increasing) then have subX: "\ ` UU \ X" by (auto simp: UU_def \_def X_def) then have "ordertype (\ ` UU) pair_less \ ordertype X pair_less" by (simp add: ordertype_mono) moreover have "ordertype (\ ` UU) pair_less = ordertype UU pair_less" proof (rule ordertype_inc_eq) show "(\ x, \ y) \ pair_less" if "x \ UU" "y \ UU" and "(x, y) \ pair_less" for x y using that by (auto simp: UU_def \_def pair_less_def) qed auto ultimately show "\\2 \ ordertype X pair_less" using ordertype_UU_\2 by simp qed next fix U assume "U \ [X]\<^bsup>2\<^esup>" then obtain a b c d where Ueq: "U = {(a,b),(c,d)}" and ne: "(a,b) \ (c,d)" and inX: "(a,b) \ X" "(c,d) \ X" and "a \ c" apply (auto simp: nsets_def subset_iff eval_nat_numeral card_Suc_eq Set.doubleton_eq_iff) apply (metis nat_le_linear)+ done show "(\k<4. form U k) \ scheme U \ N" proof show "scheme U \ N" using inX N \ by (fastforce simp: scheme_def Ueq X_def) next consider "a < c" | "a = c \ b \ d" using \a \ c\ ne nat_less_le by blast then show "\k<4. form U k" proof cases case 1 have *: "a < b" "b \ c" "c < d" using inX by (auto simp: X_def) moreover have "\a < c; c < b; \ d < b\ \ b < d" using inX apply (clarsimp simp: X_def not_less) by (metis \ \_in_C imageE nat.inject nat_less_le) ultimately consider (k0) "a b c c b c da \ c\ by blast then show ?thesis by force next case k1 then have "form U 1" unfolding form_def form_split_def using Ueq \a \ c\ by blast then show ?thesis by force next case k2 then have "form U 2" unfolding form_def form_split_def using Ueq \a \ c\ by blast then show ?thesis by force qed next case 2 then have "form_split a b c d 3" by (auto simp: form_split_def) then show ?thesis using Ueq form_def leI by force qed qed qed qed text \Theorem 2.1 of Jean A. Larson, ibid.\ lemma Specker_aux: assumes "\ \ elts \" shows "partn_lst pair_less UU [\\2,\] 2" unfolding partn_lst_def proof clarsimp fix f assume f: "f \ [UU]\<^bsup>2\<^esup> \ {..: "?P0 \ ?P1" proof (rule disjCI) assume "\ ?P1" then have not1: "\M. \M \ UU; ordertype M pair_less = \\ \ \x\[M]\<^bsup>2\<^esup>. f x \ Suc 0" by auto obtain m where m: "\ = ord_of_nat m" using assms elts_\ by auto then have f_eq_0: "M \ [UU]\<^bsup>m\<^esup> \ \x\[M]\<^bsup>2\<^esup>. f x = 0" for M using not1 [of M] finite_ordertype_eq_card [of M pair_less m] f apply (clarsimp simp: nsets_def eval_nat_numeral Pi_def) by (meson less_Suc0 not_less_less_Suc_eq subset_trans) obtain N js where "infinite N" and N: "\k u. \k < 4; u \ [UU]\<^bsup>2\<^esup>; form u k; scheme u \ N\ \ f u = js!k" using f lemma_2_3 by blast obtain M0 where M0: "M0 \ [UU]\<^bsup>m\<^esup>" "\u. u \ [M0]\<^bsup>2\<^esup> \ form u 0" "\u. u \ [M0]\<^bsup>2\<^esup> \ scheme u \ N" by (rule lemma_2_4 [OF \infinite N\]) auto obtain M1 where M1: "M1 \ [UU]\<^bsup>m\<^esup>" "\u. u \ [M1]\<^bsup>2\<^esup> \ form u 1" "\u. u \ [M1]\<^bsup>2\<^esup> \ scheme u \ N" by (rule lemma_2_4 [OF \infinite N\]) auto obtain M2 where M2: "M2 \ [UU]\<^bsup>m\<^esup>" "\u. u \ [M2]\<^bsup>2\<^esup> \ form u 2" "\u. u \ [M2]\<^bsup>2\<^esup> \ scheme u \ N" by (rule lemma_2_4 [OF \infinite N\]) auto obtain M3 where M3: "M3 \ [UU]\<^bsup>m\<^esup>" "\u. u \ [M3]\<^bsup>2\<^esup> \ form u 3" "\u. u \ [M3]\<^bsup>2\<^esup> \ scheme u \ N" by (rule lemma_2_4 [OF \infinite N\]) auto have "js!0 = 0" using N [of 0 ] M0 f_eq_0 [of M0] by (force simp: nsets_def eval_nat_numeral) moreover have "js!1 = 0" using N [of 1] M1 f_eq_0 [of M1] by (force simp: nsets_def eval_nat_numeral) moreover have "js!2 = 0" using N [of 2 ] M2 f_eq_0 [of M2] by (force simp: nsets_def eval_nat_numeral) moreover have "js!3 = 0" using N [of 3 ] M3 f_eq_0 [of M3] by (force simp: nsets_def eval_nat_numeral) ultimately have js0: "js!k = 0" if "k < 4" for k using that by (auto simp: eval_nat_numeral less_Suc_eq) obtain X where "X \ UU" and otX: "ordertype X pair_less = \\2" and X: "\u. u \ [X]\<^bsup>2\<^esup> \ (\k<4. form u k) \ scheme u \ N" using \infinite N\ lemma_2_5 by auto moreover have "f ` [X]\<^bsup>2\<^esup> \ {0}" proof (clarsimp simp: image_subset_iff) fix u assume u: "u \ [X]\<^bsup>2\<^esup>" then have u_UU2: "u \ [UU]\<^bsup>2\<^esup>" using \X \ UU\ nsets_mono by blast show "f u = 0" using X u N [OF _ u_UU2] js0 by auto qed ultimately show "\X \ UU. ordertype X pair_less = \\2 \ f ` [X]\<^bsup>2\<^esup> \ {0}" by blast qed then show "\iH\UU. ordertype H pair_less = [\\2, \] ! i \ f ` [H]\<^bsup>2\<^esup> \ {i}" proof show "?P0 \ ?thesis" by (metis nth_Cons_0 numeral_2_eq_2 pos2) show "?P1 \ ?thesis" by (metis One_nat_def lessI nth_Cons_0 nth_Cons_Suc) qed qed theorem Specker: "\ \ elts \ \ partn_lst_VWF (\\2) [\\2,\] 2" using partn_lst_imp_partn_lst_VWF_eq [OF Specker_aux] ordertype_UU_\2 wf_pair_less by blast end diff --git a/thys/ROOTS b/thys/ROOTS --- a/thys/ROOTS +++ b/thys/ROOTS @@ -1,591 +1,592 @@ ADS_Functor AI_Planning_Languages_Semantics AODV AVL-Trees AWN Abortable_Linearizable_Modules Abs_Int_ITP2012 Abstract-Hoare-Logics Abstract-Rewriting Abstract_Completeness Abstract_Soundness Adaptive_State_Counting Affine_Arithmetic Aggregation_Algebras Akra_Bazzi Algebraic_Numbers Algebraic_VCs Allen_Calculus Amicable_Numbers Amortized_Complexity AnselmGod Applicative_Lifting Approximation_Algorithms Architectural_Design_Patterns Aristotles_Assertoric_Syllogistic Arith_Prog_Rel_Primes ArrowImpossibilityGS Attack_Trees Auto2_HOL Auto2_Imperative_HOL AutoFocus-Stream Automated_Stateful_Protocol_Verification Automatic_Refinement AxiomaticCategoryTheory BDD BNF_CC BNF_Operations BTree Banach_Steinhaus Bell_Numbers_Spivey Berlekamp_Zassenhaus Bernoulli Bertrands_Postulate Bicategory BinarySearchTree Binding_Syntax_Theory Binomial-Heaps Binomial-Queues BirdKMP Blue_Eyes Bondy Boolean_Expression_Checkers Bounded_Deducibility_Security Buchi_Complementation Budan_Fourier Buffons_Needle Buildings BytecodeLogicJmlTypes C2KA_DistributedSystems CAVA_Automata CAVA_LTL_Modelchecker CCS CISC-Kernel CRDT CYK CakeML CakeML_Codegen Call_Arity Card_Equiv_Relations Card_Multisets Card_Number_Partitions Card_Partitions Cartan_FP Case_Labeling Catalan_Numbers Category Category2 Category3 Cauchy Cayley_Hamilton Certification_Monads Chandy_Lamport Chord_Segments Circus Clean ClockSynchInst Closest_Pair_Points CofGroups Coinductive Coinductive_Languages Collections Comparison_Sort_Lower_Bound Compiling-Exceptions-Correctly Complete_Non_Orders Completeness Complex_Geometry Complx ComponentDependencies ConcurrentGC ConcurrentIMP Concurrent_Ref_Alg Concurrent_Revisions Consensus_Refined Constructive_Cryptography +Constructive_Cryptography_CM Constructor_Funs Containers CoreC++ Core_DOM Core_SC_DOM Count_Complex_Roots CryptHOL CryptoBasedCompositionalProperties CSP_RefTK DFS_Framework DPT-SAT-Solver DataRefinementIBP Datatype_Order_Generator Decl_Sem_Fun_PL Decreasing-Diagrams Decreasing-Diagrams-II Deep_Learning Delta_System_Lemma Density_Compiler Dependent_SIFUM_Refinement Dependent_SIFUM_Type_Systems Depth-First-Search Derangements Deriving Descartes_Sign_Rule Dict_Construction Differential_Dynamic_Logic Differential_Game_Logic Dijkstra_Shortest_Path Diophantine_Eqns_Lin_Hom Dirichlet_L Dirichlet_Series DiscretePricing Discrete_Summation DiskPaxos DOM_Components DynamicArchitectures Dynamic_Tables E_Transcendental Echelon_Form EdmondsKarp_Maxflow Efficient-Mergesort Elliptic_Curves_Group_Law Encodability_Process_Calculi Epistemic_Logic Ergodic_Theory Error_Function Euler_MacLaurin Euler_Partition Example-Submission Extended_Finite_State_Machine_Inference Extended_Finite_State_Machines FFT FLP FOL-Fitting FOL_Harrison FOL_Seq_Calc1 Factored_Transition_System_Bounding Falling_Factorial_Sum Farkas FeatherweightJava Featherweight_OCL Fermat3_4 FileRefinement FinFun Finger-Trees Finite-Map-Extras Finite_Automata_HF First_Order_Terms First_Welfare_Theorem Fishburn_Impossibility Fisher_Yates Flow_Networks Floyd_Warshall Flyspeck-Tame FocusStreamsCaseStudies Forcing Formal_Puiseux_Series Formal_SSA Formula_Derivatives Fourier Free-Boolean-Algebra Free-Groups FunWithFunctions FunWithTilings Functional-Automata Functional_Ordered_Resolution_Prover Furstenberg_Topology GPU_Kernel_PL Gabow_SCC Game_Based_Crypto Gauss-Jordan-Elim-Fun Gauss_Jordan Gauss_Sums Gaussian_Integers GenClock General-Triangle Generalized_Counting_Sort Generic_Deriving Generic_Join GewirthPGCProof Girth_Chromatic GoedelGod Goedel_HFSet_Semantic Goedel_HFSet_Semanticless Goedel_Incompleteness Goodstein_Lambda GraphMarkingIBP Graph_Saturation Graph_Theory Green Groebner_Bases Groebner_Macaulay Gromov_Hyperbolicity Group-Ring-Module HOL-CSP HOLCF-Prelude HRB-Slicing Heard_Of Hello_World HereditarilyFinite Hermite Hermite_Lindemann Hidden_Markov_Models Higher_Order_Terms Hoare_Time Hood_Melville_Queue HotelKeyCards Huffman Hybrid_Logic Hybrid_Multi_Lane_Spatial_Logic Hybrid_Systems_VCs HyperCTL IEEE_Floating_Point IMAP-CRDT IMO2019 IMP2 IMP2_Binary_Heap IP_Addresses Imperative_Insertion_Sort Impossible_Geometry Incompleteness Incredible_Proof_Machine Inductive_Confidentiality Inductive_Inference InfPathElimination InformationFlowSlicing InformationFlowSlicing_Inter Integration Interpreter_Optimizations Interval_Arithmetic_Word32 Iptables_Semantics Irrational_Series_Erdos_Straus Irrationality_J_Hancl Isabelle_C Isabelle_Marries_Dirac Isabelle_Meta_Model IsaGeoCoq Jacobson_Basic_Algebra Jinja JinjaDCI JinjaThreads JiveDataStoreModel Jordan_Hoelder Jordan_Normal_Form KAD KAT_and_DRA KBPs KD_Tree Key_Agreement_Strong_Adversaries Kleene_Algebra Knuth_Bendix_Order Knot_Theory Knuth_Bendix_Order Knuth_Morris_Pratt Koenigsberg_Friendship Kruskal Kuratowski_Closure_Complement LLL_Basis_Reduction LLL_Factorization LOFT LTL LTL_Master_Theorem LTL_Normal_Form LTL_to_DRA LTL_to_GBA Lam-ml-Normalization LambdaAuth LambdaMu Lambda_Free_EPO Lambda_Free_KBOs Lambda_Free_RPOs Lambert_W Landau_Symbols Laplace_Transform Latin_Square LatticeProperties Launchbury Laws_of_Large_Numbers Lazy-Lists-II Lazy_Case Lehmer Lifting_Definition_Option LightweightJava LinearQuantifierElim Linear_Inequalities Linear_Programming Linear_Recurrences Liouville_Numbers List-Index List-Infinite List_Interleaving List_Inversions List_Update LocalLexing Localization_Ring Locally-Nameless-Sigma Lowe_Ontological_Argument Lower_Semicontinuous Lp Lucas_Theorem MFMC_Countable MFODL_Monitor_Optimized MFOTL_Monitor MSO_Regex_Equivalence Markov_Models Marriage Mason_Stothers Matrices_for_ODEs Matrix Matrix_Tensor Matroids Max-Card-Matching Median_Of_Medians_Selection Menger Mereology Mersenne_Primes MiniML Minimal_SSA Minkowskis_Theorem Minsky_Machines Modal_Logics_for_NTS Modular_arithmetic_LLL_and_HNF_algorithms Modular_Assembly_Kit_Security Monad_Memo_DP Monad_Normalisation MonoBoolTranAlgebra MonoidalCategory Monomorphic_Monad MuchAdoAboutTwo Multi_Party_Computation Multirelations Myhill-Nerode Name_Carrying_Type_Inference Nash_Williams Nat-Interval-Logic Native_Word Nested_Multisets_Ordinals Network_Security_Policy_Verification Neumann_Morgenstern_Utility No_FTL_observers Nominal2 Noninterference_CSP Noninterference_Concurrent_Composition Noninterference_Generic_Unwinding Noninterference_Inductive_Unwinding Noninterference_Ipurge_Unwinding Noninterference_Sequential_Composition NormByEval Nullstellensatz Octonions OpSets Open_Induction Optics Optimal_BST Orbit_Stabiliser Order_Lattice_Props Ordered_Resolution_Prover Ordinal Ordinal_Partitions Ordinals_and_Cardinals Ordinary_Differential_Equations PAC_Checker PCF PLM POPLmark-deBruijn PSemigroupsConvolution Pairing_Heap Paraconsistency Parity_Game Partial_Function_MR Partial_Order_Reduction Password_Authentication_Protocol Pell Perfect-Number-Thm Perron_Frobenius Physical_Quantities Pi_Calculus Pi_Transcendental Planarity_Certificates Poincare_Bendixson Poincare_Disc Polynomial_Factorization Polynomial_Interpolation Polynomials Pop_Refinement Posix-Lexing Possibilistic_Noninterference Power_Sum_Polynomials Pratt_Certificate Presburger-Automata Prim_Dijkstra_Simple Prime_Distribution_Elementary Prime_Harmonic_Series Prime_Number_Theorem Priority_Queue_Braun Priority_Search_Trees Probabilistic_Noninterference Probabilistic_Prime_Tests Probabilistic_System_Zoo Probabilistic_Timed_Automata Probabilistic_While Program-Conflict-Analysis Projective_Geometry Projective_Measurements Promela Proof_Strategy_Language PropResPI Propositional_Proof_Systems Prpu_Maxflow PseudoHoops Psi_Calculi Ptolemys_Theorem QHLProver QR_Decomposition Quantales Quaternions Quick_Sort_Cost RIPEMD-160-SPARK ROBDD RSAPSS Ramsey-Infinite Random_BSTs Random_Graph_Subgraph_Threshold Randomised_BSTs Randomised_Social_Choice Rank_Nullity_Theorem Real_Impl Recursion-Addition Recursion-Theory-I Refine_Imperative_HOL Refine_Monadic RefinementReactive Regex_Equivalence Regular-Sets Regular_Algebras Relation_Algebra Relational-Incorrectness-Logic Relational_Disjoint_Set_Forests Relational_Method Relational_Minimum_Spanning_Trees Relational_Paths Rep_Fin_Groups Residuated_Lattices Resolution_FOL Rewriting_Z Ribbon_Proofs Robbins-Conjecture Robinson_Arithmetic Root_Balanced_Tree Routing Roy_Floyd_Warshall SATSolverVerification SC_DOM_Components SDS_Impossibility SIFPL SIFUM_Type_Systems SPARCv8 Safe_Distance Safe_OCL Saturation_Framework Saturation_Framework_Extensions Shadow_DOM Secondary_Sylow Security_Protocol_Refinement Selection_Heap_Sort SenSocialChoice Separata Separation_Algebra Separation_Logic_Imperative_HOL SequentInvertibility Shadow_SC_DOM Shivers-CFA ShortestPath Show Sigma_Commit_Crypto Signature_Groebner Simpl Simple_Firewall Simplex Skew_Heap Skip_Lists Slicing Sliding_Window_Algorithm Smith_Normal_Form Smooth_Manifolds Sort_Encodings Source_Coding_Theorem Special_Function_Bounds Splay_Tree Sqrt_Babylonian Stable_Matching Statecharts Stateful_Protocol_Composition_and_Typing Stellar_Quorums Stern_Brocot Stewart_Apollonius Stirling_Formula Stochastic_Matrices Stone_Algebras Stone_Kleene_Relation_Algebras Stone_Relation_Algebras Store_Buffer_Reduction Stream-Fusion Stream_Fusion_Code Strong_Security Sturm_Sequences Sturm_Tarski Stuttering_Equivalence Subresultants Subset_Boolean_Algebras SumSquares Sunflowers SuperCalc Surprise_Paradox Symmetric_Polynomials Syntax_Independent_Logic Szpilrajn TESL_Language TLA Tail_Recursive_Functions Tarskis_Geometry Taylor_Models Timed_Automata Topological_Semantics Topology TortoiseHare Transcendence_Series_Hancl_Rucki Transformer_Semantics Transition_Systems_and_Automata Transitive-Closure Transitive-Closure-II Treaps Tree-Automata Tree_Decomposition Triangle Trie Twelvefold_Way Tycon Types_Tableaus_and_Goedels_God UPF UPF_Firewall UTP Universal_Turing_Machine UpDown_Scheme Valuation VectorSpace VeriComp Verified-Prover Verified_SAT_Based_AI_Planning VerifyThis2018 VerifyThis2019 Vickrey_Clarke_Groves VolpanoSmith WHATandWHERE_Security WOOT_Strong_Eventual_Consistency WebAssembly Weight_Balanced_Trees Well_Quasi_Orders Winding_Number_Eval Word_Lib WorkerWrapper XML ZFC_in_HOL Zeta_3_Irrational Zeta_Function pGCL diff --git a/web/entries/Constructive_Cryptography.html b/web/entries/Constructive_Cryptography.html --- a/web/entries/Constructive_Cryptography.html +++ b/web/entries/Constructive_Cryptography.html @@ -1,217 +1,219 @@ Constructive Cryptography in HOL - Archive of Formal Proofs

 

 

 

 

 

 

Constructive Cryptography in HOL

 

- + + +
Title: Constructive Cryptography in HOL
Authors: Andreas Lochbihler and S. Reza Sefidgar
Submission date: 2018-12-17
Abstract: Inspired by Abstract Cryptography, we extend CryptHOL, a framework for formalizing game-based proofs, with an abstract model of Random Systems and provide proof rules about their composition and equality. This foundation facilitates the formalization of Constructive Cryptography proofs, where the security of a cryptographic scheme is realized as a special form of construction in which a complex random system is built from simpler ones. This is a first step towards a fully-featured compositional framework, similar to Universal Composability framework, that supports formalization of simulation-based proofs.
BibTeX:
@article{Constructive_Cryptography-AFP,
   author  = {Andreas Lochbihler and S. Reza Sefidgar},
   title   = {Constructive Cryptography in HOL},
   journal = {Archive of Formal Proofs},
   month   = dec,
   year    = 2018,
   note    = {\url{https://isa-afp.org/entries/Constructive_Cryptography.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: CryptHOL
Used by:Constructive_Cryptography_CM

\ No newline at end of file diff --git a/web/entries/Constructive_Cryptography_CM.html b/web/entries/Constructive_Cryptography_CM.html new file mode 100644 --- /dev/null +++ b/web/entries/Constructive_Cryptography_CM.html @@ -0,0 +1,223 @@ + + + + +Constructive Cryptography in HOL: the Communication Modeling Aspect - Archive of Formal Proofs + + + + + + + + + + + + + + + + + + + + + + + + +
+

 

+ + + +

 

+

 

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

 

+

 

+
+
+

 

+

Constructive + + Cryptography + + in + + HOL: + + the + + Communication + + Modeling + + Aspect + +

+

 

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Title:Constructive Cryptography in HOL: the Communication Modeling Aspect
+ Authors: + + Andreas Lochbihler and + S. Reza Sefidgar +
Submission date:2021-03-17
Abstract: +Constructive Cryptography (CC) [ICS +2011, TOSCA +2011, TCC +2016] introduces an abstract approach to composable security +statements that allows one to focus on a particular aspect of security +proofs at a time. Instead of proving the properties of concrete +systems, CC studies system classes, i.e., the shared behavior of +similar systems, and their transformations. Modeling of systems +communication plays a crucial role in composability and reusability of +security statements; yet, this aspect has not been studied in any of +the existing CC results. We extend our previous CC formalization +[Constructive_Cryptography, +CSF +2019] with a new semantic domain called Fused Resource +Templates (FRT) that abstracts over the systems communication patterns +in CC proofs. This widens the scope of cryptography proof +formalizations in the CryptHOL library [CryptHOL, +ESOP +2016, J +Cryptol 2020]. This formalization is described in Abstract +Modeling of Systems Communication in Constructive Cryptography using +CryptHOL.
BibTeX: +
@article{Constructive_Cryptography_CM-AFP,
+  author  = {Andreas Lochbihler and S. Reza Sefidgar},
+  title   = {Constructive Cryptography in HOL: the Communication Modeling Aspect},
+  journal = {Archive of Formal Proofs},
+  month   = mar,
+  year    = 2021,
+  note    = {\url{https://isa-afp.org/entries/Constructive_Cryptography_CM.html},
+            Formal proof development},
+  ISSN    = {2150-914x},
+}
+
License:BSD License
Depends on:Constructive_Cryptography, Game_Based_Crypto, Sigma_Commit_Crypto
+ +

+ + + + + + + + + + + + + + + + + + +
+
+ + + + + + \ No newline at end of file diff --git a/web/entries/Game_Based_Crypto.html b/web/entries/Game_Based_Crypto.html --- a/web/entries/Game_Based_Crypto.html +++ b/web/entries/Game_Based_Crypto.html @@ -1,237 +1,237 @@ Game-based cryptography in HOL - Archive of Formal Proofs

 

 

 

 

 

 

Game-based cryptography in HOL

 

- +
Title: Game-based cryptography in HOL
Authors: Andreas Lochbihler, S. Reza Sefidgar and Bhargav Bhatt (bhargav /dot/ bhatt /at/ inf /dot/ ethz /dot/ ch)
Submission date: 2017-05-05
Abstract:

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.

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.

Change history: [2018-09-28]: added the CryptHOL tutorial for game-based cryptography (revision 489a395764ae)
BibTeX:
@article{Game_Based_Crypto-AFP,
   author  = {Andreas Lochbihler and S. Reza Sefidgar and Bhargav Bhatt},
   title   = {Game-based cryptography in HOL},
   journal = {Archive of Formal Proofs},
   month   = may,
   year    = 2017,
   note    = {\url{https://isa-afp.org/entries/Game_Based_Crypto.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: CryptHOL
Used by:Multi_Party_Computation
Constructive_Cryptography_CM, Multi_Party_Computation

\ No newline at end of file diff --git a/web/entries/Sigma_Commit_Crypto.html b/web/entries/Sigma_Commit_Crypto.html --- a/web/entries/Sigma_Commit_Crypto.html +++ b/web/entries/Sigma_Commit_Crypto.html @@ -1,213 +1,215 @@ Sigma Protocols and Commitment Schemes - Archive of Formal Proofs

 

 

 

 

 

 

Sigma Protocols and Commitment Schemes

 

- + + +
Title: Sigma Protocols and Commitment Schemes
Authors: David Butler and Andreas Lochbihler
Submission date: 2019-10-07
Abstract: We use CryptHOL to formalise commitment schemes and Sigma-protocols. Both are widely used fundamental two party cryptographic primitives. Security for commitment schemes is considered using game-based definitions whereas the security of Sigma-protocols is considered using both the game-based and simulation-based security paradigms. In this work, we first define security for both primitives and then prove secure multiple case studies: the Schnorr, Chaum-Pedersen and Okamoto Sigma-protocols as well as a construction that allows for compound (AND and OR statements) Sigma-protocols and the Pedersen and Rivest commitment schemes. We also prove that commitment schemes can be constructed from Sigma-protocols. We formalise this proof at an abstract level, only assuming the existence of a Sigma-protocol; consequently, the instantiations of this result for the concrete Sigma-protocols we consider come for free.
BibTeX:
@article{Sigma_Commit_Crypto-AFP,
   author  = {David Butler and Andreas Lochbihler},
   title   = {Sigma Protocols and Commitment Schemes},
   journal = {Archive of Formal Proofs},
   month   = oct,
   year    = 2019,
   note    = {\url{https://isa-afp.org/entries/Sigma_Commit_Crypto.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: CryptHOL
Used by:Constructive_Cryptography_CM

\ No newline at end of file diff --git a/web/entries/Szpilrajn.html b/web/entries/Szpilrajn.html --- a/web/entries/Szpilrajn.html +++ b/web/entries/Szpilrajn.html @@ -1,195 +1,207 @@ -Szpilrajn Extension Theorem - Archive of Formal Proofs +<title>Order Extension and Szpilrajn's Extension Theorem - Archive of Formal Proofs

 

 

 

 

 

 

-

Szpilrajn +

Order + + Extension + + and + + Szpilrajn's Extension Theorem

 

- + +This entry is concerned with the principle of order extension, i.e. the extension of an order relation to a total order relation. +To this end, we prove a more general version of Szpilrajn's extension theorem employing terminology from the book "Consistency, Choice, and Rationality" by Bossert and Suzumura. +We also formalize theorem 2.7 of their book. + + + +
Title:Szpilrajn Extension TheoremOrder Extension and Szpilrajn's Extension Theorem
- Author: + Authors: - Peter Zeller (p_zeller /at/ cs /dot/ uni-kl /dot/ de) + Peter Zeller (p_zeller /at/ cs /dot/ uni-kl /dot/ de) and + Lukas Stevens
Submission date: 2019-07-27
Abstract: -We formalize the Szpilrajn extension theorem, also known as -order-extension principal: Every strict partial order can be extended -to a strict linear order.
Change history:[2021-03-22]: +(by Lukas Stevens) generalise Szpilrajn's extension theorem and add material from the book "Consistency, Choice, and Rationality"
BibTeX:
@article{Szpilrajn-AFP,
-  author  = {Peter Zeller},
-  title   = {Szpilrajn Extension Theorem},
+  author  = {Peter Zeller and Lukas Stevens},
+  title   = {Order Extension and Szpilrajn's Extension Theorem},
   journal = {Archive of Formal Proofs},
   month   = jul,
   year    = 2019,
   note    = {\url{https://isa-afp.org/entries/Szpilrajn.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License

\ No newline at end of file diff --git a/web/index.html b/web/index.html --- a/web/index.html +++ b/web/index.html @@ -1,5398 +1,5408 @@ Archive of Formal Proofs

 

 

 

 

 

 

Archive of Formal Proofs

 

The Archive of Formal Proofs is a collection of proof libraries, examples, and larger scientific developments, mechanically checked in the theorem prover Isabelle. It is organized in the way of a scientific journal, is indexed by dblp and has an ISSN: 2150-914x. Submissions are refereed. The preferred citation style is available [here]. We encourage companion AFP submissions to conference and journal publications.

A development version of the archive is available as well.

 

 

+ + +
2021
+ 2021-03-17: Constructive Cryptography in HOL: the Communication Modeling Aspect +
+ Authors: + Andreas Lochbihler + and S. Reza Sefidgar +
2021-03-12: Two algorithms based on modular arithmetic: lattice basis reduction and Hermite normal form computation
Authors: Ralph Bottesch, Jose Divasón and René Thiemann
2021-03-03: Quantum projective measurements and the CHSH inequality
Author: Mnacho Echenim
2021-03-03: The Hermite–Lindemann–Weierstraß Transcendence Theorem
Author: Manuel Eberl
2021-03-01: Mereology
Author: Ben Blumson
2021-02-25: The Sunflower Lemma of Erdős and Rado
Author: René Thiemann
2021-02-24: A Verified Imperative Implementation of B-Trees
Author: Niels Mündler
2021-02-17: Formal Puiseux Series
Author: Manuel Eberl
2021-02-10: The Laws of Large Numbers
Author: Manuel Eberl
2021-01-31: Tarski's Parallel Postulate implies the 5th Postulate of Euclid, the Postulate of Playfair and the original Parallel Postulate of Euclid
Author: Roland Coghetto
2021-01-30: Solution to the xkcd Blue Eyes puzzle
Author: Jakub Kądziołka
2021-01-18: Hood-Melville Queue
Author: Alejandro Gómez-Londoño
2021-01-11: JinjaDCI: a Java semantics with dynamic class initialization
Author: Susannah Mansky

 

2020
2020-12-27: Cofinality and the Delta System Lemma
Author: Pedro Sánchez Terraf
2020-12-17: Topological semantics for paraconsistent and paracomplete logics
Author: David Fuenmayor
2020-12-08: Relational Minimum Spanning Tree Algorithms
Authors: Walter Guttmann and Nicolas Robinson-O'Brien
2020-12-07: Inline Caching and Unboxing Optimization for Interpreters
Author: Martin Desharnais
2020-12-05: The Relational Method with Message Anonymity for the Verification of Cryptographic Protocols
Author: Pasquale Noce
2020-11-22: Isabelle Marries Dirac: a Library for Quantum Computation and Quantum Information
Authors: Anthony Bordg, Hanna Lachnitt and Yijun He
2020-11-19: The HOL-CSP Refinement Toolkit
Authors: Safouan Taha, Burkhart Wolff and Lina Ye
2020-10-29: Verified SAT-Based AI Planning
Authors: Mohammad Abdulaziz and Friedrich Kurz
2020-10-29: AI Planning Languages Semantics
Authors: Mohammad Abdulaziz and Peter Lammich
2020-10-20: A Sound Type System for Physical Quantities, Units, and Measurements
Authors: Simon Foster and Burkhart Wolff
2020-10-12: Finite Map Extras
Author: Javier Díaz
2020-09-28: A Formal Model of the Safely Composable Document Object Model with Shadow Roots
Authors: Achim D. Brucker and Michael Herzberg
2020-09-28: A Formal Model of the Document Object Model with Shadow Roots
Authors: Achim D. Brucker and Michael Herzberg
2020-09-28: A Formalization of Safely Composable Web Components
Authors: Achim D. Brucker and Michael Herzberg
2020-09-28: A Formalization of Web Components
Authors: Achim D. Brucker and Michael Herzberg
2020-09-28: The Safely Composable DOM
Authors: Achim D. Brucker and Michael Herzberg
2020-09-16: Syntax-Independent Logic Infrastructure
Authors: Andrei Popescu and Dmitriy Traytel
2020-09-16: Robinson Arithmetic
Authors: Andrei Popescu and Dmitriy Traytel
2020-09-16: An Abstract Formalization of Gödel's Incompleteness Theorems
Authors: Andrei Popescu and Dmitriy Traytel
2020-09-16: From Abstract to Concrete Gödel's Incompleteness Theorems—Part II
Authors: Andrei Popescu and Dmitriy Traytel
2020-09-16: From Abstract to Concrete Gödel's Incompleteness Theorems—Part I
Authors: Andrei Popescu and Dmitriy Traytel
2020-09-07: A Formal Model of Extended Finite State Machines
Authors: Michael Foster, Achim D. Brucker, Ramsay G. Taylor and John Derrick
2020-09-07: Inference of Extended Finite State Machines
Authors: Michael Foster, Achim D. Brucker, Ramsay G. Taylor and John Derrick
2020-08-31: Practical Algebraic Calculus Checker
Authors: Mathias Fleury and Daniela Kaufmann
2020-08-31: Some classical results in inductive inference of recursive functions
Author: Frank J. Balbach
2020-08-26: Relational Disjoint-Set Forests
Author: Walter Guttmann
2020-08-25: Extensions to the Comprehensive Framework for Saturation Theorem Proving
Authors: Jasmin Blanchette and Sophie Tourret
2020-08-25: Putting the `K' into Bird's derivation of Knuth-Morris-Pratt string matching
Author: Peter Gammie
2020-08-04: Amicable Numbers
Author: Angeliki Koutsoukou-Argyraki
2020-08-03: Ordinal Partitions
Author: Lawrence C. Paulson
2020-07-21: A Formal Proof of The Chandy--Lamport Distributed Snapshot Algorithm
Authors: Ben Fiedler and Dmitriy Traytel
2020-07-13: Relational Characterisations of Paths
Authors: Walter Guttmann and Peter Höfner
2020-06-01: A Formally Verified Checker of the Safe Distance Traffic Rules for Autonomous Vehicles
Authors: Albert Rizaldi and Fabian Immler
2020-05-23: A verified algorithm for computing the Smith normal form of a matrix
Author: Jose Divasón
2020-05-16: The Nash-Williams Partition Theorem
Author: Lawrence C. Paulson
2020-05-13: A Formalization of Knuth–Bendix Orders
Authors: Christian Sternagel and René Thiemann
2020-05-12: Irrationality Criteria for Series by Erdős and Straus
Authors: Angeliki Koutsoukou-Argyraki and Wenda Li
2020-05-11: Recursion Theorem in ZF
Author: Georgy Dunaev
2020-05-08: An Efficient Normalisation Procedure for Linear Temporal Logic: Isabelle/HOL Formalisation
Author: Salomon Sickert
2020-05-06: Formalization of Forcing in Isabelle/ZF
Authors: Emmanuel Gunther, Miguel Pagano and Pedro Sánchez Terraf
2020-05-02: Banach-Steinhaus Theorem
Authors: Dominique Unruh and Jose Manuel Rodriguez Caballero
2020-04-27: Attack Trees in Isabelle for GDPR compliance of IoT healthcare systems
Author: Florian Kammueller
2020-04-24: Power Sum Polynomials
Author: Manuel Eberl
2020-04-24: The Lambert W Function on the Reals
Author: Manuel Eberl
2020-04-24: Gaussian Integers
Author: Manuel Eberl
2020-04-19: Matrices for ODEs
Author: Jonathan Julian Huerta y Munive
2020-04-16: Authenticated Data Structures As Functors
Authors: Andreas Lochbihler and Ognjen Marić
2020-04-10: Formalization of an Algorithm for Greedily Computing Associative Aggregations on Sliding Windows
Authors: Lukas Heimes, Dmitriy Traytel and Joshua Schneider
2020-04-09: A Comprehensive Framework for Saturation Theorem Proving
Author: Sophie Tourret
2020-04-09: Formalization of an Optimized Monitoring Algorithm for Metric First-Order Dynamic Logic with Aggregations
Authors: Thibault Dardinier, Lukas Heimes, Martin Raszyk, Joshua Schneider and Dmitriy Traytel
2020-04-08: Stateful Protocol Composition and Typing
Authors: Andreas V. Hess, Sebastian Mödersheim and Achim D. Brucker
2020-04-08: Automated Stateful Protocol Verification
Authors: Andreas V. Hess, Sebastian Mödersheim, Achim D. Brucker and Anders Schlichtkrull
2020-04-07: Lucas's Theorem
Author: Chelsea Edmonds
2020-03-25: Strong Eventual Consistency of the Collaborative Editing Framework WOOT
Authors: Emin Karayel and Edgar Gonzàlez
2020-03-22: Furstenberg's topology and his proof of the infinitude of primes
Author: Manuel Eberl
2020-03-12: An Under-Approximate Relational Logic
Author: Toby Murray
2020-03-07: Hello World
Authors: Cornelius Diekmann and Lars Hupel
2020-02-21: Implementing the Goodstein Function in λ-Calculus
Author: Bertram Felgenhauer
2020-02-10: A Generic Framework for Verified Compilers
Author: Martin Desharnais
2020-02-01: Arithmetic progressions and relative primes
Author: José Manuel Rodríguez Caballero
2020-01-31: A Hierarchy of Algebras for Boolean Subsets
Authors: Walter Guttmann and Bernhard Möller
2020-01-17: Mersenne primes and the Lucas–Lehmer test
Author: Manuel Eberl
2020-01-16: Verified Approximation Algorithms
Authors: Robin Eßmann, Tobias Nipkow and Simon Robillard
2020-01-13: Closest Pair of Points Algorithms
Authors: Martin Rau and Tobias Nipkow
2020-01-09: Skip Lists
Authors: Max W. Haslbeck and Manuel Eberl
2020-01-06: Bicategories
Author: Eugene W. Stark

 

+ and Lukas Stevens +
2019
2019-12-27: The Irrationality of ζ(3)
Author: Manuel Eberl
2019-12-20: Formalizing a Seligman-Style Tableau System for Hybrid Logic
Author: Asta Halkjær From
2019-12-18: The Poincaré-Bendixson Theorem
Authors: Fabian Immler and Yong Kiam Tan
2019-12-16: Poincaré Disc Model
Authors: Danijela Simić, Filip Marić and Pierre Boutry
2019-12-16: Complex Geometry
Authors: Filip Marić and Danijela Simić
2019-12-10: Gauss Sums and the Pólya–Vinogradov Inequality
Authors: Rodrigo Raya and Manuel Eberl
2019-12-04: An Efficient Generalization of Counting Sort for Large, possibly Infinite Key Ranges
Author: Pasquale Noce
2019-11-27: Interval Arithmetic on 32-bit Words
Author: Brandon Bohrer
2019-10-24: Zermelo Fraenkel Set Theory in Higher-Order Logic
Author: Lawrence C. Paulson
2019-10-22: Isabelle/C
Authors: Frédéric Tuong and Burkhart Wolff
2019-10-16: VerifyThis 2019 -- Polished Isabelle Solutions
Authors: Peter Lammich and Simon Wimmer
2019-10-08: Aristotle's Assertoric Syllogistic
Author: Angeliki Koutsoukou-Argyraki
2019-10-07: Sigma Protocols and Commitment Schemes
Authors: David Butler and Andreas Lochbihler
2019-10-04: Clean - An Abstract Imperative Programming Language and its Theory
Authors: Frédéric Tuong and Burkhart Wolff
2019-09-16: Formalization of Multiway-Join Algorithms
Author: Thibault Dardinier
2019-09-10: Verification Components for Hybrid Systems
Author: Jonathan Julian Huerta y Munive
2019-09-06: Fourier Series
Author: Lawrence C Paulson
2019-08-30: A Case Study in Basic Algebra
Author: Clemens Ballarin
2019-08-16: Formalisation of an Adaptive State Counting Algorithm
Author: Robert Sachtleben
2019-08-14: Laplace Transform
Author: Fabian Immler
2019-08-06: Linear Programming
Authors: Julian Parsert and Cezary Kaliszyk
2019-08-06: Communicating Concurrent Kleene Algebra for Distributed Systems Specification
Authors: Maxime Buyse and Jason Jaskolka
2019-08-05: Selected Problems from the International Mathematical Olympiad 2019
Author: Manuel Eberl
2019-08-01: Stellar Quorum Systems
Author: Giuliano Losa
2019-07-30: A Formal Development of a Polychronous Polytimed Coordination Language
Authors: Hai Nguyen Van, Frédéric Boulanger and Burkhart Wolff
- 2019-07-27: Szpilrajn Extension Theorem -
- Author: + 2019-07-27: Order Extension and Szpilrajn's Extension Theorem +
+ Authors: Peter Zeller -
2019-07-18: A Sequent Calculus for First-Order Logic
Author: Asta Halkjær From
2019-07-08: A Verified Code Generator from Isabelle/HOL to CakeML
Author: Lars Hupel
2019-07-04: Formalization of a Monitoring Algorithm for Metric First-Order Temporal Logic
Authors: Joshua Schneider and Dmitriy Traytel
2019-06-27: Complete Non-Orders and Fixed Points
Authors: Akihisa Yamada and Jérémy Dubut
2019-06-25: Priority Search Trees
Authors: Peter Lammich and Tobias Nipkow
2019-06-25: Purely Functional, Simple, and Efficient Implementation of Prim and Dijkstra
Authors: Peter Lammich and Tobias Nipkow
2019-06-21: Linear Inequalities
Authors: Ralph Bottesch, Alban Reynaud and René Thiemann
2019-06-16: Hilbert's Nullstellensatz
Author: Alexander Maletzky
2019-06-15: Gröbner Bases, Macaulay Matrices and Dubé's Degree Bounds
Author: Alexander Maletzky
2019-06-13: Binary Heaps for IMP2
Author: Simon Griebel
2019-06-03: Differential Game Logic
Author: André Platzer
2019-05-30: Multidimensional Binary Search Trees
Author: Martin Rau
2019-05-14: Formalization of Generic Authenticated Data Structures
Authors: Matthias Brun and Dmitriy Traytel
2019-05-09: Multi-Party Computation
Authors: David Aspinall and David Butler
2019-04-26: HOL-CSP Version 2.0
Authors: Safouan Taha, Lina Ye and Burkhart Wolff
2019-04-16: A Compositional and Unified Translation of LTL into ω-Automata
Authors: Benedikt Seidl and Salomon Sickert
2019-04-06: A General Theory of Syntax with Bindings
Authors: Lorenzo Gheri and Andrei Popescu
2019-03-27: The Transcendence of Certain Infinite Series
Authors: Angeliki Koutsoukou-Argyraki and Wenda Li
2019-03-24: Quantum Hoare Logic
Authors: Junyi Liu, Bohua Zhan, Shuling Wang, Shenggang Ying, Tao Liu, Yangjia Li, Mingsheng Ying and Naijun Zhan
2019-03-09: Safe OCL
Author: Denis Nikiforov
2019-02-21: Elementary Facts About the Distribution of Primes
Author: Manuel Eberl
2019-02-14: Kruskal's Algorithm for Minimum Spanning Forest
Authors: Maximilian P.L. Haslbeck, Peter Lammich and Julian Biendarra
2019-02-11: Probabilistic Primality Testing
Authors: Daniel Stüwe and Manuel Eberl
2019-02-08: Universal Turing Machine
Authors: Jian Xu, Xingyuan Zhang, Christian Urban and Sebastiaan J. C. Joosten
2019-02-01: Isabelle/UTP: Mechanised Theory Engineering for Unifying Theories of Programming
Authors: Simon Foster, Frank Zeyda, Yakoub Nemouchi, Pedro Ribeiro and Burkhart Wolff
2019-02-01: The Inversions of a List
Author: Manuel Eberl
2019-01-17: Farkas' Lemma and Motzkin's Transposition Theorem
Authors: Ralph Bottesch, Max W. Haslbeck and René Thiemann
2019-01-15: IMP2 – Simple Program Verification in Isabelle/HOL
Authors: Peter Lammich and Simon Wimmer
2019-01-15: An Algebra for Higher-Order Terms
Author: Lars Hupel
2019-01-07: A Reduction Theorem for Store Buffers
Authors: Ernie Cohen and Norbert Schirmer

 

2018
2018-12-26: A Formal Model of the Document Object Model
Authors: Achim D. Brucker and Michael Herzberg
2018-12-25: Formalization of Concurrent Revisions
Author: Roy Overbeek
2018-12-21: Verifying Imperative Programs using Auto2
Author: Bohua Zhan
2018-12-17: Constructive Cryptography in HOL
Authors: Andreas Lochbihler and S. Reza Sefidgar
2018-12-11: Transformer Semantics
Author: Georg Struth
2018-12-11: Quantales
Author: Georg Struth
2018-12-11: Properties of Orderings and Lattices
Author: Georg Struth
2018-11-23: Graph Saturation
Author: Sebastiaan J. C. Joosten
2018-11-23: A Verified Functional Implementation of Bachmair and Ganzinger's Ordered Resolution Prover
Authors: Anders Schlichtkrull, Jasmin Christian Blanchette and Dmitriy Traytel
2018-11-20: Auto2 Prover
Author: Bohua Zhan
2018-11-16: Matroids
Author: Jonas Keinholz
2018-11-06: Deriving generic class instances for datatypes
Authors: Jonas Rädle and Lars Hupel
2018-10-30: Formalisation and Evaluation of Alan Gewirth's Proof for the Principle of Generic Consistency in Isabelle/HOL
Authors: David Fuenmayor and Christoph Benzmüller
2018-10-29: Epistemic Logic
Author: Asta Halkjær From
2018-10-22: Smooth Manifolds
Authors: Fabian Immler and Bohua Zhan
2018-10-19: Randomised Binary Search Trees
Author: Manuel Eberl
2018-10-19: Formalization of the Embedding Path Order for Lambda-Free Higher-Order Terms
Author: Alexander Bentkamp
2018-10-12: Upper Bounding Diameters of State Spaces of Factored Transition Systems
Authors: Friedrich Kurz and Mohammad Abdulaziz
2018-09-28: The Transcendence of π
Author: Manuel Eberl
2018-09-25: Symmetric Polynomials
Author: Manuel Eberl
2018-09-20: Signature-Based Gröbner Basis Algorithms
Author: Alexander Maletzky
2018-09-19: The Prime Number Theorem
Authors: Manuel Eberl and Lawrence C. Paulson
2018-09-15: Aggregation Algebras
Author: Walter Guttmann
2018-09-14: Octonions
Author: Angeliki Koutsoukou-Argyraki
2018-09-05: Quaternions
Author: Lawrence C. Paulson
2018-09-02: The Budan-Fourier Theorem and Counting Real Roots with Multiplicity
Author: Wenda Li
2018-08-24: An Incremental Simplex Algorithm with Unsatisfiable Core Generation
Authors: Filip Marić, Mirko Spasić and René Thiemann
2018-08-14: Minsky Machines
Author: Bertram Felgenhauer
2018-07-16: Pricing in discrete financial models
Author: Mnacho Echenim
2018-07-04: Von-Neumann-Morgenstern Utility Theorem
Authors: Julian Parsert and Cezary Kaliszyk
2018-06-23: Pell's Equation
Author: Manuel Eberl
2018-06-14: Projective Geometry
Author: Anthony Bordg
2018-06-14: The Localization of a Commutative Ring
Author: Anthony Bordg
2018-06-05: Partial Order Reduction
Author: Julian Brunner
2018-05-27: Optimal Binary Search Trees
Authors: Tobias Nipkow and Dániel Somogyi
2018-05-25: Hidden Markov Models
Author: Simon Wimmer
2018-05-24: Probabilistic Timed Automata
Authors: Simon Wimmer and Johannes Hölzl
2018-05-23: Irrational Rapidly Convergent Series
Authors: Angeliki Koutsoukou-Argyraki and Wenda Li
2018-05-23: Axiom Systems for Category Theory in Free Logic
Authors: Christoph Benzmüller and Dana Scott
2018-05-22: Monadification, Memoization and Dynamic Programming
Authors: Simon Wimmer, Shuwei Hu and Tobias Nipkow
2018-05-10: OpSets: Sequential Specifications for Replicated Datatypes
Authors: Martin Kleppmann, Victor B. F. Gomes, Dominic P. Mulligan and Alastair R. Beresford
2018-05-07: An Isabelle/HOL Formalization of the Modular Assembly Kit for Security Properties
Authors: Oliver Bračevac, Richard Gay, Sylvia Grewe, Heiko Mantel, Henning Sudbrock and Markus Tasch
2018-04-29: WebAssembly
Author: Conrad Watt
2018-04-27: VerifyThis 2018 - Polished Isabelle Solutions
Authors: Peter Lammich and Simon Wimmer
2018-04-24: Bounded Natural Functors with Covariance and Contravariance
Authors: Andreas Lochbihler and Joshua Schneider
2018-03-22: The Incompatibility of Fishburn-Strategyproofness and Pareto-Efficiency
Authors: Felix Brandt, Manuel Eberl, Christian Saile and Christian Stricker
2018-03-13: Weight-Balanced Trees
Authors: Tobias Nipkow and Stefan Dirix
2018-03-12: CakeML
Authors: Lars Hupel and Yu Zhang
2018-03-01: A Theory of Architectural Design Patterns
Author: Diego Marmsoler
2018-02-26: Hoare Logics for Time Bounds
Authors: Maximilian P. L. Haslbeck and Tobias Nipkow
2018-02-06: Treaps
Authors: Maximilian Haslbeck, Manuel Eberl and Tobias Nipkow
2018-02-06: A verified factorization algorithm for integer polynomials with polynomial complexity
Authors: Jose Divasón, Sebastiaan Joosten, René Thiemann and Akihisa Yamada
2018-02-06: First-Order Terms
Authors: Christian Sternagel and René Thiemann
2018-02-06: The Error Function
Author: Manuel Eberl
2018-02-02: A verified LLL algorithm
Authors: Ralph Bottesch, Jose Divasón, Maximilian Haslbeck, Sebastiaan Joosten, René Thiemann and Akihisa Yamada
2018-01-18: Formalization of Bachmair and Ganzinger's Ordered Resolution Prover
Authors: Anders Schlichtkrull, Jasmin Christian Blanchette, Dmitriy Traytel and Uwe Waldmann
2018-01-16: Gromov Hyperbolicity
Author: Sebastien Gouezel
2018-01-11: An Isabelle/HOL formalisation of Green's Theorem
Authors: Mohammad Abdulaziz and Lawrence C. Paulson
2018-01-08: Taylor Models
Authors: Christoph Traut and Fabian Immler

 

2017
2017-12-22: The Falling Factorial of a Sum
Author: Lukas Bulwahn
2017-12-21: The Median-of-Medians Selection Algorithm
Author: Manuel Eberl
2017-12-21: The Mason–Stothers Theorem
Author: Manuel Eberl
2017-12-21: Dirichlet L-Functions and Dirichlet's Theorem
Author: Manuel Eberl
2017-12-19: Operations on Bounded Natural Functors
Authors: Jasmin Christian Blanchette, Andrei Popescu and Dmitriy Traytel
2017-12-18: The string search algorithm by Knuth, Morris and Pratt
Authors: Fabian Hellauer and Peter Lammich
2017-11-22: Stochastic Matrices and the Perron-Frobenius Theorem
Author: René Thiemann
2017-11-09: The IMAP CmRDT
Authors: Tim Jungnickel, Lennart Oldenburg and Matthias Loibl
2017-11-06: Hybrid Multi-Lane Spatial Logic
Author: Sven Linker
2017-10-26: The Kuratowski Closure-Complement Theorem
Authors: Peter Gammie and Gianpaolo Gioiosa
2017-10-19: Transition Systems and Automata
Author: Julian Brunner
2017-10-19: Büchi Complementation
Author: Julian Brunner
2017-10-17: Evaluate Winding Numbers through Cauchy Indices
Author: Wenda Li
2017-10-17: Count the Number of Complex Roots
Author: Wenda Li
2017-10-14: Homogeneous Linear Diophantine Equations
Authors: Florian Messner, Julian Parsert, Jonas Schöpf and Christian Sternagel
2017-10-12: The Hurwitz and Riemann ζ Functions
Author: Manuel Eberl
2017-10-12: Linear Recurrences
Author: Manuel Eberl
2017-10-12: Dirichlet Series
Author: Manuel Eberl
2017-09-21: Computer-assisted Reconstruction and Assessment of E. J. Lowe's Modal Ontological Argument
Authors: David Fuenmayor and Christoph Benzmüller
2017-09-17: Representation and Partial Automation of the Principia Logico-Metaphysica in Isabelle/HOL
Author: Daniel Kirchner
2017-09-06: Anselm's God in Isabelle/HOL
Author: Ben Blumson
2017-09-01: Microeconomics and the First Welfare Theorem
Authors: Julian Parsert and Cezary Kaliszyk
2017-08-20: Root-Balanced Tree
Author: Tobias Nipkow
2017-08-20: Orbit-Stabiliser Theorem with Application to Rotational Symmetries
Author: Jonas Rädle
2017-08-16: The LambdaMu-calculus
Authors: Cristina Matache, Victor B. F. Gomes and Dominic P. Mulligan
2017-07-31: Stewart's Theorem and Apollonius' Theorem
Author: Lukas Bulwahn
2017-07-28: Dynamic Architectures
Author: Diego Marmsoler
2017-07-21: Declarative Semantics for Functional Languages
Author: Jeremy Siek
2017-07-15: HOLCF-Prelude
Authors: Joachim Breitner, Brian Huffman, Neil Mitchell and Christian Sternagel
2017-07-13: Minkowski's Theorem
Author: Manuel Eberl
2017-07-09: Verified Metatheory and Type Inference for a Name-Carrying Simply-Typed Lambda Calculus
Author: Michael Rawson
2017-07-07: A framework for establishing Strong Eventual Consistency for Conflict-free Replicated Datatypes
Authors: Victor B. F. Gomes, Martin Kleppmann, Dominic P. Mulligan and Alastair R. Beresford
2017-07-06: Stone-Kleene Relation Algebras
Author: Walter Guttmann
2017-06-21: Propositional Proof Systems
Authors: Julius Michaelis and Tobias Nipkow
2017-06-13: Partial Semigroups and Convolution Algebras
Authors: Brijesh Dongol, Victor B. F. Gomes, Ian J. Hayes and Georg Struth
2017-06-06: Buffon's Needle Problem
Author: Manuel Eberl
2017-06-01: Formalizing Push-Relabel Algorithms
Authors: Peter Lammich and S. Reza Sefidgar
2017-06-01: Flow Networks and the Min-Cut-Max-Flow Theorem
Authors: Peter Lammich and S. Reza Sefidgar
2017-05-25: Optics
Authors: Simon Foster and Frank Zeyda
2017-05-24: Developing Security Protocols by Refinement
Authors: Christoph Sprenger and Ivano Somaini
2017-05-24: Dictionary Construction
Author: Lars Hupel
2017-05-08: The Floyd-Warshall Algorithm for Shortest Paths
Authors: Simon Wimmer and Peter Lammich
2017-05-05: Probabilistic while loop
Author: Andreas Lochbihler
2017-05-05: Effect polymorphism in higher-order logic
Author: Andreas Lochbihler
2017-05-05: Monad normalisation
Authors: Joshua Schneider, Manuel Eberl and Andreas Lochbihler
2017-05-05: Game-based cryptography in HOL
Authors: Andreas Lochbihler, S. Reza Sefidgar and Bhargav Bhatt
2017-05-05: CryptHOL
Author: Andreas Lochbihler
2017-05-04: Monoidal Categories
Author: Eugene W. Stark
2017-05-01: Types, Tableaus and Gödel’s God in Isabelle/HOL
Authors: David Fuenmayor and Christoph Benzmüller
2017-04-28: Local Lexing
Author: Steven Obua
2017-04-19: Constructor Functions
Author: Lars Hupel
2017-04-18: Lazifying case constants
Author: Lars Hupel
2017-04-06: Subresultants
Authors: Sebastiaan Joosten, René Thiemann and Akihisa Yamada
2017-04-04: Expected Shape of Random Binary Search Trees
Author: Manuel Eberl
2017-03-15: The number of comparisons in QuickSort
Author: Manuel Eberl
2017-03-15: Lower bound on comparison-based sorting algorithms
Author: Manuel Eberl
2017-03-10: The Euler–MacLaurin Formula
Author: Manuel Eberl
2017-02-28: The Group Law for Elliptic Curves
Author: Stefan Berghofer
2017-02-26: Menger's Theorem
Author: Christoph Dittmann
2017-02-13: Differential Dynamic Logic
Author: Brandon Bohrer
2017-02-10: Abstract Soundness
Authors: Jasmin Christian Blanchette, Andrei Popescu and Dmitriy Traytel
2017-02-07: Stone Relation Algebras
Author: Walter Guttmann
2017-01-31: Refining Authenticated Key Agreement with Strong Adversaries
Authors: Joseph Lallemand and Christoph Sprenger
2017-01-24: Bernoulli Numbers
Authors: Lukas Bulwahn and Manuel Eberl
2017-01-17: Minimal Static Single Assignment Form
Authors: Max Wagner and Denis Lohner
2017-01-17: Bertrand's postulate
Authors: Julian Biendarra and Manuel Eberl
2017-01-12: The Transcendence of e
Author: Manuel Eberl
2017-01-08: Formal Network Models and Their Application to Firewall Policies
Authors: Achim D. Brucker, Lukas Brügger and Burkhart Wolff
2017-01-03: Verification of a Diffie-Hellman Password-based Authentication Protocol by Extending the Inductive Method
Author: Pasquale Noce
2017-01-01: First-Order Logic According to Harrison
Authors: Alexander Birch Jensen, Anders Schlichtkrull and Jørgen Villadsen

 

2016
2016-12-30: Concurrent Refinement Algebra and Rely Quotients
Authors: Julian Fell, Ian J. Hayes and Andrius Velykis
2016-12-29: The Twelvefold Way
Author: Lukas Bulwahn
2016-12-20: Proof Strategy Language
Author: Yutaka Nagashima
2016-12-07: Paraconsistency
Authors: Anders Schlichtkrull and Jørgen Villadsen
2016-11-29: COMPLX: A Verification Framework for Concurrent Imperative Programs
Authors: Sidney Amani, June Andronick, Maksym Bortin, Corey Lewis, Christine Rizkallah and Joseph Tuong
2016-11-23: Abstract Interpretation of Annotated Commands
Author: Tobias Nipkow
2016-11-16: Separata: Isabelle tactics for Separation Algebra
Authors: Zhe Hou, David Sanan, Alwen Tiu, Rajeev Gore and Ranald Clouston
2016-11-12: Formalization of Nested Multisets, Hereditary Multisets, and Syntactic Ordinals
Authors: Jasmin Christian Blanchette, Mathias Fleury and Dmitriy Traytel
2016-11-12: Formalization of Knuth–Bendix Orders for Lambda-Free Higher-Order Terms
Authors: Heiko Becker, Jasmin Christian Blanchette, Uwe Waldmann and Daniel Wand
2016-11-10: Expressiveness of Deep Learning
Author: Alexander Bentkamp
2016-10-25: Modal Logics for Nominal Transition Systems
Authors: Tjark Weber, Lars-Henrik Eriksson, Joachim Parrow, Johannes Borgström and Ramunas Gutkovas
2016-10-24: Stable Matching
Author: Peter Gammie
2016-10-21: LOFT — Verified Migration of Linux Firewalls to SDN
Authors: Julius Michaelis and Cornelius Diekmann
2016-10-19: Source Coding Theorem
Authors: Quentin Hibon and Lawrence C. Paulson
2016-10-19: A formal model for the SPARCv8 ISA and a proof of non-interference for the LEON3 processor
Authors: Zhe Hou, David Sanan, Alwen Tiu and Yang Liu
2016-10-14: The Factorization Algorithm of Berlekamp and Zassenhaus
Authors: Jose Divasón, Sebastiaan Joosten, René Thiemann and Akihisa Yamada
2016-10-11: Intersecting Chords Theorem
Author: Lukas Bulwahn
2016-10-05: Lp spaces
Author: Sebastien Gouezel
2016-09-30: Fisher–Yates shuffle
Author: Manuel Eberl
2016-09-29: Allen's Interval Calculus
Author: Fadoua Ghourabi
2016-09-23: Formalization of Recursive Path Orders for Lambda-Free Higher-Order Terms
Authors: Jasmin Christian Blanchette, Uwe Waldmann and Daniel Wand
2016-09-09: Iptables Semantics
Authors: Cornelius Diekmann and Lars Hupel
2016-09-06: A Variant of the Superposition Calculus
Author: Nicolas Peltier
2016-09-06: Stone Algebras
Author: Walter Guttmann
2016-09-01: Stirling's formula
Author: Manuel Eberl
2016-08-31: Routing
Authors: Julius Michaelis and Cornelius Diekmann
2016-08-24: Simple Firewall
Authors: Cornelius Diekmann, Julius Michaelis and Maximilian Haslbeck
2016-08-18: Infeasible Paths Elimination by Symbolic Execution Techniques: Proof of Correctness and Preservation of Paths
Authors: Romain Aissat, Frederic Voisin and Burkhart Wolff
2016-08-12: Formalizing the Edmonds-Karp Algorithm
Authors: Peter Lammich and S. Reza Sefidgar
2016-08-08: The Imperative Refinement Framework
Author: Peter Lammich
2016-08-07: Ptolemy's Theorem
Author: Lukas Bulwahn
2016-07-17: Surprise Paradox
Author: Joachim Breitner
2016-07-14: Pairing Heap
Authors: Hauke Brinkop and Tobias Nipkow
2016-07-05: A Framework for Verifying Depth-First Search Algorithms
Authors: Peter Lammich and René Neumann
2016-07-01: Chamber Complexes, Coxeter Systems, and Buildings
Author: Jeremy Sylvestre
2016-06-30: The Z Property
Authors: Bertram Felgenhauer, Julian Nagele, Vincent van Oostrom and Christian Sternagel
2016-06-30: The Resolution Calculus for First-Order Logic
Author: Anders Schlichtkrull
2016-06-28: IP Addresses
Authors: Cornelius Diekmann, Julius Michaelis and Lars Hupel
2016-06-28: Compositional Security-Preserving Refinement for Concurrent Imperative Programs
Authors: Toby Murray, Robert Sison, Edward Pierzchalski and Christine Rizkallah
2016-06-26: Category Theory with Adjunctions and Limits
Author: Eugene W. Stark
2016-06-26: Cardinality of Multisets
Author: Lukas Bulwahn
2016-06-25: A Dependent Security Type System for Concurrent Imperative Programs
Authors: Toby Murray, Robert Sison, Edward Pierzchalski and Christine Rizkallah
2016-06-21: Catalan Numbers
Author: Manuel Eberl
2016-06-18: Program Construction and Verification Components Based on Kleene Algebra
Authors: Victor B. F. Gomes and Georg Struth
2016-06-13: Conservation of CSP Noninterference Security under Concurrent Composition
Author: Pasquale Noce
2016-06-09: Finite Machine Word Library
Authors: Joel Beeren, Matthew Fernandez, Xin Gao, Gerwin Klein, Rafal Kolanski, Japheth Lim, Corey Lewis, Daniel Matichuk and Thomas Sewell
2016-05-31: Tree Decomposition
Author: Christoph Dittmann
2016-05-24: POSIX Lexing with Derivatives of Regular Expressions
Authors: Fahad Ausaf, Roy Dyckhoff and Christian Urban
2016-05-24: Cardinality of Equivalence Relations
Author: Lukas Bulwahn
2016-05-20: Perron-Frobenius Theorem for Spectral Radius Analysis
Authors: Jose Divasón, Ondřej Kunčar, René Thiemann and Akihisa Yamada
2016-05-20: The meta theory of the Incredible Proof Machine
Authors: Joachim Breitner and Denis Lohner
2016-05-18: A Constructive Proof for FLP
Authors: Benjamin Bisping, Paul-David Brodmann, Tim Jungnickel, Christina Rickmann, Henning Seidler, Anke Stüber, Arno Wilhelm-Weidner, Kirstin Peters and Uwe Nestmann
2016-05-09: A Formal Proof of the Max-Flow Min-Cut Theorem for Countable Networks
Author: Andreas Lochbihler
2016-05-05: Randomised Social Choice Theory
Author: Manuel Eberl
2016-05-04: The Incompatibility of SD-Efficiency and SD-Strategy-Proofness
Author: Manuel Eberl
2016-05-04: Spivey's Generalized Recurrence for Bell Numbers
Author: Lukas Bulwahn
2016-05-02: Gröbner Bases Theory
Authors: Fabian Immler and Alexander Maletzky
2016-04-28: No Faster-Than-Light Observers
Authors: Mike Stannett and István Németi
2016-04-27: Algorithms for Reduced Ordered Binary Decision Diagrams
Authors: Julius Michaelis, Maximilian Haslbeck, Peter Lammich and Lars Hupel
2016-04-27: A formalisation of the Cocke-Younger-Kasami algorithm
Author: Maksym Bortin
2016-04-26: Conservation of CSP Noninterference Security under Sequential Composition
Author: Pasquale Noce
2016-04-12: Kleene Algebras with Domain
Authors: Victor B. F. Gomes, Walter Guttmann, Peter Höfner, Georg Struth and Tjark Weber
2016-03-11: Propositional Resolution and Prime Implicates Generation
Author: Nicolas Peltier
2016-03-08: Timed Automata
Author: Simon Wimmer
2016-03-08: The Cartan Fixed Point Theorems
Author: Lawrence C. Paulson
2016-03-01: Linear Temporal Logic
Author: Salomon Sickert
2016-02-17: Analysis of List Update Algorithms
Authors: Maximilian P.L. Haslbeck and Tobias Nipkow
2016-02-05: Verified Construction of Static Single Assignment Form
Authors: Sebastian Ullrich and Denis Lohner
2016-01-29: Polynomial Interpolation
Authors: René Thiemann and Akihisa Yamada
2016-01-29: Polynomial Factorization
Authors: René Thiemann and Akihisa Yamada
2016-01-20: Knot Theory
Author: T.V.H. Prathamesh
2016-01-18: Tensor Product of Matrices
Author: T.V.H. Prathamesh
2016-01-14: Cardinality of Number Partitions
Author: Lukas Bulwahn

 

2015
2015-12-28: Basic Geometric Properties of Triangles
Author: Manuel Eberl
2015-12-28: The Divergence of the Prime Harmonic Series
Author: Manuel Eberl
2015-12-28: Liouville numbers
Author: Manuel Eberl
2015-12-28: Descartes' Rule of Signs
Author: Manuel Eberl
2015-12-22: The Stern-Brocot Tree
Authors: Peter Gammie and Andreas Lochbihler
2015-12-22: Applicative Lifting
Authors: Andreas Lochbihler and Joshua Schneider
2015-12-22: Algebraic Numbers in Isabelle/HOL
Authors: René Thiemann, Akihisa Yamada and Sebastiaan Joosten
2015-12-12: Cardinality of Set Partitions
Author: Lukas Bulwahn
2015-12-02: Latin Square
Author: Alexander Bentkamp
2015-12-01: Ergodic Theory
Author: Sebastien Gouezel
2015-11-19: Euler's Partition Theorem
Author: Lukas Bulwahn
2015-11-18: The Tortoise and Hare Algorithm
Author: Peter Gammie
2015-11-11: Planarity Certificates
Author: Lars Noschinski
2015-11-02: Positional Determinacy of Parity Games
Author: Christoph Dittmann
2015-09-16: A Meta-Model for the Isabelle API
Authors: Frédéric Tuong and Burkhart Wolff
2015-09-04: Converting Linear Temporal Logic to Deterministic (Generalized) Rabin Automata
Author: Salomon Sickert
2015-08-21: Matrices, Jordan Normal Forms, and Spectral Radius Theory
Authors: René Thiemann and Akihisa Yamada
2015-08-20: Decreasing Diagrams II
Author: Bertram Felgenhauer
2015-08-18: The Inductive Unwinding Theorem for CSP Noninterference Security
Author: Pasquale Noce
2015-08-12: Representations of Finite Groups
Author: Jeremy Sylvestre
2015-08-10: Analysing and Comparing Encodability Criteria for Process Calculi
Authors: Kirstin Peters and Rob van Glabbeek
2015-07-21: Generating Cases from Labeled Subgoals
Author: Lars Noschinski
2015-07-14: Landau Symbols
Author: Manuel Eberl
2015-07-14: The Akra-Bazzi theorem and the Master theorem
Author: Manuel Eberl
2015-07-07: Hermite Normal Form
Authors: Jose Divasón and Jesús Aransay
2015-06-27: Derangements Formula
Author: Lukas Bulwahn
2015-06-11: The Ipurge Unwinding Theorem for CSP Noninterference Security
Author: Pasquale Noce
2015-06-11: The Generic Unwinding Theorem for CSP Noninterference Security
Author: Pasquale Noce
2015-06-11: Binary Multirelations
Authors: Hitoshi Furusawa and Georg Struth
2015-06-11: Reasoning about Lists via List Interleaving
Author: Pasquale Noce
2015-06-07: Parameterized Dynamic Tables
Author: Tobias Nipkow
2015-05-28: Derivatives of Logical Formulas
Author: Dmitriy Traytel
2015-05-27: A Zoo of Probabilistic Systems
Authors: Johannes Hölzl, Andreas Lochbihler and Dmitriy Traytel
2015-04-30: VCG - Combinatorial Vickrey-Clarke-Groves Auctions
Authors: Marco B. Caminati, Manfred Kerber, Christoph Lange and Colin Rowat
2015-04-15: Residuated Lattices
Authors: Victor B. F. Gomes and Georg Struth
2015-04-13: Concurrent IMP
Author: Peter Gammie
2015-04-13: Relaxing Safely: Verified On-the-Fly Garbage Collection for x86-TSO
Authors: Peter Gammie, Tony Hosking and Kai Engelhardt
2015-03-30: Trie
Authors: Andreas Lochbihler and Tobias Nipkow
2015-03-18: Consensus Refined
Authors: Ognjen Maric and Christoph Sprenger
2015-03-11: Deriving class instances for datatypes
Authors: Christian Sternagel and René Thiemann
2015-02-20: The Safety of Call Arity
Author: Joachim Breitner
2015-02-12: QR Decomposition
Authors: Jose Divasón and Jesús Aransay
2015-02-12: Echelon Form
Authors: Jose Divasón and Jesús Aransay
2015-02-05: Finite Automata in Hereditarily Finite Set Theory
Author: Lawrence C. Paulson
2015-01-28: Verification of the UpDown Scheme
Author: Johannes Hölzl

 

2014
2014-11-28: The Unified Policy Framework (UPF)
Authors: Achim D. Brucker, Lukas Brügger and Burkhart Wolff
2014-10-23: Loop freedom of the (untimed) AODV routing protocol
Authors: Timothy Bourke and Peter Höfner
2014-10-13: Lifting Definition Option
Author: René Thiemann
2014-10-10: Stream Fusion in HOL with Code Generation
Authors: Andreas Lochbihler and Alexandra Maximova
2014-10-09: A Verified Compiler for Probability Density Functions
Authors: Manuel Eberl, Johannes Hölzl and Tobias Nipkow
2014-10-08: Formalization of Refinement Calculus for Reactive Systems
Author: Viorel Preoteasa
2014-10-03: XML
Authors: Christian Sternagel and René Thiemann
2014-10-03: Certification Monads
Authors: Christian Sternagel and René Thiemann
2014-09-25: Imperative Insertion Sort
Author: Christian Sternagel
2014-09-19: The Sturm-Tarski Theorem
Author: Wenda Li
2014-09-15: The Cayley-Hamilton Theorem
Authors: Stephan Adelsberger, Stefan Hetzl and Florian Pollak
2014-09-09: The Jordan-Hölder Theorem
Author: Jakob von Raumer
2014-09-04: Priority Queues Based on Braun Trees
Author: Tobias Nipkow
2014-09-03: Gauss-Jordan Algorithm and Its Applications
Authors: Jose Divasón and Jesús Aransay
2014-08-29: Vector Spaces
Author: Holden Lee
2014-08-29: Real-Valued Special Functions: Upper and Lower Bounds
Author: Lawrence C. Paulson
2014-08-13: Skew Heap
Author: Tobias Nipkow
2014-08-12: Splay Tree
Author: Tobias Nipkow
2014-07-29: Haskell's Show Class in Isabelle/HOL
Authors: Christian Sternagel and René Thiemann
2014-07-18: Formal Specification of a Generic Separation Kernel
Authors: Freek Verbeek, Sergey Tverdyshev, Oto Havle, Holger Blasum, Bruno Langenstein, Werner Stephan, Yakoub Nemouchi, Abderrahmane Feliachi, Burkhart Wolff and Julien Schmaltz
2014-07-13: pGCL for Isabelle
Author: David Cock
2014-07-07: Amortized Complexity Verified
Author: Tobias Nipkow
2014-07-04: Network Security Policy Verification
Author: Cornelius Diekmann
2014-07-03: Pop-Refinement
Author: Alessandro Coglio
2014-06-12: Decision Procedures for MSO on Words Based on Derivatives of Regular Expressions
Authors: Dmitriy Traytel and Tobias Nipkow
2014-06-08: Boolean Expression Checkers
Author: Tobias Nipkow
2014-05-28: Promela Formalization
Author: René Neumann
2014-05-28: Converting Linear-Time Temporal Logic to Generalized Büchi Automata
Authors: Alexander Schimpf and Peter Lammich
2014-05-28: Verified Efficient Implementation of Gabow's Strongly Connected Components Algorithm
Author: Peter Lammich
2014-05-28: A Fully Verified Executable LTL Model Checker
Authors: Javier Esparza, Peter Lammich, René Neumann, Tobias Nipkow, Alexander Schimpf and Jan-Georg Smaus
2014-05-28: The CAVA Automata Library
Author: Peter Lammich
2014-05-23: Transitive closure according to Roy-Floyd-Warshall
Author: Makarius Wenzel
2014-05-23: Noninterference Security in Communicating Sequential Processes
Author: Pasquale Noce
2014-05-21: Regular Algebras
Authors: Simon Foster and Georg Struth
2014-04-28: Formalisation and Analysis of Component Dependencies
Author: Maria Spichkova
2014-04-23: A Formalization of Declassification with WHAT-and-WHERE-Security
Authors: Sylvia Grewe, Alexander Lux, Heiko Mantel and Jens Sauer
2014-04-23: A Formalization of Strong Security
Authors: Sylvia Grewe, Alexander Lux, Heiko Mantel and Jens Sauer
2014-04-23: A Formalization of Assumptions and Guarantees for Compositional Noninterference
Authors: Sylvia Grewe, Heiko Mantel and Daniel Schoepe
2014-04-22: Bounded-Deducibility Security
Authors: Andrei Popescu and Peter Lammich
2014-04-16: A shallow embedding of HyperCTL*
Authors: Markus N. Rabe, Peter Lammich and Andrei Popescu
2014-04-16: Abstract Completeness
Authors: Jasmin Christian Blanchette, Andrei Popescu and Dmitriy Traytel
2014-04-13: Discrete Summation
Author: Florian Haftmann
2014-04-03: Syntax and semantics of a GPU kernel programming language
Author: John Wickerson
2014-03-11: Probabilistic Noninterference
Authors: Andrei Popescu and Johannes Hölzl
2014-03-08: Mechanization of the Algebra for Wireless Networks (AWN)
Author: Timothy Bourke
2014-02-18: Mutually Recursive Partial Functions
Author: René Thiemann
2014-02-13: Properties of Random Graphs -- Subgraph Containment
Author: Lars Hupel
2014-02-11: Verification of Selection and Heap Sort Using Locales
Author: Danijela Petrovic
2014-02-07: Affine Arithmetic
Author: Fabian Immler
2014-02-06: Implementing field extensions of the form Q[sqrt(b)]
Author: René Thiemann
2014-01-30: Unified Decision Procedures for Regular Expression Equivalence
Authors: Tobias Nipkow and Dmitriy Traytel
2014-01-28: Secondary Sylow Theorems
Author: Jakob von Raumer
2014-01-25: Relation Algebra
Authors: Alasdair Armstrong, Simon Foster, Georg Struth and Tjark Weber
2014-01-23: Kleene Algebra with Tests and Demonic Refinement Algebras
Authors: Alasdair Armstrong, Victor B. F. Gomes and Georg Struth
2014-01-16: Featherweight OCL: A Proposal for a Machine-Checked Formal Semantics for OCL 2.5
Authors: Achim D. Brucker, Frédéric Tuong and Burkhart Wolff
2014-01-11: Sturm's Theorem
Author: Manuel Eberl
2014-01-11: Compositional Properties of Crypto-Based Components
Author: Maria Spichkova

 

2013
2013-12-01: A General Method for the Proof of Theorems on Tail-recursive Functions
Author: Pasquale Noce
2013-11-17: Gödel's Incompleteness Theorems
Author: Lawrence C. Paulson
2013-11-17: The Hereditarily Finite Sets
Author: Lawrence C. Paulson
2013-11-15: A Codatatype of Formal Languages
Author: Dmitriy Traytel
2013-11-14: Stream Processing Components: Isabelle/HOL Formalisation and Case Studies
Author: Maria Spichkova
2013-11-12: Gödel's God in Isabelle/HOL
Authors: Christoph Benzmüller and Bruno Woltzenlogel Paleo
2013-11-01: Decreasing Diagrams
Author: Harald Zankl
2013-10-02: Automatic Data Refinement
Author: Peter Lammich
2013-09-17: Native Word
Author: Andreas Lochbihler
2013-07-27: A Formal Model of IEEE Floating Point Arithmetic
Author: Lei Yu
2013-07-22: Pratt's Primality Certificates
Authors: Simon Wimmer and Lars Noschinski
2013-07-22: Lehmer's Theorem
Authors: Simon Wimmer and Lars Noschinski
2013-07-19: The Königsberg Bridge Problem and the Friendship Theorem
Author: Wenda Li
2013-06-27: Sound and Complete Sort Encodings for First-Order Logic
Authors: Jasmin Christian Blanchette and Andrei Popescu
2013-05-22: An Axiomatic Characterization of the Single-Source Shortest Path Problem
Author: Christine Rizkallah
2013-04-28: Graph Theory
Author: Lars Noschinski
2013-04-15: Light-weight Containers
Author: Andreas Lochbihler
2013-02-21: Nominal 2
Authors: Christian Urban, Stefan Berghofer and Cezary Kaliszyk
2013-01-31: The Correctness of Launchbury's Natural Semantics for Lazy Evaluation
Author: Joachim Breitner
2013-01-19: Ribbon Proofs
Author: John Wickerson
2013-01-16: Rank-Nullity Theorem in Linear Algebra
Authors: Jose Divasón and Jesús Aransay
2013-01-15: Kleene Algebra
Authors: Alasdair Armstrong, Georg Struth and Tjark Weber
2013-01-03: Computing N-th Roots using the Babylonian Method
Author: René Thiemann

 

2012
2012-11-14: A Separation Logic Framework for Imperative HOL
Authors: Peter Lammich and Rene Meis
2012-11-02: Open Induction
Authors: Mizuhito Ogawa and Christian Sternagel
2012-10-30: The independence of Tarski's Euclidean axiom
Author: T. J. M. Makarios
2012-10-27: Bondy's Theorem
Authors: Jeremy Avigad and Stefan Hetzl
2012-09-10: Possibilistic Noninterference
Authors: Andrei Popescu and Johannes Hölzl
2012-08-07: Generating linear orders for datatypes
Author: René Thiemann
2012-08-05: Proving the Impossibility of Trisecting an Angle and Doubling the Cube
Authors: Ralph Romanos and Lawrence C. Paulson
2012-07-27: Verifying Fault-Tolerant Distributed Algorithms in the Heard-Of Model
Authors: Henri Debrat and Stephan Merz
2012-07-01: Logical Relations for PCF
Author: Peter Gammie
2012-06-26: Type Constructor Classes and Monad Transformers
Author: Brian Huffman
2012-05-29: Psi-calculi in Isabelle
Author: Jesper Bengtson
2012-05-29: The pi-calculus in nominal logic
Author: Jesper Bengtson
2012-05-29: CCS in nominal logic
Author: Jesper Bengtson
2012-05-27: Isabelle/Circus
Authors: Abderrahmane Feliachi, Burkhart Wolff and Marie-Claude Gaudel
2012-05-11: Separation Algebra
Authors: Gerwin Klein, Rafal Kolanski and Andrew Boyton
2012-05-07: Stuttering Equivalence
Author: Stephan Merz
2012-05-02: Inductive Study of Confidentiality
Author: Giampaolo Bella
2012-04-26: Ordinary Differential Equations
Authors: Fabian Immler and Johannes Hölzl
2012-04-13: Well-Quasi-Orders
Author: Christian Sternagel
2012-03-01: Abortable Linearizable Modules
Authors: Rachid Guerraoui, Viktor Kuncak and Giuliano Losa
2012-02-29: Executable Transitive Closures
Author: René Thiemann
2012-02-06: A Probabilistic Proof of the Girth-Chromatic Number Theorem
Author: Lars Noschinski
2012-01-30: Refinement for Monadic Programs
Author: Peter Lammich
2012-01-30: Dijkstra's Shortest Path Algorithm
Authors: Benedikt Nordhoff and Peter Lammich
2012-01-03: Markov Models
Authors: Johannes Hölzl and Tobias Nipkow

 

2011
2011-11-19: A Definitional Encoding of TLA* in Isabelle/HOL
Authors: Gudmund Grov and Stephan Merz
2011-11-09: Efficient Mergesort
Author: Christian Sternagel
2011-09-22: Pseudo Hoops
Authors: George Georgescu, Laurentiu Leustean and Viorel Preoteasa
2011-09-22: Algebra of Monotonic Boolean Transformers
Author: Viorel Preoteasa
2011-09-22: Lattice Properties
Author: Viorel Preoteasa
2011-08-26: The Myhill-Nerode Theorem Based on Regular Expressions
Authors: Chunhan Wu, Xingyuan Zhang and Christian Urban
2011-08-19: Gauss-Jordan Elimination for Matrices Represented as Functions
Author: Tobias Nipkow
2011-07-21: Maximum Cardinality Matching
Author: Christine Rizkallah
2011-05-17: Knowledge-based programs
Author: Peter Gammie
2011-04-01: The General Triangle Is Unique
Author: Joachim Breitner
2011-03-14: Executable Transitive Closures of Finite Relations
Authors: Christian Sternagel and René Thiemann
2011-02-23: Interval Temporal Logic on Natural Numbers
Author: David Trachtenherz
2011-02-23: Infinite Lists
Author: David Trachtenherz
2011-02-23: AutoFocus Stream Processing for Single-Clocking and Multi-Clocking Semantics
Author: David Trachtenherz
2011-02-07: Lightweight Java
Authors: Rok Strniša and Matthew Parkinson
2011-01-10: RIPEMD-160
Author: Fabian Immler
2011-01-08: Lower Semicontinuous Functions
Author: Bogdan Grechuk

 

2010
2010-12-17: Hall's Marriage Theorem
Authors: Dongchen Jiang and Tobias Nipkow
2010-11-16: Shivers' Control Flow Analysis
Author: Joachim Breitner
2010-10-28: Finger Trees
Authors: Benedikt Nordhoff, Stefan Körner and Peter Lammich
2010-10-28: Functional Binomial Queues
Author: René Neumann
2010-10-28: Binomial Heaps and Skew Binomial Heaps
Authors: Rene Meis, Finn Nielsen and Peter Lammich
2010-08-29: Strong Normalization of Moggis's Computational Metalanguage
Author: Christian Doczkal
2010-08-10: Executable Multivariate Polynomials
Authors: Christian Sternagel, René Thiemann, Alexander Maletzky, Fabian Immler, Florian Haftmann, Andreas Lochbihler and Alexander Bentkamp
2010-08-08: Formalizing Statecharts using Hierarchical Automata
Authors: Steffen Helke and Florian Kammüller
2010-06-24: Free Groups
Author: Joachim Breitner
2010-06-20: Category Theory
Author: Alexander Katovsky
2010-06-17: Executable Matrix Operations on Matrices of Arbitrary Dimensions
Authors: Christian Sternagel and René Thiemann
2010-06-14: Abstract Rewriting
Authors: Christian Sternagel and René Thiemann
2010-05-28: Verification of the Deutsch-Schorr-Waite Graph Marking Algorithm using Data Refinement
Authors: Viorel Preoteasa and Ralph-Johan Back
2010-05-28: Semantics and Data Refinement of Invariant Based Programs
Authors: Viorel Preoteasa and Ralph-Johan Back
2010-05-22: A Complete Proof of the Robbins Conjecture
Author: Matthew Wampler-Doty
2010-05-12: Regular Sets and Expressions
Authors: Alexander Krauss and Tobias Nipkow
2010-04-30: Locally Nameless Sigma Calculus
Authors: Ludovic Henrio, Florian Kammüller, Bianca Lutz and Henry Sudhof
2010-03-29: Free Boolean Algebra
Author: Brian Huffman
2010-03-23: Inter-Procedural Information Flow Noninterference via Slicing
Author: Daniel Wasserrab
2010-03-23: Information Flow Noninterference via Slicing
Author: Daniel Wasserrab
2010-02-20: List Index
Author: Tobias Nipkow
2010-02-12: Coinductive
Author: Andreas Lochbihler

 

2009
2009-12-09: A Fast SAT Solver for Isabelle in Standard ML
Author: Armin Heller
2009-12-03: Formalizing the Logic-Automaton Connection
Authors: Stefan Berghofer and Markus Reiter
2009-11-25: Tree Automata
Author: Peter Lammich
2009-11-25: Collections Framework
Author: Peter Lammich
2009-11-22: Perfect Number Theorem
Author: Mark Ijbema
2009-11-13: Backing up Slicing: Verifying the Interprocedural Two-Phase Horwitz-Reps-Binkley Slicer
Author: Daniel Wasserrab
2009-10-30: The Worker/Wrapper Transformation
Author: Peter Gammie
2009-09-01: Ordinals and Cardinals
Author: Andrei Popescu
2009-08-28: Invertibility in Sequent Calculi
Author: Peter Chapman
2009-08-04: An Example of a Cofinitary Group in Isabelle/HOL
Author: Bart Kastermans
2009-05-06: Code Generation for Functions as Data
Author: Andreas Lochbihler
2009-04-29: Stream Fusion
Author: Brian Huffman

 

2008
2008-12-12: A Bytecode Logic for JML and Types
Authors: Lennart Beringer and Martin Hofmann
2008-11-10: Secure information flow and program logics
Authors: Lennart Beringer and Martin Hofmann
2008-11-09: Some classical results in Social Choice Theory
Author: Peter Gammie
2008-11-07: Fun With Tilings
Authors: Tobias Nipkow and Lawrence C. Paulson
2008-10-15: The Textbook Proof of Huffman's Algorithm
Author: Jasmin Christian Blanchette
2008-09-16: Towards Certified Slicing
Author: Daniel Wasserrab
2008-09-02: A Correctness Proof for the Volpano/Smith Security Typing System
Authors: Gregor Snelting and Daniel Wasserrab
2008-09-01: Arrow and Gibbard-Satterthwaite
Author: Tobias Nipkow
2008-08-26: Fun With Functions
Author: Tobias Nipkow
2008-07-23: Formal Verification of Modern SAT Solvers
Author: Filip Marić
2008-04-05: Recursion Theory I
Author: Michael Nedzelsky
2008-02-29: A Sequential Imperative Programming Language Syntax, Semantics, Hoare Logics and Verification Environment
Author: Norbert Schirmer
2008-02-29: BDD Normalisation
Authors: Veronika Ortner and Norbert Schirmer
2008-02-18: Normalization by Evaluation
Authors: Klaus Aehlig and Tobias Nipkow
2008-01-11: Quantifier Elimination for Linear Arithmetic
Author: Tobias Nipkow

 

2007
2007-12-14: Formalization of Conflict Analysis of Programs with Procedures, Thread Creation, and Monitors
Authors: Peter Lammich and Markus Müller-Olm
2007-12-03: Jinja with Threads
Author: Andreas Lochbihler
2007-11-06: Much Ado About Two
Author: Sascha Böhme
2007-08-12: Sums of Two and Four Squares
Author: Roelof Oosterhuis
2007-08-12: Fermat's Last Theorem for Exponents 3 and 4 and the Parametrisation of Pythagorean Triples
Author: Roelof Oosterhuis
2007-08-08: Fundamental Properties of Valuation Theory and Hensel's Lemma
Author: Hidetsune Kobayashi
2007-08-02: POPLmark Challenge Via de Bruijn Indices
Author: Stefan Berghofer
2007-08-02: First-Order Logic According to Fitting
Author: Stefan Berghofer

 

2006
2006-09-09: Hotel Key Card System
Author: Tobias Nipkow
2006-08-08: Abstract Hoare Logics
Author: Tobias Nipkow
2006-05-22: Flyspeck I: Tame Graphs
Authors: Gertrud Bauer and Tobias Nipkow
2006-05-15: CoreC++
Author: Daniel Wasserrab
2006-03-31: A Theory of Featherweight Java in Isabelle/HOL
Authors: J. Nathan Foster and Dimitrios Vytiniotis
2006-03-15: Instances of Schneider's generalized protocol of clock synchronization
Author: Damián Barsotti
2006-03-14: Cauchy's Mean Theorem and the Cauchy-Schwarz Inequality
Author: Benjamin Porter

 

2005
2005-11-11: Countable Ordinals
Author: Brian Huffman
2005-10-12: Fast Fourier Transform
Author: Clemens Ballarin
2005-06-24: Formalization of a Generalized Protocol for Clock Synchronization
Author: Alwen Tiu
2005-06-22: Proving the Correctness of Disk Paxos
Authors: Mauro Jaskelioff and Stephan Merz
2005-06-20: Jive Data and Store Model
Authors: Nicole Rauch and Norbert Schirmer
2005-06-01: Jinja is not Java
Authors: Gerwin Klein and Tobias Nipkow
2005-05-02: SHA1, RSA, PSS and more
Authors: Christina Lindenberg and Kai Wirt
2005-04-21: Category Theory to Yoneda's Lemma
Author: Greg O'Keefe

 

2004
2004-12-09: File Refinement
Authors: Karen Zee and Viktor Kuncak
2004-11-19: Integration theory and random variables
Author: Stefan Richter
2004-09-28: A Mechanically Verified, Efficient, Sound and Complete Theorem Prover For First Order Logic
Author: Tom Ridge
2004-09-20: Ramsey's theorem, infinitary version
Author: Tom Ridge
2004-09-20: Completeness theorem
Authors: James Margetson and Tom Ridge
2004-07-09: Compiling Exceptions Correctly
Author: Tobias Nipkow
2004-06-24: Depth First Search
Authors: Toshiaki Nishihara and Yasuhiko Minamide
2004-05-18: Groups, Rings and Modules
Authors: Hidetsune Kobayashi, L. Chen and H. Murao
2004-04-26: Topology
Author: Stefan Friedrich
2004-04-26: Lazy Lists II
Author: Stefan Friedrich
2004-04-05: Binary Search Trees
Author: Viktor Kuncak
2004-03-30: Functional Automata
Author: Tobias Nipkow
2004-03-19: Mini ML
Authors: Wolfgang Naraschewski and Tobias Nipkow
2004-03-19: AVL Trees
Authors: Tobias Nipkow and Cornelia Pusch
\ No newline at end of file diff --git a/web/rss.xml b/web/rss.xml --- a/web/rss.xml +++ b/web/rss.xml @@ -1,594 +1,614 @@ 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. - 12 Mar 2021 00:00:00 +0000 + 17 Mar 2021 00:00:00 +0000 + + Constructive Cryptography in HOL: the Communication Modeling Aspect + https://www.isa-afp.org/entries/Constructive_Cryptography_CM.html + https://www.isa-afp.org/entries/Constructive_Cryptography_CM.html + Andreas Lochbihler, S. Reza Sefidgar + 17 Mar 2021 00:00:00 +0000 + +Constructive Cryptography (CC) [<a +href="https://conference.iiis.tsinghua.edu.cn/ICS2011/content/papers/14.html">ICS +2011</a>, <a +href="https://doi.org/10.1007/978-3-642-27375-9_3">TOSCA +2011</a>, <a +href="https://doi.org/10.1007/978-3-662-53641-4_1">TCC +2016</a>] introduces an abstract approach to composable security +statements that allows one to focus on a particular aspect of security +proofs at a time. Instead of proving the properties of concrete +systems, CC studies system classes, i.e., the shared behavior of +similar systems, and their transformations. Modeling of systems +communication plays a crucial role in composability and reusability of +security statements; yet, this aspect has not been studied in any of +the existing CC results. We extend our previous CC formalization +[<a href="https://isa-afp.org/entries/Constructive_Cryptography.html">Constructive_Cryptography</a>, +<a href="https://doi.org/10.1109/CSF.2019.00018">CSF +2019</a>] with a new semantic domain called Fused Resource +Templates (FRT) that abstracts over the systems communication patterns +in CC proofs. This widens the scope of cryptography proof +formalizations in the CryptHOL library [<a +href="https://isa-afp.org/entries/CryptHOL.html">CryptHOL</a>, +<a +href="https://doi.org/10.1007/978-3-662-49498-1_20">ESOP +2016</a>, <a +href="https://doi.org/10.1007/s00145-019-09341-z">J +Cryptol 2020</a>]. This formalization is described in <a +href="http://www.andreas-lochbihler.de/pub/basin2021.pdf">Abstract +Modeling of Systems Communication in Constructive Cryptography using +CryptHOL</a>. + Two algorithms based on modular arithmetic: lattice basis reduction and Hermite normal form computation https://www.isa-afp.org/entries/Modular_arithmetic_LLL_and_HNF_algorithms.html https://www.isa-afp.org/entries/Modular_arithmetic_LLL_and_HNF_algorithms.html Ralph Bottesch, Jose Divasón, René Thiemann 12 Mar 2021 00:00:00 +0000 We verify two algorithms for which modular arithmetic plays an essential role: Storjohann's variant of the LLL lattice basis reduction algorithm and Kopparty's algorithm for computing the Hermite normal form of a matrix. To do this, we also formalize some facts about the modulo operation with symmetric range. Our implementations are based on the original papers, but are otherwise efficient. For basis reduction we formalize two versions: one that includes all of the optimizations/heuristics from Storjohann's paper, and one excluding a heuristic that we observed to often decrease efficiency. We also provide a fast, self-contained certifier for basis reduction, based on the efficient Hermite normal form algorithm. Quantum projective measurements and the CHSH inequality https://www.isa-afp.org/entries/Projective_Measurements.html https://www.isa-afp.org/entries/Projective_Measurements.html Mnacho Echenim 03 Mar 2021 00:00:00 +0000 This work contains a formalization of quantum projective measurements, also known as von Neumann measurements, which are based on elements of spectral theory. We also formalized the CHSH inequality, an inequality involving expectations in a probability space that is violated by quantum measurements, thus proving that quantum mechanics cannot be modeled with an underlying local hidden-variable theory. The Hermite–Lindemann–Weierstraß Transcendence Theorem https://www.isa-afp.org/entries/Hermite_Lindemann.html https://www.isa-afp.org/entries/Hermite_Lindemann.html Manuel Eberl 03 Mar 2021 00:00:00 +0000 <p>This article provides a formalisation of the Hermite-Lindemann-Weierstraß Theorem (also known as simply Hermite-Lindemann or Lindemann-Weierstraß). This theorem is one of the crowning achievements of 19th century number theory.</p> <p>The theorem states that if $\alpha_1, \ldots, \alpha_n\in\mathbb{C}$ are algebraic numbers that are linearly independent over $\mathbb{Z}$, then $e^{\alpha_1},\ldots,e^{\alpha_n}$ are algebraically independent over $\mathbb{Q}$.</p> <p>Like the <a href="https://doi.org/10.1007/978-3-319-66107-0_5">previous formalisation in Coq by Bernard</a>, I proceeded by formalising <a href="https://doi.org/10.1017/CBO9780511565977">Baker's version of the theorem and proof</a> and then deriving the original one from that. Baker's version states that for any algebraic numbers $\beta_1, \ldots, \beta_n\in\mathbb{C}$ and distinct algebraic numbers $\alpha_i, \ldots, \alpha_n\in\mathbb{C}$, we have $\beta_1 e^{\alpha_1} + \ldots + \beta_n e^{\alpha_n} = 0$ if and only if all the $\beta_i$ are zero.</p> <p>This has a number of direct corollaries, e.g.:</p> <ul> <li>$e$ and $\pi$ are transcendental</li> <li>$e^z$, $\sin z$, $\tan z$, etc. are transcendental for algebraic $z\in\mathbb{C}\setminus\{0\}$</li> <li>$\ln z$ is transcendental for algebraic $z\in\mathbb{C}\setminus\{0, 1\}$</li> </ul> Mereology https://www.isa-afp.org/entries/Mereology.html https://www.isa-afp.org/entries/Mereology.html Ben Blumson 01 Mar 2021 00:00:00 +0000 We use Isabelle/HOL to verify elementary theorems and alternative axiomatizations of classical extensional mereology. The Sunflower Lemma of Erdős and Rado https://www.isa-afp.org/entries/Sunflowers.html https://www.isa-afp.org/entries/Sunflowers.html René Thiemann 25 Feb 2021 00:00:00 +0000 We formally define sunflowers and provide a formalization of the sunflower lemma of Erd&odblac;s and Rado: whenever a set of size-<i>k</i>-sets has a larger cardinality than <i>(r - 1)<sup>k</sup> &middot; k!</i>, then it contains a sunflower of cardinality <i>r</i>. A Verified Imperative Implementation of B-Trees https://www.isa-afp.org/entries/BTree.html https://www.isa-afp.org/entries/BTree.html Niels Mündler 24 Feb 2021 00:00:00 +0000 In this work, we use the interactive theorem prover Isabelle/HOL to verify an imperative implementation of the classical B-tree data structure invented by Bayer and McCreight [ACM 1970]. The implementation supports set membership and insertion queries with efficient binary search for intra-node navigation. This is accomplished by first specifying the structure abstractly in the functional modeling language HOL and proving functional correctness. Using manual refinement, we derive an imperative implementation in Imperative/HOL. We show the validity of this refinement using the separation logic utilities from the <a href="https://www.isa-afp.org/entries/Refine_Imperative_HOL.html"> Isabelle Refinement Framework </a> . The code can be exported to the programming languages SML and Scala. We examine the runtime of all operations indirectly by reproducing results of the logarithmic relationship between height and the number of nodes. The results are discussed in greater detail in the corresponding <a href="https://mediatum.ub.tum.de/1596550">Bachelor's Thesis</a>. Formal Puiseux Series https://www.isa-afp.org/entries/Formal_Puiseux_Series.html https://www.isa-afp.org/entries/Formal_Puiseux_Series.html Manuel Eberl 17 Feb 2021 00:00:00 +0000 <p>Formal Puiseux series are generalisations of formal power series and formal Laurent series that also allow for fractional exponents. They have the following general form: \[\sum_{i=N}^\infty a_{i/d} X^{i/d}\] where <em>N</em> is an integer and <em>d</em> is a positive integer.</p> <p>This entry defines these series including their basic algebraic properties. Furthermore, it proves the Newton–Puiseux Theorem, namely that the Puiseux series over an algebraically closed field of characteristic 0 are also algebraically closed.</p> The Laws of Large Numbers https://www.isa-afp.org/entries/Laws_of_Large_Numbers.html https://www.isa-afp.org/entries/Laws_of_Large_Numbers.html Manuel Eberl 10 Feb 2021 00:00:00 +0000 <p>The Law of Large Numbers states that, informally, if one performs a random experiment $X$ many times and takes the average of the results, that average will be very close to the expected value $E[X]$.</p> <p> More formally, let $(X_i)_{i\in\mathbb{N}}$ be a sequence of independently identically distributed random variables whose expected value $E[X_1]$ exists. Denote the running average of $X_1, \ldots, X_n$ as $\overline{X}_n$. Then:</p> <ul> <li>The Weak Law of Large Numbers states that $\overline{X}_{n} \longrightarrow E[X_1]$ in probability for $n\to\infty$, i.e. $\mathcal{P}(|\overline{X}_{n} - E[X_1]| > \varepsilon) \longrightarrow 0$ as $n\to\infty$ for any $\varepsilon > 0$.</li> <li>The Strong Law of Large Numbers states that $\overline{X}_{n} \longrightarrow E[X_1]$ almost surely for $n\to\infty$, i.e. $\mathcal{P}(\overline{X}_{n} \longrightarrow E[X_1]) = 1$.</li> </ul> <p>In this entry, I formally prove the strong law and from it the weak law. The approach used for the proof of the strong law is a particularly quick and slick one based on ergodic theory, which was formalised by Gouëzel in another AFP entry.</p> Tarski's Parallel Postulate implies the 5th Postulate of Euclid, the Postulate of Playfair and the original Parallel Postulate of Euclid https://www.isa-afp.org/entries/IsaGeoCoq.html https://www.isa-afp.org/entries/IsaGeoCoq.html Roland Coghetto 31 Jan 2021 00:00:00 +0000 <p>The <a href="https://geocoq.github.io/GeoCoq/">GeoCoq library</a> contains a formalization of geometry using the Coq proof assistant. It contains both proofs about the foundations of geometry and high-level proofs in the same style as in high school. We port a part of the GeoCoq 2.4.0 library to Isabelle/HOL: more precisely, the files Chap02.v to Chap13_3.v, suma.v as well as the associated definitions and some useful files for the demonstration of certain parallel postulates. The synthetic approach of the demonstrations is directly inspired by those contained in GeoCoq. The names of the lemmas and theorems used are kept as far as possible as well as the definitions. </p> <p>It should be noted that T.J.M. Makarios has done <a href="https://www.isa-afp.org/entries/Tarskis_Geometry.html">some proofs in Tarski's Geometry</a>. It uses a definition that does not quite coincide with the definition used in Geocoq and here. Furthermore, corresponding definitions in the <a href="https://www.isa-afp.org/entries/Poincare_Disc.html">Poincaré Disc Model development</a> are not identical to those defined in GeoCoq. </p> <p>In the last part, it is formalized that, in the neutral/absolute space, the axiom of the parallels of Tarski's system implies the Playfair axiom, the 5th postulate of Euclid and Euclid's original parallel postulate. These proofs, which are not constructive, are directly inspired by Pierre Boutry, Charly Gries, Julien Narboux and Pascal Schreck. </p> Solution to the xkcd Blue Eyes puzzle https://www.isa-afp.org/entries/Blue_Eyes.html https://www.isa-afp.org/entries/Blue_Eyes.html Jakub Kądziołka 30 Jan 2021 00:00:00 +0000 In a <a href="https://xkcd.com/blue_eyes.html">puzzle published by Randall Munroe</a>, perfect logicians forbidden from communicating are stranded on an island, and may only leave once they have figured out their own eye color. We present a method of modeling the behavior of perfect logicians and formalize a solution of the puzzle. Hood-Melville Queue https://www.isa-afp.org/entries/Hood_Melville_Queue.html https://www.isa-afp.org/entries/Hood_Melville_Queue.html Alejandro Gómez-Londoño 18 Jan 2021 00:00:00 +0000 This is a verified implementation of a constant time queue. The original design is due to <a href="https://doi.org/10.1016/0020-0190(81)90030-2">Hood and Melville</a>. This formalization follows the presentation in <em>Purely Functional Data Structures</em>by Okasaki. JinjaDCI: a Java semantics with dynamic class initialization https://www.isa-afp.org/entries/JinjaDCI.html https://www.isa-afp.org/entries/JinjaDCI.html Susannah Mansky 11 Jan 2021 00:00:00 +0000 We extend Jinja to include static fields, methods, and instructions, and dynamic class initialization, based on the Java SE 8 specification. This includes extension of definitions and proofs. This work is partially described in Mansky and Gunter's paper at CPP 2019 and Mansky's doctoral thesis (UIUC, 2020). Cofinality and the Delta System Lemma https://www.isa-afp.org/entries/Delta_System_Lemma.html https://www.isa-afp.org/entries/Delta_System_Lemma.html Pedro Sánchez Terraf 27 Dec 2020 00:00:00 +0000 We formalize the basic results on cofinality of linearly ordered sets and ordinals and Šanin’s Lemma for uncountable families of finite sets. This last result is used to prove the countable chain condition for Cohen posets. We work in the set theory framework of Isabelle/ZF, using the Axiom of Choice as needed. Topological semantics for paraconsistent and paracomplete logics https://www.isa-afp.org/entries/Topological_Semantics.html https://www.isa-afp.org/entries/Topological_Semantics.html David Fuenmayor 17 Dec 2020 00:00:00 +0000 We introduce a generalized topological semantics for paraconsistent and paracomplete logics by drawing upon early works on topological Boolean algebras (cf. works by Kuratowski, Zarycki, McKinsey & Tarski, etc.). In particular, this work exemplarily illustrates the shallow semantical embeddings approach (<a href="http://dx.doi.org/10.1007/s11787-012-0052-y">SSE</a>) employing the proof assistant Isabelle/HOL. By means of the SSE technique we can effectively harness theorem provers, model finders and 'hammers' for reasoning with quantified non-classical logics. Relational Minimum Spanning Tree Algorithms https://www.isa-afp.org/entries/Relational_Minimum_Spanning_Trees.html https://www.isa-afp.org/entries/Relational_Minimum_Spanning_Trees.html Walter Guttmann, Nicolas Robinson-O'Brien 08 Dec 2020 00:00:00 +0000 We verify the correctness of Prim's, Kruskal's and Borůvka's minimum spanning tree algorithms based on algebras for aggregation and minimisation. Inline Caching and Unboxing Optimization for Interpreters https://www.isa-afp.org/entries/Interpreter_Optimizations.html https://www.isa-afp.org/entries/Interpreter_Optimizations.html Martin Desharnais 07 Dec 2020 00:00:00 +0000 This Isabelle/HOL formalization builds on the <em>VeriComp</em> entry of the <em>Archive of Formal Proofs</em> to provide the following contributions: <ul> <li>an operational semantics for a realistic virtual machine (Std) for dynamically typed programming languages;</li> <li>the formalization of an inline caching optimization (Inca), a proof of bisimulation with (Std), and a compilation function;</li> <li>the formalization of an unboxing optimization (Ubx), a proof of bisimulation with (Inca), and a simple compilation function.</li> </ul> This formalization was described in the CPP 2021 paper <em>Towards Efficient and Verified Virtual Machines for Dynamic Languages</em> The Relational Method with Message Anonymity for the Verification of Cryptographic Protocols https://www.isa-afp.org/entries/Relational_Method.html https://www.isa-afp.org/entries/Relational_Method.html Pasquale Noce 05 Dec 2020 00:00:00 +0000 This paper introduces a new method for the formal verification of cryptographic protocols, the relational method, derived from Paulson's inductive method by means of some enhancements aimed at streamlining formal definitions and proofs, specially for protocols using public key cryptography. Moreover, this paper proposes a method to formalize a further security property, message anonymity, in addition to message confidentiality and authenticity. The relational method, including message anonymity, is then applied to the verification of a sample authentication protocol, comprising Password Authenticated Connection Establishment (PACE) with Chip Authentication Mapping followed by the explicit verification of an additional password over the PACE secure channel. Isabelle Marries Dirac: a Library for Quantum Computation and Quantum Information https://www.isa-afp.org/entries/Isabelle_Marries_Dirac.html https://www.isa-afp.org/entries/Isabelle_Marries_Dirac.html Anthony Bordg, Hanna Lachnitt, Yijun He 22 Nov 2020 00:00:00 +0000 This work is an effort to formalise some quantum algorithms and results in quantum information theory. Formal methods being critical for the safety and security of algorithms and protocols, we foresee their widespread use for quantum computing in the future. We have developed a large library for quantum computing in Isabelle based on a matrix representation for quantum circuits, successfully formalising the no-cloning theorem, quantum teleportation, Deutsch's algorithm, the Deutsch-Jozsa algorithm and the quantum Prisoner's Dilemma. The HOL-CSP Refinement Toolkit https://www.isa-afp.org/entries/CSP_RefTK.html https://www.isa-afp.org/entries/CSP_RefTK.html Safouan Taha, Burkhart Wolff, Lina Ye 19 Nov 2020 00:00:00 +0000 We use a formal development for CSP, called HOL-CSP2.0, to analyse a family of refinement notions, comprising classic and new ones. This analysis enables to derive a number of properties that allow to deepen the understanding of these notions, in particular with respect to specification decomposition principles for the case of infinite sets of events. The established relations between the refinement relations help to clarify some obscure points in the CSP literature, but also provide a weapon for shorter refinement proofs. Furthermore, we provide a framework for state-normalisation allowing to formally reason on parameterised process architectures. As a result, we have a modern environment for formal proofs of concurrent systems that allow for the combination of general infinite processes with locally finite ones in a logically safe way. We demonstrate these verification-techniques for classical, generalised examples: The CopyBuffer for arbitrary data and the Dijkstra's Dining Philosopher Problem of arbitrary size. Verified SAT-Based AI Planning https://www.isa-afp.org/entries/Verified_SAT_Based_AI_Planning.html https://www.isa-afp.org/entries/Verified_SAT_Based_AI_Planning.html Mohammad Abdulaziz, Friedrich Kurz 29 Oct 2020 00:00:00 +0000 We present an executable formally verified SAT encoding of classical AI planning that is based on the encodings by Kautz and Selman and the one by Rintanen et al. The encoding was experimentally tested and shown to be usable for reasonably sized standard AI planning benchmarks. We also use it as a reference to test a state-of-the-art SAT-based planner, showing that it sometimes falsely claims that problems have no solutions of certain lengths. The formalisation in this submission was described in an independent publication. AI Planning Languages Semantics https://www.isa-afp.org/entries/AI_Planning_Languages_Semantics.html https://www.isa-afp.org/entries/AI_Planning_Languages_Semantics.html Mohammad Abdulaziz, Peter Lammich 29 Oct 2020 00:00:00 +0000 This is an Isabelle/HOL formalisation of the semantics of the multi-valued planning tasks language that is used by the planning system Fast-Downward, the STRIPS fragment of the Planning Domain Definition Language (PDDL), and the STRIPS soundness meta-theory developed by Vladimir Lifschitz. It also contains formally verified checkers for checking the well-formedness of problems specified in either language as well the correctness of potential solutions. The formalisation in this entry was described in an earlier publication. A Sound Type System for Physical Quantities, Units, and Measurements https://www.isa-afp.org/entries/Physical_Quantities.html https://www.isa-afp.org/entries/Physical_Quantities.html Simon Foster, Burkhart Wolff 20 Oct 2020 00:00:00 +0000 The present Isabelle theory builds a formal model for both the International System of Quantities (ISQ) and the International System of Units (SI), which are both fundamental for physics and engineering. Both the ISQ and the SI are deeply integrated into Isabelle's type system. Quantities are parameterised by dimension types, which correspond to base vectors, and thus only quantities of the same dimension can be equated. Since the underlying "algebra of quantities" induces congruences on quantity and SI types, specific tactic support is developed to capture these. Our construction is validated by a test-set of known equivalences between both quantities and SI units. Moreover, the presented theory can be used for type-safe conversions between the SI system and others, like the British Imperial System (BIS). Finite Map Extras https://www.isa-afp.org/entries/Finite-Map-Extras.html https://www.isa-afp.org/entries/Finite-Map-Extras.html Javier Díaz 12 Oct 2020 00:00:00 +0000 This entry includes useful syntactic sugar, new operators and functions, and their associated lemmas for finite maps which currently are not present in the standard Finite_Map theory. A Formal Model of the Safely Composable Document Object Model with Shadow Roots https://www.isa-afp.org/entries/Shadow_SC_DOM.html https://www.isa-afp.org/entries/Shadow_SC_DOM.html Achim D. Brucker, Michael Herzberg 28 Sep 2020 00:00:00 +0000 In this AFP entry, we extend our formalization of the safely composable DOM with Shadow Roots. This is a proposal for Shadow Roots with stricter safety guarantess than the standard compliant formalization (see "Shadow DOM"). Shadow Roots are a recent proposal of the web community to support a component-based development approach for client-side web applications. Shadow roots are a significant extension to the DOM standard and, as web standards are condemned to be backward compatible, such extensions often result in complex specification that may contain unwanted subtleties that can be detected by a formalization. Our Isabelle/HOL formalization is, in the sense of object-orientation, an extension of our formalization of the core DOM and enjoys the same basic properties, i.e., it is extensible, i.e., can be extended without the need of re-proving already proven properties and executable, i.e., we can generate executable code from our specification. We exploit the executability to show that our formalization complies to the official standard of the W3C, respectively, the WHATWG. A Formal Model of the Document Object Model with Shadow Roots https://www.isa-afp.org/entries/Shadow_DOM.html https://www.isa-afp.org/entries/Shadow_DOM.html Achim D. Brucker, Michael Herzberg 28 Sep 2020 00:00:00 +0000 In this AFP entry, we extend our formalization of the core DOM with Shadow Roots. Shadow roots are a recent proposal of the web community to support a component-based development approach for client-side web applications. Shadow roots are a significant extension to the DOM standard and, as web standards are condemned to be backward compatible, such extensions often result in complex specification that may contain unwanted subtleties that can be detected by a formalization. Our Isabelle/HOL formalization is, in the sense of object-orientation, an extension of our formalization of the core DOM and enjoys the same basic properties, i.e., it is extensible, i.e., can be extended without the need of re-proving already proven properties and executable, i.e., we can generate executable code from our specification. We exploit the executability to show that our formalization complies to the official standard of the W3C, respectively, the WHATWG. A Formalization of Safely Composable Web Components https://www.isa-afp.org/entries/SC_DOM_Components.html https://www.isa-afp.org/entries/SC_DOM_Components.html Achim D. Brucker, Michael Herzberg 28 Sep 2020 00:00:00 +0000 While the (safely composable) DOM with shadow trees provide the technical basis for defining web components, it does neither defines the concept of web components nor specifies the safety properties that web components should guarantee. Consequently, the standard also does not discuss how or even if the methods for modifying the DOM respect component boundaries. In AFP entry, we present a formally verified model of safely composable web components and define safety properties which ensure that different web components can only interact with each other using well-defined interfaces. Moreover, our verification of the application programming interface (API) of the DOM revealed numerous invariants that implementations of the DOM API need to preserve to ensure the integrity of components. In comparison to the strict standard compliance formalization of Web Components in the AFP entry "DOM_Components", the notion of components in this entry (based on "SC_DOM" and "Shadow_SC_DOM") provides much stronger safety guarantees. A Formalization of Web Components https://www.isa-afp.org/entries/DOM_Components.html https://www.isa-afp.org/entries/DOM_Components.html Achim D. Brucker, Michael Herzberg 28 Sep 2020 00:00:00 +0000 While the DOM with shadow trees provide the technical basis for defining web components, the DOM standard neither defines the concept of web components nor specifies the safety properties that web components should guarantee. Consequently, the standard also does not discuss how or even if the methods for modifying the DOM respect component boundaries. In AFP entry, we present a formally verified model of web components and define safety properties which ensure that different web components can only interact with each other using well-defined interfaces. Moreover, our verification of the application programming interface (API) of the DOM revealed numerous invariants that implementations of the DOM API need to preserve to ensure the integrity of components. The Safely Composable DOM https://www.isa-afp.org/entries/Core_SC_DOM.html https://www.isa-afp.org/entries/Core_SC_DOM.html Achim D. Brucker, Michael Herzberg 28 Sep 2020 00:00:00 +0000 In this AFP entry, we formalize the core of the Safely Composable Document Object Model (SC DOM). The SC DOM improve the standard DOM (as formalized in the AFP entry "Core DOM") by strengthening the tree boundaries set by shadow roots: in the SC DOM, the shadow root is a sub-class of the document class (instead of a base class). This modifications also results in changes to some API methods (e.g., getOwnerDocument) to return the nearest shadow root rather than the document root. As a result, many API methods that, when called on a node inside a shadow tree, would previously ``break out'' and return or modify nodes that are possibly outside the shadow tree, now stay within its boundaries. This change in behavior makes programs that operate on shadow trees more predictable for the developer and allows them to make more assumptions about other code accessing the DOM. Syntax-Independent Logic Infrastructure https://www.isa-afp.org/entries/Syntax_Independent_Logic.html https://www.isa-afp.org/entries/Syntax_Independent_Logic.html Andrei Popescu, Dmitriy Traytel 16 Sep 2020 00:00:00 +0000 We formalize a notion of logic whose terms and formulas are kept abstract. In particular, logical connectives, substitution, free variables, and provability are not defined, but characterized by their general properties as locale assumptions. Based on this abstract characterization, we develop further reusable reasoning infrastructure. For example, we define parallel substitution (along with proving its characterizing theorems) from single-point substitution. Similarly, we develop a natural deduction style proof system starting from the abstract Hilbert-style one. These one-time efforts benefit different concrete logics satisfying our locales' assumptions. We instantiate the syntax-independent logic infrastructure to Robinson arithmetic (also known as Q) in the AFP entry <a href="https://www.isa-afp.org/entries/Robinson_Arithmetic.html">Robinson_Arithmetic</a> and to hereditarily finite set theory in the AFP entries <a href="https://www.isa-afp.org/entries/Goedel_HFSet_Semantic.html">Goedel_HFSet_Semantic</a> and <a href="https://www.isa-afp.org/entries/Goedel_HFSet_Semanticless.html">Goedel_HFSet_Semanticless</a>, which are part of our formalization of G&ouml;del's Incompleteness Theorems described in our CADE-27 paper <a href="https://dx.doi.org/10.1007/978-3-030-29436-6_26">A Formally Verified Abstract Account of Gödel's Incompleteness Theorems</a>. - - Robinson Arithmetic - https://www.isa-afp.org/entries/Robinson_Arithmetic.html - https://www.isa-afp.org/entries/Robinson_Arithmetic.html - Andrei Popescu, Dmitriy Traytel - 16 Sep 2020 00:00:00 +0000 - -We instantiate our syntax-independent logic infrastructure developed -in <a -href="https://www.isa-afp.org/entries/Syntax_Independent_Logic.html">a -separate AFP entry</a> to the FOL theory of Robinson arithmetic -(also known as Q). The latter was formalised using Nominal Isabelle by -adapting <a -href="https://www.isa-afp.org/entries/Incompleteness.html">Larry -Paulson’s formalization of the Hereditarily Finite Set -theory</a>. - diff --git a/web/statistics.html b/web/statistics.html --- a/web/statistics.html +++ b/web/statistics.html @@ -1,302 +1,302 @@ Archive of Formal Proofs

 

 

 

 

 

 

Statistics

 

Statistics

- - - - + + + +
Number of Articles:589
Number of Authors:375
Number of lemmas:~165,000
Lines of Code:~2,891,500
Number of Articles:590
Number of Authors:376
Number of lemmas:~165,500
Lines of Code:~2,900,600

Most used AFP articles:

NameUsed by ? articles
1. List-Index 17
2. Coinductive 12
Collections 12
Regular-Sets 12
Show 12
3. Landau_Symbols 11
4. Jordan_Normal_Form 10
Polynomial_Factorization 10
5. Abstract-Rewriting 9
Automatic_Refinement 9
Deriving 9

Growth in number of articles:

Growth in lines of code:

Growth in number of authors:

Size of articles:

\ No newline at end of file diff --git a/web/topics.html b/web/topics.html --- a/web/topics.html +++ b/web/topics.html @@ -1,948 +1,950 @@ Archive of Formal Proofs

 

 

 

 

 

 

Index by Topic

 

Computer science

Artificial intelligence

Automata and formal languages

Algorithms

Knuth_Morris_Pratt   Probabilistic_While   Comparison_Sort_Lower_Bound   Quick_Sort_Cost   TortoiseHare   Selection_Heap_Sort   VerifyThis2018   CYK   Boolean_Expression_Checkers   Efficient-Mergesort   SATSolverVerification   MuchAdoAboutTwo   First_Order_Terms   Monad_Memo_DP   Hidden_Markov_Models   Imperative_Insertion_Sort   Formal_SSA   ROBDD   Median_Of_Medians_Selection   Fisher_Yates   Optimal_BST   IMP2   Auto2_Imperative_HOL   List_Inversions   IMP2_Binary_Heap   MFOTL_Monitor   Adaptive_State_Counting   Generic_Join   VerifyThis2019   Generalized_Counting_Sort   MFODL_Monitor_Optimized   Sliding_Window_Algorithm   PAC_Checker   Graph: DFS_Framework   Prpu_Maxflow   Floyd_Warshall   Roy_Floyd_Warshall   Dijkstra_Shortest_Path   EdmondsKarp_Maxflow   Depth-First-Search   GraphMarkingIBP   Transitive-Closure   Transitive-Closure-II   Gabow_SCC   Kruskal   Prim_Dijkstra_Simple   Relational_Minimum_Spanning_Trees   Distributed: DiskPaxos   GenClock   ClockSynchInst   Heard_Of   Consensus_Refined   Abortable_Linearizable_Modules   IMAP-CRDT   CRDT   Chandy_Lamport   OpSets   Stellar_Quorums   WOOT_Strong_Eventual_Consistency   Concurrent: ConcurrentGC   Online: List_Update   Geometry: Closest_Pair_Points   Approximation: Approximation_Algorithms   Mathematical: FFT   Gauss-Jordan-Elim-Fun   UpDown_Scheme   Polynomials   Gauss_Jordan   Echelon_Form   QR_Decomposition   Hermite   Groebner_Bases   Diophantine_Eqns_Lin_Hom   Taylor_Models   LLL_Basis_Reduction   Signature_Groebner   Smith_Normal_Form   Safe_Distance   Modular_arithmetic_LLL_and_HNF_algorithms   Optimization: Simplex   Quantum computing: Isabelle_Marries_Dirac   Projective_Measurements  

Concurrency

Data structures

Functional programming

Hardware

SPARCv8  

Machine learning

Networks

Programming languages

Clean   Decl_Sem_Fun_PL   Language definitions: CakeML   WebAssembly   pGCL   GPU_Kernel_PL   LightweightJava   CoreC++   FeatherweightJava   Jinja   JinjaThreads   Locally-Nameless-Sigma   AutoFocus-Stream   FocusStreamsCaseStudies   Isabelle_Meta_Model   Simpl   Complx   Safe_OCL   Isabelle_C   JinjaDCI   Lambda calculi: Higher_Order_Terms   Launchbury   PCF   POPLmark-deBruijn   Lam-ml-Normalization   LambdaMu   Binding_Syntax_Theory   LambdaAuth   Type systems: Name_Carrying_Type_Inference   MiniML   Possibilistic_Noninterference   SIFUM_Type_Systems   Dependent_SIFUM_Type_Systems   Strong_Security   WHATandWHERE_Security   VolpanoSmith   Physical_Quantities   Logics: ConcurrentIMP   Refine_Monadic   Automatic_Refinement   MonoBoolTranAlgebra   Simpl   Separation_Algebra   Separation_Logic_Imperative_HOL   Relational-Incorrectness-Logic   Abstract-Hoare-Logics   Kleene_Algebra   KAT_and_DRA   KAD   BytecodeLogicJmlTypes   DataRefinementIBP   RefinementReactive   SIFPL   TLA   Ribbon_Proofs   Separata   Complx   Differential_Dynamic_Logic   Hoare_Time   IMP2   UTP   QHLProver   Differential_Game_Logic   Compiling: CakeML_Codegen   Compiling-Exceptions-Correctly   NormByEval   Density_Compiler   VeriComp   Static analysis: RIPEMD-160-SPARK   Program-Conflict-Analysis   Shivers-CFA   Slicing   HRB-Slicing   InfPathElimination   Abs_Int_ITP2012   Transformations: Call_Arity   Refine_Imperative_HOL   WorkerWrapper   Monad_Memo_DP   Formal_SSA   Minimal_SSA   Misc: JiveDataStoreModel   Pop_Refinement   Case_Labeling   Interpreter_Optimizations  

Security

Semantics

System description languages

Logic

Philosophical aspects

General logic

Computability

Set theory

Proof theory

Rewriting

Mathematics

Order

Algebra

Analysis

Probability theory

Number theory

Games and economics

Geometry

Topology

Graph theory

Combinatorics

Category theory

Physics

Misc

Tools

\ No newline at end of file