diff --git a/metadata/metadata b/metadata/metadata --- a/metadata/metadata +++ b/metadata/metadata @@ -1,11872 +1,11991 @@ [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 = manuel@pruvisto.org 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 = manuel@pruvisto.org 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)
[2021-11-15] Improvement of alphabet and chantype commands to support code generation. Addition of a tactic "rename_alpha_vars" that removes the subscript vs in proof goals. Bug fixes and improvements to alphabet command ML implementation. Additional laws for scenes. (revisions 9f8bcd71c121 and c061bf9f46f3)
[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 = manuel@pruvisto.org 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 = manuel@pruvisto.org 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 = manuel@pruvisto.org 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 = manuel@pruvisto.org 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 = manuel@pruvisto.org 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 = manuel@pruvisto.org 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 = manuel@pruvisto.org 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)
[2021-07-22]: Minor changes to sublocale declarations related to functor/natural transformation to avoid issues with global interpretations reported 2/2/2021 by Filip Smola. (revision 49d3aa43c180)
[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 operation 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)
[2021-08-13]: generalize the derivation of the characterisation for the relator of discrete probability distributions to work for the bounded and unbounded MFMC theorem (revision 3c85bb52bbe6)
[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 = manuel@pruvisto.org [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 = manuel@pruvisto.org [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 = manuel@pruvisto.org [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 = manuel@pruvisto.org [Euler_MacLaurin] title = The Euler–MacLaurin Formula author = Manuel Eberl topic = Mathematics/Analysis date = 2017-03-10 notify = manuel@pruvisto.org 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: Completeness of Modal Logics 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). The extensions of system K (T, KB, K4, S4, S5) and their completeness proofs are based on the textbook "Modal Logic" by Blackburn, de Rijke and Venema (Cambridge University Press 2001). Papers: https://doi.org/10.1007/978-3-030-88853-4_1, https://doi.org/10.1007/978-3-030-90138-7_2. extra-history = Change history: [2021-04-15]: Added completeness of modal logics T, KB, K4, S4 and S5. [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 [Finitely_Generated_Abelian_Groups] title = Finitely Generated Abelian Groups author = Joseph Thommes<>, Manuel Eberl topic = Mathematics/Algebra date = 2021-07-07 notify = joseph-thommes@gmx.de, manuel@pruvisto.org abstract = This article deals with the formalisation of some group-theoretic results including the fundamental theorem of finitely generated abelian groups characterising the structure of these groups as a uniquely determined product of cyclic groups. Both the invariant factor decomposition and the primary decomposition are covered. Additional work includes results about the direct product, the internal direct product and more group-theoretic lemmas. [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 = manuel@pruvisto.org [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 [MDP-Rewards] title = Markov Decision Processes with Rewards author = Maximilian Schäffeler , Mohammad Abdulaziz topic = Mathematics/Probability theory date = 2021-12-16 notify = schaeffm@in.tum.de, mansour@in.tum.de abstract = We present a formalization of Markov Decision Processes with rewards. In particular we first build on Hölzl's formalization of MDPs (AFP entry: Markov_Models) and extend them with rewards. We proceed with an analysis of the expected total discounted reward criterion for infinite horizon MDPs. The central result is the construction of the iteration rule for the Bellman operator. We prove the optimality equations for this operator and show the existence of an optimal stationary deterministic solution. The analysis can be used to obtain dynamic programming algorithms such as value iteration and policy iteration to solve MDPs with formal guarantees. Our formalization is based on chapters 5 and 6 in Puterman's book "Markov Decision Processes: Discrete Stochastic Dynamic Programming". [MDP-Algorithms] title = Verified Algorithms for Solving Markov Decision Processes author = Maximilian Schäffeler , Mohammad Abdulaziz topic = Mathematics/Probability theory, Computer science/Algorithms date = 2021-12-16 notify = schaeffm@in.tum.de, mansour@in.tum.de abstract = We present a formalization of algorithms for solving Markov Decision Processes (MDPs) with formal guarantees on the optimality of their solutions. In particular we build on our analysis of the Bellman operator for discounted infinite horizon MDPs. From the iterator rule on the Bellman operator we directly derive executable value iteration and policy iteration algorithms to iteratively solve finite MDPs. We also prove correct optimized versions of value iteration that use matrix splittings to improve the convergence rate. In particular, we formally verify Gauss-Seidel value iteration and modified policy iteration. The algorithms are evaluated on two standard examples from the literature, namely, inventory management and gridworld. Our formalization covers most of chapter 6 in Puterman's book "Markov Decision Processes: Discrete Stochastic Dynamic Programming". [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 [Actuarial_Mathematics] title = Actuarial Mathematics author = Yosuke Ito topic = Mathematics/Games and economics date = 2022-01-23 notify = glacier345@gmail.com abstract = Actuarial Mathematics is a theory in applied mathematics, which is mainly used for determining the prices of insurance products and evaluating the liability of a company associating with insurance contracts. It is related to calculus, probability theory and financial theory, etc. In this entry, I formalize the very basic part of Actuarial Mathematics in Isabelle/HOL. The first formalization is about the theory of interest which deals with interest rates, present value factors, an annuity certain, etc. I have already formalized the basic part of Actuarial Mathematics in Coq (https://github.com/Yosuke-Ito-345/Actuary). This entry is currently the partial translation and a little generalization of the Coq formalization. The further translation in Isabelle/HOL is now proceeding. [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 , Thomas Bauereiss 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 transition systems. 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, thomas@bauereiss.name extra-history = Change history: [2021-08-12]: Generalised BD Security from I/O automata to nondeterministic transition systems, with the former retained as an instance of the latter (renaming locale BD_Security to BD_Security_IO). Generalise unwinding conditions to allow making more than one transition at a time when constructing alternative traces. Add results about the expressivity of declassification triggers vs. bounds, due to Thomas Bauereiss (added as author). [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 = manuel@pruvisto.org [Error_Function] title = The Error Function author = Manuel Eberl topic = Mathematics/Analysis date = 2018-02-06 notify = manuel@pruvisto.org 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 = manuel@pruvisto.org [Dirichlet_Series] title = Dirichlet Series author = Manuel Eberl topic = Mathematics/Number theory date = 2017-10-12 notify = manuel@pruvisto.org 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 = manuel@pruvisto.org 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 = manuel@pruvisto.org 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.

[Van_der_Waerden] title = Van der Waerden's Theorem author = Katharina Kreuzer , Manuel Eberl topic = Mathematics/Combinatorics date = 2021-06-22 notify = kreuzerk@in.tum.de, manuel@pruvisto.org abstract = This article formalises the proof of Van der Waerden's Theorem from Ramsey theory. Van der Waerden's Theorem states that for integers $k$ and $l$ there exists a number $N$ which guarantees that if an integer interval of length at least $N$ is coloured with $k$ colours, there will always be an arithmetic progression of length $l$ of the same colour in said interval. The proof goes along the lines of \cite{Swan}. The smallest number $N_{k,l}$ fulfilling Van der Waerden's Theorem is then called the Van der Waerden Number. Finding the Van der Waerden Number is still an open problem for most values of $k$ and $l$. [Lambert_W] title = The Lambert W Function on the Reals author = Manuel Eberl topic = Mathematics/Analysis date = 2020-04-24 notify = manuel@pruvisto.org 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 [Cubic_Quartic_Equations] title = Solving Cubic and Quartic Equations author = René Thiemann topic = Mathematics/Analysis date = 2021-09-03 notify = rene.thiemann@uibk.ac.at abstract =

We formalize Cardano's formula to solve a cubic equation $$ax^3 + bx^2 + cx + d = 0,$$ as well as Ferrari's formula to solve a quartic equation. We further turn both formulas into executable algorithms based on the algebraic number implementation in the AFP. To this end we also slightly extended this library, namely by making the minimal polynomial of an algebraic number executable, and by defining and implementing $n$-th roots of complex numbers.

[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 [Schutz_Spacetime] title = Schutz' Independent Axioms for Minkowski Spacetime author = Richard Schmoetten , Jake Palmer , Jacques Fleuriot topic = Mathematics/Physics, Mathematics/Geometry date = 2021-07-27 notify = s1311325@sms.ed.ac.uk abstract = This is a formalisation of Schutz' system of axioms for Minkowski spacetime published under the name "Independent axioms for Minkowski space-time" in 1997, as well as most of the results in the third chapter ("Temporal Order on a Path") of the above monograph. Many results are proven here that cannot be found in Schutz, either preceding the theorem they are needed for, or within their own thematic section. [Real_Power] title = Real Exponents as the Limits of Sequences of Rational Exponents author = Jacques D. Fleuriot topic = Mathematics/Analysis date = 2021-11-08 notify = jdf@ed.ac.uk abstract = In this formalisation, we construct real exponents as the limits of sequences of rational exponents. In particular, if $a \ge 1$ and $x \in \mathbb{R}$, we choose an increasing rational sequence $r_n$ such that $\lim_{n\to\infty} {r_n} = x$. Then the sequence $a^{r_n}$ is increasing and if $r$ is any rational number such that $r > x$, $a^{r_n}$ is bounded above by $a^r$. By the convergence criterion for monotone sequences, $a^{r_n}$ converges. We define $a^ x = \lim_{n\to\infty} a^{r_n}$ and show that it has the expected properties (for $a \ge 0$). This particular construction of real exponents is needed instead of the usual one using the natural logarithm and exponential functions (which already exists in Isabelle) to support our mechanical derivation of Euler's exponential series as an ``infinite polynomial". Aside from helping us avoid circular reasoning, this is, as far as we are aware, the first time real exponents are mechanised in this way within a proof assistant. [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 = manuel@pruvisto.org [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 = manuel@pruvisto.org [Median_Of_Medians_Selection] title = The Median-of-Medians Selection Algorithm author = Manuel Eberl topic = Computer science/Algorithms date = 2017-12-21 notify = manuel@pruvisto.org 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 = manuel@pruvisto.org 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 = manuel@pruvisto.org 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 = manuel@pruvisto.org 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 = manuel@pruvisto.org 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 = manuel@pruvisto.org 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 = manuel@pruvisto.org 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 = manuel@pruvisto.org 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. extra-history = Change history: [2017-07-05]: generalised extended reals to linear orders (revision b8e703159177) [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 , Ujkan Sulejmani<> 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, center selection, 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 (excluding center selection) has been published in the proceedings of IJCAR 2020. extra-history = Change history: [2021-02-08]: added theory Approx_SC_Hoare (Set Cover) by Robin Eßmann
[2021-06-29]: added theory Center_Selection by Ujkan Sulejmani [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 various shapes (e.g., rectangle, circle and 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). extra-history = Change history: [2021-10-26]: resolved the roots-on-the-border problem in the rectangular case (revision 82a159e398cf). [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 = manuel@pruvisto.org 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 = manuel@pruvisto.org 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 = manuel@pruvisto.org 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 = manuel@pruvisto.org 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 = manuel@pruvisto.org 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. extra-history = Change history: [2020-12-09]: moved Hoare logic to HOL-Hoare, moved spanning trees to Relational_Minimum_Spanning_Trees (revision dbb9bfaf4283) [Prime_Number_Theorem] title = The Prime Number Theorem author = Manuel Eberl , Lawrence C. Paulson topic = Mathematics/Number theory date = 2018-09-19 notify = manuel@pruvisto.org 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 = manuel@pruvisto.org 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 = manuel@pruvisto.org 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 = manuel@pruvisto.org 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 = manuel@pruvisto.org 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 an ITP'19 paper. [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. [BenOr_Kozen_Reif] title = The BKR Decision Procedure for Univariate Real Arithmetic author = Katherine Cordwell , Yong Kiam Tan , André Platzer topic = Computer science/Algorithms/Mathematical date = 2021-04-24 notify = kcordwel@cs.cmu.edu, yongkiat@cs.cmu.edu, aplatzer@cs.cmu.edu abstract = We formalize the univariate case of Ben-Or, Kozen, and Reif's decision procedure for first-order real arithmetic (the BKR algorithm). We also formalize the univariate case of Renegar's variation of the BKR algorithm. The two formalizations differ mathematically in minor ways (that have significant impact on the multivariate case), but are quite similar in proof structure. Both rely on sign-determination (finding the set of consistent sign assignments for a set of polynomials). The method used for sign-determination is similar to Tarski's original quantifier elimination algorithm (it stores key information in a matrix equation), but with a reduction step to keep complexity low. [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. Paper: http://ceur-ws.org/Vol-3002/paper7.pdf. [FOL_Seq_Calc2] title = A Sequent Calculus Prover for First-Order Logic with Functions author = Asta Halkjær From , Frederik Krogsdal Jacobsen topic = Logic/General logic/Classical first-order logic, Logic/Proof theory, Logic/General logic/Mechanization of proofs date = 2022-01-31 notify = ahfrom@dtu.dk, fkjac@dtu.dk abstract = We formalize an automated theorem prover for first-order logic with functions. The proof search procedure is based on sequent calculus and we verify its soundness and completeness using the Abstract Soundness and Abstract Completeness theories. Our analytic completeness proof covers both open and closed formulas. Since our deterministic prover considers only the subset of terms relevant to proving a given sequent, we do so as well when building a countermodel from a failed proof. We formally connect our prover with the proof system and semantics of the existing SeCaV system. In particular, the prover's output can be post-processed in Haskell to generate human-readable SeCaV proofs which are also machine-verifiable proof certificates. [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 = manuel@pruvisto.org 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)
[2021-07-22]: Added new material: "concrete bicategories" and "bicategory of categories". (revision 49d3aa43c180)
[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 = 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. extra-history = Change history: [2021-10-19]: corrected a mistake in the calculation of median aggregations (reported by Nicolas Kaletsch, revision 02b14c9bf3da)
[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 = manuel@pruvisto.org 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 = manuel@pruvisto.org 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 = manuel@pruvisto.org 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. extra-history = Change history: [2021-06-19]: added path halving, path splitting, relational Peano structures, union by rank (revision 98c7aa03457d) [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 = m.foster@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 = m.foster@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 extra-history = Change history: [2021-06-14]: refactored function definitions to contain explicit basic blocks
[2021-06-25]: proved conditional completeness of compilation
[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 = manuel@pruvisto.org 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, insertion and deletion 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, OCaml 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. extra-history = Change history: [2021-05-02]: Add implementation and proof of correctness of imperative deletion operations. Further add the option to export code to OCaml.
[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. [IFC_Tracking] title = Information Flow Control via Dependency Tracking author = Benedikt Nordhoff topic = Computer science/Security date = 2021-04-01 notify = b.n@wwu.de abstract = We provide a characterisation of how information is propagated by program executions based on the tracking data and control dependencies within executions themselves. The characterisation might be used for deriving approximative safety properties to be targeted by static analyses or checked at runtime. We utilise a simple yet versatile control flow graph model as a program representation. As our model is not assumed to be finite it can be instantiated for a broad class of programs. The targeted security property is indistinguishable security where executions produce sequences of observations and only non-terminating executions are allowed to drop a tail of those. A very crude approximation of our characterisation is slicing based on program dependence graphs, which we use as a minimal example and derive a corresponding soundness result. For further details and applications refer to the authors upcoming dissertation. [Grothendieck_Schemes] title = Grothendieck's Schemes in Algebraic Geometry author = Anthony Bordg , Lawrence Paulson , Wenda Li topic = Mathematics/Algebra, Mathematics/Geometry date = 2021-03-29 notify = apdb3@cam.ac.uk, lp15@cam.ac.uk abstract = We formalize mainstream structures in algebraic geometry culminating in Grothendieck's schemes: presheaves of rings, sheaves of rings, ringed spaces, locally ringed spaces, affine schemes and schemes. We prove that the spectrum of a ring is a locally ringed space, hence an affine scheme. Finally, we prove that any affine scheme is a scheme. [Progress_Tracking] title = Formalization of Timely Dataflow's Progress Tracking Protocol author = Matthias Brun<>, Sára Decova<>, Andrea Lattuada, Dmitriy Traytel topic = Computer science/Algorithms/Distributed date = 2021-04-13 notify = matthias.brun@inf.ethz.ch, traytel@di.ku.dk abstract = Large-scale stream processing systems often follow the dataflow paradigm, which enforces a program structure that exposes a high degree of parallelism. The Timely Dataflow distributed system supports expressive cyclic dataflows for which it offers low-latency data- and pipeline-parallel stream processing. To achieve high expressiveness and performance, Timely Dataflow uses an intricate distributed protocol for tracking the computation’s progress. We formalize this progress tracking protocol and verify its safety. Our formalization is described in detail in our forthcoming ITP'21 paper. [GaleStewart_Games] title = Gale-Stewart Games author = Sebastiaan Joosten topic = Mathematics/Games and economics date = 2021-04-23 notify = sjcjoosten@gmail.com abstract = This is a formalisation of the main result of Gale and Stewart from 1953, showing that closed finite games are determined. This property is now known as the Gale Stewart Theorem. While the original paper shows some additional theorems as well, we only formalize this main result, but do so in a somewhat general way. We formalize games of a fixed arbitrary length, including infinite length, using co-inductive lists, and show that defensive strategies exist unless the other player is winning. For closed games, defensive strategies are winning for the closed player, proving that such games are determined. For finite games, which are a special case in our formalisation, all games are closed. [Metalogic_ProofChecker] title = Isabelle's Metalogic: Formalization and Proof Checker author = Tobias Nipkow , Simon Roßkopf topic = Logic/General logic date = 2021-04-27 notify = rosskops@in.tum.de abstract = In this entry we formalize Isabelle's metalogic in Isabelle/HOL. Furthermore, we define a language of proof terms and an executable proof checker and prove its soundness wrt. the metalogic. The formalization is intentionally kept close to the Isabelle implementation(for example using de Brujin indices) to enable easy integration of generated code with the Isabelle system without a complicated translation layer. The formalization is described in our CADE 28 paper. [Regression_Test_Selection] title = Regression Test Selection author = Susannah Mansky topic = Computer science/Algorithms date = 2021-04-30 notify = sjohnsn2@illinois.edu, susannahej@gmail.com abstract = This development provides a general definition for safe Regression Test Selection (RTS) algorithms. RTS algorithms select which tests to rerun on revised code, reducing the time required to check for newly introduced errors. An RTS algorithm is considered safe if and only if all deselected tests would have unchanged results. This definition is instantiated with two class-collection-based RTS algorithms run over the JVM as modeled by JinjaDCI. This is achieved with a general definition for Collection Semantics, small-step semantics instrumented to collect information during execution. As the RTS definition mandates safety, these instantiations include proofs of safety. This work is described in Mansky and Gunter's LSFA 2020 paper and Mansky's doctoral thesis (UIUC, 2020). [Padic_Ints] title = Hensel's Lemma for the p-adic Integers author = Aaron Crighton topic = Mathematics/Number theory date = 2021-03-23 notify = crightoa@mcmaster.ca abstract = We formalize the ring of p-adic integers within the framework of the HOL-Algebra library. The carrier of the ring is formalized as the inverse limit of quotients of the integers by powers of a fixed prime p. We define an integer-valued valuation, as well as an extended-integer valued valuation which sends 0 to the infinite element. Basic topological facts about the p-adic integers are formalized, including completeness and sequential compactness. Taylor expansions of polynomials over a commutative ring are defined, culminating in the formalization of Hensel's Lemma based on a proof due to Keith Conrad. [Combinatorics_Words] title = Combinatorics on Words Basics author = Štěpán Holub , Martin Raška<>, Štěpán Starosta topic = Computer science/Automata and formal languages date = 2021-05-24 notify = holub@karlin.mff.cuni.cz, stepan.starosta@fit.cvut.cz abstract = We formalize basics of Combinatorics on Words. This is an extension of existing theories on lists. We provide additional properties related to prefix, suffix, factor, length and rotation. The topics include prefix and suffix comparability, mismatch, word power, total and reversed morphisms, border, periods, primitivity and roots. We also formalize basic, mostly folklore results related to word equations: equidivisibility, commutation and conjugation. Slightly advanced properties include the Periodicity lemma (often cited as the Fine and Wilf theorem) and the variant of the Lyndon-Schützenberger theorem for words. We support the algebraic point of view which sees words as generators of submonoids of a free monoid. This leads to the concepts of the (free) hull, the (free) basis (or code). [Combinatorics_Words_Lyndon] title = Lyndon words author = Štěpán Holub , Štěpán Starosta topic = Computer science/Automata and formal languages date = 2021-05-24 notify = holub@karlin.mff.cuni.cz, stepan.starosta@fit.cvut.cz abstract = Lyndon words are words lexicographically minimal in their conjugacy class. We formalize their basic properties and characterizations, in particular the concepts of the longest Lyndon suffix and the Lyndon factorization. Most of the work assumes a fixed lexicographical order. Nevertheless we also define the smallest relation guaranteeing lexicographical minimality of a given word (in its conjugacy class). [Combinatorics_Words_Graph_Lemma] title = Graph Lemma author = Štěpán Holub , Štěpán Starosta topic = Computer science/Automata and formal languages date = 2021-05-24 notify = holub@karlin.mff.cuni.cz, stepan.starosta@fit.cvut.cz abstract = Graph lemma quantifies the defect effect of a system of word equations. That is, it provides an upper bound on the rank of the system. We formalize the proof based on the decomposition of a solution into its free basis. A direct application is an alternative proof of the fact that two noncommuting words form a code. [Lifting_the_Exponent] title = Lifting the Exponent author = Jakub Kądziołka topic = Mathematics/Number theory date = 2021-04-27 notify = kuba@kadziolka.net abstract = We formalize the Lifting the Exponent Lemma, which shows how to find the largest power of $p$ dividing $a^n \pm b^n$, for a prime $p$ and positive integers $a$ and $b$. The proof follows Amir Hossein Parvardi's. [IMP_Compiler] title = A Shorter Compiler Correctness Proof for Language IMP author = Pasquale Noce topic = Computer science/Programming languages/Compiling date = 2021-06-04 notify = pasquale.noce.lavoro@gmail.com abstract = This paper presents a compiler correctness proof for the didactic imperative programming language IMP, introduced in Nipkow and Klein's book on formal programming language semantics (version of March 2021), whose size is just two thirds of the book's proof in the number of formal text lines. As such, it promises to constitute a further enhanced reference for the formal verification of compilers meant for larger, real-world programming languages. The presented proof does not depend on language determinism, so that the proposed approach can be applied to non-deterministic languages as well. As a confirmation, this paper extends IMP with an additional non-deterministic choice command, and proves compiler correctness, viz. the simulation of compiled code execution by source code, for such extended language. [Public_Announcement_Logic] title = Public Announcement Logic author = Asta Halkjær From topic = Logic/General logic/Logics of knowledge and belief date = 2021-06-17 notify = ahfrom@dtu.dk abstract = This work is a formalization of public announcement logic with countably many agents. It includes proofs of soundness and completeness for a variant of the axiom system PA + DIST! + NEC!. The completeness proof builds on the Epistemic Logic theory. Paper: https://doi.org/10.1007/978-3-030-90138-7_2. [MiniSail] title = MiniSail - A kernel language for the ISA specification language SAIL author = Mark Wassell topic = Computer science/Programming languages/Type systems date = 2021-06-18 notify = mpwassell@gmail.com abstract = MiniSail is a kernel language for Sail, an instruction set architecture (ISA) specification language. Sail is an imperative language with a light-weight dependent type system similar to refinement type systems. From an ISA specification, the Sail compiler can generate theorem prover code and C (or OCaml) to give an executable emulator for an architecture. The idea behind MiniSail is to capture the key and novel features of Sail in terms of their syntax, typing rules and operational semantics, and to confirm that they work together by proving progress and preservation lemmas. We use the Nominal2 library to handle binding. [SpecCheck] title = SpecCheck - Specification-Based Testing for Isabelle/ML author = Kevin Kappelmann , Lukas Bulwahn , Sebastian Willenbrink topic = Tools date = 2021-07-01 notify = kevin.kappelmann@tum.de abstract = SpecCheck is a QuickCheck-like testing framework for Isabelle/ML. You can use it to write specifications for ML functions. SpecCheck then checks whether your specification holds by testing your function against a given number of generated inputs. It helps you to identify bugs by printing counterexamples on failure and provides you timing information. SpecCheck is customisable and allows you to specify your own input generators, test output formats, as well as pretty printers and shrinking functions for counterexamples among other things. [Relational_Forests] title = Relational Forests author = Walter Guttmann topic = Mathematics/Graph theory date = 2021-08-03 notify = walter.guttmann@canterbury.ac.nz abstract = We study second-order formalisations of graph properties expressed as first-order formulas in relation algebras extended with a Kleene star. The formulas quantify over relations while still avoiding quantification over elements of the base set. We formalise the property of undirected graphs being acyclic this way. This involves a study of various kinds of orientation of graphs. We also verify basic algorithms to constructively prove several second-order properties. [Fresh_Identifiers] title = Fresh identifiers author = Andrei Popescu , Thomas Bauereiss topic = Computer science/Data structures date = 2021-08-16 notify = thomas@bauereiss.name, a.popescu@sheffield.ac.uk abstract = This entry defines a type class with an operator returning a fresh identifier, given a set of already used identifiers and a preferred identifier. The entry provides a default instantiation for any infinite type, as well as executable instantiations for natural numbers and strings. [CoCon] title = CoCon: A Confidentiality-Verified Conference Management System author = Andrei Popescu , Peter Lammich , Thomas Bauereiss topic = Computer science/Security date = 2021-08-16 notify = thomas@bauereiss.name, a.popescu@sheffield.ac.uk abstract = This entry contains the confidentiality verification of the (functional kernel of) the CoCon conference management system [1, 2]. The confidentiality properties refer to the documents managed by the system, namely papers, reviews, discussion logs and acceptance/rejection decisions, and also to the assignment of reviewers to papers. They have all been formulated as instances of BD Security [3, 4] and verified using the BD Security unwinding technique. [BD_Security_Compositional] title = Compositional BD Security author = Thomas Bauereiss , Andrei Popescu topic = Computer science/Security date = 2021-08-16 notify = thomas@bauereiss.name, a.popescu@sheffield.ac.uk abstract = Building on a previous AFP entry that formalizes the Bounded-Deducibility Security (BD Security) framework [1], we formalize compositionality and transport theorems for information flow security. These results allow lifting BD Security properties from individual components specified as transition systems, to a composition of systems specified as communicating products of transition systems. The underlying ideas of these results are presented in the papers [1] and [2]. The latter paper also describes a major case study where these results have been used: on verifying the CoSMeDis distributed social media platform (itself formalized as an AFP entry that builds on this entry). [CoSMed] title = CoSMed: A confidentiality-verified social media platform author = Thomas Bauereiss , Andrei Popescu topic = Computer science/Security date = 2021-08-16 notify = thomas@bauereiss.name, a.popescu@sheffield.ac.uk abstract = This entry contains the confidentiality verification of the (functional kernel of) the CoSMed social media platform. The confidentiality properties are formalized as instances of BD Security [1, 2]. An innovation in the deployment of BD Security compared to previous work is the use of dynamic declassification triggers, incorporated as part of inductive bounds, for providing stronger guarantees that account for the repeated opening and closing of access windows. To further strengthen the confidentiality guarantees, we also prove "traceback" properties about the accessibility decisions affecting the information managed by the system. [CoSMeDis] title = CoSMeDis: A confidentiality-verified distributed social media platform author = Thomas Bauereiss , Andrei Popescu topic = Computer science/Security date = 2021-08-16 notify = thomas@bauereiss.name, a.popescu@sheffield.ac.uk abstract = This entry contains the confidentiality verification of the (functional kernel of) the CoSMeDis distributed social media platform presented in [1]. CoSMeDis is a multi-node extension the CoSMed prototype social media platform [2, 3, 4]. The confidentiality properties are formalized as instances of BD Security [5, 6]. The lifting of confidentiality properties from single nodes to the entire CoSMeDis network is performed using compositionality and transport theorems for BD Security, which are described in [1] and formalized in a separate AFP entry. [Three_Circles] title = The Theorem of Three Circles author = Fox Thomson , Wenda Li topic = Mathematics/Analysis date = 2021-08-21 notify = foxthomson0@gmail.com, wl302@cam.ac.uk abstract = The Descartes test based on Bernstein coefficients and Descartes’ rule of signs effectively (over-)approximates the number of real roots of a univariate polynomial over an interval. In this entry we formalise the theorem of three circles, which gives sufficient conditions for when the Descartes test returns 0 or 1. This is the first step for efficient root isolation. [Design_Theory] title = Combinatorial Design Theory author = Chelsea Edmonds , Lawrence Paulson topic = Mathematics/Combinatorics date = 2021-08-13 notify = cle47@cam.ac.uk abstract = Combinatorial design theory studies incidence set systems with certain balance and symmetry properties. It is closely related to hypergraph theory. This formalisation presents a general library for formal reasoning on incidence set systems, designs and their applications, including formal definitions and proofs for many key properties, operations, and theorems on the construction and existence of designs. Notably, this includes formalising t-designs, balanced incomplete block designs (BIBD), group divisible designs (GDD), pairwise balanced designs (PBD), design isomorphisms, and the relationship between graphs and designs. A locale-centric approach has been used to manage the relationships between the many different types of designs. Theorems of particular interest include the necessary conditions for existence of a BIBD, Wilson's construction on GDDs, and Bose's inequality on resolvable designs. Parts of this formalisation are explored in the paper "A Modular First Formalisation of Combinatorial Design Theory", presented at CICM 2021. [Logging_Independent_Anonymity] title = Logging-independent Message Anonymity in the Relational Method author = Pasquale Noce topic = Computer science/Security date = 2021-08-26 notify = pasquale.noce.lavoro@gmail.com abstract = In the context of formal cryptographic protocol verification, logging-independent message anonymity is the property for a given message to remain anonymous despite the attacker's capability of mapping messages of that sort to agents based on some intrinsic feature of such messages, rather than by logging the messages exchanged by legitimate agents as with logging-dependent message anonymity. This paper illustrates how logging-independent message anonymity can be formalized according to the relational method for formal protocol verification by considering a real-world protocol, namely the Restricted Identification one by the BSI. This sample model is used to verify that the pseudonymous identifiers output by user identification tokens remain anonymous under the expected conditions. [Dominance_CHK] title = A data flow analysis algorithm for computing dominators author = Nan Jiang<> topic = Computer science/Programming languages/Static analysis date = 2021-09-05 notify = nanjiang@whu.edu.cn abstract = This entry formalises the fast iterative algorithm for computing dominators due to Cooper, Harvey and Kennedy. It gives a specification of computing dominators on a control flow graph where each node refers to its reverse post order number. A semilattice of reversed-ordered list which represents dominators is built and a Kildall-style algorithm on the semilattice is defined for computing dominators. Finally the soundness and completeness of the algorithm are proved w.r.t. the specification. [Conditional_Simplification] title = Conditional Simplification author = Mihails Milehins topic = Tools date = 2021-09-06 notify = mihailsmilehins@gmail.com abstract = The article provides a collection of experimental general-purpose proof methods for the object logic Isabelle/HOL of the formal proof assistant Isabelle. The methods in the collection offer functionality that is similar to certain aspects of the functionality provided by the standard proof methods of Isabelle that combine classical reasoning and rewriting, such as the method auto, but use a different approach for rewriting. More specifically, these methods allow for the side conditions of the rewrite rules to be solved via intro-resolution. [Intro_Dest_Elim] title = IDE: Introduction, Destruction, Elimination author = Mihails Milehins topic = Tools date = 2021-09-06 notify = mihailsmilehins@gmail.com abstract = The article provides the command mk_ide for the object logic Isabelle/HOL of the formal proof assistant Isabelle. The command mk_ide enables the automated synthesis of the introduction, destruction and elimination rules from arbitrary definitions of constant predicates stated in Isabelle/HOL. [CZH_Foundations] title = Category Theory for ZFC in HOL I: Foundations: Design Patterns, Set Theory, Digraphs, Semicategories author = Mihails Milehins topic = Mathematics/Category theory, Logic/Set theory date = 2021-09-06 notify = mihailsmilehins@gmail.com abstract = This article provides a foundational framework for the formalization of category theory in the object logic ZFC in HOL of the formal proof assistant Isabelle. More specifically, this article provides a formalization of canonical set-theoretic constructions internalized in the type V associated with the ZFC in HOL, establishes a design pattern for the formalization of mathematical structures using sequences and locales, and showcases the developed infrastructure by providing formalizations of the elementary theories of digraphs and semicategories. The methodology chosen for the formalization of the theories of digraphs and semicategories (and categories in future articles) rests on the ideas that were originally expressed in the article Set-Theoretical Foundations of Category Theory written by Solomon Feferman and Georg Kreisel. Thus, in the context of this work, each of the aforementioned mathematical structures is represented as a term of the type V embedded into a stage of the von Neumann hierarchy. [CZH_Elementary_Categories] title = Category Theory for ZFC in HOL II: Elementary Theory of 1-Categories author = Mihails Milehins topic = Mathematics/Category theory date = 2021-09-06 notify = mihailsmilehins@gmail.com abstract = This article provides a formalization of the foundations of the theory of 1-categories in the object logic ZFC in HOL of the formal proof assistant Isabelle. The article builds upon the foundations that were established in the AFP entry Category Theory for ZFC in HOL I: Foundations: Design Patterns, Set Theory, Digraphs, Semicategories. [CZH_Universal_Constructions] title = Category Theory for ZFC in HOL III: Universal Constructions author = Mihails Milehins topic = Mathematics/Category theory date = 2021-09-06 notify = mihailsmilehins@gmail.com abstract = The article provides a formalization of elements of the theory of universal constructions for 1-categories (such as limits, adjoints and Kan extensions) in the object logic ZFC in HOL of the formal proof assistant Isabelle. The article builds upon the foundations established in the AFP entry Category Theory for ZFC in HOL II: Elementary Theory of 1-Categories. [Conditional_Transfer_Rule] title = Conditional Transfer Rule author = Mihails Milehins topic = Tools date = 2021-09-06 notify = mihailsmilehins@gmail.com abstract = This article provides a collection of experimental utilities for unoverloading of definitions and synthesis of conditional transfer rules for the object logic Isabelle/HOL of the formal proof assistant Isabelle written in Isabelle/ML. [Types_To_Sets_Extension] title = Extension of Types-To-Sets author = Mihails Milehins topic = Tools date = 2021-09-06 notify = mihailsmilehins@gmail.com abstract = In their article titled From Types to Sets by Local Type Definitions in Higher-Order Logic and published in the proceedings of the conference Interactive Theorem Proving in 2016, Ondřej Kunčar and Andrei Popescu propose an extension of the logic Isabelle/HOL and an associated algorithm for the relativization of the type-based theorems to more flexible set-based theorems, collectively referred to as Types-To-Sets. One of the aims of their work was to open an opportunity for the development of a software tool for applied relativization in the implementation of the logic Isabelle/HOL of the proof assistant Isabelle. In this article, we provide a prototype of a software framework for the interactive automated relativization of theorems in Isabelle/HOL, developed as an extension of the proof language Isabelle/Isar. The software framework incorporates the implementation of the proposed extension of the logic, and builds upon some of the ideas for further work expressed in the original article on Types-To-Sets by Ondřej Kunčar and Andrei Popescu and the subsequent article Smooth Manifolds and Types to Sets for Linear Algebra in Isabelle/HOL that was written by Fabian Immler and Bohua Zhan and published in the proceedings of the International Conference on Certified Programs and Proofs in 2019. [Complex_Bounded_Operators] title = Complex Bounded Operators author = Jose Manuel Rodriguez Caballero , Dominique Unruh topic = Mathematics/Analysis date = 2021-09-18 notify = unruh@ut.ee abstract = We present a formalization of bounded operators on complex vector spaces. Our formalization contains material on complex vector spaces (normed spaces, Banach spaces, Hilbert spaces) that complements and goes beyond the developments of real vectors spaces in the Isabelle/HOL standard library. We define the type of bounded operators between complex vector spaces (cblinfun) and develop the theory of unitaries, projectors, extension of bounded linear functions (BLT theorem), adjoints, Loewner order, closed subspaces and more. For the finite-dimensional case, we provide code generation support by identifying finite-dimensional operators with matrices as formalized in the Jordan_Normal_Form AFP entry. [Weighted_Path_Order] title = A Formalization of Weighted Path Orders and Recursive Path Orders author = Christian Sternagel , René Thiemann , Akihisa Yamada topic = Logic/Rewriting date = 2021-09-16 notify = rene.thiemann@uibk.ac.at abstract = We define the weighted path order (WPO) and formalize several properties such as strong normalization, the subterm property, and closure properties under substitutions and contexts. Our definition of WPO extends the original definition by also permitting multiset comparisons of arguments instead of just lexicographic extensions. Therefore, our WPO not only subsumes lexicographic path orders (LPO), but also recursive path orders (RPO). We formally prove these subsumptions and therefore all of the mentioned properties of WPO are automatically transferable to LPO and RPO as well. Such a transformation is not required for Knuth–Bendix orders (KBO), since they have already been formalized. Nevertheless, we still provide a proof that WPO subsumes KBO and thereby underline the generality of WPO. [FOL_Axiomatic] title = Soundness and Completeness of an Axiomatic System for First-Order Logic author = Asta Halkjær From topic = Logic/General logic/Classical first-order logic, Logic/Proof theory date = 2021-09-24 notify = ahfrom@dtu.dk abstract = This work is a formalization of the soundness and completeness of an axiomatic system for first-order logic. The proof system is based on System Q1 by Smullyan and the completeness proof follows his textbook "First-Order Logic" (Springer-Verlag 1968). The completeness proof is in the Henkin style where a consistent set is extended to a maximal consistent set using Lindenbaum's construction and Henkin witnesses are added during the construction to ensure saturation as well. The resulting set is a Hintikka set which, by the model existence theorem, is satisfiable in the Herbrand universe. [Virtual_Substitution] title = Verified Quadratic Virtual Substitution for Real Arithmetic author = Matias Scharager , Katherine Cordwell , Stefan Mitsch , André Platzer topic = Computer science/Algorithms/Mathematical date = 2021-10-02 notify = mscharag@cs.cmu.edu, kcordwel@cs.cmu.edu, smitsch@cs.cmu.edu, aplatzer@cs.cmu.edu abstract = This paper presents a formally verified quantifier elimination (QE) algorithm for first-order real arithmetic by linear and quadratic virtual substitution (VS) in Isabelle/HOL. The Tarski-Seidenberg theorem established that the first-order logic of real arithmetic is decidable by QE. However, in practice, QE algorithms are highly complicated and often combine multiple methods for performance. VS is a practically successful method for QE that targets formulas with low-degree polynomials. To our knowledge, this is the first work to formalize VS for quadratic real arithmetic including inequalities. The proofs necessitate various contributions to the existing multivariate polynomial libraries in Isabelle/HOL. Our framework is modularized and easily expandable (to facilitate integrating future optimizations), and could serve as a basis for developing practical general-purpose QE algorithms. Further, as our formalization is designed with practicality in mind, we export our development to SML and test the resulting code on 378 benchmarks from the literature, comparing to Redlog, Z3, Wolfram Engine, and SMT-RAT. This identified inconsistencies in some tools, underscoring the significance of a verified approach for the intricacies of real arithmetic. [Correctness_Algebras] title = Algebras for Iteration, Infinite Executions and Correctness of Sequential Computations author = Walter Guttmann topic = Computer science/Programming languages/Logics date = 2021-10-12 notify = walter.guttmann@canterbury.ac.nz abstract = We study models of state-based non-deterministic sequential computations and describe them using algebras. We propose algebras that describe iteration for strict and non-strict computations. They unify computation models which differ in the fixpoints used to represent iteration. We propose algebras that describe the infinite executions of a computation. They lead to a unified approximation order and results that connect fixpoints in the approximation and refinement orders. This unifies the semantics of recursion for a range of computation models. We propose algebras that describe preconditions and the effect of while-programs under postconditions. They unify correctness statements in two dimensions: one statement applies in various computation models to various correctness claims. [Belief_Revision] title = Belief Revision Theory author = Valentin Fouillard , Safouan Taha , Frédéric Boulanger , Nicolas Sabouret <> topic = Logic/General logic/Logics of knowledge and belief date = 2021-10-19 notify = safouan.taha@lri.fr, valentin.fouillard@limsi.fr abstract = The 1985 paper by Carlos Alchourrón, Peter Gärdenfors, and David Makinson (AGM), “On the Logic of Theory Change: Partial Meet Contraction and Revision Functions” launches a large and rapidly growing literature that employs formal models and logics to handle changing beliefs of a rational agent and to take into account new piece of information observed by this agent. In 2011, a review book titled "AGM 25 Years: Twenty-Five Years of Research in Belief Change" was edited to summarize the first twenty five years of works based on AGM. This HOL-based AFP entry is a faithful formalization of the AGM operators (e.g. contraction, revision, remainder ...) axiomatized in the original paper. It also contains the proofs of all the theorems stated in the paper that show how these operators combine. Both proofs of Harper and Levi identities are established. [X86_Semantics] title = X86 instruction semantics and basic block symbolic execution author = Freek Verbeek , Abhijith Bharadwaj <>, Joshua Bockenek <>, Ian Roessle <>, Timmy Weerwag <>, Binoy Ravindran <> topic = Computer science/Hardware, Computer science/Semantics date = 2021-10-13 notify = freek@vt.edu abstract = This AFP entry provides semantics for roughly 120 different X86-64 assembly instructions. These instructions include various moves, arithmetic/logical operations, jumps, call/return, SIMD extensions and others. External functions are supported by allowing a user to provide custom semantics for these calls. Floating-point operations are mapped to uninterpreted functions. The model provides semantics for register aliasing and a byte-level little-endian memory model. The semantics are purposefully incomplete, but overapproximative. For example, the precise effect of flags may be undefined for certain instructions, or instructions may simply have no semantics at all. In those cases, the semantics are mapped to universally quantified uninterpreted terms from a locale. Second, this entry provides a method to symbolic execution of basic blocks. The method, called ''se_step'' (for: symbolic execution step) fetches an instruction and updates the current symbolic state while keeping track of assumptions made over the memory model. A key component is a set of theorems that prove how reads from memory resolve after writes have occurred. Thirdly, this entry provides a parser that allows the user to copy-paste the output of the standard disassembly tool objdump into Isabelle/HOL. A couple small and explanatory examples are included, including functions from the word count program. Several examples can be supplied upon request (they are not included due to the running time of verification): functions from the floating-point modulo function from FDLIBM, the GLIBC strlen function and the CoreUtils SHA256 implementation. [Registers] title = Quantum and Classical Registers author = Dominique Unruh topic = Computer science/Algorithms/Quantum computing, Computer science/Programming languages/Logics, Computer science/Semantics date = 2021-10-28 notify = unruh@ut.ee abstract = A formalization of the theory of quantum and classical registers as developed by (Unruh, Quantum and Classical Registers). In a nutshell, a register refers to a part of a larger memory or system that can be accessed independently. Registers can be constructed from other registers and several (compatible) registers can be composed. This formalization develops both the generic theory of registers as well as specific instantiations for classical and quantum registers. [Szemeredi_Regularity] title = Szemerédi's Regularity Lemma author = Chelsea Edmonds , Angeliki Koutsoukou-Argyraki , Lawrence C. Paulson topic = Mathematics/Graph theory, Mathematics/Combinatorics date = 2021-11-05 notify = lp15@cam.ac.uk abstract = Szemerédi's regularity lemma is a key result in the study of large graphs. It asserts the existence of an upper bound on the number of parts the vertices of a graph need to be partitioned into such that the edges between the parts are random in a certain sense. This bound depends only on the desired precision and not on the graph itself, in the spirit of Ramsey's theorem. The formalisation follows online course notes by Tim Gowers and Yufei Zhao. [Factor_Algebraic_Polynomial] title = Factorization of Polynomials with Algebraic Coefficients author = Manuel Eberl , René Thiemann topic = Mathematics/Algebra date = 2021-11-08 notify = rene.thiemann@uibk.ac.at abstract = The AFP already contains a verified implementation of algebraic numbers. However, it is has a severe limitation in its factorization algorithm of real and complex polynomials: the factorization is only guaranteed to succeed if the coefficients of the polynomial are rational numbers. In this work, we verify an algorithm to factor all real and complex polynomials whose coefficients are algebraic. The existence of such an algorithm proves in a constructive way that the set of complex algebraic numbers is algebraically closed. Internally, the algorithm is based on resultants of multivariate polynomials and an approximation algorithm using interval arithmetic. [PAL] title = Automating Public Announcement Logic and the Wise Men Puzzle in Isabelle/HOL author = Christoph Benzmüller , Sebastian Reiche topic = Logic/General logic/Logics of knowledge and belief date = 2021-11-08 notify = c.benzmueller@gmail.com abstract = We present a shallow embedding of public announcement logic (PAL) with relativized general knowledge in HOL. We then use PAL to obtain an elegant encoding of the wise men puzzle, which we solve automatically using sledgehammer. [SimplifiedOntologicalArgument] title = Exploring Simplified Variants of Gödel’s Ontological Argument in Isabelle/HOL author = Christoph Benzmüller topic = Logic/Philosophical aspects, Logic/General logic/Modal logic date = 2021-11-08 notify = c.benzmueller@gmail.com abstract =

Simplified variants of Gödel's ontological argument are explored. Among those is a particularly interesting simplified argument which is (i) valid already in basic modal logics K or KT, (ii) which does not suffer from modal collapse, and (iii) which avoids the rather complex predicates of essence (Ess.) and necessary existence (NE) as used by Gödel.

Whether the presented variants increase or decrease the attractiveness and persuasiveness of the ontological argument is a question I would like to pass on to philosophy and theology.

[Van_Emde_Boas_Trees] title = van Emde Boas Trees author = Thomas Ammer<>, Peter Lammich<> topic = Computer science/Data structures date = 2021-11-23 notify = lammich@in.tum.de abstract = The van Emde Boas tree or van Emde Boas priority queue is a data structure supporting membership test, insertion, predecessor and successor search, minimum and maximum determination and deletion in O(log log U) time, where U = 0,...,2n-1 is the overall range to be considered.

The presented formalization follows Chapter 20 of the popular Introduction to Algorithms (3rd ed.) by Cormen, Leiserson, Rivest and Stein (CLRS), extending the list of formally verified CLRS algorithms. Our current formalization is based on the first author's bachelor's thesis.

First, we prove correct a functional implementation, w.r.t. an abstract data type for sets. Apart from functional correctness, we show a resource bound, and runtime bounds w.r.t. manually defined timing functions for the operations.

Next, we refine the operations to Imperative HOL with time, and show correctness and complexity. This yields a practically more efficient implementation, and eliminates the manually defined timing functions from the trusted base of the proof. [Hahn_Jordan_Decomposition] title = The Hahn and Jordan Decomposition Theorems author = Marie Cousin , Mnacho Echenim , Hervé Guiol topic = Mathematics/Measure theory date = 2021-11-19 notify = mnacho.echenim@univ-grenoble-alpes.fr abstract = In this work we formalize the Hahn decomposition theorem for signed measures, namely that any measure space for a signed measure can be decomposed into a positive and a negative set, where every measurable subset of the positive one has a positive measure, and every measurable subset of the negative one has a negative measure. We also formalize the Jordan decomposition theorem as a corollary, which states that the signed measure under consideration admits a unique decomposition into a difference of two positive measures, at least one of which is finite. [Simplicial_complexes_and_boolean_functions] title = Simplicial Complexes and Boolean functions author = Jesús Aransay , Alejandro del Campo , Julius Michaelis topic = Mathematics/Topology date = 2021-11-29 notify = jesus-maria.aransay@unirioja.es abstract = In this work we formalise the isomorphism between simplicial complexes of dimension $n$ and monotone Boolean functions in $n$ variables, mainly following the definitions and results as introduced by N. A. Scoville. We also take advantage of the AFP representation of ROBDD (Reduced Ordered Binary Decision Diagrams) to compute the ROBDD representation of a given simplicial complex (by means of the isomorphism to Boolean functions). Some examples of simplicial complexes and associated Boolean functions are also presented. [Foundation_of_geometry] title = Foundation of geometry in planes, and some complements: Excluding the parallel axioms author = Fumiya Iwama <> topic = Mathematics/Geometry date = 2021-11-22 notify = d1623001@s.konan-u.ac.jp abstract = "Foundations of Geometry" is a mathematical book written by Hilbert in 1899. This entry is a complete formalization of "Incidence" (excluding cubic axioms), "Order" and "Congruence" (excluding point sequences) of the axioms constructed in this book. In addition, the theorem of the problem about the part that is treated implicitly and is not clearly stated in it is being carried out in parallel. [Regular_Tree_Relations] title = Regular Tree Relations author = Alexander Lochmann , Bertram Felgenhauer<>, Christian Sternagel , René Thiemann , Thomas Sternagel<> topic = Computer science/Automata and formal languages date = 2021-12-15 notify = alexander.lochmann@uibk.ac.at abstract = Tree automata have good closure properties and therefore a commonly used to prove/disprove properties. This formalization contains among other things the proofs of many closure properties of tree automata (anchored) ground tree transducers and regular relations. Additionally it includes the well known pumping lemma and a lifting of the Myhill Nerode theorem for regular languages to tree languages. We want to mention the existence of a tree automata APF-entry developed by Peter Lammich. His work is based on epsilon free top-down tree automata, while this entry builds on bottom-up tree auotamta with epsilon transitions. Moreover our formalization relies on the Collections Framework, also by Peter Lammich, to obtain efficient code. All proven constructions of the closure properties are exportable using the Isabelle/HOL code generation facilities. [Roth_Arithmetic_Progressions] title = Roth's Theorem on Arithmetic Progressions author = Chelsea Edmonds , Angeliki Koutsoukou-Argyraki , Lawrence C. Paulson topic = Mathematics/Graph theory, Mathematics/Combinatorics date = 2021-12-28 notify = lp15@cam.ac.uk abstract = We formalise a proof of Roth's Theorem on Arithmetic Progressions, a major result in additive combinatorics on the existence of 3-term arithmetic progressions in subsets of natural numbers. To this end, we follow a proof using graph regularity. We employ our recent formalisation of Szemerédi's Regularity Lemma, a major result in extremal graph theory, which we use here to prove the Triangle Counting Lemma and the Triangle Removal Lemma. Our sources are Yufei Zhao's MIT lecture notes "Graph Theory and Additive Combinatorics" (revised version here) and W.T. Gowers's Cambridge lecture notes "Topics in Combinatorics". We also refer to the University of Georgia notes by Stephanie Bell and Will Grodzicki, "Using Szemerédi's Regularity Lemma to Prove Roth's Theorem". [Gale_Shapley] title = Gale-Shapley Algorithm author = Tobias Nipkow topic = Computer science/Algorithms, Mathematics/Games and economics date = 2021-12-29 notify = nipkow@in.tum.de abstract = This is a stepwise refinement and proof of the Gale-Shapley stable matching (or marriage) algorithm down to executable code. Both a purely functional implementation based on lists and a functional implementation based on efficient arrays (provided by the Collections Framework in the AFP) are developed. The latter implementation runs in time O(n2) where n is the cardinality of the two sets to be matched. [Knights_Tour] title = Knight's Tour Revisited Revisited author = Lukas Koller topic = Mathematics/Graph theory date = 2022-01-04 notify = lukas.koller@tum.de abstract = This is a formalization of the article Knight's Tour Revisited by Cull and De Curtins where they prove the existence of a Knight's path for arbitrary n × m-boards with min(n,m) ≥ 5. If n · m is even, then there exists a Knight's circuit. A Knight's Path is a sequence of moves of a Knight on a chessboard s.t. the Knight visits every square of a chessboard exactly once. Finding a Knight's path is a an instance of the Hamiltonian path problem. A Knight's circuit is a Knight's path, where additionally the Knight can move from the last square to the first square of the path, forming a loop. During the formalization two mistakes in the original proof were discovered. These mistakes are corrected in this formalization. [Hyperdual] title = Hyperdual Numbers and Forward Differentiation author = Filip Smola <>, Jacques Fleuriot topic = Mathematics/Algebra, Mathematics/Analysis date = 2021-12-31 notify = f.smola@sms.ed.ac.uk, Jacques.Fleuriot@ed.ac.uk abstract =

Hyperdual numbers are ones with a real component and a number of infinitesimal components, usually written as $a_0 + a_1 \cdot \epsilon_1 + a_2 \cdot \epsilon_2 + a_3 \cdot \epsilon_1\epsilon_2$. They have been proposed by Fike and Alonso in an approach to automatic differentiation.

In this entry we formalise hyperdual numbers and their application to forward differentiation. We show them to be an instance of multiple algebraic structures and then, along with facts about twice-differentiability, we define what we call the hyperdual extensions of functions on real-normed fields. This extension formally represents the proposed way that the first and second derivatives of a function can be automatically calculated. We demonstrate it on the standard logistic function $f(x) = \frac{1}{1 + e^{-x}}$ and also reproduce the example analytic function $f(x) = \frac{e^x}{\sqrt{sin(x)^3 + cos(x)^3}}$ used for demonstration by Fike and Alonso.

[Median_Method] title = Median Method author = Emin Karayel topic = Mathematics/Probability theory date = 2022-01-25 notify = me@eminkarayel.de abstract =

The median method is an amplification result for randomized approximation algorithms described in [1]. Given an algorithm whose result is in a desired interval with a probability larger than 1/2, it is possible to improve the success probability, by running the algorithm multiple times independently and using the median. In contrast to using the mean, the amplification of the success probability grows exponentially with the number of independent runs.

This entry contains a formalization of the underlying theorem: Given a sequence of n independent random variables, which are in a desired interval with a probability 1/2 + a. Then their median will be in the desired interval with a probability of 1 − exp(−2a2 n). In particular, the success probability approaches 1 exponentially with the number of variables.

In addition to that, this entry also contains a proof that order-statistics of Borel-measurable random variables are themselves measurable and that generalized intervals in linearly ordered Borel-spaces are measurable.

[Irrationals_From_THEBOOK] title = Irrational numbers from THE BOOK author = Lawrence C Paulson topic = Mathematics/Number theory date = 2022-01-08 notify = lp15@cam.ac.uk abstract = An elementary proof is formalised: that exp r is irrational for every nonzero rational number r. The mathematical development comes from the well-known volume Proofs from THE BOOK, by Aigner and Ziegler, who credit the idea to Hermite. The development illustrates a number of basic Isabelle techniques: the manipulation of summations, the calculation of quite complicated derivatives and the estimation of integrals. We also see how to import another AFP entry (Stirling's formula). As for the theorem itself, note that a much stronger and more general result (the Hermite--Lindemann--Weierstraß transcendence theorem) is already available in the AFP. [Interpolation_Polynomials_HOL_Algebra] title = Interpolation Polynomials (in HOL-Algebra) author = Emin Karayel topic = Mathematics/Algebra date = 2022-01-29 notify = me@eminkarayel.de abstract =

A well known result from algebra is that, on any field, there is exactly one polynomial of degree less than n interpolating n points [1, §7].

This entry contains a formalization of the above result, as well as the following generalization in the case of finite fields F: There are |F|m-n polynomials of degree less than m ≥ n interpolating the same n points, where |F| denotes the size of the domain of the field. To establish the result the entry also includes a formalization of Lagrange interpolation, which might be of independent interest.

The formalized results are defined on the algebraic structures from HOL-Algebra, which are distinct from the type-class based structures defined in HOL. Note that there is an existing formalization for polynomial interpolation and, in particular, Lagrange interpolation by Thiemann and Yamada [2] on the type-class based structures in HOL.

[Quasi_Borel_Spaces] title = Quasi-Borel Spaces author = Michikazu Hirata <>, Yasuhiko Minamide , Tetsuya Sato topic = Computer science/Semantics date = 2022-02-03 notify = hirata.m.ac@m.titech.ac.jp, minamide@is.titech.ac.jp, tsato@c.titech.ac.jp abstract = The notion of quasi-Borel spaces was introduced by Heunen et al. The theory provides a suitable denotational model for higher-order probabilistic programming languages with continuous distributions. This entry is a formalization of the theory of quasi-Borel spaces, including construction of quasi-Borel spaces (product, coproduct, function spaces), the adjunction between the category of measurable spaces and the category of quasi-Borel spaces, and the probability monad on quasi-Borel spaces. This entry also contains the formalization of the Bayesian regression presented in the work of Heunen et al. This work is a part of the work by same authors, Program Logic for Higher-Order Probabilistic Programs in Isabelle/HOL, which will be published in the proceedings of the 16th International Symposium on Functional and Logic Programming (FLOPS 2022). [Youngs_Inequality] title = Young's Inequality for Increasing Functions author = Lawrence C Paulson topic = Mathematics/Analysis date = 2022-01-31 notify = lp15@cam.ac.uk abstract = Young's inequality states that $$ ab \leq \int_0^a f(x)dx + \int_0^b f^{-1}(y) dy $$ where $a\geq 0$, $b\geq 0$ and $f$ is strictly increasing and continuous. Its proof is formalised following the development by Cunningham and Grossman. Their idea is to make the intuitive, geometric folklore proof rigorous by reasoning about step functions. The lack of the Riemann integral makes the development longer than one would like, but their argument is reproduced faithfully. [LP_Duality] title = Duality of Linear Programming author = René Thiemann topic = Mathematics/Algebra date = 2022-02-03 notify = rene.thiemann@uibk.ac.at abstract = We formalize the weak and strong duality theorems of linear programming. For the strong duality theorem we provide three sufficient preconditions: both the primal problem and the dual problem are satisfiable, the primal problem is satisfiable and bounded, or the dual problem is satisfiable and bounded. The proofs are based on an existing formalization of Farkas' Lemma. [Equivalence_Relation_Enumeration] title = Enumeration of Equivalence Relations author = Emin Karayel topic = Mathematics/Combinatorics, Computer science/Algorithms/Mathematical date = 2022-02-04 notify = me@eminkarayel.de abstract =

This entry contains a formalization of an algorithm enumerating all equivalence relations on an initial segment of the natural numbers. The approach follows the method described by Stanton and White [5,§ 1.5] using restricted growth functions.

The algorithm internally enumerates restricted growth functions (as lists), whose equivalence kernels then form the equivalence relations. This has the advantage that the representation is compact and lookup of the relation reduces to a list lookup operation.

The algorithm can also be used within a proof and an example application is included, where a sequence of variables is split by the possible partitions they can form.

[FO_Theory_Rewriting] title = First-Order Theory of Rewriting author = Alexander Lochmann , Bertram Felgenhauer<> topic = Computer science/Automata and formal languages, Logic/Rewriting, Logic/Proof theory date = 2022-02-02 notify = alexander.lochmann@uibk.ac.at abstract = The first-order theory of rewriting (FORT) is a decidable theory for linear variable-separated rewrite systems. The decision procedure is based on tree automata technique and an inference system presented in "Certifying Proofs in the First-Order Theory of Rewriting". This AFP entry provides a formalization of the underlying decision procedure. Moreover it allows to generate a function that can verify each inference step via the code generation facility of Isabelle/HOL. Additionally it contains the specification of a certificate language (that allows to state proofs in FORT) and a formalized function that allows to verify the validity of the proof. This gives software tool authors, that implement the decision procedure, the possibility to verify their output. +[VYDRA_MDL] +title = Multi-Head Monitoring of Metric Dynamic Logic +author = Martin Raszyk +topic = Computer science/Algorithms +date = 2022-02-13 +notify = m.raszyk@gmail.com +abstract = + Runtime monitoring (or runtime verification) is an approach to + checking compliance of a system's execution with a specification + (e.g., a temporal query). The system's execution is logged into a + trace---a sequence of time-points, each consisting of a time-stamp and + observed events. A monitor is an algorithm that produces verdicts on + the satisfaction of a temporal query on a trace. We formalize a + monitoring algorithm for metric dynamic logic, an extension of metric + temporal logic with regular expressions. The monitor computes whether + a given query is satisfied at every position in an input trace of + time-stamped events. We formalize the time-stamps as an abstract + algebraic structure satisfying certain assumptions. Instances of this + structure include natural numbers, real numbers, and lexicographic + combinations of them. Our monitor follows the multi-head paradigm: it + reads the input simultaneously at multiple positions and moves its + reading heads asynchronously. This mode of operation results in + unprecedented time and space complexity guarantees for metric dynamic + logic: The monitor's amortized time complexity to process a + time-point and the monitor's space complexity neither depends on + the event-rate, i.e., the number of events within a fixed time-unit, + nor on the numeric constants occurring in the quantitative temporal + constraints in the given query. The multi-head monitoring algorithm + for metric dynamic logic is reported in our paper "Multi-Head + Monitoring of Metric Dynamic Logic" published at ATVA 2020. We + have also formalized unpublished specialized algorithms for the + temporal operators of metric temporal logic. + +[Eval_FO] +title = First-Order Query Evaluation +author = Martin Raszyk +topic = Logic/General logic/Classical first-order logic +date = 2022-02-15 +notify = m.raszyk@gmail.com +abstract = + We formalize first-order query evaluation over an infinite domain with + equality. We first define the syntax and semantics of first-order + logic with equality. Next we define a locale + eval_fo abstracting a representation of + a potentially infinite set of tuples satisfying a first-order query + over finite relations. Inside the locale, we define a function + eval checking if the set of tuples satisfying a + first-order query over a database (an interpretation of the + query's predicates) is finite (i.e., deciding relative + safety) and computing the set of satisfying tuples if it is + finite. Altogether the function eval solves + capturability (Avron and Hirshfeld, 1991) of + first-order logic with equality. We also use the function + eval to prove a code equation for the semantics of + first-order logic, i.e., the function checking if a first-order query + over a database is satisfied by a variable assignment.
We provide an + interpretation of the locale eval_fo + based on the approach by Ailamazyan et al. A core notion in the + interpretation is the active domain of a query and a database that + contains all domain elements that occur in the database or interpret + the query's constants. We prove the main theorem of Ailamazyan et + al. relating the satisfaction of a first-order query over an infinite + domain to the satisfaction of this query over a finite domain + consisting of the active domain and a few additional domain elements + (outside the active domain) whose number only depends on the query. In + our interpretation of the locale + eval_fo, we use a potentially higher + number of the additional domain elements, but their number still only + depends on the query and thus has no effect on the data complexity + (Vardi, 1982) of query evaluation. Our interpretation yields an + executable function eval. The + time complexity of eval on a query is linear in the + total number of tuples in the intermediate relations for the + subqueries. Specifically, we build a database index to evaluate a + conjunction. We also optimize the case of a negated subquery in a + conjunction. Finally, we export code for the infinite domain of + natural numbers. + +[Wetzels_Problem] +title = Wetzel's Problem and the Continuum Hypothesis +author = Lawrence C Paulson<> +topic = Mathematics/Analysis, Logic/Set theory +date = 2022-02-18 +notify = lp15@cam.ac.uk +abstract = + Let $F$ be a set of analytic functions on the complex plane such that, + for each $z\in\mathbb{C}$, the set $\{f(z) \mid f\in F\}$ is + countable; must then $F$ itself be countable? The answer is yes if the + Continuum Hypothesis is false, i.e., if the cardinality of + $\mathbb{R}$ exceeds $\aleph_1$. But if CH is true then such an $F$, + of cardinality $\aleph_1$, can be constructed by transfinite + recursion. The formal proof illustrates reasoning about complex + analysis (analytic and homomorphic functions) and set theory + (transfinite cardinalities) in a single setting. The mathematical text + comes from Proofs from THE BOOK by Aigner and + Ziegler. + +[Universal_Hash_Families] +title = Universal Hash Families +author = Emin Karayel +topic = Mathematics/Probability theory, Computer science/Algorithms +date = 2022-02-20 +notify = me@eminkarayel.de +abstract = + A k-universal hash family is a probability + space of functions, which have uniform distribution and form + k-wise independent random variables. They can often be used + in place of classic (or cryptographic) hash functions and allow the + rigorous analysis of the performance of randomized algorithms and + data structures that rely on hash functions. In 1981 + Wegman and Carter + introduced a generic construction for such families with arbitrary + k using polynomials over a finite field. This entry + contains a formalization of them and establishes the property of + k-universality. To be useful the formalization also provides + an explicit construction of finite fields using the factor ring of + integers modulo a prime. Additionally, some generic results about + independent families are shown that might be of independent interest. + diff --git a/thys/Eval_FO/Ailamazyan.thy b/thys/Eval_FO/Ailamazyan.thy new file mode 100644 --- /dev/null +++ b/thys/Eval_FO/Ailamazyan.thy @@ -0,0 +1,5597 @@ +theory Ailamazyan + imports Eval_FO Cluster Mapping_Code +begin + +fun SP :: "('a, 'b) fo_fmla \ nat set" where + "SP (Eqa (Var n) (Var n')) = (if n \ n' then {n, n'} else {})" +| "SP (Neg \) = SP \" +| "SP (Conj \ \) = SP \ \ SP \" +| "SP (Disj \ \) = SP \ \ SP \" +| "SP (Exists n \) = SP \ - {n}" +| "SP (Forall n \) = SP \ - {n}" +| "SP _ = {}" + +lemma SP_fv: "SP \ \ fv_fo_fmla \" + by (induction \ rule: SP.induct) auto + +lemma finite_SP: "finite (SP \)" + using SP_fv finite_fv_fo_fmla finite_subset by fastforce + +fun SP_list_rec :: "('a, 'b) fo_fmla \ nat list" where + "SP_list_rec (Eqa (Var n) (Var n')) = (if n \ n' then [n, n'] else [])" +| "SP_list_rec (Neg \) = SP_list_rec \" +| "SP_list_rec (Conj \ \) = SP_list_rec \ @ SP_list_rec \" +| "SP_list_rec (Disj \ \) = SP_list_rec \ @ SP_list_rec \" +| "SP_list_rec (Exists n \) = filter (\m. n \ m) (SP_list_rec \)" +| "SP_list_rec (Forall n \) = filter (\m. n \ m) (SP_list_rec \)" +| "SP_list_rec _ = []" + +definition SP_list :: "('a, 'b) fo_fmla \ nat list" where + "SP_list \ = remdups_adj (sort (SP_list_rec \))" + +lemma SP_list_set: "set (SP_list \) = SP \" + unfolding SP_list_def + by (induction \ rule: SP.induct) (auto simp: fv_fo_terms_set_list) + +lemma sorted_distinct_SP_list: "sorted_distinct (SP_list \)" + unfolding SP_list_def + by (auto intro: distinct_remdups_adj_sort) + +fun d :: "('a, 'b) fo_fmla \ nat" where + "d (Eqa (Var n) (Var n')) = (if n \ n' then 2 else 1)" +| "d (Neg \) = d \" +| "d (Conj \ \) = max (d \) (max (d \) (card (SP (Conj \ \))))" +| "d (Disj \ \) = max (d \) (max (d \) (card (SP (Disj \ \))))" +| "d (Exists n \) = d \" +| "d (Forall n \) = d \" +| "d _ = 1" + +lemma d_pos: "1 \ d \" + by (induction \ rule: d.induct) auto + +lemma card_SP_d: "card (SP \) \ d \" + using dual_order.trans + by (induction \ rule: SP.induct) (fastforce simp: card_Diff1_le finite_SP)+ + +fun eval_eterm :: "('a + 'c) val \ 'a fo_term \ 'a + 'c" (infix "\e" 60) where + "eval_eterm \ (Const c) = Inl c" +| "eval_eterm \ (Var n) = \ n" + +definition eval_eterms :: "('a + 'c) val \ ('a fo_term) list \ + ('a + 'c) list" (infix "\e" 60) where + "eval_eterms \ ts = map (eval_eterm \) ts" + +lemma eval_eterm_cong: "(\n. n \ fv_fo_term_set t \ \ n = \' n) \ + eval_eterm \ t = eval_eterm \' t" + by (cases t) auto + +lemma eval_eterms_fv_fo_terms_set: "\ \e ts = \' \e ts \ n \ fv_fo_terms_set ts \ \ n = \' n" +proof (induction ts) + case (Cons t ts) + then show ?case + by (cases t) (auto simp: eval_eterms_def fv_fo_terms_set_def) +qed (auto simp: eval_eterms_def fv_fo_terms_set_def) + +lemma eval_eterms_cong: "(\n. n \ fv_fo_terms_set ts \ \ n = \' n) \ + eval_eterms \ ts = eval_eterms \' ts" + by (auto simp: eval_eterms_def fv_fo_terms_set_def intro: eval_eterm_cong) + +lemma eval_terms_eterms: "map Inl (\ \ ts) = (Inl \ \) \e ts" +proof (induction ts) + case (Cons t ts) + then show ?case + by (cases t) (auto simp: eval_terms_def eval_eterms_def) +qed (auto simp: eval_terms_def eval_eterms_def) + +fun ad_equiv_pair :: "'a set \ ('a + 'c) \ ('a + 'c) \ bool" where + "ad_equiv_pair X (a, a') \ (a \ Inl ` X \ a = a') \ (a' \ Inl ` X \ a = a')" + +fun sp_equiv_pair :: "'a \ 'b \ 'a \ 'b \ bool" where + "sp_equiv_pair (a, b) (a', b') \ (a = a' \ b = b')" + +definition ad_equiv_list :: "'a set \ ('a + 'c) list \ ('a + 'c) list \ bool" where + "ad_equiv_list X xs ys \ length xs = length ys \ (\x \ set (zip xs ys). ad_equiv_pair X x)" + +definition sp_equiv_list :: "('a + 'c) list \ ('a + 'c) list \ bool" where + "sp_equiv_list xs ys \ length xs = length ys \ pairwise sp_equiv_pair (set (zip xs ys))" + +definition ad_agr_list :: "'a set \ ('a + 'c) list \ ('a + 'c) list \ bool" where + "ad_agr_list X xs ys \ length xs = length ys \ ad_equiv_list X xs ys \ sp_equiv_list xs ys" + +lemma ad_equiv_pair_refl[simp]: "ad_equiv_pair X (a, a)" + by auto + +declare ad_equiv_pair.simps[simp del] + +lemma ad_equiv_pair_comm: "ad_equiv_pair X (a, a') \ ad_equiv_pair X (a', a)" + by (auto simp: ad_equiv_pair.simps) + +lemma ad_equiv_pair_mono: "X \ Y \ ad_equiv_pair Y (a, a') \ ad_equiv_pair X (a, a')" + unfolding ad_equiv_pair.simps + by fastforce + +lemma sp_equiv_pair_comm: "sp_equiv_pair x y \ sp_equiv_pair y x" + by (cases x; cases y) auto + +definition sp_equiv :: "('a + 'c) val \ ('a + 'c) val \ nat set \ bool" where + "sp_equiv \ \ I \ pairwise sp_equiv_pair ((\n. (\ n, \ n)) ` I)" + +lemma sp_equiv_mono: "I \ J \ sp_equiv \ \ J \ sp_equiv \ \ I" + by (auto simp: sp_equiv_def pairwise_def) + +definition ad_agr_sets :: "nat set \ nat set \ 'a set \ ('a + 'c) val \ + ('a + 'c) val \ bool" where + "ad_agr_sets FV S X \ \ \ (\i \ FV. ad_equiv_pair X (\ i, \ i)) \ sp_equiv \ \ S" + +lemma ad_agr_sets_comm: "ad_agr_sets FV S X \ \ \ ad_agr_sets FV S X \ \" + unfolding ad_agr_sets_def sp_equiv_def pairwise_def + by (subst ad_equiv_pair_comm) auto + +lemma ad_agr_sets_mono: "X \ Y \ ad_agr_sets FV S Y \ \ \ ad_agr_sets FV S X \ \" + using ad_equiv_pair_mono + by (fastforce simp: ad_agr_sets_def) + +lemma ad_agr_sets_mono': "S \ S' \ ad_agr_sets FV S' X \ \ \ ad_agr_sets FV S X \ \" + by (auto simp: ad_agr_sets_def sp_equiv_def pairwise_def) + +lemma ad_equiv_list_comm: "ad_equiv_list X xs ys \ ad_equiv_list X ys xs" + by (auto simp: ad_equiv_list_def) (smt (verit, del_insts) ad_equiv_pair_comm in_set_zip prod.sel(1) prod.sel(2)) + +lemma ad_equiv_list_mono: "X \ Y \ ad_equiv_list Y xs ys \ ad_equiv_list X xs ys" + using ad_equiv_pair_mono + by (fastforce simp: ad_equiv_list_def) + +lemma ad_equiv_list_trans: + assumes "ad_equiv_list X xs ys" "ad_equiv_list X ys zs" + shows "ad_equiv_list X xs zs" +proof - + have lens: "length xs = length ys" "length xs = length zs" "length ys = length zs" + using assms + by (auto simp: ad_equiv_list_def) + have "\x z. (x, z) \ set (zip xs zs) \ ad_equiv_pair X (x, z)" + proof - + fix x z + assume "(x, z) \ set (zip xs zs)" + then obtain i where i_def: "i < length xs" "xs ! i = x" "zs ! i = z" + by (auto simp: set_zip) + define y where "y = ys ! i" + have "ad_equiv_pair X (x, y)" "ad_equiv_pair X (y, z)" + using assms lens i_def + by (fastforce simp: set_zip y_def ad_equiv_list_def)+ + then show "ad_equiv_pair X (x, z)" + unfolding ad_equiv_pair.simps + by blast + qed + then show ?thesis + using assms + by (auto simp: ad_equiv_list_def) +qed + +lemma ad_equiv_list_link: "(\i \ set ns. ad_equiv_pair X (\ i, \ i)) \ + ad_equiv_list X (map \ ns) (map \ ns)" + by (auto simp: ad_equiv_list_def set_zip) (metis in_set_conv_nth nth_map) + +lemma set_zip_comm: "(x, y) \ set (zip xs ys) \ (y, x) \ set (zip ys xs)" + by (metis in_set_zip prod.sel(1) prod.sel(2)) + +lemma set_zip_map: "set (zip (map \ ns) (map \ ns)) = (\n. (\ n, \ n)) ` set ns" + by (induction ns) auto + +lemma sp_equiv_list_comm: "sp_equiv_list xs ys \ sp_equiv_list ys xs" + unfolding sp_equiv_list_def + using set_zip_comm + by (auto simp: pairwise_def) force+ + +lemma sp_equiv_list_trans: + assumes "sp_equiv_list xs ys" "sp_equiv_list ys zs" + shows "sp_equiv_list xs zs" +proof - + have lens: "length xs = length ys" "length xs = length zs" "length ys = length zs" + using assms + by (auto simp: sp_equiv_list_def) + have "pairwise sp_equiv_pair (set (zip xs zs))" + proof (rule pairwiseI) + fix xz xz' + assume "xz \ set (zip xs zs)" "xz' \ set (zip xs zs)" + then obtain x z i x' z' i' where xz_def: "i < length xs" "xs ! i = x" "zs ! i = z" + "xz = (x, z)" "i' < length xs" "xs ! i' = x'" "zs ! i' = z'" "xz' = (x', z')" + by (auto simp: set_zip) + define y where "y = ys ! i" + define y' where "y' = ys ! i'" + have "sp_equiv_pair (x, y) (x', y')" "sp_equiv_pair (y, z) (y', z')" + using assms lens xz_def + by (auto simp: sp_equiv_list_def pairwise_def y_def y'_def set_zip) metis+ + then show "sp_equiv_pair xz xz'" + by (auto simp: xz_def) + qed + then show ?thesis + using assms + by (auto simp: sp_equiv_list_def) +qed + +lemma sp_equiv_list_link: "sp_equiv_list (map \ ns) (map \ ns) \ sp_equiv \ \ (set ns)" + apply (auto simp: sp_equiv_list_def sp_equiv_def pairwise_def set_zip in_set_conv_nth) + apply (metis nth_map) + apply (metis nth_map) + apply fastforce+ + done + +lemma ad_agr_list_comm: "ad_agr_list X xs ys \ ad_agr_list X ys xs" + using ad_equiv_list_comm sp_equiv_list_comm + by (fastforce simp: ad_agr_list_def) + +lemma ad_agr_list_mono: "X \ Y \ ad_agr_list Y ys xs \ ad_agr_list X ys xs" + using ad_equiv_list_mono + by (force simp: ad_agr_list_def) + +lemma ad_agr_list_rev_mono: + assumes "Y \ X" "ad_agr_list Y ys xs" "Inl -` set xs \ Y" "Inl -` set ys \ Y" + shows "ad_agr_list X ys xs" +proof - + have "(a, b) \ set (zip ys xs) \ ad_equiv_pair Y (a, b) \ ad_equiv_pair X (a, b)" for a b + using assms + apply (cases a; cases b) + apply (auto simp: ad_agr_list_def ad_equiv_list_def vimage_def set_zip) + unfolding ad_equiv_pair.simps + apply (metis Collect_mem_eq Collect_mono_iff imageI nth_mem) + apply (metis Collect_mem_eq Collect_mono_iff imageI nth_mem) + apply (metis Collect_mem_eq Collect_mono_iff imageI nth_mem) + apply (metis Inl_Inr_False image_iff) + done + then show ?thesis + using assms + by (fastforce simp: ad_agr_list_def ad_equiv_list_def) +qed + +lemma ad_agr_list_trans: "ad_agr_list X xs ys \ ad_agr_list X ys zs \ ad_agr_list X xs zs" + using ad_equiv_list_trans sp_equiv_list_trans + by (force simp: ad_agr_list_def) + +lemma ad_agr_list_refl: "ad_agr_list X xs xs" + by (auto simp: ad_agr_list_def ad_equiv_list_def set_zip ad_equiv_pair.simps + sp_equiv_list_def pairwise_def) + +lemma ad_agr_list_set: "ad_agr_list X xs ys \ y \ X \ Inl y \ set ys \ Inl y \ set xs" + by (auto simp: ad_agr_list_def ad_equiv_list_def set_zip in_set_conv_nth) + (metis ad_equiv_pair.simps image_eqI) + +lemma ad_agr_list_length: "ad_agr_list X xs ys \ length xs = length ys" + by (auto simp: ad_agr_list_def) + +lemma ad_agr_list_eq: "set ys \ AD \ ad_agr_list AD (map Inl xs) (map Inl ys) \ xs = ys" + by (fastforce simp: ad_agr_list_def ad_equiv_list_def set_zip ad_equiv_pair.simps + intro!: nth_equalityI) + +lemma sp_equiv_list_subset: + assumes "set ms \ set ns" "sp_equiv_list (map \ ns) (map \' ns)" + shows "sp_equiv_list (map \ ms) (map \' ms)" + unfolding sp_equiv_list_def length_map pairwise_def +proof (rule conjI, rule refl, (rule ballI)+, rule impI) + fix x y + assume "x \ set (zip (map \ ms) (map \' ms))" "y \ set (zip (map \ ms) (map \' ms))" "x \ y" + then have "x \ set (zip (map \ ns) (map \' ns))" "y \ set (zip (map \ ns) (map \' ns))" "x \ y" + using assms(1) + by (auto simp: set_zip) (metis in_set_conv_nth nth_map subset_iff)+ + then show "sp_equiv_pair x y" + using assms(2) + by (auto simp: sp_equiv_list_def pairwise_def) +qed + +lemma ad_agr_list_subset: "set ms \ set ns \ ad_agr_list X (map \ ns) (map \' ns) \ + ad_agr_list X (map \ ms) (map \' ms)" + by (auto simp: ad_agr_list_def ad_equiv_list_def sp_equiv_list_subset set_zip) + (metis (no_types, lifting) in_set_conv_nth nth_map subset_iff) + +lemma ad_agr_list_link: "ad_agr_sets (set ns) (set ns) AD \ \ \ + ad_agr_list AD (map \ ns) (map \ ns)" + unfolding ad_agr_sets_def ad_agr_list_def + using ad_equiv_list_link sp_equiv_list_link + by fastforce + +definition ad_agr :: "('a, 'b) fo_fmla \ 'a set \ ('a + 'c) val \ ('a + 'c) val \ bool" where + "ad_agr \ X \ \ \ ad_agr_sets (fv_fo_fmla \) (SP \) X \ \" + +lemma ad_agr_sets_restrict: + "ad_agr_sets (set (fv_fo_fmla_list \)) (set (fv_fo_fmla_list \)) AD \ \ \ ad_agr \ AD \ \" + using sp_equiv_mono SP_fv + unfolding fv_fo_fmla_list_set + by (auto simp: ad_agr_sets_def ad_agr_def) blast + +lemma finite_Inl: "finite X \ finite (Inl -` X)" + using finite_vimageI[of X Inl] + by (auto simp: vimage_def) + +lemma ex_out: + assumes "finite X" + shows "\k. k \ X \ k < Suc (card X)" + using card_mono[OF assms, of "{..: + assumes "ad_agr_sets (FV - {n}) (S - {n}) X \ \" "S \ FV" "finite S" "\ ` (FV - {n}) \ Z" + "Inl ` X \ Inr ` {.. ` (S - {n})) + (if n \ S then 1 else 0))} \ Z" + shows "\k \ Z. ad_agr_sets FV S X (\(n := x)) (\(n := k))" +proof (cases "n \ S") + case True + note n_in_S = True + show ?thesis + proof (cases "x \ Inl ` X") + case True + show ?thesis + using assms n_in_S True + apply (auto simp: ad_agr_sets_def sp_equiv_def pairwise_def intro!: bexI[of _ "x"]) + unfolding ad_equiv_pair.simps + apply (metis True insert_Diff insert_iff subsetD)+ + done + next + case False + note \_n_not_Inl = False + show ?thesis + proof (cases "\m \ S - {n}. x = \ m") + case True + obtain m where m_def: "m \ S - {n}" "x = \ m" + using True + by auto + have \_m_in: "\ m \ Z" + using assms m_def + by auto + show ?thesis + using assms n_in_S \_n_not_Inl True m_def + by (auto simp: ad_agr_sets_def sp_equiv_def pairwise_def intro!: bexI[of _ "\ m"]) + next + case False + have out: "x \ \ ` (S - {n})" + using False + by auto + have fin: "finite (Inr -` \ ` (S - {n}))" + using assms(3) + by (simp add: finite_vimageI) + obtain k where k_def: "Inr k \ \ ` (S - {n})" "k < Suc (card (Inr -` \ ` (S - {n})))" + using ex_out[OF fin] True + by auto + show ?thesis + using assms n_in_S \_n_not_Inl out k_def assms(5) + apply (auto simp: ad_agr_sets_def sp_equiv_def pairwise_def intro!: bexI[of _ "Inr k"]) + unfolding ad_equiv_pair.simps + apply fastforce + apply (metis image_eqI insertE insert_Diff) + done + qed + qed +next + case False + show ?thesis + proof (cases "x \ Inl ` X") + case x_in: True + then show ?thesis + using assms False + by (auto simp: ad_agr_sets_def sp_equiv_def pairwise_def intro!: bexI[of _ "x"]) + next + case x_out: False + then show ?thesis + using assms False + apply (auto simp: ad_agr_sets_def sp_equiv_def pairwise_def intro!: bexI[of _ "Inr 0"]) + unfolding ad_equiv_pair.simps + apply fastforce + done + qed +qed + +lemma esat_Pred: + assumes "ad_agr_sets FV S (\(set ` X)) \ \" "fv_fo_terms_set ts \ FV" "\ \e ts \ map Inl ` X" + "t \ set ts" + shows "\ \e t = \ \e t" +proof (cases t) + case (Var n) + obtain vs where vs_def: "\ \e ts = map Inl vs" "vs \ X" + using assms(3) + by auto + have "\ n \ set (\ \e ts)" + using assms(4) + by (force simp: eval_eterms_def Var) + then have "\ n \ Inl ` \ (set ` X)" + using vs_def(2) + unfolding vs_def(1) + by auto + moreover have "n \ FV" + using assms(2,4) + by (fastforce simp: Var fv_fo_terms_set_def) + ultimately show ?thesis + using assms(1) + unfolding ad_equiv_pair.simps ad_agr_sets_def Var + by fastforce +qed auto + +lemma sp_equiv_list_fv: + assumes "(\i. i \ fv_fo_terms_set ts \ ad_equiv_pair X (\ i, \ i))" + "\(set_fo_term ` set ts) \ X" "sp_equiv \ \ (fv_fo_terms_set ts)" + shows "sp_equiv_list (map ((\e) \) ts) (map ((\e) \) ts)" + using assms +proof (induction ts) + case (Cons t ts) + have ind: "sp_equiv_list (map ((\e) \) ts) (map ((\e) \) ts)" + using Cons + by (auto simp: fv_fo_terms_set_def sp_equiv_def pairwise_def) + show ?case + proof (cases t) + case (Const c) + have c_X: "c \ X" + using Cons(3) + by (auto simp: Const) + have fv_t: "fv_fo_term_set t = {}" + by (auto simp: Const) + have "t' \ set ts \ sp_equiv_pair (\ \e t, \ \e t) (\ \e t', \ \e t')" for t' + using c_X Const Cons(2) + apply (cases t') + apply (auto simp: fv_fo_terms_set_def) + unfolding ad_equiv_pair.simps + by (metis Cons(2) ad_equiv_pair.simps fv_fo_terms_setI image_insert insert_iff list.set(2) + mk_disjoint_insert)+ + then show "sp_equiv_list (map ((\e) \) (t # ts)) (map ((\e) \) (t # ts))" + using ind pairwise_insert[of sp_equiv_pair "(\ \e t, \ \e t)"] + unfolding sp_equiv_list_def set_zip_map + by (auto simp: sp_equiv_pair_comm fv_fo_terms_set_def fv_t) + next + case (Var n) + have ad_n: "ad_equiv_pair X (\ n, \ n)" + using Cons(2) + by (auto simp: fv_fo_terms_set_def Var) + have sp_equiv_Var: "\n'. Var n' \ set ts \ sp_equiv_pair (\ n, \ n) (\ n', \ n')" + using Cons(4) + by (auto simp: sp_equiv_def pairwise_def fv_fo_terms_set_def Var) + have "t' \ set ts \ sp_equiv_pair (\ \e t, \ \e t) (\ \e t', \ \e t')" for t' + using Cons(2,3) sp_equiv_Var + apply (cases t') + apply (auto simp: Var) + apply (metis SUP_le_iff ad_equiv_pair.simps ad_n fo_term.set_intros imageI subset_eq) + apply (metis SUP_le_iff ad_equiv_pair.simps ad_n fo_term.set_intros imageI subset_eq) + done + then show ?thesis + using ind pairwise_insert[of sp_equiv_pair "(\ \e t, \ \e t)" "(\n. (\ \e n, \ \e n)) ` set ts"] + unfolding sp_equiv_list_def set_zip_map + by (auto simp: sp_equiv_pair_comm) + qed +qed (auto simp: sp_equiv_def sp_equiv_list_def fv_fo_terms_set_def) + +lemma esat_Pred_inf: + assumes "fv_fo_terms_set ts \ FV" "fv_fo_terms_set ts \ S" + "ad_agr_sets FV S AD \ \" "ad_agr_list AD (\ \e ts) vs" + "\(set_fo_term ` set ts) \ AD" + shows "ad_agr_list AD (\ \e ts) vs" +proof - + have sp: "sp_equiv \ \ (fv_fo_terms_set ts)" + using assms(2,3) sp_equiv_mono + unfolding ad_agr_sets_def + by auto + have "(\i. i \ fv_fo_terms_set ts \ ad_equiv_pair AD (\ i, \ i))" + using assms(1,3) + by (auto simp: ad_agr_sets_def) + then have "sp_equiv_list (map ((\e) \) ts) (map ((\e) \) ts)" + using sp_equiv_list_fv[OF _ assms(5) sp] + by auto + moreover have "t \ set ts \ \i\fv_fo_terms_set ts. ad_equiv_pair AD (\ i, \ i) \ sp_equiv \ \ S \ ad_equiv_pair AD (\ \e t, \ \e t)" for t + by (cases t) (auto simp: ad_equiv_pair.simps intro!: fv_fo_terms_setI) + ultimately have ad_agr_list: + "ad_agr_list AD (\ \e ts) (\ \e ts)" + unfolding eval_eterms_def ad_agr_list_def ad_equiv_list_link[symmetric] + using assms(1,3) + by (auto simp: ad_agr_sets_def) + show ?thesis + by (rule ad_agr_list_comm[OF ad_agr_list_trans[OF ad_agr_list_comm[OF assms(4)] ad_agr_list]]) +qed + +type_synonym ('a, 'c) fo_t = "'a set \ nat \ ('a + 'c) table" + +fun esat :: "('a, 'b) fo_fmla \ ('a table, 'b) fo_intp \ ('a + nat) val \ ('a + nat) set \ bool" where + "esat (Pred r ts) I \ X \ \ \e ts \ map Inl ` I (r, length ts)" +| "esat (Bool b) I \ X \ b" +| "esat (Eqa t t') I \ X \ \ \e t = \ \e t'" +| "esat (Neg \) I \ X \ \esat \ I \ X" +| "esat (Conj \ \) I \ X \ esat \ I \ X \ esat \ I \ X" +| "esat (Disj \ \) I \ X \ esat \ I \ X \ esat \ I \ X" +| "esat (Exists n \) I \ X \ (\x \ X. esat \ I (\(n := x)) X)" +| "esat (Forall n \) I \ X \ (\x \ X. esat \ I (\(n := x)) X)" + +fun sz_fmla :: "('a, 'b) fo_fmla \ nat" where + "sz_fmla (Neg \) = Suc (sz_fmla \)" +| "sz_fmla (Conj \ \) = Suc (sz_fmla \ + sz_fmla \)" +| "sz_fmla (Disj \ \) = Suc (sz_fmla \ + sz_fmla \)" +| "sz_fmla (Exists n \) = Suc (sz_fmla \)" +| "sz_fmla (Forall n \) = Suc (Suc (Suc (Suc (sz_fmla \))))" +| "sz_fmla _ = 0" + +lemma sz_fmla_induct[case_names Pred Bool Eqa Neg Conj Disj Exists Forall]: + "(\r ts. P (Pred r ts)) \ (\b. P (Bool b)) \ + (\t t'. P (Eqa t t')) \ (\\. P \ \ P (Neg \)) \ + (\\ \. P \ \ P \ \ P (Conj \ \)) \ (\\ \. P \ \ P \ \ P (Disj \ \)) \ + (\n \. P \ \ P (Exists n \)) \ (\n \. P (Exists n (Neg \)) \ P (Forall n \)) \ P \" +proof (induction "sz_fmla \" arbitrary: \ rule: nat_less_induct) + case 1 + have IH: "\\. sz_fmla \ < sz_fmla \ \ P \" + using 1 + by auto + then show ?case + using 1(2,3,4,5,6,7,8,9) + by (cases \) auto +qed + +lemma esat_fv_cong: "(\n. n \ fv_fo_fmla \ \ \ n = \' n) \ esat \ I \ X \ esat \ I \' X" +proof (induction \ arbitrary: \ \' rule: sz_fmla_induct) + case (Pred r ts) + then show ?case + by (auto simp: eval_eterms_def fv_fo_terms_set_def) + (smt comp_apply eval_eterm_cong fv_fo_term_set_cong image_insert insertCI map_eq_conv + mk_disjoint_insert)+ +next + case (Eqa t t') + then show ?case + by (cases t; cases t') auto +next + case (Neg \) + show ?case + using Neg(1)[of \ \'] Neg(2) by auto +next + case (Conj \1 \2) + show ?case + using Conj(1,2)[of \ \'] Conj(3) by auto +next + case (Disj \1 \2) + show ?case + using Disj(1,2)[of \ \'] Disj(3) by auto +next + case (Exists n \) + show ?case + proof (rule iffI) + assume "esat (Exists n \) I \ X" + then obtain x where x_def: "x \ X" "esat \ I (\(n := x)) X" + by auto + from x_def(2) have "esat \ I (\'(n := x)) X" + using Exists(1)[of "\(n := x)" "\'(n := x)"] Exists(2) by fastforce + with x_def(1) show "esat (Exists n \) I \' X" + by auto + next + assume "esat (Exists n \) I \' X" + then obtain x where x_def: "x \ X" "esat \ I (\'(n := x)) X" + by auto + from x_def(2) have "esat \ I (\(n := x)) X" + using Exists(1)[of "\(n := x)" "\'(n := x)"] Exists(2) by fastforce + with x_def(1) show "esat (Exists n \) I \ X" + by auto + qed +next + case (Forall n \) + then show ?case + by auto +qed auto + +fun ad_terms :: "('a fo_term) list \ 'a set" where + "ad_terms ts = \(set (map set_fo_term ts))" + +fun act_edom :: "('a, 'b) fo_fmla \ ('a table, 'b) fo_intp \ 'a set" where + "act_edom (Pred r ts) I = ad_terms ts \ \(set ` I (r, length ts))" +| "act_edom (Bool b) I = {}" +| "act_edom (Eqa t t') I = set_fo_term t \ set_fo_term t'" +| "act_edom (Neg \) I = act_edom \ I" +| "act_edom (Conj \ \) I = act_edom \ I \ act_edom \ I" +| "act_edom (Disj \ \) I = act_edom \ I \ act_edom \ I" +| "act_edom (Exists n \) I = act_edom \ I" +| "act_edom (Forall n \) I = act_edom \ I" + +lemma finite_act_edom: "wf_fo_intp \ I \ finite (act_edom \ I)" + using finite_Inl + by (induction \ I rule: wf_fo_intp.induct) + (auto simp: finite_set_fo_term vimage_def) + +fun fo_adom :: "('a, 'c) fo_t \ 'a set" where + "fo_adom (AD, n, X) = AD" + +theorem main: "ad_agr \ AD \ \ \ act_edom \ I \ AD \ + Inl ` AD \ Inr ` {..} \ X \ \ ` fv_fo_fmla \ \ X \ + esat \ I \ UNIV \ esat \ I \ X" +proof (induction \ arbitrary: \ \ rule: sz_fmla_induct) + case (Pred r ts) + have fv_sub: "fv_fo_terms_set ts \ fv_fo_fmla (Pred r ts)" + by auto + have sub_AD: "\(set ` I (r, length ts)) \ AD" + using Pred(2) + by auto + show ?case + unfolding esat.simps + proof (rule iffI) + assume assm: "\ \e ts \ map Inl ` I (r, length ts)" + have "\ \e ts = \ \e ts" + using esat_Pred[OF ad_agr_sets_mono[OF sub_AD Pred(1)[unfolded ad_agr_def]] + fv_sub assm] + by (auto simp: eval_eterms_def) + with assm show "\ \e ts \ map Inl ` I (r, length ts)" + by auto + next + assume assm: "\ \e ts \ map Inl ` I (r, length ts)" + have "\ \e ts = \ \e ts" + using esat_Pred[OF ad_agr_sets_comm[OF ad_agr_sets_mono[OF + sub_AD Pred(1)[unfolded ad_agr_def]]] fv_sub assm] + by (auto simp: eval_eterms_def) + with assm show "\ \e ts \ map Inl ` I (r, length ts)" + by auto + qed +next + case (Eqa x1 x2) + show ?case + proof (cases x1; cases x2) + fix c c' + assume "x1 = Const c" "x2 = Const c'" + with Eqa show ?thesis + by auto + next + fix c m' + assume assms: "x1 = Const c" "x2 = Var m'" + with Eqa(1,2) have "\ m' = Inl c \ \ m' = Inl c" + apply (auto simp: ad_agr_def ad_agr_sets_def) + unfolding ad_equiv_pair.simps + by fastforce+ + with assms show ?thesis + by fastforce + next + fix m c' + assume assms: "x1 = Var m" "x2 = Const c'" + with Eqa(1,2) have "\ m = Inl c' \ \ m = Inl c'" + apply (auto simp: ad_agr_def ad_agr_sets_def) + unfolding ad_equiv_pair.simps + by fastforce+ + with assms show ?thesis + by auto + next + fix m m' + assume assms: "x1 = Var m" "x2 = Var m'" + with Eqa(1,2) have "\ m = \ m' \ \ m = \ m'" + by (auto simp: ad_agr_def ad_agr_sets_def sp_equiv_def pairwise_def split: if_splits) + with assms show ?thesis + by auto + qed +next + case (Neg \) + from Neg(2) have "ad_agr \ AD \ \" + by (auto simp: ad_agr_def) + with Neg show ?case + by auto +next + case (Conj \1 \2) + have aux: "ad_agr \1 AD \ \" "ad_agr \2 AD \ \" + "Inl ` AD \ Inr ` {..1} \ X" "Inl ` AD \ Inr ` {..2} \ X" + "\ ` fv_fo_fmla \1 \ X" "\ ` fv_fo_fmla \2 \ X" + using Conj(3,5,6) + by (auto simp: ad_agr_def ad_agr_sets_def sp_equiv_def pairwise_def) + show ?case + using Conj(1)[OF aux(1) _ aux(3) aux(5)] Conj(2)[OF aux(2) _ aux(4) aux(6)] Conj(4) + by auto +next + case (Disj \1 \2) + have aux: "ad_agr \1 AD \ \" "ad_agr \2 AD \ \" + "Inl ` AD \ Inr ` {..1} \ X" "Inl ` AD \ Inr ` {..2} \ X" + "\ ` fv_fo_fmla \1 \ X" "\ ` fv_fo_fmla \2 \ X" + using Disj(3,5,6) + by (auto simp: ad_agr_def ad_agr_sets_def sp_equiv_def pairwise_def) + show ?case + using Disj(1)[OF aux(1) _ aux(3) aux(5)] Disj(2)[OF aux(2) _ aux(4) aux(6)] Disj(4) + by auto +next + case (Exists m \) + show ?case + proof (rule iffI) + assume "esat (Exists m \) I \ UNIV" + then obtain x where assm: "esat \ I (\(m := x)) UNIV" + by auto + have "m \ SP \ \ Suc (card (Inr -` \ ` (SP \ - {m}))) \ card (SP \)" + by (metis Diff_insert_absorb card_image card_le_Suc_iff finite_Diff finite_SP + image_vimage_subset inj_Inr mk_disjoint_insert surj_card_le) + moreover have "card (Inr -` \ ` SP \) \ card (SP \)" + by (metis card_image finite_SP image_vimage_subset inj_Inr surj_card_le) + ultimately have "max 1 (card (Inr -` \ ` (SP \ - {m})) + (if m \ SP \ then 1 else 0)) \ d \" + using d_pos card_SP_d[of \] + by auto + then have "\x' \ X. ad_agr \ AD (\(m := x)) (\(m := x'))" + using extend_\[OF Exists(2)[unfolded ad_agr_def fv_fo_fmla.simps SP.simps] + SP_fv[of \] finite_SP Exists(5)[unfolded fv_fo_fmla.simps]] + Exists(4) + by (force simp: ad_agr_def) + then obtain x' where x'_def: "x' \ X" "ad_agr \ AD (\(m := x)) (\(m := x'))" + by auto + from Exists(5) have "\(m := x') ` fv_fo_fmla \ \ X" + using x'_def(1) by fastforce + then have "esat \ I (\(m := x')) X" + using Exists x'_def(1,2) assm + by fastforce + with x'_def show "esat (Exists m \) I \ X" + by auto + next + assume "esat (Exists m \) I \ X" + then obtain z where assm: "z \ X" "esat \ I (\(m := z)) X" + by auto + have ad_agr: "ad_agr_sets (fv_fo_fmla \ - {m}) (SP \ - {m}) AD \ \" + using Exists(2)[unfolded ad_agr_def fv_fo_fmla.simps SP.simps] + by (rule ad_agr_sets_comm) + have "\x. ad_agr \ AD (\(m := x)) (\(m := z))" + using extend_\[OF ad_agr SP_fv[of \] finite_SP subset_UNIV subset_UNIV] ad_agr_sets_comm + unfolding ad_agr_def + by fastforce + then obtain x where x_def: "ad_agr \ AD (\(m := x)) (\(m := z))" + by auto + have "\(m := z) ` fv_fo_fmla (Exists m \) \ X" + using Exists + by fastforce + with x_def have "esat \ I (\(m := x)) UNIV" + using Exists assm + by fastforce + then show "esat (Exists m \) I \ UNIV" + by auto + qed +next + case (Forall n \) + have unfold: "act_edom (Forall n \) I = act_edom (Exists n (Neg \)) I" + "Inl ` AD \ Inr ` {..)} = Inl ` AD \ Inr ` {..))}" + "fv_fo_fmla (Forall n \) = fv_fo_fmla (Exists n (Neg \))" + by auto + have pred: "ad_agr (Exists n (Neg \)) AD \ \" + using Forall(2) + by (auto simp: ad_agr_def) + show ?case + using Forall(1)[OF pred Forall(3,4,5)[unfolded unfold]] + by auto +qed auto + +lemma main_cor_inf: + assumes "ad_agr \ AD \ \" "act_edom \ I \ AD" "d \ \ n" + "\ ` fv_fo_fmla \ \ Inl ` AD \ Inr ` {.. I \ UNIV \ esat \ I \ (Inl ` AD \ Inr ` {.. :: "nat \ 'a + nat" + assumes "ad_agr \ AD \ \" "act_edom \ I \ AD" + shows "esat \ I \ UNIV \ esat \ I \ UNIV" +proof - + show ?thesis + using main[OF assms(1,2) subset_UNIV subset_UNIV] + by auto +qed + +lemma esat_UNIV_ad_agr_list: + fixes \ :: "nat \ 'a + nat" + assumes "ad_agr_list AD (map \ (fv_fo_fmla_list \)) (map \ (fv_fo_fmla_list \))" + "act_edom \ I \ AD" + shows "esat \ I \ UNIV \ esat \ I \ UNIV" + using esat_UNIV_cong[OF iffD2[OF ad_agr_def, OF ad_agr_sets_mono'[OF SP_fv], + OF iffD2[OF ad_agr_list_link, OF assms(1), unfolded fv_fo_fmla_list_set]] assms(2)] . + +fun fo_rep :: "('a, 'c) fo_t \ 'a table" where + "fo_rep (AD, n, X) = {ts. \ts' \ X. ad_agr_list AD (map Inl ts) ts'}" + +lemma sat_esat_conv: + fixes \ :: "('a :: infinite, 'b) fo_fmla" + assumes fin: "wf_fo_intp \ I" + shows "sat \ I \ \ esat \ I (Inl \ \ :: nat \ 'a + nat) UNIV" + using assms +proof (induction \ arbitrary: I \ rule: sz_fmla_induct) + case (Pred r ts) + show ?case + unfolding sat.simps esat.simps comp_def[symmetric] eval_terms_eterms[symmetric] + by auto +next + case (Eqa t t') + show ?case + by (cases t; cases t') auto +next + case (Exists n \) + show ?case + proof (rule iffI) + assume "sat (Exists n \) I \" + then obtain x where x_def: "esat \ I (Inl \ \(n := x)) UNIV" + using Exists + by fastforce + have Inl_unfold: "Inl \ \(n := x) = (Inl \ \)(n := Inl x)" + by auto + show "esat (Exists n \) I (Inl \ \) UNIV" + using x_def + unfolding Inl_unfold + by auto + next + assume "esat (Exists n \) I (Inl \ \) UNIV" + then obtain x where x_def: "esat \ I ((Inl \ \)(n := x)) UNIV" + by auto + show "sat (Exists n \) I \" + proof (cases x) + case (Inl a) + have Inl_unfold: "(Inl \ \)(n := x) = Inl \ \(n := a)" + by (auto simp: Inl) + show ?thesis + using x_def[unfolded Inl_unfold] Exists + by fastforce + next + case (Inr b) + obtain c where c_def: "c \ act_edom \ I \ \ ` fv_fo_fmla \" + using arb_element finite_act_edom[OF Exists(2), simplified] finite_fv_fo_fmla + by (metis finite_Un finite_imageI) + have wf_local: "wf_fo_intp \ I" + using Exists(2) + by auto + have "(a, a') \ set (zip (map (\x. if x = n then Inr b else (Inl \ \) x) (fv_fo_fmla_list \)) + (map (\a. Inl (if a = n then c else \ a)) (fv_fo_fmla_list \))) \ + ad_equiv_pair (act_edom \ I) (a, a')" for a a' + using c_def + by (cases a; cases a') (auto simp: set_zip ad_equiv_pair.simps split: if_splits) + then have "sat \ I (\(n := c))" + using c_def[folded fv_fo_fmla_list_set] + by (auto simp: ad_agr_list_def ad_equiv_list_def fun_upd_def sp_equiv_list_def pairwise_def set_zip split: if_splits + intro!: Exists(1)[OF wf_local, THEN iffD2, OF esat_UNIV_ad_agr_list[OF _ subset_refl, THEN iffD1, OF _ x_def[unfolded Inr]]]) + then show ?thesis + by auto + qed + qed +next + case (Forall n \) + show ?case + using Forall(1)[of I \] Forall(2) + by auto +qed auto + +lemma sat_ad_agr_list: + fixes \ :: "('a :: infinite, 'b) fo_fmla" + and J :: "(('a, nat) fo_t, 'b) fo_intp" + assumes "wf_fo_intp \ I" + "ad_agr_list AD (map (Inl \ \ :: nat \ 'a + nat) (fv_fo_fmla_list \)) + (map (Inl \ \) (fv_fo_fmla_list \))" "act_edom \ I \ AD" + shows "sat \ I \ \ sat \ I \" + using esat_UNIV_ad_agr_list[OF assms(2,3)] sat_esat_conv[OF assms(1)] + by auto + +definition nfv :: "('a, 'b) fo_fmla \ nat" where + "nfv \ = length (fv_fo_fmla_list \)" + +lemma nfv_card: "nfv \ = card (fv_fo_fmla \)" +proof - + have "distinct (fv_fo_fmla_list \)" + using sorted_distinct_fv_list + by auto + then have "length (fv_fo_fmla_list \) = card (set (fv_fo_fmla_list \))" + using distinct_card by fastforce + then show ?thesis + unfolding fv_fo_fmla_list_set by (auto simp: nfv_def) +qed + +fun rremdups :: "'a list \ 'a list" where + "rremdups [] = []" +| "rremdups (x # xs) = x # rremdups (filter ((\) x) xs)" + +lemma filter_rremdups_filter: "filter P (rremdups (filter Q xs)) = + rremdups (filter (\x. P x \ Q x) xs)" + apply (induction xs arbitrary: Q) + apply auto + by metis + +lemma filter_rremdups: "filter P (rremdups xs) = rremdups (filter P xs)" + using filter_rremdups_filter[where Q="\_. True"] + by auto + +lemma filter_take: "\j. filter P (take i xs) = take j (filter P xs)" + apply (induction xs arbitrary: i) + apply (auto) + apply (metis filter.simps(1) filter.simps(2) take_Cons' take_Suc_Cons) + apply (metis filter.simps(2) take0 take_Cons') + done + +lemma rremdups_take: "\j. rremdups (take i xs) = take j (rremdups xs)" +proof (induction xs arbitrary: i) + case (Cons x xs) + show ?case + proof (cases i) + case (Suc n) + obtain j where j_def: "rremdups (take n xs) = take j (rremdups xs)" + using Cons by auto + obtain j' where j'_def: "filter ((\) x) (take j (rremdups xs)) = + take j' (filter ((\) x) (rremdups xs))" + using filter_take + by blast + show ?thesis + by (auto simp: Suc filter_rremdups[symmetric] j_def j'_def intro: exI[of _ "Suc j'"]) + qed (auto simp add: take_Cons') +qed auto + +lemma rremdups_app: "rremdups (xs @ [x]) = rremdups xs @ (if x \ set xs then [] else [x])" + apply (induction xs) + apply auto + apply (smt filter.simps(1) filter.simps(2) filter_append filter_rremdups)+ + done + +lemma rremdups_set: "set (rremdups xs) = set xs" + by (induction xs) (auto simp: filter_rremdups[symmetric]) + +lemma distinct_rremdups: "distinct (rremdups xs)" +proof (induction "length xs" arbitrary: xs rule: nat_less_induct) + case 1 + then have IH: "\m ys. length (ys :: 'a list) < length xs \ distinct (rremdups ys)" + by auto + show ?case + proof (cases xs) + case (Cons z zs) + show ?thesis + using IH + by (auto simp: Cons rremdups_set le_imp_less_Suc) + qed auto +qed + +lemma length_rremdups: "length (rremdups xs) = card (set xs)" + using distinct_card[OF distinct_rremdups] + by (subst eq_commute) (auto simp: rremdups_set) + +lemma set_map_filter_sum: "set (List.map_filter (case_sum Map.empty Some) xs) = Inr -` set xs" + by (induction xs) (auto simp: List.map_filter_simps split: sum.splits) + +definition nats :: "nat list \ bool" where + "nats ns = (ns = [0.. ('a + nat) list \ bool" where + "fo_nmlzd AD xs \ Inl -` set xs \ AD \ + (let ns = List.map_filter (case_sum Map.empty Some) xs in nats (rremdups ns))" + +lemma fo_nmlzd_all_AD: + assumes "set xs \ Inl ` AD" + shows "fo_nmlzd AD xs" +proof - + have "List.map_filter (case_sum Map.empty Some) xs = []" + using assms + by (induction xs) (auto simp: List.map_filter_simps) + then show ?thesis + using assms + by (auto simp: fo_nmlzd_def nats_def Let_def) +qed + +lemma card_Inr_vimage_le_length: "card (Inr -` set xs) \ length xs" +proof - + have "card (Inr -` set xs) \ card (set xs)" + by (meson List.finite_set card_inj_on_le image_vimage_subset inj_Inr) + moreover have "\ \ length xs" + by (rule card_length) + finally show ?thesis . +qed + +lemma fo_nmlzd_set: + assumes "fo_nmlzd AD xs" + shows "set xs = set xs \ Inl ` AD \ Inr ` {.. AD" + using assms + by (auto simp: fo_nmlzd_def) + moreover have "Inr -` set xs = {.. Inl ` AD \ Inr ` {..j. List.map_filter f (take i xs) = take j (List.map_filter f xs)" + apply (induction xs arbitrary: i) + apply (auto simp: List.map_filter_simps split: option.splits) + apply (metis map_filter_simps(1) option.case(1) take0 take_Cons') + apply (metis map_filter_simps(1) map_filter_simps(2) option.case(2) take_Cons' take_Suc_Cons) + done + +lemma fo_nmlzd_take: assumes "fo_nmlzd AD xs" + shows "fo_nmlzd AD (take i xs)" +proof - + have aux: "rremdups zs = [0.. rremdups (take j zs) = + [0.. [y] | _ \ [])" + by (induction xs) (auto simp: List.map_filter_simps split: option.splits) + +lemma fo_nmlzd_app_Inr: "Inr n \ set xs \ Inr n' \ set xs \ fo_nmlzd AD (xs @ [Inr n]) \ + fo_nmlzd AD (xs @ [Inr n']) \ n = n'" + by (auto simp: List.map_filter_simps fo_nmlzd_def nats_def Let_def map_filter_app + rremdups_app set_map_filter_sum) + +fun all_tuples :: "'c set \ nat \ 'c table" where + "all_tuples xs 0 = {[]}" +| "all_tuples xs (Suc n) = \((\as. (\x. x # as) ` xs) ` (all_tuples xs n))" + +definition nall_tuples :: "'a set \ nat \ ('a + nat) table" where + "nall_tuples AD n = {zs \ all_tuples (Inl ` AD \ Inr ` {.. finite (all_tuples xs n)" + by (induction xs n rule: all_tuples.induct) auto + +lemma nall_tuples_finite: "finite AD \ finite (nall_tuples AD n)" + by (auto simp: nall_tuples_def all_tuples_finite) + +lemma all_tuplesI: "length vs = n \ set vs \ xs \ vs \ all_tuples xs n" +proof (induction xs n arbitrary: vs rule: all_tuples.induct) + case (2 xs n) + then obtain w ws where "vs = w # ws" "length ws = n" "set ws \ xs" "w \ xs" + by (metis Suc_length_conv contra_subsetD list.set_intros(1) order_trans set_subset_Cons) + with 2(1) show ?case + by auto +qed auto + +lemma nall_tuplesI: "length vs = n \ fo_nmlzd AD vs \ vs \ nall_tuples AD n" + using fo_nmlzd_set[of AD vs] + by (auto simp: nall_tuples_def intro!: all_tuplesI) + +lemma all_tuplesD: "vs \ all_tuples xs n \ length vs = n \ set vs \ xs" + by (induction xs n arbitrary: vs rule: all_tuples.induct) auto+ + +lemma all_tuples_setD: "vs \ all_tuples xs n \ set vs \ xs" + by (auto dest: all_tuplesD) + +lemma nall_tuplesD: "vs \ nall_tuples AD n \ + length vs = n \ set vs \ Inl ` AD \ Inr ` {.. fo_nmlzd AD vs" + by (auto simp: nall_tuples_def dest: all_tuplesD) + +lemma all_tuples_set: "all_tuples xs n = {ys. length ys = n \ set ys \ xs}" +proof (induction xs n rule: all_tuples.induct) + case (2 xs n) + show ?case + proof (rule subset_antisym; rule subsetI) + fix ys + assume "ys \ all_tuples xs (Suc n)" + then show "ys \ {ys. length ys = Suc n \ set ys \ xs}" + using 2 by auto + next + fix ys + assume "ys \ {ys. length ys = Suc n \ set ys \ xs}" + then have assm: "length ys = Suc n" "set ys \ xs" + by auto + then obtain z zs where zs_def: "ys = z # zs" "z \ xs" "length zs = n" "set zs \ xs" + by (cases ys) auto + with 2 have "zs \ all_tuples xs n" + by auto + with zs_def(1,2) show "ys \ all_tuples xs (Suc n)" + by auto + qed +qed auto + +lemma nall_tuples_set: "nall_tuples AD n = {ys. length ys = n \ fo_nmlzd AD ys}" + using fo_nmlzd_set[of AD] card_Inr_vimage_le_length + by (auto simp: nall_tuples_def all_tuples_set) (smt UnE nall_tuplesD nall_tuplesI subsetD) + +fun pos :: "'a \ 'a list \ nat option" where + "pos a [] = None" +| "pos a (x # xs) = + (if a = x then Some 0 else (case pos a xs of Some n \ Some (Suc n) | _ \ None))" + +lemma pos_set: "pos a xs = Some i \ a \ set xs" + by (induction a xs arbitrary: i rule: pos.induct) (auto split: if_splits option.splits) + +lemma pos_length: "pos a xs = Some i \ i < length xs" + by (induction a xs arbitrary: i rule: pos.induct) (auto split: if_splits option.splits) + +lemma pos_sound: "pos a xs = Some i \ i < length xs \ xs ! i = a" + by (induction a xs arbitrary: i rule: pos.induct) (auto split: if_splits option.splits) + +lemma pos_complete: "pos a xs = None \ a \ set xs" + by (induction a xs rule: pos.induct) (auto split: if_splits option.splits) + +fun rem_nth :: "nat \ 'a list \ 'a list" where + "rem_nth _ [] = []" +| "rem_nth 0 (x # xs) = xs" +| "rem_nth (Suc n) (x # xs) = x # rem_nth n xs" + +lemma rem_nth_length: "i < length xs \ length (rem_nth i xs) = length xs - 1" + by (induction i xs rule: rem_nth.induct) auto + +lemma rem_nth_take_drop: "i < length xs \ rem_nth i xs = take i xs @ drop (Suc i) xs" + by (induction i xs rule: rem_nth.induct) auto + +lemma rem_nth_sound: "distinct xs \ pos n xs = Some i \ + rem_nth i (map \ xs) = map \ (filter ((\) n) xs)" + apply (induction xs arbitrary: i) + apply (auto simp: pos_set split: option.splits) + by (metis (mono_tags, lifting) filter_True) + +fun add_nth :: "nat \ 'a \ 'a list \ 'a list" where + "add_nth 0 a xs = a # xs" +| "add_nth (Suc n) a zs = (case zs of x # xs \ x # add_nth n a xs)" + +lemma add_nth_length: "i \ length zs \ length (add_nth i z zs) = Suc (length zs)" + by (induction i z zs rule: add_nth.induct) (auto split: list.splits) + +lemma add_nth_take_drop: "i \ length zs \ add_nth i v zs = take i zs @ v # drop i zs" + by (induction i v zs rule: add_nth.induct) (auto split: list.splits) + +lemma add_nth_rem_nth_map: "distinct xs \ pos n xs = Some i \ + add_nth i a (rem_nth i (map \ xs)) = map (\(n := a)) xs" + by (induction xs arbitrary: i) (auto simp: pos_set split: option.splits) + +lemma add_nth_rem_nth_self: "i < length xs \ add_nth i (xs ! i) (rem_nth i xs) = xs" + by (induction i xs rule: rem_nth.induct) auto + +lemma rem_nth_add_nth: "i \ length zs \ rem_nth i (add_nth i z zs) = zs" + by (induction i z zs rule: add_nth.induct) (auto split: list.splits) + +fun merge :: "(nat \ 'a) list \ (nat \ 'a) list \ (nat \ 'a) list" where + "merge [] mys = mys" +| "merge nxs [] = nxs" +| "merge ((n, x) # nxs) ((m, y) # mys) = + (if n \ m then (n, x) # merge nxs ((m, y) # mys) + else (m, y) # merge ((n, x) # nxs) mys)" + +lemma merge_Nil2[simp]: "merge nxs [] = nxs" + by (cases nxs) auto + +lemma merge_length: "length (merge nxs mys) = length (map fst nxs @ map fst mys)" + by (induction nxs mys rule: merge.induct) auto + +lemma insort_aux_le: "\x\set nxs. n \ fst x \ \x\set mys. m \ fst x \ n \ m \ + insort n (sort (map fst nxs @ m # map fst mys)) = n # sort (map fst nxs @ m # map fst mys)" + by (induction nxs) (auto simp: insort_is_Cons insort_left_comm) + +lemma insort_aux_gt: "\x\set nxs. n \ fst x \ \x\set mys. m \ fst x \ \ n \ m \ + insort n (sort (map fst nxs @ m # map fst mys)) = + m # insort n (sort (map fst nxs @ map fst mys))" + apply (induction nxs) + apply (auto simp: insort_is_Cons) + by (metis dual_order.trans insort_key.simps(2) insort_left_comm) + +lemma map_fst_merge: "sorted_distinct (map fst nxs) \ sorted_distinct (map fst mys) \ + map fst (merge nxs mys) = sort (map fst nxs @ map fst mys)" + by (induction nxs mys rule: merge.induct) + (auto simp add: sorted_sort_id insort_is_Cons insort_aux_le insort_aux_gt) + +lemma merge_map': "sorted_distinct (map fst nxs) \ sorted_distinct (map fst mys) \ + fst ` set nxs \ fst ` set mys = {} \ + map snd nxs = map \ (map fst nxs) \ map snd mys = map \ (map fst mys) \ + map snd (merge nxs mys) = map \ (sort (map fst nxs @ map fst mys))" + by (induction nxs mys rule: merge.induct) + (auto simp: sorted_sort_id insort_is_Cons insort_aux_le insort_aux_gt) + +lemma merge_map: "sorted_distinct ns \ sorted_distinct ms \ set ns \ set ms = {} \ + map snd (merge (zip ns (map \ ns)) (zip ms (map \ ms))) = map \ (sort (ns @ ms))" + using merge_map'[of "zip ns (map \ ns)" "zip ms (map \ ms)" \] + by auto (metis length_map list.set_map map_fst_zip) + +fun fo_nmlz_rec :: "nat \ ('a + nat \ nat) \ 'a set \ + ('a + nat) list \ ('a + nat) list" where + "fo_nmlz_rec i m AD [] = []" +| "fo_nmlz_rec i m AD (Inl x # xs) = (if x \ AD then Inl x # fo_nmlz_rec i m AD xs else + (case m (Inl x) of None \ Inr i # fo_nmlz_rec (Suc i) (m(Inl x \ i)) AD xs + | Some j \ Inr j # fo_nmlz_rec i m AD xs))" +| "fo_nmlz_rec i m AD (Inr n # xs) = (case m (Inr n) of None \ + Inr i # fo_nmlz_rec (Suc i) (m(Inr n \ i)) AD xs + | Some j \ Inr j # fo_nmlz_rec i m AD xs)" + +lemma fo_nmlz_rec_sound: "ran m \ {.. filter ((\) i) (rremdups + (List.map_filter (case_sum Map.empty Some) (fo_nmlz_rec i m AD xs))) = ns \ + ns = [i.. AD") + case False + show ?thesis + proof (cases "m (Inl x)") + case None + have pred: "ran (m(Inl x \ i)) \ {..) (Suc i)) (rremdups + (List.map_filter (case_sum Map.empty Some) (fo_nmlz_rec (Suc i) (m(Inl x \ i)) AD xs)))" + using 2(5) False None + by (auto simp: List.map_filter_simps filter_rremdups) + (metis Suc_leD antisym not_less_eq_eq) + then show ?thesis + by (auto simp: 2(2)[OF False None pred, OF refl]) + (smt Suc_le_eq Suc_pred le_add1 le_zero_eq less_add_same_cancel1 not_less_eq_eq + upt_Suc_append upt_rec) + next + case (Some j) + then have j_lt_i: "j < i" + using 2(4) + by (auto simp: ran_def) + have ns_def: "ns = filter ((\) i) (rremdups + (List.map_filter (case_sum Map.empty Some) (fo_nmlz_rec i m AD xs)))" + using 2(5) False Some j_lt_i + by (auto simp: List.map_filter_simps filter_rremdups) (metis leD) + show ?thesis + by (rule 2(3)[OF False Some 2(4) ns_def[symmetric]]) + qed + qed (auto simp: List.map_filter_simps split: option.splits) +next + case (3 i m AD n xs) + show ?case + proof (cases "m (Inr n)") + case None + have pred: "ran (m(Inr n \ i)) \ {..) (Suc i)) (rremdups + (List.map_filter (case_sum Map.empty Some) (fo_nmlz_rec (Suc i) (m(Inr n \ i)) AD xs)))" + using 3(4) None + by (auto simp: List.map_filter_simps filter_rremdups) (metis Suc_leD antisym not_less_eq_eq) + then show ?thesis + by (auto simp add: 3(1)[OF None pred, OF refl]) + (smt Suc_le_eq Suc_pred le_add1 le_zero_eq less_add_same_cancel1 not_less_eq_eq + upt_Suc_append upt_rec) + next + case (Some j) + then have j_lt_i: "j < i" + using 3(3) + by (auto simp: ran_def) + have ns_def: "ns = filter ((\) i) (rremdups + (List.map_filter (case_sum Map.empty Some) (fo_nmlz_rec i m AD xs)))" + using 3(4) Some j_lt_i + by (auto simp: List.map_filter_simps filter_rremdups) (metis leD) + show ?thesis + by (rule 3(2)[OF Some 3(3) ns_def[symmetric]]) + qed +qed (auto simp: List.map_filter_simps) + +definition id_map :: "nat \ ('a + nat \ nat)" where + "id_map n = (\x. case x of Inl x \ None | Inr x \ if x < n then Some x else None)" + +lemma fo_nmlz_rec_idem: "Inl -` set ys \ AD \ + rremdups (List.map_filter (case_sum Map.empty Some) ys) = ns \ + set (filter (\n. n < i) ns) \ {.. filter ((\) i) ns = [i.. + fo_nmlz_rec i (id_map i) AD ys = ys" +proof (induction ys arbitrary: i k ns) + case (Cons y ys) + show ?case + proof (cases y) + case (Inl a) + show ?thesis + using Cons(1)[OF _ _ Cons(4,5)] Cons(2,3) + by (auto simp: Inl List.map_filter_simps) + next + case (Inr j) + show ?thesis + proof (cases "j < i") + case False + have j_i: "j = i" + using False Cons(3,5) + by (auto simp: Inr List.map_filter_simps filter_rremdups in_mono split: if_splits) + (metis (no_types, lifting) upt_eq_Cons_conv) + obtain kk where k_def: "k = Suc kk" + using Cons(3,5) + by (cases k) (auto simp: Inr List.map_filter_simps j_i) + define ns' where "ns' = rremdups (List.map_filter (case_sum Map.empty Some) ys)" + have id_map_None: "id_map i (Inr i) = None" + by (auto simp: id_map_def) + have id_map_upd: "id_map i(Inr i \ i) = id_map (Suc i)" + by (auto simp: id_map_def split: sum.splits) + have "set (filter (\n. n < Suc i) ns') \ {..) (Suc i)) ns' = [Suc i.. AD" + using Cons(2) + by (auto simp: vimage_def) + ultimately have "fo_nmlz_rec (Suc i) ((id_map i)(Inr i \ i)) AD ys = ys" + using Cons(1)[OF _ ns'_def[symmetric], of "Suc i" kk] + by (auto simp: ns'_def k_def id_map_upd split: if_splits) + then show ?thesis + by (auto simp: Inr j_i id_map_None) + next + case True + define ns' where "ns' = rremdups (List.map_filter (case_sum Map.empty Some) ys)" + have "set (filter (\y. y < i) ns') \ set (filter (\y. y < i) ns)" + "filter ((\) i) ns' = filter ((\) i) ns" + using Cons(3) True + by (auto simp: Inr List.map_filter_simps filter_rremdups[symmetric] ns'_def[symmetric]) + (smt filter_cong leD) + then have "fo_nmlz_rec i (id_map i) AD ys = ys" + using Cons(1)[OF _ ns'_def[symmetric]] Cons(3,5) Cons(2) + by (auto simp: vimage_def) + then show ?thesis + using True + by (auto simp: Inr id_map_def) + qed + qed +qed (auto simp: List.map_filter_simps intro!: exI[of _ "[]"]) + +lemma fo_nmlz_rec_length: "length (fo_nmlz_rec i m AD xs) = length xs" + by (induction i m AD xs rule: fo_nmlz_rec.induct) (auto simp: fun_upd_def split: option.splits) + +lemma insert_Inr: "\X. insert (Inr i) (X \ Inr ` {.. Inr ` {.. {.. set (fo_nmlz_rec i m AD xs) \ Inr ` {.. Inl ` AD \ Inr ` {.. AD") + case True + have "card (set (Inl x # xs) - Inl ` AD - dom m) = card (set xs - Inl ` AD - dom m)" + using True + by auto + then show ?thesis + using 2(1)[OF True 2(4)] True + by auto + next + case False + show ?thesis + proof (cases "m (Inl x)") + case None + have pred: "ran (m(Inl x \ i)) \ {.. (set xs - Inl ` AD - dom (m(Inl x \ i)))" + using None False + by (auto simp: dom_def) + then have Suc: "Suc i + card (set xs - Inl ` AD - dom (m(Inl x \ i))) = + i + card (set (Inl x # xs) - Inl ` AD - dom m)" + using None + by auto + show ?thesis + using 2(2)[OF False None pred] False None + unfolding Suc + by (auto simp: fun_upd_def[symmetric] insert_Inr) + next + case (Some j) + then have j_lt_i: "j < i" + using 2(4) + by (auto simp: ran_def) + have "card (set (Inl x # xs) - Inl ` AD - dom m) = card (set xs - Inl ` AD - dom m)" + by (auto simp: Some intro: arg_cong[of _ _ card]) + then show ?thesis + using 2(3)[OF False Some 2(4)] False Some j_lt_i + by auto + qed + qed +next + case (3 i m AD k xs) + then show ?case + proof (cases "m (Inr k)") + case None + have preds: "ran (m(Inr k \ i)) \ {.. (set xs - Inl ` AD - dom (m(Inr k \ i)))" + using None + by (auto simp: dom_def) + then have Suc: "Suc i + card (set xs - Inl ` AD - dom (m(Inr k \ i))) = + i + card (set (Inr k # xs) - Inl ` AD - dom m)" + using None + by auto + show ?thesis + using None 3(1)[OF None preds] + unfolding Suc + by (auto simp: fun_upd_def[symmetric] insert_Inr) + next + case (Some j) + have fin: "finite (set (Inr k # xs) - Inl ` AD - dom m)" + by auto + have card_eq: "card (set xs - Inl ` AD - dom m) = card (set (Inr k # xs) - Inl ` AD - dom m)" + by (auto simp: Some intro!: arg_cong[of _ _ card]) + have j_lt_i: "j < i" + using 3(3) Some + by (auto simp: ran_def) + show ?thesis + using 3(2)[OF Some 3(3)] j_lt_i + unfolding card_eq + by (auto simp: ran_def insert_Inr Some) + qed +qed auto + +lemma fo_nmlz_rec_set_rev: "set (fo_nmlz_rec i m AD xs) \ Inl ` AD \ set xs \ Inl ` AD" + by (induction i m AD xs rule: fo_nmlz_rec.induct) (auto split: if_splits option.splits) + +lemma fo_nmlz_rec_map: "inj_on m (dom m) \ ran m \ {.. \m'. inj_on m' (dom m') \ + (\n. m n \ None \ m' n = m n) \ (\(x, y) \ set (zip xs (fo_nmlz_rec i m AD xs)). + (case x of Inl x' \ if x' \ AD then x = y else \j. m' (Inl x') = Some j \ y = Inr j + | Inr n \ \j. m' (Inr n) = Some j \ y = Inr j))" +proof (induction i m AD xs rule: fo_nmlz_rec.induct) + case (2 i m AD x xs) + show ?case + using 2(1)[OF _ 2(4,5)] + proof (cases "x \ AD") + case False + show ?thesis + proof (cases "m (Inl x)") + case None + have preds: "inj_on (m(Inl x \ i)) (dom (m(Inl x \ i)))" "ran (m(Inl x \ i)) \ {.. i)) (dom (m(Inr n \ i)))" "ran (m(Inr n \ i)) \ {..x y. (x, y) \ set (zip xs ys) \ (case x of Inl x' \ + if x' \ AD then x = y else m x = Some y \ (case y of Inl z \ z \ AD | Inr _ \ True) + | Inr n \ m x = Some y \ (case y of Inl z \ z \ AD | Inr _ \ True))" + shows "ad_agr_list AD xs ys" +proof - + have "ad_equiv_pair AD (a, b)" if "(a, b) \ set (zip xs ys)" for a b + unfolding ad_equiv_pair.simps + using assms(3)[OF that] + by (auto split: sum.splits if_splits) + moreover have "False" if "(a, c) \ set (zip xs ys)" "(b, c) \ set (zip xs ys)" "a \ b" for a b c + using assms(3)[OF that(1)] assms(3)[OF that(2)] assms(2) that(3) + by (auto split: sum.splits if_splits) (metis domI inj_onD that(3))+ + moreover have "False" if "(a, b) \ set (zip xs ys)" "(a, c) \ set (zip xs ys)" "b \ c" for a b c + using assms(3)[OF that(1)] assms(3)[OF that(2)] assms(2) that(3) + by (auto split: sum.splits if_splits) + ultimately show ?thesis + using assms + by (fastforce simp: ad_agr_list_def ad_equiv_list_def sp_equiv_list_def pairwise_def) +qed + +lemma fo_nmlz_rec_take: "take n (fo_nmlz_rec i m AD xs) = fo_nmlz_rec i m AD (take n xs)" + by (induction i m AD xs arbitrary: n rule: fo_nmlz_rec.induct) + (auto simp: take_Cons' split: option.splits) + +definition fo_nmlz :: "'a set \ ('a + nat) list \ ('a + nat) list" where + "fo_nmlz = fo_nmlz_rec 0 Map.empty" + +lemma fo_nmlz_Nil[simp]: "fo_nmlz AD [] = []" + by (auto simp: fo_nmlz_def) + +lemma fo_nmlz_Cons: "fo_nmlz AD [x] = + (case x of Inl x \ if x \ AD then [Inl x] else [Inr 0] | _ \ [Inr 0])" + by (auto simp: fo_nmlz_def split: sum.splits) + +lemma fo_nmlz_Cons_Cons: "fo_nmlz AD [x, x] = + (case x of Inl x \ if x \ AD then [Inl x, Inl x] else [Inr 0, Inr 0] | _ \ [Inr 0, Inr 0])" + by (auto simp: fo_nmlz_def split: sum.splits) + +lemma fo_nmlz_sound: "fo_nmlzd AD (fo_nmlz AD xs)" + using fo_nmlz_rec_sound[of Map.empty 0] fo_nmlz_rec_set[of Map.empty 0 AD xs] + by (auto simp: fo_nmlzd_def fo_nmlz_def nats_def Let_def) + +lemma fo_nmlz_length: "length (fo_nmlz AD xs) = length xs" + using fo_nmlz_rec_length + by (auto simp: fo_nmlz_def) + +lemma fo_nmlz_map: "\\. fo_nmlz AD (map \ ns) = map \ ns" +proof - + obtain m' where m'_def: "\(x, y)\set (zip (map \ ns) (fo_nmlz AD (map \ ns))). + case x of Inl x' \ if x' \ AD then x = y else \j. m' (Inl x') = Some j \ y = Inr j + | Inr n \ \j. m' (Inr n) = Some j \ y = Inr j" + using fo_nmlz_rec_map[of Map.empty 0, of "map \ ns"] + by (auto simp: fo_nmlz_def) + define \ where "\ \ (\n. case \ n of Inl x \ if x \ AD then Inl x else Inr (the (m' (Inl x))) + | Inr j \ Inr (the (m' (Inr j))))" + have "fo_nmlz AD (map \ ns) = map \ ns" + proof (rule nth_equalityI) + show "length (fo_nmlz AD (map \ ns)) = length (map \ ns)" + using fo_nmlz_length[of AD "map \ ns"] + by auto + fix i + assume "i < length (fo_nmlz AD (map \ ns))" + then show "fo_nmlz AD (map \ ns) ! i = map \ ns ! i" + using m'_def fo_nmlz_length[of AD "map \ ns"] + apply (auto simp: set_zip \_def split: sum.splits) + apply (metis nth_map) + apply (metis nth_map option.sel)+ + done + qed + then show ?thesis + by auto +qed + +lemma card_set_minus: "card (set xs - X) \ length xs" + by (meson Diff_subset List.finite_set card_length card_mono order_trans) + +lemma fo_nmlz_set: "set (fo_nmlz AD xs) = + set xs \ Inl ` AD \ Inr ` {.. Inl ` AD \ set xs \ Inl ` AD" + using fo_nmlz_rec_set_rev[of 0 Map.empty AD xs] + by (auto simp: fo_nmlz_def) + +lemma inj_on_empty: "inj_on Map.empty (dom Map.empty)" and ran_empty_upto: "ran Map.empty \ {..<0}" + by auto + +lemma fo_nmlz_ad_agr: "ad_agr_list AD xs (fo_nmlz AD xs)" + using fo_nmlz_rec_map[OF inj_on_empty ran_empty_upto, of xs AD] + unfolding fo_nmlz_def + apply safe + subgoal for m' + by (fastforce simp: inj_on_def dom_def split: sum.splits if_splits + intro!: ad_agr_map[OF fo_nmlz_rec_length[symmetric], of "map_option Inr \ m'"]) + done + +lemma fo_nmlzd_mono: "Inl -` set xs \ AD \ fo_nmlzd AD' xs \ fo_nmlzd AD xs" + by (auto simp: fo_nmlzd_def) + +lemma fo_nmlz_idem: "fo_nmlzd AD ys \ fo_nmlz AD ys = ys" + using fo_nmlz_rec_idem[where ?i=0] + by (auto simp: fo_nmlzd_def fo_nmlz_def id_map_def nats_def Let_def) + +lemma fo_nmlz_take: "take n (fo_nmlz AD xs) = fo_nmlz AD (take n xs)" + using fo_nmlz_rec_take + by (auto simp: fo_nmlz_def) + +fun nall_tuples_rec :: "'a set \ nat \ nat \ ('a + nat) table" where + "nall_tuples_rec AD i 0 = {[]}" +| "nall_tuples_rec AD i (Suc n) = \((\as. (\x. x # as) ` (Inl ` AD \ Inr ` {.. (\as. Inr i # as) ` nall_tuples_rec AD (Suc i) n" + +lemma nall_tuples_rec_Inl: "vs \ nall_tuples_rec AD i n \ Inl -` set vs \ AD" + by (induction AD i n arbitrary: vs rule: nall_tuples_rec.induct) (fastforce simp: vimage_def)+ + +lemma nall_tuples_rec_length: "xs \ nall_tuples_rec AD i n \ length xs = n" + by (induction AD i n arbitrary: xs rule: nall_tuples_rec.induct) auto + +lemma fun_upd_id_map: "id_map i(Inr i \ i) = id_map (Suc i)" + by (rule ext) (auto simp: id_map_def split: sum.splits) + +lemma id_mapD: "id_map j (Inr i) = None \ j \ i" "id_map j (Inr i) = Some x \ i < j \ i = x" + by (auto simp: id_map_def split: if_splits) + +lemma nall_tuples_rec_fo_nmlz_rec_sound: "i \ j \ xs \ nall_tuples_rec AD i n \ + fo_nmlz_rec j (id_map j) AD xs = xs" + apply (induction n arbitrary: i j xs) + apply (auto simp: fun_upd_id_map dest!: id_mapD split: option.splits) + apply (meson dual_order.strict_trans2 id_mapD(1) not_Some_eq sup.strict_order_iff) + using Suc_leI apply blast+ + done + +lemma nall_tuples_rec_fo_nmlz_rec_complete: + assumes "fo_nmlz_rec j (id_map j) AD xs = xs" + shows "xs \ nall_tuples_rec AD j (length xs)" + using assms +proof (induction xs arbitrary: j) + case (Cons x xs) + show ?case + proof (cases x) + case (Inl a) + have a_AD: "a \ AD" + using Cons(2) + by (auto simp: Inl split: if_splits option.splits) + show ?thesis + using Cons a_AD + by (auto simp: Inl) + next + case (Inr b) + have b_j: "b \ j" + using Cons(2) + by (auto simp: Inr split: option.splits dest: id_mapD) + show ?thesis + proof (cases "b = j") + case True + have preds: "fo_nmlz_rec (Suc j) (id_map (Suc j)) AD xs = xs" + using Cons(2) + by (auto simp: Inr True fun_upd_id_map dest: id_mapD split: option.splits) + show ?thesis + using Cons(1)[OF preds] + by (auto simp: Inr True) + next + case False + have b_lt_j: "b < j" + using b_j False + by auto + have id_map: "id_map j (Inr b) = Some b" + using b_lt_j + by (auto simp: id_map_def) + have preds: "fo_nmlz_rec j (id_map j) AD xs = xs" + using Cons(2) + by (auto simp: Inr id_map) + show ?thesis + using Cons(1)[OF preds] b_lt_j + by (auto simp: Inr) + qed + qed +qed auto + +lemma nall_tuples_rec_fo_nmlz: "xs \ nall_tuples_rec AD 0 (length xs) \ fo_nmlz AD xs = xs" + using nall_tuples_rec_fo_nmlz_rec_sound[of 0 0 xs AD "length xs"] + nall_tuples_rec_fo_nmlz_rec_complete[of 0 AD xs] + by (auto simp: fo_nmlz_def id_map_def) + +lemma fo_nmlzd_code[code]: "fo_nmlzd AD xs \ fo_nmlz AD xs = xs" + using fo_nmlz_idem fo_nmlz_sound + by metis + +lemma nall_tuples_code[code]: "nall_tuples AD n = nall_tuples_rec AD 0 n" + unfolding nall_tuples_set + using nall_tuples_rec_length trans[OF nall_tuples_rec_fo_nmlz fo_nmlzd_code[symmetric]] + by fastforce + +lemma exists_map: "length xs = length ys \ distinct xs \ \f. ys = map f xs" +proof (induction xs ys rule: list_induct2) + case (Cons x xs y ys) + then obtain f where f_def: "ys = map f xs" + by auto + with Cons(3) have "y # ys = map (f(x := y)) (x # xs)" + by auto + then show ?case + by metis +qed auto + +lemma exists_fo_nmlzd: + assumes "length xs = length ys" "distinct xs" "fo_nmlzd AD ys" + shows "\f. ys = fo_nmlz AD (map f xs)" + using fo_nmlz_idem[OF assms(3)] exists_map[OF _ assms(2)] assms(1) + by metis + +lemma list_induct2_rev[consumes 1]: "length xs = length ys \ (P [] []) \ + (\x y xs ys. P xs ys \ P (xs @ [x]) (ys @ [y])) \ P xs ys" +proof (induction "length xs" arbitrary: xs ys) + case (Suc n) + then show ?case + by (cases xs rule: rev_cases; cases ys rule: rev_cases) auto +qed auto + +lemma ad_agr_list_fo_nmlzd: + assumes "ad_agr_list AD vs vs'" "fo_nmlzd AD vs" "fo_nmlzd AD vs'" + shows "vs = vs'" + using ad_agr_list_length[OF assms(1)] assms +proof (induction vs vs' rule: list_induct2_rev) + case (2 x y xs ys) + have norms: "fo_nmlzd AD xs" "fo_nmlzd AD ys" + using 2(3,4) + by (auto simp: fo_nmlzd_def nats_def Let_def map_filter_app rremdups_app + split: sum.splits if_splits) + have ad_agr: "ad_agr_list AD xs ys" + using 2(2) + by (auto simp: ad_agr_list_def ad_equiv_list_def sp_equiv_list_def pairwise_def) + note xs_ys = 2(1)[OF ad_agr norms] + have "x = y" + proof (cases "isl x \ isl y") + case True + then have "isl x \ projl x \ AD" "isl y \ projl y \ AD" + using 2(3,4) + by (auto simp: fo_nmlzd_def) + then show ?thesis + using 2(2) True + apply (auto simp: ad_agr_list_def ad_equiv_list_def isl_def) + unfolding ad_equiv_pair.simps + by blast+ + next + case False + then obtain x' y' where inr: "x = Inr x'" "y = Inr y'" + by (cases x; cases y) auto + show ?thesis + using 2(2) xs_ys + proof (cases "x \ set xs \ y \ set ys") + case False + then show ?thesis + using fo_nmlzd_app_Inr 2(3,4) + unfolding inr xs_ys + by auto + qed (auto simp: ad_agr_list_def sp_equiv_list_def pairwise_def set_zip in_set_conv_nth) + qed + then show ?case + using xs_ys + by auto +qed auto + +lemma fo_nmlz_eqI: + assumes "ad_agr_list AD vs vs'" + shows "fo_nmlz AD vs = fo_nmlz AD vs'" + using ad_agr_list_fo_nmlzd[OF + ad_agr_list_trans[OF ad_agr_list_trans[OF + ad_agr_list_comm[OF fo_nmlz_ad_agr[of AD vs]] assms] + fo_nmlz_ad_agr[of AD vs']] fo_nmlz_sound fo_nmlz_sound] . + +lemma fo_nmlz_eqD: + assumes "fo_nmlz AD vs = fo_nmlz AD vs'" + shows "ad_agr_list AD vs vs'" + using ad_agr_list_trans[OF fo_nmlz_ad_agr[of AD vs, unfolded assms] + ad_agr_list_comm[OF fo_nmlz_ad_agr[of AD vs']]] . + +lemma fo_nmlz_eq: "fo_nmlz AD vs = fo_nmlz AD vs' \ ad_agr_list AD vs vs'" + using fo_nmlz_eqI[where ?AD=AD] fo_nmlz_eqD[where ?AD=AD] + by blast + +lemma fo_nmlz_mono: + assumes "AD \ AD'" "Inl -` set xs \ AD" + shows "fo_nmlz AD' xs = fo_nmlz AD xs" +proof - + have "fo_nmlz AD (fo_nmlz AD' xs) = fo_nmlz AD' xs" + apply (rule fo_nmlz_idem[OF fo_nmlzd_mono[OF _ fo_nmlz_sound]]) + using assms + by (auto simp: fo_nmlz_set) + moreover have "fo_nmlz AD xs = fo_nmlz AD (fo_nmlz AD' xs)" + apply (rule fo_nmlz_eqI) + apply (rule ad_agr_list_mono[OF assms(1)]) + apply (rule fo_nmlz_ad_agr) + done + ultimately show ?thesis + by auto +qed + +definition proj_vals :: "'c val set \ nat list \ 'c table" where + "proj_vals R ns = (\\. map \ ns) ` R" + +definition proj_fmla :: "('a, 'b) fo_fmla \ 'c val set \ 'c table" where + "proj_fmla \ R = proj_vals R (fv_fo_fmla_list \)" + +lemmas proj_fmla_map = proj_fmla_def[unfolded proj_vals_def] + +definition "extends_subst \ \ = (\x. \ x \ None \ \ x = \ x)" + +definition ext_tuple :: "'a set \ nat list \ nat list \ + ('a + nat) list \ ('a + nat) list set" where + "ext_tuple AD fv_sub fv_sub_comp as = (if fv_sub_comp = [] then {as} + else (\fs. map snd (merge (zip fv_sub as) (zip fv_sub_comp fs))) ` + (nall_tuples_rec AD (card (Inr -` set as)) (length fv_sub_comp)))" + +lemma ext_tuple_eq: "length fv_sub = length as \ + ext_tuple AD fv_sub fv_sub_comp as = + (\fs. map snd (merge (zip fv_sub as) (zip fv_sub_comp fs))) ` + (nall_tuples_rec AD (card (Inr -` set as)) (length fv_sub_comp))" + using fo_nmlz_idem[of AD as] + by (auto simp: ext_tuple_def) + +lemma map_map_of: "length xs = length ys \ distinct xs \ + ys = map (the \ (map_of (zip xs ys))) xs" + by (induction xs ys rule: list_induct2) (auto simp: fun_upd_comp) + +lemma id_map_empty: "id_map 0 = Map.empty" + by (rule ext) (auto simp: id_map_def split: sum.splits) + +lemma fo_nmlz_rec_shift: + fixes xs :: "('a + nat) list" + shows "fo_nmlz_rec i (id_map i) AD xs = xs \ + i' = card (Inr -` (Inr ` {.. set (take n xs))) \ n \ length xs \ + fo_nmlz_rec i' (id_map i') AD (drop n xs) = drop n xs" +proof (induction i "id_map i :: 'a + nat \ nat" AD xs arbitrary: n rule: fo_nmlz_rec.induct) + case (2 i AD x xs) + have preds: "x \ AD" "fo_nmlz_rec i (id_map i) AD xs = xs" + using 2(4) + by (auto split: if_splits option.splits) + show ?case + using 2(4,5) + proof (cases n) + case (Suc k) + have k_le: "k \ length xs" + using 2(6) + by (auto simp: Suc) + have i'_def: "i' = card (Inr -` (Inr ` {.. set (take k xs)))" + using 2(5) + by (auto simp: Suc vimage_def) + show ?thesis + using 2(1)[OF preds i'_def k_le] + by (auto simp: Suc) + qed (auto simp: inj_vimage_image_eq) +next + case (3 i AD j xs) + show ?case + using 3(3,4) + proof (cases n) + case (Suc k) + have k_le: "k \ length xs" + using 3(5) + by (auto simp: Suc) + have j_le_i: "j \ i" + using 3(3) + by (auto split: option.splits dest: id_mapD) + show ?thesis + proof (cases "j = i") + case True + have id_map: "id_map i (Inr j) = None" "id_map i(Inr j \ i) = id_map (Suc i)" + unfolding True fun_upd_id_map + by (auto simp: id_map_def) + have norm_xs: "fo_nmlz_rec (Suc i) (id_map (Suc i)) AD xs = xs" + using 3(3) + by (auto simp: id_map split: option.splits dest: id_mapD) + have i'_def: "i' = card (Inr -` (Inr ` {.. set (take k xs)))" + using 3(4) + by (auto simp: Suc True inj_vimage_image_eq) + (metis Un_insert_left image_insert inj_Inr inj_vimage_image_eq lessThan_Suc vimage_Un) + show ?thesis + using 3(1)[OF id_map norm_xs i'_def k_le] + by (auto simp: Suc) + next + case False + have id_map: "id_map i (Inr j) = Some j" + using j_le_i False + by (auto simp: id_map_def) + have norm_xs: "fo_nmlz_rec i (id_map i) AD xs = xs" + using 3(3) + by (auto simp: id_map) + have i'_def: "i' = card (Inr -` (Inr ` {.. set (take k xs)))" + using 3(4) j_le_i False + by (auto simp: Suc inj_vimage_image_eq insert_absorb) + show ?thesis + using 3(2)[OF id_map norm_xs i'_def k_le] + by (auto simp: Suc) + qed + qed (auto simp: inj_vimage_image_eq) +qed auto + +fun proj_tuple :: "nat list \ (nat \ ('a + nat)) list \ ('a + nat) list" where + "proj_tuple [] mys = []" +| "proj_tuple ns [] = []" +| "proj_tuple (n # ns) ((m, y) # mys) = + (if m < n then proj_tuple (n # ns) mys else + if m = n then y # proj_tuple ns mys + else proj_tuple ns ((m, y) # mys))" + +lemma proj_tuple_idle: "proj_tuple (map fst nxs) nxs = map snd nxs" + by (induction nxs) auto + +lemma proj_tuple_merge: "sorted_distinct (map fst nxs) \ sorted_distinct (map fst mys) \ + set (map fst nxs) \ set (map fst mys) = {} \ + proj_tuple (map fst nxs) (merge nxs mys) = map snd nxs" + using proj_tuple_idle + by (induction nxs mys rule: merge.induct) auto+ + +lemma proj_tuple_map: + assumes "sorted_distinct ns" "sorted_distinct ms" "set ns \ set ms" + shows "proj_tuple ns (zip ms (map \ ms)) = map \ ns" +proof - + define ns' where "ns' = filter (\n. n \ set ns) ms" + have sd_ns': "sorted_distinct ns'" + using assms(2) sorted_filter[of id] + by (auto simp: ns'_def) + have disj: "set ns \ set ns' = {}" + by (auto simp: ns'_def) + have ms_def: "ms = sort (ns @ ns')" + apply (rule sorted_distinct_set_unique) + using assms + by (auto simp: ns'_def) + have zip: "zip ms (map \ ms) = merge (zip ns (map \ ns)) (zip ns' (map \ ns'))" + unfolding merge_map[OF assms(1) sd_ns' disj, folded ms_def, symmetric] + using map_fst_merge assms(1) + by (auto simp: ms_def) (smt length_map map_fst_merge map_fst_zip sd_ns' zip_map_fst_snd) + show ?thesis + unfolding zip + using proj_tuple_merge + by (smt assms(1) disj length_map map_fst_zip map_snd_zip sd_ns') +qed + +lemma proj_tuple_length: + assumes "sorted_distinct ns" "sorted_distinct ms" "set ns \ set ms" "length ms = length xs" + shows "length (proj_tuple ns (zip ms xs)) = length ns" +proof - + obtain \ where \: "xs = map \ ms" + using exists_map[OF assms(4)] assms(2) + by auto + show ?thesis + unfolding \ + by (auto simp: proj_tuple_map[OF assms(1-3)]) +qed + +lemma ext_tuple_sound: + assumes "sorted_distinct fv_sub" "sorted_distinct fv_sub_comp" "sorted_distinct fv_all" + "set fv_sub \ set fv_sub_comp = {}" "set fv_sub \ set fv_sub_comp = set fv_all" + "ass = fo_nmlz AD ` proj_vals R fv_sub" + "\\ \. ad_agr_sets (set fv_sub) (set fv_sub) AD \ \ \ \ \ R \ \ \ R" + "xs \ fo_nmlz AD ` \(ext_tuple AD fv_sub fv_sub_comp ` ass)" + shows "fo_nmlz AD (proj_tuple fv_sub (zip fv_all xs)) \ ass" + "xs \ fo_nmlz AD ` proj_vals R fv_all" +proof - + have fv_all_sort: "fv_all = sort (fv_sub @ fv_sub_comp)" + using assms(1,2,3,4,5) + by (simp add: sorted_distinct_set_unique) + have len_in_ass: "\xs. xs \ ass \ xs = fo_nmlz AD xs \ length xs = length fv_sub" + by (auto simp: assms(6) proj_vals_def fo_nmlz_length fo_nmlz_idem fo_nmlz_sound) + obtain as fs where as_fs_def: "as \ ass" + "fs \ nall_tuples_rec AD (card (Inr -` set as)) (length fv_sub_comp)" + "xs = fo_nmlz AD (map snd (merge (zip fv_sub as) (zip fv_sub_comp fs)))" + using fo_nmlz_sound len_in_ass assms(8) + by (auto simp: ext_tuple_def split: if_splits) + then have vs_norm: "fo_nmlzd AD xs" + using fo_nmlz_sound + by auto + obtain \ where \_def: "\ \ R" "as = fo_nmlz AD (map \ fv_sub)" + using as_fs_def(1) assms(6) + by (auto simp: proj_vals_def) + then obtain \ where \_def: "as = map \ fv_sub" "ad_agr_list AD (map \ fv_sub) (map \ fv_sub)" + using fo_nmlz_map fo_nmlz_ad_agr + by metis + have \_R: "\ \ R" + using assms(7) ad_agr_list_link \_def(1) \_def(2) + by fastforce + define \' where "\' \ \n. if n \ set fv_sub_comp then the (map_of (zip fv_sub_comp fs) n) + else \ n" + then have "\n \ set fv_sub. \ n = \' n" + using assms(4) by auto + then have \'_S: "\' \ R" + using assms(7) \_R + by (fastforce simp: ad_agr_sets_def sp_equiv_def pairwise_def ad_equiv_pair.simps) + have length_as: "length as = length fv_sub" + using as_fs_def(1) assms(6) + by (auto simp: proj_vals_def fo_nmlz_length) + have length_fs: "length fs = length fv_sub_comp" + using as_fs_def(2) + by (auto simp: nall_tuples_rec_length) + have map_fv_sub: "map \' fv_sub = map \ fv_sub" + using assms(4) \_def(2) + by (auto simp: \'_def) + have fs_map_map_of: "fs = map (the \ (map_of (zip fv_sub_comp fs))) fv_sub_comp" + using map_map_of length_fs assms(2) + by metis + have fs_map: "fs = map \' fv_sub_comp" + using \'_def length_fs by (subst fs_map_map_of) simp + have vs_map_fv_all: "xs = fo_nmlz AD (map \' fv_all)" + unfolding as_fs_def(3) \_def(1) map_fv_sub[symmetric] fs_map fv_all_sort + using merge_map[OF assms(1,2,4)] + by metis + show "xs \ fo_nmlz AD ` proj_vals R fv_all" + using \'_S vs_map_fv_all + by (auto simp: proj_vals_def) + obtain \'' where \''_def: "xs = map \'' fv_all" + using exists_map[of fv_all xs] fo_nmlz_map vs_map_fv_all + by blast + have proj: "proj_tuple fv_sub (zip fv_all xs) = map \'' fv_sub" + using proj_tuple_map assms(1,3,5) + unfolding \''_def + by blast + have \''_\': "fo_nmlz AD (map \'' fv_sub) = as" + using \''_def vs_map_fv_all \_def(2) + by (metis \_def(2) ad_agr_list_subset assms(5) fo_nmlz_ad_agr fo_nmlz_eqI map_fv_sub sup_ge1) + show "fo_nmlz AD (proj_tuple fv_sub (zip fv_all xs)) \ ass" + unfolding proj \''_\' map_fv_sub + by (rule as_fs_def(1)) +qed + +lemma ext_tuple_complete: + assumes "sorted_distinct fv_sub" "sorted_distinct fv_sub_comp" "sorted_distinct fv_all" + "set fv_sub \ set fv_sub_comp = {}" "set fv_sub \ set fv_sub_comp = set fv_all" + "ass = fo_nmlz AD ` proj_vals R fv_sub" + "\\ \. ad_agr_sets (set fv_sub) (set fv_sub) AD \ \ \ \ \ R \ \ \ R" + "xs = fo_nmlz AD (map \ fv_all)" "\ \ R" + shows "xs \ fo_nmlz AD ` \(ext_tuple AD fv_sub fv_sub_comp ` ass)" +proof - + have fv_all_sort: "fv_all = sort (fv_sub @ fv_sub_comp)" + using assms(1,2,3,4,5) + by (simp add: sorted_distinct_set_unique) + note \_def = assms(9,8) + have vs_norm: "fo_nmlzd AD xs" + using \_def(2) fo_nmlz_sound + by auto + define fs where "fs = map \ fv_sub_comp" + define as where "as = map \ fv_sub" + define nos where "nos = fo_nmlz AD (as @ fs)" + define as' where "as' = take (length fv_sub) nos" + define fs' where "fs' = drop (length fv_sub) nos" + have length_as': "length as' = length fv_sub" + by (auto simp: as'_def nos_def as_def fo_nmlz_length) + have length_fs': "length fs' = length fv_sub_comp" + by (auto simp: fs'_def nos_def as_def fs_def fo_nmlz_length) + have len_fv_sub_nos: "length fv_sub \ length nos" + by (auto simp: nos_def fo_nmlz_length as_def) + have norm_as': "fo_nmlzd AD as'" + using fo_nmlzd_take[OF fo_nmlz_sound] + by (auto simp: as'_def nos_def) + have as'_norm_as: "as' = fo_nmlz AD as" + by (auto simp: as'_def nos_def as_def fo_nmlz_take) + have ad_agr_as': "ad_agr_list AD as as'" + using fo_nmlz_ad_agr + unfolding as'_norm_as . + have nos_as'_fs': "nos = as' @ fs'" + using length_as' length_fs' + by (auto simp: as'_def fs'_def) + obtain \ where \_def: "as' = map \ fv_sub" "fs' = map \ fv_sub_comp" + using exists_map[of "fv_sub @ fv_sub_comp" "as' @ fs'"] assms(1,2,4) length_as' length_fs' + by auto + have "length fv_sub + length fv_sub_comp \ length fv_all" + using assms(1,2,3,4,5) + by (metis distinct_append distinct_card eq_iff length_append set_append) + then have nos_sub: "set nos \ Inl ` AD \ Inr ` {.. nall_tuples_rec AD (card (Inr -` set as')) (length fv_sub_comp)" + unfolding len_fs'[symmetric] + by (rule nall_tuples_rec_fo_nmlz_rec_complete) + (rule fo_nmlz_rec_shift[OF norm_nos_idem, simplified, OF refl len_fv_sub_nos, + folded as'_def fs'_def]) + have "as' \ nall_tuples AD (length fv_sub)" + using length_as' + apply (rule nall_tuplesI) + using norm_as' . + then have as'_ass: "as' \ ass" + using as'_norm_as \_def(1) as_def + unfolding assms(6) + by (auto simp: proj_vals_def) + have vs_norm: "xs = fo_nmlz AD (map snd (merge (zip fv_sub as) (zip fv_sub_comp fs)))" + using assms(1,2,4) \_def(2) + by (auto simp: merge_map as_def fs_def fv_all_sort) + have set_sort': "set (sort (fv_sub @ fv_sub_comp)) = set (fv_sub @ fv_sub_comp)" + by auto + have "xs = fo_nmlz AD (map snd (merge (zip fv_sub as') (zip fv_sub_comp fs')))" + unfolding vs_norm as_def fs_def \_def + merge_map[OF assms(1,2,4)] + apply (rule fo_nmlz_eqI) + apply (rule ad_agr_list_subset[OF equalityD1, OF set_sort']) + using fo_nmlz_ad_agr[of AD "as @ fs", folded nos_def, unfolded nos_as'_fs'] + unfolding as_def fs_def \_def map_append[symmetric] . + then show ?thesis + using as'_ass fs'_all + by (auto simp: ext_tuple_def length_as') +qed + +definition "ext_tuple_set AD ns ns' X = (if ns' = [] then X else fo_nmlz AD ` \(ext_tuple AD ns ns' ` X))" + +lemma ext_tuple_set_eq: "Ball X (fo_nmlzd AD) \ ext_tuple_set AD ns ns' X = fo_nmlz AD ` \(ext_tuple AD ns ns' ` X)" + by (auto simp: ext_tuple_set_def ext_tuple_def fo_nmlzd_code) + +lemma ext_tuple_set_mono: "A \ B \ ext_tuple_set AD ns ns' A \ ext_tuple_set AD ns ns' B" + by (auto simp: ext_tuple_set_def) + +lemma ext_tuple_correct: + assumes "sorted_distinct fv_sub" "sorted_distinct fv_sub_comp" "sorted_distinct fv_all" + "set fv_sub \ set fv_sub_comp = {}" "set fv_sub \ set fv_sub_comp = set fv_all" + "ass = fo_nmlz AD ` proj_vals R fv_sub" + "\\ \. ad_agr_sets (set fv_sub) (set fv_sub) AD \ \ \ \ \ R \ \ \ R" + shows "ext_tuple_set AD fv_sub fv_sub_comp ass = fo_nmlz AD ` proj_vals R fv_all" +proof (rule set_eqI, rule iffI) + fix xs + assume xs_in: "xs \ ext_tuple_set AD fv_sub fv_sub_comp ass" + show "xs \ fo_nmlz AD ` proj_vals R fv_all" + using ext_tuple_sound(2)[OF assms] xs_in + by (auto simp: ext_tuple_set_def ext_tuple_def assms(6) fo_nmlz_idem[OF fo_nmlz_sound] image_iff + split: if_splits) +next + fix xs + assume "xs \ fo_nmlz AD ` proj_vals R fv_all" + then obtain \ where \_def: "xs = fo_nmlz AD (map \ fv_all)" "\ \ R" + by (auto simp: proj_vals_def) + show "xs \ ext_tuple_set AD fv_sub fv_sub_comp ass" + using ext_tuple_complete[OF assms \_def] + by (auto simp: ext_tuple_set_def ext_tuple_def assms(6) fo_nmlz_idem[OF fo_nmlz_sound] image_iff + split: if_splits) +qed + +lemma proj_tuple_sound: + assumes "sorted_distinct fv_sub" "sorted_distinct fv_sub_comp" "sorted_distinct fv_all" + "set fv_sub \ set fv_sub_comp = {}" "set fv_sub \ set fv_sub_comp = set fv_all" + "ass = fo_nmlz AD ` proj_vals R fv_sub" + "\\ \. ad_agr_sets (set fv_sub) (set fv_sub) AD \ \ \ \ \ R \ \ \ R" + "fo_nmlz AD xs = xs" "length xs = length fv_all" + "fo_nmlz AD (proj_tuple fv_sub (zip fv_all xs)) \ ass" + shows "xs \ fo_nmlz AD ` \(ext_tuple AD fv_sub fv_sub_comp ` ass)" +proof - + have fv_all_sort: "fv_all = sort (fv_sub @ fv_sub_comp)" + using assms(1,2,3,4,5) + by (simp add: sorted_distinct_set_unique) + obtain \ where \_def: "xs = map \ fv_all" + using exists_map[of fv_all xs] assms(3,9) + by auto + have xs_norm: "xs = fo_nmlz AD (map \ fv_all)" + using assms(8) + by (auto simp: \_def) + have proj: "proj_tuple fv_sub (zip fv_all xs) = map \ fv_sub" + unfolding \_def + apply (rule proj_tuple_map[OF assms(1,3)]) + using assms(5) + by blast + obtain \ where \_def: "fo_nmlz AD (map \ fv_sub) = fo_nmlz AD (map \ fv_sub)" "\ \ R" + using assms(10) + by (auto simp: assms(6) proj proj_vals_def) + have \_R: "\ \ R" + using assms(7) fo_nmlz_eqD[OF \_def(1)] \_def(2) + unfolding ad_agr_list_link[symmetric] + by auto + show ?thesis + by (rule ext_tuple_complete[OF assms(1,2,3,4,5,6,7) xs_norm \_R]) assumption +qed + +lemma proj_tuple_correct: + assumes "sorted_distinct fv_sub" "sorted_distinct fv_sub_comp" "sorted_distinct fv_all" + "set fv_sub \ set fv_sub_comp = {}" "set fv_sub \ set fv_sub_comp = set fv_all" + "ass = fo_nmlz AD ` proj_vals R fv_sub" + "\\ \. ad_agr_sets (set fv_sub) (set fv_sub) AD \ \ \ \ \ R \ \ \ R" + "fo_nmlz AD xs = xs" "length xs = length fv_all" + shows "xs \ fo_nmlz AD ` \(ext_tuple AD fv_sub fv_sub_comp ` ass) \ + fo_nmlz AD (proj_tuple fv_sub (zip fv_all xs)) \ ass" + using ext_tuple_sound(1)[OF assms(1,2,3,4,5,6,7)] proj_tuple_sound[OF assms] + by blast + +fun unify_vals_terms :: "('a + 'c) list \ ('a fo_term) list \ (nat \ ('a + 'c)) \ + (nat \ ('a + 'c)) option" where + "unify_vals_terms [] [] \ = Some \" +| "unify_vals_terms (v # vs) ((Const c') # ts) \ = + (if v = Inl c' then unify_vals_terms vs ts \ else None)" +| "unify_vals_terms (v # vs) ((Var n) # ts) \ = + (case \ n of Some x \ (if v = x then unify_vals_terms vs ts \ else None) + | None \ unify_vals_terms vs ts (\(n := Some v)))" +| "unify_vals_terms _ _ _ = None" + +lemma unify_vals_terms_extends: "unify_vals_terms vs ts \ = Some \' \ extends_subst \ \'" + unfolding extends_subst_def + by (induction vs ts \ arbitrary: \' rule: unify_vals_terms.induct) + (force split: if_splits option.splits)+ + +lemma unify_vals_terms_sound: "unify_vals_terms vs ts \ = Some \' \ (the \ \') \e ts = vs" + using unify_vals_terms_extends + by (induction vs ts \ arbitrary: \' rule: unify_vals_terms.induct) + (force simp: eval_eterms_def extends_subst_def fv_fo_terms_set_def + split: if_splits option.splits)+ + +lemma unify_vals_terms_complete: "\'' \e ts = vs \ (\n. \ n \ None \ \ n = Some (\'' n)) \ + \\'. unify_vals_terms vs ts \ = Some \'" + by (induction vs ts \ rule: unify_vals_terms.induct) + (force simp: eval_eterms_def extends_subst_def split: if_splits option.splits)+ + +definition eval_table :: "'a fo_term list \ ('a + 'c) table \ ('a + 'c) table" where + "eval_table ts X = (let fvs = fv_fo_terms_list ts in + \((\vs. case unify_vals_terms vs ts Map.empty of Some \ \ + {map (the \ \) fvs} | _ \ {}) ` X))" + +lemma eval_table: + fixes X :: "('a + 'c) table" + shows "eval_table ts X = proj_vals {\. \ \e ts \ X} (fv_fo_terms_list ts)" +proof (rule set_eqI, rule iffI) + fix vs + assume "vs \ eval_table ts X" + then obtain as \ where as_def: "as \ X" "unify_vals_terms as ts Map.empty = Some \" + "vs = map (the \ \) (fv_fo_terms_list ts)" + by (auto simp: eval_table_def split: option.splits) + have "(the \ \) \e ts \ X" + using unify_vals_terms_sound[OF as_def(2)] as_def(1) + by auto + with as_def(3) show "vs \ proj_vals {\. \ \e ts \ X} (fv_fo_terms_list ts)" + by (fastforce simp: proj_vals_def) +next + fix vs :: "('a + 'c) list" + assume "vs \ proj_vals {\. \ \e ts \ X} (fv_fo_terms_list ts)" + then obtain \ where \_def: "vs = map \ (fv_fo_terms_list ts)" "\ \e ts \ X" + by (auto simp: proj_vals_def) + obtain \' where \'_def: "unify_vals_terms (\ \e ts) ts Map.empty = Some \'" + using unify_vals_terms_complete[OF refl, of Map.empty \ ts] + by auto + have "(the \ \') \e ts = (\ \e ts)" + using unify_vals_terms_sound[OF \'_def(1)] + by auto + then have "vs = map (the \ \') (fv_fo_terms_list ts)" + using fv_fo_terms_set_list eval_eterms_fv_fo_terms_set + unfolding \_def(1) + by fastforce + then show "vs \ eval_table ts X" + using \_def(2) \'_def + by (force simp: eval_table_def) +qed + +fun ad_agr_close_rec :: "nat \ (nat \ 'a + nat) \ 'a set \ + ('a + nat) list \ ('a + nat) list set" where + "ad_agr_close_rec i m AD [] = {[]}" +| "ad_agr_close_rec i m AD (Inl x # xs) = (\xs. Inl x # xs) ` ad_agr_close_rec i m AD xs" +| "ad_agr_close_rec i m AD (Inr n # xs) = (case m n of None \ \((\x. (\xs. Inl x # xs) ` + ad_agr_close_rec i (m(n := Some (Inl x))) (AD - {x}) xs) ` AD) \ + (\xs. Inr i # xs) ` ad_agr_close_rec (Suc i) (m(n := Some (Inr i))) AD xs + | Some v \ (\xs. v # xs) ` ad_agr_close_rec i m AD xs)" + +lemma ad_agr_close_rec_length: "ys \ ad_agr_close_rec i m AD xs \ length xs = length ys" + by (induction i m AD xs arbitrary: ys rule: ad_agr_close_rec.induct) (auto split: option.splits) + +lemma ad_agr_close_rec_sound: "ys \ ad_agr_close_rec i m AD xs \ + fo_nmlz_rec j (id_map j) X xs = xs \ X \ AD = {} \ X \ Y = {} \ Y \ AD = {} \ + inj_on m (dom m) \ dom m = {.. ran m \ Inl ` Y \ Inr ` {.. i \ j \ + fo_nmlz_rec i (id_map i) (X \ Y \ AD) ys = ys \ + (\m'. inj_on m' (dom m') \ (\n v. m n = Some v \ m' (Inr n) = Some v) \ + (\(x, y) \ set (zip xs ys). case x of Inl x' \ + if x' \ X then x = y else m' x = Some y \ (case y of Inl z \ z \ X | Inr x \ True) + | Inr n \ m' x = Some y \ (case y of Inl z \ z \ X | Inr x \ True)))" +proof (induction i m AD xs arbitrary: Y j ys rule: ad_agr_close_rec.induct) + case (1 i m AD) + then show ?case + by (auto simp: ad_agr_list_def ad_equiv_list_def sp_equiv_list_def inj_on_def dom_def + split: sum.splits intro!: exI[of _ "case_sum Map.empty m"]) +next + case (2 i m AD x xs) + obtain zs where ys_def: "ys = Inl x # zs" "zs \ ad_agr_close_rec i m AD xs" + using 2(2) + by auto + have preds: "fo_nmlz_rec j (id_map j) X xs = xs" "x \ X" + using 2(3) + by (auto split: if_splits option.splits) + show ?case + using 2(1)[OF ys_def(2) preds(1) 2(4,5,6,7,8,9,10)] preds(2) + by (auto simp: ys_def(1)) +next + case (3 i m AD n xs) + show ?case + proof (cases "m n") + case None + obtain v zs where ys_def: "ys = v # zs" + using 3(4) + by (auto simp: None) + have n_ge_j: "j \ n" + using 3(9,10) None + by (metis domIff leI lessThan_iff) + show ?thesis + proof (cases v) + case (Inl x) + have zs_def: "zs \ ad_agr_close_rec i (m(n \ Inl x)) (AD - {x}) xs" "x \ AD" + using 3(4) + by (auto simp: None ys_def Inl) + have preds: "fo_nmlz_rec (Suc j) (id_map (Suc j)) X xs = xs" "X \ (AD - {x}) = {}" + "X \ (Y \ {x}) = {}" "(Y \ {x}) \ (AD - {x}) = {}" "dom (m(n \ Inl x)) = {.. Inl x)) \ Inl ` (Y \ {x}) \ Inr ` {.. Suc j" "n = j" + using 3(5,6,7,8,10,11,12) n_ge_j zs_def(2) + by (auto simp: fun_upd_id_map ran_def dest: id_mapD split: option.splits) + have inj: "inj_on (m(n \ Inl x)) (dom (m(n \ Inl x)))" + using 3(8,9,10,11,12) preds(8) zs_def(2) + by (fastforce simp: inj_on_def dom_def ran_def) + have sets_unfold: "X \ (Y \ {x}) \ (AD - {x}) = X \ Y \ AD" + using zs_def(2) + by auto + note IH = 3(1)[OF None zs_def(2,1) preds(1,2,3,4) inj preds(5,6,7), unfolded sets_unfold] + have norm_ys: "fo_nmlz_rec i (id_map i) (X \ Y \ AD) ys = ys" + using conjunct1[OF IH] zs_def(2) + by (auto simp: ys_def(1) Inl split: option.splits) + show ?thesis + using norm_ys conjunct2[OF IH] None zs_def(2) 3(6) + unfolding ys_def(1) + apply safe + subgoal for m' + apply (auto simp: Inl dom_def intro!: exI[of _ m'] split: if_splits) + apply (metis option.distinct(1)) + apply (fastforce split: prod.splits sum.splits) + done + done + next + case (Inr k) + have zs_def: "zs \ ad_agr_close_rec (Suc i) (m(n \ Inr i)) AD xs" "i = k" + using 3(4) + by (auto simp: None ys_def Inr) + have preds: "fo_nmlz_rec (Suc n) (id_map (Suc n)) X xs = xs" + "dom (m(n \ Inr i)) = {.. Inr i)) \ Inl ` Y \ Inr ` {.. Suc n" + using 3(5,10,11,12) n_ge_j + by (auto simp: fun_upd_id_map ran_def dest: id_mapD split: option.splits) + have inj: "inj_on (m(n \ Inr i)) (dom (m(n \ Inr i)))" + using 3(9,11) + by (auto simp: inj_on_def dom_def ran_def) + note IH = 3(2)[OF None zs_def(1) preds(1) 3(6,7,8) inj preds(2,3,4)] + have norm_ys: "fo_nmlz_rec i (id_map i) (X \ Y \ AD) ys = ys" + using conjunct1[OF IH] zs_def(2) + by (auto simp: ys_def Inr fun_upd_id_map dest: id_mapD split: option.splits) + show ?thesis + using norm_ys conjunct2[OF IH] None + unfolding ys_def(1) zs_def(2) + apply safe + subgoal for m' + apply (auto simp: Inr dom_def intro!: exI[of _ m'] split: if_splits) + apply (metis option.distinct(1)) + apply (fastforce split: prod.splits sum.splits) + done + done + qed + next + case (Some v) + obtain zs where ys_def: "ys = v # zs" "zs \ ad_agr_close_rec i m AD xs" + using 3(4) + by (auto simp: Some) + have preds: "fo_nmlz_rec j (id_map j) X xs = xs" "n < j" + using 3(5,8,10) Some + by (auto simp: dom_def split: option.splits) + note IH = 3(3)[OF Some ys_def(2) preds(1) 3(6,7,8,9,10,11,12)] + have norm_ys: "fo_nmlz_rec i (id_map i) (X \ Y \ AD) ys = ys" + using conjunct1[OF IH] 3(11) Some + by (auto simp: ys_def(1) ran_def id_map_def) + have "case v of Inl z \ z \ X | Inr x \ True" + using 3(7,11) Some + by (auto simp: ran_def split: sum.splits) + then show ?thesis + using norm_ys conjunct2[OF IH] Some + unfolding ys_def(1) + apply safe + subgoal for m' + by (auto intro!: exI[of _ m'] split: sum.splits) + done + qed +qed + +lemma ad_agr_close_rec_complete: + fixes xs :: "('a + nat) list" + shows "fo_nmlz_rec j (id_map j) X xs = xs \ + X \ AD = {} \ X \ Y = {} \ Y \ AD = {} \ + inj_on m (dom m) \ dom m = {.. ran m = Inl ` Y \ Inr ` {.. i \ j \ + (\n b. (Inr n, b) \ set (zip xs ys) \ case m n of Some v \ v = b | None \ b \ ran m) \ + fo_nmlz_rec i (id_map i) (X \ Y \ AD) ys = ys \ ad_agr_list X xs ys \ + ys \ ad_agr_close_rec i m AD xs" +proof (induction j "id_map j :: 'a + nat \ nat option" X xs arbitrary: m i ys AD Y + rule: fo_nmlz_rec.induct) + case (2 j X x xs) + have x_X: "x \ X" "fo_nmlz_rec j (id_map j) X xs = xs" + using 2(4) + by (auto split: if_splits option.splits) + obtain z zs where ys_def: "ys = Inl z # zs" "z = x" + using 2(14) x_X(1) + by (cases ys) (auto simp: ad_agr_list_def ad_equiv_list_def ad_equiv_pair.simps) + have norm_zs: "fo_nmlz_rec i (id_map i) (X \ Y \ AD) zs = zs" + using 2(13) ys_def(2) x_X(1) + by (auto simp: ys_def(1)) + have ad_agr: "ad_agr_list X xs zs" + using 2(14) + by (auto simp: ys_def ad_agr_list_def ad_equiv_list_def sp_equiv_list_def pairwise_def) + show ?case + using 2(1)[OF x_X 2(5,6,7,8,9,10,11) _ norm_zs ad_agr] 2(12) + by (auto simp: ys_def) +next + case (3 j X n xs) + obtain z zs where ys_def: "ys = z # zs" + using 3(13) + apply (cases ys) + apply (auto simp: ad_agr_list_def) + done + show ?case + proof (cases "j \ n") + case True + then have n_j: "n = j" + using 3(3) + by (auto split: option.splits dest: id_mapD) + have id_map: "id_map j (Inr n) = None" "id_map j(Inr n \ j) = id_map (Suc j)" + unfolding n_j fun_upd_id_map + by (auto simp: id_map_def) + have norm_xs: "fo_nmlz_rec (Suc j) (id_map (Suc j)) X xs = xs" + using 3(3) + by (auto simp: ys_def fun_upd_id_map id_map(1) split: option.splits) + have None: "m n = None" + using 3(8) + by (auto simp: dom_def n_j) + have z_out: "z \ Inl ` Y \ Inr ` {.. AD" + using 3(12,13) z_out + by (auto simp: ys_def Inl ad_agr_list_def ad_equiv_list_def ad_equiv_pair.simps + split: if_splits option.splits) + have norm_zs: "fo_nmlz_rec i (id_map i) (X \ Y \ AD) zs = zs" + using 3(12) a_in + by (auto simp: ys_def Inl) + have preds: "X \ (AD - {a}) = {}" "X \ (Y \ {a}) = {}" "(Y \ {a}) \ (AD - {a}) = {}" + using 3(4,5,6) a_in + by auto + have inj: "inj_on (m(n := Some (Inl a))) (dom (m(n := Some (Inl a))))" + using 3(6,7,9) None a_in + by (auto simp: inj_on_def dom_def ran_def) blast+ + have preds': "dom (m(n \ Inl a)) = {.. Inl a)) = Inl ` (Y \ {a}) \ Inr ` {.. Suc j" + using 3(6,8,9,10) None less_Suc_eq a_in + apply (auto simp: n_j dom_def ran_def) + apply (smt Un_iff image_eqI mem_Collect_eq option.simps(3)) + apply (smt 3(8) domIff image_subset_iff lessThan_iff mem_Collect_eq sup_ge2) + done + have a_unfold: "X \ (Y \ {a}) \ (AD - {a}) = X \ Y \ AD" "Y \ {a} \ (AD - {a}) = Y \ AD" + using a_in + by auto + have ad_agr: "ad_agr_list X xs zs" + using 3(13) + by (auto simp: ys_def Inl ad_agr_list_def ad_equiv_list_def sp_equiv_list_def pairwise_def) + have "zs \ ad_agr_close_rec i (m(n \ Inl a)) (AD - {a}) xs" + apply (rule 3(1)[OF id_map norm_xs preds inj preds' _ _ ad_agr]) + using 3(11,13) norm_zs + unfolding 3(9) preds'(2) a_unfold + apply (auto simp: None Inl ys_def ad_agr_list_def sp_equiv_list_def pairwise_def + split: option.splits) + apply (metis Un_iff image_eqI option.simps(4)) + apply (metis image_subset_iff lessThan_iff option.simps(4) sup_ge2) + apply fastforce + done + then show ?thesis + using a_in + by (auto simp: ys_def Inl None) + next + case (Inr b) + have i_b: "i = b" + using 3(12) z_out + by (auto simp: ys_def Inr split: option.splits dest: id_mapD) + have norm_zs: "fo_nmlz_rec (Suc i) (id_map (Suc i)) (X \ Y \ AD) zs = zs" + using 3(12) + by (auto simp: ys_def Inr i_b fun_upd_id_map split: option.splits dest: id_mapD) + have ad_agr: "ad_agr_list X xs zs" + using 3(13) + by (auto simp: ys_def ad_agr_list_def ad_equiv_list_def sp_equiv_list_def pairwise_def) + define m' where "m' \ m(n := Some (Inr i))" + have preds: "inj_on m' (dom m')" "dom m' = {.. Suc j" + using 3(7,8,9,10) + by (auto simp: m'_def n_j inj_on_def dom_def ran_def image_iff) + (metis 3(8) domI lessThan_iff less_SucI) + have ran: "ran m' = Inl ` Y \ Inr ` {.. ad_agr_close_rec (Suc i) m' AD xs" + apply (rule 3(1)[OF id_map norm_xs 3(4,5,6) preds(1,2) ran preds(3) _ norm_zs ad_agr]) + using 3(11,13) + unfolding 3(9) ys_def Inr i_b m'_def + unfolding ran[unfolded m'_def i_b] + apply (auto simp: ad_agr_list_def sp_equiv_list_def pairwise_def split: option.splits) + apply (metis Un_upper1 image_subset_iff option.simps(4)) + apply (metis UnI1 image_eqI insert_iff lessThan_Suc lessThan_iff option.simps(4) + sp_equiv_pair.simps sum.inject(2) sup_commute) + apply fastforce + done + then show ?thesis + by (auto simp: ys_def Inr None m'_def i_b) + qed + next + case False + have id_map: "id_map j (Inr n) = Some n" + using False + by (auto simp: id_map_def) + have norm_xs: "fo_nmlz_rec j (id_map j) X xs = xs" + using 3(3) + by (auto simp: id_map) + have Some: "m n = Some z" + using False 3(11)[unfolded ys_def] + by (metis (mono_tags) 3(8) domD insert_iff leI lessThan_iff list.simps(15) + option.simps(5) zip_Cons_Cons) + have z_in: "z \ Inl ` Y \ Inr ` {.. Y \ AD" + using 3(12,13) + by (auto simp: ys_def Inl ad_agr_list_def ad_equiv_list_def ad_equiv_pair.simps + split: if_splits option.splits) + have norm_zs: "fo_nmlz_rec i (id_map i) (X \ Y \ AD) zs = zs" + using 3(12) a_in + by (auto simp: ys_def Inl) + show ?thesis + using 3(2)[OF id_map norm_xs 3(4,5,6,7,8,9,10) _ norm_zs ad_agr] 3(11) a_in + by (auto simp: ys_def Inl Some split: option.splits) + next + case (Inr b) + have b_lt: "b < i" + using z_in + by (auto simp: Inr) + have norm_zs: "fo_nmlz_rec i (id_map i) (X \ Y \ AD) zs = zs" + using 3(12) b_lt + by (auto simp: ys_def Inr split: option.splits) + show ?thesis + using 3(2)[OF id_map norm_xs 3(4,5,6,7,8,9,10) _ norm_zs ad_agr] 3(11) + by (auto simp: ys_def Inr Some) + qed + qed +qed (auto simp: ad_agr_list_def) + +definition ad_agr_close :: "'a set \ ('a + nat) list \ ('a + nat) list set" where + "ad_agr_close AD xs = ad_agr_close_rec 0 Map.empty AD xs" + +lemma ad_agr_close_sound: + assumes "ys \ ad_agr_close Y xs" "fo_nmlzd X xs" "X \ Y = {}" + shows "fo_nmlzd (X \ Y) ys \ ad_agr_list X xs ys" + using ad_agr_close_rec_sound[OF assms(1)[unfolded ad_agr_close_def] + fo_nmlz_idem[OF assms(2), unfolded fo_nmlz_def, folded id_map_empty] assms(3) + Int_empty_right Int_empty_left] + ad_agr_map[OF ad_agr_close_rec_length[OF assms(1)[unfolded ad_agr_close_def]], of _ X] + fo_nmlzd_code[unfolded fo_nmlz_def, folded id_map_empty, of "X \ Y" ys] + by (auto simp: fo_nmlz_def) + +lemma ad_agr_close_complete: + assumes "X \ Y = {}" "fo_nmlzd X xs" "fo_nmlzd (X \ Y) ys" "ad_agr_list X xs ys" + shows "ys \ ad_agr_close Y xs" + using ad_agr_close_rec_complete[OF fo_nmlz_idem[OF assms(2), + unfolded fo_nmlz_def, folded id_map_empty] assms(1) Int_empty_right Int_empty_left _ _ _ + order.refl _ _ assms(4), of Map.empty] + fo_nmlzd_code[unfolded fo_nmlz_def, folded id_map_empty, of "X \ Y" ys] + assms(3) + unfolding ad_agr_close_def + by (auto simp: fo_nmlz_def) + +lemma ad_agr_close_empty: "fo_nmlzd X xs \ ad_agr_close {} xs = {xs}" + using ad_agr_close_complete[where ?X=X and ?Y="{}" and ?xs=xs and ?ys=xs] + ad_agr_close_sound[where ?X=X and ?Y="{}" and ?xs=xs] ad_agr_list_refl ad_agr_list_fo_nmlzd + by fastforce + +lemma ad_agr_close_set_correct: + assumes "AD' \ AD" "sorted_distinct ns" + "\\ \. ad_agr_sets (set ns) (set ns) AD' \ \ \ \ \ R \ \ \ R" + shows "\(ad_agr_close (AD - AD') ` fo_nmlz AD' ` proj_vals R ns) = fo_nmlz AD ` proj_vals R ns" +proof (rule set_eqI, rule iffI) + fix vs + assume "vs \ \(ad_agr_close (AD - AD') ` fo_nmlz AD' ` proj_vals R ns)" + then obtain \ where \_def: "vs \ ad_agr_close (AD - AD') (fo_nmlz AD' (map \ ns))" "\ \ R" + by (auto simp: proj_vals_def) + have vs: "fo_nmlzd AD vs" "ad_agr_list AD' (fo_nmlz AD' (map \ ns)) vs" + using ad_agr_close_sound[OF \_def(1) fo_nmlz_sound] assms(1) Diff_partition + by fastforce+ + obtain \ where \_def: "vs = map \ ns" + using exists_map[of ns vs] assms(2) vs(2) + by (auto simp: ad_agr_list_def fo_nmlz_length) + show "vs \ fo_nmlz AD ` proj_vals R ns" + apply (subst fo_nmlz_idem[OF vs(1), symmetric]) + using iffD1[OF assms(3) \_def(2), OF iffD2[OF ad_agr_list_link ad_agr_list_trans[OF + fo_nmlz_ad_agr[of AD' "map \ ns"] vs(2), unfolded \_def]]] + unfolding \_def + by (auto simp: proj_vals_def) +next + fix vs + assume "vs \ fo_nmlz AD ` proj_vals R ns" + then obtain \ where \_def: "vs = fo_nmlz AD (map \ ns)" "\ \ R" + by (auto simp: proj_vals_def) + define xs where "xs = fo_nmlz AD' vs" + have preds: "AD' \ (AD - AD') = {}" "fo_nmlzd AD' xs" "fo_nmlzd (AD' \ (AD - AD')) vs" + using assms(1) fo_nmlz_sound Diff_partition + by (fastforce simp: \_def(1) xs_def)+ + obtain \ where \_def: "vs = map \ ns" + using exists_map[of "ns" vs] assms(2) \_def(1) + by (auto simp: fo_nmlz_length) + have "vs \ ad_agr_close (AD - AD') xs" + using ad_agr_close_complete[OF preds] ad_agr_list_comm[OF fo_nmlz_ad_agr] + by (auto simp: xs_def) + then show "vs \ \(ad_agr_close (AD - AD') ` fo_nmlz AD' ` proj_vals R ns)" + unfolding xs_def \_def + using iffD1[OF assms(3) \_def(2), OF ad_agr_sets_mono[OF assms(1) iffD2[OF ad_agr_list_link + fo_nmlz_ad_agr[of AD "map \ ns", folded \_def(1), unfolded \_def]]]] + by (auto simp: proj_vals_def) +qed + +lemma ad_agr_close_correct: + assumes "AD' \ AD" + "\\ \. ad_agr_sets (set (fv_fo_fmla_list \)) (set (fv_fo_fmla_list \)) AD' \ \ \ + \ \ R \ \ \ R" + shows "\(ad_agr_close (AD - AD') ` fo_nmlz AD' ` proj_fmla \ R) = fo_nmlz AD ` proj_fmla \ R" + using ad_agr_close_set_correct[OF _ sorted_distinct_fv_list, OF assms] + by (auto simp: proj_fmla_def) + +definition "ad_agr_close_set AD X = (if Set.is_empty AD then X else \(ad_agr_close AD ` X))" + +lemma ad_agr_close_set_eq: "Ball X (fo_nmlzd AD') \ ad_agr_close_set AD X = \(ad_agr_close AD ` X)" + by (force simp: ad_agr_close_set_def Set.is_empty_def ad_agr_close_empty) + +lemma Ball_fo_nmlzd: "Ball (fo_nmlz AD ` X) (fo_nmlzd AD)" + by (auto simp: fo_nmlz_sound) + +lemmas ad_agr_close_set_nmlz_eq = ad_agr_close_set_eq[OF Ball_fo_nmlzd] + +definition eval_pred :: "('a fo_term) list \ 'a table \ ('a, 'c) fo_t" where + "eval_pred ts X = (let AD = \(set (map set_fo_term ts)) \ \(set ` X) in + (AD, length (fv_fo_terms_list ts), eval_table ts (map Inl ` X)))" + +definition eval_bool :: "bool \ ('a, 'c) fo_t" where + "eval_bool b = (if b then ({}, 0, {[]}) else ({}, 0, {}))" + +definition eval_eq :: "'a fo_term \ 'a fo_term \ ('a, nat) fo_t" where + "eval_eq t t' = (case t of Var n \ + (case t' of Var n' \ + if n = n' then ({}, 1, {[Inr 0]}) + else ({}, 2, {[Inr 0, Inr 0]}) + | Const c' \ ({c'}, 1, {[Inl c']})) + | Const c \ + (case t' of Var n' \ ({c}, 1, {[Inl c]}) + | Const c' \ if c = c' then ({c}, 0, {[]}) else ({c, c'}, 0, {})))" + +fun eval_neg :: "nat list \ ('a, nat) fo_t \ ('a, nat) fo_t" where + "eval_neg ns (AD, _, X) = (AD, length ns, nall_tuples AD (length ns) - X)" + +definition "eval_conj_tuple AD ns\ ns\ xs ys = + (let cxs = filter (\(n, x). n \ set ns\ \ isl x) (zip ns\ xs); + nxs = map fst (filter (\(n, x). n \ set ns\ \ \isl x) (zip ns\ xs)); + cys = filter (\(n, y). n \ set ns\ \ isl y) (zip ns\ ys); + nys = map fst (filter (\(n, y). n \ set ns\ \ \isl y) (zip ns\ ys)) in + fo_nmlz AD ` ext_tuple {} (sort (ns\ @ map fst cys)) nys (map snd (merge (zip ns\ xs) cys)) \ + fo_nmlz AD ` ext_tuple {} (sort (ns\ @ map fst cxs)) nxs (map snd (merge (zip ns\ ys) cxs)))" + +definition "eval_conj_set AD ns\ X\ ns\ X\ = \((\xs. \(eval_conj_tuple AD ns\ ns\ xs ` X\)) ` X\)" + +definition "idx_join AD ns ns\ X\ ns\ X\ = + (let idx\' = cluster (Some \ (\xs. fo_nmlz AD (proj_tuple ns (zip ns\ xs)))) X\; + idx\' = cluster (Some \ (\ys. fo_nmlz AD (proj_tuple ns (zip ns\ ys)))) X\ in + set_of_idx (mapping_join (\X\'' X\''. eval_conj_set AD ns\ X\'' ns\ X\'') idx\' idx\'))" + +fun eval_conj :: "nat list \ ('a, nat) fo_t \ nat list \ ('a, nat) fo_t \ + ('a, nat) fo_t" where + "eval_conj ns\ (AD\, _, X\) ns\ (AD\, _, X\) = (let AD = AD\ \ AD\; AD\\ = AD - AD\; AD\\ = AD - AD\; ns = filter (\n. n \ set ns\) ns\ in + (AD, card (set ns\ \ set ns\), idx_join AD ns ns\ (ad_agr_close_set AD\\ X\) ns\ (ad_agr_close_set AD\\ X\)))" + +fun eval_ajoin :: "nat list \ ('a, nat) fo_t \ nat list \ ('a, nat) fo_t \ + ('a, nat) fo_t" where + "eval_ajoin ns\ (AD\, _, X\) ns\ (AD\, _, X\) = (let AD = AD\ \ AD\; AD\\ = AD - AD\; AD\\ = AD - AD\; + ns = filter (\n. n \ set ns\) ns\; ns\' = filter (\n. n \ set ns\) ns\; + idx\ = cluster (Some \ (\xs. fo_nmlz AD\ (proj_tuple ns (zip ns\ xs)))) (ad_agr_close_set AD\\ X\); + idx\ = cluster (Some \ (\ys. fo_nmlz AD\ (proj_tuple ns (zip ns\ ys)))) X\ in + (AD, card (set ns\ \ set ns\), set_of_idx (Mapping.map_values (\xs X. case Mapping.lookup idx\ xs of Some Y \ + idx_join AD ns ns\ X ns\ (ad_agr_close_set AD\\ (ext_tuple_set AD\ ns ns\' {xs} - Y)) | _ \ ext_tuple_set AD ns\ ns\' X) idx\)))" + +fun eval_disj :: "nat list \ ('a, nat) fo_t \ nat list \ ('a, nat) fo_t \ + ('a, nat) fo_t" where + "eval_disj ns\ (AD\, _, X\) ns\ (AD\, _, X\) = (let AD = AD\ \ AD\; + ns\' = filter (\n. n \ set ns\) ns\; + ns\' = filter (\n. n \ set ns\) ns\; + AD\\ = AD - AD\; AD\\ = AD - AD\ in + (AD, card (set ns\ \ set ns\), + ext_tuple_set AD ns\ ns\' (ad_agr_close_set AD\\ X\) \ + ext_tuple_set AD ns\ ns\' (ad_agr_close_set AD\\ X\)))" + +fun eval_exists :: "nat \ nat list \ ('a, nat) fo_t \ ('a, nat) fo_t" where + "eval_exists i ns (AD, _, X) = (case pos i ns of Some j \ + (AD, length ns - 1, fo_nmlz AD ` rem_nth j ` X) + | None \ (AD, length ns, X))" + +fun eval_forall :: "nat \ nat list \ ('a, nat) fo_t \ ('a, nat) fo_t" where + "eval_forall i ns (AD, _, X) = (case pos i ns of Some j \ + let n = card AD in + (AD, length ns - 1, Mapping.keys (Mapping.filter (\t Z. n + card (Inr -` set t) + 1 \ card Z) + (cluster (Some \ (\ts. fo_nmlz AD (rem_nth j ts))) X))) + | None \ (AD, length ns, X))" + +lemma combine_map2: assumes "length ys = length xs" "length ys' = length xs'" + "distinct xs" "distinct xs'" "set xs \ set xs' = {}" + shows "\f. ys = map f xs \ ys' = map f xs'" +proof - + obtain f g where fg_def: "ys = map f xs" "ys' = map g xs'" + using assms exists_map + by metis + show ?thesis + using assms + by (auto simp: fg_def intro!: exI[of _ "\x. if x \ set xs then f x else g x"]) +qed + +lemma combine_map3: assumes "length ys = length xs" "length ys' = length xs'" "length ys'' = length xs''" + "distinct xs" "distinct xs'" "distinct xs''" "set xs \ set xs' = {}" "set xs \ set xs'' = {}" "set xs' \ set xs'' = {}" + shows "\f. ys = map f xs \ ys' = map f xs' \ ys'' = map f xs''" +proof - + obtain f g h where fgh_def: "ys = map f xs" "ys' = map g xs'" "ys'' = map h xs''" + using assms exists_map + by metis + show ?thesis + using assms + by (auto simp: fgh_def intro!: exI[of _ "\x. if x \ set xs then f x else if x \ set xs' then g x else h x"]) +qed + +lemma distinct_set_zip: "length nsx = length xs \ distinct nsx \ + (a, b) \ set (zip nsx xs) \ (a, ba) \ set (zip nsx xs) \ b = ba" + by (induction nsx xs rule: list_induct2) (auto dest: set_zip_leftD) + +lemma fo_nmlz_idem_isl: + assumes "\x. x \ set xs \ (case x of Inl z \ z \ X | _ \ False)" + shows "fo_nmlz X xs = xs" +proof - + have F1: "Inl x \ set xs \ x \ X" for x + using assms[of "Inl x"] + by auto + have F2: "List.map_filter (case_sum Map.empty Some) xs = []" + using assms + by (induction xs) (fastforce simp: List.map_filter_def split: sum.splits)+ + show ?thesis + by (rule fo_nmlz_idem) (auto simp: fo_nmlzd_def nats_def F2 intro: F1) +qed + +lemma set_zip_mapI: "x \ set xs \ (f x, g x) \ set (zip (map f xs) (map g xs))" + by (induction xs) auto + +lemma ad_agr_list_fo_nmlzd_isl: + assumes "ad_agr_list X (map f xs) (map g xs)" "fo_nmlzd X (map f xs)" "x \ set xs" "isl (f x)" + shows "f x = g x" +proof - + have AD: "ad_equiv_pair X (f x, g x)" + using assms(1) set_zip_mapI[OF assms(3)] + by (auto simp: ad_agr_list_def ad_equiv_list_def split: sum.splits) + then show ?thesis + using assms(2-) + by (auto simp: fo_nmlzd_def) (metis AD ad_equiv_pair.simps ad_equiv_pair_mono image_eqI sum.collapse(1) vimageI) +qed + +lemma eval_conj_tuple_close_empty2: + assumes "fo_nmlzd X xs" "fo_nmlzd Y ys" + "length nsx = length xs" "length nsy = length ys" + "sorted_distinct nsx" "sorted_distinct nsy" + "sorted_distinct ns" "set ns \ set nsx \ set nsy" + "fo_nmlz (X \ Y) (proj_tuple ns (zip nsx xs)) \ fo_nmlz (X \ Y) (proj_tuple ns (zip nsy ys)) \ + (proj_tuple ns (zip nsx xs) \ proj_tuple ns (zip nsy ys) \ + (\x \ set (proj_tuple ns (zip nsx xs)). isl x) \ (\y \ set (proj_tuple ns (zip nsy ys)). isl y))" + "xs' \ ad_agr_close ((X \ Y) - X) xs" "ys' \ ad_agr_close ((X \ Y) - Y) ys" + shows "eval_conj_tuple (X \ Y) nsx nsy xs' ys' = {}" +proof - + define cxs where "cxs = filter (\(n, x). n \ set nsy \ isl x) (zip nsx xs')" + define nxs where "nxs = map fst (filter (\(n, x). n \ set nsy \ \isl x) (zip nsx xs'))" + define cys where "cys = filter (\(n, y). n \ set nsx \ isl y) (zip nsy ys')" + define nys where "nys = map fst (filter (\(n, y). n \ set nsx \ \isl y) (zip nsy ys'))" + define both where "both = sorted_list_of_set (set nsx \ set nsy)" + have close: "fo_nmlzd (X \ Y) xs'" "ad_agr_list X xs xs'" "fo_nmlzd (X \ Y) ys'" "ad_agr_list Y ys ys'" + using ad_agr_close_sound[OF assms(10) assms(1)] ad_agr_close_sound[OF assms(11) assms(2)] + by (auto simp add: sup_left_commute) + have close': "length xs' = length xs" "length ys' = length ys" + using close + by (auto simp: ad_agr_list_length) + have len_sort: "length (sort (nsx @ map fst cys)) = length (map snd (merge (zip nsx xs') cys))" + "length (sort (nsy @ map fst cxs)) = length (map snd (merge (zip nsy ys') cxs))" + by (auto simp: merge_length assms(3,4) close') + { + fix zs + assume "zs \ fo_nmlz (X \ Y) ` (\fs. map snd (merge (zip (sort (nsx @ map fst cys)) (map snd (merge (zip nsx xs') cys))) (zip nys fs))) ` + nall_tuples_rec {} (card (Inr -` set (map snd (merge (zip nsx xs') cys)))) (length nys)" + "zs \ fo_nmlz (X \ Y) ` (\fs. map snd (merge (zip (sort (nsy @ map fst cxs)) (map snd (merge (zip nsy ys') cxs))) (zip nxs fs))) ` + nall_tuples_rec {} (card (Inr -` set (map snd (merge (zip nsy ys') cxs)))) (length nxs)" + then obtain zxs zys where nall: "zxs \ nall_tuples_rec {} (card (Inr -` set (map snd (merge (zip nsx xs') cys)))) (length nys)" + "zs = fo_nmlz (X \ Y) (map snd (merge (zip (sort (nsx @ map fst cys)) (map snd (merge (zip nsx xs') cys))) (zip nys zxs)))" + "zys \ nall_tuples_rec {} (card (Inr -` set (map snd (merge (zip nsy ys') cxs)))) (length nxs)" + "zs = fo_nmlz (X \ Y) (map snd (merge (zip (sort (nsy @ map fst cxs)) (map snd (merge (zip nsy ys') cxs))) (zip nxs zys)))" + by auto + have len_zs: "length zxs = length nys" "length zys = length nxs" + using nall(1,3) + by (auto dest: nall_tuples_rec_length) + have aux: "sorted_distinct (map fst cxs)" "sorted_distinct nxs" "sorted_distinct nsy" + "sorted_distinct (map fst cys)" "sorted_distinct nys" "sorted_distinct nsx" + "set (map fst cxs) \ set nsy = {}" "set (map fst cxs) \ set nxs = {}" "set nsy \ set nxs = {}" + "set (map fst cys) \ set nsx = {}" "set (map fst cys) \ set nys = {}" "set nsx \ set nys = {}" + using assms(3,4,5,6) close' distinct_set_zip + by (auto simp: cxs_def nxs_def cys_def nys_def sorted_filter distinct_map_fst_filter) + (smt (z3) distinct_set_zip)+ + obtain xf where xf_def: "map snd cxs = map xf (map fst cxs)" "ys' = map xf nsy" "zys = map xf nxs" + using combine_map3[where ?ys="map snd cxs" and ?xs="map fst cxs" and ?ys'=ys' and ?xs'=nsy and ?ys''=zys and ?xs''=nxs] assms(4) aux close' + by (auto simp: len_zs) + obtain ysf where ysf_def: "ys = map ysf nsy" + using assms(4,6) exists_map + by auto + obtain xg where xg_def: "map snd cys = map xg (map fst cys)" "xs' = map xg nsx" "zxs = map xg nys" + using combine_map3[where ?ys="map snd cys" and ?xs="map fst cys" and ?ys'=xs' and ?xs'=nsx and ?ys''=zxs and ?xs''=nys] assms(3) aux close' + by (auto simp: len_zs) + obtain xsf where xsf_def: "xs = map xsf nsx" + using assms(3,5) exists_map + by auto + have set_cxs_nxs: "set (map fst cxs @ nxs) = set nsx - set nsy" + using assms(3) + unfolding cxs_def nxs_def close'[symmetric] + by (induction nsx xs' rule: list_induct2) auto + have set_cys_nys: "set (map fst cys @ nys) = set nsy - set nsx" + using assms(4) + unfolding cys_def nys_def close'[symmetric] + by (induction nsy ys' rule: list_induct2) auto + have sort_sort_both_xs: "sort (sort (nsy @ map fst cxs) @ nxs) = both" + apply (rule sorted_distinct_set_unique) + using assms(3,5,6) close' set_cxs_nxs + by (auto simp: both_def nxs_def cxs_def intro: distinct_map_fst_filter) + (metis (no_types, lifting) distinct_set_zip) + have sort_sort_both_ys: "sort (sort (nsx @ map fst cys) @ nys) = both" + apply (rule sorted_distinct_set_unique) + using assms(4,5,6) close' set_cys_nys + by (auto simp: both_def nys_def cys_def intro: distinct_map_fst_filter) + (metis (no_types, lifting) distinct_set_zip) + have "map snd (merge (zip nsy ys') cxs) = map xf (sort (nsy @ map fst cxs))" + using merge_map[where ?\=xf and ?ns=nsy and ?ms="map fst cxs"] assms(6) aux + unfolding xf_def(1)[symmetric] xf_def(2) + by (auto simp: zip_map_fst_snd) + then have zs_xf: "zs = fo_nmlz (X \ Y) (map xf both)" + using merge_map[where \=xf and ?ns="sort (nsy @ map fst cxs)" and ?ms=nxs] aux + by (fastforce simp: nall(4) xf_def(3) sort_sort_both_xs) + have "map snd (merge (zip nsx xs') cys) = map xg (sort (nsx @ map fst cys))" + using merge_map[where ?\=xg and ?ns=nsx and ?ms="map fst cys"] assms(5) aux + unfolding xg_def(1)[symmetric] xg_def(2) + by (fastforce simp: zip_map_fst_snd) + then have zs_xg: "zs = fo_nmlz (X \ Y) (map xg both)" + using merge_map[where \=xg and ?ns="sort (nsx @ map fst cys)" and ?ms=nys] aux + by (fastforce simp: nall(2) xg_def(3) sort_sort_both_ys) + have proj_map: "proj_tuple ns (zip nsx xs') = map xg ns" "proj_tuple ns (zip nsy ys') = map xf ns" + "proj_tuple ns (zip nsx xs) = map xsf ns" "proj_tuple ns (zip nsy ys) = map ysf ns" + unfolding xf_def(2) xg_def(2) xsf_def ysf_def + using assms(5,6,7,8) proj_tuple_map + by auto + have "ad_agr_list (X \ Y) (map xg both) (map xf both)" + using zs_xg zs_xf + by (fastforce dest: fo_nmlz_eqD) + then have "ad_agr_list (X \ Y) (proj_tuple ns (zip nsx xs')) (proj_tuple ns (zip nsy ys'))" + using assms(8) + unfolding proj_map + by (fastforce simp: both_def intro: ad_agr_list_subset[rotated]) + then have fo_nmlz_Un: "fo_nmlz (X \ Y) (proj_tuple ns (zip nsx xs')) = fo_nmlz (X \ Y) (proj_tuple ns (zip nsy ys'))" + by (auto intro: fo_nmlz_eqI) + have "False" + using assms(9) + proof (rule disjE) + assume c: "fo_nmlz (X \ Y) (proj_tuple ns (zip nsx xs)) \ fo_nmlz (X \ Y) (proj_tuple ns (zip nsy ys))" + have fo_nmlz_Int: "fo_nmlz (X \ Y) (proj_tuple ns (zip nsx xs')) = fo_nmlz (X \ Y) (proj_tuple ns (zip nsy ys'))" + using fo_nmlz_Un + by (rule fo_nmlz_eqI[OF ad_agr_list_mono, rotated, OF fo_nmlz_eqD]) auto + have proj_xs: "fo_nmlz (X \ Y) (proj_tuple ns (zip nsx xs)) = fo_nmlz (X \ Y) (proj_tuple ns (zip nsx xs'))" + unfolding proj_map + apply (rule fo_nmlz_eqI) + apply (rule ad_agr_list_mono[OF Int_lower1]) + apply (rule ad_agr_list_subset[OF _ close(2)[unfolded xsf_def xg_def(2)]]) + using assms(8) + apply (auto) + done + have proj_ys: "fo_nmlz (X \ Y) (proj_tuple ns (zip nsy ys)) = fo_nmlz (X \ Y) (proj_tuple ns (zip nsy ys'))" + unfolding proj_map + apply (rule fo_nmlz_eqI) + apply (rule ad_agr_list_mono[OF Int_lower2]) + apply (rule ad_agr_list_subset[OF _ close(4)[unfolded ysf_def xf_def(2)]]) + using assms(8) + apply (auto) + done + show "False" + using c fo_nmlz_Int proj_xs proj_ys + by auto + next + assume c: "proj_tuple ns (zip nsx xs) \ proj_tuple ns (zip nsy ys) \ + (\x\set (proj_tuple ns (zip nsx xs)). isl x) \ (\y\set (proj_tuple ns (zip nsy ys)). isl y)" + have "case x of Inl z \ z \ X \ Y | Inr b \ False" if "x \ set (proj_tuple ns (zip nsx xs'))" for x + using close(2) assms(1,8) c that ad_agr_list_fo_nmlzd_isl[where ?X=X and ?f=xsf and ?g=xg and ?xs=nsx] + unfolding proj_map + unfolding xsf_def xg_def(2) + apply (auto simp: fo_nmlzd_def split: sum.splits) + apply (metis image_eqI subsetD vimageI) + apply (metis subsetD sum.disc(2)) + done + then have E1: "fo_nmlz (X \ Y) (proj_tuple ns (zip nsx xs')) = proj_tuple ns (zip nsx xs')" + by (rule fo_nmlz_idem_isl) + have "case y of Inl z \ z \ X \ Y | Inr b \ False" if "y \ set (proj_tuple ns (zip nsy ys'))" for y + using close(4) assms(2,8) c that ad_agr_list_fo_nmlzd_isl[where ?X=Y and ?f=ysf and ?g=xf and ?xs=nsy] + unfolding proj_map + unfolding ysf_def xf_def(2) + apply (auto simp: fo_nmlzd_def split: sum.splits) + apply (metis image_eqI subsetD vimageI) + apply (metis subsetD sum.disc(2)) + done + then have E2: "fo_nmlz (X \ Y) (proj_tuple ns (zip nsy ys')) = proj_tuple ns (zip nsy ys')" + by (rule fo_nmlz_idem_isl) + have ad: "ad_agr_list X (map xsf ns) (map xg ns)" + using assms(8) close(2)[unfolded xsf_def xg_def(2)] ad_agr_list_subset + by blast + have "\x\set (proj_tuple ns (zip nsx xs)). isl x" + using c + by auto + then have E3: "proj_tuple ns (zip nsx xs) = proj_tuple ns (zip nsx xs')" + using assms(8) + unfolding proj_map + apply (induction ns) + using ad_agr_list_fo_nmlzd_isl[OF close(2)[unfolded xsf_def xg_def(2)] assms(1)[unfolded xsf_def]] + by auto + have "\x\set (proj_tuple ns (zip nsy ys)). isl x" + using c + by auto + then have E4: "proj_tuple ns (zip nsy ys) = proj_tuple ns (zip nsy ys')" + using assms(8) + unfolding proj_map + apply (induction ns) + using ad_agr_list_fo_nmlzd_isl[OF close(4)[unfolded ysf_def xf_def(2)] assms(2)[unfolded ysf_def]] + by auto + show "False" + using c fo_nmlz_Un + unfolding E1 E2 E3 E4 + by auto + qed + } + then show ?thesis + by (auto simp: eval_conj_tuple_def Let_def cxs_def[symmetric] nxs_def[symmetric] cys_def[symmetric] nys_def[symmetric] + ext_tuple_eq[OF len_sort(1)] ext_tuple_eq[OF len_sort(2)]) +qed + +lemma eval_conj_tuple_close_empty: + assumes "fo_nmlzd X xs" "fo_nmlzd Y ys" + "length nsx = length xs" "length nsy = length ys" + "sorted_distinct nsx" "sorted_distinct nsy" + "ns = filter (\n. n \ set nsy) nsx" + "fo_nmlz (X \ Y) (proj_tuple ns (zip nsx xs)) \ fo_nmlz (X \ Y) (proj_tuple ns (zip nsy ys))" + "xs' \ ad_agr_close ((X \ Y) - X) xs" "ys' \ ad_agr_close ((X \ Y) - Y) ys" + shows "eval_conj_tuple (X \ Y) nsx nsy xs' ys' = {}" +proof - + have aux: "sorted_distinct ns" "set ns \ set nsx \ set nsy" + using assms(5) sorted_filter[of id] + by (auto simp: assms(7)) + show ?thesis + using eval_conj_tuple_close_empty2[OF assms(1-6) aux] assms(8-) + by auto +qed + +lemma eval_conj_tuple_empty2: + assumes "fo_nmlzd Z xs" "fo_nmlzd Z ys" + "length nsx = length xs" "length nsy = length ys" + "sorted_distinct nsx" "sorted_distinct nsy" + "sorted_distinct ns" "set ns \ set nsx \ set nsy" + "fo_nmlz Z (proj_tuple ns (zip nsx xs)) \ fo_nmlz Z (proj_tuple ns (zip nsy ys)) \ + (proj_tuple ns (zip nsx xs) \ proj_tuple ns (zip nsy ys) \ + (\x \ set (proj_tuple ns (zip nsx xs)). isl x) \ (\y \ set (proj_tuple ns (zip nsy ys)). isl y))" + shows "eval_conj_tuple Z nsx nsy xs ys = {}" + using eval_conj_tuple_close_empty2[OF assms(1-8)] assms(9) ad_agr_close_empty assms(1-2) + by fastforce + +lemma eval_conj_tuple_empty: + assumes "fo_nmlzd Z xs" "fo_nmlzd Z ys" + "length nsx = length xs" "length nsy = length ys" + "sorted_distinct nsx" "sorted_distinct nsy" + "ns = filter (\n. n \ set nsy) nsx" + "fo_nmlz Z (proj_tuple ns (zip nsx xs)) \ fo_nmlz Z (proj_tuple ns (zip nsy ys))" + shows "eval_conj_tuple Z nsx nsy xs ys = {}" +proof - + have aux: "sorted_distinct ns" "set ns \ set nsx \ set nsy" + using assms(5) sorted_filter[of id] + by (auto simp: assms(7)) + show ?thesis + using eval_conj_tuple_empty2[OF assms(1-6) aux] assms(8-) + by auto +qed + +lemma nall_tuples_rec_filter: + assumes "xs \ nall_tuples_rec AD n (length xs)" "ys = filter (\x. \isl x) xs" + shows "ys \ nall_tuples_rec {} n (length ys)" + using assms +proof (induction xs arbitrary: n ys) + case (Cons x xs) + then show ?case + proof (cases x) + case (Inr b) + have b_le_i: "b \ n" + using Cons(2) + by (auto simp: Inr) + obtain zs where ys_def: "ys = Inr b # zs" "zs = filter (\x. \ isl x) xs" + using Cons(3) + by (auto simp: Inr) + show ?thesis + proof (cases "b < n") + case True + then show ?thesis + using Cons(1)[OF _ ys_def(2), of n] Cons(2) + by (auto simp: Inr ys_def(1)) + next + case False + then show ?thesis + using Cons(1)[OF _ ys_def(2), of "Suc n"] Cons(2) + by (auto simp: Inr ys_def(1)) + qed + qed auto +qed auto + +lemma nall_tuples_rec_filter_rev: + assumes "ys \ nall_tuples_rec {} n (length ys)" "ys = filter (\x. \isl x) xs" + "Inl -` set xs \ AD" + shows "xs \ nall_tuples_rec AD n (length xs)" + using assms +proof (induction xs arbitrary: n ys) + case (Cons x xs) + show ?case + proof (cases x) + case (Inl a) + have a_AD: "a \ AD" + using Cons(4) + by (auto simp: Inl) + show ?thesis + using Cons(1)[OF Cons(2)] Cons(3,4) a_AD + by (auto simp: Inl) + next + case (Inr b) + obtain zs where ys_def: "ys = Inr b # zs" "zs = filter (\x. \ isl x) xs" + using Cons(3) + by (auto simp: Inr) + show ?thesis + using Cons(1)[OF _ ys_def(2)] Cons(2,4) + by (fastforce simp: ys_def(1) Inr) + qed +qed auto + +lemma eval_conj_set_aux: + fixes AD :: "'a set" + assumes ns\'_def: "ns\' = filter (\n. n \ set ns\) ns\" + and ns\'_def: "ns\' = filter (\n. n \ set ns\) ns\" + and X\_def: "X\ = fo_nmlz AD ` proj_vals R\ ns\" + and X\_def: "X\ = fo_nmlz AD ` proj_vals R\ ns\" + and distinct: "sorted_distinct ns\" "sorted_distinct ns\" + and cxs_def: "cxs = filter (\(n, x). n \ set ns\ \ isl x) (zip ns\ xs)" + and nxs_def: "nxs = map fst (filter (\(n, x). n \ set ns\ \ \isl x) (zip ns\ xs))" + and cys_def: "cys = filter (\(n, y). n \ set ns\ \ isl y) (zip ns\ ys)" + and nys_def: "nys = map fst (filter (\(n, y). n \ set ns\ \ \isl y) (zip ns\ ys))" + and xs_ys_def: "xs \ X\" "ys \ X\" + and \xs_def: "xs = map \xs ns\" "fs\ = map \xs ns\'" + and \ys_def: "ys = map \ys ns\" "fs\ = map \ys ns\'" + and fs\_def: "fs\ \ nall_tuples_rec AD (card (Inr -` set xs)) (length ns\')" + and fs\_def: "fs\ \ nall_tuples_rec AD (card (Inr -` set ys)) (length ns\')" + and ad_agr: "ad_agr_list AD (map \ys (sort (ns\ @ ns\'))) (map \xs (sort (ns\ @ ns\')))" + shows + "map snd (merge (zip ns\ xs) (zip ns\' fs\)) = + map snd (merge (zip (sort (ns\ @ map fst cys)) (map \xs (sort (ns\ @ map fst cys)))) + (zip nys (map \xs nys)))" and + "map snd (merge (zip ns\ xs) cys) = map \xs (sort (ns\ @ map fst cys))" and + "map \xs nys \ + nall_tuples_rec {} (card (Inr -` set (map \xs (sort (ns\ @ map fst cys))))) (length nys)" +proof - + have len_xs_ys: "length xs = length ns\" "length ys = length ns\" + using xs_ys_def + by (auto simp: X\_def X\_def proj_vals_def fo_nmlz_length) + have len_fs\: "length fs\ = length ns\'" + using \xs_def(2) + by auto + have set_ns\': "set ns\' = set (map fst cys) \ set nys" + using len_xs_ys(2) + by (auto simp: ns\'_def cys_def nys_def dest: set_zip_leftD) + (metis (no_types, lifting) image_eqI in_set_impl_in_set_zip1 mem_Collect_eq + prod.sel(1) split_conv) + have "\x. Inl x \ set xs \ set fs\ \ x \ AD" "\y. Inl y \ set ys \ set fs\ \ y \ AD" + using xs_ys_def fo_nmlz_set[of AD] nall_tuples_rec_Inl[OF fs\_def] + nall_tuples_rec_Inl[OF fs\_def] + by (auto simp: X\_def X\_def) + then have Inl_xs_ys: + "\n. n \ set ns\ \ set ns\ \ isl (\xs n) \ (\x. \xs n = Inl x \ x \ AD)" + "\n. n \ set ns\ \ set ns\ \ isl (\ys n) \ (\y. \ys n = Inl y \ y \ AD)" + unfolding \xs_def \ys_def ns\'_def ns\'_def + by (auto simp: isl_def) (smt imageI mem_Collect_eq)+ + have sort_sort: "sort (ns\ @ ns\') = sort (ns\ @ ns\')" + apply (rule sorted_distinct_set_unique) + using distinct + by (auto simp: ns\'_def ns\'_def) + have isl_iff: "\n. n \ set ns\' \ set ns\' \ isl (\xs n) \ isl (\ys n) \ \xs n = \ys n" + using ad_agr Inl_xs_ys + unfolding sort_sort[symmetric] ad_agr_list_link[symmetric] + unfolding ns\'_def ns\'_def + apply (auto simp: ad_agr_sets_def) + unfolding ad_equiv_pair.simps + apply (metis (no_types, lifting) UnI2 image_eqI mem_Collect_eq) + apply (metis (no_types, lifting) UnI2 image_eqI mem_Collect_eq) + apply (metis (no_types, lifting) UnI1 image_eqI)+ + done + have "\n. n \ set (map fst cys) \ isl (\xs n)" + "\n. n \ set (map fst cxs) \ isl (\ys n)" + using isl_iff + by (auto simp: cys_def ns\'_def \ys_def(1) cxs_def ns\'_def \xs_def(1) set_zip) + (metis nth_mem)+ + then have Inr_sort: "Inr -` set (map \xs (sort (ns\ @ map fst cys))) = Inr -` set xs" + unfolding \xs_def(1) \ys_def(1) + by (auto simp: zip_map_fst_snd dest: set_zip_leftD) + (metis fst_conv image_iff sum.disc(2))+ + have map_nys: "map \xs nys = filter (\x. \isl x) fs\" + using isl_iff[unfolded ns\'_def] + unfolding nys_def \ys_def(1) \xs_def(2) ns\'_def filter_map + by (induction ns\) force+ + have map_nys_in_nall: "map \xs nys \ nall_tuples_rec {} (card (Inr -` set xs)) (length nys)" + using nall_tuples_rec_filter[OF fs\_def[folded len_fs\] map_nys] + by auto + have map_cys: "map snd cys = map \xs (map fst cys)" + using isl_iff + by (auto simp: cys_def set_zip ns\'_def \ys_def(1)) (metis nth_mem) + show merge_xs_cys: "map snd (merge (zip ns\ xs) cys) = map \xs (sort (ns\ @ map fst cys))" + apply (subst zip_map_fst_snd[of cys, symmetric]) + unfolding \xs_def(1) map_cys + apply (rule merge_map) + using distinct + by (auto simp: cys_def \ys_def sorted_filter distinct_map_filter map_fst_zip_take) + have merge_nys_prems: "sorted_distinct (sort (ns\ @ map fst cys))" "sorted_distinct nys" + "set (sort (ns\ @ map fst cys)) \ set nys = {}" + using distinct len_xs_ys(2) + by (auto simp: cys_def nys_def distinct_map_filter sorted_filter) + (metis eq_key_imp_eq_value map_fst_zip) + have map_snd_merge_nys: "map \xs (sort (sort (ns\ @ map fst cys) @ nys)) = + map snd (merge (zip (sort (ns\ @ map fst cys)) (map \xs (sort (ns\ @ map fst cys)))) + (zip nys (map \xs nys)))" + by (rule merge_map[OF merge_nys_prems, symmetric]) + have sort_sort_nys: "sort (sort (ns\ @ map fst cys) @ nys) = sort (ns\ @ ns\')" + apply (rule sorted_distinct_set_unique) + using distinct merge_nys_prems set_ns\' + by (auto simp: cys_def nys_def ns\'_def dest: set_zip_leftD) + have map_merge_fs\: "map snd (merge (zip ns\ xs) (zip ns\' fs\)) = map \xs (sort (ns\ @ ns\'))" + unfolding \xs_def + apply (rule merge_map) + using distinct sorted_filter[of id] + by (auto simp: ns\'_def) + show "map snd (merge (zip ns\ xs) (zip ns\' fs\)) = + map snd (merge (zip (sort (ns\ @ map fst cys)) (map \xs (sort (ns\ @ map fst cys)))) + (zip nys (map \xs nys)))" + unfolding map_merge_fs\ map_snd_merge_nys[unfolded sort_sort_nys] + by auto + show "map \xs nys \ nall_tuples_rec {} + (card (Inr -` set (map \xs (sort (ns\ @ map fst cys))))) (length nys)" + using map_nys_in_nall + unfolding Inr_sort[symmetric] + by auto +qed + +lemma eval_conj_set_aux': + fixes AD :: "'a set" + assumes ns\'_def: "ns\' = filter (\n. n \ set ns\) ns\" + and ns\'_def: "ns\' = filter (\n. n \ set ns\) ns\" + and X\_def: "X\ = fo_nmlz AD ` proj_vals R\ ns\" + and X\_def: "X\ = fo_nmlz AD ` proj_vals R\ ns\" + and distinct: "sorted_distinct ns\" "sorted_distinct ns\" + and cxs_def: "cxs = filter (\(n, x). n \ set ns\ \ isl x) (zip ns\ xs)" + and nxs_def: "nxs = map fst (filter (\(n, x). n \ set ns\ \ \isl x) (zip ns\ xs))" + and cys_def: "cys = filter (\(n, y). n \ set ns\ \ isl y) (zip ns\ ys)" + and nys_def: "nys = map fst (filter (\(n, y). n \ set ns\ \ \isl y) (zip ns\ ys))" + and xs_ys_def: "xs \ X\" "ys \ X\" + and \xs_def: "xs = map \xs ns\" "map snd cys = map \xs (map fst cys)" + "ys\ = map \xs nys" + and \ys_def: "ys = map \ys ns\" "map snd cxs = map \ys (map fst cxs)" + "xs\ = map \ys nxs" + and fs\_def: "fs\ = map \xs ns\'" + and fs\_def: "fs\ = map \ys ns\'" + and ys\_def: "map \xs nys \ nall_tuples_rec {} + (card (Inr -` set (map \xs (sort (ns\ @ map fst cys))))) (length nys)" + and Inl_set_AD: "Inl -` (set (map snd cxs) \ set xs\) \ AD" + "Inl -` (set (map snd cys) \ set ys\) \ AD" + and ad_agr: "ad_agr_list AD (map \ys (sort (ns\ @ ns\'))) (map \xs (sort (ns\ @ ns\')))" + shows + "map snd (merge (zip ns\ xs) (zip ns\' fs\)) = + map snd (merge (zip (sort (ns\ @ map fst cys)) (map \xs (sort (ns\ @ map fst cys)))) + (zip nys (map \xs nys)))" and + "map snd (merge (zip ns\ xs) cys) = map \xs (sort (ns\ @ map fst cys))" + "fs\ \ nall_tuples_rec AD (card (Inr -` set xs)) (length ns\')" +proof - + have len_xs_ys: "length xs = length ns\" "length ys = length ns\" + using xs_ys_def + by (auto simp: X\_def X\_def proj_vals_def fo_nmlz_length) + have len_fs\: "length fs\ = length ns\'" + by (auto simp: fs\_def) + have set_ns: "set ns\' = set (map fst cys) \ set nys" + "set ns\' = set (map fst cxs) \ set nxs" + using len_xs_ys + by (auto simp: ns\'_def cys_def nys_def ns\'_def cxs_def nxs_def dest: set_zip_leftD) + (metis (no_types, lifting) image_eqI in_set_impl_in_set_zip1 mem_Collect_eq + prod.sel(1) split_conv)+ + then have set_\_ns: "\xs ` set ns\' \ \xs ` set ns\' \ set xs \ set (map snd cys) \ set ys\" + "\ys ` set ns\' \ \ys ` set ns\' \ set ys \ set (map snd cxs) \ set xs\" + by (auto simp: \xs_def \ys_def ns\'_def ns\'_def) + have Inl_sub_AD: "\x. Inl x \ set xs \ set (map snd cys) \ set ys\ \ x \ AD" + "\y. Inl y \ set ys \ set (map snd cxs) \ set xs\ \ y \ AD" + using xs_ys_def fo_nmlz_set[of AD] Inl_set_AD + by (auto simp: X\_def X\_def) (metis in_set_zipE set_map subset_eq vimageI zip_map_fst_snd)+ + then have Inl_xs_ys: + "\n. n \ set ns\' \ set ns\' \ isl (\xs n) \ (\x. \xs n = Inl x \ x \ AD)" + "\n. n \ set ns\' \ set ns\' \ isl (\ys n) \ (\y. \ys n = Inl y \ y \ AD)" + using set_\_ns + by (auto simp: isl_def rev_image_eqI) + have sort_sort: "sort (ns\ @ ns\') = sort (ns\ @ ns\')" + apply (rule sorted_distinct_set_unique) + using distinct + by (auto simp: ns\'_def ns\'_def) + have isl_iff: "\n. n \ set ns\' \ set ns\' \ isl (\xs n) \ isl (\ys n) \ \xs n = \ys n" + using ad_agr Inl_xs_ys + unfolding sort_sort[symmetric] ad_agr_list_link[symmetric] + unfolding ns\'_def ns\'_def + apply (auto simp: ad_agr_sets_def) + unfolding ad_equiv_pair.simps + apply (metis (no_types, lifting) UnI2 image_eqI mem_Collect_eq) + apply (metis (no_types, lifting) UnI2 image_eqI mem_Collect_eq) + apply (metis (no_types, lifting) UnI1 image_eqI)+ + done + have "\n. n \ set (map fst cys) \ isl (\xs n)" + "\n. n \ set (map fst cxs) \ isl (\ys n)" + using isl_iff + by (auto simp: cys_def ns\'_def \ys_def(1) cxs_def ns\'_def \xs_def(1) set_zip) + (metis nth_mem)+ + then have Inr_sort: "Inr -` set (map \xs (sort (ns\ @ map fst cys))) = Inr -` set xs" + unfolding \xs_def(1) \ys_def(1) + by (auto simp: zip_map_fst_snd dest: set_zip_leftD) + (metis fst_conv image_iff sum.disc(2))+ + have map_nys: "map \xs nys = filter (\x. \isl x) fs\" + using isl_iff[unfolded ns\'_def] + unfolding nys_def \ys_def(1) fs\_def ns\'_def + by (induction ns\) force+ + have map_cys: "map snd cys = map \xs (map fst cys)" + using isl_iff + by (auto simp: cys_def set_zip ns\'_def \ys_def(1)) (metis nth_mem) + show merge_xs_cys: "map snd (merge (zip ns\ xs) cys) = map \xs (sort (ns\ @ map fst cys))" + apply (subst zip_map_fst_snd[of cys, symmetric]) + unfolding \xs_def(1) map_cys + apply (rule merge_map) + using distinct + by (auto simp: cys_def \ys_def sorted_filter distinct_map_filter map_fst_zip_take) + have merge_nys_prems: "sorted_distinct (sort (ns\ @ map fst cys))" "sorted_distinct nys" + "set (sort (ns\ @ map fst cys)) \ set nys = {}" + using distinct len_xs_ys(2) + by (auto simp: cys_def nys_def distinct_map_filter sorted_filter) + (metis eq_key_imp_eq_value map_fst_zip) + have map_snd_merge_nys: "map \xs (sort (sort (ns\ @ map fst cys) @ nys)) = + map snd (merge (zip (sort (ns\ @ map fst cys)) (map \xs (sort (ns\ @ map fst cys)))) + (zip nys (map \xs nys)))" + by (rule merge_map[OF merge_nys_prems, symmetric]) + have sort_sort_nys: "sort (sort (ns\ @ map fst cys) @ nys) = sort (ns\ @ ns\')" + apply (rule sorted_distinct_set_unique) + using distinct merge_nys_prems set_ns + by (auto simp: cys_def nys_def ns\'_def dest: set_zip_leftD) + have map_merge_fs\: "map snd (merge (zip ns\ xs) (zip ns\' fs\)) = map \xs (sort (ns\ @ ns\'))" + unfolding \xs_def fs\_def + apply (rule merge_map) + using distinct sorted_filter[of id] + by (auto simp: ns\'_def) + show "map snd (merge (zip ns\ xs) (zip ns\' fs\)) = + map snd (merge (zip (sort (ns\ @ map fst cys)) (map \xs (sort (ns\ @ map fst cys)))) + (zip nys (map \xs nys)))" + unfolding map_merge_fs\ map_snd_merge_nys[unfolded sort_sort_nys] + by auto + have "Inl -` set fs\ \ AD" + using Inl_sub_AD(1) set_\_ns + by (force simp: fs\_def) + then show "fs\ \ nall_tuples_rec AD (card (Inr -` set xs)) (length ns\')" + unfolding len_fs\[symmetric] + using nall_tuples_rec_filter_rev[OF _ map_nys] ys\_def[unfolded Inr_sort] + by auto +qed + +lemma eval_conj_set_correct: + assumes ns\'_def: "ns\' = filter (\n. n \ set ns\) ns\" + and ns\'_def: "ns\' = filter (\n. n \ set ns\) ns\" + and X\_def: "X\ = fo_nmlz AD ` proj_vals R\ ns\" + and X\_def: "X\ = fo_nmlz AD ` proj_vals R\ ns\" + and distinct: "sorted_distinct ns\" "sorted_distinct ns\" + shows "eval_conj_set AD ns\ X\ ns\ X\ = ext_tuple_set AD ns\ ns\' X\ \ ext_tuple_set AD ns\ ns\' X\" +proof - + have aux: "ext_tuple_set AD ns\ ns\' X\ = fo_nmlz AD ` \(ext_tuple AD ns\ ns\' ` X\)" + "ext_tuple_set AD ns\ ns\' X\ = fo_nmlz AD ` \(ext_tuple AD ns\ ns\' ` X\)" + by (auto simp: ext_tuple_set_def ext_tuple_def X\_def X\_def image_iff fo_nmlz_idem[OF fo_nmlz_sound]) + show ?thesis + unfolding aux + proof (rule set_eqI, rule iffI) + fix vs + assume "vs \ fo_nmlz AD ` \(ext_tuple AD ns\ ns\' ` X\) \ + fo_nmlz AD ` \(ext_tuple AD ns\ ns\' ` X\)" + then obtain xs ys where xs_ys_def: "xs \ X\" "vs \ fo_nmlz AD ` ext_tuple AD ns\ ns\' xs" + "ys \ X\" "vs \ fo_nmlz AD ` ext_tuple AD ns\ ns\' ys" + by auto + have len_xs_ys: "length xs = length ns\" "length ys = length ns\" + using xs_ys_def(1,3) + by (auto simp: X\_def X\_def proj_vals_def fo_nmlz_length) + obtain fs\ where fs\_def: "vs = fo_nmlz AD (map snd (merge (zip ns\ xs) (zip ns\' fs\)))" + "fs\ \ nall_tuples_rec AD (card (Inr -` set xs)) (length ns\')" + using xs_ys_def(1,2) + by (auto simp: X\_def proj_vals_def ext_tuple_def split: if_splits) + (metis fo_nmlz_map length_map map_snd_zip) + obtain fs\ where fs\_def: "vs = fo_nmlz AD (map snd (merge (zip ns\ ys) (zip ns\' fs\)))" + "fs\ \ nall_tuples_rec AD (card (Inr -` set ys)) (length ns\')" + using xs_ys_def(3,4) + by (auto simp: X\_def proj_vals_def ext_tuple_def split: if_splits) + (metis fo_nmlz_map length_map map_snd_zip) + note len_fs\ = nall_tuples_rec_length[OF fs\_def(2)] + note len_fs\ = nall_tuples_rec_length[OF fs\_def(2)] + obtain \xs where \xs_def: "xs = map \xs ns\" "fs\ = map \xs ns\'" + using exists_map[of "ns\ @ ns\'" "xs @ fs\"] len_xs_ys(1) len_fs\ distinct + by (auto simp: ns\'_def) + obtain \ys where \ys_def: "ys = map \ys ns\" "fs\ = map \ys ns\'" + using exists_map[of "ns\ @ ns\'" "ys @ fs\"] len_xs_ys(2) len_fs\ distinct + by (auto simp: ns\'_def) + have map_merge_fs\: "map snd (merge (zip ns\ xs) (zip ns\' fs\)) = map \xs (sort (ns\ @ ns\'))" + unfolding \xs_def + apply (rule merge_map) + using distinct sorted_filter[of id] + by (auto simp: ns\'_def) + have map_merge_fs\: "map snd (merge (zip ns\ ys) (zip ns\' fs\)) = map \ys (sort (ns\ @ ns\'))" + unfolding \ys_def + apply (rule merge_map) + using distinct sorted_filter[of id] + by (auto simp: ns\'_def) + define cxs where "cxs = filter (\(n, x). n \ set ns\ \ isl x) (zip ns\ xs)" + define nxs where "nxs = map fst (filter (\(n, x). n \ set ns\ \ \isl x) (zip ns\ xs))" + define cys where "cys = filter (\(n, y). n \ set ns\ \ isl y) (zip ns\ ys)" + define nys where "nys = map fst (filter (\(n, y). n \ set ns\ \ \isl y) (zip ns\ ys))" + note ad_agr1 = fo_nmlz_eqD[OF trans[OF fs\_def(1)[symmetric] fs\_def(1)], + unfolded map_merge_fs\ map_merge_fs\] + note ad_agr2 = ad_agr_list_comm[OF ad_agr1] + obtain \xs where aux1: + "map snd (merge (zip ns\ xs) (zip ns\' fs\)) = + map snd (merge (zip (sort (ns\ @ map fst cys)) (map \xs (sort (ns\ @ map fst cys)))) + (zip nys (map \xs nys)))" + "map snd (merge (zip ns\ xs) cys) = map \xs (sort (ns\ @ map fst cys))" + "map \xs nys \ nall_tuples_rec {} + (card (Inr -` set (map \xs (sort (ns\ @ map fst cys))))) (length nys)" + using eval_conj_set_aux[OF ns\'_def ns\'_def X\_def X\_def distinct cxs_def nxs_def + cys_def nys_def xs_ys_def(1,3) \xs_def \ys_def fs\_def(2) fs\_def(2) ad_agr2] + by blast + obtain \ys where aux2: + "map snd (merge (zip ns\ ys) (zip ns\' fs\)) = + map snd (merge (zip (sort (ns\ @ map fst cxs)) (map \ys (sort (ns\ @ map fst cxs)))) + (zip nxs (map \ys nxs)))" + "map snd (merge (zip ns\ ys) cxs) = map \ys (sort (ns\ @ map fst cxs))" + "map \ys nxs \ nall_tuples_rec {} + (card (Inr -` set (map \ys (sort (ns\ @ map fst cxs))))) (length nxs)" + using eval_conj_set_aux[OF ns\'_def ns\'_def X\_def X\_def distinct(2,1) cys_def nys_def + cxs_def nxs_def xs_ys_def(3,1) \ys_def \xs_def fs\_def(2) fs\_def(2) ad_agr1] + by blast + have vs_ext_nys: "vs \ fo_nmlz AD ` ext_tuple {} (sort (ns\ @ map fst cys)) nys + (map snd (merge (zip ns\ xs) cys))" + using aux1(3) + unfolding fs\_def(1) aux1(1) + by (simp add: ext_tuple_eq[OF length_map[symmetric]] aux1(2)) + have vs_ext_nxs: "vs \ fo_nmlz AD ` ext_tuple {} (sort (ns\ @ map fst cxs)) nxs + (map snd (merge (zip ns\ ys) cxs))" + using aux2(3) + unfolding fs\_def(1) aux2(1) + by (simp add: ext_tuple_eq[OF length_map[symmetric]] aux2(2)) + show "vs \ eval_conj_set AD ns\ X\ ns\ X\" + using vs_ext_nys vs_ext_nxs xs_ys_def(1,3) + by (auto simp: eval_conj_set_def eval_conj_tuple_def nys_def cys_def nxs_def cxs_def Let_def) + next + fix vs + assume "vs \ eval_conj_set AD ns\ X\ ns\ X\" + then obtain xs ys cxs nxs cys nys where + cxs_def: "cxs = filter (\(n, x). n \ set ns\ \ isl x) (zip ns\ xs)" and + nxs_def: "nxs = map fst (filter (\(n, x). n \ set ns\ \ \isl x) (zip ns\ xs))" and + cys_def: "cys = filter (\(n, y). n \ set ns\ \ isl y) (zip ns\ ys)" and + nys_def: "nys = map fst (filter (\(n, y). n \ set ns\ \ \isl y) (zip ns\ ys))" and + xs_def: "xs \ X\" "vs \ fo_nmlz AD ` ext_tuple {} (sort (ns\ @ map fst cys)) nys + (map snd (merge (zip ns\ xs) cys))" and + ys_def: "ys \ X\" "vs \ fo_nmlz AD ` ext_tuple {} (sort (ns\ @ map fst cxs)) nxs + (map snd (merge (zip ns\ ys) cxs))" + by (auto simp: eval_conj_set_def eval_conj_tuple_def Let_def) (metis (no_types, lifting) image_eqI) + have len_xs_ys: "length xs = length ns\" "length ys = length ns\" + using xs_def(1) ys_def(1) + by (auto simp: X\_def X\_def proj_vals_def fo_nmlz_length) + have len_merge_cys: "length (map snd (merge (zip ns\ xs) cys)) = + length (sort (ns\ @ map fst cys))" + using merge_length[of "zip ns\ xs" cys] len_xs_ys + by auto + obtain ys\ where ys\_def: "vs = fo_nmlz AD (map snd (merge (zip (sort (ns\ @ map fst cys)) + (map snd (merge (zip ns\ xs) cys))) (zip nys ys\)))" + "ys\ \ nall_tuples_rec {} (card (Inr -` set (map snd (merge (zip ns\ xs) cys)))) + (length nys)" + using xs_def(2) + unfolding ext_tuple_eq[OF len_merge_cys[symmetric]] + by auto + have distinct_nys: "distinct (ns\ @ map fst cys @ nys)" + using distinct len_xs_ys + by (auto simp: cys_def nys_def sorted_filter distinct_map_filter) + (metis eq_key_imp_eq_value map_fst_zip) + obtain \xs where \xs_def: "xs = map \xs ns\" "map snd cys = map \xs (map fst cys)" + "ys\ = map \xs nys" + using exists_map[OF _ distinct_nys, of "xs @ map snd cys @ ys\"] len_xs_ys(1) + nall_tuples_rec_length[OF ys\_def(2)] + by (auto simp: ns\'_def) + have len_merge_cxs: "length (map snd (merge (zip ns\ ys) cxs)) = + length (sort (ns\ @ map fst cxs))" + using merge_length[of "zip ns\ ys"] len_xs_ys + by auto + obtain xs\ where xs\_def: "vs = fo_nmlz AD (map snd (merge (zip (sort (ns\ @ map fst cxs)) + (map snd (merge (zip ns\ ys) cxs))) (zip nxs xs\)))" + "xs\ \ nall_tuples_rec {} (card (Inr -` set (map snd (merge (zip ns\ ys) cxs)))) + (length nxs)" + using ys_def(2) + unfolding ext_tuple_eq[OF len_merge_cxs[symmetric]] + by auto + have distinct_nxs: "distinct (ns\ @ map fst cxs @ nxs)" + using distinct len_xs_ys(1) + by (auto simp: cxs_def nxs_def sorted_filter distinct_map_filter) + (metis eq_key_imp_eq_value map_fst_zip) + obtain \ys where \ys_def: "ys = map \ys ns\" "map snd cxs = map \ys (map fst cxs)" + "xs\ = map \ys nxs" + using exists_map[OF _ distinct_nxs, of "ys @ map snd cxs @ xs\"] len_xs_ys(2) + nall_tuples_rec_length[OF xs\_def(2)] + by (auto simp: ns\'_def) + have sd_cs_ns: "sorted_distinct (map fst cxs)" "sorted_distinct nxs" + "sorted_distinct (map fst cys)" "sorted_distinct nys" + "sorted_distinct (sort (ns\ @ map fst cxs))" + "sorted_distinct (sort (ns\ @ map fst cys))" + using distinct len_xs_ys + by (auto simp: cxs_def nxs_def cys_def nys_def sorted_filter distinct_map_filter) + have set_cs_ns_disj: "set (map fst cxs) \ set nxs = {}" "set (map fst cys) \ set nys = {}" + "set (sort (ns\ @ map fst cys)) \ set nys = {}" + "set (sort (ns\ @ map fst cxs)) \ set nxs = {}" + using distinct nth_eq_iff_index_eq + by (auto simp: cxs_def nxs_def cys_def nys_def set_zip) blast+ + have merge_sort_cxs: "map snd (merge (zip ns\ ys) cxs) = map \ys (sort (ns\ @ map fst cxs))" + unfolding \ys_def(1) + apply (subst zip_map_fst_snd[of cxs, symmetric]) + unfolding \ys_def(2) + apply (rule merge_map) + using distinct(2) sd_cs_ns + by (auto simp: cxs_def) + have merge_sort_cys: "map snd (merge (zip ns\ xs) cys) = map \xs (sort (ns\ @ map fst cys))" + unfolding \xs_def(1) + apply (subst zip_map_fst_snd[of cys, symmetric]) + unfolding \xs_def(2) + apply (rule merge_map) + using distinct(1) sd_cs_ns + by (auto simp: cys_def) + have set_ns\': "set ns\' = set (map fst cys) \ set nys" + using len_xs_ys(2) + by (auto simp: ns\'_def cys_def nys_def dest: set_zip_leftD) + (metis (no_types, lifting) image_eqI in_set_impl_in_set_zip1 mem_Collect_eq + prod.sel(1) split_conv) + have sort_sort_nys: "sort (sort (ns\ @ map fst cys) @ nys) = sort (ns\ @ ns\')" + apply (rule sorted_distinct_set_unique) + using distinct sd_cs_ns set_cs_ns_disj set_ns\' + by (auto simp: cys_def nys_def ns\'_def dest: set_zip_leftD) + have set_ns\': "set ns\' = set (map fst cxs) \ set nxs" + using len_xs_ys(1) + by (auto simp: ns\'_def cxs_def nxs_def dest: set_zip_leftD) + (metis (no_types, lifting) image_eqI in_set_impl_in_set_zip1 mem_Collect_eq + prod.sel(1) split_conv) + have sort_sort_nxs: "sort (sort (ns\ @ map fst cxs) @ nxs) = sort (ns\ @ ns\')" + apply (rule sorted_distinct_set_unique) + using distinct sd_cs_ns set_cs_ns_disj set_ns\' + by (auto simp: cxs_def nxs_def ns\'_def dest: set_zip_leftD) + have ad_agr1: "ad_agr_list AD (map \ys (sort (ns\ @ ns\'))) (map \xs (sort (ns\ @ ns\')))" + using fo_nmlz_eqD[OF trans[OF xs\_def(1)[symmetric] ys\_def(1)]] + unfolding \xs_def(3) \ys_def(3) merge_sort_cxs merge_sort_cys + unfolding merge_map[OF sd_cs_ns(5) sd_cs_ns(2) set_cs_ns_disj(4)] + unfolding merge_map[OF sd_cs_ns(6) sd_cs_ns(4) set_cs_ns_disj(3)] + unfolding sort_sort_nxs sort_sort_nys . + note ad_agr2 = ad_agr_list_comm[OF ad_agr1] + have Inl_set_AD: "Inl -` (set (map snd cxs) \ set xs\) \ AD" + "Inl -` (set (map snd cys) \ set ys\) \ AD" + using xs_def(1) nall_tuples_rec_Inl[OF xs\_def(2)] ys_def(1) + nall_tuples_rec_Inl[OF ys\_def(2)] fo_nmlz_set[of AD] + by (fastforce simp: cxs_def X\_def cys_def X\_def dest!: set_zip_rightD)+ + note aux1 = eval_conj_set_aux'[OF ns\'_def ns\'_def X\_def X\_def distinct cxs_def nxs_def + cys_def nys_def xs_def(1) ys_def(1) \xs_def \ys_def refl refl + ys\_def(2)[unfolded \xs_def(3) merge_sort_cys] Inl_set_AD ad_agr1] + note aux2 = eval_conj_set_aux'[OF ns\'_def ns\'_def X\_def X\_def distinct(2,1) cys_def nys_def + cxs_def nxs_def ys_def(1) xs_def(1) \ys_def \xs_def refl refl + xs\_def(2)[unfolded \ys_def(3) merge_sort_cxs] Inl_set_AD(2,1) ad_agr2] + show "vs \ fo_nmlz AD ` \(ext_tuple AD ns\ ns\' ` X\) \ + fo_nmlz AD ` \(ext_tuple AD ns\ ns\' ` X\)" + using xs_def(1) ys_def(1) ys\_def(1) xs\_def(1) aux1(3) aux2(3) + ext_tuple_eq[OF len_xs_ys(1)[symmetric], of AD ns\'] + ext_tuple_eq[OF len_xs_ys(2)[symmetric], of AD ns\'] + unfolding aux1(2) aux2(2) \ys_def(3) \xs_def(3) aux1(1)[symmetric] aux2(1)[symmetric] + by blast + qed +qed + +lemma esat_exists_not_fv: "n \ fv_fo_fmla \ \ X \ {} \ + esat (Exists n \) I \ X \ esat \ I \ X" +proof (rule iffI) + assume assms: "n \ fv_fo_fmla \" "esat (Exists n \) I \ X" + then obtain x where "esat \ I (\(n := x)) X" + by auto + with assms(1) show "esat \ I \ X" + using esat_fv_cong[of \ \ "\(n := x)"] by fastforce +next + assume assms: "n \ fv_fo_fmla \" "X \ {}" "esat \ I \ X" + from assms(2) obtain x where x_def: "x \ X" + by auto + with assms(1,3) have "esat \ I (\(n := x)) X" + using esat_fv_cong[of \ \ "\(n := x)"] by fastforce + with x_def show "esat (Exists n \) I \ X" + by auto +qed + +lemma esat_forall_not_fv: "n \ fv_fo_fmla \ \ X \ {} \ + esat (Forall n \) I \ X \ esat \ I \ X" + using esat_exists_not_fv[of n "Neg \" X I \] + by auto + +lemma proj_sat_vals: "proj_sat \ I = + proj_vals {\. sat \ I \} (fv_fo_fmla_list \)" + by (auto simp: proj_sat_def proj_vals_def) + +lemma fv_fo_fmla_list_Pred: "remdups_adj (sort (fv_fo_terms_list ts)) = fv_fo_terms_list ts" + unfolding fv_fo_terms_list_def + by (simp add: distinct_remdups_adj_sort remdups_adj_distinct sorted_sort_id) + +lemma ad_agr_list_fv_list': "\(set (map set_fo_term ts)) \ X \ + ad_agr_list X (map \ (fv_fo_terms_list ts)) (map \ (fv_fo_terms_list ts)) \ + ad_agr_list X (\ \e ts) (\ \e ts)" +proof (induction ts) + case (Cons t ts) + have IH: "ad_agr_list X (\ \e ts) (\ \e ts)" + using Cons + by (auto simp: ad_agr_list_def ad_equiv_list_link[symmetric] fv_fo_terms_set_list + fv_fo_terms_set_def sp_equiv_list_link sp_equiv_def pairwise_def) blast+ + have ad_equiv: "\i. i \ fv_fo_term_set t \ \(fv_fo_term_set ` set ts) \ + ad_equiv_pair X (\ i, \ i)" + using Cons(3) + by (auto simp: ad_agr_list_def ad_equiv_list_link[symmetric] fv_fo_terms_set_list + fv_fo_terms_set_def) + have sp_equiv: "\i j. i \ fv_fo_term_set t \ \(fv_fo_term_set ` set ts) \ + j \ fv_fo_term_set t \ \(fv_fo_term_set ` set ts) \ sp_equiv_pair (\ i, \ i) (\ j, \ j)" + using Cons(3) + by (auto simp: ad_agr_list_def sp_equiv_list_link fv_fo_terms_set_list + fv_fo_terms_set_def sp_equiv_def pairwise_def) + show ?case + proof (cases t) + case (Const c) + show ?thesis + using IH Cons(2) + apply (auto simp: ad_agr_list_def eval_eterms_def ad_equiv_list_def Const + sp_equiv_list_def pairwise_def set_zip) + unfolding ad_equiv_pair.simps + apply (metis nth_map rev_image_eqI)+ + done + next + case (Var n) + note t_def = Var + have ad: "ad_equiv_pair X (\ n, \ n)" + using ad_equiv + by (auto simp: Var) + have "\y. y \ set (zip (map ((\e) \) ts) (map ((\e) \) ts)) \ y \ (\ n, \ n) \ + sp_equiv_pair (\ n, \ n) y \ sp_equiv_pair y (\ n, \ n)" + proof - + fix y + assume "y \ set (zip (map ((\e) \) ts) (map ((\e) \) ts))" + then obtain t' where y_def: "t' \ set ts" "y = (\ \e t', \ \e t')" + using nth_mem + by (auto simp: set_zip) blast + show "sp_equiv_pair (\ n, \ n) y \ sp_equiv_pair y (\ n, \ n)" + proof (cases t') + case (Const c') + have c'_X: "c' \ X" + using Cons(2) y_def(1) + by (auto simp: Const) (meson SUP_le_iff fo_term.set_intros subsetD) + then show ?thesis + using ad_equiv[of n] y_def(1) + unfolding y_def + apply (auto simp: Const t_def) + unfolding ad_equiv_pair.simps + apply fastforce+ + apply force + apply (metis rev_image_eqI) + done + next + case (Var n') + show ?thesis + using sp_equiv[of n n'] y_def(1) + unfolding y_def + by (fastforce simp: t_def Var) + qed + qed + then show ?thesis + using IH Cons(3) + by (auto simp: ad_agr_list_def eval_eterms_def ad_equiv_list_def Var ad sp_equiv_list_def + pairwise_insert) + qed +qed (auto simp: eval_eterms_def ad_agr_list_def ad_equiv_list_def sp_equiv_list_def) + +lemma ext_tuple_ad_agr_close: + assumes S\_def: "S\ \ {\. esat \ I \ UNIV}" + and AD_sub: "act_edom \ I \ AD\" "AD\ \ AD" + and X\_def: "X\ = fo_nmlz AD\ ` proj_vals S\ (fv_fo_fmla_list \)" + and ns\'_def: "ns\' = filter (\n. n \ fv_fo_fmla \) ns\" + and sd_ns\: "sorted_distinct ns\" + and fv_Un: "fv_fo_fmla \ = fv_fo_fmla \ \ set ns\" + shows "ext_tuple_set AD (fv_fo_fmla_list \) ns\' (ad_agr_close_set (AD - AD\) X\) = + fo_nmlz AD ` proj_vals S\ (fv_fo_fmla_list \)" + "ad_agr_close_set (AD - AD\) X\ = fo_nmlz AD ` proj_vals S\ (fv_fo_fmla_list \)" +proof - + have ad_agr_\: + "\\ \. ad_agr_sets (set (fv_fo_fmla_list \)) (set (fv_fo_fmla_list \)) AD\ \ \ \ + \ \ S\ \ \ \ S\" + using esat_UNIV_cong[OF ad_agr_sets_restrict, OF _ subset_refl] ad_agr_sets_mono AD_sub + unfolding S\_def + by blast + show ad_close_alt: "ad_agr_close_set (AD - AD\) X\ = fo_nmlz AD ` proj_vals S\ (fv_fo_fmla_list \)" + using ad_agr_close_correct[OF AD_sub(2) ad_agr_\] AD_sub(2) + unfolding X\_def S\_def[symmetric] proj_fmla_def + by (auto simp: ad_agr_close_set_def Set.is_empty_def) + have fv_\: "set (fv_fo_fmla_list \) \ set (fv_fo_fmla_list \)" + using fv_Un + by (auto simp: fv_fo_fmla_list_set) + have sd_ns\': "sorted_distinct ns\'" + using sd_ns\ sorted_filter[of id] + by (auto simp: ns\'_def) + show "ext_tuple_set AD (fv_fo_fmla_list \) ns\' (ad_agr_close_set (AD - AD\) X\) = + fo_nmlz AD ` proj_vals S\ (fv_fo_fmla_list \)" + apply (rule ext_tuple_correct) + using sorted_distinct_fv_list ad_close_alt ad_agr_\ ad_agr_sets_mono[OF AD_sub(2)] + fv_Un sd_ns\' + by (fastforce simp: ns\'_def fv_fo_fmla_list_set)+ +qed + +lemma proj_ext_tuple: + assumes S\_def: "S\ \ {\. esat \ I \ UNIV}" + and AD_sub: "act_edom \ I \ AD" + and X\_def: "X\ = fo_nmlz AD ` proj_vals S\ (fv_fo_fmla_list \)" + and ns\'_def: "ns\' = filter (\n. n \ fv_fo_fmla \) ns\" + and sd_ns\: "sorted_distinct ns\" + and fv_Un: "fv_fo_fmla \ = fv_fo_fmla \ \ set ns\" + and Z_props: "\xs. xs \ Z \ fo_nmlz AD xs = xs \ length xs = length (fv_fo_fmla_list \)" + shows "Z \ ext_tuple_set AD (fv_fo_fmla_list \) ns\' X\ = + {xs \ Z. fo_nmlz AD (proj_tuple (fv_fo_fmla_list \) (zip (fv_fo_fmla_list \) xs)) \ X\}" + "Z - ext_tuple_set AD (fv_fo_fmla_list \) ns\' X\ = + {xs \ Z. fo_nmlz AD (proj_tuple (fv_fo_fmla_list \) (zip (fv_fo_fmla_list \) xs)) \ X\}" +proof - + have ad_agr_\: + "\\ \. ad_agr_sets (set (fv_fo_fmla_list \)) (set (fv_fo_fmla_list \)) AD \ \ \ + \ \ S\ \ \ \ S\" + using esat_UNIV_cong[OF ad_agr_sets_restrict, OF _ subset_refl] ad_agr_sets_mono AD_sub + unfolding S\_def + by blast + have sd_ns\': "sorted_distinct ns\'" + using sd_ns\ sorted_filter[of id] + by (auto simp: ns\'_def) + have disj: "set (fv_fo_fmla_list \) \ set ns\' = {}" + by (auto simp: ns\'_def fv_fo_fmla_list_set) + have Un: "set (fv_fo_fmla_list \) \ set ns\' = set (fv_fo_fmla_list \)" + using fv_Un + by (auto simp: ns\'_def fv_fo_fmla_list_set) + note proj = proj_tuple_correct[OF sorted_distinct_fv_list sd_ns\' sorted_distinct_fv_list + disj Un X\_def ad_agr_\, simplified] + have "fo_nmlz AD ` X\ = X\" + using fo_nmlz_idem[OF fo_nmlz_sound] + by (auto simp: X\_def image_iff) + then have aux: "ext_tuple_set AD (fv_fo_fmla_list \) ns\' X\ = fo_nmlz AD ` \(ext_tuple AD (fv_fo_fmla_list \) ns\' ` X\)" + by (auto simp: ext_tuple_set_def ext_tuple_def) + show "Z \ ext_tuple_set AD (fv_fo_fmla_list \) ns\' X\ = + {xs \ Z. fo_nmlz AD (proj_tuple (fv_fo_fmla_list \) (zip (fv_fo_fmla_list \) xs)) \ X\}" + using Z_props proj + by (auto simp: aux) + show "Z - ext_tuple_set AD (fv_fo_fmla_list \) ns\' X\ = + {xs \ Z. fo_nmlz AD (proj_tuple (fv_fo_fmla_list \) (zip (fv_fo_fmla_list \) xs)) \ X\}" + using Z_props proj + by (auto simp: aux) +qed + +lemma fo_nmlz_proj_sub: "fo_nmlz AD ` proj_fmla \ R \ nall_tuples AD (nfv \)" + by (auto simp: proj_fmla_map fo_nmlz_length fo_nmlz_sound nfv_def + intro: nall_tuplesI) + +lemma fin_ad_agr_list_iff: + fixes AD :: "('a :: infinite) set" + assumes "finite AD" "\vs. vs \ Z \ length vs = n" + "Z = {ts. \ts' \ X. ad_agr_list AD (map Inl ts) ts'}" + shows "finite Z \ \(set ` Z) \ AD" +proof (rule iffI, rule ccontr) + assume fin: "finite Z" + assume "\\(set ` Z) \ AD" + then obtain \ i vs where \_def: "map \ [0.. Z" "i < n" "\ i \ AD" "vs \ X" + "ad_agr_list AD (map (Inl \ \) [0.. AD \ \ ` {0..y. y \ Y \ map ((\z. if z = \ i then y else z) \ \) [0.. Z" + using \_def(3) + by (auto simp: assms(3) intro!: bexI[OF _ \_def(4)] ad_agr_list_trans[OF _ \_def(5)]) + (auto simp: ad_agr_list_def ad_equiv_list_def set_zip Y_def ad_equiv_pair.simps + sp_equiv_list_def pairwise_def split: if_splits) + then have "(\x'. map ((\z. if z = \ i then x' else z) \ \) [0.. Z" + by auto + moreover have "inj (\x'. map ((\z. if z = \ i then x' else z) \ \) [0.._def(2) + by (auto simp: inj_def) + ultimately show "False" + using inf_UNIV_Y fin + by (meson inj_on_diff inj_on_finite) +next + assume "\(set ` Z) \ AD" + then have "Z \ all_tuples AD n" + using assms(2) + by (auto intro: all_tuplesI) + then show "finite Z" + using all_tuples_finite[OF assms(1)] finite_subset + by auto +qed + +lemma proj_out_list: + fixes AD :: "('a :: infinite) set" + and \ :: "nat \ 'a + nat" + and ns :: "nat list" + assumes "finite AD" + shows "\\. ad_agr_list AD (map \ ns) (map (Inl \ \) ns) \ + (\j x. j \ set ns \ \ j = Inl x \ \ j = x)" +proof - + have fin: "finite (AD \ Inl -` set (map \ ns))" + using assms(1) finite_Inl[OF finite_set] + by blast + obtain f where f_def: "inj (f :: nat \ 'a)" + "range f \ UNIV - (AD \ Inl -` set (map \ ns))" + using arb_countable_map[OF fin] + by auto + define \ where "\ = case_sum id f \ \" + have f_out: "\i x. i < length ns \ \ (ns ! i) = Inl (f x) \ False" + using f_def(2) + by (auto simp: vimage_def) + (metis (no_types, lifting) DiffE UNIV_I UnCI imageI image_subset_iff mem_Collect_eq nth_mem) + have "(a, b) \ set (zip (map \ ns) (map (Inl \ \) ns)) \ ad_equiv_pair AD (a, b)" for a b + using f_def(2) + by (auto simp: set_zip \_def ad_equiv_pair.simps split: sum.splits)+ + moreover have "sp_equiv_list (map \ ns) (map (Inl \ \) ns)" + using f_def(1) f_out + by (auto simp: sp_equiv_list_def pairwise_def set_zip \_def inj_def split: sum.splits)+ + ultimately have "ad_agr_list AD (map \ ns) (map (Inl \ \) ns)" + by (auto simp: ad_agr_list_def ad_equiv_list_def) + then show ?thesis + by (auto simp: \_def intro!: exI[of _ \]) +qed + +lemma proj_out: + fixes \ :: "('a :: infinite, 'b) fo_fmla" + and J :: "(('a, nat) fo_t, 'b) fo_intp" + assumes "wf_fo_intp \ I" "esat \ I \ UNIV" + shows "\\. esat \ I (Inl \ \) UNIV \ (\i x. i \ fv_fo_fmla \ \ \ i = Inl x \ \ i = x) \ + ad_agr_list (act_edom \ I) (map \ (fv_fo_fmla_list \)) (map (Inl \ \) (fv_fo_fmla_list \))" + using proj_out_list[OF finite_act_edom[OF assms(1)], of \ "fv_fo_fmla_list \"] + esat_UNIV_ad_agr_list[OF _ subset_refl] assms(2) + unfolding fv_fo_fmla_list_set + by fastforce + +lemma proj_fmla_esat_sat: + fixes \ :: "('a :: infinite, 'b) fo_fmla" + and J :: "(('a, nat) fo_t, 'b) fo_intp" + assumes wf: "wf_fo_intp \ I" + shows "proj_fmla \ {\. esat \ I \ UNIV} \ map Inl ` UNIV = + map Inl ` proj_fmla \ {\. sat \ I \}" + unfolding sat_esat_conv[OF wf] +proof (rule set_eqI, rule iffI) + fix vs + assume "vs \ proj_fmla \ {\. esat \ I \ UNIV} \ map Inl ` UNIV" + then obtain \ where \_def: "vs = map \ (fv_fo_fmla_list \)" "esat \ I \ UNIV" + "set vs \ range Inl" + by (auto simp: proj_fmla_map) (metis image_subset_iff list.set_map range_eqI) + obtain \ where \_def: "esat \ I (Inl \ \) UNIV" + "\i x. i \ fv_fo_fmla \ \ \ i = Inl x \ \ i = x" + using proj_out[OF assms \_def(2)] + by fastforce + have "vs = map (Inl \ \) (fv_fo_fmla_list \)" + using \_def(1,3) \_def(2) + by (auto simp: fv_fo_fmla_list_set) + then show "vs \ map Inl ` proj_fmla \ {\. esat \ I (Inl \ \) UNIV}" + using \_def(1) + by (force simp: proj_fmla_map) +qed (auto simp: proj_fmla_map) + +lemma norm_proj_fmla_esat_sat: + fixes \ :: "('a :: infinite, 'b) fo_fmla" + assumes "wf_fo_intp \ I" + shows "fo_nmlz (act_edom \ I) ` proj_fmla \ {\. esat \ I \ UNIV} = + fo_nmlz (act_edom \ I) ` map Inl ` proj_fmla \ {\. sat \ I \}" +proof - + have "fo_nmlz (act_edom \ I) (map \ (fv_fo_fmla_list \)) = fo_nmlz (act_edom \ I) x" + "x \ (\\. map \ (fv_fo_fmla_list \)) ` {\. esat \ I \ UNIV} \ range (map Inl)" + if "esat \ I \ UNIV" "esat \ I (Inl \ \) UNIV" "x = map (Inl \ \) (fv_fo_fmla_list \)" + "ad_agr_list (act_edom \ I) (map \ (fv_fo_fmla_list \)) (map (Inl \ \) (fv_fo_fmla_list \))" + for \ \ x + using that + by (auto intro!: fo_nmlz_eqI) (metis map_map range_eqI) + then show ?thesis + unfolding proj_fmla_esat_sat[OF assms, symmetric] + using proj_out[OF assms] + by (fastforce simp: image_iff proj_fmla_map) +qed + +lemma proj_sat_fmla: "proj_sat \ I = proj_fmla \ {\. sat \ I \}" + by (auto simp: proj_sat_def proj_fmla_map) + +fun fo_wf :: "('a, 'b) fo_fmla \ ('b \ nat \ 'a list set) \ ('a, nat) fo_t \ bool" where + "fo_wf \ I (AD, n, X) \ finite AD \ finite X \ n = nfv \ \ + wf_fo_intp \ I \ AD = act_edom \ I \ fo_rep (AD, n, X) = proj_sat \ I \ + Inl -` \(set ` X) \ AD \ (\vs \ X. fo_nmlzd AD vs \ length vs = n)" + +fun fo_fin :: "('a, nat) fo_t \ bool" where + "fo_fin (AD, n, X) \ (\x \ \(set ` X). isl x)" + +lemma fo_rep_fin: + assumes "fo_wf \ I (AD, n, X)" "fo_fin (AD, n, X)" + shows "fo_rep (AD, n, X) = map projl ` X" +proof (rule set_eqI, rule iffI) + fix vs + assume "vs \ fo_rep (AD, n, X)" + then obtain xs where xs_def: "xs \ X" "ad_agr_list AD (map Inl vs) xs" + by auto + obtain zs where zs_def: "xs = map Inl zs" + using xs_def(1) assms + by auto (meson ex_map_conv isl_def) + have "set zs \ AD" + using assms(1) xs_def(1) zs_def + by (force simp: vimage_def) + then have vs_zs: "vs = zs" + using xs_def(2) + unfolding zs_def + by (fastforce simp: ad_agr_list_def ad_equiv_list_def set_zip ad_equiv_pair.simps + intro!: nth_equalityI) + show "vs \ map projl ` X" + using xs_def(1) zs_def + by (auto simp: image_iff comp_def vs_zs intro!: bexI[of _ "map Inl zs"]) +next + fix vs + assume "vs \ map projl ` X" + then obtain xs where xs_def: "xs \ X" "vs = map projl xs" + by auto + have xs_map_Inl: "xs = map Inl vs" + using assms xs_def + by (auto simp: map_idI) + show "vs \ fo_rep (AD, n, X)" + using xs_def(1) + by (auto simp: xs_map_Inl intro!: bexI[of _ xs] ad_agr_list_refl) +qed + +definition eval_abs :: "('a, 'b) fo_fmla \ ('a table, 'b) fo_intp \ ('a, nat) fo_t" where + "eval_abs \ I = (act_edom \ I, nfv \, fo_nmlz (act_edom \ I) ` proj_fmla \ {\. esat \ I \ UNIV})" + +lemma map_projl_Inl: "map projl (map Inl xs) = xs" + by (metis (mono_tags, lifting) length_map nth_equalityI nth_map sum.sel(1)) + +lemma fo_rep_eval_abs: + fixes \ :: "('a :: infinite, 'b) fo_fmla" + assumes "wf_fo_intp \ I" + shows "fo_rep (eval_abs \ I) = proj_sat \ I" +proof - + obtain AD n X where AD_X_def: "eval_abs \ I = (AD, n, X)" "AD = act_edom \ I" + "n = nfv \" "X = fo_nmlz (act_edom \ I) ` proj_fmla \ {\. esat \ I \ UNIV}" + by (cases "eval_abs \ I") (auto simp: eval_abs_def) + have AD_sub: "act_edom \ I \ AD" + by (auto simp: AD_X_def) + have X_def: "X = fo_nmlz AD ` map Inl ` proj_fmla \ {\. sat \ I \}" + using AD_X_def norm_proj_fmla_esat_sat[OF assms] + by auto + have "{ts. \ts' \ X. ad_agr_list AD (map Inl ts) ts'} = proj_fmla \ {\. sat \ I \}" + proof (rule set_eqI, rule iffI) + fix vs + assume "vs \ {ts. \ts' \ X. ad_agr_list AD (map Inl ts) ts'}" + then obtain vs' where vs'_def: "vs' \ proj_fmla \ {\. sat \ I \}" + "ad_agr_list AD (map Inl vs) (fo_nmlz AD (map Inl vs'))" + using X_def + by auto + have "length vs = length (fv_fo_fmla_list \)" + using vs'_def + by (auto simp: proj_fmla_map ad_agr_list_def fo_nmlz_length) + then obtain \ where \_def: "vs = map \ (fv_fo_fmla_list \)" + using exists_map[of "fv_fo_fmla_list \" vs] sorted_distinct_fv_list + by fastforce + obtain \ where \_def: "fo_nmlz AD (map Inl vs') = map \ (fv_fo_fmla_list \)" + using vs'_def fo_nmlz_map + by (fastforce simp: proj_fmla_map) + have ad_agr: "ad_agr_list AD (map (Inl \ \) (fv_fo_fmla_list \)) (map \ (fv_fo_fmla_list \))" + by (metis \_def \_def map_map vs'_def(2)) + obtain \' where \'_def: "map Inl vs' = map (Inl \ \') (fv_fo_fmla_list \)" + "sat \ I \'" + using vs'_def(1) + by (fastforce simp: proj_fmla_map) + have ad_agr': "ad_agr_list AD (map \ (fv_fo_fmla_list \)) + (map (Inl \ \') (fv_fo_fmla_list \))" + by (rule ad_agr_list_comm) (metis fo_nmlz_ad_agr \'_def(1) \_def map_map map_projl_Inl) + have esat: "esat \ I \ UNIV" + using esat_UNIV_ad_agr_list[OF ad_agr' AD_sub, folded sat_esat_conv[OF assms]] \'_def(2) + by auto + show "vs \ proj_fmla \ {\. sat \ I \}" + using esat_UNIV_ad_agr_list[OF ad_agr AD_sub, folded sat_esat_conv[OF assms]] esat + unfolding \_def + by (auto simp: proj_fmla_map) + next + fix vs + assume "vs \ proj_fmla \ {\. sat \ I \}" + then have vs_X: "fo_nmlz AD (map Inl vs) \ X" + using X_def + by auto + then show "vs \ {ts. \ts' \ X. ad_agr_list AD (map Inl ts) ts'}" + using fo_nmlz_ad_agr + by auto + qed + then show ?thesis + by (auto simp: AD_X_def proj_sat_fmla) +qed + +lemma fo_wf_eval_abs: + fixes \ :: "('a :: infinite, 'b) fo_fmla" + assumes "wf_fo_intp \ I" + shows "fo_wf \ I (eval_abs \ I)" + using fo_nmlz_set[of "act_edom \ I"] finite_act_edom[OF assms(1)] + finite_subset[OF fo_nmlz_proj_sub, OF nall_tuples_finite] + fo_rep_eval_abs[OF assms] assms + by (auto simp: eval_abs_def fo_nmlz_sound fo_nmlz_length nfv_def proj_sat_def proj_fmla_map) blast + +lemma fo_fin: + fixes t :: "('a :: infinite, nat) fo_t" + assumes "fo_wf \ I t" + shows "fo_fin t = finite (fo_rep t)" +proof - + obtain AD n X where t_def: "t = (AD, n, X)" + using assms + by (cases t) auto + have fin: "finite AD" "finite X" + using assms + by (auto simp: t_def) + have len_in_X: "\vs. vs \ X \ length vs = n" + using assms + by (auto simp: t_def) + have Inl_X_AD: "\x. Inl x \ \(set ` X) \ x \ AD" + using assms + by (fastforce simp: t_def) + define Z where "Z = {ts. \ts' \ X. ad_agr_list AD (map Inl ts) ts'}" + have fin_Z_iff: "finite Z = (\(set ` Z) \ AD)" + using assms fin_ad_agr_list_iff[OF fin(1) _ Z_def, of n] + by (auto simp: Z_def t_def ad_agr_list_def) + moreover have "(\(set ` Z) \ AD) \ (\x \ \(set ` X). isl x)" + proof (rule iffI, rule ccontr) + fix x + assume Z_sub_AD: "\(set ` Z) \ AD" + assume "\(\x \ \(set ` X). isl x)" + then obtain vs i m where vs_def: "vs \ X" "i < n" "vs ! i = Inr m" + using len_in_X + by (auto simp: in_set_conv_nth) (metis sum.collapse(2)) + obtain \ where \_def: "vs = map \ [0.. where \_def: "ad_agr_list AD vs (map Inl (map \ [0.. "[0.._def) + have map_\_in_Z: "map \ [0.. Z" + using vs_def(1) ad_agr_list_comm[OF \_def] + by (auto simp: Z_def) + moreover have "\ i \ AD" + using \_def vs_def(2,3) + apply (auto simp: ad_agr_list_def ad_equiv_list_def set_zip comp_def \_def) + unfolding ad_equiv_pair.simps + by (metis (no_types, lifting) Inl_Inr_False diff_zero image_iff length_upt nth_map nth_upt + plus_nat.add_0) + ultimately show "False" + using vs_def(2) Z_sub_AD + by fastforce + next + assume "\x \ \(set ` X). isl x" + then show "\(set ` Z) \ AD" + using Inl_X_AD + apply (auto simp: Z_def ad_agr_list_def ad_equiv_list_def set_zip in_set_conv_nth) + unfolding ad_equiv_pair.simps + by (metis image_eqI isl_def nth_map nth_mem) + qed + ultimately show ?thesis + by (auto simp: t_def Z_def[symmetric]) +qed + +lemma eval_pred: + fixes I :: "'b \ nat \ 'a :: infinite list set" + assumes "finite (I (r, length ts))" + shows "fo_wf (Pred r ts) I (eval_pred ts (I (r, length ts)))" +proof - + define \ where "\ = Pred r ts" + have nfv_len: "nfv \ = length (fv_fo_terms_list ts)" + by (auto simp: \_def nfv_def fv_fo_fmla_list_def fv_fo_fmla_list_Pred) + have vimage_unfold: "Inl -` (\x\I (r, length ts). Inl ` set x) = \(set ` I (r, length ts))" + by auto + have "eval_table ts (map Inl ` I (r, length ts)) \ nall_tuples (act_edom \ I) (nfv \)" + by (auto simp: \_def proj_vals_def eval_table nfv_len[unfolded \_def] + fo_nmlz_length fo_nmlz_sound eval_eterms_def fv_fo_terms_set_list fv_fo_terms_set_def + vimage_unfold intro!: nall_tuplesI fo_nmlzd_all_AD dest!: fv_fo_term_setD) + (smt UN_I Un_iff eval_eterm.simps(2) imageE image_eqI list.set_map) + then have eval: "eval_pred ts (I (r, length ts)) = eval_abs \ I" + by (force simp: eval_abs_def \_def proj_fmla_def eval_pred_def eval_table fv_fo_fmla_list_def + fv_fo_fmla_list_Pred nall_tuples_set fo_nmlz_idem nfv_len[unfolded \_def]) + have fin: "wf_fo_intp (Pred r ts) I" + using assms + by auto + show ?thesis + using fo_wf_eval_abs[OF fin] + by (auto simp: eval \_def) +qed + +lemma ad_agr_list_eval: "\(set (map set_fo_term ts)) \ AD \ ad_agr_list AD (\ \e ts) zs \ + \\. zs = \ \e ts" +proof (induction ts arbitrary: zs) + case (Cons t ts) + obtain w ws where zs_split: "zs = w # ws" + using Cons(3) + by (cases zs) (auto simp: ad_agr_list_def eval_eterms_def) + obtain \ where \_def: "ws = \ \e ts" + using Cons + by (fastforce simp: zs_split ad_agr_list_def ad_equiv_list_def sp_equiv_list_def pairwise_def + eval_eterms_def) + show ?case + proof (cases t) + case (Const c) + then show ?thesis + using Cons(3)[unfolded zs_split] Cons(2) + unfolding Const + apply (auto simp: zs_split eval_eterms_def \_def ad_agr_list_def ad_equiv_list_def) + unfolding ad_equiv_pair.simps + by blast + next + case (Var n) + show ?thesis + proof (cases "n \ fv_fo_terms_set ts") + case True + obtain i where i_def: "i < length ts" "ts ! i = Var n" + using True + by (auto simp: fv_fo_terms_set_def in_set_conv_nth dest!: fv_fo_term_setD) + have "w = \ n" + using Cons(3)[unfolded zs_split \_def] i_def + using pairwiseD[of sp_equiv_pair _ "(\ n, w)" "(\ \e (ts ! i), \ \e (ts ! i))"] + by (force simp: Var eval_eterms_def ad_agr_list_def sp_equiv_list_def set_zip) + then show ?thesis + by (auto simp: Var zs_split eval_eterms_def \_def) + next + case False + then have "ws = (\(n := w)) \e ts" + using eval_eterms_cong[of ts \ "\(n := w)"] \_def + by fastforce + then show ?thesis + by (auto simp: zs_split eval_eterms_def Var fun_upd_def intro: exI[of _ "\(n := w)"]) + qed + qed +qed (auto simp: ad_agr_list_def eval_eterms_def) + +lemma sp_equiv_list_fv_list: + assumes "sp_equiv_list (\ \e ts) (\ \e ts)" + shows "sp_equiv_list (map \ (fv_fo_terms_list ts)) (map \ (fv_fo_terms_list ts))" +proof - + have "sp_equiv_list (\ \e (map Var (fv_fo_terms_list ts))) + (\ \e (map Var (fv_fo_terms_list ts)))" + unfolding eval_eterms_def + by (rule sp_equiv_list_subset[OF _ assms[unfolded eval_eterms_def]]) + (auto simp: fv_fo_terms_set_list dest: fv_fo_terms_setD) + then show ?thesis + by (auto simp: eval_eterms_def comp_def) +qed + +lemma ad_agr_list_fv_list: "ad_agr_list X (\ \e ts) (\ \e ts) \ + ad_agr_list X (map \ (fv_fo_terms_list ts)) (map \ (fv_fo_terms_list ts))" + using sp_equiv_list_fv_list + by (auto simp: eval_eterms_def ad_agr_list_def ad_equiv_list_def sp_equiv_list_def set_zip) + (metis (no_types, opaque_lifting) eval_eterm.simps(2) fv_fo_terms_setD fv_fo_terms_set_list + in_set_conv_nth nth_map) + +lemma eval_bool: "fo_wf (Bool b) I (eval_bool b)" + by (auto simp: eval_bool_def fo_nmlzd_def nats_def Let_def List.map_filter_simps + proj_sat_def fv_fo_fmla_list_def ad_agr_list_def ad_equiv_list_def sp_equiv_list_def nfv_def) + +lemma eval_eq: fixes I :: "'b \ nat \ 'a :: infinite list set" + shows "fo_wf (Eqa t t') I (eval_eq t t')" +proof - + define \ :: "('a, 'b) fo_fmla" where "\ = Eqa t t'" + obtain AD n X where AD_X_def: "eval_eq t t' = (AD, n, X)" + by (cases "eval_eq t t'") auto + have AD_def: "AD = act_edom \ I" + using AD_X_def + by (auto simp: eval_eq_def \_def split: fo_term.splits if_splits) + have n_def: "n = nfv \" + using AD_X_def + by (cases t; cases t') + (auto simp: \_def fv_fo_fmla_list_def eval_eq_def nfv_def split: if_splits) + have fo_nmlz_empty_x_x: "fo_nmlz {} [x, x] = [Inr 0, Inr 0]" for x :: "'a + nat" + by (cases x) (auto simp: fo_nmlz_def) + have Inr_0_in_fo_nmlz_empty: "[Inr 0, Inr 0] \ fo_nmlz {} ` (\x. [x n', x n']) ` {\ :: nat \ 'a + nat. \ n = \ n'}" for n n' + by (auto simp: image_def fo_nmlz_empty_x_x intro!: exI[of _ "[Inr 0, Inr 0]"]) + have X_def: "X = fo_nmlz AD ` proj_fmla \ {\. esat \ I \ UNIV}" + proof (rule set_eqI, rule iffI) + fix vs + assume assm: "vs \ X" + define pes where "pes = proj_fmla \ {\. esat \ I \ UNIV}" + have "\c c'. t = Const c \ t' = Const c' \ + fo_nmlz AD ` pes = (if c = c' then {[]} else {})" + by (auto simp: \_def pes_def proj_fmla_map fo_nmlz_def fv_fo_fmla_list_def) + moreover have "\c n. (t = Const c \ t' = Var n) \ (t' = Const c \ t = Var n) \ + fo_nmlz AD ` pes = {[Inl c]}" + by (auto simp: \_def AD_def pes_def proj_fmla_map fo_nmlz_Cons fv_fo_fmla_list_def image_def + split: sum.splits) (auto simp: fo_nmlz_def) + moreover have "\n. t = Var n \ t' = Var n \ fo_nmlz AD ` pes = {[Inr 0]}" + by (auto simp: \_def AD_def pes_def proj_fmla_map fo_nmlz_Cons fv_fo_fmla_list_def image_def + split: sum.splits) + moreover have "\n n'. t = Var n \ t' = Var n' \ n \ n' \ + fo_nmlz AD ` pes = {[Inr 0, Inr 0]}" + using Inr_0_in_fo_nmlz_empty + by (auto simp: \_def AD_def pes_def proj_fmla_map fo_nmlz_Cons fv_fo_fmla_list_def fo_nmlz_empty_x_x + split: sum.splits) + ultimately show "vs \ fo_nmlz AD ` pes" + using assm AD_X_def + by (cases t; cases t') (auto simp: eval_eq_def split: if_splits) + next + fix vs + assume assm: "vs \ fo_nmlz AD ` proj_fmla \ {\. esat \ I \ UNIV}" + obtain \ where \_def: "vs = fo_nmlz AD (map \ (fv_fo_fmla_list \))" + "esat (Eqa t t') I \ UNIV" + using assm + by (auto simp: \_def fv_fo_fmla_list_def proj_fmla_map) + show "vs \ X" + using \_def AD_X_def + by (cases t; cases t') + (auto simp: \_def eval_eq_def fv_fo_fmla_list_def fo_nmlz_Cons fo_nmlz_Cons_Cons + split: sum.splits) + qed + have eval: "eval_eq t t' = eval_abs \ I" + using X_def[unfolded AD_def] + by (auto simp: eval_abs_def AD_X_def AD_def n_def) + have fin: "wf_fo_intp \ I" + by (auto simp: \_def) + show ?thesis + using fo_wf_eval_abs[OF fin] + by (auto simp: eval \_def) +qed + +lemma fv_fo_terms_list_Var: "fv_fo_terms_list_rec (map Var ns) = ns" + by (induction ns) auto + +lemma eval_eterms_map_Var: "\ \e map Var ns = map \ ns" + by (auto simp: eval_eterms_def) + +lemma fo_wf_eval_table: + fixes AD :: "'a set" + assumes "fo_wf \ I (AD, n, X)" + shows "X = fo_nmlz AD ` eval_table (map Var [0..(set ` X) \ AD" + using assms + by fastforce + have fvs: "fv_fo_terms_list (map Var [0..vs. vs \ X \ length vs = n" + using assms + by auto + then have X_map: "\vs. vs \ X \ \\. vs = map \ [0... \ \e map Var [0.. X} [0.. I (AD, n, X)" + shows "X = fo_nmlz AD ` map Inl ` fo_rep (AD, n, X)" +proof (rule set_eqI, rule iffI) + fix vs + assume vs_in: "vs \ X" + have fin_AD: "finite AD" + using assms(1) + by auto + have len_vs: "length vs = n" + using vs_in assms(1) + by auto + obtain \ where \_def: "ad_agr_list AD vs (map Inl (map \ [0.._in: "map \ [0.. fo_rep (AD, n, X)" + using vs_in ad_agr_list_comm[OF \_def] + by auto + have "vs = fo_nmlz AD (map Inl (map \ [0.._def] fo_nmlz_idem vs_in assms(1) + by fastforce + then show "vs \ fo_nmlz AD ` map Inl ` fo_rep (AD, n, X)" + using map_\_in + by blast +next + fix vs + assume "vs \ fo_nmlz AD ` map Inl ` fo_rep (AD, n, X)" + then obtain xs xs' where vs_def: "xs' \ X" "ad_agr_list AD (map Inl xs) xs'" + "vs = fo_nmlz AD (map Inl xs)" + by auto + then have "vs = fo_nmlz AD xs'" + using fo_nmlz_eqI[OF vs_def(2)] + by auto + then have "vs = xs'" + using vs_def(1) assms(1) fo_nmlz_idem + by fastforce + then show "vs \ X" + using vs_def(1) + by auto +qed + +lemma fo_wf_X: + fixes \ :: "('a :: infinite, 'b) fo_fmla" + assumes wf: "fo_wf \ I (AD, n, X)" + shows "X = fo_nmlz AD ` proj_fmla \ {\. esat \ I \ UNIV}" +proof - + have fin: "wf_fo_intp \ I" + using wf + by auto + have AD_def: "AD = act_edom \ I" + using wf + by auto + have fo_wf: "fo_wf \ I (AD, n, X)" + using wf + by auto + have fo_rep: "fo_rep (AD, n, X) = proj_fmla \ {\. sat \ I \}" + using wf + by (auto simp: proj_sat_def proj_fmla_map) + show ?thesis + using fo_rep_norm[OF fo_wf] norm_proj_fmla_esat_sat[OF fin] + unfolding fo_rep AD_def[symmetric] + by auto +qed + +lemma eval_neg: + fixes \ :: "('a :: infinite, 'b) fo_fmla" + assumes wf: "fo_wf \ I t" + shows "fo_wf (Neg \) I (eval_neg (fv_fo_fmla_list \) t)" +proof - + obtain AD n X where t_def: "t = (AD, n, X)" + by (cases t) auto + have eval_neg: "eval_neg (fv_fo_fmla_list \) t = (AD, nfv \, nall_tuples AD (nfv \) - X)" + by (auto simp: t_def nfv_def) + have fv_unfold: "fv_fo_fmla_list (Neg \) = fv_fo_fmla_list \" + by (auto simp: fv_fo_fmla_list_def) + then have nfv_unfold: "nfv (Neg \) = nfv \" + by (auto simp: nfv_def) + have AD_def: "AD = act_edom (Neg \) I" + using wf + by (auto simp: t_def) + note X_def = fo_wf_X[OF wf[unfolded t_def]] + have esat_iff: "\vs. vs \ nall_tuples AD (nfv \) \ + vs \ fo_nmlz AD ` proj_fmla \ {\. esat \ I \ UNIV} \ + vs \ fo_nmlz AD ` proj_fmla \ {\. esat (Neg \) I \ UNIV}" + proof (rule iffI; rule ccontr) + fix vs + assume "vs \ fo_nmlz AD ` proj_fmla \ {\. esat \ I \ UNIV}" + then obtain \ where \_def: "vs = fo_nmlz AD (map \ (fv_fo_fmla_list \))" + "esat \ I \ UNIV" + by (auto simp: proj_fmla_map) + assume "\vs \ fo_nmlz AD ` proj_fmla \ {\. esat (Neg \) I \ UNIV}" + then obtain \' where \'_def: "vs = fo_nmlz AD (map \' (fv_fo_fmla_list \))" + "esat (Neg \) I \' UNIV" + by (auto simp: proj_fmla_map) + have "esat \ I \ UNIV = esat \ I \' UNIV" + using esat_UNIV_cong[OF ad_agr_sets_restrict[OF iffD2[OF ad_agr_list_link], + OF fo_nmlz_eqD[OF trans[OF \_def(1)[symmetric] \'_def(1)]]]] + by (auto simp: AD_def) + then show "False" + using \_def(2) \'_def(2) by simp + next + fix vs + assume assms: "vs \ fo_nmlz AD ` proj_fmla \ {\. esat (Neg \) I \ UNIV}" + "vs \ fo_nmlz AD ` proj_fmla \ {\. esat \ I \ UNIV}" + assume "vs \ nall_tuples AD (nfv \)" + then have l_vs: "length vs = length (fv_fo_fmla_list \)" "fo_nmlzd AD vs" + by (auto simp: nfv_def dest: nall_tuplesD) + obtain \ where "vs = fo_nmlz AD (map \ (fv_fo_fmla_list \))" + using l_vs sorted_distinct_fv_list exists_fo_nmlzd by metis + with assms show "False" + by (auto simp: proj_fmla_map) + qed + moreover have "\R. fo_nmlz AD ` proj_fmla \ R \ nall_tuples AD (nfv \)" + by (auto simp: proj_fmla_map nfv_def nall_tuplesI fo_nmlz_length fo_nmlz_sound) + ultimately have eval: "eval_neg (fv_fo_fmla_list \) t = eval_abs (Neg \) I" + unfolding eval_neg eval_abs_def AD_def[symmetric] + by (auto simp: X_def proj_fmla_def fv_unfold nfv_unfold image_subset_iff) + have wf_neg: "wf_fo_intp (Neg \) I" + using wf + by (auto simp: t_def) + show ?thesis + using fo_wf_eval_abs[OF wf_neg] + by (auto simp: eval) +qed + +definition "cross_with f t t' = \((\xs. \(f xs ` t')) ` t)" + +lemma mapping_join_cross_with: + assumes "\x x'. x \ t \ x' \ t' \ h x \ h' x' \ f x x' = {}" + shows "set_of_idx (mapping_join (cross_with f) (cluster (Some \ h) t) (cluster (Some \ h') t')) = cross_with f t t'" +proof - + have sub: "cross_with f {y \ t. h y = h x} {y \ t'. h' y = h x} \ cross_with f t t'" for t t' x + by (auto simp: cross_with_def) + have "\a. a \ h ` t \ a \ h' ` t' \ z \ cross_with f {y \ t. h y = a} {y \ t'. h' y = a}" if z: "z \ cross_with f t t'" for z + proof - + obtain xs ys where wit: "xs \ t" "ys \ t'" "z \ f xs ys" + using z + by (auto simp: cross_with_def) + have h: "h xs = h' ys" + using assms(1)[OF wit(1-2)] wit(3) + by auto + have hys: "h' ys \ h ` t" + using wit(1) + by (auto simp: h[symmetric]) + show ?thesis + apply (rule exI[of _ "h xs"]) + using wit hys h + by (auto simp: cross_with_def) + qed + then show ?thesis + using sub + apply (transfer fixing: f h h') + apply (auto simp: ran_def) + apply fastforce+ + done +qed + +lemma fo_nmlzd_mono_sub: "X \ X' \ fo_nmlzd X xs \ fo_nmlzd X' xs" + by (meson fo_nmlzd_def order_trans) + +lemma idx_join: + assumes X\_props: "\vs. vs \ X\ \ fo_nmlzd AD vs \ length vs = length ns\" + assumes X\_props: "\vs. vs \ X\ \ fo_nmlzd AD vs \ length vs = length ns\" + assumes sd_ns: "sorted_distinct ns\" "sorted_distinct ns\" + assumes ns_def: "ns = filter (\n. n \ set ns\) ns\" + shows "idx_join AD ns ns\ X\ ns\ X\ = eval_conj_set AD ns\ X\ ns\ X\" +proof - + have ect_empty: "x \ X\ \ x' \ X\ \ fo_nmlz AD (proj_tuple ns (zip ns\ x)) \ fo_nmlz AD (proj_tuple ns (zip ns\ x')) \ + eval_conj_tuple AD ns\ ns\ x x' = {}" + if "X\' \ X\" "X\' \ X\" for X\' X\' and x x' + apply (rule eval_conj_tuple_empty[where ?ns="filter (\n. n \ set ns\) ns\"]) + using X\_props X\_props that sd_ns + by (auto simp: ns_def ad_agr_close_set_def split: if_splits) + have cross_eval_conj_tuple: "(\X\''. eval_conj_set AD ns\ X\'' ns\) = cross_with (eval_conj_tuple AD ns\ ns\)" for AD :: "'a set" and ns\ ns\ + by (rule ext)+ (auto simp: eval_conj_set_def cross_with_def) + have "idx_join AD ns ns\ X\ ns\ X\ = cross_with (eval_conj_tuple AD ns\ ns\) X\ X\" + unfolding idx_join_def Let_def cross_eval_conj_tuple + by (rule mapping_join_cross_with[OF ect_empty]) auto + moreover have "\ = eval_conj_set AD ns\ X\ ns\ X\" + by (auto simp: cross_with_def eval_conj_set_def) + finally show ?thesis . +qed + +lemma proj_fmla_conj_sub: + assumes AD_sub: "act_edom \ I \ AD" + shows "fo_nmlz AD ` proj_fmla (Conj \ \) {\. esat \ I \ UNIV} \ + fo_nmlz AD ` proj_fmla (Conj \ \) {\. esat \ I \ UNIV} \ + fo_nmlz AD ` proj_fmla (Conj \ \) {\. esat (Conj \ \) I \ UNIV}" +proof (rule subsetI) + fix vs + assume "vs \ fo_nmlz AD ` proj_fmla (Conj \ \) {\. esat \ I \ UNIV} \ + fo_nmlz AD ` proj_fmla (Conj \ \) {\. esat \ I \ UNIV}" + then obtain \ \' where \_def: + "\ \ {\. esat \ I \ UNIV}" "vs = fo_nmlz AD (map \ (fv_fo_fmla_list (Conj \ \)))" + "\' \ {\. esat \ I \ UNIV}" "vs = fo_nmlz AD (map \' (fv_fo_fmla_list (Conj \ \)))" + unfolding proj_fmla_map + by blast + have ad_sub: "act_edom \ I \ AD" + using assms(1) + by auto + have ad_agr: "ad_agr_list AD (map \ (fv_fo_fmla_list \)) (map \' (fv_fo_fmla_list \))" + by (rule ad_agr_list_subset[OF _ fo_nmlz_eqD[OF trans[OF \_def(2)[symmetric] \_def(4)]]]) + (auto simp: fv_fo_fmla_list_set) + have "\ \ {\. esat \ I \ UNIV}" + using esat_UNIV_cong[OF ad_agr_sets_restrict[OF iffD2[OF ad_agr_list_link]], + OF ad_agr ad_sub] \_def(3) + by blast + then show "vs \ fo_nmlz AD ` proj_fmla (Conj \ \) {\. esat (Conj \ \) I \ UNIV}" + using \_def(1,2) + by (auto simp: proj_fmla_map) +qed + +lemma eval_conj: + fixes \ :: "('a :: infinite, 'b) fo_fmla" + assumes wf: "fo_wf \ I t\" "fo_wf \ I t\" + shows "fo_wf (Conj \ \) I (eval_conj (fv_fo_fmla_list \) t\ (fv_fo_fmla_list \) t\)" +proof - + obtain AD\ n\ X\ AD\ n\ X\ where ts_def: + "t\ = (AD\, n\, X\)" "t\ = (AD\, n\, X\)" + "AD\ = act_edom \ I" "AD\ = act_edom \ I" + using assms + by (cases t\, cases t\) auto + have AD_sub: "act_edom \ I \ AD\" "act_edom \ I \ AD\" + by (auto simp: ts_def(3,4)) + + obtain AD n X where AD_X_def: + "eval_conj (fv_fo_fmla_list \) t\ (fv_fo_fmla_list \) t\ = (AD, n, X)" + by (cases "eval_conj (fv_fo_fmla_list \) t\ (fv_fo_fmla_list \) t\") auto + have AD_def: "AD = act_edom (Conj \ \) I" "act_edom (Conj \ \) I \ AD" + "AD\ \ AD" "AD\ \ AD" "AD = AD\ \ AD\" + using AD_X_def + by (auto simp: ts_def Let_def) + have n_def: "n = nfv (Conj \ \)" + using AD_X_def + by (auto simp: ts_def Let_def nfv_card fv_fo_fmla_list_set) + + define S\ where "S\ \ {\. esat \ I \ UNIV}" + define S\ where "S\ \ {\. esat \ I \ UNIV}" + define AD\\ where "AD\\ = AD - AD\" + define AD\\ where "AD\\ = AD - AD\" + define ns\ where "ns\ = fv_fo_fmla_list \" + define ns\ where "ns\ = fv_fo_fmla_list \" + define ns where "ns = filter (\n. n \ fv_fo_fmla \) (fv_fo_fmla_list \)" + define ns\' where "ns\' = filter (\n. n \ fv_fo_fmla \) (fv_fo_fmla_list \)" + define ns\' where "ns\' = filter (\n. n \ fv_fo_fmla \) (fv_fo_fmla_list \)" + + note X\_def = fo_wf_X[OF wf(1)[unfolded ts_def(1)], unfolded proj_fmla_def, folded S\_def] + note X\_def = fo_wf_X[OF wf(2)[unfolded ts_def(2)], unfolded proj_fmla_def, folded S\_def] + + have sd_ns: "sorted_distinct ns\" "sorted_distinct ns\" + by (auto simp: ns\_def ns\_def sorted_distinct_fv_list) + have ad_agr_X\: "ad_agr_close_set AD\\ X\ = fo_nmlz AD ` proj_vals S\ ns\" + unfolding X\_def ad_agr_close_set_nmlz_eq ns\_def[symmetric] AD\\_def + apply (rule ad_agr_close_set_correct[OF AD_def(3) sd_ns(1)]) + using AD_sub(1) esat_UNIV_ad_agr_list + by (fastforce simp: ad_agr_list_link S\_def ns\_def) + have ad_agr_X\: "ad_agr_close_set AD\\ X\ = fo_nmlz AD ` proj_vals S\ ns\" + unfolding X\_def ad_agr_close_set_nmlz_eq ns\_def[symmetric] AD\\_def + apply (rule ad_agr_close_set_correct[OF AD_def(4) sd_ns(2)]) + using AD_sub(2) esat_UNIV_ad_agr_list + by (fastforce simp: ad_agr_list_link S\_def ns\_def) + + have idx_join_eval_conj: "idx_join AD (filter (\n. n \ set ns\) ns\) ns\ (ad_agr_close_set AD\\ X\) ns\ (ad_agr_close_set AD\\ X\) = + eval_conj_set AD ns\ (ad_agr_close_set AD\\ X\) ns\ (ad_agr_close_set AD\\ X\)" + apply (rule idx_join[OF _ _ sd_ns]) + unfolding ad_agr_X\ ad_agr_X\ + by (auto simp: fo_nmlz_sound fo_nmlz_length proj_vals_def) + + have fv_sub: "fv_fo_fmla (Conj \ \) = fv_fo_fmla \ \ set (fv_fo_fmla_list \)" + "fv_fo_fmla (Conj \ \) = fv_fo_fmla \ \ set (fv_fo_fmla_list \)" + by (auto simp: fv_fo_fmla_list_set) + note res_left_alt = ext_tuple_ad_agr_close[OF S\_def AD_sub(1) AD_def(3) + X\_def(1)[folded S\_def] ns\'_def sorted_distinct_fv_list fv_sub(1)] + note res_right_alt = ext_tuple_ad_agr_close[OF S\_def AD_sub(2) AD_def(4) + X\_def(1)[folded S\_def] ns\'_def sorted_distinct_fv_list fv_sub(2)] + + note eval_conj_set = eval_conj_set_correct[OF ns\'_def[folded fv_fo_fmla_list_set] + ns\'_def[folded fv_fo_fmla_list_set] res_left_alt(2) res_right_alt(2) + sorted_distinct_fv_list sorted_distinct_fv_list] + have "X = fo_nmlz AD ` proj_fmla (Conj \ \) {\. esat \ I \ UNIV} \ + fo_nmlz AD ` proj_fmla (Conj \ \) {\. esat \ I \ UNIV}" + using AD_X_def + apply (simp add: ts_def(1,2) Let_def ts_def(3,4)[symmetric] AD_def(5)[symmetric] idx_join_eval_conj[unfolded ns\_def ns\_def AD\\_def AD\\_def]) + unfolding eval_conj_set proj_fmla_def + unfolding res_left_alt(1) res_right_alt(1) S\_def S\_def + by auto + then have eval: "eval_conj (fv_fo_fmla_list \) t\ (fv_fo_fmla_list \) t\ = + eval_abs (Conj \ \) I" + using proj_fmla_conj_sub[OF AD_def(4)[unfolded ts_def(4)], of \] + unfolding AD_X_def AD_def(1)[symmetric] n_def eval_abs_def + by (auto simp: proj_fmla_map) + have wf_conj: "wf_fo_intp (Conj \ \) I" + using wf + by (auto simp: ts_def) + show ?thesis + using fo_wf_eval_abs[OF wf_conj] + by (auto simp: eval) +qed + +lemma map_values_cluster: "(\w z Z. Z \ X \ z \ Z \ w \ f (h z) {z} \ w \ f (h z) Z) \ + (\w z Z. Z \ X \ z \ Z \ w \ f (h z) Z \ (\z'\Z. w \ f (h z) {z'})) \ + set_of_idx (Mapping.map_values f (cluster (Some \ h) X)) = \((\x. f (h x) {x}) ` X)" + apply transfer + apply (auto simp: ran_def) + apply (smt (verit, del_insts) mem_Collect_eq subset_eq) + apply (smt (z3) imageI mem_Collect_eq subset_iff) + done + +lemma fo_nmlz_twice: + assumes "sorted_distinct ns" "sorted_distinct ns'" "set ns \ set ns'" + shows "fo_nmlz AD (proj_tuple ns (zip ns' (fo_nmlz AD (map \ ns')))) = fo_nmlz AD (map \ ns)" +proof - + obtain \' where \': "fo_nmlz AD (map \ ns') = map \' ns'" + using exists_map[where ?ys="fo_nmlz AD (map \ ns')" and ?xs=ns'] assms + by (auto simp: fo_nmlz_length) + have proj: "proj_tuple ns (zip ns' (map \' ns')) = map \' ns" + by (rule proj_tuple_map[OF assms]) + show ?thesis + unfolding \' proj + apply (rule fo_nmlz_eqI) + using \' + by (metis ad_agr_list_comm ad_agr_list_subset assms(3) fo_nmlz_ad_agr) +qed + +lemma map_values_cong: + assumes "\x y. Mapping.lookup t x = Some y \ f x y = f' x y" + shows "Mapping.map_values f t = Mapping.map_values f' t" +proof - + have "map_option (f x) (Mapping.lookup t x) = map_option (f' x) (Mapping.lookup t x)" for x + using assms + by (cases "Mapping.lookup t x") auto + then show ?thesis + by (auto simp: lookup_map_values intro!: mapping_eqI) +qed + +lemma ad_agr_close_set_length: "z \ ad_agr_close_set AD X \ (\x. x \ X \ length x = n) \ length z = n" + by (auto simp: ad_agr_close_set_def ad_agr_close_def split: if_splits dest: ad_agr_close_rec_length) + +lemma ad_agr_close_set_sound: "z \ ad_agr_close_set (AD - AD') X \ (\x. x \ X \ fo_nmlzd AD' x) \ AD' \ AD \ fo_nmlzd AD z" + using ad_agr_close_sound[where ?X=AD' and ?Y="AD - AD'"] + by (auto simp: ad_agr_close_set_def Set.is_empty_def split: if_splits) (metis Diff_partition Un_Diff_cancel) + +lemma ext_tuple_set_length: "z \ ext_tuple_set AD ns ns' X \ (\x. x \ X \ length x = length ns) \ length z = length ns + length ns'" + by (auto simp: ext_tuple_set_def ext_tuple_def fo_nmlz_length merge_length dest: nall_tuples_rec_length split: if_splits) + +lemma eval_ajoin: + fixes \ :: "('a :: infinite, 'b) fo_fmla" + assumes wf: "fo_wf \ I t\" "fo_wf \ I t\" + shows "fo_wf (Conj \ (Neg \)) I + (eval_ajoin (fv_fo_fmla_list \) t\ (fv_fo_fmla_list \) t\)" +proof - + obtain AD\ n\ X\ AD\ n\ X\ where ts_def: + "t\ = (AD\, n\, X\)" "t\ = (AD\, n\, X\)" + "AD\ = act_edom \ I" "AD\ = act_edom \ I" + using assms + by (cases t\, cases t\) auto + have AD_sub: "act_edom \ I \ AD\" "act_edom \ I \ AD\" + by (auto simp: ts_def(3,4)) + + obtain AD n X where AD_X_def: + "eval_ajoin (fv_fo_fmla_list \) t\ (fv_fo_fmla_list \) t\ = (AD, n, X)" + by (cases "eval_ajoin (fv_fo_fmla_list \) t\ (fv_fo_fmla_list \) t\") auto + have AD_def: "AD = act_edom (Conj \ (Neg \)) I" + "act_edom (Conj \ (Neg \)) I \ AD" "AD\ \ AD" "AD\ \ AD" "AD = AD\ \ AD\" + using AD_X_def + by (auto simp: ts_def Let_def) + have n_def: "n = nfv (Conj \ (Neg \))" + using AD_X_def + by (auto simp: ts_def Let_def nfv_card fv_fo_fmla_list_set) + + define S\ where "S\ \ {\. esat \ I \ UNIV}" + define S\ where "S\ \ {\. esat \ I \ UNIV}" + define both where "both = remdups_adj (sort (fv_fo_fmla_list \ @ fv_fo_fmla_list \))" + define ns\' where "ns\' = filter (\n. n \ fv_fo_fmla \) (fv_fo_fmla_list \)" + define ns\' where "ns\' = filter (\n. n \ fv_fo_fmla \) (fv_fo_fmla_list \)" + + define AD\\ where "AD\\ = AD - AD\" + define AD\\ where "AD\\ = AD - AD\" + define ns\ where "ns\ = fv_fo_fmla_list \" + define ns\ where "ns\ = fv_fo_fmla_list \" + define ns where "ns = filter (\n. n \ set ns\) ns\" + define X\' where "X\' = ext_tuple_set AD ns\ ns\' (ad_agr_close_set AD\\ X\)" + define idx\ where "idx\ = cluster (Some \ (\xs. fo_nmlz AD\ (proj_tuple ns (zip ns\ xs)))) (ad_agr_close_set AD\\ X\)" + define idx\ where "idx\ = cluster (Some \ (\ys. fo_nmlz AD\ (proj_tuple ns (zip ns\ ys)))) X\" + define res where "res = Mapping.map_values (\xs X. case Mapping.lookup idx\ xs of + Some Y \ eval_conj_set AD ns\ X ns\ (ad_agr_close_set AD\\ (ext_tuple_set AD\ ns ns\' {xs} - Y)) + | _ \ ext_tuple_set AD ns\ ns\' X) idx\" + + note X\_def = fo_wf_X[OF wf(1)[unfolded ts_def(1)], unfolded proj_fmla_def, folded S\_def] + note X\_def = fo_wf_X[OF wf(2)[unfolded ts_def(2)], unfolded proj_fmla_def, folded S\_def] + + have fv_sub: "fv_fo_fmla (Conj \ (Neg \)) = fv_fo_fmla \ \ set (fv_fo_fmla_list \)" + by (auto simp: fv_fo_fmla_list_set) + have fv_sort: "fv_fo_fmla_list (Conj \ (Neg \)) = both" + unfolding both_def + apply (rule sorted_distinct_set_unique) + using sorted_distinct_fv_list + by (auto simp: fv_fo_fmla_list_def distinct_remdups_adj_sort) + + have AD_disj: "AD\ \ AD\\ = {}" "AD\ \ AD\\ = {}" + by (auto simp: AD\\_def AD\\_def) + have AD_delta: "AD = AD\ \ AD\\" "AD = AD\ \ AD\\" + by (auto simp: AD\\_def AD\\_def AD_def ts_def) + have fo_nmlzd_X: "Ball X\ (fo_nmlzd AD\)" "Ball X\ (fo_nmlzd AD\)" + using wf + by (auto simp: ts_def) + have Ball_ad_agr: "Ball (ad_agr_close_set AD\\ X\) (fo_nmlzd AD)" + using ad_agr_close_sound[where ?X="AD\" and ?Y="AD\\"] fo_nmlzd_X(1) + by (auto simp: ad_agr_close_set_eq[OF fo_nmlzd_X(1)] AD_disj AD_delta) + have ad_agr_\: + "\\ \. ad_agr_sets (set (fv_fo_fmla_list \)) (set (fv_fo_fmla_list \)) AD\ \ \ \ \ \ S\ \ \ \ S\" + "\\ \. ad_agr_sets (set (fv_fo_fmla_list \)) (set (fv_fo_fmla_list \)) AD \ \ \ \ \ S\ \ \ \ S\" + using esat_UNIV_cong[OF ad_agr_sets_restrict, OF _ subset_refl] ad_agr_sets_mono AD_sub(1) subset_trans[OF AD_sub(1) AD_def(3)] + unfolding S\_def + by blast+ + have ad_agr_S\: "\' \ S\ \ ad_agr_list AD\ (map \' ns\) (map \'' ns\) \ \'' \ S\" for \' \'' + using ad_agr_\ + by (auto simp: ad_agr_list_link ns\_def) + have ad_agr_\: + "\\ \. ad_agr_sets (set (fv_fo_fmla_list \)) (set (fv_fo_fmla_list \)) AD\ \ \ \ \ \ S\ \ \ \ S\" + using esat_UNIV_cong[OF ad_agr_sets_restrict, OF _ subset_refl] ad_agr_sets_mono[OF AD_sub(2)] + unfolding S\_def + by blast+ + have ad_agr_S\: "\' \ S\ \ ad_agr_list AD\ (map \' ns\) (map \'' ns\) \ \'' \ S\" for \' \'' + using ad_agr_\ + by (auto simp: ad_agr_list_link ns\_def) + have aux: "sorted_distinct ns\" "sorted_distinct ns\'" "sorted_distinct both" "set ns\ \ set ns\' = {}" "set ns\ \ set ns\' = set both" + by (auto simp: ns\_def ns\'_def fv_sort[symmetric] fv_fo_fmla_list_set sorted_distinct_fv_list intro: sorted_filter[where ?f=id, simplified]) + have aux2: "ns\' = filter (\n. n \ set ns\) ns\'" "ns\ = filter (\n. n \ set ns\') ns\" + by (auto simp: ns\_def ns\'_def ns\_def ns\'_def fv_fo_fmla_list_set) + have aux3: "set ns\' \ set ns = {}" "set ns\' \ set ns = set ns\" + by (auto simp: ns\_def ns\'_def ns\_def ns_def fv_fo_fmla_list_set) + have aux4: "set ns \ set ns\' = {}" "set ns \ set ns\' = set ns\" + by (auto simp: ns\_def ns\'_def ns\_def ns_def fv_fo_fmla_list_set) + have aux5: "ns\' = filter (\n. n \ set ns\) ns\" "ns\' = filter (\n. n \ set ns\) ns\" + by (auto simp: ns\_def ns\'_def ns\_def ns\'_def fv_fo_fmla_list_set) + have aux6: "set ns\ \ set ns\' = {}" "set ns\ \ set ns\' = set both" + by (auto simp: ns\_def ns\'_def ns\_def ns\'_def both_def fv_fo_fmla_list_set) + have ns_sd: "sorted_distinct ns" "sorted_distinct ns\" "sorted_distinct ns\" "set ns \ set ns\" "set ns \ set ns\" "set ns \ set both" "set ns\' \ set ns\" "set ns\ \ set both" + by (auto simp: ns_def ns\_def ns\'_def ns\_def both_def sorted_distinct_fv_list intro: sorted_filter[where ?f=id, simplified]) + have ns_sd': "sorted_distinct ns\'" + by (auto simp: ns\'_def sorted_distinct_fv_list intro: sorted_filter[where ?f=id, simplified]) + have ns: "ns = filter (\n. n \ fv_fo_fmla \) (fv_fo_fmla_list \)" + by (rule sorted_distinct_set_unique) + (auto simp: ns_def ns\_def ns\_def fv_fo_fmla_list_set sorted_distinct_fv_list intro: sorted_filter[where ?f=id, simplified]) + have len_ns\: "length ns + length ns\' = length ns\" + using sum_length_filter_compl[where ?P="\n. n \ fv_fo_fmla \" and ?xs="fv_fo_fmla_list \"] + by (auto simp: ns ns\_def ns\'_def ns\_def fv_fo_fmla_list_set) + + have res_eq: "res = Mapping.map_values (\xs X. case Mapping.lookup idx\ xs of + Some Y \ idx_join AD ns ns\ X ns\ (ad_agr_close_set AD\\ (ext_tuple_set AD\ ns ns\' {xs} - Y)) + | _ \ ext_tuple_set AD ns\ ns\' X) idx\" + proof - + have ad_agr_X\: "ad_agr_close_set AD\\ X\ = fo_nmlz AD ` proj_vals S\ ns\" + unfolding X\_def ad_agr_close_set_nmlz_eq ns\_def[symmetric] + apply (rule ad_agr_close_set_correct[OF AD_def(3) aux(1), folded AD\\_def]) + using ad_agr_S\ ad_agr_list_comm + by (fastforce simp: ad_agr_list_link) + have idx_eval: "idx_join AD ns ns\ y ns\ (ad_agr_close_set AD\\ (ext_tuple_set AD\ ns ns\' {x} - x2)) = + eval_conj_set AD ns\ y ns\ (ad_agr_close_set AD\\ (ext_tuple_set AD\ ns ns\' {x} - x2))" + if lup: "Mapping.lookup idx\ x = Some y" "Mapping.lookup idx\ x = Some x2" for x y x2 + proof - + have "vs \ y \ fo_nmlzd AD vs \ length vs = length ns\" for vs + using lup(1) + by (auto simp: idx\_def lookup_cluster' ad_agr_X\ fo_nmlz_sound fo_nmlz_length proj_vals_def split: if_splits) + moreover have "vs \ ad_agr_close_set AD\\ (ext_tuple_set AD\ ns ns\' {x} - x2) \ fo_nmlzd AD vs" for vs + apply (rule ad_agr_close_set_sound[OF _ _ AD_def(4), folded AD\\_def, where ?X="ext_tuple_set AD\ ns ns\' {x} - x2"]) + using lup(1) + by (auto simp: idx\_def lookup_cluster' ext_tuple_set_def fo_nmlz_sound split: if_splits) + moreover have "vs \ ad_agr_close_set AD\\ (ext_tuple_set AD\ ns ns\' {x} - x2) \ length vs = length ns\" for vs + apply (erule ad_agr_close_set_length) + apply (rule ext_tuple_set_length[where ?AD=AD\ and ?ns=ns and ?ns'=ns\' and ?X="{x}", unfolded len_ns\]) + using lup(1) ns_sd(1,2,4) + by (auto simp: idx\_def lookup_cluster' fo_nmlz_length ad_agr_X\ proj_vals_def intro!: proj_tuple_length split: if_splits) + ultimately show ?thesis + by (auto intro!: idx_join[OF _ _ ns_sd(2-3) ns_def]) + qed + show ?thesis + unfolding res_def + by (rule map_values_cong) (auto simp: idx_eval split: option.splits) + qed + + have eval_conj: "eval_conj_set AD ns\ {x} ns\ (ad_agr_close_set AD\\ (ext_tuple_set AD\ ns ns\' {fo_nmlz AD\ (proj_tuple ns (zip ns\ x))} - Y)) = + ext_tuple_set AD ns\ ns\' {x} \ ext_tuple_set AD ns\ ns\' (fo_nmlz AD ` proj_vals {\ \ - S\. ad_agr_list AD\ (map \ ns) (map \' ns)} ns\)" + if x_ns: "proj_tuple ns (zip ns\ x) = map \' ns" + and x_proj_singleton: "{x} = fo_nmlz AD ` proj_vals {\} ns\" + and Some: "Mapping.lookup idx\ (fo_nmlz AD\ (proj_tuple ns (zip ns\ x))) = Some Y" + for x Y \ \' + proof - + have "Y = {ys \ fo_nmlz AD\ ` proj_vals S\ ns\. fo_nmlz AD\ (proj_tuple ns (zip ns\ ys)) = fo_nmlz AD\ (map \' ns)}" + using Some + apply (auto simp: X\_def idx\_def ns\_def x_ns lookup_cluster' split: if_splits) + done + moreover have "\ = fo_nmlz AD\ ` proj_vals {\ \ S\. fo_nmlz AD\ (map \ ns) = fo_nmlz AD\ (map \' ns)} ns\" + by (auto simp: proj_vals_def fo_nmlz_twice[OF ns_sd(1,3,5)])+ + moreover have "\ = fo_nmlz AD\ ` proj_vals {\ \ S\. ad_agr_list AD\ (map \ ns) (map \' ns)} ns\" + by (auto simp: fo_nmlz_eq) + ultimately have Y_def: "Y = fo_nmlz AD\ ` proj_vals {\ \ S\. ad_agr_list AD\ (map \ ns) (map \' ns)} ns\" + by auto + have R_def: "{fo_nmlz AD\ (map \' ns)} = fo_nmlz AD\ ` proj_vals {\. ad_agr_list AD\ (map \ ns) (map \' ns)} ns" + using ad_agr_list_refl + by (auto simp: proj_vals_def intro: fo_nmlz_eqI) + have "ext_tuple_set AD\ ns ns\' {fo_nmlz AD\ (map \' ns)} = fo_nmlz AD\ ` proj_vals {\. ad_agr_list AD\ (map \ ns) (map \' ns)} ns\" + apply (rule ext_tuple_correct[OF ns_sd(1) aux(2) ns_sd(3) aux4 R_def]) + using ad_agr_list_trans ad_agr_list_comm + apply (auto simp: ad_agr_list_link) + by fast + then have "ext_tuple_set AD\ ns ns\' {fo_nmlz AD\ (map \' ns)} - Y = fo_nmlz AD\ ` proj_vals {\ \ -S\. ad_agr_list AD\ (map \ ns) (map \' ns)} ns\" + apply (auto simp: Y_def proj_vals_def fo_nmlz_eq) + using ad_agr_S\ ad_agr_list_comm + by blast+ + moreover have "ad_agr_close_set AD\\ (fo_nmlz AD\ ` proj_vals {\ \ -S\. ad_agr_list AD\ (map \ ns) (map \' ns)} ns\) = + fo_nmlz AD ` proj_vals {\ \ -S\. ad_agr_list AD\ (map \ ns) (map \' ns)} ns\" + unfolding ad_agr_close_set_eq[OF Ball_fo_nmlzd] + apply (rule ad_agr_close_set_correct[OF AD_def(4) ns_sd(3), folded AD\\_def]) + apply (auto simp: ad_agr_list_link) + using ad_agr_S\ ad_agr_list_comm ad_agr_list_subset[OF ns_sd(5)] ad_agr_list_trans + by blast+ + ultimately have comp_proj: "ad_agr_close_set AD\\ (ext_tuple_set AD\ ns ns\' {fo_nmlz AD\ (map \' ns)} - Y) = + fo_nmlz AD ` proj_vals {\ \ -S\. ad_agr_list AD\ (map \ ns) (map \' ns)} ns\" + by simp + have "ext_tuple_set AD ns\ ns\' (fo_nmlz AD ` proj_vals {\ \ - S\. ad_agr_list AD\ (map \ ns) (map \' ns)} ns\) = fo_nmlz AD ` proj_vals {\ \ - S\. ad_agr_list AD\ (map \ ns) (map \' ns)} both" + apply (rule ext_tuple_correct[OF ns_sd(3) ns_sd'(1) aux(3) aux6 refl]) + apply (auto simp: ad_agr_list_link) + using ad_agr_S\ ad_agr_list_comm ad_agr_list_subset[OF ns_sd(5)] ad_agr_list_trans ad_agr_list_mono[OF AD_def(4)] + by fast+ + show "eval_conj_set AD ns\ {x} ns\ (ad_agr_close_set AD\\ (ext_tuple_set AD\ ns ns\' {fo_nmlz AD\ (proj_tuple ns (zip ns\ x))} - Y)) = + ext_tuple_set AD ns\ ns\' {x} \ ext_tuple_set AD ns\ ns\' (fo_nmlz AD ` proj_vals {\ \ - S\. ad_agr_list AD\ (map \ ns) (map \' ns)} ns\)" + unfolding x_ns comp_proj + using eval_conj_set_correct[OF aux5 x_proj_singleton refl aux(1) ns_sd(3)] + by auto + qed + + have "X = set_of_idx res" + using AD_X_def + unfolding eval_ajoin.simps ts_def(1,2) Let_def AD_def(5)[symmetric] fv_fo_fmla_list_set + ns\'_def[symmetric] fv_sort[symmetric] proj_fmla_def S\_def[symmetric] S\_def[symmetric] + AD\\_def[symmetric] AD\\_def[symmetric] + ns\_def[symmetric] ns\'_def[symmetric, folded fv_fo_fmla_list_set[of \, folded ns\_def] ns\_def] ns\_def[symmetric] ns_def[symmetric] + X\'_def[symmetric] idx\_def[symmetric] idx\_def[symmetric] res_eq[symmetric] + by auto + moreover have "\ = (\x\ad_agr_close_set AD\\ X\. + case Mapping.lookup idx\ (fo_nmlz AD\ (proj_tuple ns (zip ns\ x))) of None \ ext_tuple_set AD ns\ ns\' {x} + | Some Y \ eval_conj_set AD ns\ {x} ns\ (ad_agr_close_set AD\\ (ext_tuple_set AD\ ns ns\' {fo_nmlz AD\ (proj_tuple ns (zip ns\ x))} - Y)))" + unfolding res_def[unfolded idx\_def] + apply (rule map_values_cluster) + apply (auto simp: eval_conj_set_def split: option.splits) + apply (auto simp: ext_tuple_set_def split: if_splits) + done + moreover have "\ = fo_nmlz AD ` proj_fmla (Conj \ (Neg \)) {\. esat \ I \ UNIV} - + fo_nmlz AD ` proj_fmla (Conj \ (Neg \)) {\. esat \ I \ UNIV}" + unfolding S\_def[symmetric] S\_def[symmetric] proj_fmla_def fv_sort + proof (rule set_eqI, rule iffI) + fix t + assume "t \ (\x\ad_agr_close_set AD\\ X\. case Mapping.lookup idx\ (fo_nmlz AD\ (proj_tuple ns (zip ns\ x))) of + None \ ext_tuple_set AD ns\ ns\' {x} + | Some Y \ eval_conj_set AD ns\ {x} ns\ (ad_agr_close_set AD\\ (ext_tuple_set AD\ ns ns\' {fo_nmlz AD\ (proj_tuple ns (zip ns\ x))} - Y)))" + then obtain x where x: "x \ ad_agr_close_set AD\\ X\" + "Mapping.lookup idx\ (fo_nmlz AD\ (proj_tuple ns (zip ns\ x))) = None \ t \ ext_tuple_set AD ns\ ns\' {x}" + "\Y. Mapping.lookup idx\ (fo_nmlz AD\ (proj_tuple ns (zip ns\ x))) = Some Y \ + t \ eval_conj_set AD ns\ {x} ns\ (ad_agr_close_set AD\\ (ext_tuple_set AD\ ns ns\' {fo_nmlz AD\ (proj_tuple ns (zip ns\ x))} - Y))" + by (fastforce split: option.splits) + obtain \ where val: "\ \ S\" "x = fo_nmlz AD (map \ ns\)" + using ad_agr_close_correct[OF AD_def(3) ad_agr_\(1), folded AD\\_def] X\_def[folded proj_fmla_def] ad_agr_close_set_eq[OF fo_nmlzd_X(1)] x(1) + apply (auto simp: proj_fmla_def proj_vals_def ns\_def) + apply fast + done + obtain \' where \': "x = map \' ns\" + using exists_map[where ?ys=x and ?xs=ns\] aux(1) + by (auto simp: val(2) fo_nmlz_length) + have x_proj_singleton: "{x} = fo_nmlz AD ` proj_vals {\} ns\" + by (auto simp: val(2) proj_vals_def) + have x_ns: "proj_tuple ns (zip ns\ x) = map \' ns" + unfolding \' + by (rule proj_tuple_map[OF ns_sd(1-2,4)]) + have ad_agr_\_\': "ad_agr_list AD (map \ ns\) (map \' ns\)" + using \' + by (auto simp: val(2)) (metis fo_nmlz_ad_agr) + have x_proj_ad_agr: "{x} = fo_nmlz AD ` proj_vals {\. ad_agr_list AD (map \ ns\) (map \' ns\)} ns\" + using ad_agr_\_\' ad_agr_list_comm ad_agr_list_trans + by (auto simp: val(2) proj_vals_def fo_nmlz_eq) blast + have "t \ fo_nmlz AD ` \ (ext_tuple AD ns\ ns\' ` {x}) \ fo_nmlz AD (proj_tuple ns\ (zip both t)) \ {x}" + apply (rule ext_tuple_sound(1)[OF aux x_proj_ad_agr]) + apply (auto simp: ad_agr_list_link) + using ad_agr_list_comm ad_agr_list_trans + by blast+ + then have x_proj: "t \ ext_tuple_set AD ns\ ns\' {x} \ x = fo_nmlz AD (proj_tuple ns\ (zip both t))" + using ext_tuple_set_eq[where ?AD=AD] Ball_ad_agr x(1) + by (auto simp: val(2) proj_vals_def) + have x_S\: "t \ ext_tuple_set AD ns\ ns\' {x} \ t \ fo_nmlz AD ` proj_vals S\ both" + using ext_tuple_correct[OF aux refl ad_agr_\(2)[folded ns\_def]] ext_tuple_set_mono[of "{x}" "fo_nmlz AD ` proj_vals S\ ns\"] val(1) + by (fastforce simp: val(2) proj_vals_def) + show "t \ fo_nmlz AD ` proj_vals S\ both - fo_nmlz AD ` proj_vals S\ both" + proof (cases "Mapping.lookup idx\ (fo_nmlz AD\ (proj_tuple ns (zip ns\ x)))") + case None + have "False" if t_in_S\: "t \ fo_nmlz AD ` proj_vals S\ both" + proof - + obtain \ where \: "\ \ S\" "t = fo_nmlz AD (map \ both)" + using t_in_S\ + by (auto simp: proj_vals_def) + obtain \' where t_\': "t = map \' both" + using aux(3) exists_map[where ?ys=t and ?xs=both] + by (auto simp: \(2) fo_nmlz_length) + obtain \'' where \'': "fo_nmlz AD\ (map \ ns\) = map \'' ns\" + using ns_sd exists_map[where ?ys="fo_nmlz AD\ (map \ ns\)" and xs=ns\] + by (auto simp: fo_nmlz_length) + have proj_\'': "proj_tuple ns (zip ns\ (map \'' ns\)) = map \'' ns" + apply (rule proj_tuple_map) + using ns_sd + by auto + have "proj_tuple ns\ (zip both t) = map \' ns\" + unfolding t_\' + apply (rule proj_tuple_map) + using aux + by auto + then have x_\': "x = fo_nmlz AD (map \' ns\)" + by (auto simp: x_proj[OF x(2)[OF None]]) + obtain \''' where \''': "x = map \''' ns\" + using aux exists_map[where ?ys=x and ?xs=ns\] + by (auto simp: x_\' fo_nmlz_length) + have ad_\_\': "ad_agr_list AD (map \ both) (map \' both)" + using t_\' + by (auto simp: \) (metis fo_nmlz_ad_agr) + have ad_\_\'': "ad_agr_list AD\ (map \ ns\) (map \'' ns\)" + using \'' + by (metis fo_nmlz_ad_agr) + have ad_\'_\''': "ad_agr_list AD (map \' ns\) (map \''' ns\)" + using \''' + by (auto simp: x_\') (metis fo_nmlz_ad_agr) + have proj_\''': "proj_tuple ns (zip ns\ (map \''' ns\)) = map \''' ns" + apply (rule proj_tuple_map) + using aux ns_sd + by auto + have "fo_nmlz AD\ (proj_tuple ns (zip ns\ x)) = fo_nmlz AD\ (proj_tuple ns (zip ns\ (fo_nmlz AD\ (map \ ns\))))" + unfolding \'' proj_\'' \''' proj_\''' + apply (rule fo_nmlz_eqI) + using ad_agr_list_trans ad_agr_list_subset ns_sd(4-6) ad_agr_list_mono[OF AD_def(4)] ad_agr_list_comm[OF ad_\'_\'''] ad_agr_list_comm[OF ad_\_\'] ad_\_\'' + by metis + then show ?thesis + using None \(1) + by (auto simp: idx\_def lookup_cluster' X\_def ns\_def[symmetric] proj_vals_def split: if_splits) + qed + then show ?thesis + using x_S\[OF x(2)[OF None]] + by auto + next + case (Some Y) + have t_in: "t \ ext_tuple_set AD ns\ ns\' {x}" "t \ ext_tuple_set AD ns\ ns\' (fo_nmlz AD ` proj_vals {\ \ - S\. ad_agr_list AD\ (map \ ns) (map \' ns)} ns\)" + using x(3)[OF Some] eval_conj[OF x_ns x_proj_singleton Some] + by auto + have "ext_tuple_set AD ns\ ns\' (fo_nmlz AD ` proj_vals {\ \ - S\. ad_agr_list AD\ (map \ ns) (map \' ns)} ns\) = fo_nmlz AD ` proj_vals {\ \ - S\. ad_agr_list AD\ (map \ ns) (map \' ns)} both" + apply (rule ext_tuple_correct[OF ns_sd(3) ns_sd'(1) aux(3) aux6 refl]) + apply (auto simp: ad_agr_list_link) + using ad_agr_S\ ad_agr_list_comm ad_agr_list_subset[OF ns_sd(5)] ad_agr_list_trans ad_agr_list_mono[OF AD_def(4)] + by fast+ + then have t_both: "t \ fo_nmlz AD ` proj_vals {\ \ - S\. ad_agr_list AD\ (map \ ns) (map \' ns)} both" + using t_in(2) + by auto + { + assume "t \ fo_nmlz AD ` proj_vals S\ both" + then obtain \ where \: "\ \ S\" "t = fo_nmlz AD (map \ both)" + by (auto simp: proj_vals_def) + obtain \' where \': "\' \ S\" "t = fo_nmlz AD (map \' both)" + using t_both + by (auto simp: proj_vals_def) + have "False" + using \ \' + apply (auto simp: fo_nmlz_eq) + using ad_agr_S\ ad_agr_list_comm ad_agr_list_subset[OF ns_sd(8)] ad_agr_list_mono[OF AD_def(4)] + by blast + } + then show ?thesis + using x_S\[OF t_in(1)] + by auto + qed + next + fix t + assume t_in_asm: "t \ fo_nmlz AD ` proj_vals S\ both - fo_nmlz AD ` proj_vals S\ both" + then obtain \ where val: "\ \ S\" "t = fo_nmlz AD (map \ both)" + by (auto simp: proj_vals_def) + define x where "x = fo_nmlz AD (map \ ns\)" + obtain \' where \': "x = map \' ns\" + using exists_map[where ?ys=x and ?xs=ns\] aux(1) + by (auto simp: x_def fo_nmlz_length) + have x_proj_singleton: "{x} = fo_nmlz AD ` proj_vals {\} ns\" + by (auto simp: x_def proj_vals_def) + have x_in_ad_agr_close: "x \ ad_agr_close_set AD\\ X\" + using ad_agr_close_correct[OF AD_def(3) ad_agr_\(1), folded AD\\_def] val(1) + unfolding ad_agr_close_set_eq[OF fo_nmlzd_X(1)] x_def + unfolding X\_def[folded proj_fmla_def] proj_fmla_map + by (fastforce simp: x_def ns\_def) + have ad_agr_\_\': "ad_agr_list AD (map \ ns\) (map \' ns\)" + using \' + by (auto simp: x_def) (metis fo_nmlz_ad_agr) + have x_proj_ad_agr: "{x} = fo_nmlz AD ` proj_vals {\. ad_agr_list AD (map \ ns\) (map \' ns\)} ns\" + using ad_agr_\_\' ad_agr_list_comm ad_agr_list_trans + by (auto simp: x_def proj_vals_def fo_nmlz_eq) blast+ + have x_ns: "proj_tuple ns (zip ns\ x) = map \' ns" + unfolding \' + by (rule proj_tuple_map[OF ns_sd(1-2,4)]) + have "ext_tuple_set AD ns\ ns\' {x} = fo_nmlz AD ` proj_vals {\. ad_agr_list AD (map \ ns\) (map \' ns\)} both" + apply (rule ext_tuple_correct[OF aux x_proj_ad_agr]) + using ad_agr_list_comm ad_agr_list_trans + by (auto simp: ad_agr_list_link) blast+ + then have t_in_ext_x: "t \ ext_tuple_set AD ns\ ns\' {x}" + using ad_agr_\_\' + by (auto simp: val(2) proj_vals_def) + { + fix Y + assume Some: "Mapping.lookup idx\ (fo_nmlz AD\ (map \' ns)) = Some Y" + have tmp: "proj_tuple ns (zip ns\ x) = map \' ns" + unfolding \' + by (rule proj_tuple_map[OF ns_sd(1) aux(1) ns_sd(4)]) + have unfold: "ext_tuple_set AD ns\ ns\' (fo_nmlz AD ` proj_vals {\ \ - S\. ad_agr_list AD\ (map \ ns) (map \' ns)} ns\) = + fo_nmlz AD ` proj_vals {\ \ - S\. ad_agr_list AD\ (map \ ns) (map \' ns)} both" + apply (rule ext_tuple_correct[OF ns_sd(3) ns_sd'(1) aux(3) aux6 refl]) + apply (auto simp: ad_agr_list_link) + using ad_agr_S\ ad_agr_list_mono[OF AD_def(4)] ad_agr_list_comm ad_agr_list_trans ad_agr_list_subset[OF ns_sd(5)] + by blast+ + have "\ \ S\" + using t_in_asm + by (auto simp: val(2) proj_vals_def) + moreover have "ad_agr_list AD\ (map \ ns) (map \' ns)" + using ad_agr_\_\' ad_agr_list_mono[OF AD_def(4)] ad_agr_list_subset[OF ns_sd(4)] + by blast + ultimately have "t \ ext_tuple_set AD ns\ ns\' (fo_nmlz AD ` proj_vals {\ \ - S\. ad_agr_list AD\ (map \ ns) (map \' ns)} ns\)" + unfolding unfold val(2) + by (auto simp: proj_vals_def) + then have "t \ eval_conj_set AD ns\ {x} ns\ (ad_agr_close_set AD\\ (ext_tuple_set AD\ ns ns\' {fo_nmlz AD\ (map \' ns)} - Y))" + using eval_conj[OF tmp x_proj_singleton Some[folded x_ns]] t_in_ext_x + by (auto simp: x_ns) + } + then show "t \ (\x\ad_agr_close_set AD\\ X\. case Mapping.lookup idx\ (fo_nmlz AD\ (proj_tuple ns (zip ns\ x))) of + None \ ext_tuple_set AD ns\ ns\' {x} + | Some Y \ eval_conj_set AD ns\ {x} ns\ (ad_agr_close_set AD\\ (ext_tuple_set AD\ ns ns\' {fo_nmlz AD\ (proj_tuple ns (zip ns\ x))} - Y)))" + using t_in_ext_x + by (intro UN_I[OF x_in_ad_agr_close]) (auto simp: x_ns split: option.splits) + qed + ultimately have X_def: "X = fo_nmlz AD ` proj_fmla (Conj \ (Neg \)) {\. esat \ I \ UNIV} - + fo_nmlz AD ` proj_fmla (Conj \ (Neg \)) {\. esat \ I \ UNIV}" + by simp + + have AD_Neg_sub: "act_edom (Neg \) I \ AD" + by (auto simp: AD_def(1)) + have "X = fo_nmlz AD ` proj_fmla (Conj \ (Neg \)) {\. esat \ I \ UNIV} \ + fo_nmlz AD ` proj_fmla (Conj \ (Neg \)) {\. esat (Neg \) I \ UNIV}" + unfolding X_def + by (auto simp: proj_fmla_map dest!: fo_nmlz_eqD) + (metis AD_def(4) ad_agr_list_subset esat_UNIV_ad_agr_list fv_fo_fmla_list_set fv_sub + sup_ge1 ts_def(4)) + then have eval: "eval_ajoin (fv_fo_fmla_list \) t\ (fv_fo_fmla_list \) t\ = + eval_abs (Conj \ (Neg \)) I" + using proj_fmla_conj_sub[OF AD_Neg_sub, of \] + unfolding AD_X_def AD_def(1)[symmetric] n_def eval_abs_def + by (auto simp: proj_fmla_map) + have wf_conj_neg: "wf_fo_intp (Conj \ (Neg \)) I" + using wf + by (auto simp: ts_def) + show ?thesis + using fo_wf_eval_abs[OF wf_conj_neg] + by (auto simp: eval) +qed + +lemma eval_disj: + fixes \ :: "('a :: infinite, 'b) fo_fmla" + assumes wf: "fo_wf \ I t\" "fo_wf \ I t\" + shows "fo_wf (Disj \ \) I + (eval_disj (fv_fo_fmla_list \) t\ (fv_fo_fmla_list \) t\)" +proof - + obtain AD\ n\ X\ AD\ n\ X\ where ts_def: + "t\ = (AD\, n\, X\)" "t\ = (AD\, n\, X\)" + "AD\ = act_edom \ I" "AD\ = act_edom \ I" + using assms + by (cases t\, cases t\) auto + have AD_sub: "act_edom \ I \ AD\" "act_edom \ I \ AD\" + by (auto simp: ts_def(3,4)) + + obtain AD n X where AD_X_def: + "eval_disj (fv_fo_fmla_list \) t\ (fv_fo_fmla_list \) t\ = (AD, n, X)" + by (cases "eval_disj (fv_fo_fmla_list \) t\ (fv_fo_fmla_list \) t\") auto + have AD_def: "AD = act_edom (Disj \ \) I" "act_edom (Disj \ \) I \ AD" + "AD\ \ AD" "AD\ \ AD" "AD = AD\ \ AD\" + using AD_X_def + by (auto simp: ts_def Let_def) + have n_def: "n = nfv (Disj \ \)" + using AD_X_def + by (auto simp: ts_def Let_def nfv_card fv_fo_fmla_list_set) + + define S\ where "S\ \ {\. esat \ I \ UNIV}" + define S\ where "S\ \ {\. esat \ I \ UNIV}" + define ns\' where "ns\' = filter (\n. n \ fv_fo_fmla \) (fv_fo_fmla_list \)" + define ns\' where "ns\' = filter (\n. n \ fv_fo_fmla \) (fv_fo_fmla_list \)" + + note X\_def = fo_wf_X[OF wf(1)[unfolded ts_def(1)], unfolded proj_fmla_def, folded S\_def] + note X\_def = fo_wf_X[OF wf(2)[unfolded ts_def(2)], unfolded proj_fmla_def, folded S\_def] + have fv_sub: "fv_fo_fmla (Disj \ \) = fv_fo_fmla \ \ set (fv_fo_fmla_list \)" + "fv_fo_fmla (Disj \ \) = fv_fo_fmla \ \ set (fv_fo_fmla_list \)" + by (auto simp: fv_fo_fmla_list_set) + note res_left_alt = ext_tuple_ad_agr_close[OF S\_def AD_sub(1) AD_def(3) + X\_def(1)[folded S\_def] ns\'_def sorted_distinct_fv_list fv_sub(1)] + note res_right_alt = ext_tuple_ad_agr_close[OF S\_def AD_sub(2) AD_def(4) + X\_def(1)[folded S\_def] ns\'_def sorted_distinct_fv_list fv_sub(2)] + + have "X = fo_nmlz AD ` proj_fmla (Disj \ \) {\. esat \ I \ UNIV} \ + fo_nmlz AD ` proj_fmla (Disj \ \) {\. esat \ I \ UNIV}" + using AD_X_def + apply (simp add: ts_def(1,2) Let_def AD_def(5)[symmetric]) + unfolding fv_fo_fmla_list_set proj_fmla_def ns\'_def[symmetric] ns\'_def[symmetric] + S\_def[symmetric] S\_def[symmetric] + using res_left_alt(1) res_right_alt(1) + by auto + then have eval: "eval_disj (fv_fo_fmla_list \) t\ (fv_fo_fmla_list \) t\ = + eval_abs (Disj \ \) I" + unfolding AD_X_def AD_def(1)[symmetric] n_def eval_abs_def + by (auto simp: proj_fmla_map) + have wf_disj: "wf_fo_intp (Disj \ \) I" + using wf + by (auto simp: ts_def) + show ?thesis + using fo_wf_eval_abs[OF wf_disj] + by (auto simp: eval) +qed + +lemma fv_ex_all: + assumes "pos i (fv_fo_fmla_list \) = None" + shows "fv_fo_fmla_list (Exists i \) = fv_fo_fmla_list \" + "fv_fo_fmla_list (Forall i \) = fv_fo_fmla_list \" + using pos_complete[of i "fv_fo_fmla_list \"] fv_fo_fmla_list_eq[of "Exists i \" \] + fv_fo_fmla_list_eq[of "Forall i \" \] assms + by (auto simp: fv_fo_fmla_list_set) + +lemma nfv_ex_all: + assumes Some: "pos i (fv_fo_fmla_list \) = Some j" + shows "nfv \ = Suc (nfv (Exists i \))" "nfv \ = Suc (nfv (Forall i \))" +proof - + have "i \ fv_fo_fmla \" "j < nfv \" "i \ set (fv_fo_fmla_list \)" + using fv_fo_fmla_list_set pos_set[of i "fv_fo_fmla_list \"] + pos_length[of i "fv_fo_fmla_list \"] Some + by (fastforce simp: nfv_def)+ + then show "nfv \ = Suc (nfv (Exists i \))" "nfv \ = Suc (nfv (Forall i \))" + using nfv_card[of \] nfv_card[of "Exists i \"] nfv_card[of "Forall i \"] + by (auto simp: finite_fv_fo_fmla) +qed + +lemma fv_fo_fmla_list_exists: "fv_fo_fmla_list (Exists n \) = filter ((\) n) (fv_fo_fmla_list \)" + by (auto simp: fv_fo_fmla_list_def) + (metis (mono_tags, lifting) distinct_filter distinct_remdups_adj_sort + distinct_remdups_id filter_set filter_sort remdups_adj_set sorted_list_of_set_sort_remdups + sorted_remdups_adj sorted_sort sorted_sort_id) + +lemma eval_exists: + fixes \ :: "('a :: infinite, 'b) fo_fmla" + assumes wf: "fo_wf \ I t" + shows "fo_wf (Exists i \) I (eval_exists i (fv_fo_fmla_list \) t)" +proof - + obtain AD n X where t_def: "t = (AD, n, X)" + "AD = act_edom \ I" "AD = act_edom (Exists i \) I" + using assms + by (cases t) auto + note X_def = fo_wf_X[OF wf[unfolded t_def], folded t_def(2)] + have eval: "eval_exists i (fv_fo_fmla_list \) t = eval_abs (Exists i \) I" + proof (cases "pos i (fv_fo_fmla_list \)") + case None + note fv_eq = fv_ex_all[OF None] + have "X = fo_nmlz AD ` proj_fmla (Exists i \) {\. esat \ I \ UNIV}" + unfolding X_def + by (auto simp: proj_fmla_def fv_eq) + also have "\ = fo_nmlz AD ` proj_fmla (Exists i \) {\. esat (Exists i \) I \ UNIV}" + using esat_exists_not_fv[of i \ UNIV I] pos_complete[OF None] + by (simp add: fv_fo_fmla_list_set) + finally show ?thesis + by (auto simp: t_def None eval_abs_def fv_eq nfv_def) + next + case (Some j) + have "fo_nmlz AD ` rem_nth j ` X = + fo_nmlz AD ` proj_fmla (Exists i \) {\. esat (Exists i \) I \ UNIV}" + proof (rule set_eqI, rule iffI) + fix vs + assume "vs \ fo_nmlz AD ` rem_nth j ` X" + then obtain ws where ws_def: "ws \ fo_nmlz AD ` proj_fmla \ {\. esat \ I \ UNIV}" + "vs = fo_nmlz AD (rem_nth j ws)" + unfolding X_def + by auto + then obtain \ where \_def: "esat \ I \ UNIV" + "ws = fo_nmlz AD (map \ (fv_fo_fmla_list \))" + by (auto simp: proj_fmla_map) + obtain \ where \_def: "ws = map \ (fv_fo_fmla_list \)" + using fo_nmlz_map \_def(2) + by blast + have esat_\: "esat (Exists i \) I \ UNIV" + using esat_UNIV_ad_agr_list[OF fo_nmlz_ad_agr[of AD "map \ (fv_fo_fmla_list \)", + folded \_def(2), unfolded \_def]] \_def(1) + by (auto simp: t_def intro!: exI[of _ "\ i"]) + have rem_nth_ws: "rem_nth j ws = map \ (fv_fo_fmla_list (Exists i \))" + using rem_nth_sound[of "fv_fo_fmla_list \" i j \] sorted_distinct_fv_list Some + unfolding fv_fo_fmla_list_exists \_def + by auto + have "vs \ fo_nmlz AD ` proj_fmla (Exists i \) {\. esat (Exists i \) I \ UNIV}" + using ws_def(2) esat_\ + unfolding rem_nth_ws + by (auto simp: proj_fmla_map) + then show "vs \ fo_nmlz AD ` proj_fmla (Exists i \) {\. esat (Exists i \) I \ UNIV}" + by auto + next + fix vs + assume assm: "vs \ fo_nmlz AD ` proj_fmla (Exists i \) {\. esat (Exists i \) I \ UNIV}" + from assm obtain \ where \_def: "vs = fo_nmlz AD (map \ (fv_fo_fmla_list (Exists i \)))" + "esat (Exists i \) I \ UNIV" + by (auto simp: proj_fmla_map) + then obtain x where x_def: "esat \ I (\(i := x)) UNIV" + by auto + define ws where "ws \ fo_nmlz AD (map (\(i := x)) (fv_fo_fmla_list \))" + then have "length ws = nfv \" + using nfv_def fo_nmlz_length by (metis length_map) + then have ws_in: "ws \ fo_nmlz AD ` proj_fmla \ {\. esat \ I \ UNIV}" + using x_def ws_def + by (auto simp: fo_nmlz_sound proj_fmla_map) + obtain \ where \_def: "ws = map \ (fv_fo_fmla_list \)" + using fo_nmlz_map ws_def + by blast + have rem_nth_ws: "rem_nth j ws = map \ (fv_fo_fmla_list (Exists i \))" + using rem_nth_sound[of "fv_fo_fmla_list \" i j] sorted_distinct_fv_list Some + unfolding fv_fo_fmla_list_exists \_def + by auto + have "set (fv_fo_fmla_list (Exists i \)) \ set (fv_fo_fmla_list \)" + by (auto simp: fv_fo_fmla_list_exists) + then have ad_agr: "ad_agr_list AD (map (\(i := x)) (fv_fo_fmla_list (Exists i \))) + (map \ (fv_fo_fmla_list (Exists i \)))" + by (rule ad_agr_list_subset) + (rule fo_nmlz_ad_agr[of AD "map (\(i := x)) (fv_fo_fmla_list \)", folded ws_def, + unfolded \_def]) + have map_fv_cong: "map (\(i := x)) (fv_fo_fmla_list (Exists i \)) = + map \ (fv_fo_fmla_list (Exists i \))" + by (auto simp: fv_fo_fmla_list_exists) + have vs_rem_nth: "vs = fo_nmlz AD (rem_nth j ws)" + unfolding \_def(1) rem_nth_ws + apply (rule fo_nmlz_eqI) + using ad_agr[unfolded map_fv_cong] . + show "vs \ fo_nmlz AD ` rem_nth j ` X" + using Some ws_in + unfolding vs_rem_nth X_def + by auto + qed + then show ?thesis + using nfv_ex_all[OF Some] + by (auto simp: t_def Some eval_abs_def nfv_def) + qed + have wf_ex: "wf_fo_intp (Exists i \) I" + using wf + by (auto simp: t_def) + show ?thesis + using fo_wf_eval_abs[OF wf_ex] + by (auto simp: eval) +qed + +lemma fv_fo_fmla_list_forall: "fv_fo_fmla_list (Forall n \) = filter ((\) n) (fv_fo_fmla_list \)" + by (auto simp: fv_fo_fmla_list_def) + (metis (mono_tags, lifting) distinct_filter distinct_remdups_adj_sort + distinct_remdups_id filter_set filter_sort remdups_adj_set sorted_list_of_set_sort_remdups + sorted_remdups_adj sorted_sort sorted_sort_id) + +lemma pairwise_take_drop: + assumes "pairwise P (set (zip xs ys))" "length xs = length ys" + shows "pairwise P (set (zip (take i xs @ drop (Suc i) xs) (take i ys @ drop (Suc i) ys)))" + by (rule pairwise_subset[OF assms(1)]) (auto simp: set_zip assms(2)) + +lemma fo_nmlz_set_card: + "fo_nmlz AD xs = xs \ set xs = set xs \ Inl ` AD \ Inr ` {.. + ad_agr_list AD (take i xs @ drop (Suc i) xs) (take i ys @ drop (Suc i) ys)" + apply (auto simp: ad_agr_list_def ad_equiv_list_def sp_equiv_list_def) + apply (metis take_zip in_set_takeD) + apply (metis drop_zip in_set_dropD) + using pairwise_take_drop + by fastforce + +lemma fo_nmlz_rem_nth_add_nth: + assumes "fo_nmlz AD zs = zs" "i \ length zs" + shows "fo_nmlz AD (rem_nth i (fo_nmlz AD (add_nth i z zs))) = zs" +proof - + have ad_agr: "ad_agr_list AD (add_nth i z zs) (fo_nmlz AD (add_nth i z zs))" + using fo_nmlz_ad_agr + by auto + have i_lt_add: "i < length (add_nth i z zs)" "i < length (fo_nmlz AD (add_nth i z zs))" + using add_nth_length assms(2) + by (fastforce simp: fo_nmlz_length)+ + show ?thesis + using ad_agr_list_take_drop[OF ad_agr, of i, folded rem_nth_take_drop[OF i_lt_add(1)] + rem_nth_take_drop[OF i_lt_add(2)], unfolded rem_nth_add_nth[OF assms(2)]] + apply (subst eq_commute) + apply (subst assms(1)[symmetric]) + apply (auto intro: fo_nmlz_eqI) + done +qed + +lemma ad_agr_list_add: + assumes "ad_agr_list AD xs ys" "i \ length xs" + shows "\z' \ Inl ` AD \ Inr ` {.. set ys. + ad_agr_list AD (take i xs @ z # drop i xs) (take i ys @ z' # drop i ys)" +proof - + define n where "n = length xs" + have len_ys: "n = length ys" + using assms(1) + by (auto simp: ad_agr_list_def n_def) + obtain \ where \_def: "xs = map \ [0.. where \_def: "ys = map \ [0.. n" + using assms(2) + by (auto simp: n_def) + have set_n: "set [0.. \" + using iffD2[OF ad_agr_list_link, OF assms(1)[unfolded \_def \_def]] + unfolding set_n . + have set_ys: "\ ` ({..n} - {n}) = set ys" + by (auto simp: \_def) + obtain z' where z'_def: "z' \ Inl ` AD \ Inr ` {.. set ys" + "ad_agr_sets {..n} {..n} AD (\(n := z)) (\(n := z'))" + using extend_\[OF ad_agr subset_refl, + of "Inl ` AD \ Inr ` {.. set ys" z] + by (auto simp: set_ys) + have map_take: "map (\(n := z)) ([0..(n := z')) ([0.._def \_def take_map drop_map) + show ?thesis + using iffD1[OF ad_agr_list_link, OF z'_def(2)[unfolded set_n[symmetric]]] z'_def(1) + unfolding map_take + by auto +qed + +lemma add_nth_restrict: + assumes "fo_nmlz AD zs = zs" "i \ length zs" + shows "\z' \ Inl ` AD \ Inr ` {.. Inl ` AD \ Inr ` {.. Inl ` AD \ Inr ` {.. length zs" + shows "\z'. fo_nmlz AD (add_nth i z zs) = fo_nmlz AD (add_nth i z' (fo_nmlz AD zs))" +proof - + have ad_agr: "ad_agr_list AD zs (fo_nmlz AD zs)" + using fo_nmlz_ad_agr + by auto + have i_le_fo_nmlz: "i \ length (fo_nmlz AD zs)" + using assms(1) + by (auto simp: fo_nmlz_length) + obtain x where x_def: "ad_agr_list AD (add_nth i z zs) (add_nth i x (fo_nmlz AD zs))" + using ad_agr_list_add[OF ad_agr assms(1)] + by (auto simp: add_nth_take_drop[OF assms(1)] add_nth_take_drop[OF i_le_fo_nmlz]) + then show ?thesis + using fo_nmlz_eqI + by auto +qed + +lemma fo_nmlz_add_rem': + assumes "i \ length zs" + shows "\z'. fo_nmlz AD (add_nth i z (fo_nmlz AD zs)) = fo_nmlz AD (add_nth i z' zs)" +proof - + have ad_agr: "ad_agr_list AD (fo_nmlz AD zs) zs" + using ad_agr_list_comm[OF fo_nmlz_ad_agr] + by auto + have i_le_fo_nmlz: "i \ length (fo_nmlz AD zs)" + using assms(1) + by (auto simp: fo_nmlz_length) + obtain x where x_def: "ad_agr_list AD (add_nth i z (fo_nmlz AD zs)) (add_nth i x zs)" + using ad_agr_list_add[OF ad_agr i_le_fo_nmlz] + by (auto simp: add_nth_take_drop[OF assms(1)] add_nth_take_drop[OF i_le_fo_nmlz]) + then show ?thesis + using fo_nmlz_eqI + by auto +qed + +lemma fo_nmlz_add_nth_rem_nth: + assumes "fo_nmlz AD xs = xs" "i < length xs" + shows "\z. fo_nmlz AD (add_nth i z (fo_nmlz AD (rem_nth i xs))) = xs" + using rem_nth_length[OF assms(2)] fo_nmlz_add_rem[of i "rem_nth i xs" AD "xs ! i", + unfolded assms(1) add_nth_rem_nth_self[OF assms(2)]] assms(2) + by (subst eq_commute) auto + +lemma sp_equiv_list_almost_same: "sp_equiv_list (xs @ v # ys) (xs @ w # ys) \ + v \ set xs \ set ys \ w \ set xs \ set ys \ v = w" + by (auto simp: sp_equiv_list_def pairwise_def) (metis UnCI sp_equiv_pair.simps zip_same)+ + +lemma ad_agr_list_add_nth: + assumes "i \ length zs" "ad_agr_list AD (add_nth i v zs) (add_nth i w zs)" "v \ w" + shows "{v, w} \ (Inl ` AD \ set zs) = {}" + using assms(2)[unfolded add_nth_take_drop[OF assms(1)]] assms(1,3) sp_equiv_list_almost_same + by (auto simp: ad_agr_list_def ad_equiv_list_def ad_equiv_pair.simps) + (smt append_take_drop_id set_append sp_equiv_list_almost_same)+ + +lemma Inr_in_tuple: + assumes "fo_nmlz AD zs = zs" "n < card (Inr -` set zs)" + shows "Inr n \ set zs" + using assms fo_nmlz_set_card[OF assms(1)] + by (auto simp: fo_nmlzd_code[symmetric]) + +lemma card_wit_sub: + assumes "finite Z" "card Z \ card {ts \ X. \z \ Z. ts = f z}" + shows "f ` Z \ X" +proof - + have set_unfold: "{ts \ X. \z \ Z. ts = f z} = f ` Z \ X" + by auto + show ?thesis + using assms + unfolding set_unfold + by (metis Int_lower1 card_image_le card_seteq finite_imageI inf.absorb_iff1 le_antisym + surj_card_le) +qed + +lemma add_nth_iff_card: + assumes "(\xs. xs \ X \ fo_nmlz AD xs = xs)" "(\xs. xs \ X \ i < length xs)" + "fo_nmlz AD zs = zs" "i \ length zs" "finite AD" "finite X" + shows "(\z. fo_nmlz AD (add_nth i z zs) \ X) \ + Suc (card AD + card (Inr -` set zs)) \ card {ts \ X. \z. ts = fo_nmlz AD (add_nth i z zs)}" +proof - + have inj: "inj_on (\z. fo_nmlz AD (add_nth i z zs)) + (Inl ` AD \ Inr ` {.. Inr ` {..z. fo_nmlz AD (add_nth i z zs) \ X) \ + (\z \ Inl ` AD \ Inr ` {.. X)" + using add_nth_restrict[OF assms(3,4)] + by metis + have restrict_z': "{ts \ X. \z. ts = fo_nmlz AD (add_nth i z zs)} = + {ts \ X. \z \ Inl ` AD \ Inr ` {..z. fo_nmlz AD (add_nth i z zs) \ X" + then have image_sub: "(\z. fo_nmlz AD (add_nth i z zs)) ` + (Inl ` AD \ Inr ` {.. + {ts \ X. \z. ts = fo_nmlz AD (add_nth i z zs)}" + by auto + have "Suc (card AD + card (Inr -` set zs)) \ + card {ts \ X. \z. ts = fo_nmlz AD (add_nth i z zs)}" + unfolding card_Un[symmetric] + using card_inj_on_le[OF inj image_sub] assms(6) + by auto + then have "Suc (card AD + card (Inr -` set zs)) \ + card {ts \ X. \z. ts = fo_nmlz AD (add_nth i z zs)}" + by (auto simp: card_image) + } + moreover + { + assume assm: "card (Inl ` AD \ Inr ` {.. + card {ts \ X. \z \ Inl ` AD \ Inr ` {..z \ Inl ` AD \ Inr ` {.. X" + using card_wit_sub[OF _ assm] assms(5) + by auto + } + ultimately show ?thesis + unfolding restrict_z[symmetric] restrict_z'[symmetric] card_Un + by auto +qed + +lemma set_fo_nmlz_add_nth_rem_nth: + assumes "j < length xs" "\x. x \ X \ fo_nmlz AD x = x" + "\x. x \ X \ j < length x" + shows "{ts \ X. \z. ts = fo_nmlz AD (add_nth j z (fo_nmlz AD (rem_nth j xs)))} = + {y \ X. fo_nmlz AD (rem_nth j y) = fo_nmlz AD (rem_nth j xs)}" + using fo_nmlz_rem_nth_add_nth[where ?zs="fo_nmlz AD (rem_nth j xs)"] rem_nth_length[OF assms(1)] fo_nmlz_add_nth_rem_nth assms + by (fastforce simp: fo_nmlz_idem[OF fo_nmlz_sound] fo_nmlz_length) + +lemma eval_forall: + fixes \ :: "('a :: infinite, 'b) fo_fmla" + assumes wf: "fo_wf \ I t" + shows "fo_wf (Forall i \) I (eval_forall i (fv_fo_fmla_list \) t)" +proof - + obtain AD n X where t_def: "t = (AD, n, X)" "AD = act_edom \ I" + "AD = act_edom (Forall i \) I" + using assms + by (cases t) auto + have AD_sub: "act_edom \ I \ AD" + by (auto simp: t_def(2)) + have fin_AD: "finite AD" + using finite_act_edom wf + by (auto simp: t_def) + have fin_X: "finite X" + using wf + by (auto simp: t_def) + note X_def = fo_wf_X[OF wf[unfolded t_def], folded t_def(2)] + have eval: "eval_forall i (fv_fo_fmla_list \) t = eval_abs (Forall i \) I" + proof (cases "pos i (fv_fo_fmla_list \)") + case None + note fv_eq = fv_ex_all[OF None] + have "X = fo_nmlz AD ` proj_fmla (Forall i \) {\. esat \ I \ UNIV}" + unfolding X_def + by (auto simp: proj_fmla_def fv_eq) + also have "\ = fo_nmlz AD ` proj_fmla (Forall i \) {\. esat (Forall i \) I \ UNIV}" + using esat_forall_not_fv[of i \ UNIV I] pos_complete[OF None] + by (auto simp: fv_fo_fmla_list_set) + finally show ?thesis + by (auto simp: t_def None eval_abs_def fv_eq nfv_def) + next + case (Some j) + have i_in_fv: "i \ fv_fo_fmla \" + by (rule pos_set[OF Some, unfolded fv_fo_fmla_list_set]) + have fo_nmlz_X: "\xs. xs \ X \ fo_nmlz AD xs = xs" + by (auto simp: X_def proj_fmla_map fo_nmlz_idem[OF fo_nmlz_sound]) + have j_lt_len: "\xs. xs \ X \ j < length xs" + using pos_sound[OF Some] + by (auto simp: X_def proj_fmla_map fo_nmlz_length) + have rem_nth_j_le_len: "\xs. xs \ X \ j \ length (fo_nmlz AD (rem_nth j xs))" + using rem_nth_length j_lt_len + by (fastforce simp: fo_nmlz_length) + have img_proj_fmla: "Mapping.keys (Mapping.filter (\t Z. Suc (card AD + card (Inr -` set t)) \ card Z) + (cluster (Some \ (\ts. fo_nmlz AD (rem_nth j ts))) X)) = + fo_nmlz AD ` proj_fmla (Forall i \) {\. esat (Forall i \) I \ UNIV}" + proof (rule set_eqI, rule iffI) + fix vs + assume "vs \ Mapping.keys (Mapping.filter (\t Z. Suc (card AD + card (Inr -` set t)) \ card Z) + (cluster (Some \ (\ts. fo_nmlz AD (rem_nth j ts))) X))" + then obtain ws where ws_def: "ws \ X" "vs = fo_nmlz AD (rem_nth j ws)" + "\a. fo_nmlz AD (add_nth j a (fo_nmlz AD (rem_nth j ws))) \ X" + using add_nth_iff_card[OF fo_nmlz_X j_lt_len fo_nmlz_idem[OF fo_nmlz_sound] + rem_nth_j_le_len fin_AD fin_X] set_fo_nmlz_add_nth_rem_nth[OF j_lt_len fo_nmlz_X j_lt_len] + by transfer (fastforce split: option.splits if_splits) + then obtain \ where \_def: + "esat \ I \ UNIV" "ws = fo_nmlz AD (map \ (fv_fo_fmla_list \))" + unfolding X_def + by (auto simp: proj_fmla_map) + obtain \ where \_def: "ws = map \ (fv_fo_fmla_list \)" + using fo_nmlz_map \_def(2) + by blast + have fo_nmlzd_\: "fo_nmlzd AD (map \ (fv_fo_fmla_list \))" + unfolding \_def[symmetric] \_def(2) + by (rule fo_nmlz_sound) + have rem_nth_j_ws: "rem_nth j ws = map \ (filter ((\) i) (fv_fo_fmla_list \))" + using rem_nth_sound[OF _ Some] sorted_distinct_fv_list + by (auto simp: \_def) + have esat_\: "esat (Forall i \) I \ UNIV" + unfolding esat.simps + proof (rule ballI) + fix x + have "fo_nmlz AD (add_nth j x (rem_nth j ws)) \ X" + using fo_nmlz_add_rem[of j "rem_nth j ws" AD x] rem_nth_length + j_lt_len[OF ws_def(1)] ws_def(3) + by fastforce + then have "fo_nmlz AD (map (\(i := x)) (fv_fo_fmla_list \)) \ X" + using add_nth_rem_nth_map[OF _ Some, of x] sorted_distinct_fv_list + unfolding \_def + by fastforce + then show "esat \ I (\(i := x)) UNIV" + by (auto simp: X_def proj_fmla_map esat_UNIV_ad_agr_list[OF _ AD_sub] + dest!: fo_nmlz_eqD) + qed + have rem_nth_ws: "rem_nth j ws = map \ (fv_fo_fmla_list (Forall i \))" + using rem_nth_sound[OF _ Some] sorted_distinct_fv_list + by (auto simp: fv_fo_fmla_list_forall \_def) + then show "vs \ fo_nmlz AD ` proj_fmla (Forall i \) {\. esat (Forall i \) I \ UNIV}" + using ws_def(2) esat_\ + by (auto simp: proj_fmla_map rem_nth_ws) + next + fix vs + assume assm: "vs \ fo_nmlz AD ` proj_fmla (Forall i \) {\. esat (Forall i \) I \ UNIV}" + from assm obtain \ where \_def: "vs = fo_nmlz AD (map \ (fv_fo_fmla_list (Forall i \)))" + "esat (Forall i \) I \ UNIV" + by (auto simp: proj_fmla_map) + then have all_esat: "\x. esat \ I (\(i := x)) UNIV" + by auto + define ws where "ws \ fo_nmlz AD (map \ (fv_fo_fmla_list \))" + then have "length ws = nfv \" + using nfv_def fo_nmlz_length by (metis length_map) + then have ws_in: "ws \ fo_nmlz AD ` proj_fmla \ {\. esat \ I \ UNIV}" + using all_esat[of "\ i"] ws_def + by (auto simp: fo_nmlz_sound proj_fmla_map) + then have ws_in_X: "ws \ X" + by (auto simp: X_def) + obtain \ where \_def: "ws = map \ (fv_fo_fmla_list \)" + using fo_nmlz_map ws_def + by blast + have rem_nth_ws: "rem_nth j ws = map \ (fv_fo_fmla_list (Forall i \))" + using rem_nth_sound[of "fv_fo_fmla_list \" i j] sorted_distinct_fv_list Some + unfolding fv_fo_fmla_list_forall \_def + by auto + have "set (fv_fo_fmla_list (Forall i \)) \ set (fv_fo_fmla_list \)" + by (auto simp: fv_fo_fmla_list_forall) + then have ad_agr: "ad_agr_list AD (map \ (fv_fo_fmla_list (Forall i \))) + (map \ (fv_fo_fmla_list (Forall i \)))" + apply (rule ad_agr_list_subset) + using fo_nmlz_ad_agr[of AD] ws_def \_def + by metis + have map_fv_cong: "\x. map (\(i := x)) (fv_fo_fmla_list (Forall i \)) = + map \ (fv_fo_fmla_list (Forall i \))" + by (auto simp: fv_fo_fmla_list_forall) + have vs_rem_nth: "vs = fo_nmlz AD (rem_nth j ws)" + unfolding \_def(1) rem_nth_ws + apply (rule fo_nmlz_eqI) + using ad_agr[unfolded map_fv_cong] . + have "\a. fo_nmlz AD (add_nth j a (fo_nmlz AD (rem_nth j ws))) \ + fo_nmlz AD ` proj_fmla \ {\. esat \ I \ UNIV}" + proof - + fix a + obtain x where add_rem: "fo_nmlz AD (add_nth j a (fo_nmlz AD (rem_nth j ws))) = + fo_nmlz AD (map (\(i := x)) (fv_fo_fmla_list \))" + using add_nth_rem_nth_map[OF _ Some, of _ \] sorted_distinct_fv_list + fo_nmlz_add_rem'[of j "rem_nth j ws"] rem_nth_length[of j ws] + j_lt_len[OF ws_in_X] + by (fastforce simp: \_def) + have "esat (Forall i \) I \ UNIV" + apply (rule iffD1[OF esat_UNIV_ad_agr_list \_def(2), OF _ subset_refl, folded t_def]) + using fo_nmlz_ad_agr[of AD "map \ (fv_fo_fmla_list \)", folded ws_def, unfolded \_def] + unfolding ad_agr_list_link[symmetric] + by (auto simp: fv_fo_fmla_list_set ad_agr_sets_def sp_equiv_def pairwise_def) + then have "esat \ I (\(i := x)) UNIV" + by auto + then show "fo_nmlz AD (add_nth j a (fo_nmlz AD (rem_nth j ws))) \ + fo_nmlz AD ` proj_fmla \ {\. esat \ I \ UNIV}" + by (auto simp: add_rem proj_fmla_map) + qed + then show "vs \ Mapping.keys (Mapping.filter (\t Z. Suc (card AD + card (Inr -` set t)) \ card Z) + (cluster (Some \ (\ts. fo_nmlz AD (rem_nth j ts))) X))" + unfolding vs_rem_nth X_def[symmetric] + using add_nth_iff_card[OF fo_nmlz_X j_lt_len fo_nmlz_idem[OF fo_nmlz_sound] + rem_nth_j_le_len fin_AD fin_X] set_fo_nmlz_add_nth_rem_nth[OF j_lt_len fo_nmlz_X j_lt_len] ws_in_X + by transfer (fastforce split: option.splits if_splits) + qed + show ?thesis + using nfv_ex_all[OF Some] + by (simp add: t_def Some eval_abs_def nfv_def img_proj_fmla[unfolded t_def(2)] + split: option.splits) + qed + have wf_all: "wf_fo_intp (Forall i \) I" + using wf + by (auto simp: t_def) + show ?thesis + using fo_wf_eval_abs[OF wf_all] + by (auto simp: eval) +qed + +fun fo_res :: "('a, nat) fo_t \ 'a eval_res" where + "fo_res (AD, n, X) = (if fo_fin (AD, n, X) then Fin (map projl ` X) else Infin)" + +lemma fo_res_fin: + fixes t :: "('a :: infinite, nat) fo_t" + assumes "fo_wf \ I t" "finite (fo_rep t)" + shows "fo_res t = Fin (fo_rep t)" +proof - + obtain AD n X where t_def: "t = (AD, n, X)" + using assms(1) + by (cases t) auto + show ?thesis + using fo_fin assms + by (fastforce simp only: t_def fo_res.simps fo_rep_fin split: if_splits) +qed + +lemma fo_res_infin: + fixes t :: "('a :: infinite, nat) fo_t" + assumes "fo_wf \ I t" "\finite (fo_rep t)" + shows "fo_res t = Infin" +proof - + obtain AD n X where t_def: "t = (AD, n, X)" + using assms(1) + by (cases t) auto + show ?thesis + using fo_fin assms + by (fastforce simp only: t_def fo_res.simps split: if_splits) +qed + +lemma fo_rep: "fo_wf \ I t \ fo_rep t = proj_sat \ I" + by (cases t) auto + +global_interpretation Ailamazyan: eval_fo fo_wf eval_pred fo_rep fo_res + eval_bool eval_eq eval_neg eval_conj eval_ajoin eval_disj + eval_exists eval_forall + defines eval_fmla = Ailamazyan.eval_fmla + and eval = Ailamazyan.eval + apply standard + apply (rule fo_rep, assumption+) + apply (rule fo_res_fin, assumption+) + apply (rule fo_res_infin, assumption+) + apply (rule eval_pred, assumption+) + apply (rule eval_bool) + apply (rule eval_eq) + apply (rule eval_neg, assumption+) + apply (rule eval_conj, assumption+) + apply (rule eval_ajoin, assumption+) + apply (rule eval_disj, assumption+) + apply (rule eval_exists, assumption+) + apply (rule eval_forall, assumption+) + done + +definition esat_UNIV :: "('a :: infinite, 'b) fo_fmla \ ('a table, 'b) fo_intp \ ('a + nat) val \ bool" where + "esat_UNIV \ I \ = esat \ I \ UNIV" + +lemma esat_UNIV_code[code]: "esat_UNIV \ I \ \ (if wf_fo_intp \ I then + (case eval_fmla \ I of (AD, n, X) \ + fo_nmlz (act_edom \ I) (map \ (fv_fo_fmla_list \)) \ X) + else esat_UNIV \ I \)" +proof - + obtain AD n T where t_def: "Ailamazyan.eval_fmla \ I = (AD, n, T)" + by (cases "Ailamazyan.eval_fmla \ I") auto + { + assume wf_fo_intp: "wf_fo_intp \ I" + note fo_wf = Ailamazyan.eval_fmla_correct[OF wf_fo_intp, unfolded t_def] + note T_def = fo_wf_X[OF fo_wf] + have AD_def: "AD = act_edom \ I" + using fo_wf + by auto + have "esat_UNIV \ I \ \ + fo_nmlz (act_edom \ I) (map \ (fv_fo_fmla_list \)) \ T" + using esat_UNIV_ad_agr_list[OF _ subset_refl] + by (force simp add: esat_UNIV_def T_def AD_def proj_fmla_map + dest!: fo_nmlz_eqD) + } + then show ?thesis + by (auto simp: t_def) +qed + +lemma sat_code[code]: + fixes \ :: "('a :: infinite, 'b) fo_fmla" + shows "sat \ I \ \ (if wf_fo_intp \ I then + (case eval_fmla \ I of (AD, n, X) \ + fo_nmlz (act_edom \ I) (map (Inl \ \) (fv_fo_fmla_list \)) \ X) + else sat \ I \)" + using esat_UNIV_code sat_esat_conv[folded esat_UNIV_def] + by metis + +end diff --git a/thys/Eval_FO/Ailamazyan_Code.thy b/thys/Eval_FO/Ailamazyan_Code.thy new file mode 100644 --- /dev/null +++ b/thys/Eval_FO/Ailamazyan_Code.thy @@ -0,0 +1,124 @@ +theory Ailamazyan_Code + imports "HOL-Library.Code_Target_Nat" "Containers.Containers" Ailamazyan +begin + +(* Convert database to fo_intp *) + +definition insert_db :: "'a \ 'b \ ('a, 'b set) mapping \ ('a, 'b set) mapping" where + "insert_db k v m = (case Mapping.lookup m k of None \ + Mapping.update k ({v}) m + | Some vs \ Mapping.update k (({v} \ vs)) m)" + +fun convert_db_rec :: "('a \ 'c list) list \ (('a \ nat), 'c list set) mapping \ + (('a \ nat), 'c list set) mapping" where + "convert_db_rec [] m = m" +| "convert_db_rec ((r, ts) # ktss) m = convert_db_rec ktss (insert_db (r, length ts) ts m)" + +lemma convert_db_rec_mono: "Mapping.lookup m (r, n) = Some tss \ + \tss'. Mapping.lookup (convert_db_rec ktss m) (r, n) = Some tss' \ tss \ tss'" + apply (induction ktss m arbitrary: tss rule: convert_db_rec.induct) + apply (auto simp: insert_db_def fun_upd_def Mapping.lookup_update' split: option.splits if_splits) + apply (metis option.discI) + apply (smt option.inject order_trans subset_insertI) + done + +lemma convert_db_rec_sound: "(r, ts) \ set ktss \ + \tss. Mapping.lookup (convert_db_rec ktss m) (r, length ts) = Some tss \ ts \ tss" +proof (induction ktss m rule: convert_db_rec.induct) + case (2 r ts ktss m) + obtain tss where + "Mapping.lookup (convert_db_rec ktss (insert_db (r, length ts) ts m)) (r, length ts) = Some tss" + "ts \ tss" + using convert_db_rec_mono[of "insert_db (r, length ts) ts m" r "length ts" _ ktss] + by atomize_elim (auto simp: insert_db_def Mapping.lookup_update' split: option.splits)+ + then show ?case + using 2 + by auto +qed auto + +lemma convert_db_rec_complete: "Mapping.lookup (convert_db_rec ktss m) (r, n) = Some tss' \ + ts \ tss' \ + (length ts = n \ (r, ts) \ set ktss) \ (\tss. Mapping.lookup m (r, n) = Some tss \ ts \ tss)" + by (induction ktss m rule: convert_db_rec.induct) + (auto simp: insert_db_def Mapping.lookup_update' split: option.splits if_splits) + +definition convert_db :: "('a \ 'c list) list \ ('c table, 'a) fo_intp" where + "convert_db ktss = (let m = convert_db_rec ktss Mapping.empty in + (\x. case Mapping.lookup m x of None \ {} | Some v \ v))" + +lemma convert_db_correct: "(ts \ convert_db ktss (r, n) \ n = length ts) \ + ((r, ts) \ set ktss \ ts \ convert_db ktss (r, length ts))" + by (auto simp: convert_db_def dest!: convert_db_rec_sound[of _ _ _ Mapping.empty] + split: option.splits) + (metis Mapping.lookup_empty convert_db_rec_complete option.distinct(1))+ + +(* Code setup *) + +lemma Inl_vimage_set_code[code_unfold]: "Inl -` set as = set (List.map_filter (case_sum Some Map.empty) as)" + by (induction as) (auto simp: List.map_filter_simps split: option.splits sum.splits) + +lemma Inr_vimage_set_code[code_unfold]: "Inr -` set as = set (List.map_filter (case_sum Map.empty Some) as)" + by (induction as) (auto simp: List.map_filter_simps split: option.splits sum.splits) + +lemma Inl_vimage_code: "Inl -` as = projl ` {x \ as. isl x}" + by (force simp: vimage_def) + +lemmas ad_pred_code[code] = ad_terms.simps[unfolded Inl_vimage_code] +lemmas fo_wf_code[code] = fo_wf.simps[unfolded Inl_vimage_code] + +(* Monomorphise *) + +definition empty_J :: "((nat, nat) fo_t, String.literal) fo_intp" where + "empty_J = (\(_, n). eval_pred (map Var [0.. (nat table, String.literal) fo_intp \ nat eval_res" where + "eval_fin_nat \ I = eval \ I" + +definition sat_fin_nat :: "(nat, String.literal) fo_fmla \ (nat table, String.literal) fo_intp \ nat val \ bool" where + "sat_fin_nat \ I = sat \ I" + +definition convert_nat_db :: "(String.literal \ nat list) list \ + (nat table, String.literal) fo_intp" where + "convert_nat_db = convert_db" + +definition rbt_nat_fold :: "_ \ nat set_rbt \ _ \ _" where + "rbt_nat_fold = RBT_Set2.fold" + +definition rbt_nat_list_fold :: "_ \ (nat list) set_rbt \ _ \ _" where + "rbt_nat_list_fold = RBT_Set2.fold" + +definition rbt_sum_list_fold :: "_ \ ((nat + nat) list) set_rbt \ _ \ _" where + "rbt_sum_list_fold = RBT_Set2.fold" + +export_code eval_fin_nat sat_fin_nat fv_fo_fmla_list convert_nat_db rbt_nat_fold rbt_nat_list_fold + rbt_sum_list_fold Const Conj Inl Fin nat_of_integer integer_of_nat RBT_set + in OCaml module_name Eval_FO file_prefix verified + +(* Examples *) + +definition \ :: "(nat, String.literal) fo_fmla" where + "\ \ Exists 0 (Conj (FO.Eqa (Var 0) (Const 2)) (FO.Eqa (Var 0) (Var 1)))" + +value "eval_fin_nat \ (convert_nat_db [])" + +value "sat_fin_nat \ (convert_nat_db []) (\_. 0)" +value "sat_fin_nat \ (convert_nat_db []) (\_. 2)" + +definition \ :: "(nat, String.literal) fo_fmla" where + "\ \ Forall 2 (Disj (FO.Eqa (Var 2) (Const 42)) + (Exists 1 (Conj (FO.Pred (String.implode ''P'') [Var 0, Var 1]) + (Neg (FO.Pred (String.implode ''Q'') [Var 1, Var 2])))))" + +value "eval_fin_nat \ (convert_nat_db + [(String.implode ''P'', [1, 20]), + (String.implode ''P'', [9, 20]), + (String.implode ''P'', [2, 30]), + (String.implode ''P'', [3, 31]), + (String.implode ''P'', [4, 32]), + (String.implode ''P'', [5, 30]), + (String.implode ''P'', [6, 30]), + (String.implode ''P'', [7, 30]), + (String.implode ''Q'', [20, 42]), + (String.implode ''Q'', [30, 43])])" + +end diff --git a/thys/Eval_FO/Cluster.thy b/thys/Eval_FO/Cluster.thy new file mode 100644 --- /dev/null +++ b/thys/Eval_FO/Cluster.thy @@ -0,0 +1,218 @@ +theory Cluster + imports Mapping_Code +begin + +lemma these_Un[simp]: "Option.these (A \ B) = Option.these A \ Option.these B" + by (auto simp: Option.these_def) + +lemma these_insert[simp]: "Option.these (insert x A) = (case x of Some a \ insert a | None \ id) (Option.these A)" + by (auto simp: Option.these_def split: option.splits) force + +lemma these_image_Un[simp]: "Option.these (f ` (A \ B)) = Option.these (f ` A) \ Option.these (f ` B)" + by (auto simp: Option.these_def) + +lemma these_imageI: "f x = Some y \ x \ X \ y \ Option.these (f ` X)" + by (force simp: Option.these_def) + +lift_definition cluster :: "('b \ 'a option) \ 'b set \ ('a, 'b set) mapping" is + "\f Y x. if Some x \ f ` Y then Some {y \ Y. f y = Some x} else None" . + +lemma set_of_idx_cluster: "set_of_idx (cluster (Some \ f) X) = X" + by transfer (auto simp: ran_def) + +lemma lookup_cluster': "Mapping.lookup (cluster (Some \ h) X) y = (if y \ h ` X then None else Some {x \ X. h x = y})" + by transfer auto + +context ord +begin + +definition add_to_rbt :: "'a \ 'b \ ('a, 'b set) rbt \ ('a, 'b set) rbt" where + "add_to_rbt = (\(a, b) t. case rbt_lookup t a of Some X \ rbt_insert a (insert b X) t | None \ rbt_insert a {b} t)" + +abbreviation "add_option_to_rbt f \ (\b _ t. case f b of Some a \ add_to_rbt (a, b) t | None \ t)" + +definition cluster_rbt :: "('b \ 'a option) \ ('b, unit) rbt \ ('a, 'b set) rbt" where + "cluster_rbt f t = RBT_Impl.fold (add_option_to_rbt f) t RBT_Impl.Empty" + +end + +context linorder +begin + +lemma is_rbt_add_to_rbt: "is_rbt t \ is_rbt (add_to_rbt ab t)" + by (auto simp: add_to_rbt_def split: prod.splits option.splits) + +lemma is_rbt_fold_add_to_rbt: "is_rbt t' \ + is_rbt (RBT_Impl.fold (add_option_to_rbt f) t t')" + by (induction t arbitrary: t') (auto 0 0 simp: is_rbt_add_to_rbt split: option.splits) + +lemma is_rbt_cluster_rbt: "is_rbt (cluster_rbt f t)" + using is_rbt_fold_add_to_rbt Empty_is_rbt + by (fastforce simp: cluster_rbt_def) + +lemma rbt_insert_entries_None: "is_rbt t \ rbt_lookup t k = None \ + set (RBT_Impl.entries (rbt_insert k v t)) = insert (k, v) (set (RBT_Impl.entries t))" + by (auto simp: rbt_lookup_in_tree[symmetric] rbt_lookup_rbt_insert split: if_splits) + +lemma rbt_insert_entries_Some: "is_rbt t \ rbt_lookup t k = Some v' \ + set (RBT_Impl.entries (rbt_insert k v t)) = insert (k, v) (set (RBT_Impl.entries t) - {(k, v')})" + by (auto simp: rbt_lookup_in_tree[symmetric] rbt_lookup_rbt_insert split: if_splits) + +lemma keys_add_to_rbt: "is_rbt t \ set (RBT_Impl.keys (add_to_rbt (a, b) t)) = insert a (set (RBT_Impl.keys t))" + by (auto simp: add_to_rbt_def RBT_Impl.keys_def rbt_insert_entries_None rbt_insert_entries_Some split: option.splits) + +lemma keys_fold_add_to_rbt: "is_rbt t' \ set (RBT_Impl.keys (RBT_Impl.fold (add_option_to_rbt f) t t')) = + Option.these (f ` set (RBT_Impl.keys t)) \ set (RBT_Impl.keys t')" +proof (induction t arbitrary: t') + case (Branch col t1 k v t2) + have valid: "is_rbt (RBT_Impl.fold (add_option_to_rbt f) t1 t')" + using Branch(3) + by (auto intro: is_rbt_fold_add_to_rbt) + show ?case + proof (cases "f k") + case None + show ?thesis + by (auto simp: None Branch(2)[OF valid] Branch(1)[OF Branch(3)]) + next + case (Some a) + have valid': "is_rbt (add_to_rbt (a, k) (RBT_Impl.fold (add_option_to_rbt f) t1 t'))" + by (auto intro: is_rbt_add_to_rbt[OF valid]) + show ?thesis + by (auto simp: Some Branch(2)[OF valid'] keys_add_to_rbt[OF valid] Branch(1)[OF Branch(3)]) + qed +qed auto + +lemma rbt_lookup_add_to_rbt: "is_rbt t \ rbt_lookup (add_to_rbt (a, b) t) x = (if a = x then Some (case rbt_lookup t x of None \ {b} | Some Y \ insert b Y) else rbt_lookup t x)" + by (auto simp: add_to_rbt_def rbt_lookup_rbt_insert split: option.splits) + +lemma rbt_lookup_fold_add_to_rbt: "is_rbt t' \ rbt_lookup (RBT_Impl.fold (add_option_to_rbt f) t t') x = + (if x \ Option.these (f ` set (RBT_Impl.keys t)) \ set (RBT_Impl.keys t') then Some ({y \ set (RBT_Impl.keys t). f y = Some x} + \ (case rbt_lookup t' x of None \ {} | Some Y \ Y)) else None)" +proof (induction t arbitrary: t') + case Empty + then show ?case + using rbt_lookup_iff_keys(2,3)[OF is_rbt_rbt_sorted] + by (fastforce split: option.splits) +next + case (Branch col t1 k v t2) + have valid: "is_rbt (RBT_Impl.fold (add_option_to_rbt f) t1 t')" + using Branch(3) + by (auto intro: is_rbt_fold_add_to_rbt) + show ?case + proof (cases "f k") + case None + have fold_set: "x \ Option.these (f ` set (RBT_Impl.keys t2)) \ ((Option.these (f ` set (RBT_Impl.keys t1)) \ set (RBT_Impl.keys t'))) \ + x \ Option.these (f ` set (RBT_Impl.keys (Branch col t1 k v t2))) \ set (RBT_Impl.keys t')" + by (auto simp: None) + show ?thesis + unfolding fold_simps comp_def None option.case(1) Branch(2)[OF valid] keys_add_to_rbt[OF valid] keys_fold_add_to_rbt[OF Branch(3)] + rbt_lookup_add_to_rbt[OF valid] Branch(1)[OF Branch(3)] fold_set + using rbt_lookup_iff_keys(2,3)[OF is_rbt_rbt_sorted[OF Branch(3)]] + by (auto simp: None split: option.splits) (auto dest: these_imageI) + next + case (Some a) + have valid': "is_rbt (add_to_rbt (a, k) (RBT_Impl.fold (add_option_to_rbt f) t1 t'))" + by (auto intro: is_rbt_add_to_rbt[OF valid]) + have fold_set: "x \ Option.these (f ` set (RBT_Impl.keys t2)) \ (insert a (Option.these (f ` set (RBT_Impl.keys t1)) \ set (RBT_Impl.keys t'))) \ + x \ Option.these (f ` set (RBT_Impl.keys (Branch col t1 k v t2))) \ set (RBT_Impl.keys t')" + by (auto simp: Some) + have F1: "(case if P then Some X else None of None \ {k} | Some Y \ insert k Y) = + (if P then (insert k X) else {k})" for P X + by auto + have F2: "(case if a = x then Some X else if P then Some Y else None of None \ {} | Some Y \ Y) = + (if a = x then X else if P then Y else {})" + for P X and Y :: "'b set" + by auto + show ?thesis + unfolding fold_simps comp_def Some option.case(2) Branch(2)[OF valid'] keys_add_to_rbt[OF valid] keys_fold_add_to_rbt[OF Branch(3)] + rbt_lookup_add_to_rbt[OF valid] Branch(1)[OF Branch(3)] fold_set F1 F2 + using rbt_lookup_iff_keys(2,3)[OF is_rbt_rbt_sorted[OF Branch(3)]] + by (auto simp: Some split: option.splits) (auto dest: these_imageI) + qed +qed + +end + +context + fixes c :: "'a comparator" +begin + +definition add_to_rbt_comp :: "'a \ 'b \ ('a, 'b set) rbt \ ('a, 'b set) rbt" where + "add_to_rbt_comp = (\(a, b) t. case rbt_comp_lookup c t a of None \ rbt_comp_insert c a {b} t + | Some X \ rbt_comp_insert c a (insert b X) t)" + +abbreviation "add_option_to_rbt_comp f \ (\b _ t. case f b of Some a \ add_to_rbt_comp (a, b) t | None \ t)" + +definition cluster_rbt_comp :: "('b \ 'a option) \ ('b, unit) rbt \ ('a, 'b set) rbt" where + "cluster_rbt_comp f t = RBT_Impl.fold (add_option_to_rbt_comp f) t RBT_Impl.Empty" + +context + assumes c: "comparator c" +begin + +lemma add_to_rbt_comp: "add_to_rbt_comp = ord.add_to_rbt (lt_of_comp c)" + unfolding add_to_rbt_comp_def ord.add_to_rbt_def rbt_comp_lookup[OF c] rbt_comp_insert[OF c] + by simp + +lemma cluster_rbt_comp: "cluster_rbt_comp = ord.cluster_rbt (lt_of_comp c)" + unfolding cluster_rbt_comp_def ord.cluster_rbt_def add_to_rbt_comp + by simp + +end + +end + +lift_definition mapping_of_cluster :: "('b \ 'a :: ccompare option) \ ('b, unit) rbt \ ('a, 'b set) mapping_rbt" is + "cluster_rbt_comp ccomp" + using linorder.is_rbt_fold_add_to_rbt[OF comparator.linorder[OF ID_ccompare'] ord.Empty_is_rbt] + by (fastforce simp: cluster_rbt_comp[OF ID_ccompare'] ord.cluster_rbt_def) + +lemma cluster_code[code]: + fixes f :: "'b :: ccompare \ 'a :: ccompare option" and t :: "('b, unit) mapping_rbt" + shows "cluster f (RBT_set t) = (case ID CCOMPARE('a) of None \ + Code.abort (STR ''cluster: ccompare = None'') (\_. cluster f (RBT_set t)) + | Some c \ (case ID CCOMPARE('b) of None \ + Code.abort (STR ''cluster: ccompare = None'') (\_. cluster f (RBT_set t)) + | Some c' \ (RBT_Mapping (mapping_of_cluster f (RBT_Mapping2.impl_of t)))))" +proof - + { + fix c c' + assume assms: "ID ccompare = (Some c :: 'a comparator option)" "ID ccompare = (Some c' :: 'b comparator option)" + have c_def: "c = ccomp" + using assms(1) + by auto + have c'_def: "c' = ccomp" + using assms(2) + by auto + have c: "comparator (ccomp :: 'a comparator)" + using ID_ccompare'[OF assms(1)] + by (auto simp: c_def) + have c': "comparator (ccomp :: 'b comparator)" + using ID_ccompare'[OF assms(2)] + by (auto simp: c'_def) + note c_class = comparator.linorder[OF c] + note c'_class = comparator.linorder[OF c'] + have rbt_lookup_cluster: "ord.rbt_lookup cless (cluster_rbt_comp ccomp f t) = + (\x. if x \ Option.these (f ` (set (RBT_Impl.keys t))) then Some {y \ (set (RBT_Impl.keys t)). f y = Some x} else None)" + if "ord.is_rbt cless (t :: ('b, unit) rbt) \ ID ccompare = (None :: 'b comparator option)" for t + proof - + have is_rbt_t: "ord.is_rbt cless t" + using assms that + by auto + show ?thesis + unfolding cluster_rbt_comp[OF c] ord.cluster_rbt_def linorder.rbt_lookup_fold_add_to_rbt[OF c_class ord.Empty_is_rbt] + by (auto simp: ord.rbt_lookup.simps split: option.splits) + qed + have dom_ord_rbt_lookup: "ord.is_rbt cless t \ dom (ord.rbt_lookup cless t) = set (RBT_Impl.keys t)" for t :: "('b, unit) rbt" + using linorder.rbt_lookup_keys[OF c'_class] ord.is_rbt_def + by auto + have "cluster f (Collect (RBT_Set2.member t)) = Mapping (RBT_Mapping2.lookup (mapping_of_cluster f (mapping_rbt.impl_of t)))" + using assms(2)[unfolded c'_def] + by (transfer fixing: f) (auto simp: in_these_eq rbt_comp_lookup[OF c] rbt_comp_lookup[OF c'] rbt_lookup_cluster dom_ord_rbt_lookup) + } + then show ?thesis + unfolding RBT_set_def + by (auto split: option.splits) +qed + +end diff --git a/thys/Eval_FO/Eval_FO.thy b/thys/Eval_FO/Eval_FO.thy new file mode 100644 --- /dev/null +++ b/thys/Eval_FO/Eval_FO.thy @@ -0,0 +1,168 @@ +theory Eval_FO + imports Infinite FO +begin + +datatype 'a eval_res = Fin "'a table" | Infin | Wf_error + +locale eval_fo = + fixes wf :: "('a :: infinite, 'b) fo_fmla \ ('b \ nat \ 'a list set) \ 't \ bool" + and abs :: "('a fo_term) list \ 'a table \ 't" + and rep :: "'t \ 'a table" + and res :: "'t \ 'a eval_res" + and eval_bool :: "bool \ 't" + and eval_eq :: "'a fo_term \ 'a fo_term \ 't" + and eval_neg :: "nat list \ 't \ 't" + and eval_conj :: "nat list \ 't \ nat list \ 't \ 't" + and eval_ajoin :: "nat list \ 't \ nat list \ 't \ 't" + and eval_disj :: "nat list \ 't \ nat list \ 't \ 't" + and eval_exists :: "nat \ nat list \ 't \ 't" + and eval_forall :: "nat \ nat list \ 't \ 't" + assumes fo_rep: "wf \ I t \ rep t = proj_sat \ I" + and fo_res_fin: "wf \ I t \ finite (rep t) \ res t = Fin (rep t)" + and fo_res_infin: "wf \ I t \ \finite (rep t) \ res t = Infin" + and fo_abs: "finite (I (r, length ts)) \ wf (Pred r ts) I (abs ts (I (r, length ts)))" + and fo_bool: "wf (Bool b) I (eval_bool b)" + and fo_eq: "wf (Eqa trm trm') I (eval_eq trm trm')" + and fo_neg: "wf \ I t \ wf (Neg \) I (eval_neg (fv_fo_fmla_list \) t)" + and fo_conj: "wf \ I t\ \ wf \ I t\ \ (case \ of Neg \' \ False | _ \ True) \ + wf (Conj \ \) I (eval_conj (fv_fo_fmla_list \) t\ (fv_fo_fmla_list \) t\)" + and fo_ajoin: "wf \ I t\ \ wf \' I t\' \ + wf (Conj \ (Neg \')) I (eval_ajoin (fv_fo_fmla_list \) t\ (fv_fo_fmla_list \') t\')" + and fo_disj: "wf \ I t\ \ wf \ I t\ \ + wf (Disj \ \) I (eval_disj (fv_fo_fmla_list \) t\ (fv_fo_fmla_list \) t\)" + and fo_exists: "wf \ I t \ wf (Exists i \) I (eval_exists i (fv_fo_fmla_list \) t)" + and fo_forall: "wf \ I t \ wf (Forall i \) I (eval_forall i (fv_fo_fmla_list \) t)" +begin + +fun eval_fmla :: "('a, 'b) fo_fmla \ ('a table, 'b) fo_intp \ 't" where + "eval_fmla (Pred r ts) I = abs ts (I (r, length ts))" +| "eval_fmla (Bool b) I = eval_bool b" +| "eval_fmla (Eqa t t') I = eval_eq t t'" +| "eval_fmla (Neg \) I = eval_neg (fv_fo_fmla_list \) (eval_fmla \ I)" +| "eval_fmla (Conj \ \) I = (let ns\ = fv_fo_fmla_list \; ns\ = fv_fo_fmla_list \; + X\ = eval_fmla \ I in + case \ of Neg \' \ let X\' = eval_fmla \' I in + eval_ajoin ns\ X\ (fv_fo_fmla_list \') X\' + | _ \ eval_conj ns\ X\ ns\ (eval_fmla \ I))" +| "eval_fmla (Disj \ \) I = eval_disj (fv_fo_fmla_list \) (eval_fmla \ I) + (fv_fo_fmla_list \) (eval_fmla \ I)" +| "eval_fmla (Exists i \) I = eval_exists i (fv_fo_fmla_list \) (eval_fmla \ I)" +| "eval_fmla (Forall i \) I = eval_forall i (fv_fo_fmla_list \) (eval_fmla \ I)" + +lemma eval_fmla_correct: + fixes \ :: "('a :: infinite, 'b) fo_fmla" + assumes "wf_fo_intp \ I" + shows "wf \ I (eval_fmla \ I)" + using assms +proof (induction \ I rule: eval_fmla.induct) + case (1 r ts I) + then show ?case + using fo_abs + by auto +next + case (2 b I) + then show ?case + using fo_bool + by auto +next + case (3 t t' I) + then show ?case + using fo_eq + by auto +next + case (4 \ I) + then show ?case + using fo_neg + by auto +next + case (5 \ \ I) + have fins: "wf_fo_intp \ I" "wf_fo_intp \ I" + using 5(10) + by auto + have eval\: "wf \ I (eval_fmla \ I)" + using 5(1)[OF _ _ fins(1)] + by auto + show ?case + proof (cases "\\'. \ = Neg \'") + case True + then obtain \' where \_def: "\ = Neg \'" + by auto + have fin: "wf_fo_intp \' I" + using fins(2) + by (auto simp: \_def) + have eval\': "wf \' I (eval_fmla \' I)" + using 5(5)[OF _ _ _ \_def fin] + by auto + show ?thesis + unfolding \_def + using fo_ajoin[OF eval\ eval\'] + by auto + next + case False + then have eval\: "wf \ I (eval_fmla \ I)" + using 5 fins(2) + by (cases \) auto + have eval: "eval_fmla (Conj \ \) I = eval_conj (fv_fo_fmla_list \) (eval_fmla \ I) + (fv_fo_fmla_list \) (eval_fmla \ I)" + using False + by (auto simp: Let_def split: fo_fmla.splits) + show "wf (Conj \ \) I (eval_fmla (Conj \ \) I)" + using fo_conj[OF eval\ eval\, folded eval] False + by (auto split: fo_fmla.splits) + qed +next + case (6 \ \ I) + then show ?case + using fo_disj + by auto +next + case (7 i \ I) + then show ?case + using fo_exists + by auto +next + case (8 i \ I) + then show ?case + using fo_forall + by auto +qed + +definition eval :: "('a, 'b) fo_fmla \ ('a table, 'b) fo_intp \ 'a eval_res" where + "eval \ I = (if wf_fo_intp \ I then res (eval_fmla \ I) else Wf_error)" + +lemma eval_fmla_proj_sat: + fixes \ :: "('a :: infinite, 'b) fo_fmla" + assumes "wf_fo_intp \ I" + shows "rep (eval_fmla \ I) = proj_sat \ I" + using eval_fmla_correct[OF assms] + by (auto simp: fo_rep) + +lemma eval_sound: + fixes \ :: "('a :: infinite, 'b) fo_fmla" + assumes "eval \ I = Fin Z" + shows "Z = proj_sat \ I" +proof - + have "wf \ I (eval_fmla \ I)" + using eval_fmla_correct assms + by (auto simp: eval_def split: if_splits) + then show ?thesis + using assms fo_res_fin fo_res_infin + by (fastforce simp: eval_def fo_rep split: if_splits) +qed + +lemma eval_complete: + fixes \ :: "('a :: infinite, 'b) fo_fmla" + assumes "eval \ I = Infin" + shows "infinite (proj_sat \ I)" +proof - + have "wf \ I (eval_fmla \ I)" + using eval_fmla_correct assms + by (auto simp: eval_def split: if_splits) + then show ?thesis + using assms fo_res_fin + by (auto simp: eval_def fo_rep split: if_splits) +qed + +end + +end diff --git a/thys/Eval_FO/FO.thy b/thys/Eval_FO/FO.thy new file mode 100644 --- /dev/null +++ b/thys/Eval_FO/FO.thy @@ -0,0 +1,220 @@ +theory FO + imports Main +begin + +abbreviation "sorted_distinct xs \ sorted xs \ distinct xs" + +datatype 'a fo_term = Const 'a | Var nat + +type_synonym 'a val = "nat \ 'a" + +fun list_fo_term :: "'a fo_term \ 'a list" where + "list_fo_term (Const c) = [c]" +| "list_fo_term _ = []" + +fun fv_fo_term_list :: "'a fo_term \ nat list" where + "fv_fo_term_list (Var n) = [n]" +| "fv_fo_term_list _ = []" + +fun fv_fo_term_set :: "'a fo_term \ nat set" where + "fv_fo_term_set (Var n) = {n}" +| "fv_fo_term_set _ = {}" + +definition fv_fo_terms_set :: "('a fo_term) list \ nat set" where + "fv_fo_terms_set ts = \(set (map fv_fo_term_set ts))" + +fun fv_fo_terms_list_rec :: "('a fo_term) list \ nat list" where + "fv_fo_terms_list_rec [] = []" +| "fv_fo_terms_list_rec (t # ts) = fv_fo_term_list t @ fv_fo_terms_list_rec ts" + +definition fv_fo_terms_list :: "('a fo_term) list \ nat list" where + "fv_fo_terms_list ts = remdups_adj (sort (fv_fo_terms_list_rec ts))" + +fun eval_term :: "'a val \ 'a fo_term \ 'a" (infix "\" 60) where + "eval_term \ (Const c) = c" +| "eval_term \ (Var n) = \ n" + +definition eval_terms :: "'a val \ ('a fo_term) list \ 'a list" (infix "\" 60) where + "eval_terms \ ts = map (eval_term \) ts" + +lemma finite_set_fo_term: "finite (set_fo_term t)" + by (cases t) auto + +lemma list_fo_term_set: "set (list_fo_term t) = set_fo_term t" + by (cases t) auto + +lemma finite_fv_fo_term_set: "finite (fv_fo_term_set t)" + by (cases t) auto + +lemma fv_fo_term_setD: "n \ fv_fo_term_set t \ t = Var n" + by (cases t) auto + +lemma fv_fo_term_set_list: "set (fv_fo_term_list t) = fv_fo_term_set t" + by (cases t) auto + +lemma sorted_distinct_fv_fo_term_list: "sorted_distinct (fv_fo_term_list t)" + by (cases t) auto + +lemma fv_fo_term_set_cong: "fv_fo_term_set t = fv_fo_term_set (map_fo_term f t)" + by (cases t) auto + +lemma fv_fo_terms_setI: "Var m \ set ts \ m \ fv_fo_terms_set ts" + by (induction ts) (auto simp: fv_fo_terms_set_def) + +lemma fv_fo_terms_setD: "m \ fv_fo_terms_set ts \ Var m \ set ts" + by (induction ts) (auto simp: fv_fo_terms_set_def dest: fv_fo_term_setD) + +lemma finite_fv_fo_terms_set: "finite (fv_fo_terms_set ts)" + by (auto simp: fv_fo_terms_set_def finite_fv_fo_term_set) + +lemma fv_fo_terms_set_list: "set (fv_fo_terms_list ts) = fv_fo_terms_set ts" + using fv_fo_term_set_list + unfolding fv_fo_terms_list_def + by (induction ts rule: fv_fo_terms_list_rec.induct) + (auto simp: fv_fo_terms_set_def set_insort_key) + +lemma distinct_remdups_adj_sort: "sorted xs \ distinct (remdups_adj xs)" + by (induction xs rule: induct_list012) auto + +lemma sorted_distinct_fv_fo_terms_list: "sorted_distinct (fv_fo_terms_list ts)" + unfolding fv_fo_terms_list_def + by (induction ts rule: fv_fo_terms_list_rec.induct) + (auto simp add: sorted_insort intro: distinct_remdups_adj_sort) + +lemma fv_fo_terms_set_cong: "fv_fo_terms_set ts = fv_fo_terms_set (map (map_fo_term f) ts)" + using fv_fo_term_set_cong + by (induction ts) (fastforce simp: fv_fo_terms_set_def)+ + +lemma eval_term_cong: "(\n. n \ fv_fo_term_set t \ \ n = \' n) \ + eval_term \ t = eval_term \' t" + by (cases t) auto + +lemma eval_terms_fv_fo_terms_set: "\ \ ts = \' \ ts \ n \ fv_fo_terms_set ts \ \ n = \' n" +proof (induction ts) + case (Cons t ts) + then show ?case + by (cases t) (auto simp: eval_terms_def fv_fo_terms_set_def) +qed (auto simp: eval_terms_def fv_fo_terms_set_def) + +lemma eval_terms_cong: "(\n. n \ fv_fo_terms_set ts \ \ n = \' n) \ + eval_terms \ ts = eval_terms \' ts" + by (auto simp: eval_terms_def fv_fo_terms_set_def intro: eval_term_cong) + +datatype ('a, 'b) fo_fmla = + Pred 'b "('a fo_term) list" +| Bool bool +| Eqa "'a fo_term" "'a fo_term" +| Neg "('a, 'b) fo_fmla" +| Conj "('a, 'b) fo_fmla" "('a, 'b) fo_fmla" +| Disj "('a, 'b) fo_fmla" "('a, 'b) fo_fmla" +| Exists nat "('a, 'b) fo_fmla" +| Forall nat "('a, 'b) fo_fmla" + +fun fv_fo_fmla_list_rec :: "('a, 'b) fo_fmla \ nat list" where + "fv_fo_fmla_list_rec (Pred _ ts) = fv_fo_terms_list ts" +| "fv_fo_fmla_list_rec (Bool b) = []" +| "fv_fo_fmla_list_rec (Eqa t t') = fv_fo_term_list t @ fv_fo_term_list t'" +| "fv_fo_fmla_list_rec (Neg \) = fv_fo_fmla_list_rec \" +| "fv_fo_fmla_list_rec (Conj \ \) = fv_fo_fmla_list_rec \ @ fv_fo_fmla_list_rec \" +| "fv_fo_fmla_list_rec (Disj \ \) = fv_fo_fmla_list_rec \ @ fv_fo_fmla_list_rec \" +| "fv_fo_fmla_list_rec (Exists n \) = filter (\m. n \ m) (fv_fo_fmla_list_rec \)" +| "fv_fo_fmla_list_rec (Forall n \) = filter (\m. n \ m) (fv_fo_fmla_list_rec \)" + +definition fv_fo_fmla_list :: "('a, 'b) fo_fmla \ nat list" where + "fv_fo_fmla_list \ = remdups_adj (sort (fv_fo_fmla_list_rec \))" + +fun fv_fo_fmla :: "('a, 'b) fo_fmla \ nat set" where + "fv_fo_fmla (Pred _ ts) = fv_fo_terms_set ts" +| "fv_fo_fmla (Bool b) = {}" +| "fv_fo_fmla (Eqa t t') = fv_fo_term_set t \ fv_fo_term_set t'" +| "fv_fo_fmla (Neg \) = fv_fo_fmla \" +| "fv_fo_fmla (Conj \ \) = fv_fo_fmla \ \ fv_fo_fmla \" +| "fv_fo_fmla (Disj \ \) = fv_fo_fmla \ \ fv_fo_fmla \" +| "fv_fo_fmla (Exists n \) = fv_fo_fmla \ - {n}" +| "fv_fo_fmla (Forall n \) = fv_fo_fmla \ - {n}" + +lemma finite_fv_fo_fmla: "finite (fv_fo_fmla \)" + by (induction \ rule: fv_fo_fmla.induct) + (auto simp: finite_fv_fo_term_set finite_fv_fo_terms_set) + +lemma fv_fo_fmla_list_set: "set (fv_fo_fmla_list \) = fv_fo_fmla \" + unfolding fv_fo_fmla_list_def + by (induction \ rule: fv_fo_fmla.induct) (auto simp: fv_fo_terms_set_list fv_fo_term_set_list) + +lemma sorted_distinct_fv_list: "sorted_distinct (fv_fo_fmla_list \)" + by (auto simp: fv_fo_fmla_list_def intro: distinct_remdups_adj_sort) + +lemma length_fv_fo_fmla_list: "length (fv_fo_fmla_list \) = card (fv_fo_fmla \)" + using fv_fo_fmla_list_set[of \] sorted_distinct_fv_list[of \] + distinct_card[of "fv_fo_fmla_list \"] + by auto + +lemma fv_fo_fmla_list_eq: "fv_fo_fmla \ = fv_fo_fmla \ \ fv_fo_fmla_list \ = fv_fo_fmla_list \" + using fv_fo_fmla_list_set sorted_distinct_fv_list + by (metis sorted_distinct_set_unique) + +lemma fv_fo_fmla_list_Conj: "fv_fo_fmla_list (Conj \ \) = fv_fo_fmla_list (Conj \ \)" + using fv_fo_fmla_list_eq[of "Conj \ \" "Conj \ \"] + by auto + +type_synonym 'a table = "('a list) set" + +type_synonym ('t, 'b) fo_intp = "'b \ nat \ 't" + +fun wf_fo_intp :: "('a, 'b) fo_fmla \ ('a table, 'b) fo_intp \ bool" where + "wf_fo_intp (Pred r ts) I \ finite (I (r, length ts))" +| "wf_fo_intp (Bool b) I \ True" +| "wf_fo_intp (Eqa t t') I \ True" +| "wf_fo_intp (Neg \) I \ wf_fo_intp \ I" +| "wf_fo_intp (Conj \ \) I \ wf_fo_intp \ I \ wf_fo_intp \ I" +| "wf_fo_intp (Disj \ \) I \ wf_fo_intp \ I \ wf_fo_intp \ I" +| "wf_fo_intp (Exists n \) I \ wf_fo_intp \ I" +| "wf_fo_intp (Forall n \) I \ wf_fo_intp \ I" + +fun sat :: "('a, 'b) fo_fmla \ ('a table, 'b) fo_intp \ 'a val \ bool" where + "sat (Pred r ts) I \ \ \ \ ts \ I (r, length ts)" +| "sat (Bool b) I \ \ b" +| "sat (Eqa t t') I \ \ \ \ t = \ \ t'" +| "sat (Neg \) I \ \ \sat \ I \" +| "sat (Conj \ \) I \ \ sat \ I \ \ sat \ I \" +| "sat (Disj \ \) I \ \ sat \ I \ \ sat \ I \" +| "sat (Exists n \) I \ \ (\x. sat \ I (\(n := x)))" +| "sat (Forall n \) I \ \ (\x. sat \ I (\(n := x)))" + +lemma sat_fv_cong: "(\n. n \ fv_fo_fmla \ \ \ n = \' n) \ + sat \ I \ \ sat \ I \'" +proof (induction \ arbitrary: \ \') + case (Neg \) + show ?case + using Neg(1)[of \ \'] Neg(2) + by auto +next + case (Conj \ \) + show ?case + using Conj(1,2)[of \ \'] Conj(3) + by auto +next + case (Disj \ \) + show ?case + using Disj(1,2)[of \ \'] Disj(3) + by auto +next + case (Exists n \) + have "\x. sat \ I (\(n := x)) = sat \ I (\'(n := x))" + using Exists(2) + by (auto intro!: Exists(1)) + then show ?case + by simp +next + case (Forall n \) + have "\x. sat \ I (\(n := x)) = sat \ I (\'(n := x))" + using Forall(2) + by (auto intro!: Forall(1)) + then show ?case + by simp +qed (auto cong: eval_terms_cong eval_term_cong) + +definition proj_sat :: "('a, 'b) fo_fmla \ ('a table, 'b) fo_intp \ 'a table" where + "proj_sat \ I = (\\. map \ (fv_fo_fmla_list \)) ` {\. sat \ I \}" + +end \ No newline at end of file diff --git a/thys/Eval_FO/Infinite.thy b/thys/Eval_FO/Infinite.thy new file mode 100644 --- /dev/null +++ b/thys/Eval_FO/Infinite.thy @@ -0,0 +1,32 @@ +theory Infinite + imports Main +begin + +class infinite = + assumes infinite_UNIV: "infinite (UNIV :: 'a set)" +begin + +lemma arb_element: "finite Y \ \x :: 'a. x \ Y" + using ex_new_if_finite infinite_UNIV + by blast + +lemma arb_finite_subset: "finite Y \ \X :: 'a set. Y \ X = {} \ finite X \ n \ card X" +proof - + assume fin: "finite Y" + then obtain X where "X \ UNIV - Y" "finite X" "n \ card X" + using infinite_UNIV + by (metis Compl_eq_Diff_UNIV finite_compl infinite_arbitrarily_large order_refl) + then show ?thesis + by auto +qed + +lemma arb_countable_map: "finite Y \ \f :: (nat \ 'a). inj f \ range f \ UNIV - Y" + using infinite_UNIV + by (auto simp: infinite_countable_subset) + +end + +instance nat :: infinite + by standard auto + +end diff --git a/thys/Eval_FO/Mapping_Code.thy b/thys/Eval_FO/Mapping_Code.thy new file mode 100644 --- /dev/null +++ b/thys/Eval_FO/Mapping_Code.thy @@ -0,0 +1,61 @@ +theory Mapping_Code + imports "Containers.Mapping_Impl" +begin + +lift_definition set_of_idx :: "('a, 'b set) mapping \ 'b set" is + "\m. \(ran m)" . + +lemma set_of_idx_code[code]: + fixes t :: "('a :: ccompare, 'b set) mapping_rbt" + shows "set_of_idx (RBT_Mapping t) = + (case ID CCOMPARE('a) of None \ Code.abort (STR ''set_of_idx RBT_Mapping: ccompare = None'') (\_. set_of_idx (RBT_Mapping t)) + | Some _ \ \(snd ` set (RBT_Mapping2.entries t)))" + unfolding RBT_Mapping_def + by transfer (auto simp: ran_def rbt_comp_lookup[OF ID_ccompare'] ord.is_rbt_def linorder.rbt_lookup_in_tree[OF comparator.linorder[OF ID_ccompare']] split: option.splits)+ + +lemma mapping_combine[code]: + fixes t :: "('a :: ccompare, 'b) mapping_rbt" + shows "Mapping.combine f (RBT_Mapping t) (RBT_Mapping u) = + (case ID CCOMPARE('a) of None \ Code.abort (STR ''combine RBT_Mapping: ccompare = None'') (\_. Mapping.combine f (RBT_Mapping t) (RBT_Mapping u)) + | Some _ \ RBT_Mapping (RBT_Mapping2.join (\_. f) t u))" + by (auto simp add: Mapping.combine.abs_eq Mapping_inject lookup_join split: option.split) + +lift_definition mapping_join :: "('b \ 'b \ 'b) \ ('a, 'b) mapping \ ('a, 'b) mapping \ ('a, 'b) mapping" is + "\f m m' x. case m x of None \ None | Some y \ (case m' x of None \ None | Some y' \ Some (f y y'))" . + +lemma mapping_join_code[code]: + fixes t :: "('a :: ccompare, 'b) mapping_rbt" + shows "mapping_join f (RBT_Mapping t) (RBT_Mapping u) = + (case ID CCOMPARE('a) of None \ Code.abort (STR ''mapping_join RBT_Mapping: ccompare = None'') (\_. mapping_join f (RBT_Mapping t) (RBT_Mapping u)) + | Some _ \ RBT_Mapping (RBT_Mapping2.meet (\_. f) t u))" + by (auto simp add: mapping_join.abs_eq Mapping_inject lookup_meet split: option.split) + +context fixes dummy :: "'a :: ccompare" begin + +lift_definition diff :: + "('a, 'b) mapping_rbt \ ('a, 'b) mapping_rbt \ ('a, 'b) mapping_rbt" is "rbt_comp_minus ccomp" + by (auto 4 3 intro: linorder.rbt_minus_is_rbt ID_ccompare ord.is_rbt_rbt_sorted simp: rbt_comp_minus[OF ID_ccompare']) + +end + +context assumes ID_ccompare_neq_None: "ID CCOMPARE('a :: ccompare) \ None" +begin + +lemma lookup_diff: + "RBT_Mapping2.lookup (diff (t1 :: ('a, 'b) mapping_rbt) t2) = + (\k. case RBT_Mapping2.lookup t1 k of None \ None | Some v1 \ (case RBT_Mapping2.lookup t2 k of None \ Some v1 | Some v2 \ None))" + by transfer (auto simp add: fun_eq_iff linorder.rbt_lookup_rbt_minus[OF mapping_linorder] ID_ccompare_neq_None restrict_map_def split: option.splits) + +end + +lift_definition mapping_antijoin :: "('a, 'b) mapping \ ('a, 'b) mapping \ ('a, 'b) mapping" is + "\m m' x. case m x of None \ None | Some y \ (case m' x of None \ Some y | Some y' \ None)" . + +lemma mapping_antijoin_code[code]: + fixes t :: "('a :: ccompare, 'b) mapping_rbt" + shows "mapping_antijoin (RBT_Mapping t) (RBT_Mapping u) = + (case ID CCOMPARE('a) of None \ Code.abort (STR ''mapping_antijoin RBT_Mapping: ccompare = None'') (\_. mapping_antijoin (RBT_Mapping t) (RBT_Mapping u)) + | Some _ \ RBT_Mapping (diff t u))" + by (auto simp add: mapping_antijoin.abs_eq Mapping_inject lookup_diff split: option.split) + +end \ No newline at end of file diff --git a/thys/Eval_FO/ROOT b/thys/Eval_FO/ROOT new file mode 100644 --- /dev/null +++ b/thys/Eval_FO/ROOT @@ -0,0 +1,17 @@ +chapter AFP + +session Eval_FO (AFP) = Containers + + options [timeout=600] + theories + Ailamazyan_Code + Ailamazyan + Cluster + Eval_FO + FO + Infinite + Mapping_Code + document_files + "root.tex" + "root.bib" +export_files (in ".") [2] + "Eval_FO.Ailamazyan_Code:code/**" diff --git a/thys/Eval_FO/document/root.bib b/thys/Eval_FO/document/root.bib new file mode 100644 --- /dev/null +++ b/thys/Eval_FO/document/root.bib @@ -0,0 +1,45 @@ +@article{AGSS86, + author = {Ailamazyan, Alfred K. and Gilula, Mikhail M. and Stolboushkin, Alexei P. and Schwartz, Grigorii F.}, + title = {Reduction of a relational model with infinite domains to the case of finite domains}, + journal = {Dokl. Akad. Nauk SSSR}, + year = {1986}, + volume = {286}, + issue = {2}, + pages = {308--311}, + url = {http://mi.mathnet.ru/dan47310} +} + +@inproceedings{DBLP:conf/lics/AvronH91, + author = {Arnon Avron and + Yoram Hirshfeld}, + title = {On First Order Database Query Languages}, + booktitle = {Proceedings of the Sixth Annual Symposium on Logic in Computer Science + {(LICS} '91), Amsterdam, The Netherlands, July 15-18, 1991}, + pages = {226--231}, + publisher = {{IEEE} Computer Society}, + year = {1991}, + url = {https://doi.org/10.1109/LICS.1991.151647}, + doi = {10.1109/LICS.1991.151647}, + timestamp = {Wed, 16 Oct 2019 14:14:54 +0200}, + biburl = {https://dblp.org/rec/conf/lics/AvronH91.bib}, + bibsource = {dblp computer science bibliography, https://dblp.org} +} + +@inproceedings{DBLP:conf/stoc/Vardi82, + author = {Moshe Y. Vardi}, + editor = {Harry R. Lewis and + Barbara B. Simons and + Walter A. Burkhard and + Lawrence H. Landweber}, + title = {The Complexity of Relational Query Languages (Extended Abstract)}, + booktitle = {Proceedings of the 14th Annual {ACM} Symposium on Theory of Computing, + May 5-7, 1982, San Francisco, California, {USA}}, + pages = {137--146}, + publisher = {{ACM}}, + year = {1982}, + url = {https://doi.org/10.1145/800070.802186}, + doi = {10.1145/800070.802186}, + timestamp = {Wed, 14 Nov 2018 10:51:38 +0100}, + biburl = {https://dblp.org/rec/conf/stoc/Vardi82.bib}, + bibsource = {dblp computer science bibliography, https://dblp.org} +} diff --git a/thys/Eval_FO/document/root.tex b/thys/Eval_FO/document/root.tex new file mode 100644 --- /dev/null +++ b/thys/Eval_FO/document/root.tex @@ -0,0 +1,70 @@ +\documentclass[10pt,a4paper]{article} +\usepackage[T1]{fontenc} +\usepackage{isabelle,isabellesym} +\usepackage{a4wide} +\usepackage[english]{babel} +\usepackage{eufrak} +\usepackage{amssymb} + +% this should be the last package used +\usepackage{pdfsetup} + +% urls in roman style, theory text in math-similar italics +\urlstyle{rm} +\isabellestyle{literal} + + +\begin{document} + +\title{First-Order Query Evaluation} +\author{Martin Raszyk} + +\maketitle + +\begin{abstract} +We formalize first-order query evaluation over an infinite domain with equality. +We first define the syntax and semantics of first-order logic with equality. +Next we define a locale $\mathit{eval\_fo}$ abstracting a representation of a +potentially infinite set of tuples satisfying a first-order query over finite +relations. Inside the locale, we define a function $\mathit{eval}$ checking if +the set of tuples satisfying a first-order query over a database (an +interpretation of the query's predicates) is finite (i.e., deciding +\emph{relative safety}) and computing the set of satisfying tuples if it is +finite. Altogether the function $\mathit{eval}$ solves +\emph{capturability}~\cite{DBLP:conf/lics/AvronH91} of first-order logic with +equality. We also use the function $\mathit{eval}$ to prove a code equation for +the semantics of first-order logic, i.e., the function checking if a first-order +query over a database is satisfied by a variable assignment. + +We provide an interpretation of the locale $\mathit{eval\_fo}$ based on the +approach by Ailamazyan et al.~\cite{AGSS86}. A core notion in the interpretation +is the active domain of a query and a database that contains all domain elements +that occur in the database or interpret the query's constants. We prove the main +theorem of Ailamazyan et al.~\cite{AGSS86} relating the satisfaction of a +first-order query over an infinite domain to the satisfaction of this query over +a finite domain consisting of the active domain and a few additional domain +elements (outside the active domain) whose number only depends on the query. In +our interpretation of the locale $\mathit{eval\_fo}$, we use a potentially +higher number of the additional domain elements, but their number still only +depends on the query and thus has no effect on the data +complexity~\cite{DBLP:conf/stoc/Vardi82} of query evaluation. Our interpretation +yields an \emph{executable} function $\mathit{eval}$. The time complexity of +$\mathit{eval}$ on a query is linear in the total number of tuples in the +intermediate relations for the subqueries. Specifically, we build a database +index to evaluate a conjunction. We also optimize the case of a negated subquery +in a conjunction. Finally, we export code for the infinite domain of natural +numbers. +\end{abstract} + +\tableofcontents + +% sane default for proof documents +\parindent 0pt\parskip 0.5ex + +% generated text of all theories +\input{session} + +\bibliographystyle{abbrv} +\bibliography{root} + +\end{document} diff --git a/thys/ROOTS b/thys/ROOTS --- a/thys/ROOTS +++ b/thys/ROOTS @@ -1,662 +1,666 @@ 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 Actuarial_Mathematics 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 BD_Security_Compositional BNF_CC BNF_Operations BTree Banach_Steinhaus Belief_Revision Bell_Numbers_Spivey BenOr_Kozen_Reif 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 CSP_RefTK CYK CZH_Elementary_Categories CZH_Foundations CZH_Universal_Constructions 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 CoCon CoSMeDis CoSMed CofGroups Coinductive Coinductive_Languages Collections Combinatorics_Words Combinatorics_Words_Graph_Lemma Combinatorics_Words_Lyndon Comparison_Sort_Lower_Bound Compiling-Exceptions-Correctly Complete_Non_Orders Completeness Complex_Bounded_Operators Complex_Geometry Complx ComponentDependencies ConcurrentGC ConcurrentIMP Concurrent_Ref_Alg Concurrent_Revisions Conditional_Simplification Conditional_Transfer_Rule Consensus_Refined Constructive_Cryptography Constructive_Cryptography_CM Constructor_Funs Containers CoreC++ Core_DOM Core_SC_DOM Correctness_Algebras Count_Complex_Roots CryptHOL CryptoBasedCompositionalProperties Cubic_Quartic_Equations DFS_Framework DOM_Components 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 Design_Theory Dict_Construction Differential_Dynamic_Logic Differential_Game_Logic Dijkstra_Shortest_Path Diophantine_Eqns_Lin_Hom Dirichlet_L Dirichlet_Series DiscretePricing Discrete_Summation DiskPaxos Dominance_CHK DynamicArchitectures Dynamic_Tables E_Transcendental Echelon_Form EdmondsKarp_Maxflow Efficient-Mergesort Elliptic_Curves_Group_Law Encodability_Process_Calculi Epistemic_Logic Equivalence_Relation_Enumeration Ergodic_Theory Error_Function Euler_MacLaurin Euler_Partition +Eval_FO Example-Submission Extended_Finite_State_Machine_Inference Extended_Finite_State_Machines FFT FLP FOL-Fitting FOL_Axiomatic FOL_Harrison FOL_Seq_Calc1 FOL_Seq_Calc2 Factor_Algebraic_Polynomial Factored_Transition_System_Bounding Falling_Factorial_Sum Farkas FeatherweightJava Featherweight_OCL Fermat3_4 FileRefinement FinFun Finger-Trees Finite-Map-Extras Finite_Automata_HF Finitely_Generated_Abelian_Groups 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 Foundation_of_geometry Fourier FO_Theory_Rewriting Free-Boolean-Algebra Free-Groups Fresh_Identifiers FunWithFunctions FunWithTilings Functional-Automata Functional_Ordered_Resolution_Prover Furstenberg_Topology GPU_Kernel_PL Gabow_SCC GaleStewart_Games Gale_Shapley 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 Grothendieck_Schemes Group-Ring-Module HOL-CSP HOLCF-Prelude HRB-Slicing Hahn_Jordan_Decomposition 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 Hyperdual IEEE_Floating_Point IFC_Tracking IMAP-CRDT IMO2019 IMP2 IMP2_Binary_Heap IMP_Compiler IP_Addresses Imperative_Insertion_Sort Impossible_Geometry Incompleteness Incredible_Proof_Machine Inductive_Confidentiality Inductive_Inference InfPathElimination InformationFlowSlicing InformationFlowSlicing_Inter Integration Interpolation_Polynomials_HOL_Algebra Interpreter_Optimizations Interval_Arithmetic_Word32 Intro_Dest_Elim Iptables_Semantics Irrational_Series_Erdos_Straus Irrationality_J_Hancl Irrationals_From_THEBOOK IsaGeoCoq Isabelle_C Isabelle_Marries_Dirac Isabelle_Meta_Model 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 Knights_Tour 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 Lifting_the_Exponent 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 Logging_Independent_Anonymity Lowe_Ontological_Argument Lower_Semicontinuous Lp LP_Duality Lucas_Theorem MDP-Algorithms MDP-Rewards 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_Method Median_Of_Medians_Selection Menger Mereology Mersenne_Primes Metalogic_ProofChecker MiniML MiniSail Minimal_SSA Minkowskis_Theorem Minsky_Machines Modal_Logics_for_NTS Modular_Assembly_Kit_Security Modular_arithmetic_LLL_and_HNF_algorithms 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 PAL PCF PLM POPLmark-deBruijn PSemigroupsConvolution Padic_Ints 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 Progress_Tracking Projective_Geometry Projective_Measurements Promela Proof_Strategy_Language PropResPI Propositional_Proof_Systems Prpu_Maxflow PseudoHoops Psi_Calculi Ptolemys_Theorem Public_Announcement_Logic QHLProver QR_Decomposition Quantales Quasi_Borel_Spaces 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 Real_Power Recursion-Addition Recursion-Theory-I Refine_Imperative_HOL Refine_Monadic RefinementReactive Regex_Equivalence Registers Regression_Test_Selection Regular-Sets Regular_Algebras Regular_Tree_Relations Relation_Algebra Relational-Incorrectness-Logic Relational_Disjoint_Set_Forests Relational_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 Roth_Arithmetic_Progressions Routing Roy_Floyd_Warshall SATSolverVerification SC_DOM_Components SDS_Impossibility SIFPL SIFUM_Type_Systems SPARCv8 Safe_Distance Safe_OCL Saturation_Framework Saturation_Framework_Extensions Schutz_Spacetime Secondary_Sylow Security_Protocol_Refinement Selection_Heap_Sort SenSocialChoice Separata Separation_Algebra Separation_Logic_Imperative_HOL SequentInvertibility Shadow_DOM Shadow_SC_DOM Shivers-CFA ShortestPath Show Sigma_Commit_Crypto Signature_Groebner Simpl Simple_Firewall Simplex Simplicial_complexes_and_boolean_functions SimplifiedOntologicalArgument Skew_Heap Skip_Lists Slicing Sliding_Window_Algorithm Smith_Normal_Form Smooth_Manifolds Sort_Encodings Source_Coding_Theorem SpecCheck 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 Szemeredi_Regularity Szpilrajn TESL_Language TLA Tail_Recursive_Functions Tarskis_Geometry Taylor_Models Three_Circles 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 Types_To_Sets_Extension UPF UPF_Firewall UTP +Universal_Hash_Families Universal_Turing_Machine UpDown_Scheme Valuation Van_Emde_Boas_Trees Van_der_Waerden VectorSpace VeriComp Verified-Prover Verified_SAT_Based_AI_Planning VerifyThis2018 VerifyThis2019 Vickrey_Clarke_Groves Virtual_Substitution VolpanoSmith +VYDRA_MDL WHATandWHERE_Security WOOT_Strong_Eventual_Consistency WebAssembly Weight_Balanced_Trees Weighted_Path_Order Well_Quasi_Orders +Wetzels_Problem Winding_Number_Eval Word_Lib WorkerWrapper X86_Semantics XML Youngs_Inequality ZFC_in_HOL Zeta_3_Irrational Zeta_Function pGCL diff --git a/thys/Universal_Hash_Families/Carter_Wegman_Hash_Family.thy b/thys/Universal_Hash_Families/Carter_Wegman_Hash_Family.thy new file mode 100644 --- /dev/null +++ b/thys/Universal_Hash_Families/Carter_Wegman_Hash_Family.thy @@ -0,0 +1,293 @@ +section \Carter-Wegman Hash Family\label{sec:carter_wegman}\ + +theory Carter_Wegman_Hash_Family + imports + Interpolation_Polynomials_HOL_Algebra.Interpolation_Polynomial_Cardinalities + Preliminary_Results +begin + +text \The Carter-Wegman hash family is a generic method to obtain +$k$-universal hash families for arbitrary $k$. (There are faster solutions, such as tabulation +hashing, which are limited to a specific $k$. See for example \cite{thorup2010}.) + +The construction was described by Wegman and Carter~\cite{wegman1981}, it is a hash +family between the elements of a finite field and works by choosing randomly a polynomial +over the field with degree less than $k$. The hash function is the evaluation of a such a +polynomial. + +Using the property that the fraction of polynomials interpolating a given set of $s \leq k$ +points is @{term "1/(card (carrier R)^s)"}, which is shown in +\cite{Interpolation_Polynomials_HOL_Algebra-AFP}, it is possible to obtain both that +the hash functions are $k$-wise independent and uniformly distributed. + +In the following two locales are introduced, the main reason for both is to make the statements +of the theorems and proofs more concise. The first locale @{term "poly_hash_family"} fixes a finite +ring $R$ and the probability space of the polynomials of degree less than $k$. Because the ring is +not a field, the family is not yet $k$-universal, but it is still possible to state a few results such +as the fact that the range of the hash function is a subset of the carrier of the ring. + +The second locale @{term "carter_wegman_hash_family"} is an extension of the former with the +assumption that $R$ is a field with which the $k$-universality follows. + +The reason for using two separate locales is to support use cases, where the ring is only probably +a field. For example if it is the set of integers modulo an approximate prime, in such a situation a +subset of the properties of an algorithm using approximate primes would need to be verified +even if $R$ is only a ring.\ + +definition (in ring) "hash x \ = eval \ x" + +locale poly_hash_family = ring + + fixes k :: nat + assumes finite_carrier[simp]: "finite (carrier R)" + assumes k_ge_0: "k > 0" +begin + +definition space where "space = bounded_degree_polynomials R k" +definition M where "M = measure_pmf (pmf_of_set space)" + +lemma finite_space[simp]:"finite space" + unfolding space_def using fin_degree_bounded finite_carrier by simp + +lemma non_empty_bounded_degree_polynomials[simp]:"space \ {}" + unfolding space_def using non_empty_bounded_degree_polynomials by simp + +text \This is to add @{thm [source] carrier_not_empty} to the simp set in the context of +@{locale "poly_hash_family"}:\ + +lemma non_empty_carrier[simp]: "carrier R \ {}" + by (simp add:carrier_not_empty) + +sublocale prob_space "M" + by (simp add:M_def prob_space_measure_pmf) + +lemma hash_range[simp]: + assumes "\ \ space" + assumes "x \ carrier R" + shows "hash x \ \ carrier R" + using assms unfolding hash_def space_def bounded_degree_polynomials_def + by (simp, metis eval_in_carrier polynomial_incl univ_poly_carrier) + +lemma hash_range_2: + assumes "\ \ space" + shows "(\x. hash x \) ` carrier R \ carrier R" + using hash_range assms by auto + +lemma integrable_M[simp]: + fixes f :: "'a list \ 'c::{banach, second_countable_topology}" + shows "integrable M f" + unfolding M_def + by (rule integrable_measure_pmf_finite, simp) + +end + +locale carter_wegman_hash_family = poly_hash_family + + assumes field_R: "field R" +begin +sublocale field + using field_R by simp + +abbreviation "field_size \ card (carrier R)" + +lemma poly_cards: + assumes "K \ carrier R" + assumes "card K \ k" + assumes "y ` K \ (carrier R)" + shows + "card {\ \ space. (\k \ K. eval \ k = y k)} = field_size^(k-card K)" + unfolding space_def + using interpolating_polynomials_card[where n="k-card K" and K="K"] assms + using finite_carrier finite_subset by fastforce + +lemma poly_cards_single: + assumes "x \ carrier R" + assumes "y \ carrier R" + shows "card {\ \ space. eval \ x = y} = field_size^(k-1)" + using poly_cards[where K="{x}" and y="\_. y", simplified] assms k_ge_0 by simp + +lemma hash_prob: + assumes "K \ carrier R" + assumes "card K \ k" + assumes "y ` K \ carrier R" + shows + "prob {\. (\x \ K. hash x \ = y x)} = 1/(real field_size)^card K" +proof - + have "\ \ carrier R" by simp + + hence a:"field_size > 0" + using finite_carrier card_gt_0_iff by blast + + have b:"real (card {\ \ space. \x\K. eval \ x = y x}) / real (card space) = + 1 / real field_size ^ card K" + using a assms(2) + apply (simp add: frac_eq_eq poly_cards[OF assms(1,2,3)] power_add[symmetric]) + by (simp add:space_def bounded_degree_polynomials_card) + + show ?thesis + unfolding M_def + by (simp add:hash_def measure_pmf_of_set Int_def b) +qed + +lemma prob_single: + assumes "x \ carrier R" "y \ carrier R" + shows "prob {\. hash x \ = y} = 1/(real field_size)" + using hash_prob[where K="{x}"] assms finite_carrier k_ge_0 by simp + +lemma prob_range: + assumes [simp]:"x \ carrier R" + shows "prob {\. hash x \ \ A} = card (A \ carrier R) / field_size" +proof - + have "prob {\. hash x \ \ A} = prob (\a \ A \ carrier R. {\. hash x \ = a})" + by (rule measure_pmf_eq, auto simp:M_def) + also have "... = (\ a \ (A \ carrier R). prob {\. hash x \ = a})" + by (rule measure_finite_Union, auto simp:M_def disjoint_family_on_def) + also have "... = (\ a \ (A \ carrier R). 1/(real field_size))" + by (rule sum.cong, auto simp:prob_single) + also have "... = card (A \ carrier R) / field_size" + by simp + finally show ?thesis by simp +qed + +lemma indep: + assumes "J \ carrier R" + assumes "card J \ k" + shows "indep_vars (\_. discrete) hash J" +proof - + have "\ \ carrier R" by simp + hence card_R_ge_0:"field_size > 0" + using card_gt_0_iff finite_carrier by blast + + have fin_J: "finite J" + using finite_carrier assms(1) finite_subset by blast + + show ?thesis + proof (rule indep_vars_pmf[OF M_def]) + fix a + fix J' + assume a: "J' \ J" "finite J'" + have card_J': "card J' \ k" + by (metis card_mono order_trans a(1) assms(2) fin_J) + have J'_in_carr: "J' \ carrier R" by (metis order_trans a(1) assms(1)) + + show "prob {\. \x\J'. hash x \ = a x} = (\x\J'. prob {\. hash x \ = a x})" + proof (cases "a ` J' \ carrier R") + case True + have a_carr: "\x. x \ J' \ a x \ carrier R" using True by force + have "prob {\. \x\J'. hash x \ = a x} = + real (card {\ \ space. \x\J'. eval \ x = a x}) / real (card space)" + by (simp add:M_def measure_pmf_of_set Int_def hash_def) + also have "... = real (field_size ^ (k - card J')) / real (card space)" + using True by (simp add: poly_cards[OF J'_in_carr card_J']) + also have + "... = real field_size ^ (k - card J') / real field_size ^ k" + by (simp add:space_def bounded_degree_polynomials_card) + also have + "... = real field_size ^ ((k - 1) * card J') / real field_size ^ (k * card J')" + using card_J' by (simp add:power_add[symmetric] power_mult[symmetric] + diff_mult_distrib frac_eq_eq add.commute) + also have + "... = (real field_size ^ (k - 1)) ^ card J' / (real field_size ^ k) ^ card J'" + by (simp add:power_add power_mult) + also have + "... = (\x\J'. real (card {\ \ space. eval \ x = a x}) / real (card space))" + using a_carr poly_cards_single[OF subsetD[OF J'_in_carr]] + by (simp add:space_def bounded_degree_polynomials_card power_divide) + also have "... = (\x\J'. prob {\. hash x \ = a x})" + by (simp add:measure_pmf_of_set M_def Int_def hash_def) + finally show ?thesis by simp + next + case False + then obtain j where j_def: "j \ J'" "a j \ carrier R" by blast + have "{\ \ space. hash j \ = a j} \ {\ \ space. hash j \ \ carrier R}" + by (rule subsetI, simp add:j_def) + also have "... \ {}" using j_def(1) J'_in_carr hash_range by blast + finally have b:"{\ \ space. hash j \ = a j} = {}" by simp + hence "real (card ({\ \ space. hash j \ = a j})) = 0" by simp + hence "(\x\J'. real (card {\ \ space. hash x \ = a x})) = 0" + using a(2) prod_zero[OF a(2)] j_def(1) by auto + moreover have + "{\ \ space. \x\J'. hash x \ = a x} \ {\ \ space. hash j \ = a j}" + using j_def by blast + hence "{\ \ space. \x\J'. hash x \ = a x} = {}" using b by blast + ultimately show ?thesis + by (simp add:measure_pmf_of_set M_def Int_def prod_dividef) + qed + qed +qed + +lemma k_wise_indep: + "k_wise_indep_vars k (\_. discrete) hash (carrier R)" + unfolding k_wise_indep_vars_def using indep by simp + +lemma inj_if_degree_1: + assumes "\ \ space" + assumes "degree \ = 1" + shows "inj_on (\x. hash x \) (carrier R)" + using assms eval_inj_if_degree_1 + by (simp add:M_def space_def bounded_degree_polynomials_def hash_def) + +lemma uniform: + assumes "i \ carrier R" + shows "uniform_on (hash i) (carrier R)" +proof - + have a: + "\a. prob {\. hash i \ \ {a}} = indicat_real (carrier R) a / real field_size" + by (subst prob_range[OF assms], simp add:indicator_def) + show ?thesis + by (rule uniform_onI, use a M_def in auto) +qed + +text \This the main result of this section - the Carter-Wegman hash family is $k$-universal.\ + +theorem k_universal: + "k_universal k hash (carrier R) (carrier R)" + using uniform k_wise_indep by (simp add:k_universal_def) + +end + +lemma poly_hash_familyI: + assumes "ring R" + assumes "finite (carrier R)" + assumes "0 < k" + shows "poly_hash_family R k" + using assms + by (simp add:poly_hash_family_def poly_hash_family_axioms_def) + +lemma carter_wegman_hash_familyI: + assumes "field F" + assumes "finite (carrier F)" + assumes "0 < k" + shows "carter_wegman_hash_family F k" + using assms field.is_ring[OF assms(1)] poly_hash_familyI + by (simp add:carter_wegman_hash_family_def carter_wegman_hash_family_axioms_def) + +lemma hash_k_wise_indep: + assumes "field F \ finite (carrier F)" + assumes "1 \ n" + shows + "prob_space.k_wise_indep_vars (pmf_of_set (bounded_degree_polynomials F n)) n + (\_. pmf_of_set (carrier F)) (ring.hash F) (carrier F)" +proof - + interpret carter_wegman_hash_family "F" "n" + using assms carter_wegman_hash_familyI by force + have "k_wise_indep_vars n (\_. pmf_of_set (carrier F)) hash (carrier F)" + by (rule k_wise_indep_vars_compose[OF k_wise_indep], simp) + thus ?thesis + by (simp add:M_def space_def) +qed + +lemma hash_prob_single: + assumes "field F \ finite (carrier F)" + assumes "x \ carrier F" + assumes "1 \ n" + assumes "y \ carrier F" + shows + "\

(\ in pmf_of_set (bounded_degree_polynomials F n). ring.hash F x \ = y) + = 1/(real (card (carrier F)))" +proof - + interpret carter_wegman_hash_family "F" "n" + using assms carter_wegman_hash_familyI by force + show ?thesis + using prob_single[OF assms(2,4)] by (simp add:M_def space_def) +qed + +end diff --git a/thys/Universal_Hash_Families/Definitions.thy b/thys/Universal_Hash_Families/Definitions.thy new file mode 100644 --- /dev/null +++ b/thys/Universal_Hash_Families/Definitions.thy @@ -0,0 +1,81 @@ +section \Introduction and Definition\ + +theory Definitions + imports "HOL-Probability.Independent_Family" +begin + +text \Universal hash families are commonly used in randomized algorithms and data structures to +randomize the input of algorithms, such that probabilistic methods can be employed without requiring +any assumptions about the input distribution. + +If we regard a family of hash functions from a domain $D$ to a finite range $R$ as a uniform probability +space, then the family is $k$-universal if: +\begin{itemize} +\item For each $x \in D$ the evaluation of the functions at $x$ forms a uniformly distributed random variable on $R$. +\item The evaluation random variables for $k$ or fewer distinct domain elements form an +independent family of random variables. +\end{itemize} + +This definition closely follows the definition from Vadhan~\cite[\textsection 3.5.5]{vadhan2012}, with the minor +modification that independence is required not only for exactly $k$, but also for \emph{fewer} than $k$ distinct +domain elements. The correction is due to the fact that in the corner case where $D$ has fewer than $k$ elements, +the second part of their definition becomes void. In the formalization this helps avoid an unnecessary assumption in +the theorems. + +The following definition introduces the notion of $k$-wise independent random variables:\ + +definition (in prob_space) k_wise_indep_vars where + "k_wise_indep_vars k M' X I = + (\J \ I. card J \ k \ finite J \ indep_vars M' X J)" + +lemma (in prob_space) k_wise_indep_vars_subset: + assumes "k_wise_indep_vars k M' X I" + assumes "J \ I" + assumes "finite J" + assumes "card J \ k" + shows "indep_vars M' X J" + using assms + by (simp add:k_wise_indep_vars_def) + +text \Similarly for a finite non-empty set $A$ the predicate @{term "uniform_on X A"} indicates that +the random variable is uniformly distributed on $A$:\ + +definition (in prob_space) "uniform_on X A = ( + distr M (count_space UNIV) X = uniform_measure (count_space UNIV) A \ + A \ {} \ finite A \ random_variable (count_space UNIV) X)" + +lemma (in prob_space) uniform_onD: + assumes "uniform_on X A" + shows "prob {\ \ space M. X \ \ B} = card (A \ B) / card A" +proof - + have "prob {\ \ space M. X \ \ B} = prob (X -` B \ space M)" + by (subst Int_commute, simp add:vimage_def Int_def) + also have "... = measure (distr M (count_space UNIV) X) B" + using assms by (subst measure_distr, auto simp:uniform_on_def) + also have "... = measure (uniform_measure (count_space UNIV) A) B" + using assms by (simp add:uniform_on_def) + also have "... = card (A \ B) / card A" + using assms by (subst measure_uniform_measure, auto simp:uniform_on_def)+ + finally show ?thesis by simp +qed + +text \With the two previous definitions it is possible to define the $k$-universality condition for a family +of hash functions from $D$ to $R$:\ + +definition (in prob_space) "k_universal k X D R = ( + k_wise_indep_vars k (\_. count_space UNIV) X D \ + (\i \ D. uniform_on (X i) R))" + +text \Note: The definition is slightly more generic then the informal specification from above. +This is because usually a family is formed by a single function with a variable seed parameter. Instead of +choosing a random function from a probability space, a random seed is chosen from the probability space +which parameterizes the hash function. + +The following section contains some preliminary results about independent families +of random variables. +Section~\ref{sec:carter_wegman} introduces the Carter-Wegman hash family, which is an +explicit construction of $k$-universal families for arbitrary $k$ using polynomials over finite fields. +The last section contains a proof that the factor ring of the integers modulo a prime ideal is a finite field, +followed by an isomorphic construction of prime fields over an initial segment of the natural numbers.\ + +end diff --git a/thys/Universal_Hash_Families/Field.thy b/thys/Universal_Hash_Families/Field.thy new file mode 100644 --- /dev/null +++ b/thys/Universal_Hash_Families/Field.thy @@ -0,0 +1,389 @@ +section \Finite Fields\ + +theory Field + imports "HOL-Algebra.Ring_Divisibility" "HOL-Algebra.IntRing" +begin + +text \This section contains a proof that the factor ring @{term "ZFact p"} for +@{term [names_short] "prime p"} is a field. Note that the bulk of the work has already been done in +HOL-Algebra, in particular it is established that @{term "ZFact p"} is a domain. + +However, any domain with a finite carrier is already a field. This can be seen by establishing that +multiplication by a non-zero element is an injective map between the elements of the carrier of the +domain. But an injective map between sets of the same non-finite cardinality is also surjective. +Hence it is possible to find the unit element in the image of such a map. + +The following definition introduces the canonical embedding of @{term "{..<(p::nat)}"} into @{term "ZFact p"}. +It will be shown that it is a bijection which establishes that @{term "ZFact p"} is finite.\ + +definition zfact_iso :: "nat \ nat \ int set" where + "zfact_iso p k = Idl\<^bsub>\\<^esub> {int p} +>\<^bsub>\\<^esub> (int k)" + +context + fixes n :: nat + fixes I :: "int set" + assumes n_ge_0: "n > 0" + defines "I \ Idl\<^bsub>\\<^esub> {int n}" +begin + +lemma ideal_I: "ideal I \" + unfolding I_def by (simp add: int.genideal_ideal) + +lemma zfact_iso_inj: + "inj_on (zfact_iso n) {.. {.. {..\<^bsub>\\<^esub> (int x) = I +>\<^bsub>\\<^esub> (int y)" + by (simp add:zfact_iso_def I_def) + hence "int x - int y \ I" + by (subst int.quotient_eq_iff_same_a_r_cos[OF ideal_I], auto) + hence "int x mod int n = int y mod int n" + unfolding I_def + by (meson Idl_subset_eq_dvd int_Idl_subset_ideal mod_eq_dvd_iff) + thus "x = y" + using a b by simp +qed + +lemma I_shift: + assumes "u mod (int n) = v mod (int n)" + shows "I +>\<^bsub>\\<^esub> u = I +>\<^bsub>\\<^esub> v" +proof - + have "u - v \ I" + unfolding I_def + by (metis Idl_subset_eq_dvd assms int_Idl_subset_ideal mod_eq_dvd_iff) + thus ?thesis + using ideal_I int.quotient_eq_iff_same_a_r_cos by simp +qed + +lemma zfact_iso_ran: + "zfact_iso n ` {.. carrier (ZFact (int n))" + unfolding zfact_iso_def ZFact_def FactRing_simps + using int.a_rcosetsI by auto + moreover have "\x. x \ carrier (ZFact (int n)) \ x \ zfact_iso n ` {.. carrier (ZFact (int n))" + then obtain y where y_def: "x = I +>\<^bsub>\\<^esub> y" + unfolding I_def ZFact_def FactRing_simps by auto + obtain z where z_def: "(int z) mod (int n) = y mod (int n)" "z < n" + by (metis Euclidean_Division.pos_mod_sign mod_mod_trivial n_ge_0 nonneg_int_cases + of_nat_0_less_iff of_nat_mod unique_euclidean_semiring_numeral_class.pos_mod_bound) + have "x = I +>\<^bsub>\\<^esub> y" + by (simp add:y_def) + also have "... = I +>\<^bsub>\\<^esub> (int z)" + by (rule I_shift, simp add:z_def) + also have "... = zfact_iso n z" + by (simp add:zfact_iso_def I_def) + finally have "x = zfact_iso n z" + by simp + thus "x \ zfact_iso n ` {..\<^bsub>ZFact (int n)\<^esub>" +proof - + interpret i:ideal "I" "\" using ideal_I by simp + interpret s:ring_hom_ring "\" "ZFact (int n)" "(+>\<^bsub>\\<^esub>) I" + using i.rcos_ring_hom_ring ZFact_def I_def by auto + + show ?thesis + by (simp add:zfact_iso_def ZFact_def I_def[symmetric]) +qed + +lemma zfact_iso_bij: + "bij_betw (zfact_iso n) {..\<^bsub>R\<^esub>}" + proof + have "Units R \ carrier R" by (simp add:Units_def) + moreover have "\\<^bsub>R\<^esub> \ Units R" + by (meson assms(1) domain.zero_is_prime(1) primeE) + ultimately show "Units R \ carrier R - {\\<^bsub>R\<^esub>}" by blast + next + show "carrier R - {\\<^bsub>R\<^esub>} \ Units R" + proof + fix x + assume a:"x \ carrier R - {\\<^bsub>R\<^esub>}" + hence x_carr: "x \ carrier R" by blast + define f where "f = (\y. y \\<^bsub>R\<^esub> x)" + have "inj_on f (carrier R)" unfolding f_def + by (rule inj_onI, metis DiffD1 DiffD2 a assms(1) domain.m_rcancel insertI1) + hence "card (carrier R) = card (f ` carrier R)" + by (metis card_image) + moreover have "f ` carrier R \ carrier R" unfolding f_def + by (rule image_subsetI, simp add: ring.ring_simprules x_carr) + ultimately have "f ` carrier R = carrier R" + using card_subset_eq assms(2) by metis + moreover have "\\<^bsub>R\<^esub> \ carrier R" by simp + ultimately have "\y \ carrier R. f y = \\<^bsub>R\<^esub>" + by (metis image_iff) + then obtain y where y_carrier: "y \ carrier R" and y_left_inv: "y \\<^bsub>R\<^esub> x = \\<^bsub>R\<^esub>" + using f_def by blast + hence y_right_inv: "x \\<^bsub>R\<^esub> y = \\<^bsub>R\<^esub>" using assms(1) a + by (metis DiffD1 a cring.cring_simprules(14) domain.axioms(1)) + show "x \ Units R" using y_carrier y_left_inv y_right_inv + by (metis DiffD1 a assms(1) cring.divides_one domain.axioms(1) factor_def) + qed + qed + then show "field R" by (simp add: assms(1) field.intro field_axioms.intro) +qed + +lemma zfact_prime_is_field: + assumes "Factorial_Ring.prime (p :: nat)" + shows "field (ZFact (int p))" +proof - + have "finite (carrier (ZFact (int p)))" + using zfact_finite assms prime_gt_0_nat by blast + moreover have "domain (ZFact (int p))" + using ZFact_prime_is_domain assms by auto + ultimately show ?thesis + using finite_domains_are_fields by blast +qed + +text \In some applications it is more convenient to work with natural numbers instead of +@{term "ZFact p"} whose elements are cosets. To support that use case the following definition +introduces an additive and multiplicative structure on @{term "{.. + +definition mod_ring :: "nat => nat ring" + where "mod_ring n = \ + carrier = {.. x y. (x * y) mod n), + one = 1, + zero = 0, + add = (\ x y. (x + y) mod n) \" + +definition zfact_iso_inv :: "nat \ int set \ nat" where + "zfact_iso_inv p = inv_into {.. 0" + shows "zfact_iso_inv n \\<^bsub>ZFact (int n)\<^esub> = 0" + unfolding zfact_iso_inv_def zfact_iso_0[OF n_ge_0, symmetric] using n_ge_0 + by (rule inv_into_f_f[OF zfact_iso_inj], simp add:mod_ring_def) + +lemma zfact_coset: + assumes n_ge_0: "n > 0" + assumes "x \ carrier (ZFact (int n))" + defines "I \ Idl\<^bsub>\\<^esub> {int n}" + shows "x = I +>\<^bsub>\\<^esub> (int (zfact_iso_inv n x))" +proof - + have "x \ zfact_iso n ` {.. 1" + shows "zfact_iso_inv n \ ring_iso (ZFact (int n)) (mod_ring n)" +proof (rule ring_iso_memI) + interpret r:cring "(ZFact (int n))" + using ZFact_is_cring by simp + + define I where "I = Idl\<^bsub>\\<^esub> {int n}" + + have n_ge_0: "n > 0" using n_ge_1 by simp + + interpret i:ideal "I" "\" + using ideal_I[OF n_ge_0] I_def by simp + + interpret s:ring_hom_ring "\" "ZFact (int n)" "(+>\<^bsub>\\<^esub>) I" + using i.rcos_ring_hom_ring ZFact_def I_def by auto + + show + "\x. x \ carrier (ZFact (int n)) \ zfact_iso_inv n x \ carrier (mod_ring n)" + proof - + fix x + assume "x \ carrier (ZFact (int n))" + hence "zfact_iso_inv n x \ {.. carrier (mod_ring n)" + unfolding mod_ring_def by simp + qed + + show "\x y. x \ carrier (ZFact (int n)) \ y \ carrier (ZFact (int n)) \ + zfact_iso_inv n (x \\<^bsub>ZFact (int n)\<^esub> y) = + zfact_iso_inv n x \\<^bsub>mod_ring n\<^esub> zfact_iso_inv n y" + proof - + fix x y + assume x_carr: "x \ carrier (ZFact (int n))" + define x' where "x' = zfact_iso_inv n x" + assume y_carr: "y \ carrier (ZFact (int n))" + define y' where "y' = zfact_iso_inv n y" + have "x \\<^bsub>ZFact (int n)\<^esub> y = (I +>\<^bsub>\\<^esub> (int x')) \\<^bsub>ZFact (int n)\<^esub> (I +>\<^bsub>\\<^esub> (int y'))" + unfolding x'_def y'_def + using x_carr y_carr zfact_coset[OF n_ge_0] I_def by simp + also have "... = (I +>\<^bsub>\\<^esub> (int x' * int y'))" + by simp + also have "... = (I +>\<^bsub>\\<^esub> (int ((x' * y') mod n)))" + unfolding I_def zmod_int by (rule I_shift[OF n_ge_0],simp) + also have "... = (I +>\<^bsub>\\<^esub> (x' \\<^bsub>mod_ring n\<^esub> y'))" + unfolding mod_ring_def by simp + also have "... = zfact_iso n (x' \\<^bsub>mod_ring n\<^esub> y')" + unfolding zfact_iso_def I_def by simp + finally have a:"x \\<^bsub>ZFact (int n)\<^esub> y = zfact_iso n (x' \\<^bsub>mod_ring n\<^esub> y')" + by simp + have b:"x' \\<^bsub>mod_ring n\<^esub> y' \ {..\<^bsub>mod_ring n\<^esub> y')) = x' \\<^bsub>mod_ring n\<^esub> y'" + unfolding zfact_iso_inv_def + by (rule inv_into_f_f[OF zfact_iso_inj[OF n_ge_0] b]) + thus + "zfact_iso_inv n (x \\<^bsub>ZFact (int n)\<^esub> y) = + zfact_iso_inv n x \\<^bsub>mod_ring n\<^esub> zfact_iso_inv n y" + using a x'_def y'_def by simp + qed + + show "\x y. x \ carrier (ZFact (int n)) \ y \ carrier (ZFact (int n)) \ + zfact_iso_inv n (x \\<^bsub>ZFact (int n)\<^esub> y) = + zfact_iso_inv n x \\<^bsub>mod_ring n\<^esub> zfact_iso_inv n y" + proof - + fix x y + assume x_carr: "x \ carrier (ZFact (int n))" + define x' where "x' = zfact_iso_inv n x" + assume y_carr: "y \ carrier (ZFact (int n))" + define y' where "y' = zfact_iso_inv n y" + have "x \\<^bsub>ZFact (int n)\<^esub> y = (I +>\<^bsub>\\<^esub> (int x')) \\<^bsub>ZFact (int n)\<^esub> (I +>\<^bsub>\\<^esub> (int y'))" + unfolding x'_def y'_def + using x_carr y_carr zfact_coset[OF n_ge_0] I_def by simp + also have "... = (I +>\<^bsub>\\<^esub> (int x' + int y'))" + by simp + also have "... = (I +>\<^bsub>\\<^esub> (int ((x' + y') mod n)))" + unfolding I_def zmod_int by (rule I_shift[OF n_ge_0],simp) + also have "... = (I +>\<^bsub>\\<^esub> (x' \\<^bsub>mod_ring n\<^esub> y'))" + unfolding mod_ring_def by simp + also have "... = zfact_iso n (x' \\<^bsub>mod_ring n\<^esub> y')" + unfolding zfact_iso_def I_def by simp + finally have a:"x \\<^bsub>ZFact (int n)\<^esub> y = zfact_iso n (x' \\<^bsub>mod_ring n\<^esub> y')" + by simp + have b:"x' \\<^bsub>mod_ring n\<^esub> y' \ {..\<^bsub>mod_ring n\<^esub> y')) = x' \\<^bsub>mod_ring n\<^esub> y'" + unfolding zfact_iso_inv_def + by (rule inv_into_f_f[OF zfact_iso_inj[OF n_ge_0] b]) + thus + "zfact_iso_inv n (x \\<^bsub>ZFact (int n)\<^esub> y) = + zfact_iso_inv n x \\<^bsub>mod_ring n\<^esub> zfact_iso_inv n y" + using a x'_def y'_def by simp + qed + + have "\\<^bsub>ZFact (int n)\<^esub> = zfact_iso n (\\<^bsub>mod_ring n\<^esub>)" + by (simp add:zfact_iso_def ZFact_def I_def[symmetric] mod_ring_def) + + thus "zfact_iso_inv n \\<^bsub>ZFact (int n)\<^esub> = \\<^bsub>mod_ring n\<^esub>" + unfolding zfact_iso_inv_def mod_ring_def + using inv_into_f_f[OF zfact_iso_inj] n_ge_1 by simp + + show "bij_betw (zfact_iso_inv n) (carrier (ZFact (int n))) (carrier (mod_ring n))" + using zfact_iso_inv_def mod_ring_def zfact_iso_bij[OF n_ge_0] bij_betw_inv_into + by force +qed + +lemma mod_ring_finite: + "finite (carrier (mod_ring n))" + by (simp add:mod_ring_def) + +lemma mod_ring_carr: + "x \ carrier (mod_ring n) \ x < n" + by (simp add:mod_ring_def) + +lemma mod_ring_is_cring: + assumes n_ge_1: "n > 1" + shows "cring (mod_ring n)" +proof - + have n_ge_0: "n > 0" using n_ge_1 by simp + + interpret cring "ZFact (int n)" + using ZFact_is_cring by simp + + have "cring ((mod_ring n) \ zero := zfact_iso_inv n \\<^bsub>ZFact (int n)\<^esub> \)" + by (rule ring_iso_imp_img_cring[OF zfact_iso_inv_is_ring_iso[OF n_ge_1]]) + moreover have + "(mod_ring n) \ zero := zfact_iso_inv n \\<^bsub>ZFact (int n)\<^esub> \ = mod_ring n" + using zfact_iso_inv_0[OF n_ge_0] + by (simp add:mod_ring_def) + ultimately show ?thesis by simp +qed + +lemma zfact_iso_is_ring_iso: + assumes n_ge_1: "n > 1" + shows "zfact_iso n \ ring_iso (mod_ring n) (ZFact (int n))" +proof - + have r:"ring (ZFact (int n))" + using ZFact_is_cring cring.axioms(1) by blast + + interpret s: ring "(mod_ring n)" + using mod_ring_is_cring cring.axioms(1) n_ge_1 by blast + have n_ge_0: "n > 0" using n_ge_1 by linarith + + have + "inv_into (carrier (ZFact (int n))) (zfact_iso_inv n) + \ ring_iso (mod_ring n) (ZFact (int n))" + using ring_iso_set_sym[OF r zfact_iso_inv_is_ring_iso[OF n_ge_1]] by simp + moreover have "\x. x \ carrier (mod_ring n) \ + inv_into (carrier (ZFact (int n))) (zfact_iso_inv n) x = zfact_iso n x" + proof - + fix x + assume "x \ carrier (mod_ring n)" + hence "x \ {..If @{term "p"} is a prime than @{term "mod_ring p"} is a field:\ + +lemma mod_ring_is_field: + assumes"Factorial_Ring.prime p" + shows "field (mod_ring p)" +proof - + have p_ge_0: "p > 0" using assms prime_gt_0_nat by blast + have p_ge_1: "p > 1" using assms prime_gt_1_nat by blast + + interpret field "ZFact (int p)" + using zfact_prime_is_field[OF assms] by simp + + have "field ((mod_ring p) \ zero := zfact_iso_inv p \\<^bsub>ZFact (int p)\<^esub> \)" + by (rule ring_iso_imp_img_field[OF zfact_iso_inv_is_ring_iso[OF p_ge_1]]) + + moreover have + "(mod_ring p) \ zero := zfact_iso_inv p \\<^bsub>ZFact (int p)\<^esub> \ = mod_ring p" + using zfact_iso_inv_0[OF p_ge_0] + by (simp add:mod_ring_def) + ultimately show ?thesis by simp +qed + +end diff --git a/thys/Universal_Hash_Families/Preliminary_Results.thy b/thys/Universal_Hash_Families/Preliminary_Results.thy new file mode 100644 --- /dev/null +++ b/thys/Universal_Hash_Families/Preliminary_Results.thy @@ -0,0 +1,346 @@ +section \Preliminary Results\ + +theory Preliminary_Results + imports + "Definitions" + "HOL-Probability.Stream_Space" + "HOL-Probability.Probability_Mass_Function" +begin + +lemma set_comp_image_cong: + assumes "\x. P x \ f x = h (g x)" + shows "{f x| x. P x} = h ` {g x| x. P x}" + using assms by (auto simp: setcompr_eq_image) + +lemma (in prob_space) k_wise_indep_vars_compose: + assumes "k_wise_indep_vars k M' X I" + assumes "\i. i \ I \ Y i \ measurable (M' i) (N i)" + shows "k_wise_indep_vars k N (\i x. Y i (X i x)) I" + using indep_vars_compose2[where N="N" and X="X" and Y="Y" and M'="M'"] assms + by (simp add: k_wise_indep_vars_def subsetD) + +text \The following two lemmas are of independent interest, they help infer independence of events +and random variables on distributions. (Candidates for +@{theory "HOL-Probability.Independent_Family"}).\ + +lemma (in prob_space) indep_sets_distr: + fixes A + assumes "random_variable N f" + defines "F \ (\i. (\a. f -` a \ space M) ` A i)" + assumes indep_F: "indep_sets F I" + assumes sets_A: "\i. i \ I \ A i \ sets N" + shows "prob_space.indep_sets (distr M N f) A I" +proof (rule prob_space.indep_setsI) + show "\A' J. J \ {} \ J \ I \ finite J \ \j\J. A' j \ A j \ + measure (distr M N f) (\ (A' ` J)) = (\j\J. measure (distr M N f) (A' j))" + proof - + fix A' J + assume a:"J \ I" "finite J" "J \ {}" "\j \ J. A' j \ A j" + + define F' where "F' = (\i. f -` A' i \ space M)" + + have "\ (F' ` J) = f -` (\ (A' ` J)) \ space M" + unfolding set_eq_iff F'_def using a(3) by simp + moreover have "\ (A' ` J) \ sets N" + by (metis a sets_A sets.finite_INT subset_iff) + ultimately have b: + "measure (distr M N f) (\ (A' ` J)) = measure M (\ (F' ` J))" + by (metis assms(1) measure_distr) + + have "\j. j \ J \ F' j \ F j" + using a(4) F'_def F_def by blast + hence c:"measure M (\ (F' ` J)) = (\j\ J. measure M (F' j))" + by (metis indep_F indep_setsD a(1,2,3)) + + have "\j. j \ J \ F' j = f -` A' j \ space M" + by (simp add:F'_def) + moreover have "\j. j \ J \ A' j \ sets N" + using a(1,4) sets_A by blast + ultimately have d: + "\j. j \ J \ measure M (F' j) = measure (distr M N f) (A' j)" + using assms(1) measure_distr by metis + + show + "measure (distr M N f) (\ (A' ` J)) = (\j\J. measure (distr M N f) (A' j))" + using b c d by auto + qed + show "prob_space (distr M N f)" using prob_space_distr assms by blast + show "\i. i \ I \ A i \ sets (distr M N f)" using sets_A sets_distr by blast +qed + +lemma (in prob_space) indep_vars_distr: + assumes "f \ measurable M N" + assumes "\i. i \ I \ X' i \ measurable N (M' i)" + assumes "indep_vars M' (\i. (X' i) \ f) I" + shows "prob_space.indep_vars (distr M N f) M' X' I" +proof - + interpret D: prob_space "(distr M N f)" + using prob_space_distr[OF assms(1)] by simp + + have a: "f \ space M \ space N" using assms(1) by (simp add:measurable_def) + + have "D.indep_sets (\i. {X' i -` A \ space N |A. A \ sets (M' i)}) I" + proof (rule indep_sets_distr[OF assms(1)]) + have "\i. i \ I \ {(X' i \ f) -` A \ space M |A. A \ sets (M' i)} = + (\a. f -` a \ space M) ` {X' i -` A \ space N |A. A \ sets (M' i)}" + by (rule set_comp_image_cong, simp add:set_eq_iff, use a in blast) + thus "indep_sets (\i. (\a. f -` a \ space M) ` + {X' i -` A \ space N |A. A \ sets (M' i)}) I" + using assms(3) by (simp add:indep_vars_def2 cong:indep_sets_cong) + next + fix i + assume "i \ I" + thus "{X' i -` A \ space N |A. A \ sets (M' i)} \ sets N" + using assms(2) measurable_sets by blast + qed + thus ?thesis + using assms by (simp add:D.indep_vars_def2) +qed + +lemma range_inter: "range ((\) F) = Pow F" + unfolding image_def by auto + +text \The singletons and the empty set form an intersection stable generator of a countable +discrete $\sigma$-algebra:\ + +lemma sigma_sets_singletons_and_empty: + assumes "countable M" + shows "sigma_sets M (insert {} ((\k. {k}) ` M)) = Pow M" +proof - + have "sigma_sets M ((\k. {k}) ` M) = Pow M" + using assms sigma_sets_singletons by auto + hence "Pow M \ sigma_sets M (insert {} ((\k. {k}) ` M))" + by (metis sigma_sets_subseteq subset_insertI) + moreover have "(insert {} ((\k. {k}) ` M)) \ Pow M" by blast + hence "sigma_sets M (insert {} ((\k. {k}) ` M)) \ Pow M" + by (meson sigma_algebra.sigma_sets_subset sigma_algebra_Pow) + ultimately show ?thesis by force +qed + +text \In some of the following theorems, the premise @{term "M = measure_pmf p"} is used. This allows stating +theorems that hold for pmfs more concisely, for example, instead of +@{term "measure_pmf.prob p A \ measure_pmf.prob p B"} we can +just write @{term "M = measure_pmf p \ prob A \ prob B"} in the locale @{locale "prob_space"}.\ + +lemma prob_space_restrict_space: + assumes [simp]:"M = measure_pmf p" + shows "prob_space (restrict_space M (set_pmf p))" + by (rule prob_spaceI, auto simp:emeasure_restrict_space emeasure_pmf) + +text \The abbreviation below is used to specify the discrete $\sigma$-algebra on @{term "UNIV"} +as a measure space. It is used in places where the existing definitions, such as @{term "indep_vars"}, +expect a measure space even though only a \emph{measurable} space is really needed, i.e., in cases +where the property is invariant with respect to the actual measure.\ + +abbreviation "discrete \ count_space UNIV" + +lemma (in prob_space) indep_vars_restrict_space: + assumes [simp]:"M = measure_pmf p" + assumes + "prob_space.indep_vars (restrict_space M (set_pmf p)) (\_. discrete) X I" + shows "indep_vars (\_. discrete) X I" +proof - + have a: "id \ restrict_space M (set_pmf p) \\<^sub>M M" + by (simp add:measurable_def range_inter sets_restrict_space) + + have "prob_space.indep_vars (distr (restrict_space M (set_pmf p)) M id) (\_. discrete) X I" + using assms a prob_space_restrict_space by (auto intro!:prob_space.indep_vars_distr) + moreover have + "\A. emeasure (distr (restrict_space M (set_pmf p)) M id) A = emeasure M A" + using emeasure_distr[OF a] + by (auto simp add: emeasure_restrict_space emeasure_Int_set_pmf) + hence "distr (restrict_space M p) M id = M" + by (auto intro: measure_eqI) + ultimately show ?thesis by simp +qed + +lemma (in prob_space) measure_pmf_eq: + assumes "M = measure_pmf p" + assumes "\x. x \ set_pmf p \ (x \ P) = (x \ Q)" + shows "prob P = prob Q" + unfolding assms(1) + by (rule measure_eq_AE, rule AE_pmfI[OF assms(2)], auto) + +text \The following lemma is an intro rule for the independence of random variables defined on pmfs. +In that case it is possible, to check the independence of random variables point-wise. + +The proof relies on the fact that the support of a pmf is countable and the $\sigma$-algebra of +such a set can be generated by singletons.\ + +lemma (in prob_space) indep_vars_pmf: + assumes [simp]:"M = measure_pmf p" + assumes "\a J. J \ I \ finite J \ + prob {\. \i \ J. X i \ = a i} = (\i \ J. prob {\. X i \ = a i})" + shows "indep_vars (\_. discrete) X I" +proof - + interpret R:prob_space "(restrict_space M (set_pmf p))" + using prob_space_restrict_space by auto + + have events_eq_pow: "R.events = Pow (set_pmf p)" + by (simp add:sets_restrict_space range_inter) + + define G where "G = (\i. {{}} \ (\x. {x}) ` (X i ` set_pmf p))" + define F where "F = (\i. {X i -` a \ set_pmf p|a. a \ G i})" + + have sigma_sets_pow: + "\i. i \ I \ sigma_sets (X i ` set_pmf p) (G i) = Pow (X i ` set_pmf p)" + by (simp add:G_def, metis countable_image countable_set_pmf sigma_sets_singletons_and_empty) + + have F_in_events: "\i. i \ I \ F i \ Pow (set_pmf p)" + unfolding F_def by blast + + have as_sigma_sets: + "\i. i \ I \ {u. \A. u = X i -` A \ set_pmf p} = sigma_sets (set_pmf p) (F i)" + proof - + fix i + assume a:"i \ I" + have "\A. X i -` A \ set_pmf p = X i -` (A \ X i ` set_pmf p) \ set_pmf p" + by auto + hence "{u. \A. u = X i -` A \ set_pmf p} = + {X i -` A \ set_pmf p |A. A \ X i ` set_pmf p}" + by (metis (no_types, opaque_lifting) inf_le2) + also have + "... = {X i -` A \ set_pmf p |A. A \ sigma_sets (X i ` set_pmf p) (G i)}" + using a by (simp add:sigma_sets_pow) + also have "... = sigma_sets (set_pmf p) {X i -` a \ set_pmf p |a. a \ G i}" + by (subst sigma_sets_vimage_commute[symmetric], auto) + also have "... = sigma_sets (set_pmf p) (F i)" + by (simp add:F_def) + finally show + "{u. \A. u = X i -` A \ set_pmf p} = sigma_sets (set_pmf p) (F i)" + by simp + qed + + have F_Int_stable: "\i. i \ I \ Int_stable (F i)" + proof (rule Int_stableI) + fix i a b + assume "i \ I" "a \ F i" "b \ F i" + thus "a \ b \ (F i)" + unfolding F_def G_def by (cases "a \ b = {}", auto) + qed + + have F_indep_sets:"R.indep_sets F I" + proof (rule R.indep_setsI) + fix i + assume "i \ I" + show "F i \ R.events" + unfolding F_def events_eq_pow by blast + next + fix A + fix J + assume a:"J \ I" "J \ {}" "finite J" "\j\J. A j \ F j" + have b: "\j. j \ J \ A j \ set_pmf p" + by (metis PowD a(1,4) subsetD F_in_events) + obtain x where x_def:"\j. j \ J \ A j = X j -` x j \ set_pmf p \ x j \ G j" + using a by (simp add:Pi_def F_def, metis) + + show "R.prob (\ (A ` J)) = (\j\J. R.prob (A j))" + proof (cases "\j \ J. A j = {}") + case True + hence "\ (A ` J) = {}" by blast + then show ?thesis + using a True by (simp, metis measure_empty) + next + case False + then have "\j. j \ J \ x j \ {}" using x_def by auto + hence "\j. j \ J \ x j \ (\x. {x}) ` X j ` set_pmf p" + using x_def by (simp add:G_def) + then obtain y where y_def: "\j. j \ J \ x j = {y j}" + by (simp add:image_def, metis) + + have "\ (A ` J) \ set_pmf p" using b a(2) by blast + hence "R.prob (\ (A ` J)) = prob (\ j \ J. A j)" + by (simp add: measure_restrict_space) + also have "... = prob ({\. \j \ J. X j \ = y j})" + using a x_def y_def apply (simp add:vimage_def measure_Int_set_pmf) + by (rule arg_cong2 [where f="measure"], auto) + also have "... = (\ j\ J. prob (A j))" + using x_def y_def a assms(2) + by (simp add:vimage_def measure_Int_set_pmf) + also have "... = (\j\J. R.prob (A j))" + using b by (simp add: measure_restrict_space cong:prod.cong) + finally show ?thesis by blast + qed + qed + + have "R.indep_sets (\i. sigma_sets (set_pmf p) (F i)) I" + using R.indep_sets_sigma[simplified] F_Int_stable F_indep_sets + by (auto simp:space_restrict_space) + + hence "R.indep_sets (\i. {u. \A. u = X i -` A \ set_pmf p}) I" + by (simp add: as_sigma_sets cong:R.indep_sets_cong) + + hence "R.indep_vars (\_. discrete) X I" + unfolding R.indep_vars_def2 + by (simp add:measurable_def sets_restrict_space range_inter) + + thus ?thesis + using indep_vars_restrict_space[OF assms(1)] by simp +qed + +lemma (in prob_space) split_indep_events: + assumes "M = measure_pmf p" + assumes "indep_vars (\i. discrete) X' I" + assumes "K \ I" "finite K" + shows "prob {\. \x \ K. P x (X' x \)} = (\x \ K. prob {\. P x (X' x \)})" +proof - + have [simp]: "space M = UNIV" "events = UNIV" "prob UNIV = 1" + by (simp add:assms(1))+ + + have "indep_vars (\_. discrete) X' K" + using assms(2,3) indep_vars_subset by blast + hence "indep_events (\x. {\ \ space M. P x (X' x \)}) K" + using indep_eventsI_indep_vars by force + hence a:"indep_events (\x. {\. P x (X' x \)}) K" + by simp + + have "prob {\. \x \ K. P x (X' x \)} = prob (\x \ K. {\. P x (X' x \)})" + by (simp add: measure_pmf_eq[OF assms(1)]) + also have "... = (\ x \ K. prob {\. P x (X' x \)})" + using a assms(4) by (cases "K = {}", auto simp: indep_events_def) + finally show ?thesis by simp +qed + +lemma pmf_of_set_eq_uniform: + assumes "finite A" "A \ {}" + shows "measure_pmf (pmf_of_set A) = uniform_measure discrete A" +proof - + have a:"real (card A) > 0" using assms + by (simp add: card_gt_0_iff) + + have b: + "\Y. emeasure (pmf_of_set A) Y = emeasure (uniform_measure discrete A) Y" + using assms a + by (simp add: emeasure_pmf_of_set divide_ennreal ennreal_of_nat_eq_real_of_nat) + + show ?thesis + by (rule measure_eqI, auto simp add: b) +qed + +lemma (in prob_space) uniform_onI: + assumes "M = measure_pmf p" + assumes "finite A" "A \ {}" + assumes "\a. prob {\. X \ = a} = indicator A a / card A" + shows "uniform_on X A" +proof - + have a:"\a. measure_pmf.prob p {x. X x = a} = indicator A a / card A" + using assms(1,4) by simp + + have b:"map_pmf X p = pmf_of_set A" + by (rule pmf_eqI, simp add:assms pmf_map vimage_def a) + + have "distr M discrete X = map_pmf X p" + by (simp add: map_pmf_rep_eq assms(1)) + also have "... = measure_pmf (pmf_of_set A)" + using b by simp + also have "... = uniform_measure discrete A" + by (rule pmf_of_set_eq_uniform[OF assms(2,3)]) + finally have "distr M discrete X = uniform_measure discrete A" + by simp + moreover have "random_variable discrete X" + by (simp add: assms(1)) + ultimately show ?thesis using assms(2,3) + by (simp add: uniform_on_def) +qed + +end diff --git a/thys/Universal_Hash_Families/ROOT b/thys/Universal_Hash_Families/ROOT new file mode 100644 --- /dev/null +++ b/thys/Universal_Hash_Families/ROOT @@ -0,0 +1,15 @@ +chapter AFP + +session Universal_Hash_Families (AFP) = "HOL-Probability" + + options [timeout = 600] + sessions + "HOL-Algebra" + "Interpolation_Polynomials_HOL_Algebra" + theories + Definitions + Preliminary_Results + Carter_Wegman_Hash_Family + Field + document_files + "root.tex" + "root.bib" diff --git a/thys/Universal_Hash_Families/document/root.bib b/thys/Universal_Hash_Families/document/root.bib new file mode 100644 --- /dev/null +++ b/thys/Universal_Hash_Families/document/root.bib @@ -0,0 +1,49 @@ +@article{wegman1981, + title = {New hash functions and their use in authentication and set equality}, + journal = {Journal of Computer and System Sciences}, + volume = {22}, + number = {3}, + pages = {265--279}, + year = {1981}, + issn = {0022-0000}, + _doi = {https://doi.org/10.1016/0022-0000(81)90033-7}, + _url = {https://www.sciencedirect.com/science/article/pii/0022000081900337}, + author = {Mark N. Wegman and J. Lawrence Carter}, +} + +@article{Interpolation_Polynomials_HOL_Algebra-AFP, + author = {Emin Karayel}, + title = {Interpolation Polynomials (in HOL-Algebra)}, + journal = {Archive of Formal Proofs}, + month = jan, + year = 2022, + note = {\url{https://isa-afp.org/entries/Interpolation_Polynomials_HOL_Algebra.html}, + Formal proof development}, + ISSN = {2150-914x}, +} + +@inproceedings{thorup2010, + author = {Thorup, Mikkel and Zhang, Yin}, + title = {Tabulation Based 5-Universal Hashing and Linear Probing}, + year = {2010}, + publisher = {Society for Industrial and Applied Mathematics}, + address = {USA}, + booktitle = {Proceedings of the Meeting on Algorithm Engineering \& Expermiments}, + pages = {62--76}, + numpages = {15}, + location = {Austin, Texas}, + series = {ALENEX '10} +} + +@article{vadhan2012, + _url = {http://dx.doi.org/10.1561/0400000010}, + year = {2012}, + volume = {7}, + journal = {Foundations and Trends\textregistered in Theoretical Computer Science}, + title = {Pseudorandomness}, + _doi = {10.1561/0400000010}, + issn = {1551-305X}, + number = {1-3}, + pages = {1--336}, + author = {Salil P. Vadhan} +} diff --git a/thys/Universal_Hash_Families/document/root.tex b/thys/Universal_Hash_Families/document/root.tex new file mode 100644 --- /dev/null +++ b/thys/Universal_Hash_Families/document/root.tex @@ -0,0 +1,44 @@ +\documentclass[11pt,a4paper]{article} +\usepackage[T1]{fontenc} +\usepackage{isabelle,isabellesym} +\usepackage{amssymb} +\usepackage{pdfsetup} + +\urlstyle{rm} +\isabellestyle{it} + +\begin{document} + +\title{Universal Hash Families} +\author{Emin Karayel} +\maketitle + +\begin{abstract} +A $k$-universal hash family is a probability space of functions, which have uniform distribution and +form $k$-wise independent random variables. + +They can often be used in place of classic (or cryptographic) hash functions and allow the +rigorous analysis of the performance of randomized algorithms and data structures that +rely on hash functions. + +In 1981 Wegman and Carter~\cite{wegman1981} introduced a generic construction for such +families with arbitrary $k$ using polynomials over a finite field. This entry contains a formalization +of them and establishes the property of $k$-universality. + +To be useful the formalization also provides an explicit construction of finite fields using the +factor ring of integers modulo a prime. Additionally, some generic results about independent +families are shown that might be of independent interest. +\end{abstract} + +\parindent 0pt\parskip 0.5ex + +\input{session} + +\bibliographystyle{abbrv} +\bibliography{root} +\end{document} + +%%% Local Variables: +%%% mode: latex +%%% TeX-master: t +%%% End: diff --git a/thys/VYDRA_MDL/Interval.thy b/thys/VYDRA_MDL/Interval.thy new file mode 100644 --- /dev/null +++ b/thys/VYDRA_MDL/Interval.thy @@ -0,0 +1,108 @@ +(*<*) +theory Interval + imports "HOL-Library.Product_Lexorder" Timestamp +begin +(*>*) + +section \Intervals\ + +typedef (overloaded) ('a :: timestamp) \ = "{(i :: 'a, j :: 'a, lei :: bool, lej :: bool). 0 \ i \ i \ j \ i \ tfin \ \(j = 0 \ \lej)}" + by (intro exI[of _ "(0, 0, True, True)"]) (auto intro: zero_tfin) + +setup_lifting type_definition_\ + +instantiation \ :: (timestamp) equal begin + +lift_definition equal_\ :: "'a \ \ 'a \ \ bool" is "(=)" . + +instance by standard (transfer, auto) + +end + +lift_definition left :: "'a :: timestamp \ \ 'a" is "fst" . +lift_definition right :: "'a :: timestamp \ \ 'a" is "fst \ snd" . + +lift_definition memL :: "'a :: timestamp \ 'a \ 'a \ \ bool" is + "\t t' (a, b, lei, lej). if lei then t + a \ t' else t + a < t'" . + +lift_definition memR :: "'a :: timestamp \ 'a \ 'a \ \ bool" is + "\t t' (a, b, lei, lej). if lej then t' \ t + b else t' < t + b" . + +definition mem :: "'a :: timestamp \ 'a \ 'a \ \ bool" where + "mem t t' I \ memL t t' I \ memR t t' I" + +lemma memL_mono: "memL t t' I \ t'' \ t \ memL t'' t' I" + by transfer (auto simp: add.commute order_le_less_subst2 order_subst2 add_mono split: if_splits) + +lemma memL_mono': "memL t t' I \ t' \ t'' \ memL t t'' I" + by transfer (auto split: if_splits) + +lemma memR_mono: "memR t t' I \ t \ t'' \ memR t'' t' I" + apply transfer + apply (simp split: prod.splits) + apply (meson add_mono_comm dual_order.trans order_less_le_trans) + done + +lemma memR_mono': "memR t t' I \ t'' \ t' \ memR t t'' I" + by transfer (auto split: if_splits) + +lemma memR_dest: "memR t t' I \ t' \ t + right I" + by transfer (auto split: if_splits) + +lemma memR_tfin_refl: + assumes fin: "t \ tfin" + shows "memR t t I" + by (transfer fixing: t) (force split: if_splits intro: order_trans[OF _ add_mono, where ?x=t and ?a1=t and ?c1=0] add_pos[OF fin]) + +lemma right_I_add_mono: + fixes x :: "'a :: timestamp" + shows "x \ x + right I" + by transfer (auto split: if_splits intro: order_trans[OF _ add_mono, of _ _ 0]) + +lift_definition interval :: "'a :: timestamp \ 'a \ bool \ bool \ 'a \" is + "\i j lei lej. (if 0 \ i \ i \ j \ i \ tfin \ \(j = 0 \ \lej)then (i, j, lei, lej) else Code.abort (STR ''malformed interval'') (\_. (0, 0, True, True)))" + by (auto intro: zero_tfin) + +lemma "Rep_\ I = (l, r, b1, b2) \ memL 0 0 I \ l = 0 \ b1" + by transfer auto + +lift_definition dropL :: "'a :: timestamp \ \ 'a \" is + "\(l, r, b1, b2). (0, r, True, b2)" + by (auto intro: zero_tfin) + +lemma memL_dropL: "t \ t' \ memL t t' (dropL I)" + by transfer auto + +lemma memR_dropL: "memR t t' (dropL I) = memR t t' I" + by transfer auto + +lift_definition flipL :: "'a :: timestamp \ \ 'a \" is + "\(l, r, b1, b2). if \(l = 0 \ b1) then (0, l, True, \b1) else Code.abort (STR ''invalid flipL'') (\_. (0, 0, True, True))" + by (auto intro: zero_tfin split: if_splits) + +lemma memL_flipL: "t \ t' \ memL t t' (flipL I)" + by transfer (auto split: if_splits) + +lemma memR_flipLD: "\memL 0 0 I \ memR t t' (flipL I) \ \memL t t' I" + by transfer (auto split: if_splits) + +lemma memR_flipLI: + fixes t :: "'a :: timestamp" + shows "(\u v. (u :: 'a :: timestamp) \ v \ v \ u) \ \memL t t' I \ memR t t' (flipL I)" + by transfer (force split: if_splits) + +lemma "t \ tfin \ memL 0 0 I \ memL t t I" + apply transfer + apply (simp split: prod.splits) + apply (metis add.right_neutral add_pos antisym_conv2 dual_order.eq_iff order_less_imp_not_less) + done + +definition "full (I :: ('a :: timestamp_total) \) \ (\t t'. 0 \ t \ t \ t' \ t \ tfin \ t' \ tfin \ mem t t' I)" + +lemma "memL 0 0 I \ right I \ tfin \ full I" + unfolding full_def mem_def + by transfer (fastforce split: if_splits dest: aux) + +(*<*) +end +(*>*) diff --git a/thys/VYDRA_MDL/MDL.thy b/thys/VYDRA_MDL/MDL.thy new file mode 100644 --- /dev/null +++ b/thys/VYDRA_MDL/MDL.thy @@ -0,0 +1,350 @@ +theory MDL + imports Interval Trace +begin + +section \Formulas and Satisfiability\ + +declare [[typedef_overloaded]] + +datatype ('a, 't :: timestamp) formula = Bool bool | Atom 'a | Neg "('a, 't) formula" | + Bin "bool \ bool \ bool" "('a, 't) formula" "('a, 't) formula" | + Prev "'t \" "('a, 't) formula" | Next "'t \" "('a, 't) formula" | + Since "('a, 't) formula" "'t \" "('a, 't) formula" | + Until "('a, 't) formula" "'t \" "('a, 't) formula" | + MatchP "'t \" "('a, 't) regex" | MatchF "'t \" "('a, 't) regex" + and ('a, 't) regex = Lookahead "('a, 't) formula" | Symbol "('a, 't) formula" | + Plus "('a, 't) regex" "('a, 't) regex" | Times "('a, 't) regex" "('a, 't) regex" | + Star "('a, 't) regex" + +fun eps :: "('a, 't :: timestamp) regex \ bool" where + "eps (Lookahead phi) = True" +| "eps (Symbol phi) = False" +| "eps (Plus r s) = (eps r \ eps s)" +| "eps (Times r s) = (eps r \ eps s)" +| "eps (Star r) = True" + +fun atms :: "('a, 't :: timestamp) regex \ ('a, 't) formula set" where + "atms (Lookahead phi) = {phi}" +| "atms (Symbol phi) = {phi}" +| "atms (Plus r s) = atms r \ atms s" +| "atms (Times r s) = atms r \ atms s" +| "atms (Star r) = atms r" + +lemma size_atms[termination_simp]: "phi \ atms r \ size phi < size r" + by (induction r) auto + +fun wf_fmla :: "('a, 't :: timestamp) formula \ bool" + and wf_regex :: "('a, 't) regex \ bool" where + "wf_fmla (Bool b) = True" +| "wf_fmla (Atom a) = True" +| "wf_fmla (Neg phi) = wf_fmla phi" +| "wf_fmla (Bin f phi psi) = (wf_fmla phi \ wf_fmla psi)" +| "wf_fmla (Prev I phi) = wf_fmla phi" +| "wf_fmla (Next I phi) = wf_fmla phi" +| "wf_fmla (Since phi I psi) = (wf_fmla phi \ wf_fmla psi)" +| "wf_fmla (Until phi I psi) = (wf_fmla phi \ wf_fmla psi)" +| "wf_fmla (MatchP I r) = (wf_regex r \ (\phi \ atms r. wf_fmla phi))" +| "wf_fmla (MatchF I r) = (wf_regex r \ (\phi \ atms r. wf_fmla phi))" +| "wf_regex (Lookahead phi) = False" +| "wf_regex (Symbol phi) = wf_fmla phi" +| "wf_regex (Plus r s) = (wf_regex r \ wf_regex s)" +| "wf_regex (Times r s) = (wf_regex s \ (\eps s \ wf_regex r))" +| "wf_regex (Star r) = wf_regex r" + +fun progress :: "('a, 't :: timestamp) formula \ 't list \ nat" where + "progress (Bool b) ts = length ts" +| "progress (Atom a) ts = length ts" +| "progress (Neg phi) ts = progress phi ts" +| "progress (Bin f phi psi) ts = min (progress phi ts) (progress psi ts)" +| "progress (Prev I phi) ts = min (length ts) (Suc (progress phi ts))" +| "progress (Next I phi) ts = (case progress phi ts of 0 \ 0 | Suc k \ k)" +| "progress (Since phi I psi) ts = min (progress phi ts) (progress psi ts)" +| "progress (Until phi I psi) ts = (if length ts = 0 then 0 else + (let k = min (length ts - 1) (min (progress phi ts) (progress psi ts)) in + Min {j. 0 \ j \ j \ k \ memR (ts ! j) (ts ! k) I}))" +| "progress (MatchP I r) ts = Min ((\f. progress f ts) ` atms r)" +| "progress (MatchF I r) ts = (if length ts = 0 then 0 else + (let k = min (length ts - 1) (Min ((\f. progress f ts) ` atms r)) in + Min {j. 0 \ j \ j \ k \ memR (ts ! j) (ts ! k) I}))" + +fun bounded_future_fmla :: "('a, 't :: timestamp) formula \ bool" + and bounded_future_regex :: "('a, 't) regex \ bool" where + "bounded_future_fmla (Bool b) \ True" +| "bounded_future_fmla (Atom a) \ True" +| "bounded_future_fmla (Neg phi) \ bounded_future_fmla phi" +| "bounded_future_fmla (Bin f phi psi) \ bounded_future_fmla phi \ bounded_future_fmla psi" +| "bounded_future_fmla (Prev I phi) \ bounded_future_fmla phi" +| "bounded_future_fmla (Next I phi) \ bounded_future_fmla phi" +| "bounded_future_fmla (Since phi I psi) \ bounded_future_fmla phi \ bounded_future_fmla psi" +| "bounded_future_fmla (Until phi I psi) \ bounded_future_fmla phi \ bounded_future_fmla psi \ right I \ tfin" +| "bounded_future_fmla (MatchP I r) \ bounded_future_regex r" +| "bounded_future_fmla (MatchF I r) \ bounded_future_regex r \ right I \ tfin" +| "bounded_future_regex (Lookahead phi) \ bounded_future_fmla phi" +| "bounded_future_regex (Symbol phi) \ bounded_future_fmla phi" +| "bounded_future_regex (Plus r s) \ bounded_future_regex r \ bounded_future_regex s" +| "bounded_future_regex (Times r s) \ bounded_future_regex r \ bounded_future_regex s" +| "bounded_future_regex (Star r) \ bounded_future_regex r" + +lemmas regex_induct[case_names Lookahead Symbol Plus Times Star, induct type: regex] = + regex.induct[of "\_. True", simplified] + +definition "Once I \ \ Since (Bool True) I \" +definition "Historically I \ \ Neg (Once I (Neg \))" +definition "Eventually I \ \ Until (Bool True) I \" +definition "Always I \ \ Neg (Eventually I (Neg \))" + +fun rderive :: "('a, 't :: timestamp) regex \ ('a, 't) regex" where + "rderive (Lookahead phi) = Lookahead (Bool False)" +| "rderive (Symbol phi) = Lookahead phi" +| "rderive (Plus r s) = Plus (rderive r) (rderive s)" +| "rderive (Times r s) = (if eps s then Plus (rderive r) (Times r (rderive s)) else Times r (rderive s))" +| "rderive (Star r) = Times (Star r) (rderive r)" + +lemma atms_rderive: "phi \ atms (rderive r) \ phi \ atms r \ phi = Bool False" + by (induction r) (auto split: if_splits) + +lemma size_formula_positive: "size (phi :: ('a, 't :: timestamp) formula) > 0" + by (induction phi) auto + +lemma size_regex_positive: "size (r :: ('a, 't :: timestamp) regex) > Suc 0" + by (induction r) (auto intro: size_formula_positive) + +lemma size_rderive[termination_simp]: "phi \ atms (rderive r) \ size phi < size r" + by (drule atms_rderive) (auto intro: size_atms size_regex_positive) + +locale MDL = + fixes \ :: "('a, 't :: timestamp) trace" +begin + +fun sat :: "('a, 't) formula \ nat \ bool" + and match :: "('a, 't) regex \ (nat \ nat) set" where + "sat (Bool b) i = b" +| "sat (Atom a) i = (a \ \ \ i)" +| "sat (Neg \) i = (\ sat \ i)" +| "sat (Bin f \ \) i = (f (sat \ i) (sat \ i))" +| "sat (Prev I \) i = (case i of 0 \ False | Suc j \ mem (\ \ j) (\ \ i) I \ sat \ j)" +| "sat (Next I \) i = (mem (\ \ i) (\ \ (Suc i)) I \ sat \ (Suc i))" +| "sat (Since \ I \) i = (\j\i. mem (\ \ j) (\ \ i) I \ sat \ j \ (\k \ {j<..i}. sat \ k))" +| "sat (Until \ I \) i = (\j\i. mem (\ \ i) (\ \ j) I \ sat \ j \ (\k \ {i.. k))" +| "sat (MatchP I r) i = (\j\i. mem (\ \ j) (\ \ i) I \ (j, Suc i) \ match r)" +| "sat (MatchF I r) i = (\j\i. mem (\ \ i) (\ \ j) I \ (i, Suc j) \ match r)" +| "match (Lookahead \) = {(i, i) | i. sat \ i}" +| "match (Symbol \) = {(i, Suc i) | i. sat \ i}" +| "match (Plus r s) = match r \ match s" +| "match (Times r s) = match r O match s" +| "match (Star r) = rtrancl (match r)" + +lemma "sat (Prev I (Bool False)) i \ sat (Bool False) i" + "sat (Next I (Bool False)) i \ sat (Bool False) i" + "sat (Since \ I (Bool False)) i \ sat (Bool False) i" + "sat (Until \ I (Bool False)) i \ sat (Bool False) i" + apply (auto split: nat.splits) + done + +lemma prev_rewrite: "sat (Prev I \) i \ sat (MatchP I (Times (Symbol \) (Symbol (Bool True)))) i" + apply (auto split: nat.splits) + subgoal for j + by (fastforce intro: exI[of _ j]) + done + +lemma next_rewrite: "sat (Next I \) i \ sat (MatchF I (Times (Symbol (Bool True)) (Symbol \))) i" + by (fastforce intro: exI[of _ "Suc i"]) + +lemma trancl_Base: "{(i, Suc i) |i. P i}\<^sup>* = {(i, j). i \ j \ (\k\{i.. {(i, j). i \ j \ (\k\{i.. {(i, Suc i) |i. P i}\<^sup>*" for x y + using that by (induct rule: rtrancl_induct) (auto simp: less_Suc_eq) + moreover have "(x, y) \ {(i, Suc i) |i. P i}\<^sup>*" + if "(x, y) \ {(i, j). i \ j \ (\k\{i..k\{j..k \ {j<..i}. P k)" + by (auto simp: less_eq_Suc_le less_eq_nat.simps split: nat.splits) + +lemma since_rewrite: "sat (Since \ I \) i \ sat (MatchP I (Times (Symbol \) (Star (Symbol \)))) i" +proof (rule iffI) + assume "sat (Since \ I \) i" + then obtain j where j_def: "j \ i" "mem (\ \ j) (\ \ i) I" "sat \ j" + "\k \ {j.. (Suc k)" + by auto + have "k \ {Suc j.. (k, Suc k) \ match (Symbol \)" for k + using j_def(4) + by (cases k) auto + then have "(Suc j, Suc i) \ (match (Symbol \))\<^sup>*" + using j_def(1) trancl_Base + by auto + then show "sat (MatchP I (Times (Symbol \) (Star (Symbol \)))) i" + using j_def(1,2,3) + by auto +next + assume "sat (MatchP I (Times (Symbol \) (Star (Symbol \)))) i" + then obtain j where j_def: "j \ i" "mem (\ \ j) (\ \ i) I" "(Suc j, Suc i) \ (match (Symbol \))\<^sup>*" "sat \ j" + by auto + have "\k. k \ {Suc j.. (k, Suc k) \ match (Symbol \)" + using j_def(3) trancl_Base[of "\k. (k, Suc k) \ match (Symbol \)"] + by simp + then have "\k \ {j.. (Suc k)" + by auto + then show "sat (Since \ I \) i" + using j_def(1,2,4) Ball_atLeastLessThan_reindex[of j i "sat \"] + by auto +qed + +lemma until_rewrite: "sat (Until \ I \) i \ sat (MatchF I (Times (Star (Symbol \)) (Symbol \))) i" +proof (rule iffI) + assume "sat (Until \ I \) i" + then obtain j where j_def: "j \ i" "mem (\ \ i) (\ \ j) I" "sat \ j" + "\k \ {i.. k" + by auto + have "k \ {i.. (k, Suc k) \ match (Symbol \)" for k + using j_def(4) + by auto + then have "(i, j) \ (match (Symbol \))\<^sup>*" + using j_def(1) trancl_Base + by simp + then show "sat (MatchF I (Times (Star (Symbol \)) (Symbol \))) i" + using j_def(1,2,3) + by auto +next + assume "sat (MatchF I (Times (Star (Symbol \)) (Symbol \))) i" + then obtain j where j_def: "j \ i" "mem (\ \ i) (\ \ j) I" "(i, j) \ (match (Symbol \))\<^sup>*" "sat \ j" + by auto + have "\k. k \ {i.. (k, Suc k) \ match (Symbol \)" + using j_def(3) trancl_Base[of "\k. (k, Suc k) \ match (Symbol \)"] + by auto + then have "\k \ {i.. k" + by simp + then show "sat (Until \ I \) i" + using j_def(1,2,4) + by auto +qed + +lemma match_le: "(i, j) \ match r \ i \ j" +proof (induction r arbitrary: i j) + case (Times r s) + then show ?case using order.trans by fastforce +next + case (Star r) + from Star.prems show ?case + unfolding match.simps + by (induct i j rule: rtrancl.induct) (force dest: Star.IH)+ +qed auto + +lemma match_Times: "(i, i + n) \ match (Times r s) \ + (\k \ n. (i, i + k) \ match r \ (i + k, i + n) \ match s)" + using match_le by auto (metis le_iff_add nat_add_left_cancel_le) + +lemma rtrancl_unfold: "(x, z) \ rtrancl R \ + x = z \ (\y. (x, y) \ R \ x \ y \ (y, z) \ rtrancl R)" + by (induction x z rule: rtrancl.induct) auto + +lemma rtrancl_unfold': "(x, z) \ rtrancl R \ + x = z \ (\y. (x, y) \ rtrancl R \ y \ z \ (y, z) \ R)" + by (induction x z rule: rtrancl.induct) auto + +lemma match_Star: "(i, i + Suc n) \ match (Star r) \ + (\k \ n. (i, i + 1 + k) \ match r \ (i + 1 + k, i + Suc n) \ match (Star r))" +proof (rule iffI) + assume assms: "(i, i + Suc n) \ match (Star r)" + obtain k where k_def: "(i, k) \ local.match r" "i \ k" "i \ k" + "(k, i + Suc n) \ (local.match r)\<^sup>*" + using rtrancl_unfold[OF assms[unfolded match.simps]] match_le by auto + from k_def(4) have "(k, i + Suc n) \ match (Star r)" + unfolding match.simps by simp + then have k_le: "k \ i + Suc n" + using match_le by blast + from k_def(2,3) obtain k' where k'_def: "k = i + Suc k'" + by (metis Suc_diff_Suc le_add_diff_inverse le_neq_implies_less) + show "\k \ n. (i, i + 1 + k) \ match r \ (i + 1 + k, i + Suc n) \ match (Star r)" + using k_def k_le unfolding k'_def by auto +next + assume assms: "\k \ n. (i, i + 1 + k) \ match r \ + (i + 1 + k, i + Suc n) \ match (Star r)" + then show "(i, i + Suc n) \ match (Star r)" + by (induction n) auto +qed + +lemma match_refl_eps: "(i, i) \ match r \ eps r" +proof (induction r) + case (Times r s) + then show ?case + using match_Times[where ?i=i and ?n=0] + by auto +qed auto + +lemma wf_regex_eps_match: "wf_regex r \ eps r \ (i, i) \ match r" + by (induction r arbitrary: i) auto + +lemma match_Star_unfold: "i < j \ (i, j) \ match (Star r) \ \k \ {i.. match (Star r) \ (k, j) \ match r" + using rtrancl_unfold'[of i j "match r"] match_le[of _ j r] match_le[of i _ "Star r"] + by auto (meson atLeastLessThan_iff order_le_less) + +lemma match_rderive: "wf_regex r \ i \ j \ (i, Suc j) \ match r \ (i, j) \ match (rderive r)" +proof (induction r arbitrary: i j) + case (Times r1 r2) + then show ?case + using match_refl_eps[of "Suc j" r2] match_le[of _ "Suc j" r2] + apply (auto) + apply (metis le_Suc_eq relcomp.simps) + apply (meson match_le relcomp.simps) + apply (metis le_SucE relcomp.simps) + apply (meson relcomp.relcompI wf_regex_eps_match) + apply (meson match_le relcomp.simps) + apply (metis le_SucE relcomp.simps) + apply (meson match_le relcomp.simps) + done +next + case (Star r) + then show ?case + using match_Star_unfold[of i "Suc j" r] + by auto (meson match_le rtrancl.simps) +qed auto + +end + +lemma atms_nonempty: "atms r \ {}" + by (induction r) auto + +lemma atms_finite: "finite (atms r)" + by (induction r) auto + +lemma progress_le_ts: + assumes "\t. t \ set ts \ t \ tfin" + shows "progress phi ts \ length ts" + using assms +proof (induction phi ts rule: progress.induct) + case (8 phi I psi ts) + have "ts \ [] \ Min {j. j \ min (length ts - Suc 0) (min (progress phi ts) (progress psi ts)) \ + memR (ts ! j) (ts ! min (length ts - Suc 0) (min (progress phi ts) (progress psi ts))) I} + \ length ts" + apply (rule le_trans[OF Min_le[where ?x="min (length ts - Suc 0) (min (progress phi ts) (progress psi ts))"]]) + apply (auto simp: in_set_conv_nth intro!: memR_tfin_refl 8(3)) + apply (metis One_nat_def diff_less length_greater_0_conv less_numeral_extra(1) min.commute min.strict_coboundedI2) + done + then show ?case + by auto +next + case (9 I r ts) + then show ?case + using atms_nonempty[of r] atms_finite[of r] + by auto (meson Min_le dual_order.trans finite_imageI image_iff) +next + case (10 I r ts) + have "ts \ [] \ Min {j. j \ min (length ts - Suc 0) (MIN f\atms r. progress f ts) \ + memR (ts ! j) (ts ! min (length ts - Suc 0) (MIN f\atms r. progress f ts)) I} + \ length ts" + apply (rule le_trans[OF Min_le[where ?x="min (length ts - Suc 0) (Min ((\f. progress f ts) ` atms r))"]]) + apply (auto simp: in_set_conv_nth intro!: memR_tfin_refl 10(2)) + apply (metis One_nat_def diff_less length_greater_0_conv less_numeral_extra(1) min.commute min.strict_coboundedI2) + done + then show ?case + by auto +qed (auto split: nat.splits) + +end \ No newline at end of file diff --git a/thys/VYDRA_MDL/Monitor.thy b/thys/VYDRA_MDL/Monitor.thy new file mode 100644 --- /dev/null +++ b/thys/VYDRA_MDL/Monitor.thy @@ -0,0 +1,1882 @@ +theory Monitor + imports MDL Temporal +begin + +type_synonym ('h, 't) time = "('h \ 't) option" + +datatype (dead 'a, dead 't :: timestamp, dead 'h) vydra_aux = + VYDRA_None + | VYDRA_Bool bool 'h + | VYDRA_Atom 'a 'h + | VYDRA_Neg "('a, 't, 'h) vydra_aux" + | VYDRA_Bin "bool \ bool \ bool" "('a, 't, 'h) vydra_aux" "('a, 't, 'h) vydra_aux" + | VYDRA_Prev "'t \" "('a, 't, 'h) vydra_aux" 'h "('t \ bool) option" + | VYDRA_Next "'t \" "('a, 't, 'h) vydra_aux" 'h "'t option" + | VYDRA_Since "'t \" "('a, 't, 'h) vydra_aux" "('a, 't, 'h) vydra_aux" "('h, 't) time" nat nat "nat option" "'t option" + | VYDRA_Until "'t \" "('h, 't) time" "('a, 't, 'h) vydra_aux" "('a, 't, 'h) vydra_aux" "('h, 't) time" nat "('t \ bool \ bool) option" + | VYDRA_MatchP "'t \" "transition iarray" nat + "(bool iarray, nat set, 't, ('h, 't) time, ('a, 't, 'h) vydra_aux list) window" + | VYDRA_MatchF "'t \" "transition iarray" nat + "(bool iarray, nat set, 't, ('h, 't) time, ('a, 't, 'h) vydra_aux list) window" + +type_synonym ('a, 't, 'h) vydra = "nat \ ('a, 't, 'h) vydra_aux" + +fun msize_vydra :: "nat \ ('a, 't :: timestamp, 'h) vydra_aux \ nat" where + "msize_vydra n VYDRA_None = 0" +| "msize_vydra n (VYDRA_Bool b e) = 0" +| "msize_vydra n (VYDRA_Atom a e) = 0" +| "msize_vydra (Suc n) (VYDRA_Bin f v1 v2) = msize_vydra n v1 + msize_vydra n v2 + 1" +| "msize_vydra (Suc n) (VYDRA_Neg v) = msize_vydra n v + 1" +| "msize_vydra (Suc n) (VYDRA_Prev I v e tb) = msize_vydra n v + 1" +| "msize_vydra (Suc n) (VYDRA_Next I v e to) = msize_vydra n v + 1" +| "msize_vydra (Suc n) (VYDRA_Since I vphi vpsi e cphi cpsi cppsi tppsi) = msize_vydra n vphi + msize_vydra n vpsi + 1" +| "msize_vydra (Suc n) (VYDRA_Until I e vphi vpsi epsi c zo) = msize_vydra n vphi + msize_vydra n vpsi + 1" +| "msize_vydra (Suc n) (VYDRA_MatchP I transs qf w) = size_list (msize_vydra n) (w_si w) + size_list (msize_vydra n) (w_sj w) + 1" +| "msize_vydra (Suc n) (VYDRA_MatchF I transs qf w) = size_list (msize_vydra n) (w_si w) + size_list (msize_vydra n) (w_sj w) + 1" +| "msize_vydra _ _ = 0" + +fun next_vydra :: "('a, 't :: timestamp, 'h) vydra_aux \ nat" where + "next_vydra (VYDRA_Next I v e None) = 1" +| "next_vydra _ = 0" + +context + fixes init_hd :: "'h" + and run_hd :: "'h \ ('h \ ('t :: timestamp \ 'a set)) option" +begin + +definition t0 :: "('h, 't) time" where + "t0 = (case run_hd init_hd of None \ None | Some (e', (t, X)) \ Some (e', t))" + +fun run_t :: "('h, 't) time \ (('h, 't) time \ 't) option" where + "run_t None = None" +| "run_t (Some (e, t)) = (case run_hd e of None \ Some (None, t) + | Some (e', (t', X)) \ Some (Some (e', t'), t))" + +fun read_t :: "('h, 't) time \ 't option" where + "read_t None = None" +| "read_t (Some (e, t)) = Some t" + +lemma run_t_read: "run_t x = Some (x', t) \ read_t x = Some t" + by (cases x) (auto split: option.splits) + +lemma read_t_run: "read_t x = Some t \ \x'. run_t x = Some (x', t)" + by (cases x) (auto split: option.splits) + +lemma reach_event_t: "reaches_on run_hd e vs e'' \ run_hd e = Some (e', (t, X)) \ + run_hd e'' = Some (e''', (t', X')) \ + reaches_on run_t (Some (e', t)) (map fst vs) (Some (e''', t'))" +proof (induction e vs e'' arbitrary: t' X' e''' rule: reaches_on_rev_induct) + case (2 s s' v vs s'') + obtain v_t v_X where v_def: "v = (v_t, v_X)" + by (cases v) auto + have run_t_s'': "run_t (Some (s'', v_t)) = Some (Some (e''', t'), v_t)" + by (auto simp: 2(5)) + show ?case + using reaches_on_app[OF 2(3)[OF 2(4) 2(2)[unfolded v_def]] run_t_s''] + by (auto simp: v_def) +qed (auto intro: reaches_on.intros) + +lemma reach_event_t0_t: + assumes "reaches_on run_hd init_hd vs e''" "run_hd e'' = Some (e''', (t', X'))" + shows "reaches_on run_t t0 (map fst vs) (Some (e''', t'))" +proof - + have t0_not_None: "t0 \ None" + apply (rule reaches_on.cases[OF assms(1)]) + using assms(2) + by (auto simp: t0_def split: option.splits prod.splits) + then show ?thesis + using reach_event_t[OF assms(1) _ assms(2)] + by (auto simp: t0_def split: option.splits) +qed + +lemma reaches_on_run_hd_t: + assumes "reaches_on run_hd init_hd vs e" + shows "\x. reaches_on run_t t0 (map fst vs) x" +proof (cases vs rule: rev_cases) + case (snoc ys y) + show ?thesis + using assms + apply (cases y) + apply (auto simp: snoc dest!: reaches_on_split_last) + apply (meson reaches_on_app[OF reach_event_t0_t] read_t.simps(2) read_t_run) + done +qed (auto intro: reaches_on.intros) + +definition "run_subs run = (\vs. let vs' = map run vs in + (if (\x \ set vs'. Option.is_none x) then None + else Some (map (fst \ the) vs', iarray_of_list (map (snd \ snd \ the) vs'))))" + +lemma run_subs_lD: "run_subs run vs = Some (vs', bs) \ + length vs' = length vs \ IArray.length bs = length vs" + by (auto simp: run_subs_def Let_def iarray_of_list_def split: option.splits if_splits) + +lemma run_subs_vD: "run_subs run vs = Some (vs', bs) \ j < length vs \ + \vj' tj bj. run (vs ! j) = Some (vj', (tj, bj)) \ vs' ! j = vj' \ IArray.sub bs j = bj" + apply (cases "run (vs ! j)") + apply (auto simp: Option.is_none_def run_subs_def Let_def iarray_of_list_def + split: option.splits if_splits) + by (metis image_eqI nth_mem) + +fun msize_fmla :: "('a, 'b :: timestamp) formula \ nat" + and msize_regex :: "('a, 'b) regex \ nat" where + "msize_fmla (Bool b) = 0" +| "msize_fmla (Atom a) = 0" +| "msize_fmla (Neg phi) = Suc (msize_fmla phi)" +| "msize_fmla (Bin f phi psi) = Suc (msize_fmla phi + msize_fmla psi)" +| "msize_fmla (Prev I phi) = Suc (msize_fmla phi)" +| "msize_fmla (Next I phi) = Suc (msize_fmla phi)" +| "msize_fmla (Since phi I psi) = Suc (max (msize_fmla phi) (msize_fmla psi))" +| "msize_fmla (Until phi I psi) = Suc (max (msize_fmla phi) (msize_fmla psi))" +| "msize_fmla (MatchP I r) = Suc (msize_regex r)" +| "msize_fmla (MatchF I r) = Suc (msize_regex r)" +| "msize_regex (Lookahead phi) = msize_fmla phi" +| "msize_regex (Symbol phi) = msize_fmla phi" +| "msize_regex (Plus r s) = max (msize_regex r) (msize_regex s)" +| "msize_regex (Times r s) = max (msize_regex r) (msize_regex s)" +| "msize_regex (Star r) = msize_regex r" + +lemma collect_subfmlas_msize: "x \ set (collect_subfmlas r []) \ + msize_fmla x \ msize_regex r" +proof (induction r) + case (Lookahead phi) + then show ?case + by (auto split: if_splits) +next + case (Symbol phi) + then show ?case + by (auto split: if_splits) +next + case (Plus r1 r2) + then show ?case + by (auto simp: collect_subfmlas_set[of r2 "collect_subfmlas r1 []"]) +next + case (Times r1 r2) + then show ?case + by (auto simp: collect_subfmlas_set[of r2 "collect_subfmlas r1 []"]) +next + case (Star r) + then show ?case + by fastforce +qed + +definition "until_ready I t c zo = (case (c, zo) of (Suc _, Some (t', b1, b2)) \ (b2 \ memL t t' I) \ \b1 | _ \ False)" + +definition "while_since_cond I t = (\(vpsi, e, cpsi :: nat, cppsi, tppsi). cpsi > 0 \ memL (the (read_t e)) t I)" +definition "while_since_body run = + (\(vpsi, e, cpsi :: nat, cppsi, tppsi). + case run vpsi of Some (vpsi', (t', b')) \ + Some (vpsi', fst (the (run_t e)), cpsi - 1, if b' then Some cpsi else cppsi, if b' then Some t' else tppsi) + | _ \ None + )" + +definition "while_until_cond I t = (\(vphi, vpsi, epsi, c, zo). \until_ready I t c zo \ (case read_t epsi of Some t' \ memR t t' I | None \ False))" +definition "while_until_body run = + (\(vphi, vpsi, epsi, c, zo). case run_t epsi of Some (epsi', t') \ + (case run vphi of Some (vphi', (_, b1)) \ + (case run vpsi of Some (vpsi', (_, b2)) \ Some (vphi', vpsi', epsi', Suc c, Some (t', b1, b2)) + | _ \ None) + | _ \ None))" + +function (sequential) run :: "nat \ ('a, 't, 'h) vydra_aux \ (('a, 't, 'h) vydra_aux \ ('t \ bool)) option" where + "run n (VYDRA_None) = None" +| "run n (VYDRA_Bool b e) = (case run_hd e of None \ None + | Some (e', (t, _)) \ Some (VYDRA_Bool b e', (t, b)))" +| "run n (VYDRA_Atom a e) = (case run_hd e of None \ None + | Some (e', (t, X)) \ Some (VYDRA_Atom a e', (t, a \ X)))" +| "run (Suc n) (VYDRA_Neg v) = (case run n v of None \ None + | Some (v', (t, b)) \ Some (VYDRA_Neg v', (t, \b)))" +| "run (Suc n) (VYDRA_Bin f vl vr) = (case run n vl of None \ None + | Some (vl', (t, bl)) \ (case run n vr of None \ None + | Some (vr', (_, br)) \ Some (VYDRA_Bin f vl' vr', (t, f bl br))))" +| "run (Suc n) (VYDRA_Prev I v e tb) = (case run_hd e of Some (e', (t, _)) \ + (let \ = (case tb of Some (t', b') \ b' \ mem t' t I | None \ False) in + case run n v of Some (v', _, b') \ Some (VYDRA_Prev I v' e' (Some (t, b')), (t, \)) + | None \ Some (VYDRA_None, (t, \))) + | None \ None)" +| "run (Suc n) (VYDRA_Next I v e to) = (case run_hd e of Some (e', (t, _)) \ + (case to of None \ + (case run n v of Some (v', _, _) \ run (Suc n) (VYDRA_Next I v' e' (Some t)) + | None \ None) + | Some t' \ + (case run n v of Some (v', _, b) \ Some (VYDRA_Next I v' e' (Some t), (t', b \ mem t' t I)) + | None \ if mem t' t I then None else Some (VYDRA_None, (t', False)))) + | None \ None)" +| "run (Suc n) (VYDRA_Since I vphi vpsi e cphi cpsi cppsi tppsi) = (case run n vphi of + Some (vphi', (t, b1)) \ + let cphi = (if b1 then Suc cphi else 0) in + let cpsi = Suc cpsi in + let cppsi = map_option Suc cppsi in + (case while_break (while_since_cond I t) (while_since_body (run n)) (vpsi, e, cpsi, cppsi, tppsi) of Some (vpsi', e', cpsi', cppsi', tppsi') \ + (let \ = (case cppsi' of Some k \ k - 1 \ cphi \ memR (the tppsi') t I | _ \ False) in + Some (VYDRA_Since I vphi' vpsi' e' cphi cpsi' cppsi' tppsi', (t, \))) + | _ \ None) + | _ \ None)" +| "run (Suc n) (VYDRA_Until I e vphi vpsi epsi c zo) = (case run_t e of Some (e', t) \ + (case while_break (while_until_cond I t) (while_until_body (run n)) (vphi, vpsi, epsi, c, zo) of Some (vphi', vpsi', epsi', c', zo') \ + if c' = 0 then None else + (case zo' of Some (t', b1, b2) \ + (if b2 \ memL t t' I then Some (VYDRA_Until I e' vphi' vpsi' epsi' (c' - 1) zo', (t, True)) + else if \b1 then Some (VYDRA_Until I e' vphi' vpsi' epsi' (c' - 1) zo', (t, False)) + else (case read_t epsi' of Some t' \ Some (VYDRA_Until I e' vphi' vpsi' epsi' (c' - 1) zo', (t, False)) | _ \ None)) + | _ \ None) + | _ \ None) + | _ \ None)" +| "run (Suc n) (VYDRA_MatchP I transs qf w) = + (case eval_matchP (init_args ({0}, NFA.delta' transs qf, NFA.accept' transs qf) + (run_t, read_t) (run_subs (run n))) I w of None \ None + | Some ((t, b), w') \ Some (VYDRA_MatchP I transs qf w', (t, b)))" +| "run (Suc n) (VYDRA_MatchF I transs qf w) = + (case eval_matchF (init_args ({0}, NFA.delta' transs qf, NFA.accept' transs qf) + (run_t, read_t) (run_subs (run n))) I w of None \ None + | Some ((t, b), w') \ Some (VYDRA_MatchF I transs qf w', (t, b)))" +| "run _ _ = undefined" + by pat_completeness auto +termination + by (relation "(\p. size (fst p)) <*mlex*> (\p. next_vydra (snd p)) <*mlex*> (\p. msize_vydra (fst p) (snd p)) <*mlex*> {}") (auto simp: mlex_prod_def) + +lemma wf_since: "wf {(t, s). while_since_cond I tt s \ Some t = while_since_body (run n) s}" +proof - + let ?X = "{(t, s). while_since_cond I tt s \ Some t = while_since_body (run n) s}" + have sub: "?X \ measure (\(vpsi, e, cpsi, cppsi, tppsi). cpsi)" + by (auto simp: while_since_cond_def while_since_body_def Let_def split: option.splits) + then show ?thesis + using wf_subset[OF wf_measure] + by auto +qed + +definition run_vydra :: "('a, 't, 'h) vydra \ (('a, 't, 'h) vydra \ ('t \ bool)) option" where + "run_vydra v = (case v of (n, w) \ map_option (apfst (Pair n)) (run n w))" + +fun sub :: "nat \ ('a, 't) formula \ ('a, 't, 'h) vydra_aux" where + "sub n (Bool b) = VYDRA_Bool b init_hd" +| "sub n (Atom a) = VYDRA_Atom a init_hd" +| "sub (Suc n) (Neg phi) = VYDRA_Neg (sub n phi)" +| "sub (Suc n) (Bin f phi psi) = VYDRA_Bin f (sub n phi) (sub n psi)" +| "sub (Suc n) (Prev I phi) = VYDRA_Prev I (sub n phi) init_hd None" +| "sub (Suc n) (Next I phi) = VYDRA_Next I (sub n phi) init_hd None" +| "sub (Suc n) (Since phi I psi) = VYDRA_Since I (sub n phi) (sub n psi) t0 0 0 None None" +| "sub (Suc n) (Until phi I psi) = VYDRA_Until I t0 (sub n phi) (sub n psi) t0 0 None" +| "sub (Suc n) (MatchP I r) = (let qf = state_cnt r; + transs = iarray_of_list (build_nfa_impl r (0, qf, [])) in + VYDRA_MatchP I transs qf (init_window (init_args + ({0}, NFA.delta' transs qf, NFA.accept' transs qf) + (run_t, read_t) (run_subs (run n))) + t0 (map (sub n) (collect_subfmlas r []))))" +| "sub (Suc n) (MatchF I r) = (let qf = state_cnt r; + transs = iarray_of_list (build_nfa_impl r (0, qf, [])) in + VYDRA_MatchF I transs qf (init_window (init_args + ({0}, NFA.delta' transs qf, NFA.accept' transs qf) + (run_t, read_t) (run_subs (run n))) + t0 (map (sub n) (collect_subfmlas r []))))" +| "sub _ _ = undefined" + +definition init_vydra :: "('a, 't) formula \ ('a, 't, 'h) vydra" where + "init_vydra \ = (let n = msize_fmla \ in (n, sub n \))" + +end + +locale VYDRA_MDL = MDL \ + for \ :: "('a, 't :: timestamp) trace" + + fixes init_hd :: "'h" + and run_hd :: "'h \ ('h \ ('t \ 'a set)) option" + assumes run_hd_sound: "reaches run_hd init_hd n s \ run_hd s = Some (s', (t, X)) \ (t, X) = (\ \ n, \ \ n)" +begin + +lemma reaches_on_run_hd: "reaches_on run_hd init_hd es s \ run_hd s = Some (s', (t, X)) \ t = \ \ (length es) \ X = \ \ (length es)" + using run_hd_sound + by (auto dest: reaches_on_n) + +abbreviation "ru_t \ run_t run_hd" +abbreviation "l_t0 \ t0 init_hd run_hd" +abbreviation "ru \ run run_hd" +abbreviation "su \ sub init_hd run_hd" + +lemma ru_t_event: "reaches_on ru_t t ts t' \ t = l_t0 \ ru_t t' = Some (t'', x) \ + \rho e tt. t' = Some (e, tt) \ reaches_on run_hd init_hd rho e \ length rho = Suc (length ts) \ + x = \ \ (length ts)" +proof (induction t ts t' arbitrary: t'' x rule: reaches_on_rev_induct) + case (1 s) + show ?case + using 1 reaches_on_run_hd[OF reaches_on.intros(1)] + by (auto simp: t0_def split: option.splits intro!: reaches_on.intros) +next + case (2 s s' v vs s'') + obtain rho e tt where rho_def: "s' = Some (e, tt)" "reaches_on run_hd init_hd rho e" + "length rho = Suc (length vs)" + using 2(3)[OF 2(4,2)] + by auto + then show ?case + using 2(2,5) reaches_on_app[OF rho_def(2)] reaches_on_run_hd[OF rho_def(2)] + by (fastforce split: option.splits) +qed + +lemma ru_t_tau: "reaches_on ru_t l_t0 ts t' \ ru_t t' = Some (t'', x) \ x = \ \ (length ts)" + using ru_t_event + by fastforce + +lemma ru_t_Some_tau: + assumes "reaches_on ru_t l_t0 ts (Some (e, t))" + shows "t = \ \ (length ts)" +proof - + obtain z where z_def: "ru_t (Some (e, t)) = Some (z, t)" + by (cases "run_hd e") auto + show ?thesis + by (rule ru_t_tau[OF assms z_def]) +qed + +lemma ru_t_tau_in: + assumes "reaches_on ru_t l_t0 ts t" "j < length ts" + shows "ts ! j = \ \ j" +proof - + obtain t' where t'_def: "reaches_on ru_t l_t0 (take j ts) t'" "reaches_on ru_t t' (drop j ts) t" + using reaches_on_split'[OF assms(1), where ?i=j] assms(2) + by auto + have drop: "drop j ts = ts ! j # tl (drop j ts)" + using assms(2) + by (cases "drop j ts") (auto simp add: nth_via_drop) + obtain t'' where t''_def: "ru_t t' = Some (t'', ts ! j)" + using t'_def(2) assms(2) drop + by (auto elim: reaches_on.cases) + show ?thesis + using ru_t_event[OF t'_def(1) refl t''_def] assms(2) + by auto +qed + +lemmas run_hd_tau_in = ru_t_tau_in[OF reach_event_t0_t, simplified] + +fun last_before :: "(nat \ bool) \ nat \ nat option" where + "last_before P 0 = None" +| "last_before P (Suc n) = (if P n then Some n else last_before P n)" + +lemma last_before_None: "last_before P n = None \ m < n \ \P m" +proof (induction P n rule: last_before.induct) + case (2 P n) + then show ?case + by (cases "m = n") (auto split: if_splits) +qed (auto split: if_splits) + +lemma last_before_Some: "last_before P n = Some m \ m < n \ P m \ (\k \ {m<..P k)" + apply (induction P n rule: last_before.induct) + apply (auto split: if_splits) + apply (metis greaterThanLessThan_iff less_antisym) + done + +inductive wf_vydra :: "('a, 't :: timestamp) formula \ nat \ nat \ ('a, 't, 'h) vydra_aux \ bool" where + "wf_vydra phi i n w \ ru n w = None \ wf_vydra (Prev I phi) (Suc i) (Suc n) VYDRA_None" +| "wf_vydra phi i n w \ ru n w = None \ wf_vydra (Next I phi) i (Suc n) VYDRA_None" +| "reaches_on run_hd init_hd es sub' \ length es = i \ wf_vydra (Bool b) i n (VYDRA_Bool b sub')" +| "reaches_on run_hd init_hd es sub' \ length es = i \ wf_vydra (Atom a) i n (VYDRA_Atom a sub')" +| "wf_vydra phi i n v \ wf_vydra (Neg phi) i (Suc n) (VYDRA_Neg v)" +| "wf_vydra phi i n v \ wf_vydra psi i n v' \ wf_vydra (Bin f phi psi) i (Suc n) (VYDRA_Bin f v v')" +| "wf_vydra phi i n v \ reaches_on run_hd init_hd es sub' \ length es = i \ + wf_vydra (Prev I phi) i (Suc n) (VYDRA_Prev I v sub' (case i of 0 \ None | Suc j \ Some (\ \ j, sat phi j)))" +| "wf_vydra phi i n v \ reaches_on run_hd init_hd es sub' \ length es = i \ + wf_vydra (Next I phi) (i - 1) (Suc n) (VYDRA_Next I v sub' (case i of 0 \ None | Suc j \ Some (\ \ j)))" +| "wf_vydra phi i n vphi \ wf_vydra psi j n vpsi \ j \ i \ + reaches_on ru_t l_t0 es sub' \ length es = j \ (\t. t \ set es \ memL t (\ \ i) I) \ + cphi = i - (case last_before (\k. \sat phi k) i of None \ 0 | Some k \ Suc k) \ cpsi = i - j \ + cppsi = (case last_before (sat psi) j of None \ None | Some k \ Some (i - k)) \ + tppsi = (case last_before (sat psi) j of None \ None | Some k \ Some (\ \ k)) \ + wf_vydra (Since phi I psi) i (Suc n) (VYDRA_Since I vphi vpsi sub' cphi cpsi cppsi tppsi)" +| "wf_vydra phi j n vphi \ wf_vydra psi j n vpsi \ i \ j \ + reaches_on ru_t l_t0 es back \ length es = i \ + reaches_on ru_t l_t0 es' front \ length es' = j \ (\t. t \ set es' \ memR (\ \ i) t I) \ + c = j - i \ z = (case j of 0 \ None | Suc k \ Some (\ \ k, sat phi k, sat psi k)) \ + (\k. k \ {i.. sat phi k \ (memL (\ \ i) (\ \ k) I \ \sat psi k)) \ + wf_vydra (Until phi I psi) i (Suc n) (VYDRA_Until I back vphi vpsi front c z)" +| "valid_window_matchP args I l_t0 (map (su n) (collect_subfmlas r [])) xs i w \ + n \ msize_regex r \ qf = state_cnt r \ + transs = iarray_of_list (build_nfa_impl r (0, qf, [])) \ + args = init_args ({0}, NFA.delta' transs qf, NFA.accept' transs qf) + (ru_t, read_t) (run_subs (ru n)) \ + wf_vydra (MatchP I r) i (Suc n) (VYDRA_MatchP I transs qf w)" +| "valid_window_matchF args I l_t0 (map (su n) (collect_subfmlas r [])) xs i w \ + n \ msize_regex r \ qf = state_cnt r \ + transs = iarray_of_list (build_nfa_impl r (0, qf, [])) \ + args = init_args ({0}, NFA.delta' transs qf, NFA.accept' transs qf) + (ru_t, read_t) (run_subs (ru n)) \ + wf_vydra (MatchF I r) i (Suc n) (VYDRA_MatchF I transs qf w)" + +lemma reach_run_subs_len: + assumes reaches_ons: "reaches_on (run_subs (ru n)) (map (su n) (collect_subfmlas r [])) rho vs" + shows "length vs = length (collect_subfmlas r [])" + using reaches_ons run_subs_lD + by (induction "map (su n) (collect_subfmlas r [])" rho vs rule: reaches_on_rev_induct) fastforce+ + +lemma reach_run_subs_run: + assumes reaches_ons: "reaches_on (run_subs (ru n)) (map (su n) (collect_subfmlas r [])) rho vs" + and subfmla: "j < length (collect_subfmlas r [])" "phi = collect_subfmlas r [] ! j" + shows "\rho'. reaches_on (ru n) (su n phi) rho' (vs ! j) \ length rho' = length rho" + using reaches_ons subfmla +proof (induction "map (su n) (collect_subfmlas r [])" rho vs rule: reaches_on_rev_induct) + case 1 + then show ?case + by (auto intro: reaches_on.intros) +next + case (2 s' v vs' s'') + note len_s'_vs = reach_run_subs_len[OF 2(1)] + obtain rho' where reach_s'_vs: "reaches_on (ru n) (su n phi) rho' (s' ! j)" + "length rho' = length vs'" + using 2(2)[OF 2(4,5)] + by auto + note run_subslD = run_subs_lD[OF 2(3)] + note run_subsvD = run_subs_vD[OF 2(3) 2(4)[unfolded len_s'_vs[symmetric]]] + obtain vj' tj bj where vj'_def: "ru n (s' ! j) = Some (vj', tj, bj)" + "s'' ! j = vj'" "IArray.sub v j = bj" + using run_subsvD by auto + obtain rho'' where rho''_def: "reaches_on (ru n) (su n phi) rho'' (s'' ! j)" + "length rho'' = Suc (length vs')" + using reaches_on_app[OF reach_s'_vs(1) vj'_def(1)] vj'_def(2) reach_s'_vs(2) + by auto + then show ?case + using conjunct1[OF run_subslD, unfolded len_s'_vs[symmetric]] + by auto +qed + +lemma IArray_nth_equalityI: "IArray.length xs = length ys \ + (\i. i < IArray.length xs \ IArray.sub xs i = ys ! i) \ xs = IArray ys" + by (induction xs arbitrary: ys) (auto intro: nth_equalityI) + +lemma bs_sat: + assumes IH: "\phi i v v' b. phi \ set (collect_subfmlas r []) \ wf_vydra phi i n v \ ru n v = Some (v', b) \ snd b = sat phi i" + and reaches_ons: "\j. j < length (collect_subfmlas r []) \ wf_vydra (collect_subfmlas r [] ! j) i n (vs ! j)" + and run_subs: "run_subs (ru n) vs = Some (vs', bs)" "length vs = length (collect_subfmlas r [])" + shows "bs = iarray_of_list (map (\phi. sat phi i) (collect_subfmlas r []))" +proof - + have "\j. j < length (collect_subfmlas r []) \ + IArray.sub bs j = sat (collect_subfmlas r [] ! j) i" + proof - + fix j + assume lassm: "j < length (collect_subfmlas r [])" + define phi where "phi = collect_subfmlas r [] ! j" + have phi_in_set: "phi \ set (collect_subfmlas r [])" + using lassm + by (auto simp: phi_def) + have wf: "wf_vydra phi i n (vs ! j)" + using reaches_ons lassm phi_def + by metis + show "IArray.sub bs j = sat (collect_subfmlas r [] ! j) i" + using IH(1)[OF phi_in_set wf] run_subs_vD[OF run_subs(1) lassm[folded run_subs(2)]] + unfolding phi_def[symmetric] + by auto + qed + moreover have "length (IArray.list_of bs) = length vs" + using run_subs(1) + by (auto simp: run_subs_def Let_def iarray_of_list_def split: if_splits) + ultimately show ?thesis + using run_subs(2) + by (auto simp: iarray_of_list_def intro!: IArray_nth_equalityI) +qed + +lemma run_induct[case_names Bool Atom Neg Bin Prev Next Since Until MatchP MatchF, consumes 1]: + fixes phi :: "('a, 't) formula" + assumes "msize_fmla phi \ n" "(\b n. P n (Bool b))" "(\a n. P n (Atom a))" + "(\n phi. msize_fmla phi \ n \ P n phi \ P (Suc n) (Neg phi))" + "(\n f phi psi. msize_fmla (Bin f phi psi) \ Suc n \ P n phi \ P n psi \ + P (Suc n) (Bin f phi psi))" + "(\n I phi. msize_fmla phi \ n \ P n phi \ P (Suc n) (Prev I phi))" + "(\n I phi. msize_fmla phi \ n \ P n phi \ P (Suc n) (Next I phi))" + "(\n I phi psi. msize_fmla phi \ n \ msize_fmla psi \ n \ P n phi \ P n psi \ P (Suc n) (Since phi I psi))" + "(\n I phi psi. msize_fmla phi \ n \ msize_fmla psi \ n \ P n phi \ P n psi \ P (Suc n) (Until phi I psi))" + "(\n I r. msize_fmla (MatchP I r) \ Suc n \ (\x. msize_fmla x \ n \ P n x) \ + P (Suc n) (MatchP I r))" + "(\n I r. msize_fmla (MatchF I r) \ Suc n \ (\x. msize_fmla x \ n \ P n x) \ + P (Suc n) (MatchF I r))" + shows "P n phi" + using assms(1) +proof (induction n arbitrary: phi rule: nat_less_induct) + case (1 n) + show ?case + proof (cases n) + case 0 + show ?thesis + using 1 assms(2-) + by (cases phi) (auto simp: 0) + next + case (Suc m) + show ?thesis + using 1 assms(2-) + by (cases phi) (auto simp: Suc) + qed +qed + +lemma wf_vydra_sub: "msize_fmla \ \ n \ wf_vydra \ 0 n (su n \)" +proof (induction n \ rule: run_induct) + case (Prev n I phi) + then show ?case + using wf_vydra.intros(7)[where ?i=0, OF _ reaches_on.intros(1)] + by auto +next + case (Next n I phi) + then show ?case + using wf_vydra.intros(8)[where ?i=0, OF _ reaches_on.intros(1)] + by auto +next + case (MatchP n I r) + let ?qf = "state_cnt r" + let ?transs = "iarray_of_list (build_nfa_impl r (0, ?qf, []))" + let ?args = "init_args ({0}, NFA.delta' ?transs ?qf, NFA.accept' ?transs ?qf) (ru_t, read_t) (run_subs (ru n))" + show ?case + using MatchP valid_init_window[of ?args l_t0 "map (su n) (collect_subfmlas r [])", simplified] + by (auto simp: Let_def valid_window_matchP_def split: option.splits intro: reaches_on.intros + intro!: wf_vydra.intros(11)[where ?xs="[]", OF _ _ refl refl refl]) +next + case (MatchF n I r) + let ?qf = "state_cnt r" + let ?transs = "iarray_of_list (build_nfa_impl r (0, ?qf, []))" + let ?args = "init_args ({0}, NFA.delta' ?transs ?qf, NFA.accept' ?transs ?qf) (ru_t, read_t) (run_subs (ru n))" + show ?case + using MatchF valid_init_window[of ?args l_t0 "map (su n) (collect_subfmlas r [])", simplified] + by (auto simp: Let_def valid_window_matchF_def split: option.splits intro: reaches_on.intros + intro!: wf_vydra.intros(12)[where ?xs="[]", OF _ _ refl refl refl]) +qed (auto simp: Let_def intro: wf_vydra.intros reaches_on.intros) + +lemma ru_t_Some: "\e' et. ru_t e = Some (e', et)" if reaches_Suc_i: "reaches_on run_hd init_hd fs f" "length fs = Suc i" + and aux: "reaches_on ru_t l_t0 es e" "length es \ i" for es e +proof - + obtain fs' ft where ft_def: "reaches_on ru_t l_t0 (map fst (fs' :: ('t \ 'a set) list)) (Some (f, ft))" + "map fst fs = map fst fs' @ [ft]" "length fs' = i" + using reaches_Suc_i + by (cases fs rule: rev_cases) (auto dest!: reaches_on_split_last reach_event_t0_t) + show ?thesis + proof (cases "length es = i") + case True + have e_def: "e = Some (f, ft)" + using reaches_on_inj[OF aux(1) ft_def(1)] + by (auto simp: True ft_def(3)) + then show ?thesis + by (cases "run_hd f") (auto simp: e_def) + next + case False + obtain s' s'' where split: "reaches_on ru_t l_t0 (take (length es) (map fst fs')) s'" + "ru_t s' = Some (s'', map fst fs' ! (length es))" + using reaches_on_split[OF ft_def(1), where ?i="length es"] False aux(2) + by (auto simp: ft_def(3)) + show ?thesis + using reaches_on_inj[OF aux(1) split(1)] aux(2) + by (auto simp: ft_def(3) split(2)) + qed +qed + +lemma vydra_sound_aux: + assumes "msize_fmla \ \ n" "wf_vydra \ i n v" "ru n v = Some (v', t, b)" "bounded_future_fmla \" "wf_fmla \" + shows "wf_vydra \ (Suc i) n v' \ (\es e. reaches_on run_hd init_hd es e \ length es = Suc i) \ t = \ \ i \ b = sat \ i" + using assms +proof (induction n \ arbitrary: i v v' t b rule: run_induct) + case (Bool \ n) + then show ?case + using reaches_on_run_hd reaches_on_app wf_vydra.intros(3)[OF reaches_on_app refl] + by (fastforce elim!: wf_vydra.cases[of _ _ _ "v"] split: option.splits) +next + case (Atom a n) + then show ?case + using reaches_on_run_hd reaches_on_app wf_vydra.intros(4)[OF reaches_on_app refl] + by (fastforce elim!: wf_vydra.cases[of _ _ _ v] split: option.splits) +next + case (Neg n x) + have IH: "wf_vydra x i n v \ ru n v = Some (v', t, b) \ wf_vydra x (Suc i) n v' \ (\es e. reaches_on run_hd init_hd es e \ length es = Suc i) \ t = \ \ i \ b = sat x i" for v v' t b + using Neg(2,5,6) + by auto + show ?case + apply (rule wf_vydra.cases[OF Neg(3)]) + using Neg(4) IH wf_vydra.intros(5) + by (fastforce split: option.splits)+ +next + case (Bin n f x1 x2) + have IH1: "wf_vydra x1 i n v \ ru n v = Some (v', t, b) \ wf_vydra x1 (Suc i) n v' \ (\es e. reaches_on run_hd init_hd es e \ length es = Suc i) \ t = \ \ i \ b = sat x1 i" for v v' t b + using Bin(2,6,7) + by auto + have IH2: "wf_vydra x2 i n v \ ru n v = Some (v', t, b) \ wf_vydra x2 (Suc i) n v' \ t = \ \ i \ b = sat x2 i" for v v' t b + using Bin(3,6,7) + by auto + show ?case + apply (rule wf_vydra.cases[OF Bin(4)]) + using Bin(5) IH1 IH2 wf_vydra.intros(6) + by (fastforce split: option.splits)+ +next + case (Prev n I phi) + show ?case + proof (cases i) + case 0 + then show ?thesis + using Prev run_hd_sound[OF reaches.intros(1)] wf_vydra.intros(7)[OF _ reaches_on.intros(2)[OF _ reaches_on.intros(1)], where ?i="Suc 0", simplified] + by (fastforce split: nat.splits option.splits dest!: reaches_on_NilD elim!: wf_vydra.cases[of _ _ _ v] intro: wf_vydra.intros(1) reaches_on.intros(2)[OF _ reaches_on.intros(1)]) + next + case (Suc j) + obtain vphi es sub where v_def: "v = VYDRA_Prev I vphi sub (Some (\ \ j, sat phi j))" + "wf_vydra phi i n vphi" "reaches_on run_hd init_hd es sub" "length es = i" + using Prev(3,4) + by (auto simp: Suc elim!: wf_vydra.cases[of _ _ _ v]) + obtain sub' X where run_sub: "run_hd sub = Some (sub', (t, X))" + using Prev(4) + by (auto simp: v_def(1) Let_def split: option.splits) + note reaches_sub' = reaches_on_app[OF v_def(3) run_sub] + have t_def: "t = \ \ (Suc j)" + using reaches_on_run_hd[OF v_def(3) run_sub] + by (auto simp: Suc v_def(2,4)) + show ?thesis + proof (cases "v' = VYDRA_None") + case v'_def: True + show ?thesis + using Prev(4) v_def(2) reaches_sub' + by (auto simp: Suc Let_def v_def(1,4) v'_def run_sub t_def split: option.splits intro: wf_vydra.intros(1)) + next + case False + obtain vphi' where ru_vphi: "ru n vphi = Some (vphi', (\ \ i, sat phi i))" + using Prev(2)[OF v_def(2)] Prev(4,5,6) False + by (auto simp: v_def(1) Let_def split: option.splits) + have wf': "wf_vydra phi (Suc (Suc j)) n vphi'" + using Prev(2)[OF v_def(2) ru_vphi] Prev(5,6) + by (auto simp: Suc) + show ?thesis + using Prev(4) wf_vydra.intros(7)[OF wf' reaches_sub'] reaches_sub' + by (auto simp: Let_def Suc t_def v_def(1,4) run_sub ru_vphi) + qed + qed +next + case (Next n I phi) + obtain w sub to es where v_def: "v = VYDRA_Next I w sub to" "wf_vydra phi (length es) n w" + "reaches_on run_hd init_hd es sub" "length es = (case to of None \ 0 | _ \ Suc i)" + "case to of None \ i = 0 | Some told \ told = \ \ i" + using Next(3,4) + by (auto elim!: wf_vydra.cases[of _ _ _ v] split: option.splits nat.splits) + obtain sub' tnew X where run_sub: "run_hd sub = Some (sub', (tnew, X))" + using Next(4) + by (auto simp: v_def(1) split: option.splits) + have tnew_def: "tnew = \ \ (length es)" + using reaches_on_run_hd[OF v_def(3) run_sub] + by auto + have aux: ?case if aux_assms: "wf_vydra phi (Suc i) n w" + "ru (Suc n) (VYDRA_Next I w sub (Some t0)) = Some (v', t, b)" + "reaches_on run_hd init_hd es sub" "length es = Suc i" "t0 = \ \ i" for w sub t0 es + using aux_assms(1,2,5) wf_vydra.intros(2)[OF aux_assms(1)] + Next(2)[where ?i="Suc i" and ?v="w"] Next(5,6) reaches_on_run_hd[OF aux_assms(3)] + wf_vydra.intros(8)[OF _ reaches_on_app[OF aux_assms(3)], where ?phi=phi and ?i="Suc (Suc i)" and ?n="n"] aux_assms(3) + by (auto simp: run_sub aux_assms(4,5) split: option.splits if_splits) + show ?case + proof (cases to) + case None + obtain w' z where w_def: "ru (Suc n) v = ru (Suc n) (VYDRA_Next I w' sub' (Some tnew))" + "ru n w = Some (w', z)" + using Next(4) + by (cases "ru n w") (auto simp: v_def(1) run_sub None split: option.splits) + have wf: "wf_vydra phi (Suc i) n w'" + using v_def w_def(2) Next(2,5,6) + by (cases z) (auto simp: None intro: wf_vydra.intros(1)) + show ?thesis + using aux[OF wf Next(4)[unfolded w_def(1)] reaches_on_app[OF v_def(3) run_sub]] v_def(4,5) tnew_def + by (auto simp: None) + next + case (Some z) + show ?thesis + using aux[OF _ _ v_def(3), where ?w="w"] v_def(2,4,5) Next(4) + by (auto simp: v_def(1) Some simp del: run.simps) + qed +next + case (Since n I phi psi) + obtain vphi vpsi e cphi cpsi cppsi tppsi j es where v_def: + "v = VYDRA_Since I vphi vpsi e cphi cpsi cppsi tppsi" + "wf_vydra phi i n vphi" "wf_vydra psi j n vpsi" "j \ i" + "reaches_on ru_t l_t0 es e" "length es = j" "\t. t \ set es \ memL t (\ \ i) I" + "cphi = i - (case last_before (\k. \sat phi k) i of None \ 0 | Some k \ Suc k)" "cpsi = i - j" + "cppsi = (case last_before (sat psi) j of None \ None | Some k \ Some (i - k))" + "tppsi = (case last_before (sat psi) j of None \ None | Some k \ Some (\ \ k))" + using Since(5) + by (auto elim: wf_vydra.cases) + obtain vphi' b1 where run_vphi: "ru n vphi = Some (vphi', t, b1)" + using Since(6) + by (auto simp: v_def(1) Let_def split: option.splits) + obtain fs f where wf_vphi': "wf_vydra phi (Suc i) n vphi'" + and reaches_Suc_i: "reaches_on run_hd init_hd fs f" "length fs = Suc i" + and t_def: "t = \ \ i" and b1_def: "b1 = sat phi i" + using Since(3)[OF v_def(2) run_vphi] Since(7,8) + by auto + note ru_t_Some = ru_t_Some[OF reaches_Suc_i] + define loop_inv where "loop_inv = (\(vpsi, e, cpsi :: nat, cppsi, tppsi). + let j = Suc i - cpsi in cpsi \ Suc i \ + wf_vydra psi j n vpsi \ (\es. reaches_on ru_t l_t0 es e \ length es = j \ (\t \ set es. memL t (\ \ i) I)) \ + cppsi = (case last_before (sat psi) j of None \ None | Some k \ Some (Suc i - k)) \ + tppsi = (case last_before (sat psi) j of None \ None | Some k \ Some (\ \ k)))" + define loop_init where "loop_init = (vpsi, e, Suc cpsi, map_option Suc cppsi, tppsi)" + obtain vpsi' e' cpsi' cppsi' tppsi' where loop_def: "while_break (while_since_cond I t) (while_since_body run_hd (ru n)) loop_init = + Some (vpsi', e', cpsi', cppsi', tppsi')" + using Since(6) + by (auto simp: v_def(1) run_vphi loop_init_def Let_def split: option.splits) + have j_def: "j = i - cpsi" + using v_def(4,9) + by auto + have "cpsi \ i" + using v_def(9) + by auto + then have loop_inv_init: "loop_inv loop_init" + using v_def(3,5,6,7,10,11) last_before_Some + by (fastforce simp: loop_inv_def loop_init_def Let_def j_def split: option.splits) + have wf_loop: "wf {(s', s). loop_inv s \ while_since_cond I t s \ Some s' = while_since_body run_hd (ru n) s}" + by (auto intro: wf_subset[OF wf_since]) + have step_loop: "loop_inv s'" if loop_assms: "loop_inv s" "while_since_cond I t s" "while_since_body run_hd (ru n) s = Some s'" for s s' + proof - + obtain vpsi e cpsi cppsi tppsi where s_def: "s = (vpsi, e, cpsi, cppsi, tppsi)" + by (cases s) auto + define j where "j = Suc i - cpsi" + obtain es where loop_before: "cpsi \ Suc i" "wf_vydra psi j n vpsi" + "reaches_on ru_t l_t0 es e" "length es = j" "\t. t \ set es \ memL t (\ \ i) I" + "cppsi = (case last_before (sat psi) j of None \ None | Some k \ Some (Suc i - k))" + "tppsi = (case last_before (sat psi) j of None \ None | Some k \ Some (\ \ k))" + using loop_assms(1) + by (auto simp: s_def j_def loop_inv_def Let_def) + obtain tt h where tt_def: "read_t e = Some tt" "memL tt t I" "e = Some (h, tt)" + using ru_t_Some[OF loop_before(3)] loop_before(4) loop_assms(2) + by (cases e) (fastforce simp: while_since_cond_def s_def j_def split: option.splits)+ + obtain e' where e'_def: "reaches_on ru_t l_t0 (es @ [tt]) e'" "ru_t e = Some (e', tt)" + using reaches_on_app[OF loop_before(3)] tt_def(1) + by (cases "run_hd h") (auto simp: tt_def(3)) + obtain vpsi' t' b' where run_vpsi: "ru n vpsi = Some (vpsi', (t', b'))" + using loop_assms(3) + by (auto simp: while_since_body_def s_def Let_def split: option.splits) + have wf_psi': "wf_vydra psi (Suc j) n vpsi'" and t'_def: "t' = \ \ j" and b'_def: "b' = sat psi j" + using Since(4)[OF loop_before(2) run_vpsi] Since(7,8) + by auto + define j' where j'_def: "j' = Suc i - (cpsi - Suc 0)" + have cpsi_pos: "cpsi > 0" + using loop_assms(2) + by (auto simp: while_since_cond_def s_def) + have j'_j: "j' = Suc j" + using loop_before(1) cpsi_pos + by (auto simp: j'_def j_def) + define cppsi' where "cppsi' = (if b' then Some cpsi else cppsi)" + define tppsi' where "tppsi' = (if b' then Some t' else tppsi)" + have cppsi': "cppsi' = (case last_before (sat psi) j' of None \ None | Some k \ Some (Suc i - k))" + using cpsi_pos loop_before(1) + by (auto simp: cppsi'_def b'_def j'_j loop_before(6) j_def) + have tppsi': "tppsi' = (case last_before (sat psi) j' of None \ None | Some k \ Some (\ \ k))" + by (auto simp: tppsi'_def t'_def b'_def j'_j loop_before(7) split: option.splits) + have s'_def: "s' = (vpsi', fst (the (ru_t e)), cpsi - Suc 0, cppsi', tppsi')" + using loop_assms(3) + by (auto simp: while_since_body_def s_def run_vpsi cppsi'_def tppsi'_def) + show ?thesis + using loop_before(1,4,5) tt_def(2) wf_psi'[folded j'_j] cppsi' tppsi' e'_def(1) + by (fastforce simp: loop_inv_def s'_def j'_def[symmetric] e'_def(2) j'_j t_def) + qed + have loop: "loop_inv (vpsi', e', cpsi', cppsi', tppsi')" "\while_since_cond I t (vpsi', e', cpsi', cppsi', tppsi')" + using while_break_sound[where ?P="loop_inv" and ?Q="\s. loop_inv s \ \while_since_cond I t s", OF step_loop _ wf_loop loop_inv_init] + by (auto simp: loop_def) + define cphi' where "cphi' = (if b1 then Suc cphi else 0)" + have v'_def: "v' = VYDRA_Since I vphi' vpsi' e' cphi' cpsi' cppsi' tppsi'" + and b_def: "b = (case cppsi' of None \ False | Some k \ k - 1 \ cphi' \ memR (the tppsi') t I)" + using Since(6) + by (auto simp: v_def(1) run_vphi loop_init_def[symmetric] loop_def cphi'_def Let_def split: option.splits) + have read_t_e': "cpsi' > 0 \ read_t e' = None \ False" + using loop(1) ru_t_Some[where ?e=e'] run_t_read + by (fastforce simp: loop_inv_def Let_def) + define j' where "j' = Suc i - cpsi'" + have wf_vpsi': "wf_vydra psi j' n vpsi'" and cpsi'_le_Suc_i: "cpsi' \ Suc i" + and cppsi'_def: "cppsi' = (case last_before (sat psi) j' of None \ None | Some k \ Some (Suc i - k))" + and tppsi'_def: "tppsi' = (case last_before (sat psi) j' of None \ None | Some k \ Some (\ \ k))" + using loop(1) + by (auto simp: loop_inv_def j'_def[symmetric]) + obtain es' where es'_def: "reaches_on ru_t l_t0 es' e'" "length es' = j'" "\t. t \ set es' \ memL t (\ \ i) I" + using loop(1) + by (auto simp: loop_inv_def j'_def[symmetric]) + have wf_v': "wf_vydra (Since phi I psi) (Suc i) (Suc n) v'" + and cphi'_sat: "cphi' = Suc i - (case last_before (\k. \sat phi k) (Suc i) of None \ 0 | Some k \ Suc k)" + using cpsi'_le_Suc_i last_before_Some es'_def(3) memL_mono'[OF _ \_mono[of i "Suc i" \]] + by (force simp: v'_def cppsi'_def tppsi'_def j'_def cphi'_def b1_def v_def(8) split: option.splits + intro!: wf_vydra.intros(9)[OF wf_vphi' wf_vpsi' _ es'_def(1-2)])+ + have "j' = Suc i \ \memL (\ \ j') (\ \ i) I" + using loop(2) j'_def read_t_e' ru_t_tau[OF es'_def(1)] read_t_run[where ?run_hd=run_hd] + by (fastforce simp: while_since_cond_def es'_def(2) t_def split: option.splits) + then have tau_k_j': "k \ i \ memL (\ \ k) (\ \ i) I \ k < j'" for k + using ru_t_tau_in[OF es'_def(1)] es'_def(3) \_mono[of j' k \] memL_mono + by (fastforce simp: es'_def(2) in_set_conv_nth) + have b_sat: "b = sat (Since phi I psi) i" + proof (rule iffI) + assume b: "b" + obtain m where m_def: "last_before (sat psi) j' = Some m" "i - m \ cphi'" "memR (\ \ m) (\ \ i) I" + using b + by (auto simp: b_def t_def cppsi'_def tppsi'_def split: option.splits) + note aux = last_before_Some[OF m_def(1)] + have mem: "mem (\ \ m) (\ \ i) I" + using m_def(3) tau_k_j' aux + by (auto simp: mem_def j'_def) + have sat_phi: "sat phi x" if "m < x" "x \ i" for x + using m_def(2) that le_neq_implies_less + by (fastforce simp: cphi'_sat dest: last_before_None last_before_Some split: option.splits if_splits) + show "sat (Since phi I psi) i" + using aux mem sat_phi + by (auto simp: j'_def intro!: exI[of _ m]) + next + assume sat: "sat (Since phi I psi) i" + then obtain k where k_def: "k \ i" "mem (\ \ k) (\ \ i) I" "sat psi k" "\k'. k < k' \ k' \ i \ sat phi k'" + by auto + have k_j': "k < j'" + using tau_k_j'[OF k_def(1)] k_def(2) + by (auto simp: mem_def) + obtain m where m_def: "last_before (sat psi) j' = Some m" + using last_before_None[where ?P="sat psi" and ?n=j' and ?m=k] k_def(3) k_j' + by (cases "last_before (sat psi) j'") auto + have cppsi'_Some: "cppsi' = Some (Suc i - m)" + by (auto simp: cppsi'_def m_def) + have tppsi'_Some: "tppsi' = Some (\ \ m)" + by (auto simp: tppsi'_def m_def) + have m_k: "k \ m" + using last_before_Some[OF m_def] k_def(3) k_j' + by auto + have tau_i_m: "memR (\ \ m) (\ \ i) I" + using \_mono[OF m_k, where ?s=\] memR_mono k_def(2) + by (auto simp: mem_def) + have "i - m \ cphi'" + using k_def(1) k_def(4) m_k + apply (cases "k = i") + apply (auto simp: cphi'_sat b1_def dest!: last_before_Some split: option.splits) + apply (metis diff_le_mono2 le_neq_implies_less le_trans less_imp_le_nat nat_le_linear) + done + then show "b" + using tau_i_m + by (auto simp: b_def t_def cppsi'_Some tppsi'_Some) + qed + show ?case + using wf_v' reaches_Suc_i + by (auto simp: t_def b_sat) +next + case (Until n I phi psi) + obtain "back" vphi vpsi front c z es es' j where v_def: + "v = VYDRA_Until I back vphi vpsi front c z" + "wf_vydra phi j n vphi" "wf_vydra psi j n vpsi" "i \ j" + "reaches_on ru_t l_t0 es back" "length es = i" + "reaches_on ru_t l_t0 es' front" "length es' = j" "\t. t \ set es' \ memR (\ \ i) t I" + "c = j - i" "z = (case j of 0 \ None | Suc k \ Some (\ \ k, sat phi k, sat psi k))" + "\k. k \ {i.. sat phi k \ (memL (\ \ i) (\ \ k) I \ \sat psi k)" + using Until(5) + by (auto elim: wf_vydra.cases) + define loop_init where "loop_init = (vphi, vpsi, front, c, z)" + obtain back' vphi' vpsi' epsi' c' zo' zt zb1 zb2 where run_back: "ru_t back = Some (back', t)" + and loop_def: "while_break (while_until_cond I t) (while_until_body run_hd (ru n)) loop_init = Some (vphi', vpsi', epsi', c', zo')" + and v'_def: "v' = VYDRA_Until I back' vphi' vpsi' epsi' (c' - 1) zo'" + and c'_pos: "\c' = 0" + and zo'_Some: "zo' = Some (zt, (zb1, zb2))" + and b_def: "b = (zb2 \ memL t zt I)" + using Until(6) + apply (auto simp: v_def(1) Let_def loop_init_def[symmetric] split: option.splits nat.splits if_splits) + done + define j' where "j' = i + c'" + have j_eq: "j = i + c" + using v_def(4) + by (auto simp: v_def(10)) + have t_def: "t = \ \ i" + using ru_t_tau[OF v_def(5) run_back] + by (auto simp: v_def(6)) + define loop_inv where "loop_inv = (\(vphi, vpsi, epsi, c, zo). + let j = i + c in + wf_vydra phi j n vphi \ wf_vydra psi j n vpsi \ + (\gs. reaches_on ru_t l_t0 gs epsi \ length gs = j \ (\t. t \ set gs \ memR (\ \ i) t I)) \ + zo = (case j of 0 \ None | Suc k \ Some (\ \ k, sat phi k, sat psi k)) \ + (\k. k \ {i.. sat phi k \ (memL (\ \ i) (\ \ k) I \ \sat psi k)))" + have loop_inv_init: "loop_inv loop_init" + using v_def(2,3,7,9,12) + by (auto simp: loop_inv_def loop_init_def j_eq[symmetric] v_def(8,11)) + have loop_step: "loop_inv s'" if loop_assms: "loop_inv s" "while_until_cond I t s" "while_until_body run_hd (ru n) s = Some s'" for s s' + proof - + obtain vphi_cur vpsi_cur epsi_cur c_cur zo_cur where s_def: "s = (vphi_cur, vpsi_cur, epsi_cur, c_cur, zo_cur)" + by (cases s) auto + define j_cur where "j_cur = i + c_cur" + obtain epsi'_cur t'_cur vphi'_cur tphi_cur bphi_cur vpsi'_cur tpsi_cur bpsi_cur where + run_epsi: "ru_t epsi_cur = Some (epsi'_cur, t'_cur)" + and run_vphi: "ru n vphi_cur = Some (vphi'_cur, (tphi_cur, bphi_cur))" + and run_vpsi: "ru n vpsi_cur = Some (vpsi'_cur, (tpsi_cur, bpsi_cur))" + using loop_assms(2,3) + apply (auto simp: while_until_cond_def while_until_body_def s_def split: option.splits dest: read_t_run[where ?run_hd=run_hd]) + done + have wf: "wf_vydra phi j_cur n vphi_cur" "wf_vydra psi j_cur n vpsi_cur" + and zo_cur_def: "zo_cur = (case j_cur of 0 \ None | Suc k \ Some (\ \ k, sat phi k, sat psi k))" + using loop_assms(1) + by (auto simp: loop_inv_def s_def j_cur_def[symmetric]) + have wf': "wf_vydra phi (Suc j_cur) n vphi'_cur" "tphi_cur = \ \ j_cur" "bphi_cur = sat phi j_cur" + "wf_vydra psi (Suc j_cur) n vpsi'_cur" "tpsi_cur = \ \ j_cur" "bpsi_cur = sat psi j_cur" + using Until(3)[OF wf(1) run_vphi] Until(4)[OF wf(2) run_vpsi] Until(7,8) + apply (auto) + done + have s'_def: "s' = (vphi'_cur, vpsi'_cur, epsi'_cur, Suc c_cur, Some (t'_cur, (bphi_cur, bpsi_cur)))" + using loop_assms(3) + by (auto simp: while_until_body_def s_def run_epsi run_vphi run_vpsi) + obtain gs_cur where gs_cur_def: "reaches_on ru_t l_t0 gs_cur epsi_cur" + "length gs_cur = j_cur" "\t. t \ set gs_cur \ memR (\ \ i) t I" + using loop_assms(1) + by (auto simp: loop_inv_def s_def j_cur_def[symmetric]) + have t'_cur_def: "t'_cur = \ \ j_cur" + using ru_t_tau[OF gs_cur_def(1) run_epsi] + by (auto simp: gs_cur_def(2)) + have t'_cur_right_I: "memR t t'_cur I" + using loop_assms(2) run_t_read[OF run_epsi] + by (auto simp: while_until_cond_def s_def) + have c_cur_zero: "c_cur = 0 \ j_cur = i" + by (auto simp: j_cur_def) + have "k \ {i.. sat phi k \ (memL (\ \ i) (\ \ k) I \ \sat psi k)" for k + using loop_assms(1,2) + by (cases "k = j_cur - Suc 0") (auto simp: while_until_cond_def loop_inv_def j_cur_def[symmetric] zo_cur_def s_def until_ready_def t_def split: nat.splits dest: c_cur_zero) + then show ?thesis + using wf' t'_cur_right_I + using reaches_on_app[OF gs_cur_def(1) run_epsi] gs_cur_def(2,3) + by (auto simp: loop_inv_def s'_def j_cur_def[symmetric] t_def t'_cur_def intro!: exI[of _ "gs_cur @ [t'_cur]"]) + qed + have wf_loop: "wf {(s', s). loop_inv s \ while_until_cond I t s \ Some s' = while_until_body run_hd (ru n) s}" + proof - + obtain m where m_def: "\\ \ m \ \ \ i + right I" + using ex_lt_\[where ?x="right I" and ?s=\] Until(7) + by auto + define X where "X = {(s', s). loop_inv s \ while_until_cond I t s \ Some s' = while_until_body run_hd (ru n) s}" + have "memR t (\ \ (i + c)) I \ i + c < m" for c + using m_def order_trans[OF \_mono[where ?i=m and ?j="i + c" and ?s=\]] + by (fastforce simp: t_def dest!: memR_dest) + then have "X \ measure (\(vphi, vpsi, epsi, c, zo). m - c)" + by (fastforce simp: X_def while_until_cond_def while_until_body_def loop_inv_def Let_def split: option.splits + dest!: read_t_run[where ?run_hd=run_hd] dest: ru_t_tau) + then show ?thesis + using wf_subset + by (auto simp: X_def[symmetric]) + qed + have loop: "loop_inv (vphi', vpsi', epsi', c', zo')" "\while_until_cond I t (vphi', vpsi', epsi', c', zo')" + using while_break_sound[where ?Q="\s. loop_inv s \ \while_until_cond I t s", OF _ _ wf_loop loop_inv_init] loop_step + by (auto simp: loop_def) + have tau_right_I: "k < j' \ memR (\ \ i) (\ \ k) I" for k + using loop(1) ru_t_tau_in + by (auto simp: loop_inv_def j'_def[symmetric] in_set_conv_nth) + have read_t_epsi': "read_t epsi' = Some et \ et = \ \ j'" for et + using loop(1) ru_t_tau + by (fastforce simp: loop_inv_def Let_def j'_def dest!: read_t_run[where ?run_hd=run_hd]) + have end_cond: "until_ready I t c' zo' \ \(memR (\ \ i) (\ \ j') I)" + unfolding t_def[symmetric] + using Until(6) c'_pos loop(2)[unfolded while_until_cond_def] + by (auto simp: until_ready_def v_def(1) run_back loop_init_def[symmetric] loop_def zo'_Some split: if_splits option.splits nat.splits dest: read_t_epsi') + have Suc_i_le_j': "Suc i \ j'" and c'_j': "c' - Suc 0 = j' - Suc i" + using end_cond c'_pos + by (auto simp: until_ready_def j'_def split: nat.splits) + have zo'_def: "zo' = (case j' of 0 \ None | Suc k \ Some (\ \ k, sat phi k, sat psi k))" + and sat_phi: "k \ {i.. sat phi k" + and not_sat_psi: "k \ {i.. memL (\ \ i) (\ \ k) I \ \sat psi k" for k + using loop(1) + by (auto simp: loop_inv_def j'_def[symmetric]) + have b_sat: "b = sat (Until phi I psi) i" + proof (rule iffI) + assume b: "b" + have mem: "mem (\ \ i) (\ \ (j' - Suc 0)) I" + using b zo'_def tau_right_I[where ?k="j' - 1"] + by (auto simp: mem_def b_def t_def zo'_Some split: nat.splits) + have sat_psi: "sat psi (j' - 1)" + using b zo'_def + by (auto simp: b_def zo'_Some split: nat.splits) + show "sat (Until phi I psi) i" + using Suc_i_le_j' mem sat_psi sat_phi + by (auto intro!: exI[of _ "j' - 1"]) + next + assume "sat (Until phi I psi) i" + then obtain k where k_def: "i \ k" "mem (\ \ i) (\ \ k) I" "sat psi k" "\m \ {i.. {i..k}. memL (\ \ i) (\ \ m) I \ sat psi m}" + have fin_X: "finite X" and X_nonempty: "X \ {}" and k_X: "k \ X" + using k_def + by (auto simp: X_def mem_def) + define km where "km = Min X" + note aux = Min_in[OF fin_X X_nonempty, folded km_def] + have km_def: "i \ km" "km \ k" "memL (\ \ i) (\ \ km) I" "sat psi km" "\m \ {i..m \ {i.. \ i) (\ \ m) I \ \sat psi m" + using aux Min_le[OF fin_X, folded km_def] k_def(4) + by (fastforce simp: X_def)+ + have j'_le_km: "j' - 1 \ km" + using not_sat_psi[OF _ km_def(3)] km_def(1,4) + by fastforce + show "b" + proof (cases "j' - 1 < km") + case True + have "until_ready I t c' zo'" + using end_cond True km_def(2) k_def(2) memR_mono'[OF _ \_mono[where ?i=j' and ?j=k and ?s=\]] + by (auto simp: mem_def) + then show ?thesis + using c'_pos zo'_def km_def(5) Suc_i_le_j' True + by (auto simp: until_ready_def zo'_Some b_def split: nat.splits) + next + case False + have km_j': "km = j' - 1" + using j'_le_km False + by auto + show ?thesis + using c'_pos zo'_def km_def(3,4) + by (auto simp: zo'_Some b_def km_j' t_def split: nat.splits) + qed + qed + obtain gs where gs_def: "reaches_on ru_t l_t0 gs epsi'" "length gs = j'" + "\t. t \ set gs \ memR (\ \ i) t I" + using loop(1) + by (auto simp: loop_inv_def j'_def[symmetric]) + note aux = \_mono[where ?s=\ and ?i=i and ?j="Suc i"] + have wf_v': "wf_vydra (Until phi I psi) (Suc i) (Suc n) v'" + unfolding v'_def + apply (rule wf_vydra.intros(10)[where ?j=j' and ?es'=gs]) + using loop(1) reaches_on_app[OF v_def(5) run_back] Suc_i_le_j' c'_j' memL_mono[OF _ aux] memR_mono[OF _ aux] gs_def + by (auto simp: loop_inv_def j'_def[symmetric] v_def(6,8)) + show ?case + using wf_v' ru_t_event[OF v_def(5) refl run_back] + by (auto simp: b_sat v_def(6)) +next + case (MatchP n I r) + have IH: "x \ set (collect_subfmlas r []) \ wf_vydra x j n v \ ru n v = Some (v', t, b) \ wf_vydra x (Suc j) n v' \ t = \ \ j \ b = sat x j" for x j v v' t b + using MatchP(2,1,5,6) le_trans[OF collect_subfmlas_msize] + using bf_collect_subfmlas[where ?r="r" and ?phis="[]"] + by (fastforce simp: collect_subfmlas_atms[where ?phis="[]", simplified, symmetric]) + have "reaches_on (ru n) (su n phi) vs v \ wf_vydra phi (length vs) n v" if phi: "phi \ set (collect_subfmlas r [])" for phi vs v + apply (induction vs arbitrary: v rule: rev_induct) + using MatchP(1) wf_vydra_sub collect_subfmlas_msize[OF phi] + apply (auto elim!: reaches_on.cases)[1] + using IH[OF phi] + apply (fastforce dest!: reaches_on_split_last) + done + then have wf: "reaches_on (run_subs (ru n)) (map (su n) (collect_subfmlas r [])) bs s \ j < length (collect_subfmlas r []) \ + wf_vydra (collect_subfmlas r [] ! j) (length bs) n (s ! j)" for bs s j + using reach_run_subs_run + by (fastforce simp: in_set_conv_nth) + let ?qf = "state_cnt r" + let ?transs = "iarray_of_list (build_nfa_impl r (0, ?qf, []))" + define args where "args = init_args ({0}, NFA.delta' ?transs ?qf, NFA.accept' ?transs ?qf) (ru_t, read_t) (run_subs (ru n))" + interpret MDL_window \ r l_t0 "map (su n) (collect_subfmlas r [])" args + using bs_sat[where ?r=r and ?n=n, OF _ wf _ reach_run_subs_len[where ?n=n]] IH run_t_read[of run_hd] + read_t_run[of _ _ run_hd] ru_t_tau MatchP(5) collect_subfmlas_atms[where ?phis="[]"] + unfolding args_def iarray_of_list_def + by unfold_locales auto + obtain w xs where w_def: "v = VYDRA_MatchP I ?transs ?qf w" + "valid_window_matchP args I l_t0 (map (su n) (collect_subfmlas r [])) xs i w" + using MatchP(3,4) + by (auto simp: args_def elim!: wf_vydra.cases[of _ _ _ v]) + obtain tj' t' sj' bs where somes: "w_run_t args (w_tj w) = Some (tj', t')" + "w_run_sub args (w_sj w) = Some (sj', bs)" + using MatchP(4) + by (auto simp: w_def(1) adv_end_def args_def Let_def split: option.splits prod.splits) + obtain w' where w'_def: "eval_mP I w = Some ((\ \ i, sat (MatchP I r) i), w')" + "t' = \ \ i" "valid_matchP I l_t0 (map (su n) (collect_subfmlas r [])) (xs @ [(t', bs)]) (Suc i) w'" + using valid_eval_matchP[OF w_def(2) somes] MatchP(6) + by auto + have v'_def: "v' = VYDRA_MatchP I ?transs ?qf w'" "(t, b) = (\ \ i, sat (MatchP I r) i)" + using MatchP(4) + by (auto simp: w_def(1) args_def[symmetric] w'_def(1) simp del: eval_matchP.simps init_args.simps) + have len_xs: "length xs = i" + using w'_def(3) + by (auto simp: valid_window_matchP_def) + have "\es e. reaches_on run_hd init_hd es e \ length es = Suc i" + using ru_t_event valid_window_matchP_reach_tj[OF w_def(2)] somes(1) len_xs + by (fastforce simp: args_def) + then show ?case + using MatchP(1) v'_def(2) w'_def(3) + by (auto simp: v'_def(1) args_def[symmetric] simp del: init_args.simps intro!: wf_vydra.intros(11)) +next + case (MatchF n I r) + have IH: "x \ set (collect_subfmlas r []) \ wf_vydra x j n v \ ru n v = Some (v', t, b) \ wf_vydra x (Suc j) n v' \ t = \ \ j \ b = sat x j" for x j v v' t b + using MatchF(2,1,5,6) le_trans[OF collect_subfmlas_msize] + using bf_collect_subfmlas[where ?r="r" and ?phis="[]"] + by (fastforce simp: collect_subfmlas_atms[where ?phis="[]", simplified, symmetric]) + have "reaches_on (ru n) (su n phi) vs v \ wf_vydra phi (length vs) n v" if phi: "phi \ set (collect_subfmlas r [])" for phi vs v + apply (induction vs arbitrary: v rule: rev_induct) + using MatchF(1) wf_vydra_sub collect_subfmlas_msize[OF phi] + apply (auto elim!: reaches_on.cases)[1] + using IH[OF phi] + apply (fastforce dest!: reaches_on_split_last) + done + then have wf: "reaches_on (run_subs (ru n)) (map (su n) (collect_subfmlas r [])) bs s \ j < length (collect_subfmlas r []) \ + wf_vydra (collect_subfmlas r [] ! j) (length bs) n (s ! j)" for bs s j + using reach_run_subs_run + by (fastforce simp: in_set_conv_nth) + let ?qf = "state_cnt r" + let ?transs = "iarray_of_list (build_nfa_impl r (0, ?qf, []))" + define args where "args = init_args ({0}, NFA.delta' ?transs ?qf, NFA.accept' ?transs ?qf) (ru_t, read_t) (run_subs (ru n))" + interpret MDL_window \ r l_t0 "map (su n) (collect_subfmlas r [])" args + using bs_sat[where ?r=r and ?n=n, OF _ wf _ reach_run_subs_len[where ?n=n]] IH run_t_read[of run_hd] + read_t_run[of _ _ run_hd] ru_t_tau MatchF(5) collect_subfmlas_atms[where ?phis="[]"] + unfolding args_def iarray_of_list_def + by unfold_locales auto + obtain w xs where w_def: "v = VYDRA_MatchF I ?transs ?qf w" + "valid_window_matchF args I l_t0 (map (su n) (collect_subfmlas r [])) xs i w" + using MatchF(3,4) + by (auto simp: args_def elim!: wf_vydra.cases[of _ _ _ v]) + obtain w' rho' where w'_def: "eval_mF I w = Some ((t, b), w')" "valid_matchF I l_t0 (map (su n) (collect_subfmlas r [])) rho' (Suc i) w'" "t = \ \ i" "b = sat (MatchF I r) i" + using valid_eval_matchF_sound[OF w_def(2)] MatchF(4,5,6) + by (fastforce simp: w_def(1) args_def[symmetric] simp del: eval_matchF.simps init_args.simps split: option.splits) + have v'_def: "v' = VYDRA_MatchF I ?transs ?qf w'" + using MatchF(4) + by (auto simp: w_def(1) args_def[symmetric] w'_def(1) simp del: eval_matchF.simps init_args.simps) + obtain w_ti' ti where ru_w_ti: "ru_t (w_ti w) = Some (w_ti', ti)" + using MatchF(4) read_t_run + by (auto simp: w_def(1) args_def split: option.splits) + have "\es e. reaches_on run_hd init_hd es e \ length es = Suc i" + using w_def(2) ru_t_event[OF _ refl ru_w_ti, where ?ts="take (w_i w) (map fst xs)"] + by (auto simp: valid_window_matchF_def args_def) + then show ?case + using MatchF(1) w'_def(2) + by (auto simp: v'_def(1) args_def[symmetric] w'_def(3,4) simp del: init_args.simps intro!: wf_vydra.intros(12)) +qed + +lemma reaches_ons_run_lD: "reaches_on (run_subs (ru n)) vs ws vs' \ + length vs = length vs'" + by (induction vs ws vs' rule: reaches_on_rev_induct) + (auto simp: run_subs_def Let_def split: option.splits if_splits) + +lemma reaches_ons_run_vD: "reaches_on (run_subs (ru n)) vs ws vs' \ + i < length vs \ (\ys. reaches_on (ru n) (vs ! i) ys (vs' ! i) \ length ys = length ws)" +proof (induction vs ws vs' rule: reaches_on_rev_induct) + case (2 s s' bs bss s'') + obtain ys where ys_def: "reaches_on (ru n) (s ! i) ys (s' ! i)" + "length s = length s'" "length ys = length bss" + using reaches_ons_run_lD[OF 2(1)] 2(3)[OF 2(4)] + by auto + obtain tb where tb_def: "ru n (s' ! i) = Some (s'' ! i, tb)" + using run_subs_vD[OF 2(2) 2(4)[unfolded ys_def(2)]] + by auto + show ?case + using reaches_on_app[OF ys_def(1) tb_def(1)] ys_def(2,3) tb_def + by auto +qed (auto intro: reaches_on.intros) + +lemma reaches_ons_runI: + assumes "\phi. phi \ set (collect_subfmlas r []) \ \ws v. reaches_on (ru n) (su n phi) ws v \ length ws = i" + shows "\ws v. reaches_on (run_subs (ru n)) (map (su n) (collect_subfmlas r [])) ws v \ length ws = i" + using assms +proof (induction i) + case 0 + show ?case + by (fastforce intro: reaches_on.intros) +next + case (Suc i) + have IH': "\phi. phi \ set (collect_subfmlas r []) \ \ws v. reaches_on (ru n) (su n phi) ws v \ length ws = i \ ru n v \ None" + proof - + fix phi + assume lassm: "phi \ set (collect_subfmlas r [])" + obtain ws v where ws_def: "reaches_on (ru n) (su n phi) ws v" + "length ws = Suc i" + using Suc(2)[OF lassm] + by auto + obtain y ys where ws_snoc: "ws = ys @ [y]" + using ws_def(2) + by (cases ws rule: rev_cases) auto + show "\ws v. reaches_on (ru n) (su n phi) ws v \ length ws = i \ ru n v \ None" + using reaches_on_split_last[OF ws_def(1)[unfolded ws_snoc]] ws_def(2) ws_snoc + by fastforce + qed + obtain ws v where ws_def: "reaches_on (run_subs (ru n)) (map (su n) (collect_subfmlas r [])) ws v" "length ws = i" + using Suc(1) IH' + by blast + have "x \ set v \ Option.is_none (ru n x) \ False" for x + using ws_def IH' + by (auto simp: in_set_conv_nth) (metis is_none_code(2) reach_run_subs_len reach_run_subs_run reaches_on_inj) + then obtain v' tb where v'_def: "run_subs (ru n) v = Some (v', tb)" + by (fastforce simp: run_subs_def Let_def) + show ?case + using reaches_on_app[OF ws_def(1) v'_def] ws_def(2) + by fastforce +qed + +lemma reaches_on_takeWhile: "reaches_on r s vs s' \ r s' = Some (s'', v) \ \f v \ + vs' = takeWhile f vs \ + \t' t'' v'. reaches_on r s vs' t' \ r t' = Some (t'', v') \ \f v' \ + reaches_on r t' (drop (length vs') vs) s'" + by (induction s vs s' arbitrary: vs' rule: reaches_on.induct) (auto intro: reaches_on.intros) + +lemma reaches_on_suffix: + assumes "reaches_on r s vs s'" "reaches_on r s vs' s''" "length vs' \ length vs" + shows "\vs''. reaches_on r s'' vs'' s' \ vs = vs' @ vs''" + using reaches_on_split'[where ?i="length vs'", OF assms(1,3)] assms(3) reaches_on_inj[OF assms(2)] + by (metis add_diff_cancel_right' append_take_drop_id diff_diff_cancel length_append length_drop) + +lemma vydra_wf_reaches_on: + assumes "\j v. j < i \ wf_vydra \ j n v \ ru n v = None \ False" "bounded_future_fmla \" "wf_fmla \" "msize_fmla \ \ n" + shows "\vs v. reaches_on (ru n) (su n \) vs v \ wf_vydra \ i n v \ length vs = i" + using assms(1) +proof (induction i) + case (Suc i) + obtain vs v where IH: "reaches_on (ru n) (su n \) vs v" "wf_vydra \ i n v" "length vs = i" + using Suc(1) Suc(2)[OF less_SucI] + by auto + show ?case + using reaches_on_app[OF IH(1)] Suc(2)[OF _ IH(2)] vydra_sound_aux[OF assms(4) IH(2) _ assms(2,3)] IH(3) + by fastforce +qed (auto intro: reaches_on.intros wf_vydra_sub[OF assms(4)]) + +lemma reaches_on_Some: + assumes "reaches_on r s vs s'" "reaches_on r s vs' s''" "length vs < length vs'" + shows "\s''' x. r s' = Some (s''', x)" + using reaches_on_split[OF assms(2,3)] reaches_on_inj[OF assms(1)] assms(3) + by auto + +lemma reaches_on_progress: + assumes "reaches_on run_hd init_hd vs e" + shows "progress phi (map fst vs) \ length vs" + using progress_le_ts[of "map fst vs" phi] reaches_on_run_hd \_fin + by (fastforce dest!: reaches_on_setD[OF assms] reaches_on_split_last) + +lemma vydra_complete_aux: + assumes prefix: "reaches_on run_hd init_hd vs e" + and run: "wf_vydra \ i n v" "ru n v = None" "i < progress \ (map fst vs)" "bounded_future_fmla \" "wf_fmla \" + and msize: "msize_fmla \ \ n" + shows "False" + using msize run +proof (induction n \ arbitrary: i v rule: run_induct) + case (Bool b n) + have False if v_def: "v = VYDRA_Bool b g" for g + proof - + obtain es where g_def: "reaches_on run_hd init_hd es g" "length es = i" + using Bool(1) + by (auto simp: v_def elim: wf_vydra.cases) + show False + using Bool(2) reaches_on_Some[OF g_def(1) prefix] Bool(3) + by (auto simp: v_def g_def(2) split: option.splits) + qed + then show False + using Bool(1) + by (auto elim!: wf_vydra.cases[of _ _ _ v]) +next + case (Atom a n) + have False if v_def: "v = VYDRA_Atom a g" for g + proof - + obtain es where g_def: "reaches_on run_hd init_hd es g" "length es = i" + using Atom(1) + by (auto simp: v_def elim: wf_vydra.cases) + show False + using Atom(2) reaches_on_Some[OF g_def(1) prefix] Atom(3) + by (auto simp: v_def g_def(2) split: option.splits) + qed + then show False + using Atom(1) + by (auto elim!: wf_vydra.cases[of _ _ _ v]) +next + case (Neg n phi) + show ?case + apply (rule wf_vydra.cases[OF Neg(3)]) + using Neg + by (fastforce split: option.splits)+ +next + case (Bin n f phi psi) + show ?case + apply (rule wf_vydra.cases[OF Bin(4)]) + using Bin + by (fastforce split: option.splits)+ +next + case (Prev n I phi) + show ?case + proof (cases i) + case 0 + obtain vphi where v_def: "v = VYDRA_Prev I vphi init_hd None" + using Prev(3) + by (auto simp: 0 dest: reaches_on_NilD elim!: wf_vydra.cases[of "Prev I phi"]) + show ?thesis + using Prev(4,5) prefix + by (auto simp: 0 v_def elim: reaches_on.cases split: option.splits) + next + case (Suc j) + show ?thesis + proof (cases "v = VYDRA_None") + case v_def: True + obtain w where w_def: "wf_vydra phi j n w" "ru n w = None" + using Prev(3) + by (auto simp: Suc v_def elim!: wf_vydra.cases[of "Prev I phi"]) + show ?thesis + using Prev(2)[OF w_def(1,2)] Prev(5,6,7) + by (auto simp: Suc) + next + case False + obtain vphi tphi bphi es g where v_def: "v = VYDRA_Prev I vphi g (Some (tphi, bphi))" + "wf_vydra phi (Suc j) n vphi" "reaches_on run_hd init_hd es g" "length es = Suc j" + using Prev(3) False + by (auto simp: Suc elim!: wf_vydra.cases[of "Prev I phi"]) + show ?thesis + using Prev(4,5) reaches_on_Some[OF v_def(3) prefix] + by (auto simp: Let_def Suc v_def(1,4) split: option.splits) + qed + qed +next + case (Next n I phi) + show ?case + proof (cases "v = VYDRA_None") + case True + obtain w where w_def: "wf_vydra phi i n w" "ru n w = None" + using Next(3) + by (auto simp: True elim: wf_vydra.cases) + show ?thesis + using Next(2)[OF w_def] Next(5,6,7) + by (auto split: nat.splits) + next + case False + obtain w sub to es where v_def: "v = VYDRA_Next I w sub to" "wf_vydra phi (length es) n w" + "reaches_on run_hd init_hd es sub" "length es = (case to of None \ 0 | _ \ Suc i)" + "case to of None \ i = 0 | Some told \ told = \ \ i" + using Next(3) False + by (auto elim!: wf_vydra.cases[of _ _ _ v] split: option.splits nat.splits) + show ?thesis + proof (cases to) + case None + obtain w' tw' bw' where w'_def: "ru n w = Some (w', (tw', bw'))" + using Next(2)[OF v_def(2)] Next(5,6,7) + by (fastforce simp: v_def(4) None split: nat.splits) + have wf: "wf_vydra phi (Suc (length es)) n w'" + using v_def(4,5) vydra_sound_aux[OF Next(1) v_def(2) w'_def] Next(6,7) + by (auto simp: None) + show ?thesis + using Next(2)[OF wf] Next(4,5,6,7) reaches_on_Some[OF v_def(3) prefix] + reaches_on_Some[OF reaches_on_app[OF v_def(3)] prefix] reaches_on_progress[OF prefix, where ?phi=phi] + by (cases vs) (fastforce simp: v_def(1,4) w'_def None split: option.splits nat.splits if_splits)+ + next + case (Some z) + show ?thesis + using Next(2)[OF v_def(2)] Next(4,5,6,7) reaches_on_Some[OF v_def(3) prefix] reaches_on_progress[OF prefix, where ?phi=phi] + by (auto simp: v_def(1,4) Some split: option.splits nat.splits) + qed + qed +next + case (Since n I phi psi) + obtain vphi vpsi g cphi cpsi cppsi tppsi j gs where v_def: + "v = VYDRA_Since I vphi vpsi g cphi cpsi cppsi tppsi" + "wf_vydra phi i n vphi" "wf_vydra psi j n vpsi" "j \ i" + "reaches_on ru_t l_t0 gs g" "length gs = j" "cpsi = i - j" + using Since(5) + by (auto elim: wf_vydra.cases) + obtain vphi' t1 b1 where run_vphi: "ru n vphi = Some (vphi', t1, b1)" + using Since(3)[OF v_def(2)] Since(7,8,9) + by fastforce + obtain cs c where wf_vphi': "wf_vydra phi (Suc i) n vphi'" + and reaches_Suc_i: "reaches_on run_hd init_hd cs c" "length cs = Suc i" + and t1_def: "t1 = \ \ i" + using vydra_sound_aux[OF Since(1) v_def(2) run_vphi] Since(8,9) + by auto + note ru_t_Some = ru_t_Some[OF reaches_Suc_i] + define loop_inv where "loop_inv = (\(vpsi, e, cpsi :: nat, cppsi :: nat option, tppsi :: 't option). + let j = Suc i - cpsi in cpsi \ Suc i \ wf_vydra psi j n vpsi \ (\es. reaches_on ru_t l_t0 es e \ length es = j))" + define loop_init where "loop_init = (vpsi, g, Suc cpsi, map_option Suc cppsi, tppsi)" + have j_def: "j = i - cpsi" and cpsi_i: "cpsi \ i" + using v_def(4,7) + by auto + then have loop_inv_init: "loop_inv loop_init" + using v_def(3,5,6,7) last_before_Some + by (fastforce simp: loop_inv_def loop_init_def Let_def j_def split: option.splits) + have wf_loop: "wf {(s', s). loop_inv s \ while_since_cond I t1 s \ Some s' = while_since_body run_hd (ru n) s}" + by (auto intro: wf_subset[OF wf_since]) + have step_loop: "pred_option' loop_inv (while_since_body run_hd (ru n) s)" + if loop_assms: "loop_inv s" "while_since_cond I t1 s" for s + proof - + obtain vpsi d cpsi cppsi tppsi where s_def: "s = (vpsi, d, cpsi, cppsi, tppsi)" + by (cases s) auto + have cpsi_pos: "cpsi > 0" + using loop_assms(2) + by (auto simp: while_since_cond_def s_def) + define j where "j = Suc i - cpsi" + have j_i: "j \ i" + using cpsi_pos + by (auto simp: j_def) + obtain ds where loop_before: "cpsi \ Suc i" "wf_vydra psi j n vpsi" "reaches_on ru_t l_t0 ds d" "length ds = j" + using loop_assms(1) + by (auto simp: s_def j_def loop_inv_def Let_def) + obtain h tt where tt_def: "read_t d = Some tt" "d = Some (h, tt)" + using ru_t_Some[OF loop_before(3)] loop_before(4) loop_assms(2) + by (cases d) (fastforce simp: while_since_cond_def s_def j_def split: option.splits)+ + obtain d' where d'_def: "reaches_on ru_t l_t0 (ds @ [tt]) d'" "ru_t d = Some (d', tt)" + using reaches_on_app[OF loop_before(3)] tt_def(1) + by (cases "run_hd h") (auto simp: tt_def(2)) + obtain vpsi' tpsi' bpsi' where run_vpsi: "ru n vpsi = Some (vpsi', (tpsi', bpsi'))" + using Since(4) j_i Since(7,8,9) loop_before(2) + by fastforce + have wf_psi': "wf_vydra psi (Suc j) n vpsi'" and t'_def: "tpsi' = \ \ j" and b'_def: "bpsi' = sat psi j" + using vydra_sound_aux[OF Since(2) loop_before(2) run_vpsi] Since(8,9) + by auto + define j' where j'_def: "j' = Suc i - (cpsi - Suc 0)" + have j'_j: "j' = Suc j" + using loop_before(1) cpsi_pos + by (auto simp: j'_def j_def) + show ?thesis + using wf_psi'(1) loop_before(1,4) d'_def(1) + by (fastforce simp: while_since_body_def s_def run_vpsi pred_option'_def loop_inv_def j'_def[symmetric] j'_j d'_def(2) t1_def) + qed + show ?case + using while_break_complete[OF step_loop _ wf_loop loop_inv_init, where ?Q="\_. True"] Since(6) + by (auto simp: pred_option'_def v_def(1) run_vphi Let_def loop_init_def split: option.splits) +next + case (Until n I phi psi) + obtain "back" vphi vpsi front c z es es' j where v_def: + "v = VYDRA_Until I back vphi vpsi front c z" + "wf_vydra phi j n vphi" "wf_vydra psi j n vpsi" "i \ j" + "reaches_on ru_t l_t0 es back" "length es = i" + "reaches_on ru_t l_t0 es' front" "length es' = j" "\t. t \ set es' \ memR (\ \ i) t I" + "c = j - i" "z = (case j of 0 \ None | Suc k \ Some (\ \ k, sat phi k, sat psi k))" + "\k. k \ {i.. sat phi k \ (memL (\ \ i) (\ \ k) I \ \sat psi k)" + using Until(5) + by (auto simp: elim: wf_vydra.cases) + have ru_t_Some: "reaches_on ru_t l_t0 gs g \ length gs < length vs \ \g' gt. ru_t g = Some (g', gt)" for gs g + using reaches_on_Some reaches_on_run_hd_t[OF prefix] + by fastforce + have vs_tau: "map fst vs ! k = \ \ k" if k_vs: "k < length vs" for k + using reaches_on_split[OF prefix k_vs] run_hd_sound k_vs + apply (cases "vs ! k") + apply (auto) + apply (metis fst_conv length_map nth_map prefix reaches_on_run_hd_t ru_t_tau_in) + done + define m where "m = min (length (map fst vs) - 1) (min (progress phi (map fst vs)) (progress psi (map fst vs)))" + have m_vs: "m < length vs" + using Until(7) + by (cases vs) (auto simp: m_def split: if_splits) + define A where "A = {j. 0 \ j \ j \ m \ memR (map fst vs ! j) (map fst vs ! m) I}" + have m_A: "m \ A" + using memR_tfin_refl[OF \_fin] vs_tau[OF m_vs] + by (fastforce simp: A_def) + then have A_nonempty: "A \ {}" + by auto + have A_finite: "finite A" + by (auto simp: A_def) + have p: "progress (Until phi I psi) (map fst vs) = Min A" + using Until(7) + unfolding progress.simps m_def[symmetric] Let_def A_def[symmetric] + by auto + have i_A: "i \ A" + using Until(7) A_finite A_nonempty + by (auto simp del: progress.simps simp: p) + have i_m: "i < m" + using Until(7) m_A A_finite A_nonempty + by (auto simp del: progress.simps simp: p) + have memR_i_m: "\memR (map fst vs ! i) (map fst vs ! m) I" + using i_A i_m + by (auto simp: A_def) + have i_vs: "i < length vs" + using i_m m_vs + by auto + have j_m: "j \ m" + using ru_t_tau_in[OF v_def(7), of m] v_def(9)[of "\ \ m"] memR_i_m + unfolding vs_tau[OF i_vs] vs_tau[OF m_vs] + by (force simp: in_set_conv_nth v_def(8)) + have j_vs: "j < length vs" + using j_m m_vs + by auto + obtain back' t where run_back: "ru_t back = Some (back', t)" and t_def: "t = \ \ i" + using ru_t_Some[OF v_def(5)] v_def(4) j_vs ru_t_tau[OF v_def(5)] + by (fastforce simp: v_def(6)) + define loop_inv where "loop_inv = (\(vphi, vpsi, front, c, z :: ('t \ bool \ bool) option). + let j = i + c in wf_vydra phi j n vphi \ wf_vydra psi j n vpsi \ j < length vs \ + (\es'. reaches_on ru_t l_t0 es' front \ length es' = j) \ + (z = None \ j = 0))" + define loop_init where "loop_init = (vphi, vpsi, front, c, z)" + have j_eq: "j = i + c" + using v_def(4) + by (auto simp: v_def(10)) + have "j = 0 \ c = 0" + by (auto simp: j_eq) + then have loop_inv_init: "loop_inv loop_init" + using v_def(2,3,4,7,8,9,11) j_vs + by (auto simp: loop_inv_def loop_init_def j_eq[symmetric] split: nat.splits) + have loop_step: "pred_option' loop_inv (while_until_body run_hd (ru n) s)" if loop_assms: "loop_inv s" "while_until_cond I t s" for s + proof - + obtain vphi_cur vpsi_cur epsi_cur c_cur zo_cur where s_def: "s = (vphi_cur, vpsi_cur, epsi_cur, c_cur, zo_cur)" + by (cases s) auto + define j_cur where "j_cur = i + c_cur" + obtain gs where wf: "wf_vydra phi j_cur n vphi_cur" "wf_vydra psi j_cur n vpsi_cur" + and gs_def: "reaches_on ru_t l_t0 gs epsi_cur" "length gs = j_cur" + and j_cur_vs: "j_cur < length vs" + using loop_assms(1) + by (auto simp: loop_inv_def s_def j_cur_def[symmetric]) + obtain epsi'_cur t'_cur where run_epsi: "ru_t epsi_cur = Some (epsi'_cur, t'_cur)" + and t'_cur_def: "t'_cur = \ \ (length gs)" + using ru_t_Some[OF gs_def(1)] ru_t_event[OF gs_def(1) refl] j_cur_vs + by (auto simp: gs_def(2)) + have j_m: "j_cur < m" + using loop_assms(2) memR_i_m memR_mono'[OF _ \_mono, of _ _ _ _ m] + unfolding vs_tau[OF i_vs] vs_tau[OF m_vs] + by (fastforce simp: gs_def(2) while_until_cond_def s_def run_t_read[OF run_epsi] t_def t'_cur_def) + have j_cur_prog_phi: "j_cur < progress phi (map fst vs)" + using j_m + by (auto simp: m_def) + have j_cur_prog_psi: "j_cur < progress psi (map fst vs)" + using j_m + by (auto simp: m_def) + obtain vphi'_cur tphi_cur bphi_cur where run_vphi: "ru n vphi_cur = Some (vphi'_cur, (tphi_cur, bphi_cur))" + using Until(3)[OF wf(1) _ j_cur_prog_phi] Until(8,9) + by fastforce + obtain vpsi'_cur tpsi_cur bpsi_cur where run_vpsi: "ru n vpsi_cur = Some (vpsi'_cur, (tpsi_cur, bpsi_cur))" + using Until(4)[OF wf(2) _ j_cur_prog_psi] Until(8,9) + by fastforce + have wf': "wf_vydra phi (Suc j_cur) n vphi'_cur" "wf_vydra psi (Suc j_cur) n vpsi'_cur" + using vydra_sound_aux[OF Until(1) wf(1) run_vphi] vydra_sound_aux[OF Until(2) wf(2) run_vpsi] Until(8,9) + by auto + show ?thesis + using wf' reaches_on_app[OF gs_def(1) run_epsi] gs_def(2) j_m m_vs + by (auto simp: pred_option'_def while_until_body_def s_def run_epsi run_vphi run_vpsi loop_inv_def j_cur_def[symmetric]) + qed + have wf_loop: "wf {(s', s). loop_inv s \ while_until_cond I t s \ Some s' = while_until_body run_hd (ru n) s}" + proof - + obtain m where m_def: "\\ \ m \ \ \ i + right I" + using ex_lt_\[where ?x="right I" and ?s=\] Until(8) + by auto + define X where "X = {(s', s). loop_inv s \ while_until_cond I t s \ Some s' = while_until_body run_hd (ru n) s}" + have "memR t (\ \ (i + c)) I \ i + c < m" for c + using m_def order_trans[OF \_mono[where ?i=m and ?j="i + c" and ?s=\]] + by (fastforce simp: t_def dest!: memR_dest) + then have "X \ measure (\(vphi, vpsi, epsi, c, zo). m - c)" + by (fastforce simp: X_def while_until_cond_def while_until_body_def loop_inv_def Let_def split: option.splits + dest!: read_t_run[where ?run_hd=run_hd] dest: ru_t_tau) + then show ?thesis + using wf_subset + by (auto simp: X_def[symmetric]) + qed + obtain vphi' vpsi' front' c' z' where loop: + "while_break (while_until_cond I t) (while_until_body run_hd (ru n)) loop_init = Some (vphi', vpsi', front', c', z')" + "loop_inv (vphi', vpsi', front', c', z')" "\while_until_cond I t (vphi', vpsi', front', c', z')" + using while_break_complete[where ?P="loop_inv", OF loop_step _ wf_loop loop_inv_init] + by (cases "while_break (while_until_cond I t) (while_until_body run_hd (ru n)) loop_init") (force simp: pred_option'_def)+ + define j' where "j' = i + c'" + obtain tf where read_front': "read_t front' = Some tf" + using loop(2) + by (auto simp: loop_inv_def j'_def[symmetric] dest!: ru_t_Some run_t_read[where ?run_hd=run_hd]) + have tf_fin: "tf \ tfin" + using loop(2) ru_t_Some[where ?g=front'] ru_t_tau[where ?t'=front'] read_t_run[OF read_front'] \_fin[where ?\=\] + by (fastforce simp: loop_inv_def j'_def[symmetric]) + have c'_pos: "c' = 0 \ False" + using loop(2,3) ru_t_tau ru_t_tau[OF reaches_on.intros(1)] read_t_run[OF read_front'] + memR_tfin_refl[OF tf_fin] + by (fastforce simp: loop_inv_def while_until_cond_def until_ready_def read_front' t_def dest!: reaches_on_NilD) + have z'_Some: "z' = None \ False" + using loop(2) c'_pos + by (auto simp: loop_inv_def j'_def[symmetric]) + show ?case + using Until(6) c'_pos z'_Some + by (auto simp: v_def(1) run_back loop_init_def[symmetric] loop(1) read_front' split: if_splits option.splits) +next + case (MatchP n I r) + have msize_sub: "\x. x \ set (collect_subfmlas r []) \ msize_fmla x \ n" + using le_trans[OF collect_subfmlas_msize] MatchP(1) + by auto + have sound: "x \ set (collect_subfmlas r []) \ wf_vydra x j n v \ ru n v = Some (v', t, b) \ wf_vydra x (Suc j) n v' \ t = \ \ j \ b = sat x j" for x j v v' t b + using MatchP vydra_sound_aux[OF msize_sub] le_trans[OF collect_subfmlas_msize] + using bf_collect_subfmlas[where ?r="r" and ?phis="[]"] + by (fastforce simp: collect_subfmlas_atms[where ?phis="[]", simplified, symmetric]) + have "reaches_on (ru n) (su n phi) vs v \ wf_vydra phi (length vs) n v" if phi: "phi \ set (collect_subfmlas r [])" for phi vs v + apply (induction vs arbitrary: v rule: rev_induct) + using MatchP(1) wf_vydra_sub collect_subfmlas_msize[OF phi] + apply (auto elim!: reaches_on.cases)[1] + using sound[OF phi] + apply (fastforce dest!: reaches_on_split_last) + done + then have wf: "reaches_on (run_subs (ru n)) (map (su n) (collect_subfmlas r [])) bs s \ j < length (collect_subfmlas r []) \ + wf_vydra (collect_subfmlas r [] ! j) (length bs) n (s ! j)" for bs s j + using reach_run_subs_run + by (fastforce simp: in_set_conv_nth) + let ?qf = "state_cnt r" + let ?transs = "iarray_of_list (build_nfa_impl r (0, ?qf, []))" + define args where "args = init_args ({0}, NFA.delta' ?transs ?qf, NFA.accept' ?transs ?qf) (ru_t, read_t) (run_subs (ru n))" + interpret MDL_window \ r l_t0 "map (su n) (collect_subfmlas r [])" args + using bs_sat[where ?r=r and ?n=n, OF _ wf _ reach_run_subs_len[where ?n=n]] sound run_t_read[of run_hd] + read_t_run[of _ _ run_hd] ru_t_tau MatchP(5) collect_subfmlas_atms[where ?phis="[]"] + unfolding args_def iarray_of_list_def + by unfold_locales auto + obtain w xs where w_def: "v = VYDRA_MatchP I ?transs ?qf w" + "valid_window_matchP args I l_t0 (map (su n) (collect_subfmlas r [])) xs i w" + using MatchP(3) + by (auto simp: args_def elim!: wf_vydra.cases) + note args' = args_def[unfolded init_args.simps, symmetric] + have run_args: "w_run_t args = ru_t" "w_run_sub args = run_subs (ru n)" + by (auto simp: args_def) + have len_xs: "length xs = i" + using w_def(2) + by (auto simp: valid_window_matchP_def) + obtain ej tj where w_tj: "ru_t (w_tj w) = Some (ej, tj)" + using reaches_on_Some[OF valid_window_matchP_reach_tj[OF w_def(2)]] reaches_on_run_hd_t[OF prefix] + MatchP(5) reaches_on_progress[OF prefix, where ?phi="MatchP I r"] + by (fastforce simp: run_args len_xs simp del: progress.simps) + have "run_subs (ru n) (w_sj w) = None" + using valid_eval_matchP[OF w_def(2), unfolded run_args] w_tj MatchP(4,7) + by (cases "run_subs (ru n) (w_sj w)") (auto simp: w_def(1) args' simp del: eval_matchP.simps split: option.splits) + then obtain j where j_def: "j < length (w_sj w)" "ru n (w_sj w ! j) = None" + by (auto simp: run_subs_def Let_def in_set_conv_nth Option.is_none_def split: if_splits) + have len_w_sj: "length (w_sj w) = length (collect_subfmlas r [])" + using valid_window_matchP_reach_sj[OF w_def(2)] reach_run_subs_len + by (auto simp: run_args) + define phi where "phi = collect_subfmlas r [] ! j" + have phi_in_set: "phi \ set (collect_subfmlas r [])" + using j_def(1) + by (auto simp: phi_def in_set_conv_nth len_w_sj) + have wf: "wf_vydra phi i n (w_sj w ! j)" + using valid_window_matchP_reach_sj[OF w_def(2)] wf[folded len_w_sj, OF _ j_def(1)] len_xs + by (fastforce simp: run_args phi_def) + have "i < progress phi (map fst vs)" + using MatchP(5) phi_in_set atms_nonempty[of r] atms_finite[of r] collect_subfmlas_atms[of r "[]"] + by auto + then show ?case + using MatchP(2)[OF msize_sub[OF phi_in_set] wf j_def(2)] MatchP(6,7) phi_in_set + bf_collect_subfmlas[where ?r="r" and ?phis="[]"] + by (auto simp: collect_subfmlas_atms) +next + case (MatchF n I r) + have subfmla: "msize_fmla x \ n" "bounded_future_fmla x" "wf_fmla x" if "x \ set (collect_subfmlas r [])" for x + using that MatchF(1,6,7) le_trans[OF collect_subfmlas_msize] bf_collect_subfmlas[where ?r="r" and ?phis="[]" and ?phi=x] + collect_subfmlas_atms[where ?phis="[]" and ?r=r] + by auto + have sound: "x \ set (collect_subfmlas r []) \ wf_vydra x j n v \ ru n v = Some (v', t, b) \ wf_vydra x (Suc j) n v' \ t = \ \ j \ b = sat x j" for x j v v' t b + using MatchF vydra_sound_aux subfmla + by fastforce + have "reaches_on (ru n) (su n phi) vs v \ wf_vydra phi (length vs) n v" if phi: "phi \ set (collect_subfmlas r [])" for phi vs v + apply (induction vs arbitrary: v rule: rev_induct) + using MatchF(1) wf_vydra_sub subfmla(1)[OF phi] sound[OF phi] + apply (auto elim!: reaches_on.cases)[1] + using sound[OF phi] + apply (fastforce dest!: reaches_on_split_last) + done + then have wf: "reaches_on (run_subs (ru n)) (map (su n) (collect_subfmlas r [])) bs s \ j < length (collect_subfmlas r []) \ + wf_vydra (collect_subfmlas r [] ! j) (length bs) n (s ! j)" for bs s j + using reach_run_subs_run + by (fastforce simp: in_set_conv_nth) + let ?qf = "state_cnt r" + let ?transs = "iarray_of_list (build_nfa_impl r (0, ?qf, []))" + define args where "args = init_args ({0}, NFA.delta' ?transs ?qf, NFA.accept' ?transs ?qf) (ru_t, read_t) (run_subs (ru n))" + interpret MDL_window \ r l_t0 "map (su n) (collect_subfmlas r [])" args + using bs_sat[where ?r=r and ?n=n, OF _ wf _ reach_run_subs_len[where ?n=n]] sound run_t_read[of run_hd] + read_t_run[of _ _ run_hd] ru_t_tau MatchF(5) subfmla + unfolding args_def iarray_of_list_def + by unfold_locales auto + obtain w xs where w_def: "v = VYDRA_MatchF I ?transs ?qf w" + "valid_window_matchF args I l_t0 (map (su n) (collect_subfmlas r [])) xs i w" + using MatchF(3) + by (auto simp: args_def elim!: wf_vydra.cases) + note args' = args_def[unfolded init_args.simps, symmetric] + have run_args: "w_run_t args = ru_t" "w_read_t args = read_t" "w_run_sub args = run_subs (ru n)" + by (auto simp: args_def) + have vs_tau: "map fst vs ! k = \ \ k" if k_vs: "k < length vs" for k + using reaches_on_split[OF prefix k_vs] run_hd_sound k_vs + apply (cases "vs ! k") + apply (auto) + apply (metis fst_conv length_map nth_map prefix reaches_on_run_hd_t ru_t_tau_in) + done + define m where "m = min (length (map fst vs) - 1) (Min ((\f. progress f (map fst vs)) ` atms r))" + have m_vs: "m < length vs" + using MatchF(5) + by (cases vs) (auto simp: m_def split: if_splits) + define A where "A = {j. 0 \ j \ j \ m \ memR (map fst vs ! j) (map fst vs ! m) I}" + have m_A: "m \ A" + using memR_tfin_refl[OF \_fin] vs_tau[OF m_vs] + by (fastforce simp: A_def) + then have A_nonempty: "A \ {}" + by auto + have A_finite: "finite A" + by (auto simp: A_def) + have p: "progress (MatchF I r) (map fst vs) = Min A" + using MatchF(5) + unfolding progress.simps m_def[symmetric] Let_def A_def[symmetric] + by auto + have i_A: "i \ A" + using MatchF(5) A_finite A_nonempty + by (auto simp del: progress.simps simp: p) + have i_m: "i < m" + using MatchF(5) m_A A_finite A_nonempty + by (auto simp del: progress.simps simp: p) + have memR_i_m: "\memR (map fst vs ! i) (map fst vs ! m) I" + using i_A i_m + by (auto simp: A_def) + have i_vs: "i < length vs" + using i_m m_vs + by auto + obtain ti where read_ti: "w_read_t args (w_ti w) = Some ti" + using w_def(2) reaches_on_Some[where ?r=ru_t and ?s=l_t0 and ?s'="w_ti w"] + reaches_on_run_hd_t[OF prefix] i_vs run_t_read[where ?t="w_ti w"] + by (fastforce simp: valid_window_matchF_def run_args) + have ti_def: "ti = \ \ i" + using w_def(2) ru_t_tau read_t_run[OF read_ti] + by (fastforce simp: valid_window_matchF_def run_args) + note reach_tj = valid_window_matchF_reach_tj[OF w_def(2), unfolded run_args] + note reach_sj = valid_window_matchF_reach_sj[OF w_def(2), unfolded run_args] + have len_xs: "length xs = w_j w" and memR_xs: "\l. l\{w_i w.. memR (ts_at xs i) (ts_at xs l) I" + and i_def: "w_i w = i" + using w_def(2) + unfolding valid_window_matchF_def + by (auto simp: valid_window_matchF_def run_args) + have j_m: "w_j w \ m" + using ru_t_tau_in[OF reach_tj, of i] ru_t_tau_in[OF reach_tj, of m] memR_i_m i_m memR_xs[of m] + unfolding vs_tau[OF i_vs] vs_tau[OF m_vs] + by (force simp: in_set_conv_nth len_xs ts_at_def i_def) + obtain tm tm' where tm_def: "reaches_on ru_t l_t0 (take m (map fst vs)) tm" + "ru_t tm = Some (tm', fst (vs ! m))" + using reaches_on_split[where ?i=m] reaches_on_run_hd_t[OF prefix] m_vs + by fastforce + have reach_tj_m: "reaches_on (w_run_t args) (w_tj w) (drop (w_j w) (take m (map fst vs))) tm" + using reaches_on_split'[OF tm_def(1), where ?i="w_j w"] reaches_on_inj[OF reach_tj] m_vs j_m + by (auto simp: len_xs run_args) + have vs_m: "fst (vs ! m) = \ \ m" + using vs_tau[OF m_vs] m_vs + by auto + have memR_ti_m: "\memR ti (\ \ m) I" + using memR_i_m + unfolding vs_tau[OF i_vs] vs_tau[OF m_vs] + by (auto simp: ti_def) + have m_prog: "m \ progress phi (map fst vs)" if "phi \ set (collect_subfmlas r [])" for phi + using collect_subfmlas_atms[where ?r=r and ?phis="[]"] that atms_finite[of r] + by (auto simp: m_def min.coboundedI2) + obtain ws s where ws_def: "reaches_on (run_subs (ru n)) (map (su n) (collect_subfmlas r [])) ws s" "length ws = m" + using reaches_ons_runI[where ?r=r and ?n=n and ?i=m] + vydra_wf_reaches_on[where ?i=m and ?n=n] subfmla + MatchF(2) m_prog + by fastforce + have reach_sj_m: "reaches_on (run_subs (ru n)) (w_sj w) (drop (w_j w) ws) s" + using reaches_on_split'[OF ws_def(1), where ?i="w_j w"] reaches_on_inj[OF reach_sj] i_m j_m + by (auto simp: ws_def(2) len_xs) + define rho where "rho = zip (drop (w_j w) (take m (map fst vs))) (drop (w_j w) ws)" + have map_fst_rho: "map fst rho = drop (w_j w) (take m (map fst vs))" + and map_snd_rho: "map snd rho = drop (w_j w) ws" + using ws_def(2) j_m m_vs + by (auto simp: rho_def) + show False + using valid_eval_matchF_complete[OF w_def(2) reach_tj_m[folded map_fst_rho] reach_sj_m[folded map_snd_rho run_args] read_ti run_t_read[OF tm_def(2)[folded run_args], unfolded vs_m] memR_ti_m] MatchF(4,7) + by (auto simp: w_def(1) args_def simp del: eval_matchF.simps) +qed + +definition "ru' \ = ru (msize_fmla \)" +definition "su' \ = su (msize_fmla \) \" + +lemma vydra_wf: + assumes "reaches (ru n) (su n \) i v" "bounded_future_fmla \" "wf_fmla \" "msize_fmla \ \ n" + shows "wf_vydra \ i n v" + using assms(1) +proof (induction i arbitrary: v) + case 0 + then show ?case + using wf_vydra_sub[OF assms(4)] + by (auto elim: reaches.cases) +next + case (Suc i) + show ?case + using reaches_Suc_split_last[OF Suc(2)] Suc(1) vydra_sound_aux[OF assms(4) _ _ assms(2,3)] + by fastforce +qed + +lemma vydra_sound': + assumes "reaches (ru' \) (su' \) n v" "ru' \ v = Some (v', (t, b))" "bounded_future_fmla \" "wf_fmla \" + shows "(t, b) = (\ \ n, sat \ n)" + using vydra_sound_aux[OF order.refl vydra_wf[OF assms(1)[unfolded ru'_def su'_def] assms(3,4) order.refl] assms(2)[unfolded ru'_def] assms(3,4)] + by auto + +lemma vydra_complete': + assumes prefix: "reaches_on run_hd init_hd vs e" + and prog: "n < progress \ (map fst vs)" "bounded_future_fmla \" "wf_fmla \" + shows "\v v'. reaches (ru' \) (su' \) n v \ ru' \ v = Some (v', (\ \ n, sat \ n))" +proof - + have aux: "False" if aux_assms: "j \ n" "wf_vydra \ j (msize_fmla \) v" "ru (msize_fmla \) v = None" for j v + using vydra_complete_aux[OF prefix aux_assms(2,3) _ prog(2-)] aux_assms(1) prog(1) + by auto + obtain ws v where ws_def: "reaches_on (ru' \) (su' \) ws v" "wf_vydra \ n (msize_fmla \) v" "length ws = n" + using vydra_wf_reaches_on[OF _ prog(2,3)] aux[OF less_imp_le_nat] + unfolding ru'_def su'_def + by blast + have ru_Some: "ru' \ v \ None" + using aux[OF order.refl ws_def(2)] + by (fastforce simp: ru'_def) + obtain v' t b where tb_def: "ru' \ v = Some (v', (t, b))" + using ru_Some + by auto + show ?thesis + using reaches_on_n[OF ws_def(1)] tb_def vydra_sound'[OF reaches_on_n[OF ws_def(1)] tb_def prog(2,3)] + by (auto simp: ws_def(3)) +qed + +lemma map_option_apfst_idle: "map_option (apfst snd) (map_option (apfst (Pair n)) x) = x" + by (cases x) auto + +lemma vydra_sound: + assumes "reaches (run_vydra run_hd) (init_vydra init_hd run_hd \) n v" "run_vydra run_hd v = Some (v', (t, b))" "bounded_future_fmla \" "wf_fmla \" + shows "(t, b) = (\ \ n, sat \ n)" +proof - + have fst_v: "fst v = msize_fmla \" + by (rule reaches_invar[OF assms(1)]) (auto simp: init_vydra_def run_vydra_def Let_def) + have "reaches (ru' \) (su' \) n (snd v)" + using reaches_cong[OF assms(1), where ?P="\(m, w). m = msize_fmla \" and ?g=snd] + by (auto simp: init_vydra_def run_vydra_def ru'_def su'_def map_option_apfst_idle Let_def simp del: sub.simps) + then show ?thesis + using vydra_sound'[OF _ _ assms(3,4)] assms(2) fst_v + by (auto simp: run_vydra_def ru'_def split: prod.splits) +qed + +lemma vydra_complete: + assumes prefix: "reaches_on run_hd init_hd vs e" + and prog: "n < progress \ (map fst vs)" "bounded_future_fmla \" "wf_fmla \" + shows "\v v'. reaches (run_vydra run_hd) (init_vydra init_hd run_hd \) n v \ run_vydra run_hd v = Some (v', (\ \ n, sat \ n))" +proof - + obtain v v' where wits: "reaches (ru' \) (su' \) n v" "ru' \ v = Some (v', \ \ n, sat \ n)" + using vydra_complete'[OF assms] + by auto + have reach: "reaches (run_vydra run_hd) (init_vydra init_hd run_hd \) n (msize_fmla \, v)" + using reaches_cong[OF wits(1), where ?P="\x. True" and ?f'="run_vydra run_hd" and ?g="Pair (msize_fmla \)"] + by (auto simp: init_vydra_def run_vydra_def ru'_def su'_def Let_def simp del: sub.simps) + show ?thesis + apply (rule exI[of _ "(msize_fmla \, v)"]) + apply (rule exI[of _ "(msize_fmla \, v')"]) + apply (auto simp: run_vydra_def wits(2)[unfolded ru'_def] intro: reach) + done +qed + +end + +context MDL +begin + +lemma reach_elem: + assumes "reaches (\i. if P i then Some (Suc i, (\ \ i, \ \ i)) else None) s n s'" "s = 0" + shows "s' = n" +proof - + obtain vs where vs_def: "reaches_on (\i. if P i then Some (Suc i, (\ \ i, \ \ i)) else None) s vs s'" "length vs = n" + using reaches_on[OF assms(1)] + by auto + have "s' = length vs" + using vs_def(1) assms(2) + by (induction s vs s' rule: reaches_on_rev_induct) (auto split: if_splits) + then show ?thesis + using vs_def(2) + by auto +qed + +interpretation default_vydra: VYDRA_MDL \ 0 "\i. Some (Suc i, (\ \ i, \ \ i))" + using reach_elem[where ?P="\_. True"] + by unfold_locales auto + +end + +lemma reaches_inj: "reaches r s i t \ reaches r s i t' \ t = t'" + using reaches_on_inj reaches_on + by metis + +lemma progress_sound: + assumes + "\n. n < length ts \ ts ! n = \ \ n" + "\n. n < length ts \ \ \ n = \ \' n" + "\n. n < length ts \ \ \ n = \ \' n" + "n < progress phi ts" + "bounded_future_fmla phi" + "wf_fmla phi" + shows "MDL.sat \ phi n \ MDL.sat \' phi n" +proof - + define run_hd where "run_hd = (\i. if i < length ts then Some (Suc i, (\ \ i, \ \ i)) else None)" + interpret vydra: VYDRA_MDL \ 0 run_hd + using MDL.reach_elem[where ?P="\i. i < length ts"] + by unfold_locales (auto simp: run_hd_def split: if_splits) + define run_hd' where "run_hd' = (\i. if i < length ts then Some (Suc i, (\ \' i, \ \' i)) else None)" + interpret vydra': VYDRA_MDL \' 0 run_hd' + using MDL.reach_elem[where ?P="\i. i < length ts"] + by unfold_locales (auto simp: run_hd'_def split: if_splits) + have run_hd_hd': "run_hd = run_hd'" + using assms(1-3) + by (auto simp: run_hd_def run_hd'_def) + have reaches_run_hd: "n \ length ts \ reaches_on run_hd 0 (map (\i. (\ \ i, \ \ i)) [0..i. (\ \ i, \ \ i)) [0.. \ n, vydra.sat phi n)" + using vydra.vydra_complete[OF reaches_run_hd[OF order.refl] _ assms(5,6)] assms(4) + unfolding ts_map[symmetric] + by blast + have reaches_run_hd': "n \ length ts \ reaches_on run_hd' 0 (map (\i. (\ \' i, \ \' i)) [0..i. (\ \' i, \ \' i)) [0.. \' n, vydra'.sat phi n)" + using vydra'.vydra_complete[OF reaches_run_hd'[OF order.refl] _ assms(5,6)] assms(4) + unfolding ts'_map[symmetric] + by blast + note v_w = reaches_inj[OF vv_def(1) ww_def(1)[folded run_hd_hd']] + show ?thesis + using vv_def(2) ww_def(2) + by (auto simp: run_hd_hd' v_w) +qed + +end diff --git a/thys/VYDRA_MDL/Monitor_Code.thy b/thys/VYDRA_MDL/Monitor_Code.thy new file mode 100644 --- /dev/null +++ b/thys/VYDRA_MDL/Monitor_Code.thy @@ -0,0 +1,132 @@ +theory Monitor_Code + imports "HOL-Library.Code_Target_Nat" "Containers.Containers" Monitor Preliminaries +begin + +derive (eq) ceq enat + +instantiation enat :: ccompare begin + +definition ccompare_enat :: "enat comparator option" where + "ccompare_enat = Some (\x y. if x = y then order.Eq else if x < y then order.Lt else order.Gt)" + +instance by intro_classes + (auto simp: ccompare_enat_def split: if_splits intro!: comparator.intro) + +end + +code_printing + code_module "IArray" \ (OCaml) +\module IArray : sig + val length' : 'a array -> Z.t + val sub' : 'a array * Z.t -> 'a +end = struct + +let length' xs = Z.of_int (Array.length xs);; + +let sub' (xs, i) = Array.get xs (Z.to_int i);; + +end\ for type_constructor iarray constant IArray.length' IArray.sub' + +code_reserved OCaml IArray + +code_printing + type_constructor iarray \ (OCaml) "_ array" +| constant iarray_of_list \ (OCaml) "Array.of'_list" +| constant IArray.list_of \ (OCaml) "Array.to'_list" +| constant IArray.length' \ (OCaml) "IArray.length'" +| constant IArray.sub' \ (OCaml) "IArray.sub'" + +lemma iarray_list_of_inj: "IArray.list_of xs = IArray.list_of ys \ xs = ys" + by (cases xs; cases ys) auto + +instantiation iarray :: (ccompare) ccompare +begin + +definition ccompare_iarray :: "('a iarray \ 'a iarray \ order) option" where + "ccompare_iarray = (case ID CCOMPARE('a list) of None \ None + | Some c \ Some (\xs ys. c (IArray.list_of xs) (IArray.list_of ys)))" + +instance + apply standard + apply unfold_locales + using comparator.sym[OF ID_ccompare'] comparator.weak_eq[OF ID_ccompare'] + comparator.comp_trans[OF ID_ccompare'] iarray_list_of_inj + apply (auto simp: ccompare_iarray_def split: option.splits) + apply blast+ + done + +end + +derive (rbt) mapping_impl iarray + +definition mk_db :: "String.literal list \ String.literal set" where "mk_db = set" + +definition init_vydra_string_enat :: "_ \ _ \ _ \ (String.literal, enat, 'e) vydra" where + "init_vydra_string_enat = init_vydra" +definition run_vydra_string_enat :: " _ \ (String.literal, enat, 'e) vydra \ _" where + "run_vydra_string_enat = run_vydra" +definition progress_enat :: "(String.literal, enat) formula \ enat list \ nat" where + "progress_enat = progress" +definition bounded_future_fmla_enat :: "(String.literal, enat) formula \ bool" where + "bounded_future_fmla_enat = bounded_future_fmla" +definition wf_fmla_enat :: "(String.literal, enat) formula \ bool" where + "wf_fmla_enat = wf_fmla" +definition mdl2mdl'_enat :: "(String.literal, enat) formula \ (String.literal, enat) Preliminaries.formula" where + "mdl2mdl'_enat = mdl2mdl'" +definition interval_enat :: "enat \ enat \ bool \ bool \ enat \" where + "interval_enat = interval" +definition left_enat :: "enat \ \ enat" where + "left_enat = left" +definition right_enat :: "enat \ \ enat" where + "right_enat = right" + +definition init_vydra_string_ereal :: "_ \ _ \ _ \ (String.literal, ereal, 'e) vydra" where + "init_vydra_string_ereal = init_vydra" +definition run_vydra_string_ereal :: " _ \ (String.literal, ereal, 'e) vydra \ _" where + "run_vydra_string_ereal = run_vydra" +definition progress_ereal :: "(String.literal, ereal) formula \ ereal list \ real" where + "progress_ereal = progress" +definition bounded_future_fmla_ereal :: "(String.literal, ereal) formula \ bool" where + "bounded_future_fmla_ereal = bounded_future_fmla" +definition wf_fmla_ereal :: "(String.literal, ereal) formula \ bool" where + "wf_fmla_ereal = wf_fmla" +definition mdl2mdl'_ereal :: "(String.literal, ereal) formula \ (String.literal, ereal) Preliminaries.formula" where + "mdl2mdl'_ereal = mdl2mdl'" +definition interval_ereal :: "ereal \ ereal \ bool \ bool \ ereal \" where + "interval_ereal = interval" +definition left_ereal :: "ereal \ \ ereal" where + "left_ereal = left" +definition right_ereal :: "ereal \ \ ereal" where + "right_ereal = right" + +lemma tfin_enat_code[code]: "(tfin :: enat set) = Collect_set (\x. x \ \)" + by (auto simp: tfin_enat_def) + +lemma tfin_ereal_code[code]: "(tfin :: ereal set) = Collect_set (\x. x \ -\ \ x \ \)" + by (auto simp: tfin_ereal_def) + +lemma Ball_atms[code_unfold]: "Ball (atms r) P = list_all P (collect_subfmlas r [])" + using collect_subfmlas_atms[where ?phis="[]"] + by (auto simp: list_all_def) + +lemma MIN_fold: "(MIN x\set (z # zs). f x) = fold min (map f zs) (f z)" + by (metis Min.set_eq_fold list.set_map list.simps(9)) + +declare progress.simps(1-8)[code] + +lemma progress_matchP_code[code]: + "progress (MatchP I r) ts = (case collect_subfmlas r [] of x # xs \ fold min (map (\f. progress f ts) xs) (progress x ts))" + using collect_subfmlas_atms[where ?r=r and ?phis="[]"] atms_nonempty[of r] + by (auto split: list.splits) (smt (z3) MIN_fold[where ?f="\f. progress f ts"] list.simps(15)) + +lemma progress_matchF_code[code]: + "progress (MatchF I r) ts = (if length ts = 0 then 0 else + (let k = min (length ts - 1) (case collect_subfmlas r [] of x # xs \ fold min (map (\f. progress f ts) xs) (progress x ts)) in + Min {j \ {..k}. memR (ts ! j) (ts ! k) I}))" + by (auto simp: progress_matchP_code[unfolded progress.simps]) + +export_code init_vydra_string_enat run_vydra_string_enat progress_enat bounded_future_fmla_enat wf_fmla_enat mdl2mdl'_enat + Bool Preliminaries.Bool enat interval_enat left_enat right_enat nat_of_integer integer_of_nat mk_db + in OCaml module_name VYDRA file_prefix "verified" + +end diff --git a/thys/VYDRA_MDL/NFA.thy b/thys/VYDRA_MDL/NFA.thy new file mode 100644 --- /dev/null +++ b/thys/VYDRA_MDL/NFA.thy @@ -0,0 +1,958 @@ +theory NFA + imports "HOL-Library.IArray" +begin + +type_synonym state = nat + +datatype transition = eps_trans state nat | symb_trans state | split_trans state state + +fun state_set :: "transition \ state set" where + "state_set (eps_trans s _) = {s}" +| "state_set (symb_trans s) = {s}" +| "state_set (split_trans s s') = {s, s'}" + +fun fmla_set :: "transition \ nat set" where + "fmla_set (eps_trans _ n) = {n}" +| "fmla_set _ = {}" + +lemma rtranclp_closed: "rtranclp R q q' \ X = X \ {q'. \q \ X. R q q'} \ + q \ X \ q' \ X" + by (induction q q' rule: rtranclp.induct) auto + +lemma rtranclp_closed_sub: "rtranclp R q q' \ {q'. \q \ X. R q q'} \ X \ + q \ X \ q' \ X" + by (induction q q' rule: rtranclp.induct) auto + +lemma rtranclp_closed_sub': "rtranclp R q q' \ q' = q \ (\q''. R q q'' \ rtranclp R q'' q')" + using converse_rtranclpE by force + +lemma rtranclp_step: "rtranclp R q q'' \ (\q'. R q q' \ q' \ X) \ + q = q'' \ (\q' \ X. R q q' \ rtranclp R q' q'')" + by (induction q q'' rule: rtranclp.induct) + (auto intro: rtranclp.rtrancl_into_rtrancl) + +lemma rtranclp_unfold: "rtranclp R x z \ x = z \ (\y. R x y \ rtranclp R y z)" + by (induction x z rule: rtranclp.induct) auto + +context fixes + q0 :: "state" and + qf :: "state" and + transs :: "transition list" +begin + +(* sets of states *) + +qualified definition SQ :: "state set" where + "SQ = {q0.. SQ \ q0 \ q \ q < q0 + length transs" + by (auto simp: SQ_def) + +lemma finite_SQ: "finite SQ" + by (auto simp add: SQ_def) + +lemma transs_q_in_set: "q \ SQ \ transs ! (q - q0) \ set transs" + by (auto simp add: SQ_def) + +qualified definition Q :: "state set" where + "Q = SQ \ {qf}" + +lemma finite_Q: "finite Q" + by (auto simp add: Q_def SQ_def) + +lemma SQ_sub_Q: "SQ \ Q" + by (auto simp add: SQ_def Q_def) + +(* set of formula indices *) + +qualified definition nfa_fmla_set :: "nat set" where + "nfa_fmla_set = \(fmla_set ` set transs)" + +(* step relation *) + +qualified definition step_eps :: "bool list \ state \ state \ bool" where + "step_eps bs q q' \ q \ SQ \ + (case transs ! (q - q0) of eps_trans p n \ n < length bs \ bs ! n \ p = q' + | split_trans p p' \ p = q' \ p' = q' | _ \ False)" + +lemma step_eps_dest: "step_eps bs q q' \ q \ SQ" + by (auto simp add: step_eps_def) + +lemma step_eps_mono: "step_eps [] q q' \ step_eps bs q q'" + by (auto simp: step_eps_def split: transition.splits) + +(* successors in step relation *) + +qualified definition step_eps_sucs :: "bool list \ state \ state set" where + "step_eps_sucs bs q = (if q \ SQ then + (case transs ! (q - q0) of eps_trans p n \ if n < length bs \ bs ! n then {p} else {} + | split_trans p p' \ {p, p'} | _ \ {}) else {})" + +lemma step_eps_sucs_sound: "q' \ step_eps_sucs bs q \ step_eps bs q q'" + by (auto simp add: step_eps_sucs_def step_eps_def split: transition.splits) + +qualified definition step_eps_set :: "bool list \ state set \ state set" where + "step_eps_set bs R = \(step_eps_sucs bs ` R)" + +lemma step_eps_set_sound: "step_eps_set bs R = {q'. \q \ R. step_eps bs q q'}" + using step_eps_sucs_sound by (auto simp add: step_eps_set_def) + +lemma step_eps_set_mono: "R \ S \ step_eps_set bs R \ step_eps_set bs S" + by (auto simp add: step_eps_set_def) + +(* reflexive and transitive closure of step relation *) + +qualified definition step_eps_closure :: "bool list \ state \ state \ bool" where + "step_eps_closure bs = (step_eps bs)\<^sup>*\<^sup>*" + +lemma step_eps_closure_dest: "step_eps_closure bs q q' \ q \ q' \ q \ SQ" + unfolding step_eps_closure_def + apply (induction q q' rule: rtranclp.induct) using step_eps_dest by auto + +qualified definition step_eps_closure_set :: "state set \ bool list \ state set" where + "step_eps_closure_set R bs = \((\q. {q'. step_eps_closure bs q q'}) ` R)" + +lemma step_eps_closure_set_refl: "R \ step_eps_closure_set R bs" + by (auto simp add: step_eps_closure_set_def step_eps_closure_def) + +lemma step_eps_closure_set_mono: "R \ S \ step_eps_closure_set R bs \ step_eps_closure_set S bs" + by (auto simp add: step_eps_closure_set_def) + +lemma step_eps_closure_set_empty: "step_eps_closure_set {} bs = {}" + by (auto simp add: step_eps_closure_set_def) + +lemma step_eps_closure_set_mono': "step_eps_closure_set R [] \ step_eps_closure_set R bs" + by (auto simp: step_eps_closure_set_def step_eps_closure_def) (metis mono_rtranclp step_eps_mono) + +lemma step_eps_closure_set_split: "step_eps_closure_set (R \ S) bs = + step_eps_closure_set R bs \ step_eps_closure_set S bs" + by (auto simp add: step_eps_closure_set_def) + +lemma step_eps_closure_set_Un: "step_eps_closure_set (\x \ X. R x) bs = + (\x \ X. step_eps_closure_set (R x) bs)" + by (auto simp add: step_eps_closure_set_def) + +lemma step_eps_closure_set_idem: "step_eps_closure_set (step_eps_closure_set R bs) bs = + step_eps_closure_set R bs" + unfolding step_eps_closure_set_def step_eps_closure_def by auto + +lemma step_eps_closure_set_flip: + assumes "step_eps_closure_set R bs = R \ S" + shows "step_eps_closure_set S bs \ R \ S" + using step_eps_closure_set_idem[of R bs, unfolded assms, unfolded step_eps_closure_set_split] + by auto + +lemma step_eps_closure_set_unfold: "(\q'. step_eps bs q q' \ q' \ X) \ + step_eps_closure_set {q} bs = {q} \ step_eps_closure_set X bs" + unfolding step_eps_closure_set_def step_eps_closure_def + using rtranclp_step[of "step_eps bs" q] + by (auto simp add: converse_rtranclp_into_rtranclp) + +lemma step_step_eps_closure: "step_eps bs q q' \ q \ R \ q' \ step_eps_closure_set R bs" + unfolding step_eps_closure_set_def step_eps_closure_def by auto + +lemma step_eps_closure_set_code[code]: + "step_eps_closure_set R bs = + (let R' = R \ step_eps_set bs R in if R = R' then R else step_eps_closure_set R' bs)" + using rtranclp_closed + by (auto simp add: step_eps_closure_set_def step_eps_closure_def step_eps_set_sound Let_def) + +(* no step_eps *) + +lemma step_eps_closure_empty: "step_eps_closure bs q q' \ (\q'. \step_eps bs q q') \ q = q'" + unfolding step_eps_closure_def by (induction q q' rule: rtranclp.induct) auto + +lemma step_eps_closure_set_step_id: "(\q q'. q \ R \ \step_eps bs q q') \ + step_eps_closure_set R bs = R" + using step_eps_closure_empty step_eps_closure_set_refl unfolding step_eps_closure_set_def by blast + +(* wildcard step relation *) + +qualified definition step_symb :: "state \ state \ bool" where + "step_symb q q' \ q \ SQ \ + (case transs ! (q - q0) of symb_trans p \ p = q' | _ \ False)" + +lemma step_symb_dest: "step_symb q q' \ q \ SQ" + by (auto simp add: step_symb_def) + +(* successors in wildcard step relation *) + +qualified definition step_symb_sucs :: "state \ state set" where + "step_symb_sucs q = (if q \ SQ then + (case transs ! (q - q0) of symb_trans p \ {p} | _ \ {}) else {})" + +lemma step_symb_sucs_sound: "q' \ step_symb_sucs q \ step_symb q q'" + by (auto simp add: step_symb_sucs_def step_symb_def split: transition.splits) + +qualified definition step_symb_set :: "state set \ state set" where + "step_symb_set R = {q'. \q \ R. step_symb q q'}" + +lemma step_symb_set_mono: "R \ S \ step_symb_set R \ step_symb_set S" + by (auto simp add: step_symb_set_def) + +lemma step_symb_set_empty: "step_symb_set {} = {}" + by (auto simp add: step_symb_set_def) + +lemma step_symb_set_proj: "step_symb_set R = step_symb_set (R \ SQ)" + using step_symb_dest by (auto simp add: step_symb_set_def) + +lemma step_symb_set_split: "step_symb_set (R \ S) = step_symb_set R \ step_symb_set S" + by (auto simp add: step_symb_set_def) + +lemma step_symb_set_Un: "step_symb_set (\x \ X. R x) = (\x \ X. step_symb_set (R x))" + by (auto simp add: step_symb_set_def) + +lemma step_symb_set_code[code]: "step_symb_set R = \(step_symb_sucs ` R)" + using step_symb_sucs_sound by (auto simp add: step_symb_set_def) + +(* delta function *) + +qualified definition delta :: "state set \ bool list \ state set" where + "delta R bs = step_symb_set (step_eps_closure_set R bs)" + +lemma delta_eps: "delta (step_eps_closure_set R bs) bs = delta R bs" + unfolding delta_def step_eps_closure_set_idem by (rule refl) + +lemma delta_eps_split: + assumes "step_eps_closure_set R bs = R \ S" + shows "delta R bs = step_symb_set R \ delta S bs" + unfolding delta_def assms step_symb_set_split + using step_symb_set_mono[OF step_eps_closure_set_flip[OF assms], unfolded step_symb_set_split] + step_symb_set_mono[OF step_eps_closure_set_refl] by auto + +lemma delta_split: "delta (R \ S) bs = delta R bs \ delta S bs" + by (auto simp add: delta_def step_symb_set_split step_eps_closure_set_split) + +lemma delta_Un: "delta (\x \ X. R x) bs = (\x \ X. delta (R x) bs)" + unfolding delta_def step_eps_closure_set_Un step_symb_set_Un by simp + +lemma delta_step_symb_set_absorb: "delta R bs = delta R bs \ step_symb_set R" + using step_eps_closure_set_refl by (auto simp add: delta_def step_symb_set_def) + +lemma delta_sub_eps_mono: + assumes "S \ step_eps_closure_set R bs" + shows "delta S bs \ delta R bs" + unfolding delta_def + using step_symb_set_mono[OF step_eps_closure_set_mono[OF assms, of bs, + unfolded step_eps_closure_set_idem]] by simp + +(* run delta function *) + +qualified definition run :: "state set \ bool list list \ state set" where + "run R bss = foldl delta R bss" + +lemma run_eps_split: + assumes "step_eps_closure_set R bs = R \ S" "step_symb_set R = {}" + shows "run R (bs # bss) = run S (bs # bss)" + unfolding run_def foldl.simps delta_eps_split[OF assms(1), unfolded assms(2)] + by auto + +lemma run_empty: "run {} bss = {}" + unfolding run_def + by (induction bss) + (auto simp add: delta_def step_symb_set_empty step_eps_closure_set_empty) + +lemma run_Nil: "run R [] = R" + by (auto simp add: run_def) + +lemma run_Cons: "run R (bs # bss) = run (delta R bs) bss" + unfolding run_def by simp + +lemma run_split: "run (R \ S) bss = run R bss \ run S bss" + unfolding run_def + by (induction bss arbitrary: R S) (auto simp add: delta_split) + +lemma run_Un: "run (\x \ X. R x) bss = (\x \ X. run (R x) bss)" + unfolding run_def + by (induction bss arbitrary: R) (auto simp add: delta_Un) + +lemma run_comp: "run R (bss @ css) = run (run R bss) css" + unfolding run_def by simp + +(* accept function *) + +qualified definition accept_eps :: "state set \ bool list \ bool" where + "accept_eps R bs \ (qf \ step_eps_closure_set R bs)" + +lemma step_eps_accept_eps: "step_eps bs q qf \ q \ R \ accept_eps R bs" + unfolding accept_eps_def using step_step_eps_closure by simp + +lemma accept_eps_empty: "accept_eps {} bs \ False" + by (auto simp add: accept_eps_def step_eps_closure_set_def) + +lemma accept_eps_split: "accept_eps (R \ S) bs \ accept_eps R bs \ accept_eps S bs" + by (auto simp add: accept_eps_def step_eps_closure_set_split) + +lemma accept_eps_Un: "accept_eps (\x \ X. R x) bs \ (\x \ X. accept_eps (R x) bs)" + by (auto simp add: accept_eps_def step_eps_closure_set_def) + +qualified definition accept :: "state set \ bool" where + "accept R \ accept_eps R []" + +(* is a run accepting? *) + +qualified definition run_accept_eps :: "state set \ bool list list \ bool list \ bool" where + "run_accept_eps R bss bs = accept_eps (run R bss) bs" + +lemma run_accept_eps_empty: "\run_accept_eps {} bss bs" + unfolding run_accept_eps_def run_empty accept_eps_empty by simp + +lemma run_accept_eps_Nil: "run_accept_eps R [] cs \ accept_eps R cs" + by (auto simp add: run_accept_eps_def run_Nil) + +lemma run_accept_eps_Cons: "run_accept_eps R (bs # bss) cs \ run_accept_eps (delta R bs) bss cs" + by (auto simp add: run_accept_eps_def run_Cons) + +lemma run_accept_eps_Cons_delta_cong: "delta R bs = delta S bs \ + run_accept_eps R (bs # bss) cs \ run_accept_eps S (bs # bss) cs" + unfolding run_accept_eps_Cons by auto + +lemma run_accept_eps_Nil_eps: "run_accept_eps (step_eps_closure_set R bs) [] bs \ run_accept_eps R [] bs" + unfolding run_accept_eps_Nil accept_eps_def step_eps_closure_set_idem by (rule refl) + +lemma run_accept_eps_Cons_eps: "run_accept_eps (step_eps_closure_set R cs) (cs # css) bs \ + run_accept_eps R (cs # css) bs" + unfolding run_accept_eps_Cons delta_eps by (rule refl) + +lemma run_accept_eps_Nil_eps_split: + assumes "step_eps_closure_set R bs = R \ S" "step_symb_set R = {}" "qf \ R" + shows "run_accept_eps R [] bs = run_accept_eps S [] bs" + unfolding Nil run_accept_eps_Nil accept_eps_def assms(1) + using assms(3) step_eps_closure_set_refl step_eps_closure_set_flip[OF assms(1)] by auto + +lemma run_accept_eps_Cons_eps_split: + assumes "step_eps_closure_set R cs = R \ S" "step_symb_set R = {}" "qf \ R" + shows "run_accept_eps R (cs # css) bs = run_accept_eps S (cs # css) bs" + unfolding run_accept_eps_def Cons run_eps_split[OF assms(1,2)] by (rule refl) + +lemma run_accept_eps_split: "run_accept_eps (R \ S) bss bs \ + run_accept_eps R bss bs \ run_accept_eps S bss bs" + unfolding run_accept_eps_def run_split accept_eps_split by auto + +lemma run_accept_eps_Un: "run_accept_eps (\x \ X. R x) bss bs \ + (\x \ X. run_accept_eps (R x) bss bs)" + unfolding run_accept_eps_def run_Un accept_eps_Un by simp + +qualified definition run_accept :: "state set \ bool list list \ bool" where + "run_accept R bss = accept (run R bss)" + +end + +definition "iarray_of_list xs = IArray xs" + +context fixes + transs :: "transition iarray" + and len :: nat +begin + +qualified definition step_eps' :: "bool iarray \ state \ state \ bool" where + "step_eps' bs q q' \ q < len \ + (case transs !! q of eps_trans p n \ n < IArray.length bs \ bs !! n \ p = q' + | split_trans p p' \ p = q' \ p' = q' | _ \ False)" + +qualified definition step_eps_closure' :: "bool iarray \ state \ state \ bool" where + "step_eps_closure' bs = (step_eps' bs)\<^sup>*\<^sup>*" + +qualified definition step_eps_sucs' :: "bool iarray \ state \ state set" where + "step_eps_sucs' bs q = (if q < len then + (case transs !! q of eps_trans p n \ if n < IArray.length bs \ bs !! n then {p} else {} + | split_trans p p' \ {p, p'} | _ \ {}) else {})" + +lemma step_eps_sucs'_sound: "q' \ step_eps_sucs' bs q \ step_eps' bs q q'" + by (auto simp add: step_eps_sucs'_def step_eps'_def split: transition.splits) + +qualified definition step_eps_set' :: "bool iarray \ state set \ state set" where + "step_eps_set' bs R = \(step_eps_sucs' bs ` R)" + +lemma step_eps_set'_sound: "step_eps_set' bs R = {q'. \q \ R. step_eps' bs q q'}" + using step_eps_sucs'_sound by (auto simp add: step_eps_set'_def) + +qualified definition step_eps_closure_set' :: "state set \ bool iarray \ state set" where + "step_eps_closure_set' R bs = \((\q. {q'. step_eps_closure' bs q q'}) ` R)" + +lemma step_eps_closure_set'_code[code]: + "step_eps_closure_set' R bs = + (let R' = R \ step_eps_set' bs R in if R = R' then R else step_eps_closure_set' R' bs)" + using rtranclp_closed + by (auto simp add: step_eps_closure_set'_def step_eps_closure'_def step_eps_set'_sound Let_def) + +qualified definition step_symb_sucs' :: "state \ state set" where + "step_symb_sucs' q = (if q < len then + (case transs !! q of symb_trans p \ {p} | _ \ {}) else {})" + +qualified definition step_symb_set' :: "state set \ state set" where + "step_symb_set' R = \(step_symb_sucs' ` R)" + +qualified definition delta' :: "state set \ bool iarray \ state set" where + "delta' R bs = step_symb_set' (step_eps_closure_set' R bs)" + +qualified definition accept_eps' :: "state set \ bool iarray \ bool" where + "accept_eps' R bs \ (len \ step_eps_closure_set' R bs)" + +qualified definition accept' :: "state set \ bool" where + "accept' R \ accept_eps' R (iarray_of_list [])" + +qualified definition run' :: "state set \ bool iarray list \ state set" where + "run' R bss = foldl delta' R bss" + +qualified definition run_accept_eps' :: "state set \ bool iarray list \ bool iarray \ bool" where + "run_accept_eps' R bss bs = accept_eps' (run' R bss) bs" + +qualified definition run_accept' :: "state set \ bool iarray list \ bool" where + "run_accept' R bss = accept' (run' R bss)" + +end + +locale nfa_array = + fixes transs :: "transition list" + and transs' :: "transition iarray" + and len :: nat + assumes transs_eq: "transs' = IArray transs" + and len_def: "len = length transs" +begin + +abbreviation "step_eps \ NFA.step_eps 0 transs" +abbreviation "step_eps' \ NFA.step_eps' transs' len" +abbreviation "step_eps_closure \ NFA.step_eps_closure 0 transs" +abbreviation "step_eps_closure' \ NFA.step_eps_closure' transs' len" +abbreviation "step_eps_sucs \ NFA.step_eps_sucs 0 transs" +abbreviation "step_eps_sucs' \ NFA.step_eps_sucs' transs' len" +abbreviation "step_eps_set \ NFA.step_eps_set 0 transs" +abbreviation "step_eps_set' \ NFA.step_eps_set' transs' len" +abbreviation "step_eps_closure_set \ NFA.step_eps_closure_set 0 transs" +abbreviation "step_eps_closure_set' \ NFA.step_eps_closure_set' transs' len" +abbreviation "step_symb_sucs \ NFA.step_symb_sucs 0 transs" +abbreviation "step_symb_sucs' \ NFA.step_symb_sucs' transs' len" +abbreviation "step_symb_set \ NFA.step_symb_set 0 transs" +abbreviation "step_symb_set' \ NFA.step_symb_set' transs' len" +abbreviation "delta \ NFA.delta 0 transs" +abbreviation "delta' \ NFA.delta' transs' len" +abbreviation "accept_eps \ NFA.accept_eps 0 len transs" +abbreviation "accept_eps' \ NFA.accept_eps' transs' len" +abbreviation "accept \ NFA.accept 0 len transs" +abbreviation "accept' \ NFA.accept' transs' len" +abbreviation "run \ NFA.run 0 transs" +abbreviation "run' \ NFA.run' transs' len" +abbreviation "run_accept_eps \ NFA.run_accept_eps 0 len transs" +abbreviation "run_accept_eps' \ NFA.run_accept_eps' transs' len" +abbreviation "run_accept \ NFA.run_accept 0 len transs" +abbreviation "run_accept' \ NFA.run_accept' transs' len" + +lemma q_in_SQ: "q \ NFA.SQ 0 transs \ q < len" + using len_def + by (auto simp: NFA.SQ_def) + +lemma step_eps'_eq: "bs' = IArray bs \ step_eps bs q q' \ step_eps' bs' q q'" + by (auto simp: NFA.step_eps_def NFA.step_eps'_def q_in_SQ transs_eq split: transition.splits) + +lemma step_eps_closure'_eq: "bs' = IArray bs \ step_eps_closure bs q q' \ step_eps_closure' bs' q q'" +proof - + assume lassm: "bs' = IArray bs" + have step_eps_eq_folded: "step_eps bs = step_eps' bs'" + using step_eps'_eq[OF lassm] + by auto + show ?thesis + by (auto simp: NFA.step_eps_closure_def NFA.step_eps_closure'_def step_eps_eq_folded) +qed + +lemma step_eps_sucs'_eq: "bs' = IArray bs \ step_eps_sucs bs q = step_eps_sucs' bs' q" + by (auto simp: NFA.step_eps_sucs_def NFA.step_eps_sucs'_def q_in_SQ transs_eq + split: transition.splits) + +lemma step_eps_set'_eq: "bs' = IArray bs \ step_eps_set bs R = step_eps_set' bs' R" + by (auto simp: NFA.step_eps_set_def NFA.step_eps_set'_def step_eps_sucs'_eq) + +lemma step_eps_closure_set'_eq: "bs' = IArray bs \ step_eps_closure_set R bs = step_eps_closure_set' R bs'" + by (auto simp: NFA.step_eps_closure_set_def NFA.step_eps_closure_set'_def step_eps_closure'_eq) + +lemma step_symb_sucs'_eq: "bs' = IArray bs \ step_symb_sucs R = step_symb_sucs' R" + by (auto simp: NFA.step_symb_sucs_def NFA.step_symb_sucs'_def q_in_SQ transs_eq + split: transition.splits) + +lemma step_symb_set'_eq: "bs' = IArray bs \ step_symb_set R = step_symb_set' R" + by (auto simp: step_symb_set_code NFA.step_symb_set'_def step_symb_sucs'_eq) + +lemma delta'_eq: "bs' = IArray bs \ delta R bs = delta' R bs'" + by (auto simp: NFA.delta_def NFA.delta'_def step_eps_closure_set'_eq step_symb_set'_eq) + +lemma accept_eps'_eq: "bs' = IArray bs \ accept_eps R bs = accept_eps' R bs'" + by (auto simp: NFA.accept_eps_def NFA.accept_eps'_def step_eps_closure_set'_eq) + +lemma accept'_eq: "accept R = accept' R" + by (auto simp: NFA.accept_def NFA.accept'_def accept_eps'_eq iarray_of_list_def) + +lemma run'_eq: "bss' = map IArray bss \ run R bss = run' R bss'" + by (induction bss arbitrary: R bss') (auto simp: NFA.run_def NFA.run'_def delta'_eq) + +lemma run_accept_eps'_eq: "bss' = map IArray bss \ bs' = IArray bs \ + run_accept_eps R bss bs \ run_accept_eps' R bss' bs'" + by (auto simp: NFA.run_accept_eps_def NFA.run_accept_eps'_def accept_eps'_eq run'_eq) + +lemma run_accept'_eq: "bss' = map IArray bss \ + run_accept R bss \ run_accept' R bss'" + by (auto simp: NFA.run_accept_def NFA.run_accept'_def run'_eq accept'_eq) + +end + +locale nfa = + fixes q0 :: nat + and qf :: nat + and transs :: "transition list" + assumes state_closed: "\t. t \ set transs \ state_set t \ NFA.Q q0 qf transs" + and transs_not_Nil: "transs \ []" + and qf_not_in_SQ: "qf \ NFA.SQ q0 transs" +begin + +abbreviation "SQ \ NFA.SQ q0 transs" +abbreviation "Q \ NFA.Q q0 qf transs" +abbreviation "nfa_fmla_set \ NFA.nfa_fmla_set transs" +abbreviation "step_eps \ NFA.step_eps q0 transs" +abbreviation "step_eps_sucs \ NFA.step_eps_sucs q0 transs" +abbreviation "step_eps_set \ NFA.step_eps_set q0 transs" +abbreviation "step_eps_closure \ NFA.step_eps_closure q0 transs" +abbreviation "step_eps_closure_set \ NFA.step_eps_closure_set q0 transs" +abbreviation "step_symb \ NFA.step_symb q0 transs" +abbreviation "step_symb_sucs \ NFA.step_symb_sucs q0 transs" +abbreviation "step_symb_set \ NFA.step_symb_set q0 transs" +abbreviation "delta \ NFA.delta q0 transs" +abbreviation "run \ NFA.run q0 transs" +abbreviation "accept_eps \ NFA.accept_eps q0 qf transs" +abbreviation "run_accept_eps \ NFA.run_accept_eps q0 qf transs" + +lemma Q_diff_qf_SQ: "Q - {qf} = SQ" + using qf_not_in_SQ by (auto simp add: NFA.Q_def) + +lemma q0_sub_SQ: "{q0} \ SQ" + using transs_not_Nil by (auto simp add: NFA.SQ_def) + +lemma q0_sub_Q: "{q0} \ Q" + using q0_sub_SQ SQ_sub_Q by auto + +lemma step_eps_closed: "step_eps bs q q' \ q' \ Q" + using transs_q_in_set state_closed + by (fastforce simp add: NFA.step_eps_def split: transition.splits) + +lemma step_eps_set_closed: "step_eps_set bs R \ Q" + using step_eps_closed by (auto simp add: step_eps_set_sound) + +lemma step_eps_closure_closed: "step_eps_closure bs q q' \ q \ q' \ q' \ Q" + unfolding NFA.step_eps_closure_def + apply (induction q q' rule: rtranclp.induct) using step_eps_closed by auto + +lemma step_eps_closure_set_closed_union: "step_eps_closure_set R bs \ R \ Q" + using step_eps_closure_closed by (auto simp add: NFA.step_eps_closure_set_def NFA.step_eps_closure_def) + +lemma step_eps_closure_set_closed: "R \ Q \ step_eps_closure_set R bs \ Q" + using step_eps_closure_set_closed_union by auto + +lemma step_symb_closed: "step_symb q q' \ q' \ Q" + using transs_q_in_set state_closed + by (fastforce simp add: NFA.step_symb_def split: transition.splits) + +lemma step_symb_set_closed: "step_symb_set R \ Q" + using step_symb_closed by (auto simp add: NFA.step_symb_set_def) + +lemma step_symb_set_qf: "step_symb_set {qf} = {}" + using qf_not_in_SQ step_symb_set_proj[of _ _ "{qf}"] step_symb_set_empty by auto + +lemma delta_closed: "delta R bs \ Q" + using step_symb_set_closed by (auto simp add: NFA.delta_def) + +lemma run_closed_Cons: "run R (bs # bss) \ Q" + unfolding NFA.run_def + using delta_closed by (induction bss arbitrary: R bs) auto + +lemma run_closed: "R \ Q \ run R bss \ Q" + using run_Nil run_closed_Cons by (cases bss) auto + +(* transitions from accepting state *) + +lemma step_eps_qf: "step_eps bs qf q \ False" + using qf_not_in_SQ step_eps_dest by force + +lemma step_symb_qf: "step_symb qf q \ False" + using qf_not_in_SQ step_symb_dest by force + +lemma step_eps_closure_qf: "step_eps_closure bs q q' \ q = qf \ q = q'" + unfolding NFA.step_eps_closure_def + apply (induction q q' rule: rtranclp.induct) using step_eps_qf by auto + +lemma step_eps_closure_set_qf: "step_eps_closure_set {qf} bs = {qf}" + using step_eps_closure_qf unfolding NFA.step_eps_closure_set_def NFA.step_eps_closure_def by auto + +lemma delta_qf: "delta {qf} bs = {}" + using step_eps_closure_qf step_symb_qf + by (auto simp add: NFA.delta_def NFA.step_symb_set_def NFA.step_eps_closure_set_def) + +lemma run_qf_many: "run {qf} (bs # bss) = {}" + unfolding run_Cons delta_qf run_empty by (rule refl) + +lemma run_accept_eps_qf_many: "run_accept_eps {qf} (bs # bss) cs \ False" + unfolding NFA.run_accept_eps_def using run_qf_many accept_eps_empty by simp + +lemma run_accept_eps_qf_one: "run_accept_eps {qf} [] bs \ True" + unfolding NFA.run_accept_eps_def NFA.accept_eps_def using run_Nil step_eps_closure_set_refl by force + +end + +locale nfa_cong = nfa q0 qf transs + nfa': nfa q0' qf' transs' + for q0 q0' qf qf' transs transs' + + assumes SQ_sub: "nfa'.SQ \ SQ" and + qf_eq: "qf = qf'" and + transs_eq: "\q. q \ nfa'.SQ \ transs ! (q - q0) = transs' ! (q - q0')" +begin + +lemma q_Q_SQ_nfa'_SQ: "q \ nfa'.Q \ q \ SQ \ q \ nfa'.SQ" + using SQ_sub qf_not_in_SQ qf_eq by (auto simp add: NFA.Q_def) + +lemma step_eps_cong: "q \ nfa'.Q \ step_eps bs q q' \ nfa'.step_eps bs q q'" + using q_Q_SQ_nfa'_SQ transs_eq by (auto simp add: NFA.step_eps_def) + +lemma eps_nfa'_step_eps_closure: "step_eps_closure bs q q' \ q \ nfa'.Q \ + q' \ nfa'.Q \ nfa'.step_eps_closure bs q q'" + unfolding NFA.step_eps_closure_def + apply (induction q q' rule: rtranclp.induct) + using nfa'.step_eps_closure_closed step_eps_cong by (auto simp add: NFA.step_eps_closure_def) + +lemma nfa'_eps_step_eps_closure: "nfa'.step_eps_closure bs q q' \ q \ nfa'.Q \ + q' \ nfa'.Q \ step_eps_closure bs q q'" + unfolding NFA.step_eps_closure_def + apply (induction q q' rule: rtranclp.induct) + using nfa'.step_eps_closed step_eps_cong + by (auto simp add: NFA.step_eps_closure_def intro: rtranclp.intros(2)) + +lemma step_eps_closure_set_cong: "R \ nfa'.Q \ step_eps_closure_set R bs = + nfa'.step_eps_closure_set R bs" + using eps_nfa'_step_eps_closure nfa'_eps_step_eps_closure + by (fastforce simp add: NFA.step_eps_closure_set_def) + +lemma step_symb_cong: "q \ nfa'.Q \ step_symb q q' \ nfa'.step_symb q q'" + using q_Q_SQ_nfa'_SQ transs_eq by (auto simp add: NFA.step_symb_def) + +lemma step_symb_set_cong: "R \ nfa'.Q \ step_symb_set R = nfa'.step_symb_set R" + using step_symb_cong by (auto simp add: NFA.step_symb_set_def) + +lemma delta_cong: "R \ nfa'.Q \ delta R bs = nfa'.delta R bs" + using step_symb_set_cong nfa'.step_eps_closure_set_closed + by (auto simp add: NFA.delta_def step_eps_closure_set_cong) + +lemma run_cong: "R \ nfa'.Q \ run R bss = nfa'.run R bss" + unfolding NFA.run_def + using nfa'.delta_closed delta_cong by (induction bss arbitrary: R) auto + +lemma accept_eps_cong: "R \ nfa'.Q \ accept_eps R bs \ nfa'.accept_eps R bs" + unfolding NFA.accept_eps_def using step_eps_closure_set_cong qf_eq by auto + +lemma run_accept_eps_cong: + assumes "R \ nfa'.Q" + shows "run_accept_eps R bss bs \ nfa'.run_accept_eps R bss bs" + unfolding NFA.run_accept_eps_def run_cong[OF assms] + accept_eps_cong[OF nfa'.run_closed[OF assms]] by simp + +end + +fun list_split :: "'a list \ ('a list \ 'a list) set" where + "list_split [] = {}" +| "list_split (x # xs) = {([], x # xs)} \ (\(ys, zs) \ list_split xs. {(x # ys, zs)})" + +lemma list_split_unfold: "(\(ys, zs) \ list_split (x # xs). f ys zs) = + f [] (x # xs) \ (\(ys, zs) \ list_split xs. f (x # ys) zs)" + by (induction xs) auto + +lemma list_split_def: "list_split xs = (\n < length xs. {(take n xs, drop n xs)})" + using less_Suc_eq_0_disj by (induction xs rule: list_split.induct) auto+ + +locale nfa_cong' = nfa q0 qf transs + nfa': nfa q0' qf' transs' + for q0 q0' qf qf' transs transs' + + assumes SQ_sub: "nfa'.SQ \ SQ" and + qf'_in_SQ: "qf' \ SQ" and + transs_eq: "\q. q \ nfa'.SQ \ transs ! (q - q0) = transs' ! (q - q0')" +begin + +lemma nfa'_Q_sub_Q: "nfa'.Q \ Q" + unfolding NFA.Q_def using SQ_sub qf'_in_SQ by auto + +lemma q_SQ_SQ_nfa'_SQ: "q \ nfa'.SQ \ q \ SQ \ q \ nfa'.SQ" + using SQ_sub by auto + +lemma step_eps_cong_SQ: "q \ nfa'.SQ \ step_eps bs q q' \ nfa'.step_eps bs q q'" + using q_SQ_SQ_nfa'_SQ transs_eq by (auto simp add: NFA.step_eps_def) + +lemma step_eps_cong_Q: "q \ nfa'.Q \ nfa'.step_eps bs q q' \ step_eps bs q q'" + using SQ_sub transs_eq by (auto simp add: NFA.step_eps_def) + +lemma nfa'_step_eps_closure_cong: "nfa'.step_eps_closure bs q q' \ q \ nfa'.Q \ + step_eps_closure bs q q'" + unfolding NFA.step_eps_closure_def + apply (induction q q' rule: rtranclp.induct) + using NFA.Q_def NFA.step_eps_closure_def + by (auto simp add: rtranclp.rtrancl_into_rtrancl step_eps_cong_SQ step_eps_dest) + +lemma nfa'_step_eps_closure_set_sub: "R \ nfa'.Q \ nfa'.step_eps_closure_set R bs \ + step_eps_closure_set R bs" + unfolding NFA.step_eps_closure_set_def + using nfa'_step_eps_closure_cong by fastforce + +lemma eps_nfa'_step_eps_closure_cong: "step_eps_closure bs q q' \ q \ nfa'.Q \ + (q' \ nfa'.Q \ nfa'.step_eps_closure bs q q') \ + (nfa'.step_eps_closure bs q qf' \ step_eps_closure bs qf' q')" + unfolding NFA.step_eps_closure_def + apply (induction q q' rule: rtranclp.induct) + using nfa'.step_eps_closure_closed nfa'.step_eps_closed step_eps_cong_SQ NFA.Q_def + by (auto simp add: intro: rtranclp.rtrancl_into_rtrancl) fastforce+ + +lemma nfa'_eps_step_eps_closure_cong: "nfa'.step_eps_closure bs q q' \ q \ nfa'.Q \ + q' \ nfa'.Q \ step_eps_closure bs q q'" + unfolding NFA.step_eps_closure_def + apply (induction q q' rule: rtranclp.induct) + using nfa'.step_eps_closed step_eps_cong_Q + by (auto intro: rtranclp.intros(2)) + +lemma step_eps_closure_set_cong_reach: "R \ nfa'.Q \ qf' \ nfa'.step_eps_closure_set R bs \ + step_eps_closure_set R bs = nfa'.step_eps_closure_set R bs \ step_eps_closure_set {qf'} bs" + using eps_nfa'_step_eps_closure_cong nfa'_eps_step_eps_closure_cong + rtranclp_trans[of "step_eps bs"] + unfolding NFA.step_eps_closure_set_def NFA.step_eps_closure_def + by auto blast+ + +lemma step_eps_closure_set_cong_unreach: "R \ nfa'.Q \ qf' \ nfa'.step_eps_closure_set R bs \ + step_eps_closure_set R bs = nfa'.step_eps_closure_set R bs" + using eps_nfa'_step_eps_closure_cong nfa'_eps_step_eps_closure_cong + unfolding NFA.step_eps_closure_set_def NFA.step_eps_closure_def + by auto blast+ + +lemma step_symb_cong_SQ: "q \ nfa'.SQ \ step_symb q q' \ nfa'.step_symb q q'" + using q_SQ_SQ_nfa'_SQ transs_eq by (auto simp add: NFA.step_symb_def) + +lemma step_symb_cong_Q: "nfa'.step_symb q q' \ step_symb q q'" + using SQ_sub transs_eq by (auto simp add: NFA.step_symb_def) + +lemma step_symb_set_cong_SQ: "R \ nfa'.SQ \ step_symb_set R = nfa'.step_symb_set R" + using step_symb_cong_SQ by (auto simp add: NFA.step_symb_set_def) + +lemma step_symb_set_cong_Q: "nfa'.step_symb_set R \ step_symb_set R" + using step_symb_cong_Q by (auto simp add: NFA.step_symb_set_def) + +lemma delta_cong_unreach: + assumes "R \ nfa'.Q" "\nfa'.accept_eps R bs" + shows "delta R bs = nfa'.delta R bs" +proof - + have "nfa'.step_eps_closure_set R bs \ nfa'.SQ" + using nfa'.step_eps_closure_set_closed[OF assms(1), unfolded NFA.Q_def] + assms(2)[unfolded NFA.accept_eps_def] by auto + then show ?thesis + unfolding NFA.accept_eps_def NFA.delta_def using step_symb_set_cong_SQ + step_eps_closure_set_cong_unreach[OF assms(1) assms(2)[unfolded NFA.accept_eps_def]] + by auto +qed + +lemma nfa'_delta_sub_delta: + assumes "R \ nfa'.Q" + shows "nfa'.delta R bs \ delta R bs" + unfolding NFA.delta_def + using step_symb_set_mono[OF nfa'_step_eps_closure_set_sub[OF assms]] step_symb_set_cong_Q + by fastforce + +lemma delta_cong_reach: + assumes "R \ nfa'.Q" "nfa'.accept_eps R bs" + shows "delta R bs = nfa'.delta R bs \ delta {qf'} bs" +proof (rule set_eqI, rule iffI) + fix q + assume assm: "q \ delta R bs" + have nfa'_eps_diff_Un: "nfa'.step_eps_closure_set R bs = + nfa'.step_eps_closure_set R bs - {qf'} \ {qf'}" + using assms(2)[unfolded NFA.accept_eps_def] by auto + from assm have "q \ step_symb_set (nfa'.step_eps_closure_set R bs - {qf'}) \ + step_symb_set {qf'} \ delta {qf'} bs" + unfolding NFA.delta_def step_eps_closure_set_cong_reach[OF assms(1) + assms(2)[unfolded NFA.accept_eps_def]] step_symb_set_split[symmetric] + nfa'_eps_diff_Un[symmetric] by simp + then have "q \ step_symb_set (nfa'.step_eps_closure_set R bs - {qf'}) \ delta {qf'} bs" + using step_symb_set_mono[of "{qf'}" "step_eps_closure_set {qf'} bs", + OF step_eps_closure_set_refl, unfolded NFA.delta_def[symmetric]] + delta_step_symb_set_absorb by blast + then show "q \ nfa'.delta R bs \ delta {qf'} bs" + unfolding NFA.delta_def + using nfa'.step_eps_closure_set_closed[OF assms(1), unfolded NFA.Q_def] + step_symb_set_cong_SQ[of "nfa'.step_eps_closure_set R bs - {qf'}"] + step_symb_set_mono by blast +next + fix q + assume "q \ nfa'.delta R bs \ delta {qf'} bs" + then show "q \ delta R bs" + using nfa'_delta_sub_delta[OF assms(1)] delta_sub_eps_mono[of "{qf'}" _ _ R bs] + assms(2)[unfolded NFA.accept_eps_def] nfa'_step_eps_closure_set_sub[OF assms(1)] + by fastforce +qed + +lemma run_cong: + assumes "R \ nfa'.Q" + shows "run R bss = nfa'.run R bss \ (\(css, css') \ list_split bss. + if nfa'.run_accept_eps R css (hd css') then run {qf'} css' else {})" + using assms +proof (induction bss arbitrary: R rule: list_split.induct) + case 1 + then show ?case + using run_Nil by simp +next + case (2 x xs) + show ?case + apply (cases "nfa'.accept_eps R x") + unfolding run_Cons delta_cong_reach[OF 2(2)] + delta_cong_unreach[OF 2(2)] run_split run_accept_eps_Nil run_accept_eps_Cons + list_split_unfold[of "\ys zs. if nfa'.run_accept_eps R ys (hd zs) + then run {qf'} zs else {}" x xs] using 2(1)[of "nfa'.delta R x", + OF nfa'.delta_closed, unfolded run_accept_eps_Nil] by auto +qed + +lemma run_cong_Cons_sub: + assumes "R \ nfa'.Q" "delta {qf'} bs \ nfa'.delta R bs" + shows "run R (bs # bss) = nfa'.run R (bs # bss) \ + (\(css, css') \ list_split bss. + if nfa'.run_accept_eps (nfa'.delta R bs) css (hd css') then run {qf'} css' else {})" + unfolding run_Cons using run_cong[OF nfa'.delta_closed] + delta_cong_reach[OF assms(1)] delta_cong_unreach[OF assms(1)] + by (cases "nfa'.accept_eps R bs") (auto simp add: Un_absorb2[OF assms(2)]) + +lemma accept_eps_nfa'_run: + assumes "R \ nfa'.Q" + shows "accept_eps (nfa'.run R bss) bs \ + nfa'.accept_eps (nfa'.run R bss) bs \ accept_eps (run {qf'} []) bs" + unfolding NFA.accept_eps_def run_Nil + using step_eps_closure_set_cong_reach[OF nfa'.run_closed[OF assms]] + step_eps_closure_set_cong_unreach[OF nfa'.run_closed[OF assms]] qf_not_in_SQ + qf'_in_SQ nfa'.step_eps_closure_set_closed[OF nfa'.run_closed[OF assms], + unfolded NFA.Q_def] SQ_sub + by (cases "qf' \ nfa'.step_eps_closure_set (nfa'.run R bss) bs") fastforce+ + +lemma run_accept_eps_cong: + assumes "R \ nfa'.Q" + shows "run_accept_eps R bss bs \ (nfa'.run_accept_eps R bss bs \ run_accept_eps {qf'} [] bs) \ + (\(css, css') \ list_split bss. nfa'.run_accept_eps R css (hd css') \ + run_accept_eps {qf'} css' bs)" + unfolding NFA.run_accept_eps_def run_cong[OF assms] accept_eps_split + accept_eps_Un accept_eps_nfa'_run[OF assms] + using accept_eps_empty by (auto split: if_splits)+ + +lemma run_accept_eps_cong_Cons_sub: + assumes "R \ nfa'.Q" "delta {qf'} bs \ nfa'.delta R bs" + shows "run_accept_eps R (bs # bss) cs \ + (nfa'.run_accept_eps R (bs # bss) cs \ run_accept_eps {qf'} [] cs) \ + (\(css, css') \ list_split bss. nfa'.run_accept_eps (nfa'.delta R bs) css (hd css') \ + run_accept_eps {qf'} css' cs)" + unfolding NFA.run_accept_eps_def run_cong_Cons_sub[OF assms] + accept_eps_split accept_eps_Un accept_eps_nfa'_run[OF assms(1)] + using accept_eps_empty by (auto split: if_splits)+ + +lemmas run_accept_eps_cong_Cons_sub_simp = + run_accept_eps_cong_Cons_sub[unfolded list_split_def, simplified, + unfolded run_accept_eps_Cons[symmetric] take_Suc_Cons[symmetric]] + +end + +locale nfa_cong_Plus = nfa_cong q0 q0' qf qf' transs transs' + + right: nfa_cong q0 q0'' qf qf'' transs transs'' + for q0 q0' q0'' qf qf' qf'' transs transs' transs'' + + assumes step_eps_q0: "step_eps bs q0 q \ q \ {q0', q0''}" and + step_symb_q0: "\step_symb q0 q" +begin + +lemma step_symb_set_q0: "step_symb_set {q0} = {}" + unfolding NFA.step_symb_set_def using step_symb_q0 by simp + +lemma qf_not_q0: "qf \ {q0}" + using qf_not_in_SQ q0_sub_SQ by auto + +lemma step_eps_closure_set_q0: "step_eps_closure_set {q0} bs = {q0} \ + (nfa'.step_eps_closure_set {q0'} bs \ right.nfa'.step_eps_closure_set {q0''} bs)" + using step_eps_closure_set_unfold[OF step_eps_q0] + insert_is_Un[of q0' "{q0''}"] + step_eps_closure_set_split[of _ _ "{q0'}" "{q0''}"] + step_eps_closure_set_cong[OF nfa'.q0_sub_Q] + right.step_eps_closure_set_cong[OF right.nfa'.q0_sub_Q] + by auto + +lemmas run_accept_eps_Nil_cong = + run_accept_eps_Nil_eps_split[OF step_eps_closure_set_q0 step_symb_set_q0 qf_not_q0, + unfolded run_accept_eps_split + run_accept_eps_cong[OF nfa'.step_eps_closure_set_closed[OF nfa'.q0_sub_Q]] + right.run_accept_eps_cong[OF right.nfa'.step_eps_closure_set_closed[OF right.nfa'.q0_sub_Q]] + run_accept_eps_Nil_eps] + +lemmas run_accept_eps_Cons_cong = + run_accept_eps_Cons_eps_split[OF step_eps_closure_set_q0 step_symb_set_q0 qf_not_q0, + unfolded run_accept_eps_split + run_accept_eps_cong[OF nfa'.step_eps_closure_set_closed[OF nfa'.q0_sub_Q]] + right.run_accept_eps_cong[OF right.nfa'.step_eps_closure_set_closed[OF right.nfa'.q0_sub_Q]] + run_accept_eps_Cons_eps] + +lemma run_accept_eps_cong: "run_accept_eps {q0} bss bs \ + (nfa'.run_accept_eps {q0'} bss bs \ right.nfa'.run_accept_eps {q0''} bss bs)" + using run_accept_eps_Nil_cong run_accept_eps_Cons_cong by (cases bss) auto + +end + +locale nfa_cong_Times = nfa_cong' q0 q0 qf q0' transs transs' + + right: nfa_cong q0 q0' qf qf transs transs'' + for q0 q0' qf transs transs' transs'' +begin + +lemmas run_accept_eps_cong = + run_accept_eps_cong[OF nfa'.q0_sub_Q, unfolded + right.run_accept_eps_cong[OF right.nfa'.q0_sub_Q], unfolded list_split_def, simplified] + +end + +locale nfa_cong_Star = nfa_cong' q0 q0' qf q0 transs transs' + for q0 q0' qf transs transs' + + assumes step_eps_q0: "step_eps bs q0 q \ q \ {q0', qf}" and + step_symb_q0: "\step_symb q0 q" +begin + +lemma step_symb_set_q0: "step_symb_set {q0} = {}" + unfolding NFA.step_symb_set_def using step_symb_q0 by simp + +lemma run_accept_eps_Nil: "run_accept_eps {q0} [] bs" + unfolding NFA.run_accept_eps_def NFA.run_def using step_eps_accept_eps step_eps_q0 by fastforce + +lemma rtranclp_step_eps_q0_q0': "(step_eps bs)\<^sup>*\<^sup>* q q' \ q = q0 \ + q' \ {q0, qf} \ (q' \ nfa'.SQ \ (nfa'.step_eps bs)\<^sup>*\<^sup>* q0' q')" + apply (induction q q' rule: rtranclp.induct) + using step_eps_q0 step_eps_dest qf_not_in_SQ step_eps_cong_SQ nfa'.q0_sub_SQ + nfa'.step_eps_closed[unfolded NFA.Q_def] by fastforce+ + +lemma step_eps_closure_set_q0: "step_eps_closure_set {q0} bs \ {q0, qf} \ + (nfa'.step_eps_closure_set {q0'} bs \ nfa'.SQ)" + unfolding NFA.step_eps_closure_set_def NFA.step_eps_closure_def + using rtranclp_step_eps_q0_q0' by auto + +lemma delta_sub_nfa'_delta: "delta {q0} bs \ nfa'.delta {q0'} bs" + unfolding NFA.delta_def + using step_symb_set_mono[OF step_eps_closure_set_q0, unfolded step_symb_set_q0 + step_symb_set_qf step_symb_set_split insert_is_Un[of q0 "{qf}"]] + step_symb_set_cong_SQ + by (metis boolean_algebra_cancel.sup0 inf_le2 step_symb_set_proj step_symb_set_q0 + step_symb_set_qf sup_commute) + +lemma step_eps_closure_set_q0_split: "step_eps_closure_set {q0} bs = {q0, qf} \ + step_eps_closure_set {q0'} bs" + unfolding NFA.step_eps_closure_set_def NFA.step_eps_closure_def + using step_eps_qf step_eps_q0 + apply (auto) + apply (metis rtranclp_unfold) + by (metis r_into_rtranclp rtranclp.rtrancl_into_rtrancl rtranclp_idemp) + +lemma delta_q0_q0': "delta {q0} bs = delta {q0'} bs" + unfolding NFA.delta_def step_eps_closure_set_q0_split step_symb_set_split + unfolding NFA.delta_def[symmetric] + unfolding NFA.step_symb_set_def + using step_symb_q0 step_symb_dest qf_not_in_SQ + by fastforce + +lemmas run_accept_eps_cong_Cons = + run_accept_eps_cong_Cons_sub_simp[OF nfa'.q0_sub_Q delta_sub_nfa'_delta, + unfolded run_accept_eps_Cons_delta_cong[OF delta_q0_q0', symmetric]] + +end + +end diff --git a/thys/VYDRA_MDL/Preliminaries.thy b/thys/VYDRA_MDL/Preliminaries.thy new file mode 100644 --- /dev/null +++ b/thys/VYDRA_MDL/Preliminaries.thy @@ -0,0 +1,123 @@ +theory Preliminaries + imports MDL +begin + +section \Formulas and Satisfiability\ + +declare [[typedef_overloaded]] + +context +begin + +qualified datatype ('a, 't :: timestamp) formula = Bool bool | Atom 'a | Neg "('a, 't) formula" | + Bin "bool \ bool \ bool" "('a, 't) formula" "('a, 't) formula" | + Prev "'t \" "('a, 't) formula" | Next "'t \" "('a, 't) formula" | + Since "('a, 't) formula" "'t \" "('a, 't) formula" | + Until "('a, 't) formula" "'t \" "('a, 't) formula" | + MatchP "'t \" "('a, 't) regex" | MatchF "'t \" "('a, 't) regex" + and ('a, 't) regex = Test "('a, 't) formula" | Wild | + Plus "('a, 't) regex" "('a, 't) regex" | Times "('a, 't) regex" "('a, 't) regex" | + Star "('a, 't) regex" + +end + +fun mdl2mdl :: "('a, 't :: timestamp) Preliminaries.formula \ ('a, 't) formula" + and embed :: "('a, 't) Preliminaries.regex \ ('a, 't) regex" where + "mdl2mdl (Preliminaries.Bool b) = Bool b" +| "mdl2mdl (Preliminaries.Atom a) = Atom a" +| "mdl2mdl (Preliminaries.Neg phi) = Neg (mdl2mdl phi)" +| "mdl2mdl (Preliminaries.Bin f phi psi) = Bin f (mdl2mdl phi) (mdl2mdl psi)" +| "mdl2mdl (Preliminaries.Prev I phi) = Prev I (mdl2mdl phi)" +| "mdl2mdl (Preliminaries.Next I phi) = Next I (mdl2mdl phi)" +| "mdl2mdl (Preliminaries.Since phi I psi) = Since (mdl2mdl phi) I (mdl2mdl psi)" +| "mdl2mdl (Preliminaries.Until phi I psi) = Until (mdl2mdl phi) I (mdl2mdl psi)" +| "mdl2mdl (Preliminaries.MatchP I r) = MatchP I (Times (embed r) (Symbol (Bool True)))" +| "mdl2mdl (Preliminaries.MatchF I r) = MatchF I (Times (embed r) (Symbol (Bool True)))" +| "embed (Preliminaries.Test phi) = Lookahead (mdl2mdl phi)" +| "embed Preliminaries.Wild = Symbol (Bool True)" +| "embed (Preliminaries.Plus r s) = Plus (embed r) (embed s)" +| "embed (Preliminaries.Times r s) = Times (embed r) (embed s)" +| "embed (Preliminaries.Star r) = Star (embed r)" + +lemma mdl2mdl_wf: + fixes phi :: "('a, 't :: timestamp) Preliminaries.formula" + shows "wf_fmla (mdl2mdl phi)" + by (induction phi rule: mdl2mdl_embed.induct(1)[where ?Q="\r. wf_regex (Times (embed r) (Symbol (Bool True))) \ (\phi \ atms (embed r). wf_fmla phi)"]) auto + +fun embed' :: "(('a, 't :: timestamp) formula \ ('a, 't) Preliminaries.formula) \ ('a, 't) regex \ ('a, 't) Preliminaries.regex" where + "embed' f (Lookahead phi) = Preliminaries.Test (f phi)" +| "embed' f (Symbol phi) = Preliminaries.Times (Preliminaries.Test (f phi)) Preliminaries.Wild" +| "embed' f (Plus r s) = Preliminaries.Plus (embed' f r) (embed' f s)" +| "embed' f (Times r s) = Preliminaries.Times (embed' f r) (embed' f s)" +| "embed' f (Star r) = Preliminaries.Star (embed' f r)" + +lemma embed'_cong[fundef_cong]: "(\phi. phi \ atms r \ f phi = f' phi) \ embed' f r = embed' f' r" + by (induction r) auto + +fun mdl2mdl' :: "('a, 't :: timestamp) formula \ ('a, 't) Preliminaries.formula" where + "mdl2mdl' (Bool b) = Preliminaries.Bool b" +| "mdl2mdl' (Atom a) = Preliminaries.Atom a" +| "mdl2mdl' (Neg phi) = Preliminaries.Neg (mdl2mdl' phi)" +| "mdl2mdl' (Bin f phi psi) = Preliminaries.Bin f (mdl2mdl' phi) (mdl2mdl' psi)" +| "mdl2mdl' (Prev I phi) = Preliminaries.Prev I (mdl2mdl' phi)" +| "mdl2mdl' (Next I phi) = Preliminaries.Next I (mdl2mdl' phi)" +| "mdl2mdl' (Since phi I psi) = Preliminaries.Since (mdl2mdl' phi) I (mdl2mdl' psi)" +| "mdl2mdl' (Until phi I psi) = Preliminaries.Until (mdl2mdl' phi) I (mdl2mdl' psi)" +| "mdl2mdl' (MatchP I r) = Preliminaries.MatchP I (embed' mdl2mdl' (rderive r))" +| "mdl2mdl' (MatchF I r) = Preliminaries.MatchF I (embed' mdl2mdl' (rderive r))" + +context MDL +begin + +fun rvsat :: "('a, 't) Preliminaries.formula \ nat \ bool" + and rvmatch :: "('a, 't) Preliminaries.regex \ (nat \ nat) set" where + "rvsat (Preliminaries.Bool b) i = b" +| "rvsat (Preliminaries.Atom a) i = (a \ \ \ i)" +| "rvsat (Preliminaries.Neg \) i = (\ rvsat \ i)" +| "rvsat (Preliminaries.Bin f \ \) i = (f (rvsat \ i) (rvsat \ i))" +| "rvsat (Preliminaries.Prev I \) i = (case i of 0 \ False | Suc j \ mem (\ \ j) (\ \ i) I \ rvsat \ j)" +| "rvsat (Preliminaries.Next I \) i = (mem (\ \ i) (\ \ (Suc i)) I \ rvsat \ (Suc i))" +| "rvsat (Preliminaries.Since \ I \) i = (\j\i. mem (\ \ j) (\ \ i) I \ rvsat \ j \ (\k \ {j<..i}. rvsat \ k))" +| "rvsat (Preliminaries.Until \ I \) i = (\j\i. mem (\ \ i) (\ \ j) I \ rvsat \ j \ (\k \ {i.. k))" +| "rvsat (Preliminaries.MatchP I r) i = (\j\i. mem (\ \ j) (\ \ i) I \ (j, i) \ rvmatch r)" +| "rvsat (Preliminaries.MatchF I r) i = (\j\i. mem (\ \ i) (\ \ j) I \ (i, j) \ rvmatch r)" +| "rvmatch (Preliminaries.Test \) = {(i, i) | i. rvsat \ i}" +| "rvmatch Preliminaries.Wild = {(i, i + 1) | i. True}" +| "rvmatch (Preliminaries.Plus r s) = rvmatch r \ rvmatch s" +| "rvmatch (Preliminaries.Times r s) = rvmatch r O rvmatch s" +| "rvmatch (Preliminaries.Star r) = rtrancl (rvmatch r)" + +lemma mdl2mdl_equivalent: + fixes phi :: "('a, 't :: timestamp) Preliminaries.formula" + shows "\i. sat (mdl2mdl phi) i \ rvsat phi i" + by (induction phi rule: mdl2mdl_embed.induct(1)[where ?Q="\r. match (embed r) = rvmatch r"]) (auto split: nat.splits) + +lemma mdlstar2mdl: + fixes phi :: "('a, 't :: timestamp) Preliminaries.formula" + shows "wf_fmla (mdl2mdl phi)" "\i. sat (mdl2mdl phi) i \ rvsat phi i" + apply (rule mdl2mdl_wf) + apply (rule mdl2mdl_equivalent) + done + +lemma rvmatch_embed': + assumes "\phi i. phi \ atms r \ rvsat (mdl2mdl' phi) i \ sat phi i" + shows "rvmatch (embed' mdl2mdl' r) = match r" + using assms + by (induction r) auto + +lemma mdl2mdlstar: + fixes phi :: "('a, 't :: timestamp) formula" + assumes "wf_fmla phi" + shows "\i. rvsat (mdl2mdl' phi) i \ sat phi i" + using assms + apply (induction phi rule: mdl2mdl'.induct) + apply (auto split: nat.splits)[8] + subgoal for I r i + by auto (metis atms_rderive match_rderive rvmatch_embed' wf_fmla.simps(1))+ + subgoal for I r i + by auto (metis atms_rderive match_rderive rvmatch_embed' wf_fmla.simps(1))+ + done + +end + +end diff --git a/thys/VYDRA_MDL/ROOT b/thys/VYDRA_MDL/ROOT new file mode 100644 --- /dev/null +++ b/thys/VYDRA_MDL/ROOT @@ -0,0 +1,23 @@ +chapter AFP + +session VYDRA_MDL (AFP) = Containers + + options [timeout=600] + theories + Interval + MDL + Monitor_Code + Monitor + NFA + Preliminaries + Temporal + Timestamp_Lex + Timestamp_Lex_Total + Timestamp_Prod + Timestamp + Trace + Window + document_files + "root.tex" + "root.bib" +export_files (in ".") [2] + "VYDRA_MDL.Monitor_Code:code/**" diff --git a/thys/VYDRA_MDL/Temporal.thy b/thys/VYDRA_MDL/Temporal.thy new file mode 100644 --- /dev/null +++ b/thys/VYDRA_MDL/Temporal.thy @@ -0,0 +1,2012 @@ +theory Temporal + imports MDL NFA Window +begin + +fun state_cnt :: "('a, 'b :: timestamp) regex \ nat" where + "state_cnt (Lookahead phi) = 1" +| "state_cnt (Symbol phi) = 2" +| "state_cnt (Plus r s) = 1 + state_cnt r + state_cnt s" +| "state_cnt (Times r s) = state_cnt r + state_cnt s" +| "state_cnt (Star r) = 1 + state_cnt r" + +lemma state_cnt_pos: "state_cnt r > 0" + by (induction r rule: state_cnt.induct) auto + +fun collect_subfmlas :: "('a, 'b :: timestamp) regex \ ('a, 'b) formula list \ + ('a, 'b) formula list" where + "collect_subfmlas (Lookahead \) phis = (if \ \ set phis then phis else phis @ [\])" +| "collect_subfmlas (Symbol \) phis = (if \ \ set phis then phis else phis @ [\])" +| "collect_subfmlas (Plus r s) phis = collect_subfmlas s (collect_subfmlas r phis)" +| "collect_subfmlas (Times r s) phis = collect_subfmlas s (collect_subfmlas r phis)" +| "collect_subfmlas (Star r) phis = collect_subfmlas r phis" + +lemma bf_collect_subfmlas: "bounded_future_regex r \ phi \ set (collect_subfmlas r phis) \ + phi \ set phis \ bounded_future_fmla phi" + by (induction r phis rule: collect_subfmlas.induct) (auto split: if_splits) + +lemma collect_subfmlas_atms: "set (collect_subfmlas r phis) = set phis \ atms r" + by (induction r phis rule: collect_subfmlas.induct) (auto split: if_splits) + +lemma collect_subfmlas_set: "set (collect_subfmlas r phis) = set (collect_subfmlas r []) \ set phis" +proof (induction r arbitrary: phis) + case (Plus r1 r2) + show ?case + using Plus(1)[of phis] Plus(2)[of "collect_subfmlas r1 phis"] + Plus(2)[of "collect_subfmlas r1 []"] + by auto +next + case (Times r1 r2) + show ?case + using Times(1)[of phis] Times(2)[of "collect_subfmlas r1 phis"] + Times(2)[of "collect_subfmlas r1 []"] + by auto +next + case (Star r) + show ?case + using Star[of phis] + by auto +qed auto + +lemma collect_subfmlas_size: "x \ set (collect_subfmlas r []) \ size x < size r" +proof (induction r) + case (Plus r1 r2) + then show ?case + by (auto simp: collect_subfmlas_set[of r2 "collect_subfmlas r1 []"]) +next + case (Times r1 r2) + then show ?case + by (auto simp: collect_subfmlas_set[of r2 "collect_subfmlas r1 []"]) +next + case (Star r) + then show ?case + by fastforce +qed (auto split: if_splits) + +lemma collect_subfmlas_app: "\phis'. collect_subfmlas r phis = phis @ phis'" + by (induction r phis rule: collect_subfmlas.induct) auto + +lemma length_collect_subfmlas: "length (collect_subfmlas r phis) \ length phis" + by (induction r phis rule: collect_subfmlas.induct) auto + +fun pos :: "'a \ 'a list \ nat option" where + "pos a [] = None" +| "pos a (x # xs) = + (if a = x then Some 0 else (case pos a xs of Some n \ Some (Suc n) | _ \ None))" + +lemma pos_sound: "pos a xs = Some i \ i < length xs \ xs ! i = a" + by (induction a xs arbitrary: i rule: pos.induct) (auto split: if_splits option.splits) + +lemma pos_complete: "pos a xs = None \ a \ set xs" + by (induction a xs rule: pos.induct) (auto split: if_splits option.splits) + +fun build_nfa_impl :: "('a, 'b :: timestamp) regex \ (state \ state \ ('a, 'b) formula list) \ + transition list" where + "build_nfa_impl (Lookahead \) (q0, qf, phis) = (case pos \ phis of + Some n \ [eps_trans qf n] + | None \ [eps_trans qf (length phis)])" +| "build_nfa_impl (Symbol \) (q0, qf, phis) = (case pos \ phis of + Some n \ [eps_trans (Suc q0) n, symb_trans qf] + | None \ [eps_trans (Suc q0) (length phis), symb_trans qf])" +| "build_nfa_impl (Plus r s) (q0, qf, phis) = ( + let ts_r = build_nfa_impl r (q0 + 1, qf, phis); + ts_s = build_nfa_impl s (q0 + 1 + state_cnt r, qf, collect_subfmlas r phis) in + split_trans (q0 + 1) (q0 + 1 + state_cnt r) # ts_r @ ts_s)" +| "build_nfa_impl (Times r s) (q0, qf, phis) = ( + let ts_r = build_nfa_impl r (q0, q0 + state_cnt r, phis); + ts_s = build_nfa_impl s (q0 + state_cnt r, qf, collect_subfmlas r phis) in + ts_r @ ts_s)" +| "build_nfa_impl (Star r) (q0, qf, phis) = ( + let ts_r = build_nfa_impl r (q0 + 1, q0, phis) in + split_trans (q0 + 1) qf # ts_r)" + +lemma build_nfa_impl_state_cnt: "length (build_nfa_impl r (q0, qf, phis)) = state_cnt r" + by (induction r "(q0, qf, phis)" arbitrary: q0 qf phis rule: build_nfa_impl.induct) + (auto split: option.splits) + +lemma build_nfa_impl_not_Nil: "build_nfa_impl r (q0, qf, phis) \ []" + by (induction r "(q0, qf, phis)" arbitrary: q0 qf phis rule: build_nfa_impl.induct) + (auto split: option.splits) + +lemma build_nfa_impl_state_set: "t \ set (build_nfa_impl r (q0, qf, phis)) \ + state_set t \ {q0.. {qf}" + by (induction r "(q0, qf, phis)" arbitrary: q0 qf phis t rule: build_nfa_impl.induct) + (fastforce simp add: build_nfa_impl_state_cnt state_cnt_pos build_nfa_impl_not_Nil + split: option.splits)+ + +lemma build_nfa_impl_fmla_set: "t \ set (build_nfa_impl r (q0, qf, phis)) \ + n \ fmla_set t \ n < length (collect_subfmlas r phis)" +proof (induction r "(q0, qf, phis)" arbitrary: q0 qf phis t rule: build_nfa_impl.induct) + case (1 \ q0 qf phis) + then show ?case + using pos_sound pos_complete by (force split: option.splits) +next + case (2 \ q0 qf phis) + then show ?case + using pos_sound pos_complete by (force split: option.splits) +next + case (3 r s q0 qf phis) + then show ?case + using length_collect_subfmlas dual_order.strict_trans1 by fastforce +next + case (4 r s q0 qf phis) + then show ?case + using length_collect_subfmlas dual_order.strict_trans1 by fastforce +next + case (5 r q0 qf phis) + then show ?case + using length_collect_subfmlas dual_order.strict_trans1 by fastforce +qed + +context MDL +begin + +definition "IH r q0 qf phis transs bss bs i \ + let n = length (collect_subfmlas r phis) in + transs = build_nfa_impl r (q0, qf, phis) \ (\cs \ set bss. length cs \ n) \ length bs \ n \ + qf \ NFA.SQ q0 (build_nfa_impl r (q0, qf, phis)) \ + (\k < n. (bs ! k \ sat (collect_subfmlas r phis ! k) (i + length bss))) \ + (\j < length bss. \k < n. ((bss ! j) ! k \ sat (collect_subfmlas r phis ! k) (i + j)))" + +lemma nfa_correct: "IH r q0 qf phis transs bss bs i \ + NFA.run_accept_eps q0 qf transs {q0} bss bs \ (i, i + length bss) \ match r" +proof (induct r arbitrary: q0 qf phis transs bss bs i rule: regex_induct) +case (Lookahead \) + have qf_not_in_SQ: "qf \ NFA.SQ q0 transs" + using Lookahead unfolding IH_def by (auto simp: Let_def) + have qf_not_q0_Suc_q0: "qf \ {q0}" + using Lookahead unfolding IH_def + by (auto simp: NFA.SQ_def split: option.splits) + have transs_def: "transs = build_nfa_impl (Lookahead \) (q0, qf, phis)" + using Lookahead(1) + by (auto simp: Let_def IH_def) + interpret base: nfa q0 qf transs + apply unfold_locales + using build_nfa_impl_state_set build_nfa_impl_not_Nil qf_not_in_SQ + unfolding IH_def NFA.Q_def NFA.SQ_def transs_def + by (auto split: option.splits) + define n where "n \ case pos \ phis of Some n \ n | _ \ length phis" + then have collect: "n < length (collect_subfmlas (Lookahead \) phis)" + "(collect_subfmlas (Lookahead \) phis) ! n = \" + using pos_sound pos_complete by (force split: option.splits)+ + have "\cs q. base.step_eps cs q0 q \ n < length cs \ cs ! n \ q = qf" "\cs q. \base.step_eps cs qf q" + using base.q0_sub_SQ qf_not_in_SQ + by (auto simp: NFA.step_eps_def transs_def n_def split: option.splits) + then have base_eps: "base.step_eps_closure_set {q0} cs = (if n < length cs \ cs ! n then {q0, qf} else {q0})" for cs + using NFA.step_eps_closure_set_unfold[where ?X="{qf}"] + using NFA.step_eps_closure_set_step_id[where ?R="{q0}"] + using NFA.step_eps_closure_set_step_id[where ?R="{qf}"] + by auto + have base_delta: "base.delta {q0} cs = {}" for cs + unfolding NFA.delta_def NFA.step_symb_set_def base_eps + by (auto simp: NFA.step_symb_def NFA.SQ_def transs_def split: option.splits) + show ?case + proof (cases bss) + case Nil + have sat: "n < length bs \ bs ! n \ sat \ i" + using Lookahead(1) collect + by (auto simp: Let_def IH_def Nil) + show ?thesis + using qf_not_q0_Suc_q0 + unfolding NFA.run_accept_eps_def NFA.run_def NFA.accept_eps_def Nil + by (auto simp: base_eps sat) + next + case bss_def: (Cons cs css) + show ?thesis + using NFA.run_accept_eps_empty + unfolding NFA.run_accept_eps_def NFA.run_def NFA.accept_eps_def bss_def + by (auto simp: bss_def base_delta) + qed +next + case (Symbol \) + have qf_not_in_SQ: "qf \ NFA.SQ q0 transs" + using Symbol unfolding IH_def by (auto simp: Let_def) + have qf_not_q0_Suc_q0: "qf \ {q0, Suc q0}" + using Symbol unfolding IH_def + by (auto simp: NFA.SQ_def split: option.splits) + have transs_def: "transs = build_nfa_impl (Symbol \) (q0, qf, phis)" + using Symbol(1) + by (auto simp: Let_def IH_def) + interpret base: nfa q0 qf transs + apply unfold_locales + using build_nfa_impl_state_set build_nfa_impl_not_Nil qf_not_in_SQ + unfolding IH_def NFA.Q_def NFA.SQ_def transs_def + by (auto split: option.splits) + define n where "n \ case pos \ phis of Some n \ n | _ \ length phis" + then have collect: "n < length (collect_subfmlas (Symbol \) phis)" + "(collect_subfmlas (Symbol \) phis) ! n = \" + using pos_sound pos_complete by (force split: option.splits)+ + have "\cs q. base.step_eps cs q0 q \ n < length cs \ cs ! n \ q = Suc q0" "\cs q. \base.step_eps cs (Suc q0) q" + using base.q0_sub_SQ + by (auto simp: NFA.step_eps_def transs_def n_def split: option.splits) + then have base_eps: "base.step_eps_closure_set {q0} cs = (if n < length cs \ cs ! n then {q0, Suc q0} else {q0})" for cs + using NFA.step_eps_closure_set_unfold[where ?X="{Suc q0}"] + using NFA.step_eps_closure_set_step_id[where ?R="{q0}"] + using NFA.step_eps_closure_set_step_id[where ?R="{Suc q0}"] + by auto + have base_delta: "base.delta {q0} cs = (if n < length cs \ cs ! n then {qf} else {})" for cs + unfolding NFA.delta_def NFA.step_symb_set_def base_eps + by (auto simp: NFA.step_symb_def NFA.SQ_def transs_def split: option.splits) + show ?case + proof (cases bss) + case Nil + show ?thesis + using qf_not_q0_Suc_q0 + unfolding NFA.run_accept_eps_def NFA.run_def NFA.accept_eps_def Nil + by (auto simp: base_eps) + next + case bss_def: (Cons cs css) + have sat: "n < length cs \ cs ! n \ sat \ i" + using Symbol(1) collect + by (auto simp: Let_def IH_def bss_def) + show ?thesis + proof (cases css) + case Nil + show ?thesis + unfolding NFA.run_accept_eps_def NFA.run_def NFA.accept_eps_def bss_def Nil + by (auto simp: base_delta sat NFA.step_eps_closure_set_def NFA.step_eps_closure_def) + next + case css_def: (Cons ds dss) + have "base.delta {} ds = {}" "base.delta {qf} ds = {}" + using base.step_eps_closure_qf qf_not_in_SQ step_symb_dest + by (fastforce simp: NFA.delta_def NFA.step_eps_closure_set_def NFA.step_symb_set_def)+ + then show ?thesis + using NFA.run_accept_eps_empty + unfolding NFA.run_accept_eps_def NFA.run_def NFA.accept_eps_def bss_def css_def + by (auto simp: base_delta) + qed + qed +next + case (Plus r s) + obtain phis' where collect: "collect_subfmlas (Plus r s) phis = + collect_subfmlas r phis @ phis'" + using collect_subfmlas_app by auto + have qf_not_in_SQ: "qf \ NFA.SQ q0 (build_nfa_impl (Plus r s) (q0, qf, phis))" + using Plus unfolding IH_def by auto + interpret base: nfa q0 qf "build_nfa_impl (Plus r s) (q0, qf, phis)" + apply unfold_locales + using build_nfa_impl_state_set build_nfa_impl_not_Nil qf_not_in_SQ + unfolding NFA.Q_def NFA.SQ_def build_nfa_impl_state_cnt by fast+ + interpret left: nfa "q0 + 1" qf "build_nfa_impl r (q0 + 1, qf, phis)" + apply unfold_locales + using build_nfa_impl_state_set build_nfa_impl_not_Nil qf_not_in_SQ + unfolding NFA.Q_def NFA.SQ_def build_nfa_impl_state_cnt + by fastforce+ + interpret right: nfa "q0 + 1 + state_cnt r" qf + "build_nfa_impl s (q0 + 1 + state_cnt r, qf, collect_subfmlas r phis)" + apply unfold_locales + using build_nfa_impl_state_set build_nfa_impl_not_Nil qf_not_in_SQ + unfolding NFA.Q_def NFA.SQ_def build_nfa_impl_state_cnt + by fastforce+ + from Plus(3) have "IH r (q0 + 1) qf phis (build_nfa_impl r (q0 + 1, qf, phis)) bss bs i" + unfolding Let_def IH_def collect + using left.qf_not_in_SQ + by (auto simp: nth_append) + then have left_IH: "left.run_accept_eps {q0 + 1} bss bs \ + (i, i + length bss) \ match r" + using Plus(1) build_nfa_impl_state_cnt + by auto + have "IH s (q0 + 1 + state_cnt r) qf (collect_subfmlas r phis) + (build_nfa_impl s (q0 + 1 + state_cnt r, qf, collect_subfmlas r phis)) bss bs i" + using right.qf_not_in_SQ IH_def Plus + by (auto simp: Let_def) + then have right_IH: "right.run_accept_eps {q0 + 1 + state_cnt r} bss bs \ + (i, i + length bss) \ match s" + using Plus(2) build_nfa_impl_state_cnt + by auto + interpret cong: nfa_cong_Plus q0 "q0 + 1" "q0 + 1 + state_cnt r" qf qf qf + "build_nfa_impl (Plus r s) (q0, qf, phis)" "build_nfa_impl r (q0 + 1, qf, phis)" + "build_nfa_impl s (q0 + 1 + state_cnt r, qf, collect_subfmlas r phis)" + apply unfold_locales + unfolding NFA.SQ_def build_nfa_impl_state_cnt + NFA.step_eps_def NFA.step_symb_def + by (auto simp add: nth_append build_nfa_impl_state_cnt) + show ?case + using cong.run_accept_eps_cong left_IH right_IH Plus + by (auto simp: Let_def IH_def) +next + case (Times r s) + obtain phis' where collect: "collect_subfmlas (Times r s) phis = + collect_subfmlas r phis @ phis'" + using collect_subfmlas_app by auto + have transs_def: "transs = build_nfa_impl (Times r s) (q0, qf, phis)" + using Times unfolding IH_def by (auto simp: Let_def) + have qf_not_in_SQ: "qf \ NFA.SQ q0 (build_nfa_impl (Times r s) (q0, qf, phis))" + using Times unfolding IH_def by auto + interpret base: nfa q0 qf "build_nfa_impl (Times r s) (q0, qf, phis)" + apply unfold_locales + using build_nfa_impl_state_set build_nfa_impl_not_Nil qf_not_in_SQ + unfolding NFA.Q_def NFA.SQ_def build_nfa_impl_state_cnt by fast+ + interpret left: nfa "q0" "q0 + state_cnt r" "build_nfa_impl r (q0, q0 + state_cnt r, phis)" + apply unfold_locales + using build_nfa_impl_state_set build_nfa_impl_not_Nil qf_not_in_SQ + unfolding NFA.Q_def NFA.SQ_def build_nfa_impl_state_cnt + by fastforce+ + interpret right: nfa "q0 + state_cnt r" qf + "build_nfa_impl s (q0 + state_cnt r, qf, collect_subfmlas r phis)" + apply unfold_locales + using build_nfa_impl_state_set build_nfa_impl_not_Nil qf_not_in_SQ + unfolding NFA.Q_def NFA.SQ_def build_nfa_impl_state_cnt + by fastforce+ + from Times(3) have left_IH: "IH r q0 (q0 + state_cnt r) phis + (build_nfa_impl r (q0 , q0 + state_cnt r, phis)) bss bs i" + unfolding Let_def IH_def collect + using left.qf_not_in_SQ + by (auto simp: nth_append) + from Times(3) have left_IH_take: "\n. n < length bss \ + IH r q0 (q0 + state_cnt r) phis + (build_nfa_impl r (q0, q0 + state_cnt r, phis)) (take n bss) (hd (drop n bss)) i" + unfolding Let_def IH_def collect + using left.qf_not_in_SQ + apply (auto simp: nth_append min_absorb2 hd_drop_conv_nth) + apply (meson in_set_takeD le_add1 le_trans) + by (meson le_add1 le_trans nth_mem) + have left_IH_match: "left.run_accept_eps {q0} bss bs \ + (i, i + length bss) \ match r" + using Times(1) build_nfa_impl_state_cnt left_IH + by auto + have left_IH_match_take: "\n. n < length bss \ + left.run_accept_eps {q0} (take n bss) (hd (drop n bss)) \ (i, i + n) \ match r" + using Times(1) build_nfa_impl_state_cnt left_IH_take + by (fastforce simp add: nth_append min_absorb2) + have "IH s (q0 + state_cnt r) qf (collect_subfmlas r phis) + (build_nfa_impl s (q0 + state_cnt r, qf, collect_subfmlas r phis)) bss bs i" + using right.qf_not_in_SQ IH_def Times + by (auto simp: Let_def) + then have right_IH: "\n. n \ length bss \ IH s (q0 + state_cnt r) qf (collect_subfmlas r phis) + (build_nfa_impl s (q0 + state_cnt r, qf, collect_subfmlas r phis)) (drop n bss) bs (i + n)" + unfolding Let_def IH_def + by (auto simp: nth_append add.assoc) (meson in_set_dropD) + have right_IH_match: "\n. n \ length bss \ + right.run_accept_eps {q0 + state_cnt r} (drop n bss) bs \ (i + n, i + length bss) \ match s" + using Times(2)[OF right_IH] build_nfa_impl_state_cnt + by (auto simp: IH_def) + interpret cong: nfa_cong_Times q0 "q0 + state_cnt r" qf + "build_nfa_impl (Times r s) (q0, qf, phis)" + "build_nfa_impl r (q0, q0 + state_cnt r, phis)" + "build_nfa_impl s (q0 + state_cnt r, qf, collect_subfmlas r phis)" + apply unfold_locales + using NFA.Q_def NFA.SQ_def NFA.step_eps_def NFA.step_symb_def build_nfa_impl_state_set + by (fastforce simp add: nth_append build_nfa_impl_state_cnt build_nfa_impl_not_Nil + state_cnt_pos)+ + have right_IH_Nil: "right.run_accept_eps {q0 + state_cnt r} [] bs \ + (i + length bss, i + length bss) \ match s" + using right_IH_match + by fastforce + show ?case + unfolding match_Times transs_def cong.run_accept_eps_cong left_IH_match right_IH_Nil + using left_IH_match_take right_IH_match less_imp_le_nat le_eq_less_or_eq + by auto +next + case (Star r) + then show ?case + proof (induction "length bss" arbitrary: bss bs i rule: nat_less_induct) + case 1 + have transs_def: "transs = build_nfa_impl (Star r) (q0, qf, phis)" + using 1 unfolding IH_def by (auto simp: Let_def) + have qf_not_in_SQ: "qf \ NFA.SQ q0 (build_nfa_impl (Star r) (q0, qf, phis))" + using 1 unfolding IH_def by auto + interpret base: nfa q0 qf "build_nfa_impl (Star r) (q0, qf, phis)" + apply unfold_locales + using build_nfa_impl_state_set build_nfa_impl_not_Nil qf_not_in_SQ + unfolding NFA.Q_def NFA.SQ_def build_nfa_impl_state_cnt + by fast+ + interpret left: nfa "q0 + 1" q0 "build_nfa_impl r (q0 + 1, q0, phis)" + apply unfold_locales + using build_nfa_impl_state_set build_nfa_impl_not_Nil qf_not_in_SQ + unfolding NFA.Q_def NFA.SQ_def build_nfa_impl_state_cnt + by fastforce+ + from 1(3) have left_IH: "IH r (q0 + 1) q0 phis (build_nfa_impl r (q0 + 1, q0, phis)) bss bs i" + using left.qf_not_in_SQ + unfolding Let_def IH_def + by (auto simp add: nth_append) + from 1(3) have left_IH_take: "\n. n < length bss \ + IH r (q0 + 1) q0 phis (build_nfa_impl r (q0 + 1, q0, phis)) (take n bss) (hd (drop n bss)) i" + using left.qf_not_in_SQ + unfolding Let_def IH_def + by (auto simp add: nth_append min_absorb2 hd_drop_conv_nth) (meson in_set_takeD) + have left_IH_match: "left.run_accept_eps {q0 + 1} bss bs \ + (i, i + length bss) \ match r" + using 1(2) left_IH + unfolding build_nfa_impl_state_cnt NFA.SQ_def + by auto + have left_IH_match_take: "\n. n < length bss \ + left.run_accept_eps {q0 + 1} (take n bss) (hd (drop n bss)) \ + (i, i + n) \ match r" + using 1(2) left_IH_take + unfolding build_nfa_impl_state_cnt NFA.SQ_def + by (fastforce simp add: nth_append min_absorb2) + interpret cong: nfa_cong_Star q0 "q0 + 1" qf + "build_nfa_impl (Star r) (q0, qf, phis)" + "build_nfa_impl r (q0 + 1, q0, phis)" + apply unfold_locales + unfolding NFA.SQ_def build_nfa_impl_state_cnt NFA.step_eps_def NFA.step_symb_def + by (auto simp add: nth_append build_nfa_impl_state_cnt) + show ?case + using cong.run_accept_eps_Nil + proof (cases bss) + case Nil + show ?thesis + unfolding transs_def Nil + using cong.run_accept_eps_Nil run_Nil run_accept_eps_Nil + by auto + next + case (Cons cs css) + have aux: "\n j x P. n < x \ j < x - n \ (\j < Suc x. P j) \ P (Suc (n + j))" + by auto + from 1(3) have star_IH: "\n. n < length css \ + IH (Star r) q0 qf phis transs (drop n css) bs (i + n + 1)" + unfolding Cons Let_def IH_def + using aux[of _ _ _ "\j. \kxs i. length xs \ length css \ IH (Star r) q0 qf phis transs xs bs i \ + (base.run_accept_eps {q0} xs bs \ (i, i + length xs) \ match (Star r))" + using 1 + unfolding Cons + by (auto simp add: nth_append less_Suc_eq_le transs_def) + have "\n. n < length css \ base.run_accept_eps {q0} (drop n css) bs \ + (i + n + 1, i + length (cs # css)) \ match (Star r)" + proof - + fix n + assume assm: "n < length css" + then show "base.run_accept_eps {q0} (drop n css) bs \ + (i + n + 1, i + length (cs # css)) \ match (Star r)" + using IH_inst[of "drop n css" "i + n + 1"] star_IH + by (auto simp add: nth_append) + qed + then show ?thesis + using match_Star length_Cons Cons cong.run_accept_eps_cong_Cons + using cong.run_accept_eps_Nil left_IH_match left_IH_match_take + apply (auto simp add: Cons transs_def) + apply (metis Suc_less_eq add_Suc_right drop_Suc_Cons less_imp_le_nat take_Suc_Cons) + apply (metis Suc_less_eq add_Suc_right drop_Suc_Cons le_eq_less_or_eq lessThan_iff + take_Suc_Cons) + done + qed + qed +qed + +lemma step_eps_closure_set_empty_list: + assumes "wf_regex r" "IH r q0 qf phis transs bss bs i" "NFA.step_eps_closure q0 transs bs q qf" + shows "NFA.step_eps_closure q0 transs [] q qf" + using assms +proof (induction r arbitrary: q0 qf phis transs q) + case (Symbol \) + have qf_not_in_SQ: "qf \ NFA.SQ q0 transs" + using Symbol unfolding IH_def by (auto simp: Let_def) + have qf_not_q0_Suc_q0: "qf \ {q0, Suc q0}" + using Symbol unfolding IH_def + by (auto simp: NFA.SQ_def split: option.splits) + have transs_def: "transs = build_nfa_impl (Symbol \) (q0, qf, phis)" + using Symbol(2) + by (auto simp: Let_def IH_def) + interpret base: nfa q0 qf transs + apply unfold_locales + using build_nfa_impl_state_set build_nfa_impl_not_Nil qf_not_in_SQ + unfolding IH_def NFA.Q_def NFA.SQ_def transs_def + by (auto split: option.splits) + define n where "n \ case pos \ phis of Some n \ n | _ \ length phis" + then have collect: "n < length (collect_subfmlas (Symbol \) phis)" + "(collect_subfmlas (Symbol \) phis) ! n = \" + using pos_sound pos_complete by (force split: option.splits)+ + have SQD: "q \ NFA.SQ q0 transs \ q = q0 \ q = Suc q0" for q + by (auto simp: NFA.SQ_def transs_def split: option.splits) + have "\base.step_eps cs q qf" if "q \ NFA.SQ q0 transs" for cs q + using SQD[OF that] qf_not_q0_Suc_q0 + by (auto simp: NFA.step_eps_def transs_def split: option.splits transition.splits) + then show ?case + using Symbol(3) + by (auto simp: NFA.step_eps_closure_def) (metis rtranclp.simps step_eps_dest) +next + case (Plus r s) + have transs_def: "transs = build_nfa_impl (Plus r s) (q0, qf, phis)" + using Plus(4) + by (auto simp: IH_def Let_def) + define ts_l where "ts_l = build_nfa_impl r (q0 + 1, qf, phis)" + define ts_r where "ts_r = build_nfa_impl s (q0 + 1 + state_cnt r, qf, collect_subfmlas r phis)" + have len_ts: "length ts_l = state_cnt r" "length ts_r = state_cnt s" "length transs = Suc (state_cnt r + state_cnt s)" + by (auto simp: ts_l_def ts_r_def transs_def build_nfa_impl_state_cnt) + have transs_eq: "transs = split_trans (q0 + 1) (q0 + 1 + state_cnt r) # ts_l @ ts_r" + by (auto simp: transs_def ts_l_def ts_r_def) + have ts_nonempty: "ts_l = [] \ False" "ts_r = [] \ False" + by (auto simp: ts_l_def ts_r_def build_nfa_impl_not_Nil) + obtain phis' where collect: "collect_subfmlas (Plus r s) phis = collect_subfmlas r phis @ phis'" + using collect_subfmlas_app by auto + have qf_not_in_SQ: "qf \ NFA.SQ q0 (build_nfa_impl (Plus r s) (q0, qf, phis))" + using Plus unfolding IH_def by auto + interpret base: nfa q0 qf transs + apply unfold_locales + using build_nfa_impl_state_set build_nfa_impl_not_Nil qf_not_in_SQ + unfolding NFA.Q_def NFA.SQ_def build_nfa_impl_state_cnt transs_def by fast+ + interpret left: nfa "Suc q0" qf ts_l + apply unfold_locales + using build_nfa_impl_state_set build_nfa_impl_not_Nil qf_not_in_SQ + unfolding NFA.Q_def NFA.SQ_def build_nfa_impl_state_cnt ts_l_def + by fastforce+ + interpret right: nfa "Suc (q0 + state_cnt r)" qf ts_r + apply unfold_locales + using build_nfa_impl_state_set build_nfa_impl_not_Nil qf_not_in_SQ + unfolding NFA.Q_def NFA.SQ_def build_nfa_impl_state_cnt ts_r_def + by fastforce+ + interpret cong: nfa_cong_Plus q0 "Suc q0" "Suc (q0 + state_cnt r)" qf qf qf transs ts_l ts_r + apply unfold_locales + unfolding NFA.SQ_def build_nfa_impl_state_cnt + NFA.step_eps_def NFA.step_symb_def transs_def ts_l_def ts_r_def + by (auto simp add: nth_append build_nfa_impl_state_cnt) + have "IH s (Suc (q0 + state_cnt r)) qf (collect_subfmlas r phis) ts_r bss bs i" + using right.qf_not_in_SQ IH_def Plus + by (auto simp: Let_def ts_r_def) + then have case_right: "base.step_eps_closure [] q qf" if "base.step_eps_closure bs q qf" "q \ right.Q" for q + using cong.right.eps_nfa'_step_eps_closure[OF that] Plus(2,3) cong.right.nfa'_eps_step_eps_closure[OF _ that(2)] + by auto + from Plus(4) have "IH r (Suc q0) qf phis ts_l bss bs i" + using left.qf_not_in_SQ + unfolding Let_def IH_def collect ts_l_def + by (auto simp: nth_append) + then have case_left: "base.step_eps_closure [] q qf" if "base.step_eps_closure bs q qf" "q \ left.Q" for q + using cong.eps_nfa'_step_eps_closure[OF that] Plus(1,3) cong.nfa'_eps_step_eps_closure[OF _ that(2)] + by auto + have "q = q0 \ q \ left.Q \ q \ right.Q" + using Plus(5) + by (auto simp: NFA.Q_def NFA.SQ_def len_ts dest!: NFA.step_eps_closure_dest) + moreover have ?case if q_q0: "q = q0" + proof - + have "q0 \ qf" + using qf_not_in_SQ + by (auto simp: NFA.SQ_def) + then obtain q' where q'_def: "base.step_eps bs q q'" "base.step_eps_closure bs q' qf" + using Plus(5) + by (auto simp: q_q0 NFA.step_eps_closure_def elim: converse_rtranclpE) + have fst_step_eps: "base.step_eps [] q q'" + using q'_def(1) + by (auto simp: q_q0 NFA.step_eps_def transs_eq) + have "q' \ left.Q \ q' \ right.Q" + using q'_def(1) + by (auto simp: NFA.step_eps_def NFA.Q_def NFA.SQ_def q_q0 transs_eq dest: ts_nonempty split: transition.splits) + then show ?case + using fst_step_eps case_left[OF q'_def(2)] case_right[OF q'_def(2)] + by (auto simp: NFA.step_eps_closure_def) + qed + ultimately show ?case + using Plus(5) case_left case_right + by auto +next + case (Times r s) + obtain phis' where collect: "collect_subfmlas (Times r s) phis = + collect_subfmlas r phis @ phis'" + using collect_subfmlas_app by auto + have transs_def: "transs = build_nfa_impl (Times r s) (q0, qf, phis)" + using Times unfolding IH_def by (auto simp: Let_def) + define ts_l where "ts_l = build_nfa_impl r (q0, q0 + state_cnt r, phis)" + define ts_r where "ts_r = build_nfa_impl s (q0 + state_cnt r, qf, collect_subfmlas r phis)" + have len_ts: "length ts_l = state_cnt r" "length ts_r = state_cnt s" "length transs = state_cnt r + state_cnt s" + by (auto simp: ts_l_def ts_r_def transs_def build_nfa_impl_state_cnt) + have transs_eq: "transs = ts_l @ ts_r" + by (auto simp: transs_def ts_l_def ts_r_def) + have ts_nonempty: "ts_l = [] \ False" "ts_r = [] \ False" + by (auto simp: ts_l_def ts_r_def build_nfa_impl_not_Nil) + have qf_not_in_SQ: "qf \ NFA.SQ q0 (build_nfa_impl (Times r s) (q0, qf, phis))" + using Times unfolding IH_def by auto + interpret base: nfa q0 qf transs + apply unfold_locales + using build_nfa_impl_state_set build_nfa_impl_not_Nil qf_not_in_SQ + unfolding NFA.Q_def NFA.SQ_def build_nfa_impl_state_cnt transs_def by fast+ + interpret left: nfa "q0" "q0 + state_cnt r" ts_l + apply unfold_locales + using build_nfa_impl_state_set build_nfa_impl_not_Nil qf_not_in_SQ + unfolding NFA.Q_def NFA.SQ_def build_nfa_impl_state_cnt ts_l_def + by fastforce+ + interpret right: nfa "q0 + state_cnt r" qf ts_r + apply unfold_locales + using build_nfa_impl_state_set build_nfa_impl_not_Nil qf_not_in_SQ + unfolding NFA.Q_def NFA.SQ_def build_nfa_impl_state_cnt ts_r_def + by fastforce+ + interpret cong: nfa_cong_Times q0 "q0 + state_cnt r" qf transs ts_l ts_r + apply unfold_locales + using NFA.Q_def NFA.SQ_def NFA.step_eps_def NFA.step_symb_def build_nfa_impl_state_set + by (auto simp add: nth_append build_nfa_impl_state_cnt build_nfa_impl_not_Nil + state_cnt_pos len_ts transs_eq) + have "qf \ base.SQ" + using Times(4) + by (auto simp: IH_def Let_def) + then have qf_left_Q: "qf \ left.Q \ False" + by (auto simp: NFA.Q_def NFA.SQ_def len_ts state_cnt_pos) + have left_IH: "IH r q0 (q0 + state_cnt r) phis ts_l bss bs i" + using left.qf_not_in_SQ Times + unfolding Let_def IH_def collect + by (auto simp: nth_append ts_l_def) + have case_left: "base.step_eps_closure [] q (q0 + state_cnt r)" if "left.step_eps_closure bs q (q0 + state_cnt r)" "q \ left.Q" and wf: "wf_regex r" for q + using that(1) Times(1)[OF wf left_IH] cong.nfa'_step_eps_closure_cong[OF _ that(2)] + by auto + have left_IH: "IH s (q0 + state_cnt r) qf (collect_subfmlas r phis) ts_r bss bs i" + using right.qf_not_in_SQ IH_def Times + by (auto simp: Let_def ts_r_def) + then have case_right: "base.step_eps_closure [] q qf" if "base.step_eps_closure bs q qf" "q \ right.Q" for q + using cong.right.eps_nfa'_step_eps_closure[OF that] Times(2,3) cong.right.nfa'_eps_step_eps_closure[OF _ that(2)] + by auto + have init_right: "q0 + state_cnt r \ right.Q" + by (auto simp: NFA.Q_def NFA.SQ_def dest: ts_nonempty) + { + assume q_left_Q: "q \ left.Q" + then have split: "left.step_eps_closure bs q (q0 + state_cnt r)" "base.step_eps_closure bs (q0 + state_cnt r) qf" + using cong.eps_nfa'_step_eps_closure_cong[OF Times(5)] + by (auto dest: qf_left_Q) + have empty_IH: "IH s (q0 + state_cnt r) qf (collect_subfmlas r phis) ts_r [] bs (i + length bss)" + using left_IH + by (auto simp: IH_def Let_def ts_r_def) + have "right.step_eps_closure bs (q0 + state_cnt r) qf" + using cong.right.eps_nfa'_step_eps_closure[OF split(2) init_right] + by auto + then have "right.run_accept_eps {q0 + state_cnt r} [] bs" + by (auto simp: NFA.run_accept_eps_def NFA.accept_eps_def NFA.step_eps_closure_set_def NFA.run_def) + then have wf: "wf_regex r" + using nfa_correct[OF empty_IH] Times(3) match_refl_eps + by auto + have ?case + using case_left[OF split(1) q_left_Q wf] case_right[OF split(2) init_right] + by (auto simp: NFA.step_eps_closure_def) + } + moreover have "q \ left.Q \ q \ right.Q" + using Times(5) + by (auto simp: NFA.Q_def NFA.SQ_def transs_eq len_ts dest!: NFA.step_eps_closure_dest) + ultimately show ?case + using case_right[OF Times(5)] + by auto +next + case (Star r) + have transs_def: "transs = build_nfa_impl (Star r) (q0, qf, phis)" + using Star unfolding IH_def by (auto simp: Let_def) + obtain ts_r where ts_r: "transs = split_trans (q0 + 1) qf # ts_r" "ts_r = build_nfa_impl r (Suc q0, q0, phis)" + using Star(3) + by (auto simp: Let_def IH_def) + have qf_not_in_SQ: "qf \ NFA.SQ q0 transs" + using Star unfolding IH_def transs_def by auto + interpret base: nfa q0 qf transs + apply unfold_locales + using build_nfa_impl_state_set build_nfa_impl_not_Nil qf_not_in_SQ + unfolding NFA.Q_def NFA.SQ_def build_nfa_impl_state_cnt transs_def + by fast+ + interpret left: nfa "Suc q0" q0 ts_r + apply unfold_locales + using build_nfa_impl_state_set build_nfa_impl_not_Nil qf_not_in_SQ + unfolding NFA.Q_def NFA.SQ_def build_nfa_impl_state_cnt ts_r(2) + by fastforce+ + interpret cong: nfa_cong_Star q0 "Suc q0" qf transs ts_r + apply unfold_locales + unfolding NFA.SQ_def build_nfa_impl_state_cnt NFA.step_eps_def NFA.step_symb_def + by (auto simp add: nth_append build_nfa_impl_state_cnt ts_r(1)) + have IH: "wf_regex r" "IH r (Suc q0) q0 phis ts_r bss bs i" + using Star(2,3) + by (auto simp: Let_def IH_def NFA.SQ_def ts_r(2)) + have step_eps_q'_qf: "q' = q0" if "base.step_eps bs q' qf" for q' + proof (rule ccontr) + assume "q' \ q0" + then have "q' \ left.SQ" + using that + by (auto simp: NFA.step_eps_def NFA.SQ_def ts_r(1)) + then have "left.step_eps bs q' qf" + using cong.step_eps_cong_SQ that + by simp + then show "False" + using qf_not_in_SQ + by (metis NFA.Q_def UnE base.q0_sub_SQ cong.SQ_sub left.step_eps_closed subset_eq) + qed + show ?case + proof (cases "q = qf") + case False + then have base_q_q0: "base.step_eps_closure bs q q0" "base.step_eps bs q0 qf" + using Star(4) step_eps_q'_qf + by (auto simp: NFA.step_eps_closure_def) (metis rtranclp.cases)+ + have base_Nil_q0_qf: "base.step_eps [] q0 qf" + by (auto simp: NFA.step_eps_def NFA.SQ_def ts_r(1)) + have q_left_Q: "q \ left.Q" + using base_q_q0 + by (auto simp: NFA.Q_def NFA.SQ_def ts_r(1) dest: step_eps_closure_dest) + have "left.step_eps_closure [] q q0" + using cong.eps_nfa'_step_eps_closure_cong[OF base_q_q0(1) q_left_Q] Star(1)[OF IH] + by auto + then show ?thesis + using cong.nfa'_step_eps_closure_cong[OF _ q_left_Q] base_Nil_q0_qf + by (auto simp: NFA.step_eps_closure_def) (meson rtranclp.rtrancl_into_rtrancl) + qed (auto simp: NFA.step_eps_closure_def) +qed auto + +lemma accept_eps_iff_accept: + assumes "wf_regex r" "IH r q0 qf phis transs bss bs i" + shows "NFA.accept_eps q0 qf transs R bs = NFA.accept q0 qf transs R" + using step_eps_closure_set_empty_list[OF assms] step_eps_closure_set_mono' + unfolding NFA.accept_eps_def NFA.accept_def + by (fastforce simp: NFA.accept_eps_def NFA.accept_def NFA.step_eps_closure_set_def) + +lemma run_accept_eps_iff_run_accept: + assumes "wf_regex r" "IH r q0 qf phis transs bss bs i" + shows "NFA.run_accept_eps q0 qf transs {q0} bss bs \ NFA.run_accept q0 qf transs {q0} bss" + unfolding NFA.run_accept_eps_def NFA.run_accept_def accept_eps_iff_accept[OF assms] .. + +end + +definition pred_option' :: "('a \ bool) \ 'a option \ bool" where + "pred_option' P z = (case z of Some z' \ P z' | None \ False)" + +definition map_option' :: "('b \ 'c option) \ 'b option \ 'c option" where + "map_option' f z = (case z of Some z' \ f z' | None \ None)" + +definition while_break :: "('a \ bool) \ ('a \ 'a option) \ 'a \ 'a option" where + "while_break P f x = while (pred_option' P) (map_option' f) (Some x)" + +lemma wf_while_break: + assumes "wf {(t, s). P s \ b s \ Some t = c s}" + shows "wf {(t, s). pred_option P s \ pred_option' b s \ t = map_option' c s}" +proof - + have sub: "{(t, s). pred_option P s \ pred_option' b s \ t = map_option' c s} \ + map_prod Some Some ` {(t, s). P s \ b s \ Some t = c s} \ ({None} \ (Some ` UNIV))" + by (auto simp: pred_option'_def map_option'_def split: option.splits) + (smt (z3) case_prodI map_prod_imageI mem_Collect_eq not_Some_eq) + show ?thesis + apply (rule wf_subset[OF _ sub]) + apply (rule wf_union_compatible) + apply (rule wf_map_prod_image) + apply (fastforce simp: wf_def intro: assms)+ + done +qed + +lemma wf_while_break': + assumes "wf {(t, s). P s \ b s \ Some t = c s}" + shows "wf {(t, s). pred_option' P s \ pred_option' b s \ t = map_option' c s}" + by (rule wf_subset[OF wf_while_break[OF assms]]) (auto simp: pred_option'_def split: option.splits) + +lemma while_break_sound: + assumes "\s s'. P s \ b s \ c s = Some s' \ P s'" "\s. P s \ \ b s \ Q s" "wf {(t, s). P s \ b s \ Some t = c s}" "P s" + shows "pred_option Q (while_break b c s)" +proof - + have aux: "P t \ b t \ pred_option P (c t)" for t + using assms(1) + by (cases "c t") auto + show ?thesis + using assms aux + by (auto simp: while_break_def pred_option'_def map_option'_def split: option.splits + intro!: while_rule_lemma[where ?P="pred_option P" and ?Q="pred_option Q" and ?b="pred_option' b" and ?c="map_option' c", OF _ _ wf_while_break]) +qed + +lemma while_break_complete: "(\s. P s \ b s \ pred_option' P (c s)) \ (\s. P s \ \ b s \ Q s) \ wf {(t, s). P s \ b s \ Some t = c s} \ P s \ + pred_option' Q (while_break b c s)" + unfolding while_break_def + by (rule while_rule_lemma[where ?P="pred_option' P" and ?Q="pred_option' Q" and ?b="pred_option' b" and ?c="map_option' c", OF _ _ wf_while_break']) + (force simp: pred_option'_def map_option'_def split: option.splits elim!: case_optionE)+ + +context + fixes args :: "(bool iarray, nat set, 'd :: timestamp, 't, 'e) args" +begin + +abbreviation "reach_w \ reach_window args" + +qualified definition "in_win = init_window args" + +definition valid_window_matchP :: "'d \ \ 't \ 'e \ + ('d \ bool iarray) list \ nat \ (bool iarray, nat set, 'd, 't, 'e) window \ bool" where + "valid_window_matchP I t0 sub rho j w \ j = w_j w \ + valid_window args t0 sub rho w \ + reach_w t0 sub rho (w_i w, w_ti w, w_si w, w_j w, w_tj w, w_sj w) \ + (case w_read_t args (w_tj w) of None \ True + | Some t \ (\l < w_i w. memL (ts_at rho l) t I))" + +lemma valid_window_matchP_reach_tj: "valid_window_matchP I t0 sub rho i w \ + reaches_on (w_run_t args) t0 (map fst rho) (w_tj w)" + using reach_window_run_tj + by (fastforce simp: valid_window_matchP_def simp del: reach_window.simps) + +lemma valid_window_matchP_reach_sj: "valid_window_matchP I t0 sub rho i w \ + reaches_on (w_run_sub args) sub (map snd rho) (w_sj w)" + using reach_window_run_sj + by (fastforce simp: valid_window_matchP_def simp del: reach_window.simps) + +lemma valid_window_matchP_len_rho: "valid_window_matchP I t0 sub rho i w \ length rho = i" + by (auto simp: valid_window_matchP_def) + +definition "matchP_loop_cond I t = (\w. w_i w < w_j w \ memL (the (w_read_t args (w_ti w))) t I)" + +definition "matchP_loop_inv I t0 sub rho j0 tj0 sj0 t = + (\w. valid_window args t0 sub rho w \ + w_j w = j0 \ w_tj w = tj0 \ w_sj w = sj0 \ (\l < w_i w. memL (ts_at rho l) t I))" + +fun ex_key :: "('c, 'd) mmap \ ('d \ bool) \ + ('c \ bool) \ ('c, bool) mapping \ (bool \ ('c, bool) mapping)" where + "ex_key [] time accept ac = (False, ac)" +| "ex_key ((q, t) # qts) time accept ac = (if time t then + (case cac accept ac q of (\, ac') \ + if \ then (True, ac') else ex_key qts time accept ac') + else ex_key qts time accept ac)" + +lemma ex_key_sound: + assumes inv: "\q. case Mapping.lookup ac q of None \ True | Some v \ accept q = v" + and distinct: "distinct (map fst qts)" + and eval: "ex_key qts time accept ac = (b, ac')" + shows "b = (\q \ mmap_keys qts. time (the (mmap_lookup qts q)) \ accept q) \ + (\q. case Mapping.lookup ac' q of None \ True | Some v \ accept q = v)" + using assms +proof (induction qts arbitrary: ac) + case (Cons a qts) + obtain q t where qt_def: "a = (q, t)" + by fastforce + show ?case + proof (cases "time t") + case True + note time_t = True + obtain \ ac'' where ac''_def: "cac accept ac q = (\, ac'')" + by fastforce + have accept: "\ = accept q" "\q. case Mapping.lookup ac'' q of None \ True + | Some v \ accept q = v" + using ac''_def Cons(2) + by (fastforce simp: cac_def Let_def Mapping.lookup_update' split: option.splits if_splits)+ + show ?thesis + proof (cases \) + case True + then show ?thesis + using accept(2) time_t Cons(4) + by (auto simp: qt_def mmap_keys_def accept(1) mmap_lookup_def ac''_def) + next + case False + have ex_key: "ex_key qts time accept ac'' = (b, ac')" + using Cons(4) time_t False + by (auto simp: qt_def ac''_def) + show ?thesis + using Cons(1)[OF accept(2) _ ex_key] False[unfolded accept(1)] Cons(3) + by (auto simp: mmap_keys_def mmap_lookup_def qt_def) + qed + next + case False + have ex_key: "ex_key qts time accept ac = (b, ac')" + using Cons(4) False + by (auto simp: qt_def) + show ?thesis + using Cons(1)[OF Cons(2) _ ex_key] False Cons(3) + by (auto simp: mmap_keys_def mmap_lookup_def qt_def) + qed +qed (auto simp: mmap_keys_def) + +fun eval_matchP :: "'d \ \ (bool iarray, nat set, 'd, 't, 'e) window \ + (('d \ bool) \ (bool iarray, nat set, 'd, 't, 'e) window) option" where + "eval_matchP I w = + (case w_read_t args (w_tj w) of None \ None | Some t \ + (case adv_end args w of None \ None | Some w' \ + let w'' = while (matchP_loop_cond I t) (adv_start args) w'; + (\, ac') = ex_key (w_e w'') (\t'. memR t' t I) (w_accept args) (w_ac w'') in + Some ((t, \), w''\w_ac := ac'\)))" + +definition valid_window_matchF :: "'d \ \ 't \ 'e \ ('d \ bool iarray) list \ nat \ + (bool iarray, nat set, 'd, 't, 'e) window \ bool" where + "valid_window_matchF I t0 sub rho i w \ i = w_i w \ + valid_window args t0 sub rho w \ + reach_w t0 sub rho (w_i w, w_ti w, w_si w, w_j w, w_tj w, w_sj w) \ + (\l \ {w_i w.. + reaches_on (w_run_t args) t0 (map fst rho) (w_tj w)" + using reach_window_run_tj + by (fastforce simp: valid_window_matchF_def simp del: reach_window.simps) + +lemma valid_window_matchF_reach_sj: "valid_window_matchF I t0 sub rho i w \ + reaches_on (w_run_sub args) sub (map snd rho) (w_sj w)" + using reach_window_run_sj + by (fastforce simp: valid_window_matchF_def simp del: reach_window.simps) + +definition "matchF_loop_cond I t = + (\w. case w_read_t args (w_tj w) of None \ False | Some t' \ memR t t' I)" + +definition "matchF_loop_inv I t0 sub rho i ti si tjm sjm = + (\w. valid_window args t0 sub (take (w_j w) rho) w \ + w_i w = i \ w_ti w = ti \ w_si w = si \ + reach_window args t0 sub rho (w_j w, w_tj w, w_sj w, length rho, tjm, sjm) \ + (\l \ {w_i w..w. w_i w = i \ w_ti w = ti \ w_si w = si \ + (\rho'. valid_window args t0 sub (rho @ rho') w \ + reach_window args t0 sub (rho @ rho') (j, tj, sj, w_j w, w_tj w, w_sj w)))" + +fun eval_matchF :: "'d \ \ (bool iarray, nat set, 'd, 't, 'e) window \ + (('d \ bool) \ (bool iarray, nat set, 'd, 't, 'e) window) option" where + "eval_matchF I w = + (case w_read_t args (w_ti w) of None \ None | Some t \ + (case while_break (matchF_loop_cond I t) (adv_end args) w of None \ None | Some w' \ + (case w_read_t args (w_tj w') of None \ None | Some t' \ + let \ = (case snd (the (mmap_lookup (w_s w') {0})) of None \ False + | Some tstp \ memL t (fst tstp) I) in + Some ((t, \), adv_start args w'))))" + +end + +locale MDL_window = MDL \ + for \ :: "('a, 'd :: timestamp) trace" + + fixes r :: "('a, 'd :: timestamp) regex" + and t0 :: 't + and sub :: 'e + and args :: "(bool iarray, nat set, 'd, 't, 'e) args" + assumes init_def: "w_init args = {0 :: nat}" + and step_def: "w_step args = + NFA.delta' (IArray (build_nfa_impl r (0, state_cnt r, []))) (state_cnt r)" + and accept_def: "w_accept args = NFA.accept' (IArray (build_nfa_impl r (0, state_cnt r, []))) (state_cnt r)" + and run_t_sound: "reaches_on (w_run_t args) t0 ts t \ + w_run_t args t = Some (t', x) \ x = \ \ (length ts)" + and run_sub_sound: "reaches_on (w_run_sub args) sub bs s \ + w_run_sub args s = Some (s', b) \ + b = IArray (map (\phi. sat phi (length bs)) (collect_subfmlas r []))" + and run_t_read: "w_run_t args t = Some (t', x) \ w_read_t args t = Some x" + and read_t_run: "w_read_t args t = Some x \ \t'. w_run_t args t = Some (t', x)" +begin + +definition "qf = state_cnt r" +definition "transs = build_nfa_impl r (0, qf, [])" + +abbreviation "init \ w_init args" +abbreviation "step \ w_step args" +abbreviation "accept \ w_accept args" +abbreviation "run \ NFA.run' (IArray transs) qf" +abbreviation "wacc \ Window.acc (w_step args) (w_accept args)" +abbreviation "rw \ reach_window args" + +abbreviation "valid_matchP \ valid_window_matchP args" +abbreviation "eval_mP \ eval_matchP args" +abbreviation "matchP_inv \ matchP_loop_inv args" +abbreviation "matchP_cond \ matchP_loop_cond args" + +abbreviation "valid_matchF \ valid_window_matchF args" +abbreviation "eval_mF \ eval_matchF args" +abbreviation "matchF_inv \ matchF_loop_inv args" +abbreviation "matchF_inv' \ matchF_loop_inv' args" +abbreviation "matchF_cond \ matchF_loop_cond args" + +lemma run_t_sound': + assumes "reaches_on (w_run_t args) t0 ts t" "i < length ts" + shows "ts ! i = \ \ i" +proof - + obtain t' t'' where t'_def: "reaches_on (w_run_t args) t0 (take i ts) t'" + "w_run_t args t' = Some (t'', ts ! i)" + using reaches_on_split[OF assms] + by auto + show ?thesis + using run_t_sound[OF t'_def] assms(2) + by simp +qed + +lemma run_sub_sound': + assumes "reaches_on (w_run_sub args) sub bs s" "i < length bs" + shows "bs ! i = IArray (map (\phi. sat phi i) (collect_subfmlas r []))" +proof - + obtain s' s'' where s'_def: "reaches_on (w_run_sub args) sub (take i bs) s'" + "w_run_sub args s' = Some (s'', bs ! i)" + using reaches_on_split[OF assms] + by auto + show ?thesis + using run_sub_sound[OF s'_def] assms(2) + by simp +qed + +lemma run_ts: "reaches_on (w_run_t args) t ts t' \ t = t0 \ chain_le ts" +proof (induction t ts t' rule: reaches_on_rev_induct) + case (2 s s' v vs s'') + show ?case + proof (cases vs rule: rev_cases) + case (snoc zs z) + show ?thesis + using 2(3)[OF 2(4)] + using chain_le_app[OF _ \_mono[of "length zs" "Suc (length zs)" \]] + run_t_sound'[OF reaches_on_app[OF 2(1,2), unfolded 2(4)], of "length zs"] + run_t_sound'[OF reaches_on_app[OF 2(1,2), unfolded 2(4)], of "Suc (length zs)"] + unfolding snoc + by (auto simp: nth_append) + qed (auto intro: chain_le.intros) +qed (auto intro: chain_le.intros) + +lemma ts_at_tau: "reaches_on (w_run_t args) t0 (map fst rho) t \ i < length rho \ + ts_at rho i = \ \ i" + using run_t_sound' + unfolding ts_at_def + by fastforce + +lemma length_bs_at: "reaches_on (w_run_sub args) sub (map snd rho) s \ i < length rho \ + IArray.length (bs_at rho i) = length (collect_subfmlas r [])" + using run_sub_sound' + unfolding bs_at_def + by fastforce + +lemma bs_at_nth: "reaches_on (w_run_sub args) sub (map snd rho) s \ i < length rho \ + n < IArray.length (bs_at rho i) \ + IArray.sub (bs_at rho i) n \ sat (collect_subfmlas r [] ! n) i" + using run_sub_sound' + unfolding bs_at_def + by fastforce + +lemma ts_at_mono: "\i j. reaches_on (w_run_t args) t0 (map fst rho) t \ + i \ j \ j < length rho \ ts_at rho i \ ts_at rho j" + using ts_at_tau + by fastforce + +lemma steps_is_run: "steps (w_step args) rho q ij = run q (sub_bs rho ij)" + unfolding NFA.run'_def steps_def step_def transs_def qf_def .. + +lemma acc_is_accept: "wacc rho q (i, j) = w_accept args (run q (sub_bs rho (i, j)))" + unfolding acc_def steps_is_run by auto + +lemma iarray_list_of: "IArray (IArray.list_of xs) = xs" + by (cases xs) auto + +lemma map_iarray_list_of: "map IArray (map IArray.list_of bss) = bss" + using iarray_list_of + by (induction bss) auto + +lemma acc_match: + fixes ts :: "'d list" + assumes "reaches_on (w_run_sub args) sub (map snd rho) s" "i \ j" "j \ length rho" "wf_regex r" + shows "wacc rho {0} (i, j) \ (i, j) \ match r" +proof - + have j_eq: "j = i + length (sub_bs rho (i, j))" + using assms by auto + define bs where "bs = map (\phi. sat phi j) (collect_subfmlas r [])" + have IH: "IH r 0 qf [] transs (map IArray.list_of (sub_bs rho (i, j))) bs i" + unfolding IH_def transs_def qf_def NFA.SQ_def build_nfa_impl_state_cnt bs_def + using assms run_sub_sound bs_at_nth length_bs_at by fastforce + interpret NFA_array: nfa_array transs "IArray transs" qf + by unfold_locales (auto simp: qf_def transs_def build_nfa_impl_state_cnt) + have run_run': "NFA_array.run R (map IArray.list_of (sub_bs rho (i, j))) = NFA_array.run' R (sub_bs rho (i, j))" for R + using NFA_array.run'_eq[of "sub_bs rho (i, j)" "map IArray.list_of (sub_bs rho (i, j))"] + unfolding map_iarray_list_of + by auto + show ?thesis + using nfa_correct[OF IH, unfolded NFA.run_accept_def] + unfolding run_accept_eps_iff_run_accept[OF assms(4) IH] acc_is_accept NFA.run_accept_def run_run' NFA_array.accept'_eq + by (simp add: j_eq[symmetric] accept_def assms(2) qf_def transs_def) +qed + +lemma accept_match: + fixes ts :: "'d list" + shows "reaches_on (w_run_sub args) sub (map snd rho) s \ i \ j \ j \ length rho \ wf_regex r \ + w_accept args (steps (w_step args) rho {0} (i, j)) \ (i, j) \ match r" + using acc_match acc_is_accept steps_is_run + by metis + +lemma drop_take_drop: "i \ j \ j \ length rho \ drop i (take j rho) @ drop j rho = drop i rho" + apply (induction i arbitrary: j rho) + by auto (metis append_take_drop_id diff_add drop_drop drop_take) + +lemma take_Suc: "drop n xs = y # ys \ take n xs @ [y] = take (Suc n) xs" + by (metis drop_all list.distinct(1) list.sel(1) not_less take_hd_drop) + +lemma valid_init_matchP: "valid_matchP I t0 sub [] 0 (init_window args t0 sub)" + using valid_init_window + by (fastforce simp: valid_window_matchP_def Let_def intro: reaches_on.intros split: option.splits) + +lemma valid_init_matchF: "valid_matchF I t0 sub [] 0 (init_window args t0 sub)" + using valid_init_window + by (fastforce simp: valid_window_matchF_def Let_def intro: reaches_on.intros split: option.splits) + +lemma valid_eval_matchP: + assumes valid_before': "valid_matchP I t0 sub rho j w" + and before_end: "w_run_t args (w_tj w) = Some (tj''', t)" "w_run_sub args (w_sj w) = Some (sj''', b)" + and wf: "wf_regex r" + shows "\w'. eval_mP I w = Some ((\ \ j, sat (MatchP I r) j), w') \ + t = \ \ j \ valid_matchP I t0 sub (rho @ [(t, b)]) (Suc j) w'" +proof - + obtain w' where w'_def: "adv_end args w = Some w'" + using before_end + by (fastforce simp: adv_end_def Let_def split: prod.splits) + define st where "st = w_st w'" + define i where "i = w_i w'" + define ti where "ti = w_ti w'" + define si where "si = w_si w'" + define tj where "tj = w_tj w'" + define sj where "sj = w_sj w'" + define s where "s = w_s w'" + define e where "e = w_e w'" + define rho' where "rho' = rho @ [(t, b)]" + have reaches_on': "reaches_on (w_run_t args) t0 (map fst rho') tj'''" + using valid_before' reach_window_run_tj[OF reach_window_app[OF _ before_end]] + by (auto simp: valid_window_matchP_def rho'_def) + have rho_mono: "\t'. t' \ set (map fst rho) \ t' \ t" + using ts_at_mono[OF reaches_on'] nat_less_le + by (fastforce simp: rho'_def ts_at_def nth_append in_set_conv_nth split: list.splits) + have valid_adv_end_w: "valid_window args t0 sub rho' w'" + using valid_before' valid_adv_end[OF _ before_end rho_mono] + by (auto simp: valid_window_matchP_def rho'_def w'_def) + have w_ij_adv_end: "w_i w' = w_i w" "w_j w' = Suc j" + using valid_before' w'_def + by (auto simp: valid_window_matchP_def adv_end_def Let_def before_end split: prod.splits) + have valid_before: "rw t0 sub rho' (i, ti, si, Suc j, tj, sj)" + "\i j. i \ j \ j < length rho' \ ts_at rho' i \ ts_at rho' j" + "\q. mmap_lookup e q = sup_leadsto init step rho' i (Suc j) q" + "valid_s init step st accept rho' i i (Suc j) s" + "w_j w' = Suc j" "i \ Suc j" + using valid_adv_end_w + unfolding valid_window_def Let_def ti_def si_def i_def tj_def sj_def s_def e_def w_ij_adv_end st_def + by auto + note read_t_def = run_t_read[OF before_end(1)] + have t_props: "\l < i. memL (ts_at rho' l) t I" + using valid_before' + by (auto simp: valid_window_matchP_def i_def w_ij_adv_end read_t_def rho'_def ts_at_def nth_append) + + note reaches_on_tj = reach_window_run_tj[OF valid_before(1)] + note reaches_on_sj = reach_window_run_sj[OF valid_before(1)] + have length_rho': "length rho' = Suc j" "length rho = j" + using valid_before + by (auto simp: rho'_def) + have j_len_rho': "j < length rho'" + by (auto simp: length_rho') + have tj_eq: "t = \ \ j" "t = ts_at rho' j" + using run_t_sound'[OF reaches_on_tj, of j] + by (auto simp: rho'_def length_rho' nth_append ts_at_def) + have bj_def: "b = bs_at rho' j" + using run_sub_sound'[OF reaches_on_sj, of j] + by (auto simp: rho'_def length_rho' nth_append bs_at_def) + define w'' where loop_def: "w'' = while (matchP_cond I t) (adv_start args) w'" + have inv_before: "matchP_inv I t0 sub rho' (Suc j) tj sj t w'" + using valid_adv_end_w valid_before t_props + unfolding matchP_loop_inv_def + by (auto simp: tj_def sj_def i_def) + have loop: "matchP_inv I t0 sub rho' (Suc j) tj sj t w'' \ \matchP_cond I t w''" + unfolding loop_def + proof (rule while_rule_lemma[of "matchP_inv I t0 sub rho' (Suc j) tj sj t"]) + fix w_cur :: "(bool iarray, nat set, 'd, 't, 'e) window" + assume assms: "matchP_inv I t0 sub rho' (Suc j) tj sj t w_cur" "matchP_cond I t w_cur" + define st_cur where "st_cur = w_st w_cur" + define i_cur where "i_cur = w_i w_cur" + define ti_cur where "ti_cur = w_ti w_cur" + define si_cur where "si_cur = w_si w_cur" + define s_cur where "s_cur = w_s w_cur" + define e_cur where "e_cur = w_e w_cur" + have valid_loop: "rw t0 sub rho' (i_cur, ti_cur, si_cur, Suc j, tj, sj)" + "\i j. i \ j \ j < length rho' \ ts_at rho' i \ ts_at rho' j" + "\q. mmap_lookup e_cur q = sup_leadsto init step rho' i_cur (Suc j) q" + "valid_s init step st_cur accept rho' i_cur i_cur (Suc j) s_cur" + "w_j w_cur = Suc j" + using assms(1)[unfolded matchP_loop_inv_def valid_window_matchP_def] valid_before(6) + ti_cur_def si_cur_def i_cur_def s_cur_def e_cur_def + by (auto simp: valid_window_def Let_def init_def step_def st_cur_def accept_def + split: option.splits) + obtain ti'_cur si'_cur t_cur b_cur where run_si_cur: + "w_run_t args ti_cur = Some (ti'_cur, t_cur)" "w_run_sub args si_cur = Some (si'_cur, b_cur)" + "t_cur = ts_at rho' i_cur" "b_cur = bs_at rho' i_cur" + using assms(2) reach_window_run_si[OF valid_loop(1)] reach_window_run_ti[OF valid_loop(1)] + unfolding matchP_loop_cond_def valid_loop(5) i_cur_def + by auto + have "\l. l < i_cur \ memL (ts_at rho' l) t I" + using assms(1) + unfolding matchP_loop_inv_def i_cur_def + by auto + then have "\l. l < Suc (i_cur) \ memL (ts_at rho' l) t I" + using assms(2) run_t_read[OF run_si_cur(1), unfolded run_si_cur(3)] + unfolding matchP_loop_cond_def i_cur_def ti_cur_def + by (auto simp: less_Suc_eq) + then show "matchP_inv I t0 sub rho' (Suc j) tj sj t (adv_start args w_cur)" + using assms i_cur_def valid_adv_start valid_adv_start_bounds + unfolding matchP_loop_inv_def matchP_loop_cond_def + by fastforce + next + { + fix w1 w2 + assume lassms: "matchP_inv I t0 sub rho' (Suc j) tj sj t w1" "matchP_cond I t w1" + "w2 = adv_start args w1" + define i_cur where "i_cur = w_i w1" + define ti_cur where "ti_cur = w_ti w1" + define si_cur where "si_cur = w_si w1" + have valid_loop: "rw t0 sub rho' (i_cur, ti_cur, si_cur, Suc j, tj, sj)" "w_j w1 = Suc j" + using lassms(1)[unfolded matchP_loop_inv_def valid_window_matchP_def] valid_before(6) + ti_cur_def si_cur_def i_cur_def + by (auto simp: valid_window_def Let_def) + obtain ti'_cur si'_cur t_cur b_cur where run_si_cur: + "w_run_t args ti_cur = Some (ti'_cur, t_cur)" + "w_run_sub args si_cur = Some (si'_cur, b_cur)" + using lassms(2) reach_window_run_si[OF valid_loop(1)] reach_window_run_ti[OF valid_loop(1)] + unfolding matchP_loop_cond_def valid_loop i_cur_def + by auto + have w1_ij: "w_i w1 < Suc j" "w_j w1 = Suc j" + using lassms + unfolding matchP_loop_inv_def matchP_loop_cond_def + by auto + have w2_ij: "w_i w2 = Suc (w_i w1)" "w_j w2 = Suc j" + using w1_ij lassms(3) run_si_cur(1,2) + unfolding ti_cur_def si_cur_def + by (auto simp: adv_start_def Let_def split: option.splits prod.splits if_splits) + have "w_j w2 - w_i w2 < w_j w1 - w_i w1" + using w1_ij w2_ij + by auto + } + then have "{(s', s). matchP_inv I t0 sub rho' (Suc j) tj sj t s \ matchP_cond I t s \ + s' = adv_start args s} \ measure (\w. w_j w - w_i w)" + by auto + then show "wf {(s', s). matchP_inv I t0 sub rho' (Suc j) tj sj t s \ matchP_cond I t s \ + s' = adv_start args s}" + using wf_measure wf_subset by auto + qed (auto simp: inv_before) + have valid_w': "valid_window args t0 sub rho' w''" + using conjunct1[OF loop] + unfolding matchP_loop_inv_def + by auto + have w_tsj_w': "w_tj w'' = tj" "w_sj w'' = sj" "w_j w'' = Suc j" + using loop + by (auto simp: matchP_loop_inv_def) + define st' where "st' = w_st w''" + define ac where "ac = w_ac w''" + define i' where "i' = w_i w''" + define ti' where "ti' = w_ti w''" + define si' where "si' = w_si w''" + define s' where "s' = w_s w''" + define e' where "e' = w_e w''" + define tj' where "tj' = w_tj w''" + define sj' where "sj' = w_sj w''" + have i'_le_Suc_j: "i' \ Suc j" + using loop + unfolding matchP_loop_inv_def + by (auto simp: valid_window_def Let_def i'_def) + have valid_after: "rw t0 sub rho' (i', ti', si', Suc j, tj', sj')" + "\i j. i \ j \ j < length rho' \ ts_at rho' i \ ts_at rho' j" + "distinct (map fst e')" + "\q. mmap_lookup e' q = sup_leadsto init step rho' i' (Suc j) q" + "\q. case Mapping.lookup ac q of None \ True | Some v \ accept q = v" + "valid_s init step st' accept rho' i' i' (Suc j) s'" "i' \ Suc j" "Suc j \ length rho'" + using valid_w' i'_le_Suc_j + unfolding valid_window_def Let_def i'_def ti'_def si'_def s'_def e'_def tj'_def sj'_def ac_def st'_def w_tsj_w' + by auto + note lookup_e' = valid_after(3,4,5,6) + obtain \ ac' where ac'_def: "ex_key e' (\t'. memR t' t I) + (w_accept args) ac = (\, ac')" + by fastforce + have \_def: "\ = (\q\mmap_keys e'. memR (the (mmap_lookup e' q)) t I \ accept q)" + "\q. case Mapping.lookup ac' q of None \ True | Some v \ accept q = v" + using ex_key_sound[OF valid_after(5) valid_after(3) ac'_def] + by auto + have i'_set: "\l. l < w_i w'' \ memL (ts_at rho' l) (ts_at rho' j) I" + using loop length_rho' i'_le_Suc_j + unfolding matchP_loop_inv_def + by (auto simp: ts_at_def rho'_def nth_append i'_def) + have b_alt: "(\q \ mmap_keys e'. memR (the (mmap_lookup e' q)) t I \ accept q) \ sat (MatchP I r) j" + proof (rule iffI) + assume "\q \ mmap_keys e'. memR (the (mmap_lookup e' q)) t I \ accept q" + then obtain q where q_def: "q \ mmap_keys e'" + "memR (the (mmap_lookup e' q)) t I" "accept q" + by auto + then obtain ts' where ts_def: "mmap_lookup e' q = Some ts'" + by (auto dest: Mapping_keys_dest) + have "sup_leadsto init step rho' i' (Suc j) q = Some ts'" + using lookup_e' ts_def q_def valid_after(4,7,8) + by (auto simp: rho'_def sup_leadsto_app_cong) + then obtain l where l_def: "l < i'" "steps step rho' init (l, Suc j) = q" + "ts_at rho' l = ts'" + using sup_leadsto_SomeE[OF i'_le_Suc_j] + unfolding i'_def + by fastforce + have l_le_j: "l \ j" and l_le_Suc_j: "l \ Suc j" + using l_def(1) i'_le_Suc_j + by (auto simp: i'_def) + have tau_l: "l < j \ fst (rho ! l) = \ \ l" + using run_t_sound'[OF reaches_on_tj, of l] length_rho' + by (auto simp: rho'_def nth_append) + have tau_l_left: "memL ts' t I" + unfolding l_def(3)[symmetric] tj_eq(2) + using i'_set l_def(1) + by (auto simp: i'_def) + have "(l, Suc j) \ match r" + using accept_match[OF reaches_on_sj l_le_Suc_j _ wf] q_def(3) length_rho' init_def l_def(2) + rho'_def + by auto + then show "sat (MatchP I r) j" + using l_le_j q_def(2) ts_at_tau[OF reaches_on_tj] tau_l_left + by (auto simp: mem_def tj_eq rho'_def ts_def l_def(3)[symmetric] tau_l tj_def ts_at_def + nth_append length_rho' intro: exI[of _ l] split: if_splits) + next + assume "sat (MatchP I r) j" + then obtain l where l_def: "l \ j" "l \ Suc j" "mem (\ \ l) (\ \ j) I" "(l, Suc j) \ match r" + by auto + show "(\q\mmap_keys e'. memR (the (mmap_lookup e' q)) t I \ accept q)" + proof - + have l_lt_j: "l < Suc j" + using l_def(1) by auto + then have ts_at_l_j: "ts_at rho' l \ ts_at rho' j" + using ts_at_mono[OF reaches_on' _ j_len_rho'] + by (auto simp: rho'_def length_rho') + have ts_j_l: "memL (ts_at rho' l) (ts_at rho' j) I" + using l_def(3) ts_at_tau[OF reaches_on_tj] l_lt_j length_rho' tj_eq + unfolding rho'_def mem_def + by auto + have "i' = Suc j \ \memL (ts_at rho' i') (ts_at rho' j) I" + proof (rule Meson.disj_comm, rule disjCI) + assume "i' \ Suc j" + then have i'_j: "i' < Suc j" + using valid_after + by auto + obtain t' b' where tbi_cur_def: "w_read_t args ti' = Some t'" + "t' = ts_at rho' i'" "b' = bs_at rho' i'" + using reach_window_run_ti[OF valid_after(1) i'_j] + reach_window_run_si[OF valid_after(1) i'_j] run_t_read + by auto + show "\memL (ts_at rho' i') (ts_at rho' j) I" + using loop tbi_cur_def(1) i'_j length_rho' + unfolding matchP_loop_inv_def matchP_loop_cond_def tj_eq(2) ti'_def[symmetric] + by (auto simp: i'_def tbi_cur_def) + qed + then have l_lt_i': "l < i'" + proof (rule disjE) + assume assm: "\memL (ts_at rho' i') (ts_at rho' j) I" + show "l < i'" + proof (rule ccontr) + assume "\l < i'" + then have ts_at_i'_l: "ts_at rho' i' \ ts_at rho' l" + using ts_at_mono[OF reaches_on'] l_lt_j length_rho' + by (auto simp: rho'_def length_rho') + show False + using assm memL_mono[OF ts_j_l ts_at_i'_l] + by auto + qed + qed (auto simp add: l_lt_j) + define q where q_def: "q = steps step rho' init (l, Suc j)" + then obtain l' where l'_def: "sup_leadsto init step rho' i' (Suc j) q = Some (ts_at rho' l')" + "l \ l'" "l' < i'" + using sup_leadsto_SomeI[OF l_lt_i'] by fastforce + have ts_j_l': "memR (ts_at rho' l') (ts_at rho' j) I" + proof - + have ts_at_l_l': "ts_at rho' l \ ts_at rho' l'" + using ts_at_mono[OF reaches_on' l'_def(2)] l'_def(3) valid_after(4,7,8) + by (auto simp add: rho'_def length_rho' dual_order.order_iff_strict) + show ?thesis + using l_def(3) memR_mono[OF _ ts_at_l_l'] + ts_at_tau[OF reaches_on_tj] l'_def(2,3) valid_after(4,7,8) + by (auto simp: mem_def rho'_def length_rho') + qed + have lookup_e'_q: "mmap_lookup e' q = Some (ts_at rho' l')" + using lookup_e' l'_def(1) valid_after(4,7,8) + by (auto simp: rho'_def sup_leadsto_app_cong) + show ?thesis + using accept_match[OF reaches_on_sj l_def(2) _ wf] l_def(4) ts_j_l' lookup_e'_q tj_eq(2) + by (auto simp: bs_at_def nth_append init_def length_rho'(1) q_def intro!: bexI[of _ q] Mapping_keys_intro) + qed + qed + have read_tj_Some: "\t' l. w_read_t args tj = Some t' \ l < i' \ memL (ts_at rho' l) t' I" + proof - + fix t' l + assume lassms: "(w_read_t args) tj = Some t'" "l < i'" + obtain tj'''' where reaches_on_tj'''': + "reaches_on (w_run_t args) t0 (map fst (rho' @ [(t', undefined)])) tj''''" + using reaches_on_app[OF reaches_on_tj] read_t_run[OF lassms(1)] + by auto + have "t \ t'" + using ts_at_mono[OF reaches_on_tj'''', of "length rho" "length rho'"] + by (auto simp: ts_at_def nth_append rho'_def) + then show "memL (ts_at rho' l) t' I" + using memL_mono' lassms(2) loop + unfolding matchP_loop_inv_def + by (fastforce simp: i'_def) + qed + define w''' where "w''' = w''\w_ac := ac'\" + have "rw t0 sub rho' (w_i w''', w_ti w''', w_si w''', w_j w''', w_tj w''', w_sj w''')" + using valid_after(1) + by (auto simp del: reach_window.simps simp: w'''_def i'_def ti'_def si'_def tj'_def sj'_def w_tsj_w') + moreover have "valid_window args t0 sub rho' w'''" + using valid_w' + by (auto simp: w'''_def valid_window_def Let_def \_def(2)) + ultimately have "valid_matchP I t0 sub rho' (Suc j) w'''" + using i'_set read_tj_Some + by (auto simp: valid_window_matchP_def w'''_def w_tsj_w' i'_def split: option.splits) + moreover have "eval_mP I w = Some ((t, sat (MatchP I r) j), w''')" + by (simp add: read_t_def Let_def loop_def[symmetric] ac'_def[unfolded e'_def ac_def] w'''_def w'_def trans[OF \_def(1) b_alt]) + ultimately show ?thesis + by (auto simp: tj_eq rho'_def) +qed + +lemma valid_eval_matchF_Some: + assumes valid_before': "valid_matchF I t0 sub rho i w" + and eval: "eval_mF I w = Some ((t, b), w'')" + and bounded: "right I \ tfin" + shows "\rho' tm. reaches_on (w_run_t args) (w_tj w) (map fst rho') (w_tj w'') \ + reaches_on (w_run_sub args) (w_sj w) (map snd rho') (w_sj w'') \ + (w_read_t args) (w_ti w) = Some t \ + (w_read_t args) (w_tj w'') = Some tm \ + \memR t tm I" +proof - + define st where "st = w_st w" + define ti where "ti = w_ti w" + define si where "si = w_si w" + define j where "j = w_j w" + define tj where "tj = w_tj w" + define sj where "sj = w_sj w" + define s where "s = w_s w" + define e where "e = w_e w" + have valid_before: "rw t0 sub rho (i, ti, si, j, tj, sj)" + "\i j. i \ j \ j < length rho \ ts_at rho i \ ts_at rho j" + "\q. mmap_lookup e q = sup_leadsto init step rho i j q" + "valid_s init step st accept rho i i j s" + "i = w_i w" "i \ j" "length rho = j" + using valid_before'[unfolded valid_window_matchF_def] ti_def + si_def j_def tj_def sj_def s_def e_def + by (auto simp: valid_window_def Let_def init_def step_def st_def accept_def) + obtain ti''' where tbi_def: "w_run_t args ti = Some (ti''', t)" + using eval read_t_run + by (fastforce simp: Let_def ti_def si_def split: option.splits if_splits) + have t_tau: "t = \ \ i" + using run_t_sound[OF _ tbi_def] valid_before(1) + by auto + note t_def = run_t_read[OF tbi_def(1)] + obtain w' where loop_def: "while_break (matchF_cond I t) (adv_end args) w = Some w'" + using eval + by (auto simp: ti_def[symmetric] t_def split: option.splits) + have adv_start_last: + "adv_start args w' = w''" + using eval loop_def[symmetric] run_t_read[OF tbi_def(1)] + by (auto simp: ti_def split: option.splits prod.splits if_splits) + have inv_before: "matchF_inv' t0 sub rho i ti si j tj sj w" + using valid_before(1) valid_before' + unfolding matchF_loop_inv'_def valid_before(6) valid_window_matchF_def + by (auto simp add: ti_def si_def j_def tj_def sj_def simp del: reach_window.simps + dest: reach_window_shift_all intro!: exI[of _ "[]"]) + have i_j: "i \ j" "length rho = j" + using valid_before by auto + define j'' where "j'' = w_j w''" + define tj'' where "tj'' = w_tj w''" + define sj'' where "sj'' = w_sj w''" + have loop: "matchF_inv' t0 sub rho i ti si j tj sj w' \ \ matchF_cond I t w'" + proof (rule while_break_sound[of "matchF_inv' t0 sub rho i ti si j tj sj" "matchF_cond I t" "adv_end args" "\w'. matchF_inv' t0 sub rho i ti si j tj sj w' \ \ matchF_cond I t w'" w, unfolded loop_def, simplified]) + fix w_cur w_cur' :: "(bool iarray, nat set, 'd, 't, 'e) window" + assume assms: "matchF_inv' t0 sub rho i ti si j tj sj w_cur" "matchF_cond I t w_cur" "adv_end args w_cur = Some w_cur'" + define j_cur where "j_cur = w_j w_cur" + define tj_cur where "tj_cur = w_tj w_cur" + define sj_cur where "sj_cur = w_sj w_cur" + obtain rho' where rho'_def: "valid_window args t0 sub (rho @ rho') w_cur" + "rw t0 sub (rho @ rho') (j, tj, sj, w_j w_cur, w_tj w_cur, w_sj w_cur)" + using assms(1)[unfolded matchF_loop_inv'_def valid_window_matchF_def] + by auto + obtain tj' x sj' y where append: "w_run_t args tj_cur = Some (tj', x)" + "w_run_sub args sj_cur = Some (sj', y)" + using assms(3) + unfolding tj_cur_def sj_cur_def + by (auto simp: adv_end_def Let_def split: option.splits) + note append' = append[unfolded tj_cur_def sj_cur_def] + define rho'' where "rho'' = rho @ rho'" + have reach: "reaches_on (w_run_t args) t0 (map fst (rho'' @ [(x, undefined)])) tj'" + using reaches_on_app[OF reach_window_run_tj[OF rho'_def(2)] append'(1)] + by (auto simp: rho''_def) + have mono: "\t'. t' \ set (map fst rho'') \ t' \ x" + using ts_at_mono[OF reach, of _ "length rho''"] nat_less_le + by (fastforce simp: ts_at_def nth_append in_set_conv_nth split: list.splits) + show "matchF_inv' t0 sub rho i ti si j tj sj w_cur'" + using assms(1,3) reach_window_app[OF rho'_def(2) append[unfolded tj_cur_def sj_cur_def]] + valid_adv_end[OF rho'_def(1) append' mono] adv_end_bounds[OF append'] + unfolding matchF_loop_inv'_def matchF_loop_cond_def rho''_def + by auto + next + obtain l where l_def: "\\ \ l \ t + right I" + unfolding t_tau + using ex_lt_\[OF bounded] + by auto + { + fix w1 w2 + assume lassms: "matchF_inv' t0 sub rho i ti si j tj sj w1" "matchF_cond I t w1" + "Some w2 = adv_end args w1" + define j_cur where "j_cur = w_j w1" + define tj_cur where "tj_cur = w_tj w1" + define sj_cur where "sj_cur = w_sj w1" + obtain rho' where rho'_def: "valid_window args t0 sub (rho @ rho') w1" + "rw t0 sub (rho @ rho') (j, tj, sj, w_j w1, w_tj w1, w_sj w1)" + using lassms(1)[unfolded matchF_loop_inv'_def valid_window_matchF_def] + by auto + obtain tj' x sj' y where append: "w_run_t args tj_cur = Some (tj', x)" + "w_run_sub args sj_cur = Some (sj', y)" + using lassms(3) + unfolding tj_cur_def sj_cur_def + by (auto simp: adv_end_def Let_def split: option.splits) + note append' = append[unfolded tj_cur_def sj_cur_def] + define rho'' where "rho'' = rho @ rho'" + have reach: "reaches_on (w_run_t args) t0 (map fst (rho'' @ [(x, undefined)])) tj'" + using reaches_on_app[OF reach_window_run_tj[OF rho'_def(2)] append'(1)] + by (auto simp: rho''_def) + have mono: "\t'. t' \ set (map fst rho'') \ t' \ x" + using ts_at_mono[OF reach, of _ "length rho''"] nat_less_le + by (fastforce simp: ts_at_def nth_append in_set_conv_nth split: list.splits) + have t_cur_tau: "x = \ \ j_cur" + using ts_at_tau[OF reach, of "length rho''"] rho'_def(2) + by (auto simp: ts_at_def j_cur_def rho''_def) + have "j_cur < l" + using lassms(2)[unfolded matchF_loop_cond_def] l_def memR_mono'[OF _ \_mono[of l j_cur \]] + unfolding run_t_read[OF append(1), unfolded t_cur_tau tj_cur_def] + by (fastforce dest: memR_dest) + moreover have "w_j w2 = Suc j_cur" + using adv_end_bounds[OF append'] + unfolding lassms(3)[symmetric] j_cur_def + by auto + ultimately have "l - w_j w2 < l - w_j w1" + unfolding j_cur_def + by auto + } + then have "{(ta, s). matchF_inv' t0 sub rho i ti si j tj sj s \ matchF_cond I t s \ + Some ta = adv_end args s} \ measure (\w. l - w_j w)" + by auto + then show "wf {(ta, s). matchF_inv' t0 sub rho i ti si j tj sj s \ matchF_cond I t s \ + Some ta = adv_end args s}" + using wf_measure wf_subset + by auto + qed (auto simp: inv_before) + define i' where "i' = w_i w'" + define ti' where "ti' = w_ti w'" + define si' where "si' = w_si w'" + define j' where "j' = w_j w'" + define tj' where "tj' = w_tj w'" + define sj' where "sj' = w_sj w'" + obtain rho' where rho'_def: "valid_window args t0 sub (rho @ rho') w'" + "rw t0 sub (rho @ rho') (j, tj, sj, j', tj', sj')" + "i = i'" "j \ j'" + using loop + unfolding matchF_loop_inv'_def i'_def j'_def tj'_def sj'_def + by auto + obtain tje tm where tm_def: "w_read_t args tj' = Some tm" "w_run_t args tj' = Some (tje, tm)" + using eval read_t_run loop_def t_def ti_def + by (auto simp: t_def Let_def tj'_def split: option.splits if_splits) + have drop_j_rho: "drop j (map fst (rho @ rho')) = map fst rho'" + using i_j + by auto + have "reaches_on (w_run_t args) ti (drop i (map fst rho)) tj" + using valid_before(1) + by auto + then have "reaches_on (w_run_t args) ti + (drop i (map fst rho) @ (drop j (map fst (rho @ rho')))) tj'" + using rho'_def reaches_on_trans + by fastforce + then have "reaches_on (w_run_t args) ti (drop i (map fst (rho @ rho'))) tj'" + unfolding drop_j_rho + by (auto simp: i_j) + then have reach_tm: "reaches_on (w_run_t args) ti (drop i (map fst (rho @ rho')) @ [tm]) tje" + using reaches_on_app tm_def(2) + by fastforce + have run_tsi': "w_run_t args ti' \ None" + using tbi_def loop + by (auto simp: matchF_loop_inv'_def ti'_def si'_def) + have memR_t_tm: "\ memR t tm I" + using loop tm_def + by (auto simp: tj'_def matchF_loop_cond_def) + have i_le_rho: "i \ length rho" + using valid_before + by auto + define rho'' where "rho'' = rho @ rho'" + have t_tfin: "t \ tfin" + using \_fin + by (auto simp: t_tau) + have i'_lt_j': "i' < j'" + using rho'_def(1,2,3)[folded rho''_def] i_j reach_tm[folded rho''_def] memR_t_tm tbi_def memR_tfin_refl[OF t_tfin] + by (cases "i' = j'") (auto dest!: reaches_on_NilD elim!: reaches_on.cases[of _ _ "[tm]"]) + have adv_last_bounds: "j'' = j'" "tj'' = tj'" "sj'' = sj'" + using valid_adv_start_bounds[OF rho'_def(1) i'_lt_j'[unfolded i'_def j'_def]] + unfolding adv_start_last j'_def j''_def tj'_def tj''_def sj'_def sj''_def + by auto + show ?thesis + using eval rho'_def run_tsi' i_j(2) adv_last_bounds tj''_def tj_def sj''_def sj_def + loop_def t_def ti_def tj'_def tm_def memR_t_tm + by (auto simp: drop_map run_t_read[OF tbi_def(1)] Let_def + split: option.splits prod.splits if_splits intro!: exI[of _ rho']) +qed + +lemma valid_eval_matchF_complete: + assumes valid_before': "valid_matchF I t0 sub rho i w" + and before_end: "reaches_on (w_run_t args) (w_tj w) (map fst rho') tj'''" + "reaches_on (w_run_sub args) (w_sj w) (map snd rho') sj'''" + "w_read_t args (w_ti w) = Some t" "w_read_t args tj''' = Some tm" "\memR t tm I" + and wf: "wf_regex r" + shows "\w'. eval_mF I w = Some ((\ \ i, sat (MatchF I r) i), w') \ + valid_matchF I t0 sub (take (w_j w') (rho @ rho')) (Suc i) w'" +proof - + define st where "st = w_st w" + define ti where "ti = w_ti w" + define si where "si = w_si w" + define j where "j = w_j w" + define tj where "tj = w_tj w" + define sj where "sj = w_sj w" + define s where "s = w_s w" + define e where "e = w_e w" + have valid_before: "rw t0 sub rho (i, ti, si, j, tj, sj)" + "\i j. i \ j \ j < length rho \ ts_at rho i \ ts_at rho j" + "\q. mmap_lookup e q = sup_leadsto init step rho i j q" + "valid_s init step st accept rho i i j s" + "i = w_i w" "i \ j" "length rho = j" + using valid_before'[unfolded valid_window_matchF_def] ti_def + si_def j_def tj_def sj_def s_def e_def + by (auto simp: valid_window_def Let_def init_def step_def st_def accept_def) + define rho'' where "rho'' = rho @ rho'" + have ij_le: "i \ j" "j = length rho" + using valid_before + by auto + have reach_tj: "reaches_on (w_run_t args) t0 (take j (map fst rho'')) tj" + using valid_before(1) ij_le + by (auto simp: take_map rho''_def simp del: reach_window.simps dest!: reach_window_run_tj) + have reach_ti: "reaches_on (w_run_t args) t0 (take i (map fst rho'')) ti" + using valid_before(1) ij_le + by (auto simp: take_map rho''_def) + have reach_si: "reaches_on (w_run_sub args) sub (take i (map snd rho'')) si" + using valid_before(1) ij_le + by (auto simp: take_map rho''_def) + have reach_sj: "reaches_on (w_run_sub args) sub (take j (map snd rho'')) sj" + using valid_before(1) ij_le + by (auto simp: take_map rho''_def simp del: reach_window.simps dest!: reach_window_run_sj) + have reach_tj''': "reaches_on (w_run_t args) t0 (map fst rho'') tj'''" + using reaches_on_trans[OF reach_tj before_end(1)[folded tj_def]] ij_le(2) + by (auto simp del: map_append simp: rho''_def take_map drop_map map_append[symmetric]) + have rho''_mono: "\i j. i \ j \ j < length rho'' \ ts_at rho'' i \ ts_at rho'' j" + using ts_at_mono[OF reach_tj'''] . + obtain tm' where reach_tm: "reaches_on (w_run_t args) t0 + (map fst (rho'' @ [(tm, undefined)])) tm'" + using reaches_on_app[OF reach_tj'''] read_t_run[OF before_end(4)] + by auto + have tj'''_eq: "\tj_cur. reaches_on (w_run_t args) t0 (map fst rho'') tj_cur \ + tj_cur = tj'''" + using reaches_on_inj[OF reach_tj'''] + by blast + have reach_sj''': "reaches_on (w_run_sub args) sub (map snd rho'') sj'''" + using reaches_on_trans[OF reach_sj before_end(2)[folded sj_def]] ij_le(2) + by (auto simp del: map_append simp: rho''_def take_map drop_map map_append[symmetric]) + have sj'''_eq: "\sj_cur. reaches_on (w_run_sub args) sub (map snd rho'') sj_cur \ + sj_cur = sj'''" + using reaches_on_inj[OF reach_sj'''] + by blast + have reach_window_i: "rw t0 sub rho'' (i, ti, si, length rho'', tj''', sj''')" + using reach_windowI[OF reach_ti reach_si reach_tj''' reach_sj''' _ refl] ij_le + by (auto simp: rho''_def) + have reach_window_j: "rw t0 sub rho'' (j, tj, sj, length rho'', tj''', sj''')" + using reach_windowI[OF reach_tj reach_sj reach_tj''' reach_sj''' _ refl] ij_le + by (auto simp: rho''_def) + have t_def: "t = \ \ i" + using valid_before(6) read_t_run[OF before_end(3)] reaches_on_app[OF reach_ti] + ts_at_tau[where ?rho="take i rho'' @ [(t, undefined)]"] + by (fastforce simp: ti_def rho''_def valid_before(5,7) take_map ts_at_def nth_append) + have t_tfin: "t \ tfin" + using \_fin + by (auto simp: t_def) + have i_lt_rho'': "i < length rho''" + using ij_le before_end(3,4,5) reach_window_i memR_tfin_refl[OF t_tfin] + by (cases "i = length rho''") (auto simp: rho''_def ti_def dest!: reaches_on_NilD) + obtain ti''' si''' b where tbi_def: "w_run_t args ti = Some (ti''', t)" + "w_run_sub args si = Some (si''', b)" "t = ts_at rho'' i" "b = bs_at rho'' i" + using reach_window_run_ti[OF reach_window_i i_lt_rho''] + reach_window_run_si[OF reach_window_i i_lt_rho''] + read_t_run[OF before_end(3), folded ti_def] + by auto + note before_end' = before_end(5) + have read_ti: "w_read_t args ti = Some t" + using run_t_read[OF tbi_def(1)] . + have inv_before: "matchF_inv I t0 sub rho'' i ti si tj''' sj''' w" + using valid_before' before_end(1,2,3) reach_window_j ij_le ti_def si_def j_def tj_def sj_def + unfolding matchF_loop_inv_def valid_window_matchF_def + by (auto simp: rho''_def ts_at_def nth_append) + have i_j: "i \ j" + using valid_before by auto + have loop: "pred_option' (\w'. matchF_inv I t0 sub rho'' i ti si tj''' sj''' w' \ \ matchF_cond I t w') (while_break (matchF_cond I t) (adv_end args) w)" + proof (rule while_break_complete[of "matchF_inv I t0 sub rho'' i ti si tj''' sj'''", OF _ _ _ inv_before]) + fix w_cur :: "(bool iarray, nat set, 'd, 't, 'e) window" + assume assms: "matchF_inv I t0 sub rho'' i ti si tj''' sj''' w_cur" "matchF_cond I t w_cur" + define j_cur where "j_cur = w_j w_cur" + define tj_cur where "tj_cur = w_tj w_cur" + define sj_cur where "sj_cur = w_sj w_cur" + define s_cur where "s_cur = w_s w_cur" + define e_cur where "e_cur = w_e w_cur" + have loop: "valid_window args t0 sub (take (w_j w_cur) rho'') w_cur" + "rw t0 sub rho'' (j_cur, tj_cur, sj_cur, length rho'', tj''', sj''')" + "\l. l\{w_i w_cur.. memR (ts_at rho'' i) (ts_at rho'' l) I" + using j_cur_def tj_cur_def sj_cur_def s_cur_def e_cur_def + assms(1)[unfolded matchF_loop_inv_def] + by auto + have j_cur_lt_rho'': "j_cur < length rho''" + using assms tj'''_eq before_end(4,5) + unfolding matchF_loop_inv_def matchF_loop_cond_def + by (cases "j_cur = length rho''") (auto simp: j_cur_def split: option.splits) + obtain tj_cur' sj_cur' x b_cur where tbi_cur_def: "w_run_t args tj_cur = Some (tj_cur', x)" + "w_run_sub args sj_cur = Some (sj_cur', b_cur)" + "x = ts_at rho'' j_cur" "b_cur = bs_at rho'' j_cur" + using reach_window_run_ti[OF loop(2) j_cur_lt_rho''] + reach_window_run_si[OF loop(2) j_cur_lt_rho''] + by auto + note reach_window_j'_cur = reach_window_shift[OF loop(2) j_cur_lt_rho'' tbi_cur_def(1,2)] + note tbi_cur_def' = tbi_cur_def(1,2)[unfolded tj_cur_def sj_cur_def] + have mono: "\t'. t' \ set (map fst (take (w_j w_cur) rho'')) \ t' \ x" + using rho''_mono[of _ j_cur] j_cur_lt_rho'' nat_less_le + by (fastforce simp: tbi_cur_def(3) j_cur_def ts_at_def nth_append in_set_conv_nth + split: list.splits) + have take_unfold: "take (w_j w_cur) rho'' @ [(x, b_cur)] = (take (Suc (w_j w_cur)) rho'')" + using j_cur_lt_rho'' + unfolding tbi_cur_def(3,4) + by (auto simp: ts_at_def bs_at_def j_cur_def take_Suc_conv_app_nth) + obtain w_cur' where w_cur'_def: "adv_end args w_cur = Some w_cur'" + by (fastforce simp: adv_end_def Let_def tj_cur_def[symmetric] sj_cur_def[symmetric] tbi_cur_def(1,2) split: prod.splits) + have "\l. l \{w_i w_cur'.. + memR (ts_at rho'' i) (ts_at rho'' l) I" + using loop(3) assms(2) w_cur'_def + unfolding adv_end_bounds[OF tbi_cur_def' w_cur'_def] matchF_loop_cond_def + run_t_read[OF tbi_cur_def(1)[unfolded tj_cur_def]] tbi_cur_def(3) tbi_def(3) + by (auto simp: j_cur_def elim: less_SucE) + then show "pred_option' (matchF_inv I t0 sub rho'' i ti si tj''' sj''') (adv_end args w_cur)" + using assms(1) reach_window_j'_cur valid_adv_end[OF loop(1) tbi_cur_def' mono] + w_cur'_def adv_end_bounds[OF tbi_cur_def' w_cur'_def] + unfolding matchF_loop_inv_def j_cur_def take_unfold + by (auto simp: pred_option'_def) + next + { + fix w1 w2 + assume lassms: "matchF_inv I t0 sub rho'' i ti si tj''' sj''' w1" "matchF_cond I t w1" + "Some w2 = adv_end args w1" + define j_cur where "j_cur = w_j w1" + define tj_cur where "tj_cur = w_tj w1" + define sj_cur where "sj_cur = w_sj w1" + define s_cur where "s_cur = w_s w1" + define e_cur where "e_cur = w_e w1" + have loop: "valid_window args t0 sub (take (w_j w1) rho'') w1" + "rw t0 sub rho'' (j_cur, tj_cur, sj_cur, length rho'', tj''', sj''')" + "\l. l\{w_i w1.. memR (ts_at rho'' i) (ts_at rho'' l) I" + using j_cur_def tj_cur_def sj_cur_def s_cur_def e_cur_def + lassms(1)[unfolded matchF_loop_inv_def] + by auto + have j_cur_lt_rho'': "j_cur < length rho''" + using lassms tj'''_eq ij_le before_end(4,5) + unfolding matchF_loop_inv_def matchF_loop_cond_def + by (cases "j_cur = length rho''") (auto simp: j_cur_def split: option.splits) + obtain tj_cur' sj_cur' x b_cur where tbi_cur_def: "w_run_t args tj_cur = Some (tj_cur', x)" + "w_run_sub args sj_cur = Some (sj_cur', b_cur)" + "x = ts_at rho'' j_cur" "b_cur = bs_at rho'' j_cur" + using reach_window_run_ti[OF loop(2) j_cur_lt_rho''] + reach_window_run_si[OF loop(2) j_cur_lt_rho''] + by auto + note tbi_cur_def' = tbi_cur_def(1,2)[unfolded tj_cur_def sj_cur_def] + have "length rho'' - w_j w2 < length rho'' - w_j w1" + using j_cur_lt_rho'' adv_end_bounds[OF tbi_cur_def', folded lassms(3)] + unfolding j_cur_def + by auto + } + then have "{(ta, s). matchF_inv I t0 sub rho'' i ti si tj''' sj''' s \ matchF_cond I t s \ + Some ta = adv_end args s} \ measure (\w. length rho'' - w_j w)" + by auto + then show "wf {(ta, s). matchF_inv I t0 sub rho'' i ti si tj''' sj''' s \ matchF_cond I t s \ + Some ta = adv_end args s}" + using wf_measure wf_subset + by auto + qed (auto simp add: inv_before) + obtain w' where w'_def: "while_break (matchF_cond I t) (adv_end args) w = Some w'" + using loop + by (auto simp: pred_option'_def split: option.splits) + define w'' where adv_start_last: "w'' = adv_start args w'" + define st' where "st' = w_st w'" + define i' where "i' = w_i w'" + define ti' where "ti' = w_ti w'" + define si' where "si' = w_si w'" + define j' where "j' = w_j w'" + define tj' where "tj' = w_tj w'" + define sj' where "sj' = w_sj w'" + define s' where "s' = w_s w'" + define e' where "e' = w_e w'" + have valid_after: "valid_window args t0 sub (take (w_j w') rho'') w'" + "rw t0 sub rho'' (j', tj', sj', length rho'', tj''', sj''')" + "\l. l\{i.. memR (ts_at rho'' i) (ts_at rho'' l) I" + "i' = i" "ti' = ti" "si' = si" + using loop + unfolding matchF_loop_inv_def w'_def i'_def ti'_def si'_def j'_def tj'_def sj'_def + by (auto simp: pred_option'_def) + define i'' where "i'' = w_i w''" + define j'' where "j'' = w_j w''" + define tj'' where "tj'' = w_tj w''" + define sj'' where "sj'' = w_sj w''" + have j'_le_rho'': "j' \ length rho''" + using loop + unfolding matchF_loop_inv_def valid_window_matchF_def w'_def j'_def + by (auto simp: pred_option'_def) + obtain te where tbj'_def: "w_read_t args tj' = Some te" + "te = ts_at (rho'' @ [(tm, undefined)]) j'" + proof (cases "j' < length rho''") + case True + show ?thesis + using reach_window_run_ti[OF valid_after(2) True] that True + by (auto simp: ts_at_def nth_append dest!: run_t_read) + next + case False + then have "tj' = tj'''" "j' = length rho''" + using valid_after(2) j'_le_rho'' tj'''_eq + by auto + then show ?thesis + using that before_end(4) + by (auto simp: ts_at_def nth_append) + qed + have not_ets_te: "\memR (ts_at rho'' i) te I" + using loop + unfolding w'_def + by (auto simp: pred_option'_def matchF_loop_cond_def tj'_def[symmetric] tbj'_def(1) tbi_def(3) split: option.splits) + have i'_set: "\l. l \ {i.. memR (ts_at rho'' i) (ts_at rho'' l) I" + "\memR (ts_at rho'' i) (ts_at (rho'' @ [(tm, undefined)]) j') I" + using loop tbj'_def not_ets_te valid_after atLeastLessThan_iff + unfolding matchF_loop_inv_def matchF_loop_cond_def tbi_def(3) + by (auto simp: tbi_def tj'_def split: option.splits) + have i_le_j': "i \ j'" + using valid_after(1) + unfolding valid_after(4)[symmetric] + by (auto simp: valid_window_def Let_def i'_def j'_def) + have i_lt_j': "i < j'" + using i_le_j' i'_set(2) i_lt_rho'' + using memR_tfin_refl[OF \_fin] ts_at_tau[OF reach_tj''', of j'] + by (cases "i = j'") (auto simp: ts_at_def nth_append) + then have i'_lt_j': "i' < j'" + unfolding valid_after + by auto + have adv_last_bounds: "i'' = Suc i'" "w_ti w'' = ti'''" "w_si w'' = si'''" "j'' = j'" + "tj'' = tj'" "sj'' = sj'" + using valid_adv_start_bounds[OF valid_after(1) i'_lt_j'[unfolded i'_def j'_def]] + valid_adv_start_bounds'[OF valid_after(1) tbi_def(1,2)[folded valid_after(5,6), + unfolded ti'_def si'_def]] + unfolding adv_start_last i'_def i''_def j'_def j''_def tj'_def tj''_def sj'_def sj''_def + by auto + have i''_i: "i'' = i + 1" + using valid_after adv_last_bounds by auto + have i_le_j': "i \ j'" + using valid_after i'_lt_j' + by auto + then have i_le_rho: "i \ length rho''" + using valid_after(2) + by auto + have "valid_s init step st' accept (take j' rho'') i i j' s'" + using valid_after(1,4) i'_def + by (auto simp: valid_window_def Let_def init_def step_def st'_def accept_def j'_def s'_def) + note valid_s' = this[unfolded valid_s_def] + have q0_in_keys: "{0} \ mmap_keys s'" + using valid_s' init_def steps_refl by auto + then obtain q' tstp where lookup_s': "mmap_lookup s' {0} = Some (q', tstp)" + by (auto dest: Mapping_keys_dest) + have lookup_sup_acc: "snd (the (mmap_lookup s' {0})) = + sup_acc step accept (take j' rho'') {0} i j'" + using conjunct2[OF valid_s'] lookup_s' + by auto (smt case_prodD option.simps(5)) + have b_alt: "(case snd (the (mmap_lookup s' {0})) of None \ False + | Some tstp \ memL t (fst tstp) I) \ sat (MatchF I r) i" + proof (rule iffI) + assume assm: "case snd (the (mmap_lookup s' {0})) of None \ False + | Some tstp \ memL t (fst tstp) I" + then obtain ts tp where tstp_def: + "sup_acc step accept (take j' rho'') {0} i j' = Some (ts, tp)" + "memL (ts_at rho'' i) ts I" + unfolding lookup_sup_acc + by (auto simp: tbi_def split: option.splits) + then have sup_acc_rho'': "sup_acc step accept rho'' {0} i j' = Some (ts, tp)" + using sup_acc_concat_cong[of j' "take j' rho''" step accept "drop j' rho''"] j'_le_rho'' + by auto + have tp_props: "tp \ {i.. Suc tp" + using tp_props by auto + have "memR (ts_at rho'' i) (ts_at rho'' tp) I" + using i'_set(1)[OF tp_props(1)] . + then have "mem (ts_at rho'' i) (ts_at rho'' tp) I" + using tstp_def(2) unfolding ts_ts_at mem_def by auto + then show "sat (MatchF I r) i" + using i_le_tp acc_match[OF reach_sj''' i_le_tp _ wf] tp_props(2) ts_at_tau[OF reach_tj'''] + tp_props(1) j'_le_rho'' + by auto + next + assume "sat (MatchF I r) i" + then obtain l where l_def: "l \ i" "mem (\ \ i) (\ \ l) I" "(i, Suc l) \ match r" + by auto + have l_lt_rho: "l < length rho''" + proof (rule ccontr) + assume contr: "\l < length rho''" + have "tm = ts_at (rho'' @ [(tm, undefined)]) (length rho'')" + using i_le_rho + by (auto simp add: ts_at_def rho''_def) + moreover have "\ \ \ \ l" + using \_mono ts_at_tau[OF reach_tm] i_le_rho contr + by (metis One_nat_def Suc_eq_plus1 length_append lessI list.size(3) + list.size(4) not_le_imp_less) + moreover have "memR (\ \ i) (\ \ l) I" + using l_def(2) + unfolding mem_def + by auto + ultimately have "memR (\ \ i) tm I" + using memR_mono' + by auto + then show "False" + using before_end' ts_at_tau[OF reach_tj''' i_lt_rho''] tbi_def(3) + by (auto simp: rho''_def) + qed + have l_lt_j': "l < j'" + proof (rule ccontr) + assume contr: "\l < j'" + then have ts_at_j'_l: "ts_at rho'' j' \ ts_at rho'' l" + using ts_at_mono[OF reach_tj'''] l_lt_rho + by (auto simp add: order.not_eq_order_implies_strict) + have ts_at_l_iu: "memR (ts_at rho'' i) (ts_at rho'' l) I" + using l_def(2) ts_at_tau[OF reach_tj''' l_lt_rho] ts_at_tau[OF reach_tj''' i_lt_rho''] + unfolding mem_def + by auto + show "False" + using i'_set(2) ts_at_j'_l ts_at_l_iu contr l_lt_rho memR_mono' + by (auto simp: ts_at_def nth_append split: if_splits) + qed + have i_le_Suc_l: "i \ Suc l" + using l_def(1) + by auto + obtain tp where tstp_def: "sup_acc step accept rho'' {0} i j' = Some (ts_at rho'' tp, tp)" + "l \ tp" "tp < j'" + using l_def(1,3) l_lt_j' l_lt_rho + by (meson accept_match[OF reach_sj''' i_le_Suc_l _ wf, unfolded steps_is_run] sup_acc_SomeI[unfolded acc_is_accept, of step accept] acc_is_accept atLeastLessThan_iff less_eq_Suc_le) + have "memL (ts_at rho'' i) (ts_at rho'' l) I" + using l_def(2) + unfolding ts_at_tau[OF reach_tj''' i_lt_rho'', symmetric] + ts_at_tau[OF reach_tj''' l_lt_rho, symmetric] mem_def + by auto + then have "memL (ts_at rho'' i) (ts_at rho'' tp) I" + using ts_at_mono[OF reach_tj''' tstp_def(2)] tstp_def(3) j'_le_rho'' memL_mono' + by auto + then show "case snd (the (mmap_lookup s' {0})) of None \ False + | Some tstp \ memL t (fst tstp) I" + using lookup_sup_acc tstp_def j'_le_rho'' + sup_acc_concat_cong[of j' "take j' rho''" step accept "drop j' rho''"] + by (auto simp: tbi_def split: option.splits) + qed + have "valid_matchF I t0 sub (take j'' rho'') i'' (adv_start args w')" + proof - + have "\l \ {i'..l \ {i''.. \ i, sat (MatchF I r) i), w'')" + unfolding j''_def adv_start_last[symmetric] adv_last_bounds valid_after rho''_def + eval_matchF.simps run_t_read[OF tbi_def(1)[unfolded ti_def]] + using tbj'_def[unfolded tj'_def] not_ets_te[folded tbi_def(3)] + b_alt[unfolded s'_def] t_def adv_start_last w'_def + by (auto simp only: Let_def split: option.splits if_splits) + ultimately show ?thesis + unfolding j''_def adv_start_last[symmetric] adv_last_bounds valid_after rho''_def + by auto +qed + +lemma valid_eval_matchF_sound: + assumes valid_before: "valid_matchF I t0 sub rho i w" + and eval: "eval_mF I w = Some ((t, b), w'')" + and bounded: "right I \ tfin" + and wf: "wf_regex r" +shows "t = \ \ i \ b = sat (MatchF I r) i \ (\rho'. valid_matchF I t0 sub rho' (Suc i) w'')" +proof - + obtain rho' t tm where rho'_def: "reaches_on (w_run_t args) (w_tj w) (map fst rho') (w_tj w'')" + "reaches_on (w_run_sub args) (w_sj w) (map snd rho') (w_sj w'')" + "w_read_t args (w_ti w) = Some t" + "w_read_t args (w_tj w'') = Some tm" + "\memR t tm I" + using valid_eval_matchF_Some[OF assms(1-3)] + by auto + show ?thesis + using valid_eval_matchF_complete[OF assms(1) rho'_def wf] + unfolding eval + by blast +qed + +thm valid_eval_matchP +thm valid_eval_matchF_sound +thm valid_eval_matchF_complete + +end + +end diff --git a/thys/VYDRA_MDL/Timestamp.thy b/thys/VYDRA_MDL/Timestamp.thy new file mode 100644 --- /dev/null +++ b/thys/VYDRA_MDL/Timestamp.thy @@ -0,0 +1,147 @@ +theory Timestamp + imports "HOL-Library.Extended_Nat" "HOL-Library.Extended_Real" +begin + +class timestamp = comm_monoid_add + semilattice_sup + + fixes tfin :: "'a set" and \ :: "nat \ 'a" + assumes \_mono: "\i j. i \ j \ \ i \ \ j" + and \_fin: "\i. \ i \ tfin" + and \_progressing: "x \ tfin \ \j. \\ j \ \ i + x" + and zero_tfin: "0 \ tfin" + and tfin_closed: "c \ tfin \ d \ tfin \ c + d \ tfin" + and add_mono: "c \ d \ a + c \ a + d" + and add_pos: "a \ tfin \ 0 < c \ a < a + c" +begin + +lemma add_mono_comm: + fixes a :: 'a + shows "c \ d \ c + a \ d + a" + by (auto simp: add.commute add_mono) + +end + +instantiation prod :: (comm_monoid_add, comm_monoid_add) comm_monoid_add +begin + +definition zero_prod :: "'a \ 'b" where + "zero_prod = (zero_class.zero, zero_class.zero)" + +fun plus_prod :: "'a \ 'b \ 'a \ 'b \ 'a \ 'b" where + "(a, b) + (c, d) = (a + c, b + d)" + +instance + by standard (auto simp: zero_prod_def ac_simps) + +end + +instantiation enat :: timestamp +begin + +definition tfin_enat :: "enat set" where + "tfin_enat = UNIV - {\}" + +definition \_enat :: "nat \ enat" where + "\_enat n = n" + +instance + by standard (auto simp add: \_enat_def tfin_enat_def dest!: leD) + +end + +instantiation ereal :: timestamp +begin + +definition \_ereal :: "nat \ ereal" where + "\_ereal n = ereal n" + +definition tfin_ereal :: "ereal set" where + "tfin_ereal = UNIV - {-\, \}" + +lemma ereal_add_pos: + fixes a :: ereal + shows "a \ tfin \ 0 < c \ a < a + c" + by (auto simp: tfin_ereal_def) (metis add.right_neutral ereal_add_cancel_left ereal_le_add_self order_less_le) + +instance + by standard (auto simp add: \_ereal_def tfin_ereal_def add.commute + ereal_add_le_add_iff2 not_le less_PInf_Ex_of_nat ereal_less_ereal_Ex reals_Archimedean2 intro: ereal_add_pos) + +end + +class timestamp_strict = timestamp + + assumes timestamp_strict_total: "a \ b \ b \ a" + and add_mono_strict: "c < d \ a + c < a + d" + +instantiation nat :: timestamp_strict +begin + +definition tfin_nat :: "nat set" where + "tfin_nat = UNIV" + +definition \_nat :: "nat \ nat" where + "\_nat n = n" + +instance + by standard (auto simp add: \_nat_def tfin_nat_def dest!: leD) + +end + +instantiation real :: timestamp_strict +begin + +definition tfin_real :: "real set" where "tfin_real = UNIV" + +definition \_real :: "nat \ real" where "\_real n = real n" +instance + by standard (auto simp: tfin_real_def \_real_def not_le reals_Archimedean2) + +end + +class timestamp_total = timestamp + + assumes timestamp_total: "a \ b \ b \ a" + assumes aux: "0 \ a \ a \ c \ a \ tfin \ c \ tfin \ 0 \ b \ b \ tfin \ c < a + b" + +instantiation enat :: timestamp_total +begin + +instance + apply standard + apply (auto simp: tfin_enat_def) + done + +end + +instantiation ereal :: timestamp_total +begin + +instance + apply standard + apply (auto simp: tfin_ereal_def) + done + +end + +class timestamp_total_strict = timestamp_total + + assumes add_mono_strict_total: "c < d \ a + c < a + d" + +instantiation nat :: timestamp_total_strict +begin + +instance + apply standard + apply (auto simp: tfin_nat_def) + done + +end + +instantiation real :: timestamp_total_strict +begin + +instance + apply standard + apply (auto simp: tfin_real_def) + done + +end + +end diff --git a/thys/VYDRA_MDL/Timestamp_Lex.thy b/thys/VYDRA_MDL/Timestamp_Lex.thy new file mode 100644 --- /dev/null +++ b/thys/VYDRA_MDL/Timestamp_Lex.thy @@ -0,0 +1,80 @@ +theory Timestamp_Lex + imports Timestamp +begin + +instantiation prod :: (timestamp_strict, timestamp_strict) timestamp_strict +begin + +definition tfin_prod :: "('a \ 'b) set" where + "tfin_prod = tfin \ UNIV" + +definition \_prod :: "nat \ 'a \ 'b" where + "\_prod n = (\ n, \ n)" + +fun sup_prod :: "'a \ 'b \ 'a \ 'b \ 'a \ 'b" where + "sup_prod (a, b) (c, d) = (if a < c then (c, d) else if c < a then (a, b) else (a, sup b d))" + +fun less_eq_prod :: "'a \ 'b \ 'a \ 'b \ bool" where + "less_eq_prod (a, b) (c, d) \ a < c \ (a = c \ b \ d)" + +definition less_prod :: "'a \ 'b \ 'a \ 'b \ bool" where + "less_prod x y \ x \ y \ x \ y" + +instance + apply standard + apply (auto simp: zero_prod_def less_prod_def)[2] + subgoal for x y z + using order.strict_trans + by (cases x; cases y; cases z) auto + subgoal for x y + by (cases x; cases y) auto + subgoal for x y + by (cases x; cases y) (auto simp add: sup.commute sup.strict_order_iff) + subgoal for x y + apply (cases x; cases y) + apply (auto simp add: sup.commute sup.strict_order_iff) + apply (metis sup.absorb_iff2 sup.order_iff timestamp_strict_total) + done + subgoal for y x z + by (cases x; cases y; cases z) auto + subgoal for i j + using \_mono less_le + apply (auto simp: \_prod_def less_prod_def) + by (simp add: \_mono) + subgoal for i + by (auto simp: \_prod_def tfin_prod_def intro: \_fin) + subgoal for x i + apply (cases x) + apply (auto simp: \_prod_def tfin_prod_def) + apply (metis \_progressing dual_order.refl order_less_le) + done + apply (auto simp: tfin_prod_def tfin_closed)[1] + apply (auto simp: zero_prod_def tfin_prod_def intro: zero_tfin)[1] + subgoal for c d + by (cases c; cases d) (auto simp: tfin_prod_def intro: tfin_closed) + subgoal for c d a + by (cases c; cases d; cases a) (auto simp: add_mono add_mono_strict) + subgoal for a c + apply (cases a; cases c) + apply (auto simp: tfin_prod_def zero_prod_def) + apply (metis less_eq_prod.simps add.right_neutral add_mono_strict less_prod_def order_le_less order_less_le prod.inject) + done + subgoal for a b + apply (cases a; cases b) + apply (auto) + apply (metis antisym_conv1 timestamp_strict_total) + apply (metis antisym_conv1 timestamp_strict_total) + apply (metis antisym_conv1 timestamp_strict_total) + apply (metis timestamp_strict_total) + done + subgoal for c d a + apply (cases c; cases d; cases a) + apply (auto simp add: add_mono_strict less_prod_def order.strict_implies_order) + apply (metis add_mono_strict sup.strict_order_iff) + apply (metis add_mono_strict sup.strict_order_iff) + by (metis add_mono_strict dual_order.order_iff_strict less_le_not_le) + done + +end + +end \ No newline at end of file diff --git a/thys/VYDRA_MDL/Timestamp_Lex_Total.thy b/thys/VYDRA_MDL/Timestamp_Lex_Total.thy new file mode 100644 --- /dev/null +++ b/thys/VYDRA_MDL/Timestamp_Lex_Total.thy @@ -0,0 +1,93 @@ +theory Timestamp_Lex_Total + imports Timestamp +begin + +instantiation prod :: (timestamp_total_strict, timestamp_total_strict) timestamp_total_strict +begin + +definition tfin_prod :: "('a \ 'b) set" where + "tfin_prod = tfin \ UNIV" + +definition \_prod :: "nat \ 'a \ 'b" where + "\_prod n = (\ n, \ n)" + +fun sup_prod :: "'a \ 'b \ 'a \ 'b \ 'a \ 'b" where + "sup_prod (a, b) (c, d) = (if a < c then (c, d) else if c < a then (a, b) else (a, sup b d))" + +fun less_eq_prod :: "'a \ 'b \ 'a \ 'b \ bool" where + "less_eq_prod (a, b) (c, d) \ a < c \ (a = c \ b \ d)" + +definition less_prod :: "'a \ 'b \ 'a \ 'b \ bool" where + "less_prod x y \ x \ y \ x \ y" + +instance + apply standard + apply (auto simp: zero_prod_def less_prod_def)[2] + subgoal for x y z + using order.strict_trans + by (cases x; cases y; cases z) auto + subgoal for x y + by (cases x; cases y) auto + subgoal for x y + by (cases x; cases y) (auto simp add: sup.commute sup.strict_order_iff) + subgoal for x y + apply (cases x; cases y) + apply (auto simp add: sup.commute sup.strict_order_iff) + apply (metis sup.absorb_iff2 sup.order_iff timestamp_total) + done + subgoal for y x z + by (cases x; cases y; cases z) auto + subgoal for i j + using \_mono less_le + apply (auto simp: \_prod_def less_prod_def) + by (simp add: \_mono) + subgoal for i + by (auto simp: \_prod_def tfin_prod_def intro: \_fin) + subgoal for x i + apply (cases x) + apply (auto simp: \_prod_def tfin_prod_def) + apply (metis \_progressing dual_order.refl order_less_le) + done + apply (auto simp: tfin_prod_def tfin_closed)[1] + apply (auto simp: zero_prod_def tfin_prod_def intro: zero_tfin)[1] + subgoal for c d + apply (cases c; cases d) + apply (auto simp: tfin_prod_def intro: tfin_closed) + done + subgoal for c d a + by (cases c; cases d; cases a) (auto simp: add_mono add_mono_strict_total) + subgoal for a c + apply (cases a; cases c) + apply (auto simp: tfin_prod_def zero_prod_def) + apply (metis less_eq_prod.simps add.right_neutral add_mono_strict_total less_prod_def order_less_le prod.inject) + done + subgoal for a b + apply (cases a; cases b) + apply (auto) + apply (metis antisym_conv1 timestamp_total) + apply (metis antisym_conv1 timestamp_total) + apply (metis antisym_conv1 timestamp_total) + apply (metis timestamp_total) + done + subgoal for a c b + apply (cases a; cases c; cases b) + apply (auto simp: zero_prod_def tfin_prod_def) + apply (metis less_eq_prod.simps aux less_prod_def order_less_imp_le order_less_irrefl prod.sel(1)) + using zero_tfin apply blast + apply (metis less_eq_prod.simps add_pos less_prod_def order_less_le prod.inject) + using zero_tfin apply blast + apply (smt (z3) add_0 aux less_eq_prod.simps less_prod_def order_le_less order_le_less_trans order_less_irrefl) + using less_prod_def + apply force + done + subgoal for c d a + apply (cases c; cases d; cases a) + apply (auto simp add: add_mono_strict_total less_prod_def order.strict_implies_order) + apply (metis add_mono_strict_total sup.strict_order_iff) + apply (metis add_mono_strict_total sup.strict_order_iff) + by (metis add_mono_strict_total dual_order.order_iff_strict less_le_not_le) + done + +end + +end diff --git a/thys/VYDRA_MDL/Timestamp_Prod.thy b/thys/VYDRA_MDL/Timestamp_Prod.thy new file mode 100644 --- /dev/null +++ b/thys/VYDRA_MDL/Timestamp_Prod.thy @@ -0,0 +1,49 @@ +theory Timestamp_Prod + imports Timestamp +begin + +instantiation prod :: (timestamp, timestamp) timestamp +begin + +definition tfin_prod :: "('a \ 'b) set" where + "tfin_prod = tfin \ tfin" + +definition \_prod :: "nat \ 'a \ 'b" where + "\_prod n = (\ n, \ n)" + +fun sup_prod :: "'a \ 'b \ 'a \ 'b \ 'a \ 'b" where + "sup_prod (a, b) (c, d) = (sup a c, sup b d)" + +fun less_eq_prod :: "'a \ 'b \ 'a \ 'b \ bool" where + "less_eq_prod (a, b) (c, d) \ a \ c \ b \ d" + +definition less_prod :: "'a \ 'b \ 'a \ 'b \ bool" where + "less_prod x y \ x \ y \ x \ y" + +instance + apply standard + apply (auto simp: add.commute zero_prod_def less_prod_def)[7] + subgoal for i j + using \_mono \_mono less_le + by (fastforce simp: \_prod_def less_prod_def) + subgoal for i + by (auto simp: \_prod_def tfin_prod_def intro: \_fin) + subgoal for x i + apply (cases x) + using \_progressing + by (auto simp: tfin_prod_def \_prod_def) + apply (auto simp: zero_prod_def tfin_prod_def intro: zero_tfin)[1] + subgoal for c d + by (cases c; cases d) (auto simp: tfin_prod_def intro: tfin_closed) + subgoal for c d a + by (cases c; cases d; cases a) (auto simp add: add_mono_strict add_mono) + subgoal for a c + apply (cases a; cases c) + apply (auto simp: tfin_prod_def zero_prod_def) + apply (metis add.right_neutral add_pos less_eq_prod.simps less_prod_def order_less_le prod.inject timestamp_class.add_mono) + done + done + +end + +end diff --git a/thys/VYDRA_MDL/Trace.thy b/thys/VYDRA_MDL/Trace.thy new file mode 100644 --- /dev/null +++ b/thys/VYDRA_MDL/Trace.thy @@ -0,0 +1,112 @@ +(*<*) +theory Trace + imports "HOL-Library.Stream" Timestamp +begin +(*>*) + +section \Infinite Traces\ + +inductive sorted_list :: "'a :: order list \ bool" where + [intro]: "sorted_list []" +| [intro]: "sorted_list [x]" +| [intro]: "x \ y \ sorted_list (y # ys) \ sorted_list (x # y # ys)" + +lemma sorted_list_app: "sorted_list xs \ (\x. x \ set xs \ x \ y) \ sorted_list (xs @ [y])" + by (induction xs rule: sorted_list.induct) auto + +lemma sorted_list_drop: "sorted_list xs \ sorted_list (drop n xs)" +proof (induction xs arbitrary: n rule: sorted_list.induct) + case (2 x n) + then show ?case + by (cases n) auto +next + case (3 x y ys n) + then show ?case + by (cases n) auto +qed auto + +lemma sorted_list_ConsD: "sorted_list (x # xs) \ sorted_list xs" + by (auto elim: sorted_list.cases) + +lemma sorted_list_Cons_nth: "sorted_list (x # xs) \ j < length xs \ x \ xs ! j" + by (induction "x # xs" arbitrary: x xs j rule: sorted_list.induct) + (fastforce simp: nth_Cons split: nat.splits)+ + +lemma sorted_list_atD: "sorted_list xs \ i \ j \ j < length xs \ xs ! i \ xs ! j" +proof (induction xs arbitrary: i j rule: sorted_list.induct) + case (2 x i j) + then show ?case + by (cases i) auto +next + case (3 x y ys i j) + have "x \ (x # y # ys) ! j" + using 3(5) sorted_list_Cons_nth[OF sorted_list.intros(3)[OF 3(1,2)]] + by (auto simp: nth_Cons split: nat.splits) + then show ?case + using 3 + by (cases i) auto +qed auto + +coinductive ssorted :: "'a :: order stream \ bool" where + "shd s \ shd (stl s) \ ssorted (stl s) \ ssorted s" + +lemma ssorted_siterate[simp]: "(\n. n \ f n) \ ssorted (siterate f n)" + by (coinduction arbitrary: n) auto + +lemma ssortedD: "ssorted s \ s !! i \ stl s !! i" + by (induct i arbitrary: s) (auto elim: ssorted.cases) + +lemma ssorted_sdrop: "ssorted s \ ssorted (sdrop i s)" + by (coinduction arbitrary: i s) (auto elim: ssorted.cases ssortedD) + +lemma ssorted_monoD: "ssorted s \ i \ j \ s !! i \ s !! j" +proof (induct "j - i" arbitrary: j) + case (Suc x) + from Suc(1)[of "j - 1"] Suc(2-4) ssortedD[of s "j - 1"] + show ?case by (cases j) (auto simp: le_Suc_eq Suc_diff_le) +qed simp + +lemma sorted_stake: "ssorted s \ sorted_list (stake i s)" +proof (induct i arbitrary: s) + case (Suc i) + then show ?case + by (cases i) (auto elim: ssorted.cases) +qed auto + +lemma ssorted_monoI: "\i j. i \ j \ s !! i \ s !! j \ ssorted s" + by (coinduction arbitrary: s) + (auto dest: spec2[of _ "Suc _" "Suc _"] spec2[of _ 0 "Suc 0"]) + +lemma ssorted_iff_mono: "ssorted s \ (\i j. i \ j \ s !! i \ s !! j)" + using ssorted_monoI ssorted_monoD by metis + +typedef (overloaded) ('a, 'b :: timestamp) trace = "{s :: ('a set \ 'b) stream. + ssorted (smap snd s) \ (\x. x \ snd ` sset s \ x \ tfin) \ (\i x. x \ tfin \ (\j. \snd (s !! j) \ snd (s !! i) + x))}" + by (auto simp: \_mono \_fin \_progressing stream.set_map + intro!: exI[of _ "smap (\n. ({}, \ n)) nats"] ssorted_monoI) + +setup_lifting type_definition_trace + +lift_definition \ :: "('a, 'b :: timestamp) trace \ nat \ 'a set" is + "\s i. fst (s !! i)" . +lift_definition \ :: "('a, 'b :: timestamp) trace \ nat \ 'b" is + "\s i. snd (s !! i)" . + +lemma \_mono[simp]: "i \ j \ \ s i \ \ s j" + by transfer (auto simp: ssorted_iff_mono) + +lemma \_fin: "\ \ i \ tfin" + by transfer auto + +lemma ex_lt_\: "x \ tfin \ \j. \\ s j \ \ s i + x" + by transfer auto + +lemma le_\_less: "\ \ i \ \ \ j \ j < i \ \ \ i = \ \ j" + by (simp add: antisym) + +lemma less_\D: "\ \ i < \ \ j \ i < j" + by (meson \_mono less_le_not_le not_le_imp_less) + +(*<*) +end +(*>*) diff --git a/thys/VYDRA_MDL/Window.thy b/thys/VYDRA_MDL/Window.thy new file mode 100644 --- /dev/null +++ b/thys/VYDRA_MDL/Window.thy @@ -0,0 +1,1817 @@ +theory Window + imports "HOL-Library.AList" "HOL-Library.Mapping" "HOL-Library.While_Combinator" Timestamp +begin + +type_synonym ('a, 'b) mmap = "('a \ 'b) list" + +(* 'b is a polymorphic input symbol; 'c is a polymorphic DFA state; + 'd is a timestamp; 'e is a submonitor state *) + +inductive chain_le :: "'d :: timestamp list \ bool" where + chain_le_Nil: "chain_le []" +| chain_le_singleton: "chain_le [x]" +| chain_le_cons: "chain_le (y # xs) \ x \ y \ chain_le (x # y # xs)" + +lemma chain_le_app: "chain_le (zs @ [z]) \ z \ w \ chain_le ((zs @ [z]) @ [w])" + apply (induction "zs @ [z]" arbitrary: zs rule: chain_le.induct) + apply (auto intro: chain_le.intros)[2] + subgoal for y xs x zs + apply (cases zs) + apply (auto) + apply (metis append.assoc append_Cons append_Nil chain_le_cons) + done + done + +inductive reaches_on :: "('e \ ('e \ 'f) option) \ 'e \ 'f list \ 'e \ bool" + for run :: "'e \ ('e \ 'f) option" where + "reaches_on run s [] s" + | "run s = Some (s', v) \ reaches_on run s' vs s'' \ reaches_on run s (v # vs) s''" + +lemma reaches_on_init_Some: "reaches_on r s xs s' \ r s' \ None \ r s \ None" + by (auto elim: reaches_on.cases) + +lemma reaches_on_split: "reaches_on run s vs s' \ i < length vs \ + \s'' s'''. reaches_on run s (take i vs) s'' \ run s'' = Some (s''', vs ! i) \ reaches_on run s''' (drop (Suc i) vs) s'" +proof (induction s vs s' arbitrary: i rule: reaches_on.induct) + case (2 s s' v vs s'') + show ?case + using 2(1,2) + proof (cases i) + case (Suc n) + show ?thesis + using 2 + by (fastforce simp: Suc intro: reaches_on.intros) + qed (auto intro: reaches_on.intros) +qed auto + +lemma reaches_on_split': "reaches_on run s vs s' \ i \ length vs \ + \s'' . reaches_on run s (take i vs) s'' \ reaches_on run s'' (drop i vs) s'" +proof (induction s vs s' arbitrary: i rule: reaches_on.induct) + case (2 s s' v vs s'') + show ?case + using 2(1,2) + proof (cases i) + case (Suc n) + show ?thesis + using 2 + by (fastforce simp: Suc intro: reaches_on.intros) + qed (auto intro: reaches_on.intros) +qed (auto intro: reaches_on.intros) + +lemma reaches_on_split_app: "reaches_on run s (vs @ vs') s' \ + \s''. reaches_on run s vs s'' \ reaches_on run s'' vs' s'" + using reaches_on_split'[where i="length vs", of run s "vs @ vs'" s'] + by auto + +lemma reaches_on_inj: "reaches_on run s vs t \ reaches_on run s vs' t' \ + length vs = length vs' \ vs = vs' \ t = t'" + apply (induction s vs t arbitrary: vs' t' rule: reaches_on.induct) + apply (auto elim: reaches_on.cases)[1] + subgoal for s s' v vs s'' vs' t' + apply (rule reaches_on.cases[of run s' vs s'']; rule reaches_on.cases[of run s vs' t']) + apply assumption+ + apply auto[2] + apply fastforce + apply (metis length_0_conv list.discI) + apply (metis Pair_inject length_Cons nat.inject option.inject) + done + done + +lemma reaches_on_split_last: "reaches_on run s (xs @ [x]) s'' \ + \s'. reaches_on run s xs s' \ run s' = Some (s'', x)" + apply (induction s "xs @ [x]" s'' arbitrary: xs x rule: reaches_on.induct) + apply simp + subgoal for s s' v vs s'' xs x + by (cases vs rule: rev_cases) (fastforce elim: reaches_on.cases intro: reaches_on.intros)+ + done + +lemma reaches_on_rev_induct[consumes 1]: "reaches_on run s vs s' \ + (\s. P s [] s) \ + (\s s' v vs s''. reaches_on run s vs s' \ P s vs s' \ run s' = Some (s'', v) \ + P s (vs @ [v]) s'') \ + P s vs s'" +proof (induction vs arbitrary: s s' rule: rev_induct) + case (snoc x xs) + from snoc(2) obtain s'' where s''_def: "reaches_on run s xs s''" "run s'' = Some (s', x)" + using reaches_on_split_last + by fast + show ?case + using snoc(4)[OF s''_def(1) _ s''_def(2)] snoc(1)[OF s''_def(1) snoc(3,4)] + by auto +qed (auto elim: reaches_on.cases) + +lemma reaches_on_app: "reaches_on run s vs s' \ run s' = Some (s'', v) \ + reaches_on run s (vs @ [v]) s''" + by (induction s vs s' rule: reaches_on.induct) (auto intro: reaches_on.intros) + +lemma reaches_on_trans: "reaches_on run s vs s' \ reaches_on run s' vs' s'' \ + reaches_on run s (vs @ vs') s''" + by (induction s vs s' rule: reaches_on.induct) (auto intro: reaches_on.intros) + +lemma reaches_onD: "reaches_on run s ((t, b) # vs) s' \ + \s''. run s = Some (s'', (t, b)) \ reaches_on run s'' vs s'" + by (auto elim: reaches_on.cases) + +lemma reaches_on_setD: "reaches_on run s vs s' \ x \ set vs \ + \vs' vs'' s''. reaches_on run s (vs' @ [x]) s'' \ reaches_on run s'' vs'' s' \ vs = vs' @ x # vs''" +proof (induction s vs s' rule: reaches_on_rev_induct) + case (2 s s' v vs s'') + show ?case + proof (cases "x \ set vs") + case True + obtain vs' vs'' s''' where split_def: "reaches_on run s (vs' @ [x]) s'''" + "reaches_on run s''' vs'' s'" "vs = vs' @ x # vs''" + using 2(3)[OF True] + by auto + show ?thesis + using split_def(1,3) reaches_on_app[OF split_def(2) 2(2)] + by auto + next + case False + have x_v: "x = v" + using 2(4) False + by auto + show ?thesis + unfolding x_v + using reaches_on_app[OF 2(1,2)] reaches_on.intros(1)[of run s''] + by auto + qed +qed auto + +lemma reaches_on_len: "\vs s'. reaches_on run s vs s' \ (length vs = n \ run s' = None)" +proof (induction n arbitrary: s) + case (Suc n) + show ?case + proof (cases "run s") + case (Some x) + obtain s' v where x_def: "x = (s', v)" + by (cases x) auto + obtain vs s'' where s''_def: "reaches_on run s' vs s''" "length vs = n \ run s'' = None" + using Suc[of s'] + by auto + show ?thesis + using reaches_on.intros(2)[OF Some[unfolded x_def] s''_def(1)] s''_def(2) + by fastforce + qed (auto intro: reaches_on.intros) +qed (auto intro: reaches_on.intros) + +lemma reaches_on_NilD: "reaches_on run q [] q' \ q = q'" + by (auto elim: reaches_on.cases) + +lemma reaches_on_ConsD: "reaches_on run q (x # xs) q' \ \q''. run q = Some (q'', x) \ reaches_on run q'' xs q'" + by (auto elim: reaches_on.cases) + +inductive reaches :: "('e \ ('e \ 'f) option) \ 'e \ nat \ 'e \ bool" + for run :: "'e \ ('e \ 'f) option" where + "reaches run s 0 s" + | "run s = Some (s', v) \ reaches run s' n s'' \ reaches run s (Suc n) s''" + +lemma reaches_Suc_split_last: "reaches run s (Suc n) s' \ \s'' x. reaches run s n s'' \ run s'' = Some (s', x)" +proof (induction n arbitrary: s) + case (Suc n) + obtain s'' x where s''_def: "run s = Some (s'', x)" "reaches run s'' (Suc n) s'" + using Suc(2) + by (auto elim: reaches.cases) + show ?case + using s''_def(1) Suc(1)[OF s''_def(2)] + by (auto intro: reaches.intros) +qed (auto elim!: reaches.cases intro: reaches.intros) + +lemma reaches_invar: "reaches f x n y \ P x \ (\z z' v. P z \ f z = Some (z', v) \ P z') \ P y" + by (induction x n y rule: reaches.induct) auto + +lemma reaches_cong: "reaches f x n y \ P x \ (\z z' v. P z \ f z = Some (z', v) \ P z') \ (\z. P z \ f' (g z) = map_option (apfst g) (f z)) \ reaches f' (g x) n (g y)" + by (induction x n y rule: reaches.induct) (auto intro: reaches.intros) + +lemma reaches_on_n: "reaches_on run s vs s' \ reaches run s (length vs) s'" + by (induction s vs s' rule: reaches_on.induct) (auto intro: reaches.intros) + +lemma reaches_on: "reaches run s n s' \ \vs. reaches_on run s vs s' \ length vs = n" + by (induction s n s' rule: reaches.induct) (auto intro: reaches_on.intros) + +definition ts_at :: "('d \ 'b) list \ nat \ 'd" where + "ts_at rho i = fst (rho ! i)" + +definition bs_at :: "('d \ 'b) list \ nat \ 'b" where + "bs_at rho i = snd (rho ! i)" + +fun sub_bs :: "('d \ 'b) list \ nat \ nat \ 'b list" where + "sub_bs rho (i, j) = map (bs_at rho) [i.. 'b \ 'c) \ ('d \ 'b) list \ 'c \ nat \ nat \ 'c" where + "steps step rho q ij = foldl step q (sub_bs rho ij)" + +definition acc :: "('c \ 'b \ 'c) \ ('c \ bool) \ ('d \ 'b) list \ + 'c \ nat \ nat \ bool" where + "acc step accept rho q ij = accept (steps step rho q ij)" + +definition sup_acc :: "('c \ 'b \ 'c) \ ('c \ bool) \ ('d \ 'b) list \ + 'c \ nat \ nat \ ('d \ nat) option" where + "sup_acc step accept rho q i j = + (let L' = {l \ {i.. ('c \ 'b \ 'c) \ ('d \ 'b) list \ + nat \ nat \ 'c \ 'd option" where + "sup_leadsto init step rho i j q = + (let L' = {l. l < i \ steps step rho init (l, j) = q}; m = Max L' in + if L' = {} then None else Some (ts_at rho m))" + +definition mmap_keys :: "('a, 'b) mmap \ 'a set" where + "mmap_keys kvs = set (map fst kvs)" + +definition mmap_lookup :: "('a, 'b) mmap \ 'a \ 'b option" where + "mmap_lookup = map_of" + +definition valid_s :: "'c \ ('c \ 'b \ 'c) \ ('c \ 'b, 'c) mapping \ ('c \ bool) \ + ('d \ 'b) list \ nat \ nat \ nat \ ('c, 'c \ ('d \ nat) option) mmap \ bool" where + "valid_s init step st accept rho u i j s \ + (\q bs. case Mapping.lookup st (q, bs) of None \ True | Some v \ step q bs = v) \ + (mmap_keys s = {q. (\l \ u. steps step rho init (l, i) = q)} \ distinct (map fst s) \ + (\q. case mmap_lookup s q of None \ True + | Some (q', tstp) \ steps step rho q (i, j) = q' \ tstp = sup_acc step accept rho q i j))" + +record ('b, 'c, 'd, 't, 'e) args = + w_init :: 'c + w_step :: "'c \ 'b \ 'c" + w_accept :: "'c \ bool" + w_run_t :: "'t \ ('t \ 'd) option" + w_read_t :: "'t \ 'd option" + w_run_sub :: "'e \ ('e \ 'b) option" + +record ('b, 'c, 'd, 't, 'e) window = + w_st :: "('c \ 'b, 'c) mapping" + w_ac :: "('c, bool) mapping" + w_i :: nat + w_ti :: 't + w_si :: 'e + w_j :: nat + w_tj :: 't + w_sj :: 'e + w_s :: "('c, 'c \ ('d \ nat) option) mmap" + w_e :: "('c, 'd) mmap" + +copy_bnf (dead 'b, dead 'c, dead 'd, dead 't, 'e, dead 'ext) window_ext + +fun reach_window :: "('b, 'c, 'd, 't, 'e) args \ 't \ 'e \ + ('d \ 'b) list \ nat \ 't \ 'e \ nat \ 't \ 'e \ bool" where + "reach_window args t0 sub rho (i, ti, si, j, tj, sj) \ i \ j \ length rho = j \ + reaches_on (w_run_t args) t0 (take i (map fst rho)) ti \ + reaches_on (w_run_t args) ti (drop i (map fst rho)) tj \ + reaches_on (w_run_sub args) sub (take i (map snd rho)) si \ + reaches_on (w_run_sub args) si (drop i (map snd rho)) sj" + +lemma reach_windowI: "reaches_on (w_run_t args) t0 (take i (map fst rho)) ti \ + reaches_on (w_run_sub args) sub (take i (map snd rho)) si \ + reaches_on (w_run_t args) t0 (map fst rho) tj \ + reaches_on (w_run_sub args) sub (map snd rho) sj \ + i \ length rho \ length rho = j \ + reach_window args t0 sub rho (i, ti, si, j, tj, sj)" + by auto (metis reaches_on_split'[of _ _ _ _ i] length_map reaches_on_inj)+ + +lemma reach_window_shift: + assumes "reach_window args t0 sub rho (i, ti, si, j, tj, sj)" "i < j" + "w_run_t args ti = Some (ti', t)" "w_run_sub args si = Some (si', s)" + shows "reach_window args t0 sub rho (Suc i, ti', si', j, tj, sj)" + using reaches_on_app[of "w_run_t args" t0 "take i (map fst rho)" ti ti' t] + reaches_on_app[of "w_run_sub args" sub "take i (map snd rho)" si si' s] assms + apply (auto) + apply (smt append_take_drop_id id_take_nth_drop length_map list.discI list.inject + option.inject reaches_on.cases same_append_eq snd_conv take_Suc_conv_app_nth) + apply (smt Cons_nth_drop_Suc fst_conv length_map list.discI list.inject option.inject + reaches_on.cases) + apply (smt append_take_drop_id id_take_nth_drop length_map list.discI list.inject + option.inject reaches_on.cases same_append_eq snd_conv take_Suc_conv_app_nth) + apply (smt Cons_nth_drop_Suc fst_conv length_map list.discI list.inject option.inject + reaches_on.cases) + done + +lemma reach_window_run_ti: "reach_window args t0 sub rho (i, ti, si, j, tj, sj) \ + i < j \ \ti'. reaches_on (w_run_t args) t0 (take i (map fst rho)) ti \ + w_run_t args ti = Some (ti', ts_at rho i) \ + reaches_on (w_run_t args) ti' (drop (Suc i) (map fst rho)) tj" + apply (auto simp: ts_at_def elim!: reaches_on.cases[of "w_run_t args" ti "drop i (map fst rho)"]) + using nth_via_drop apply fastforce + by (metis Cons_nth_drop_Suc length_map list.inject) + +lemma reach_window_run_si: "reach_window args t0 sub rho (i, ti, si, j, tj, sj) \ + i < j \ \si'. reaches_on (w_run_sub args) sub (take i (map snd rho)) si \ + w_run_sub args si = Some (si', bs_at rho i) \ + reaches_on (w_run_sub args) si' (drop (Suc i) (map snd rho)) sj" + apply (auto simp: bs_at_def elim!: reaches_on.cases[of "w_run_sub args" si "drop i (map snd rho)"]) + using nth_via_drop apply fastforce + by (metis Cons_nth_drop_Suc length_map list.inject) + +lemma reach_window_run_tj: "reach_window args t0 sub rho (i, ti, si, j, tj, sj) \ + reaches_on (w_run_t args) t0 (map fst rho) tj" + using reaches_on_trans + by fastforce + +lemma reach_window_run_sj: "reach_window args t0 sub rho (i, ti, si, j, tj, sj) \ + reaches_on (w_run_sub args) sub (map snd rho) sj" + using reaches_on_trans + by fastforce + +lemma reach_window_shift_all: "reach_window args t0 sub rho (i, si, ti, j, sj, tj) \ + reach_window args t0 sub rho (j, sj, tj, j, sj, tj)" + using reach_window_run_tj[of args t0 sub rho] reach_window_run_sj[of args t0 sub rho] + by (auto intro: reaches_on.intros) + +lemma reach_window_app: "reach_window args t0 sub rho (i, si, ti, j, tj, sj) \ + w_run_t args tj = Some (tj', x) \ w_run_sub args sj = Some (sj', y) \ + reach_window args t0 sub (rho @ [(x, y)]) (i, si, ti, Suc j, tj', sj')" + by (fastforce simp add: reaches_on_app) + +fun init_args :: "('c \ ('c \ 'b \ 'c) \ ('c \ bool)) \ + (('t \ ('t \ 'd) option) \ ('t \ 'd option)) \ + ('e \ ('e \ 'b) option) \ ('b, 'c, 'd, 't, 'e) args" where + "init_args (init, step, accept) (run_t, read_t) run_sub = + \w_init = init, w_step = step, w_accept = accept, w_run_t = run_t, w_read_t = read_t, w_run_sub = run_sub\" + +fun init_window :: "('b, 'c, 'd, 't, 'e) args \ 't \ 'e \ ('b, 'c, 'd, 't, 'e) window" where + "init_window args t0 sub = \w_st = Mapping.empty, w_ac = Mapping.empty, + w_i = 0, w_ti = t0, w_si = sub, w_j = 0, w_tj = t0, w_sj = sub, + w_s =[(w_init args, (w_init args, None))], w_e = []\" + +definition valid_window :: "('b, 'c, 'd :: timestamp, 't, 'e) args \ 't \ 'e \ ('d \ 'b) list \ + ('b, 'c, 'd, 't, 'e) window \ bool" where + "valid_window args t0 sub rho w \ + (let init = w_init args; step = w_step args; accept = w_accept args; + run_t = w_run_t args; run_sub = w_run_sub args; + st = w_st w; ac = w_ac w; + i = w_i w; ti = w_ti w; si = w_si w; j = w_j w; tj = w_tj w; sj = w_sj w; + s = w_s w; e = w_e w in + (reach_window args t0 sub rho (i, ti, si, j, tj, sj) \ + (\i j. i \ j \ j < length rho \ ts_at rho i \ ts_at rho j) \ + (\q. case Mapping.lookup ac q of None \ True | Some v \ accept q = v) \ + (\q. mmap_lookup e q = sup_leadsto init step rho i j q) \ distinct (map fst e) \ + valid_s init step st accept rho i i j s))" + +lemma valid_init_window: "valid_window args t0 sub [] (init_window args t0 sub)" + by (auto simp: valid_window_def mmap_keys_def mmap_lookup_def sup_leadsto_def + valid_s_def steps_def sup_acc_def intro: reaches_on.intros split: option.splits) + +lemma steps_app_cong: "j \ length rho \ steps step (rho @ [x]) q (i, j) = + steps step rho q (i, j)" +proof - + assume "j \ length rho" + then have map_cong: "map (bs_at (rho @ [x])) [i.. acc step accept (rho @ [x]) q (i, j) = + acc step accept rho q (i, j)" + by (auto simp: acc_def bs_at_def nth_append steps_app_cong) + +lemma sup_acc_app_cong: "j \ length rho \ sup_acc step accept (rho @ [x]) q i j = + sup_acc step accept rho q i j" + apply (auto simp: sup_acc_def Let_def ts_at_def nth_append acc_def) + apply (metis (mono_tags, opaque_lifting) less_eq_Suc_le order_less_le_trans steps_app_cong)+ + done + +lemma sup_acc_concat_cong: "j \ length rho \ sup_acc step accept (rho @ rho') q i j = + sup_acc step accept rho q i j" + apply (induction rho' rule: rev_induct) + apply auto + apply (smt append.assoc le_add1 le_trans length_append sup_acc_app_cong) + done + +lemma sup_leadsto_app_cong: "i \ j \ j \ length rho \ + sup_leadsto init step (rho @ [x]) i j q = sup_leadsto init step rho i j q" +proof - + assume assms: "i \ j" "j \ length rho" + define L' where "L' = {l. l < i \ steps step rho init (l, j) = q}" + define L'' where "L'' = {l. l < i \ steps step (rho @ [x]) init (l, j) = q}" + show ?thesis + using assms + by (cases "L' = {}") + (auto simp: sup_leadsto_def L'_def L''_def ts_at_def nth_append steps_app_cong) +qed + +lemma chain_le: + fixes xs :: "'d :: timestamp list" + shows "chain_le xs \ i \ j \ j < length xs \ xs ! i \ xs ! j" +proof (induction xs arbitrary: i j rule: chain_le.induct) + case (chain_le_cons y xs x) + then show ?case + proof (cases i) + case 0 + then show ?thesis + using chain_le_cons + apply (cases j) + apply auto + apply (metis (no_types, lifting) le_add1 le_add_same_cancel1 le_less less_le_trans nth_Cons_0) + done + qed auto +qed auto + +lemma steps_refl[simp]: "steps step rho q (i, i) = q" + unfolding steps_def by auto + +lemma steps_split: "i < j \ steps step rho q (i, j) = + steps step rho (step q (bs_at rho i)) (Suc i, j)" + unfolding steps_def by (simp add: upt_rec) + +lemma steps_app: "i \ j \ steps step rho q (i, j + 1) = + step (steps step rho q (i, j)) (bs_at rho j)" + unfolding steps_def by auto + +lemma steps_appE: "i \ j \ steps step rho q (i, Suc j) = q' \ + \q''. steps step rho q (i, j) = q'' \ q' = step q'' (bs_at rho j)" + unfolding steps_def sub_bs.simps by auto + +lemma steps_comp: "i \ l \ l \ j \ steps step rho q (i, l) = q' \ + steps step rho q' (l, j) = q'' \ steps step rho q (i, j) = q''" +proof - + assume assms: "i \ l" "l \ j" "steps step rho q (i, l) = q'" "steps step rho q' (l, j) = q''" + have range_app: "[i.. l \ {i.. + \tp. sup_acc step accept rho q i j = Some (ts_at rho tp, tp) \ l \ tp \ tp < j" +proof - + assume assms: "acc step accept rho q (i, Suc l)" "l \ {i.. {i.. {}" "l \ L" + using assms unfolding L_def by auto + then show "\tp. sup_acc step accept rho q i j = Some (ts_at rho tp, tp) \ l \ tp \ tp < j" + using L_def L_props + by (auto simp add: sup_acc_def) + (smt L_props(1) L_props(2) Max_ge Max_in mem_Collect_eq) +qed + +lemma sup_acc_Some_ts: "sup_acc step accept rho q i j = Some (ts, tp) \ ts = ts_at rho tp" + by (auto simp add: sup_acc_def Let_def split: if_splits) + +lemma sup_acc_SomeE: "sup_acc step accept rho q i j = Some (ts, tp) \ + tp \ {i.. acc step accept rho q (i, Suc tp)" +proof - + assume assms: "sup_acc step accept rho q i j = Some (ts, tp)" + define L where "L = {l \ {i.. {}" "Max L = tp" + unfolding L_def using assms + by (auto simp add: sup_acc_def Let_def split: if_splits) + show ?thesis + using Max_in[OF L_props(1,2)] unfolding L_props(3) unfolding L_def by auto +qed + +lemma sup_acc_NoneE: "l \ {i.. sup_acc step accept rho q i j = None \ + \acc step accept rho q (i, Suc l)" + by (auto simp add: sup_acc_def Let_def split: if_splits) + +lemma sup_acc_same: "sup_acc step accept rho q i i = None" + by (auto simp add: sup_acc_def) + +lemma sup_acc_None_restrict: "i \ j \ sup_acc step accept rho q i j = None \ + sup_acc step accept rho (step q (bs_at rho i)) (Suc i) j = None" + using steps_split + apply (auto simp add: sup_acc_def Let_def acc_def split: if_splits) + apply (smt (z3) lessI less_imp_le_nat order_less_le_trans steps_split) + done + +lemma sup_acc_ext_idle: "i \ j \ \acc step accept rho q (i, Suc j) \ + sup_acc step accept rho q i (Suc j) = sup_acc step accept rho q i j" +proof - + assume assms: "i \ j" "\acc step accept rho q (i, Suc j)" + define L where "L = {l \ {i.. {i.. l \ l \ j \ tp \ l \ + sup_acc step accept rho (steps step rho q (i, l)) l j = Some (ts, tp) \ + sup_acc step accept rho q i j = sup_acc step accept rho (steps step rho q (i, l)) l j" +proof - + assume assms: "i \ l" "l \ j" "sup_acc step accept rho (steps step rho q (i, l)) l j = + Some (ts, tp)" "tp \ l" + define L where "L = {l \ {i.. {l.. {}" "tp = Max L'" "ts = ts_at rho tp" + using assms(3) unfolding L'_def + by (auto simp add: sup_acc_def Let_def split: if_splits) + have tp_in_L': "tp \ L'" + using Max_in[OF L'_props(1,2)] unfolding L'_props(3) . + then have tp_in_L: "tp \ L" + unfolding L_def L'_def using assms(1) steps_comp[OF assms(1,2), of step rho] + apply (auto simp add: acc_def) + using steps_comp + by (metis le_SucI) + have L_props: "finite L" "L \ {}" + using L_def tp_in_L by auto + have "\l'. l' \ L \ l' \ tp" + proof - + fix l' + assume assm: "l' \ L" + show "l' \ tp" + proof (cases "l' < l") + case True + then show ?thesis + using assms(4) by auto + next + case False + then have "l' \ L'" + using assm + unfolding L_def L'_def + by (auto simp add: acc_def) (metis assms(1) less_imp_le_nat not_less_eq steps_comp) + then show ?thesis + using Max_eq_iff[OF L'_props(1,2)] L'_props(3) by auto + qed + qed + then have "Max L = tp" + using Max_eq_iff[OF L_props] tp_in_L by auto + then have "sup_acc step accept rho q i j = Some (ts, tp)" + using L_def L_props(2) unfolding L'_props(4) + by (auto simp add: sup_acc_def) + then show "sup_acc step accept rho q i j = sup_acc step accept rho (steps step rho q (i, l)) l j" + using assms(3) by auto +qed + +lemma sup_acc_comp_None: "i \ l \ l \ j \ + sup_acc step accept rho (steps step rho q (i, l)) l j = None \ + sup_acc step accept rho q i j = sup_acc step accept rho q i l" +proof (induction "j - l" arbitrary: l) + case (Suc n) + have i_lt_j: "i < j" + using Suc by auto + have l_lt_j: "l < j" + using Suc by auto + have "\acc step accept rho q (i, Suc l)" + using sup_acc_NoneE[of l l j step accept rho "steps step rho q (i, l)"] Suc(2-) + by (auto simp add: acc_def steps_def) + then have "sup_acc step accept rho q i (l + 1) = sup_acc step accept rho q i l" + using sup_acc_ext_idle[OF Suc(3)] by auto + moreover have "sup_acc step accept rho (steps step rho q (i, l + 1)) (l + 1) j = None" + using sup_acc_None_restrict[OF Suc(4,5)] steps_app[OF Suc(3), of step rho] + by auto + ultimately show ?case + using Suc(1)[of "l + 1"] Suc(2,3,4,5) + by auto +qed (auto simp add: sup_acc_same) + +lemma sup_acc_ext: "i \ j \ acc step accept rho q (i, Suc j) \ + sup_acc step accept rho q i (Suc j) = Some (ts_at rho j, j)" +proof - + assume assms: "i \ j" "acc step accept rho q (i, Suc j)" + define L' where "L' = {l \ {i.. {}" "j \ L'" + using assms unfolding L'_def by auto + have j_is_Max: "Max L' = j" + using Max_eq_iff[OF j_in_L'(1,2)] j_in_L'(3) + by (auto simp add: L'_def) + show "sup_acc step accept rho q i (Suc j) = Some (ts_at rho j, j)" + using L'_def j_is_Max j_in_L'(2) + by (auto simp add: sup_acc_def) +qed + +lemma sup_acc_None: "i < j \ sup_acc step accept rho q i j = None \ + sup_acc step accept rho (step q (bs_at rho i)) (i + 1) j = None" + using steps_split[of _ _ step rho] + by (auto simp add: sup_acc_def Let_def acc_def split: if_splits) + +lemma sup_acc_i: "i < j \ sup_acc step accept rho q i j = Some (ts, i) \ + sup_acc step accept rho (step q (bs_at rho i)) (Suc i) j = None" +proof (rule ccontr) + assume assms: "i < j" "sup_acc step accept rho q i j = Some (ts, i)" + "sup_acc step accept rho (step q (bs_at rho i)) (Suc i) j \ None" + from assms(3) obtain l where l_def: "l \ {Suc i.. {i.. {}" "Max L' = i" + by (auto simp add: sup_acc_def L'_def Let_def split: if_splits) + have i_lt_l: "i < l" + using l_def(1) by auto + from l_def have "l \ L'" + unfolding L'_def acc_def using steps_split[OF i_lt_l, of step rho] by (auto simp: steps_def) + then show "False" + using l_def(1) L'_props Max_ge i_lt_l not_le by auto +qed + +lemma sup_acc_l: "i < j \ i \ l \ sup_acc step accept rho q i j = Some (ts, l) \ + sup_acc step accept rho q i j = sup_acc step accept rho (step q (bs_at rho i)) (Suc i) j" +proof - + assume assms: "i < j" "i \ l" "sup_acc step accept rho q i j = Some (ts, l)" + define L where "L = {l \ {i.. {Suc i.. {}" "l = Max L" + "sup_acc step accept rho q i j = Some (ts_at rho l, l)" + by (auto simp add: sup_acc_def L_def Let_def split: if_splits) + have l_in_L: "l \ L" + using Max_in[OF L_props(1,2)] L_props(3) by auto + then have i_lt_l: "i < l" + unfolding L_def using assms(2) by auto + have l_in_L': "finite L'" "L' \ {}" "l \ L'" + using steps_split[OF i_lt_l, of step rho q] l_in_L assms(2) + unfolding L_def L'_def acc_def by (auto simp: steps_def) + have "\l'. l' \ L' \ l' \ l" + proof - + fix l' + assume assms: "l' \ L'" + have i_lt_l': "i < l'" + using assms unfolding L'_def by auto + have "l' \ L" + using steps_split[OF i_lt_l', of step rho] assms unfolding L_def L'_def acc_def by (auto simp: steps_def) + then show "l' \ l" + using L_props by simp + qed + then have l_sup_L': "Max L' = l" + using Max_eq_iff[OF l_in_L'(1,2)] l_in_L'(3) by auto + then show "sup_acc step accept rho q i j = + sup_acc step accept rho (step q (bs_at rho i)) (Suc i) j" + unfolding L_props(4) + unfolding sup_acc_def Let_def + using L'_def l_in_L'(2,3) L_props + unfolding Suc_eq_plus1 by auto +qed + +lemma sup_leadsto_idle: "i < j \ steps step rho init (i, j) \ q \ + sup_leadsto init step rho i j q = sup_leadsto init step rho (i + 1) j q" +proof - + assume assms: "i < j" "steps step rho init (i, j) \ q" + define L where "L = {l. l < i \ steps step rho init (l, j) = q}" + define L' where "L' = {l. l < i + 1 \ steps step rho init (l, j) = q}" + have L_L': "L = L'" + unfolding L_def L'_def using assms(2) less_antisym + by fastforce + show "sup_leadsto init step rho i j q = sup_leadsto init step rho (i + 1) j q" + using L_def L'_def L_L' + by (auto simp add: sup_leadsto_def) +qed + +lemma sup_leadsto_SomeI: "l < i \ steps step rho init (l, j) = q \ + \l'. sup_leadsto init step rho i j q = Some (ts_at rho l') \ l \ l' \ l' < i" +proof - + assume assms: "l < i" "steps step rho init (l, j) = q" + define L' where "L' = {l. l < i \ steps step rho init (l, j) = q}" + have fin_L': "finite L'" + unfolding L'_def by auto + moreover have L_nonempty: "L' \ {}" + using assms unfolding L'_def + by (auto simp add: sup_leadsto_def split: if_splits) + ultimately have "Max L' \ L'" + using Max_in by auto + then show "\l'. sup_leadsto init step rho i j q = Some (ts_at rho l') \ l \ l' \ l' < i" + using L'_def L_nonempty assms + by (fastforce simp add: sup_leadsto_def split: if_splits) +qed + +lemma sup_leadsto_SomeE: "i \ j \ sup_leadsto init step rho i j q = Some ts \ + \l < i. steps step rho init (l, j) = q \ ts_at rho l = ts" +proof - + assume assms: "i \ j" "sup_leadsto init step rho i j q = Some ts" + define L' where "L' = {l. l < i \ steps step rho init (l, j) = q}" + have fin_L': "finite L'" + unfolding L'_def by auto + moreover have L_nonempty: "L' \ {}" + using assms(2) unfolding L'_def + by (auto simp add: sup_leadsto_def split: if_splits) + ultimately have "Max L' \ L'" + using Max_in by auto + then show "\l < i. steps step rho init (l, j) = q \ ts_at rho l = ts" + using assms(2) L'_def + apply (auto simp add: sup_leadsto_def split: if_splits) + using \Max L' \ L'\ by blast +qed + +lemma Mapping_keys_dest: "x \ mmap_keys f \ \y. mmap_lookup f x = Some y" + by (auto simp add: mmap_keys_def mmap_lookup_def weak_map_of_SomeI) + +lemma Mapping_keys_intro: "mmap_lookup f x \ None \ x \ mmap_keys f" + by (auto simp add: mmap_keys_def mmap_lookup_def) + (metis map_of_eq_None_iff option.distinct(1)) + +lemma Mapping_not_keys_intro: "mmap_lookup f x = None \ x \ mmap_keys f" + unfolding mmap_lookup_def mmap_keys_def + using weak_map_of_SomeI by force + +lemma Mapping_lookup_None_intro: "x \ mmap_keys f \ mmap_lookup f x = None" + unfolding mmap_lookup_def mmap_keys_def + by (simp add: map_of_eq_None_iff) + +primrec mmap_combine :: "'key \ 'val \ ('val \ 'val \ 'val) \ ('key \ 'val) list \ + ('key \ 'val) list" + where + "mmap_combine k v c [] = [(k, v)]" +| "mmap_combine k v c (p # ps) = (case p of (k', v') \ + if k = k' then (k, c v' v) # ps else p # mmap_combine k v c ps)" + +lemma mmap_combine_distinct_set: "distinct (map fst r) \ + distinct (map fst (mmap_combine k v c r)) \ + set (map fst (mmap_combine k v c r)) = set (map fst r) \ {k}" + by (induction r) force+ + +lemma mmap_combine_lookup: "distinct (map fst r) \ mmap_lookup (mmap_combine k v c r) z = + (if k = z then (case mmap_lookup r k of None \ Some v | Some v' \ Some (c v' v)) + else mmap_lookup r z)" + using eq_key_imp_eq_value + by (induction r) (fastforce simp: mmap_lookup_def split: option.splits)+ + +definition mmap_fold :: "('c, 'd) mmap \ (('c \ 'd) \ ('c \ 'd)) \ ('d \ 'd \ 'd) \ + ('c, 'd) mmap \ ('c, 'd) mmap" where + "mmap_fold m f c r = foldl (\r p. case f p of (k, v) \ mmap_combine k v c r) r m" + +definition mmap_fold' :: "('c, 'd) mmap \ 'e \ (('c \ 'd) \ 'e \ ('c \ 'd) \ 'e) \ + ('d \ 'd \ 'd) \ ('c, 'd) mmap \ ('c, 'd) mmap \ 'e" where + "mmap_fold' m e f c r = foldl (\(r, e) p. case f (p, e) of ((k, v), e') \ + (mmap_combine k v c r, e')) (r, e) m" + +lemma mmap_fold'_eq: "mmap_fold' m e f' c r = (m', e') \ P e \ + (\p e p' e'. P e \ f' (p, e) = (p', e') \ p' = f p \ P e') \ + m' = mmap_fold m f c r \ P e'" +proof (induction m arbitrary: e r m' e') + case (Cons p m) + obtain k v e'' where kv_def: "f' (p, e) = ((k, v), e'')" "P e''" + using Cons + by (cases "f' (p, e)") fastforce + have mmap_fold: "mmap_fold m f c (mmap_combine k v c r) = mmap_fold (p # m) f c r" + using Cons(1)[OF _ kv_def(2), where ?r="mmap_combine k v c r"] Cons(2,3,4) + by (simp add: mmap_fold_def mmap_fold'_def kv_def(1)) + have mmap_fold': "mmap_fold' m e'' f' c (mmap_combine k v c r) = (m', e')" + using Cons(2) + by (auto simp: mmap_fold'_def kv_def) + show ?case + using Cons(1)[OF mmap_fold' kv_def(2) Cons(4)] + unfolding mmap_fold + by auto +qed (auto simp: mmap_fold_def mmap_fold'_def) + +lemma foldl_mmap_combine_distinct_set: "distinct (map fst r) \ + distinct (map fst (mmap_fold m f c r)) \ + set (map fst (mmap_fold m f c r)) = set (map fst r) \ set (map (fst \ f) m)" + apply (induction m arbitrary: r) + using mmap_combine_distinct_set + apply (auto simp: mmap_fold_def split: prod.splits) + apply force + apply (smt Un_iff fst_conv imageI insert_iff) + using mk_disjoint_insert + apply fastforce+ + done + +lemma mmap_fold_lookup_rec: "distinct (map fst r) \ mmap_lookup (mmap_fold m f c r) z = + (case map (snd \ f) (filter (\(k, v). fst (f (k, v)) = z) m) of [] \ mmap_lookup r z + | v # vs \ (case mmap_lookup r z of None \ Some (foldl c v vs) + | Some w \ Some (foldl c w (v # vs))))" +proof (induction m arbitrary: r) + case (Cons p ps) + obtain k v where kv_def: "f p = (k, v)" + by fastforce + have distinct: "distinct (map fst (mmap_combine k v c r))" + using mmap_combine_distinct_set[OF Cons(2)] + by auto + show ?case + using Cons(1)[OF distinct, unfolded mmap_combine_lookup[OF Cons(2)]] + by (auto simp: mmap_lookup_def kv_def mmap_fold_def split: list.splits option.splits) +qed (auto simp: mmap_fold_def) + +lemma mmap_fold_distinct: "distinct (map fst m) \ distinct (map fst (mmap_fold m f c []))" + using foldl_mmap_combine_distinct_set[of "[]"] + by auto + +lemma mmap_fold_set: "distinct (map fst m) \ + set (map fst (mmap_fold m f c [])) = (fst \ f) ` set m" + using foldl_mmap_combine_distinct_set[of "[]"] + by force + +lemma mmap_lookup_empty: "mmap_lookup [] z = None" + by (auto simp: mmap_lookup_def) + +lemma mmap_fold_lookup: "distinct (map fst m) \ mmap_lookup (mmap_fold m f c []) z = + (case map (snd \ f) (filter (\(k, v). fst (f (k, v)) = z) m) of [] \ None + | v # vs \ Some (foldl c v vs))" + using mmap_fold_lookup_rec[of "[]" _ f c] + by (auto simp: mmap_lookup_empty split: list.splits) + +definition fold_sup :: "('c, 'd :: timestamp) mmap \ ('c \ 'c) \ ('c, 'd) mmap" where + "fold_sup m f = mmap_fold m (\(x, y). (f x, y)) sup []" + +lemma mmap_lookup_distinct: "distinct (map fst m) \ (k, v) \ set m \ + mmap_lookup m k = Some v" + by (auto simp: mmap_lookup_def) + +lemma fold_sup_distinct: "distinct (map fst m) \ distinct (map fst (fold_sup m f))" + using mmap_fold_distinct + by (auto simp: fold_sup_def) + +lemma fold_sup: + fixes v :: "'d :: timestamp" + shows "foldl sup v vs = fold sup vs v" + by (induction vs arbitrary: v) (auto simp: sup.commute) + +lemma lookup_fold_sup: + assumes distinct: "distinct (map fst m)" + shows "mmap_lookup (fold_sup m f) z = + (let Z = {x \ mmap_keys m. f x = z} in + if Z = {} then None else Some (Sup_fin ((the \ mmap_lookup m) ` Z)))" +proof (cases "{x \ mmap_keys m. f x = z} = {}") + case True + have "z \ mmap_keys (mmap_fold m (\(x, y). (f x, y)) sup [])" + using True[unfolded mmap_keys_def] mmap_fold_set[OF distinct] + by (auto simp: mmap_keys_def) + then have "mmap_lookup (fold_sup m f) z = None" + unfolding fold_sup_def + by (meson Mapping_keys_intro) + then show ?thesis + unfolding True + by auto +next + case False + have z_in_keys: "z \ mmap_keys (mmap_fold m (\(x, y). (f x, y)) sup [])" + using False[unfolded mmap_keys_def] mmap_fold_set[OF distinct] + by (force simp: mmap_keys_def) + obtain v vs where vs_def: "mmap_lookup (fold_sup m f) z = Some (foldl sup v vs)" + "v # vs = map snd (filter (\(k, v). f k = z) m)" + using mmap_fold_lookup[OF distinct, of "(\(x, y). (f x, y))" sup z] + Mapping_keys_dest[OF z_in_keys] + by (force simp: fold_sup_def mmap_keys_def comp_def split: list.splits prod.splits) + have "set (v # vs) = (the \ mmap_lookup m) ` {x \ mmap_keys m. f x = z}" + proof (rule set_eqI, rule iffI) + fix w + assume "w \ set (v # vs)" + then obtain x where x_def: "x \ mmap_keys m" "f x = z" "(x, w) \ set m" + using vs_def(2) + by (auto simp add: mmap_keys_def rev_image_eqI) + show "w \ (the \ mmap_lookup m) ` {x \ mmap_keys m. f x = z}" + using x_def(1,2) mmap_lookup_distinct[OF distinct x_def(3)] + by force + next + fix w + assume "w \ (the \ mmap_lookup m) ` {x \ mmap_keys m. f x = z}" + then obtain x where x_def: "x \ mmap_keys m" "f x = z" "(x, w) \ set m" + using mmap_lookup_distinct[OF distinct] + by (auto simp add: Mapping_keys_intro distinct mmap_lookup_def dest: Mapping_keys_dest) + show "w \ set (v # vs)" + using x_def + by (force simp: vs_def(2)) + qed + then have "foldl sup v vs = Sup_fin ((the \ mmap_lookup m) ` {x \ mmap_keys m. f x = z})" + unfolding fold_sup + by (metis Sup_fin.set_eq_fold) + then show ?thesis + using False + by (auto simp: vs_def(1)) +qed + +definition mmap_map :: "('a \ 'b \ 'c) \ ('a, 'b) mmap \ ('a, 'c) mmap" where + "mmap_map f m = map (\(k, v). (k, f k v)) m" + +lemma mmap_map_keys: "mmap_keys (mmap_map f m) = mmap_keys m" + by (force simp: mmap_map_def mmap_keys_def) + +lemma mmap_map_fst: "map fst (mmap_map f m) = map fst m" + by (auto simp: mmap_map_def) + +definition cstep :: "('c \ 'b \ 'c) \ ('c \ 'b, 'c) mapping \ + 'c \ 'b \ ('c \ ('c \ 'b, 'c) mapping)" where + "cstep step st q bs = (case Mapping.lookup st (q, bs) of None \ (let res = step q bs in + (res, Mapping.update (q, bs) res st)) | Some v \ (v, st))" + +definition cac :: "('c \ bool) \ ('c, bool) mapping \ 'c \ (bool \ ('c, bool) mapping)" where + "cac accept ac q = (case Mapping.lookup ac q of None \ (let res = accept q in + (res, Mapping.update q res ac)) | Some v \ (v, ac))" + +fun mmap_fold_s :: "('c \ 'b \ 'c) \ ('c \ 'b, 'c) mapping \ + ('c \ bool) \ ('c, bool) mapping \ + 'b \ 'd \ nat \ ('c, 'c \ ('d \ nat) option) mmap \ + (('c, 'c \ ('d \ nat) option) mmap \ ('c \ 'b, 'c) mapping \ ('c, bool) mapping)" where + "mmap_fold_s step st accept ac bs t j [] = ([], st, ac)" +| "mmap_fold_s step st accept ac bs t j ((q, (q', tstp)) # qbss) = + (let (q'', st') = cstep step st q' bs; + (\, ac') = cac accept ac q''; + (qbss', st'', ac'') = mmap_fold_s step st' accept ac' bs t j qbss in + ((q, (q'', if \ then Some (t, j) else tstp)) # qbss', st'', ac''))" + +lemma mmap_fold_s_sound: "mmap_fold_s step st accept ac bs t j qbss = (qbss', st', ac') \ + (\q bs. case Mapping.lookup st (q, bs) of None \ True | Some v \ step q bs = v) \ + (\q bs. case Mapping.lookup ac q of None \ True | Some v \ accept q = v) \ + qbss' = mmap_map (\q (q', tstp). (step q' bs, if accept (step q' bs) then Some (t, j) else tstp)) qbss \ + (\q bs. case Mapping.lookup st' (q, bs) of None \ True | Some v \ step q bs = v) \ + (\q bs. case Mapping.lookup ac' q of None \ True | Some v \ accept q = v)" +proof (induction qbss arbitrary: st ac qbss') + case (Cons a qbss) + obtain q q' tstp where a_def: "a = (q, (q', tstp))" + by (cases a) auto + obtain q'' st'' where q''_def: "cstep step st q' bs = (q'', st'')" + "q'' = step q' bs" + using Cons(3) + by (cases "cstep step st q' bs") + (auto simp: cstep_def Let_def option.case_eq_if split: option.splits if_splits) + obtain b ac'' where b_def: "cac accept ac q'' = (b, ac'')" + "b = accept q''" + using Cons(4) + by (cases "cac accept ac q''") + (auto simp: cac_def Let_def option.case_eq_if split: option.splits if_splits) + obtain qbss'' where qbss''_def: "mmap_fold_s step st'' accept ac'' bs t j qbss = + (qbss'', st', ac')" "qbss' = (q, q'', if b then Some (t, j) else tstp) # qbss''" + using Cons(2)[unfolded a_def mmap_fold_s.simps q''_def(1) b_def(1)] + unfolding Let_def + by (auto simp: b_def(1) split: prod.splits) + have ih: "\q bs. case Mapping.lookup st'' (q, bs) of None \ True | Some a \ step q bs = a" + "\q bs. case Mapping.lookup ac'' q of None \ True | Some a \ accept q = a" + using q''_def b_def Cons(3,4) + by (auto simp: cstep_def cac_def Let_def Mapping.lookup_update' option.case_eq_if + split: option.splits if_splits) + show ?case + using Cons(1)[OF qbss''_def(1) ih] + unfolding a_def q''_def(2) b_def(2) qbss''_def(2) + by (auto simp: mmap_map_def) +qed (auto simp: mmap_map_def) + +definition adv_end :: "('b, 'c, 'd :: timestamp, 't, 'e) args \ + ('b, 'c, 'd, 't, 'e) window \ ('b, 'c, 'd, 't, 'e) window option" where + "adv_end args w = (let step = w_step args; accept = w_accept args; + run_t = w_run_t args; run_sub = w_run_sub args; st = w_st w; ac = w_ac w; + j = w_j w; tj = w_tj w; sj = w_sj w; s = w_s w; e = w_e w in + (case run_t tj of None \ None | Some (tj', t) \ (case run_sub sj of None \ None | Some (sj', bs) \ + let (s', st', ac') = mmap_fold_s step st accept ac bs t j s; + (e', st'') = mmap_fold' e st' (\((x, y), st). let (q', st') = cstep step st x bs in ((q', y), st')) sup [] in + Some (w\w_st := st'', w_ac := ac', w_j := Suc j, w_tj := tj', w_sj := sj', w_s := s', w_e := e'\))))" + +lemma map_values_lookup: "mmap_lookup (mmap_map f m) z = Some v' \ + \v. mmap_lookup m z = Some v \ v' = f z v" + by (induction m) (auto simp: mmap_lookup_def mmap_map_def) + +lemma acc_app: + assumes "i \ j" "steps step rho q (i, Suc j) = q'" "accept q'" + shows "sup_acc step accept rho q i (Suc j) = Some (ts_at rho j, j)" +proof - + define L where "L = {l \ {i.. {}" + using assms unfolding L_def by auto + moreover have "Max {l \ {i.. j" "steps step rho q (i, Suc j) = q'" "\accept q'" + shows "sup_acc step accept rho q i (Suc j) = sup_acc step accept rho q i j" + using assms + by (auto simp add: sup_acc_def Let_def acc_def elim: less_SucE) (metis less_Suc_eq)+ + +lemma sup_fin_closed: "finite A \ A \ {} \ + (\x y. x \ A \ y \ A \ sup x y \ {x, y}) \ \\<^sub>f\<^sub>i\<^sub>n A \ A" + apply (induct A rule: finite.induct) + using Sup_fin.insert + by auto fastforce + +lemma valid_adv_end: + assumes "valid_window args t0 sub rho w" "w_run_t args (w_tj w) = Some (tj', t)" + "w_run_sub args (w_sj w) = Some (sj', bs)" + "\t'. t' \ set (map fst rho) \ t' \ t" + shows "case adv_end args w of None \ False | Some w' \ valid_window args t0 sub (rho @ [(t, bs)]) w'" +proof - + define init where "init = w_init args" + define step where "step = w_step args" + define accept where "accept = w_accept args" + define run_t where "run_t = w_run_t args" + define run_sub where "run_sub = w_run_sub args" + define st where "st = w_st w" + define ac where "ac = w_ac w" + define i where "i = w_i w" + define ti where "ti = w_ti w" + define si where "si = w_si w" + define j where "j = w_j w" + define tj where "tj = w_tj w" + define sj where "sj = w_sj w" + define s where "s = w_s w" + define e where "e = w_e w" + have valid_before: "reach_window args t0 sub rho (i, ti, si, j, tj, sj)" + "\i j. i \ j \ j < length rho \ ts_at rho i \ ts_at rho j" + "(\q bs. case Mapping.lookup st (q, bs) of None \ True | Some v \ step q bs = v)" + "(\q bs. case Mapping.lookup ac q of None \ True | Some v \ accept q = v)" + "\q. mmap_lookup e q = sup_leadsto init step rho i j q" "distinct (map fst e)" + "valid_s init step st accept rho i i j s" + using assms(1) + unfolding valid_window_def valid_s_def Let_def init_def step_def accept_def run_t_def + run_sub_def st_def ac_def i_def ti_def si_def j_def tj_def sj_def s_def e_def + by auto + have i_j: "i \ j" + using valid_before(1) + by auto + have distinct_before: "distinct (map fst s)" "distinct (map fst e)" + using valid_before + by (auto simp: valid_s_def) + note run_tj = assms(2)[folded run_t_def tj_def] + note run_sj = assms(3)[folded run_sub_def sj_def] + define rho' where "rho' = rho @ [(t, bs)]" + have ts_at_mono: "\i j. i \ j \ j < length rho' \ ts_at rho' i \ ts_at rho' j" + using valid_before(2) assms(4) + by (auto simp: rho'_def ts_at_def nth_append split: option.splits list.splits if_splits) + obtain s' st' ac' where s'_def: "mmap_fold_s step st accept ac bs t j s = (s', st', ac')" + apply (cases "mmap_fold_s step st accept ac bs t j s") + apply (auto) + done + have s'_mmap_map: "s' = mmap_map (\q (q', tstp). + (step q' bs, if accept (step q' bs) then Some (t, j) else tstp)) s" + "(\q bs. case Mapping.lookup st' (q, bs) of None \ True | Some v \ step q bs = v)" + "(\q bs. case Mapping.lookup ac' q of None \ True | Some v \ accept q = v)" + using mmap_fold_s_sound[OF s'_def valid_before(3,4)] + by auto + obtain e' st'' where e'_def: "mmap_fold' e st' (\((x, y), st). + let (q', st') = cstep step st x bs in ((q', y), st')) sup [] = (e', st'')" + by (metis old.prod.exhaust) + define inv where "inv \ \st'. \q bs. case Mapping.lookup st' (q, bs) of None \ True + | Some v \ step q bs = v" + have inv_st': "inv st'" + using s'_mmap_map(2) + by (auto simp: inv_def) + have "\p e p' e'. inv e \ (case (p, e) of (x, xa) \ (case x of (x, y) \ + \st. let (q', st') = cstep step st x bs in ((q', y), st')) xa) = (p', e') \ + p' = (case p of (x, y) \ (step x bs, y)) \ inv e'" + by (auto simp: inv_def cstep_def Let_def Mapping.lookup_update' split: option.splits if_splits) + then have e'_fold_sup_st'': "e' = fold_sup e (\q. step q bs)" + "(\q bs. case Mapping.lookup st'' (q, bs) of None \ True | Some v \ step q bs = v)" + using mmap_fold'_eq[OF e'_def, of inv "\(x, y). (step x bs, y)", OF inv_st'] + by (fastforce simp: fold_sup_def inv_def)+ + have adv_end: "adv_end args w = Some (w\w_st := st'', w_ac := ac', + w_j := Suc j, w_tj := tj', w_sj := sj', w_s := s', w_e := e'\)" + using run_tj run_sj e'_def[unfolded st_def] + unfolding adv_end_def init_def step_def accept_def run_t_def run_sub_def + i_def ti_def si_def j_def tj_def sj_def s_def e_def s'_def e'_def + by (auto simp: Let_def s'_def[unfolded step_def st_def accept_def ac_def j_def s_def]) + have keys_s': "mmap_keys s' = mmap_keys s" + by (force simp: mmap_keys_def mmap_map_def s'_mmap_map(1)) + have lookup_s: "\q q' tstp. mmap_lookup s q = Some (q', tstp) \ + steps step rho' q (i, j) = q' \ tstp = sup_acc step accept rho' q i j" + using valid_before Mapping_keys_intro + by (force simp add: Let_def rho'_def valid_s_def steps_app_cong sup_acc_app_cong + split: option.splits) + have bs_at_rho'_j: "bs_at rho' j = bs" + using valid_before + by (auto simp: rho'_def bs_at_def nth_append) + have ts_at_rho'_j: "ts_at rho' j = t" + using valid_before + by (auto simp: rho'_def ts_at_def nth_append) + have lookup_s': "\q q' tstp. mmap_lookup s' q = Some (q', tstp) \ + steps step rho' q (i, Suc j) = q' \ tstp = sup_acc step accept rho' q i (Suc j)" + proof - + fix q q'' tstp' + assume assm: "mmap_lookup s' q = Some (q'', tstp')" + obtain q' tstp where "mmap_lookup s q = Some (q', tstp)" "q'' = step q' bs" + "tstp' = (if accept (step q' bs) then Some (t, j) else tstp)" + using map_values_lookup[OF assm[unfolded s'_mmap_map]] by auto + then show "steps step rho' q (i, Suc j) = q'' \ tstp' = sup_acc step accept rho' q i (Suc j)" + using lookup_s + apply (auto simp: bs_at_rho'_j ts_at_rho'_j) + apply (metis Suc_eq_plus1 bs_at_rho'_j i_j steps_app) + apply (metis acc_app bs_at_rho'_j i_j steps_appE ts_at_rho'_j) + apply (metis Suc_eq_plus1 bs_at_rho'_j i_j steps_app) + apply (metis (no_types, lifting) acc_app_idle bs_at_rho'_j i_j steps_appE) + done + qed + have lookup_e: "\q. mmap_lookup e q = sup_leadsto init step rho' i j q" + using valid_before sup_leadsto_app_cong[of _ _ rho init step] + by (auto simp: rho'_def) + have keys_e_alt: "mmap_keys e = {q. \l < i. steps step rho' init (l, j) = q}" + using valid_before + apply (auto simp add: sup_leadsto_def rho'_def) + apply (metis (no_types, lifting) Mapping_keys_dest lookup_e rho'_def sup_leadsto_SomeE) + apply (metis (no_types, lifting) Mapping_keys_intro option.simps(3) order_refl steps_app_cong) + done + have finite_keys_e: "finite (mmap_keys e)" + unfolding keys_e_alt + by (rule finite_surj[of "{l. l < i}"]) auto + have "reaches_on run_sub sub (map snd rho) sj" + using valid_before reaches_on_trans + unfolding run_sub_def sub_def + by fastforce + then have reaches_on': "reaches_on run_sub sub (map snd rho @ [bs]) sj'" + using reaches_on_app run_sj + by fast + have "reaches_on run_t t0 (map fst rho) tj" + using valid_before reaches_on_trans + unfolding run_t_def + by fastforce + then have reach_t': "reaches_on run_t t0 (map fst rho') tj'" + using reaches_on_app run_tj + unfolding rho'_def + by fastforce + have lookup_e': "\q. mmap_lookup e' q = sup_leadsto init step rho' i (Suc j) q" + proof - + fix q + define Z where "Z = {x \ mmap_keys e. step x bs = q}" + show "mmap_lookup e' q = sup_leadsto init step rho' i (Suc j) q" + proof (cases "Z = {}") + case True + then have "mmap_lookup e' q = None" + using Z_def lookup_fold_sup[OF distinct_before(2)] + unfolding e'_fold_sup_st'' + by (auto simp: Let_def) + moreover have "sup_leadsto init step rho' i (Suc j) q = None" + proof (rule ccontr) + assume assm: "sup_leadsto init step rho' i (Suc j) q \ None" + obtain l where l_def: "l < i" "steps step rho' init (l, Suc j) = q" + using i_j sup_leadsto_SomeE[of i "Suc j"] assm + by force + have l_j: "l \ j" + using less_le_trans[OF l_def(1) i_j] by auto + obtain q'' where q''_def: "steps step rho' init (l, j) = q''" "step q'' bs = q" + using steps_appE[OF _ l_def(2)] l_j + by (auto simp: bs_at_rho'_j) + then have "q'' \ mmap_keys e" + using keys_e_alt l_def(1) + by auto + then show "False" + using Z_def q''_def(2) True + by auto + qed + ultimately show ?thesis + by auto + next + case False + then have lookup_e': "mmap_lookup e' q = Some (Sup_fin ((the \ mmap_lookup e) ` Z))" + using Z_def lookup_fold_sup[OF distinct_before(2)] + unfolding e'_fold_sup_st'' + by (auto simp: Let_def) + define L where "L = {l. l < i \ steps step rho' init (l, Suc j) = q}" + have fin_L: "finite L" + unfolding L_def by auto + have Z_alt: "Z = {x. \l < i. steps step rho' init (l, j) = x \ step x bs = q}" + using Z_def[unfolded keys_e_alt] by auto + have fin_Z: "finite Z" + unfolding Z_alt by auto + have L_nonempty: "L \ {}" + using L_def Z_alt False i_j steps_app[of _ _ step rho q] + by (auto simp: bs_at_rho'_j) + (smt Suc_eq_plus1 bs_at_rho'_j less_irrefl_nat less_le_trans nat_le_linear steps_app) + have sup_leadsto: "sup_leadsto init step rho' i (Suc j) q = Some (ts_at rho' (Max L))" + using L_nonempty L_def + by (auto simp add: sup_leadsto_def) + have j_lt_rho': "j < length rho'" + using valid_before + by (auto simp: rho'_def) + have "Sup_fin ((the \ mmap_lookup e) ` Z) = ts_at rho' (Max L)" + proof (rule antisym) + obtain z ts where zts_def: "z \ Z" "(the \ mmap_lookup e) z = ts" + "Sup_fin ((the \ mmap_lookup e) ` Z) = ts" + proof - + assume lassm: "\z ts. z \ Z \ (the \ mmap_lookup e) z = ts \ + \\<^sub>f\<^sub>i\<^sub>n ((the \ mmap_lookup e) ` Z) = ts \ thesis" + define T where "T = (the \ mmap_lookup e) ` Z" + have T_sub: "T \ ts_at rho' ` {..j}" + using lookup_e keys_e_alt i_j + by (auto simp add: T_def Z_def sup_leadsto_def) + have "finite T" "T \ {}" + using fin_Z False + by (auto simp add: T_def) + then have sup_in: "\\<^sub>f\<^sub>i\<^sub>n T \ T" + proof (rule sup_fin_closed) + fix x y + assume xy: "x \ T" "y \ T" + then obtain a c where "x = ts_at rho' a" "y = ts_at rho' c" "a \ j" "c \ j" + using T_sub + by (meson atMost_iff imageE subsetD) + then show "sup x y \ {x, y}" + using ts_at_mono j_lt_rho' + by (cases "a \ c") (auto simp add: sup.absorb1 sup.absorb2) + qed + then show ?thesis + using lassm + by (auto simp add: T_def) + qed + from zts_def(2) have lookup_e_z: "mmap_lookup e z = Some ts" + using zts_def(1) Z_def by (auto dest: Mapping_keys_dest) + have "sup_leadsto init step rho' i j z = Some ts" + using lookup_e_z lookup_e + by auto + then obtain l where l_def: "l < i" "steps step rho' init (l, j) = z" "ts_at rho' l = ts" + using sup_leadsto_SomeE[OF i_j] + by (fastforce simp: rho'_def ts_at_def nth_append) + have l_j: "l \ j" + using less_le_trans[OF l_def(1) i_j] by auto + have "l \ L" + unfolding L_def using l_def zts_def(1) Z_alt + by auto (metis (no_types, lifting) Suc_eq_plus1 bs_at_rho'_j l_j steps_app) + then have "l \ Max L" "Max L < i" + using L_nonempty fin_L + by (auto simp add: L_def) + then show "Sup_fin ((the \ mmap_lookup e) ` Z) \ ts_at rho' (Max L)" + unfolding zts_def(3) l_def(3)[symmetric] + using ts_at_mono i_j j_lt_rho' + by (auto simp: rho'_def) + next + obtain l where l_def: "Max L = l" "l < i" "steps step rho' init (l, Suc j) = q" + using Max_in[OF fin_L L_nonempty] L_def by auto + obtain z where z_def: "steps step rho' init (l, j) = z" "step z bs = q" + using l_def(2,3) i_j bs_at_rho'_j + by (metis less_imp_le_nat less_le_trans steps_appE) + have z_in_Z: "z \ Z" + unfolding Z_alt + using l_def(2) z_def i_j + by fastforce + have lookup_e_z: "mmap_lookup e z = sup_leadsto init step rho' i j z" + using lookup_e z_in_Z Z_alt + by auto + obtain l' where l'_def: "sup_leadsto init step rho' i j z = Some (ts_at rho' l')" + "l \ l'" "l' < i" + using sup_leadsto_SomeI[OF l_def(2) z_def(1)] by auto + have "ts_at rho' l' \ (the \ mmap_lookup e) ` Z" + using lookup_e_z l'_def(1) z_in_Z + by force + then have "ts_at rho' l' \ Sup_fin ((the \ mmap_lookup e) ` Z)" + using Inf_fin_le_Sup_fin fin_Z z_in_Z + by (simp add: Sup_fin.coboundedI) + then show "ts_at rho' (Max L) \ Sup_fin ((the \ mmap_lookup e) ` Z)" + unfolding l_def(1) + using ts_at_mono l'_def(2,3) i_j j_lt_rho' + by (fastforce simp: rho'_def) + qed + then show ?thesis + unfolding lookup_e' sup_leadsto by auto + qed + qed + have "distinct (map fst s')" "distinct (map fst e')" + using distinct_before mmap_fold_distinct + unfolding s'_mmap_map mmap_map_fst e'_fold_sup_st'' fold_sup_def + by auto + moreover have "mmap_keys s' = {q. \l\i. steps step rho' init (l, i) = q}" + unfolding keys_s' rho'_def + using valid_before(1,7) valid_s_def[of init step st accept rho i i j s] + by (auto simp: steps_app_cong[of _ rho step]) + moreover have "reaches_on run_t ti (drop i (map fst rho')) tj'" + "reaches_on run_sub si (drop i (map snd rho')) sj'" + using valid_before reaches_on_app run_tj run_sj + by (auto simp: rho'_def run_t_def run_sub_def) + ultimately show ?thesis + unfolding adv_end + using valid_before lookup_e' lookup_s' ts_at_mono s'_mmap_map(3) e'_fold_sup_st''(2) + by (fastforce simp: valid_window_def Let_def init_def step_def accept_def run_t_def + run_sub_def i_def ti_def si_def j_def tj_def sj_def s_def e'_def + rho'_def valid_s_def intro!: exI[of _ rho'] split: option.splits) +qed + +lemma adv_end_bounds: + assumes "w_run_t args (w_tj w) = Some (tj', t)" + "w_run_sub args (w_sj w) = Some (sj', bs)" + "adv_end args w = Some w'" + shows "w_i w' = w_i w" "w_ti w' = w_ti w" "w_si w' = w_si w" + "w_j w' = Suc (w_j w)" "w_tj w' = tj'" "w_sj w' = sj'" + using assms + by (auto simp: adv_end_def Let_def split: prod.splits) + +definition drop_cur :: "nat \ ('c \ ('d \ nat) option) \ ('c \ ('d \ nat) option)" where + "drop_cur i = (\(q', tstp). (q', case tstp of Some (ts, tp) \ + if tp = i then None else tstp | None \ tstp))" + +definition adv_d :: "('c \ 'b \ 'c) \ ('c \ 'b, 'c) mapping \ nat \ 'b \ + ('c, 'c \ ('d \ nat) option) mmap \ + (('c, 'c \ ('d \ nat) option) mmap \ ('c \ 'b, 'c) mapping)" where + "adv_d step st i b s = (mmap_fold' s st (\((x, v), st). case cstep step st x b of (x', st') \ + ((x', drop_cur i v), st')) (\x y. x) [])" + +lemma adv_d_mmap_fold: + assumes inv: "\q bs. case Mapping.lookup st (q, bs) of None \ True | Some v \ step q bs = v" + and fold': "mmap_fold' s st (\((x, v), st). case cstep step st x bs of (x', st') \ + ((x', drop_cur i v), st')) (\x y. x) r = (s', st')" + shows "s' = mmap_fold s (\(x, v). (step x bs, drop_cur i v)) (\x y. x) r \ + (\q bs. case Mapping.lookup st' (q, bs) of None \ True | Some v \ step q bs = v)" +proof - + define inv where "inv \ \st. \q bs. case Mapping.lookup st (q, bs) of None \ True + | Some v \ step q bs = v" + have inv_st: "inv st" + using inv + by (auto simp: inv_def) + show ?thesis + by (rule mmap_fold'_eq[OF fold', of inv "\(x, v). (step x bs, drop_cur i v)", + OF inv_st, unfolded inv_def]) + (auto simp: cstep_def Let_def Mapping.lookup_update' + split: prod.splits option.splits if_splits) +qed + +definition keys_idem :: "('c \ 'b \ 'c) \ nat \ 'b \ + ('c, 'c \ ('d \ nat) option) mmap \ bool" where + "keys_idem step i b s = (\x \ mmap_keys s. \x' \ mmap_keys s. + step x b = step x' b \ drop_cur i (the (mmap_lookup s x)) = + drop_cur i (the (mmap_lookup s x')))" + +lemma adv_d_keys: + assumes inv: "\q bs. case Mapping.lookup st (q, bs) of None \ True | Some v \ step q bs = v" + and distinct: "distinct (map fst s)" + and adv_d: "adv_d step st i bs s = (s', st')" +shows "mmap_keys s' = (\q. step q bs) ` (mmap_keys s)" + using adv_d_mmap_fold[OF inv adv_d[unfolded adv_d_def]] + mmap_fold_set[OF distinct] + unfolding mmap_keys_def + by fastforce + +lemma lookup_adv_d_None: + assumes inv: "\q bs. case Mapping.lookup st (q, bs) of None \ True | Some v \ step q bs = v" + and distinct: "distinct (map fst s)" + and adv_d: "adv_d step st i bs s = (s', st')" + and Z_empty: "{x \ mmap_keys s. step x bs = z} = {}" + shows "mmap_lookup s' z = None" +proof - + have "z \ mmap_keys (mmap_fold s (\(x, v). (step x bs, drop_cur i v)) (\x y. x) [])" + using Z_empty[unfolded mmap_keys_def] mmap_fold_set[OF distinct] + by (auto simp: mmap_keys_def) + then show ?thesis + using adv_d adv_d_mmap_fold[OF inv adv_d[unfolded adv_d_def]] + unfolding adv_d_def + by (simp add: Mapping_lookup_None_intro) +qed + +lemma lookup_adv_d_Some: + assumes inv: "\q bs. case Mapping.lookup st (q, bs) of None \ True | Some v \ step q bs = v" + and distinct: "distinct (map fst s)" and idem: "keys_idem step i bs s" + and wit: "x \ mmap_keys s" "step x bs = z" + and adv_d: "adv_d step st i bs s = (s', st')" + shows "mmap_lookup s' z = Some (drop_cur i (the (mmap_lookup s x)))" +proof - + have z_in_keys: "z \ mmap_keys (mmap_fold s (\(x, v). (step x bs, drop_cur i v)) (\x y. x) [])" + using wit(1,2)[unfolded mmap_keys_def] mmap_fold_set[OF distinct] + by (force simp: mmap_keys_def) + obtain v vs where vs_def: "mmap_lookup s' z = Some (foldl (\x y. x) v vs)" + "v # vs = map (\(x, v). drop_cur i v) (filter (\(k, v). step k bs = z) s)" + using adv_d adv_d_mmap_fold[OF inv adv_d[unfolded adv_d_def]] + unfolding adv_d_def + using mmap_fold_lookup[OF distinct, of "(\(x, v). (step x bs, drop_cur i v))" "\x y. x" z] + Mapping_keys_dest[OF z_in_keys] + by (force simp: adv_d_def mmap_keys_def split: list.splits) + have "set (v # vs) = drop_cur i ` (the \ mmap_lookup s) ` {x \ mmap_keys s. step x bs = z}" + proof (rule set_eqI, rule iffI) + fix w + assume "w \ set (v # vs)" + then obtain x y where xy_def: "x \ mmap_keys s" "step x bs = z" "(x, y) \ set s" + "w = drop_cur i y" + using vs_def(2) + by (auto simp add: mmap_keys_def rev_image_eqI) + show "w \ drop_cur i ` (the \ mmap_lookup s) ` {x \ mmap_keys s. step x bs = z}" + using xy_def(1,2,4) mmap_lookup_distinct[OF distinct xy_def(3)] + by force + next + fix w + assume "w \ drop_cur i ` (the \ mmap_lookup s) ` {x \ mmap_keys s. step x bs = z}" + then obtain x y where xy_def: "x \ mmap_keys s" "step x bs = z" "(x, y) \ set s" + "w = drop_cur i y" + using mmap_lookup_distinct[OF distinct] + by (auto simp add: Mapping_keys_intro distinct mmap_lookup_def dest: Mapping_keys_dest) + show "w \ set (v # vs)" + using xy_def + by (force simp: vs_def(2)) + qed + then have "foldl (\x y. x) v vs = drop_cur i (the (mmap_lookup s x))" + using wit + apply (induction vs arbitrary: v) + apply (auto) + apply (smt empty_is_image idem imageE insert_not_empty keys_idem_def mem_Collect_eq + the_elem_eq the_elem_image_unique) + apply (smt Collect_cong idem imageE insert_compr keys_idem_def mem_Collect_eq) + done + then show ?thesis + using wit + by (auto simp: vs_def(1)) +qed + +definition "loop_cond j = (\(st, ac, i, ti, si, q, s, tstp). i < j \ q \ mmap_keys s)" +definition "loop_body step accept run_t run_sub = + (\(st, ac, i, ti, si, q, s, tstp). case run_t ti of Some (ti', t) \ + case run_sub si of Some (si', b) \ case adv_d step st i b s of (s', st') \ + case cstep step st' q b of (q', st'') \ case cac accept ac q' of (\, ac') \ + (st'', ac', Suc i, ti', si', q', s', if \ then Some (t, i) else tstp))" +definition "loop_inv init step accept args t0 sub rho u j tj sj = + (\(st, ac, i, ti, si, q, s, tstp). u + 1 \ i \ + reach_window args t0 sub rho (i, ti, si, j, tj, sj) \ + steps step rho init (u + 1, i) = q \ + (\q. case Mapping.lookup ac q of None \ True | Some v \ accept q = v) \ + valid_s init step st accept rho u i j s \ tstp = sup_acc step accept rho init (u + 1) i)" + +definition mmap_update :: "'a \ 'b \ ('a, 'b) mmap \ ('a, 'b) mmap" where + "mmap_update = AList.update" + +lemma mmap_update_distinct: "distinct (map fst m) \ distinct (map fst (mmap_update k v m))" + by (auto simp: mmap_update_def distinct_update) + +definition adv_start :: "('b, 'c, 'd :: timestamp, 't, 'e) args \ + ('b, 'c, 'd, 't, 'e) window \ ('b, 'c, 'd, 't, 'e) window" where + "adv_start args w = (let init = w_init args; step = w_step args; accept = w_accept args; + run_t = w_run_t args; run_sub = w_run_sub args; st = w_st w; ac = w_ac w; + i = w_i w; ti = w_ti w; si = w_si w; j = w_j w; + s = w_s w; e = w_e w in + (case run_t ti of Some (ti', t) \ (case run_sub si of Some (si', bs) \ + let (s', st') = adv_d step st i bs s; + e' = mmap_update (fst (the (mmap_lookup s init))) t e; + (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) = + while (loop_cond j) (loop_body step accept run_t run_sub) + (st', ac, Suc i, ti', si', init, s', None); + s'' = mmap_update init (case mmap_lookup s_cur q_cur of Some (q', tstp') \ + (case tstp' of Some (ts, tp) \ (q', tstp') | None \ (q', tstp_cur)) + | None \ (q_cur, tstp_cur)) s' in + w\w_st := st_cur, w_ac := ac_cur, w_i := Suc i, w_ti := ti', w_si := si', + w_s := s'', w_e := e'\)))" + +lemma valid_adv_d: + assumes valid_before: "valid_s init step st accept rho u i j s" + and u_le_i: "u \ i" and i_lt_j: "i < j" and b_def: "b = bs_at rho i" + and adv_d: "adv_d step st i b s = (s', st')" + shows "valid_s init step st' accept rho u (i + 1) j s'" +proof - + have inv_st: "\q bs. case Mapping.lookup st (q, bs) of None \ True | Some v \ step q bs = v" + using valid_before by (auto simp add: valid_s_def) + have keys_s: "mmap_keys s = {q. (\l \ u. steps step rho init (l, i) = q)}" + using valid_before by (auto simp add: valid_s_def) + have fin_keys_s: "finite (mmap_keys s)" + using valid_before by (auto simp add: valid_s_def) + have lookup_s: "\q q' tstp. mmap_lookup s q = Some (q', tstp) \ + steps step rho q (i, j) = q' \ tstp = sup_acc step accept rho q i j" + using valid_before Mapping_keys_intro + by (auto simp add: valid_s_def) (smt case_prodD option.simps(5))+ + have drop_cur_i: "\x. x \ mmap_keys s \ drop_cur i (the (mmap_lookup s x)) = + (steps step rho (step x (bs_at rho i)) (i + 1, j), + sup_acc step accept rho (step x (bs_at rho i)) (i + 1) j)" + proof - + fix x + assume assms: "x \ mmap_keys s" + obtain q tstp where q_def: "mmap_lookup s x = Some (q, tstp)" + using assms(1) by (auto dest: Mapping_keys_dest) + have q_q': "q = steps step rho (step x (bs_at rho i)) (i + 1, j)" + "tstp = sup_acc step accept rho x i j" + using lookup_s[OF q_def] steps_split[OF i_lt_j] assms(1) by auto + show "drop_cur i (the (mmap_lookup s x)) = + (steps step rho (step x (bs_at rho i)) (i + 1, j), + sup_acc step accept rho (step x (bs_at rho i)) (i + 1) j)" + using q_def sup_acc_None[OF i_lt_j, of step accept rho] + sup_acc_i[OF i_lt_j, of step accept rho] sup_acc_l[OF i_lt_j, of _ step accept rho] + unfolding q_q' + by (auto simp add: drop_cur_def split: option.splits) + qed + have valid_drop_cur: "\x x'. x \ mmap_keys s \ x' \ mmap_keys s \ + step x (bs_at rho i) = step x' (bs_at rho i) \ drop_cur i (the (mmap_lookup s x)) = + drop_cur i (the (mmap_lookup s x'))" + using drop_cur_i by auto + then have keys_idem: "keys_idem step i b s" + unfolding keys_idem_def b_def + by blast + have distinct: "distinct (map fst s)" + using valid_before + by (auto simp: valid_s_def) + have "(\q. step q (bs_at rho i)) ` {q. \l\u. steps step rho init (l, i) = q} = + {q. \l\u. steps step rho init (l, i + 1) = q}" + using steps_app[of _ i step rho init] u_le_i + by auto + then have keys_s': "mmap_keys s' = {q. \l\u. steps step rho init (l, i + 1) = q}" + using adv_d_keys[OF _ distinct adv_d] inv_st + unfolding keys_s b_def + by auto + have lookup_s': "\q q' tstp. mmap_lookup s' q = Some (q', tstp) \ + steps step rho q (i + 1, j) = q' \ tstp = sup_acc step accept rho q (i + 1) j" + proof - + fix q q' tstp + assume assm: "mmap_lookup s' q = Some (q', tstp)" + obtain x where wit: "x \ mmap_keys s" "step x (bs_at rho i) = q" + using assm lookup_adv_d_None[OF _ distinct adv_d] inv_st + by (fastforce simp: b_def) + have lookup_s'_q: "mmap_lookup s' q = Some (drop_cur i (the (mmap_lookup s x)))" + using lookup_adv_d_Some[OF _ distinct keys_idem wit[folded b_def] adv_d] inv_st + by auto + then show "steps step rho q (i + 1, j) = q' \ tstp = sup_acc step accept rho q (i + 1) j" + using assm + by (simp add: drop_cur_i wit) + qed + have "distinct (map fst s')" + using mmap_fold_distinct[OF distinct] adv_d_mmap_fold[OF inv_st adv_d[unfolded adv_d_def]] + unfolding adv_d_def mmap_map_fst + by auto + then show "valid_s init step st' accept rho u (i + 1) j s'" + unfolding valid_s_def + using keys_s' lookup_s' u_le_i inv_st adv_d[unfolded adv_d_def] + adv_d_mmap_fold[OF inv_st adv_d[unfolded adv_d_def]] + by (auto split: option.splits dest: Mapping_keys_dest) +qed + +lemma mmap_lookup_update': + "mmap_lookup (mmap_update k v kvs) z = (if k = z then Some v else mmap_lookup kvs z)" + unfolding mmap_lookup_def mmap_update_def + by (auto simp add: update_conv') + +lemma mmap_keys_update: "mmap_keys (mmap_update k v kvs) = mmap_keys kvs \ {k}" + by (induction kvs) (auto simp: mmap_keys_def mmap_update_def) + +lemma valid_adv_start: + assumes "valid_window args t0 sub rho w" "w_i w < w_j w" + shows "valid_window args t0 sub rho (adv_start args w)" +proof - + define init where "init = w_init args" + define step where "step = w_step args" + define accept where "accept = w_accept args" + define run_t where "run_t = w_run_t args" + define run_sub where "run_sub = w_run_sub args" + define st where "st = w_st w" + define ac where "ac = w_ac w" + define i where "i = w_i w" + define ti where "ti = w_ti w" + define si where "si = w_si w" + define j where "j = w_j w" + define tj where "tj = w_tj w" + define sj where "sj = w_sj w" + define s where "s = w_s w" + define e where "e = w_e w" + have valid_before: "reach_window args t0 sub rho (i, ti, si, j, tj, sj)" + "\i j. i \ j \ j < length rho \ ts_at rho i \ ts_at rho j" + "(\q bs. case Mapping.lookup st (q, bs) of None \ True | Some v \ step q bs = v)" + "(\q bs. case Mapping.lookup ac q of None \ True | Some v \ accept q = v)" + "\q. mmap_lookup e q = sup_leadsto init step rho i j q" "distinct (map fst e)" + "valid_s init step st accept rho i i j s" + using assms(1) + unfolding valid_window_def valid_s_def Let_def init_def step_def accept_def run_t_def + run_sub_def st_def ac_def i_def ti_def si_def j_def tj_def sj_def s_def e_def + by auto + have distinct_before: "distinct (map fst s)" "distinct (map fst e)" + using valid_before + by (auto simp: valid_s_def) + note i_lt_j = assms(2)[folded i_def j_def] + obtain ti' si' t b where tb_def: "run_t ti = Some (ti', t)" + "run_sub si = Some (si', b)" + "reaches_on run_t ti' (drop (Suc i) (map fst rho)) tj" + "reaches_on run_sub si' (drop (Suc i) (map snd rho)) sj" + "t = ts_at rho i" "b = bs_at rho i" + using valid_before i_lt_j + apply (auto simp: ts_at_def bs_at_def run_t_def[symmetric] run_sub_def[symmetric] + elim!: reaches_on.cases[of run_t ti "drop i (map fst rho)" tj] + reaches_on.cases[of run_sub si "drop i (map snd rho)" sj]) + by (metis Cons_nth_drop_Suc length_map list.inject nth_map) + have reaches_on_si': "reaches_on run_sub sub (take (Suc i) (map snd rho)) si'" + using valid_before tb_def(2,3,4) i_lt_j reaches_on_app tb_def(1) + by (auto simp: run_sub_def sub_def bs_at_def take_Suc_conv_app_nth reaches_on_app tb_def(6)) + have reaches_on_ti': "reaches_on run_t t0 (take (Suc i) (map fst rho)) ti'" + using valid_before tb_def(2,3,4) i_lt_j reaches_on_app tb_def(1) + by (auto simp: run_t_def ts_at_def take_Suc_conv_app_nth reaches_on_app tb_def(5)) + define e' where "e' = mmap_update (fst (the (mmap_lookup s init))) t e" + obtain st' s' where s'_def: "adv_d step st i b s = (s', st')" + by (metis old.prod.exhaust) + obtain st_cur ac_cur i_cur ti_cur si_cur q_cur s_cur tstp_cur where loop_def: + "(st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) = + while (loop_cond j) (loop_body step accept run_t run_sub) + (st', ac, Suc i, ti', si', init, s', None)" + by (cases "while (loop_cond j) (loop_body step accept run_t run_sub) + (st', ac, Suc i, ti', si', init, s', None)") auto + define s'' where "s'' = mmap_update init (case mmap_lookup s_cur q_cur of + Some (q', tstp') \ (case tstp' of Some (ts, tp) \ (q', tstp') | None \ (q', tstp_cur)) + | None \ (q_cur, tstp_cur)) s'" + have i_le_j: "i \ j" + using i_lt_j by auto + have length_rho: "length rho = j" + using valid_before by auto + have lookup_s: "\q q' tstp. mmap_lookup s q = Some (q', tstp) \ + steps step rho q (i, j) = q' \ tstp = sup_acc step accept rho q i j" + using valid_before Mapping_keys_intro + by (auto simp: valid_s_def) (smt case_prodD option.simps(5))+ + have init_in_keys_s: "init \ mmap_keys s" + using valid_before by (auto simp add: valid_s_def) + then have run_init_i_j: "steps step rho init (i, j) = fst (the (mmap_lookup s init))" + using lookup_s by (auto dest: Mapping_keys_dest) + have lookup_e: "\q. mmap_lookup e q = sup_leadsto init step rho i j q" + using valid_before by auto + have lookup_e': "\q. mmap_lookup e' q = sup_leadsto init step rho (i + 1) j q" + proof - + fix q + show "mmap_lookup e' q = sup_leadsto init step rho (i + 1) j q" + proof (cases "steps step rho init (i, j) = q") + case True + have "Max {l. l < Suc i \ steps step rho init (l, j) = steps step rho init (i, j)} = i" + by (rule iffD2[OF Max_eq_iff]) auto + then have "sup_leadsto init step rho (i + 1) j q = Some (ts_at rho i)" + by (auto simp add: sup_leadsto_def True) + then show ?thesis + unfolding e'_def using run_init_i_j tb_def + by (auto simp add: mmap_lookup_update' True) + next + case False + show ?thesis + using run_init_i_j sup_leadsto_idle[OF i_lt_j False] lookup_e[of q] False + by (auto simp add: e'_def mmap_lookup_update') + qed + qed + have reach_split: "{q. \l\i + 1. steps step rho init (l, i + 1) = q} = + {q. \l\i. steps step rho init (l, i + 1) = q} \ {init}" + using le_Suc_eq by auto + have valid_s_i: "valid_s init step st accept rho i i j s" + using valid_before by auto + have valid_s'_Suc_i: "valid_s init step st' accept rho i (i + 1) j s'" + using valid_adv_d[OF valid_s_i order.refl i_lt_j, OF tb_def(6) s'_def] unfolding s'_def . + have loop: "loop_inv init step accept args t0 sub rho i j tj sj + (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur) \ + \loop_cond j (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur)" + unfolding loop_def + proof (rule while_rule_lemma[of "loop_inv init step accept args t0 sub rho i j tj sj" + "loop_cond j" "loop_body step accept run_t run_sub" + "\s. loop_inv init step accept args t0 sub rho i j tj sj s \ \ loop_cond j s"]) + show "loop_inv init step accept args t0 sub rho i j tj sj + (st', ac, Suc i, ti', si', init, s', None)" + unfolding loop_inv_def + using i_lt_j valid_s'_Suc_i sup_acc_same[of step accept rho] + length_rho reaches_on_si' reaches_on_ti' tb_def(3,4) valid_before(4) + by (auto simp: run_t_def run_sub_def split: prod.splits) + next + have "{(t, s). loop_inv init step accept args t0 sub rho i j tj sj s \ + loop_cond j s \ t = loop_body step accept run_t run_sub s} \ + measure (\(st, ac, i_cur, ti, si, q, s, tstp). j - i_cur)" + unfolding loop_inv_def loop_cond_def loop_body_def + apply (auto simp: run_t_def run_sub_def split: option.splits) + apply (metis drop_eq_Nil length_map not_less option.distinct(1) reaches_on.simps) + apply (metis (no_types, lifting) drop_eq_Nil length_map not_less option.distinct(1) + reaches_on.simps) + apply (auto split: prod.splits) + done + then show "wf {(t, s). loop_inv init step accept args t0 sub rho i j tj sj s \ + loop_cond j s \ t = loop_body step accept run_t run_sub s}" + using wf_measure wf_subset by auto + next + fix state + assume assms: "loop_inv init step accept args t0 sub rho i j tj sj state" + "loop_cond j state" + obtain st_cur ac_cur i_cur ti_cur si_cur q_cur s_cur tstp_cur + where state_def: "state = (st_cur, ac_cur, i_cur, ti_cur, si_cur, q_cur, s_cur, tstp_cur)" + by (cases state) auto + obtain ti'_cur si'_cur t_cur b_cur where tb_cur_def: "run_t ti_cur = Some (ti'_cur, t_cur)" + "run_sub si_cur = Some (si'_cur, b_cur)" + "reaches_on run_t ti'_cur (drop (Suc i_cur) (map fst rho)) tj" + "reaches_on run_sub si'_cur (drop (Suc i_cur) (map snd rho)) sj" + "t_cur = ts_at rho i_cur" "b_cur = bs_at rho i_cur" + using assms + unfolding loop_inv_def loop_cond_def state_def + apply (auto simp: ts_at_def bs_at_def run_t_def[symmetric] run_sub_def[symmetric] + elim!: reaches_on.cases[of run_t ti_cur "drop i_cur (map fst rho)" tj] + reaches_on.cases[of run_sub si_cur "drop i_cur (map snd rho)" sj]) + by (metis Cons_nth_drop_Suc length_map list.inject nth_map) + obtain s'_cur st'_cur where s'_cur_def: "adv_d step st_cur i_cur b_cur s_cur = + (s'_cur, st'_cur)" + by fastforce + have valid_s'_cur: "valid_s init step st'_cur accept rho i (i_cur + 1) j s'_cur" + using assms valid_adv_d[of init step st_cur accept rho] tb_cur_def(6) s'_cur_def + unfolding loop_inv_def loop_cond_def state_def + by auto + obtain q' st''_cur where q'_def: "cstep step st'_cur q_cur b_cur = (q', st''_cur)" + by fastforce + obtain \ ac'_cur where b_def: "cac accept ac_cur q' = (\, ac'_cur)" + by fastforce + have step: "q' = step q_cur b_cur" "\q bs. case Mapping.lookup st''_cur (q, bs) of + None \ True | Some v \ step q bs = v" + using valid_s'_cur q'_def + unfolding valid_s_def + by (auto simp: cstep_def Let_def Mapping.lookup_update' split: option.splits if_splits) + have accept: "\ = accept q'" "\q. case Mapping.lookup ac'_cur q of + None \ True | Some v \ accept q = v" + using assms b_def + unfolding loop_inv_def state_def + by (auto simp: cac_def Let_def Mapping.lookup_update' split: option.splits if_splits) + have steps_q': "steps step rho init (i + 1, Suc i_cur) = q'" + using assms + unfolding loop_inv_def state_def + by auto (metis local.step(1) steps_appE tb_cur_def(6)) + have b_acc: "\ = acc step accept rho init (i + 1, Suc i_cur)" + unfolding accept(1) acc_def steps_q' + by (auto simp: tb_cur_def) + have valid_s''_cur: "valid_s init step st''_cur accept rho i (i_cur + 1) j s'_cur" + using valid_s'_cur step(2) + unfolding valid_s_def + by auto + have reaches_on_si': "reaches_on run_sub sub (take (Suc i_cur) (map snd rho)) si'_cur" + using assms + unfolding loop_inv_def loop_cond_def state_def + by (auto simp: run_sub_def sub_def bs_at_def take_Suc_conv_app_nth reaches_on_app + tb_cur_def(2,4,6)) + (metis bs_at_def reaches_on_app run_sub_def tb_cur_def(2) tb_cur_def(6)) + have reaches_on_ti': "reaches_on run_t t0 (take (Suc i_cur) (map fst rho)) ti'_cur" + using assms + unfolding loop_inv_def loop_cond_def state_def + by (auto simp: run_t_def ts_at_def take_Suc_conv_app_nth reaches_on_app tb_cur_def(1,3,5)) + (metis reaches_on_app run_t_def tb_cur_def(1) tb_cur_def(5) ts_at_def) + have "reach_window args t0 sub rho (Suc i_cur, ti'_cur, si'_cur, j, tj, sj)" + using reaches_on_si' reaches_on_ti' tb_cur_def(3,4) length_rho assms(2) + unfolding loop_cond_def state_def + by (auto simp: run_t_def run_sub_def) + moreover have "steps step rho init (i + 1, Suc i_cur) = q'" + using assms steps_app + unfolding loop_inv_def state_def step(1) + by (auto simp: tb_cur_def(6)) + ultimately show "loop_inv init step accept args t0 sub rho i j tj sj + (loop_body step accept run_t run_sub state)" + using assms accept(2) valid_s''_cur sup_acc_ext[of _ _ step accept rho] + sup_acc_ext_idle[of _ _ step accept rho] + unfolding loop_inv_def loop_body_def state_def + by (auto simp: tb_cur_def(1,2,5) s'_cur_def q'_def b_def b_acc + split: option.splits prod.splits) + qed auto + have valid_stac_cur: "\q bs. case Mapping.lookup st_cur (q, bs) of None \ True + | Some v \ step q bs = v" "\q. case Mapping.lookup ac_cur q of None \ True + | Some v \ accept q = v" + using loop unfolding loop_inv_def valid_s_def + by auto + have valid_s'': "valid_s init step st_cur accept rho (i + 1) (i + 1) j s''" + proof (cases "mmap_lookup s_cur q_cur") + case None + then have added: "steps step rho init (i + 1, j) = q_cur" + "tstp_cur = sup_acc step accept rho init (i + 1) j" + using loop unfolding loop_inv_def loop_cond_def + by (auto dest: Mapping_keys_dest) + have s''_case: "s'' = mmap_update init (q_cur, tstp_cur) s'" + unfolding s''_def using None by auto + show ?thesis + using valid_s'_Suc_i reach_split added mmap_update_distinct valid_stac_cur + unfolding s''_case valid_s_def mmap_keys_update + by (auto simp add: mmap_lookup_update' split: option.splits) + next + case (Some p) + obtain q' tstp' where p_def: "p = (q', tstp')" + by (cases p) auto + note lookup_s_cur = Some[unfolded p_def] + have i_cur_in: "i + 1 \ i_cur" "i_cur \ j" + using loop unfolding loop_inv_def by auto + have q_cur_def: "steps step rho init (i + 1, i_cur) = q_cur" + using loop unfolding loop_inv_def by auto + have valid_s_cur: "valid_s init step st_cur accept rho i i_cur j s_cur" + using loop unfolding loop_inv_def by auto + have q'_steps: "steps step rho q_cur (i_cur, j) = q'" + using Some valid_s_cur unfolding valid_s_def p_def + by (auto intro: Mapping_keys_intro) (smt case_prodD option.simps(5)) + have tstp_cur: "tstp_cur = sup_acc step accept rho init (i + 1) i_cur" + using loop unfolding loop_inv_def by auto + have tstp': "tstp' = sup_acc step accept rho q_cur i_cur j" + using loop Some unfolding loop_inv_def p_def valid_s_def + by (auto intro: Mapping_keys_intro) (smt case_prodD option.simps(5)) + have added: "steps step rho init (i + 1, j) = q'" + using steps_comp[OF i_cur_in q_cur_def q'_steps] . + show ?thesis + proof (cases tstp') + case None + have s''_case: "s'' = mmap_update init (q', tstp_cur) s'" + unfolding s''_def lookup_s_cur None by auto + have tstp_cur_opt: "tstp_cur = sup_acc step accept rho init (i + 1) j" + using sup_acc_comp_None[OF i_cur_in, of step accept rho init, unfolded q_cur_def, + OF tstp'[unfolded None, symmetric]] + unfolding tstp_cur by auto + then show ?thesis + using valid_s'_Suc_i reach_split added mmap_update_distinct valid_stac_cur + unfolding s''_case valid_s_def mmap_keys_update + by (auto simp add: mmap_lookup_update' split: option.splits) + next + case (Some p') + obtain ts tp where p'_def: "p' = (ts, tp)" + by (cases p') auto + have True: "tp \ i_cur" + using sup_acc_SomeE[OF tstp'[unfolded Some p'_def, symmetric]] by auto + have s''_case: "s'' = mmap_update init (q', tstp') s'" + unfolding s''_def lookup_s_cur Some p'_def using True by auto + have tstp'_opt: "tstp' = sup_acc step accept rho init (i + 1) j" + using sup_acc_comp_Some_ge[OF i_cur_in True + tstp'[unfolded Some p'_def q_cur_def[symmetric], symmetric]] + unfolding tstp' by (auto simp: q_cur_def[symmetric]) + then show ?thesis + using valid_s'_Suc_i reach_split added mmap_update_distinct valid_stac_cur + unfolding s''_case valid_s_def mmap_keys_update + by (auto simp add: mmap_lookup_update' split: option.splits) + qed + qed + have "distinct (map fst e')" + using mmap_update_distinct[OF distinct_before(2), unfolded e'_def] + unfolding e'_def . + then have "valid_window args t0 sub rho + (w\w_st := st_cur, w_ac := ac_cur, w_i := Suc i, w_ti := ti', w_si := si', w_s := s'', w_e := e'\)" + using i_lt_j lookup_e' valid_s'' length_rho tb_def(3,4) reaches_on_si' reaches_on_ti' + valid_before[unfolded step_def accept_def] valid_stac_cur(2)[unfolded accept_def] + by (auto simp: valid_window_def Let_def init_def step_def accept_def run_t_def + run_sub_def st_def ac_def i_def ti_def si_def j_def tj_def sj_def s_def e_def) + moreover have "adv_start args w = w\w_st := st_cur, w_ac := ac_cur, w_i := Suc i, + w_ti := ti', w_si := si', w_s := s'', w_e := e'\" + unfolding adv_start_def Let_def s''_def e'_def + using tb_def(1,2) s'_def i_lt_j loop_def valid_before(3) + by (auto simp: valid_window_def Let_def init_def step_def accept_def run_t_def + run_sub_def st_def ac_def i_def ti_def si_def j_def tj_def sj_def s_def e_def + split: prod.splits) + ultimately show ?thesis + by auto +qed + +lemma valid_adv_start_bounds: + assumes "valid_window args t0 sub rho w" "w_i w < w_j w" + shows "w_i (adv_start args w) = Suc (w_i w)" "w_j (adv_start args w) = w_j w" + "w_tj (adv_start args w) = w_tj w" "w_sj (adv_start args w) = w_sj w" + using assms + by (auto simp: adv_start_def Let_def valid_window_def split: option.splits prod.splits + elim: reaches_on.cases) + +lemma valid_adv_start_bounds': + assumes "valid_window args t0 sub rho w" "w_run_t args (w_ti w) = Some (ti', t)" + "w_run_sub args (w_si w) = Some (si', bs)" + shows "w_ti (adv_start args w) = ti'" "w_si (adv_start args w) = si'" + using assms + by (auto simp: adv_start_def Let_def valid_window_def split: option.splits prod.splits) + +end diff --git a/thys/VYDRA_MDL/document/root.bib b/thys/VYDRA_MDL/document/root.bib new file mode 100644 --- /dev/null +++ b/thys/VYDRA_MDL/document/root.bib @@ -0,0 +1,20 @@ +@inproceedings{DBLP:conf/atva/RaszykBT20, + author = {Martin Raszyk and + David A. Basin and + Dmitriy Traytel}, + editor = {Dang Van Hung and + Oleg Sokolsky}, + title = {Multi-head Monitoring of Metric Dynamic Logic}, + booktitle = {Automated Technology for Verification and Analysis - 18th International + Symposium, {ATVA} 2020, Hanoi, Vietnam, October 19-23, 2020, Proceedings}, + series = {Lecture Notes in Computer Science}, + volume = {12302}, + pages = {233--250}, + publisher = {Springer}, + year = {2020}, + url = {https://doi.org/10.1007/978-3-030-59152-6\_13}, + doi = {10.1007/978-3-030-59152-6\_13}, + timestamp = {Tue, 20 Oct 2020 18:27:30 +0200}, + biburl = {https://dblp.org/rec/conf/atva/RaszykBT20.bib}, + bibsource = {dblp computer science bibliography, https://dblp.org} +} diff --git a/thys/VYDRA_MDL/document/root.tex b/thys/VYDRA_MDL/document/root.tex new file mode 100644 --- /dev/null +++ b/thys/VYDRA_MDL/document/root.tex @@ -0,0 +1,66 @@ +\documentclass[10pt,a4paper]{article} +\usepackage[T1]{fontenc} +\usepackage{isabelle,isabellesym} +\usepackage{a4wide} +\usepackage[english]{babel} +\usepackage{eufrak} +\usepackage{amssymb} + +% this should be the last package used +\usepackage{pdfsetup} + +% urls in roman style, theory text in math-similar italics +\urlstyle{rm} +\isabellestyle{literal} + + +\begin{document} + +\title{Multi-Head Monitoring of Metric Dynamic Logic} +\author{Martin Raszyk} + +\maketitle + +\begin{abstract} +Runtime monitoring (or runtime verification) +is an approach to checking compliance +of a system's execution with a specification (e.g., a temporal query). +The system's execution is logged into a \emph{trace}---a sequence of time-points, +each consisting of a time-stamp and observed events. +A \emph{monitor} is an algorithm that produces \emph{verdicts} +on the satisfaction of a temporal query on a trace. + +We formalize a monitoring algorithm for metric dynamic logic, an extension of +metric temporal logic with regular expressions. The monitor computes whether a +given query is satisfied at every position in an input trace of +time-stamped events. We formalize the time-stamps as an abstract algebraic +structure satisfying certain assumptions. Instances of this structure +include natural numbers, real numbers, and lexicographic combinations of them. +Our monitor follows the multi-head paradigm: it reads the +input simultaneously at multiple positions and moves its reading heads +asynchronously. This mode of operation results in unprecedented time and space +complexity guarantees for metric dynamic logic: The monitor's amortized time +complexity to process a time-point and the monitor's space complexity +neither depends on the event-rate, i.e., the number of events within a fixed +time-unit, nor on the numeric constants occurring in the quantitative temporal +constraints in the given query. + +The multi-head monitoring algorithm for metric dynamic logic +is reported in our paper ``Multi-Head Monitoring of Metric Dynamic Logic''~\cite{DBLP:conf/atva/RaszykBT20} +published at ATVA 2020. +We have also formalized unpublished specialized algorithms +for the temporal operators of metric temporal logic. +\end{abstract} + +\tableofcontents + +% sane default for proof documents +\parindent 0pt\parskip 0.5ex + +% generated text of all theories +\input{session} + +\bibliographystyle{abbrv} +\bibliography{root} + +\end{document} diff --git a/thys/Wetzels_Problem/ROOT b/thys/Wetzels_Problem/ROOT new file mode 100644 --- /dev/null +++ b/thys/Wetzels_Problem/ROOT @@ -0,0 +1,12 @@ +chapter AFP + +session Wetzels_Problem (AFP) = "HOL-Complex_Analysis" + + options [timeout = 300] + sessions + ZFC_in_HOL + theories + Wetzels_Problem + document_files + "root.tex" + "root.bib" + diff --git a/thys/Wetzels_Problem/Wetzels_Problem.thy b/thys/Wetzels_Problem/Wetzels_Problem.thy new file mode 100644 --- /dev/null +++ b/thys/Wetzels_Problem/Wetzels_Problem.thy @@ -0,0 +1,868 @@ +section \Wetzel's Problem, Solved by Erdös\ + +text \Martin Aigner and Günter M. Ziegler. Proofs from THE BOOK. (Springer, 2018). +Chapter 19: Sets, functions, and the continuum hypothesis +Theorem 5 (pages 137--8)\ + +theory Wetzels_Problem imports + "HOL-Complex_Analysis.Complex_Analysis" "ZFC_in_HOL.ZFC_Typeclasses" + +begin + +subsection \Added to the developer libraries\ + +lemma inj_on_restrict_iff: "A \ B \ inj_on (restrict f B) A \ inj_on f A" + by (metis inj_on_cong restrict_def subset_iff) + +lemma Rats_closure_real: "closure \ = (UNIV::real set)" +proof - + have "\x::real. x \ closure \" + by (metis closure_approachable dist_real_def rational_approximation) + then show ?thesis by auto +qed + +lemma fsigma_UNIV [iff]: "fsigma (UNIV :: 'a::real_inner set)" +proof - + have "(UNIV ::'a set) = (\i. cball 0 (of_nat i))" + by (auto simp: real_arch_simple) + then show ?thesis + by (metis closed_cball fsigma.intros) +qed + +theorem complex_non_denum: "\f :: nat \ complex. surj f" + by (metis (full_types) Re_complex_of_real comp_surj real_non_denum surj_def) + +lemma uncountable_UNIV_complex: "uncountable (UNIV :: complex set)" + using complex_non_denum unfolding uncountable_def by auto + +lemma analytic_on_prod [analytic_intros]: + "(\i. i \ I \ (f i) analytic_on S) \ (\x. prod (\i. f i x) I) analytic_on S" + by (induct I rule: infinite_finite_induct) (auto simp: analytic_on_mult) + +lemma holomorphic_countable_zeros: + assumes S: "f holomorphic_on S" "open S" "connected S" and "fsigma S" + and "\ f constant_on S" + shows "countable {z\S. f z = 0}" +proof - + obtain F::"nat \ complex set" + where F: "range F \ Collect compact" and Seq: "S = (\i. F i)" + using \fsigma S\ by (meson fsigma_Union_compact) + have fin: "finite {z \ F i. f z = 0}" for i + using holomorphic_compact_finite_zeros assms F Seq Union_iff by blast + have "{z \ S. f z = 0} = (\i. {z \ F i. f z = 0})" + using Seq by auto + with fin show ?thesis + by (simp add: countable_finite) +qed + +lemma holomorphic_countable_equal: + assumes "f holomorphic_on S" "g holomorphic_on S" "open S" "connected S" and "fsigma S" + and eq: "uncountable {z\S. f z = g z}" + shows "S \ {z\S. f z = g z}" +proof - + obtain z where z: "z\S" "f z = g z" + using eq not_finite_existsD uncountable_infinite by blast + have "(\x. f x - g x) holomorphic_on S" + by (simp add: assms holomorphic_on_diff) + then have "(\x. f x - g x) constant_on S" + using holomorphic_countable_zeros assms by force + with z have "\x. x\S \ f x - g x = 0" + unfolding constant_on_def by force + then show ?thesis + by auto +qed + +lemma holomorphic_countable_equal_UNIV: + assumes fg: "f holomorphic_on UNIV" "g holomorphic_on UNIV" + and eq: "uncountable {z. f z = g z}" + shows "f=g" + using holomorphic_countable_equal [OF fg] eq by fastforce + +lemma finite_iff_less_Aleph0: "finite (elts x) \ vcard x < \" +proof + show "finite (elts x) \ vcard x < \" + by (metis Card_\ Card_def finite_lesspoll_infinite infinite_\ lesspoll_imp_Card_less) + show "vcard x < \ \ finite (elts x)" + by (meson Ord_cardinal cardinal_eqpoll eqpoll_finite_iff infinite_Ord_omega less_le_not_le) +qed + +lemma cadd_left_commute: "j \ (i \ k) = i \ (j \ k)" + using cadd_assoc cadd_commute by force + +lemmas cadd_ac = cadd_assoc cadd_commute cadd_left_commute + +lemma csucc_lt_csucc_iff: "\Card \'; Card \\ \ (csucc \' < csucc \) = (\' < \)" + by (metis Card_csucc Card_is_Ord Card_lt_csucc_iff Ord_not_less) + +lemma csucc_le_csucc_iff: "\Card \'; Card \\ \ (csucc \' \ csucc \) = (\' \ \)" + by (metis Card_csucc Card_is_Ord Card_lt_csucc_iff Ord_not_less) + +lemma Card_Un [simp,intro]: + assumes "Card(x)" "Card(y)" shows "Card(x \ y)" + by (metis Card_is_Ord Ord_linear_le assms sup.absorb2 sup.orderE) + +lemma csucc_0 [simp]: "csucc 0 = 1" + by (simp add: finite_csucc one_V_def) + +lemma InfCard_Aleph [simp, intro]: + assumes "Ord \" + shows "InfCard(Aleph \)" + unfolding InfCard_def + by (metis Aleph_0 Aleph_increasing Card_Aleph antisym_conv1 assms in_succ_iff nless_le zero_in_succ) + +corollary Aleph_csquare_eq [simp]: "Ord \ \ \\ \ \\ = \\" + using InfCard_csquare_eq by auto + +lemma small_Times_iff: "small (X \ Y) \ small X \ small Y \ X={} \ Y={}" (is "_ = ?rhs") +proof + assume *: "small (X \ Y)" + { have "small X \ small Y" if "x \ X" "y \ Y" for x y + proof - + have "X \ fst ` (X \ Y)" "Y \ snd ` (X \ Y)" + using that by auto + with that show ?thesis + by (metis * replacement smaller_than_small) + qed } + then show ?rhs + by (metis equals0I) +next + assume ?rhs + then show "small (X \ Y)" + by auto +qed + +lemma lepoll_small: + assumes "A \ B" "small B" + shows "small A" + by (meson assms lepoll_iff replacement smaller_than_small) + +lemma countable_iff_vcard_less1: "countable (elts x) \ vcard x < \1" + by (simp add: countable_iff_le_Aleph0 lt_csucc_iff one_V_def) + +lemma countable_infinite_vcard: "countable (elts x) \ infinite (elts x) \ vcard x = \0" + by (metis Aleph_0 countable_iff_le_Aleph0 dual_order.refl finite_iff_less_Aleph0 less_V_def) + +lemma vcard_set_image: "inj_on f (elts x) \ vcard (ZFC_in_HOL.set (f ` elts x)) = vcard x" + by (simp add: cardinal_cong) + + +(*The same as the library but without the type constraint*) +definition transrec :: "((V \ 'a) \ V \ 'a) \ V \ 'a" + where "transrec H a \ wfrec {(x,y). x \ elts y} H a" + +lemma transrec: "transrec H a = H (\x \ elts a. transrec H x) a" +proof - + have "(cut (wfrec {(x, y). x \ elts y} H) {(x, y). x \ elts y} a) + = (\x\elts a. wfrec {(x, y). x \ elts y} H x)" + by (force simp: cut_def) + then show ?thesis + unfolding transrec_def + by (simp add: foundation wfrec) +qed + +lemma less_succ_self: "x < succ x" + by (simp add: less_eq_V_def order_neq_le_trans subset_insertI) + +lemma subset_smaller_vcard: + assumes "\ \ vcard x" "Card \" + obtains y where "y \ x" "vcard y = \" +proof - + obtain \ where \: "bij_betw \ (elts (vcard x)) (elts x)" + using cardinal_eqpoll eqpoll_def by blast + show thesis + proof + let ?y = "ZFC_in_HOL.set (\ ` elts \)" + show "?y \ x" + by (meson \ assms bij_betwE set_image_le_iff small_elts vsubsetD) + show "vcard ?y = \" + by (metis vcard_set_image Card_def assms bij_betw_def bij_betw_subset \ less_eq_V_def) + qed +qed + +lemma vcard_sup: "vcard (x \ y) \ vcard x \ vcard y" +proof - + have "elts (x \ y) \ elts (x \ y)" + unfolding lepoll_def + proof (intro exI conjI) + let ?f = "\z. if z \ elts x then Inl z else Inr z" + show "inj_on ?f (elts (x \ y))" + by (simp add: inj_on_def) + show "?f ` elts (x \ y) \ elts (x \ y)" + by force + qed + then show ?thesis + using cadd_ac + by (metis cadd_def cardinal_cong cardinal_idem lepoll_imp_Card_le vsum_0_eqpoll) +qed + +lemma elts_cmult: "elts (\' \ \) \ elts \' \ elts \" + by (simp add: cmult_def elts_vcard_VSigma_eqpoll) + + +lemma vcard_Sup_le_cmult: + assumes "small U" and \: "\x. x \ U \ vcard x \ \" + shows "vcard (\U) \ vcard (set U) \ \" +proof - + have "\f. f \ elts x \ elts \ \ inj_on f (elts x)" if "x \ U" for x + using \ [OF that] by (metis cardinal_le_lepoll image_subset_iff_funcset lepoll_def) + then obtain \ where \: "\x. x \ U \ (\ x) \ elts x \ elts \ \ inj_on (\ x) (elts x)" + by metis + define u where "u \ \y. @x. x \ U \ y \ elts x" + have u: "u y \ U \ y \ elts (u y)" if "y \ \(elts ` U)" for y + unfolding u_def by (metis (mono_tags, lifting)that someI2_ex UN_iff) + define \ where "\ \ \y. (u y, \ (u y) y)" + have U: "elts (vcard (set U)) \ U" + by (metis \small U\ cardinal_eqpoll elts_of_set) + have "elts (\U) = \(elts ` U)" + using \small U\ by blast + also have "\ \ U \ elts \" + unfolding lepoll_def + proof (intro exI conjI) + show "inj_on \ (\ (elts ` U))" + using \ u by (smt (verit) \_def inj_on_def prod.inject) + show "\ ` \ (elts ` U) \ U \ elts \" + using \ u by (auto simp: \_def) + qed + also have "\ \ elts (vcard (set U) \ \)" + using U elts_cmult eqpoll_sym eqpoll_trans times_eqpoll_cong by blast + finally have "elts (\ U) \ elts (vcard (set U) \ \)" . + then show ?thesis + by (simp add: cmult_def lepoll_cardinal_le) +qed + +lemma csucc_le_Card_iff: "\Card \'; Card \\ \ csucc \' \ \ \ \' < \" + by (metis Card_csucc Card_is_Ord Card_lt_csucc_iff Ord_not_le) + +lemma cadd_InfCard_le: + assumes "\ \ \" "\ \ \" "InfCard \" + shows "\ \ \ \ \" + using assms by (metis InfCard_cdouble_eq cadd_le_mono) + +lemma cmult_InfCard_le: + assumes "\ \ \" "\ \ \" "InfCard \" + shows "\ \ \ \ \" + using assms + by (metis InfCard_csquare_eq cmult_le_mono) + +lemma vcard_Aleph [simp]: "Ord \ \ vcard (\\) = \\" + by (simp add: Card_cardinal_eq) + +lemma omega_le_Aleph [simp]: "Ord \ \ \ \ \\" + using InfCard_def by auto + +subsection \Making the embedding explicit\ + +definition V_of :: "'a::embeddable \ V" + where "V_of \ SOME f. inj f" + +lemma inj_V_of: "inj V_of" + unfolding V_of_def by (metis embeddable_class.ex_inj some_eq_imp) + +declare inv_f_f [OF inj_V_of, simp] + +lemma inv_V_of_image_eq [simp]: "inv V_of ` (V_of ` X) = X" + by (auto simp: image_comp) + +lemma infinite_V_of: "infinite (UNIV::'a set) \ infinite (range (V_of::'a::embeddable\V))" + using finite_imageD inj_V_of by blast + +lemma countable_V_of: "countable (range (V_of::'a::countable\V))" + by blast + +lemma elts_set_V_of: "small X \ elts (ZFC_in_HOL.set (V_of ` X)) \ X" + by (metis inj_V_of inj_eq inj_on_def inj_on_image_eqpoll_self replacement set_of_elts small_iff) + +lemma V_of_image_times: "V_of ` (X \ Y) \ (V_of ` X) \ (V_of ` Y)" +proof - + have "V_of ` (X \ Y) \ X \ Y" + by (meson inj_V_of inj_eq inj_onI inj_on_image_eqpoll_self) + also have "\ \ (V_of ` X) \ (V_of ` Y)" + by (metis eqpoll_sym inj_V_of inj_eq inj_onI inj_on_image_eqpoll_self times_eqpoll_cong) + finally show ?thesis . +qed + +subsection \The cardinality of the continuum\ + +definition "Real_set \ ZFC_in_HOL.set (range (V_of::real\V))" +definition "Complex_set \ ZFC_in_HOL.set (range (V_of::complex\V))" +definition "C_continuum \ vcard Real_set" + +lemma V_of_Real_set: "bij_betw V_of (UNIV::real set) (elts Real_set)" + by (simp add: Real_set_def bij_betw_def inj_V_of) + +lemma uncountable_Real_set: "uncountable (elts Real_set)" + using V_of_Real_set countable_iff_bij uncountable_UNIV_real by blast + +lemma "Card C_continuum" + by (simp add: C_continuum_def Card_def) + +lemma C_continuum_ge: "C_continuum \ \1" +proof - + have "\ C_continuum < \1" + proof - + have "\ vcard Real_set \ \0" + using countable_iff_le_Aleph0 uncountable_Real_set by presburger + then show ?thesis + by (simp add: C_continuum_def lt_csucc_iff one_V_def) + qed + then show ?thesis + by (simp add: C_continuum_def Ord_not_less) +qed + + +lemma V_of_Complex_set: "bij_betw V_of (UNIV::complex set) (elts Complex_set)" + by (simp add: Complex_set_def bij_betw_def inj_V_of) + +lemma uncountable_Complex_set: "uncountable (elts Complex_set)" + using V_of_Complex_set countableI_bij2 uncountable_UNIV_complex by blast + +lemma Complex_vcard: "vcard Complex_set = C_continuum" +proof - + define emb1 where "emb1 \ V_of o complex_of_real o inv V_of" + have "elts Real_set \ elts Complex_set" + proof (rule lepoll_antisym) + show "elts Real_set \ elts Complex_set" + unfolding lepoll_def + proof (intro conjI exI) + show "inj_on emb1 (elts Real_set)" + unfolding emb1_def Real_set_def + by (simp add: inj_V_of inj_compose inj_of_real inj_on_imageI) + show "emb1 ` elts Real_set \ elts Complex_set" + by (simp add: emb1_def Real_set_def Complex_set_def image_subset_iff) + qed + define emb2 where "emb2 \ (\z. (V_of (Re z), V_of (Im z))) o inv V_of" + have "elts Complex_set \ elts Real_set \ elts Real_set" + unfolding lepoll_def + proof (intro conjI exI) + show "inj_on emb2 (elts Complex_set)" + unfolding emb2_def Complex_set_def inj_on_def + by (simp add: complex.expand inj_V_of inj_eq) + show "emb2 ` elts Complex_set \ elts Real_set \ elts Real_set" + by (simp add: emb2_def Real_set_def Complex_set_def image_subset_iff) + qed + also have "\ \ elts Real_set" + by (simp add: infinite_times_eqpoll_self uncountable_Real_set uncountable_infinite) + finally show "elts Complex_set \ elts Real_set" . + qed + then show ?thesis + by (simp add: C_continuum_def cardinal_cong) +qed + +subsection \Cardinality of an arbitrary HOL set\ + +definition gcard :: "'a::embeddable set \ V" + where "gcard X \ vcard (ZFC_in_HOL.set (V_of ` X))" + +lemma gcard_big_0: "\ small X \ gcard X = 0" + by (metis elts_eq_empty_iff elts_of_set gcard_def inv_V_of_image_eq replacement vcard_0) + +lemma gcard_empty_0 [simp]: "gcard {} = 0" + by (metis gcard_def image_is_empty vcard_0 zero_V_def) + +lemma gcard_single_1 [simp]: "gcard {x} = 1" + by (simp add: gcard_def) + +lemma gcard_finite_set: "\finite X; a \ X\ \ gcard (insert a X) = succ (gcard X)" + by (simp add: gcard_def inj_V_of inj_image_mem_iff finite_csucc vcard_finite_set) + +lemma gcard_eq_card: "finite X \ gcard X = ord_of_nat (card X)" + by (induction X rule: finite_induct) (auto simp add: gcard_finite_set) + +lemma Card_gcard [iff]: "Card (gcard X)" + by (simp add: Card_def gcard_def) + +lemma gcard_eq_vcard [simp]: "gcard (elts x) = vcard x" + by (metis cardinal_cong elts_set_V_of gcard_def small_elts) + +lemma gcard_eqpoll: "small X \ elts (gcard X) \ X" + by (metis cardinal_eqpoll elts_set_V_of eqpoll_trans gcard_def) + +lemma gcard_image_le: + assumes "small A" + shows "gcard (f ` A) \ gcard A" +proof - + have "(V_of ` f ` A) \ (V_of ` A)" + by (metis image_lepoll inv_V_of_image_eq lepoll_trans) + then show ?thesis + by (simp add: assms gcard_def lepoll_imp_Card_le) +qed + +lemma gcard_image: "inj_on f A \ gcard (f ` A) = gcard A" + by (metis dual_order.antisym gcard_big_0 gcard_image_le small_image_iff the_inv_into_onto) + +lemma lepoll_imp_gcard_le: + assumes "A \ B" "small B" + shows "gcard A \ gcard B" +proof - + have "elts (ZFC_in_HOL.set (V_of ` A)) \ A" "elts (ZFC_in_HOL.set (V_of ` B)) \ B" + by (meson assms elts_set_V_of lepoll_small)+ + with \A \ B\ show ?thesis + unfolding gcard_def + by (meson lepoll_imp_Card_le eqpoll_sym lepoll_iff_leqpoll lepoll_trans) +qed + +lemma subset_imp_gcard_le: + assumes "A \ B" "small B" + shows "gcard A \ gcard B" + by (simp add: assms lepoll_imp_gcard_le subset_imp_lepoll) + +lemma gcard_le_lepoll: "\gcard A \ \; small A\ \ A \ elts \" + by (meson eqpoll_sym gcard_eqpoll lepoll_trans1 less_eq_V_def subset_imp_lepoll) + +lemma gcard_Union_le_cmult: + assumes "small U" and \: "\x. x \ U \ gcard x \ \" and sm: "\x. x \ U \ small x" + shows "gcard (\U) \ gcard U \ \" +proof - + have "\f. f \ x \ elts \ \ inj_on f x" if "x \ U" for x + using \ [OF that] gcard_le_lepoll by (smt (verit) Pi_iff TC_small imageI lepoll_def subset_eq) + then obtain \ where \: "\x. x \ U \ (\ x) \ x \ elts \ \ inj_on (\ x) x" + by metis + define u where "u \ \y. @x. x \ U \ y \ x" + have u: "u y \ U \ y \ (u y)" if "y \ \( U)" for y + unfolding u_def using that by (fast intro!: someI2) + define \ where "\ \ \y. (u y, \ (u y) y)" + have U: "elts (gcard U) \ U" + by (simp add: gcard_eqpoll) + have "\U \ U \ elts \" + unfolding lepoll_def + proof (intro exI conjI) + show "inj_on \ (\ U)" + using \ u by (smt (verit) \_def inj_on_def prod.inject) + show "\ ` \ U \ U \ elts \" + using \ u by (auto simp: \_def) + qed + also have "\ \ elts (gcard U \ \)" + using U elts_cmult eqpoll_sym eqpoll_trans times_eqpoll_cong by blast + finally have " (\U) \ elts (gcard U \ \)" . + then show ?thesis + by (metis cardinal_idem cmult_def gcard_eq_vcard lepoll_imp_gcard_le small_elts) +qed + +lemma countable_iff_g_le_Aleph0: "small X \ countable X \ gcard X \ \0" + unfolding gcard_def + by (metis countable_iff_le_Aleph0 countable_image elts_of_set inv_V_of_image_eq replacement) + +lemma countable_imp_g_le_Aleph0: "countable X \ gcard X \ \0" + by (meson countable countable_iff_g_le_Aleph0) + +lemma finite_iff_g_le_Aleph0: "small X \ finite X \ gcard X < \0" + by (metis Aleph_0 elts_set_V_of eqpoll_finite_iff finite_iff_less_Aleph0 gcard_def) + +lemma finite_imp_g_le_Aleph0: "finite X \ gcard X < \0" + by (meson finite_iff_g_le_Aleph0 finite_imp_small) + +lemma countable_infinite_gcard: "countable X \ infinite X \ gcard X = \0" +proof - + have "gcard X = \" + if "countable X" and "infinite X" + using that countable countable_imp_g_le_Aleph0 finite_iff_g_le_Aleph0 less_V_def by auto + moreover have "countable X" if "gcard X = \" + by (metis Aleph_0 countable_iff_g_le_Aleph0 dual_order.refl gcard_big_0 omega_nonzero that) + moreover have False if "gcard X = \" and "finite X" + by (metis Aleph_0 dual_order.irrefl finite_iff_g_le_Aleph0 finite_imp_small that) + ultimately show ?thesis + by auto +qed + +lemma uncountable_gcard: "small X \ uncountable X \ gcard X > \0" + by (simp add: Ord_not_le countable_iff_g_le_Aleph0 gcard_def) + +lemma uncountable_gcard_ge: "small X \ uncountable X \ gcard X \ \1" + by (simp add: uncountable_gcard csucc_le_Card_iff one_V_def) + +lemma subset_smaller_gcard: + assumes \: "\ \ gcard X" "Card \" + obtains Y where "Y \ X" "gcard Y = \" +proof (cases "small X") + case True + with subset_smaller_vcard [OF \ [unfolded gcard_def]] show ?thesis + by (metis elts_of_set gcard_def less_eq_V_def replacement set_of_elts subset_imageE that) +next + case False + with assms show ?thesis + by (metis antisym gcard_big_0 le_0 order_refl that) +qed + +lemma Real_gcard: "gcard (UNIV::real set) = C_continuum" + by (metis C_continuum_def Real_set_def gcard_def) + +lemma Complex_gcard: "gcard (UNIV::complex set) = C_continuum" + by (metis Complex_set_def Complex_vcard gcard_def) + + +lemma gcard_Times [simp]: "gcard (X \ Y) = gcard X \ gcard Y" +proof (cases "small X \ small Y") + case True + have "V_of ` (X \ Y) \ (V_of ` X) \ (V_of ` Y)" + by (metis V_of_image_times) + also have "\ \ elts (vcard (ZFC_in_HOL.set (V_of ` X))) \ elts (vcard (ZFC_in_HOL.set (V_of ` Y)))" + by (metis True cardinal_eqpoll eqpoll_sym replacement set_of_elts small_iff times_eqpoll_cong) + also have "\ \ elts (vtimes (vcard (ZFC_in_HOL.set (V_of ` X))) (vcard (ZFC_in_HOL.set (V_of ` Y))))" + using elts_VSigma by auto + finally show ?thesis + using True cardinal_cong by (simp add: gcard_def cmult_def) +next + case False + have "gcard (X \ Y) = 0" + by (metis False Times_empty gcard_big_0 gcard_empty_0 small_Times_iff) + then show ?thesis + by (metis False cmult_0 cmult_commute gcard_big_0) +qed + + +subsection \Wetzel's problem\ + +definition Wetzel :: "(complex \ complex) set \ bool" + where "Wetzel \ \F. (\f\F. f analytic_on UNIV) \ (\z. countable((\f. f z) ` F))" + +subsubsection \When the continuum hypothesis is false\ + +proposition Erdos_Wetzel_nonCH: + assumes W: "Wetzel F" and NCH: "C_continuum > \1" and "small F" + shows "countable F" +proof - + have "\z0. gcard ((\f. f z0) ` F) \ \1" if "uncountable F" + proof - + have "gcard F \ \1" + using \small F\ that uncountable_gcard_ge by blast + then obtain F' where "F' \ F" and F': "gcard F' = \1" + by (meson Card_Aleph Ord_1 subset_smaller_gcard \small F\) + then obtain \ where \: "bij_betw \ (elts (\1)) F'" + by (metis TC_small eqpoll_def gcard_eqpoll) + define S where "S \ \\ \. {z. \ \ z = \ \ z}" + have co_S: "gcard (S \ \) \ \0" if "\ \ elts \" "\ \ elts (\1)" for \ \ + proof - + have "\ \ holomorphic_on UNIV" "\ \ holomorphic_on UNIV" + using W \F' \ F\ unfolding Wetzel_def + by (meson Ord_\1 Ord_trans \ analytic_imp_holomorphic bij_betwE subsetD that)+ + moreover have "\ \ \ \ \" + by (metis Ord_\1 Ord_in_Ord Ord_trans OrdmemD \ bij_betw_imp_inj_on inj_on_def less_V_def that) + ultimately have "countable (S \ \)" + using holomorphic_countable_equal_UNIV unfolding S_def by blast + then show ?thesis + using countable_imp_g_le_Aleph0 by blast + qed + define SS where "SS \ \((\\. \((\\. S \ \) ` elts \)) ` elts(\1))" +(* "SS \ \\ \ elts(\1). \\ \ elts \. S \ \" *) + have F'_eq: "F' = \ ` elts \1" + using \ bij_betw_imp_surj_on by auto + have \

: "\x xa. xa \ elts \1 \ gcard (\\\elts xa. S \ xa) \ \" + by (metis Aleph_0 TC_small co_S countable_UN countable_iff_g_le_Aleph0 less_\1_imp_countable) + have "gcard SS \ gcard ((\\. \\\elts \. S \ \) ` elts \1) \ \0" + apply (simp add: SS_def) + by (metis (no_types, lifting) "\
" TC_small gcard_Union_le_cmult imageE) + also have "\ \ \1" + proof (rule cmult_InfCard_le) + show "gcard ((\\. \\\elts \. S \ \) ` elts \1) \ \1" + using gcard_image_le by fastforce + qed auto + finally have "gcard SS \ \1" . + with NCH obtain z0 where "z0 \ SS" + by (metis Complex_gcard UNIV_eq_I less_le_not_le) + then have "inj_on (\x. \ x z0) (elts \1)" + apply (simp add: SS_def S_def inj_on_def) + by (metis Ord_\1 Ord_in_Ord Ord_linear) + then have "gcard ((\f. f z0) ` F') = \1" + by (smt (verit) F' F'_eq gcard_image imageE inj_on_def) + then show ?thesis + by (metis TC_small \F' \ F\ image_mono subset_imp_gcard_le) + qed + with W show ?thesis + unfolding Wetzel_def by (meson countable uncountable_gcard_ge) +qed + +subsubsection \When the continuum hypothesis is true\ + +lemma Rats_closure_real2: "closure (\\\) = (UNIV::real set)\(UNIV::real set)" + by (simp add: Rats_closure_real closure_Times) + +proposition Erdos_Wetzel_CH: + assumes CH: "C_continuum = \1" + obtains F where "Wetzel F" and "uncountable F" +proof - + define D where "D \ {z. Re z \ \ \ Im z \ \}" + have Deq: "D = (\x\\. \y\\. {Complex x y})" + using complex.collapse by (force simp: D_def) + with countable_rat have "countable D" + by blast + have "infinite D" + unfolding Deq + by (intro infinite_disjoint_family_imp_infinite_UNION Rats_infinite) (auto simp: disjoint_family_on_def) + have "\w. Re w \ \ \ Im w \ \ \ norm (w - z) < e" if "e > 0" for z and e::real + proof - + obtain x y where "x\\" "y\\" and xy: "dist (x,y) (Re z, Im z) < e" + using \e > 0\ Rats_closure_real2 by (force simp: closure_approachable) + moreover have "dist (x,y) (Re z, Im z) = norm (Complex x y - z)" + by (simp add: norm_complex_def norm_prod_def dist_norm) + ultimately show "\w. Re w \ \ \ Im w \ \ \ norm (w - z) < e" + by (metis complex.sel) + qed + then have cloD: "closure D = UNIV" + by (auto simp: D_def closure_approachable dist_complex_def) + obtain \ where \: "bij_betw \ (elts (\1)) (UNIV::complex set)" + by (metis Complex_gcard TC_small assms eqpoll_def gcard_eqpoll) + define inD where "inD \ \\ f. (\\ \ elts \. f (\ \) \ D)" + define \ where "\ \ \\ f. f \ analytic_on UNIV \ inD \ (f \) \ inj_on f (elts (succ \))" + have *: "\h. \ \ ((restrict f (elts \))(\:=h))" + if \: "\ \ elts (\1)" and "\\ \ elts \. \ \ f" for \ f + proof - + have f: "\\ \ elts \. f \ analytic_on UNIV \ inD \ (f \)" + using that by (auto simp: \_def) + have inj: "inj_on f (elts \)" + using that by (simp add: \_def inj_on_def) (meson Ord_\1 Ord_in_Ord Ord_linear) + obtain h where "h analytic_on UNIV" "inD \ h" "(\\ \ elts \. h \ f \)" + proof (cases "finite (elts \)") + case True + then obtain \ where \: "bij_betw \ {..)} (elts \)" + using bij_betw_from_nat_into_finite by blast + define g where "g \ f o \" + define w where "w \ \ o \" + have gf: "\i). h \ g i \ \\\elts \. h \ f \" for h + using \ by (auto simp: bij_betw_iff_bijections g_def) + have *: "\h. h analytic_on UNIV \ (\i D \ h (w i) \ g i (w i))" + if "n \ card (elts \)" for n + using that + proof (induction n) + case 0 + then show ?case + using analytic_on_const by blast + next + case (Suc n) + then obtain h where "h analytic_on UNIV" and hg: "\i D \ h (w i) \ g i (w i)" + using Suc_leD by blast + define p where "p \ \z. \i (\i D - {g n (w n)}" + using \infinite D\ by (metis ex_in_conv finite.emptyI infinite_remove) + define h' where "h' \ \z. h z + p z * (d - h (w n)) / p (w n)" + have h'_eq: "h' (w i) = h (w i)" if "i)" + using Suc.prems Suc_le_eq by blast + with \ have "\ n \ \ i" if "i \ \ have pwn_nonzero: "p (w n) \ 0" + apply (clarsimp simp: p0 w_def bij_betw_iff_bijections) + by (metis Ord_\1 Ord_trans nless lessThan_iff order_less_trans) + then show "h' analytic_on UNIV" + unfolding h'_def p_def by (intro analytic_intros \h analytic_on UNIV\) + fix i + assume "i < Suc n" + then have \
: "i < n \ i = n" + by linarith + then show "h' (w i) \ D" + using h'_eq hg d h'_def pwn_nonzero by force + show "h' (w i) \ g i (w i)" + using \
h'_eq hg h'_def d pwn_nonzero by fastforce + qed + qed + show ?thesis + using * [OF order_refl] \ that gf + by (simp add: w_def bij_betw_iff_bijections inD_def) metis + next + case False + then obtain \ where \: "bij_betw \ (UNIV::nat set) (elts \)" + by (meson \ countable_infiniteE' less_\1_imp_countable) + then have \_inject [simp]: "\ i = \ j \ i=j" for i j + by (simp add: bij_betw_imp_inj_on inj_eq) + define g where "g \ f o \" + define w where "w \ \ o \" + then have w_inject [simp]: "w i = w j \ i=j" for i j + by (smt (verit) Ord_\1 Ord_trans UNIV_I \ \ \ bij_betw_iff_bijections comp_apply) + define p where "p \ \n z. \i \n. \i \n \ z. \i i * p i z" + define BALL where "BALL \ \n \. ball (h n \ (w n)) (norm (p n (w n)) / (fact n * q n))" + \ \The demonimator above is the key to keeping the epsilons small\ + define DD where "DD \ \n \. D \ BALL n \ - {g n (w n)}" + define dd where "dd \ \n \. SOME x. x \ DD n \" + have p0: "p n z = 0 \ (\i \ {}" for n \ + proof - + have "r > 0 \ infinite (D \ ball z r)" for z r + by (metis islimpt_UNIV limpt_of_closure islimpt_eq_infinite_ball cloD) + then have "infinite (D \ BALL n \)" for n \ + by (simp add: BALL_def p0 q_gt0) + then show ?thesis + by (metis DD_def finite.emptyI infinite_remove) + qed + then have dd_in_DD: "dd n \ \ DD n \" for n \ + by (simp add: dd_def some_in_eq) + + have h_cong: "h n \ = h n \'" if "\i. i \ i = \' i" for n \ \' + using that by (simp add: h_def) + have dd_cong: "dd n \ = dd n \'" if "\i. i \ i = \' i" for n \ \' + using that by (metis dd_def DD_def BALL_def h_cong) + + have [simp]: "h n (cut \ less_than n) = h n \" for n \ + by (meson cut_apply h_cong less_than_iff) + have [simp]: "dd n (cut \ less_than n) = dd n \" for n \ + by (meson cut_apply dd_cong less_than_iff) + + define coeff where "coeff \ wfrec less_than (\\ n. (dd n \ - h n \ (w n)) / p n (w n))" + have coeff_eq: "coeff n = (dd n coeff - h n coeff (w n)) / p n (w n)" for n + by (simp add: def_wfrec [OF coeff_def]) + + have norm_coeff: "norm (coeff n) < 1 / (fact n * q n)" for n + using dd_in_DD [of n coeff] + by (simp add: q_gt0 coeff_eq DD_def BALL_def dist_norm norm_minus_commute norm_divide divide_simps) + have h_truncated: "h n coeff (w k) = h (Suc k) coeff (w k)" if "k < n" for n k + proof - + have "(\iii=Suc k.. = (\i q n * (1 + norm z) ^ n" + if "dist z z' \ 1" for n z z' + proof (induction n ) + case 0 + then show ?case + by (auto simp: p_def q_def) + next + case (Suc n) + have "norm z' - norm z \ 1" + by (smt (verit) dist_norm norm_triangle_ineq3 that) + then have \
: "norm (z' - w n) \ (1 + norm (w n)) * (1 + norm z)" + by (simp add: mult.commute add_mono distrib_left norm_triangle_le_diff) + have "norm (p n z') * norm (z' - w n) \ (q n * (1 + norm z) ^ n) * norm (z' - w n)" + by (metis Suc mult.commute mult_left_mono norm_ge_zero) + also have "\ \ (q n * (1 + norm z) ^ n) * (1 + norm (w n)) * ((1 + norm z))" + by (smt (verit) "\
" Suc mult.assoc mult_left_mono norm_ge_zero) + also have "\ \ q n * (1 + norm (w n)) * ((1 + norm z) * (1 + norm z) ^ n)" + by (simp add: mult_ac) + finally have "norm (p n z') * norm (z' - w n) \ q n * (1 + norm (w n)) * ((1 + norm z) * (1 + norm z) ^ n)" . + with that show ?case + by (auto simp: p_def q_def norm_mult simp del: fact_Suc) + qed + + show ?thesis + proof + define hh where "hh \ \z. suminf (\i. coeff i * p i z)" + have "hh holomorphic_on UNIV" + proof (rule holomorphic_uniform_sequence) + fix n \\Many thanks to Manuel Eberl for suggesting these approach\ + show "h n coeff holomorphic_on UNIV" + unfolding h_def p_def by (intro holomorphic_intros) + next + fix z + have "uniform_limit (cball z 1) (\n. h n coeff) hh sequentially" + unfolding hh_def h_def + proof (rule Weierstrass_m_test) + let ?M = "\n. (1 + norm z) ^ n / fact n" + have "\N. \n\N. B \ (1 + real n) / (1 + norm z)" for B + proof + show "\n\nat \B * (1 + norm z)\. B \ (1 + real n) / (1 + norm z)" + using norm_ge_zero [of z] by (auto simp: divide_simps simp del: norm_ge_zero) + qed + then have L: "liminf (\n. ereal ((1 + real n) / (1 + norm z))) = \" + by (simp add: Lim_PInfty flip: liminf_PInfty) + have "\\<^sub>F n in sequentially. 0 < (1 + cmod z) ^ n / fact n" + using norm_ge_zero [of z] by (simp del: norm_ge_zero) + then show "summable ?M" + by (rule ratio_test_convergence) (auto simp: add_nonneg_eq_0_iff L) + fix n z' + assume "z' \ cball z 1" + then have "norm (coeff n * p n z') \ norm (coeff n) * q n * (1 + norm z) ^ n" + by (metis norm_p_bound norm_mult mem_cball mult.assoc mult_left_mono norm_ge_zero) + also have "\ \ (1 / fact n) * (1 + norm z) ^ n" + proof (rule mult_right_mono) + show "norm (coeff n) * q n \ 1 / fact n" + by (metis divide_divide_eq_left less_divide_eq less_eq_real_def norm_coeff q_gt0) + qed auto + also have "\ \ ?M n" + by (simp add: divide_simps) + finally show "norm (coeff n * p n z') \ ?M n" . + qed + then show "\d>0. cball z d \ UNIV \ uniform_limit (cball z d) (\n. h n coeff) hh sequentially" + using zero_less_one by blast + qed auto + then show "hh analytic_on UNIV" + by (simp add: analytic_on_open) + have hh_eq_dd: "hh (w n) = dd n coeff" for n + proof - + have "hh (w n) = h (Suc n) coeff (w n)" + unfolding hh_def h_def by (intro suminf_finite) auto + also have "\ = dd n coeff" + by (induction n) (auto simp add: p0 h_def p_def coeff_eq [of "Suc _"] coeff_eq [of 0]) + finally show ?thesis . + qed + then have "hh (w n) \ D" for n + using DD_def dd_in_DD by fastforce + then show "inD \ hh" + unfolding inD_def by (metis \ bij_betw_iff_bijections comp_apply w_def) + have "hh (w n) \ f (\ n) (w n)" for n + using DD_def dd_in_DD g_def hh_eq_dd by auto + then show "\\\elts \. hh \ f \" + by (metis \ bij_betw_imp_surj_on imageE) + qed + qed + with f show ?thesis + using inj by (rule_tac x="h" in exI) (auto simp: \_def inj_on_def) + qed + define G where "G \ \f \. @h. \ \ ((restrict f (elts \))(\:=h))" + have nxt: "\ \ ((restrict f (elts \))(\:= G f \))" + if "\ \ elts (\1)" "\\ \ elts \. \ \ f" for f \ + unfolding G_def using * [OF that] by (metis someI) + have G_restr: "G (restrict f (elts \)) \ = G f \" if "\ \ elts (\1)" for f \ + by (auto simp: G_def) + define f where "f \ transrec G" + have \f: "\ \ f" if "\ \ elts (\1)" for \ + using that + proof (induction \ rule: eps_induct) + case (step \) + then have *: "\\\elts \. \ \ f" + using Ord_\1 Ord_trans by blast + have [simp]: "inj_on (\\. G (restrict f (elts \)) \) (elts \) \ inj_on f (elts \)" + by (metis (no_types, lifting) f_def transrec inj_on_cong) + have "f \ = G f \" + by (metis G_restr transrec f_def step.prems) + with nxt [OF step.prems] * show ?case + by (metis \_def elts_succ fun_upd_same fun_upd_triv inj_on_restrict_eq restrict_upd) + qed + then have anf: "\\. \ \ elts (\1) \ f \ analytic_on UNIV" + and inD: "\\ \. \\ \ elts (\1); \ \ elts \\ \ f \ (\ \) \ D" + using \_def inD_def by blast+ + have injf: "inj_on f (elts (\1))" + using \f unfolding inj_on_def \_def by (metis Ord_\1 Ord_in_Ord Ord_linear_le in_succ_iff) + show ?thesis + proof + let ?F = "f ` elts (\1)" + have "countable ((\f. f z) ` f ` elts \1)" for z + proof - + obtain \ where \: "\ \ = z" "\ \ elts (\1)" "Ord \" + by (meson Ord_\1 Ord_in_Ord UNIV_I \ bij_betw_iff_bijections) + let ?B = "elts \1 - elts (succ \)" + have eq: "elts \1 = elts (succ \) \ ?B" + using \ by (metis Diff_partition Ord_\1 OrdmemD less_eq_V_def succ_le_iff) + have "(\f. f z) ` f ` ?B \ D" + using \ inD by clarsimp (meson Ord_\1 Ord_in_Ord Ord_linear) + then have "countable ((\f. f z) ` f ` ?B)" + by (meson \countable D\ countable_subset) + moreover have "countable ((\f. f z) ` f ` elts (succ \))" + by (simp add: \ less_\1_imp_countable) + ultimately show ?thesis + using eq by (metis countable_Un_iff image_Un) + qed + then show "Wetzel ?F" + unfolding Wetzel_def by (blast intro: anf) + show "uncountable ?F" + using Ord_\1 countable_iff_less_\1 countable_image_inj_eq injf by blast + qed +qed + +theorem Erdos_Wetzel: "C_continuum = \1 \ (\F. Wetzel F \ uncountable F)" + by (metis C_continuum_ge Erdos_Wetzel_CH Erdos_Wetzel_nonCH TC_small less_V_def) + +end diff --git a/thys/Wetzels_Problem/document/root.bib b/thys/Wetzels_Problem/document/root.bib new file mode 100644 --- /dev/null +++ b/thys/Wetzels_Problem/document/root.bib @@ -0,0 +1,35 @@ +%% This BibTeX bibliography file was created using BibDesk. +%% http://bibdesk.sourceforge.net/ + + +%% Created for Larry Paulson at 2022-01-28 15:00:12 +0000 + + +%% Saved with string encoding Unicode (UTF-8) + + + +@article{cunningham-youngs, + author = {F. Cunningham and Nathaniel Grossman}, + date-added = {2022-01-28 14:56:42 +0000}, + date-modified = {2022-01-28 15:00:12 +0000}, + issn = {00029890, 19300972}, + journal = {The American Mathematical Monthly}, + number = {7}, + pages = {781-783}, + publisher = {Mathematical Association of America}, + title = {On {Young's} Inequality}, + url = {http://www.jstor.org/stable/2318018}, + volume = {78}, + year = {1971}, + bdsk-url-1 = {http://www.jstor.org/stable/2318018}} + +@book{aigner-proofs, + author = {M. Aigner and G. M. Ziegler}, + booktitle = {Proofs from THE BOOK}, + date-added = {2022-01-06 11:42:58 +0000}, + date-modified = {2022-01-06 13:07:25 +0000}, + edition = {6th}, + publisher = {Springer}, + title = {Proofs from THE BOOK}, + year = {2018}} diff --git a/thys/Wetzels_Problem/document/root.tex b/thys/Wetzels_Problem/document/root.tex new file mode 100644 --- /dev/null +++ b/thys/Wetzels_Problem/document/root.tex @@ -0,0 +1,51 @@ +\documentclass[11pt,a4paper]{article} +\usepackage[T1]{fontenc} +\usepackage{isabelle,isabellesym} +\usepackage{amssymb} +\usepackage{stmaryrd} + +% 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{Wetzel's Problem and the Continuum Hypothesis} +\author{Lawrence C. Paulson} +\maketitle + +\begin{abstract} +Let $F$ be a set of analytic functions on the complex plane such that, +for each $z\in\mathbb{C}$, the set $\{f(z) \mid f\in F\}$ is countable; +must then $F$ itself be countable? +The answer is yes if the Continuum Hypothesis is false, i.e., +if the cardinality of $\mathbb{R}$ exceeds $\aleph_1$. +But if CH is true then such an $F$, of cardinality $\aleph_1$, +can be constructed by transfinite recursion. + +The formal proof illustrates reasoning about complex +analysis (analytic and homomorphic functions) and set theory +(transfinite cardinalities) in a single setting. +The mathematical text comes from \emph{Proofs from THE BOOK}~\cite[pp.\thinspace137--8]{aigner-proofs}, by Aigner and Ziegler. +\end{abstract} + +\newpage +\tableofcontents + +\paragraph*{Acknowledgements} +The author was supported by the ERC Advanced Grant ALEXANDRIA (Project 742178) funded by the European Research Council. +Thanks also to Manuel Eberl for advice on proving a function to be holomorphic. + +\newpage + +% include generated text of all theories +\input{session} + +\bibliographystyle{abbrv} +\bibliography{root} + +\end{document} diff --git a/web/entries/Containers.html b/web/entries/Containers.html --- a/web/entries/Containers.html +++ b/web/entries/Containers.html @@ -1,268 +1,268 @@ Light-weight Containers - Archive of Formal Proofs

 

 

 

 

 

 

Light-weight Containers

 

- +
Title: Light-weight Containers
Author: Andreas Lochbihler
Contributor: René Thiemann (rene /dot/ thiemann /at/ uibk /dot/ ac /dot/ at)
Submission date: 2013-04-15
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.

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)
BibTeX:
@article{Containers-AFP,
   author  = {Andreas Lochbihler},
   title   = {Light-weight Containers},
   journal = {Archive of Formal Proofs},
   month   = apr,
   year    = 2013,
   note    = {\url{https://isa-afp.org/entries/Containers.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: Automatic_Refinement, Collections, Deriving, Finger-Trees, Regular-Sets
Used by:AI_Planning_Languages_Semantics, MFOTL_Monitor, Polynomial_Factorization
AI_Planning_Languages_Semantics, Eval_FO, MFOTL_Monitor, Polynomial_Factorization, VYDRA_MDL

\ No newline at end of file diff --git a/web/entries/Eval_FO.html b/web/entries/Eval_FO.html new file mode 100644 --- /dev/null +++ b/web/entries/Eval_FO.html @@ -0,0 +1,220 @@ + + + + +First-Order Query Evaluation - Archive of Formal Proofs + + + + + + + + + + + + + + + + + + + + + + + + +
+

 

+ + + +

 

+

 

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

 

+

 

+
+
+

 

+

First-Order + + Query + + Evaluation + +

+

 

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Title:First-Order Query Evaluation
+ Author: + + Martin Raszyk (martin /dot/ raszyk /at/ inf /dot/ ethz /dot/ ch) +
Submission date:2022-02-15
Abstract: +We formalize first-order query evaluation over an infinite domain with +equality. We first define the syntax and semantics of first-order +logic with equality. Next we define a locale +eval_fo abstracting a representation of +a potentially infinite set of tuples satisfying a first-order query +over finite relations. Inside the locale, we define a function +eval checking if the set of tuples satisfying a +first-order query over a database (an interpretation of the +query's predicates) is finite (i.e., deciding relative +safety) and computing the set of satisfying tuples if it is +finite. Altogether the function eval solves +capturability (Avron and Hirshfeld, 1991) of +first-order logic with equality. We also use the function +eval to prove a code equation for the semantics of +first-order logic, i.e., the function checking if a first-order query +over a database is satisfied by a variable assignment.
We provide an +interpretation of the locale eval_fo +based on the approach by Ailamazyan et al. A core notion in the +interpretation is the active domain of a query and a database that +contains all domain elements that occur in the database or interpret +the query's constants. We prove the main theorem of Ailamazyan et +al. relating the satisfaction of a first-order query over an infinite +domain to the satisfaction of this query over a finite domain +consisting of the active domain and a few additional domain elements +(outside the active domain) whose number only depends on the query. In +our interpretation of the locale +eval_fo, we use a potentially higher +number of the additional domain elements, but their number still only +depends on the query and thus has no effect on the data complexity +(Vardi, 1982) of query evaluation. Our interpretation yields an +executable function eval. The +time complexity of eval on a query is linear in the +total number of tuples in the intermediate relations for the +subqueries. Specifically, we build a database index to evaluate a +conjunction. We also optimize the case of a negated subquery in a +conjunction. Finally, we export code for the infinite domain of +natural numbers.
BibTeX: +
@article{Eval_FO-AFP,
+  author  = {Martin Raszyk},
+  title   = {First-Order Query Evaluation},
+  journal = {Archive of Formal Proofs},
+  month   = feb,
+  year    = 2022,
+  note    = {\url{https://isa-afp.org/entries/Eval_FO.html},
+            Formal proof development},
+  ISSN    = {2150-914x},
+}
+
License:BSD License
Depends on:Containers
+ +

+ + + + + + + + + + + + + + + + + + +
+
+ + + + + + \ No newline at end of file diff --git a/web/entries/Fourier.html b/web/entries/Fourier.html --- a/web/entries/Fourier.html +++ b/web/entries/Fourier.html @@ -1,202 +1,202 @@ Fourier Series - Archive of Formal Proofs

 

 

 

 

 

 

Fourier Series

 

Title: Fourier Series
Author: - Lawrence C Paulson + Lawrence C Paulson
Submission date: 2019-09-06
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
BibTeX:
@article{Fourier-AFP,
   author  = {Lawrence C Paulson},
   title   = {Fourier Series},
   journal = {Archive of Formal Proofs},
   month   = sep,
   year    = 2019,
   note    = {\url{https://isa-afp.org/entries/Fourier.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: Lp

\ No newline at end of file diff --git a/web/entries/Interpolation_Polynomials_HOL_Algebra.html b/web/entries/Interpolation_Polynomials_HOL_Algebra.html --- a/web/entries/Interpolation_Polynomials_HOL_Algebra.html +++ b/web/entries/Interpolation_Polynomials_HOL_Algebra.html @@ -1,202 +1,204 @@ Interpolation Polynomials (in HOL-Algebra) - Archive of Formal Proofs

 

 

 

 

 

 

Interpolation Polynomials (in HOL-Algebra)

 

- + + +
Title: Interpolation Polynomials (in HOL-Algebra)
Author: Emin Karayel
Submission date: 2022-01-29
Abstract:

A well known result from algebra is that, on any field, there is exactly one polynomial of degree less than n interpolating n points [1, §7].

This entry contains a formalization of the above result, as well as the following generalization in the case of finite fields F: There are |F|m-n polynomials of degree less than m ≥ n interpolating the same n points, where |F| denotes the size of the domain of the field. To establish the result the entry also includes a formalization of Lagrange interpolation, which might be of independent interest.

The formalized results are defined on the algebraic structures from HOL-Algebra, which are distinct from the type-class based structures defined in HOL. Note that there is an existing formalization for polynomial interpolation and, in particular, Lagrange interpolation by Thiemann and Yamada [2] on the type-class based structures in HOL.

BibTeX:
@article{Interpolation_Polynomials_HOL_Algebra-AFP,
   author  = {Emin Karayel},
   title   = {Interpolation Polynomials (in HOL-Algebra)},
   journal = {Archive of Formal Proofs},
   month   = jan,
   year    = 2022,
   note    = {\url{https://isa-afp.org/entries/Interpolation_Polynomials_HOL_Algebra.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Used by:Universal_Hash_Families

\ No newline at end of file diff --git a/web/entries/Irrationals_From_THEBOOK.html b/web/entries/Irrationals_From_THEBOOK.html --- a/web/entries/Irrationals_From_THEBOOK.html +++ b/web/entries/Irrationals_From_THEBOOK.html @@ -1,197 +1,197 @@ Irrational numbers from THE BOOK - Archive of Formal Proofs

 

 

 

 

 

 

Irrational numbers from THE BOOK

 

Title: Irrational numbers from THE BOOK
Author: - Lawrence C Paulson + Lawrence C Paulson
Submission date: 2022-01-08
Abstract: An elementary proof is formalised: that exp r is irrational for every nonzero rational number r. The mathematical development comes from the well-known volume Proofs from THE BOOK, by Aigner and Ziegler, who credit the idea to Hermite. The development illustrates a number of basic Isabelle techniques: the manipulation of summations, the calculation of quite complicated derivatives and the estimation of integrals. We also see how to import another AFP entry (Stirling's formula). As for the theorem itself, note that a much stronger and more general result (the Hermite--Lindemann--Weierstraß transcendence theorem) is already available in the AFP.
BibTeX:
@article{Irrationals_From_THEBOOK-AFP,
   author  = {Lawrence C Paulson},
   title   = {Irrational numbers from THE BOOK},
   journal = {Archive of Formal Proofs},
   month   = jan,
   year    = 2022,
   note    = {\url{https://isa-afp.org/entries/Irrationals_From_THEBOOK.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: Stirling_Formula

\ No newline at end of file diff --git a/web/entries/Universal_Hash_Families.html b/web/entries/Universal_Hash_Families.html new file mode 100644 --- /dev/null +++ b/web/entries/Universal_Hash_Families.html @@ -0,0 +1,197 @@ + + + + +Universal Hash Families - Archive of Formal Proofs + + + + + + + + + + + + + + + + + + + + + + + + +
+

 

+ + + +

 

+

 

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

 

+

 

+
+
+

 

+

Universal + + Hash + + Families + +

+

 

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Title:Universal Hash Families
+ Author: + + Emin Karayel +
Submission date:2022-02-20
Abstract: +A k-universal hash family is a probability +space of functions, which have uniform distribution and form +k-wise independent random variables. They can often be used +in place of classic (or cryptographic) hash functions and allow the +rigorous analysis of the performance of randomized algorithms and +data structures that rely on hash functions. In 1981 +Wegman and Carter +introduced a generic construction for such families with arbitrary +k using polynomials over a finite field. This entry +contains a formalization of them and establishes the property of +k-universality. To be useful the formalization also provides +an explicit construction of finite fields using the factor ring of +integers modulo a prime. Additionally, some generic results about +independent families are shown that might be of independent interest.
BibTeX: +
@article{Universal_Hash_Families-AFP,
+  author  = {Emin Karayel},
+  title   = {Universal Hash Families},
+  journal = {Archive of Formal Proofs},
+  month   = feb,
+  year    = 2022,
+  note    = {\url{https://isa-afp.org/entries/Universal_Hash_Families.html},
+            Formal proof development},
+  ISSN    = {2150-914x},
+}
+
License:BSD License
Depends on:Interpolation_Polynomials_HOL_Algebra
+ +

+ + + + + + + + + + + + + + + + + + +
+
+ + + + + + \ No newline at end of file diff --git a/web/entries/VYDRA_MDL.html b/web/entries/VYDRA_MDL.html new file mode 100644 --- /dev/null +++ b/web/entries/VYDRA_MDL.html @@ -0,0 +1,214 @@ + + + + +Multi-Head Monitoring of Metric Dynamic Logic - Archive of Formal Proofs + + + + + + + + + + + + + + + + + + + + + + + + +
+

 

+ + + +

 

+

 

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

 

+

 

+
+
+

 

+

Multi-Head + + Monitoring + + of + + Metric + + Dynamic + + Logic + +

+

 

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Title:Multi-Head Monitoring of Metric Dynamic Logic
+ Author: + + Martin Raszyk (martin /dot/ raszyk /at/ inf /dot/ ethz /dot/ ch) +
Submission date:2022-02-13
Abstract: +Runtime monitoring (or runtime verification) is an approach to +checking compliance of a system's execution with a specification +(e.g., a temporal query). The system's execution is logged into a +trace---a sequence of time-points, each consisting of a time-stamp and +observed events. A monitor is an algorithm that produces verdicts on +the satisfaction of a temporal query on a trace. We formalize a +monitoring algorithm for metric dynamic logic, an extension of metric +temporal logic with regular expressions. The monitor computes whether +a given query is satisfied at every position in an input trace of +time-stamped events. We formalize the time-stamps as an abstract +algebraic structure satisfying certain assumptions. Instances of this +structure include natural numbers, real numbers, and lexicographic +combinations of them. Our monitor follows the multi-head paradigm: it +reads the input simultaneously at multiple positions and moves its +reading heads asynchronously. This mode of operation results in +unprecedented time and space complexity guarantees for metric dynamic +logic: The monitor's amortized time complexity to process a +time-point and the monitor's space complexity neither depends on +the event-rate, i.e., the number of events within a fixed time-unit, +nor on the numeric constants occurring in the quantitative temporal +constraints in the given query. The multi-head monitoring algorithm +for metric dynamic logic is reported in our paper "Multi-Head +Monitoring of Metric Dynamic Logic" published at ATVA 2020. We +have also formalized unpublished specialized algorithms for the +temporal operators of metric temporal logic.
BibTeX: +
@article{VYDRA_MDL-AFP,
+  author  = {Martin Raszyk},
+  title   = {Multi-Head Monitoring of Metric Dynamic Logic},
+  journal = {Archive of Formal Proofs},
+  month   = feb,
+  year    = 2022,
+  note    = {\url{https://isa-afp.org/entries/VYDRA_MDL.html},
+            Formal proof development},
+  ISSN    = {2150-914x},
+}
+
License:BSD License
Depends on:Containers
+ +

+ + + + + + + + + + + + + + + + + + +
+
+ + + + + + \ No newline at end of file diff --git a/web/entries/Wetzels_Problem.html b/web/entries/Wetzels_Problem.html new file mode 100644 --- /dev/null +++ b/web/entries/Wetzels_Problem.html @@ -0,0 +1,200 @@ + + + + +Wetzel's Problem and the Continuum Hypothesis - Archive of Formal Proofs + + + + + + + + + + + + + + + + + + + + + + + + +
+

 

+ + + +

 

+

 

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

 

+

 

+
+
+

 

+

Wetzel's + + Problem + + and + + the + + Continuum + + Hypothesis + +

+

 

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Title:Wetzel's Problem and the Continuum Hypothesis
+ Author: + + Lawrence C Paulson +
Submission date:2022-02-18
Abstract: +Let $F$ be a set of analytic functions on the complex plane such that, +for each $z\in\mathbb{C}$, the set $\{f(z) \mid f\in F\}$ is +countable; must then $F$ itself be countable? The answer is yes if the +Continuum Hypothesis is false, i.e., if the cardinality of +$\mathbb{R}$ exceeds $\aleph_1$. But if CH is true then such an $F$, +of cardinality $\aleph_1$, can be constructed by transfinite +recursion. The formal proof illustrates reasoning about complex +analysis (analytic and homomorphic functions) and set theory +(transfinite cardinalities) in a single setting. The mathematical text +comes from Proofs from THE BOOK by Aigner and +Ziegler.
BibTeX: +
@article{Wetzels_Problem-AFP,
+  author  = {Lawrence C Paulson},
+  title   = {Wetzel's Problem and the Continuum Hypothesis},
+  journal = {Archive of Formal Proofs},
+  month   = feb,
+  year    = 2022,
+  note    = {\url{https://isa-afp.org/entries/Wetzels_Problem.html},
+            Formal proof development},
+  ISSN    = {2150-914x},
+}
+
License:BSD License
Depends on:ZFC_in_HOL
+ +

+ + + + + + + + + + + + + + + + + + +
+
+ + + + + + \ No newline at end of file diff --git a/web/entries/Youngs_Inequality.html b/web/entries/Youngs_Inequality.html --- a/web/entries/Youngs_Inequality.html +++ b/web/entries/Youngs_Inequality.html @@ -1,194 +1,194 @@ Young's Inequality for Increasing Functions - Archive of Formal Proofs

 

 

 

 

 

 

Young's Inequality for Increasing Functions

 

Title: Young's Inequality for Increasing Functions
Author: - Lawrence C Paulson + Lawrence C Paulson
Submission date: 2022-01-31
Abstract: Young's inequality states that $$ ab \leq \int_0^a f(x)dx + \int_0^b f^{-1}(y) dy $$ where $a\geq 0$, $b\geq 0$ and $f$ is strictly increasing and continuous. Its proof is formalised following the development by Cunningham and Grossman. Their idea is to make the intuitive, geometric folklore proof rigorous by reasoning about step functions. The lack of the Riemann integral makes the development longer than one would like, but their argument is reproduced faithfully.
BibTeX:
@article{Youngs_Inequality-AFP,
   author  = {Lawrence C Paulson},
   title   = {Young's Inequality for Increasing Functions},
   journal = {Archive of Formal Proofs},
   month   = jan,
   year    = 2022,
   note    = {\url{https://isa-afp.org/entries/Youngs_Inequality.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License

\ No newline at end of file diff --git a/web/entries/ZFC_in_HOL.html b/web/entries/ZFC_in_HOL.html --- a/web/entries/ZFC_in_HOL.html +++ b/web/entries/ZFC_in_HOL.html @@ -1,233 +1,233 @@ Zermelo Fraenkel Set Theory in Higher-Order Logic - Archive of Formal Proofs

 

 

 

 

 

 

Zermelo Fraenkel Set Theory in Higher-Order Logic

 

- +
Title: Zermelo Fraenkel Set Theory in Higher-Order Logic
Author: Lawrence C. Paulson
Submission date: 2019-10-24
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)
BibTeX:
@article{ZFC_in_HOL-AFP,
   author  = {Lawrence C. Paulson},
   title   = {Zermelo Fraenkel Set Theory in Higher-Order Logic},
   journal = {Archive of Formal Proofs},
   month   = oct,
   year    = 2019,
   note    = {\url{https://isa-afp.org/entries/ZFC_in_HOL.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Used by:CZH_Foundations, Ordinal_Partitions
CZH_Foundations, Ordinal_Partitions, Wetzels_Problem

\ 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,6049 +1,6081 @@ 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.

 

 

+ + + + + + + + + + + +
2022
+ 2022-02-20: Universal Hash Families +
+ Author: + Emin Karayel +
+ 2022-02-18: Wetzel's Problem and the Continuum Hypothesis +
+ Author: + Lawrence C Paulson +
+ 2022-02-15: First-Order Query Evaluation +
+ Author: + Martin Raszyk +
+ 2022-02-13: Multi-Head Monitoring of Metric Dynamic Logic +
+ Author: + Martin Raszyk +
2022-02-04: Enumeration of Equivalence Relations
Author: Emin Karayel
2022-02-03: Quasi-Borel Spaces
Authors: Michikazu Hirata, Yasuhiko Minamide and Tetsuya Sato
2022-02-03: Duality of Linear Programming
Author: René Thiemann
2022-02-02: First-Order Theory of Rewriting
Authors: Alexander Lochmann and Bertram Felgenhauer
2022-01-31: Young's Inequality for Increasing Functions
Author: - Lawrence C Paulson + Lawrence C Paulson
2022-01-31: A Sequent Calculus Prover for First-Order Logic with Functions
Authors: Asta Halkjær From and Frederik Krogsdal Jacobsen
2022-01-29: Interpolation Polynomials (in HOL-Algebra)
Author: Emin Karayel
2022-01-25: Median Method
Author: Emin Karayel
2022-01-23: Actuarial Mathematics
Author: Yosuke Ito
2022-01-08: Irrational numbers from THE BOOK
Author: - Lawrence C Paulson + Lawrence C Paulson
2022-01-04: Knight's Tour Revisited Revisited
Author: Lukas Koller

 

2021
2021-12-31: Hyperdual Numbers and Forward Differentiation
Authors: Filip Smola and Jacques Fleuriot
2021-12-29: Gale-Shapley Algorithm
Author: Tobias Nipkow
2021-12-28: Roth's Theorem on Arithmetic Progressions
Authors: Chelsea Edmonds, Angeliki Koutsoukou-Argyraki and Lawrence C. Paulson
2021-12-16: Markov Decision Processes with Rewards
Authors: Maximilian Schäffeler and Mohammad Abdulaziz
2021-12-16: Verified Algorithms for Solving Markov Decision Processes
Authors: Maximilian Schäffeler and Mohammad Abdulaziz
2021-12-15: Regular Tree Relations
Authors: Alexander Lochmann, Bertram Felgenhauer, Christian Sternagel, René Thiemann and Thomas Sternagel
2021-11-29: Simplicial Complexes and Boolean functions
Authors: Jesús Aransay, Alejandro del Campo and Julius Michaelis
2021-11-23: van Emde Boas Trees
Authors: Thomas Ammer and Peter Lammich
2021-11-22: Foundation of geometry in planes, and some complements: Excluding the parallel axioms
Author: Fumiya Iwama
2021-11-19: The Hahn and Jordan Decomposition Theorems
Authors: Marie Cousin, Mnacho Echenim and Hervé Guiol
2021-11-08: Exploring Simplified Variants of Gödel’s Ontological Argument in Isabelle/HOL
Author: Christoph Benzmüller
2021-11-08: Real Exponents as the Limits of Sequences of Rational Exponents
Author: Jacques D. Fleuriot
2021-11-08: Automating Public Announcement Logic and the Wise Men Puzzle in Isabelle/HOL
Authors: Christoph Benzmüller and Sebastian Reiche
2021-11-08: Factorization of Polynomials with Algebraic Coefficients
Authors: Manuel Eberl and René Thiemann
2021-11-05: Szemerédi's Regularity Lemma
Authors: Chelsea Edmonds, Angeliki Koutsoukou-Argyraki and Lawrence C. Paulson
2021-10-28: Quantum and Classical Registers
Author: Dominique Unruh
2021-10-19: Belief Revision Theory
Authors: Valentin Fouillard, Safouan Taha, Frédéric Boulanger and Nicolas Sabouret
2021-10-13: X86 instruction semantics and basic block symbolic execution
Authors: Freek Verbeek, Abhijith Bharadwaj, Joshua Bockenek, Ian Roessle, Timmy Weerwag and Binoy Ravindran
2021-10-12: Algebras for Iteration, Infinite Executions and Correctness of Sequential Computations
Author: Walter Guttmann
2021-10-02: Verified Quadratic Virtual Substitution for Real Arithmetic
Authors: Matias Scharager, Katherine Cordwell, Stefan Mitsch and André Platzer
2021-09-24: Soundness and Completeness of an Axiomatic System for First-Order Logic
Author: Asta Halkjær From
2021-09-18: Complex Bounded Operators
Authors: Jose Manuel Rodriguez Caballero and Dominique Unruh
2021-09-16: A Formalization of Weighted Path Orders and Recursive Path Orders
Authors: Christian Sternagel, René Thiemann and Akihisa Yamada
2021-09-06: Extension of Types-To-Sets
Author: Mihails Milehins
2021-09-06: IDE: Introduction, Destruction, Elimination
Author: Mihails Milehins
2021-09-06: Conditional Transfer Rule
Author: Mihails Milehins
2021-09-06: Conditional Simplification
Author: Mihails Milehins
2021-09-06: Category Theory for ZFC in HOL III: Universal Constructions
Author: Mihails Milehins
2021-09-06: Category Theory for ZFC in HOL I: Foundations: Design Patterns, Set Theory, Digraphs, Semicategories
Author: Mihails Milehins
2021-09-06: Category Theory for ZFC in HOL II: Elementary Theory of 1-Categories
Author: Mihails Milehins
2021-09-05: A data flow analysis algorithm for computing dominators
Author: Nan Jiang
2021-09-03: Solving Cubic and Quartic Equations
Author: René Thiemann
2021-08-26: Logging-independent Message Anonymity in the Relational Method
Author: Pasquale Noce
2021-08-21: The Theorem of Three Circles
Authors: Fox Thomson and Wenda Li
2021-08-16: Fresh identifiers
Authors: Andrei Popescu and Thomas Bauereiss
2021-08-16: CoSMed: A confidentiality-verified social media platform
Authors: Thomas Bauereiss and Andrei Popescu
2021-08-16: CoSMeDis: A confidentiality-verified distributed social media platform
Authors: Thomas Bauereiss and Andrei Popescu
2021-08-16: CoCon: A Confidentiality-Verified Conference Management System
Authors: Andrei Popescu, Peter Lammich and Thomas Bauereiss
2021-08-16: Compositional BD Security
Authors: Thomas Bauereiss and Andrei Popescu
2021-08-13: Combinatorial Design Theory
Authors: Chelsea Edmonds and Lawrence Paulson
2021-08-03: Relational Forests
Author: Walter Guttmann
2021-07-27: Schutz' Independent Axioms for Minkowski Spacetime
Authors: Richard Schmoetten, Jake Palmer and Jacques Fleuriot
2021-07-07: Finitely Generated Abelian Groups
Authors: Joseph Thommes and Manuel Eberl
2021-07-01: SpecCheck - Specification-Based Testing for Isabelle/ML
Authors: Kevin Kappelmann, Lukas Bulwahn and Sebastian Willenbrink
2021-06-22: Van der Waerden's Theorem
Authors: Katharina Kreuzer and Manuel Eberl
2021-06-18: MiniSail - A kernel language for the ISA specification language SAIL
Author: Mark Wassell
2021-06-17: Public Announcement Logic
Author: Asta Halkjær From
2021-06-04: A Shorter Compiler Correctness Proof for Language IMP
Author: Pasquale Noce
2021-05-24: Lyndon words
Authors: Štěpán Holub and Štěpán Starosta
2021-05-24: Graph Lemma
Authors: Štěpán Holub and Štěpán Starosta
2021-05-24: Combinatorics on Words Basics
Authors: Štěpán Holub, Martin Raška and Štěpán Starosta
2021-04-30: Regression Test Selection
Author: Susannah Mansky
2021-04-27: Isabelle's Metalogic: Formalization and Proof Checker
Authors: Tobias Nipkow and Simon Roßkopf
2021-04-27: Lifting the Exponent
Author: Jakub Kądziołka
2021-04-24: The BKR Decision Procedure for Univariate Real Arithmetic
Authors: Katherine Cordwell, Yong Kiam Tan and André Platzer
2021-04-23: Gale-Stewart Games
Author: Sebastiaan Joosten
2021-04-13: Formalization of Timely Dataflow's Progress Tracking Protocol
Authors: Matthias Brun, Sára Decova, Andrea Lattuada and Dmitriy Traytel
2021-04-01: Information Flow Control via Dependency Tracking
Author: Benedikt Nordhoff
2021-03-29: Grothendieck's Schemes in Algebraic Geometry
Authors: Anthony Bordg, Lawrence Paulson and Wenda Li
2021-03-23: Hensel's Lemma for the p-adic Integers
Author: Aaron Crighton
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, Simon Robillard and Ujkan Sulejmani
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

 

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 + 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: Order Extension and Szpilrajn's Extension Theorem
Authors: Peter Zeller and Lukas Stevens
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: Completeness of Modal Logics
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, Peter Lammich and Thomas Bauereiss
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,630 +1,659 @@ 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. - 04 Feb 2022 00:00:00 +0000 + 20 Feb 2022 00:00:00 +0000 + + Universal Hash Families + https://www.isa-afp.org/entries/Universal_Hash_Families.html + https://www.isa-afp.org/entries/Universal_Hash_Families.html + Emin Karayel + 20 Feb 2022 00:00:00 +0000 + +A <i>k</i>-universal hash family is a probability +space of functions, which have uniform distribution and form +<i>k</i>-wise independent random variables. They can often be used +in place of classic (or cryptographic) hash functions and allow the +rigorous analysis of the performance of randomized algorithms and +data structures that rely on hash functions. In 1981 +<a href="https://doi.org/10.1016/0022-0000(81)90033-7">Wegman and Carter</a> +introduced a generic construction for such families with arbitrary +<i>k</i> using polynomials over a finite field. This entry +contains a formalization of them and establishes the property of +<i>k</i>-universality. To be useful the formalization also provides +an explicit construction of finite fields using the factor ring of +integers modulo a prime. Additionally, some generic results about +independent families are shown that might be of independent interest. + + + Wetzel's Problem and the Continuum Hypothesis + https://www.isa-afp.org/entries/Wetzels_Problem.html + https://www.isa-afp.org/entries/Wetzels_Problem.html + Lawrence C Paulson + 18 Feb 2022 00:00:00 +0000 + +Let $F$ be a set of analytic functions on the complex plane such that, +for each $z\in\mathbb{C}$, the set $\{f(z) \mid f\in F\}$ is +countable; must then $F$ itself be countable? The answer is yes if the +Continuum Hypothesis is false, i.e., if the cardinality of +$\mathbb{R}$ exceeds $\aleph_1$. But if CH is true then such an $F$, +of cardinality $\aleph_1$, can be constructed by transfinite +recursion. The formal proof illustrates reasoning about complex +analysis (analytic and homomorphic functions) and set theory +(transfinite cardinalities) in a single setting. The mathematical text +comes from <em>Proofs from THE BOOK</em> by Aigner and +Ziegler. + + + First-Order Query Evaluation + https://www.isa-afp.org/entries/Eval_FO.html + https://www.isa-afp.org/entries/Eval_FO.html + Martin Raszyk + 15 Feb 2022 00:00:00 +0000 + +We formalize first-order query evaluation over an infinite domain with +equality. We first define the syntax and semantics of first-order +logic with equality. Next we define a locale +<i>eval&lowbar;fo</i> abstracting a representation of +a potentially infinite set of tuples satisfying a first-order query +over finite relations. Inside the locale, we define a function +<i>eval</i> checking if the set of tuples satisfying a +first-order query over a database (an interpretation of the +query's predicates) is finite (i.e., deciding <i>relative +safety</i>) and computing the set of satisfying tuples if it is +finite. Altogether the function <i>eval</i> solves +<i>capturability</i> (Avron and Hirshfeld, 1991) of +first-order logic with equality. We also use the function +<i>eval</i> to prove a code equation for the semantics of +first-order logic, i.e., the function checking if a first-order query +over a database is satisfied by a variable assignment.<br/> We provide an +interpretation of the locale <i>eval&lowbar;fo</i> +based on the approach by Ailamazyan et al. A core notion in the +interpretation is the active domain of a query and a database that +contains all domain elements that occur in the database or interpret +the query's constants. We prove the main theorem of Ailamazyan et +al. relating the satisfaction of a first-order query over an infinite +domain to the satisfaction of this query over a finite domain +consisting of the active domain and a few additional domain elements +(outside the active domain) whose number only depends on the query. In +our interpretation of the locale +<i>eval&lowbar;fo</i>, we use a potentially higher +number of the additional domain elements, but their number still only +depends on the query and thus has no effect on the data complexity +(Vardi, 1982) of query evaluation. Our interpretation yields an +<i>executable</i> function <i>eval</i>. The +time complexity of <i>eval</i> on a query is linear in the +total number of tuples in the intermediate relations for the +subqueries. Specifically, we build a database index to evaluate a +conjunction. We also optimize the case of a negated subquery in a +conjunction. Finally, we export code for the infinite domain of +natural numbers. + + + Multi-Head Monitoring of Metric Dynamic Logic + https://www.isa-afp.org/entries/VYDRA_MDL.html + https://www.isa-afp.org/entries/VYDRA_MDL.html + Martin Raszyk + 13 Feb 2022 00:00:00 +0000 + +Runtime monitoring (or runtime verification) is an approach to +checking compliance of a system's execution with a specification +(e.g., a temporal query). The system's execution is logged into a +trace---a sequence of time-points, each consisting of a time-stamp and +observed events. A monitor is an algorithm that produces verdicts on +the satisfaction of a temporal query on a trace. We formalize a +monitoring algorithm for metric dynamic logic, an extension of metric +temporal logic with regular expressions. The monitor computes whether +a given query is satisfied at every position in an input trace of +time-stamped events. We formalize the time-stamps as an abstract +algebraic structure satisfying certain assumptions. Instances of this +structure include natural numbers, real numbers, and lexicographic +combinations of them. Our monitor follows the multi-head paradigm: it +reads the input simultaneously at multiple positions and moves its +reading heads asynchronously. This mode of operation results in +unprecedented time and space complexity guarantees for metric dynamic +logic: The monitor's amortized time complexity to process a +time-point and the monitor's space complexity neither depends on +the event-rate, i.e., the number of events within a fixed time-unit, +nor on the numeric constants occurring in the quantitative temporal +constraints in the given query. The multi-head monitoring algorithm +for metric dynamic logic is reported in our paper "Multi-Head +Monitoring of Metric Dynamic Logic" published at ATVA 2020. We +have also formalized unpublished specialized algorithms for the +temporal operators of metric temporal logic. + Enumeration of Equivalence Relations https://www.isa-afp.org/entries/Equivalence_Relation_Enumeration.html https://www.isa-afp.org/entries/Equivalence_Relation_Enumeration.html Emin Karayel 04 Feb 2022 00:00:00 +0000 <p>This entry contains a formalization of an algorithm enumerating all equivalence relations on an initial segment of the natural numbers. The approach follows the method described by Stanton and White <a href="https://doi.org/10.1007/978-1-4612-4968-9">[5,§ 1.5]</a> using restricted growth functions.</p> <p>The algorithm internally enumerates restricted growth functions (as lists), whose equivalence kernels then form the equivalence relations. This has the advantage that the representation is compact and lookup of the relation reduces to a list lookup operation.</p> <p>The algorithm can also be used within a proof and an example application is included, where a sequence of variables is split by the possible partitions they can form.</p> Quasi-Borel Spaces https://www.isa-afp.org/entries/Quasi_Borel_Spaces.html https://www.isa-afp.org/entries/Quasi_Borel_Spaces.html Michikazu Hirata, Yasuhiko Minamide, Tetsuya Sato 03 Feb 2022 00:00:00 +0000 The notion of quasi-Borel spaces was introduced by <a href="https://dl.acm.org/doi/10.5555/3329995.3330072"> Heunen et al</a>. The theory provides a suitable denotational model for higher-order probabilistic programming languages with continuous distributions. This entry is a formalization of the theory of quasi-Borel spaces, including construction of quasi-Borel spaces (product, coproduct, function spaces), the adjunction between the category of measurable spaces and the category of quasi-Borel spaces, and the probability monad on quasi-Borel spaces. This entry also contains the formalization of the Bayesian regression presented in the work of Heunen et al. This work is a part of the work by same authors, <i>Program Logic for Higher-Order Probabilistic Programs in Isabelle/HOL</i>, which will be published in the proceedings of the 16th International Symposium on Functional and Logic Programming (FLOPS 2022). Duality of Linear Programming https://www.isa-afp.org/entries/LP_Duality.html https://www.isa-afp.org/entries/LP_Duality.html René Thiemann 03 Feb 2022 00:00:00 +0000 We formalize the weak and strong duality theorems of linear programming. For the strong duality theorem we provide three sufficient preconditions: both the primal problem and the dual problem are satisfiable, the primal problem is satisfiable and bounded, or the dual problem is satisfiable and bounded. The proofs are based on an existing formalization of Farkas' Lemma. First-Order Theory of Rewriting https://www.isa-afp.org/entries/FO_Theory_Rewriting.html https://www.isa-afp.org/entries/FO_Theory_Rewriting.html Alexander Lochmann, Bertram Felgenhauer 02 Feb 2022 00:00:00 +0000 The first-order theory of rewriting (FORT) is a decidable theory for linear variable-separated rewrite systems. The decision procedure is based on tree automata technique and an inference system presented in "Certifying Proofs in the First-Order Theory of Rewriting". This AFP entry provides a formalization of the underlying decision procedure. Moreover it allows to generate a function that can verify each inference step via the code generation facility of Isabelle/HOL. Additionally it contains the specification of a certificate language (that allows to state proofs in FORT) and a formalized function that allows to verify the validity of the proof. This gives software tool authors, that implement the decision procedure, the possibility to verify their output. Young's Inequality for Increasing Functions https://www.isa-afp.org/entries/Youngs_Inequality.html https://www.isa-afp.org/entries/Youngs_Inequality.html Lawrence C Paulson 31 Jan 2022 00:00:00 +0000 Young's inequality states that $$ ab \leq \int_0^a f(x)dx + \int_0^b f^{-1}(y) dy $$ where $a\geq 0$, $b\geq 0$ and $f$ is strictly increasing and continuous. Its proof is formalised following <a href="https://www.jstor.org/stable/2318018">the development</a> by Cunningham and Grossman. Their idea is to make the intuitive, geometric folklore proof rigorous by reasoning about step functions. The lack of the Riemann integral makes the development longer than one would like, but their argument is reproduced faithfully. A Sequent Calculus Prover for First-Order Logic with Functions https://www.isa-afp.org/entries/FOL_Seq_Calc2.html https://www.isa-afp.org/entries/FOL_Seq_Calc2.html Asta Halkjær From, Frederik Krogsdal Jacobsen 31 Jan 2022 00:00:00 +0000 We formalize an automated theorem prover for first-order logic with functions. The proof search procedure is based on sequent calculus and we verify its soundness and completeness using the Abstract Soundness and Abstract Completeness theories. Our analytic completeness proof covers both open and closed formulas. Since our deterministic prover considers only the subset of terms relevant to proving a given sequent, we do so as well when building a countermodel from a failed proof. We formally connect our prover with the proof system and semantics of the existing SeCaV system. In particular, the prover's output can be post-processed in Haskell to generate human-readable SeCaV proofs which are also machine-verifiable proof certificates. Interpolation Polynomials (in HOL-Algebra) https://www.isa-afp.org/entries/Interpolation_Polynomials_HOL_Algebra.html https://www.isa-afp.org/entries/Interpolation_Polynomials_HOL_Algebra.html Emin Karayel 29 Jan 2022 00:00:00 +0000 <p>A well known result from algebra is that, on any field, there is exactly one polynomial of degree less than n interpolating n points [<a href="https://doi.org/10.1017/CBO9780511814549">1</a>, §7].</p> <p>This entry contains a formalization of the above result, as well as the following generalization in the case of finite fields <i>F</i>: There are <i>|F|<sup>m-n</sup></i> polynomials of degree less than <i>m ≥ n</i> interpolating the same n points, where <i>|F|</i> denotes the size of the domain of the field. To establish the result the entry also includes a formalization of Lagrange interpolation, which might be of independent interest.</p> <p>The formalized results are defined on the algebraic structures from HOL-Algebra, which are distinct from the type-class based structures defined in HOL. Note that there is an existing formalization for polynomial interpolation and, in particular, Lagrange interpolation by Thiemann and Yamada [<a href="https://www.isa-afp.org/entries/Polynomial_Interpolation.html">2</a>] on the type-class based structures in HOL.</p> Median Method https://www.isa-afp.org/entries/Median_Method.html https://www.isa-afp.org/entries/Median_Method.html Emin Karayel 25 Jan 2022 00:00:00 +0000 <p>The median method is an amplification result for randomized approximation algorithms described in [<a href="https://doi.org/10.1006/jcss.1997.1545">1</a>]. Given an algorithm whose result is in a desired interval with a probability larger than <i>1/2</i>, it is possible to improve the success probability, by running the algorithm multiple times independently and using the median. In contrast to using the mean, the amplification of the success probability grows exponentially with the number of independent runs.</p> <p>This entry contains a formalization of the underlying theorem: Given a sequence of n independent random variables, which are in a desired interval with a probability <i>1/2 + a</i>. Then their median will be in the desired interval with a probability of <i>1 − exp(−2a<sup>2</sup> n)</i>. In particular, the success probability approaches <i>1</i> exponentially with the number of variables.</p> <p>In addition to that, this entry also contains a proof that order-statistics of Borel-measurable random variables are themselves measurable and that generalized intervals in linearly ordered Borel-spaces are measurable.</p> Actuarial Mathematics https://www.isa-afp.org/entries/Actuarial_Mathematics.html https://www.isa-afp.org/entries/Actuarial_Mathematics.html Yosuke Ito 23 Jan 2022 00:00:00 +0000 Actuarial Mathematics is a theory in applied mathematics, which is mainly used for determining the prices of insurance products and evaluating the liability of a company associating with insurance contracts. It is related to calculus, probability theory and financial theory, etc. In this entry, I formalize the very basic part of Actuarial Mathematics in Isabelle/HOL. The first formalization is about the theory of interest which deals with interest rates, present value factors, an annuity certain, etc. I have already formalized the basic part of Actuarial Mathematics in Coq (https://github.com/Yosuke-Ito-345/Actuary). This entry is currently the partial translation and a little generalization of the Coq formalization. The further translation in Isabelle/HOL is now proceeding. Irrational numbers from THE BOOK https://www.isa-afp.org/entries/Irrationals_From_THEBOOK.html https://www.isa-afp.org/entries/Irrationals_From_THEBOOK.html Lawrence C Paulson 08 Jan 2022 00:00:00 +0000 An elementary proof is formalised: that <em>exp r</em> is irrational for every nonzero rational number <em>r</em>. The mathematical development comes from the well-known volume <em>Proofs from THE BOOK</em>, by Aigner and Ziegler, who credit the idea to Hermite. The development illustrates a number of basic Isabelle techniques: the manipulation of summations, the calculation of quite complicated derivatives and the estimation of integrals. We also see how to import another AFP entry (Stirling's formula). As for the theorem itself, note that a much stronger and more general result (the Hermite--Lindemann--Weierstraß transcendence theorem) is already available in the AFP. Knight's Tour Revisited Revisited https://www.isa-afp.org/entries/Knights_Tour.html https://www.isa-afp.org/entries/Knights_Tour.html Lukas Koller 04 Jan 2022 00:00:00 +0000 This is a formalization of the article <i>Knight's Tour Revisited</i> by Cull and De Curtins where they prove the existence of a Knight's path for arbitrary <i>n &times; m</i>-boards with <i>min(n,m) &ge; 5</i>. If <i>n &middot; m</i> is even, then there exists a Knight's circuit. A Knight's Path is a sequence of moves of a Knight on a chessboard s.t. the Knight visits every square of a chessboard exactly once. Finding a Knight's path is a an instance of the Hamiltonian path problem. A Knight's circuit is a Knight's path, where additionally the Knight can move from the last square to the first square of the path, forming a loop. During the formalization two mistakes in the original proof were discovered. These mistakes are corrected in this formalization. Hyperdual Numbers and Forward Differentiation https://www.isa-afp.org/entries/Hyperdual.html https://www.isa-afp.org/entries/Hyperdual.html Filip Smola, Jacques Fleuriot 31 Dec 2021 00:00:00 +0000 <p>Hyperdual numbers are ones with a real component and a number of infinitesimal components, usually written as $a_0 + a_1 \cdot \epsilon_1 + a_2 \cdot \epsilon_2 + a_3 \cdot \epsilon_1\epsilon_2$. They have been proposed by <a href="https://doi.org/10.2514/6.2011-886">Fike and Alonso</a> in an approach to automatic differentiation.</p> <p>In this entry we formalise hyperdual numbers and their application to forward differentiation. We show them to be an instance of multiple algebraic structures and then, along with facts about twice-differentiability, we define what we call the hyperdual extensions of functions on real-normed fields. This extension formally represents the proposed way that the first and second derivatives of a function can be automatically calculated. We demonstrate it on the standard logistic function $f(x) = \frac{1}{1 + e^{-x}}$ and also reproduce the example analytic function $f(x) = \frac{e^x}{\sqrt{sin(x)^3 + cos(x)^3}}$ used for demonstration by Fike and Alonso.</p> Gale-Shapley Algorithm https://www.isa-afp.org/entries/Gale_Shapley.html https://www.isa-afp.org/entries/Gale_Shapley.html Tobias Nipkow 29 Dec 2021 00:00:00 +0000 This is a stepwise refinement and proof of the Gale-Shapley stable matching (or marriage) algorithm down to executable code. Both a purely functional implementation based on lists and a functional implementation based on efficient arrays (provided by the Collections Framework in the AFP) are developed. The latter implementation runs in time <i>O(n<sup>2</sup>)</i> where <i>n</i> is the cardinality of the two sets to be matched. Roth's Theorem on Arithmetic Progressions https://www.isa-afp.org/entries/Roth_Arithmetic_Progressions.html https://www.isa-afp.org/entries/Roth_Arithmetic_Progressions.html Chelsea Edmonds, Angeliki Koutsoukou-Argyraki, Lawrence C. Paulson 28 Dec 2021 00:00:00 +0000 We formalise a proof of Roth's Theorem on Arithmetic Progressions, a major result in additive combinatorics on the existence of 3-term arithmetic progressions in subsets of natural numbers. To this end, we follow a proof using graph regularity. We employ our recent formalisation of Szemerédi's Regularity Lemma, a major result in extremal graph theory, which we use here to prove the Triangle Counting Lemma and the Triangle Removal Lemma. Our sources are Yufei Zhao's MIT lecture notes "<a href="https://ocw.mit.edu/courses/mathematics/18-217-graph-theory-and-additive-combinatorics-fall-2019/lecture-notes/MIT18_217F19_ch3.pdf">Graph Theory and Additive Combinatorics</a>" (revised version <a href="https://yufeizhao.com/gtac/gtac17.pdf">here</a>) and W.T. Gowers's Cambridge lecture notes "<a href="https://www.dpmms.cam.ac.uk/~par31/notes/tic.pdf">Topics in Combinatorics</a>". We also refer to the University of Georgia notes by Stephanie Bell and Will Grodzicki, "<a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.432.327">Using Szemerédi's Regularity Lemma to Prove Roth's Theorem</a>". Markov Decision Processes with Rewards https://www.isa-afp.org/entries/MDP-Rewards.html https://www.isa-afp.org/entries/MDP-Rewards.html Maximilian Schäffeler, Mohammad Abdulaziz 16 Dec 2021 00:00:00 +0000 We present a formalization of Markov Decision Processes with rewards. In particular we first build on Hölzl's formalization of MDPs (AFP entry: Markov_Models) and extend them with rewards. We proceed with an analysis of the expected total discounted reward criterion for infinite horizon MDPs. The central result is the construction of the iteration rule for the Bellman operator. We prove the optimality equations for this operator and show the existence of an optimal stationary deterministic solution. The analysis can be used to obtain dynamic programming algorithms such as value iteration and policy iteration to solve MDPs with formal guarantees. Our formalization is based on chapters 5 and 6 in Puterman's book "Markov Decision Processes: Discrete Stochastic Dynamic Programming". Verified Algorithms for Solving Markov Decision Processes https://www.isa-afp.org/entries/MDP-Algorithms.html https://www.isa-afp.org/entries/MDP-Algorithms.html Maximilian Schäffeler, Mohammad Abdulaziz 16 Dec 2021 00:00:00 +0000 We present a formalization of algorithms for solving Markov Decision Processes (MDPs) with formal guarantees on the optimality of their solutions. In particular we build on our analysis of the Bellman operator for discounted infinite horizon MDPs. From the iterator rule on the Bellman operator we directly derive executable value iteration and policy iteration algorithms to iteratively solve finite MDPs. We also prove correct optimized versions of value iteration that use matrix splittings to improve the convergence rate. In particular, we formally verify Gauss-Seidel value iteration and modified policy iteration. The algorithms are evaluated on two standard examples from the literature, namely, inventory management and gridworld. Our formalization covers most of chapter 6 in Puterman's book "Markov Decision Processes: Discrete Stochastic Dynamic Programming". Regular Tree Relations https://www.isa-afp.org/entries/Regular_Tree_Relations.html https://www.isa-afp.org/entries/Regular_Tree_Relations.html Alexander Lochmann, Bertram Felgenhauer, Christian Sternagel, René Thiemann, Thomas Sternagel 15 Dec 2021 00:00:00 +0000 Tree automata have good closure properties and therefore a commonly used to prove/disprove properties. This formalization contains among other things the proofs of many closure properties of tree automata (anchored) ground tree transducers and regular relations. Additionally it includes the well known pumping lemma and a lifting of the Myhill Nerode theorem for regular languages to tree languages. We want to mention the existence of a <a href="https://www.isa-afp.org/entries/Tree-Automata.html">tree automata APF-entry</a> developed by Peter Lammich. His work is based on epsilon free top-down tree automata, while this entry builds on bottom-up tree auotamta with epsilon transitions. Moreover our formalization relies on the <a href="https://www.isa-afp.org/entries/Collections.html">Collections Framework</a>, also by Peter Lammich, to obtain efficient code. All proven constructions of the closure properties are exportable using the Isabelle/HOL code generation facilities. Simplicial Complexes and Boolean functions https://www.isa-afp.org/entries/Simplicial_complexes_and_boolean_functions.html https://www.isa-afp.org/entries/Simplicial_complexes_and_boolean_functions.html Jesús Aransay, Alejandro del Campo, Julius Michaelis 29 Nov 2021 00:00:00 +0000 In this work we formalise the isomorphism between simplicial complexes of dimension $n$ and monotone Boolean functions in $n$ variables, mainly following the definitions and results as introduced by N. A. Scoville. We also take advantage of the AFP representation of <a href="https://www.isa-afp.org/entries/ROBDD.html">ROBDD</a> (Reduced Ordered Binary Decision Diagrams) to compute the ROBDD representation of a given simplicial complex (by means of the isomorphism to Boolean functions). Some examples of simplicial complexes and associated Boolean functions are also presented. van Emde Boas Trees https://www.isa-afp.org/entries/Van_Emde_Boas_Trees.html https://www.isa-afp.org/entries/Van_Emde_Boas_Trees.html Thomas Ammer, Peter Lammich 23 Nov 2021 00:00:00 +0000 The <em>van Emde Boas tree</em> or <em>van Emde Boas priority queue</em> is a data structure supporting membership test, insertion, predecessor and successor search, minimum and maximum determination and deletion in <em>O(log log U)</em> time, where <em>U = 0,...,2<sup>n-1</sup></em> is the overall range to be considered. <p/> The presented formalization follows Chapter 20 of the popular <em>Introduction to Algorithms (3rd ed.)</em> by Cormen, Leiserson, Rivest and Stein (CLRS), extending the list of formally verified CLRS algorithms. Our current formalization is based on the first author's bachelor's thesis. <p/> First, we prove correct a <em>functional</em> implementation, w.r.t. an abstract data type for sets. Apart from functional correctness, we show a resource bound, and runtime bounds w.r.t. manually defined timing functions for the operations. <p/> Next, we refine the operations to Imperative HOL with time, and show correctness and complexity. This yields a practically more efficient implementation, and eliminates the manually defined timing functions from the trusted base of the proof. Foundation of geometry in planes, and some complements: Excluding the parallel axioms https://www.isa-afp.org/entries/Foundation_of_geometry.html https://www.isa-afp.org/entries/Foundation_of_geometry.html Fumiya Iwama 22 Nov 2021 00:00:00 +0000 "Foundations of Geometry" is a mathematical book written by Hilbert in 1899. This entry is a complete formalization of "Incidence" (excluding cubic axioms), "Order" and "Congruence" (excluding point sequences) of the axioms constructed in this book. In addition, the theorem of the problem about the part that is treated implicitly and is not clearly stated in it is being carried out in parallel. The Hahn and Jordan Decomposition Theorems https://www.isa-afp.org/entries/Hahn_Jordan_Decomposition.html https://www.isa-afp.org/entries/Hahn_Jordan_Decomposition.html Marie Cousin, Mnacho Echenim, Hervé Guiol 19 Nov 2021 00:00:00 +0000 In this work we formalize the Hahn decomposition theorem for signed measures, namely that any measure space for a signed measure can be decomposed into a positive and a negative set, where every measurable subset of the positive one has a positive measure, and every measurable subset of the negative one has a negative measure. We also formalize the Jordan decomposition theorem as a corollary, which states that the signed measure under consideration admits a unique decomposition into a difference of two positive measures, at least one of which is finite. Exploring Simplified Variants of Gödel’s Ontological Argument in Isabelle/HOL https://www.isa-afp.org/entries/SimplifiedOntologicalArgument.html https://www.isa-afp.org/entries/SimplifiedOntologicalArgument.html Christoph Benzmüller 08 Nov 2021 00:00:00 +0000 <p>Simplified variants of Gödel's ontological argument are explored. Among those is a particularly interesting simplified argument which is (i) valid already in basic modal logics K or KT, (ii) which does not suffer from modal collapse, and (iii) which avoids the rather complex predicates of essence (Ess.) and necessary existence (NE) as used by Gödel. </p><p> Whether the presented variants increase or decrease the attractiveness and persuasiveness of the ontological argument is a question I would like to pass on to philosophy and theology. </p> Real Exponents as the Limits of Sequences of Rational Exponents https://www.isa-afp.org/entries/Real_Power.html https://www.isa-afp.org/entries/Real_Power.html Jacques D. Fleuriot 08 Nov 2021 00:00:00 +0000 In this formalisation, we construct real exponents as the limits of sequences of rational exponents. In particular, if $a \ge 1$ and $x \in \mathbb{R}$, we choose an increasing rational sequence $r_n$ such that $\lim_{n\to\infty} {r_n} = x$. Then the sequence $a^{r_n}$ is increasing and if $r$ is any rational number such that $r > x$, $a^{r_n}$ is bounded above by $a^r$. By the convergence criterion for monotone sequences, $a^{r_n}$ converges. We define $a^ x = \lim_{n\to\infty} a^{r_n}$ and show that it has the expected properties (for $a \ge 0$). This particular construction of real exponents is needed instead of the usual one using the natural logarithm and exponential functions (which already exists in Isabelle) to support our mechanical derivation of Euler's exponential series as an ``infinite polynomial". Aside from helping us avoid circular reasoning, this is, as far as we are aware, the first time real exponents are mechanised in this way within a proof assistant. Automating Public Announcement Logic and the Wise Men Puzzle in Isabelle/HOL https://www.isa-afp.org/entries/PAL.html https://www.isa-afp.org/entries/PAL.html Christoph Benzmüller, Sebastian Reiche 08 Nov 2021 00:00:00 +0000 We present a shallow embedding of public announcement logic (PAL) with relativized general knowledge in HOL. We then use PAL to obtain an elegant encoding of the wise men puzzle, which we solve automatically using sledgehammer. Factorization of Polynomials with Algebraic Coefficients https://www.isa-afp.org/entries/Factor_Algebraic_Polynomial.html https://www.isa-afp.org/entries/Factor_Algebraic_Polynomial.html Manuel Eberl, René Thiemann 08 Nov 2021 00:00:00 +0000 The AFP already contains a verified implementation of algebraic numbers. However, it is has a severe limitation in its factorization algorithm of real and complex polynomials: the factorization is only guaranteed to succeed if the coefficients of the polynomial are rational numbers. In this work, we verify an algorithm to factor all real and complex polynomials whose coefficients are algebraic. The existence of such an algorithm proves in a constructive way that the set of complex algebraic numbers is algebraically closed. Internally, the algorithm is based on resultants of multivariate polynomials and an approximation algorithm using interval arithmetic. Szemerédi's Regularity Lemma https://www.isa-afp.org/entries/Szemeredi_Regularity.html https://www.isa-afp.org/entries/Szemeredi_Regularity.html Chelsea Edmonds, Angeliki Koutsoukou-Argyraki, Lawrence C. Paulson 05 Nov 2021 00:00:00 +0000 <a href="https://en.wikipedia.org/wiki/Szemerédi_regularity_lemma">Szemerédi's regularity lemma</a> is a key result in the study of large graphs. It asserts the existence of an upper bound on the number of parts the vertices of a graph need to be partitioned into such that the edges between the parts are random in a certain sense. This bound depends only on the desired precision and not on the graph itself, in the spirit of Ramsey's theorem. The formalisation follows online course notes by <a href="https://www.dpmms.cam.ac.uk/~par31/notes/tic.pdf">Tim Gowers</a> and <a href="https://yufeizhao.com/gtac/gtac.pdf">Yufei Zhao</a>. - - Quantum and Classical Registers - https://www.isa-afp.org/entries/Registers.html - https://www.isa-afp.org/entries/Registers.html - Dominique Unruh - 28 Oct 2021 00:00:00 +0000 - -A formalization of the theory of quantum and classical registers as -developed by (Unruh, Quantum and Classical Registers). In a nutshell, -a register refers to a part of a larger memory or system that can be -accessed independently. Registers can be constructed from other -registers and several (compatible) registers can be composed. This -formalization develops both the generic theory of registers as well as -specific instantiations for classical and quantum registers. - - - Belief Revision Theory - https://www.isa-afp.org/entries/Belief_Revision.html - https://www.isa-afp.org/entries/Belief_Revision.html - Valentin Fouillard, Safouan Taha, Frédéric Boulanger, Nicolas Sabouret - 19 Oct 2021 00:00:00 +0000 - -The 1985 paper by Carlos Alchourrón, Peter Gärdenfors, and David -Makinson (AGM), “On the Logic of Theory Change: Partial Meet -Contraction and Revision Functions” launches a large and rapidly -growing literature that employs formal models and logics to handle -changing beliefs of a rational agent and to take into account new -piece of information observed by this agent. In 2011, a review book -titled "AGM 25 Years: Twenty-Five Years of Research in Belief -Change" was edited to summarize the first twenty five years of -works based on AGM. This HOL-based AFP entry is a faithful -formalization of the AGM operators (e.g. contraction, revision, -remainder ...) axiomatized in the original paper. It also contains the -proofs of all the theorems stated in the paper that show how these -operators combine. Both proofs of Harper and Levi identities are -established. - - - X86 instruction semantics and basic block symbolic execution - https://www.isa-afp.org/entries/X86_Semantics.html - https://www.isa-afp.org/entries/X86_Semantics.html - Freek Verbeek, Abhijith Bharadwaj, Joshua Bockenek, Ian Roessle, Timmy Weerwag, Binoy Ravindran - 13 Oct 2021 00:00:00 +0000 - -This AFP entry provides semantics for roughly 120 different X86-64 -assembly instructions. These instructions include various moves, -arithmetic/logical operations, jumps, call/return, SIMD extensions and -others. External functions are supported by allowing a user to provide -custom semantics for these calls. Floating-point operations are mapped -to uninterpreted functions. The model provides semantics for register -aliasing and a byte-level little-endian memory model. The semantics -are purposefully incomplete, but overapproximative. For example, the -precise effect of flags may be undefined for certain instructions, or -instructions may simply have no semantics at all. In those cases, the -semantics are mapped to universally quantified uninterpreted terms -from a locale. Second, this entry provides a method to symbolic -execution of basic blocks. The method, called -''se_step'' (for: symbolic execution step) fetches -an instruction and updates the current symbolic state while keeping -track of assumptions made over the memory model. A key component is a -set of theorems that prove how reads from memory resolve after writes -have occurred. Thirdly, this entry provides a parser that allows the -user to copy-paste the output of the standard disassembly tool objdump -into Isabelle/HOL. A couple small and explanatory examples are -included, including functions from the word count program. Several -examples can be supplied upon request (they are not included due to -the running time of verification): functions from the floating-point -modulo function from FDLIBM, the GLIBC strlen function and the -CoreUtils SHA256 implementation. - - - Algebras for Iteration, Infinite Executions and Correctness of Sequential Computations - https://www.isa-afp.org/entries/Correctness_Algebras.html - https://www.isa-afp.org/entries/Correctness_Algebras.html - Walter Guttmann - 12 Oct 2021 00:00:00 +0000 - -We study models of state-based non-deterministic sequential -computations and describe them using algebras. We propose algebras -that describe iteration for strict and non-strict computations. They -unify computation models which differ in the fixpoints used to -represent iteration. We propose algebras that describe the infinite -executions of a computation. They lead to a unified approximation -order and results that connect fixpoints in the approximation and -refinement orders. This unifies the semantics of recursion for a range -of computation models. We propose algebras that describe preconditions -and the effect of while-programs under postconditions. They unify -correctness statements in two dimensions: one statement applies in -various computation models to various correctness claims. - 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:661
Number of Articles:665
Number of Authors:423
Number of lemmas:~193,600
Lines of Code:~3,335,600
Number of lemmas:~194,500
Lines of Code:~3,350,900

Most used AFP articles:

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

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,1042 +1,1048 @@ 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   MDP-Algorithms   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   Regression_Test_Selection   Gale_Shapley   + VYDRA_MDL   + Universal_Hash_Families   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   Progress_Tracking   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   BenOr_Kozen_Reif   Smith_Normal_Form   Safe_Distance   Modular_arithmetic_LLL_and_HNF_algorithms   Virtual_Substitution   Equivalence_Relation_Enumeration   Optimization: Simplex   Quantum computing: Isabelle_Marries_Dirac   Projective_Measurements   Registers  

Concurrency

Data structures

Functional programming

Hardware

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   MiniSail   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   Correctness_Algebras   Registers   Compiling: CakeML_Codegen   Compiling-Exceptions-Correctly   NormByEval   Density_Compiler   VeriComp   IMP_Compiler   Static analysis: RIPEMD-160-SPARK   Program-Conflict-Analysis   Shivers-CFA   Slicing   HRB-Slicing   InfPathElimination   Abs_Int_ITP2012   Dominance_CHK   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

Optics   Subresultants   Buildings   Algebraic_VCs   C2KA_DistributedSystems   Multirelations   Residuated_Lattices   PseudoHoops   Impossible_Geometry   Gauss-Jordan-Elim-Fun   Matrix_Tensor   Kleene_Algebra   KAT_and_DRA   KAD   Regular_Algebras   Free-Groups   CofGroups   Finitely_Generated_Abelian_Groups   Group-Ring-Module   Robbins-Conjecture   Valuation   Rank_Nullity_Theorem   Polynomials   Relation_Algebra   PSemigroupsConvolution   Secondary_Sylow   Jordan_Hoelder   Cayley_Hamilton   VectorSpace   Echelon_Form   QR_Decomposition   Hermite   Rep_Fin_Groups   Jordan_Normal_Form   Algebraic_Numbers   Polynomial_Interpolation   Polynomial_Factorization   Perron_Frobenius   Stochastic_Matrices   Groebner_Bases   Nullstellensatz   Mason_Stothers   Berlekamp_Zassenhaus   Stone_Relation_Algebras   Stone_Kleene_Relation_Algebras   Orbit_Stabiliser   Dirichlet_L   Symmetric_Polynomials   Taylor_Models   LLL_Basis_Reduction   LLL_Factorization   Localization_Ring   Quaternions   Octonions   Aggregation_Algebras   Signature_Groebner   Quantales   Transformer_Semantics   Farkas   Groebner_Macaulay   Linear_Inequalities   Linear_Programming   Jacobson_Basic_Algebra   Hybrid_Systems_VCs   Subset_Boolean_Algebras   Power_Sum_Polynomials   Formal_Puiseux_Series   Matrices_for_ODEs   Smith_Normal_Form   Grothendieck_Schemes   Factor_Algebraic_Polynomial   Hyperdual   Interpolation_Polynomials_HOL_Algebra   LP_Duality  

Analysis

Measure theory

Probability theory

Number theory

Games and economics

Geometry

Topology

Graph theory

Combinatorics

Category theory

Physics

Misc

Tools

\ No newline at end of file