diff --git a/metadata/metadata b/metadata/metadata --- a/metadata/metadata +++ b/metadata/metadata @@ -1,11413 +1,11476 @@ [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 [Probabilistic_System_Zoo] title = A Zoo of Probabilistic Systems author = Johannes Hölzl , Andreas Lochbihler , Dmitriy Traytel date = 2015-05-27 topic = Computer science/Automata and formal languages abstract = Numerous models of probabilistic systems are studied in the literature. Coalgebra has been used to classify them into system types and compare their expressiveness. We formalize the resulting hierarchy of probabilistic system types by modeling the semantics of the different systems as codatatypes. This approach yields simple and concise proofs, as bisimilarity coincides with equality for codatatypes.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

notify = pasquale.noce.lavoro@gmail.com [CryptoBasedCompositionalProperties] title = Compositional Properties of Crypto-Based Components author = Maria Spichkova date = 2014-01-11 topic = Computer science/Security abstract = This paper presents an Isabelle/HOL set of theories which allows the specification of crypto-based components and the verification of their composition properties wrt. cryptographic aspects. We introduce a formalisation of the security property of data secrecy, the corresponding definitions and proofs. Please note that here we import the Isabelle/HOL theory ListExtras.thy, presented in the AFP entry FocusStreamsCaseStudies-AFP. notify = maria.spichkova@rmit.edu.au [Featherweight_OCL] title = Featherweight OCL: A Proposal for a Machine-Checked Formal Semantics for OCL 2.5 author = Achim D. Brucker , Frédéric Tuong , Burkhart Wolff date = 2014-01-16 topic = Computer science/System description languages abstract = The Unified Modeling Language (UML) is one of the few modeling languages that is widely used in industry. While UML is mostly known as diagrammatic modeling language (e.g., visualizing class models), it is complemented by a textual language, called Object Constraint Language (OCL). The current version of OCL is based on a four-valued logic that turns UML into a formal language. Any type comprises the elements "invalid" and "null" which are propagated as strict and non-strict, respectively. Unfortunately, the former semi-formal semantics of this specification language, captured in the "Annex A" of the OCL standard, leads to different interpretations of corner cases. We formalize the core of OCL: denotational definitions, a logical calculus and operational rules that allow for the execution of OCL expressions by a mixture of term rewriting and code compilation. Our formalization reveals several inconsistencies and contradictions in the current version of the OCL standard. Overall, this document is intended to provide the basis for a machine-checked text "Annex A" of the OCL standard targeting at tool implementors. extra-history = Change history: [2015-10-13]: afp-devel@ea3b38fc54d6 and hol-testgen@12148
   Update of Featherweight OCL including a change in the abstract.
[2014-01-16]: afp-devel@9091ce05cb20 and hol-testgen@10241
   New Entry: Featherweight OCL notify = brucker@spamfence.net, tuong@users.gforge.inria.fr, wolff@lri.fr [Relation_Algebra] title = Relation Algebra author = Alasdair Armstrong <>, Simon Foster , Georg Struth , Tjark Weber date = 2014-01-25 topic = Mathematics/Algebra abstract = Tarski's algebra of binary relations is formalised along the lines of the standard textbooks of Maddux and Schmidt and Ströhlein. This includes relation-algebraic concepts such as subidentities, vectors and a domain operation as well as various notions associated to functions. Relation algebras are also expanded by a reflexive transitive closure operation, and they are linked with Kleene algebras and models of binary relations and Boolean matrices. notify = g.struth@sheffield.ac.uk, tjark.weber@it.uu.se [PSemigroupsConvolution] title = Partial Semigroups and Convolution Algebras author = Brijesh Dongol , Victor B. F. Gomes , Ian J. Hayes , Georg Struth topic = Mathematics/Algebra date = 2017-06-13 notify = g.struth@sheffield.ac.uk, victor.gomes@cl.cam.ac.uk abstract = Partial Semigroups are relevant to the foundations of quantum mechanics and combinatorics as well as to interval and separation logics. Convolution algebras can be understood either as algebras of generalised binary modalities over ternary Kripke frames, in particular over partial semigroups, or as algebras of quantale-valued functions which are equipped with a convolution-style operation of multiplication that is parametrised by a ternary relation. Convolution algebras provide algebraic semantics for various substructural logics, including categorial, relevance and linear logics, for separation logic and for interval logics; they cover quantitative and qualitative applications. These mathematical components for partial semigroups and convolution algebras provide uniform foundations from which models of computation based on relations, program traces or pomsets, and verification components for separation or interval temporal logics can be built with little effort. [Secondary_Sylow] title = Secondary Sylow Theorems author = Jakob von Raumer date = 2014-01-28 topic = Mathematics/Algebra abstract = These theories extend the existing proof of the first Sylow theorem (written by Florian Kammueller and L. C. Paulson) by what are often called the second, third and fourth Sylow theorems. These theorems state propositions about the number of Sylow p-subgroups of a group and the fact that they are conjugate to each other. The proofs make use of an implementation of group actions and their properties. notify = psxjv4@nottingham.ac.uk [Jordan_Hoelder] title = The Jordan-Hölder Theorem author = Jakob von Raumer date = 2014-09-09 topic = Mathematics/Algebra abstract = This submission contains theories that lead to a formalization of the proof of the Jordan-Hölder theorem about composition series of finite groups. The theories formalize the notions of isomorphism classes of groups, simple groups, normal series, composition series, maximal normal subgroups. Furthermore, they provide proofs of the second isomorphism theorem for groups, the characterization theorem for maximal normal subgroups as well as many useful lemmas about normal subgroups and factor groups. The proof is inspired by course notes of Stuart Rankin. notify = psxjv4@nottingham.ac.uk [Cayley_Hamilton] title = The Cayley-Hamilton Theorem author = Stephan Adelsberger , Stefan Hetzl , Florian Pollak date = 2014-09-15 topic = Mathematics/Algebra abstract = This document contains a proof of the Cayley-Hamilton theorem based on the development of matrices in HOL/Multivariate Analysis. notify = stvienna@gmail.com [Probabilistic_Noninterference] title = Probabilistic Noninterference author = Andrei Popescu , Johannes Hölzl date = 2014-03-11 topic = Computer science/Security abstract = We formalize a probabilistic noninterference for a multi-threaded language with uniform scheduling, where probabilistic behaviour comes from both the scheduler and the individual threads. We define notions probabilistic noninterference in two variants: resumption-based and trace-based. For the resumption-based notions, we prove compositionality w.r.t. the language constructs and establish sound type-system-like syntactic criteria. This is a formalization of the mathematical development presented at CPP 2013 and CALCO 2013. It is the probabilistic variant of the Possibilistic Noninterference AFP entry. notify = hoelzl@in.tum.de [HyperCTL] title = A shallow embedding of HyperCTL* author = Markus N. Rabe , Peter Lammich , Andrei Popescu date = 2014-04-16 topic = Computer science/Security, Logic/General logic/Temporal logic abstract = We formalize HyperCTL*, a temporal logic for expressing security properties. We first define a shallow embedding of HyperCTL*, within which we prove inductive and coinductive rules for the operators. Then we show that a HyperCTL* formula captures Goguen-Meseguer noninterference, a landmark information flow property. We also define a deep embedding and connect it to the shallow embedding by a denotational semantics, for which we prove sanity w.r.t. dependence on the free variables. Finally, we show that under some finiteness assumptions about the model, noninterference is given by a (finitary) syntactic formula. notify = uuomul@yahoo.com [Bounded_Deducibility_Security] title = Bounded-Deducibility Security author = Andrei Popescu , Peter Lammich , 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. [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. [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 = eminkarayel@google.com, edgargip@google.com, me@eminkarayel.de abstract = Commutative Replicated Data Types (CRDTs) are a promising new class of data structures for large-scale shared mutable content in applications that only require eventual consistency. The WithOut Operational Transforms (WOOT) framework is a CRDT for collaborative text editing introduced by Oster et al. (CSCW 2006) for which the eventual consistency property was verified only for a bounded model to date. We contribute a formal proof for WOOTs strong eventual consistency. [Furstenberg_Topology] title = Furstenberg's topology and his proof of the infinitude of primes author = Manuel Eberl topic = Mathematics/Number theory date = 2020-03-22 notify = manuel.eberl@tum.de abstract =

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

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

[Saturation_Framework] title = A Comprehensive Framework for Saturation Theorem Proving author = Sophie Tourret topic = Logic/General logic/Mechanization of proofs date = 2020-04-09 notify = stourret@mpi-inf.mpg.de abstract = This Isabelle/HOL formalization is the companion of the technical report “A comprehensive framework for saturation theorem proving”, itself companion of the eponym IJCAR 2020 paper, written by Uwe Waldmann, Sophie Tourret, Simon Robillard and Jasmin Blanchette. It verifies a framework for formal refutational completeness proofs of abstract provers that implement saturation calculi, such as ordered resolution or superposition, and allows to model entire prover architectures in such a way that the static refutational completeness of a calculus immediately implies the dynamic refutational completeness of a prover implementing the calculus using a variant of the given clause loop. The technical report “A comprehensive framework for saturation theorem proving” is available on the Matryoshka website. The names of the Isabelle lemmas and theorems corresponding to the results in the report are indicated in the margin of the report. [Saturation_Framework_Extensions] title = Extensions to the Comprehensive Framework for Saturation Theorem Proving author = Jasmin Blanchette , Sophie Tourret topic = Logic/General logic/Mechanization of proofs date = 2020-08-25 notify = jasmin.blanchette@gmail.com abstract = This Isabelle/HOL formalization extends the AFP entry Saturation_Framework with the following contributions:
  • an application of the framework to prove Bachmair and Ganzinger's resolution prover RP refutationally complete, which was formalized in a more ad hoc fashion by Schlichtkrull et al. in the AFP entry Ordered_Resultion_Prover;
  • generalizations of various basic concepts formalized by Schlichtkrull et al., which were needed to verify RP and could be useful to formalize other calculi, such as superposition;
  • alternative proofs of fairness (and hence saturation and ultimately refutational completeness) for the given clause procedures GC and LGC, based on invariance.
[MFODL_Monitor_Optimized] title = Formalization of an Optimized Monitoring Algorithm for Metric First-Order Dynamic Logic with Aggregations author = Thibault Dardinier<>, Lukas Heimes<>, Martin Raszyk , Joshua Schneider , Dmitriy Traytel topic = Computer science/Algorithms, Logic/General logic/Modal logic, Computer science/Automata and formal languages date = 2020-04-09 notify = martin.raszyk@inf.ethz.ch, joshua.schneider@inf.ethz.ch, traytel@inf.ethz.ch abstract = A monitor is a runtime verification tool that solves the following problem: Given a stream of time-stamped events and a policy formulated in a specification language, decide whether the policy is satisfied at every point in the stream. We verify the correctness of an executable monitor for specifications given as formulas in metric first-order dynamic logic (MFODL), which combines the features of metric first-order temporal logic (MFOTL) and metric dynamic logic. Thus, MFODL supports real-time constraints, first-order parameters, and regular expressions. Additionally, the monitor supports aggregation operations such as count and sum. This formalization, which is described in a forthcoming paper at IJCAR 2020, significantly extends previous work on a verified monitor for MFOTL. Apart from the addition of regular expressions and aggregations, we implemented multi-way joins and a specialized sliding window algorithm to further optimize the monitor. 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 = jmafoster1@sheffield.ac.uk, adbrucker@0x5f.org abstract = In this AFP entry, we provide a formalisation of extended finite state machines (EFSMs) where models are represented as finite sets of transitions between states. EFSMs execute traces to produce observable outputs. We also define various simulation and equality metrics for EFSMs in terms of traces and prove their strengths in relation to each other. Another key contribution is a framework of function definitions such that LTL properties can be phrased over EFSMs. Finally, we provide a simple example case study in the form of a drinks machine. [Extended_Finite_State_Machine_Inference] title = Inference of Extended Finite State Machines author = Michael Foster , Achim D. Brucker , Ramsay G. Taylor , John Derrick topic = Computer science/Automata and formal languages date = 2020-09-07 notify = jmafoster1@sheffield.ac.uk, adbrucker@0x5f.org abstract = In this AFP entry, we provide a formal implementation of a state-merging technique to infer extended finite state machines (EFSMs), complete with output and update functions, from black-box traces. In particular, we define the subsumption in context relation as a means of determining whether one transition is able to account for the behaviour of another. Building on this, we define the direct subsumption relation, which lifts the subsumption in context relation to EFSM level such that we can use it to determine whether it is safe to merge a given pair of transitions. Key proofs include the conditions necessary for subsumption to occur and that subsumption and direct subsumption are preorder relations. We also provide a number of different heuristics which can be used to abstract away concrete values into registers so that more states and transitions can be merged and provide proofs of the various conditions which must hold for these abstractions to subsume their ungeneralised counterparts. A Code Generator setup to create executable Scala code is also defined. [Physical_Quantities] title = A Sound Type System for Physical Quantities, Units, and Measurements author = Simon Foster , Burkhart Wolff topic = Mathematics/Physics, Computer science/Programming languages/Type systems date = 2020-10-20 notify = simon.foster@york.ac.uk, wolff@lri.fr abstract = The present Isabelle theory builds a formal model for both the International System of Quantities (ISQ) and the International System of Units (SI), which are both fundamental for physics and engineering. Both the ISQ and the SI are deeply integrated into Isabelle's type system. Quantities are parameterised by dimension types, which correspond to base vectors, and thus only quantities of the same dimension can be equated. Since the underlying "algebra of quantities" induces congruences on quantity and SI types, specific tactic support is developed to capture these. Our construction is validated by a test-set of known equivalences between both quantities and SI units. Moreover, the presented theory can be used for type-safe conversions between the SI system and others, like the British Imperial System (BIS). [Shadow_DOM] title = A Formal Model of the Document Object Model with Shadow Roots author = Achim D. Brucker , Michael Herzberg topic = Computer science/Data structures date = 2020-09-28 notify = adbrucker@0x5f.org, mail@michael-herzberg.de abstract = In this AFP entry, we extend our formalization of the core DOM with Shadow Roots. Shadow roots are a recent proposal of the web community to support a component-based development approach for client-side web applications. Shadow roots are a significant extension to the DOM standard and, as web standards are condemned to be backward compatible, such extensions often result in complex specification that may contain unwanted subtleties that can be detected by a formalization. Our Isabelle/HOL formalization is, in the sense of object-orientation, an extension of our formalization of the core DOM and enjoys the same basic properties, i.e., it is extensible, i.e., can be extended without the need of re-proving already proven properties and executable, i.e., we can generate executable code from our specification. We exploit the executability to show that our formalization complies to the official standard of the W3C, respectively, the WHATWG. [DOM_Components] title = A Formalization of Web Components author = Achim D. Brucker , Michael Herzberg topic = Computer science/Data structures date = 2020-09-28 notify = adbrucker@0x5f.org, mail@michael-herzberg.de abstract = While the DOM with shadow trees provide the technical basis for defining web components, the DOM standard neither defines the concept of web components nor specifies the safety properties that web components should guarantee. Consequently, the standard also does not discuss how or even if the methods for modifying the DOM respect component boundaries. In AFP entry, we present a formally verified model of web components and define safety properties which ensure that different web components can only interact with each other using well-defined interfaces. Moreover, our verification of the application programming interface (API) of the DOM revealed numerous invariants that implementations of the DOM API need to preserve to ensure the integrity of components. [Interpreter_Optimizations] title = Inline Caching and Unboxing Optimization for Interpreters author = Martin Desharnais topic = Computer science/Programming languages/Misc date = 2020-12-07 notify = martin.desharnais@unibw.de abstract = This Isabelle/HOL formalization builds on the VeriComp entry of the Archive of Formal Proofs to provide the following contributions:
  • an operational semantics for a realistic virtual machine (Std) for dynamically typed programming languages;
  • the formalization of an inline caching optimization (Inca), a proof of bisimulation with (Std), and a compilation function;
  • the formalization of an unboxing optimization (Ubx), a proof of bisimulation with (Inca), and a simple compilation function.
This formalization was described in the CPP 2021 paper Towards Efficient and Verified Virtual Machines for Dynamic Languages 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 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. diff --git a/metadata/topics b/metadata/topics --- a/metadata/topics +++ b/metadata/topics @@ -1,65 +1,66 @@ Computer science Artificial intelligence Automata and formal languages Algorithms Graph Distributed Concurrent Online Geometry Approximation Mathematical Optimization Quantum computing Concurrency Process calculi Data structures Functional programming Hardware Machine learning Networks Programming languages Language definitions Lambda calculi Type systems Logics Compiling Static analysis Transformations Misc Security Cryptography Semantics System description languages Logic Philosophical aspects General logic Classical propositional logic Classical first-order logic Decidability of theories Mechanization of proofs Lambda calculus Logics of knowledge and belief Temporal logic Modal logic Paraconsistent logics Computability Set theory Proof theory Rewriting Mathematics Order Algebra Analysis + Measure theory Probability theory Number theory Games and economics Geometry Topology Graph theory Combinatorics Category theory Physics Quantum information Misc Tools diff --git a/thys/Hahn_Jordan_Decomposition/Extended_Reals_Sums_Compl.thy b/thys/Hahn_Jordan_Decomposition/Extended_Reals_Sums_Compl.thy new file mode 100644 --- /dev/null +++ b/thys/Hahn_Jordan_Decomposition/Extended_Reals_Sums_Compl.thy @@ -0,0 +1,232 @@ +theory Extended_Reals_Sums_Compl imports + "HOL-Analysis.Analysis" +begin + +lemma real_ereal_leq: + fixes a::ereal and b::real + assumes "real_of_ereal a \ b" + and "a \ \" + shows "a \ ereal b" + by (metis (mono_tags, opaque_lifting) MInfty_eq_minfinity assms eq_iff ereal_eq_0(2) ereal_le_real_iff + ereal_less_eq(2) le_cases real_of_ereal.elims real_of_ereal.simps(1) zero_ereal_def) + +lemma ereal_sums_Pinfty: + fixes f::"nat \ ereal" + assumes "f sums \" + and "\n. \f n\ \ \" + shows "(\n. - f n) sums -\" +proof - + define rf where "rf = (\n. real_of_ereal (f n))" + have "\n. f n = ereal (rf n)" unfolding rf_def using assms by (simp add: ereal_real') + define g where "g = (\n. (\i \ {..< n}. rf i))" + define gm where "gm = (\n. (\i \ {..< n}. - rf i))" + have "\n. gm n = - g n" unfolding g_def gm_def by (simp add: sum_negf) + hence "\n. ereal (gm n) = (\i \ {..< n}.- f i)" using \\n. f n = ereal (rf n)\ + using gm_def by auto + have "(\n. ereal (g n)) \ \" using assms \\n. f n = ereal (rf n)\ unfolding sums_def g_def + by simp + have "\M. \N. \n\ N. (gm n) \ M" + proof + fix M + have "\N. \n\ N. ereal (-M) \ g n" using \g \ \\ Lim_PInfty by simp + from this obtain N where "\n\ N. ereal (-M) \ g n" by auto + hence "\n \ N. - (g n) \ M" by auto + hence "\n \ N. gm n \ M" using \\n. gm n = - g n\ by simp + thus "\N. \n \ N. gm n \ M" by auto + qed + hence "(\n. ereal (gm n)) \ -\" by (simp add: Lim_MInfty) + thus ?thesis using \\n. ereal (gm n) = (\i \ {..< n}.- f i)\ unfolding sums_def by simp +qed + +lemma ereal_sums_Minfty: + fixes f::"nat \ ereal" + assumes "f sums -\" + and "\n. \f n\ \ \" + shows "(\n. - f n) sums \" +proof - + define rf where "rf = (\n. real_of_ereal (f n))" + have "\n. f n = ereal (rf n)" unfolding rf_def using assms by (simp add: ereal_real') + define g where "g = (\n. (\i \ {..< n}. rf i))" + define gm where "gm = (\n. (\i \ {..< n}. - rf i))" + have "\n. gm n = - g n" unfolding g_def gm_def by (simp add: sum_negf) + hence "\n. ereal (gm n) = (\i \ {..< n}.- f i)" using \\n. f n = ereal (rf n)\ + using gm_def by auto + have "(\n. ereal (g n)) \ -\" using assms \\n. f n = ereal (rf n)\ unfolding sums_def g_def + by simp + have "\M. \N. \n\ N. M \ (gm n)" + proof + fix M + have "\N. \n\ N. g n \ ereal (-M)" using \g \ -\\ Lim_MInfty by simp + from this obtain N where "\n\ N. g n \ ereal (-M)" by auto + hence "\n \ N. M \ - (g n)" by auto + hence "\n \ N. M \ gm n" using \\n. gm n = - g n\ by simp + thus "\N. \n \ N. M \ gm n" by auto + qed + hence "(\n. ereal (gm n)) \ \" by (simp add: Lim_PInfty) + thus ?thesis using \\n. ereal (gm n) = (\i \ {..< n}.- f i)\ unfolding sums_def by simp +qed + +lemma mem_sums_Pinfty: + assumes "((f i)::ereal) = \" + shows "f sums \" +proof - + define g where "g = (\n. (\i \ {..< n}. f i))" + have ginf: "\ j \ Suc i. g j = \" + proof (intro allI impI) + fix j + assume "Suc i \ j" + hence "i < j" by simp + hence "i \ {..< j}" by auto + thus "g j = \" unfolding g_def using sum_Pinfty[of f "{..< j}"] assms by blast + qed + have "\M. \N. \n\ N. M \ (g n)" + proof + fix M + show "\N. \n\ N. M \ g n" using ginf by force + qed + hence "g \ \" by (simp add: Lim_PInfty) + thus ?thesis unfolding sums_def g_def by simp +qed + +lemma sum_Minfty: + fixes f :: "nat \ ereal" + shows "\i. finite P \ i \ P \ f i = - \ \ \ \ range f \ sum f P = -\" +proof - + fix i + assume "finite P" + and "i \ P" + and "f i = -\" + and "\ \ range f" + thus "sum f P = -\" + proof induct + case empty + then show ?case by simp + next + case (insert x F) + then show ?case + by (metis ereal_plus_eq_MInfty insert_iff rangeI sum.insert sum_Pinfty) + qed +qed + +lemma mem_sums_Minfty: + assumes "((f i)::ereal) = -\" + and "\ \ range f" + shows "f sums -\" +proof - + define g where "g = (\n. (\i \ {..< n}. f i))" + have ginf: "\ j \ Suc i. g j = -\" + proof (intro allI impI) + fix j + assume "Suc i \ j" + hence "i < j" by simp + hence "i \ {..< j}" by auto + thus "g j = -\" unfolding g_def using sum_Minfty[of "{..< j}"] assms by simp + qed + have "\M. \N. \n\ N. (g n) \ M" + proof + fix M + show "\N. \n\ N. g n \ M" using ginf by force + qed + hence "g \ -\" by (simp add: Lim_MInfty) + thus ?thesis unfolding sums_def g_def by simp +qed + +lemma ereal_sums_not_infty: + assumes "f sums (a::ereal)" + and "\a\ \ \" + shows "\n. \f n\ \ \" +proof (rule ccontr) + fix n + assume "\\f n\ \ \" + hence "\f n\ = \" by simp + show False + proof (cases "f n = \") + case True + hence "f sums \" using mem_sums_Pinfty by simp + thus False using assms sums_unique2 by force + next + case False + hence "f n = -\" using \\f n\ = \\ by blast + show False + proof (cases "\i. f i = \") + case True + from this obtain i where "f i = \" by auto + hence "f sums \" using mem_sums_Pinfty by simp + thus False using assms sums_unique2 by force + next + case False + hence "\i. f i \ \" by simp + hence "f sums -\" using mem_sums_Minfty \f n = -\\ + by (metis MInfty_eq_minfinity image_iff) + thus False using assms sums_unique2 by force + qed + qed +qed + +lemma ereal_sums_not_infty_minus: + assumes "f sums (a::ereal)" + and "\a\ \ \" + shows "(\n. - f n) sums -a" +proof - + have "\n. \f n\ \ \" using assms ereal_sums_not_infty by simp + define g where "g = (\n. real_of_ereal (f n))" + have "\n. f n = ereal (g n)" using \\n. \f n\ \ \\ by (simp add: ereal_real' g_def) + hence "\n. - f n = ereal (-g n)" by simp + have "\r. a = ereal (r)" using assms by auto + from this obtain r where "a = ereal r" by auto + hence "f sums (ereal r)" using assms by simp + hence "(\n. ereal (g n)) sums (ereal r)" using \\n. f n = ereal (g n)\ + sums_cong[of f "\n. ereal (g n)"] by simp + hence "g sums r" by (simp add: sums_ereal) + hence "(\n. -g n) sums -r" using sums_minus[of g] by simp + hence "(\n. ereal (- g n)) sums ereal (-r)" by (simp add: sums_ereal) + hence "(\n. - f n) sums (ereal (-r))" using \\n. - f n = ereal (-g n)\ + sums_cong[of f "\n. ereal (g n)"] by simp + thus ?thesis using \a = ereal r\ by simp +qed + +lemma ereal_sums_minus: + fixes f::"nat \ ereal" + assumes "f sums a" + and "\n. \f n\ \ \" + shows "(\n. - f n) sums -a" +proof (cases "\a\ = \") + case False + thus ?thesis using assms ereal_sums_not_infty_minus by simp +next + case True + hence "a = \ \ a = - \" by auto + thus ?thesis using assms ereal_sums_Pinfty ereal_sums_Minfty by auto +qed + +lemma sums_minus': + fixes f::"nat \ ereal" + assumes "-\ \ range f \ \ \ range f" + and "f sums a" + shows "(\n. - f n) sums (- a)" +proof (cases "\n. \f n\ \ \") + case True + thus ?thesis using ereal_sums_minus assms by simp +next + case False + have "\n. \f n\ = \" using False by simp + from this obtain n where "\f n\ = \" by meson + show ?thesis + proof (cases "\ \ range f") + case True + hence "\j. f j = \" by (metis image_iff) + from this obtain j where "f j = \" by auto + hence "a = \" using mem_sums_Pinfty assms(2) sums_unique2 by blast + moreover have "-\ \ range f" using assms True by simp + ultimately show ?thesis using mem_sums_Minfty[of "\n. - f n"] assms \f j = \\ + using ereal_uminus_eq_reorder by fastforce + next + case False + hence "f n = -\" using \\f n\ = \\ by (metis ereal_infinity_cases range_eqI) + hence "a = -\" using mem_sums_Minfty False sums_unique2 assms(2) by blast + thus ?thesis using mem_sums_Pinfty[of "\n. - f n"] assms + by (metis MInfty_eq_minfinity \f n = - \\ ereal_uminus_uminus uminus_ereal.simps(3)) + qed +qed + +end \ No newline at end of file diff --git a/thys/Hahn_Jordan_Decomposition/Hahn_Jordan_Decomposition.thy b/thys/Hahn_Jordan_Decomposition/Hahn_Jordan_Decomposition.thy new file mode 100644 --- /dev/null +++ b/thys/Hahn_Jordan_Decomposition/Hahn_Jordan_Decomposition.thy @@ -0,0 +1,2176 @@ +section \Signed measures\ + +text \In this section we define signed measures. These are generalizations of measures that can also +take negative values but cannot contain both $\infty$ and $-\infty$ in their range.\ + +subsection \Basic definitions\ +theory Hahn_Jordan_Decomposition imports + "HOL-Probability.Probability" + Hahn_Jordan_Prelims +begin + +definition signed_measure::"'a measure \ ('a set \ ereal) \ bool" where + "signed_measure M \ \ \ {} = 0 \ (-\ \ range \ \ \ \ range \) \ + (\A. range A \ sets M \ disjoint_family A \ \ (range A) \ sets M \ + (\i. \ (A i)) sums \ (\ (range A))) \ + (\A. range A \ sets M \ disjoint_family A \ \ (range A) \ sets M \ + \\ (\ (range A))\ < \ \ summable (\i. real_of_ereal \\ (A i)\))" + +lemma signed_measure_empty: + assumes "signed_measure M \" + shows "\ {} = 0" using assms unfolding signed_measure_def by simp + +lemma signed_measure_sums: + assumes "signed_measure M \" + and "range A \ M" + and "disjoint_family A" + and "\ (range A) \ sets M" + shows "(\i. \ (A i)) sums \ (\ (range A))" + using assms unfolding signed_measure_def by simp + +lemma signed_measure_summable: + assumes "signed_measure M \" + and "range A \ M" + and "disjoint_family A" + and "\ (range A) \ sets M" + and "\\ (\ (range A))\ < \" + shows "summable (\i. real_of_ereal \\ (A i)\)" + using assms unfolding signed_measure_def by simp + +lemma signed_measure_inf_sum: + assumes "signed_measure M \" + and "range A \ M" + and "disjoint_family A" + and "\ (range A) \ sets M" + shows "(\i. \ (A i)) = \ (\ (range A))" using sums_unique assms + signed_measure_sums by (metis) + +lemma signed_measure_abs_convergent: + assumes "signed_measure M \" + and "range A \ sets M" + and "disjoint_family A" + and "\ (range A) \ sets M" + and "\\ (\ (range A))\ < \" + shows "summable (\i. real_of_ereal \\ (A i)\)" using assms + unfolding signed_measure_def by simp + +lemma signed_measure_additive: + assumes "signed_measure M \" + shows "additive M \" +proof (auto simp add: additive_def) + fix x y + assume x: "x \ M" and y: "y \ M" and "x \ y = {}" + hence "disjoint_family (binaryset x y)" + by (auto simp add: disjoint_family_on_def binaryset_def) + have "(\i. \ ((binaryset x y) i)) sums (\ x + \ y)" using binaryset_sums + signed_measure_empty[of M \] assms by simp + have "range (binaryset x y) = {x, y, {}}" using range_binaryset_eq by simp + moreover have "{x, y, {}} \ M" using x y by auto + moreover have "x\y \ sets M" using x y by simp + moreover have "(\ (range (binaryset x y))) = x\ y" + by (simp add: calculation(1)) + ultimately have "(\i. \ ((binaryset x y) i)) sums \ (x \ y)" using assms x y + signed_measure_empty[of M \] signed_measure_sums[of M \] + \disjoint_family (binaryset x y)\ by (metis) + then show "\ (x \ y) = \ x + \ y" + using \(\i. \ ((binaryset x y) i)) sums (\ x + \ y)\ sums_unique2 by force +qed + +lemma signed_measure_add: + assumes "signed_measure M \" + and "a\ sets M" + and "b\ sets M" + and "a\ b = {}" + shows "\ (a\ b) = \ a + \ b" using additiveD[OF signed_measure_additive] + assms by auto + +lemma signed_measure_disj_sum: + shows "finite I \ signed_measure M \ \ disjoint_family_on A I \ + (\i. i \ I \ A i \ sets M) \ \ (\ i\ I. A i) = (\ i\ I. \ (A i))" +proof (induct rule:finite_induct) + case empty + then show ?case unfolding signed_measure_def by simp +next + case (insert x F) + have "\ (\ (A ` insert x F)) = \ ((\ (A `F)) \ A x)" + by (simp add: Un_commute) + also have "... = \ (\ (A `F)) + \ (A x)" + proof - + have "(\ (A `F)) \ (A x) = {}" using insert + by (metis disjoint_family_on_insert inf_commute) + moreover have "\ (A `F) \ sets M" using insert by auto + moreover have "A x \ sets M" using insert by simp + ultimately show ?thesis by (meson insert.prems(1) signed_measure_add) + qed + also have "... = (\ i\ F. \ (A i)) + \ (A x)" using insert + by (metis disjoint_family_on_insert insert_iff) + also have "... = (\i\insert x F. \ (A i))" + by (simp add: add.commute insert.hyps(1) insert.hyps(2)) + finally show ?case . +qed + +lemma pos_signed_measure_count_additive: + assumes "signed_measure M \" + and "\ E \ sets M. 0 \ \ E" + shows "countably_additive (sets M) (\A. e2ennreal (\ A))" + unfolding countably_additive_def +proof (intro allI impI) + fix A::"nat \ 'a set" + assume "range A \ sets M" + and "disjoint_family A" + and "\ (range A) \ sets M" note Aprops = this + have eq: "\i. \ (A i) = enn2ereal (e2ennreal (\ (A i)))" + using assms enn2ereal_e2ennreal Aprops by simp + have "(\n. \i\n. \ (A i)) \ \ (\ (range A))" using + sums_def_le[of "\i. \ (A i)" "\ (\ (range A))"] assms + signed_measure_sums[of M] Aprops by simp + hence "((\n. e2ennreal (\i\n. \ (A i))) \ + e2ennreal (\ (\ (range A)))) sequentially" + using tendsto_e2ennrealI[of "(\n. \i\n. \ (A i))" "\ (\ (range A))"] + by simp + moreover have "\n. e2ennreal (\i\n. \ (A i)) = (\i\n. e2ennreal (\ (A i)))" + using e2ennreal_finite_sum by (metis enn2ereal_nonneg eq finite_atMost) + ultimately have "((\n. (\i\n. e2ennreal (\ (A i)))) \ + e2ennreal (\ (\ (range A)))) sequentially" by simp + hence "(\i. e2ennreal (\ (A i))) sums e2ennreal (\ (\ (range A)))" + using sums_def_le[of "\i. e2ennreal (\ (A i))" "e2ennreal (\ (\ (range A)))"] + by simp + thus "(\i. e2ennreal (\ (A i))) = e2ennreal (\ (\ (range A)))" + using sums_unique assms by (metis) +qed + +lemma signed_measure_minus: + assumes "signed_measure M \" + shows "signed_measure M (\A. - \ A)" unfolding signed_measure_def +proof (intro conjI) + show "- \ {} = 0" using assms unfolding signed_measure_def by simp + show "- \ \ range (\A. - \ A) \ \ \ range (\A. - \ A)" + proof (cases "\ \ range \") + case True + hence "-\ \ range \" using assms unfolding signed_measure_def by simp + hence "\ \ range (\A. - \ A)" using ereal_uminus_eq_reorder by blast + thus "- \ \ range (\A. - \ A) \ \ \ range (\A. - \ A)" by simp + next + case False + hence "-\ \ range (\A. - \ A)" using ereal_uminus_eq_reorder + by (simp add: image_iff) + thus "- \ \ range (\A. - \ A) \ \ \ range (\A. - \ A)" by simp + qed + show "\A. range A \ sets M \ disjoint_family A \ \ (range A) \ sets M \ + \- \ (\ (range A))\ < \ \ summable (\i. real_of_ereal \- \ (A i)\)" + proof (intro allI impI) + fix A::"nat \ 'a set" + assume "range A \ sets M" and "disjoint_family A" and "\ (range A) \ sets M" + and "\- \ (\ (range A))\ < \" + thus "summable (\i. real_of_ereal \- \ (A i)\)" using assms + unfolding signed_measure_def by simp + qed + show "\A. range A \ sets M \ disjoint_family A \ \ (range A) \ sets M \ + (\i. - \ (A i)) sums - \ (\ (range A))" + proof - + { + fix A::"nat \ 'a set" + assume "range A \ sets M" and "disjoint_family A" and + "\ (range A) \ sets M" note Aprops = this + have "- \ \ range (\i. \ (A i)) \ \ \ range (\i. \ (A i))" + proof - + have "range (\i. \ (A i)) \ range \" by auto + thus ?thesis using assms unfolding signed_measure_def by auto + qed + moreover have "(\i. \ (A i)) sums \ (\ (range A))" + using signed_measure_sums[of M] Aprops assms by simp + ultimately have "(\i. - \ (A i)) sums - \ (\ (range A))" + using sums_minus'[of "\i. \ (A i)"] by simp + } + thus ?thesis by auto + qed +qed + +locale near_finite_function = + fixes \:: "'b set \ ereal" + assumes inf_range: "- \ \ range \ \ \ \ range \" + +lemma (in near_finite_function) finite_subset: + assumes "\\ E\ < \" + and "A\ E" + and "\ E = \ A + \ (E - A)" + shows "\\ A\ < \" +proof (cases "\ \ range \") + case False + show ?thesis + proof (cases "0 < \ A") + case True + hence "\\ A\ = \ A" by simp + also have "... < \" using False by (metis ereal_less_PInfty rangeI) + finally show ?thesis . + next + case False + hence "\\ A\ = -\ A" using not_less_iff_gr_or_eq by fastforce + also have "... = \ (E - A) - \ E" + proof - + have "\ E = \ A + \ (E - A)" using assms by simp + hence "\ E - \ A = \ (E - A)" + by (metis abs_ereal_uminus assms(1) calculation ereal_diff_add_inverse + ereal_infty_less(2) ereal_minus(5) ereal_minus_less_iff + ereal_minus_less_minus ereal_uminus_uminus less_ereal.simps(2) + minus_ereal_def plus_ereal.simps(3)) + thus ?thesis using assms(1) ereal_add_uminus_conv_diff ereal_eq_minus + by auto + qed + also have "... \ \ (E - A) + \\ E\" + by (metis \- \ A = \ (E - A) - \ E\ abs_ereal_less0 abs_ereal_pos + ereal_diff_le_self ereal_le_add_mono1 less_eq_ereal_def + minus_ereal_def not_le_imp_less) + also have "... < \" using assms \\ \ range \\ + by (metis UNIV_I ereal_less_PInfty ereal_plus_eq_PInfty image_eqI) + finally show ?thesis . + qed +next + case True + hence "-\ \ range \" using inf_range by simp + hence "-\ < \ A" by (metis ereal_infty_less(2) rangeI) + show ?thesis + proof (cases "\ A < 0") + case True + hence "\\ A\ = -\ A" using not_less_iff_gr_or_eq by fastforce + also have "... < \" using \-\ < \ A\ using ereal_uminus_less_reorder + by blast + finally show ?thesis . + next + case False + hence "\\ A\ = \ A" by simp + also have "... = \ E - \ (E - A)" + proof - + have "\ E = \ A + \ (E - A)" using assms by simp + thus "\ A = \ E - \ (E - A)" by (metis add.right_neutral assms(1) + add_diff_eq_ereal calculation ereal_diff_add_eq_diff_diff_swap + ereal_diff_add_inverse ereal_infty_less(1) ereal_plus_eq_PInfty + ereal_x_minus_x) + qed + also have "... \ \\ E\ - \ (E - A)" + by (metis \\\ A\ = \ A\ \\ A = \ E - \ (E - A)\ abs_ereal_ge0 + abs_ereal_pos abs_ereal_uminus antisym_conv ereal_0_le_uminus_iff + ereal_abs_diff ereal_diff_le_mono_left ereal_diff_le_self le_cases + less_eq_ereal_def minus_ereal_def) + also have "... < \" + proof - + have "-\ < \ (E - A)" using \-\ \ range \\ + by (metis ereal_infty_less(2) rangeI) + hence "- \ (E - A) < \" using ereal_uminus_less_reorder by blast + thus ?thesis using assms by (simp add: ereal_minus_eq_PInfty_iff + ereal_uminus_eq_reorder) + qed + finally show ?thesis . + qed +qed + +locale signed_measure_space= + fixes M::"'a measure" and \ + assumes sgn_meas: "signed_measure M \" + +sublocale signed_measure_space \ near_finite_function +proof (unfold_locales) + show "- \ \ range \ \ \ \ range \" using sgn_meas + unfolding signed_measure_def by simp +qed + +context signed_measure_space +begin +lemma signed_measure_finite_subset: + assumes "E \ sets M" + and "\\ E\ < \" + and "A\ sets M" + and "A\ E" + shows "\\ A\ < \" +proof (rule finite_subset) + show "\\ E\ < \" "A\ E" using assms by auto + show "\ E = \ A + \ (E - A)" using assms + sgn_meas signed_measure_add[of M \ A "E - A"] + by (metis Diff_disjoint Diff_partition sets.Diff) +qed + +lemma measure_space_e2ennreal : + assumes "measure_space (space M) (sets M) m \ (\E \ sets M. m E < \) \ + (\E \ sets M. m E \ 0)" + shows "\E \ sets M. e2ennreal (m E) < \" +proof + fix E + assume "E \ sets M" + show "e2ennreal (m E) < \" + proof - + have "m E < \" using assms \E \ sets M\ + by blast + then have "e2ennreal (m E) < \" using e2ennreal_less_top + using \m E < \\ by auto + thus ?thesis by simp + qed +qed + +subsection \Positive and negative subsets\ + +text \The Hahn decomposition theorem is based on the notions of positive and negative measurable +sets. A measurable set is positive (resp. negative) if all its measurable subsets have a positive +(resp. negative) measure by $\mu$. The decomposition theorem states that any measure space for +a signed measure can be decomposed into a positive and a negative measurable set.\ + +definition pos_meas_set where + "pos_meas_set E \ E \ sets M \ (\A \ sets M. A \ E \ 0 \ \ A)" + +definition neg_meas_set where + "neg_meas_set E \ E \ sets M \ (\A \ sets M. A \ E \ \ A \ 0)" + +lemma pos_meas_setI: + assumes "E \ sets M" + and "\A. A \ sets M \ A \ E \ 0 \ \ A" + shows "pos_meas_set E" unfolding pos_meas_set_def using assms by simp + +lemma pos_meas_setD1 : + assumes "pos_meas_set E" + shows "E \ sets M" + using assms unfolding pos_meas_set_def + by simp + +lemma neg_meas_setD1 : + assumes "neg_meas_set E" + shows "E \ sets M" using assms unfolding neg_meas_set_def by simp + +lemma neg_meas_setI: + assumes "E \ sets M" + and "\A. A \ sets M \ A \ E \ \ A \ 0" + shows "neg_meas_set E" unfolding neg_meas_set_def using assms by simp + +lemma pos_meas_self: + assumes "pos_meas_set E" + shows "0 \ \ E" using assms unfolding pos_meas_set_def by simp + +lemma empty_pos_meas_set: + shows "pos_meas_set {}" + by (metis bot.extremum_uniqueI eq_iff pos_meas_set_def sets.empty_sets + sgn_meas signed_measure_empty) + +lemma empty_neg_meas_set: + shows "neg_meas_set {}" + by (metis neg_meas_set_def order_refl sets.empty_sets sgn_meas + signed_measure_empty subset_empty) + +lemma pos_measure_meas: + assumes "pos_meas_set E" + and "A\ E" + and "A\ sets M" + shows "0 \ \ A" using assms unfolding pos_meas_set_def by simp + +lemma pos_meas_subset: + assumes "pos_meas_set A" + and "B\ A" + and "B\ sets M" + shows "pos_meas_set B" using assms pos_meas_set_def by auto + +lemma neg_meas_subset: + assumes "neg_meas_set A" + and "B\ A" + and "B\ sets M" + shows "neg_meas_set B" using assms neg_meas_set_def by auto + +lemma pos_meas_set_Union: + assumes "\(i::nat). pos_meas_set (A i)" + and "\i. A i \ sets M" + and "\\ (\ i. A i)\ < \" + shows "pos_meas_set (\ i. A i)" +proof (rule pos_meas_setI) + show "\ (range A) \ sets M" using sigma_algebra.countable_UN assms by simp + obtain B where "disjoint_family B" and "(\(i::nat). B i) = (\(i::nat). A i)" + and "\i. B i \ sets M" and "\i. B i \ A i" using disj_Union2 assms by auto + fix C + assume "C \ sets M" and "C\ (\ i. A i)" + hence "C = C \ (\ i. A i)" by auto + also have "... = C \ (\ i. B i)" using \(\i. B i) = (\i. A i)\ by simp + also have "... = (\ i. C \ B i)" by auto + finally have "C = (\ i. C \ B i)" . + hence "\ C = \ (\ i. C \ B i)" by simp + also have "... = (\i. \ (C \ (B i)))" + proof (rule signed_measure_inf_sum[symmetric]) + show "signed_measure M \" using sgn_meas by simp + show "disjoint_family (\i. C \ B i)" using \disjoint_family B\ + by (meson Int_iff disjoint_family_subset subset_iff) + show "range (\i. C \ B i) \ sets M" using \C\ sets M\ \\i. B i \ sets M\ + by auto + show "(\i. C \ B i) \ sets M" using \C = (\ i. C \ B i)\ \C\ sets M\ + by simp + qed + also have "... \ 0" + proof (rule suminf_nonneg) + show "\n. 0 \ \ (C \ B n)" + proof - + fix n + have "C\ B n \ A n" using \\i. B i \ A i\ by auto + moreover have "C \ B n \ sets M" using \C\ sets M\ \\i. B i \ sets M\ + by simp + ultimately show "0 \ \ (C \ B n)" using assms pos_measure_meas[of "A n"] + by simp + qed + have "summable (\i. real_of_ereal (\ (C \ B i)))" + proof (rule summable_norm_cancel) + have "\n. norm (real_of_ereal (\ (C \ B n))) = + real_of_ereal \\ (C \ B n)\" by simp + moreover have "summable (\i. real_of_ereal \\ (C \ B i)\)" + proof (rule signed_measure_abs_convergent) + show "signed_measure M \" using sgn_meas by simp + show "range (\i. C \ B i) \ sets M" using \C\ sets M\ + \\i. B i \ sets M\ by auto + show "disjoint_family (\i. C \ B i)" using \disjoint_family B\ + by (meson Int_iff disjoint_family_subset subset_iff) + show "(\i. C \ B i) \ sets M" using \C = (\ i. C \ B i)\ \C\ sets M\ + by simp + have "\\ C\ < \" + proof (rule signed_measure_finite_subset) + show "(\ i. A i) \ sets M" using assms by simp + show "\\ (\ (range A))\ < \" using assms by simp + show "C \ sets M" using \C \ sets M\ . + show "C \ \ (range A)" using \C \ \ (range A) \ . + qed + thus "\\ (\i. C \ B i)\ < \" using \C = (\ i. C \ B i)\ by simp + qed + ultimately show "summable (\n. norm (real_of_ereal (\ (C \ B n))))" + by auto + qed + thus "summable (\i. \ (C \ B i))" by (simp add: \\n. 0 \ \ (C \ B n)\ + summable_ereal_pos) + qed + finally show "0 \ \ C" . +qed + +lemma pos_meas_set_pos_lim: + assumes "\(i::nat). pos_meas_set (A i)" + and "\i. A i \ sets M" + shows "0 \ \ (\ i. A i)" +proof - + obtain B where "disjoint_family B" and "(\(i::nat). B i) = (\(i::nat). A i)" + and "\i. B i \ sets M" and "\i. B i \ A i" using disj_Union2 assms by auto + note Bprops = this + have sums: "(\n. \ (B n)) sums \ (\i. B i)" + proof (rule signed_measure_sums) + show "signed_measure M \" using sgn_meas . + show "range B \ sets M" using Bprops by auto + show "disjoint_family B" using Bprops by simp + show "\ (range B) \ sets M" using Bprops by blast + qed + hence "summable (\n. \ (B n))" using sums_summable[of "\n. \ (B n)"] by simp + hence "suminf (\n. \ (B n)) = \ (\i. B i)" using sums sums_iff by auto + thus ?thesis using suminf_nonneg + by (metis Bprops(2) Bprops(3) Bprops(4) \summable (\n. \ (B n))\ assms(1) + pos_measure_meas) +qed + +lemma pos_meas_disj_union: + assumes "pos_meas_set A" + and "pos_meas_set B" + and "A\ B = {}" + shows "pos_meas_set (A \ B)" unfolding pos_meas_set_def +proof (intro conjI ballI impI) + show "A\ B \ sets M" + by (metis assms(1) assms(2) pos_meas_set_def sets.Un) +next + fix C + assume "C\ sets M" and "C\ A\ B" + define DA where "DA = C\ A" + define DB where "DB = C\ B" + have "DA\ sets M" using DA_def \C \ sets M\ assms(1) pos_meas_set_def + by blast + have "DB\ sets M" using DB_def \C \ sets M\ assms(2) pos_meas_set_def + by blast + have "DA \ DB = {}" unfolding DA_def DB_def using assms by auto + have "C = DA \ DB" unfolding DA_def DB_def using \C\ A\ B\ by auto + have "0 \ \ DB" using assms unfolding DB_def pos_meas_set_def + by (metis DB_def Int_lower2\DB \ sets M\) + also have "... \ \ DA + \ DB" using assms unfolding pos_meas_set_def + by (metis DA_def Diff_Diff_Int Diff_subset Int_commute \DA \ sets M\ + ereal_le_add_self2) + also have "... = \ C" using signed_measure_add sgn_meas \DA \ sets M\ + \DB \ sets M\ \DA \ DB = {}\ \C = DA \ DB\ by metis + finally show "0 \ \ C" . +qed + +lemma pos_meas_set_union: + assumes "pos_meas_set A" + and "pos_meas_set B" + shows "pos_meas_set (A \ B)" +proof - + define C where "C = B - A" + have "A\ C = A\ B" unfolding C_def by auto + moreover have "pos_meas_set (A\ C)" + proof (rule pos_meas_disj_union) + show "pos_meas_set C" unfolding C_def + by (meson Diff_subset assms(1) assms(2) sets.Diff + signed_measure_space.pos_meas_set_def + signed_measure_space.pos_meas_subset signed_measure_space_axioms) + show "pos_meas_set A" using assms by simp + show "A \ C = {}" unfolding C_def by auto + qed + ultimately show ?thesis by simp +qed + +lemma neg_meas_disj_union: + assumes "neg_meas_set A" + and "neg_meas_set B" + and "A\ B = {}" + shows "neg_meas_set (A \ B)" unfolding neg_meas_set_def +proof (intro conjI ballI impI) + show "A\ B \ sets M" + by (metis assms(1) assms(2) neg_meas_set_def sets.Un) +next + fix C + assume "C\ sets M" and "C\ A\ B" + define DA where "DA = C\ A" + define DB where "DB = C\ B" + have "DA\ sets M" using DA_def \C \ sets M\ assms(1) neg_meas_set_def + by blast + have "DB\ sets M" using DB_def \C \ sets M\ assms(2) neg_meas_set_def + by blast + have "DA \ DB = {}" unfolding DA_def DB_def using assms by auto + have "C = DA \ DB" unfolding DA_def DB_def using \C\ A\ B\ by auto + have "\ C = \ DA + \ DB" using signed_measure_add sgn_meas \DA \ sets M\ + \DB \ sets M\ \DA \ DB = {}\ \C = DA \ DB\ by metis + also have "... \ \ DB" using assms unfolding neg_meas_set_def + by (metis DA_def Int_lower2 \DA \ sets M\ add_decreasing dual_order.refl) + also have "... \ 0" using assms unfolding DB_def neg_meas_set_def + by (metis DB_def Int_lower2\DB \ sets M\) + finally show "\ C \ 0" . +qed + +lemma neg_meas_set_union: + assumes "neg_meas_set A" + and "neg_meas_set B" + shows "neg_meas_set (A \ B)" +proof - + define C where "C = B - A" + have "A\ C = A\ B" unfolding C_def by auto + moreover have "neg_meas_set (A\ C)" + proof (rule neg_meas_disj_union) + show "neg_meas_set C" unfolding C_def + by (meson Diff_subset assms(1) assms(2) sets.Diff neg_meas_set_def + neg_meas_subset signed_measure_space_axioms) + show "neg_meas_set A" using assms by simp + show "A \ C = {}" unfolding C_def by auto + qed + ultimately show ?thesis by simp +qed + +lemma neg_meas_self : + assumes "neg_meas_set E" + shows "\ E \ 0" using assms unfolding neg_meas_set_def by simp + +lemma pos_meas_set_opp: + assumes "signed_measure_space.pos_meas_set M (\ A. - \ A) A" + shows "neg_meas_set A" +proof - + have m_meas_pos : "signed_measure M (\ A. - \ A)" + using assms signed_measure_space_def + by (simp add: sgn_meas signed_measure_minus) + thus ?thesis + by (metis assms ereal_0_le_uminus_iff neg_meas_setI + signed_measure_space.intro signed_measure_space.pos_meas_set_def) +qed + +lemma neg_meas_set_opp: + assumes "signed_measure_space.neg_meas_set M (\ A. - \ A) A" + shows "pos_meas_set A" +proof - + have m_meas_neg : "signed_measure M (\ A. - \ A)" + using assms signed_measure_space_def + by (simp add: sgn_meas signed_measure_minus) + thus ?thesis + by (metis assms ereal_uminus_le_0_iff m_meas_neg pos_meas_setI + signed_measure_space.intro signed_measure_space.neg_meas_set_def) +qed +end + +lemma signed_measure_inter: + assumes "signed_measure M \" + and "A \ sets M" + shows "signed_measure M (\E. \ (E \ A))" unfolding signed_measure_def +proof (intro conjI) + show "\ ({} \ A) = 0" using assms(1) signed_measure_empty by auto + show "- \ \ range (\E. \ (E \ A)) \ \ \ range (\E. \ (E \ A))" + proof (rule ccontr) + assume "\ (- \ \ range (\E. \ (E \ A)) \ \ \ range (\E. \ (E \ A)))" + hence "- \ \ range (\E. \ (E \ A)) \ \ \ range (\E. \ (E \ A))" by simp + hence "- \ \ range \ \ \ \ range \" by auto + thus False using assms unfolding signed_measure_def by simp + qed + show "\E. range E \ sets M \ disjoint_family E \ \ (range E) \ sets M \ + (\i. \ (E i \ A)) sums \ (\ (range E) \ A)" + proof (intro allI impI) + fix E::"nat \ 'a set" + assume "range E \ sets M" and "disjoint_family E" and "\ (range E) \ sets M" + note Eprops = this + define F where "F = (\i. E i \ A)" + have "(\i. \ (F i)) sums \ (\ (range F))" + proof (rule signed_measure_sums) + show "signed_measure M \" using assms by simp + show "range F \ sets M" using Eprops F_def assms by blast + show "disjoint_family F" using Eprops F_def assms + by (metis disjoint_family_subset inf.absorb_iff2 inf_commute + inf_right_idem) + show "\ (range F) \ sets M" using Eprops assms unfolding F_def + by (simp add: Eprops assms countable_Un_Int(1) sets.Int) + qed + moreover have "\ (range F) = A \ \ (range E)" unfolding F_def by auto + ultimately show "(\i. \ (E i \ A)) sums \ (\ (range E) \ A)" + unfolding F_def by simp + qed + show "\E. range E \ sets M \ + disjoint_family E \ + \ (range E) \ sets M \ \\ (\ (range E) \ A)\ < \ \ + summable (\i. real_of_ereal \\ (E i \ A)\)" + proof (intro allI impI) + fix E::"nat \ 'a set" + assume "range E \ sets M" and "disjoint_family E" and + "\ (range E) \ sets M" and "\\ (\ (range E) \ A)\ < \" note Eprops = this + show "summable (\i. real_of_ereal \\ (E i \ A)\)" + proof (rule signed_measure_summable) + show "signed_measure M \" using assms by simp + show "range (\i. E i \ A) \ sets M" using Eprops assms by blast + show "disjoint_family (\i. E i \ A)" using Eprops assms + disjoint_family_subset inf.absorb_iff2 inf_commute inf_right_idem + by fastforce + show "(\i. E i \ A) \ sets M" using Eprops assms + by (simp add: Eprops assms countable_Un_Int(1) sets.Int) + show "\\ (\i. E i \ A)\ < \" using Eprops by auto + qed + qed +qed + +context signed_measure_space +begin +lemma pos_signed_to_meas_space : + assumes "pos_meas_set M1" + and "m1 = (\A. \ (A \ M1))" + shows "measure_space (space M) (sets M) m1" unfolding measure_space_def +proof (intro conjI) + show "sigma_algebra (space M) (sets M)" + by (simp add: sets.sigma_algebra_axioms) + show "positive (sets M) m1" using assms unfolding pos_meas_set_def + by (metis Sigma_Algebra.positive_def Un_Int_eq(4) + e2ennreal_neg neg_meas_self sup_bot_right empty_neg_meas_set) + show "countably_additive (sets M) m1" + proof (rule pos_signed_measure_count_additive) + show "\E\sets M. 0 \ m1 E" by (metis assms inf.cobounded2 + pos_meas_set_def sets.Int) + show "signed_measure M m1" using assms pos_meas_set_def + signed_measure_inter[of M \ M1] sgn_meas by blast + qed +qed + +lemma neg_signed_to_meas_space : + assumes "neg_meas_set M2" + and "m2 = (\A. -\ (A \ M2))" + shows "measure_space (space M) (sets M) m2" unfolding measure_space_def +proof (intro conjI) + show "sigma_algebra (space M) (sets M)" + by (simp add: sets.sigma_algebra_axioms) + show "positive (sets M) m2" using assms unfolding neg_meas_set_def + by (metis Sigma_Algebra.positive_def e2ennreal_neg ereal_uminus_zero + inf.absorb_iff2 inf.orderE inf_bot_right neg_meas_self pos_meas_self + empty_neg_meas_set empty_pos_meas_set) + show "countably_additive (sets M) m2" + proof (rule pos_signed_measure_count_additive) + show "\E\sets M. 0 \ m2 E" + by (metis assms ereal_uminus_eq_reorder ereal_uminus_le_0_iff + inf.cobounded2 neg_meas_set_def sets.Int) + have "signed_measure M (\A. \ (A \ M2))" using assms neg_meas_set_def + signed_measure_inter[of M \ M2] sgn_meas by blast + thus "signed_measure M m2" using signed_measure_minus assms by simp + qed +qed + +lemma pos_part_meas_nul_neg_set : + assumes "pos_meas_set M1" + and "neg_meas_set M2" + and "m1 = (\A. \ (A \ M1))" + and "E \ sets M" + and "E \ M2" + shows "m1 E = 0" +proof - + have "m1 E \ 0" using assms unfolding pos_meas_set_def + by (simp add: \E \ sets M\ sets.Int) + have "\ E \ 0" using \E \ M2\ assms unfolding neg_meas_set_def + using \E \ sets M\ by blast + then have "m1 E \ 0" using \\ E \ 0\ assms + by (metis Int_Un_eq(1) Un_subset_iff \E \ sets M\ \E \ M2\ pos_meas_setD1 + sets.Int signed_measure_space.neg_meas_set_def + signed_measure_space_axioms) + thus "m1 E = 0" using \m1 E \ 0\ \m1 E \ 0\ by auto +qed + +lemma neg_part_meas_nul_pos_set : + assumes "pos_meas_set M1" + and "neg_meas_set M2" + and "m2 = (\A. -\ (A \ M2))" + and "E \ sets M" + and "E \ M1" + shows "m2 E = 0" +proof - + have "m2 E \ 0" using assms unfolding neg_meas_set_def + by (simp add: \E \ sets M\ sets.Int) + have "\ E \ 0" using assms unfolding pos_meas_set_def by blast + then have "m2 E \ 0" using \\ E \ 0\ assms + by (metis \E \ sets M\ \E \ M1\ ereal_0_le_uminus_iff ereal_uminus_uminus + inf_sup_ord(1) neg_meas_setD1 pos_meas_set_def pos_meas_subset + sets.Int) + thus "m2 E = 0" using \m2 E \ 0\ \m2 E \ 0\ by auto +qed + +definition pos_sets where + "pos_sets = {A. A \ sets M \ pos_meas_set A}" + +definition pos_img where + "pos_img = {\ A|A. A\ pos_sets}" + +subsection \Essential uniqueness\ + +text \In this part, under the assumption that a measure space for a signed measure admits a +decomposition into a positive and a negative set, we prove that this decomposition is +essentially unique; in other words, that if two such decompositions $(P,N)$ and $(X,Y)$ exist, +then any measurable subset of $(P\triangle X) \cup (N \triangle Y)$ has a null measure.\ + +definition hahn_space_decomp where + "hahn_space_decomp M1 M2 \ (pos_meas_set M1) \ (neg_meas_set M2) \ +(space M = M1 \ M2) \ (M1 \ M2 = {})" + +lemma pos_neg_null_set: + assumes "pos_meas_set A" + and "neg_meas_set A" + shows "\ A = 0" using assms pos_meas_self[of A] neg_meas_self[of A] by simp + +lemma pos_diff_neg_meas_set: + assumes "(pos_meas_set M1)" + and "(neg_meas_set N2)" + and "(space M = N1 \ N2)" + and "N1 \ sets M" + shows "neg_meas_set ((M1 - N1) \ space M)" using assms neg_meas_subset + by (metis Diff_subset_conv Int_lower2 pos_meas_setD1 sets.Diff + sets.Int_space_eq2) + +lemma neg_diff_pos_meas_set: + assumes "(neg_meas_set M2)" + and "(pos_meas_set N1)" + and "(space M = N1 \ N2)" + and "N2 \ sets M" + shows "pos_meas_set ((M2 - N2) \ space M)" +proof - + have "(M2 - N2) \ space M \ N1" using assms by auto + thus ?thesis using assms pos_meas_subset neg_meas_setD1 by blast +qed + +lemma pos_sym_diff_neg_meas_set: + assumes "hahn_space_decomp M1 M2" + and "hahn_space_decomp N1 N2" + shows "neg_meas_set ((sym_diff M1 N1) \ space M)" using assms + unfolding hahn_space_decomp_def + by (metis Int_Un_distrib2 neg_meas_set_union pos_meas_setD1 + pos_diff_neg_meas_set) + +lemma neg_sym_diff_pos_meas_set: + assumes "hahn_space_decomp M1 M2" + and "hahn_space_decomp N1 N2" + shows "pos_meas_set ((sym_diff M2 N2) \ space M)" using assms + neg_diff_pos_meas_set unfolding hahn_space_decomp_def + by (metis (no_types, lifting) Int_Un_distrib2 neg_meas_setD1 + pos_meas_set_union) + +lemma pos_meas_set_diff: + assumes "pos_meas_set A" + and "B\ sets M" + shows "pos_meas_set ((A - B) \ (space M))" using pos_meas_subset + by (metis Diff_subset assms(1) assms(2) pos_meas_setD1 sets.Diff + sets.Int_space_eq2) + +lemma pos_meas_set_sym_diff: + assumes "pos_meas_set A" + and "pos_meas_set B" + shows "pos_meas_set ((sym_diff A B) \ space M)" using pos_meas_set_diff + by (metis Int_Un_distrib2 assms(1) assms(2) pos_meas_setD1 + pos_meas_set_union) + +lemma neg_meas_set_diff: + assumes "neg_meas_set A" + and "B\ sets M" + shows "neg_meas_set ((A - B) \ (space M))" using neg_meas_subset + by (metis Diff_subset assms(1) assms(2) neg_meas_setD1 sets.Diff + sets.Int_space_eq2) + +lemma neg_meas_set_sym_diff: + assumes "neg_meas_set A" + and "neg_meas_set B" + shows "neg_meas_set ((sym_diff A B) \ space M)" using neg_meas_set_diff + by (metis Int_Un_distrib2 assms(1) assms(2) neg_meas_setD1 + neg_meas_set_union) + +lemma hahn_decomp_space_diff: + assumes "hahn_space_decomp M1 M2" + and "hahn_space_decomp N1 N2" + shows "pos_meas_set ((sym_diff M1 N1 \ sym_diff M2 N2) \ space M)" + "neg_meas_set ((sym_diff M1 N1 \ sym_diff M2 N2) \ space M)" +proof - + show "pos_meas_set ((sym_diff M1 N1 \ sym_diff M2 N2) \ space M)" + by (metis Int_Un_distrib2 assms(1) assms(2) hahn_space_decomp_def + neg_sym_diff_pos_meas_set pos_meas_set_sym_diff pos_meas_set_union) + show "neg_meas_set ((sym_diff M1 N1 \ sym_diff M2 N2) \ space M)" + by (metis Int_Un_distrib2 assms(1) assms(2) hahn_space_decomp_def + neg_meas_set_sym_diff neg_meas_set_union pos_sym_diff_neg_meas_set) +qed + +lemma hahn_decomp_ess_unique: + assumes "hahn_space_decomp M1 M2" + and "hahn_space_decomp N1 N2" + and "C \ sym_diff M1 N1 \ sym_diff M2 N2" + and "C\ sets M" + shows "\ C = 0" +proof - + have "C\ (sym_diff M1 N1 \ sym_diff M2 N2) \ space M" using assms + by (simp add: sets.sets_into_space) + thus ?thesis using assms hahn_decomp_space_diff pos_neg_null_set + by (meson neg_meas_subset pos_meas_subset) +qed + +section \Existence of a positive subset\ + +text \The goal of this part is to prove that any measurable set of finite and positive measure must +contain a positive subset with a strictly positive measure.\ + +subsection \A sequence of negative subsets\ + +definition inf_neg where + "inf_neg A = (if (A \ sets M \ pos_meas_set A) then (0::nat) + else Inf {n|n. (1::nat) \ n \ (\B \ sets M. B \ A \ \ B < ereal(-1/n))})" + +lemma inf_neg_ne: + assumes "A \ sets M" + and "\ pos_meas_set A" + shows "{n::nat|n. (1::nat) \ n \ + (\B \ sets M. B \ A \ \ B < ereal (-1/n))} \ {}" +proof - + define N where "N = {n::nat|n. (1::nat) \ n \ + (\B \ sets M. B \ A \ \ B < ereal (-1/n))}" + have "\B \ sets M. B\ A \ \ B < 0" using assms unfolding pos_meas_set_def + by auto + from this obtain B where "B\ sets M" and "B\ A" and "\ B < 0" by auto + hence "\n::nat. (1::nat) \ n \ \ B < ereal (-1/n)" + proof (cases "\ B = -\") + case True + hence "\ B < -1/(2::nat)" by simp + thus ?thesis using numeral_le_real_of_nat_iff one_le_numeral by blast + next + case False + hence "real_of_ereal (\ B) < 0" using \\ B < 0\ + by (metis Infty_neq_0(3) ereal_mult_eq_MInfty ereal_zero_mult + less_eq_ereal_def less_eq_real_def less_ereal.simps(2) + real_of_ereal_eq_0 real_of_ereal_le_0) + hence "\n::nat. Suc 0 \ n \ real_of_ereal (\ B) < -1/n" + proof - + define nw where "nw = Suc (nat (floor (-1/ (real_of_ereal (\ B)))))" + have "Suc 0 \ nw" unfolding nw_def by simp + have "0 < -1/ (real_of_ereal (\ B))" using \real_of_ereal (\ B) < 0\ + by simp + have "-1/ (real_of_ereal (\ B)) < nw" unfolding nw_def by linarith + hence "1/nw < 1/(-1/ (real_of_ereal (\ B)))" + using \0 < -1/ (real_of_ereal (\ B))\ by (metis frac_less2 + le_eq_less_or_eq of_nat_1 of_nat_le_iff zero_less_one) + also have "... = - (real_of_ereal (\ B))" by simp + finally have "1/nw < - (real_of_ereal (\ B))" . + hence "real_of_ereal (\ B) < -1/nw" by simp + thus ?thesis using \Suc 0 \ nw\ by auto + qed + from this obtain n1::nat where "Suc 0 \ n1" + and "real_of_ereal (\ B) < -1/n1" by auto + hence "ereal (real_of_ereal (\ B)) < -1/n1" using real_ereal_leq[of "\ B"] + \\ B < 0\ by simp + moreover have "\ B = real_of_ereal (\ B)" using \\ B < 0\ False + by (metis less_ereal.simps(2) real_of_ereal.elims zero_ereal_def) + ultimately show ?thesis using \Suc 0 \ n1\ by auto + qed + from this obtain n0::nat where "(1::nat) \ n0" and "\ B < -1/n0" by auto + hence "n0 \ {n::nat|n. (1::nat) \ n \ + (\B \ sets M. B \ A \ \ B < ereal(-1/n))}" + using \B\ sets M\ \B\ A\ by auto + thus ?thesis by auto +qed + +lemma inf_neg_ge_1: + assumes "A \ sets M" + and "\ pos_meas_set A" + shows "(1::nat) \ inf_neg A" +proof - + define N where "N = {n::nat|n. (1::nat) \ n \ + (\B \ sets M. B \ A \ \ B < ereal (-1/n))}" + have "N \ {}" unfolding N_def using assms inf_neg_ne by auto + moreover have "\n. n\ N \ (1::nat) \ n" unfolding N_def by simp + ultimately show "1 \ inf_neg A" unfolding inf_neg_def N_def + using Inf_nat_def1 assms(1) assms(2) by presburger +qed + +lemma inf_neg_pos: + assumes "A \ sets M" + and "\ pos_meas_set A" + shows "\ B \ sets M. B\ A \ \ B < -1/(inf_neg A)" +proof - + define N where "N = {n::nat|n. (1::nat) \ n \ + (\B \ sets M. B \ A \ \ B < ereal (-1/n))}" + have "N \ {}" unfolding N_def using assms inf_neg_ne by auto + hence "Inf N \ N" using Inf_nat_def1[of N] by simp + hence "inf_neg A \ N" unfolding N_def inf_neg_def using assms by auto + thus ?thesis unfolding N_def by auto +qed + +definition rep_neg where + "rep_neg A = (if (A \ sets M \ pos_meas_set A) then {} else + SOME B. B \ sets M \ B \ A \ \ B \ ereal (-1 / (inf_neg A)))" + +lemma g_rep_neg: + assumes "A\ sets M" + and "\ pos_meas_set A" + shows "rep_neg A \ sets M" "rep_neg A \ A" + "\ (rep_neg A) \ ereal (-1 / (inf_neg A))" +proof - + have "\ B. B \ sets M \ B\ A \ \ B \ -1 / (inf_neg A)" using assms + inf_neg_pos[of A] by auto + from someI_ex[OF this] show "rep_neg A \ sets M" "rep_neg A \ A" + "\ (rep_neg A) \ -1 / (inf_neg A)" + unfolding rep_neg_def using assms by auto +qed + +lemma rep_neg_sets: + shows "rep_neg A \ sets M" +proof (cases "A \ sets M \ pos_meas_set A") + case True + then show ?thesis unfolding rep_neg_def by simp +next + case False + then show ?thesis using g_rep_neg(1) by blast +qed + +lemma rep_neg_subset: + shows "rep_neg A \ A" +proof (cases "A \ sets M \ pos_meas_set A") + case True + then show ?thesis unfolding rep_neg_def by simp +next + case False + then show ?thesis using g_rep_neg(2) by blast +qed + +lemma rep_neg_less: + assumes "A\ sets M" + and "\ pos_meas_set A" + shows "\ (rep_neg A) \ ereal (-1 / (inf_neg A))" using assms g_rep_neg(3) + by simp + +lemma rep_neg_leq: + shows "\ (rep_neg A) \ 0" +proof (cases "A \ sets M \ pos_meas_set A") + case True + hence "rep_neg A = {}" unfolding rep_neg_def by simp + then show ?thesis using sgn_meas signed_measure_empty by force +next + case False + then show ?thesis using rep_neg_less by (metis le_ereal_le minus_divide_left + neg_le_0_iff_le of_nat_0 of_nat_le_iff zero_ereal_def zero_le + zero_le_divide_1_iff) +qed + +subsection \Construction of the positive subset\ + +fun pos_wtn + where + pos_wtn_base: "pos_wtn E 0 = E"| + pos_wtn_step: "pos_wtn E (Suc n) = pos_wtn E n - rep_neg (pos_wtn E n)" + +lemma pos_wtn_subset: + shows "pos_wtn E n \ E" +proof (induct n) + case 0 + then show ?case using pos_wtn_base by simp +next + case (Suc n) + hence "rep_neg (pos_wtn E n) \ pos_wtn E n" using rep_neg_subset by simp + then show ?case using Suc by auto +qed + +lemma pos_wtn_sets: + assumes "E\ sets M" + shows "pos_wtn E n \ sets M" +proof (induct n) + case 0 + then show ?case using assms by simp +next + case (Suc n) + then show ?case using pos_wtn_step rep_neg_sets by auto +qed + +definition neg_wtn where + "neg_wtn E (n::nat) = rep_neg (pos_wtn E n)" + +lemma neg_wtn_neg_meas: + shows "\ (neg_wtn E n) \ 0" unfolding neg_wtn_def using rep_neg_leq by simp + +lemma neg_wtn_sets: + shows "neg_wtn E n \ sets M" unfolding neg_wtn_def using rep_neg_sets by simp + +lemma neg_wtn_subset: + shows "neg_wtn E n \ E" unfolding neg_wtn_def + using pos_wtn_subset[of E n] rep_neg_subset[of "pos_wtn E n"] by simp + +lemma neg_wtn_union_subset: + shows "(\ i \ n. neg_wtn E i) \ E" using neg_wtn_subset by auto + +lemma pos_wtn_Suc: + shows "pos_wtn E (Suc n) = E - (\ i \ n. neg_wtn E i)" unfolding neg_wtn_def +proof (induct n) + case 0 + then show ?case using pos_wtn_base pos_wtn_step by simp +next + case (Suc n) + have "pos_wtn E (Suc (Suc n)) = pos_wtn E (Suc n) - + rep_neg (pos_wtn E (Suc n))" + using pos_wtn_step by simp + also have "... = (E - (\ i \ n. rep_neg (pos_wtn E i))) - + rep_neg (pos_wtn E (Suc n))" + using Suc by simp + also have "... = E - (\ i \ (Suc n). rep_neg (pos_wtn E i))" + using diff_union[of E "\i. rep_neg (pos_wtn E i)" n] by auto + finally show "pos_wtn E (Suc (Suc n)) = + E - (\ i \ (Suc n). rep_neg (pos_wtn E i))" . +qed + +definition pos_sub where + "pos_sub E = (\ n. pos_wtn E n)" + +lemma pos_sub_sets: + assumes "E\ sets M" + shows "pos_sub E \ sets M" unfolding pos_sub_def using pos_wtn_sets assms + by auto + +lemma pos_sub_subset: + shows "pos_sub E \ E" unfolding pos_sub_def using pos_wtn_subset by blast + +lemma pos_sub_infty: + assumes "E \ sets M" + and "\\ E\ < \" + shows "\\ (pos_sub E)\ < \" using signed_measure_finite_subset assms + pos_sub_sets pos_sub_subset by simp + +lemma neg_wtn_djn: + shows "disjoint_family (\n. neg_wtn E n)" unfolding disjoint_family_on_def +proof - + { + fix n + fix m::nat + assume "n < m" + hence "\p. m = Suc p" using old.nat.exhaust by auto + from this obtain p where "m = Suc p" by auto + have "neg_wtn E m \ pos_wtn E m" unfolding neg_wtn_def + by (simp add: rep_neg_subset) + also have "... = E - (\ i \ p. neg_wtn E i)" using pos_wtn_Suc \m = Suc p\ + by simp + finally have "neg_wtn E m \ E - (\ i \ p. neg_wtn E i)" . + moreover have "neg_wtn E n \ (\ i \ p. neg_wtn E i)" using \n < m\ + \m = Suc p\ by (simp add: UN_upper) + ultimately have "neg_wtn E n \ neg_wtn E m = {}" by auto + } + thus "\m\UNIV. \n\UNIV. m \ n \ neg_wtn E m \ neg_wtn E n = {}" + by (metis inf_commute linorder_neqE_nat) +qed +end + +lemma disjoint_family_imp_on: + assumes "disjoint_family A" + shows "disjoint_family_on A S" + using assms disjoint_family_on_mono subset_UNIV by blast + +context signed_measure_space +begin +lemma neg_wtn_union_neg_meas: + shows "\ (\ i \ n. neg_wtn E i) \ 0" +proof - + have "\ (\ i \ n. neg_wtn E i) = (\i\{.. n}. \ (neg_wtn E i))" + proof (rule signed_measure_disj_sum, simp+) + show "signed_measure M \" using sgn_meas . + show "disjoint_family_on (neg_wtn E) {..n}" using neg_wtn_djn + disjoint_family_imp_on[of "neg_wtn E"] by simp + show "\i. i \ {..n} \ neg_wtn E i \ sets M" using neg_wtn_sets by simp + qed + also have "... \ 0" using neg_wtn_neg_meas by (simp add: sum_nonpos) + finally show ?thesis . +qed + +lemma pos_wtn_meas_gt: + assumes "0 < \ E" + and "E\ sets M" + shows "0 < \ (pos_wtn E n)" +proof (cases "n = 0") + case True + then show ?thesis using assms by simp +next + case False + hence "\m. n = Suc m" by (simp add: not0_implies_Suc) + from this obtain m where "n = Suc m" by auto + hence eq: "pos_wtn E n = E - (\ i \ m. neg_wtn E i)" using pos_wtn_Suc + by simp + hence "pos_wtn E n \ (\ i \ m. neg_wtn E i) = {}" by auto + moreover have "E = pos_wtn E n \ (\ i \ m. neg_wtn E i)" + using eq neg_wtn_union_subset[of E m] by auto + ultimately have "\ E = \ (pos_wtn E n) + \ (\ i \ m. neg_wtn E i)" + using signed_measure_add[of M \ "pos_wtn E n" "\ i \ m. neg_wtn E i"] + pos_wtn_sets neg_wtn_sets assms sgn_meas by auto + hence "0 < \ (pos_wtn E n) + \ (\ i \ m. neg_wtn E i)" using assms by simp + thus ?thesis using neg_wtn_union_neg_meas + by (metis add.right_neutral add_mono not_le) +qed + +definition union_wit where + "union_wit E = (\ n. neg_wtn E n)" + +lemma union_wit_sets: + shows "union_wit E \ sets M" unfolding union_wit_def +proof (intro sigma_algebra.countable_nat_UN) + show "sigma_algebra (space M) (sets M)" + by (simp add: sets.sigma_algebra_axioms) + show "range (neg_wtn E) \ sets M" + proof - + { + fix n + have "neg_wtn E n \ sets M" unfolding neg_wtn_def + by (simp add: rep_neg_sets) + } + thus ?thesis by auto + qed +qed + +lemma union_wit_subset: + shows "union_wit E \ E" +proof - + { + fix n + have "neg_wtn E n \ E" unfolding neg_wtn_def using pos_wtn_subset + rep_neg_subset[of "pos_wtn E n"] by auto + } + thus ?thesis unfolding union_wit_def by auto +qed + +lemma pos_sub_diff: + shows "pos_sub E = E - union_wit E" +proof + show "pos_sub E \ E - union_wit E" + proof - + have "pos_sub E \ E" using pos_sub_subset by simp + moreover have "pos_sub E \ union_wit E = {}" + proof (rule ccontr) + assume "pos_sub E \ union_wit E \ {}" + hence "\ a. a\ pos_sub E \ union_wit E" by auto + from this obtain a where "a\ pos_sub E \ union_wit E" by auto + hence "a\ union_wit E" by simp + hence "\n. a \ rep_neg (pos_wtn E n)" unfolding union_wit_def neg_wtn_def + by auto + from this obtain n where "a \ rep_neg (pos_wtn E n)" by auto + have "a \ pos_wtn E (Suc n)" using \a\ pos_sub E \ union_wit E\ + unfolding pos_sub_def by blast + hence "a\ rep_neg (pos_wtn E n)" using pos_wtn_step by simp + thus False using \a \ rep_neg (pos_wtn E n)\ by simp + qed + ultimately show ?thesis by auto + qed +next + show "E - union_wit E \ pos_sub E" + proof + fix a + assume "a \ E - union_wit E" + show "a \ pos_sub E" unfolding pos_sub_def + proof + fix n + show "a \ pos_wtn E n" + proof (cases "n = 0") + case True + thus ?thesis using pos_wtn_base \a\ E - union_wit E\ by simp + next + case False + hence "\m. n = Suc m" by (simp add: not0_implies_Suc) + from this obtain m where "n = Suc m" by auto + have "(\ i \ m. rep_neg (pos_wtn E i)) \ + (\ n. (rep_neg (pos_wtn E n)))" by auto + hence "a \ E - (\ i \ m. rep_neg (pos_wtn E i))" + using \a \ E - union_wit E\ unfolding union_wit_def neg_wtn_def + by auto + thus "a\ pos_wtn E n" using pos_wtn_Suc \n = Suc m\ + unfolding neg_wtn_def by simp + qed + qed + qed +qed + +definition num_wtn where + "num_wtn E n = inf_neg (pos_wtn E n)" + +lemma num_wtn_geq: + shows "\ (neg_wtn E n) \ ereal (-1/(num_wtn E n))" +proof (cases "(pos_wtn E n) \ sets M \ pos_meas_set (pos_wtn E n)") + case True + hence "neg_wtn E n = {}" unfolding neg_wtn_def rep_neg_def by simp + moreover have "num_wtn E n = 0" using True unfolding num_wtn_def inf_neg_def + by simp + ultimately show ?thesis using sgn_meas signed_measure_empty by force +next + case False + then show ?thesis using g_rep_neg(3)[of "pos_wtn E n"] unfolding neg_wtn_def + num_wtn_def by simp +qed + +lemma neg_wtn_infty: + assumes "E \ sets M" + and "\\ E\ < \" + shows "\\ (neg_wtn E i)\ < \" +proof (rule signed_measure_finite_subset) + show "E \ sets M" "\\ E\ < \" using assms by auto + show "neg_wtn E i \ sets M" + proof (cases "pos_wtn E i \ sets M \ pos_meas_set (pos_wtn E i)") + case True + then show ?thesis unfolding neg_wtn_def rep_neg_def by simp + next + case False + then show ?thesis unfolding neg_wtn_def + using g_rep_neg(1)[of "pos_wtn E i"] by simp + qed + show "neg_wtn E i \ E" unfolding neg_wtn_def using pos_wtn_subset[of E] + rep_neg_subset[of "pos_wtn E i"] by auto +qed + +lemma union_wit_infty: + assumes "E \ sets M" + and "\\ E\ < \" + shows "\\ (union_wit E)\ < \" using union_wit_subset union_wit_sets + signed_measure_finite_subset assms unfolding union_wit_def by simp + +lemma neg_wtn_summable: + assumes "E \ sets M" + and "\\ E\ < \" + shows "summable (\i. - real_of_ereal (\ (neg_wtn E i)))" +proof - + have "signed_measure M \" using sgn_meas . + moreover have "range (neg_wtn E) \ sets M" unfolding neg_wtn_def + using rep_neg_sets by auto + moreover have "disjoint_family (neg_wtn E)" using neg_wtn_djn by simp + moreover have "\ (range (neg_wtn E)) \ sets M" using union_wit_sets + unfolding union_wit_def by simp + moreover have "\\ (\ (range (neg_wtn E)))\ < \" + using union_wit_subset signed_measure_finite_subset union_wit_sets assms + unfolding union_wit_def by simp + ultimately have "summable (\i. real_of_ereal \\ (neg_wtn E i)\)" + using signed_measure_abs_convergent[of M ] by simp + moreover have "\i. \\ (neg_wtn E i)\ = -(\ (neg_wtn E i))" + proof - + fix i + have "\ (neg_wtn E i) \ 0" using rep_neg_leq[of "pos_wtn E i"] + unfolding neg_wtn_def . + thus "\\ (neg_wtn E i)\ = -\ (neg_wtn E i)" using less_eq_ereal_def by auto + qed + ultimately show ?thesis by simp +qed + +lemma inv_num_wtn_summable: + assumes "E \ sets M" + and "\\ E\ < \" + shows "summable (\n. 1/(num_wtn E n))" +proof (rule summable_bounded) + show "\i. 0 \ 1 / real (num_wtn E i)" by simp + show "\i. 1 / real (num_wtn E i) \ (\n. -real_of_ereal (\ (neg_wtn E n))) i" + proof - + fix i + have "\\ (neg_wtn E i)\ < \" using assms neg_wtn_infty by simp + have "ereal (1/(num_wtn E i)) \ -\ (neg_wtn E i)" using num_wtn_geq[of E i] + ereal_minus_le_minus by fastforce + also have "... = ereal(- real_of_ereal (\ (neg_wtn E i)))" + using \\\ (neg_wtn E i)\ < \\ ereal_real' by auto + finally have "ereal (1/(num_wtn E i)) \ + ereal(- real_of_ereal (\ (neg_wtn E i)))" . + thus "1 / real (num_wtn E i) \ -real_of_ereal (\ (neg_wtn E i))" by simp + qed + show "summable (\i. - real_of_ereal (\ (neg_wtn E i)))" + using assms neg_wtn_summable by simp +qed + +lemma inv_num_wtn_shift_summable: + assumes "E \ sets M" + and "\\ E\ < \" + shows "summable (\n. 1/(num_wtn E n - 1))" +proof (rule sum_shift_denum) + show "summable (\n. 1 / real (num_wtn E n))" using assms inv_num_wtn_summable + by simp +qed + +lemma neg_wtn_meas_sums: + assumes "E \ sets M" + and "\\ E\ < \" + shows "(\i. - (\ (neg_wtn E i))) sums + suminf (\i. - real_of_ereal (\ (neg_wtn E i)))" +proof - + have "(\i. ereal (- real_of_ereal (\ (neg_wtn E i)))) sums + suminf (\i. - real_of_ereal (\ (neg_wtn E i)))" + proof (rule sums_ereal[THEN iffD2]) + have "summable (\i. - real_of_ereal (\ (neg_wtn E i)))" + using neg_wtn_summable assms by simp + thus "(\x. - real_of_ereal (\ (neg_wtn E x))) + sums (\i. - real_of_ereal (\ (neg_wtn E i)))" + by auto + qed + moreover have "\i. \ (neg_wtn E i) = ereal (real_of_ereal (\ (neg_wtn E i)))" + proof - + fix i + show "\ (neg_wtn E i) = ereal (real_of_ereal (\ (neg_wtn E i)))" + using assms(1) assms(2) ereal_real' neg_wtn_infty by auto + qed + ultimately show ?thesis + by (metis (no_types, lifting) sums_cong uminus_ereal.simps(1)) +qed + +lemma neg_wtn_meas_suminf_le: + assumes "E \ sets M" + and "\\ E\ < \" + shows "suminf (\i. \ (neg_wtn E i)) \ - suminf (\n. 1/(num_wtn E n))" +proof - + have "suminf (\n. 1/(num_wtn E n)) \ + suminf (\i. -real_of_ereal (\ (neg_wtn E i)))" + proof (rule suminf_le) + show "summable (\n. 1 / real (num_wtn E n))" using assms + inv_num_wtn_summable[of E] + summable_minus[of "\n. 1 / real (num_wtn E n)"] by simp + show "summable (\i. -real_of_ereal (\ (neg_wtn E i)))" + using neg_wtn_summable assms + summable_minus[of "\i. real_of_ereal (\ (neg_wtn E i))"] + by (simp add: summable_minus_iff) + show "\n. 1 / real (num_wtn E n) \ -real_of_ereal (\ (neg_wtn E n))" + proof - + fix n + have "\ (neg_wtn E n) \ ereal (- 1 / real (num_wtn E n))" + using num_wtn_geq by simp + hence "ereal (1/ real (num_wtn E n)) \ - \ (neg_wtn E n)" + by (metis add.inverse_inverse eq_iff ereal_uminus_le_reorder linear + minus_divide_left uminus_ereal.simps(1)) + have "real_of_ereal (ereal (1 / real (num_wtn E n))) \ + real_of_ereal (- \ (neg_wtn E n))" + proof (rule real_of_ereal_positive_mono) + show "0 \ ereal (1 / real (num_wtn E n))" by simp + show "ereal (1 / real (num_wtn E n)) \ - \ (neg_wtn E n)" + using \ereal (1 / real (num_wtn E n)) \ - \ (neg_wtn E n)\ . + show "- \ (neg_wtn E n) \ \" using neg_wtn_infty[of E n] assms by auto + qed + thus "(1 / real (num_wtn E n)) \ -real_of_ereal ( \ (neg_wtn E n))" + by simp + qed + qed + also have "... = - suminf (\i. real_of_ereal (\ (neg_wtn E i)))" + proof (rule suminf_minus) + show "summable (\n. real_of_ereal (\ (neg_wtn E n)))" + using neg_wtn_summable assms + summable_minus[of "\i. real_of_ereal (\ (neg_wtn E i))"] + by (simp add: summable_minus_iff) + qed + finally have "suminf (\n. 1/(num_wtn E n)) \ + - suminf (\i. real_of_ereal (\ (neg_wtn E i)))" . + hence a: "suminf (\i. real_of_ereal (\ (neg_wtn E i))) \ + - suminf (\n. 1/(num_wtn E n))" by simp + show "suminf (\i. (\ (neg_wtn E i))) \ ereal (-suminf (\n. 1/(num_wtn E n)))" + proof - + have sumeq: "suminf (\i. ereal (real_of_ereal (\ (neg_wtn E i)))) = + suminf (\i. (real_of_ereal (\ (neg_wtn E i))))" + proof (rule sums_suminf_ereal) + have "summable (\i. -real_of_ereal (\ (neg_wtn E i)))" + using neg_wtn_summable assms + summable_minus[of "\i. real_of_ereal (\ (neg_wtn E i))"] + by (simp add: summable_minus_iff) + thus "(\i. real_of_ereal (\ (neg_wtn E i))) sums + (\i. real_of_ereal (\ (neg_wtn E i)))" + using neg_wtn_summable[of E] assms summable_minus_iff by blast + qed + hence "suminf (\i. \ (neg_wtn E i)) = + suminf (\i. (real_of_ereal (\ (neg_wtn E i))))" + proof - + have "\i. ereal (real_of_ereal (\ (neg_wtn E i))) = \ (neg_wtn E i)" + proof - + fix i + show "ereal (real_of_ereal (\ (neg_wtn E i))) = \ (neg_wtn E i)" + using neg_wtn_infty[of E] assms by (simp add: ereal_real') + qed + thus ?thesis using sumeq by auto + qed + thus ?thesis using a by simp + qed +qed + +lemma union_wit_meas_le: + assumes "E \ sets M" + and "\\ E\ < \" + shows "\ (union_wit E) \ - suminf (\n. 1 / real (num_wtn E n))" +proof - + have "\ (union_wit E) = \ (\ (range (neg_wtn E)))" unfolding union_wit_def + by simp + also have "... = (\i. \ (neg_wtn E i))" + proof (rule signed_measure_inf_sum[symmetric]) + show "signed_measure M \" using sgn_meas . + show "range (neg_wtn E) \ sets M" + by (simp add: image_subset_iff neg_wtn_def rep_neg_sets) + show "disjoint_family (neg_wtn E)" using neg_wtn_djn by simp + show "\ (range (neg_wtn E)) \ sets M" using union_wit_sets + unfolding union_wit_def by simp + qed + also have "... \ - suminf (\n. 1 / real (num_wtn E n))" + using assms neg_wtn_meas_suminf_le by simp + finally show ?thesis . +qed + +lemma pos_sub_pos_meas: + assumes "E \ sets M" + and "\\ E\ < \" + and "0 < \ E" + and "\ pos_meas_set E" + shows "0 < \ (pos_sub E)" +proof - + have "0 < \ E" using assms by simp + also have "... = \ (pos_sub E) + \ (union_wit E)" + proof - + have "E = pos_sub E \ (union_wit E)" + using pos_sub_diff[of E] union_wit_subset by force + moreover have "pos_sub E \ union_wit E = {}" + using pos_sub_diff by auto + ultimately show ?thesis + using signed_measure_add[of M \ "pos_sub E" "union_wit E"] + pos_sub_sets union_wit_sets assms sgn_meas by simp + qed + also have "... \ \ (pos_sub E) + (- suminf (\n. 1 / real (num_wtn E n)))" + proof - + have "\ (union_wit E) \ - suminf (\n. 1 / real (num_wtn E n))" + using union_wit_meas_le[of E] assms by simp + thus ?thesis using union_wit_infty assms using add_left_mono by blast + qed + also have "... = \ (pos_sub E) - suminf (\n. 1 / real (num_wtn E n))" + by (simp add: minus_ereal_def) + finally have "0 < \ (pos_sub E) - suminf (\n. 1 / real (num_wtn E n))" . + moreover have "0 < suminf (\n. 1 / real (num_wtn E n))" + proof (rule suminf_pos2) + show "0 < 1 / real (num_wtn E 0)" + using inf_neg_ge_1[of E] assms pos_wtn_base unfolding num_wtn_def by simp + show "\n. 0 \ 1 / real (num_wtn E n)" by simp + show "summable (\n. 1 / real (num_wtn E n))" + using assms inv_num_wtn_summable by simp + qed + ultimately show ?thesis using pos_sub_infty assms by fastforce +qed + +lemma num_wtn_conv: + assumes "E \ sets M" + and "\\ E\ < \" + shows "(\n. 1/(num_wtn E n)) \ 0" +proof (rule summable_LIMSEQ_zero) + show "summable (\n. 1 / real (num_wtn E n))" + using assms inv_num_wtn_summable by simp +qed + +lemma num_wtn_shift_conv: + assumes "E \ sets M" + and "\\ E\ < \" + shows "(\n. 1/(num_wtn E n - 1)) \ 0" +proof (rule summable_LIMSEQ_zero) + show "summable (\n. 1 / real (num_wtn E n - 1))" + using assms inv_num_wtn_shift_summable by simp +qed + +lemma inf_neg_E_set: + assumes "0 < inf_neg E" + shows "E \ sets M" using assms unfolding inf_neg_def by presburger + +lemma inf_neg_pos_meas: + assumes "0 < inf_neg E" + shows "\ pos_meas_set E" using assms unfolding inf_neg_def by presburger + +lemma inf_neg_mem: + assumes "0 < inf_neg E" + shows "inf_neg E \ {n::nat|n. (1::nat) \ n \ + (\B \ sets M. B \ E \ \ B < ereal (-1/n))}" +proof - + have "E \ sets M" using assms unfolding inf_neg_def by presburger + moreover have "\ pos_meas_set E" using assms unfolding inf_neg_def + by presburger + ultimately have "{n::nat|n. (1::nat) \ n \ + (\B \ sets M. B \ E \ \ B < ereal (-1/n))} \ {}" + using inf_neg_ne[of E] by simp + thus ?thesis unfolding inf_neg_def + by (meson Inf_nat_def1 \E \ sets M\ \\ pos_meas_set E\) +qed + +lemma prec_inf_neg_pos: + assumes "0 < inf_neg E - 1" + and "B \ sets M" + and "B\ E" + shows "-1/(inf_neg E - 1) \ \ B" +proof (rule ccontr) + define S where "S = {p::nat|p. (1::nat) \ p \ + (\B \ sets M. B \ E \ \ B < ereal (-1/p))}" + assume "\ ereal (- 1 / real (inf_neg E - 1)) \ \ B" + hence "\ B < -1/(inf_neg E - 1)" by auto + hence "inf_neg E - 1\ S" unfolding S_def using assms by auto + have "Suc 0 < inf_neg E" using assms by simp + hence "inf_neg E \ S" unfolding S_def using inf_neg_mem[of E] by simp + hence "S \ {}" by auto + have "inf_neg E = Inf S" unfolding S_def inf_neg_def + using assms inf_neg_E_set inf_neg_pos_meas by auto + have "inf_neg E - 1 < inf_neg E" using assms by simp + hence "inf_neg E -1 \ S" + using cInf_less_iff[of S] \S \ {}\ \inf_neg E = Inf S\ by auto + thus False using \inf_neg E - 1 \ S\ by simp +qed + +lemma pos_wtn_meas_ge: + assumes "E \ sets M" + and "\\ E\ < \" + and "C\ sets M" + and "\n. C\ pos_wtn E n" + and "\n. 0 < num_wtn E n" + shows "\N. \n\ N. - 1/ (num_wtn E n - 1) \ \ C" +proof - + have "\N. \n\ N. 1/(num_wtn E n) < 1/2" using num_wtn_conv[of E] + conv_0_half[of "\n. 1 / real (num_wtn E n)"] assms by simp + from this obtain N where "\n\ N. 1/(num_wtn E n) < 1/2" by auto + { + fix n + assume "N \ n" + hence "1/(num_wtn E n) < 1/2" using \\n\ N. 1/(num_wtn E n) < 1/2\ by simp + have "1/(1/2) < 1/(1/(num_wtn E n))" + proof (rule frac_less2, auto) + show "2 / real (num_wtn E n) < 1" using \1/(num_wtn E n) < 1/2\ + by linarith + show "0 < num_wtn E n" unfolding num_wtn_def using inf_neg_ge_1 assms + by (simp add: num_wtn_def) + qed + hence "2 < (num_wtn E n)" by simp + hence "Suc 0 < num_wtn E n - 1" unfolding num_wtn_def by simp + hence "- 1/ (num_wtn E n - 1) \ \ C" using assms prec_inf_neg_pos + unfolding num_wtn_def by simp + } + thus ?thesis by auto +qed + +lemma pos_sub_pos_meas_subset: + assumes "E \ sets M" + and "\\ E\ < \" + and "C\ sets M" + and "C\ (pos_sub E)" + and "\n. 0 < num_wtn E n" + shows "0 \ \ C" +proof - + have "\n. C \ pos_wtn E n" using assms unfolding pos_sub_def by auto + hence "\N. \n\ N. - 1/ (num_wtn E n - 1) \ \ C" using assms + pos_wtn_meas_ge[of E C] by simp + from this obtain N where Nprop: "\n\ N. - 1/ (num_wtn E n - 1) \ \ C" by auto + show "0 \ \ C" + proof (rule lim_mono) + show "\n. N \ n \ - 1/ (num_wtn E n - 1) \ (\n. \ C) n" + using Nprop by simp + have "(\n. ( 1 / real (num_wtn E n - 1))) \ 0" + using assms num_wtn_shift_conv[of E] by simp + hence "(\n. (- 1 / real (num_wtn E n - 1))) \ 0" + using tendsto_minus[of "\n. 1 / real (num_wtn E n - 1)" 0] by simp + thus "(\n. ereal (- 1 / real (num_wtn E n - 1))) \ 0" + by (simp add: zero_ereal_def) + show "(\n. \ C) \ \ C" by simp + qed +qed + +lemma pos_sub_pos_meas': + assumes "E \ sets M" + and "\\ E\ < \" + and "0 < \ E" + and "\n. 0 < num_wtn E n" + shows "0 < \ (pos_sub E)" +proof - + have "0 < \ E" using assms by simp + also have "... = \ (pos_sub E) + \ (union_wit E)" + proof - + have "E = pos_sub E \ (union_wit E)" + using pos_sub_diff[of E] union_wit_subset by force + moreover have "pos_sub E \ union_wit E = {}" + using pos_sub_diff by auto + ultimately show ?thesis + using signed_measure_add[of M \ "pos_sub E" "union_wit E"] + pos_sub_sets union_wit_sets assms sgn_meas by simp + qed + also have "... \ \ (pos_sub E) + (- suminf (\n. 1 / real (num_wtn E n)))" + proof - + have "\ (union_wit E) \ - suminf (\n. 1 / real (num_wtn E n))" + using union_wit_meas_le[of E] assms by simp + thus ?thesis using union_wit_infty assms using add_left_mono by blast + qed + also have "... = \ (pos_sub E) - suminf (\n. 1 / real (num_wtn E n))" + by (simp add: minus_ereal_def) + finally have "0 < \ (pos_sub E) - suminf (\n. 1 / real (num_wtn E n))" . + moreover have "0 < suminf (\n. 1 / real (num_wtn E n))" + proof (rule suminf_pos2) + show "0 < 1 / real (num_wtn E 0)" using assms by simp + show "\n. 0 \ 1 / real (num_wtn E n)" by simp + show "summable (\n. 1 / real (num_wtn E n))" + using assms inv_num_wtn_summable by simp + qed + ultimately show ?thesis using pos_sub_infty assms by fastforce +qed + +text \We obtain the main result of this part on the existence of a positive subset.\ + +lemma exists_pos_meas_subset: + assumes "E \ sets M" + and "\\ E\ < \" + and "0 < \ E" + shows "\A. A \ E \ pos_meas_set A \ 0 < \ A" +proof (cases "\n. 0 < num_wtn E n") + case True + have "pos_meas_set (pos_sub E)" + proof (rule pos_meas_setI) + show "pos_sub E \ sets M" by (simp add: assms(1) pos_sub_sets) + fix A + assume "A \ sets M" and "A\ pos_sub E" + thus "0 \ \ A" using assms True pos_sub_pos_meas_subset[of E] by simp + qed + moreover have "0 < \ (pos_sub E)" + using pos_sub_pos_meas'[of E] True assms by simp + ultimately show ?thesis using pos_meas_set_def by (metis pos_sub_subset) +next + case False + hence "\n. num_wtn E n = 0" by simp + from this obtain n where "num_wtn E n = 0" by auto + hence "pos_wtn E n \ sets M \ pos_meas_set (pos_wtn E n)" + using inf_neg_ge_1 unfolding num_wtn_def by fastforce + hence "pos_meas_set (pos_wtn E n)" using assms + by (simp add: \E \ sets M\ pos_wtn_sets) + moreover have "0 < \ (pos_wtn E n)" using pos_wtn_meas_gt assms by simp + ultimately show ?thesis using pos_meas_set_def by (meson pos_wtn_subset) +qed + +section \The Hahn decomposition theorem\ + +definition seq_meas where + "seq_meas = (SOME f. incseq f \ range f \ pos_img \ \ pos_img = \ range f)" + +lemma seq_meas_props: + shows "incseq seq_meas \ range seq_meas \ pos_img \ + \ pos_img = \ range seq_meas" +proof - + have ex: "\f. incseq f \ range f \ pos_img \ \ pos_img = \ range f" + proof (rule Extended_Real.Sup_countable_SUP) + show "pos_img \ {}" + proof - + have "{} \ pos_sets" using empty_pos_meas_set unfolding pos_sets_def + by simp + hence "\ {} \ pos_img" unfolding pos_img_def by auto + thus ?thesis by auto + qed + qed + let ?V = "SOME f. incseq f \ range f \ pos_img \ \ pos_img = \ range f" + have vprop: "incseq ?V \ range ?V \ pos_img \ \ pos_img = \ range ?V" + using someI_ex[of "\f. incseq f \ range f \ pos_img \ + \ pos_img = \ range f"] ex by blast + show ?thesis using seq_meas_def vprop by presburger +qed + +definition seq_meas_rep where + "seq_meas_rep n = (SOME A. A\ pos_sets \ seq_meas n = \ A)" + +lemma seq_meas_rep_ex: + shows "seq_meas_rep n \ pos_sets \ \ (seq_meas_rep n) = seq_meas n" +proof - + have ex: "\A. A \ pos_sets \ seq_meas n = \ A" using seq_meas_props + by (smt (z3) UNIV_I image_subset_iff mem_Collect_eq pos_img_def) + let ?V = "SOME A. A\ pos_sets \ seq_meas n = \ A" + have vprop: "?V\ pos_sets \ seq_meas n = \ ?V" using + someI_ex[of "\A. A\ pos_sets \ seq_meas n = \ A"] using ex by blast + show ?thesis using seq_meas_rep_def vprop by fastforce +qed + +lemma seq_meas_rep_pos: + assumes "\E \ sets M. \ E < \" + shows "pos_meas_set (\ i. seq_meas_rep i)" +proof (rule pos_meas_set_Union) + show " \i. pos_meas_set (seq_meas_rep i)" + using seq_meas_rep_ex signed_measure_space.pos_sets_def + signed_measure_space_axioms by auto + then show "\i. seq_meas_rep i \ sets M" + by (simp add: pos_meas_setD1) + show "\\ (\ (range seq_meas_rep))\ < \" + proof - + have "(\ (range seq_meas_rep)) \ sets M" + proof (rule sigma_algebra.countable_Union) + show "sigma_algebra (space M) (sets M)" + by (simp add: sets.sigma_algebra_axioms) + show "countable (range seq_meas_rep)" by simp + show "range seq_meas_rep \ sets M" + by (simp add: \\i. seq_meas_rep i \ sets M\ image_subset_iff) + qed + hence "\ (\ (range seq_meas_rep)) \ 0 " + using \\i. pos_meas_set (seq_meas_rep i)\ \\i. seq_meas_rep i \ sets M\ + signed_measure_space.pos_meas_set_pos_lim signed_measure_space_axioms + by blast + thus ?thesis using assms \\ (range seq_meas_rep) \ sets M\ abs_ereal_ge0 + by simp + qed +qed + +lemma sup_seq_meas_rep: + assumes "\E \ sets M. \ E < \" + and "S = (\ pos_img)" + and "A = (\ i. seq_meas_rep i)" + shows "\ A = S" +proof - + have pms: "pos_meas_set (\ i. seq_meas_rep i)" + using assms seq_meas_rep_pos by simp + hence "\ A \ S" + by (metis (mono_tags, lifting) Sup_upper \S = \ pos_img\ mem_Collect_eq + pos_img_def pos_meas_setD1 pos_sets_def assms(2) assms(3)) + have "\n. (\ A = \ (A - seq_meas_rep n) + \ (seq_meas_rep n))" + proof + fix n + have "A = (A - seq_meas_rep n) \ seq_meas_rep n " + using \A = \ (range seq_meas_rep)\ by blast + hence "\ A = \ ((A - seq_meas_rep n) \ seq_meas_rep n)" by simp + also have "... = \ (A - seq_meas_rep n) + \ (seq_meas_rep n)" + proof (rule signed_measure_add) + show "signed_measure M \" using sgn_meas by simp + show "seq_meas_rep n \ sets M" + using pos_sets_def seq_meas_rep_ex by auto + then show "A - seq_meas_rep n \ sets M" + by (simp add: assms pms pos_meas_setD1 sets.Diff) + show "(A - seq_meas_rep n) \ seq_meas_rep n = {}" by auto + qed + finally show "\ A = \ (A - seq_meas_rep n) + \ (seq_meas_rep n)". + qed + have "\n. \ A \ \ (seq_meas_rep n)" + proof + fix n + have "\ A \ 0" using pms assms unfolding pos_meas_set_def by auto + have "(A - seq_meas_rep n) \ A" by simp + hence "pos_meas_set (A - seq_meas_rep n)" + proof - + have "(A - seq_meas_rep n) \ sets M" + using pms assms pos_meas_setD1 pos_sets_def seq_meas_rep_ex by auto + thus ?thesis using pms assms unfolding pos_meas_set_def by auto + qed + hence "\ (A - seq_meas_rep n) \ 0" unfolding pos_meas_set_def by auto + thus "\ (seq_meas_rep n) \ \ A" + using \\n. (\ A = \ (A - seq_meas_rep n) + \ (seq_meas_rep n))\ + by (metis ereal_le_add_self2) + qed + hence "\ A \ (\ range seq_meas)" by (simp add: Sup_le_iff seq_meas_rep_ex) + moreover have "S = (\ range seq_meas)" + using seq_meas_props \S = (\ pos_img)\ by simp + ultimately have "\ A \ S" by simp + thus "\ A = S" using \\ A \ S\ by simp +qed + +lemma seq_meas_rep_compl: + assumes "\E \ sets M. \ E < \" + and "A = (\ i. seq_meas_rep i)" + shows "neg_meas_set ((space M) - A)" unfolding neg_meas_set_def +proof (rule ccontr) + assume asm: "\ (space M - A \ sets M \ + (\Aa\sets M. Aa \ space M - A \ \ Aa \ 0))" + define S where "S = (\ pos_img)" + have "pos_meas_set A" using assms seq_meas_rep_pos by simp + have "\ A = S" using sup_seq_meas_rep assms S_def by simp + hence "S < \" using assms \pos_meas_set A\ pos_meas_setD1 by blast + have "(space M - A \ sets M)" + by (simp add: \pos_meas_set A\ pos_meas_setD1 sets.compl_sets) + hence " \(\Aa\sets M. Aa \ space M - A \ \ Aa \ 0)" using asm by blast + hence "\ E \ sets M. E \ ((space M) - A) \ \ E > 0" + by (metis less_eq_ereal_def linear) + from this obtain E where "E \ sets M" and "E \ ((space M) - A)" and + "\ E > 0" by auto + have "\ A0 \ E. pos_meas_set A0 \ \ A0 > 0" + proof (rule exists_pos_meas_subset) + show "E \ sets M" using \E \ sets M\ by simp + show "0 < \ E" using \\ E > 0\ by simp + show "\\ E\ < \" + proof - + have "\ E < \" using assms \E \ sets M\ by simp + moreover have "- \ < \ E" using \0 < \ E\ by simp + ultimately show ?thesis + by (meson ereal_infty_less(1) not_inftyI) + qed + qed + from this obtain A0 where "A0 \ E" and "pos_meas_set A0" and " \ A0 > 0" + by auto + have "pos_meas_set (A \ A0)" + using pos_meas_set_union \pos_meas_set A0\ \pos_meas_set A\ by simp + have "\ (A \ A0) = \ A + \ A0" + proof (rule signed_measure_add) + show "signed_measure M \" using sgn_meas by simp + show "A \ sets M" using \pos_meas_set A\ + unfolding pos_meas_set_def by simp + show "A0 \ sets M" using \pos_meas_set A0\ + unfolding pos_meas_set_def by simp + show "(A \ A0) = {}" using \A0 \ E\ \E \ ((space M) - A)\ by auto + qed + then have "\ (A \ A0) > S" + using \\ A = S\ \\ A0 > 0\ + by (metis \S < \\ \pos_meas_set (A \ A0)\ abs_ereal_ge0 ereal_between(2) + not_inftyI not_less_iff_gr_or_eq pos_meas_self) + have "(A \ A0) \ pos_sets" + proof - + have " (A \ A0) \ sets M" using sigma_algebra.countable_Union + by (simp add: \pos_meas_set (A \ A0)\ pos_meas_setD1) + moreover have "pos_meas_set (A \ A0)" using \pos_meas_set (A \ A0)\ by simp + ultimately show ?thesis unfolding pos_sets_def by simp + qed + then have "\ (A \ A0) \ pos_img" unfolding pos_img_def by auto + show False using \\ (A \ A0) > S\ \\ (A \ A0) \ pos_img\ \S = (\ pos_img)\ + by (metis Sup_upper sup.absorb_iff2 sup.strict_order_iff) +qed + +lemma hahn_decomp_finite: + assumes "\E \ sets M. \ E < \" + shows "\ M1 M2. hahn_space_decomp M1 M2" unfolding hahn_space_decomp_def +proof - + define S where "S = (\ pos_img)" + define A where "A = (\ i. seq_meas_rep i)" + have "pos_meas_set A" unfolding A_def using assms seq_meas_rep_pos by simp + have "neg_meas_set ((space M) - A)" + using seq_meas_rep_compl assms unfolding A_def by simp + show "\M1 M2. pos_meas_set M1 \ neg_meas_set M2 \ space M = M1 \ M2 \ + M1 \ M2 = {}" + proof (intro exI conjI) + show "pos_meas_set A" using \pos_meas_set A\ . + show "neg_meas_set (space M - A)" using \neg_meas_set (space M - A)\ . + show "space M = A \ (space M - A)" + by (metis Diff_partition \pos_meas_set A\ inf.absorb_iff2 pos_meas_setD1 + sets.Int_space_eq1) + show "A \ (space M - A) = {}" by auto + qed +qed + +theorem hahn_decomposition: + shows "\ M1 M2. hahn_space_decomp M1 M2" +proof (cases "\E \ sets M. \ E < \") + case True + thus ?thesis using hahn_decomp_finite by simp +next + case False + define m where "m = (\A . - \ A)" + have "\ M1 M2. signed_measure_space.hahn_space_decomp M m M1 M2" + proof (rule signed_measure_space.hahn_decomp_finite) + show "signed_measure_space M m" + using signed_measure_minus sgn_meas \m = (\A . - \ A)\ + by (unfold_locales, simp) + show "\E\sets M. m E < \" + proof + fix E + assume "E \ sets M" + show "m E < \" + proof + show "m E \ \" + proof (rule ccontr) + assume "\ m E \ \" + have "m E = \" + using \\ m E \ \\ by auto + have "signed_measure M m" + using \signed_measure_space M m\ signed_measure_space_def by auto + moreover have "m E = - \ E" using \m = (\A . - \ A)\ by auto + then have "\ \ range m" using \signed_measure M m\ + by (metis (no_types, lifting) False ereal_less_PInfty + ereal_uminus_eq_reorder image_iff inf_range m_def rangeI) + show False using \m E = \\ \\ \ range m\ + by (metis rangeI) + qed + qed + qed + qed + hence "\ M1 M2. (neg_meas_set M1) \ (pos_meas_set M2) \ (space M = M1 \ M2) \ + (M1 \ M2 = {})" + using pos_meas_set_opp neg_meas_set_opp unfolding m_def + by (metis sgn_meas signed_measure_minus signed_measure_space_def + signed_measure_space.hahn_space_decomp_def) + thus ?thesis using hahn_space_decomp_def by (metis inf_commute sup_commute) +qed + +section \The Jordan decomposition theorem\ + +definition jordan_decomp where + "jordan_decomp m1 m2 \ ((measure_space (space M) (sets M) m1) \ + (measure_space (space M) (sets M) m2) \ + (\A\ sets M. 0 \ m1 A) \ + (\ A\ sets M. 0 \ m2 A) \ + (\A \ sets M. \ A = (m1 A) - (m2 A)) \ + (\ P N A. hahn_space_decomp P N \ + (A \ sets M \ A \ P \ (m2 A) = 0) \ + (A \ sets M \ A \ N \ (m1 A) = 0)) \ + ((\A \ sets M. m1 A < \) \ (\A \ sets M. m2 A < \)))" + +lemma jordan_decomp_pos_meas: + assumes "jordan_decomp m1 m2" + and "hahn_space_decomp P N" + and "A \ sets M" + shows "m1 A = \ (A \ P)" +proof - + have "A\P \ sets M" using assms unfolding hahn_space_decomp_def + by (simp add: pos_meas_setD1 sets.Int) + have "A\ N \ sets M" using assms unfolding hahn_space_decomp_def + by (simp add: neg_meas_setD1 sets.Int) + have "(A \ P) \ (A\ N) = {}" using assms unfolding hahn_space_decomp_def + by auto + have "A = (A \ P) \ (A\ N)" using assms unfolding hahn_space_decomp_def + by (metis Int_Un_distrib sets.Int_space_eq2) + hence "m1 A = m1 ((A \ P) \ (A\ N))" by simp + also have "... = m1 (A \ P) + m1 (A \ N)" + using assms pos_e2ennreal_additive[of M m1] \A\P \ sets M\ \A\N \ sets M\ + \A \ P \ (A \ N) = {}\ + unfolding jordan_decomp_def additive_def by simp + also have "... = m1 (A \ P)" using assms unfolding jordan_decomp_def + by (metis Int_lower2 \A \ N \ sets M\ add.right_neutral) + also have "... = m1 (A \ P) - m2 (A \ P)" + using assms unfolding jordan_decomp_def + by (metis Int_subset_iff \A \ P \ sets M\ ereal_minus(7) + local.pos_wtn_base pos_wtn_subset) + also have "... = \ (A \ P)" using assms \A \ P \ sets M\ + unfolding jordan_decomp_def by simp + finally show ?thesis . +qed + +lemma jordan_decomp_neg_meas: + assumes "jordan_decomp m1 m2" + and "hahn_space_decomp P N" + and "A \ sets M" + shows "m2 A = -\ (A \ N)" +proof - + have "A\P \ sets M" using assms unfolding hahn_space_decomp_def + by (simp add: pos_meas_setD1 sets.Int) + have "A\ N \ sets M" using assms unfolding hahn_space_decomp_def + by (simp add: neg_meas_setD1 sets.Int) + have "(A \ P) \ (A\ N) = {}" + using assms unfolding hahn_space_decomp_def by auto + have "A = (A \ P) \ (A\ N)" + using assms unfolding hahn_space_decomp_def + by (metis Int_Un_distrib sets.Int_space_eq2) + hence "m2 A = m2 ((A \ P) \ (A\ N))" by simp + also have "... = m2 (A \ P) + m2 (A \ N)" + using pos_e2ennreal_additive[of M m2] assms + \A\P \ sets M\ \A\N \ sets M\ \A \ P \ (A \ N) = {}\ + unfolding jordan_decomp_def additive_def by simp + also have "... = m2 (A \ N)" using assms unfolding jordan_decomp_def + by (metis Int_lower2 \A \ P \ sets M\ add.commute add.right_neutral) + also have "... = m2 (A \ N) - m1 (A \ N)" + using assms unfolding jordan_decomp_def + by (metis Int_lower2 \A \ N \ sets M\ ereal_minus(7)) + also have "... = -\ (A \ N)" using assms \A \ P \ sets M\ + unfolding jordan_decomp_def + by (metis Diff_cancel Diff_eq_empty_iff Int_Un_eq(2) \A \ N \ sets M\ + \m2 (A \ N) = m2 (A \ N) - m1 (A \ N)\ ereal_minus(8) + ereal_uminus_eq_reorder sup.bounded_iff) + finally show ?thesis . +qed + +lemma pos_inter_neg_0: + assumes "hahn_space_decomp M1 M2" + and "hahn_space_decomp P N" + and "A \ sets M" + and "A \ N" + shows "\ (A \ M1) = 0" +proof - + have "\ (A \ M1) = \ (A \ ((M1 \ P) \ (M1 \ (sym_diff M1 P))))" + by (metis Diff_subset_conv Int_Un_distrib Un_upper1 inf.orderE) + also have "... = \ ((A \ (M1 \ P)) \ (A \ (M1 \ (sym_diff M1 P))))" + by (simp add: Int_Un_distrib) + also have "... = \ (A \ (M1 \ P)) + \ (A \ (M1 \ (sym_diff M1 P)))" + proof (rule signed_measure_add) + show "signed_measure M \" using sgn_meas . + show "A \ (M1 \ P) \ sets M" + by (meson assms(1) assms(2) assms(3) hahn_space_decomp_def sets.Int + signed_measure_space.pos_meas_setD1 signed_measure_space_axioms) + show "A \ (M1 \ sym_diff M1 P) \ sets M" + by (meson Diff_subset assms(1) assms(2) assms(3) hahn_space_decomp_def + pos_meas_setD1 pos_meas_set_union pos_meas_subset sets.Diff sets.Int) + show "A \ (M1 \ P) \ (A \ (M1 \ sym_diff M1 P)) = {}" by auto + qed + also have "... = \ (A \ (M1 \ (sym_diff M1 P)))" + proof - + have "A \ (M1 \ P) = {}" using assms hahn_space_decomp_def by auto + thus ?thesis using signed_measure_empty[OF sgn_meas] by simp + qed + also have "... = 0" + proof (rule hahn_decomp_ess_unique[OF assms(1) assms(2)]) + show "A \ (M1 \ sym_diff M1 P) \ sym_diff M1 P \ sym_diff M2 N" by auto + show "A \ (M1 \ sym_diff M1 P) \ sets M" + proof - + have "sym_diff M1 P \ sets M" using assms + by (meson hahn_space_decomp_def sets.Diff sets.Un + signed_measure_space.pos_meas_setD1 signed_measure_space_axioms) + hence "M1 \ sym_diff M1 P \ sets M" + by (meson assms(1) hahn_space_decomp_def pos_meas_setD1 sets.Int) + thus ?thesis by (simp add: assms sets.Int) + qed + qed + finally show ?thesis . +qed + +lemma neg_inter_pos_0: + assumes "hahn_space_decomp M1 M2" + and "hahn_space_decomp P N" + and "A \ sets M" + and "A \ P" + shows "\ (A \ M2) = 0" +proof - + have "\ (A \ M2) = \ (A \ ((M2 \ N) \ (M2 \ (sym_diff M2 N))))" + by (metis Diff_subset_conv Int_Un_distrib Un_upper1 inf.orderE) + also have "... = \ ((A \ (M2 \ N)) \ (A \ (M2 \ (sym_diff M2 N))))" + by (simp add: Int_Un_distrib) + also have "... = \ (A \ (M2 \ N)) + \ (A \ (M2 \ (sym_diff M2 N)))" + proof (rule signed_measure_add) + show "signed_measure M \" using sgn_meas . + show "A \ (M2 \ N) \ sets M" + by (meson assms(1) assms(2) assms(3) hahn_space_decomp_def sets.Int + signed_measure_space.neg_meas_setD1 signed_measure_space_axioms) + show "A \ (M2 \ sym_diff M2 N) \ sets M" + by (meson Diff_subset assms(1) assms(2) assms(3) hahn_space_decomp_def + neg_meas_setD1 neg_meas_set_union neg_meas_subset sets.Diff sets.Int) + show "A \ (M2 \ N) \ (A \ (M2 \ sym_diff M2 N)) = {}" by auto + qed + also have "... = \ (A \ (M2 \ (sym_diff M2 N)))" + proof - + have "A \ (M2 \ N) = {}" using assms hahn_space_decomp_def by auto + thus ?thesis using signed_measure_empty[OF sgn_meas] by simp + qed + also have "... = 0" + proof (rule hahn_decomp_ess_unique[OF assms(1) assms(2)]) + show "A \ (M2 \ sym_diff M2 N) \ sym_diff M1 P \ sym_diff M2 N" by auto + show "A \ (M2 \ sym_diff M2 N) \ sets M" + proof - + have "sym_diff M2 N \ sets M" using assms + by (meson hahn_space_decomp_def sets.Diff sets.Un + signed_measure_space.neg_meas_setD1 signed_measure_space_axioms) + hence "M2 \ sym_diff M2 N \ sets M" + by (meson assms(1) hahn_space_decomp_def neg_meas_setD1 sets.Int) + thus ?thesis by (simp add: assms sets.Int) + qed + qed + finally show ?thesis . +qed + +lemma jordan_decomposition : + shows "\ m1 m2. jordan_decomp m1 m2" +proof - + have "\ M1 M2. hahn_space_decomp M1 M2" using hahn_decomposition + unfolding hahn_space_decomp_def by simp + from this obtain M1 M2 where "hahn_space_decomp M1 M2" by auto + note Mprops = this + define m1 where "m1 = (\A. \ (A \ M1))" + define m2 where "m2 = (\A. -\ (A \ M2))" + show ?thesis unfolding jordan_decomp_def + proof (intro exI allI impI conjI ballI) + show "measure_space (space M) (sets M) (\x. e2ennreal (m1 x))" + using pos_signed_to_meas_space Mprops m1_def + unfolding hahn_space_decomp_def by auto + next + show "measure_space (space M) (sets M) (\x. e2ennreal (m2 x))" + using neg_signed_to_meas_space Mprops m2_def + unfolding hahn_space_decomp_def by auto + next + fix A + assume "A\ sets M" + thus "0 \ m1 A" unfolding m1_def using Mprops + unfolding hahn_space_decomp_def + by (meson inf_sup_ord(2) pos_meas_setD1 sets.Int + signed_measure_space.pos_measure_meas signed_measure_space_axioms) + next + fix A + assume "A\ sets M" + thus "0 \ m2 A" unfolding m2_def using Mprops + unfolding hahn_space_decomp_def + by (metis ereal_0_le_uminus_iff inf_sup_ord(2) neg_meas_self + neg_meas_setD1 neg_meas_subset sets.Int) + next + fix A + assume "A \ sets M" + have "\ A = \ ((A \ M1) \ (A \ M2))" using Mprops + unfolding hahn_space_decomp_def + by (metis Int_Un_distrib \A \ sets M\ sets.Int_space_eq2) + also have "... = \ (A \ M1) + \ (A \ M2)" + proof (rule signed_measure_add) + show "signed_measure M \" using sgn_meas . + show "A \ M1 \ sets M" using Mprops \A \ sets M\ + unfolding hahn_space_decomp_def + by (simp add: pos_meas_setD1 sets.Int) + show "A \ M2 \ sets M" using Mprops \A \ sets M\ + unfolding hahn_space_decomp_def + by (simp add: neg_meas_setD1 sets.Int) + show "A \ M1 \ (A \ M2) = {}" using Mprops + unfolding hahn_space_decomp_def by auto + qed + also have "... = m1 A - m2 A" using m1_def m2_def by simp + finally show "\ A = m1 A - m2 A" . + next + fix P N A + assume "hahn_space_decomp P N" and "A \ sets M" and "A \ N" + note hn = this + have "\ (A \ M1) = 0" + proof (rule pos_inter_neg_0[OF _ hn]) + show "hahn_space_decomp M1 M2" using Mprops + unfolding hahn_space_decomp_def by simp + qed + thus "m1 A = 0" unfolding m1_def by simp + next + fix P N A + assume "hahn_space_decomp P N" and "A \ sets M" and "A \ P" + note hp = this + have "\ (A \ M2) = 0" + proof (rule neg_inter_pos_0[OF _ hp]) + show "hahn_space_decomp M1 M2" using Mprops + unfolding hahn_space_decomp_def by simp + qed + thus "m2 A = 0" unfolding m2_def by simp + next + show "(\E\sets M. m1 E < \) \ (\E\sets M. m2 E < \)" + proof (cases "\ E \ sets M. m1 E < \") + case True + thus ?thesis by simp + next + case False + have "\ E \ sets M. m2 E < \" + proof + fix E + assume "E \ sets M" + show "m2 E < \" + proof - + have "(m2 E) = -\ (E \ M2)" using m2_def by simp + also have "... \ \" using False sgn_meas inf_range + by (metis ereal_less_PInfty ereal_uminus_uminus m1_def rangeI) + finally have "m2 E \ \" . + thus ?thesis by (simp add: top.not_eq_extremum) + qed + qed + thus ?thesis by simp + qed + qed +qed + +lemma jordan_decomposition_unique : + assumes "jordan_decomp m1 m2" + and "jordan_decomp n1 n2" + and "A \ sets M" + shows "m1 A = n1 A" "m2 A = n2 A" +proof - + have "\ M1 M2. hahn_space_decomp M1 M2" using hahn_decomposition by simp + from this obtain M1 M2 where "hahn_space_decomp M1 M2" by auto + note mprop = this + have "m1 A = \ (A \ M1)" using assms jordan_decomp_pos_meas mprop by simp + also have "... = n1 A" using assms jordan_decomp_pos_meas[of n1] mprop + by simp + finally show "m1 A = n1 A" . + have "m2 A = -\ (A \ M2)" using assms jordan_decomp_neg_meas mprop by simp + also have "... = n2 A" using assms jordan_decomp_neg_meas[of n1] mprop + by simp + finally show "m2 A = n2 A" . +qed +end +end + diff --git a/thys/Hahn_Jordan_Decomposition/Hahn_Jordan_Prelims.thy b/thys/Hahn_Jordan_Decomposition/Hahn_Jordan_Prelims.thy new file mode 100644 --- /dev/null +++ b/thys/Hahn_Jordan_Decomposition/Hahn_Jordan_Prelims.thy @@ -0,0 +1,378 @@ +theory Hahn_Jordan_Prelims imports + "HOL-Analysis.Analysis" + Extended_Reals_Sums_Compl +begin + +section \Preliminary results\ + +lemma diff_union: + shows "A - (\ i \ n. B i) - B (Suc n) = A - (\ i \ (Suc n). B i)" + using atMost_Suc by auto + +lemma disj_subsets: + assumes "B 0 = A 0" + and "\(i::nat). B (Suc i) = A (Suc i) - (\ j\{..i}. A j)" + shows "(\i. B i) = (\i. A i)" +proof + have "B i \ A i" for i + proof (cases "i = 0") + case True + thus ?thesis using assms by simp + next + case False + hence "\j. i = Suc j" by (simp add: not0_implies_Suc) + from this obtain j where "i = Suc j" by auto + thus "B i \ A i" using assms by auto + qed + thus "\ (range B) \ \ (range A)" by auto +next + have ale: "\n. A (Suc n) \ B (Suc n) \ (\ j\{0..n}. A j)" using assms by auto + have inc: "\n. (\ i\ {0..n}. A i) \ (\ i \ {0..n}. B i)" + proof - + fix n + show "(\ i\ {0..n}. A i) \ (\ i \ {0..n}. B i)" + proof (induct n) + case 0 + then show ?case using assms by auto + next + case (Suc n) + have "\ (A ` {0..Suc n}) = (\ (A ` {0.. n})) \ A (Suc n)" + by (simp add: Un_commute atLeast0_atMost_Suc) + also have "... \ (\ (B ` {0.. n})) \ A (Suc n)" using Suc by auto + also have "... \ (\ (B ` {0.. n})) \ B (Suc n) \ (\ j\{0..n}. A j)" using ale by auto + also have "... \ (\ (B ` {0.. n})) \ B (Suc n) \ (\ (B ` {0.. n}))" using Suc by auto + also have "... = (\ (B ` {0.. n})) \ B (Suc n)" by auto + also have "... = (\ (B ` {0.. Suc n}))" by (simp add: Un_commute atLeast0_atMost_Suc) + finally show ?case . + qed + qed + have "\n. (\ i\ {0.. (\ i \ {0.. i\ {0.. (\ i \ {0..m. n = Suc m" by (simp add: not0_implies_Suc) + from this obtain m where "n = Suc m" by auto + hence "{0.. i\ {0..m}. A i) \ (\ i \ {0..m}. B i)" using inc by simp + thus ?thesis using \{0.. by simp + qed + qed + thus "\ (range A) \ \ (range B)" using UN_finite2_subset[of A B 0] by simp +qed + +lemma disj_Union2: + assumes "\i. A i \ sets M" + obtains B where "disjoint_family B" and "(\(i::nat). B i) = (\(i::nat). A i)" + and "\i. B i \ sets M" and "\i. B i \ A i" +proof + define B where "B = (\(i::nat). A i - (\ j\{..i. B i \ A i" + proof - + fix i + show "B i \ A i" + proof (cases "i = 0") + case True + thus ?thesis unfolding B_def by simp + next + case False + hence "\j. i = Suc j" by (simp add: not0_implies_Suc) + from this obtain j where "i = Suc j" by auto + thus "B i \ A i" unfolding B_def by auto + qed + qed + show "disjoint_family B" unfolding disjoint_family_on_def + proof - + { + fix n m::nat + assume "n (\ j\{..\i. B i \ A i\ by auto + hence "B n \ B m = {}" unfolding B_def by auto + } + thus "\m\UNIV. \n\UNIV. m \ n \ B m \ B n = {}" by (metis Int_commute antisym_conv3) + qed + show "(\(i::nat). B i) = (\(i::nat). A i)" + proof (rule disj_subsets) + show "B 0 = A 0" unfolding B_def by simp + show "\i. B (Suc i) = A (Suc i) - \ (A ` {..i})" unfolding B_def by auto + qed + show "\i. B i \ sets M" unfolding B_def using assms by auto +qed + +lemma conv_0_half: + assumes "f \ (0::real)" + and "\n. 0 \ f n" + shows "\N. \n \ N. f n < 1/2" +proof - + have "\r>0. \no. \n\no. dist (f n) 0 < r" using assms by (simp add: lim_sequentially) + hence "\no. \n\ no. dist (f n) 0 < 1/2" using half_gt_zero_iff zero_less_one by blast + from this obtain N where "\n \ N. dist (f n) 0 < 1/2" by auto + have "\n. dist (f n) 0 = f n" using assms + proof - + fix n + have "dist (f n) 0 = \f n\" by simp + also have "... = f n" using assms by simp + finally show "dist (f n) 0 = f n" . + qed + hence "\n \ N. f n < 1/2" using \\n \ N. dist (f n) 0 < 1/2\ by simp + thus ?thesis by auto +qed + +lemma e2ennreal_add: + fixes x::ereal + assumes "0 \ x" + and "0 \ y" + shows "e2ennreal (x+y) = e2ennreal x + e2ennreal y" +proof (rule ereal_ennreal_cases[of x]) + show "x < 0 \ e2ennreal (x + y) = e2ennreal x + e2ennreal y" using assms by simp + show "\b. 0 \ x \ x = enn2ereal b \ e2ennreal (x + y) = e2ennreal x + e2ennreal y" + proof - + fix b + assume "0 \ x" and "x = enn2ereal b" + hence "e2ennreal x= b" by simp + show "e2ennreal (x + y) = e2ennreal x + e2ennreal y" + proof (rule ereal_ennreal_cases[of y]) + show "y < 0 \ e2ennreal (x + y) = e2ennreal x + e2ennreal y" using assms by simp + show "\b. 0 \ y \ y = enn2ereal b \ e2ennreal (x + y) = e2ennreal x + e2ennreal y" + proof - + fix c + assume "0 \ y" and "y = enn2ereal c" + hence "e2ennreal y = c" by simp + show "e2ennreal (x + y) = e2ennreal x + e2ennreal y" + proof (rule ereal_ennreal_cases[of "x+y"]) + show "x + y < 0 \ e2ennreal (x + y) = e2ennreal x + e2ennreal y" using assms + by (simp add: leD) + show "\b. 0 \ x + y \ x + y = enn2ereal b \ e2ennreal (x + y) = + e2ennreal x + e2ennreal y" + proof - + fix d + assume "0 \ x+y" and "x+y = enn2ereal d" + hence "e2ennreal (x+y) = d" by simp + show "e2ennreal (x + y) = e2ennreal x + e2ennreal y" + using \e2ennreal (x+y) = d\ \e2ennreal x= b\ \e2ennreal y= c\ + by (metis \x = enn2ereal b\ \y = enn2ereal c\ e2ennreal_enn2ereal plus_ennreal.rep_eq) + qed + qed + qed + qed + qed +qed + +lemma e2ennreal_finite_sum: + shows "finite I \ (\i. i\ I \ 0 \ ((A i)::ereal)) \ +(\ i\ I. e2ennreal (A i)) = e2ennreal (\i\ I. A i)" +proof (induct rule: finite_induct) + case empty + then show ?case by (simp add: zero_ennreal.abs_eq) +next + case (insert x F) + hence "(\ i\ (insert x F). e2ennreal (A i)) = e2ennreal (A x) + (\ i\ F. e2ennreal (A i))" + by simp + also have "... = e2ennreal (A x) + e2ennreal (\i\ F. A i)" using insert by simp + also have "... = e2ennreal (A x + (\i\ F. A i))" + proof (rule e2ennreal_add[symmetric]) + show "0 \ A x" using insert by simp + show "0 \ sum A F" using insert by (simp add: sum_nonneg) + qed + also have "... = e2ennreal (\i\ insert x F. A i)" using insert by simp + finally show ?case . +qed + +lemma e2ennreal_less_top: + fixes x::ereal + assumes "x < \" + shows "e2ennreal x < \" +proof (rule ereal_ennreal_cases[of x]) + assume "x < 0" + hence "e2ennreal x = 0" using e2ennreal_neg by simp + thus "e2ennreal x < \" by simp +next + fix b + assume "0 \ x" and "x = enn2ereal b" + hence "b = e2ennreal x" by simp + have "b < \" + proof (rule ccontr) + assume "\ b < \" + hence "b = \" by (simp add: less_ennreal.rep_eq) + hence "x = \" using enn2ereal_eq_top_iff \x = enn2ereal b\ by simp + thus False using assms by simp + qed + thus "e2ennreal x < \" using \b = e2ennreal x\ by simp +qed + +lemma pos_e2ennreal_additive: + assumes "measure_space (space M) (sets M) (\x. e2ennreal (m1 x))" + and "\x\ sets M. 0 \ m1 x" + shows "additive (sets M) m1" +proof (auto simp add: additive_def) + fix A B + assume "A\ sets M" and "B\ sets M" and "A\ B = {}" note abprops = this + define M1 where "M1 = (\x. e2ennreal (m1 x))" + have "additive (sets M) M1" using ring_of_sets.countably_additive_additive + sets.ring_of_sets_axioms assms unfolding measure_space_def M1_def by auto + have "A\B \ sets M" using abprops by simp + hence "m1 (A\ B) = enn2ereal (M1 (A\ B))" unfolding M1_def using assms enn2ereal_e2ennreal + abprops by presburger + also have "... = enn2ereal (M1 A + M1 B)" using \additive (sets M) M1\ abprops + unfolding additive_def by simp + also have "... = enn2ereal (M1 A) + enn2ereal (M1 B)" by (simp add: plus_ennreal.rep_eq) + also have "... = m1 A + m1 B" unfolding M1_def using assms enn2ereal_e2ennreal + abprops by presburger + finally show "m1 (A\ B) = m1 A + m1 B" . +qed + +subsection \Some summability properties\ + +lemma shift_denum: + shows "1/(x i - (1::nat)) \ 2/x i" +proof (cases "x i \ 1") + case True + hence "x i - 1 = 0" by simp + thus ?thesis by simp +next + case False + hence "2 \ x i" by simp + hence "0 < x i * (x i - 1)" by simp + hence "0 \ (2 * (x i - 1) - x i)/(x i * (x i - 1))" using \2 \ x i\ by simp + also have "... = (real (2 * (x i - 1)) - real (x i))/(x i * (x i - 1))" + using of_nat_diff by auto + also have "... = (2 * (x i - 1))/(x i * (x i - 1)) - x i/(x i * (x i - 1))" + using diff_divide_distrib[of "2 * (x i - 1)" "x i" "x i * (x i - 1)"] by simp + also have "... = 2/x i - x i/(x i * (x i - 1))" using \2 \ x i\ by auto + also have "... = 2/x i - 1/(x i - 1)" by simp + finally have "0 \ 2/x i - 1/(x i - 1)" . + thus ?thesis by simp +qed + +lemma shift_denum': + assumes "\i. k \ x i \ k +e \ ((x i)::nat)" + and "\i. 0 < x i" + and "\i. x i < p" + and "0 < e" + shows "\c. \i. 1/(x i - k) \ c/(x i)" +proof + have "\i. k \ x i \ e \ x i - k" + proof - + fix i + assume "k \ x i" + hence "k + e \ x i" using assms by simp + thus "e \ x i - k" using assms by simp + qed + have "\i. k \ x i \ 0 < (x i)*(x i - k)" + proof - + fix i + assume "k \ x i" + thus "0 < (x i)*(x i - k)" using assms by force + qed + define cw where "cw = p/e" + have "0 < p" using assms using neq0_conv by blast + hence "0 < cw" unfolding cw_def by (simp add: assms(4)) + show "\i. 1 / (x i - k) \ cw / x i" + proof + fix i + show "1 / (x i - k) \ cw / x i" + proof (cases "k \ x i") + case True + hence "0 \ (p - x i)/((x i) * (x i - k))" using \\i. k \ x i \0 < x i * (x i - k)\ assms(3) + divide_nonneg_pos[of "p - x i" "x i * (x i - k)"] by (simp add: less_eq_real_def) + also have "... = (cw * e - x i)/((x i) * (x i - k))" unfolding cw_def using assms True + by (metis divide_less_cancel division_ring_divide_zero eq_divide_imp nat_less_le + of_nat_0_less_iff of_nat_diff times_divide_eq_left) + also have "... \ (cw * (x i - k) - x i)/((x i) * (x i - k))" + proof - + have "cw * (x i - k) - x i \ cw * e - x i" using \k \ x i \ e \ x i - k\ \0 < cw\ True + by simp + thus ?thesis using \k \ x i \ 0 < (x i)*(x i - k)\ + divide_right_mono[of "cw * e - x i" "cw * (x i - k) - x i" "(x i) * (x i - k)"] by simp + qed + also have "... = (cw * (x i -k))/((x i)*(x i - k)) - x i/((x i) * (x i - k))" + using assms diff_divide_distrib by blast + also have "... = cw / x i - 1/(x i-k)" + proof - + have "1/(x i-k) = x i/((x i) * (x i - k))" using assms(2) less_imp_neq by fastforce + thus ?thesis using \\i. k \ x i \ 0 < x i * (x i - k)\ assms(2) zero_less_mult_pos + proof - + have f1: "\r ra. (1::real) / (ra / r) = r / ra" + by simp + have "real (x i * (x i - k)) \ 0" + by (metis True \\i. k \ x i \ 0 < x i * (x i - k)\ neq0_conv of_nat_0 of_nat_le_0_iff) + thus ?thesis using f1 by (metis \1 / real (x i - k) = real (x i) / real (x i * (x i - k))\ + div_by_1 divide_divide_eq_right nonzero_mult_div_cancel_left) + qed + qed + finally have "0 \ cw / x i - 1/(x i-k)" . + thus "1 / (x i - k) \ cw / x i" by simp + next + case False + hence "real (x i - k) = 0" by simp + hence "1/ real (x i - k) = 0" by simp + thus "1 / real (x i - k) \ cw / real (x i)" by (simp add: cw_def) + qed + qed +qed + +lemma sum_le: + assumes "\i. f i \ ((g i) :: real)" + shows "sum f {.. (n::nat)} \ sum g {.. n}" +proof (induct n) + case 0 + then show ?case using assms by simp +next + case (Suc n) + have "sum f {..Suc n} = sum f {.. n} + f (Suc n)" by simp + also have "... \ sum g {.. n} + f (Suc n)" using Suc by simp + also have "... \ sum g {.. n} + g (Suc n)" using assms by simp + also have "... = sum g {.. Suc n}" by simp + finally show ?case . +qed + +lemma summable_bounded: + assumes "\i. 0 \ ((f i)::real)" + and "\i. f i \ g i" + and "summable g" + shows "summable f" +proof (rule bounded_imp_summable, (auto simp add: assms)) + fix n + have "\i. 0 \ g i" using assms dual_order.trans by blast + have "sum f {.. n} \ sum g {.. n}" using assms sum_le by simp + also have "... \ suminf g" by (rule sum_le_suminf, (auto simp add: assms \\i. 0 \ g i\)) + finally show "sum f {.. n} \ suminf g" . +qed + +lemma sum_shift_denum: + assumes "summable (\i. 1/((f i)::nat))" + shows "summable (\i. 1/(f i - 1))" +proof - + have "\i. 1/(f i - 1) \ 2 / f i" using shift_denum[of f] by auto + have "summable (\i. 2/ f i)" using assms summable_mult[of "\n. 1/ f n"] by simp + thus ?thesis using summable_bounded[of "\i. 1/(f i - 1)" "\i. 2 * 1/f i"] + \\i. 1 / real (f i - 1) \ 2 / real (f i)\ by auto +qed + +lemma sum_shift_denum': + assumes "summable (\i. 1/(f i))" + and "0 < e" + and "\i. k \ f i \ k + e \ ((f i)::nat)" + and "\i. 0 < f i" + and "\i. f i < p" + shows "summable (\i. 1/(f i - k))" +proof - + have "\i. 0 \ 1/(f i - k)" + proof - + fix i + have "0 \ f i - k" using assms by simp + thus "0 \ 1/(f i - k)" by simp + qed + have "\c. \i. 1/(f i - k) \ c / f i" using shift_denum'[of k f e p] assms by simp + from this obtain c where "\i. 1/(f i - k) \ c / f i" by auto + have "summable (\i. c * 1/ f i)" using assms summable_mult[of "\n. 1/ f n"] by simp + thus ?thesis using summable_bounded[of "\i. 1/(f i - k)" "\i. c * 1/f i"] + \\i. 0 \ 1/(f i - k)\ by (simp add: \\i. 1 / (f i - k) \ c / f i\) +qed + +end \ No newline at end of file diff --git a/thys/Hahn_Jordan_Decomposition/ROOT b/thys/Hahn_Jordan_Decomposition/ROOT new file mode 100644 --- /dev/null +++ b/thys/Hahn_Jordan_Decomposition/ROOT @@ -0,0 +1,12 @@ +chapter AFP + +session Hahn_Jordan_Decomposition(AFP) = "HOL-Probability" + + options [timeout = 600] + theories [document = false] + Extended_Reals_Sums_Compl + Hahn_Jordan_Prelims + theories + Hahn_Jordan_Decomposition + document_files + "root.bib" + "root.tex" diff --git a/thys/Hahn_Jordan_Decomposition/document/root.bib b/thys/Hahn_Jordan_Decomposition/document/root.bib new file mode 100644 --- /dev/null +++ b/thys/Hahn_Jordan_Decomposition/document/root.bib @@ -0,0 +1,7 @@ +@book{benedetto, + author = {DiBenedetto,Emmanuele}, + title = {Real {A}nalysis}, + date = {2002}, + series = {Birkh\"auser {A}dvanced {T}exts}, + publisher = {Birkh\"auser} +} diff --git a/thys/Hahn_Jordan_Decomposition/document/root.tex b/thys/Hahn_Jordan_Decomposition/document/root.tex new file mode 100644 --- /dev/null +++ b/thys/Hahn_Jordan_Decomposition/document/root.tex @@ -0,0 +1,46 @@ +\documentclass[11pt,a4paper]{article} +\usepackage{isabelle,isabellesym} + +\usepackage{url} +\usepackage{amssymb} +\usepackage{xspace} +\usepackage{amsmath} + +% this should be the last package used +\usepackage{pdfsetup} + +% urls in roman style, theory text in math-similar italics +\urlstyle{rm} +\isabellestyle{it} + +\newcommand\isafor{\textsf{Isa\kern-0.15exF\kern-0.15exo\kern-0.15exR}} +\newcommand\ceta{\textsf{C\kern-0.15exe\kern-0.45exT\kern-0.45exA}} + +\begin{document} + +\title{The Hahn and Jordan Decomposition Theorems} +\author{Marie Cousin \and Mnacho Echenim \and Herv\'e Guiol} +\maketitle + +%\begin{abstract} +%We present formalizations of both the Hahn and Jordan decomposition theorems for signed measures. +%\end{abstract} + +\tableofcontents + +\section{Introduction} + +Signed measures are a generalization of measures that can map measurable sets to negative values. In this work we formalize the Hahn decomposition theorem for signed measures, namely that if $(\Omega, \mathcal{A}, \mu)$ is a measure space for a signed measure $\mu$, then $\Omega$ can be decomposed as $\Omega^+ \cup \Omega^-$, where every measurable subset of $\Omega^+$ has a positive measure, and every measurable subset of $\Omega^-$ has a negative measure. We then prove that this decomposition is essentially unique, meaning that if $X^+ \cup X^-$ is another such decomposition, then any measurable subset in $(\Omega^+\triangle X^+) \cup (\Omega^- \triangle X^-)$ has a zero measure. + +We also formalize the Jordan decomposition theorem as a corollary, which states that the signed measure $\mu$ admits a unique decomposition into a difference $\mu = \mu^+ - \mu^-$ of two positive measures, at least one of which is finite, and such that for any Hahn decomposition $\Omega^+ \cup \Omega^-$ and measurable set $A$, if $A\subseteq \Omega^-$ then $\mu^+(A) = 0$ and if $A\subseteq \Omega^+$ then $\mu^-(A) = 0$. +The formalization is mostly based on \cite{benedetto}, Section 16 of Chapter 4. + +\input{session} + + + +\bibliographystyle{abbrv} +\bibliography{root} + +\end{document} + diff --git a/thys/ROOTS b/thys/ROOTS --- a/thys/ROOTS +++ b/thys/ROOTS @@ -1,640 +1,643 @@ ADS_Functor AI_Planning_Languages_Semantics AODV AVL-Trees AWN Abortable_Linearizable_Modules Abs_Int_ITP2012 Abstract-Hoare-Logics Abstract-Rewriting Abstract_Completeness Abstract_Soundness Adaptive_State_Counting Affine_Arithmetic Aggregation_Algebras Akra_Bazzi Algebraic_Numbers Algebraic_VCs Allen_Calculus Amicable_Numbers Amortized_Complexity AnselmGod Applicative_Lifting Approximation_Algorithms Architectural_Design_Patterns Aristotles_Assertoric_Syllogistic Arith_Prog_Rel_Primes ArrowImpossibilityGS Attack_Trees Auto2_HOL Auto2_Imperative_HOL AutoFocus-Stream Automated_Stateful_Protocol_Verification Automatic_Refinement AxiomaticCategoryTheory BDD 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 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 CoSMed CoSMeDis 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 Ergodic_Theory Error_Function Euler_MacLaurin Euler_Partition Example-Submission Extended_Finite_State_Machine_Inference Extended_Finite_State_Machines FFT FLP FOL-Fitting FOL_Axiomatic FOL_Harrison FOL_Seq_Calc1 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 Fourier Free-Boolean-Algebra Free-Groups Fresh_Identifiers FunWithFunctions FunWithTilings Functional-Automata Functional_Ordered_Resolution_Prover Furstenberg_Topology GPU_Kernel_PL Gabow_SCC GaleStewart_Games 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 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 Interpreter_Optimizations Interval_Arithmetic_Word32 Intro_Dest_Elim Iptables_Semantics Irrational_Series_Erdos_Straus Irrationality_J_Hancl 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 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 Lucas_Theorem MFMC_Countable MFODL_Monitor_Optimized MFOTL_Monitor MSO_Regex_Equivalence Markov_Models Marriage Mason_Stothers Matrices_for_ODEs Matrix Matrix_Tensor Matroids Max-Card-Matching Median_Of_Medians_Selection Menger Mereology Mersenne_Primes 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 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 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 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 +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 Szpilrajn Szemeredi_Regularity 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_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 WHATandWHERE_Security WOOT_Strong_Eventual_Consistency WebAssembly Weighted_Path_Order Weight_Balanced_Trees Well_Quasi_Orders Winding_Number_Eval Word_Lib WorkerWrapper X86_Semantics XML ZFC_in_HOL Zeta_3_Irrational Zeta_Function pGCL diff --git a/thys/SimplifiedOntologicalArgument/BaseDefs.thy b/thys/SimplifiedOntologicalArgument/BaseDefs.thy new file mode 100644 --- /dev/null +++ b/thys/SimplifiedOntologicalArgument/BaseDefs.thy @@ -0,0 +1,22 @@ +subsection\Preliminaries: Further Basic Notions (Fig.~3 in \cite{C85})\ + +theory BaseDefs imports HOML +begin +text\Positive properties.\ +consts posProp::"\\\" ("\

") + +text\Basic definitions for modal ontological argument.\ +abbreviation a ("_\<^bold>\_") where "X\<^bold>\Y \ \<^bold>\\<^sup>Ez.((X z) \<^bold>\ (Y z))" +abbreviation b ("_\_") where "X\Y \ \<^bold>\(X\<^bold>\Y)" +abbreviation c ("\

\\") where "\

\\ Z \ \<^bold>\X.((Z X) \<^bold>\ (\

X))" +abbreviation d ("_\_") where "X\\ \ \<^bold>\(\<^bold>\\<^sup>Eu.((X u) \<^bold>\ (\<^bold>\Y.((\ Y) \<^bold>\ (Y u)))))" + +text\Definition of Godlike.\ +definition G ("\") where "\ x \ \<^bold>\Y.((\

Y) \<^bold>\ (Y x))" + +text\Definitions of Essence and Necessary Existence.\ +definition E ("\") where "\ Y x \ (Y x) \<^bold>\ (\<^bold>\Z.((Z x) \<^bold>\ (Y\Z)))" +definition NE ("\\") where "\\ x \ \<^bold>\Y.((\ Y x) \<^bold>\ \<^bold>\(\<^bold>\\<^sup>E Y))" +end + + diff --git a/thys/SimplifiedOntologicalArgument/DisableKodkodScala.thy b/thys/SimplifiedOntologicalArgument/DisableKodkodScala.thy new file mode 100644 --- /dev/null +++ b/thys/SimplifiedOntologicalArgument/DisableKodkodScala.thy @@ -0,0 +1,14 @@ +theory DisableKodkodScala + imports Main +begin + +text \Some of the nitpick invocation within this AFP entry do not work, + if "Kodkod Scala" is enabled, i.e., if the box under + Plugin Options — Isabelle — General — Miscelleaneous Tools — Kodkod Scala + is activated. Therefore, in this theory we explicitly disable this configuration option.\ + +ML \ + Options.default_put_bool \<^system_option>\kodkod_scala\ false +\ + +end \ No newline at end of file diff --git a/thys/SimplifiedOntologicalArgument/HOML.thy b/thys/SimplifiedOntologicalArgument/HOML.thy new file mode 100644 --- /dev/null +++ b/thys/SimplifiedOntologicalArgument/HOML.thy @@ -0,0 +1,53 @@ +section\Higher-Order Modal Logic in HOL (cf.~\cite{J23} and Fig.~1 in \cite{C85}).\ + +theory HOML imports Main +begin +nitpick_params[user_axioms,expect=genuine] + +text\Type i is associated with possible worlds and type e with entities:\ +typedecl i \\Possible worlds\ +typedecl e \\Individuals\ +type_synonym \ = "i\bool" \\World-lifted propositions\ +type_synonym \ = "e\\" \\Lifted predicates\ +type_synonym \ = "\\\" \\Unary modal connectives\ +type_synonym \ = "\\\\\" \\Binary modal connectives\ + +text\Logical connectives (operating on truth-sets):\ +abbreviation c1::\ ("\<^bold>\") where "\<^bold>\ \ \w. False" +abbreviation c2::\ ("\<^bold>\") where "\<^bold>\ \ \w. True" +abbreviation c3::\ ("\<^bold>\_"[52]53) where "\<^bold>\\ \ \w.\(\ w)" +abbreviation c4::\ (infix"\<^bold>\"50) where "\\<^bold>\\ \ \w.(\ w)\(\ w)" +abbreviation c5::\ (infix"\<^bold>\"49) where "\\<^bold>\\ \ \w.(\ w)\(\ w)" +abbreviation c6::\ (infix"\<^bold>\"48) where "\\<^bold>\\ \ \w.(\ w)\(\ w)" +abbreviation c7::\ (infix"\<^bold>\"47) where "\\<^bold>\\ \ \w.(\ w)\(\ w)" +consts R::"i\i\bool" ("_\<^bold>r_") \\Accessibility relation\ +abbreviation c8::\ ("\<^bold>\_"[54]55) where "\<^bold>\\ \ \w.\v.(w\<^bold>rv)\(\ v)" +abbreviation c9::\ ("\<^bold>\_"[54]55) where "\<^bold>\\ \ \w.\v.(w\<^bold>rv)\(\ v)" +abbreviation c10::"\\\" ("\<^bold>\_"[52]53) where "\<^bold>\\ \ \x.\w.\(\ x w)" +abbreviation c11::"\\\" ("\<^bold>\_") where "\<^bold>\\ \ \x.\w.\(\ x w)" +abbreviation c12::"e\e\\" ("_\<^bold>=_") where "x\<^bold>=y \ \w.(x=y)" +abbreviation c13::"e\e\\" ("_\<^bold>\_") where "x\<^bold>\y \ \w.(x\y)" + +text\Polymorphic possibilist quantification:\ +abbreviation q1::"('a\\)\\" ("\<^bold>\") where "\<^bold>\\ \ \w.\x.(\ x w)" +abbreviation q2 (binder"\<^bold>\"[10]11) where "\<^bold>\x. \(x) \ \<^bold>\\" +abbreviation q3::"('a\\)\\" ("\<^bold>\") where "\<^bold>\\ \ \w.\x.(\ x w)" +abbreviation q4 (binder"\<^bold>\"[10]11) where "\<^bold>\x. \(x) \ \<^bold>\\" + +text\Actualist quantification for individuals/entities:\ +consts existsAt::\ ("_\<^bold>@_") +abbreviation q5::"\\\" ("\<^bold>\\<^sup>E") where "\<^bold>\\<^sup>E\ \ \w.\x.(x\<^bold>@w)\(\ x w)" +abbreviation q6 (binder"\<^bold>\\<^sup>E"[8]9) where "\<^bold>\\<^sup>Ex. \(x) \ \<^bold>\\<^sup>E\" +abbreviation q7::"\\\" ("\<^bold>\\<^sup>E") where "\<^bold>\\<^sup>E\ \ \w.\x.(x\<^bold>@w)\(\ x w)" +abbreviation q8 (binder"\<^bold>\\<^sup>E"[8]9) where "\<^bold>\\<^sup>Ex. \(x) \ \<^bold>\\<^sup>E\" + +text\Meta-logical predicate for global validity:\ +abbreviation g1::"\\bool" ("\_\") where "\\\ \ \w. \ w" + +text\Barcan and converse Barcan formula:\ +lemma True nitpick[satisfy] oops \\Model found by Nitpick\ +lemma "\(\<^bold>\\<^sup>Ex.\<^bold>\(\ x)) \<^bold>\ \<^bold>\(\<^bold>\\<^sup>Ex.(\ x))\" nitpick oops \\Ctm\ +lemma "\\<^bold>\(\<^bold>\\<^sup>Ex.(\ x)) \<^bold>\ (\<^bold>\\<^sup>Ex.\<^bold>\(\ x))\" nitpick oops \\Ctm\ +lemma "\(\<^bold>\x.\<^bold>\(\ x)) \<^bold>\ \<^bold>\(\<^bold>\x. \ x)\" by simp +lemma "\\<^bold>\(\<^bold>\x.(\ x)) \<^bold>\ (\<^bold>\x.\<^bold>\(\ x))\" by simp +end diff --git a/thys/SimplifiedOntologicalArgument/KanckosLethenNo2Possibilist.thy b/thys/SimplifiedOntologicalArgument/KanckosLethenNo2Possibilist.thy new file mode 100644 --- /dev/null +++ b/thys/SimplifiedOntologicalArgument/KanckosLethenNo2Possibilist.thy @@ -0,0 +1,91 @@ +subsection\Formal Study of Version No.2 of Gödel’s Argument as + Reported by Kanckos and Lethen, 2019 \cite{KanckosLethen19} (Fig.~11 in \cite{C85})\ + +theory KanckosLethenNo2Possibilist imports + HOML + MFilter + BaseDefs +begin +text\Axioms of Version No. 2 \cite{KanckosLethen19}.\ +abbreviation delta ("\") where "\ A \ \x.(\<^bold>\\. ((A \) \<^bold>\ (\ x)))" +abbreviation N ("\") where "\ \ \ \x.(\<^bold>\(\ x))" + +axiomatization where + Axiom1: "\\<^bold>\\ \.(((\

\) \<^bold>\ (\<^bold>\(\<^bold>\x. ((\ x) \<^bold>\ (\ x))))) \<^bold>\ (\

\))\" and \\The \\<^bold>\\ can be omitted here; the proofs still work.\ + Axiom2: "\\<^bold>\A .(\<^bold>\((\<^bold>\\.((A \) \<^bold>\ (\

\))) \<^bold>\ (\

(\ A))))\" and \\The \\<^bold>\\ can be omitted here; the proofs still work.\ + Axiom3: "\\<^bold>\\.((\

\) \<^bold>\ (\

(\ \)))\" and + Axiom4: "\\<^bold>\\.((\

\) \<^bold>\ (\<^bold>\(\

(\<^bold>\\))))\" and + \\Logic S5\ + axB: "\\<^bold>\\.(\ \<^bold>\ \<^bold>\\<^bold>\\)\" and axM: "\\<^bold>\\.((\<^bold>\\) \<^bold>\ \)\" and ax4: "\\<^bold>\\.((\<^bold>\\) \<^bold>\ (\<^bold>\\<^bold>\\))\" + +text\Sahlqvist correspondences: they are better suited for proof automation.\ +lemma axB': "\x y. \(x\<^bold>ry) \ (y\<^bold>rx)" using axB by fastforce +lemma axM': "\x. (x\<^bold>rx)" using axM by blast +lemma ax4': "\x y z. (((x\<^bold>ry) \ (y\<^bold>rz)) \ (x\<^bold>rz))" using ax4 by auto + +text\Proofs for all theorems for No.2 from \cite{KanckosLethen19}.\ +theorem Theorem0: "\\<^bold>\\ \.((\<^bold>\Q. ((Q \) \<^bold>\ (Q \))) \<^bold>\ ((\

\) \<^bold>\ (\

\)))\" by auto \\not needed\ +theorem Theorem1: "\\

\\" unfolding G_def using Axiom2 axM by blast +theorem Theorem2: "\\<^bold>\x. ((\ x)\<^bold>\(\<^bold>\y. \ y))\" by blast \\not needed\ +theorem Theorem3a: "\\

(\x. (\<^bold>\y. \ y))\" by (metis (no_types, lifting) Axiom1 Theorem1) +theorem Theorem3b: "\\<^bold>\(\

(\x.(\<^bold>\(\<^bold>\y. \ y))))\" by (smt Axiom1 G_def Theorem3a Axiom3 Theorem1 axB') +theorem Theorem4: "\\<^bold>\x. \<^bold>\((\ x) \<^bold>\ ((\

(\x.(\<^bold>\(\<^bold>\y. \ y)))) \<^bold>\ (\<^bold>\(\<^bold>\y. \ y))))\" using G_def by fastforce \\not needed\ +theorem Theorem5: "\\<^bold>\x. \<^bold>\((\ x) \<^bold>\ (\<^bold>\(\<^bold>\y. \ y)))\" by (smt (verit) G_def Theorem3a Theorem3b) \\not needed\ +theorem Theorem6: "\\<^bold>\((\<^bold>\y. \ y) \<^bold>\ (\<^bold>\(\<^bold>\y. \ y)))\" by (smt G_def Theorem3a Theorem3b) +theorem Theorem7: "\\<^bold>\((\<^bold>\(\<^bold>\y. \ y)) \<^bold>\ (\<^bold>\(\<^bold>\y. \ y)))\" using Theorem6 axB' by blast +theorem Theorem8: "\\<^bold>\(\<^bold>\y. \ y)\" by (metis Axiom1 Axiom4 Theorem1 Theorem7 axB') +theorem Theorem9: "\\<^bold>\\. ((\

\) \<^bold>\ \<^bold>\(\<^bold>\x. \ x))\" using Axiom1 Axiom4 axM' by metis + +text\Short proof of Theorem8; analogous to the one presented in Sec. 7 of Benzmüller 2020.\ +theorem "\\<^bold>\(\<^bold>\y. \ y)\" \\Note: this version of the proof uses only \axB'\ and \axM'\.\ +proof - + have L1: "\(\<^bold>\X.((\

X)\<^bold>\\<^bold>\(\<^bold>\X)))\<^bold>\(\

(\x.(x\<^bold>\x)))\" using Axiom1 Axiom3 axB' by blast \\Use metis here if \\<^bold>\\ is omitted in Axiom1 and Axiom 2\ + have L2: "\\<^bold>\(\

(\x.(x\<^bold>\x)))\" using Axiom1 Axiom4 by metis + have L3: "\\<^bold>\(\<^bold>\X.((\

X) \<^bold>\ \<^bold>\(\<^bold>\ X)))\" using L1 L2 by blast + have T2: "\\

\\" by (smt Axiom1 Axiom2 G_def axM') + have T3: "\\<^bold>\y. \ y\" using L3 T2 by blast + have T6: "\\<^bold>\(\<^bold>\y. \ y)\" by (simp add: T3) + thus ?thesis by blast qed + +theorem T5: "\(\<^bold>\(\<^bold>\y. \ y)) \<^bold>\ \<^bold>\(\<^bold>\y. \ y)\" \\Obvious: If we can prove Theorem8, then we also have T5.\ +proof - + have L1: "\(\<^bold>\X.((\

X)\<^bold>\\<^bold>\(\<^bold>\X)))\<^bold>\(\

(\x.(x\<^bold>\x)))\" using Axiom1 Axiom3 axB' by blast \\Use metis here if \\<^bold>\\ is omitted in Axiom1 and Axiom 2\ + have L2: "\\<^bold>\(\

(\x.(x\<^bold>\x)))\" using Axiom1 Axiom4 by metis + have L3: "\\<^bold>\(\<^bold>\X.((\

X) \<^bold>\ \<^bold>\(\<^bold>\ X)))\" using L1 L2 by blast + have T2: "\\

\\" by (smt Axiom1 Axiom2 G_def axM') + have T3: "\\<^bold>\y. \ y\" using L3 T2 by blast + have T6: "\\<^bold>\(\<^bold>\y. \ y)\" by (simp add: T3) + thus ?thesis by blast qed + +text\Another short proof of Theorem8.\ +theorem "\\<^bold>\(\<^bold>\y. \ y)\" \\Note: fewer assumptions used in some cases than in \cite{KanckosLethen19}.\ +proof - + have T1: "\\

\\" unfolding G_def using Axiom2 axM by blast + have T3a: "\\

(\x. (\<^bold>\y. \ y))\" by (metis (no_types, lifting) Axiom1 T1) + have T3b: "\\<^bold>\(\

(\x.(\<^bold>\(\<^bold>\y. \ y))))\" by (smt Axiom1 G_def T3a Axiom3 T1 axB') + have T6: "\\<^bold>\((\<^bold>\y. \ y) \<^bold>\ (\<^bold>\(\<^bold>\y. \ y)))\" by (smt G_def T3a T3b) + have T7: "\\<^bold>\((\<^bold>\(\<^bold>\y. \ y)) \<^bold>\ (\<^bold>\(\<^bold>\y. \ y)))\" using T6 axB' by blast + thus ?thesis by (smt Axiom1 Axiom4 T3b axB') qed + +text\Are the axioms of the simplified versions implied?\ +text\Actualist version of the axioms.\ +lemma A1': "\\<^bold>\(\

(\x.(x\<^bold>\x)))\" using Theorem9 by blast +lemma A2': "\\<^bold>\X Y.(((\

X) \<^bold>\ ((X\<^bold>\Y)\<^bold>\(X\Y))) \<^bold>\ (\

Y))\" nitpick oops \\Countermodel\ +lemma A3: "\\<^bold>\\.((\

\\ \) \<^bold>\ (\<^bold>\X.((X\\) \<^bold>\ (\

X))))\" nitpick oops \\Countermodel\ + +text\Possibilist version of the axioms.\ +abbreviation a ("_\<^bold>\\<^sup>p_") where "X\<^bold>\\<^sup>pY \ \<^bold>\z.((X z) \<^bold>\ (Y z))" +abbreviation b ("_\\<^sup>p_") where "X\\<^sup>pY \ \<^bold>\(X\<^bold>\\<^sup>pY)" +abbreviation d ("_\\<^sup>p_") where "X\\<^sup>p\ \ \<^bold>\(\<^bold>\u.((X u) \<^bold>\ (\<^bold>\Y.((\ Y) \<^bold>\ (Y u)))))" + +lemma A1'P: "\\<^bold>\(\

(\x.(x\<^bold>\x)))\" using Theorem9 by blast +lemma A2'P: "\\<^bold>\X Y.(((\

X) \<^bold>\ ((X\<^bold>\\<^sup>pY)\<^bold>\(X\\<^sup>pY))) \<^bold>\ (\

Y))\" oops \\no answer, yet by sledgehammer and nitpick\ +lemma A2'aP: "\\<^bold>\X Y.(((\

X) \<^bold>\ (X\\<^sup>pY)) \<^bold>\ (\

Y))\" using Axiom1 axM' by metis +lemma A2'bP: "\\<^bold>\X Y.(((\

X) \<^bold>\ (X\<^bold>\\<^sup>pY)) \<^bold>\ (\

Y))\" oops \\no answer, yet by sledgehammer and nitpick\ +lemma A3P: "\\<^bold>\\.((\

\\ \) \<^bold>\ (\<^bold>\X.((X\\<^sup>p\) \<^bold>\ (\

X))))\" + by (smt (verit, del_insts) Axiom1 Axiom2 axM') \\proof found\ + +text\Are Axiom2 and A3 equivalent? Only when assuming Axiom1 and axiom M.\ +lemma "\\<^bold>\A .(\<^bold>\((\<^bold>\\.((A \) \<^bold>\ (\

\))) \<^bold>\ (\

(\ A))))\ \ \\<^bold>\\.((\

\\ \) \<^bold>\ (\<^bold>\X.((X\\<^sup>p\) \<^bold>\ (\

X))))\" + by (smt (verit, ccfv_threshold) Axiom1 axM') \\proof found\ +end \ No newline at end of file diff --git a/thys/SimplifiedOntologicalArgument/MFilter.thy b/thys/SimplifiedOntologicalArgument/MFilter.thy new file mode 100644 --- /dev/null +++ b/thys/SimplifiedOntologicalArgument/MFilter.thy @@ -0,0 +1,30 @@ +section\Presentation of All Variants as Studied in \cite{C85} \label{sec:all}\ + +subsection\Preliminaries: Modal Ultrafilter (Fig.~2 in \cite{C85})\ + +theory MFilter imports HOML +begin +text\Some abbreviations for auxiliary operations.\ +abbreviation a::"\\(\\\)\\" ("_\<^bold>\_") where "x\<^bold>\S \ S x" +abbreviation b::\ ("\<^bold>\") where "\<^bold>\ \ \x. \<^bold>\" +abbreviation c::\ ("\<^bold>U") where "\<^bold>U \ \x. \<^bold>\" +abbreviation d::"\\\\\" ("_\<^bold>\_") where "\\<^bold>\\ \ \<^bold>\x.((\ x) \<^bold>\ (\ x))" +abbreviation e::"\\\\\" ("_\<^bold>\_") where "\\<^bold>\\ \ \x.((\ x) \<^bold>\ (\ x))" +abbreviation f::"\\\" ("\_") where "\\ \ \x. \<^bold>\(\ x)" + +text\Definition of modal filter.\ +abbreviation g::"(\\\)\\" ("Filter") + where "Filter \ \ (((\<^bold>U\<^bold>\\) \<^bold>\ \<^bold>\(\<^bold>\\<^bold>\\)) + \<^bold>\ (\<^bold>\\ \. (((\\<^bold>\\) \<^bold>\ (\\<^bold>\\)) \<^bold>\ (\\<^bold>\\)))) + \<^bold>\ (\<^bold>\\ \. (((\\<^bold>\\) \<^bold>\ (\\<^bold>\\)) \<^bold>\ ((\\<^bold>\\)\<^bold>\\)))" + +text\Definition of modal ultrafilter .\ +abbreviation h::"(\\\)\\" ("UFilter") where + "UFilter \ \ (Filter \)\<^bold>\(\<^bold>\\.((\\<^bold>\\) \<^bold>\ ((\\)\<^bold>\\)))" + +text\Modal filter and modal ultrafilter are consistent.\ +lemma "\\<^bold>\\ \.((UFilter \) \<^bold>\ \<^bold>\((\\<^bold>\\) \<^bold>\ ((\\)\<^bold>\\)))\" by force +end + + + diff --git a/thys/SimplifiedOntologicalArgument/ROOT b/thys/SimplifiedOntologicalArgument/ROOT new file mode 100644 --- /dev/null +++ b/thys/SimplifiedOntologicalArgument/ROOT @@ -0,0 +1,21 @@ +chapter AFP + +session "SimplifiedOntologicalArgument" (AFP) = HOL + + + options [timeout = 600] + + theories + SimplifiedOntologicalArgument + MFilter + BaseDefs + ScottVariant + UFilterVariant + SimpleVariant + SimpleVariantPG + SimpleVariantSE + SimpleVariantSEinT + SimpleVariantHF + KanckosLethenNo2Possibilist + document_files + "root.bib" + "root.tex" diff --git a/thys/SimplifiedOntologicalArgument/ScottVariant.thy b/thys/SimplifiedOntologicalArgument/ScottVariant.thy new file mode 100644 --- /dev/null +++ b/thys/SimplifiedOntologicalArgument/ScottVariant.thy @@ -0,0 +1,67 @@ +subsection\Ultrafilter Analysis of Scott's Variant (Fig.~3 in \cite{C85}))\ + +theory ScottVariant imports + HOML + MFilter + BaseDefs +begin +text\Axioms of Scott's variant.\ +axiomatization where + A1: "\\<^bold>\X.((\<^bold>\(\

X)) \<^bold>\ (\

(\<^bold>\X)))\" and + A2: "\\<^bold>\X Y.(((\

X) \<^bold>\ (X\Y)) \<^bold>\ (\

Y))\" and + A3: "\\<^bold>\\.((\

\\ \) \<^bold>\ (\<^bold>\X.((X\\) \<^bold>\ (\

X))))\" and + A4: "\\<^bold>\X.((\

X) \<^bold>\ \<^bold>\(\

X))\" and + A5: "\\

\\\" and + B: "\\<^bold>\\.(\ \<^bold>\ \<^bold>\\<^bold>\\)\" \\Logic KB\ + +lemma B': "\x y. \(x\<^bold>ry) \ (y\<^bold>rx)" using B by fastforce + +text\Necessary existence of a Godlike entity.\ +theorem T6: "\\<^bold>\(\<^bold>\\<^sup>E \)\" +proof - + have T1: "\\<^bold>\X.((\

X) \<^bold>\ \<^bold>\(\<^bold>\\<^sup>E X))\" using A1 A2 by blast + have T2: "\\

\\" by (metis A3 G_def) + have T3: "\\<^bold>\(\<^bold>\\<^sup>E \)\" using T1 T2 by simp + have T4: "\\<^bold>\\<^sup>Ex.((\ x)\<^bold>\(\ \ x))\" unfolding G_def E_def using A1 A4 by metis + have T5: "\(\<^bold>\(\<^bold>\\<^sup>E\))\<^bold>\ \<^bold>\(\<^bold>\\<^sup>E\)\" by (smt A5 G_def B' NE_def T4) + thus ?thesis using T3 by blast qed + +text\Existence of a Godlike entity.\ +lemma "\\<^bold>\\<^sup>E \\" using A1 A2 B' T6 by blast + +text\Consistency\ +lemma True nitpick[satisfy] oops \\Model found.\ + +text\Modal collapse: holds.\ +lemma MC: "\\<^bold>\\.(\ \<^bold>\ \<^bold>\\)\" +proof - { + fix w fix Q + have 1: "\x.((\ x w) \ (\<^bold>\Z.((Z x) \<^bold>\ \<^bold>\(\<^bold>\\<^sup>Ez.((\ z) \<^bold>\ (Z z))))) w)" + by (metis A1 A4 G_def) + have 2: "(\x. \ x w)\((Q \<^bold>\ \<^bold>\(\<^bold>\\<^sup>Ez.((\ z) \<^bold>\ Q))) w)" + using 1 by force + have 3: "(Q \<^bold>\ \<^bold>\Q) w" using B' T6 2 by blast} + thus ?thesis by auto qed + +text\Analysis of positive properties using ultrafilters.\ +theorem U1: "\UFilter \

\" \\Proof found by sledgehammer\ +proof - + have 1: "\(\<^bold>U\<^bold>\\

) \<^bold>\ \<^bold>\(\<^bold>\\<^bold>\\

)\" using A1 A2 by blast + have 2: "\\<^bold>\\ \.(((\\<^bold>\\

)\<^bold>\(\\<^bold>\\))\<^bold>\(\\<^bold>\\

))\" by (smt A2 B' MC) + have 3: "\\<^bold>\\ \.(((\\<^bold>\\

)\<^bold>\(\\<^bold>\\

))\<^bold>\((\\<^bold>\\)\<^bold>\\

))\" by (metis A1 A2 G_def B' T6) + have 4: "\\<^bold>\\.((\\<^bold>\\

) \<^bold>\ ((\\)\<^bold>\\

))\" using A1 by blast + thus ?thesis using 1 2 3 4 by simp qed + +lemma L1: "\\<^bold>\X Y.((X\Y) \<^bold>\ (X\<^bold>\Y))\" by (metis A1 A2 MC) +lemma L2: "\\<^bold>\X Y.(((\

X) \<^bold>\ (X\<^bold>\Y)) \<^bold>\ (\

Y))\" by (smt A2 B' MC) + +text\Set of supersets of X, we call this HF X.\ +abbreviation HF where "HF X \ \Y.(X\<^bold>\Y)" + +text\\HF \\ is a filter; hence, \HF \\ is Hauptfilter of \\\.\ +lemma F1: "\Filter (HF \)\" by (metis A2 B' T6 U1) +lemma F2: "\UFilter (HF \)\" by (smt A1 F1 G_def) + +text\T6 follows directly from F1.\ +theorem T6again: "\\<^bold>\(\<^bold>\\<^sup>E \)\" using F1 by simp +end \ No newline at end of file diff --git a/thys/SimplifiedOntologicalArgument/SimpleVariant.thy b/thys/SimplifiedOntologicalArgument/SimpleVariant.thy new file mode 100644 --- /dev/null +++ b/thys/SimplifiedOntologicalArgument/SimpleVariant.thy @@ -0,0 +1,42 @@ +subsection\Simplified Variant (Fig.~6 in \cite{C85})\ + +theory SimpleVariant imports + HOML + MFilter + BaseDefs + DisableKodkodScala +begin +text\Axiom's of new, simplified variant.\ +axiomatization where + A1': "\\<^bold>\(\

(\x.(x\<^bold>\x)))\" and + A2': "\\<^bold>\X Y.(((\

X) \<^bold>\ ((X\<^bold>\Y) \<^bold>\ (X\Y))) \<^bold>\ (\

Y))\" and + A3: "\\<^bold>\\.((\

\\ \) \<^bold>\ (\<^bold>\X.((X\\) \<^bold>\ (\

X))))\" + +lemma T2: "\\

\\" by (metis A3 G_def) \\From A3\ +lemma L1: "\\

(\x.(x\<^bold>=x))\" by (metis A2' A3) + +text\Necessary existence of a Godlike entity.\ +theorem T6: "\\<^bold>\(\<^bold>\\<^sup>E \)\" \\Proof found by sledgehammer\ +proof - + have T1: "\\<^bold>\X.((\

X) \<^bold>\ \<^bold>\(\<^bold>\\<^sup>E X))\" by (metis A1' A2') + have T3: "\\<^bold>\(\<^bold>\\<^sup>E \)\" using T1 T2 by simp + have T5: "\(\<^bold>\(\<^bold>\\<^sup>E \)) \<^bold>\ \<^bold>\(\<^bold>\\<^sup>E \)\" by (metis A1' A2' T2) + thus ?thesis using T3 by blast qed + +lemma True nitpick[satisfy] oops \\Consistency: model found\ + +text\Modal collapse and monotheism: not implied.\ +lemma MC: "\\<^bold>\\.(\ \<^bold>\ \<^bold>\\)\" nitpick oops \\Countermodel\ +lemma MT: "\\<^bold>\x y.(((\ x) \<^bold>\ (\ y)) \<^bold>\ (x\<^bold>=y))\" + nitpick oops \\Countermodel.\ + +text\Gödel's A1, A4, A5: not implied anymore.\ +lemma A1: "\\<^bold>\X.((\<^bold>\(\

X))\<^bold>\(\

(\<^bold>\X)))\" nitpick oops \\Countermodel\ +lemma A4: "\\<^bold>\X.((\

X) \<^bold>\ \<^bold>\(\

X))\" nitpick oops \\Countermodel\ +lemma A5: "\\

\\\" nitpick oops \\Countermodel\ + +text\Checking filter and ultrafilter properties.\ +theorem F1: "\Filter \

\" oops \\Proof found by sledgehammer, but reconstruction timeout\ +theorem U1: "\UFilter \

\" nitpick oops \\Countermodel\ +end + diff --git a/thys/SimplifiedOntologicalArgument/SimpleVariantHF.thy b/thys/SimplifiedOntologicalArgument/SimpleVariantHF.thy new file mode 100644 --- /dev/null +++ b/thys/SimplifiedOntologicalArgument/SimpleVariantHF.thy @@ -0,0 +1,39 @@ +subsection\Hauptfiltervariant (Fig.~10 in \cite{C85})\ + +theory SimpleVariantHF imports + HOML + MFilter + BaseDefs + DisableKodkodScala +begin +text\Definition: Set of supersets of \X\, we call this \\\ X\.\ +abbreviation HF::"\\(\\\)" where "HF X \ \Y.(X\<^bold>\Y)" + +text\Postulate: \\\ \\ is a filter; i.e., Hauptfilter of \\\.\ +axiomatization where F1: "\Filter (HF \)\" + +text\Necessary existence of a Godlike entity.\ +theorem T6: "\\<^bold>\(\<^bold>\\<^sup>E \)\" using F1 by auto \\Proof found\ + +theorem T6again: "\\<^bold>\(\<^bold>\\<^sup>E \)\" +proof - + have T3': "\\<^bold>\\<^sup>E \\" using F1 by auto + have T6: "\\<^bold>\(\<^bold>\\<^sup>E \)\" using T3' by blast + thus ?thesis by simp qed + +text\Possible existence of Godlike entity not implied.\ +lemma T3: "\\<^bold>\(\<^bold>\\<^sup>E \)\" nitpick oops \\Countermodel\ + +text\Axiom T enforces possible existence of Godlike entity.\ +axiomatization +lemma T3: assumes T: "\\<^bold>\\.((\<^bold>\\) \<^bold>\ \)\" + shows "\\<^bold>\(\<^bold>\\<^sup>E \)\" using F1 T by auto + +lemma True nitpick[satisfy] oops \\Consistency: model found\ + +text\Modal collapse: not implied anymore.\ +lemma MC: "\\<^bold>\\.(\ \<^bold>\ \<^bold>\\)\" nitpick oops \\Countermodel\ +lemma MT: "\\<^bold>\x y.(((\ x) \<^bold>\ (\ y)) \<^bold>\ (x\<^bold>=y))\" + nitpick oops \\Countermodel\ +end + diff --git a/thys/SimplifiedOntologicalArgument/SimpleVariantPG.thy b/thys/SimplifiedOntologicalArgument/SimpleVariantPG.thy new file mode 100644 --- /dev/null +++ b/thys/SimplifiedOntologicalArgument/SimpleVariantPG.thy @@ -0,0 +1,28 @@ +subsection\Simplified Variant with Axiom T2 (Fig.~7 in \cite{C85})\ + +theory SimpleVariantPG imports + HOML + MFilter + BaseDefs + DisableKodkodScala +begin +text\Axiom's of simplified variant with A3 replaced.\ +axiomatization where + A1': "\\<^bold>\(\

(\x.(x\<^bold>\x)))\" and + A2': "\\<^bold>\X Y.(((\

X) \<^bold>\ ((X\<^bold>\Y)\<^bold>\(X\Y))) \<^bold>\ (\

Y))\" and + T2: "\\

\\" + +text\Necessary existence of a Godlike entity.\ +theorem T6: "\\<^bold>\(\<^bold>\\<^sup>E \)\" \\Proof found by sledgehammer\ +proof - + have T1: "\\<^bold>\X.((\

X) \<^bold>\ \<^bold>\(\<^bold>\\<^sup>E X))\" by (metis A1' A2') + have T3: "\\<^bold>\(\<^bold>\\<^sup>E \)\" using T1 T2 by simp + have T5: "\(\<^bold>\(\<^bold>\\<^sup>E \)) \<^bold>\ \<^bold>\(\<^bold>\\<^sup>E \)\" by (metis A1' A2' T2) + thus ?thesis using T3 by blast qed + +lemma True nitpick[satisfy] oops \\Consistency: model found\ + +text\Modal collapse and Monotheism: not implied.\ +lemma MC: "\\<^bold>\\.(\ \<^bold>\ \<^bold>\\)\" nitpick oops \\Countermodel\ +lemma MT: "\\<^bold>\x y.(((\ x)\<^bold>\(\ y))\<^bold>\(x\<^bold>=y))\" nitpick oops \\Countermodel\ +end diff --git a/thys/SimplifiedOntologicalArgument/SimpleVariantSE.thy b/thys/SimplifiedOntologicalArgument/SimpleVariantSE.thy new file mode 100644 --- /dev/null +++ b/thys/SimplifiedOntologicalArgument/SimpleVariantSE.thy @@ -0,0 +1,24 @@ +subsection\Simplified Variant with Simple Entailment in Logic K (Fig.~8 in \cite{C85})\ + +theory SimpleVariantSE imports + HOML + MFilter + BaseDefs +begin +text\Axiom's of new variant based on ultrafilters.\ +axiomatization where + A1': "\\<^bold>\(\

(\x.(x\<^bold>\x)))\" and + A2'': "\\<^bold>\X Y.(((\

X) \<^bold>\ (X\<^bold>\Y)) \<^bold>\ (\

Y))\" and + T2: "\\

\\" + +text\Necessary existence of a Godlike entity.\ +theorem T6: "\\<^bold>\(\<^bold>\\<^sup>E \)\" using A1' A2'' T2 by blast +theorem T7: "\\<^bold>\\<^sup>E \\" using A1' A2'' T2 by blast + +text\Possible existence of a Godlike: has counterodel.\ +lemma T3: "\\<^bold>\(\<^bold>\\<^sup>E \)\" nitpick oops \\Countermodel\ + +lemma T3': assumes T: "\\<^bold>\\.((\<^bold>\\) \<^bold>\ \)\" + shows "\\<^bold>\(\<^bold>\\<^sup>E \)\" + using A1' A2'' T2 T by metis +end diff --git a/thys/SimplifiedOntologicalArgument/SimpleVariantSEinT.thy b/thys/SimplifiedOntologicalArgument/SimpleVariantSEinT.thy new file mode 100644 --- /dev/null +++ b/thys/SimplifiedOntologicalArgument/SimpleVariantSEinT.thy @@ -0,0 +1,37 @@ +subsection\Simplified Variant with Simple Entailment in Logic T (Fig.~9 in \cite{C85})\ + +theory SimpleVariantSEinT imports + HOML + MFilter + BaseDefs +begin +text\Axiom's of new variant based on ultrafilters.\ +axiomatization where + A1': "\\<^bold>\(\

(\x.(x\<^bold>\x)))\" and + A2'': "\\<^bold>\X Y.(((\

X) \<^bold>\ (X\<^bold>\Y)) \<^bold>\ (\

Y))\" and + T2: "\\

\\" + +text\Modal Logic T.\ +axiomatization where T: "\\<^bold>\\.((\<^bold>\\) \<^bold>\ \)\" +lemma T': "\\<^bold>\\.(\ \<^bold>\ (\<^bold>\\))\" by (metis T) + +text\Necessary existence of a Godlike entity.\ +theorem T6: "\\<^bold>\(\<^bold>\\<^sup>E \)\" \\Proof found by sledgehammer\ +proof - + have T1: "\\<^bold>\X.((\

X)\<^bold>\(\<^bold>\(\<^bold>\\<^sup>E X)))\" by (metis A1' A2'' T') + have T3: "\\<^bold>\(\<^bold>\\<^sup>E \)\" by (metis T1 T2) + have T5: "\(\<^bold>\(\<^bold>\\<^sup>E \)) \<^bold>\ \<^bold>\(\<^bold>\\<^sup>E \)\" by (metis A1' A2'' T2) + thus ?thesis using T3 by simp qed + +text\T6 again, with an alternative, simpler proof.\ +theorem T6again: "\\<^bold>\(\<^bold>\\<^sup>E \)\" +proof - + have L1: "\(\<^bold>\X.((\

X)\<^bold>\\<^bold>\(\<^bold>\\<^sup>EX)))\<^bold>\(\

(\x.(x\<^bold>\x)))\" + by (smt A2'') + have L2: "\\<^bold>\(\<^bold>\X.((\

X) \<^bold>\ \<^bold>\(\<^bold>\\<^sup>E X)))\" by (metis L1 A1') + have T1': "\\<^bold>\X.((\

X) \<^bold>\ (\<^bold>\\<^sup>E X))\" by (metis L2) + have T3': "\\<^bold>\\<^sup>E \\" by (metis T1' T2) + have L3: "\\<^bold>\(\<^bold>\\<^sup>E \)\" by (metis T3' T') \\not needed\ + thus ?thesis using T3' by simp qed +end + diff --git a/thys/SimplifiedOntologicalArgument/SimplifiedOntologicalArgument.thy b/thys/SimplifiedOntologicalArgument/SimplifiedOntologicalArgument.thy new file mode 100644 --- /dev/null +++ b/thys/SimplifiedOntologicalArgument/SimplifiedOntologicalArgument.thy @@ -0,0 +1,72 @@ +section \Selected Simplified Ontological Argument \label{sec:selected}\ + +theory SimplifiedOntologicalArgument imports + HOML + DisableKodkodScala +begin +text \Positive properties:\ +consts posProp::"\\\" ("\

") + +text \An entity x is God-like if it possesses all positive properties.\ +definition G ("\") where "\(x) \ \<^bold>\\.(\

(\) \<^bold>\ \(x))" + +text \The axiom's of the simplified variant are presented next; these axioms are further motivated in \cite{C85,J52}).\ +text \Self-difference is not a positive property (possible alternative: + the empty property is not a positive property).\ +axiomatization where CORO1: "\\<^bold>\(\

(\x.(x\<^bold>\x)))\" +text \A property entailed by a positive property is positive.\ +axiomatization where CORO2: "\\<^bold>\\ \. \

(\) \<^bold>\ (\<^bold>\x. \(x) \<^bold>\ \(x)) \<^bold>\ \

(\)\" +text \Being Godlike is a positive property.\ +axiomatization where AXIOM3: "\\

\\" + +subsection\Verifying the Selected Simplified Ontological Argument (version 1)\ + +text \The existence of a non-exemplified positive property implies that self-difference + (or, alternatively, the empty property) is a positive property.\ +lemma LEMMA1: "\(\<^bold>\\.(\

(\) \<^bold>\ \<^bold>\(\<^bold>\x. \(x)))) \<^bold>\ \

(\x.(x\<^bold>\x))\" + using CORO2 by meson +text \A non-exemplified positive property does not exist.\ +lemma LEMMA2: "\\<^bold>\(\<^bold>\\.(\

(\) \<^bold>\ \<^bold>\(\<^bold>\x. \(x))))\" + using CORO1 LEMMA1 by blast +text \Positive properties are exemplified.\ +lemma LEMMA3: "\\<^bold>\\.(\

(\) \<^bold>\ (\<^bold>\x. \(x)))\" + using LEMMA2 by blast +text \There exists a God-like entity.\ +theorem THEOREM3': "\\<^bold>\x. \(x)\" + using AXIOM3 LEMMA3 by auto +text \Necessarily, there exists a God-like entity.\ +theorem THEOREM3: "\\<^bold>\(\<^bold>\x. \(x))\" + using THEOREM3' by simp +text \However, the possible existence of Godlike entity is not implied.\ +theorem CORO: "\\<^bold>\(\<^bold>\x. \(x))\" + nitpick oops (*Countermodel*) + +subsection\Verifying the Selected Simplified Ontological Argument (version 2)\ + +text \We switch to logic T.\ +axiomatization where T: "\\<^bold>\\. \<^bold>\\ \<^bold>\ \\" +lemma T': "\\<^bold>\\. \ \<^bold>\ \<^bold>\\\" using T by metis +text \Positive properties are possibly exemplified.\ +theorem THEOREM1: "\\<^bold>\\. \

(\) \<^bold>\ \<^bold>\(\<^bold>\x. \(x))\" + using CORO1 CORO2 T' by metis +text \Possibly there exists a God-like entity.\ +theorem CORO: "\\<^bold>\(\<^bold>\x. \(x))\" + using AXIOM3 THEOREM1 by auto +text \The possible existence of a God-like entity impplies the necessary existence of a God-like entity.\ +theorem THEOREM2: "\\<^bold>\(\<^bold>\x. \(x)) \<^bold>\ \<^bold>\(\<^bold>\x. \(x))\" + using AXIOM3 CORO1 CORO2 by metis +text \Necessarily, there exists a God-like entity.\ +theorem THEO3: "\\<^bold>\(\<^bold>\x. \(x))\" + using CORO THEOREM2 by blast +text \There exists a God-like entity.\ +theorem THEO3': "\\<^bold>\x. \(x)\" + using T THEO3 by metis + +text \Modal collapse is not implied; nitpick reports a countermodel.\ + +lemma MC: "\\<^bold>\\. \ \<^bold>\ \<^bold>\\\" nitpick oops + +text \Consistency of the theory; nitpick reports a model.\ +lemma True nitpick[satisfy] oops (*Model found*) +end + diff --git a/thys/SimplifiedOntologicalArgument/UFilterVariant.thy b/thys/SimplifiedOntologicalArgument/UFilterVariant.thy new file mode 100644 --- /dev/null +++ b/thys/SimplifiedOntologicalArgument/UFilterVariant.thy @@ -0,0 +1,46 @@ +subsection\Ultrafilter Variant (Fig.~5 in \cite{C85})\ + +theory UFilterVariant imports + HOML + MFilter + BaseDefs + DisableKodkodScala +begin +text\Axiom's of ultrafilter variant.\ +axiomatization where + U1: "\UFilter \

\" and + A2: "\\<^bold>\X Y.(((\

X) \<^bold>\ (X\Y)) \<^bold>\ (\

Y))\" and + A3: "\\<^bold>\\.((\

\\ \) \<^bold>\ (\<^bold>\X.((X\\) \<^bold>\ (\

X))))\" + +text\Necessary existence of a Godlike entity.\ +theorem T6: "\\<^bold>\(\<^bold>\\<^sup>E \)\" \\Proof also found by sledgehammer\ +proof - + have T1: "\\<^bold>\X.((\

X) \<^bold>\ \<^bold>\(\<^bold>\\<^sup>E X))\" by (metis A2 U1) + have T2: "\\

\\" by (metis A3 G_def) + have T3: "\\<^bold>\(\<^bold>\\<^sup>E \)\" using T1 T2 by simp + have T5: "\(\<^bold>\(\<^bold>\\<^sup>E \)) \<^bold>\ \<^bold>\(\<^bold>\\<^sup>E \)\" by (metis A2 G_def T2 U1) + thus ?thesis using T3 by blast qed + +text\Checking for consistency.\ +lemma True nitpick[satisfy] oops \\Model found\ + +text\Checking for modal collapse.\ +lemma MC: "\\<^bold>\\.(\ \<^bold>\ \<^bold>\\)\" nitpick oops \\Countermodel\ +end + + + +(* + definition ess ("\") where "\ Y x \ Y x \<^bold>\ (\<^bold>\Z.(Z x \<^bold>\ (Y\Z)))" + definition NE ("NE") where "NE x \ \w.((\<^bold>\Y.(\ Y x \<^bold>\ \<^bold>\\<^bold>\\<^sup>E Y)) w)" + consts Godlike::\ UltraFilter::"(\\\)\\" NeEx::\ + axiomatization where + 1: "Godlike = G" and + 2: "UltraFilter = Ultrafilter" and + 3: "NeEx = NE" + lemma True nitpick[satisfy] oops + lemma MC: "\\<^bold>\\. \ \<^bold>\ \<^bold>\\\" nitpick[format=8] oops (*Countermodel*) + lemma A1: "\\<^bold>\X. \<^bold>\(\

X) \<^bold>\ \

(\<^bold>\X)\" using U1 by fastforce + lemma A4: "\(\

X \<^bold>\ \<^bold>\(\

X))\" nitpick [format=4] oops (*Countermodel*) + lemma A5: "\\

NE\" nitpick oops (*Countermodel*) +*) \ No newline at end of file diff --git a/thys/SimplifiedOntologicalArgument/document/root.bib b/thys/SimplifiedOntologicalArgument/document/root.bib new file mode 100644 --- /dev/null +++ b/thys/SimplifiedOntologicalArgument/document/root.bib @@ -0,0 +1,2167 @@ +@article{J52, + Author = {Christoph Benzm\"uller and David Fuenmayor}, + Journal = {Bulletin of the Section of Logic}, + Publisher = {Department of Logic, University of Lodz}, + Keywords = {own, Ontological Argument, Computational + Metaphysics, Higher Order Logic, Semantic Embedding, + Modal Logics, Automated Reasoning, Ontology + Reasoning}, + Title = {Computer-supported Analysis of Positive Properties, Ultrafilters and Modal Collapse in Variants of {G\"odel's} Ontological Argument}, + OPTUrl = {https://czasopisma.uni.lodz.pl/bulletin/}, + Year = 2020, + Volume = {49}, + Number = {2}, + Doi = {10.18778/0138-0680.2020.08}, + OPTAddendum = {Preprint: \url{https://www.researchgate.net/publication/336742445}}, + Pages = {127-148}, +} + +@InProceedings{C85, + Keywords = {own, Ontological Argument, Computational + Metaphysics, Higher Order Logic, Semantic Embedding, + Modal Logics, Automated Reasoning, Ontology + Reasoning}, + title = {{A (Simplified) Supreme Being Necessarily Exists, says the Computer: Computationally Explored Variants of Gödel's Ontological Argument}}, + author = {Benzmüller, Christoph}, + booktitle = {{Proceedings of the 17th International Conference on Principles of Knowledge Representation and Reasoning, KR 2020}}, + pages = {779--789}, + year = {2020}, + month = {9}, + doi = {10.24963/kr.2020/80}, + url = {https://doi.org/10.24963/kr.2020/80}, + publisher = {{IJCAI} organization}, +} + +@article{J48, +Author = {Benzm{\"u}ller, Christoph and Parent, Xavier and van + der Torre, Leendert}, + Keywords = {own, Normative Reasoning, Deontic Logic, Machine Ethics, Formal Methods, Automated Reasoning, ProoF Assistants, Explainable AI}, +Journal = {Artificial Intelligence (accepted for publication)}, +Publisher = {Elsevier}, +Title = {Designing Normative Theories for Ethical and Legal Reasoning: + LogiKEy Framework, Methodology, and Tool Support}, +Year = 2020, +Pages = {1--50}, +Addendum = {Preprint: \url{https://www.researchgate.net/publication/331986665}}, +} + + +@InCollection{odifreddi00:_ultraf_dictat_gods, + author = {Piergiorgio Odifreddi}, + title = {Ultrafilters, Dictators, and Gods}, + booktitle = {Finite Versus Infinite. Discrete Mathematics and Theoretical Computer Science}, + publisher = {Springer, London}, + year = 2000, + editor = {Cristian Calude and Gheorghe Paun}, + pages = {239-245}} + +@book{1965proslogion, + title={Proslogion}, + author={Charlesworth, M.J.}, + lccn=65005321, + url={https://books.google.lu/books?id=TtFDAQAAMAAJ}, + year=1965, + publisher={Clarendon Press} +} + +@Article{bjoerdal18, + author = {Frode Alfson Bj{\o}rdal}, + title = {All Properties are Divine or God Exists -- The Sacred Thesis and its Ontological Argument}, + journal = {Logic and Logical Philosophy}, + year = 2018, + volume = 27, + number = 3} + +@Unpublished{Swietorzecka19, + author = {Kordula \'Swi\c etorzecka}, + title = {Identity or equality of {Gödelian} God}, + note = {Draft paper, private communication}, + month = {May}, + year = 2019} + +@article{J35, + Author = {David Fuenmayor and Christoph Benzm{\"u}ller}, + Journal = {Archive of Formal Proofs}, + Keywords = {own, Automated Reasoning, Interactive Proof, + Ontology Reasoning, Higher Order Logic, + Computational Metaphysics}, + Note = {Note: verified data publication}, + Title = {{Types, Tableaus and G{\"o}del's God in + Isabelle/HOL}}, + Url = + {http://afp.sourceforge.net/entries/Types_Tableaus_and_Goedels_God.shtml}, + Year = 2017, + Pages = {1--34}, +} + + + +@inproceedings{R74, + Author = {Benzm{\"u}ller, Christoph}, + Title = {Computational Metaphysics: New Insights on {G{\"o}del's} Ontological Argument and Modal Collapse}, + Editor = {Sr\'{e}cko Kova\v{c} and Kordula Swietorzecka}, + Booktitle = {Formal Methods and Science in Philosophy III, Informal Proceedings}, + Year = 2019, + Pages = {3--4}, + Address = {Dubrovnik, Croatia}, + Url = {http://christoph-benzmueller.de/papers/2019-FMSPh-Proceedings.pdf}, +} + +@incollection{Kovacs2012, + year = 2012, + editor = {Miroslaw Szatkowski}, + pages = {50--323}, + author = {Sr\'{e}cko Kova\v{c}}, + booktitle = {Ontological Proofs Today}, + publisher = {Ontos Verlag}, + title = {Modal Collapse in {G\"odel's} Ontological Proof} +} + +@InCollection{sep-logic-modal, + author = {Garson, James}, + title = {Modal Logic}, + booktitle = {The Stanford Encyclopedia of Philosophy}, + editor = {Edward N. Zalta}, + howpublished = {\url{https://plato.stanford.edu/archives/fall2018/entries/logic-modal/}}, + year = {2018}, + edition = {Fall 2018}, + publisher = {Metaphysics Research Lab, Stanford University} +} + +@article{J47, +Author = {Kirchner, Daniel and Benzm{\"u}ller, Christoph and Zalta, Edward N.}, +Journal = {Open Philosophy}, +Title = {Computer Science and Metaphysics: A Cross-Fertilization}, +Editor = {Patrick Grim}, +Year = 2019, +Volume = 2, +Issue = 1, +Pages = {230–251}, +Doi = {10.1515/opphil-2019-0015}, +OPTNote = {Preprint: \url{http://doi.org/10.13140/RG.2.2.25229.18403}}, +OPTUrl = {https://arxiv.org/abs/1905.00787}, +} + +@InCollection{J43, + author = {Benzm\"uller, Christoph and Andrews, Peter}, + title = {Church's Type Theory}, + booktitle = {The Stanford Encyclopedia of Philosophy}, + editor = {Edward N. Zalta}, + howpublished = {\url{https://plato.stanford.edu/entries/type-theory-church/}}, + year = 2019, + edition = {Summer 2019}, + OPTpages = {pp.~1--62 (in pdf version)}, + publisher = {Metaphysics Research Lab, Stanford University}, + url = {https://plato.stanford.edu/entries/type-theory-church/}, +} + +@InCollection{Lowe2013, + author= {Lowe, Edward Jonathan}, + editor= {Moreland, J. P. and Sweis, K. A. and Meister, C. V.}, + title= {A Modal Version of the Ontological Argument}, + booktitle = {Debating Christian Theism}, + publisher = {Oxford University Press}, + year = {2013}, + chapter= {4}, + pages= {61--71}, + isbn = {9780199981434} +} + +@article{zalta1999, + Author = {Edward N. Zalta}, + Title = {{Natural Numbers and Natural Cardinals as Abstract Objects: +A Partial Reconstruction of {Frege's} Grundgesetze in Object +Theory}}, + Journal = {Journal of Philosophical Logic}, + volume = {28}, + number = {6}, + year = {1999}, + pages = {619--660} +} + +@article{zalta1993, + Author = {Edward N. Zalta}, + Title = {{Twenty-Five Basic Theorems in Situation and World Theory}}, + Journal = {Journal of Philosophical Logic}, + volume = {22}, + number = {4}, + year = {1993}, + pages = {385--428} +} + +@article{OppenheimerZalta1991, + author = {Paul E. Oppenheimer and Edward N. Zalta}, + title = {On the Logic of the Ontological Argument}, + volume = {5}, + journal = {Philosophical Perspectives}, + year = {1991}, + pages = {509--529} +} + +@article{PelletierZalta, + Author = {Francis J. Pelletier and Edward N. Zalta}, + Title = {{How to Say Goodbye to the Third Man}}, + Journal = {No\^us}, + volume = {34}, + number = {2}, + year = {2000}, + pages = {165--202} +} + + + +@inproceedings{C74, + Author = {Christoph Benzm{\"u}ller and Fuenmayor, David}, + Booktitle = {Mathematics and Reality, Proceedings of the 11th All India Students' Conference on Science \& Spiritual Quest (AISSQ), 6-7 October, 2018, IIT Bhubaneswar, Bhubaneswar, India}, + Editor = {Gosh, Sudipto and Uppalari, Ramgopal and Rao, K. Vasudeva and Agarwal, Varun and Sharma, Sushant}, + Keywords = {own, Ontological Argument, Computational Metaphysics, Higher Order Logic, Semantic Embedding, Modal Logics, Automated Reasoning, Ontology Reasoning}, + Publisher = {The Bhaktivedanta Institute, Kolkata, \url{www.binstitute.org}}, + Title = {Can Computers Help to Sharpen our Understanding of Ontological Arguments?}, + Url = {http://christoph-benzmueller.de/papers/C74.pdf}, + pages = {195-226}, + isbn = {81-89635-31-X}, + Comment = {DOI (preprint): 10.13140/RG.2.2.31921.84323}, + Doi = {10.13140/RG.2.2.31921.84323}, + Year = 2018, +} + +@inproceedings{HuffmanK13, + author = {Brian Huffman and + Ondrej Kuncar}, + title = {Lifting and Transfer: {A} Modular Design for Quotients in {Isabelle/HOL}}, + booktitle = {Certified Programs and Proofs --- Third International Conference, {CPP} + 2013, Melbourne, VIC, Australia, December 11-13, 2013, Proceedings}, + pages = {131--146}, + year = {2013}, + editor = {Georges Gonthier and + Michael Norrish}, + series = {Lecture Notes in Computer Science}, + volume = {8307}, + publisher = {Springer}, +} + + +@inproceedings{C70, + Author = {Alexander Steen and Christoph Benzm{\"u}ller}, + Booktitle = {Automated Reasoning. IJCAR 2018}, + Editor = {Didier Galmiche and Stephan Schulz and Roberto Sebastiani}, + Keywords = {own, Higher Order Logic, Automated Reasoning, LEO Prover}, + Publisher = {Springer, Cham}, + Series = {Lecture Notes in Computer Science}, + Title = {The Higher-Order Prover {Leo-III}}, + Url = {http://christoph-benzmueller.de/papers/C70.pdf}, + volume = 10900, + pages = {108-116}, + doi = {10.1007/978-3-319-94205-6_8}, + isbn = {978-3-319-94204-9}, + Year = 2018, +} + +@article{J30, + Author = {Christoph Benzm{\"u}ller and Nik Sultana and Lawrence C. Paulson and Frank Thei{\ss}}, + Doi = {10.1007/s10817-015-9348-y}, + Journal = {Journal of Automated Reasoning}, + Keywords = {own, Automated Reasoning, Interactive Proof, Ontology Reasoning, LEO Prover, Higher Order Logic, DFG-2501-Selected}, + Number = 4, + Pages = {389-404}, + Title = {The Higher-Order Prover {LEO-II}}, + Url = {http://christoph-benzmueller.de/papers/J30.pdf}, + Volume = 55, + Year = 2015, +} + +@inproceedings{Nunchaku, + author = {Cruanes, Simon and + Blanchette, Jasmin C.}, + title = {Extending Nunchaku to Dependent Type Theory}, + booktitle = {Proceedings First International Workshop on Hammers for Type Theories, + HaTT@IJCAR 2016, Coimbra, Portugal, July 1, 2016.}, + pages = {3--12}, + year = {2016}, + doi = {10.4204/EPTCS.210.3}, + series = {{EPTCS}}, + volume = {210}, + url = {https://doi.org/10.4204/EPTCS.210}, +} + + +@misc{W62, + Author = {Benzm\"uller, Christoph and Farjami, Ali and Parent, Xavier}, + OPTBooktitle = {MIREL 2018}, + OPTEditor = {}, + Keywords = {own, Dyadic Deontic Logic E, Preference Models, Higher Order Logic, Semantic Embedding, Automated Reasoning}, + Note = {MIREL 2018 workshop on MIning and REasoning with Legal texts; available online at \url{http://orbilu.uni.lu/handle/10993/37014}}, + Url = {http://orbilu.uni.lu/handle/10993/37014}, + Title = {Aqvist's Dyadic Deontic Logic {E} in {HOL}}, + Year = 2018, +} + + +@misc{W63, + Author = {Farjami, Ali and Meder, Paul and Parent, Xavier and Benzm\"uller, Christoph}, + OPTBooktitle = {MIREL 2018}, + OPTEditor = {}, + Keywords = {own, Input/Output Logic, Higher Order Logic, Semantic Embedding, Automated Reasoning, General Data Protection Regulation}, + Note = {MIREL 2018 workshop on MIning and REasoning with Legal texts; available online at \url{http://orbilu.uni.lu/handle/10993/37013}}, + Title = { {I/O} Logic in {HOL}}, + Year = 2018, +} + +@inproceedings{C71, + Author = {Benzm{\"u}ller, Christoph and Farjami, Ali and Parent, Xavier}, + Booktitle = {Deontic Logic and Normative Systems --- 14th International Conference, DEON 2018, Utrecht, The Netherlands, 3-6 July, 2018}, + Editor = {Jan Broersen and Cleo Condoravdi and Shyam Nair and Gabriella Pigozzi}, + Keywords = {own, Higher Order Logic, Deontic Logic, + Automated Reasoning, Universal Reasoning}, + Publisher = {College Publications}, + pages = {33-50}, + OPTSeries = {}, + Title = {A Dyadic Deontic Logic in {HOL}}, + Url = {http://christoph-benzmueller.de/papers/C71.pdf}, + OPTVolume = 9706, + Year = 2018, + isbn = {978-1-84890-278-7}, + note = {(John-Jules Meyer Best Paper Award)}, +} + +@article{J41, + author = {Christoph Benzm{\"u}ller}, + title = {Universal (Meta-)Logical Reasoning: Recent Successes}, + journal = {Science of Computer Programming}, + year = 2019, + volume = 172, + month = {3}, + pages = {48-62}, + OPTnote = {DOI (preprint): \url{http://dx.doi.org/10.13140/RG.2.2.11039.61609/2}}, + doi = {10.1016/j.scico.2018.10.008}, + url = {https://doi.org/10.1016/j.scico.2018.10.008} +} + + +@inproceedings{C47, + Address = {Berlin, Germany}, + Author = {Christoph Benzm{\"u}ller and Maximilian Claus and Nik Sultana}, + Booktitle = {PxTP 2015}, + Comment = {slides}, + Doi = {10.4204/EPTCS.186.5}, + Editor = {Cezary Kaliszyk and Andrei Paskevich}, + Issn = {2075-2180}, + Keywords = {own, Automated Reasoning, Interactive Proof, Ontology Reasoning, LEO Prover, Higher Order Logic}, + Pages = {27-41}, + Publisher = {EPTCS}, + Title = {Systematic Verification of the Modal Logic Cube in {Isabelle/HOL}}, + Url = {http://christoph-benzmueller.de/papers/C47.pdf}, + Volume = 186, + Year = 2015, +} + +@inproceedings{C72, + Author = {Benzm{\"u}ller, Christoph}, + Booktitle = {Deontic Logic and Normative Systems --- 14th International Conference, DEON 2018, Utrecht, The Netherlands, 3-6 July, 2018}, + Editor = {Jan Broersen and Cleo Condoravdi and Shyam Nair and Gabriella Pigozzi}, + Keywords = {own, Higher Order Logic, Deontic Logic, + Automated Reasoning, Universal Reasoning}, + Publisher = {College Publications}, + pages = 7, + Title = {A Flexible Infrastructure for Normative Reasoning (invited keynote abstract)}, + Url = {http://christoph-benzmueller.de/papers/C72.pdf}, + Volume = 9706, + Year = 2018, + isbn = {978-1-84890-278-7}, +} + +@inproceedings{C44, + Author = {Christoph Benzm{\"{u}}ller and Woltzenlogel Paleo, Bruno}, + Booktitle = {Computer Science --- Theory and Applications --- 10th International Computer Science Symposium in Russia, {CSR} 2015, Listvyanka, Russia, July 13-17, 2015, Proceedings}, + Doi = {10.1007/978-3-319-20297-6_25}, + Editor = {Lev D. Beklemishev and Daniil V. Musatov}, + Keywords = {own, Automated Reasoning, Interactive Proof, Ontology Reasoning, LEO Prover, Higher Order Logic, Computational Metaphysics}, + Pages = {398--411}, + Publisher = {Springer}, + Series = {Lecture Notes in Computer Science}, + Title = {Interacting with Modal Logics in the {Coq} Proof Assistant}, + Url = {http://christoph-benzmueller.de/papers/C44.pdf}, + Volume = 9139, + Year = 2015 +} + +@article{B17, + Author = {David Fuenmayor and Christoph Benzm\"uller}, + Journal = {Journal of Applied Logic - IfCoLoG Journal of Logics + and their Applications (special issue on Formal + Approaches to the Ontological Argument)}, + Volume = 5, + Number = 7, + Pages = {1567-1603}, + Editors = {Silvestre, Ricardo and B\'{e}ziau, Jean-Yves}, + Keywords = {own, Automated Reasoning, Interactive Proof, + Ontology Reasoning, Higher Order Logic, + Computational Metaphysics}, + Title = {A Case Study On Computational Hermeneutics: + {E.~J.~Lowe's} Modal Ontological Argument}, + Year = 2018, +} + + + +@book{lambek86:_introd_higher_order_categ_logic, + author = {Lambek, J. and Scott, P.J.}, + publisher = {Cambridge University Press}, + title = {Introduction to Higher Order Categorical Logic}, + year = {1986}, +} + +@book{jacobs99:_categ_logic_type_theor, + author = {B. Jacobs}, + publisher = {North Holland, Elsevier}, + series = {Studies in Logic and the Foundations of Mathematics}, + title = {Categorical Logic and Type Theory}, + volume = {141}, + year = {1999}, +} + +@book{andreka17:_univer_algeb_logic, + author = {Andreka, H. and N\'emeti, I. and Sain, I.}, + publisher = {Birkh\"auser Basel}, + series = {Studies in Universal Logic}, + title = {Universal Algebraic Logic}, + year = {2017}, +} + +@article{moss99:_coalg_logic, + author = {L.S. Moss}, + journal = {Annals of Pure and Applied Logic}, + number = {1-3}, + pages = {277-317}, + title = {Coalgebraic Logic}, + volume = {96}, + year = {1999}, +} + +@article{rutten00:_univer, + author = {J.J.M.M. Rutten}, + journal = {Theoretical Computer Science}, + number = {1}, + pages = {3-80}, + title = {Universal coalgebra: a theory of systems}, + volume = {249}, + year = {2000}, +} + +@inproceedings{DBLP:conf/icfem/GuttmannSW11, + author = {Walter Guttmann and Georg Struth and Tjark Weber}, + booktitle = {Proc. of ICFEM 2011}, + editor = {Shengchao Qin and Zongyan Qiu}, + pages = {617-632}, + publisher = {Springer}, + series = {Lecture Notes in Computer Science}, + title = {Automating Algebraic Methods in {Isabelle}}, + volume = {6991}, + year = {2011}, +} + +@article{foster15:_fine_struc_regul_algeb, + author = {S. Foster and G. Struth}, + journal = {Journal of Automated Reasoning}, + number = {2}, + pages = {165-197}, + title = {On the Fine-Structure of Regular Algebra}, + volume = {54}, + year = {2015}, +} + +@article{Church40, + author = {Alonzo Church}, + journal = {Journal of Symbolic Logic}, + pages = {56--68}, + title = {A Formulation of the Simple Theory of Types}, + volume = {5}, + year = {1940}, +} + +@InCollection{AndrewsSEP, + author = {Andrews, Peter}, + title = {Church's Type Theory}, + booktitle = {The Stanford Encyclopedia of Philosophy}, + editor = {Edward N. Zalta}, + howpublished = {\url{https://plato.stanford.edu/archives/sum2018/entries/type-theory-church/}}, + year = {2018}, + edition = {Summer 2018}, + publisher = {Metaphysics Research Lab, Stanford University} +} + +@incollection{B5, + author = {Christoph Benzm{\"u}ller and Dale Miller}, + booktitle = {Handbook of the History of Logic, Volume 9 --- + Computational Logic}, + editor = {Gabbay, Dov M. and Siekmann, J\"org H. and + Woods, John}, + pages = {215-254}, + publisher = {North Holland, Elsevier}, + title = {Automation of Higher-Order Logic}, + year = {2014}, + doi = {10.1016/B978-0-444-51624-4.50005-8}, + isbn = {978-0-444-51624-4}, + OPTurl = {http://christoph-benzmueller.de/papers/B5.pdf}, +} + +@article{J23, + author = {Christoph Benzm{\"u}ller and Lawrence Paulson}, + journal = {Logica Universalis}, + number = {1}, + pages = {7-20}, + title = {Quantified Multimodal Logics in Simple Type Theory}, + volume = {7}, + year = {2013}, + doi = {10.1007/s11787-012-0052-y}, + OPTurl = {http://christoph-benzmueller.de/papers/J23.pdf}, +} + +@book{frege79:_begrif, + author = {Gottlob Frege}, + publisher = {Halle}, + title = {Begriffsschrift. Eine der arithmetischen + nachgebildete Formelsprache des reinen Denkens}, + year = {1879}, +} + +@article{J6, + author = {Christoph Benzm{\"u}ller and Chad Brown and + Michael Kohlhase}, + journal = {Journal of Symbolic Logic}, + number = {4}, + pages = {1027-1088}, + title = {Higher-Order Semantics and Extensionality}, + volume = {69}, + year = {2004}, + doi = {10.2178/jsl/1102022211}, + OPTurl = {http://christoph-benzmueller.de/papers/J6.pdf}, +} + +@book{andrews2002introduction, + author = {Peter B Andrews}, + publisher = {Springer}, + series = {Applied Logic Series}, + title = {An Introduction to Mathematical Logic and Type + Theory: To Truth Through Proof}, + volume = {27}, + year = {2002}, +} + +@book{Isabelle2, + author = {Nipkow, Tobias and Paulson, Lawrence C. and + Wenzel, Makarius}, + volume = {2283}, + publisher = {Springer}, + series = {LNCS}, + title = {{{Isabelle/HOL: A Proof Assistant for Higher-Order + Logic}}}, + year = {2002}, +} + +@book{Coq, + author = {Bertot, Y. and Casteran, P.}, + publisher = {Springer}, + title = {{Interactive Theorem Proving and Program + Development}}, + year = {2004}, +} + + + + +@inproceedings{Satallax, + author = {Chad E. Brown}, + booktitle = {Automated Reasoning --- 6th International Joint + Conference, {IJCAR} 2012, Manchester, UK, June 26-29, + 2012. Proceedings}, + editor = {Bernhard Gramlich and Dale Miller and Uli Sattler}, + pages = {111--117}, + publisher = {Springer}, + series = {Lecture Notes in Computer Science}, + title = {Satallax: An Automatic Higher-Order Prover}, + volume = {7364}, + year = {2012}, + isbn = {978-3-642-31364-6}, +} + +@inproceedings{Nitpick, + author = {Jasmin C. Blanchette and Tobias Nipkow}, + booktitle = {Interactive Theorem Proving --- {ITP} 2010}, + editor = {M.~Kaufmann and L.~C.~Paulson}, + pages = {131--146}, + publisher = {Springer}, + series = {LNCS}, + title = {Nitpick: {A} Counterexample Generator for + Higher-Order Logic Based on a Relational Model + Finder}, + volume = {6172}, + year = {2010}, +} + +@article{Sledgehammer, + author = {Blanchette, Jasmin C. and B\"ohme, Sascha and + Paulson, Lawrence C.}, + journal = {Journal of Automated Reasoning}, + number = {1}, + pages = {109-128}, + publisher = {Springer}, + title = {Extending {Sledgehammer} with {SMT} Solvers}, + volume = {51}, + year = {2013}, + issn = {0168-7433}, + language = {English}, +} + +@inproceedings{E, + author = {Stephan Schulz}, + booktitle = {Logic for Programming, Artificial Intelligence, and + Reasoning -- 19th International Conference, LPAR-19, + Stellenbosch, South Africa, December 14-19, 2013. + Proceedings}, + editor = {Kenneth L. McMillan and Aart Middeldorp and + Andrei Voronkov}, + pages = {735--743}, + publisher = {Springer}, + series = {Lecture Notes in Computer Science}, + title = {System Description: {E} 1.8}, + volume = {8312}, + year = {2013}, + doi = {10.1007/978-3-642-45221-5}, + isbn = {978-3-642-45220-8}, + OPTurl = {http://dx.doi.org/10.1007/978-3-642-45221-5}, +} + +@inproceedings{CVC4, + author = {Morgan Deters and Andrew Reynolds and Tim King and + Clark W. Barrett and Cesare Tinelli}, + booktitle = {Formal Methods in Computer-Aided Design, {FMCAD} + 2014, Lausanne, Switzerland, October 21-24, 2014}, + editor = {Koen Claessen and Viktor Kuncak}, + pages = {7}, + publisher = {{IEEE}}, + title = {A tour of {CVC4:} {How} it works, and how to use it}, + year = {2014}, + isbn = {978-0-9835678-4-4}, +} + +@InProceedings{Z3, +author="de Moura, Leonardo +and Bj{\o}rner, Nikolaj", +editor="Ramakrishnan, C. R. +and Rehof, Jakob", +title="Z3: An Efficient SMT Solver", +booktitle="Tools and Algorithms for the Construction and Analysis of Systems", +year="2008", +publisher="Springer Berlin Heidelberg", +address="Berlin, Heidelberg", +pages="337--340", +abstract="Satisfiability Modulo Theories (SMT) problem is a decision problem for logical first order formulas with respect to combinations of background theories such as: arithmetic, bit-vectors, arrays, and uninterpreted functions. Z3 is a new and efficient SMT Solver freely available from Microsoft Research. It is used in various software verification and analysis applications.", +isbn="978-3-540-78800-3" +} + +@inproceedings{Spass, + author = {Jasmin C. Blanchette and Andrei Popescu and + Daniel Wand and Christoph Weidenbach}, + booktitle = {Interactive Theorem Proving --- Third International + Conference, {ITP} F2012, Princeton, NJ, USA, August + 13-15, 2012. Proceedings}, + editor = {Lennart Beringer and Amy P. Felty}, + pages = {345--360}, + publisher = {Springer}, + series = {Lecture Notes in Computer Science}, + title = {{More {SPASS} with Isabelle -- Superposition with + Hard Sorts and Configurable Simplification}}, + volume = {7406}, + year = {2012}, + isbn = {978-3-642-32346-1}, +} + +@inproceedings{Vampire, + author = {Laura Kov{\'{a}}cs and Andrei Voronkov}, + booktitle = {Computer Aided Verification - 25th International + Conference, {CAV} 2013, Saint Petersburg, Russia, + July 13-19, 2013. Proceedings}, + editor = {Natasha Sharygina and Helmut Veith}, + pages = {1--35}, + publisher = {Springer}, + series = {Lecture Notes in Computer Science}, + title = {{First-Order Theorem Proving and Vampire}}, + volume = {8044}, + year = {2013}, + isbn = {978-3-642-39798-1}, +} + +@phdthesis{BaldoniPhD, + author = {Matteo Baldoni}, + note = {(Revised version dated July 9, 2003)}, + school = {Dipartimento di Informatica, Universit\'a degli Studi + di Torino}, + title = {Normal Multimodal Logics: Automatic Deduction and + Logic Programming Extension}, + year = {2003}, +} + +@book{fagin04:_reason_about_knowl, + author = {Ronald Fagin and Halpern, Joseph Y. and Yoram Moses and + Moshe Vardi}, + publisher = {The MIT Press}, + title = {Reasoning About Knowledge}, + year = {2004}, +} + +@incollection{DBLP:books/el/RV01/OhlbachNRG01, + author = {Ohlbach, H.J. and Nonnengart, A. and de Rijke, M. and + Gabbay, D.M.}, + booktitle = {Handbook of Automated Reasoning (in 2 volumes)}, + editor = {J.A. Robinson and A. Voronkov}, + pages = {1403--1486}, + publisher = {Elsevier and {MIT} Press}, + title = {Encoding Two-Valued Nonclassical Logics in Classical + Logic}, + year = {2001}, +} + +@article{J25, + author = {Christoph Benzm{\"u}ller}, + journal = {Annals of Mathematics and Artificial Intelligence}, + number = {1--2}, + pages = {103-128}, + title = {Combining and Automating Classical and Non-Classical + Logics in Classical Higher-Order Logic}, + volume = {62}, + year = {2011}, + doi = {10.1007/s10472-011-9249-7}, + OPTurl = {http://christoph-benzmueller.de/papers/J25.pdf}, +} + +@misc{sergot08:_epist_logic_common_knowl, + author = {Marek Sergot}, + howpublished = {Lecture Course Notes, Department of Computing + Imperial College, London, + \url{https://www.doc.ic.ac.uk/~mjs/teaching/ModalTemporal499/Epistemic_499_v0809_2up.pdf}}, + title = {Epistemic Logic and ‘Common Knowledge’}, + year = {2008}, +} + +@incollection{sep-dynamic-epistemic, + author = {Baltag, Alexandru and Renne, Bryan}, + booktitle = {The Stanford Encyclopedia of Philosophy}, + edition = {Winter 2016}, + editor = {Edward N. Zalta}, + howpublished = + {\url{https://plato.stanford.edu/archives/win2016/entries/dynamic-epistemic/}}, + publisher = {Metaphysics Research Lab, Stanford University}, + title = {Dynamic Epistemic Logic}, + year = {2016}, +} + +@article{J22, + author = {Geoff Sutcliffe and Christoph Benzm{\"u}ller}, + journal = {Journal of Formalized Reasoning}, + number = {1}, + pages = {1-27}, + title = {Automated Reasoning in Higher-Order Logic using the + {TPTP THF} Infrastructure}, + volume = {3}, + year = {2010}, + issn = {1972-5787}, + OPTurl = {http://christoph-benzmueller.de/papers/J22.pdf}, +} + +@article{J5, + author = {Christoph Benzm{\"u}ller}, + journal = {Synthese}, + number = {1-2}, + pages = {203-235}, + title = {Comparing Approaches to Resolution based Higher-Order + Theorem Proving}, + volume = {133}, + year = {2002}, + abstract = {We investigate several approaches to resolution based + automated theorem proving in classical higher-order + logic (based on Church's simply typed lambda + calculus) and discuss their requirements with respect + to Henkin completeness and full extensionality. In + particular we focus on Andrews' higher-order + resolution [Andrews71], Huet's constrained resolution + [Huet72], higher-order $E$-resolution, and + extensional higher-order resolution + [BenzmuellerKohlhase98]. With the help of examples we + illustrate the parallels and differences of the + extensionality treatment of these approaches and + demonstrate that extensional higher-order resolution + is the sole approach that can completely avoid + additional extensionality axioms.}, + doi = {10.1023/A:1020840027781}, + issn = {0039-7857}, + OPTurl = {http://christoph-benzmueller.de/papers/J5.pdf}, +} + +@article{J12, + author = {J{\"o}rg Siekmann and Christoph Benzm{\"u}ller and + Serge Autexier}, + journal = {Journal of Applied Logic}, + number = {4}, + pages = {533-559}, + title = {Computer Supported Mathematics with {OMEGA}}, + volume = {4}, + year = {2006}, + doi = {10.1016/j.jal.2005.10.008}, + OPTurl = {http://christoph-benzmueller.de/papers/J12.pdf}, +} + +@incollection{B10, + author = {Serge Autexier and Christoph Benzm\"uller and + Dominik Dietrich and J\"org Siekmann}, + booktitle = {Resource-Adaptive Cognitive Processes}, + editor = {Matthew W. Crocker and J\"org Siekmann}, + pages = {389-423}, + publisher = {Springer}, + series = {Cognitive Technologies}, + title = {{OMEGA}: Resource-Adaptive Processes in an Automated + Reasoning Systems}, + year = {2010}, + doi = {10.1007/978-3-540-89408-7_17}, + isbn = {978-3-540-89407-0}, + OPTurl = {http://christoph-benzmueller.de/papers/B10.pdf}, +} + +@incollection{B1, + author = {J{\"o}rg Siekmann and Christoph Benzm{\"u}ller and + Armin Fiedler and Andreas Meier and Immanuel Normann and + Martin Pollet}, + booktitle = {Thirty Five Years of Automating Mathematics}, + editor = {Fairouz Kamareddine}, + pages = {271-314}, + publisher = {Kluwer Academic Publishers}, + series = {Applied Logic series (28)}, + title = {Proof Development in {OMEGA}: The Irrationality of + Square Root of 2}, + year = {2003}, + doi = {10.1007/978-94-017-0253-9_11}, + isbn = {978-1-402-01656-1}, + OPTurl = {http://christoph-benzmueller.de/papers/B1.pdf}, +} + +@incollection{B11, + author = {Christoph Benzm\"uller and Marvin Schiller and + J\"org Siekmann}, + booktitle = {Resource-Adaptive Cognitive Processes}, + editor = {Matthew W. Crocker and J\"org Siekmann}, + pages = {291-311}, + publisher = {Springer}, + series = {Cognitive Technologies}, + title = {Resource-Bounded Modelling and Analysis of + Human-Level Interactive Proofs}, + year = {2010}, + doi = {10.1007/978-3-540-89408-7_13}, + isbn = {978-3-540-89407-0}, + OPTurl = {http://christoph-benzmueller.de/papers/B11.pdf}, +} + +@article{J27, + author = {Christoph Benzm{\"u}ller and Adam Pease}, + journal = {Journal of Web Semantics}, + pages = {104-117}, + title = {Higher-order Aspects and Context in {SUMO}}, + volume = {12-13}, + year = {2012}, + doi = {10.1016/j.websem.2011.11.008}, + OPTurl = {http://christoph-benzmueller.de/papers/J27.pdf}, +} + +@incollection{B9, + author = {Christoph Benzm{\"u}ller and Lawrence Paulson}, + booktitle = {Reasoning in Simple Type Theory --- Festschrift in + Honor of {Peter B. Andrews} on His 70th Birthday}, + editor = {Christoph Benzm{\"u}ller and Chad Brown and + J{\"o}rg Siekmann and Richard Statman}, + note = {(Superseded by 2013 article in Logica Universalis)}, + pages = {386-406}, + publisher = {College Publications}, + series = {Studies in Logic, Mathematical Logic and Foundations}, + title = {Exploring Properties of Normal Multimodal Logics in + Simple Type Theory with {LEO-II}}, + year = {2008}, + isbn = {978-1-904987-70-3}, + OPTurl = {http://christoph-benzmueller.de/papers/B9.pdf}, +} + +@article{J21, + author = {Christoph Benzm{\"u}ller and Lawrence Paulson}, + journal = {The Logic Journal of the IGPL}, + number = {6}, + pages = {881-892}, + title = {Multimodal and Intuitionistic Logics in Simple Type + Theory}, + volume = {18}, + year = {2010}, + doi = {10.1093/jigpal/jzp080}, + OPTurl = {http://christoph-benzmueller.de/papers/J21.pdf}, +} + +@unpublished{zalta16:_princ_logic_metap, + author = {Edward N. Zalta}, + note = {Preprint available at + \url{https://mally.stanford.edu/principia.pdf}}, + title = {{Principia Logico-Metaphysica (Draft/Excerpt)}}, + year = {2018}, +} + +@book{stalnaker12:_mere_possin, + author = {Robert C. Stalnaker}, + publisher = {Princeton University Press}, + title = {Mere Possibilities: Metaphysical Foundations of Modal + Semantics}, + year = {2012}, +} + +@book{williamson13, + author = {T. Williamson}, + publisher = {Oxford:OUP}, + title = {Modal Logic as Metaphysics}, + year = {2013}, +} + +@article{FitelsonZalta, + author = {Branden Fitelson and Edward N. Zalta}, + journal = {Journal Philosophical Logic}, + number = {2}, + pages = {227--247}, + title = {Steps Toward a Computational Metaphysics}, + volume = {36}, + year = {2007}, + doi = {10.1007/s10992-006-9038-7}, +} + +@article{OppenheimerZalta2011, + author = {P. E. Oppenheimer and Edward N. Zalta}, + journal = {Australasian Journal of Philosophy}, + number = {2}, + pages = {333-349}, + title = {A Computationally-Discovered Simplification of the + Ontological Argument}, + volume = {89}, + year = {2011}, +} + +@inproceedings{AlamaZalta2015, + author = {Jesse Alama and Oppenheimer, Paul E. and + Zalta, Edward N.}, + booktitle = {Automated Deduction -- {CADE-25}}, + OPTeditor = {A.~P.~Felty and A.~Middeldorp}, + pages = {73--97}, + publisher = {Springer}, + series = {LNCS}, + title = {Automating Leibniz's Theory of Concepts}, + volume = {9195}, + year = {2015}, +} + + +@inproceedings{C40, + author = {Christoph Benzm{\"u}ller and + Woltzenlogel Paleo, Bruno}, + booktitle = {ECAI 2014}, + OPTeditor = {T. Schaub and et al.}, + pages = {93--98}, + publisher = {IOS Press}, + series = {Frontiers in Artificial Intelligence and + Applications}, + title = {Automating {G\"{o}del's} Ontological Proof of {God}'s + Existence with Higher-order Automated Theorem + Provers}, + volume = {263}, + year = {2014}, + doi = {10.3233/978-1-61499-419-0-93}, + OPTurl = {http://christoph-benzmueller.de/papers/C40.pdf}, +} + +@inproceedings{C55, + author = {Christoph Benzm{\"u}ller and + Woltzenlogel Paleo, Bruno}, + booktitle = {{IJCAI} 2016}, + editor = {S.~Kambhampati}, + pages = {936-942}, + publisher = {AAAI Press}, + title = {The Inconsistency in {G{\"o}del's} Ontological + Argument: A Success Story for {AI} in Metaphysics}, + volume = {1-3}, + year = {2016}, + isbn = {978-1-57735-770-4}, + url = {http://www.ijcai.org/Proceedings/16/Papers/137.pdf}, +} + +@inproceedings{C60, + address = {Berlin, Germany}, + author = {Christoph Benzm{\"u}ller and + Woltzenlogel Paleo, Bruno}, + booktitle = {{KI 2016}: Advances in Artificial Intelligence, + Proceedings}, + editor = {Malte Helmert and Franz Wotawa}, + pages = {244-250}, + publisher = {Springer}, + series = {Lecture Notes in Computer Science}, + title = {An Object-Logic Explanation for the Inconsistency in + {G\"odel's} Ontological Theory (Extended Abstract, + Sister Conferences)}, + year = {2016}, + doi = {10.1007/978-3-319-46073-4}, + OPTurl = {http://christoph-benzmueller.de/papers/C60.pdf}, +} + +@inCollection{GoedelNotes, + author = {Kurt G\"odel}, + OPTbooktitle = {Logic and Theism: Arguments for and Against Beliefs + in God}, + editor = {Sobel, J.H.}, + pages = {144--145}, + OPTpublisher = {Cambridge University Press}, + title = {{Appendix A. Notes in Kurt G\"odel's Hand}}, + OPTchapter = {Appendix A. Notes in Kurt G\"odel's Hand}, + year = {1970}, + isbn = {9781139449984}, + crossref = {sobel2004logic}, +} + +@inCollection{ScottNotes, + author = {Dana S. Scott}, + OPTbooktitle = {Logic and Theism: Arguments for and Against Beliefs + in God}, + editor = {Sobel, J.H.}, + pages = {145-146}, + OPTpublisher = {Cambridge U. Press}, + title = {{Appendix B: Notes in Dana Scott's Hand}}, + OPTchapter = {Appendix B: Notes in Dana Scott's Hand}, + year = 1972, + isbn = 9781139449984, + crossref = {sobel2004logic}, +} + +@book{BC04, + author = {Bertot, Y. and Casteran, P.}, + publisher = {Springer}, + series = {Texts in Theoretical Computer Science}, + title = {{Interactive Theorem Proving and Program Development + - Coq'Art: The Calculus of Inductive Constructions}}, + year = {2004}, +} + +@incollection{Sobel, + author = {Sobel, Jordan H.}, + booktitle = {{On Being and Saying. Essays for Richard Cartwright}}, + editor = {Judith Jarvis Tomson}, + pages = {241-261}, + publisher = {{MIT Press}}, + title = {G\"odel's Ontological Proof}, + year = {1987}, +} + +@article{Anderson90, + author = {C. Anthony Anderson}, + journal = {Faith and Philosophy}, + number = {3}, + title = {Some emendations of {G{\"o}del's} ontological proof}, + volume = {7}, + year = {1990}, + pages = {291--303} +} + +@incollection{AndersonGettings, + author = {Anderson, C. Anthony and Gettings, M.}, + booktitle = {{G\"odel'96: Logical Foundations of Mathematics, + Computer Science, and Physics: Lecture Notes in Logic + 6}}, + pages = {167-172}, + publisher = {{Springer}}, + title = {{G\"odel}'s Ontological Proof Revisited}, + year = {1996}, +} + +@incollection{Hajek1, + author = {H\'ajek, Petr}, + booktitle = {Logic and algebra}, + editor = {A. Ursini and P. Agliano}, + pages = {125–135}, + publisher = {Dekker, New York etc.}, + title = {Magari and others on {G\"odel’s} ontological proof}, + year = {1996}, +} + +@incollection{Hajek2, + author = {H\'ajek, Petr}, + booktitle = {{Kurt G{\"o}del. Wahrheit und Beweisbarkeit}}, + editor = {Buldt et al., B.}, + note = {ISBN 3-209-03835-X}, + pages = {325-336}, + publisher = {öbv \& hpt Verlagsgesellschaft mbH, Wien}, + title = {{Der Mathematiker und die Frage der Existenz Gottes}}, + year = {2001}, +} + +@article{Hajek3, + author = {Petr H{\'{a}}jek}, + journal = {Studia Logica}, + number = {2}, + pages = {149--164}, + title = {A New Small Emendation of {G{\"{o}}del's} Ontological + Proof}, + volume = {71}, + year = {2002}, +} + +@incollection{Bjordal, + author = {F. Bj{\o}rdal}, + booktitle = {The Logica Yearbook 1998}, + editor = {T. Childers}, + publisher = {Filosofia}, + title = {Understanding {G\"{o}del’s} Ontological Argument}, + pages = {214-217}, + year = {1999}, +} + +@article{J32, + author = {Benzm{\"u}ller, Christoph and Weber, Leon and + Woltzenlogel Paleo, Bruno}, + journal = {Logica Universalis}, + number = {1}, + pages = {139-151}, + title = {Computer-Assisted Analysis of the + {Anderson-H\'{a}jek} Controversy}, + volume = {11}, + year = {2017}, + doi = {10.1007/s11787-017-0160-9}, + OPTurl = {http://christoph-benzmueller.de/papers/J32.pdf}, +} + + +@Article{J36, + Keywords = {own, Automated Reasoning, Intensional Higher-Order Modal + Logic, Higher Order Logic}, + author = {Christoph Benzm{\"u}ller and Woltzenlogel Paleo, + Bruno}, + title = {Experiments in {Computational Metaphysics}: + {G\"odel's} Proof of {God's} Existence}, + journal = {Savijnanam: scientific exploration for a spiritual + paradigm. Journal of the Bhaktivedanta Institute}, + year = 2017, + volume = 9, + pages = {43-57}, + OPTurl = + {https://sites.google.com/binstitute.org/journal/article-3-page-43}, + issn = {0972-6586}, +} + + +@inproceedings{C50, + address = {Wroclaw, Poland}, + author = {Christoph Benzm{\"u}ller}, + booktitle = {TABLEAUX 2015}, + editor = {Hans De Nivelle}, + pages = {213-220}, + publisher = {Springer}, + series = {LNAI}, + title = {Invited Talk: On a (Quite) Universal Theorem Proving + Approach and Its Application in Metaphysics}, + volume = {9323}, + year = {2015}, + doi = {10.1007/978-3-319-24312-2_15}, + OPTurl = {http://christoph-benzmueller.de/papers/C50.pdf}, +} + +@inproceedings{C46, + address = {Berlin, Germany}, + author = {Christoph Benzm{\"u}ller and + Woltzenlogel Paleo, Bruno}, + booktitle = {Reasoning Web 2015}, + editor = {Adrian Paschke and Wolfgang Faber}, + number = {9203}, + pages = {32-74}, + publisher = {Springer}, + series = {Lecture Notes in Computer Science}, + title = {Higher-Order Modal Logics: Automation and + Applications}, + year = {2015}, + doi = {10.1007/978-3-319-21768-0_2}, + OPTurl = {http://christoph-benzmueller.de/papers/C46.pdf}, +} + + + +@article{J28, + author = {Christoph Benzm\"uller and Woltzenlogel Paleo, Bruno}, + journal = {Archive of Formal Proofs}, + OPTnote = {This publication is machine verified with + Isabelle/HOL, but comparably mildly human reviewed}, + title = {{G{\"o}del's God in Isabelle/HOL}}, + volume = {2013}, + year = {2013}, + url = {http://afp.sourceforge.net/entries/GoedelGod.shtml}, +} + +@inproceedings{W55, + address = {Sinaia, Romania}, + author = {Christoph Benzm{\"u}ller and + Woltzenlogel Paleo, Bruno}, + booktitle = {Recent Trends in Algebraic Development Techniques: + 22nd International Workshop, WADT 2014, Sinaia, + Romania, September 4-7, 2014, Revised Selected + Papers}, + editor = {Codescu, Mihai and Diaconescu, Razvan and + Tutu, Ionut}, + number = {9563}, + pages = {3-6}, + publisher = {Springer}, + series = {Lecture Notes in Computer Science}, + title = {On Logic Embeddings and {G\"odel's} {God}}, + year = {2015}, + doi = {10.1007/978-3-319-28114-8_1}, + isbn = {978-3-319-28114-8}, + OPTurl = {http://christoph-benzmueller.de/papers/W55.pdf}, +} + +@incollection{B15, + author = {Benzm{\"u}ller, Christoph and + Woltzenlogel Paleo, Bruno}, + booktitle = {The Square of Opposition: A Cornerstone of Thought + (Collection of papers related to the World Congress + on the Square of Opposition IV, Vatican, 2014)}, + note = {\url{http://www.springer.com/us/book/9783319450612}}, + editor = {B\'{e}ziau, Jean-Yves and Basti, Gianfranco}, + pages = {307-313}, + publisher = {Springer International Publishing Switzerland}, + series = {Studies in Universal Logic}, + title = {The Modal Collapse as a Collapse of the Modal Square + of Opposition}, + year = {2016}, + doi = {10.1007/978-3-319-45062-9_18}, + OPTurl = {http://christoph-benzmueller.de/papers/B15.pdf}, +} + + + +@inproceedings{C56, + address = {Berlin, Germany}, + author = {Alexander Steen and Max Wisniewski and + Christoph Benzm{\"u}ller}, + booktitle = {Mathematical Software -- ICMS 2016, 5th International + Congress, Proceedings}, + editor = {G.-M. Greuel and T. Koch and P. Paule and A. Sommese}, + pages = {75-81}, + publisher = {Springer}, + series = {Lecture Notes in Computer Science}, + title = {Agent-Based {HOL} Reasoning}, + volume = {9725}, + year = {2016}, + doi = {10.1007/978-3-319-42432-3_10}, + isbn = {978-3-319-42431-6}, + OPTurl = {http://christoph-benzmueller.de/papers/C56.pdf}, +} + +@book{fitting02:_types_tableaus_god, + author = {Melvin Fitting}, + publisher = {Kluwer}, + title = {Types, Tableaus, and {G}{\"o}del's God}, + year = {2002}, +} + +@book{Principia, + author = {Alfred North Whitehead and Bertrand Russell}, + publisher = {Cambridge: Cambridge University Press. Second + edition, 1925 (Vol. 1), 1927 (Vols 2, 3). Abridged as + Principia Mathematica to *56, Cambridge: Cambridge + University Press, 1962.}, + title = {Principia Mathematica, 3 vols}, + year = {1910, 1912, 1913}, +} + +@book{zalta1988intensional, + author = {Edward N. Zalta}, + publisher = {MIT Press}, + series = {A Bradford book}, + title = {Intensional Logic and the Metaphysics of + Intentionality}, + year = {1988}, + isbn = {9780262240277}, +} + +@article{zalta1988validity, + author = {Edward N. Zalta}, + journal = {The Journal of Philosophy}, + title = {Logical and Analytic Truths That Are Not Necessary}, + year = {1988}, + volume = {85}, + number = {2}, + pages = {57--74}, +} + +@book{zalta1983abstract, + author = {Edward N. Zalta}, + publisher = {D. Reidel}, + title = {Abstract Objects: An Introduction to Axiomatic + Metaphysics}, + city = {Dordrecht}, + year = {1983}, + isbn = {9789027714749}, + OPTurl = {https://books.google.de/books?id=voCSP6k3FCcC}, +} + +@article{DBLP:journals/logcom/OppenheimerZ11, + author = {Paul E. Oppenheimer and Edward N. Zalta}, + journal = {Journal of Logic and Computation}, + number = 2, + pages = {351--374}, + title = {Relations Versus Functions at the Foundations of + Logic: Type-Theoretic Considerations}, + volume = 21, + year = 2011, + doi = {10.1093/logcom/exq017}, + url = {http://dx.doi.org/10.1093/logcom/exq017}, +} + + + +@article{DBLP:journals/afp/Kirchner17, + author = {Daniel Kirchner}, + journal = {Archive of Formal Proofs}, + title = {Representation and Partial Automation of the + Principia Logico-Metaphysica in {Isabelle/HOL}}, + volume = {2017}, + year = {2017}, + url = {https://www.isa-afp.org/entries/PLM.html}, +} + +@techreport{R60, + author = {Kirchner, Daniel and Benzm{\"u}ller, Christoph and + Edward N. Zalta}, + institution = {CoRR}, + note = {Preprint of submitted article}, + title = {{Mechanizing Principia Logico-Metaphysica in + Functional Type Theory}}, + year = {2017}, + url = {https://arxiv.org/abs/1711.06542}, +} + +@book{link08:_one_hundr_years_russel_parad, + editor = {Link, Godehard}, + publisher = {De Gruyter}, + title = {One Hundred Years of Russell's Paradox}, + year = {2008}, +} + +@book{Frege1879, + author = {Gottlob Frege}, + note = {Translated in \cite{vanHeijenoort67}}, + publisher = {Halle}, + title = {Begriffsschrift, eine der arithmetischen + nachgebildete Formelsprache des reinen Denkens}, + year = {1879}, +} + +@inproceedings{Lambert60, + author = {Karel Lambert}, + booktitle = {Abstracts: The International Congress for Logic, + Methodology and Philosophy of Science}, + publisher = {Stanford: Stanford University Press}, + title = {The Definition of E(xistence)! in Free Logic}, + year = {1960}, +} + +@incollection{Scott67, + author = {Dana S. Scott}, + booktitle = {Bertrand Russell: Philosopher of the Century}, + editor = {R. Schoenman}, + note = {(Reprinted with additions in: Philosophical + Application of Free Logic, edited by K. Lambert. + Oxford Universitry Press, 1991, pp. 28 - 48)}, + pages = {181-200}, + publisher = {George Allen \& Unwin, London}, + title = {Existence and description in formal logic}, + year = {1967}, +} + +@book{lambert02:_free_logic, + author = {Karel Lambert}, + publisher = {Cambridge: Cambridge University Press}, + title = {Free Logic: Selected Essays}, + year = {2002}, +} + +@InCollection{sep-logic-free, + author = {Nolt, John}, + title = {Free Logic}, + booktitle = {The Stanford Encyclopedia of Philosophy}, + editor = {Edward N. Zalta}, + howpublished = {\url{https://plato.stanford.edu/archives/fall2018/entries/logic-free/}}, + year = {2018}, + edition = {Fall 2018}, + publisher = {Metaphysics Research Lab, Stanford University} +} + + +@techreport{R58, + author = {Christoph Benzm{\"u}ller and Scott, Dana S.}, + institution = {CoRR}, + title = {Axiomatizing Category Theory in Free Logic}, + year = {2016}, + url = {http://arxiv.org/abs/1609.01493}, +} + +@inproceedings{C57, + address = {Berlin, Germany}, + author = {Christoph Benzm{\"u}ller and Scott, Dana S.}, + booktitle = {Mathematical Software -- ICMS 2016, 5th International + Congress, Proceedings}, + editor = {G.-M. Greuel and T. Koch and P. Paule and A. Sommese}, + pages = {43-50}, + publisher = {Springer}, + series = {Lecture Notes in Computer Science}, + title = {Automating Free Logic in {Isabelle/HOL}}, + volume = {9725}, + year = {2016}, + doi = {10.1007/978-3-319-42432-3_6}, + isbn = {978-3-319-42431-6}, + OPTurl = {http://christoph-benzmueller.de/papers/C57.pdf}, +} + + +@article{J39, + author = {Christoph Benzm{\"u}ller and Scott, Dana S.}, + title = {Axiom Systems for Category Theory in Free Logic}, + journal = {Archive of Formal Proofs}, + month = may, + year = 2018, + note = {\url{http://isa-afp.org/entries/AxiomaticCategoryTheory.html}, + Formal proof development}, + ISSN = {2150-914x}, +} + +@book{FreydScedrov90, + author = {Peter Freyd and Andre Scedrov}, + publisher = {North Holland}, + title = {Categories, Allegories}, + year = {1990}, +} + +@incollection{Scott79, + author = {Scott, Dana S.}, + booktitle = {Applications of Sheaves: Proceedings of the Research + Symposium on Applications of Sheaf Theory to Logic, + Algebra, and Analysis, Durham, July 9--21, 1977}, + editor = {Fourman, Michael and Mulvey, Christopher and + Scott, Dana}, + pages = {660--696}, + publisher = {Springer}, + series = {Lecture Notes in Mathematics}, + title = {Identity and existence in intuitionistic logic}, + volume = {752}, + year = {1979}, +} + +@article{J31, + author = {Christoph Benzm{\"u}ller}, + journal = {Journal of Philosophical Logic}, + number = {3}, + pages = {333-353}, + title = {Cut-Elimination for Quantified Conditional Logic}, + volume = {46}, + year = {2017}, + doi = {10.1007/s10992-016-9403-0}, + OPTurl = {http://christoph-benzmueller.de/papers/J31.pdf}, +} + +@incollection{Stalnaker68, + author = {Robert C. Stalnaker}, + booktitle = {Studies in Logical Theory}, + pages = {98--112}, + publisher = {Blackwell}, + title = {A Theory of Conditionals}, + year = {1968}, +} + +@article{Chellas75, + author = {Chellas, B.F.}, + journal = {Journal of Philosophical Logic}, + number = {2}, + pages = {133-153}, + title = {Basic Conditional Logic}, + volume = {4}, + year = {1975}, +} + +@article{delgrande98, + author = {J.P. Delgrande}, + journal = {Artificial Intelligence}, + number = {1-2}, + pages = {105-137}, + title = {On First-Order Conditional Logics}, + volume = {105}, + year = {1998}, +} + +@article{delgrande87, + author = {J.P. Delgrande}, + journal = {Artificial Intelligence}, + number = {1}, + pages = {105-130}, + title = {A First-Order Conditional Logic for Prototypical + Properties}, + volume = {33}, + year = {1987}, +} + +@article{DBLP:journals/tocl/FriedmanHK00, + author = {N. Friedman and J.Y. Halpern and D. Koller}, + journal = {ACM Transactions on Computational Logic}, + number = {2}, + pages = {175-207}, + title = {First-order conditional logic for default reasoning + revisited}, + volume = {1}, + year = {2000}, +} + +@article{DBLP:journals/corr/abs-1011-3479, + author = {Dirk Pattinson and Lutz Schr{\"{o}}der}, + journal = {Logical Methods in Computer Science}, + number = {1}, + title = {Generic Modal Cut Elimination Applied to Conditional + Logics}, + volume = {7}, + year = {2011}, + bibOPTurl = {http://dblp.uni-trier.de/rec/bib/journals/corr/abs-1011- + 3479}, + doi = {10.2168/LMCS-7(1:4)2011}, +} + +@article{DBLP:journals/apal/Rasga07, + author = {Jo{\~{a}}o Rasga}, + journal = {Ann. Pure Appl. Logic}, + number = {1-3}, + pages = {81--99}, + title = {Sufficient conditions for cut elimination with + complexity analysis}, + volume = {149}, + year = {2007}, + bibOPTurl = {http://dblp.uni-trier.de/rec/bib/journals/apal/Rasga07}, + doi = {10.1016/j.apal.2007.08.001}, +} + +@inproceedings{C37, + address = {Beijing, China}, + author = {Christoph Benzm{\"u}ller}, + booktitle = {23rd International Joint Conference on Artificial + Intelligence ({IJCAI-13})}, + editor = {Francesca Rossi}, + pages = {746-753}, + publisher = {AAAI Press}, + title = {Automating Quantified Conditional Logics in {HOL}}, + year = {2013}, + isbn = {978-1-57735-633-2}, + OPTurl = {http://christoph-benzmueller.de/papers/C37.pdf}, +} + +@article{J18, + author = {Christoph Benzm{\"u}ller and Chad Brown and + Michael Kohlhase}, + journal = {Logical Methods in Computer Science}, + number = {1:6}, + pages = {1-21}, + title = {Cut-Simulation and Impredicativity}, + volume = {5}, + year = {2009}, + doi = {10.2168/LMCS-5(1:6)2009}, + OPTurl = {http://christoph-benzmueller.de/papers/J18.pdf}, +} + +@inproceedings{C58, + OPTaddress = {Potsdam}, + author = {Max Wisniewski and Alexander Steen and + Christoph Benzm{\"u}ller}, + booktitle = {Hochschuldidaktik der Informatik: 7. Fachtagung des + GI-Fachbereichs Informatik und Ausbildung/Didaktik + der Informatik}, + editor = {Andreas Schwill and Ulrike Lucke}, + pages = {81-92}, + publisher = {Universit{\"a}tsverlag Potsdam}, + series = {Commentarii informaticae didacticae (CID)}, + title = {{Einsatz von Theorembeweisern in der Lehre}}, + year = {2016}, + isbn = {978-3-86956-376-3}, + issn = {1868-0844}, + OPTurl = {https://publishup.uni-potsdam.de/opus4-ubp/frontdoor/index/ + index/docId/9485}, +} + +@unpublished{R57, + author = {Christoph Benzm{\"u}ller and Max Wisniewski and + Alexander Steen}, + note = {This lecture course proposal received the 2015 + central teaching award of FU Berlin}, + title = {{Computational Metaphysics}}, + year = {2015}, + url = {http://christoph-benzmueller.de/papers/R57.pdf}, +} + +@incollection{B16, + author = {Bentert, Matthias and Benzm{\"u}ller, Christoph and + Streit, David and Woltzenlogel Paleo, Bruno}, + booktitle = {Death and Anti-Death, Volume 14: Four Decades after + Michael Polanyi, Three Centuries after G.W. Leibniz}, + editor = {Tandy, Charles}, + note = {Preprint: + \url{https://www.researchgate.net/publication/311456135}}, + publisher = {Ria University Press}, + title = {Analysis of an Ontological Proof Proposed by + {Leibniz}}, + year = {2016}, + isbn = {978-1934297254}, + OPTurl = {https://philpapers.org/rec/TANDAA-10}, +} + +@inproceedings{C63, + author = {David Fuenmayor and Christoph Benzm{\"u}ller and + Alexander Steen and Max Wisniewski}, + booktitle = {Handbook of the 2nd World Congress on Logic and + Religion, Warsaw, Poland}, + editor = {Stanislaw Krajewski and Piotr Balcerowicz}, + pages = {3}, + title = {The Virtues of Automated Theorem Proving in + Metaphysics --- A Case Study: {E. J. Lowe's} Modal + Ontological Argument}, + year = {2017}, + OPTurl = {http://christoph-benzmueller.de/papers/C63.pdf}, +} + +@inproceedings{C65, + author = {David Fuenmayor and Christoph Benzm{\"u}ller}, + booktitle = {KI 2017: Advances in Artificial Intelligence}, + pages = {114-127}, + publisher = {Springer}, + series = {LNAI}, + title = {Automating Emendations of the Ontological Argument in + Intensional Higher-Order Modal Logic}, + volume = {10505}, + year = {2017}, + doi = {10.1007/978-3-319-67190-1_9}, + isbn = {978-3-319-67189-5}, + OPTurl = {http://christoph-benzmueller.de/papers/C65.pdf}, +} + + +@article{J37, + author = {David Fuenmayor and Christoph Benzm\"uller}, + journal = {Archive of Formal Proofs}, + OPTnote = {This publication is machine verified with + Isabelle/HOL, but comparably mildly human reviewed}, + title = {{Computer-assisted Reconstruction and Assessment of + E. J. Lowe's Modal Ontological Argument}}, +volume = {2017}, + year = {2017}, + url = {https://www.isa-afp.org/entries/Lowe_Ontological_Argument.html}, +} + + + +@MastersThesis{BScMakarenko, + author = {Irina Makarenko}, + school = {Department of Mathematics and Computer Science, Freie + Universit{\"a}t Berlin}, + type = {Bachelor's Thesis}, + title = {Automatisierung von freier Logik in Logik h{\"o}herer + Stufe}, + year = {2016}, +} + +@MastersThesis{BScFuenmayor, + author = {David Fuenmayor}, + school = {Department of Philosophy, Freie Universit{\"a}t + Berlin}, + type = {Bachelor's Thesis}, + title = {Computational Hermeneutics: Using Computers to + Understand Philosophical Arguments}, + year = {2017}, +} + +@MastersThesis{BScGleissner, + author = {Tobias Gleissner}, + school = {Department of Mathematics and Computer Science, Freie + Universit{\"a}t Berlin}, + type = {Bachelor's Thesis}, + title = {Converting Higher-Order Modal Logic Problems into + Classical Higher-Order Logic}, + year = {2017}, +} + +@MastersThesis{MScSchuetz, + author = {Fabian Sch{\"u}tz}, + school = {Department of Mathematics and Computer Science, Freie + Universit{\"a}t Berlin}, + type = {Master's Thesis}, + title = {{Wahrhaftiger Toren Zorn - Repr{\"a}sentation und + Interpretation von Argumenten}}, + year = {2017}, +} + +@article{J33, + author = {Steen, Alexander and Benzm{\"u}ller, Christoph}, + journal = {Logic and Logical Philosophy}, + pages = {535-554}, + title = {Sweet {SIXTEEN}: Automation via Embedding into + Classical Higher-Order Logic}, + volume = {25}, + year = {2016}, + doi = {10.12775/LLP.2016.021}, + issn = {1425-3305}, + OPTurl = {http://christoph-benzmueller.de/papers/J33.pdf}, +} + +@inproceedings{wisniewski14:_embed_quant_higher_order_nomin, + author = {Max Wisniewski and Alexander Steen}, + booktitle = {1st International Workshop on Automated Reasoning in + Quantified Non-Classical Logics (ARQNL 2014), Vienna, + Austria, Proceedings}, + editor = {Christoph Benzm\"uller and Jens Otten}, + pages = {59-64}, + publisher = {EasyChair Publications}, + series = {EasyChair Proceedings in Computing}, + title = {Embedding of Quantified Higher-Order Nominal Modal + Logic into Classical Higher-Order Logic}, + volume = {33}, + year = {2014}, +} + +@MastersThesis{MScClaus, + author = {Maximilian Claus}, + school = {Department of Mathematics and Computer Science, Freie + Universit{\"a}t Berlin}, + type = {Master's Thesis}, + title = {Software Model Checking With Higher-Order Automated + Theorem Provers: A Logic Embedding Approach}, + year = {2015}, +} + +@book{boolos93:_logic_provab, + author = {George Boolos}, + publisher = {Cambridge University Press}, + title = {The Logic of Provability}, + year = {1993}, +} + +@article{bostrom03:_are_we_livin_comput_simul, + author = {Nick Bostrom}, + journal = {The Philosophical Quarterly}, + number = {211}, + pages = {243–255}, + title = {Are We Living in a Computer Simulation?}, + volume = {53}, + year = {2003}, + doi = {10.1111/1467-9213.00309}, +} + +@techreport{R59, + author = {Christoph Benzm{\"u}ller}, + institution = {CoRR}, + title = {Universal Reasoning, Rational Argumentation and + Human-Machine Interaction}, + year = {2017}, + url = {http://arxiv.org/abs/1703.09620}, +} + +@book{gabbay13:_handb_deont_logic_normat_system, + editor = {Dov Gabbay and John Horty and Xavier Parent and + van der Meyden, Ron and van der Torre, Leendert}, + publisher = {College Publications}, + title = {Handbook of Deontic Logic and Normative Systems}, + year = {2013}, +} + +@article{DBLP:journals/jphil/MakinsonT00, + author = {David Makinson and Leendert W. N. van der Torre}, + journal = {Journal of Philosophical Logic}, + number = {4}, + pages = {383--408}, + title = {Input/Output Logics}, + volume = {29}, + year = {2000}, + biburl = {http://dblp.uni-trier.de/rec/bib/journals/jphil/ + MakinsonT00}, + doi = {10.1023/A:1004748624537}, + OPTurl = {http://dx.doi.org/10.1023/A:1004748624537}, +} + +@article{DBLP:journals/logcom/CarmoJ13, + author = {Jos{\'{e}} Carmo and Andrew J. I. Jones}, + journal = {Journal of Logic and Computation}, + number = {3}, + pages = {585--626}, + title = {Completeness and decidability results for a logic of + contrary-to-duty conditionals}, + volume = {23}, + year = {2013}, + biburl = {http://dblp.uni-trier.de/rec/bib/journals/logcom/CarmoJ13}, + doi = {10.1093/logcom/exs009}, + OPTurl = {http://dx.doi.org/10.1093/logcom/exs009}, +} + +@inproceedings{C69, + author = {Benzm{\"u}ller, Christoph and Parent, Xavier and + van der Torre, Leendert}, + booktitle = {14th Conference on Computability in Europe, CiE 2018, + Kiel, Germany, July 30-August, 2018, Proceedings}, + editor = {Manea, Florin and Miller, Russell G. and + Nowotka, Dirk}, + pages = {60-69}, + publisher = {Springer}, + series = {Lecture Notes in Computer Science}, + title = {A Deontic Logic Reasoning Infrastructure}, + volume = {10936}, + year = {2018}, + doi = {10.1007/978-3-319-94418-0_6}, + isbn = {978-3-319-67189-5}, + OPTurl = {http://christoph-benzmueller.de/papers/C69.pdf}, +} + +@techreport{R66, + author = {Benzm{\"u}ller, Christoph and Parent, Xavier}, + institution = {CoRR}, + title = {First Experiments with a Flexible Infrastructure for + Normative Reasoning}, + year = {2018}, + url = {http://arxiv.org/abs/1804.02929}, +} + +@techreport{R65, + author = {Benzm{\"u}ller, Christoph and Parent, Xavier}, + institution = {CoRR}, + + title = {{I/O} Logic in {HOL} --- First Steps}, + year = {2018}, + url = {http://arxiv.org/abs/1803.09681}, +} + +@techreport{R63, + author = {Benzm{\"u}ller, Christoph and Farjami, Ali and + Parent, Xavier}, + institution = {CoRR}, + title = {Faithful Semantical Embedding of a Dyadic Deontic + Logic in {HOL}}, + year = {2018}, + url = {https://arxiv.org/abs/1802.08454}, +} + +@inproceedings{C62, + address = {Maun, Botswana}, + author = {Tobias Glei{\ss}ner and Alexander Steen and + Christoph Benzm{\"u}ller}, + booktitle = {LPAR-21. 21st International Conference on Logic for + Programming, Artificial Intelligence and Reasoning}, + editor = {Thomas Eiter and David Sands}, + pages = {14-30}, + publisher = {EasyChair}, + series = {EPiC Series in Computing}, + title = {Theorem Provers for Every Normal Modal Logic}, + volume = {46}, + year = {2017}, + doi = {10.29007/jsb9}, + issn = {2398-7340}, + OPTurl = {https://easychair.org/publications/paper/340346}, +} + +@inproceedings{W56, + author = {Max Wisniewski and Alexander Steen and + Christoph Benzm\"uller}, + booktitle = {ARQNL 2016. Automated Reasoning in Quantified + Non-Classical Logics}, + editor = {Christoph Benzm{\"u}ller and Jens Otten}, + pages = {51-65}, + publisher = {CEUR Workshop Proceedings, http://ceur-ws.org}, + title = {{TPTP} and Beyond: Representation of Quantified + Non-Classical Logics}, + volume = {1770}, + year = {2016}, + OPTurl = {http://ceur-ws.org/Vol-1770/}, +} + +@inproceedings{C38, + address = {Stellenbosch, South Africa}, + author = {Christoph Benzm{\"u}ller and Thomas Raths}, + booktitle = {Proceedings of the 19th International Conference on + Logic for Programming, Artificial Intelligence and + Reasoning (LPAR)}, + editor = {Kenneth L. McMillan and Aart Middeldorp and + Andrei Voronkov}, + pages = {127-136}, + publisher = {Springer}, + series = {Lecture Notes in Computer Science}, + title = {{HOL} based First-order Modal Logic Provers}, + volume = {8312}, + year = {2013}, + doi = {10.1007/978-3-642-45221-5_9}, + isbn = {978-3-642-45220-8}, + OPTurl = {http://christoph-benzmueller.de/papers/C38.pdf}, +} + +@inproceedings{C34, + address = {Montpellier, France}, + author = {Christoph Benzm{\"u}ller and Jens Otten and + Thomas Raths}, + booktitle = {ECAI 2012}, + editor = {Luc De Raedt and Christian Bessiere and Didier Dubois and + Patrick Doherty and Paolo Frasconi and Fredrik Heintz and + Peter Lucas}, + pages = {163-168}, + publisher = {IOS Press}, + series = {Frontiers in Artificial Intelligence and + Applications}, + title = {Implementing and Evaluating Provers for First-order + Modal Logics}, + volume = {242}, + year = {2012}, + doi = {10.3233/978-1-61499-098-7-163}, + isbn = {978-1-61499-097-0}, + OPTurl = {http://christoph-benzmueller.de/papers/C34.pdf}, +} + +@inproceedings{C64, + address = {Maun, Botswana}, + author = {Christoph Benzm{\"u}ller and Alexander Steen and + Max Wisniewski}, + booktitle = {IWIL@LPAR 2017 Workshop and {LPAR-21} Short + Presentations, Maun, Botswana, May 7-12, 2017}, + editor = {Thomas Eiter and David Sands and Geoff Sutcliffe and + Andrei Voronkov}, + pages = {11-61}, + publisher = {EasyChair}, + series = {Kalpa Publications in Computing}, + title = {{Leo-III} Version 1.1 (System description)}, + volume = {1}, + year = {2017}, + OPTurl = {http://www.easychair.org/publications/paper/342979}, +} + +@inproceedings{W57, + address = {Maun, Botswana}, + author = {Alexander Steen and Max Wisniewski and + Christoph Benzm{\"u}ller}, + booktitle = {IWIL@LPAR 2017 Workshop and {LPAR-21} Short + Presentations, Maun, Botswana, May 7-12, 2017}, + editor = {Thomas Eiter and David Sands and Geoff Sutcliffe and + Andrei Voronkov}, + pages = {100-112}, + publisher = {EasyChair}, + series = {Kalpa Publications in Computing}, + title = {Going Polymorphic - {TH1} Reasoning for {Leo-III}}, + volume = {1}, + year = {2017}, + OPTurl = {http://www.easychair.org/publications/paper/346851}, +} + +@book{vanHeijenoort67, + address = {Cambridge, MA}, + author = {Jean van Heijenoort}, + edition = {3rd printing, 1997}, + publisher = {Harvard Univ. Press}, + series = {Source books in the history of the sciences series}, + title = {From {F}rege to {G}{\"o}del: {A} Source Book in + Mathematics, 1879-1931}, + year = {1967}, + isbn = {0-674-32450-1}, +} + +@article{J38, + Author = {David Fuenmayor and Christoph Benzm\"uller}, + Journal = {Journal of Applied Logic - IfCoLoG Journal of Logics and their Applications (special issue on Formal Approaches to the Ontological Argument)}, + Editors = {Silvestre, Ricardo and B\'{e}ziau, Jean-Yves}, + Keywords = {own, Automated Reasoning, Interactive Proof, Ontology + Reasoning, Higher Order Logic, Computational + Metaphysics}, + Title = {A Case Study On Computational Hermeneutics: {E.J. Lowe's Modal} Ontological Argument}, + Year = 2018, + Url = {http://christoph-benzmueller.de/papers/J38.pdf}, + Note = {Accepted for publication; to be published also as chapter in the book 'Beyond Faith and Rationality: Essays on Logic, Religion and Philosophy' printed in the Springer book series 'Sophia Studies in Cross-cultural Philosophy of Traditions and Cultures'}, +} + +@Article{MacLane48, + author = {Saunders MacLane}, + title = {Groups, Categories and Duality}, + journal = {Proceedings of the National Academy of Sciences}, + year = 1948, + volume = 34, + number = 6, + pages = {263-267}} + +@article{J42, + author = {David Fuenmayor and Christoph Benzmüller}, + title = {{Formalisation and Evaluation of Alan Gewirth's Proof for the Principle of Generic Consistency in Isabelle/HOL}}, + journal = {Archive of Formal Proofs}, + month = oct, + year = 2018, + note = {\url{http://isa-afp.org/entries/GewirthPGCProof.html}, + Formal proof development}, + ISSN = {2150-914x}, +} + +@Book{Isabelle, + author = {Tobias Nipkow and Lawrence C. Paulson and Markus Wenzel}, + title = {{Isabelle/HOL} --- A Proof Assistant for Higher-Order Logic}, + publisher = {Springer}, + series = {LNCS}, + volume = 2283, + year = 2002} + +@article{J50, + Author = {Kirchner, Daniel and Benzm{\"u}ller, Christoph and + Zalta, Edward N.}, + Keywords = {own, Higher Order Logic, Higher Order Modal Logic, + Universal Reasoning, Computational Metaphysics}, + Title = {Mechanizing Principia Logico-Metaphysica in + Functional Type Theory}, + Journal = {Review of Symbolic Logic}, + Volume = {13}, + Number = {1}, + Publisher = {Cambridge University Press}, + Doi = {10.1017/S1755020319000297}, + pages = {206-218}, + Addendum = {Preprint: \url{https://www.researchgate.net/publication/321160582}}, + Year = 2020, +} + +@article{Thesis, + author = {Daniel Kirchner}, + title = {{Representation and Partial Automation of the Principia Logico-Metaphysica in Isabelle/HOL}}, + journal = {Archive of Formal Proofs}, + month = sep, + year = 2017, + note = {\url{http://isa-afp.org/entries/PLM.html}, + Formal proof development}, + ISSN = {2150-914x}, +} +@Article{rtt, + author = {Oppenheimer, Paul E. and Zalta, Edward N.}, + title = {{Relations Versus Functions at the Foundations of Logic: Type-Theoretic Considerations}}, + journal = {Journal of Logic and Computation}, + year = 2011, + volume = 21, + number = 2, + pages = {351--374} +} +@article{Andrews89, + author = {Peter B. Andrews}, + title = {On Connections and Higher-Order Logic}, + journal = {Journal of Automated Reasoning}, + volume = {5}, + number = {3}, + pages = {257--291}, + year = {1989}, + url = {https://doi.org/10.1007/BF00248320}, + doi = {10.1007/BF00248320}, + timestamp = {Sat, 20 May 2017 00:22:32 +0200}, + biburl = {https://dblp.org/rec/bib/journals/jar/Andrews89}, + bibsource = {dblp computer science bibliography, https://dblp.org} +} + + + + +@book{BurrisSankappanavar1981, + author = {Burris, S. and Sankap\-panavar, H.P.}, + owner = 23, + publisher = {Springer}, + title = {A Course in Universal Algebra}, + url = {http://www.math.uwaterloo.ca/~snburris/htdocs/ualg.html}, + year = 1981 +} + +@article{Kanckos2017VariantsOG, + title={Variants of {G{\"o}del}’s Ontological Proof in a Natural Deduction Calculus}, + author={Annika Kanckos and Woltzenlogel Paleo, Bruno}, + journal={Studia Logica}, + year={2017}, + volume={105}, + pages={553-586} +} + + +@Article{Rushby, + author = {John Rushby}, + title = {A Mechanically Assisted Examination of Begging the Question in {Anselm's} Ontological Argument}, + journal = {J. Applied Logics}, + year = 2018, + volume = 5, + number = 7, + pages = {1473--1496}} + + +@Article{Blumson, + author = {Ben Blumson}, + title = {{Anselm's God in Isabelle/HOL}}, + journal = {Archive of Formal Proofs}, + year = 2017} + + +@article{KanckosLethen19, +title = "The Development of {G{\"o}del}'s ontological Proof", +keywords = "611 Philosophy", +author = "Annika Kanckos and Tim Lethen", +year = "2019", +month = "11", +day = "15", +doi = "10.1017/S1755020319000479", +language = "English", +OPTpages = "1 -- 19", +journal = "The Review of Symbolic Logic", +issn = "1755-0203", +publisher = "Cambridge University Press", +} + + +@InProceedings{C78, + Keywords = {own, Automated Reasoning, Free Logic, Higher Order + Logic, Category Theory, Algebraic Structures, Modeloids}, + Author = {Lucca Tiemens and Dana S. Scott and Christoph Benzm\"uller and Miroslav Benda}, + title = {Computer-supported Exploration of a Categorical Axiomatization of Modeloids}, + booktitle = {Relational and Algebraic Methods in Computer Science -- 18th International Conference, RAMiCS 2020}, + editors = {Uli Fahrenberg and Peter Jipsen and Michael Winter}, + year = 2020, + series = {LNCS}, + url = {https://www.springerprofessional.de/computer-supported-exploration-of-a-categorical-axiomatization-o/17853766}, + publisher = {Springer}, + volume = 12062, + pages = {302--317}, + doi = {10.1007/978-3-030-43520-2_19}, + addendum = {Preprint (with proofs): \url{https://www.researchgate.net/publication/336838722}}, +} + + +@article{J40, + author = {Christoph Benzm{\"u}ller and Scott, Dana S.}, + Keywords = {own, Automated Reasoning, Free Logic, Higher Order + Logic, Category Theory}, + title = {Automating Free Logic in {HOL}, with an Experimental + Application in Category Theory}, + volume = 64, + number = 1, + pages = {53--72}, + year = 2020, + url = {http://doi.org/10.13140/RG.2.2.11432.83202}, + journal = {Journal of Automated Reasoning}, + publisher = {Springer Netherlands}, + doi = {10.1007/s10817-018-09507-7}, + Addendum = {Preprint: + \url{http://doi.org/10.13140/RG.2.2.11432.83202}}, +} + + +@book{sobel2004logic, + author = {Sobel, Jordan H.}, + booktitle = {Logic and Theism: Arguments for and Against Beliefs + in {God}}, + OPTeditor = {Sobel, J.H.}, + publisher = {Cambridge University Press}, + title = {Logic and Theism: Arguments for and Against Beliefs + in God}, + year = {2004}, + isbn = {9781139449984}, +} \ No newline at end of file diff --git a/thys/SimplifiedOntologicalArgument/document/root.tex b/thys/SimplifiedOntologicalArgument/document/root.tex new file mode 100644 --- /dev/null +++ b/thys/SimplifiedOntologicalArgument/document/root.tex @@ -0,0 +1,51 @@ +\documentclass[11pt,a4paper]{article} +\usepackage{isabelle,isabellesym} +\usepackage{amsmath,amssymb} +\usepackage{latexsym} + +% this should be the last package used +\usepackage{pdfsetup} +\usepackage{stmaryrd} + +% urls in roman style, theory text in math-similar italics +\urlstyle{rm} +\isabellestyle{it} + + +\begin{document} + +\title{Exploring Simplified Variants of Gödel's Ontological Argument in Isabelle/HOL} +\author{Christoph Benzm\"uller} +\maketitle + +\begin{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. +\end{abstract} + +\tableofcontents + +% include generated text of all theories +\section{Background Reading} +The selected simplified variants of Gödel's ontological argument +\cite{GoedelNotes,ScottNotes} as presented in \S\ref{sec:selected} have first been +extracted from the insights gained in \S6 of \cite{C85}. These variants are also influenced by the work +presented in \cite{J52} and they significantly extend the findings +from \cite{J28}. In \S\ref{sec:all} we additionally include the +sources from \cite{C85}. + + +\input{session} + +\bibliographystyle{abbrv} +\bibliography{root} + +\end{document} diff --git a/thys/Van_Emde_Boas_Trees/Imperative_HOL_Time/Array_Time.thy b/thys/Van_Emde_Boas_Trees/Imperative_HOL_Time/Array_Time.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/Imperative_HOL_Time/Array_Time.thy @@ -0,0 +1,511 @@ +(* Title: Imperative_HOL_Time/Array_Time.thy + Author: Maximilian P. L. Haslbeck & Bohua Zhan, TU Muenchen +*) +section \Monadic arrays\ + +text \This theory is an adaptation of \HOL/Imperative_HOL/Array_Time.thy\, + adding time bookkeeping.\ + +theory Array_Time +imports Heap_Time_Monad +begin + +subsection \Primitives\ + +definition present :: "heap \ 'a::heap array \ bool" where + "present h a \ addr_of_array a < lim h" + +definition get :: "heap \ 'a::heap array \ 'a list" where + "get h a = map from_nat (arrays h (TYPEREP('a)) (addr_of_array a))" + +definition set :: "'a::heap array \ 'a list \ heap \ heap" where + "set a x = arrays_update (\h. h(TYPEREP('a) := ((h(TYPEREP('a))) (addr_of_array a:=map to_nat x))))" + +definition alloc :: "'a list \ heap \ 'a::heap array \ heap" where + "alloc xs h = (let + l = lim h; + r = Array l; + h'' = set r xs (h\lim := l + 1\) + in (r, h''))" + +definition length :: "heap \ 'a::heap array \ nat" where + "length h a = List.length (get h a)" + +definition update :: "'a::heap array \ nat \ 'a \ heap \ heap" where + "update a i x h = set a ((get h a)[i:=x]) h" + +definition noteq :: "'a::heap array \ 'b::heap array \ bool" (infix "=!!=" 70) where + "r =!!= s \ TYPEREP('a) \ TYPEREP('b) \ addr_of_array r \ addr_of_array s" + + +subsection \Monad operations\ + +definition new :: "nat \ 'a::heap \ 'a array Heap" where + [code del]: "new n x = Heap_Time_Monad.heap (%h. let (r,h') = alloc (replicate n x) h in (r,h',n+1))" + +definition of_list :: "'a::heap list \ 'a array Heap" where + [code del]: "of_list xs = Heap_Time_Monad.heap (%h. let (r,h') = alloc xs h in (r,h',1+List.length xs))" + +definition make :: "nat \ (nat \ 'a::heap) \ 'a array Heap" where + [code del]: "make n f = Heap_Time_Monad.heap (%h. let (r,h') = alloc (map f [0 ..< n]) h in (r,h',n+1))" + +definition len :: "'a::heap array \ nat Heap" where + [code del]: "len a = Heap_Time_Monad.tap (\h. length h a)" + +definition nth :: "'a::heap array \ nat \ 'a Heap" where + [code del]: "nth a i = Heap_Time_Monad.guard (\h. i < length h a) + (\h. (get h a ! i, h, 1))" + +definition upd :: "nat \ 'a \ 'a::heap array \ 'a::heap array Heap" where + [code del]: "upd i x a = Heap_Time_Monad.guard (\h. i < length h a) + (\h. (a, update a i x h, 1))" + +definition map_entry :: "nat \ ('a::heap \ 'a) \ 'a array \ 'a array Heap" where + [code del]: "map_entry i f a = Heap_Time_Monad.guard (\h. i < length h a) + (\h. (a, update a i (f (get h a ! i)) h, 2))" + +definition swap :: "nat \ 'a \ 'a::heap array \ 'a Heap" where + [code del]: "swap i x a = Heap_Time_Monad.guard (\h. i < length h a) + (\h. (get h a ! i, update a i x h, 2 ))" (* questionable *) + +definition freeze :: "'a::heap array \ 'a list Heap" where + [code del]: "freeze a = Heap_Time_Monad.heap (\h. (get h a, h, 1+length h a)) " + + +subsection \Properties\ + +text \FIXME: Does there exist a "canonical" array axiomatisation in +the literature?\ + +text \Primitives\ + +lemma noteq_sym: "a =!!= b \ b =!!= a" + and unequal [simp]: "a \ a' \ a =!!= a'" + unfolding noteq_def by auto + +lemma noteq_irrefl: "r =!!= r \ False" + unfolding noteq_def by auto + +lemma present_alloc_noteq: "present h a \ a =!!= fst (alloc xs h)" + by (simp add: present_def noteq_def alloc_def Let_def) + +lemma get_set_eq [simp]: "get (set r x h) r = x" + by (simp add: get_def set_def o_def) + +lemma get_set_neq [simp]: "r =!!= s \ get (set s x h) r = get h r" + by (simp add: noteq_def get_def set_def) + +lemma set_same [simp]: + "set r x (set r y h) = set r x h" + by (simp add: set_def) + +lemma set_set_swap: + "r =!!= r' \ set r x (set r' x' h) = set r' x' (set r x h)" + by (simp add: Let_def fun_eq_iff noteq_def set_def) + +lemma get_update_eq [simp]: + "get (update a i v h) a = (get h a) [i := v]" + by (simp add: update_def) + +lemma nth_update_neq [simp]: + "a =!!= b \ get (update b j v h) a ! i = get h a ! i" + by (simp add: update_def noteq_def) + +lemma get_update_elem_neqIndex [simp]: + "i \ j \ get (update a j v h) a ! i = get h a ! i" + by simp + +lemma length_update [simp]: + "length (update b i v h) = length h" + by (simp add: update_def length_def set_def get_def fun_eq_iff) + +lemma update_swap_neq: + "a =!!= a' \ + update a i v (update a' i' v' h) + = update a' i' v' (update a i v h)" +apply (unfold update_def) +apply simp +apply (subst set_set_swap, assumption) +apply (subst get_set_neq) +apply (erule noteq_sym) +apply simp +done + +lemma update_swap_neqIndex: + "\ i \ i' \ \ update a i v (update a i' v' h) = update a i' v' (update a i v h)" + by (auto simp add: update_def set_set_swap list_update_swap) + +lemma get_alloc: + "get (snd (alloc xs h)) (fst (alloc ys h)) = xs" + by (simp add: Let_def split_def alloc_def) + +lemma length_alloc: + "length (snd (alloc (xs :: 'a::heap list) h)) (fst (alloc (ys :: 'a list) h)) = List.length xs" + by (simp add: Array_Time.length_def get_alloc) + +lemma set: + "set (fst (alloc ls h)) + new_ls (snd (alloc ls h)) + = snd (alloc new_ls h)" + by (simp add: Let_def split_def alloc_def) + +lemma present_update [simp]: + "present (update b i v h) = present h" + by (simp add: update_def present_def set_def get_def fun_eq_iff) + +lemma present_alloc [simp]: + "present (snd (alloc xs h)) (fst (alloc xs h))" + by (simp add: present_def alloc_def set_def Let_def) + +lemma not_present_alloc [simp]: + "\ present h (fst (alloc xs h))" + by (simp add: present_def alloc_def Let_def) + + +text \Monad operations\ + +lemma execute_new [execute_simps]: + "execute (new n x) h = Some (let (r,h') = alloc (replicate n x) h in (r,h',n+1))" + by (simp add: new_def execute_simps) + +lemma success_newI [success_intros]: + "success (new n x) h" + by (auto intro: success_intros simp add: new_def) + +lemma effect_newI [effect_intros]: + assumes "(a, h') = alloc (replicate n x) h" + shows "effect (new n x) h h' a (n+1)" + apply (rule effectI) apply (simp add: assms execute_simps) by (metis assms case_prod_conv) + +lemma effect_newE [effect_elims]: + assumes "effect (new n x) h h' r n'" + obtains "r = fst (alloc (replicate n x) h)" "h' = snd (alloc (replicate n x) h)" + "get h' r = replicate n x" "present h' r" "\ present h r" "n+1=n'" + using assms apply (rule effectE) using case_prod_beta get_alloc execute_new + by (metis (mono_tags, lifting) fst_conv not_present_alloc option.sel present_alloc sndI) + + (* apply (si mp add: case_prod_beta get_alloc execute_simps) refactor proof *) + +lemma execute_of_list [execute_simps]: + "execute (of_list xs) h = Some (let (r,h') = alloc xs h in (r,h',1 + List.length xs))" + by (simp add: of_list_def execute_simps) + +lemma success_of_listI [success_intros]: + "success (of_list xs) h" + by (auto intro: success_intros simp add: of_list_def) + +lemma effect_of_listI [effect_intros]: + assumes "(a, h') = alloc xs h" + shows "effect (of_list xs) h h' a (1 + List.length xs)" + by (rule effectI, simp add: assms execute_simps, metis assms case_prod_conv) + + +lemma effect_of_listE [effect_elims]: + assumes "effect (of_list xs) h h' r n'" + obtains "r = fst (alloc xs h)" "h' = snd (alloc xs h)" + "get h' r = xs" "present h' r" "\ present h r" "n' = 1 + List.length xs" + using assms apply (rule effectE) apply (simp add: get_alloc execute_of_list) by (simp add: case_prod_unfold) + +lemma execute_make [execute_simps]: + "execute (make n f) h = Some (let (r,h') = alloc (map f [0 ..< n]) h in (r,h',n+1))" + by (simp add: make_def execute_simps) + +lemma success_makeI [success_intros]: + "success (make n f) h" + by (auto intro: success_intros simp add: make_def) + +lemma effect_makeI [effect_intros]: + assumes "(a, h') = alloc (map f [0 ..< n]) h" + shows "effect (make n f) h h' a (n+1)" + by (rule effectI) (simp add: assms execute_simps, metis assms case_prod_conv) + +lemma effect_makeE [effect_elims]: + assumes "effect (make n f) h h' r n'" + obtains "r = fst (alloc (map f [0 ..< n]) h)" "h' = snd (alloc (map f [0 ..< n]) h)" + "get h' r = map f [0 ..< n]" "present h' r" "\ present h r" "n+1=n'" + using assms apply (rule effectE) using get_alloc + by (metis (mono_tags, opaque_lifting) effectE effect_makeI not_present_alloc present_alloc prod.collapse) + + (* apply (si mp add: get_alloc execute_make) by (s imp add: case_prod_unfold) *) + +lemma execute_len [execute_simps]: + "execute (len a) h = Some (length h a, h, 1)" + by (simp add: len_def execute_simps) + +lemma success_lenI [success_intros]: + "success (len a) h" + by (auto intro: success_intros simp add: len_def) + +lemma effect_lengthI [effect_intros]: + assumes "h' = h" "r = length h a" "n=1" + shows "effect (len a) h h' r n" + by (rule effectI) (simp add: assms execute_simps) + +lemma effect_lengthE [effect_elims]: + assumes "effect (len a) h h' r n" + obtains "r = length h' a" "h' = h" "n=1" + using assms by (rule effectE) (simp add: execute_simps) + +lemma execute_nth [execute_simps]: + "i < length h a \ + execute (nth a i) h = Some (get h a ! i, h,1)" + "i \ length h a \ execute (nth a i) h = None" + by (simp_all add: nth_def execute_simps) + +lemma success_nthI [success_intros]: + "i < length h a \ success (nth a i) h" + by (auto intro: success_intros simp add: nth_def) + +lemma effect_nthI [effect_intros]: + assumes "i < length h a" "h' = h" "r = get h a ! i" "n=1" + shows "effect (nth a i) h h' r n" + by (rule effectI) (insert assms, simp add: execute_simps) + +lemma effect_nthE [effect_elims]: + assumes "effect (nth a i) h h' r n" + obtains "i < length h a" "r = get h a ! i" "h' = h" "n=1" + using assms by (rule effectE) (cases "i < length h a", auto simp: execute_simps elim: successE) + +lemma execute_upd [execute_simps]: + "i < length h a \ + execute (upd i x a) h = Some (a, update a i x h, 1)" + "i \ length h a \ execute (upd i x a) h = None" + by (simp_all add: upd_def execute_simps) + +lemma success_updI [success_intros]: + "i < length h a \ success (upd i x a) h" + by (auto intro: success_intros simp add: upd_def) + +lemma effect_updI [effect_intros]: + assumes "i < length h a" "h' = update a i v h" "n=1" + shows "effect (upd i v a) h h' a n" + by (rule effectI) (insert assms, simp add: execute_simps) + +lemma effect_updE [effect_elims]: + assumes "effect (upd i v a) h h' r n" + obtains "r = a" "h' = update a i v h" "i < length h a" "n=1" + using assms by (rule effectE) (cases "i < length h a", auto simp: execute_simps elim: successE) + +lemma execute_map_entry [execute_simps]: + "i < length h a \ + execute (map_entry i f a) h = + Some (a, update a i (f (get h a ! i)) h, 2)" + "i \ length h a \ execute (map_entry i f a) h = None" + by (simp_all add: map_entry_def execute_simps) + +lemma success_map_entryI [success_intros]: + "i < length h a \ success (map_entry i f a) h" + by (auto intro: success_intros simp add: map_entry_def) + +lemma effect_map_entryI [effect_intros]: + assumes "i < length h a" "h' = update a i (f (get h a ! i)) h" "r = a" "n=2" + shows "effect (map_entry i f a) h h' r n" + by (rule effectI) (insert assms, simp add: execute_simps) + +lemma effect_map_entryE [effect_elims]: + assumes "effect (map_entry i f a) h h' r n" + obtains "r = a" "h' = update a i (f (get h a ! i)) h" "i < length h a" "n=2" + using assms by (rule effectE) (cases "i < length h a", auto simp: execute_simps elim: successE) + +lemma execute_swap [execute_simps]: + "i < length h a \ + execute (swap i x a) h = + Some (get h a ! i, update a i x h, 2)" + "i \ length h a \ execute (swap i x a) h = None" + by (simp_all add: swap_def execute_simps) + +lemma success_swapI [success_intros]: + "i < length h a \ success (swap i x a) h" + by (auto intro: success_intros simp add: swap_def) + +lemma effect_swapI [effect_intros]: + assumes "i < length h a" "h' = update a i x h" "r = get h a ! i" "n=2" + shows "effect (swap i x a) h h' r n" + by (rule effectI) (insert assms, simp add: execute_simps) + +lemma effect_swapE [effect_elims]: + assumes "effect (swap i x a) h h' r n" + obtains "r = get h a ! i" "h' = update a i x h" "i < length h a" "n=2" + using assms by (rule effectE) (cases "i < length h a", auto simp: execute_simps elim: successE) + +lemma execute_freeze [execute_simps]: + "execute (freeze a) h = Some (get h a, h, 1+length h a)" + by (simp add: freeze_def execute_simps) + +lemma success_freezeI [success_intros]: + "success (freeze a) h" + by (auto intro: success_intros simp add: freeze_def) + +lemma effect_freezeI [effect_intros]: + assumes "h' = h" "r = get h a" "n=length h a" + shows "effect (freeze a) h h' r (n+1)" + by (rule effectI) (insert assms, simp add: execute_simps) + +lemma effect_freezeE [effect_elims]: + assumes "effect (freeze a) h h' r n" + obtains "h' = h" "r = get h a" "n=length h a+1" + using assms by (rule effectE) (simp add: execute_simps) + +lemma upd_ureturn: + "upd i x a \ ureturn a = upd i x a " + by (rule Heap_eqI) (simp add: bind_def guard_def upd_def execute_simps) + +lemma array_make: + "new n x = make n (\_. x)" + by (rule Heap_eqI) (simp add: map_replicate_trivial execute_simps) + +lemma array_of_list_make [code]: + "of_list xs = make (List.length xs) (\n. xs ! n)" + by (rule Heap_eqI) (simp add: map_nth execute_simps) + +hide_const (open) present get set alloc length update noteq new of_list make len nth upd map_entry swap freeze + + +subsection \Code generator setup\ + +subsubsection \Logical intermediate layer\ + +definition new' where + [code del]: "new' = Array_Time.new o nat_of_integer" + +lemma [code]: + "Array_Time.new = new' o of_nat" + by (simp add: new'_def o_def) + +definition make' where + [code del]: "make' i f = Array_Time.make (nat_of_integer i) (f o of_nat)" + +lemma [code]: + "Array_Time.make n f = make' (of_nat n) (f o nat_of_integer)" + by (simp add: make'_def o_def) + +definition len' where + [code del]: "len' a = Array_Time.len a \ (\n. ureturn (of_nat n))" + +lemma [code]: + "Array_Time.len a = len' a \ (\i. ureturn (nat_of_integer i))" + by (simp add: len'_def execute_simps) + +definition nth' where + [code del]: "nth' a = Array_Time.nth a o nat_of_integer" + +lemma [code]: + "Array_Time.nth a n = nth' a (of_nat n)" + by (simp add: nth'_def) + +definition upd' where + [code del]: "upd' a i x = Array_Time.upd (nat_of_integer i) x a \ ureturn ()" + +lemma [code]: + "Array_Time.upd i x a = upd' a (of_nat i) x \ ureturn a" + by (simp add: upd'_def upd_ureturn execute_simps) + +lemma [code]: + "Array_Time.map_entry i f a = do { + x \ Array_Time.nth a i; + Array_Time.upd i (f x) a + }" + by (rule Heap_eqI) (simp add: bind_def guard_def map_entry_def execute_simps) + +lemma [code]: + "Array_Time.swap i x a = do { + y \ Array_Time.nth a i; + Array_Time.upd i x a; + ureturn y + }" + by (rule Heap_eqI) (simp add: bind_def guard_def swap_def execute_simps) +(* +lemma [code]: + "Array_Time.freeze a = do { + n \ Array_Time.len a; + Heap_Monad.fold_map (\i. Array_Time.nth a i) [0..x. fst (the (if x < Array_Time.length h a + then Some (Array_Time.get h a ! x, h) else None))) + [0.. Array_Time.len a; + Heap_Monad.fold_map (Array_Time.nth a) [0.. Array_Time.len a; + Heap_Monad.fold_map (Array_Time.nth a) [0..SML\ + +code_printing type_constructor array \ (SML) "_/ array" +code_printing constant Array \ (SML) "raise/ (Fail/ \"bare Array\")" +code_printing constant Array_Time.new' \ (SML) "(fn/ ()/ =>/ Array.array/ ((_),/ (_)))" +code_printing constant Array_Time.of_list \ (SML) "(fn/ ()/ =>/ Array.fromList/ _)" +code_printing constant Array_Time.make' \ (SML) "(fn/ ()/ =>/ Array.tabulate/ ((_),/ (_)))" +code_printing constant Array_Time.len' \ (SML) "(fn/ ()/ =>/ Array.length/ _)" +code_printing constant Array_Time.nth' \ (SML) "(fn/ ()/ =>/ Array.sub/ ((_),/ (_)))" +code_printing constant Array_Time.upd' \ (SML) "(fn/ ()/ =>/ Array.update/ ((_),/ (_),/ (_)))" +code_printing constant "HOL.equal :: 'a array \ 'a array \ bool" \ (SML) infixl 6 "=" + +code_reserved SML Array + + +text \OCaml\ + +code_printing type_constructor array \ (OCaml) "_/ array" +code_printing constant Array \ (OCaml) "failwith/ \"bare Array\"" +code_printing constant Array_Time.new' \ (OCaml) "(fun/ ()/ ->/ Array.make/ (Big'_int.int'_of'_big'_int/ _)/ _)" +code_printing constant Array_Time.of_list \ (OCaml) "(fun/ ()/ ->/ Array.of'_list/ _)" +code_printing constant Array_Time.make' \ (OCaml) + "(fun/ ()/ ->/ Array.init/ (Big'_int.int'_of'_big'_int/ _)/ (fun k'_ ->/ _/ (Big'_int.big'_int'_of'_int/ k'_)))" +code_printing constant Array_Time.len' \ (OCaml) "(fun/ ()/ ->/ Big'_int.big'_int'_of'_int/ (Array.length/ _))" +code_printing constant Array_Time.nth' \ (OCaml) "(fun/ ()/ ->/ Array.get/ _/ (Big'_int.int'_of'_big'_int/ _))" +code_printing constant Array_Time.upd' \ (OCaml) "(fun/ ()/ ->/ Array.set/ _/ (Big'_int.int'_of'_big'_int/ _)/ _)" +code_printing constant "HOL.equal :: 'a array \ 'a array \ bool" \ (OCaml) infixl 4 "=" + +code_reserved OCaml Array + + +text \Haskell\ + +code_printing type_constructor array \ (Haskell) "Heap.STArray/ Heap.RealWorld/ _" +code_printing constant Array \ (Haskell) "error/ \"bare Array\"" +code_printing constant Array_Time.new' \ (Haskell) "Heap.newArray" +code_printing constant Array_Time.of_list \ (Haskell) "Heap.newListArray" +code_printing constant Array_Time.make' \ (Haskell) "Heap.newFunArray" +code_printing constant Array_Time.len' \ (Haskell) "Heap.lengthArray" +code_printing constant Array_Time.nth' \ (Haskell) "Heap.readArray" +code_printing constant Array_Time.upd' \ (Haskell) "Heap.writeArray" +code_printing constant "HOL.equal :: 'a array \ 'a array \ bool" \ (Haskell) infix 4 "==" +code_printing class_instance array :: HOL.equal \ (Haskell) - + + +text \Scala\ + +code_printing type_constructor array \ (Scala) "!collection.mutable.ArraySeq[_]" +code_printing constant Array \ (Scala) "!sys.error(\"bare Array\")" +code_printing constant Array_Time.new' \ (Scala) "('_: Unit)/ => / Array.alloc((_))((_))" +code_printing constant Array_Time.make' \ (Scala) "('_: Unit)/ =>/ Array.make((_))((_))" +code_printing constant Array_Time.len' \ (Scala) "('_: Unit)/ =>/ Array.len((_))" +code_printing constant Array_Time.nth' \ (Scala) "('_: Unit)/ =>/ Array.nth((_), (_))" +code_printing constant Array_Time.upd' \ (Scala) "('_: Unit)/ =>/ Array.upd((_), (_), (_))" +code_printing constant Array_Time.freeze \ (Scala) "('_: Unit)/ =>/ Array.freeze((_))" +code_printing constant "HOL.equal :: 'a array \ 'a array \ bool" \ (Scala) infixl 5 "==" + + + +end diff --git a/thys/Van_Emde_Boas_Trees/Imperative_HOL_Time/Heap.thy b/thys/Van_Emde_Boas_Trees/Imperative_HOL_Time/Heap.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/Imperative_HOL_Time/Heap.thy @@ -0,0 +1,90 @@ +(* Title: HOL/Imperative_HOL/Heap.thy + Author: John Matthews, Galois Connections; Alexander Krauss, TU Muenchen +*) + +section \A polymorphic heap based on cantor encodings\ + +theory Heap +imports Main "HOL-Library.Countable" +begin + +subsection \Representable types\ + +text \The type class of representable types\ + +class heap = typerep + countable + +instance unit :: heap .. + +instance bool :: heap .. + +instance nat :: heap .. + +instance prod :: (heap, heap) heap .. + +instance sum :: (heap, heap) heap .. + +instance list :: (heap) heap .. + +instance option :: (heap) heap .. + +instance int :: heap .. + +instance String.literal :: heap .. + +instance typerep :: heap .. + + +subsection \A polymorphic heap with dynamic arrays and references\ + +text \ + References and arrays are developed in parallel, + but keeping them separate makes some later proofs simpler. +\ + +type_synonym addr = nat \ \untyped heap references\ +type_synonym heap_rep = nat \ \representable values\ + +record heap = + arrays :: "typerep \ addr \ heap_rep list" + refs :: "typerep \ addr \ heap_rep" + lim :: addr + +definition empty :: heap where + "empty = \arrays = (\_ _. []), refs = (\_ _. 0), lim = 0\" + +datatype 'a array = Array addr \ \note the phantom type 'a\ +datatype 'a ref = Ref addr \ \note the phantom type 'a\ + +primrec addr_of_array :: "'a array \ addr" where + "addr_of_array (Array x) = x" + +primrec addr_of_ref :: "'a ref \ addr" where + "addr_of_ref (Ref x) = x" + +lemma addr_of_array_inj [simp]: + "addr_of_array a = addr_of_array a' \ a = a'" + by (cases a, cases a') simp_all + +lemma addr_of_ref_inj [simp]: + "addr_of_ref r = addr_of_ref r' \ r = r'" + by (cases r, cases r') simp_all + +instance array :: (type) countable + by (rule countable_classI [of addr_of_array]) simp + +instance ref :: (type) countable + by (rule countable_classI [of addr_of_ref]) simp + +text \Syntactic convenience\ + +setup \ + Sign.add_const_constraint (@{const_name Array}, SOME @{typ "nat \ 'a::heap array"}) + #> Sign.add_const_constraint (@{const_name Ref}, SOME @{typ "nat \ 'a::heap ref"}) + #> Sign.add_const_constraint (@{const_name addr_of_array}, SOME @{typ "'a::heap array \ nat"}) + #> Sign.add_const_constraint (@{const_name addr_of_ref}, SOME @{typ "'a::heap ref \ nat"}) +\ + +hide_const (open) empty + +end diff --git a/thys/Van_Emde_Boas_Trees/Imperative_HOL_Time/Heap_Time_Monad.thy b/thys/Van_Emde_Boas_Trees/Imperative_HOL_Time/Heap_Time_Monad.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/Imperative_HOL_Time/Heap_Time_Monad.thy @@ -0,0 +1,769 @@ +(* Title: Imperative_HOL_Time/Heap_Time_Monad.thy + Author: Maximilian P. L. Haslbeck & Bohua Zhan, TU Muenchen +*) + +section \A monad with a polymorphic heap and time and primitive reasoning infrastructure\ + +text \This theory is an adapted version of \Imperative_HOL/Heap_Time_Monad\, where the heap is + extended by time bookkeeping.\ + +theory Heap_Time_Monad + imports + "HOL-Imperative_HOL.Heap" + "HOL-Library.Monad_Syntax" +begin + +subsection \The monad\ + +subsubsection \Monad construction\ + +text \Monadic heap actions either produce values + and transform the heap, or fail\ +datatype 'a Heap = Heap "heap \ ('a \ heap \ nat) option" + +lemma [code, code del]: + "(Code_Evaluation.term_of :: 'a::typerep Heap \ Code_Evaluation.term) = Code_Evaluation.term_of" + .. + +primrec execute :: "'a Heap \ heap \ ('a \ heap \ nat) option" where + [code del]: "execute (Heap f) = f" + +lemma Heap_cases [case_names succeed fail]: + fixes f and h + assumes succeed: "\x h'. execute f h = Some (x, h') \ P" + assumes fail: "execute f h = None \ P" + shows P + using assms by (cases "execute f h") auto + +lemma Heap_execute [simp]: + "Heap (execute f) = f" by (cases f) simp_all + +lemma Heap_eqI: + "(\h. execute f h = execute g h) \ f = g" + by (cases f, cases g) (auto simp: fun_eq_iff) + +named_theorems execute_simps "simplification rules for execute" + +lemma execute_Let [execute_simps]: + "execute (let x = t in f x) = (let x = t in execute (f x))" + by (simp add: Let_def) + + +subsubsection \Specialised lifters\ + +definition tap :: "(heap \ 'a) \ 'a Heap" where + [code del]: "tap f = Heap (\h. Some (f h, h, 1))" + +lemma execute_tap [execute_simps]: + "execute (tap f) h = Some (f h, h, 1)" + by (simp add: tap_def) + +definition heap :: "(heap \ 'a \ heap \ nat) \ 'a Heap" where + [code del]: "heap f = Heap (Some \ f)" + +lemma execute_heap [execute_simps]: + "execute (heap f) = Some \ f" + by (simp add: heap_def) + +definition guard :: "(heap \ bool) \ (heap \ 'a \ heap \ nat) \ 'a Heap" where + [code del]: "guard P f = Heap (\h. if P h then Some (f h) else None)" + +lemma execute_guard [execute_simps]: + "\ P h \ execute (guard P f) h = None" + "P h \ execute (guard P f) h = Some (f h)" + by (simp_all add: guard_def) + + +subsubsection \Predicate classifying successful computations\ + +definition success :: "'a Heap \ heap \ bool" where + "success f h \ execute f h \ None" + +lemma successI: + "execute f h \ None \ success f h" + by (simp add: success_def) + +lemma successE: + assumes "success f h" + obtains r h' where "execute f h = Some (r, h')" + using assms by (auto simp: success_def) + +named_theorems success_intros "introduction rules for success" + +lemma success_tapI [success_intros]: + "success (tap f) h" + by (rule successI) (simp add: execute_simps) + +lemma success_heapI [success_intros]: + "success (heap f) h" + by (rule successI) (simp add: execute_simps) + +lemma success_guardI [success_intros]: + "P h \ success (guard P f) h" + by (rule successI) (simp add: execute_guard) + +lemma success_LetI [success_intros]: + "x = t \ success (f x) h \ success (let x = t in f x) h" + by (simp add: Let_def) + +lemma success_ifI: + "(c \ success t h) \ (\ c \ success e h) \ + success (if c then t else e) h" + by (simp add: success_def) + + +subsubsection \Predicate for a simple relational calculus\ + +text \ + The \effect\ vebt_predicate states that when a computation \c\ + runs with the heap \h\ will result in return value \r\ + and a heap \h'\, i.e.~no exception occurs. AND consume time \n\ +\ + +definition effect :: "'a Heap \ heap \ heap \ 'a \ nat \ bool" where + effect_def: "effect c h h' r n \ execute c h = Some (r, h', n)" + +lemma effectI: + "execute c h = Some (r, h',n) \ effect c h h' r n" + by (simp add: effect_def) + +lemma effectE: + assumes "effect c h h' r n" + obtains "r = fst (the (execute c h))" + and "h' = fst (snd (the (execute c h)))" + and "n = snd (snd (the (execute c h)))" + and "success c h" +proof (rule that) + from assms have *: "execute c h = Some (r, h',n)" by (simp add: effect_def) + then show "success c h" by (simp add: success_def) + from * have "fst (the (execute c h)) = r" and "fst (snd (the (execute c h))) = h'" + and "snd (snd (the (execute c h))) = n" + by simp_all + then show "r = fst (the (execute c h))" + and "h' = fst (snd (the (execute c h)))" + and "n = snd (snd (the (execute c h)))" by simp_all +qed + +lemma effect_success: + "effect c h h' r n \ success c h" + by (simp add: effect_def success_def) + +lemma success_effectE: + assumes "success c h" + obtains r h' n where "effect c h h' r n" + using assms by (auto simp add: effect_def success_def) + +lemma effect_deterministic: + assumes "effect f h h' a n" + and "effect f h h'' b n'" + shows "a = b" and "h' = h''" and "n = n'" + using assms unfolding effect_def by auto + +named_theorems effect_intros "introduction rules for effect" + and effect_elims "elimination rules for effect" + +lemma effect_LetI [effect_intros]: + assumes "x = t" "effect (f x) h h' r n" + shows "effect (let x = t in f x) h h' r n" + using assms by simp + +lemma effect_LetE [effect_elims]: + assumes "effect (let x = t in f x) h h' r n" + obtains "effect (f t) h h' r n" + using assms by simp + +lemma effect_ifI: + assumes "c \ effect t h h' r n" + and "\ c \ effect e h h' r n" + shows "effect (if c then t else e) h h' r n" + by (cases c) (simp_all add: assms) + +lemma effect_ifE: + assumes "effect (if c then t else e) h h' r n" + obtains "c" "effect t h h' r n" + | "\ c" "effect e h h' r n" + using assms by (cases c) simp_all + +lemma effect_tapI [effect_intros]: + assumes "h' = h" "r = f h" + shows "effect (tap f) h h' r 1" + by (rule effectI) (simp add: assms execute_simps) + +lemma effect_tapE [effect_elims]: + assumes "effect (tap f) h h' r n" + obtains "h' = h" and "r = f h" and "n=1" + using assms by (rule effectE) (auto simp add: execute_simps) + +lemma effect_heapI [effect_intros]: + assumes "n = snd (snd (f h))" "h' = fst (snd (f h))" "r = fst (f h)" + shows "effect (heap f) h h' r n" + by (rule effectI) (simp add: assms execute_simps) + +lemma effect_heapE [effect_elims]: + assumes "effect (heap f) h h' r n" + obtains "h' = fst (snd (f h))" and "n = snd (snd (f h))" and "r = fst (f h)" + using assms by (rule effectE) (simp add: execute_simps) + +lemma effect_guardI [effect_intros]: + assumes "P h" "h' = fst (snd (f h))" "n = snd (snd (f h))" "r = fst (f h)" + shows "effect (guard P f) h h' r n" + by (rule effectI) (simp add: assms execute_simps) + +lemma effect_guardE [effect_elims]: + assumes "effect (guard P f) h h' r n" + obtains "h' = fst (snd (f h))" "n = snd (snd (f h))" "r = fst (f h)" "P h" + using assms by (rule effectE) + (auto simp add: execute_simps elim!: successE, cases "P h", auto simp add: execute_simps) + + +subsubsection \Monad combinators\ + +definition return :: "'a \ 'a Heap" where + [code del]: "return x = heap (\h. (x,h,1))" + +lemma execute_return [execute_simps]: + "execute (return x) = Some \ (\h. (x,h,1))" + by (simp add: return_def execute_simps) + +lemma success_returnI [success_intros]: + "success (return x) h" + by (rule successI) (simp add: execute_simps) + +lemma effect_returnI [effect_intros]: + "h = h' \ effect (return x) h h' x 1" + by (rule effectI) (simp add: execute_simps) + +lemma effect_returnE [effect_elims]: + assumes "effect (return x) h h' r n" + obtains "r = x" "h' = h" "n=1" + using assms by (rule effectE) (simp add: execute_simps) + +definition ureturn :: "'a \ 'a Heap" where + [code del]: "ureturn x = heap (\h. (x,h,0))" + +lemma execute_ureturn [execute_simps]: + "execute (ureturn x) = Some \ (\h. (x,h,0))" + by (simp add: ureturn_def execute_simps) + +lemma success_ureturnI [success_intros]: + "success (ureturn x) h" + by (rule successI) (simp add: execute_simps) + +lemma effect_ureturnI [effect_intros]: + "h = h' \ effect (ureturn x) h h' x 0" + by (rule effectI) (simp add: execute_simps) + +lemma effect_ureturnE [effect_elims]: + assumes "effect (ureturn x) h h' r n" + obtains "r = x" "h' = h" "n=0" + using assms by (rule effectE) (simp add: execute_simps) + +definition raise :: "string \ 'a Heap" where \ \the string is just decoration\ + [code del]: "raise s = Heap (\_. None)" + +lemma execute_raise [execute_simps]: + "execute (raise s) = (\_. None)" + by (simp add: raise_def) + +lemma effect_raiseE [effect_elims]: + assumes "effect (raise x) h h' r n" + obtains "False" + using assms by (rule effectE) (simp add: success_def execute_simps) + + +fun timeFrame :: "nat \ ('a \ heap \ nat) option \ ('a \ heap \ nat) option" where + "timeFrame n (Some (r,h,n')) = Some (r, h, n+n')" +| "timeFrame n None = None" + +lemma timeFrame_zero[simp]: "timeFrame 0 h = h" apply(cases h) by auto + + +lemma timeFrame_assoc[simp]: "timeFrame n (timeFrame n' f) = timeFrame (n+n') f" + by (metis (no_types, lifting) ab_semigroup_add_class.add_ac(1) timeFrame.elims timeFrame.simps(1)) (* refactor proof *) + + + +definition bind :: "'a Heap \ ('a \ 'b Heap) \ 'b Heap" where + [code del]: "bind f g = Heap (\h. case execute f h of + Some (r, h', n) \ timeFrame n (execute (g r) h') + | None \ None)" + + + +adhoc_overloading + Monad_Syntax.bind Heap_Time_Monad.bind + +lemma execute_bind [execute_simps]: + "execute f h = Some (x, h',n) \ execute (f \ g) h = timeFrame n (execute (g x) h')" + "execute f h = None \ execute (f \ g) h = None" + by (simp_all add: bind_def) + +lemma execute_bind_case: + "execute (f \ g) h = (case (execute f h) of + Some (x, h',n) \ timeFrame n (execute (g x) h') | None \ None)" + by (simp add: bind_def) + +lemma execute_bind_success: + "success f h \ execute (f \ g) h + = timeFrame (snd (snd (the (execute f h)))) (execute (g (fst (the (execute f h)))) (fst (snd (the (execute f h)))))" + by (cases f h rule: Heap_cases) (auto elim: successE simp add: bind_def) + +lemma success_bind_executeI: + "execute f h = Some (x, h',n) \ success (g x) h' \ success (f \ g) h" + by (auto intro!: successI elim: successE simp add: bind_def) + +lemma success_bind_effectI [success_intros]: + "effect f h h' x n \ success (g x) h' \ success (f \ g) h" + by (auto simp add: effect_def success_def bind_def) + +lemma effect_bindI [effect_intros]: + assumes "effect f h h' r n" "effect (g r) h' h'' r' n'" + shows "effect (f \ g) h h'' r' (n+n')" + using assms + apply (auto intro!: effectI elim!: effectE successE) + apply (subst execute_bind, simp_all) + apply auto + done + +lemma effect_bindE [effect_elims]: + assumes "effect (f \ g) h h'' r' n" + obtains h' r n1 n2 where "effect f h h' r n1" "effect (g r) h' h'' r' n2" "n = n1 + n2" + using assms apply (auto simp add: effect_def bind_def split: option.split_asm) + (* To cleanup *) + by (smt Pair_inject option.distinct(1) option.inject timeFrame.elims) + +lemma execute_bind_eq_SomeI: + assumes "execute f h = Some (x, h',n)" + and "execute (g x) h' = Some (y, h'',n')" + shows "execute (f \ g) h = Some (y, h'',n+n')" + using assms by (simp add: bind_def) + +term "return x \ f" + +definition wait :: "nat \ unit Heap" where + [execute_simps]: "wait n = Heap (\h. Some ((),h,n))" + +lemma [simp]: "wait n \ (%_. wait m) = wait (n+m)" + unfolding wait_def bind_def by auto + + +term "wait 1 \ (%_. f x)" +term "return x \ f" + +lemma ureturn_bind [execute_simps]: "ureturn x \ f = f x" + apply (rule Heap_eqI) by (simp add: execute_simps) + +lemma return_bind [execute_simps]: "return x \ f = (wait 1) \ f x" + apply (rule Heap_eqI) by (simp add: execute_simps) + +lemma bind_return [execute_simps]: "f \ return = wait 1 \ f" + by (rule Heap_eqI) (simp add: bind_def execute_simps split: option.splits) + +lemma bind_ureturn [execute_simps]: "f \ ureturn = f" + by (rule Heap_eqI) (simp add: bind_def execute_simps split: option.splits) + +lemma bind_bind [simp]: "(f \ g) \ k = (f :: 'a Heap) \ (\x. g x \ k)" + by (rule Heap_eqI) (simp add: bind_def execute_simps split: option.splits) + +lemma raise_bind [simp]: "raise e \ f = raise e" + by (rule Heap_eqI) (simp add: execute_simps) + + +subsection \Generic combinators\ + +subsubsection \Assertions\ + +definition assert :: "('a \ bool) \ 'a \ 'a Heap" where + "assert P x = (if P x then return x else raise ''assert'')" + +lemma execute_assert [execute_simps]: + "P x \ execute (assert P x) h = Some (x, h, 1)" + "\ P x \ execute (assert P x) h = None" + by (simp_all add: assert_def execute_simps) + +lemma success_assertI [success_intros]: + "P x \ success (assert P x) h" + by (rule successI) (simp add: execute_assert) + +lemma effect_assertI [effect_intros]: + "P x \ h' = h \ r = x \ n = 1 \ effect (assert P x) h h' r n" + by (rule effectI) (simp add: execute_assert) + +lemma effect_assertE [effect_elims]: + assumes "effect (assert P x) h h' r n" + obtains "P x" "r = x" "h' = h" "n=1" + using assms by (rule effectE) (cases "P x", simp_all add: execute_assert success_def) + +lemma assert_cong [fundef_cong]: + assumes "P = P'" + assumes "\x. P' x \ f x = f' x" + shows "(assert P x \ f) = (assert P' x \ f')" + by (rule Heap_eqI) (insert assms, simp add: assert_def execute_simps) + + +subsubsection \Plain lifting\ + +definition lift :: "('a \ 'b) \ 'a \ 'b Heap" where + "lift f = return o f" + +lemma lift_collapse [simp]: + "lift f x = return (f x)" + by (simp add: lift_def) + +lemma bind_lift: + "(f \ lift g) = (f \ (\x. return (g x)))" + by (simp add: lift_def comp_def) + +(* +subsubsection \Iteration -- warning: this is rarely useful!\ + +primrec fold_map :: "('a \ 'b Heap) \ 'a list \ 'b list Heap" where + "fold_map f [] = return []" +| "fold_map f (x # xs) = do { + y \ f x; + ys \ fold_map f xs; + return (y # ys) + }" + +lemma fold_map_append: + "fold_map f (xs @ ys) = fold_map f xs \ (\xs. fold_map f ys \ (\ys. return (xs @ ys)))" + by (induct xs) simp_all + +lemma execute_fold_map_unchanged_heap [execute_simps]: + assumes "\x. x \ set xs \ \y. execute (f x) h = Some (y, h)" + shows "execute (fold_map f xs) h = + Some (List.map (\x. fst (the (execute (f x) h))) xs, h)" +using assms proof (induct xs) + case Nil show ?case by (simp add: execute_simps) +next + case (Cons x xs) + from Cons.prems obtain y + where y: "execute (f x) h = Some (y, h)" by auto + moreover from Cons.prems Cons.hyps have "execute (fold_map f xs) h = + Some (map (\x. fst (the (execute (f x) h))) xs, h)" by auto + ultimately show ?case by (simp, simp only: execute_bind(1), simp add: execute_simps) +qed +*) + +subsection \Partial function definition setup\ + +definition Heap_ord :: "'a Heap \ 'a Heap \ bool" where + "Heap_ord = img_ord execute (fun_ord option_ord)" + +definition Heap_lub :: "'a Heap set \ 'a Heap" where + "Heap_lub = img_lub execute Heap (fun_lub (flat_lub None))" + +lemma Heap_lub_empty: "Heap_lub {} = Heap Map.empty" +by(simp add: Heap_lub_def img_lub_def fun_lub_def flat_lub_def) + +lemma heap_interpretation: "partial_function_definitions Heap_ord Heap_lub" +proof - + have "partial_function_definitions (fun_ord option_ord) (fun_lub (flat_lub None))" + by (rule partial_function_lift) (rule flat_interpretation) + then have "partial_function_definitions (img_ord execute (fun_ord option_ord)) + (img_lub execute Heap (fun_lub (flat_lub None)))" + by (rule partial_function_image) (auto intro: Heap_eqI) + then show "partial_function_definitions Heap_ord Heap_lub" + by (simp only: Heap_ord_def Heap_lub_def) +qed + +interpretation heap: partial_function_definitions Heap_ord Heap_lub + rewrites "Heap_lub {} \ Heap Map.empty" +by (fact heap_interpretation)(simp add: Heap_lub_empty) + +lemma heap_step_admissible: + "option.admissible + (\f:: 'a => ('b * 'c* 'd) option. \h h' r n. f h = Some (r, h',n) \ P x h h' r n)" +proof (rule ccpo.admissibleI) + fix A :: "('a \ ('b * 'c * 'd) option) set" + assume ch: "Complete_Partial_Order.chain option.le_fun A" + and IH: "\f\A. \h h' r n. f h = Some (r, h', n) \ P x h h' r n" + from ch have ch': "\x. Complete_Partial_Order.chain option_ord {y. \f\A. y = f x}" by (rule chain_fun) + show "\h h' r n. option.lub_fun A h = Some (r, h', n) \ P x h h' r n" + proof (intro allI impI) + fix h h' r n assume "option.lub_fun A h = Some (r, h', n)" + from flat_lub_in_chain[OF ch' this[unfolded fun_lub_def]] + have "Some (r, h', n) \ {y. \f\A. y = f h}" by simp + then have "\f\A. f h = Some (r, h', n)" by auto + with IH show "P x h h' r n" by auto + qed +qed + +lemma admissible_heap: + "heap.admissible (\f. \x h h' r n. effect (f x) h h' r n \ P x h h' r n)" +proof (rule admissible_fun[OF heap_interpretation]) + fix x + show "ccpo.admissible Heap_lub Heap_ord (\a. \h h' r n. effect a h h' r n \ P x h h' r n)" + unfolding Heap_ord_def Heap_lub_def + proof (intro admissible_image partial_function_lift flat_interpretation) + show "option.admissible ((\a. \h h' r n. effect a h h' r n \ P x h h' r n) \ Heap)" + unfolding comp_def effect_def execute.simps + by (rule heap_step_admissible) + qed (auto simp add: Heap_eqI) +qed + +lemma fixp_induct_heap: + fixes F :: "'c \ 'c" and + U :: "'c \ 'b \ 'a Heap" and + C :: "('b \ 'a Heap) \ 'c" and + P :: "'b \ heap \ heap \ 'a \ nat \ bool" + assumes mono: "\x. monotone (fun_ord Heap_ord) Heap_ord (\f. U (F (C f)) x)" + assumes eq: "f \ C (ccpo.fixp (fun_lub Heap_lub) (fun_ord Heap_ord) (\f. U (F (C f))))" + assumes inverse2: "\f. U (C f) = f" + assumes step: "\f x h h' r n. (\x h h' r n. effect (U f x) h h' r n \ P x h h' r n) + \ effect (U (F f) x) h h' r n \ P x h h' r n" + assumes defined: "effect (U f x) h h' r n" + shows "P x h h' r n" + using step defined heap.fixp_induct_uc[of U F C, OF mono eq inverse2 admissible_heap, of P] + unfolding effect_def execute.simps + by blast + +declaration \Partial_Function.init "heap_time" @{term heap.fixp_fun} + @{term heap.mono_body} @{thm heap.fixp_rule_uc} @{thm heap.fixp_induct_uc} + (SOME @{thm fixp_induct_heap})\ + +abbreviation "mono_Heap \ monotone (fun_ord Heap_ord) Heap_ord" + +lemma Heap_ordI: + assumes "\h. execute x h = None \ execute x h = execute y h" + shows "Heap_ord x y" + using assms unfolding Heap_ord_def img_ord_def fun_ord_def flat_ord_def + by blast + +lemma Heap_ordE: + assumes "Heap_ord x y" + obtains "execute x h = None" | "execute x h = execute y h" + using assms unfolding Heap_ord_def img_ord_def fun_ord_def flat_ord_def + by atomize_elim blast + +lemma bind_mono [partial_function_mono]: + assumes mf: "mono_Heap B" and mg: "\y. mono_Heap (\f. C y f)" + shows "mono_Heap (\f. B f \ (\y. C y f))" +proof (rule monotoneI) + fix f g :: "'a \ 'b Heap" assume fg: "fun_ord Heap_ord f g" + from mf + have 1: "Heap_ord (B f) (B g)" by (rule monotoneD) (rule fg) + from mg + have 2: "\y'. Heap_ord (C y' f) (C y' g)" by (rule monotoneD) (rule fg) + + have "Heap_ord (B f \ (\y. C y f)) (B g \ (\y. C y f))" + (is "Heap_ord ?L ?R") + proof (rule Heap_ordI) + fix h + from 1 show "execute ?L h = None \ execute ?L h = execute ?R h" + by (rule Heap_ordE[where h = h]) (auto simp: execute_bind_case) + qed + also + have "Heap_ord (B g \ (\y'. C y' f)) (B g \ (\y'. C y' g))" + (is "Heap_ord ?L ?R") + proof (rule Heap_ordI) + fix h + show "execute ?L h = None \ execute ?L h = execute ?R h" + proof (cases "execute (B g) h") + case None + then have "execute ?L h = None" by (auto simp: execute_bind_case) + thus ?thesis .. + next + case Some + then obtain r h' n where "execute (B g) h = Some (r, h', n)" + by (metis surjective_pairing) + then have "execute ?L h = timeFrame n (execute (C r f) h')" + "execute ?R h = timeFrame n (execute (C r g) h')" + by (auto simp: execute_bind_case) + with 2[of r] show ?thesis apply (auto elim: Heap_ordE) + by (metis Heap_ordE timeFrame.simps(2)) + qed + qed + finally (heap.leq_trans) + show "Heap_ord (B f \ (\y. C y f)) (B g \ (\y'. C y' g))" . +qed + +subsection \Code generator setup\ + + + +subsubsection \SML and OCaml\ + +code_printing type_constructor Heap \ (SML) "(unit/ ->/ _)" +code_printing constant bind \ (SML) "!(fn/ f'_/ =>/ fn/ ()/ =>/ f'_/ (_/ ())/ ())" +code_printing constant return \ (SML) "!(fn/ ()/ =>/ _)" +code_printing constant Heap_Time_Monad.raise \ (SML) "!(raise/ Fail/ _)" + +code_printing type_constructor Heap \ (OCaml) "(unit/ ->/ _)" +code_printing constant bind \ (OCaml) "!(fun/ f'_/ ()/ ->/ f'_/ (_/ ())/ ())" +code_printing constant return \ (OCaml) "!(fun/ ()/ ->/ _)" +code_printing constant Heap_Time_Monad.raise \ (OCaml) "failwith" + + +subsubsection \Haskell\ + +text \Adaption layer\ + +code_printing code_module "Heap" \ (Haskell) +\import qualified Control.Monad; +import qualified Control.Monad.ST; +import qualified Data.STRef; +import qualified Data.Array.ST; + +type RealWorld = Control.Monad.ST.RealWorld; +type ST s a = Control.Monad.ST.ST s a; +type STRef s a = Data.STRef.STRef s a; +type STArray s a = Data.Array.ST.STArray s Integer a; + +newSTRef = Data.STRef.newSTRef; +readSTRef = Data.STRef.readSTRef; +writeSTRef = Data.STRef.writeSTRef; + +newArray :: Integer -> a -> ST s (STArray s a); +newArray k = Data.Array.ST.newArray (0, k - 1); + +newListArray :: [a] -> ST s (STArray s a); +newListArray xs = Data.Array.ST.newListArray (0, (fromInteger . toInteger . length) xs - 1) xs; + +newFunArray :: Integer -> (Integer -> a) -> ST s (STArray s a); +newFunArray k f = Data.Array.ST.newListArray (0, k - 1) (map f [0..k-1]); + +lengthArray :: STArray s a -> ST s Integer; +lengthArray a = Control.Monad.liftM (\(_, l) -> l + 1) (Data.Array.ST.getBounds a); + +readArray :: STArray s a -> Integer -> ST s a; +readArray = Data.Array.ST.readArray; + +writeArray :: STArray s a -> Integer -> a -> ST s (); +writeArray = Data.Array.ST.writeArray;\ + +code_reserved Haskell Heap + +text \Monad\ + +code_printing type_constructor Heap \ (Haskell) "Heap.ST/ Heap.RealWorld/ _" +code_monad bind Haskell +code_printing constant return \ (Haskell) "return" +code_printing constant Heap_Time_Monad.raise \ (Haskell) "error" + + +subsubsection \Scala\ + +code_printing code_module "Heap" \ (Scala) +\object Heap { + def bind[A, B](f: Unit => A, g: A => Unit => B): Unit => B = (_: Unit) => g (f ()) () +} + +class Ref[A](x: A) { + var value = x +} + +object Ref { + def apply[A](x: A): Ref[A] = + new Ref[A](x) + def lookup[A](r: Ref[A]): A = + r.value + def update[A](r: Ref[A], x: A): Unit = + { r.value = x } +} + +object Array { + import collection.mutable.ArraySeq + def alloc[A](n: BigInt)(x: A): ArraySeq[A] = + ArraySeq.fill(n.toInt)(x) + def make[A](n: BigInt)(f: BigInt => A): ArraySeq[A] = + ArraySeq.tabulate(n.toInt)((k: Int) => f(BigInt(k))) + def len[A](a: ArraySeq[A]): BigInt = + BigInt(a.length) + def nth[A](a: ArraySeq[A], n: BigInt): A = + a(n.toInt) + def upd[A](a: ArraySeq[A], n: BigInt, x: A): Unit = + a.update(n.toInt, x) + def freeze[A](a: ArraySeq[A]): List[A] = + a.toList +} +\ + +code_reserved Scala Heap Ref Array + +code_printing type_constructor Heap \ (Scala) "(Unit/ =>/ _)" +code_printing constant bind \ (Scala) "Heap.bind" +code_printing constant return \ (Scala) "('_: Unit)/ =>/ _" +code_printing constant Heap_Time_Monad.raise \ (Scala) "!sys.error((_))" + + +subsubsection \Target variants with less units\ + +setup \ + +let + +open Code_Thingol; + +val imp_program = + let + val is_bind = curry (op =) @{const_name bind}; + val is_return = curry (op =) @{const_name return}; + val dummy_name = ""; + val dummy_case_term = IVar NONE; + (*assumption: dummy values are not relevant for serialization*) + val unitT = @{type_name unit} `%% []; + val unitt = + IConst { sym = Code_Symbol.Constant @{const_name Unity}, typargs = [], dicts = [], dom = [], + annotation = NONE }; + fun dest_abs ((v, ty) `|=> t, _) = ((v, ty), t) + | dest_abs (t, ty) = + let + val vs = fold_varnames cons t []; + val v = singleton (Name.variant_list vs) "x"; + val ty' = (hd o fst o unfold_fun) ty; + in ((SOME v, ty'), t `$ IVar (SOME v)) end; + fun force (t as IConst { sym = Code_Symbol.Constant c, ... } `$ t') = if is_return c + then t' else t `$ unitt + | force t = t `$ unitt; + fun tr_bind'' [(t1, _), (t2, ty2)] = + let + val ((v, ty), t) = dest_abs (t2, ty2); + in ICase { term = force t1, typ = ty, clauses = [(IVar v, tr_bind' t)], primitive = dummy_case_term } end + and tr_bind' t = case unfold_app t + of (IConst { sym = Code_Symbol.Constant c, dom = ty1 :: ty2 :: _, ... }, [x1, x2]) => if is_bind c + then tr_bind'' [(x1, ty1), (x2, ty2)] + else force t + | _ => force t; + fun imp_monad_bind'' ts = (SOME dummy_name, unitT) `|=> + ICase { term = IVar (SOME dummy_name), typ = unitT, clauses = [(unitt, tr_bind'' ts)], primitive = dummy_case_term } + fun imp_monad_bind' (const as { sym = Code_Symbol.Constant c, dom = dom, ... }) ts = if is_bind c then case (ts, dom) + of ([t1, t2], ty1 :: ty2 :: _) => imp_monad_bind'' [(t1, ty1), (t2, ty2)] + | ([t1, t2, t3], ty1 :: ty2 :: _) => imp_monad_bind'' [(t1, ty1), (t2, ty2)] `$ t3 + | (ts, _) => imp_monad_bind (eta_expand 2 (const, ts)) + else IConst const `$$ map imp_monad_bind ts + and imp_monad_bind (IConst const) = imp_monad_bind' const [] + | imp_monad_bind (t as IVar _) = t + | imp_monad_bind (t as _ `$ _) = (case unfold_app t + of (IConst const, ts) => imp_monad_bind' const ts + | (t, ts) => imp_monad_bind t `$$ map imp_monad_bind ts) + | imp_monad_bind (v_ty `|=> t) = v_ty `|=> imp_monad_bind t + | imp_monad_bind (ICase { term = t, typ = ty, clauses = clauses, primitive = t0 }) = + ICase { term = imp_monad_bind t, typ = ty, + clauses = (map o apply2) imp_monad_bind clauses, primitive = imp_monad_bind t0 }; + + in (Code_Symbol.Graph.map o K o map_terms_stmt) imp_monad_bind end; + +in + +Code_Target.add_derived_target ("SML_imp", [("SML", imp_program)]) +#> Code_Target.add_derived_target ("OCaml_imp", [("OCaml", imp_program)]) +#> Code_Target.add_derived_target ("Scala_imp", [("Scala", imp_program)]) + +end + +\ + +hide_const (open) Heap heap guard (* fold_map TODO *) + +(*two additional lemmas, not by Haslbeck and Zhan, +lemmas just added for this project*) + +lemma fold_if_return: "(if b then return c else return d) = return (if b then c else d)" + by simp + +lemma distrib_if_bind: "do { x \ if b then (c::_ Heap) else d; f x } = (if b then do {x \ c; f x} else do { x\d; f x })" + by simp + +lemmas heap_monad_laws = bind_return return_bind bind_bind +end diff --git a/thys/Van_Emde_Boas_Trees/Imperative_HOL_Time/Imperative_HOL_Time.thy b/thys/Van_Emde_Boas_Trees/Imperative_HOL_Time/Imperative_HOL_Time.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/Imperative_HOL_Time/Imperative_HOL_Time.thy @@ -0,0 +1,11 @@ +(* Title: Imperative_HOL_Time/Imperative_HOL_Time.thy + Author: Maximilian P. L. Haslbeck & Bohua Zhan, TU Muenchen +*) + +section \Entry point into monadic imperative HOL with time\ + +theory Imperative_HOL_Time +imports Array_Time Ref_Time +begin + +end diff --git a/thys/Van_Emde_Boas_Trees/Imperative_HOL_Time/README b/thys/Van_Emde_Boas_Trees/Imperative_HOL_Time/README new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/Imperative_HOL_Time/README @@ -0,0 +1,5 @@ +This is a part of the Imperative HOL with Time development by Maximilian P. L. Haslbeck & Bohua Zhan, TU Muenchen + +See https://github.com/bzhan/Imperative_HOL_Time + +Included here with friendly permission by the authors. diff --git a/thys/Van_Emde_Boas_Trees/Imperative_HOL_Time/Ref_Time.thy b/thys/Van_Emde_Boas_Trees/Imperative_HOL_Time/Ref_Time.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/Imperative_HOL_Time/Ref_Time.thy @@ -0,0 +1,328 @@ +(* Title: Imperative_HOL_Time/Ref_Time.thy + Author: Maximilian P. L. Haslbeck & Bohua Zhan, TU Muenchen +*) + +section \Monadic references\ + +text \This theory is an adaptation of \HOL/Imperative_HOL/Array_Time.thy\, + adding time bookkeeping.\ + +theory Ref_Time +imports Array_Time +begin + +text \ + Imperative reference operations; modeled after their ML counterparts. + See \<^url>\http://caml.inria.fr/pub/docs/manual-caml-light/node14.15.html\ + and \<^url>\http://www.smlnj.org/doc/Conversion/top-level-comparison.html\. +\ + +subsection \Primitives\ + +definition present :: "heap \ 'a::heap ref \ bool" where + "present h r \ addr_of_ref r < lim h" + +definition get :: "heap \ 'a::heap ref \ 'a" where + "get h = from_nat \ refs h TYPEREP('a) \ addr_of_ref" + +definition set :: "'a::heap ref \ 'a \ heap \ heap" where + "set r x = refs_update + (\h. h(TYPEREP('a) := ((h (TYPEREP('a))) (addr_of_ref r := to_nat x))))" + +definition alloc :: "'a \ heap \ 'a::heap ref \ heap" where + "alloc x h = (let + l = lim h; + r = Ref l + in (r, set r x (h\lim := l + 1\)))" + +definition noteq :: "'a::heap ref \ 'b::heap ref \ bool" (infix "=!=" 70) where + "r =!= s \ TYPEREP('a) \ TYPEREP('b) \ addr_of_ref r \ addr_of_ref s" + + +subsection \Monad operations\ + +definition ref :: "'a::heap \ 'a ref Heap" where + [code del]: "ref v = Heap_Time_Monad.heap (%h. let (r,h') = alloc v h in (r,h',1))" + +definition lookup :: "'a::heap ref \ 'a Heap" ("!_" 61) where + [code del]: "lookup r = Heap_Time_Monad.tap (\h. get h r)" + +definition update :: "'a ref \ 'a::heap \ unit Heap" ("_ := _" 62) where + [code del]: "update r v = Heap_Time_Monad.heap (\h. ((), set r v h, 1))" + +definition change :: "('a::heap \ 'a) \ 'a ref \ 'a Heap" where + "change f r = do { + x \ ! r; + let y = f x; + r := y; + return y + }" + + +subsection \Properties\ + +text \Primitives\ + +lemma noteq_sym: "r =!= s \ s =!= r" + and unequal [simp]: "r \ r' \ r =!= r'" \ \same types!\ + by (auto simp add: noteq_def) + +lemma noteq_irrefl: "r =!= r \ False" + by (auto simp add: noteq_def) + +lemma present_alloc_neq: "present h r \ r =!= fst (alloc v h)" + by (simp add: present_def alloc_def noteq_def Let_def) + +lemma next_fresh [simp]: + assumes "(r, h') = alloc x h" + shows "\ present h r" + using assms by (cases h) (auto simp add: alloc_def present_def Let_def) + +lemma next_present [simp]: + assumes "(r, h') = alloc x h" + shows "present h' r" + using assms by (cases h) (auto simp add: alloc_def set_def present_def Let_def) + +lemma get_set_eq [simp]: + "get (set r x h) r = x" + by (simp add: get_def set_def) + +lemma get_set_neq [simp]: + "r =!= s \ get (set s x h) r = get h r" + by (simp add: noteq_def get_def set_def) + +lemma set_same [simp]: + "set r x (set r y h) = set r x h" + by (simp add: set_def) + +lemma not_present_alloc [simp]: + "\ present h (fst (alloc v h))" + by (simp add: present_def alloc_def Let_def) + +lemma set_set_swap: + "r =!= r' \ set r x (set r' x' h) = set r' x' (set r x h)" + by (simp add: noteq_def set_def fun_eq_iff) + +lemma alloc_set: + "fst (alloc x (set r x' h)) = fst (alloc x h)" + by (simp add: alloc_def set_def Let_def) + +lemma get_alloc [simp]: + "get (snd (alloc x h)) (fst (alloc x' h)) = x" + by (simp add: alloc_def Let_def) + +lemma set_alloc [simp]: + "set (fst (alloc v h)) v' (snd (alloc v h)) = snd (alloc v' h)" + by (simp add: alloc_def Let_def) + +lemma get_alloc_neq: "r =!= fst (alloc v h) \ + get (snd (alloc v h)) r = get h r" + by (simp add: get_def set_def alloc_def Let_def noteq_def) + +lemma lim_set [simp]: + "lim (set r v h) = lim h" + by (simp add: set_def) + +lemma present_alloc [simp]: + "present h r \ present (snd (alloc v h)) r" + by (simp add: present_def alloc_def Let_def) + +lemma present_set [simp]: + "present (set r v h) = present h" + by (simp add: present_def fun_eq_iff) + +lemma noteq_I: + "present h r \ \ present h r' \ r =!= r'" + by (auto simp add: noteq_def present_def) + + +text \Monad operations\ + +lemma execute_ref [execute_simps]: + "execute (ref v) h = Some (let (r,h') = alloc v h in (r,h',1))" + by (simp add: ref_def execute_simps) + +lemma success_refI [success_intros]: + "success (ref v) h" + by (auto intro: success_intros simp add: ref_def) + +lemma effect_refI [effect_intros]: + assumes "(r, h') = alloc v h" "n=1" + shows "effect (ref v) h h' r n" + apply (rule effectI) apply (insert assms, simp add: execute_simps) + by (metis case_prod_conv) + +lemma effect_refE [effect_elims]: + assumes "effect (ref v) h h' r n" + obtains "get h' r = v" and "present h' r" and "\ present h r" and "n=1" + using assms apply (rule effectE) apply (simp add: execute_simps) + by (metis (no_types, lifting) Ref_Time.alloc_def Ref_Time.get_set_eq fst_conv next_fresh next_present prod.case_eq_if snd_conv) + +lemma execute_lookup [execute_simps]: + "Heap_Time_Monad.execute (lookup r) h = Some (get h r, h, 1)" + by (simp add: lookup_def execute_simps) + +lemma success_lookupI [success_intros]: + "success (lookup r) h" + by (auto intro: success_intros simp add: lookup_def) + +lemma effect_lookupI [effect_intros]: + assumes "h' = h" "x = get h r" "n=1" + shows "effect (!r) h h' x n" + by (rule effectI) (insert assms, simp add: execute_simps) + +lemma effect_lookupE [effect_elims]: + assumes "effect (!r) h h' x n" + obtains "h' = h" "x = get h r" "n=1" + using assms by (rule effectE) (simp add: execute_simps) + +lemma execute_update [execute_simps]: + "Heap_Time_Monad.execute (update r v) h = Some ((), set r v h, 1)" + by (simp add: update_def execute_simps) + +lemma success_updateI [success_intros]: + "success (update r v) h" + by (auto intro: success_intros simp add: update_def) + +lemma effect_updateI [effect_intros]: + assumes "h' = set r v h" "n=1" + shows "effect (r := v) h h' x n" + by (rule effectI) (insert assms, simp add: execute_simps) + +lemma effect_updateE [effect_elims]: + assumes "effect (r' := v) h h' r n" + obtains "h' = set r' v h" "n=1" + using assms by (rule effectE) (simp add: execute_simps) + +lemma execute_change [execute_simps]: + "Heap_Time_Monad.execute (change f r) h = Some (f (get h r), set r (f (get h r)) h, 3)" + by (simp add: change_def bind_def Let_def execute_simps) + +lemma success_changeI [success_intros]: + "success (change f r) h" + by (auto intro!: success_intros effect_intros simp add: change_def) + +lemma effect_changeI [effect_intros]: + assumes "h' = set r (f (get h r)) h" "x = f (get h r)" "n=3" + shows "effect (change f r) h h' x n" + by (rule effectI) (insert assms, simp add: execute_simps) + +lemma effect_changeE [effect_elims]: + assumes "effect (change f r') h h' r n" + obtains "h' = set r' (f (get h r')) h" "r = f (get h r')" "n=3" + using assms by (rule effectE) (simp add: execute_simps) + +lemma lookup_chain: + "(!r \ f) = wait 1 \ f" + by (rule Heap_eqI) (auto simp add: lookup_def execute_simps intro: execute_bind) + +(* this one is wrong! +lemma update_change [code]: + "r := e = change (\_. e) r \ return ()" + by (rule Heap_eqI) (simp add: change_def lookup_chain) +*) + +text \Non-interaction between imperative arrays and imperative references\ + +lemma array_get_set [simp]: + "Array_Time.get (set r v h) = Array_Time.get h" + by (simp add: Array_Time.get_def set_def fun_eq_iff) + +lemma get_update [simp]: + "get (Array_Time.update a i v h) r = get h r" + by (simp add: get_def Array_Time.update_def Array_Time.set_def) + +lemma alloc_update: + "fst (alloc v (Array_Time.update a i v' h)) = fst (alloc v h)" + by (simp add: Array_Time.update_def Array_Time.get_def Array_Time.set_def alloc_def Let_def) + +lemma update_set_swap: + "Array_Time.update a i v (set r v' h) = set r v' (Array_Time.update a i v h)" + by (simp add: Array_Time.update_def Array_Time.get_def Array_Time.set_def set_def) + +lemma length_alloc [simp]: + "Array_Time.length (snd (alloc v h)) a = Array_Time.length h a" + by (simp add: Array_Time.length_def Array_Time.get_def alloc_def set_def Let_def) + +lemma array_get_alloc [simp]: + "Array_Time.get (snd (alloc v h)) = Array_Time.get h" + by (simp add: Array_Time.get_def alloc_def set_def Let_def fun_eq_iff) + +lemma present_update [simp]: + "present (Array_Time.update a i v h) = present h" + by (simp add: Array_Time.update_def Array_Time.set_def fun_eq_iff present_def) + +lemma array_present_set [simp]: + "Array_Time.present (set r v h) = Array_Time.present h" + by (simp add: Array_Time.present_def set_def fun_eq_iff) + +lemma array_present_alloc [simp]: + "Array_Time.present h a \ Array_Time.present (snd (alloc v h)) a" + by (simp add: Array_Time.present_def alloc_def Let_def) + +lemma set_array_set_swap: + "Array_Time.set a xs (set r x' h) = set r x' (Array_Time.set a xs h)" + by (simp add: Array_Time.set_def set_def) + +hide_const (open) present get set alloc noteq lookup update change + + +subsection \Code generator setup\ + +text \Intermediate operation avoids invariance problem in \Scala\ (similar to value restriction)\ + +definition ref' where + [code del]: "ref' = ref" + +lemma [code]: + "ref x = ref' x" + by (simp add: ref'_def) + + +text \SML / Eval\ + +code_printing type_constructor ref \ (SML) "_/ ref" +code_printing type_constructor ref \ (Eval) "_/ Unsynchronized.ref" +code_printing constant Ref \ (SML) "raise/ (Fail/ \"bare Ref\")" +code_printing constant ref' \ (SML) "(fn/ ()/ =>/ ref/ _)" +code_printing constant ref' \ (Eval) "(fn/ ()/ =>/ Unsynchronized.ref/ _)" +code_printing constant Ref_Time.lookup \ (SML) "(fn/ ()/ =>/ !/ _)" +code_printing constant Ref_Time.update \ (SML) "(fn/ ()/ =>/ _/ :=/ _)" +code_printing constant "HOL.equal :: 'a ref \ 'a ref \ bool" \ (SML) infixl 6 "=" + +code_reserved Eval Unsynchronized + + +text \OCaml\ + +code_printing type_constructor ref \ (OCaml) "_/ ref" +code_printing constant Ref \ (OCaml) "failwith/ \"bare Ref\"" +code_printing constant ref' \ (OCaml) "(fun/ ()/ ->/ ref/ _)" +code_printing constant Ref_Time.lookup \ (OCaml) "(fun/ ()/ ->/ !/ _)" +code_printing constant Ref_Time.update \ (OCaml) "(fun/ ()/ ->/ _/ :=/ _)" +code_printing constant "HOL.equal :: 'a ref \ 'a ref \ bool" \ (OCaml) infixl 4 "=" + +code_reserved OCaml ref + + +text \Haskell\ + +code_printing type_constructor ref \ (Haskell) "Heap.STRef/ Heap.RealWorld/ _" +code_printing constant Ref \ (Haskell) "error/ \"bare Ref\"" +code_printing constant ref' \ (Haskell) "Heap.newSTRef" +code_printing constant Ref_Time.lookup \ (Haskell) "Heap.readSTRef" +code_printing constant Ref_Time.update \ (Haskell) "Heap.writeSTRef" +code_printing constant "HOL.equal :: 'a ref \ 'a ref \ bool" \ (Haskell) infix 4 "==" +code_printing class_instance ref :: HOL.equal \ (Haskell) - + + +text \Scala\ + +code_printing type_constructor ref \ (Scala) "!Ref[_]" +code_printing constant Ref \ (Scala) "!sys.error(\"bare Ref\")" +code_printing constant ref' \ (Scala) "('_: Unit)/ =>/ Ref((_))" +code_printing constant Ref_Time.lookup \ (Scala) "('_: Unit)/ =>/ Ref.lookup((_))" +code_printing constant Ref_Time.update \ (Scala) "('_: Unit)/ =>/ Ref.update((_), (_))" +code_printing constant "HOL.equal :: 'a ref \ 'a ref \ bool" \ (Scala) infixl 5 "==" + +end diff --git a/thys/Van_Emde_Boas_Trees/ROOT b/thys/Van_Emde_Boas_Trees/ROOT new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/ROOT @@ -0,0 +1,42 @@ +chapter AFP + +session Van_Emde_Boas_Trees (AFP) = HOL + + (*descpription "Functional and imperative van Emde Boas Trees"*) + options [timeout = 900] + sessions + "HOL-Imperative_HOL" + "Automatic_Refinement" + Deriving +directories + Imperative_HOL_Time + Separation_Logic_Imperative_HOL + "Separation_Logic_Imperative_HOL/Tools" + Time_Reasoning + (*suppression of some theories*) + + theories [document = false] + "Imperative_HOL_Time/Array_Time" + "Imperative_HOL_Time/Heap" + "Imperative_HOL_Time/Heap_Time_Monad" + "Imperative_HOL_Time/Imperative_HOL_Time" + "Imperative_HOL_Time/Ref_Time" + "Separation_Logic_Imperative_HOL/Assertions" + "Separation_Logic_Imperative_HOL/Automation" + "Separation_Logic_Imperative_HOL/Hoare_Triple" + "Separation_Logic_Imperative_HOL/Refine_Imp_Hol" + "Separation_Logic_Imperative_HOL/Sep_Main" + "Separation_Logic_Imperative_HOL/Tools/Imperative_HOL_Add" + "Separation_Logic_Imperative_HOL/Tools/Syntax_Match" + + theories [document = false] + VEBT_Example_Setup + "Time_Reasoning/Simple_TBOUND_Cond" + + theories + VEBT_Intf_Imperative + VEBT_Example + + document_files + "root.bib" + "root.tex" + diff --git a/thys/Van_Emde_Boas_Trees/Separation_Logic_Imperative_HOL/Assertions.thy b/thys/Van_Emde_Boas_Trees/Separation_Logic_Imperative_HOL/Assertions.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/Separation_Logic_Imperative_HOL/Assertions.thy @@ -0,0 +1,988 @@ +section "Assertions" + +theory Assertions +imports + "../Imperative_HOL_Time/Imperative_HOL_Time" + (*"Tools/Imperative_HOL_Add" *) + "Tools/Syntax_Match" + Automatic_Refinement.Misc +begin + +subsection \Partial Heaps\ +text \ + A partial heap is modeled by a heap and a set of valid addresses, with the + side condition that the valid addresses have to be within the limit of the + heap. This modeling is somewhat strange for separation logic, however, it + allows us to solve some technical problems related to definition of + Hoare triples, that will be detailed later. +\ +type_synonym pheap = "heap \ addr set" + +text \Predicate that expresses that the address set of a partial heap is + within the heap's limit. +\ +fun in_range :: "(heap \ addr set) \ bool" + where "in_range (h,as) \ (\a\as. a < lim h)" + +declare in_range.simps[simp del] + +lemma in_range_empty[simp, intro!]: "in_range (h,{})" + by (auto simp: in_range.simps) + +lemma in_range_dist_union[simp]: + "in_range (h,as \ as') \ in_range (h,as) \ in_range (h,as')" + by (auto simp: in_range.simps) + +lemma in_range_subset: + "\as \ as'; in_range (h,as')\ \ in_range (h,as)" + by (auto simp: in_range.simps) + +text \Relation that holds if two heaps are identical on a given + address range\ +definition relH :: "addr set \ heap \ heap \ bool" + where "relH as h h' \ + in_range (h,as) + \ in_range (h',as) + \ (\t. \a \ as. + refs h t a = refs h' t a + \ arrays h t a = arrays h' t a + )" + +lemma relH_in_rangeI: + assumes "relH as h h'" + shows "in_range (h,as)" and "in_range (h',as)" + using assms unfolding relH_def by auto + +text "Reflexivity" +lemma relH_refl: "in_range (h,as) \ relH as h h" + unfolding relH_def by simp + +text "Symmetry" +lemma relH_sym: "relH as h h' \ relH as h' h" + unfolding relH_def + by auto + +text "Transitivity" +lemma relH_trans[trans]: "\relH as h1 h2; relH as h2 h3\ \ relH as h1 h3" + unfolding relH_def + by auto + +lemma relH_dist_union[simp]: + "relH (as\as') h h' \ relH as h h' \ relH as' h h'" + unfolding relH_def + by auto + +lemma relH_subset: + assumes "relH bs h h'" + assumes "as \ bs" + shows "relH as h h'" + using assms unfolding relH_def by (auto intro: in_range_subset) + +lemma relH_ref: + assumes "relH as h h'" + assumes "addr_of_ref r \ as" + shows "Ref_Time.get h r = Ref_Time.get h' r" + using assms unfolding relH_def Ref_Time.get_def by auto + +lemma relH_array: + assumes "relH as h h'" + assumes "addr_of_array r \ as" + shows "Array_Time.get h r = Array_Time.get h' r" + using assms unfolding relH_def Array_Time.get_def by auto + +lemma relH_set_ref: "\ addr_of_ref r \ as; in_range (h,as)\ + \ relH as h (Ref_Time.set r x h)" + unfolding relH_def Ref_Time.set_def + by (auto simp: in_range.simps) + +lemma relH_set_array: "\addr_of_array r \ as; in_range (h,as)\ + \ relH as h (Array_Time.set r x h)" + unfolding relH_def Array_Time.set_def + by (auto simp: in_range.simps) + +subsection \Assertions\ +text \ + Assertions are predicates on partial heaps, that fulfill a well-formedness + condition called properness: They only depend on the part of the heap + by the address set, and must be false for partial heaps that are not in range. +\ +type_synonym assn_raw = "pheap \ bool" + +definition proper :: "assn_raw \ bool" where + "proper P \ \h h' as. (P (h,as) \ in_range (h,as)) + \ (P (h,as) \ relH as h h' \ in_range (h',as) \ P (h',as))" + +lemma properI[intro?]: + assumes "\as h. P (h,as) \ in_range (h,as)" + assumes "\as h h'. + \P (h,as); relH as h h'; in_range (h',as)\ \ P (h',as)" + shows "proper P" + unfolding proper_def using assms by blast + +lemma properD1: + assumes "proper P" + assumes "P (h,as)" + shows "in_range (h,as)" + using assms unfolding proper_def by blast + +lemma properD2: + assumes "proper P" + assumes "P (h,as)" + assumes "relH as h h'" + assumes "in_range (h',as)" + shows "P (h',as)" + using assms unfolding proper_def by blast + +lemmas properD = properD1 properD2 + +lemma proper_iff: + assumes "proper P" + assumes "relH as h h'" + assumes "in_range (h',as)" + shows "P (h,as) \ P (h',as)" + using assms + by (metis properD2 relH_in_rangeI(1) relH_sym) + +text \We encapsulate assertions in their own type\ +typedef assn = "Collect proper" + apply simp + unfolding proper_def + by fastforce + +lemmas [simp] = Rep_assn_inverse Rep_assn_inject +lemmas [simp, intro!] = Rep_assn[unfolded mem_Collect_eq] + +lemma Abs_assn_eqI[intro?]: + "(\h. P h = Rep_assn Pr h) \ Abs_assn P = Pr" + "(\h. P h = Rep_assn Pr h) \ Pr = Abs_assn P" + by (metis Rep_assn_inverse predicate1I xt1(5))+ + +abbreviation models :: "pheap \ assn \ bool" (infix "\" 50) + where "h\P \ Rep_assn P h" + + +lemma models_in_range: "h\P \ in_range h" + apply (cases h) + by (metis mem_Collect_eq Rep_assn properD1) + +subsubsection \Empty Partial Heap\ +text \The empty partial heap satisfies some special properties. + We set up a simplification that tries to rewrite it to the standard + empty partial heap \h\<^sub>\\\ +abbreviation h_bot ("h\<^sub>\") where "h\<^sub>\ \ (undefined,{})" +lemma mod_h_bot_indep: "(h,{})\P \ (h',{})\P" + by (metis mem_Collect_eq Rep_assn emptyE in_range_empty + proper_iff relH_def) + +lemma mod_h_bot_normalize[simp]: + "syntax_fo_nomatch undefined h \ (h,{})\P \ h\<^sub>\ \ P" + using mod_h_bot_indep[where h'=undefined] by simp + +text \Properness, lifted to the assertion type.\ +lemma mod_relH: "relH as h h' \ (h,as)\P \ (h',as)\P" + by (metis mem_Collect_eq Rep_assn proper_iff relH_in_rangeI(2)) + +subsection \Connectives\ +text \ + We define several operations on assertions, and instantiate some type classes. +\ + +subsubsection \Empty Heap and Separation Conjunction\ +text \The assertion that describes the empty heap, and the separation + conjunction form a commutative monoid:\ +instantiation assn :: one begin + fun one_assn_raw :: "pheap \ bool" + where "one_assn_raw (h,as) \ as={}" + + lemma one_assn_proper[intro!,simp]: "proper one_assn_raw" + by (auto intro!: properI) + + definition one_assn :: assn where "1 \ Abs_assn one_assn_raw" + instance .. +end + +abbreviation one_assn::assn ("emp") where "one_assn \ 1" + +instantiation assn :: times begin + fun times_assn_raw :: "assn_raw \ assn_raw \ assn_raw" where + "times_assn_raw P Q (h,as) + = (\as1 as2. as=as1\as2 \ as1\as2={} + \ P (h,as1) \ Q (h,as2))" + + lemma times_assn_proper[intro!,simp]: + "proper P \ proper Q \ proper (times_assn_raw P Q)" + apply (rule properI) + apply (auto dest: properD1) [] + apply clarsimp + apply (drule (3) properD2) + apply (drule (3) properD2) + apply blast + done + + definition times_assn where "P*Q \ + Abs_assn (times_assn_raw (Rep_assn P) (Rep_assn Q))" + + instance .. +end + +lemma mod_star_conv: "h\A*B + \ (\hr as1 as2. h=(hr,as1\as2) \ as1\as2={} \ (hr,as1)\A \ (hr,as2)\B)" + unfolding times_assn_def + apply (cases h) + by (auto simp: Abs_assn_inverse) + +lemma mod_starD: "h\A*B \ \h1 h2. h1\A \ h2\B" + by (auto simp: mod_star_conv) + +lemma mod_starE: + assumes "h \ a*b" + obtains h\<^sub>1 h\<^sub>2 where "h\<^sub>1 \ a" "h\<^sub>2 \ b" + using assms by (auto dest: mod_starD) + +lemma star_assnI: + assumes "(h,as)\P" and "(h,as')\Q" and "as\as'={}" + shows "(h,as\as')\P*Q" + using assms unfolding times_assn_def + by (auto simp: Abs_assn_inverse) + +instantiation assn :: comm_monoid_mult begin + lemma assn_one_left: "1*P = (P::assn)" + unfolding one_assn_def times_assn_def + apply (rule) + apply (auto simp: Abs_assn_inverse) + done + + lemma assn_times_comm: "P*Q = Q*(P::assn)" + unfolding times_assn_def + apply rule + apply (fastforce simp add: Abs_assn_inverse Un_ac) + done + + lemma assn_times_assoc: "(P*Q)*R = P*(Q*(R::assn))" + unfolding times_assn_def + apply rule + apply (auto simp: Abs_assn_inverse) + apply (rule_tac x="as1\as1a" in exI) + apply (rule_tac x="as2a" in exI) + apply (auto simp add: Un_ac) [] + + apply (rule_tac x="as1a" in exI) + apply (rule_tac x="as2a\as2" in exI) + apply (fastforce simp add: Un_ac) [] + done + + instance + apply standard + apply (rule assn_times_assoc) + apply (rule assn_times_comm) + apply (rule assn_one_left) + done + +end + +subsubsection \Magic Wand\ +fun wand_raw :: "assn_raw \ assn_raw \ assn_raw" where + "wand_raw P Q (h,as) \ in_range (h,as) + \ (\h' as'. as\as'={} \ relH as h h' \ in_range (h',as) + \ P (h',as') + \ Q (h',as\as'))" + +lemma wand_proper[simp, intro!]: "proper (wand_raw P Q)" + apply (rule properI) + apply simp + apply (auto dest: relH_trans) + done + +definition + wand_assn :: "assn \ assn \ assn" (infixl "-*" 56) + where "P-*Q \ Abs_assn (wand_raw (Rep_assn P) (Rep_assn Q))" + +lemma wand_assnI: + assumes "in_range (h,as)" + assumes "\h' as'. \ + as \ as' = {}; + relH as h h'; + in_range (h',as); + (h',as')\Q + \ \ (h',as\as') \ R" + shows "(h,as) \ Q -* R" + using assms + unfolding wand_assn_def + apply (auto simp: Abs_assn_inverse) + done + +subsubsection \Boolean Algebra on Assertions\ +instantiation assn :: boolean_algebra begin + definition top_assn where "top \ Abs_assn in_range" + definition bot_assn where "bot \ Abs_assn (\_. False)" + definition sup_assn where "sup P Q \ Abs_assn (\h. h\P \ h\Q)" + definition inf_assn where "inf P Q \ Abs_assn (\h. h\P \ h\Q)" + definition uminus_assn where + "-P \ Abs_assn (\h. in_range h \ \h\P)" + + lemma bool_assn_proper[simp, intro!]: + "proper in_range" + "proper (\_. False)" + "proper P \ proper Q \ proper (\h. P h \ Q h)" + "proper P \ proper Q \ proper (\h. P h \ Q h)" + "proper P \ proper (\h. in_range h \ \P h)" + apply (auto + intro!: properI + intro: relH_in_rangeI + dest: properD1 + simp: proper_iff) + done + + text \(And, Or, True, False, Not) are a Boolean algebra. + Due to idiosyncrasies of the Isabelle/HOL class setup, we have to + also define a difference and an ordering:\ + definition less_eq_assn where + [simp]: "(a::assn) \ b \ a = inf a b" + + definition less_assn where + [simp]: "(a::assn) < b \ a \ b \ a\b" + + definition minus_assn where + [simp]: "(a::assn) - b \ inf a (-b)" + + instance + apply standard + unfolding + top_assn_def bot_assn_def sup_assn_def inf_assn_def uminus_assn_def + less_eq_assn_def less_assn_def minus_assn_def + apply (auto + simp: Abs_assn_inverse conj_commute conj_ac + intro: Abs_assn_eqI models_in_range) + apply rule + apply (metis (mono_tags) Abs_assn_inverse[unfolded mem_Collect_eq] + Rep_assn[unfolded mem_Collect_eq] bool_assn_proper(4)) + apply rule + apply (metis (mono_tags) + Abs_assn_inverse[unfolded mem_Collect_eq] + Rep_assn[unfolded mem_Collect_eq] bool_assn_proper(4)) + apply rule + apply (simp add: Abs_assn_inverse) + apply (metis (mono_tags) + Abs_assn_inverse[unfolded mem_Collect_eq] + Rep_assn[unfolded mem_Collect_eq] bool_assn_proper(4)) + done + +end + +text \We give the operations some more standard names\ +abbreviation top_assn::assn ("true") where "top_assn \ top" +abbreviation bot_assn::assn ("false") where "bot_assn \ bot" +abbreviation sup_assn::"assn\assn\assn" (infixr "\\<^sub>A" 61) + where "sup_assn \ sup" +abbreviation inf_assn::"assn\assn\assn" (infixr "\\<^sub>A" 62) + where "inf_assn \ inf" +abbreviation uminus_assn::"assn \ assn" ("\\<^sub>A _" [81] 80) + where "uminus_assn \ uminus" + +text \Now we prove some relations between the Boolean algebra operations + and the (empty heap,separation conjunction) monoid\ + +lemma star_false_left[simp]: "false * P = false" + unfolding times_assn_def bot_assn_def + apply rule + apply (auto simp add: Abs_assn_inverse) + done + +lemma star_false_right[simp]: "P * false = false" + using star_false_left by (simp add: assn_times_comm) + +lemmas star_false = star_false_left star_false_right + +lemma assn_basic_inequalities[simp, intro!]: + "true \ emp" "emp \ true" + "false \ emp" "emp \ false" + "true \ false" "false \ true" + subgoal + unfolding one_assn_def top_assn_def + proof (subst Abs_assn_inject; simp?) + have "in_range (\arrays = (\_ _. []), refs = (\_ _. 0), lim = 1\,{0})" (is "in_range ?h") + by (auto simp: in_range.simps) + moreover have "\one_assn_raw ?h" by auto + ultimately show "in_range \ one_assn_raw" by auto + qed + subgoal + by (simp add: \true \ emp\) + subgoal + using star_false_left \true \ emp\ by force + subgoal + by (simp add: \false \ emp\) + subgoal + by (metis inf_bot_right inf_top.right_neutral \true \ emp\) + subgoal + using \true \ false\ by auto + done + + +subsubsection \Existential Quantification\ +definition ex_assn :: "('a \ assn) \ assn" (binder "\\<^sub>A" 11) + where "(\\<^sub>Ax. P x) \ Abs_assn (\h. \x. h\P x)" + +lemma ex_assn_proper[simp, intro!]: + "(\x. proper (P x)) \ proper (\h. \x. P x h)" + by (auto intro!: properI dest: properD1 simp: proper_iff) + +lemma ex_assn_const[simp]: "(\\<^sub>Ax. c) = c" + unfolding ex_assn_def by auto + +lemma ex_one_point_gen: + "\\h x. h\P x \ x=v\ \ (\\<^sub>Ax. P x) = (P v)" + unfolding ex_assn_def + apply rule + apply auto + done + +lemma ex_distrib_star: "(\\<^sub>Ax. P x * Q) = (\\<^sub>Ax. P x) * Q" + unfolding ex_assn_def times_assn_def + apply rule + apply (simp add: Abs_assn_inverse) + apply fastforce + done + +lemma ex_distrib_and: "(\\<^sub>Ax. P x \\<^sub>A Q) = (\\<^sub>Ax. P x) \\<^sub>A Q" + unfolding ex_assn_def inf_assn_def + apply rule + apply (simp add: Abs_assn_inverse) + done + +lemma ex_distrib_or: "(\\<^sub>Ax. P x \\<^sub>A Q) = (\\<^sub>Ax. P x) \\<^sub>A Q" + unfolding ex_assn_def sup_assn_def + apply rule + apply (auto simp add: Abs_assn_inverse) + done + +lemma ex_join_or: "(\\<^sub>Ax. P x \\<^sub>A (\\<^sub>Ax. Q x)) = (\\<^sub>Ax. P x \\<^sub>A Q x)" + unfolding ex_assn_def sup_assn_def + apply rule + apply (auto simp add: Abs_assn_inverse) + done + +subsubsection \Pure Assertions\ +text \Pure assertions do not depend on any heap content.\ +fun pure_assn_raw where "pure_assn_raw b (h,as) \ as={} \ b" +definition pure_assn :: "bool \ assn" ("\") where + "\b \ Abs_assn (pure_assn_raw b)" + +lemma pure_assn_proper[simp, intro!]: "proper (pure_assn_raw b)" + by (auto intro!: properI intro: relH_in_rangeI) + + + +lemma pure_true[simp]: "\True = emp" + unfolding pure_assn_def one_assn_def + apply rule + apply (simp add: Abs_assn_inverse) + apply (auto) + done + +lemma pure_false[simp]: "\False = false" + unfolding pure_assn_def bot_assn_def + apply rule + apply (auto simp: Abs_assn_inverse) + done + +lemma pure_assn_eq_false_iff[simp]: "\P = false \ \P" by auto + +lemma pure_assn_eq_emp_iff[simp]: "\P = emp \ P" by (cases P) auto + +lemma merge_pure_star[simp]: + "\a * \b = \(a\b)" + unfolding times_assn_def + apply rule + unfolding pure_assn_def + apply (simp add: Abs_assn_inverse) + apply fastforce + done + +lemma merge_true_star[simp]: "true*true = true" + unfolding times_assn_def top_assn_def + apply rule + apply (simp add: Abs_assn_inverse) + apply (fastforce simp: in_range.simps) + done + +lemma merge_pure_and[simp]: + "\a \\<^sub>A \b = \(a\b)" + unfolding inf_assn_def + apply rule + unfolding pure_assn_def + apply (simp add: Abs_assn_inverse) + apply fastforce + done + +lemma merge_pure_or[simp]: + "\a \\<^sub>A \b = \(a\b)" + unfolding sup_assn_def + apply rule + unfolding pure_assn_def + apply (simp add: Abs_assn_inverse) + apply fastforce + done + + +lemma pure_assn_eq_conv[simp]: "\P = \Q \ P=Q" by auto + +definition "is_pure_assn a \ \P. a=\P" +lemma is_pure_assnE: assumes "is_pure_assn a" obtains P where "a=\P" + using assms + by (auto simp: is_pure_assn_def) + +lemma is_pure_assn_pure[simp, intro!]: "is_pure_assn (\P)" + by (auto simp add: is_pure_assn_def) + +lemma is_pure_assn_basic_simps[simp]: + "is_pure_assn false" + "is_pure_assn emp" +proof - + have "is_pure_assn (\False)" by rule thus "is_pure_assn false" by simp + have "is_pure_assn (\True)" by rule thus "is_pure_assn emp" by simp +qed + +lemma is_pure_assn_starI[simp,intro!]: + "\is_pure_assn a; is_pure_assn b\ \ is_pure_assn (a*b)" + by (auto elim!: is_pure_assnE) + + + + +subsubsection \Pointers\ +text \In Imperative HOL, we have to distinguish between pointers to single + values and pointers to arrays. For both, we define assertions that + describe the part of the heap that a pointer points to.\ +fun sngr_assn_raw :: "'a::heap ref \ 'a \ assn_raw" where + "sngr_assn_raw r x (h,as) \ Ref_Time.get h r = x \ as = {addr_of_ref r} \ + addr_of_ref r < lim h" + +lemma sngr_assn_proper[simp, intro!]: "proper (sngr_assn_raw r x)" + apply (auto intro!: properI simp: relH_ref) + apply (simp add: in_range.simps) + apply (auto simp add: in_range.simps dest: relH_in_rangeI) + done + +definition sngr_assn :: "'a::heap ref \ 'a \ assn" (infix "\\<^sub>r" 82) + where "r\\<^sub>rx \ Abs_assn (sngr_assn_raw r x)" + +fun snga_assn_raw :: "'a::heap array \ 'a list \ assn_raw" + where "snga_assn_raw r x (h,as) + \ Array_Time.get h r = x \ as = {addr_of_array r} + \ addr_of_array r < lim h" + +lemma snga_assn_proper[simp, intro!]: "proper (snga_assn_raw r x)" + apply (auto intro!: properI simp: relH_array) + apply (simp add: in_range.simps) + apply (auto simp add: in_range.simps dest: relH_in_rangeI) + done + +definition + snga_assn :: "'a::heap array \ 'a list \ assn" (infix "\\<^sub>a" 82) + where "r\\<^sub>aa \ Abs_assn (snga_assn_raw r a)" + +text \Two disjoint parts of the heap cannot be pointed to by the + same pointer\ +lemma sngr_same_false[simp]: + "p \\<^sub>r x * p \\<^sub>r y = false" + unfolding times_assn_def bot_assn_def sngr_assn_def + apply rule + apply (auto simp: Abs_assn_inverse) + done + +lemma snga_same_false[simp]: + "p \\<^sub>a x * p \\<^sub>a y = false" + unfolding times_assn_def bot_assn_def snga_assn_def + apply rule + apply (auto simp: Abs_assn_inverse) + done + +subsection \Properties of the Models-Predicate\ +lemma mod_true[simp]: "h\true \ in_range h" + unfolding top_assn_def by (simp add: Abs_assn_inverse) +lemma mod_false[simp]: "\ h\false" + unfolding bot_assn_def by (simp add: Abs_assn_inverse) + +lemma mod_emp: "h\emp \ snd h = {}" + unfolding one_assn_def by (cases h) (simp add: Abs_assn_inverse) + +lemma mod_emp_simp[simp]: "(h,{})\emp" + by (simp add: mod_emp) + +lemma mod_pure[simp]: "h\\b \ snd h = {} \ b" + unfolding pure_assn_def + apply (cases h) + apply (auto simp add: Abs_assn_inverse) + done + +lemma mod_ex_dist[simp]: "h\(\\<^sub>Ax. P x) \ (\x. h\P x)" + unfolding ex_assn_def by (auto simp: Abs_assn_inverse) + +lemma mod_exI: "\x. h\P x \ h\(\\<^sub>Ax. P x)" + by (auto simp: mod_ex_dist) +lemma mod_exE: assumes "h\(\\<^sub>Ax. P x)" obtains x where "h\P x" + using assms by (auto simp: mod_ex_dist) + +(* Not declared as simp, to not interfere with precision. + TODO: Perhaps define own connector for precision claims? +*) +lemma mod_and_dist: "h\P\\<^sub>AQ \ h\P \ h\Q" + unfolding inf_assn_def by (simp add: Abs_assn_inverse) + +lemma mod_or_dist[simp]: "h\P\\<^sub>AQ \ h\P \ h\Q" + unfolding sup_assn_def by (simp add: Abs_assn_inverse) + +lemma mod_not_dist[simp]: "h\(\\<^sub>AP) \ in_range h \ \ h\P" + unfolding uminus_assn_def by (simp add: Abs_assn_inverse) + +lemma mod_pure_star_dist[simp]: "h\P*\b \ h\P \ b" + by (metis (full_types) mod_false mult_1_right pure_false + pure_true star_false_right) + +lemmas mod_dist = mod_pure mod_pure_star_dist mod_ex_dist mod_and_dist + mod_or_dist mod_not_dist + +lemma mod_star_trueI: "h\P \ h\P*true" + unfolding times_assn_def top_assn_def + apply (simp add: Abs_assn_inverse) + apply (cases h) + apply auto + done + +lemma mod_star_trueE': assumes "h\P*true" obtains h' where + "fst h' = fst h" and "snd h' \ snd h" and "h'\P" + using assms + unfolding times_assn_def top_assn_def + apply (cases h) + apply (fastforce simp add: Abs_assn_inverse) + done + +lemma mod_star_trueE: assumes "h\P*true" obtains h' where "h'\P" + using assms by (blast elim: mod_star_trueE') + +lemma mod_h_bot_iff[simp]: + "(h,{}) \ \b \ b" + "(h,{}) \ true" + "(h,{}) \ p\\<^sub>rx \ False" + "(h,{}) \ q\\<^sub>ay \ False" + "(h,{}) \ P*Q \ ((h,{}) \ P) \ ((h,{}) \ Q)" + "(h,{}) \ P\\<^sub>AQ \ ((h,{}) \ P) \ ((h,{}) \ Q)" + "(h,{}) \ P\\<^sub>AQ \ ((h,{}) \ P) \ ((h,{}) \ Q)" + "(h,{}) \ (\\<^sub>Ax. R x) \ (\x. (h,{}) \ R x)" + apply (simp add: pure_assn_def Abs_assn_inverse) + apply simp + apply (simp add: sngr_assn_def Abs_assn_inverse) + apply (simp add: snga_assn_def Abs_assn_inverse) + apply (simp add: times_assn_def Abs_assn_inverse) + apply (simp add: inf_assn_def Abs_assn_inverse) + apply (simp add: sup_assn_def Abs_assn_inverse) + apply (simp add: ex_assn_def Abs_assn_inverse) + done + +subsection \Entailment\ +definition entails :: "assn \ assn \ bool" (infix "\\<^sub>A" 10) + where "P \\<^sub>A Q \ \h. h\P \ h\Q" + +lemma entailsI: + assumes "\h. h\P \ h\Q" + shows "P \\<^sub>A Q" + using assms unfolding entails_def by auto + +lemma entailsD: + assumes "P \\<^sub>A Q" + assumes "h\P" + shows "h\Q" + using assms unfolding entails_def by blast + +subsubsection \Properties\ +lemma ent_fwd: + assumes "h\P" + assumes "P \\<^sub>A Q" + shows "h\Q" using assms(2,1) by (rule entailsD) + +lemma ent_refl[simp]: "P \\<^sub>A P" + by (auto simp: entailsI) + +lemma ent_trans[trans]: "\ P \\<^sub>A Q; Q \\<^sub>AR \ \ P \\<^sub>A R" + by (auto intro: entailsI dest: entailsD) + +lemma ent_iffI: + assumes "A\\<^sub>AB" + assumes "B\\<^sub>AA" + shows "A=B" + apply (subst Rep_assn_inject[symmetric]) + apply (rule ext) + using assms unfolding entails_def + by blast + +lemma ent_false[simp]: "false \\<^sub>A P" + by (auto intro: entailsI) +lemma ent_true[simp]: "P \\<^sub>A true" + by (auto intro!: entailsI simp: models_in_range) + +lemma ent_false_iff[simp]: "(P \\<^sub>A false) \ (\h. \h\P)" + unfolding entails_def + by auto + +lemma ent_pure_pre_iff[simp]: "(P*\b \\<^sub>A Q) \ (b \ (P \\<^sub>A Q))" + unfolding entails_def + by (auto simp add: mod_dist) + +lemma ent_pure_pre_iff_sng[simp]: + "(\b \\<^sub>A Q) \ (b \ (emp \\<^sub>A Q))" + using ent_pure_pre_iff[where P=emp] + by simp + +lemma ent_pure_post_iff[simp]: + "(P \\<^sub>A Q*\b) \ ((\h. h\P \ b) \ (P \\<^sub>A Q))" + unfolding entails_def + by (auto simp add: mod_dist) + +lemma ent_pure_post_iff_sng[simp]: + "(P \\<^sub>A \b) \ ((\h. h\P \ b) \ (P \\<^sub>A emp))" + using ent_pure_post_iff[where Q=emp] + by simp + +lemma ent_ex_preI: "(\x. P x \\<^sub>A Q) \ \\<^sub>Ax. P x \\<^sub>A Q" + unfolding entails_def ex_assn_def + by (auto simp: Abs_assn_inverse) + +lemma ent_ex_postI: "(P \\<^sub>A Q x) \ P \\<^sub>A \\<^sub>Ax. Q x" + unfolding entails_def ex_assn_def + by (auto simp: Abs_assn_inverse) + +lemma ent_mp: "(P * (P -* Q)) \\<^sub>A Q" + apply (rule entailsI) + unfolding times_assn_def wand_assn_def + apply (clarsimp simp add: Abs_assn_inverse) + apply (drule_tac x="a" in spec) + apply (drule_tac x="as1" in spec) + apply (auto simp: Un_ac relH_refl) + done + +lemma ent_star_mono: "\ P \\<^sub>A P'; Q \\<^sub>A Q'\ \ P*Q \\<^sub>A P'*Q'" + unfolding entails_def times_assn_def + apply (simp add: Abs_assn_inverse) + apply metis + done + +lemma ent_wandI: + assumes IMP: "Q*P \\<^sub>A R" + shows "P \\<^sub>A (Q -* R)" + unfolding entails_def + apply clarsimp + apply (rule wand_assnI) + apply (blast intro: models_in_range) +proof - + fix h as h' as' + assume "(h,as)\P" + and "as\as'={}" + and "relH as h h'" + and "in_range (h',as)" + and "(h',as') \ Q" + + from \(h,as)\P\ and \relH as h h'\ have "(h',as)\P" + by (simp add: mod_relH) + with \(h',as') \ Q\ and \as\as'={}\ have "(h',as\as')\Q*P" + by (metis star_assnI Int_commute Un_commute) + with IMP show "(h',as\as') \ R" by (blast dest: ent_fwd) +qed + +lemma ent_disjI1: + assumes "P \\<^sub>A Q \\<^sub>A R" + shows "P \\<^sub>A R" using assms unfolding entails_def by simp + +lemma ent_disjI2: + assumes "P \\<^sub>A Q \\<^sub>A R" + shows "Q \\<^sub>A R" using assms unfolding entails_def by simp + +lemma ent_disjI1_direct[simp]: "A \\<^sub>A A \\<^sub>A B" + by (simp add: entails_def) + +lemma ent_disjI2_direct[simp]: "B \\<^sub>A A \\<^sub>A B" + by (simp add: entails_def) + +lemma ent_disjE: "\ A\\<^sub>AC; B\\<^sub>AC \ \ A\\<^sub>AB \\<^sub>AC" + unfolding entails_def by auto + +lemma ent_conjI: "\ A\\<^sub>AB; A\\<^sub>AC \ \ A \\<^sub>A B \\<^sub>A C" + unfolding entails_def by (auto simp: mod_and_dist) + +lemma ent_conjE1: "\A\\<^sub>AC\ \ A\\<^sub>AB\\<^sub>AC" + unfolding entails_def by (auto simp: mod_and_dist) +lemma ent_conjE2: "\B\\<^sub>AC\ \ A\\<^sub>AB\\<^sub>AC" + unfolding entails_def by (auto simp: mod_and_dist) + + + +lemma star_or_dist1: + "(A \\<^sub>A B)*C = (A*C \\<^sub>A B*C)" + apply (rule ent_iffI) + unfolding entails_def + by (auto simp add: mod_star_conv) + +lemma star_or_dist2: + "C*(A \\<^sub>A B) = (C*A \\<^sub>A C*B)" + apply (rule ent_iffI) + unfolding entails_def + by (auto simp add: mod_star_conv) + +lemmas star_or_dist = star_or_dist1 star_or_dist2 + +lemma ent_disjI1': "A\\<^sub>AB \ A\\<^sub>AB\\<^sub>AC" + by (auto simp: entails_def star_or_dist) + +lemma ent_disjI2': "A\\<^sub>AC \ A\\<^sub>AB\\<^sub>AC" + by (auto simp: entails_def star_or_dist) + +lemma triv_exI[simp, intro!]: "Q x \\<^sub>A \\<^sub>Ax. Q x" + by (meson ent_ex_postI ent_refl) + +subsubsection \Weak Entails\ +text \Weakening of entails to allow arbitrary unspecified memory in conclusion\ +definition entailst :: "assn \ assn \ bool" (infix "\\<^sub>t" 10) + where "entailst A B \ A \\<^sub>A B * true" + +lemma enttI: "A\\<^sub>AB*true \ A\\<^sub>tB" unfolding entailst_def . +lemma enttD: "A\\<^sub>tB \ A\\<^sub>AB*true" unfolding entailst_def . + +lemma entt_trans: + "entailst A B \ entailst B C \ entailst A C" + unfolding entailst_def + apply (erule ent_trans) + by (metis assn_times_assoc ent_star_mono ent_true merge_true_star) + +lemma entt_refl[simp, intro!]: "entailst A A" + unfolding entailst_def + by (simp add: entailsI mod_star_trueI) + +lemma entt_true[simp, intro!]: + "entailst A true" + unfolding entailst_def by simp + +lemma entt_emp[simp, intro!]: + "entailst A emp" + unfolding entailst_def by simp + +lemma entt_star_true_simp[simp]: + "entailst A (B*true) \ entailst A B" + "entailst (A*true) B \ entailst A B" + unfolding entailst_def + subgoal by (auto simp: assn_times_assoc) + subgoal + apply (intro iffI) + subgoal using entails_def mod_star_trueI by blast + subgoal by (metis assn_times_assoc ent_refl ent_star_mono merge_true_star) + done + done + +lemma entt_star_mono: "\entailst A B; entailst C D\ \ entailst (A*C) (B*D)" + unfolding entailst_def +proof - + assume a1: "A \\<^sub>A B * true" + assume "C \\<^sub>A D * true" + then have "A * C \\<^sub>A true * B * (true * D)" + using a1 assn_times_comm ent_star_mono by force + then show "A * C \\<^sub>A B * D * true" + by (simp add: ab_semigroup_mult_class.mult.left_commute assn_times_comm) +qed + +lemma entt_frame_fwd: + assumes "entailst P Q" + assumes "entailst A (P*F)" + assumes "entailst (Q*F) B" + shows "entailst A B" + using assms + by (metis entt_refl entt_star_mono entt_trans) + +lemma enttI_true: "P*true \\<^sub>A Q*true \ P\\<^sub>tQ" + by (drule enttI) simp + +lemma entt_def_true: "(P\\<^sub>tQ) \ (P*true \\<^sub>A Q*true)" + unfolding entailst_def + apply (rule eq_reflection) + using entailst_def entt_star_true_simp(2) by auto + +lemma ent_imp_entt: "P\\<^sub>AQ \ P\\<^sub>tQ" + apply (rule enttI) + apply (erule ent_trans) + by (simp add: entailsI mod_star_trueI) + +lemma entt_disjI1_direct[simp]: "A \\<^sub>t A \\<^sub>A B" + by (rule ent_imp_entt[OF ent_disjI1_direct]) + +lemma entt_disjI2_direct[simp]: "B \\<^sub>t A \\<^sub>A B" + by (rule ent_imp_entt[OF ent_disjI2_direct]) + +lemma entt_disjI1': "A\\<^sub>tB \ A\\<^sub>tB\\<^sub>AC" + by (auto simp: entailst_def entails_def star_or_dist) + +lemma entt_disjI2': "A\\<^sub>tC \ A\\<^sub>tB\\<^sub>AC" + by (auto simp: entailst_def entails_def star_or_dist) + +lemma entt_disjE: "\ A\\<^sub>tM; B\\<^sub>tM \ \ A\\<^sub>AB \\<^sub>t M" + using ent_disjE enttD enttI by blast + +lemma entt_disjD1: "A\\<^sub>AB\\<^sub>tC \ A\\<^sub>tC" + using entt_disjI1_direct entt_trans by blast + +lemma entt_disjD2: "A\\<^sub>AB\\<^sub>tC \ B\\<^sub>tC" + using entt_disjI2_direct entt_trans by blast + + +subsection \Precision\ +text \ + Precision rules describe that parts of an assertion may depend only on the + underlying heap. For example, the data where a pointer points to is the same + for the same heap. +\ +text \Precision rules should have the form: + @{text [display] "\x y. (h\(P x * F1) \\<^sub>A (P y * F2)) \ x=y"}\ +definition "precise R \ \a a' h p F F'. + h \ R a p * F \\<^sub>A R a' p * F' \ a = a'" + +lemma preciseI[intro?]: + assumes "\a a' h p F F'. h \ R a p * F \\<^sub>A R a' p * F' \ a = a'" + shows "precise R" + using assms unfolding precise_def by blast + +lemma preciseD: + assumes "precise R" + assumes "h \ R a p * F \\<^sub>A R a' p * F'" + shows "a=a'" + using assms unfolding precise_def by blast + +lemma preciseD': + assumes "precise R" + assumes "h \ R a p * F" + assumes "h \ R a' p * F'" + shows "a=a'" + apply (rule preciseD) + apply (rule assms) + apply (simp only: mod_and_dist) + apply (blast intro: assms) + done + +lemma precise_extr_pure[simp]: + "precise (\x y. \P * R x y) \ (P \ precise R)" + "precise (\x y. R x y * \P) \ (P \ precise R)" + apply (cases P, (auto intro!: preciseI) [2])+ + done + +lemma sngr_prec: "precise (\x p. p\\<^sub>rx)" + apply rule + apply (clarsimp simp: mod_and_dist) + unfolding sngr_assn_def times_assn_def + apply (simp add: Abs_assn_inverse) + apply auto + done + +lemma snga_prec: "precise (\x p. p\\<^sub>ax)" + apply rule + apply (clarsimp simp: mod_and_dist) + unfolding snga_assn_def times_assn_def + apply (simp add: Abs_assn_inverse) + apply auto + done + +end diff --git a/thys/Van_Emde_Boas_Trees/Separation_Logic_Imperative_HOL/Automation.thy b/thys/Van_Emde_Boas_Trees/Separation_Logic_Imperative_HOL/Automation.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/Separation_Logic_Imperative_HOL/Automation.thy @@ -0,0 +1,1071 @@ +section \Automation\ +theory Automation +imports Hoare_Triple Refine_Imp_Hol (*"../Lib/Refine_Util"*) +begin + +text \ + In this theory, we provide a set of tactics and a simplifier setup for easy + reasoning with our separation logic.\ + +subsection \Normalization of Assertions\ +text \ + In this section, we provide a set of lemmas and a simplifier + setup to bring assertions to a normal form. We provide a simproc that + detects pure parts of assertions and duplicate pointers. Moreover, + we provide ac-rules for assertions. See Section~\ref{sec:auto:overview} + for a short overview of the available proof methods. +\ + +lemmas assn_aci = + inf_aci[where 'a=assn] + sup_aci[where 'a=assn] + mult.left_ac[where 'a=assn] + +lemmas star_assoc = mult.assoc[where 'a=assn] +lemmas assn_assoc = + mult.left_assoc inf_assoc[where 'a=assn] sup_assoc[where 'a=assn] + +lemma merge_true_star_ctx: "true * (true * P) = true * P" + by (simp add: mult.left_ac) + +lemmas star_aci = + mult.assoc[where 'a=assn] mult.commute[where 'a=assn] mult.left_commute[where 'a=assn] + assn_one_left mult_1_right[where 'a=assn] + merge_true_star merge_true_star_ctx + +text \Move existential quantifiers to the front of assertions\ +lemma ex_assn_move_out[simp]: + "\Q R. (\\<^sub>Ax. Q x) * R = (\\<^sub>Ax. (Q x * R))" + "\Q R. R * (\\<^sub>Ax. Q x) = (\\<^sub>Ax. (R * Q x))" + + "\P Q. (\\<^sub>Ax. Q x) \\<^sub>A P = (\\<^sub>Ax. (Q x \\<^sub>A P)) " + "\P Q. Q \\<^sub>A (\\<^sub>Ax. P x) = (\\<^sub>Ax. (Q \\<^sub>A P x))" + + "\P Q. (\\<^sub>Ax. Q x) \\<^sub>A P = (\\<^sub>Ax. (Q x \\<^sub>A P))" + "\P Q. Q \\<^sub>A (\\<^sub>Ax. P x) = (\\<^sub>Ax. (Q \\<^sub>A P x))" + apply - + apply (simp add: ex_distrib_star) + apply (subst mult.commute) + apply (subst (2) mult.commute) + apply (simp add: ex_distrib_star) + + apply (simp add: ex_distrib_and) + apply (subst inf_commute) + apply (subst (2) inf_commute) + apply (simp add: ex_distrib_and) + + apply (simp add: ex_distrib_or) + apply (subst sup_commute) + apply (subst (2) sup_commute) + apply (simp add: ex_distrib_or) + done + +text \Extract pure assertions from and-clauses\ +lemma and_extract_pure_left_iff[simp]: "\b \\<^sub>A Q = (emp\\<^sub>AQ)*\b" + by (cases b) auto + +lemma and_extract_pure_left_ctx_iff[simp]: "P*\b \\<^sub>A Q = (P\\<^sub>AQ)*\b" + by (cases b) auto + +lemma and_extract_pure_right_iff[simp]: "P \\<^sub>A \b = (emp\\<^sub>AP)*\b" + by (cases b) (auto simp: assn_aci) + +lemma and_extract_pure_right_ctx_iff[simp]: "P \\<^sub>A Q*\b = (P\\<^sub>AQ)*\b" + by (cases b) auto + +lemmas and_extract_pure_iff = + and_extract_pure_left_iff and_extract_pure_left_ctx_iff + and_extract_pure_right_iff and_extract_pure_right_ctx_iff + +lemmas norm_assertion_simps = + (* Neutral elements *) + mult_1[where 'a=assn] mult_1_right[where 'a=assn] + inf_top_left[where 'a=assn] inf_top_right[where 'a=assn] + sup_bot_left[where 'a=assn] sup_bot_right[where 'a=assn] + + (* Zero elements *) + star_false_left star_false_right + inf_bot_left[where 'a=assn] inf_bot_right[where 'a=assn] + sup_top_left[where 'a=assn] sup_top_right[where 'a=assn] + + (* Associativity *) + mult.left_assoc[where 'a=assn] + inf_assoc[where 'a=assn] + sup_assoc[where 'a=assn] + + (* Existential Quantifiers *) + ex_assn_move_out ex_assn_const + + (* Extract pure assertions from conjunctions *) + and_extract_pure_iff + + (* Merging *) + merge_pure_star merge_pure_and merge_pure_or + merge_true_star + inf_idem[where 'a=assn] sup_idem[where 'a=assn] + + (* Duplicated References *) + sngr_same_false snga_same_false + + +subsubsection \Simplifier Setup Fine-Tuning\ +(*text \Imperative HOL likes to simplify pointer inequations to this strange + operator. We do some additional simplifier setup here\ +lemma not_same_noteqr[simp]: "\ a=!=a" + by (metis Ref.unequal) +declare Ref.noteq_irrefl[dest!] + +lemma not_same_noteqa[simp]: "\ a=!!=a" + by (metis Array.unequal) +declare Array.noteq_irrefl[dest!] +*) + +text \However, it is safest to disable this rewriting, as there is + a working standard simplifier setup for \(\)\ +\ +(*declare Ref.unequal[simp del] +declare Array.unequal[simp del] +*) + + +subsection \Normalization of Entailments\ + +text \Used by existential quantifier extraction tactic\ +lemma enorm_exI': (* Incomplete, as chosen x may depend on heap! *) + "(\x. Z x \ (P \\<^sub>A Q x)) \ (\x. Z x) \ (P \\<^sub>A (\\<^sub>Ax. Q x))" + by (metis ent_ex_postI) + +text \Example of how to build an extraction lemma.\ +thm enorm_exI'[OF enorm_exI'[OF imp_refl]] + +lemmas ent_triv = ent_true ent_false + +text \Dummy rule to detect Hoare triple goal\ +lemma is_hoare_triple: "

c \

c " . +text \Dummy rule to detect entailment goal\ +lemma is_entails: "P\\<^sub>AQ \ P \\<^sub>AQ" . + +subsection \Frame Matcher\ +text \Given star-lists P,Q and a frame F, this method tries to match + all elements of Q with corresponding elements of P. The result is a + partial match, that contains matching pairs and the unmatched content.\ + +text \The frame-matcher internally uses syntactic lists separated by + star, and delimited by the special symbol \SLN\, which is defined + to be \emp\.\ +definition [simp]: "SLN \ emp" +lemma SLN_left: "SLN * P = P" by simp +lemma SLN_right: "P * SLN = P" by simp + +lemmas SLN_normalize = SLN_right mult.left_assoc[where 'a=assn] +lemmas SLN_strip = SLN_right SLN_left mult.left_assoc[where 'a=assn] + +text \A query to the frame matcher. Contains the assertions + P and Q that shall be matched, as well as a frame F, that is not + touched.\ + +definition [simp]: "FI_QUERY P Q F \ P \\<^sub>A Q*F" + +abbreviation "fi_m_fst M \ foldr (*) (map fst M) emp" +abbreviation "fi_m_snd M \ foldr (*) (map snd M) emp" +abbreviation "fi_m_match M \ (\(p,q)\set M. p \\<^sub>A q)" + +text \A result of the frame matcher. Contains a list of matching pairs, + as well as the unmatched parts of P and Q, and the frame F. +\ +definition [simp]: "FI_RESULT M UP UQ F \ + fi_m_match M \ (fi_m_fst M * UP \\<^sub>A fi_m_snd M * UQ * F)" + +text \Internal structure used by the frame matcher: + m contains the matched pairs; p,q the assertions that still needs to be + matched; up,uq the assertions that could not be matched; and f the frame. + p and q are SLN-delimited syntactic lists. +\ + +definition [simp]: "FI m p q up uq f \ + fi_m_match m \ (fi_m_fst m * p * up \\<^sub>A fi_m_snd m * q * uq * f)" + +text \Initialize processing of query\ +lemma FI_init: + assumes "FI [] (SLN*P) (SLN*Q) SLN SLN F" + shows "FI_QUERY P Q F" + using assms by simp + +text \Construct result from internal representation\ +lemma FI_finalize: + assumes "FI_RESULT m (p*up) (q*uq) f" + shows "FI m p q up uq f" + using assms by (simp add: assn_aci) + +text \Auxiliary lemma to show that all matching pairs together form + an entailment. This is required for most applications.\ +lemma fi_match_entails: + assumes "fi_m_match m" + shows "fi_m_fst m \\<^sub>A fi_m_snd m" + using assms apply (induct m) + apply (simp_all split: prod.split_asm add: ent_star_mono) + done + +text \Internally, the frame matcher tries to match the first assertion + of q with the first assertion of p. If no match is found, the first + assertion of p is discarded. If no match for any assertion in p can be + found, the first assertion of q is discarded.\ + +text \Match\ +lemma FI_match: + assumes "p \\<^sub>A q" + assumes "FI ((p,q)#m) (ps*up) (qs*uq) SLN SLN f" + shows "FI m (ps*p) (qs*q) up uq f" + using assms unfolding FI_def + by (simp add: assn_aci) + +text \No match\ +lemma FI_p_nomatch: + assumes "FI m ps (qs*q) (p*up) uq f" + shows "FI m (ps*p) (qs*q) up uq f" + using assms unfolding FI_def + by (simp add: assn_aci) + +text \Head of q could not be matched\ +lemma FI_q_nomatch: + assumes "FI m (SLN*up) qs SLN (q*uq) f" + shows "FI m SLN (qs*q) up uq f" + using assms unfolding FI_def + by (simp add: assn_aci) + +subsection \Frame Inference\ +lemma frame_inference_init: + assumes "FI_QUERY P Q F" + shows "P \\<^sub>A Q * F" + using assms by simp + +lemma frame_inference_finalize: + shows "FI_RESULT M F emp F" + apply simp + apply rule + apply (drule fi_match_entails) + apply (rule ent_star_mono[OF _ ent_refl]) + apply assumption + done + +subsection \Entailment Solver\ +lemma entails_solve_init: + "FI_QUERY P Q true \ P \\<^sub>A Q * true" + "FI_QUERY P Q emp \ P \\<^sub>A Q" + by (simp_all add: assn_aci) + +lemma entails_solve_finalize: + "FI_RESULT M P emp true" + "FI_RESULT M emp emp emp" + by (auto simp add: fi_match_entails intro: ent_star_mono) + +lemmas solve_ent_preprocess_simps = + ent_pure_post_iff ent_pure_post_iff_sng ent_pure_pre_iff ent_pure_pre_iff_sng + +subsection \Verification Condition Generator\ + +lemmas normalize_rules = norm_pre_ex_rule norm_pre_pure_rule + +(* Originally we introduced backwards-reasoning here, via + cons_pre_rule[OF _ return_wp_rule] (old name: complete_return_cons). + This only works, if the postcondition is not schematic! However, for + forward reasoning, one usually assumes a schematic postcondition! + *) +text \May be useful in simple, manual proofs, where the postcondition + is no schematic variable.\ +lemmas return_cons_rule = cons_pre_rule[OF _ return_wp_rule] + +text \Useful frame-rule variant for manual proof:\ +lemma frame_rule_left: + "

c \ c <\x. R * Q x>" + using frame_rule by (simp add: assn_aci) + +lemmas deconstruct_rules = + wait_bind_decon assert'_bind_rule + bind_rule if_rule false_rule return_sp_rule let_rule + case_prod_rule case_list_rule case_option_rule case_sum_rule + + +lemmas heap_rules = + ref_rule + lookup_rule + update_rule + new_rule + make_rule + of_list_rule + length_rule + nth_rule + upd_rule + freeze_rule + wait_rule + assert'_rule + +lemma fi_rule: + assumes CMD: "

c " + assumes FRAME: "Ps \\<^sub>A P * F" + shows " c <\x. Q x * F>" + apply (rule cons_pre_rule[rotated]) + apply (rule frame_rule) + apply (rule CMD) + apply (rule FRAME) + done + + +subsection \ML-setup\ + +named_theorems sep_dflt_simps "Seplogic: Default simplification rules for automated solvers" +named_theorems sep_eintros "Seplogic: Intro rules for entailment solver" +named_theorems sep_heap_rules "Seplogic: VCG heap rules" +named_theorems sep_decon_rules "Seplogic: VCG deconstruct rules" + +ML \ +infix 1 THEN_IGNORE_NEWGOALS + +structure Seplogic_Auto = +struct + + (***********************************) + (* Tools *) + (***********************************) + + (* Repeat tac on subgoal. Determinize each step. + Stop if tac fails or subgoal is solved. *) + fun REPEAT_DETERM' tac i st = let + val n = Thm.nprems_of st + in + REPEAT_DETERM (COND (has_fewer_prems n) no_tac (tac i)) st + end + + + (***********************************) + (* Debugging *) + (***********************************) + fun tr_term t = Pretty.string_of (Syntax.pretty_term @{context} t); + + + (***********************************) + (* Custom Tacticals *) + (***********************************) + + (* Apply tac1, and then tac2 with an offset such that anything left + over by tac1 is skipped. + + The typical usage of this tactic is, if a theorem is instantiated + with another theorem that produces additional goals that should + be ignored first. Here, it is used in the vcg to ensure that + frame inference is done before additional premises (that may + depend on the frame) are discharged. + *) + fun (tac1 THEN_IGNORE_NEWGOALS tac2) i st = let + val np = Thm.nprems_of st + in + (tac1 i THEN (fn st' => let val np' = Thm.nprems_of st' in + if np' term) (ts:term list) = let + fun frec _ [] = NONE + | frec tab (t::ts) = let val k=key_of t in + if Termtab.defined tab k then + SOME (the (Termtab.lookup tab k),t) + else frec (Termtab.update (k,t) tab) ts + end + in + frec Termtab.empty ts + end; + + (* Perform DFS over term with binary operator opN, threading through + a state. Atomic terms are transformed by tr. Supports omission of + terms from the result structure by transforming them to NONE. *) + fun dfs_opr opN (tr:'state -> term -> ('state*term option)) + d (t as ((op_t as Const (fN,_))$t1$t2)) = + if fN = opN then let + val (d1,t1') = dfs_opr opN tr d t1; + val (d2,t2') = dfs_opr opN tr d1 t2; + in + case (t1',t2') of + (NONE,NONE) => (d2,NONE) + | (SOME t1',NONE) => (d2,SOME t1') + | (NONE,SOME t2') => (d2,SOME t2') + | (SOME t1',SOME t2') => (d2,SOME (op_t$t1'$t2')) + end + else tr d t + | dfs_opr _ tr d t = tr d t; + + (* Replace single occurrence of (atomic) ot in t by nt. + Returns new term or NONE if nothing was removed. *) + fun dfs_replace_atomic opN ot nt t = let + fun tr d t = if not d andalso t=ot then (true,SOME nt) else (d,SOME t); + val (success,SOME t') = dfs_opr opN tr false t; + in + if success then SOME t' else NONE + end; + + fun assn_simproc_fun ctxt credex = let + val ([redex],ctxt') = Variable.import_terms true [Thm.term_of credex] ctxt; + (*val _ = tracing (tr_term redex);*) + val export = singleton (Variable.export ctxt' ctxt) + + fun mk_star t1 t2 = @{term "(*)::assn \ _ \ _"}$t2$t1; + + fun mk_star' NONE NONE = NONE + | mk_star' (SOME t1) NONE = SOME t1 + | mk_star' NONE (SOME t2) = SOME t2 + | mk_star' (SOME t1) (SOME t2) = SOME (mk_star t1 t2); + + fun ptrs_key (_$k$_) = k; + + fun remove_term pt t = case + dfs_replace_atomic @{const_name "Groups.times_class.times"} pt + @{term emp} t + of + SOME t' => t'; + + fun normalize t = let + + fun ep_tr (has_true,ps,ptrs) t = case t of + Const (@{const_name "Assertions.pure_assn"},_)$_ + => ((has_true,t::ps,ptrs),NONE) + | Const (@{const_name "Assertions.sngr_assn"},_)$_$_ + => ((has_true,ps,t::ptrs),SOME t) + | Const (@{const_name "Assertions.snga_assn"},_)$_$_ + => ((has_true,ps,t::ptrs),SOME t) + | Const (@{const_name "Orderings.top_class.top"},_) + => ((true,ps,ptrs),NONE) + | (inf_op as Const (@{const_name "Lattices.inf_class.inf"},_))$t1$t2 + => ((has_true,ps,ptrs),SOME (inf_op$normalize t1$normalize t2)) + | _ => ((has_true,ps,ptrs),SOME t); + + fun normalizer t = case dfs_opr @{const_name "Groups.times_class.times"} + ep_tr (false,[],[]) t + of + ((has_true,ps,ptrs),rt) => ((has_true,rev ps,ptrs),rt); + + fun normalize_core t = let + val ((has_true,pures,ptrs),rt) = normalizer t; + val similar = find_similar ptrs_key ptrs; + val true_t = if has_true then SOME @{term "Assertions.top_assn"} + else NONE; + val pures' = case pures of + [] => NONE + | p::ps => SOME (fold mk_star ps p); + in + case similar of NONE => the (mk_star' pures' (mk_star' true_t rt)) + | SOME (t1,t2) => let + val t_stripped = remove_term t1 (remove_term t2 t); + in mk_star t_stripped (mk_star t1 t2) end + end; + + fun skip_ex ((exq as Const (@{const_name "ex_assn"},_))$(Abs (n,ty,t))) = + exq$Abs (n,ty,skip_ex t) + | skip_ex t = normalize_core t; + + val (bs,t') = strip_abs t; + val ty = fastype_of1 (map #2 bs,t'); + in + if ty = @{typ assn} then + Logic.rlist_abs (bs,skip_ex t') + else t + end; + + (*val _ = tracing (tr_term redex);*) + val (f,terms) = strip_comb redex; + val nterms = map (fn t => let + (*val _ = tracing (tr_term t); *) + val t'=normalize t; + (*val _ = tracing (tr_term t');*) + in t' end) terms; + val new_form = list_comb (f,nterms); + + val res_ss = (put_simpset HOL_basic_ss ctxt addsimps @{thms star_aci}); + val result = Option.map (export o mk_meta_eq) (Arith_Data.prove_conv_nohyps + [simp_tac res_ss 1] ctxt' (redex,new_form) + ); + + in + result + end handle exc => + if Exn.is_interrupt exc then Exn.reraise exc + else + (tracing ("assn_simproc failed with exception\n:" ^ Runtime.exn_message exc); + NONE) (* Fail silently *); + + val assn_simproc = + Simplifier.make_simproc @{context} "assn_simproc" + {lhss = + [@{term "h \ P"}, + @{term "P \\<^sub>A Q"}, + @{term "P \\<^sub>t Q"}, + @{term "Hoare_Triple.hoare_triple P c Q"}, + @{term "(P::assn) = Q"}], + proc = K assn_simproc_fun}; + + + + (***********************************) + (* Default Simplifications *) + (***********************************) + + (* Default simplification. MUST contain assertion normalization! + Tactic must not fail! *) + fun dflt_tac ctxt = asm_full_simp_tac + (put_simpset HOL_ss ctxt + addsimprocs [assn_simproc] + addsimps @{thms norm_assertion_simps} + addsimps (Named_Theorems.get ctxt @{named_theorems sep_dflt_simps}) + |> fold Splitter.del_split @{thms if_split} + ); + + (***********************************) + (* Frame Matcher *) + (***********************************) + + (* Do frame matching + imp_solve_tac - tactic used to discharge first assumption of match-rule + cf. lemma FI_match. + *) + fun match_frame_tac imp_solve_tac ctxt = let + (* Normalize star-lists *) + val norm_tac = simp_tac ( + put_simpset HOL_basic_ss ctxt addsimps @{thms SLN_normalize}); + + (* Strip star-lists *) + val strip_tac = + simp_tac (put_simpset HOL_basic_ss ctxt addsimps @{thms SLN_strip}) THEN' + simp_tac (put_simpset HOL_basic_ss ctxt addsimps @{thms SLN_def}); + + (* Do a match step *) + val match_tac = resolve_tac ctxt @{thms FI_match} (* Separate p,q*) + THEN' SOLVED' imp_solve_tac (* Solve implication *) + THEN' norm_tac; + + (* Do a no-match step *) + val nomatch_tac = resolve_tac ctxt @{thms FI_p_nomatch} ORELSE' + (resolve_tac ctxt @{thms FI_q_nomatch} THEN' norm_tac); + in + resolve_tac ctxt @{thms FI_init} THEN' norm_tac + THEN' REPEAT_DETERM' (FIRST' [ + CHANGED o dflt_tac ctxt, + (match_tac ORELSE' nomatch_tac)]) + THEN' resolve_tac ctxt @{thms FI_finalize} THEN' strip_tac + end; + + + (***********************************) + (* Frame Inference *) + (***********************************) + + fun frame_inference_tac ctxt = + resolve_tac ctxt @{thms frame_inference_init} + THEN' match_frame_tac (resolve_tac ctxt @{thms ent_refl}) ctxt + THEN' resolve_tac ctxt @{thms frame_inference_finalize}; + + + (***********************************) + (* Entailment Solver *) + (***********************************) + + (* Extract existential quantifiers from entailment goal *) + fun extract_ex_tac ctxt i st = let + fun count_ex (Const (@{const_name Assertions.entails},_)$_$c) = + count_ex c RS @{thm HOL.mp} + | count_ex (Const (@{const_name Assertions.ex_assn},_)$Abs (_,_,t)) + = count_ex t RS @{thm enorm_exI'} + | count_ex _ = @{thm imp_refl}; + + val concl = Logic.concl_of_goal (Thm.prop_of st) i |> HOLogic.dest_Trueprop; + val thm = count_ex concl; + in + (TRY o REPEAT_ALL_NEW (match_tac ctxt @{thms ent_ex_preI}) THEN' + resolve_tac ctxt [thm]) i st + end; + + + (* Solve Entailment *) + fun solve_entails_tac ctxt = let + val preprocess_entails_tac = + dflt_tac ctxt + THEN' extract_ex_tac ctxt + THEN' simp_tac + (put_simpset HOL_ss ctxt addsimps @{thms solve_ent_preprocess_simps}); + + val match_entails_tac = + resolve_tac ctxt @{thms entails_solve_init} + THEN' match_frame_tac (resolve_tac ctxt @{thms ent_refl}) ctxt + THEN' resolve_tac ctxt @{thms entails_solve_finalize}; + in + preprocess_entails_tac + THEN' (TRY o + REPEAT_ALL_NEW (match_tac ctxt (rev (Named_Theorems.get ctxt @{named_theorems sep_eintros})))) + THEN_ALL_NEW (dflt_tac ctxt THEN' + TRY o (match_tac ctxt @{thms ent_triv} + ORELSE' resolve_tac ctxt @{thms ent_refl} + ORELSE' match_entails_tac)) + end; + + + (***********************************) + (* Verification Condition Generator*) + (***********************************) + + fun heap_rule_tac ctxt h_thms = + resolve_tac ctxt h_thms ORELSE' ( + resolve_tac ctxt @{thms fi_rule} THEN' (resolve_tac ctxt h_thms THEN_IGNORE_NEWGOALS + frame_inference_tac ctxt)); + + fun vcg_step_tac ctxt = let + val h_thms = rev (Named_Theorems.get ctxt @{named_theorems sep_heap_rules}); + val d_thms = rev (Named_Theorems.get ctxt @{named_theorems sep_decon_rules}); + val heap_rule_tac = heap_rule_tac ctxt h_thms + + (* Apply consequence rule if postcondition is not a schematic var *) + fun app_post_cons_tac i st = + case Logic.concl_of_goal (Thm.prop_of st) i |> HOLogic.dest_Trueprop of + Const (@{const_name Hoare_Triple.hoare_triple},_)$_$_$qt => + if is_Var (head_of qt) then no_tac st + else resolve_tac ctxt @{thms cons_post_rule} i st + | _ => no_tac st; + + in + CSUBGOAL (snd #> (FIRST' [ + CHANGED o dflt_tac ctxt, + REPEAT_ALL_NEW (resolve_tac ctxt @{thms normalize_rules}), + CHANGED o (FIRST' [resolve_tac ctxt d_thms, heap_rule_tac] + ORELSE' (app_post_cons_tac THEN' + FIRST' [resolve_tac ctxt d_thms, heap_rule_tac])) + ])) + end; + + fun vcg_tac ctxt = REPEAT_DETERM' (vcg_step_tac ctxt) + + (***********************************) + (* Automatic Solver *) + (***********************************) + + fun sep_autosolve_tac do_pre do_post ctxt = let + val pre_tacs = [ + CHANGED o clarsimp_tac ctxt, + CHANGED o REPEAT_ALL_NEW (match_tac ctxt @{thms ballI allI impI conjI}) + ]; + val main_tacs = [ + match_tac ctxt @{thms is_hoare_triple} THEN' CHANGED o vcg_tac ctxt, + match_tac ctxt @{thms is_entails} THEN' CHANGED o solve_entails_tac ctxt + ]; + val post_tacs = [SELECT_GOAL (auto_tac ctxt)]; + val tacs = (if do_pre then pre_tacs else []) + @ main_tacs + @ (if do_post then post_tacs else []); + in + REPEAT_DETERM' (CHANGED o FIRST' tacs) + end; + + + (***********************************) + (* Method Setup *) + (***********************************) + + val dflt_simps_modifiers = [ + Args.$$$ "dflt_simps" -- Scan.option Args.add -- Args.colon + >> K (Method.modifier (Named_Theorems.add @{named_theorems sep_dflt_simps}) \<^here>), + Args.$$$ "dflt_simps" -- Scan.option Args.del -- Args.colon + >> K (Method.modifier (Named_Theorems.del @{named_theorems sep_dflt_simps}) \<^here>) + ]; + val heap_modifiers = [ + Args.$$$ "heap" -- Scan.option Args.add -- Args.colon + >> K (Method.modifier (Named_Theorems.add @{named_theorems sep_heap_rules}) \<^here>), + Args.$$$ "heap" -- Scan.option Args.del -- Args.colon + >> K (Method.modifier (Named_Theorems.del @{named_theorems sep_heap_rules}) \<^here>) + ]; + val decon_modifiers = [ + Args.$$$ "decon" -- Scan.option Args.add -- Args.colon + >> K (Method.modifier (Named_Theorems.add @{named_theorems sep_decon_rules}) \<^here>), + Args.$$$ "decon" -- Scan.option Args.del -- Args.colon + >> K (Method.modifier (Named_Theorems.del @{named_theorems sep_decon_rules}) \<^here>) + ]; + + val eintros_modifiers = [ + Args.$$$ "eintros" -- Scan.option Args.add -- Args.colon + >> K (Method.modifier (Named_Theorems.add @{named_theorems sep_eintros}) \<^here>), + Args.$$$ "eintros" -- Scan.option Args.del -- Args.colon + >> K (Method.modifier (Named_Theorems.del @{named_theorems sep_eintros}) \<^here>) + ]; + + + val solve_entails_modifiers = dflt_simps_modifiers @ eintros_modifiers; + + val vcg_modifiers = + heap_modifiers @ decon_modifiers @ dflt_simps_modifiers; + + val sep_auto_modifiers = + clasimp_modifiers @ vcg_modifiers @ eintros_modifiers; + +end; +\ + +simproc_setup assn_simproc + ("h\P" | "P\\<^sub>AQ" | "P\\<^sub>tQ" | "

c " | "(P::assn) = Q") + = \K Seplogic_Auto.assn_simproc_fun\ + +method_setup assn_simp =\Scan.succeed (fn ctxt => (SIMPLE_METHOD' ( + CHANGED o Seplogic_Auto.dflt_tac ctxt +)))\ "Seplogic: Simplification of assertions" + +method_setup frame_inference = \Scan.succeed (fn ctxt => (SIMPLE_METHOD' ( + CHANGED o Seplogic_Auto.frame_inference_tac ctxt +)))\ "Seplogic: Frame inference" + +method_setup solve_entails = \ + Method.sections Seplogic_Auto.solve_entails_modifiers >> + (fn _ => fn ctxt => SIMPLE_METHOD' ( + CHANGED o Seplogic_Auto.solve_entails_tac ctxt +))\ "Seplogic: Entailment Solver" + +method_setup heap_rule = \ + Attrib.thms >> + (fn thms => fn ctxt => SIMPLE_METHOD' ( + let + val thms = case thms of [] => rev (Named_Theorems.get ctxt @{named_theorems sep_heap_rules}) + | _ => thms + in + CHANGED o Seplogic_Auto.heap_rule_tac ctxt thms + end +))\ "Seplogic: Apply rule with frame inference" + + +method_setup vcg = \ + Scan.lift (Args.mode "ss") -- + Method.sections Seplogic_Auto.vcg_modifiers >> + (fn (ss,_) => fn ctxt => SIMPLE_METHOD' ( + CHANGED o ( + if ss then Seplogic_Auto.vcg_step_tac ctxt + else Seplogic_Auto.vcg_tac ctxt + ) +))\ "Seplogic: Verification Condition Generator" + +method_setup sep_auto = + \Scan.lift (Args.mode "nopre" -- Args.mode "nopost" -- Args.mode "plain") + --| Method.sections Seplogic_Auto.sep_auto_modifiers >> + (fn ((nopre,nopost),plain) => fn ctxt => SIMPLE_METHOD' ( + CHANGED o Seplogic_Auto.sep_autosolve_tac + ((not nopre) andalso (not plain)) + ((not nopost) andalso (not plain)) ctxt + ))\ "Seplogic: Automatic solver" + +lemmas [sep_dflt_simps] = split + +declare deconstruct_rules[sep_decon_rules] +declare heap_rules[sep_heap_rules] + +lemmas [sep_eintros] = impI conjI exI + +subsection \Semi-Automatic Reasoning\ +text \In this section, we provide some lemmas for semi-automatic reasoning\ + +text \Forward reasoning with frame. Use \frame_inference\-method + to discharge second assumption.\ +lemma ent_frame_fwd: + assumes R: "P \\<^sub>A R" + assumes F: "Ps \\<^sub>A P*F" + assumes I: "R*F \\<^sub>A Q" + shows "Ps \\<^sub>A Q" + using assms + by (metis ent_refl ent_star_mono ent_trans) + +lemma mod_frame_fwd: + assumes M: "h\Ps" + assumes R: "P\\<^sub>AR" + assumes F: "Ps \\<^sub>A P*F" + shows "h\R*F" + using assms + by (metis ent_star_mono entails_def) + + +text \Apply precision rule with frame inference.\ +lemma prec_frame: + assumes PREC: "precise P" + assumes M1: "h\(R1 \\<^sub>A R2)" + assumes F1: "R1 \\<^sub>A P x p * F1" + assumes F2: "R2 \\<^sub>A P y p * F2" + shows "x=y" + using preciseD[OF PREC] M1 F1 F2 + by (metis entailsD mod_and_dist) + +lemma prec_frame_expl: + assumes PREC: "\x y. (h\(P x * F1) \\<^sub>A (P y * F2)) \ x=y" + assumes M1: "h\(R1 \\<^sub>A R2)" + assumes F1: "R1 \\<^sub>A P x * F1" + assumes F2: "R2 \\<^sub>A P y * F2" + shows "x=y" + using assms + by (metis entailsD mod_and_dist) + + +text \Variant that is useful within induction proofs, where induction + goes over \x\ or \y\\ +lemma prec_frame': + assumes PREC: "(h\(P x * F1) \\<^sub>A (P y * F2)) \ x=y" + assumes M1: "h\(R1 \\<^sub>A R2)" + assumes F1: "R1 \\<^sub>A P x * F1" + assumes F2: "R2 \\<^sub>A P y * F2" + shows "x=y" + using assms + by (metis entailsD mod_and_dist) + + +lemma ent_wand_frameI: + assumes "(Q -* R) * F \\<^sub>A S" + assumes "P \\<^sub>A F * X" + assumes "Q*X \\<^sub>A R" + shows "P \\<^sub>A S" + using assms + by (metis ent_frame_fwd ent_wandI mult.commute) + +subsubsection \Manual Frame Inference\ + +lemma ent_true_drop: + "P\\<^sub>AQ*true \ P*R\\<^sub>AQ*true" + "P\\<^sub>AQ \ P\\<^sub>AQ*true" + apply (metis assn_times_comm ent_star_mono ent_true merge_true_star_ctx) + apply (metis assn_one_left ent_star_mono ent_true star_aci(2)) + done + +lemma fr_refl: "A\\<^sub>AB \ A*C \\<^sub>AB*C" + by (blast intro: ent_star_mono ent_refl) + +lemma fr_rot: "(A*B \\<^sub>A C) \ (B*A \\<^sub>A C)" + by (simp add: assn_aci) + +lemma fr_rot_rhs: "(A \\<^sub>A B*C) \ (A \\<^sub>A C*B)" + by (simp add: assn_aci) + +lemma ent_star_mono_true: + assumes "A \\<^sub>A A' * true" + assumes "B \\<^sub>A B' * true" + shows "A*B*true \\<^sub>A A'*B'*true" + using ent_star_mono[OF assms] apply simp + using ent_true_drop(1) by blast + +lemma ent_refl_true: "A \\<^sub>A A * true" + by (simp add: ent_true_drop(2)) + +lemma entt_fr_refl: "F\\<^sub>tF' \ F*A \\<^sub>t F'*A" by (rule entt_star_mono) auto +lemma entt_fr_drop: "F\\<^sub>tF' \ F*A \\<^sub>t F'" + using ent_true_drop(1) enttD enttI by blast + + +method_setup fr_rot = \ + let + fun rot_tac ctxt = + resolve_tac ctxt @{thms fr_rot} THEN' + simp_tac (put_simpset HOL_basic_ss ctxt + addsimps @{thms star_assoc[symmetric]}) + + in + Scan.lift Parse.nat >> + (fn n => fn ctxt => SIMPLE_METHOD' ( + fn i => REPEAT_DETERM_N n (rot_tac ctxt i))) + + end +\ + +method_setup fr_rot_rhs = \ + let + fun rot_tac ctxt = + resolve_tac ctxt @{thms fr_rot_rhs} THEN' + simp_tac (put_simpset HOL_basic_ss ctxt + addsimps @{thms star_assoc[symmetric]}) + + in + Scan.lift Parse.nat >> + (fn n => fn ctxt => SIMPLE_METHOD' ( + fn i => REPEAT_DETERM_N n (rot_tac ctxt i))) + + end +\ + + + +(*<*) +subsection \Test Cases\ + +lemma "\x. A x * true * Q x \\<^sub>A true * A x * Q x" + apply simp + done + +lemma "A * (true * B) \\<^sub>A true * A * B" + apply (simp) + done + +lemma "h\true*P*true \ h\P*true" + by simp + +lemma "A * true * \(b \ c) * true * B \\<^sub>A \b * \c * true *A * B" + by simp + +lemma "\y c. \\<^sub>Ax. P x * (R x * Q y) * \ (b \ c) \\<^sub>A (\\<^sub>Ax. \b * (P x * (R x * Q y) * \c))" + apply simp + done + +lemma "A * B * (\c * B * C * D * \a * true * \d) * (\\<^sub>Ax. E x * F * \b) * true \\<^sub>A (\\<^sub>Ax. \ (c \ a \ d \ b) * + true * A * B * (true * B * C * D) * (E x * F))" + apply simp + done + +lemma "

c <\r. Q r * true * \(b r) * true * \a> + \

c <\r. Q r * true * \(b r \ a)>" + apply simp + done + + +lemma "(h\((A*B*\b*true*\c*true) \\<^sub>A (\(p=q)*P*Q))) + \ h \ A * B * true \\<^sub>A P * Q \ b \ c \ p = q" + apply simp + done + +lemma assumes "FI_RESULT [(B, B), (A, A)] C D F" + shows "FI_QUERY (A*B*C) (D*B*A) F" + apply (tactic \Seplogic_Auto.match_frame_tac + (resolve_tac @{context} @{thms ent_refl}) @{context} 1\) + by (rule assms) + +lemma + assumes "FI_RESULT [(B,B), (A,A)] C emp F" + shows "FI_QUERY (A*B*C) (B*A) F" + apply (tactic \Seplogic_Auto.match_frame_tac + (resolve_tac @{context} @{thms ent_refl}) @{context} 1\) + by (rule assms) + +lemma + assumes "FI_RESULT [(B, B), (A, A)] emp emp F" + shows "FI_QUERY (A*B) (B*A) F" + apply (tactic \Seplogic_Auto.match_frame_tac + (resolve_tac @{context} @{thms ent_refl}) @{context} 1\) + by (rule assms) + +lemma + assumes "FI_RESULT [(A, A)] emp emp F" + shows "FI_QUERY (A) (A) F" + apply (tactic \Seplogic_Auto.match_frame_tac + (resolve_tac @{context} @{thms ent_refl}) @{context} 1\) + by (rule assms) + +lemma + assumes "FI_RESULT [(A, A)] (B * C * D) emp F" + shows "FI_QUERY (B*C*D*A) (A) F" + apply (tactic \Seplogic_Auto.match_frame_tac + (resolve_tac @{context} @{thms ent_refl}) @{context} 1\) + by (rule assms) + + +schematic_goal + "P1 * P2 * P3 * P4 \\<^sub>A P3 * ?R1" + "P1 * (P2 * (P3 * P4)) \\<^sub>A P1 * ?R2" + "P4 * (P2 * (P1 * P3)) \\<^sub>A P1 * ?R2'" + "P1 * P2 * P3 * P4 \\<^sub>A P4 * ?R3" + "P1 * P2 \\<^sub>A P1 * ?R4" + "P1 * P2 \\<^sub>A P2 * ?R5" + "P1 \\<^sub>A P1 * ?R6" + "P1 * P2 \\<^sub>A emp * ?R7" + by frame_inference+ + + +lemma "\A; B; C; b 17\ \ + Q 1 5 3 \\<^sub>A (\\<^sub>Ax y z. \\<^sub>Aa. Q x y z * \(b a) * \(y=5))" + by solve_entails + +thm nth_rule +lemma "

\<^sub>a[1,2,3]> + do { v\Array_Time.nth x 1; return v } + <\r. P * x\\<^sub>a[1,2,3] * \(r=2)>" + apply sep_auto + done + +(*>*) + +subsection \Quick Overview of Proof Methods\ + text_raw \\label{sec:auto:overview}\ +text \ + In this section, we give a quick overview of the available proof methods + and options. The most versatile proof method that we provide is + \sep_auto\. It tries to solve the first subgoal, invoking appropriate + proof methods as required. If it cannot solve the subgoal completely, it + stops at the intermediate state that it could not handle any more. + + \sep_auto\ can be configured by + section-arguments for the simplifier, the classical reasoner, and all + section-arguments for the verification condition generator and + entailment solver. Moreover, it takes an optional mode argument (mode), where + valid modes are: + \begin{description} + \item[(nopre)] No preprocessing of goal. The preprocessor tries to clarify + and simplify the goal before the main method is invoked. + \item[(nopost)] No postprocessing of goal. The postprocessor tries to + solve or simplify goals left over by verification condition generation or + entailment solving. + \item[(plain)] Neither pre- nor postprocessing. Just applies vcg and + entailment solver. + \end{description} + + \paragraph{Entailment Solver.} The entailment solver processes goals of the + form \P \\<^sub>A Q\. It is invoked by the method \solve_entails\. + It first tries to pull out pure parts of + \P\ and \Q\. This may introduce quantifiers, conjunction, + and implication into the goal, that are eliminated by resolving with rules + declared as \sep_eintros\ (method argument: eintros[add/del]:). + Moreover, it simplifies with rules declared as \sep_dflt_simps\ + (section argument: \dflt_simps[add/del]:\). + + Now, \P\ and \Q\ should have the form \X\<^sub>1*\*X\<^sub>n\. + Then, the frame-matcher is used to match all items of \P\ with items + of \Q\, and thus solve the implication. Matching is currently done + syntactically, but can instantiate schematic variables. + + Note that, by default, existential introduction is declared as + \sep_eintros\-rule. This introduces schematic variables, that can + later be matched against. However, in some cases, the matching may instantiate + the schematic variables in an undesired way. In this case, the argument + \eintros del: exI\ should be passed to the entailment solver, and + the existential quantifier should be instantiated manually. + + \paragraph{Frame Inference} + The method \frame_inference\ tries to solve a goal of the + form \P\Q*?F\, by matching \Q\ against the parts of + \P\, and instantiating \?F\ accordingly. + Matching is done syntactically, possibly + instantiating schematic variables. \P\ and \Q\ should be + assertions separated by \*\. Note that frame inference does no + simplification or other kinds of normalization. + + The method \heap_rule\ applies the specified heap rules, using + frame inference if necessary. If no rules are specified, the default + heap rules are used. + + \paragraph{Verification Condition Generator} + The verification condition generator processes goals of the form + \

c\. It is invoked by the method \vcg\. + First, it tries to pull out pure parts and simplifies with + the default simplification rules. Then, it tries to resolve the goal with + deconstruct rules (attribute: \sep_decon_rules\, + section argument: \decon[add/del]:\), and if this does not succeed, + it tries + to resolve the goal with heap rules (attribute: \sep_heap_rules\, + section argument: \heap[add/del]:\), using the frame rule and + frame inference. + If resolving is not possible, it also tries to apply the consequence rule to + make the postcondition a schematic variable. +\ + + +(*<*) +subsection \Hiding of internal stuff\ +hide_const (open) FI SLN +(*>*) + +end diff --git a/thys/Van_Emde_Boas_Trees/Separation_Logic_Imperative_HOL/Hoare_Triple.thy b/thys/Van_Emde_Boas_Trees/Separation_Logic_Imperative_HOL/Hoare_Triple.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/Separation_Logic_Imperative_HOL/Hoare_Triple.thy @@ -0,0 +1,517 @@ +section \Hoare-Triples\ +theory Hoare_Triple +imports Assertions +begin + +text \In this theory, we define Hoare-Triples, which are our basic tool + for specifying properties of Imperative HOL programs.\ + +subsection \Definition\ + +text \Analyze the heap before and after executing a command, to add + the allocated addresses to the covered address range.\ +definition new_addrs :: "heap \ addr set \ heap \ addr set" where + "new_addrs h as h' = as \ {a. lim h \ a \ a < lim h'}" + +lemma new_addr_refl[simp]: "new_addrs h as h = as" + unfolding new_addrs_def by auto + +text \ + Apart from correctness of the program wrt. the pre- and post condition, + a Hoare-triple also encodes some well-formedness conditions of the command: + The command must not change addresses outside the address range of the + precondition, and it must not decrease the heap limit. + + Note that we do not require that the command only reads from heap locations + inside the precondition's address range, as this condition would be quite + complicated to express with the heap model of Imperative/HOL, and is not + necessary in our formalization of partial heaps, that always contain the + information for all addresses. +\ + +definition hoare_triple + :: "assn \ 'a Heap \ ('a \ assn) \ bool" ("<_>/ _/ <_>") + where + "

c \ \h as. (h,as)\P \ (\r h' t. execute c h = Some (r,h',t) + \ (let as'=new_addrs h as h' in + (h',as')\Q r \ relH ({a . a a\as}) h h' + \ lim h \ lim h'))" + + +text \Sanity checking theorems for Hoare-Triples\ +lemma + assumes "

c " + assumes "(h,as)\P" + shows hoare_triple_success: "success c h" + and hoare_triple_effect: "\h' r t. effect c h h' r t \ (h',new_addrs h as h')\Q r" + using assms + unfolding hoare_triple_def success_def effect_def + apply - + apply (auto simp: Let_def) apply fastforce+ done + + +lemma hoare_tripleE: + assumes "

c " + assumes "(h,as)\P" + obtains r h' t where + "execute c h = Some (r,h',t)" + "(h',new_addrs h as h')\Q r" + "relH ({a . a a\as}) h h'" + "lim h \ lim h'" + using assms + unfolding hoare_triple_def Let_def + by blast + +lemma hoare_tripleI[intro?]: + assumes "\h as. (h,as)\P \ (\r h' t. + execute c h = Some (r,h',t) + \ (h',new_addrs h as h') \ Q r + \ relH ({a . a a\as}) h h' + \ lim h \ lim h' + )" + shows "

c " + using assms unfolding hoare_triple_def Let_def + by blast + + + +(*lemma hoare_tripleD: + fixes h h' as as' r + assumes "

c " + assumes "(h,as)\P" + assumes "execute c h = Some (r,h')" + defines "as'\new_addrs h as h'" + shows "(h',as')\Q r" + and "relH ({a . a a\as}) h h'" + and "lim h \ lim h'" + using assms + unfolding hoare_triple_def as'_def + apply (auto simp: Let_def) +*) + +text \For garbage-collected languages, specifications usually allow for some + arbitrary heap parts in the postcondition. The following abbreviation defines + a handy shortcut notation for such specifications.\ +abbreviation hoare_triple' + :: "assn \ 'r Heap \ ('r \ assn) \ bool" ("<_> _ <_>\<^sub>t") + where "

c \<^sub>t \

c <\r. Q r * true>" + +subsection \Rules\ +text \ + In this section, we provide a set of rules to prove Hoare-Triples correct. +\ +subsubsection \Basic Rules\ + + +lemma hoare_triple_preI: + assumes "\h. h\P \

c " + shows "

c " + using assms + unfolding hoare_triple_def + by auto + +lemma frame_rule: + assumes A: "

c " + shows " c <\x. Q x * R>" + unfolding hoare_triple_def Let_def + apply (intro allI impI) +proof - + fix h as + assume "(h,as) \ P * R" + then obtain as1 as2 where [simp]: "as=as1\as2" and DJ: "as1\as2={}" + and M1: "(h,as1)\P" and M2: "(h,as2)\R" + by (auto simp: mod_star_conv) + + + from hoare_tripleE[OF A M1] obtain r h' t where + EX: "execute c h = Some (r, h',t)" + and MDL: "(h', new_addrs h as1 h') \ Q r" + and RH1: "relH {a. a < lim h \ a \ as1} h h'" + and "lim h \ lim h'" + . + + have "{a. a < lim h \ a \ as} \ {a. a < lim h \ a \ as1}" + by auto + then have "relH {a. a < lim h \ a \ as} h h'" using RH1 + by (blast intro: relH_subset) + + have DJN: "new_addrs h as1 h' \ as2 = {}" + using DJ models_in_range[OF M2] + by (auto simp: in_range.simps new_addrs_def) + moreover have "as2 \ {a. a < lim h \ a \ as1}" + using DJ models_in_range[OF M2] + by (auto simp: in_range.simps) + hence "relH as2 h h'" using RH1 + by (blast intro: relH_subset) + with M2 have "(h', as2)\R" + by (metis mem_Collect_eq Rep_assn + proper_iff relH_in_rangeI(2)) + moreover have "new_addrs h as h' + = new_addrs h as1 h' \ as2" + by (auto simp: new_addrs_def) + ultimately have + M: "(h', new_addrs h as h') \ Q r * R" + using MDL + unfolding times_assn_def + apply (simp add: Abs_assn_inverse) + apply blast + done + + show "\r h' t. + execute c h = Some (r, h',t) \ + (h', new_addrs h as h') \ Q r * R \ relH {a. a < lim h \ a \ as} h h' \ lim h \ lim h'" + apply (rule exI[where x=r]) + apply (rule exI[where x=h']) + apply (rule exI[where x=t]) + apply safe + apply fact + apply fact + apply fact + apply fact + done +qed + + +lemma false_rule[simp, intro!]: " c " + unfolding hoare_triple_def by simp + + +lemma cons_rule: + assumes CPRE: "P \\<^sub>A P'" + assumes CPOST: "\x. Q x \\<^sub>A Q' x" + assumes R: " c " + shows "

c " + using assms + unfolding hoare_triple_def Let_def + using entailsD by blast + + +lemmas cons_pre_rule = cons_rule[OF _ ent_refl] +lemmas cons_post_rule = cons_rule[OF ent_refl, rotated] + +lemma cons_rulet: "\P\\<^sub>tP'; \x. Q x \\<^sub>t Q' x; c \<^sub>t \ \

c \<^sub>t" + unfolding entailst_def + apply (rule cons_pre_rule) + apply assumption + apply (rule cons_post_rule) + apply (erule frame_rule) + by (simp add: enttD enttI) + +lemmas cons_pre_rulet = cons_rulet[OF _ entt_refl] +lemmas cons_post_rulet = cons_rulet[OF entt_refl, rotated] + + + +lemma norm_pre_ex_rule: + assumes A: "\x.

f " + shows "<\\<^sub>Ax. P x> f " + unfolding hoare_triple_def Let_def + apply (intro allI impI, elim conjE mod_exE) + using assms hoare_tripleE by fastforce + +lemma norm_pre_pure_iff[simp]: + "b> f \ (b \

f )" + unfolding hoare_triple_def Let_def + by auto + +lemma norm_pre_pure_iff_sng[simp]: + "<\b> f \ (b \ f )" + using norm_pre_pure_iff[where P=emp] + by simp + +lemma norm_pre_pure_rule1: + "\b \

f \ \ b> f " by simp + +lemma norm_pre_pure_rule2: + "\ b \ f \ \ <\b> f " by simp + +lemmas norm_pre_pure_rule = norm_pre_pure_rule1 norm_pre_pure_rule2 + +lemma post_exI_rule: "

c <\r. Q r x> \

c <\r. \\<^sub>Ax. Q r x>" + by (blast intro: cons_post_rule ent_ex_postI ent_refl) + + + +subsubsection \Rules for Time Commands\ +lemma wait_rule: " wait n <\_. emp>" + apply rule + apply (simp add: execute_simps) + by (simp add: in_range.simps relH_refl) + +lemma wait_bind_decon: "

m \

do {wait n; m} " + apply rule + apply (auto elim!: hoare_tripleE simp: execute_simps) + done + + + +subsubsection \Rules for Atomic Commands\ +lemma ref_rule: + " ref x <\r. r \\<^sub>r x>" + unfolding one_assn_def sngr_assn_def hoare_triple_def + apply (simp add: Let_def Abs_assn_inverse) + apply (simp add: execute_simps) + apply (auto + simp: new_addrs_def Ref_Time.alloc_def Let_def + Ref_Time.set_def Ref_Time.get_def relH_def in_range.simps) + done + +lemma lookup_rule: + "

\<^sub>r x> !p <\r. p \\<^sub>r x * \(r = x)>" + unfolding hoare_triple_def sngr_assn_def + apply (simp add: Let_def Abs_assn_inverse) + apply (simp add: execute_simps) + apply (auto elim: simp add: relH_refl in_range.simps new_addrs_def) + done + +lemma update_rule: + "

\<^sub>r y> p := x <\r. p \\<^sub>r x>" + unfolding hoare_triple_def sngr_assn_def + apply (simp add: execute_simps) + apply (auto elim!: + simp: Let_def Abs_assn_inverse new_addrs_def in_range.simps + intro!: relH_set_ref) + done + +lemma update_wp_rule: + "\<^sub>r y * ((r \\<^sub>r x) -* (Q ()))> r := x " + apply (rule cons_post_rule) + apply (rule frame_rule[OF update_rule[where p=r and x=x], + where R="((r \\<^sub>r x) -* (Q ()))"]) + apply (rule ent_trans) + apply (rule ent_mp) + by simp + +lemma new_rule: + " Array_Time.new n x <\r. r \\<^sub>a replicate n x>" + unfolding hoare_triple_def snga_assn_def one_assn_def + apply (simp add: Let_def Abs_assn_inverse) + apply (simp add: execute_simps) + apply (auto + simp: Let_def new_addrs_def Array_Time.get_def Array_Time.set_def Array_Time.alloc_def + relH_def in_range.simps + ) + done + +lemma make_rule: " Array_Time.make n f <\r. r \\<^sub>a (map f [0 ..< n])>" + unfolding hoare_triple_def snga_assn_def one_assn_def + apply (simp add: Let_def Abs_assn_inverse) + apply (simp add: execute_simps) + apply (auto + simp: Let_def new_addrs_def Array_Time.get_def Array_Time.set_def Array_Time.alloc_def + relH_def in_range.simps + ) + done + +lemma of_list_rule: " Array_Time.of_list xs <\r. r \\<^sub>a xs>" + unfolding hoare_triple_def snga_assn_def one_assn_def + apply (simp add: Let_def Abs_assn_inverse) + apply (simp add: execute_simps) + apply (auto + simp: Let_def new_addrs_def Array_Time.get_def Array_Time.set_def Array_Time.alloc_def + relH_def in_range.simps + ) + by (simp add: map_idI) + +lemma length_rule: + "\<^sub>a xs> Array_Time.len a <\r. a \\<^sub>a xs * \(r = length xs)>" + unfolding hoare_triple_def snga_assn_def + apply (simp add: Let_def Abs_assn_inverse) + apply (simp add: execute_simps) + apply (auto + simp: Let_def new_addrs_def Array_Time.get_def Array_Time.set_def Array_Time.alloc_def + relH_def in_range.simps Array_Time.length_def + ) + done + +text \Note that the Boolean expression is placed at meta level and not + inside the precondition. This makes frame inference simpler.\ +lemma nth_rule: + "\i < length xs\ \ \<^sub>a xs> Array_Time.nth a i <\r. a \\<^sub>a xs * \(r = xs ! i)>" + unfolding hoare_triple_def snga_assn_def + apply (simp add: Let_def Abs_assn_inverse) + apply (auto + simp: Let_def new_addrs_def Array_Time.get_def Array_Time.set_def Array_Time.alloc_def + relH_def in_range.simps Array_Time.length_def + execute_simps + ) + done + +lemma upd_rule: + "\i < length xs\ \ + \<^sub>a xs> + Array_Time.upd i x a + <\r. (a \\<^sub>a (list_update xs i x)) * \(r = a)>" + unfolding hoare_triple_def snga_assn_def + apply (simp add: Let_def Abs_assn_inverse) + apply (auto + simp: Let_def new_addrs_def Array_Time.get_def Array_Time.set_def Array_Time.alloc_def + relH_def in_range.simps Array_Time.length_def Array_Time.update_def comp_def + execute_simps + ) + done + +lemma freeze_rule: + "\<^sub>a xs> Array_Time.freeze a <\r. a \\<^sub>a xs * \(r = xs)>" + unfolding hoare_triple_def snga_assn_def + apply (simp add: Let_def Abs_assn_inverse) + apply (auto + simp: Let_def new_addrs_def Array_Time.get_def Array_Time.set_def Array_Time.alloc_def + relH_def in_range.simps Array_Time.length_def Array_Time.update_def + execute_simps + ) + done + +lemma return_wp_rule: + " return x " + unfolding hoare_triple_def Let_def + apply (auto simp: execute_simps) + apply (rule relH_refl) + apply (simp add: in_range.simps) + done + +lemma return_sp_rule: + "

return x <\r. P * \(r = x)>" + unfolding hoare_triple_def Let_def + apply (simp add: Abs_assn_inverse) + apply (auto intro!: relH_refl intro: models_in_range simp: execute_simps) + apply (simp add: in_range.simps) + done + +lemma raise_iff: + "

raise s \ P = false" + unfolding hoare_triple_def Let_def + apply (rule iffI) + apply (unfold bot_assn_def) [] + apply rule + apply (auto simp add: execute_simps) [] + + apply (auto simp add: execute_simps) [] + done + +lemma raise_rule: " raise s " + by (simp add: raise_iff) + +subsubsection \Rules for Composed Commands\ +lemma bind_rule: + assumes T1: "

f " + assumes T2: "\x. g x " + shows "

bind f g " +proof + fix h as + assume "(h, as) \ P" + + from hoare_tripleE[OF T1 this] obtain rf h' t' where + EX_F: "execute f h = Some (rf, h',t')" + and POST_F: "(h', new_addrs h as h') \ R rf" + and RH_F: "relH {a. a < lim h \ a \ as} h h'" + and LIM_F: "lim h \ lim h'" + . + + from hoare_tripleE[OF T2 POST_F] obtain rg h'' t'' where + EX_G: "execute (g rf) h' = Some (rg, h'',t'')" + and POST_G: "(h'', new_addrs h' (new_addrs h as h') h'') \ Q rg" + and RH_G: "relH {a. a < lim h' \ a \ new_addrs h as h'} h' h''" + and LIM_G: "lim h' \ lim h''" + . + + have + "new_addrs + h' + (new_addrs h as h') + h'' + = new_addrs h as h''" + using LIM_F LIM_G + by (auto simp add: new_addrs_def) + with POST_G have + "(h'', new_addrs h as h'') \ Q rg" + by simp + + note RH_F + also have "relH {a. a < lim h \ a \ as} h' h''" + apply (rule relH_subset[OF RH_G]) + using LIM_F LIM_G + by (auto simp: new_addrs_def) + finally have "relH {a. a < lim h \ a \ as} h h''" . + + note LIM_F + also note LIM_G + finally have "lim h \ lim h''" . + + + show "\r h' t'. + execute (f \ g) h = Some (r, h',t') \ + (h', new_addrs h as h') \ Q r \ relH {a. a < lim h \ a \ as} h h' \ lim h \ lim h'" + apply (intro exI conjI) + apply (simp add: EX_F EX_G execute_simps; fail) + apply fact+ + done +qed + +lemma bind_rule' : + assumes T1: "\ r.

f <\ r. (P * R r) >" + assumes T2: "\x. g x " + shows "

bind f g " + by (metis (no_types, lifting) T1 T2 ab_semigroup_mult_class.mult.commute bind_rule) + + +lemma if_rule: + assumes "b \

f " + assumes "\b \

g " + shows "

if b then f else g " + using assms by auto + +lemma if_rule_split: + assumes B: "b \

f " + assumes NB: "\b \

g " + assumes M: "\x. (Q1 x * \b) \\<^sub>A (Q2 x * \(\b)) \\<^sub>A Q x" + shows "

if b then f else g " + apply (cases b) + apply simp_all + apply (rule cons_post_rule) + apply (erule B) + apply (rule ent_trans[OF _ ent_disjI1[OF M]]) + apply simp + + apply (rule cons_post_rule) + apply (erule NB) + apply (rule ent_trans[OF _ ent_disjI2[OF M]]) + apply simp + done + +lemma split_rule: + assumes P: "

c " + assumes Q: " c " + shows "

\<^sub>A Q> c " + apply rule + using assms + apply (auto elim!: hoare_tripleE) + done + +lemmas decon_if_split = if_rule_split split_rule + \ \Use with care: Complete splitting of if statements\ + +lemma case_prod_rule: + "(\a b. x = (a, b) \

f a b ) \

case x of (a, b) \ f a b " + by (auto split: prod.split) + +lemma case_list_rule: + "\ l=[] \

fn ; \x xs. l=x#xs \

fc x xs \ \ +

case_list fn fc l " + by (auto split: list.split) + +lemma case_option_rule: + "\ v=None \

fn ; \x. v=Some x \

fs x \ + \

case_option fn fs v " + by (auto split: option.split) + +lemma case_sum_rule: + "\ \x. v=Inl x \

fl x ; + \x. v=Inr x \

fr x \ + \

case_sum fl fr v " + by (auto split: sum.split) + +lemma let_rule: "(\x. x = t \

f x ) \

Let t f " + by (auto) + +end diff --git a/thys/Van_Emde_Boas_Trees/Separation_Logic_Imperative_HOL/Refine_Imp_Hol.thy b/thys/Van_Emde_Boas_Trees/Separation_Logic_Imperative_HOL/Refine_Imp_Hol.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/Separation_Logic_Imperative_HOL/Refine_Imp_Hol.thy @@ -0,0 +1,144 @@ +section \Refinement for Imperative-HOL Programs\ +theory Refine_Imp_Hol + imports "Hoare_Triple" + "HOL-Eisbach.Eisbach" +begin + + subsection \Assertions\ + + text \We add assertions that consume no time to Imperative HOL Time. + + Note that the original \<^const>\assert\ consumes one time unit, i.e., is designed for + actually being checked at runtime. On the other hand, our assertions are not executable, + and must be refined before code generation. + \ + definition [code del]: "assert' P \ if P then ureturn () else raise ''assert''" + + lemma execute_assert'[execute_simps]: "execute (assert' P) h = (if P then Some ((),h,0) else None)" + by (auto simp: assert'_def execute_simps) + + + lemma assert'_rule: "\\h. h\P \ \\ \

assert' \ <\_. P>" + apply rule + apply (auto simp: execute_simps in_range.simps relH_refl) + done + + lemma assert'_bind_rule: + assumes "\h. h\P \ \" + assumes "\ \

c " + shows "

do {assert' \; c} " + apply rule + using assms + apply (auto simp: execute_simps in_range.simps relH_refl elim!: hoare_tripleE) + done + + subsection \Refinement Predicate\ + text \An imperative-HOL program \p\ refines a program \q\, if either \q\ fails, or \p\ returns the + same result as \q\. In case \q\ is already proved correct (in particular does not fail), this + implies correctness of \p\. Moreover, for the refinement proof, we can assume that \q\ does not fail, + in particular, that all assertions in \q\ hold. This can be used to transfer knowledge from the + correctness proof (proving the assertions) to the refinement proof (assuming the assertions). + \ + definition "refines p q \ \h. case execute q h of None \ True | Some (r,h',t) \ execute p h = Some (r,h',t)" + + lemma hoare_triple_refines: + assumes "

c " + assumes "refines c' c" + shows "

c' " + apply rule + using assms + by (auto simp: refines_def elim!: hoare_tripleE split: option.splits) + + + subsubsection \Admissibility\ + context begin + + private lemma refines_adm_aux: "option.admissible (\xa. \h a aa b. xa h = Some (a, aa, b) \ execute (t x) h = Some (a, aa, b))" + proof- + have "option.admissible (\xa. \h y. xa h = Some y \ execute (t x) h = Some y)" + using option_admissible by metis + thus ?thesis by auto + qed + + lemma refines_adm: "heap.admissible (\f. \x. refines (t x) (f x) )" + unfolding refines_def + apply (rule admissible_fun[OF heap_interpretation]) + + unfolding Heap_lub_def Heap_ord_def + apply (rule admissible_image) + using option.partial_function_definitions_axioms partial_function_lift apply auto[1] + apply(simp split: option.splits) + apply auto[3] + subgoal for x + apply (simp add: comp_def) + apply(rule refines_adm_aux) + done + subgoal for xa y + apply (metis Heap_execute) + done + done + + end + + subsection \Syntactic rules for \<^const>\refines\\ + + named_theorems refines_rule + + lemma refines_assert'[refines_rule]: "refines (ureturn ()) (assert' \)" + unfolding refines_def + by (simp add: execute_simps) + + lemma refines_assert'_bind[refines_rule]: "refines p q \ refines p (do {assert' \; q})" + unfolding refines_def + apply (cases \) + apply (auto simp add: execute_simps split: option.splits) + done + + lemma refines_bind[refines_rule]: "refines m m' \ (\x. refines (f x) (f' x)) \ refines (do {x\m; f x}) (do {x\m'; f' x})" + unfolding refines_def + apply clarsimp + subgoal for h + apply (cases "execute m' h"; cases "execute m h") + apply (auto simp add: execute_simps split: option.splits) + by (smt (verit, best) option.case(2) prod.simps(2) timeFrame.elims) + done + + lemma refines_If[refines_rule]: "\b\refines t t'\ \ \\b\refines e e'\ \ refines (If b t e) (If b t' e')" by auto + lemma refines_Let[refines_rule]: "\ \x. \x=v\ \ refines (f x) (f' x) \ \ refines (let x=v in f x) (let x=v in f' x)" by auto + + + lemma refines_refl: "refines p p" + unfolding refines_def + by (auto split: option.splits) + + lemma refines_empty[simp]: "refines m (Heap.Heap Map.empty)" + apply(simp add: refines_def) + done + + lemma refines_let_right: assumes "refines m (m' a)" + shows "refines m (let x = a in m' x)" + using assms by simp + + lemma refines_case_prod_right: assumes "\ a b. refines m (m' a b)" + shows "refines m (case t of (a,b) \ m' a b)" + using assms apply(cases t) + by simp + + lemma refines_option[refines_rule]: assumes "a=a'" "refines m1 m1'" "\ x. refines (m2 x) (m2' x)" + shows "refines (case a of None \ m1 | Some x \ m2 x) (case a' of None \ m1' | Some x \ m2' x)" + using assms apply(cases a') + apply simp_all + done + + lemma prod_case_refines[refines_rule]: assumes "p= p'" " \ a b. refines (f a b) (f' a b)" + shows " refines (case p of (a, b) \ f a b) (case p' of (a, b) \ f' a b )" + using assms apply(cases p') by simp + +subsection \Automation\ + + method refines_step= determ\rule refines_rule refl refines_refl refines_let_right refines_case_prod_right + | assumption | simp only:\ + + method refines = refines_step+ + +end diff --git a/thys/Van_Emde_Boas_Trees/Separation_Logic_Imperative_HOL/Sep_Main.thy b/thys/Van_Emde_Boas_Trees/Separation_Logic_Imperative_HOL/Sep_Main.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/Separation_Logic_Imperative_HOL/Sep_Main.thy @@ -0,0 +1,7 @@ +section \Separation Logic Framework Entrypoint\ +theory Sep_Main +imports Automation +begin + text \Import this theory to make available Imperative/HOL with + separation logic.\ +end diff --git a/thys/Van_Emde_Boas_Trees/Separation_Logic_Imperative_HOL/Tools/Imperative_HOL_Add.thy b/thys/Van_Emde_Boas_Trees/Separation_Logic_Imperative_HOL/Tools/Imperative_HOL_Add.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/Separation_Logic_Imperative_HOL/Tools/Imperative_HOL_Add.thy @@ -0,0 +1,57 @@ +section \Additions to Imperative/HOL\ +theory Imperative_HOL_Add +imports "HOL-Imperative_HOL.Imperative_HOL" +begin + +text \This theory loads the Imperative HOL framework and provides + some additional lemmas needed for the separation logic framework.\ + +text \A stronger elimination rule for \ref\\ + +lemma effect_ref[effect_elims]: + assumes "effect (ref (x::('a::heap))) h h' r" + obtains "r = fst (Ref.alloc x h)" and "h' = snd (Ref.alloc x h)" +proof - + from assms have "execute (ref x) h = Some (r, h')" by (unfold effect_def) + then have "r = fst (Ref.alloc x h)" "h' = snd (Ref.alloc x h)" + by (auto simp add: execute_simps) + then show thesis .. +qed + + +text \Some lemmas about the evaluation of the limit for modifications on + a heap\ + +lemma lim_Ref_alloc[simp]: "lim (snd (Ref.alloc x h)) = Suc (lim h)" + unfolding Ref.alloc_def + by (simp add: Let_def) + +lemma lim_Array_alloc[simp]: "lim (snd (Array.alloc x h)) = Suc (lim h)" + unfolding Array.alloc_def Array.set_def + by (simp add: Let_def) + + +lemma lim_Array_set[simp]: "lim (Array.set a xs h) = lim h" + unfolding Array.set_def + by (simp add: Let_def) + +thm Array.update_def +lemma lim_Array_update[simp]: "lim (Array.update a i x h) = lim h" + unfolding Array.update_def + by (simp add: Let_def) + + +text \Simplification rules for the addresses of new allocated arrays and + references\ + +lemma addr_of_ref_alloc[simp]: + "addr_of_ref (fst (Ref.alloc x h)) = lim h" + unfolding Ref.alloc_def + by (simp add: Let_def) + +lemma addr_of_array_alloc[simp]: + "addr_of_array (fst (Array.alloc x h)) = lim h" + unfolding Array.alloc_def + by (simp add: Let_def) + +end diff --git a/thys/Van_Emde_Boas_Trees/Separation_Logic_Imperative_HOL/Tools/Syntax_Match.thy b/thys/Van_Emde_Boas_Trees/Separation_Logic_Imperative_HOL/Tools/Syntax_Match.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/Separation_Logic_Imperative_HOL/Tools/Syntax_Match.thy @@ -0,0 +1,113 @@ +section \Syntactic Matching in the Simplifier\ +theory Syntax_Match +imports Main +begin + +subsection \Non-Matching\ + +text \ + We define the vebt_predicates \syntax_nomatch\ + and \syntax_fo_nomatch\. The expression + \syntax_nomatch pattern object\ is simplified to true only if + the term \pattern\ syntactically matches the term \object\. + Note that, semantically, \syntax_nomatch pattern object\ is always + true. While \syntax_nomatch\ does higher-order matching, + \syntax_fo_nomatch\ does first-order matching. + + The intended application of these vebt_predicates are as guards for simplification + rules, enforcing additional syntactic restrictions on the applicability of + the simplification rule. +\ +definition syntax_nomatch :: "'a \ 'b \ bool" + where syntax_nomatch_def: "syntax_nomatch pat obj \ True" +definition syntax_fo_nomatch :: "'a \ 'b \ bool" + where syntax_fo_nomatch_def: "syntax_fo_nomatch pat obj \ True" + +(* Prevent simplifier to simplify inside syntax_xx vebt_predicates *) +lemma [cong]: "syntax_fo_nomatch x y = syntax_fo_nomatch x y" by simp +lemma [cong]: "syntax_nomatch x y = syntax_nomatch x y" by simp + +ML \ +structure Syntax_Match = struct + val nomatch_thm = @{thm syntax_nomatch_def}; + val fo_nomatch_thm = @{thm syntax_fo_nomatch_def}; + + fun fo_nomatch_simproc ctxt credex = let + (*val ctxt = Simplifier.the_context ss;*) + val thy = Proof_Context.theory_of ctxt; + + val redex = Thm.term_of credex; + val (_,[pat,obj]) = strip_comb redex; + + fun fo_matches po = (Pattern.first_order_match + thy po (Vartab.empty, Vartab.empty); true) handle Pattern.MATCH => false; + in + if fo_matches (pat,obj) then NONE else SOME fo_nomatch_thm + end + + fun nomatch_simproc ctxt credex = let + (*val ctxt = Simplifier.the_context ss;*) + val thy = Proof_Context.theory_of ctxt; + + val redex = Thm.term_of credex; + val (_,[pat,obj]) = strip_comb redex; + in + if Pattern.matches thy (pat,obj) then NONE else SOME nomatch_thm + end +end +\ +simproc_setup nomatch ("syntax_nomatch pat obj") + = \K Syntax_Match.nomatch_simproc\ +simproc_setup fo_nomatch ("syntax_fo_nomatch pat obj") + = \K Syntax_Match.fo_nomatch_simproc\ + + +subsection \Examples\ +subsubsection \Ordering AC-structures\ +text \ + Currently, the simplifier rules for ac-rewriting only work when + associativity groups to the right. Here, we define rules that work for + associativity grouping to the left. They are useful for operators where + syntax is parsed (and pretty-printed) left-associative. +\ + +locale ac_operator = + fixes f + assumes right_assoc: "f (f a b) c = f a (f b c)" + assumes commute: "f a b = f b a" +begin + lemmas left_assoc = right_assoc[symmetric] + lemma left_commute: "f a (f b c) = f b (f a c)" + apply (simp add: left_assoc) + apply (simp add: commute) + done + + lemmas right_ac = right_assoc left_commute commute + + lemma right_commute: "f (f a b) c = f (f a c) b" + by (simp add: right_ac) + + lemma safe_commute: "syntax_fo_nomatch (f x y) a \ f a b = f b a" + by (simp add: right_ac) + + lemmas left_ac = left_assoc right_commute safe_commute +end + +interpretation mult: ac_operator "(*) ::'a::ab_semigroup_mult \ _ \ _" + apply unfold_locales + apply (simp_all add: ac_simps) + done + +interpretation add: ac_operator "(+) ::'a::ab_semigroup_add \ _ \ _" + apply unfold_locales + apply (simp_all add: ac_simps) + done + +text \Attention: \conj_assoc\ is in standard simpset, it has to be + removed when using \conj.left_ac\ !\ +interpretation conj: ac_operator "(\)" + by unfold_locales auto +interpretation disj: ac_operator "(\)" + by unfold_locales auto + +end diff --git a/thys/Van_Emde_Boas_Trees/Time_Reasoning/Simple_TBOUND_Cond.thy b/thys/Van_Emde_Boas_Trees/Time_Reasoning/Simple_TBOUND_Cond.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/Time_Reasoning/Simple_TBOUND_Cond.thy @@ -0,0 +1,80 @@ +(*by Ammer*) +theory Simple_TBOUND_Cond +imports Time_Reasoning +begin + +text \This entry stops at showing the correctness and complexity of the operations, + but does not provide a complete or universally usable methods to reason about + programs using these operations. + + In this theory, we provide an ad-hoc method, which is showcased + with a simple example later on. +\ + +text \definition of conditional TBOUND relation and setup\ + +definition cond_TBOUND::"assn \ 'a Heap \ nat\ bool"("\

_ \
/ TBOUND/ _ _") where + "cond_TBOUND P c t \ (\h as. (h,as) \ P \ time c h \ t)" + +named_theorems cond_TBOUND + +lemma htt_elim: + assumes "

c T[b]" + shows "\

P\
TBOUND c b" + using assms + unfolding htt_def cond_TBOUND_def by simp + +lemma htt_intro: + assumes "

c " + and "\

P\
TBOUND c b" + shows "

c T[b]" + using assms unfolding htt_def cond_TBOUND_def by simp + +lemma cond_TBOUND_mono: "\

P\
TBOUND c b \ b \ b' \ \
P\
TBOUND c b'" + unfolding cond_TBOUND_def by auto + +lemma time_leq_bindy: "time c h \ t1 \ time (d (the_res c h)) (the_heap c h) \ t2 \ + time (c \ d) h \ t1+t2" + by (simp add: time_bind) + +lemma cond_TBOUND_bind[cond_TBOUND]: + assumes "\
P\
TBOUND c t1" + and "

c " + and "(\ x h. x = the_res c h \ \

Q x\
TBOUND (d x) t2)" +shows "\
P\
TBOUND (c \ d) (t1+t2)" + unfolding cond_TBOUND_def hoare_triple_def + apply auto + subgoal for h as + apply(cases "fails (d (the_res c h)) (the_heap c h)") + apply (simp add: time_bind) + apply(rule time_leq_bindy) + subgoal + using assms unfolding cond_TBOUND_def hoare_triple_def + apply auto + done + using assms(3)[of "(the_res c h)" h] + unfolding cond_TBOUND_def + using assms(2) + unfolding hoare_triple_def Let_def the_res_def the_heap_def + apply(auto split: option.split) + apply force+ + done + done + +lemma cond_TBOUND_return[cond_TBOUND]: "\
P \
TBOUND (return x) 1" + by (simp add: cond_TBOUND_def time_return) + +lemma cond_TBOUND_cons: + assumes "P \\<^sub>A Q" + and "\
Q \
TBOUND c b" + shows "\
P \
TBOUND c b" + using assms + unfolding cond_TBOUND_def + apply sep_auto + by (meson entailsD) + +method cond_TBOUND= (rule cond_TBOUND_mono, rule cond_TBOUND) + + + +end diff --git a/thys/Van_Emde_Boas_Trees/Time_Reasoning/Time_Reasoning.thy b/thys/Van_Emde_Boas_Trees/Time_Reasoning/Time_Reasoning.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/Time_Reasoning/Time_Reasoning.thy @@ -0,0 +1,484 @@ +(*by Lammich*) +theory Time_Reasoning +imports "../Separation_Logic_Imperative_HOL/Sep_Main" +begin + + text \Separating correctness and time reasoning for imperative HOL. + In this theory, we provide a method to add time-reasoning to + an already proved-correct program. + + The time-reasoning can exploit knowledge from the correctness proof via assertions. + \ + + +subsection \Selectors\ + text \We define selectors into the result of a state-time-monad computation\ + + definition "fails m h \ execute m h = None" + definition "the_res m h \ case execute m h of Some (r,_,_) \ r" + definition "the_heap m h \ case execute m h of Some (_,h',_) \ h'" + + text \We define the time to be zero for a failing computation, + such that failing computations trivially satisfy time bounds. + + Note that the computation is already proved non-failing by the correctness proof, + this allows us to assume computations do not fail for the time-bound proof. + \ + definition "time c h \ case execute c h of None \ 0 | Some (_,_,t) \ t" + + lemma time_refines: "refines c c' \ \fails c' h \ time c h \ time c' h" + unfolding time_def refines_def fails_def + apply (auto split: option.splits) + done + + lemma fails_refines: "refines c c' \ fails c h \ fails c' h" + unfolding time_def refines_def fails_def + apply (auto split: option.splits) + by (metis option.exhaust prod_cases3) + +subsubsection \Simplification Lemmas\ + + + named_theorems fails_simp + named_theorems time_simp + + + + lemma fails_return[fails_simp]: "\fails (return x) h" + unfolding fails_def by (auto simp add: execute_simps split: option.split) + + lemma fails_wait[fails_simp]: "\fails (wait x) h" + unfolding fails_def by (auto simp add: execute_simps split: option.split) + + lemma fails_assert'[fails_simp]: "fails (assert' P) h \ \P" + unfolding fails_def by (auto simp add: execute_simps split: option.split) + + lemma fails_bind[fails_simp]: "fails (bind m f) h \ (\fails m h \ fails (f (the_res m h)) (the_heap m h))" + unfolding fails_def the_res_def the_heap_def + apply (auto simp add: execute_simps split: option.split) + using timeFrame.elims by auto + + lemma fails_array_nth[fails_simp]: "fails (Array_Time.nth p i) h \ \(i < Array_Time.length h p)" + unfolding fails_def by (auto simp add: execute_simps split: option.split) + + lemma fails_array_upd[fails_simp]: "fails (Array_Time.upd i x p) h \ \(i < Array_Time.length h p)" + unfolding fails_def by (auto simp add: execute_simps split: option.split) + + lemma fails_array_len[fails_simp]: "\fails (Array_Time.len p) h" + unfolding fails_def by (auto simp add: execute_simps split: option.split) + + lemma fails_array_new[fails_simp]: "\fails (Array_Time.new n x) h" + unfolding fails_def by (auto simp add: execute_simps split: option.split) + + lemma fails_array_of_list[fails_simp]: "\fails (Array_Time.of_list xs) h" + unfolding fails_def by (auto simp add: execute_simps split: option.split) + + lemma fails_array_make[fails_simp]: "\fails (Array_Time.make n f) h" + unfolding fails_def by (auto simp add: execute_simps split: option.split) + + lemma fails_array_map_entry[fails_simp]: "fails (Array_Time.map_entry i x p) h \ \(i < Array_Time.length h p)" + unfolding fails_def by (auto simp add: execute_simps split: option.split) + + lemma fails_array_swap[fails_simp]: "fails (Array_Time.swap i x p) h \ \(i < Array_Time.length h p)" + unfolding fails_def by (auto simp add: execute_simps split: option.split) + + + + + lemma time_return[time_simp]: "time (return x) h = 1" + unfolding time_def by (simp add: execute_simps) + + lemma time_bind[time_simp]: "time (bind m f) h = ( + if \fails m h \ \fails (f (the_res m h)) (the_heap m h) then time m h + time (f (the_res m h)) (the_heap m h) + else 0 + )" + unfolding time_def the_res_def fails_def the_heap_def + by (auto simp add: execute_simps split: option.split) + + lemma time_wait[time_simp]: "time (wait n) h = n" + unfolding time_def by (simp add: execute_simps) + + lemma time_raise[time_simp]: "time (raise msg) h = 0" + by (auto simp: time_def execute_simps) + + lemma time_assert'[time_simp]: "time (assert' P) h = 0" + unfolding time_def + by (auto simp add: execute_simps split: option.split) + + + lemma time_array_nth[time_simp]: "time (Array_Time.nth p i) h = (if fails (Array_Time.nth p i) h then 0 else 1)" + unfolding time_def by (auto simp add: execute_simps fails_simp split: option.split) + + lemma time_array_upd[time_simp]: "time (Array_Time.upd i x p) h = (if fails (Array_Time.upd i x p) h then 0 else 1)" + unfolding time_def by (auto simp add: execute_simps fails_simp split: option.split) + + lemma time_array_len[time_simp]: "time (Array_Time.len p) h = 1" + unfolding time_def by (auto simp add: execute_simps fails_simp split: option.split) + + lemma time_array_new[time_simp]: "time (Array_Time.new n x) h = n+1" + unfolding time_def + by (auto simp add: execute_simps fails_simp split: option.split prod.splits) + + lemma time_array_of_list[time_simp]: "time (Array_Time.of_list xs) h = length xs+1" + unfolding time_def + by (auto simp add: execute_simps fails_simp split: option.split prod.splits) + + lemma time_array_make[time_simp]: "time (Array_Time.make n f) h = n+1" + unfolding time_def + by (auto simp add: execute_simps fails_simp split: option.split prod.splits) + + lemma time_array_map_entry[time_simp]: "time (Array_Time.map_entry i f p) h = (if fails (Array_Time.map_entry i f p) h then 0 else 2)" + unfolding time_def by (auto simp add: execute_simps fails_simp split: option.split) + + lemma time_array_swap[time_simp]: "time (Array_Time.swap i x p) h = (if fails (Array_Time.map_entry i f p) h then 0 else 2)" + unfolding time_def by (auto simp add: execute_simps fails_simp split: option.split) + + lemma time_array_freeze[time_simp]: "time (Array_Time.freeze p) h = Array_Time.length h p+1" + unfolding time_def + by (auto simp add: execute_simps fails_simp split: option.split prod.splits) + + +subsection \Hoare Triple with Time\ + + definition htt::"assn \ 'a Heap \ ('a \ assn) \ nat\ bool"("<_>/ _/ <_> T/[_]") where + "htt P c Q t \

c \ (\h as. (h,as) \ P \ time c h \ t)" + + lemma httI[intro?]: + assumes "

c " + assumes "\h as. (h,as) \ P \ time c h \ t" + shows "< P> c T[t]" + using assms unfolding htt_def by auto + + lemma htt_refine: + assumes "< P> c T[ t]" + assumes "refines c' c" + shows "

c' T[ t]" + by (smt (verit, best) assms(1) assms(2) dual_order.trans fails_def + hoare_tripleE hoare_triple_refines htt_def option.simps(3) time_refines) + + + lemma htt_cons_rule: + assumes " c T[t']" + " P \\<^sub>A P'" + "\ x. Q' x \\<^sub>A Q x" "t' \ t" + shows "

c <\ x. Q x >T[t]" + using assms cons_rule[OF assms(2,3)] unfolding htt_def + using entails_def by fastforce + + lemma norm_pre_ex_rule_htt: + " (\x.

f T[t]) \ <\\<^sub>Ax. P x> f T[t]" + by (metis htt_def mod_ex_dist norm_pre_ex_rule) + + lemma norm_post_ex_rule_htt: + " (

f <(Q x)>T[t]) \

f <\ r. (\\<^sub>A x. Q x r)>T[t]" + by (meson ent_refl eq_iff htt_cons_rule triv_exI) + + lemma norm_pre_pure_iff_htt: + "

b> f T[t] = (b \

f T[t])" + using htt_def by fastforce + + lemma norm_pre_pure_iff_htt': + "< \ b*P > f T[t] = (b \

f T[t])" + using htt_def by fastforce + + + + +subsection \Proving time Bounds\ + + definition "TBOUND m t \ \h. time m h \ t" + + lemma TBOUNDI[intro?]: "\\h. time m h \ t\ \ TBOUND m t" + by (auto simp: TBOUND_def) + + lemma TBOUNDD: "TBOUND m t \ time m h \ t" + by (auto simp: TBOUND_def) + + lemma TBOUND_eqI: + assumes "\h. time m h = t" + shows "TBOUND m t" + apply rule + using assms by simp + + lemma TBOUND_empty: "TBOUND (Heap.Heap Map.empty) t" + unfolding TBOUND_def time_def by (simp) + + lemma TBOUND_mono: "TBOUND c t \ t\t' \ TBOUND c t'" + apply (auto simp: TBOUND_def) + by (meson order.trans) + +lemma TBOUND_refines: "TBOUND c t \ refines c d \ TBOUND d t" + apply (auto simp: TBOUND_def refines_def time_def) + apply(auto split: option.split) + subgoal for h a aa b + proof- + assume 1: "\h. (case execute c h of None \ 0 | Some (x, xa, t) \ t) \ t" + show "\h. case execute d h of None \ True | Some (r, h', t) \ execute c h = Some (r, h', t) \ + execute d h = Some (a, aa, b) \ b \ t " + proof- + assume 2:"\h. case execute d h of None \ True | Some (r, h', t) \ execute c h = Some (r, h', t)" + show "execute d h = Some (a, aa, b) \ b \ t " + proof- + assume "execute d h = Some (a, aa, b)" + hence "execute c h = Some (a, aa, b)" using 2 + by (smt (z3) old.prod.case option.simps(5)) + thus "b \ t" using 1 + by (metis old.prod.case option.simps(5)) + qed + qed + qed + done + + + + text \This rule splits a Hoare-triple with time into + a Hoare-triple without time and a time-bound proof, + thus separating the proof of correctness and time. + \ + lemma httI_TBOUND: + assumes "

c " + assumes "TBOUND c t" + shows "< P> c T[t]" + by (simp add: TBOUNDD assms(1) assms(2) httI) + + lemma htt_htD: + assumes "

c T[t]" + shows "

c " + using assms htt_def by auto + + subsubsection \Admissibility\ + context begin + private lemma TBOUND_adm_aux: + "(\f. \xx y. f xx = Some y \ (case y of (_,_,tt) \ tt \ t x)) + = (\xa. \h. time (Heap.Heap xa) h \ t x)" + apply (auto simp: fun_eq_iff time_def split: option.splits) + done + + lemma TBOUND_adm: "heap.admissible (\f. \x. TBOUND (f x) (t x))" + unfolding TBOUND_def + apply (rule admissible_fun[OF heap_interpretation]) + + unfolding Heap_lub_def Heap_ord_def + apply (rule admissible_image) + subgoal + by (simp add: flat_interpretation partial_function_lift) + + subgoal + apply (simp add: comp_def) + apply (fold TBOUND_adm_aux) + using option_admissible . + + apply (metis Heap_execute) + by simp + end + + text \Ad-hoc instances of admissible rule\ + lemma TBOUND_fi_adm: "heap.admissible (\ fi'. \x xa. TBOUND (curry fi' x xa) (foo x xa))" + apply (rule ccpo.admissibleI) + apply clarsimp + apply (rule ccpo.admissibleD[OF TBOUND_adm, rule_format, where t="\(x,xa). foo x xa" and x="(x,xa)" for x xa, simplified]) + by auto + + lemma TBOUND_fi'_adm: "heap.admissible (\ fi'. \x xa xb. TBOUND (curry (curry fi') x xa xb) (foo x xa xb))" + apply (rule ccpo.admissibleI) + apply clarsimp + apply (rule ccpo.admissibleD[OF TBOUND_adm, rule_format, where t="\((x,xa),xb). foo x xa xb" and x="((x,xa),xb)" for x xa xb, simplified]) + by auto + + + subsubsection \Syntactic Rules for \<^const>\TBOUND\\ + + text \Technical workaround: + Tag to protect a schematic variable from the simplifier's solver. + Used to simplify a term and then unify with schematic variable. + + A goal of the form \EQ t ?t'\ can be simplified, and then resolved with rule \EQ_refl\. + If one would run the simplifier on \t = ?t'\, the solver would apply @{thm refl} immediately, + not simplifying \t\. + \ + definition "EQ a b \ a=b" + lemma EQI: "a=b \ EQ a b" by (simp add: EQ_def) + lemma EQD: "EQ a b \ a=b" by (simp add: EQ_def) + lemma EQ_refl: "EQ a a" by (simp add: EQ_def) + + + named_theorems TBOUND \Syntactic rules for time-bounds\ + + lemma TBOUND_bind: + assumes "TBOUND m t\<^sub>1" + assumes "\x h. \x = the_res m h; \fails m h\ \ TBOUND (f x) t\<^sub>2" + shows "TBOUND (do {x\m; f x}) (t\<^sub>1 + t\<^sub>2)" + apply (rule) + using assms[THEN TBOUNDD] + apply (auto simp add: time_simp add_mono) + done + + lemma TBOUND_assert'_bind: + assumes "EQ P P'" + assumes "P \ TBOUND m t" + shows "TBOUND (do {assert' P; m}) (if P' then t else 0)" + apply (rule) + using assms(2)[THEN TBOUNDD] using assms(1)[THEN EQD] + apply (auto simp add: time_simp add_mono fails_simp) + done + + lemma TBOUND_assert'_weak[TBOUND]: + assumes "P \ TBOUND m t" + shows "TBOUND (do {assert' P; m}) t" + apply (rule) + using assms[THEN TBOUNDD] + apply (auto simp add: time_simp add_mono fails_simp) + done + + lemma TBOUND_bind_weak[TBOUND]: + assumes "TBOUND m t\<^sub>1" + assumes "\x h. \\fails m h\ \ TBOUND (f x) t\<^sub>2" + shows "TBOUND (do {x\m; f x}) (t\<^sub>1 + t\<^sub>2)" + apply (rule) + using assms[THEN TBOUNDD] + apply (auto simp add: time_simp add_mono) + done + + + lemma TBOUND_return[TBOUND]: "TBOUND (return x) 1" + apply(rule TBOUND_eqI) + apply(simp add: time_simp) + done + + lemma TBOUND_of_list[TBOUND]: "TBOUND (Array_Time.of_list xs) (Suc (length xs))" + apply(rule TBOUND_eqI) + apply(simp add: time_simp) + done + + lemma TBOUND_len[TBOUND]: "TBOUND (Array_Time.len xs) 1" + apply(rule TBOUND_eqI) + apply(simp add: time_simp) + done + + lemma TBOUND_nth[TBOUND]: "TBOUND (Array_Time.nth xs i) 1" + apply(rule TBOUNDI) + apply(simp add: time_simp) + done + + lemma TBOUND_upd[TBOUND]: "TBOUND (Array_Time.upd xs i x) 1" + apply(rule TBOUNDI) + apply(simp add: time_simp) + done + + lemma TBOUND_new[TBOUND]: "TBOUND (Array_Time.new n x) (n+1)" + apply(rule TBOUNDI) + apply(simp add: time_simp) + done + + lemma TBOUND_make[TBOUND]: "TBOUND (Array_Time.make n f) (n+1)" + apply(rule TBOUNDI) + apply(simp add: time_simp) + done + + lemma TBOUND_swap[TBOUND]: "TBOUND (Array_Time.swap i x a) 2" + apply(rule TBOUNDI) + apply(subst time_simp) + apply(simp) + done + + lemma TBOUND_map_entry[TBOUND]: "TBOUND (Array_Time.map_entry i x a) 2" + apply(rule TBOUNDI) + apply(subst time_simp) + apply(simp) + done + + lemma TBOUND_cons: " TBOUND m t\ EQ t t' \ TBOUND m t'" + unfolding EQ_def + by simp + + + lemma TBOUND_if_max[TBOUND]: + assumes "P \ TBOUND m bm" + assumes "\ P \ TBOUND n bn" + shows "TBOUND (if P then m else n) (max bm bn)" + using assms + apply( auto simp add: TBOUND_def max_def) + apply (meson TBOUNDD TBOUND_mono assms) + apply (meson dual_order.trans nat_le_linear) + done + + lemma TBOUND_if_strong: + assumes "EQ b b'" + assumes "b \ TBOUND m\<^sub>1 t\<^sub>1" + assumes "\b \ TBOUND m\<^sub>2 t\<^sub>2" + shows "TBOUND (if b then m\<^sub>1 else m\<^sub>2) (if b' then t\<^sub>1 else t\<^sub>2)" + using assms unfolding EQ_def by auto + + + lemma TBOUND_if: + assumes "b \ TBOUND m\<^sub>1 t\<^sub>1" + assumes "\b \ TBOUND m\<^sub>2 t\<^sub>2" + shows "TBOUND (if b then m\<^sub>1 else m\<^sub>2) (if b then t\<^sub>1 else t\<^sub>2)" + using assms by auto + + lemma TBOUND_Let: + assumes "\x. x = v \ TBOUND (f x) (t x)" + shows "TBOUND (let x=v in f x) (let x=v in t x)" + using assms by auto + + lemma TBOUND_Let_strong: + assumes "EQ v v'" + assumes "\ x. x = v \ TBOUND (f x) (bnd x)" + shows " TBOUND (let x = v in f x) (let x = v' in bnd x)" + using assms unfolding EQ_def by simp + + lemma TBOUND_Let_weak[TBOUND]: + assumes "\ x. x = v \ TBOUND (f x) (bnd )" + shows " TBOUND (let x = v in f x) bnd " + using assms by simp + + lemma TBOUND_option_case[TBOUND]: + assumes "t = None \ TBOUND f bnd" + "\ x. t = Some x \ TBOUND (f' x) (bnd' x)" + shows "TBOUND (case t of None \ f | Some x \ f' x) + (case t of None \ bnd | Some x \ bnd' x)" + using assms + apply(cases t) + apply auto + done + + lemma TBOUND_prod_case[TBOUND]: + assumes "\ a b. t = (a, b) \ TBOUND (f a b) (bnd a b)" + shows "TBOUND (case t of (a, b) \ f a b) (case t of (a, b) \ bnd a b) " + using assms apply(cases t) + by auto + + lemma TBOUND_assert'_bind_strong: + assumes "P \ TBOUND m t" + shows "TBOUND (do {assert' P; m}) (if P then t else 0)" + apply (rule) + using assms[THEN TBOUNDD] + apply (auto simp add: time_simp add_mono fails_simp) + done + +subsubsection \Automation\ + + named_theorems TBOUND_simps + + lemmas [TBOUND_simps] = if_cancel Let_const + + method TBOUND_simp_EQ = ( rule EQI; (elim conjE )? ;simp only: TBOUND_simps ; fail) + + method TBOUND_step_strong = (rule TBOUND_assert'_bind TBOUND_Let_strong TBOUND_if_strong, TBOUND_simp_EQ) + + method TBOUND_gen_step methods fallback = + (TBOUND_step_strong | + rule TBOUND | + assumption| + rule TBOUND_cons, (rule TBOUND| assumption) | + TBOUND_simp_EQ | + fallback) + + method TBOUND_step' = TBOUND_gen_step \simp; fail\ + method TBOUND_step = TBOUND_gen_step \fail\ + + method defer_le = (rule asm_rl[of "_ \ _"], tactic \defer_tac 1\) + +method TBOUND= (rule TBOUND_mono, ( TBOUND_step'+ ; fail), defer_le) + +end diff --git a/thys/Van_Emde_Boas_Trees/VEBT_Bounds.thy b/thys/Van_Emde_Boas_Trees/VEBT_Bounds.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/VEBT_Bounds.thy @@ -0,0 +1,1742 @@ +(*by Ammer*) +theory VEBT_Bounds imports VEBT_Height VEBT_Member VEBT_Insert VEBT_Succ VEBT_Pred +begin + +section \Upper Bounds for canonical Functions: Relationships between Run Time and Tree Heights\ + +subsection \Membership test\ + +context begin + + interpretation VEBT_internal . + +fun T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r::"VEBT \ nat \ nat" where + "T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (Leaf a b) x = 2 + (if x = 0 then 1 else 1 +( if x=1 then 1 else 1))"| + "T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (Node None _ _ _) x = 2"| + "T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (Node _ 0 _ _) x = 2"| + "T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (Node _ (Suc 0) _ _) x = 2"| + "T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (Node (Some (mi, ma)) deg treeList summary) x = 2 + ( + if x = mi then 1 else 1+ ( + if x = ma then 1 else 1+( + if x < mi then 1 else 1+ ( + if x > ma then 1 else 9 + + (let + h = high x (deg div 2); + l = low x (deg div 2) in + (if h < length treeList + then 1 + T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (treeList ! h) l + else 1))))))" + + +fun T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r'::"VEBT \ nat \ nat" where + "T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (Leaf a b) x = 1"| + "T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (Node None _ _ _) x = 1"| + "T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (Node _ 0 _ _) x = 1"| + "T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (Node _ (Suc 0) _ _) x = 1"| + "T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (Node (Some (mi, ma)) deg treeList summary) x = 1+( + if x = mi then 0 else ( + if x = ma then 0 else ( + if x < mi then 0 else ( + if x > ma then 0 else if (x>mi \ x < ma) then + (let + h = high x (deg div 2); + l = low x (deg div 2) in + (if h < length treeList + then T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (treeList ! h) l + else 0)) +else 0))))" + + +lemma height_node: "invar_vebt (Node (Some (mi, ma)) deg treeList summary) n + \ height (Node (Some (mi, ma)) deg treeList summary) >= 1" + using height.simps(2) by presburger + +theorem member_bound_height: "invar_vebt t n \ T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r t x \ (1+height t)*15" +proof(induction t n arbitrary: x rule: invar_vebt.induct) + case (1 a b) + then show ?case by simp +next + case (2 treeList n summary m deg) + then show ?case by simp +next + case (3 treeList n summary m deg) + then show ?case by simp +next + case (4 treeList n summary m deg mi ma) + hence "n \ 1 \ m \ 1" + by (metis Nat.add_0_right Suc_leI deg_not_0 plus_1_eq_Suc) + hence "deg \ 2" + by (simp add: "4.hyps"(4)) + then show ?case + proof(cases "x = mi") + case True + hence "T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (Node (Some (mi, ma)) deg treeList summary) x = 3" + using T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r.simps(5)[of mi ma "deg -2" treeList summary x] + by (smt (z3) Suc_1 Suc_diff_le Suc_eq_plus1 Suc_leD \2 \ deg\ diff_Suc_1 diff_Suc_Suc eval_nat_numeral(3)) + then show ?thesis by simp + next + case False + hence "x \ mi" by simp + hence 1:"T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (Node (Some (mi, ma)) deg treeList summary) x = 3 + ( + if x = ma then 1 else 1+( + if x < mi then 1 else 1+ ( + if x > ma then 1 else 9 + + (let h = high x (deg div 2); l = low x (deg div 2) in + (if h < length treeList + then 1 + T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (treeList ! h) l + else 1)))))" + using T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r.simps(5)[of mi ma "deg -2" treeList summary x] + by (smt (z3) One_nat_def Suc_1 \2 \ deg\ add_Suc_shift le_add_diff_inverse numeral_3_eq_3 plus_1_eq_Suc) + then show ?thesis + proof(cases "x = ma") + case True + hence "T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (Node (Some (mi, ma)) deg treeList summary) x = 4" using 1 by auto + then show ?thesis by simp + next + case False + hence "x \ ma" by simp + hence 2:"T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (Node (Some (mi, ma)) deg treeList summary) x = 4 +( + if x < mi then 1 else 1+ ( + if x > ma then 1 else 9 + + (let + h = high x (deg div 2); + l = low x (deg div 2) in + (if h < length treeList + then 1 + T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (treeList ! h) l + else 1))))" + using 1 by simp + then show ?thesis + proof(cases "x < mi") + case True + hence "T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (Node (Some (mi, ma)) deg treeList summary) x = 5" using 2 by auto + then show ?thesis by simp + next + case False + hence "x > mi" + using \x \ mi\ antisym_conv3 by blast + hence 3:"T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (Node (Some (mi, ma)) deg treeList summary) x = 5 + ( + if x > ma then 1 else 9 + + (let h = high x (deg div 2); l = low x (deg div 2) in + (if h < length treeList + then 1 + T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (treeList ! h) l + else 1)))" + using 2 by simp + then show ?thesis + proof(cases "x > ma") + case True + hence "T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (Node (Some (mi, ma)) deg treeList summary) x = 6" using 3 by simp + then show ?thesis by simp + next + case False + hence "x < ma" + by (meson \x \ ma\ nat_neq_iff) + hence 4:"T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (Node (Some (mi, ma)) deg treeList summary) x = 14+ + (let h = high x (deg div 2); l = low x (deg div 2) in + (if h < length treeList + then 1 + T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (treeList ! h) l + else 1))" + using 3 by simp + let ?h = "high x (deg div 2)" + let ?l = " low x (deg div 2)" + have "?h < length treeList" + using "4.hyps"(2) "4.hyps"(3) "4.hyps"(4) "4.hyps"(8) \x < ma\ high_bound_aux by force + hence 5:"T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (Node (Some (mi, ma)) deg treeList summary) x = 15 + T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (treeList ! ?h) ?l" + using "4" by presburger + moreover have "invar_vebt (treeList ! ?h) n \ (treeList ! ?h) \ set treeList " + using "4.IH"(1) \high x (deg div 2) < length treeList\ nth_mem by blast + moreover hence " T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (treeList ! ?h) ?l \ (1 + height (treeList ! ?h))*15" using "4.IH"(1) by simp + ultimately have 6:"T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (Node (Some (mi, ma)) deg treeList summary) x \ + 15 + 15 * (1 + height (treeList ! ?h))" by simp + moreover have "i< length treeList \ + height (treeList ! i) \ Max (height ` (insert summary (set treeList)))" for i + apply (induction treeList arbitrary: i) + apply simp + apply (meson List.finite_set Max_ge finite_imageI finite_insert image_iff nth_mem subsetD subset_insertI) + done + moreover hence " (1 + height (treeList ! ?h)) \ height (Node (Some (mi, ma)) deg treeList summary)" + by (simp add: \high x (deg div 2) < length treeList\) + moreover hence " 14 * (1 + height (treeList ! ?h)) \ 14 * height (Node (Some (mi, ma)) deg treeList summary)" by simp + ultimately show ?thesis using 6 algebra_simps add_mono_thms_linordered_semiring(2) mult.right_neutral order_trans by force + qed + qed + qed + qed +next + case (5 treeList n summary m deg mi ma) + hence "n \ 1 \ m \ 1" + by (metis le_add1 plus_1_eq_Suc set_n_deg_not_0) + hence "deg \ 2" + by (simp add: "5.hyps"(4)) + then show ?case + proof(cases "x = mi") + case True + hence "T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (Node (Some (mi, ma)) deg treeList summary) x = 3" + using T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r.simps(5)[of mi ma "deg -2" treeList summary x] + by (smt (z3) One_nat_def Suc_nat_number_of_add \2 \ deg\ le_add_diff_inverse numeral_3_eq_3 numerals(1) plus_1_eq_Suc semiring_norm(2)) + then show ?thesis by simp + next + case False + hence "x \ mi" by simp + hence 1:"T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (Node (Some (mi, ma)) deg treeList summary) x = 3 + ( + if x = ma then 1 else 1+( + if x < mi then 1 else 1+ ( + if x > ma then 1 else 9 + + (let h = high x (deg div 2); l = low x (deg div 2) in + (if h < length treeList + then 1 + T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (treeList ! h) l + else 1)))))" + using T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r.simps(5)[of mi ma "deg -2" treeList summary x] + by (smt (z3) One_nat_def Suc_1 \2 \ deg\ add_Suc_shift le_add_diff_inverse numeral_3_eq_3 plus_1_eq_Suc) + then show ?thesis + proof(cases "x = ma") + case True + hence "T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (Node (Some (mi, ma)) deg treeList summary) x = 4" using 1 by auto + then show ?thesis by simp + next + case False + hence "x \ ma" by simp + hence 2:"T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (Node (Some (mi, ma)) deg treeList summary) x = 4 +( + if x < mi then 1 else 1+ ( + if x > ma then 1 else 9 + + (let h = high x (deg div 2); l = low x (deg div 2) in + (if h < length treeList + then 1 + T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (treeList ! h) l + else 1))))" + using 1 by simp + then show ?thesis + proof(cases "x < mi") + case True + hence "T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (Node (Some (mi, ma)) deg treeList summary) x = 5" using 2 by auto + then show ?thesis by simp + next + case False + hence "x > mi" + using \x \ mi\ antisym_conv3 by blast + hence 3:"T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (Node (Some (mi, ma)) deg treeList summary) x = 5 + ( + if x > ma then 1 else 9 + + (let h = high x (deg div 2); l = low x (deg div 2) in + (if h < length treeList then 1 + T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (treeList ! h) l else 1)))" + using 2 by simp + then show ?thesis + proof(cases "x > ma") + case True + hence "T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (Node (Some (mi, ma)) deg treeList summary) x = 6" using 3 by simp + then show ?thesis by simp + next + case False + hence "x < ma" + by (meson \x \ ma\ nat_neq_iff) + hence 4:"T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (Node (Some (mi, ma)) deg treeList summary) x = 14+ + (let h = high x (deg div 2); l = low x (deg div 2) in + (if h < length treeList + then 1 + T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (treeList ! h) l + else 1))" + using 3 by simp + let ?h = "high x (deg div 2)" + let ?l = " low x (deg div 2)" + have "?h < length treeList" + by (metis "5.hyps"(2) "5.hyps"(3) "5.hyps"(4) "5.hyps"(8) \x < ma\ add_Suc_right add_self_div_2 even_Suc_div_two high_bound_aux odd_add order.strict_trans) + hence 5:"T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (Node (Some (mi, ma)) deg treeList summary) x = 15 + T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (treeList ! ?h) ?l" + using "4" by presburger + moreover have "invar_vebt (treeList ! ?h) n \ (treeList ! ?h) \ set treeList " + using "5.IH"(1) \high x (deg div 2) < length treeList\ nth_mem by blast + moreover hence " T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (treeList ! ?h) ?l \ (1 + height (treeList ! ?h))*15" using "5.IH"(1) by simp + ultimately have 6:"T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r (Node (Some (mi, ma)) deg treeList summary) x \ + 15 + 15 * (1 + height (treeList ! ?h))" + by simp + moreover have "i< length treeList \ + height (treeList ! i) \ Max (height ` (insert summary (set treeList)))" for i + apply (induction treeList arbitrary: i) + apply simp + apply (meson List.finite_set Max_ge finite_imageI finite_insert image_iff nth_mem subsetD subset_insertI) + done + moreover hence " (1 + height (treeList ! ?h)) \ height (Node (Some (mi, ma)) deg treeList summary)" + by (simp add: \high x (deg div 2) < length treeList\) + moreover hence " 15 * (1 + height (treeList ! ?h)) \ 15 * height (Node (Some (mi, ma)) deg treeList summary)" by simp + ultimately show ?thesis using 6 + algebra_simps add_mono_thms_linordered_semiring(2) mult.right_neutral order_trans by force + qed + qed + qed + qed +qed + +theorem member_bound_height': "invar_vebt t n \ T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' t x \ (1+height t)" +proof(induction t n arbitrary: x rule: invar_vebt.induct) + case (4 treeList n summary m deg mi ma) + hence "n \ 1 \ m \ 1" + by (metis Nat.add_0_right Suc_leI deg_not_0 plus_1_eq_Suc) + hence "deg \ 2" + by (simp add: "4.hyps"(4)) + then show ?case + proof(cases "x = mi") + case True + hence "T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (Node (Some (mi, ma)) deg treeList summary) x = 1" + using T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r'.simps(5)[of mi ma "deg -2" treeList summary x] + by (smt (z3) One_nat_def \2 \ deg\ add_2_eq_Suc ordered_cancel_comm_monoid_diff_class.add_diff_inverse plus_1_eq_Suc) + then show ?thesis by simp + next + case False + hence "x \ mi" by simp + hence 1:"T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (Node (Some (mi, ma)) deg treeList summary) x = 1 + ( + if x = ma then 0 else ( + if x < mi then 0 else ( + if x > ma then 0 else + (let h = high x (deg div 2); l = low x (deg div 2) in + (if h < length treeList + then T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (treeList ! h) l + else 0)))))" + using T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r'.simps(5)[of mi ma "deg -2" treeList summary x] + by (smt (z3) \2 \ deg\ add_2_eq_Suc le_add_diff_inverse linorder_not_less nat_less_le) + then show ?thesis + proof(cases "x = ma") + case True + hence "T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (Node (Some (mi, ma)) deg treeList summary) x = 1" using 1 by auto + then show ?thesis by simp + next + case False + hence "x \ ma" by simp + hence 2:"T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (Node (Some (mi, ma)) deg treeList summary) x = 1 +( + if x < mi then 0 else ( + if x > ma then 0 else + (let h = high x (deg div 2); l = low x (deg div 2) in + (if h < length treeList + then T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (treeList ! h) l + else 0))))" + using 1 by simp + then show ?thesis + proof(cases "x < mi") + case True + hence "T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (Node (Some (mi, ma)) deg treeList summary) x = 1" using 2 by auto + then show ?thesis by simp + next + case False + hence "x > mi" + using \x \ mi\ antisym_conv3 by blast + hence 3:"T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (Node (Some (mi, ma)) deg treeList summary) x = 1 + ( + if x > ma then 0 else + (let h = high x (deg div 2); l = low x (deg div 2) in + (if h < length treeList + then T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (treeList ! h) l + else 0)))" + using 2 by simp + then show ?thesis + proof(cases "x > ma") + case True + hence "T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (Node (Some (mi, ma)) deg treeList summary) x = 1" using 3 by simp + then show ?thesis by simp + next + case False + hence "x < ma" + by (meson \x \ ma\ nat_neq_iff) + hence 4:"T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (Node (Some (mi, ma)) deg treeList summary) x = 1+ + (let h = high x (deg div 2); l = low x (deg div 2) in + (if h < length treeList + then T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (treeList ! h) l + else 0))" + using 3 by simp + let ?h = "high x (deg div 2)" + let ?l = " low x (deg div 2)" + have "?h < length treeList" + using "4.hyps"(2) "4.hyps"(3) "4.hyps"(4) "4.hyps"(8) \x < ma\ high_bound_aux by force + hence 5:"T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (Node (Some (mi, ma)) deg treeList summary) x = 1+ T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (treeList ! ?h) ?l" + using "4" by presburger + moreover have "invar_vebt (treeList ! ?h) n \ (treeList ! ?h) \ set treeList " + using "4.IH"(1) \high x (deg div 2) < length treeList\ nth_mem by blast + moreover hence " T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (treeList ! ?h) ?l \ (1 + height (treeList ! ?h))*1" using "4.IH"(1) by simp + ultimately have 6:"T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (Node (Some (mi, ma)) deg treeList summary) x \ + 1 + (1 + height (treeList ! ?h))" by simp + moreover have "i< length treeList \ + height (treeList ! i) \ Max (height ` (insert summary (set treeList)))" for i + apply (induction treeList arbitrary: i) + apply simp + apply (meson List.finite_set Max_ge finite_imageI finite_insert image_iff nth_mem subsetD subset_insertI) + done + moreover hence " (1 + height (treeList ! ?h)) \ height (Node (Some (mi, ma)) deg treeList summary)" + by (simp add: \high x (deg div 2) < length treeList\) + moreover hence " 14 * (1 + height (treeList ! ?h)) \ 14 * height (Node (Some (mi, ma)) deg treeList summary)" by simp + ultimately show ?thesis using 6 algebra_simps add_mono_thms_linordered_semiring(2) mult.right_neutral order_trans by force + qed + qed + qed + qed +next + case (5 treeList n summary m deg mi ma) + hence "n \ 1 \ m \ 1" + by (metis le_add1 plus_1_eq_Suc set_n_deg_not_0) + hence "deg \ 2" + by (simp add: "5.hyps"(4)) + then show ?case + proof(cases "x = mi") + case True + hence "T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (Node (Some (mi, ma)) deg treeList summary) x = 1" + using T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r'.simps(5)[of mi ma "deg -2" treeList summary x] + by (smt (z3) One_nat_def \2 \ deg\ add_2_eq_Suc ordered_cancel_comm_monoid_diff_class.add_diff_inverse plus_1_eq_Suc) + then show ?thesis by simp + next + case False + hence "x \ mi" by simp + hence 1:"T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (Node (Some (mi, ma)) deg treeList summary) x = 1 + ( + if x = ma then 0 else ( + if x < mi then 0 else ( + if x > ma then 0 else + (let h = high x (deg div 2); l = low x (deg div 2) in + (if h < length treeList + then T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (treeList ! h) l + else 0)))))" + using T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r'.simps(5)[of mi ma "deg -2" treeList summary x] + by (smt (z3) \2 \ deg\ add_2_eq_Suc le_add_diff_inverse linorder_not_less nat_less_le) + then show ?thesis + proof(cases "x = ma") + case True + hence "T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (Node (Some (mi, ma)) deg treeList summary) x = 1" using 1 by auto + then show ?thesis by simp + next + case False + hence "x \ ma" by simp + hence 2:"T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (Node (Some (mi, ma)) deg treeList summary) x = 1 +( + if x < mi then 0 else ( + if x > ma then 0 else + (let h = high x (deg div 2); l = low x (deg div 2) in + (if h < length treeList + then T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (treeList ! h) l + else 0))))" + using 1 by simp + then show ?thesis + proof(cases "x < mi") + case True + hence "T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (Node (Some (mi, ma)) deg treeList summary) x = 1" using 2 by auto + then show ?thesis by simp + next + case False + hence "x > mi" + using \x \ mi\ antisym_conv3 by blast + hence 3:"T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (Node (Some (mi, ma)) deg treeList summary) x = 1 + ( + if x > ma then 0 else + (let h = high x (deg div 2); l = low x (deg div 2) in + (if h < length treeList + then T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (treeList ! h) l + else 0)))" + using 2 by simp + then show ?thesis + proof(cases "x > ma") + case True + hence "T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (Node (Some (mi, ma)) deg treeList summary) x = 1" using 3 by simp + then show ?thesis by simp + next + case False + hence "x < ma" + by (meson \x \ ma\ nat_neq_iff) + hence 4:"T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (Node (Some (mi, ma)) deg treeList summary) x = 1+ + (let h = high x (deg div 2); l = low x (deg div 2) in + (if h < length treeList + then T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (treeList ! h) l + else 0))" + using 3 by simp + let ?h = "high x (deg div 2)" + let ?l = " low x (deg div 2)" + have "?h < length treeList" + using "5.hyps"(2) "5.hyps"(3) "5.hyps"(4) "5.hyps"(8) \x < ma\ high_bound_aux + by (metis add_Suc_right add_self_div_2 even_Suc_div_two odd_add order.strict_trans) + hence 5:"T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (Node (Some (mi, ma)) deg treeList summary) x = 1+ T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (treeList ! ?h) ?l" + using "4" by presburger + moreover have "invar_vebt (treeList ! ?h) n \ (treeList ! ?h) \ set treeList " + using "5.IH"(1) \high x (deg div 2) < length treeList\ nth_mem by blast + moreover hence " T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (treeList ! ?h) ?l \ (1 + height (treeList ! ?h))*1" using "5.IH"(1) by simp + ultimately have 6:"T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r' (Node (Some (mi, ma)) deg treeList summary) x \ + 1 + (1 + height (treeList ! ?h))" by simp + moreover have "i< length treeList \ + height (treeList ! i) \ Max (height ` (insert summary (set treeList)))" for i + apply (induction treeList arbitrary: i) + apply simp + apply (meson List.finite_set Max_ge finite_imageI finite_insert image_iff nth_mem subsetD subset_insertI) + done + moreover hence " (1 + height (treeList ! ?h)) \ height (Node (Some (mi, ma)) deg treeList summary)" + by (simp add: \high x (deg div 2) < length treeList\) + moreover hence " 14 * (1 + height (treeList ! ?h)) \ 14 * height (Node (Some (mi, ma)) deg treeList summary)" by simp + ultimately show ?thesis using 6 algebra_simps add_mono_thms_linordered_semiring(2) mult.right_neutral order_trans by force + qed + qed + qed + qed +qed simp+ + +theorem member_bound_size_univ: "invar_vebt t n \ u = 2^n \ T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r t x \ 30 + 15 * lb (lb u)" + using member_bound_height[of t n x] height_double_log_univ_size[of u n t] algebra_simps by simp + +subsection \Minimum, Maximum, Emptiness Test\ + +fun T\<^sub>m\<^sub>i\<^sub>n\<^sub>t::"VEBT \ nat" where + "T\<^sub>m\<^sub>i\<^sub>n\<^sub>t (Leaf a b) = (1+ (if a then 0 else 1 + (if b then 1 else 1)))"| + "T\<^sub>m\<^sub>i\<^sub>n\<^sub>t (Node None _ _ _) = 1"| + "T\<^sub>m\<^sub>i\<^sub>n\<^sub>t (Node (Some (mi,ma)) _ _ _ ) = 1" + + +lemma mint_bound: "T\<^sub>m\<^sub>i\<^sub>n\<^sub>t t \ 3" by (induction t rule: T\<^sub>m\<^sub>i\<^sub>n\<^sub>t.induct) auto + +fun T\<^sub>m\<^sub>a\<^sub>x\<^sub>t::"VEBT \ nat" where + "T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (Leaf a b) = (1+ (if b then 1 else 1 +( if a then 1 else 1)))"| + "T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (Node None _ _ _) = 1"| + "T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (Node (Some (mi,ma)) _ _ _ ) = 1" + + +lemma maxt_bound: "T\<^sub>m\<^sub>a\<^sub>x\<^sub>t t \ 3" by (induction t rule: T\<^sub>m\<^sub>a\<^sub>x\<^sub>t.induct) auto + +fun T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l::"VEBT \ nat" where + "T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l (Leaf False False) = 1"| + "T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l (Leaf _ _ ) = 1"| + "T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l (Node None _ _ _) = 1"| + "T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l (Node (Some _) _ _ _) = 1" + + +lemma minNull_bound: "T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l t \ 1" + by (metis T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l.elims order_refl) + +subsection \Insertion\ + +fun T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t::"VEBT \ nat \nat" where + "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Leaf a b) x = 1+ (if x=0 then 1 else 1 + (if x=1 then 1 else 1))"| + "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node info 0 ts s) x = 1"| + "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node info (Suc 0) ts s) x = 1"| + "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node None (Suc deg) treeList summary) x = 2"| + "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x = 19+ + ( let xn = (if x < mi then mi else x); minn = (if x< mi then x else mi); + l= low xn (deg div 2); h = high xn (deg div 2) + in + ( if h < length treeList \ \ (x = mi \ x = ma)then + T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (treeList ! h) l + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l (treeList ! h)+ + (if minNull (treeList ! h) then T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t summary h else 1) + else 1))" + +fun T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t'::"VEBT \ nat \nat" where + "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Leaf a b) x = 1"| + "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Node info 0 ts s) x = 1"| + "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Node info (Suc 0) ts s) x = 1"| + "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Node None (Suc deg) treeList summary) x = 1"| + "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Node (Some (mi,ma)) deg treeList summary) x = + (let xn = (if x < mi then mi else x); minn = (if x< mi then x else mi); + l= low xn (deg div 2); h = high xn (deg div 2) + in ( if h < length treeList \ \ (x = mi \ x = ma)then + T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (treeList ! h) l + + (if minNull (treeList ! h) then T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' summary h else 1) else 1))" + +lemma insersimp:assumes "invar_vebt t n" and "\ x. both_member_options t x " shows "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t t y \ 3" +proof- + from assms(1) show ?thesis + proof(cases) + case (1 a b) + then show ?thesis by simp + next + case (2 treeList n summary m) + hence "n+m \ 2" + by (metis add_self_div_2 deg_not_0 div_greater_zero_iff) + then show ?thesis using T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t.simps(4)[of "n+m-2" treeList summary y] + by (metis "2"(1) "2"(6) add.commute add_2_eq_Suc le_add2 numeral_3_eq_3 ordered_cancel_comm_monoid_diff_class.add_diff_inverse) + next + case (3 treeList n summary m) + hence "n+m \ 2" + by (metis add_mono_thms_linordered_semiring(1) le_add1 nat_1_add_1 plus_1_eq_Suc set_n_deg_not_0) + then show ?thesis using T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t.simps(4)[of "n+m-2" treeList summary y] + by (metis "3"(1) "3"(6) add.commute add_2_eq_Suc le_add2 numeral_3_eq_3 ordered_cancel_comm_monoid_diff_class.add_diff_inverse) + next + case (4 treeList n summary m mi ma) + hence "membermima (Node (Some (mi, ma)) (n+m) treeList summary) mi " + by (metis Suc_pred assms(1) deg_not_0 membermima.simps(4)) + hence False + using "4"(1) "4"(6) assms(2) both_member_options_def by blast + then show ?thesis by simp + next + case (5 treeList n summary m mi ma) + hence "membermima (Node (Some (mi, ma)) (n+m) treeList summary) mi " + by (metis Suc_pred assms(1) deg_not_0 membermima.simps(4)) + hence False + using "5"(1) "5"(6) assms(2) both_member_options_def by blast + then show ?thesis by simp + qed +qed + +lemma insertsimp: "invar_vebt t n \ minNull t \ T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t t l \ 3" + using insersimp min_Null_member valid_member_both_member_options by blast + +lemma insersimp':assumes "invar_vebt t n" and "\ x. both_member_options t x " shows "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' t y \ 1" + using assms(1) + apply cases + apply simp + apply(metis add_self_div_2 deg_not_0 div_greater_zero_iff T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t'.simps(4) add_2_eq_Suc dual_order.refl less_eqE) + apply(cases "n\ 2") + apply(smt (z3) T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t'.simps(4)[of "n-2"] T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t'.elims le_Suc_eq add_2_eq_Suc le_refl ordered_cancel_comm_monoid_diff_class.add_diff_inverse) + apply (metis Suc_1 add_mono_thms_linordered_semiring(1) le_add1 plus_1_eq_Suc set_n_deg_not_0) + apply(cases "n\ 2") + apply(metis Suc_pred assms(1) assms(2) both_member_options_def deg_not_0 membermima.simps(4)) + apply(metis add_self_div_2 deg_not_0 div_greater_zero_iff T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t'.simps(4) add_2_eq_Suc dual_order.refl less_eqE) + apply(cases "n\ 2") + apply(metis Suc_pred assms(1) assms(2) both_member_options_def deg_not_0 membermima.simps(4)) + apply (metis Suc_1 add_mono_thms_linordered_semiring(1) le_add1 plus_1_eq_Suc set_n_deg_not_0) + done + +lemma insertsimp': "invar_vebt t n \ minNull t \ T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' t l \ 1" + using insersimp' min_Null_member valid_member_both_member_options by blast + +theorem insert_bound_height: "invar_vebt t n \ T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t t x \ (1+height t)*23" +proof(induction t n arbitrary: x rule: invar_vebt.induct) + case (1 a b) + then show ?case + using T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t.simps(1)[of a b x] height.simps(1)[of a b] by simp+ +next + case (2 treeList n summary m deg) + hence "deg \ 2" + by (metis add_self_div_2 deg_not_0 div_greater_zero_iff) + moreover hence "height (Node None deg treeList summary) \ 1" using height.simps(2)[of None deg treeList summary] by simp + ultimately show ?case using T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t.simps(4)[of "deg-2"treeList summary x] algebra_simps + by (smt (z3) Suc_1 add_lessD1 eval_nat_numeral(3) le_add_diff_inverse less_Suc_eq_le linorder_not_less mult.left_neutral plus_1_eq_Suc) +next + case (3 treeList n summary m deg) + hence "deg \ 2" + by (metis Suc_1 add_mono_thms_linordered_semiring(1) le_add1 plus_1_eq_Suc set_n_deg_not_0) + moreover hence "height (Node None deg treeList summary) \ 1" using height.simps(2)[of None deg treeList summary] by simp + ultimately show ?case using T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t.simps(4)[of "deg-2"treeList summary x] algebra_simps + by (smt (z3) Suc_1 add_lessD1 eval_nat_numeral(3) le_add_diff_inverse less_Suc_eq_le linorder_not_less mult.left_neutral plus_1_eq_Suc) +next + case (4 treeList n summary m deg mi ma) + hence "deg \ 2" + by (metis add_self_div_2 deg_not_0 div_greater_zero_iff) + let ?xn = "(if x < mi then mi else x)" + let ?minn = "(if x< mi then x else mi)" + let ?l= "low ?xn (deg div 2)" + let ?h = "high ?xn (deg div 2)" + show ?case + proof(cases "x < mi") + case True + hence 0:"T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x = 19+ + ( if ?h < length treeList \ \ (x = mi \ x = ma)then + T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (treeList ! ?h) ?l + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l (treeList ! ?h)+ + (if minNull (treeList ! ?h) then T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t summary ?h else 1) else 1)" + using T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t.simps(5)[of mi ma "deg -2 " treeList summary x] + by (smt (z3) \2 \ deg\ add_2_eq_Suc le_add_diff_inverse) + then show ?thesis + proof(cases " ?h < length treeList \ \ (x = mi \ x = ma)") + case True + hence 1: "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x = 19+ + T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (treeList ! ?h) ?l + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l (treeList ! ?h)+ + (if minNull (treeList ! ?h) then T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t summary ?h else 1)" + using 0 by simp + then show ?thesis + proof(cases " minNull (treeList ! ?h)") + case True + hence " T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (treeList ! ?h) ?l \ 3" + by (smt (z3) "0" "1" "4.IH"(1) insertsimp le_add1 nat_add_left_cancel_le nth_mem numeral_3_eq_3 order_trans plus_1_eq_Suc) + hence 2: "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x \ 22 + + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l (treeList ! ?h)+ + (if minNull (treeList ! ?h) then T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t summary ?h else 1)" + using 1 algebra_simps by simp + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x \ 23 + + (if minNull (treeList ! ?h) then T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t summary ?h else 1)" + by (smt (verit, ccfv_SIG) add.commute minNull_bound nat_add_left_cancel_le numeral_Bit0 numeral_Bit1 order_trans) + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x \ 23 + T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t summary ?h" using True by simp + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x \ 23 + (height summary +1)*23" using "4.IH"(2) + by (smt (verit) add.commute add_le_cancel_left add_le_mono add_mono_thms_linordered_semiring(1) nat_add_left_cancel_le) + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x \ ((1+ height summary)+1 )*23" by simp + then show ?thesis using height_compose_summary[of summary "Some (mi, ma)" deg treeList] algebra_simps + by (simp add: \1 + height summary \ height (Node (Some (mi, ma)) deg treeList summary)\ \T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi, ma)) deg treeList summary) x \ (1 + height summary + 1) * 23\ add.assoc add.commute add.left_commute add_diff_eq diff_add_eq diff_diff_add diff_diff_eq2 diff_eq_eq diff_le_eq diff_less_eq distrib_left distrib_right eq_diff_eq le_diff_eq left_diff_distrib left_diff_distrib' less_diff_eq mult.assoc mult.commute mult.left_commute power_mult_distrib right_diff_distrib right_diff_distrib' scaleR_add_left scaleR_add_right scale_left_diff_distrib scale_right_diff_distrib add_mono le_trans mult_le_mono order_refl) + next + case False + hence 2:"T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x = 20+ + T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (treeList ! ?h) ?l + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l (treeList ! ?h)" using 1 by simp + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x \ 23+ T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (treeList ! ?h) ?l " + using minNull_bound[of "treeList ! ?h"] algebra_simps by linarith + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x \ 23+ (1+ height (treeList ! ?h))*23" + by (meson "4.IH"(1) True nat_add_left_cancel_le nth_mem order_trans) + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x \ ((1+ height (treeList!?h))+1)*23" by simp + moreover have " (treeList!?h) \ set treeList" + using True nth_mem by blast + ultimately show ?thesis using height_compose_child[of "treeList!?h" treeList "Some (mi, ma)" deg summary] algebra_simps + by (smt (verit, ccfv_SIG) Suc_leI add.right_neutral le_add1 le_imp_less_Suc mult_le_mono order_trans plus_1_eq_Suc) + qed + next + case False + then show ?thesis + using "4.hyps"(2) "4.hyps"(3) "4.hyps"(4) "4.hyps"(7) "4.hyps"(8) True high_bound_aux by auto + qed + next + case False + hence 0:"T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x = 19+ + ( if ?h < length treeList \ \ (x = mi \ x = ma)then + T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (treeList ! ?h) ?l + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l (treeList ! ?h)+ + (if minNull (treeList ! ?h) then T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t summary ?h else 1) else 1)" + using T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t.simps(5)[of mi ma "deg -2 " treeList summary x] + by (smt (z3) \2 \ deg\ add_2_eq_Suc le_add_diff_inverse) + then show ?thesis + proof(cases " ?h < length treeList \ \ (x = mi \ x = ma)") + case True + hence 1: "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x = 19+ + T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (treeList ! ?h) ?l + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l (treeList ! ?h)+ + (if minNull (treeList ! ?h) then T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t summary ?h else 1)" + using 0 by simp + then show ?thesis + proof(cases " minNull (treeList ! ?h)") + case True + hence " T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (treeList ! ?h) ?l \ 3" + by (smt (z3) "0" "1" "4.IH"(1) insertsimp le_add1 nat_add_left_cancel_le nth_mem numeral_3_eq_3 order_trans plus_1_eq_Suc) + hence 2: "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x \ 22 + + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l (treeList ! ?h)+ + (if minNull (treeList ! ?h) then T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t summary ?h else 1)" + using 1 algebra_simps by simp + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x \ 23 + + (if minNull (treeList ! ?h) then T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t summary ?h else 1)" + by (smt (verit, ccfv_SIG) add.commute minNull_bound nat_add_left_cancel_le numeral_Bit0 numeral_Bit1 order_trans) + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x \ 23 + T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t summary ?h" using True by simp + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x \ 23 + (height summary +1)*23" using "4.IH"(2) + by (smt (verit) add.commute add_le_cancel_left add_le_mono add_mono_thms_linordered_semiring(1) nat_add_left_cancel_le) + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x \ ((1+ height summary)+1 )*23" by simp + then show ?thesis using height_compose_summary[of summary "Some (mi, ma)" deg treeList] algebra_simps + by (simp add: \1 + height summary \ height (Node (Some (mi, ma)) deg treeList summary)\ \T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi, ma)) deg treeList summary) x \ (1 + height summary + 1) * 23\ add.assoc add.commute add.left_commute add_diff_eq diff_add_eq diff_diff_add diff_diff_eq2 diff_eq_eq diff_le_eq diff_less_eq distrib_left distrib_right eq_diff_eq le_diff_eq left_diff_distrib left_diff_distrib' less_diff_eq mult.assoc mult.commute mult.left_commute power_mult_distrib right_diff_distrib right_diff_distrib' scaleR_add_left scaleR_add_right scale_left_diff_distrib scale_right_diff_distrib add_mono le_trans mult_le_mono order_refl) + next + case False + hence 2:"T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x = 20+ + T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (treeList ! ?h) ?l + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l (treeList ! ?h)" using 1 by simp + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x \ 23+ T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (treeList ! ?h) ?l " + using minNull_bound[of "treeList ! ?h"] algebra_simps by linarith + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x \ 23+ (1+ height (treeList ! ?h))*23" + by (meson "4.IH"(1) True nat_add_left_cancel_le nth_mem order_trans) + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x \ ((1+ height (treeList!?h))+1)*23" by simp + moreover have " (treeList!?h) \ set treeList" + using True nth_mem by blast + ultimately show ?thesis using height_compose_child[of "treeList!?h" treeList "Some (mi, ma)" deg summary] algebra_simps + by (smt (verit, ccfv_SIG) Suc_leI add.right_neutral le_add1 le_imp_less_Suc mult_le_mono order_trans plus_1_eq_Suc) + qed + next + case False + then show ?thesis + using "0" by force + qed + qed +next + case (5 treeList n summary m deg mi ma) + hence "deg \ 2" + by (metis Suc_1 add_mono_thms_linordered_semiring(1) le_add1 plus_1_eq_Suc set_n_deg_not_0) + let ?xn = "(if x < mi then mi else x)" + let ?minn = "(if x< mi then x else mi)" + let ?l= "low ?xn (deg div 2)" + let ?h = "high ?xn (deg div 2)" + show ?case + proof(cases "x < mi") + case True + hence 0:"T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x = 19+ + ( if ?h < length treeList \ \ (x = mi \ x = ma)then + T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (treeList ! ?h) ?l + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l (treeList ! ?h)+ + (if minNull (treeList ! ?h) then T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t summary ?h else 1) else 1)" + using T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t.simps(5)[of mi ma "deg -2 " treeList summary x] + by (smt (z3) \2 \ deg\ add_2_eq_Suc le_add_diff_inverse) + then show ?thesis + proof(cases " ?h < length treeList \ \ (x = mi \ x = ma)") + case True + hence 1: "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x = 19+ + T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (treeList ! ?h) ?l + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l (treeList ! ?h)+ + (if minNull (treeList ! ?h) then T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t summary ?h else 1)" + using 0 by simp + then show ?thesis + proof(cases " minNull (treeList ! ?h)") + case True + hence " T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (treeList ! ?h) ?l \ 3" + by (smt (z3) "0" "1" "5.IH"(1) insertsimp le_add1 nat_add_left_cancel_le nth_mem numeral_3_eq_3 order_trans plus_1_eq_Suc) + hence 2: "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x \ 22 + + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l (treeList ! ?h)+(if minNull (treeList ! ?h) then T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t summary ?h else 1)" + using 1 algebra_simps by simp + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x \ + 23 + (if minNull (treeList ! ?h) then T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t summary ?h else 1)" + by (smt (verit, ccfv_SIG) add.commute minNull_bound nat_add_left_cancel_le numeral_Bit0 numeral_Bit1 order_trans) + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x \ 23 + T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t summary ?h" using True by simp + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x \ 23 + (height summary +1)*23" using "5.IH"(2) + by (smt (verit) add.commute add_le_cancel_left add_le_mono add_mono_thms_linordered_semiring(1) nat_add_left_cancel_le) + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x \ ((1+ height summary)+1 )*23" by simp + then show ?thesis using height_compose_summary[of summary "Some (mi, ma)" deg treeList] algebra_simps + by (simp add: \1 + height summary \ height (Node (Some (mi, ma)) deg treeList summary)\ \T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi, ma)) deg treeList summary) x \ (1 + height summary + 1) * 23\ add.assoc add.commute add.left_commute add_diff_eq diff_add_eq diff_diff_add diff_diff_eq2 diff_eq_eq diff_le_eq diff_less_eq distrib_left distrib_right eq_diff_eq le_diff_eq left_diff_distrib left_diff_distrib' less_diff_eq mult.assoc mult.commute mult.left_commute power_mult_distrib right_diff_distrib right_diff_distrib' scaleR_add_left scaleR_add_right scale_left_diff_distrib scale_right_diff_distrib add_mono le_trans mult_le_mono order_refl) + next + case False + hence 2:"T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x = 20+ + T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (treeList ! ?h) ?l + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l (treeList ! ?h)" using 1 by simp + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x \ 23+ T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (treeList ! ?h) ?l " + using minNull_bound[of "treeList ! ?h"] algebra_simps by linarith + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x \ 23+ (1+ height (treeList ! ?h))*23" + by (meson "5.IH"(1) True nat_add_left_cancel_le nth_mem order_trans) + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x \ ((1+ height (treeList!?h))+1)*23" by simp + moreover have " (treeList!?h) \ set treeList" + using True nth_mem by blast + ultimately show ?thesis using height_compose_child[of "treeList!?h" treeList "Some (mi, ma)" deg summary] algebra_simps + by (smt (verit, ccfv_SIG) Suc_leI add.right_neutral le_add1 le_imp_less_Suc mult_le_mono order_trans plus_1_eq_Suc) + qed + next + case False + then show ?thesis + by (smt (z3) "0" Suc_eq_plus1 Suc_numeral add_lessD1 linorder_not_less mult_Suc not_add_less1 plus_1_eq_Suc semiring_norm(5) semiring_norm(8)) + qed + next + case False + hence 0:"T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x = 19+ + ( if ?h < length treeList \ \ (x = mi \ x = ma)then + T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (treeList ! ?h) ?l + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l (treeList ! ?h)+ + (if minNull (treeList ! ?h) then T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t summary ?h else 1) else 1)" + using T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t.simps(5)[of mi ma "deg -2 " treeList summary x] + by (smt (z3) \2 \ deg\ add_2_eq_Suc le_add_diff_inverse) + then show ?thesis + proof(cases " ?h < length treeList \ \ (x = mi \ x = ma)") + case True + hence 1: "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x = 19+ + T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (treeList ! ?h) ?l + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l (treeList ! ?h)+ + (if minNull (treeList ! ?h) then T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t summary ?h else 1)" + using 0 by simp + then show ?thesis + proof(cases " minNull (treeList ! ?h)") + case True + hence " T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (treeList ! ?h) ?l \ 3" + by (smt (z3) "0" "1" "5.IH"(1) insertsimp le_add1 nat_add_left_cancel_le nth_mem + numeral_3_eq_3 order_trans plus_1_eq_Suc) + hence 2: "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x \ 22 + + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l (treeList ! ?h)+(if minNull (treeList ! ?h) then T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t summary ?h else 1)" + using 1 algebra_simps by simp + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x \ 23 + + (if minNull (treeList ! ?h) then T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t summary ?h else 1)" + by (smt (verit, ccfv_SIG) add.commute minNull_bound nat_add_left_cancel_le numeral_Bit0 numeral_Bit1 order_trans) + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x \ 23 + T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t summary ?h" using True by simp + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x \ 23 + (height summary +1)*23" using "5.IH"(2) + by (smt (verit) add.commute add_le_cancel_left add_le_mono add_mono_thms_linordered_semiring(1) nat_add_left_cancel_le) + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x \ ((1+ height summary)+1 )*23" by simp + then show ?thesis using height_compose_summary[of summary "Some (mi, ma)" deg treeList] algebra_simps + by (simp add: \1 + height summary \ height (Node (Some (mi, ma)) deg treeList summary)\ \T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi, ma)) deg treeList summary) x \ (1 + height summary + 1) * 23\ add.assoc add.commute add.left_commute add_diff_eq diff_add_eq diff_diff_add diff_diff_eq2 diff_eq_eq diff_le_eq diff_less_eq distrib_left distrib_right eq_diff_eq le_diff_eq left_diff_distrib left_diff_distrib' less_diff_eq mult.assoc mult.commute mult.left_commute power_mult_distrib right_diff_distrib right_diff_distrib' scaleR_add_left scaleR_add_right scale_left_diff_distrib scale_right_diff_distrib add_mono le_trans mult_le_mono order_refl) + next + case False + hence 2:"T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x = 20+ + T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (treeList ! ?h) ?l + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l (treeList ! ?h)" using 1 by simp + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x \ 23+ T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (treeList ! ?h) ?l " + using minNull_bound[of "treeList ! ?h"] algebra_simps by linarith + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x \ 23+ (1+ height (treeList ! ?h))*23" + by (meson "5.IH"(1) True nat_add_left_cancel_le nth_mem order_trans) + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t (Node (Some (mi,ma)) deg treeList summary) x \ ((1+ height (treeList!?h))+1)*23" by simp + moreover have " (treeList!?h) \ set treeList" + using True nth_mem by blast + ultimately show ?thesis using height_compose_child[of "treeList!?h" treeList "Some (mi, ma)" deg summary] algebra_simps + by (smt (verit, ccfv_SIG) Suc_leI add.right_neutral le_add1 le_imp_less_Suc mult_le_mono order_trans plus_1_eq_Suc) + qed + next + case False + then show ?thesis + using "0" by force + qed + qed +qed + + +theorem insert_bound_size_univ: "invar_vebt t n \ u = 2^n \ T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t t x \ 46 + 23 * lb (lb u)" + using insert_bound_height[of t n x] height_double_log_univ_size[of u n t] algebra_simps by simp + +theorem insert'_bound_height: "invar_vebt t n \ T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' t x \ (1+height t)" +proof(induction t n arbitrary: x rule: invar_vebt.induct ) + case (2 treeList n summary m deg) + then show ?case apply(cases "deg \ 2") + apply (metis "2.hyps"(1) "2.hyps"(3) "2.hyps"(4) Suc_leI T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t'.simps(4) add_le_cancel_right deg_not_0 le_add2 le_add_diff_inverse nat_less_le plus_1_eq_Suc) + apply (metis add_self_div_2 deg_not_0 div_greater_zero_iff) + done +next + case (3 treeList n summary m deg) + then show ?case apply(cases "deg \ 2") + apply (metis T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t'.simps(4) add_Suc_shift leI le_Suc_ex not_add_less1 one_add_one plus_1_eq_Suc) + by (metis One_nat_def Suc_eq_plus1 T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t'.simps(3) add.commute add_mono le_SucE le_add1 numeral_2_eq_2) +next + case (4 treeList n summary m deg mi ma) + hence "deg \ 2" + by (metis add_self_div_2 deg_not_0 div_greater_zero_iff) + let ?xn = "(if x < mi then mi else x)" + let ?minn = "(if x< mi then x else mi)" + let ?l= "low ?xn (deg div 2)" + let ?h = "high ?xn (deg div 2)" + show ?case + proof(cases "x < mi") + case True + hence 0:"T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Node (Some (mi,ma)) deg treeList summary) x = + ( if ?h < length treeList \ \ (x = mi \ x = ma)then + T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (treeList ! ?h) ?l + (if minNull (treeList ! ?h) then T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' summary ?h else 1) else 1)" + using T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t'.simps(5)[of mi ma "deg -2 " treeList summary x] + by (smt (z3) \2 \ deg\ add_2_eq_Suc le_add_diff_inverse) + then show ?thesis + proof(cases " ?h < length treeList \ \ (x = mi \ x = ma)") + case True + hence 1: "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Node (Some (mi,ma)) deg treeList summary) x = + T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (treeList ! ?h) ?l +(if minNull (treeList ! ?h) then T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' summary ?h else 1)" + using 0 by simp + then show ?thesis + proof(cases " minNull (treeList ! ?h)") + case True + hence " T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (treeList ! ?h) ?l \ 1" + by (metis "0" "1" "4.IH"(1) insertsimp' nat_le_iff_add nth_mem) + hence 2: "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Node (Some (mi,ma)) deg treeList summary) x \ 1+ + (if minNull (treeList ! ?h) then T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' summary ?h else 1)" + using 1 algebra_simps by simp + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Node (Some (mi,ma)) deg treeList summary) x \ 1 + T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' summary ?h" using True by simp + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Node (Some (mi,ma)) deg treeList summary) x \ 1 + (height summary +1)" using "4.IH"(2) + using "1" \T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (treeList ! high (if x < mi then mi else x) (deg div 2)) (low (if x < mi then mi else x) (deg div 2)) \ 1\ add_mono_thms_linordered_semiring(1) by fastforce + then show ?thesis using height_compose_summary[of summary "Some (mi, ma)" deg treeList] algebra_simps by linarith + next + case False + hence 2:"T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Node (Some (mi,ma)) deg treeList summary) x = + 1+ T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (treeList ! ?h) ?l " using 1 by simp + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Node (Some (mi,ma)) deg treeList summary) x \ 1+ (1+ height (treeList ! ?h))" + using "4.IH"(1) True by force + moreover have " (treeList!?h) \ set treeList" + using True nth_mem by blast + ultimately show ?thesis using height_compose_child[of "treeList!?h" treeList "Some (mi, ma)" deg summary] algebra_simps + by (smt (verit, ccfv_SIG) Suc_leI add.right_neutral le_add1 le_imp_less_Suc mult_le_mono order_trans plus_1_eq_Suc) + qed + next + case False + then show ?thesis using "0" Suc_eq_plus1 le_add2 plus_1_eq_Suc by presburger + qed + next + case False + hence 0:"T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Node (Some (mi,ma)) deg treeList summary) x = + ( if ?h < length treeList \ \ (x = mi \ x = ma)then + T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (treeList ! ?h) ?l + (if minNull (treeList ! ?h) then T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' summary ?h else 1) else 1)" + using T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t'.simps(5)[of mi ma "deg -2 " treeList summary x] + by (smt (z3) \2 \ deg\ add_2_eq_Suc le_add_diff_inverse) + then show ?thesis + proof(cases " ?h < length treeList \ \ (x = mi \ x = ma)") + case True + hence 1: "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Node (Some (mi,ma)) deg treeList summary) x = + T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (treeList ! ?h) ?l + + (if minNull (treeList ! ?h) then T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' summary ?h else 1)" + using 0 by simp + then show ?thesis + proof(cases " minNull (treeList ! ?h)") + case True + hence " T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (treeList ! ?h) ?l \ 1" + by (smt (z3) "0" "1" "4.IH"(1) insertsimp' le_add1 nat_add_left_cancel_le nth_mem numeral_3_eq_3 order_trans plus_1_eq_Suc) + hence 2: "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Node (Some (mi,ma)) deg treeList summary) x \ 1+ + (if minNull (treeList ! ?h) then T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' summary ?h else 1)" + using 1 algebra_simps by simp + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Node (Some (mi,ma)) deg treeList summary) x \ 1 + T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' summary ?h" using True by simp + then show ?thesis using height_compose_summary[of summary "Some (mi, ma)" deg treeList] algebra_simps + by (smt (z3) "1" "4.IH"(2) True \T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (treeList ! high (if x < mi then mi else x) (deg div 2)) (low (if x < mi then mi else x) (deg div 2)) \ 1\ add_mono order_trans) + next + case False + hence 2:"T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Node (Some (mi,ma)) deg treeList summary) x = 1+ + T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (treeList ! ?h) ?l" using 1 by simp + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Node (Some (mi,ma)) deg treeList summary) x \ 1+ T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (treeList ! ?h) ?l " + using minNull_bound[of "treeList ! ?h"] algebra_simps by linarith + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Node (Some (mi,ma)) deg treeList summary) x \ 1+ (1+ height (treeList ! ?h))" + by (meson "4.IH"(1) True nat_add_left_cancel_le nth_mem order_trans) + moreover have " (treeList!?h) \ set treeList" + using True nth_mem by blast + ultimately show ?thesis using height_compose_child[of "treeList!?h" treeList "Some (mi, ma)" deg summary] algebra_simps + by (smt (verit, ccfv_SIG) Suc_leI add.right_neutral le_add1 le_imp_less_Suc mult_le_mono order_trans plus_1_eq_Suc) + qed + next + case False + then show ?thesis + using "0" by force + qed + qed +next + case (5 treeList n summary m deg mi ma) + hence "deg \ 2" + by (metis Suc_1 add_mono le_add1 plus_1_eq_Suc set_n_deg_not_0) + let ?xn = "(if x < mi then mi else x)" + let ?minn = "(if x< mi then x else mi)" + let ?l= "low ?xn (deg div 2)" + let ?h = "high ?xn (deg div 2)" + show ?case + proof(cases "x < mi") + case True + hence 0:"T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Node (Some (mi,ma)) deg treeList summary) x = + ( if ?h < length treeList \ \ (x = mi \ x = ma)then + T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (treeList ! ?h) ?l + + (if minNull (treeList ! ?h) then T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' summary ?h else 1) + else 1)" using T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t'.simps(5)[of mi ma "deg -2 " treeList summary x] + by (smt (z3) \2 \ deg\ add_2_eq_Suc le_add_diff_inverse) + then show ?thesis + proof(cases " ?h < length treeList \ \ (x = mi \ x = ma)") + case True + hence 1: "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Node (Some (mi,ma)) deg treeList summary) x = + T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (treeList ! ?h) ?l + (if minNull (treeList ! ?h) then T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' summary ?h else 1)" + using 0 by simp + then show ?thesis + proof(cases " minNull (treeList ! ?h)") + case True + hence " T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (treeList ! ?h) ?l \ 1" + by (metis "0" "1" "5.IH"(1) insertsimp' nat_le_iff_add nth_mem) + hence 2: "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Node (Some (mi,ma)) deg treeList summary) x \ 1+ + (if minNull (treeList ! ?h) then T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' summary ?h else 1)" + using 1 algebra_simps by simp + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Node (Some (mi,ma)) deg treeList summary) x \ 1 + T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' summary ?h" + using True by simp + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Node (Some (mi,ma)) deg treeList summary) x \ 1 + (height summary +1)" + using "5.IH"(2) "1" \T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (treeList ! high (if x < mi then mi else x) (deg div 2)) + (low (if x < mi then mi else x) (deg div 2)) \ 1\ add_mono_thms_linordered_semiring(1) + by fastforce + then show ?thesis using height_compose_summary[of summary "Some (mi, ma)" deg treeList] algebra_simps by linarith + next + case False + hence 2:"T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Node (Some (mi,ma)) deg treeList summary) x = + 1+ T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (treeList ! ?h) ?l " using 1 by simp + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Node (Some (mi,ma)) deg treeList summary) x \ 1+ (1+ height (treeList ! ?h))" + using "5.IH"(1) True by force + moreover have " (treeList!?h) \ set treeList" + using True nth_mem by blast + ultimately show ?thesis using height_compose_child[of "treeList!?h" treeList "Some (mi, ma)" deg summary] algebra_simps + by (smt (verit, ccfv_SIG) Suc_leI add.right_neutral le_add1 le_imp_less_Suc mult_le_mono order_trans plus_1_eq_Suc) + qed + next + case False + then show ?thesis using "0" Suc_eq_plus1 le_add2 plus_1_eq_Suc by presburger + qed + next + case False + hence 0:"T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Node (Some (mi,ma)) deg treeList summary) x = + ( if ?h < length treeList \ \ (x = mi \ x = ma)then + T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (treeList ! ?h) ?l + (if minNull (treeList ! ?h) then T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' summary ?h else 1) else 1)" + using T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t'.simps(5)[of mi ma "deg -2 " treeList summary x] + by (smt (z3) \2 \ deg\ add_2_eq_Suc le_add_diff_inverse) + then show ?thesis + proof(cases " ?h < length treeList \ \ (x = mi \ x = ma)") + case True + hence 1: "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Node (Some (mi,ma)) deg treeList summary) x = + T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (treeList ! ?h) ?l + (if minNull (treeList ! ?h) then T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' summary ?h else 1)" + using 0 by simp + then show ?thesis + proof(cases " minNull (treeList ! ?h)") + case True + hence " T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (treeList ! ?h) ?l \ 1" + by (smt (z3) "0" "1" "5.IH"(1) insertsimp' le_add1 nat_add_left_cancel_le nth_mem numeral_3_eq_3 order_trans plus_1_eq_Suc) + hence 2: "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Node (Some (mi,ma)) deg treeList summary) x \ 1+ + (if minNull (treeList ! ?h) then T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' summary ?h else 1)" + using 1 algebra_simps by simp + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Node (Some (mi,ma)) deg treeList summary) x \ 1 + T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' summary ?h" + using True by simp + then show ?thesis + using height_compose_summary[of summary "Some (mi, ma)" deg treeList] algebra_simps + by (smt (z3) "1" "5.IH"(2) True \T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (treeList ! high (if x < mi then mi else x) (deg div 2)) (low (if x < mi then mi else x) (deg div 2)) \ 1\ add_mono order_trans) + next + case False + hence 2:"T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Node (Some (mi,ma)) deg treeList summary) x = 1+ + T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (treeList ! ?h) ?l" using 1 by simp + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Node (Some (mi,ma)) deg treeList summary) x \ 1+ T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (treeList ! ?h) ?l " + using minNull_bound[of "treeList ! ?h"] algebra_simps by linarith + hence "T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t' (Node (Some (mi,ma)) deg treeList summary) x \ 1+ (1+ height (treeList ! ?h))" + by (meson "5.IH"(1) True nat_add_left_cancel_le nth_mem order_trans) + moreover have " (treeList!?h) \ set treeList" + using True nth_mem by blast + ultimately show ?thesis using height_compose_child[of "treeList!?h" treeList "Some (mi, ma)" deg summary] algebra_simps + by (smt (verit, ccfv_SIG) Suc_leI add.right_neutral le_add1 le_imp_less_Suc mult_le_mono order_trans plus_1_eq_Suc) + qed + next + case False + then show ?thesis + using "0" by force + qed + qed +qed simp+ + +subsection \Successor Function\ + +fun T\<^sub>s\<^sub>u\<^sub>c\<^sub>c::"VEBT \ nat \ nat" where + "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Leaf _ b) 0 = 1+ (if b then 1 else 1)"| + "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Leaf _ _) (Suc n) = 1"| + "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node None _ _ _) _ = 1"| + "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node _ 0 _ _) _ = 1"| + "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node _ (Suc 0) _ _) _ = 1"| + "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x = 1+ ( + if x < mi then 1 + else (let l = low x (deg div 2); h = high x (deg div 2) in 10 + + (if h < length treeList then 1+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (treeList ! h) + ( + let maxlow = vebt_maxt (treeList ! h) in 3 + + (if maxlow \ None \ (Some l <\<^sub>o maxlow) then + 4 + T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (treeList ! h) l + else let sc = vebt_succ summary h in 1+ T\<^sub>s\<^sub>u\<^sub>c\<^sub>c summary h + 1 + ( + if sc = None then 1 + else (4 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>t (treeList ! the sc) )))) + + else 1)))" + +fun T\<^sub>s\<^sub>u\<^sub>c\<^sub>c'::"VEBT \ nat \ nat" where + "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c' (Leaf _ b) 0 = 1"| + "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c' (Leaf _ _) (Suc n) = 1"| + "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c' (Node None _ _ _) _ = 1"| + "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c' (Node _ 0 _ _) _ = 1"| + "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c' (Node _ (Suc 0) _ _) _ = 1"| + "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c' (Node (Some (mi, ma)) deg treeList summary) x =( + if x < mi then 1 + else (let l = low x (deg div 2); h = high x (deg div 2) in + (if h < length treeList then ( + let maxlow = vebt_maxt (treeList ! h) in + (if maxlow \ None \ (Some l <\<^sub>o maxlow) then + 1+ T\<^sub>s\<^sub>u\<^sub>c\<^sub>c' (treeList ! h) l + else let sc = vebt_succ summary h in T\<^sub>s\<^sub>u\<^sub>c\<^sub>c' summary h + ( + if sc = None then 1 + else 1 ))) + else 1)))" + +theorem succ_bound_height: "invar_vebt t n \ T\<^sub>s\<^sub>u\<^sub>c\<^sub>c t x \ (1+height t)*27" +proof(induction t n arbitrary: x rule: invar_vebt.induct) + case (1 a b) + then show ?case using T\<^sub>s\<^sub>u\<^sub>c\<^sub>c.simps(1)[of a b] + proof - + have "\b v ba n. T\<^sub>s\<^sub>u\<^sub>c\<^sub>c v n = 1 \ Leaf b ba \ v \ 0 = n" + using T\<^sub>s\<^sub>u\<^sub>c\<^sub>c.elims by blast + then show ?thesis + by (metis (no_types) Nat.add_0_right \T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Leaf a b) 0 = 1 + (if b then 1 else 1)\ height.simps(1) nat_mult_1 numeral_le_iff one_add_one one_le_numeral semiring_norm(68) semiring_norm(72)) + qed +next + case (2 treeList n summary m deg) + then show ?case by simp +next + case (3 treeList n summary m deg) + then show ?case by simp +next + case (4 treeList n summary m deg mi ma) + hence "deg \ 2" + by (metis add_self_div_2 deg_not_0 div_greater_zero_iff) + then show ?case + proof(cases "x < mi") + case True + then show ?thesis using T\<^sub>s\<^sub>u\<^sub>c\<^sub>c.simps(6)[of mi ma "deg-2" treeList summary x] + by (smt (z3) Suc_leI \2 \ deg\ add_2_eq_Suc distrib_right le_add_diff_inverse linorder_not_less mult.left_neutral numeral_le_one_iff plus_1_eq_Suc semiring_norm(70) trans_le_add1) + next + case False + let ?l = "low x (deg div 2)" + let ?h = "high x (deg div 2)" + show ?thesis + proof(cases "?h < length treeList") + case True + hence "?h < length treeList" by simp + hence 0:"T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x =12 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (treeList ! ?h) + ( + let maxlow = vebt_maxt (treeList ! ?h) in 3 + + (if maxlow \ None \ (Some ?l <\<^sub>o maxlow) then + 4 + T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (treeList ! ?h) ?l + else let sc = vebt_succ summary ?h in 1+ T\<^sub>s\<^sub>u\<^sub>c\<^sub>c summary ?h + 1 + ( + if sc = None then 1 + else (4 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>t (treeList ! the sc) ))))" using + T\<^sub>s\<^sub>u\<^sub>c\<^sub>c.simps(6)[of mi ma "deg-2" treeList summary x] False True + by (smt (z3) \2 \ deg\ add.commute add.left_commute add_2_eq_Suc' le_add_diff_inverse numeral_plus_one semiring_norm(5) semiring_norm(8)) + let ?maxlow= "vebt_maxt (treeList ! ?h)" + let ?sc="vebt_succ summary ?h" + have 1:"T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x =15 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (treeList ! ?h) + + (if ?maxlow \ None \ (Some ?l <\<^sub>o ?maxlow) then + 4 + T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (treeList ! ?h) ?l + else 2+ T\<^sub>s\<^sub>u\<^sub>c\<^sub>c summary ?h + ( + if ?sc = None then 1 + else (4 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>t (treeList ! the ?sc))))" using 0 by auto + then show ?thesis + proof(cases " ?maxlow \ None \ (Some ?l <\<^sub>o ?maxlow)") + case True + hence "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x = + 19 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (treeList ! ?h) + T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (treeList ! ?h) ?l" + using 1 by simp + hence "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x \ + 22 + T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (treeList ! ?h) ?l" using maxt_bound[of "treeList ! ?h"] + by simp + moreover have a:"treeList ! ?h \ set treeList " + by (simp add: \high x (deg div 2) < length treeList\) + ultimately have "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x \ + 22 + (1+ height (treeList ! ?h))*27" + by (meson "4.IH"(1) nat_add_left_cancel_le order_trans) + hence "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x \ + ((1+ height (treeList ! ?h))+1)*27" by simp + then show ?thesis + using height_compose_child[of "treeList ! ?h" treeList "Some (mi, ma)" deg summary] a + by (smt (z3) Suc_leI add.commute dual_order.strict_trans2 le_imp_less_Suc linorder_not_less mult.commute mult_le_mono2 plus_1_eq_Suc) + next + case False + have 2:"T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x =17 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (treeList ! ?h) + + T\<^sub>s\<^sub>u\<^sub>c\<^sub>c summary ?h + ( + if ?sc = None then 1 + else (4 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>t (treeList ! the ?sc)))" using 1 + by (smt (z3) False Suc_eq_plus1 add.assoc add.commute add_2_eq_Suc' eval_nat_numeral(3) numeral_plus_one semiring_norm(2) semiring_norm(8)) + then show ?thesis + proof(cases " ?sc = None") + case True + hence 3:"T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x = + 18 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (treeList ! ?h) + T\<^sub>s\<^sub>u\<^sub>c\<^sub>c summary ?h " + using 2 by simp + hence "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x \ 21 + T\<^sub>s\<^sub>u\<^sub>c\<^sub>c summary ?h" + using maxt_bound[of "treeList ! ?h"] by simp + hence "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x \ 21 + (1+ height summary)*27" + by (metis "3" "4.IH"(2) add_le_cancel_right add_le_mono) + then show ?thesis using height_compose_summary[of summary "Some (mi, ma)" deg treeList] by presburger + next + case False + hence 3:"T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x =21 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (treeList ! ?h) + + T\<^sub>s\<^sub>u\<^sub>c\<^sub>c summary ?h + T\<^sub>m\<^sub>i\<^sub>n\<^sub>t (treeList ! the ?sc)" using 2 by simp + hence "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x \ 27+ T\<^sub>s\<^sub>u\<^sub>c\<^sub>c summary ?h " + using maxt_bound[of "treeList ! ?h"] mint_bound[of "treeList ! the ?sc"] by simp + hence "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x \ 27+ (1+height summary)*27" + by (meson "4.IH"(2) add_mono_thms_linordered_semiring(2) dual_order.trans) + hence "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x \ ((1+height summary)+1)*27" by simp + hence "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x \ (height (Node (Some (mi, ma)) deg treeList summary) + 1)*27" + using height_compose_summary[of summary "Some (mi, ma)" deg treeList] + by (simp add: \1 + height summary \ height (Node (Some (mi, ma)) deg treeList summary)\ \T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x \ (1 + height summary + 1) * 27\ add.commute add_mono le_numeral_extra(4) le_trans mult.commute mult_le_mono2) + then show ?thesis by simp + qed + qed + next + case False + hence " T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x = 12" + using T\<^sub>s\<^sub>u\<^sub>c\<^sub>c.simps(6)[of mi ma "deg-2" treeList summary x] + by (smt (z3) "4.hyps"(2) "4.hyps"(3) "4.hyps"(4) "4.hyps"(7) "4.hyps"(8) \2 \ deg\ add_Suc add_self_div_2 dual_order.strict_trans2 high_bound_aux le_add_diff_inverse less_imp_le_nat numeral_plus_one numerals(1) plus_1_eq_Suc semiring_norm(2) semiring_norm(5) semiring_norm(8)) + then show ?thesis + by auto + qed + qed +next + case (5 treeList n summary m deg mi ma) + hence "deg \ 2" + by (metis Suc_1 add_mono_thms_linordered_semiring(1) le_add1 plus_1_eq_Suc set_n_deg_not_0) + then show ?case + proof(cases "x < mi") + case True + then show ?thesis + using T\<^sub>s\<^sub>u\<^sub>c\<^sub>c.simps(6)[of mi ma "deg-2" treeList summary x] + by (smt (z3) Suc_leI \2 \ deg\ add_2_eq_Suc distrib_right le_add_diff_inverse linorder_not_less mult.left_neutral numeral_le_one_iff plus_1_eq_Suc semiring_norm(70) trans_le_add1) + next + case False + let ?l = "low x (deg div 2)" + let ?h = "high x (deg div 2)" + show ?thesis + proof(cases "?h < length treeList") + case True + hence "?h < length treeList" by simp + hence 0:"T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x =12 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (treeList ! ?h) + ( + let maxlow = vebt_maxt (treeList ! ?h) in 3 + + (if maxlow \ None \ (Some ?l <\<^sub>o maxlow) then + 4 + T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (treeList ! ?h) ?l + else let sc = vebt_succ summary ?h in 1+ T\<^sub>s\<^sub>u\<^sub>c\<^sub>c summary ?h + 1 + ( + if sc = None then 1 + else (4 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>t (treeList ! the sc) ))))" using + T\<^sub>s\<^sub>u\<^sub>c\<^sub>c.simps(6)[of mi ma "deg-2" treeList summary x] False True + by (smt (z3) \2 \ deg\ add.commute add.left_commute add_2_eq_Suc' le_add_diff_inverse numeral_plus_one semiring_norm(5) semiring_norm(8)) + let ?maxlow= "vebt_maxt (treeList ! ?h)" + let ?sc="vebt_succ summary ?h" + have 1:"T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x =15 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (treeList ! ?h) + + (if ?maxlow \ None \ (Some ?l <\<^sub>o ?maxlow) then + 4 + T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (treeList ! ?h) ?l + else 2+ T\<^sub>s\<^sub>u\<^sub>c\<^sub>c summary ?h + ( + if ?sc = None then 1 + else (4 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>t (treeList ! the ?sc))))" using 0 by auto + then show ?thesis + proof(cases " ?maxlow \ None \ (Some ?l <\<^sub>o ?maxlow)") + case True + hence "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x = + 19 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (treeList ! ?h) + T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (treeList ! ?h) ?l" using 1 by simp + hence "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x \ + 22 + T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (treeList ! ?h) ?l" using maxt_bound[of "treeList ! ?h"] by simp + moreover have a:"treeList ! ?h \ set treeList " + by (simp add: \high x (deg div 2) < length treeList\) + ultimately have "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x \ + 22 + (1+ height (treeList ! ?h))*27" + by (meson "5.IH"(1) nat_add_left_cancel_le order_trans) + hence "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x \ + ((1+ height (treeList ! ?h))+1)*27" by simp + then show ?thesis using height_compose_child[of "treeList ! ?h" treeList "Some (mi, ma)" deg summary] a + by (smt (z3) Suc_leI add.commute dual_order.strict_trans2 le_imp_less_Suc linorder_not_less mult.commute mult_le_mono2 plus_1_eq_Suc) + next + case False + have 2:"T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x =17 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (treeList ! ?h) + + T\<^sub>s\<^sub>u\<^sub>c\<^sub>c summary ?h + ( + if ?sc = None then 1 + else (4 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>t (treeList ! the ?sc)))" using 1 + by (smt (z3) False Suc_eq_plus1 add.assoc add.commute add_2_eq_Suc' eval_nat_numeral(3) numeral_plus_one semiring_norm(2) semiring_norm(8)) + then show ?thesis + proof(cases " ?sc = None") + case True + hence 3:"T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x =18 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (treeList ! ?h) + + T\<^sub>s\<^sub>u\<^sub>c\<^sub>c summary ?h " using 2 by simp + hence "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x \ 21 + T\<^sub>s\<^sub>u\<^sub>c\<^sub>c summary ?h" + using maxt_bound[of "treeList ! ?h"] by simp + hence "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x \ 21 + (1+ height summary)*27" + by (metis "3" "5.IH"(2) add_le_cancel_right add_le_mono) + then show ?thesis using height_compose_summary[of summary "Some (mi, ma)" deg treeList] by presburger + next + case False + hence 3:"T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x =21 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (treeList ! ?h) + + T\<^sub>s\<^sub>u\<^sub>c\<^sub>c summary ?h + T\<^sub>m\<^sub>i\<^sub>n\<^sub>t (treeList ! the ?sc)" using 2 by simp + hence "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x \ 27+ T\<^sub>s\<^sub>u\<^sub>c\<^sub>c summary ?h " + using maxt_bound[of "treeList ! ?h"] mint_bound[of "treeList ! the ?sc"] by simp + hence "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x \ 27+ (1+height summary)*27" + by (meson "5.IH"(2) add_mono_thms_linordered_semiring(2) dual_order.trans) + hence "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x \ ((1+height summary)+1)*27" by simp + hence "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x \ (height (Node (Some (mi, ma)) deg treeList summary) + 1)*27" + using height_compose_summary[of summary "Some (mi, ma)" deg treeList] + by (simp add: \1 + height summary \ height (Node (Some (mi, ma)) deg treeList summary)\ \T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x \ (1 + height summary + 1) * 27\ add.commute add_mono le_numeral_extra(4) le_trans mult.commute mult_le_mono2) + then show ?thesis by simp + qed + qed + next + case False + hence " T\<^sub>s\<^sub>u\<^sub>c\<^sub>c (Node (Some (mi, ma)) deg treeList summary) x = 12" using + T\<^sub>s\<^sub>u\<^sub>c\<^sub>c.simps(6)[of mi ma "deg-2" treeList summary x] "5.hyps"(2) "5.hyps"(3) "5.hyps"(4) + "5.hyps"(7) "5.hyps"(8) \2 \ deg\ add_Suc add_self_div_2 dual_order.strict_trans2 + high_bound_aux le_add_diff_inverse less_imp_le_nat numeral_plus_one numerals(1) + plus_1_eq_Suc semiring_norm(2) semiring_norm(5) semiring_norm(8) apply auto + by (smt (z3) "5.hyps"(4) le_less_trans less_trans power_Suc) + then show ?thesis + by auto + qed + qed +qed + +theorem succ_bound_size_univ: "invar_vebt t n \ u = 2^n \ T\<^sub>s\<^sub>u\<^sub>c\<^sub>c t x \ 54 + 27 * lb (lb u)" + using succ_bound_height[of t n x] height_double_log_univ_size[of u n t] by simp + +theorem succ'_bound_height: "invar_vebt t n \ T\<^sub>s\<^sub>u\<^sub>c\<^sub>c' t x \ (1+height t)" +proof(induction t n arbitrary: x rule: invar_vebt.induct) + case (1 a b) + then show ?case + by (metis One_nat_def T\<^sub>s\<^sub>u\<^sub>c\<^sub>c'.simps(1) T\<^sub>s\<^sub>u\<^sub>c\<^sub>c'.simps(2) height.simps(1) le_add2 le_add_same_cancel2 le_neq_implies_less less_imp_Suc_add order_refl plus_1_eq_Suc) +next + case (4 treeList n summary m deg mi ma) + hence degprop: "deg \ 2" + by (metis add_self_div_2 deg_not_0 div_greater_zero_iff) + then show ?case + proof(cases "x< mi") + case True + then show ?thesis using T\<^sub>s\<^sub>u\<^sub>c\<^sub>c'.simps(6)[of mi ma "deg-2" treeList summary x] degprop + by (metis add_2_eq_Suc le_add_diff_inverse le_numeral_extra(4) trans_le_add1) + next + case False + hence "x \ mi" by simp + let ?l = "low x (deg div 2)" + let ?h = "high x (deg div 2)" + show ?thesis + proof(cases "?h < length treeList") + case True + hence hprop: "?h < length treeList" by simp + let ?maxlow = "vebt_maxt (treeList ! ?h)" + show ?thesis + proof(cases " ?maxlow \ None \ (Some ?l <\<^sub>o ?maxlow)") + case True + hence "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c' (Node (Some (mi, ma)) deg treeList summary) x = 1+ T\<^sub>s\<^sub>u\<^sub>c\<^sub>c' (treeList ! ?h) ?l" + using T\<^sub>s\<^sub>u\<^sub>c\<^sub>c'.simps(6)[of mi ma "deg-2" treeList summary x] degprop hprop + by (smt (z3) False add_2_eq_Suc le_add_diff_inverse) + moreover have " (treeList ! ?h) \ set treeList" + using hprop nth_mem by blast + moreover have " T\<^sub>s\<^sub>u\<^sub>c\<^sub>c' (treeList ! ?h) ?l \ 1+ height (treeList ! ?h)" using 4(1) calculation by blast + ultimately have "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c' (Node (Some (mi, ma)) deg treeList summary) x \ 1 + 1+ height (treeList ! ?h)" by simp + then show ?thesis + by (smt (z3) Suc_le_mono \T\<^sub>s\<^sub>u\<^sub>c\<^sub>c' (Node (Some (mi, ma)) deg treeList summary) x = 1 + T\<^sub>s\<^sub>u\<^sub>c\<^sub>c' (treeList ! high x (deg div 2)) (low x (deg div 2))\ \T\<^sub>s\<^sub>u\<^sub>c\<^sub>c' (treeList ! high x (deg div 2)) (low x (deg div 2)) \ 1 + height (treeList ! high x (deg div 2))\ \treeList ! high x (deg div 2) \ set treeList\ height_compose_child le_trans plus_1_eq_Suc) + next + case False + hence "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c' (Node (Some (mi, ma)) deg treeList summary) x = 1+ T\<^sub>s\<^sub>u\<^sub>c\<^sub>c' summary ?h" + using T\<^sub>s\<^sub>u\<^sub>c\<^sub>c'.simps(6)[of mi ma "deg-2" treeList summary x] degprop hprop + apply(cases " vebt_succ summary ?h") using False add_2_eq_Suc le_add_diff_inverse + apply (smt (z3) Suc_eq_plus1 \mi \ x\ linorder_not_less plus_1_eq_Suc)+ + done + moreover have " T\<^sub>s\<^sub>u\<^sub>c\<^sub>c' summary ?h \ 1+ height summary" using 4(2) calculation by blast + ultimately have "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c' (Node (Some (mi, ma)) deg treeList summary) x \ 1 + 1+ height summary" by simp + then show ?thesis + by (simp add: le_trans) + qed + next + case False + then show ?thesis using T\<^sub>s\<^sub>u\<^sub>c\<^sub>c'.simps(6)[of mi ma "deg-2" treeList summary x] degprop + by (smt (z3) add_2_eq_Suc leI le_add_diff_inverse not_add_less1) + qed + qed +next + case (5 treeList n summary m deg mi ma) + hence degprop: "deg \ 2" + by (metis Suc_1 add_mono le_add1 plus_1_eq_Suc set_n_deg_not_0) + then show ?case + proof(cases "x< mi") + case True + then show ?thesis using T\<^sub>s\<^sub>u\<^sub>c\<^sub>c'.simps(6)[of mi ma "deg-2" treeList summary x] degprop + by (metis add_2_eq_Suc le_add_diff_inverse le_numeral_extra(4) trans_le_add1) + next + case False + hence "x \ mi" by simp + let ?l = "low x (deg div 2)" + let ?h = "high x (deg div 2)" + show ?thesis + proof(cases "?h < length treeList") + case True + hence hprop: "?h < length treeList" by simp + let ?maxlow = "vebt_maxt (treeList ! ?h)" + show ?thesis + proof(cases " ?maxlow \ None \ (Some ?l <\<^sub>o ?maxlow)") + case True + hence "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c' (Node (Some (mi, ma)) deg treeList summary) x = 1+ T\<^sub>s\<^sub>u\<^sub>c\<^sub>c' (treeList ! ?h) ?l" + using T\<^sub>s\<^sub>u\<^sub>c\<^sub>c'.simps(6)[of mi ma "deg-2" treeList summary x] degprop hprop + by (smt (z3) False add_2_eq_Suc le_add_diff_inverse) + moreover have " (treeList ! ?h) \ set treeList" + using hprop nth_mem by blast + moreover have " T\<^sub>s\<^sub>u\<^sub>c\<^sub>c' (treeList ! ?h) ?l \ 1+ height (treeList ! ?h)" using 5(1) calculation by blast + ultimately have "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c' (Node (Some (mi, ma)) deg treeList summary) x \ 1 + 1+ height (treeList ! ?h)" by simp + then show ?thesis + by (smt (z3) Suc_le_mono \T\<^sub>s\<^sub>u\<^sub>c\<^sub>c' (Node (Some (mi, ma)) deg treeList summary) x = 1 + T\<^sub>s\<^sub>u\<^sub>c\<^sub>c' (treeList ! high x (deg div 2)) (low x (deg div 2))\ \T\<^sub>s\<^sub>u\<^sub>c\<^sub>c' (treeList ! high x (deg div 2)) (low x (deg div 2)) \ 1 + height (treeList ! high x (deg div 2))\ \treeList ! high x (deg div 2) \ set treeList\ height_compose_child le_trans plus_1_eq_Suc) + next + case False + hence "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c' (Node (Some (mi, ma)) deg treeList summary) x = 1+ T\<^sub>s\<^sub>u\<^sub>c\<^sub>c' summary ?h" + using T\<^sub>s\<^sub>u\<^sub>c\<^sub>c'.simps(6)[of mi ma "deg-2" treeList summary x] degprop hprop + by (cases " vebt_succ summary ?h") + (smt (z3) Suc_eq_plus1 \mi \ x\ linorder_not_less plus_1_eq_Suc False add_2_eq_Suc le_add_diff_inverse)+ + moreover have " T\<^sub>s\<^sub>u\<^sub>c\<^sub>c' summary ?h \ 1+ height summary" using 5(2) calculation by blast + ultimately have "T\<^sub>s\<^sub>u\<^sub>c\<^sub>c' (Node (Some (mi, ma)) deg treeList summary) x \ 1 + 1+ height summary" by simp + then show ?thesis + by (simp add: le_trans) + qed + next + case False + then show ?thesis using T\<^sub>s\<^sub>u\<^sub>c\<^sub>c'.simps(6)[of mi ma "deg-2" treeList summary x] degprop + by (smt (z3) add_2_eq_Suc leI le_add_diff_inverse not_add_less1) + qed + qed +qed simp+ + +theorem succ_bound_size_univ': "invar_vebt t n \ u = 2^n \ T\<^sub>s\<^sub>u\<^sub>c\<^sub>c' t x \ 2 + lb (lb u)" + using succ'_bound_height[of t n x] height_double_log_univ_size[of u n t] by simp + +subsection \Predecessor Function\ + +fun T\<^sub>p\<^sub>r\<^sub>e\<^sub>d::"VEBT \ nat \ nat " where + "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Leaf _ _) 0 = 1"| + "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Leaf a _) (Suc 0) = 1+ (if a then 1 else 1)"| + "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Leaf a b) _ = 1+ (if b then 1 else 1+ (if a then 1 else 1))"| + +"T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node None _ _ _) _ = 1"| +"T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node _ 0 _ _) _ = 1"| +"T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node _ (Suc 0) _ _) _ = 1"| +"T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node (Some (mi, ma)) deg treeList summary) x = 1+ ( + if x > ma then 1 + else (let l = low x (deg div 2); h = high x (deg div 2) in 10 + 1+ + (if h < length treeList then + + let minlow = vebt_mint (treeList ! h) in 2 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>t(treeList ! h) + 3 + + (if minlow \ None \ (Some l >\<^sub>o minlow) then + 4 + T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (treeList ! h) l + else let pr = vebt_pred summary h in 1 + T\<^sub>p\<^sub>r\<^sub>e\<^sub>d summary h+ 1 + ( + if pr = None then 1 + (if x > mi then 1 else 1) + else 4 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (treeList ! the pr) )) + else 1)))" + +theorem pred_bound_height: "invar_vebt t n \ T\<^sub>p\<^sub>r\<^sub>e\<^sub>d t x \ (1+height t)*29" +proof(induction t n arbitrary: x rule: invar_vebt.induct) + case (1 a b) + then show ?case apply(cases x) + using T\<^sub>p\<^sub>r\<^sub>e\<^sub>d.simps(1)[of a b] apply simp + apply(cases "x > 1") + using T\<^sub>p\<^sub>r\<^sub>e\<^sub>d.simps(3)[of a b] + apply (smt (z3) One_nat_def Suc_eq_numeral height.simps(1) less_Suc_eq_le less_antisym less_imp_Suc_add mult.left_neutral not_less numeral_One numeral_eq_iff numeral_le_one_iff plus_1_eq_Suc pred_numeral_simps(3) semiring_norm(70) semiring_norm(85)) + using T\<^sub>p\<^sub>r\<^sub>e\<^sub>d.simps(2)[of a b] apply simp + done +next + case (2 treeList n summary m deg) + then show ?case by simp +next + case (3 treeList n summary m deg) + then show ?case by simp +next + case (4 treeList n summary m deg mi ma) + hence "deg \ 2" + by (metis add_self_div_2 deg_not_0 div_greater_zero_iff) + then show ?case + proof(cases "x > ma") + case True + hence " T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node (Some (mi, ma)) deg treeList summary) x =2" using T\<^sub>p\<^sub>r\<^sub>e\<^sub>d.simps(7)[of mi ma "deg-2" treeList summary x ] + by (smt (z3) Suc_1 \2 \ deg\ add_2_eq_Suc le_add_diff_inverse plus_1_eq_Suc) + then show ?thesis by simp + next + case False + let ?l = "low x (deg div 2)" + let ?h = "high x (deg div 2)" + have 0: "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node (Some (mi, ma)) deg treeList summary) x = 1 + 10 +1 + + (if ?h < length treeList then + + let minlow = vebt_mint (treeList ! ?h) in 2 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>t(treeList ! ?h) + 3 + + (if minlow \ None \ (Some ?l >\<^sub>o minlow) then + 4 + T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (treeList ! ?h) ?l + else let pr = vebt_pred summary ?h in 1 + T\<^sub>p\<^sub>r\<^sub>e\<^sub>d summary ?h+ 1 + ( + if pr = None then 1 + (if x > mi then 1 else 1) + else 4 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (treeList ! the pr) )) + else 1)" + using T\<^sub>p\<^sub>r\<^sub>e\<^sub>d.simps(7)[of mi ma "deg-2" treeList summary x] False \2 \ deg\ + by (smt (z3) Suc_1 Suc_eq_plus1 add.assoc add.commute le_add_diff_inverse) + then show ?thesis + proof(cases " ?h < length treeList") + case True + let ?minlow = "vebt_mint (treeList ! ?h)" + have 1: "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node (Some (mi, ma)) deg treeList summary) x =17 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>t(treeList ! ?h) + + (if ?minlow \ None \ (Some ?l >\<^sub>o ?minlow) then + 4 + T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (treeList ! ?h) ?l + else let pr = vebt_pred summary ?h in 1 + T\<^sub>p\<^sub>r\<^sub>e\<^sub>d summary ?h+ 1 + ( + if pr = None then 1 + (if x > mi then 1 else 1) + else 4 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (treeList ! the pr) ))" using True 0 by simp + then show ?thesis + proof(cases "?minlow \ None \ (Some ?l >\<^sub>o ?minlow)") + case True + have 2: "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node (Some (mi, ma)) deg treeList summary) x =21 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>t(treeList ! ?h) + + T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (treeList ! ?h) ?l" using True 1 by simp + hence "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node (Some (mi, ma)) deg treeList summary) x \ 24 + T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (treeList ! ?h) ?l" using mint_bound by simp + moreover hence "(treeList ! ?h) \ set treeList" + using "4.hyps"(2) "4.hyps"(3) "4.hyps"(4) "4.hyps"(8) False high_bound_aux by force + ultimately have "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node (Some (mi, ma)) deg treeList summary) x \ 24 + (1 + height(treeList ! ?h))*29" + using "4.IH" by (meson nat_add_left_cancel_le order_trans) + hence "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node (Some (mi, ma)) deg treeList summary) x \ + 24 + (height (Node (Some (mi, ma)) deg treeList summary))*29" + using height_compose_child[of "treeList ! ?h" treeList "Some(mi, ma)" deg summary] + by (meson \treeList ! high x (deg div 2) \ set treeList\ add_le_cancel_left le_refl mult_le_mono order_trans) + then show ?thesis by simp + next + case False + let ?pr = "vebt_pred summary ?h " + have 2: "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node (Some (mi, ma)) deg treeList summary) x =19 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>t(treeList ! ?h) + + T\<^sub>p\<^sub>r\<^sub>e\<^sub>d summary ?h+ ( + if ?pr = None then 1 + (if x > mi then 1 else 1) + else 4 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (treeList ! the ?pr))" using False 1 by auto + hence 3:"T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node (Some (mi, ma)) deg treeList summary) x \22 + + T\<^sub>p\<^sub>r\<^sub>e\<^sub>d summary ?h+ ( + if ?pr = None then 1 + (if x > mi then 1 else 1) + else 4 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (treeList ! the ?pr))" using mint_bound[of "treeList ! ?h"] by simp + then show ?thesis + proof(cases " ?pr = None") + case True + hence "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node (Some (mi, ma)) deg treeList summary) x \24 + T\<^sub>p\<^sub>r\<^sub>e\<^sub>d summary ?h" using 3 by simp + hence "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node (Some (mi, ma)) deg treeList summary) x \24 + (1+ height summary) * 29" + by (meson "4.IH"(2) add_le_mono dual_order.trans le_refl) + hence "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node (Some (mi, ma)) deg treeList summary) x \ + 24 + (height (Node (Some (mi, ma)) deg treeList summary) ) * 29" + using height_compose_summary[of summary "Some (mi, ma)" deg treeList] by presburger + then show ?thesis by simp + next + case False + hence "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node (Some (mi, ma)) deg treeList summary) x \29 + + T\<^sub>p\<^sub>r\<^sub>e\<^sub>d summary ?h " using maxt_bound[of "treeList ! the ?pr"] 3 by auto + hence "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node (Some (mi, ma)) deg treeList summary) x \29 + (1+ height summary) * 29" + using "4.IH"(2)[of ?h] by simp + hence "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node (Some (mi, ma)) deg treeList summary) x \ + 29 + (height (Node (Some (mi, ma)) deg treeList summary)) * 29" + using height_compose_summary[of summary "Some (mi, ma)" deg treeList] by presburger + then show ?thesis by simp + qed + qed + next + case False + then show ?thesis using 0 by simp + qed + qed +next + case (5 treeList n summary m deg mi ma) + hence "deg \ 2" + by (metis Suc_1 add_mono_thms_linordered_semiring(1) le_add1 plus_1_eq_Suc set_n_deg_not_0) + then show ?case + proof(cases "x > ma") + case True + hence " T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node (Some (mi, ma)) deg treeList summary) x =2" using T\<^sub>p\<^sub>r\<^sub>e\<^sub>d.simps(7)[of mi ma "deg-2" treeList summary x ] + by (smt (z3) Suc_1 \2 \ deg\ add_2_eq_Suc le_add_diff_inverse plus_1_eq_Suc) + then show ?thesis by simp + next + case False + let ?l = "low x (deg div 2)" + let ?h = "high x (deg div 2)" + have 0: "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node (Some (mi, ma)) deg treeList summary) x = 1 + 10 +1 + + (if ?h < length treeList then + + let minlow = vebt_mint (treeList ! ?h) in 2 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>t(treeList ! ?h) + 3 + + (if minlow \ None \ (Some ?l >\<^sub>o minlow) then + 4 + T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (treeList ! ?h) ?l + else let pr = vebt_pred summary ?h in 1 + T\<^sub>p\<^sub>r\<^sub>e\<^sub>d summary ?h+ 1 + ( + if pr = None then 1 + (if x > mi then 1 else 1) + else 4 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (treeList ! the pr) )) + else 1)" + using T\<^sub>p\<^sub>r\<^sub>e\<^sub>d.simps(7)[of mi ma "deg-2" treeList summary x] False \2 \ deg\ + by (smt (z3) Suc_1 Suc_eq_plus1 add.assoc add.commute le_add_diff_inverse) + then show ?thesis + proof(cases " ?h < length treeList") + case True + hence " ?h < length treeList" by simp + let ?minlow = "vebt_mint (treeList ! ?h)" + have 1: "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node (Some (mi, ma)) deg treeList summary) x =17 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>t(treeList ! ?h) + + (if ?minlow \ None \ (Some ?l >\<^sub>o ?minlow) then + 4 + T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (treeList ! ?h) ?l + else let pr = vebt_pred summary ?h in 1 + T\<^sub>p\<^sub>r\<^sub>e\<^sub>d summary ?h+ 1 + ( + if pr = None then 1 + (if x > mi then 1 else 1) + else 4 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (treeList ! the pr) ))" + using True 0 by simp + then show ?thesis + proof(cases "?minlow \ None \ (Some ?l >\<^sub>o ?minlow)") + case True + have 2: "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node (Some (mi, ma)) deg treeList summary) x =21 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>t(treeList ! ?h) + + T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (treeList ! ?h) ?l" using True 1 by simp + hence "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node (Some (mi, ma)) deg treeList summary) x \ 24 + T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (treeList ! ?h) ?l" using mint_bound by simp + moreover hence "(treeList ! ?h) \ set treeList" + by (meson \high x (deg div 2) < length treeList\ nth_mem) + ultimately have "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node (Some (mi, ma)) deg treeList summary) x \ 24 + (1 + height(treeList ! ?h))*29" + using "5.IH" by (meson nat_add_left_cancel_le order_trans) + hence "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node (Some (mi, ma)) deg treeList summary) x \ + 24 + (height (Node (Some (mi, ma)) deg treeList summary))*29" + using height_compose_child[of "treeList ! ?h" treeList "Some(mi, ma)" deg summary] + by (meson \treeList ! high x (deg div 2) \ set treeList\ add_le_cancel_left le_refl mult_le_mono order_trans) + then show ?thesis by simp + next + case False + let ?pr = "vebt_pred summary ?h " + have 2: "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node (Some (mi, ma)) deg treeList summary) x =19 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>t(treeList ! ?h) + + T\<^sub>p\<^sub>r\<^sub>e\<^sub>d summary ?h+ ( + if ?pr = None then 1 + (if x > mi then 1 else 1) + else 4 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (treeList ! the ?pr))" + using False 1 by auto + hence 3:"T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node (Some (mi, ma)) deg treeList summary) x \22 + + T\<^sub>p\<^sub>r\<^sub>e\<^sub>d summary ?h+ ( + if ?pr = None then 1 + (if x > mi then 1 else 1) + else 4 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (treeList ! the ?pr))" using mint_bound[of "treeList ! ?h"] by simp + then show ?thesis + proof(cases " ?pr = None") + case True + hence "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node (Some (mi, ma)) deg treeList summary) x \24 + T\<^sub>p\<^sub>r\<^sub>e\<^sub>d summary ?h" using 3 by simp + hence "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node (Some (mi, ma)) deg treeList summary) x \24 + (1+ height summary) * 29" + by (meson "5.IH"(2) add_le_mono dual_order.trans le_refl) + hence "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node (Some (mi, ma)) deg treeList summary) x \ + 24 + (height (Node (Some (mi, ma)) deg treeList summary) ) * 29" + using height_compose_summary[of summary "Some (mi, ma)" deg treeList] by presburger + then show ?thesis by simp + next + case False + hence "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node (Some (mi, ma)) deg treeList summary) x \29 + T\<^sub>p\<^sub>r\<^sub>e\<^sub>d summary ?h " + using maxt_bound[of "treeList ! the ?pr"] 3 by auto + hence "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node (Some (mi, ma)) deg treeList summary) x \29 + (1+ height summary) * 29" + using "5.IH"(2)[of ?h] by simp + hence "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d (Node (Some (mi, ma)) deg treeList summary) x \ + 29 + (height (Node (Some (mi, ma)) deg treeList summary)) * 29" + using height_compose_summary[of summary "Some (mi, ma)" deg treeList] by presburger + then show ?thesis by simp + qed + qed + next + case False + then show ?thesis using 0 by simp + qed + qed +qed + + +theorem pred_bound_size_univ: "invar_vebt t n \ u = 2^n \ T\<^sub>p\<^sub>r\<^sub>e\<^sub>d t x \ 58 + 29 * lb (lb u)" + using pred_bound_height[of t n x] height_double_log_univ_size[of u n t] by simp + +fun T\<^sub>p\<^sub>r\<^sub>e\<^sub>d'::"VEBT \ nat \ nat " where + "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d' (Leaf _ _) 0 = 1"| + "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d' (Leaf a _) (Suc 0) = 1"| + "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d' (Leaf a b) _ = 1"| + +"T\<^sub>p\<^sub>r\<^sub>e\<^sub>d' (Node None _ _ _) _ = 1"| +"T\<^sub>p\<^sub>r\<^sub>e\<^sub>d' (Node _ 0 _ _) _ = 1"| +"T\<^sub>p\<^sub>r\<^sub>e\<^sub>d' (Node _ (Suc 0) _ _) _ = 1"| +"T\<^sub>p\<^sub>r\<^sub>e\<^sub>d' (Node (Some (mi, ma)) deg treeList summary) x = ( + if x > ma then 1 + else (let l = low x (deg div 2); h = high x (deg div 2) in + (if h < length treeList then + + let minlow = vebt_mint (treeList ! h) in + (if minlow \ None \ (Some l >\<^sub>o minlow) then + 1+ T\<^sub>p\<^sub>r\<^sub>e\<^sub>d' (treeList ! h) l + else let pr = vebt_pred summary h in T\<^sub>p\<^sub>r\<^sub>e\<^sub>d' summary h+ ( + if pr = None then 1 + else 1 )) + else 1)))" + +theorem pred_bound_height': "invar_vebt t n\ T\<^sub>p\<^sub>r\<^sub>e\<^sub>d' t x \ (1 + height t)" +proof(induction t n arbitrary: x rule: invar_vebt.induct) + case (1 a b) + then show ?case + by (metis One_nat_def Suc_eq_plus1_left T\<^sub>p\<^sub>r\<^sub>e\<^sub>d'.simps(1) T\<^sub>p\<^sub>r\<^sub>e\<^sub>d'.simps(2) T\<^sub>p\<^sub>r\<^sub>e\<^sub>d'.simps(3) vebt_buildup.cases height.simps(1) le_refl) +next + case (4 treeList n summary m deg mi ma) + hence degprop:"deg \ 2" + by (metis add_self_div_2 deg_not_0 div_greater_zero_iff) + then show ?case + proof(cases "x > ma") + case True + then show ?thesis using T\<^sub>p\<^sub>r\<^sub>e\<^sub>d'.simps(7)[of mi ma "deg -2" treeList summary x ] degprop + by (metis add_2_eq_Suc le_add_diff_inverse le_numeral_extra(4) trans_le_add1) + next + case False + hence "x \ ma" by simp + let ?l = "low x (deg div 2)" + let ?h = "high x (deg div 2)" + show ?thesis + proof(cases "?h< length treeList") + case True + hence hprop: "?h< length treeList" by simp + let ?minlow = "vebt_mint (treeList ! ?h)" + show ?thesis + proof(cases "?minlow \ None \ (Some ?l >\<^sub>o ?minlow)") + case True + hence "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d' (Node (Some (mi, ma)) deg treeList summary) x = 1+ T\<^sub>p\<^sub>r\<^sub>e\<^sub>d' (treeList ! ?h) ?l" + using T\<^sub>p\<^sub>r\<^sub>e\<^sub>d'.simps(7)[of mi ma "deg -2" treeList summary x ] degprop hprop + by (smt (z3) False add_2_eq_Suc le_add_diff_inverse) + moreover have "treeList ! ?h \ set treeList" using hprop by simp + moreover hence "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d' (treeList ! ?h) ?l \ 1 + height (treeList ! ?h)" using 4(1) by simp + ultimately have "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d' (Node (Some (mi, ma)) deg treeList summary) x \ 1+ 1+ height (treeList ! ?h)" by simp + then show ?thesis + by (smt (z3) Suc_le_mono \T\<^sub>p\<^sub>r\<^sub>e\<^sub>d' (Node (Some (mi, ma)) deg treeList summary) x = 1 + T\<^sub>p\<^sub>r\<^sub>e\<^sub>d' (treeList ! high x (deg div 2)) (low x (deg div 2))\ \T\<^sub>p\<^sub>r\<^sub>e\<^sub>d' (treeList ! high x (deg div 2)) (low x (deg div 2)) \ 1 + height (treeList ! high x (deg div 2))\ \treeList ! high x (deg div 2) \ set treeList\ height_compose_child le_trans plus_1_eq_Suc) + next + case False + hence "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d' (Node (Some (mi, ma)) deg treeList summary) x = 1+ T\<^sub>p\<^sub>r\<^sub>e\<^sub>d' summary ?h" + using T\<^sub>p\<^sub>r\<^sub>e\<^sub>d'.simps(7)[of mi ma "deg -2" treeList summary x ] degprop hprop + by (cases "vebt_pred summary ?h") + (smt (z3) Suc_eq_plus1 \x \ ma\ add_2_eq_Suc le_add_diff_inverse linorder_not_less plus_1_eq_Suc)+ + hence "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d' (Node (Some (mi, ma)) deg treeList summary) x \ 1 + 1 +height summary" using 4(2)[of ?h] by simp + then show ?thesis by(simp add: le_trans) + qed + next + case False + then show ?thesis using T\<^sub>p\<^sub>r\<^sub>e\<^sub>d'.simps(7)[of mi ma "deg -2" treeList summary x ] degprop + by (metis "4.hyps"(2) "4.hyps"(3) "4.hyps"(4) "4.hyps"(8) \x \ ma\ add_self_div_2 high_bound_aux le_less_trans) + qed + qed +next + case (5 treeList n summary m deg mi ma) + hence degprop:"deg \ 2" + by (metis Suc_1 leD less_numeral_extra(1) not_add_less1 not_less_eq_eq not_less_iff_gr_or_eq plus_1_eq_Suc set_n_deg_not_0) + then show ?case + proof(cases "x > ma") + case True + then show ?thesis using T\<^sub>p\<^sub>r\<^sub>e\<^sub>d'.simps(7)[of mi ma "deg -2" treeList summary x ] degprop + by (metis add_2_eq_Suc le_add_diff_inverse le_numeral_extra(4) trans_le_add1) + next + case False + hence "x \ ma" by simp + let ?l = "low x (deg div 2)" + let ?h = "high x (deg div 2)" + show ?thesis + proof(cases "?h< length treeList") + case True + hence hprop: "?h< length treeList" by simp + let ?minlow = "vebt_mint (treeList ! ?h)" + show ?thesis + proof(cases "?minlow \ None \ (Some ?l >\<^sub>o ?minlow)") + case True + hence "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d' (Node (Some (mi, ma)) deg treeList summary) x = 1+ T\<^sub>p\<^sub>r\<^sub>e\<^sub>d' (treeList ! ?h) ?l" + using T\<^sub>p\<^sub>r\<^sub>e\<^sub>d'.simps(7)[of mi ma "deg -2" treeList summary x ] degprop hprop + by (smt (z3) False add_2_eq_Suc le_add_diff_inverse) + moreover have "treeList ! ?h \ set treeList" using hprop by simp + moreover hence "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d' (treeList ! ?h) ?l \ 1 + height (treeList ! ?h)" using 5(1) by simp + ultimately have "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d' (Node (Some (mi, ma)) deg treeList summary) x \ 1+ 1+ height (treeList ! ?h)" by simp + then show ?thesis + by (smt (z3) Suc_le_mono \T\<^sub>p\<^sub>r\<^sub>e\<^sub>d' (Node (Some (mi, ma)) deg treeList summary) x = 1 + T\<^sub>p\<^sub>r\<^sub>e\<^sub>d' (treeList ! high x (deg div 2)) (low x (deg div 2))\ \T\<^sub>p\<^sub>r\<^sub>e\<^sub>d' (treeList ! high x (deg div 2)) (low x (deg div 2)) \ 1 + height (treeList ! high x (deg div 2))\ \treeList ! high x (deg div 2) \ set treeList\ height_compose_child le_trans plus_1_eq_Suc) + next + case False + hence "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d' (Node (Some (mi, ma)) deg treeList summary) x = 1+ T\<^sub>p\<^sub>r\<^sub>e\<^sub>d' summary ?h" + using T\<^sub>p\<^sub>r\<^sub>e\<^sub>d'.simps(7)[of mi ma "deg -2" treeList summary x ] degprop hprop + by (cases "vebt_pred summary ?h") + (smt (z3) Suc_eq_plus1 \x \ ma\ add_2_eq_Suc le_add_diff_inverse linorder_not_less plus_1_eq_Suc)+ + hence "T\<^sub>p\<^sub>r\<^sub>e\<^sub>d' (Node (Some (mi, ma)) deg treeList summary) x \ 1 + 1 +height summary" using 5(2)[of ?h] by simp + then show ?thesis by(simp add: le_trans) + qed + next + case False + then show ?thesis using T\<^sub>p\<^sub>r\<^sub>e\<^sub>d'.simps(7)[of mi ma "deg -2" treeList summary x ] degprop + by (smt (z3) add_2_eq_Suc leI le_add_diff_inverse not_add_less1) + qed + qed +qed simp+ + +theorem pred_bound_size_univ': "invar_vebt t n \ u = 2^n \ T\<^sub>p\<^sub>r\<^sub>e\<^sub>d' t x \ 2 + lb (lb u)" + using pred_bound_height'[of t n x] height_double_log_univ_size[of u n t] by simp + +end +end diff --git a/thys/Van_Emde_Boas_Trees/VEBT_BuildupMemImp.thy b/thys/Van_Emde_Boas_Trees/VEBT_BuildupMemImp.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/VEBT_BuildupMemImp.thy @@ -0,0 +1,1114 @@ +(*by Ammer*) +theory VEBT_BuildupMemImp + imports + VEBT_List_Assn + VEBT_Space + "Deriving.Derive" + VEBT_Member VEBT_Insert + "HOL-Library.Countable" + "Time_Reasoning/Time_Reasoning" VEBT_DeleteBounds +begin + +section \Imperative van Emde Boas Trees\ + +datatype VEBTi = Nodei "(nat*nat) option" nat "VEBTi array" VEBTi | Leafi bool bool + +derive countable VEBTi +instance VEBTi :: heap by standard + +subsection \Assertions on van Emde Boas Trees\ +fun vebt_assn_raw :: "VEBT \ VEBTi \ assn" where + "vebt_assn_raw (Leaf a b) (Leafi ai bi) = \(ai=a \ bi=b)" +| "vebt_assn_raw (Node mmo deg tree_list summary) (Nodei mmoi degi tree_array summaryi) = ( + \(mmoi=mmo \ degi=deg) + * vebt_assn_raw summary summaryi + * (\\<^sub>A tree_is. tree_array \\<^sub>a tree_is * list_assn vebt_assn_raw tree_list tree_is) + )" +| "vebt_assn_raw _ _ = false" + +lemmas [simp del] = vebt_assn_raw.simps + +context VEBT_internal begin + +lemmas [simp] = vebt_assn_raw.simps + + + +lemma TBOUND_VEBT_case[TBOUND]: assumes "\ a b. ti = Leafi a b \ TBOUND (f a b) (bnd a b)" + "\ info deg treeArray summary . ti = Nodei info deg treeArray summary \ + TBOUND (f' info deg treeArray summary) (bnd' info deg treeArray summary) " + + shows "TBOUND (case ti of Leafi a b \ f a b | + Nodei info deg treeArray summary \ f' info deg treeArray summary) + (case ti of Leafi a b \ bnd a b | + Nodei info deg treeArray summary \ bnd' info deg treeArray summary)" + using assms + apply(cases ti) + apply auto + done + + + +text \Some Lemmas\ + +lemma length_corresp:"(\\<^sub>A tree_is. tree_array \\<^sub>a tree_is) = true \ return (length tree_is ) = Array_Time.len tree_array" +proof- + assume "(\\<^sub>A tree_is. tree_array \\<^sub>a tree_is) = true " + then obtain tree_is where " tree_array \\<^sub>a tree_is = true" + by (metis mod_h_bot_iff(2) mod_h_bot_iff(4) mod_h_bot_iff(8)) + then show ?thesis + by (metis assn_basic_inequalities(5) merge_true_star snga_same_false) +qed + +lemma heaphelp:assumes " h \ + xa \\<^sub>a tree_is * list_assn vebt_assn_raw treeList tree_is * + vebt_assn_raw summary xb *\(None = None \ n = n)* + \ (xc = Nodei None n xa xb)" + shows "h \ vebt_assn_raw (Node None n treeList summary) xc" +proof- + have "h \ vebt_assn_raw (Node None n treeList summary) (Nodei None n xa xb)" + using vebt_assn_raw.simps(2)[of None n treeList summary None n xa xb] apply simp + by (metis assms mod_pure_star_dist star_aci(2)) + then show ?thesis + using assms by auto +qed + +lemma assnle:" list_assn vebt_assn_raw treeList tree_is * (x13 \\<^sub>a tree_is * vebt_assn_raw summary x14) \\<^sub>A + vebt_assn_raw summary x14 * x13 \\<^sub>a tree_is * list_assn vebt_assn_raw treeList tree_is" + using star_aci(2) by auto + +lemma ext:" y < length treeList \x13 \\<^sub>a tree_is * (vebt_assn_raw summary x14 * + (vebt_assn_raw (treeList ! y) (tree_is ! y) * listI_assn ({0..\<^sub>A (x13 \\<^sub>a tree_is * vebt_assn_raw summary x14 * + ( listI_assn ({0.. vebt_assn_raw (treeList ! y) (tree_is ! y) * x13 \\<^sub>a tree_is * vebt_assn_raw summary x14 * + listI_assn ({0..\<^sub>A + vebt_assn_raw summary x14 * x13 \\<^sub>a tree_is * list_assn vebt_assn_raw treeList tree_is" + by (smt (z3) assn_aci(9) assn_times_comm assnle atLeastLessThan_iff less_nat_zero_code listI_assn_extract list_assn_conv_idx not_less) + +lemma recomp: " i < length treeList \ vebt_assn_raw (treeList ! i) (tree_is ! i) * + listI_assn ({0..\<^sub>a tree_is * + vebt_assn_raw summary x14 \\<^sub>A + vebt_assn_raw summary x14 * x13 \\<^sub>a tree_is * list_assn vebt_assn_raw treeList tree_is" + by (smt (z3) ab_semigroup_mult_class.mult.commute ab_semigroup_mult_class.mult.left_commute atLeastLessThan_iff ent_refl listI_assn_extract list_assn_conv_idx zero_le) + +lemma repack: "i < length treeList \ +vebt_assn_raw (treeList ! i) (tree_is ! i) * + Rest * + (x13 \\<^sub>a tree_is * vebt_assn_raw summary x14 * + listI_assn ({0..\<^sub>A Rest* vebt_assn_raw summary x14 * x13 \\<^sub>a tree_is * list_assn vebt_assn_raw treeList tree_is" + apply- + by (smt (z3) assn_times_assoc atLeastLessThan_iff entails_def leI less_nat_zero_code listI_assn_extract list_assn_conv_idx mod_pure_star_dist star_aci(2)) + +lemma big_assn_simp: "h < length treeList \ + vebt_assn_raw (vebt_delete(treeList ! h) l) x * + \ (xaa = vebt_mint (vebt_delete(treeList ! h) l)) * + ( x13 \\<^sub>a (tree_is [h := x]) * + vebt_assn_raw summary x14 * + listI_assn ({0..\<^sub>A + x13 \\<^sub>a tree_is[h:=x] * vebt_assn_raw summary x14 * \ (xaa = vebt_mint (vebt_delete(treeList ! h) l)) * +list_assn vebt_assn_raw (treeList[h:= (vebt_delete(treeList ! h) l)]) (tree_is[h:= x]) " + by (smt (z3) Diff_iff ab_semigroup_mult_class.mult.left_commute assn_aci(10) atLeastLessThan_iff ent_refl insertCI insert_Diff_single insert_absorb leI length_list_update less_nat_zero_code listI_assn_subst list_assn_conv_idx mult.right_neutral) + +lemma tcd: "i < length treeList \ length treeList = length treeList' \ + vebt_assn_raw y x * x13 \\<^sub>a tree_is[i:= x] * vebt_assn_raw summary x14 * listI_assn ({0..\<^sub>A x13 \\<^sub>a tree_is[i:= x] * vebt_assn_raw summary x14 * list_assn vebt_assn_raw (treeList[i :=y]) (tree_is[i := x])" + by (smt (z3) ab_semigroup_mult_class.mult.commute assn_aci(10) atLeastLessThan_iff ent_pure_pre_iff entails_def leI length_list_update less_nat_zero_code listI_assn_def listI_assn_extract list_assn_conv_idx nth_list_update_eq) + +lemma big_assn_simp': "h < length treeList ==> xaa = vebt_delete (treeList ! h)l \ + vebt_assn_raw xaa x * \ (xb = vebt_mint xaa) * + (x13 \\<^sub>a tree_is[h := x] * vebt_assn_raw summary x14 * + listI_assn ({0..\<^sub>A + (x13 \\<^sub>a tree_is[h:= x] * vebt_assn_raw summary x14 * \ (xb = vebt_mint xaa) * + list_assn vebt_assn_raw (treeList[h:= xaa]) (tree_is[h:= x]))" + by (smt (verit, best) Diff_iff assn_aci(9) ent_refl insertCI length_list_update listI_assn_weak_cong mult.right_neutral nth_list_update_neq pure_false pure_true star_false_left star_false_right tcd) + + +lemma refines_case_VEBTi[refines_rule]: assumes "ti = ti'" "\ a b. refines (f1 a b) (f1' a b)" +"\ info deg treeArray summary . refines (f2 info deg treeArray summary) (f2' info deg treeArray summary) " + shows "refines (case ti of Leafi a b \ f1 a b | + Nodei info deg treeArray summary \ f2 info deg treeArray summary) + (case ti' of Leafi a b\ f1' a b | + Nodei info deg treeArray summary \ f2' info deg treeArray summary)" + using assms apply (cases ti') apply simp_all + done + +subsection\High and low Bitsequences Definition\ + +definition highi::"nat \ nat \ nat Heap" where + "highi x n == return (x div (2^n))" + +definition lowi::"nat \ nat \ nat Heap" where + "lowi x n == return (x mod (2^n))" + +lemma highi_h: " highi x n <\ r. \(r = high x n)>" + by (simp add: high_def highi_def return_cons_rule) + +lemma highi_hT: " highi x n <\ r. \(r = high x n)>T[1]" + by (metis cons_post_rule entails_def highi_def highi_h httI order_refl time_return) + +lemma lowi_h: " lowi x n <\ r. \(r = low x n)>" + by (simp add: low_def lowi_def return_cons_rule) + +lemma lowi_hT: " lowi x n <\ r. \(r = low x n)>T[1]" + by (metis httI lowi_def lowi_h order_refl time_return) + +section \Imperative Implementation of $vebt-buildup$\ + +fun replicatei::"nat \'a Heap \ ('a list) Heap" where + "replicatei 0 x = return []"| + "replicatei (Suc n) x = do{ y <- x; + ys <- replicatei n x; + return (y#ys) }" + +lemma time_replicate: "\\h. time x h \ c \ \ time (replicatei n x) h \ (1+(1+c)*n)" + apply (induction n arbitrary: h) + apply (simp add: time_simp algebra_simps) + apply (auto simp: time_simp fails_simp algebra_simps) + by (metis add_le_mono group_cancel.add2 nat_arith.suc1) + +lemma TBOUND_replicate: "\TBOUND x c\ \ TBOUND (replicatei n x) (1+(1+c)*n)" + by (meson TBOUND_def time_replicate) + +lemma refines_replicate[refines_rule]: + "refines f f' \ refines (replicatei n f) (replicatei n f')" + apply (induction n) + apply simp_all + apply refines + done + +fun vebt_buildupi'::"nat \ VEBTi Heap" where + "vebt_buildupi' 0 = return (Leafi False False)"| + "vebt_buildupi' (Suc 0) = return (Leafi False False)"| + "vebt_buildupi' n = (if even n then (let half = n div 2 in do{ + treeList <- replicatei (2^half) (vebt_buildupi' half); + assert' (length treeList = 2^half); + trees <- Array_Time.of_list treeList; + summary <- (vebt_buildupi' half); + return (Nodei None n trees summary)}) + else (let half = n div 2 in do{ + treeList <- replicatei (2^(Suc half)) (vebt_buildupi' half); + assert' (length treeList = 2^Suc half); + trees <- Array_Time.of_list treeList; + summary <- (vebt_buildupi' (Suc half)); + return (Nodei None n trees summary)} ))" + +end + +context begin + interpretation VEBT_internal . + +fun vebt_buildupi::"nat \ VEBTi Heap" where + "vebt_buildupi 0 = return (Leafi False False)"| + "vebt_buildupi (Suc 0) = return (Leafi False False)"| + "vebt_buildupi n = (if even n then (let half = n div 2 in do{ + treeList <- replicatei (2^half) (vebt_buildupi half); + trees <- Array_Time.of_list treeList; + summary <- (vebt_buildupi half); + return (Nodei None n trees summary)}) + else (let half = n div 2 in do{ + treeList <- replicatei (2^(Suc half)) (vebt_buildupi half); + trees <- Array_Time.of_list treeList; + summary <- (vebt_buildupi (Suc half)); + return (Nodei None n trees summary)} ))" + +end + +context VEBT_internal begin + +lemma vebt_buildupi_refines: "refines (vebt_buildupi n) (vebt_buildupi' n)" + apply (induction n rule: vebt_buildupi.induct) + apply (subst vebt_buildupi.simps; subst vebt_buildupi'.simps; refines)+ + done + +fun T_vebt_buildupi where + "T_vebt_buildupi 0 = Suc 0" +| "T_vebt_buildupi (Suc 0) = Suc 0" +| "T_vebt_buildupi (Suc (Suc n)) = ( + if even n then + Suc (Suc (Suc (T_vebt_buildupi (Suc (n div 2)) + + (4 * 2 ^ (n div 2) + 2 * (T_vebt_buildupi (Suc (n div 2)) * 2 ^ (n div 2)))))) + else + Suc (Suc (Suc (T_vebt_buildupi (Suc (Suc (n div 2))) + + (8 * 2 ^ (n div 2) + 4 * (T_vebt_buildupi (Suc (n div 2)) * 2 ^ (n div 2)))))))" + +lemma TBOUND_vebt_buildupi: + defines "foo \ T_vebt_buildupi" + shows "TBOUND (vebt_buildupi' n) (foo n)" + supply [simp del] = vebt_buildupi'.simps + supply [TBOUND] = TBOUND_replicate + apply (induction n rule: vebt_buildupi.induct) + apply (subst vebt_buildupi'.simps) + apply (rule TBOUND_mono) + apply (TBOUND_step) + apply(rule asm_rl[of "_ \ _"]) + apply defer_le + apply (subst vebt_buildupi'.simps) + apply (rule TBOUND_mono) + apply (TBOUND_step) + apply(rule asm_rl[of "_ \ _"]) + apply defer_le + apply (subst vebt_buildupi'.simps) + apply (rule TBOUND_mono) + apply TBOUND_step+ + apply(rule asm_rl[of "_ \ _"]) + apply defer_le + apply (all \((determ \thin_tac \TBOUND _ _\\)+)? \) + apply (simp_all add: foo_def) + done + +lemma T_vebt_buildupi: "time (vebt_buildupi' n) h \ T_vebt_buildupi n" + using TBOUND_vebt_buildupi[THEN TBOUNDD] . + +lemma repli_cons_repl: " x <\ r. Q* A y r > \ replicatei n x <\ r. Q*list_assn A (replicate n y) r >" +proof(induction n arbitrary: Q) + case (Suc n) + then show ?case + apply (sep_auto heap: "Suc.IH"(1)) + apply (smt (z3) assn_aci(10) cons_post_rule ent_refl fi_rule) + apply sep_auto + done +qed sep_auto + +corollary repli_emp: " x <\ r. A y r > \ replicatei n x <\ r. list_assn A (replicate n y) r >" + apply(rule cons_post_rule) + apply(rule repli_cons_repl[where Q = emp]) + apply sep_auto+ + done + + +lemma builupi'corr: " vebt_buildupi' n <\ r. vebt_assn_raw (vebt_buildup n) r>" +proof(induction n rule: vebt_buildup.induct) + case (3 n) + then show ?case + proof(cases "even (Suc (Suc n))") + case True + then show ?thesis + apply( simp add: vebt_buildupi'.simps(2)) + apply(rule bind_rule) + apply(sep_auto heap: repli_cons_repl) + apply(rule "3.IH"(1)) + apply simp+ + apply sep_auto + apply (extract_pre_pure dest: extract_pre_list_assn_lengthD; simp) + apply (sep_auto heap: "3.IH"(1)) + done + next + case False + hence 11:" \<^sub>a x * list_assn vebt_assn_raw (replicate (4 * 2 ^ (n div 2)) (vebt_buildup (Suc (n div 2)))) x> + vebt_buildupi' (Suc (Suc (Suc n) div 2)) <\ r. xa \\<^sub>a x * list_assn vebt_assn_raw (replicate (4 * 2 ^ (n div 2)) (vebt_buildup (Suc (n div 2)))) x * + vebt_assn_raw ( vebt_buildup (Suc (Suc (Suc n) div 2))) r>" for xa x + proof - + show ?thesis + by (metis (no_types) "3.IH"(4) False frame_rule_left mult.right_neutral) + qed + hence "vebt_buildupi' (Suc (Suc n)) = do{ treeList <- replicatei (2^(Suc ((Suc (Suc n)) div 2))) (vebt_buildupi' ((Suc (Suc n)) div 2)); + assert' (length treeList = (2^(Suc ((Suc (Suc n)) div 2)))); + trees <- Array_Time.of_list treeList; + summary <- (vebt_buildupi' (Suc ((Suc (Suc n)) div 2))); + return (Nodei None (Suc (Suc n)) trees summary)}" + using vebt_buildupi'.simps(3)[of n] Let_def False + by auto + moreover have " do{treeList <- replicatei (2^(Suc ((Suc (Suc n)) div 2))) (vebt_buildupi' ((Suc (Suc n)) div 2)); + assert' (length treeList = (2^(Suc ((Suc (Suc n)) div 2)))); + trees <- Array_Time.of_list treeList; + summary <- (vebt_buildupi' (Suc ((Suc (Suc n)) div 2))); + return (Nodei None (Suc (Suc n)) trees summary)} " + apply(rule bind_rule) + apply(sep_auto heap: repli_cons_repl) + apply(rule "3.IH"(3)) + using False apply simp + using False apply simp + apply(rule assert'_bind_rule) + apply (extract_pre_pure dest: extract_pre_list_assn_lengthD; simp) + apply(rule bind_rule) + apply sep_auto + apply(rule bind_rule) + apply (rule 11) + apply vcg + proof- + fix x xa xb xc + show " xa \\<^sub>a x * list_assn vebt_assn_raw (replicate (4 * 2 ^ (n div 2)) (vebt_buildup (Suc (n div 2)))) x * + vebt_assn_raw (vebt_buildup (Suc (Suc (Suc n) div 2))) xb * \ (xc = Nodei None (Suc (Suc n)) xa xb) \\<^sub>A vebt_assn_raw (vebt_buildup (Suc (Suc n))) xc" + apply(rule entailsI) + proof- + fix h + assume " h \xa \\<^sub>a x * list_assn vebt_assn_raw (replicate (4 * 2 ^ (n div 2)) (vebt_buildup (Suc (n div 2)))) x * + vebt_assn_raw (vebt_buildup (Suc (Suc (Suc n) div 2))) xb * \ (xc = Nodei None (Suc (Suc n)) xa xb)" + then show " h \ vebt_assn_raw (vebt_buildup (Suc (Suc n))) xc" + using heaphelp by (smt (z3) False SLN_def SLN_right ab_semigroup_mult_class.mult.commute ab_semigroup_mult_class.mult.left_commute vebt_buildup.simps(3) div2_Suc_Suc even_numeral even_two_times_div_two numeral_Bit0_div_2 power_Suc power_commutes pure_true) + qed + qed + then show ?thesis using calculation + by presburger + qed +qed sep_auto+ + +lemma htt_vebt_buildupi': "< emp> (vebt_buildupi' n) <\ r. vebt_assn_raw (vebt_buildup n) r> T [T_vebt_buildupi n]" + apply (rule httI_TBOUND) + apply (rule builupi'corr) + apply (rule TBOUND_vebt_buildupi) + done + +lemma builupicorr: " vebt_buildupi n <\ r. vebt_assn_raw (vebt_buildup n) r>" + using vebt_buildupi_refines builupi'corr hoare_triple_refines by blast + +lemma htt_vebt_buildupi: " (vebt_buildupi n) <\ r. vebt_assn_raw (vebt_buildup n) r> T [T_vebt_buildupi n]" + apply (rule htt_refine) + apply (rule htt_vebt_buildupi') + apply (rule vebt_buildupi_refines) + done + +text \Closed bound for $T-vebt-buildupi$\ + +text \Amortization\ + +lemma T_vebt_buildupi_gq_0: "T_vebt_buildupi n > 0" + apply(induction n rule : T_vebt_buildupi.induct) + apply auto + done + +fun T_vebt_buildupi'::"nat \ int" where + "T_vebt_buildupi' 0 = 1" +| "T_vebt_buildupi' (Suc 0) = 1" +| "T_vebt_buildupi' (Suc (Suc n)) = ( + if even n then + 3+(T_vebt_buildupi' (Suc (n div 2)) + + (4 * 2 ^ (n div 2) + 2 * (T_vebt_buildupi' (Suc (n div 2)) * 2 ^ (n div 2)))) + else + 3+ (T_vebt_buildupi' (Suc (Suc (n div 2))) + + (8 * 2 ^ (n div 2) + 4 * (T_vebt_buildupi' (Suc (n div 2)) * 2 ^ (n div 2)))))" + +lemma Tbuildupi_buildupi': "T_vebt_buildupi n = T_vebt_buildupi' n" + by(induction n rule: T_vebt_buildupi.induct) auto + +fun Tb::"nat \ int" where + "Tb 0 = 3" +| "Tb (Suc 0) =3" +| "Tb (Suc (Suc n)) = ( + if even n then + 5+ Tb (Suc (n div 2)) + (Tb (Suc (n div 2))) * 2 ^ (Suc (n div 2)) + else + 5 + Tb (Suc (Suc (n div 2))) + (Tb (Suc (n div 2))) * 2 ^(Suc (Suc (n div 2))))" + +lemma Tb_T_vebt_buildupi': "T_vebt_buildupi' n \ Tb n - 2" +proof(induction n rule: T_vebt_buildupi.induct) + case 1 + then show ?case + apply(subst Tb.simps) + apply(subst T_vebt_buildupi'.simps) + apply simp + done +next + case 2 + then show ?case + apply(subst Tb.simps) + apply(subst T_vebt_buildupi'.simps) + apply simp + done +next + case (3 n) + then show ?case + proof(cases "even (Suc (Suc n))") + case True + then show ?thesis + apply(subst Tb.simps) + apply(subst T_vebt_buildupi'.simps) + using True apply simp + thm 3 + proof- + have 0:"T_vebt_buildupi' (Suc (n div 2)) + + (4 * 2 ^ (n div 2) + 2 * (T_vebt_buildupi' (Suc (n div 2)) * 2 ^ (n div 2))) + \ Tb (Suc (n div 2)) - 2 + 2^(Suc (n div 2))*2 + + 2^(Suc (n div 2)) * (T_vebt_buildupi' (Suc (n div 2)))" + using "3.IH"(1) True algebra_simps by simp + moreover have 1:"2^(Suc (n div 2))*2 + + 2^(Suc (n div 2)) * (T_vebt_buildupi' (Suc (n div 2))) = + 2^(Suc (n div 2)) * (T_vebt_buildupi' (Suc (n div 2)) + 2)" by algebra + ultimately have 2:"T_vebt_buildupi' (Suc (n div 2)) + + (4 * 2 ^ (n div 2) + 2 * (T_vebt_buildupi' (Suc (n div 2)) * 2 ^ (n div 2))) + \ Tb (Suc (n div 2)) - 2 + + 2^(Suc (n div 2)) * (T_vebt_buildupi' (Suc (n div 2)) + 2)"by linarith + hence 3:" (4 * 2 ^ (n div 2) + 2 * (T_vebt_buildupi' (Suc (n div 2))) * 2 ^ (n div 2)) + \ 2* 2^(Suc (n div 2))+ 2^(Suc (n div 2)) * ((Tb (Suc (n div 2)) - 2))" + using "3.IH"(1) True by simp + hence 4:" (4 * 2 ^ (n div 2) + 2 * (T_vebt_buildupi' (Suc (n div 2))) * 2 ^ (n div 2)) + \ 2^(Suc (n div 2)) * ((Tb (Suc (n div 2)) - 2) + 2)" + using algebra_simps by (smt (verit, del_insts) "1") + hence 4:" T_vebt_buildupi' (Suc (n div 2)) + + (4 * 2 ^ (n div 2) + 2 * (T_vebt_buildupi' (Suc (n div 2))) * 2 ^ (n div 2)) + \ Tb (Suc (n div 2)) - (2::int) + 2^(Suc (n div 2)) * (Tb (Suc (n div 2)))" + using "3.IH"(1) True by simp + have 5:" (x::int) \ (y::int) - (z::int) + a \ z \ 0 \ x \ y + a" for x y z a by simp + have "T_vebt_buildupi' (Suc (n div 2)) + + (4 * 2 ^ (n div 2) + 2 * (T_vebt_buildupi' (Suc (n div 2)) * 2 ^ (n div 2))) + \ Tb (Suc (n div 2)) + 2^(Suc (n div 2)) * (Tb (Suc (n div 2)))" using + 5[of " T_vebt_buildupi' (Suc (n div 2)) + + (4 * 2 ^ (n div 2) + 2 * (T_vebt_buildupi' (Suc (n div 2))) * 2 ^ (n div 2))" + " Tb (Suc (n div 2))" 2 "Tb (Suc (n div 2)) * (2 * 2 ^ (n div 2))"] 4 by simp + then show "T_vebt_buildupi' (Suc (n div 2)) + + (4 * 2 ^ (n div 2) + 2 * (T_vebt_buildupi' (Suc (n div 2)) * 2 ^ (n div 2))) + \ Tb (Suc (n div 2)) + Tb (Suc (n div 2)) * (2 * 2 ^ (n div 2))" + using power_Suc [of 2 "(n div 2)"] mult.commute by metis + qed + next + case False + have "3 + + (T_vebt_buildupi' (Suc (Suc (n div 2))) + + (8 * 2 ^ (n div 2) + 4 * (T_vebt_buildupi' (Suc (n div 2)) * 2 ^ (n div 2)))) + \ 5 + Tb (Suc (Suc (n div 2))) + Tb (Suc (n div 2)) * 2 ^ Suc (Suc (n div 2)) - 2" + proof- + have 0:"3 + + (T_vebt_buildupi' (Suc (Suc (n div 2))) + + (8 * 2 ^ (n div 2) + 4 * (T_vebt_buildupi' (Suc (n div 2)) * 2 ^ (n div 2)))) + \ 1 + Tb (Suc (Suc (n div 2))) + (8 * 2 ^ (n div 2) + 4 * (T_vebt_buildupi' (Suc (n div 2)) * 2 ^ (n div 2)))" + using "3.IH"(3) False by simp + moreover have " 4 * (T_vebt_buildupi' (Suc (n div 2))*2 ^ (n div 2)) \ + 4 * ((Tb (Suc (n div 2)) - 2) * 2 ^ (n div 2))" + using "3.IH"(4) False algebra_simps by simp + moreover have "8 * 2 ^ (n div 2) + 4 * ((Tb (Suc (n div 2)) - 2) * 2 ^ (n div 2)) = + 4* (2 * 2 ^ (n div 2) + ((Tb (Suc (n div 2)) - 2) * 2 ^ (n div 2)))" by simp + moreover have "4* (2 * 2 ^ (n div 2) + ((Tb (Suc (n div 2)) - 2) * 2 ^ (n div 2))) = + 4* ( ((Tb (Suc (n div 2)) - 2) + 2) * 2 ^ (n div 2))" by algebra + moreover hence "4* (2 * 2 ^ (n div 2) + ((Tb (Suc (n div 2)) - 2) * 2 ^ (n div 2))) = + 4* ((Tb (Suc (n div 2)) ) * 2 ^ (n div 2))" by simp + ultimately have "8 * 2 ^ (n div 2) + 4 * (T_vebt_buildupi' (Suc (n div 2))*2 ^ (n div 2)) \ + 4 * (((Tb (Suc (n div 2))-2) + 2 ) * 2 ^ (n div 2))" by presburger + then show ?thesis using 0 by force + qed + then show ?thesis + apply(subst Tb.simps) + apply(subst T_vebt_buildupi'.simps) + using False by simp + qed qed + +fun Tb'::"nat \ nat" where + "Tb' 0 = 3" +| "Tb' (Suc 0) =3" +| "Tb' (Suc (Suc n)) = ( + if even n then + 5+ Tb' (Suc (n div 2)) + (Tb' (Suc (n div 2))) * 2 ^ (Suc (n div 2)) + else + 5 + Tb' (Suc (Suc (n div 2))) + (Tb' (Suc (n div 2))) * 2 ^(Suc (Suc (n div 2))))" + +lemma Tb_Tb': "Tb t = Tb' t" + by(induction t rule: Tb.induct) auto + +lemma Tb_T_vebt_buildupi: "T_vebt_buildupi n \ Tb n - 2" + using Tb_T_vebt_buildupi' Tbuildupi_buildupi' by simp + +lemma Tb_T_vebt_buildupi'': "T_vebt_buildupi n \ Tb' n - 2" + using Tb_T_vebt_buildupi[of n] Tb_Tb' by simp + +lemma Tb'_cnt: "Tb' n \ 5 * cnt' (vebt_buildup n)" +proof(induction n rule: vebt_buildup.induct) + case (3 n) + then show ?case + proof(cases "even n") + case True + have 0:" 5 + Tb' (Suc (n div 2)) + Tb' (Suc (n div 2)) * 2 ^ Suc (n div 2) + \ 5 * cnt' ( let half = Suc (Suc n) div 2 + in Node None (Suc (Suc n)) (replicate (2 ^ half) (vebt_buildup half)) + (vebt_buildup half))" + unfolding Let_def + apply(subst cnt'.simps) + proof- + have 0:"5 * (1 + cnt' (vebt_buildup (Suc (Suc n) div 2)) + + foldr (+) + (map cnt' (replicate (2 ^ (Suc (Suc n) div 2)) (vebt_buildup (Suc (Suc n) div 2)))) 0) = + 5 * (1 + cnt' (vebt_buildup (Suc (Suc n) div 2)) + (2 ^ (Suc (Suc n) div 2)) * cnt' (vebt_buildup (Suc (Suc n) div 2)))" + using map_replicate[of cnt' "(2 ^ (Suc (Suc n) div 2))" "(vebt_buildup (Suc (Suc n) div 2))"] + foldr_same_int[of "replicate (2 ^ (Suc (Suc n) div 2)) (cnt' (vebt_buildup (Suc (Suc n) div 2)))" + "(cnt' (vebt_buildup (Suc (Suc n) div 2)))"] length_replicate by simp + have 1:" Tb' (Suc (n div 2)) * 2 ^ Suc (n div 2) + \ 5 * (2 ^ (Suc (Suc n) div 2) * cnt' (vebt_buildup (Suc (Suc n) div 2)))" + using True "3.IH"(1)[of "Suc (Suc n) div 2"] by simp + have 2:" Tb' (Suc (n div 2)) \ 5 * cnt' (vebt_buildup (Suc (Suc n) div 2))" + using True "3.IH"(1)[of "Suc (Suc n) div 2"] by simp + show "5 + Tb' (Suc (n div 2)) + Tb' (Suc (n div 2)) * 2 ^ Suc (n div 2) + \ 5 * (1 + cnt' (vebt_buildup (Suc (Suc n) div 2)) + + foldr (+) + (map cnt' (replicate (2 ^ (Suc (Suc n) div 2)) (vebt_buildup (Suc (Suc n) div 2)))) 0)" + apply(rule ord_le_eq_trans[where b = "5 * (1 + cnt' (vebt_buildup (Suc (Suc n) div 2)) + + (2 ^ (Suc (Suc n) div 2)) * cnt' (vebt_buildup (Suc (Suc n) div 2)))"]) + defer + using 0 apply simp + using 1 2 "order.trans" trans_le_add1 algebra_simps + by (smt (z3) add_le_cancel_left add_mono_thms_linordered_semiring(1) mult_Suc_right plus_1_eq_Suc) + qed + show ?thesis + apply (subst vebt_buildup.simps) + apply(subst Tb'.simps) + using 0 True apply simp + done + next + case False + have 0:" 5 + Tb' (Suc (Suc (n div 2))) + Tb' (Suc (n div 2)) * 2 ^ Suc (Suc (n div 2)) + \ 5 * cnt' ( let half = Suc (Suc n) div 2 + in Node None (Suc (Suc n)) (replicate (2 ^ Suc half) (vebt_buildup half)) + (vebt_buildup (Suc half)))" + unfolding Let_def + apply(subst cnt'.simps) + proof- + have 0:"5 * (1 + cnt' (vebt_buildup (Suc (Suc (Suc n) div 2))) + + foldr (+) (map cnt' (replicate (2 ^ Suc (Suc (Suc n) div 2)) (vebt_buildup (Suc (Suc n) div 2))))0) + = 5 * (1 + cnt' (vebt_buildup (Suc (Suc (Suc n) div 2))) + (2 ^ Suc (Suc (Suc n) div 2)) * cnt' (vebt_buildup (Suc (Suc n) div 2)))" + using map_replicate[of cnt' "(2 ^ Suc (Suc (Suc n) div 2))" "(vebt_buildup (Suc (Suc n) div 2))"] + foldr_same_int[of "replicate (2 ^ Suc (Suc (Suc n) div 2)) (cnt' (vebt_buildup (Suc (Suc n) div 2)))" + "(cnt' (vebt_buildup (Suc (Suc n) div 2)))"] length_replicate by simp + have 1:" Tb' (Suc (n div 2)) * 2 ^ ((Suc n) div 2) + \ 5 * (2 ^ (Suc (Suc n) div 2) * cnt' (vebt_buildup (Suc (Suc n) div 2)))" + using False "3.IH"(3)[of " (Suc (Suc n) div 2)"] by simp + have 2:" Tb' (Suc (Suc (n div 2))) \ 5 * cnt' (vebt_buildup (Suc (Suc (Suc n) div 2)))" + using False "3.IH"(4)[of "(Suc n) div 2"] by simp + show " 5 + Tb' (Suc (Suc (n div 2))) + Tb' (Suc (n div 2)) * 2 ^ Suc (Suc (n div 2)) + \ 5 * (1 + cnt' (vebt_buildup (Suc (Suc (Suc n) div 2))) + + foldr (+) + (map cnt' (replicate (2 ^ Suc (Suc (Suc n) div 2)) (vebt_buildup (Suc (Suc n) div 2)))) 0)" + + apply(rule ord_le_eq_trans[where b = "5 * (1 + cnt' (vebt_buildup (Suc (Suc (Suc n) div 2))) + + (2 ^ Suc (Suc (Suc n) div 2)) * cnt' (vebt_buildup (Suc (Suc n) div 2)))"]) + defer + using 0 apply simp + using 1 2 "order.trans" trans_le_add1 algebra_simps + by (smt (z3) "3.IH"(3) False add_le_cancel_left add_mono_thms_linordered_semiring(1) diff_diff_cancel diff_le_self div2_Suc_Suc even_Suc mult_Suc_right plus_1_eq_Suc) + qed + show ?thesis + apply (subst vebt_buildup.simps) + apply(subst Tb'.simps) + using 0 False apply simp + done + qed +qed (subst vebt_buildup.simps cnt'.simps Tb'.simps , simp )+ + +lemma T_vebt_buildupi_cnt': "T_vebt_buildupi n \ 5 * cnt (vebt_buildup n)" + apply(rule ord_le_eq_trans[where b = "real (5 * cnt' (vebt_buildup n))"]) + defer + apply(simp add: cnt_cnt_eq) + apply(rule of_nat_mono) + apply(rule order.trans[]) + apply(rule Tb_T_vebt_buildupi'') + apply(rule order.trans[where b = "Tb' n"]) + apply simp + apply(rule Tb'_cnt) + done + +lemma T_vebt_buildupi_univ: + assumes "u =2^n " + shows "T_vebt_buildupi n \10 * u" +proof- + have "cnt (vebt_buildup n) \ 2 * u" + using count_buildup[of n] assms by simp + hence "real (T_vebt_buildupi n) \ 5 * 2 * u" + using T_vebt_buildupi_cnt'[of n] by simp + then show ?thesis by simp +qed + +lemma htt_vebt_buildupi'_univ: + assumes "u = 2^n" + shows + "< emp> (vebt_buildupi' n) <\ r. vebt_assn_raw (vebt_buildup n) r> T [10 * u]" + apply (rule httI_TBOUND) + apply (rule builupi'corr) + apply (rule TBOUND_mono[where t = "T_vebt_buildupi n"]) + apply (rule TBOUND_vebt_buildupi) + using T_vebt_buildupi_univ[of u n] assms apply simp + done + +text \We obtain the main theorem for $buildupi$\ + +lemma htt_vebt_buildupi_univ: + assumes "u = 2^n" + shows + "< emp> (vebt_buildupi n) <\ r. vebt_assn_raw (vebt_buildup n) r> T [10 * u]" + using vebt_buildupi_refines + by (metis VEBT_internal.htt_vebt_buildupi'_univ assms htt_refine) + +lemma vebt_buildupi_rule: "<\ (n > 0)> vebt_buildupi n <\ r. vebt_assn_raw (vebt_buildup n) r > T[10 * 2^n]" +proof- + have vebt_buildupi'_rule: "<\ (n > 0)> vebt_buildupi' n <\ r. vebt_assn_raw (vebt_buildup n) r >" + using builupicorr[of n] + apply simp + using VEBT_internal.builupi'corr by blast + have vebt_buildupi'_rule_univ: "<\ (n > 0)> vebt_buildupi' n <\ r. vebt_assn_raw (vebt_buildup n) r > T[10 * 2^n]" + apply (rule httI_TBOUND) + apply(rule vebt_buildupi'_rule) + apply(rule TBOUND_refines[where c = "vebt_buildupi' n"]) + apply(rule TBOUND_mono[where t="T_vebt_buildupi n"]) + apply(rule TBOUND_vebt_buildupi) + using T_vebt_buildupi_univ[of "2^n" n] + apply simp + apply(rule refines_refl) + done + show ?thesis + using vebt_buildupi_refines htt_refine vebt_buildupi'_rule_univ by blast +qed + + +lemma TBOUND_buildupi: assumes "n>0" shows " TBOUND (vebt_buildupi n) (10 * 2 ^ n)" + using vebt_buildupi_rule[of n] unfolding htt_def TBOUND_def + apply auto + subgoal for h + using time_return[of "Leafi False False" h] by simp + subgoal for h + using time_return[of "Leafi False False" h] by simp + done + +section \Minimum and Maximum Determination\ + +end + +context begin + interpretation VEBT_internal . + +fun vebt_minti::"VEBTi \ nat option Heap" where + "vebt_minti (Leafi a b) = (if a then return ( Some 0) else if b then return (Some 1) else return None)"| + "vebt_minti (Nodei None _ _ _) = return None"| + "vebt_minti (Nodei (Some (mi,ma)) _ _ _ ) = return (Some mi)" + +fun vebt_maxti::"VEBTi \ nat option Heap" where + "vebt_maxti (Leafi a b) = (if b then return (Some 1) else if a then return (Some 0) else return None)"| + "vebt_maxti (Nodei None _ _ _) = return None"| + "vebt_maxti (Nodei (Some (mi,ma)) _ _ _ ) = return (Some ma)" + +end + +context VEBT_internal begin + +lemma vebt_minti_h:" vebt_minti ti <\r. vebt_assn_raw t ti * \(r = vebt_mint t)>" + by (cases t rule: vebt_mint.cases; cases ti rule: vebt_minti.cases) (sep_auto+) + +lemma vebt_maxti_h:" vebt_maxti ti <\r. vebt_assn_raw t ti * \(r = vebt_maxt t)>" + by (cases t rule: vebt_mint.cases; cases ti rule: vebt_minti.cases) (sep_auto+) + +lemma TBOUND_vebt_maxti[TBOUND]: "TBOUND (vebt_maxti t) 1" + apply (induction t rule: vebt_maxti.induct) + apply (subst vebt_maxti.simps| TBOUND_step)+ + done + +lemma TBOUND_vebt_minti[TBOUND]: "TBOUND (vebt_minti t) 1" + apply (induction t rule: vebt_minti.induct) + apply (subst vebt_minti.simps| TBOUND_step)+ + done + +lemma vebt_minti_hT:" vebt_minti ti <\r. vebt_assn_raw t ti * \(r = vebt_mint t)>T[1]" + using TBOUND_vebt_minti httI_TBOUND vebt_minti_h by blast + +lemma vebt_maxti_hT:" vebt_maxti ti <\r. vebt_assn_raw t ti * \(r = vebt_maxt t)>T[1]" + using TBOUND_vebt_maxti httI_TBOUND vebt_maxti_h by blast + +lemma vebt_maxtilist:"i < length ts \ + vebt_maxti (tsi ! i) + < \ r. \(r = vebt_maxt (ts ! i)) *list_assn vebt_assn_raw ts tsi>" + apply(unwrap_idx i) + apply (sep_auto heap: vebt_maxti_h) + apply(wrap_idx R: listI_assn_reinsert_upd) + apply sep_auto + done + +lemma vebt_mintilist:"i < length ts \ + vebt_minti (tsi ! i) + < \ r. \(r = vebt_mint (ts ! i)) *list_assn vebt_assn_raw ts tsi>" + apply(unwrap_idx i) + apply (sep_auto heap: vebt_minti_h) + apply(wrap_idx R: listI_assn_reinsert_upd) + apply sep_auto + done + +section \Membership Test on imperative van Emde Boas Trees\ + +end + +context begin +interpretation VEBT_internal . + +partial_function (heap_time) vebt_memberi::"VEBTi \ nat \ bool Heap" where + "vebt_memberi t x = + (case t of + (Leafi a b ) \ return (if x = 0 then a else if x=1 then b else False) | + (Nodei info deg treeList summary ) \ ( + case info of None \ return False | + (Some (mi, ma)) \ ( if deg \ 1 then return False else ( + if x = mi then return True else + if x = ma then return True else + if x < mi then return False else + if x > ma then return False else + (do { + h \ highi x (deg div 2); + l \ lowi x (deg div 2); + len \ Array_Time.len treeList; + if h < len then do { + th \ Array_Time.nth treeList h; + vebt_memberi th l + } else return False + })))))" + +end + +context VEBT_internal begin + +partial_function (heap_time) vebt_memberi'::"VEBT \VEBTi \ nat \ bool Heap" where + "vebt_memberi' t ti x = + (case ti of + (Leafi a b ) \ return (if x = 0 then a else if x=1 then b else False) | + (Nodei info deg treeArray summary ) \ ( do {assert' (is_Node t); + case info of None \ return False | + (Some (mi, ma)) \ ( if deg \ 1 then return False else ( + if x = mi then return True else + if x = ma then return True else + if x < mi then return False else + if x > ma then return False else + (do { + let (info',deg',treeList,summary') = + (case t of (Node info' deg' treeList summary') \ + (info', deg', treeList, summary')); + assert'(info= info' \ deg = deg'); + h \ highi x (deg div 2); + l \ lowi x (deg div 2); + assert'(l = low x (deg div 2) \ h = high x (deg div 2)); + len \ Array_Time.len treeArray; + assert'(len = length treeList); + if h < len then do { + assert'(h = high x (deg div 2) \ h < length treeList); + th \ Array_Time.nth treeArray h; + vebt_memberi' (treeList ! h) th l } + else return False + })))}))" + +lemma highsimp: "return (high x n) = highi x n" + by (simp add: high_def highi_def) + +lemma lowsimp: "return (low x n) = lowi x n" + by (simp add: low_def lowi_def) + +lemma TBOUND_highi[TBOUND]: "TBOUND (highi x n) 1" + unfolding highi_def + apply TBOUND_step + done + +lemma TBOUND_lowi[TBOUND]: "TBOUND (lowi x n) 1" + unfolding lowi_def + apply TBOUND_step + done + +text \Correctness of $vebt-memberi$\ + +lemma vebt_memberi'_rf_abstr:" vebt_memberi' t ti x <\r. vebt_assn_raw t ti * \(r = vebt_member t x)>" +proof(induction t x arbitrary: ti rule: vebt_member.induct) + case (1 a b x) + then show ?case apply (subst vebt_memberi'.simps) by(cases ti; sep_auto) +next + case (2 uu uv uw x) + then show ?case apply (subst vebt_memberi'.simps) by(cases ti; sep_auto) +next + case (3 v uy uz x) + then show ?case apply (subst vebt_memberi'.simps) by(cases ti; sep_auto) +next + case (4 v vb vc x) + then show ?case apply (subst vebt_memberi'.simps) by(cases ti; sep_auto) +next + case (5 mi ma va treeList summary x) + note IH[sep_heap_rules] = "5.IH" (*[THEN cons_post_rule]*) + show ?case + apply (subst vebt_memberi'.simps) unfolding highi_def lowi_def + apply (cases ti;sep_auto) + apply(simp add: low_def ) + apply(simp add: high_def ) + apply sep_auto + apply (extract_pre_pure dest: extract_pre_list_assn_lengthD) + apply(simp add: high_def) + apply sep_auto + apply (extract_pre_pure dest: extract_pre_list_assn_lengthD) + subgoal + apply (extract_pre_pure dest: extract_pre_list_assn_lengthD) + apply (rewrite in "<\>_<_>" list_assn_conv_idx) + apply (rewrite in "<\>_<_>" listI_assn_extract[where i="(x div (2 * 2 ^ (va div 2)))"]) + apply simp + apply simp + apply (sep_auto simp: high_def low_def) + apply (rule listI_assn_reinsert) + apply frame_inference + apply simp + apply simp + apply (rewrite in "\ \\<^sub>A _" list_assn_conv_idx[symmetric]) + apply sep_auto + done + apply (extract_pre_pure dest: extract_pre_list_assn_lengthD) + apply (sep_auto simp: high_def) + done +qed + +lemma TBOUND_vebt_memberi: + defines foo_def: "\ t x. foo t x \ 4 * (1+height t)" + shows "TBOUND (vebt_memberi' t ti x) (foo t x)" + apply (induction arbitrary: t ti x rule: vebt_memberi'.fixp_induct) + apply (rule TBOUND_fi'_adm) + apply (rule TBOUND_empty) + subgoal for f t ti x + apply(rule TBOUND_mono) + apply ( TBOUND_step)+ + unfolding foo_def + apply (auto split: VEBTi.splits option.splits VEBT.splits) + apply (meson List.finite_set Max_ge finite_imageI imageI le_max_iff_disj nth_mem) + done + done + +lemma vebt_memberi_refines: "refines (vebt_memberi ti x) (vebt_memberi' t ti x)" + apply (induction arbitrary: t ti x rule: vebt_memberi'.fixp_induct) + subgoal using refines_adm[where t = "\ arg. vebt_memberi (snd (fst arg)) (snd arg)"] + by simp + subgoal by simp + subgoal for f t ti x + apply(subst vebt_memberi.simps) + apply refines + done + done + +lemma htt_vebt_memberi: + "vebt_memberi ti x <\ r. vebt_assn_raw t ti * \(r = vebt_member t x)>T[ 5 + 5 * height t]" + apply (rule htt_refine[where c = "vebt_memberi' t ti x"]) + prefer 2 + apply(rule vebt_memberi_refines) + apply (rule httI_TBOUND) + apply(rule vebt_memberi'_rf_abstr) + apply(rule TBOUND_mono) + apply(rule TBOUND_vebt_memberi) + apply simp + done + +lemma htt_vebt_memberi_invar_vebt: assumes "invar_vebt t n" shows + " vebt_memberi ti x <\ r. vebt_assn_raw t ti * \(r = vebt_member t x)>T[5 + 5 * (nat \lb n \)]" + by (metis assms heigt_uplog_rel htt_vebt_memberi nat_int) + +subsection \$minNulli$: empty tree?\ + +fun minNulli::"VEBTi \ bool Heap" where + "minNulli (Leafi False False) = return True"| + "minNulli (Leafi _ _ ) = return False"| + "minNulli (Nodei None _ _ _) = return True"| + "minNulli (Nodei (Some _) _ _ _) = return False" + +lemma minNulli_rule[sep_heap_rules]: " minNulli ti <\r. vebt_assn_raw t ti * \(r = minNull t)>" + by (cases t rule: minNull.cases; cases ti rule: minNulli.cases) (sep_auto+) + +lemma TBOUND_minNulli[TBOUND]: "TBOUND (minNulli t) 1" + apply (induction t rule: minNulli.induct) + apply (subst minNulli.simps | TBOUND_step)+ + done + +lemma minNrulli_ruleT: + " minNulli ti <\r. vebt_assn_raw t ti * \(r = minNull t)>T[1]" + by (metis TBOUND_minNulli hoare_triple_def httI_TBOUND minNulli_rule) + + +section \Imperative $vebt-insert$ to van Emde Boas Tree\ + +end + +context begin +interpretation VEBT_internal . + + +partial_function (heap_time) vebt_inserti::"VEBTi \ nat \VEBTi Heap" where + "vebt_inserti t x = (case t of + (Leafi a b) \ (if x=0 then return (Leafi True b) else if x=1 + then return (Leafi a True) else return (Leafi a b)) | + (Nodei info deg treeArray summary) \ ( case info of None \ + if deg \ 1 then + return (Nodei info deg treeArray summary) + else + return (Nodei (Some (x,x)) deg treeArray summary)| + (Some minma) \ + ( if deg \ 1 + then return (Nodei info deg treeArray summary) + else ( do{ + mi <- return (fst minma); + ma <- return (snd minma); + xn <- (if x < mi then return mi else return x); + minn <- (if x < mi then return x else return mi); + l<- lowi xn (deg div 2); + h <- highi xn (deg div 2); + len \ Array_Time.len treeArray; + if h < len \ \ (x = mi \ x = ma) then do { + node <- Array_Time.nth treeArray h; + empt <- minNulli node; + newnode <- vebt_inserti node l; + newarray <- Array_Time.upd h newnode treeArray; + newsummary<-(if empt then + vebt_inserti summary h + else return summary); + man <- (if xn > ma then return xn else return ma); + return (Nodei (Some (minn, man)) deg newarray newsummary)} + else return (Nodei (Some (mi,ma)) deg treeArray summary) + }))))" + +end + +context VEBT_internal begin + +partial_function (heap_time) vebt_inserti'::"VEBT \VEBTi \ nat \VEBTi Heap" where + "vebt_inserti' t ti x = (case ti of + (Leafi a b) \ (if x=0 then return (Leafi True b) else if x=1 + then return (Leafi a True) else return (Leafi a b)) | + (Nodei info deg treeArray summary) \ ( case info of None \ + if deg \ 1 then + return (Nodei info deg treeArray summary) + else + return (Nodei (Some (x,x)) deg treeArray summary)| + (Some minma) \ + ( if deg \ 1 + then return (Nodei info deg treeArray summary) + else ( + do{ + assert' (is_Node t); + let (info',deg',treeList,summary') = + (case t of (Node info' deg' treeList summary') \ + (info', deg', treeList, summary')); + assert'(info= info' \ deg = deg'); + let (mi', ma') = (the info'); + mi <- return (fst minma); + ma <- return (snd minma); + xn <- (if x < mi then return mi else return x); + let xn' = (if x < mi' then mi' else x); + minn <- (if x < mi then return x else return mi); + let minn' = (if x < mi' then x else mi'); + l<- lowi xn (deg div 2); + assert' (l = low xn' (deg' div 2)); + h <- highi xn (deg div 2); + len \ Array_Time.len treeArray; + if h < len \ \ (x = mi \ x = ma) then do { + assert' (h = high xn' (deg' div 2)); + assert'( h < length treeList); + node <- Array_Time.nth treeArray h; + empt <- minNulli node; + assert' (empt = minNull (treeList ! h)); + newnode <- vebt_inserti' (treeList ! h) node l; + newarray <- Array_Time.upd h newnode treeArray; + newsummary<-(if empt then + vebt_inserti' summary' summary h + else return summary); + man <- (if xn > ma then return xn else return ma); + return (Nodei (Some (minn, man)) deg newarray newsummary)} + else return (Nodei (Some (mi,ma)) deg treeArray summary) + }))))" + +lemmas listI_assn_wrap_insert = listI_assn_reinsert_upd'[ + where x="VEBT_Insert.vebt_insert _ _" and A=vebt_assn_raw ] + +lemma vebt_inserti'_rf_abstr: " vebt_inserti' t ti x <\r. vebt_assn_raw ( vebt_insert t x) r >" +proof(induction t x arbitrary: ti rule: vebt_insert.induct) + case (1 a b x) + then show ?case by (subst vebt_inserti'.simps)(cases ti; sep_auto) +next + case (2 info ts s x) + then show ?case by (subst vebt_inserti'.simps) (cases ti; sep_auto) +next + case (3 info ts s x) + then show ?case by(subst vebt_inserti'.simps) (cases ti; sep_auto) +next + case (4 v treeList summary x) + then show ?case by (subst vebt_inserti'.simps)(cases ti; sep_auto) +next + case (5 mi ma va treeList summary x) + note IH1 = "5.IH"(1)[OF refl refl _ _] + note IH2 = "5.IH"(2)[OF refl refl refl] + show ?case + apply (cases ti) + subgoal + supply [split del] = if_split + apply (subst vebt_inserti'.simps; clarsimp split del: ) + apply (assn_simp; intro normalize_rules) + apply (extract_pre_pure dest: extract_pre_list_assn_lengthD) + apply (simp only: fold_if_return distrib_if_bind heap_monad_laws) + apply (clarsimp simp: lowi_def highi_def) + apply (sep_auto simp: lowi_def highi_def) + apply(simp add: low_def) + apply (metis fst_conv) + apply(rule bind_rule) + apply sep_auto + apply (simp cong: if_cong) + apply sep_auto + apply(simp add: high_def) + apply (unwrap_idx "((if x < mi then mi else x) div (2 * 2 ^ (va div 2)))") + apply (sep_auto simp: low_def high_def) + apply (heap_rule IH1) + subgoal + by (simp add: low_def high_def split: if_splits) + subgoal + by (simp add: low_def high_def split: if_splits) + subgoal + by (simp add: low_def high_def split: if_splits) + apply (sep_auto simp: low_def high_def) + apply (heap_rule IH2) + subgoal + by (simp add: low_def high_def split: if_splits) + subgoal + by (simp add: low_def high_def) + subgoal + by (simp add: low_def high_def split: if_splits) + apply (wrap_idx R: listI_assn_wrap_insert) + apply (sep_auto simp: low_def high_def Let_def) + apply (wrap_idx R: listI_assn_wrap_insert) + apply (sep_auto simp: low_def high_def Let_def)+ + done + subgoal + by simp + done +qed + +lemma TBOUND_minNull: "minNull t \ TBOUND (vebt_inserti' t ti x ) 1" + apply(subst vebt_inserti'.simps) + apply(cases t rule: minNull.cases; simp) + apply TBOUND+ + apply (auto split: VEBTi.splits option.splits) + done + +lemma TBOUND_vebt_inserti: + defines foo_def: "\ t x. foo t x \ if minNull t then 1 else 13 * (1+height t)" + shows "TBOUND (vebt_inserti' t ti x) (foo t x)" +proof- + have fooNull:"minNull t \ foo t x = 1" for t x using foo_def by simp + have fooElse: "foo t x \ 13* (1+ height t)" for t using foo_def by simp + show ?thesis + apply (induction arbitrary: t ti x rule: vebt_inserti'.fixp_induct) + apply (rule TBOUND_fi'_adm) + apply (rule TBOUND_empty) + apply (rule TBOUND_mono) + apply TBOUND_step+ + apply (simp split!: VEBTi.splits VEBT.split option.splits prod.splits if_split) + apply(simp_all add: foo_def height_i_max) + done +qed + +lemma vebt_inserti_refines: "refines (vebt_inserti ti x) (vebt_inserti' t ti x)" + apply (induction arbitrary: t ti x rule: vebt_inserti'.fixp_induct) + subgoal using refines_adm[where t = "\ arg. vebt_inserti (snd (fst arg)) (snd arg)"] + by simp + subgoal + by simp + apply(subst vebt_inserti.simps) + apply refines + done + +lemma htt_vebt_inserti: + " vebt_inserti ti x <\ r. vebt_assn_raw (vebt_insert t x) r>T[ 13 + 13 * height t]" + apply (rule htt_refine[where c = "vebt_inserti' t ti x"]) + prefer 2 + apply(rule vebt_inserti_refines) + apply (rule httI_TBOUND) + apply(rule vebt_inserti'_rf_abstr) + apply(rule TBOUND_mono) + apply(rule TBOUND_vebt_inserti) + apply simp + done + +lemma htt_vebt_inserti_invar_vebt: assumes "invar_vebt t n" shows + " vebt_inserti ti x <\ r. vebt_assn_raw (vebt_insert t x) r>T[13 + 13 * (nat \lb n \)]" + by (metis assms heigt_uplog_rel htt_vebt_inserti nat_int) + +end +end diff --git a/thys/Van_Emde_Boas_Trees/VEBT_Definitions.thy b/thys/Van_Emde_Boas_Trees/VEBT_Definitions.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/VEBT_Definitions.thy @@ -0,0 +1,759 @@ +(*by Ammer*) +theory VEBT_Definitions imports + Main + "HOL-Library.Extended_Nat" + "HOL-Library.Code_Target_Numeral" + "HOL-Library.Code_Target_Nat" + +begin +section \Preliminaries and Preparations\ + +subsection \Data Type Definition\ + +datatype VEBT = is_Node: Node (info:"(nat*nat) option")(deg: nat)(treeList: "VEBT list") (summary:VEBT) | + is_Leaf: Leaf bool bool + +hide_const (open) info deg treeList summary + +locale VEBT_internal begin + +subsection \Functions for obtaining high and low bits of an input number.\ + +definition high :: "nat \ nat \ nat" where + "high x n = (x div (2^n))" + +definition low :: "nat \ nat \ nat" where + "low x n = (x mod (2^n))" + +subsection \Some auxiliary lemmata\ + +lemma inthall[termination_simp]: "(\ x. x \ set xs \ P x) \ n < length xs \ P (xs ! n)" + apply(induction xs arbitrary: n) + apply auto + using less_Suc_eq_0_disj + apply auto + done + +lemma intind: "i < n \ P x \ P (replicate n x ! i)" + by (metis in_set_replicate inthall length_replicate) + +lemma concat_inth:"(xs @[x]@ys)! (length xs) = x" + by simp + +lemma pos_n_replace: "n length xs = length (take n xs @ [y] @drop (Suc n) xs)" + by simp + +lemma inthrepl: "i < n \ (replicate n x) ! i = x" by simp + +lemma nth_repl: "m n m\ n \(take n xs @ [x] @ drop (n+1) xs) ! m = xs ! m" + by (metis Suc_eq_plus1 append_Cons append_Nil nth_list_update_neq upd_conv_take_nth_drop) + +lemma [termination_simp]:assumes "high x deg < length treeList" + shows"size (treeList ! high x deg) < Suc (size_list size treeList + size s)" +proof- + have "treeList ! high x deg \ set treeList" + using assms by auto + then show ?thesis + using not_less_eq size_list_estimation by fastforce +qed + +subsection \ Auxiliary functions for defining valid Van Emde Boas Trees\ + +text \This function checks whether an element occurs in a Leaf\ + +fun naive_member :: "VEBT \ nat \ bool" where + "naive_member (Leaf a b) x = (if x = 0 then a else if x = 1 then b else False)"| + "naive_member (Node _ 0 _ _) _ = False"| + "naive_member (Node _ deg treeList s) x = (let pos = high x (deg div 2) in + (if pos < length treeList then naive_member (treeList ! pos) (low x (deg div 2)) else False))" + +text \Test for elements stored by using the provide min-max-fields\ + +fun membermima :: "VEBT \ nat \ bool" where + "membermima (Leaf _ _) _ = False"| + "membermima (Node None 0 _ _ )_ =False"| + "membermima (Node (Some (mi,ma)) 0 _ _) x = (x = mi \ x = ma)"| + "membermima (Node (Some (mi, ma)) deg treeList _) x = (x = mi \ x = ma \ ( + let pos = high x ( deg div 2) in (if pos < length treeList + then membermima (treeList ! pos) (low x (deg div 2)) else False)))"| + "membermima (Node None (deg) treeList _) x = (let pos = high x (deg div 2) in + (if pos < length treeList then membermima (treeList ! pos) (low x (deg div 2)) else False))" + +lemma length_mul_elem:"(\ x \ set xs. length x = n) \ length (concat xs) = (length xs) * n" + apply(induction xs) + apply auto + done + +text \We combine both auxiliary functions: The following test returns true if and only if an element occurs in the tree with respect to our interpretation no matter where it is stored.\ + +definition both_member_options :: "VEBT \ nat \ bool" where + "both_member_options t x = (naive_member t x \ membermima t x)" + + +end +context begin + interpretation VEBT_internal . + +definition set_vebt :: "VEBT \ nat set" where + "set_vebt t = {x. both_member_options t x}" +end + +subsection \Inductive Definition of semantically valid Vam Emde Boas Trees\ + +text \Invariant for verification proofs\ + +context begin + interpretation VEBT_internal . + +inductive invar_vebt::"VEBT \ nat \ bool" where + "invar_vebt (Leaf a b) (Suc 0) "| + "( \ t \ set treeList. invar_vebt t n) \ invar_vebt summary m \ length treeList = 2^m + \ m = n \ deg = n + m \ (\ i. both_member_options summary i) + \(\ t \ set treeList. \ x. both_member_options t x) + \ invar_vebt (Node None deg treeList summary) deg"| + "( \ t \ set treeList. invar_vebt t n) \ invar_vebt summary m + \ length treeList = 2^m \ m = Suc n \ deg = n + m \ (\ i. both_member_options summary i) + \ (\ t \ set treeList. \ x. both_member_options t x) + \ invar_vebt (Node None deg treeList summary) deg"| + "( \ t \ set treeList. invar_vebt t n) \ invar_vebt summary m \ length treeList = 2^m \ m = n + \deg = n + m\ (\ i < 2^m. (\ x. both_member_options (treeList ! i) x) \ ( both_member_options summary i)) \ + (mi = ma \ (\ t \ set treeList. \ x. both_member_options t x)) \ + mi \ ma \ ma < 2^deg \ + (mi \ ma \ + (\ i < 2^m. + (high ma n = i \ both_member_options (treeList ! i) (low ma n)) \ + (\ x. (high x n = i \ both_member_options (treeList ! i) (low x n) ) \ mi < x \ x \ ma) ) ) + \ invar_vebt (Node (Some (mi, ma)) deg treeList summary) deg"| + "( \ t \ set treeList. invar_vebt t n) \invar_vebt summary m \ length treeList = 2^m + \ m = Suc n \deg = n + m\(\ i < 2^m. (\ x. both_member_options (treeList ! i) x) \ ( both_member_options summary i)) \ + (mi = ma \ (\ t \ set treeList. \ x. both_member_options t x)) \ + mi \ ma \ ma < 2^deg \ + (mi \ ma \ + (\ i < 2^m. + (high ma n = i \ both_member_options (treeList ! i) (low ma n)) \ + (\ x. (high x n = i \ both_member_options (treeList ! i) (low x n) ) \ mi < x \ x \ ma))) + \ invar_vebt (Node (Some (mi, ma)) deg treeList summary) deg" + +end + +context VEBT_internal begin + +definition "in_children n treeList x \ both_member_options (treeList ! high x n) (low x n)" + +text \functional validness definition\ +fun valid' :: "VEBT \ nat \ bool" where + "valid' (Leaf _ _) d \ d=1" +| "valid' (Node mima deg treeList summary) deg' \ + ( + deg=deg' \ ( + let n = deg div 2; m = deg - n in + ( \ t \ set treeList. valid' t n ) + \ valid' summary m + \ length treeList = 2^m + \ ( + case mima of + None \ (\ i. both_member_options summary i) \ (\ t \ set treeList. \ x. both_member_options t x) + | Some (mi,ma) \ + mi \ ma \ ma<2^deg + \ (\ i < 2^m. (\ x. both_member_options (treeList ! i) x) \ ( both_member_options summary i)) + \ (if mi=ma then (\ t \ set treeList. \ x. both_member_options t x) + else + in_children n treeList ma + \ (\x < 2^deg. in_children n treeList x \ mi x\ma) + ) + ) + ) + ) +" + +text \equivalence proofs\ + +lemma high_bound_aux: "ma < 2^(n+m) \ high ma n < 2^m" + unfolding high_def + by (simp add: add.commute less_mult_imp_div_less power_add) + +lemma valid_eq1: + assumes "invar_vebt t d" + shows "valid' t d" + using assms apply induction + apply simp_all + apply (auto simp: in_children_def dest: high_bound_aux) [] + subgoal for treeList n summary m deg mi ma + apply (intro allI impI conjI) + apply (auto simp: in_children_def dest: high_bound_aux) [] + apply (metis add_Suc_right high_bound_aux power_Suc) + apply (auto simp: in_children_def dest: high_bound_aux) [] + apply (metis add_Suc_right high_bound_aux power_Suc) + apply (auto simp: in_children_def dest: high_bound_aux) [] + apply (metis add_Suc_right high_bound_aux power_Suc) + done + done + +lemma even_odd_cases: + fixes x :: nat + obtains n where "x=n+n" | n where "x = n + Suc n" + apply (cases "even x"; simp) + apply (metis add_self_div_2 div_add) + by (metis add.commute mult_2 oddE plus_1_eq_Suc) + +lemma valid_eq2: "valid' t d \ invar_vebt t d" + apply (induction t d rule: valid'.induct) + apply (auto intro: invar_vebt.intros simp: Let_def split: option.splits) + subgoal for deg treeList summary + apply (rule even_odd_cases[of deg]; simp) + apply (rule invar_vebt.intros(2); simp) + apply (rule invar_vebt.intros(3); simp add: algebra_simps) by presburger + subgoal for deg treeList summary mi ma + apply (rule even_odd_cases[of deg]; simp) + subgoal + apply (rule invar_vebt.intros(4); simp?) + apply (auto simp: in_children_def) [] + apply (meson le_less_linear le_less_trans) + apply (metis Euclidean_Division.div_eq_0_iff div_exp_eq gr_implies_not0 high_def) + done + subgoal + apply (rule invar_vebt.intros(5); simp?) + apply (auto) [] + apply (auto) [] + apply (auto simp: in_children_def) [] + apply (meson le_less_linear le_less_trans) + by (metis Euclidean_Division.div_eq_0_iff add_Suc_right div_exp_eq high_def power_Suc power_eq_0_iff zero_neq_numeral) + done + done + +lemma valid_eq: "valid' t d \ invar_vebt t d" + using valid_eq1 valid_eq2 by auto + +lemma [termination_simp]: assumes "odd (v::nat)" shows "v div 2 < v" + by (simp add: assms odd_pos) + +lemma [termination_simp]:assumes "n > 1" and " odd n" shows" Suc (n div 2) < n" + by (metis Suc_lessI add_diff_cancel_left' assms(1) assms(2) div_eq_dividend_iff div_less_dividend even_Suc even_Suc_div_two odd_pos one_less_numeral_iff plus_1_eq_Suc semiring_norm(76) zero_less_diff) + +end + +subsection \Function for generating an empty tree of arbitrary degree respectively order\ + +context begin +interpretation VEBT_internal . + +fun vebt_buildup :: "nat \ VEBT" where + "vebt_buildup 0 = Leaf False False"| + "vebt_buildup (Suc 0) = Leaf False False"| + "vebt_buildup n = (if even n then (let half = n div 2 in + Node None n (replicate (2^half) (vebt_buildup half)) (vebt_buildup half)) + else (let half = n div 2 in + Node None n ( replicate (2^(Suc half)) (vebt_buildup half)) (vebt_buildup (Suc half))))" + +end + +context VEBT_internal begin + +lemma buildup_nothing_in_leaf: "\ naive_member (vebt_buildup n) x" +proof(induction arbitrary: x rule: vebt_buildup.induct) + case 1 + then show ?case by simp +next + case (2 v) + then show ?case + by simp +next + case (3 n) + let ?n = "Suc(Suc n)" + show ?case proof(cases "even ?n") + case True + let ?half = "?n div 2" + have "\ naive_member (vebt_buildup ?half) y" for y + using "3.IH"(1) True by blast + hence 0:"\ t \ set (replicate (2^?half) (vebt_buildup ?half)) . \ naive_member t x" + by simp + have "naive_member (vebt_buildup ?n) x \ False" + proof- + assume "naive_member (vebt_buildup ?n) x" + hence "high x ?half < 2^?half \ + naive_member ((replicate (2^?half) (vebt_buildup ?half)) ! (high x ?half)) (low x ?half)" + by (metis True vebt_buildup.simps(3) length_replicate naive_member.simps(3)) + hence "\ t \ set (replicate (2^?half) (vebt_buildup ?half)) . naive_member t x " + by (metis \\y. \ naive_member (vebt_buildup (Suc (Suc n) div 2)) y\ nth_replicate) + then show False using 0 by simp + qed + then show ?thesis + by blast + next + case False + let ?half = "?n div 2" + have "\ naive_member (vebt_buildup ?half) y" for y + using "3.IH" False by blast + hence 0:"\ t \ set (replicate (2^(Suc ?half)) (vebt_buildup ?half)) . \ naive_member t x" + by simp + have "naive_member (vebt_buildup ?n) x \ False" + proof- + assume "naive_member (vebt_buildup ?n) x" + hence "high x ?half < 2^(Suc ?half) \ + naive_member ((replicate (2^(Suc ?half)) (vebt_buildup ?half)) ! (high x ?half)) (low x ?half)" + by (metis False vebt_buildup.simps(3) length_replicate naive_member.simps(3)) + hence "\ t \ set (replicate (2^(Suc ?half)) (vebt_buildup ?half)) . naive_member t x " + by (metis \\y. \ naive_member (vebt_buildup (Suc (Suc n) div 2)) y\ nth_replicate) + then show False using 0 by simp + qed + then show ?thesis by force + qed +qed + + +lemma buildup_nothing_in_min_max:"\ membermima (vebt_buildup n) x" +proof(induction arbitrary: x rule: vebt_buildup.induct) + case 1 + then show ?case by simp +next + case 2 + then show ?case by simp +next + case (3 va) + let ?n = "Suc (Suc va)" + let ?half = "?n div 2" + show ?case proof(cases "even ?n") + case True + have "\ membermima (vebt_buildup ?half) y" for y + using "3.IH"(1) True by blast + hence 0:"\ t \ set (replicate (2^?half) (vebt_buildup ?half)) . \ membermima t x" + by simp + then show ?thesis + by (metis "3.IH"(1) True vebt_buildup.simps(3) inthrepl length_replicate membermima.simps(5)) + next + case False + have "\ membermima (vebt_buildup ?half) y" for y + using "3.IH" False by blast + moreover hence 0:"\ t \ set (replicate (2^(Suc ?half)) (vebt_buildup ?half)) . \ membermima t x" + by simp + ultimately show ?thesis + by (metis vebt_buildup.simps(3) inthrepl length_replicate membermima.simps(5)) + qed +qed + +text \The empty tree generated by $vebt_buildup$ is indeed a valid tree.\ + +lemma buildup_gives_valid: "n>0 \ invar_vebt (vebt_buildup n) n" +proof( induction n rule: vebt_buildup.induct) + case 1 + then show ?case by simp +next + case 2 + then show ?case + by (simp add: invar_vebt.intros(1)) +next + case (3 va) + let ?n = "Suc (Suc va)" + let ?half = "?n div 2" + show ?case proof(cases "even ?n") + case True + hence a:"vebt_buildup ?n = Node None ?n (replicate (2^?half) (vebt_buildup ?half)) (vebt_buildup ?half)" by simp + moreover hence "invar_vebt (vebt_buildup ?half) ?half" + using "3.IH"(1) True by auto + moreover hence "( \ t \ set (replicate (2^?half) (vebt_buildup ?half)). invar_vebt t ?half)" by simp + moreover have "length (replicate (2^?half) (vebt_buildup ?half)) = 2^?half" by auto + moreover have "?half+?half = ?n" + using True by auto + moreover have " \ t \ set (replicate (2^?half) (vebt_buildup ?half)). (\ x. both_member_options t x)" + proof + fix t + assume "t \ set (replicate (2^?half) (vebt_buildup ?half))" + hence "t = (vebt_buildup ?half)" by simp + thus "\ x. both_member_options t x" + by (simp add: both_member_options_def buildup_nothing_in_leaf buildup_nothing_in_min_max) + qed + moreover have " (\ i. both_member_options (vebt_buildup ?half) i)" + using both_member_options_def buildup_nothing_in_leaf buildup_nothing_in_min_max by blast + ultimately have "invar_vebt (Node None ?n (replicate (2^?half) (vebt_buildup ?half)) (vebt_buildup ?half)) ?n" + using invar_vebt.intros(2)[of "replicate (2^?half) (vebt_buildup ?half)" ?half "vebt_buildup ?half" ?half ?n] + by simp + then show ?thesis using a by auto + next + case False + hence a:"vebt_buildup ?n = Node None ?n (replicate (2^(Suc ?half)) (vebt_buildup ?half)) (vebt_buildup (Suc ?half))" by simp + moreover hence "invar_vebt (vebt_buildup (Suc ?half)) (Suc ?half)" + using "3.IH" False by auto + moreover have "invar_vebt (vebt_buildup ?half) ?half" + using "3.IH"(3) False by auto + moreover hence "( \ t \ set (replicate (2^(Suc ?half)) (vebt_buildup ?half)). invar_vebt t ?half)" by simp + moreover have "length (replicate (2^(Suc ?half)) (vebt_buildup ?half)) = 2^(Suc ?half)" by auto + moreover have "(Suc ?half)+?half = ?n" + using False by presburger + moreover have " \ t \ set (replicate (2^(Suc ?half)) (vebt_buildup ?half)). (\ x. both_member_options t x)" + proof + fix t + assume "t \ set (replicate (2^(Suc ?half)) (vebt_buildup ?half))" + hence "t = (vebt_buildup ?half)" by simp + thus "\ x. both_member_options t x" + by (simp add: both_member_options_def buildup_nothing_in_leaf buildup_nothing_in_min_max) + qed + moreover have " (\ i. both_member_options (vebt_buildup (Suc ?half)) i)" + using both_member_options_def buildup_nothing_in_leaf buildup_nothing_in_min_max by blast + moreover have "?half + Suc ?half = ?n" + using calculation(6) by auto + ultimately have "invar_vebt (Node None ?n (replicate (2^(Suc ?half)) (vebt_buildup ?half)) (vebt_buildup (Suc ?half))) ?n" + using invar_vebt.intros(3)[of "replicate (2^(Suc ?half)) (vebt_buildup ?half)" ?half "vebt_buildup (Suc ?half)" "Suc ?half" ?n ] + by simp + then show ?thesis using a by auto + qed +qed + +lemma mi_ma_2_deg: assumes "invar_vebt (Node (Some (mi, ma)) deg treeList summary) n" shows "mi\ ma \ ma < 2^deg" +proof- + from assms show ?thesis proof cases qed blast+ +qed + +lemma deg_not_0: "invar_vebt t n \ n > 0" + apply(induction t n rule: invar_vebt.induct) + apply auto + done + +lemma set_n_deg_not_0:assumes " \t\set treeList. invar_vebt t n"and" length treeList = 2^m "shows " n \ 1" +proof- + have "length treeList > 0" + by (simp add: assms(2)) + then obtain t ts where "treeList = t#ts" + by (metis list.size(3) neq_Nil_conv not_less0) + hence "invar_vebt t n" + by (simp add: assms(1)) + hence "n \ 1" + using deg_not_0 by force + thus ?thesis by simp +qed + +lemma both_member_options_ding: assumes"invar_vebt (Node info deg treeList summary) n "and "x<2^deg"and" + both_member_options (treeList ! (high x (deg div 2))) (low x (deg div 2))"shows "both_member_options (Node info deg treeList summary) x" +proof- + from assms(1) show ?thesis proof(induction "(Node info deg treeList summary)" n rule: invar_vebt.induct) + case (2 n m) + hence "membermima (treeList ! (high x (deg div 2))) (low x (deg div 2)) \ + naive_member (treeList ! (high x (deg div 2))) (low x (deg div 2))" + using assms(3) both_member_options_def by auto + moreover hence "deg > 1" + using "2.hyps"(2) "2.hyps"(5) "2.hyps"(6) deg_not_0 by force + moreover have "high x (deg div 2)<2^m" + by (metis "2.hyps"(5) "2.hyps"(6) Euclidean_Division.div_eq_0_iff add_self_div_2 assms(2) div_exp_eq high_def power_not_zero zero_neq_one) + moreover have "membermima (treeList ! (high x (deg div 2))) (low x (deg div 2)) + \ membermima (Node info deg treeList summary) x" using membermima.simps(5)[of "deg-1" treeList summary x] + using "2.hyps"(4) "2.hyps"(9) \1 < deg\ \high x (deg div 2) < 2 ^ m\ zero_le_one by fastforce + moreover have "naive_member (treeList ! (high x (deg div 2))) (low x (deg div 2)) + \ naive_member (Node info deg treeList summary) x" + by (smt "2.hyps"(4) Suc_diff_Suc \1 < deg\ \high x (deg div 2) < 2 ^ m\ diff_zero le_less_trans naive_member.simps(3) zero_le_one) + ultimately show ?case + using both_member_options_def by blast + next + case (3 n m) + hence "membermima (treeList ! (high x (deg div 2))) (low x (deg div 2)) \ + naive_member (treeList ! (high x (deg div 2))) (low x (deg div 2))" + using assms(3) both_member_options_def by auto + moreover hence "deg > 1" + by (metis "3.hyps"(1) "3.hyps"(2) "3.hyps"(4) "3.hyps"(5) "3.hyps"(6) One_nat_def Suc_lessI add_Suc add_gr_0 add_self_div_2 deg_not_0 le_imp_less_Suc plus_1_eq_Suc set_n_deg_not_0) + moreover have "high x (deg div 2)<2^m" + by (smt "3.hyps"(5) "3.hyps"(6) Euclidean_Division.div_eq_0_iff add_Suc_right add_self_div_2 assms(2) diff_Suc_1 div_exp_eq div_mult_self1_is_m even_Suc high_def odd_add odd_two_times_div_two_nat one_add_one plus_1_eq_Suc power_not_zero zero_less_Suc) + moreover have "membermima (treeList ! (high x (deg div 2))) (low x (deg div 2)) + \ membermima (Node info deg treeList summary) x" using membermima.simps(5)[of "deg-1" treeList summary x] + using "3.hyps"(4) "3.hyps"(9) \1 < deg\ \high x (deg div 2) < 2 ^ m\ zero_le_one by fastforce + moreover have "naive_member (treeList ! (high x (deg div 2))) (low x (deg div 2)) + \ naive_member (Node info deg treeList summary) x" + by (smt "3.hyps"(4) Suc_diff_Suc \1 < deg\ \high x (deg div 2) < 2 ^ m\ diff_zero le_less_trans naive_member.simps(3) zero_le_one) + ultimately show ?case + using both_member_options_def by blast + next + case (4 n m mi ma) + hence "membermima (treeList ! (high x (deg div 2))) (low x (deg div 2)) \ + naive_member (treeList ! (high x (deg div 2))) (low x (deg div 2))" + using assms(3) both_member_options_def by auto + moreover hence "deg > 1" + using "4.hyps"(2) "4.hyps"(5) "4.hyps"(6) deg_not_0 by force + moreover have "high x (deg div 2)<2^m" + by (metis "4.hyps"(5) "4.hyps"(6) Euclidean_Division.div_eq_0_iff add_self_div_2 assms(2) div_exp_eq high_def power_not_zero zero_neq_one) + moreover have "membermima (treeList ! (high x (deg div 2))) (low x (deg div 2)) + \ membermima (Node info deg treeList summary) x" using membermima.simps(5)[of "deg-1" treeList summary x] + by (smt "4.hyps"(12) "4.hyps"(4) Suc_diff_Suc calculation(2) calculation(3) diff_zero le_less_trans membermima.simps(4) zero_le_one) + moreover have "naive_member (treeList ! (high x (deg div 2))) (low x (deg div 2)) + \ naive_member (Node info deg treeList summary) x" + by (metis "4.hyps"(4) calculation(2) calculation(3) gr_implies_not0 naive_member.simps(3) old.nat.exhaust) ultimately show ?case + using both_member_options_def by blast + next + case (5 n m mi ma) + hence "membermima (treeList ! (high x (deg div 2))) (low x (deg div 2)) \ + naive_member (treeList ! (high x (deg div 2))) (low x (deg div 2))" + using assms(3) both_member_options_def by auto + moreover hence "deg > 1" + by (metis "5.hyps"(1) "5.hyps"(2) "5.hyps"(4) "5.hyps"(5) "5.hyps"(6) One_nat_def Suc_lessI add_Suc add_gr_0 add_self_div_2 deg_not_0 le_imp_less_Suc plus_1_eq_Suc set_n_deg_not_0) + moreover have "high x (deg div 2)<2^m" + by (metis "5.hyps"(5) "5.hyps"(6) Euclidean_Division.div_eq_0_iff add_Suc_right add_self_div_2 assms(2) div_exp_eq even_Suc_div_two even_add high_def nat.simps(3) power_not_zero) + moreover have "membermima (treeList ! (high x (deg div 2))) (low x (deg div 2)) + \ membermima (Node info deg treeList summary) x" using membermima.simps(5)[of "deg-1" treeList summary x] + by (smt "5.hyps"(12) "5.hyps"(4) Suc_diff_Suc calculation(2) calculation(3) diff_zero le_less_trans membermima.simps(4) zero_le_one) + moreover have "naive_member (treeList ! (high x (deg div 2))) (low x (deg div 2)) + \ naive_member (Node info deg treeList summary) x" + using "5.hyps"(4) "5.hyps"(5) "5.hyps"(6) calculation(3) by auto + ultimately show ?case + using both_member_options_def by blast + qed +qed + +lemma exp_split_high_low: assumes "x < 2^(n+m)" and "n > 0" and "m> 0" + shows "high x n < 2^m" and "low x n < 2^n" + apply (metis Euclidean_Division.div_eq_0_iff assms(1) div_exp_eq high_def nat.simps(3) numeral_2_eq_2 power_not_zero) + by (simp add: low_def) + +lemma low_inv: assumes "x< 2^n " shows "low (y*2^n + x) n = x" unfolding low_def + by (simp add: assms) + +lemma high_inv: assumes "x< 2^n " shows "high (y*2^n + x) n = y" unfolding high_def + by (simp add: assms) + +lemma both_member_options_from_chilf_to_complete_tree: + assumes "high x (deg div 2) < length treeList" and "deg \1" and "both_member_options (treeList ! ( high x (deg div 2))) (low x (deg div 2))" + shows "both_member_options (Node (Some (mi, ma)) deg treeList summary) x" +proof- + have "membermima (treeList ! ( high x (deg div 2))) (low x (deg div 2)) \ + naive_member (treeList ! ( high x (deg div 2))) (low x (deg div 2))" using assms + using both_member_options_def by blast + moreover have "membermima (treeList ! ( high x (deg div 2))) (low x (deg div 2)) \ + membermima (Node (Some (mi, ma)) deg treeList summary) x" + using membermima.simps(4)[of mi ma "deg-1" treeList summary x] + by (metis Suc_1 Suc_leD assms(1) assms(2) le_add_diff_inverse plus_1_eq_Suc) + moreover have "naive_member (treeList ! ( high x (deg div 2))) (low x (deg div 2)) \ + naive_member (Node (Some (mi, ma)) deg treeList summary) x" + using naive_member.simps(3)[of "Some (mi, ma)" "deg-1" treeList summary x] + by (metis Suc_1 Suc_leD assms(1) assms(2) le_add_diff_inverse plus_1_eq_Suc) + ultimately show ?thesis + using both_member_options_def by blast +qed + +lemma both_member_options_from_complete_tree_to_child: + assumes "deg \1" and "both_member_options (Node (Some (mi, ma)) deg treeList summary) x" + shows "both_member_options (treeList ! ( high x (deg div 2))) (low x (deg div 2)) \ x = mi \ x = ma" +proof- + have "naive_member (Node (Some (mi, ma)) deg treeList summary) x \ + membermima (Node (Some (mi, ma)) deg treeList summary) x " + using assms(2) both_member_options_def by auto + moreover have " naive_member (Node (Some (mi, ma)) deg treeList summary) x + \ naive_member (treeList ! ( high x (deg div 2))) (low x (deg div 2))" + using naive_member.simps(3)[of "Some (mi, ma)" "deg-1" treeList summary x] + by (metis assms(1) le_add_diff_inverse plus_1_eq_Suc) + moreover have " membermima (Node (Some (mi, ma)) deg treeList summary) x + \ membermima (treeList ! ( high x (deg div 2))) (low x (deg div 2))\ x = mi \ x = ma" + by (smt (z3) assms(1) le_add_diff_inverse membermima.simps(4) plus_1_eq_Suc) + ultimately show ?thesis + using both_member_options_def by presburger +qed + +lemma pow_sum: "(divide::nat \ nat \ nat) ((2::nat) ^((a::nat)+(b::nat))) (2^a) = 2^b" + by (induction a) simp+ + +fun elim_dead::"VEBT \ enat \ VEBT" where +"elim_dead (Leaf a b) _ = Leaf a b "| +"elim_dead (Node info deg treeList summary) \ = + (Node info deg (map (\ t. elim_dead t (enat (2^(deg div 2)))) treeList) + (elim_dead summary \))"| +"elim_dead (Node info deg treeList summary) (enat l) = + (Node info deg (take (l div (2^(deg div 2))) (map (\ t. elim_dead t (enat (2^(deg div 2))))treeList)) + (elim_dead summary ((enat (l div (2^(deg div 2))))))) " + +lemma elimnum: "invar_vebt (Node info deg treeList summary) n \ + elim_dead (Node info deg treeList summary) (enat ((2::nat)^n)) = (Node info deg treeList summary)" +proof(induction rule: invar_vebt.induct) + case (1 a b) + then show ?case + by simp +next + case (2 treeList n summary m deg) + have a:"i < 2^m \ (elim_dead (treeList ! i) (enat( 2^n)) = treeList ! i)" for i + proof + assume "i < 2^m" + hence "treeList ! i \ set treeList" + by (simp add: "2.hyps"(2)) + thus "elim_dead (treeList ! i) (enat (2 ^ n)) = treeList ! i" + using "2.IH"(1) by blast + qed + hence b:"map (\ t. elim_dead t (enat (2 ^ n))) treeList = treeList" + by (simp add: "2.IH"(1) map_idI) + have "deg div 2 = n" + by (simp add: "2.hyps"(3) "2.hyps"(4)) + hence "(2^m ::nat) = ( (2^deg) div (2^(deg div 2))::nat) " + using "2.hyps"(4) pow_sum by metis + hence "take (2^deg div (2^(deg div 2)))(map (\ t. elim_dead t (enat (2 ^ n))) treeList) = treeList" + using b "2"(4) by simp + moreover hence " ( elim_dead summary ((enat ((2^deg) div (2^(deg div 2)))))) = summary" + using "2.IH"(2) + by (metis \2 ^ m = 2 ^ deg div 2 ^ (deg div 2)\) + ultimately show ?case using elim_dead.simps(3)[of None deg treeList summary "2^deg"] + using \deg div 2 = n\ by metis +next + case (3 treeList n summary m deg) + have a:"i < 2^m \ (elim_dead (treeList ! i) (enat( 2^n)) = treeList ! i)" for i + proof + assume "i < 2^m" + hence "treeList ! i \ set treeList" + by (simp add: "3.hyps"(2)) + thus "elim_dead (treeList ! i) (enat (2 ^ n)) = treeList ! i" + using "3.IH"(1) by blast + qed + hence b:"map (\ t. elim_dead t (enat (2 ^ n))) treeList = treeList" + by (simp add: "3.IH"(1) map_idI) + have "deg div 2 = n" + by (simp add: "3.hyps"(3) "3.hyps"(4)) + hence "(2^m ::nat) = ( (2^deg) div (2^(deg div 2))::nat) " + using "3.hyps"(4) pow_sum by metis + hence "take (2^deg div (2^(deg div 2)))(map (\ t. elim_dead t (enat (2 ^ n))) treeList) = treeList" + using b "3"(4) by simp + moreover hence " ( elim_dead summary ((enat ((2^deg) div (2^(deg div 2)))))) = summary" using "3.IH"(2) + by (metis \2 ^ m = 2 ^ deg div 2 ^ (deg div 2)\) + ultimately show ?case using elim_dead.simps(3)[of None deg treeList summary "2^deg"] + using \deg div 2 = n\ by metis +next + case (4 treeList n summary m deg mi ma) + have a:"i < 2^m \ (elim_dead (treeList ! i) (enat( 2^n)) = treeList ! i)" for i + proof + assume "i < 2^m" + hence "treeList ! i \ set treeList" + by (simp add: "4.hyps"(2)) + thus "elim_dead (treeList ! i) (enat (2 ^ n)) = treeList ! i" + using "4.IH"(1) by blast + qed + hence b:"map (\ t. elim_dead t (enat (2 ^ n))) treeList = treeList" + by (simp add: "4.IH"(1) map_idI) + have "deg div 2 = n" + by (simp add: "4.hyps"(3) "4.hyps"(4)) + hence "(2^m ::nat) = ( (2^deg) div (2^(deg div 2))::nat) " + using "4.hyps"(4) pow_sum by metis + hence "take (2^deg div (2^(deg div 2)))(map (\ t. elim_dead t (enat (2 ^ n))) treeList) = treeList" + using b "4"(4) by simp + moreover hence " ( elim_dead summary ((enat ((2^deg) div (2^(deg div 2)))))) = summary" using "4.IH"(2) + by (metis \2 ^ m = 2 ^ deg div 2 ^ (deg div 2)\) + ultimately show ?case using elim_dead.simps(3)[of "Some (mi, ma)" deg treeList summary "2^deg"] + using \deg div 2 = n\ by metis +next + case (5 treeList n summary m deg mi ma) + have a:"i < 2^m \ (elim_dead (treeList ! i) (enat( 2^n)) = treeList ! i)" for i + proof + assume "i < 2^m" + hence "treeList ! i \ set treeList" + by (simp add: "5.hyps"(2)) + thus "elim_dead (treeList ! i) (enat (2 ^ n)) = treeList ! i" + using "5.IH"(1) by blast + qed + hence b:"map (\ t. elim_dead t (enat (2 ^ n))) treeList = treeList" + by (simp add: "5.IH"(1) map_idI) + have "deg div 2 = n" + by (simp add: "5.hyps"(3) "5.hyps"(4)) + hence "(2^m ::nat) = ( (2^deg) div (2^(deg div 2))::nat) " + using "5.hyps"(4) pow_sum by metis + hence "take (2^deg div (2^(deg div 2)))(map (\ t. elim_dead t (enat (2 ^ n))) treeList) = treeList" + using b "5"(4) by simp + moreover hence " ( elim_dead summary ((enat ((2^deg) div (2^(deg div 2)))))) = summary" using "5.IH"(2) + by (metis \2 ^ m = 2 ^ deg div 2 ^ (deg div 2)\) + ultimately show ?case using elim_dead.simps(3)[of "Some (mi, ma)" deg treeList summary "2^deg"] + using \deg div 2 = n\ by metis +qed + +lemma elimcomplete: "invar_vebt (Node info deg treeList summary) n \ + elim_dead (Node info deg treeList summary) \ = (Node info deg treeList summary)" +proof(induction rule: invar_vebt.induct) + case (1 a b) + then show ?case + by simp +next + case (2 treeList n summary m deg) + have a:"i < 2^m \ (elim_dead (treeList ! i) (enat( 2^n)) = treeList ! i)" for i + proof + assume "i < 2^m" + hence "treeList ! i \ set treeList" + by (simp add: "2.hyps"(2)) + thus "elim_dead (treeList ! i) (enat (2 ^ n)) = treeList ! i" + apply(cases "(treeList ! i)") + apply (smt (z3) "2.IH"(1) \treeList ! i \ set treeList\ elim_dead.simps(1) elimnum invar_vebt.cases)+ + done + qed + hence b:"map (\ t. elim_dead t (enat (2 ^ n))) treeList = treeList" + by (metis "2.hyps"(2) in_set_conv_nth map_idI) + have "deg div 2 = n" + by (simp add: "2.hyps"(3) "2.hyps"(4)) + hence "(2^m ::nat) = ( (2^deg) div (2^(deg div 2))::nat) " + using "2.hyps"(4) pow_sum by metis + hence "take (2^deg div (2^(deg div 2)))(map (\ t. elim_dead t (enat (2 ^ n))) treeList) = treeList" + using b "2"(4) by simp + moreover hence " ( elim_dead summary \) = summary" using "2.IH"(2) + by (metis \2 ^ m = 2 ^ deg div 2 ^ (deg div 2)\) + ultimately show ?case using elim_dead.simps(2)[of None deg treeList summary] + using \deg div 2 = n\ b by presburger +next + case (3 treeList n summary m deg) + have a:"i < 2^m \ (elim_dead (treeList ! i) (enat( 2^n)) = treeList ! i)" for i + proof + assume "i < 2^m" + hence "treeList ! i \ set treeList" + by (simp add: "3.hyps"(2)) + thus "elim_dead (treeList ! i) (enat (2 ^ n)) = treeList ! i" + apply(cases "(treeList ! i)") + apply (smt (z3) "3.IH"(1) \treeList ! i \ set treeList\ elim_dead.simps(1) elimnum invar_vebt.cases)+ + done + qed + hence b:"map (\ t. elim_dead t (enat (2 ^ n))) treeList = treeList" + by (metis "3.hyps"(2) in_set_conv_nth map_idI) + have "deg div 2 = n" + by (simp add: "3.hyps"(3) "3.hyps"(4)) + hence "(2^m ::nat) = ( (2^deg) div (2^(deg div 2))::nat) " + using "3.hyps"(4) pow_sum by metis + hence "take (2^deg div (2^(deg div 2)))(map (\ t. elim_dead t (enat (2 ^ n))) treeList) = treeList" + using b "3"(4) by simp + moreover hence " ( elim_dead summary \) = summary" using "3.IH"(2) + by (metis \2 ^ m = 2 ^ deg div 2 ^ (deg div 2)\) + ultimately show ?case using elim_dead.simps(2)[of None deg treeList summary] + using \deg div 2 = n\ b by presburger +next + case (4 treeList n summary m deg mi ma) + have a:"i < 2^m \ (elim_dead (treeList ! i) (enat( 2^n)) = treeList ! i)" for i + proof + assume "i < 2^m" + hence "treeList ! i \ set treeList" + by (simp add: "4.hyps"(2)) + thus "elim_dead (treeList ! i) (enat (2 ^ n)) = treeList ! i" + apply(cases "(treeList ! i)") + apply (smt (z3) "4.IH"(1) \treeList ! i \ set treeList\ elim_dead.simps(1) elimnum invar_vebt.cases)+ + done + qed + hence b:"map (\ t. elim_dead t (enat (2 ^ n))) treeList = treeList" + by (metis "4.hyps"(2) in_set_conv_nth map_idI) + have "deg div 2 = n" + by (simp add: "4.hyps"(3) "4.hyps"(4)) + hence "(2^m ::nat) = ( (2^deg) div (2^(deg div 2))::nat) " + using "4.hyps"(4) pow_sum by metis + hence "take (2^deg div (2^(deg div 2)))(map (\ t. elim_dead t (enat (2 ^ n))) treeList) = treeList" + using b "4"(4) by simp + moreover hence " ( elim_dead summary \) = summary" using "4.IH"(2) + by (metis \2 ^ m = 2 ^ deg div 2 ^ (deg div 2)\) + ultimately show ?case using elim_dead.simps(2)[of "Some (mi, ma)" deg treeList summary] + using \deg div 2 = n\ b by presburger +next + case (5 treeList n summary m deg mi ma) + have a:"i < 2^m \ (elim_dead (treeList ! i) (enat( 2^n)) = treeList ! i)" for i + proof + assume "i < 2^m" + hence "treeList ! i \ set treeList" + by (simp add: "5.hyps"(2)) + thus "elim_dead (treeList ! i) (enat (2 ^ n)) = treeList ! i" + apply(cases "(treeList ! i)") + apply (smt (z3) "5.IH"(1) \treeList ! i \ set treeList\ elim_dead.simps(1) elimnum invar_vebt.cases)+ + done + qed + hence b:"map (\ t. elim_dead t (enat (2 ^ n))) treeList = treeList" + by (metis "5.hyps"(2) in_set_conv_nth map_idI) + have "deg div 2 = n" + by (simp add: "5.hyps"(3) "5.hyps"(4)) + hence "(2^m ::nat) = ( (2^deg) div (2^(deg div 2))::nat) " + using "5.hyps"(4) pow_sum by metis + hence "take (2^deg div (2^(deg div 2)))(map (\ t. elim_dead t (enat (2 ^ n))) treeList) = treeList" + using b "5"(4) by simp + moreover hence " ( elim_dead summary \) = summary" using "5.IH"(2) + by (metis \2 ^ m = 2 ^ deg div 2 ^ (deg div 2)\) + ultimately show ?case using elim_dead.simps(2)[of "Some (mi, ma)" deg treeList summary] + using \deg div 2 = n\ b by presburger +qed + +end +end diff --git a/thys/Van_Emde_Boas_Trees/VEBT_DelImperative.thy b/thys/Van_Emde_Boas_Trees/VEBT_DelImperative.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/VEBT_DelImperative.thy @@ -0,0 +1,615 @@ +(*by Ammer*) +theory VEBT_DelImperative imports VEBT_DeleteCorrectness VEBT_SuccPredImperative +begin + +context begin +interpretation VEBT_internal . + +section \Imperative Delete\ + +partial_function (heap_time) vebt_deletei::"VEBTi \ nat \ VEBTi Heap" where + "vebt_deletei t x = (case t of (Leafi a b) \ (if x = 0 then return (Leafi False b) else + if x = 1 then return (Leafi a False) else + return (Leafi a b)) | + (Nodei info deg treeArray summary) \ ( + if deg \ 1 then return (Nodei info deg treeArray summary) else + case info of None \ return (Nodei info deg treeArray summary)| + (Some mima) \ ( if x < fst mima \ x > snd mima then return (Nodei info deg treeArray summary) + else if fst mima = x \ snd mima = x then return (Nodei None deg treeArray summary) + else do{ xminew <- (if x = fst mima then do { + firstcluster <- vebt_minti summary; + firsttree <- Array_Time.nth treeArray (the firstcluster); + mintft <- vebt_minti firsttree; + let xn = (2^(deg div 2) * (the firstcluster) + + (the mintft) ); + return (xn, xn) + } + else return (x, fst mima)); + let xnew = fst xminew; + let minew = snd xminew; + h <- highi xnew (deg div 2); + l <- lowi xnew (deg div 2); + aktnode <- Array_Time.nth treeArray h; + aktnode'<-vebt_deletei aktnode l; + treeArray' <- Array_Time.upd h aktnode' treeArray; + miny <- vebt_minti aktnode'; + (if (miny = None) then + do{ + summary' <-vebt_deletei summary h; + ma <- (if xnew = snd mima then + do{ + summax <- vebt_maxti summary'; + if summax = None then + return minew + else do{ + maxtree <- Array_Time.nth treeArray' (the summax); + mofmtree<- vebt_maxti maxtree; + return (the summax * 2^(deg div 2) + + the mofmtree ) + } + } + else return (snd mima)); + return (Nodei (Some (minew, ma)) deg treeArray' summary') + } else if xnew = snd mima then + do{ + nextree <- Array_Time.nth treeArray' h; + maxnext<- vebt_maxti nextree; + let ma = h * 2^(deg div 2) + + (the maxnext); + return (Nodei (Some ( minew, ma)) deg treeArray' summary) + } + else return (Nodei (Some (minew, snd mima)) deg treeArray' summary) ) + })))" + +end + +context VEBT_internal begin + + +text \Some general lemmas\ + +lemma midextr:"(P * Q * Q' *R \\<^sub>A X) \ (P * R * Q *Q' \\<^sub>A X)" + by (smt (verit, ccfv_threshold) ab_semigroup_mult_class.mult.commute assn_aci(9) entails_def mod_frame_fwd) + +lemma groupy: "A *B * (C * D) \\<^sub>A X \A *B * C * D \\<^sub>A X " + by (simp add: assn_aci(9)) + +lemma swappa: "B* A* C \\<^sub>A X \A *B * C \\<^sub>A X " + by (simp add: ab_semigroup_mult_class.mult.commute) + +lemma mulcomm: "(i::nat) * (2 * 2 ^ (va div 2)) = (2 * 2 ^ (va div 2)) * i" + by simp + +text \Modified function with ghost variable\ + +partial_function (heap_time) vebt_deletei'::"VEBT \ VEBTi \ nat \ VEBTi Heap" where + "vebt_deletei' t ti x = (case ti of (Leafi a b) \ (if x = 0 then return (Leafi False b) else + if x = 1 then return (Leafi a False) else + return (Leafi a b)) | + (Nodei info deg treeArray summary) \ ( + do { assert'( is_Node t); + let (info',deg',treeList,summary') = + (case t of Node info' deg' treeList summary' + \ (info',deg',treeList,summary')); + assert'(info'=info \ deg'=deg \ is_Node t); + if deg \ 1 then return (Nodei info deg treeArray summary) else + case info of None \ return (Nodei info deg treeArray summary)| + (Some mima) \ ( + if x < fst mima \ x > snd mima then return (Nodei info deg treeArray summary) + else if fst mima = x \ snd mima = x then return (Nodei None deg treeArray summary) + else do{ xminew <- (if x = fst mima then do { + firstcluster <- vebt_minti summary; + firsttree <- Array_Time.nth treeArray (the firstcluster); + mintft <- vebt_minti firsttree; + let xn = (2^(deg div 2) * (the firstcluster) + + (the mintft) ); + return (xn, xn) + } + else return (x, fst mima)); + let xnew = fst xminew; + let xn' = + (if x = fst (the info') + then the (vebt_mint summary') * 2^(deg div 2) + + the (vebt_mint (treeList ! the (vebt_mint summary'))) + else x); + assert' (xnew = xn'); + let minew = snd xminew; + assert' (minew = (if x = fst (the info') then xn' else fst (the info'))); + h <- highi xnew (deg div 2); + assert' (h = high xnew (deg div 2)); + assert'( h < length treeList); + l <- lowi xnew (deg div 2); + assert'(l = low xnew (deg div 2)); + aktnode <- Array_Time.nth treeArray h; + aktnode'<-vebt_deletei' (treeList ! h) aktnode l; + treeArray' <- Array_Time.upd h aktnode' treeArray; + let funnode = vebt_delete (treeList ! h) l; + let treeList' = treeList[h:= funnode]; + miny <- vebt_minti aktnode'; + assert' (miny = vebt_mint funnode); + (if (miny = None) then + do{ + summaryi' <-vebt_deletei' summary' summary h; + ma <- (if xnew = snd mima then + do{ + summax <- vebt_maxti summaryi'; + assert' (summax = vebt_maxt (vebt_delete summary' h)); + if summax = None then + return minew + else do{ + maxtree <- Array_Time.nth treeArray' (the summax); + mofmtree<- vebt_maxti maxtree; + return (the summax * 2^(deg div 2) + + the mofmtree ) + } + } + else return (snd mima)); + return (Nodei (Some (minew, ma)) deg treeArray' summaryi') + } else if xnew = snd mima then + do{ + nextree <- Array_Time.nth treeArray' h; + maxnext<- vebt_maxti nextree; + assert' (maxnext = vebt_maxt (treeList' ! h)); + let ma = h * 2^(deg div 2) + + (the maxnext); + return (Nodei (Some ( minew, ma)) deg treeArray' summary) + } + else return (Nodei (Some (minew, snd mima)) deg treeArray' summary) ) + })}))" + + +theorem deleti'_rf_abstr: "invar_vebt t n \ vebt_deletei' t ti x< vebt_assn_raw (vebt_delete t x)>" +proof(induction t x arbitrary: ti n rule: vebt_delete.induct) + case (1 a b) + then show ?case by(subst vebt_deletei'.simps) (cases ti; sep_auto) +next + case (2 a b) + then show ?case by(subst vebt_deletei'.simps) (cases ti; sep_auto) +next + case (3 a b n) + then show ?case by(subst vebt_deletei'.simps) (cases ti; sep_auto) +next + case (4 deg treeList summary uu) + then show ?case by(subst vebt_deletei'.simps) (cases ti; sep_auto) +next + case (5 mi ma treeList summary x) + then show ?case by(subst vebt_deletei'.simps) (cases ti; sep_auto) +next + case (6 mi ma treeList summary x) + then show ?case by(subst vebt_deletei'.simps) (cases ti; sep_auto) +next + case (7 mi ma va treeList summary x) + have setprop: "t \ set treeList \ invar_vebt t (n div 2 )" for t using 7(3) + by (cases) simp+ + have listlength: "length treeList = 2^(n - n div 2)" using 7(3) + by (cases) simp+ + have sumprop: "invar_vebt summary (n - n div 2)" using 7(3) + by (cases) simp+ + have mimaxprop: "mi \ ma \ ma \ 2^n" using 7(3) + by cases simp+ + hence xbound: "mi \ x \ x \ ma \ high x (n div 2) \ length treeList " + using div_le_mono high_def listlength power_minus_is_div by auto + let ?xn = " the (vebt_mint summary) * 2 ^ (Suc (Suc va) div 2) + the (vebt_mint (treeList ! the (vebt_mint summary)))" + obtain xnew where xndef: "xnew = ?xn" by simp + let ?minn = "?xn" + obtain minew where minewdef: "minew =?minn" by simp + have highboundn:"ma \ mi \x\ ma \high xnew (n div 2 )< length treeList" using xndef + by (smt (z3) "7.prems" deg_deg_n diff_diff_cancel div2_Suc_Suc div_le_dividend high_bound_aux leD le_add_diff_inverse less_imp_diff_less listlength mi_ma_2_deg nested_mint power_Suc) + have highbound: "ma \ mi \x\ ma \high x (n div 2 )< length treeList" + by (smt (z3) "7.prems" deg_deg_n div_le_dividend high_bound_aux le_less_trans listlength mi_ma_2_deg ordered_cancel_comm_monoid_diff_class.add_diff_inverse) + let ?aktnode = "(treeList ! + high (2 * 2 ^ (va div 2) * the (vebt_mint summary) + the (vebt_mint (treeList ! the (vebt_mint summary)))) (Suc (va div 2)))" + obtain aktnode where aktnodedef:"ma \ mi \x\ ma \aktnode = ?aktnode" + by meson + let ?newnode = "vebt_delete ?aktnode (low ?xn (Suc (Suc va) div 2))" + obtain newnode where newnodedef:"newnode = ?newnode" by presburger + let ?newlist="treeList[ high (2 * 2 ^ (va div 2) * the (vebt_mint summary) + the (vebt_mint (treeList ! the (vebt_mint summary)))) (Suc (va div 2)) := + ?newnode]" + let ?newlist'="treeList[ high x (Suc (va div 2)) := vebt_delete (treeList ! high x (Suc (va div 2))) (low x (Suc (va div 2)))]" + show ?case + apply(cases ti) + prefer 2 + subgoal + apply simp + done + supply [split del] = if_split + apply (subst vebt_deletei'.simps; clarsimp split del: ) + apply (assn_simp; intro normalize_rules) + apply simp + apply(cases "x < mi \ ma < x") + subgoal + apply simp + apply sep_auto + done + apply simp + apply(cases "mi = x \ ma = x") + subgoal + apply simp + apply sep_auto + done + apply (extract_pre_pure dest: extract_pre_list_assn_lengthD) + apply (cases "mi = x \ ma = x"; simp) + apply(cases "x = mi") + subgoal + apply simp + apply sep_auto + apply(sep_auto heap: vebt_minti_h) + apply sep_auto + apply (metis "7.prems" listlength mintlistlength option.sel) + apply sep_auto + apply (rewrite in "<\>_<_>" list_assn_conv_idx) + apply (rewrite in "<\>_<_>" listI_assn_extract[where i="the (vebt_mint summary)"]) + apply (metis "7.prems" atLeastLessThan_iff le0 listlength mintlistlength option.sel) + apply (metis "7.prems" listlength mintlistlength option.sel) + apply(sep_auto heap: vebt_minti_h) + apply(rule cons_pre_rule) + apply (rule repack) + apply (metis "7.prems" listlength mintlistlength option.sel) + apply sep_auto + apply (sep_auto heap: highi_h) + apply sep_auto + apply (metis "7.prems" ab_semigroup_mult_class.mult.commute deg_deg_n nested_mint) + apply (sep_auto heap: lowi_h) + apply (metis "7.prems" ab_semigroup_mult_class.mult.commute deg_deg_n div2_Suc_Suc highboundn mimaxprop power_Suc xndef) + apply sep_auto + apply (rewrite in "<\>_<_>" list_assn_conv_idx) + apply (rewrite in "<\>_<_>" listI_assn_extract[where i=" high (2 * 2 ^ (va div 2) * the (vebt_mint summary) + the (vebt_mint (treeList ! the (vebt_mint summary)))) (Suc (va div 2))"]) + apply (metis "7.prems" ab_semigroup_mult_class.mult.commute atLeastLessThan_iff deg_deg_n leI less_nat_zero_code nested_mint) + apply (metis "7.prems" ab_semigroup_mult_class.mult.commute deg_deg_n nested_mint) + apply sep_auto + apply(sep_auto heap: "7.IH"(1)) + apply(simp add: algebra_simps) + apply(simp add: algebra_simps) + apply (metis "7.prems" ab_semigroup_mult_class.mult.commute deg_deg_n nested_mint) + apply(rule setprop) + apply (metis "7.prems" ab_semigroup_mult_class.mult.commute deg_deg_n nested_mint nth_mem) + apply sep_auto + apply (metis "7.prems" ab_semigroup_mult_class.mult.commute deg_deg_n nested_mint) + apply(simp add: Let_def) + apply sep_auto + apply(sep_auto heap: vebt_minti_h) + apply(rule cons_pre_rule) + apply(rule big_assn_simp[of "high (2 * 2 ^ (va div 2) * the (vebt_mint summary) + the (vebt_mint (treeList ! the (vebt_mint summary)))) (Suc (va div 2))" + treeList "(low (2 * 2 ^ (va div 2) * the (vebt_mint summary) + the (vebt_mint (treeList ! the (vebt_mint summary)))) (Suc (va div 2)))" + _ _ _ _ summary]) + apply (metis "7.prems" ab_semigroup_mult_class.mult.commute deg_deg_n div2_Suc_Suc highboundn mimaxprop power_Suc xndef) + apply(cases "vebt_mint (vebt_delete (treeList ! + high (2 * 2 ^ (va div 2) * the (vebt_mint summary) + the (vebt_mint (treeList ! the (vebt_mint summary)))) (Suc (va div 2))) + (low (2 * 2 ^ (va div 2) * the (vebt_mint summary) + the (vebt_mint (treeList ! the (vebt_mint summary)))) (Suc (va div 2)))) = None") + apply simp + subgoal + apply sep_auto + apply(sep_auto heap: "7.IH"(2)) + apply(simp add: algebra_simps)+ + apply (smt (z3) "7.prems" ab_semigroup_add_class.add.commute ab_semigroup_mult_class.mult.left_commute deg_deg_n nested_mint) + apply(rule DEADID.rel_refl) + apply(rule DEADID.rel_refl) + apply(rule minminNull) + apply (metis ab_semigroup_mult_class.mult.commute) + apply(rule sumprop) + apply(rule bind_rule'[where R="\ r.(let sn = vebt_delete summary (high (2 * 2 ^ (va div 2) * + the (vebt_mint summary) + the (vebt_mint (treeList ! the (vebt_mint summary)))) (Suc (va div 2))) in ( \(r = ( + if ?xn = ma then let maxs = vebt_maxt sn in if maxs = None then ?xn + else 2 ^ (Suc (Suc va) div 2) * the maxs + the (vebt_maxt (?newlist ! the maxs)) else ma))))"]) + apply(cases "2 * 2 ^ (va div 2) * the (vebt_mint summary) + the (vebt_mint (treeList ! the (vebt_mint summary))) = ma") + apply simp+ + apply sep_auto + apply(sep_auto heap: vebt_maxti_h) + apply sep_auto + using delete_pres_valid[of summary "n - n div 2" + "(high (2 * 2 ^ (va div 2) * the (vebt_mint summary) + the (vebt_mint (treeList ! the (vebt_mint summary)))) (Suc (va div 2)))"] + maxt_member[of "vebt_delete summary _" "n-n div 2"] member_bound[of "vebt_delete summary _ " _ "n-n div 2"] listlength sumprop + apply (metis both_member_options_equiv_member dele_bmo_cont_corr maxbmo member_bound) + apply sep_auto + apply (rewrite in "<\>_<_>" list_assn_conv_idx) + apply (rewrite in "<\>_<_>" listI_assn_extract[where i=" the ( vebt_maxt (vebt_delete summary (high (2 * 2 ^ (va div 2) * the (vebt_mint summary) + + the (vebt_mint (treeList ! the (vebt_mint summary)))) (Suc (va div 2)))))"]) + apply (metis atLeastLessThan_iff both_member_options_equiv_member dele_bmo_cont_corr le0 length_list_update listlength maxbmo member_bound option.sel sumprop) + apply (metis both_member_options_equiv_member dele_bmo_cont_corr length_list_update listlength maxbmo member_bound option.sel sumprop) + apply(sep_auto heap: vebt_maxti_h) + apply sep_auto + apply (simp add: ab_semigroup_mult_class.mult.commute) + apply auto[1] + apply(cases " the( vebt_maxt (vebt_delete summary + (high (2 * 2 ^ (va div 2) * the (vebt_mint summary) + the (vebt_mint (treeList ! the (vebt_mint summary)))) (Suc (va div 2))))) < length treeList") + using txe + apply (metis length_list_update option.sel) + apply (metis both_member_options_equiv_member dele_bmo_cont_corr listlength maxbmo member_bound option.sel sumprop) + apply simp + apply sep_auto + apply (metis ab_semigroup_mult_class.mult.commute) + apply sep_auto + apply(simp add: Let_def) + apply(cases " high (the (vebt_mint summary) * (2 * 2 ^ (va div 2)) + the (vebt_mint (treeList ! the (vebt_mint summary)))) (Suc (va div 2)) < length treeList") + apply simp + apply(cases "minNull (vebt_delete (treeList ! + high (the (vebt_mint summary) * (2 * 2 ^ (va div 2)) + the (vebt_mint (treeList ! the (vebt_mint summary)))) (Suc (va div 2))) + (low (the (vebt_mint summary) * (2 * 2 ^ (va div 2)) + the (vebt_mint (treeList ! the (vebt_mint summary)))) (Suc (va div 2))))") + subgoal + apply(sep_auto simp: algebra_simps split: if_split) + done + subgoal + apply(auto split: if_split) + apply sep_auto + prefer 2 + apply(rule entails_solve_init) + apply (tactic \Seplogic_Auto.match_frame_tac (resolve_tac @{context} @{thms ent_refl}) @{context} 1\) + apply simp + apply solve_entails + apply (simp add: ab_semigroup_mult_class.mult.commute) + prefer 3 + apply sep_auto + apply (metis ab_semigroup_mult_class.mult.commute minminNull)+ + done + subgoal + apply(rule entails_solve_init) + apply simp + done + subgoal + apply(simp add: Let_def) + apply(auto split: if_split) + apply sep_auto + using "7.prems" deg_deg_n nested_mint apply blast + apply(rule entails_solve_init) + apply (tactic \Seplogic_Auto.match_frame_tac (resolve_tac @{context} @{thms ent_refl}) @{context} 1\) + apply simp + apply solve_entails + apply (simp add: ab_semigroup_mult_class.mult.commute) + using "7.prems" deg_deg_n nested_mint apply blast + apply sep_auto + using "7.prems" deg_deg_n nested_mint apply blast + using "7.prems" deg_deg_n nested_mint apply blast + apply(rule entails_solve_init) + apply (tactic \Seplogic_Auto.match_frame_tac (resolve_tac @{context} @{thms ent_refl}) @{context} 1\) + apply simp + apply solve_entails + apply (simp add: ab_semigroup_mult_class.mult.commute) + using "7.prems" deg_deg_n nested_mint apply blast + done + subgoal + apply(simp add: Let_def) + apply(auto split: if_split) + apply sep_auto + apply(rule entails_solve_init) + apply (tactic \Seplogic_Auto.match_frame_tac (resolve_tac @{context} @{thms ent_refl}) @{context} 1\) + apply simp + apply solve_entails + apply (simp add: ab_semigroup_mult_class.mult.commute) + apply (simp add: ab_semigroup_mult_class.mult.commute minminNull) + done + using "7.prems" deg_deg_n nested_mint apply blast + done + apply(auto split: if_split) + apply sep_auto + apply (metis "7.prems" ab_semigroup_mult_class.mult.commute deg_deg_n nested_mint) + apply (rewrite in "<\>_<_>" list_assn_conv_idx) + apply (rewrite in "<\>_<_>" listI_assn_extract[where i=" high (2 * 2 ^ (va div 2) * the (vebt_mint summary) + the (vebt_mint (treeList ! the (vebt_mint summary)))) (Suc (va div 2))"]) + apply (metis "7.prems" highboundn ab_semigroup_mult_class.mult.commute atLeastLessThan_iff deg_deg_n div2_Suc_Suc leI length_list_update less_nat_zero_code power_Suc xndef) + apply (metis "7.prems" ab_semigroup_mult_class.mult.commute deg_deg_n length_list_update nested_mint) + apply(sep_auto) + apply(sep_auto heap: vebt_maxti_h) + apply sep_auto + apply (simp add: Let_def) + apply(auto split: if_split) + apply(simp add: Let_def) + apply(auto split: if_split) + apply (metis minNullmin mulcomm option.simps(3)) + apply (metis minNullmin mulcomm option.distinct(1)) + subgoal + apply sep_auto + apply (simp add: ab_semigroup_mult_class.mult.commute) + apply(rule listI_assn_reinsert_upd[ where x = "_ ! _"] ) + apply(rule midextr) + apply(rule midextr) + apply(rule groupy) + apply(rule ent_refl) + apply (metis ab_semigroup_mult_class.mult.commute length_list_update) + apply (metis ab_semigroup_mult_class.mult.commute atLeastLessThan_iff le0) + apply(fr_rot 1) + apply(rule swappa) + apply(simp add: mulcomm) + apply(simp add: listI_assn_conv) + apply(rule ent_refl) + done + using "7.prems" deg_deg_n nested_mint + apply blast + apply sep_auto + apply(simp add: Let_def) + apply(auto split: if_split) + apply (simp add: minNullmin mulcomm) + apply (simp add: ab_semigroup_mult_class.mult.commute minNullmin) + apply sep_auto + apply sep_auto + using "7.prems" deg_deg_n nested_mint apply blast + apply(rule swappa) + apply(simp add: mulcomm) + apply(rule ent_refl) + done + apply simp + apply(sep_auto heap: highi_h) + apply (metis "7.prems" deg_deg_n div2_Suc_Suc highbound leI linorder_neqE_nat) + apply(sep_auto heap: lowi_h) + apply (metis "7.prems" deg_deg_n div2_Suc_Suc highbound leI linorder_neqE_nat) + apply sep_auto + apply (rewrite in "<\>_<_>" list_assn_conv_idx) + apply (rewrite in "<\>_<_>" listI_assn_extract[where i=" high x (Suc (va div 2))"]) + apply (metis "7.prems" atLeastLessThan_iff deg_deg_n div2_Suc_Suc highbound leI le_neq_implies_less less_nat_zero_code) + apply (metis "7.prems" antisym_conv2 deg_deg_n div2_Suc_Suc highbound not_le_imp_less) + apply(sep_auto heap: "7.IH"(1)) + apply (metis "7.prems" antisym_conv2 deg_deg_n div2_Suc_Suc highbound not_le_imp_less) + apply(rule setprop) + apply (metis "7.prems" antisym_conv2 deg_deg_n div2_Suc_Suc highbound not_le_imp_less nth_mem) + apply sep_auto + apply (metis "7.prems" deg_deg_n div2_Suc_Suc highbound not_le_imp_less order.not_eq_order_implies_strict) + apply(sep_auto) + apply(sep_auto heap: vebt_minti_h) + apply(rule bind_rule) + apply(rule assert'_rule) + apply (meson mod_pure_star_dist mod_starE) + apply(rule cons_pre_rule) + apply(rule big_assn_simp'[]) + apply (metis "7.prems" deg_deg_n div2_Suc_Suc highbound leI le_neq_implies_less) apply auto[1] + apply(cases "vebt_mint (vebt_delete (treeList ! high x (Suc (va div 2))) (low x (Suc (va div 2))))") + apply simp + subgoal + apply sep_auto + apply(sep_auto heap: "7.IH"(2)) + apply (metis "7.prems" deg_deg_n div2_Suc_Suc highbound leI le_neq_implies_less) + apply simp+ + apply(simp add: minminNull) + apply(rule sumprop) + apply(rule bind_rule'[where R="\ r.(let sn = vebt_delete summary (high x (Suc (va div 2))) in ( \(r = ( + if x = ma then let maxs = vebt_maxt sn in if maxs = None then mi + else 2 ^ (Suc (Suc va) div 2) * the maxs + the (vebt_maxt (?newlist' ! the maxs)) else ma))))"]) + apply(cases "x = ma") + apply simp + apply(sep_auto) + apply(sep_auto heap: vebt_maxti_h) + apply(cases "vebt_maxt (vebt_delete summary (high ma (Suc (va div 2))))") + apply simp + apply sep_auto + apply simp + apply sep_auto + apply (metis both_member_options_equiv_member dele_bmo_cont_corr listlength maxbmo member_bound sumprop) + apply (rewrite in "<\>_<_>" list_assn_conv_idx) + apply (rewrite in "<\>_<_>" listI_assn_extract[where i="the ( vebt_maxt (vebt_delete summary (high ma (Suc (va div 2)))))"]) + apply (metis atLeastLessThan_iff both_member_options_equiv_member dele_bmo_cont_corr le0 length_list_update listlength maxbmo member_bound option.sel sumprop) + apply (metis both_member_options_equiv_member dele_bmo_cont_corr length_list_update listlength maxbmo member_bound option.sel sumprop) + apply sep_auto + apply(sep_auto heap: vebt_maxti_h) + apply sep_auto + apply (smt (verit, ccfv_SIG) ab_semigroup_mult_class.mult.commute ab_semigroup_mult_class.mult.left_commute atLeastLessThan_empty_iff2 atLeastLessThan_iff both_member_options_equiv_member deg_deg_n dele_bmo_cont_corr div2_Suc_Suc div_by_Suc_0 div_mult_self1_is_m div_mult_self_is_m empty_iff ent_refl le0 le_neq_implies_less length_list_update listI_assn_extract list_assn_conv_idx listlength maxbmo member_bound mimaxprop numeral_2_eq_2 option.collapse option.distinct(1) sumprop zero_less_Suc) + apply simp + apply sep_auto + apply sep_auto + apply(simp add: Let_def) + apply(cases "high ma (Suc (va div 2)) < length treeList") + apply simp + apply(simp add: Let_def) + apply(cases "high ma (Suc (va div 2)) < length treeList") + apply simp + apply(cases "minNull (vebt_delete (treeList ! high ma (Suc (va div 2))) (low ma (Suc (va div 2))))") + apply simp + apply(simp add: Let_def) + apply sep_auto + apply simp + apply sep_auto + apply (meson minminNull)+ + apply simp + apply(auto split: if_split) + apply (metis "7.prems" deg_deg_n div2_Suc_Suc highbound le_refl) + apply sep_auto + apply (metis "7.prems" deg_deg_n div2_Suc_Suc highbound le_refl) + apply (metis "7.prems" deg_deg_n div2_Suc_Suc highbound le_refl) + apply(simp add: Let_def) + apply(auto split: if_split) + apply(simp add: Let_def) + apply(auto split: if_split) + apply sep_auto+ + apply (meson minminNull) + apply sep_auto + apply (metis "7.prems" deg_deg_n div2_Suc_Suc highbound linorder_neqE_nat not_le_imp_less) + done + apply simp + apply(auto split: if_split) + apply sep_auto + apply (metis "7.prems" deg_deg_n div2_Suc_Suc dual_order.refl highbound) + apply (rewrite in "<\>_<_>" list_assn_conv_idx) + apply (rewrite in "<\>_<_>" listI_assn_extract[where i="high ma (Suc (va div 2))"]) + apply (metis "7.prems" atLeastLessThan_iff deg_deg_n div2_Suc_Suc highbound le0 le_refl length_list_update) + apply (metis "7.prems" deg_deg_n div2_Suc_Suc highbound le_refl length_list_update) + apply sep_auto + apply(sep_auto heap: vebt_maxti_h) + apply sep_auto + apply(simp add: Let_def) + apply(auto split: if_split) + apply(simp add: Let_def) + apply(auto split: if_split) + apply(simp add: Let_def) + subgoal + apply sep_auto + apply (metis minNullmin option.distinct)+ + done + apply sep_auto + apply(rule ent_trans) + apply(rule tcd[where treeList'= treeList]) + apply blast+ + apply(rule swappa) + apply(rule ent_refl) + apply sep_auto + apply (metis "7.prems" deg_deg_n div2_Suc_Suc highbound le_refl) + apply (metis "7.prems" deg_deg_n div2_Suc_Suc dual_order.refl highbound) + apply sep_auto + apply(simp add: Let_def) + apply(auto split: if_split) + apply(simp add: Let_def) + apply(auto split: if_split) + apply sep_auto + apply (metis minNullmin option.distinct(1)) + apply sep_auto+ + done +qed + +lemma TBOUND_vebt_deletei: + defines foo_def: "\ t x. foo t x \ if minNull (vebt_delete t x) then 1 else 20 * (1+height t)" + shows "TBOUND (vebt_deletei' t ti x) (foo t x)" +proof- + have fooNull:"minNull (vebt_delete t x) \ foo t x = 1" for t x using foo_def by simp + have fooElse: "foo t x \ 20* (1+ height t)" for t using foo_def by simp + have succ0foo: "Suc 0 \ foo t x" for t x unfolding foo_def by simp + have fooNull': "vebt_mint (vebt_delete t x) = None \ foo t x = 1" for t x + by (simp add: fooNull minminNull) + have fooNull'': "vebt_maxt (vebt_delete t x) = None \ foo t x = 1" for t x + by (metis fooNull fooNull' vebt_maxt.elims minNull.simps(4) vebt_mint.simps(1) option.simps(3)) + have minNotMaxDel: "x12a \ 2 \ c \ d \ + \ minNull (vebt_delete (Node (Some (c, d)) x12a x13 x14) y )" for x12a x13 x14 c d y + apply(cases "( (Node (Some (c, d)) x12a x13 x14), y )" rule: vebt_delete.cases; simp) + apply(auto simp add: Let_def) + done + have twentyheight:" i< length x13 \n * height (x13 !i) \ m + n * max (height x14) (Max (height ` set x13))" for i x13 x14 n m + by (meson height_i_max mult_le_mono2 trans_le_add2) + have summheight:"n * height x14 \ m + n * max (height x14) (Max (height ` set x13))" for x14 x13 m n + apply(simp add: max_def) + apply (meson mult_le_mono2 trans_le_add2) + done + show ?thesis + apply (induction arbitrary: t ti x rule: vebt_deletei'.fixp_induct) + apply (rule TBOUND_fi'_adm) + apply (rule TBOUND_empty) + apply TBOUND + apply(simp add: Let_def eq_commute[of "Suc 0" "_" ] succ0foo fooNull' fooNull'' + split!: VEBT.splits VEBTi.splits option.splits prod.splits ) + apply(all \(intro allI impI conjI)?\) + apply(all \(clarify; simp only: succ0foo; fail)?\) + apply(simp_all add: foo_def minNotMaxDel twentyheight summheight not_less) + done + qed + +lemma vebt_deletei_refines: "refines (vebt_deletei ti x) (vebt_deletei' t ti x)" + apply (induction arbitrary: t ti x rule: vebt_deletei'.fixp_induct) + subgoal + using refines_adm[where t = "\ arg. vebt_deletei (snd (fst arg)) (snd arg)"] + by simp + subgoal by simp + subgoal for f t ti x + apply(subst vebt_deletei.simps) + apply refines + done + done + +lemma htt_vebt_deletei: assumes "invar_vebt t n" + shows " vebt_deletei ti x <\ r. vebt_assn_raw (vebt_delete t x) r >T[20 + 20*(nat \lb n\)]" + apply (rule htt_refine[where c = "vebt_deletei' t ti x"]) + prefer 2 + apply(rule vebt_deletei_refines) + apply (rule httI_TBOUND) + apply(rule deleti'_rf_abstr) + apply(rule assms) + apply(rule TBOUND_mono) + apply(rule TBOUND_vebt_deletei) + apply (auto simp add: if_split) + apply(metis assms eq_imp_le heigt_uplog_rel int_eq_iff) + done + +end +end diff --git a/thys/Van_Emde_Boas_Trees/VEBT_Delete.thy b/thys/Van_Emde_Boas_Trees/VEBT_Delete.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/VEBT_Delete.thy @@ -0,0 +1,1791 @@ +(*by Ammer*) +theory VEBT_Delete imports VEBT_Pred VEBT_Succ +begin + +section \Deletion\ + +subsection \Function Definition\ + +context begin + interpretation VEBT_internal . + +fun vebt_delete :: "VEBT \ nat \ VEBT" where + "vebt_delete (Leaf a b) 0 = Leaf False b"| + "vebt_delete (Leaf a b) (Suc 0) = Leaf a False"| + "vebt_delete (Leaf a b) (Suc (Suc n)) = Leaf a b"| + "vebt_delete (Node None deg treeList summary) _ = (Node None deg treeList summary)"| + "vebt_delete (Node (Some (mi, ma)) 0 trLst smry) x = (Node (Some (mi, ma)) 0 trLst smry) "| + "vebt_delete (Node (Some (mi, ma)) (Suc 0) tr sm) x = (Node (Some (mi, ma)) (Suc 0) tr sm) "| + "vebt_delete (Node (Some (mi, ma)) deg treeList summary) x =( + if (x < mi \ x > ma) then (Node (Some (mi, ma)) deg treeList summary) + else if (x = mi \ x = ma) then (Node None deg treeList summary) + else let xn = (if x = mi + then the (vebt_mint summary) * 2^(deg div 2) + + the (vebt_mint (treeList ! the (vebt_mint summary))) + else x); + minn = (if x = mi then xn else mi); + l = low xn (deg div 2); + h = high xn (deg div 2) in + if h < length treeList + then( + let newnode = vebt_delete (treeList ! h) l; + newlist = treeList[h:= newnode]in + if minNull newnode + then( let sn = vebt_delete summary h in( + Node (Some (minn, if xn = ma then + (let maxs = vebt_maxt sn in ( + if maxs = None + then minn + else 2^(deg div 2) * the maxs + + the (vebt_maxt (newlist ! the maxs)))) + else ma)) deg newlist sn)) + else (Node (Some (minn, (if xn = ma + then h * 2^(deg div 2) + the( vebt_maxt (newlist ! h)) + else ma))) deg newlist summary )) + else (Node (Some (mi, ma)) deg treeList summary))" + +end + + +subsection \Auxiliary Lemmas\ + +context VEBT_internal begin + +context begin + +lemma delt_out_of_range: + assumes "x < mi \ x > ma" and "deg \ 2" + shows + "vebt_delete (Node (Some (mi, ma)) deg treeList summary) x =(Node (Some (mi, ma)) deg treeList summary)" + using vebt_delete.simps(7)[of mi ma "deg-2" treeList summary x] + by (metis add_2_eq_Suc assms(1) assms(2) le_add_diff_inverse) + +lemma del_single_cont: + assumes "x = mi \ x = ma" and "deg \ 2" + shows "vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = (Node None deg treeList summary)" + using vebt_delete.simps(7)[of mi ma "deg-2" treeList summary x] + by (metis add_2_eq_Suc assms(1) assms(2) le_add_diff_inverse nat_less_le) + +lemma del_in_range: + assumes "x \ mi \ x \ ma" and "mi \ ma" and "deg \ 2" + shows + " vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = ( let xn = (if x = mi + then the (vebt_mint summary) * 2^(deg div 2) + + the (vebt_mint (treeList ! the (vebt_mint summary))) + else x); + minn = (if x = mi then xn else mi); + l = low xn (deg div 2); + h = high xn (deg div 2) in + if h < length treeList + then( + let newnode = vebt_delete (treeList ! h) l; + newlist = treeList[h:= newnode] in + if minNull newnode + then( + let sn = vebt_delete summary h in + (Node (Some (minn, if xn = ma then (let maxs = vebt_maxt sn in + (if maxs = None + then minn + else 2^(deg div 2) * the maxs + + the (vebt_maxt (newlist ! the maxs)) + ) + ) + else ma)) + deg newlist sn) + )else + (Node (Some (minn, (if xn = ma then + h * 2^(deg div 2) + the( vebt_maxt (newlist ! h)) + else ma))) + deg newlist summary ) + )else + (Node (Some (mi, ma)) deg treeList summary))" + using vebt_delete.simps(7)[of mi ma "deg-2" treeList summary x] + by (smt (z3) add_2_eq_Suc assms(1) assms(2) assms(3) leD le_add_diff_inverse) + +lemma del_x_not_mia: + assumes "x > mi \ x \ ma" and "mi \ ma" and "deg \ 2" and "high x (deg div 2) = h" and + "low x (deg div 2) = l"and "high x (deg div 2) < length treeList" + shows + " vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = ( + let newnode = vebt_delete (treeList ! h) l; + newlist = treeList[h:= newnode] in + if minNull newnode + then( + let sn = vebt_delete summary h in + (Node (Some (mi, if x = ma then (let maxs = vebt_maxt sn in + (if maxs = None + then mi + else 2^(deg div 2) * the maxs + + the (vebt_maxt (newlist ! the maxs)) + ) + ) + else ma)) + deg newlist sn) + )else + (Node (Some (mi, (if x = ma then + h * 2^(deg div 2) + the( vebt_maxt (newlist ! h)) + else ma))) + deg newlist summary ) +)" + using del_in_range[of mi x ma deg treeList summary] unfolding Let_def + using assms(1) assms(2) assms(3) assms(4) assms(5) assms(6) nat_less_le by fastforce + +lemma del_x_not_mi: + assumes "x > mi \ x \ ma" and "mi \ ma" and "deg \ 2" and "high x (deg div 2) = h" and + "low x (deg div 2) = l"and " newnode = vebt_delete (treeList ! h) l" + and "newlist = treeList[h:= newnode]" and "high x (deg div 2) < length treeList" + shows + " vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = ( + if minNull newnode + then( + let sn = vebt_delete summary h in + (Node (Some (mi, if x = ma then (let maxs = vebt_maxt sn in + (if maxs = None + then mi + else 2^(deg div 2) * the maxs + + the (vebt_maxt (newlist ! the maxs)) + ) + ) + else ma)) + deg newlist sn) + )else + (Node (Some (mi, (if x = ma then + h * 2^(deg div 2) + the( vebt_maxt (newlist ! h)) + else ma))) + deg newlist summary ) +)" using del_x_not_mia[of mi x ma deg h l treeList summary] + by (smt (z3) assms(1) assms(2) assms(3) assms(4) assms(5) assms(6) assms(7) assms(8)) + +lemma del_x_not_mi_new_node_nil: + assumes "x > mi \ x \ ma" and "mi \ ma" and "deg \ 2" and "high x (deg div 2) = h" and + "low x (deg div 2) = l"and " newnode = vebt_delete (treeList ! h) l" and "minNull newnode " and + "sn = vebt_delete summary h" and "newlist =treeList[h:= newnode]" and "high x (deg div 2) < length treeList" + shows + " vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = (Node (Some (mi, if x = ma then (let maxs = vebt_maxt sn in + (if maxs = None + then mi + else 2^(deg div 2) * the maxs + + the (vebt_maxt (newlist ! the maxs)) + ) + ) + else ma)) deg newlist sn)" + using del_x_not_mi[of mi x ma deg h l newnode treeList] + by (metis assms(1) assms(10) assms(2) assms(3) assms(4) assms(5) assms(6) assms(7) assms(8) assms(9)) + +lemma del_x_not_mi_newnode_not_nil: + assumes "x > mi \ x \ ma" and "mi \ ma" and "deg \ 2" and "high x (deg div 2) = h" and + "low x (deg div 2) = l"and " newnode = vebt_delete (treeList ! h) l" and "\ minNull newnode " and + "newlist = treeList[h:= newnode]" and"high x (deg div 2) < length treeList" + shows + " vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = + (Node (Some (mi, (if x = ma then + h * 2^(deg div 2) + the( vebt_maxt (newlist ! h)) + else ma))) + deg newlist summary )" + using del_x_not_mi[of mi x ma deg h l newnode treeList newlist summary] + using assms(1) assms(2) assms(3) assms(4) assms(5) assms(6) assms(7) assms(8) assms(9) by auto + +lemma del_x_mia: assumes "x = mi \ x < ma" and "mi \ ma" and "deg \ 2" + shows "vebt_delete (Node (Some (mi, ma)) deg treeList summary) x =( + let xn = the (vebt_mint summary) * 2^(deg div 2) + + the (vebt_mint (treeList ! the (vebt_mint summary))); + minn = xn; + l = low xn (deg div 2); + h = high xn (deg div 2) in + if h < length treeList + then( + let newnode = vebt_delete (treeList ! h) l; + newlist = treeList[h:= newnode]in + if minNull newnode + then( + let sn = vebt_delete summary h in + (Node (Some (minn, if xn = ma then (let maxs = vebt_maxt sn in + (if maxs = None + then minn + else 2^(deg div 2) * the maxs + + the (vebt_maxt (newlist ! the maxs)) + ) + ) + else ma)) + deg newlist sn) + )else + (Node (Some (minn, (if xn = ma then + h * 2^(deg div 2) + the( vebt_maxt (newlist ! h)) + else ma))) + deg newlist summary ) + )else + (Node (Some (mi, ma)) deg treeList summary) + )" + using del_in_range[of mi x ma deg treeList summary] + using assms(1) assms(3) nat_less_le order_refl by fastforce + +lemma del_x_mi: + assumes "x = mi \ x < ma" and "mi \ ma" and "deg \ 2" and "high xn (deg div 2) = h" and + "xn = the (vebt_mint summary) * 2^(deg div 2) + the (vebt_mint (treeList ! the (vebt_mint summary))) " + "low xn (deg div 2) = l"and "high xn (deg div 2) < length treeList" + shows + "vebt_delete (Node (Some (mi, ma)) deg treeList summary) x =( + let newnode = vebt_delete (treeList ! h) l; + newlist = treeList[h:= newnode]in + if minNull newnode + then( + let sn = vebt_delete summary h in + (Node (Some (xn, if xn = ma then (let maxs = vebt_maxt sn in + (if maxs = None + then xn + else 2^(deg div 2) * the maxs + + the (vebt_maxt (newlist ! the maxs)) + ) + ) + else ma)) + deg newlist sn) + )else + (Node (Some (xn, (if xn = ma then + h * 2^(deg div 2) + the( vebt_maxt (newlist ! h)) + else ma))) + deg newlist summary )) + " + using del_x_mia[of x mi ma deg treeList summary] + by (smt (z3) assms(1) assms(2) assms(3) assms(4) assms(5) assms(6) assms(7)) + +lemma del_x_mi_lets_in: + assumes "x = mi \ x < ma" and "mi \ ma" and "deg \ 2" and "high xn (deg div 2) = h" and + "xn = the (vebt_mint summary) * 2^(deg div 2) + the (vebt_mint (treeList ! the (vebt_mint summary))) " + "low xn (deg div 2) = l"and "high xn (deg div 2) < length treeList" and + " newnode = vebt_delete (treeList ! h) l" and " newlist = treeList[h:= newnode]" + shows "vebt_delete (Node (Some (mi, ma)) deg treeList summary) x =( if minNull newnode + then( + let sn = vebt_delete summary h in + (Node (Some (xn, if xn = ma then (let maxs = vebt_maxt sn in + (if maxs = None + then xn + else 2^(deg div 2) * the maxs + + the (vebt_maxt (newlist ! the maxs)) + ) + ) + else ma)) + deg newlist sn) + )else + (Node (Some (xn, (if xn = ma then + h * 2^(deg div 2) + the( vebt_maxt (newlist ! h)) + else ma))) + deg newlist summary ))" + using del_x_mi[of x mi ma deg xn h summary treeList l] + by (smt (z3) assms(1) assms(2) assms(3) assms(4) assms(5) assms(6) assms(7) assms(8) assms(9)) + +lemma del_x_mi_lets_in_minNull: + assumes "x = mi \ x < ma" and "mi \ ma" and "deg \ 2" and "high xn (deg div 2) = h" and + "xn = the (vebt_mint summary) * 2^(deg div 2) + the (vebt_mint (treeList ! the (vebt_mint summary))) " + "low xn (deg div 2) = l"and "high xn (deg div 2) < length treeList" and + "newnode = vebt_delete (treeList ! h) l" and " newlist =treeList[h:= newnode]" and + "minNull newnode " and " sn = vebt_delete summary h" + shows + "vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = + (Node (Some (xn, if xn = ma then (let maxs = vebt_maxt sn in + (if maxs = None + then xn + else 2^(deg div 2) * the maxs + + the (vebt_maxt (newlist ! the maxs)) + ) + ) + else ma)) deg newlist sn)" + using del_x_mi_lets_in[of x mi ma deg xn h summary treeList l newnode newlist] + by (metis assms(1) assms(10) assms(11) assms(2) assms(3) assms(4) assms(5) assms(6) assms(7) assms(8) assms(9)) + +lemma del_x_mi_lets_in_not_minNull: + assumes "x = mi \ x < ma" and "mi \ ma" and "deg \ 2" and "high xn (deg div 2) = h" and + "xn = the (vebt_mint summary) * 2^(deg div 2) + the (vebt_mint (treeList ! the (vebt_mint summary))) " + "low xn (deg div 2) = l"and "high xn (deg div 2) < length treeList" and + " newnode = vebt_delete (treeList ! h) l" and " newlist = treeList[h:= newnode]" and + "\minNull newnode " + shows + "vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = + (Node (Some (xn, (if xn = ma then + h * 2^(deg div 2) + the( vebt_maxt (newlist ! h)) + else ma))) + deg newlist summary )" + using del_x_mi_lets_in[of x mi ma deg xn h summary treeList l newnode newlist] + by (meson assms(1) assms(10) assms(2) assms(3) assms(4) assms(5) assms(6) assms(7) assms(8) assms(9)) + +theorem dele_bmo_cont_corr:"invar_vebt t n \ (both_member_options (vebt_delete t x) y \ x \ y \ both_member_options t y)" +proof(induction t n arbitrary: x y rule: invar_vebt.induct) + case (1 a b) + have "(both_member_options (vebt_delete (Leaf a b) x) y) \ (x \ y \ both_member_options (Leaf a b) y)" + by (metis One_nat_def both_member_options_def vebt_buildup.cases vebt_delete.simps(1) vebt_delete.simps(2) vebt_delete.simps(3) membermima.simps(1) naive_member.simps(1)) + moreover have "(x \ y \ both_member_options (Leaf a b) y) \(both_member_options (vebt_delete (Leaf a b) x) y)" + by (metis One_nat_def both_member_options_def vebt_buildup.cases vebt_delete.simps(1) vebt_delete.simps(2) vebt_delete.simps(3) membermima.simps(1) naive_member.simps(1)) + ultimately show ?case by blast +next + case (2 treeList n summary m deg) + hence "deg \ 2" + by (metis Suc_leI deg_not_0 dual_order.strict_trans2 less_add_same_cancel1 numerals(2)) + hence " (vebt_delete (Node None deg treeList summary) x) = (Node None deg treeList summary)" by simp + moreover have "\vebt_member (Node None deg treeList summary) y" by simp + moreover hence "\both_member_options (Node None deg treeList summary) y" + using invar_vebt.intros(2)[of treeList n summary m deg] 2 + by (metis valid_member_both_member_options) + moreover hence "\both_member_options (vebt_delete (Node None deg treeList summary) x) y" by simp + ultimately show ?case + by force +next + case (3 treeList n summary m deg) + hence "deg \ 2" + by (metis One_nat_def add_mono le_add1 numeral_2_eq_2 plus_1_eq_Suc set_n_deg_not_0) + hence " (vebt_delete (Node None deg treeList summary) x) = (Node None deg treeList summary)" by simp + moreover have "\vebt_member (Node None deg treeList summary) y" by simp + moreover hence "\both_member_options (Node None deg treeList summary) y" + using invar_vebt.intros(3)[of treeList n summary m deg] 3 + by (metis valid_member_both_member_options) + moreover hence "\both_member_options (vebt_delete (Node None deg treeList summary) x) y" by simp + ultimately show ?case + by force +next + case (4 treeList n summary m deg mi ma) + hence tvalid: "invar_vebt (Node (Some (mi, ma)) deg treeList summary) deg" + using invar_vebt.intros(4)[of treeList n summary m deg mi ma] by simp + hence "mi \ ma" and "deg div 2 = n" and "ma \ 2^deg" using 4 + by (auto simp add: "4.hyps"(3) "4.hyps"(4)) + hence dp:"deg \ 2" + using "4.hyps"(1) "4.hyps"(3) deg_not_0 div_greater_zero_iff by blast + then show ?case proof(cases "x x > ma") + case True + hence "vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = (Node (Some (mi, ma)) deg treeList summary)" + using delt_out_of_range[of x mi ma deg treeList summary] \2 \ deg\ by blast + then show ?thesis + by (metis "4.hyps"(7) True tvalid leD member_inv not_less_iff_gr_or_eq valid_member_both_member_options) + next + case False + hence "mi \ x \ x \ ma" by simp + hence "x < 2^deg" + using "4.hyps"(8) order.strict_trans1 by blast + then show ?thesis + proof(cases "x = mi \ x = ma") + case True + hence "vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = (Node None deg treeList summary)" + using del_single_cont[of x mi ma deg treeList summary] \2 \ deg\ by blast + moreover hence "invar_vebt (Node None deg treeList summary) deg" + using "4"(4) "4.IH"(1) "4.hyps"(1) "4.hyps"(3) "4.hyps"(4) True mi_eq_ma_no_ch tvalid invar_vebt.intros(2) by force + moreover hence "\ vebt_member (Node None deg treeList summary) y" by simp + moreover hence "\both_member_options (Node None deg treeList summary) y" + using calculation(2) valid_member_both_member_options by blast + then show ?thesis + by (metis True calculation(1) member_inv not_less_iff_gr_or_eq tvalid valid_member_both_member_options) + next + case False + hence mimapr:"mi < ma" + by (metis "4.hyps"(7) \mi \ x \ x \ ma\ le_antisym nat_less_le) + then show ?thesis + proof(cases "x \ mi") + case True + hence xmi:"x \ mi" by simp + let ?h ="high x n" + let ?l = "low x n" + have "?h < length treeList" + using "4"(10) "4"(4) "4.hyps"(1) "4.hyps"(3) "4.hyps"(4) \mi \ x \ x \ ma\ deg_not_0 exp_split_high_low(1) by auto + let ?newnode = "vebt_delete (treeList ! ?h) ?l" + let ?newlist = "treeList[?h:= ?newnode]" + have "length treeList = length ?newlist" by simp + hence hprolist: "?newlist ! ?h = ?newnode" + by (meson \high x n < length treeList\ nth_list_update_eq) + have nothprolist: "i \ ?h \ i < 2^m \ ?newlist ! i = treeList ! i" for i by auto + then show ?thesis + proof(cases "minNull ?newnode") + case True + let ?sn = "vebt_delete summary ?h" + let ?newma= "(if x = ma then (let maxs = vebt_maxt ?sn in (if maxs = None + then mi + else 2^(deg div 2) * the maxs + + the (vebt_maxt (?newlist ! the maxs)) + ) + ) + else ma)" + let ?delsimp =" (Node (Some (mi, ?newma)) deg ?newlist ?sn)" + have "vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = ?delsimp" + using del_x_not_mi_new_node_nil[of mi x ma deg ?h ?l ?newnode treeList ?sn summary ?newlist] + by (metis True \2 \ deg\ \deg div 2 = n\ \high x n < length treeList\ \mi < ma\ \mi \ x \ x \ ma\ \x \ mi\ less_not_refl3 order.not_eq_order_implies_strict) + moreover have "both_member_options (?delsimp) y \ (x \ y \ both_member_options (Node (Some (mi, ma)) deg treeList summary) y)" + proof- + assume "both_member_options (?delsimp) y" + hence "y = mi \ y = ?newma \ + (both_member_options (?newlist ! (high y (deg div 2))) (low y (deg div 2)) \ (high y (deg div 2)) < length ?newlist)" + using both_member_options_from_complete_tree_to_child[of deg mi ?newma ?newlist ?sn y] dp + by (smt (z3) Suc_1 Suc_le_D both_member_options_def membermima.simps(4) naive_member.simps(3)) + moreover have "y = mi \ ?thesis" + by (meson \x \ mi\ both_member_options_equiv_member vebt_mint.simps(3) mint_member tvalid) + moreover have "y = ?newma \ ?thesis" + proof- + assume "y = ?newma" + show ?thesis + proof(cases "x = ma") + case True + let ?maxs = "vebt_maxt ?sn" + have "?newma = (if ?maxs = None then mi + else 2 ^ (deg div 2) * the ?maxs + the (vebt_maxt + ((treeList[(high x n):= vebt_delete (treeList ! (high x n)) (low x n)]) ! + the ?maxs)))" using True by force + then show ?thesis + proof(cases "?maxs = None ") + case True + then show ?thesis + using \(if x = ma then let maxs = vebt_maxt (vebt_delete summary (high x n)) in if maxs = None then mi else 2 ^ (deg div 2) * the maxs + the (vebt_maxt (treeList [high x n := vebt_delete (treeList ! high x n) (low x n)] ! the maxs)) else ma) = (if vebt_maxt (vebt_delete summary (high x n)) = None then mi else 2 ^ (deg div 2) * the (vebt_maxt (vebt_delete summary (high x n))) + the (vebt_maxt (treeList[high x n := vebt_delete (treeList ! high x n) (low x n)] ! the (vebt_maxt (vebt_delete summary (high x n))))))\ \y = (if x = ma then let maxs = vebt_maxt (vebt_delete summary (high x n)) in if maxs = None then mi else 2 ^ (deg div 2) * the maxs + the (vebt_maxt (treeList [high x n := vebt_delete (treeList ! high x n) (low x n)] ! the maxs)) else ma)\ calculation(2) by presburger + next + case False + then obtain maxs where "Some maxs = ?maxs" by force + hence "both_member_options ?sn maxs" + by (simp add: maxbmo) + hence "both_member_options summary maxs \ maxs \ ?h" + using "4.IH"(2) by blast + hence "?newlist ! the ?maxs = treeList ! maxs" + by (metis "4.hyps"(1) \Some maxs = vebt_maxt (vebt_delete summary (high x n))\ option.sel member_bound nothprolist valid_member_both_member_options) + have "maxs < 2^m" + using "4.hyps"(1) \both_member_options summary maxs \ maxs \ high x n\ member_bound valid_member_both_member_options by blast + hence "the (vebt_maxt (?newlist ! the ?maxs)) = the (vebt_maxt (treeList ! maxs))" + by (simp add: \treeList[high x n := vebt_delete (treeList ! high x n) (low x n)] ! the (vebt_maxt (vebt_delete summary (high x n))) = treeList ! maxs\) + have "\ z. both_member_options(treeList ! maxs) z" + by (simp add: "4.hyps"(5) \both_member_options summary maxs \ maxs \ high x n\ \maxs < 2 ^ m\) + moreover have "invar_vebt (treeList ! maxs) n" using 4 + by (metis \maxs < 2 ^ m\ inthall member_def) + ultimately obtain maxi where "Some maxi = (vebt_maxt (treeList ! maxs))" + by (metis empty_Collect_eq maxt_corr_help_empty not_None_eq set_vebt'_def valid_member_both_member_options) + hence "maxi < 2^n" + by (metis \invar_vebt (treeList ! maxs) n\ maxt_member member_bound) + hence "both_member_options (treeList ! maxs) maxi" + using \Some maxi = vebt_maxt (treeList ! maxs)\ maxbmo by presburger + hence "2 ^ (deg div 2) * the ?maxs + the + (vebt_maxt (?newlist ! the ?maxs)) = 2^n * maxs + maxi " + by (metis \Some maxi = vebt_maxt (treeList ! maxs)\ \Some maxs = vebt_maxt (vebt_delete summary (high x n))\ \deg div 2 = n\ \the (vebt_maxt (treeList[high x n := vebt_delete (treeList ! high x n) (low x n)] ! the (vebt_maxt (vebt_delete summary (high x n))))) = the (vebt_maxt (treeList ! maxs))\ option.sel) + hence "y = 2^n * maxs + maxi" + using False True \y = (if x = ma then let maxs = vebt_maxt (vebt_delete summary (high x n)) in if maxs = None then mi else 2 ^ (deg div 2) * the maxs + the (vebt_maxt (treeList [high x n := vebt_delete (treeList ! high x n) (low x n)] ! the maxs)) else ma)\ by fastforce + hence "both_member_options (Node (Some (mi, ma)) deg treeList summary) y" + by (metis "4.hyps"(2) Suc_1 \both_member_options (treeList ! maxs) maxi\ \deg div 2 = n\ \maxi < 2 ^ n\ \maxs < 2 ^ m\ add_leD1 both_member_options_from_chilf_to_complete_tree dp high_inv low_inv mult.commute plus_1_eq_Suc) + moreover hence "y \ x" + by (metis \both_member_options summary maxs \ maxs \ high x n\ \maxi < 2 ^ n\ \y = 2 ^ n * maxs + maxi\ high_inv mult.commute) + ultimately show ?thesis by force + qed + next + case False + hence "?newma = ma" by simp + moreover hence "y \ x" + using False \y = ?newma\ by presburger + then show ?thesis + by (metis False \y =?newma\ both_member_options_equiv_member vebt_maxt.simps(3) maxt_member tvalid) + qed + qed + moreover have "(both_member_options (?newlist ! (high y (deg div 2))) (low y (deg div 2)) \ (high y (deg div 2)) < length ?newlist) \ ?thesis" + proof- + assume assm:"both_member_options (?newlist ! (high y (deg div 2))) (low y (deg div 2)) \ (high y (deg div 2)) < length ?newlist" + show ?thesis + proof(cases "(high y (deg div 2)) = ?h") + case True + hence "both_member_options ?newnode (low y (deg div 2)) " using hprolist by (metis assm) + moreover hence "invar_vebt (treeList ! (high y (deg div 2))) n" + by (metis "4.IH"(1) True \high x n < length treeList\ inthall member_def) + ultimately have "both_member_options (treeList ! ?h) (low y (deg div 2)) \ (low y (deg div 2)) \ (low x (deg div 2))" + by (metis "4.IH"(1) \deg div 2 = n\ \high x n < length treeList\ inthall member_def) + then show ?thesis + by (metis Suc_1 True \high x n < length treeList\ add_leD1 both_member_options_from_chilf_to_complete_tree dp plus_1_eq_Suc) + next + case False + hence "x \ y" + using \deg div 2 = n\ by blast + moreover hence "(?newlist ! (high y (deg div 2))) = treeList ! (high y (deg div 2))" using nothprolist + using "4.hyps"(2) False \length treeList = length ?newlist\ assm by presburger + moreover hence "both_member_options (treeList ! (high y (deg div 2)) ) (low y (deg div 2))" + using assm by presburger + moreover hence "both_member_options (Node (Some (mi, ma)) deg treeList summary) y" + by (metis One_nat_def Suc_leD \length treeList = length ?newlist\ assm both_member_options_from_chilf_to_complete_tree dp numeral_2_eq_2) + ultimately show ?thesis by blast + qed + qed + ultimately show ?thesis by fastforce + qed + moreover have " (x \ y \ both_member_options (Node (Some (mi, ma)) deg treeList summary) y) \ both_member_options (?delsimp) y" + proof- + assume "(x \ y \ both_member_options (Node (Some (mi, ma)) deg treeList summary) y)" + hence aa:"x \ y" and bb:"y = mi \ y = ma \ (both_member_options (treeList ! (high y n)) (low y n) \ high y n < length treeList)" + apply auto[1] by (metis Suc_1 \deg div 2 = n\ \x \ y \ both_member_options (Node (Some (mi, ma)) deg treeList summary) y\ add_leD1 both_member_options_from_complete_tree_to_child member_inv plus_1_eq_Suc tvalid valid_member_both_member_options) + show "both_member_options (?delsimp) y" + proof- + have "y = mi \both_member_options (?delsimp) y" + by (metis Suc_1 Suc_le_D both_member_options_def dp membermima.simps(4)) + moreover have "y = ma \ both_member_options (?delsimp) y" + using aa maxbmo vebt_maxt.simps(3) by presburger + moreover have "both_member_options (treeList ! (high y n)) (low y n) \both_member_options (?delsimp) y " + proof- + assume assmy: "both_member_options (treeList ! (high y n)) (low y n)" + then show "both_member_options (?delsimp) y " + proof(cases "high y n = ?h") + case True + moreover hence "?newlist ! (high y n) = ?newnode" + using hprolist by auto + hence 0:"invar_vebt (treeList !(high y n)) n" using 4 + by (metis True \high x n < length treeList\ inthall member_def) + moreover have 1:"low y n \ low x n" + by (metis True aa bit_split_inv) + moreover have 11:" (treeList !(high y n)) \ set treeList" + by (metis True \high x n < length treeList\ inthall member_def) + ultimately have " (\ xa. both_member_options ?newnode xa = + ((low x n) \ xa \ both_member_options (treeList ! ?h) xa))" + by (simp add: "4.IH"(1)) + hence "((low x n) \ xa \ both_member_options (treeList ! ?h) xa) \ both_member_options ?newnode xa" for xa by blast + moreover have "((low x n) \ (low y n) \ both_member_options (treeList ! ?h) (low y n))" using 1 + using True assmy by presburger + ultimately have "both_member_options ?newnode (low y n)" by blast + then show ?thesis + by (metis One_nat_def Suc_leD True \deg div 2 = n\ \high x n < length treeList\ \length treeList = length ?newlist\ both_member_options_from_chilf_to_complete_tree dp hprolist numerals(2)) + next + case False + hence "?newlist ! (high y n) = treeList ! (high y n)" by auto + hence "both_member_options (?newlist !(high y n)) (low y n)" + using assmy by presburger + then show ?thesis + by (smt (z3) Suc_1 Suc_le_D \deg div 2 = n\ \length treeList = length ?newlist\ aa add_leD1 bb both_member_options_def both_member_options_from_chilf_to_complete_tree dp membermima.simps(4) plus_1_eq_Suc) + qed + qed + ultimately show ?thesis using bb by fastforce + qed + qed + ultimately show ?thesis by metis + next + case False + hence notemp:"\ z. both_member_options ?newnode z" + using not_min_Null_member by auto + let ?newma = "(if x = ma then + ?h * 2^(deg div 2) + the( vebt_maxt (?newlist ! ?h)) + else ma)" + let ?delsimp =" (Node (Some (mi, ?newma)) deg ?newlist summary)" + have "vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = ?delsimp" + using del_x_not_mi_newnode_not_nil[of mi x ma deg ?h ?l ?newnode treeList ?newlist summary] False xmi mimapr + using \deg div 2 = n\ \high x n < length treeList\ \mi \ x \ x \ ma\ dp nat_less_le plus_1_eq_Suc by fastforce + moreover have "both_member_options ?delsimp y + \ x \ y \ both_member_options (Node (Some (mi, ma)) deg treeList summary) y" + proof- + assume ssms: "both_member_options ?delsimp y " + hence aaaa: "y = mi \ y = ?newma \ (both_member_options (?newlist ! (high y n)) (low y n) \ high y n < length ?newlist)" + by (smt (z3) Suc_1 Suc_le_D \deg div 2 = n\ both_member_options_def dp membermima.simps(4) naive_member.simps(3)) + show " x \ y \ both_member_options (Node (Some (mi, ma)) deg treeList summary) y" + proof- + have "y = mi \?thesis" + by (metis Suc_1 Suc_le_D both_member_options_def dp membermima.simps(4) xmi) + moreover have " y = ?newma \ ?thesis" + proof- + assume "y = ?newma" + show ?thesis + proof(cases "x = ma") + case True + hence "?newma =?h * 2 ^ (deg div 2) +the(vebt_maxt(?newlist ! ?h))" + by metis + have "?newlist ! ?h = ?newnode" using hprolist by blast + obtain maxi where maxidef:"Some maxi = vebt_maxt(?newlist ! ?h)" + by (metis False hprolist vebt_maxt.elims minNull.simps(1) minNull.simps(4)) + have aa:"invar_vebt (treeList ! ?h) n" + by (metis "4.IH"(1) \high x n < length treeList\ inthall member_def) + moreover hence ab:"maxi \ ?l \ both_member_options ?newnode maxi" + by (metis "4.IH"(1) \high x n < length treeList\ hprolist inthall maxbmo maxidef member_def) + ultimately have ac:"maxi \ ?l \ both_member_options (treeList ! ?h) maxi" + by (metis "4.IH"(1) \high x n < length treeList\ inthall member_def) + hence ad:"maxi < 2^n" + using \invar_vebt (treeList ! high x n) n\ member_bound valid_member_both_member_options by blast + then show ?thesis + by (metis Suc_1 \(if x = ma then high x n * 2 ^ (deg div 2) + the (vebt_maxt (treeList[high x n := vebt_delete (treeList ! high x n) (low x n)] ! high x n)) else ma) = high x n * 2 ^ (deg div 2) + the (vebt_maxt (treeList[high x n := vebt_delete (treeList ! high x n) (low x n)] ! high x n))\ \deg div 2 = n\ \high x n < length treeList\ \y = (if x = ma then high x n * 2 ^ (deg div 2) + the (vebt_maxt (treeList[high x n := vebt_delete (treeList ! high x n) (low x n)] ! high x n)) else ma)\ ac add_leD1 both_member_options_from_chilf_to_complete_tree dp option.sel high_inv low_inv maxidef plus_1_eq_Suc) + next + case False + then show ?thesis + by (simp add: \y = ?newma\ maxbmo) + qed + qed + moreover have "both_member_options (?newlist ! (high y n)) (low y n) \ ?thesis" + proof- + assume assmy:"both_member_options (?newlist ! (high y n)) (low y n)" + then show ?thesis + proof(cases "high y n = ?h") + case True + hence "?newlist ! (high y n) = ?newnode" + using hprolist by presburger + have "invar_vebt (treeList ! ?h) n" + by (metis "4.IH"(1) \high x n < length treeList\ inthall member_def) + hence "low y n \ ?l \ both_member_options (treeList ! ?h ) (low y n)" + by (metis "4.IH"(1) True \high x n < length treeList\ assmy hprolist inthall member_def) + then show ?thesis + by (metis Suc_1 True \deg div 2 = n\ \high x n < length treeList\ add_leD1 both_member_options_from_chilf_to_complete_tree dp plus_1_eq_Suc) + next + case False + hence "?newlist ! (high y n) = treeList !(high y n)" by auto + then show ?thesis + by (metis False Suc_1 \deg div 2 = n\ \length treeList = length ?newlist\ aaaa add_leD1 both_member_options_from_chilf_to_complete_tree calculation(1) calculation(2) dp plus_1_eq_Suc) + qed + qed + ultimately show ?thesis + using aaaa by fastforce + qed + qed + + moreover have "(x \ y \ both_member_options (Node (Some (mi, ma)) deg treeList summary) y)\ + both_member_options ?delsimp y" + proof- + assume assm: "x \ y \ both_member_options (Node (Some (mi, ma)) deg treeList summary) y" + hence abcv:"y = mi \ y = ma \ ( high y n < length treeList \ both_member_options (treeList ! (high y n)) (low y n))" + by (metis Suc_1 \deg div 2 = n\ add_leD1 both_member_options_from_complete_tree_to_child member_inv plus_1_eq_Suc tvalid valid_member_both_member_options) + thus " both_member_options ?delsimp y" + proof- + have "y = mi \ ?thesis" + by (metis Suc_1 Suc_le_D both_member_options_def dp membermima.simps(4)) + moreover have " y = ma \ ?thesis" + using assm maxbmo vebt_maxt.simps(3) by presburger + moreover have " both_member_options (treeList ! (high y n)) (low y n) \ ?thesis" + proof- + assume myass: "both_member_options (treeList ! (high y n)) (low y n) " + thus ?thesis + proof(cases "high y n = ?h") + case True + hence "low y n \ ?l" + by (metis assm bit_split_inv) + hence pp:"?newlist ! ?h = ?newnode" + using hprolist by blast + hence "invar_vebt (treeList ! ?h) n" + by (metis "4.IH"(1) \high x n < length treeList\ inthall member_def) + hence "both_member_options ?newnode (low y n)" + by (metis "4.IH"(1) True \high x n < length treeList\ \low y n \ low x n\ in_set_member inthall myass) + then show ?thesis + by (metis One_nat_def Suc_leD True \deg div 2 = n\ \high x n < length treeList\ \length treeList = length ?newlist\ both_member_options_from_chilf_to_complete_tree dp numerals(2) pp) + next + case False + hence pp:"?newlist ! (high y n) = treeList ! (high y n)" using nothprolist by auto + then show ?thesis + by (metis Suc_1 \deg div 2 = n\ \length treeList = length (treeList[high x n := vebt_delete (treeList ! high x n) (low x n)])\ add_leD1 assm both_member_options_from_chilf_to_complete_tree calculation(1) calculation(2) member_inv myass plus_1_eq_Suc tvalid valid_member_both_member_options) + qed + qed + then show ?thesis + by (metis Suc_1 Suc_leD \deg div 2 = n\ assm both_member_options_from_complete_tree_to_child calculation(1) calculation(2) dp) + qed + qed + ultimately show ?thesis by metis + qed + next + case False + hence "x = mi" by simp + have "both_member_options summary (high ma n)" + by (metis "4"(10) "4"(11) "4"(7) "4.hyps"(4) Euclidean_Division.div_eq_0_iff Suc_leI Suc_le_D div_exp_eq dual_order.irrefl high_def mimapr nat.simps(3)) + hence "vebt_member summary (high ma n)" + using "4.hyps"(1) valid_member_both_member_options by blast + obtain summin where "Some summin = vebt_mint summary" + by (metis "4.hyps"(1) \vebt_member summary (high ma n)\ empty_Collect_eq mint_corr_help_empty not_None_eq set_vebt'_def) + hence "\ z . both_member_options (treeList ! summin) z" + by (metis "4.hyps"(1) "4.hyps"(5) both_member_options_equiv_member member_bound mint_member) + moreover have "invar_vebt (treeList ! summin) n" + by (metis "4"(4) "4.IH"(1) "4.hyps"(1) \Some summin = vebt_mint summary\ member_bound mint_member nth_mem) + ultimately obtain lx where "Some lx = vebt_mint (treeList ! summin)" + by (metis empty_Collect_eq mint_corr_help_empty not_None_eq set_vebt'_def valid_member_both_member_options) + let ?xn = "summin*2^n + lx" + have "?xn = (if x = mi + then the (vebt_mint summary) * 2^(deg div 2) + + the (vebt_mint (treeList ! the (vebt_mint summary))) + else x)" + by (metis False \Some lx = vebt_mint (treeList ! summin)\ \Some summin = vebt_mint summary\ \deg div 2 = n\ option.sel) + have "vebt_member (treeList ! summin) lx" + using \Some lx = vebt_mint (treeList ! summin)\ \invar_vebt (treeList ! summin) n\ mint_member by auto + moreover have "summin < 2^m" + by (metis "4.hyps"(1) \Some summin = vebt_mint summary\ member_bound mint_member) + ultimately have xnin: "both_member_options (Node (Some (mi, ma)) deg treeList summary) ?xn" + by (metis "4.hyps"(2) Suc_1 \deg div 2 = n\ \invar_vebt (treeList ! summin) n\ add_leD1 both_member_options_equiv_member both_member_options_from_chilf_to_complete_tree dp high_inv low_inv member_bound plus_1_eq_Suc) + let ?h ="high ?xn n" + let ?l = "low ?xn n" + have "?xn < 2^deg" + by (smt (verit, ccfv_SIG) "4.hyps"(1) "4.hyps"(4) Euclidean_Division.div_eq_0_iff \Some lx = vebt_mint (treeList ! summin)\ \Some summin = vebt_mint summary\ \invar_vebt (treeList ! summin) n\ div_exp_eq high_def high_inv le_0_eq member_bound mint_member not_numeral_le_zero power_not_zero) + hence "?h < length treeList" + using "4.hyps"(2) "4.hyps"(3) "4.hyps"(4) \invar_vebt (treeList ! summin) n\ deg_not_0 exp_split_high_low(1) by metis + let ?newnode = "vebt_delete (treeList ! ?h) ?l" + let ?newlist = "treeList[?h:= ?newnode]" + have "length treeList = length ?newlist" by simp + hence hprolist: "?newlist ! ?h = ?newnode" + by (meson \high (summin * 2 ^ n + lx) n < length treeList\ nth_list_update) + have nothprolist: "i \ ?h \ i < 2^m \ ?newlist ! i = treeList ! i" for i by simp + have firstsimp: "vebt_delete (Node (Some (mi, ma)) deg treeList summary) x =( + let newnode = vebt_delete (treeList ! ?h) ?l; + newlist = (take ?h treeList @ [ newnode]@drop (?h+1) treeList)in + if minNull newnode + then( + let sn = vebt_delete summary ?h in + (Node (Some (?xn, if ?xn = ma then (let maxs = vebt_maxt sn in + (if maxs = None + then ?xn + else 2^(deg div 2) * the maxs + + the (vebt_maxt (newlist ! the maxs)) + ) + ) + else ma)) + deg newlist sn) + )else + (Node (Some (?xn, (if ?xn = ma then + ?h * 2^(deg div 2) + the( vebt_maxt (newlist ! ?h)) + else ma))) + deg newlist summary ))" + using del_x_mi[of x mi ma deg ?xn ?h summary treeList ?l] + by (smt (z3) \deg div 2 = n\ \high (summin * 2 ^ n + lx) n < length treeList\ \summin * 2 ^ n + lx = (if x = mi then the (vebt_mint summary) * 2 ^ (deg div 2) + the (vebt_mint (treeList ! the (vebt_mint summary))) else x)\ \x = mi\ add.commute append_Cons append_Nil dp mimapr nat_less_le plus_1_eq_Suc upd_conv_take_nth_drop) + have minxnrel: "?xn \ mi" + by (metis "4.hyps"(2) "4.hyps"(9) \high (summin * 2 ^ n + lx) n < length treeList\ \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ both_member_options_equiv_member high_inv less_not_refl low_inv member_bound mimapr) + then show ?thesis + proof(cases "minNull ?newnode") + case True + let ?sn = "vebt_delete summary ?h" + let ?newma= "(if ?xn= ma then (let maxs = vebt_maxt ?sn in + (if maxs = None + then ?xn + else 2^(deg div 2) * the maxs + + the (vebt_maxt (?newlist ! the maxs)) + ) + ) + else ma)" + let ?delsimp =" (Node (Some (?xn, ?newma)) deg ?newlist ?sn)" + have "vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = ?delsimp" + using del_x_mi_lets_in_minNull[of x mi ma deg ?xn ?h summary treeList ?l ?newnode ?newlist ?sn] False True \deg div 2 = n\ \?h < length treeList\ \summin * 2 ^ n + lx = (if x = mi then the (vebt_mint summary) * 2 ^ (deg div 2) + the (vebt_mint (treeList ! the (vebt_mint summary))) else x)\ dp less_not_refl3 mimapr by fastforce + moreover have "both_member_options (?delsimp) y \ (x \ y \ both_member_options (Node (Some (mi, ma)) deg treeList summary) y)" + proof- + assume "both_member_options (?delsimp) y" + hence "y = ?xn \ y = ?newma \ + (both_member_options (?newlist ! (high y (deg div 2))) (low y (deg div 2)) \ (high y (deg div 2)) < length ?newlist)" + using both_member_options_from_complete_tree_to_child[of deg mi ?newma ?newlist ?sn y] dp + by (smt (z3) Suc_1 Suc_le_D both_member_options_def membermima.simps(4) naive_member.simps(3)) + moreover have "y = ?xn \ ?thesis" + by (metis "4.hyps"(9) False \vebt_member (treeList ! summin) lx\ \summin < 2 ^ m\ \invar_vebt (treeList ! summin) n\ both_member_options_equiv_member high_inv less_not_refl low_inv member_bound mimapr xnin) + moreover have "y = ?newma \ ?thesis" + proof- + assume asmt: "y = ?newma" + show ?thesis + proof(cases "?xn = ma") + case True + let ?maxs = "vebt_maxt ?sn" + have newmaext:"?newma = (if ?maxs = None then ?xn + else 2 ^ (deg div 2) * the ?maxs + the (vebt_maxt + ( ?newlist ! the ?maxs)))" using True by force + then show ?thesis + proof(cases "?maxs = None ") + case True + hence aa:"?newma = ?xn" using newmaext by auto + hence bb: "?newma \ x" + using False minxnrel by presburger + hence "both_member_options (Node (Some (mi, ma)) deg treeList summary) ?xn" + using xnin newmaext minxnrel asmt by simp + moreover have "?xn = y" using aa asmt by simp + ultimately have "both_member_options (Node (Some (mi, ma)) deg treeList summary) y" by simp + then show ?thesis using bb + using \summin * 2 ^ n + lx = y\ \y = ?xn \ x \ y \ both_member_options (Node (Some (mi, ma)) deg treeList summary) y\ by blast + next + case False + then obtain maxs where "Some maxs = ?maxs" by force + hence "both_member_options ?sn maxs" + by (simp add: maxbmo) + hence "both_member_options summary maxs \ maxs \ ?h" + using "4.IH"(2) by blast + hence "?newlist ! the ?maxs = treeList ! maxs" + by (metis "4.hyps"(1) \Some maxs = vebt_maxt (vebt_delete summary (high (summin * 2 ^ n + lx) n))\ option.sel member_bound nothprolist valid_member_both_member_options) + have "maxs < 2^m" + using "4.hyps"(1) \both_member_options summary maxs \ maxs \ high (summin * 2 ^ n + lx) n\ member_bound valid_member_both_member_options by blast + hence "the (vebt_maxt (?newlist ! the ?maxs)) = the (vebt_maxt (treeList ! maxs))" + using \?newlist ! the (vebt_maxt ?sn) = treeList ! maxs\ by presburger + have "\ z. both_member_options(treeList ! maxs) z" + using "4.hyps"(5) \both_member_options summary maxs \ maxs \?h\ \maxs < 2 ^ m\ by blast + moreover have "invar_vebt (treeList ! maxs) n" using 4 + by (metis \maxs < 2 ^ m\ inthall member_def) + ultimately obtain maxi where "Some maxi = (vebt_maxt (treeList ! maxs))" + by (metis empty_Collect_eq maxt_corr_help_empty not_None_eq set_vebt'_def valid_member_both_member_options) + hence "maxi < 2^n" + by (metis \invar_vebt (treeList ! maxs) n\ maxt_member member_bound) + hence "both_member_options (treeList ! maxs) maxi" + using \Some maxi = vebt_maxt (treeList ! maxs)\ maxbmo by presburger + hence "2 ^ (deg div 2) * the ?maxs + the + (vebt_maxt (?newlist ! the ?maxs)) = 2^n * maxs + maxi " + by (metis \Some maxi = vebt_maxt (treeList ! maxs)\ \Some maxs = vebt_maxt ?sn\ \deg div 2 = n\ \the (vebt_maxt (?newlist ! the (vebt_maxt ?sn))) = the (vebt_maxt (treeList ! maxs))\ option.sel) + hence "?newma = 2^n * maxs + maxi" + using False True by auto + hence "y = 2^n * maxs + maxi" using asmt by simp + hence "both_member_options (Node (Some (mi, ma)) deg treeList summary) y" + by (metis "4.hyps"(2) Suc_1 \both_member_options (treeList ! maxs) maxi\ \deg div 2 = n\ \maxi < 2 ^ n\ \maxs < 2 ^ m\ add_leD1 both_member_options_from_chilf_to_complete_tree dp high_inv low_inv mult.commute plus_1_eq_Suc) + moreover hence "y \ x" + by (metis "4.hyps"(9) True \Some maxi = vebt_maxt (treeList ! maxs)\ \maxi < 2 ^ n\ \maxs < 2 ^ m\ \x = mi\ \y = 2 ^ n * maxs + maxi\ high_inv less_not_refl low_inv maxbmo minxnrel mult.commute) + ultimately show ?thesis by force + qed + next + case False + hence "?newma = ma" by simp + moreover hence "mi \ ma" + using mimapr by blast + moreover hence "y \ x" + using False \y = ?newma\ \x = mi\ by auto + then show ?thesis + by (metis False \y =?newma\ both_member_options_equiv_member vebt_maxt.simps(3) maxt_member tvalid) + qed + qed + moreover have "(both_member_options (?newlist ! (high y (deg div 2))) (low y (deg div 2)) \ (high y (deg div 2)) < length ?newlist) \ ?thesis" + proof- + assume assm:"both_member_options (?newlist ! (high y (deg div 2))) (low y (deg div 2)) \ (high y (deg div 2)) < length ?newlist" + show ?thesis + proof(cases "(high y (deg div 2)) = ?h") + case True + hence 000:"both_member_options ?newnode (low y (deg div 2)) " using hprolist by (metis assm) + hence 001:"invar_vebt (treeList ! (high y (deg div 2))) n" + using True \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ high_inv member_bound by presburger + then show ?thesis + proof(cases "low y n = ?l") + case True + hence "y = ?xn" + by (metis "000" "4.IH"(1) \deg div 2 = n\ \high (summin * 2 ^ n + lx) n < length treeList\ inthall member_def) + then show ?thesis + using calculation(2) by blast + next + case False + hence "both_member_options (treeList ! ?h) (low y (deg div 2)) \ (low y (deg div 2)) \ (low ?xn (deg div 2))" + using "4.IH"(1) \deg div 2 = n\ \high ?xn n < length treeList\ inthall member_def + by (metis "000") + then show ?thesis + by (metis "4.hyps"(2) "4.hyps"(9) Suc_1 Suc_leD True \deg div 2 = n\ \length treeList = length ?newlist\ \x = mi\ assm both_member_options_from_chilf_to_complete_tree dp less_not_refl mimapr) + qed + next + case False + hence "x \ y" + by (metis "4.hyps"(2) "4.hyps"(9) \deg div 2 = n\ \length treeList = length ?newlist\ \x = mi\ assm less_not_refl mimapr nothprolist) + moreover hence "(?newlist ! (high y (deg div 2))) = treeList ! (high y (deg div 2))" using nothprolist + using "4.hyps"(2) False \length treeList = length ?newlist\ assm by presburger + moreover hence "both_member_options (treeList ! (high y (deg div 2)) ) (low y (deg div 2))" + using assm by presburger + moreover hence "both_member_options (Node (Some (mi, ma)) deg treeList summary) y" + by (metis One_nat_def Suc_leD \length treeList = length ?newlist\ assm both_member_options_from_chilf_to_complete_tree dp numeral_2_eq_2) + ultimately show ?thesis by blast + qed + qed + ultimately show ?thesis by fastforce + qed + moreover have "(x \ y \ both_member_options (Node (Some (mi, ma)) deg treeList summary) y)\ + both_member_options ?delsimp y" + proof- + assume assm: "x \ y \ both_member_options (Node (Some (mi, ma)) deg treeList summary) y" + hence abcv:"y = mi \ y = ma \ ( high y n < length treeList \ both_member_options (treeList ! (high y n)) (low y n))" + by (metis Suc_1 \deg div 2 = n\ add_leD1 both_member_options_from_complete_tree_to_child member_inv plus_1_eq_Suc tvalid valid_member_both_member_options) + thus " both_member_options ?delsimp y" + proof- + have "y = mi \ ?thesis" + using False assm by force + moreover have " y = ma \ ?thesis" + by (smt (z3) Suc_le_D both_member_options_def dp membermima.simps(4) nat_1_add_1 plus_1_eq_Suc) + moreover have " both_member_options (treeList ! (high y n)) (low y n) \ ?thesis" + proof- + assume myass: "both_member_options (treeList ! (high y n)) (low y n) " + thus ?thesis + proof(cases "high y n = ?h") + case True + hence "high y n = ?h" by simp + then show ?thesis + proof(cases "low y n = ?l") + case True + hence "y = ?xn" + by (metis \high y n = high (summin * 2 ^ n + lx) n\ bit_split_inv) + then show ?thesis + by (metis Suc_le_D both_member_options_def dp membermima.simps(4) nat_1_add_1 plus_1_eq_Suc) + next + case False + hence "low y n \ ?l" + by (metis assm bit_split_inv) + hence pp:"?newlist ! ?h = ?newnode" + using hprolist by blast + hence "invar_vebt (treeList ! ?h) n" + using \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ high_inv member_bound by presburger + hence "both_member_options ?newnode (low y n)" + using "4.IH"(1) False True \high (summin * 2 ^ n + lx) n < length treeList\ myass by auto + then show ?thesis + by (metis True \deg div 2 = n\ \high (summin * 2 ^ n + lx) n < length treeList\ \length treeList = length ?newlist\ add_leD1 both_member_options_from_chilf_to_complete_tree dp nat_1_add_1 pp) + qed + next + case False + hence pp:"?newlist ! (high y n) = treeList ! (high y n)" using nothprolist abcv + by (metis "4.hyps"(1) "4.hyps"(3) "4.hyps"(4) assm deg_not_0 exp_split_high_low(1) member_bound tvalid valid_member_both_member_options) + then show ?thesis + by (metis One_nat_def Suc_leD \deg div 2 = n\ \length treeList = length ?newlist\ abcv both_member_options_from_chilf_to_complete_tree calculation(1) calculation(2) dp numerals(2)) + qed + qed + then show ?thesis + using abcv calculation(1) calculation(2) by fastforce + qed + qed + ultimately show ?thesis by metis + next + case False + hence notemp:"\ z. both_member_options ?newnode z" + using not_min_Null_member by auto + let ?newma = "(if ?xn = ma then + ?h * 2^(deg div 2) + the( vebt_maxt (?newlist ! ?h)) + else ma)" + let ?delsimp =" (Node (Some (?xn, ?newma)) deg ?newlist summary)" + have "vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = ?delsimp" + using del_x_mi_lets_in_not_minNull[of x mi ma deg ?xn ?h summary treeList ?l ?newnode ?newlist] + by (metis "4.hyps"(3) "4.hyps"(4) False \Some lx = vebt_mint (treeList ! summin)\ \Some summin = vebt_mint summary\ \high (summin * 2 ^ n + lx) n < length treeList\ \x = mi\ add_self_div_2 dp option.sel less_not_refl mimapr) + moreover have "both_member_options ?delsimp y + \ x \ y \ both_member_options (Node (Some (mi, ma)) deg treeList summary) y" + proof- + assume ssms: "both_member_options ?delsimp y " + hence aaaa: "y = ?xn \ y = ?newma \ (both_member_options (?newlist ! (high y n)) (low y n) \ high y n < length ?newlist)" + by (smt (z3) Suc_1 Suc_le_D \deg div 2 = n\ both_member_options_def dp membermima.simps(4) naive_member.simps(3)) + show " x \ y \ both_member_options (Node (Some (mi, ma)) deg treeList summary) y" + proof- + have "y = ?xn \?thesis" + using \x = mi\ minxnrel xnin by blast + moreover have " y = ?newma \ ?thesis" + proof- + assume "y = ?newma" + show ?thesis + proof(cases "?xn = ma") + case True + hence aaa:"?newma =?h * 2 ^ (deg div 2) +the(vebt_maxt(?newlist ! ?h))" + by metis + have "?newlist ! ?h = ?newnode" using hprolist by blast + obtain maxi where maxidef:"Some maxi = vebt_maxt(?newlist ! ?h)" + by (metis False hprolist vebt_maxt.elims minNull.simps(1) minNull.simps(4)) + have aa:"invar_vebt (treeList ! ?h) n" + by (metis "4.IH"(1) \high ?xn n < length treeList\ inthall member_def) + moreover hence ab:"maxi \ ?l \ both_member_options ?newnode maxi" + by (metis "4.IH"(1) \high ?xn n < length treeList\ hprolist inthall maxbmo maxidef member_def) + ultimately have ac:"maxi \ ?l \ both_member_options (treeList ! ?h) maxi" + by (metis "4.IH"(1) \high ?xn n < length treeList\ inthall member_def) + hence ad:"maxi < 2^n" + by (meson aa member_bound valid_member_both_member_options) + then show ?thesis using Suc_1 aaa \y = ?newma\ ac add_leD1 + by (metis "4.hyps"(2) "4.hyps"(9) Suc_leD \deg div 2 = n\ \high (summin * 2 ^ n + lx) n < length treeList\ \x = mi\ both_member_options_from_chilf_to_complete_tree dp option.sel high_inv less_not_refl low_inv maxidef mimapr) + next + case False + then show ?thesis + by (metis \mi \ x \ x \ ma\ \x = mi\ \y = ?newma\ both_member_options_equiv_member leD vebt_maxt.simps(3) maxt_member mimapr tvalid) + qed + qed + moreover have "(both_member_options (?newlist ! (high y n)) (low y n)\ high y n < length ?newlist) \ ?thesis" + proof- + assume assmy:"(both_member_options (?newlist ! (high y n)) (low y n)\ high y n < length ?newlist)" + then show ?thesis + proof(cases "high y n = ?h") + case True + hence "?newlist ! (high y n) = ?newnode" + using hprolist by presburger + have "invar_vebt (treeList ! ?h) n" + by (metis "4.IH"(1) \high ?xn n < length treeList\ inthall member_def) + then show ?thesis + proof(cases "low y n= ?l") + case True + hence "y = ?xn" + using "4.IH"(1) \high (summin * 2 ^ n + lx) n < length treeList\ \treeList [high (summin * 2 ^ n + lx) n := vebt_delete (treeList ! high (summin * 2 ^ n + lx) n) (low (summin * 2 ^ n + lx) n)] ! high y n = vebt_delete (treeList ! high (summin * 2 ^ n + lx) n) (low (summin * 2 ^ n + lx) n)\ assmy by force + then show ?thesis + using calculation(1) by blast + next + case False + hence "low y n \ ?l \ both_member_options (treeList ! ?h ) (low y n)" using assmy + by (metis "4.IH"(1) "4.hyps"(2) \?newlist ! high y n = vebt_delete (treeList ! high (summin * 2 ^ n + lx) n) (low (summin * 2 ^ n + lx) n)\ \vebt_member (treeList ! summin) lx\ \summin < 2 ^ m\ high_inv inthall member_bound member_def) + then show ?thesis + by (metis "4.hyps"(2) "4.hyps"(9) Suc_1 Suc_leD True \deg div 2 = n\ \high (summin * 2 ^ n + lx) n < length treeList\ \mi \ x \ x \ ma\ \x = mi\ both_member_options_from_chilf_to_complete_tree dp leD mimapr) + qed + next + case False + hence "?newlist ! (high y n) = treeList !(high y n)" + by (smt (z3) "4.hyps"(1) "4.hyps"(2) "4.hyps"(3) "4.hyps"(4) "4.hyps"(8) \length treeList = length ?newlist\ \ma \ 2 ^ deg\ aaaa calculation(2) deg_not_0 exp_split_high_low(1) less_le_trans member_inv mimapr nothprolist tvalid valid_member_both_member_options) + hence "both_member_options (treeList !(high y n)) (low y n)" + using assmy by presburger + moreover have "x \ y" + by (metis "4.hyps"(1) "4.hyps"(4) "4.hyps"(9) \invar_vebt (treeList ! summin) n\ \x < 2 ^ deg\ \x = mi\ calculation deg_not_0 exp_split_high_low(1) mimapr not_less_iff_gr_or_eq) + moreover have "high y n < length ?newlist" using assmy by blast + moreover hence "high y n < length treeList" + using \length treeList = length ?newlist\ by presburger + ultimately show ?thesis + by (metis One_nat_def Suc_leD \deg div 2 = n\ both_member_options_from_chilf_to_complete_tree dp numerals(2)) + qed + qed + ultimately show ?thesis + using aaaa by fastforce + qed + qed + + moreover have "(x \ y \ both_member_options (Node (Some (mi, ma)) deg treeList summary) y)\ + both_member_options ?delsimp y" + proof- + assume assm: "x \ y \ both_member_options (Node (Some (mi, ma)) deg treeList summary) y" + hence abcv:"y = mi \ y = ma \ ( high y n < length treeList \ both_member_options (treeList ! (high y n)) (low y n))" + by (metis Suc_1 \deg div 2 = n\ add_leD1 both_member_options_from_complete_tree_to_child member_inv plus_1_eq_Suc tvalid valid_member_both_member_options) + thus " both_member_options ?delsimp y" + proof- + have "y = mi \ ?thesis" + using \x = mi\ assm by blast + moreover have " y = ma \ ?thesis" + by (smt (z3) Suc_1 Suc_le_D both_member_options_def dp membermima.simps(4)) + moreover have " ( high y n < length treeList \ both_member_options (treeList ! (high y n)) (low y n)) + \ ?thesis" + proof- + assume myass: "( high y n < length treeList \ both_member_options (treeList ! (high y n)) (low y n)) " + thus ?thesis + proof(cases "high y n = ?h") + case True + then show ?thesis + proof(cases "low y n = ?l") + case True + then show ?thesis + by (smt (z3) Suc_1 Suc_le_D \deg div 2 = n\ \length treeList = length (treeList [high (summin * 2 ^ n + lx) n := vebt_delete (treeList ! high (summin * 2 ^ n + lx) n) (low (summin * 2 ^ n + lx) n)])\ add_leD1 bit_split_inv both_member_options_def both_member_options_from_chilf_to_complete_tree dp membermima.simps(4) myass nth_list_update_neq plus_1_eq_Suc) + next + case False + hence "low y n \ ?l" by simp + hence pp:"?newlist ! ?h = ?newnode" + using hprolist by blast + hence "invar_vebt (treeList ! ?h) n" + by (metis "4.IH"(1) \high ?xn n < length treeList\ inthall member_def) + hence "both_member_options ?newnode (low y n)" + by (metis "4.IH"(1) True \high ?xn n < length treeList\ \low y n \ low ?xn n\ in_set_member inthall myass) + then show ?thesis + by (metis One_nat_def Suc_leD True \deg div 2 = n\ \high (summin * 2 ^ n + lx) n < length treeList\ \length treeList = length ?newlist\ both_member_options_from_chilf_to_complete_tree dp numerals(2) pp) + qed + next + case False + have pp:"?newlist ! (high y n) = treeList ! (high y n)" + using nothprolist[of "high y n"] False + by (metis "4.hyps"(1) "4.hyps"(3) "4.hyps"(4) assm deg_not_0 exp_split_high_low(1) member_bound tvalid valid_member_both_member_options) + then show ?thesis + by (metis One_nat_def Suc_leD \deg div 2 = n\ \length treeList = length ?newlist\ abcv both_member_options_from_chilf_to_complete_tree calculation(1) calculation(2) dp numerals(2)) + qed + qed + then show ?thesis + using abcv calculation(1) calculation(2) by fastforce + qed + qed + ultimately show ?thesis by metis + qed + qed + qed + qed +next + case (5 treeList n summary m deg mi ma) + hence tvalid: "invar_vebt (Node (Some (mi, ma)) deg treeList summary) deg" + using invar_vebt.intros(5)[of treeList n summary m deg mi ma] by simp + hence "mi \ ma" and "deg div 2 = n" and "ma \ 2^deg" using 5 + by (auto simp add: "5.hyps"(3) "5.hyps"(4)) + hence dp:"deg \ 2" + by (meson vebt_maxt.simps(3) maxt_member member_inv tvalid) + hence nmpr:"n\ 1 \ m = Suc n" + using "5.hyps"(3) \deg div 2 = n\ by linarith + then show ?case proof(cases "x x > ma") + case True + hence "vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = (Node (Some (mi, ma)) deg treeList summary)" + using delt_out_of_range[of x mi ma deg treeList summary] \2 \ deg\ by blast + then show ?thesis + by (metis "5.hyps"(7) True tvalid leD member_inv not_less_iff_gr_or_eq valid_member_both_member_options) + next + case False + hence "mi \ x \ x \ ma" by simp + hence xdegrel:"x < 2^deg" + using "5.hyps"(8) order.strict_trans1 by blast + then show ?thesis + proof(cases "x = mi \ x = ma") + case True + hence "vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = (Node None deg treeList summary)" + using del_single_cont[of x mi ma deg treeList summary] \2 \ deg\ by blast + moreover hence "invar_vebt (Node None deg treeList summary) deg" + using "5"(4) "5.IH"(1) "5.hyps"(1) "5.hyps"(3) "5.hyps"(4) True mi_eq_ma_no_ch + tvalid invar_vebt.intros(3) by force + moreover hence "\ vebt_member (Node None deg treeList summary) y" by simp + moreover hence "\both_member_options (Node None deg treeList summary) y" + using calculation(2) valid_member_both_member_options by blast + then show ?thesis + by (metis True calculation(1) member_inv not_less_iff_gr_or_eq tvalid valid_member_both_member_options) + next + case False + hence mimapr:"mi < ma" + by (metis "5.hyps"(7) \mi \ x \ x \ ma\ le_antisym nat_less_le) + then show ?thesis + proof(cases "x \ mi") + case True + hence xmi:"x \ mi" by simp + let ?h ="high x n" + let ?l = "low x n" + have "?h < length treeList" using xdegrel 5 + by (metis \deg div 2 = n\ deg_not_0 div_greater_zero_iff dp exp_split_high_low(1) zero_less_numeral) + let ?newnode = "vebt_delete (treeList ! ?h) ?l" + let ?newlist = "treeList[?h:=?newnode]" + have "length treeList = length ?newlist" by simp + hence hprolist: "?newlist ! ?h = ?newnode" + by (meson \high x n < length treeList\ nth_list_update_eq) + have nothprolist: "i \ ?h \ i < 2^m \ ?newlist ! i = treeList ! i" for i by simp + then show ?thesis + proof(cases "minNull ?newnode") + case True + let ?sn = "vebt_delete summary ?h" + let ?newma= "(if x = ma then (let maxs = vebt_maxt ?sn in + (if maxs = None + then mi + else 2^(deg div 2) * the maxs + + the (vebt_maxt (?newlist ! the maxs)) + ) + ) + else ma)" + let ?delsimp =" (Node (Some (mi, ?newma)) deg ?newlist ?sn)" + have "vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = ?delsimp" + using del_x_not_mi_new_node_nil[of mi x ma deg ?h ?l ?newnode treeList ?sn summary ?newlist] + by (metis True \2 \ deg\ \deg div 2 = n\ \high x n < length treeList\ \mi < ma\ \mi \ x \ x \ ma\ \x \ mi\ less_not_refl3 order.not_eq_order_implies_strict) + moreover have "both_member_options (?delsimp) y \ (x \ y \ both_member_options (Node (Some (mi, ma)) deg treeList summary) y)" + proof- + assume "both_member_options (?delsimp) y" + hence "y = mi \ y = ?newma \ + (both_member_options (?newlist ! (high y (deg div 2))) (low y (deg div 2)) \ (high y (deg div 2)) < length ?newlist)" + using both_member_options_from_complete_tree_to_child[of deg mi ?newma ?newlist ?sn y] dp + by (smt (z3) Suc_1 Suc_le_D both_member_options_def membermima.simps(4) naive_member.simps(3)) + moreover have "y = mi \ ?thesis" + by (meson \x \ mi\ both_member_options_equiv_member vebt_mint.simps(3) mint_member tvalid) + moreover have "y = ?newma \ ?thesis" + proof- + assume "y = ?newma" + show ?thesis + proof(cases "x = ma") + case True + let ?maxs = "vebt_maxt ?sn" + have newmapropy:"?newma = (if ?maxs = None then mi + else 2 ^ (deg div 2) * the ?maxs + the (vebt_maxt + (?newlist ! + the ?maxs)))" using True by force + then show ?thesis + proof(cases "?maxs = None ") + case True + then show ?thesis + using \y = (if x = ma then let maxs = vebt_maxt (vebt_delete summary (high x n)) in if maxs = None then mi else 2 ^ (deg div 2) * the maxs + the (vebt_maxt (treeList [high x n := vebt_delete (treeList ! high x n) (low x n)] ! the maxs)) else ma)\ calculation(2) newmapropy by presburger + next + case False + then obtain maxs where "Some maxs = ?maxs" by force + hence "both_member_options ?sn maxs" + by (simp add: maxbmo) + hence "both_member_options summary maxs \ maxs \ ?h" + using "5.IH"(2) by blast + hence "?newlist ! the ?maxs = treeList ! maxs" + by (metis "5.hyps"(1) \Some maxs = vebt_maxt (vebt_delete summary (high x n))\ option.sel member_bound nothprolist valid_member_both_member_options) + have "maxs < 2^m" + using "5.hyps"(1) \both_member_options summary maxs \ maxs \ high x n\ member_bound valid_member_both_member_options by blast + hence "the (vebt_maxt (?newlist ! the ?maxs)) = the (vebt_maxt (treeList ! maxs))" + by (metis \Some maxs = vebt_maxt (vebt_delete summary (high x n))\ \both_member_options summary maxs \ maxs \ high x n\ option.sel nth_list_update_neq) + have "\ z. both_member_options(treeList ! maxs) z" + by (simp add: "5.hyps"(5) \both_member_options summary maxs \ maxs \ high x n\ \maxs < 2 ^ m\) + moreover have "invar_vebt (treeList ! maxs) n" using 5 + by (metis \maxs < 2 ^ m\ inthall member_def) + ultimately obtain maxi where "Some maxi = (vebt_maxt (treeList ! maxs))" + by (metis empty_Collect_eq maxt_corr_help_empty not_None_eq set_vebt'_def valid_member_both_member_options) + hence "maxi < 2^n" + by (metis \invar_vebt (treeList ! maxs) n\ maxt_member member_bound) + hence "both_member_options (treeList ! maxs) maxi" + using \Some maxi = vebt_maxt (treeList ! maxs)\ maxbmo by presburger + hence "2 ^ (deg div 2) * the ?maxs + the + (vebt_maxt (?newlist ! the ?maxs)) = 2^n * maxs + maxi " + by (metis \Some maxi = vebt_maxt (treeList ! maxs)\ \Some maxs = vebt_maxt (vebt_delete summary (high x n))\ \deg div 2 = n\ \the (vebt_maxt (treeList[high x n := vebt_delete (treeList ! high x n) (low x n)] ! the (vebt_maxt (vebt_delete summary (high x n))))) = the (vebt_maxt (treeList ! maxs))\ option.sel) + hence "y = 2^n * maxs + maxi" + using False \y = (if x = ma then let maxs = vebt_maxt (vebt_delete summary (high x n)) in if maxs = None then mi else 2 ^ (deg div 2) * the maxs + the (vebt_maxt (treeList [high x n := vebt_delete (treeList ! high x n) (low x n)] ! the maxs)) else ma)\ newmapropy by presburger + hence "both_member_options (Node (Some (mi, ma)) deg treeList summary) y" + by (metis "5.hyps"(2) Suc_1 \both_member_options (treeList ! maxs) maxi\ \deg div 2 = n\ \maxi < 2 ^ n\ \maxs < 2 ^ m\ add_leD1 both_member_options_from_chilf_to_complete_tree dp high_inv low_inv mult.commute plus_1_eq_Suc) + moreover hence "y \ x" + by (metis \both_member_options summary maxs \ maxs \ high x n\ \maxi < 2 ^ n\ \y = 2 ^ n * maxs + maxi\ high_inv mult.commute) + ultimately show ?thesis by force + qed + next + case False + hence "?newma = ma" by simp + moreover hence "y \ x" + using False \y = ?newma\ by presburger + then show ?thesis + by (metis False \y =?newma\ both_member_options_equiv_member vebt_maxt.simps(3) maxt_member tvalid) + qed + qed + moreover have "(both_member_options (?newlist ! (high y (deg div 2))) (low y (deg div 2)) \ (high y (deg div 2)) < length ?newlist) \ ?thesis" + proof- + assume assm:"both_member_options (?newlist ! (high y (deg div 2))) (low y (deg div 2)) \ (high y (deg div 2)) < length ?newlist" + show ?thesis + proof(cases "(high y (deg div 2)) = ?h") + case True + hence "both_member_options ?newnode (low y (deg div 2)) " using hprolist by (metis assm) + moreover hence "invar_vebt (treeList ! (high y (deg div 2))) n" + by (metis "5.IH"(1) True \high x n < length treeList\ inthall member_def) + ultimately have "both_member_options (treeList ! ?h) (low y (deg div 2)) \ (low y (deg div 2)) \ (low x (deg div 2))" + by (metis "5.IH"(1) \deg div 2 = n\ \high x n < length treeList\ inthall member_def) + then show ?thesis + by (metis Suc_1 True \high x n < length treeList\ add_leD1 both_member_options_from_chilf_to_complete_tree dp plus_1_eq_Suc) + next + case False + hence "x \ y" + using \deg div 2 = n\ by blast + moreover hence "(?newlist ! (high y (deg div 2))) = treeList ! (high y (deg div 2))" using nothprolist + using "5.hyps"(2) False \length treeList = length ?newlist\ assm by presburger + moreover hence "both_member_options (treeList ! (high y (deg div 2)) ) (low y (deg div 2))" + using assm by presburger + moreover hence "both_member_options (Node (Some (mi, ma)) deg treeList summary) y" + by (metis One_nat_def Suc_leD \length treeList = length ?newlist\ assm both_member_options_from_chilf_to_complete_tree dp numeral_2_eq_2) + ultimately show ?thesis by blast + qed + qed + ultimately show ?thesis by fastforce + qed + moreover have " (x \ y \ both_member_options (Node (Some (mi, ma)) deg treeList summary) y) \ both_member_options (?delsimp) y" + proof- + assume "(x \ y \ both_member_options (Node (Some (mi, ma)) deg treeList summary) y)" + hence aa:"x \ y" and bb:"y = mi \ y = ma \ (both_member_options (treeList ! (high y n)) (low y n) \ high y n < length treeList)" + apply auto[1] by (metis Suc_1 \deg div 2 = n\ \x \ y \ both_member_options (Node (Some (mi, ma)) deg treeList summary) y\ add_leD1 both_member_options_from_complete_tree_to_child member_inv plus_1_eq_Suc tvalid valid_member_both_member_options) + show "both_member_options (?delsimp) y" + proof- + have "y = mi \both_member_options (?delsimp) y" + by (metis Suc_1 Suc_le_D both_member_options_def dp membermima.simps(4)) + moreover have "y = ma \ both_member_options (?delsimp) y" + using aa maxbmo vebt_maxt.simps(3) by presburger + moreover have "both_member_options (treeList ! (high y n)) (low y n) \both_member_options (?delsimp) y " + proof- + assume assmy: "both_member_options (treeList ! (high y n)) (low y n)" + then show "both_member_options (?delsimp) y " + proof(cases "high y n = ?h") + case True + moreover hence "?newlist ! (high y n) = ?newnode" + using hprolist by auto + hence 0:"invar_vebt (treeList !(high y n)) n" using 5 + by (metis True \high x n < length treeList\ inthall member_def) + moreover have 1:"low y n \ low x n" + by (metis True aa bit_split_inv) + moreover have 11:" (treeList !(high y n)) \ set treeList" + by (metis True \high x n < length treeList\ inthall member_def) + ultimately have " (\ xa. both_member_options ?newnode xa = + ((low x n) \ xa \ both_member_options (treeList ! ?h) xa))" + by (simp add: "5.IH"(1)) + hence "((low x n) \ xa \ both_member_options (treeList ! ?h) xa) \ both_member_options ?newnode xa" for xa by blast + moreover have "((low x n) \ (low y n) \ both_member_options (treeList ! ?h) (low y n))" using 1 + using True assmy by presburger + ultimately have "both_member_options ?newnode (low y n)" by blast + then show ?thesis + by (metis One_nat_def Suc_leD True \deg div 2 = n\ \high x n < length treeList\ \length treeList = length ?newlist\ both_member_options_from_chilf_to_complete_tree dp hprolist numerals(2)) + next + case False + hence "?newlist ! (high y n) = treeList ! (high y n)" by auto + hence "both_member_options (?newlist !(high y n)) (low y n)" + using assmy by presburger + then show ?thesis + by (smt (z3) Suc_1 Suc_le_D \deg div 2 = n\ \length treeList = length ?newlist\ aa add_leD1 bb both_member_options_def both_member_options_from_chilf_to_complete_tree dp membermima.simps(4) plus_1_eq_Suc) + qed + qed + ultimately show ?thesis using bb by fastforce + qed + qed + ultimately show ?thesis by metis + next + case False + hence notemp:"\ z. both_member_options ?newnode z" + using not_min_Null_member by auto + let ?newma = "(if x = ma then + ?h * 2^(deg div 2) + the( vebt_maxt (?newlist ! ?h)) + else ma)" + let ?delsimp =" (Node (Some (mi, ?newma)) deg ?newlist summary)" + have "vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = ?delsimp" + using del_x_not_mi_newnode_not_nil[of mi x ma deg ?h ?l ?newnode treeList ?newlist summary] False xmi mimapr + using \deg div 2 = n\ \high x n < length treeList\ \mi \ x \ x \ ma\ dp nat_less_le plus_1_eq_Suc by fastforce + moreover have "both_member_options ?delsimp y + \ x \ y \ both_member_options (Node (Some (mi, ma)) deg treeList summary) y" + proof- + assume ssms: "both_member_options ?delsimp y " + hence aaaa: "y = mi \ y = ?newma \ (both_member_options (?newlist ! (high y n)) (low y n) \ high y n < length ?newlist)" + by (smt (z3) Suc_1 Suc_le_D \deg div 2 = n\ both_member_options_def dp membermima.simps(4) naive_member.simps(3)) + show " x \ y \ both_member_options (Node (Some (mi, ma)) deg treeList summary) y" + proof- + have "y = mi \?thesis" + by (metis Suc_1 Suc_le_D both_member_options_def dp membermima.simps(4) xmi) + moreover have " y = ?newma \ ?thesis" + proof- + assume "y = ?newma" + show ?thesis + proof(cases "x = ma") + case True + hence "?newma =?h * 2 ^ (deg div 2) +the(vebt_maxt(?newlist ! ?h))" + by metis + have "?newlist ! ?h = ?newnode" using hprolist by blast + obtain maxi where maxidef:"Some maxi = vebt_maxt(?newlist ! ?h)" + by (metis False hprolist vebt_maxt.elims minNull.simps(1) minNull.simps(4)) + have aa:"invar_vebt (treeList ! ?h) n" + by (metis "5.IH"(1) \high x n < length treeList\ inthall member_def) + moreover hence ab:"maxi \ ?l \ both_member_options ?newnode maxi" + by (metis "5.IH"(1) \high x n < length treeList\ hprolist inthall maxbmo maxidef member_def) + ultimately have ac:"maxi \ ?l \ both_member_options (treeList ! ?h) maxi" + by (metis "5.IH"(1) \high x n < length treeList\ inthall member_def) + hence ad:"maxi < 2^n" + using \invar_vebt (treeList ! high x n) n\ member_bound valid_member_both_member_options by blast + then show ?thesis + by (metis Suc_1 \(if x = ma then high x n * 2 ^ (deg div 2) + the (vebt_maxt (treeList[high x n := vebt_delete (treeList ! high x n) (low x n)] ! high x n)) else ma) = high x n * 2 ^ (deg div 2) + the (vebt_maxt (treeList[high x n := vebt_delete (treeList ! high x n) (low x n)] ! high x n))\ \deg div 2 = n\ \high x n < length treeList\ \y = (if x = ma then high x n * 2 ^ (deg div 2) + the (vebt_maxt (treeList[high x n := vebt_delete (treeList ! high x n) (low x n)] ! high x n)) else ma)\ ac add_leD1 both_member_options_from_chilf_to_complete_tree dp option.sel high_inv low_inv maxidef plus_1_eq_Suc) + next + case False + then show ?thesis + by (simp add: \y = ?newma\ maxbmo) + qed + qed + moreover have "both_member_options (?newlist ! (high y n)) (low y n) \ ?thesis" + proof- + assume assmy:"both_member_options (?newlist ! (high y n)) (low y n)" + then show ?thesis + proof(cases "high y n = ?h") + case True + hence "?newlist ! (high y n) = ?newnode" + using hprolist by presburger + have "invar_vebt (treeList ! ?h) n" + by (metis "5.IH"(1) \high x n < length treeList\ inthall member_def) + hence "low y n \ ?l \ both_member_options (treeList ! ?h ) (low y n)" + by (metis "5.IH"(1) True \high x n < length treeList\ assmy hprolist inthall member_def) + then show ?thesis + by (metis Suc_1 True \deg div 2 = n\ \high x n < length treeList\ add_leD1 both_member_options_from_chilf_to_complete_tree dp plus_1_eq_Suc) + next + case False + hence "?newlist ! (high y n) = treeList !(high y n)" by auto + then show ?thesis + by (metis False Suc_1 \deg div 2 = n\ \length treeList = length ?newlist\ aaaa add_leD1 both_member_options_from_chilf_to_complete_tree calculation(1) calculation(2) dp plus_1_eq_Suc) + qed + qed + ultimately show ?thesis + using aaaa by fastforce + qed + qed + moreover have "(x \ y \ both_member_options (Node (Some (mi, ma)) deg treeList summary) y)\ + both_member_options ?delsimp y" + proof- + assume assm: "x \ y \ both_member_options (Node (Some (mi, ma)) deg treeList summary) y" + hence abcv:"y = mi \ y = ma \ ( high y n < length treeList \ both_member_options (treeList ! (high y n)) (low y n))" + by (metis Suc_1 \deg div 2 = n\ add_leD1 both_member_options_from_complete_tree_to_child member_inv plus_1_eq_Suc tvalid valid_member_both_member_options) + thus " both_member_options ?delsimp y" + proof- + have "y = mi \ ?thesis" + by (metis Suc_1 Suc_le_D both_member_options_def dp membermima.simps(4)) + moreover have " y = ma \ ?thesis" + using assm maxbmo vebt_maxt.simps(3) by presburger + moreover have " both_member_options (treeList ! (high y n)) (low y n) \ ?thesis" + proof- + assume myass: "both_member_options (treeList ! (high y n)) (low y n) " + thus ?thesis + proof(cases "high y n = ?h") + case True + hence "low y n \ ?l" + by (metis assm bit_split_inv) + hence pp:"?newlist ! ?h = ?newnode" + using hprolist by blast + hence "invar_vebt (treeList ! ?h) n" + by (metis "5.IH"(1) \high x n < length treeList\ inthall member_def) + hence "both_member_options ?newnode (low y n)" + by (metis "5.IH"(1) True \high x n < length treeList\ \low y n \ low x n\ in_set_member inthall myass) + then show ?thesis + by (metis One_nat_def Suc_leD True \deg div 2 = n\ \high x n < length treeList\ \length treeList = length ?newlist\ both_member_options_from_chilf_to_complete_tree dp numerals(2) pp) + next + case False + hence pp:"?newlist ! (high y n) = treeList ! (high y n)" using nothprolist abcv by auto + then show ?thesis + by (metis One_nat_def Suc_leD \deg div 2 = n\ \length treeList = length ?newlist\ abcv both_member_options_from_chilf_to_complete_tree calculation(1) calculation(2) dp numerals(2)) + qed + qed + then show ?thesis + using abcv calculation(1) calculation(2) by fastforce + qed + qed + ultimately show ?thesis by metis + qed + next + case False + hence "x = mi" by simp + have "both_member_options summary (high ma n)" + by (metis "5"(10) "5"(11) "5"(7) "5.hyps"(4) Euclidean_Division.div_eq_0_iff Suc_leI Suc_le_D div_exp_eq dual_order.irrefl high_def mimapr nat.simps(3)) + hence "vebt_member summary (high ma n)" + using "5.hyps"(1) valid_member_both_member_options by blast + obtain summin where "Some summin = vebt_mint summary" + by (metis "5.hyps"(1) \vebt_member summary (high ma n)\ empty_Collect_eq mint_corr_help_empty not_None_eq set_vebt'_def) + hence "\ z . both_member_options (treeList ! summin) z" + by (metis "5.hyps"(1) "5.hyps"(5) both_member_options_equiv_member member_bound mint_member) + moreover have "invar_vebt (treeList ! summin) n" + by (metis "5.IH"(1) "5.hyps"(1) "5.hyps"(2) \Some summin = vebt_mint summary\ member_bound mint_member nth_mem) + ultimately obtain lx where "Some lx = vebt_mint (treeList ! summin)" + by (metis empty_Collect_eq mint_corr_help_empty not_None_eq set_vebt'_def valid_member_both_member_options) + let ?xn = "summin*2^n + lx" + have "?xn = (if x = mi + then the (vebt_mint summary) * 2^(deg div 2) + + the (vebt_mint (treeList ! the (vebt_mint summary))) + else x)" + by (metis False \Some lx = vebt_mint (treeList ! summin)\ \Some summin = vebt_mint summary\ \deg div 2 = n\ option.sel) + have "vebt_member (treeList ! summin) lx" + using \Some lx = vebt_mint (treeList ! summin)\ \invar_vebt (treeList ! summin) n\ mint_member by auto + moreover have "summin < 2^m" + by (metis "5.hyps"(1) \Some summin = vebt_mint summary\ member_bound mint_member) + ultimately have xnin: "both_member_options (Node (Some (mi, ma)) deg treeList summary) ?xn" + by (metis "5.hyps"(2) Suc_1 \deg div 2 = n\ \invar_vebt (treeList ! summin) n\ add_leD1 both_member_options_equiv_member both_member_options_from_chilf_to_complete_tree dp high_inv low_inv member_bound plus_1_eq_Suc) + let ?h ="high ?xn n" + let ?l = "low ?xn n" + have "?xn < 2^deg" + by (smt (verit, ccfv_SIG) "5.hyps"(1) "5.hyps"(4) Euclidean_Division.div_eq_0_iff \Some lx = vebt_mint (treeList ! summin)\ \Some summin = vebt_mint summary\ \invar_vebt (treeList ! summin) n\ div_exp_eq high_def high_inv le_0_eq member_bound mint_member not_numeral_le_zero power_not_zero) + hence "?h < length treeList" + using "5.hyps"(2) \vebt_member (treeList ! summin) lx\ \summin < 2 ^ m\ \invar_vebt (treeList ! summin) n\ high_inv member_bound by presburger + let ?newnode = "vebt_delete (treeList ! ?h) ?l" + let ?newlist = "treeList[?h:= ?newnode]" + have "length treeList = length ?newlist" by simp + hence hprolist: "?newlist ! ?h = ?newnode" + by (meson \high (summin * 2 ^ n + lx) n < length treeList\ nth_list_update) + have nothprolist: "i \ ?h \ i < 2^m \ ?newlist ! i = treeList ! i" for i by simp + have firstsimp: "vebt_delete (Node (Some (mi, ma)) deg treeList summary) x =( + let newnode = vebt_delete (treeList ! ?h) ?l; + newlist = treeList[?h:= ?newnode] in + if minNull newnode + then( + let sn = vebt_delete summary ?h in + (Node (Some (?xn, if ?xn = ma then (let maxs = vebt_maxt sn in + (if maxs = None + then ?xn + else 2^(deg div 2) * the maxs + + the (vebt_maxt (newlist ! the maxs)) + ) + ) + else ma)) + deg newlist sn) + )else + (Node (Some (?xn, (if ?xn = ma then + ?h * 2^(deg div 2) + the( vebt_maxt (newlist ! ?h)) + else ma))) + deg newlist summary ))" + using del_x_mi[of x mi ma deg ?xn ?h summary treeList ?l] + \deg div 2 = n\ \high (summin * 2 ^ n + lx) n < length treeList\ + \summin * 2 ^ n + lx = (if x = mi then the (vebt_mint summary) * 2 ^ (deg div 2) + + the (vebt_mint (treeList ! the (vebt_mint summary))) else x)\ \x = mi\ dp mimapr nat_less_le by smt + have minxnrel: "?xn \ mi" + by (metis "5.hyps"(2) "5.hyps"(9) \high (summin * 2 ^ n + lx) n < length treeList\ \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ both_member_options_equiv_member high_inv less_not_refl low_inv member_bound mimapr) + then show ?thesis + proof(cases "minNull ?newnode") + case True + let ?sn = "vebt_delete summary ?h" + let ?newma= "(if ?xn= ma then (let maxs = vebt_maxt ?sn in + (if maxs = None + then ?xn + else 2^(deg div 2) * the maxs + + the (vebt_maxt (?newlist ! the maxs)) + ) + ) + else ma)" + let ?delsimp =" (Node (Some (?xn, ?newma)) deg ?newlist ?sn)" + have "vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = ?delsimp" + using del_x_mi_lets_in_minNull[of x mi ma deg ?xn ?h summary treeList ?l ?newnode ?newlist ?sn] False True \deg div 2 = n\ \?h < length treeList\ \summin * 2 ^ n + lx = (if x = mi then the (vebt_mint summary) * 2 ^ (deg div 2) + the (vebt_mint (treeList ! the (vebt_mint summary))) else x)\ dp less_not_refl3 mimapr by fastforce + moreover have "both_member_options (?delsimp) y \ (x \ y \ both_member_options (Node (Some (mi, ma)) deg treeList summary) y)" + proof- + assume "both_member_options (?delsimp) y" + hence "y = ?xn \ y = ?newma \ + (both_member_options (?newlist ! (high y (deg div 2))) (low y (deg div 2)) \ (high y (deg div 2)) < length ?newlist)" + using both_member_options_from_complete_tree_to_child[of deg mi ?newma ?newlist ?sn y] dp + by (smt (z3) Suc_1 Suc_le_D both_member_options_def membermima.simps(4) naive_member.simps(3)) + moreover have "y = ?xn \ ?thesis" + by (metis "5.hyps"(9) False \vebt_member (treeList ! summin) lx\ \summin < 2 ^ m\ \invar_vebt (treeList ! summin) n\ both_member_options_equiv_member high_inv less_not_refl low_inv member_bound mimapr xnin) + moreover have "y = ?newma \ ?thesis" + proof- + assume asmt: "y = ?newma" + show ?thesis + proof(cases "?xn = ma") + case True + let ?maxs = "vebt_maxt ?sn" + have newmaext:"?newma = (if ?maxs = None then ?xn + else 2 ^ (deg div 2) * the ?maxs + the (vebt_maxt + ( ?newlist ! the ?maxs)))" using True by force + then show ?thesis + proof(cases "?maxs = None ") + case True + hence aa:"?newma = ?xn" using newmaext by auto + hence bb: "?newma \ x" + using False minxnrel by presburger + hence "both_member_options (Node (Some (mi, ma)) deg treeList summary) ?xn" + using xnin newmaext minxnrel asmt by simp + moreover have "?xn = y" using aa asmt by simp + ultimately have "both_member_options (Node (Some (mi, ma)) deg treeList summary) y" by simp + then show ?thesis using bb + using \summin * 2 ^ n + lx = y\ \y = ?xn \ x \ y \ both_member_options (Node (Some (mi, ma)) deg treeList summary) y\ by blast + next + case False + then obtain maxs where "Some maxs = ?maxs" by force + hence "both_member_options ?sn maxs" + by (simp add: maxbmo) + hence "both_member_options summary maxs \ maxs \ ?h" + using "5.IH"(2) by blast + hence "?newlist ! the ?maxs = treeList ! maxs" + by (metis "5.hyps"(1) \Some maxs = vebt_maxt (vebt_delete summary (high (summin * 2 ^ n + lx) n))\ option.sel member_bound nothprolist valid_member_both_member_options) + have "maxs < 2^m" + using "5.hyps"(1) \both_member_options summary maxs \ maxs \ high (summin * 2 ^ n + lx) n\ member_bound valid_member_both_member_options by blast + hence "the (vebt_maxt (?newlist ! the ?maxs)) = the (vebt_maxt (treeList ! maxs))" + using \?newlist ! the (vebt_maxt ?sn) = treeList ! maxs\ by presburger + have "\ z. both_member_options(treeList ! maxs) z" + using "5.hyps"(5) \both_member_options summary maxs \ maxs \?h\ \maxs < 2 ^ m\ by blast + moreover have "invar_vebt (treeList ! maxs) n" using 5 + by (metis \maxs < 2 ^ m\ inthall member_def) + ultimately obtain maxi where "Some maxi = (vebt_maxt (treeList ! maxs))" + by (metis empty_Collect_eq maxt_corr_help_empty not_None_eq set_vebt'_def valid_member_both_member_options) + hence "maxi < 2^n" + by (metis \invar_vebt (treeList ! maxs) n\ maxt_member member_bound) + hence "both_member_options (treeList ! maxs) maxi" + using \Some maxi = vebt_maxt (treeList ! maxs)\ maxbmo by presburger + hence "2 ^ (deg div 2) * the ?maxs + the + (vebt_maxt (?newlist ! the ?maxs)) = 2^n * maxs + maxi " + by (metis \Some maxi = vebt_maxt (treeList ! maxs)\ \Some maxs = vebt_maxt ?sn\ \deg div 2 = n\ \the (vebt_maxt (?newlist ! the (vebt_maxt ?sn))) = the (vebt_maxt (treeList ! maxs))\ option.sel) + hence "?newma = 2^n * maxs + maxi" + using False True by auto + hence "y = 2^n * maxs + maxi" using asmt by simp + hence "both_member_options (Node (Some (mi, ma)) deg treeList summary) y" + by (metis "5.hyps"(2) Suc_1 \both_member_options (treeList ! maxs) maxi\ \deg div 2 = n\ \maxi < 2 ^ n\ \maxs < 2 ^ m\ add_leD1 both_member_options_from_chilf_to_complete_tree dp high_inv low_inv mult.commute plus_1_eq_Suc) + moreover hence "y \ x" + by (metis "5.hyps"(9) True \Some maxi = vebt_maxt (treeList ! maxs)\ \maxi < 2 ^ n\ \maxs < 2 ^ m\ \x = mi\ \y = 2 ^ n * maxs + maxi\ high_inv less_not_refl low_inv maxbmo minxnrel mult.commute) + ultimately show ?thesis by force + qed + next + case False + hence "?newma = ma" by simp + moreover hence "mi \ ma" + using mimapr by blast + moreover hence "y \ x" + using False \y = ?newma\ \x = mi\ by auto + then show ?thesis + by (metis False \y =?newma\ both_member_options_equiv_member vebt_maxt.simps(3) maxt_member tvalid) + qed + qed + moreover have "(both_member_options (?newlist ! (high y (deg div 2))) (low y (deg div 2)) \ (high y (deg div 2)) < length ?newlist) \ ?thesis" + proof- + assume assm:"both_member_options (?newlist ! (high y (deg div 2))) (low y (deg div 2)) \ (high y (deg div 2)) < length ?newlist" + show ?thesis + proof(cases "(high y (deg div 2)) = ?h") + case True + hence 000:"both_member_options ?newnode (low y (deg div 2)) " using hprolist by (metis assm) + hence 001:"invar_vebt (treeList ! (high y (deg div 2))) n" + using True \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ high_inv member_bound by presburger + then show ?thesis + proof(cases "low y n = ?l") + case True + hence "y = ?xn" + by (metis "000" "5.IH"(1) \deg div 2 = n\ \high (summin * 2 ^ n + lx) n < length treeList\ inthall member_def) + then show ?thesis + using calculation(2) by blast + next + case False + hence "both_member_options (treeList ! ?h) (low y (deg div 2)) \ (low y (deg div 2)) \ (low ?xn (deg div 2))" + using "5.IH"(1) \deg div 2 = n\ \high ?xn n < length treeList\ inthall member_def + by (metis "000") + then show ?thesis + by (metis "5.hyps"(2) "5.hyps"(9) Suc_1 Suc_leD True \deg div 2 = n\ \length treeList = length ?newlist\ \x = mi\ assm both_member_options_from_chilf_to_complete_tree dp less_not_refl mimapr) + qed + next + case False + hence "x \ y" + by (metis "5.hyps"(2) "5.hyps"(9) \deg div 2 = n\ \length treeList = length ?newlist\ \x = mi\ assm less_not_refl mimapr nothprolist) + moreover hence "(?newlist ! (high y (deg div 2))) = treeList ! (high y (deg div 2))" using nothprolist + using "5.hyps"(2) False \length treeList = length ?newlist\ assm by presburger + moreover hence "both_member_options (treeList ! (high y (deg div 2)) ) (low y (deg div 2))" + using assm by presburger + moreover hence "both_member_options (Node (Some (mi, ma)) deg treeList summary) y" + by (metis One_nat_def Suc_leD \length treeList = length ?newlist\ assm both_member_options_from_chilf_to_complete_tree dp numeral_2_eq_2) + ultimately show ?thesis by blast + qed + qed + ultimately show ?thesis by fastforce + qed + moreover have "(x \ y \ both_member_options (Node (Some (mi, ma)) deg treeList summary) y)\ + both_member_options ?delsimp y" + proof- + assume assm: "x \ y \ both_member_options (Node (Some (mi, ma)) deg treeList summary) y" + hence abcv:"y = mi \ y = ma \ ( high y n < length treeList \ both_member_options (treeList ! (high y n)) (low y n))" + by (metis Suc_1 \deg div 2 = n\ add_leD1 both_member_options_from_complete_tree_to_child member_inv plus_1_eq_Suc tvalid valid_member_both_member_options) + thus " both_member_options ?delsimp y" + proof- + have "y = mi \ ?thesis" + using False assm by force + moreover have " y = ma \ ?thesis" + by (smt (z3) Suc_le_D both_member_options_def dp membermima.simps(4) nat_1_add_1 plus_1_eq_Suc) + moreover have " both_member_options (treeList ! (high y n)) (low y n) \ ?thesis" + proof- + assume myass: "both_member_options (treeList ! (high y n)) (low y n) " + thus ?thesis + proof(cases "high y n = ?h") + case True + hence "high y n = ?h" by simp + then show ?thesis + proof(cases "low y n = ?l") + case True + hence "y = ?xn" + by (metis \high y n = high (summin * 2 ^ n + lx) n\ bit_split_inv) + then show ?thesis + by (metis Suc_le_D both_member_options_def dp membermima.simps(4) nat_1_add_1 plus_1_eq_Suc) + next + case False + hence "low y n \ ?l" + by (metis assm bit_split_inv) + hence pp:"?newlist ! ?h = ?newnode" + using hprolist by blast + hence "invar_vebt (treeList ! ?h) n" + using \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ high_inv member_bound by presburger + hence "both_member_options ?newnode (low y n)" + using "5.IH"(1) False True \high (summin * 2 ^ n + lx) n < length treeList\ myass by force + then show ?thesis + by (metis True \deg div 2 = n\ \high (summin * 2 ^ n + lx) n < length treeList\ \length treeList = length ?newlist\ add_leD1 both_member_options_from_chilf_to_complete_tree dp nat_1_add_1 pp) + qed + next + case False + hence pp:"?newlist ! (high y n) = treeList ! (high y n)" using nothprolist abcv by auto + then show ?thesis + by (metis One_nat_def Suc_leD \deg div 2 = n\ \length treeList = length ?newlist\ abcv both_member_options_from_chilf_to_complete_tree calculation(1) calculation(2) dp numerals(2)) + qed + qed + then show ?thesis + using abcv calculation(1) calculation(2) by fastforce + qed + qed + ultimately show ?thesis by metis + next + case False + hence notemp:"\ z. both_member_options ?newnode z" + using not_min_Null_member by auto + let ?newma = "(if ?xn = ma then + ?h * 2^(deg div 2) + the( vebt_maxt (?newlist ! ?h)) + else ma)" + let ?delsimp =" (Node (Some (?xn, ?newma)) deg ?newlist summary)" + have "vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = ?delsimp" + using del_x_mi_lets_in_not_minNull[of x mi ma deg ?xn ?h summary treeList ?l ?newnode ?newlist] + using False \deg div 2 = n\ \high (summin * 2 ^ n + lx) n < length treeList\ \summin * 2 ^ n + lx = (if x = mi then the (vebt_mint summary) * 2 ^ (deg div 2) + the (vebt_mint (treeList ! the (vebt_mint summary))) else x)\ \x = mi\ dp mimapr nat_less_le by fastforce + moreover have "both_member_options ?delsimp y + \ x \ y \ both_member_options (Node (Some (mi, ma)) deg treeList summary) y" + proof- + assume ssms: "both_member_options ?delsimp y " + hence aaaa: "y = ?xn \ y = ?newma \ (both_member_options (?newlist ! (high y n)) (low y n) \ high y n < length ?newlist)" + by (smt (z3) Suc_1 Suc_le_D \deg div 2 = n\ both_member_options_def dp membermima.simps(4) naive_member.simps(3)) + show " x \ y \ both_member_options (Node (Some (mi, ma)) deg treeList summary) y" + proof- + have "y = ?xn \?thesis" + using \x = mi\ minxnrel xnin by blast + moreover have " y = ?newma \ ?thesis" + proof- + assume "y = ?newma" + show ?thesis + proof(cases "?xn = ma") + case True + hence aaa:"?newma =?h * 2 ^ (deg div 2) +the(vebt_maxt(?newlist ! ?h))" + by metis + have "?newlist ! ?h = ?newnode" using hprolist by blast + obtain maxi where maxidef:"Some maxi = vebt_maxt(?newlist ! ?h)" + by (metis False hprolist vebt_maxt.elims minNull.simps(1) minNull.simps(4)) + have aa:"invar_vebt (treeList ! ?h) n" + by (metis "5.IH"(1) \high ?xn n < length treeList\ inthall member_def) + moreover hence ab:"maxi \ ?l \ both_member_options ?newnode maxi" + by (metis "5.IH"(1) \high ?xn n < length treeList\ hprolist inthall maxbmo maxidef member_def) + ultimately have ac:"maxi \ ?l \ both_member_options (treeList ! ?h) maxi" + by (metis "5.IH"(1) \high ?xn n < length treeList\ inthall member_def) + hence ad:"maxi < 2^n" + using \invar_vebt (treeList ! high ?xn n) n\ member_bound valid_member_both_member_options by blast + then show ?thesis using Suc_1 aaa \y = ?newma\ ac add_leD1 + both_member_options_from_chilf_to_complete_tree dp option.sel high_inv low_inv maxidef plus_1_eq_Suc + by (metis (no_types, lifting) True \Some lx = vebt_mint (treeList ! summin)\ + \deg div 2 = n\ \high (summin * 2 ^ n + lx) n < length treeList\ + \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ + \x = mi\ leD member_bound mimapr mint_corr_help nat_add_left_cancel_le + valid_member_both_member_options) + next + case False + then show ?thesis + by (metis \mi \ x \ x \ ma\ \x = mi\ \y = ?newma\ both_member_options_equiv_member leD vebt_maxt.simps(3) maxt_member mimapr tvalid) + qed + qed + moreover have "(both_member_options (?newlist ! (high y n)) (low y n)\ high y n < length ?newlist) \ ?thesis" + proof- + assume assmy:"(both_member_options (?newlist ! (high y n)) (low y n)\ high y n < length ?newlist)" + then show ?thesis + proof(cases "high y n = ?h") + case True + hence "?newlist ! (high y n) = ?newnode" + using hprolist by presburger + have "invar_vebt (treeList ! ?h) n" + by (metis "5.IH"(1) \high ?xn n < length treeList\ inthall member_def) + then show ?thesis + proof(cases "low y n= ?l") + case True + hence "y = ?xn" + using "5.IH"(1) \high (summin * 2 ^ n + lx) n < length treeList\ \treeList [high (summin * 2 ^ n + lx) n := vebt_delete (treeList ! high (summin * 2 ^ n + lx) n) (low (summin * 2 ^ n + lx) n)] ! high y n = vebt_delete (treeList ! high (summin * 2 ^ n + lx) n) (low (summin * 2 ^ n + lx) n)\ assmy by force + then show ?thesis + using calculation(1) by blast + next + case False + hence "low y n \ ?l \ both_member_options (treeList ! ?h ) (low y n)" using assmy + by (metis "5.IH"(1) "5.hyps"(2) \?newlist ! high y n = vebt_delete (treeList ! high (summin * 2 ^ n + lx) n) (low (summin * 2 ^ n + lx) n)\ \vebt_member (treeList ! summin) lx\ \summin < 2 ^ m\ high_inv inthall member_bound member_def) + then show ?thesis + by (metis "5.hyps"(2) "5.hyps"(9) Suc_1 Suc_leD True \deg div 2 = n\ \high (summin * 2 ^ n + lx) n < length treeList\ \mi \ x \ x \ ma\ \x = mi\ both_member_options_from_chilf_to_complete_tree dp leD mimapr) + qed + next + case False + hence "?newlist ! (high y n) = treeList !(high y n)" + using "5.hyps"(2) \length treeList = length ?newlist\ assmy nothprolist by presburger + hence "both_member_options (treeList !(high y n)) (low y n)" + using assmy by presburger + moreover have "x \ y" + by (metis "5.hyps"(1) "5.hyps"(4) "5.hyps"(9) \invar_vebt (treeList ! summin) n\ \x < 2 ^ deg\ \x = mi\ calculation deg_not_0 exp_split_high_low(1) mimapr not_less_iff_gr_or_eq) + moreover have "high y n < length ?newlist" using assmy by blast + moreover hence "high y n < length treeList" + using \length treeList = length ?newlist\ by presburger + ultimately show ?thesis + by (metis One_nat_def Suc_leD \deg div 2 = n\ both_member_options_from_chilf_to_complete_tree dp numerals(2)) + qed + qed + ultimately show ?thesis + using aaaa by fastforce + qed + qed + moreover have "(x \ y \ both_member_options (Node (Some (mi, ma)) deg treeList summary) y)\ + both_member_options ?delsimp y" + proof- + assume assm: "x \ y \ both_member_options (Node (Some (mi, ma)) deg treeList summary) y" + hence abcv:"y = mi \ y = ma \ ( high y n < length treeList \ both_member_options (treeList ! (high y n)) (low y n))" + by (metis Suc_1 \deg div 2 = n\ add_leD1 both_member_options_from_complete_tree_to_child member_inv plus_1_eq_Suc tvalid valid_member_both_member_options) + thus " both_member_options ?delsimp y" + proof- + have "y = mi \ ?thesis" + using \x = mi\ assm by blast + moreover have " y = ma \ ?thesis" + by (smt (z3) Suc_1 Suc_le_D both_member_options_def dp membermima.simps(4)) + moreover have " ( high y n < length treeList \ both_member_options (treeList ! (high y n)) (low y n)) + \ ?thesis" + proof- + assume myass: "( high y n < length treeList \ both_member_options (treeList ! (high y n)) (low y n)) " + thus ?thesis + proof(cases "high y n = ?h") + case True + then show ?thesis + proof(cases "low y n = ?l") + case True + then show ?thesis + by (smt (z3) "5.hyps"(3) "5.hyps"(4) Suc_1 \deg div 2 = n\ \length treeList = length (treeList [high (summin * 2 ^ n + lx) n := vebt_delete (treeList ! high (summin * 2 ^ n + lx) n) (low (summin * 2 ^ n + lx) n)])\ add_Suc_right add_leD1 bit_split_inv both_member_options_def both_member_options_from_chilf_to_complete_tree dp membermima.simps(4) myass nth_list_update_neq plus_1_eq_Suc) + next + case False + hence "low y n \ ?l" by simp + hence pp:"?newlist ! ?h = ?newnode" + using hprolist by blast + hence "invar_vebt (treeList ! ?h) n" + by (metis "5.IH"(1) \high ?xn n < length treeList\ inthall member_def) + hence "both_member_options ?newnode (low y n)" + by (metis "5.IH"(1) True \high ?xn n < length treeList\ \low y n \ low ?xn n\ in_set_member inthall myass) + then show ?thesis + by (metis One_nat_def Suc_leD True \deg div 2 = n\ \high (summin * 2 ^ n + lx) n < length treeList\ \length treeList = length ?newlist\ both_member_options_from_chilf_to_complete_tree dp numerals(2) pp) + qed + next + case False + have pp:"?newlist ! (high y n) = treeList ! (high y n)" + using nothprolist[of "high y n"] False "5.hyps"(2) myass by presburger + then show ?thesis + by (metis One_nat_def Suc_leD \deg div 2 = n\ \length treeList = length ?newlist\ abcv both_member_options_from_chilf_to_complete_tree calculation(1) calculation(2) dp numerals(2)) + qed + qed + then show ?thesis + using abcv calculation(1) calculation(2) by fastforce + qed + qed + ultimately show ?thesis by metis + qed + qed + qed + qed +qed + +end + +corollary "invar_vebt t n \ both_member_options t x \ x \ y \ both_member_options (vebt_delete t y) x" + using dele_bmo_cont_corr by blast + +corollary "invar_vebt t n \ both_member_options t x \ \ both_member_options (vebt_delete t x) x " + by (simp add: dele_bmo_cont_corr) + +corollary "invar_vebt t n \ both_member_options (vebt_delete t y) x \ both_member_options t x \ x \ y" + using dele_bmo_cont_corr by blast + +end +end diff --git a/thys/Van_Emde_Boas_Trees/VEBT_DeleteBounds.thy b/thys/Van_Emde_Boas_Trees/VEBT_DeleteBounds.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/VEBT_DeleteBounds.thy @@ -0,0 +1,1700 @@ +(*by Ammer*) +theory VEBT_DeleteBounds imports VEBT_Bounds VEBT_Delete VEBT_DeleteCorrectness +begin + +subsection \Running Time Bounds for Deletion\ + +context begin +interpretation VEBT_internal . + +fun T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e::"VEBT \ nat \ nat" where + "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Leaf a b) 0 = 1"| + "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Leaf a b) (Suc 0) = 1"| + "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Leaf a b) (Suc (Suc n)) = 1"| + "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node None deg treeList summary) _ = 1"| + "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) 0 treeList summary) x = 1"| + "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) (Suc 0) treeList summary) x =1 "| + "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x = 3 + ( + if (x < mi \ x > ma) then 1 + else 3 + (if (x = mi \ x = ma) then 3 + else 13 + ( if x = mi then T\<^sub>m\<^sub>i\<^sub>n\<^sub>t summary + T\<^sub>m\<^sub>i\<^sub>n\<^sub>t (treeList ! the (vebt_mint summary))+ 7 else 1 )+ + (if x = mi then 1 else 1) + + ( let xn = (if x = mi + then the (vebt_mint summary) * 2^(deg div 2) + the (vebt_mint (treeList ! the (vebt_mint summary))) + else x); + minn = (if x = mi then xn else mi); + l = low xn (deg div 2); + h = high xn (deg div 2) in + if h < length treeList + then( 4 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! h) l +( + let newnode = vebt_delete (treeList ! h) l; + newlist = treeList[h:= newnode]in 1 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l newnode + ( + if minNull newnode + then( 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary h + ( + let sn = vebt_delete summary h in + 2+ (if xn = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t sn + (let maxs = vebt_maxt sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (newlist ! the maxs) + ) ) + else 1) + ))else + 2 + (if xn = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (newlist ! h) else 1) + )))else 1 )))" + +end + +context VEBT_internal begin + +lemma tdeletemimi:"deg \ 2 \ T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, mi)) deg treeList summary) x \ 9" + using T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e.simps(7)[of mi mi "deg-2" treeList summary x] + apply(cases "x \ mi") + apply (smt (z3) One_nat_def Suc_1 add_Suc_shift div_le_dividend le_add_diff_inverse not_less_iff_gr_or_eq numeral_3_eq_3 numeral_Bit0 numeral_Bit1_div_2 plus_1_eq_Suc) + apply (smt (z3) Suc3_eq_add_3 Suc_eq_plus1 Suc_nat_number_of_add add_2_eq_Suc dual_order.eq_iff le_add_diff_inverse nat_less_le numeral_Bit1 semiring_norm(2) semiring_norm(8)) + done + +lemma minNull_delete_time_bound: "invar_vebt t n \ minNull (vebt_delete t x) \ T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e t x \ 9" +proof(induction t n rule: invar_vebt.induct) + case (1 a b) + then show ?case + apply(cases x) + apply simp + apply(cases "x=1") + apply simp + by (smt (z3) One_nat_def Suc_diff_le Suc_leI T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e.simps(3) diff_Suc_Suc le_add_diff_inverse one_le_numeral order.not_eq_order_implies_strict plus_1_eq_Suc zero_less_Suc) +next + case (2 treeList n summary m deg) + then show ?case by simp +next + case (3 treeList n summary m deg) + then show ?case by simp +next + case (4 treeList n summary m deg mi ma) + hence "deg \ 2" + by (metis add_self_div_2 deg_not_0 div_greater_zero_iff) + then show ?case + proof(cases "(x < mi \ x > ma)") + case True + then show ?thesis + using "4.prems" \2 \ deg\ delt_out_of_range by force + next + case False + hence "x \ ma \ x \ mi" by simp + then show ?thesis + proof(cases "(x = mi \ x = ma)") + case True + then show ?thesis + using \2 \ deg\ tdeletemimi by blast + next + case False + hence "\ (x = mi \ x = ma)" by simp + then show ?thesis + proof(cases "x = mi") + case True + hence "x = mi" by simp + let ?xn = "the (vebt_mint summary) * 2^(deg div 2) + + the (vebt_mint (treeList ! the (vebt_mint summary)))" + let ?l = "low ?xn (deg div 2)" + let ?h = "high ?xn (deg div 2)" + have "\ y. both_member_options summary y" + using "4.hyps"(4) "4.hyps"(5) "4.hyps"(8) "4.hyps"(9) False True high_bound_aux by blast + then obtain i where aa:" (vebt_mint summary) = Some i" + by (metis "4.hyps"(1) Collect_empty_eq mint_corr_help_empty not_Some_eq set_vebt'_def valid_member_both_member_options) + hence "\ y. both_member_options (treeList ! i ) y" + by (meson "4.hyps"(1) "4.hyps"(5) both_member_options_equiv_member member_bound mint_member) + hence "\ y. both_member_options (treeList ! the (vebt_mint summary) ) y" + using \vebt_mint summary = Some i\ by auto + hence "invar_vebt (treeList ! the (vebt_mint summary)) n" + by (metis "4.IH"(1) "4.hyps"(1) "4.hyps"(2) \vebt_mint summary = Some i\ option.sel member_bound mint_member nth_mem) + then obtain y where "(vebt_mint (treeList ! the (vebt_mint summary))) = Some y" + by (metis Collect_empty_eq \\y. both_member_options (treeList ! the (vebt_mint summary)) y\ mint_corr_help_empty option.exhaust set_vebt'_def valid_member_both_member_options) + have "y < 2^n \ i < 2^m" + using "4.hyps"(1) \vebt_mint (treeList ! the (vebt_mint summary)) = Some y\ \invar_vebt (treeList ! the (vebt_mint summary)) n\ aa member_bound mint_member by blast + hence "?h \ 2^m" using aa + using "4.hyps"(3) "4.hyps"(4) \vebt_mint (treeList ! the (vebt_mint summary)) = Some y\ high_inv by force + have 0:"vebt_delete (Node (Some (mi, ma)) deg treeList summary) x =( + let newnode = vebt_delete (treeList ! ?h) ?l; + newlist = treeList[?h:= newnode]in + if minNull newnode + then( + let sn = vebt_delete summary ?h in + (Node (Some (?xn, if ?xn = ma then (let maxs = vebt_maxt sn in + (if maxs = None + then ?xn + else 2^(deg div 2) * the maxs + + the (vebt_maxt (newlist ! the maxs)) + ) + ) + else ma)) + deg newlist sn) + )else + (Node (Some (?xn, (if ?xn = ma then + ?h * 2^(deg div 2) + the( vebt_maxt (newlist ! ?h)) + else ma))) + deg newlist summary ))" + using del_x_mi[of x mi ma deg ?xn ?h summary treeList ?l] "4.hyps"(2) "4.hyps"(3) + "4.hyps"(4) "4.hyps"(7) False True \2 \ deg\ \vebt_mint (treeList ! the (vebt_mint summary)) = + Some y\ \y < 2 ^ n \ i < 2 ^ m\ aa high_inv + by fastforce + let ?newnode = "vebt_delete (treeList ! ?h) ?l" + let ?newlist = "treeList[?h:= ?newnode]" + show ?thesis + proof(cases "minNull ?newnode") + case True + then show ?thesis + by (smt (z3) "0" "4.prems" minNull.simps(5)) + next + case False + then show ?thesis + by (smt (z3) "0" "4.prems" minNull.simps(5)) + qed + next + case False + hence "x > mi" + using \x \ ma \ mi \ x\ nat_less_le by blast + let ?l = "low x (deg div 2)" + let ?h = "high x (deg div 2)" + let ?newnode = "vebt_delete (treeList ! ?h) ?l" + let ?newlist = "treeList[?h:= ?newnode]" + have "?h < length treeList" + using "4.hyps"(2) "4.hyps"(3) "4.hyps"(4) "4.hyps"(8) \x \ ma \ mi \ x\ high_bound_aux by auto + hence 0:"vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = ( + if minNull ?newnode + then( + let sn = vebt_delete summary ?h in + (Node (Some (mi, if x = ma then (let maxs = vebt_maxt sn in + (if maxs = None + then mi + else 2^(deg div 2) * the maxs + + the (vebt_maxt (?newlist ! the maxs)) + ) + ) + else ma)) + deg ?newlist sn) + )else + (Node (Some (mi, (if x = ma then + ?h * 2^(deg div 2) + the( vebt_maxt (?newlist ! ?h)) + else ma))) + deg ?newlist summary ))" + using del_x_not_mi[of mi x ma deg ?h ?l ?newnode ?newlist treeList summary] + by (metis \2 \ deg\ \mi < x\ \x \ ma \ mi \ x\ del_x_not_mi leD) + then show ?thesis + proof(cases " minNull ?newnode ") + case True + then show ?thesis + by (metis "0" "4.prems" minNull.simps(5)) + next + case False + then show ?thesis + using "0" "4.prems" by fastforce + qed + qed + qed + qed +next + case (5 treeList n summary m deg mi ma) + hence "deg \ 2" + by (metis Suc_1 add_mono_thms_linordered_semiring(1) le_add1 plus_1_eq_Suc set_n_deg_not_0) + then show ?case + proof(cases "(x < mi \ x > ma)") + case True + then show ?thesis + using "5.prems" \2 \ deg\ delt_out_of_range by force + next + case False + hence "x \ ma \ x \ mi" by simp + then show ?thesis + proof(cases "(x = mi \ x = ma)") + case True + then show ?thesis + using \2 \ deg\ tdeletemimi by blast + next + case False + hence "\ (x = mi \ x = ma)" by simp + then show ?thesis + proof(cases "x = mi") + case True + hence "x = mi" by simp + let ?xn = "the (vebt_mint summary) * 2^(deg div 2) + + the (vebt_mint (treeList ! the (vebt_mint summary)))" + let ?l = "low ?xn (deg div 2)" + let ?h = "high ?xn (deg div 2)" + have "\ y. both_member_options summary y" + using "5.hyps"(4) "5.hyps"(5) "5.hyps"(8) "5.hyps"(9) False True high_bound_aux by blast + then obtain i where aa:" (vebt_mint summary) = Some i" + by (metis "5.hyps"(1) Collect_empty_eq mint_corr_help_empty not_Some_eq set_vebt'_def valid_member_both_member_options) + hence "\ y. both_member_options (treeList ! i ) y" + by (meson "5.hyps"(1) "5.hyps"(5) both_member_options_equiv_member member_bound mint_member) + hence "\ y. both_member_options (treeList ! the (vebt_mint summary) ) y" + using \vebt_mint summary = Some i\ by auto + hence "invar_vebt (treeList ! the (vebt_mint summary)) n" + by (metis "5.IH"(1) "5.hyps"(1) "5.hyps"(2) \vebt_mint summary = Some i\ option.sel member_bound mint_member nth_mem) + then obtain y where "(vebt_mint (treeList ! the (vebt_mint summary))) = Some y" + by (metis Collect_empty_eq \\y. both_member_options (treeList ! the (vebt_mint summary)) y\ mint_corr_help_empty option.exhaust set_vebt'_def valid_member_both_member_options) + have "y < 2^n \ i < 2^m" + using "5.hyps"(1) \vebt_mint (treeList ! the (vebt_mint summary)) = Some y\ \invar_vebt (treeList ! the (vebt_mint summary)) n\ aa member_bound mint_member by blast + hence "?h \ 2^m" using aa + using "5.hyps"(3) "5.hyps"(4) \vebt_mint (treeList ! the (vebt_mint summary)) = Some y\ high_inv by force + have 0:"vebt_delete (Node (Some (mi, ma)) deg treeList summary) x =( + let newnode = vebt_delete (treeList ! ?h) ?l; + newlist = treeList[?h:= newnode]in + if minNull newnode + then( + let sn = vebt_delete summary ?h in + (Node (Some (?xn, if ?xn = ma then (let maxs = vebt_maxt sn in + (if maxs = None + then ?xn + else 2^(deg div 2) * the maxs + + the (vebt_maxt (newlist ! the maxs)) + ) + ) + else ma)) + deg newlist sn) + )else + (Node (Some (?xn, (if ?xn = ma then + ?h * 2^(deg div 2) + the( vebt_maxt (newlist ! ?h)) + else ma))) + deg newlist summary )) " + using del_x_mi[of x mi ma deg ?xn ?h summary treeList ?l] "5.hyps"(2) "5.hyps"(3) + "5.hyps"(4) "5.hyps"(7) False True \2 \ deg\ \vebt_mint (treeList ! the (vebt_mint summary + )) = Some y\ \y < 2 ^ n \ i < 2 ^ m\ aa high_inv + by fastforce + let ?newnode = "vebt_delete (treeList ! ?h) ?l" + let ?newlist = "treeList[?h:= ?newnode]" + show ?thesis + proof(cases "minNull ?newnode") + case True + then show ?thesis + by (smt (z3) "0" "5.prems" minNull.simps(5)) + next + case False + then show ?thesis + by (smt (z3) "0" "5.prems" minNull.simps(5)) + qed + next + case False + hence "x > mi" + using \x \ ma \ mi \ x\ nat_less_le by blast + let ?l = "low x (deg div 2)" + let ?h = "high x (deg div 2)" + let ?newnode = "vebt_delete (treeList ! ?h) ?l" + let ?newlist = "treeList[?h:= ?newnode]" + have "x <2^deg" + using "5.hyps"(8) \x \ ma \ mi \ x\ dual_order.strict_trans2 by blast + hence "?h < 2^m" using "5.prems" \2 \ deg\ \mi < x\ \x \ ma \ mi \ x\ + del_in_range minNull.simps(5) verit_comp_simplify1(3) apply simp + by (smt (z3) minNull.simps(5)) + hence 0:"vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = ( + if minNull ?newnode + then( + let sn = vebt_delete summary ?h in + (Node (Some (mi, if x = ma then (let maxs = vebt_maxt sn in + (if maxs = None + then mi + else 2^(deg div 2) * the maxs + + the (vebt_maxt (?newlist ! the maxs)) + ) + ) + else ma)) + deg ?newlist sn) + )else + (Node (Some (mi, (if x = ma then + ?h * 2^(deg div 2) + the( vebt_maxt (?newlist ! ?h)) + else ma))) + deg ?newlist summary ))" using del_x_not_mi[of mi x ma deg ?h ?l ?newnode ?newlist treeList summary] + by (metis "5.hyps"(2) \2 \ deg\ \mi < x\ \x \ ma \ mi \ x\ del_x_not_mi leD) + then show ?thesis + proof(cases " minNull ?newnode ") + case True + then show ?thesis + by (metis "0" "5.prems" minNull.simps(5)) + next + case False + then show ?thesis + using "0" "5.prems" by fastforce + qed + qed + qed + qed +qed + +lemma delete_bound_height: "invar_vebt t n \ T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e t x \ (1+ height t)*70" +proof(induction t n arbitrary: x rule: invar_vebt.induct) + case (1 a b) + then show ?case + apply(cases x) + apply simp + apply(cases "x = 1") + apply simp + apply (metis One_nat_def Suc_eq_plus1_left Suc_le_mono T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e.simps(3) comm_monoid_mult_class.mult_1 dual_order.trans height.simps(1) le_SucE lessI less_Suc_eq_le less_imp_Suc_add one_le_numeral zero_less_Suc) + done +next + case (2 treeList n summary m deg) + then show ?case by simp +next + case (3 treeList n summary m deg) + then show ?case by simp +next + case (4 treeList n summary m deg mi ma) + hence deggy: "deg \ 2" + by (metis add_self_div_2 deg_not_0 div_greater_zero_iff) + then show ?case + proof(cases " (x < mi \ x > ma)") + case True + hence " T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x = 4" using + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e.simps(7)[of mi ma "deg-2" treeList summary x] + by (smt (z3) Suc3_eq_add_3 Suc_1 \2 \ deg\ add_2_eq_Suc' le_add_diff_inverse2 numeral_code(2)) + then show ?thesis using T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e.simps(7)[of mi ma "deg-2" treeList summary x] by auto + next + case False + hence "mi \ x \ x \ ma" by simp + hence 0: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x = 3+3 + (if (x = mi \ x = ma) then 3 + else 13 + ( if x = mi then T\<^sub>m\<^sub>i\<^sub>n\<^sub>t summary + T\<^sub>m\<^sub>i\<^sub>n\<^sub>t (treeList ! the (vebt_mint summary))+ 7 else 1 )+ + (if x = mi then 1 else 1) + + ( let xn = (if x = mi + then the (vebt_mint summary) * 2^(deg div 2) + the (vebt_mint (treeList ! the (vebt_mint summary))) + else x); + minn = (if x = mi then xn else mi); + l = low xn (deg div 2); + h = high xn (deg div 2) in + if h < length treeList + then( 4 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! h) l +( + let newnode = vebt_delete (treeList ! h) l; + newlist = treeList[h:= newnode]in 1 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l newnode + ( + if minNull newnode + then( 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary h + ( + let sn = vebt_delete summary h in + 2+ (if xn = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t sn + (let maxs = vebt_maxt sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (newlist ! the maxs) + ) ) + else 1) + ))else + 2 + (if xn = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (newlist ! h) else 1) + )))else 1 ))" using T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e.simps(7)[of mi ma "deg-2" treeList summary x] deggy + by (smt (z3) False add.commute add_2_eq_Suc' add_numeral_left le_add_diff_inverse numeral_plus_numeral) + then show ?thesis + proof(cases " (x = mi \ x = ma)") + case True + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x = 9" using 0 by simp + then show ?thesis by simp + next + case False + hence 1: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x =3+3 +13+ + (if x = mi then T\<^sub>m\<^sub>i\<^sub>n\<^sub>t summary + T\<^sub>m\<^sub>i\<^sub>n\<^sub>t (treeList ! the (vebt_mint summary))+ 7 else 1 )+ + (if x = mi then 1 else 1) + + (let xn = (if x = mi + then the (vebt_mint summary) * 2^(deg div 2) + the (vebt_mint (treeList ! the (vebt_mint summary))) + else x); + minn = (if x = mi then xn else mi); + l = low xn (deg div 2); + h = high xn (deg div 2) in + if h < length treeList + then( 4 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! h) l +( + let newnode = vebt_delete (treeList ! h) l; + newlist = treeList[h:= newnode]in 1 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l newnode + ( + if minNull newnode + then( 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary h + ( + let sn = vebt_delete summary h in + 2+ (if xn = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t sn + (let maxs = vebt_maxt sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (newlist ! the maxs) + ) ) + else 1) + ))else + 2 + (if xn = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (newlist ! h) else 1) + )))else 1 )" using 0 + by (simp add: False) + then show ?thesis + proof(cases "x = mi") + case True + let ?xn = " the (vebt_mint summary) * 2^(deg div 2) + the (vebt_mint (treeList ! the (vebt_mint summary)))" + have 2: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x =3+3 +13+ T\<^sub>m\<^sub>i\<^sub>n\<^sub>t summary + + T\<^sub>m\<^sub>i\<^sub>n\<^sub>t (treeList ! the (vebt_mint summary))+ 7+1 + + (let l = low ?xn (deg div 2); + h = high ?xn (deg div 2) in + if h < length treeList + then( 4 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! h) l +( + let newnode = vebt_delete (treeList ! h) l; + newlist = treeList[h:= newnode]in 1 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l newnode + ( + if minNull newnode + then( 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary h + ( + let sn = vebt_delete summary h in + 2+ (if ?xn = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t sn + (let maxs = vebt_maxt sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (newlist ! the maxs) + ) ) else 1) ))else + 2 + (if ?xn = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (newlist ! h) else 1) + )))else 1 )" + using 1 by (smt (z3) True add.assoc) + let ?l = "low ?xn (deg div 2)" + let ?h = "high ?xn (deg div 2)" + have 3: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x = 3+3 +13+ T\<^sub>m\<^sub>i\<^sub>n\<^sub>t summary + + T\<^sub>m\<^sub>i\<^sub>n\<^sub>t (treeList ! the (vebt_mint summary))+ 7+1 + + (if ?h < length treeList + then( 4 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l +( + let newnode = vebt_delete (treeList ! ?h) ?l; + newlist = treeList[?h:= newnode]in 1 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l newnode + ( + if minNull newnode + then( 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + ( + let sn = vebt_delete summary ?h in + 2+ (if ?xn = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t sn + (let maxs = vebt_maxt sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (newlist ! the maxs) + ) ) else 1) ))else + 2 + (if ?xn = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (newlist ! ?h) else 1) + )))else 1 )" + using 2 by meson + then show ?thesis + proof(cases "?h < length treeList") + case True + hence "?h < length treeList" by simp + let ?newnode = "vebt_delete (treeList ! ?h) ?l" + let ?newlist = "treeList[?h:= ?newnode]" + have "invar_vebt (treeList ! ?h) n" + using "4.IH"(1) True nth_mem by blast + hence "invar_vebt ?newnode n" + using delete_pres_valid by blast + have 4: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 37 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l +( + let newnode = vebt_delete (treeList ! ?h) ?l; + newlist = treeList[?h:= newnode]in 1 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l newnode + ( + if minNull newnode + then( 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + ( + let sn = vebt_delete summary ?h in + 2+ (if ?xn = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t sn + (let maxs = vebt_maxt sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (newlist ! the maxs) + ) ) else 1) ))else + 2 + (if ?xn = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (newlist ! ?h) else 1) + ))" + using 3 mint_bound[of "treeList ! the (vebt_mint summary)"] mint_bound[of "summary"] + by simp + hence 5: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 38 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l +( + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l ?newnode + ( + if minNull ?newnode + then( 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + ( + let sn = vebt_delete summary ?h in + 2+ (if ?xn = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t sn + (let maxs = vebt_maxt sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the maxs) + ) ) else 1) ))else + 2 + (if ?xn = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! ?h) else 1) + ))" + by (smt (z3) Suc_eq_plus1 add.commute add_Suc numeral_plus_one semiring_norm(5) semiring_norm(8)) + then show ?thesis + proof(cases "minNull ?newnode ") + case True + hence 6: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 39 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l + + 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + ( + let sn = vebt_delete summary ?h in + 2+ (if ?xn = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t sn + (let maxs = vebt_maxt sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the maxs) + ) ) else 1))" using 5 minNull_bound[of ?newnode] by presburger + have 7: " T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l \ 9" using True + minNull_delete_time_bound[of "treeList ! ?h"] + using \invar_vebt (treeList ! high (the (vebt_mint summary) * 2 ^ (deg div 2) + the (vebt_mint (treeList ! the (vebt_mint summary)))) (deg div 2)) n\ by blast + let ?sn = "vebt_delete summary ?h" + have 8: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 39 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l + + 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + ( + 2+ (if ?xn = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t ?sn + (let maxs = vebt_maxt ?sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the maxs) + ) ) else 1))" + by (meson "6") + hence 9: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 39 + 9 + 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + 2+ + (if ?xn = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t ?sn + (let maxs = vebt_maxt ?sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the maxs) + ) ) else 1)" using 6 7 by force + hence 10: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 51 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + + (if ?xn = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t ?sn + (let maxs = vebt_maxt ?sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the maxs) + ) ) else 1)" by simp + then show ?thesis + proof(cases "?xn = ma") + case True + hence 10: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 51 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + + 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t ?sn + (let maxs = vebt_maxt ?sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the maxs) + ))" using 10 + by (smt (z3) add.assoc trans_le_add1) + hence 11: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 55 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + + (let maxs = vebt_maxt ?sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the maxs) + ))" using maxt_bound[of ?sn] by force + then show ?thesis + proof(cases " vebt_maxt ?sn") + case None + hence 12: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 57 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h" using 11 by simp + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 57 + (1+height summary)*70" using "4.IH"(2)[of ?l] + by (meson "4.IH"(2) le_trans nat_add_left_cancel_le) + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 57 + (height (Node (Some (mi, ma)) deg treeList summary))*70" + using height_compose_summary[of summary "Some (mi, ma)" deg treeList] by presburger + then show ?thesis by simp + next + case (Some a) + hence 12: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 55 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + + 1+ 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the (vebt_maxt ?sn))" + using "11" by fastforce + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 67 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h " + using maxt_bound[of "?newlist ! the (vebt_maxt ?sn)"] by linarith + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 67 + (1+ height summary)*70" + by (meson "4.IH"(2) le_trans nat_add_left_cancel_le) + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 67 + (height (Node (Some (mi, ma)) deg treeList summary) )*70" + using height_compose_summary[of summary "Some (mi, ma)" deg treeList] by presburger + then show ?thesis by simp + qed + next + case False + hence 11: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 52 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h " + using 10 by simp + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 52 + (1+ height summary)*70" + by (meson "4.IH"(2) le_trans nat_add_left_cancel_le) + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ + 52 + (height (Node (Some (mi, ma)) deg treeList summary) )*70" using height_compose_summary[of summary "Some (mi, ma)" deg treeList ] + by (meson add_mono_thms_linordered_semiring(2) le_refl mult_le_mono order_trans) + then show ?thesis by simp + qed + next + case False + hence 6: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 38 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l +( + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l ?newnode + 2 + (if ?xn = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! ?h) else 1))" using 5 by simp + moreover have "invar_vebt (?newlist ! ?h) n" + by (simp add: True \invar_vebt (vebt_delete (treeList ! high (the (vebt_mint summary) * 2 ^ (deg div 2) + the (vebt_mint (treeList ! the (vebt_mint summary)))) (deg div 2)) (low (the (vebt_mint summary) * 2 ^ (deg div 2) + the (vebt_mint (treeList ! the (vebt_mint summary)))) (deg div 2))) n\) + ultimately have "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ + 43 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l + (if ?xn = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! ?h) else 1)" + using minNull_bound[of ?newnode] by linarith + moreover have " (if ?xn = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! ?h) else 1) \ 9" + apply(cases "?xn = ma") using maxt_bound[of " (?newlist ! ?h) "] by simp+ + ultimately have "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 55 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l" by force + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ + 55 + (1 + height (treeList ! ?h))*70" + by (meson "4.IH"(1) True le_trans nat_add_left_cancel_le nth_mem) + moreover have "treeList ! ?h \ set treeList" + using True nth_mem by blast + ultimately have "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ + 55 + (height (Node (Some (mi, ma)) deg treeList summary))*70" + using height_compose_child[of "treeList ! ?h" treeList "Some (mi, ma)" deg summary] by presburger + then show ?thesis by simp + qed + next + case False + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x = 3+3 +13+ T\<^sub>m\<^sub>i\<^sub>n\<^sub>t summary + + T\<^sub>m\<^sub>i\<^sub>n\<^sub>t (treeList ! the (vebt_mint summary))+ 7+1 +1" using 3 by simp + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 34" using + mint_bound[of "treeList ! the (vebt_mint summary)"] + mint_bound[of "summary"] by simp + then show ?thesis by simp + qed + next + case False + let ?l = "low x (deg div 2)" + let ?h = "high x (deg div 2)" + have 2: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x =3+3 +13+1 +1 + + (let l = low x (deg div 2); + h = high x (deg div 2) in + if h < length treeList + then( 4 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! h) l +( + let newnode = vebt_delete (treeList ! h) l; + newlist = treeList[h:= newnode]in 1 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l newnode + ( + if minNull newnode + then( 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary h + ( + let sn = vebt_delete summary h in + 2+ (if x = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t sn + (let maxs = vebt_maxt sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (newlist ! the maxs) + ) ) else 1) ))else + 2 + (if x = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (newlist ! h) else 1) + )))else 1 )" + using 1 False by simp + hence 3: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x = 21+( + if ?h < length treeList + then( 4 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l +( + let newnode = vebt_delete (treeList ! ?h) ?l; + newlist = treeList[?h:= newnode]in 1 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l newnode + ( + if minNull newnode + then( 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + ( + let sn = vebt_delete summary ?h in + 2+ (if x = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t sn + (let maxs = vebt_maxt sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (newlist ! the maxs) + ) ) else 1) ))else + 2 + (if x = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (newlist ! ?h) else 1) + )))else 1 )" + apply auto by metis + then show ?thesis + proof(cases "?h < length treeList") + case True + hence "?h < length treeList" by simp + let ?newnode = "vebt_delete (treeList ! ?h) ?l" + let ?newlist = "treeList[?h:= ?newnode]" + have "invar_vebt (treeList ! ?h) n" + using "4.IH"(1) True nth_mem by blast + hence "invar_vebt ?newnode n" + using delete_pres_valid by blast + hence 4: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x = 21+ 4 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l + + 1 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l ?newnode + ( + if minNull ?newnode + then( 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + ( + let sn = vebt_delete summary ?h in + 2+ (if x = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t sn + (let maxs = vebt_maxt sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the maxs) + ) ) else 1) ))else + 2 + (if x = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! ?h) else 1))" + using 3 mint_bound[of "treeList ! the (vebt_mint summary)"] mint_bound[of "summary"] + by (smt (z3) True add.assoc) + hence 5: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 26 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l + + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l ?newnode + ( + if minNull ?newnode + then( 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + ( + let sn = vebt_delete summary ?h in + 2+ (if x = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t sn + (let maxs = vebt_maxt sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the maxs) + ) ) else 1) ))else + 2 + (if x = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! ?h) else 1))" by force + then show ?thesis + proof(cases "minNull ?newnode ") + case True + hence 6: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 29 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l + + 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + ( + let sn = vebt_delete summary ?h in + 2+ (if x = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t sn + (let maxs = vebt_maxt sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the maxs) + ) ) else 1))" using 5 minNull_bound[of ?newnode] by force + have 7: " T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l \ 9" using True + minNull_delete_time_bound[of "treeList ! ?h"] + using \invar_vebt (treeList ! high x (deg div 2)) n\ by blast + let ?sn = "vebt_delete summary ?h" + have 8: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 29 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l + + 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + ( + 2+ (if x = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t ?sn + (let maxs = vebt_maxt ?sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the maxs) + ) ) else 1))" + by (meson "6") + hence 9: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 29 + 9 + 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + 2+ + (if x = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t ?sn + (let maxs = vebt_maxt ?sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the maxs) + ) ) else 1)" + using 6 7 by force + hence 10: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 41 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + + (if x = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t ?sn + (let maxs = vebt_maxt ?sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the maxs) + ) ) else 1)" + by simp + then show ?thesis + proof(cases "x = ma") + case True + hence 10: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 41 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + + 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t ?sn + (let maxs = vebt_maxt ?sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the maxs) + ))" + using 10 by (smt (z3) add.assoc trans_le_add1) + hence 11: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 45 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + + (let maxs = vebt_maxt ?sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the maxs) + ))" + using maxt_bound[of ?sn] by force + then show ?thesis + proof(cases " vebt_maxt ?sn") + case None + hence 12: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 47 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h" using 11 by simp + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 47 + (1+height summary)*70" using "4.IH"(2)[of ?l] + by (meson "4.IH"(2) le_trans nat_add_left_cancel_le) + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 47 + (height (Node (Some (mi, ma)) deg treeList summary))*70" + using height_compose_summary[of summary "Some (mi, ma)" deg treeList] by presburger + then show ?thesis by simp + next + case (Some a) + hence 12: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 45 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + + 1+ 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the (vebt_maxt ?sn))" + using "11" by fastforce + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 57 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h " + using maxt_bound[of "?newlist ! the (vebt_maxt ?sn)"] by linarith + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 57 + (1+ height summary)*70" + by (meson "4.IH"(2) le_trans nat_add_left_cancel_le) + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 57 + (height (Node (Some (mi, ma)) deg treeList summary) )*70" + using height_compose_summary[of summary "Some (mi, ma)" deg treeList] by presburger + then show ?thesis by simp + qed + next + case False + hence 11: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 42 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h " + using 10 by simp + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 42 + (1+ height summary)*70" + by (meson "4.IH"(2) le_trans nat_add_left_cancel_le) + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ + 42 + (height (Node (Some (mi, ma)) deg treeList summary) )*70" using height_compose_summary[of summary "Some (mi, ma)" deg treeList ] + by (meson add_mono_thms_linordered_semiring(2) le_refl mult_le_mono order_trans) + then show ?thesis by simp + qed + next + case False + hence 6: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 26 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l +( + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l ?newnode + 2 + (if x = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! ?h) else 1))" using 5 by simp + moreover have "invar_vebt (?newlist ! ?h) n" + by (simp add: True \invar_vebt (vebt_delete (treeList ! high x (deg div 2)) (low x (deg div 2))) n\) + ultimately have "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ + 29 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l + (if x = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! ?h) else 1)" + using minNull_bound[of ?newnode] by linarith + moreover have " (if x = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! ?h) else 1) \ 9" + apply(cases "x = ma") using maxt_bound[of " (?newlist ! ?h) "] by simp+ + ultimately have "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ + 38 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l" by force + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ + 38 + (1 + height (treeList ! ?h))*70" + by (meson "4.IH"(1) True le_trans nat_add_left_cancel_le nth_mem) + moreover have "treeList ! ?h \ set treeList" + using True nth_mem by blast + ultimately have "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ + 38 + (height (Node (Some (mi, ma)) deg treeList summary))*70" + using height_compose_child[of "treeList ! ?h" treeList "Some (mi, ma)" deg summary] by presburger + then show ?thesis by simp + qed + next + case False + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x = 21+1" using 3 by simp + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 22" using + mint_bound[of "treeList ! the (vebt_mint summary)"] + mint_bound[of "summary"] by simp + then show ?thesis by simp + qed + qed + qed + qed +next + case (5 treeList n summary m deg mi ma) + hence deggy: "deg \ 2" + by (metis Suc_1 add_mono_thms_linordered_semiring(1) le_add1 plus_1_eq_Suc set_n_deg_not_0) + then show ?case + proof(cases " (x < mi \ x > ma)") + case True + hence " T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x = 4" using + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e.simps(7)[of mi ma "deg-2" treeList summary x] + by (smt (z3) Suc3_eq_add_3 Suc_1 \2 \ deg\ add_2_eq_Suc' le_add_diff_inverse2 numeral_code(2)) + then show ?thesis using T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e.simps(7)[of mi ma "deg-2" treeList summary x] by auto + next + case False + hence "mi \ x \ x \ ma" by simp + hence 0: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x = 3+3 + (if (x = mi \ x = ma) then 3 + else 13 + ( if x = mi then T\<^sub>m\<^sub>i\<^sub>n\<^sub>t summary + T\<^sub>m\<^sub>i\<^sub>n\<^sub>t (treeList ! the (vebt_mint summary))+ 7 else 1 )+ + (if x = mi then 1 else 1) + + ( let xn = (if x = mi + then the (vebt_mint summary) * 2^(deg div 2) + the (vebt_mint (treeList ! the (vebt_mint summary))) + else x); + minn = (if x = mi then xn else mi); + l = low xn (deg div 2); + h = high xn (deg div 2) in + if h < length treeList + then( 4 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! h) l +( + let newnode = vebt_delete (treeList ! h) l; + newlist = treeList[h:= newnode]in 1 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l newnode + ( + if minNull newnode + then( 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary h + ( + let sn = vebt_delete summary h in + 2+ (if xn = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t sn + (let maxs = vebt_maxt sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (newlist ! the maxs) + ) ) + else 1) + ))else + 2 + (if xn = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (newlist ! h) else 1) + )))else 1 ))" using T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e.simps(7)[of mi ma "deg-2" treeList summary x] deggy + by (smt (z3) False add.commute add_2_eq_Suc' add_numeral_left le_add_diff_inverse numeral_plus_numeral) + then show ?thesis + proof(cases " (x = mi \ x = ma)") + case True + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x = 9" using 0 by simp + then show ?thesis by simp + next + case False + hence 1: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x =3+3 +13+ + ( if x = mi then T\<^sub>m\<^sub>i\<^sub>n\<^sub>t summary + T\<^sub>m\<^sub>i\<^sub>n\<^sub>t (treeList ! the (vebt_mint summary))+ 7 else 1 )+ + (if x = mi then 1 else 1) + + ( let xn = (if x = mi + then the (vebt_mint summary) * 2^(deg div 2) + the (vebt_mint (treeList ! the (vebt_mint summary))) + else x); + minn = (if x = mi then xn else mi); + l = low xn (deg div 2); + h = high xn (deg div 2) in + if h < length treeList + then( 4 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! h) l +( + let newnode = vebt_delete (treeList ! h) l; + newlist = treeList[h:= newnode]in 1 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l newnode + ( + if minNull newnode + then( 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary h + ( + let sn = vebt_delete summary h in + 2+ (if xn = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t sn + (let maxs = vebt_maxt sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (newlist ! the maxs) + ) ) + else 1) + ))else + 2 + (if xn = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (newlist ! h) else 1) + )))else 1 )" using 0 + by (simp add: False) + then show ?thesis + proof(cases "x = mi") + case True + let ?xn = " the (vebt_mint summary) * 2^(deg div 2) + the (vebt_mint (treeList ! the (vebt_mint summary)))" + have 2: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x =3+3 +13+ T\<^sub>m\<^sub>i\<^sub>n\<^sub>t summary + + T\<^sub>m\<^sub>i\<^sub>n\<^sub>t (treeList ! the (vebt_mint summary))+ 7+1 + + (let l = low ?xn (deg div 2); + h = high ?xn (deg div 2) in + if h < length treeList + then( 4 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! h) l +( + let newnode = vebt_delete (treeList ! h) l; + newlist = treeList[h:= newnode]in 1 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l newnode + ( + if minNull newnode + then( 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary h + ( + let sn = vebt_delete summary h in + 2+ (if ?xn = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t sn + (let maxs = vebt_maxt sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (newlist ! the maxs) + ) ) else 1) ))else + 2 + (if ?xn = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (newlist ! h) else 1) + )))else 1 )" + using 1 by (smt (z3) True add.assoc) + let ?l = "low ?xn (deg div 2)" + let ?h = "high ?xn (deg div 2)" + have 3: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x = 3+3 +13+ T\<^sub>m\<^sub>i\<^sub>n\<^sub>t summary + + T\<^sub>m\<^sub>i\<^sub>n\<^sub>t (treeList ! the (vebt_mint summary))+ 7+1 + + (if ?h < length treeList + then( 4 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l +( + let newnode = vebt_delete (treeList ! ?h) ?l; + newlist = treeList[?h:= newnode]in 1 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l newnode + ( + if minNull newnode + then( 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + ( + let sn = vebt_delete summary ?h in + 2+ (if ?xn = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t sn + (let maxs = vebt_maxt sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (newlist ! the maxs) + ) ) else 1) ))else + 2 + (if ?xn = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (newlist ! ?h) else 1) + )))else 1 )" + using 2 by meson + then show ?thesis + proof(cases "?h < length treeList") + case True + hence "?h < length treeList" by simp + let ?newnode = "vebt_delete (treeList ! ?h) ?l" + let ?newlist = "treeList[?h:= ?newnode]" + have "invar_vebt (treeList ! ?h) n" + using "5.IH"(1) True nth_mem by blast + hence "invar_vebt ?newnode n" + using delete_pres_valid by blast + have 4: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 37 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l +( + let newnode = vebt_delete (treeList ! ?h) ?l; + newlist = treeList[?h:= newnode]in 1 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l newnode + ( + if minNull newnode + then( 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + ( + let sn = vebt_delete summary ?h in + 2+ (if ?xn = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t sn + (let maxs = vebt_maxt sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (newlist ! the maxs) + ) ) else 1) ))else + 2 + (if ?xn = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (newlist ! ?h) else 1) + ))" + using 3 mint_bound[of "treeList ! the (vebt_mint summary)"] mint_bound[of "summary"] + by simp + hence 5: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 38 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l +( + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l ?newnode + ( + if minNull ?newnode + then( 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + ( + let sn = vebt_delete summary ?h in + 2+ (if ?xn = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t sn + (let maxs = vebt_maxt sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the maxs) + ) ) else 1) ))else + 2 + (if ?xn = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! ?h) else 1) + ))" + by (smt (z3) Suc_eq_plus1 add.commute add_Suc numeral_plus_one semiring_norm(5) semiring_norm(8)) + then show ?thesis + proof(cases "minNull ?newnode ") + case True + hence 6: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 39 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l + + 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + ( + let sn = vebt_delete summary ?h in + 2+ (if ?xn = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t sn + (let maxs = vebt_maxt sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the maxs) + ) ) else 1))" using 5 minNull_bound[of ?newnode] by presburger + have 7: " T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l \ 9" using True + minNull_delete_time_bound[of "treeList ! ?h"] + using \invar_vebt (treeList ! high (the (vebt_mint summary) * 2 ^ (deg div 2) + the (vebt_mint (treeList ! the (vebt_mint summary)))) (deg div 2)) n\ by blast + let ?sn = "vebt_delete summary ?h" + have 8: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 39 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l + + 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + ( + 2+ (if ?xn = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t ?sn + (let maxs = vebt_maxt ?sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the maxs) + ) ) else 1))" + by (meson "6") + hence 9: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 39 + 9 + 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + 2+ + (if ?xn = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t ?sn + (let maxs = vebt_maxt ?sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the maxs) + ) ) else 1)" + using 6 7 by force + hence 10: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 51 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + + (if ?xn = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t ?sn + (let maxs = vebt_maxt ?sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the maxs) + ) ) else 1)" + by simp + then show ?thesis + proof(cases "?xn = ma") + case True + hence 10: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 51 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + + 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t ?sn + (let maxs = vebt_maxt ?sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the maxs) + ))" + using 10 by (smt (z3) add.assoc trans_le_add1) + hence 11: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 55 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + + (let maxs = vebt_maxt ?sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the maxs) + ))" + using maxt_bound[of ?sn] by force + then show ?thesis + proof(cases " vebt_maxt ?sn") + case None + hence 12: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 57 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h" using 11 by simp + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 57 + (1+height summary)*70" using "5.IH"(2)[of ?l] + by (meson "5.IH"(2) le_trans nat_add_left_cancel_le) + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 57 + (height (Node (Some (mi, ma)) deg treeList summary))*70" + using height_compose_summary[of summary "Some (mi, ma)" deg treeList] by presburger + then show ?thesis by simp + next + case (Some a) + hence 12: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 55 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + + 1+ 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the (vebt_maxt ?sn))" + using "11" by fastforce + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 67 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h " + using maxt_bound[of "?newlist ! the (vebt_maxt ?sn)"] by linarith + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 67 + (1+ height summary)*70" + by (meson "5.IH"(2) le_trans nat_add_left_cancel_le) + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 67 + (height (Node (Some (mi, ma)) deg treeList summary) )*70" + using height_compose_summary[of summary "Some (mi, ma)" deg treeList] by presburger + then show ?thesis by simp + qed + next + case False + hence 11: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 52 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h " + using 10 by simp + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 52 + (1+ height summary)*70" + by (meson "5.IH"(2) le_trans nat_add_left_cancel_le) + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ + 52 + (height (Node (Some (mi, ma)) deg treeList summary) )*70" using height_compose_summary[of summary "Some (mi, ma)" deg treeList ] + by (meson add_mono_thms_linordered_semiring(2) le_refl mult_le_mono order_trans) + then show ?thesis by simp + qed + next + case False + hence 6: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 38 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l +( + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l ?newnode + 2 + (if ?xn = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! ?h) else 1))" using 5 by simp + moreover have "invar_vebt (?newlist ! ?h) n" + by (simp add: True \invar_vebt (vebt_delete (treeList ! high (the (vebt_mint summary) * 2 ^ (deg div 2) + the (vebt_mint (treeList ! the (vebt_mint summary)))) (deg div 2)) (low (the (vebt_mint summary) * 2 ^ (deg div 2) + the (vebt_mint (treeList ! the (vebt_mint summary)))) (deg div 2))) n\) + ultimately have "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ + 43 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l + (if ?xn = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! ?h) else 1)" + using minNull_bound[of ?newnode] by linarith + moreover have " (if ?xn = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! ?h) else 1) \ 9" + apply(cases "?xn = ma") using maxt_bound[of " (?newlist ! ?h) "] by simp+ + ultimately have "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 55 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l" by force + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ + 55 + (1 + height (treeList ! ?h))*70" + by (meson "5.IH"(1) True le_trans nat_add_left_cancel_le nth_mem) + moreover have "treeList ! ?h \ set treeList" + using True nth_mem by blast + ultimately have "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ + 55 + (height (Node (Some (mi, ma)) deg treeList summary))*70" + using height_compose_child[of "treeList ! ?h" treeList "Some (mi, ma)" deg summary] by presburger + then show ?thesis by simp + qed + next + case False + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x = 3+3 +13+ T\<^sub>m\<^sub>i\<^sub>n\<^sub>t summary + + T\<^sub>m\<^sub>i\<^sub>n\<^sub>t (treeList ! the (vebt_mint summary))+ 7+1 +1" using 3 by simp + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 34" using + mint_bound[of "treeList ! the (vebt_mint summary)"] + mint_bound[of "summary"] by simp + then show ?thesis by simp + qed + next + case False + let ?l = "low x (deg div 2)" + let ?h = "high x (deg div 2)" + have 2: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x =3+3 +13+1 +1 + + (let l = low x (deg div 2); + h = high x (deg div 2) in + if h < length treeList + then( 4 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! h) l +( + let newnode = vebt_delete (treeList ! h) l; + newlist = treeList[h:= newnode]in 1 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l newnode + ( + if minNull newnode + then( 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary h + ( + let sn = vebt_delete summary h in + 2+ (if x = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t sn + (let maxs = vebt_maxt sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (newlist ! the maxs) + ) ) else 1) ))else + 2 + (if x = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (newlist ! h) else 1) + )))else 1 )" using 1 False by simp + hence 3: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x = 21+( + if ?h < length treeList + then( 4 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l +( + let newnode = vebt_delete (treeList ! ?h) ?l; + newlist = treeList[?h:= newnode]in 1 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l newnode + ( + if minNull newnode + then( 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + ( + let sn = vebt_delete summary ?h in + 2+ (if x = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t sn + (let maxs = vebt_maxt sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (newlist ! the maxs) + ) ) else 1) ))else + 2 + (if x = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (newlist ! ?h) else 1) + )))else 1 )" apply auto by metis + then show ?thesis + proof(cases "?h < length treeList") + case True + hence "?h < length treeList" by simp + let ?newnode = "vebt_delete (treeList ! ?h) ?l" + let ?newlist = "treeList[?h:= ?newnode]" + have "invar_vebt (treeList ! ?h) n" + using "5.IH"(1) True nth_mem by blast + hence "invar_vebt ?newnode n" + using delete_pres_valid by blast + hence 4: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x = 21+ 4 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l + + 1 + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l ?newnode + ( + if minNull ?newnode + then( 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + ( + let sn = vebt_delete summary ?h in + 2+ (if x = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t sn + (let maxs = vebt_maxt sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the maxs) + ) ) else 1) ))else + 2 + (if x = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! ?h) else 1))" using 3 mint_bound[of "treeList ! the (vebt_mint summary)"] + mint_bound[of "summary"] by (smt (z3) True add.assoc) + hence 5: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 26 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l + + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l ?newnode + ( + if minNull ?newnode + then( 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + ( + let sn = vebt_delete summary ?h in + 2+ (if x = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t sn + (let maxs = vebt_maxt sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the maxs) + ) ) else 1) ))else + 2 + (if x = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! ?h) else 1))" by force + then show ?thesis + proof(cases "minNull ?newnode ") + case True + hence 6: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 29 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l + + 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + ( + let sn = vebt_delete summary ?h in + 2+ (if x = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t sn + (let maxs = vebt_maxt sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the maxs) + ) ) else 1))" + using 5 minNull_bound[of ?newnode] by force + have 7: " T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l \ 9" using True + minNull_delete_time_bound[of "treeList ! ?h"] + using \invar_vebt (treeList ! high x (deg div 2)) n\ by blast + let ?sn = "vebt_delete summary ?h" + have 8: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 29 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l + + 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + ( + 2+ (if x = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t ?sn + (let maxs = vebt_maxt ?sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the maxs) + ) ) else 1))" + by (meson "6") + hence 9: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 29 + 9 + 1 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + 2+ + (if x = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t ?sn + (let maxs = vebt_maxt ?sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the maxs) + ) ) else 1)" + using 6 7 by force + hence 10: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 41 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + + (if x = ma then 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t ?sn + (let maxs = vebt_maxt ?sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the maxs) + ) ) else 1)" + by simp + then show ?thesis + proof(cases "x = ma") + case True + hence 10: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 41 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + + 1 + T\<^sub>m\<^sub>a\<^sub>x\<^sub>t ?sn + (let maxs = vebt_maxt ?sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the maxs) + ))" + using 10 by (smt (z3) add.assoc trans_le_add1) + hence 11: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 45 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + + (let maxs = vebt_maxt ?sn in + 1 + (if maxs = None + then 1 + else 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the maxs) + ))" + using maxt_bound[of ?sn] by force + then show ?thesis + proof(cases " vebt_maxt ?sn") + case None + hence 12: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 47 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h" using 11 by simp + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 47 + (1+height summary)*70" using "5.IH"(2)[of ?l] + by (meson "5.IH"(2) le_trans nat_add_left_cancel_le) + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 47 + (height (Node (Some (mi, ma)) deg treeList summary))*70" + using height_compose_summary[of summary "Some (mi, ma)" deg treeList] by presburger + then show ?thesis by simp + next + case (Some a) + hence 12: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 45 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h + + 1+ 8+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! the (vebt_maxt ?sn))" + using "11" by fastforce + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 57 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h " + using maxt_bound[of "?newlist ! the (vebt_maxt ?sn)"] by linarith + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 57 + (1+ height summary)*70" + by (meson "5.IH"(2) le_trans nat_add_left_cancel_le) + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 57 + (height (Node (Some (mi, ma)) deg treeList summary) )*70" + using height_compose_summary[of summary "Some (mi, ma)" deg treeList] by presburger + then show ?thesis by simp + qed + next + case False + hence 11: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 42 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e summary ?h " + using 10 by simp + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 42 + (1+ height summary)*70" + by (meson "5.IH"(2) le_trans nat_add_left_cancel_le) + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ + 42 + (height (Node (Some (mi, ma)) deg treeList summary) )*70" + using height_compose_summary[of summary "Some (mi, ma)" deg treeList ] + by (meson add_mono_thms_linordered_semiring(2) le_refl mult_le_mono order_trans) + then show ?thesis by simp + qed + next + case False + hence 6: "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 26 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l +( + T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l ?newnode + 2 + (if x = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! ?h) else 1))" using 5 by simp + moreover have "invar_vebt (?newlist ! ?h) n" + by (simp add: True \invar_vebt (vebt_delete (treeList ! high x (deg div 2)) (low x (deg div 2))) n\) + ultimately have "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ + 29 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l + (if x = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! ?h) else 1)" + using minNull_bound[of ?newnode] by linarith + moreover have " (if x = ma then 6+ T\<^sub>m\<^sub>a\<^sub>x\<^sub>t (?newlist ! ?h) else 1) \ 9" + apply(cases "x = ma") using maxt_bound[of " (?newlist ! ?h) "] by simp+ + ultimately have "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ + 38 + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (treeList ! ?h) ?l" by force + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ + 38 + (1 + height (treeList ! ?h))*70" + by (meson "5.IH"(1) True le_trans nat_add_left_cancel_le nth_mem) + moreover have "treeList ! ?h \ set treeList" + using True nth_mem by blast + ultimately have "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ + 38 + (height (Node (Some (mi, ma)) deg treeList summary))*70" + using height_compose_child[of "treeList ! ?h" treeList "Some (mi, ma)" deg summary] + by presburger + then show ?thesis by simp + qed + next + case False + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x = 21+1" using 3 by simp + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e (Node (Some (mi, ma)) deg treeList summary) x \ 22" using + mint_bound[of "treeList ! the (vebt_mint summary)"] + mint_bound[of "summary"] by simp + then show ?thesis by simp + qed + qed + qed + qed +qed + +theorem delete_bound_size_univ: "invar_vebt t n \ u = 2^n \ T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e t x \ 140 + 70 * lb (lb u)" + using delete_bound_height[of t n x] height_double_log_univ_size[of u n t] by simp + +fun T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e'::"VEBT \ nat \ nat" where + "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' (Leaf a b) 0 = 1"| + "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' (Leaf a b) (Suc 0) = 1"| + "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' (Leaf a b) (Suc (Suc n)) = 1"| + "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' (Node None deg treeList summary) _ = 1"| + "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' (Node (Some (mi, ma)) 0 treeList summary) x = 1"| + "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' (Node (Some (mi, ma)) (Suc 0) treeList summary) x =1 "| + "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' (Node (Some (mi, ma)) deg treeList summary) x = ( + if (x < mi \ x > ma) then 1 + else if (x = mi \ x = ma) then 1 + else ( let xn = (if x = mi + then the (vebt_mint summary) * 2^(deg div 2) + the (vebt_mint (treeList ! the (vebt_mint summary))) + else x); + minn = (if x = mi then xn else mi); + l = low xn (deg div 2); + h = high xn (deg div 2) in + if h < length treeList + then( T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' (treeList ! h) l +( + let newnode = vebt_delete (treeList ! h) l; + newlist = treeList[h:= newnode]in + if minNull newnode + then T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' summary h + else 1 + ))else 1 ))" + + +lemma tdeletemimi':"deg \ 2 \ T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' (Node (Some (mi, mi)) deg treeList summary) x \ 1" + using T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e'.simps(7)[of mi mi "deg-2" treeList summary x] + apply(cases "x \ mi") + apply (metis add_2_eq_Suc' le_add_diff_inverse2 le_eq_less_or_eq linorder_neqE_nat) + by (metis add_2_eq_Suc' eq_imp_le le_add_diff_inverse2) + +lemma minNull_delete_time_bound': "invar_vebt t n \ minNull (vebt_delete t x) \ T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' t x \ 1" +proof(induction t n rule: invar_vebt.induct) + case (1 a b) + then show ?case + by (metis T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e'.simps(1) T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e'.simps(2) T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e'.simps(3) vebt_buildup.cases order_refl) +next + case (4 treeList n summary m deg mi ma) + hence "deg \ 2" + by (metis add_self_div_2 deg_not_0 div_greater_zero_iff) + then show ?case + proof(cases "(x < mi \ x > ma)") + case True + then show ?thesis + using "4.prems" \2 \ deg\ delt_out_of_range by force + next + case False + hence "x \ ma \ x \ mi" by simp + then show ?thesis + proof(cases "(x = mi \ x = ma)") + case True + then show ?thesis + using \2 \ deg\ tdeletemimi' by blast + next + case False + hence "\ (x = mi \ x = ma)" by simp + then show ?thesis + proof(cases "x = mi") + case True + hence "x = mi" by simp + let ?xn = "the (vebt_mint summary) * 2^(deg div 2) + + the (vebt_mint (treeList ! the (vebt_mint summary)))" + let ?l = "low ?xn (deg div 2)" + let ?h = "high ?xn (deg div 2)" + have "\ y. both_member_options summary y" + using "4.hyps"(4) "4.hyps"(5) "4.hyps"(8) "4.hyps"(9) False True high_bound_aux by blast + then obtain i where aa:" (vebt_mint summary) = Some i" + by (metis "4.hyps"(1) Collect_empty_eq mint_corr_help_empty not_Some_eq set_vebt'_def valid_member_both_member_options) + hence "\ y. both_member_options (treeList ! i ) y" + by (meson "4.hyps"(1) "4.hyps"(5) both_member_options_equiv_member member_bound mint_member) + hence "\ y. both_member_options (treeList ! the (vebt_mint summary) ) y" + using \vebt_mint summary = Some i\ by auto + hence "invar_vebt (treeList ! the (vebt_mint summary)) n" + by (metis "4.IH"(1) "4.hyps"(1) "4.hyps"(2) \vebt_mint summary = Some i\ option.sel member_bound mint_member nth_mem) + then obtain y where "(vebt_mint (treeList ! the (vebt_mint summary))) = Some y" + by (metis Collect_empty_eq \\y. both_member_options (treeList ! the (vebt_mint summary)) y\ mint_corr_help_empty option.exhaust set_vebt'_def valid_member_both_member_options) + have "y < 2^n \ i < 2^m" + using "4.hyps"(1) \vebt_mint (treeList ! the (vebt_mint summary)) = Some y\ \invar_vebt (treeList ! the (vebt_mint summary)) n\ aa member_bound mint_member by blast + hence "?h \ 2^m" using aa + using "4.hyps"(3) "4.hyps"(4) \vebt_mint (treeList ! the (vebt_mint summary)) = Some y\ high_inv by force + have 0:"vebt_delete (Node (Some (mi, ma)) deg treeList summary) x =( + let newnode = vebt_delete (treeList ! ?h) ?l; + newlist = treeList[?h:= newnode]in + if minNull newnode + then( + let sn = vebt_delete summary ?h in + (Node (Some (?xn, if ?xn = ma then (let maxs = vebt_maxt sn in + (if maxs = None + then ?xn + else 2^(deg div 2) * the maxs + + the (vebt_maxt (newlist ! the maxs)) + ) ) + else ma)) + deg newlist sn) + )else + (Node (Some (?xn, (if ?xn = ma then + ?h * 2^(deg div 2) + the( vebt_maxt (newlist ! ?h)) + else ma))) + deg newlist summary )) + " using del_x_mi[of x mi ma deg ?xn ?h summary treeList ?l] + using "4.hyps"(2) "4.hyps"(3) "4.hyps"(4) "4.hyps"(7) False True \2 \ deg\ \vebt_mint (treeList ! the (vebt_mint summary)) = Some y\ \y < 2 ^ n \ i < 2 ^ m\ aa high_inv by fastforce + let ?newnode = "vebt_delete (treeList ! ?h) ?l" + let ?newlist = "treeList[?h:= ?newnode]" + show ?thesis + proof(cases "minNull ?newnode") + case True + then show ?thesis + by (smt (z3) "0" "4.prems" minNull.simps(5)) + next + case False + then show ?thesis + by (smt (z3) "0" "4.prems" minNull.simps(5)) + qed + next + case False + hence "x > mi" + using \x \ ma \ mi \ x\ nat_less_le by blast + let ?l = "low x (deg div 2)" + let ?h = "high x (deg div 2)" + let ?newnode = "vebt_delete (treeList ! ?h) ?l" + let ?newlist = "treeList[?h:= ?newnode]" + have "?h < length treeList" + using "4.hyps"(2) "4.hyps"(3) "4.hyps"(4) "4.hyps"(8) \x \ ma \ mi \ x\ high_bound_aux by auto + hence 0:"vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = ( + if minNull ?newnode + then( + let sn = vebt_delete summary ?h in + (Node (Some (mi, if x = ma then (let maxs = vebt_maxt sn in + (if maxs = None + then mi + else 2^(deg div 2) * the maxs + + the (vebt_maxt (?newlist ! the maxs)) + ) + ) + else ma)) + deg ?newlist sn) + )else + (Node (Some (mi, (if x = ma then + ?h * 2^(deg div 2) + the( vebt_maxt (?newlist ! ?h)) + else ma))) + deg ?newlist summary ))" using del_x_not_mi[of mi x ma deg ?h ?l ?newnode ?newlist treeList summary] + by (metis \2 \ deg\ \mi < x\ \x \ ma \ mi \ x\ del_x_not_mi leD) + + then show ?thesis + proof(cases " minNull ?newnode ") + case True + then show ?thesis + by (metis "0" "4.prems" minNull.simps(5)) + next + case False + then show ?thesis + using "0" "4.prems" by fastforce + qed + qed + qed + qed +next + case (5 treeList n summary m deg mi ma) + hence "deg \ 2" + by (metis Suc_1 add_mono_thms_linordered_semiring(1) le_add1 plus_1_eq_Suc set_n_deg_not_0) + then show ?case + proof(cases "(x < mi \ x > ma)") + case True + then show ?thesis + using "5.prems" \2 \ deg\ delt_out_of_range by force + next + case False + hence "x \ ma \ x \ mi" by simp + then show ?thesis + proof(cases "(x = mi \ x = ma)") + case True + then show ?thesis + using \2 \ deg\ tdeletemimi' by blast + next + case False + hence "\ (x = mi \ x = ma)" by simp + then show ?thesis + proof(cases "x = mi") + case True + hence "x = mi" by simp + let ?xn = "the (vebt_mint summary) * 2^(deg div 2) + + the (vebt_mint (treeList ! the (vebt_mint summary)))" + let ?l = "low ?xn (deg div 2)" + let ?h = "high ?xn (deg div 2)" + have "\ y. both_member_options summary y" + using "5.hyps"(4) "5.hyps"(5) "5.hyps"(8) "5.hyps"(9) False True high_bound_aux by blast + then obtain i where aa:" (vebt_mint summary) = Some i" + by (metis "5.hyps"(1) Collect_empty_eq mint_corr_help_empty not_Some_eq set_vebt'_def valid_member_both_member_options) + hence "\ y. both_member_options (treeList ! i ) y" + by (meson "5.hyps"(1) "5.hyps"(5) both_member_options_equiv_member member_bound mint_member) + hence "\ y. both_member_options (treeList ! the (vebt_mint summary) ) y" + using \vebt_mint summary = Some i\ by auto + hence "invar_vebt (treeList ! the (vebt_mint summary)) n" + by (metis "5.IH"(1) "5.hyps"(1) "5.hyps"(2) \vebt_mint summary = Some i\ option.sel member_bound mint_member nth_mem) + then obtain y where "(vebt_mint (treeList ! the (vebt_mint summary))) = Some y" + by (metis Collect_empty_eq \\y. both_member_options (treeList ! the (vebt_mint summary)) y\ mint_corr_help_empty option.exhaust set_vebt'_def valid_member_both_member_options) + have "y < 2^n \ i < 2^m" + using "5.hyps"(1) \vebt_mint (treeList ! the (vebt_mint summary)) = Some y\ \invar_vebt (treeList ! the (vebt_mint summary)) n\ aa member_bound mint_member by blast + hence "?h \ 2^m" using aa + using "5.hyps"(3) "5.hyps"(4) \vebt_mint (treeList ! the (vebt_mint summary)) = Some y\ high_inv by force + have 0:"vebt_delete (Node (Some (mi, ma)) deg treeList summary) x =( + let newnode = vebt_delete (treeList ! ?h) ?l; + newlist = treeList[?h:= newnode]in + if minNull newnode + then( + let sn = vebt_delete summary ?h in + (Node (Some (?xn, if ?xn = ma then (let maxs = vebt_maxt sn in + (if maxs = None + then ?xn + else 2^(deg div 2) * the maxs + + the (vebt_maxt (newlist ! the maxs)) + ) + ) + else ma)) + deg newlist sn) + )else + (Node (Some (?xn, (if ?xn = ma then + ?h * 2^(deg div 2) + the( vebt_maxt (newlist ! ?h)) + else ma))) + deg newlist summary )) + " using del_x_mi[of x mi ma deg ?xn ?h summary treeList ?l] + using "5.hyps"(2) "5.hyps"(3) "5.hyps"(4) "5.hyps"(7) False True \2 \ deg\ \vebt_mint (treeList ! the (vebt_mint summary)) = Some y\ \y < 2 ^ n \ i < 2 ^ m\ aa high_inv by fastforce + let ?newnode = "vebt_delete (treeList ! ?h) ?l" + let ?newlist = "treeList[?h:= ?newnode]" + show ?thesis + proof(cases "minNull ?newnode") + case True + then show ?thesis + by (smt (z3) "0" "5.prems" minNull.simps(5)) + next + case False + then show ?thesis + by (smt (z3) "0" "5.prems" minNull.simps(5)) + qed + next + case False + hence "x > mi" + using \x \ ma \ mi \ x\ nat_less_le by blast + let ?l = "low x (deg div 2)" + let ?h = "high x (deg div 2)" + let ?newnode = "vebt_delete (treeList ! ?h) ?l" + let ?newlist = "treeList[?h:= ?newnode]" + have "x <2^deg" + using "5.hyps"(8) \x \ ma \ mi \ x\ dual_order.strict_trans2 by blast + hence "?h < 2^m" using "5.prems" \2 \ deg\ \mi < x\ \x \ ma \ mi \ x\ + del_in_range minNull.simps(5) verit_comp_simplify1(3) apply simp + by (smt (z3) minNull.simps(5)) + hence 0:"vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = ( + if minNull ?newnode + then( + let sn = vebt_delete summary ?h in + (Node (Some (mi, if x = ma then (let maxs = vebt_maxt sn in + (if maxs = None + then mi + else 2^(deg div 2) * the maxs + + the (vebt_maxt (?newlist ! the maxs)) + ) + ) + else ma)) + deg ?newlist sn) + )else + (Node (Some (mi, (if x = ma then + ?h * 2^(deg div 2) + the( vebt_maxt (?newlist ! ?h)) + else ma))) + deg ?newlist summary ))" using del_x_not_mi[of mi x ma deg ?h ?l ?newnode ?newlist treeList summary] + by (metis "5.hyps"(2) \2 \ deg\ \mi < x\ \x \ ma \ mi \ x\ del_x_not_mi leD) + then show ?thesis + proof(cases " minNull ?newnode ") + case True + then show ?thesis + by (metis "0" "5.prems" minNull.simps(5)) + next + case False + then show ?thesis + using "0" "5.prems" by fastforce + qed + qed + qed + qed +qed simp+ + + +lemma delete_bound_height': "invar_vebt t n \ T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' t x \ 1+ height t" +proof(induction t n arbitrary: x rule: invar_vebt.induct) + case (1 a b) + then show ?case + apply(cases "x \ 0") + apply simp + apply(cases "x = 1") + apply simp + using T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e'.simps(3)[of a b "x-2"] height.simps(1)[of a b] + by (metis One_nat_def T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e'.simps(3) vebt_buildup.cases lessI less_Suc_eq_le plus_1_eq_Suc) +next + case (4 treeList n summary m deg mi ma) + hence "deg \2" + by (metis Suc_leI add_2_eq_Suc' add_Suc_shift add_le_mono deg_not_0 numeral_2_eq_2) + then show ?case + proof(cases "(x < mi \ x > ma)") + case True + then show ?thesis + by (metis One_nat_def Suc_1 T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e'.simps(7) \2 \ deg\ add_leD2 vebt_buildup.cases le_add1 lessI not_less plus_1_eq_Suc) + next + case False + hence miama:"mi \ x \ x \ ma" by simp + then show ?thesis + proof(cases "x = mi \ x = ma") + case True + then show ?thesis using T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e'.simps(7)[of mi ma "deg-2" treeList summary x] \2 \ deg\ tdeletemimi' trans_le_add1 by blast + next + case False + let ?xn = "(if x = mi + then the (vebt_mint summary) * 2^(deg div 2) + the (vebt_mint (treeList ! the (vebt_mint summary))) + else x)" + let ?minn = "(if x = mi then ?xn else mi)" + let ?l = "low ?xn (deg div 2)" + let ?h = "high ?xn (deg div 2)" + have 0:"T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' (Node (Some (mi, ma)) deg treeList summary) x = (if ?h < length treeList + then( T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' (treeList ! ?h) ?l +( + let newnode = vebt_delete (treeList ! ?h) ?l; + newlist = treeList[?h:= newnode]in + if minNull newnode + then T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' summary ?h + else 1 + ))else 1)" + using T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e'.simps(7)[of mi ma "deg-2" treeList summary x] \2 \ deg\ False miama + by (smt (z3) add_2_eq_Suc le_add_diff_inverse not_less) + then show ?thesis + proof(cases "?h< length treeList") + case True + let ?newnode = "vebt_delete (treeList ! ?h) ?l" + let ?newlist = "treeList[?h:= ?newnode]" + have 1:"T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' (Node (Some (mi, ma)) deg treeList summary) x = + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' (treeList ! ?h) ?l +( + if minNull ?newnode + then T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' summary ?h + else 1 )" using 0 True by simp + then show ?thesis + proof(cases "minNull ?newnode") + case True + hence " T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' (treeList ! ?h) ?l \ 1" + by (metis "0" "1" "4.IH"(1) minNull_delete_time_bound' nat_le_iff_add nth_mem) + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' (Node (Some (mi, ma)) deg treeList summary) x \ 1+ T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' summary ?h" using 1 True by auto + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' (Node (Some (mi, ma)) deg treeList summary) x \ 1+1+ height summary" using 4(2)[of ?h] by simp + then show ?thesis + using order_trans by fastforce + next + case False + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' (Node (Some (mi, ma)) deg treeList summary) x = + 1+ T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' (treeList ! ?h) ?l " using 1 by simp + moreover have 2:" (treeList ! ?h) \set treeList" + by (meson True nth_mem) + ultimately have "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' (Node (Some (mi, ma)) deg treeList summary) x \ 1 + 1+ height (treeList ! ?h)" + using 4(1) by simp + then show ?thesis + by (smt (z3) "2" Suc_eq_plus1_left Suc_le_mono add_2_eq_Suc dual_order.trans height_compose_child nat_1_add_1) + qed + qed (simp add : 0) + qed + qed +next + case (5 treeList n summary m deg mi ma) + hence "deg \2" + by (metis Suc_1 Suc_eq_plus1 add_mono_thms_linordered_semiring(1) le_add2 set_n_deg_not_0) + then show ?case + proof(cases "(x < mi \ x > ma)") + case True + then show ?thesis + by (metis One_nat_def Suc_1 T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e'.simps(7) \2 \ deg\ add_leD2 vebt_buildup.cases le_add1 lessI not_less plus_1_eq_Suc) + next + case False + hence miama:"mi \ x \ x \ ma" by simp + then show ?thesis + proof(cases "x = mi \ x = ma") + case True + then show ?thesis using T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e'.simps(7)[of mi ma "deg-2" treeList summary x] \2 \ deg\ tdeletemimi' trans_le_add1 by blast + next + case False + let ?xn = "(if x = mi + then the (vebt_mint summary) * 2^(deg div 2) + the (vebt_mint (treeList ! the (vebt_mint summary))) + else x)" + let ?minn = "(if x = mi then ?xn else mi)" + let ?l = "low ?xn (deg div 2)" + let ?h = "high ?xn (deg div 2)" + have 0:"T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' (Node (Some (mi, ma)) deg treeList summary) x = (if ?h < length treeList + then( T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' (treeList ! ?h) ?l +( + let newnode = vebt_delete (treeList ! ?h) ?l; + newlist = treeList[?h:= newnode]in + if minNull newnode + then T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' summary ?h + else 1 + ))else 1)" + using T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e'.simps(7)[of mi ma "deg-2" treeList summary x] \2 \ deg\ False miama + by (smt (z3) add_2_eq_Suc le_add_diff_inverse not_less) + then show ?thesis + proof(cases "?h< length treeList") + case True + let ?newnode = "vebt_delete (treeList ! ?h) ?l" + let ?newlist = "treeList[?h:= ?newnode]" + have 1:"T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' (Node (Some (mi, ma)) deg treeList summary) x = + T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' (treeList ! ?h) ?l +( + if minNull ?newnode + then T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' summary ?h + else 1 )" using 0 True by simp + then show ?thesis + proof(cases "minNull ?newnode") + case True + hence " T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' (treeList ! ?h) ?l \ 1" + by (metis "0" "1" "5.IH"(1) minNull_delete_time_bound' nat_le_iff_add nth_mem) + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' (Node (Some (mi, ma)) deg treeList summary) x \ 1+ T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' summary ?h" using 1 True by auto + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' (Node (Some (mi, ma)) deg treeList summary) x \ 1+1+ height summary" using 5(2)[of ?h] by simp + then show ?thesis + using order_trans by fastforce + next + case False + hence "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' (Node (Some (mi, ma)) deg treeList summary) x = + 1+ T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' (treeList ! ?h) ?l " using 1 by simp + moreover have 2:" (treeList ! ?h) \set treeList" + by (meson True nth_mem) + ultimately have "T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' (Node (Some (mi, ma)) deg treeList summary) x \ 1 + 1+ height (treeList ! ?h)" + using 5(1) by simp + then show ?thesis + by (smt (z3) "2" Suc_eq_plus1_left Suc_le_mono add_2_eq_Suc dual_order.trans height_compose_child nat_1_add_1) + qed + qed (simp add : 0) + qed + qed +qed simp+ + +theorem delete_bound_size_univ': "invar_vebt t n \ u = 2^n \ T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e' t x \ 2 + lb (lb u)" + using delete_bound_height'[of t n x] height_double_log_univ_size[of u n t] by simp + +end +end diff --git a/thys/Van_Emde_Boas_Trees/VEBT_DeleteCorrectness.thy b/thys/Van_Emde_Boas_Trees/VEBT_DeleteCorrectness.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/VEBT_DeleteCorrectness.thy @@ -0,0 +1,2265 @@ +(*by Ammer*) +theory VEBT_DeleteCorrectness imports VEBT_Delete +begin + +context VEBT_internal begin + +subsection \Validness Preservation\ + +theorem delete_pres_valid: "invar_vebt t n \ invar_vebt (vebt_delete t x) n" +proof(induction t n arbitrary: x rule: invar_vebt.induct) + case (1 a b) + then show ?case + proof(cases x) + case 0 + then show ?thesis + by (simp add: invar_vebt.intros(1)) + next + case (Suc prex) + hence "x = Suc prex" by simp + then show ?thesis + proof(cases prex) + case 0 + then show ?thesis + by (simp add: Suc invar_vebt.intros(1)) + next + case (Suc preprex) + then show ?thesis + by (simp add: \x = Suc prex\ invar_vebt.intros(1)) + qed + qed +next + case (2 treeList n summary m deg) + then show ?case + using invar_vebt.intros(2) by force +next + case (3 treeList n summary m deg) + then show ?case + using invar_vebt.intros(3) by auto +next + case (4 treeList n summary m deg mi ma) + hence 0: "( \ t \ set treeList. invar_vebt t n)" and 1: " invar_vebt summary m" and 2:"length treeList = 2^m" and 3:" deg = n+m" and + 4: "(\ i < 2^m. (\ y. both_member_options (treeList ! i) y) \ ( both_member_options summary i))" and + 5: "(mi = ma \ (\ t \ set treeList. \ y. both_member_options t y))" and 6:"mi \ ma \ ma < 2^deg" and + 7: "(mi \ ma \ (\ i < 2^m. (high ma n = i \ both_member_options (treeList ! i) (low ma n)) \ + (\ y. (high y n = i \ both_member_options (treeList ! i) (low y n) ) \ mi < y \ y \ ma)))" + and 8: "n = m" and 9: "deg div 2 = n" using "4" add_self_div_2 by auto + hence 10: "invar_vebt (Node (Some (mi, ma)) deg treeList summary) deg" + using invar_vebt.intros(4)[of treeList n summary m deg mi ma] by blast + hence 11:"n \ 1 " and 12: " deg \ 2" + by (metis "1" "8" "9" One_nat_def Suc_leI deg_not_0 div_greater_zero_iff)+ + then show ?case + proof(cases "(x < mi \ x > ma)") + case True + hence "vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = (Node (Some (mi, ma)) deg treeList summary)" + using delt_out_of_range[of x mi ma deg treeList summary] + using "1" "4.hyps"(3) "9" deg_not_0 div_greater_zero_iff by blast + then show ?thesis + by (simp add: "10") + next + case False + hence inrg: "mi\ x \ x \ ma" by simp + then show ?thesis + proof(cases "x = mi \ x = ma") + case True + hence" (\ t \ set treeList. \ y. both_member_options t y)" + using "5" by blast + moreover have "vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = (Node None deg treeList summary)" + using del_single_cont[of x mi ma deg treeList summary] "1" "8" "9" True deg_not_0 div_greater_zero_iff by blast + moreover have " (\ i. both_member_options summary i)" + using "10" True mi_eq_ma_no_ch by blast + ultimately show ?thesis + using "0" "1" "2" "3" "4.hyps"(3) invar_vebt.intros(2) by force + next + case False + hence "x \ mi \ x \ ma" by simp + hence "mi \ ma \ x < 2^deg" + by (metis "6" inrg le_antisym le_less_trans) + hence "7b": "(\ i < 2^m. (high ma n = i \ both_member_options (treeList ! i) (low ma n)) \ + (\ y. (high y n = i \ both_member_options (treeList ! i) (low y n) ) \ mi < y \ y \ ma))" + using "7" by fastforce + hence "both_member_options (treeList ! (high ma n)) (low ma n)" + using "1" "3" "6" "8" deg_not_0 exp_split_high_low(1) by blast + hence yhelper:"both_member_options (treeList ! (high y n)) (low y n) + \ high y n < 2^m \ mi < y \ y \ ma \ low y n < 2^n" for y + by (simp add: "7b" low_def) + then show ?thesis + proof(cases "x \ mi") + case True + hence xnotmi: "x \ mi" by simp + let ?h = "high x n" + let ?l = "low x n" + have hlbound:"?h < 2^m \ ?l < 2^n" + using "1" "3" "8" \mi \ ma \ x < 2 ^ deg\ deg_not_0 exp_split_high_low(1) exp_split_high_low(2) by blast + let ?newnode = "vebt_delete (treeList ! ?h) ?l" + have "treeList ! ?h \ set treeList " + by (metis "2" hlbound in_set_member inthall) + hence nnvalid: "invar_vebt ?newnode n" + by (simp add: "4.IH"(1)) + let ?newlist = "treeList[?h:= ?newnode]" + have hlist:"?newlist ! ?h = ?newnode" + by (simp add: "2" hlbound) + have nothlist:"i \ ?h \ i < 2^m \ ?newlist ! i = treeList ! i" for i by simp + have allvalidinlist:"\ t \ set ?newlist. invar_vebt t n" + proof + fix t + assume "t \ set ?newlist" + then obtain i where "i< 2^m \ ?newlist ! i = t" + by (metis "2" in_set_conv_nth length_list_update) + show "invar_vebt t n" + by (metis "0" "2" \i < 2 ^ m \ treeList[high x n := vebt_delete (treeList ! high x n) (low x n)] ! i = t\ hlist nnvalid nth_list_update_neq nth_mem) + qed + have newlistlength: "length ?newlist = 2^m" using 2 by auto + then show ?thesis + proof(cases "minNull ?newnode") + case True + hence ninNullc: "minNull ?newnode" by simp + let ?sn = "vebt_delete summary ?h" + let ?newma= "(if x = ma then (let maxs = vebt_maxt ?sn in + (if maxs = None + then mi + else 2^(deg div 2) * the maxs + + the (vebt_maxt (?newlist ! the maxs)) + ) + ) + else ma)" + let ?delsimp =" (Node (Some (mi, ?newma)) deg ?newlist ?sn)" + have dsimp:"vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = ?delsimp" + using del_x_not_mi_new_node_nil[of mi x ma deg ?h ?l ?newnode treeList ?sn summary ?newlist] + hlbound 9 11 12 True 2 inrg xnotmi by simp + have newsummvalid: "invar_vebt ?sn m" + by (simp add: "4.IH"(2)) + have 111: "(\ i < 2^m. (\ x. both_member_options (?newlist ! i) x) \ ( both_member_options ?sn i))" + proof + fix i + show " i < 2^m \ ((\ x. both_member_options (?newlist ! i) x) = ( both_member_options ?sn i))" + proof + assume "i < 2^m" + show "(\ x. both_member_options (?newlist ! i) x) = ( both_member_options ?sn i)" + proof(cases "i = ?h") + case True + hence 1000:"?newlist ! i = ?newnode" + using hlist by blast + hence 1001:"\ x. vebt_member (?newlist ! i) x" + by (simp add: min_Null_member ninNullc) + hence 1002: "\ x. both_member_options (?newlist ! i) x" + using "1000" nnvalid valid_member_both_member_options by auto + have 1003: "\ both_member_options ?sn i" + using "1" True dele_bmo_cont_corr by auto + then show ?thesis + using "1002" by blast + next + case False + hence 1000:"?newlist ! i = treeList ! i" + using \i < 2 ^ m\ nothlist by blast + hence "both_member_options (?newlist ! i) y \ both_member_options ?sn i" for y + proof- + assume "both_member_options (?newlist ! i) y" + hence "both_member_options summary i" + using "1000" "4" \i < 2 ^ m\ by auto + thus "both_member_options ?sn i" + using "1" False dele_bmo_cont_corr by blast + qed + moreover have "both_member_options ?sn i \ \ y. both_member_options (?newlist ! i) y" + proof- + assume "both_member_options ?sn i " + hence "both_member_options summary i" + using "1" dele_bmo_cont_corr by auto + thus " \ y. both_member_options (?newlist ! i) y" + using "1000" "4" \i < 2 ^ m\ by presburger + qed + then show ?thesis + using calculation by blast + qed + qed + qed + have 112:" (mi = ?newma \ (\ t \ set ?newlist. \ x. both_member_options t x))" + proof + assume aampt:"mi = ?newma" + show "(\ t \ set ?newlist. \ y. both_member_options t y)" + proof(cases "x = ma") + case True + let ?maxs = "vebt_maxt ?sn" + show ?thesis + proof(cases "?maxs = None") + case True + hence aa:"\ y. vebt_member ?sn y" + using maxt_corr_help_empty newsummvalid set_vebt'_def by auto + hence "\ y. both_member_options ?sn y" + using newsummvalid valid_member_both_member_options by blast + hence "t \ set ?newlist \ \y. both_member_options t y" for t + proof- + assume "t \ set ?newlist" + then obtain i where "?newlist ! i = t \ i< 2^m" + by (metis in_set_conv_nth newlistlength) + thus " \y. both_member_options t y" + using "111" \\y. both_member_options (vebt_delete summary (high x n)) y\ by blast + qed + then show ?thesis by blast + next + case False + then obtain maxs where "Some maxs = ?maxs" + by fastforce + hence "both_member_options summary maxs" + by (metis "1" dele_bmo_cont_corr maxbmo) + have bb:"maxs \ ?h \ maxs < 2^m" + by (metis "1" \Some maxs = vebt_maxt ?sn\ dele_bmo_cont_corr maxbmo member_bound valid_member_both_member_options) + hence "invar_vebt (?newlist ! maxs) n"using 0 "2" by auto + hence "\ y. both_member_options (?newlist ! maxs) y" + using "4" bb \both_member_options summary maxs\ nothlist by presburger + then obtain maxi where "Some maxi = vebt_maxt (?newlist ! maxs)" using + \invar_vebt (treeList[high x n := vebt_delete (treeList ! high x n) (low x n)] ! maxs) n\ + empty_Collect_eq option.sel maxt_corr_help_empty set_vebt'_def valid_member_both_member_options by fastforce + hence "maxs = high mi n \ both_member_options (?newlist ! maxs) (low mi n)" + by (smt (z3) "9" True \Some maxs = vebt_maxt (vebt_delete summary (high x n))\ \invar_vebt (treeList[high x n := vebt_delete (treeList ! high x n) (low x n)] ! maxs) n\ aampt option.sel high_inv low_inv maxbmo member_bound mult.commute option.distinct(1) valid_member_both_member_options) + hence False + by (metis bb nat_less_le nothlist yhelper) + then show ?thesis by simp + qed + next + case False + then show ?thesis + using \mi \ ma \ x < 2 ^ deg\ aampt by presburger + qed + qed + have 114: "?newma < 2^deg \ mi \ ?newma" + proof(cases "x = ma") + case True + hence "x = ma" by simp + let ?maxs = "vebt_maxt ?sn" + show ?thesis + proof(cases "?maxs = None") + case True + then show ?thesis + using "6" by fastforce + next + case False + then obtain maxs where "Some maxs = ?maxs" + by fastforce + hence "both_member_options summary maxs" + by (metis "1" dele_bmo_cont_corr maxbmo) + have bb:"maxs \ ?h \ maxs < 2^m" + by (metis "1" \Some maxs = vebt_maxt ?sn\ dele_bmo_cont_corr maxbmo member_bound valid_member_both_member_options) + hence "invar_vebt (?newlist ! maxs) n"using 0 "2" by auto + hence "\ y. both_member_options (?newlist ! maxs) y" + using "4" bb \both_member_options summary maxs\ nothlist by presburger + then obtain maxi where "Some maxi = vebt_maxt (?newlist ! maxs)" + by (metis \invar_vebt (treeList[high x n := vebt_delete (treeList ! high x n) (low x n)] ! maxs) n\ empty_Collect_eq maxt_corr_help_empty option_shift.elims set_vebt'_def valid_member_both_member_options) + then show ?thesis + by (smt (verit, best) "6" "9" \Some maxs = vebt_maxt (vebt_delete summary (high x n))\ \invar_vebt (?newlist ! maxs) n\ bb option.sel high_inv less_le_trans low_inv maxbmo maxt_member member_bound mult.commute not_less_iff_gr_or_eq nothlist verit_comp_simplify1(3) yhelper) + qed + next + case False + then show ?thesis + using "6" by auto + qed + have 115: "mi \ ?newma \ + (\ i < 2^m. + (high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n)) \ + (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ mi < y \ y \ ?newma))" + proof + assume "mi \ ?newma" + show " (\ i < 2^m. + (high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n)) \ + (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ mi < y \ y \ ?newma))" + proof + fix i + show "i < 2^m \ + (high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n)) \ + (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ mi < y \ y \ ?newma)" + proof + assume assumption:"i < 2^m" + show " (high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n)) \ + (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ mi < y \ y \ ?newma)" + proof- + have "(high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n))" + proof + assume newmaassm: "high ?newma n = i" + thus " both_member_options (?newlist ! i) (low ?newma n)" + proof(cases "x = ma" ) + case True + let ?maxs = "vebt_maxt ?sn" + show ?thesis + proof(cases "?maxs = None") + case True + then show ?thesis + by (smt (z3) "0" \both_member_options (treeList ! high ma n) (low ma n)\ \mi \ (if x = ma then let maxs = vebt_maxt (vebt_delete summary (high x n)) in if maxs = None then mi else 2 ^ (deg div 2) * the maxs + the (vebt_maxt (treeList [high x n := vebt_delete (treeList ! high x n) (low x n)] ! the maxs)) else ma)\ \treeList ! high x n \ set treeList\ bit_split_inv dele_bmo_cont_corr hlist newmaassm nth_list_update_neq) + next + case False + then obtain maxs where "Some maxs = ?maxs" + by fastforce + hence "both_member_options summary maxs" + by (metis "1" dele_bmo_cont_corr maxbmo) + have bb:"maxs \ ?h \ maxs < 2^m" + by (metis "1" \Some maxs = vebt_maxt ?sn\ dele_bmo_cont_corr maxbmo member_bound valid_member_both_member_options) + hence "invar_vebt (?newlist ! maxs) n"using 0 2 by auto + hence "\ y. both_member_options (?newlist ! maxs) y" + using "4" bb \both_member_options summary maxs\ nothlist by presburger + then obtain maxi where "Some maxi = vebt_maxt (?newlist ! maxs)" using + \invar_vebt (treeList[high x n := vebt_delete (treeList ! high x n) (low x n)] ! maxs) n\ + empty_Collect_eq maxt_corr_help_empty set_vebt'_def valid_member_both_member_options + by (smt (z3) VEBT_Member.vebt_member.simps(2) \invar_vebt (treeList[high x n := vebt_delete (treeList ! high x n) (low x n)] ! maxs) n\ vebt_maxt.elims minNull.simps(1) min_Null_member valid_member_both_member_options) + then show ?thesis + by (smt (z3) "9" False True \Some maxs = vebt_maxt (vebt_delete summary (high x n))\ \invar_vebt (treeList[high x n := vebt_delete (treeList ! high x n) (low x n)] ! maxs) n\ option.sel high_inv low_inv maxbmo maxt_member member_bound mult.commute newmaassm) + qed + next + case False + then show ?thesis + by (smt (z3) "0" \both_member_options (treeList ! high ma n) (low ma n)\ \treeList ! high x n \ set treeList\ assumption bit_split_inv dele_bmo_cont_corr hlist newmaassm nothlist) + qed + qed + moreover have " (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ mi < y \ y \ ?newma)" + proof + fix y + show "(high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ mi < y \ y \ ?newma" + proof + assume yassm: "(high y n = i \ both_member_options (?newlist ! i) (low y n) )" + hence "mi < y" + proof(cases "i = ?h") + case True + hence "both_member_options (treeList ! i) (low y n)" + using "0" \treeList ! high x n \ set treeList\ dele_bmo_cont_corr hlist yassm by auto + then show ?thesis + by (simp add: assumption yassm yhelper) + next + case False + then show ?thesis + using assumption nothlist yassm yhelper by presburger + qed + moreover have "y \ ?newma" + proof(cases "x = ma") + case True + hence "x= ma" by simp + let ?maxs = "vebt_maxt ?sn" + show ?thesis + proof(cases "?maxs = None") + case True + then show ?thesis + using \mi \ ?newma\ \x = ma\ by presburger + next + case False + then obtain maxs where "Some maxs = ?maxs" + by fastforce + hence "both_member_options summary maxs" + by (metis "1" dele_bmo_cont_corr maxbmo) + have bb:"maxs \ ?h \ maxs < 2^m" + by (metis "1" \Some maxs = vebt_maxt ?sn\ dele_bmo_cont_corr maxbmo member_bound valid_member_both_member_options) + hence "invar_vebt (?newlist ! maxs) n"using 0 2 by auto + hence "\ y. both_member_options (?newlist ! maxs) y" + using "4" bb \both_member_options summary maxs\ nothlist by presburger + then obtain maxi where "Some maxi = vebt_maxt (?newlist ! maxs)" + by (metis "2" "4.IH"(1) Collect_empty_eq bb both_member_options_equiv_member maxt_corr_help_empty nth_list_update_neq nth_mem option.exhaust set_vebt'_def) + hence "maxs < 2^m \ maxi < 2^n" + by (metis \invar_vebt (?newlist ! maxs) n\ bb maxt_member member_bound) + hence "?newma = 2^n* maxs + maxi" + by (smt (z3) "9" False True \Some maxi = vebt_maxt (?newlist ! maxs)\ \Some maxs = vebt_maxt (vebt_delete summary (high x n))\ option.sel) + hence "low ?newma n = maxi \ high ?newma n = maxs" + by (simp add: \maxs < 2 ^ m \ maxi < 2 ^ n\ high_inv low_inv mult.commute) + hence "both_member_options (treeList ! (high y n)) (low y n)" + by (metis "0" \treeList ! high x n \ set treeList\ assumption dele_bmo_cont_corr hlist nothlist yassm) + hence hleqdraft:"high y n > maxs \ False" + proof- + assume "high y n > maxs" + have "both_member_options summary (high y n)" + using "1" "111" assumption dele_bmo_cont_corr yassm by blast + moreover have "both_member_options ?sn (high y n)" + using "111" assumption yassm by blast + ultimately show False + by (metis \Some maxs = vebt_maxt (vebt_delete summary (high x n))\ \maxs < high y n\ leD maxt_corr_help newsummvalid valid_member_both_member_options) + qed + hence hleqmaxs: "high y n \ maxs" by presburger + then show ?thesis + proof(cases "high y n = maxs") + case True + hence "low y n \ maxi" + by (metis \Some maxi = vebt_maxt (treeList[high x n := vebt_delete (treeList ! high x n) (low x n)] ! maxs)\ \invar_vebt (treeList[high x n := vebt_delete (treeList ! high x n) (low x n)] ! maxs) n\ maxt_corr_help valid_member_both_member_options yassm) + then show ?thesis + by (smt (z3) True \(if x = ma then let maxs = vebt_maxt (vebt_delete summary (high x n)) in if maxs = None then mi else 2 ^ (deg div 2) * the maxs + the (vebt_maxt ((?newlist) ! the maxs)) else ma) = 2 ^ n * maxs + maxi\ add_le_cancel_left bit_concat_def bit_split_inv mult.commute) + next + case False + then show ?thesis + by (metis \low (if x = ma then let maxs = vebt_maxt (vebt_delete summary (high x n)) in if maxs = None then mi else 2 ^ (deg div 2) * the maxs + the (vebt_maxt ((?newlist) ! the maxs)) else ma) n = maxi \ high (if x = ma then let maxs = vebt_maxt (vebt_delete summary (high x n)) in if maxs = None then mi else 2 ^ (deg div 2) * the maxs + the (vebt_maxt ((?newlist) ! the maxs)) else ma) n = maxs\ div_le_mono high_def hleqdraft le_neq_implies_less nat_le_linear) + qed + qed + next + case False + then show ?thesis + by (smt (z3) "0" \treeList ! high x n \ set treeList\ assumption dele_bmo_cont_corr hlist nothlist yassm yhelper) + qed + ultimately show " mi < y \ y \ ?newma" by simp + qed + qed + ultimately show ?thesis by simp + qed + qed + qed + qed + hence 117: "?newma < 2^deg" and 118: "mi \ ?newma" using 114 by auto + have 116: " invar_vebt (Node (Some (mi, ?newma)) deg ?newlist ?sn) deg" + using invar_vebt.intros(4)[of ?newlist n ?sn m deg mi ?newma] + using 3 allvalidinlist newlistlength newsummvalid "4.hyps"(3) 111 112 118 117 115 by fastforce + show ?thesis + using "116" dsimp by presburger + next + case False + hence notemp:"\ z. both_member_options ?newnode z" + using not_min_Null_member by auto + let ?newma = "(if x = ma then + ?h * 2^(deg div 2) + the( vebt_maxt (?newlist ! ?h)) + else ma)" + let ?delsimp =" (Node (Some (mi, ?newma)) deg ?newlist summary)" + have dsimp:"vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = ?delsimp" + using del_x_not_mi_newnode_not_nil[of mi x ma deg ?h ?l ?newnode treeList ?newlist summary] + by (metis "12" "2" "9" False dual_order.eq_iff hlbound inrg order.not_eq_order_implies_strict xnotmi) + have 111: "(\ i < 2^m. (\ x. both_member_options (?newlist ! i) x) \ ( both_member_options summary i))" + proof + fix i + show " i < 2^m \ ((\ x. both_member_options (?newlist ! i) x) = ( both_member_options summary i))" + proof + assume "i < 2^m" + show "(\ x. both_member_options (?newlist ! i) x) = ( both_member_options summary i)" + proof(cases "i = ?h") + case True + hence 1000:"?newlist ! i = ?newnode" + using hlist by blast + hence 1001:"\ x. vebt_member (?newlist ! i) x" + using nnvalid notemp valid_member_both_member_options by auto + hence 1002: "\ x. both_member_options (?newlist ! i) x" + using "1000" notemp by presburger + have 1003: "both_member_options summary i" + using "0" "1000" "1002" "4" True \i < 2 ^ m\ \treeList ! high x n \ set treeList\ dele_bmo_cont_corr by fastforce + then show ?thesis + using "1002" by blast + next + case False + hence 1000:"?newlist ! i = treeList ! i" + using \i < 2 ^ m\ nothlist by blast + then show ?thesis + using "4" \i < 2 ^ m\ by presburger + qed + qed + qed + have 112:" (mi = ?newma \ (\ t \ set ?newlist. \ x. both_member_options t x))" + proof + assume aampt:"mi = ?newma" + show "(\ t \ set ?newlist. \ y. both_member_options t y)" + proof(cases "x = ma") + case True + obtain maxi where " vebt_maxt (?newlist ! ?h) = Some maxi" + by (metis False VEBT_Member.vebt_member.simps(2) hlist vebt_maxt.elims minNull.simps(1) nnvalid notemp valid_member_both_member_options) + hence "both_member_options ?newnode maxi" + using hlist maxbmo by auto + hence "both_member_options (treeList ! ?h) maxi" + using "0" \treeList ! high x n \ set treeList\ dele_bmo_cont_corr by blast + hence False + by (metis "9" True \both_member_options ?newnode maxi\ \vebt_maxt (?newlist ! high x n) = Some maxi\ aampt option.sel high_inv hlbound low_inv member_bound nnvalid not_less_iff_gr_or_eq valid_member_both_member_options yhelper) + then show ?thesis by blast + next + case False + then show ?thesis + using \mi \ ma \ x < 2 ^ deg\ aampt by presburger + qed + qed + have 114: "?newma < 2^deg \ mi \ ?newma" + proof(cases "x = ma") + case True + hence "x = ma" by simp + obtain maxi where " vebt_maxt (?newlist ! ?h) = Some maxi" + by (metis empty_Collect_eq hlist maxt_corr_help_empty nnvalid notemp option.exhaust set_vebt'_def valid_member_both_member_options) + hence "both_member_options ?newnode maxi" + using hlist maxbmo by auto + hence "both_member_options (treeList ! ?h) maxi" + using "0" \treeList ! high x n \ set treeList\ dele_bmo_cont_corr by blast + hence "maxi < 2^n" + using \both_member_options?newnode maxi\ member_bound nnvalid valid_member_both_member_options by blast + show ?thesis + by (smt (z3) "3" "9" Euclidean_Division.div_eq_0_iff True \both_member_options (treeList ! high x n) maxi\ \maxi < 2 ^ n\ \vebt_maxt (?newlist ! high x n) = Some maxi\ add.right_neutral div_exp_eq div_mult_self3 option.sel high_inv hlbound le_0_eq less_imp_le_nat low_inv power_not_zero rel_simps(28) yhelper) + next + case False + then show ?thesis + using "6" by auto + qed + have 115: "mi \ ?newma \ + (\ i < 2^m. + (high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n)) \ + (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ mi < y \ y \ ?newma))" + proof + assume "mi \ ?newma" + show " (\ i < 2^m. + (high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n)) \ + (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ mi < y \ y \ ?newma))" + proof + fix i + show "i < 2^m \ + (high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n)) \ + (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ mi < y \ y \ ?newma)" + proof + assume assumption:"i < 2^m" + show " (high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n)) \ + (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ mi < y \ y \ ?newma)" + proof- + have "(high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n))" + proof + assume newmaassm: "high ?newma n = i" + thus " both_member_options (?newlist ! i) (low ?newma n)" + proof(cases "x = ma") + case True + obtain maxi where "vebt_maxt (?newlist ! ?h) = Some maxi" + by (metis Collect_empty_eq both_member_options_equiv_member hlist maxt_corr_help_empty nnvalid not_Some_eq notemp set_vebt'_def) + hence "both_member_options (?newlist ! ?h) maxi" + using maxbmo by blast + then show ?thesis + by (smt (z3) "9" True \vebt_maxt (?newlist ! high x n) = Some maxi\ option.sel high_inv hlist low_inv maxt_member member_bound newmaassm nnvalid) + next + case False + then show ?thesis + by (smt (z3) "0" \both_member_options (treeList ! high ma n) (low ma n)\ \treeList ! high x n \ set treeList\ assumption bit_split_inv dele_bmo_cont_corr hlist newmaassm nothlist) + qed + qed + moreover have " (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ mi < y \ y \ ?newma)" + proof + fix y + show "(high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ mi < y \ y \ ?newma" + proof + assume yassm: "(high y n = i \ both_member_options (?newlist ! i) (low y n) )" + hence "mi < y" + proof(cases "i = ?h") + case True + hence "both_member_options (treeList ! i) (low y n)" + using "0" \treeList ! high x n \ set treeList\ dele_bmo_cont_corr hlist yassm by auto + then show ?thesis + by (simp add: assumption yassm yhelper) + next + case False + then show ?thesis + using assumption nothlist yassm yhelper by presburger + qed + moreover have "y \ ?newma" + proof(cases "x = ma") + case True + hence "x= ma" by simp + obtain maxi where "vebt_maxt (?newlist ! ?h) = Some maxi" + by (metis Collect_empty_eq both_member_options_equiv_member hlist maxt_corr_help_empty nnvalid not_Some_eq notemp set_vebt'_def) + hence "both_member_options (?newlist ! ?h) maxi" + using maxbmo by blast + have "high y n \ ?h" + by (metis "7b" True assumption div_le_mono high_def nothlist yassm) + then show ?thesis + proof(cases "high y n = ?h") + case True + have "low y n > maxi \ False" + by (metis True \vebt_maxt (?newlist ! ?h) = Some maxi\ hlist leD maxt_corr_help nnvalid valid_member_both_member_options yassm) + then show ?thesis + by (smt (z3) "9" True \vebt_maxt (?newlist ! ?h) = Some maxi\ \x = ma\ add_le_cancel_left div_mult_mod_eq option.sel high_def low_def nat_le_linear nat_less_le) + next + case False + then show ?thesis + by (smt (z3) "9" True \both_member_options (?newlist ! high x n) maxi\ \high y n \ high x n\ \vebt_maxt (?newlist ! high x n) = Some maxi\ div_le_mono option.sel high_def high_inv hlist le_antisym member_bound nat_le_linear nnvalid valid_member_both_member_options) + qed + next + case False + then show ?thesis + by (smt (z3) "0" \treeList ! high x n \ set treeList\ assumption dele_bmo_cont_corr hlist nothlist yassm yhelper) + qed + ultimately show " mi < y \ y \ ?newma" by simp + qed + qed + ultimately show ?thesis by simp + qed + qed + qed + qed + hence 117: "?newma < 2^deg" and 118: "mi \ ?newma" using 114 by auto + have 116: " invar_vebt (Node (Some (mi, ?newma)) deg ?newlist summary) deg" + using invar_vebt.intros(4)[of ?newlist n summary m deg mi ?newma] allvalidinlist + 1 newlistlength 8 3 111 112 117 118 115 by fastforce + then show ?thesis + using dsimp by presburger + qed + next + case False + hence xmi:"x = mi" by simp + have "both_member_options summary (high ma n)" + using "1" "3" "4" "4.hyps"(3) "6" \both_member_options (treeList ! high ma n) (low ma n)\ deg_not_0 exp_split_high_low(1) by blast + hence "vebt_member summary (high ma n)" + using "4.hyps"(1) valid_member_both_member_options by blast + obtain summin where "Some summin = vebt_mint summary" + by (metis "4.hyps"(1) \vebt_member summary (high ma n)\ empty_Collect_eq mint_corr_help_empty not_None_eq set_vebt'_def) + hence "\ z . both_member_options (treeList ! summin) z" + by (metis "4.hyps"(1) "4.hyps"(5) both_member_options_equiv_member member_bound mint_member) + moreover have "invar_vebt (treeList ! summin) n" + by (metis "0" "1" "2" \Some summin = vebt_mint summary\ member_bound mint_member nth_mem) + ultimately obtain lx where "Some lx = vebt_mint (treeList ! summin)" + by (metis empty_Collect_eq mint_corr_help_empty not_None_eq set_vebt'_def valid_member_both_member_options) + let ?xn = "summin*2^n + lx" + have "?xn = (if x = mi + then the (vebt_mint summary) * 2^(deg div 2) + + the (vebt_mint (treeList ! the (vebt_mint summary))) + else x)" + by (metis False \Some lx = vebt_mint (treeList ! summin)\ \Some summin = vebt_mint summary\ \deg div 2 = n\ option.sel) + have "vebt_member (treeList ! summin) lx" + using \Some lx = vebt_mint (treeList ! summin)\ \invar_vebt (treeList ! summin) n\ mint_member by auto + moreover have "summin < 2^m" + by (metis "4.hyps"(1) \Some summin = vebt_mint summary\ member_bound mint_member) + ultimately have xnin: "both_member_options (Node (Some (mi, ma)) deg treeList summary) ?xn" + by (metis "12" "2" "9" \invar_vebt (treeList ! summin) n\ add_leD1 both_member_options_equiv_member both_member_options_from_chilf_to_complete_tree high_inv low_inv member_bound numeral_2_eq_2 plus_1_eq_Suc) + let ?h ="high ?xn n" + let ?l = "low ?xn n" + have "?xn < 2^deg" + by (smt (verit, ccfv_SIG) "4.hyps"(1) "4.hyps"(4) Euclidean_Division.div_eq_0_iff \Some lx = vebt_mint (treeList ! summin)\ \Some summin = vebt_mint summary\ \invar_vebt (treeList ! summin) n\ div_exp_eq high_def high_inv le_0_eq member_bound mint_member not_numeral_le_zero power_not_zero) + hence "?h < length treeList" + using "4.hyps"(2) "4.hyps"(3) "4.hyps"(4) \invar_vebt (treeList ! summin) n\ deg_not_0 exp_split_high_low(1) by metis + let ?newnode = "vebt_delete (treeList ! ?h) ?l" + let ?newlist = "treeList[?h:= ?newnode]" + have "length treeList = length ?newlist" by simp + hence hprolist: "?newlist ! ?h = ?newnode" + by (meson \high (summin * 2 ^ n + lx) n < length treeList\ nth_list_update_eq) + have nothprolist: "i \ ?h \ i < 2^m \ ?newlist ! i = treeList ! i" for i by simp + have hlbound:"?h < 2^m \ ?l < 2^n" + using "1" "2" "3" "8" \high (summin * 2 ^ n + lx) n < length treeList\ \summin * 2 ^ n + lx < 2 ^ deg\ deg_not_0 exp_split_high_low(2) by presburger + hence nnvalid: "invar_vebt ?newnode n" + by (metis "4.IH"(1) \high (summin * 2 ^ n + lx) n < length treeList\ inthall member_def) + have allvalidinlist:"\ t \ set ?newlist. invar_vebt t n" + proof + fix t + assume "t \ set ?newlist" + then obtain i where "i < 2^m \ ?newlist ! i = t" + by (metis "2" \length treeList = length (treeList [high (summin * 2 ^ n + lx) n := vebt_delete (treeList ! high (summin * 2 ^ n + lx) n) (low (summin * 2 ^ n + lx) n)])\ in_set_conv_nth) + then show "invar_vebt t n" + by (metis "0" "2" hprolist nnvalid nth_list_update_neq nth_mem) + qed + have newlistlength: "length ?newlist = 2^m" + by (simp add: "2") + then show ?thesis + proof(cases "minNull ?newnode") + case True + hence ninNullc: "minNull ?newnode" by simp + let ?sn = "vebt_delete summary ?h" + let ?newma= "(if ?xn = ma then (let maxs = vebt_maxt ?sn in + (if maxs = None + then ?xn + else 2^(deg div 2) * the maxs + + the (vebt_maxt (?newlist ! the maxs)) + ) + ) + else ma)" + let ?delsimp =" (Node (Some (?xn, ?newma)) deg ?newlist ?sn)" + have dsimp:"vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = ?delsimp" + using del_x_mi_lets_in_minNull[of x mi ma deg ?xn ?h summary treeList ?l ?newnode ?newlist ?sn] + by (metis "12" "9" \high (summin * 2 ^ n + lx) n < length treeList\ \summin * 2 ^ n + lx = (if x = mi then the (vebt_mint summary) * 2 ^ (deg div 2) + the (vebt_mint (treeList ! the (vebt_mint summary))) else x)\ \x = mi\ \x \ mi \ x \ ma\ inrg nat_less_le ninNullc) + have newsummvalid: "invar_vebt ?sn m" + by (simp add: "4.IH"(2)) + have 111: "(\ i < 2^m. (\ x. both_member_options (?newlist ! i) x) \ ( both_member_options ?sn i))" + proof + fix i + show " i < 2^m \ ((\ x. both_member_options (?newlist ! i) x) = ( both_member_options ?sn i))" + proof + assume "i < 2^m" + show "(\ x. both_member_options (?newlist ! i) x) = ( both_member_options ?sn i)" + proof(cases "i = ?h") + case True + hence 1000:"?newlist ! i = ?newnode" + using hprolist by fastforce + hence 1001:"\ x. vebt_member (?newlist ! i) x" + by (simp add: min_Null_member ninNullc) + hence 1002: "\ x. both_member_options (?newlist ! i) x" + using "1000" nnvalid valid_member_both_member_options by auto + have 1003: "\ both_member_options ?sn i" + using "1" True dele_bmo_cont_corr by auto + then show ?thesis + using "1002" by blast + next + case False + hence 1000:"?newlist ! i = treeList ! i" + using \i < 2 ^ m\ nothprolist by blast + hence "both_member_options (?newlist ! i) y \ both_member_options ?sn i" for y + proof- + assume "both_member_options (?newlist ! i) y" + hence "both_member_options summary i" + using "1000" "4" \i < 2 ^ m\ by auto + thus "both_member_options ?sn i" + using "1" False dele_bmo_cont_corr by blast + qed + moreover have "both_member_options ?sn i \ \ y. both_member_options (?newlist ! i) y" + proof- + assume "both_member_options ?sn i " + hence "both_member_options summary i" + using "1" dele_bmo_cont_corr by auto + thus " \ y. both_member_options (?newlist ! i) y" + using "1000" "4" \i < 2 ^ m\ by presburger + qed + then show ?thesis + using calculation by blast + qed + qed + qed + have 112:" (?xn = ?newma \ (\ t \ set ?newlist. \ x. both_member_options t x))" + proof + assume aampt:"?xn = ?newma" + show "(\ t \ set ?newlist. \ y. both_member_options t y)" + proof(cases "?xn = ma") + case True + let ?maxs = "vebt_maxt ?sn" + show ?thesis + proof(cases "?maxs = None") + case True + hence aa:"\ y. vebt_member ?sn y" + using maxt_corr_help_empty newsummvalid set_vebt'_def by auto + hence "\ y. both_member_options ?sn y" + using newsummvalid valid_member_both_member_options by blast + hence "t \ set ?newlist \ \y. both_member_options t y" for t + proof- + assume "t \ set ?newlist" + then obtain i where "?newlist ! i = t \ i< 2^m" + by (metis "2" \length treeList = length (treeList [high (summin * 2 ^ n + lx) n := vebt_delete (treeList ! high (summin * 2 ^ n + lx) n) (low (summin * 2 ^ n + lx) n)])\ in_set_conv_nth) + thus " \y. both_member_options t y" + using "111" \\y. both_member_options (vebt_delete summary (high (summin * 2 ^ n + lx) n)) y\ by blast + qed + then show ?thesis by blast + next + case False + then obtain maxs where "Some maxs = ?maxs" + by fastforce + hence "both_member_options summary maxs" + by (metis "1" dele_bmo_cont_corr maxbmo) + have bb:"maxs \ ?h \ maxs < 2^m" + by (metis "1" \Some maxs = vebt_maxt ?sn\ dele_bmo_cont_corr maxbmo member_bound valid_member_both_member_options) + hence "invar_vebt (?newlist ! maxs) n"using 0 + by (simp add: "2" allvalidinlist) + hence "\ y. both_member_options (?newlist ! maxs) y" + using "4" bb \both_member_options summary maxs\ nothprolist by presburger + then obtain maxi where "Some maxi = vebt_maxt (?newlist ! maxs)" + using \invar_vebt (treeList [high (summin * 2 ^ n + lx) n := vebt_delete (treeList ! high (summin * 2 ^ n + lx) n) (low (summin * 2 ^ n + lx) n)] ! maxs) n\ maxt_corr_help_empty set_vebt'_def valid_member_both_member_options by fastforce + hence "maxs = high ?xn n \ both_member_options (?newlist ! maxs) (low ?xn n)" + by (smt (z3) "9" False True \Some maxs = vebt_maxt (vebt_delete summary ?h)\ \invar_vebt (?newlist ! maxs) n\ aampt option.sel high_inv low_inv maxbmo maxt_member member_bound mult.commute) + hence False + using bb by blast + then show ?thesis by simp + qed + next + case False + hence "?xn \ ?newma" by simp + hence False using aampt by simp + then show ?thesis by blast + qed + qed + have 114: "?newma < 2^deg \ ?xn \ ?newma" + proof(cases "?xn = ma") + case True + hence "?xn = ma" by simp + let ?maxs = "vebt_maxt ?sn" + show ?thesis + proof(cases "?maxs = None") + case True + then show ?thesis + using "4.hyps"(8) \?xn = ma\ by force + next + case False + then obtain maxs where "Some maxs = ?maxs" + by fastforce + hence "both_member_options summary maxs" + by (metis "1" dele_bmo_cont_corr maxbmo) + have bb:"maxs \ ?h \ maxs < 2^m" + by (metis "1" \Some maxs = vebt_maxt ?sn\ dele_bmo_cont_corr maxbmo member_bound valid_member_both_member_options) + hence "invar_vebt (?newlist ! maxs) n"using 0 by (simp add: "2" allvalidinlist) + hence "\ y. both_member_options (?newlist ! maxs) y" + using "4" \both_member_options summary maxs\ bb nothprolist by presburger + then obtain maxi where "Some maxi = vebt_maxt (?newlist ! maxs)" + using \invar_vebt (treeList [high (summin * 2 ^ n + lx) n := vebt_delete (treeList ! high (summin * 2 ^ n + lx) n) (low (summin * 2 ^ n + lx) n)] ! maxs) n\ empty_Collect_eq maxt_corr_help_empty not_Some_eq set_vebt'_def valid_member_both_member_options by fastforce + hence abc:"?newma = 2^n * maxs + maxi" + by (smt (z3) "9" True \Some maxs = vebt_maxt (vebt_delete summary (high (summin * 2 ^ n + lx) n))\ option.sel not_None_eq) + have abd:"maxi < 2^n" + by (metis \Some maxi = vebt_maxt (?newlist ! maxs)\ \invar_vebt (?newlist ! maxs) n\ maxt_member member_bound) + have "high ?xn n \ maxs" + using "1" \Some summin = vebt_mint summary\ \both_member_options summary maxs\ \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ high_inv member_bound mint_corr_help valid_member_both_member_options by force + then show ?thesis + proof(cases "high ?xn n = maxs") + case True + then show ?thesis + using bb by fastforce + next + case False + hence "high ?xn n < maxs" + by (simp add: \high (summin * 2 ^ n + lx) n \ maxs\ order.not_eq_order_implies_strict) + hence "?newma < 2^deg"using + "1" "10" "9" True \both_member_options summary maxs\ \mi \ ma \ x < 2 ^ deg\ + equals0D leD maxt_corr_help maxt_corr_help_empty mem_Collect_eq summaxma set_vebt'_def + valid_member_both_member_options + by (metis option.exhaust_sel) + moreover have "high ?xn n < high ?newma n" + by (smt (z3) "9" True \Some maxi = vebt_maxt (treeList [high (summin * 2 ^ n + lx) n := vebt_delete (treeList ! high (summin * 2 ^ n + lx) n) (low (summin * 2 ^ n + lx) n)] ! maxs)\ \Some maxs = vebt_maxt (vebt_delete summary (high (summin * 2 ^ n + lx) n))\ \high (summin * 2 ^ n + lx) n < maxs\ abd option.sel high_inv mult.commute option.discI) + ultimately show ?thesis + by (metis div_le_mono high_def linear not_less) + qed + qed + next + case False + then show ?thesis + by (smt (z3) "12" "4.hyps"(7) "4.hyps"(8) "9" both_member_options_from_complete_tree_to_child dual_order.trans hlbound one_le_numeral xnin yhelper) + qed + have 115: "?xn \ ?newma \ + (\ i < 2^m. + (high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n)) \ + (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ ?xn < y \ y \ ?newma))" + proof + assume assumption0:"?xn \ ?newma" + show " (\ i < 2^m. + (high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n)) \ + (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ ?xn < y \ y \ ?newma))" + proof + fix i + show "i < 2^m \ + (high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n)) \ + (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ ?xn < y \ y \ ?newma)" + proof + assume assumption:"i < 2^m" + show " (high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n)) \ + (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ ?xn < y \ y \ ?newma)" + proof- + have "(high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n))" + proof + assume newmaassm: "high ?newma n = i" + thus " both_member_options (?newlist ! i) (low ?newma n)" + proof(cases "?xn = ma" ) + case True + hence bb:"?xn = ma" by simp + let ?maxs = "vebt_maxt ?sn" + show ?thesis + proof(cases "?maxs = None") + case True + hence "?newma = ?xn" using assumption Let_def bb by simp + hence False using assumption0 by simp + then show ?thesis by simp + next + case False + then obtain maxs where "Some maxs = ?maxs" + by fastforce + hence "both_member_options summary maxs" + by (metis "1" dele_bmo_cont_corr maxbmo) + have bb:"maxs \ ?h \ maxs < 2^m" + by (metis "1" \Some maxs = vebt_maxt ?sn\ dele_bmo_cont_corr maxbmo member_bound valid_member_both_member_options) + hence "invar_vebt (?newlist ! maxs) n"using 0 by (simp add: "2" allvalidinlist) + hence "\ y. both_member_options (?newlist ! maxs) y" + using "4" \both_member_options summary maxs\ bb nothprolist by presburger + then obtain maxi where "Some maxi = vebt_maxt (?newlist ! maxs)" using + \invar_vebt (treeList [high (summin * 2 ^ n + lx) n := + vebt_delete (treeList ! high (summin * 2 ^ n + lx) n) (low (summin * 2 ^ n + lx) n)] ! maxs) n\ + equals0D maxt_corr_help_empty mem_Collect_eq set_vebt'_def + valid_member_both_member_options + by (metis option.collapse) + then show ?thesis using "1" "10" "9" True \Some summin = vebt_mint summary\ + \both_member_options summary maxs\ \vebt_member (treeList ! summin) lx\ \mi \ ma \ x < 2 ^ deg\ + \invar_vebt (treeList ! summin) n\ bb equals0D high_inv maxt_corr_help maxt_corr_help_empty + mem_Collect_eq member_bound mint_corr_help nat_less_le summaxma set_vebt'_def + valid_member_both_member_options verit_comp_simplify1(3) + by (metis option.collapse) + qed + next + case False + hence ccc:"?newma = ma" by simp + then show ?thesis + proof(cases "?xn = ma") + case True + hence "?xn = ?newma" + using False by blast + hence False + using False by auto + then show ?thesis by simp + next + case False + hence "both_member_options (?newlist ! high ma n) (low ma n)" + by (metis "1" \both_member_options (treeList ! high ma n) (low ma n)\ \vebt_member (treeList ! summin) lx\ \vebt_member summary (high ma n)\ \invar_vebt (treeList ! summin) n\ bit_split_inv dele_bmo_cont_corr high_inv hprolist member_bound nothprolist) + moreover have "high ma n = i \ low ma n = low ?newma n" using ccc newmaassm by simp + ultimately show ?thesis by simp + qed + qed + qed + moreover have " (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ ?xn < y \ y \ ?newma)" + proof + fix y + show "(high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ ?xn < y \ y \ ?newma" + proof + assume yassm: "(high y n = i \ both_member_options (?newlist ! i) (low y n) )" + hence "?xn < y" + proof(cases "i = ?h") + case True + hence "both_member_options (treeList ! i) (low y n)" + using \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ dele_bmo_cont_corr high_inv hprolist member_bound yassm by auto + then show ?thesis + using True hprolist min_Null_member ninNullc nnvalid valid_member_both_member_options yassm by fastforce + next + case False + hence "i \ ?h \ False" + by (metis "1" "111" \Some summin = vebt_mint summary\ \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ assumption dele_bmo_cont_corr high_inv le_antisym member_bound mint_corr_help valid_member_both_member_options yassm) + hence "i > ?h" + using leI by blast + then show ?thesis + by (metis div_le_mono high_def not_less yassm) + qed + moreover have "y \ ?newma" + proof(cases "?xn = ma") + case True + hence "?xn= ma" by simp + let ?maxs = "vebt_maxt ?sn" + show ?thesis + proof(cases "?maxs = None") + case True + then show ?thesis + using "1" "111" assumption dele_bmo_cont_corr nothprolist yassm yhelper by auto + next + case False + then obtain maxs where "Some maxs = ?maxs" + by fastforce + hence "both_member_options summary maxs" + by (metis "1" dele_bmo_cont_corr maxbmo) + have bb:"maxs \ ?h \ maxs < 2^m" + by (metis "1" \Some maxs = vebt_maxt ?sn\ dele_bmo_cont_corr maxbmo member_bound valid_member_both_member_options) + hence "invar_vebt (?newlist ! maxs) n"using 0 + by (simp add: "2" allvalidinlist) + hence "\ y. both_member_options (?newlist ! maxs) y" + using "4" \both_member_options summary maxs\ bb nothprolist by presburger + then obtain maxi where "Some maxi = vebt_maxt (?newlist ! maxs)" + by (metis True \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ assumption calculation dele_bmo_cont_corr high_inv hprolist leD member_bound nth_list_update_neq yassm yhelper) + hence "maxs < 2^m \ maxi < 2^n" + by (metis \invar_vebt (?newlist ! maxs) n\ bb maxt_member member_bound) + hence "?newma = 2^n* maxs + maxi" + by (smt (z3) "9" False True \Some maxi = vebt_maxt (?newlist ! maxs)\ \Some maxs = vebt_maxt (vebt_delete summary (high ?xn n))\ option.sel) + hence "low ?newma n = maxi \ high ?newma n = maxs" + by (simp add: \maxs < 2 ^ m \ maxi < 2 ^ n\ high_inv low_inv mult.commute) + hence "both_member_options (treeList ! (high y n)) (low y n)" + by (metis "1" "111" assumption dele_bmo_cont_corr nothprolist yassm) + hence hleqdraft:"high y n > maxs \ False" + proof- + assume "high y n > maxs" + have "both_member_options summary (high y n)" + using "1" "111" assumption dele_bmo_cont_corr yassm by blast + moreover have "both_member_options ?sn (high y n)" + using "111" assumption yassm by blast + ultimately show False + using True \both_member_options (treeList ! high y n) (low y n)\ \summin * 2 ^ n + lx < y\ assumption leD yassm yhelper by blast + qed + hence hleqmaxs: "high y n \ maxs" by presburger + then show ?thesis + using \both_member_options (treeList ! high y n) (low y n)\ assumption calculation dual_order.strict_trans1 yassm yhelper by auto + qed + next + case False + then show ?thesis + by (smt (z3) \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ assumption dele_bmo_cont_corr high_inv hprolist member_bound nothprolist yassm yhelper) + qed + ultimately show " ?xn < y \ y \ ?newma" by simp + qed + qed + ultimately show ?thesis by simp + qed + qed + qed + qed + hence 117: "?newma < 2^deg" and 118: "?xn \ ?newma" using 114 by auto + have 116: " invar_vebt (Node (Some (?xn, ?newma)) deg ?newlist ?sn) deg" + using invar_vebt.intros(4)[of ?newlist n ?sn m deg ?xn ?newma] + using 3 allvalidinlist newlistlength newsummvalid "4.hyps"(3) 111 112 118 117 115 by fastforce + show ?thesis + using "116" dsimp by presburger + next + case False + hence notemp:"\ z. both_member_options ?newnode z" + using not_min_Null_member by auto + let ?newma = "(if ?xn = ma then + ?h * 2^(deg div 2) + the( vebt_maxt (?newlist ! ?h)) + else ma)" + let ?delsimp =" (Node (Some (?xn, ?newma)) deg ?newlist summary)" + have dsimp:"vebt_delete (Node (Some (x, ma)) deg treeList summary) x = ?delsimp" + using del_x_mi_lets_in_not_minNull[of x mi ma deg ?xn ?h summary treeList ?l ?newnode ?newlist] + "12" "2" "9" False dual_order.eq_iff hlbound inrg order.not_eq_order_implies_strict xmi + by (metis \summin * 2 ^ n + lx = (if x = mi then the (vebt_mint summary) * 2 ^ (deg div 2) + the (vebt_mint (treeList ! the (vebt_mint summary))) else x)\ \x \ mi \ x \ ma\) + have 111: "(\ i < 2^m. (\ x. both_member_options (?newlist ! i) x) \ ( both_member_options summary i))" + proof + fix i + show " i < 2^m \ ((\ x. both_member_options (?newlist ! i) x) = ( both_member_options summary i))" + proof + assume "i < 2^m" + show "(\ x. both_member_options (?newlist ! i) x) = ( both_member_options summary i)" + proof(cases "i = ?h") + case True + hence 1000:"?newlist ! i = ?newnode" + using hprolist by blast + hence 1001:"\ x. vebt_member (?newlist ! i) x" + using nnvalid notemp valid_member_both_member_options by auto + hence 1002: "\ x. both_member_options (?newlist ! i) x" + using "1000" notemp by presburger + have 1003: "both_member_options summary i" + using "4" True \\z. both_member_options (treeList ! summin) z\ \vebt_member (treeList ! summin) lx\ \summin < 2 ^ m\ \invar_vebt (treeList ! summin) n\ high_inv member_bound by auto + then show ?thesis + using "1002" by blast + next + case False + hence 1000:"?newlist ! i = treeList ! i" + using \i < 2 ^ m\ nothprolist by blast + then show ?thesis + using "4" \i < 2 ^ m\ by presburger + qed + qed + qed + have 112:" (?xn = ?newma \ (\ t \ set ?newlist. \ x. both_member_options t x))" + proof + assume aampt:"?xn = ?newma" + show "(\ t \ set ?newlist. \ y. both_member_options t y)" + proof(cases "?xn = ma") + case True + obtain maxi where " vebt_maxt (?newlist ! ?h) = Some maxi" + by (metis Collect_empty_eq False hprolist maxt_corr_help_empty nnvalid not_None_eq not_min_Null_member set_vebt'_def valid_member_both_member_options) + hence "both_member_options ?newnode maxi" + using hprolist maxbmo by auto + hence "both_member_options (treeList ! ?h) maxi" + using \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ dele_bmo_cont_corr high_inv member_bound by force + hence False + by (metis "9" \both_member_options (vebt_delete (treeList ! high (summin * 2 ^ n + lx) n) (low (summin * 2 ^ n + lx) n)) maxi\ \vebt_maxt (?newlist ! ?h) = Some maxi\ \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ aampt add_diff_cancel_left' dele_bmo_cont_corr option.sel high_inv low_inv member_bound) + then show ?thesis by blast + next + case False + then show ?thesis + using \mi \ ma \ x < 2 ^ deg\ aampt by presburger + qed + qed + have 114: "?newma < 2^deg \ ?xn \ ?newma" + proof(cases "?xn = ma") + case True + hence "?xn = ma" by simp + obtain maxi where " vebt_maxt (?newlist ! ?h) = Some maxi" + by (metis "111" "2" "4" Collect_empty_eq True \both_member_options (treeList ! high ma n) (low ma n)\ \high (summin * 2 ^ n + lx) n < length treeList\ hprolist maxt_corr_help_empty nnvalid not_None_eq set_vebt'_def valid_member_both_member_options) + hence "both_member_options ?newnode maxi" + using hprolist maxbmo by auto + hence "both_member_options (treeList ! ?h) maxi" + using \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ dele_bmo_cont_corr high_inv member_bound by force + hence "maxi < 2^n" + using \both_member_options?newnode maxi\ member_bound nnvalid valid_member_both_member_options by blast + show ?thesis + by (smt (verit, ccfv_threshold) "3" "9" Euclidean_Division.div_eq_0_iff True \Some lx = vebt_mint (treeList ! summin)\ \both_member_options (treeList ! high (summin * 2 ^ n + lx) n) maxi\ \vebt_maxt (?newlist ! high (summin * 2 ^ n + lx) n) = Some maxi\ \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ add.right_neutral add_left_mono div_mult2_eq div_mult_self3 option.sel high_inv hlbound le_0_eq member_bound mint_corr_help power_add power_not_zero rel_simps(28) valid_member_both_member_options) + next + case False + then show ?thesis + using "10" "4.hyps"(8) maxt_corr_help valid_member_both_member_options xnin by force + + qed + have 115: "?xn \ ?newma \ + (\ i < 2^m. + (high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n)) \ + (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ ?xn < y \ y \ ?newma))" + proof + assume xnmassm:"?xn \ ?newma" + show " (\ i < 2^m. + (high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n)) \ + (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ ?xn < y \ y \ ?newma))" + proof + fix i + show "i < 2^m \ + (high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n)) \ + (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ ?xn < y \ y \ ?newma)" + proof + assume assumption:"i < 2^m" + show " (high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n)) \ + (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ ?xn < y \ y \ ?newma)" + proof- + have "(high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n))" + proof + assume newmaassm: "high ?newma n = i" + thus " both_member_options (?newlist ! i) (low ?newma n)" + proof(cases "?xn = ma") + case True + obtain maxi where "vebt_maxt (?newlist ! ?h) = Some maxi" + by (metis Collect_empty_eq both_member_options_equiv_member hprolist maxt_corr_help_empty nnvalid not_Some_eq notemp set_vebt'_def) + hence "both_member_options (?newlist ! ?h) maxi" + using maxbmo by blast + then show ?thesis + by (smt (z3) "2" "9" True \Some lx = vebt_mint (treeList ! summin)\ \high (summin * 2 ^ n + lx) n < length treeList\ \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ add_left_mono dele_bmo_cont_corr eq_iff high_inv hprolist low_inv member_bound mint_corr_help valid_member_both_member_options yhelper) + next + case False + hence abcd:"?newma = ma" by simp + then show ?thesis + proof(cases "high ma n = ?h") + case True + hence "?newlist ! high ma n = ?newnode" + using hprolist by presburger + then show ?thesis + by (smt (z3) False True \both_member_options (treeList ! high ma n) (low ma n)\ \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ bit_split_inv dele_bmo_cont_corr high_inv member_bound newmaassm) + next + case False + hence "?newlist ! high ma n = treeList ! high ma n" + using "1" \vebt_member summary (high ma n)\ member_bound nothprolist by blast + moreover hence "both_member_options (treeList ! high ma n) (low ma n)" + using \both_member_options (treeList ! high ma n) (low ma n)\ by blast + ultimately show ?thesis using abcd newmaassm by simp + qed + qed + qed + moreover have " (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ ?xn < y \ y \ ?newma)" + proof + fix y + show "(high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ ?xn < y \ y \ ?newma" + proof + assume yassm: "(high y n = i \ both_member_options (?newlist ! i) (low y n) )" + hence "?xn < y" + proof(cases "i = ?h") + case True + hence "both_member_options (treeList ! i) (low y n)" + using \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ dele_bmo_cont_corr high_inv hprolist member_bound yassm by force + moreover have "vebt_mint (treeList ! i) = Some (low ?xn n)" + using True \Some lx = vebt_mint (treeList ! summin)\ \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ high_inv low_inv member_bound by presburger + moreover hence "low y n \ low ?xn n" + using True \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ calculation(1) high_inv member_bound mint_corr_help valid_member_both_member_options by auto + moreover have "low y n \ low ?xn n" + using True \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ dele_bmo_cont_corr high_inv hprolist member_bound yassm by auto + ultimately have "low y n > low ?xn n" by simp + show ?thesis + by (metis True \low (summin * 2 ^ n + lx) n \ low y n\ \low y n \ low (summin * 2 ^ n + lx) n\ bit_concat_def bit_split_inv leD linorder_neqE_nat nat_add_left_cancel_less yassm) + next + case False + have "Some (high ?xn n) = vebt_mint summary" + using \Some summin = vebt_mint summary\ \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ high_inv member_bound by presburger + moreover hence "high y n \ high ?xn n" + by (metis "1" "111" assumption mint_corr_help valid_member_both_member_options yassm) + ultimately show ?thesis + by (metis False div_le_mono high_def leI le_antisym yassm) + qed + moreover have "y \ ?newma" + by (smt (z3) \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ assumption calculation dele_bmo_cont_corr high_inv hprolist leD member_bound nothprolist yassm yhelper) + ultimately show " ?xn < y \ y \ ?newma" by simp + qed + qed + ultimately show ?thesis by simp + qed + qed + qed + qed + hence 117: "?newma < 2^deg" and 118: "?xn \ ?newma" using 114 by auto + have 116: " invar_vebt (Node (Some (?xn, ?newma)) deg ?newlist summary) deg" + using invar_vebt.intros(4)[of ?newlist n summary m deg ?xn ?newma] allvalidinlist + 1 newlistlength 8 3 111 112 117 118 115 by fastforce + hence "invar_vebt (?delsimp) deg" by simp + moreover obtain delsimp where 118:"delsimp = ?delsimp" by simp + ultimately have 119:"invar_vebt delsimp deg" by simp + have "vebt_delete (Node (Some (x, ma)) deg treeList summary) x = delsimp" using dsimp 118 by simp + hence "delsimp = vebt_delete (Node (Some (x, ma)) deg treeList summary) x" by simp + then show ?thesis using 119 + using xmi by auto + qed + qed + qed + qed +next + case (5 treeList n summary m deg mi ma) + hence 0: "( \ t \ set treeList. invar_vebt t n)" and 1: " invar_vebt summary m" and 2:"length treeList = 2^m" and 3:" deg = n+m" and + 4: "(\ i < 2^m. (\ y. both_member_options (treeList ! i) y) \ ( both_member_options summary i))" and + 5: "(mi = ma \ (\ t \ set treeList. \ y. both_member_options t y))" and 6:"mi \ ma \ ma < 2^deg" and + 7: "(mi \ ma \ (\ i < 2^m. (high ma n = i \ both_member_options (treeList ! i) (low ma n)) \ + (\ y. (high y n = i \ both_member_options (treeList ! i) (low y n) ) \ mi < y \ y \ ma)))" + and 8: "Suc n = m" and 9: "deg div 2 = n" using "5" add_self_div_2 by auto + hence 10: "invar_vebt (Node (Some (mi, ma)) deg treeList summary) deg" + using invar_vebt.intros(5)[of treeList n summary m deg mi ma] by blast + hence 11:"n \ 1 " and 12: " deg \ 2" + by (metis "0" "2" "9" One_nat_def deg_not_0 div_greater_zero_iff le_0_eq numeral_2_eq_2 set_n_deg_not_0)+ + then show ?case + proof(cases "(x < mi \ x > ma)") + case True + hence "vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = (Node (Some (mi, ma)) deg treeList summary)" + using delt_out_of_range[of x mi ma deg treeList summary] + using "12" by fastforce + then show ?thesis + by (simp add: "10") + next + case False + hence inrg: "mi\ x \ x \ ma" by simp + then show ?thesis + proof(cases "x = mi \ x = ma") + case True + hence" (\ t \ set treeList. \ y. both_member_options t y)" + using "5" by blast + moreover have "vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = (Node None deg treeList summary)" + using del_single_cont[of x mi ma deg treeList summary] "1" "8" "9" True deg_not_0 div_greater_zero_iff "12" by fastforce + moreover have " (\ i. both_member_options summary i)" + using "10" True mi_eq_ma_no_ch by blast + ultimately show ?thesis + using "0" "1" "2" "3" "8" invar_vebt.intros(3) by force + next + case False + hence "x \ mi \ x \ ma" by simp + hence "mi \ ma \ x < 2^deg" + by (metis "6" inrg le_antisym le_less_trans) + hence "7b": "(\ i < 2^m. (high ma n = i \ both_member_options (treeList ! i) (low ma n)) \ + (\ y. (high y n = i \ both_member_options (treeList ! i) (low y n) ) \ mi < y \ y \ ma))" + using "7" by fastforce + hence "both_member_options (treeList ! (high ma n)) (low ma n)" + by (metis "1" "12" "3" "6" "9" deg_not_0 div_greater_zero_iff exp_split_high_low(1) zero_less_numeral) + hence yhelper:"both_member_options (treeList ! (high y n)) (low y n) + \ high y n < 2^m \ mi < y \ y \ ma \ low y n < 2^n" for y + by (simp add: "7b" low_def) + then show ?thesis + proof(cases "x \ mi") + case True + hence xnotmi: "x \ mi" by simp + let ?h = "high x n" + let ?l = "low x n" + have hlbound:"?h < 2^m \ ?l < 2^n" + by (metis "1" "11" "3" One_nat_def \mi \ ma \ x < 2 ^ deg\ deg_not_0 dual_order.strict_trans1 exp_split_high_low(1) exp_split_high_low(2) zero_less_Suc) + let ?newnode = "vebt_delete (treeList ! ?h) ?l" + have "treeList ! ?h \ set treeList " + by (metis "2" hlbound in_set_member inthall) + hence nnvalid: "invar_vebt ?newnode n" + by (simp add: "5.IH"(1)) + let ?newlist = "treeList[?h:= ?newnode]" + have hlist:"?newlist ! ?h = ?newnode" + by (simp add: "2" hlbound) + have nothlist:"i \ ?h \ i < 2^m \ ?newlist ! i = treeList ! i" for i by simp + have allvalidinlist:"\ t \ set ?newlist. invar_vebt t n" + proof + fix t + assume "t \ set ?newlist" + then obtain i where "i< 2^m \ ?newlist ! i = t" + by (metis "2" in_set_conv_nth length_list_update) + then show "invar_vebt t n" + by (metis "0" "2" hlist nnvalid nth_list_update_neq nth_mem) + qed + have newlistlength: "length ?newlist = 2^m" + by (simp add: "2") + then show ?thesis + proof(cases "minNull ?newnode") + case True + hence ninNullc: "minNull ?newnode" by simp + let ?sn = "vebt_delete summary ?h" + let ?newma= "(if x = ma then (let maxs = vebt_maxt ?sn in + (if maxs = None + then mi + else 2^(deg div 2) * the maxs + + the (vebt_maxt (?newlist ! the maxs)) + ) + ) + else ma)" + let ?delsimp =" (Node (Some (mi, ?newma)) deg ?newlist ?sn)" + have dsimp:"vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = ?delsimp" + using del_x_not_mi_new_node_nil[of mi x ma deg ?h ?l ?newnode treeList ?sn summary ?newlist] + hlbound 9 11 12 True 2 inrg xnotmi by simp + have newsummvalid: "invar_vebt ?sn m" + by (simp add: "5.IH"(2)) + have 111: "(\ i < 2^m. (\ x. both_member_options (?newlist ! i) x) \ ( both_member_options ?sn i))" + proof + fix i + show " i < 2^m \ ((\ x. both_member_options (?newlist ! i) x) = ( both_member_options ?sn i))" + proof + assume "i < 2^m" + show "(\ x. both_member_options (?newlist ! i) x) = ( both_member_options ?sn i)" + proof(cases "i = ?h") + case True + hence 1000:"?newlist ! i = ?newnode" + using hlist by blast + hence 1001:"\ x. vebt_member (?newlist ! i) x" + by (simp add: min_Null_member ninNullc) + hence 1002: "\ x. both_member_options (?newlist ! i) x" + using "1000" nnvalid valid_member_both_member_options by auto + have 1003: "\ both_member_options ?sn i" + using "1" True dele_bmo_cont_corr by auto + then show ?thesis + using "1002" by blast + next + case False + hence 1000:"?newlist ! i = treeList ! i" + using \i < 2 ^ m\ nothlist by blast + hence "both_member_options (?newlist ! i) y \ both_member_options ?sn i" for y + by (metis "1" "4" False \i < 2 ^ m\ dele_bmo_cont_corr) + moreover have "both_member_options ?sn i \ \ y. both_member_options (?newlist ! i) y" + using "1" "4" \i < 2 ^ m\ dele_bmo_cont_corr by force + then show ?thesis + using calculation by blast + qed + qed + qed + have 112:" (mi = ?newma \ (\ t \ set ?newlist. \ x. both_member_options t x))" + proof + assume aampt:"mi = ?newma" + show "(\ t \ set ?newlist. \ y. both_member_options t y)" + proof(cases "x = ma") + case True + let ?maxs = "vebt_maxt ?sn" + show ?thesis + proof(cases "?maxs = None") + case True + hence aa:"\ y. vebt_member ?sn y" + using maxt_corr_help_empty newsummvalid set_vebt'_def by auto + hence "\ y. both_member_options ?sn y" + using newsummvalid valid_member_both_member_options by blast + hence "t \ set ?newlist \ \y. both_member_options t y" for t + proof- + assume "t \ set ?newlist" + then obtain i where "?newlist ! i = t \ i< 2^m" + by (metis in_set_conv_nth newlistlength) + thus " \y. both_member_options t y" + using "111" \\y. both_member_options (vebt_delete summary (high x n)) y\ by blast + qed + then show ?thesis by blast + next + case False + then obtain maxs where "Some maxs = ?maxs" + by fastforce + hence "both_member_options summary maxs" + by (metis "1" dele_bmo_cont_corr maxbmo) + have bb:"maxs \ ?h \ maxs < 2^m" + by (metis "1" \Some maxs = vebt_maxt ?sn\ dele_bmo_cont_corr maxbmo member_bound valid_member_both_member_options) + hence "invar_vebt (?newlist ! maxs) n"using 0 + by (metis allvalidinlist newlistlength nth_mem) + hence "\ y. both_member_options (?newlist ! maxs) y" + using "4" bb \both_member_options summary maxs\ nothlist by presburger + then obtain maxi where "Some maxi = vebt_maxt (?newlist ! maxs)" + by (metis Collect_empty_eq_bot \invar_vebt (treeList[high x n := vebt_delete (treeList ! high x n) (low x n)] ! maxs) n\ bb bot_empty_eq equals0D maxt_corr_help_empty nth_list_update_neq option_shift.elims set_vebt'_def valid_member_both_member_options) + hence "maxs = high mi n \ both_member_options (?newlist ! maxs) (low mi n)" + by (smt (z3) "9" False True \Some maxs = vebt_maxt (vebt_delete summary (high x n))\ \invar_vebt (?newlist ! maxs) n\ aampt option.sel high_inv low_inv maxbmo maxt_member member_bound mult.commute) + hence False + by (metis bb nat_less_le nothlist yhelper) + then show ?thesis by simp + qed + next + case False + then show ?thesis + using \mi \ ma \ x < 2 ^ deg\ aampt by presburger + qed + qed + have 114: "?newma < 2^deg \ mi \ ?newma" + proof(cases "x = ma") + case True + hence "x = ma" by simp + let ?maxs = "vebt_maxt ?sn" + show ?thesis + proof(cases "?maxs = None") + case True + then show ?thesis + using "6" by fastforce + next + case False + then obtain maxs where "Some maxs = ?maxs" + by fastforce + hence "both_member_options summary maxs" + by (metis "1" dele_bmo_cont_corr maxbmo) + have bb:"maxs \ ?h \ maxs < 2^m" + by (metis "1" \Some maxs = vebt_maxt ?sn\ dele_bmo_cont_corr maxbmo member_bound valid_member_both_member_options) + hence "invar_vebt (?newlist ! maxs) n"using 0 + by (metis allvalidinlist newlistlength nth_mem) + hence "\ y. both_member_options (?newlist ! maxs) y" + using "4" bb \both_member_options summary maxs\ nothlist by presburger + then obtain maxi where "Some maxi = vebt_maxt (?newlist ! maxs)" + by (smt (z3) VEBT_Member.vebt_member.simps(2) \invar_vebt (?newlist ! maxs) n\ vebt_maxt.elims minNull.simps(1) min_Null_member valid_member_both_member_options) + then show ?thesis + by (smt (verit, best) "6" "9" \Some maxs = vebt_maxt (vebt_delete summary (high x n))\ \invar_vebt (?newlist ! maxs) n\ bb option.sel high_inv less_le_trans low_inv maxbmo maxt_member member_bound mult.commute not_less_iff_gr_or_eq nothlist verit_comp_simplify1(3) yhelper) + qed + next + case False + then show ?thesis + using "6" by auto + qed + have 115: "mi \ ?newma \ + (\ i < 2^m. + (high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n)) \ + (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ mi < y \ y \ ?newma))" + proof + assume "mi \ ?newma" + show " (\ i < 2^m. + (high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n)) \ + (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ mi < y \ y \ ?newma))" + proof + fix i + show "i < 2^m \ + (high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n)) \ + (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ mi < y \ y \ ?newma)" + proof + assume assumption:"i < 2^m" + show " (high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n)) \ + (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ mi < y \ y \ ?newma)" + proof- + have "(high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n))" + proof + assume newmaassm: "high ?newma n = i" + thus " both_member_options (?newlist ! i) (low ?newma n)" + proof(cases "x = ma" ) + case True + let ?maxs = "vebt_maxt ?sn" + show ?thesis + proof(cases "?maxs = None") + case True + then show ?thesis + by (smt (z3) "0" \both_member_options (treeList ! high ma n) (low ma n)\ \mi \ (if x = ma then let maxs = vebt_maxt (vebt_delete summary (high x n)) in if maxs = None then mi else 2 ^ (deg div 2) * the maxs + the (vebt_maxt (?newlist ! the maxs)) else ma)\ \treeList ! high x n \ set treeList\ assumption bit_split_inv dele_bmo_cont_corr hlist newmaassm nothlist) + next + case False + then obtain maxs where "Some maxs = ?maxs" + by fastforce + hence "both_member_options summary maxs" + by (metis "1" dele_bmo_cont_corr maxbmo) + have bb:"maxs \ ?h \ maxs < 2^m" + by (metis "1" \Some maxs = vebt_maxt ?sn\ dele_bmo_cont_corr maxbmo member_bound valid_member_both_member_options) + hence "invar_vebt (?newlist ! maxs) n"using 0 "2" by auto + hence "\ y. both_member_options (?newlist ! maxs) y" + using "4" bb \both_member_options summary maxs\ nothlist by presburger + then obtain maxi where "Some maxi = vebt_maxt (?newlist ! maxs)" + by (smt (z3) VEBT_Member.vebt_member.simps(2) \invar_vebt (treeList[high x n := vebt_delete (treeList ! high x n) (low x n)] ! maxs) n\ vebt_maxt.elims minNull.simps(1) min_Null_member valid_member_both_member_options) + then show ?thesis + by (smt (z3) "9" True \Some maxs = vebt_maxt (vebt_delete summary (high x n))\ \invar_vebt (treeList[high x n := vebt_delete (treeList ! high x n) (low x n)] ! maxs) n\ option.sel high_inv low_inv maxbmo maxt_member member_bound mult.commute newmaassm option.distinct(1)) + qed + next + case False + then show ?thesis + by (smt (z3) "0" \both_member_options (treeList ! high ma n) (low ma n)\ \treeList ! high x n \ set treeList\ assumption bit_split_inv dele_bmo_cont_corr hlist newmaassm nothlist) + qed + qed + moreover have " (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ mi < y \ y \ ?newma)" + proof + fix y + show "(high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ mi < y \ y \ ?newma" + proof + assume yassm: "(high y n = i \ both_member_options (?newlist ! i) (low y n) )" + hence "mi < y" + proof(cases "i = ?h") + case True + hence "both_member_options (treeList ! i) (low y n)" + using "0" \treeList ! high x n \ set treeList\ dele_bmo_cont_corr hlist yassm by auto + then show ?thesis + by (simp add: assumption yassm yhelper) + next + case False + then show ?thesis + using assumption nothlist yassm yhelper by presburger + qed + moreover have "y \ ?newma" + proof(cases "x = ma") + case True + hence "x= ma" by simp + let ?maxs = "vebt_maxt ?sn" + show ?thesis + proof(cases "?maxs = None") + case True + then show ?thesis + using \mi \ ?newma\ \x = ma\ by presburger + next + case False + then obtain maxs where "Some maxs = ?maxs" + by fastforce + hence "both_member_options summary maxs" + by (metis "1" dele_bmo_cont_corr maxbmo) + have bb:"maxs \ ?h \ maxs < 2^m" + by (metis "1" \Some maxs = vebt_maxt ?sn\ dele_bmo_cont_corr maxbmo member_bound valid_member_both_member_options) + hence "invar_vebt (?newlist ! maxs) n"using 0 "2" by fastforce + hence "\ y. both_member_options (?newlist ! maxs) y" + using "4" bb \both_member_options summary maxs\ nothlist by presburger + then obtain maxi where "Some maxi = vebt_maxt (?newlist ! maxs)" + by (metis \invar_vebt (treeList[high x n := vebt_delete (treeList ! high x n) (low x n)] ! maxs) n\ equals0D maxt_corr_help_empty mem_Collect_eq option_shift.elims set_vebt'_def valid_member_both_member_options) + hence "maxs < 2^m \ maxi < 2^n" + by (metis \invar_vebt (?newlist ! maxs) n\ bb maxt_member member_bound) + hence "?newma = 2^n* maxs + maxi" + by (smt (z3) "9" False True \Some maxi = vebt_maxt (?newlist ! maxs)\ \Some maxs = vebt_maxt (vebt_delete summary (high x n))\ option.sel) + hence "low ?newma n = maxi \ high ?newma n = maxs" + by (simp add: \maxs < 2 ^ m \ maxi < 2 ^ n\ high_inv low_inv mult.commute) + hence "both_member_options (treeList ! (high y n)) (low y n)" + by (metis "0" \treeList ! high x n \ set treeList\ assumption dele_bmo_cont_corr hlist nothlist yassm) + hence hleqdraft:"high y n > maxs \ False" + proof- + assume "high y n > maxs" + have "both_member_options summary (high y n)" + using "1" "111" assumption dele_bmo_cont_corr yassm by blast + moreover have "both_member_options ?sn (high y n)" + using "111" assumption yassm by blast + ultimately show False + by (metis \Some maxs = vebt_maxt (vebt_delete summary (high x n))\ \maxs < high y n\ leD maxt_corr_help newsummvalid valid_member_both_member_options) + qed + hence hleqmaxs: "high y n \ maxs" by presburger + then show ?thesis + proof(cases "high y n = maxs") + case True + hence "low y n \ maxi" + by (metis \Some maxi = vebt_maxt (treeList[high x n := vebt_delete (treeList ! high x n) (low x n)] ! maxs)\ \invar_vebt (treeList[high x n := vebt_delete (treeList ! high x n) (low x n)] ! maxs) n\ maxt_corr_help valid_member_both_member_options yassm) + then show ?thesis + by (smt (z3) True \(if x = ma then let maxs = vebt_maxt (vebt_delete summary (high x n)) in if maxs = None then mi else 2 ^ (deg div 2) * the maxs + the (vebt_maxt (treeList [high x n := vebt_delete (treeList ! high x n) (low x n)] ! the maxs)) else ma) = 2 ^ n * maxs + maxi\ add_le_cancel_left bit_concat_def bit_split_inv mult.commute) + next + case False + then show ?thesis + by (smt (z3) \low (if x = ma then let maxs = vebt_maxt (vebt_delete summary (high x n)) in if maxs = None then mi else 2 ^ (deg div 2) * the maxs + the (vebt_maxt (treeList [high x n := vebt_delete (treeList ! high x n) (low x n)] ! the maxs)) else ma) n = maxi \ high (if x = ma then let maxs = vebt_maxt (vebt_delete summary (high x n)) in if maxs = None then mi else 2 ^ (deg div 2) * the maxs + the (vebt_maxt (treeList [high x n := vebt_delete (treeList ! high x n) (low x n)] ! the maxs)) else ma) n = maxs\ div_le_mono high_def hleqmaxs le_antisym nat_le_linear) + qed + qed + next + case False + then show ?thesis + by (smt (z3) "0" \treeList ! high x n \ set treeList\ assumption dele_bmo_cont_corr hlist nothlist yassm yhelper) + qed + ultimately show " mi < y \ y \ ?newma" by simp + qed + qed + ultimately show ?thesis by simp + qed + qed + qed + qed + hence 117: "?newma < 2^deg" and 118: "mi \ ?newma" using 114 by auto + have 116: " invar_vebt (Node (Some (mi, ?newma)) deg ?newlist ?sn) deg" + using invar_vebt.intros(5)[of ?newlist n ?sn m deg mi ?newma] + using 3 allvalidinlist newlistlength newsummvalid "5.hyps"(3) 111 112 118 117 115 by fastforce + show ?thesis + using "116" dsimp by presburger + next + case False + hence notemp:"\ z. both_member_options ?newnode z" + using not_min_Null_member by auto + let ?newma = "(if x = ma then + ?h * 2^(deg div 2) + the( vebt_maxt (?newlist ! ?h)) + else ma)" + let ?delsimp =" (Node (Some (mi, ?newma)) deg ?newlist summary)" + have dsimp:"vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = ?delsimp" + using del_x_not_mi_newnode_not_nil[of mi x ma deg ?h ?l ?newnode treeList ?newlist summary] + by (metis "12" "2" "9" False dual_order.eq_iff hlbound inrg order.not_eq_order_implies_strict xnotmi) + have 111: "(\ i < 2^m. (\ x. both_member_options (?newlist ! i) x) \ ( both_member_options summary i))" + proof + fix i + show " i < 2^m \ ((\ x. both_member_options (?newlist ! i) x) = ( both_member_options summary i))" + proof + assume "i < 2^m" + show "(\ x. both_member_options (?newlist ! i) x) = ( both_member_options summary i)" + proof(cases "i = ?h") + case True + hence 1000:"?newlist ! i = ?newnode" + using hlist by blast + hence 1001:"\ x. vebt_member (?newlist ! i) x" + using nnvalid notemp valid_member_both_member_options by auto + hence 1002: "\ x. both_member_options (?newlist ! i) x" + using "1000" notemp by presburger + have 1003: "both_member_options summary i" + using "0" "1000" "1002" "4" True \i < 2 ^ m\ \treeList ! high x n \ set treeList\ dele_bmo_cont_corr by fastforce + then show ?thesis + using "1002" by blast + next + case False + hence 1000:"?newlist ! i = treeList ! i" + using \i < 2 ^ m\ nothlist by blast + then show ?thesis + using "4" \i < 2 ^ m\ by presburger + qed + qed + qed + have 112:" (mi = ?newma \ (\ t \ set ?newlist. \ x. both_member_options t x))" + proof + assume aampt:"mi = ?newma" + show "(\ t \ set ?newlist. \ y. both_member_options t y)" + proof(cases "x = ma") + case True + obtain maxi where " vebt_maxt (?newlist ! ?h) = Some maxi" + by (metis False VEBT_Member.vebt_member.simps(2) hlist vebt_maxt.elims minNull.simps(1) nnvalid notemp valid_member_both_member_options) + hence "both_member_options ?newnode maxi" + using hlist maxbmo by auto + hence "both_member_options (treeList ! ?h) maxi" + using "0" \treeList ! high x n \ set treeList\ dele_bmo_cont_corr by blast + hence False + by (metis "9" True \both_member_options ?newnode maxi\ \vebt_maxt ( ?newlist ! high x n) = Some maxi\ aampt option.sel high_inv hlbound low_inv member_bound nnvalid not_less_iff_gr_or_eq valid_member_both_member_options yhelper) + then show ?thesis by blast + next + case False + then show ?thesis + using \mi \ ma \ x < 2 ^ deg\ aampt by presburger + qed + qed + have 114: "?newma < 2^deg \ mi \ ?newma" + proof(cases "x = ma") + case True + hence "x = ma" by simp + obtain maxi where " vebt_maxt (?newlist ! ?h) = Some maxi" + by (metis False VEBT_Member.vebt_member.simps(2) hlist vebt_maxt.elims minNull.simps(1) nnvalid notemp valid_member_both_member_options) + hence "both_member_options ?newnode maxi" + using hlist maxbmo by auto + hence "both_member_options (treeList ! ?h) maxi" + using "0" \treeList ! high x n \ set treeList\ dele_bmo_cont_corr by blast + hence "maxi < 2^n" + using \both_member_options?newnode maxi\ member_bound nnvalid valid_member_both_member_options by blast + show ?thesis + by (smt (z3) "3" "9" Euclidean_Division.div_eq_0_iff True \both_member_options (treeList ! high x n) maxi\ \maxi < 2 ^ n\ \vebt_maxt ( ?newlist ! high x n) = Some maxi\ add.right_neutral div_exp_eq div_mult_self3 option.sel high_inv hlbound le_0_eq less_imp_le_nat low_inv power_not_zero rel_simps(28) yhelper) + next + case False + then show ?thesis + using "6" by auto + qed + have 115: "mi \ ?newma \ + (\ i < 2^m. + (high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n)) \ + (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ mi < y \ y \ ?newma))" + proof + assume "mi \ ?newma" + show " (\ i < 2^m. + (high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n)) \ + (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ mi < y \ y \ ?newma))" + proof + fix i + show "i < 2^m \ + (high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n)) \ + (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ mi < y \ y \ ?newma)" + proof + assume assumption:"i < 2^m" + show " (high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n)) \ + (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ mi < y \ y \ ?newma)" + proof- + have "(high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n))" + proof + assume newmaassm: "high ?newma n = i" + thus " both_member_options (?newlist ! i) (low ?newma n)" + proof(cases "x = ma") + case True + obtain maxi where "vebt_maxt (?newlist ! ?h) = Some maxi" + by (metis Collect_empty_eq both_member_options_equiv_member hlist maxt_corr_help_empty nnvalid not_Some_eq notemp set_vebt'_def) + hence "both_member_options (?newlist ! ?h) maxi" + using maxbmo by blast + then show ?thesis + by (smt (z3) "9" True \vebt_maxt (?newlist ! high x n) = Some maxi\ option.sel high_inv hlist low_inv maxt_member member_bound newmaassm nnvalid) + next + case False + then show ?thesis + by (smt (z3) "0" \both_member_options (treeList ! high ma n) (low ma n)\ \treeList ! high x n \ set treeList\ assumption bit_split_inv dele_bmo_cont_corr hlist newmaassm nothlist) + qed + qed + moreover have " (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ mi < y \ y \ ?newma)" + proof + fix y + show "(high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ mi < y \ y \ ?newma" + proof + assume yassm: "(high y n = i \ both_member_options (?newlist ! i) (low y n) )" + hence "mi < y" + proof(cases "i = ?h") + case True + hence "both_member_options (treeList ! i) (low y n)" + using "0" \treeList ! high x n \ set treeList\ dele_bmo_cont_corr hlist yassm by auto + then show ?thesis + by (simp add: assumption yassm yhelper) + next + case False + then show ?thesis + using assumption nothlist yassm yhelper by presburger + qed + moreover have "y \ ?newma" + proof(cases "x = ma") + case True + hence "x= ma" by simp + obtain maxi where "vebt_maxt (?newlist ! ?h) = Some maxi" + by (metis Collect_empty_eq both_member_options_equiv_member hlist maxt_corr_help_empty nnvalid not_Some_eq notemp set_vebt'_def) + hence "both_member_options (?newlist ! ?h) maxi" + using maxbmo by blast + have "high y n \ ?h" + by (metis "7b" True assumption div_le_mono high_def nothlist yassm) + then show ?thesis + proof(cases "high y n = ?h") + case True + have "low y n > maxi \ False" + by (metis True \vebt_maxt (?newlist ! ?h) = Some maxi\ hlist leD maxt_corr_help nnvalid valid_member_both_member_options yassm) + then show ?thesis + by (smt (z3) "9" True \vebt_maxt (?newlist ! ?h) = Some maxi\ \x = ma\ add_le_cancel_left div_mult_mod_eq option.sel high_def low_def nat_le_linear nat_less_le) + next + case False + then show ?thesis + by (smt (z3) "9" True \both_member_options (?newlist ! high x n) maxi\ \high y n \ high x n\ \vebt_maxt (?newlist ! high x n) = Some maxi\ div_le_mono option.sel high_def high_inv hlist le_antisym member_bound nat_le_linear nnvalid valid_member_both_member_options) + qed + next + case False + then show ?thesis + by (smt (z3) "0" \treeList ! high x n \ set treeList\ assumption dele_bmo_cont_corr hlist nothlist yassm yhelper) + qed + ultimately show " mi < y \ y \ ?newma" by simp + qed + qed + ultimately show ?thesis by simp + qed + qed + qed + qed + hence 117: "?newma < 2^deg" and 118: "mi \ ?newma" using 114 by auto + have 116: " invar_vebt (Node (Some (mi, ?newma)) deg ?newlist summary) deg" + using invar_vebt.intros(5)[of ?newlist n summary m deg mi ?newma] allvalidinlist + 1 newlistlength 8 3 111 112 117 118 115 by fastforce + then show ?thesis + using dsimp by presburger + qed + next + case False + hence xmi:"x = mi" by simp + have "both_member_options summary (high ma n)" + by (metis "1" "11" "3" "4" "6" One_nat_def Suc_le_eq \both_member_options (treeList ! high ma n) (low ma n)\ deg_not_0 exp_split_high_low(1)) + hence "vebt_member summary (high ma n)" + using "5.hyps"(1) valid_member_both_member_options by blast + obtain summin where "Some summin = vebt_mint summary" + by (metis "5.hyps"(1) \vebt_member summary (high ma n)\ empty_Collect_eq mint_corr_help_empty not_None_eq set_vebt'_def) + hence "\ z . both_member_options (treeList ! summin) z" + by (metis "5.hyps"(1) "5.hyps"(5) both_member_options_equiv_member member_bound mint_member) + moreover have "invar_vebt (treeList ! summin) n" + by (metis "0" "1" "2" \Some summin = vebt_mint summary\ member_bound mint_member nth_mem) + ultimately obtain lx where "Some lx = vebt_mint (treeList ! summin)" + by (metis empty_Collect_eq mint_corr_help_empty not_None_eq set_vebt'_def valid_member_both_member_options) + let ?xn = "summin*2^n + lx" + have "?xn = (if x = mi + then the (vebt_mint summary) * 2^(deg div 2) + + the (vebt_mint (treeList ! the (vebt_mint summary))) + else x)" + by (metis False \Some lx = vebt_mint (treeList ! summin)\ \Some summin = vebt_mint summary\ \deg div 2 = n\ option.sel) + have "vebt_member (treeList ! summin) lx" + using \Some lx = vebt_mint (treeList ! summin)\ \invar_vebt (treeList ! summin) n\ mint_member by auto + moreover have "summin < 2^m" + by (metis "5.hyps"(1) \Some summin = vebt_mint summary\ member_bound mint_member) + ultimately have xnin: "both_member_options (Node (Some (mi, ma)) deg treeList summary) ?xn" + by (metis "12" "2" "9" \invar_vebt (treeList ! summin) n\ add_leD1 both_member_options_equiv_member both_member_options_from_chilf_to_complete_tree high_inv low_inv member_bound numeral_2_eq_2 plus_1_eq_Suc) + let ?h ="high ?xn n" + let ?l = "low ?xn n" + have "?xn < 2^deg" + by (smt (verit, ccfv_SIG) "5.hyps"(1) "5.hyps"(4) Euclidean_Division.div_eq_0_iff \Some lx = vebt_mint (treeList ! summin)\ \Some summin = vebt_mint summary\ \invar_vebt (treeList ! summin) n\ div_exp_eq high_def high_inv le_0_eq member_bound mint_member not_numeral_le_zero power_not_zero) + hence "?h < length treeList" + using "2" \vebt_member (treeList ! summin) lx\ \summin < 2 ^ m\ \invar_vebt (treeList ! summin) n\ high_inv member_bound by presburger + let ?newnode = "vebt_delete (treeList ! ?h) ?l" + let ?newlist = "treeList[?h:= ?newnode]" + have "length treeList = length ?newlist" by auto + hence hprolist: "?newlist ! ?h = ?newnode" + by (meson \high (summin * 2 ^ n + lx) n < length treeList\ nth_list_update_eq) + have nothprolist: "i \ ?h \ i < 2^m \ ?newlist ! i = treeList ! i" for i by auto + have hlbound:"?h < 2^m \ ?l < 2^n" + using "2" \high (summin * 2 ^ n + lx) n < length treeList\ \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ low_inv member_bound by presburger + hence nnvalid: "invar_vebt ?newnode n" + by (metis "5.IH"(1) \high (summin * 2 ^ n + lx) n < length treeList\ inthall member_def) + have allvalidinlist:"\ t \ set ?newlist. invar_vebt t n" + proof + fix t + assume "t \ set ?newlist" + then obtain i where "i < 2^m \ ?newlist ! i = t" + by (metis "2" in_set_conv_nth length_list_update) + then show "invar_vebt t n" + by (metis "0" "2" hprolist nnvalid nth_list_update_neq nth_mem) + qed + have newlistlength: "length ?newlist = 2^m" + by (simp add: "2") + then show ?thesis + proof(cases "minNull ?newnode") + case True + hence ninNullc: "minNull ?newnode" by simp + let ?sn = "vebt_delete summary ?h" + let ?newma= "(if ?xn = ma then (let maxs = vebt_maxt ?sn in + (if maxs = None + then ?xn + else 2^(deg div 2) * the maxs + + the (vebt_maxt (?newlist ! the maxs)) + ) + ) + else ma)" + let ?delsimp =" (Node (Some (?xn, ?newma)) deg ?newlist ?sn)" + have dsimp:"vebt_delete (Node (Some (mi, ma)) deg treeList summary) x = ?delsimp" + using del_x_mi_lets_in_minNull[of x mi ma deg ?xn ?h summary treeList ?l ?newnode ?newlist ?sn] + by (metis "12" "9" \high (summin * 2 ^ n + lx) n < length treeList\ \summin * 2 ^ n + lx = (if x = mi then the (vebt_mint summary) * 2 ^ (deg div 2) + the (vebt_mint (treeList ! the (vebt_mint summary))) else x)\ \x = mi\ \x \ mi \ x \ ma\ inrg nat_less_le ninNullc) + have newsummvalid: "invar_vebt ?sn m" + by (simp add: "5.IH"(2)) + have 111: "(\ i < 2^m. (\ x. both_member_options (?newlist ! i) x) \ ( both_member_options ?sn i))" + proof + fix i + show " i < 2^m \ ((\ x. both_member_options (?newlist ! i) x) = ( both_member_options ?sn i))" + proof + assume "i < 2^m" + show "(\ x. both_member_options (?newlist ! i) x) = ( both_member_options ?sn i)" + proof(cases "i = ?h") + case True + hence 1000:"?newlist ! i = ?newnode" + using hprolist by fastforce + hence 1001:"\ x. vebt_member (?newlist ! i) x" + by (simp add: min_Null_member ninNullc) + hence 1002: "\ x. both_member_options (?newlist ! i) x" + using "1000" nnvalid valid_member_both_member_options by auto + have 1003: "\ both_member_options ?sn i" + using "1" True dele_bmo_cont_corr by auto + then show ?thesis + using "1002" by blast + next + case False + hence 1000:"?newlist ! i = treeList ! i" + using \i < 2 ^ m\ nothprolist by blast + hence "both_member_options (?newlist ! i) y \ both_member_options ?sn i" for y + using "1" "4" False \i < 2 ^ m\ dele_bmo_cont_corr by auto + moreover have "both_member_options ?sn i \ \ y. both_member_options (?newlist ! i) y" + proof- + assume "both_member_options ?sn i " + hence "both_member_options summary i" + using "1" dele_bmo_cont_corr by auto + thus " \ y. both_member_options (?newlist ! i) y" + using "1000" "4" \i < 2 ^ m\ by presburger + qed + then show ?thesis + using calculation by blast + qed + qed + qed + have 112:" (?xn = ?newma \ (\ t \ set ?newlist. \ x. both_member_options t x))" + proof + assume aampt:"?xn = ?newma" + show "(\ t \ set ?newlist. \ y. both_member_options t y)" + proof(cases "?xn = ma") + case True + let ?maxs = "vebt_maxt ?sn" + show ?thesis + proof(cases "?maxs = None") + case True + hence aa:"\ y. vebt_member ?sn y" + using maxt_corr_help_empty newsummvalid set_vebt'_def by auto + hence "\ y. both_member_options ?sn y" + using newsummvalid valid_member_both_member_options by blast + hence "t \ set ?newlist \ \y. both_member_options t y" for t + proof- + assume "t \ set ?newlist" + then obtain i where "?newlist ! i = t \ i< 2^m" + by (metis "2" \length treeList = length (treeList [high (summin * 2 ^ n + lx) n := vebt_delete (treeList ! high (summin * 2 ^ n + lx) n) (low (summin * 2 ^ n + lx) n)])\ in_set_conv_nth) + thus " \y. both_member_options t y" + using "111" \\y. both_member_options (vebt_delete summary (high (summin * 2 ^ n + lx) n)) y\ by blast + qed + then show ?thesis by blast + next + case False + then obtain maxs where "Some maxs = ?maxs" + by fastforce + hence "both_member_options summary maxs" + by (metis "1" dele_bmo_cont_corr maxbmo) + have bb:"maxs \ ?h \ maxs < 2^m" + by (metis "1" \Some maxs = vebt_maxt ?sn\ dele_bmo_cont_corr maxbmo member_bound valid_member_both_member_options) + hence "invar_vebt (?newlist ! maxs) n"using 0 + by (simp add: "2" allvalidinlist) + hence "\ y. both_member_options (?newlist ! maxs) y" + using "4" bb \both_member_options summary maxs\ nothprolist by presburger + then obtain maxi where "Some maxi = vebt_maxt (?newlist ! maxs)" + by (smt (z3) VEBT_Member.vebt_member.simps(2) \invar_vebt (?newlist ! maxs) n\ vebt_maxt.elims minNull.simps(1) min_Null_member valid_member_both_member_options) + hence "maxs = high ?xn n \ both_member_options (?newlist ! maxs) (low ?xn n)" + by (smt (z3) "9" False True \Some maxs = vebt_maxt (vebt_delete summary ?h)\ \invar_vebt (?newlist ! maxs) n\ aampt option.sel high_inv low_inv maxbmo maxt_member member_bound mult.commute) + hence False + using bb by blast + then show ?thesis by simp + qed + next + case False + hence "?xn \ ?newma" by simp + hence False using aampt by simp + then show ?thesis by blast + qed + qed + have 114: "?newma < 2^deg \ ?xn \ ?newma" + proof(cases "?xn = ma") + case True + hence "?xn = ma" by simp + let ?maxs = "vebt_maxt ?sn" + show ?thesis + proof(cases "?maxs = None") + case True + then show ?thesis + using "5.hyps"(8) \?xn = ma\ by force + next + case False + then obtain maxs where "Some maxs = ?maxs" + by fastforce + hence "both_member_options summary maxs" + by (metis "1" dele_bmo_cont_corr maxbmo) + have bb:"maxs \ ?h \ maxs < 2^m" + by (metis "1" \Some maxs = vebt_maxt ?sn\ dele_bmo_cont_corr maxbmo member_bound valid_member_both_member_options) + hence "invar_vebt (?newlist ! maxs) n"using 0 by (simp add: "2" allvalidinlist) + hence "\ y. both_member_options (?newlist ! maxs) y" + using "4" \both_member_options summary maxs\ bb nothprolist by presburger + then obtain maxi where "Some maxi = vebt_maxt (?newlist ! maxs)" + using \invar_vebt (treeList [high (summin * 2 ^ n + lx) n := vebt_delete (treeList ! high (summin * 2 ^ n + lx) n) (low (summin * 2 ^ n + lx) n)] ! maxs) n\ maxt_corr_help_empty set_vebt'_def valid_member_both_member_options by fastforce + hence abc:"?newma = 2^n * maxs + maxi" + by (smt (z3) "9" True \Some maxs = vebt_maxt (vebt_delete summary (high (summin * 2 ^ n + lx) n))\ option.sel not_None_eq) + have abd:"maxi < 2^n" + by (metis \Some maxi = vebt_maxt (?newlist ! maxs)\ \invar_vebt (?newlist ! maxs) n\ maxt_member member_bound) + have "high ?xn n \ maxs" + using "1" \Some summin = vebt_mint summary\ \both_member_options summary maxs\ \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ high_inv member_bound mint_corr_help valid_member_both_member_options by force + then show ?thesis + proof(cases "high ?xn n = maxs") + case True + then show ?thesis + using bb by fastforce + next + case False + hence "high ?xn n < maxs" + by (simp add: \high (summin * 2 ^ n + lx) n \ maxs\ order.not_eq_order_implies_strict) + hence "?newma < 2^deg" + by (smt (z3) "5.hyps"(8) "9" \Some maxi = vebt_maxt (?newlist ! maxs)\ \Some maxs = vebt_maxt (vebt_delete summary (high (summin * 2 ^ n + lx) n))\ \invar_vebt (?newlist ! maxs) n\ abd bb both_member_options_equiv_member option.sel high_inv less_le_trans low_inv maxt_member mult.commute nothprolist verit_comp_simplify1(3) yhelper) + moreover have "high ?xn n < high ?newma n" + by (smt (z3) "9" True \Some maxi = vebt_maxt (?newlist ! maxs)\ \Some maxs = vebt_maxt (vebt_delete summary (high (summin * 2 ^ n + lx) n))\ \high (summin * 2 ^ n + lx) n < maxs\ abd option.sel high_inv mult.commute option.discI) + ultimately show ?thesis + by (metis div_le_mono high_def linear not_less) + qed + qed + next + case False + then show ?thesis + by (smt (z3) "12" "5.hyps"(7) "5.hyps"(8) "9" both_member_options_from_complete_tree_to_child dual_order.trans hlbound one_le_numeral xnin yhelper) + qed + have 115: "?xn \ ?newma \ + (\ i < 2^m. + (high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n)) \ + (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ ?xn < y \ y \ ?newma))" + proof + assume assumption0:"?xn \ ?newma" + show " (\ i < 2^m. + (high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n)) \ + (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ ?xn < y \ y \ ?newma))" + proof + fix i + show "i < 2^m \ + (high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n)) \ + (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ ?xn < y \ y \ ?newma)" + proof + assume assumption:"i < 2^m" + show " (high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n)) \ + (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ ?xn < y \ y \ ?newma)" + proof- + have "(high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n))" + proof + assume newmaassm: "high ?newma n = i" + thus " both_member_options (?newlist ! i) (low ?newma n)" + proof(cases "?xn = ma" ) + case True + hence bb:"?xn = ma" by simp + let ?maxs = "vebt_maxt ?sn" + show ?thesis + proof(cases "?maxs = None") + case True + hence "?newma = ?xn" using assumption Let_def bb by simp + hence False using assumption0 by simp + then show ?thesis by simp + next + case False + then obtain maxs where "Some maxs = ?maxs" + by fastforce + hence "both_member_options summary maxs" + by (metis "1" dele_bmo_cont_corr maxbmo) + have bb:"maxs \ ?h \ maxs < 2^m" + by (metis "1" \Some maxs = vebt_maxt ?sn\ dele_bmo_cont_corr maxbmo member_bound valid_member_both_member_options) + hence "invar_vebt (?newlist ! maxs) n"using 0 by (simp add: "2" allvalidinlist) + hence "\ y. both_member_options (?newlist ! maxs) y" + using "4" \both_member_options summary maxs\ bb nothprolist by presburger + then obtain maxi where "Some maxi = vebt_maxt (?newlist ! maxs)" + using \invar_vebt (treeList [high (summin * 2 ^ n + lx) n := vebt_delete (treeList ! high (summin * 2 ^ n + lx) n) (low (summin * 2 ^ n + lx) n)] ! maxs) n\ maxt_corr_help_empty set_vebt'_def valid_member_both_member_options by fastforce + then show ?thesis + by (metis "1" "10" "9" True \Some summin = vebt_mint summary\ \both_member_options summary maxs\ \vebt_member (treeList ! summin) lx\ \mi \ ma \ x < 2 ^ deg\ \invar_vebt (treeList ! summin) n\ bb equals0D high_inv le_antisym maxt_corr_help maxt_corr_help_empty mem_Collect_eq member_bound mint_corr_help option.collapse summaxma set_vebt'_def valid_member_both_member_options) + + qed + next + case False + hence ccc:"?newma = ma" by simp + then show ?thesis + proof(cases "?xn = ma") + case True + hence "?xn = ?newma" + using False by blast + hence False + using False by auto + then show ?thesis by simp + next + case False + hence "both_member_options (?newlist ! high ma n) (low ma n)" + by (metis "1" \both_member_options (treeList ! high ma n) (low ma n)\ \vebt_member (treeList ! summin) lx\ \vebt_member summary (high ma n)\ \invar_vebt (treeList ! summin) n\ bit_split_inv dele_bmo_cont_corr high_inv hprolist member_bound nothprolist) + moreover have "high ma n = i \ low ma n = low ?newma n" using ccc newmaassm by simp + ultimately show ?thesis by simp + qed + qed + qed + moreover have " (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ ?xn < y \ y \ ?newma)" + proof + fix y + show "(high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ ?xn < y \ y \ ?newma" + proof + assume yassm: "(high y n = i \ both_member_options (?newlist ! i) (low y n) )" + hence "?xn < y" + proof(cases "i = ?h") + case True + hence "both_member_options (treeList ! i) (low y n)" + using \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ dele_bmo_cont_corr high_inv hprolist member_bound yassm by auto + then show ?thesis + using True hprolist min_Null_member ninNullc nnvalid valid_member_both_member_options yassm by fastforce + next + case False + hence "i \ ?h \ False" + by (metis "1" "111" \Some summin = vebt_mint summary\ \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ assumption dele_bmo_cont_corr high_inv le_antisym member_bound mint_corr_help valid_member_both_member_options yassm) + hence "i > ?h" + using leI by blast + then show ?thesis + by (metis div_le_mono high_def not_less yassm) + qed + moreover have "y \ ?newma" + proof(cases "?xn = ma") + case True + hence "?xn= ma" by simp + let ?maxs = "vebt_maxt ?sn" + show ?thesis + proof(cases "?maxs = None") + case True + then show ?thesis + using "1" "111" assumption dele_bmo_cont_corr nothprolist yassm yhelper by auto + next + case False + then obtain maxs where "Some maxs = ?maxs" + by fastforce + hence "both_member_options summary maxs" + by (metis "1" dele_bmo_cont_corr maxbmo) + have bb:"maxs \ ?h \ maxs < 2^m" + by (metis "1" \Some maxs = vebt_maxt ?sn\ dele_bmo_cont_corr maxbmo member_bound valid_member_both_member_options) + hence "invar_vebt (?newlist ! maxs) n"using 0 by (simp add: "2" allvalidinlist) + hence "\ y. both_member_options (?newlist ! maxs) y" + using "4" \both_member_options summary maxs\ bb nothprolist by presburger + then obtain maxi where "Some maxi = vebt_maxt (?newlist ! maxs)" + by (metis True \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ assumption calculation dele_bmo_cont_corr high_inv hprolist leD member_bound nth_list_update_neq yassm yhelper) + hence "maxs < 2^m \ maxi < 2^n" + by (metis \invar_vebt (?newlist ! maxs) n\ bb maxt_member member_bound) + hence "?newma = 2^n* maxs + maxi" + by (smt (z3) "9" False True \Some maxi = vebt_maxt (?newlist ! maxs)\ \Some maxs = vebt_maxt (vebt_delete summary (high ?xn n))\ option.sel) + hence "low ?newma n = maxi \ high ?newma n = maxs" + by (simp add: \maxs < 2 ^ m \ maxi < 2 ^ n\ high_inv low_inv mult.commute) + hence "both_member_options (treeList ! (high y n)) (low y n)" + by (metis "1" "111" assumption dele_bmo_cont_corr nothprolist yassm) + hence hleqdraft:"high y n > maxs \ False" + proof- + assume "high y n > maxs" + have "both_member_options summary (high y n)" + using "1" "111" assumption dele_bmo_cont_corr yassm by blast + moreover have "both_member_options ?sn (high y n)" + using "111" assumption yassm by blast + ultimately show False + using True \both_member_options (treeList ! high y n) (low y n)\ \summin * 2 ^ n + lx < y\ assumption leD yassm yhelper by blast + qed + hence hleqmaxs: "high y n \ maxs" by presburger + then show ?thesis + using \both_member_options (treeList ! high y n) (low y n)\ assumption calculation dual_order.strict_trans1 yassm yhelper by auto + qed + next + case False + then show ?thesis + by (smt (z3) \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ assumption dele_bmo_cont_corr high_inv hprolist member_bound nothprolist yassm yhelper) + qed + ultimately show " ?xn < y \ y \ ?newma" by simp + qed + qed + ultimately show ?thesis by simp + qed + qed + qed + qed + hence 117: "?newma < 2^deg" and 118: "?xn \ ?newma" using 114 by auto + have 116: " invar_vebt (Node (Some (?xn, ?newma)) deg ?newlist ?sn) deg" + using invar_vebt.intros(5)[of ?newlist n ?sn m deg ?xn ?newma] + using 3 allvalidinlist newlistlength newsummvalid "5.hyps"(3) 111 112 118 117 115 by fastforce + show ?thesis + using "116" dsimp by presburger + next + case False + hence notemp:"\ z. both_member_options ?newnode z" + using not_min_Null_member by auto + let ?newma = "(if ?xn = ma then + ?h * 2^(deg div 2) + the( vebt_maxt (?newlist ! ?h)) + else ma)" + let ?delsimp =" (Node (Some (?xn, ?newma)) deg ?newlist summary)" + have dsimp:"vebt_delete (Node (Some (x, ma)) deg treeList summary) x = ?delsimp" + using del_x_mi_lets_in_not_minNull[of x mi ma deg ?xn ?h summary treeList ?l ?newnode ?newlist] + "12" "2" "9" False dual_order.eq_iff hlbound inrg order.not_eq_order_implies_strict xmi + by (metis \summin * 2 ^ n + lx = (if x = mi then the (vebt_mint summary) * 2 ^ (deg div 2) + the (vebt_mint (treeList ! the (vebt_mint summary))) else x)\ \x \ mi \ x \ ma\) + have 111: "(\ i < 2^m. (\ x. both_member_options (?newlist ! i) x) \ ( both_member_options summary i))" + proof + fix i + show " i < 2^m \ ((\ x. both_member_options (?newlist ! i) x) = ( both_member_options summary i))" + proof + assume "i < 2^m" + show "(\ x. both_member_options (?newlist ! i) x) = ( both_member_options summary i)" + proof(cases "i = ?h") + case True + hence 1000:"?newlist ! i = ?newnode" + using hprolist by blast + hence 1001:"\ x. vebt_member (?newlist ! i) x" + using nnvalid notemp valid_member_both_member_options by auto + hence 1002: "\ x. both_member_options (?newlist ! i) x" + using "1000" notemp by presburger + have 1003: "both_member_options summary i" + using "4" True \\z. both_member_options (treeList ! summin) z\ \vebt_member (treeList ! summin) lx\ \summin < 2 ^ m\ \invar_vebt (treeList ! summin) n\ high_inv member_bound by auto + then show ?thesis + using "1002" by blast + next + case False + hence 1000:"?newlist ! i = treeList ! i" + using \i < 2 ^ m\ nothprolist by blast + then show ?thesis + using "4" \i < 2 ^ m\ by presburger + qed + qed + qed + have 112:" (?xn = ?newma \ (\ t \ set ?newlist. \ x. both_member_options t x))" + proof + assume aampt:"?xn = ?newma" + show "(\ t \ set ?newlist. \ y. both_member_options t y)" + proof(cases "?xn = ma") + case True + obtain maxi where " vebt_maxt (?newlist ! ?h) = Some maxi" + by (metis Collect_empty_eq False hprolist maxt_corr_help_empty nnvalid not_None_eq not_min_Null_member set_vebt'_def valid_member_both_member_options) + hence "both_member_options ?newnode maxi" + using hprolist maxbmo by auto + hence "both_member_options (treeList ! ?h) maxi" + using \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ dele_bmo_cont_corr high_inv member_bound by force + hence False + by (metis "9" \both_member_options (vebt_delete (treeList ! high (summin * 2 ^ n + lx) n) (low (summin * 2 ^ n + lx) n)) maxi\ \vebt_maxt (?newlist ! ?h) = Some maxi\ \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ aampt add_diff_cancel_left' dele_bmo_cont_corr option.sel high_inv low_inv member_bound) + then show ?thesis by blast + next + case False + then show ?thesis + using \mi \ ma \ x < 2 ^ deg\ aampt by presburger + qed + qed + have 114: "?newma < 2^deg \ ?xn \ ?newma" + proof(cases "?xn = ma") + case True + hence "?xn = ma" by simp + obtain maxi where " vebt_maxt (?newlist ! ?h) = Some maxi" + by (metis "111" "2" "4" Collect_empty_eq True \both_member_options (treeList ! high ma n) (low ma n)\ \high (summin * 2 ^ n + lx) n < length treeList\ hprolist maxt_corr_help_empty nnvalid not_None_eq set_vebt'_def valid_member_both_member_options) + hence "both_member_options ?newnode maxi" + using hprolist maxbmo by auto + hence "both_member_options (treeList ! ?h) maxi" + using \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ dele_bmo_cont_corr high_inv member_bound by force + hence "maxi < 2^n" + using \both_member_options?newnode maxi\ member_bound nnvalid valid_member_both_member_options by blast + show ?thesis + by (smt (verit, ccfv_threshold) "3" "9" Euclidean_Division.div_eq_0_iff True \Some lx = vebt_mint (treeList ! summin)\ \both_member_options (treeList ! high (summin * 2 ^ n + lx) n) maxi\ \vebt_maxt (?newlist ! high (summin * 2 ^ n + lx) n) = Some maxi\ \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ add.right_neutral add_left_mono div_mult2_eq div_mult_self3 option.sel high_inv hlbound le_0_eq member_bound mint_corr_help power_add power_not_zero rel_simps(28) valid_member_both_member_options) + next + case False + then show ?thesis + using "10" "5.hyps"(8) maxt_corr_help valid_member_both_member_options xnin by force + + qed + have 115: "?xn \ ?newma \ + (\ i < 2^m. + (high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n)) \ + (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ ?xn < y \ y \ ?newma))" + proof + assume xnmassm:"?xn \ ?newma" + show " (\ i < 2^m. + (high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n)) \ + (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ ?xn < y \ y \ ?newma))" + proof + fix i + show "i < 2^m \ + (high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n)) \ + (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ ?xn < y \ y \ ?newma)" + proof + assume assumption:"i < 2^m" + show " (high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n)) \ + (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ ?xn < y \ y \ ?newma)" + proof- + have "(high ?newma n = i \ both_member_options (?newlist ! i) (low ?newma n))" + proof + assume newmaassm: "high ?newma n = i" + thus " both_member_options (?newlist ! i) (low ?newma n)" + proof(cases "?xn = ma") + case True + obtain maxi where "vebt_maxt (?newlist ! ?h) = Some maxi" + by (metis Collect_empty_eq both_member_options_equiv_member hprolist maxt_corr_help_empty nnvalid not_Some_eq notemp set_vebt'_def) + hence "both_member_options (?newlist ! ?h) maxi" + using maxbmo by blast + then show ?thesis + by (smt (z3) "2" "9" True \Some lx = vebt_mint (treeList ! summin)\ \high (summin * 2 ^ n + lx) n < length treeList\ \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ add_left_mono dele_bmo_cont_corr eq_iff high_inv hprolist low_inv member_bound mint_corr_help valid_member_both_member_options yhelper) + next + case False + hence abcd:"?newma = ma" by simp + then show ?thesis + proof(cases "high ma n = ?h") + case True + hence "?newlist ! high ma n = ?newnode" + using hprolist by presburger + then show ?thesis + proof(cases "low ma n = ?l") + case True + hence "?newma = ?xn" + by (metis "1" False \?newlist ! high ma n = vebt_delete (treeList ! high (summin * 2 ^ n + lx) n) (low (summin * 2 ^ n + lx) n)\ \both_member_options (treeList ! high ma n) (low ma n)\ + \vebt_member (treeList ! summin) lx\ \vebt_member summary (high ma n)\ \invar_vebt (treeList ! summin) n\ bit_split_inv dele_bmo_cont_corr high_inv member_bound nothprolist) + hence False + using False by presburger + then show ?thesis by simp + next + case False + have "both_member_options (treeList ! high ma n) (low ma n)" + by (simp add: \both_member_options (treeList ! high ma n) (low ma n)\) + hence "both_member_options ?newnode (low ma n)" + using False True \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ dele_bmo_cont_corr high_inv member_bound by force + hence "both_member_options (?newlist ! high ma n) (low ma n)" + using True hprolist by presburger + then show ?thesis using abcd newmaassm by simp + qed + next + case False + hence "?newlist ! high ma n = treeList ! high ma n" + using "1" \vebt_member summary (high ma n)\ member_bound nothprolist by blast + moreover hence "both_member_options (treeList ! high ma n) (low ma n)" + using \both_member_options (treeList ! high ma n) (low ma n)\ by blast + ultimately show ?thesis using abcd newmaassm by simp + qed + qed + qed + moreover have " (\ y. (high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ ?xn < y \ y \ ?newma)" + proof + fix y + show "(high y n = i \ both_member_options (?newlist ! i) (low y n) ) \ ?xn < y \ y \ ?newma" + proof + assume yassm: "(high y n = i \ both_member_options (?newlist ! i) (low y n) )" + hence "?xn < y" + proof(cases "i = ?h") + case True + hence "both_member_options (treeList ! i) (low y n)" + using \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ dele_bmo_cont_corr high_inv hprolist member_bound yassm by force + moreover have "vebt_mint (treeList ! i) = Some (low ?xn n)" + using True \Some lx = vebt_mint (treeList ! summin)\ \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ high_inv low_inv member_bound by presburger + moreover hence "low y n \ low ?xn n" + using True \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ calculation(1) high_inv member_bound mint_corr_help valid_member_both_member_options by auto + moreover have "low y n \ low ?xn n" + using True \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ dele_bmo_cont_corr high_inv hprolist member_bound yassm by auto + ultimately have "low y n > low ?xn n" by simp + show ?thesis + by (metis True \low (summin * 2 ^ n + lx) n \ low y n\ \low y n \ low (summin * 2 ^ n + lx) n\ bit_concat_def bit_split_inv leD linorder_neqE_nat nat_add_left_cancel_less yassm) + next + case False + have "Some (high ?xn n) = vebt_mint summary" + using \Some summin = vebt_mint summary\ \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ high_inv member_bound by presburger + moreover hence "high y n \ high ?xn n" + by (metis "1" "111" assumption mint_corr_help valid_member_both_member_options yassm) + ultimately show ?thesis + by (metis False div_le_mono high_def leI le_antisym yassm) + qed + moreover have "y \ ?newma" + by (smt (z3) \vebt_member (treeList ! summin) lx\ \invar_vebt (treeList ! summin) n\ assumption calculation dele_bmo_cont_corr high_inv hprolist leD member_bound nothprolist yassm yhelper) + ultimately show " ?xn < y \ y \ ?newma" by simp + qed + qed + ultimately show ?thesis by simp + qed + qed + qed + qed + hence 117: "?newma < 2^deg" and 118: "?xn \ ?newma" using 114 by auto + have 116: " invar_vebt (Node (Some (?xn, ?newma)) deg ?newlist summary) deg" + using invar_vebt.intros(5)[of ?newlist n summary m deg ?xn ?newma] allvalidinlist + 1 newlistlength 8 3 111 112 117 118 115 by fastforce + hence "invar_vebt (?delsimp) deg" by simp + moreover obtain delsimp where 118:"delsimp = ?delsimp" by simp + ultimately have 119:"invar_vebt delsimp deg" by simp + have "vebt_delete (Node (Some (x, ma)) deg treeList summary) x = delsimp" using dsimp 118 by simp + hence "delsimp = vebt_delete (Node (Some (x, ma)) deg treeList summary) x" by simp + then show ?thesis using 119 + using xmi by auto + qed + qed + qed + qed +qed + +corollary dele_member_cont_corr:"invar_vebt t n \ (vebt_member (vebt_delete t x) y \ x \ y \ vebt_member t y)" + by (meson both_member_options_equiv_member dele_bmo_cont_corr delete_pres_valid) + +subsection \Correctness with Respect to Set Interpretation\ +theorem delete_correct': assumes "invar_vebt t n" + shows "set_vebt' (vebt_delete t x) = set_vebt' t - {x}" + using assms by(auto simp add: set_vebt'_def dele_member_cont_corr) + + +corollary delete_correct: assumes "invar_vebt t n" + shows "set_vebt' (vebt_delete t x) = set_vebt t - {x}" + using assms delete_correct' set_vebt_set_vebt'_valid by auto + +end +end diff --git a/thys/Van_Emde_Boas_Trees/VEBT_Example.thy b/thys/Van_Emde_Boas_Trees/VEBT_Example.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/VEBT_Example.thy @@ -0,0 +1,135 @@ +(*by Lammich and Ammer*) +section \Interface Usage Example\ +theory VEBT_Example +imports VEBT_Intf_Imperative VEBT_Example_Setup +begin + + + + subsection \Test Program\ + + definition "test n xs ys \ do { + t \ vebt_buildupi n; + t \ mfold (\x s. vebt_inserti s x) (0#xs) t; + + let f = (\x. if\<^sub>m vebt_memberi t x then return x else the $\<^sub>m (vebt_predi t x)); + + mmap f ys + }" + + subsection \Correctness without Time\ + text \The non-time part of our datastructure is fully integrated into sep-auto\ + + lemma fold_list_rl[sep_heap_rules]: "\x\set xs. x<2^n \ hoare_triple + (vebt_assn n s t) + (mfold (\x s. vebt_inserti s x) xs t) + (\t'. vebt_assn n (s \ set xs) t')" + proof (induction xs arbitrary: s t) + case Nil + then show ?case by sep_auto + next + case (Cons a xs) + + note Cons.IH[sep_heap_rules] + + show ?case using Cons.prems + by sep_auto + + qed + + + lemma test_hoare: "\\x\set xs. x<2^n; n>0\ \ + (test n xs ys) <\r. \(r = map (\y. (GREATEST y'. y'\insert 0 (set xs) \ y'\y)) ys) >\<^sub>t " + unfolding test_def + supply R = mmap_pure_aux[where f="(\y. (GREATEST y'. y'\insert 0 (set xs) \ y'\y))"] + apply (sep_auto decon: R) + subgoal + by (metis (mono_tags, lifting) GreatestI_ex_nat zero_le_numeral) + subgoal + by (metis (no_types, lifting) Greatest_equality le_eq_less_or_eq) + apply sep_auto + subgoal + apply (auto simp: is_pred_in_set_def) + subgoal + by (smt (z3) GreatestI_nat le_neq_implies_less less_eq_nat.simps(1)) + subgoal + by (smt (z3) GreatestI_nat mult.right_neutral nat_less_le power_eq_0_iff power_mono_iff) + subgoal + by (metis (no_types, lifting) Greatest_le_nat less_imp_le) + done + apply sep_auto + done + +subsection \Time Bound Reasoning\ +text \ + We use some ad-hoc reasoning to also show the time-bound of our test program. + A generalization of such methods, or the integration of this entry into existing + reasoning frameworks with time is left to future work. +\ + +lemma insert_time_pure[cond_TBOUND]:"a < 2^n \ + \

vebt_assn n S ti\
TBOUND (vebt_inserti ti a) (13 + 13 * nat \log 2 (real n)\)" + by(rule htt_elim, rule vebt_inserti_rule, simp) + +lemma member_time_pure[cond_TBOUND]:"\
vebt_assn n S ti\
TBOUND (vebt_memberi ti a) (5 + 5 * nat \log 2 (real n)\)" + by(rule htt_elim, rule vebt_memberi_rule) + +lemma pred_time_pure[cond_TBOUND]:"\
vebt_assn n S ti\
TBOUND (vebt_predi ti a) (7 + 7 * nat \log 2 (real n)\)" + by(rule htt_elim, rule vebt_predi_rule) + +lemma TBOUND_mfold[cond_TBOUND]:" + (\ x. x \ set xs \ x < 2^n) \ + \
vebt_assn n S ti \
TBOUND (mfold (\x s. vebt_inserti s x) xs ti) (length xs * (13 + 13 * nat \log 2 n \) + 1)" + apply(induction xs arbitrary: ti S) + apply(subst mfold.simps) + apply(cond_TBOUND, simp) + apply sep_auto + subgoal for a xs ti S + apply(rule cond_TBOUND_mono[where b = "(13 + 13 * nat \log 2 (real n)\) + (length xs * (13 + 13 * nat \log 2 (real n)\) + 1)"]) + apply(rule cond_TBOUND, auto|(rule vebt_heap_rules(3), auto))+ + done + done + +lemma TBOUND_mmap[cond_TBOUND]: + defines b_def: "b ys n \ 1 + length ys * ( 5 + 5 * nat \log 2 (real n)\ + 9 + 7 * nat \log 2 (real n)\)" + shows "\
vebt_assn n S ti \
TBOUND + (mmap (\x. if\<^sub>m vebt_memberi ti x then return x + else vebt_predi ti x \ (\x. return (the x))) ys) (b ys n)" + apply(induction ys arbitrary:) + apply(subst mmap.simps) + subgoal + unfolding b_def + apply(rule cond_TBOUND_mono[where b = 1], rule cond_TBOUND_return, simp) + done + apply sep_auto + subgoal for a ys + apply(rule cond_TBOUND_mono[ + where b = "((5 + 5 * nat \log 2 (real n)\) + max 1 ((7 + 7 * nat \log 2 (real n)\) + 1)) + +(b ys n + 1)"]) + apply(rule cond_TBOUND_bind[where Q = "\ r. vebt_assn n S ti"]) + apply(rule cond_TBOUND | rule mmap_pres | sep_auto | rule cond_TBOUND_cons)+ + unfolding b_def + apply simp + done + done + +lemma TBOUND_test[cond_TBOUND]: "\\x\set xs. x<2^n; n>0 \ \ + \
\ (n> 0) \
TBOUND (test n xs ys) (10 * 2^n + ( + ( length (0#xs) * (13 + 13 * nat \log 2 n \) + 1) + + (1 + length ys * ( 5 + 5 * nat \log 2 (real n)\ + 9 + 7 * nat \log 2 (real n)\))))" + unfolding test_def + apply(cond_TBOUND| rule htt_elim[OF vebt_buildupi_rule] | sep_auto)+ + done + +lemma test_hoare_with_time: "\\x\set xs. x<2^n; n>0\ \ + (test n xs ys) <\r. \(r = map (\y. (GREATEST y'. y'\insert 0 (set xs) \ y'\y)) ys) * true > + T[10 * 2 ^ n + + (length (0 # xs) * (13 + 13 * nat \log 2 (real n)\) + 1 + + (1 + length ys * (5 + 5 * nat \log 2 (real n)\ + 9 + 7 * nat \log 2 (real n)\)))]" + apply(rule htt_intro, rule test_hoare, simp+) + apply(rule cond_TBOUND_mono, rule cond_TBOUND_cons) + defer + apply(rule TBOUND_test, simp+) + done + +end diff --git a/thys/Van_Emde_Boas_Trees/VEBT_Example_Setup.thy b/thys/Van_Emde_Boas_Trees/VEBT_Example_Setup.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/VEBT_Example_Setup.thy @@ -0,0 +1,77 @@ +(*by Lammich and Ammer*) +section \Setup for Usage Example\ +theory VEBT_Example_Setup +imports "Time_Reasoning/Simple_TBOUND_Cond" +begin + text \We provide a few monadic combinators and associated reasoning rules, + that are required for our usage example. + + Warning: ad-hoc and highly incomplete! + \ + + fun mfold where + "mfold f [] s = return s" + | "mfold f (x#xs) s = do { s \ f x s; mfold f xs s }" + + fun mmap where + "mmap f [] = return []" + | "mmap f (x#xs) = do { y\f x; ys \ mmap f xs; return (y#ys) }" + + definition mIf :: "bool Heap \ 'a Heap \ 'a Heap \ 'a Heap" + ("(if\<^sub>m (_)/ then (_)/ else (_))" [0, 0, 10] 10) + where "mIf b t e \ do { bb \ b; if bb then t else e }" + + lemma mIf_rule[sep_decon_rules]: + "

do { bb \ b; if bb then t else e } \

mIf b t e " + unfolding mIf_def by simp + + abbreviation (input) pure_app (infix "$\<^sub>m" 10) where "f $\<^sub>m m \ do { x\m; return (f x) }" + + + lemma mmap_pure_aux: + assumes "\x. x\set xs \

fi x <\r. P * \(r = f x)>" + shows "

mmap fi xs <\ys. P * \(ys = map f xs )>" + using assms + proof (induction xs) + case Nil + then show ?case by sep_auto + next + case (Cons a xs) + + note [sep_heap_rules] = Cons + + show ?case + by sep_auto + + qed + +lemma mmap_pres: + assumes "\x. x\set xs \

fi x <\r. P>" + shows "

mmap fi xs <\ys. P >" + using assms + apply(induction xs) + apply sep_auto+ + done + + + lemma cond_TBOUND_mIf[cond_TBOUND]: + assumes "\

P \
TBOUND cond b1" + and "\ h. \
Q (the_res cond h)\
TBOUND t b2" + and "\ h.\
Q (the_res cond h) \
TBOUND e b3" + and "

cond " + shows "\

P \
TBOUND (if\<^sub>m cond then t else e) (b1 + max b2 b3)" + unfolding mIf_def + apply(rule cond_TBOUND_bind) + apply (rule assms)+ + subgoal for x h + apply(auto split: if_split) + apply(rule cond_TBOUND_mono[where b = b2]) + using assms apply (metis (full_types)) + apply simp + apply(rule cond_TBOUND_mono[where b = b3]) + using assms apply (metis (full_types)) + apply simp + done + done + +end diff --git a/thys/Van_Emde_Boas_Trees/VEBT_Height.thy b/thys/Van_Emde_Boas_Trees/VEBT_Height.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/VEBT_Height.thy @@ -0,0 +1,219 @@ +(*by Ammer*) +theory VEBT_Height imports VEBT_Definitions Complex_Main +begin + +context VEBT_internal begin + +section \Heights of van Emde Boas Trees\ + +fun height::"VEBT \ nat" where + "height (Leaf a b) = 0"| + "height (Node _ deg treeList summary) = (1+ Max (height ` (insert summary (set treeList))))" + +abbreviation "lb x \ log 2 x" + +lemma setceilmax: "invar_vebt s m \\ t \ set listy. invar_vebt t n + \m = Suc n \(\ t \ set listy. height t = \lb n \ ) \ height s = \lb m\ + \ Max (height ` (insert s (set listy))) = \lb m\" +proof(induction listy) + case Nil + hence "Max (height ` (insert s(set []))) = height s" by simp + then show ?case using Nil by simp +next + case (Cons a list) + have "Max (height ` insert s (set (a # list))) = + max (height a) (Max (height ` insert s (set ( list))))" + by (simp add: insert_commute) + moreover have "max (height a) (Max (height ` insert s (set ( list)))) = max (height a) \lb m \" + using Cons insert_iff list.simps(15) max_def of_nat_max by force + moreover have " \ t \ set (a#list). invar_vebt t n " using Cons by simp + moreover hence "invar_vebt a n" by simp + hence "m \ n" + by (simp add: Cons.prems(3)) + hence "lb m \ lb n" + using deg_not_0 \invar_vebt a n\ by fastforce + hence "\ lb m\ \ \ lb n\" + by (simp add: ceiling_mono) + moreover hence " max \log 2 n \ \log 2 m \ = \log 2 m \" by simp + ultimately show ?case + using Cons.prems(4) \invar_vebt a n\ + by (metis list.set_intros(1)) +qed + +lemma log_ceil_idem: + assumes"(x::real) \ 1" + shows "\lb x \ = \lb \x\\" +proof- + have "\log 2 x \ \ 0" + by (smt (verit, ccfv_SIG) assms zero_le_ceiling zero_le_log_cancel_iff) + have " \log 2 x \ -1 < log 2 x \log 2 x \ \log 2 x \" + by linarith + moreover hence "2 powr (\log 2 x \ -1) < x \ x \ 2 powr ( \log 2 x \)" + by (smt (verit, ccfv_SIG) assms less_log_iff real_nat_ceiling_ge) + moreover hence "2 powr ((\log 2 x \ -1)) < \x\" and " \x\ \ 2 powr (\log 2 x \)" + apply linarith + using \0 \ \log 2 x\\ calculation(2) ceiling_mono powr_int by fastforce + moreover hence " \log 2 x \ -1 < log 2 \ x \ \log 2 \x\ \ \log 2 x \" + by (smt (verit, best) assms ceiling_correct less_log_iff) + ultimately show ?thesis + by linarith +qed + +lemma heigt_uplog_rel:"invar_vebt t n \ (height t) = \lb n\" +proof(induction t n rule: invar_vebt.induct) + case (1 a b) + then show ?case by simp +next + case (2 treeList n summary m deg) + hence "m \ n" by simp + hence "log 2 m \ log 2 n" + by (simp add: "2.hyps"(3)) + hence "\ log 2 m\ \ \ log 2 n\" + by (simp add: "2.hyps"(3)) + have "Max (height ` (insert summary (set treeList))) = \ log 2 m\" + by (smt (verit, best) "2.IH"(1) "2.IH"(2) "2.hyps"(3) List.finite_set Max_in empty_is_image finite_imageI finite_insert image_iff insert_iff insert_not_empty) + hence "height (Node None deg treeList summary) = 1+ \ log 2 m\" by simp + moreover have "1+ \ log 2 m\ = \1+ log 2 m\" by linarith + moreover have "1+ log 2 m = log 2 (2*m)" + using "2.hyps"(1) deg_not_0 log_mult by force + moreover hence "\1+ log 2 m\ = \log 2 (2*m)\" by simp + moreover hence " \log 2 (2*m)\ = \log 2 (n+m)\" + using "2.hyps"(3) by force + ultimately show ?case + using "2.hyps"(4) by metis +next + case (3 treeList n summary m deg) + hence 00: "n \ 1 \ Suc n = m" + using set_n_deg_not_0 by blast + hence 0:"m \ n"using 3 by simp + hence 1:"log 2 m \ log 2 n" + using "3.IH"(1) "3.hyps"(2) set_n_deg_not_0 by fastforce + hence 2:"\ log 2 m\ \ \ log 2 n\" + by (simp add: ceiling_mono) + have 3: "Max (height ` (insert summary (set treeList))) = \ log 2 m\" + using "3.IH"(1) "3.IH"(2) "3.hyps"(3) List.finite_set Max_in empty_is_image + finite_imageI finite_insert image_iff insert_iff insert_not_empty "3.hyps"(1) setceilmax by auto + hence 4:"height (Node None deg treeList summary) = 1+ \ log 2 m\" by simp + have 5:"1+ \ log 2 m\ = \1+ log 2 m\" by linarith + have 6:"1+ log 2 m = log 2 (m+m)" + using "3.hyps"(1) deg_not_0 log_mult by force + hence 7:"log 2 (m+n) = 1+log 2 ((n+m) / 2) " + by (simp add: "3.hyps"(3) log_divide) + have 8:"log 2 ((n+m) / 2) = log 2 (n + 1/2)" + by (smt (verit, best) "3.hyps"(3) field_sum_of_halves of_nat_Suc of_nat_add) + have 9 : "\ log 2 (n + 1/2) \ = \ log 2 \n + 1/2 \ \" + by (smt (verit) "00" field_sum_of_halves log_ceil_idem of_nat_1 of_nat_mono) + hence 10: " \n + 1/2 \ = m" using 00 by linarith + hence 11: "\ log 2 (n + 1/2) \ = \ log 2 m \ " using 9 by simp + hence 12:"\ 1+ log 2 (n + 1/2) \ = \1+ log 2 m \" + by (smt (verit) ceiling_add_one) + hence "\ log 2 (n + n+1) \ = \ log 2 (m+m) \" + using "3.hyps"(3) "6" "7" "8" by force + then show ?case + by (metis "12" "3.hyps"(4) "4" "5" "7" "8" add.commute) +next + case (4 treeList n summary m deg mi ma) + hence "m \ n" by simp + hence "log 2 m \ log 2 n" + by (simp add: "4.hyps"(3)) + hence "\ log 2 m\ \ \ log 2 n\" + by (simp add: "4.hyps"(3)) + have "Max (height ` (insert summary (set treeList))) = \ log 2 m\" + by (smt (verit, best) "4.IH"(1) "4.IH"(2) "4.hyps"(3) List.finite_set Max_in empty_is_image finite_imageI finite_insert image_iff insert_iff insert_not_empty) + hence "height (Node None deg treeList summary) = 1+ \ log 2 m\" by simp + moreover have "1+ \ log 2 m\ = \1+ log 2 m\" by linarith + moreover have "1+ log 2 m = log 2 (2*m)" + using "4.hyps"(1) deg_not_0 log_mult by force + moreover hence "\1+ log 2 m\ = \log 2 (2*m)\" by simp + moreover hence " \log 2 (2*m)\ = \log 2 (n+m)\" + using "4.hyps"(3) by force + ultimately show ?case + by (metis "4.hyps"(4) height.simps(2)) +next + case (5 treeList n summary m deg mi ma) + hence 00: "n \ 1 \ Suc n = m" + using set_n_deg_not_0 by blast + hence 0:"m \ n"using 5 by simp + hence 1:"log 2 m \ log 2 n" + using "5.IH"(1) "5.hyps"(2) set_n_deg_not_0 by fastforce + hence 2:"\ log 2 m\ \ \ log 2 n\" + by (simp add: ceiling_mono) + have 3: "Max (height ` (insert summary (set treeList))) = \ log 2 m\" + using "5.IH"(1) "5.IH"(2) "5.hyps"(3) List.finite_set Max_in empty_is_image + finite_imageI finite_insert image_iff insert_iff insert_not_empty "5.hyps"(1) setceilmax by auto + hence 4:"height (Node None deg treeList summary) = 1+ \ log 2 m\" by simp + have 5:"1+ \ log 2 m\ = \1+ log 2 m\" by linarith + have 6:"1+ log 2 m = log 2 (m+m)" + using "5.hyps"(1) deg_not_0 log_mult by force + hence 7:"log 2 (m+n) = 1+log 2 ((n+m) / 2) " + by (simp add: "5.hyps"(3) log_divide) + have 8:"log 2 ((n+m) / 2) = log 2 (n + 1/2)" + by (smt (verit, best) "5.hyps"(3) field_sum_of_halves of_nat_Suc of_nat_add) + have 9 : "\ log 2 (n + 1/2) \ = \ log 2 \n + 1/2 \ \" + by (smt (verit) "00" field_sum_of_halves log_ceil_idem of_nat_1 of_nat_mono) + hence 10: " \n + 1/2 \ = m" using 00 by linarith + hence 11: "\ log 2 (n + 1/2) \ = \ log 2 m \ " using 9 by simp + hence 12:"\ 1+ log 2 (n + 1/2) \ = \1+ log 2 m \" + by (smt (verit) ceiling_add_one) + hence "\ log 2 (n + n+1) \ = \ log 2 (m+m) \" + using "5.hyps"(3) "6" "7" "8" by force + then show ?case + using "4" "5" "5.hyps"(3) "5.hyps"(4) "6" by force +qed + +lemma two_powr_height_bound_deg: + assumes "invar_vebt t n " + shows " 2^(height t) \ 2*(n::nat)" +proof- + have " (height t) = \ log 2 n\" + by (simp add: assms heigt_uplog_rel) + moreover have "\ log 2 n\ \ log 2 n +1" by simp + moreover hence "2 powr \ log 2 n\ \ 2 powr (log 2 n +1)" by simp + moreover have " 2 powr (log 2 n +1) = 2 powr 1 * 2 powr (log 2 n)" + by (simp add: powr_add) + moreover hence " 2 powr (log 2 n +1) = 2 * n" + using assms deg_not_0 by force + ultimately show ?thesis + by (metis linorder_not_less not_one_le_zero of_int_0 of_int_less_iff of_int_numeral of_int_of_nat_eq of_nat_le_iff one_add_one order_less_le powr_realpow real_of_nat_eq_numeral_power_cancel_iff zle_add1_eq_le) +qed + +text \Main Theorem\ + +theorem height_double_log_univ_size: + assumes "u = 2^deg" and "invar_vebt t deg " + shows "height t \ 1 + lb (lb u)" +proof- + have "(height t) = \lb deg\" + by (simp add: assms(2) heigt_uplog_rel) + have "2^(height t) \ 2 * deg" using assms(2) two_powr_height_bound_deg[of t deg] + by (meson dual_order.eq_iff dual_order.trans self_le_ge2_pow) + hence "height t \ 1 + lb deg" + using \int (height t) = \lb (real deg)\\ by linarith + hence "height t \ 1 + lb (lb u)" using assms by simp + thus ?thesis by simp +qed + +lemma height_compose_list: " t\ set treeList \ + Max (height ` (insert summary (set treeList))) \ height t" + apply(induction treeList) apply simp + by (meson List.finite_set Max_ge finite_imageI finite_insert image_eqI subsetD subset_insertI) + +lemma height_compose_child: " t\ set treeList \ + height (Node info deg treeList summary) \ 1+ height t" by simp + +lemma height_compose_summary: " height (Node info deg treeList summary) \ 1+ height summary" by simp + +lemma height_i_max: " i < length x13 \ + height (x13 ! i) \ max foo (Max (height ` set x13))" + by (meson List.finite_set Max_ge finite_imageI max.coboundedI2 nth_mem rev_image_eqI) + +lemma max_ins_scaled: " n* height x14 \ m + n* Max (insert (height x14) (height ` set x13))" + by (meson List.finite_set Max_ge finite_imageI finite_insert insertI1 mult_le_mono2 trans_le_add2) + +lemma max_idx_list: + assumes "i < length x13 " + shows " n * height (x13 !i) \ Suc (Suc (n * max (height x14) (Max (height ` set x13))))" + by (metis assms height_i_max less_Suc_eq mult_le_mono2 nat_less_le) + +end +end diff --git a/thys/Van_Emde_Boas_Trees/VEBT_Insert.thy b/thys/Van_Emde_Boas_Trees/VEBT_Insert.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/VEBT_Insert.thy @@ -0,0 +1,825 @@ +(*by Ammer*) +theory VEBT_Insert imports VEBT_Member +begin + + +section \Insert Function\ + +context begin + interpretation VEBT_internal . + +fun vebt_insert :: "VEBT \ nat \VEBT" where + "vebt_insert (Leaf a b) x = (if x=0 then Leaf True b else if x = 1 then Leaf a True else Leaf a b)"| + "vebt_insert (Node info 0 ts s) x = (Node info 0 ts s)"| + "vebt_insert (Node info (Suc 0) ts s) x = (Node info (Suc 0) ts s)"| + "vebt_insert (Node None (Suc deg) treeList summary) x = + (Node (Some (x,x)) (Suc deg) treeList summary)"| + "vebt_insert (Node (Some (mi,ma)) deg treeList summary) x = ( + let xn = (if x < mi then mi else x); + minn = (if x < mi then x else mi); + l = low xn (deg div 2); + h = high xn (deg div 2) in ( + if h < length treeList \ \ (x = mi \ x = ma) then + Node (Some (minn, max xn ma)) deg (treeList[h:= vebt_insert (treeList ! h) l]) + (if minNull (treeList ! h) then vebt_insert summary h else summary) + else (Node (Some (mi, ma)) deg treeList summary)))" + +end + +context VEBT_internal begin + +lemma insert_simp_norm: + assumes "high x (deg div 2) < length treeList " and "(mi::nat)< x" and "deg\ 2" and "x \ ma" + shows "vebt_insert (Node (Some (mi,ma)) deg treeList summary) x = + Node (Some (mi, max x ma)) deg (treeList [(high x (deg div 2)):= vebt_insert (treeList ! (high x (deg div 2))) (low x (deg div 2))]) + (if minNull (treeList ! (high x (deg div 2))) then vebt_insert summary (high x (deg div 2)) else summary) " +proof- + have 11:"vebt_insert (Node (Some (mi,ma)) deg treeList summary) x = + (let xn = (if x < mi then mi else x); minn = (if x< mi then x else mi); + l= low xn (deg div 2); h = high xn (deg div 2) + in + ( if h < length treeList \ \ (x = mi \ x = ma)then + Node (Some (minn, max xn ma)) deg (treeList [h:= vebt_insert (treeList ! h) l]) + (if minNull (treeList ! h) then vebt_insert summary h else summary) + else (Node (Some (mi, ma)) deg treeList summary)))" + using assms(3) vebt_insert.simps(5)[of mi ma "deg-2" treeList summary x] + by (smt add_numeral_left le_add_diff_inverse numerals(1) plus_1_eq_Suc semiring_norm(2)) + have 14:"vebt_insert (Node (Some (mi,ma)) deg treeList summary) x = + Node (Some (mi, max x ma)) deg (treeList[(high x (deg div 2)) := vebt_insert (treeList ! (high x (deg div 2))) (low x (deg div 2))]) + (if minNull (treeList ! (high x (deg div 2))) then vebt_insert summary (high x (deg div 2)) else summary)" + using 11 apply (simp add: Let_def) + apply (auto simp add: If_def) + using assms not_less_iff_gr_or_eq apply blast+ + done + then show ?thesis by blast +qed + +lemma insert_simp_excp: + assumes "high mi (deg div 2) < length treeList " and " (x::nat) < mi" and "deg\ 2" and "x \ ma" + shows "vebt_insert (Node (Some (mi,ma)) deg treeList summary) x = + Node (Some (x, max mi ma)) deg (treeList[(high mi (deg div 2)) := vebt_insert (treeList ! (high mi (deg div 2))) (low mi (deg div 2))]) + (if minNull (treeList ! (high mi (deg div 2))) then vebt_insert summary (high mi (deg div 2)) else summary) " +proof- + have 11:"vebt_insert (Node (Some (mi,ma)) deg treeList summary) x = + ( let xn = (if x < mi then mi else x); minn = (if x< mi then x else mi); + l= low xn (deg div 2); h = high xn (deg div 2) + in + ( if h < length treeList \ \ (x = mi \ x = ma)then + Node (Some (minn, max xn ma)) deg (treeList[h:=vebt_insert (treeList ! h) l]) + (if minNull (treeList ! h) then vebt_insert summary h else summary) + else (Node (Some (mi, ma)) deg treeList summary)))" + using assms(3) vebt_insert.simps(5)[of mi ma "deg-2" treeList summary x] + by (smt add_numeral_left le_add_diff_inverse numerals(1) plus_1_eq_Suc semiring_norm(2)) + have 14:"vebt_insert (Node (Some (mi,ma)) deg treeList summary) x = + Node (Some (x, max mi ma)) deg ( treeList[ (high mi (deg div 2)) := vebt_insert (treeList ! (high mi (deg div 2))) (low mi (deg div 2))]) + (if minNull (treeList ! (high mi (deg div 2))) then vebt_insert summary (high mi (deg div 2)) else summary)" + using 11 apply (simp add: Let_def) + apply (auto simp add: If_def) + using assms not_less_iff_gr_or_eq apply blast+ + done + then show ?thesis by blast +qed + + +lemma insert_simp_mima: assumes "x = mi \ x = ma" and "deg \ 2" + shows "vebt_insert (Node (Some (mi,ma)) deg treeList summary) x = (Node (Some (mi,ma)) deg treeList summary)" +proof - + have 11:"vebt_insert (Node (Some (mi,ma)) deg treeList summary) x = + ( let xn = (if x < mi then mi else x); minn = (if x< mi then x else mi); + l= low xn (deg div 2); h = high xn (deg div 2) + in + ( if h < length treeList \ \ (x = mi \ x = ma)then + Node (Some (minn, max xn ma)) deg (treeList[h:= vebt_insert (treeList ! h) l]) + (if minNull (treeList ! h) then vebt_insert summary h else summary) + else (Node (Some (mi, ma)) deg treeList summary)))" using assms vebt_insert.simps(5)[of mi ma "deg-2" treeList summary x] + by (smt add_numeral_left le_add_diff_inverse numerals(1) plus_1_eq_Suc semiring_norm(2)) + then show ?thesis + using assms(1) by auto +qed + + +lemma valid_insert_both_member_options_add: "invar_vebt t n \ x< 2^n \ both_member_options (vebt_insert t x) x" +proof(induction t n arbitrary: x rule: invar_vebt.induct) + case (1 a b) + then show ?case apply(cases x) + by (auto simp add: both_member_options_def) +next + case (2 treeList n summary m deg) + hence "deg>1" + using valid_tree_deg_neq_0 + by (metis One_nat_def Suc_lessI add_gr_0 add_self_div_2 neq0_conv one_div_two_eq_zero) + then show ?case using vebt_insert.simps(4)[of "deg-2" treeList summary x ] + by (smt Suc_1 Suc_leI add_numeral_left both_member_options_def le_add_diff_inverse membermima.simps(4) + numerals(1) plus_1_eq_Suc semiring_norm(2)) +next + case (3 treeList n summary m deg) + hence "\t\set treeList. invar_vebt t n" by blast + hence "n > 0" using set_n_deg_not_0[of treeList n m] "3"(4) + by linarith + hence "deg \ 2" + by (simp add: "3.hyps"(3) "3.hyps"(4) Suc_leI) + then show ?case using vebt_insert.simps(4)[of "deg-2" treeList summary x ] + by (smt Suc_1 Suc_leI add_numeral_left both_member_options_def le_add_diff_inverse membermima.simps(4) + numerals(1) plus_1_eq_Suc semiring_norm(2)) +next + case (4 treeList n summary m deg mi ma) + hence "length treeList =2^n" by blast + hence "high x n < length treeList" + using "4.hyps"(1) "4.hyps"(3) "4.hyps"(4) "4.prems" deg_not_0 exp_split_high_low(1) by auto + hence "mi < 2^deg" + using "4.hyps"(7) "4.hyps"(8) le_less_trans by blast + then show ?case + proof(cases "x = mi \ x = ma") + case True + then show ?thesis using vebt_insert.simps(5)[of mi ma "deg-2" treeList summary x] + by (smt "4.hyps"(1) "4.hyps"(3) "4.hyps"(4) add_diff_inverse_nat add_numeral_left add_self_div_2 both_member_options_def div_if membermima.simps(4) numerals(1) plus_1_eq_Suc semiring_norm(2) valid_tree_deg_neq_0) + next + case False + hence "\ (x = mi \ x = ma)" by simp + then show ?thesis + proof(cases "x < mi") + case True + hence "high mi n < length treeList" + using "4.hyps"(1) "4.hyps"(2) "4.hyps"(3) "4.hyps"(4) \mi < 2 ^ deg\ deg_not_0 exp_split_high_low(1) by auto + hence "vebt_insert ( Node (Some (mi, ma)) deg treeList summary) x = + Node (Some (x, max mi ma)) deg ( treeList[(high mi n):= vebt_insert (treeList ! (high mi n)) (low mi n)] ) + (if minNull (treeList ! high mi n) then vebt_insert summary (high mi n) else summary)" + by (metis "4.hyps"(1) "4.hyps"(3) "4.hyps"(4) False True add_self_div_2 div_if insert_simp_excp not_less valid_tree_deg_neq_0) + then show ?thesis + by (smt "4.hyps"(1) "4.hyps"(4) Suc_pred add_diff_inverse_nat both_member_options_def membermima.simps(4) valid_tree_deg_neq_0 zero_eq_add_iff_both_eq_0) + next + case False + hence "vebt_insert ( Node (Some (mi, ma)) deg treeList summary) x = + Node (Some (mi, max x ma)) deg (treeList[ (high x n):=vebt_insert (treeList ! (high x n)) (low x n)]) + (if minNull (treeList ! high x n) then vebt_insert summary (high x n) else summary)" + by (metis "4.hyps"(1) "4.hyps"(3) "4.hyps"(4) \\ (x = mi \ x = ma)\ \high x n < length treeList\ add_self_div_2 div_if insert_simp_norm linorder_neqE_nat not_less valid_tree_deg_neq_0) + have "low x n < 2^n \ high x n < 2^n" + using "4.hyps"(2) "4.hyps"(3) \high x n < length treeList\ low_def by auto + have "invar_vebt (treeList ! (high x n)) n" + by (metis "4.IH"(1) \high x n < length treeList\ inthall member_def) + hence "both_member_options (vebt_insert (treeList ! (high x n)) (low x n)) (low x n)" + by (simp add: "4.IH"(1) \high x n < length treeList\ low_def) + have " (treeList[ (high x n):=vebt_insert (treeList ! (high x n)) (low x n)]) ! (high x n) = vebt_insert (treeList ! (high x n)) (low x n)" + by (simp add: \high x n < length treeList\) + then show ?thesis + using both_member_options_ding[of "Some (mi, max x ma)" deg + "(take (high x n) treeList @ [vebt_insert (treeList ! (high x n)) (low x n)] @ drop (high x n +1) treeList)" + "if minNull (treeList ! high x n) then vebt_insert summary (high x n) else summary" n x] + by (metis "4.hyps"(2) "4.hyps"(3) "4.hyps"(4) Suc_1 Suc_leD + \vebt_insert (Node (Some (mi, ma)) deg treeList summary) x = Node (Some (mi, max x ma)) deg (treeList[high x n := vebt_insert (treeList ! high x n) (low x n)]) (if minNull (treeList ! high x n) then vebt_insert summary (high x n) else summary)\ \both_member_options (vebt_insert (treeList ! high x n) (low x n)) (low x n)\ \low x n < 2 ^ n \ high x n < 2 ^ n\ \invar_vebt (treeList ! high x n) n\ add_self_div_2 both_member_options_from_chilf_to_complete_tree deg_not_0 div_greater_zero_iff length_list_update) + qed + qed +next + case (5 treeList n summary m deg mi ma) + hence "length treeList =2^m" by blast + hence "high x n < length treeList" + by (metis "5.hyps"(4) "5.prems" Euclidean_Division.div_eq_0_iff div_exp_eq high_def length_0_conv length_greater_0_conv zero_less_numeral zero_less_power) + hence "mi<2^deg" + using "5.hyps"(7) "5.hyps"(8) le_less_trans by blast + then show ?case + proof(cases "x = mi \ x = ma") + case True + then show ?thesis using vebt_insert.simps(5)[of mi ma "deg-2" treeList summary x] + by (smt "5.hyps"(3) "5.hyps"(4) Suc_leI add_Suc_right add_diff_inverse_nat add_numeral_left both_member_options_def diff_is_0_eq' vebt_insert.simps(3) membermima.simps(4) not_add_less1 numerals(1) plus_1_eq_Suc semiring_norm(2)) + next + case False + hence "\ (x = mi \ x = ma)" by simp + then show ?thesis + proof(cases "x < mi") + case True + hence "high mi n < length treeList" + by (metis "5.hyps"(2) "5.hyps"(4) Euclidean_Division.div_eq_0_iff \mi < 2 ^ deg\ div_exp_eq high_def length_0_conv length_greater_0_conv zero_less_numeral zero_less_power) + hence "vebt_insert ( Node (Some (mi, ma)) deg treeList summary) x = + Node (Some (x, max mi ma)) deg ( treeList[ (high mi n):=vebt_insert (treeList ! (high mi n)) (low mi n)] ) + (if minNull (treeList ! high mi n) then vebt_insert summary (high mi n) else summary)" + using insert_simp_excp[of mi deg treeList x ma summary] + "5"(1) "5.hyps"(3) "5.hyps"(4) False True add_Suc_right add_self_div_2 + append_Cons div_less even_Suc_div_two in_set_conv_decomp not_less odd_add valid_tree_deg_neq_0 + by (smt (z3) nth_mem) + then show ?thesis + by (simp add: "5.hyps"(3) "5.hyps"(4) both_member_options_def) + next + case False + hence "vebt_insert ( Node (Some (mi, ma)) deg treeList summary) x = + Node (Some (mi, max x ma)) deg (treeList[(high x n):= vebt_insert (treeList ! (high x n)) (low x n)]) + (if minNull (treeList ! high x n) then vebt_insert summary (high x n) else summary)" + by (smt (z3) "5.IH"(1) "5.hyps"(3) "5.hyps"(4) \\ (x = mi \ x = ma)\ \high x n < length treeList\ add_Suc_right add_self_div_2 deg_not_0 div_greater_zero_iff even_Suc_div_two insert_simp_norm linorder_neqE_nat nth_mem odd_add) + have "low x n < 2^n \ high x n < 2^m" + using "5.hyps"(2) "5.hyps"(3) \high x n < length treeList\ low_def by auto + have "invar_vebt (treeList ! (high x n)) n" + by (metis "5.IH"(1) \high x n < length treeList\ inthall member_def) + hence "both_member_options (vebt_insert (treeList ! (high x n)) (low x n)) (low x n)" + by (metis "5.IH"(1) \high x n < length treeList\ \low x n < 2 ^ n \ high x n < 2 ^ m\ inthall member_def) + have " (treeList[ (high x n):=vebt_insert (treeList ! (high x n)) (low x n)]) ! (high x n) = vebt_insert (treeList ! (high x n)) (low x n)" + by (meson \high x n < length treeList\ nth_list_update_eq) + then show ?thesis + using both_member_options_ding[of "Some (mi, max x ma)" deg + "(treeList[ (high x n):=vebt_insert (treeList ! (high x n)) (low x n)])" + "if minNull (treeList ! high x n) then vebt_insert summary (high x n) else summary" n x] + using "5.hyps"(2) "5.hyps"(3) "5.hyps"(4) \vebt_insert (Node (Some (mi, ma)) deg treeList summary) x = Node (Some (mi, max x ma)) deg (treeList[high x n := vebt_insert (treeList ! high x n) (low x n)]) (if minNull (treeList ! high x n) then vebt_insert summary (high x n) else summary)\ \both_member_options (vebt_insert (treeList ! high x n) (low x n)) (low x n)\ \low x n < 2 ^ n \ high x n < 2 ^ m\ both_member_options_from_chilf_to_complete_tree by auto + qed + qed +qed + +lemma valid_insert_both_member_options_pres: "invar_vebt t n \ x<2^n \ y < 2^n \ both_member_options t x + \ both_member_options (vebt_insert t y) x" +proof(induction t n arbitrary: x y rule: invar_vebt.induct) + case (1 a b) + then show ?case by (simp add: both_member_options_def) +next + case (2 treeList n summary m deg) + then show ?case + using vebt_member.simps(2) invar_vebt.intros(2) valid_member_both_member_options by blast +next + case (3 treeList n summary m deg) + then show ?case + using vebt_member.simps(2) invar_vebt.intros(3) valid_member_both_member_options by blast +next + case (4 treeList n summary m deg mi ma) + hence 00:"deg = n + m \ length treeList = 2^n \ n = m \ n \ 1 \ deg \ 2" + by (metis One_nat_def Suc_leI add_mono_thms_linordered_semiring(1) deg_not_0 one_add_one) + hence xyprop: "high x n < 2^m \ high y n < 2^m" + by (metis "4.prems"(1) "4.prems"(2) high_def less_mult_imp_div_less mult_2 power2_eq_square power_even_eq) + have "low x n <2^n \ low y n< 2^n" + by (simp add: low_def) + hence "x = mi \ x = ma \ both_member_options (treeList ! (high x n)) (low x n)" + by (smt "00" "4.prems"(3) add_Suc_right add_self_div_2 both_member_options_def le_add_diff_inverse membermima.simps(4) naive_member.simps(3) plus_1_eq_Suc) + have 001:"invar_vebt (Node (Some (mi, ma)) deg treeList summary) deg" using invar_vebt.intros(4)[of treeList n summary m deg mi ma] "4" by simp + then show ?case + proof(cases "x = y") + case True + hence "both_member_options (vebt_insert (Node (Some (mi, ma)) deg treeList summary) y) y" + using 001 valid_insert_both_member_options_add[of "(Node (Some (mi, ma)) deg treeList summary)" deg y ] + using "4.prems"(2) by blast + then show ?thesis + by (simp add: True) + next + case False + then show ?thesis + proof(cases "y = mi \ y = ma") + case True + have "Suc (Suc (deg -2)) = deg" + using "00" by linarith + hence "vebt_insert (Node (Some (mi, ma)) deg treeList summary) y = Node (Some (mi, ma)) deg treeList summary" + using vebt_insert.simps(5)[of mi ma "deg-2" treeList summary x] 00 True insert_simp_mima by blast + then show ?thesis + by (simp add: "4.prems"(3)) + next + case False + hence 0:"y \ mi \ y \ ma" by simp + then show ?thesis + proof(cases "x = mi") + case True + hence 1:"x = mi" by simp + then show ?thesis + proof(cases "x < y") + case True + have 14:"vebt_insert (Node (Some (mi,ma)) deg treeList summary) y = + Node (Some (x, max y ma)) deg (treeList [ (high y n):=vebt_insert (treeList ! (high y n)) (low y n)] ) + (if minNull (treeList ! (high y n)) then vebt_insert summary (high y n) else summary)" + using "00" "1" False True insert_simp_norm xyprop by auto + then show ?thesis + by (metis "001" Suc_pred both_member_options_def deg_not_0 membermima.simps(4)) + next + case False + have 14:"vebt_insert (Node (Some (mi,ma)) deg treeList summary) y = + Node (Some (y, max x ma)) deg (treeList [ (high x n) :=vebt_insert (treeList ! (high x n)) (low x n)]) + (if minNull (treeList ! (high x n)) then vebt_insert summary (high x n) else summary)" + by (metis "0" "00" False True add_self_div_2 insert_simp_excp linorder_neqE_nat xyprop) + have 15: " invar_vebt (treeList ! (high x n)) n" + by (metis "4"(1) "4.hyps"(2) in_set_member inthall xyprop) + hence 16: "both_member_options (vebt_insert (treeList ! high x n) (low x n)) (low x n)" + using \low x n < 2 ^ n \ low y n < 2 ^ n\ valid_insert_both_member_options_add by blast + then show ?thesis + by (metis "00" "14" Suc_1 add_leD1 add_self_div_2 both_member_options_from_chilf_to_complete_tree length_list_update nth_list_update_eq plus_1_eq_Suc xyprop) + + qed + next + case False + hence "mi \ ma" + using "001" "4.prems"(3) less_irrefl member_inv valid_member_both_member_options by fastforce + hence "both_member_options (treeList !(high x n) ) (low x n) \ x = ma" + using False \x = mi \ x = ma \ both_member_options (treeList ! high x n) (low x n)\ by blast + have "high ma n < 2^n" + by (metis "4.hyps"(3) "4.hyps"(4) "4.hyps"(8) high_def less_mult_imp_div_less mult_2 power2_eq_square power_even_eq) + hence "both_member_options (treeList !(high ma n) ) (low ma n)" + using "4.hyps"(3) "4.hyps"(9) \mi \ ma\ by blast + hence "both_member_options (treeList !(high x n) ) (low x n)" + using \both_member_options (treeList ! high x n) (low x n) \ x = ma\ by blast + then show ?thesis + proof(cases "mi < y") + case True + have 14:"vebt_insert (Node (Some (mi,ma)) deg treeList summary) y = + Node (Some (mi, max y ma)) deg (treeList[(high y n):=vebt_insert (treeList ! (high y n)) (low y n)]) + (if minNull (treeList ! (high y n)) then vebt_insert summary (high y n) else summary)" + using "0" "00" True insert_simp_norm xyprop by auto + have "invar_vebt (treeList ! (high x n)) n" + by (metis "4.IH"(1) "4.hyps"(2) in_set_member inthall xyprop) + then show ?thesis + proof(cases "high x n = high y n") + case True + have "both_member_options (vebt_insert (treeList ! (high y n)) (low y n)) (low x n)" + using "4.IH"(1) "4.hyps"(2) True \both_member_options (treeList ! high x n) (low x n)\ \low x n < 2 ^ n \ low y n < 2 ^ n\ xyprop by auto + then show ?thesis + by (metis "00" "14" Suc_1 True add_leD1 add_self_div_2 both_member_options_from_chilf_to_complete_tree length_list_update nth_list_update_eq plus_1_eq_Suc xyprop) + next + case False + have "(treeList[ (high y n):=vebt_insert (treeList ! (high y n)) (low y n)]) ! (high x n) = treeList ! (high x n)" + using False by auto + then show ?thesis + by (metis "00" "14" One_nat_def Suc_leD \both_member_options (treeList ! high x n) (low x n)\ add_self_div_2 both_member_options_from_chilf_to_complete_tree length_list_update numeral_2_eq_2 xyprop) + qed + next + case False + have 14:"vebt_insert (Node (Some (mi,ma)) deg treeList summary) y = + Node (Some (y, max mi ma)) deg (treeList[ (high mi n):=vebt_insert (treeList ! (high mi n)) (low mi n)]) + (if minNull (treeList ! (high mi n)) then vebt_insert summary (high mi n) else summary)" + using insert_simp_excp[of mi deg treeList y ma summary] + by (smt "0" "00" "4.hyps"(7) "4.hyps"(8) False add_self_div_2 antisym_conv3 high_def le_less_trans less_mult_imp_div_less mult_2 power2_eq_square power_even_eq) + have mimaprop: "high mi n < 2^n \ low mi n < 2^n" + by (metis "00" "4.hyps"(7) "4.hyps"(8) Euclidean_Division.div_eq_0_iff div_exp_eq high_def le_less_trans low_def mod_less_divisor zero_less_numeral zero_less_power) + have "invar_vebt (treeList ! (high x n)) n" + by (metis "4.IH"(1) "4.hyps"(2) in_set_member inthall xyprop) + then show ?thesis + proof(cases "high x n = high mi n") + case True + have "both_member_options (vebt_insert (treeList ! (high mi n)) (low mi n)) (low x n)" + by (metis "4.IH"(1) "4.hyps"(2) True \both_member_options (treeList ! high x n) (low x n)\ \low x n < 2 ^ n \ low y n < 2 ^ n\ mimaprop nth_mem xyprop) + then show ?thesis + by (metis "00" "14" Suc_1 Suc_leD True add_self_div_2 both_member_options_from_chilf_to_complete_tree length_list_update nth_list_update_eq xyprop) + next + case False + have "(treeList[(high mi n):=vebt_insert (treeList ! (high mi n)) (low mi n)]) ! (high x n) = treeList ! (high x n)" + using False by force + then show ?thesis + by (metis "00" "14" One_nat_def Suc_leD \both_member_options (treeList ! high x n) (low x n)\ add_self_div_2 both_member_options_from_chilf_to_complete_tree length_list_update numeral_2_eq_2 xyprop) + qed + qed + qed + qed + qed +next + case (5 treeList n summary m deg mi ma) + hence 00:"deg = n + m \ length treeList = 2^m \ Suc n = m \ n \ 1 \ deg \ 2 \ n = deg div 2" + by (metis Suc_1 add_Suc_right add_mono_thms_linordered_semiring(1) add_self_div_2 even_Suc_div_two le_add1 odd_add plus_1_eq_Suc set_n_deg_not_0) + hence xyprop: "high x n < 2^m \ high y n < 2^m" + by (metis "5.prems"(1) "5.prems"(2) Suc_1 div_exp_eq div_if high_def nat.discI power_not_zero) + have "low x n <2^n \ low y n< 2^n" + by (simp add: low_def) + hence "x = mi \ x = ma \ both_member_options (treeList ! (high x n)) (low x n)" + by (smt "00" "5.prems"(3) add_Suc_right add_self_div_2 both_member_options_def le_add_diff_inverse membermima.simps(4) naive_member.simps(3) plus_1_eq_Suc) + have 001:"invar_vebt (Node (Some (mi, ma)) deg treeList summary) deg" + using invar_vebt.intros(5)[of treeList n summary m deg mi ma] "5" by simp + then show ?case + proof(cases "x = y") + case True + hence "both_member_options (vebt_insert (Node (Some (mi, ma)) deg treeList summary) y) y" + using 001 valid_insert_both_member_options_add[of "(Node (Some (mi, ma)) deg treeList summary)" deg y ] + using "5.prems"(2) by blast + then show ?thesis + by (simp add: True) + next + case False + then show ?thesis + proof(cases "y = mi \ y = ma") + case True + have "Suc (Suc (deg -2)) = deg" + using "00" by linarith + hence "vebt_insert (Node (Some (mi, ma)) deg treeList summary) y = Node (Some (mi, ma)) deg treeList summary" + using vebt_insert.simps(5)[of mi ma "deg-2" treeList summary x] 00 True insert_simp_mima by blast + then show ?thesis + by (simp add: "5.prems"(3)) + next + case False + hence 0:"y \ mi \ y \ ma" by simp + then show ?thesis + proof(cases "x = mi") + case True + hence 1:"x = mi" by simp + then show ?thesis + proof(cases "x < y") + case True + have 14:"vebt_insert (Node (Some (mi,ma)) deg treeList summary) y = + Node (Some (x, max y ma)) deg (treeList[ (high y n):=vebt_insert (treeList ! (high y n)) (low y n)] ) + (if minNull (treeList ! (high y n)) then vebt_insert summary (high y n) else summary)" + using "00" "1" False True insert_simp_norm xyprop by metis + then show ?thesis + by (metis "001" Suc_pred both_member_options_def deg_not_0 membermima.simps(4)) + next + case False + have 14:"vebt_insert (Node (Some (mi,ma)) deg treeList summary) y = + Node (Some (y, max x ma)) deg (treeList[ (high x n):=vebt_insert (treeList ! (high x n)) (low x n)]) + (if minNull (treeList ! (high x n)) then vebt_insert summary (high x n) else summary)" + by (metis "0" "00" False True add_self_div_2 insert_simp_excp linorder_neqE_nat xyprop) + have 15: " invar_vebt (treeList ! (high x n)) n" + by (metis "5"(1) "5.hyps"(2) in_set_member inthall xyprop) + hence 16: "both_member_options (vebt_insert (treeList ! high x n) (low x n)) (low x n)" + using \low x n < 2 ^ n \ low y n < 2 ^ n\ valid_insert_both_member_options_add by blast + then show ?thesis + by (metis "00" "14" Suc_1 add_leD1 both_member_options_from_chilf_to_complete_tree length_list_update nth_list_update_eq plus_1_eq_Suc xyprop) + qed + next + case False + hence "mi \ ma" + using "001" "5.prems"(3) less_irrefl member_inv valid_member_both_member_options by fastforce + hence "both_member_options (treeList !(high x n) ) (low x n) \ x = ma" + using False \x = mi \ x = ma \ both_member_options (treeList ! high x n) (low x n)\ by blast + have "high ma n < 2^m" + by (metis "00" "5.hyps"(8) Euclidean_Division.div_eq_0_iff div_exp_eq high_def nat_zero_less_power_iff power_not_zero zero_power2) + hence "both_member_options (treeList !(high ma n) ) (low ma n)" + using "5.hyps"(3) "5.hyps"(9) \mi \ ma\ by blast + hence "both_member_options (treeList !(high x n) ) (low x n)" + using \both_member_options (treeList ! high x n) (low x n) \ x = ma\ by blast + then show ?thesis + proof(cases "mi < y") + case True + have 14:"vebt_insert (Node (Some (mi,ma)) deg treeList summary) y = + Node (Some (mi, max y ma)) deg (treeList[(high y n):= vebt_insert (treeList ! (high y n)) (low y n)]) + (if minNull (treeList ! (high y n)) then vebt_insert summary (high y n) else summary)" + by (metis "0" "00" True insert_simp_norm xyprop) + have "invar_vebt (treeList ! (high x n)) n" + by (metis "5.IH"(1) "5.hyps"(2) in_set_member inthall xyprop) + then show ?thesis + proof(cases "high x n = high y n") + case True + have "both_member_options (vebt_insert (treeList ! (high y n)) (low y n)) (low x n)" + by (metis "5.IH"(1) "5.hyps"(2) True \both_member_options (treeList ! high x n) (low x n)\ \low x n < 2 ^ n \ low y n < 2 ^ n\ nth_mem xyprop) + then show ?thesis + by (metis "00" "14" Suc_1 True add_leD1 both_member_options_from_chilf_to_complete_tree length_list_update nth_list_update_eq plus_1_eq_Suc xyprop) + next + case False + have "(treeList[ (high y n):=vebt_insert (treeList ! (high y n)) (low y n)] ) ! (high x n) = treeList ! (high x n)" + using False by force + then show ?thesis + by (metis "00" "14" One_nat_def Suc_leD \both_member_options (treeList ! high x n) (low x n)\ both_member_options_from_chilf_to_complete_tree length_list_update numeral_2_eq_2 xyprop) + qed + next + case False + have 14:"vebt_insert (Node (Some (mi,ma)) deg treeList summary) y = + Node (Some (y, max mi ma)) deg (treeList[(high mi n):= vebt_insert (treeList ! (high mi n)) (low mi n)] ) + (if minNull (treeList ! (high mi n)) then vebt_insert summary (high mi n) else summary)" + using insert_simp_excp[of mi deg treeList y ma summary] + by (metis "0" "00" "5.hyps"(7) "5.hyps"(8) Euclidean_Division.div_eq_0_iff False antisym_conv3 div_exp_eq high_def le_less_trans power_not_zero zero_neq_numeral) + have mimaprop: "high mi n < 2^m \ low mi n < 2^n" using exp_split_high_low[of mi n m] 00 "5"(9,10) by force + have "invar_vebt (treeList ! (high x n)) n" + by (metis "5.IH"(1) "5.hyps"(2) in_set_member inthall xyprop) + then show ?thesis + proof(cases "high x n = high mi n") + case True + have "both_member_options (vebt_insert (treeList ! (high mi n)) (low mi n)) (low x n)" + by (metis "5.IH"(1) "5.hyps"(2) True \both_member_options (treeList ! high x n) (low x n)\ \low x n < 2 ^ n \ low y n < 2 ^ n\ mimaprop nth_mem) + then show ?thesis + by (metis "00" "14" Suc_1 True add_leD1 both_member_options_from_chilf_to_complete_tree length_list_update nth_list_update_eq plus_1_eq_Suc xyprop) + next + case False + have "(treeList[ (high mi n):=vebt_insert (treeList ! (high mi n)) (low mi n)]) ! (high x n) = treeList ! (high x n)" + by (metis False nth_list_update_neq) + then show ?thesis + by (metis "00" "14" One_nat_def Suc_leD \both_member_options (treeList ! high x n) (low x n)\ both_member_options_from_chilf_to_complete_tree length_list_update numeral_2_eq_2 xyprop) + qed + qed + qed + qed + qed +qed + +lemma post_member_pre_member:"invar_vebt t n \ x< 2^n \ y <2^n \ vebt_member (vebt_insert t x) y \ vebt_member t y \ x = y" +proof(induction t n arbitrary: x y rule: invar_vebt.induct) + case (1 a b) then show ?case by auto +next + case (2 treeList n summary m deg) + hence "deg \ 2" + using deg_not_0 by fastforce + then show ?case using vebt_insert.simps(4)[of "deg-2" treeList summary x] + by (metis (no_types, lifting) "2.prems"(3) vebt_member.simps(5) add_numeral_left le_add_diff_inverse member_inv numerals(1) plus_1_eq_Suc semiring_norm(2)) +next + case (3 treeList n summary m deg) + hence "deg \ 2" + by (metis vebt_member.simps(2) One_nat_def Suc_1 Suc_eq_plus1 add_mono_thms_linordered_semiring(1) vebt_insert.simps(3) le_Suc_eq le_add1 plus_1_eq_Suc) + then show ?case using vebt_insert.simps(4)[of "deg-2" treeList summary x] + by (metis (no_types, lifting) "3.prems"(3) vebt_member.simps(5) add_numeral_left le_add_diff_inverse member_inv numerals(1) plus_1_eq_Suc semiring_norm(2)) +next + case (4 treeList n summary m deg mi ma) + hence 00:"deg = n+m \ n \ 0 \ n = m \ deg \ 2 \ length treeList =2^n" + by (metis Euclidean_Division.div_eq_0_iff add_self_div_2 deg_not_0 not_less zero_le) + hence xyprop: "high x n < 2^n \ high y n < 2^n" + using "4.hyps"(1) "4.prems"(1) "4.prems"(2) deg_not_0 exp_split_high_low(1) by blast + have "low x n <2^n \ low y n< 2^n" + by (simp add: low_def) + then show ?case + proof(cases "x = mi \ x = ma") + case True + then show ?thesis + using "00" "4.prems"(3) insert_simp_mima by auto + next + case False + hence mimaxyprop: "\ (x = mi \ x = ma) \ high x n < 2^n \ high mi n < 2^n \ low x n <2^n \ low mi n < 2^n \ length treeList = 2^n" + using "00" "4.hyps"(1) "4.hyps"(7) "4.hyps"(8) \low x n < 2 ^ n \ low y n < 2 ^ n\ deg_not_0 exp_split_high_low(1) exp_split_high_low(2) le_less_trans xyprop by blast + then show ?thesis + proof(cases "mi < x") + case True + hence "vebt_insert (Node (Some (mi,ma)) deg treeList summary) x = + Node (Some (mi, max x ma)) deg (treeList[(high x n) :=vebt_insert (treeList ! (high x n)) (low x n)]) + (if minNull (treeList ! (high x n)) then vebt_insert summary (high x n) else summary)" + using insert_simp_norm[of x n treeList mi ma summary] mimaxyprop "00" add_self_div_2 insert_simp_norm by metis + then show ?thesis + proof(cases "y = mi \ y = max x ma") + case True + then show ?thesis + proof(cases "y = mi") + case True + then show ?thesis + by (metis "00" vebt_member.simps(5) le0 not_less_eq_eq numeral_2_eq_2 old.nat.exhaust) + next + case False + hence "y = max x ma" + using True by blast + then show ?thesis + proof(cases "x < ma") + case True + then show ?thesis + by (metis (no_types, lifting) "00" vebt_member.simps(5) \y = max x ma\ add_numeral_left le_add_diff_inverse max_less_iff_conj not_less_iff_gr_or_eq numerals(1) plus_1_eq_Suc semiring_norm(2)) + next + case False + then show ?thesis + using \y = max x ma\ by linarith + qed + qed + next + case False + hence "vebt_member ((treeList[(high x n):= vebt_insert (treeList ! (high x n)) (low x n)]) ! (high y n)) (low y n)" + by (metis "4.hyps"(3) "4.hyps"(4) "4.prems"(3) \vebt_insert (Node (Some (mi, ma)) deg treeList summary) x = Node (Some (mi, max x ma)) deg (treeList[high x n := vebt_insert (treeList ! high x n) (low x n)]) (if minNull (treeList ! high x n) then vebt_insert summary (high x n) else summary)\ add_self_div_2 member_inv) + then show ?thesis + proof(cases "high x n = high y n") + case True + hence 000:"vebt_member (vebt_insert (treeList ! (high x n)) (low x n)) (low y n)" + using \vebt_member (treeList[high x n := vebt_insert (treeList ! high x n) (low x n)] ! high y n) (low y n)\ mimaxyprop by auto + have 001:"invar_vebt (treeList ! (high x n)) n \ treeList ! (high x n) \ set treeList " + by (simp add: "4.IH"(1) mimaxyprop) + hence 002:"vebt_member (treeList ! (high x n)) (low y n) \ low y n = low x n" + using "000" "4.IH"(1) \low x n < 2 ^ n \ low y n < 2 ^ n\ by fastforce + hence 003:"both_member_options (treeList ! (high x n)) (low y n) \ low y n = low x n" + using \invar_vebt (treeList ! high x n) n \ treeList ! high x n \ set treeList\ both_member_options_equiv_member by blast + have 004:"naive_member (treeList ! (high x n)) (low y n) \ + naive_member (Node (Some (mi , ma)) deg treeList summary) y" + by (metis "00" Suc_le_D True add_self_div_2 mimaxyprop naive_member.simps(3) one_add_one plus_1_eq_Suc) + hence 005:"both_member_options (Node (Some (mi , ma)) deg treeList summary) y \ x = y" + by (metis "00" "001" "002" Suc_le_D True add_self_div_2 bit_split_inv both_member_options_def member_valid_both_member_options membermima.simps(4) mimaxyprop one_add_one plus_1_eq_Suc) + then show ?thesis + by (smt "00" "001" "002" "003" "4"(11) "4"(8) vebt_member.simps(5) True add_numeral_left add_self_div_2 bit_split_inv le_add_diff_inverse mimaxyprop not_less not_less_iff_gr_or_eq numerals(1) plus_1_eq_Suc semiring_norm(2)) + next + case False + hence 000:"vebt_member (treeList ! (high y n)) (low y n)" + using \vebt_member (treeList[high x n := vebt_insert (treeList ! high x n) (low x n)] ! high y n) (low y n)\ by auto + moreover have 004:"naive_member (treeList ! (high y n)) (low y n) \ + naive_member (Node (Some (mi , ma)) deg treeList summary) y" + by (metis "00" Suc_le_D add_self_div_2 naive_member.simps(3) one_add_one plus_1_eq_Suc xyprop) + moreover have 001:"invar_vebt (treeList ! (high y n)) n \ treeList ! (high y n) \ set treeList " + by (metis (full_types) "4.IH"(1) "4.hyps"(2) "4.hyps"(3) inthall member_def xyprop) + moreover have " both_member_options (Node (Some (mi , ma)) deg treeList summary) y" + by (metis "00" "000" "001" "004" Suc_le_D add_self_div_2 both_member_options_def member_valid_both_member_options membermima.simps(4) one_add_one plus_1_eq_Suc xyprop) + moreover have "vebt_member (Node (Some (mi, ma)) deg treeList summary) y" + using both_member_options_equiv_member[of "(Node (Some (mi, ma)) deg treeList summary)" deg y] + invar_vebt.intros(4)[of treeList n summary m deg mi ma] + using "4" calculation(4) by blast + then show ?thesis by simp + qed + qed + next + case False + hence "x < mi" + using mimaxyprop nat_neq_iff by blast + hence "vebt_insert (Node (Some (mi,ma)) deg treeList summary) x = + Node (Some (x, max mi ma)) deg (treeList[ (high mi n):=vebt_insert (treeList ! (high mi n)) (low mi n)]) + (if minNull (treeList ! (high mi n)) then vebt_insert summary (high mi n) else summary)" + using insert_simp_excp[of mi n treeList x ma summary] mimaxyprop "00" add_self_div_2 insert_simp_excp by metis + then show ?thesis + proof(cases "y = x \ y = max mi ma") + case True + then show ?thesis + proof(cases "y = x") + case True + then show ?thesis + by (simp add: "00") + next + case False + hence "y = max mi ma" + using True by blast + then show ?thesis + proof(cases "mi < ma") + case True + then show ?thesis using "00" vebt_member.simps(5) \y = max mi ma\ add_numeral_left + le_add_diff_inverse max_less_iff_conj not_less_iff_gr_or_eq numerals(1) plus_1_eq_Suc semiring_norm(2) + by (metis (no_types, lifting)) + next + case False + then show ?thesis + by (metis "00" "4.hyps"(7) vebt_member.simps(5) \y = max mi ma\ add_numeral_left le_add_diff_inverse max.absorb2 numerals(1) plus_1_eq_Suc semiring_norm(2)) + qed + qed + next + case False + hence "vebt_member ((treeList[(high mi n) :=vebt_insert (treeList ! (high mi n)) (low mi n)]) ! (high y n)) (low y n)" + by (metis "4.hyps"(3) "4.hyps"(4) "4.prems"(3) \vebt_insert (Node (Some (mi, ma)) deg treeList summary) x = Node (Some (x, max mi ma)) deg (treeList[high mi n := vebt_insert (treeList ! high mi n) (low mi n)]) (if minNull (treeList ! high mi n) then vebt_insert summary (high mi n) else summary)\ add_self_div_2 member_inv) + then show ?thesis + proof(cases "high mi n = high y n") + case True + hence 000:"vebt_member (vebt_insert (treeList ! (high mi n)) (low mi n)) (low y n)" + by (metis \vebt_member (treeList[high mi n := vebt_insert (treeList ! high mi n) (low mi n)] ! high y n) (low y n)\ mimaxyprop nth_list_update_eq) + have 001:"invar_vebt (treeList ! (high mi n)) n \ treeList ! (high mi n) \ set treeList" + by (simp add: "4.IH"(1) mimaxyprop) + hence 002:"vebt_member (treeList ! (high mi n)) (low y n) \ low y n = low mi n" + using "000" "4.IH"(1) \low x n < 2 ^ n \ low y n < 2 ^ n\ mimaxyprop by fastforce + hence 003:"both_member_options (treeList ! (high mi n)) (low y n) \ low y n = low mi n" + using \invar_vebt (treeList ! high mi n) n \ treeList ! high mi n \ set treeList\ both_member_options_equiv_member by blast + have 004:"naive_member (treeList ! (high mi n)) (low y n) \ + naive_member (Node (Some (mi , ma)) deg treeList summary) y" using naive_member.simps(3)[of "Some (mi, ma)" "deg-1" treeList summary y] + using "00" True mimaxyprop by fastforce + hence 005:"both_member_options (Node (Some (mi , ma)) deg treeList summary) y \ x = y" + by (metis "00" "001" "002" Suc_le_D True add_self_div_2 bit_split_inv both_member_options_def member_valid_both_member_options membermima.simps(4) mimaxyprop one_add_one plus_1_eq_Suc) + then show ?thesis + by (smt "00" "001" "002" "003" "4.hyps"(6) "4.hyps"(9) vebt_member.simps(5) True add_numeral_left add_self_div_2 bit_split_inv le_add_diff_inverse mimaxyprop not_less not_less_iff_gr_or_eq numerals(1) plus_1_eq_Suc semiring_norm(2)) + next + case False + hence 000:"vebt_member (treeList ! (high y n)) (low y n)" + using \vebt_member (treeList[high mi n := vebt_insert (treeList ! high mi n) (low mi n)] ! high y n) (low y n)\ by auto + moreover have 004:"naive_member (treeList ! (high y n)) (low y n) \ + naive_member (Node (Some (mi , ma)) deg treeList summary) y" + by (metis "00" Suc_le_D add_self_div_2 naive_member.simps(3) one_add_one plus_1_eq_Suc xyprop) + moreover have 001:"invar_vebt (treeList ! (high y n)) n \ treeList ! (high y n) \ set treeList " + by (metis (full_types) "4.IH"(1) "4.hyps"(2) "4.hyps"(3) inthall member_def xyprop) + moreover have " both_member_options (Node (Some (mi , ma)) deg treeList summary) y" + by (metis "00" "000" "001" "004" Suc_le_D add_self_div_2 both_member_options_def member_valid_both_member_options membermima.simps(4) one_add_one plus_1_eq_Suc xyprop) + then show ?thesis using both_member_options_equiv_member[of "(Node (Some (mi, ma)) deg treeList summary)" deg y] + invar_vebt.intros(4)[of treeList n summary m deg mi ma] "4" by blast + qed + qed + qed + qed +next + case (5 treeList n summary m deg mi ma) + hence 00:"deg = n+m \ n \ 0 \ Suc n = m \ deg \ 2 \ length treeList =2^m \ n \ 1" + by (metis Suc_1 add_mono_thms_linordered_semiring(1) le_add1 plus_1_eq_Suc set_n_deg_not_0 zero_le) + hence xyprop: "high x n < 2^m \ high y n < 2^m" + using "5.prems"(1) "5.prems"(2) exp_split_high_low(1) by auto + have "low x n <2^n \ low y n< 2^n" + by (simp add: low_def) + then show ?case + proof(cases "x = mi \ x = ma") + case True + then show ?thesis + using "00" "5.prems"(3) insert_simp_mima by auto + next + case False + hence mimaxyprop: "\ (x = mi \ x = ma) \ high x n < 2^m \ high mi n < 2^m \ low x n <2^n \ low mi n < 2^n \ length treeList = 2^m" + using "00" "5" \low x n < 2 ^ n \ low y n < 2 ^ n\ deg_not_0 exp_split_high_low(1) exp_split_high_low(2) le_less_trans xyprop + by (smt less_le_trans less_numeral_extra(1)) + then show ?thesis + proof(cases "mi < x") + case True + hence "vebt_insert (Node (Some (mi,ma)) deg treeList summary) x = + Node (Some (mi, max x ma)) deg (treeList[ (high x n):=vebt_insert (treeList ! (high x n)) (low x n)]) + (if minNull (treeList ! (high x n)) then vebt_insert summary (high x n) else summary)" + using insert_simp_norm[of x deg treeList mi ma summary] + by (smt "00" False add_Suc_right add_self_div_2 even_Suc_div_two odd_add xyprop) + then show ?thesis + proof(cases "y = mi \ y = max x ma") + case True + then show ?thesis + proof(cases "y = mi") + case True + then show ?thesis + by (metis "00" vebt_member.simps(5) le0 not_less_eq_eq numeral_2_eq_2 old.nat.exhaust) + next + case False + hence "y = max x ma" + using True by blast + then show ?thesis + proof(cases "x < ma") + case True + then show ?thesis + by (metis (no_types, lifting) "00" vebt_member.simps(5) \y = max x ma\ add_numeral_left le_add_diff_inverse max_less_iff_conj not_less_iff_gr_or_eq numerals(1) plus_1_eq_Suc semiring_norm(2)) + next + case False + then show ?thesis + using \y = max x ma\ by linarith + qed + qed + next + case False + hence "vebt_member ((treeList[ (high x n):=vebt_insert (treeList ! (high x n)) (low x n)]) ! (high y n)) (low y n)" + using "5.hyps"(3) "5.hyps"(4) "5.prems"(3) \vebt_insert (Node (Some (mi, ma)) deg treeList summary) x = Node (Some (mi, max x ma)) deg (treeList[high x n := vebt_insert (treeList ! high x n) (low x n)]) (if minNull (treeList ! high x n) then vebt_insert summary (high x n) else summary)\ add_Suc_right add_self_div_2 member_inv by force + then show ?thesis + proof(cases "high x n = high y n") + case True + hence 000:"vebt_member (vebt_insert (treeList ! (high x n)) (low x n)) (low y n)" + by (metis "5.hyps"(2) \vebt_member (treeList[high x n := vebt_insert (treeList ! high x n) (low x n)] ! high y n) (low y n)\ nth_list_update_eq xyprop) + have 001:"invar_vebt (treeList ! (high x n)) n \ treeList ! (high x n) \ set treeList " + by (simp add: "5.IH"(1) "5.hyps"(2) xyprop) + hence 002:"vebt_member (treeList ! (high x n)) (low y n) \ low y n = low x n" + using "000" "5.IH"(1) \low x n < 2 ^ n \ low y n < 2 ^ n\ by fastforce + hence 003:"both_member_options (treeList ! (high x n)) (low y n) \ low y n = low x n" + using \invar_vebt (treeList ! high x n) n \ treeList ! high x n \ set treeList\ both_member_options_equiv_member by blast + have 004:"naive_member (treeList ! (high x n)) (low y n) \ + naive_member (Node (Some (mi , ma)) deg treeList summary) y" + using "00" True xyprop by auto + hence 005:"both_member_options (Node (Some (mi , ma)) deg treeList summary) y \ x = y" + by (smt "00" "001" "002" True add_Suc_right add_self_div_2 bit_split_inv both_member_options_def even_Suc_div_two member_valid_both_member_options membermima.simps(4) odd_add xyprop) + then show ?thesis + using both_member_options_equiv_member[of "(Node (Some (mi, ma)) deg treeList summary)" deg y] + invar_vebt.intros(5)[of treeList n summary m deg mi ma] "5" by blast + next + case False + hence 000:"vebt_member (treeList ! (high y n)) (low y n)" + using \vebt_member (treeList[high x n := vebt_insert (treeList ! high x n) (low x n)] ! high y n) (low y n)\ by fastforce + moreover have 004:"naive_member (treeList ! (high y n)) (low y n) \ + naive_member (Node (Some (mi , ma)) deg treeList summary) y" + using "00" xyprop by auto + moreover have 001:"invar_vebt (treeList ! (high y n)) n \ treeList ! (high y n) \ set treeList " + by (metis (full_types) "5"inthall member_def xyprop) + moreover have " both_member_options (Node (Some (mi , ma)) deg treeList summary) y" + using "00" "000" "001" both_member_options_def member_valid_both_member_options xyprop by fastforce + moreover have "vebt_member (Node (Some (mi, ma)) deg treeList summary) y" + using both_member_options_equiv_member[of "(Node (Some (mi, ma)) deg treeList summary)" deg y] + invar_vebt.intros(5)[of treeList n summary m deg mi ma] "5" calculation(4) by blast + then show ?thesis by simp + qed + qed + next + case False + hence "x < mi" + using mimaxyprop nat_neq_iff by blast + hence "vebt_insert (Node (Some (mi,ma)) deg treeList summary) x = + Node (Some (x, max mi ma)) deg (treeList[ (high mi n):=vebt_insert (treeList ! (high mi n)) (low mi n)]) + (if minNull (treeList ! (high mi n)) then vebt_insert summary (high mi n) else summary)" + using insert_simp_excp[of mi n treeList x ma summary] mimaxyprop "00" add_self_div_2 insert_simp_excp + by (smt add_Suc_right even_Suc_div_two odd_add) + then show ?thesis + proof(cases "y = x \ y = max mi ma") + case True + then show ?thesis + proof(cases "y = x") + case True + then show ?thesis + by (simp add: "00") + next + case False + hence "y = max mi ma" + using True by blast + then show ?thesis + proof(cases "mi < ma") + case True + then show ?thesis using "00" vebt_member.simps(5) \y = max mi ma\ add_numeral_left + le_add_diff_inverse max_less_iff_conj not_less_iff_gr_or_eq numerals(1) plus_1_eq_Suc semiring_norm(2) + by (metis (no_types, lifting)) + next + case False + then show ?thesis + by (metis "00" "5.hyps"(7) vebt_member.simps(5) \y = max mi ma\ add_numeral_left le_add_diff_inverse max.absorb2 numerals(1) plus_1_eq_Suc semiring_norm(2)) + qed + qed + next + case False + hence "vebt_member ((treeList[(high mi n):=vebt_insert (treeList ! (high mi n)) (low mi n)]) ! (high y n)) (low y n)" + using "5.hyps"(3) "5.hyps"(4) "5.prems"(3) \vebt_insert (Node (Some (mi, ma)) deg treeList summary) x = Node (Some (x, max mi ma)) deg (treeList[high mi n := vebt_insert (treeList ! high mi n) (low mi n)]) (if minNull (treeList ! high mi n) then vebt_insert summary (high mi n) else summary)\ member_inv by force + then show ?thesis + proof(cases "high mi n = high y n") + case True + hence 000:"vebt_member (vebt_insert (treeList ! (high mi n)) (low mi n)) (low y n)" + by (metis \vebt_member (treeList[high mi n := vebt_insert (treeList ! high mi n) (low mi n)] ! high y n) (low y n)\ mimaxyprop nth_list_update_eq) + have 001:"invar_vebt (treeList ! (high mi n)) n \ treeList ! (high mi n) \ set treeList " + by (simp add: "5.IH"(1) mimaxyprop) + hence 002:"vebt_member (treeList ! (high mi n)) (low y n) \ low y n = low mi n" + using "000" "5.IH"(1) \low x n < 2 ^ n \ low y n < 2 ^ n\ mimaxyprop by fastforce + hence 003:"both_member_options (treeList ! (high mi n)) (low y n) \ low y n = low mi n" + using \invar_vebt (treeList ! high mi n) n \ treeList ! high mi n \ set treeList\ both_member_options_equiv_member by blast + have 004:"naive_member (treeList ! (high mi n)) (low y n) \ + naive_member (Node (Some (mi , ma)) deg treeList summary) y" using naive_member.simps(3)[of "Some (mi, ma)" "deg-1" treeList summary y] + using "00" True mimaxyprop by fastforce + hence 005:"both_member_options (Node (Some (mi , ma)) deg treeList summary) y \ x = y" + by (smt "00" "001" "002" True add_Suc_right add_self_div_2 bit_split_inv both_member_options_def even_Suc_div_two member_valid_both_member_options membermima.simps(4) odd_add xyprop) + then show ?thesis using "00" "001" "002" "003" "5"(14) "5.hyps"(6) "5.hyps"(7) "5.hyps"(9) vebt_member.simps(5) True + add_Suc_right add_self_div_2 bit_split_inv even_Suc_div_two le_add_diff_inverse max.absorb2 + mimaxyprop not_less_iff_gr_or_eq odd_add plus_1_eq_Suc + by (smt (z3) \vebt_insert (Node (Some (mi, ma)) deg treeList summary) x = Node (Some (x, max mi ma)) deg (treeList[high mi n := vebt_insert (treeList ! high mi n) (low mi n)]) (if minNull (treeList ! high mi n) then vebt_insert summary (high mi n) else summary)\) + next + case False + hence 000:"vebt_member (treeList ! (high y n)) (low y n)" + using \vebt_member (treeList[high mi n := vebt_insert (treeList ! high mi n) (low mi n)] ! high y n) (low y n)\ by auto + moreover have 004:"naive_member (treeList ! (high y n)) (low y n) \ + naive_member (Node (Some (mi , ma)) deg treeList summary) y" + using "00" xyprop by auto + moreover have 001:"invar_vebt (treeList ! (high y n)) n \ treeList ! (high y n) \ set treeList " + by (metis (full_types) "5.IH"(1) "5.hyps"(2) "5.hyps"(3) inthall member_def xyprop) + moreover have " both_member_options (Node (Some (mi , ma)) deg treeList summary) y" + using "00" "000" "001" both_member_options_def member_valid_both_member_options xyprop by fastforce + then show ?thesis using both_member_options_equiv_member[of "(Node (Some (mi, ma)) deg treeList summary)" deg y] + invar_vebt.intros(5)[of treeList n summary m deg mi ma] "5" by simp + qed + qed + qed + qed +qed + +end +end diff --git a/thys/Van_Emde_Boas_Trees/VEBT_InsertCorrectness.thy b/thys/Van_Emde_Boas_Trees/VEBT_InsertCorrectness.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/VEBT_InsertCorrectness.thy @@ -0,0 +1,1091 @@ +(*by Ammer*) +theory VEBT_InsertCorrectness imports VEBT_Member VEBT_Insert +begin + +context VEBT_internal begin + +section \Correctness of the Insert Operation\ + +subsection \Validness Preservation\ + +theorem valid_pres_insert: "invar_vebt t n \ x< 2^n \ invar_vebt (vebt_insert t x) n" +proof(induction t n arbitrary: x rule: invar_vebt.induct) + case (1 a b) + then show ?case using vebt_insert.simps(1)[of a b x] + by (simp add: invar_vebt.intros(1)) +next + case (2 treeList n summary m deg) + hence 0: " ( \ t \ set treeList. invar_vebt t n) " and 1:" invar_vebt summary n" and 2:" length treeList = 2^n" and + 3:" deg = 2*n" and 4:" (\ i. both_member_options summary i)" and 5:" (\ t \ set treeList. \ x. both_member_options t x) " and 6: "n\ 1" + using "2.prems" by (auto simp add: Suc_leI deg_not_0) + let ?t = "Node None deg treeList summary" + let ?tnew = "vebt_insert ?t x" + have 6:"?tnew = (Node (Some (x,x)) deg treeList summary)" using vebt_insert.simps(4)[of "deg-2" treeList summary x] + by (metis "1" "2.hyps"(3) "2.hyps"(4) add_2_eq_Suc add_diff_inverse_nat add_self_div_2 deg_not_0 div_less gr_implies_not0) + have 7:"(x = x \ (\ t \ set treeList. \ x. both_member_options t x))" + using \\t\set treeList. \x. both_member_options t x\ by blast + have 8:"x \ x" by simp + have 9:" x < 2^deg" + by (simp add: "2.prems") + have 10:"(x \ x \ (\ i < 2^(2^n). (high x deg = i \ both_member_options (treeList ! i) (low x deg)) \ + (\ y. (high y deg = i \ both_member_options (treeList ! i) (low y deg) ) \ x < y \ y \ x) ))" + by simp + then show ?case using 0 1 2 3 4 5 6 7 8 9 10 invar_vebt.intros(4)[of treeList n summary m deg x x] + by (metis "2.hyps"(3) "2.hyps"(4) nth_mem) +next + case (3 treeList n summary m deg) + hence 0: " ( \ t \ set treeList. invar_vebt t n) " and 1:" invar_vebt summary m" and 2:" length treeList = 2^m" and + 3:" deg = n+m" and 4:" (\ i. both_member_options summary i)" and 5:" (\ t \ set treeList. \ x. both_member_options t x) " and 6: "n\ 1" + and 7: "Suc n = m" using "3.prems" apply auto + by (metis "3.hyps"(2) One_nat_def set_n_deg_not_0) + let ?t = "Node None deg treeList summary" + let ?tnew = "vebt_insert ?t x" + have 6:"?tnew = (Node (Some (x,x)) deg treeList summary)" using vebt_insert.simps(4)[of "deg-2" treeList summary x] + by (smt "3" "3.hyps"(3) "6" Nat.add_diff_assoc One_nat_def Suc_le_mono add_diff_inverse_nat add_gr_0 add_numeral_left diff_is_0_eq' not_less not_less_iff_gr_or_eq numeral_2_eq_2 numerals(1) plus_1_eq_Suc semiring_norm(2)) + have 7:"(x = x \ (\ t \ set treeList. \ x. both_member_options t x))" + using \\t\set treeList. \x. both_member_options t x\ by blast + have 8:"x \ x" by simp + have 9:" x < 2^deg" + by (simp add: "3.prems") + have 10:"(x \ x \ (\ i < 2^(2^n). (high x deg = i \ both_member_options (treeList ! i) (low x deg)) \ + (\ y. (high y deg = i \ both_member_options (treeList ! i) (low y deg) ) \ x < y \ y \ x) ))" + by simp + then show ?case using 0 1 2 3 4 5 6 7 8 9 10 invar_vebt.intros(5)[of treeList n summary m deg x x] "3.hyps"(3) nth_mem by force +next + case (4 treeList n summary m deg mi ma) + hence myIHs: "x \ set treeList \ invar_vebt x n \ xa < 2 ^ n \ invar_vebt (vebt_insert x xa) n" for x xa by simp + hence 0: "( \ t \ set treeList. invar_vebt t n)" and 1: " invar_vebt summary m" and 2:"length treeList = 2^m" and 3:" deg = n+m" and + 4: "(\ i < 2^m. (\ y. both_member_options (treeList ! i) y) \ ( both_member_options summary i))" and + 5: "(mi = ma \ (\ t \ set treeList. \ y. both_member_options t y))" and 6:"mi \ ma \ ma < 2^deg" and + 7: "(mi \ ma \ (\ i < 2^m. (high ma n = i \ both_member_options (treeList ! i) (low ma n)) \ + (\ y. (high y n = i \ both_member_options (treeList ! i) (low y n) ) \ mi < y \ y \ ma)))" + and 8: "n = m" and 9: "deg div 2 = n" using "4" add_self_div_2 by blast+ + then show ?case + proof(cases "x = mi \ x = ma") + case True + then show ?thesis using insert_simp_mima[of x mi ma deg treeList summary] + invar_vebt.intros(4)[of treeList n summary m deg mi ma] + by (smt "0" "1" "2" "3" "4" "4.hyps"(3) "4.hyps"(7) "4.hyps"(8) "5" "7" "9" deg_not_0 div_greater_zero_iff) + next + case False + hence mimaxrel: "x \ mi \ x \ ma" by simp + then show ?thesis + proof(cases "mi < x") + case True + hence abcdef: "mi < x" by simp + let ?h = "high x n" and ?l="low x n" + have highlowprop: "high x n < 2^m \ low x n < 2^n" + using "1" "3" "4.hyps"(3) "4.prems" deg_not_0 exp_split_high_low(1) exp_split_high_low(2) by blast + have 10:"vebt_insert (Node (Some (mi,ma)) deg treeList summary) x = + Node (Some (mi, max x ma)) deg (treeList[?h:=vebt_insert (treeList ! ?h) ?l]) + (if minNull (treeList ! ?h) then vebt_insert summary ?h else summary) " + using "2" "3" False True \high x n < 2 ^ m \ low x n < 2 ^ n\ insert_simp_norm by (metis "1" "4.hyps"(3) "9" deg_not_0 div_greater_zero_iff) + let ?maxnew = "max x ma" and ?nextTreeList = "(take ?h treeList @ [vebt_insert (treeList ! ?h) ?l] @ drop (?h+1) treeList)" and + ?nextSummary = "(if minNull (treeList ! ?h) then vebt_insert summary ?h else summary)" + have 11: "( \ t \ set ?nextTreeList. invar_vebt t n)" proof + fix t + assume " t \ set ?nextTreeList" + hence 111:"t \ set (take ?h treeList) \ t \ set ([vebt_insert (treeList ! ?h) ?l] @ drop (?h+1) treeList)" by auto + show "invar_vebt t n" + proof(cases "t \ set (take ?h treeList) ") + case True + then show ?thesis + by (meson "0" in_set_takeD) + next + case False + hence 1110: "t = vebt_insert (treeList ! ?h) ?l \ t \ set ( drop (?h+1) treeList)" + using "111" by auto + then show ?thesis + proof(cases "t = vebt_insert (treeList ! ?h) ?l") + case True + have 11110: "invar_vebt (treeList ! ?h) n" + by (simp add: "2" "4.IH"(1) highlowprop) + have 11111: "?l < 2^n" + by (simp add: low_def) + then show ?thesis using myIHs[of "treeList ! ?h"] + by (simp add: "11110" "2" True highlowprop) + next + case False + then show ?thesis + by (metis "0" "1110" append_assoc append_take_drop_id in_set_conv_decomp) + qed + qed + qed + have 12: "invar_vebt ?nextSummary n" + proof(cases "minNull (treeList ! high x n)") + case True + then show ?thesis + using "4.IH"(2) "8" highlowprop by auto + next + case False + then show ?thesis + by (simp add: "1" "8") + qed + have 13: "\ i < 2^m. (\ y. both_member_options (?nextTreeList ! i) y) \ ( both_member_options ?nextSummary i)" + proof + fix i + show "i < 2 ^ m \ (\y. both_member_options ((?nextTreeList) ! i) y) = both_member_options (?nextSummary) i " + proof + assume "i< 2^m" + show "(\y. both_member_options ((?nextTreeList) ! i) y) = both_member_options (?nextSummary) i " + proof(cases "minNull (treeList ! high x n)") + case True + hence tc: "minNull (treeList ! high x n)" by simp + hence nsprop: "?nextSummary = vebt_insert summary ?h" by simp + have insprop:"?nextTreeList ! ?h = vebt_insert (treeList ! ?h) ?l" + by (metis "2" Suc_eq_plus1 append_Cons highlowprop nth_list_update_eq self_append_conv2 upd_conv_take_nth_drop) + then show ?thesis + proof(cases "i = ?h") + case True + have 161:"\ y. vebt_member (treeList ! ?h) y" + by (simp add: min_Null_member tc) + hence 162:"\ y. both_member_options (treeList ! ?h) y" + by (metis "2" "4.IH"(1) highlowprop nth_mem valid_member_both_member_options) + hence 163:"\ both_member_options summary i" + using "11" "2" "4" True \i < 2 ^ m\ by blast + have 164:"?nextTreeList ! i = vebt_insert (treeList ! ?h) ?l" + using True insprop by simp + have 165:"invar_vebt (vebt_insert (treeList ! ?h) ?l) n" + by (simp add: "11") + have 166:"both_member_options (vebt_insert (treeList ! ?h) ?l) ?l" using myIHs[of "treeList ! ?h" ?l] + by (metis "0" "2" highlowprop nth_mem valid_insert_both_member_options_add) + have 167:"\ y. both_member_options ((?nextTreeList) ! i) y " + using "164" "166" by auto + then show ?thesis + using "1" "11" "2" True nsprop valid_insert_both_member_options_add highlowprop by auto + next + case False + have "?nextTreeList ! i = treeList ! i" + by (metis "2" False \i < 2 ^ m\ highlowprop nth_repl) + have fstprop:"both_member_options ((?nextTreeList) ! i) y \ both_member_options (?nextSummary) i " for y + using "1" "4" \(take (high x n) treeList @ [VEBT_Insert.vebt_insert (treeList ! high x n) (low x n)] @ drop (high x n + 1) treeList) ! i = treeList ! i\ \i < 2 ^ m\ highlowprop valid_insert_both_member_options_pres by auto + moreover have" both_member_options (?nextSummary) i \ \ y . both_member_options ((?nextTreeList) ! i) y " + proof- + assume "both_member_options (?nextSummary) i " + have "i \ high x n" + by (simp add: False) + hence "both_member_options summary i" + by (smt (z3) "1" "12" \both_member_options (if minNull (treeList ! high x n) then VEBT_Insert.vebt_insert summary (high x n) else summary) i\ \i < 2 ^ m\ both_member_options_equiv_member highlowprop post_member_pre_member) + hence "\ y. both_member_options (treeList ! i) y" + by (simp add: "4" \i < 2 ^ m\) + then show ?thesis + using \(take (high x n) treeList @ [VEBT_Insert.vebt_insert (treeList ! high x n) (low x n)] @ drop (high x n + 1) treeList) ! i = treeList ! i\ by presburger + qed + ultimately show ?thesis by auto + qed + next + case False + hence "?nextSummary = summary" by simp + hence "\ y. both_member_options (treeList ! high x n) y" + using not_min_Null_member False by blast + hence "both_member_options summary (high x n)" + using "4" highlowprop by blast + hence " both_member_options (?nextTreeList ! high x n) ?l" + by (metis "0" "2" Suc_eq_plus1 append_Cons append_Nil highlowprop nth_list_update_eq nth_mem upd_conv_take_nth_drop valid_insert_both_member_options_add) + then show ?thesis + by (smt (verit, best) "2" "4" False \both_member_options summary (high x n)\ \i < 2 ^ m\ highlowprop nth_repl) + qed + qed + qed + have 14: "(mi = max ma x \ (\ t \ set ?nextTreeList. \ y. both_member_options t y))" + using True max_less_iff_conj by blast + have 15: "mi \ max ma x \ max ma x < 2^deg" + using "4.hyps"(8) "4.prems" abcdef by auto + have 16: "(mi \ max ma x \ (\ i < 2^m. (high (max ma x) n = i \ both_member_options (?nextTreeList ! i) (low (max ma x) n)) \ + (\ y. (high y n = i \ both_member_options (?nextTreeList ! i) (low y n) ) \ mi < y \ y \ max ma x)))" + proof + assume "mi \ max ma x" + show "(\ i < 2^m. (high (max ma x) n = i \ both_member_options (?nextTreeList ! i) (low (max ma x) n)) \ + (\ y. (high y n = i \ both_member_options (?nextTreeList ! i) (low y n) ) \ mi < y \ y \ max ma x))" + proof + fix i::nat + show "i < 2 ^ m\ + (high (max ma x) n = i \ both_member_options (?nextTreeList ! i) (low (max ma x) n)) \ + (\y. high y n = i \ both_member_options (?nextTreeList ! i) (low y n) \ mi < y \ y \ max ma x)" + proof + assume "i < 2^m" + show " (high (max ma x) n = i \ both_member_options (?nextTreeList ! i) (low (max ma x) n)) \ + (\y. high y n = i \ both_member_options (?nextTreeList ! i) (low y n) \ mi < y \ y \ max ma x)" + proof + show "(high (max ma x) n = i \ both_member_options (?nextTreeList ! i) (low (max ma x) n))" + proof + assume "high (max ma x) n = i" + show "both_member_options (?nextTreeList ! i) (low (max ma x) n)" + proof(cases "high x n = high ma n") + case True + have "invar_vebt (treeList ! i ) n" + by (metis "0" "2" \i < 2 ^ m\ in_set_member inthall) + have "length ?nextTreeList = 2^m" + using "2" highlowprop by auto + hence "?nextTreeList ! i = vebt_insert (treeList ! i) (low x n)" + using concat_inth[of "take (high x n) treeList" "vebt_insert (treeList ! i) (low x n)" "drop (high x n + 1) treeList"] + "2" True \high (max ma x) n = i\ \i < 2 ^ m\ concat_inth length_take max_def + by (metis Suc_eq_plus1 append_Cons append_Nil nth_list_update_eq upd_conv_take_nth_drop) + hence "vebt_member (?nextTreeList ! i) (low x n)" using Un_iff \i < 2 ^ m\ + \invar_vebt (treeList ! i) n\ both_member_options_equiv_member highlowprop + list.set_intros(1) set_append valid_insert_both_member_options_add + by (metis "11" True \high (max ma x) n = i\ max_def) + then show ?thesis proof(cases "mi = ma") + case True + then show ?thesis + by (metis \(take (high x n) treeList @ [VEBT_Insert.vebt_insert (treeList ! high x n) (low x n)] @ drop (high x n + 1) treeList) ! i = VEBT_Insert.vebt_insert (treeList ! i) (low x n)\ \mi \ max ma x\ \invar_vebt (treeList ! i) n\ highlowprop max_def valid_insert_both_member_options_add) + next + case False + hence "vebt_member (treeList ! i) (low ma n)" + by (metis "7" True \high (max ma x) n = i\ \invar_vebt (treeList ! i) n\ both_member_options_equiv_member highlowprop linorder_cases max.absorb3 max.absorb4 mimaxrel) + hence "vebt_member (?nextTreeList ! i) (low ma n) \ (low ma n = low x n)" + using post_member_pre_member[of " (treeList ! i)" n "low x n" "low ma n" ] + by (metis "2" "4.IH"(1) \(take (high x n) treeList @ [VEBT_Insert.vebt_insert (treeList ! high x n) (low x n)] @ drop (high x n + 1) treeList) ! i = VEBT_Insert.vebt_insert (treeList ! i) (low x n)\ \i < 2 ^ m\ both_member_options_equiv_member highlowprop member_bound nth_mem valid_insert_both_member_options_pres) + then show ?thesis + by (metis "2" "4.IH"(1) True \(take (high x n) treeList @ [VEBT_Insert.vebt_insert (treeList ! high x n) (low x n)] @ drop (high x n + 1) treeList) ! i = VEBT_Insert.vebt_insert (treeList ! i) (low x n)\ \high (max ma x) n = i\ both_member_options_equiv_member highlowprop max_def nth_mem valid_insert_both_member_options_add) + qed + next + case False + then show ?thesis + proof(cases "x < ma") + case True + then show ?thesis + by (metis "2" "7" False \high (max ma x) n = i\ \i < 2 ^ m\ abcdef highlowprop less_trans max.strict_order_iff nth_repl) + next + case False + hence "x > ma" + using mimaxrel nat_neq_iff by blast + then show ?thesis + by (metis "2" "4.IH"(1) One_nat_def \high (max ma x) n = i\ add.right_neutral add_Suc_right append_Cons highlowprop max.commute max.strict_order_iff nth_list_update_eq nth_mem self_append_conv2 upd_conv_take_nth_drop valid_insert_both_member_options_add) + qed + qed + qed + show "(\y. high y n = i \ both_member_options (?nextTreeList ! i) (low y n) \ mi < y \ y \ max ma x)" + proof + fix y + show "high y n = i \ both_member_options (?nextTreeList ! i) (low y n) \ mi < y \ y \ max ma x" + proof + assume bb:"high y n = i \ both_member_options (?nextTreeList ! i) (low y n)" + show " mi < y \ y \ max ma x" + proof(cases "i = high x n") + case True + hence cc:" i = high x n" by simp + have "invar_vebt (treeList ! i ) n" + by (metis "0" "2" \i < 2 ^ m\ in_set_member inthall) + have "length ?nextTreeList = 2^m" + using "2" highlowprop by auto + hence aa:"?nextTreeList ! i = vebt_insert (treeList ! i) (low x n)" + using concat_inth[of "take (high x n) treeList" "vebt_insert (treeList ! i) (low x n)" "drop (high x n + 1) treeList"] + by (metis "2" Suc_eq_plus1 append_Cons append_self_conv2 cc highlowprop nth_list_update_eq upd_conv_take_nth_drop) + hence "invar_vebt (?nextTreeList ! i) n" + by (simp add: "11" True) + hence "vebt_member (treeList ! i) (low y n) \ (low y n) = (low x n)" + by (metis \invar_vebt (treeList ! i) n\ aa bb highlowprop member_bound post_member_pre_member valid_member_both_member_options) + then show ?thesis + proof(cases "low y n = low x n") + case True + hence "high x n = high y n \ low y n = low x n" + by (simp add: bb cc) + hence "x = y" + by (metis bit_split_inv) + then show ?thesis + using abcdef by auto + next + case False + hence "vebt_member (treeList ! i) (low y n)" + using \vebt_member (treeList ! i) (low y n) \ low y n = low x n\ by blast + hence "mi \ ma " using 5 inthall + by (metis "2" \i < 2 ^ m\ min_Null_member not_min_Null_member) + then show ?thesis + using "7" \i < 2 ^ m\ \vebt_member (treeList ! i) (low y n)\ \invar_vebt (treeList ! i) n\ bb both_member_options_equiv_member max.coboundedI1 by blast + qed + next + case False + have "invar_vebt (treeList ! i ) n" + by (metis "0" "2" \i < 2 ^ m\ in_set_member inthall) + have "length ?nextTreeList = 2^m" + using "2" highlowprop by auto + hence aa:"?nextTreeList ! i = (treeList ! i)" + by (metis "2" False \i < 2 ^ m\ highlowprop nth_repl) + hence "both_member_options (treeList !i) (low y n)" + using bb by auto + hence "mi \ ma " using 5 "2" \i < 2 ^ m\ by force + then show ?thesis using 7 + using \both_member_options (treeList ! i) (low y n)\ \i < 2 ^ m\ bb max.coboundedI1 by blast + qed + qed + qed + qed + qed + qed + qed + then show ?thesis using invar_vebt.intros(4)[of ?nextTreeList n ?nextSummary m deg mi "max ma x"] + by (smt (z3) "10" "11" "12" "13" "15" "2" "3" "8" One_nat_def abcdef add.right_neutral add_Suc_right append_Cons highlowprop leD max.cobounded2 max.commute pos_n_replace self_append_conv2 upd_conv_take_nth_drop) + next + case False + hence abcdef: "x < mi" + using antisym_conv3 mimaxrel by blast + let ?h = "high mi n" and ?l="low mi n" + have highlowprop: "high mi n < 2^m \ low mi n < 2^n" + using "1" "3" "4.hyps"(3) "4.hyps"(7) "4.hyps"(8) deg_not_0 exp_split_high_low(1) exp_split_high_low(2) le_less_trans by blast + have 10:"vebt_insert (Node (Some (mi,ma)) deg treeList summary) x = + Node (Some (x, max mi ma)) deg (treeList[?h:=vebt_insert (treeList ! ?h) ?l]) + (if minNull (treeList ! ?h) then vebt_insert summary ?h else summary) " + by (metis "1" "2" "4.hyps"(3) "9" abcdef deg_not_0 div_greater_zero_iff highlowprop insert_simp_excp mimaxrel) + let ?maxnew = "max mi ma" and ?nextTreeList = "(treeList[ ?h :=vebt_insert (treeList ! ?h) ?l])" and + ?nextSummary = "(if minNull (treeList ! ?h) then vebt_insert summary ?h else summary)" + have 11: "( \ t \ set ?nextTreeList. invar_vebt t n)" proof + fix t + assume " t \ set ?nextTreeList" + then obtain i where "?nextTreeList ! i = t \ i < 2^m" + by (metis "2" in_set_conv_nth length_list_update) + show "invar_vebt t n" + by (metis "2" "4.IH"(1) \treeList[high mi n := VEBT_Insert.vebt_insert (treeList ! high mi n) (low mi n)] ! i = t \ i < 2 ^ m\ highlowprop nth_list_update_eq nth_list_update_neq nth_mem) + qed + have 12: "invar_vebt ?nextSummary n" + using "1" "4.IH"(2) "8" highlowprop by presburger + have 13: "\ i < 2^m. (\ y. both_member_options (?nextTreeList ! i) y) \ ( both_member_options ?nextSummary i)" + proof + fix i + show "i < 2 ^ m \ (\y. both_member_options ((?nextTreeList) ! i) y) = both_member_options (?nextSummary) i " + proof + assume "i< 2^m" + show "(\y. both_member_options ((?nextTreeList) ! i) y) = both_member_options (?nextSummary) i " + proof(cases "minNull (treeList ! high mi n)") + case True + hence tc: "minNull (treeList ! high mi n)" by simp + hence nsprop: "?nextSummary = vebt_insert summary ?h" by simp + have insprop:"?nextTreeList ! ?h = vebt_insert (treeList ! ?h) ?l" + by (simp add: "2" highlowprop) + then show ?thesis + proof(cases "i = ?h") + case True + have 161:"\ y. vebt_member (treeList ! ?h) y" + by (simp add: min_Null_member tc) + hence 162:"\ y. both_member_options (treeList ! ?h) y" + by (metis "2" "4.IH"(1) highlowprop nth_mem valid_member_both_member_options) + hence 163:"\ both_member_options summary i" + using "11" "2" "4" True \i < 2 ^ m\ by blast + have 164:"?nextTreeList ! i = vebt_insert (treeList ! ?h) ?l" + using True insprop by simp + have 165:"invar_vebt (vebt_insert (treeList ! ?h) ?l) n" + by (simp add: "2" "4.IH"(1) highlowprop) + have 166:"both_member_options (vebt_insert (treeList ! ?h) ?l) ?l" using myIHs[of "treeList ! ?h" ?l] + by (metis "0" "2" highlowprop in_set_member inthall valid_insert_both_member_options_add) + have 167:"\ y. both_member_options ((?nextTreeList) ! i) y " + using "164" "166" by auto + then show ?thesis + using "1" "11" "2" True nsprop valid_insert_both_member_options_add highlowprop by auto + next + case False + have "?nextTreeList ! i = treeList ! i" + using False by fastforce + have fstprop:"both_member_options ((?nextTreeList) ! i) y \ both_member_options (?nextSummary) i " for y + using "1" "4" \i < 2 ^ m\ \treeList[high mi n := VEBT_Insert.vebt_insert (treeList ! high mi n) (low mi n)] ! i = treeList ! i\ highlowprop valid_insert_both_member_options_pres by auto + moreover have" both_member_options (?nextSummary) i \ \ y . both_member_options ((?nextTreeList) ! i) y " + proof- + assume "both_member_options (?nextSummary) i " + have "i \ high mi n" + by (simp add: False) + hence "both_member_options summary i" + by (smt (z3) "1" "12" \both_member_options (if minNull (treeList ! high mi n) then VEBT_Insert.vebt_insert summary (high mi n) else summary) i\ \i < 2 ^ m\ both_member_options_equiv_member highlowprop post_member_pre_member) + hence "\ y. both_member_options (treeList ! i) y" + by (simp add: "4" \i < 2 ^ m\) + then show ?thesis + by (simp add: \treeList[high mi n := VEBT_Insert.vebt_insert (treeList ! high mi n) (low mi n)] ! i = treeList ! i\) + qed + ultimately show ?thesis by auto + qed + next + case False + hence "?nextSummary = summary" by simp + hence "\ y. both_member_options (treeList ! high mi n) y" + using not_min_Null_member False by blast + hence "both_member_options summary (high mi n)" + using "4" highlowprop by blast + hence " both_member_options (?nextTreeList ! high mi n) ?l" + by (metis "0" "2" highlowprop nth_list_update_eq nth_mem valid_insert_both_member_options_add) + then show ?thesis + by (metis (full_types, opaque_lifting) "4" False \both_member_options summary (high mi n)\ \i < 2 ^ m\ nth_list_update_neq) + qed + qed + qed + have 14: "(x = max ma mi \ (\ t \ set ?nextTreeList. \ y. both_member_options t y))" + using mimaxrel by linarith + have 15: "x \ max ma mi \ max ma mi < 2^deg" + using "6" abcdef by linarith + have 16: "(x \ max ma mi \ (\ i < 2^m. (high (max ma mi) n = i \ both_member_options (?nextTreeList ! i) (low (max ma mi) n)) \ + (\ y. (high y n = i \ both_member_options (?nextTreeList ! i) (low y n) ) \ x < y \ y \ max ma mi)))" + proof + assume "x \ max ma mi" + show "(\ i < 2^m. (high (max ma mi) n = i \ both_member_options (?nextTreeList ! i) (low (max ma mi) n)) \ + (\ y. (high y n = i \ both_member_options (?nextTreeList ! i) (low y n) ) \ x < y \ y \ max ma mi))" + proof + fix i::nat + show "i < 2 ^ m\ + (high (max ma mi) n = i \ both_member_options (?nextTreeList ! i) (low (max ma mi) n)) \ + (\y. high y n = i \ both_member_options (?nextTreeList ! i) (low y n) \ x < y \ y \ max ma mi)" + proof + assume "i < 2^m" + show " (high (max ma mi) n = i \ both_member_options (?nextTreeList ! i) (low (max ma mi) n)) \ + (\y. high y n = i \ both_member_options (?nextTreeList ! i) (low y n) \ x < y \ y \ max ma mi)" + proof + show "(high (max ma mi) n = i \ both_member_options (?nextTreeList ! i) (low (max ma mi) n))" + proof + assume "high (max ma mi) n = i" + show "both_member_options (?nextTreeList ! i) (low (max ma mi) n)" + proof(cases "high mi n = high ma n") + case True + have "invar_vebt (treeList ! i ) n" + by (metis "0" "2" \i < 2 ^ m\ in_set_member inthall) + have "length ?nextTreeList = 2^m" + using "2" highlowprop by auto + hence "?nextTreeList ! i = vebt_insert (treeList ! i) (low mi n)" + using concat_inth[of "take (high x n) treeList" "vebt_insert (treeList ! i) (low x n)" "drop (high x n + 1) treeList"] + by (metis "2" True \high (max ma mi) n = i\ highlowprop max_def nth_list_update_eq) + hence "vebt_member (?nextTreeList ! i) (low mi n)" + by (metis "11" "2" True \high (max ma mi) n = i\ \invar_vebt (treeList ! i) n\ highlowprop max_def set_update_memI valid_insert_both_member_options_add valid_member_both_member_options) + then show ?thesis + proof(cases "mi = ma") + case True + then show ?thesis + using \treeList[high mi n := VEBT_Insert.vebt_insert (treeList ! high mi n) (low mi n)] ! i = VEBT_Insert.vebt_insert (treeList ! i) (low mi n)\ \invar_vebt (treeList ! i) n\ highlowprop valid_insert_both_member_options_add by force + next + case False + hence "vebt_member (treeList ! i) (low ma n)" + using "6" "7" \high (max ma mi) n = i\ \i < 2 ^ m\ \invar_vebt (treeList ! i) n\ both_member_options_equiv_member by auto + hence "vebt_member (?nextTreeList ! i) (low ma n) \ (low ma n = low mi n)" + using post_member_pre_member[of " (treeList ! i)" n "low mi n" "low ma n" ] + by (metis "11" "2" "7" True \high (max ma mi) n = i\ \treeList[high mi n := VEBT_Insert.vebt_insert (treeList ! high mi n) (low mi n)] ! i = VEBT_Insert.vebt_insert (treeList ! i) (low mi n)\ \invar_vebt (treeList ! i) n\ highlowprop max_def member_bound set_update_memI valid_insert_both_member_options_pres valid_member_both_member_options) + then show ?thesis + by (metis "11" "2" "4.hyps"(7) "7" False True \high (max ma mi) n = i\ \treeList[high mi n := VEBT_Insert.vebt_insert (treeList ! high mi n) (low mi n)] ! i = VEBT_Insert.vebt_insert (treeList ! i) (low mi n)\ both_member_options_equiv_member highlowprop less_irrefl max.commute max_def set_update_memI) + qed + next + case False + hence "?nextTreeList ! i = treeList ! i" + by (metis "4.hyps"(7) \high (max ma mi) n = i\ max.commute max_def nth_list_update_neq) + then show ?thesis + by (metis "4.hyps"(7) "7" False \high (max ma mi) n = i\ \i < 2 ^ m\ max.orderE) + qed + qed + show "(\y. high y n = i \ both_member_options (?nextTreeList ! i) (low y n) \ x < y \ y \ max ma mi)" + proof + fix y + show "high y n = i \ both_member_options (?nextTreeList ! i) (low y n) \ x < y \ y \ max ma mi" + proof + assume bb:"high y n = i \ both_member_options (?nextTreeList ! i) (low y n)" + show " x < y \ y \ max ma mi" + proof(cases "i = high mi n") + case True + hence cc:" i = high mi n" by simp + have "invar_vebt (treeList ! i ) n" + by (metis "0" "2" \i < 2 ^ m\ in_set_member inthall) + have "length ?nextTreeList = 2^m" + using "2" highlowprop by auto + hence aa:"?nextTreeList ! i = vebt_insert (treeList ! i) (low mi n)" + using concat_inth[of "take (high x n) treeList" "vebt_insert (treeList ! i) (low x n)" "drop (high x n + 1) treeList"] + by (simp add: cc highlowprop) + hence "invar_vebt (?nextTreeList ! i) n" + by (simp add: "2" "4.IH"(1) cc highlowprop) + hence "vebt_member (treeList ! i) (low y n) \ (low y n) = (low mi n)" + by (metis \invar_vebt (treeList ! i) n\ aa bb both_member_options_equiv_member highlowprop member_bound post_member_pre_member) + then show ?thesis + proof(cases "low y n = low mi n") + case True + hence "high mi n = high y n \ low y n = low mi n" + by (simp add: bb cc) + hence "mi = y" + by (metis bit_split_inv) + then show ?thesis + using abcdef by auto + next + case False + hence "vebt_member (treeList ! i) (low y n)" + using \vebt_member (treeList ! i) (low y n) \ low y n = low mi n\ by blast + hence "mi \ ma " using 5 inthall + by (metis "2" \i < 2 ^ m\ min_Null_member not_min_Null_member) + then show ?thesis + using "7" + by (metis \i < 2 ^ m\ \vebt_member (treeList ! i) (low y n)\ \invar_vebt (treeList ! i) n\ abcdef bb both_member_options_equiv_member max.absorb1 max.strict_order_iff max_less_iff_conj) + qed + next + case False + have "invar_vebt (treeList ! i ) n" + by (metis "0" "2" \i < 2 ^ m\ in_set_member inthall) + have "length ?nextTreeList = 2^m" + using "2" highlowprop by auto + hence aa:"?nextTreeList ! i = (treeList ! i)" + using False by auto + hence "both_member_options (treeList ! i) (low y n)" + using bb by auto + hence "mi \ ma " using 5 "2" \i < 2 ^ m\ by force + then show ?thesis using 7 + by (metis \both_member_options (treeList ! i) (low y n)\ \i < 2 ^ m\ abcdef bb max.absorb1 max.strict_order_iff max_less_iff_conj) + qed + qed + qed + qed + qed + qed + qed + then show ?thesis using invar_vebt.intros(4)[of ?nextTreeList n ?nextSummary m deg x "max ma mi"] + by (smt (z3) "10" "11" "12" "13" "14" "15" "2" "3" "4.hyps"(3) "4.hyps"(7) length_list_update max.absorb1 max.absorb2) + qed + qed +next + case (5 treeList n summary m deg mi ma) + hence myIHs: "x \ set treeList \ invar_vebt x n \ xa < 2 ^ n \ invar_vebt (vebt_insert x xa) n" for x xa by simp + hence 0: "( \ t \ set treeList. invar_vebt t n)" and 1: " invar_vebt summary m" and 2:"length treeList = 2^m" and 3:" deg = n+m" and + 4: "(\ i < 2^m. (\ y. both_member_options (treeList ! i) y) \ ( both_member_options summary i))" and + 5: "(mi = ma \ (\ t \ set treeList. \ y. both_member_options t y))" and 6:"mi \ ma \ ma < 2^deg" and + 7: "(mi \ ma \ (\ i < 2^m. (high ma n = i \ both_member_options (treeList ! i) (low ma n)) \ + (\ y. (high y n = i \ both_member_options (treeList ! i) (low y n) ) \ mi < y \ y \ ma)))" + and 8: "Suc n = m" and 9: "deg div 2 = n" + using "5" add_self_div_2 apply blast+ by (simp add: "5.hyps"(3) "5.hyps"(4)) + then show ?case + proof(cases "x = mi \ x = ma") + case True + then show ?thesis using insert_simp_mima[of x mi ma deg treeList summary] + invar_vebt.intros(5)[of treeList n summary m deg mi ma] + by (smt "0" "1" "2" "3" "4" "5" "5.hyps"(3) "5.hyps"(7) "5.hyps"(8) "7" "9" div_less not_less not_one_le_zero set_n_deg_not_0) + next + case False + hence mimaxrel: "x \ mi \ x \ ma" by simp + then show ?thesis + proof(cases "mi < x") + case True + hence abcdef: "mi < x" by simp + let ?h = "high x n" and ?l="low x n" + have highlowprop: "high x n < 2^m \ low x n < 2^n" + by (metis "1" "2" "3" "5.IH"(1) "5.prems" Euclidean_Division.div_eq_0_iff add_nonneg_eq_0_iff deg_not_0 div_exp_eq exp_split_high_low(2) high_def not_one_le_zero one_add_one power_not_zero set_n_deg_not_0 zero_le_one zero_neq_one) + have 10:"vebt_insert (Node (Some (mi,ma)) deg treeList summary) x = + Node (Some (mi, max x ma)) deg (treeList[?h :=vebt_insert (treeList ! ?h) ?l]) + (if minNull (treeList ! ?h) then vebt_insert summary ?h else summary) " + using "2" "3" False True \high x n < 2 ^ m \ low x n < 2 ^ n\ insert_simp_norm + by (smt "5.IH"(1) "9" div_greater_zero_iff div_if less_Suc_eq_0_disj not_one_le_zero set_n_deg_not_0) + let ?maxnew = "max x ma" and ?nextTreeList = "(treeList[ ?h :=vebt_insert (treeList ! ?h) ?l])" and + ?nextSummary = "(if minNull (treeList ! ?h) then vebt_insert summary ?h else summary)" + have 11: "( \ t \ set ?nextTreeList. invar_vebt t n)" + proof + fix t + assume " t \ set ?nextTreeList" + then obtain i where "i <2^m \ ?nextTreeList ! i = t" + by (metis "2" in_set_conv_nth length_list_update) + show "invar_vebt t n" + by (metis "2" "5.IH"(1) \i < 2 ^ m \ treeList[high x n := VEBT_Insert.vebt_insert (treeList ! high x n) (low x n)] ! i = t\ highlowprop nth_list_update_eq nth_list_update_neq nth_mem) + qed + have 12: "invar_vebt ?nextSummary m" + by (simp add: "1" "5.IH"(2) highlowprop) + have 13: "\ i < 2^m. (\ y. both_member_options (?nextTreeList ! i) y) \ ( both_member_options ?nextSummary i)" + proof + fix i + show "i < 2 ^ m \ (\y. both_member_options ((?nextTreeList) ! i) y) = both_member_options (?nextSummary) i " + proof + assume "i< 2^m" + show "(\y. both_member_options ((?nextTreeList) ! i) y) = both_member_options (?nextSummary) i " + proof(cases "minNull (treeList ! high x n)") + case True + hence tc: "minNull (treeList ! high x n)" by simp + hence nsprop: "?nextSummary = vebt_insert summary ?h" by simp + have insprop:"?nextTreeList ! ?h = vebt_insert (treeList ! ?h) ?l" + by (simp add: "2" highlowprop) + then show ?thesis + proof(cases "i = ?h") + case True + have 161:"\ y. vebt_member (treeList ! ?h) y" + by (simp add: min_Null_member tc) + hence 162:"\ y. both_member_options (treeList ! ?h) y" + by (metis "0" "2" highlowprop nth_mem valid_member_both_member_options) + hence 163:"\ both_member_options summary i" + using "11" "2" "4" True \i < 2 ^ m\ by blast + have 164:"?nextTreeList ! i = vebt_insert (treeList ! ?h) ?l" + using True insprop by simp + have 165:"invar_vebt (vebt_insert (treeList ! ?h) ?l) n" + by (simp add: "11" "2" highlowprop set_update_memI) + have 166:"both_member_options (vebt_insert (treeList ! ?h) ?l) ?l" using myIHs[of "treeList ! ?h" ?l] + by (metis "0" "2" highlowprop in_set_member inthall valid_insert_both_member_options_add) + have 167:"\ y. both_member_options ((?nextTreeList) ! i) y " + using "164" "166" by auto + then show ?thesis + using "1" "11" "2" True nsprop valid_insert_both_member_options_add highlowprop by auto + next + case False + have "?nextTreeList ! i = treeList ! i" + using False by auto + have fstprop:"both_member_options ((?nextTreeList) ! i) y \ both_member_options (?nextSummary) i " for y + using "1" "4" \i < 2 ^ m\ \treeList[high x n := VEBT_Insert.vebt_insert (treeList ! high x n) (low x n)] ! i = treeList ! i\ highlowprop valid_insert_both_member_options_pres by auto + moreover have" both_member_options (?nextSummary) i \ \ y . both_member_options ((?nextTreeList) ! i) y " + proof- + assume "both_member_options (?nextSummary) i " + have "i \ high x n" + by (simp add: False) + hence "both_member_options summary i" + by (smt "1" "12" \both_member_options (if minNull (treeList ! high x n) then vebt_insert summary (high x n) else summary) i\ \i < 2 ^ m\ both_member_options_equiv_member highlowprop post_member_pre_member) + hence "\ y. both_member_options (treeList ! i) y" + by (simp add: "4" \i < 2 ^ m\) + then show ?thesis + by (simp add: \treeList[high x n := VEBT_Insert.vebt_insert (treeList ! high x n) (low x n)] ! i = treeList ! i\) + qed + ultimately show ?thesis by auto + qed + next + case False + hence "?nextSummary = summary" by simp + hence "\ y. both_member_options (treeList ! high x n) y" + using not_min_Null_member False by blast + hence "both_member_options summary (high x n)" + using "4" highlowprop by blast + hence " both_member_options (?nextTreeList ! high x n) ?l" + by (metis "0" "2" highlowprop nth_list_update_eq nth_mem valid_insert_both_member_options_add) + then show ?thesis + by (metis (full_types) "4" False \both_member_options summary (high x n)\ \i < 2 ^ m\ nth_list_update_neq) + qed + qed + qed + have 14: "(mi = max ma x \ (\ t \ set ?nextTreeList. \ y. both_member_options t y))" + using True max_less_iff_conj by blast + have 15: "mi \ max ma x \ max ma x < 2^deg" + using "5.hyps"(8) "5.prems" abcdef by auto + have 16: "(mi \ max ma x \ (\ i < 2^m. (high (max ma x) n = i \ both_member_options (?nextTreeList ! i) (low (max ma x) n)) \ + (\ y. (high y n = i \ both_member_options (?nextTreeList ! i) (low y n) ) \ mi < y \ y \ max ma x)))" + proof + assume "mi \ max ma x" + show "(\ i < 2^m. (high (max ma x) n = i \ both_member_options (?nextTreeList ! i) (low (max ma x) n)) \ + (\ y. (high y n = i \ both_member_options (?nextTreeList ! i) (low y n) ) \ mi < y \ y \ max ma x))" + proof + fix i::nat + show "i < 2 ^ m\ + (high (max ma x) n = i \ both_member_options (?nextTreeList ! i) (low (max ma x) n)) \ + (\y. high y n = i \ both_member_options (?nextTreeList ! i) (low y n) \ mi < y \ y \ max ma x)" + proof + assume "i < 2^m" + show " (high (max ma x) n = i \ both_member_options (?nextTreeList ! i) (low (max ma x) n)) \ + (\y. high y n = i \ both_member_options (?nextTreeList ! i) (low y n) \ mi < y \ y \ max ma x)" + proof + show "(high (max ma x) n = i \ both_member_options (?nextTreeList ! i) (low (max ma x) n))" + proof + assume "high (max ma x) n = i" + show "both_member_options (?nextTreeList ! i) (low (max ma x) n)" + proof(cases "high x n = high ma n") + case True + have "invar_vebt (treeList ! i ) n" + by (metis "0" "2" \i < 2 ^ m\ in_set_member inthall) + have "length ?nextTreeList = 2^m" + using "2" highlowprop by auto + hence "?nextTreeList ! i = vebt_insert (treeList ! i) (low x n)" + using concat_inth[of "take (high x n) treeList" "vebt_insert (treeList ! i) (low x n)" "drop (high x n + 1) treeList"] + by (metis "2" False True \high (max ma x) n = i\ highlowprop linorder_neqE_nat max.commute max.strict_order_iff nth_list_update_eq) + hence "vebt_member (?nextTreeList ! i) (low x n)" + by (metis "11" "2" True \high (max ma x) n = i\ \invar_vebt (treeList ! i) n\ highlowprop max_def set_update_memI valid_insert_both_member_options_add valid_member_both_member_options) + then show ?thesis + proof(cases "mi = ma") + case True + then show ?thesis + by (metis \treeList[high x n := VEBT_Insert.vebt_insert (treeList ! high x n) (low x n)] ! i = VEBT_Insert.vebt_insert (treeList ! i) (low x n)\ \invar_vebt (treeList ! i) n\ abcdef highlowprop max.commute max.strict_order_iff valid_insert_both_member_options_add) + next + case False + hence "vebt_member (treeList ! i) (low ma n)" + by (metis "7" True \high (max ma x) n = i\ \invar_vebt (treeList ! i) n\ highlowprop max_def valid_member_both_member_options) + hence "vebt_member (?nextTreeList ! i) (low ma n) \ (low ma n = low x n)" + using post_member_pre_member[of " (treeList ! i)" n "low x n" "low ma n" ] + by (metis "1" "11" "2" "3" "5.hyps"(8) "7" False True \treeList[high x n := VEBT_Insert.vebt_insert (treeList ! high x n) (low x n)] ! i = VEBT_Insert.vebt_insert (treeList ! i) (low x n)\ \invar_vebt (treeList ! i) n\ deg_not_0 exp_split_high_low(2) highlowprop nth_list_update_neq set_update_memI valid_insert_both_member_options_pres valid_member_both_member_options) + then show ?thesis + by (metis "11" "2" True \high (max ma x) n = i\ \treeList[high x n := VEBT_Insert.vebt_insert (treeList ! high x n) (low x n)] ! i = VEBT_Insert.vebt_insert (treeList ! i) (low x n)\ \invar_vebt (treeList ! i) n\ both_member_options_equiv_member highlowprop max_def set_update_memI valid_insert_both_member_options_add) + qed + next + case False + then show ?thesis + by (metis "0" "2" "7" \high (max ma x) n = i\ \i < 2 ^ m\ \mi \ max ma x\ highlowprop max_def nth_list_update_eq nth_list_update_neq nth_mem valid_insert_both_member_options_add) + qed + qed + show "(\y. high y n = i \ both_member_options (?nextTreeList ! i) (low y n) \ mi < y \ y \ max ma x)" + proof + fix y + show "high y n = i \ both_member_options (?nextTreeList ! i) (low y n) \ mi < y \ y \ max ma x" + proof + assume bb:"high y n = i \ both_member_options (?nextTreeList ! i) (low y n)" + show " mi < y \ y \ max ma x" + proof(cases "i = high x n") + case True + hence cc:" i = high x n" by simp + have "invar_vebt (treeList ! i ) n" + by (metis "0" "2" \i < 2 ^ m\ in_set_member inthall) + have "length ?nextTreeList = 2^m" + using "2" highlowprop by auto + hence aa:"?nextTreeList ! i = vebt_insert (treeList ! i) (low x n)" + using concat_inth[of "take (high x n) treeList" "vebt_insert (treeList ! i) (low x n)" "drop (high x n + 1) treeList"] + by (simp add: cc highlowprop) + hence "invar_vebt (?nextTreeList ! i) n" + by (simp add: "2" "5.IH"(1) cc highlowprop) + hence "vebt_member (treeList ! i) (low y n) \ (low y n) = (low x n)" + by (metis \high y n = i \ both_member_options ((treeList[?h:=vebt_insert (treeList ! high x n) (low x n)]) ! i) (low y n)\ + \invar_vebt (treeList ! i) n\ aa highlowprop member_bound post_member_pre_member valid_member_both_member_options) + then show ?thesis + proof(cases "low y n = low x n") + case True + hence "high x n = high y n \ low y n = low x n" + by (simp add: bb cc) + hence "x = y" + by (metis bit_split_inv) + then show ?thesis + using abcdef by auto + next + case False + hence "vebt_member (treeList ! i) (low y n)" + using \vebt_member (treeList ! i) (low y n) \ low y n = low x n\ by blast + hence "mi \ ma " using 5 inthall + by (metis "2" \i < 2 ^ m\ min_Null_member not_min_Null_member) + then show ?thesis + using "7" \i < 2 ^ m\ \vebt_member (treeList ! i) (low y n)\ \invar_vebt (treeList ! i) n\ bb both_member_options_equiv_member max.coboundedI1 by blast + qed + next + case False + have "invar_vebt (treeList ! i ) n" + by (metis "0" "2" \i < 2 ^ m\ in_set_member inthall) + have "length ?nextTreeList = 2^m" + using "2" highlowprop by auto + hence aa:"?nextTreeList ! i = (treeList ! i)" + using False by auto + hence "both_member_options (treeList ! i) (low y n)" + using bb by auto + hence "mi \ ma " using 5 + using "2" \i < 2 ^ m\ by fastforce + then show ?thesis using 7 + using \both_member_options (treeList ! i) (low y n)\ \i < 2 ^ m\ bb max.coboundedI1 by blast + qed + qed + qed + qed + qed + qed + qed + then show ?thesis using invar_vebt.intros(5)[of ?nextTreeList n ?nextSummary m deg mi "max ma x"] + by (smt (z3) "10" "11" "12" "13" "14" "15" "2" "3" "8" length_list_update max.commute) + next + case False + hence abcdef: "x < mi" + using antisym_conv3 mimaxrel by blast + let ?h = "high mi n" and ?l="low mi n" + have highlowprop: "high mi n < 2^m \ low mi n < 2^n" + by (metis (full_types) "1" "2" "3" "5.IH"(1) "5.hyps"(7) "5.hyps"(8) deg_not_0 exp_split_high_low(1) exp_split_high_low(2) le_less_trans not_one_le_zero set_n_deg_not_0) + have 10:"vebt_insert (Node (Some (mi,ma)) deg treeList summary) x = + Node (Some (x, max mi ma)) deg (treeList[ ?h :=vebt_insert (treeList ! ?h) ?l]) + (if minNull (treeList ! ?h) then vebt_insert summary ?h else summary) " + by (metis "0" "2" "9" abcdef div_less highlowprop insert_simp_excp mimaxrel not_less not_one_le_zero set_n_deg_not_0) + let ?maxnew = "max mi ma" and ?nextTreeList = "(treeList[ ?h:=vebt_insert (treeList ! ?h) ?l])" and + ?nextSummary = "(if minNull (treeList ! ?h) then vebt_insert summary ?h else summary)" + have 11: "( \ t \ set ?nextTreeList. invar_vebt t n)" + proof + fix t + assume " t \ set ?nextTreeList" + then obtain i where "i < 2^m \ ?nextTreeList ! i = t" + by (metis "2" in_set_conv_nth length_list_update) + thus "invar_vebt t n" + by (metis "2" "5.IH"(1) highlowprop nth_list_update_eq nth_list_update_neq nth_mem) + qed + have 12: "invar_vebt ?nextSummary m" + by (simp add: "1" "5.IH"(2) highlowprop) + have 13: "\ i < 2^m. (\ y. both_member_options (?nextTreeList ! i) y) \ ( both_member_options ?nextSummary i)" + proof + fix i + show "i < 2 ^ m \ (\y. both_member_options ((?nextTreeList) ! i) y) = both_member_options (?nextSummary) i " + proof + assume "i< 2^m" + show "(\y. both_member_options ((?nextTreeList) ! i) y) = both_member_options (?nextSummary) i " + proof(cases "minNull (treeList ! high mi n)") + case True + hence tc: "minNull (treeList ! high mi n)" by simp + hence nsprop: "?nextSummary = vebt_insert summary ?h" by simp + have insprop:"?nextTreeList ! ?h = vebt_insert (treeList ! ?h) ?l" + by (simp add: "2" highlowprop) + then show ?thesis + proof(cases "i = ?h") + case True + have 161:"\ y. vebt_member (treeList ! ?h) y" + by (simp add: min_Null_member tc) + hence 162:"\ y. both_member_options (treeList ! ?h) y" + by (metis "0" "2" highlowprop nth_mem valid_member_both_member_options) + hence 163:"\ both_member_options summary i" + using "11" "2" "4" True \i < 2 ^ m\ by blast + have 164:"?nextTreeList ! i = vebt_insert (treeList ! ?h) ?l" + using True insprop by simp + have 165:"invar_vebt (vebt_insert (treeList ! ?h) ?l) n" + by (simp add: "11" "2" highlowprop set_update_memI) + have 166:"both_member_options (vebt_insert (treeList ! ?h) ?l) ?l" using myIHs[of "treeList ! ?h" ?l] + by (metis "0" "2" highlowprop in_set_member inthall valid_insert_both_member_options_add) + have 167:"\ y. both_member_options ((?nextTreeList) ! i) y " + using "164" "166" by auto + then show ?thesis + using "1" "11" "2" True nsprop valid_insert_both_member_options_add highlowprop by auto + next + case False + have "?nextTreeList ! i = treeList ! i" + by (metis False nth_list_update_neq) + have fstprop:"both_member_options ((?nextTreeList) ! i) y \ both_member_options (?nextSummary) i " for y + using "1" "4" \i < 2 ^ m\ \treeList[high mi n := VEBT_Insert.vebt_insert (treeList ! high mi n) (low mi n)] ! i = treeList ! i\ highlowprop valid_insert_both_member_options_pres by auto + moreover have" both_member_options (?nextSummary) i \ \ y . both_member_options ((?nextTreeList) ! i) y " + proof- + assume "both_member_options (?nextSummary) i " + have "i \ high mi n" + by (simp add: False) + hence "both_member_options summary i" + by (smt (z3) "1" "12" \both_member_options (if minNull (treeList ! high mi n) then VEBT_Insert.vebt_insert summary (high mi n) else summary) i\ \i < 2 ^ m\ both_member_options_equiv_member highlowprop post_member_pre_member) + hence "\ y. both_member_options (treeList ! i) y" + by (simp add: "4" \i < 2 ^ m\) + then show ?thesis + by (simp add: \treeList[high mi n := VEBT_Insert.vebt_insert (treeList ! high mi n) (low mi n)] ! i = treeList ! i\) + qed + ultimately show ?thesis by auto + qed + next + case False + hence "?nextSummary = summary" by simp + hence "\ y. both_member_options (treeList ! high mi n) y" + using not_min_Null_member False by blast + hence "both_member_options summary (high mi n)" + using "4" highlowprop by blast + hence " both_member_options (?nextTreeList ! high mi n) ?l" + by (metis "0" "2" highlowprop nth_list_update_eq nth_mem valid_insert_both_member_options_add) + then show ?thesis + by (metis (full_types) "4" False \both_member_options summary (high mi n)\ \i < 2 ^ m\ nth_list_update_neq) + qed + qed + qed + have 14: "(x = max ma mi \ (\ t \ set ?nextTreeList. \ y. both_member_options t y))" + using mimaxrel by linarith + have 15: "x \ max ma mi \ max ma mi < 2^deg" + using "6" abcdef by linarith + have 16: "(x \ max ma mi \ (\ i < 2^m. (high (max ma mi) n = i \ both_member_options (?nextTreeList ! i) (low (max ma mi) n)) \ + (\ y. (high y n = i \ both_member_options (?nextTreeList ! i) (low y n) ) \ x < y \ y \ max ma mi)))" + proof + assume "x \ max ma mi" + show "(\ i < 2^m. (high (max ma mi) n = i \ both_member_options (?nextTreeList ! i) (low (max ma mi) n)) \ + (\ y. (high y n = i \ both_member_options (?nextTreeList ! i) (low y n) ) \ x < y \ y \ max ma mi))" + proof + fix i::nat + show "i < 2 ^ m\ + (high (max ma mi) n = i \ both_member_options (?nextTreeList ! i) (low (max ma mi) n)) \ + (\y. high y n = i \ both_member_options (?nextTreeList ! i) (low y n) \ x < y \ y \ max ma mi)" + proof + assume "i < 2^m" + show " (high (max ma mi) n = i \ both_member_options (?nextTreeList ! i) (low (max ma mi) n)) \ + (\y. high y n = i \ both_member_options (?nextTreeList ! i) (low y n) \ x < y \ y \ max ma mi)" + proof + show "(high (max ma mi) n = i \ both_member_options (?nextTreeList ! i) (low (max ma mi) n))" + proof + assume "high (max ma mi) n = i" + show "both_member_options (?nextTreeList ! i) (low (max ma mi) n)" + proof(cases "high mi n = high ma n") + case True + have "invar_vebt (treeList ! i ) n" + by (metis "0" "2" \i < 2 ^ m\ in_set_member inthall) + have "length ?nextTreeList = 2^m" + using "2" highlowprop by auto + hence "?nextTreeList ! i = vebt_insert (treeList ! i) (low mi n)" + using concat_inth[of "take (high x n) treeList" "vebt_insert (treeList ! i) (low x n)" "drop (high x n + 1) treeList"] + by (metis "2" "5.hyps"(7) True \high (max ma mi) n = i\ highlowprop max.orderE nth_list_update_eq) + hence "vebt_member (?nextTreeList ! i) (low mi n)" + by (metis "11" "2" True \high (max ma mi) n = i\ \invar_vebt (treeList ! i) n\ highlowprop max_def set_update_memI valid_insert_both_member_options_add valid_member_both_member_options) + then show ?thesis + proof(cases "mi = ma") + case True + then show ?thesis + using \treeList[high mi n := VEBT_Insert.vebt_insert (treeList ! high mi n) (low mi n)] ! i = VEBT_Insert.vebt_insert (treeList ! i) (low mi n)\ \invar_vebt (treeList ! i) n\ highlowprop valid_insert_both_member_options_add by auto + next + case False + hence "vebt_member (treeList ! i) (low ma n)" + using "6" "7" \high (max ma mi) n = i\ \i < 2 ^ m\ \invar_vebt (treeList ! i) n\ both_member_options_equiv_member by auto + hence "vebt_member (?nextTreeList ! i) (low ma n) \ (low ma n = low mi n)" + using post_member_pre_member[of " (treeList ! i)" n "low mi n" "low ma n" ] + by (metis "1" "11" "2" "3" "5.hyps"(8) "7" True \high (max ma mi) n = i\ \treeList[high mi n := VEBT_Insert.vebt_insert (treeList ! high mi n) (low mi n)] ! i = VEBT_Insert.vebt_insert (treeList ! i) (low mi n)\ \invar_vebt (treeList ! i) n\ deg_not_0 exp_split_high_low(2) highlowprop max_def set_update_memI valid_insert_both_member_options_pres valid_member_both_member_options) + then show ?thesis + by (metis "5.hyps"(7) "7" False \high (max ma mi) n = i\ \i < 2 ^ m\ \vebt_member (treeList ! i) (low ma n)\ \treeList[high mi n := VEBT_Insert.vebt_insert (treeList ! high mi n) (low mi n)] ! i = VEBT_Insert.vebt_insert (treeList ! i) (low mi n)\ \invar_vebt (treeList ! i) n\ highlowprop max.absorb1 member_bound valid_insert_both_member_options_pres) + qed + next + case False + hence "?nextTreeList ! i = treeList ! i" + by (metis "5.hyps"(7) \high (max ma mi) n = i\ max.commute max_def nth_list_update_neq) + then show ?thesis + proof(cases "mi < ma") + case True + then show ?thesis + by (metis "5.hyps"(7) "7" False \high (max ma mi) n = i\ \i < 2 ^ m\ \treeList[high mi n := VEBT_Insert.vebt_insert (treeList ! high mi n) (low mi n)] ! i = treeList ! i\ max.commute max_def) + next + case False + hence "mi \ ma " by simp + hence "mi = ma" + by (simp add: "6" eq_iff) + hence "\both_member_options (treeList ! i) (low (max ma mi) n)" using 5 "2" \i < 2 ^ m\ by auto + then show ?thesis + by (metis "11" "2" \high (max ma mi) n = i\ \mi = ma\ \treeList[high mi n := VEBT_Insert.vebt_insert (treeList ! high mi n) (low mi n)] ! i = treeList ! i\ highlowprop max.idem nth_list_update_eq set_update_memI valid_insert_both_member_options_add) + qed + qed + qed + show "(\y. high y n = i \ both_member_options (?nextTreeList ! i) (low y n) \ x < y \ y \ max ma mi)" + proof + fix y + show "high y n = i \ both_member_options (?nextTreeList ! i) (low y n) \ x < y \ y \ max ma mi" + proof + assume bb:"high y n = i \ both_member_options (?nextTreeList ! i) (low y n)" + show " x < y \ y \ max ma mi" + proof(cases "i = high mi n") + case True + hence cc:" i = high mi n" by simp + have "invar_vebt (treeList ! i ) n" + by (metis "0" "2" \i < 2 ^ m\ in_set_member inthall) + have "length ?nextTreeList = 2^m" + using "2" highlowprop by auto + hence aa:"?nextTreeList ! i = vebt_insert (treeList ! i) (low mi n)" + using concat_inth[of "take (high x n) treeList" "vebt_insert (treeList ! i) (low x n)" "drop (high x n + 1) treeList"] + by (simp add: cc highlowprop) + hence "invar_vebt (?nextTreeList ! i) n" + by (simp add: "2" "5.IH"(1) \i < 2 ^ m\ highlowprop) + hence "vebt_member (treeList ! i) (low y n) \ (low y n) = (low mi n)" + by (metis \invar_vebt (treeList ! i) n\ aa bb both_member_options_equiv_member highlowprop member_bound post_member_pre_member) + then show ?thesis + proof(cases "low y n = low mi n") + case True + hence "high mi n = high y n \ low y n = low mi n" + by (simp add: bb cc) + hence "mi = y" + by (metis bit_split_inv) + then show ?thesis + using abcdef by auto + next + case False + hence "vebt_member (treeList ! i) (low y n)" + using \vebt_member (treeList ! i) (low y n) \ low y n = low mi n\ by blast + hence "mi \ ma " using 5 inthall + by (metis "2" \i < 2 ^ m\ min_Null_member not_min_Null_member) + then show ?thesis + using "7" + by (metis \i < 2 ^ m\ \vebt_member (treeList ! i) (low y n)\ \invar_vebt (treeList ! i) n\ abcdef bb both_member_options_equiv_member max.absorb1 max.strict_order_iff max_less_iff_conj) + qed + next + case False + have "invar_vebt (treeList ! i ) n" + by (metis "0" "2" \i < 2 ^ m\ in_set_member inthall) + have "length ?nextTreeList = 2^m" + using "2" highlowprop by auto + hence aa:"?nextTreeList ! i = (treeList ! i)" + using False by auto + hence "both_member_options (treeList ! i) (low y n)" + using bb by auto + hence "mi \ ma " using 5 "2" \i < 2 ^ m\ by fastforce + then show ?thesis using 7 + by (metis \both_member_options (treeList ! i) (low y n)\ \i < 2 ^ m\ abcdef bb max.absorb1 max.strict_order_iff max_less_iff_conj) + qed + qed + qed + qed + qed + qed + qed + then show ?thesis using invar_vebt.intros(5)[of ?nextTreeList n ?nextSummary m deg x "max ma mi"] + by (smt (z3) "10" "11" "12" "13" "14" "15" "2" "3" "5.hyps"(7) "8" length_list_update max.absorb2 max.orderE) + qed + qed +qed + +subsection \Correctness with Respect to Set Interpretation\ + +theorem insert_corr: + assumes "invar_vebt t n " and "x < 2^n " + shows " set_vebt' t \ {x} = set_vebt' (vebt_insert t x) " +proof + show "set_vebt' t \ {x} \ set_vebt' (vebt_insert t x)" + proof + fix y + assume "y \ set_vebt' t \ {x}" + show "y \set_vebt' (vebt_insert t x)" + proof(cases "x=y") + case True + then show ?thesis + by (metis (full_types) assms(1) assms(2) both_member_options_equiv_member mem_Collect_eq set_vebt'_def valid_insert_both_member_options_add valid_pres_insert) + next + case False + have "vebt_member t y" + using False \y \ set_vebt' t \ {x}\ set_vebt'_def by auto + hence "vebt_member (vebt_insert t x) y" + by (meson assms(1) assms(2) both_member_options_equiv_member member_bound valid_insert_both_member_options_pres valid_pres_insert) + then show ?thesis + by (simp add: set_vebt'_def) + qed + qed + show " set_vebt' (vebt_insert t x) \ set_vebt' t \ {x} " + proof + fix y + assume "y \ set_vebt' (vebt_insert t x)" + show "y \set_vebt' t \ {x}" + proof(cases "x=y") + case True + then show ?thesis by simp + next + case False + hence "vebt_member t y \ x=y" using post_member_pre_member + using \y \ set_vebt' (vebt_insert t x)\ assms(1) assms(2) set_vebt'_def member_bound valid_pres_insert by fastforce + hence "vebt_member t y" + by (simp add: False) + hence "y \ set_vebt' t" + by (simp add: set_vebt'_def) + then show ?thesis by simp + qed + qed +qed + +corollary insert_correct: assumes "invar_vebt t n " and "x < 2^n " shows + " set_vebt t \ {x} = set_vebt (vebt_insert t x) " + using assms(1) assms(2) insert_corr set_vebt_set_vebt'_valid valid_pres_insert by blast + +fun insert'::"VEBT \ nat \ VEBT" where + "insert' (Leaf a b) x = vebt_insert (Leaf a b) x"| + "insert' (Node info deg treeList summary) x = + (if x \ 2^deg then (Node info deg treeList summary ) + else vebt_insert (Node info deg treeList summary) x)" + +theorem insert'_pres_valid: assumes "invar_vebt t n" shows "invar_vebt (insert' t x) n" + using assms + apply cases + apply (metis One_nat_def deg1Leaf insert'.simps(1) vebt_insert.simps(1)) + apply (metis assms insert'.simps(2) leI valid_pres_insert)+ + done + +theorem insert'_correct: assumes "invar_vebt t n" + shows "set_vebt (insert' t x) = (set_vebt t \ {x})\{0..2^n-1}" +proof(cases t) + case (Node x11 x12 x13 x14) + then show ?thesis + proof(cases "x < 2^n") + case True + hence "set_vebt (insert' t x) = set_vebt(vebt_insert t x)" + by (metis Node assms deg_deg_n insert'.simps(2) leD) + moreover hence "set_vebt(vebt_insert t x) = set_vebt t \ {x}" + using True assms insert_correct by auto + moreover hence "set_vebt t \ {x} = (set_vebt t \ {x})\{0..2^n-1} " + by (metis Diff_Diff_Int True assms calculation(1) inf_le1 inrange le_inf_iff order_refl subset_antisym set_vebt'_def set_vebt_def set_vebt_set_vebt'_valid valid_pres_insert) + ultimately show ?thesis by simp + next + case False + hence "set_vebt (insert' t x) = set_vebt t" + by (metis Node assms deg_deg_n insert'.simps(2) leI) + moreover hence "set_vebt t = (set_vebt t \ {x})\{0..2^n-1} " + by (smt (z3) False Int_commute Int_insert_right_if0 Un_Int_assoc_eq assms atLeastAtMost_iff boolean_algebra_cancel.sup0 inf_bot_right inrange le_add_diff_inverse le_imp_less_Suc one_le_numeral one_le_power plus_1_eq_Suc sup_commute set_vebt_set_vebt'_valid) + ultimately show ?thesis by simp + qed +next + case (Leaf x21 x22) + then show ?thesis + apply(auto simp add: insert'.simps vebt_insert.simps set_vebt_def both_member_options_def) + using assms + apply cases + apply simp+ + using assms + apply cases + apply simp+ + using assms + apply cases + apply simp+ + using assms + apply cases + apply simp+ + done +qed + +end +end + diff --git a/thys/Van_Emde_Boas_Trees/VEBT_Intf_Functional.thy b/thys/Van_Emde_Boas_Trees/VEBT_Intf_Functional.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/VEBT_Intf_Functional.thy @@ -0,0 +1,372 @@ +section \Functional Interface\ +theory VEBT_Intf_Functional +imports Main + VEBT_Definitions VEBT_Space + VEBT_Uniqueness + VEBT_Member + VEBT_Insert VEBT_InsertCorrectness + VEBT_MinMax + VEBT_Pred VEBT_Succ + VEBT_Bounds + VEBT_Delete VEBT_DeleteCorrectness VEBT_DeleteBounds + +begin + + subsection \Code Generation Setup\ + + subsubsection \Code Equations\ + text \Code generator seems to not support patterns and nat code target\ + + context begin + interpretation VEBT_internal . + + lemma vebt_member_code[code]: + "vebt_member (Leaf a b) x = (if x = 0 then a else if x=1 then b else False)" + "vebt_member (Node None t r e) x = False" + "vebt_member (Node (Some (mi, ma)) deg treeList summary) x = + (if deg = 0 \ deg = Suc 0 then False else ( + if x = mi then True else + if x = ma then True else + if x < mi then False else + if x > ma then False else + (let + h = high x (deg div 2); + l = low x (deg div 2) in + (if h < length treeList + then vebt_member (treeList ! h) l + else False))))" + apply simp + apply simp + proof(goal_cases) + case 1 + consider "deg = 0"| "deg = Suc 0" + | n where "deg = Suc (Suc n)" + by (meson vebt_buildup.cases) + then show ?case apply(cases) + by simp_all + qed + + lemma vebt_insert_code[code]: + "vebt_insert (Leaf a b) x = (if x=0 then Leaf True b else if x=1 then Leaf a True else Leaf a b)" + "vebt_insert (Node info deg treeList summary) x = ( + if deg \ 1 then + (Node info deg treeList summary) + else ( case info of + None \ (Node (Some (x,x)) deg treeList summary) + | Some mima \ ( case mima of (mi, ma) \ ( + let + xn = (if x < mi then mi else x); + minn = (if x< mi then x else mi); + l= low xn (deg div 2); h = high xn (deg div 2) + in ( + if h < length treeList \ \ (x = mi \ x = ma) then + Node (Some (minn, max xn ma)) + deg + (treeList[h:= vebt_insert (treeList ! h) l]) + (if minNull (treeList ! h) then vebt_insert summary h else summary) + else Node (Some (mi, ma)) deg treeList summary) + ))))" + apply simp + apply simp + proof(goal_cases) + case 1 + consider "deg = 0"| "deg = Suc 0" + | n where "deg = Suc (Suc n)" + by (meson vebt_buildup.cases) + then show ?case apply(cases) + apply simp+ + apply(cases info) + apply simp+ + apply(cases "the info") + apply simp + by meson + + qed + + lemma vebt_succ_code[code]: + "vebt_succ (Leaf a b) x = (if b\ x = 0 then Some 1 else None)" + "vebt_succ (Node info deg treeList summary) x = (if deg \ 1 then None else + (case info of None \ None | + (Some mima) \ (case mima of (mi, ma) \ ( + if x < mi then (Some mi) + else (let l = low x (deg div 2); h = high x (deg div 2) in( + if h < length treeList then + let maxlow = vebt_maxt (treeList ! h) in + (if maxlow \ None \ (Some l <\<^sub>o maxlow) then + Some (2^(deg div 2)) *\<^sub>o Some h +\<^sub>o vebt_succ (treeList ! h) l + else let sc = vebt_succ summary h in + if sc = None then None + else Some (2^(deg div 2)) *\<^sub>o sc +\<^sub>o vebt_mint (treeList ! the sc) ) + + else None))))))" + apply (cases "(Leaf a b,x)" rule: vebt_succ.cases; simp) + apply (cases "(Node info deg treeList summary,x)" rule: vebt_succ.cases; simp add: Let_def) + done + + lemma vebt_pred_code[code]: + "vebt_pred (Leaf a b) x = (if x = 0 then None else if x = 1 then + (if a then Some 0 else None) else + (if b then Some 1 else if a then Some 0 else None))" and + "vebt_pred (Node info deg treeList summary) x =(if deg \ 1 then None else ( + case info of None \ None | + (Some mima) \ (case mima of (mi, ma) \ ( + if x > ma then Some ma + else (let l = low x (deg div 2); h = high x (deg div 2) in + if h < length treeList then + let minlow = vebt_mint (treeList ! h) in + (if minlow \ None \ (Some l >\<^sub>o minlow) then + Some (2^(deg div 2)) *\<^sub>o Some h +\<^sub>o vebt_pred (treeList ! h) l + else let pr = vebt_pred summary h in + if pr = None then (if x > mi then Some mi else None) + else Some (2^(deg div 2)) *\<^sub>o pr +\<^sub>o vebt_maxt (treeList ! the pr) ) + else None)))))" + apply (cases "(Leaf a b,x)" rule: vebt_pred.cases; simp) + apply (cases "(Node info deg treeList summary,x)" rule: vebt_pred.cases; simp add: Let_def) + done + + + lemma vebt_delete_code[code]: + "vebt_delete (Leaf a b) x = (if x = 0 then Leaf False b else if x = 1 then Leaf a False else Leaf a b)" + "vebt_delete (Node info deg treeList summary) x = ( + case info of + None \ (Node info deg treeList summary) + | Some mima \ ( + if deg \ 1 then (Node info deg treeList summary) + else (case mima of (mi, ma) \ ( + if (x < mi \ x > ma) then (Node (Some (mi, ma)) deg treeList summary) + else if (x = mi \ x = ma) then (Node None deg treeList summary) + else let + xn = (if x = mi then the (vebt_mint summary) * 2^(deg div 2) + + the (vebt_mint (treeList ! the (vebt_mint summary))) + else x); + minn = (if x = mi then xn else mi); + l = low xn (deg div 2); + h = high xn (deg div 2) + in + if h < length treeList then let + newnode = vebt_delete (treeList ! h) l; + newlist = treeList[h:= newnode] + in + if minNull newnode then let + sn = vebt_delete summary h; + maxn = + if xn = ma then let + maxs = vebt_maxt sn + in + if maxs = None then minn + else 2^(deg div 2) * the maxs + the (vebt_maxt (newlist ! the maxs)) + else ma + in (Node (Some (minn, maxn)) deg newlist sn) + else let + maxn = (if xn = ma then h * 2^(deg div 2) + the( vebt_maxt (newlist ! h)) + else ma) + in (Node (Some (minn, maxn)) deg newlist summary) + else (Node (Some (mi, ma)) deg treeList summary) + ))))" + apply (cases "(Leaf a b,x)" rule: vebt_delete.cases; simp) + apply (cases "(Node info deg treeList summary,x)" rule: vebt_delete.cases; simp add: Let_def) + done +end + +lemmas [code] = + VEBT_internal.high_def VEBT_internal.low_def VEBT_internal.minNull.simps + VEBT_internal.less.simps VEBT_internal.mul_def VEBT_internal.add_def + VEBT_internal.option_comp_shift.simps VEBT_internal.option_shift.simps + +export_code + vebt_buildup + vebt_insert + vebt_member + vebt_maxt + vebt_mint + vebt_pred + vebt_succ + vebt_delete + checking SML + +subsection \Correctness Lemmas\ + +named_theorems vebt_simps \Simplifier rules for VEBT functional interface\ + +locale vebt_inst = + fixes n :: nat +begin + + interpretation VEBT_internal . + +subsubsection \Space Bound\ +theorem vebt_space_linear_bound: + fixes t + defines "u \ 2^n" + shows "invar_vebt t n \ space t \ 12*u" + by (simp add: space_bound u_def) + +subsubsection \Buildup\ +lemma invar_vebt_buildup[vebt_simps]: "invar_vebt (vebt_buildup n) n \ n>0" + by (auto simp add: buildup_gives_valid deg_not_0) + +lemma set_vebt_buildup[vebt_simps]: "set_vebt (vebt_buildup i) = {}" + by (metis VEBT_internal.buildup_gives_empty VEBT_internal.buildup_gives_valid VEBT_internal.set_vebt_set_vebt'_valid neq0_conv invar_vebt.intros(1) vebt_buildup.simps(1)) + +lemma time_vebt_buildup: "u = 2^n \ T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d\<^sub>u\<^sub>p n \ 26 * u" + using vebt_buildup_bound by simp + +subsubsection \Equality\ +lemma set_vebt_equal[vebt_simps]: "invar_vebt t\<^sub>1 n \ invar_vebt t\<^sub>2 n \ t\<^sub>1=t\<^sub>2 \ set_vebt t\<^sub>1 = set_vebt t\<^sub>2" + by (auto simp: unique_tree) + +subsubsection \Member\ +lemma set_vebt_member[vebt_simps]: "invar_vebt t n \ vebt_member t x \ x\set_vebt t" + by (rule member_correct) + +theorem time_vebt_member: "invar_vebt t n \ u = 2^n \ T\<^sub>m\<^sub>e\<^sub>m\<^sub>b\<^sub>e\<^sub>r t x \ 30 + 15 * lb (lb u)" + using member_bound_size_univ by auto + + +subsubsection \Insert\ +theorem invar_vebt_insert[vebt_simps]: "invar_vebt t n \ x< 2^n \ invar_vebt (vebt_insert t x) n" + by (simp add: valid_pres_insert) + +theorem set_vebt_insert[vebt_simps]: "invar_vebt t n \ x < 2^n \ set_vebt (vebt_insert t x) = set_vebt t \ {x}" + by (meson insert_correct[symmetric]) + +theorem time_vebt_insert: "invar_vebt t n \ u = 2^n \ T\<^sub>i\<^sub>n\<^sub>s\<^sub>e\<^sub>r\<^sub>t t x \ 46 + 23 * lb (lb u)" + by (meson insert_bound_size_univ) + + +subsubsection \Maximum\ +theorem set_vebt_maxt: "invar_vebt t n \ vebt_maxt t = Some x \ max_in_set (set_vebt t) x" + by (metis maxt_sound maxt_corr set_vebt_set_vebt'_valid) + +theorem set_vebt_maxt': "invar_vebt t n \ vebt_maxt t = Some x \ (x\set_vebt t \ (\y\set_vebt t. x\y))" + using set_vebt_maxt unfolding max_in_set_def by blast + +lemma set_vebt_maxt''[vebt_simps]: + "invar_vebt t n \ vebt_maxt t = (if set_vebt t = {} then None else Some (Max (set_vebt t)))" + by (metis Max_ge Max_in VEBT_internal.set_vebt_finite VEBT_internal.set_vebt_set_vebt'_valid empty_iff option.exhaust set_vebt_maxt') + +lemma time_vebt_maxt: "T\<^sub>m\<^sub>a\<^sub>x\<^sub>t t \ 3" + by (simp add: maxt_bound) + + +subsubsection \Minimum\ +theorem set_vebt_mint[vebt_simps]: "invar_vebt t n \ vebt_mint t = Some x \ min_in_set (set_vebt t) x" + by (metis VEBT_internal.mint_corr VEBT_internal.mint_sound VEBT_internal.set_vebt_set_vebt'_valid) + +theorem set_vebt_mint': "invar_vebt t n \ vebt_mint t = Some x \ (x\set_vebt t \ (\y\set_vebt t. x\y))" + using set_vebt_mint unfolding min_in_set_def by blast + +lemma set_vebt_mint''[vebt_simps]: + "invar_vebt t n \ vebt_mint t = (if set_vebt t = {} then None else Some (Min (set_vebt t)))" + by (metis Min_in Min_le VEBT_internal.set_vebt_finite VEBT_internal.set_vebt_set_vebt'_valid empty_iff option.exhaust set_vebt_mint') + +lemma time_vebt_mint: "T\<^sub>m\<^sub>i\<^sub>n\<^sub>t t \ 3" + by (simp add: mint_bound) + +subsection \Emptiness determination\ +text \ A tree is empty if and only if its minimum is None\ + +lemma vebt_minNull_mint: " minNull t \ vebt_mint t = None" + by (meson VEBT_internal.minNullmin VEBT_internal.minminNull) + +lemma set_vebt_minNull: "invar_vebt t n \ minNull t \ set_vebt t = {}" + by (metis VEBT_internal.minNullmin VEBT_internal.minminNull VEBT_internal.mint_corr_help_empty VEBT_internal.set_vebt_set_vebt'_valid vebt_inst.set_vebt_mint'') + +lemma time_vebt_minNull: "T\<^sub>m\<^sub>i\<^sub>n\<^sub>N\<^sub>u\<^sub>l\<^sub>l t \ 1" + using minNull_bound by auto + +subsubsection \Successor\ +theorem set_vebt_succ: "invar_vebt t n \ vebt_succ t x = Some sx \ is_succ_in_set (set_vebt t) x sx" + by (simp add: succ_corr set_vebt_set_vebt'_valid) + +lemma set_vebt_succ'[vebt_simps]: "invar_vebt t n \ vebt_succ t x = (if \ y \ set_vebt t. y > x then Some (LEAST y \ set_vebt t. y > x) else None)" + apply (clarsimp;safe) + subgoal + apply(clarsimp simp add: succ_correct is_succ_in_set_def Least_le) + by (metis (no_types, lifting) LeastI_ex) + subgoal by (meson succ_correct is_succ_in_set_def option.exhaust_sel) + done + +theorem time_vebt_succ: + fixes t defines "u \ 2^n" + shows "invar_vebt t n \ T\<^sub>s\<^sub>u\<^sub>c\<^sub>c t x \ 54 + 27 * lb (lb u)" + using succ_bound_size_univ unfolding u_def by presburger + + +subsubsection \Predecessor\ +theorem set_vebt_pred: "invar_vebt t n \ vebt_pred t x = Some px \ is_pred_in_set (set_vebt t) x px" + by (simp add: pred_corr set_vebt_set_vebt'_valid) + +theorem set_vebt_pred'[vebt_simps]: "invar_vebt t n \ + vebt_pred t x = (if \ y \ set_vebt t. y < x then Some (GREATEST y. y \ set_vebt t \ y < x) else None)" + apply (clarsimp simp: member_correct pred_empty pred_correct is_pred_in_set_def) + by (metis (no_types, lifting) GreatestI_nat Greatest_le_nat less_imp_le) + +theorem time_vebt_pred: fixes t defines "u \ 2^n" + shows "invar_vebt t n \ T\<^sub>p\<^sub>r\<^sub>e\<^sub>d t x \ 58 + 29 * lb (lb u)" + unfolding u_def by (meson pred_bound_size_univ) + + +subsubsection \Delete\ +theorem invar_vebt_delete[vebt_simps]: "invar_vebt t n \ invar_vebt (vebt_delete t x) n" + by (simp add: delete_pres_valid) + +theorem set_vebt_delete[vebt_simps]: "invar_vebt t n \ set_vebt (vebt_delete t x) = set_vebt t - {x}" + by (metis delete_correct invar_vebt_delete set_vebt_set_vebt'_valid) + +theorem time_vebt_delete: fixes t defines "u \ 2^n" + shows "invar_vebt t n \ T\<^sub>d\<^sub>e\<^sub>l\<^sub>e\<^sub>t\<^sub>e t x \ 140 + 70 * lb (lb u)" + unfolding u_def by (meson delete_bound_size_univ) + +end + +subsection \Interface Usage Example\ + +experiment +begin + + definition "test n xs ys \ let + t = vebt_buildup n; + t = foldl vebt_insert t (0#xs); + + f = (\x. if vebt_member t x then x else the (vebt_pred t x)) + in + map f ys" + + + context fixes n :: nat begin + interpretation vebt_inst n . + + lemmas [simp] = vebt_simps + + lemma [simp]: + assumes "invar_vebt t n" "\x\set xs. x<2^n" + shows "invar_vebt (foldl vebt_insert t xs) n" + using assms apply (induction xs arbitrary: t) + by auto + + lemma [simp]: + assumes "invar_vebt t n" "\x\set xs. x<2^n" + shows "set_vebt (foldl vebt_insert t xs) = set_vebt t \ set xs" + using assms + apply (induction xs arbitrary: t) + apply auto + done + + lemma "\\x\set xs. x<2^n; n>0\ \ test n xs ys = map (\y. (GREATEST y'. y'\insert 0 (set xs) \ y'\y)) ys" + unfolding test_def + apply (auto simp add: Let_def) + subgoal by (metis (mono_tags, lifting) Greatest_equality le_zero_eq) + subgoal by (metis (no_types, lifting) Greatest_equality order_refl) + subgoal by (metis less_le) + done + + end + +end + + + (* TODO: Use uniqueness to define = operation! *) + +end + diff --git a/thys/Van_Emde_Boas_Trees/VEBT_Intf_Imperative.thy b/thys/Van_Emde_Boas_Trees/VEBT_Intf_Imperative.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/VEBT_Intf_Imperative.thy @@ -0,0 +1,176 @@ +(*by Lammich*) +section \Imperative Interface\ +theory VEBT_Intf_Imperative + imports + VEBT_Definitions + VEBT_Uniqueness + VEBT_Member + VEBT_Insert VEBT_InsertCorrectness + VEBT_MinMax + VEBT_Pred VEBT_Succ + VEBT_Delete VEBT_DeleteCorrectness + VEBT_Bounds + VEBT_DeleteBounds + VEBT_Space + VEBT_Intf_Functional + VEBT_List_Assn + VEBT_BuildupMemImp + VEBT_SuccPredImperative + VEBT_DelImperative +begin + + subsection \Code Export\ + + context begin + interpretation VEBT_internal . + + lemmas [code] = replicatei.simps vebt_memberi.simps highi_def lowi_def vebt_inserti.simps + minNulli.simps vebt_succi.simps vebt_predi.simps vebt_deletei.simps + + greater.simps + + end + + + export_code + vebt_buildupi + vebt_memberi + vebt_inserti + vebt_maxti vebt_minti + vebt_predi vebt_succi + vebt_deletei + + checking SML_imp + + subsection \Interface\ + +definition vebt_assn::"nat \ nat set \ VEBTi \ assn" where +"vebt_assn n s ti \ \\<^sub>A t. vebt_assn_raw t ti * \(s = set_vebt t \ invar_vebt t n)" + + +subsubsection \Buildup\ + +context begin + interpretation VEBT_internal . + + interpretation vebt_inst for n . + + +lemma vebt_buildupi_rule_basic[sep_heap_rules]: "n > 0 \ vebt_buildupi n <\ r. vebt_assn n {} r >" + unfolding vebt_assn_def + apply(rule post_exI_rule[where x = "vebt_buildup n"]) + using builupicorr[of n] invar_vebt_buildup[of n] set_vebt_buildup[of n] + apply simp + done + +lemma vebt_buildupi_rule: "<\ (n > 0)> vebt_buildupi n <\ r. vebt_assn n {} r > T[10 * 2^n]" + unfolding vebt_assn_def htt_def + apply rule + apply(rule post_exI_rule[where x = "vebt_buildup n"]) + using vebt_buildupi_rule[of n] invar_vebt_buildup[of n] set_vebt_buildup[of n] + unfolding htt_def + apply simp + using TBOUND_buildupi[of n] unfolding TBOUND_def + apply simp + done + +subsubsection \Member\ +lemma vebt_memberi_rule: " vebt_memberi ti x <\ r. vebt_assn n s ti * \(r = (x \ s))>T[5 + 5 * (nat \lb n \)]" + unfolding vebt_assn_def + apply(rule norm_pre_ex_rule_htt) + apply(clarsimp simp: norm_pre_pure_iff_htt) + apply(rule htt_cons_rule[OF htt_vebt_memberi_invar_vebt]) + apply assumption + apply simp + apply (sep_auto simp: member_correct) + apply simp + done + + +subsubsection \Insert\ +lemma vebt_inserti_rule: "x < 2^n \ vebt_inserti ti x <\ r. vebt_assn n (s \ {x}) r >T[13 + 13 * (nat \lb n \)]" + apply(sep_auto simp: norm_pre_pure_iff_htt) + unfolding vebt_assn_def + apply(rule norm_pre_ex_rule_htt) + apply(clarsimp simp: norm_pre_pure_iff_htt) + apply(rule htt_cons_rule[OF htt_vebt_inserti_invar_vebt]) + apply assumption + apply simp + apply sep_auto + apply (auto simp add: insert_correct) + apply (simp add: valid_insert_both_member_options_add set_vebt_def) + apply (metis UnCI insert_correct) + apply (metis UnE insert_correct singletonD) + using valid_pres_insert by presburger + + +subsubsection \Maximum\ +lemma vebt_maxti_rule: " vebt_maxti ti <\ r. vebt_assn n s ti * \( r = Some y \ max_in_set s y)>T[1]" + unfolding vebt_assn_def + apply(rule norm_pre_ex_rule_htt) + apply(clarsimp simp: norm_pre_pure_iff_htt) + apply(rule htt_cons_rule[OF vebt_maxti_hT]) + apply(rule ent_refl) + apply (sep_auto simp: set_vebt_maxt) + by simp + +subsubsection \Minimum\ +lemma vebt_minti_rule: " vebt_minti ti <\ r. vebt_assn n s ti * \( r = Some y \ min_in_set s y)>T[1]" + unfolding vebt_assn_def + apply(rule norm_pre_ex_rule_htt) + apply(clarsimp simp: norm_pre_pure_iff_htt) + apply(rule htt_cons_rule[OF vebt_minti_hT]) + apply(rule ent_refl) + apply (sep_auto simp: set_vebt_mint) + by auto + + +subsubsection \Successor\ +lemma vebt_succi_rule: " vebt_succi ti x <\ r. vebt_assn n s ti * \( r = Some y \ is_succ_in_set s x y)>T[7 + 7 * (nat \lb n \)]" + unfolding vebt_assn_def + apply(rule norm_pre_ex_rule_htt) + apply(clarsimp simp: norm_pre_pure_iff_htt) + apply(rule htt_cons_rule[OF htt_vebt_succi]) + apply assumption + apply simp + apply (sep_auto simp: set_vebt_succ) + apply simp + done + +subsubsection \Predecessor\ +lemma vebt_predi_rule: " vebt_predi ti x <\ r. vebt_assn n s ti * \( r = Some y \ is_pred_in_set s x y)>T[7 + 7 * (nat \lb n \)]" + unfolding vebt_assn_def + apply(rule norm_pre_ex_rule_htt) + apply(clarsimp simp: norm_pre_pure_iff_htt) + apply(rule htt_cons_rule[OF htt_vebt_predi]) + apply assumption + apply simp + apply (sep_auto simp: set_vebt_pred) + apply simp + done + +subsubsection \Delete\ +lemma vebt_deletei_rule: " vebt_deletei ti x <\ r. vebt_assn n (s - {x}) r >T[20 + 20 * (nat \lb n \)]" + unfolding vebt_assn_def + apply(rule norm_pre_ex_rule_htt) + apply(clarsimp simp: norm_pre_pure_iff_htt) + apply(rule htt_cons_rule[OF htt_vebt_deletei]) + apply assumption + apply simp + apply sep_auto + apply (auto simp add: set_vebt_delete invar_vebt_delete) + done + +subsection \Setup of VCG\ +lemmas vebt_heap_rules[THEN htt_htD,sep_heap_rules] = + vebt_buildupi_rule + vebt_memberi_rule + vebt_inserti_rule + vebt_maxti_rule + vebt_minti_rule + vebt_succi_rule + vebt_predi_rule + vebt_deletei_rule + +end +end diff --git a/thys/Van_Emde_Boas_Trees/VEBT_List_Assn.thy b/thys/Van_Emde_Boas_Trees/VEBT_List_Assn.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/VEBT_List_Assn.thy @@ -0,0 +1,333 @@ +(*by Lammich and Ammer*) +theory VEBT_List_Assn +imports + "Separation_Logic_Imperative_HOL/Sep_Main" + "HOL-Library.Rewrite" + +begin + +subsection "Lists" + +fun list_assn :: "('a \ 'c \ assn) \ 'a list \ 'c list \ assn" where + "list_assn P [] [] = emp" +| "list_assn P (a#as) (c#cs) = P a c * list_assn P as cs" +| "list_assn _ _ _ = false" + +lemma list_assn_aux_simps[simp]: + "list_assn P [] l' = (\(l'=[]))" + "list_assn P l [] = (\(l=[]))" + apply (cases l') + apply simp + apply simp + apply (cases l) + apply simp + apply simp + done + +lemma list_assn_aux_append[simp]: + "length l1=length l1' \ + list_assn P (l1@l2) (l1'@l2') + = list_assn P l1 l1' * list_assn P l2 l2'" + apply (induct rule: list_induct2) + apply simp + apply (simp add: star_assoc) + done + +lemma list_assn_aux_ineq_len: "length l \ length li \ list_assn A l li = false" +proof (induction l arbitrary: li) + case (Cons x l li) thus ?case by (cases li; auto) +qed simp + +lemma list_assn_aux_append2[simp]: + assumes "length l2=length l2'" + shows "list_assn P (l1@l2) (l1'@l2') + = list_assn P l1 l1' * list_assn P l2 l2'" + apply (cases "length l1 = length l1'") + apply (erule list_assn_aux_append) + apply (simp add: list_assn_aux_ineq_len assms) + done + +lemma list_assn_simps[simp]: + "(list_assn P) [] [] = emp" + "(list_assn P) (a#as) (c#cs) = P a c * (list_assn P) as cs" + "(list_assn P) (a#as) [] = false" + "(list_assn P) [] (c#cs) = false" + apply simp_all + done + + +lemma list_assn_mono: + "\\x x'. P x x'\\<^sub>AP' x x'\ \ list_assn P l l' \\<^sub>A list_assn P' l l'" + apply (induct P l l' rule: list_assn.induct) + by (auto intro: ent_star_mono) + +lemma list_assn_cong[fundef_cong]: + assumes "xs=xs'" "xsi=xsi'" + assumes "\x xi. x\set xs' \ xi\set xsi' \ A x xi = A' x xi" + shows "list_assn A xs xsi = list_assn A' xs' xsi'" + using assms + apply (induct A\A xs' xsi' arbitrary: xs xsi rule: list_assn.induct) + apply simp_all + done + +term prod_list + + +definition "listI_assn I A xs xsi \ + \(length xsi=length xs \ I\{0..i a. a * A (xs!i) (xsi!i)) 1 I" + + +lemmas comp_fun_commute_fold_insert = + comp_fun_commute_on.fold_insert[where S=UNIV, folded comp_fun_commute_def', simplified] + + +lemma aux: "Finite_Set.fold (\i aa. aa * P ((a # as) ! i) ((c # cs) ! i)) emp {0..i aa. aa * P (as ! i) (cs ! i)) emp {0..i x. P (Suc i) x = Q i x" + and "comp_fun_commute P" + and "comp_fun_commute Q" + for P Q n + using that + apply (induction n arbitrary: a) + subgoal by simp + thm comp_fun_commute_on.fold_insert + apply (simp add: comp_fun_commute_fold_insert) + apply (subst 2) + apply (subst 3) + apply (simp add: comp_fun_commute_fold_insert) + done + show ?thesis + apply (simp add: 1) + apply (subst comp_fun_commute_fold_insert) + subgoal + apply unfold_locales + apply (auto simp: fun_eq_iff algebra_simps) + done + subgoal by simp + subgoal by simp + apply simp + apply (rewrite at "\ = _*_" mult.commute) + apply (rule arg_cong[where f="\x. P _ _ * x"]) + apply (rule A) + subgoal by auto + subgoal + apply unfold_locales + apply (auto simp: fun_eq_iff algebra_simps) + done + subgoal + apply unfold_locales + apply (auto simp: fun_eq_iff algebra_simps) + done + done +qed + + +lemma list_assn_conv_idx: "list_assn A xs xsi = listI_assn {0.. listI_assn {0.. listI_assn {0..finite I \ listI_assn I A xs xsi = false" + using subset_eq_atLeast0_lessThan_finite by (auto simp: listI_assn_def) + + +find_theorems Finite_Set.fold name: cong + +lemma mult_fun_commute: "comp_fun_commute (\i (a::assn). a * f i)" + apply unfold_locales + apply (auto simp: fun_eq_iff mult_ac) + done + +lemma listI_assn_weak_cong: + assumes I: "I=I'" "A=A'" "length xs=length xs'" "length xsi=length xsi'" + assumes A: "\i. \i\I; i + \ xs!i = xs'!i \ xsi!i = xsi'!i" + shows "listI_assn I A xs xsi = listI_assn I' A' xs' xsi'" + unfolding listI_assn_def + apply (simp add: I) + apply (cases "length xsi' = length xs' \ I' \ {0..i. \i\I; i + \ xs!i = xs'!i \ xsi!i = xsi'!i + \ A (xs!i) (xsi!i) = A' (xs'!i) (xsi'!i)" + shows "listI_assn I A xs xsi = listI_assn I' A' xs' xsi'" + unfolding listI_assn_def + apply (simp add: I) + apply (cases "length xsi' = length xs' \ I' \ {0..I \ i + listI_assn (insert i I) A xs xsi = A (xs!i) (xsi!i) * listI_assn I A xs xsi" + apply (cases "finite I"; simp?) + unfolding listI_assn_def + apply (subst comp_fun_commute_fold_insert) + subgoal + apply unfold_locales + apply (auto simp: fun_eq_iff algebra_simps) + done + subgoal by simp + subgoal by simp + subgoal by (auto simp: algebra_simps) + done + +lemma listI_assn_extract: + assumes "i\I" "i\<^sub>A A (xs!i) (xsi!i) * listI_assn (I-{i}) A xs xsi * F" + assumes "iI" + assumes "listI_assn I A xs xsi * F \\<^sub>A Q" + shows "P \\<^sub>A Q" +proof - + show ?thesis + apply (rule ent_trans[OF assms(1)]) + apply (subst listI_assn_extract[symmetric]) + subgoal by fact + subgoal by fact + subgoal by fact + done +qed + +lemma listI_assn_reinsert_upd: + fixes xs xsi :: "_ list" + assumes "P \\<^sub>A A x xi * listI_assn (I-{i}) A xs xsi * F" + assumes "iI" + assumes "listI_assn I A (xs[i:=x]) (xsi[i:=xi]) * F \\<^sub>A Q" + shows "P \\<^sub>A Q" +proof (cases "length xs = length xsi") + case True + have 1: "listI_assn (I-{i}) A xs xsi = listI_assn (I-{i}) A (xs[i:=x]) (xsi[i:=xi])" + by (rule listI_assn_cong) auto + + have 2: "A x xi = A ((xs[i:=x])!i) ((xsi[i:=xi])!i)" using \i True by auto + + from assms[unfolded 1 2] show ?thesis + apply (rule_tac listI_assn_reinsert) + apply assumption + apply simp_all + done + +next + case False + with assms(1) have "P \\<^sub>A false" + by (simp add: listI_assn_def) + thus ?thesis using ent_false_iff entailsI by blast +qed + + +lemma listI_assn_reinsert': + assumes "P \\<^sub>A A (xs!i) (xsi!i) * listI_assn (I-{i}) A xs xsi * F" + assumes "iI" + assumes "c" + shows "

c" +proof - + show ?thesis + apply (rule cons_pre_rule[OF assms(1)]) + apply (subst listI_assn_extract[symmetric]) + subgoal by fact + subgoal by fact + subgoal by fact + done +qed + +lemma listI_assn_reinsert_upd': + fixes xs xsi :: "_ list" + assumes "P \\<^sub>A A x xi * listI_assn (I-{i}) A xs xsi * F" + assumes "iI" + assumes " c " + shows "

c " + by (meson assms(1) assms(2) assms(3) assms(4) cons_pre_rule ent_refl listI_assn_reinsert_upd) + +lemma subst_not_in: + assumes "i\I " " iI "" i list_assn A xs xsi \ length xsi = length xs" + by (metis list_assn_aux_ineq_len mod_false) + +method unwrap_idx for i ::nat = + (rewrite in "<\>_<_>" list_assn_conv_idx), + (rewrite in "<\>_<_>" listI_assn_extract[where i="i"]), + (simp split: if_splits; fail), + (simp split: if_splits; fail) + +method wrap_idx uses R = + (rule R), + frame_inference, + (simp split: if_splits; fail), + (simp split: if_splits; fail), + (subst listI_assn_conv, (simp; fail)) + +method extract_pre_pure uses dest = + (rule hoare_triple_preI | drule asm_rl[of "_\_"]), + (determ \elim mod_starE dest[elim_format]\)?, + ((determ \thin_tac "_ \ _"\)+)?, + (simp (no_asm) only: triv_forall_equality)? + +lemma rule_at_index: + assumes + 1:"P \\<^sub>A list_assn A xs xsi * F" and + 2[simp]:"i < length xs" and + 3:" c " and + 4: "\ r. Q' r \\<^sub>A A (xs ! i) (xsi ! i) * + listI_assn ({0..c <\ r. list_assn A xs xsi * F' r> " + apply(rule cons_pre_rule[OF 1]) + apply(unwrap_idx i) + apply(rule cons_post_rule) + apply(rule 3) + apply(rule ent_trans[OF 4]) + apply(wrap_idx R: listI_assn_reinsert_upd) + apply simp + done + + +end diff --git a/thys/Van_Emde_Boas_Trees/VEBT_Member.thy b/thys/Van_Emde_Boas_Trees/VEBT_Member.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/VEBT_Member.thy @@ -0,0 +1,525 @@ +(*by Ammer*) +theory VEBT_Member imports VEBT_Definitions +begin + + +section \Member Function\ + +context begin +interpretation VEBT_internal . + +fun vebt_member :: "VEBT \ nat \ bool" where + "vebt_member (Leaf a b) x = (if x = 0 then a else if x = 1 then b else False)"| + "vebt_member (Node None _ _ _) x = False"| + "vebt_member (Node _ 0 _ _) x = False"| + "vebt_member (Node _ (Suc 0) _ _) x = False"| + "vebt_member (Node (Some (mi, ma)) deg treeList summary) x = ( + if x = mi then True else + if x = ma then True else + if x < mi then False else + if x > ma then False else ( + let h = high x (deg div 2); + l = low x (deg div 2) in( + if h < length treeList + then vebt_member (treeList ! h) l + else False))) " + +end + +context VEBT_internal begin + +lemma member_inv: + assumes "vebt_member (Node (Some (mi, ma)) deg treeList summary) x " + shows "deg \ 2 \ + (x = mi \ x = ma \ (x < ma \ x > mi \ high x (deg div 2) < length treeList \ + vebt_member (treeList ! ( high x (deg div 2))) (low x (deg div 2))))" +proof(cases deg) + case 0 + then show ?thesis using vebt_member.simps(3)[of "(mi, ma)" treeList summary x] + using assms by blast + next + case (Suc nat) + hence "deg = Suc nat" by simp + then show ?thesis proof(cases nat) + case 0 + then show ?thesis + using Suc assms by auto + next + case (Suc nata) + hence "deg \ 2" + by (simp add: \deg = Suc nat\) + then show ?thesis + by (metis vebt_member.simps(5) Suc \deg = Suc nat\ assms linorder_neqE_nat) + qed +qed + + +definition bit_concat::"nat \ nat \ nat \ nat" where +"bit_concat h l d = h*2^d + l" + +lemma bit_split_inv: "bit_concat (high x d) (low x d) d = x" + unfolding bit_concat_def high_def low_def + by presburger + +definition set_vebt'::"VEBT \ nat set" where + "set_vebt' t = {x. vebt_member t x}" + +lemma Leaf_0_not: assumes "invar_vebt (Leaf a b) 0 "shows " False" +proof- + from assms show ?thesis + proof(cases) + qed +qed + +lemma valid_0_not: "invar_vebt t 0 \ False" +proof(induction t) + case (Node info deg treeList summary) + from this(3) have "length treeList > 0" + apply cases + apply auto + done + then obtain t where "t \ set treeList" by fastforce + from Node(3) obtain n where "invar_vebt t n" + apply cases + using Node.IH(2) apply auto + done + from Node(3) have "n \ 0" + apply cases + using Node.IH(2) apply auto + done + hence "n = 0" by blast + then show ?case + using Node.IH(1) \t \ set treeList\ \invar_vebt t n\ by blast +next + case (Leaf x1 x2) + then show ?case + using Leaf_0_not by blast +qed + +theorem valid_tree_deg_neq_0: "(\ invar_vebt t 0)" + using valid_0_not by blast + +lemma deg_1_Leafy: "invar_vebt t n \ n = 1 \ \ a b. t = Leaf a b" + apply(induction rule: invar_vebt.induct) + apply simp + apply presburger + apply (metis (full_types) Suc_eq_plus1 add_cancel_right_left in_set_replicate list.map_cong0 map_replicate_const nat_neq_iff not_add_less2 numeral_1_eq_Suc_0 numeral_2_eq_2 numerals(1) order_less_irrefl power_eq_0_iff valid_tree_deg_neq_0 zero_less_numeral) + apply (metis odd_add odd_one) + by (metis Suc_eq_plus1 add_cancel_right_left in_set_replicate list.map_cong0 map_replicate_const nat_neq_iff not_add_less2 numeral_2_eq_2 power_eq_0_iff valid_tree_deg_neq_0) + +lemma deg_1_Leaf: "invar_vebt t 1 \ \ a b. t = Leaf a b" + using deg_1_Leafy by blast + +corollary deg1Leaf: "invar_vebt t 1 \ (\ a b. t = Leaf a b)" + using deg_1_Leaf invar_vebt.intros(1) by auto + +lemma deg_SUcn_Node: assumes "invar_vebt tree (Suc (Suc n)) " shows + " \ info treeList s. tree = Node info (Suc (Suc n)) treeList s" +proof- + from assms show ?thesis apply(cases) + apply blast+ + done +qed + +lemma "invar_vebt (Node info deg treeList summary) deg \ deg > 1" + by (metis VEBT.simps(4) deg_1_Leafy less_one linorder_neqE_nat valid_tree_deg_neq_0) + +lemma deg_deg_n: assumes "invar_vebt (Node info deg treeList summary) n "shows" deg = n" +proof- + from assms show ?thesis proof(cases) + qed blast+ +qed + +lemma member_valid_both_member_options: + "invar_vebt tree n \ vebt_member tree x \ (naive_member tree x \ membermima tree x)" +proof(induction tree n arbitrary: x rule: invar_vebt.induct) + case (1 a b) + then show ?case + using vebt_member.simps(1) naive_member.simps(1) by blast +next + case (2 treeList n summary m deg) + then show ?case by simp +next + case (3 treeList n summary m deg) + then show ?case + using vebt_member.simps(2) by blast +next + case (4 treeList n summary m deg mi ma) + hence "deg \ 2" + by (metis Euclidean_Division.div_eq_0_iff add_self_div_2 le_less_linear valid_tree_deg_neq_0) + then show ?case proof(cases "x = mi \ x = ma") + case True + then show ?thesis + by (metis (full_types) "4"(12) vebt_member.simps(3) membermima.simps(4) old.nat.exhaust) + next + case False + hence 1:"mi < x \ x < ma \ (high x (deg div 2 )) < length treeList \ vebt_member (treeList ! (high x (deg div 2))) (low x (deg div 2))" + using member_inv[of mi ma deg treeList summary x] "4"(12) by blast + hence " (treeList ! (high x (deg div 2))) \ set treeList" + by (metis in_set_member inthall) + hence "both_member_options (treeList ! (high x (deg div 2))) (low x (deg div 2))" + using "1" "4.IH"(1) both_member_options_def by blast + then show ?thesis + by (smt "1" "4"(1) "4"(6) \treeList ! high x (deg div 2) \ set treeList\ membermima.simps(4) naive_member.simps(3) old.nat.exhaust valid_tree_deg_neq_0 zero_eq_add_iff_both_eq_0) + qed +next + case (5 treeList n summary m deg mi ma) + hence "deg \ 2" + using member_inv by presburger + then show ?case proof(cases "x = mi \ x = ma") + case True + then show ?thesis + by (metis (full_types) "5"(12) vebt_member.simps(3) membermima.simps(4) old.nat.exhaust) + next + case False + hence 1:"mi < x \ x < ma \ (high x (deg div 2 )) < length treeList \ vebt_member (treeList ! (high x (deg div 2))) (low x (deg div 2))" + using member_inv[of mi ma deg treeList summary x] "5"(12) by blast + hence " (treeList ! (high x (deg div 2))) \ set treeList" + by (metis in_set_member inthall) + hence "both_member_options (treeList ! (high x (deg div 2))) (low x (deg div 2))" + using "1" "5.IH"(1) both_member_options_def by blast + then show ?thesis + by (smt "1" "5"(1) "5"(6) \treeList ! high x (deg div 2) \ set treeList\ membermima.simps(4) naive_member.simps(3) old.nat.exhaust valid_tree_deg_neq_0 zero_eq_add_iff_both_eq_0) + qed +qed + +lemma member_bound: "vebt_member tree x \ invar_vebt tree n \ x < 2^n" +proof(induction tree x arbitrary: n rule: vebt_member.induct) + case (1 a b x) + then show ?case by (metis vebt_member.simps(1) One_nat_def le_neq_implies_less nat_power_eq_Suc_0_iff + numeral_eq_iff numerals(1) one_le_numeral one_le_power semiring_norm(85) valid_tree_deg_neq_0 + zero_less_numeral zero_less_power) +next + case (2 uu uv uw x) + then show ?case by simp +next + case (3 v uy uz x) + then show ?case by simp +next + case (4 v vb vc x) + then show ?case by simp +next + case (5 mi ma va treeList summary x) + hence 111: "n = Suc (Suc va)" + using deg_deg_n by fastforce + hence "ma < 2^n" + using "5.prems"(2) mi_ma_2_deg by blast + then show ?case + by (metis "5.prems"(1) "5.prems"(2) le_less_trans less_imp_le_nat member_inv mi_ma_2_deg) +qed + +theorem inrange: assumes "invar_vebt t n" shows " set_vebt' t \ {0..2^n-1}" +proof + fix x + assume "x \ set_vebt' t" + hence "vebt_member t x" + using set_vebt'_def by auto + hence "x < 2^n" + using assms member_bound by blast + then show "x \ {0..2^n-1}" by simp + qed + +theorem buildup_gives_empty: "set_vebt' (vebt_buildup n) = {}" + unfolding set_vebt'_def + by (metis Collect_empty_eq vebt_member.simps(1) vebt_member.simps(2) vebt_buildup.elims) + +fun minNull::"VEBT \ bool" where +"minNull (Leaf False False) = True"| +"minNull (Leaf _ _ ) = False"| +"minNull (Node None _ _ _) = True"| +"minNull (Node (Some _) _ _ _) = False" + +lemma min_Null_member: "minNull t \ \ vebt_member t x" + apply(induction t) + using vebt_member.simps(2) minNull.elims(2) apply blast + apply auto + done + +lemma not_min_Null_member: "\ minNull t \ \ y. both_member_options t y" +proof(induction t) + case (Node info deg treeList summary) + obtain mi ma where "info = Some(mi , ma)" + by (metis Node.prems minNull.simps(4) not_None_eq surj_pair) + then show ?case + by (metis (full_types) both_member_options_def membermima.simps(3) membermima.simps(4) not0_implies_Suc) +next + case (Leaf x1 x2) + then show ?case + by (metis (full_types) both_member_options_def minNull.simps(1) naive_member.simps(1) zero_neq_one) +qed + +lemma valid_member_both_member_options: "invar_vebt t n \ both_member_options t x \ vebt_member t x" +proof(induction t n arbitrary: x rule: invar_vebt.induct) + case (1 a b) + then show ?case + by (simp add: both_member_options_def) +next + case (2 treeList n summary m deg) + hence 0: " ( \ t \ set treeList. invar_vebt t n) " and 1:" invar_vebt summary n" and 2:" length treeList = 2^n" and + 3:" deg = 2*n" and 4:" (\ i. both_member_options summary i)" and 5:" (\ t \ set treeList. \ y. both_member_options t y) " and 6: "n> 0" + apply blast+ + apply (auto simp add: "2.hyps"(3) "2.hyps") + using "2.hyps"(1) "2.hyps"(3) neq0_conv valid_tree_deg_neq_0 by blast + have "both_member_options (Node None deg treeList summary) x \ False" + proof- + assume "both_member_options (Node None deg treeList summary) x" + hence "naive_member (Node None deg treeList summary) x \ membermima (Node None deg treeList summary) x" unfolding both_member_options_def by simp + then show False + proof(cases "naive_member (Node None deg treeList summary) x") + case True + hence "high x n < length treeList \ naive_member (treeList ! (high x n)) (low x n)" + by (metis "1" "2.hyps"(3) "2.hyps"(4) add_cancel_right_left add_self_div_2 naive_member.simps(3) old.nat.exhaust valid_tree_deg_neq_0) + then show ?thesis + by (metis "5" both_member_options_def in_set_member inthall) + next + case False + hence "membermima (Node None deg treeList summary) x" + using \naive_member (Node None deg treeList summary) x \ membermima (Node None deg treeList summary) x\ by blast + moreover have "Suc (deg-1) =deg" + by (simp add: "2.hyps"(4) "6") + moreover hence "(let pos = high x (deg div 2) in if pos < length treeList then membermima (treeList ! pos) (low x (Suc (deg - 1) div 2)) else False)" + using calculation(1) membermima.simps(5) by metis + moreover hence " if high x (deg div 2) < length treeList then membermima (treeList ! ( high x (deg div 2))) (low x(deg div 2)) else False" + using calculation(2) by metis + ultimately + have " high x (deg div 2) < length treeList \ membermima (treeList ! (high x n)) (low x n)" + by (metis "2.hyps"(3) "2.hyps"(4) add_self_div_2) + then show ?thesis using "2.IH" "5" both_member_options_def in_set_member inthall + by (metis "2.hyps"(3) "2.hyps"(4) add_self_div_2) + qed + qed + then show ?case + by (simp add: "2.prems") +next + case (3 treeList n summary m deg) + hence 0: " ( \ t \ set treeList. invar_vebt t n) " and 1:" invar_vebt summary m" and 2:" length treeList = 2^m" and + 3:" deg = n+m" and 4:" (\ i. both_member_options summary i)" and 5:" (\ t \ set treeList. \ y. both_member_options t y) " and 6: "n> 0" and 7: "m> 0" + and 8: "n+1 = m" + apply blast+ + apply (metis (full_types) "3.IH"(1) "3.hyps"(2) in_set_member inthall neq0_conv power_eq_0_iff valid_tree_deg_neq_0 zero_neq_numeral) + apply (simp add: "3.hyps"(3)) + by (simp add: "3.hyps"(3)) + have "both_member_options (Node None deg treeList summary) x \ False" + proof- + assume "both_member_options (Node None deg treeList summary) x" + hence "naive_member (Node None deg treeList summary) x \ membermima (Node None deg treeList summary) x" unfolding both_member_options_def by simp + then show False + proof(cases "naive_member (Node None deg treeList summary) x") + case True + hence "high x n < length treeList \ naive_member (treeList ! (high x n)) (low x n)" + by (metis "3" "3.hyps"(3) add_Suc_right add_self_div_2 even_Suc_div_two naive_member.simps(3) odd_add) + then show ?thesis + by (metis "5" both_member_options_def in_set_member inthall) + next + case False + hence "membermima (Node None deg treeList summary) x" + using \naive_member (Node None deg treeList summary) x \ membermima (Node None deg treeList summary) x\ by blast + moreover have "Suc (deg-1) =deg" + by (simp add: "3" "3.hyps"(3)) + moreover hence "(let pos = high x (deg div 2) in if pos < length treeList then membermima (treeList ! pos) (low x (Suc (deg - 1) div 2)) else False)" + using calculation(1) membermima.simps(5) by metis + moreover hence 11:" if high x (deg div 2) < length treeList then membermima (treeList ! ( high x (deg div 2))) (low x(deg div 2)) else False" + using calculation(2) by metis + ultimately + have " high x (deg div 2) < length treeList \ membermima (treeList ! (high x n)) (low x n)" + by (metis "3" "3.hyps"(3) add_Suc_right add_self_div_2 even_Suc_div_two odd_add) + then show ?thesis using "3.IH" "5" both_member_options_def in_set_member inthall 11 by metis + qed + qed + then show ?case + using "3.prems" by blast +next + case (4 treeList n summary m deg mi ma) + hence 0: "( \ t \ set treeList. invar_vebt t n)" and 1: " invar_vebt summary n" and 2:"length treeList = 2^n" and 3:" deg = n+m" and "n=m" and + 4: "(\ i < 2^n. (\ y. both_member_options (treeList ! i) y) \ ( both_member_options summary i))" and + 5: "(mi = ma \ (\ t \ set treeList. \ y. both_member_options t y))" and 6:"mi \ ma \ ma < 2^deg" and + 7: "(mi \ ma \ (\ i < 2^m. (high ma n = i \ both_member_options (treeList ! i) (low ma n)) \ + (\ y. (high y n = i \ both_member_options (treeList ! i) (low y n) ) \ mi < y \ y \ ma)))" + using "4.prems" by auto + hence "n>0" + by (metis neq0_conv valid_tree_deg_neq_0) + then show ?case proof(cases "x = mi \ x = ma") + case True + hence xmimastmt: "x = mi \ x=ma" by simp + then show ?thesis using vebt_member.simps(5)[of mi ma "deg-2" treeList summary x] + by (metis "3" "4.hyps"(3) \0 < n\ add_diff_inverse_nat add_numeral_left add_self_div_2 div_if nat_neq_iff numerals(1) plus_1_eq_Suc semiring_norm(2)) + next + case False + hence xmimastmt: "x \ mi \ x\ma" by simp + hence "mi = ma \ False" + proof- + assume "mi = ma" + hence astmt: "(\ t \ set treeList. \ y. both_member_options t y)" using 5 by simp + have bstmt: "both_member_options (Node (Some (mi, ma)) deg treeList summary) x" + by (simp add: "4.prems") + then show False + proof(cases "naive_member (Node (Some (mi, ma)) deg treeList summary) x") + case True + hence "high x n < length treeList \ naive_member (treeList ! (high x n)) (low x n)" + by (metis (no_types, opaque_lifting) "3" "4.hyps"(1) "4.hyps"(3) add_self_div_2 naive_member.simps(3) old.nat.exhaust valid_0_not zero_eq_add_iff_both_eq_0) + then show ?thesis + by (metis "5" \mi = ma\ both_member_options_def in_set_member inthall) + next + case False + hence "membermima (Node (Some (mi, ma)) deg treeList summary) x" using bstmt unfolding both_member_options_def by blast + hence " x = mi \ x = ma \ (if high x n < length treeList then membermima (treeList ! (high x n)) (low x n) else False)" + using membermima.simps(4)[of mi ma "deg-1" treeList summary x] + by (metis "3" "4.hyps"(3) One_nat_def Suc_diff_Suc \0 < n\ add_gr_0 add_self_div_2 diff_zero) + hence " high x n < length treeList \ membermima (treeList ! (high x n)) (low x n)" using xmimastmt + by presburger + then show ?thesis using both_member_options_def in_set_member inthall membermima.simps(4)[of mi ma n treeList summary x] astmt + by metis + qed + qed + hence "mi \ ma " by blast + hence followstmt: "(\ i < 2^m. (high ma n = i \ both_member_options (treeList ! i) (low ma n)) \ + (\ y. (high y n = i \ both_member_options (treeList ! i) (low y n) ) \ mi < y \ y \ ma))" + using 7 by simp + have 10:"high x n < length treeList \ + (naive_member (treeList ! (high x n)) (low x n) \ membermima (treeList ! (high x n)) (low x n) )" + by (smt "3" "4.hyps"(3) "4.prems" False One_nat_def Suc_leI \0 < n\ add_gr_0 add_self_div_2 both_member_options_def le_add_diff_inverse membermima.simps(4) naive_member.simps(3) plus_1_eq_Suc) + hence 11:"both_member_options (treeList ! (high x n)) (low x n)" + by (simp add: both_member_options_def) + have 12:"high x n< 2^m" + using "10" "4.hyps"(2) by auto + hence "mi < x \ x < ma" proof- + have "(\ y. (high y n = (high x n) \ both_member_options (treeList ! (high y n)) (low y n) ) \ mi < y \ y \ ma)" + using "12" followstmt by auto + then show ?thesis + using "11" False order.not_eq_order_implies_strict by blast + qed + have "vebt_member (treeList ! (high x n)) (low x n)" + by (metis"10" "11" "4.IH"(1) in_set_member inthall) + then show ?thesis + by (smt "10" "11" "12" "3" "4.hyps"(3) vebt_member.simps(5) One_nat_def Suc_leI \0 < n\ add_Suc_right add_self_div_2 followstmt le_add_diff_inverse le_imp_less_Suc not_less_eq not_less_iff_gr_or_eq plus_1_eq_Suc) + qed +next + case (5 treeList n summary m deg mi ma) + hence 0: "( \ t \ set treeList. invar_vebt t n)" and 1: " invar_vebt summary m" and 2:"length treeList = 2^m" and 3:" deg = n+m" and "Suc n=m" and + 4: "(\ i < 2^m. (\ y. both_member_options (treeList ! i) y) \ ( both_member_options summary i))" and + 5: "(mi = ma \ (\ t \ set treeList. \ y. both_member_options t y))" and 6:"mi \ ma \ ma < 2^deg" and + 7: "(mi \ ma \ (\ i < 2^m. (high ma n = i \ both_member_options (treeList ! i) (low ma n)) \ + (\ y. (high y n = i \ both_member_options (treeList ! i) (low y n) ) \ mi < y \ y \ ma)))" + using "5.prems" by auto + hence "n>0" + by (metis "5.hyps"(3) in_set_member inthall neq0_conv power_Suc0_right valid_tree_deg_neq_0 zero_neq_numeral) + then show ?case proof(cases "x = mi \ x = ma") + case True + hence xmimastmt: "x = mi \ x=ma" by simp + then show ?thesis using vebt_member.simps(5)[of mi ma "deg-2" treeList summary x] + using "3" "5.hyps"(3) \0 < n\ by auto + next + case False + hence xmimastmt: "x \ mi \ x\ma" by simp + hence "mi = ma \ False" + proof- + assume "mi = ma" + hence astmt: "(\ t \ set treeList. \ y. both_member_options t y)" using 5 by simp + have bstmt: "both_member_options (Node (Some (mi, ma)) deg treeList summary) x" + by (simp add: "5.prems") + then show False + proof(cases "naive_member (Node (Some (mi, ma)) deg treeList summary) x") + case True + hence "high x n < length treeList \ naive_member (treeList ! (high x n)) (low x n)" + by (metis "3" "5.hyps"(3) add_Suc_right add_self_div_2 even_Suc_div_two naive_member.simps(3) odd_add) + then show ?thesis + by (metis "5" \mi = ma\ both_member_options_def in_set_member inthall) + next + case False + hence "membermima (Node (Some (mi, ma)) deg treeList summary) x" using bstmt unfolding both_member_options_def by blast + hence " x = mi \ x = ma \ (if high x n < length treeList then membermima (treeList ! (high x n)) (low x n) else False)" + using membermima.simps(4)[of mi ma "deg-1" treeList summary x] + using "3" "5.hyps"(3) by auto + hence " high x n < length treeList \ membermima (treeList ! (high x n)) (low x n)" using xmimastmt + by presburger + then show ?thesis using both_member_options_def in_set_member inthall membermima.simps(4)[of mi ma n treeList summary x] astmt + by metis + qed + qed + hence "mi \ ma " by blast + hence followstmt: "(\ i < 2^m. (high ma n = i \ both_member_options (treeList ! i) (low ma n)) \ + (\ y. (high y n = i \ both_member_options (treeList ! i) (low y n) ) \ mi < y \ y \ ma))" + using 7 by simp + have 10:"high x n < length treeList \ + (naive_member (treeList ! (high x n)) (low x n) \ membermima (treeList ! (high x n)) (low x n) )" + by (smt "3" "5.hyps"(3) "5.prems" False add_Suc_right add_self_div_2 both_member_options_def even_Suc_div_two membermima.simps(4) naive_member.simps(3) odd_add) + hence 11:"both_member_options (treeList ! (high x n)) (low x n)" + by (simp add: both_member_options_def) + have 12:"high x n< 2^m" + using "10" "5.hyps"(2) by auto + hence "mi < x \ x < ma" proof- + have "(\ y. (high y n = (high x n) \ both_member_options (treeList ! (high y n)) (low y n) ) \ mi < y \ y \ ma)" + using "12" followstmt by auto + then show ?thesis + using "11" False order.not_eq_order_implies_strict by blast + qed + have "vebt_member (treeList ! (high x n)) (low x n)" + by (metis "10" "11" "5.IH"(1) in_set_member inthall) + then show ?thesis + by (smt "10" "11" "12" "3" "5.hyps"(3) vebt_member.simps(5) Suc_pred \0 < n\ add_Suc_right add_self_div_2 even_Suc_div_two followstmt le_neq_implies_less not_less_iff_gr_or_eq odd_add) + qed +qed + +corollary both_member_options_equiv_member: assumes "invar_vebt t n" + shows "both_member_options t x \ vebt_member t x" + using assms both_member_options_def member_valid_both_member_options valid_member_both_member_options by blast + +lemma member_correct: "invar_vebt t n \ vebt_member t x \ x \ set_vebt t " + using both_member_options_equiv_member set_vebt_def by auto + +corollary set_vebt_set_vebt'_valid: assumes "invar_vebt t n" shows "set_vebt t =set_vebt' t" + unfolding set_vebt_def set_vebt'_def + apply auto + using assms valid_member_both_member_options apply auto[1] + using assms both_member_options_equiv_member by auto + +lemma set_vebt_finite: "invar_vebt t n \ finite (set_vebt' t)" + using finite_subset inrange by blast + +lemma mi_eq_ma_no_ch:assumes "invar_vebt (Node (Some (mi, ma)) deg treeList summary) deg " and " mi = ma " + shows "(\ t \ set treeList. \ x. both_member_options t x ) \ (\ x. both_member_options summary x)" +proof- + from assms(1) show ?thesis + proof(cases) + case (4 n m) + have 0:"\t\set treeList. \ Ex (both_member_options t)" + by (simp add: "4"(7) assms(2)) + moreover have "both_member_options summary x \ False" for x + proof- + assume "both_member_options summary x " + hence "vebt_member summary x" + using "4"(2) valid_member_both_member_options by auto + moreover hence "x < 2^m" + using "4"(2) member_bound by auto + ultimately have "\ y. both_member_options (treeList ! (high x n)) y" + using "0" "4"(3) "4"(4) "4"(6) \both_member_options summary x\ inthall + by (metis nth_mem) + then show ?thesis + by (metis "0" "4"(3) "4"(4) Euclidean_Division.div_eq_0_iff \x < 2 ^ m\ high_def nth_mem zero_less_numeral zero_less_power) + qed + then show ?thesis + using calculation by blast + next + case (5 n m) + have 0:"\t\set treeList. \ Ex (both_member_options t)" + using "5"(7) assms(2) by blast + moreover have "both_member_options summary x \ False" for x + proof- + assume "both_member_options summary x " + hence "vebt_member summary x" + using "5"(2) valid_member_both_member_options by auto + moreover hence "x < 2^m" + using "5"(2) member_bound by auto + ultimately have "\ y. both_member_options (treeList ! (high x n)) y" + using "0" "5"(3) "5"(4) "5"(6) \both_member_options summary x\ inthall + by (metis nth_mem) + then show ?thesis + by (metis "0" "5"(3) "5"(6) \both_member_options summary x\ \x < 2 ^ m\ nth_mem) + qed + then show ?thesis + using calculation by blast + qed +qed + +end +end diff --git a/thys/Van_Emde_Boas_Trees/VEBT_MinMax.thy b/thys/Van_Emde_Boas_Trees/VEBT_MinMax.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/VEBT_MinMax.thy @@ -0,0 +1,326 @@ +(*by Ammer*) +theory VEBT_MinMax imports VEBT_Member +begin + +section \The Minimum and Maximum Operation\ + +fun vebt_mint :: "VEBT \ nat option" where + "vebt_mint (Leaf a b) = (if a then Some 0 else if b then Some 1 else None)"| + "vebt_mint (Node None _ _ _) = None"| + "vebt_mint (Node (Some (mi,ma)) _ _ _ ) = Some mi" + + +fun vebt_maxt :: "VEBT \ nat option" where + "vebt_maxt (Leaf a b) = (if b then Some 1 else if a then Some 0 else None)"| + "vebt_maxt (Node None _ _ _) = None"| + "vebt_maxt (Node (Some (mi,ma)) _ _ _ ) = Some ma" + + +context VEBT_internal begin + +fun option_shift::"('a\'a\'a) \'a option \'a option\ 'a option" where +"option_shift _ None _ = None"| +"option_shift _ _ None = None"| +"option_shift f (Some a) (Some b) = Some (f a b)" + +definition power::"nat option \ nat option \ nat option" (infixl"^\<^sub>o" 81) where +"power= option_shift (^)" + +definition add::"nat option \ nat option \ nat option" (infixl"+\<^sub>o" 79) where +"add= option_shift (+)" + +definition mul::"nat option \ nat option \ nat option" (infixl"*\<^sub>o" 80) where +"mul = option_shift (*)" + +fun option_comp_shift::"('a \ 'a \ bool) \ 'a option \ 'a option \ bool" where +"option_comp_shift _ None _ = False"| +"option_comp_shift _ _ None = False"| +"option_comp_shift f (Some x) (Some y) = f x y" + +fun less::"nat option \ nat option \ bool" (infixl"<\<^sub>o" 80) where +"less x y= option_comp_shift (<) x y" + +fun lesseq::"nat option \ nat option \ bool" (infixl"\\<^sub>o" 80) where +"lesseq x y = option_comp_shift (\) x y" + +fun greater::"nat option \ nat option \ bool" (infixl">\<^sub>o" 80) where +"greater x y = option_comp_shift (>) x y" + +lemma add_shift:"x+y = z \ Some x +\<^sub>o Some y = Some z" + by (simp add: add_def) + +lemma mul_shift:"x*y = z \ Some x *\<^sub>o Some y = Some z" by (simp add: mul_def) + +lemma power_shift:"x^y = z \ Some x ^\<^sub>o Some y = Some z" by (simp add: power_def) + +lemma less_shift: "x < y \ Some x <\<^sub>o Some y" by simp + +lemma lesseq_shift: "x \ y \ Some x \\<^sub>o Some y" by simp + +lemma greater_shift: "x > y \ Some x >\<^sub>o Some y" by simp + +definition max_in_set :: "nat set \ nat \ bool" where + "max_in_set xs x \ (x \ xs \ (\ y \ xs. y \ x))" + +lemma maxt_member: "invar_vebt t n \ vebt_maxt t = Some maxi \ vebt_member t maxi" +proof(induction t n arbitrary: maxi rule: invar_vebt.induct) +case (1 a b) + then show ?case + by (metis VEBT_Member.vebt_member.simps(1) vebt_maxt.simps(1) option.distinct(1) option.inject zero_neq_one) +next +case (2 treeList n summary m deg) + then show ?case + by simp +next +case (3 treeList n summary m deg) + then show ?case + by simp +next + case (4 treeList n summary m deg mi ma) + hence "deg \ 2" + by (metis One_nat_def Suc_le_eq add_mono deg_not_0 numeral_2_eq_2 plus_1_eq_Suc) + then show ?case + by (metis "4.prems" VEBT_Member.vebt_member.simps(5) Suc_diff_Suc Suc_pred lessI less_le_trans vebt_maxt.simps(3) numeral_2_eq_2 option.inject zero_less_Suc) +next + case (5 treeList n summary m deg mi ma) + hence "deg \ 2" + by (metis Suc_leI le_add2 less_add_same_cancel2 less_le_trans not_less_iff_gr_or_eq not_one_le_zero numeral_2_eq_2 plus_1_eq_Suc set_n_deg_not_0) + then show ?case + by (metis "5.prems" VEBT_Member.vebt_member.simps(5) add_2_eq_Suc le_add_diff_inverse vebt_maxt.simps(3) option.inject) +qed + + +lemma maxt_corr_help: "invar_vebt t n \ vebt_maxt t = Some maxi \ vebt_member t x \ maxi \ x " + by (smt VEBT_Member.vebt_member.simps(1) le_less vebt_maxt.elims member_inv mi_ma_2_deg option.simps(1) option.simps(3) zero_le_one) + +lemma maxt_corr_help_empty: "invar_vebt t n \ vebt_maxt t = None \ set_vebt' t = {}" + by (metis (full_types) VEBT_Member.vebt_member.simps(1) empty_Collect_eq vebt_maxt.elims minNull.simps(4) min_Null_member option.distinct(1) set_vebt'_def) + + +theorem maxt_corr:assumes "invar_vebt t n" and "vebt_maxt t = Some x" shows "max_in_set (set_vebt' t) x" + unfolding set_vebt'_def Max_def max_in_set_def + using assms(1) assms(2) maxt_corr_help maxt_member by blast + +theorem maxt_sound:assumes "invar_vebt t n" and "max_in_set (set_vebt' t) x" shows "vebt_maxt t = Some x" + by (metis (no_types, opaque_lifting) assms(1) assms(2) empty_Collect_eq le_less max_in_set_def + maxt_corr_help maxt_corr_help_empty maxt_member mem_Collect_eq not_le option.exhaust set_vebt'_def) + + +definition min_in_set :: "nat set \ nat \ bool" where + "min_in_set xs x \ (x \ xs \ (\ y \ xs. y \ x))" + +lemma mint_member: "invar_vebt t n \ vebt_mint t = Some maxi \ vebt_member t maxi" +proof(induction t n arbitrary: maxi rule: invar_vebt.induct) +case (1 a b) + then show ?case + by (metis VEBT_Member.vebt_member.simps(1) vebt_mint.simps(1) option.distinct(1) option.inject zero_neq_one) +next +case (2 treeList n summary m deg) + then show ?case + by simp +next +case (3 treeList n summary m deg) + then show ?case + by simp +next + case (4 treeList n summary m deg mi ma) + hence "deg \ 2" + by (metis One_nat_def Suc_le_eq add_mono deg_not_0 numeral_2_eq_2 plus_1_eq_Suc) + then show ?case + by (metis "4.prems" VEBT_Member.vebt_member.simps(5) One_nat_def Suc_diff_Suc Suc_pred dual_order.strict_trans1 le_imp_less_Suc le_numeral_extra(4) vebt_mint.simps(3) numeral_2_eq_2 option.inject zero_le_one) +next + case (5 treeList n summary m deg mi ma) + hence "deg \ 2" + by (metis Suc_leI le_add2 less_add_same_cancel2 less_le_trans not_less_iff_gr_or_eq not_one_le_zero numeral_2_eq_2 plus_1_eq_Suc set_n_deg_not_0) + then show ?case using "5.prems" VEBT_Member.vebt_member.simps(5) add_2_eq_Suc le_add_diff_inverse vebt_mint.simps(3) + by (metis option.inject) +qed + + +lemma mint_corr_help: "invar_vebt t n \ vebt_mint t = Some mini \ vebt_member t x \ mini \ x " + by (smt VEBT_Member.vebt_member.simps(1) eq_iff option.inject less_imp_le_nat member_inv mi_ma_2_deg vebt_mint.elims of_nat_0 of_nat_0_le_iff of_nat_le_iff option.simps(3)) + +lemma mint_corr_help_empty: "invar_vebt t n \ vebt_mint t = None \ set_vebt' t = {}" + by (metis VEBT_internal.maxt_corr_help_empty option.distinct(1) vebt_maxt.simps(1) vebt_maxt.simps(2) vebt_mint.elims) + +theorem mint_corr:assumes "invar_vebt t n" and "vebt_mint t = Some x" shows "min_in_set (set_vebt' t) x" + using assms(1) assms(2) min_in_set_def mint_corr_help mint_member set_vebt'_def by auto + +theorem mint_sound:assumes "invar_vebt t n" and "min_in_set (set_vebt' t) x" shows "vebt_mint t = Some x" + by (metis assms(1) assms(2) empty_Collect_eq eq_iff mem_Collect_eq min_in_set_def + mint_corr_help mint_corr_help_empty mint_member option.exhaust set_vebt'_def) + +lemma summaxma:assumes "invar_vebt (Node (Some (mi, ma)) deg treeList summary) deg" and "mi \ ma" + shows "the (vebt_maxt summary) = high ma (deg div 2)" +proof- + from assms(1) show ?thesis + proof(cases) + case (4 n m) + have "both_member_options summary (high ma n)" + using "4"(10) "4"(2) "4"(4) "4"(5) "4"(6) "4"(9) assms(2) deg_not_0 exp_split_high_low(1) by blast + have "high ma n \ the (vebt_maxt summary)" using "4"(2) \both_member_options summary + (high ma n)\ empty_Collect_eq option.inject maxt_corr_help maxt_corr_help_empty + not_None_eq set_vebt'_def valid_member_both_member_options + by (metis option.exhaust_sel) + have "high ma n < the (vebt_maxt summary) \ False" + proof- + assume "high ma n < the (vebt_maxt summary)" + obtain maxs where "Some maxs = vebt_maxt summary" + by (metis "4"(2) \both_member_options summary (high ma n)\ empty_Collect_eq maxt_corr_help_empty + not_None_eq set_vebt'_def valid_member_both_member_options) + hence "\ x. both_member_options (treeList ! maxs) x" + by (metis "4"(2) "4"(6) both_member_options_equiv_member maxt_member member_bound) + then obtain x where "both_member_options (treeList ! maxs) x" + by auto + hence "vebt_member (treeList ! maxs) x" + by (metis "4"(1) "4"(2) "4"(3) \Some maxs = vebt_maxt summary\ maxt_member member_bound nth_mem valid_member_both_member_options) + have "maxs < 2^m" + by (metis "4"(2) \Some maxs = vebt_maxt summary\ maxt_member member_bound) + have "invar_vebt (treeList ! maxs) n" + by (metis "4"(1) "4"(3) \maxs < 2 ^ m\ inthall member_def) + hence "x < 2^n" + using \vebt_member (treeList ! maxs) x\ member_bound by auto + let ?X = "2^n*maxs + x" + have "high ?X n = maxs" + by (simp add: \x < 2 ^ n\ high_inv mult.commute) + hence "both_member_options (Node (Some (mi, ma)) deg treeList summary) (2^n*maxs + x)" + by (metis "4"(3) "4"(4) "4"(5) One_nat_def Suc_leI \both_member_options (treeList ! maxs) x\ \maxs < 2 ^ m\ \x < 2 ^ n\ add_self_div_2 assms(1) both_member_options_from_chilf_to_complete_tree deg_not_0 low_inv mult.commute) + hence "vebt_member (Node (Some (mi, ma)) deg treeList summary) ?X" + using assms(1) both_member_options_equiv_member by auto + have "high ?X n> high ma n" + by (metis \Some maxs = vebt_maxt summary\ \high (2 ^ n * maxs + x) n = maxs\ \high ma n < the (vebt_maxt summary)\ option.exhaust_sel option.inject option.simps(3)) + hence "?X > ma" + by (metis div_le_mono high_def not_le) + then show ?thesis + by (metis "4"(8) \vebt_member (Node (Some (mi, ma)) deg treeList summary) (2 ^ n * maxs + x)\ leD member_inv not_less_iff_gr_or_eq) + qed + then show ?thesis + using "4"(4) "4"(5) \high ma n \ the (vebt_maxt summary)\ by fastforce +next + case (5 n m) + have "both_member_options summary (high ma n)" + by (metis "5"(10) "5"(5) "5"(6) "5"(9) Euclidean_Division.div_eq_0_iff assms(2) div_exp_eq high_def nat.simps(3) numerals(2) power_not_zero) + have "high ma n \ the (vebt_maxt summary)" + by (metis "5"(2) VEBT_Member.vebt_member.simps(2) \both_member_options summary (high ma n)\ vebt_maxt.elims maxt_corr_help minNull.simps(1) min_Null_member option.exhaust_sel option.simps(3) valid_member_both_member_options) + have "high ma n < the (vebt_maxt summary) \ False" + proof- + assume "high ma n < the (vebt_maxt summary)" + obtain maxs where "Some maxs = vebt_maxt summary" + by (metis "5"(2) \both_member_options summary (high ma n)\ empty_Collect_eq maxt_corr_help_empty + not_None_eq set_vebt'_def valid_member_both_member_options) + hence "\ x. both_member_options (treeList ! maxs) x" + by (metis "5"(2) "5"(6) both_member_options_equiv_member maxt_member member_bound) + then obtain x where "both_member_options (treeList ! maxs) x" + by auto + hence "vebt_member (treeList ! maxs) x" + by (metis "5"(1) "5"(2) "5"(3) \Some maxs = vebt_maxt summary\ both_member_options_equiv_member maxt_member member_bound nth_mem) + have "maxs < 2^m" + by (metis "5"(2) \Some maxs = vebt_maxt summary\ maxt_member member_bound) + have "invar_vebt (treeList ! maxs) n" + by (metis "5"(1) "5"(3) \maxs < 2 ^ m\ inthall member_def) + hence "x < 2^n" + using \vebt_member (treeList ! maxs) x\ member_bound by auto + let ?X = "2^n*maxs + x" + have "high ?X n = maxs" + by (simp add: \x < 2 ^ n\ high_inv mult.commute) + hence "both_member_options (Node (Some (mi, ma)) deg treeList summary) (2^n*maxs + x)" + by (smt (z3) "5"(3) "5"(4) "5"(5) \both_member_options (treeList ! maxs) x\ \maxs < 2 ^ m\ \x < 2 ^ n\ add_Suc_right add_self_div_2 both_member_options_from_chilf_to_complete_tree even_Suc_div_two le_add1 low_inv mult.commute odd_add plus_1_eq_Suc) + hence "vebt_member (Node (Some (mi, ma)) deg treeList summary) ?X" + using assms(1) both_member_options_equiv_member by auto + have "high ?X n> high ma n" + by (metis \Some maxs = vebt_maxt summary\ \high (2 ^ n * maxs + x) n = maxs\ \high ma n < the (vebt_maxt summary)\ option.sel) + hence "?X > ma" + by (metis div_le_mono high_def not_le) + then show ?thesis + by (metis "5"(8) \vebt_member (Node (Some (mi, ma)) deg treeList summary) (2 ^ n * maxs + x)\ leD member_inv not_less_iff_gr_or_eq) + qed + then show ?thesis + using "5"(4) "5"(5) \high ma n \ the(vebt_maxt summary)\ by fastforce + qed +qed + +lemma maxbmo: "vebt_maxt t = Some x \ both_member_options t x" + apply(induction t rule: vebt_maxt.induct) + apply auto + apply (metis both_member_options_def naive_member.simps(1) option.distinct(1) option.sel zero_neq_one) + by (metis One_nat_def Suc_le_D both_member_options_def div_by_1 div_greater_zero_iff membermima.simps(3) membermima.simps(4) not_gr0) + +lemma misiz:"invar_vebt t n \ Some m = vebt_mint t \ m < 2^n" + by (metis member_bound mint_member) + +lemma mintlistlength: assumes "invar_vebt (Node (Some (mi, ma)) deg treeList summary) n " " + mi \ ma " shows " ma > mi \ (\ m. Some m = vebt_mint summary \ m < 2^(n - n div 2))" + using assms(1) +proof cases + case (4 n m) + hence "both_member_options (treeList ! high ma n) (low ma n)" + by (metis assms(2) high_bound_aux) + moreover hence "both_member_options summary (high ma n)" + using "4"(10) "4"(6) "4"(7) high_bound_aux by blast + moreover then obtain mini where "Some mini = vebt_mint summary" + by (metis "4"(3) empty_Collect_eq mint_corr_help_empty option.exhaust_sel set_vebt'_def valid_member_both_member_options) + moreover hence "mini < 2^m" + by (metis "4"(3) mint_member member_bound) + moreover have "m = (deg - deg div 2)" using 4(6) 4(5) + by auto + ultimately show ?thesis using 4(1) assms 4(9) by auto +next + case (5 n m) + hence "both_member_options (treeList ! high ma n) (low ma n)" + by (metis assms(2) high_bound_aux) + moreover hence "both_member_options summary (high ma n)" + using "5"(10) "5"(6) "5"(7) high_bound_aux by blast + moreover then obtain mini where "Some mini = vebt_mint summary" + by (metis "5"(3) empty_Collect_eq mint_corr_help_empty option.exhaust_sel set_vebt'_def valid_member_both_member_options) + moreover hence "mini < 2^m" + by (metis "5"(3) mint_member member_bound) + moreover have "m = (deg - deg div 2)" using 5(6) 5(5) + by auto + ultimately show ?thesis using 5(1) assms 5(9) by auto +qed + +lemma power_minus_is_div: + "b \ a \ (2 :: nat) ^ (a - b) = 2 ^ a div 2 ^ b" + apply (induct a arbitrary: b) + apply simp + apply (erule le_SucE) + apply (clarsimp simp:Suc_diff_le le_iff_add power_add) + apply simp + done + +lemma nested_mint:assumes "invar_vebt (Node (Some (mi, ma)) deg treeList summary) n " "n = Suc (Suc va) "" + \ ma < mi "" ma \ mi " shows " + high (the (vebt_mint summary) * (2 * 2 ^ (va div 2)) + the (vebt_mint (treeList ! the (vebt_mint summary)))) (Suc (va div 2)) + < length treeList" +proof- + have setprop: "t \ set treeList \ invar_vebt t (n div 2 )" for t using assms(1) + by (cases) simp+ + have listlength: "length treeList = 2^(n - n div 2)" using assms(1) + by (cases) simp+ + have sumprop: "invar_vebt summary (n - n div 2)" using assms(1) + by (cases) simp+ + have mimaxprop: "mi \ ma \ ma \ 2^n" using assms(1) + by cases simp+ + hence xbound: "mi \ x \ x \ ma \ high x (n div 2) \ length treeList " for x + using div_le_dividend div_le_mono high_def listlength power_minus_is_div by auto + have contcong:"i < length treeList \ \ x. both_member_options (treeList ! i) x \ both_member_options summary i " for i + using assms(1)by cases auto+ + obtain m where " Some m = vebt_mint summary \ m < 2^(n - n div 2)" + using assms(1) assms(4) mintlistlength by blast + then obtain miny where "(vebt_mint (treeList ! the (vebt_mint summary))) =Some miny" + by (metis both_member_options_equiv_member contcong empty_Collect_eq listlength mint_corr_help_empty mint_member nth_mem option.exhaust_sel option.sel setprop sumprop set_vebt'_def) + hence "miny < 2^(n div 2)" + by (metis \\thesis. (\m. Some m = vebt_mint summary \ m < 2 ^ (n - n div 2) \ thesis) \ thesis\ listlength misiz nth_mem option.sel setprop) + then show ?thesis + by (metis \\thesis. (\m. Some m = vebt_mint summary \ m < 2 ^ (n - n div 2) \ thesis) \ thesis\ \vebt_mint (treeList ! the (vebt_mint summary)) = Some miny\ assms(2) div2_Suc_Suc high_inv listlength option.sel power_Suc) +qed + +lemma minminNull: "vebt_mint t = None \ minNull t" + by (metis minNull.simps(1) minNull.simps(4) vebt_mint.elims option.distinct(1)) + +lemma minNullmin: "minNull t \ vebt_mint t = None" + by (metis minNull.elims(2) vebt_mint.simps(1) vebt_mint.simps(2)) + + +end +end diff --git a/thys/Van_Emde_Boas_Trees/VEBT_Pred.thy b/thys/Van_Emde_Boas_Trees/VEBT_Pred.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/VEBT_Pred.thy @@ -0,0 +1,886 @@ +(*by Ammer*) +theory VEBT_Pred imports VEBT_MinMax VEBT_Insert +begin + +section \The Predecessor Operation\ + +definition is_pred_in_set :: "nat set \ nat \ nat \ bool" where + "is_pred_in_set xs x y = (y \ xs \ y < x \ (\ z \ xs. (z < x \ z \ y)))" + +context VEBT_internal begin + +subsection \Lemmas on Sets and Predecessorship\ + +corollary pred_member: "is_pred_in_set (set_vebt' t) x y = (vebt_member t y \ y < x \ (\ z. vebt_member t z \ z < x \ z \ y))" + using is_pred_in_set_def set_vebt'_def by auto + +lemma "finite (A:: nat set) \ A \ {}\ Max A \ A" +proof(induction A rule: finite.induct) + case emptyI + then show ?case by blast +next + case (insertI A a) + then show ?case + by (meson Max_in finite_insert) +qed + +lemma obtain_set_pred: assumes "(x::nat) > z " and "min_in_set A z" and "finite A" shows "\ y. is_pred_in_set A x y" +proof- + have "{y \ A. y < x} \ {}" + using assms(1) assms(2) min_in_set_def by auto + hence "Max {y \ A. y < x} \ {y \ A. y < x}" + by (metis (full_types) Max_eq_iff finite_M_bounded_by_nat) + moreover have "i \ A\ i < x \ i \ Max {y \ A. y < x} " for i by simp + ultimately have "is_pred_in_set A x (Max {y \ A. y < x})" + using is_pred_in_set_def by auto + then show?thesis by auto +qed + +lemma pred_none_empty: assumes "(\ x. is_pred_in_set (xs) a x)" and "finite xs"shows "\ (\ x \ xs. ord_class.less x a)" +proof- + have "\ x \ xs. ord_class.less x a \ False" + proof- + assume "\ x \ xs. ord_class.less x a" + hence "{x \ xs. ord_class.less x a} \ {}" by auto + hence "Max {y \ xs. y < a} \ {y \ xs. y < a}" + by (metis (full_types) Max_eq_iff finite_M_bounded_by_nat) + moreover hence "i \ xs \ ord_class.less i a\ + ord_class.less_eq i (Max {y \ xs. ord_class.less y a}) " for i + by (simp add: assms(2)) + ultimately have "is_pred_in_set xs a (Max {y \ xs. y < a})" + using is_pred_in_set_def by auto + then show False + using assms(1) by blast + qed + then show ?thesis by blast +qed + +end + +subsection \The actual Function for Predecessor Search\ + +context begin + interpretation VEBT_internal . + +fun vebt_pred :: "VEBT \ nat \ nat option" where + "vebt_pred (Leaf _ _) 0 = None"| + "vebt_pred (Leaf a _) (Suc 0) = (if a then Some 0 else None)"| + "vebt_pred (Leaf a b) _ = (if b then Some 1 else if a then Some 0 else None)"| + "vebt_pred (Node None _ _ _) _ = None"| + "vebt_pred (Node _ 0 _ _) _ = None"| + "vebt_pred (Node _ (Suc 0) _ _) _ = None"| + "vebt_pred (Node (Some (mi, ma)) deg treeList summary) x = ( + if x > ma then Some ma + else (let l = low x (deg div 2); h = high x (deg div 2) in + if h < length treeList then + let minlow = vebt_mint (treeList ! h) in ( + if minlow \ None \ (Some l >\<^sub>o minlow) then + Some (2^(deg div 2)) *\<^sub>o Some h +\<^sub>o vebt_pred (treeList ! h) l + else let pr = vebt_pred summary h in + if pr = None then ( + if x > mi then Some mi + else None) + else Some (2^(deg div 2)) *\<^sub>o pr +\<^sub>o vebt_maxt (treeList ! the pr) ) + else None))" + +end + +context VEBT_internal begin +subsection \Auxiliary Lemmas\ + +lemma pred_max: + assumes "deg \ 2" and "(x::nat) > ma" + shows "vebt_pred (Node (Some (mi, ma)) deg treeList summary) x = Some ma" + by (metis VEBT_Pred.vebt_pred.simps(7) add_2_eq_Suc assms(1) assms(2) le_add_diff_inverse) + +lemma pred_lesseq_max: + assumes "deg \ 2" and "(x::nat) \ ma" + shows "vebt_pred (Node (Some (mi, ma)) deg treeList summary) x = (let l = low x (deg div 2); h = high x (deg div 2) in + if h < length treeList then + + let minlow = vebt_mint (treeList ! h) in + (if minlow \ None \ (Some l >\<^sub>o minlow) then + Some (2^(deg div 2)) *\<^sub>o Some h +\<^sub>o vebt_pred (treeList ! h) l + else let pr = vebt_pred summary h in + if pr = None then (if x > mi then Some mi else None) + else Some (2^(deg div 2)) *\<^sub>o pr +\<^sub>o vebt_maxt (treeList ! the pr) ) + + else None)" + by (smt VEBT_Pred.vebt_pred.simps(7) add_numeral_left assms(1) assms(2) leD le_add_diff_inverse numerals(1) plus_1_eq_Suc semiring_norm(2)) + +lemma pred_list_to_short: + assumes "deg \ 2" and "ord_class.less_eq x ma" and " high x (deg div 2) \ length treeList" + shows "vebt_pred (Node (Some (mi, ma)) deg treeList summary) x = None" + by (simp add: assms(1) assms(2) assms(3) leD pred_lesseq_max) + + +lemma pred_less_length_list: + assumes "deg \ 2" and "ord_class.less_eq x ma" and " high x (deg div 2) < length treeList" + shows + "vebt_pred (Node (Some (mi, ma)) deg treeList summary) x = (let l = low x (deg div 2); h = high x (deg div 2); minlow = vebt_mint (treeList ! h) in + (if minlow \ None \ (Some l >\<^sub>o minlow) then + Some (2^(deg div 2)) *\<^sub>o Some h +\<^sub>o vebt_pred (treeList ! h) l + else let pr = vebt_pred summary h in + if pr = None then (if x > mi then Some mi else None) + else Some (2^(deg div 2)) *\<^sub>o pr +\<^sub>o vebt_maxt (treeList ! the pr) ))" + by (simp add: assms(1) assms(2) assms(3) pred_lesseq_max) + +subsection \Correctness Proof\ + +theorem pred_corr: "invar_vebt t n \ vebt_pred t x = Some px == is_pred_in_set (set_vebt' t) x px" +proof(induction t n arbitrary: x px rule: invar_vebt.induct) + case (1 a b) + then show ?case + proof(cases x) + case 0 + then show ?thesis + by (simp add: is_pred_in_set_def) + next + case (Suc sucX) + hence "x \ 0 \ x = Suc sucX" by auto + then show ?thesis + proof(cases sucX) + case 0 + then show ?thesis + by (simp add: Suc pred_member) + next + case (Suc nat) + hence "x\ 2" + by (simp add: \0 \ x \ x = Suc sucX\) + then show ?thesis + proof(cases b) + case True + hence "vebt_pred (Leaf a b) x = Some 1" + by (simp add: Suc \0 \ x \ x = Suc sucX\) + moreover have "is_pred_in_set (set_vebt' (Leaf a b)) x 1" + by (simp add: Suc True \0 \ x \ x = Suc sucX\ pred_member) + ultimately show ?thesis + using pred_member by auto + next + case False + hence "b = False" by simp + then show ?thesis + proof(cases a) + case True + hence "vebt_pred (Leaf a b) x = Some 0" + by (simp add: False Suc \0 \ x \ x = Suc sucX\) + moreover have "is_pred_in_set (set_vebt' (Leaf a b)) x 0" + by (simp add: False True \0 \ x \ x = Suc sucX\ pred_member) + ultimately show ?thesis + by (metis False VEBT_Member.vebt_member.simps(1) option.sel pred_member) + next + case False + then show ?thesis + by (simp add: Suc \0 \ x \ x = Suc sucX\ pred_member) + qed + qed + qed + qed +next + case (2 treeList n summary m deg) + then show ?case + by (simp add: pred_member) +next + case (3 treeList n summary m deg) + then show ?case + by (simp add: pred_member) +next + case (4 treeList n summary m deg mi ma) + hence "n = m" and "n \ 1" and "deg \ 2" and "deg = n + m" + apply blast+ + using "4.hyps"(2) "4.hyps"(5) Suc_le_eq deg_not_0 apply auto[1] + using "4.hyps"(2) "4.hyps"(5) "4.hyps"(6) deg_not_0 apply fastforce + by (simp add: "4.hyps"(6)) + moreover hence thisvalid:"invar_vebt (Node (Some (mi, ma)) deg treeList summary) deg" + using 4 invar_vebt.intros(4)[of treeList n summary m] by blast + ultimately have "deg div 2 =n" and "length treeList = 2^n" + using add_self_div_2 apply blast by (simp add: "4.hyps"(4) "4.hyps"(5)) + then show ?case + proof(cases "x > ma") + case True + hence 0: "vebt_pred (Node (Some (mi, ma)) deg treeList summary) x = Some ma" + by (simp add: \2 \ deg\ pred_max) + have 1:"ma = the (vebt_maxt (Node (Some (mi, ma)) deg treeList summary))" by simp + hence "ma \ set_vebt' (Node (Some (mi, ma)) deg treeList summary)" + by (metis VEBT_Member.vebt_member.simps(5) \2 \ deg\ add_numeral_left arith_simps(1) le_add_diff_inverse mem_Collect_eq numerals(1) plus_1_eq_Suc set_vebt'_def) + hence 2:"y \ set_vebt' (Node (Some (mi, ma)) deg treeList summary) \ y \ x" for y + using "4.hyps"(9) True member_inv set_vebt'_def by fastforce + hence 3: "y \ set_vebt' (Node (Some (mi, ma)) deg treeList summary) \ (y < ma \ y \ x)" for y by blast + hence 4: "\ y \ set_vebt' (Node (Some (mi, ma)) deg treeList summary). y < ma \ y \ x" by blast + hence "is_pred_in_set (set_vebt' (Node (Some (mi, ma)) deg treeList summary)) x ma" + by (metis "4.hyps"(9) True \ma \ set_vebt' (Node (Some (mi, ma)) deg treeList summary)\ less_or_eq_imp_le mem_Collect_eq member_inv pred_member set_vebt'_def) + then show ?thesis + by (metis "0" option.sel leD le_less_Suc_eq not_less_eq pred_member) + next + case False + hence "x \ ma"by simp + then show ?thesis + proof(cases "high x (deg div 2)< length treeList ") + case True + hence "high x n < 2^n \ low x n < 2^n" + by (simp add: \deg div 2 = n\ \length treeList = 2 ^ n\ low_def) + let ?l = "low x (deg div 2)" + let ?h = "high x (deg div 2)" + let ?minlow = "vebt_mint (treeList ! ?h)" + let ?pr = "vebt_pred summary ?h" + have 1:"vebt_pred (Node (Some (mi, ma)) deg treeList summary) x = + (if ?minlow \ None \ (Some ?l >\<^sub>o ?minlow) then + Some (2^(deg div 2)) *\<^sub>o Some ?h +\<^sub>o vebt_pred (treeList ! ?h) ?l + else let pr = vebt_pred summary ?h in + if pr = None then (if x > mi then Some mi else None) + else Some (2^(deg div 2)) *\<^sub>o pr +\<^sub>o vebt_maxt (treeList ! the pr) )" + by (smt True \2 \ deg\ \x \ ma\ pred_less_length_list) + then show ?thesis + proof(cases "?minlow \ None \ (Some ?l >\<^sub>o ?minlow)") + case True + then obtain minl where 00:"(Some minl = ?minlow) \ ?l > minl" by auto + have 01:"invar_vebt ((treeList ! ?h)) n \ (treeList ! ?h) \ set treeList " + by (simp add: "4.hyps"(1) "4.hyps"(4) "4.hyps"(5) \deg div 2 = n\ \high x n < 2 ^ n \ low x n < 2 ^ n\) + have 02:"vebt_member ((treeList ! ?h)) minl" + using "00" "01" mint_member by auto + hence 03: "\ y. y < ?l \ vebt_member ((treeList ! ?h)) y" + using "00" by blast + hence afinite: "finite (set_vebt' (treeList ! ?h)) " + using "01" set_vebt_finite by blast + then obtain predy where 04:"is_pred_in_set (set_vebt' (treeList ! ?h)) ?l predy" + using "00" "01" mint_corr obtain_set_pred by fastforce + hence 05:"Some predy = vebt_pred (treeList ! ?h) ?l" using 4(1) 01 by force + hence "vebt_pred (Node (Some (mi, ma)) deg treeList summary) x = Some (2^(deg div 2)* ?h + predy) " + using "1" True add_def mul_def option_shift.simps(3) by metis + hence 06: "predy \ set_vebt' (treeList ! ?h)" + using "04" is_pred_in_set_def by blast + hence 07: "predy < 2^(deg div 2) \ ?h < 2^(deg div 2) \ deg div 2 + deg div 2 = deg" + using "01" "04" "4.hyps"(5) "4.hyps"(6) \high x n < 2 ^ n \ low x n < 2 ^ n\ member_bound pred_member by auto + let ?y = "2^(deg div 2)* ?h + predy" + have 08: "vebt_member (treeList ! ?h) predy" + using "06" set_vebt'_def by auto + hence 09: "both_member_options (treeList ! ?h) predy" + using "01" both_member_options_equiv_member by blast + have 10: "high ?y (deg div 2) = ?h \ low ?y (deg div 2) = predy" + by (simp add: "07" high_inv low_inv mult.commute) + hence 14:"both_member_options (Node (Some (mi, ma)) deg treeList summary) ?y" + by (metis "07" "09" "4.hyps"(4) "4.hyps"(5) Suc_1 \2 \ deg\ \deg div 2 = n\ add_leD1 both_member_options_from_chilf_to_complete_tree plus_1_eq_Suc) + have 15: "vebt_member (Node (Some (mi, ma)) deg treeList summary) ?y" + using "14" thisvalid valid_member_both_member_options by blast + have 16: "Some ?y = vebt_pred (Node (Some (mi, ma)) deg treeList summary) x" + by (simp add: \vebt_pred (Node (Some (mi, ma)) deg treeList summary) x = Some (2 ^ (deg div 2) * high x (deg div 2) + predy)\) + have 17: "x = ?h * 2^(deg div 2) + ?l" + using bit_concat_def bit_split_inv by auto + have 18: "x - ?y = ?h * 2^(deg div 2) + ?l -?h * 2^(deg div 2) - predy " + by (metis "17" diff_diff_add mult.commute) + hence 19: "?y < x" + using "04" "17" mult.commute nat_add_left_cancel_less pred_member by fastforce + have 20: "z < x \ vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ z\ ?y " for z + proof- + assume "z < x" and "vebt_member (Node (Some (mi, ma)) deg treeList summary) z" + hence "high z (deg div 2) \ high x (deg div 2)" + by (simp add: div_le_mono high_def) + then show ?thesis + proof(cases "high z (deg div 2) = high x (deg div 2)") + case True + hence 0000: "high z (deg div 2) = high x (deg div 2)" by simp + then show ?thesis + proof(cases "z = mi") + case True + then show ?thesis + using "15" vebt_mint.simps(3) mint_corr_help thisvalid by blast + next + case False + hence ad:"vebt_member (treeList ! ?h) (low z (deg div 2))" + using vebt_member.simps(5)[of mi ma "deg-2" treeList summary z] + by (metis True \vebt_member (Node (Some (mi, ma)) deg treeList summary) z\ \x \ ma\ \z < x\ leD member_inv) + have "is_pred_in_set (set_vebt' (treeList ! ?h)) ?l predy" + using "04" by blast + have "low z (deg div 2) < ?l" + by (metis (full_types) True \z < x\ bit_concat_def bit_split_inv nat_add_left_cancel_less) + hence "predy \ low z (deg div 2)" using 04 ad unfolding is_pred_in_set_def + by (simp add: set_vebt'_def) + hence "?y \ z" + by (smt True bit_concat_def bit_split_inv diff_add_inverse diff_diff_add diff_is_0_eq mult.commute) + then show ?thesis by blast + qed + next + case False + hence "high z (deg div 2) < high ?y (deg div 2)" + using "10" \high z (deg div 2) \ high x (deg div 2)\ by linarith + then show ?thesis + by (metis div_le_mono high_def nat_le_linear not_le) + qed + qed + hence "is_pred_in_set (set_vebt' (Node (Some (mi, ma)) deg treeList summary)) x ?y" + by (simp add: "15" "19" pred_member) + then show ?thesis using 16 + by (metis eq_iff option.inject pred_member) + next + case False + hence i1:"?minlow = None \ \ (Some ?l >\<^sub>o ?minlow)" by simp + hence 2: "vebt_pred (Node (Some (mi, ma)) deg treeList summary) x = ( + if ?pr = None then (if x > mi + then Some mi + else None) + else Some (2^(deg div 2)) *\<^sub>o ?pr +\<^sub>o vebt_maxt (treeList ! the ?pr))" + using "1" by auto + have " invar_vebt (treeList ! ?h) n" + by (metis "4"(1) True inthall member_def) + hence 33:"\ u. vebt_member (treeList ! ?h) u \ u < ?l" + proof(cases "?minlow = None") + case True + then show ?thesis using mint_corr_help_empty[of "treeList ! ?h" n] + by (simp add: \invar_vebt (treeList ! high x (deg div 2)) n\ set_vebt'_def) + next + case False + obtain minilow where "?minlow =Some minilow" + using False by blast + hence "minilow \ ?l" + using "i1" by auto + then show ?thesis + by (meson \vebt_mint (treeList ! high x (deg div 2)) = Some minilow\ \invar_vebt (treeList ! high x (deg div 2)) n\ leD less_le_trans mint_corr_help) + qed + then show ?thesis + proof(cases "?pr= None") + case True + hence "vebt_pred (Node (Some (mi, ma)) deg treeList summary) x = (if x > mi then Some mi else None)" + by (simp add: "2") + hence "\ i. is_pred_in_set (set_vebt' summary) ?h i" + using "4.hyps"(3) True by force + hence "\ i. i < ?h \ vebt_member summary i " using pred_none_empty[of "set_vebt' summary" ?h] + proof - + { fix nn :: nat + have "\n. ((is_pred_in_set (Collect (vebt_member summary)) (high x (deg div 2)) esk1_0 \ infinite (Collect (vebt_member summary))) \ n \ Collect (vebt_member summary)) \ \ n < high x (deg div 2)" + using \\i. is_pred_in_set (set_vebt' summary) (high x (deg div 2)) i\ pred_none_empty set_vebt'_def by auto + then have "\ nn < high x (deg div 2) \ \ vebt_member summary nn" + by (metis (no_types) "4.hyps"(2) \\i. is_pred_in_set (set_vebt' summary) (high x (deg div 2)) i\ mem_Collect_eq set_vebt'_def set_vebt_finite) } + then show ?thesis + by blast + qed + then show ?thesis + proof(cases "x > mi") + case True + hence "vebt_pred (Node (Some (mi, ma)) deg treeList summary) x = Some mi" + by (simp add: \vebt_pred (Node (Some (mi, ma)) deg treeList summary) x = (if mi < x then Some mi else None)\) + have "(vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ z < x \ z > mi) \ False" for z + proof- + assume "vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ z < x \ z > mi" + hence "vebt_member ( treeList ! (high z (deg div 2))) (low z (deg div 2))" + using \x \ ma\ member_inv not_le by blast + moreover hence "high z (deg div 2) < 2^m" + using "4.hyps"(4) \vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ z < x \ mi < z\ \x \ ma\ member_inv by fastforce + moreover hence "invar_vebt (treeList ! (high z (deg div 2))) n" using 4(1) + by (simp add: "4.hyps"(4)) + ultimately have "vebt_member summary (high z (deg div 2))" using 4(7) + using "4.hyps"(2) both_member_options_equiv_member by blast + have "(high z (deg div 2)) \ ?h" + by (simp add: \vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ z < x \ mi < z\ div_le_mono high_def less_or_eq_imp_le) + then show False + by (metis "33" \\ (\i \vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ z < x \ mi < z\ \vebt_member (treeList ! high z (deg div 2)) (low z (deg div 2))\ \vebt_member summary (high z (deg div 2))\ bit_concat_def bit_split_inv le_neq_implies_less nat_add_left_cancel_less) + qed + hence "is_pred_in_set (set_vebt' ((Node (Some (mi, ma)) deg treeList summary))) x mi" + by (metis VEBT_Member.vebt_member.simps(5) True \2 \ deg\ add_2_eq_Suc le_add_diff_inverse le_less_linear pred_member) + then show ?thesis + by (metis \vebt_pred (Node (Some (mi, ma)) deg treeList summary) x = Some mi\ \x \ ma\ option.sel leD member_inv pred_member) + next + case False + hence "vebt_pred (Node (Some (mi, ma)) deg treeList summary) x = None" + by (simp add: "2" True) + then show ?thesis + by (metis (full_types) False less_trans member_inv option.distinct(1) pred_max pred_member) + qed + next + case False + hence fst:"vebt_pred (Node (Some (mi, ma)) deg treeList summary) x = + Some (2^(deg div 2)) *\<^sub>o ?pr +\<^sub>o vebt_maxt (treeList ! the ?pr)" + using "2" by presburger + obtain pr where "?pr = Some pr" + using False by blast + hence "is_pred_in_set (set_vebt' summary) ?h pr" + using "4.hyps"(3) by blast + hence "vebt_member summary pr" + using pred_member by blast + hence "both_member_options summary pr" + using "4.hyps"(2) both_member_options_equiv_member by auto + hence "pr < 2^m" + using "4.hyps"(2) \vebt_member summary pr\ member_bound by blast + hence "\ maxy. both_member_options (treeList ! pr) maxy" + using "4.hyps"(7) \both_member_options summary pr\ by blast + hence fgh:"set_vebt' (treeList ! pr) \ {}" + by (metis "4.hyps"(1) "4.hyps"(2) "4.hyps"(4) \vebt_member summary pr\ empty_Collect_eq member_bound nth_mem set_vebt'_def valid_member_both_member_options) + hence "invar_vebt (treeList ! the ?pr) n" + by (simp add: "4.hyps"(1) "4.hyps"(4) \pr < 2 ^ m\ \vebt_pred summary (high x (deg div 2)) = Some pr\) + then obtain maxy where "Some maxy = vebt_maxt (treeList ! pr)" + by (metis \vebt_pred summary (high x (deg div 2)) = Some pr\ fgh option.sel vebt_maxt.elims maxt_corr_help_empty) + hence "Some maxy = vebt_maxt (treeList ! the ?pr)" + by (simp add: \vebt_pred summary (high x (deg div 2)) = Some pr\) + hence "max_in_set (set_vebt' (treeList ! the ?pr)) maxy" + using \invar_vebt (treeList ! the (vebt_pred summary (high x (deg div 2)))) n\ maxt_corr by auto + hence scmem:"vebt_member (treeList ! the ?pr) maxy" + using \Some maxy = vebt_maxt (treeList ! the (vebt_pred summary (high x (deg div 2))))\ \invar_vebt (treeList ! the (vebt_pred summary (high x (deg div 2)))) n\ maxt_member by force + let ?res = "Some (2^(deg div 2)) *\<^sub>o ?pr +\<^sub>o vebt_maxt (treeList ! the ?pr)" + obtain res where snd: "res = the ?res" by blast + hence "res = 2^(deg div 2) * pr + maxy" + by (metis \Some maxy = vebt_maxt (treeList ! pr)\ \vebt_pred summary (high x (deg div 2)) = Some pr\ add_def option.sel mul_def option_shift.simps(3)) + have "high res (deg div 2) = pr" + by (metis \deg div 2 = n\ \res = 2 ^ (deg div 2) * pr + maxy\ \invar_vebt (treeList ! the ?pr) n\ high_inv member_bound mult.commute scmem) + hence "res < x" + by (metis \is_pred_in_set (set_vebt' summary) (high x (deg div 2)) pr\ div_le_mono high_def pred_member verit_comp_simplify1(3)) + have "both_member_options (treeList ! (high res (deg div 2))) (low res (deg div 2))" + by (metis \deg div 2 = n\ \high res (deg div 2) = pr\ \vebt_pred summary (high x (deg div 2)) = Some pr\ \res = 2 ^ (deg div 2) * pr + maxy\ \invar_vebt (treeList ! the (vebt_pred summary (high x (deg div 2)))) n\ both_member_options_equiv_member option.sel low_inv member_bound mult.commute scmem) + have "both_member_options (Node (Some (mi, ma)) deg treeList summary) res" + by (metis "4.hyps"(2) "4.hyps"(4) "4.hyps"(6) \1 \ n\ \both_member_options (treeList ! high res (deg div 2)) (low res (deg div 2))\ \high res (deg div 2) = pr\ \vebt_member summary pr\ both_member_options_from_chilf_to_complete_tree member_bound trans_le_add1) + hence "vebt_member (Node (Some (mi, ma)) deg treeList summary) res" + using thisvalid valid_member_both_member_options by auto + hence "res > mi" + by (metis "4.hyps"(11) \both_member_options (treeList ! high res (deg div 2)) (low res (deg div 2))\ \deg div 2 = n\ \high res (deg div 2) = pr\ \pr < 2 ^ m\ \res < x\ \x \ ma\ less_le_trans member_inv) + hence "res < ma" + using \res < x\ \x \ ma\ less_le_trans by blast + have "(vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ z < x) \ z \ res" for z + proof- + fix z + assume "vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ z < x" + hence 20: "z = mi \ z = ma \ (high z (deg div 2) < length treeList + \ vebt_member ( treeList ! (high z (deg div 2))) (low z (deg div 2)))" using + vebt_member.simps(5)[of mi ma "deg-2" treeList summary z] + using member_inv by blast + have "z \ ma" + using \vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ z < x\ \x \ ma\ leD by blast + hence "mi \ ma" + by (metis \mi < res\ \res < x\ \x \ ma\ leD less_trans) + hence "z < 2^deg" + using \vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ z < x\ member_bound thisvalid by blast + hence abc:"invar_vebt (treeList ! (high z (deg div 2))) n" + by (metis "4.hyps"(1) "4.hyps"(2) "4.hyps"(5) "4.hyps"(6) \deg div 2 = n\ \z < 2 ^ deg\ \length treeList = 2 ^ n\ deg_not_0 exp_split_high_low(1) in_set_member inthall) + then show "z \ res" + proof(cases "z = mi") + case True + then show ?thesis + using \mi < res\ by auto + next + case False + hence abe:"vebt_member( treeList ! (high z (deg div 2))) (low z (deg div 2))" + using "20" \z \ ma\ by blast + hence abh:"vebt_member summary (high z (deg div 2))" + by (metis "20" "4.hyps"(2) "4.hyps"(4) "4.hyps"(7) False \vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ z < x\ \x \ ma\ abc both_member_options_equiv_member not_le) + have aaa:"(high z (deg div 2)) = (high x (deg div 2)) \ vebt_member (treeList ! ?h) (low z (deg div 2))" + using abe by auto + have "high z(deg div 2) > pr \ False" + proof- + assume "high z(deg div 2) > pr" + hence "vebt_member summary (high z(deg div 2))" + using abh by blast + have aaaa:"?h \ high z(deg div 2)" + by (meson \is_pred_in_set (set_vebt' summary) (high x (deg div 2)) pr\ \pr < high z (deg div 2)\ abh leD not_le_imp_less pred_member) + have bbbb:"?h \ high z(deg div 2)" + by (simp add: \vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ z < x\ div_le_mono dual_order.strict_implies_order high_def) + hence "?h = high z (deg div 2)" + using aaaa eq_iff by blast + hence "vebt_member (treeList ! ?h) (low z (deg div 2))" + using aaa by linarith + hence "(low z (deg div 2)) < ?l" + by (metis \high x (deg div 2) = high z (deg div 2)\ \vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ z < x\ add_le_cancel_left div_mult_mod_eq high_def less_le low_def) + then show False + using "33" \vebt_member (treeList ! high x (deg div 2)) (low z (deg div 2))\ by blast + qed + hence "high z(deg div 2) \ pr" + using not_less by blast + then show " z \ res" + proof(cases "high z(deg div 2) = pr") + case True + hence "vebt_member (treeList ! (high z(deg div 2))) (low z (deg div 2))" + using abe by blast + have "low z (deg div 2) \ maxy" + using True \Some maxy = vebt_maxt (treeList ! pr)\ abc abe maxt_corr_help by auto + hence "z \ res" + by (metis True \res = 2 ^ (deg div 2) * pr + maxy\ add_le_cancel_left div_mult_mod_eq high_def low_def mult.commute) + then show ?thesis by simp + next + case False + hence "high z(deg div 2) < pr" + by (simp add: \high z (deg div 2) \ pr\ less_le) + then show ?thesis + by (metis \high res (deg div 2) = pr\ div_le_mono high_def leD linear) + qed + qed + qed + hence "is_pred_in_set (set_vebt' (Node (Some (mi, ma)) deg treeList summary)) x res" + using \vebt_member (Node (Some (mi, ma)) deg treeList summary) res\ \res < x\ pred_member by presburger + then show ?thesis using fst snd + by (metis \Some maxy = vebt_maxt (treeList ! the (vebt_pred summary (high x (deg div 2))))\ \vebt_pred summary (high x (deg div 2)) = Some pr\ \res = 2 ^ (deg div 2) * pr + maxy\ add_shift dual_order.eq_iff mul_shift pred_member) + qed + qed + next + case False + then show ?thesis + by (metis "4.hyps"(10) "4.hyps"(5) "4.hyps"(6) \1 \ n\ \deg div 2 = n\ \length treeList = 2 ^ n\ \x \ ma\ exp_split_high_low(1) le_less_trans le_neq_implies_less not_less not_less_zero zero_neq_one) + qed + qed +next + case (5 treeList n summary m deg mi ma) + hence "Suc n = m" and "deg = n + m" and "length treeList = 2^m \ invar_vebt summary m" + by blast + + hence "n \ 1" + using "5.hyps"(1) set_n_deg_not_0 by blast + hence "deg \ 2" + by (simp add: "5.hyps"(5) "5.hyps"(6)) + hence "deg div 2 =n" + by (simp add: "5.hyps"(5) "5.hyps"(6)) + moreover hence thisvalid:"invar_vebt (Node (Some (mi, ma)) deg treeList summary) deg" + using 5 invar_vebt.intros(5)[of treeList n summary m] by blast + ultimately have "deg div 2 =n" by simp + then show ?case + proof(cases "x > ma") + case True + hence 0: "vebt_pred (Node (Some (mi, ma)) deg treeList summary) x = Some ma" + by (simp add: \2 \ deg\ pred_max) + have 1:"ma = the (vebt_maxt (Node (Some (mi, ma)) deg treeList summary))" by simp + hence "ma \ set_vebt' (Node (Some (mi, ma)) deg treeList summary)" + by (metis VEBT_Member.vebt_member.simps(5) \2 \ deg\ add_numeral_left arith_simps(1) le_add_diff_inverse mem_Collect_eq numerals(1) plus_1_eq_Suc set_vebt'_def) + hence 2:"y \ set_vebt' (Node (Some (mi, ma)) deg treeList summary) \ y \ x" for y + using "5.hyps"(9) True member_inv set_vebt'_def by fastforce + hence 3: "y \ set_vebt' (Node (Some (mi, ma)) deg treeList summary) \ (y < ma \ y \ x)" for y by blast + hence 4: "\ y \ set_vebt' (Node (Some (mi, ma)) deg treeList summary). y < ma \ y \ x" by blast + hence "is_pred_in_set (set_vebt' (Node (Some (mi, ma)) deg treeList summary)) x ma" + by (metis "5.hyps"(9) True \ma \ set_vebt' (Node (Some (mi, ma)) deg treeList summary)\ less_or_eq_imp_le mem_Collect_eq member_inv pred_member set_vebt'_def) + then show ?thesis + by (metis "0" option.sel leD le_less_Suc_eq not_less_eq pred_member) + next + case False + hence "x \ ma"by simp + then show ?thesis + proof(cases "high x (deg div 2)< length treeList ") + case True + hence "high x n < 2^m \ low x n < 2^n" + by (simp add: \deg div 2 = n\ \length treeList = 2 ^ m\ low_def) + let ?l = "low x (deg div 2)" + let ?h = "high x (deg div 2)" + let ?minlow = "vebt_mint (treeList ! ?h)" + let ?pr = "vebt_pred summary ?h" + have 1:"vebt_pred (Node (Some (mi, ma)) deg treeList summary) x = + (if ?minlow \ None \ (Some ?l >\<^sub>o ?minlow) then + Some (2^(deg div 2)) *\<^sub>o Some ?h +\<^sub>o vebt_pred (treeList ! ?h) ?l + else let pr = vebt_pred summary ?h in + if pr = None then (if x > mi then Some mi else None) + else Some (2^(deg div 2)) *\<^sub>o pr +\<^sub>o vebt_maxt (treeList ! the pr) )" + by (smt True \2 \ deg\ \x \ ma\ pred_less_length_list) + then show ?thesis + proof(cases "?minlow \ None \ (Some ?l >\<^sub>o ?minlow)") + case True + then obtain minl where 00:"(Some minl = ?minlow) \ ?l > minl" by auto + have 01:"invar_vebt ((treeList ! ?h)) n \ (treeList ! ?h) \ set treeList " + by (metis "5.hyps"(1) \deg div 2 = n\ \high x n < 2 ^ m \ low x n < 2 ^ n\ \length treeList = 2 ^ m \ invar_vebt summary m\ inthall member_def) + have 02:"vebt_member ((treeList ! ?h)) minl" + using "00" "01" mint_member by auto + hence 03: "\ y. y < ?l \ vebt_member ((treeList ! ?h)) y" + using "00" by blast + hence afinite: "finite (set_vebt' (treeList ! ?h)) " + using "01" set_vebt_finite by blast + then obtain predy where 04:"is_pred_in_set (set_vebt' (treeList ! ?h)) ?l predy" + using "00" "01" mint_corr obtain_set_pred by fastforce + hence 05:"Some predy = vebt_pred (treeList ! ?h) ?l" using 5(1) 01 by force + hence "vebt_pred (Node (Some (mi, ma)) deg treeList summary) x = Some (2^(deg div 2)* ?h + predy) " + by (metis "1" True add_def mul_def option_shift.simps(3)) + hence 06: "predy \ set_vebt' (treeList ! ?h)" + using "04" is_pred_in_set_def by blast + hence 07: "predy < 2^(deg div 2) \ ?h < 2^(deg div 2 +1) \ deg div 2 + deg div 2 +1 = deg" + using "04" "5.hyps"(5) "5.hyps"(6) \high x n < 2 ^ m \ low x n < 2 ^ n\ pred_member by force + let ?y = "2^(deg div 2)* ?h + predy" + have 08: "vebt_member (treeList ! ?h) predy" + using "06" set_vebt'_def by auto + hence 09: "both_member_options (treeList ! ?h) predy" + using "01" both_member_options_equiv_member by blast + have 10: "high ?y (deg div 2) = ?h \ low ?y (deg div 2) = predy" + by (simp add: "07" high_inv low_inv mult.commute) + hence 14:"both_member_options (Node (Some (mi, ma)) deg treeList summary) ?y" + using "07" "09" "5.hyps"(4) \deg div 2 = n\ \high x n < 2 ^ m \ low x n < 2 ^ n\ both_member_options_from_chilf_to_complete_tree by auto + have 15: "vebt_member (Node (Some (mi, ma)) deg treeList summary) ?y" + using "14" thisvalid valid_member_both_member_options by blast + have 16: "Some ?y = vebt_pred (Node (Some (mi, ma)) deg treeList summary) x" + by (simp add: \vebt_pred (Node (Some (mi, ma)) deg treeList summary) x = Some (2 ^ (deg div 2) * high x (deg div 2) + predy)\) + have 17: "x = ?h * 2^(deg div 2) + ?l" + using bit_concat_def bit_split_inv by auto + have 18: "x - ?y = ?h * 2^(deg div 2) + ?l -?h * 2^(deg div 2) - predy " + by (metis "17" diff_diff_add mult.commute) + hence 19: "?y < x" + using "04" "17" mult.commute nat_add_left_cancel_less pred_member by fastforce + have 20: "z < x \ vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ z\ ?y " for z + proof- + assume "z < x" and "vebt_member (Node (Some (mi, ma)) deg treeList summary) z" + hence "high z (deg div 2) \ high x (deg div 2)" + by (simp add: div_le_mono high_def) + then show ?thesis + proof(cases "high z (deg div 2) = high x (deg div 2)") + case True + hence 0000: "high z (deg div 2) = high x (deg div 2)" by simp + then show ?thesis + proof(cases "z = mi") + case True + then show ?thesis + by (metis "15" "5.hyps"(9) add.left_neutral le_add2 less_imp_le_nat member_inv) + next + case False + hence ad:"vebt_member (treeList ! ?h) (low z (deg div 2))" + using vebt_member.simps(5)[of mi ma "deg-2" treeList summary z] + by (metis True \vebt_member (Node (Some (mi, ma)) deg treeList summary) z\ \x \ ma\ \z < x\ leD member_inv) + have "is_pred_in_set (set_vebt' (treeList ! ?h)) ?l predy" + using "04" by blast + have "low z (deg div 2) < ?l" + by (metis (full_types) True \z < x\ bit_concat_def bit_split_inv nat_add_left_cancel_less) + hence "predy \ low z (deg div 2)" using 04 ad unfolding is_pred_in_set_def + by (simp add: set_vebt'_def) + hence "?y \ z" + by (smt True bit_concat_def bit_split_inv diff_add_inverse diff_diff_add diff_is_0_eq mult.commute) + then show ?thesis by blast + qed + next + case False + hence "high z (deg div 2) < high ?y (deg div 2)" + using "10" \high z (deg div 2) \ high x (deg div 2)\ by linarith + then show ?thesis + by (metis div_le_mono high_def nat_le_linear not_le) + qed + qed + hence "is_pred_in_set (set_vebt'(Node (Some (mi, ma)) deg treeList summary)) x ?y" + by (simp add: "15" "19" pred_member) + then show ?thesis using 16 + by (metis eq_iff option.inject pred_member) + next + case False + hence i1:"?minlow = None \ \ (Some ?l >\<^sub>o ?minlow)" by simp + hence 2: "vebt_pred (Node (Some (mi, ma)) deg treeList summary) x = ( + if ?pr = None then (if x > mi + then Some mi + else None) + else Some (2^(deg div 2)) *\<^sub>o ?pr +\<^sub>o vebt_maxt (treeList ! the ?pr))" + using "1" by auto + have " invar_vebt (treeList ! ?h) n" + by (metis "5"(1) True inthall member_def) + hence 33:"\ u. vebt_member (treeList ! ?h) u \ u < ?l" + proof(cases "?minlow = None") + case True + then show ?thesis using mint_corr_help_empty[of "treeList ! ?h" n] + by (simp add: \invar_vebt (treeList ! high x (deg div 2)) n\ set_vebt'_def) + next + case False + obtain minilow where "?minlow =Some minilow" + using False by blast + hence "minilow \ ?l" + using "i1" by auto + then show ?thesis + by (meson \vebt_mint (treeList ! high x (deg div 2)) = Some minilow\ \invar_vebt (treeList ! high x (deg div 2)) n\ leD less_le_trans mint_corr_help) + qed + then show ?thesis + proof(cases "?pr= None") + case True + hence "vebt_pred (Node (Some (mi, ma)) deg treeList summary) x = (if x > mi then Some mi else None)" + by (simp add: "2") + hence "\ i. is_pred_in_set (set_vebt' summary) ?h i" + using "5.hyps"(3) True by force + hence "\ i. i < ?h \ vebt_member summary i " using pred_none_empty[of "set_vebt' summary" ?h] + proof - + { fix nn :: nat + have "\n. ((is_pred_in_set (Collect (vebt_member summary)) (high x (deg div 2)) esk1_0 \ infinite (Collect (vebt_member summary))) \ n \ Collect (vebt_member summary)) \ \ n < high x (deg div 2)" + using \\i. is_pred_in_set (set_vebt' summary) (high x (deg div 2)) i\ pred_none_empty set_vebt'_def by auto + then have "\ nn < high x (deg div 2) \ \ vebt_member summary nn" + by (metis (no_types) "5.hyps"(2) \\i. is_pred_in_set (set_vebt' summary) (high x (deg div 2)) i\ mem_Collect_eq set_vebt'_def set_vebt_finite) } + then show ?thesis + by blast + qed + then show ?thesis + proof(cases "x > mi") + case True + hence "vebt_pred (Node (Some (mi, ma)) deg treeList summary) x = Some mi" + by (simp add: \vebt_pred (Node (Some (mi, ma)) deg treeList summary) x = (if mi < x then Some mi else None)\) + have "(vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ z < x \ z > mi) \ False" for z + proof- + assume "vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ z < x \ z > mi" + hence "vebt_member ( treeList ! (high z (deg div 2))) (low z (deg div 2))" + using \x \ ma\ member_inv not_le by blast + moreover hence "high z (deg div 2) < 2^m" + using "5.hyps"(4) \vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ z < x \ mi < z\ \x \ ma\ member_inv by fastforce + moreover hence "invar_vebt (treeList ! (high z (deg div 2))) n" using 5(1) + by (simp add: "5.hyps"(4)) + ultimately have "vebt_member summary (high z (deg div 2))" using 5(7) + using "5.hyps"(2) both_member_options_equiv_member by blast + have "(high z (deg div 2)) \ ?h" + by (simp add: \vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ z < x \ mi < z\ div_le_mono high_def less_or_eq_imp_le) + then show False + by (metis "33" \\ (\i \vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ z < x \ mi < z\ \vebt_member (treeList ! high z (deg div 2)) (low z (deg div 2))\ \vebt_member summary (high z (deg div 2))\ bit_concat_def bit_split_inv le_neq_implies_less nat_add_left_cancel_less) + qed + hence "is_pred_in_set (set_vebt' ((Node (Some (mi, ma)) deg treeList summary))) x mi" + by (metis VEBT_Member.vebt_member.simps(5) True \2 \ deg\ add_2_eq_Suc le_add_diff_inverse le_less_linear pred_member) + then show ?thesis + by (metis \vebt_pred (Node (Some (mi, ma)) deg treeList summary) x = Some mi\ \x \ ma\ option.sel leD member_inv pred_member) + next + case False + hence "vebt_pred (Node (Some (mi, ma)) deg treeList summary) x = None" + by (simp add: "2" True) + then show ?thesis + by (metis (full_types) False less_trans member_inv option.distinct(1) pred_max pred_member) + qed + next + case False + hence fst:"vebt_pred (Node (Some (mi, ma)) deg treeList summary) x = + Some (2^(deg div 2)) *\<^sub>o ?pr +\<^sub>o vebt_maxt (treeList ! the ?pr)" + using "2" by presburger + obtain pr where "?pr = Some pr" + using False by blast + hence "is_pred_in_set (set_vebt' summary) ?h pr" + using "5.hyps"(3) by blast + hence "vebt_member summary pr" + using pred_member by blast + hence "both_member_options summary pr" + using "5.hyps"(2) both_member_options_equiv_member by auto + hence "pr < 2^m" + using "5.hyps"(2) \vebt_member summary pr\ member_bound by blast + hence "\ maxy. both_member_options (treeList ! pr) maxy" + using "5.hyps"(7) \both_member_options summary pr\ by blast + hence fgh:"set_vebt' (treeList ! pr) \ {}" + by (metis "5.hyps"(1) "5.hyps"(4) Collect_empty_eq \pr < 2 ^ m\ nth_mem set_vebt'_def valid_member_both_member_options) + hence "invar_vebt (treeList ! the ?pr) n" + by (simp add: "5.hyps"(1) "5.hyps"(4) \pr < 2 ^ m\ \vebt_pred summary (high x (deg div 2)) = Some pr\) + then obtain maxy where "Some maxy = vebt_maxt (treeList ! pr)" + by (metis \vebt_pred summary (high x (deg div 2)) = Some pr\ fgh option.sel vebt_maxt.elims maxt_corr_help_empty) + hence "Some maxy = vebt_maxt (treeList ! the ?pr)" + by (simp add: \vebt_pred summary (high x (deg div 2)) = Some pr\) + hence "max_in_set (set_vebt' (treeList ! the ?pr)) maxy" + using \invar_vebt (treeList ! the (vebt_pred summary (high x (deg div 2)))) n\ maxt_corr by auto + hence scmem:"vebt_member (treeList ! the ?pr) maxy" + using \Some maxy = vebt_maxt (treeList ! the (vebt_pred summary (high x (deg div 2))))\ \invar_vebt (treeList ! the (vebt_pred summary (high x (deg div 2)))) n\ maxt_member by force + let ?res = "Some (2^(deg div 2)) *\<^sub>o ?pr +\<^sub>o vebt_maxt (treeList ! the ?pr)" + obtain res where snd: "res = the ?res" by blast + hence "res = 2^(deg div 2) * pr + maxy" + by (metis \Some maxy = vebt_maxt (treeList ! pr)\ \vebt_pred summary (high x (deg div 2)) = Some pr\ add_def option.sel mul_def option_shift.simps(3)) + have "high res (deg div 2) = pr" + by (metis \deg div 2 = n\ \res = 2 ^ (deg div 2) * pr + maxy\ \invar_vebt (treeList ! the ?pr) n\ high_inv member_bound mult.commute scmem) + hence "res < x" + by (metis \is_pred_in_set (set_vebt' summary) (high x (deg div 2)) pr\ div_le_mono high_def pred_member verit_comp_simplify1(3)) + have "both_member_options (treeList ! (high res (deg div 2))) (low res (deg div 2))" + by (metis \deg div 2 = n\ \high res (deg div 2) = pr\ \vebt_pred summary (high x (deg div 2)) = Some pr\ \res = 2 ^ (deg div 2) * pr + maxy\ \invar_vebt (treeList ! the (vebt_pred summary (high x (deg div 2)))) n\ both_member_options_equiv_member option.sel low_inv member_bound mult.commute scmem) + have "both_member_options (Node (Some (mi, ma)) deg treeList summary) res" + by (metis "5.hyps"(2) "5.hyps"(4) "5.hyps"(6) \1 \ n\ \both_member_options (treeList ! high res (deg div 2)) (low res (deg div 2))\ \high res (deg div 2) = pr\ \vebt_member summary pr\ both_member_options_from_chilf_to_complete_tree member_bound trans_le_add1) + hence "vebt_member (Node (Some (mi, ma)) deg treeList summary) res" + using thisvalid valid_member_both_member_options by auto + hence "res > mi" + by (metis "5.hyps"(11) \both_member_options (treeList ! high res (deg div 2)) (low res (deg div 2))\ \deg div 2 = n\ \high res (deg div 2) = pr\ \pr < 2 ^ m\ \res < x\ \x \ ma\ less_le_trans member_inv) + hence "res < ma" + using \res < x\ \x \ ma\ less_le_trans by blast + have "(vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ z < x) \ z \ res" for z + proof- + fix z + assume "vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ z < x" + hence 20: "z = mi \ z = ma \ (high z (deg div 2) < length treeList + \ vebt_member ( treeList ! (high z (deg div 2))) (low z (deg div 2)))" using + vebt_member.simps(5)[of mi ma "deg-2" treeList summary z] + using member_inv by blast + have "z \ ma" + using \vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ z < x\ \x \ ma\ leD by blast + hence "mi \ ma" + by (metis \mi < res\ \res < x\ \x \ ma\ leD less_trans) + hence "z < 2^deg" + using \vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ z < x\ member_bound thisvalid by blast + hence "(high z (deg div 2)) <2^m" + by (metis "5.hyps"(5) "5.hyps"(6) \1 \ n\ \deg div 2 = n\ exp_split_high_low(1) less_le_trans numeral_One zero_less_Suc zero_less_numeral) + hence abc:"invar_vebt (treeList ! (high z (deg div 2))) n" + by (simp add: "5.hyps"(1) "5.hyps"(4)) + then show "z \ res" + proof(cases "z = mi") + case True + then show ?thesis + using \mi < res\ by auto + next + case False + hence abe:"vebt_member( treeList ! (high z (deg div 2))) (low z (deg div 2))" + using "20" \z \ ma\ by blast + hence abh:"vebt_member summary (high z (deg div 2))" + using "5.hyps"(7) \high z (deg div 2) < 2 ^ m\ \length treeList = 2 ^ m \ invar_vebt summary m\ abc both_member_options_equiv_member by blast + have aaa:"(high z (deg div 2)) = (high x (deg div 2)) \ vebt_member (treeList ! ?h) (low z (deg div 2))" + using abe by auto + have "high z(deg div 2) > pr \ False" + proof- + assume "high z(deg div 2) > pr" + hence "vebt_member summary (high z(deg div 2))" + using abh by blast + have aaaa:"?h \ high z(deg div 2)" + by (meson \is_pred_in_set (set_vebt' summary) (high x (deg div 2)) pr\ \pr < high z (deg div 2)\ abh leD not_le_imp_less pred_member) + have bbbb:"?h \ high z(deg div 2)" + by (simp add: \vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ z < x\ div_le_mono dual_order.strict_implies_order high_def) + hence "?h = high z (deg div 2)" + using aaaa eq_iff by blast + hence "vebt_member (treeList ! ?h) (low z (deg div 2))" + using aaa by linarith + hence "(low z (deg div 2)) < ?l" + by (metis \high x (deg div 2) = high z (deg div 2)\ \vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ z < x\ add_le_cancel_left div_mult_mod_eq high_def less_le low_def) + then show False + using "33" \vebt_member (treeList ! high x (deg div 2)) (low z (deg div 2))\ by blast + qed + hence "high z(deg div 2) \ pr" + using not_less by blast + then show " z \ res" + proof(cases "high z(deg div 2) = pr") + case True + hence "vebt_member (treeList ! (high z(deg div 2))) (low z (deg div 2))" + using abe by blast + have "low z (deg div 2) \ maxy" + using True \Some maxy = vebt_maxt (treeList ! pr)\ abc abe maxt_corr_help by auto + hence "z \ res" + by (metis True \res = 2 ^ (deg div 2) * pr + maxy\ add_le_cancel_left div_mult_mod_eq high_def low_def mult.commute) + then show ?thesis by simp + next + case False + hence "high z(deg div 2) < pr" + by (simp add: \high z (deg div 2) \ pr\ less_le) + then show ?thesis + by (metis \high res (deg div 2) = pr\ div_le_mono high_def leD linear) + qed + qed + qed + hence "is_pred_in_set (set_vebt' (Node (Some (mi, ma)) deg treeList summary)) x res" + using \vebt_member (Node (Some (mi, ma)) deg treeList summary) res\ \res < x\ pred_member by presburger + then show ?thesis using fst snd + by (metis \Some maxy = vebt_maxt (treeList ! the (vebt_pred summary (high x (deg div 2))))\ \vebt_pred summary (high x (deg div 2)) = Some pr\ \res = 2 ^ (deg div 2) * pr + maxy\ add_shift dual_order.eq_iff mul_shift pred_member) + qed + qed + next + case False + then show ?thesis + by (metis "5.hyps"(10) "5.hyps"(4) "5.hyps"(5) "5.hyps"(6) \1 \ n\ \deg div 2 = n\ \x \ ma\ exp_split_high_low(1) le_0_eq le_less_trans verit_comp_simplify1(3) zero_less_Suc zero_neq_one) + qed + qed +qed + +corollary pred_empty: assumes "invar_vebt t n " + shows " (vebt_pred t x = None) = ({y. vebt_member t y \ y < x} = {})" +proof + show " vebt_pred t x = None \ {y. vebt_member t y \ x > y} = {}" + proof + show "vebt_pred t x = None \ {y. vebt_member t y \ x > y} \ {}" + proof- + assume "vebt_pred t x = None" + hence "\ y. is_pred_in_set (set_vebt' t) x y" + using assms pred_corr by force + moreover hence "is_pred_in_set (set_vebt' t) x y \ vebt_member t y \ x < y " for y by auto + ultimately show "{y. vebt_member t y \ x > y} \ {}" + using assms pred_none_empty set_vebt'_def set_vebt_finite by auto + qed + show " vebt_pred t x = None \ {} \ {y. vebt_member t y \ x > y}" by simp + qed + show " {y. vebt_member t y \ x > y} = {} \ vebt_pred t x = None" + proof- + assume "{y. vebt_member t y \ x > y} = {} " + hence "is_pred_in_set (set_vebt' t) x y \ False" for y + using pred_member by auto + thus "vebt_pred t x = None" + by (meson assms option_shift.elims pred_corr) + qed +qed + +theorem pred_correct: "invar_vebt t n \ vebt_pred t x = Some sx \is_pred_in_set (set_vebt t) x sx" + by (simp add: pred_corr set_vebt_set_vebt'_valid) + +lemma helpypredd:"invar_vebt t n \ vebt_pred t x = Some y \ y < 2^n" + using member_bound pred_corr pred_member by blast + +lemma "invar_vebt t n \ vebt_pred t x = Some y \ y < x" + by (simp add: pred_corr pred_member) + +end +end + diff --git a/thys/Van_Emde_Boas_Trees/VEBT_Space.thy b/thys/Van_Emde_Boas_Trees/VEBT_Space.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/VEBT_Space.thy @@ -0,0 +1,455 @@ +(*by Ammer*) +theory VEBT_Space imports VEBT_Definitions Complex_Main +begin + +section \Space Complexity and $buildup$ Time Consumption\ +subsection \Space Comlexity of valid van Emde Boas Trees\ +text \Space Complexity is linear in relation to universe sizes\ + +context VEBT_internal begin + +fun space:: "VEBT \ nat" where +"space (Leaf a b) = 3"| +"space (Node info deg treeList summary) = 5 + space summary + length treeList + foldr (\ a b. a+b) (map space treeList) 0" + +fun space':: "VEBT \ nat" where +"space' (Leaf a b) = 4"| +"space' (Node info deg treeList summary) = 6 + space' summary + foldr (\ a b. a+b) (map space' treeList) 0" + +text \Count in reals\ + +fun cnt:: "VEBT \ real" where +"cnt (Leaf a b) = 1"| +"cnt (Node info deg treeList summary) = 1 + cnt summary + foldr (\ a b. a+b) (map cnt treeList) 0" + +subsection \Auxiliary Lemmas for List Summation\ + +lemma list_every_elemnt_bound_sum_bound:"\ x \ set xs. f x \ bound \ foldr (\ a b. a+b) (map f xs) i \ length xs * bound + i" + by(induction xs) auto + +lemma list_every_elemnt_bound_sum_bound_real:"\ x \ set (xs::'a list). (f::'a\real) x \ (bound::real) \ foldr (\ a b. a+b) (map f xs) i \ real(length xs) * bound + i" + apply(induction xs) apply simp + apply (simp add: algebra_simps) + done + +lemma foldr_one: "d \ foldr (+) ys (d::nat)" + by (induction ys) auto + +lemma foldr_zero: "\ i < length xs. xs ! i > 0 \ + foldr (\ a b. a+b) xs (d::nat) - d \ length xs" +proof(induction xs) + case Nil + then show ?case by simp +next + case (Cons a xs) + hence "\i foldr (+) xs d - d" using Cons.IH by simp + have "a \ 1" + by (metis gr0_conv_Suc length_Cons less_one local.Cons(2) not_gr0 not_less nth_Cons_0) + then show ?case + by (metis Nat.add_diff_assoc \length xs \ foldr (+) xs d - d\ add_mono_thms_linordered_semiring(1) foldr.simps(2) foldr_one length_Cons o_apply plus_1_eq_Suc) +qed + +lemma foldr_mono: "length xs = length ys \\ i < length xs. xs ! i < ys ! i \ c \ d \ + foldr (\ a b. a+b) xs c + length ys \ foldr (\ a b. a+b) ys (d::nat)" +proof(induction xs arbitrary: d c ys) + case Nil + then show ?case using length_0_conv list.size(3) foldr_one by simp +next + case (Cons a xs) + then obtain y ys1 where "ys = y #ys1" + by (metis Suc_leI Suc_le_length_iff nth_equalityI) + hence 0:"length xs = length ys1" + using Cons.prems(1) by force + hence 1:"\iys = y # ys1\ by force + hence 3: "\i 0" + by (metis "0" less_nat_zero_code neq0_conv) + have "foldr (+) (a # xs)c = a +foldr (+) xs (c)" by simp + have "foldr (+) (ys) d = y +foldr (+) ys1 (d)" + by (simp add: \ys = y # ys1\) + have 2:"a < y" using Cons.prems(2) \ys = y # ys1\ + by (metis length_Cons nth_Cons_0 zero_less_Suc) + have 4:"foldr (+) xs c \ foldr (+) ys1 d - length ys1" + using Cons.IH[of ys1 c d] 0 1 Cons.prems(3) by simp + have "foldr (+) ys1 d \ length ys1"using foldr_zero[of ys1 d] 3 by simp + hence "a + foldr (+) xs c < y + foldr (+) ys1 d - length ys1 " using 2 foldr_zero[of ys1 d] 4 by simp + then show ?case + using \ys = y # ys1\ by auto +qed + +lemma two_realpow_ge_two :"(n::real)\ 1 \ (2::real)^n \ 2" + by (metis less_one not_less of_nat_1 of_nat_le_iff of_nat_numeral power_increasing power_one_right zero_neq_numeral) + +lemma foldr0: "foldr (+) xs (c+d) = foldr (+) xs (d::real) + c" + by(induction xs) auto + +lemma f_g_map_foldr_bound:" (\ x \ set xs. f x \ c * g x) + \ foldr (\ a b. a+b) (map f xs) d \ c * foldr (\ a b. a+b) (map g xs) (0::real) + d" + by(induction xs) (auto simp add: algebra_simps) + +lemma real_nat_list: "real (foldr (+) ( map f xs) (c::nat)) + = foldr (+) (map (\ x. real(f x))xs) c" + by(induction xs arbitrary: c) auto + +subsection \Actual Space Reasoning\ + +lemma space_space': "space' t > space t" +proof(induction t) + case (Node info deg treeList summary) + hence "\ i < length treeList . (map space treeList)!i < ( map space' treeList)!i" + by simp + hence 0:"foldr (+) (map space treeList) 0 + length treeList \ foldr (+) (map space' treeList) 0 " + using foldr_mono[of "(map space treeList)" "(map space' treeList)" 0 0] by simp + have 1:"space summary < space' summary" using Node by simp + hence "foldr (+) (map space treeList) 0 + length treeList + space summary \ + foldr (+) (map space' treeList) 0 + space' summary" using 0 by simp + then show ?case using space'.simps(2)[of info deg treeList summary] + space.simps(2)[of info deg treeList summary] by simp +qed simp + +lemma cnt_bound: + defines "c \ 1.5" + shows "invar_vebt t n \ cnt t \ 2*((2^n - c)::real)" +proof(induction t n rule: invar_vebt.induct) +case (2 treeList n summary m deg) + hence "\t\set treeList. (cnt t) \ 2 * (2 ^ n - c)" by simp + hence " foldr (\ a b. a+b) (map cnt treeList) 0 \ 2^n*2 * ((2^n - c)::real)" + using list_every_elemnt_bound_sum_bound_real[of treeList cnt "2*((2^n - c)::real)" 0 ] 2 + by (auto simp add: algebra_simps) + hence "cnt ( Node None deg treeList summary) \ 2*(2^n+1)*(2^n-c) + 1" using 2 + by(auto simp add: algebra_simps) + hence "cnt ( Node None deg treeList summary) \ 2*(2^(n+n) + (1-c)*2^n - c + 1/2)" + by(auto simp add: algebra_simps power_add) + moreover have "2*(2^(n+n) + (1-c)*2^n - c + 1/2) \ 2*(2^(n+n) + -0.5*1 - 1.5 + 1/2)" + by(auto simp add: algebra_simps two_realpow_ge_one c_def) + moreover hence "2*(2^(n+n) + (1-c)*2^n - c + 1/2) \ 2*(2^(n+n) - 1.5 )" + by(auto simp add: algebra_simps power_add) + ultimately have "cnt ( Node None deg treeList summary) \ 2*(2^(n+n) - 1.5 )" by simp + then show ?case using c_def 2(5) 2(6) by simp +next + case (3 treeList n summary m deg) + hence "\t\set treeList. (cnt t) \ 2 * (2 ^ n - c)" by simp + hence " foldr (\ a b. a+b) (map cnt treeList) 0 \ 2^(n+1)*2 * ((2^n - c)::real)" + using list_every_elemnt_bound_sum_bound_real[of treeList cnt "2*((2^n - c)::real)" 0 ] 3 + by (auto simp add: algebra_simps) + moreover + hence "cnt ( Node None deg treeList summary) \ 2*(2^n*2^m - c* 2^(m) + 2^(m) - c + 1/2)" + using 3 + by (auto simp add: algebra_simps powr_add) + moreover have "2*(2^n*2^m - c* 2^(m) + 2^(m) - c + 1/2) = 2*(2^(n+m) + (1-c)* 2^(m) - c + 1/2)" + by (auto simp add: algebra_simps power_add) + moreover have " 2*(2^(n+m) + (1-c)* 2^(m) - c + 1/2) \ 2*(2^(n+m) + -0.5*1 - 1.5 + 1/2)" + by(auto simp add: algebra_simps two_realpow_ge_one c_def) + moreover hence "2*(2^(n+m) + (1-c)*2^m - c + 1/2) \ 2*(2^(n+m) - 1.5 )" + by(auto simp add: algebra_simps power_add) + ultimately have "cnt ( Node None deg treeList summary) \ 2*(2^(n+m) - 1.5 )" by simp + then show ?case using c_def 3(5) 3(6) by simp +next + case (4 treeList n summary m deg mi ma) +hence "\t\set treeList. (cnt t) \ 2 * (2 ^ n - c)" by simp + hence " foldr (\ a b. a+b) (map cnt treeList) 0 \ 2^n*2 * ((2^n - c)::real)" + using list_every_elemnt_bound_sum_bound_real[of treeList cnt "2*((2^n - c)::real)" 0 ] 4 + by (auto simp add: algebra_simps) + hence "cnt ( Node (Some (mi, ma)) deg treeList summary) \ 2*(2^n+1)*(2^n-c) + 1" using 4 + by(auto simp add: algebra_simps) + hence "cnt ( Node None deg treeList summary) \ 2*(2^(n+n) + (1-c)*2^n - c + 1/2)" + by(auto simp add: algebra_simps power_add) + moreover have "2*(2^(n+n) + (1-c)*2^n - c + 1/2) \ 2*(2^(n+n) + -0.5*1 - 1.5 + 1/2)" + by(auto simp add: algebra_simps two_realpow_ge_one c_def) + moreover hence "2*(2^(n+n) + (1-c)*2^n - c + 1/2) \ 2*(2^(n+n) - 1.5 )" + by(auto simp add: algebra_simps power_add) + ultimately have "cnt ( Node None deg treeList summary) \ 2*(2^(n+n) - 1.5 )" by simp + then show ?case using c_def 4 by simp +next + case (5 treeList n summary m deg mi ma) + hence "\t\set treeList. (cnt t) \ 2 * (2 ^ n - c)" by simp + hence " foldr (\ a b. a+b) (map cnt treeList) 0 \ 2^(n+1)*2 * ((2^n - c)::real)" + using list_every_elemnt_bound_sum_bound_real[of treeList cnt "2*((2^n - c)::real)" 0 ] 5 + by (auto simp add: algebra_simps) + moreover + hence "cnt ( Node (Some (mi, ma)) deg treeList summary) \ 2*(2^n*2^m - c* 2^(m) + 2^(m) - c + 1/2)" + using 5 + by (auto simp add: algebra_simps powr_add) + moreover have "2*(2^n*2^m - c* 2^(m) + 2^(m) - c + 1/2) = 2*(2^(n+m) + (1-c)* 2^(m) - c + 1/2)" + by (auto simp add: algebra_simps power_add) + moreover have " 2*(2^(n+m) + (1-c)* 2^(m) - c + 1/2) \ 2*(2^(n+m) + -0.5*1 - 1.5 + 1/2)" + by(auto simp add: algebra_simps two_realpow_ge_one c_def) + moreover hence "2*(2^(n+m) + (1-c)*2^m - c + 1/2) \ 2*(2^(n+m) - 1.5 )" + by(auto simp add: algebra_simps power_add) + ultimately have "cnt ( Node None deg treeList summary) \ 2*(2^(n+m) - 1.5 )" by simp + then show ?case using c_def 5 by simp +qed (simp add: cnt.simps c_def) + +theorem cnt_bound': "invar_vebt t n \ cnt t \ 2 * (2 ^ n - 1)" + using cnt_bound by fastforce + +lemma space_cnt: "space' t \ 6*cnt t" +proof(induction t) + case (Node info deg treeList summary) + hence " \t\set treeList. space' t \ 6 * cnt t" by blast + hence " foldr (\ a b. a+b) (map space' treeList) 0 \ + 6 *foldr (\ a b. a+b) (map cnt treeList) 0" + using f_g_map_foldr_bound[of treeList space' 6 cnt 0] + by(auto simp add: algebra_simps real_nat_list) +then show ?case + using Node.IH(2) by force +qed simp + +lemma space_2_pow_bound: assumes "invar_vebt t n " shows "real (space' t) \ 12 * (2^n -1)" +proof- + have "space' t \ 6 * cnt t" + using space_cnt[of t] assms by simp + moreover have "6 * cnt t \ 12 * (2^n -1)" + using cnt_bound'[of t n] assms by simp + ultimately show ?thesis by linarith +qed + +lemma space'_bound: assumes "invar_vebt t n" "u = 2^n" + shows "space' t \ 12 * u" + using space_2_pow_bound[of t n] +proof - +have "real u - 1 = real (u - 1)" +by (simp add: assms(2) of_nat_diff) +then show ?thesis + using \invar_vebt t n \ real (space' t) \ 12 * (2 ^ n - 1)\ assms(1) assms(2) by auto +qed + +text \Main Theorem\ + +theorem space_bound: assumes "invar_vebt t n" "u = 2^n" + shows "space t \ 12 * u" + by (metis assms(1) assms(2) dual_order.trans less_imp_le_nat space'_bound space_space') + +subsection \Complexity of Generation Time \ +text \Space complexity is closely related to tree generation time complexity\ + +text \Time approximation for replicate function. $T_{replicate} \; n \; t \;x$ denotes runnig time of the $n$-times replication of $x$ into a list. +$t$ models runtime for generation of a single $x$.\ + +fun T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d\<^sub>u\<^sub>p::"nat \ nat" where +"T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d\<^sub>u\<^sub>p 0 = 3"| +"T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d\<^sub>u\<^sub>p (Suc 0) = 3"| +"T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d\<^sub>u\<^sub>p n = (if even n then 1 + (let half = n div 2 in + 9 + T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d\<^sub>u\<^sub>p half + (2^half) * (T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d\<^sub>u\<^sub>p half + 1)) + else (let half = n div 2 in + 11 + T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d\<^sub>u\<^sub>p (Suc half) + (2^(Suc half))* (T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d\<^sub>u\<^sub>p half + 1 )))" + +fun T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d::"nat \ nat" where +"T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d 0 = 4"| +"T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d (Suc 0) = 4"| +"T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d n = (if even n then 1 + (let half = n div 2 in + 10 + T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d half + (2^half) * (T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d half)) + else (let half = n div 2 in + 12 + T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d (Suc half) + (2^(Suc half))* (T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d half)))" + +lemma buildup_build_time: "T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d\<^sub>u\<^sub>p n < T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d n" +proof(induction n rule: T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d\<^sub>u\<^sub>p.induct) + case (3 va) + then show ?case + proof(cases "even (Suc (Suc va))") + case True + then show ?thesis + apply(subst T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d\<^sub>u\<^sub>p.simps) + apply(subst T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d.simps) + using True apply simp + by (smt (z3) "3.IH"(1) Suc_1 True add_mono_thms_linordered_semiring(1) distrib_left div2_Suc_Suc less_mult_imp_div_less linorder_not_le mult.commute mult_numeral_1_right nat_0_less_mult_iff nat_less_le nat_zero_less_power_iff nonzero_mult_div_cancel_left not_less_eq numerals(1) plus_1_eq_Suc zero_le_one) + next + case False + hence *: "(let half = Suc (Suc va) div 2 + in 11 + T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d\<^sub>u\<^sub>p (Suc half) + 2 ^ Suc half * (T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d\<^sub>u\<^sub>p half + 1)) + < (let half = Suc (Suc va) div 2 + in 12 + T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d (Suc half) + 2 ^ Suc half * T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d half)" + unfolding Let_def + proof- + assume "odd (Suc (Suc va))" + have " 11 + T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d\<^sub>u\<^sub>p (Suc (Suc (Suc va) div 2)) + < 12 + T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d (Suc (Suc (Suc va) div 2))" + using "3.IH"(3) False add_less_mono by presburger + moreover have " 2 ^ Suc (Suc (Suc va) div 2) * (T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d\<^sub>u\<^sub>p (Suc (Suc va) div 2) + 1) + \ 2 ^ Suc (Suc (Suc va) div 2) * T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d (Suc (Suc va) div 2)" + by (metis "3.IH"(4) False Suc_leI add.commute mult_le_mono2 plus_1_eq_Suc) + ultimately show " 11 + T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d\<^sub>u\<^sub>p (Suc (Suc (Suc va) div 2)) + + 2 ^ Suc (Suc (Suc va) div 2) * (T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d\<^sub>u\<^sub>p (Suc (Suc va) div 2) + 1) + < 12 + T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d (Suc (Suc (Suc va) div 2)) + + 2 ^ Suc (Suc (Suc va) div 2) * T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d (Suc (Suc va) div 2)" + using add_mono_thms_linordered_field(3) by blast + qed + show ?thesis apply(subst T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d\<^sub>u\<^sub>p.simps) + apply(subst T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d.simps) + using False * + by simp + qed +qed simp+ + + +lemma listsum_bound: "(\ x. x \ set xs \ f x \ (0::real)) \ + foldr (+) (map f xs) y \ y" + apply(induction xs arbitrary: y) + apply simp + apply(subst list.map(2)) + apply(subst foldr.simps) + apply (simp add: add_increasing) + done + +lemma cnt_non_neg: "cnt t \ 0" + by (induction t) (simp add: VEBT_internal.listsum_bound)+ + +lemma foldr_same: "(\ x y. x \ set (xs::real list) \ y \ set xs \ x = y) \ + (\ x . (x::real) \ set xs \ x = (y::real)) \ + foldr (\ (a::real) (b::real). a+b) xs 0 = real (length xs) * y" + apply(induction xs) + apply simp + apply(subst foldr.simps) + unfolding comp_def +proof - + fix a :: real and xsa :: "real list" + assume a1: "\\x y. \x \ set xsa; y \ set xsa\ \ x = y; \x. x \ set xsa \ x = y\ \ foldr (+) xsa 0 = real (length xsa) * y" + assume "\x y. \x \ set (a # xsa); y \ set (a # xsa)\ \ x = y" +assume a2: "\x. x \ set (a # xsa) \ x = y" + then have f3: "a = y" + by simp + then have "a * real (length xsa) = foldr (+) xsa 0" + using a2 a1 by (metis (no_types) list.set_intros(2) mult.commute) + then show "a + foldr (+) xsa 0 = real (length (a # xsa)) * y" + using f3 by (simp add: distrib_left mult.commute) +qed + +lemma foldr_same_int: "(\ x y. x \ set xs \ y \ set xs \ x = y) \ + (\ x . x \ set xs \ x = y) \ + foldr (+) xs 0 = (length xs) * y" + apply(induction xs) + apply simp + apply(subst foldr.simps) + apply fastforce + done + +lemma t_build_cnt: "T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d n \ cnt (vebt_buildup n) * 13" +proof(induction n rule: T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d.induct) + case 1 + then show ?case by simp +next + case 2 + then show ?case by simp +next + case (3 va) + then show ?case + proof(cases "even (Suc (Suc va))") + case True + hence *: "T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d (Suc (Suc va)) = 11+ + T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d (Suc (Suc va) div 2) + + 2 ^ (Suc (Suc va) div 2) * (T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d (Suc (Suc va) div 2))" + apply(subst T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d.simps) + by simp + have " real (T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d (Suc (va div 2))) \ 13 * cnt (vebt_buildup (Suc (va div 2)))" + using "3.IH"(1) True by force + moreover hence 1:" 2 ^ (Suc (Suc va) div 2)* (T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d (Suc (Suc va) div 2)) \ + 2 ^ (Suc (Suc va) div 2) * ((cnt (vebt_buildup (Suc (Suc va) div 2)))*13)" + using ordered_semiring_class.mult_mono[of "(T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d (Suc (Suc va) div 2))" " ((cnt (vebt_buildup (Suc (Suc va) div 2)))*13)" + "2 ^ (Suc (Suc va) div 2)" "2 ^ (Suc (Suc va) div 2)"] by simp + ultimately have " T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d (Suc (Suc va) div 2) + + 2 ^ (Suc (Suc va) div 2) * (T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d (Suc (Suc va) div 2)) \ + cnt (vebt_buildup (Suc (Suc va) div 2))*13 + + 2 ^ (Suc (Suc va) div 2) * ((cnt (vebt_buildup (Suc (Suc va) div 2)))*13)" + by (smt (verit) "3.IH"(1) True of_nat_add) + have 10: "(foldr (+) + (replicate (l) ((cnt (vebt_buildup (Suc (Suc va) div 2))) + )) 0) = + l * ((cnt (vebt_buildup (Suc (Suc va) div 2))))" for l + using foldr_same[of "(replicate l (cnt (vebt_buildup (Suc (Suc va) div 2))))" + "cnt (vebt_buildup (Suc (Suc va) div 2))" ] + length_replicate by simp + have " cnt (vebt_buildup (Suc (Suc va) div 2))*13 + + 2 ^ (Suc (Suc va) div 2) * ((cnt (vebt_buildup (Suc (Suc va) div 2)))*13) + 11\ + 13* cnt (vebt_buildup (Suc (Suc va)))" + apply(subst vebt_buildup.simps) + using True apply simp + apply(subst sym[OF foldr_replicate]) + proof- + assume "even va" + have " 2* (2 ^ (va div 2) * cnt (vebt_buildup (Suc (va div 2)))) = + foldr (+) (replicate (2 * 2 ^ (va div 2)) (cnt (vebt_buildup (Suc (va div 2))))) 0" + apply(rule sym) + using 10 div2_Suc_Suc[of va] by simp + then show "26 * (2 ^ (va div 2) * cnt (vebt_buildup (Suc (va div 2)))) + \ 2 + 13 * foldr (+) (replicate (2 * 2 ^ (va div 2)) (cnt (vebt_buildup (Suc (va div 2))))) 0" + by simp + qed + then show ?thesis + by (smt (verit, ccfv_SIG) "*" "1" "3.IH"(1) True numeral_Bit1 numeral_plus_numeral numeral_plus_one of_nat_add of_nat_numeral semiring_norm(2)) + next + case False + have "12 + T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d (Suc ( Suc (va div 2))) + 2 ^ Suc ( Suc ( va div 2)) * T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d ( Suc ( va div 2)) + \ cnt ( Node None (Suc (Suc va)) (replicate (2 ^ Suc ( Suc ( va div 2))) (vebt_buildup ( Suc ( va div 2)))) + (vebt_buildup (Suc ( Suc ( va div 2))))) * 13" + apply(subst cnt.simps) + proof- + have 10: "(foldr (+) + (replicate (l) ((cnt (vebt_buildup (Suc (Suc va) div 2))) + )) 0) = + l * ((cnt (vebt_buildup (Suc (Suc va) div 2))))" for l + using foldr_same[of "(replicate l (cnt (vebt_buildup (Suc (Suc va) div 2))))" + "cnt (vebt_buildup (Suc (Suc va) div 2))" ] + length_replicate by simp + hence map_cnt: " foldr (+) (map cnt (replicate (2 ^ Suc (Suc (va div 2))) (vebt_buildup (Suc (va div 2))))) 0 = + 2 ^ Suc (Suc (va div 2)) * cnt (vebt_buildup (Suc (va div 2))) " by simp + have "T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d (Suc (Suc (va div 2))) \ 13 * cnt (vebt_buildup (Suc (Suc (va div 2))))" + using "3.IH"(3) False by force + moreover have "T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d (Suc (va div 2)) \ 13 * cnt(vebt_buildup (Suc (va div 2)))" + using "3.IH"(4) False by force + moreover have add_double_trans: "(a::real) \ b \ c \ d \ + i \ 0\ a + c*i \ b + d*i" for a b c d i + using mult_right_mono by fastforce + ultimately have " real(T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d (Suc (Suc (va div 2)))) + 2 ^ Suc (Suc (va div 2)) * real( T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d (Suc (va div 2))) \ + 13 * cnt (vebt_buildup (Suc (Suc (va div 2)))) + + 2 ^ Suc (Suc (va div 2)) * (13 * cnt(vebt_buildup (Suc (va div 2))))" + by (meson add_mono_thms_linordered_semiring(1) mult_mono of_nat_0_le_iff order_refl zero_le_numeral zero_le_power) + hence 11:"(12 + T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d (Suc (Suc (va div 2))) + 2 ^ Suc (Suc (va div 2)) * T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d (Suc (va div 2))) \ + 12 + 13 * cnt (vebt_buildup (Suc (Suc (va div 2)))) + + 2 ^ Suc (Suc (va div 2)) * 13 * cnt(vebt_buildup (Suc (va div 2)))" + using algebra_simps by simp + show " (12 + T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d (Suc (Suc (va div 2))) + + 2 ^ Suc (Suc (va div 2)) * T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d (Suc (va div 2))) + \ (1 + cnt (vebt_buildup (Suc (Suc (va div 2)))) + + foldr (+) (map cnt (replicate (2 ^ Suc (Suc (va div 2))) (vebt_buildup (Suc (va div 2))))) 0) * 13" + apply(subst map_cnt) + using 11 algebra_simps by simp + qed + then show ?thesis + apply(subst vebt_buildup.simps) + apply(subst T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d.simps) + using False by force +qed +qed + +lemma t_buildup_cnt: "T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d\<^sub>u\<^sub>p n \ cnt (vebt_buildup n) * 13" + apply(rule order.trans[where b = "real(T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d n)"]) + apply(rule order.strict_implies_order) + apply (simp add: VEBT_internal.buildup_build_time) + apply(rule t_build_cnt) + done + +lemma count_buildup: "cnt (vebt_buildup n) \ 2 * 2^n" + by (smt (verit, ccfv_threshold) VEBT_internal.cnt_bound' add.right_neutral add_less_mono buildup_gives_valid cnt.simps(1) even_Suc lessI odd_pos one_le_power plus_1_eq_Suc vebt_buildup.elims) + +lemma count_buildup': "cnt (vebt_buildup n) \ 2 * (2::nat)^n" + by (simp add: VEBT_internal.count_buildup) + +theorem vebt_buildup_bound: "u = 2^n \ T\<^sub>b\<^sub>u\<^sub>i\<^sub>l\<^sub>d\<^sub>u\<^sub>p n \ 26 * u" + using count_buildup'[of n] t_buildup_cnt[of n] by linarith + +text \Count in natural numbers\ + +fun cnt':: "VEBT \ nat" where +"cnt' (Leaf a b) = 1"| +"cnt' (Node info deg treeList summary) = 1 + cnt' summary + foldr (\ a b. a+b) (map cnt' treeList) 0" + +lemma cnt_cnt_eq:"cnt t = cnt' t" + apply(induction t) + apply auto + apply (smt (z3) VEBT_internal.real_nat_list map_eq_conv of_nat_0) + done + +end +end \ No newline at end of file diff --git a/thys/Van_Emde_Boas_Trees/VEBT_Succ.thy b/thys/Van_Emde_Boas_Trees/VEBT_Succ.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/VEBT_Succ.thy @@ -0,0 +1,893 @@ +(*by Ammer*) +theory VEBT_Succ imports VEBT_Insert VEBT_MinMax +begin + +section \The Successor Operation\ + +definition is_succ_in_set :: "nat set \ nat \ nat \ bool" where + "is_succ_in_set xs x y = (y \ xs \ y > x \ (\ z \ xs. (z > x \ z \ y)))" + +context VEBT_internal begin + +corollary succ_member: "is_succ_in_set (set_vebt' t) x y = (vebt_member t y \ y > x \ (\ z. vebt_member t z \ z > x \ z \ y))" + using is_succ_in_set_def set_vebt'_def by auto + +subsection \Auxiliary Lemmas on Sets and Successorship\ + +lemma "finite (A:: nat set) \ A \ {}\ Min A \ A" + by(induction A rule: finite.induct)(blast | meson Min_in finite_insert)+ + +lemma obtain_set_succ: assumes "(x::nat) < z " and "max_in_set A z" and "finite B" and "A=B" shows "\ y. is_succ_in_set A x y" +proof- + have "{y \ A. y > x} \ {}" + using assms(1) assms(2) max_in_set_def by auto + have "Min {y \ A. y > x} \ {y \ A. y > x}" + by (metis (full_types) Collect_mem_eq \{y \ A. x < y} \ {}\ assms(3) assms(4) eq_Min_iff finite_Collect_conjI) + have "i \ A\ i > x \ i \ Min {y \ A. y > x} " for i + by (simp add: assms(3) assms(4)) + have "is_succ_in_set A x (Min {y \ A. y > x})" + using is_succ_in_set_def \Min {y \ A. x < y} \ {y \ A. x < y}\ \\i. \i \ A; x < i\ \ Min {y \ A. x < y} \ i\ by blast + then show?thesis by auto +qed + +lemma succ_none_empty: assumes "(\ x. is_succ_in_set (xs) a x)" and "finite xs"shows "\ (\ x \ xs. ord_class.greater x a)" +proof- + have "\ x \ xs. ord_class.greater x a \ False" + proof- + assume "\ x \ xs. ord_class.greater x a" + hence "{x \ xs. ord_class.greater x a} \ {}" by auto + have "Min {y \ xs. y > a} \ {y \ xs. y > a}" + by (metis (full_types) Collect_mem_eq Min_in \{x \ xs. a < x} \ {}\ assms(2) finite_Collect_conjI) + have "i \ xs \ ord_class.greater i a\ + ord_class.greater_eq i (Min {y \ xs. ord_class.greater y a}) " for i + by (simp add: assms(2)) + have "is_succ_in_set xs a (Min {y \ xs. y > a})" + using is_succ_in_set_def \Min {y \ xs. a < y} \ {y \ xs. a < y}\ \\i. \i \ xs; a < i\ \ Min {y \ xs. a < y} \ i\ by blast + then show False + using assms(1) by blast + qed + then show ?thesis by blast +qed + +end + +subsection \The actual Function\ + +context begin + interpretation VEBT_internal . + +fun vebt_succ :: "VEBT \ nat \ nat option" where + "vebt_succ (Leaf _ b) 0 = (if b then Some 1 else None)"| + "vebt_succ (Leaf _ _) (Suc n) = None"| + "vebt_succ (Node None _ _ _) _ = None"| + "vebt_succ (Node _ 0 _ _) _ = None"| + "vebt_succ (Node _ (Suc 0) _ _) _ = None"| + "vebt_succ (Node (Some (mi, ma)) deg treeList summary) x = ( + if x < mi then (Some mi) + else (let l = low x (deg div 2); h = high x (deg div 2) in + if h < length treeList then + let maxlow = vebt_maxt (treeList ! h) in ( + if maxlow \ None \ (Some l <\<^sub>o maxlow) then + Some (2^(deg div 2)) *\<^sub>o Some h +\<^sub>o vebt_succ (treeList ! h) l + else let sc = vebt_succ summary h in + if sc = None then None + else Some (2^(deg div 2)) *\<^sub>o sc +\<^sub>o vebt_mint (treeList ! the sc) ) + else None))" + +end + +subsection \Lemmas for Term Decomposition\ +context VEBT_internal begin + +lemma succ_min: assumes "deg \ 2" and "(x::nat) < mi" shows + "vebt_succ (Node (Some (mi, ma)) deg treeList summary) x = Some mi" + by (metis add_2_eq_Suc assms(1) assms(2) le_add_diff_inverse vebt_succ.simps(6)) + +lemma succ_greatereq_min: assumes "deg \ 2" and "(x::nat) \ mi" shows + "vebt_succ (Node (Some (mi, ma)) deg treeList summary) x = (let l = low x (deg div 2); h = high x (deg div 2) in + if h < length treeList then + + let maxlow = vebt_maxt (treeList ! h) in + (if maxlow \ None \ (Some l <\<^sub>o maxlow) then + Some (2^(deg div 2)) *\<^sub>o Some h +\<^sub>o vebt_succ (treeList ! h) l + else let sc = vebt_succ summary h in + if sc = None then None + else Some (2^(deg div 2)) *\<^sub>o sc +\<^sub>o vebt_mint (treeList ! the sc) ) + + else None)" + by (smt add_numeral_left arith_simps(1) assms(1) assms(2) le_add_diff_inverse not_less numerals(1) plus_1_eq_Suc vebt_succ.simps(6)) + +lemma succ_list_to_short: assumes "deg \ 2" and "x \ mi" and " high x (deg div 2) \ length treeList" shows + "vebt_succ (Node (Some (mi, ma)) deg treeList summary) x = None" + using assms(1) assms(2) assms(3) succ_greatereq_min by auto + +lemma succ_less_length_list: assumes "deg \ 2" and "x \ mi" and " high x (deg div 2) < length treeList" shows + "vebt_succ (Node (Some (mi, ma)) deg treeList summary) x = + (let l = low x (deg div 2); h = high x (deg div 2) ; maxlow = vebt_maxt (treeList ! h) in + (if maxlow \ None \ (Some l <\<^sub>o maxlow) then + Some (2^(deg div 2)) *\<^sub>o Some h +\<^sub>o vebt_succ (treeList ! h) l + else let sc = vebt_succ summary h in + if sc = None then None + else Some (2^(deg div 2)) *\<^sub>o sc +\<^sub>o vebt_mint (treeList !the sc)))" + by (simp add: assms(1) assms(2) assms(3) succ_greatereq_min) + +subsection \Correctness Proof\ + +theorem succ_corr: "invar_vebt t n \ vebt_succ t x = Some sx == is_succ_in_set (set_vebt' t) x sx" +proof(induction t n arbitrary: x sx rule: invar_vebt.induct) + case (1 a b) + then show ?case proof(cases x) + case 0 + then show ?thesis + by (simp add: succ_member) + next + case (Suc nat) + then show ?thesis proof(cases nat) + case 0 + then show ?thesis + by (simp add: Suc succ_member) + next + case (Suc nat) + then show ?thesis by (metis (no_types) VEBT_Member.vebt_member.simps(1) Suc_eq_plus1 add_cancel_right_left le_add2 le_imp_less_Suc not_add_less2 not_less0 old.nat.exhaust option.distinct(1) option.simps(1) vebt_succ.simps(1) vebt_succ.simps(2) succ_member) + qed + qed +next + case (2 treeList n summary m deg) + then show ?case + by (simp add: succ_member) +next + case (3 treeList n summary m deg) + then show ?case + by (simp add: succ_member) +next + case (4 treeList n summary m deg mi ma) + hence "n = m" and "n \ 1" and "deg \ 2" and "deg = n + m" + apply blast+ + using "4.hyps"(2) "4.hyps"(5) Suc_le_eq deg_not_0 apply auto[1] + using "4.hyps"(2) "4.hyps"(5) "4.hyps"(6) deg_not_0 apply fastforce + by (simp add: "4.hyps"(6)) + hence "deg div 2 =n" and "length treeList = 2^n" + using add_self_div_2 apply blast by (simp add: "4.hyps"(4) "4.hyps"(5)) + then show ?case proof(cases "x < mi") + case True + hence 0: "vebt_succ (Node (Some (mi, ma)) deg treeList summary) x = Some mi" + by (simp add: \2 \ deg\ succ_min) + have 1:"mi = the (vebt_mint (Node (Some (mi, ma)) deg treeList summary))" by simp + hence "mi \ set_vebt' (Node (Some (mi, ma)) deg treeList summary)" + by (metis VEBT_Member.vebt_member.simps(5) \2 \ deg\ add_numeral_left arith_simps(1) le_add_diff_inverse mem_Collect_eq numerals(1) plus_1_eq_Suc set_vebt'_def) + hence 2:"y \ set_vebt' (Node (Some (mi, ma)) deg treeList summary) \ y \ x" for y + using "4.hyps"(9) True member_inv set_vebt'_def by fastforce + hence 3: "y \ set_vebt' (Node (Some (mi, ma)) deg treeList summary) \ (y > mi \ y \ x)" for y by blast + hence 4: "\ y \ set_vebt' (Node (Some (mi, ma)) deg treeList summary). y > mi \ y \ x" by blast + hence "is_succ_in_set (set_vebt' (Node (Some (mi, ma)) deg treeList summary)) x mi" + by (metis (mono_tags, lifting) "4.hyps"(9) True \mi \ set_vebt' (Node (Some (mi, ma)) deg treeList summary)\ eq_iff less_imp_le_nat mem_Collect_eq member_inv succ_member set_vebt'_def) + then show ?thesis using 0 + by (metis is_succ_in_set_def antisym_conv option.inject) + next + case False + hence "x \ mi"by simp + then show ?thesis + proof(cases "high x (deg div 2)< length treeList ") + case True + hence "high x n < 2^n \ low x n < 2^n" + by (simp add: \deg div 2 = n\ \length treeList = 2 ^ n\ low_def) + let ?l = "low x (deg div 2)" + let ?h = "high x (deg div 2)" + let ?maxlow = "vebt_maxt (treeList ! ?h)" + let ?sc = "vebt_succ summary ?h" + have 1:"vebt_succ (Node (Some (mi, ma)) deg treeList summary) x = + (if ?maxlow \ None \ (Some ?l <\<^sub>o ?maxlow) then + Some (2^(deg div 2)) *\<^sub>o Some ?h +\<^sub>o vebt_succ (treeList ! ?h) ?l + else if ?sc = None then None + else Some (2^(deg div 2)) *\<^sub>o ?sc +\<^sub>o vebt_mint (treeList ! the ?sc))" + by (smt True \2 \ deg\ \mi \ x\ succ_less_length_list) + then show ?thesis + proof(cases "?maxlow \ None \ (Some ?l <\<^sub>o ?maxlow)") + case True + then obtain maxl where 00:"Some maxl = ?maxlow \ ?l < maxl" by auto + have 01:"invar_vebt ((treeList ! ?h)) n \ (treeList ! ?h) \ set treeList " + by (simp add: "4.hyps"(1) \deg div 2 = n\ \high x n < 2 ^ n \ low x n < 2 ^ n\ \length treeList = 2 ^ n\) + have 02:"vebt_member ((treeList ! ?h)) maxl" + using "00" "01" maxt_member by auto + hence 03: "\ y. y > ?l \ vebt_member ((treeList ! ?h)) y" + using "00" by blast + hence afinite: "finite (set_vebt' (treeList ! ?h)) " + using "01" set_vebt_finite by blast + then obtain succy where 04:"is_succ_in_set (set_vebt' (treeList ! ?h)) ?l succy" + using "00" "01" maxt_corr obtain_set_succ by fastforce + hence 05:"Some succy = vebt_succ (treeList ! ?h) ?l" using 4(1) 01 by force + hence "vebt_succ (Node (Some (mi, ma)) deg treeList summary) x = Some (2^(deg div 2)* ?h + succy) " + by (metis "1" True add_def mul_def option_shift.simps(3)) + hence 06: "succy \ set_vebt' (treeList ! ?h)" + using "04" is_succ_in_set_def by blast + hence 07: "succy < 2^(deg div 2) \ ?h < 2^(deg div 2) \ deg div 2 + deg div 2 = deg" + using "01" "04" "4.hyps"(5) "4.hyps"(6) \high x n < 2 ^ n \ low x n < 2 ^ n\ member_bound succ_member by auto + let ?y = "2^(deg div 2)* ?h + succy" + have 08: "vebt_member (treeList ! ?h) succy" + using "06" set_vebt'_def by auto + hence 09: "both_member_options (treeList ! ?h) succy" + using "01" both_member_options_equiv_member by blast + have 10: "high ?y (deg div 2) = ?h \ low ?y (deg div 2) = succy" + by (simp add: "07" high_inv low_inv mult.commute) + hence 11: "naive_member (treeList ! ?h) succy + \ naive_member (Node (Some (mi, ma)) deg treeList summary) ?y" + using naive_member.simps(3)[of "Some (mi, ma)" "deg-1" treeList summary ?y] + by (metis "07" "4.hyps"(4) "4.hyps"(5) One_nat_def Suc_pred \2 \ deg\ \deg div 2 = n\ add_gr_0 div_greater_zero_iff zero_less_numeral) + have 12: "?y \ mi \ ?y \ ma" + by (metis "01" "07" "09" "10" "4.hyps"(11) "4.hyps"(5) "4.hyps"(8) \deg div 2 = n\ less_imp_le_nat) + hence 13: "membermima (treeList ! ?h) succy + \ membermima (Node (Some (mi, ma)) deg treeList summary) ?y" + using membermima.simps(4)[of mi ma "deg -1" treeList summary ?y] + apply(cases "?y = mi \ ?y = ma") + apply (metis "07" One_nat_def Suc_pred \2 \ deg\ add_gr_0 div_greater_zero_iff zero_less_numeral) + by (metis "07" "10" "4.hyps"(4) "4.hyps"(5) One_nat_def Suc_pred \2 \ deg\ \deg div 2 = n\ add_gr_0 div_greater_zero_iff zero_less_numeral) + hence 14:"both_member_options (Node (Some (mi, ma)) deg treeList summary) ?y" + using "09" "11" both_member_options_def by blast + have 15: "vebt_member (Node (Some (mi, ma)) deg treeList summary) ?y" + by (smt "07" "08" "10" "12" "4.hyps"(4) "4.hyps"(5) VEBT_Member.vebt_member.simps(5) One_nat_def Suc_1 Suc_le_eq Suc_pred \2 \ deg\ \deg div 2 = n\ add_gr_0 div_greater_zero_iff not_less zero_less_numeral) + have 16: "Some ?y = vebt_succ (Node (Some (mi, ma)) deg treeList summary) x" + by (simp add: \vebt_succ (Node (Some (mi, ma)) deg treeList summary) x = Some (2 ^ (deg div 2) * high x (deg div 2) + succy)\) + have 17: "x = ?h * 2^(deg div 2) + ?l" + using bit_concat_def bit_split_inv by auto + have 18: "?y - x = ?h * 2^(deg div 2) + succy - ?h * 2^(deg div 2) - ?l " + by (metis "17" diff_diff_add mult.commute) + hence "?y -x > 0" + using "04" is_succ_in_set_def by auto + hence 19: "?y > x" + using zero_less_diff by blast + have 20: "z > x \ vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ z\ ?y " for z + proof- + assume "z > x" and "vebt_member (Node (Some (mi, ma)) deg treeList summary) z" + hence "high z (deg div 2) \ high x (deg div 2)" + by (simp add: div_le_mono high_def) + then show ?thesis proof(cases "high z (deg div 2) = high x (deg div 2)") + case True + hence "vebt_member (treeList ! ?h) (low z (deg div 2))" + using vebt_member.simps(5)[of mi ma "deg-2" treeList summary z] + by (metis "01" "07" "4.hyps"(11) "4.hyps"(5) False \deg div 2 = n\ \vebt_member (Node (Some (mi, ma)) deg treeList summary) z\ \x < z\ both_member_options_equiv_member member_inv) + hence "succy \ low z (deg div 2)" using 04 unfolding is_succ_in_set_def + by (metis True \x < z\ add_diff_cancel_left' bit_concat_def bit_split_inv diff_diff_left mem_Collect_eq set_vebt'_def zero_less_diff) + hence "?y \ z" + by (smt True bit_concat_def bit_split_inv diff_add_inverse diff_diff_add diff_is_0_eq mult.commute) + then show ?thesis by blast + next + case False + hence "high z (deg div 2) > high ?y (deg div 2)" + using "10" \high x (deg div 2) \ high z (deg div 2)\ by linarith + then show ?thesis + by (metis div_le_mono high_def nat_le_linear not_le) + qed + qed + hence "is_succ_in_set (set_vebt' (Node (Some (mi, ma)) deg treeList summary)) x ?y" + by (simp add: "15" "19" succ_member) + then show ?thesis using 16 + by (metis eq_iff option.inject succ_member) + next + case False + hence i1:"?maxlow = None \ \ (Some ?l <\<^sub>o ?maxlow)" by simp + hence 2: "vebt_succ (Node (Some (mi, ma)) deg treeList summary) x = (if ?sc = None then None + else Some (2^(deg div 2)) *\<^sub>o ?sc +\<^sub>o vebt_mint (treeList ! the ?sc))" + using "1" by auto + have " invar_vebt (treeList ! ?h) n" + by (metis "4"(1) True inthall member_def) + hence 33:"\ u. vebt_member (treeList ! ?h) u \ u > ?l" + proof(cases "?maxlow = None") + case True + then show ?thesis using maxt_corr_help_empty[of "treeList ! ?h" n] + by (simp add: \invar_vebt (treeList ! high x (deg div 2)) n\ set_vebt'_def) + next + case False + obtain maxilow where "?maxlow =Some maxilow" + using False by blast + hence "maxilow \ ?l" + using "i1" by auto + then show ?thesis + by (meson \vebt_maxt (treeList ! high x (deg div 2)) = Some maxilow\ \invar_vebt (treeList ! high x (deg div 2)) n\ le_imp_less_Suc le_less_trans maxt_corr_help not_less_eq) + qed + then show ?thesis + proof(cases " ?sc = None") + case True + hence "vebt_succ (Node (Some (mi, ma)) deg treeList summary) x = None" + by (simp add: "2") + hence "\ i. is_succ_in_set (set_vebt' summary) ?h i" + using "4.hyps"(3) True by force + hence "\ i. i > ?h \ vebt_member summary i " using succ_none_empty[of "set_vebt' summary" ?h] + proof - + { fix nn :: nat + have "\n. ((is_succ_in_set (Collect (vebt_member summary)) (high x (deg div 2)) esk1_0 \ infinite (Collect (vebt_member summary))) \ n \ Collect (vebt_member summary)) \ \ high x (deg div 2) < n" + using \\i. is_succ_in_set (set_vebt' summary) (high x (deg div 2)) i\ succ_none_empty set_vebt'_def by auto + then have "\ high x (deg div 2) < nn \ \ vebt_member summary nn" + using "4.hyps"(2) \\i. is_succ_in_set (set_vebt' summary) (high x (deg div 2)) i\ set_vebt'_def set_vebt_finite by auto } + then show ?thesis + by blast + qed + hence "(i > x \ vebt_member (Node (Some (mi, ma)) deg treeList summary) i) \ False" for i + proof- + fix i + assume "i > x \ vebt_member (Node (Some (mi, ma)) deg treeList summary) i" + hence 20: "i = mi \ i = ma \ (high i (deg div 2) < length treeList + \ vebt_member ( treeList ! (high i (deg div 2))) (low i (deg div 2)))" using + vebt_member.simps(5)[of mi ma "deg-2" treeList summary i] + using member_inv by blast + have "i \ mi" + using \mi \ x\ \x < i \ vebt_member (Node (Some (mi, ma)) deg treeList summary) i\ not_le by blast + hence "mi \ ma" + using \x < i \ vebt_member (Node (Some (mi, ma)) deg treeList summary) i\ member_inv not_less_iff_gr_or_eq by blast + hence "i < 2^deg" + using "4.hyps"(10) \i \ mi\ \x < i \ vebt_member (Node (Some (mi, ma)) deg treeList summary) i\ member_inv by fastforce + hence aa:"i = ma \ both_member_options( treeList ! (high i (deg div 2))) (low i (deg div 2))" + using "4.hyps"(11) "4.hyps"(2) "4.hyps"(5) "4.hyps"(6) \mi \ ma\ deg_not_0 exp_split_high_low(1) by auto + hence abc:"invar_vebt (treeList ! (high i (deg div 2))) n" + by (metis "4.hyps"(1) "4.hyps"(2) "4.hyps"(5) "4.hyps"(6) \deg div 2 = n\ \i < 2 ^ deg\ \length treeList = 2 ^ n\ deg_not_0 exp_split_high_low(1) in_set_member inthall) + hence abd:"i = ma \ vebt_member( treeList ! (high i (deg div 2))) (low i (deg div 2))" + using aa valid_member_both_member_options by blast + hence abe:"vebt_member( treeList ! (high i (deg div 2))) (low i (deg div 2))" + using "20" \i \ mi\ by blast + hence abf:"both_member_options( treeList ! (high i (deg div 2))) (low i (deg div 2))" + using \invar_vebt (treeList ! high i (deg div 2)) n\ both_member_options_equiv_member by blast + hence abg:"both_member_options summary (high i (deg div 2))" + by (metis "20" "4.hyps"(10) "4.hyps"(2) "4.hyps"(4) "4.hyps"(6) "4.hyps"(7) \2 \ deg\ \deg div 2 = n\ \i \ mi\ deg_not_0 div_greater_zero_iff exp_split_high_low(1) zero_less_numeral) + hence abh:"vebt_member summary (high i (deg div 2))" + using "4.hyps"(2) valid_member_both_member_options by blast + have aaa:"(high i (deg div 2)) = (high x (deg div 2)) \ vebt_member (treeList ! ?h) (low i (deg div 2))" + using \vebt_member (treeList ! high i (deg div 2)) (low i (deg div 2))\ by auto + have abi:"(high i (deg div 2)) = (high x (deg div 2)) \ low i (deg div 2) > ?l" + by (metis \x < i \ vebt_member (Node (Some (mi, ma)) deg treeList summary) i\ add_le_cancel_left bit_concat_def bit_split_inv le_neq_implies_less less_imp_le_nat nat_neq_iff) + hence abj:"(high i (deg div 2)) = (high x (deg div 2)) \ False" using 33 aaa by blast + hence abk:" (high i (deg div 2)) \ (set_vebt' summary) \ (high i (deg div 2)) > (high x (deg div 2)) " + by (metis (full_types) \vebt_member summary (high i (deg div 2))\ \x < i \ vebt_member (Node (Some (mi, ma)) deg treeList summary) i\ div_le_mono high_def le_less mem_Collect_eq set_vebt'_def) + then show ?thesis + using \\ (\i>high x (deg div 2). vebt_member summary i)\ abh by blast + qed + then show ?thesis + using \vebt_succ (Node (Some (mi, ma)) deg treeList summary) x = None\ succ_member by auto + next + case False + hence "vebt_succ (Node (Some (mi, ma)) deg treeList summary) x = + Some (2^(deg div 2)) *\<^sub>o ?sc +\<^sub>o vebt_mint (treeList ! the ?sc)" + by (simp add: False "2") + obtain sc where "?sc = Some sc" + using False by blast + hence "is_succ_in_set (set_vebt' summary) ?h sc" + using "4.hyps"(3) by blast + hence "vebt_member summary sc" + using succ_member by blast + hence "both_member_options summary sc" + using "4.hyps"(2) both_member_options_equiv_member by auto + hence "sc < 2^m" + using "4.hyps"(2) \vebt_member summary sc\ member_bound by blast + hence "\ miny. both_member_options (treeList ! sc) miny" + using "4.hyps"(7) \both_member_options summary sc\ by blast + hence fgh:"set_vebt' (treeList ! sc) \ {}" + by (metis "4.hyps"(1) "4.hyps"(4) "4.hyps"(5) Collect_empty_eq_bot \deg div 2 = n\ \sc < 2 ^ m\ bot_empty_eq empty_iff nth_mem set_vebt'_def valid_member_both_member_options) + hence "invar_vebt (treeList ! the ?sc) n" + by (simp add: "4.hyps"(1) "4.hyps"(4) \sc < 2 ^ m\ \vebt_succ summary (high x (deg div 2)) = Some sc\) + then obtain miny where "Some miny = vebt_mint (treeList ! sc)" + by (metis fgh Collect_empty_eq VEBT_Member.vebt_member.simps(2) vebt_buildup.simps(2) buildup_gives_empty vebt_mint.elims set_vebt'_def) + hence "Some miny = vebt_mint (treeList ! the ?sc)" + by (simp add: \vebt_succ summary (high x (deg div 2)) = Some sc\) + hence "min_in_set (set_vebt' (treeList ! the ?sc)) miny" + using \invar_vebt (treeList ! the (vebt_succ summary (high x (deg div 2)))) n\ mint_corr by auto + hence scmem:"vebt_member (treeList ! the ?sc) miny" + using \Some miny = vebt_mint (treeList ! the (vebt_succ summary (high x (deg div 2))))\ \invar_vebt (treeList ! the(vebt_succ summary (high x (deg div 2)))) n\ mint_member by auto + let ?res = "Some (2^(deg div 2)) *\<^sub>o ?sc +\<^sub>o vebt_mint (treeList !the ?sc)" + obtain res where "res = the ?res" by blast + hence "res = 2^(deg div 2) * sc + miny" + by (metis \Some miny = vebt_mint (treeList ! the (vebt_succ summary (high x (deg div 2))))\ \vebt_succ summary (high x (deg div 2)) = Some sc\ add_def mul_def option.sel option_shift.simps(3)) + have "high res (deg div 2) = sc" + by (metis \deg div 2 = n\ \res = 2 ^ (deg div 2) * sc + miny\ \invar_vebt (treeList ! the ?sc) n\ high_inv member_bound mult.commute scmem) + hence "res > x" + by (metis is_succ_in_set_def \is_succ_in_set (set_vebt' summary) (high x (deg div 2)) sc\ div_le_mono high_def not_le) + hence "res > mi" + using \mi \ x\ le_less_trans by blast + hence "res \ ma" + proof(cases "high res n < high ma n") + case True + then show ?thesis + by (metis div_le_mono high_def leD nat_le_linear) + next + case False + hence "mi \ ma" + by (metis "4.hyps"(5) "4.hyps"(8) \\miny. both_member_options (treeList ! sc) miny\ \length treeList = 2 ^ n\ \sc < 2 ^ m\ nth_mem) + have "high res n < 2^m" + using \deg div 2 = n\ \high res (deg div 2) = sc\ \sc < 2 ^ m\ by blast + hence " (\x. high x n = high res n \ both_member_options (treeList ! (high res n)) (low x n) \ mi < x \ x \ ma)" using 4(11) + using \mi \ ma\ by blast + have "high res n = high res n \ both_member_options (treeList ! (high res n)) (low res n)" + by (metis \deg div 2 = n\ \high res (deg div 2) = sc\ \res = 2 ^ (deg div 2) * sc + miny\ \vebt_succ summary (high x (deg div 2)) = Some sc\ \invar_vebt (treeList ! the (vebt_succ summary (high x (deg div 2)))) n\ both_member_options_equiv_member low_inv member_bound mult.commute option.sel scmem) + then show ?thesis + using \\x. high x n = high res n \ both_member_options (treeList ! high res n) (low x n) \ mi < x \ x \ ma\ by blast + qed + hence "vebt_member (Node (Some (mi, ma)) deg treeList summary) (the ?res)" using vebt_member.simps(5)[of mi ma "deg-2" treeList summary res] + by (metis "4.hyps"(4) \2 \ deg\ \deg div 2 = n\ \high res (deg div 2) = sc\ \mi < res\ \res = 2 ^ (deg div 2) * sc + miny\ \res = the (Some (2 ^ (deg div 2)) *\<^sub>o vebt_succ summary (high x (deg div 2)) +\<^sub>o vebt_mint (treeList ! the (vebt_succ summary (high x (deg div 2)))))\ \sc < 2 ^ m\ \vebt_succ summary (high x (deg div 2)) = Some sc\ \invar_vebt (treeList ! the (vebt_succ summary (high x (deg div 2)))) n\ add_2_eq_Suc leD le_add_diff_inverse low_inv member_bound mult.commute not_less_iff_gr_or_eq option.sel scmem) + have "(vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ z > x) \ z \ res" for z + proof- + fix z + assume "vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ z > x" + hence 20: "z = mi \ z = ma \ (high z (deg div 2) < length treeList + \ vebt_member ( treeList ! (high z (deg div 2))) (low z (deg div 2)))" using + vebt_member.simps(5)[of mi ma "deg-2" treeList summary z] + using member_inv by blast + have "z \ mi" + using \vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ x < z\ \mi \ x\ not_le by blast + hence "mi \ ma" + using \mi < res\ \res \ ma\ not_le by blast + hence "z < 2^deg" + using "4.hyps"(10) \vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ x < z\ \z \ mi\ member_inv by fastforce + hence aa:"z = ma \ both_member_options( treeList ! (high z (deg div 2))) (low z (deg div 2))" + using "4.hyps"(11) "4.hyps"(2) "4.hyps"(5) "4.hyps"(6) \mi \ ma\ deg_not_0 exp_split_high_low(1) by auto + hence abc:"invar_vebt (treeList ! (high z (deg div 2))) n" + by (metis "4.hyps"(1) "4.hyps"(2) "4.hyps"(5) "4.hyps"(6) \deg div 2 = n\ \z < 2 ^ deg\ \length treeList = 2 ^ n\ deg_not_0 exp_split_high_low(1) in_set_member inthall) + hence abd:"z = ma \ vebt_member( treeList ! (high z (deg div 2))) (low z (deg div 2))" + using aa valid_member_both_member_options by blast + hence abe:"vebt_member( treeList ! (high z (deg div 2))) (low z (deg div 2))" + using "20" \z \ mi\ by blast + hence abf:"both_member_options( treeList ! (high z (deg div 2))) (low z (deg div 2))" + using \invar_vebt (treeList ! high z (deg div 2)) n\ both_member_options_equiv_member by blast + hence abg:"both_member_options summary (high z (deg div 2))" + by (metis (full_types) "4.hyps"(5) "4.hyps"(6) "4.hyps"(7) \deg div 2 = n\ \invar_vebt (treeList ! the (vebt_succ summary (high x (deg div 2)))) n\ \z < 2 ^ deg\ deg_not_0 exp_split_high_low(1)) + hence abh:"vebt_member summary (high z (deg div 2))" + using "4.hyps"(2) valid_member_both_member_options by blast + have aaa:"(high z (deg div 2)) = (high x (deg div 2)) \ vebt_member (treeList ! ?h) (low z (deg div 2))" + using abe by auto + have "high z(deg div 2)< sc \ False" + proof- + assume "high z(deg div 2)< sc" + hence "vebt_member summary (high z(deg div 2))" + using abh by blast + have aaaa:"?h \ high z(deg div 2)" + by (simp add: \vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ x < z\ div_le_mono high_def less_imp_le_nat) + have bbbb:"?h \ high z(deg div 2)" + using \is_succ_in_set (set_vebt' summary) (high x (deg div 2)) sc\ \high z (deg div 2) < sc\ abh leD succ_member by auto + hence "?h = high z (deg div 2)" + using aaaa eq_iff by blast + hence "vebt_member (treeList ! ?h) (low z (deg div 2))" + using aaa by linarith + then show False + by (metis "33" \high x (deg div 2) = high z (deg div 2)\ \vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ x < z\ add_diff_cancel_left' bit_concat_def bit_split_inv diff_diff_left zero_less_diff) + qed + hence "high z(deg div 2) \ sc" + using not_less by blast + then show " z \ res" + proof(cases "high z(deg div 2) = sc") + case True + hence "vebt_member (treeList ! (high z(deg div 2))) (low z (deg div 2))" + using abe by blast + have "low z (deg div 2) \ miny" + using True \min_in_set (set_vebt' (treeList ! the (vebt_succ summary (high x (deg div 2))))) miny\ \vebt_succ summary (high x (deg div 2)) = Some sc\ abe min_in_set_def set_vebt'_def by auto + hence "z \ res" + by (metis (full_types) True \res = 2 ^ (deg div 2) * sc + miny\ add_le_cancel_left bit_concat_def bit_split_inv mult.commute) + then show ?thesis by simp + next + case False + hence "high z(deg div 2) > sc" + using \sc \ high z (deg div 2)\ le_less by blast + then show ?thesis + by (metis \high res (deg div 2) = sc\ div_le_mono high_def leD linear) + qed + qed + hence "is_succ_in_set (set_vebt' (Node (Some (mi, ma)) deg treeList summary)) x res" + using \vebt_member (Node (Some (mi, ma)) deg treeList summary) (the (Some (2 ^ (deg div 2)) *\<^sub>o vebt_succ summary ?h +\<^sub>o vebt_mint (treeList ! the (vebt_succ summary ?h))))\ + \res = the (Some (2 ^ (deg div 2)) *\<^sub>o vebt_succ summary ?h +\<^sub>o vebt_mint (treeList ! the (vebt_succ summary ?h)))\ \x < res\ succ_member by blast + moreover have "Some res = Some (2^(deg div 2)) *\<^sub>o ?sc +\<^sub>o vebt_mint (treeList ! the ?sc)" + by (metis \Some miny = vebt_mint (treeList !the (vebt_succ summary (high x (deg div 2))))\ \res = 2 ^ (deg div 2) * sc + miny\ \vebt_succ summary (high x (deg div 2)) = Some sc\ add_def mul_def option_shift.simps(3)) + ultimately show ?thesis + by (metis (mono_tags) is_succ_in_set_def \vebt_succ (Node (Some (mi, ma)) deg treeList summary) x = Some (2 ^ (deg div 2)) *\<^sub>o vebt_succ summary ?h +\<^sub>o vebt_mint (treeList ! the (vebt_succ summary ?h))\ eq_iff option.inject) + qed + qed + next + case False + hence 0:"vebt_succ (Node (Some (mi, ma)) deg treeList summary) x = None" + by (simp add: \2 \ deg\ \mi \ x\ succ_greatereq_min) + have 1:"x \ 2^deg" + by (metis "4.hyps"(4) "4.hyps"(5) "4.hyps"(6) False \deg div 2 = n\ high_def le_less_linear less_mult_imp_div_less mult_2 power2_eq_square power_even_eq) + hence "x \ set_vebt' (Node (Some (mi, ma)) deg treeList summary)" + using "4.hyps"(10) "4.hyps"(9) member_inv set_vebt'_def by fastforce + hence "\ ss. is_succ_in_set (set_vebt' (Node (Some (mi, ma)) deg treeList summary)) x ss" + using "4.hyps"(10) 1 \mi \ x\ member_inv succ_member by fastforce + then show ?thesis using 0 by auto + qed + qed +next + case (5 treeList n summary m deg mi ma) + hence "Suc n = m" and "deg = n + m" and "length treeList = 2^m \ invar_vebt summary m" + by blast + + hence "n \ 1" + using "5.hyps"(1) set_n_deg_not_0 by blast + hence "deg \ 2" + by (simp add: "5.hyps"(5) "5.hyps"(6)) + hence "deg div 2 =n" + by (simp add: "5.hyps"(5) "5.hyps"(6)) + then show ?case proof(cases "x < mi") + case True + hence 0: "vebt_succ (Node (Some (mi, ma)) deg treeList summary) x = Some mi" + by (simp add: \2 \ deg\ succ_min) + have 1:"mi = the (vebt_mint (Node (Some (mi, ma)) deg treeList summary))" by simp + hence "mi \ set_vebt' (Node (Some (mi, ma)) deg treeList summary)" + by (metis VEBT_Member.vebt_member.simps(5) \2 \ deg\ add_numeral_left arith_simps(1) le_add_diff_inverse mem_Collect_eq numerals(1) plus_1_eq_Suc set_vebt'_def) + hence 2:"y \ set_vebt' (Node (Some (mi, ma)) deg treeList summary) \ y \ x" for y + using "5.hyps"(9) True member_inv set_vebt'_def by fastforce + hence 3: "y \ set_vebt' (Node (Some (mi, ma)) deg treeList summary) \ (y > mi \ y \ x)" for y by blast + hence 4: "\ y \ set_vebt' (Node (Some (mi, ma)) deg treeList summary). y > mi \ y \ x" by blast + hence "is_succ_in_set (set_vebt' (Node (Some (mi, ma)) deg treeList summary)) x mi" + by (metis (mono_tags, lifting) "5.hyps"(9) True \mi \ set_vebt' (Node (Some (mi, ma)) deg treeList summary)\ eq_iff less_imp_le_nat mem_Collect_eq member_inv succ_member set_vebt'_def) + then show ?thesis using 0 + by (metis is_succ_in_set_def antisym_conv option.inject) + next + case False + hence "x \ mi"by simp + then show ?thesis + proof(cases "high x (deg div 2)< length treeList ") + case True + hence "high x n < 2^m \ low x n < 2^n" + by (simp add: "5.hyps"(4) \deg div 2 = n\ low_def) + let ?l = "low x (deg div 2)" + let ?h = "high x (deg div 2)" + let ?maxlow = "vebt_maxt (treeList ! ?h)" + let ?sc = "vebt_succ summary ?h" + have 1:"vebt_succ (Node (Some (mi, ma)) deg treeList summary) x = + (if ?maxlow \ None \ (Some ?l <\<^sub>o ?maxlow) then + Some (2^(deg div 2)) *\<^sub>o Some ?h +\<^sub>o vebt_succ (treeList ! ?h) ?l + else if ?sc = None then None + else Some (2^(deg div 2)) *\<^sub>o ?sc +\<^sub>o vebt_mint (treeList ! the ?sc))" + by (smt True \2 \ deg\ \mi \ x\ succ_less_length_list) + then show ?thesis + proof(cases "?maxlow \ None \ (Some ?l <\<^sub>o ?maxlow)") + case True + then obtain maxl where 00:"Some maxl = ?maxlow \ ?l < maxl" by auto + have 01:"invar_vebt ((treeList ! ?h)) n \ (treeList ! ?h) \ set treeList " + by (metis (full_types) "5.hyps"(1) "5.hyps"(4) \deg div 2 = n\ \high x n < 2 ^ m \ low x n < 2 ^ n\ inthall member_def) + have 02:"vebt_member ((treeList ! ?h)) maxl" + using "00" "01" maxt_member by auto + hence 03: "\ y. y > ?l \ vebt_member ((treeList ! ?h)) y" + using "00" by blast + hence afinite: "finite (set_vebt' (treeList ! ?h)) " + using "01" set_vebt_finite by blast + then obtain succy where 04:"is_succ_in_set (set_vebt' (treeList ! ?h)) ?l succy" + using "00" "01" maxt_corr obtain_set_succ by fastforce + hence 05:"Some succy = vebt_succ (treeList ! ?h) ?l" using 5(1) 01 by force + hence "vebt_succ (Node (Some (mi, ma)) deg treeList summary) x = Some (2^(deg div 2)* ?h + succy) " + by (metis "1" True add_def mul_def option_shift.simps(3)) + hence 06: "succy \ set_vebt' (treeList ! ?h)" + using "04" is_succ_in_set_def by blast + hence 07: "succy < 2^(deg div 2) \ ?h < 2^m \ Suc (deg div 2 + deg div 2 ) = deg" + using "01" "04" "5.hyps"(5) "5.hyps"(6) \high x n < 2 ^ m \ low x n < 2 ^ n\ member_bound succ_member by auto + let ?y = "2^(deg div 2)* ?h + succy" + have 08: "vebt_member (treeList ! ?h) succy" + using "06" set_vebt'_def by auto + hence 09: "both_member_options (treeList ! ?h) succy" + using "01" both_member_options_equiv_member by blast + have 10: "high ?y (deg div 2) = ?h \ low ?y (deg div 2) = succy" + by (simp add: "07" high_inv low_inv mult.commute) + hence 11: "naive_member (treeList ! ?h) succy + \ naive_member (Node (Some (mi, ma)) deg treeList summary) ?y" + using naive_member.simps(3)[of "Some (mi, ma)" "deg-1" treeList summary ?y] + using "07" "5.hyps"(4) by auto + have 12: "?y \ mi \ ?y \ ma" + by (metis "01" "07" "09" "10" "5.hyps"(11) "5.hyps"(5) "5.hyps"(8) \deg div 2 = n\ less_imp_le_nat) + hence 13: "membermima (treeList ! ?h) succy + \ membermima (Node (Some (mi, ma)) deg treeList summary) ?y" + using membermima.simps(4)[of mi ma "deg -1" treeList summary ?y] + apply(cases "?y = mi \ ?y = ma") + using "07" apply auto[1] + using "07" "10" "5.hyps"(4) by auto + hence 14:"both_member_options (Node (Some (mi, ma)) deg treeList summary) ?y" + using "09" "11" both_member_options_def by blast + have 15: "vebt_member (Node (Some (mi, ma)) deg treeList summary) ?y" + by (smt "07" "08" "10" "12" "5.hyps"(4) "5.hyps"(5) VEBT_Member.vebt_member.simps(5) One_nat_def Suc_1 Suc_le_eq Suc_pred \2 \ deg\ \deg div 2 = n\ add_gr_0 div_greater_zero_iff not_less zero_less_numeral) + have 16: "Some ?y = vebt_succ (Node (Some (mi, ma)) deg treeList summary) x" + by (simp add: \vebt_succ (Node (Some (mi, ma)) deg treeList summary) x = Some (2 ^ (deg div 2) * high x (deg div 2) + succy)\) + have 17: "x = ?h * 2^(deg div 2) + ?l" + using bit_concat_def bit_split_inv by auto + have 18: "?y - x = ?h * 2^(deg div 2) + succy - ?h * 2^(deg div 2) - ?l " + by (metis "17" diff_diff_add mult.commute) + hence "?y -x > 0" + using "04" is_succ_in_set_def by auto + hence 19: "?y > x" + using zero_less_diff by blast + have 20: "z > x \ vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ z\ ?y " for z + proof- + assume "z > x" and "vebt_member (Node (Some (mi, ma)) deg treeList summary) z" + hence "high z (deg div 2) \ high x (deg div 2)" + by (simp add: div_le_mono high_def) + then show ?thesis + proof(cases "high z (deg div 2) = high x (deg div 2)") + case True + hence "vebt_member (treeList ! ?h) (low z (deg div 2))" + using vebt_member.simps(5)[of mi ma "deg-2" treeList summary z] + by (metis "01" "07" "5.hyps"(11) "5.hyps"(5) False \deg div 2 = n\ \vebt_member (Node (Some (mi, ma)) deg treeList summary) z\ \x < z\ both_member_options_equiv_member member_inv) + hence "succy \ low z (deg div 2)" using 04 unfolding is_succ_in_set_def + by (metis True \x < z\ add_diff_cancel_left' bit_concat_def bit_split_inv diff_diff_left mem_Collect_eq set_vebt'_def zero_less_diff) + hence "?y \ z" + by (smt True bit_concat_def bit_split_inv diff_add_inverse diff_diff_add diff_is_0_eq mult.commute) + then show ?thesis by blast + next + case False + hence "high z (deg div 2) > high ?y (deg div 2)" + using "10" \high x (deg div 2) \ high z (deg div 2)\ by linarith + then show ?thesis + by (metis div_le_mono high_def nat_le_linear not_le) + qed + qed + hence "is_succ_in_set (set_vebt' (Node (Some (mi, ma)) deg treeList summary)) x ?y" + by (simp add: "15" "19" succ_member) + then show ?thesis using 16 + by (metis eq_iff option.inject succ_member) + next + case False + hence i1:"?maxlow = None \ \ (Some ?l <\<^sub>o ?maxlow)" by simp + hence 2: "vebt_succ (Node (Some (mi, ma)) deg treeList summary) x = (if ?sc = None then None + else Some (2^(deg div 2)) *\<^sub>o ?sc +\<^sub>o vebt_mint (treeList ! the ?sc))" + using "1" by auto + have " invar_vebt (treeList ! ?h) n" + by (metis "5"(1) True inthall member_def) + hence 33:"\ u. vebt_member (treeList ! ?h) u \ u > ?l" + proof(cases "?maxlow = None") + case True + then show ?thesis using maxt_corr_help_empty[of "treeList ! ?h" n] + by (simp add: \invar_vebt (treeList ! high x (deg div 2)) n\ set_vebt'_def) + next + case False + obtain maxilow where "?maxlow =Some maxilow" + using False by blast + hence "maxilow \ ?l" + using "i1" by auto + then show ?thesis + by (meson \vebt_maxt (treeList ! high x (deg div 2)) = Some maxilow\ \invar_vebt (treeList ! high x (deg div 2)) n\ le_imp_less_Suc le_less_trans maxt_corr_help not_less_eq) + qed + then show ?thesis + proof(cases " ?sc = None") + case True + hence "vebt_succ (Node (Some (mi, ma)) deg treeList summary) x = None" + by (simp add: "2") + hence "\ i. is_succ_in_set (set_vebt' summary) ?h i" + using "5.hyps"(3) True by force + hence "\ i. i > ?h \ vebt_member summary i " using succ_none_empty[of "set_vebt' summary" ?h] + proof - + { fix nn :: nat + have "\n. ((is_succ_in_set (Collect (vebt_member summary)) (high x (deg div 2)) esk1_0 \ infinite (Collect (vebt_member summary))) \ n \ Collect (vebt_member summary)) \ \ high x (deg div 2) < n" + using \\i. is_succ_in_set (set_vebt' summary) (high x (deg div 2)) i\ succ_none_empty set_vebt'_def by auto + then have "\ high x (deg div 2) < nn \ \ vebt_member summary nn" + using "5.hyps"(2) \\i. is_succ_in_set (set_vebt' summary) (high x (deg div 2)) i\ set_vebt'_def set_vebt_finite by auto } + then show ?thesis + by blast + qed + hence "(i > x \ vebt_member (Node (Some (mi, ma)) deg treeList summary) i) \ False" for i + proof- + fix i + assume "i > x \ vebt_member (Node (Some (mi, ma)) deg treeList summary) i" + hence 20: "i = mi \ i = ma \ (high i (deg div 2) < length treeList + \ vebt_member ( treeList ! (high i (deg div 2))) (low i (deg div 2)))" using + vebt_member.simps(5)[of mi ma "deg-2" treeList summary i] + using member_inv by blast + have "i \ mi" + using \mi \ x\ \x < i \ vebt_member (Node (Some (mi, ma)) deg treeList summary) i\ not_le by blast + hence "mi \ ma" + using \x < i \ vebt_member (Node (Some (mi, ma)) deg treeList summary) i\ member_inv not_less_iff_gr_or_eq by blast + hence "i < 2^deg" + using "5.hyps"(10) \i \ mi\ \x < i \ vebt_member (Node (Some (mi, ma)) deg treeList summary) i\ member_inv by fastforce + hence aa:"i = ma \ both_member_options( treeList ! (high i (deg div 2))) (low i (deg div 2))" + using "5.hyps"(11) "5.hyps"(2) "5.hyps"(6) \deg div 2 = n\ \i \ mi\ \invar_vebt (treeList ! high x (deg div 2)) n\ deg_not_0 exp_split_high_low(1) by auto + hence abc:"invar_vebt (treeList ! (high i (deg div 2))) n" + by (metis "5.hyps"(1) "5.hyps"(4) "5.hyps"(5) "5.hyps"(6) \deg div 2 = n\ \i < 2 ^ deg\ \invar_vebt (treeList ! high x (deg div 2)) n\ deg_not_0 exp_split_high_low(1) in_set_member inthall zero_less_Suc) + hence abd:"i = ma \ vebt_member( treeList ! (high i (deg div 2))) (low i (deg div 2))" + using aa valid_member_both_member_options by blast + hence abe:"vebt_member( treeList ! (high i (deg div 2))) (low i (deg div 2))" + using "20" \i \ mi\ by blast + hence abf:"both_member_options( treeList ! (high i (deg div 2))) (low i (deg div 2))" + using \invar_vebt (treeList ! high i (deg div 2)) n\ both_member_options_equiv_member by blast + hence abg:"both_member_options summary (high i (deg div 2))" + by (metis (full_types) "5.hyps"(5) "5.hyps"(6) "5.hyps"(7) \deg div 2 = n\ \i < 2 ^ deg\ abc deg_not_0 exp_split_high_low(1) zero_less_Suc) + hence abh:"vebt_member summary (high i (deg div 2))" + using "5.hyps"(2) valid_member_both_member_options by blast + have aaa:"(high i (deg div 2)) = (high x (deg div 2)) \ vebt_member (treeList ! ?h) (low i (deg div 2))" + using \vebt_member (treeList ! high i (deg div 2)) (low i (deg div 2))\ by auto + have abi:"(high i (deg div 2)) = (high x (deg div 2)) \ low i (deg div 2) > ?l" + by (metis \x < i \ vebt_member (Node (Some (mi, ma)) deg treeList summary) i\ add_le_cancel_left bit_concat_def bit_split_inv le_neq_implies_less less_imp_le_nat nat_neq_iff) + hence abj:"(high i (deg div 2)) = (high x (deg div 2)) \ False" using 33 aaa by blast + hence abk:" (high i (deg div 2)) \ (set_vebt' summary) \ (high i (deg div 2)) > (high x (deg div 2)) " + by (metis (full_types) \vebt_member summary (high i (deg div 2))\ \x < i \ vebt_member (Node (Some (mi, ma)) deg treeList summary) i\ div_le_mono high_def le_less mem_Collect_eq set_vebt'_def) + then show ?thesis + using \\ (\i>high x (deg div 2). vebt_member summary i)\ abh by blast + qed + then show ?thesis + using \vebt_succ (Node (Some (mi, ma)) deg treeList summary) x = None\ succ_member by auto + next + case False + hence "vebt_succ (Node (Some (mi, ma)) deg treeList summary) x = + Some (2^(deg div 2)) *\<^sub>o ?sc +\<^sub>o vebt_mint (treeList ! the ?sc)" + by (simp add: False "2") + obtain sc where "?sc = Some sc" + using False by blast + hence "is_succ_in_set (set_vebt' summary) ?h sc" + using "5.hyps"(3) by blast + hence "vebt_member summary sc" + using succ_member by blast + hence "both_member_options summary sc" + using "5.hyps"(2) both_member_options_equiv_member by auto + hence "sc < 2^m" + using "5.hyps"(2) \vebt_member summary sc\ member_bound by blast + hence "\ miny. both_member_options (treeList ! sc) miny" + using "5.hyps"(7) \both_member_options summary sc\ by blast + hence fgh:"set_vebt' (treeList ! sc) \ {}" + by (metis "5.hyps"(1) "5.hyps"(4) \sc < 2 ^ m\ empty_Collect_eq inthall member_def set_vebt'_def valid_member_both_member_options) + hence "invar_vebt (treeList ! the ?sc) n" + by (simp add: "5.hyps"(1) "5.hyps"(4) \sc < 2 ^ m\ \vebt_succ summary (high x (deg div 2)) = Some sc\) + then obtain miny where "Some miny = vebt_mint (treeList ! sc)" + by (metis fgh Collect_empty_eq VEBT_Member.vebt_member.simps(2) vebt_buildup.simps(2) buildup_gives_empty vebt_mint.elims set_vebt'_def) + hence "Some miny = vebt_mint (treeList ! the ?sc)" + by (simp add: \vebt_succ summary (high x (deg div 2)) = Some sc\) + hence "min_in_set (set_vebt' (treeList ! the ?sc)) miny" + using \invar_vebt (treeList ! the (vebt_succ summary (high x (deg div 2)))) n\ mint_corr by auto + hence scmem:"vebt_member (treeList ! the ?sc) miny" + using \Some miny = vebt_mint (treeList ! the (vebt_succ summary (high x (deg div 2))))\ + \invar_vebt (treeList ! the (vebt_succ summary (high x (deg div 2)))) n\ mint_member by auto + let ?res = "Some (2^(deg div 2)) *\<^sub>o ?sc +\<^sub>o vebt_mint (treeList ! the ?sc)" + obtain res where "res = the ?res" by blast + hence "res = 2^(deg div 2) * sc + miny" + by (metis \Some miny = vebt_mint (treeList ! sc)\ \vebt_succ summary (high x (deg div 2)) = Some sc\ add_shift mul_shift option.sel) + have "high res (deg div 2) = sc" + by (metis \deg div 2 = n\ \res = 2 ^ (deg div 2) * sc + miny\ \invar_vebt (treeList ! the ?sc) n\ high_inv member_bound mult.commute scmem) + hence "res > x" + by (metis is_succ_in_set_def \is_succ_in_set (set_vebt' summary) (high x (deg div 2)) sc\ div_le_mono high_def not_le) + hence "res > mi" + using \mi \ x\ le_less_trans by blast + hence "res \ ma" + proof(cases "high res n < high ma n") + case True + then show ?thesis + by (metis div_le_mono high_def leD nat_le_linear) + next + case False + hence "mi \ ma" + by (metis "5.hyps"(4) "5.hyps"(8) \\miny. both_member_options (treeList ! sc) miny\ \sc < 2 ^ m\ nth_mem) + have "high res n < 2^m" + using \deg div 2 = n\ \high res (deg div 2) = sc\ \sc < 2 ^ m\ by blast + hence " (\x. high x n = high res n \ both_member_options (treeList ! (high res n)) (low x n) \ mi < x \ x \ ma)" using 5(11) + using \mi \ ma\ by blast + have "high res n = high res n \ both_member_options (treeList ! (high res n)) (low res n)" + by (metis \deg div 2 = n\ \high res (deg div 2) = sc\ \res = 2 ^ (deg div 2) * sc + miny\ \vebt_succ summary (high x (deg div 2)) = Some sc\ \invar_vebt (treeList ! the (vebt_succ summary (high x (deg div 2)))) n\ both_member_options_equiv_member low_inv member_bound mult.commute option.sel scmem) + then show ?thesis + using \\x. high x n = high res n \ both_member_options (treeList ! high res n) (low x n) \ mi < x \ x \ ma\ by blast + qed + hence "vebt_member (Node (Some (mi, ma)) deg treeList summary) (the ?res)" using vebt_member.simps(5)[of mi ma "deg-2" treeList summary res] + by (metis "5.hyps"(4) \2 \ deg\ \deg div 2 = n\ \high res (deg div 2) = sc\ \mi < res\ \res = 2 ^ (deg div 2) * sc + miny\ \res = the (Some (2 ^ (deg div 2)) *\<^sub>o vebt_succ summary (high x (deg div 2)) +\<^sub>o vebt_mint (treeList ! the (vebt_succ summary (high x (deg div 2)))))\ \sc < 2 ^ m\ \vebt_succ summary (high x (deg div 2)) = Some sc\ \invar_vebt (treeList ! the (vebt_succ summary (high x (deg div 2)))) n\ add_2_eq_Suc' le_add_diff_inverse2 less_imp_le low_inv member_bound mult.commute not_less option.sel scmem) + have "(vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ z > x) \ z \ res" for z + proof- + fix z + assume "vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ z > x" + hence 20: "z = mi \ z = ma \ (high z (deg div 2) < length treeList + \ vebt_member ( treeList ! (high z (deg div 2))) (low z (deg div 2)))" using + vebt_member.simps(5)[of mi ma "deg-2" treeList summary z] + using member_inv by blast + have "z \ mi" + using \vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ x < z\ \mi \ x\ not_le by blast + hence "mi \ ma" + using \mi < res\ \res \ ma\ not_le by blast + hence "z < 2^deg" + using "5.hyps"(10) \vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ x < z\ \z \ mi\ member_inv by fastforce + hence aa:"z = ma \ both_member_options( treeList ! (high z (deg div 2))) (low z (deg div 2))" + using "5.hyps"(11) "5.hyps"(2) "5.hyps"(6) \deg div 2 = n\ \mi \ ma\ \invar_vebt (treeList ! high x (deg div 2)) n\ deg_not_0 exp_split_high_low(1) by auto + hence abc:"invar_vebt (treeList ! (high z (deg div 2))) n" + by (metis "20" "5.hyps"(1) "5.hyps"(10) "5.hyps"(4) "5.hyps"(5) "5.hyps"(6) \deg div 2 = n\ \invar_vebt (treeList ! the(vebt_succ summary (high x (deg div 2)))) n\ \z \ mi\ deg_not_0 exp_split_high_low(1) nth_mem zero_less_Suc) + hence abd:"z = ma \ vebt_member( treeList ! (high z (deg div 2))) (low z (deg div 2))" + using aa valid_member_both_member_options by blast + hence abe:"vebt_member( treeList ! (high z (deg div 2))) (low z (deg div 2))" + using "20" \z \ mi\ by blast + hence abf:"both_member_options( treeList ! (high z (deg div 2))) (low z (deg div 2))" + using \invar_vebt (treeList ! high z (deg div 2)) n\ both_member_options_equiv_member by blast + hence abg:"both_member_options summary (high z (deg div 2))" + by (metis (full_types) "5.hyps"(5) "5.hyps"(6) "5.hyps"(7) \deg div 2 = n\ \invar_vebt (treeList ! the (vebt_succ summary (high x (deg div 2)))) n\ \z < 2 ^ deg\ deg_not_0 exp_split_high_low(1) zero_less_Suc) + hence abh:"vebt_member summary (high z (deg div 2))" + using "5.hyps"(2) valid_member_both_member_options by blast + have aaa:"(high z (deg div 2)) = (high x (deg div 2)) \ vebt_member (treeList ! ?h) (low z (deg div 2))" + using abe by auto + have "high z(deg div 2)< sc \ False" + proof- + assume "high z(deg div 2)< sc" + hence "vebt_member summary (high z(deg div 2))" + using abh by blast + have aaaa:"?h \ high z(deg div 2)" + by (simp add: \vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ x < z\ div_le_mono high_def less_imp_le_nat) + have bbbb:"?h \ high z(deg div 2)" + using \is_succ_in_set (set_vebt' summary) (high x (deg div 2)) sc\ \high z (deg div 2) < sc\ abh leD succ_member by auto + hence "?h = high z (deg div 2)" + using aaaa eq_iff by blast + hence "vebt_member (treeList ! ?h) (low z (deg div 2))" + using aaa by linarith + then show False + by (metis "33" \high x (deg div 2) = high z (deg div 2)\ \vebt_member (Node (Some (mi, ma)) deg treeList summary) z \ x < z\ add_diff_cancel_left' bit_concat_def bit_split_inv diff_diff_left zero_less_diff) + qed + hence "high z(deg div 2) \ sc" + using not_less by blast + then show " z \ res" + proof(cases "high z(deg div 2) = sc") + case True + hence "vebt_member (treeList ! (high z(deg div 2))) (low z (deg div 2))" + using abe by blast + have "low z (deg div 2) \ miny" + using True \min_in_set (set_vebt' (treeList ! the (vebt_succ summary (high x (deg div 2))))) miny\ \vebt_succ summary (high x (deg div 2)) = Some sc\ abe min_in_set_def set_vebt'_def by auto + hence "z \ res" + by (metis (full_types) True \res = 2 ^ (deg div 2) * sc + miny\ add_le_cancel_left bit_concat_def bit_split_inv mult.commute) + then show ?thesis by simp + next + case False + hence "high z(deg div 2) > sc" + using \sc \ high z (deg div 2)\ le_less by blast + then show ?thesis + by (metis \high res (deg div 2) = sc\ div_le_mono high_def leD linear) + qed + qed + hence "is_succ_in_set (set_vebt' (Node (Some (mi, ma)) deg treeList summary)) x res" + using \vebt_member (Node (Some (mi, ma)) deg treeList summary) (the (Some (2 ^ (deg div 2)) *\<^sub>o vebt_succ summary ?h +\<^sub>o vebt_mint (treeList ! the (vebt_succ summary ?h))))\ + \res = the (Some (2 ^ (deg div 2)) *\<^sub>o vebt_succ summary ?h +\<^sub>o vebt_mint (treeList ! the (vebt_succ summary ?h)))\ \x < res\ succ_member by blast + moreover have "Some res = Some (2^(deg div 2)) *\<^sub>o ?sc +\<^sub>o vebt_mint (treeList ! the ?sc)" + by (metis \Some miny = vebt_mint (treeList ! the (vebt_succ summary (high x (deg div 2))))\ \res = 2 ^ (deg div 2) * sc + miny\ \vebt_succ summary (high x (deg div 2)) = Some sc\ add_def mul_def option_shift.simps(3)) + ultimately show ?thesis + by (metis (mono_tags) is_succ_in_set_def \vebt_succ (Node (Some (mi, ma)) deg treeList summary) x = Some (2 ^ (deg div 2)) *\<^sub>o vebt_succ summary ?h +\<^sub>o vebt_mint (treeList ! the (vebt_succ summary ?h))\ eq_iff option.inject) + qed + qed + next + case False + hence 0:"vebt_succ (Node (Some (mi, ma)) deg treeList summary) x = None" + by (simp add: \2 \ deg\ \mi \ x\ succ_greatereq_min) + have 1:"x \ 2^deg" + by (metis "5.hyps"(4) "5.hyps"(5) "5.hyps"(6) False One_nat_def Suc_le_eq \1 \ n\ \deg div 2 = n\ exp_split_high_low(1) leI zero_less_Suc) + hence "x \ set_vebt' (Node (Some (mi, ma)) deg treeList summary)" + using "5.hyps"(10) "5.hyps"(9) member_inv set_vebt'_def by fastforce + hence "\ ss. is_succ_in_set (set_vebt' (Node (Some (mi, ma)) deg treeList summary)) x ss" + using "5.hyps"(10) 1 \mi \ x\ member_inv succ_member by fastforce + then show ?thesis using 0 by auto + qed + qed +qed + +corollary succ_empty: assumes "invar_vebt t n " + shows " (vebt_succ t x = None) = ({y. vebt_member t y \ y > x} = {})" +proof + show " vebt_succ t x = None \ {y. vebt_member t y \ x < y} = {}" + proof + show "vebt_succ t x = None \ {y. vebt_member t y \ x < y} \ {}" + proof- + assume "vebt_succ t x = None" + hence "\ y. is_succ_in_set (set_vebt' t) x y" + using assms succ_corr by force + moreover hence "is_succ_in_set (set_vebt' t) x y \ vebt_member t y \ x < y " for y by auto + ultimately show "{y. vebt_member t y \ x < y} \ {}" + using assms succ_none_empty set_vebt'_def set_vebt_finite by auto + qed + show " vebt_succ t x = None \ {} \ {y. vebt_member t y \ x < y}" by simp + qed + show " {y. vebt_member t y \ x < y} = {} \ vebt_succ t x = None" + proof- + assume "{y. vebt_member t y \ x < y} = {} " + hence "is_succ_in_set (set_vebt' t) x y \ False" for y + using succ_member by auto + thus "vebt_succ t x = None" + by (meson assms not_Some_eq succ_corr) + qed +qed + +theorem succ_correct: "invar_vebt t n \ vebt_succ t x = Some sx \is_succ_in_set (set_vebt t) x sx" + by (simp add: succ_corr set_vebt_set_vebt'_valid) + +lemma "is_succ_in_set S x y \ min_in_set {s . s \ S \ s > x} y" + using is_succ_in_set_def min_in_set_def by fastforce + +lemma helpyd:"invar_vebt t n \ vebt_succ t x = Some y \ y < 2^n" + using member_bound succ_corr succ_member by blast + +lemma geqmaxNone: + assumes "invar_vebt (Node (Some (mi, ma)) deg treeList summary) n ""x \ ma " + shows "vebt_succ (Node (Some (mi, ma)) deg treeList summary) x = None " +proof(rule ccontr) + assume "vebt_succ (Node (Some (mi, ma)) deg treeList summary) x \ None" + then obtain y where "vebt_succ (Node (Some (mi, ma)) deg treeList summary) x = Some y" by auto + hence "y > ma \ y \ set_vebt' ((Node (Some (mi, ma)) deg treeList summary))" + by (smt (verit, ccfv_SIG) assms(1) assms(2) dual_order.strict_trans2 member_inv min_in_set_def vebt_mint.simps(3) mint_corr not_less_iff_gr_or_eq succ_corr succ_member) + then show False + by (metis assms(1) leD vebt_maxt.simps(3) maxt_corr_help mem_Collect_eq set_vebt'_def) +qed + +end +end diff --git a/thys/Van_Emde_Boas_Trees/VEBT_SuccPredImperative.thy b/thys/Van_Emde_Boas_Trees/VEBT_SuccPredImperative.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/VEBT_SuccPredImperative.thy @@ -0,0 +1,481 @@ +(*by Ammer*) +theory VEBT_SuccPredImperative + imports VEBT_BuildupMemImp VEBT_Succ VEBT_Pred +begin + +context begin +interpretation VEBT_internal . + +section \Imperative Successor\ +partial_function (heap_time) vebt_succi::"VEBTi \ nat \ (nat option) Heap" where + "vebt_succi t x = (case t of (Leafi a b) \(if x = 0 then (if b then return (Some 1) else return None) + else return None)| + (Nodei info deg treeArray summary) \ ( + case info of None \ return None | + (Some mima) \ ( if deg \ 1 then return None else + (if x < fst mima then return (Some (fst mima)) else + if x \ snd mima then return None else + do { + l <- lowi x (deg div 2); + h <- highi x (deg div 2); + aktnode <- Array_Time.nth treeArray h; + maxlow <- vebt_maxti aktnode; + if (maxlow \ None \ (Some l <\<^sub>o maxlow)) + then do { + succy <- vebt_succi aktnode l; + return ( Some (2^(deg div 2)) *\<^sub>o Some h +\<^sub>o succy) + } + else do { + succsum <- vebt_succi summary h; + if succsum = None then + return None + else + do{ + nextnode <- Array_Time.nth treeArray (the succsum); + minnext <- vebt_minti nextnode; + return (Some (2^(deg div 2)) *\<^sub>o succsum +\<^sub>o minnext) + } + } + + }) +)))" + +end + +context VEBT_internal begin + +partial_function (heap_time) vebt_succi'::"VEBT \ VEBTi \ nat \ (nat option) Heap" where + "vebt_succi' t ti x = (case ti of (Leafi a b) \(if x = 0 then (if b then return (Some 1) else return None) + else return None)| + (Nodei info deg treeArray summary) \ do { assert'( is_Node t); + let (info',deg',treeList,summary') = + (case t of Node info' deg' treeList summary' \ (info',deg',treeList,summary')); + assert'(info'=info \ deg'=deg \ is_Node t); + case info of None \ return None | + (Some mima) \ (if deg \ 1 then return None else + (if x < fst mima then return (Some (fst mima)) else + if x \ snd mima then return None else + do { + l <- lowi x (deg div 2); + h <- highi x (deg div 2); + + assert'(l = low x (deg div 2)); + assert'(h = high x (deg div 2)); + assert'(h < length treeList); + + aktnode <- Array_Time.nth treeArray h; + let aktnode' = treeList!h; + + maxlow <- vebt_maxti aktnode; + assert' (maxlow = vebt_maxt aktnode'); + if (maxlow \ None \ (Some l <\<^sub>o maxlow)) + then do { + succy <- vebt_succi' aktnode' aktnode l; + return ( Some (2^(deg div 2)) *\<^sub>o Some h +\<^sub>o succy) + } + else do { + succsum <- vebt_succi' summary' summary h; + assert'(succsum = None \ vebt_succ summary' h = None); + if succsum = None then do{ + return None} + else + do{ + nextnode <- Array_Time.nth treeArray (the succsum); + minnext <- vebt_minti nextnode; + return (Some (2^(deg div 2)) *\<^sub>o succsum +\<^sub>o minnext) + } + } + + }) +)})" + +theorem vebt_succi'_rf_abstr:"invar_vebt t n \ vebt_succi' t ti x <\r. vebt_assn_raw t ti * \(r = vebt_succ t x)>" +proof(induction t x arbitrary: ti n rule: vebt_succ.induct) + case (1 uu b) + then show ?case by(subst vebt_succi'.simps) (cases ti; sep_auto) +next + case (2 uv uw n) + then show ?case by(subst vebt_succi'.simps) (cases ti; sep_auto) +next + case (3 ux uy uz va) + then show ?case by(subst vebt_succi'.simps) (cases ti; sep_auto) +next + case (4 v vc vd ve) + then show ?case by(subst vebt_succi'.simps) (cases ti; sep_auto) +next + case (5 v vg vh vi) + then show ?case by(subst vebt_succi'.simps) (cases ti; sep_auto) +next + case (6 mi ma va treeList summary x) + have setprop: "t \ set treeList \ invar_vebt t (n div 2 )" for t using 6(3) + by (cases) simp+ + have listlength: "length treeList = 2^(n - n div 2)" using 6(3) + by (cases) simp+ + have sumprop: "invar_vebt summary (n - n div 2)" using 6(3) + by (cases) simp+ + have xprop [simp]: " \ ma \ x \ high x (Suc (va div 2)) < length treeList" + by (smt (z3) "6.prems" deg_deg_n div2_Suc_Suc div_le_dividend high_bound_aux listlength mi_ma_2_deg not_le_imp_less order.strict_trans ordered_cancel_comm_monoid_diff_class.add_diff_inverse) + hence xprop' [simp]: " \ ma \ x \ x div (2 * 2 ^ (va div 2)) < length treeList" unfolding high_def by simp + show ?case + apply (cases ti) + prefer 2 + subgoal + apply simp + done + subgoal for x11 x12 x13 x14 + supply [split del] = if_split + apply (subst vebt_succi'.simps; clarsimp split del: ) + apply (assn_simp; intro normalize_rules) + apply simp + apply(auto split: if_split) + subgoal + apply sep_auto + done + apply sep_auto + using "6.prems" geqmaxNone + apply fastforce + apply sep_auto + apply (extract_pre_pure dest: extract_pre_list_assn_lengthD) + apply (sep_auto simp: lowi_def low_def heap: highi_h) + apply(sep_auto heap: vebt_maxtilist) + apply sep_auto + apply(simp add: high_def low_def) + apply (rewrite in "<\>_<_>" list_assn_conv_idx) + apply(rewrite in "<\>_<_>" listI_assn_extract[where i="(x div (2 * 2 ^ (va div 2)))"]) + apply (smt (z3) "6.prems" atLeastLessThan_iff deg_deg_n div2_Suc_Suc div_le_dividend dual_order.strict_trans2 high_bound_aux high_def le0 le_add_diff_inverse listlength mi_ma_2_deg nat_le_linear power_Suc) + apply (smt (z3) "6.prems" deg_deg_n div2_Suc_Suc div_le_dividend dual_order.strict_trans2 high_bound_aux high_def le_add_diff_inverse listlength mi_ma_2_deg nat_le_linear power_Suc) + apply(sep_auto heap: "6.IH"(1)) + apply(simp add: low_def) + apply(simp add: high_def) + apply simp+ + apply(rule setprop) + apply simp + subgoal for tree_is x + apply sep_auto + apply (smt (z3) "6.prems" deg_deg_n div2_Suc_Suc div_le_dividend dual_order.strict_trans2 high_bound_aux high_def le_add_diff_inverse less_shift listlength low_def mi_ma_2_deg nat_le_linear option.distinct(1) power_Suc) + apply(rule ent_trans[where Q=" vebt_assn_raw summary x14 * (x13 \\<^sub>a tree_is )* + (list_assn vebt_assn_raw treeList tree_is)"]) + apply (smt (z3) assn_aci(10) atLeastLessThan_iff entails_def leI less_nat_zero_code listI_assn_extract list_assn_conv_idx star_aci(2) xprop') + apply(rule ent_refl) + done + apply simp + apply sep_auto + apply(sep_auto heap: "6.IH"(2)) + apply (simp add: high_def low_def)+ + apply (rule sumprop) + apply(sep_auto heap: "6.IH"(2)) + apply (simp add: high_def low_def)+ + apply (rule sumprop) + apply sep_auto+ + apply(simp add: high_def low_def)+ + using helpyd listlength sumprop + apply presburger+ + apply (sep_auto heap: vebt_mintilist) + using helpyd listlength sumprop + apply presburger + using helpyd listlength sumprop + apply presburger+ + apply sep_auto + done + done +qed + +lemma TBOUND_vebt_succi: + defines foo_def: "\ t x. foo t x \ 7 * (1+height t)" + shows "TBOUND (vebt_succi' t ti x) (foo t x)" + apply (induction arbitrary: t ti x rule: vebt_succi'.fixp_induct) + apply (rule TBOUND_fi'_adm) + apply (rule TBOUND_empty) + apply TBOUND + apply(simp add: Let_def split!: VEBTi.splits VEBT.splits prod.splits option.splits if_splits) + apply(simp_all add: foo_def max_idx_list) + done + +lemma vebt_succi_refines: "refines (vebt_succi ti x) (vebt_succi' t ti x)" + apply (induction arbitrary: t ti x rule: vebt_succi'.fixp_induct) + subgoal using refines_adm[where t = "\ arg. vebt_succi (snd (fst arg)) (snd arg)"] + by simp + subgoal by simp + subgoal for f t ti x + apply(subst vebt_succi.simps) + apply refines + done + done + +lemma htt_vebt_succi: assumes "invar_vebt t n" + shows " vebt_succi ti x <\ r. vebt_assn_raw t ti * \(r = vebt_succ t x) >T[7 + 7*(nat \lb n\)]" + apply (rule htt_refine[where c = "vebt_succi' t ti x"]) + prefer 2 + apply(rule vebt_succi_refines) + apply (rule httI_TBOUND) + apply(rule vebt_succi'_rf_abstr) + apply(rule assms) + apply(rule TBOUND_mono) + apply(rule TBOUND_vebt_succi) + apply simp + apply(rule Nat.eq_imp_le) + apply (metis assms nat_int heigt_uplog_rel) + done + +end + +context begin +interpretation VEBT_internal . + + +partial_function (heap_time) vebt_predi::"VEBTi \ nat \ (nat option) Heap" where + "vebt_predi t x = (case t of (Leafi a b) \(if x \ 2then (if b then return (Some 1) else if a then return (Some 0) else return None) + else if x = 1 then (if a then return (Some 0) else return None) else return None)| + (Nodei info deg treeArray summary) \ ( + case info of None \ return None | + (Some mima) \ ( if deg \ 1 then return None else + (if x > snd mima then return (Some (snd mima)) else + do { + l <- lowi x (deg div 2); + h <- highi x (deg div 2); + aktnode <- Array_Time.nth treeArray h; + minlow <- vebt_minti aktnode; + if (minlow \ None \ (Some l >\<^sub>o minlow)) + then do { + predy <- vebt_predi aktnode l; + return ( Some (2^(deg div 2)) *\<^sub>o Some h +\<^sub>o predy) + } + else do { + predsum <- vebt_predi summary h; + if predsum = None then + if x > fst mima then + return (Some (fst mima)) + else + return None + else + do{ + nextnode <- Array_Time.nth treeArray (the predsum); + maxnext <- vebt_maxti nextnode; + return (Some (2^(deg div 2)) *\<^sub>o predsum +\<^sub>o maxnext) + } + } + }))))" + +end +context VEBT_internal begin + +section \Imperative Predecessor\ +partial_function (heap_time) vebt_predi'::"VEBT \ VEBTi \ nat \ (nat option) Heap" where + "vebt_predi' t ti x = (case ti of (Leafi a b) \(if x \ 2then (if b then return (Some 1) else if a then return (Some 0) else return None) + else if x = 1 then (if a then return (Some 0) else return None) else return None)| + (Nodei info deg treeArray summary) \ ( do { assert'( is_Node t); + let (info',deg',treeList,summary') = + (case t of Node info' deg' treeList summary' \ (info',deg',treeList,summary')); + assert'(info'=info \ deg'=deg \ is_Node t); + case info of None \ return None | + (Some mima) \ ( if deg \ 1 then return None else + (if x > snd mima then return (Some (snd mima)) else + do { + l <- lowi x (deg div 2); + h <- highi x (deg div 2); + + assert'(l = low x (deg div 2)); + assert'(h = high x (deg div 2)); + assert'(h < length treeList); + + aktnode <- Array_Time.nth treeArray h; + let aktnode' = treeList!h; + minlow <- vebt_minti aktnode; + assert' (minlow = vebt_mint aktnode'); + + if (minlow \ None \ (Some l >\<^sub>o minlow)) + then do { + predy <- vebt_predi' aktnode' aktnode l; + return ( Some (2^(deg div 2)) *\<^sub>o Some h +\<^sub>o predy) + } + else do { + predsum <- vebt_predi' summary' summary h; + assert'(predsum = None \ vebt_pred summary' h = None); + if predsum = None then + if x > fst mima then + return (Some (fst mima)) + else + return None + else + do{ + nextnode <- Array_Time.nth treeArray (the predsum); + maxnext <- vebt_maxti nextnode; + return (Some (2^(deg div 2)) *\<^sub>o predsum +\<^sub>o maxnext) + } + } + }))}))" + +theorem vebt_pred'_rf_abstr:"invar_vebt t n \ vebt_predi' t ti x <\r. vebt_assn_raw t ti * \(r = vebt_pred t x)>" +proof(induction t x arbitrary: ti n rule: vebt_pred.induct) + case (1 uu uv) + then show ?case by(subst vebt_predi'.simps) (cases ti; sep_auto) +next + case (2 a uw) + then show ?case by(subst vebt_predi'.simps) (cases ti; sep_auto) +next + case (3 a b va) + then show ?case by(subst vebt_predi'.simps) (cases ti; sep_auto) +next + case (4 uy uz va vb) + then show ?case by(subst vebt_predi'.simps) (cases ti; sep_auto) +next + case (5 v vd ve vf) + then show ?case by(subst vebt_predi'.simps) (cases ti; sep_auto) +next + case (6 v vh vi vj) + then show ?case by(subst vebt_predi'.simps) (cases ti; sep_auto) +next + case (7 mi ma va treeList summary x) + have setprop: "t \ set treeList \ invar_vebt t (n div 2 )" for t using 7(3) + by (cases) simp+ + have listlength: "length treeList = 2^(n - n div 2)" using 7(3) + by (cases) simp+ + have sumprop: "invar_vebt summary (n - n div 2)" using 7(3) + by (cases) simp+ + have mimapr: "ma \ mi" using 7(3) + by (cases) simp+ + show ?case + apply (cases ti) + prefer 2 + subgoal + apply simp + done + subgoal + supply [split del] = if_split + apply (subst vebt_predi'.simps; clarsimp split del: ) + apply (assn_simp; intro normalize_rules) + apply simp + apply(cases "ma < x") + subgoal + apply simp + apply sep_auto + done + apply simp + apply (extract_pre_pure dest: extract_pre_list_assn_lengthD) + apply(sep_auto simp: highi_def) + apply (sep_auto simp: lowi_def) + apply sep_auto + apply(simp add: low_def) + apply sep_auto + apply(simp add: high_def) + apply sep_auto + apply (smt (z3) "7.prems" deg_deg_n div2_Suc_Suc div_le_dividend high_bound_aux high_def le_add_diff_inverse linorder_neqE_nat listlength mi_ma_2_deg order.strict_trans power_Suc) + apply sep_auto + apply (smt (z3) "7.prems" deg_deg_n div2_Suc_Suc div_le_dividend high_bound_aux high_def le_add_diff_inverse linorder_neqE_nat listlength mi_ma_2_deg order.strict_trans power_Suc) + apply (sep_auto heap: vebt_mintilist) + apply (smt (z3) "7.prems" deg_deg_n div2_Suc_Suc div_le_dividend high_bound_aux high_def le_add_diff_inverse linorder_neqE_nat listlength mi_ma_2_deg order.strict_trans power_Suc) + apply sep_auto + apply (rewrite in "<\>_<_>" list_assn_conv_idx) + apply(rewrite in "<\>_<_>" listI_assn_extract[where i="(x div (2 * 2 ^ (va div 2)))"]) + apply (smt (z3) "7.prems" atLeastLessThan_iff deg_deg_n div2_Suc_Suc div_le_dividend high_bound_aux high_def le0 le_add_diff_inverse linorder_neqE_nat listlength mi_ma_2_deg order.strict_trans power_Suc) + apply (smt (z3) "7.prems" deg_deg_n div2_Suc_Suc div_le_dividend high_bound_aux high_def le_add_diff_inverse linorder_neqE_nat listlength mi_ma_2_deg order.strict_trans power_Suc) + apply (sep_auto heap: "7.IH"(1)) + apply(simp add: high_def low_def)+ + apply (smt (z3) "7.prems" deg_deg_n div2_Suc_Suc div_le_dividend high_bound_aux high_def le_add_diff_inverse linorder_neqE_nat listlength mi_ma_2_deg order.strict_trans power_Suc) + apply(rule DEADID.rel_refl) + apply (metis greater_shift option.simps(3)) + apply(rule setprop) + apply(rule nth_mem) + apply (smt (z3) "7.prems" atLeastLessThan_iff deg_deg_n div2_Suc_Suc div_le_dividend high_bound_aux high_def le0 le_add_diff_inverse linorder_neqE_nat listlength mi_ma_2_deg order.strict_trans power_Suc) + apply simp + subgoal + apply sep_auto + apply (smt (z3) "7.prems" deg_deg_n div2_Suc_Suc div_le_dividend dual_order.strict_trans2 greater_shift high_bound_aux high_def leI le_add_diff_inverse listlength low_def mi_ma_2_deg option.distinct(1) power_Suc) + apply (rule recomp) + apply (smt (z3) "7.prems" atLeastLessThan_iff deg_deg_n div2_Suc_Suc div_le_dividend high_bound_aux high_def le0 le_add_diff_inverse linorder_neqE_nat listlength mi_ma_2_deg order.strict_trans power_Suc) + apply (smt (z3) "7.prems" deg_deg_n div2_Suc_Suc div_le_dividend dual_order.strict_trans2 greater_shift high_bound_aux high_def leI le_add_diff_inverse listlength low_def mi_ma_2_deg option.distinct(1) power_Suc) + apply (rule recomp) + apply (smt (z3) "7.prems" atLeastLessThan_iff deg_deg_n div2_Suc_Suc div_le_dividend high_bound_aux high_def le0 le_add_diff_inverse linorder_neqE_nat listlength mi_ma_2_deg order.strict_trans power_Suc) + done + apply(sep_auto heap: "7.IH"(2)) + apply(simp add: high_def low_def)+ + apply (smt (z3) "7.prems" atLeastLessThan_iff deg_deg_n div2_Suc_Suc div_le_dividend high_bound_aux high_def le0 le_add_diff_inverse linorder_neqE_nat listlength mi_ma_2_deg order.strict_trans power_Suc) + apply(rule DEADID.rel_refl) + apply (simp add: low_def) + apply(rule sumprop) + apply sep_auto + apply(sep_auto simp: high_def low_def)+ + apply (smt (z3) "7.prems" deg_deg_n div2_Suc_Suc div_le_dividend dual_order.strict_trans2 high_bound_aux high_def leI le_add_diff_inverse listlength mi_ma_2_deg power_Suc) + apply (simp add: high_def low_def) + apply (smt (z3) "7.prems" deg_deg_n div2_Suc_Suc div_le_dividend dual_order.strict_trans2 greater.elims(2) high_bound_aux high_def leI le_add_diff_inverse listlength mi_ma_2_deg power_Suc) + apply sep_auto + apply(sep_auto simp: high_def low_def)+ + apply presburger + apply (smt (z3) greater.elims(2) high_def low_def power_Suc) + apply (simp add: high_def low_def) + apply sep_auto + subgoal + using helpypredd listlength sumprop apply simp + done + subgoal + using helpypredd listlength sumprop apply simp + done + apply sep_auto + apply(rule cons_pre_rule) + apply(sep_auto heap: vebt_maxti_h) + apply (rewrite in "<\>_<_>" list_assn_conv_idx) + apply (rewrite in "<\>_<_>" listI_assn_extract[where i="the (vebt_pred summary (x div (2 * 2 ^ (va div 2))))"]) + apply (metis atLeastLessThan_iff helpypredd le0 listlength option.sel sumprop) + apply (metis helpypredd listlength option.sel sumprop) + apply (simp add: algebra_simps) + apply(rule cons_pre_rule) + apply(rule ext) + using helpypredd listlength sumprop apply presburger + apply(sep_auto heap: vebt_maxti_h) + apply (rewrite in "<\>_<_>" list_assn_conv_idx) + apply (rewrite in "<\>_<_>" listI_assn_extract[where i="the (vebt_pred summary (x div (2 * 2 ^ (va div 2))))"]) + apply (metis atLeastLessThan_iff helpypredd le0 listlength option.sel sumprop) + apply (metis helpypredd listlength option.sel sumprop) + apply simp + apply(sep_auto heap: vebt_maxti_h) + apply sep_auto + apply (smt (z3) "7.prems" deg_deg_n div2_Suc_Suc div_le_dividend dual_order.strict_trans2 high_bound_aux high_def leI le_add_diff_inverse listlength mi_ma_2_deg option.distinct(1) option.sel power_Suc) + apply (smt (z3) "7.prems" deg_deg_n div2_Suc_Suc div_le_dividend dual_order.strict_trans2 greater.elims(2) high_bound_aux high_def leI le_add_diff_inverse listlength mi_ma_2_deg option.distinct(1) option.sel power_Suc) + apply(rule txe) + using helpypredd listlength sumprop apply presburger + apply (smt (z3) "7.prems" deg_deg_n div2_Suc_Suc div_le_dividend dual_order.strict_trans2 greater.elims(2) high_bound_aux high_def leI le_add_diff_inverse listlength mi_ma_2_deg option.distinct(1) option.sel power_Suc) + apply(rule txe) + using helpypredd listlength sumprop apply presburger + done + done +qed + +lemma TBOUND_vebt_predi: + defines foo_def: "\ t x. foo t x \ 7 * (1+height t)" + shows "TBOUND (vebt_predi' t ti x) (foo t x)" + apply (induction arbitrary: t ti x rule: vebt_predi'.fixp_induct) + apply (rule TBOUND_fi'_adm) + apply (rule TBOUND_empty) + apply TBOUND + apply (simp add: Let_def split!: VEBTi.splits VEBT.splits option.splits prod.splits if_splits) + apply(simp_all add: foo_def max_idx_list) + done + +lemma vebt_predi_refines: "refines (vebt_predi ti x) (vebt_predi' t ti x)" + apply (induction arbitrary: t ti x rule: vebt_predi'.fixp_induct) + subgoal using refines_adm[where t = "\ arg. vebt_predi (snd (fst arg)) (snd arg)"] + by simp + subgoal by simp + subgoal for f t ti x + apply(subst vebt_predi.simps) + apply refines + done + done + +lemma htt_vebt_predi: assumes "invar_vebt t n" + shows " vebt_predi ti x <\ r. vebt_assn_raw t ti * \(r = vebt_pred t x) >T[7 + 7*(nat \lb n\)]" + apply (rule htt_refine[where c = "vebt_predi' t ti x"]) + prefer 2 + apply(rule vebt_predi_refines) + apply (rule httI_TBOUND) + apply(rule vebt_pred'_rf_abstr) + apply(rule assms) + apply(rule TBOUND_mono) + apply(rule TBOUND_vebt_predi) + apply simp + apply(rule Nat.eq_imp_le) + apply (metis assms nat_int heigt_uplog_rel) + done + +end +end diff --git a/thys/Van_Emde_Boas_Trees/VEBT_Uniqueness.thy b/thys/Van_Emde_Boas_Trees/VEBT_Uniqueness.thy new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/VEBT_Uniqueness.thy @@ -0,0 +1,588 @@ +(*by Ammer*) +theory VEBT_Uniqueness imports VEBT_InsertCorrectness VEBT_Succ VEBT_Pred VEBT_DeleteCorrectness +begin + +context VEBT_internal begin + +section \Uniqueness Property of valid Trees\ +text \Two valid van Emde Boas trees having equal degree number and representing the same integer set are equal.\ + +theorem uniquetree: "invar_vebt t n \ invar_vebt s n \ set_vebt' t = set_vebt' s \ s = t" +proof(induction t n arbitrary: s rule: invar_vebt.induct) + case (1 a b) + then show ?case + apply(cases "vebt_member t 0") + apply(cases "vebt_member t 1") + apply(cases "vebt_member t 1") + apply (smt (z3) "1.prems"(1) "1.prems"(2) VEBT_Member.vebt_member.simps(1) One_nat_def deg_1_Leafy deg_not_0 less_not_refl mem_Collect_eq set_vebt'_def) + + done +next + case (2 treeList n summary m deg) + from 2(9) obtain treeList' summary' where sprop:"s = Node None deg treeList' summary' \ deg = n+m + \ length treeList' =2^m \ invar_vebt summary' m \ (\ t \ set treeList'. invar_vebt t n) \ + (\i. both_member_options summary' i)" + apply(cases) + using "2.hyps"(3) "2.hyps"(4) one_is_add apply force + apply (metis "2.hyps"(3) "2.hyps"(4) add_self_div_2) + apply (metis "2.hyps"(3) "2.hyps"(4) One_nat_def add_self_div_2 div_greater_zero_iff even_Suc_div_two not_numeral_le_zero odd_add order.not_eq_order_implies_strict plus_1_eq_Suc zero_le_one zero_neq_one) + apply (metis "2.prems"(1) "2.prems"(2) VEBT_Member.vebt_member.simps(2) Suc_1 add_leD1 add_self_div_2 both_member_options_def deg_not_0 div_greater_zero_iff empty_Collect_eq membermima.simps(4) nat_le_iff_add plus_1_eq_Suc set_vebt'_def valid_member_both_member_options) + apply (metis "2.hyps"(3) "2.hyps"(4) add_self_div_2 div2_Suc_Suc even_Suc_div_two odd_add one_is_add plus_1_eq_Suc zero_neq_one) + done + from 2(9) have aa:"\ t \ set treeList'. invar_vebt t n" using sprop by simp + have ac:"deg \ 2" + by (metis "2.hyps"(3) add_self_div_2 deg_not_0 div_greater_zero_iff sprop) + hence ab:"\ t \ set treeList. set_vebt' t = {}" + by (metis "2.hyps"(6) empty_Collect_eq min_Null_member not_min_Null_member set_vebt'_def) + hence ac:"length treeList' =length treeList" + by (simp add: "2.hyps"(2) sprop) + hence membercongy:"i < 2^m \ vebt_member (treeList! i) x \ vebt_member (treeList' ! i) x" for i x + proof- + assume "i < 2^m" + show "vebt_member (treeList! i) x \ vebt_member (treeList' ! i) x" + proof + show "vebt_member (treeList ! i) x \ vebt_member (treeList' ! i) x" + by (metis "2.hyps"(6) \i < 2 ^ m\ ac min_Null_member not_min_Null_member nth_mem sprop) + show "vebt_member (treeList' ! i) x \ vebt_member (treeList ! i) x" + proof- + assume "vebt_member (treeList' ! i) x" + hence "both_member_options (treeList' ! i) x" + by (metis \i < 2 ^ m\ both_member_options_equiv_member nth_mem sprop) + hence "membermima (treeList' ! i) x \ naive_member (treeList' ! i) x" unfolding both_member_options_def by auto + moreover have "membermima (treeList' ! i) x \ membermima s (2^m*i+x)" + using membermima.simps(5)[of "deg-1" treeList' summary' "(2^m*i+x)"] sprop ac + apply auto + apply (metis One_nat_def Suc_diff_1 \membermima (Node None (Suc (deg - 1)) treeList' summary') (2 ^ m * i + x) = (let pos = high (2 ^ m * i + x) (Suc (deg - 1) div 2) in if pos < length treeList' then membermima (treeList' ! pos) (low (2 ^ m * i + x) (Suc (deg - 1) div 2)) else False)\ add.commute deg_not_0 neq0_conv not_add_less1) + by (smt (z3) "2.hyps"(3) Nat.add_0_right Suc_pred \i < 2 ^ m\ \vebt_member (treeList' ! i) x\ add_gr_0 add_self_div_2 deg_not_0 div_less div_mult_self4 high_def low_inv member_bound mult.commute nth_mem power_not_zero zero_neq_numeral) + moreover have "naive_member (treeList' ! i) x \ naive_member s (2^m*i+x)" + using naive_member.simps(3)[of None "deg-1" treeList' summary' "(2^m*i+x)" ] sprop ac + apply auto + apply (metis One_nat_def Suc_pred' \naive_member (Node None (Suc (deg - 1)) treeList' summary') (2 ^ m * i + x) = (let pos = high (2 ^ m * i + x) (Suc (deg - 1) div 2) in if pos < length treeList' then naive_member (treeList' ! pos) (low (2 ^ m * i + x) (Suc (deg - 1) div 2)) else False)\ add_gr_0 deg_not_0) + by (smt (z3) "2.hyps"(3) Nat.add_0_right Suc_pred \i < 2 ^ m\ \vebt_member (treeList' ! i) x\ add_gr_0 add_self_div_2 deg_not_0 div_less div_mult_self4 high_def low_inv member_bound mult.commute nth_mem power_not_zero zero_neq_numeral) + ultimately have "both_member_options s (2^m*i +x)" unfolding both_member_options_def by auto + hence False + using "2.prems"(1) VEBT_Member.vebt_member.simps(2) sprop valid_member_both_member_options by blast + then show ?thesis by simp + qed + qed + qed + hence ad:"i<2^m \ set_vebt' (treeList' ! i ) = {}" for i + proof- + assume assm:"i < 2^m" + show "set_vebt' (treeList' ! i ) = {}" + proof(rule ccontr) + assume "set_vebt' (treeList' ! i ) \ {}" + then obtain y where "vebt_member (treeList' ! i) y" + using set_vebt'_def by fastforce + thus False + using ab ac assm membercongy sprop set_vebt'_def by force + qed + qed + hence ae:"i< 2^m \ treeList' ! i = treeList ! i" for i + by (simp add: "2.IH"(1) "2.hyps"(2) ab sprop) + then show ?case + by (metis "2.IH"(2) "2.hyps"(1) "2.hyps"(5) ac both_member_options_equiv_member empty_Collect_eq list_eq_iff_nth_eq sprop set_vebt'_def) +next + case (3 treeList n summary m deg) + from 3(9) obtain treeList' summary' where sprop:"s = Node None deg treeList' summary' \ deg = n+m + \ length treeList' =2^m \ invar_vebt summary' m \ (\ t \ set treeList'. invar_vebt t n) \ + (\i. both_member_options summary' i)" + apply(cases) + apply (metis "3.IH"(1) "3.hyps"(2) "3.hyps"(3) "3.hyps"(4) One_nat_def Suc_1 not_one_le_zero one_is_add set_n_deg_not_0 zero_neq_numeral) + apply (metis "3.hyps"(3) "3.hyps"(4) add_self_div_2 div2_Suc_Suc even_Suc_div_two odd_add plus_1_eq_Suc) + apply (metis "3.hyps"(3) "3.hyps"(4) Suc_inject add_Suc_right add_self_div_2) + apply (metis "3.hyps"(3) "3.hyps"(4) add_Suc_right add_self_div_2 even_Suc_div_two le_add2 le_less_Suc_eq odd_add order.strict_iff_order plus_1_eq_Suc) + apply (metis "3.prems"(1) "3.prems"(2) VEBT_Member.vebt_member.simps(2) Suc_pred' both_member_options_def deg_not_0 mem_Collect_eq membermima.simps(4) set_vebt'_def valid_member_both_member_options) + done + have ac:"deg \ 2" + by (metis "3.hyps"(3) One_nat_def add_le_mono le_add1 numeral_2_eq_2 plus_1_eq_Suc set_n_deg_not_0 sprop) + hence ab:"\ t \ set treeList. set_vebt' t = {}" + by (metis "3.hyps"(6) empty_Collect_eq min_Null_member not_min_Null_member set_vebt'_def) + hence ac:"length treeList' =length treeList" + by (simp add: "3.hyps"(2) sprop) + hence membercongy:"i < 2^m \ vebt_member (treeList! i) x \ vebt_member (treeList' ! i) x" for i x + proof- + assume "i < 2^m" + show "vebt_member (treeList! i) x \ vebt_member (treeList' ! i) x" + proof + show "vebt_member (treeList ! i) x \ vebt_member (treeList' ! i) x" + by (metis "3.hyps"(6) \i < 2 ^ m\ ac min_Null_member not_min_Null_member nth_mem sprop) + show "vebt_member (treeList' ! i) x \ vebt_member (treeList ! i) x" + proof- + assume "vebt_member (treeList' ! i) x" + hence "both_member_options (treeList' ! i) x" + by (metis \i < 2 ^ m\ both_member_options_equiv_member nth_mem sprop) + hence "membermima (treeList' ! i) x \ naive_member (treeList' ! i) x" + unfolding both_member_options_def by auto + moreover have "membermima (treeList' ! i) x \ membermima s (2^n*i+x)" + using membermima.simps(5)[of "deg-1" treeList' summary' "(2^n*i+x)"] sprop ac + by (smt (z3) "3.hyps"(3) "3.prems"(1) Nat.add_diff_assoc Suc_pred \i < 2 ^ m\ \vebt_member (treeList' ! i) x\ add_diff_cancel_left' add_self_div_2 deg_not_0 even_Suc high_inv le_add1 low_inv member_bound mult.commute mult_2 nth_mem odd_two_times_div_two_nat plus_1_eq_Suc) + moreover have "naive_member (treeList' ! i) x \ naive_member s (2^n*i+x)" + using naive_member.simps(3)[of None "deg-1" treeList' summary' "(2^n*i+x)" ] sprop ac + by (smt (z3) "3.hyps"(3) "3.prems"(1) Nat.add_0_right Nat.add_diff_assoc Suc_pred \i < 2 ^ m\ \vebt_member (treeList' ! i) x\ add_self_div_2 deg_not_0 div_less div_mult_self4 even_Suc_div_two high_def le_add1 low_inv member_bound mult.commute nth_mem odd_add plus_1_eq_Suc power_not_zero zero_neq_numeral) + ultimately have "both_member_options s (2^n*i +x)" unfolding both_member_options_def + by auto + hence False + using "3.prems"(1) VEBT_Member.vebt_member.simps(2) sprop valid_member_both_member_options + by blast + then show ?thesis by simp + qed + qed + qed + hence ad:"i<2^m \ set_vebt' (treeList' ! i ) = {}" for i + proof- + assume assm:"i < 2^m" + show "set_vebt' (treeList' ! i ) = {}" + proof(rule ccontr) + assume "set_vebt' (treeList' ! i ) \ {}" + then obtain y where "vebt_member (treeList' ! i) y" + using set_vebt'_def by fastforce + thus False + using ab ac assm membercongy sprop set_vebt'_def by force + qed + qed + hence ae:"i< 2^m \ treeList' ! i = treeList ! i" for i + by (simp add: "3.IH"(1) "3.hyps"(2) ab sprop) + then show ?case + by (metis "3.IH"(2) "3.hyps"(1) "3.hyps"(5) Collect_empty_eq ac both_member_options_equiv_member list_eq_iff_nth_eq sprop set_vebt'_def) +next + case (4 treeList n summary m deg mi ma) + note case4= this + hence "set_vebt' (Node (Some (mi, ma)) deg treeList summary) = set_vebt' s" by simp + hence a0:"deg \ 2" using 4 + by (metis add_self_div_2 deg_not_0 div_greater_zero_iff) + hence aa:"{mi, ma} \ set_vebt' (Node (Some (mi, ma)) deg treeList summary)" + apply auto using vebt_member.simps(5)[of mi ma "deg -2" treeList summary mi] + apply (metis add_2_eq_Suc' le_add_diff_inverse2 mem_Collect_eq set_vebt'_def) + using vebt_member.simps(5)[of mi ma "deg -2" treeList summary ma] + apply (metis add_2_eq_Suc' le_add_diff_inverse2 mem_Collect_eq set_vebt'_def) + done + from 4(12) obtain treeList' summary' info where sprop1:"s = Node info deg treeList' summary' \ deg = n+m + \ length treeList' =2^m \ invar_vebt summary' m \ (\ t \ set treeList'. invar_vebt t n) " + apply cases + using "4.hyps"(3) "4.hyps"(4) one_is_add apply force + apply (metis "4.hyps"(3) "4.hyps"(4) add_self_div_2) + apply (metis "4.hyps"(3) "4.hyps"(4) even_Suc odd_add) + apply (metis "4.hyps"(3) "4.hyps"(4) add_self_div_2) + apply (metis "4.hyps"(3) "4.hyps"(4) even_Suc odd_add) + done + have ac:"invar_vebt t h \ invar_vebt k h \ set_vebt' t = set_vebt' k \ vebt_mint t = vebt_mint k" for t k h + proof- + assume assms: "invar_vebt t h" "invar_vebt k h" "set_vebt' t = set_vebt' k" + have "\ vebt_mint t = vebt_mint k \ False" + proof- + assume "vebt_mint t \ vebt_mint k" + then obtain a b where abdef:"vebt_mint t = None \ vebt_mint k = Some b \ + vebt_mint t = Some a \ vebt_mint k = None \ + a < b \ Some a = vebt_mint t \ Some b = vebt_mint k \ + b < a \ Some a = vebt_mint t \ Some b = vebt_mint k" + by (metis linorder_neqE_nat option.exhaust) + show False + apply(cases "vebt_mint t = None \ vebt_mint k = Some b") + apply (metis \vebt_mint t \ vebt_mint k\ assms(1) assms(2) assms(3) mint_corr mint_sound) + apply(cases " vebt_mint t = Some a \ vebt_mint k = None") + apply (metis \vebt_mint t \ vebt_mint k\ assms(1) assms(2) assms(3) mint_corr mint_sound) + apply (cases "a < b \ Some a = vebt_mint t \ Some b = vebt_mint k") + apply (metis \vebt_mint t \ vebt_mint k\ assms(1) assms(2) assms(3) mint_corr mint_sound) + apply (metis \vebt_mint t \ vebt_mint k\ abdef assms(1) assms(2) assms(3) mint_corr mint_sound) + done + qed + thus "vebt_mint t = vebt_mint k" by auto + qed + have ad:"invar_vebt t h \ invar_vebt k h \ set_vebt' t = set_vebt' k \ vebt_maxt t = vebt_maxt k" for t k h + proof- + assume assms: "invar_vebt t h" "invar_vebt k h" "set_vebt' t = set_vebt' k" + have "\ vebt_maxt t = vebt_maxt k \ False" + proof- + assume "vebt_maxt t \ vebt_maxt k" + then obtain a b where abdef:"vebt_maxt t = None \ vebt_maxt k = Some b \ + vebt_maxt t = Some a \ vebt_maxt k = None \ + a < b \ Some a = vebt_maxt t \ Some b = vebt_maxt k \ + b < a \ Some a = vebt_maxt t \ Some b = vebt_maxt k" + by (metis linorder_neqE_nat option.exhaust) + show False apply(cases "vebt_maxt t = None \ vebt_maxt k = Some b") + apply (metis \vebt_maxt t \ vebt_maxt k\ assms(1) assms(2) assms(3) maxt_corr maxt_sound) + apply(cases " vebt_maxt t = Some a \ vebt_maxt k = None") + apply (metis \vebt_maxt t \ vebt_maxt k\ assms(1) assms(2) assms(3) maxt_corr maxt_sound) + apply (cases "a < b \ Some a = vebt_maxt t \ Some b = vebt_maxt k") + apply (metis \vebt_maxt t \ vebt_maxt k\ assms(1) assms(2) assms(3) maxt_corr maxt_sound) + by (metis \vebt_maxt t \ vebt_maxt k\ abdef assms(1) assms(2) assms(3) maxt_corr maxt_sound) + qed + thus "vebt_maxt t = vebt_maxt k" by auto + qed + have infsplit: "info = Some (mi ,ma)" using 4(12) + proof cases + case (1 a b) + then show ?thesis + using sprop1 by blast + next + case (2 treeList n summary m) + then show ?thesis + by (metis "4.prems"(2) Collect_empty_eq VEBT_Member.vebt_member.simps(2) aa empty_iff insert_subset set_vebt'_def) + next + case (3 treeList n summary m) + then show ?thesis + by (metis "4.prems"(2) Collect_empty_eq VEBT_Member.vebt_member.simps(2) aa empty_iff insert_subset set_vebt'_def) + next + case (4 treeList' n' summary' m' mi' ma') + have "vebt_mint s = Some mi'" + by (simp add: "4"(1)) + hence "mi' = mi" + by (smt (verit, ccfv_threshold) "4.hyps"(7) "4.prems"(1) "4.prems"(2) VEBT_Member.vebt_member.simps(5) One_nat_def a0 aa add.assoc eq_iff insert_subset leI le_add_diff_inverse less_imp_le_nat mem_Collect_eq min_in_set_def mint_sound numeral_2_eq_2 option.sel order.not_eq_order_implies_strict plus_1_eq_Suc set_vebt'_def) + have "vebt_maxt s = Some ma'" + by (simp add: "4"(1)) + hence "ma' < ma \ ma\ set_vebt' s" + by (meson "4.prems"(1) leD max_in_set_def maxt_corr) + moreover have "ma < ma' \ ma' \ set_vebt' (Node (Some (mi, ma)) deg treeList summary)" using case4 + by (metis dual_order.strict_trans2 mem_Collect_eq member_inv not_less_iff_gr_or_eq set_vebt'_def) + ultimately have "ma'=ma" + by (metis \vebt_maxt s = Some ma'\ aa case4(12) case4(13) insert_subset max_in_set_def maxt_corr not_less_iff_gr_or_eq) + then show ?thesis + using "4"(1) \mi' = mi\ sprop1 by force + next + case (5 treeList n summary m mi' ma') + have "vebt_mint s = Some mi'" + by (simp add: "5"(1)) + hence "mi' = mi" + by (smt (verit, ccfv_threshold) "4.hyps"(7) "4.prems"(1) "4.prems"(2) VEBT_Member.vebt_member.simps(5) One_nat_def a0 aa add.assoc eq_iff insert_subset leI le_add_diff_inverse less_imp_le_nat mem_Collect_eq min_in_set_def mint_sound numeral_2_eq_2 option.sel order.not_eq_order_implies_strict plus_1_eq_Suc set_vebt'_def) + have "vebt_maxt s = Some ma'" + by (simp add: "5"(1)) + hence "ma' < ma \ ma\ set_vebt' s" + by (meson "4.prems"(1) leD max_in_set_def maxt_corr) + moreover have "ma < ma' \ ma' \ set_vebt' (Node (Some (mi, ma)) deg treeList summary)" using case4 + by (metis dual_order.strict_trans2 mem_Collect_eq member_inv not_less_iff_gr_or_eq set_vebt'_def) + ultimately have "ma'=ma" + by (metis "5"(5) "5"(6) case4(5) case4(6) even_Suc odd_add) + then show ?thesis + using "5"(1) \mi' = mi\ sprop1 by force + qed + from 4(12) have acd:"mi \ ma \ + (\i<2 ^ m. + (high ma n = i \ both_member_options (treeList' ! i) (low ma n)) \ + (\x. high x n = i \ both_member_options (treeList' ! i) (low x n) \ mi < x \ x \ ma))" + apply cases using sprop1 apply simp + using sprop1 infsplit apply simp + using sprop1 infsplit apply simp + apply (metis VEBT.inject(1) add_self_div_2 case4(5) infsplit option.inject prod.inject sprop1) + by (metis case4(5) case4(6) even_Suc odd_add) + hence "length treeList' = 2^m" + using sprop1 by fastforce + hence aca:"length treeList' =length treeList" using "4.hyps"(2) + by (simp add: "4.hyps"(2) sprop1) + from 4(12) have sumtreelistcong: " \i<2 ^ m. (\x. both_member_options (treeList' ! i) x) = both_member_options summary' i" + apply cases + using a0 apply linarith + apply (metis VEBT.inject(1) nth_mem sprop1) + using infsplit sprop1 apply force + apply (metis VEBT.inject(1) sprop1) + using sprop1 by auto + hence membercongy:"i < 2^m \ vebt_member (treeList! i) x \ vebt_member (treeList' ! i) x" for i x + proof- + assume "i < 2^m" + show "vebt_member (treeList! i) x \ vebt_member (treeList' ! i) x" + proof + show "vebt_member (treeList ! i) x \ vebt_member (treeList' ! i) x" + proof- + assume "vebt_member (treeList ! i) x" + hence aaa:"both_member_options (treeList ! i) x" + by (metis \i < 2 ^ m\ both_member_options_equiv_member case4(1) case4(4) nth_mem) + have "x < 2^n" + by (metis \i < 2 ^ m\ \vebt_member (treeList ! i) x\ case4(1) case4(4) member_bound nth_mem) + hence "vebt_member (Node (Some (mi, ma)) deg treeList summary) (2^n*i+x)" + using both_member_options_from_chilf_to_complete_tree + [of " (2^n*i+x)" deg treeList mi ma summary] aaa high_inv[of x n i] + by (smt (z3) VEBT_Member.vebt_member.simps(5) Suc_diff_Suc Suc_leD \i < 2 ^ m\ \vebt_member (treeList ! i) x\ a0 add_self_div_2 case4(11) case4(4) case4(5) case4(8) le_add_diff_inverse le_less_Suc_eq le_neq_implies_less low_inv mult.commute nat_1_add_1 not_less_iff_gr_or_eq nth_mem plus_1_eq_Suc sprop1) + have "mi < (2^n*i+x) \ (2^n*i+x) \ ma" using vebt_mint.simps(3)[of mi ma deg treeList summary] + by (metis \i < 2 ^ m\ \x < 2 ^ n\ aaa case4(11) case4(4) case4(8) high_inv low_inv mult.commute nth_mem) + moreover have "both_member_options s (2^m*i +x)" + using \vebt_member (Node (Some (mi, ma)) deg treeList summary) (2 ^ n * i + x)\ both_member_options_equiv_member case4(12) case4(13) case4(5) set_vebt'_def by auto + hence "both_member_options (treeList' ! i) x" + by (smt (z3) \i < 2 ^ m\ acd \x < 2 ^ n\ a0 add_leD1 add_self_div_2 both_member_options_from_complete_tree_to_child calculation case4(5) high_inv infsplit low_inv mult.commute nat_neq_iff numeral_2_eq_2 plus_1_eq_Suc sprop1) + then show ?thesis + by (metis \i < 2 ^ m\ nth_mem sprop1 valid_member_both_member_options) + qed + show "vebt_member (treeList' ! i) x \ vebt_member (treeList ! i) x" + proof- + assume "vebt_member (treeList' ! i) x" + hence "vebt_member s (2^n*i +x)" using sprop1 both_member_options_from_chilf_to_complete_tree + [of "(2^n*i +x)" deg treeList' mi ma summary'] + by (smt (z3) Nat.add_0_right \i < 2 ^ m\ a0 add_leD1 add_self_div_2 both_member_options_equiv_member case4(12) case4(5) div_less div_mult_self4 high_def infsplit low_inv member_bound mult.commute nat_1_add_1 nth_mem power_not_zero zero_neq_numeral) + hence "mi < (2^n*i +x) \ (2^n*i +x) \ ma " + using vebt_mint.simps(3)[of mi ma deg treeList' summary'] vebt_maxt.simps(3)[of mi ma deg treeList' summary'] + by (metis \i < 2 ^ m\ \vebt_member (treeList' ! i) x\ acd both_member_options_equiv_member case4(12) high_inv infsplit low_inv member_bound mi_eq_ma_no_ch mult.commute nth_mem sprop1) + moreover have "both_member_options (Node (Some (mi, ma)) deg treeList summary) (2^m*i +x)" + by (metis \vebt_member s (2 ^ n * i + x)\ add_leD1 both_member_options_equiv_member both_member_options_from_chilf_to_complete_tree calculation case4(1) case4(13) case4(5) maxbmo vebt_maxt.simps(3) mem_Collect_eq member_inv nat_neq_iff nth_mem one_add_one set_vebt'_def) + hence "both_member_options (treeList ! i) x" + using both_member_options_from_complete_tree_to_child[of deg mi ma treeList summary "(2^n*i +x)"] + by (smt (z3) Nat.add_0_right Suc_leD \i < 2 ^ m\ \vebt_member (treeList' ! i) x\ a0 add_self_div_2 calculation case4(11) case4(5) div_less div_mult_self4 high_def low_inv member_bound mult.commute nat_1_add_1 nat_neq_iff nth_mem plus_1_eq_Suc power_not_zero sprop1 zero_neq_numeral) + then show ?thesis + by (metis \i < 2 ^ m\ aca case4(1) nth_mem sprop1 valid_member_both_member_options) + qed + qed + qed + hence setcongy: "i < 2^m \ set_vebt' (treeList ! i) = set_vebt' (treeList' ! i)" for i unfolding set_vebt'_def by presburger + hence treecongy: "i < 2^m \ treeList ! i = treeList' ! i" for i + by (metis case4(1) case4(4) nth_mem sprop1) + hence "treeList = treeList'" + by (metis aca case4(4) nth_equalityI) + have "vebt_member summary x \ vebt_member summary' x" for x + by (metis \treeList = treeList'\ both_member_options_equiv_member case4(3) case4(7) member_bound sprop1 sumtreelistcong) + hence "set_vebt' summary = set_vebt' summary'" unfolding set_vebt'_def by auto + hence "summary = summary'" + using case4(2) sprop1 by blast + then show ?case + using \treeList = treeList'\ infsplit sprop1 by fastforce +next + case (5 treeList n summary m deg mi ma) + note case4= this + hence "set_vebt' (Node (Some (mi, ma)) deg treeList summary) = set_vebt' s" by simp + hence a0:"deg \ 2" using 5 + by (metis Suc_leI add_le_mono diff_Suc_1 less_add_same_cancel1 not_add_less1 not_less_iff_gr_or_eq numeral_2_eq_2 plus_1_eq_Suc set_n_deg_not_0) + hence aa:"{mi, ma} \ set_vebt' (Node (Some (mi, ma)) deg treeList summary)" + apply auto using vebt_member.simps(5)[of mi ma "deg -2" treeList summary mi] + apply (metis add_2_eq_Suc' le_add_diff_inverse2 mem_Collect_eq set_vebt'_def) + using vebt_member.simps(5)[of mi ma "deg -2" treeList summary ma] + apply (metis add_2_eq_Suc' le_add_diff_inverse2 mem_Collect_eq set_vebt'_def) + done + from 5(12) obtain treeList' summary' info where sprop1:"s = Node info deg treeList' summary' \ deg = n+m + \ length treeList' =2^m \ invar_vebt summary' m \ (\ t \ set treeList'. invar_vebt t n) " + apply cases + using a0 apply linarith + apply (metis case4(5) case4(6) even_Suc odd_add add_self_div_2) + apply (metis Suc_inject add_Suc_right add_self_div_2 case4(5) case4(6)) + apply (metis case4(5) case4(6) even_Suc odd_add) + apply (metis Suc_inject add_Suc_right add_self_div_2 case4(5) case4(6)) + done + have ac:"invar_vebt t h \ invar_vebt k h \ set_vebt' t = set_vebt' k \ vebt_mint t = vebt_mint k" for t k h + proof- + assume assms: "invar_vebt t h" "invar_vebt k h" "set_vebt' t = set_vebt' k" + have "\ vebt_mint t = vebt_mint k \ False" + proof- + assume "vebt_mint t \ vebt_mint k" + then obtain a b where abdef:"vebt_mint t = None \ vebt_mint k = Some b \ + vebt_mint t = Some a \ vebt_mint k = None \ + a < b \ Some a = vebt_mint t \ Some b = vebt_mint k \ + b < a \ Some a = vebt_mint t \ Some b = vebt_mint k" + by (metis linorder_neqE_nat option.exhaust) + show False apply(cases "vebt_mint t = None \ vebt_mint k = Some b") + apply (metis \vebt_mint t \ vebt_mint k\ assms(1) assms(2) assms(3) mint_corr mint_sound) + apply(cases " vebt_mint t = Some a \ vebt_mint k = None") + apply (metis \vebt_mint t \ vebt_mint k\ assms(1) assms(2) assms(3) mint_corr mint_sound) + apply (cases "a < b \ Some a = vebt_mint t \ Some b = vebt_mint k") + apply (metis \vebt_mint t \ vebt_mint k\ assms(1) assms(2) assms(3) mint_corr mint_sound) + by (metis \vebt_mint t \ vebt_mint k\ abdef assms(1) assms(2) assms(3) mint_corr mint_sound) + qed + thus "vebt_mint t = vebt_mint k" by auto + qed + have ad:"invar_vebt t h \ invar_vebt k h \ set_vebt' t = set_vebt' k \ vebt_maxt t = vebt_maxt k" for t k h + proof- + assume assms: "invar_vebt t h" "invar_vebt k h" "set_vebt' t = set_vebt' k" + have "\ vebt_maxt t = vebt_maxt k \ False" + proof- + assume "vebt_maxt t \ vebt_maxt k" + then obtain a b where abdef:"vebt_maxt t = None \ vebt_maxt k = Some b \ + vebt_maxt t = Some a \ vebt_maxt k = None \ + a < b \ Some a = vebt_maxt t \ Some b = vebt_maxt k \ + b < a \ Some a = vebt_maxt t \ Some b = vebt_maxt k" + by (metis linorder_neqE_nat option.exhaust) + show False + apply(cases "vebt_maxt t = None \ vebt_maxt k = Some b") + apply (metis \vebt_maxt t \ vebt_maxt k\ assms(1) assms(2) assms(3) maxt_corr maxt_sound) + apply(cases " vebt_maxt t = Some a \ vebt_maxt k = None") + apply (metis \vebt_maxt t \ vebt_maxt k\ assms(1) assms(2) assms(3) maxt_corr maxt_sound) + apply (cases "a < b \ Some a = vebt_maxt t \ Some b = vebt_maxt k") + apply (metis \vebt_maxt t \ vebt_maxt k\ assms(1) assms(2) assms(3) maxt_corr maxt_sound) + apply (metis \vebt_maxt t \ vebt_maxt k\ abdef assms(1) assms(2) assms(3) maxt_corr maxt_sound) + done + qed + thus "vebt_maxt t = vebt_maxt k" by auto + qed + have infsplit: "info = Some (mi ,ma)" using 5(12) + proof cases + case (1 a b) + then show ?thesis + using sprop1 by blast + next + case (2 treeList n summary m) + then show ?thesis + by (metis "5.prems"(2) Collect_empty_eq VEBT_Member.vebt_member.simps(2) aa empty_iff insert_subset set_vebt'_def) + next + case (3 treeList n summary m) + then show ?thesis + by (metis "5.prems"(2) Collect_empty_eq VEBT_Member.vebt_member.simps(2) aa empty_iff insert_subset set_vebt'_def) + next + case (4 treeList' n' summary' m' mi' ma') + have "vebt_mint s = Some mi'" + by (simp add: "4"(1)) + hence "mi' = mi" + by (smt (verit, ccfv_threshold) "5.hyps"(7) "5.prems"(1) "5.prems"(2) VEBT_Member.vebt_member.simps(5) One_nat_def a0 aa add.assoc eq_iff insert_subset leI le_add_diff_inverse less_imp_le_nat mem_Collect_eq min_in_set_def mint_sound numeral_2_eq_2 option.sel order.not_eq_order_implies_strict plus_1_eq_Suc set_vebt'_def) + have "vebt_maxt s = Some ma'" + by (simp add: "4"(1)) + hence "ma' < ma \ ma\ set_vebt' s" + by (meson "5.prems"(1) leD max_in_set_def maxt_corr) + moreover have "ma < ma' \ ma' \ set_vebt' (Node (Some (mi, ma)) deg treeList summary)" using case4 + by (metis dual_order.strict_trans2 mem_Collect_eq member_inv not_less_iff_gr_or_eq set_vebt'_def) + ultimately have "ma'=ma" + by (metis \vebt_maxt s = Some ma'\ aa case4(12) case4(13) insert_subset max_in_set_def maxt_corr not_less_iff_gr_or_eq) + then show ?thesis + using "4"(1) \mi' = mi\ sprop1 by force + next + case (5 treeList' n' summary' m' mi' ma') + have "vebt_mint s = Some mi'" + by (simp add: "5"(1)) + hence "mi' = mi" + by (smt (verit, ccfv_threshold) "5.hyps"(7) "5.prems"(1) "5.prems"(2) VEBT_Member.vebt_member.simps(5) One_nat_def a0 aa add.assoc eq_iff insert_subset leI le_add_diff_inverse less_imp_le_nat mem_Collect_eq min_in_set_def mint_sound numeral_2_eq_2 option.sel order.not_eq_order_implies_strict plus_1_eq_Suc set_vebt'_def) + have "vebt_maxt s = Some ma'" + by (simp add: "5"(1)) + hence "ma' < ma \ ma\ set_vebt' s" + by (meson "5.prems"(1) leD max_in_set_def maxt_corr) + moreover have "ma < ma' \ ma' \ set_vebt' (Node (Some (mi, ma)) deg treeList summary)" using case4 + by (metis dual_order.strict_trans2 mem_Collect_eq member_inv not_less_iff_gr_or_eq set_vebt'_def) + ultimately have "ma'=ma" using case4(13) 5 + by (metis \vebt_maxt s = Some ma'\ aa both_member_options_equiv_member case4(12) insert_subset maxbmo mem_Collect_eq not_less_iff_gr_or_eq set_vebt'_def) + then show ?thesis + using "5"(1) \mi' = mi\ sprop1 by force + qed + from 5(12) have acd:"mi \ ma \ + (\i<2 ^ m. + (high ma n = i \ both_member_options (treeList' ! i) (low ma n)) \ + (\x. high x n = i \ both_member_options (treeList' ! i) (low x n) \ mi < x \ x \ ma))" + apply cases using sprop1 apply simp + using sprop1 infsplit apply simp + using sprop1 infsplit apply simp + apply (metis case4(5) even_Suc odd_add sprop1) + apply (smt (z3) Suc_inject VEBT.inject(1) add_Suc_right add_self_div_2 case4(5) infsplit option.inject prod.inject sprop1) + done + hence "length treeList' = 2^m" + using sprop1 by fastforce + hence aca:"length treeList' =length treeList" using "5.hyps"(2) + by (simp add: "5.hyps"(2) sprop1) + from 5(12) have sumtreelistcong: " \i<2 ^ m. (\x. both_member_options (treeList' ! i) x) = both_member_options summary' i" + apply cases + using a0 apply linarith + apply (metis VEBT.inject(1) nth_mem sprop1) + using infsplit sprop1 apply force + apply (metis VEBT.inject(1) sprop1) + using sprop1 apply auto + done + hence membercongy:"i < 2^m \ vebt_member (treeList! i) x \ vebt_member (treeList' ! i) x" for i x + proof- + assume "i < 2^m" + show "vebt_member (treeList! i) x \ vebt_member (treeList' ! i) x" + proof + show "vebt_member (treeList ! i) x \ vebt_member (treeList' ! i) x" + proof- + assume "vebt_member (treeList ! i) x" + hence aaa:"both_member_options (treeList ! i) x" + by (metis \i < 2 ^ m\ both_member_options_equiv_member case4(1) case4(4) nth_mem) + have "x < 2^n" + by (metis \i < 2 ^ m\ \vebt_member (treeList ! i) x\ case4(1) case4(4) member_bound nth_mem) + hence "both_member_options (Node (Some (mi, ma)) deg treeList summary) (2^n*i+x)" + using both_member_options_from_chilf_to_complete_tree + [of " (2^n*i+x)" deg treeList mi ma summary] aaa high_inv[of x n i] + \i < 2 ^ m\ \vebt_member (treeList ! i) x\ low_inv[of x n i] + by (simp add: case4(4) case4(5) mult.commute sprop1) + hence "vebt_member (Node (Some (mi, ma)) deg treeList summary) (2^n*i+x)" using + valid_member_both_member_options[of "(Node (Some (mi, ma)) deg treeList summary)" deg "2^n*i+x"] + invar_vebt.intros(5)[of treeList n summary m deg mi ma] case4 by fastforce + hence "mi < (2^n*i+x) \ (2^n*i+x) \ ma" using vebt_mint.simps(3)[of mi ma deg treeList summary] + by (metis \i < 2 ^ m\ \x < 2 ^ n\ aaa case4(11) case4(4) case4(8) high_inv low_inv mult.commute nth_mem) + moreover have "both_member_options s (2^n*i +x)" + using \vebt_member (Node (Some (mi, ma)) deg treeList summary) (2 ^ n * i + x)\ both_member_options_equiv_member case4(12) case4(13) case4(5) set_vebt'_def by auto + have acffs:"both_member_options (treeList' ! (high ma n)) (low ma n)" + using acd calculation case4(10) high_bound_aux sprop1 verit_comp_simplify1(3) by blast + hence "both_member_options (treeList' ! i) x" + using both_member_options_from_complete_tree_to_child[of deg mi ma treeList' summary' "2^n*i+x"] + low_inv[of x n i] high_inv[of x n i] + by (smt (z3) Nat.add_0_right \vebt_member (Node (Some (mi, ma)) deg treeList summary) (2 ^ n * i + x)\ \x < 2 ^ n\ a0 add_Suc_right add_leD1 both_member_options_equiv_member calculation case4(12) case4(13) case4(5) diff_Suc_1 div_less div_mult_self4 infsplit le_add_diff_inverse2 mem_Collect_eq mult.commute mult_2 nat_1_add_1 nat_neq_iff one_less_numeral_iff semiring_norm(76) sprop1 set_vebt'_def zero_neq_numeral) + then show "vebt_member (treeList' ! i) x" + by (metis \i < 2 ^ m\ nth_mem sprop1 valid_member_both_member_options) + qed + show "vebt_member (treeList' ! i) x \ vebt_member (treeList ! i) x" + proof- + assume "vebt_member (treeList' ! i) x" + hence "vebt_member s (2^n*i +x)" using sprop1 both_member_options_from_chilf_to_complete_tree + [of "(2^n*i +x)" deg treeList' mi ma summary'] + by (smt (z3) Nat.add_0_right Suc_leD \i < 2 ^ m\ a0 add_Suc_right both_member_options_equiv_member case4(12) case4(5) diff_Suc_1 div_less div_mult_self4 even_Suc high_def infsplit low_inv member_bound mult.commute mult_2_right nat_1_add_1 nth_mem odd_add odd_two_times_div_two_nat plus_1_eq_Suc power_not_zero zero_neq_numeral) + hence "mi < (2^n*i +x) \ (2^n*i +x) \ ma " + using vebt_mint.simps(3)[of mi ma deg treeList' summary'] vebt_maxt.simps(3)[of mi ma deg treeList' summary'] + by (metis \i < 2 ^ m\ \vebt_member (treeList' ! i) x\ acd both_member_options_equiv_member case4(12) high_inv infsplit low_inv member_bound mi_eq_ma_no_ch mult.commute nth_mem sprop1) + moreover have "both_member_options (Node (Some (mi, ma)) deg treeList summary) (2^n*i +x)" + by (metis \vebt_member s (2 ^ n * i + x)\ add_leD1 both_member_options_equiv_member both_member_options_from_chilf_to_complete_tree calculation case4(1) case4(13) case4(5) maxbmo vebt_maxt.simps(3) mem_Collect_eq member_inv nat_neq_iff nth_mem one_add_one set_vebt'_def) + have "invar_vebt (treeList' ! i) n" + by (simp add: \i < 2 ^ m\ sprop1) + hence "x < 2^n" + using \vebt_member (treeList' ! i) x\ member_bound by auto + hence "both_member_options (treeList ! i) x" + using both_member_options_from_complete_tree_to_child[of deg mi ma treeList summary "(2^n*i +x)"] + low_inv[of x n i] high_inv[of x n i] + by (smt (z3) Nat.add_0_right Suc_leD \both_member_options (Node (Some (mi, ma)) deg treeList summary) (2 ^ n * i + x)\ \i < 2 ^ m\ a0 add_Suc_right calculation case4(11) case4(5) div_less div_mult_self4 mult.commute mult_2 nat_1_add_1 nat_neq_iff one_less_numeral_iff plus_1_eq_Suc semiring_norm(76) sprop1 zero_neq_numeral) + then show ?thesis + by (metis \i < 2 ^ m\ aca case4(1) nth_mem sprop1 valid_member_both_member_options) + qed + qed + qed + hence setcongy: "i < 2^m \ set_vebt' (treeList ! i) = set_vebt' (treeList' ! i)" for i unfolding set_vebt'_def by presburger + hence treecongy: "i < 2^m \ treeList ! i = treeList' ! i" for i + by (metis case4(1) case4(4) nth_mem sprop1) + hence "treeList = treeList'" + by (metis aca case4(4) nth_equalityI) + have "vebt_member summary x \ vebt_member summary' x" for x + by (metis \treeList = treeList'\ both_member_options_equiv_member case4(3) case4(7) member_bound sprop1 sumtreelistcong) + hence "set_vebt' summary = set_vebt' summary'" unfolding set_vebt'_def by auto + hence "summary = summary'" + using case4(2) sprop1 by blast + then show ?case + using \treeList = treeList'\ infsplit sprop1 by fastforce +qed + +corollary "invar_vebt t n \ set_vebt' t = {} \ t = vebt_buildup n" + by (metis buildup_gives_empty buildup_gives_valid deg_not_0 uniquetree) + +corollary unique_tree: "invar_vebt t n \ invar_vebt s n \ set_vebt t = set_vebt s \ s = t" + by (simp add: set_vebt_set_vebt'_valid uniquetree) + +corollary "invar_vebt t n \ set_vebt t = {} \ t = vebt_buildup n" + by (metis buildup_gives_empty buildup_gives_valid deg_not_0 uniquetree set_vebt_set_vebt'_valid) + +text \All valid trees can be generated by $vebt-insertion$ chains on an empty tree with same degree parameter:\ + +inductive perInsTrans::"VEBT \ VEBT \ bool" where + "perInsTrans t t"| + "(t = vebt_insert s x) \ perInsTrans t u \ perInsTrans s u" + +lemma perIT_concat:" perInsTrans s t \ perInsTrans t u \ perInsTrans s u" + by (induction s t rule: perInsTrans.induct) (simp add: perInsTrans.intros)+ + +lemma assumes "invar_vebt t n " shows + "perInsTrans (vebt_buildup n) t" +proof- + have "finite A \invar_vebt s n \set_vebt' s = B \ B\ A \ perInsTrans (vebt_buildup n) s" for s A B + proof (induction "card B" arbitrary: s B) + case 0 + then show ?case + by (metis buildup_gives_empty buildup_gives_valid card_eq_0_iff deg_not_0 perInsTrans.intros(1) set_vebt_finite uniquetree) + next + case (Suc car) + hence "finite B" + by (meson rev_finite_subset) + obtain x b where "B = insert x b \ x \ b" + by (metis Suc.hyps(2) card_Suc_eq) + have "set_vebt' (vebt_delete s x) = b" + using Suc.prems(2) Suc.prems(3) \B = insert x b \ x \ b\ delete_correct' by auto + moreover hence "perInsTrans (vebt_buildup n) (vebt_delete s x)" + by (metis Suc.hyps(1) Suc.hyps(2) Suc.prems(1) Suc.prems(2) Suc.prems(4) \B = insert x b \ x \ b\ \finite B\ card_insert_disjoint delete_pres_valid finite_insert nat.inject subset_insertI subset_trans) + hence "set_vebt' (vebt_insert (vebt_delete s x) x) = set_vebt' s" + by (metis Diff_insert_absorb Suc.prems(2) Suc.prems(3) Un_insert_right \B = insert x b \ x \ b\ boolean_algebra_cancel.sup0 delete_pres_valid delete_correct' insertI1 insert_corr mem_Collect_eq member_bound set_vebt'_def) + have "invar_vebt (vebt_insert (vebt_delete s x) x) n" + by (metis Suc.prems(2) Suc.prems(3) \B = insert x b \ x \ b\ delete_pres_valid insertI1 mem_Collect_eq member_bound set_vebt'_def valid_pres_insert) + moreover hence "vebt_insert (vebt_delete s x) x = s" + using Suc.prems(2) \set_vebt' (VEBT_Insert.vebt_insert (vebt_delete s x) x) = set_vebt' s\ uniquetree by force + ultimately show ?case + by (metis \perInsTrans (vebt_buildup n) (vebt_delete s x)\ perIT_concat perInsTrans.intros(1) perInsTrans.intros(2)) + qed + then show ?thesis + by (meson assms equalityD1 set_vebt_finite) +qed + +end +end diff --git a/thys/Van_Emde_Boas_Trees/document/root.bib b/thys/Van_Emde_Boas_Trees/document/root.bib new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/document/root.bib @@ -0,0 +1,141 @@ +@book{10.5555/1614191, +author = {Cormen, Thomas H. and Leiserson, Charles E. and Rivest, Ronald L. and Stein, Clifford}, +title = {Introduction to Algorithms, Third Edition}, +year = {2009}, +isbn = {0262033844}, +publisher = {The MIT Press}, +edition = {3rd}, +abstract = {If you had to buy just one text on algorithms, Introduction to Algorithms is a magnificent choice. The book begins by considering the mathematical foundations of the analysis of algorithms and maintains this mathematical rigor throughout the work. The tools developed in these opening sections are then applied to sorting, data structures, graphs, and a variety of selected algorithms including computational geometry, string algorithms, parallel models of computation, fast Fourier transforms (FFTs), and more. This book's strength lies in its encyclopedic range, clear exposition, and powerful analysis. Pseudo-code explanation of the algorithms coupled with proof of their accuracy makes this book is a great resource on the basic tools used to analyze the performance of algorithms.} +} + +@inproceedings{NipkowEH-ATVA20, +author = {Tobias Nipkow and Manuel Eberl and Maximilian P. L. Haslbeck}, +title = {Verified Textbook Algorithms. {A} Biased Survey}, +booktitle = {ATVA 2020, Automated Technology for Verification and Analysis}, +editor = {Dang Van Hung and Oleg Sokolsky}, +publisher = {Springer}, +series = {LNCS}, +volume = {12302}, +pages = {25-53}, +year =2020, +note = {Invited paper} +} + +@INPROCEEDINGS{4567861, + + author={van Emde Boas, P.}, + + booktitle={16th Annual Symposium on Foundations of Computer Science (sfcs 1975)}, + + title={Preserving order in a forest in less than logarithmic time}, + + year={1975}, + + volume={}, + + number={}, + + pages={75-84}, + + doi={10.1109/SFCS.1975.26}} + + @article{Emde_Boas_1976, + doi = {10.1007/bf01683268}, + url = {https://doi.org/10.1007%2Fbf01683268}, + year = 1976, + month = {dec}, + publisher = {Springer Science and Business Media {LLC}}, + volume = {10}, + number = {1}, + pages = {99--127}, + author = {P. Emde Boas and R. Kaas and E. Zijlstra}, + title = {Design and implementation of an efficient priority queue}, + journal = {Mathematical Systems Theory} +} + + +@misc{funalgs, +author = "{Tobias Nipkow, Jasmin Blanchette, Manuel Eberl, Alejandro Gómez-Londoño, Peter Lammich, Christian Sternagel, Simon Wimmer, Bohua Zhan}", +title = {Functional Algorithms, Verified!}, +year = 2021, +howpublished = {\url{https://functional-algorithms-verified.org/}} +} + +@article{RefImp, +author = {Lammich, Peter}, +year = {2019}, +month = {04}, +pages = {}, +title = {Refinement to Imperative HOL}, +volume = {62}, +journal = {Journal of Automated Reasoning}, +doi = {10.1007/s10817-017-9437-1} +} + +@inproceedings{dynhash, +author = {Dietzfelbinger, Martin and Karlin, Anna and Mehlhorn, Kurt and Meyer auf der Heide, Friedhelm and Rohnert, Hans and Tarjan, Robert}, +year = {1988}, +month = {01}, +pages = {524-531}, +title = {Dynamic Perfect Hashing: Upper and Lower Bounds}, +volume = {0}, +journal = {Foundations of Computer Science, IEEE Annual Symposium on}, +doi = {10.1109/SFCS.1988.21968} +} + +@inproceedings{8f77891e4e7647feb9515038709bc165, +title = "Generating Verified LLVM from Isabelle/HOL", +abstract = "We present a framework to generate verified LLVM programs from Isabelle/HOL. It is based on a code generator that generates LLVM text from a simplified fragment of LLVM, shallowly embedded into Isabelle/HOL. On top, we have developed a separation logic, a verification condition generator, and an LLVM backend to the Isabelle Refinement Framework. As case studies, we have produced verified LLVM implementations of binary search and the Knuth-Morris-Pratt string search algorithm. These are one order of magnitude faster than the Standard-ML implementations produced with the original Refinement Framework, and on par with unverified C implementations. Adoption of the original correctness proofs to the new LLVM backend was straightforward. The trusted code base of our approach is the shallow embedding of the LLVM fragment and the code generator, which is a pretty printer combined with some straightforward compilation steps", +keywords = "Isabelle/HOL, LLVM, Separation Logic, Verification condition generator, Code generation", +author = "Peter Lammich", +year = "2019", +month = jun, +day = "1", +language = "English", +booktitle = "ITP 2019: Interactive Theorem Proving", +note = "Interactive Theorem Proving, ITP 2019 ; Conference date: 08-09-2019 Through 13-09-2019", +url = "https://itp19.cecs.pdx.edu/", + +} + +@InProceedings{llvm, +author="Haslbeck, Maximilian P. L. +and Lammich, Peter", +editor="Yoshida, Nobuko", +title="For a Few Dollars More", +booktitle="Programming Languages and Systems", +year="2021", +publisher="Springer International Publishing", +address="Cham", +pages="292--319", +abstract="We present a framework to verify both, functional correctness and worst-case complexity of practically efficient algorithms. We implemented a stepwise refinement approach, using the novel concept of resource currencies to naturally structure the resource analysis along the refinement chain, and allow a fine-grained analysis of operation counts. Our framework targets the LLVM intermediate representation. We extend its semantics from earlier work with a cost model. As case study, we verify the correctness and {\$}{\$}O(n{\backslash}log n){\$}{\$}O(nlogn)worst-case complexity of an implementation of the introsort algorithm, whose performance is on par with the state-of-the-art implementation found in the GNU C++ Library.", +isbn="978-3-030-72019-3" +} + +@article{Separation_Logic_Imperative_HOL-AFP, + author = {Peter Lammich and Rene Meis}, + title = {A Separation Logic Framework for Imperative HOL}, + journal = {Archive of Formal Proofs}, + month = nov, + year = 2012, + note = {\url{https://isa-afp.org/entries/Separation_Logic_Imperative_HOL.html}, + Formal proof development}, + ISSN = {2150-914x}, +} + +@misc{zhan2018verifying, + title={Verifying Asymptotic Time Complexity of Imperative Programs in Isabelle}, + author={Bohua Zhan and Maximilian P. L. Haslbeck}, + year={2018}, + eprint={1802.01336}, + archivePrefix={arXiv}, + primaryClass={cs.LO} +} + +@phdthesis{ funalgdata, +author = {Milan Straka}, +title = {Functional Data Structures and Algorithms}, +school = {Charles University in Prague, Faculty of Mathematics and Physics}, +year = 2013, +note = {\url{https://ufal.mff.cuni.cz/~straka/theses/doctoral-functional_data_structures_and_algorithms.pdf}} +} diff --git a/thys/Van_Emde_Boas_Trees/document/root.tex b/thys/Van_Emde_Boas_Trees/document/root.tex new file mode 100644 --- /dev/null +++ b/thys/Van_Emde_Boas_Trees/document/root.tex @@ -0,0 +1,95 @@ +\documentclass[11pt,a4paper]{article} +\usepackage{isabelle,isabellesym} +%\usepackage{hyperref} +\usepackage{amsmath, amssymb, wasysym} +\usepackage[autostyle]{csquotes} +\usepackage{stmaryrd} +\usepackage[backend = bibtex, +url=false, + citestyle=numeric, + bibstyle = numeric, + maxnames=4, + minnames=3, + maxbibnames=99, + giveninits, + sorting = none, + uniquename=init]{biblatex} +% this should be the last package used +\usepackage{pdfsetup} + +\addtolength{\hoffset}{-1,5cm} +\addtolength{\textwidth}{3cm} +\bibliography{root} +\begin{document} + +\title{van Emde Boas Trees} +\author{Thomas Ammer and Peter Lammich} +\maketitle + +\begin{abstract} + \indent The \textit{van Emde Boas tree} or \textit{van Emde Boas priority queue}~\cite{4567861, Emde_Boas_1976} is a data structure supporting membership test, insertion, predecessor and successor search, minimum and maximum determination and deletion in $\mathcal{O}(\log \log \vert \mathcal{U}\vert)$ time, where $\mathcal{U} = \lbrace0, \, ...,\, 2^n-1 \rbrace$ is the overall range to be considered. + The presented formalization follows Chapter~20 of the popular \textit{Introduction to Algorithms (3rd ed.)}~\cite{10.5555/1614191} by Cormen, Leiserson, Rivest and Stein (CLRS), extending the list + of formally verified CLRS algorithms~\cite{NipkowEH-ATVA20}. Our current formalization is based on the first author's bachelor's thesis.\\ + \indent First, we prove correct a \emph{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~\cite{funalgs} for the operations.\\ + \indent Next, we refine the operations to Imperative HOL~\cite{Separation_Logic_Imperative_HOL-AFP, refimp} + with time~\cite{zhan2018verifying}, 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. + % \indent Usually, data structures for representing dynamic sets map keys to satelite data. This may impede a proper invariant definition and thus we ommit the issue of storing associated values. This is also done in the popular~\cite{CLRS} textbook which is our main referrence. However, a future enahcement in order to store satelite values may completely reuse the current implementation without any adaptations necessary.\\ +\end{abstract} + +% \begin{small} +% \textbf{Note} The present formalization is oriented towards Chapter 20 of the popular \textit{Introduction to Algorithms (3rd ed.)}~\cite{10.5555/1614191} by Cormen, Leiserson, Rivest and Stein. +% Therefore, it does not support the treatment of associated satellite data.\\ +% \indent Our work extends a list~\cite{NipkowEH-ATVA20} of CLRS textbook algorithms already verified in Isabelle. +% \end{small} + +\pagebreak + +\tableofcontents +\pagebreak +%\parindent 0pt\parskip 0.5ex +\isabellestyle{it} +% include generated text of all theories +\input{session} +\section{Conclusion} +We have formalized van Emde Boas trees in Isabelle, proving correct a functional and an imperative version, together with space and run-time bounds. +This work amends a list~\cite{NipkowEH-ATVA20} of formally verified CLRS algorithms~\cite{10.5555/1614191}. + +% \indent \indent Please note that this work extends a collection~\cite{NipkowEH-ATVA20} of CLRS textbook algorithms~\cite{10.5555/1614191} verified in Isabelle/HOL.\\ +Closing we sketch some enhancements of van Emde Boas trees in Isabelle. +An examination of the data structure points out that there is probably a \textit{join} operation with the semantics $set\text{-}vebt \;(vebt\text{-}join\; s \; t) = set\text{-}vebt \;s\, \cup\, set\text{-}vebt\; t$. + We make the restriction of joining only valid trees with equal degree numbers. + Obviously, the join of two leaves is trivial. + If one tree is empty or singleton, a join is implemented by immediately returning the other tree or performing an insertion before. + Otherwise, summary and subtrees are to be joined recursively and afterwards we have to determine minimum and maximum. Certainly, this last step can be complicated, because argument trees may also coincide on minima or maxima. + + One may also consider the treatment of associated satellite data. + Those are to be stored in ordinary subtrees, whereas the definition of summary trees does not have to be changed. + We can transfer this to Isabelle by introducing another data type representing van Emde Boas trees. + The adapted $naive\text{-}member$ and $membermima$ still refer to integer keys, but we add an auxiliary function $assoc$ such that $assoc\; t \; x \; y$ holds iff the key $x$ is associated with the value $y$. + A $both\text{-}member\text{-}options$ is also defined and can be used for specifying a suitable validness invariant. We may show a conjecture like $both\text{-}member\text{-}options \; t \;x \longleftrightarrow \exists \, y. \; assoc \; t \; x \; y$. Besides, valid trees enforce keys to be associated with at most one value. + All canonical functions $f$ are shifted to the new type and return a key-value pair $(x, \, y)$ or the modified tree. Proofs for being $x$ the desired successor etc. are obtained by reuse and adaptation of prior proofs. + In addition, modified canonical functions $f'$ may only return the associated values $y$. We show the proposition $\exists \, x. \;f \; t \; i = (x, \, y) \longleftrightarrow f'\; t \; i = y$. + All writing operations require a reasoning regarding the proper (non-)modification of associations. The modified functions $f'$ are to be exposed to a user later on. + +Moreover, we did not consider lazy implementation. +Currently, $vebt\text{-}buildup \; n$ generates a full van Emde Boas tree of degree $n$. A \textit{lazy implementation} would construct a subtree only if needed. +From this just a constant amount of additional effort per recursive step will arise. Thereby, proven running time bounds of $\mathcal{O}(\log \log u)$ will be preserved. + Beside this, a lazy implementation can also be obtained by exporting verified Isabelle code to Haskell, which heavily applies the lazy evaluation technique. + +Obviously, a lazy implementation would drastically reduce memory usage. +Each insertion allocates $\mathcal{O}(\log \log u)$ space and hence an implementation that does not store empty subtrees gives us memory consumption in $\mathcal{O}(n \cdot \log \log u)$ where $n$ is the number of elements currently stored. + %\footnote{This proposition holds, because there is constant memory allocation per recursive step and recursion depth is bounded by tree heights.} + Furthermore, one may replace ordinary arrays by \textit{dynamic perfect hashing}~\cite{dynhash} allowing treatment of elements in (amortized) constant time and linear space. + Unfortunately, a linear memory consumption in $\mathcal{O}(n)$ is achieved at cost of some worst case runtime bounds~\cite{funalgdata}. + By this, $\mathcal{O}(\log \log u)$ is turned to an amortized bound for $vebt\text{-}insert$ and $vebt\text{-}delete$, since the complexity of those functions is indeed affected by the amortization. + An implementation of this van Emde Boas tree variant requires verified dynamic perfect hashing and amortization in Isabelle to build on. + + We used Imperative HOL due to its support of arrays and type reflexive references that are necessary for setting up a recursive tree data structure. + For generating verified code, however, there also exist other frameworks, e.g. Isabelle LLVM~\cite{8f77891e4e7647feb9515038709bc165}~\cite{llvm}. It supports refinement-based verification of correctness and worst-case time complexities. + Additionally, verified programs can be exported to LLVM code, which itself is compiled to executable machine code. Strikingly, code of the introsort algorithm generated by this formalization stayed competitive with the GNU C++ library~\cite{llvm}. +\pagebreak +\printbibliography{} +\end{document} diff --git a/web/entries/AI_Planning_Languages_Semantics.html b/web/entries/AI_Planning_Languages_Semantics.html --- a/web/entries/AI_Planning_Languages_Semantics.html +++ b/web/entries/AI_Planning_Languages_Semantics.html @@ -1,202 +1,202 @@ AI Planning Languages Semantics - Archive of Formal Proofs

 

 

 

 

 

 

AI Planning Languages Semantics

 

Title: AI Planning Languages Semantics
Authors: Mohammad Abdulaziz and - Peter Lammich (lammich /at/ in /dot/ tum /dot/ de) + Peter Lammich
Submission date: 2020-10-29
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.
BibTeX:
@article{AI_Planning_Languages_Semantics-AFP,
   author  = {Mohammad Abdulaziz and Peter Lammich},
   title   = {AI Planning Languages Semantics},
   journal = {Archive of Formal Proofs},
   month   = oct,
   year    = 2020,
   note    = {\url{https://isa-afp.org/entries/AI_Planning_Languages_Semantics.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: Certification_Monads, Containers, Propositional_Proof_Systems, Show
Used by: Verified_SAT_Based_AI_Planning

\ No newline at end of file diff --git a/web/entries/Algebraic_Numbers.html b/web/entries/Algebraic_Numbers.html --- a/web/entries/Algebraic_Numbers.html +++ b/web/entries/Algebraic_Numbers.html @@ -1,241 +1,241 @@ Algebraic Numbers in Isabelle/HOL - Archive of Formal Proofs

 

 

 

 

 

 

Algebraic Numbers in Isabelle/HOL

 

- +
Title: Algebraic Numbers in Isabelle/HOL
Authors: René Thiemann (rene /dot/ thiemann /at/ uibk /dot/ ac /dot/ at), Akihisa Yamada (akihisa /dot/ yamada /at/ aist /dot/ go /dot/ jp) and Sebastiaan Joosten
Contributor: Manuel Eberl
Submission 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.

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
BibTeX:
@article{Algebraic_Numbers-AFP,
   author  = {René Thiemann and Akihisa Yamada and Sebastiaan Joosten},
   title   = {Algebraic Numbers in Isabelle/HOL},
   journal = {Archive of Formal Proofs},
   month   = dec,
   year    = 2015,
   note    = {\url{https://isa-afp.org/entries/Algebraic_Numbers.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: Berlekamp_Zassenhaus, Sturm_Sequences
Used by:BenOr_Kozen_Reif, Cubic_Quartic_Equations, Hermite_Lindemann, LLL_Basis_Reduction
BenOr_Kozen_Reif, Cubic_Quartic_Equations, Factor_Algebraic_Polynomial, Hermite_Lindemann, LLL_Basis_Reduction

\ No newline at end of file diff --git a/web/entries/Automatic_Refinement.html b/web/entries/Automatic_Refinement.html --- a/web/entries/Automatic_Refinement.html +++ b/web/entries/Automatic_Refinement.html @@ -1,246 +1,246 @@ Automatic Data Refinement - Archive of Formal Proofs

 

 

 

 

 

 

Automatic Data Refinement

 

- +
Title: Automatic Data Refinement
Author: - Peter Lammich (lammich /at/ in /dot/ tum /dot/ de) + Peter Lammich
Submission 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.

BibTeX:
@article{Automatic_Refinement-AFP,
   author  = {Peter Lammich},
   title   = {Automatic Data Refinement},
   journal = {Archive of Formal Proofs},
   month   = oct,
   year    = 2013,
   note    = {\url{https://isa-afp.org/entries/Automatic_Refinement.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Used by:Containers, Dict_Construction, IP_Addresses, JinjaThreads, Network_Security_Policy_Verification, Refine_Monadic, ROBDD, Separation_Logic_Imperative_HOL, UpDown_Scheme
Containers, Dict_Construction, IP_Addresses, JinjaThreads, Network_Security_Policy_Verification, Refine_Monadic, ROBDD, Separation_Logic_Imperative_HOL, UpDown_Scheme, Van_Emde_Boas_Trees

\ No newline at end of file diff --git a/web/entries/Binomial-Heaps.html b/web/entries/Binomial-Heaps.html --- a/web/entries/Binomial-Heaps.html +++ b/web/entries/Binomial-Heaps.html @@ -1,282 +1,282 @@ Binomial Heaps and Skew Binomial Heaps - Archive of Formal Proofs

 

 

 

 

 

 

Binomial Heaps and Skew Binomial Heaps

 

Title: Binomial Heaps and Skew Binomial Heaps
Authors: Rene Meis (rene /dot/ meis /at/ uni-due /dot/ de), Finn Nielsen (finn /dot/ nielsen /at/ uni-muenster /dot/ de) and - Peter Lammich (lammich /at/ in /dot/ tum /dot/ de) + Peter Lammich
Submission date: 2010-10-28
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.
BibTeX:
@article{Binomial-Heaps-AFP,
   author  = {Rene Meis and Finn Nielsen and Peter Lammich},
   title   = {Binomial Heaps and Skew Binomial Heaps},
   journal = {Archive of Formal Proofs},
   month   = oct,
   year    = 2010,
   note    = {\url{https://isa-afp.org/entries/Binomial-Heaps.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Used by: Collections, JinjaThreads

\ No newline at end of file diff --git a/web/entries/Bounded_Deducibility_Security.html b/web/entries/Bounded_Deducibility_Security.html --- a/web/entries/Bounded_Deducibility_Security.html +++ b/web/entries/Bounded_Deducibility_Security.html @@ -1,247 +1,247 @@ Bounded-Deducibility Security - Archive of Formal Proofs

 

 

 

 

 

 

Bounded-Deducibility Security

 

Title: Bounded-Deducibility Security
Authors: Andrei Popescu, - Peter Lammich (lammich /at/ in /dot/ tum /dot/ de) and + Peter Lammich and Thomas Bauereiss (thomas /at/ bauereiss /dot/ name)
Submission date: 2014-04-22
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.
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).
BibTeX:
@article{Bounded_Deducibility_Security-AFP,
   author  = {Andrei Popescu and Peter Lammich and Thomas Bauereiss},
   title   = {Bounded-Deducibility Security},
   journal = {Archive of Formal Proofs},
   month   = apr,
   year    = 2014,
   note    = {\url{https://isa-afp.org/entries/Bounded_Deducibility_Security.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Used by: BD_Security_Compositional, CoCon, CoSMed

\ No newline at end of file diff --git a/web/entries/CAVA_Automata.html b/web/entries/CAVA_Automata.html --- a/web/entries/CAVA_Automata.html +++ b/web/entries/CAVA_Automata.html @@ -1,255 +1,255 @@ The CAVA Automata Library - Archive of Formal Proofs

 

 

 

 

 

 

The CAVA Automata Library

 

Title: The CAVA Automata Library
Author: - Peter Lammich (lammich /at/ in /dot/ tum /dot/ de) + Peter Lammich
Submission date: 2014-05-28
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.

BibTeX:
@article{CAVA_Automata-AFP,
   author  = {Peter Lammich},
   title   = {The CAVA Automata Library},
   journal = {Archive of Formal Proofs},
   month   = may,
   year    = 2014,
   note    = {\url{https://isa-afp.org/entries/CAVA_Automata.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Used by: DFS_Framework, Flow_Networks, Formal_SSA, Gabow_SCC, LTL_to_GBA, Promela

\ No newline at end of file diff --git a/web/entries/CAVA_LTL_Modelchecker.html b/web/entries/CAVA_LTL_Modelchecker.html --- a/web/entries/CAVA_LTL_Modelchecker.html +++ b/web/entries/CAVA_LTL_Modelchecker.html @@ -1,261 +1,261 @@ A Fully Verified Executable LTL Model Checker - Archive of Formal Proofs

 

 

 

 

 

 

A Fully Verified Executable LTL Model Checker

 

Title: A Fully Verified Executable LTL Model Checker
Authors: Javier Esparza, - Peter Lammich (lammich /at/ in /dot/ tum /dot/ de), + Peter Lammich, René Neumann (rene /dot/ neumann /at/ in /dot/ tum /dot/ de), Tobias Nipkow, Alexander Schimpf (schimpfa /at/ informatik /dot/ uni-freiburg /dot/ de) and Jan-Georg Smaus
Submission date: 2014-05-28
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.

BibTeX:
@article{CAVA_LTL_Modelchecker-AFP,
   author  = {Javier Esparza and Peter Lammich and René Neumann and Tobias Nipkow and Alexander Schimpf and Jan-Georg Smaus},
   title   = {A Fully Verified Executable LTL Model Checker},
   journal = {Archive of Formal Proofs},
   month   = may,
   year    = 2014,
   note    = {\url{https://isa-afp.org/entries/CAVA_LTL_Modelchecker.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License

\ No newline at end of file diff --git a/web/entries/CoCon.html b/web/entries/CoCon.html --- a/web/entries/CoCon.html +++ b/web/entries/CoCon.html @@ -1,202 +1,202 @@ CoCon: A Confidentiality-Verified Conference Management System - Archive of Formal Proofs

 

 

 

 

 

 

CoCon: A Confidentiality-Verified Conference Management System

 

Title: CoCon: A Confidentiality-Verified Conference Management System
Authors: Andrei Popescu, - Peter Lammich (lammich /at/ in /dot/ tum /dot/ de) and + Peter Lammich and Thomas Bauereiss (thomas /at/ bauereiss /dot/ name)
Submission date: 2021-08-16
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.
BibTeX:
@article{CoCon-AFP,
   author  = {Andrei Popescu and Peter Lammich and Thomas Bauereiss},
   title   = {CoCon: A Confidentiality-Verified Conference Management System},
   journal = {Archive of Formal Proofs},
   month   = aug,
   year    = 2021,
   note    = {\url{https://isa-afp.org/entries/CoCon.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: Bounded_Deducibility_Security, Fresh_Identifiers

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

 

 

 

 

 

 

Collections Framework

 

Title: Collections Framework
Author: - Peter Lammich (lammich /at/ in /dot/ tum /dot/ de) + Peter Lammich
Contributors: Andreas Lochbihler and Thomas Tuerk
Submission date: 2009-11-25
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.
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})
BibTeX:
@article{Collections-AFP,
   author  = {Peter Lammich},
   title   = {Collections Framework},
   journal = {Archive of Formal Proofs},
   month   = nov,
   year    = 2009,
   note    = {\url{https://isa-afp.org/entries/Collections.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: Binomial-Heaps, Finger-Trees, Native_Word, Refine_Monadic, Trie
Used by: Abstract_Completeness, Containers, Deriving, Dijkstra_Shortest_Path, Formal_SSA, JinjaThreads, Kruskal, ROBDD, Separation_Logic_Imperative_HOL, Transition_Systems_and_Automata, Transitive-Closure, Tree-Automata

\ No newline at end of file diff --git a/web/entries/Cubic_Quartic_Equations.html b/web/entries/Cubic_Quartic_Equations.html --- a/web/entries/Cubic_Quartic_Equations.html +++ b/web/entries/Cubic_Quartic_Equations.html @@ -1,197 +1,195 @@ Solving Cubic and Quartic Equations - Archive of Formal Proofs

 

 

 

 

 

 

Solving Cubic and Quartic Equations

 

- + - - - +
Title: Solving Cubic and Quartic Equations
Author: René Thiemann (rene /dot/ thiemann /at/ uibk /dot/ ac /dot/ at)
Submission date: 2021-09-03
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.

BibTeX:
@article{Cubic_Quartic_Equations-AFP,
   author  = {René Thiemann},
   title   = {Solving Cubic and Quartic Equations},
   journal = {Archive of Formal Proofs},
   month   = sep,
   year    = 2021,
   note    = {\url{https://isa-afp.org/entries/Cubic_Quartic_Equations.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on:Algebraic_Numbers, Complex_Geometry
Algebraic_Numbers, Complex_Geometry, Factor_Algebraic_Polynomial
Used by:Factor_Algebraic_Polynomial

\ No newline at end of file diff --git a/web/entries/DFS_Framework.html b/web/entries/DFS_Framework.html --- a/web/entries/DFS_Framework.html +++ b/web/entries/DFS_Framework.html @@ -1,246 +1,246 @@ A Framework for Verifying Depth-First Search Algorithms - Archive of Formal Proofs

 

 

 

 

 

 

A Framework for Verifying Depth-First Search Algorithms

 

Title: A Framework for Verifying Depth-First Search Algorithms
Authors: - Peter Lammich (lammich /at/ in /dot/ tum /dot/ de) and + Peter Lammich and René Neumann (rene /dot/ neumann /at/ in /dot/ tum /dot/ de)
Submission date: 2016-07-05
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

BibTeX:
@article{DFS_Framework-AFP,
   author  = {Peter Lammich and René Neumann},
   title   = {A Framework for Verifying Depth-First Search Algorithms},
   journal = {Archive of Formal Proofs},
   month   = jul,
   year    = 2016,
   note    = {\url{https://isa-afp.org/entries/DFS_Framework.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: CAVA_Automata
Used by: Flow_Networks, Refine_Imperative_HOL, Transition_Systems_and_Automata

\ No newline at end of file diff --git a/web/entries/Deriving.html b/web/entries/Deriving.html --- a/web/entries/Deriving.html +++ b/web/entries/Deriving.html @@ -1,239 +1,239 @@ Deriving class instances for datatypes - Archive of Formal Proofs

 

 

 

 

 

 

Deriving class instances for datatypes

 

- +
Title: Deriving class instances for datatypes
Authors: Christian Sternagel (c /dot/ sternagel /at/ gmail /dot/ com) and René Thiemann (rene /dot/ thiemann /at/ uibk /dot/ ac /dot/ at)
Submission date: 2015-03-11
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.

BibTeX:
@article{Deriving-AFP,
   author  = {Christian Sternagel and René Thiemann},
   title   = {Deriving class instances for datatypes},
   journal = {Archive of Formal Proofs},
   month   = mar,
   year    = 2015,
   note    = {\url{https://isa-afp.org/entries/Deriving.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: Collections
Used by:Affine_Arithmetic, Containers, Datatype_Order_Generator, Formula_Derivatives, Groebner_Bases, LTL_Master_Theorem, MSO_Regex_Equivalence, Real_Impl, Show
Affine_Arithmetic, Containers, Datatype_Order_Generator, Formula_Derivatives, Groebner_Bases, LTL_Master_Theorem, MSO_Regex_Equivalence, Real_Impl, Show, Van_Emde_Boas_Trees

\ No newline at end of file diff --git a/web/entries/Dijkstra_Shortest_Path.html b/web/entries/Dijkstra_Shortest_Path.html --- a/web/entries/Dijkstra_Shortest_Path.html +++ b/web/entries/Dijkstra_Shortest_Path.html @@ -1,268 +1,268 @@ Dijkstra's Shortest Path Algorithm - Archive of Formal Proofs

 

 

 

 

 

 

Dijkstra's Shortest Path Algorithm

 

Title: Dijkstra's Shortest Path Algorithm
Authors: Benedikt Nordhoff (b /dot/ n /at/ wwu /dot/ de) and - Peter Lammich (lammich /at/ in /dot/ tum /dot/ de) + Peter Lammich
Submission 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.
BibTeX:
@article{Dijkstra_Shortest_Path-AFP,
   author  = {Benedikt Nordhoff and Peter Lammich},
   title   = {Dijkstra's Shortest Path Algorithm},
   journal = {Archive of Formal Proofs},
   month   = jan,
   year    = 2012,
   note    = {\url{https://isa-afp.org/entries/Dijkstra_Shortest_Path.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: Collections
Used by: Formal_SSA, Koenigsberg_Friendship, Refine_Imperative_HOL

\ No newline at end of file diff --git a/web/entries/DiscretePricing.html b/web/entries/DiscretePricing.html --- a/web/entries/DiscretePricing.html +++ b/web/entries/DiscretePricing.html @@ -1,222 +1,222 @@ Pricing in discrete financial models - Archive of Formal Proofs

 

 

 

 

 

 

Pricing in discrete financial models

 

Title: Pricing in discrete financial models
Author: - Mnacho Echenim + Mnacho Echenim (mnacho /dot/ echenim /at/ univ-grenoble-alpes /dot/ fr)
Submission date: 2018-07-16
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.
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)
BibTeX:
@article{DiscretePricing-AFP,
   author  = {Mnacho Echenim},
   title   = {Pricing in discrete financial models},
   journal = {Archive of Formal Proofs},
   month   = jul,
   year    = 2018,
   note    = {\url{https://isa-afp.org/entries/DiscretePricing.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License

\ No newline at end of file diff --git a/web/entries/EdmondsKarp_Maxflow.html b/web/entries/EdmondsKarp_Maxflow.html --- a/web/entries/EdmondsKarp_Maxflow.html +++ b/web/entries/EdmondsKarp_Maxflow.html @@ -1,228 +1,228 @@ Formalizing the Edmonds-Karp Algorithm - Archive of Formal Proofs

 

 

 

 

 

 

Formalizing the Edmonds-Karp Algorithm

 

Title: Formalizing the Edmonds-Karp Algorithm
Authors: - Peter Lammich (lammich /at/ in /dot/ tum /dot/ de) and + Peter Lammich and S. Reza Sefidgar
Submission date: 2016-08-12
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.
BibTeX:
@article{EdmondsKarp_Maxflow-AFP,
   author  = {Peter Lammich and S. Reza Sefidgar},
   title   = {Formalizing the Edmonds-Karp Algorithm},
   journal = {Archive of Formal Proofs},
   month   = aug,
   year    = 2016,
   note    = {\url{https://isa-afp.org/entries/EdmondsKarp_Maxflow.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: Flow_Networks
Used by: MFMC_Countable

\ No newline at end of file diff --git a/web/entries/Epistemic_Logic.html b/web/entries/Epistemic_Logic.html --- a/web/entries/Epistemic_Logic.html +++ b/web/entries/Epistemic_Logic.html @@ -1,217 +1,218 @@ Epistemic Logic: Completeness of Modal Logics - Archive of Formal Proofs

 

 

 

 

 

 

Epistemic Logic: Completeness of Modal Logics

 

+(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.
Title: Epistemic Logic: Completeness of Modal Logics
Author: Asta Halkjær From
Submission date: 2018-10-29
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).
Change history: [2021-04-15]: Added completeness of modal logics T, KB, K4, S4 and S5.
BibTeX:
@article{Epistemic_Logic-AFP,
   author  = {Asta Halkjær From},
   title   = {Epistemic Logic: Completeness of Modal Logics},
   journal = {Archive of Formal Proofs},
   month   = oct,
   year    = 2018,
   note    = {\url{https://isa-afp.org/entries/Epistemic_Logic.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Used by: Public_Announcement_Logic

\ No newline at end of file diff --git a/web/entries/FOL_Seq_Calc1.html b/web/entries/FOL_Seq_Calc1.html --- a/web/entries/FOL_Seq_Calc1.html +++ b/web/entries/FOL_Seq_Calc1.html @@ -1,216 +1,217 @@ A Sequent Calculus for First-Order Logic - Archive of Formal Proofs

 

 

 

 

 

 

A Sequent Calculus for First-Order Logic

 

+Mathematical Logic for Computer Science. +Paper: http://ceur-ws.org/Vol-3002/paper7.pdf.
Title: A Sequent Calculus for First-Order Logic
Author: Asta Halkjær From
Contributors: Alexander Birch Jensen, Anders Schlichtkrull and Jørgen Villadsen
Submission date: 2019-07-18
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.
BibTeX:
@article{FOL_Seq_Calc1-AFP,
   author  = {Asta Halkjær From},
   title   = {A Sequent Calculus for First-Order Logic},
   journal = {Archive of Formal Proofs},
   month   = jul,
   year    = 2019,
   note    = {\url{https://isa-afp.org/entries/FOL_Seq_Calc1.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: FOL-Fitting

\ No newline at end of file diff --git a/web/entries/Factor_Algebraic_Polynomial.html b/web/entries/Factor_Algebraic_Polynomial.html --- a/web/entries/Factor_Algebraic_Polynomial.html +++ b/web/entries/Factor_Algebraic_Polynomial.html @@ -1,200 +1,202 @@ Factorization of Polynomials with Algebraic Coefficients - Archive of Formal Proofs

 

 

 

 

 

 

Factorization of Polynomials with Algebraic Coefficients

 

+ + + -
Title: Factorization of Polynomials with Algebraic Coefficients
Authors: Manuel Eberl and René Thiemann (rene /dot/ thiemann /at/ uibk /dot/ ac /dot/ at)
Submission date: 2021-11-08
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.
BibTeX:
@article{Factor_Algebraic_Polynomial-AFP,
   author  = {Manuel Eberl and René Thiemann},
   title   = {Factorization of Polynomials with Algebraic Coefficients},
   journal = {Archive of Formal Proofs},
   month   = nov,
   year    = 2021,
   note    = {\url{https://isa-afp.org/entries/Factor_Algebraic_Polynomial.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on:Algebraic_Numbers, Hermite_Lindemann, Polynomials
Used by: Cubic_Quartic_Equations

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

 

 

 

 

 

 

Finger Trees

 

Title: Finger Trees
Authors: Benedikt Nordhoff (b /dot/ n /at/ wwu /dot/ de), Stefan Körner (s_koer03 /at/ uni-muenster /dot/ de) and - Peter Lammich (lammich /at/ in /dot/ tum /dot/ de) + Peter Lammich
Submission date: 2010-10-28
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.
BibTeX:
@article{Finger-Trees-AFP,
   author  = {Benedikt Nordhoff and Stefan Körner and Peter Lammich},
   title   = {Finger Trees},
   journal = {Archive of Formal Proofs},
   month   = oct,
   year    = 2010,
   note    = {\url{https://isa-afp.org/entries/Finger-Trees.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Used by: Collections, Containers, JinjaThreads

\ No newline at end of file diff --git a/web/entries/Flow_Networks.html b/web/entries/Flow_Networks.html --- a/web/entries/Flow_Networks.html +++ b/web/entries/Flow_Networks.html @@ -1,227 +1,227 @@ Flow Networks and the Min-Cut-Max-Flow Theorem - Archive of Formal Proofs

 

 

 

 

 

 

Flow Networks and the Min-Cut-Max-Flow Theorem

 

Title: Flow Networks and the Min-Cut-Max-Flow Theorem
Authors: - Peter Lammich (lammich /at/ in /dot/ tum /dot/ de) and + Peter Lammich and S. Reza Sefidgar
Submission date: 2017-06-01
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.
BibTeX:
@article{Flow_Networks-AFP,
   author  = {Peter Lammich and S. Reza Sefidgar},
   title   = {Flow Networks and the Min-Cut-Max-Flow Theorem},
   journal = {Archive of Formal Proofs},
   month   = jun,
   year    = 2017,
   note    = {\url{https://isa-afp.org/entries/Flow_Networks.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: CAVA_Automata, DFS_Framework, Program-Conflict-Analysis, Refine_Imperative_HOL
Used by: EdmondsKarp_Maxflow, Prpu_Maxflow

\ No newline at end of file diff --git a/web/entries/Floyd_Warshall.html b/web/entries/Floyd_Warshall.html --- a/web/entries/Floyd_Warshall.html +++ b/web/entries/Floyd_Warshall.html @@ -1,229 +1,229 @@ The Floyd-Warshall Algorithm for Shortest Paths - Archive of Formal Proofs

 

 

 

 

 

 

The Floyd-Warshall Algorithm for Shortest Paths

 

Title: The Floyd-Warshall Algorithm for Shortest Paths
Authors: Simon Wimmer and - Peter Lammich (lammich /at/ in /dot/ tum /dot/ de) + Peter Lammich
Submission date: 2017-05-08
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.
BibTeX:
@article{Floyd_Warshall-AFP,
   author  = {Simon Wimmer and Peter Lammich},
   title   = {The Floyd-Warshall Algorithm for Shortest Paths},
   journal = {Archive of Formal Proofs},
   month   = may,
   year    = 2017,
   note    = {\url{https://isa-afp.org/entries/Floyd_Warshall.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: Refine_Imperative_HOL

\ No newline at end of file diff --git a/web/entries/Gabow_SCC.html b/web/entries/Gabow_SCC.html --- a/web/entries/Gabow_SCC.html +++ b/web/entries/Gabow_SCC.html @@ -1,251 +1,251 @@ Verified Efficient Implementation of Gabow's Strongly Connected Components Algorithm - Archive of Formal Proofs

 

 

 

 

 

 

Verified Efficient Implementation of Gabow's Strongly Connected Components Algorithm

 

Title: Verified Efficient Implementation of Gabow's Strongly Connected Components Algorithm
Author: - Peter Lammich (lammich /at/ in /dot/ tum /dot/ de) + Peter Lammich
Submission date: 2014-05-28
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.
BibTeX:
@article{Gabow_SCC-AFP,
   author  = {Peter Lammich},
   title   = {Verified Efficient Implementation of Gabow's Strongly Connected Components Algorithm},
   journal = {Archive of Formal Proofs},
   month   = may,
   year    = 2014,
   note    = {\url{https://isa-afp.org/entries/Gabow_SCC.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: CAVA_Automata
Used by: Transition_Systems_and_Automata

\ No newline at end of file diff --git a/web/entries/Hahn_Jordan_Decomposition.html b/web/entries/Hahn_Jordan_Decomposition.html new file mode 100644 --- /dev/null +++ b/web/entries/Hahn_Jordan_Decomposition.html @@ -0,0 +1,198 @@ + + + + +The Hahn and Jordan Decomposition Theorems - Archive of Formal Proofs + + + + + + + + + + + + + + + + + + + + + + + + +
+

 

+ + + +

 

+

 

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

 

+

 

+
+
+

 

+

The + + Hahn + + and + + Jordan + + Decomposition + + Theorems + +

+

 

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Title:The Hahn and Jordan Decomposition Theorems
+ Authors: + + Marie Cousin (marie /dot/ cousin /at/ grenoble-inp /dot/ org), + Mnacho Echenim (mnacho /dot/ echenim /at/ univ-grenoble-alpes /dot/ fr) and + Hervé Guiol (herve /dot/ guiol /at/ univ-grenoble-alpes /dot/ fr) +
Submission date:2021-11-19
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.
BibTeX: +
@article{Hahn_Jordan_Decomposition-AFP,
+  author  = {Marie Cousin and Mnacho Echenim and Hervé Guiol},
+  title   = {The Hahn and Jordan Decomposition Theorems},
+  journal = {Archive of Formal Proofs},
+  month   = nov,
+  year    = 2021,
+  note    = {\url{https://isa-afp.org/entries/Hahn_Jordan_Decomposition.html},
+            Formal proof development},
+  ISSN    = {2150-914x},
+}
+
License:BSD License
+ +

+ + + + + + + + + + + + + + + + + + +
+
+ + + + + + \ No newline at end of file diff --git a/web/entries/Hermite_Lindemann.html b/web/entries/Hermite_Lindemann.html --- a/web/entries/Hermite_Lindemann.html +++ b/web/entries/Hermite_Lindemann.html @@ -1,210 +1,212 @@ The Hermite–Lindemann–Weierstraß Transcendence Theorem - Archive of Formal Proofs

 

 

 

 

 

 

The Hermite–Lindemann–Weierstraß Transcendence Theorem

 

- + + +
Title: The Hermite–Lindemann–Weierstraß Transcendence Theorem
Author: Manuel Eberl
Submission date: 2021-03-03
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\}$
BibTeX:
@article{Hermite_Lindemann-AFP,
   author  = {Manuel Eberl},
   title   = {The Hermite–Lindemann–Weierstraß Transcendence Theorem},
   journal = {Archive of Formal Proofs},
   month   = mar,
   year    = 2021,
   note    = {\url{https://isa-afp.org/entries/Hermite_Lindemann.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: Algebraic_Numbers, Pi_Transcendental, Power_Sum_Polynomials
Used by:Factor_Algebraic_Polynomial

\ No newline at end of file diff --git a/web/entries/HyperCTL.html b/web/entries/HyperCTL.html --- a/web/entries/HyperCTL.html +++ b/web/entries/HyperCTL.html @@ -1,239 +1,239 @@ A shallow embedding of HyperCTL* - Archive of Formal Proofs

 

 

 

 

 

 

A shallow embedding of HyperCTL*

 

Title: A shallow embedding of HyperCTL*
Authors: Markus N. Rabe, - Peter Lammich (lammich /at/ in /dot/ tum /dot/ de) and + Peter Lammich and Andrei Popescu
Submission date: 2014-04-16
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.
BibTeX:
@article{HyperCTL-AFP,
   author  = {Markus N. Rabe and Peter Lammich and Andrei Popescu},
   title   = {A shallow embedding of HyperCTL*},
   journal = {Archive of Formal Proofs},
   month   = apr,
   year    = 2014,
   note    = {\url{https://isa-afp.org/entries/HyperCTL.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License

\ No newline at end of file diff --git a/web/entries/IMP2.html b/web/entries/IMP2.html --- a/web/entries/IMP2.html +++ b/web/entries/IMP2.html @@ -1,226 +1,226 @@ IMP2 – Simple Program Verification in Isabelle/HOL - Archive of Formal Proofs

 

 

 

 

 

 

IMP2 Simple Program Verification in Isabelle/HOL

 

Title: IMP2 – Simple Program Verification in Isabelle/HOL
Authors: - Peter Lammich (lammich /at/ in /dot/ tum /dot/ de) and + Peter Lammich and Simon Wimmer
Submission date: 2019-01-15
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.
BibTeX:
@article{IMP2-AFP,
   author  = {Peter Lammich and Simon Wimmer},
   title   = {IMP2 – Simple Program Verification in Isabelle/HOL},
   journal = {Archive of Formal Proofs},
   month   = jan,
   year    = 2019,
   note    = {\url{https://isa-afp.org/entries/IMP2.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Used by: IMP2_Binary_Heap

\ No newline at end of file diff --git a/web/entries/Knuth_Morris_Pratt.html b/web/entries/Knuth_Morris_Pratt.html --- a/web/entries/Knuth_Morris_Pratt.html +++ b/web/entries/Knuth_Morris_Pratt.html @@ -1,223 +1,223 @@ The string search algorithm by Knuth, Morris and Pratt - Archive of Formal Proofs

 

 

 

 

 

 

The string search algorithm by Knuth, Morris and Pratt

 

Title: The string search algorithm by Knuth, Morris and Pratt
Authors: Fabian Hellauer (hellauer /at/ in /dot/ tum /dot/ de) and - Peter Lammich (lammich /at/ in /dot/ tum /dot/ de) + Peter Lammich
Submission date: 2017-12-18
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.
BibTeX:
@article{Knuth_Morris_Pratt-AFP,
   author  = {Fabian Hellauer and Peter Lammich},
   title   = {The string search algorithm by Knuth, Morris and Pratt},
   journal = {Archive of Formal Proofs},
   month   = dec,
   year    = 2017,
   note    = {\url{https://isa-afp.org/entries/Knuth_Morris_Pratt.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License

\ No newline at end of file diff --git a/web/entries/Kruskal.html b/web/entries/Kruskal.html --- a/web/entries/Kruskal.html +++ b/web/entries/Kruskal.html @@ -1,215 +1,215 @@ Kruskal's Algorithm for Minimum Spanning Forest - Archive of Formal Proofs

 

 

 

 

 

 

Kruskal's Algorithm for Minimum Spanning Forest

 

Title: Kruskal's Algorithm for Minimum Spanning Forest
Authors: Maximilian P.L. Haslbeck, - Peter Lammich (lammich /at/ in /dot/ tum /dot/ de) and + Peter Lammich and Julian Biendarra
Submission date: 2019-02-14
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.
BibTeX:
@article{Kruskal-AFP,
   author  = {Maximilian P.L. Haslbeck and Peter Lammich and Julian Biendarra},
   title   = {Kruskal's Algorithm for Minimum Spanning Forest},
   journal = {Archive of Formal Proofs},
   month   = feb,
   year    = 2019,
   note    = {\url{https://isa-afp.org/entries/Kruskal.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: Collections, Matroids, Refine_Imperative_HOL, Refine_Monadic

\ No newline at end of file diff --git a/web/entries/LTL_to_GBA.html b/web/entries/LTL_to_GBA.html --- a/web/entries/LTL_to_GBA.html +++ b/web/entries/LTL_to_GBA.html @@ -1,251 +1,251 @@ Converting Linear-Time Temporal Logic to Generalized Büchi Automata - Archive of Formal Proofs

 

 

 

 

 

 

Converting Linear-Time Temporal Logic to Generalized Büchi Automata

 

Title: Converting Linear-Time Temporal Logic to Generalized Büchi Automata
Authors: Alexander Schimpf (schimpfa /at/ informatik /dot/ uni-freiburg /dot/ de) and - Peter Lammich (lammich /at/ in /dot/ tum /dot/ de) + Peter Lammich
Submission date: 2014-05-28
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.

BibTeX:
@article{LTL_to_GBA-AFP,
   author  = {Alexander Schimpf and Peter Lammich},
   title   = {Converting Linear-Time Temporal Logic to Generalized Büchi Automata},
   journal = {Archive of Formal Proofs},
   month   = may,
   year    = 2014,
   note    = {\url{https://isa-afp.org/entries/LTL_to_GBA.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: CAVA_Automata, LTL, Stuttering_Equivalence

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

 

 

 

 

 

 

Optics

 

+(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)
Title: Optics
Authors: Simon Foster and Frank Zeyda
Submission date: 2017-05-25
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.
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) +(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)
BibTeX:
@article{Optics-AFP,
   author  = {Simon Foster and Frank Zeyda},
   title   = {Optics},
   journal = {Archive of Formal Proofs},
   month   = may,
   year    = 2017,
   note    = {\url{https://isa-afp.org/entries/Optics.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License

\ No newline at end of file diff --git a/web/entries/Polynomials.html b/web/entries/Polynomials.html --- a/web/entries/Polynomials.html +++ b/web/entries/Polynomials.html @@ -1,301 +1,301 @@ Executable Multivariate Polynomials - Archive of Formal Proofs

 

 

 

 

 

 

Executable Multivariate Polynomials

 

- +
Title: Executable Multivariate Polynomials
Authors: Christian Sternagel (c /dot/ sternagel /at/ gmail /dot/ com), René Thiemann (rene /dot/ thiemann /at/ uibk /dot/ ac /dot/ at), Alexander Maletzky, Fabian Immler, Florian Haftmann, Andreas Lochbihler and Alexander Bentkamp (bentkamp /at/ gmail /dot/ com)
Submission date: 2010-08-10
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].

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.
BibTeX:
@article{Polynomials-AFP,
   author  = {Christian Sternagel and René Thiemann and Alexander Maletzky and Fabian Immler and Florian Haftmann and Andreas Lochbihler and Alexander Bentkamp},
   title   = {Executable Multivariate Polynomials},
   journal = {Archive of Formal Proofs},
   month   = aug,
   year    = 2010,
   note    = {\url{https://isa-afp.org/entries/Polynomials.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: GNU Lesser General Public License (LGPL)
Depends on: Abstract-Rewriting, Matrix, Show, Well_Quasi_Orders
Used by:Deep_Learning, Groebner_Bases, Lambda_Free_KBOs, PAC_Checker, Symmetric_Polynomials, Virtual_Substitution
Deep_Learning, Factor_Algebraic_Polynomial, Groebner_Bases, Lambda_Free_KBOs, PAC_Checker, Symmetric_Polynomials, Virtual_Substitution

\ No newline at end of file diff --git a/web/entries/Prim_Dijkstra_Simple.html b/web/entries/Prim_Dijkstra_Simple.html --- a/web/entries/Prim_Dijkstra_Simple.html +++ b/web/entries/Prim_Dijkstra_Simple.html @@ -1,215 +1,215 @@ Purely Functional, Simple, and Efficient Implementation of Prim and Dijkstra - Archive of Formal Proofs

 

 

 

 

 

 

Purely Functional, Simple, and Efficient Implementation of Prim and Dijkstra

 

Title: Purely Functional, Simple, and Efficient Implementation of Prim and Dijkstra
Authors: - Peter Lammich (lammich /at/ in /dot/ tum /dot/ de) and + Peter Lammich and Tobias Nipkow
Submission date: 2019-06-25
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.
BibTeX:
@article{Prim_Dijkstra_Simple-AFP,
   author  = {Peter Lammich and Tobias Nipkow},
   title   = {Purely Functional, Simple, and Efficient Implementation of Prim and Dijkstra},
   journal = {Archive of Formal Proofs},
   month   = jun,
   year    = 2019,
   note    = {\url{https://isa-afp.org/entries/Prim_Dijkstra_Simple.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: Priority_Search_Trees

\ No newline at end of file diff --git a/web/entries/Priority_Search_Trees.html b/web/entries/Priority_Search_Trees.html --- a/web/entries/Priority_Search_Trees.html +++ b/web/entries/Priority_Search_Trees.html @@ -1,205 +1,205 @@ Priority Search Trees - Archive of Formal Proofs

 

 

 

 

 

 

Priority Search Trees

 

Title: Priority Search Trees
Authors: - Peter Lammich (lammich /at/ in /dot/ tum /dot/ de) and + Peter Lammich and Tobias Nipkow
Submission date: 2019-06-25
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.
BibTeX:
@article{Priority_Search_Trees-AFP,
   author  = {Peter Lammich and Tobias Nipkow},
   title   = {Priority Search Trees},
   journal = {Archive of Formal Proofs},
   month   = jun,
   year    = 2019,
   note    = {\url{https://isa-afp.org/entries/Priority_Search_Trees.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Used by: Prim_Dijkstra_Simple

\ No newline at end of file diff --git a/web/entries/Program-Conflict-Analysis.html b/web/entries/Program-Conflict-Analysis.html --- a/web/entries/Program-Conflict-Analysis.html +++ b/web/entries/Program-Conflict-Analysis.html @@ -1,303 +1,303 @@ Formalization of Conflict Analysis of Programs with Procedures, Thread Creation, and Monitors - Archive of Formal Proofs

 

 

 

 

 

 

Formalization of Conflict Analysis of Programs with Procedures, Thread Creation, and Monitors

 

Title: Formalization of Conflict Analysis of Programs with Procedures, Thread Creation, and Monitors
Authors: - Peter Lammich (lammich /at/ in /dot/ tum /dot/ de) and + Peter Lammich and Markus Müller-Olm
Submission 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.
BibTeX:
@article{Program-Conflict-Analysis-AFP,
   author  = {Peter Lammich and Markus Müller-Olm},
   title   = {Formalization of Conflict Analysis of Programs with Procedures, Thread Creation, and Monitors},
   journal = {Archive of Formal Proofs},
   month   = dec,
   year    = 2007,
   note    = {\url{https://isa-afp.org/entries/Program-Conflict-Analysis.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Used by: Flow_Networks

\ No newline at end of file diff --git a/web/entries/Projective_Measurements.html b/web/entries/Projective_Measurements.html --- a/web/entries/Projective_Measurements.html +++ b/web/entries/Projective_Measurements.html @@ -1,196 +1,196 @@ Quantum projective measurements and the CHSH inequality - Archive of Formal Proofs

 

 

 

 

 

 

Quantum projective measurements and the CHSH inequality

 

Title: Quantum projective measurements and the CHSH inequality
Author: - Mnacho Echenim + Mnacho Echenim (mnacho /dot/ echenim /at/ univ-grenoble-alpes /dot/ fr)
Submission date: 2021-03-03
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.
BibTeX:
@article{Projective_Measurements-AFP,
   author  = {Mnacho Echenim},
   title   = {Quantum projective measurements and the CHSH inequality},
   journal = {Archive of Formal Proofs},
   month   = mar,
   year    = 2021,
   note    = {\url{https://isa-afp.org/entries/Projective_Measurements.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: Isabelle_Marries_Dirac, QHLProver

\ No newline at end of file diff --git a/web/entries/Prpu_Maxflow.html b/web/entries/Prpu_Maxflow.html --- a/web/entries/Prpu_Maxflow.html +++ b/web/entries/Prpu_Maxflow.html @@ -1,225 +1,225 @@ Formalizing Push-Relabel Algorithms - Archive of Formal Proofs

 

 

 

 

 

 

Formalizing Push-Relabel Algorithms

 

Title: Formalizing Push-Relabel Algorithms
Authors: - Peter Lammich (lammich /at/ in /dot/ tum /dot/ de) and + Peter Lammich and S. Reza Sefidgar
Submission date: 2017-06-01
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.
BibTeX:
@article{Prpu_Maxflow-AFP,
   author  = {Peter Lammich and S. Reza Sefidgar},
   title   = {Formalizing Push-Relabel Algorithms},
   journal = {Archive of Formal Proofs},
   month   = jun,
   year    = 2017,
   note    = {\url{https://isa-afp.org/entries/Prpu_Maxflow.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: Flow_Networks

\ No newline at end of file diff --git a/web/entries/Public_Announcement_Logic.html b/web/entries/Public_Announcement_Logic.html --- a/web/entries/Public_Announcement_Logic.html +++ b/web/entries/Public_Announcement_Logic.html @@ -1,187 +1,188 @@ Public Announcement Logic - Archive of Formal Proofs

 

 

 

 

 

 

Public Announcement Logic

 

+completeness proof builds on the Epistemic Logic theory. +Paper: https://doi.org/10.1007/978-3-030-90138-7_2.
Title: Public Announcement Logic
Author: Asta Halkjær From
Submission date: 2021-06-17
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.
BibTeX:
@article{Public_Announcement_Logic-AFP,
   author  = {Asta Halkjær From},
   title   = {Public Announcement Logic},
   journal = {Archive of Formal Proofs},
   month   = jun,
   year    = 2021,
   note    = {\url{https://isa-afp.org/entries/Public_Announcement_Logic.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: Epistemic_Logic

\ No newline at end of file diff --git a/web/entries/ROBDD.html b/web/entries/ROBDD.html --- a/web/entries/ROBDD.html +++ b/web/entries/ROBDD.html @@ -1,232 +1,232 @@ Algorithms for Reduced Ordered Binary Decision Diagrams - Archive of Formal Proofs

 

 

 

 

 

 

Algorithms for Reduced Ordered Binary Decision Diagrams

 

Title: Algorithms for Reduced Ordered Binary Decision Diagrams
Authors: Julius Michaelis, Maximilian Haslbeck, - Peter Lammich (lammich /at/ in /dot/ tum /dot/ de) and + Peter Lammich and Lars Hupel
Submission date: 2016-04-27
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.
BibTeX:
@article{ROBDD-AFP,
   author  = {Julius Michaelis and Maximilian Haslbeck and Peter Lammich and Lars Hupel},
   title   = {Algorithms for Reduced Ordered Binary Decision Diagrams},
   journal = {Archive of Formal Proofs},
   month   = apr,
   year    = 2016,
   note    = {\url{https://isa-afp.org/entries/ROBDD.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: Automatic_Refinement, Collections, Native_Word

\ No newline at end of file diff --git a/web/entries/Refine_Imperative_HOL.html b/web/entries/Refine_Imperative_HOL.html --- a/web/entries/Refine_Imperative_HOL.html +++ b/web/entries/Refine_Imperative_HOL.html @@ -1,239 +1,239 @@ The Imperative Refinement Framework - Archive of Formal Proofs

 

 

 

 

 

 

The Imperative Refinement Framework

 

Title: The Imperative Refinement Framework
Author: - Peter Lammich (lammich /at/ in /dot/ tum /dot/ de) + Peter Lammich
Submission date: 2016-08-08
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
BibTeX:
@article{Refine_Imperative_HOL-AFP,
   author  = {Peter Lammich},
   title   = {The Imperative Refinement Framework},
   journal = {Archive of Formal Proofs},
   month   = aug,
   year    = 2016,
   note    = {\url{https://isa-afp.org/entries/Refine_Imperative_HOL.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: DFS_Framework, Dijkstra_Shortest_Path, List-Index
Used by: BTree, Flow_Networks, Floyd_Warshall, Kruskal

\ No newline at end of file diff --git a/web/entries/Refine_Monadic.html b/web/entries/Refine_Monadic.html --- a/web/entries/Refine_Monadic.html +++ b/web/entries/Refine_Monadic.html @@ -1,285 +1,285 @@ Refinement for Monadic Programs - Archive of Formal Proofs

 

 

 

 

 

 

Refinement for Monadic Programs

 

Title: Refinement for Monadic Programs
Author: - Peter Lammich (lammich /at/ in /dot/ tum /dot/ de) + Peter Lammich
Submission 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.

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.
BibTeX:
@article{Refine_Monadic-AFP,
   author  = {Peter Lammich},
   title   = {Refinement for Monadic Programs},
   journal = {Archive of Formal Proofs},
   month   = jan,
   year    = 2012,
   note    = {\url{https://isa-afp.org/entries/Refine_Monadic.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: Automatic_Refinement
Used by: Collections, JinjaThreads, Kruskal

\ No newline at end of file diff --git a/web/entries/Separation_Logic_Imperative_HOL.html b/web/entries/Separation_Logic_Imperative_HOL.html --- a/web/entries/Separation_Logic_Imperative_HOL.html +++ b/web/entries/Separation_Logic_Imperative_HOL.html @@ -1,272 +1,272 @@ A Separation Logic Framework for Imperative HOL - Archive of Formal Proofs

 

 

 

 

 

 

A Separation Logic Framework for Imperative HOL

 

Title: A Separation Logic Framework for Imperative HOL
Authors: - Peter Lammich (lammich /at/ in /dot/ tum /dot/ de) and + Peter Lammich and Rene Meis (rene /dot/ meis /at/ uni-due /dot/ de)
Submission date: 2012-11-14
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.
BibTeX:
@article{Separation_Logic_Imperative_HOL-AFP,
   author  = {Peter Lammich and Rene Meis},
   title   = {A Separation Logic Framework for Imperative HOL},
   journal = {Archive of Formal Proofs},
   month   = nov,
   year    = 2012,
   note    = {\url{https://isa-afp.org/entries/Separation_Logic_Imperative_HOL.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: Automatic_Refinement, Collections, Native_Word
Used by: UpDown_Scheme

\ No newline at end of file diff --git a/web/entries/SimplifiedOntologicalArgument.html b/web/entries/SimplifiedOntologicalArgument.html new file mode 100644 --- /dev/null +++ b/web/entries/SimplifiedOntologicalArgument.html @@ -0,0 +1,204 @@ + + + + +Exploring Simplified Variants of Gödel’s Ontological Argument in Isabelle/HOL - Archive of Formal Proofs + + + + + + + + + + + + + + + + + + + + + + + + +
+

 

+ + + +

 

+

 

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

 

+

 

+
+
+

 

+

Exploring + + Simplified + + Variants + + of + + Gödel’s + + Ontological + + Argument + + in + + Isabelle/HOL + +

+

 

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Title:Exploring Simplified Variants of Gödel’s Ontological Argument in Isabelle/HOL
+ Author: + + Christoph Benzmüller +
Submission date:2021-11-08
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. +

BibTeX: +
@article{SimplifiedOntologicalArgument-AFP,
+  author  = {Christoph Benzmüller},
+  title   = {Exploring Simplified Variants of Gödel’s Ontological Argument in Isabelle/HOL},
+  journal = {Archive of Formal Proofs},
+  month   = nov,
+  year    = 2021,
+  note    = {\url{https://isa-afp.org/entries/SimplifiedOntologicalArgument.html},
+            Formal proof development},
+  ISSN    = {2150-914x},
+}
+
License:BSD License
+ +

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

 

 

 

 

 

 

Tree Automata

 

Title: Tree Automata
Author: - Peter Lammich (lammich /at/ in /dot/ tum /dot/ de) + Peter Lammich
Submission date: 2009-11-25
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.
BibTeX:
@article{Tree-Automata-AFP,
   author  = {Peter Lammich},
   title   = {Tree Automata},
   journal = {Archive of Formal Proofs},
   month   = nov,
   year    = 2009,
   note    = {\url{https://isa-afp.org/entries/Tree-Automata.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: Collections

\ No newline at end of file diff --git a/web/entries/Van_Emde_Boas_Trees.html b/web/entries/Van_Emde_Boas_Trees.html new file mode 100644 --- /dev/null +++ b/web/entries/Van_Emde_Boas_Trees.html @@ -0,0 +1,205 @@ + + + + +van Emde Boas Trees - Archive of Formal Proofs + + + + + + + + + + + + + + + + + + + + + + + + +
+

 

+ + + +

 

+

 

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

 

+

 

+
+
+

 

+

van + + Emde + + Boas + + Trees + +

+

 

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Title:van Emde Boas Trees
+ Authors: + + Thomas Ammer and + Peter Lammich +
Submission date:2021-11-23
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.

BibTeX: +
@article{Van_Emde_Boas_Trees-AFP,
+  author  = {Thomas Ammer and Peter Lammich},
+  title   = {van Emde Boas Trees},
+  journal = {Archive of Formal Proofs},
+  month   = nov,
+  year    = 2021,
+  note    = {\url{https://isa-afp.org/entries/Van_Emde_Boas_Trees.html},
+            Formal proof development},
+  ISSN    = {2150-914x},
+}
+
License:BSD License
Depends on:Automatic_Refinement, Deriving
+ +

+ + + + + + + + + + + + + + + + + + +
+
+ + + + + + \ No newline at end of file diff --git a/web/entries/VerifyThis2018.html b/web/entries/VerifyThis2018.html --- a/web/entries/VerifyThis2018.html +++ b/web/entries/VerifyThis2018.html @@ -1,215 +1,215 @@ VerifyThis 2018 - Polished Isabelle Solutions - Archive of Formal Proofs

 

 

 

 

 

 

VerifyThis 2018 - Polished Isabelle Solutions

 

Title: VerifyThis 2018 - Polished Isabelle Solutions
Authors: - Peter Lammich (lammich /at/ in /dot/ tum /dot/ de) and + Peter Lammich and Simon Wimmer
Submission date: 2018-04-27
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.
BibTeX:
@article{VerifyThis2018-AFP,
   author  = {Peter Lammich and Simon Wimmer},
   title   = {VerifyThis 2018 - Polished Isabelle Solutions},
   journal = {Archive of Formal Proofs},
   month   = apr,
   year    = 2018,
   note    = {\url{https://isa-afp.org/entries/VerifyThis2018.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License

\ No newline at end of file diff --git a/web/entries/VerifyThis2019.html b/web/entries/VerifyThis2019.html --- a/web/entries/VerifyThis2019.html +++ b/web/entries/VerifyThis2019.html @@ -1,204 +1,204 @@ VerifyThis 2019 -- Polished Isabelle Solutions - Archive of Formal Proofs

 

 

 

 

 

 

VerifyThis 2019 -- Polished Isabelle Solutions

 

Title: VerifyThis 2019 -- Polished Isabelle Solutions
Authors: - Peter Lammich (lammich /at/ in /dot/ tum /dot/ de) and + Peter Lammich and Simon Wimmer
Submission date: 2019-10-16
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.
BibTeX:
@article{VerifyThis2019-AFP,
   author  = {Peter Lammich and Simon Wimmer},
   title   = {VerifyThis 2019 -- Polished Isabelle Solutions},
   journal = {Archive of Formal Proofs},
   month   = oct,
   year    = 2019,
   note    = {\url{https://isa-afp.org/entries/VerifyThis2019.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License

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

 

 

 

 

 

 

Archive of Formal Proofs

 

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

A development version of the archive is available as well.

 

 

+ + + + + + + + +
2021
+ 2021-11-23: van Emde Boas Trees +
+ Authors: + Thomas Ammer + and Peter Lammich +
+ 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 + 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
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 + 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,595 +1,595 @@ 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. - 08 Nov 2021 00:00:00 +0000 + 23 Nov 2021 00:00:00 +0000 + + 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. + + + 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 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. Verified Quadratic Virtual Substitution for Real Arithmetic https://www.isa-afp.org/entries/Virtual_Substitution.html https://www.isa-afp.org/entries/Virtual_Substitution.html Matias Scharager, Katherine Cordwell, Stefan Mitsch, André Platzer 02 Oct 2021 00:00:00 +0000 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. Soundness and Completeness of an Axiomatic System for First-Order Logic https://www.isa-afp.org/entries/FOL_Axiomatic.html https://www.isa-afp.org/entries/FOL_Axiomatic.html Asta Halkjær From 24 Sep 2021 00:00:00 +0000 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. Complex Bounded Operators https://www.isa-afp.org/entries/Complex_Bounded_Operators.html https://www.isa-afp.org/entries/Complex_Bounded_Operators.html Jose Manuel Rodriguez Caballero, Dominique Unruh 18 Sep 2021 00:00:00 +0000 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 (<em>cblinfun</em>) 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 <a href="Jordan_Normal_Form.html">Jordan_Normal_Form</a> AFP entry. A Formalization of Weighted Path Orders and Recursive Path Orders https://www.isa-afp.org/entries/Weighted_Path_Order.html https://www.isa-afp.org/entries/Weighted_Path_Order.html Christian Sternagel, René Thiemann, Akihisa Yamada 16 Sep 2021 00:00:00 +0000 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&ndash;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. Extension of Types-To-Sets https://www.isa-afp.org/entries/Types_To_Sets_Extension.html https://www.isa-afp.org/entries/Types_To_Sets_Extension.html Mihails Milehins 06 Sep 2021 00:00:00 +0000 In their article titled <i>From Types to Sets by Local Type Definitions in Higher-Order Logic</i> and published in the proceedings of the conference <i>Interactive Theorem Proving</i> 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 <i>type-based theorems</i> to more flexible <i>set-based theorems</i>, collectively referred to as <i>Types-To-Sets</i>. 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 <i>Smooth Manifolds and Types to Sets for Linear Algebra in Isabelle/HOL</i> that was written by Fabian Immler and Bohua Zhan and published in the proceedings of the <i>International Conference on Certified Programs and Proofs</i> in 2019. IDE: Introduction, Destruction, Elimination https://www.isa-afp.org/entries/Intro_Dest_Elim.html https://www.isa-afp.org/entries/Intro_Dest_Elim.html Mihails Milehins 06 Sep 2021 00:00:00 +0000 The article provides the command <b>mk_ide</b> for the object logic Isabelle/HOL of the formal proof assistant Isabelle. The command <b>mk_ide</b> enables the automated synthesis of the introduction, destruction and elimination rules from arbitrary definitions of constant predicates stated in Isabelle/HOL. Conditional Transfer Rule https://www.isa-afp.org/entries/Conditional_Transfer_Rule.html https://www.isa-afp.org/entries/Conditional_Transfer_Rule.html Mihails Milehins 06 Sep 2021 00:00:00 +0000 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. Conditional Simplification https://www.isa-afp.org/entries/Conditional_Simplification.html https://www.isa-afp.org/entries/Conditional_Simplification.html Mihails Milehins 06 Sep 2021 00:00:00 +0000 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 <i>auto</i>, 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. Category Theory for ZFC in HOL III: Universal Constructions https://www.isa-afp.org/entries/CZH_Universal_Constructions.html https://www.isa-afp.org/entries/CZH_Universal_Constructions.html Mihails Milehins 06 Sep 2021 00:00:00 +0000 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 <i>Category Theory for ZFC in HOL II: Elementary Theory of 1-Categories</i>. Category Theory for ZFC in HOL I: Foundations: Design Patterns, Set Theory, Digraphs, Semicategories https://www.isa-afp.org/entries/CZH_Foundations.html https://www.isa-afp.org/entries/CZH_Foundations.html Mihails Milehins 06 Sep 2021 00:00:00 +0000 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 <i>V</i> 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 <i>Set-Theoretical Foundations of Category Theory</i> 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 <i>V</i> embedded into a stage of the von Neumann hierarchy. Category Theory for ZFC in HOL II: Elementary Theory of 1-Categories https://www.isa-afp.org/entries/CZH_Elementary_Categories.html https://www.isa-afp.org/entries/CZH_Elementary_Categories.html Mihails Milehins 06 Sep 2021 00:00:00 +0000 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 <i>Category Theory for ZFC in HOL I: Foundations: Design Patterns, Set Theory, Digraphs, Semicategories</i>. A data flow analysis algorithm for computing dominators https://www.isa-afp.org/entries/Dominance_CHK.html https://www.isa-afp.org/entries/Dominance_CHK.html Nan Jiang 05 Sep 2021 00:00:00 +0000 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. Solving Cubic and Quartic Equations https://www.isa-afp.org/entries/Cubic_Quartic_Equations.html https://www.isa-afp.org/entries/Cubic_Quartic_Equations.html René Thiemann 03 Sep 2021 00:00:00 +0000 <p>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.</p> Logging-independent Message Anonymity in the Relational Method https://www.isa-afp.org/entries/Logging_Independent_Anonymity.html https://www.isa-afp.org/entries/Logging_Independent_Anonymity.html Pasquale Noce 26 Aug 2021 00:00:00 +0000 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. The Theorem of Three Circles https://www.isa-afp.org/entries/Three_Circles.html https://www.isa-afp.org/entries/Three_Circles.html Fox Thomson, Wenda Li 21 Aug 2021 00:00:00 +0000 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. Fresh identifiers https://www.isa-afp.org/entries/Fresh_Identifiers.html https://www.isa-afp.org/entries/Fresh_Identifiers.html Andrei Popescu, Thomas Bauereiss 16 Aug 2021 00:00:00 +0000 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. CoSMed: A confidentiality-verified social media platform https://www.isa-afp.org/entries/CoSMed.html https://www.isa-afp.org/entries/CoSMed.html Thomas Bauereiss, Andrei Popescu 16 Aug 2021 00:00:00 +0000 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 [<a href="https://doi.org/10.4230/LIPIcs.ITP.2021.3">1</a>, <a href="https://www.isa-afp.org/entries/Bounded_Deducibility_Security.html">2</a>]. 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: A confidentiality-verified distributed social media platform https://www.isa-afp.org/entries/CoSMeDis.html https://www.isa-afp.org/entries/CoSMeDis.html Thomas Bauereiss, Andrei Popescu 16 Aug 2021 00:00:00 +0000 This entry contains the confidentiality verification of the (functional kernel of) the CoSMeDis distributed social media platform presented in [<a href="https://doi.org/10.1109/SP.2017.24">1</a>]. CoSMeDis is a multi-node extension the CoSMed prototype social media platform [<a href="https://doi.org/10.1007/978-3-319-43144-4_6">2</a>, <a href="https://doi.org/10.1007/s10817-017-9443-3">3</a>, <a href="https://www.isa-afp.org/entries/CoSMed.html">4</a>]. The confidentiality properties are formalized as instances of BD Security [<a href="https://doi.org/10.4230/LIPIcs.ITP.2021.3">5</a>, <a href="https://www.isa-afp.org/entries/Bounded_Deducibility_Security.html">6</a>]. 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 [<a href="https://doi.org/10.1109/SP.2017.24">1</a>] and formalized in a separate <a href="https://www.isa-afp.org/entries/BD_Security_Compositional.html">AFP entry</a>. CoCon: A Confidentiality-Verified Conference Management System https://www.isa-afp.org/entries/CoCon.html https://www.isa-afp.org/entries/CoCon.html Andrei Popescu, Peter Lammich, Thomas Bauereiss 16 Aug 2021 00:00:00 +0000 This entry contains the confidentiality verification of the (functional kernel of) the CoCon conference management system [<a href="https://doi.org/10.1007/978-3-319-08867-9_11">1</a>, <a href="https://doi.org/10.1007/s10817-020-09566-9">2</a>]. 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 [<a href="https://doi.org/10.4230/LIPIcs.ITP.2021.3">3</a>, <a href="https://www.isa-afp.org/entries/Bounded_Deducibility_Security.html">4</a>] and verified using the BD Security unwinding technique. - - Compositional BD Security - https://www.isa-afp.org/entries/BD_Security_Compositional.html - https://www.isa-afp.org/entries/BD_Security_Compositional.html - Thomas Bauereiss, Andrei Popescu - 16 Aug 2021 00:00:00 +0000 - -Building on a previous <a -href="https://www.isa-afp.org/entries/Bounded_Deducibility_Security.html">AFP -entry</a> that formalizes the Bounded-Deducibility Security (BD -Security) framework <a href="https://doi.org/10.4230/LIPIcs.ITP.2021.3">[1]</a>, -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 <a href="https://doi.org/10.4230/LIPIcs.ITP.2021.3">[1]</a> -and <a href="https://doi.org/10.1109/SP.2017.24">[2]</a>. -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 <a -href="https://www.isa-afp.org/entries/CoSMeDis.html">AFP -entry</a> that builds on this entry). - - - Combinatorial Design Theory - https://www.isa-afp.org/entries/Design_Theory.html - https://www.isa-afp.org/entries/Design_Theory.html - Chelsea Edmonds, Lawrence Paulson - 13 Aug 2021 00:00:00 +0000 - -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. - - - Relational Forests - https://www.isa-afp.org/entries/Relational_Forests.html - https://www.isa-afp.org/entries/Relational_Forests.html - Walter Guttmann - 03 Aug 2021 00:00:00 +0000 - -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. - diff --git a/web/statistics.html b/web/statistics.html --- a/web/statistics.html +++ b/web/statistics.html @@ -1,307 +1,302 @@ Archive of Formal Proofs

 

 

 

 

 

 

Statistics

 

Statistics

- - - - + + + +
Number of Articles:639
Number of Authors:409
Number of lemmas:~187,300
Lines of Code:~3,242,600
Number of Articles:642
Number of Authors:412
Number of lemmas:~188,300
Lines of Code:~3,264,500

Most used AFP articles:

- - + - + - - - - - +
NameUsed by ? articles
1. List-Index 19
2. Show 14
3. Coinductive 12
Collections 12
Regular-Sets 12
4. Jordan_Normal_Form 11
Landau_Symbols 11
Polynomial_Factorization 11
5. Abstract-Rewriting 10
6. Automatic_Refinement910
Deriving9
Native_Word910

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,1007 +1,1014 @@ Archive of Formal Proofs

 

 

 

 

 

 

Index by Topic

 

Computer science

Artificial intelligence

Automata and formal languages

Algorithms

Knuth_Morris_Pratt   Probabilistic_While   Comparison_Sort_Lower_Bound   Quick_Sort_Cost   TortoiseHare   Selection_Heap_Sort   VerifyThis2018   CYK   Boolean_Expression_Checkers   Efficient-Mergesort   SATSolverVerification   MuchAdoAboutTwo   First_Order_Terms   Monad_Memo_DP   Hidden_Markov_Models   Imperative_Insertion_Sort   Formal_SSA   ROBDD   Median_Of_Medians_Selection   Fisher_Yates   Optimal_BST   IMP2   Auto2_Imperative_HOL   List_Inversions   IMP2_Binary_Heap   MFOTL_Monitor   Adaptive_State_Counting   Generic_Join   VerifyThis2019   Generalized_Counting_Sort   MFODL_Monitor_Optimized   Sliding_Window_Algorithm   PAC_Checker   Regression_Test_Selection   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   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

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