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

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

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

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

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

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

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

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

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

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

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

The entry contains a proof of both theorems.

[Name_Carrying_Type_Inference] title = Verified Metatheory and Type Inference for a Name-Carrying Simply-Typed Lambda Calculus author = Michael Rawson topic = Computer science/Programming languages/Type systems date = 2017-07-09 notify = mr644@cam.ac.uk, michaelrawson76@gmail.com abstract = I formalise a Church-style simply-typed \(\lambda\)-calculus, extended with pairs, a unit value, and projection functions, and show some metatheory of the calculus, such as the subject reduction property. Particular attention is paid to the treatment of names in the calculus. A nominal style of binding is used, but I use a manual approach over Nominal Isabelle in order to extract an executable type inference algorithm. More information can be found in my undergraduate dissertation. [Propositional_Proof_Systems] title = Propositional Proof Systems author = Julius Michaelis , Tobias Nipkow topic = Logic/Proof theory date = 2017-06-21 notify = maintainafpppt@liftm.de abstract = We formalize a range of proof systems for classical propositional logic (sequent calculus, natural deduction, Hilbert systems, resolution) and prove the most important meta-theoretic results about semantics and proofs: compactness, soundness, completeness, translations between proof systems, cut-elimination, interpolation and model existence. [Optics] title = Optics author = Simon Foster , Frank Zeyda topic = Computer science/Functional programming, Mathematics/Algebra date = 2017-05-25 notify = simon.foster@york.ac.uk abstract = Lenses provide an abstract interface for manipulating data types through spatially-separated views. They are defined abstractly in terms of two functions, get, the return a value from the source type, and put that updates the value. We mechanise the underlying theory of lenses, in terms of an algebraic hierarchy of lenses, including well-behaved and very well-behaved lenses, each lens class being characterised by a set of lens laws. We also mechanise a lens algebra in Isabelle that enables their composition and comparison, so as to allow construction of complex lenses. This is accompanied by a large library of algebraic laws. Moreover we also show how the lens classes can be applied by instantiating them with a number of Isabelle data types. extra-history = Change history: [2020-03-02]: Added partial bijective and symmetric lenses. Improved alphabet command generating additional lenses and results. Several additional lens relations, including observational equivalence. Additional theorems throughout. Adaptations for Isabelle 2020. (revision 44e2e5c) [Game_Based_Crypto] title = Game-based cryptography in HOL author = Andreas Lochbihler , S. Reza Sefidgar <>, Bhargav Bhatt topic = Computer science/Security/Cryptography date = 2017-05-05 notify = mail@andreas-lochbihler.de abstract =

In this AFP entry, we show how to specify game-based cryptographic security notions and formally prove secure several cryptographic constructions from the literature using the CryptHOL framework. Among others, we formalise the notions of a random oracle, a pseudo-random function, an unpredictable function, and of encryption schemes that are indistinguishable under chosen plaintext and/or ciphertext attacks. We prove the random-permutation/random-function switching lemma, security of the Elgamal and hashed Elgamal public-key encryption scheme and correctness and security of several constructions with pseudo-random functions.

Our proofs follow the game-hopping style advocated by Shoup and Bellare and Rogaway, from which most of the examples have been taken. We generalise some of their results such that they can be reused in other proofs. Thanks to CryptHOL's integration with Isabelle's parametricity infrastructure, many simple hops are easily justified using the theory of representation independence.

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

CryptHOL provides a framework for formalising cryptographic arguments in Isabelle/HOL. It shallowly embeds a probabilistic functional programming language in higher order logic. The language features monadic sequencing, recursion, random sampling, failures and failure handling, and black-box access to oracles. Oracles are probabilistic functions which maintain hidden state between different invocations. All operators are defined in the new semantic domain of generative probabilistic values, a codatatype. We derive proof rules for the operators and establish a connection with the theory of relational parametricity. Thus, the resuting proofs are trustworthy and comprehensible, and the framework is extensible and widely applicable.

The framework is used in the accompanying AFP entry "Game-based Cryptography in HOL". There, we show-case our framework by formalizing different game-based proofs from the literature. This formalisation continues the work described in the author's ESOP 2016 paper.

[Constructive_Cryptography] title = Constructive Cryptography in HOL author = Andreas Lochbihler , S. Reza Sefidgar<> topic = Computer science/Security/Cryptography, Mathematics/Probability theory date = 2018-12-17 notify = mail@andreas-lochbihler.de, reza.sefidgar@inf.ethz.ch abstract = Inspired by Abstract Cryptography, we extend CryptHOL, a framework for formalizing game-based proofs, with an abstract model of Random Systems and provide proof rules about their composition and equality. This foundation facilitates the formalization of Constructive Cryptography proofs, where the security of a cryptographic scheme is realized as a special form of construction in which a complex random system is built from simpler ones. This is a first step towards a fully-featured compositional framework, similar to Universal Composability framework, that supports formalization of simulation-based proofs. [Probabilistic_While] title = Probabilistic while loop author = Andreas Lochbihler topic = Computer science/Functional programming, Mathematics/Probability theory, Computer science/Algorithms date = 2017-05-05 notify = mail@andreas-lochbihler.de abstract = This AFP entry defines a probabilistic while operator based on sub-probability mass functions and formalises zero-one laws and variant rules for probabilistic loop termination. As applications, we implement probabilistic algorithms for the Bernoulli, geometric and arbitrary uniform distributions that only use fair coin flips, and prove them correct and terminating with probability 1. extra-history = Change history: [2018-02-02]: Added a proof that probabilistic conditioning can be implemented by repeated sampling. (revision 305867c4e911)
[Monad_Normalisation] title = Monad normalisation author = Joshua Schneider <>, Manuel Eberl , Andreas Lochbihler topic = Tools, Computer science/Functional programming, Logic/Rewriting date = 2017-05-05 notify = mail@andreas-lochbihler.de abstract = The usual monad laws can directly be used as rewrite rules for Isabelle’s simplifier to normalise monadic HOL terms and decide equivalences. In a commutative monad, however, the commutativity law is a higher-order permutative rewrite rule that makes the simplifier loop. This AFP entry implements a simproc that normalises monadic expressions in commutative monads using ordered rewriting. The simproc can also permute computations across control operators like if and case. [Monomorphic_Monad] title = Effect polymorphism in higher-order logic author = Andreas Lochbihler topic = Computer science/Functional programming date = 2017-05-05 notify = mail@andreas-lochbihler.de abstract = The notion of a monad cannot be expressed within higher-order logic (HOL) due to type system restrictions. We show that if a monad is used with values of only one type, this notion can be formalised in HOL. Based on this idea, we develop a library of effect specifications and implementations of monads and monad transformers. Hence, we can abstract over the concrete monad in HOL definitions and thus use the same definition for different (combinations of) effects. We illustrate the usefulness of effect polymorphism with a monadic interpreter for a simple language. extra-history = Change history: [2018-02-15]: added further specifications and implementations of non-determinism; more examples (revision bc5399eea78e)
[Constructor_Funs] title = Constructor Functions author = Lars Hupel topic = Tools date = 2017-04-19 notify = hupel@in.tum.de abstract = Isabelle's code generator performs various adaptations for target languages. Among others, constructor applications have to be fully saturated. That means that for constructor calls occuring as arguments to higher-order functions, synthetic lambdas have to be inserted. This entry provides tooling to avoid this construction altogether by introducing constructor functions. [Lazy_Case] title = Lazifying case constants author = Lars Hupel topic = Tools date = 2017-04-18 notify = hupel@in.tum.de abstract = Isabelle's code generator performs various adaptations for target languages. Among others, case statements are printed as match expressions. Internally, this is a sophisticated procedure, because in HOL, case statements are represented as nested calls to the case combinators as generated by the datatype package. Furthermore, the procedure relies on laziness of match expressions in the target language, i.e., that branches guarded by patterns that fail to match are not evaluated. Similarly, if-then-else is printed to the corresponding construct in the target language. This entry provides tooling to replace these special cases in the code generator by ignoring these target language features, instead printing case expressions and if-then-else as functions. [Dict_Construction] title = Dictionary Construction author = Lars Hupel topic = Tools date = 2017-05-24 notify = hupel@in.tum.de abstract = Isabelle's code generator natively supports type classes. For targets that do not have language support for classes and instances, it performs the well-known dictionary translation, as described by Haftmann and Nipkow. This translation happens outside the logic, i.e., there is no guarantee that it is correct, besides the pen-and-paper proof. This work implements a certified dictionary translation that produces new class-free constants and derives equality theorems. [Higher_Order_Terms] title = An Algebra for Higher-Order Terms author = Lars Hupel contributors = Yu Zhang <> topic = Computer science/Programming languages/Lambda calculi date = 2019-01-15 notify = lars@hupel.info abstract = In this formalization, I introduce a higher-order term algebra, generalizing the notions of free variables, matching, and substitution. The need arose from the work on a verified compiler from Isabelle to CakeML. Terms can be thought of as consisting of a generic (free variables, constants, application) and a specific part. As example applications, this entry provides instantiations for de-Bruijn terms, terms with named variables, and Blanchette’s λ-free higher-order terms. Furthermore, I implement translation functions between de-Bruijn terms and named terms and prove their correctness. [Subresultants] title = Subresultants author = Sebastiaan Joosten , René Thiemann , Akihisa Yamada topic = Mathematics/Algebra date = 2017-04-06 notify = rene.thiemann@uibk.ac.at abstract = We formalize the theory of subresultants and the subresultant polynomial remainder sequence as described by Brown and Traub. As a result, we obtain efficient certified algorithms for computing the resultant and the greatest common divisor of polynomials. [Comparison_Sort_Lower_Bound] title = Lower bound on comparison-based sorting algorithms author = Manuel Eberl topic = Computer science/Algorithms date = 2017-03-15 notify = eberlm@in.tum.de abstract =

This article contains a formal proof of the well-known fact that number of comparisons that a comparison-based sorting algorithm needs to perform to sort a list of length n is at least log2 (n!) in the worst case, i. e. Ω(n log n).

For this purpose, a shallow embedding for comparison-based sorting algorithms is defined: a sorting algorithm is a recursive datatype containing either a HOL function or a query of a comparison oracle with a continuation containing the remaining computation. This makes it possible to force the algorithm to use only comparisons and to track the number of comparisons made.

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

We give a formal proof of the well-known results about the number of comparisons performed by two variants of QuickSort: first, the expected number of comparisons of randomised QuickSort (i. e. QuickSort with random pivot choice) is 2 (n+1) Hn - 4 n, which is asymptotically equivalent to 2 n ln n; second, the number of comparisons performed by the classic non-randomised QuickSort has the same distribution in the average case as the randomised one.

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

This entry contains proofs for the textbook results about the distributions of the height and internal path length of random binary search trees (BSTs), i. e. BSTs that are formed by taking an empty BST and inserting elements from a fixed set in random order.

In particular, we prove a logarithmic upper bound on the expected height and the Θ(n log n) closed-form solution for the expected internal path length in terms of the harmonic numbers. We also show how the internal path length relates to the average-case cost of a lookup in a BST.

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

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

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

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

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

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

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

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

[DFS_Framework] title = A Framework for Verifying Depth-First Search Algorithms author = Peter Lammich , René Neumann notify = lammich@in.tum.de date = 2016-07-05 topic = Computer science/Algorithms/Graph abstract =

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

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

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

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

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

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

Building on the formalization of basic category theory set out in the author's previous AFP article, the present article formalizes some basic aspects of the theory of monoidal categories. Among the notions defined here are monoidal category, monoidal functor, and equivalence of monoidal categories. The main theorems formalized are MacLane's coherence theorem and the constructions of the free monoidal category and free strict monoidal category generated by a given category. The coherence theorem is proved syntactically, using a structurally recursive approach to reduction of terms that might have some novel aspects. We also give proofs of some results given by Etingof et al, which may prove useful in a formal setting. In particular, we show that the left and right unitors need not be taken as given data in the definition of monoidal category, nor does the definition of monoidal functor need to take as given a specific isomorphism expressing the preservation of the unit object. Our definitions of monoidal category and monoidal functor are stated so as to take advantage of the economy afforded by these facts.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

The Euler-MacLaurin formula relates the value of a discrete sum to that of the corresponding integral in terms of the derivatives at the borders of the summation and a remainder term. Since the remainder term is often very small as the summation bounds grow, this can be used to compute asymptotic expansions for sums.

This entry contains a proof of this formula for functions from the reals to an arbitrary Banach space. Two variants of the formula are given: the standard textbook version and a variant outlined in Concrete Mathematics that is more useful for deriving asymptotic estimates.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

notify = pasquale.noce.lavoro@gmail.com [Floyd_Warshall] title = The Floyd-Warshall Algorithm for Shortest Paths author = Simon Wimmer , Peter Lammich topic = Computer science/Algorithms/Graph date = 2017-05-08 notify = wimmers@in.tum.de abstract = The Floyd-Warshall algorithm [Flo62, Roy59, War62] is a classic dynamic programming algorithm to compute the length of all shortest paths between any two vertices in a graph (i.e. to solve the all-pairs shortest path problem, or APSP for short). Given a representation of the graph as a matrix of weights M, it computes another matrix M' which represents a graph with the same path lengths and contains the length of the shortest path between any two vertices i and j. This is only possible if the graph does not contain any negative cycles. However, in this case the Floyd-Warshall algorithm will detect the situation by calculating a negative diagonal entry. This entry includes a formalization of the algorithm and of these key properties. The algorithm is refined to an efficient imperative version using the Imperative Refinement Framework. [Roy_Floyd_Warshall] title = Transitive closure according to Roy-Floyd-Warshall author = Makarius Wenzel <> date = 2014-05-23 topic = Computer science/Algorithms/Graph abstract = This formulation of the Roy-Floyd-Warshall algorithm for the transitive closure bypasses matrices and arrays, but uses a more direct mathematical model with adjacency functions for immediate predecessors and successors. This can be implemented efficiently in functional programming languages and is particularly adequate for sparse relations. notify = [GPU_Kernel_PL] title = Syntax and semantics of a GPU kernel programming language author = John Wickerson date = 2014-04-03 topic = Computer science/Programming languages/Language definitions abstract = This document accompanies the article "The Design and Implementation of a Verification Technique for GPU Kernels" by Adam Betts, Nathan Chong, Alastair F. Donaldson, Jeroen Ketema, Shaz Qadeer, Paul Thomson and John Wickerson. It formalises all of the definitions provided in Sections 3 and 4 of the article. notify = [AWN] title = Mechanization of the Algebra for Wireless Networks (AWN) author = Timothy Bourke date = 2014-03-08 topic = Computer science/Concurrency/Process calculi abstract =

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

In this contribution, we represent the Heard-Of model in Isabelle/HOL. We define two semantics of runs of algorithms with different unit of atomicity and relate these through a reduction theorem that allows us to verify algorithms in the coarse-grained semantics (where proofs are easier) and infer their correctness for the fine-grained one (which corresponds to actual executions). We instantiate the framework by verifying six Consensus algorithms that differ in the underlying algorithmic mechanisms and the kinds of faults they tolerate. notify = Stephan.Merz@loria.fr [Consensus_Refined] title = Consensus Refined date = 2015-03-18 author = Ognjen Maric <>, Christoph Sprenger topic = Computer science/Algorithms/Distributed abstract = Algorithms for solving the consensus problem are fundamental to distributed computing. Despite their brevity, their ability to operate in concurrent, asynchronous and failure-prone environments comes at the cost of complex and subtle behaviors. Accordingly, understanding how they work and proving their correctness is a non-trivial endeavor where abstraction is immensely helpful. Moreover, research on consensus has yielded a large number of algorithms, many of which appear to share common algorithmic ideas. A natural question is whether and how these similarities can be distilled and described in a precise, unified way. In this work, we combine stepwise refinement and lockstep models to provide an abstract and unified view of a sizeable family of consensus algorithms. Our models provide insights into the design choices underlying the different algorithms, and classify them based on those choices. notify = sprenger@inf.ethz.ch [Key_Agreement_Strong_Adversaries] title = Refining Authenticated Key Agreement with Strong Adversaries author = Joseph Lallemand , Christoph Sprenger topic = Computer science/Security license = LGPL date = 2017-01-31 notify = joseph.lallemand@loria.fr, sprenger@inf.ethz.ch abstract = We develop a family of key agreement protocols that are correct by construction. Our work substantially extends prior work on developing security protocols by refinement. First, we strengthen the adversary by allowing him to compromise different resources of protocol participants, such as their long-term keys or their session keys. This enables the systematic development of protocols that ensure strong properties such as perfect forward secrecy. Second, we broaden the class of protocols supported to include those with non-atomic keys and equationally defined cryptographic operators. We use these extensions to develop key agreement protocols including signed Diffie-Hellman and the core of IKEv1 and SKEME. [Security_Protocol_Refinement] title = Developing Security Protocols by Refinement author = Christoph Sprenger , Ivano Somaini<> topic = Computer science/Security license = LGPL date = 2017-05-24 notify = sprenger@inf.ethz.ch abstract = We propose a development method for security protocols based on stepwise refinement. Our refinement strategy transforms abstract security goals into protocols that are secure when operating over an insecure channel controlled by a Dolev-Yao-style intruder. As intermediate levels of abstraction, we employ messageless guard protocols and channel protocols communicating over channels with security properties. These abstractions provide insights on why protocols are secure and foster the development of families of protocols sharing common structure and properties. We have implemented our method in Isabelle/HOL and used it to develop different entity authentication and key establishment protocols, including realistic features such as key confirmation, replay caches, and encrypted tickets. Our development highlights that guard protocols and channel protocols provide fundamental abstractions for bridging the gap between security properties and standard protocol descriptions based on cryptographic messages. It also shows that our refinement approach scales to protocols of nontrivial size and complexity. [Abortable_Linearizable_Modules] title = Abortable Linearizable Modules author = Rachid Guerraoui , Viktor Kuncak , Giuliano Losa date = 2012-03-01 topic = Computer science/Algorithms/Distributed abstract = We define the Abortable Linearizable Module automaton (ALM for short) and prove its key composition property using the IOA theory of HOLCF. The ALM is at the heart of the Speculative Linearizability framework. This framework simplifies devising correct speculative algorithms by enabling their decomposition into independent modules that can be analyzed and proved correct in isolation. It is particularly useful when working in a distributed environment, where the need to tolerate faults and asynchrony has made current monolithic protocols so intricate that it is no longer tractable to check their correctness. Our theory contains a typical example of a refinement proof in the I/O-automata framework of Lynch and Tuttle. notify = giuliano@losa.fr, nipkow@in.tum.de [Amortized_Complexity] title = Amortized Complexity Verified author = Tobias Nipkow date = 2014-07-07 topic = Computer science/Data structures abstract = A framework for the analysis of the amortized complexity of functional data structures is formalized in Isabelle/HOL and applied to a number of standard examples and to the folowing non-trivial ones: skew heaps, splay trees, splay heaps and pairing heaps.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Not in the generated document are the following sessions:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

extra-history = Change history: [2016-01-07]: Added Schur-decomposition, Gram-Schmidt orthogonalization, uniqueness of Jordan normal forms
[2018-04-17]: Integrated lemmas from deep-learning AFP-entry of Alexander Bentkamp notify = rene.thiemann@uibk.ac.at, ayamada@trs.cm.is.nagoya-u.ac.jp [LTL_to_DRA] title = Converting Linear Temporal Logic to Deterministic (Generalized) Rabin Automata topic = Computer science/Automata and formal languages author = Salomon Sickert date = 2015-09-04 abstract = Recently, Javier Esparza and Jan Kretinsky proposed a new method directly translating linear temporal logic (LTL) formulas to deterministic (generalized) Rabin automata. Compared to the existing approaches of constructing a non-deterministic Buechi-automaton in the first step and then applying a determinization procedure (e.g. some variant of Safra's construction) in a second step, this new approach preservers a relation between the formula and the states of the resulting automaton. While the old approach produced a monolithic structure, the new method is compositional. Furthermore, in some cases the resulting automata are much smaller than the automata generated by existing approaches. In order to ensure the correctness of the construction, this entry contains a complete formalisation and verification of the translation. Furthermore from this basis executable code is generated. extra-history = Change history: [2015-09-23]: Enable code export for the eager unfolding optimisation and reduce running time of the generated tool. Moreover, add support for the mlton SML compiler.
[2016-03-24]: Make use of the LTL entry and include the simplifier. notify = sickert@in.tum.de [Timed_Automata] title = Timed Automata author = Simon Wimmer date = 2016-03-08 topic = Computer science/Automata and formal languages abstract = Timed automata are a widely used formalism for modeling real-time systems, which is employed in a class of successful model checkers such as UPPAAL [LPY97], HyTech [HHWt97] or Kronos [Yov97]. This work formalizes the theory for the subclass of diagonal-free timed automata, which is sufficient to model many interesting problems. We first define the basic concepts and semantics of diagonal-free timed automata. Based on this, we prove two types of decidability results for the language emptiness problem. The first is the classic result of Alur and Dill [AD90, AD94], which uses a finite partitioning of the state space into so-called `regions`. Our second result focuses on an approach based on `Difference Bound Matrices (DBMs)`, which is practically used by model checkers. We prove the correctness of the basic forward analysis operations on DBMs. One of these operations is the Floyd-Warshall algorithm for the all-pairs shortest paths problem. To obtain a finite search space, a widening operation has to be used for this kind of analysis. We use Patricia Bouyer's [Bou04] approach to prove that this widening operation is correct in the sense that DBM-based forward analysis in combination with the widening operation also decides language emptiness. The interesting property of this proof is that the first decidability result is reused to obtain the second one. notify = wimmers@in.tum.de [Parity_Game] title = Positional Determinacy of Parity Games author = Christoph Dittmann date = 2015-11-02 topic = Mathematics/Games and economics, Mathematics/Graph theory abstract = We present a formalization of parity games (a two-player game on directed graphs) and a proof of their positional determinacy in Isabelle/HOL. This proof works for both finite and infinite games. notify = [Ergodic_Theory] title = Ergodic Theory author = Sebastien Gouezel 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 date = 2015-12-22 abstract = Based on existing libraries for matrices, factorization of rational polynomials, and Sturm's theorem, we formalized algebraic numbers in Isabelle/HOL. Our development serves as an implementation for real and complex numbers, and it admits to compute roots and completely factorize real and complex polynomials, provided that all coefficients are rational numbers. Moreover, we provide two implementations to display algebraic numbers, an injective and expensive one, or a faster but approximative version.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[Stone_Relation_Algebras] title = Stone Relation Algebras author = Walter Guttmann topic = Mathematics/Algebra date = 2017-02-07 notify = walter.guttmann@canterbury.ac.nz abstract = We develop Stone relation algebras, which generalise relation algebras by replacing the underlying Boolean algebra structure with a Stone algebra. We show that finite matrices over extended real numbers form an instance. As a consequence, relation-algebraic concepts and methods can be used for reasoning about weighted graphs. We also develop a fixpoint calculus and apply it to compare different definitions of reflexive-transitive closures in semirings. [Stone_Kleene_Relation_Algebras] title = Stone-Kleene Relation Algebras author = Walter Guttmann topic = Mathematics/Algebra date = 2017-07-06 notify = walter.guttmann@canterbury.ac.nz abstract = We develop Stone-Kleene relation algebras, which expand Stone relation algebras with a Kleene star operation to describe reachability in weighted graphs. Many properties of the Kleene star arise as a special case of a more general theory of iteration based on Conway semirings extended by simulation axioms. This includes several theorems representing complex program transformations. We formally prove the correctness of Conway's automata-based construction of the Kleene star of a matrix. We prove numerous results useful for reasoning about weighted graphs. [Abstract_Soundness] title = Abstract Soundness author = Jasmin Christian Blanchette , Andrei Popescu , Dmitriy Traytel topic = Logic/Proof theory date = 2017-02-10 notify = jasmin.blanchette@gmail.com abstract = A formalized coinductive account of the abstract development of Brotherston, Gorogiannis, and Petersen [APLAS 2012], in a slightly more general form since we work with arbitrary infinite proofs, which may be acyclic. This work is described in detail in an article by the authors, published in 2017 in the Journal of Automated Reasoning. The abstract proof can be instantiated for various formalisms, including first-order logic with inductive predicates. [Differential_Dynamic_Logic] title = Differential Dynamic Logic author = Brandon Bohrer topic = Logic/General logic/Modal logic, Computer science/Programming languages/Logics date = 2017-02-13 notify = bbohrer@cs.cmu.edu abstract = We formalize differential dynamic logic, a logic for proving properties of hybrid systems. The proof calculus in this formalization is based on the uniform substitution principle. We show it is sound with respect to our denotational semantics, which provides increased confidence in the correctness of the KeYmaera X theorem prover based on this calculus. As an application, we include a proof term checker embedded in Isabelle/HOL with several example proofs. Published in: Brandon Bohrer, Vincent Rahli, Ivana Vukotic, Marcus Völp, André Platzer: Formally verified differential dynamic logic. CPP 2017. [Syntax_Independent_Logic] title = Syntax-Independent Logic Infrastructure author = Andrei Popescu , Dmitriy Traytel topic = Logic/Proof theory date = 2020-09-16 notify = a.popescu@sheffield.ac.uk, traytel@di.ku.dk abstract = We formalize a notion of logic whose terms and formulas are kept abstract. In particular, logical connectives, substitution, free variables, and provability are not defined, but characterized by their general properties as locale assumptions. Based on this abstract characterization, we develop further reusable reasoning infrastructure. For example, we define parallel substitution (along with proving its characterizing theorems) from single-point substitution. Similarly, we develop a natural deduction style proof system starting from the abstract Hilbert-style one. These one-time efforts benefit different concrete logics satisfying our locales' assumptions. We instantiate the syntax-independent logic infrastructure to Robinson arithmetic (also known as Q) in the AFP entry Robinson_Arithmetic and to hereditarily finite set theory in the AFP entries Goedel_HFSet_Semantic and Goedel_HFSet_Semanticless, which are part of our formalization of Gödel's Incompleteness Theorems described in our CADE-27 paper A Formally Verified Abstract Account of Gödel's Incompleteness Theorems. [Goedel_Incompleteness] title = An Abstract Formalization of Gödel's Incompleteness Theorems author = Andrei Popescu , Dmitriy Traytel topic = Logic/Proof theory date = 2020-09-16 notify = a.popescu@sheffield.ac.uk, traytel@di.ku.dk abstract = We present an abstract formalization of Gödel's incompleteness theorems. We analyze sufficient conditions for the theorems' applicability to a partially specified logic. Our abstract perspective enables a comparison between alternative approaches from the literature. These include Rosser's variation of the first theorem, Jeroslow's variation of the second theorem, and the Swierczkowski–Paulson semantics-based approach. This AFP entry is the main entry point to the results described in our CADE-27 paper A Formally Verified Abstract Account of Gödel's Incompleteness Theorems. As part of our abstract formalization's validation, we instantiate our locales twice in the separate AFP entries Goedel_HFSet_Semantic and Goedel_HFSet_Semanticless. [Goedel_HFSet_Semantic] title = From Abstract to Concrete Gödel's Incompleteness Theorems—Part I author = Andrei Popescu , Dmitriy Traytel topic = Logic/Proof theory date = 2020-09-16 notify = a.popescu@sheffield.ac.uk, traytel@di.ku.dk abstract = We validate an abstract formulation of Gödel's First and Second Incompleteness Theorems from a separate AFP entry by instantiating them to the case of finite sound extensions of the Hereditarily Finite (HF) Set theory, i.e., FOL theories extending the HF Set theory with a finite set of axioms that are sound in the standard model. The concrete results had been previously formalised in an AFP entry by Larry Paulson; our instantiation reuses the infrastructure developed in that entry. [Goedel_HFSet_Semanticless] title = From Abstract to Concrete Gödel's Incompleteness Theorems—Part II author = Andrei Popescu , Dmitriy Traytel topic = Logic/Proof theory date = 2020-09-16 notify = a.popescu@sheffield.ac.uk, traytel@di.ku.dk abstract = We validate an abstract formulation of Gödel's Second Incompleteness Theorem from a separate AFP entry by instantiating it to the case of finite consistent extensions of the Hereditarily Finite (HF) Set theory, i.e., consistent FOL theories extending the HF Set theory with a finite set of axioms. The instantiation draws heavily on infrastructure previously developed by Larry Paulson in his direct formalisation of the concrete result. It strengthens Paulson's formalization of Gödel's Second from that entry by not assuming soundness, and in fact not relying on any notion of model or semantic interpretation. The strengthening was obtained by first replacing some of Paulson’s semantic arguments with proofs within his HF calculus, and then plugging in some of Paulson's (modified) lemmas to instantiate our soundness-free Gödel's Second locale. [Robinson_Arithmetic] title = Robinson Arithmetic author = Andrei Popescu , Dmitriy Traytel topic = Logic/Proof theory date = 2020-09-16 notify = a.popescu@sheffield.ac.uk, traytel@di.ku.dk abstract = We instantiate our syntax-independent logic infrastructure developed in a separate AFP entry to the FOL theory of Robinson arithmetic (also known as Q). The latter was formalised using Nominal Isabelle by adapting Larry Paulson’s formalization of the Hereditarily Finite Set theory. [Elliptic_Curves_Group_Law] title = The Group Law for Elliptic Curves author = Stefan Berghofer topic = Computer science/Security/Cryptography date = 2017-02-28 notify = berghofe@in.tum.de abstract = We prove the group law for elliptic curves in Weierstrass form over fields of characteristic greater than 2. In addition to affine coordinates, we also formalize projective coordinates, which allow for more efficient computations. By specializing the abstract formalization to prime fields, we can apply the curve operations to parameters used in standard security protocols. [Example-Submission] title = Example Submission author = Gerwin Klein topic = Mathematics/Analysis, Mathematics/Number theory date = 2004-02-25 notify = kleing@cse.unsw.edu.au abstract =

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[Forcing] title = Formalization of Forcing in Isabelle/ZF author = Emmanuel Gunther , Miguel Pagano , Pedro Sánchez Terraf topic = Logic/Set theory date = 2020-05-06 notify = gunther@famaf.unc.edu.ar, pagano@famaf.unc.edu.ar, sterraf@famaf.unc.edu.ar abstract = We formalize the theory of forcing in the set theory framework of Isabelle/ZF. Under the assumption of the existence of a countable transitive model of ZFC, we construct a proper generic extension and show that the latter also satisfies ZFC. [Recursion-Addition] title = Recursion Theorem in ZF author = Georgy Dunaev topic = Logic/Set theory date = 2020-05-11 notify = georgedunaev@gmail.com abstract = This document contains a proof of the recursion theorem. This is a mechanization of the proof of the recursion theorem from the text Introduction to Set Theory, by Karel Hrbacek and Thomas Jech. This implementation may be used as the basis for a model of Peano arithmetic in ZF. While recursion and the natural numbers are already available in Isabelle/ZF, this clean development is much easier to follow. [LTL_Normal_Form] title = An Efficient Normalisation Procedure for Linear Temporal Logic: Isabelle/HOL Formalisation author = Salomon Sickert topic = Computer science/Automata and formal languages, Logic/General logic/Temporal logic date = 2020-05-08 notify = s.sickert@tum.de abstract = In the mid 80s, Lichtenstein, Pnueli, and Zuck proved a classical theorem stating that every formula of Past LTL (the extension of LTL with past operators) is equivalent to a formula of the form $\bigwedge_{i=1}^n \mathbf{G}\mathbf{F} \varphi_i \vee \mathbf{F}\mathbf{G} \psi_i$, where $\varphi_i$ and $\psi_i$ contain only past operators. Some years later, Chang, Manna, and Pnueli built on this result to derive a similar normal form for LTL. Both normalisation procedures have a non-elementary worst-case blow-up, and follow an involved path from formulas to counter-free automata to star-free regular expressions and back to formulas. We improve on both points. We present an executable formalisation of a direct and purely syntactic normalisation procedure for LTL yielding a normal form, comparable to the one by Chang, Manna, and Pnueli, that has only a single exponential blow-up. [Matrices_for_ODEs] title = Matrices for ODEs author = Jonathan Julian Huerta y Munive topic = Mathematics/Analysis, Mathematics/Algebra date = 2020-04-19 notify = jonjulian23@gmail.com abstract = Our theories formalise various matrix properties that serve to establish existence, uniqueness and characterisation of the solution to affine systems of ordinary differential equations (ODEs). In particular, we formalise the operator and maximum norm of matrices. Then we use them to prove that square matrices form a Banach space, and in this setting, we show an instance of Picard-Lindelöf’s theorem for affine systems of ODEs. Finally, we use this formalisation to verify three simple hybrid programs. [Irrational_Series_Erdos_Straus] title = Irrationality Criteria for Series by Erdős and Straus author = Angeliki Koutsoukou-Argyraki , Wenda Li topic = Mathematics/Number theory, Mathematics/Analysis date = 2020-05-12 notify = ak2110@cam.ac.uk, wl302@cam.ac.uk, liwenda1990@hotmail.com abstract = We formalise certain irrationality criteria for infinite series of the form: \[\sum_{n=1}^\infty \frac{b_n}{\prod_{i=1}^n a_i} \] where $\{b_n\}$ is a sequence of integers and $\{a_n\}$ a sequence of positive integers with $a_n >1$ for all large n. The results are due to P. Erdős and E. G. Straus [1]. In particular, we formalise Theorem 2.1, Corollary 2.10 and Theorem 3.1. The latter is an application of Theorem 2.1 involving the prime numbers. [Knuth_Bendix_Order] title = A Formalization of Knuth–Bendix Orders author = Christian Sternagel , René Thiemann topic = Logic/Rewriting date = 2020-05-13 notify = c.sternagel@gmail.com, rene.thiemann@uibk.ac.at abstract = We define a generalized version of Knuth–Bendix orders, including subterm coefficient functions. For these orders we formalize several properties such as strong normalization, the subterm property, closure properties under substitutions and contexts, as well as ground totality. [Stateful_Protocol_Composition_and_Typing] title = Stateful Protocol Composition and Typing author = Andreas V. Hess , Sebastian Mödersheim , Achim D. Brucker topic = Computer science/Security date = 2020-04-08 notify = avhe@dtu.dk, andreasvhess@gmail.com, samo@dtu.dk, brucker@spamfence.net, andschl@dtu.dk abstract = We provide in this AFP entry several relative soundness results for security protocols. In particular, we prove typing and compositionality results for stateful protocols (i.e., protocols with mutable state that may span several sessions), and that focuses on reachability properties. Such results are useful to simplify protocol verification by reducing it to a simpler problem: Typing results give conditions under which it is safe to verify a protocol in a typed model where only "well-typed" attacks can occur whereas compositionality results allow us to verify a composed protocol by only verifying the component protocols in isolation. The conditions on the protocols under which the results hold are furthermore syntactic in nature allowing for full automation. The foundation presented here is used in another entry to provide fully automated and formalized security proofs of stateful protocols. [Automated_Stateful_Protocol_Verification] title = Automated Stateful Protocol Verification author = Andreas V. Hess , Sebastian Mödersheim , Achim D. Brucker , Anders Schlichtkrull topic = Computer science/Security, Tools date = 2020-04-08 notify = avhe@dtu.dk, andreasvhess@gmail.com, samo@dtu.dk, brucker@spamfence.net, andschl@dtu.dk abstract = In protocol verification we observe a wide spectrum from fully automated methods to interactive theorem proving with proof assistants like Isabelle/HOL. In this AFP entry, we present a fully-automated approach for verifying stateful security protocols, i.e., protocols with mutable state that may span several sessions. The approach supports reachability goals like secrecy and authentication. We also include a simple user-friendly transaction-based protocol specification language that is embedded into Isabelle. [Smith_Normal_Form] title = A verified algorithm for computing the Smith normal form of a matrix author = Jose Divasón topic = Mathematics/Algebra, Computer science/Algorithms/Mathematical date = 2020-05-23 notify = jose.divason@unirioja.es abstract = This work presents a formal proof in Isabelle/HOL of an algorithm to transform a matrix into its Smith normal form, a canonical matrix form, in a general setting: the algorithm is parameterized by operations to prove its existence over elementary divisor rings, while execution is guaranteed over Euclidean domains. We also provide a formal proof on some results about the generality of this algorithm as well as the uniqueness of the Smith normal form. Since Isabelle/HOL does not feature dependent types, the development is carried out switching conveniently between two different existing libraries: the Hermite normal form (based on HOL Analysis) and the Jordan normal form AFP entries. This permits to reuse results from both developments and it is done by means of the lifting and transfer package together with the use of local type definitions. [Nash_Williams] title = The Nash-Williams Partition Theorem author = Lawrence C. Paulson topic = Mathematics/Combinatorics date = 2020-05-16 notify = lp15@cam.ac.uk abstract = In 1965, Nash-Williams discovered a generalisation of the infinite form of Ramsey's theorem. Where the latter concerns infinite sets of n-element sets for some fixed n, the Nash-Williams theorem concerns infinite sets of finite sets (or lists) subject to a “no initial segment” condition. The present formalisation follows a monograph on Ramsey Spaces by Todorčević. [Safe_Distance] title = A Formally Verified Checker of the Safe Distance Traffic Rules for Autonomous Vehicles author = Albert Rizaldi , Fabian Immler topic = Computer science/Algorithms/Mathematical, Mathematics/Physics date = 2020-06-01 notify = albert.rizaldi@ntu.edu.sg, fimmler@andrew.cmu.edu, martin.rau@tum.de abstract = The Vienna Convention on Road Traffic defines the safe distance traffic rules informally. This could make autonomous vehicle liable for safe-distance-related accidents because there is no clear definition of how large a safe distance is. We provide a formally proven prescriptive definition of a safe distance, and checkers which can decide whether an autonomous vehicle is obeying the safe distance rule. Not only does our work apply to the domain of law, but it also serves as a specification for autonomous vehicle manufacturers and for online verification of path planners. [Relational_Paths] title = Relational Characterisations of Paths author = Walter Guttmann , Peter Höfner topic = Mathematics/Graph theory date = 2020-07-13 notify = walter.guttmann@canterbury.ac.nz, peter@hoefner-online.de abstract = Binary relations are one of the standard ways to encode, characterise and reason about graphs. Relation algebras provide equational axioms for a large fragment of the calculus of binary relations. Although relations are standard tools in many areas of mathematics and computing, researchers usually fall back to point-wise reasoning when it comes to arguments about paths in a graph. We present a purely algebraic way to specify different kinds of paths in Kleene relation algebras, which are relation algebras equipped with an operation for reflexive transitive closure. We study the relationship between paths with a designated root vertex and paths without such a vertex. Since we stay in first-order logic this development helps with mechanising proofs. To demonstrate the applicability of the algebraic framework we verify the correctness of three basic graph algorithms. [Amicable_Numbers] title = Amicable Numbers author = Angeliki Koutsoukou-Argyraki topic = Mathematics/Number theory date = 2020-08-04 notify = ak2110@cam.ac.uk abstract = This is a formalisation of Amicable Numbers, involving some relevant material including Euler's sigma function, some relevant definitions, results and examples as well as rules such as Thābit ibn Qurra's Rule, Euler's Rule, te Riele's Rule and Borho's Rule with breeders. [Ordinal_Partitions] title = Ordinal Partitions author = Lawrence C. Paulson topic = Mathematics/Combinatorics, Logic/Set theory date = 2020-08-03 notify = lp15@cam.ac.uk abstract = The theory of partition relations concerns generalisations of Ramsey's theorem. For any ordinal $\alpha$, write $\alpha \to (\alpha, m)^2$ if for each function $f$ from unordered pairs of elements of $\alpha$ into $\{0,1\}$, either there is a subset $X\subseteq \alpha$ order-isomorphic to $\alpha$ such that $f\{x,y\}=0$ for all $\{x,y\}\subseteq X$, or there is an $m$ element set $Y\subseteq \alpha$ such that $f\{x,y\}=1$ for all $\{x,y\}\subseteq Y$. (In both cases, with $\{x,y\}$ we require $x\not=y$.) In particular, the infinite Ramsey theorem can be written in this notation as $\omega \to (\omega, \omega)^2$, or if we restrict $m$ to the positive integers as above, then $\omega \to (\omega, m)^2$ for all $m$. This entry formalises Larson's proof of $\omega^\omega \to (\omega^\omega, m)^2$ along with a similar proof of a result due to Specker: $\omega^2 \to (\omega^2, m)^2$. Also proved is a necessary result by Erdős and Milner: $\omega^{1+\alpha\cdot n} \to (\omega^{1+\alpha}, 2^n)^2$. [Relational_Disjoint_Set_Forests] title = Relational Disjoint-Set Forests author = Walter Guttmann topic = Computer science/Data structures date = 2020-08-26 notify = walter.guttmann@canterbury.ac.nz abstract = We give a simple relation-algebraic semantics of read and write operations on associative arrays. The array operations seamlessly integrate with assignments in the Hoare-logic library. Using relation algebras and Kleene algebras we verify the correctness of an array-based implementation of disjoint-set forests with a naive union operation and a find operation with path compression. [PAC_Checker] title = Practical Algebraic Calculus Checker author = Mathias Fleury , Daniela Kaufmann topic = Computer science/Algorithms date = 2020-08-31 notify = mathias.fleury@jku.at abstract = Generating and checking proof certificates is important to increase the trust in automated reasoning tools. In recent years formal verification using computer algebra became more important and is heavily used in automated circuit verification. An existing proof format which covers algebraic reasoning and allows efficient proof checking is the practical algebraic calculus (PAC). In this development, we present the verified checker Pastèque that is obtained by synthesis via the Refinement Framework. This is the formalization going with our FMCAD'20 tool presentation. [BirdKMP] title = Putting the `K' into Bird's derivation of Knuth-Morris-Pratt string matching author = Peter Gammie topic = Computer science/Functional programming date = 2020-08-25 notify = peteg42@gmail.com abstract = Richard Bird and collaborators have proposed a derivation of an intricate cyclic program that implements the Morris-Pratt string matching algorithm. Here we provide a proof of total correctness for Bird's derivation and complete it by adding Knuth's optimisation. [Extended_Finite_State_Machines] title = A Formal Model of Extended Finite State Machines author = Michael Foster , Achim D. Brucker , Ramsay G. Taylor , John Derrick topic = Computer science/Automata and formal languages date = 2020-09-07 notify = jmafoster1@sheffield.ac.uk, adbrucker@0x5f.org abstract = In this AFP entry, we provide a formalisation of extended finite state machines (EFSMs) where models are represented as finite sets of transitions between states. EFSMs execute traces to produce observable outputs. We also define various simulation and equality metrics for EFSMs in terms of traces and prove their strengths in relation to each other. Another key contribution is a framework of function definitions such that LTL properties can be phrased over EFSMs. Finally, we provide a simple example case study in the form of a drinks machine. [Extended_Finite_State_Machine_Inference] title = Inference of Extended Finite State Machines author = Michael Foster , Achim D. Brucker , Ramsay G. Taylor , John Derrick topic = Computer science/Automata and formal languages date = 2020-09-07 notify = jmafoster1@sheffield.ac.uk, adbrucker@0x5f.org abstract = In this AFP entry, we provide a formal implementation of a state-merging technique to infer extended finite state machines (EFSMs), complete with output and update functions, from black-box traces. In particular, we define the subsumption in context relation as a means of determining whether one transition is able to account for the behaviour of another. Building on this, we define the direct subsumption relation, which lifts the subsumption in context relation to EFSM level such that we can use it to determine whether it is safe to merge a given pair of transitions. Key proofs include the conditions necessary for subsumption to occur and that subsumption and direct subsumption are preorder relations. We also provide a number of different heuristics which can be used to abstract away concrete values into registers so that more states and transitions can be merged and provide proofs of the various conditions which must hold for these abstractions to subsume their ungeneralised counterparts. A Code Generator setup to create executable Scala code is also defined. [Physical_Quantities] title = A Sound Type System for Physical Quantities, Units, and Measurements author = Simon Foster , Burkhart Wolff topic = Mathematics/Physics, Computer science/Programming languages/Type systems date = 2020-10-20 notify = simon.foster@york.ac.uk, wolff@lri.fr abstract = The present Isabelle theory builds a formal model for both the International System of Quantities (ISQ) and the International System of Units (SI), which are both fundamental for physics and engineering. Both the ISQ and the SI are deeply integrated into Isabelle's type system. Quantities are parameterised by dimension types, which correspond to base vectors, and thus only quantities of the same dimension can be equated. Since the underlying "algebra of quantities" induces congruences on quantity and SI types, specific tactic support is developed to capture these. Our construction is validated by a test-set of known equivalences between both quantities and SI units. Moreover, the presented theory can be used for type-safe conversions between the SI system and others, like the British Imperial System (BIS). [Shadow_DOM] title = A Formal Model of the Document Object Model with Shadow Roots author = Achim D. Brucker , Michael Herzberg topic = Computer science/Data structures date = 2020-09-28 notify = adbrucker@0x5f.org, mail@michael-herzberg.de abstract = In this AFP entry, we extend our formalization of the core DOM with Shadow Roots. Shadow roots are a recent proposal of the web community to support a component-based development approach for client-side web applications. Shadow roots are a significant extension to the DOM standard and, as web standards are condemned to be backward compatible, such extensions often result in complex specification that may contain unwanted subtleties that can be detected by a formalization. Our Isabelle/HOL formalization is, in the sense of object-orientation, an extension of our formalization of the core DOM and enjoys the same basic properties, i.e., it is extensible, i.e., can be extended without the need of re-proving already proven properties and executable, i.e., we can generate executable code from our specification. We exploit the executability to show that our formalization complies to the official standard of the W3C, respectively, the WHATWG. [DOM_Components] title = A Formalization of Web Components author = Achim D. Brucker , Michael Herzberg topic = Computer science/Data structures date = 2020-09-28 notify = adbrucker@0x5f.org, mail@michael-herzberg.de abstract = While the DOM with shadow trees provide the technical basis for defining web components, the DOM standard neither defines the concept of web components nor specifies the safety properties that web components should guarantee. Consequently, the standard also does not discuss how or even if the methods for modifying the DOM respect component boundaries. In AFP entry, we present a formally verified model of web components and define safety properties which ensure that different web components can only interact with each other using well-defined interfaces. Moreover, our verification of the application programming interface (API) of the DOM revealed numerous invariants that implementations of the DOM API need to preserve to ensure the integrity of components. [Interpreter_Optimizations] title = Inline Caching and Unboxing Optimization for Interpreters author = Martin Desharnais topic = Computer science/Programming languages/Misc date = 2020-12-07 notify = martin.desharnais@unibw.de -abstract = +abstract = This Isabelle/HOL formalization builds on the VeriComp entry of the Archive of Formal Proofs to provide the following contributions:
  • an operational semantics for a realistic virtual machine (Std) for dynamically typed programming languages;
  • the formalization of an inline caching optimization (Inca), a proof of bisimulation with (Std), and a compilation function;
  • the formalization of an unboxing optimization (Ubx), a proof of bisimulation with (Inca), and a simple compilation function.
This formalization was described in the CPP 2021 paper Towards Efficient and Verified Virtual Machines for Dynamic Languages +[Isabelle_Marries_Dirac] +title = Isabelle Marries Dirac: a Library for Quantum Computation and Quantum Information +author = Anthony Bordg , Hanna Lachnitt, Yijun He +topic = Computer science/Algorithms/Quantum computing, Mathematics/Physics/Quantum information +date = 2020-11-22 +notify = apdb3@cam.ac.uk, lachnitt@stanford.edu +abstract = + This work is an effort to formalise some quantum algorithms and + results in quantum information theory. Formal methods being critical + for the safety and security of algorithms and protocols, we foresee + their widespread use for quantum computing in the future. We have + developed a large library for quantum computing in Isabelle based on a + matrix representation for quantum circuits, successfully formalising + the no-cloning theorem, quantum teleportation, Deutsch's + algorithm, the Deutsch-Jozsa algorithm and the quantum Prisoner's + Dilemma. + +[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. diff --git a/metadata/topics b/metadata/topics --- a/metadata/topics +++ b/metadata/topics @@ -1,63 +1,65 @@ 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 Probability theory Number theory Games and economics Geometry Topology Graph theory Combinatorics Category theory Physics + Quantum information Misc Tools diff --git a/thys/Finite-Map-Extras/Finite_Map_Extras.thy b/thys/Finite-Map-Extras/Finite_Map_Extras.thy new file mode 100644 --- /dev/null +++ b/thys/Finite-Map-Extras/Finite_Map_Extras.thy @@ -0,0 +1,701 @@ +section \ Extra Features for Finite Maps \ + +theory Finite_Map_Extras + imports "HOL-Library.Finite_Map" +begin + +text \ Extra lemmas and syntactic sugar for \fmap\ \ + +notation fmlookup (infixl \$$\ 900) + +notation fmempty (\{$$}\) + +nonterminal fmaplets and fmaplet + +syntax + "_fmaplet" :: "['a, 'a] \ fmaplet" ("_ /$$:=/ _") + "_fmaplets" :: "['a, 'a] \ fmaplet" ("_ /[$$:=]/ _") + "" :: "fmaplet \ fmaplets" ("_") + "_Fmaplets" :: "[fmaplet, fmaplets] \ fmaplets" ("_,/ _") + "_FmapUpd" :: "[('a, 'b) fmap, fmaplets] \ ('a, 'b) fmap" ("_/'(_')" [900, 0] 900) + "_Fmap" :: "fmaplets \ ('a, 'b) fmap" ("(1{_})") + +translations + "_FmapUpd m (_Fmaplets xy ms)" \ "_FmapUpd (_FmapUpd m xy) ms" + "_FmapUpd m (_fmaplet x y)" \ "CONST fmupd x y m" + "_Fmap ms" \ "_FmapUpd (CONST fmempty) ms" + "_Fmap (_Fmaplets ms1 ms2)" \ "_FmapUpd (_Fmap ms1) ms2" + "_Fmaplets ms1 (_Fmaplets ms2 ms3)" \ "_Fmaplets (_Fmaplets ms1 ms2) ms3" + +abbreviation fmap_lookup_the (infixl \$$!\ 900) where + "m $$! k \ the (m $$ k)" + +lemma fmadd_singletons_comm: + assumes "k\<^sub>1 \ k\<^sub>2" + shows "{k\<^sub>1 $$:= v\<^sub>1} ++\<^sub>f {k\<^sub>2 $$:= v\<^sub>2} = {k\<^sub>2 $$:= v\<^sub>2} ++\<^sub>f {k\<^sub>1 $$:= v\<^sub>1}" +proof (intro fmap_ext) + fix k + consider + (a) "k = k\<^sub>1" | + (b) "k = k\<^sub>2" | + (c) "k \ k\<^sub>1 \ k \ k\<^sub>2" + by auto + with assms show "({k\<^sub>1 $$:= v\<^sub>1} ++\<^sub>f {k\<^sub>2 $$:= v\<^sub>2}) $$ k = ({k\<^sub>2 $$:= v\<^sub>2} ++\<^sub>f {k\<^sub>1 $$:= v\<^sub>1}) $$ k" + by auto +qed + +lemma fmap_singleton_comm: + assumes "m $$ k = None" + shows "m ++\<^sub>f {k $$:= v} = {k $$:= v} ++\<^sub>f m" + using assms +proof (induction m arbitrary: k v) + case fmempty + then show ?case + by simp +next + case (fmupd x y m) + have "m(x $$:= y) ++\<^sub>f {k $$:= v} = m ++\<^sub>f {x $$:= y} ++\<^sub>f {k $$:= v}" + by simp + also from fmupd.hyps and fmupd.IH have "\ = {x $$:= y} ++\<^sub>f m ++\<^sub>f {k $$:= v}" + by simp + also from fmupd.prems and fmupd.hyps and fmupd.IH have "\ = {x $$:= y} ++\<^sub>f {k $$:= v} ++\<^sub>f m" + by (metis fmadd_assoc fmupd_lookup) + also have "\ = {k $$:= v} ++\<^sub>f m(x $$:= y)" + proof (cases "x \ k") + case True + then have "{x $$:= y} ++\<^sub>f {k $$:= v} ++\<^sub>f m = {k $$:= v} ++\<^sub>f {x $$:= y} ++\<^sub>f m" + using fmadd_singletons_comm by metis + also from fmupd.prems and fmupd.hyps and fmupd.IH have "\ = {k $$:= v} ++\<^sub>f m ++\<^sub>f {x $$:= y}" + by (metis fmadd_assoc) + finally show ?thesis + by simp + next + case False + with fmupd.prems show ?thesis + by auto + qed + finally show ?case . +qed + +lemma fmap_disj_comm: + assumes "fmdom' m\<^sub>1 \ fmdom' m\<^sub>2 = {}" + shows "m\<^sub>1 ++\<^sub>f m\<^sub>2 = m\<^sub>2 ++\<^sub>f m\<^sub>1" + using assms +proof (induction m\<^sub>2 arbitrary: m\<^sub>1) + case fmempty + then show ?case + by simp +next + case (fmupd k v m\<^sub>2) + then show ?case + proof (cases "m\<^sub>1 $$ k = None") + case True + from fmupd.hyps have "m\<^sub>1 ++\<^sub>f m\<^sub>2(k $$:= v) = m\<^sub>1 ++\<^sub>f m\<^sub>2 ++\<^sub>f {k $$:= v}" + by simp + also from fmupd.prems and fmupd.hyps and fmupd.IH have "\ = m\<^sub>2 ++\<^sub>f m\<^sub>1 ++\<^sub>f {k $$:= v}" + by simp + also from True have "\ = m\<^sub>2 ++\<^sub>f {k $$:= v} ++\<^sub>f m\<^sub>1" + using fmap_singleton_comm by (metis fmadd_assoc) + finally show ?thesis + by simp + next + case False + with fmupd.prems show ?thesis + by auto + qed +qed + +lemma fmran_singleton: "fmran {k $$:= v} = {|v|}" +proof - + have "v' |\| fmran {k $$:= v} \ v' = v" for v' + proof - + assume "v' |\| fmran {k $$:= v}" + fix k' + have "fmdom' {k $$:= v} = {k}" + by simp + then show "v' = v" + proof (cases "k' = k") + case True + with \v' |\| fmran {k $$:= v}\ show ?thesis + using fmdom'I by fastforce + next + case False + with \fmdom' {k $$:= v} = {k}\ and \v' |\| fmran {k $$:= v}\ show ?thesis + using fmdom'I by fastforce + qed + qed + moreover have "v |\| fmran {k $$:= v}" + by (simp add: fmranI) + ultimately show ?thesis + by (simp add: fsubsetI fsubset_antisym) +qed + +lemma fmmap_keys_hom: + assumes "fmdom' m\<^sub>1 \ fmdom' m\<^sub>2 = {}" + shows "fmmap_keys f (m\<^sub>1 ++\<^sub>f m\<^sub>2) = fmmap_keys f m\<^sub>1 ++\<^sub>f fmmap_keys f m\<^sub>2" + using assms + by (simp add: fmap_ext) + +lemma map_insort_is_insort_key: + assumes "m $$ k = None" + shows "map (\k'. (k', m(k $$:= v) $$! k')) (insort k xs) = + insort_key fst (k, v) (map (\k'. (k', m(k $$:= v) $$! k')) xs)" + using assms by (induction xs) auto + +lemma sorted_list_of_fmap_is_insort_key_fst: + assumes "m $$ k = None" + shows "sorted_list_of_fmap (m(k $$:= v)) = insort_key fst (k, v) (sorted_list_of_fmap m)" +proof - + have "sorted_list_of_fmap (m(k $$:= v)) = + map (\k'. (k', m(k $$:= v) $$! k')) (sorted_list_of_fset (fmdom (m(k $$:= v))))" + unfolding sorted_list_of_fmap_def .. + also have "\ = map (\k'. (k', m(k $$:= v) $$! k')) (sorted_list_of_fset (finsert k (fmdom m)))" + by simp + also from \m $$ k = None\ have "\ = + map (\k'. (k', m(k $$:= v) $$! k')) (insort k (sorted_list_of_fset (fmdom m - {|k|})))" + by (simp add: sorted_list_of_fset.rep_eq) + also from \m $$ k = None\ have "\ = + map (\k'. (k', m(k $$:= v) $$! k')) (insort k (sorted_list_of_fset (fmdom m)))" + by (simp add: fmdom_notI) + also from \m $$ k = None\ have "\ = + insort_key fst (k, v) (map (\k'. (k', m(k $$:= v) $$! k')) (sorted_list_of_fset (fmdom m)))" + using map_insort_is_insort_key by fastforce + also have "\ = insort_key fst (k, v) (map (\k'. (k', m $$! k')) (sorted_list_of_fset (fmdom m)))" + proof - + from \m $$ k = None\ have "\k'. k' \ fmdom' m \ m(k $$:= v) $$! k' = m $$! k'" + using fmdom'_notI by force + moreover from \m $$ k = None\ have "k \ set (sorted_list_of_fset (fmdom m))" + using fmdom'_alt_def and fmdom'_notI and in_set_member by force + ultimately show ?thesis + by (metis (mono_tags, lifting) fmdom'_alt_def map_eq_conv sorted_list_of_fset_simps(1)) + qed + finally show ?thesis + unfolding sorted_list_of_fmap_def by simp +qed + +lemma distinct_fst_inj: + assumes "distinct (map fst ps)" + and "inj f" + shows "distinct (map fst (map (\(k, v). (f k, v)) ps))" +proof - + have "map fst (map (\(k, v). (f k, v)) ps) = map f (map fst ps)" + by (induction ps) auto + moreover from assms have "distinct (map f (map fst ps))" + by (simp add: distinct_map inj_on_def) + ultimately show ?thesis + by presburger +qed + +lemma distinct_sorted_list_of_fmap: + shows "distinct (map fst (sorted_list_of_fmap m))" + unfolding sorted_list_of_fmap_def and sorted_list_of_fset_def + by (simp add: distinct_map inj_on_def) + +lemma map_inj_pair_non_membership: + assumes "k \ set (map fst ps)" + and "inj f" + shows "f k \ set (map fst (map (\(k, v). (f k, v)) ps))" + using assms by (induction ps) (simp add: member_rec(2), fastforce simp add: injD) + +lemma map_insort_key_fst: + assumes "distinct (map fst ps)" + and "k \ set (map fst ps)" + and "inj f" + and "mono f" + shows "map (\(k, v). (f k, v)) (insort_key fst (k, v) ps) = + insort_key fst (f k, v) (map (\(k, v). (f k, v)) ps)" + using assms +proof (induction ps) + case Nil + then show ?case + by simp +next + let ?g = "(\(k, v). (f k, v))" + case (Cons p ps) + then show ?case + proof (cases "k \ fst p") + case True + let ?f_p = "(f (fst p), snd p)" + have "insort_key fst (f k, v) (map ?g (p # ps)) = insort_key fst (f k, v) (?f_p # map ?g ps)" + by (simp add: prod.case_eq_if) + moreover from Cons.prems(4) and True have "f k \ f (fst p)" + by (auto dest: monoE) + then have "insort_key fst (f k, v) (?f_p # map ?g ps) = (f k, v) # ?f_p # map ?g ps" + by simp + ultimately have "insort_key fst (f k, v) (map ?g (p # ps)) = (f k, v) # ?f_p # map ?g ps" + by simp + moreover from True have "map ?g (insort_key fst (k, v) (p # ps)) = (f k, v) # ?f_p # map ?g ps" + by (simp add: case_prod_beta') + ultimately show ?thesis + by simp + next + case False + let ?f_p = "(f (fst p), snd p)" + have "insort_key fst (f k, v) (map ?g (p # ps)) = insort_key fst (f k, v) (?f_p # map ?g ps)" + by (simp add: prod.case_eq_if) + moreover from \mono f\ and False have "f (fst p) \ f k" + using not_le by (blast dest: mono_invE) + ultimately have "insort_key fst (f k, v) (map ?g (p # ps)) = + ?f_p # insort_key fst (f k, v) (map ?g ps)" + using False and \inj f\ by (fastforce dest: injD) + also from Cons.IH and Cons.prems(1,2) and assms(3,4) have "\ = + ?f_p # (map ?g (insort_key fst (k, v) ps))" + by (fastforce simp add: member_rec(1)) + also have "\ = map ?g (p # insort_key fst (k, v) ps)" + by (simp add: case_prod_beta) + finally show ?thesis + using False by simp + qed +qed + +lemma map_sorted_list_of_fmap: + assumes "inj f" + and "mono f" + and "m $$ k = None" + shows "map (\(k, v). (f k, v)) (sorted_list_of_fmap (m(k $$:= v))) = + insort_key fst (f k, v) (map (\(k, v). (f k, v)) (sorted_list_of_fmap m))" +proof - + let ?g = "(\(k, v). (f k, v))" + from \m $$ k = None\ have "map ?g (sorted_list_of_fmap (m(k $$:= v))) = + map ?g (insort_key fst (k, v) (sorted_list_of_fmap m))" + using sorted_list_of_fmap_is_insort_key_fst by fastforce + also have "\ = insort_key fst (f k, v) (map ?g (sorted_list_of_fmap m))" + proof - + have "distinct (map fst (sorted_list_of_fmap m))" + by (simp add: distinct_sorted_list_of_fmap) + moreover from \m $$ k = None\ have "k \ set (map fst (sorted_list_of_fmap m))" + by (metis image_set map_of_eq_None_iff map_of_sorted_list) + ultimately show ?thesis + by (simp add: map_insort_key_fst assms(1,2)) + qed + finally show ?thesis . +qed + +lemma fmap_of_list_insort_key_fst: + assumes "distinct (map fst ps)" + and "k \ set (map fst ps)" + shows "fmap_of_list (insort_key fst (k, v) ps) = (fmap_of_list ps)(k $$:= v)" + using assms +proof (induction ps) + case Nil + then show ?case + by simp +next + case (Cons p ps) + then show ?case + proof (cases "k \ fst p") + case True + then show ?thesis + by simp + next + case False + then have "fmap_of_list (insort_key fst (k, v) (p # ps)) = + fmap_of_list (p # insort_key fst (k, v) ps)" + by simp + also have "\ = (fmap_of_list (insort_key fst (k, v) ps))(fst p $$:= snd p)" + by (metis fmap_of_list_simps(2) prod.collapse) + also from Cons.prems(1,2) and Cons.IH have "\ = (fmap_of_list ps)(k $$:= v)(fst p $$:= snd p)" + by (fastforce simp add: member_rec(1)) + finally show ?thesis + proof - + assume *: "fmap_of_list (insort_key fst (k, v) (p # ps)) = + (fmap_of_list ps)(k $$:= v)(fst p $$:= snd p)" + from Cons.prems(2) have "k \ set (fst p # map fst ps)" + by simp + then have **: "{k $$:= v} $$ (fst p) = None" + by (fastforce simp add: member_rec(1)) + have "fmap_of_list (p # ps) = (fmap_of_list ps)(fst p $$:= snd p)" + by (metis fmap_of_list_simps(2) prod.collapse) + with * and ** show ?thesis + using fmap_singleton_comm by (metis fmadd_fmupd fmap_of_list_simps(1,2) fmupd_alt_def) + qed + qed +qed + +lemma fmap_of_list_insort_key_fst_map: + assumes "inj f" + and "m $$ k = None" + shows "fmap_of_list (insort_key fst (f k, v) (map (\(k, v). (f k, v)) (sorted_list_of_fmap m))) = + (fmap_of_list (map (\(k, v). (f k, v)) (sorted_list_of_fmap m)))(f k $$:= v)" +proof - + let ?g = "\(k, v). (f k, v)" + let ?ps = "map ?g (sorted_list_of_fmap m)" + from \inj f\ have "distinct (map fst ?ps)" + using distinct_fst_inj and distinct_sorted_list_of_fmap by fastforce + moreover have "f k \ set (map fst ?ps)" + proof - + from \m $$ k = None\ have "k \ set (map fst (sorted_list_of_fmap m))" + by (metis map_of_eq_None_iff map_of_sorted_list set_map) + with \inj f\ show ?thesis + using map_inj_pair_non_membership by force + qed + ultimately show ?thesis + using fmap_of_list_insort_key_fst by fast +qed + +lemma fmap_of_list_sorted_list_of_fmap: + fixes m :: "('a::linorder, 'b) fmap" + and f :: "'a \ 'c::linorder" + assumes "inj f" + and "mono f" + and "m $$ k = None" + shows "fmap_of_list (map (\(k, v). (f k, v)) (sorted_list_of_fmap (m(k $$:= v)))) = + (fmap_of_list (map (\(k, v). (f k, v)) (sorted_list_of_fmap m)))(f k $$:= v)" +proof - + let ?g = "\(k, v). (f k, v)" + from assms(3) have "fmap_of_list (map ?g (sorted_list_of_fmap (m(k $$:= v)))) = + fmap_of_list (map ?g (insort_key fst (k, v) (sorted_list_of_fmap m)))" + by (simp add: sorted_list_of_fmap_is_insort_key_fst) + also from assms have "\ = fmap_of_list (insort_key fst (f k, v) (map ?g (sorted_list_of_fmap m)))" + using calculation and map_sorted_list_of_fmap by fastforce + also from assms(1,3) have "\ = (fmap_of_list (map ?g (sorted_list_of_fmap m)))(f k $$:= v)" + by (simp add: fmap_of_list_insort_key_fst_map) + finally show ?thesis . +qed + +text \ Map difference \ + +lemma fsubset_antisym: + assumes "m \\<^sub>f n" + and "n \\<^sub>f m" + shows "m = n" +proof - + from \m \\<^sub>f n\ have "\k \ dom (($$) m). (($$) m) k = (($$) n) k" + by (simp add: fmsubset.rep_eq map_le_def) + moreover from \n \\<^sub>f m\ have "\k \ dom (($$) n). (($$) n) k = (($$) m) k" + by (simp add: fmsubset.rep_eq map_le_def) + ultimately show ?thesis + proof (intro fmap_ext) + fix k + consider + (a) "k \ dom (($$) m)" | + (b) "k \ dom (($$) n)" | + (c) "k \ dom (($$) m) \ k \ dom (($$) n)" + by auto + then show "m $$ k = n $$ k" + proof cases + case a + with \\k \ dom (($$) m). m $$ k = n $$ k\ show ?thesis + by simp + next + case b + with \\k \ dom (($$) n). n $$ k = m $$ k\ show ?thesis + by simp + next + case c + then show ?thesis + by (simp add: fmdom'_notD) + qed + qed +qed + +abbreviation + fmdiff :: "('a, 'b) fmap \ ('a, 'b) fmap \ ('a, 'b) fmap" (infixl \--\<^sub>f\ 100) where + "m\<^sub>1 --\<^sub>f m\<^sub>2 \ fmfilter (\x. x \ fmdom' m\<^sub>2) m\<^sub>1" + +lemma fmdiff_partition: + assumes "m\<^sub>2 \\<^sub>f m\<^sub>1" + shows "m\<^sub>2 ++\<^sub>f (m\<^sub>1 --\<^sub>f m\<^sub>2) = m\<^sub>1" +proof - + have *: "m\<^sub>2 ++\<^sub>f (m\<^sub>1 --\<^sub>f m\<^sub>2) \\<^sub>f m\<^sub>1" + proof - + have "\k v. (m\<^sub>2 ++\<^sub>f (m\<^sub>1 --\<^sub>f m\<^sub>2)) $$ k = Some v \ m\<^sub>1 $$ k = Some v" + proof (intro allI impI) + fix k v + assume "(m\<^sub>2 ++\<^sub>f (m\<^sub>1 --\<^sub>f m\<^sub>2)) $$ k = Some v" + then have **: "(if k |\| fmdom (m\<^sub>1 --\<^sub>f m\<^sub>2) then (m\<^sub>1 --\<^sub>f m\<^sub>2) $$ k else m\<^sub>2 $$ k) = Some v" + by simp + then show "m\<^sub>1 $$ k = Some v" + proof (cases "k |\| fmdom (m\<^sub>1 --\<^sub>f m\<^sub>2)") + case True + with ** show ?thesis + by simp + next + case False + with ** and \m\<^sub>2 \\<^sub>f m\<^sub>1\ show ?thesis + by (metis (mono_tags, lifting) fmpredD fmsubset_alt_def) + qed + qed + then have "fmpred (\k v. m\<^sub>1 $$ k = Some v) (m\<^sub>2 ++\<^sub>f (m\<^sub>1 --\<^sub>f m\<^sub>2))" + by (blast intro: fmpred_iff) + then show ?thesis + by (auto simp add: fmsubset_alt_def) + qed + then have "m\<^sub>1 \\<^sub>f m\<^sub>2 ++\<^sub>f (m\<^sub>1 --\<^sub>f m\<^sub>2)" + by (simp add: fmsubset.rep_eq map_le_def) + with * show ?thesis + by (simp add: fsubset_antisym) +qed + +lemma fmdiff_fmupd: + assumes "m $$ k = None" + shows "m(k $$:= v) --\<^sub>f {k $$:= v} = m" +proof - + let ?P = "(\k'. k' \ {k})" + have "m(k $$:= v) --\<^sub>f {k $$:= v} = fmfilter (\x. x \ fmdom' {k $$:= v}) (m(k $$:= v))" .. + also have "\ = fmfilter ?P (m(k $$:= v))" + by simp + also have "\ = (if ?P k then (fmfilter ?P m)(k $$:= v) else fmfilter ?P m)" + by simp + also have "\ = fmfilter ?P m" + by simp + finally show ?thesis + proof - + from \m $$ k = None\ have "\k' v'. m $$ k' = Some v' \ ?P k'" + by fastforce + then show ?thesis + by simp + qed +qed + +text \ Map symmetric difference \ + +abbreviation fmsym_diff :: "('a, 'b) fmap \ ('a, 'b) fmap \ ('a, 'b) fmap" (infixl \\\<^sub>f\ 100) where + "m\<^sub>1 \\<^sub>f m\<^sub>2 \ (m\<^sub>1 --\<^sub>f m\<^sub>2) ++\<^sub>f (m\<^sub>2 --\<^sub>f m\<^sub>1)" + +text \ Domain restriction \ + +abbreviation dom_res :: "'a set \ ('a, 'b) fmap \ ('a, 'b) fmap" (infixl \\\ 150) where + "s \ m \ fmfilter (\x. x \ s) m" + +text \ Domain exclusion \ + +abbreviation dom_exc :: "'a set \ ('a, 'b) fmap \ ('a, 'b) fmap" (infixl \\'/\ 150) where + "s \/ m \ fmfilter (\x. x \ s) m" + +text \ Intersection plus \ + +abbreviation intersection_plus :: "('a, 'b::monoid_add) fmap \ ('a, 'b) fmap \ ('a, 'b) fmap" + (infixl \\\<^sub>+\ 100) +where + "m\<^sub>1 \\<^sub>+ m\<^sub>2 \ fmmap_keys (\k v. v + m\<^sub>1 $$! k) (fmdom' m\<^sub>1 \ m\<^sub>2)" + +text \ Union override right \ + +abbreviation union_override_right :: "('a, 'b) fmap \ ('a, 'b) fmap \ ('a, 'b) fmap" + (infixl \\\<^sub>\\ 100) +where + "m\<^sub>1 \\<^sub>\ m\<^sub>2 \ (fmdom' m\<^sub>2 \/ m\<^sub>1) ++\<^sub>f m\<^sub>2" + +text \ Union override left \ + +abbreviation union_override_left :: "('a, 'b) fmap \ ('a, 'b) fmap \ ('a, 'b) fmap" + (infixl \\\<^sub>\\ 100) +where + "m\<^sub>1 \\<^sub>\ m\<^sub>2 \ m\<^sub>1 ++\<^sub>f (fmdom' m\<^sub>1 \/ m\<^sub>2)" + +text \ Union override plus \ + +abbreviation union_override_plus :: "('a, 'b::monoid_add) fmap \ ('a, 'b) fmap \ ('a, 'b) fmap" + (infixl \\\<^sub>+\ 100) +where + "m\<^sub>1 \\<^sub>+ m\<^sub>2 \ (m\<^sub>1 \\<^sub>f m\<^sub>2) ++\<^sub>f (m\<^sub>1 \\<^sub>+ m\<^sub>2)" + +text \ Extra lemmas for the non-standard map operators \ + +lemma dom_res_singleton: + assumes "m $$ k = Some v" + shows "{k} \ m = {k $$:= v}" + using assms +proof (induction m) + case fmempty + then show ?case + by simp +next + case (fmupd k' v' m) + then show ?case + proof (cases "k = k'") + case True + with \m(k' $$:= v') $$ k = Some v\ have "v = v'" + by simp + with True have "{k} \ m(k' $$:= v') = ({k} \ m)(k $$:= v)" + by simp + also from True and \m $$ k' = None\ have "\ = {$$}(k $$:= v)" + by (simp add: fmap_ext) + finally show ?thesis + by simp + next + case False + with \m(k' $$:= v') $$ k = Some v\ have *: "m $$ k = Some v" + by simp + with False have "{k} \ m(k' $$:= v') = {k} \ m" + by simp + with * and fmupd.IH show ?thesis + by simp + qed +qed + +lemma dom_res_union_distr: + shows "(A \ B) \ m = A \ m ++\<^sub>f B \ m" +proof - + have "($$) ((A \ B) \ m) \\<^sub>m ($$) (A \ m ++\<^sub>f B \ m)" + proof (unfold map_le_def, intro ballI) + fix k + assume "k \ dom (($$) ((A \ B) \ m))" + then show "((A \ B) \ m) $$ k = (A \ m ++\<^sub>f B \ m) $$ k" + by auto + qed + moreover have "($$) (A \ m ++\<^sub>f B \ m) \\<^sub>m ($$) ((A \ B) \ m)" + proof (unfold map_le_def, intro ballI) + fix k + assume "k \ dom (($$) (A \ m ++\<^sub>f B \ m))" + then show "(A \ m ++\<^sub>f B \ m) $$ k = ((A \ B) \ m) $$ k" + by auto + qed + ultimately show ?thesis + using fmlookup_inject and map_le_antisym by blast +qed + +lemma dom_exc_add_distr: + shows "s \/ (m\<^sub>1 ++\<^sub>f m\<^sub>2) = (s \/ m\<^sub>1) ++\<^sub>f (s \/ m\<^sub>2)" + by (blast intro: fmfilter_add_distrib) + +lemma fmap_partition: + shows "m = s \/ m ++\<^sub>f s \ m" +proof (induction m) + case fmempty + then show ?case + by simp +next + case (fmupd k v m) + from fmupd.hyps have "s \/ m(k $$:= v) ++\<^sub>f s \ m(k $$:= v) = + s \/ (m ++\<^sub>f {k $$:= v}) ++\<^sub>f s \ (m ++\<^sub>f {k $$:= v})" + by simp + also have "\ = s \/ m ++\<^sub>f s \/ {k $$:= v} ++\<^sub>f s \ m ++\<^sub>f s \ {k $$:= v}" + using dom_exc_add_distr by simp + finally show ?case + proof (cases "k \ s") + case True + then have "s \/ m ++\<^sub>f s \/ {k $$:= v} ++\<^sub>f s \ m ++\<^sub>f s \ {k $$:= v} = + s \/ m ++\<^sub>f {$$} ++\<^sub>f s \ m ++\<^sub>f {k $$:= v}" + by simp + also have "\ = s \/ m ++\<^sub>f s \ m ++\<^sub>f {k $$:= v}" + by simp + also from fmupd.IH have "\ = m ++\<^sub>f {k $$:= v}" + by simp + finally show ?thesis using fmupd.hyps + by auto + next + case False + then have "s \/ m ++\<^sub>f s \/ {k $$:= v} ++\<^sub>f s \ m ++\<^sub>f s \ {k $$:= v} = + s \/ m ++\<^sub>f {k $$:= v} ++\<^sub>f s \ m ++\<^sub>f {$$}" + by simp + also have "\ = s \/ m ++\<^sub>f {k $$:= v} ++\<^sub>f s \ m" + by simp + also from fmupd.hyps have "\ = s \/ m ++\<^sub>f s \ m ++\<^sub>f {k $$:= v}" + using fmap_singleton_comm by (metis (full_types) fmadd_assoc fmlookup_filter) + also from fmupd.IH have "\ = m ++\<^sub>f {k $$:= v}" + by simp + finally show ?thesis + by auto + qed +qed + +lemma dom_res_addition_in: + assumes "m\<^sub>1 $$ k = None" + and "m\<^sub>2 $$ k = Some v'" + shows "fmdom' (m\<^sub>1(k $$:= v)) \ m\<^sub>2 = fmdom' m\<^sub>1 \ m\<^sub>2 ++\<^sub>f {k $$:= v'}" +proof - + from \m\<^sub>1 $$ k = None\ have "fmdom' (m\<^sub>1(k $$:= v)) \ m\<^sub>2 = (fmdom' m\<^sub>1 \ {k}) \ m\<^sub>2" + by simp + also have "\ = fmdom' m\<^sub>1 \ m\<^sub>2 ++\<^sub>f {k} \ m\<^sub>2" + using dom_res_union_distr . + finally show ?thesis + using \m\<^sub>2 $$ k = Some v'\ and dom_res_singleton by fastforce +qed + +lemma dom_res_addition_not_in: + assumes "m\<^sub>2 $$ k = None" + shows "fmdom' (m\<^sub>1(k $$:= v)) \ m\<^sub>2 = fmdom' m\<^sub>1 \ m\<^sub>2" +proof - + have "fmdom' (m\<^sub>1(k $$:= v)) \ m\<^sub>2 = fmfilter (\k'. k' = k \ k' \ fmdom' m\<^sub>1) m\<^sub>2" + by simp + also have "\ = fmdom' m\<^sub>1 \ m\<^sub>2" + proof (intro fmfilter_cong') + show "m\<^sub>2 = m\<^sub>2" .. + next + from assms show "k' \ fmdom' m\<^sub>2 \ (k' = k \ k' \ fmdom' m\<^sub>1) = (k' \ fmdom' m\<^sub>1)" for k' + by (cases "k' = k") (simp_all add: fmdom'_notI) + qed + finally show ?thesis . +qed + +lemma inter_plus_addition_in: + assumes "m\<^sub>1 $$ k = None" + and "m\<^sub>2 $$ k = Some v'" + shows "m\<^sub>1(k $$:= v) \\<^sub>+ m\<^sub>2 = (m\<^sub>1 \\<^sub>+ m\<^sub>2) ++\<^sub>f {k $$:= v' + v}" +proof - + let ?f = "\k' v'. v' + m\<^sub>1(k $$:= v) $$! k'" + from assms have "m\<^sub>1(k $$:= v) \\<^sub>+ m\<^sub>2 = fmmap_keys ?f ((fmdom' m\<^sub>1 \ m\<^sub>2) ++\<^sub>f {k $$:= v'})" + using dom_res_addition_in by fastforce + also have "\ = fmmap_keys ?f (fmdom' m\<^sub>1 \ m\<^sub>2) ++\<^sub>f fmmap_keys ?f {k $$:= v'}" + proof - + from \m\<^sub>1 $$ k = None\ have "fmdom' (fmdom' m\<^sub>1 \ m\<^sub>2) \ fmdom' {k $$:= v'} = {}" + by (simp add: fmdom'_notI) + then show ?thesis + using fmmap_keys_hom by blast + qed + also from assms + have "\ = fmmap_keys ?f (fmdom' m\<^sub>1 \ m\<^sub>2) ++\<^sub>f {k $$:= v' + v}" + proof - + have "fmmap_keys ?f {k $$:= v'} = {k $$:= v' + v}" + proof (intro fmap_ext) + fix k' + have "fmmap_keys ?f {k $$:= v'} $$ k' = map_option (?f k') ({k $$:= v'} $$ k')" + using fmlookup_fmmap_keys . + also have "\ = map_option (?f k') (if k = k' then Some v' else {$$} $$ k')" + by simp + also have "\ = {k $$:= v' + v} $$ k'" + by (cases "k' = k") simp_all + finally show "fmmap_keys ?f {k $$:= v'} $$ k' = {k $$:= v' + v} $$ k'" . + qed + then show ?thesis + by simp + qed + also have "\ = fmmap_keys (\k' v'. v' + m\<^sub>1 $$! k') (fmdom' m\<^sub>1 \ m\<^sub>2) ++\<^sub>f {k $$:= v' + v}" + by (simp add: fmap_ext) + finally show ?thesis . +qed + +lemma inter_plus_addition_notin: + assumes "m\<^sub>1 $$ k = None" + and "m\<^sub>2 $$ k = None" + shows "m\<^sub>1(k $$:= v) \\<^sub>+ m\<^sub>2 = (m\<^sub>1 \\<^sub>+ m\<^sub>2)" +proof - + let ?f = "\k' v'. v' + m\<^sub>1(k $$:= v) $$! k'" + from \m\<^sub>2 $$ k = None\ + have "m\<^sub>1(k $$:= v) \\<^sub>+ m\<^sub>2 = fmmap_keys ?f (fmdom' m\<^sub>1 \ m\<^sub>2)" + using dom_res_addition_not_in by metis + also have "\ = fmmap_keys (\k' v'. v' + m\<^sub>1 $$! k') (fmdom' m\<^sub>1 \ m\<^sub>2)" + proof (intro fmap_ext) + fix k' + have "fmmap_keys ?f (fmdom' m\<^sub>1 \ m\<^sub>2) $$ k' = map_option (?f k') ((fmdom' m\<^sub>1 \ m\<^sub>2) $$ k')" + using fmlookup_fmmap_keys . + also from \m\<^sub>1 $$ k = None\ have "\ = fmmap_keys (\k' v'. v' + m\<^sub>1 $$! k') (fmdom' m\<^sub>1 \ m\<^sub>2) $$ k'" + by (cases "k' = k") (simp_all add: fmdom'_notI) + finally show "fmmap_keys ?f (fmdom' m\<^sub>1 \ m\<^sub>2) $$ k' = + fmmap_keys (\k' v'. v' + m\<^sub>1 $$! k') (fmdom' m\<^sub>1 \ m\<^sub>2) $$ k'" . + qed + finally show ?thesis . +qed + +lemma union_plus_addition_notin: (* TODO: Find nicer proofs for SMT calls. *) + assumes "m\<^sub>1 $$ k = None" + and "m\<^sub>2 $$ k = None" + shows "m\<^sub>1(k $$:= v) \\<^sub>+ m\<^sub>2 = (m\<^sub>1 \\<^sub>+ m\<^sub>2) ++\<^sub>f {k $$:= v}" +proof - + from \m\<^sub>2 $$ k = None\ have "(m\<^sub>1(k $$:= v)) \\<^sub>+ m\<^sub>2 = + fmdom' m\<^sub>2 \/ m\<^sub>1 ++\<^sub>f {k $$:= v} ++\<^sub>f fmdom' (m\<^sub>1(k $$:= v)) \/ m\<^sub>2 ++\<^sub>f (m\<^sub>1(k $$:= v) \\<^sub>+ m\<^sub>2)" + by (simp add: fmdom'_notI) + also from assms have "\ = + fmdom' m\<^sub>2 \/ m\<^sub>1 ++\<^sub>f {k $$:= v} ++\<^sub>f fmdom' m\<^sub>1 \/ m\<^sub>2 ++\<^sub>f (m\<^sub>1(k $$:= v) \\<^sub>+ m\<^sub>2)" + by (smt fmdom'_fmupd fmfilter_cong insert_iff option.distinct(1)) + also from assms have "\ = fmdom' m\<^sub>2 \/ m\<^sub>1 ++\<^sub>f {k $$:= v} ++\<^sub>f fmdom' m\<^sub>1 \/ m\<^sub>2 ++\<^sub>f (m\<^sub>1 \\<^sub>+ m\<^sub>2)" + using inter_plus_addition_notin by metis + also from assms have "\ = fmdom' m\<^sub>2 \/ m\<^sub>1 ++\<^sub>f fmdom' m\<^sub>1 \/ m\<^sub>2 ++\<^sub>f (m\<^sub>1 \\<^sub>+ m\<^sub>2) ++\<^sub>f {k $$:= v}" + using fmap_singleton_comm + by (smt fmadd_assoc fmfilter_fmmap_keys fmlookup_filter fmlookup_fmmap_keys) + finally show ?thesis . +qed + +end diff --git a/thys/Finite-Map-Extras/ROOT b/thys/Finite-Map-Extras/ROOT new file mode 100644 --- /dev/null +++ b/thys/Finite-Map-Extras/ROOT @@ -0,0 +1,14 @@ +chapter AFP + +session "Finite-Map-Extras" (AFP) = HOL + + options [timeout = 600] + + sessions + "HOL-Library" + + theories + Finite_Map_Extras + + document_files + "root.tex" + diff --git a/thys/Finite-Map-Extras/document/root.tex b/thys/Finite-Map-Extras/document/root.tex new file mode 100644 --- /dev/null +++ b/thys/Finite-Map-Extras/document/root.tex @@ -0,0 +1,32 @@ +\documentclass[11pt,a4paper]{article} + +\usepackage{isabelle,isabellesym} + +\usepackage{latexsym} +\usepackage{amssymb} +\usepackage{pdfsetup} + +\addtolength{\hoffset}{-1,5cm} +\addtolength{\textwidth}{3cm} + +%\urlstyle{rm} +\isabellestyle{it} + +\begin{document} + +\title{Finite Map Extras} +\author{Javier D\'iaz\\\url{}} +\maketitle + +\begin{abstract} + This includes useful syntactic sugar, new operators and functions and their associated lemmas for + finite maps which currently are not present in the standard \texttt{Finite\_Map} theory. +\end{abstract} + +\tableofcontents + +\parindent 0pt\parskip 0.5ex + +\input{session} + +\end{document} diff --git a/thys/Isabelle_Marries_Dirac/Basics.thy b/thys/Isabelle_Marries_Dirac/Basics.thy new file mode 100755 --- /dev/null +++ b/thys/Isabelle_Marries_Dirac/Basics.thy @@ -0,0 +1,235 @@ +section \Basic Results\ + +theory Basics +imports + HOL.Set_Interval + HOL.Semiring_Normalization + HOL.Real_Vector_Spaces + HOL.Power + HOL.Complex + Jordan_Normal_Form.Jordan_Normal_Form +begin + + + +subsection \Basic Set-Theoretic Results\ + +lemma set_2_atLeast0 [simp]: "{0..<2::nat} = {0,1}" by auto + +lemma set_2: "{..<2::nat} = {0,1}" by auto + +lemma set_4_atLeast0 [simp]:"{0..<4::nat} = {0,1,2,3}" by auto + +lemma set_4: "{..<4::nat} = {0,1,2,3}" by auto + +lemma set_4_disj [simp]: + fixes i:: nat + assumes "i < 4" + shows "i = 0 \ i = 1 \ i = 2 \ i = 3" + using assms by auto + +lemma set_8_atLeast0 [simp]: "{0..<8::nat} = {0,1,2,3,4,5,6,7}" by auto + +lemma index_is_2 [simp]: "\i::nat. i \ Suc 0 \ i \ 3 \ 0 < i \ i < 4 \ i = 2" by simp + +lemma index_sl_four [simp]: "\i::nat. i < 4 \ i = 0 \ i = 1 \ i = 2 \ i = 3" by auto + + +subsection \Basic Arithmetic Results\ + +lemma index_div_eq [simp]: + fixes i::nat + shows "i\{a*b..<(a+1)*b} \ i div b = a" +proof- + fix i::nat + assume a:"i\{a*b..<(a+1)*b}" + then have "i div b \ a" + by (metis Suc_eq_plus1 atLeastLessThan_iff le_refl semiring_normalization_rules(7) split_div') + moreover have "i div b < a+1" + using a by (simp add: less_mult_imp_div_less) + ultimately show "i div b = a" by simp +qed + +lemma index_mod_eq [simp]: + fixes i::nat + shows "i\{a*b..<(a+1)*b} \ i mod b = i-a*b" + by (simp add: modulo_nat_def) + +lemma sqr_of_cmod_of_prod: + shows "(cmod (z1 * z2))\<^sup>2 = (cmod z1)\<^sup>2 * (cmod z2)\<^sup>2" + by (simp add: norm_mult power_mult_distrib) + +lemma less_power_add_imp_div_less [simp]: + fixes i m n:: nat + assumes "i < 2^(m+n)" + shows "i div 2^n < 2^m" + using assms by (simp add: less_mult_imp_div_less power_add) + +lemma div_mult_mod_eq_minus: + fixes i j:: nat + shows "(i div 2^n) * 2^n + i mod 2^n - (j div 2^n) * 2^n - j mod 2^n = i - j" + by (simp add: div_mult_mod_eq algebra_simps) + +lemma neq_imp_neq_div_or_mod: + fixes i j:: nat + assumes "i \ j" + shows "i div 2^n \ j div 2^n \ i mod 2^n \ j mod 2^n" + using assms div_mult_mod_eq_minus + by (metis add.right_neutral cancel_div_mod_rules(2)) + +lemma index_one_mat_div_mod: + assumes "i < 2^(m+n)" and "j < 2^(m+n)" + shows "((1\<^sub>m(2^m) $$ (i div 2^n, j div 2^n))::complex) * 1\<^sub>m(2^n) $$ (i mod 2^n, j mod 2^n) = 1\<^sub>m(2^(m+n)) $$ (i, j)" +proof (cases "i = j") + case True + then show ?thesis by(simp add: assms) +next + case c1:False + have "i div 2^n \ j div 2^n \ i mod 2^n \ j mod 2^n" + using c1 neq_imp_neq_div_or_mod by simp + then have "1\<^sub>m (2^m) $$ (i div 2^n, j div 2^n) = 0 \ 1\<^sub>m (2^n) $$ (i mod 2^n, j mod 2^n) = 0" + using assms by simp + then show ?thesis + using assms by (simp add: c1) +qed + +lemma sqr_of_sqrt_2 [simp]: + fixes z:: "complex" + shows "z * 2 / (complex_of_real (sqrt 2) * complex_of_real (sqrt 2)) = z" + by(metis nonzero_mult_div_cancel_right norm_numeral of_real_numeral of_real_power power2_eq_square +real_norm_def real_sqrt_abs real_sqrt_power zero_neq_numeral) + +lemma two_div_sqrt_two [simp]: + shows "2 * complex_of_real (sqrt (1/2)) = complex_of_real (sqrt 2)" + apply(auto simp add: real_sqrt_divide algebra_simps) + by (metis divide_eq_0_iff nonzero_mult_div_cancel_left sqr_of_sqrt_2) + +lemma two_div_sqr_of_cmd_sqrt_two [simp]: + shows "2 * (cmod (1 / complex_of_real (sqrt 2)))\<^sup>2 = 1" + using cmod_def by (simp add: power_divide) + +lemma two_div_two [simp]: + shows "2 div Suc (Suc 0) = 1" by simp + +lemma two_mod_two [simp]: + shows "2 mod Suc (Suc 0) = 0" by (simp add: numeral_2_eq_2) + +lemma three_div_two [simp]: + shows "3 div Suc (Suc 0) = 1" by (simp add: numeral_3_eq_3) + +lemma three_mod_two [simp]: + shows "3 mod Suc (Suc 0) = 1" by (simp add: mod_Suc numeral_3_eq_3) + + +subsection \Basic Results on Matrices\ + +lemma index_matrix_prod [simp]: + assumes "i < dim_row A" and "j < dim_col B" and "dim_col A = dim_row B" + shows "(A * B) $$ (i,j) = (\kBasic Results on Sums\ + +lemma sum_insert [simp]: + assumes "x \ F" and "finite F" + shows "(\y\insert x F. P y) = (\y\F. P y) + P x" + using assms insert_def by(simp add: add.commute) + +lemma sum_of_index_diff [simp]: + fixes f:: "nat \ 'a::comm_monoid_add" + shows "(\i\{a..i\{..Basic Results Involving the Exponential Function.\ + +lemma exp_of_real_cnj: + fixes x ::real + shows "cnj (exp (\ * x)) = exp (-(\ * x))" +proof + show "Re (cnj (exp (\ * x))) = Re (exp (-(\ * x)))" + using Re_exp by simp + show "Im (cnj (exp (\ * x))) = Im (exp (-(\ * x)))" + using Im_exp by simp +qed + +lemma exp_of_real_cnj2: + fixes x ::real + shows "cnj (exp (-(\ * x))) = exp (\ * x)" +proof + show "Re (cnj (exp (-(\ * x)))) = Re (exp (\ * x))" + using Re_exp by simp + show "Im (cnj (exp (-(\ * x)))) = Im (exp (\ * x))" + using Im_exp by simp +qed + +lemma exp_of_half_pi: + fixes x:: real + assumes "x = pi/2" + shows "exp (\ * complex_of_real x) = \" + using assms cis_conv_exp cis_pi_half by fastforce + +lemma exp_of_minus_half_pi: + fixes x:: real + assumes "x = pi/2" + shows "exp (-(\ * complex_of_real x)) = -\" + using assms cis_conv_exp cis_minus_pi_half by fastforce + +lemma exp_of_real: + fixes x:: real + shows "exp (\ * x) = cos x + \ * (sin x)" +proof + show "Re (exp (\ * x)) = Re ((cos x) + \ * (sin x))" + using Re_exp by simp + show "Im (exp (\ * x)) = Im ((cos x) + \ * (sin x))" + using Im_exp by simp +qed + +lemma exp_of_real_inv: + fixes x:: real + shows "exp (-(\ * x)) = cos x - \ * (sin x)" +proof + show "Re (exp (-(\ * x))) = Re ((cos x) - \ * (sin x))" + using Re_exp by simp + show "Im (exp (-(\ * x))) = Im ((cos x) - \ * (sin x))" + using Im_exp by simp +qed + + +subsection \Basic Results with Trigonometric Functions.\ + +subsubsection \Basic Inequalities\ + +lemma sin_squared_le_one: + fixes x:: real + shows "(sin x)\<^sup>2 \ 1" + using abs_sin_le_one abs_square_le_1 by blast + +lemma cos_squared_le_one: + fixes x:: real + shows "(cos x)\<^sup>2 \ 1" + using abs_cos_le_one abs_square_le_1 by blast + +subsubsection \Basic Equalities\ + +lemma sin_of_quarter_pi: + fixes x:: real + assumes "x = pi/2" + shows "sin (x/2) = (sqrt 2)/2" + by (auto simp add: assms sin_45) + +lemma cos_of_quarter_pi: + fixes x:: real + assumes "x = pi/2" + shows "cos (x/2) = (sqrt 2)/2" + by (auto simp add: assms cos_45) + +end \ No newline at end of file diff --git a/thys/Isabelle_Marries_Dirac/Binary_Nat.thy b/thys/Isabelle_Marries_Dirac/Binary_Nat.thy new file mode 100755 --- /dev/null +++ b/thys/Isabelle_Marries_Dirac/Binary_Nat.thy @@ -0,0 +1,246 @@ +(* +Authors: + Anthony Bordg, University of Cambridge, apdb3@cam.ac.uk + Hanna Lachnitt, TU Wien, lachnitt@student.tuwien.ac.at +*) + +section \Binary Representation of Natural Numbers\ + +theory Binary_Nat +imports + HOL.Nat + HOL.List + Basics +begin + + +primrec bin_rep_aux:: "nat \ nat \ nat list" where + "bin_rep_aux 0 m = [m]" +| "bin_rep_aux (Suc n) m = m div 2^n # bin_rep_aux n (m mod 2^n)" + +lemma length_of_bin_rep_aux: + fixes n m:: nat + assumes "m < 2^n" + shows "length (bin_rep_aux n m) = n+1" + using assms +proof(induction n arbitrary: m) + case 0 + then show "length (bin_rep_aux 0 m) = 0 + 1" by simp +next + case (Suc n) + assume a0:"\m. m < 2^n \ length (bin_rep_aux n m) = n + 1" and "m < 2^(Suc n)" + then show "length (bin_rep_aux (Suc n) m) = Suc n + 1" + using a0 by simp +qed + +lemma bin_rep_aux_neq_nil: + fixes n m:: nat + shows "bin_rep_aux n m \ []" + using bin_rep_aux.simps by (metis list.distinct(1) old.nat.exhaust) + +lemma last_of_bin_rep_aux: + fixes n m:: nat + assumes "m < 2^n" and "m \ 0" + shows "last (bin_rep_aux n m) = 0" + using assms +proof(induction n arbitrary: m) + case 0 + assume "m < 2^0" and "m \ 0" + then show "last (bin_rep_aux 0 m) = 0" by simp +next + case (Suc n) + assume a0:"\m. m < 2^n \ m \ 0 \ last (bin_rep_aux n m) = 0" and "m < 2^(Suc n)" +and "m \ 0" + then show "last (bin_rep_aux (Suc n) m) = 0" + using bin_rep_aux_neq_nil by simp +qed + +lemma mod_mod_power_cancel: + fixes m n p:: nat + assumes "m \ n" + shows "p mod 2^n mod 2^m = p mod 2^m" + using assms by (simp add: dvd_power_le mod_mod_cancel) + +lemma bin_rep_aux_index: + fixes n m i:: nat + assumes "n \ 1" and "m < 2^n" and "m \ 0" and "i \ n" + shows "bin_rep_aux n m ! i = (m mod 2^(n-i)) div 2^(n-1-i)" + using assms +proof(induction n arbitrary: m i rule: nat_induct_at_least) + case base + assume "m < 2^1" and "i \ 1" + then show "bin_rep_aux 1 m ! i = m mod 2^(1-i) div 2^(1-1-i)" + using bin_rep_aux.simps + by (metis One_nat_def base.prems(2) diff_is_0_eq' diff_zero div_by_1 le_Suc_eq le_numeral_extra(3) +nth_Cons' power_0 unique_euclidean_semiring_numeral_class.mod_less) +next + case (Suc n) + assume a0:"\m i. m < 2^n \ m \ 0 \ i \ n \ bin_rep_aux n m ! i = m mod 2 ^ (n-i) div 2^(n-1-i)" +and a1:"m < 2^(Suc n)" and a2:"i \ Suc n" and a3:"m \ 0" + then show "bin_rep_aux (Suc n) m ! i = m mod 2^(Suc n - i) div 2^(Suc n - 1 - i)" + proof- + have "bin_rep_aux (Suc n) m = m div 2^n # bin_rep_aux n (m mod 2^n)" by simp + then have f0:"bin_rep_aux (Suc n) m ! i = (m div 2^n # bin_rep_aux n (m mod 2^n)) ! i" by simp + then have "bin_rep_aux (Suc n) m ! i = m div 2^n" if "i = 0" using that by simp + then have f1:"bin_rep_aux (Suc n) m ! i = m mod 2^(Suc n - i) div 2^(Suc n - 1 - i)" if "i = 0" + proof- + have "m mod 2^(Suc n - i) = m" + using that a1 by (simp add: Suc.prems(2)) + then have "m mod 2^(Suc n - i) div 2^(Suc n - 1 - i) = m div 2^n" + using that by simp + thus ?thesis by (simp add: that) + qed + then have "bin_rep_aux (Suc n) m ! i = bin_rep_aux n (m mod 2^n) ! (i-1)" if "i \ 1" + using that f0 by simp + then have f2:"bin_rep_aux (Suc n) m ! i = ((m mod 2^n) mod 2^(n - (i - 1))) div 2^(n - 1 - (i - 1))" if "i \ 1" + using that a0 a1 a2 a3 Suc.prems(2) by simp + then have f3:"bin_rep_aux (Suc n) m ! i = ((m mod 2^n) mod 2^(Suc n - i)) div 2^(Suc n - 1 - i)" if "i \ 1" + using that by simp + then have "bin_rep_aux (Suc n) m ! i = m mod 2^(Suc n - i) div 2^(Suc n - 1 - i)" if "i \ 1" + proof- + have "Suc n - i \ n" using that by simp + then have "m mod 2^n mod 2^(Suc n - i) = m mod 2^(Suc n - i)" + using mod_mod_power_cancel[of "Suc n - i" "n" "m"] by simp + thus ?thesis + using that f3 by simp + qed + thus ?thesis using f1 f2 + using linorder_not_less by blast + qed +qed + +lemma bin_rep_aux_coeff: + fixes n m i:: nat + assumes "m < 2^n" and "i \ n" and "m \ 0" + shows "bin_rep_aux n m ! i = 0 \ bin_rep_aux n m ! i = 1" + using assms +proof(induction n arbitrary: m i) + case 0 + assume "m < 2^0" and "i \ 0" and "m \ 0" + then show "bin_rep_aux 0 m ! i = 0 \ bin_rep_aux 0 m ! i = 1" by simp +next + case (Suc n) + assume a0:"\m i. m < 2 ^ n \ i \ n \ m \ 0 \ bin_rep_aux n m ! i = 0 \ bin_rep_aux n m ! i = 1" +and a1:"m < 2^Suc n" and a2:"i \ Suc n" and a3:"m \ 0" + then show "bin_rep_aux (Suc n) m ! i = 0 \ bin_rep_aux (Suc n) m ! i = 1" + proof- + have "bin_rep_aux (Suc n) m ! i = (m div 2^n # bin_rep_aux n (m mod 2^n)) ! i" by simp + moreover have "\ = bin_rep_aux n (m mod 2^n) ! (i - 1)" if "i \ 1" + using that by simp + moreover have "m mod 2^n < 2^n" by simp + ultimately have "bin_rep_aux (Suc n) m ! i = 0 \ bin_rep_aux (Suc n) m ! i = 1" if "i\1" + using that a0[of "m mod 2^n" "i-1"] a2 by simp + moreover have "m div 2^n = 0 \ m div 2^n = 1" + using a1 a3 less_mult_imp_div_less by(simp add: less_2_cases) + ultimately show ?thesis by (simp add: nth_Cons') + qed +qed + +definition bin_rep:: "nat \ nat \ nat list" where +"bin_rep n m = butlast (bin_rep_aux n m)" + +lemma length_of_bin_rep: + fixes n m:: nat + assumes "m < 2^n" + shows "length (bin_rep n m) = n" + using assms length_of_bin_rep_aux bin_rep_def by simp + +lemma bin_rep_coeff: + fixes n m i:: nat + assumes "m < 2^n" and "i < n" and "m \ 0" + shows "bin_rep n m ! i = 0 \ bin_rep n m ! i = 1" + using assms bin_rep_def bin_rep_aux_coeff length_of_bin_rep by(simp add: nth_butlast) + +lemma bin_rep_index: + fixes n m i:: nat + assumes "n \ 1" and "m < 2^n" and "i < n" and "m \ 0" + shows "bin_rep n m ! i = (m mod 2^(n-i)) div 2^(n-1-i)" +proof- + have "bin_rep n m ! i = bin_rep_aux n m ! i" + using bin_rep_def length_of_bin_rep nth_butlast assms(3) + by (simp add: nth_butlast assms(2)) + thus ?thesis + using assms bin_rep_aux_index by simp +qed + +lemma bin_rep_eq: + fixes n m:: nat + assumes "n \ 1" and "m \ 0" and "m < 2^n" and "m \ 0" + shows "m = (\i = m mod 2^(n-i) - m mod 2^(n-i) mod 2^(n-1-i)" + by (simp add: minus_mod_eq_div_mult) + moreover have "\ = int(m mod 2^(n-i)) - m mod 2^(n-i) mod 2^(n-1-i)" + using mod_less_eq_dividend of_nat_diff by blast + moreover have "\ = int(m mod 2^(n-i)) - m mod 2^(n-1-i)" + using mod_mod_power_cancel[of "n-1-i" "n-i"] by (simp add: dvd_power_le mod_mod_cancel) + ultimately have "bin_rep n m ! i * 2^(n-1-i) = int (m mod 2^(n-i)) - m mod 2^(n-1-i)" + by presburger + } + then have f0:"(\iiiiii. (m mod 2^(n-i)))::nat\nat" "(\i. (m mod 2^(n-1-i)))::nat\nat" "{..<(n::nat)}"] + by auto + moreover have "\ = m mod 2^n + (\i\{1..i = m mod 2^n + (\iii. m mod 2 ^ (n - 1 - i)" "1" "n-1"]) + by (smt One_nat_def assms(1) le_add_diff_inverse lessThan_atLeast0 plus_1_eq_Suc sum.cong sum.shift_bounds_Suc_ivl) + moreover have "\ = m mod 2^n - m mod 2^0" by simp + moreover have "\ = m" using assms by auto + ultimately show "m = (\i n" + shows "(bin_rep k m) ! 0 = 0" +proof- + have "m < 2^(k-1)" + using assms by(smt Suc_diff_1 Suc_leI gr0I le_trans less_or_eq_imp_le linorder_neqE_nat not_less +one_less_numeral_iff power_strict_increasing semiring_norm(76)) + then have f:"m div 2^(k-1) = 0" + by auto + have "k \ 1" + using assms(2) by simp + moreover have "bin_rep_aux k m = (m div 2^(k-1)) # (bin_rep_aux (k-1) (m mod 2^(k-1)))" + using bin_rep_aux.simps(2) by(metis Suc_diff_1 assms(2) diff_0_eq_0 neq0_conv zero_less_diff) + moreover have "bin_rep k m = butlast ((m div 2^(k-1)) # (bin_rep_aux (k-1) (m mod 2^(k-1))))" + using bin_rep_def by (simp add: calculation(2)) + moreover have "\ = butlast (0 # (bin_rep_aux (k-1) (m mod 2^(k-1))))" + using f by simp + moreover have "\ = 0 # butlast (bin_rep_aux (k-1) (m mod 2^(k-1)))" + by(simp add: bin_rep_aux_neq_nil) + ultimately show ?thesis + by simp +qed + +lemma bin_rep_index_0_geq: + fixes n m:: nat + assumes "m \ 2^n" and "m < 2^(n+1)" + shows "bin_rep (n+1) m ! 0 = 1" +proof- + have "bin_rep (Suc n) m = butlast (bin_rep_aux (Suc n) m)" + using bin_rep_def by simp + moreover have "\ = butlast (1 # (bin_rep_aux n (m mod 2^n)))" + using assms bin_rep_aux_def by simp + moreover have "\ = 1 # butlast (bin_rep_aux n (m mod 2^n))" + by (simp add: bin_rep_aux_neq_nil) + ultimately show ?thesis + by (simp add: bin_rep_aux_neq_nil) +qed + +end \ No newline at end of file diff --git a/thys/Isabelle_Marries_Dirac/Complex_Vectors.thy b/thys/Isabelle_Marries_Dirac/Complex_Vectors.thy new file mode 100755 --- /dev/null +++ b/thys/Isabelle_Marries_Dirac/Complex_Vectors.thy @@ -0,0 +1,236 @@ +(* Author: Anthony Bordg, University of Cambridge, apdb3@cam.ac.uk *) + +section \Complex Vectors\ + +theory Complex_Vectors +imports + Quantum + VectorSpace.VectorSpace +begin + + +subsection \The Vector Space of Complex Vectors of Dimension n\ + +definition module_cpx_vec:: "nat \ (complex, complex vec) module" where +"module_cpx_vec n \ module_vec TYPE(complex) n" + +definition cpx_rng:: "complex ring" where +"cpx_rng \ \carrier = UNIV, mult = (*), one = 1, zero = 0, add = (+)\" + +lemma cpx_cring_is_field [simp]: + "field cpx_rng" + apply unfold_locales + apply (auto intro: right_inverse simp: cpx_rng_def Units_def field_simps) + by (metis add.right_neutral add_diff_cancel_left' add_uminus_conv_diff) + +lemma cpx_abelian_monoid [simp]: + "abelian_monoid cpx_rng" + using cpx_cring_is_field + by (simp add: field_def abelian_group_def cring_def domain_def ring_def) + +lemma vecspace_cpx_vec [simp]: + "vectorspace cpx_rng (module_cpx_vec n)" + apply unfold_locales + apply (auto simp: cpx_rng_def module_cpx_vec_def module_vec_def Units_def field_simps) + apply (auto intro: right_inverse add_inv_exists_vec) + by (metis add.right_neutral add_diff_cancel_left' add_uminus_conv_diff) + +lemma module_cpx_vec [simp]: + "Module.module cpx_rng (module_cpx_vec n)" + using vecspace_cpx_vec by (simp add: vectorspace_def) + +definition state_basis:: "nat \ nat \ complex vec" where +"state_basis n i \ unit_vec (2^n) i" + +definition unit_vectors:: "nat \ (complex vec) set" where +"unit_vectors n \ {unit_vec n i | i::nat. 0 \ i \ i < n}" + +lemma unit_vectors_carrier_vec [simp]: + "unit_vectors n \ carrier_vec n" + using unit_vectors_def by auto + +lemma (in Module.module) finsum_over_singleton [simp]: + assumes "f x \ carrier M" + shows "finsum M f {x} = f x" + using assms by simp + +lemma lincomb_over_singleton [simp]: + assumes "x \ carrier_vec n" and "f \ {x} \ UNIV" + shows "module.lincomb (module_cpx_vec n) f {x} = f x \\<^sub>v x" + using assms module.lincomb_def module_cpx_vec module_cpx_vec_def module.finsum_over_singleton + by (smt module_vec_simps(3) module_vec_simps(4) smult_carrier_vec) + +lemma dim_vec_lincomb [simp]: + assumes "finite F" and "f: F \ UNIV" and "F \ carrier_vec n" + shows "dim_vec (module.lincomb (module_cpx_vec n) f F) = n" + using assms +proof(induct F) + case empty + show "dim_vec (module.lincomb (module_cpx_vec n) f {}) = n" + proof - + have "module.lincomb (module_cpx_vec n) f {} = 0\<^sub>v n" + using module.lincomb_def abelian_monoid.finsum_empty module_cpx_vec_def vecspace_cpx_vec vectorspace_def + by (smt abelian_group_def Module.module_def module_vec_simps(2)) + thus ?thesis by simp + qed +next + case (insert x F) + hence "module.lincomb (module_cpx_vec n) f (insert x F) = + (f x \\<^sub>v x) \\<^bsub>module_cpx_vec n\<^esub> module.lincomb (module_cpx_vec n) f F" + using module_cpx_vec_def module_vec_def module_cpx_vec module.lincomb_insert cpx_rng_def insert_subset + by (smt Pi_I' UNIV_I Un_insert_right module_vec_simps(4) partial_object.select_convs(1) sup_bot.comm_neutral) + hence "dim_vec (module.lincomb (module_cpx_vec n) f (insert x F)) = + dim_vec (module.lincomb (module_cpx_vec n) f F)" + using index_add_vec by (simp add: module_cpx_vec_def module_vec_simps(1)) + thus "dim_vec (module.lincomb (module_cpx_vec n) f (insert x F)) = n" + using insert.hyps(3) insert.prems(2) by simp +qed + +lemma lincomb_vec_index [simp]: + assumes "finite F" and a2:"i < n" and "F \ carrier_vec n" and "f: F \ UNIV" + shows "module.lincomb (module_cpx_vec n) f F $ i = (\v\F. f v * (v $ i))" + using assms +proof(induct F) + case empty + then show "module.lincomb (module_cpx_vec n) f {} $ i = (\v\{}. f v * v $ i)" + apply auto + using a2 module.lincomb_def abelian_monoid.finsum_empty module_cpx_vec_def + by (metis (mono_tags) abelian_group_def index_zero_vec(1) module_cpx_vec Module.module_def module_vec_simps(2)) +next + case(insert x F) + have "module.lincomb (module_cpx_vec n) f (insert x F) = + f x \\<^sub>v x \\<^bsub>module_cpx_vec n\<^esub> module.lincomb (module_cpx_vec n) f F" + using module.lincomb_insert module_cpx_vec insert.hyps(1) module_cpx_vec_def module_vec_def + insert.prems(2) insert.hyps(2) insert.prems(3) insert_def + by (smt Pi_I' UNIV_I Un_insert_right cpx_rng_def insert_subset module_vec_simps(4) + partial_object.select_convs(1) sup_bot.comm_neutral) + then have "module.lincomb (module_cpx_vec n) f (insert x F) $ i = + (f x \\<^sub>v x) $ i + module.lincomb (module_cpx_vec n) f F $ i" + using index_add_vec(1) a2 dim_vec_lincomb + by (metis Pi_split_insert_domain insert.hyps(1) insert.prems(2) insert.prems(3) insert_subset + module_cpx_vec_def module_vec_simps(1)) + hence "module.lincomb (module_cpx_vec n) f (insert x F) $ i = f x * x $ i + (\v\F. f v * v $ i)" + using index_smult_vec a2 insert.prems(2) insert_def insert.hyps(3) by auto + with insert show "module.lincomb (module_cpx_vec n) f (insert x F) $ i = (\v\insert x F. f v * v $ i)" + by auto +qed + +lemma unit_vectors_is_lin_indpt [simp]: + "module.lin_indpt cpx_rng (module_cpx_vec n) (unit_vectors n)" +proof + assume "module.lin_dep cpx_rng (module_cpx_vec n) (unit_vectors n)" + hence "\A a v. (finite A \ A \ (unit_vectors n) \ (a \ A \ UNIV) \ + (module.lincomb (module_cpx_vec n) a A = \\<^bsub>module_cpx_vec n\<^esub>) \ (v \ A) \ (a v \ \\<^bsub>cpx_rng\<^esub>))" + using module.lin_dep_def cpx_rng_def module_cpx_vec by (smt Pi_UNIV UNIV_I) + moreover obtain A and a and v where f1:"finite A" and f2:"A \ (unit_vectors n)" and "a \ A \ UNIV" + and f4:"module.lincomb (module_cpx_vec n) a A = \\<^bsub>module_cpx_vec n\<^esub>" and f5:"v \ A" and + f6:"a v \ \\<^bsub>cpx_rng\<^esub>" + using calculation by blast + moreover obtain i where f7:"v = unit_vec n i" and f8:"i < n" + using unit_vectors_def calculation by auto + ultimately have f9:"module.lincomb (module_cpx_vec n) a A $ i = (\u\A. a u * (u $ i))" + using lincomb_vec_index + by (smt carrier_dim_vec index_unit_vec(3) mem_Collect_eq subset_iff sum.cong unit_vectors_def) + moreover have "\u\A.\j j \ i \ a u * (u $ i) = 0" + using unit_vectors_def index_unit_vec by (simp add: f8) + then have "(\u\A. a u * (u $ i)) = (\u\A. if u=v then a v * v $ i else 0)" + using f2 unit_vectors_def f7 by (smt mem_Collect_eq subsetCE sum.cong) + also have "\ = a v * (v $ i)" + using abelian_monoid.finsum_singleton[of cpx_rng v A "\u\A. a u * (u $ i)"] cpx_abelian_monoid + f5 f1 cpx_rng_def by simp + also have "\ = a v" + using f7 index_unit_vec f8 by simp + also have "\ \ 0" + using f6 by (simp add: cpx_rng_def) + finally show False + using f4 module_cpx_vec_def module_vec_def index_zero_vec f8 f9 by (simp add: module_vec_simps(2)) +qed + +lemma unit_vectors_is_genset [simp]: + "module.gen_set cpx_rng (module_cpx_vec n) (unit_vectors n)" +proof + show "module.span cpx_rng (module_cpx_vec n) (unit_vectors n) \ carrier (module_cpx_vec n)" + using module.span_def dim_vec_lincomb carrier_vec_def cpx_rng_def + by (smt Collect_mono index_unit_vec(3) module.span_is_subset2 module_cpx_vec module_cpx_vec_def + module_vec_simps(3) unit_vectors_def) +next + show "carrier (module_cpx_vec n) \ module.span cpx_rng (module_cpx_vec n) (unit_vectors n)" + proof + fix v + assume a1:"v \ carrier (module_cpx_vec n)" + define A a lc where "A = {unit_vec n i ::complex vec| i::nat. i < n \ v $ i \ 0}" and + "a = (\u\A. u \ v)" and "lc = module.lincomb (module_cpx_vec n) a A" + then have f1:"finite A" by simp + have f2:"A \ carrier_vec n" + using carrier_vec_def A_def by auto + have f3:"a \ A \ UNIV" + using a_def by simp + then have f4:"dim_vec v = dim_vec lc" + using f1 f2 f3 a1 module_cpx_vec_def dim_vec_lincomb lc_def by (simp add: module_vec_simps(3)) + then have f5:"i < n \ lc $ i = (\u\A. u \ v * u $ i)" for i + using lincomb_vec_index lc_def a_def f1 f2 f3 by simp + then have "i < n \ j < n \ j \ i \ unit_vec n j \ v * unit_vec n j $ i = 0" for i j by simp + then have "i < n \ lc $ i = (\u\A. if u = unit_vec n i then v $ i else 0)" for i + using a1 A_def f5 scalar_prod_left_unit + by (smt f4 carrier_vecI dim_vec_lincomb f1 f2 f3 index_unit_vec(2) lc_def + mem_Collect_eq mult.right_neutral sum.cong) + then have "i < n \ lc $ i = v $ i" for i + using abelian_monoid.finsum_singleton[of cpx_rng i] A_def cpx_rng_def by simp + then have f6:"v = lc" + using eq_vecI f4 dim_vec_lincomb f1 f2 lc_def by auto + have "A \ unit_vectors n" + using A_def unit_vectors_def by auto + thus "v \ module.span cpx_rng (module_cpx_vec n) (unit_vectors n)" + using f6 module.span_def[of cpx_rng "module_cpx_vec n"] lc_def f1 f2 cpx_rng_def module_cpx_vec + by (smt Pi_I' UNIV_I mem_Collect_eq partial_object.select_convs(1)) + qed +qed + +lemma unit_vectors_is_basis [simp]: + "vectorspace.basis cpx_rng (module_cpx_vec n) (unit_vectors n)" +proof - + fix n + have "unit_vectors n \ carrier (module_cpx_vec n)" + using unit_vectors_def module_cpx_vec_def module_vec_simps(3) by fastforce + then show ?thesis + using vectorspace.basis_def unit_vectors_is_lin_indpt unit_vectors_is_genset vecspace_cpx_vec + by(smt carrier_dim_vec index_unit_vec(3) mem_Collect_eq module_cpx_vec_def module_vec_simps(3) + subsetI unit_vectors_def) +qed + +lemma state_qbit_is_lincomb [simp]: + "state_qbit n = + {module.lincomb (module_cpx_vec (2^n)) a A|a A. + finite A \ A\(unit_vectors (2^n)) \ a\ A \ UNIV \ \module.lincomb (module_cpx_vec (2^n)) a A\ = 1}" +proof + show "state_qbit n + \ {module.lincomb (module_cpx_vec (2^n)) a A |a A. + finite A \ A \ unit_vectors (2^n) \ a \ A \ UNIV \ \module.lincomb (module_cpx_vec (2^n)) a A\ = 1}" + proof + fix v + assume a1:"v \ state_qbit n" + then show "v \ {module.lincomb (module_cpx_vec (2^n)) a A |a A. + finite A \ A \ unit_vectors (2^n) \ a \ A \ UNIV \ \module.lincomb (module_cpx_vec (2^n)) a A\ = 1}" + proof - + obtain a and A where "finite A" and "a\ A \ UNIV" and "A \ unit_vectors (2^n)" and + "v = module.lincomb (module_cpx_vec (2^n)) a A" + using a1 state_qbit_def unit_vectors_is_basis vectorspace.basis_def module.span_def + vecspace_cpx_vec module_cpx_vec module_cpx_vec_def module_vec_def carrier_vec_def + by(smt Pi_UNIV UNIV_I mem_Collect_eq module_vec_simps(3)) + thus ?thesis + using a1 state_qbit_def by auto + qed + qed + show "{module.lincomb (module_cpx_vec (2 ^ n)) a A |a A. + finite A \ A \ unit_vectors (2 ^ n) \ a \ A \ UNIV \ \module.lincomb (module_cpx_vec (2 ^ n)) a A\ = 1} + \ state_qbit n" + proof + fix v + assume "v \ {module.lincomb (module_cpx_vec (2 ^ n)) a A |a A. + finite A \ A \ unit_vectors (2 ^ n) \ a \ A \ UNIV \ \module.lincomb (module_cpx_vec (2 ^ n)) a A\ = 1}" + then show "v \ state_qbit n" + using state_qbit_def dim_vec_lincomb unit_vectors_carrier_vec by(smt mem_Collect_eq order_trans) + qed +qed + +end \ No newline at end of file diff --git a/thys/Isabelle_Marries_Dirac/Deutsch.thy b/thys/Isabelle_Marries_Dirac/Deutsch.thy new file mode 100755 --- /dev/null +++ b/thys/Isabelle_Marries_Dirac/Deutsch.thy @@ -0,0 +1,526 @@ +(* +Authors: + + Hanna Lachnitt, TU Wien, lachnitt@student.tuwien.ac.at + Anthony Bordg, University of Cambridge, apdb3@cam.ac.uk +*) + +section \The Deutsch Algorithm\ + +theory Deutsch +imports + More_Tensor + Measurement +begin + + +text \ +Given a function $f:{0,1}\mapsto {0,1}$, Deutsch's algorithm decides if this function is constant +or balanced with a single $f(x)$ circuit to evaluate the function for multiple values of $x$ +simultaneously. The algorithm makes use of quantum parallelism and quantum interference. +\ + +text \ +A constant function with values in {0,1} returns either always 0 or always 1. +A balanced function is 0 for half of the inputs and 1 for the other half. +\ + +locale deutsch = + fixes f:: "nat \ nat" + assumes dom: "f \ ({0,1} \\<^sub>E {0,1})" + +context deutsch +begin + +definition is_swap:: bool where +"is_swap = (\x \ {0,1}. f x = 1 - x)" + +lemma is_swap_values: + assumes "is_swap" + shows "f 0 = 1" and "f 1 = 0" + using assms is_swap_def by auto + +lemma is_swap_sum_mod_2: + assumes "is_swap" + shows "(f 0 + f 1) mod 2 = 1" + using assms is_swap_def by simp + +definition const:: "nat \ bool" where +"const n = (\x \ {0,1}.(f x = n))" + +definition is_const:: "bool" where +"is_const \ const 0 \ const 1" + +definition is_balanced:: "bool" where +"is_balanced \ (\x \ {0,1}.(f x = x)) \ is_swap" + +lemma f_values: "(f 0 = 0 \ f 0 = 1) \ (f 1 = 0 \ f 1 = 1)" + using dom by auto + +lemma f_cases: + shows "is_const \ is_balanced" + using dom is_balanced_def const_def is_const_def is_swap_def f_values by auto + +lemma const_0_sum_mod_2: + assumes "const 0" + shows "(f 0 + f 1) mod 2 = 0" + using assms const_def by simp + +lemma const_1_sum_mod_2: + assumes "const 1" + shows "(f 0 + f 1) mod 2 = 0" + using assms const_def by simp + +lemma is_const_sum_mod_2: + assumes "is_const" + shows "(f 0 + f 1) mod 2 = 0" + using assms is_const_def const_0_sum_mod_2 const_1_sum_mod_2 by auto + +lemma id_sum_mod_2: + assumes "f = id" + shows "(f 0 + f 1) mod 2 = 1" + using assms by simp + +lemma is_balanced_sum_mod_2: + assumes "is_balanced" + shows "(f 0 + f 1) mod 2 = 1" + using assms is_balanced_def id_sum_mod_2 is_swap_sum_mod_2 by auto + +lemma f_ge_0: "\ x. (f x \ 0)" by simp + +end (* context deutsch *) + +text \The Deutsch's Transform @{text U\<^sub>f}.\ + +definition (in deutsch) deutsch_transform:: "complex Matrix.mat" ("U\<^sub>f") where +"U\<^sub>f \ mat_of_cols_list 4 [[1 - f(0), f(0), 0, 0], + [f(0), 1 - f(0), 0, 0], + [0, 0, 1 - f(1), f(1)], + [0, 0, f(1), 1 - f(1)]]" + +lemma (in deutsch) deutsch_transform_dim [simp]: + shows "dim_row U\<^sub>f = 4" and "dim_col U\<^sub>f = 4" + by (auto simp add: deutsch_transform_def mat_of_cols_list_def) + +lemma (in deutsch) deutsch_transform_coeff_is_zero [simp]: + shows "U\<^sub>f $$ (0,2) = 0" and "U\<^sub>f $$ (0,3) = 0" + and "U\<^sub>f $$ (1,2) = 0" and "U\<^sub>f $$(1,3) = 0" + and "U\<^sub>f $$ (2,0) = 0" and "U\<^sub>f $$(2,1) = 0" + and "U\<^sub>f $$ (3,0) = 0" and "U\<^sub>f $$ (3,1) = 0" + using deutsch_transform_def by auto + +lemma (in deutsch) deutsch_transform_coeff [simp]: + shows "U\<^sub>f $$ (0,1) = f(0)" and "U\<^sub>f $$ (1,0) = f(0)" + and "U\<^sub>f $$(2,3) = f(1)" and "U\<^sub>f $$ (3,2) = f(1)" + and "U\<^sub>f $$ (0,0) = 1 - f(0)" and "U\<^sub>f $$(1,1) = 1 - f(0)" + and "U\<^sub>f $$ (2,2) = 1 - f(1)" and "U\<^sub>f $$ (3,3) = 1 - f(1)" + using deutsch_transform_def by auto + +abbreviation (in deutsch) V\<^sub>f:: "complex Matrix.mat" where +"V\<^sub>f \ Matrix.mat 4 4 (\(i,j). + if i=0 \ j=0 then 1 - f(0) else + (if i=0 \ j=1 then f(0) else + (if i=1 \ j=0 then f(0) else + (if i=1 \ j=1 then 1 - f(0) else + (if i=2 \ j=2 then 1 - f(1) else + (if i=2 \ j=3 then f(1) else + (if i=3 \ j=2 then f(1) else + (if i=3 \ j=3 then 1 - f(1) else 0))))))))" + +lemma (in deutsch) deutsch_transform_alt_rep_coeff_is_zero [simp]: + shows "V\<^sub>f $$ (0,2) = 0" and "V\<^sub>f $$ (0,3) = 0" + and "V\<^sub>f $$ (1,2) = 0" and "V\<^sub>f $$(1,3) = 0" + and "V\<^sub>f $$ (2,0) = 0" and "V\<^sub>f $$(2,1) = 0" + and "V\<^sub>f $$ (3,0) = 0" and "V\<^sub>f $$ (3,1) = 0" + by auto + +lemma (in deutsch) deutsch_transform_alt_rep_coeff [simp]: + shows "V\<^sub>f $$ (0,1) = f(0)" and "V\<^sub>f $$ (1,0) = f(0)" + and "V\<^sub>f $$(2,3) = f(1)" and "V\<^sub>f $$ (3,2) = f(1)" + and "V\<^sub>f $$ (0,0) = 1 - f(0)" and "V\<^sub>f $$(1,1) = 1 - f(0)" + and "V\<^sub>f $$ (2,2) = 1 - f(1)" and "V\<^sub>f $$ (3,3) = 1 - f(1)" + by auto + +lemma (in deutsch) deutsch_transform_alt_rep: + shows "U\<^sub>f = V\<^sub>f" +proof + show c0:"dim_row U\<^sub>f = dim_row V\<^sub>f" by simp + show c1:"dim_col U\<^sub>f = dim_col V\<^sub>f" by simp + fix i j:: nat + assume "i < dim_row V\<^sub>f" and "j < dim_col V\<^sub>f" + then have "i < 4" and "j < 4" by auto + thus "U\<^sub>f $$ (i,j) = V\<^sub>f $$ (i,j)" + by (smt deutsch_transform_alt_rep_coeff deutsch_transform_alt_rep_coeff_is_zero deutsch_transform_coeff + deutsch_transform_coeff_is_zero set_4_disj) +qed + +text \@{text U\<^sub>f} is a gate.\ + +lemma (in deutsch) transpose_of_deutsch_transform: + shows "(U\<^sub>f)\<^sup>t = U\<^sub>f" +proof + show "dim_row (U\<^sub>f\<^sup>t) = dim_row U\<^sub>f" by simp + show "dim_col (U\<^sub>f\<^sup>t) = dim_col U\<^sub>f" by simp + fix i j:: nat + assume "i < dim_row U\<^sub>f" and "j < dim_col U\<^sub>f" + thus "U\<^sub>f\<^sup>t $$ (i, j) = U\<^sub>f $$ (i, j)" + by (auto simp add: transpose_mat_def) + (metis deutsch_transform_coeff(1-4) deutsch_transform_coeff_is_zero set_4_disj) +qed + +lemma (in deutsch) adjoint_of_deutsch_transform: + shows "(U\<^sub>f)\<^sup>\ = U\<^sub>f" +proof + show "dim_row (U\<^sub>f\<^sup>\) = dim_row U\<^sub>f" by simp + show "dim_col (U\<^sub>f\<^sup>\) = dim_col U\<^sub>f" by simp + fix i j:: nat + assume "i < dim_row U\<^sub>f" and "j < dim_col U\<^sub>f" + thus "U\<^sub>f\<^sup>\ $$ (i, j) = U\<^sub>f $$ (i, j)" + by (auto simp add: dagger_def) + (metis complex_cnj_of_nat complex_cnj_zero deutsch_transform_coeff + deutsch_transform_coeff_is_zero set_4_disj) +qed + +lemma (in deutsch) deutsch_transform_is_gate: + shows "gate 2 U\<^sub>f" +proof + show "dim_row U\<^sub>f = 2\<^sup>2" by simp + show "square_mat U\<^sub>f" by simp + show "unitary U\<^sub>f" + proof- + have "U\<^sub>f * U\<^sub>f = 1\<^sub>m (dim_col U\<^sub>f)" + proof + show "dim_row (U\<^sub>f * U\<^sub>f) = dim_row (1\<^sub>m (dim_col U\<^sub>f))" by simp + next + show "dim_col (U\<^sub>f * U\<^sub>f) = dim_col (1\<^sub>m (dim_col U\<^sub>f))" by simp + next + fix i j:: nat + assume "i < dim_row (1\<^sub>m (dim_col U\<^sub>f))" and "j < dim_col (1\<^sub>m (dim_col U\<^sub>f))" + then show "(U\<^sub>f * U\<^sub>f) $$ (i,j) = 1\<^sub>m (dim_col U\<^sub>f) $$ (i, j)" + apply (auto simp add: deutsch_transform_alt_rep one_mat_def times_mat_def) + apply (auto simp: scalar_prod_def) + using f_values by auto + qed + thus ?thesis by (simp add: adjoint_of_deutsch_transform unitary_def) + qed +qed + +text \ +Two qubits are prepared. +The first one in the state $|0\rangle$, the second one in the state $|1\rangle$. +\ + +abbreviation zero where "zero \ unit_vec 2 0" +abbreviation one where "one \ unit_vec 2 1" + +lemma ket_zero_is_state: + shows "state 1 |zero\" + by (simp add: state_def ket_vec_def cpx_vec_length_def numerals(2)) + +lemma ket_one_is_state: + shows "state 1 |one\" + by (simp add: state_def ket_vec_def cpx_vec_length_def numerals(2)) + +lemma ket_zero_to_mat_of_cols_list [simp]: "|zero\ = mat_of_cols_list 2 [[1, 0]]" + by (auto simp add: ket_vec_def mat_of_cols_list_def) + +lemma ket_one_to_mat_of_cols_list [simp]: "|one\ = mat_of_cols_list 2 [[0, 1]]" + apply (auto simp add: ket_vec_def unit_vec_def mat_of_cols_list_def) + using less_2_cases by fastforce + +text \ +Applying the Hadamard gate to the state $|0\rangle$ results in the new state +@{term "\\<^sub>0\<^sub>0"} = $\dfrac {(|0\rangle + |1\rangle)} {\sqrt 2 }$ +\ + +abbreviation \\<^sub>0\<^sub>0:: "complex Matrix.mat" where +"\\<^sub>0\<^sub>0 \ mat_of_cols_list 2 [[1/sqrt(2), 1/sqrt(2)]]" + +lemma H_on_ket_zero: + shows "(H * |zero\) = \\<^sub>0\<^sub>0" +proof + fix i j:: nat + assume "i < dim_row \\<^sub>0\<^sub>0" and "j < dim_col \\<^sub>0\<^sub>0" + then have "i \ {0,1} \ j = 0" by (simp add: mat_of_cols_list_def less_2_cases) + then show "(H * |zero\) $$ (i,j) = \\<^sub>0\<^sub>0 $$ (i,j)" + by (auto simp add: mat_of_cols_list_def times_mat_def scalar_prod_def H_def) +next + show "dim_row (H * |zero\) = dim_row \\<^sub>0\<^sub>0" by (simp add: H_def mat_of_cols_list_def) + show "dim_col (H * |zero\) = dim_col \\<^sub>0\<^sub>0" by (simp add: H_def mat_of_cols_list_def) +qed + +lemma H_on_ket_zero_is_state: + shows "state 1 (H * |zero\)" +proof + show "gate 1 H" + using H_is_gate by simp + show "state 1 |zero\" + using ket_zero_is_state by simp +qed + +text \ +Applying the Hadamard gate to the state $|0\rangle$ results in the new state +@{text \\<^sub>0\<^sub>1} = $\dfrac {(|0\rangle - |1\rangle)} {\sqrt 2}$. +\ + +abbreviation \\<^sub>0\<^sub>1:: "complex Matrix.mat" where +"\\<^sub>0\<^sub>1 \ mat_of_cols_list 2 [[1/sqrt(2), -1/sqrt(2)]]" + +lemma H_on_ket_one: + shows "(H * |one\) = \\<^sub>0\<^sub>1" +proof + fix i j:: nat + assume "i < dim_row \\<^sub>0\<^sub>1" and "j < dim_col \\<^sub>0\<^sub>1" + then have "i \ {0,1} \ j = 0" by (simp add: mat_of_cols_list_def less_2_cases) + then show "(H * |one\) $$ (i,j) = \\<^sub>0\<^sub>1 $$ (i,j)" + by (auto simp add: mat_of_cols_list_def times_mat_def scalar_prod_def H_def ket_vec_def) +next + show "dim_row (H * |one\) = dim_row \\<^sub>0\<^sub>1" by (simp add: H_def mat_of_cols_list_def) + show "dim_col (H * |one\) = dim_col \\<^sub>0\<^sub>1" by (simp add: H_def mat_of_cols_list_def ket_vec_def) +qed + +lemma H_on_ket_one_is_state: + shows "state 1 (H * |one\)" + using H_is_gate ket_one_is_state by simp + +text\ +Then, the state @{text \\<^sub>1} = $\dfrac {(|00\rangle - |01\rangle + |10\rangle - |11\rangle)} {2} $ +is obtained by taking the tensor product of the states +@{text \\<^sub>0\<^sub>0} = $\dfrac {(|0\rangle + |1\rangle)} {\sqrt 2} $ and +@{text \\<^sub>0\<^sub>1} = $\dfrac {(|0\rangle - |1\rangle)} {\sqrt 2} $. +\ + +abbreviation \\<^sub>1:: "complex Matrix.mat" where +"\\<^sub>1 \ mat_of_cols_list 4 [[1/2, -1/2, 1/2, -1/2]]" + +lemma \\<^sub>0_to_\\<^sub>1: + shows "(\\<^sub>0\<^sub>0 \ \\<^sub>0\<^sub>1) = \\<^sub>1" +proof + fix i j:: nat + assume "i < dim_row \\<^sub>1" and "j < dim_col \\<^sub>1" + then have "i \ {0,1,2,3}" and "j = 0" using mat_of_cols_list_def by auto + moreover have "complex_of_real (sqrt 2) * complex_of_real (sqrt 2) = 2" + by (metis mult_2_right numeral_Bit0 of_real_mult of_real_numeral real_sqrt_four real_sqrt_mult) + ultimately show "(\\<^sub>0\<^sub>0 \ \\<^sub>0\<^sub>1) $$ (i,j) = \\<^sub>1 $$ (i,j)" using mat_of_cols_list_def by auto +next + show "dim_row (\\<^sub>0\<^sub>0 \ \\<^sub>0\<^sub>1) = dim_row \\<^sub>1" by (simp add: mat_of_cols_list_def) + show "dim_col (\\<^sub>0\<^sub>0 \ \\<^sub>0\<^sub>1) = dim_col \\<^sub>1" by (simp add: mat_of_cols_list_def) +qed + +lemma \\<^sub>1_is_state: + shows "state 2 \\<^sub>1" +proof + show "dim_col \\<^sub>1 = 1" + by (simp add: Tensor.mat_of_cols_list_def) + show "dim_row \\<^sub>1 = 2\<^sup>2" + by (simp add: Tensor.mat_of_cols_list_def) + show "\Matrix.col \\<^sub>1 0\ = 1" + using H_on_ket_one_is_state H_on_ket_zero_is_state state.is_normal tensor_state2 \\<^sub>0_to_\\<^sub>1 + H_on_ket_one H_on_ket_zero by force +qed + +text \ +Next, the gate @{text U\<^sub>f} is applied to the state +@{text \\<^sub>1} = $\dfrac {(|00\rangle - |01\rangle + |10\rangle - |11\rangle)} {2}$ and +@{text \\<^sub>2}= $\dfrac {(|0f(0)\oplus 0\rangle - |0 f(0) \oplus 1\rangle + |1 f(1)\oplus 0\rangle - |1f(1)\oplus 1\rangle)} {2}$ +is obtained. This simplifies to +@{text \\<^sub>2}= $\dfrac {(|0f(0)\rangle - |0 \overline{f(0)} \rangle + |1 f(1)\rangle - |1\overline{f(1)}\rangle)} {2}$ +\ + +abbreviation (in deutsch) \\<^sub>2:: "complex Matrix.mat" where +"\\<^sub>2 \ mat_of_cols_list 4 [[(1 - f(0))/2 - f(0)/2, + f(0)/2 - (1 - f(0))/2, + (1 - f(1))/2 - f(1)/2, + f(1)/2 - (1- f(1))/2]]" + +lemma (in deutsch) \\<^sub>1_to_\\<^sub>2: + shows "U\<^sub>f * \\<^sub>1 = \\<^sub>2" +proof + fix i j:: nat + assume "i < dim_row \\<^sub>2 " and "j < dim_col \\<^sub>2" + then have asm:"i \ {0,1,2,3} \ j = 0 " by (auto simp add: mat_of_cols_list_def) + then have "i < dim_row U\<^sub>f \ j < dim_col \\<^sub>1" + using deutsch_transform_def mat_of_cols_list_def by auto + then have "(U\<^sub>f * \\<^sub>1) $$ (i, j) + = (\ k \ {0 ..< dim_vec \\<^sub>1}. (Matrix.row U\<^sub>f i) $ k * (Matrix.col \\<^sub>1 j) $ k)" + apply (auto simp add: times_mat_def scalar_prod_def). + thus "(U\<^sub>f * \\<^sub>1) $$ (i, j) = \\<^sub>2 $$ (i, j)" + using mat_of_cols_list_def deutsch_transform_def asm by auto +next + show "dim_row (U\<^sub>f * \\<^sub>1) = dim_row \\<^sub>2" by (simp add: mat_of_cols_list_def) + show "dim_col (U\<^sub>f * \\<^sub>1) = dim_col \\<^sub>2" by (simp add: mat_of_cols_list_def) +qed + +lemma (in deutsch) \\<^sub>2_is_state: + shows "state 2 \\<^sub>2" +proof + show "dim_col \\<^sub>2 = 1" + by (simp add: Tensor.mat_of_cols_list_def) + show "dim_row \\<^sub>2 = 2\<^sup>2" + by (simp add: Tensor.mat_of_cols_list_def) + show "\Matrix.col \\<^sub>2 0\ = 1" + using gate_on_state_is_state \\<^sub>1_is_state deutsch_transform_is_gate \\<^sub>1_to_\\<^sub>2 state_def + by (metis (no_types, lifting)) +qed + +lemma H_tensor_Id_1: + defines d:"v \ mat_of_cols_list 4 [[1/sqrt(2), 0, 1/sqrt(2), 0], + [0, 1/sqrt(2), 0, 1/sqrt(2)], + [1/sqrt(2), 0, -1/sqrt(2), 0], + [0, 1/sqrt(2), 0, -1/sqrt(2)]]" + shows "(H \ Id 1) = v" +proof + show "dim_col (H \ Id 1) = dim_col v" + by (simp add: d H_def Id_def mat_of_cols_list_def) + show "dim_row (H \ Id 1) = dim_row v" + by (simp add: d H_def Id_def mat_of_cols_list_def) + fix i j:: nat assume "i < dim_row v" and "j < dim_col v" + then have "i \ {0..<4} \ j \ {0..<4}" + by (auto simp add: d mat_of_cols_list_def) + thus "(H \ Id 1) $$ (i, j) = v $$ (i, j)" + by (auto simp add: d Id_def H_def mat_of_cols_list_def) +qed + +lemma H_tensor_Id_1_is_gate: + shows "gate 2 (H \ Id 1)" +proof + show "dim_row (H \ Quantum.Id 1) = 2\<^sup>2" + using H_tensor_Id_1 by (simp add: mat_of_cols_list_def) + show "square_mat (H \ Quantum.Id 1)" + using H_is_gate id_is_gate tensor_gate_sqr_mat by blast + show "unitary (H \ Quantum.Id 1)" + using H_is_gate gate_def id_is_gate tensor_gate by blast +qed + +text \ +Applying the Hadamard gate to the first qubit of @{text \\<^sub>2} results in @{text \\<^sub>3} = +$\pm |f(0)\oplus f(1)\rangle \left[ \dfrac {(|0\rangle - |1\rangle)} {\sqrt 2}\right]$ +\ + +abbreviation (in deutsch) \\<^sub>3:: "complex Matrix.mat" where +"\\<^sub>3 \ mat_of_cols_list 4 +[[(1-f(0))/(2*sqrt(2)) - f(0)/(2*sqrt(2)) + (1-f(1))/(2*sqrt(2)) - f(1)/(2*sqrt(2)), + f(0)/(2*sqrt(2)) - (1-f(0))/(2*sqrt(2)) + (f(1)/(2*sqrt(2)) - (1-f(1))/(2*sqrt(2))), + (1-f(0))/(2*sqrt(2)) - f(0)/(2*sqrt(2)) - (1-f(1))/(2*sqrt(2)) + f(1)/(2*sqrt(2)), + f(0)/(2*sqrt(2)) - (1-f(0))/(2*sqrt(2)) - f(1)/(2*sqrt(2)) + (1-f(1))/(2*sqrt(2))]]" + +lemma (in deutsch) \\<^sub>2_to_\\<^sub>3: + shows "(H \ Id 1) * \\<^sub>2 = \\<^sub>3" +proof + fix i j:: nat + assume "i < dim_row \\<^sub>3" and "j < dim_col \\<^sub>3" + then have a0:"i \ {0,1,2,3} \ j = 0" by (auto simp add: mat_of_cols_list_def) + then have "i < dim_row (H \ Id 1) \ j < dim_col \\<^sub>2" + using mat_of_cols_list_def H_tensor_Id_1 by auto + then have "((H \ Id 1)*\\<^sub>2) $$ (i,j) + = (\ k \ {0 ..< dim_vec \\<^sub>2}. (Matrix.row (H \ Id 1) i) $ k * (Matrix.col \\<^sub>2 j) $ k)" + by (auto simp: times_mat_def scalar_prod_def) + thus "((H \ Id 1) * \\<^sub>2) $$ (i, j) = \\<^sub>3 $$ (i, j)" + using mat_of_cols_list_def H_tensor_Id_1 a0 f_ge_0 + by (auto simp: diff_divide_distrib) +next + show "dim_row ((H \ Id 1) * \\<^sub>2) = dim_row \\<^sub>3" + using H_tensor_Id_1 mat_of_cols_list_def by simp + show "dim_col ((H \ Id 1) * \\<^sub>2) = dim_col \\<^sub>3" + using H_tensor_Id_1 mat_of_cols_list_def by simp +qed + +lemma (in deutsch) \\<^sub>3_is_state: + shows "state 2 \\<^sub>3" +proof- + have "gate 2 (H \ Id 1)" + using H_tensor_Id_1_is_gate by simp + thus "state 2 \\<^sub>3" + using \\<^sub>2_is_state \\<^sub>2_to_\\<^sub>3 by (metis gate_on_state_is_state) +qed + +text \ +Finally, all steps are put together. The result depends on the function f. If f is constant +the first qubit of $\pm |f(0)\oplus f(1)\rangle \left[ \dfrac {(|0\rangle - |1\rangle)} {\sqrt 2}\right]$ +is 0, if it is is\_balanced it is 1. +The algorithm only uses one evaluation of f(x) and will always succeed. +\ + +definition (in deutsch) deutsch_algo:: "complex Matrix.mat" where +"deutsch_algo \ (H \ Id 1) * (U\<^sub>f * ((H * |zero\) \ (H * |one\)))" + +lemma (in deutsch) deutsch_algo_result [simp]: + shows "deutsch_algo = \\<^sub>3" + using deutsch_algo_def H_on_ket_zero H_on_ket_one \\<^sub>0_to_\\<^sub>1 \\<^sub>1_to_\\<^sub>2 \\<^sub>2_to_\\<^sub>3 by simp + +lemma (in deutsch) deutsch_algo_result_is_state: + shows "state 2 deutsch_algo" + using \\<^sub>3_is_state by simp + + +text \ +If the function is constant then the measurement of the first qubit should result in the state +$|0\rangle$ with probability 1. +\ + +lemma (in deutsch) prob0_deutsch_algo_const: + assumes "is_const" + shows "prob0 2 deutsch_algo 0 = 1" +proof - + have "{k| k::nat. (k < 4) \ \ select_index 2 0 k} = {0,1}" + using select_index_def by auto + then have "prob0 2 deutsch_algo 0 = (\j\{0,1}. (cmod(deutsch_algo $$ (j,0)))\<^sup>2)" + using deutsch_algo_result_is_state prob0_def by simp + thus "prob0 2 deutsch_algo 0 = 1" + using assms is_const_def const_def by auto +qed + +lemma (in deutsch) prob1_deutsch_algo_const: + assumes "is_const" + shows "prob1 2 deutsch_algo 0 = 0" + using assms prob0_deutsch_algo_const prob_sum_is_one[of "2" "deutsch_algo" "0"] +deutsch_algo_result_is_state by simp + +text \ +If the function is balanced the measurement of the first qubit should result in the state $|1\rangle$ +with probability 1. +\ + +lemma (in deutsch) prob0_deutsch_algo_balanced: + assumes "is_balanced" + shows "prob0 2 deutsch_algo 0 = 0" +proof- + have "{k| k::nat. (k < 4) \ \ select_index 2 0 k} = {0,1}" + using select_index_def by auto + then have "prob0 2 deutsch_algo 0 = (\j \ {0,1}. (cmod(deutsch_algo $$ (j,0)))\<^sup>2)" + using deutsch_algo_result_is_state prob0_def by simp + thus "prob0 2 deutsch_algo 0 = 0" + using is_swap_values assms is_balanced_def by auto +qed + +lemma (in deutsch) prob1_deutsch_algo_balanced: + assumes "is_balanced" + shows "prob1 2 deutsch_algo 0 = 1" +using assms prob0_deutsch_algo_balanced prob_sum_is_one[of "2" "deutsch_algo" "0"] +deutsch_algo_result_is_state by simp + +text \Eventually, the measurement of the first qubit results in $f(0)\oplus f(1)$. \ + +definition (in deutsch) deutsch_algo_eval:: "real" where +"deutsch_algo_eval \ prob1 2 deutsch_algo 0" + +lemma (in deutsch) sum_mod_2_cases: + shows "(f 0 + f 1) mod 2 = 0 \ is_const" + and "(f 0 + f 1) mod 2 = 1 \ is_balanced" + using f_cases is_balanced_sum_mod_2 is_const_sum_mod_2 by auto + +lemma (in deutsch) deutsch_algo_eval_is_sum_mod_2: + shows "deutsch_algo_eval = (f 0 + f 1) mod 2" + using deutsch_algo_eval_def f_cases is_const_sum_mod_2 is_balanced_sum_mod_2 +prob1_deutsch_algo_const prob1_deutsch_algo_balanced by auto + +text \ +If the algorithm returns 0 then one concludes that the input function is constant and +if it returns 1 then the function is balanced. +\ + +theorem (in deutsch) deutsch_algo_is_correct: + shows "deutsch_algo_eval = 0 \ is_const" and "deutsch_algo_eval = 1 \ is_balanced" + using deutsch_algo_eval_is_sum_mod_2 sum_mod_2_cases by auto + +end \ No newline at end of file diff --git a/thys/Isabelle_Marries_Dirac/Deutsch_Jozsa.thy b/thys/Isabelle_Marries_Dirac/Deutsch_Jozsa.thy new file mode 100755 --- /dev/null +++ b/thys/Isabelle_Marries_Dirac/Deutsch_Jozsa.thy @@ -0,0 +1,1765 @@ +(* +Authors: + Hanna Lachnitt, TU Wien, lachnitt@student.tuwien.ac.at + Anthony Bordg, University of Cambridge, apdb3@cam.ac.uk +*) + +section \The Deutsch-Jozsa Algorithm\ + +theory Deutsch_Jozsa +imports + Deutsch + More_Tensor + Binary_Nat +begin + + +text \ +Given a function $f:{0,1}^n \mapsto {0,1}$, the Deutsch-Jozsa algorithm decides if this function is +constant or balanced with a single $f(x)$ circuit to evaluate the function for multiple values of $x$ +simultaneously. The algorithm makes use of quantum parallelism and quantum interference. + +A constant function with values in {0,1} returns either always 0 or always 1. +A balanced function is 0 for half of the inputs and 1 for the other half. +\ + +locale bob_fun = + fixes f:: "nat \ nat" and n:: "nat" + assumes dom: "f \ ({(i::nat). i < 2^n} \\<^sub>E {0,1})" + assumes dim: "n \ 1" + +context bob_fun +begin + +definition const:: "nat \ bool" where +"const c = (\x\{i::nat. i<2^n}. f x = c)" + +definition is_const:: bool where +"is_const \ const 0 \ const 1" + +definition is_balanced:: bool where +"is_balanced \ \A B ::nat set. A \ {i::nat. i < 2^n} \ B \ {i::nat. i < 2^n} + \ card A = 2^(n-1) \ card B = 2^(n-1) + \ (\x\A. f x = 0) \ (\x\B. f x = 1)" + +lemma is_balanced_inter: + fixes A B:: "nat set" + assumes "\x \ A. f x = 0" and "\x \ B. f x = 1" + shows "A \ B = {}" + using assms by auto + +lemma is_balanced_union: + fixes A B:: "nat set" + assumes "A \ {i::nat. i < 2^n}" and "B \ {i::nat. i < 2^n}" + and "card A = 2^(n-1)" and "card B = 2^(n-1)" + and "A \ B = {}" + shows "A \ B = {i::nat. i < 2^n}" +proof- + have "finite A" and "finite B" + by (simp add: assms(3) card_ge_0_finite) + (simp add: assms(4) card_ge_0_finite) + then have "card(A \ B) = 2 * 2^(n-1)" + using assms(3-5) by (simp add: card_Un_disjoint) + then have "card(A \ B) = 2^n" + by (metis Nat.nat.simps(3) One_nat_def dim le_0_eq power_eq_if) + moreover have "\ = card({i::nat. i < 2^n})" by simp + moreover have "A \ B \ {i::nat. i < 2^n}" + using assms(1,2) by simp + moreover have "finite ({i::nat. i < 2^n})" by simp + ultimately show ?thesis + using card_subset_eq[of "{i::nat. i < 2^n}" "A \ B"] by simp +qed + +lemma f_ge_0: "\x. f x \ 0" by simp + +lemma f_dom_not_zero: + shows "f \ ({i::nat. n \ 1 \ i < 2^n} \\<^sub>E {0,1})" + using dim dom by simp + +lemma f_values: "\x \ {(i::nat). i < 2^n} . f x = 0 \ f x = 1" + using dom by auto + +end (* bob_fun *) + +text \The input function has to be constant or balanced.\ + +locale jozsa = bob_fun + + assumes const_or_balanced: "is_const \ is_balanced " + +text \ +Introduce two customised rules: disjunctions with four disjuncts and induction starting from one +instead of zero. +\ + +(* To deal with Uf it is often necessary to do a case distinction with four different cases.*) +lemma disj_four_cases: + assumes "A \ B \ C \ D" and "A \ P" and "B \ P" and "C \ P" and "D \ P" + shows "P" + using assms by auto + +text \The unitary transform @{term U\<^sub>f}.\ + +definition (in jozsa) jozsa_transform:: "complex Matrix.mat" ("U\<^sub>f") where +"U\<^sub>f \ Matrix.mat (2^(n+1)) (2^(n+1)) (\(i,j). + if i = j then (1-f(i div 2)) else + if i = j + 1 \ odd i then f(i div 2) else + if i = j - 1 \ even i \ j\1 then f(i div 2) else 0)" + +lemma (in jozsa) jozsa_transform_dim [simp]: + shows "dim_row U\<^sub>f = 2^(n+1)" and "dim_col U\<^sub>f = 2^(n+1)" + by (auto simp add: jozsa_transform_def) + +lemma (in jozsa) jozsa_transform_coeff_is_zero [simp]: + assumes "i < dim_row U\<^sub>f \ j < dim_col U\<^sub>f" + shows "(i\j \ \(i=j+1 \ odd i) \ \ (i=j-1 \ even i \ j\1)) \ U\<^sub>f $$ (i,j) = 0" + using jozsa_transform_def assms by auto + +lemma (in jozsa) jozsa_transform_coeff [simp]: + assumes "i < dim_row U\<^sub>f \ j < dim_col U\<^sub>f" + shows "i = j \ U\<^sub>f $$ (i,j) = 1 - f (i div 2)" + and "i = j + 1 \ odd i \ U\<^sub>f $$ (i,j) = f (i div 2)" + and "j \ 1 \ i = j - 1 \ even i \ U\<^sub>f $$ (i,j) = f (i div 2)" + using jozsa_transform_def assms by auto + +lemma (in jozsa) U\<^sub>f_mult_without_empty_summands_sum_even: + fixes i j A + assumes "i < dim_row U\<^sub>f" and "j < dim_col A" and "even i" and "dim_col U\<^sub>f = dim_row A" + shows "(\k\{0..< dim_row A}. U\<^sub>f $$ (i,k) * A $$ (k,j)) =(\k\{i,i+1}. U\<^sub>f $$ (i,k) * A $$ (k,j))" +proof- + have "(\k \ {0..< 2^(n+1)}. U\<^sub>f $$ (i,k) * A $$ (k,j)) = + (\k \ {0..f $$ (i,k) * A $$ (k,j)) + + (\k \ {i,i+1}. U\<^sub>f $$ (i,k) * A $$ (k,j)) + + (\k \ {(i+2)..< 2^(n+1)}. U\<^sub>f $$ (i,k) * A $$ (k,j))" + proof- + have "{0..< 2^(n+1)} = {0.. {i..< 2^(n+1)} + \ {i..< 2^(n+1)} = {i,i+1} \ {(i+2)..<2^(n+1)}" using assms(1-3) by auto + moreover have "{0.. {i,i+1} = {} + \ {i,i+1} \ {(i+2)..< 2^(n+1)} = {} + \ {0.. {(i+2)..< 2^(n+1)} = {}" using assms by simp + ultimately show ?thesis + using sum.union_disjoint + by (metis (no_types, lifting) finite_Un finite_atLeastLessThan is_num_normalize(1) ivl_disj_int_two(3)) + qed + moreover have "(\k \ {0..f $$ (i,k) * A $$ (k,j)) = 0" + proof- + have "k \ {0.. (i\k \ \(i=k+1 \ odd i) \ \ (i=k-1 \ even i \ k\1))" for k + using assms by auto + then have "k \ {0.. U\<^sub>f $$ (i,k) = 0" for k + using assms(1) by auto + then show ?thesis by simp + qed + moreover have "(\k \ {(i+2)..< 2^(n+1)}. U\<^sub>f $$ (i,k) * A $$ (k,j)) = 0" + proof- + have "k\{(i+2)..< 2^(n+1)} \ (i\k \ \(i=k+1 \ odd i) \ \ (i=k-1 \ even i \ k\1))" for k by auto + then have "k \ {(i+2)..< 2^(n+1)}\ U\<^sub>f $$ (i,k) = 0" for k + using assms(1) by auto + then show ?thesis by simp + qed + moreover have "dim_row A = 2^(n+1)" using assms(4) by simp + ultimately show "?thesis" by(metis (no_types, lifting) add.left_neutral add.right_neutral) +qed + +lemma (in jozsa) U\<^sub>f_mult_without_empty_summands_even: + fixes i j A + assumes "i < dim_row U\<^sub>f" and "j < dim_col A" and "even i" and "dim_col U\<^sub>f = dim_row A" + shows "(U\<^sub>f * A) $$ (i,j) = (\k \ {i,i+1}. U\<^sub>f $$ (i,k) * A $$ (k,j))" +proof- + have "(U\<^sub>f * A) $$ (i,j) = (\ k\{0..< dim_row A}. (U\<^sub>f $$ (i,k)) * (A $$ (k,j)))" + using assms(1,2,4) index_matrix_prod by (simp add: atLeast0LessThan) + then show ?thesis + using assms U\<^sub>f_mult_without_empty_summands_sum_even by simp +qed + +lemma (in jozsa) U\<^sub>f_mult_without_empty_summands_sum_odd: + fixes i j A + assumes "i < dim_row U\<^sub>f" and "j < dim_col A" and "odd i" and "dim_col U\<^sub>f = dim_row A" + shows "(\k\{0..< dim_row A}. U\<^sub>f $$ (i,k) * A $$ (k,j)) =(\k\{i-1,i}. U\<^sub>f $$ (i,k) * A $$ (k,j))" +proof- + have "(\k\{0..< 2^(n+1)}. U\<^sub>f $$ (i,k) * A $$ (k,j)) = + (\k \ {0..f $$ (i,k) * A $$ (k,j)) + + (\k \ {i-1,i}. U\<^sub>f $$ (i,k) * A $$ (k,j)) + + (\k \ {i+1..< 2^(n+1)}. U\<^sub>f $$ (i,k) * A $$ (k,j))" + proof- + have "{0..< 2^(n+1)} = {0.. {i-1..< 2^(n+1)} + \ {i-1..< 2^(n+1)} = {i-1,i} \ {i+1..<2^(n+1)}" using assms(1-3) by auto + moreover have "{0.. {i-1,i} = {} + \ {i-1,i} \ {i+1..< 2^(n+1)} = {} + \ {0.. {i+1..< 2^(n+1)} = {}" using assms by simp + ultimately show ?thesis + using sum.union_disjoint + by(metis (no_types, lifting) finite_Un finite_atLeastLessThan is_num_normalize(1) ivl_disj_int_two(3)) + qed + moreover have "(\k \ {0..f $$ (i,k) * A $$ (k,j)) = 0" + proof- + have "k \ {0.. (i\k \ \(i=k+1 \ odd i) \ \ (i=k-1 \ even i \ k\1))" for k by auto + then have "k \ {0.. U\<^sub>f $$ (i,k) = 0" for k + using assms(1) by auto + then show ?thesis by simp + qed + moreover have "(\k \ {i+1..< 2^(n+1)}. U\<^sub>f $$ (i,k) * A $$ (k,j)) = 0" + using assms(3) by auto + moreover have "dim_row A = 2^(n+1)" using assms(4) by simp + ultimately show "?thesis" by(metis (no_types, lifting) add.left_neutral add.right_neutral) +qed + +lemma (in jozsa) U\<^sub>f_mult_without_empty_summands_odd: + fixes i j A + assumes "i < dim_row U\<^sub>f" and "j < dim_col A" and "odd i" and "dim_col U\<^sub>f = dim_row A" + shows "(U\<^sub>f * A) $$ (i,j) = (\k \ {i-1,i}. U\<^sub>f $$ (i,k) * A $$ (k,j)) " +proof- + have "(U\<^sub>f * A) $$ (i,j) = (\k \ {0 ..< dim_row A}. (U\<^sub>f $$ (i,k)) * (A $$ (k,j)))" + using assms(1,2,4) index_matrix_prod by (simp add: atLeast0LessThan) + then show "?thesis" + using assms U\<^sub>f_mult_without_empty_summands_sum_odd by auto +qed + +text \@{term U\<^sub>f} is a gate.\ + +lemma (in jozsa) transpose_of_jozsa_transform: + shows "(U\<^sub>f)\<^sup>t = U\<^sub>f" +proof + show "dim_row (U\<^sub>f\<^sup>t) = dim_row U\<^sub>f" by simp +next + show "dim_col (U\<^sub>f\<^sup>t) = dim_col U\<^sub>f" by simp +next + fix i j:: nat + assume a0: "i < dim_row U\<^sub>f" and a1: "j < dim_col U\<^sub>f" + then show "U\<^sub>f\<^sup>t $$ (i, j) = U\<^sub>f $$ (i, j)" + proof (induct rule: disj_four_cases) + show "i=j \ (i=j+1 \ odd i) \ (i=j-1 \ even i \ j\1) \ (i\j \ \(i=j+1 \ odd i) \ \ (i=j-1 \ even i \ j\1))" + by linarith + next + assume "i = j" + then show "U\<^sub>f\<^sup>t $$ (i,j) = U\<^sub>f $$ (i,j)" using a0 by simp + next + assume "(i=j+1 \ odd i)" + then show "U\<^sub>f\<^sup>t $$ (i,j) = U\<^sub>f $$ (i,j)" using transpose_mat_def a0 a1 by auto + next + assume a2:"(i=j-1 \ even i \ j\1)" + then have "U\<^sub>f $$ (i,j) = f (i div 2)" + using a0 a1 jozsa_transform_coeff by auto + moreover have "U\<^sub>f $$ (j,i) = f (i div 2)" + using a0 a1 a2 jozsa_transform_coeff + by (metis add_diff_assoc2 diff_add_inverse2 even_plus_one_iff even_succ_div_two jozsa_transform_dim) + ultimately show "?thesis" + using transpose_mat_def a0 a1 by simp + next + assume a2:"(i\j \ \(i=j+1 \ odd i) \ \ (i=j-1 \ even i \ j\1))" + then have "(j\i \ \(j=i+1 \ odd j) \ \ (j=i-1 \ even j \ i\1))" + by (metis le_imp_diff_is_add diff_add_inverse even_plus_one_iff le_add1) + then have "U\<^sub>f $$ (j,i) = 0" + using jozsa_transform_coeff_is_zero a0 a1 by auto + moreover have "U\<^sub>f $$ (i,j) = 0" + using jozsa_transform_coeff_is_zero a0 a1 a2 by auto + ultimately show "U\<^sub>f\<^sup>t $$ (i,j) = U\<^sub>f $$ (i,j)" + using transpose_mat_def a0 a1 by simp + qed +qed + +lemma (in jozsa) adjoint_of_jozsa_transform: + shows "(U\<^sub>f)\<^sup>\ = U\<^sub>f" +proof + show "dim_row (U\<^sub>f\<^sup>\) = dim_row U\<^sub>f" by simp +next + show "dim_col (U\<^sub>f\<^sup>\) = dim_col U\<^sub>f" by simp +next + fix i j:: nat + assume a0: "i < dim_row U\<^sub>f" and a1: "j < dim_col U\<^sub>f" + then show "U\<^sub>f\<^sup>\ $$ (i,j) = U\<^sub>f $$ (i,j)" + proof (induct rule: disj_four_cases) + show "i=j \ (i=j+1 \ odd i) \ (i=j-1 \ even i \ j\1) \ (i\j \ \(i=j+1 \ odd i) \ \ (i=j-1 \ even i \ j\1))" + by linarith + next + assume "i=j" + then show "U\<^sub>f\<^sup>\ $$ (i,j) = U\<^sub>f $$ (i,j)" using a0 dagger_def by simp + next + assume "(i=j+1 \ odd i)" + then show "U\<^sub>f\<^sup>\ $$ (i,j) = U\<^sub>f $$ (i,j)" using a0 dagger_def by auto + next + assume a2:"(i=j-1 \ even i \ j\1)" + then have "U\<^sub>f $$ (i,j) = f (i div 2)" + using a0 a1 jozsa_transform_coeff by auto + moreover have "U\<^sub>f\<^sup>\ $$ (j,i) = f (i div 2)" + using a1 a2 jozsa_transform_coeff dagger_def by auto + ultimately show "U\<^sub>f\<^sup>\ $$ (i,j) = U\<^sub>f $$ (i,j)" + by(metis a0 a1 cnj_transpose_is_dagger dim_row_of_dagger index_transpose_mat dagger_of_transpose_is_cnj transpose_of_jozsa_transform) + next + assume a2: "(i\j \ \(i=j+1 \ odd i) \ \ (i=j-1 \ even i \ j\1))" + then have f0:"(i\j \ \(j=i+1 \ odd j) \ \ (j=i-1 \ even j \ i\1))" + by (metis le_imp_diff_is_add diff_add_inverse even_plus_one_iff le_add1) + then have "U\<^sub>f $$ (j,i) = 0" and "cnj 0 = 0" + using jozsa_transform_coeff_is_zero a0 a1 a2 by auto + then have "U\<^sub>f\<^sup>\ $$ (i,j) = 0" + using a0 a1 dagger_def by simp + then show "U\<^sub>f\<^sup>\ $$ (i, j) = U\<^sub>f $$ (i, j)" + using a0 a1 a2 jozsa_transform_coeff_is_zero by auto + qed +qed + +lemma (in jozsa) jozsa_transform_is_unitary_index_even: + fixes i j:: nat + assumes "i < dim_row U\<^sub>f" and "j < dim_col U\<^sub>f" and "even i" + shows "(U\<^sub>f * U\<^sub>f) $$ (i,j) = 1\<^sub>m (dim_col U\<^sub>f) $$ (i,j)" +proof- + have "(U\<^sub>f * U\<^sub>f) $$ (i,j) = (\k \ {i,i+1}. U\<^sub>f $$ (i,k) * U\<^sub>f $$ (k,j)) " + using U\<^sub>f_mult_without_empty_summands_even[of i j U\<^sub>f ] assms by simp + moreover have "U\<^sub>f $$ (i,i) * U\<^sub>f $$ (i,j) = (1-f(i div 2)) * U\<^sub>f $$ (i,j)" + using assms(1,3) by simp + moreover have f0: "U\<^sub>f $$ (i,i+1) * U\<^sub>f $$ (i+1,j) = f(i div 2) * U\<^sub>f $$ (i+1,j)" + by (metis One_nat_def Suc_leI add.right_neutral add_Suc_right assms(1) assms(3) diff_add_inverse2 +even_add even_mult_iff jozsa_transform_coeff(3) jozsa_transform_dim le_add2 le_eq_less_or_eq odd_one +one_add_one power.simps(2)) + ultimately have f1: "(U\<^sub>f * U\<^sub>f) $$ (i,j) = (1-f(i div 2)) * U\<^sub>f $$ (i,j) + f(i div 2) * U\<^sub>f $$ (i+1,j)" by auto + thus ?thesis + proof (induct rule: disj_four_cases) + show "j=i \ (j=i+1 \ odd j) \ (j=i-1 \ even j \ i\1) \ (j\i \ \(j=i+1 \ odd j) \ \ (j=i-1 \ even j \ i\1))" + by linarith + next + assume a0:"j=i" + then have "U\<^sub>f $$ (i,j) = (1-f(i div 2))" + using assms(1,2) a0 by simp + moreover have "U\<^sub>f $$ (i+1,j) = f(i div 2)" + using assms(1,3) a0 by auto + ultimately have "(U\<^sub>f * U\<^sub>f) $$ (i,j) = (1-f(i div 2)) * (1-f(i div 2)) + f(i div 2) * f(i div 2)" + using f1 by simp + moreover have "(1-f(i div 2)) * (1-f(i div 2)) + f(i div 2) * f(i div 2) = 1" + using f_values assms(1) + by (metis (no_types, lifting) Nat.minus_nat.diff_0 diff_add_0 diff_add_inverse jozsa_transform_dim(1) + less_power_add_imp_div_less mem_Collect_eq mult_eq_if one_power2 power2_eq_square power_one_right) + ultimately show "(U\<^sub>f * U\<^sub>f) $$ (i,j) = 1\<^sub>m (dim_col U\<^sub>f) $$ (i,j)" by(metis assms(2) a0 index_one_mat(1) of_nat_1) + next + assume a0: "(j=i+1 \ odd j)" + then have "U\<^sub>f $$ (i,j) = f(i div 2)" + using assms(1,2) a0 by simp + moreover have "U\<^sub>f $$ (i+1,j) = (1-f(i div 2))" + using assms(2,3) a0 by simp + ultimately have "(U\<^sub>f * U\<^sub>f) $$ (i,j) = (1-f(i div 2)) * f(i div 2) + f(i div 2) * (1-f(i div 2))" + using f0 f1 assms by simp + then show "(U\<^sub>f * U\<^sub>f) $$ (i,j) = 1\<^sub>m (dim_col U\<^sub>f) $$ (i,j)" + using assms(1,2) a0 by auto + next + assume "(j=i-1 \ even j \ i\1)" + then show "(U\<^sub>f * U\<^sub>f) $$ (i,j) = 1\<^sub>m (dim_col U\<^sub>f) $$ (i,j)" + using assms(3) dvd_diffD1 odd_one by blast + next + assume a0:"(j\i \ \(j=i+1 \ odd j) \ \ (j=i-1 \ even j \ i\1))" + then have "U\<^sub>f $$ (i,j) = 0" + using assms(1,2) by(metis index_transpose_mat(1) jozsa_transform_coeff_is_zero jozsa_transform_dim transpose_of_jozsa_transform) + moreover have "U\<^sub>f $$ (i+1,j) = 0" + using assms a0 by auto + ultimately have "(U\<^sub>f * U\<^sub>f) $$ (i,j) = (1-f(i div 2)) * 0 + f(i div 2) * 0" + by (simp add: f1) + then show "(U\<^sub>f * U\<^sub>f) $$ (i,j) = 1\<^sub>m (dim_col U\<^sub>f) $$ (i,j)" + using a0 assms(1,2) by(metis add.left_neutral index_one_mat(1) jozsa_transform_dim mult_0_right of_nat_0) + qed +qed + +lemma (in jozsa) jozsa_transform_is_unitary_index_odd: + fixes i j:: nat + assumes "i < dim_row U\<^sub>f" and "j < dim_col U\<^sub>f" and "odd i" + shows "(U\<^sub>f * U\<^sub>f) $$ (i,j) = 1\<^sub>m (dim_col U\<^sub>f) $$ (i,j)" +proof- + have f0: "i \ 1" + using linorder_not_less assms(3) by auto + have "(U\<^sub>f * U\<^sub>f) $$ (i,j) = (\k \ {i-1,i}. U\<^sub>f $$ (i,k) * U\<^sub>f $$ (k,j)) " + using U\<^sub>f_mult_without_empty_summands_odd[of i j U\<^sub>f ] assms by simp + moreover have "(\k \ {i-1,i}. U\<^sub>f $$ (i,k) * U\<^sub>f $$ (k,j)) + = U\<^sub>f $$ (i,i-1) * U\<^sub>f $$ (i-1,j) + U\<^sub>f $$ (i,i) * U\<^sub>f $$ (i,j)" + using f0 by simp + moreover have "U\<^sub>f $$ (i,i) * U\<^sub>f $$ (i,j) = (1-f(i div 2)) * U\<^sub>f $$ (i,j)" + using assms(1,2) by simp + moreover have f1: "U\<^sub>f $$ (i,i-1) * U\<^sub>f $$ (i-1,j) = f(i div 2) * U\<^sub>f $$ (i-1,j)" + using assms(1) assms(3) by simp + ultimately have f2: "(U\<^sub>f * U\<^sub>f) $$ (i,j) = f(i div 2) * U\<^sub>f $$ (i-1,j) + (1-f(i div 2)) * U\<^sub>f $$ (i,j)" by simp + then show "?thesis" + proof (induct rule: disj_four_cases) + show "j=i \ (j=i+1 \ odd j) \ (j=i-1 \ even j \ i\1) \ (j\i \ \(j=i+1 \ odd j) \ \ (j=i-1 \ even j \ i\1))" + by linarith + next + assume a0:"j=i" + then have "U\<^sub>f $$ (i,j) = (1-f(i div 2))" + using assms(1,2) by simp + moreover have "U\<^sub>f $$ (i-1,j) = f(i div 2)" + using a0 assms + by (metis index_transpose_mat(1) jozsa_transform_coeff(2) less_imp_diff_less odd_two_times_div_two_nat + odd_two_times_div_two_succ transpose_of_jozsa_transform) + ultimately have "(U\<^sub>f * U\<^sub>f) $$ (i,j) = f(i div 2) * f(i div 2) + (1-f(i div 2)) * (1-f(i div 2))" + using f2 by simp + moreover have "f(i div 2) * f(i div 2) + (1-f(i div 2)) * (1-f(i div 2)) = 1" + using f_values assms(1) + by (metis (no_types, lifting) Nat.minus_nat.diff_0 diff_add_0 diff_add_inverse jozsa_transform_dim(1) + less_power_add_imp_div_less mem_Collect_eq mult_eq_if one_power2 power2_eq_square power_one_right) + ultimately show "(U\<^sub>f * U\<^sub>f) $$ (i,j) = 1\<^sub>m (dim_col U\<^sub>f) $$ (i,j)" by(metis assms(2) a0 index_one_mat(1) of_nat_1) + next + assume a0:"(j=i+1 \ odd j)" + then show "(U\<^sub>f * U\<^sub>f) $$ (i,j) = 1\<^sub>m (dim_col U\<^sub>f) $$ (i,j)" + using assms(3) dvd_diffD1 odd_one even_plus_one_iff by blast + next + assume a0:"(j=i-1 \ even j \ i\1)" + then have "(U\<^sub>f * U\<^sub>f) $$ (i,j) = f(i div 2) * (1-f(i div 2)) + (1-f(i div 2)) * f(i div 2)" + using f0 f1 f2 assms + by (metis jozsa_transform_coeff(1) Groups.ab_semigroup_mult_class.mult.commute even_succ_div_two f2 + jozsa_transform_dim odd_two_times_div_two_nat odd_two_times_div_two_succ of_nat_add of_nat_mult) + then show "(U\<^sub>f * U\<^sub>f) $$ (i,j) = 1\<^sub>m (dim_col U\<^sub>f) $$ (i,j)" + using assms(1) a0 by auto + next + assume a0:"j\i \ \(j=i+1 \ odd j) \ \ (j=i-1 \ even j \ i\1)" + then have "U\<^sub>f $$ (i,j) = 0" + by (metis assms(1,2) index_transpose_mat(1) jozsa_transform_coeff_is_zero jozsa_transform_dim transpose_of_jozsa_transform) + moreover have "U\<^sub>f $$ (i-1,j) = 0" + using assms a0 f0 + by auto (smt One_nat_def Suc_n_not_le_n add_diff_inverse_nat assms(1) assms(2) diff_Suc_less even_add +jozsa_transform_coeff_is_zero jozsa_axioms less_imp_le less_le_trans less_one odd_one) + ultimately have "(U\<^sub>f * U\<^sub>f) $$ (i,j) = (1-f(i div 2)) * 0 + f(i div 2) * 0" + using f2 by simp + then show "(U\<^sub>f * U\<^sub>f) $$ (i,j) = 1\<^sub>m (dim_col U\<^sub>f) $$ (i,j)" + using a0 assms by (metis add.left_neutral index_one_mat(1) jozsa_transform_dim mult_0_right of_nat_0) + qed +qed + +lemma (in jozsa) jozsa_transform_is_gate: + shows "gate (n+1) U\<^sub>f" +proof + show "dim_row U\<^sub>f = 2^(n+1)" by simp +next + show "square_mat U\<^sub>f" by simp +next + show "unitary U\<^sub>f" + proof- + have "U\<^sub>f * U\<^sub>f = 1\<^sub>m (dim_col U\<^sub>f)" + proof + show "dim_row (U\<^sub>f * U\<^sub>f) = dim_row (1\<^sub>m (dim_col U\<^sub>f))" by simp + show "dim_col (U\<^sub>f * U\<^sub>f) = dim_col (1\<^sub>m (dim_col U\<^sub>f))" by simp + fix i j:: nat + assume "i < dim_row (1\<^sub>m (dim_col U\<^sub>f))" and "j < dim_col (1\<^sub>m (dim_col U\<^sub>f))" + then have "i < dim_row U\<^sub>f" and "j < dim_col U\<^sub>f" by auto + then show "(U\<^sub>f * U\<^sub>f) $$ (i,j) = 1\<^sub>m (dim_col U\<^sub>f) $$ (i,j)" + using jozsa_transform_is_unitary_index_odd jozsa_transform_is_unitary_index_even by blast + qed + thus ?thesis by (simp add: adjoint_of_jozsa_transform unitary_def) + qed +qed + +text \N-fold application of the tensor product\ + +fun iter_tensor:: "complex Matrix.mat \ nat \ complex Matrix.mat" ("_ \\<^bsup>_\<^esup>" 75) where + "A \\<^bsup>(Suc 0)\<^esup> = A" +| "A \\<^bsup>(Suc k)\<^esup> = A \ (A \\<^bsup>k\<^esup>)" + +lemma one_tensor_is_id [simp]: + fixes A + shows "A \\<^bsup>1\<^esup> = A" + using one_mat_def by simp + +lemma iter_tensor_suc: + fixes n + assumes "n \ 1" + shows " A \\<^bsup>(Suc n)\<^esup> = A \ (A \\<^bsup>n\<^esup>)" + using assms by (metis Deutsch_Jozsa.iter_tensor.simps(2) One_nat_def Suc_le_D) + +lemma dim_row_of_iter_tensor [simp]: + fixes A n + assumes "n \ 1" + shows "dim_row(A \\<^bsup>n\<^esup>) = (dim_row A)^n" + using assms +proof (rule nat_induct_at_least) + show "dim_row (A \\<^bsup>1\<^esup>) = (dim_row A)^1" + using one_tensor_is_id by simp + fix n:: nat + assume "n \ 1" and "dim_row (A \\<^bsup>n\<^esup>) = (dim_row A)^n" + then show "dim_row (A \\<^bsup>Suc n\<^esup>) = (dim_row A)^Suc n" + using iter_tensor_suc assms dim_row_tensor_mat by simp +qed + +lemma dim_col_of_iter_tensor [simp]: + fixes A n + assumes "n \ 1" + shows "dim_col(A \\<^bsup>n\<^esup>) = (dim_col A)^n" + using assms +proof (rule nat_induct_at_least) + show "dim_col (A \\<^bsup>1\<^esup>) = (dim_col A)^1" + using one_tensor_is_id by simp + fix n:: nat + assume "n \ 1" and "dim_col (A \\<^bsup>n\<^esup>) = (dim_col A)^n" + then show "dim_col (A \\<^bsup>Suc n\<^esup>) = (dim_col A)^Suc n" + using iter_tensor_suc assms dim_col_tensor_mat by simp +qed + +lemma iter_tensor_values: + fixes A n i j + assumes "n \ 1" and "i < dim_row (A \ (A \\<^bsup>n\<^esup>))" and "j < dim_col (A \ (A \\<^bsup>n\<^esup>))" + shows "(A \\<^bsup>(Suc n)\<^esup>) $$ (i,j) = (A \ (A \\<^bsup>n\<^esup>)) $$ (i,j)" + using assms by (metis One_nat_def le_0_eq not0_implies_Suc iter_tensor.simps(2)) + +lemma iter_tensor_mult_distr: + assumes "n \ 1" and "dim_col A = dim_row B" and "dim_col A > 0" and "dim_col B > 0" + shows "(A \\<^bsup>(Suc n)\<^esup>) * (B \\<^bsup>(Suc n)\<^esup>) = (A * B) \ ((A \\<^bsup>n\<^esup>) * (B \\<^bsup>n\<^esup>))" +proof- + have "(A \\<^bsup>(Suc n)\<^esup>) * (B \\<^bsup>(Suc n)\<^esup>) = (A \ (A \\<^bsup>n\<^esup>)) * (B \ (B \\<^bsup>n\<^esup>))" + using Suc_le_D assms(1) by fastforce + then show "?thesis" + using mult_distr_tensor[of "A" "B" "(iter_tensor A n)" "(iter_tensor B n)"] assms by simp +qed + +lemma index_tensor_mat_with_vec2_row_cond: + fixes A B:: "complex Matrix.mat" and i:: "nat" + assumes "i < 2 * (dim_row B)" and "i \ dim_row B" and "dim_col B > 0" +and "dim_row A = 2" and "dim_col A = 1" + shows "(A \ B) $$ (i,0) = (A $$ (1,0)) * (B $$ (i-dim_row B,0))" +proof- + have "(A \ B) $$ (i,0) = A $$ (i div (dim_row B),0) * B $$ (i mod (dim_row B),0)" + using assms index_tensor_mat[of A "dim_row A" "dim_col A" B "dim_row B" "dim_col B" i 0] by simp + moreover have "i div (dim_row B) = 1" + using assms(1,2,4) by simp + then have "i mod (dim_row B) = i - (dim_row B)" + by (simp add: modulo_nat_def) + ultimately show "(A \ B) $$ (i,0) = (A $$ (1,0)) * (B $$ (i-dim_row B,0))" + by (simp add: \i div dim_row B = 1\) +qed + +lemma iter_tensor_of_gate_is_gate: + fixes A:: "complex Matrix.mat" and n m:: "nat" + assumes "gate m A" and "n \ 1" + shows "gate (m*n) (A \\<^bsup>n\<^esup>)" + using assms(2) +proof(rule nat_induct_at_least) + show "gate (m * 1) (A \\<^bsup>1\<^esup>)" using assms(1) by simp + fix n:: nat + assume "n \ 1" and IH:"gate (m * n) (A \\<^bsup>n\<^esup>)" + then have "A \\<^bsup>(Suc n)\<^esup> = A \ (A \\<^bsup>n\<^esup>)" + by (simp add: iter_tensor_suc) + moreover have "gate (m*n + m) (A \\<^bsup>(Suc n)\<^esup>)" + using tensor_gate assms(1) by (simp add: IH add.commute calculation(1)) + then show "gate (m*(Suc n)) (A \\<^bsup>(Suc n)\<^esup>)" + by (simp add: add.commute) +qed + +lemma iter_tensor_of_state_is_state: + fixes A:: "complex Matrix.mat" and n m:: "nat" + assumes "state m A" and "n\1" + shows "state (m*n) (A \\<^bsup>n\<^esup>)" + using assms(2) +proof(rule nat_induct_at_least) + show "state (m * 1) (A \\<^bsup>1\<^esup>)" + using one_tensor_is_id assms(1) by simp + fix n:: nat + assume "n \ 1" and IH:"state (m * n) (A \\<^bsup>n\<^esup>)" + then have "A \\<^bsup>(Suc n)\<^esup> = A \ (A \\<^bsup>n\<^esup>)" + by (simp add: iter_tensor_suc) + moreover have "state (m*n + m) (A \\<^bsup>(Suc n)\<^esup>)" + using tensor_gate assms(1) by (simp add: IH add.commute calculation) + then show "state (m*(Suc n)) (A \\<^bsup>(Suc n)\<^esup>)" + by (simp add: add.commute) +qed + +text \ +We prepare n+1 qubits. The first n qubits in the state $|0\rangle$, the last one in the state +$|1\rangle$. +\ + +abbreviation \\<^sub>1\<^sub>0:: "nat \ complex Matrix.mat" where +"\\<^sub>1\<^sub>0 n \ Matrix.mat (2^n) 1 (\(i,j). 1/(sqrt 2)^n)" + +lemma \\<^sub>1\<^sub>0_values: + fixes i j n + assumes "i < dim_row (\\<^sub>1\<^sub>0 n)" and "j < dim_col (\\<^sub>1\<^sub>0 n)" + shows "(\\<^sub>1\<^sub>0 n) $$ (i,j) = 1/(sqrt 2)^n" + using assms case_prod_conv by simp + +text \$H^{\otimes n}$ is applied to $|0\rangle^{\otimes n}$.\ + +lemma H_on_ket_zero: + shows "(H * |zero\) = \\<^sub>1\<^sub>0 1" +proof + fix i j:: nat + assume "i < dim_row (\\<^sub>1\<^sub>0 1)" and "j < dim_col (\\<^sub>1\<^sub>0 1)" + then have f1: "i \ {0,1} \ j = 0" by (simp add: less_2_cases) + then show "(H * |zero\) $$ (i,j) = (\\<^sub>1\<^sub>0 1) $$ (i,j)" + by (auto simp add: times_mat_def scalar_prod_def H_def ket_vec_def) +next + show "dim_row (H * |zero\) = dim_row (\\<^sub>1\<^sub>0 1)" by (simp add: H_def) + show "dim_col (H * |zero\) = dim_col (\\<^sub>1\<^sub>0 1)" using H_def + by (simp add: ket_vec_def) +qed + +lemma \\<^sub>1\<^sub>0_tensor: + assumes "n \ 1" + shows "(\\<^sub>1\<^sub>0 1) \ (\\<^sub>1\<^sub>0 n) = (\\<^sub>1\<^sub>0 (Suc n))" +proof + have "dim_row (\\<^sub>1\<^sub>0 1) * dim_row (\\<^sub>1\<^sub>0 n) = 2^(Suc n)" by simp + then show "dim_row ((\\<^sub>1\<^sub>0 1) \ (\\<^sub>1\<^sub>0 n)) = dim_row (\\<^sub>1\<^sub>0 (Suc n))" by simp + have "dim_col (\\<^sub>1\<^sub>0 1) * dim_col (\\<^sub>1\<^sub>0 n) = 1" by simp + then show "dim_col ((\\<^sub>1\<^sub>0 1) \ (\\<^sub>1\<^sub>0 n)) = dim_col (\\<^sub>1\<^sub>0 (Suc n))" by simp +next + fix i j:: nat + assume a0: "i < dim_row (\\<^sub>1\<^sub>0 (Suc n))" and a1: "j < dim_col (\\<^sub>1\<^sub>0 (Suc n))" + then have f0: "j = 0" and f1: "i < 2^(Suc n)" by auto + then have f2:"(\\<^sub>1\<^sub>0 (Suc n)) $$ (i,j) = 1/(sqrt 2)^(Suc n)" + using \\<^sub>1\<^sub>0_values[of "i" "(Suc n)" "j"] a0 a1 by simp + show "((\\<^sub>1\<^sub>0 1) \ (\\<^sub>1\<^sub>0 n)) $$ (i,j) = (\\<^sub>1\<^sub>0 (Suc n)) $$ (i,j)" + proof (rule disjE) (*case distinction*) + show "i < dim_row (\\<^sub>1\<^sub>0 n) \ i \ dim_row (\\<^sub>1\<^sub>0 n)" by linarith + next (* case i < dim_row (\\<^sub>1\<^sub>0 n) *) + assume a2: "i < dim_row (\\<^sub>1\<^sub>0 n)" + then have "((\\<^sub>1\<^sub>0 1) \ (\\<^sub>1\<^sub>0 n)) $$ (i,j) = (\\<^sub>1\<^sub>0 1) $$ (0,0) * (\\<^sub>1\<^sub>0 n) $$ (i,0)" + using index_tensor_mat f0 assms by simp + also have "... = 1/sqrt(2) * 1/(sqrt(2)^n)" + using \\<^sub>1\<^sub>0_values a2 assms by simp + finally show "((\\<^sub>1\<^sub>0 1) \ (\\<^sub>1\<^sub>0 n)) $$ (i,j) = (\\<^sub>1\<^sub>0 (Suc n)) $$ (i,j)" + using f2 divide_divide_eq_left power_Suc by simp + next (* case i \ dim_row (\\<^sub>1\<^sub>0 n) *) + assume "i \ dim_row (\\<^sub>1\<^sub>0 n)" + then have "((\\<^sub>1\<^sub>0 1) \ (\\<^sub>1\<^sub>0 n)) $$ (i,0) = ((\\<^sub>1\<^sub>0 1) $$ (1, 0)) * ((\\<^sub>1\<^sub>0 n) $$ ( i -dim_row (\\<^sub>1\<^sub>0 n),0))" + using index_tensor_mat_with_vec2_row_cond[of i "(\\<^sub>1\<^sub>0 1)" "(\\<^sub>1\<^sub>0 n)" ] a0 a1 f0 + by (metis dim_col_mat(1) dim_row_mat(1) index_tensor_mat_with_vec2_row_cond power_Suc power_one_right) + then have "((\\<^sub>1\<^sub>0 1) \ (\\<^sub>1\<^sub>0 n)) $$ (i,0) = 1/sqrt(2) * 1/(sqrt 2)^n" + using \\<^sub>1\<^sub>0_values[of "i -dim_row (\\<^sub>1\<^sub>0 n)" "n" "j"] a0 a1 by simp + then show "((\\<^sub>1\<^sub>0 1) \ (\\<^sub>1\<^sub>0 n)) $$ (i,j) = (\\<^sub>1\<^sub>0 (Suc n)) $$ (i,j)" + using f0 f1 divide_divide_eq_left power_Suc by simp + qed +qed + +lemma \\<^sub>1\<^sub>0_tensor_is_state: + assumes "n \ 1" + shows "state n ( |zero\ \\<^bsup>n\<^esup>)" + using iter_tensor_of_state_is_state ket_zero_is_state assms by fastforce + +lemma iter_tensor_of_H_is_gate: + assumes "n \ 1" + shows "gate n (H \\<^bsup>n\<^esup>)" + using iter_tensor_of_gate_is_gate H_is_gate assms by fastforce + +lemma iter_tensor_of_H_on_zero_tensor: + assumes "n \ 1" + shows "(H \\<^bsup>n\<^esup>) * ( |zero\ \\<^bsup>n\<^esup>) = \\<^sub>1\<^sub>0 n" + using assms +proof(rule nat_induct_at_least) + show "(H \\<^bsup>1\<^esup>) * ( |zero\ \\<^bsup>1\<^esup>) = \\<^sub>1\<^sub>0 1" + using H_on_ket_zero by simp +next + fix n:: nat + assume a0: "n \ 1" and IH: "(H \\<^bsup>n\<^esup>) * ( |zero\ \\<^bsup>n\<^esup>) = \\<^sub>1\<^sub>0 n" + then have "(H \\<^bsup>(Suc n)\<^esup>) * ( |zero\ \\<^bsup>(Suc n)\<^esup>) = (H * |zero\) \ ((H \\<^bsup>n\<^esup>) * ( |zero\ \\<^bsup>n\<^esup>))" + using iter_tensor_mult_distr[of "n" "H" "|zero\"] a0 ket_vec_def H_def by(simp add: H_def) + also have "... = (H * |zero\) \ (\\<^sub>1\<^sub>0 n)" using IH by simp + also have "... = (\\<^sub>1\<^sub>0 1) \ (\\<^sub>1\<^sub>0 n)" using H_on_ket_zero by simp + also have "... = (\\<^sub>1\<^sub>0 (Suc n))" using \\<^sub>1\<^sub>0_tensor a0 by simp + finally show "(H \\<^bsup>(Suc n)\<^esup>) * ( |zero\ \\<^bsup>(Suc n)\<^esup>) = (\\<^sub>1\<^sub>0 (Suc n))" by simp +qed + +lemma \\<^sub>1\<^sub>0_is_state: + assumes "n \ 1" + shows "state n (\\<^sub>1\<^sub>0 n)" + using iter_tensor_of_H_is_gate \\<^sub>1\<^sub>0_tensor_is_state assms gate_on_state_is_state iter_tensor_of_H_on_zero_tensor assms by metis + +abbreviation \\<^sub>1\<^sub>1:: "complex Matrix.mat" where +"\\<^sub>1\<^sub>1 \ Matrix.mat 2 1 (\(i,j). if i=0 then 1/sqrt(2) else -1/sqrt(2))" + +lemma H_on_ket_one_is_\\<^sub>1\<^sub>1: + shows "(H * |one\) = \\<^sub>1\<^sub>1" +proof + fix i j:: nat + assume "i < dim_row \\<^sub>1\<^sub>1" and "j < dim_col \\<^sub>1\<^sub>1" + then have "i \ {0,1} \ j = 0" by (simp add: less_2_cases) + then show "(H * |one\) $$ (i,j) = \\<^sub>1\<^sub>1 $$ (i,j)" + by (auto simp add: times_mat_def scalar_prod_def H_def ket_vec_def) +next + show "dim_row (H * |one\) = dim_row \\<^sub>1\<^sub>1" by (simp add: H_def) +next + show "dim_col (H * |one\) = dim_col \\<^sub>1\<^sub>1" by (simp add: H_def ket_vec_def) +qed + +abbreviation \\<^sub>1:: "nat \ complex Matrix.mat" where +"\\<^sub>1 n \ Matrix.mat (2^(n+1)) 1 (\(i,j). if even i then 1/(sqrt 2)^(n+1) else -1/(sqrt 2)^(n+1))" + +lemma \\<^sub>1_values_even[simp]: + fixes i j n + assumes "i < dim_row (\\<^sub>1 n)" and "j < dim_col (\\<^sub>1 n)" and "even i" + shows "(\\<^sub>1 n) $$ (i,j) = 1/(sqrt 2)^(n+1)" + using assms case_prod_conv by simp + +lemma \\<^sub>1_values_odd [simp]: + fixes i j n + assumes "i < dim_row (\\<^sub>1 n)" and "j < dim_col (\\<^sub>1 n)" and "odd i" + shows "(\\<^sub>1 n) $$ (i,j) = -1/(sqrt 2)^(n+1)" + using assms case_prod_conv by simp + +lemma "\\<^sub>1\<^sub>0_tensor_\\<^sub>1\<^sub>1_is_\\<^sub>1": + assumes "n \ 1" + shows "(\\<^sub>1\<^sub>0 n) \ \\<^sub>1\<^sub>1 = \\<^sub>1 n" +proof + show "dim_col ((\\<^sub>1\<^sub>0 n) \ \\<^sub>1\<^sub>1) = dim_col (\\<^sub>1 n)" by simp +next + show "dim_row ((\\<^sub>1\<^sub>0 n) \ \\<^sub>1\<^sub>1) = dim_row (\\<^sub>1 n)" by simp +next + fix i j:: nat + assume a0: "i < dim_row (\\<^sub>1 n)" and a1: "j < dim_col (\\<^sub>1 n)" + then have "i < 2^(n+1)" and "j = 0" by auto + then have f0: "((\\<^sub>1\<^sub>0 n) \ \\<^sub>1\<^sub>1) $$ (i,j) = 1/(sqrt 2)^n * \\<^sub>1\<^sub>1 $$ (i mod 2, j)" + using \\<^sub>1\<^sub>0_values[of "i div 2" n "j div 1"] a0 a1 by simp + show "((\\<^sub>1\<^sub>0 n) \ \\<^sub>1\<^sub>1) $$ (i,j) = (\\<^sub>1 n) $$ (i,j)" + using f0 \\<^sub>1_values_even \\<^sub>1_values_odd a0 a1 by auto +qed + +lemma \\<^sub>1_is_state: + assumes "n \ 1" + shows "state (n+1) (\\<^sub>1 n)" + using assms \\<^sub>1\<^sub>0_tensor_\\<^sub>1\<^sub>1_is_\\<^sub>1 \\<^sub>1\<^sub>0_is_state H_on_ket_one_is_state H_on_ket_one_is_\\<^sub>1\<^sub>1 tensor_state by metis + +abbreviation (in jozsa) \\<^sub>2:: "complex Matrix.mat" where +"\\<^sub>2 \ Matrix.mat (2^(n+1)) 1 (\(i,j). if even i then (-1)^f(i div 2)/(sqrt 2)^(n+1) + else (-1)^(f(i div 2)+1)/(sqrt 2)^(n+1))" + +lemma (in jozsa) \\<^sub>2_values_even [simp]: + fixes i j + assumes "i < dim_row \\<^sub>2 " and "j < dim_col \\<^sub>2" and "even i" + shows "\\<^sub>2 $$ (i,j) = (-1)^f(i div 2)/(sqrt 2)^(n+1)" + using assms case_prod_conv by simp + +lemma (in jozsa) \\<^sub>2_values_odd [simp]: + fixes i j + assumes "i < dim_row \\<^sub>2" and "j < dim_col \\<^sub>2" and "odd i" + shows "\\<^sub>2 $$ (i,j) = (-1)^(f(i div 2)+1)/(sqrt 2)^(n+1)" + using assms case_prod_conv by simp + +lemma (in jozsa) \\<^sub>2_values_odd_hidden [simp]: + assumes "2*k+1 < dim_row \\<^sub>2" and "j < dim_col \\<^sub>2" + shows "\\<^sub>2 $$ (2*k+1,j) = ((-1)^(f((2*k+1) div 2)+1))/(sqrt 2)^(n+1)" + using assms by simp + +lemma (in jozsa) snd_rep_of_\\<^sub>2: + assumes "i < dim_row \\<^sub>2" + shows "((1-f(i div 2)) + -f(i div 2)) * 1/(sqrt 2)^(n+1) = (-1)^f(i div 2)/(sqrt 2)^(n+1)" + and "(-(1-f(i div 2))+(f(i div 2)))* 1/(sqrt 2)^(n+1) = (-1)^(f(i div 2)+1)/(sqrt 2)^(n+1)" +proof- + have "i div 2 \ {i. i < 2 ^ n}" + using assms by auto + then have "real (Suc 0 - f (i div 2)) - real (f (i div 2)) = (- 1) ^ f (i div 2)" + using assms f_values by auto + thus "((1-f(i div 2)) + -f(i div 2)) * 1/(sqrt 2)^(n+1) = (-1)^f(i div 2)/(sqrt 2)^(n+1)" by auto +next + have "i div 2 \ {i. i < 2^n}" + using assms by simp + then have "(real (f (i div 2)) - real (Suc 0 - f (i div 2))) / (sqrt 2 ^ (n+1)) = + - ((- 1) ^ f (i div 2) / (sqrt 2 ^ (n+1)))" + using assms f_values by fastforce + then show "(-(1-f(i div 2))+(f(i div 2)))* 1/(sqrt 2)^(n+1) = (-1)^(f(i div 2)+1)/(sqrt 2)^(n+1)" by simp +qed + +lemma (in jozsa) jozsa_transform_times_\\<^sub>1_is_\\<^sub>2: + shows "U\<^sub>f * (\\<^sub>1 n) = \\<^sub>2" +proof + show "dim_row (U\<^sub>f * (\\<^sub>1 n)) = dim_row \\<^sub>2" by simp +next + show "dim_col (U\<^sub>f * (\\<^sub>1 n)) = dim_col \\<^sub>2" by simp +next + fix i j ::nat + assume a0: "i < dim_row \\<^sub>2" and a1: "j < dim_col \\<^sub>2" + then have f0:"i \ {0..2^(n+1)} \ j=0" by simp + then have f1: "i < dim_row U\<^sub>f \ j < dim_col U\<^sub>f " using a0 by simp + have f2: "i < dim_row (\\<^sub>1 n) \ j < dim_col (\\<^sub>1 n)" using a0 a1 by simp + show "(U\<^sub>f * (\\<^sub>1 n)) $$ (i,j) = \\<^sub>2 $$ (i,j)" + proof (rule disjE) + show "even i \ odd i" by auto + next + assume a2: "even i" + then have "(U\<^sub>f * (\\<^sub>1 n)) $$ (i,j) = (\k \ {i,i+1}. U\<^sub>f $$ (i,k) * (\\<^sub>1 n) $$ (k,j))" + using f1 f2 U\<^sub>f_mult_without_empty_summands_even[of i j "(\\<^sub>1 n)"] by simp + moreover have "U\<^sub>f $$ (i,i) * (\\<^sub>1 n) $$ (i,j) = (1-f(i div 2))* 1/(sqrt 2)^(n+1)" + using f0 f1 a2 by simp + moreover have "U\<^sub>f $$ (i,i+1) * (\\<^sub>1 n) $$ (i+1,j) = (-f(i div 2))* 1/(sqrt 2)^(n+1)" + using f0 f1 a2 by auto + ultimately have "(U\<^sub>f * (\\<^sub>1 n)) $$ (i,j) = (1-f(i div 2))* 1/(sqrt 2)^(n+1) + (-f(i div 2))* 1/(sqrt 2)^(n+1)" by simp + also have "... = ((1-f(i div 2))+-f(i div 2)) * 1/(sqrt 2)^(n+1)" + using add_divide_distrib + by (metis (no_types, hide_lams) mult.right_neutral of_int_add of_int_of_nat_eq) + also have "... = \\<^sub>2 $$ (i,j)" + using a0 a1 a2 snd_rep_of_\\<^sub>2 by simp + finally show "(U\<^sub>f * (\\<^sub>1 n)) $$ (i,j) = \\<^sub>2 $$ (i,j)" by simp + next + assume a2: "odd i" + then have f6: "i\1" + using linorder_not_less by auto + have "(U\<^sub>f * (\\<^sub>1 n)) $$ (i,j) = (\k \ {i-1,i}. U\<^sub>f $$ (i,k) * (\\<^sub>1 n) $$ (k,j))" + using f1 f2 a2 U\<^sub>f_mult_without_empty_summands_odd[of i j "(\\<^sub>1 n)"] + by (metis dim_row_mat(1) jozsa_transform_dim(2)) + moreover have "(\k \ {i-1,i}. U\<^sub>f $$ (i,k) * (\\<^sub>1 n) $$ (k,j)) + = U\<^sub>f $$ (i,i-1) * (\\<^sub>1 n) $$ (i-1,j) + U\<^sub>f $$ (i,i) * (\\<^sub>1 n) $$ (i,j)" + using a2 f6 by simp + moreover have "U\<^sub>f $$ (i,i) * (\\<^sub>1 n) $$ (i,j) = (1-f(i div 2))* -1/(sqrt 2)^(n+1)" + using f1 f2 a2 by simp + moreover have "U\<^sub>f $$ (i,i-1) * (\\<^sub>1 n) $$ (i-1,j) = f(i div 2)* 1/(sqrt 2)^(n+1)" + using a0 a1 a2 by simp + ultimately have "(U\<^sub>f * (\\<^sub>1 n)) $$ (i,j) = (1-f(i div 2))* -1/(sqrt 2)^(n+1) +(f(i div 2))* 1/(sqrt 2)^(n+1)" + using of_real_add by simp + also have "... = (-(1-f(i div 2)) + (f(i div 2))) * 1/(sqrt 2)^(n+1)" + by (metis (no_types, hide_lams) mult.right_neutral add_divide_distrib mult_minus1_right + of_int_add of_int_of_nat_eq) + also have "... = (-1)^(f(i div 2)+1)/(sqrt 2)^(n+1)" + using a0 a1 a2 snd_rep_of_\\<^sub>2 by simp + finally show "(U\<^sub>f * (\\<^sub>1 n)) $$ (i,j) = \\<^sub>2 $$ (i,j)" + using a0 a1 a2 by simp + qed +qed + +lemma (in jozsa) \\<^sub>2_is_state: + shows "state (n+1) \\<^sub>2" + using jozsa_transform_times_\\<^sub>1_is_\\<^sub>2 jozsa_transform_is_gate \\<^sub>1_is_state dim gate_on_state_is_state by fastforce + +text \@{text "H^\<^sub>\ n"} is the result of taking the nth tensor product of H\ + +abbreviation iter_tensor_of_H_rep:: "nat \ complex Matrix.mat" ("H^\<^sub>\ _") where +"iter_tensor_of_H_rep n \ Matrix.mat (2^n) (2^n) (\(i,j).(-1)^(i \\<^bsub>n\<^esub> j)/(sqrt 2)^n)" + +lemma tensor_of_H_values [simp]: + fixes n i j:: nat + assumes "i < dim_row (H^\<^sub>\ n)" and "j < dim_col (H^\<^sub>\ n)" + shows "(H^\<^sub>\ n) $$ (i,j) = (-1)^(i \\<^bsub>n\<^esub> j)/(sqrt 2)^n" + using assms by simp + +lemma dim_row_of_iter_tensor_of_H [simp]: + assumes "n \ 1" + shows "1 < dim_row (H^\<^sub>\ n)" + using assms by(metis One_nat_def Suc_1 dim_row_mat(1) le_trans lessI linorder_not_less one_less_power) + +lemma iter_tensor_of_H_fst_pos: + fixes n i j:: nat + assumes "i < 2^n \ j < 2^n" and "i < 2^(n+1) \ j < 2^(n+1)" + shows "(H^\<^sub>\ (Suc n)) $$ (i,j) = 1/sqrt(2) * ((H^\<^sub>\ n) $$ (i mod 2^n, j mod 2^n))" +proof- + have "(H^\<^sub>\ (Suc n)) $$ (i,j) = (-1)^(bip i (Suc n) j)/(sqrt 2)^(Suc n)" + using assms by simp + moreover have "bip i (Suc n) j = bip (i mod 2^n) n (j mod 2^n)" + using bitwise_inner_prod_fst_el_0 assms(1) by simp + ultimately show ?thesis + using bitwise_inner_prod_def by simp +qed + +lemma iter_tensor_of_H_fst_neg: + fixes n i j:: nat + assumes "i \ 2^n \ j \ 2^n" and "i < 2^(n+1) \ j < 2^(n+1)" + shows "(H^\<^sub>\ (Suc n)) $$ (i,j) = -1/sqrt(2) * (H^\<^sub>\ n) $$ (i mod 2^n, j mod 2^n)" +proof- + have "(H^\<^sub>\ (Suc n)) $$ (i,j) = (-1)^(bip i (n+1) j)/(sqrt 2)^(n+1)" + using assms(2) by simp + moreover have "bip i (n+1) j = 1 + bip (i mod 2^n) n (j mod 2^n)" + using bitwise_inner_prod_fst_el_is_1 assms by simp + ultimately show ?thesis by simp +qed + +lemma H_tensor_iter_tensor_of_H: + fixes n:: nat + shows "(H \ H^\<^sub>\ n) = H^\<^sub>\ (Suc n)" +proof + fix i j:: nat + assume a0: "i < dim_row (H^\<^sub>\ (Suc n))" and a1: "j < dim_col (H^\<^sub>\ (Suc n))" + then have f0: "i \ {0..<2^(n+1)} \ j \ {0..<2^(n+1)}" by simp + then have f1: "(H \ H^\<^sub>\ n) $$ (i,j) = H $$ (i div (dim_row (H^\<^sub>\ n)),j div (dim_col (H^\<^sub>\ n))) + * (H^\<^sub>\ n) $$ (i mod (dim_row (H^\<^sub>\ n)),j mod (dim_col (H^\<^sub>\ n)))" + by (simp add: H_without_scalar_prod) + show "(H \ H^\<^sub>\ n) $$ (i,j) = (H^\<^sub>\ (Suc n)) $$ (i,j)" + proof (rule disjE) + show "(i < 2^n \ j < 2^n) \ \(i < 2^n \ j < 2^n)" by auto + next + assume a2: "(i < 2^n \ j < 2^n)" + then have "(H^\<^sub>\ (Suc n)) $$ (i,j) = 1/sqrt(2) * ((H^\<^sub>\ n) $$ (i mod 2^n, j mod 2^n))" + using a0 a1 f0 iter_tensor_of_H_fst_pos by (metis (mono_tags, lifting) atLeastLessThan_iff) + moreover have "H $$ (i div (dim_row (H^\<^sub>\ n)),j div (dim_col (H^\<^sub>\ n))) = 1/sqrt 2" + using a0 a1 f0 H_without_scalar_prod H_values a2 + by (metis (no_types, lifting) dim_col_mat(1) dim_row_mat(1) div_less le_eq_less_or_eq + le_numeral_extra(2) less_power_add_imp_div_less plus_1_eq_Suc power_one_right) + ultimately show "(H \ H^\<^sub>\ n) $$ (i,j) = (H^\<^sub>\ (Suc n)) $$ (i,j)" + using f1 by simp + next + assume a2: "\(i < 2^n \ j < 2^n)" + then have "i \ 2^n \ j \ 2^n" by simp + then have f2:"(H^\<^sub>\ (Suc n)) $$ (i,j) = -1/sqrt(2) * ((H^\<^sub>\ n) $$ (i mod 2^n, j mod 2^n))" + using a0 a1 f0 iter_tensor_of_H_fst_neg by simp + have "i div (dim_row (H^\<^sub>\ n)) =1" and "j div (dim_row (H^\<^sub>\ n)) = 1" + using a2 a0 a1 by auto + then have "H $$ (i div (dim_row (H^\<^sub>\ n)),j div (dim_col (H^\<^sub>\ n))) = -1/sqrt 2" + using a0 a1 f0 H_values_right_bottom[of "i div (dim_row (H^\<^sub>\ n))" "j div (dim_col (H^\<^sub>\ n))"] a2 + by fastforce + then show "(H \ H^\<^sub>\ n) $$ (i,j) = (H^\<^sub>\ (Suc n)) $$ (i,j)" + using f1 f2 by simp + qed +next + show "dim_row (H \ H^\<^sub>\ n) = dim_row (H^\<^sub>\ (Suc n))" + by (simp add: H_without_scalar_prod) +next + show "dim_col (H \ H^\<^sub>\ n) = dim_col (H^\<^sub>\ (Suc n))" + by (simp add: H_without_scalar_prod) +qed + +text \ +We prove that @{term "H^\<^sub>\ n"} is indeed the matrix representation of @{term "H \\<^bsup>n\<^esup>"}, the iterated +tensor product of the Hadamard gate H. +\ + +lemma one_tensor_of_H_is_H: + shows "(H^\<^sub>\ 1) = H" +proof(rule eq_matI) + show "dim_row (H^\<^sub>\ 1) = dim_row H" + by (simp add: H_without_scalar_prod) + show "dim_col (H^\<^sub>\ 1) = dim_col H" + by (simp add: H_without_scalar_prod) +next + fix i j:: nat + assume a0:"i < dim_row H" and a1:"j < dim_col H" + then show "(H^\<^sub>\ 1) $$ (i,j) = H $$ (i,j)" + proof- + have "(H^\<^sub>\ 1) $$ (0, 0) = 1/sqrt(2)" + using bitwise_inner_prod_def bin_rep_def by simp + moreover have "(H^\<^sub>\ 1) $$ (0,1) = 1/sqrt(2)" + using bitwise_inner_prod_def bin_rep_def by simp + moreover have "(H^\<^sub>\ 1) $$ (1,0) = 1/sqrt(2)" + using bitwise_inner_prod_def bin_rep_def by simp + moreover have "(H^\<^sub>\ 1) $$ (1,1) = -1/sqrt(2)" + using bitwise_inner_prod_def bin_rep_def by simp + ultimately show "(H^\<^sub>\ 1) $$ (i,j) = H $$ (i,j)" + using a0 a1 H_values H_values_right_bottom + by (metis (no_types, lifting) H_without_scalar_prod One_nat_def dim_col_mat(1) dim_row_mat(1) +divide_minus_left less_2_cases) + qed +qed + +lemma iter_tensor_of_H_rep_is_correct: + fixes n:: nat + assumes "n \ 1" + shows "(H \\<^bsup>n\<^esup>) = H^\<^sub>\ n" + using assms +proof(rule nat_induct_at_least) + show "(H \\<^bsup>1\<^esup>) = H^\<^sub>\ 1" + using one_tensor_is_id one_tensor_of_H_is_H by simp +next + fix n:: nat + assume a0:"n \ 1" and IH:"(H \\<^bsup>n\<^esup>) = H^\<^sub>\ n" + then have "(H \\<^bsup>(Suc n)\<^esup>) = H \ (H \\<^bsup>n\<^esup>)" + using iter_tensor_suc Nat.Suc_eq_plus1 by metis + also have "... = H \ (H^\<^sub>\ n)" + using IH by simp + also have "... = H^\<^sub>\ (Suc n)" + using a0 H_tensor_iter_tensor_of_H by simp + finally show "(H \\<^bsup>(Suc n)\<^esup>) = H^\<^sub>\ (Suc n)" + by simp +qed + +text \@{text "HId^\<^sub>\ 1"} is the result of taking the tensor product of the nth tensor of H and Id 1 \ + +abbreviation tensor_of_H_tensor_Id:: "nat \ complex Matrix.mat" ("HId^\<^sub>\ _") where +"tensor_of_H_tensor_Id n \ Matrix.mat (2^(n+1)) (2^(n+1)) (\(i,j). + if (i mod 2 = j mod 2) then (-1)^((i div 2) \\<^bsub>n\<^esub> (j div 2))/(sqrt 2)^n else 0)" + +lemma mod_2_is_both_even_or_odd: + "((even i \ even j) \ (odd i \ odd j)) \ (i mod 2 = j mod 2)" + by (metis even_iff_mod_2_eq_zero odd_iff_mod_2_eq_one) + +lemma HId_values [simp]: + assumes "n \ 1" and "i < dim_row (HId^\<^sub>\ n)" and "j < dim_col (HId^\<^sub>\ n)" + shows "even i \ even j \ (HId^\<^sub>\ n) $$ (i,j) = (-1)^((i div 2) \\<^bsub>n\<^esub> (j div 2))/(sqrt 2)^n" +and "odd i \ odd j \ (HId^\<^sub>\ n) $$ (i,j) = (-1)^((i div 2) \\<^bsub>n\<^esub> (j div 2))/(sqrt 2)^n" +and "(i mod 2 = j mod 2) \ (HId^\<^sub>\ n) $$ (i,j) = (-1)^((i div 2) \\<^bsub>n\<^esub> (j div 2))/(sqrt 2)^n" +and "\(i mod 2 = j mod 2) \ (HId^\<^sub>\ n) $$ (i,j) = 0" + using assms mod_2_is_both_even_or_odd by auto + +lemma iter_tensor_of_H_tensor_Id_is_HId: + shows "(H^\<^sub>\ n) \ Id 1 = HId^\<^sub>\ n" +proof + show "dim_row ((H^\<^sub>\ n) \ Id 1) = dim_row (HId^\<^sub>\ n)" + by (simp add: Quantum.Id_def) + show "dim_col ((H^\<^sub>\ n) \ Id 1) = dim_col (HId^\<^sub>\ n)" + by (simp add: Quantum.Id_def) +next + fix i j:: nat + assume a0: "i < dim_row (HId^\<^sub>\ n)" and a1: "j < dim_col (HId^\<^sub>\ n)" + then have f0: "i < (2^(n+1)) \ j < (2^(n+1))" by simp + then have "i < dim_row (H^\<^sub>\ n) * dim_row (Id 1) \ j < dim_col (H^\<^sub>\ n) * dim_col (Id 1)" + using Id_def by simp + moreover have "dim_col (H^\<^sub>\ n) \ 0 \ dim_col (Id 1) \ 0" + using Id_def by simp + ultimately have f1: "((H^\<^sub>\ n) \ (Id 1)) $$ (i,j) + = (H^\<^sub>\ n) $$ (i div (dim_row (Id 1)),j div (dim_col (Id 1))) * + (Id 1) $$ (i mod (dim_row (Id 1)),j mod (dim_col (Id 1)))" + by (simp add: Quantum.Id_def) + show "((H^\<^sub>\ n)\Id 1) $$ (i,j) = (HId^\<^sub>\ n) $$ (i,j)" + proof (rule disjE) + show "(i mod 2 = j mod 2) \ \ (i mod 2 = j mod 2)" by simp + next + assume a2:"(i mod 2 = j mod 2)" + then have "(Id 1) $$ (i mod (dim_row (Id 1)),j mod (dim_col (Id 1))) = 1" + by (simp add: Quantum.Id_def) + moreover have "(H^\<^sub>\ n) $$ (i div (dim_row (Id 1)), j div (dim_col (Id 1))) + = (-1)^((i div (dim_row (Id 1))) \\<^bsub>n\<^esub> (j div (dim_col (Id 1))))/(sqrt 2)^n" + using tensor_of_H_values Id_def f0 less_mult_imp_div_less by simp + ultimately show "((H^\<^sub>\ n) \ Id 1) $$ (i,j) = (HId^\<^sub>\ n) $$ (i,j)" + using a2 f0 f1 Id_def by simp + next + assume a2: "\(i mod 2 = j mod 2)" + then have "(Id 1) $$ (i mod (dim_row (Id 1)),j mod (dim_col (Id 1))) = 0" + by (simp add: Quantum.Id_def) + then show "((H^\<^sub>\ n) \ Id 1) $$ (i,j) = (HId^\<^sub>\ n) $$ (i,j)" + using a2 f0 f1 by simp + qed +qed + +lemma HId_is_gate: + assumes "n \ 1" + shows "gate (n+1) (HId^\<^sub>\ n)" +proof- + have "(HId^\<^sub>\ n) = (H^\<^sub>\ n) \ Id 1" + using iter_tensor_of_H_tensor_Id_is_HId by simp + moreover have "gate 1 (Id 1)" + using id_is_gate by simp + moreover have "gate n (H^\<^sub>\ n)" + using H_is_gate iter_tensor_of_gate_is_gate[of 1 H n] assms by(simp add: iter_tensor_of_H_rep_is_correct) + ultimately show "gate (n+1) (HId^\<^sub>\ n)" + using tensor_gate by presburger +qed + +text \State @{term "\\<^sub>3"} is obtained by the multiplication of @{term "HId^\<^sub>\ n"} and @{term "\\<^sub>2"}\ + +abbreviation (in jozsa) \\<^sub>3:: "complex Matrix.mat" where +"\\<^sub>3 \ Matrix.mat (2^(n+1)) 1 (\(i,j). +if even i + then (\k<2^n. (-1)^(f(k) + ((i div 2) \\<^bsub>n\<^esub> k))/((sqrt 2)^n * (sqrt 2)^(n+1))) + else (\k<2^n. (-1)^(f(k)+ 1 + ((i div 2) \\<^bsub>n\<^esub> k)) /((sqrt 2)^n * (sqrt 2)^(n+1))))" + +lemma (in jozsa) \\<^sub>3_values: + assumes "i < dim_row \\<^sub>3" + shows "odd i \ \\<^sub>3 $$ (i,0) = (\k<2^n. (-1)^(f(k) + 1 + ((i div 2) \\<^bsub>n\<^esub> k))/((sqrt 2)^n * (sqrt 2)^(n+1)))" + using assms by simp + +lemma (in jozsa) \\<^sub>3_dim [simp]: + shows "1 < dim_row \\<^sub>3" + using dim_row_mat(1) nat_neq_iff by fastforce + +lemma sum_every_odd_summand_is_zero: + fixes n:: nat + assumes "n \ 1" + shows "\f::(nat \ complex).(\i. i<2^(n+1) \ odd i \ f i = 0) \ + (\k\{0..<2^(n+1)}. f k) = (\k\{0..<2^n}. f (2*k))" + using assms +proof(rule nat_induct_at_least) + show "\f::(nat \ complex).(\i. i<2^(1+1) \ odd i \ f i = 0) \ + (\k\{0..<2^(1+1)}. f k) = (\k \ {0..<2^1}. f (2*k))" + proof(rule allI,rule impI) + fix f:: "(nat \ complex)" + assume asm: "(\i. i<2^(1+1) \ odd i \ f i = 0)" + moreover have "(\k\{0..<4}. f k) = f 0 + f 1 + f 2 + f 3" + by (simp add: add.commute add.left_commute) + moreover have "f 1 = 0" + using asm by simp + moreover have "f 3 = 0" + using asm by simp + moreover have "(\k\{0..<2^1}. f (2*k)) = f 0 + f 2" + using add.commute add.left_commute by simp + ultimately show "(\k\{0..<2^(1+1)}. f k) = (\k\{0..<2^1}. f (2*k))" + by simp + qed +next + fix n:: nat + assume "n \ 1" + and IH: "\f::(nat \complex).(\i. i<2^(n+1) \ odd i \ f i = 0) \ +(\k\{0..<2^(n+1)}. f k) = (\k\{0..<2^n}. f (2*k))" + show "\f::(nat \complex).(\i. i<2^(Suc n +1) \ odd i \ f i = 0) \ +(\k\{0..<2^(Suc n +1)}. f k) = (\k\{0..< 2^(Suc n)}. f (2*k))" + proof (rule allI,rule impI) + fix f::"nat \ complex" + assume asm: "(\i. i<2^(Suc n +1) \ odd i \ f i = 0)" + have f0: "(\k\{0..<2^(n+1)}. f k) = (\k\{0..<2^n}. f (2*k))" + using asm IH by simp + have f1: "(\k\{0..<2^(n+1)}. (\x. f (x+2^(n+1))) k) = (\k\{0..< 2^n}. (\x. f (x+2^(n+1))) (2*k))" + using asm IH by simp + have "(\k\{0..<2^(n+2)}. f k) = (\k\{0..<2^(n+1)}. f k) + (\k\{2^(n+1)..<2^(n+2)}. f k)" + by (simp add: sum.atLeastLessThan_concat) + also have "... = (\k\{0..<2^n}. f (2*k)) + (\k\{2^(n+1)..<2^(n+2)}. f k)" + using f0 by simp + also have "... = (\k\{0..<2^n}. f (2*k)) + (\k\{0..<2^(n+1)}. f (k+2^(n+1)))" + using sum.shift_bounds_nat_ivl[of "f" "0" "2^(n+1)" "2^(n+1)"] by simp + also have "... = (\k\{0..<2^n}. f (2*k)) + (\k\{0..< 2^n}. (\x. f (x+2^(n+1))) (2*k))" + using f1 by simp + also have "... = (\k\{0..<2^n}. f (2*k)) + (\k\{2^n..< 2^(n+1)}. f (2 *k))" + using sum.shift_bounds_nat_ivl[of "\x. (f::nat\complex) (2*(x-2^n)+2^(n+1))" "0" "2^n" "2^n"] + by (simp add: mult_2) + also have "... = (\k \ {0..<2^(n+1)}. f (2*k))" + by (metis Suc_eq_plus1 lessI less_imp_le_nat one_le_numeral power_increasing sum.atLeastLessThan_concat zero_le) + finally show "(\k\{0..<2^((Suc n)+1)}. f k) = (\k\{0..< 2^(Suc n)}. f (2*k))" + by (metis Suc_eq_plus1 add_2_eq_Suc') + qed +qed + +lemma sum_every_even_summand_is_zero: + fixes n:: nat + assumes "n \ 1" + shows "\f::(nat \ complex).(\i. i<2^(n+1) \ even i \ f i = 0) \ + (\k\{0..<2^(n+1)}. f k) = (\k\{0..< 2^n}. f (2*k+1))" + using assms +proof(rule nat_induct_at_least) + show "\f::(nat \ complex).(\i. i<2^(1+1) \ even i \ f i = 0) \ + (\k\{0..<2^(1+1)}. f k) = (\k\{0..< 2^1}. f (2*k+1))" + proof(rule allI,rule impI) + fix f:: "nat \complex" + assume asm: "(\i. i<2^(1+1) \ even i \ f i = 0)" + moreover have "(\k\{0..<4}. f k) = f 0 + f 1 + f 2 + f 3" + by (simp add: add.commute add.left_commute) + moreover have "f 0 = 0" using asm by simp + moreover have "f 2 = 0" using asm by simp + moreover have "(\k \ {0..< 2^1}. f (2*k+1)) = f 1 + f 3" + using add.commute add.left_commute by simp + ultimately show "(\k\{0..<2^(1+1)}. f k) = (\k\{0..< 2^1}. f (2*k+1))" by simp + qed +next + fix n:: nat + assume "n \ 1" + and IH: "\f::(nat \complex).(\i. i<2^(n+1) \ even i \ f i = 0) \ +(\k\{0..<2^(n+1)}. f k) = (\k\{0..< 2^n}. f (2*k+1))" + show "\f::(nat \complex).(\i. i<2^((Suc n)+1) \ even i \ f i = 0) \ +(\k\{0..<2^((Suc n)+1)}. f k) = (\k\{0..< 2^(Suc n)}. f (2*k+1))" + proof (rule allI,rule impI) + fix f::"nat \complex" + assume asm: "(\i. i<2^((Suc n)+1) \ even i \ f i = 0)" + have f0: "(\k \{0..<2^(n+1)}. f k) = (\k \ {0..< 2^n}. f (2*k+1))" + using asm IH by simp + have f1: "(\k\{0..<2^(n+1)}. (\x. f (x+2^(n+1))) k) + = (\k\{0..< 2^n}. (\x. f (x+2^(n+1))) (2*k+1))" + using asm IH by simp + have "(\k\{0..<2^(n+2)}. f k) + = (\k\{0..<2^(n+1)}. f k) + (\k\{2^(n+1)..<2^(n+2)}. f k)" + by (simp add: sum.atLeastLessThan_concat) + also have "... = (\k\{0..< 2^n}. f (2*k+1)) + (\k\{2^(n+1)..<2^(n+2)}. f k)" + using f0 by simp + also have "... = (\k\{0..< 2^n}. f (2*k+1)) + (\k\{0..<2^(n+1)}. f (k+(2^(n+1))))" + using sum.shift_bounds_nat_ivl[of "f" "0" "2^(n+1)" "2^(n+1)"] by simp + also have "... = (\k\{0..< 2^n}. f (2*k+1)) + (\k\{0..< 2^n}. (\x. f (x+2^(n+1))) (2*k+1))" + using f1 by simp + also have "... = (\k\{0..< 2^n}. f (2*k+1)) + (\k\{2^n..< 2^(n+1)}. f (2 *k+1))" + using sum.shift_bounds_nat_ivl[of "\x. (f::nat\complex) (2*(x-2^n)+1+2^(n+1))" "0" "2^n" "2^n"] + by (simp add: mult_2) + also have "... = (\k\{0..< 2^(n+1)}. f (2*k+1))" + by (metis Suc_eq_plus1 lessI less_imp_le_nat one_le_numeral power_increasing sum.atLeastLessThan_concat zero_le) + finally show "(\k\{0..<2^((Suc n)+1)}. f k) = (\k\{0..< 2^(Suc n)}. f (2*k+1))" + by (metis Suc_eq_plus1 add_2_eq_Suc') + qed +qed + +lemma (in jozsa) iter_tensor_of_H_times_\\<^sub>2_is_\\<^sub>3: + shows "((H^\<^sub>\ n) \ Id 1) * \\<^sub>2 = \\<^sub>3" +proof + fix i j + assume a0:"i < dim_row \\<^sub>3" and a1:"j < dim_col \\<^sub>3" + then have f0: "i < (2^(n+1)) \ j = 0" by simp + have f1: "((HId^\<^sub>\ n)* \\<^sub>2) $$ (i,j) = (\k<(2^(n+1)). ((HId^\<^sub>\ n) $$ (i,k)) * (\\<^sub>2 $$ (k,j)))" + using a1 f0 by (simp add: atLeast0LessThan) + show "(((H^\<^sub>\ n) \ Id 1) * \\<^sub>2) $$ (i,j) = \\<^sub>3 $$ (i,j)" + proof(rule disjE) + show "even i \ odd i" by simp + next + assume a2: "even i" + have "(\(i mod 2 = k mod 2) \ k\ n)) \ ((HId^\<^sub>\ n) $$ (i,k)) * (\\<^sub>2 $$ (k,j)) = 0" for k + using f0 by simp + then have "k<(2^(n+1)) \ odd k \ ((HId^\<^sub>\ n) $$ (i,k)) * (\\<^sub>2 $$ (k,j)) = 0" for k + using a2 mod_2_is_both_even_or_odd f0 by (metis (no_types, lifting) dim_col_mat(1)) + then have "(\k\{(0::nat)..<(2^(n+1))}. ((HId^\<^sub>\ n) $$ (i,k)) * (\\<^sub>2 $$ (k,j))) + = (\k\{(0::nat)..< (2^n)}. ((HId^\<^sub>\ n) $$ (i,2*k)) * (\\<^sub>2 $$ (2*k,j)))" + using sum_every_odd_summand_is_zero dim by simp + moreover have "(\k<2^n. ((HId^\<^sub>\ n) $$ (i,2*k)) * (\\<^sub>2 $$ (2*k,j))) + = (\k<2^n.(-1)^((i div 2) \\<^bsub>n\<^esub> k)/(sqrt(2)^n) *((-1)^f(k))/(sqrt(2)^(n+1)))" + proof- + have "(even k \ k\<^sub>2) \ (\\<^sub>2 $$ (k,j)) = ((-1)^f(k div 2))/(sqrt(2)^(n+1))" for k + using a0 a1 by simp + then have "(\k<2^n. ((HId^\<^sub>\ n) $$ (i,2*k)) * (\\<^sub>2 $$ (2*k,j))) + = (\k<2^n. ((HId^\<^sub>\ n) $$ (i,2*k)) *((-1)^f((2*k) div 2))/(sqrt(2)^(n+1)))" + by simp + moreover have "(even k \ k\ n)) + \ ((HId^\<^sub>\ n) $$ (i,k)) = (-1)^ ((i div 2) \\<^bsub>n\<^esub> (k div 2))/(sqrt(2)^n)" for k + using a2 a0 a1 by simp + ultimately have "(\k<2^n. ((HId^\<^sub>\ n) $$ (i,2*k)) * (\\<^sub>2 $$ (2*k,j))) + = (\k<2^n. (-1)^((i div 2) \\<^bsub>n\<^esub> ((2*k) div 2))/(sqrt(2)^n) * + ((-1)^f((2*k) div 2))/(sqrt(2)^(n+1)))" + by simp + then show "(\k<2^n. ((HId^\<^sub>\ n) $$ (i,2*k)) * (\\<^sub>2 $$ (2*k,j))) + = (\k<2^n. (-1)^((i div 2) \\<^bsub>n\<^esub> k)/(sqrt(2)^n) *((-1)^f(k))/(sqrt(2)^(n+1)))" + by simp + qed + ultimately have "((HId^\<^sub>\ n)* \\<^sub>2) $$ (i,j) = (\k<2^n. (-1)^((i div 2) \\<^bsub>n\<^esub> k)/(sqrt(2)^n) + * ((-1)^f(k))/(sqrt(2)^(n+1)))" + using f1 by (metis atLeast0LessThan) + also have "... = (\k<2^n. (-1)^(f(k)+((i div 2) \\<^bsub>n\<^esub> k))/((sqrt(2)^n)*(sqrt(2)^(n+1))))" + by (simp add: power_add mult.commute) + finally have "((HId^\<^sub>\ n)* \\<^sub>2) $$ (i,j) = (\k<2^n. (-1)^(f(k)+((i div 2) \\<^bsub>n\<^esub> k))/((sqrt(2)^n)*(sqrt(2)^(n+1))))" + by simp + moreover have "\\<^sub>3 $$ (i,j) = (\k<2^n. (-1)^(f(k) + ((i div 2) \\<^bsub>n\<^esub> k))/(sqrt(2)^n * sqrt(2)^(n+1)))" + using a0 a1 a2 by simp + ultimately show "(((H^\<^sub>\ n) \ Id 1)* \\<^sub>2) $$ (i,j) = \\<^sub>3 $$ (i,j)" + using iter_tensor_of_H_tensor_Id_is_HId dim by simp + next + assume a2: "odd i" + have "(\(i mod 2 = k mod 2) \ k\ n)) \ ((HId^\<^sub>\ n) $$ (i,k)) * (\\<^sub>2 $$ (k,j)) = 0" for k + using f0 by simp + then have "k<(2^(n+1)) \ even k \ ((HId^\<^sub>\ n) $$ (i,k)) * (\\<^sub>2 $$ (k,j)) = 0" for k + using a2 mod_2_is_both_even_or_odd f0 by (metis (no_types, lifting) dim_col_mat(1)) + then have "(\k\{0..<2^(n+1)}. ((HId^\<^sub>\ n) $$ (i,k)) * (\\<^sub>2 $$ (k,j))) + = (\k\{0..<2^n}. ((HId^\<^sub>\ n) $$ (i,2*k+1)) * (\\<^sub>2 $$ (2*k+1,j)))" + using sum_every_even_summand_is_zero dim by simp + moreover have "(\k<2^n. ((HId^\<^sub>\ n) $$ (i,2*k+1)) * (\\<^sub>2 $$ (2*k+1,j))) + = (\ k<2^n. (-1)^((i div 2) \\<^bsub>n\<^esub> k)/(sqrt(2)^n) * ((-1)^(f(k)+1))/(sqrt(2)^(n+1)))" + proof- + have "(odd k \ k\<^sub>2) \ (\\<^sub>2 $$ (k,j)) = ((-1)^(f(k div 2)+1))/(sqrt(2)^(n+1))" for k + using a0 a1 a2 by simp + then have f2:"(\k<2^n. ((HId^\<^sub>\ n) $$ (i,2*k+1)) * (\\<^sub>2 $$ (2*k+1,j))) + = (\k<2^n. ((HId^\<^sub>\ n) $$ (i,2*k+1)) * ((-1)^(f((2*k+1) div 2)+1))/(sqrt(2)^(n+1)))" + by simp + have "i < dim_row (HId^\<^sub>\ n)" + using f0 a2 mod_2_is_both_even_or_odd by simp + then have "((i mod 2 = k mod 2) \ k\ n)) + \ ((HId^\<^sub>\ n) $$ (i,k)) = (-1)^((i div 2) \\<^bsub>n\<^esub> (k div 2))/(sqrt(2)^n) " for k + using a2 a0 a1 f0 dim HId_values by simp + moreover have "odd k \ (i mod 2 = k mod 2)" for k + using a2 mod_2_is_both_even_or_odd by auto + ultimately have "(odd k \ k\ n)) + \ ((HId^\<^sub>\ n) $$ (i,k)) = (-1)^((i div 2) \\<^bsub>n\<^esub> (k div 2))/(sqrt(2)^n)" for k + by simp + then have "k<2^n \ ((HId^\<^sub>\ n) $$ (i,2*k+1)) = (-1)^((i div 2) \\<^bsub>n\<^esub> ((2*k+1) div 2))/(sqrt(2)^n) " for k + by simp + then have "(\k<2^n. ((HId^\<^sub>\ n) $$ (i,2*k+1)) * (\\<^sub>2 $$ (2*k+1,j))) + = (\k<2^n. (-1)^((i div 2) \\<^bsub>n\<^esub> ((2*k+1) div 2))/(sqrt(2)^n) + * ((-1)^(f((2*k+1) div 2)+1))/(sqrt(2)^(n+1)))" + using f2 by simp + then show "(\k<2^n. ((HId^\<^sub>\ n) $$ (i,2*k+1)) * (\\<^sub>2 $$ (2*k+1,j))) + = (\k<2^n. (-1)^((i div 2) \\<^bsub>n\<^esub> k)/(sqrt(2)^n) *((-1)^(f(k)+1))/(sqrt(2)^(n+1)))" + by simp + qed + ultimately have "((HId^\<^sub>\ n)* \\<^sub>2) $$ (i,j) = (\k<2^n. (-1)^((i div 2) \\<^bsub>n\<^esub> k)/(sqrt(2)^n) + * ((-1)^(f(k)+1))/(sqrt(2)^(n+1)))" + using f1 by (metis atLeast0LessThan) + also have "... = (\k<2^n. (-1)^(f(k)+1+((i div 2) \\<^bsub>n\<^esub> k))/((sqrt(2)^n)*(sqrt(2)^(n+1))))" + by (simp add: mult.commute power_add) + finally have "((HId^\<^sub>\ n)* \\<^sub>2) $$ (i,j) + = (\k< 2^n. (-1)^(f(k)+1+((i div 2) \\<^bsub>n\<^esub> k))/((sqrt(2)^n)*(sqrt(2)^(n+1))))" + by simp + then show "(((H^\<^sub>\ n) \ Id 1)* \\<^sub>2) $$ (i,j) = \\<^sub>3 $$ (i,j)" + using iter_tensor_of_H_tensor_Id_is_HId dim a2 a0 a1 by simp + qed +next + show "dim_row (((H^\<^sub>\ n) \ Id 1) * \\<^sub>2) = dim_row \\<^sub>3" + using iter_tensor_of_H_tensor_Id_is_HId dim by simp +next + show "dim_col (((H^\<^sub>\ n) \ Id 1)* \\<^sub>2) = dim_col \\<^sub>3" + using iter_tensor_of_H_tensor_Id_is_HId dim by simp +qed + +lemma (in jozsa) \\<^sub>3_is_state: + shows "state (n+1) \\<^sub>3" +proof- + have "((H^\<^sub>\ n) \ Id 1) * \\<^sub>2 = \\<^sub>3" + using iter_tensor_of_H_times_\\<^sub>2_is_\\<^sub>3 by simp + moreover have "gate (n+1) ((H^\<^sub>\ n) \ Id 1)" + using iter_tensor_of_H_tensor_Id_is_HId HId_is_gate dim by simp + moreover have "state (n+1) \\<^sub>2" + using \\<^sub>2_is_state by simp + ultimately show "state (n+1) \\<^sub>3" + using gate_on_state_is_state dim by (metis (no_types, lifting)) +qed + +text \ +Finally, all steps are put together. The result depends on the function f. If f is constant +the first n qubits are 0, if f is balanced there is at least one qubit in state 1 among the +first n qubits. +The algorithm only uses one evaluation of f(x) and will always succeed. +\ + +definition (in jozsa) jozsa_algo:: "complex Matrix.mat" where +"jozsa_algo \ ((H \\<^bsup>n\<^esup>) \ Id 1) * (U\<^sub>f * (((H \\<^bsup>n\<^esup>) * ( |zero\ \\<^bsup>n\<^esup>)) \ (H * |one\)))" + +lemma (in jozsa) jozsa_algo_result [simp]: + shows "jozsa_algo = \\<^sub>3" + using jozsa_algo_def H_on_ket_one_is_\\<^sub>1\<^sub>1 iter_tensor_of_H_on_zero_tensor \\<^sub>1\<^sub>0_tensor_\\<^sub>1\<^sub>1_is_\\<^sub>1 + jozsa_transform_times_\\<^sub>1_is_\\<^sub>2 iter_tensor_of_H_times_\\<^sub>2_is_\\<^sub>3 dim iter_tensor_of_H_rep_is_correct + by simp + +lemma (in jozsa) jozsa_algo_result_is_state: + shows "state (n+1) jozsa_algo" + using \\<^sub>3_is_state by simp + +lemma (in jozsa) prob0_fst_qubits_of_jozsa_algo: + shows "(prob0_fst_qubits n jozsa_algo) = (\j\{0,1}. (cmod(jozsa_algo $$ (j,0)))\<^sup>2)" + using prob0_fst_qubits_eq by simp + +text \General lemmata required to compute probabilities.\ + +lemma aux_comp_with_sqrt2: + shows "(sqrt 2)^n * (sqrt 2)^n = 2^n" + by (smt power_mult_distrib real_sqrt_mult_self) + +lemma aux_comp_with_sqrt2_bis [simp]: + shows "2^n/(sqrt(2)^n * sqrt(2)^(n+1)) = 1/sqrt 2" + using aux_comp_with_sqrt2 by (simp add: mult.left_commute) + +lemma aux_ineq_with_card: + fixes g:: "nat \ nat" and A:: "nat set" + assumes "finite A" + shows "(\k\A. (-1)^(g k)) \ card A" and "(\k\A. (-1)^(g k)) \ -card A" + apply (smt assms neg_one_even_power neg_one_odd_power card_eq_sum of_nat_1 of_nat_sum sum_mono) + apply (smt assms neg_one_even_power neg_one_odd_power card_eq_sum of_nat_1 of_nat_sum sum_mono sum_negf). + +lemma aux_comp_with_cmod: + fixes g:: "nat \ nat" + assumes "(\x<2^n. g x = 0) \ (\x<2^n. g x = 1)" + shows "(cmod (\k<2^n. (-1)^(g k)))\<^sup>2 = 2^(2*n)" +proof(rule disjE) + show "(\x<2^n. g x = 0) \ (\x<2^n. g x = 1)" + using assms by simp +next + assume "\x<2^n. g x = 0" + then have "(cmod (\k<2^n. (-1)^(g k)))\<^sup>2 = (2^n)\<^sup>2" + by (simp add: norm_power) + then show "?thesis" + by (simp add: power_even_eq) +next + assume "\x<2^n. g x = 1" + then have "(cmod (\k<2^n. (-1)^(g k)))\<^sup>2 = (2^n)\<^sup>2" + by (simp add: norm_power) + then show "?thesis" + by (simp add: power_even_eq) +qed + +lemma cmod_less: + fixes a n:: int + assumes "a < n" and "a > -n" + shows "cmod a < n" + using assms by simp + +lemma square_less: + fixes a n:: real + assumes "a < n" and "a > -n" + shows "a\<^sup>2 < n\<^sup>2" + using assms by (smt power2_eq_iff power2_minus power_less_imp_less_base) + +lemma cmod_square_real [simp]: + fixes n:: real + shows "(cmod n)\<^sup>2 = n\<^sup>2" + by simp + +lemma aux_comp_sum_divide_cmod: + fixes n:: nat and g:: "nat \ int" and a:: real + shows "(cmod(complex_of_real(\k2 = (cmod (\k2" + by (metis cmod_square_real of_int_sum of_real_of_int_eq power_divide sum_divide_distrib) + + +text \ +The function is constant if and only if the first n qubits are 0. So, if the function is constant, +then the probability of measuring 0 for the first n qubits is 1. +\ + +lemma (in jozsa) prob0_jozsa_algo_of_const_0: + assumes "const 0" + shows "prob0_fst_qubits n jozsa_algo = 1" +proof- + have "prob0_fst_qubits n jozsa_algo = (\j\{0,1}. (cmod(jozsa_algo $$ (j,0)))\<^sup>2)" + using prob0_fst_qubits_of_jozsa_algo by simp + moreover have "(cmod(jozsa_algo $$ (0,0)))\<^sup>2 = 1/2" + proof- + have "k<2^n \ ((0 div 2) \\<^bsub>n\<^esub> k) = 0" for k::nat + using bitwise_inner_prod_with_zero by simp + then have "(cmod(jozsa_algo $$ (0,0)))\<^sup>2 = (cmod(\k::nat<2^n. 1/(sqrt(2)^n * sqrt(2)^(n+1))))\<^sup>2" + using jozsa_algo_result const_def assms by simp + also have "... = (cmod((2::nat)^n/(sqrt(2)^n * sqrt(2)^(n+1))))\<^sup>2" by simp + also have "... = (cmod(1/(sqrt(2))))\<^sup>2" + using aux_comp_with_sqrt2_bis by simp + also have "... = 1/2" + by (simp add: norm_divide power2_eq_square) + finally show "?thesis" by simp + qed + moreover have "(cmod(jozsa_algo $$ (1,0)))\<^sup>2 = 1/2" + proof- + have "k<2^n \ ((1 div 2) \\<^bsub>n\<^esub> k) = 0" for k:: nat + using bitwise_inner_prod_with_zero by simp + then have "k<2^n \ f k + 1 + ((1 div 2) \\<^bsub>n\<^esub> k) = 1" for k::nat + using const_def assms by simp + moreover have "(cmod(jozsa_algo $$ (1,0)))\<^sup>2 + = (cmod (\k::nat<2^n. (-1)^(f k + 1 + ((1 div 2) \\<^bsub>n\<^esub> k))/(sqrt(2)^n * sqrt(2)^(n+1))))\<^sup>2" + using \\<^sub>3_dim by simp + ultimately have "(cmod(jozsa_algo $$ (1,0)))\<^sup>2 = (cmod(\k::nat<2^n. -1/(sqrt(2)^n * sqrt(2)^(n+1))))\<^sup>2" + by (smt lessThan_iff power_one_right sum.cong) + also have "... = (cmod(-1/(sqrt(2))))\<^sup>2" + using aux_comp_with_sqrt2_bis by simp + also have "... = 1/2" + by (simp add: norm_divide power2_eq_square) + finally show "?thesis" by simp + qed + ultimately have "prob0_fst_qubits n jozsa_algo = 1/2 + 1/2" by simp + then show "?thesis" by simp +qed + +lemma (in jozsa) prob0_jozsa_algo_of_const_1: + assumes "const 1" + shows "prob0_fst_qubits n jozsa_algo = 1" +proof- + have "prob0_fst_qubits n jozsa_algo = (\j\{0,1}. (cmod(jozsa_algo $$ (j,0)))\<^sup>2)" + using prob0_fst_qubits_of_jozsa_algo by simp + moreover have "(cmod(jozsa_algo $$ (0,0)))\<^sup>2 = 1/2" + proof- + have "k<2^n \ ((0 div 2) \\<^bsub>n\<^esub> k) = 0" for k::nat + using bitwise_inner_prod_with_zero by simp + then have "(cmod(jozsa_algo $$ (0,0)))\<^sup>2 = (cmod(\k::nat<2^n. 1/(sqrt(2)^n * sqrt(2)^(n+1))))\<^sup>2" + using jozsa_algo_result const_def assms by simp + also have "... = (cmod((-1)/(sqrt(2))))\<^sup>2 " + using aux_comp_with_sqrt2_bis by simp + also have "... = 1/2" + by (simp add: norm_divide power2_eq_square) + finally show "?thesis" by simp + qed + moreover have "(cmod(jozsa_algo $$ (1,0)))\<^sup>2 = 1/2" + proof- + have "k<2^n \ ((1 div 2) \\<^bsub>n\<^esub> k) = 0" for k::nat + using bitwise_inner_prod_with_zero by simp + then have "(\k::nat<2^n. (-1)^(f k +1 + ((1 div 2) \\<^bsub>n\<^esub> k))/(sqrt(2)^n * sqrt(2)^(n+1))) + = (\k::nat<2^n. 1/(sqrt(2)^n * sqrt(2)^(n+1)))" + using const_def assms by simp + moreover have "(cmod(jozsa_algo $$ (1,0)))\<^sup>2 + = (cmod (\k::nat<2^n. (-1)^(f k + 1 + ((1 div 2) \\<^bsub>n\<^esub> k))/(sqrt(2)^n * sqrt(2)^(n+1))))\<^sup>2" + using \\<^sub>3_dim by simp + ultimately have "(cmod(jozsa_algo $$ (1,0)))\<^sup>2 = (cmod(\k::nat<2^n. 1/(sqrt(2)^n * sqrt(2)^(n+1))))\<^sup>2" by simp + also have "... = (cmod(1/(sqrt(2))))\<^sup>2 " + using aux_comp_with_sqrt2_bis by simp + also have "... = 1/2" + by (simp add: norm_divide power2_eq_square) + finally show "?thesis" by simp + qed + ultimately have "prob0_fst_qubits n jozsa_algo = 1/2 + 1/2" by simp + then show "?thesis" by simp +qed + +text \If the probability of measuring 0 for the first n qubits is 1, then the function is constant.\ + +lemma (in jozsa) max_value_of_not_const_less: + assumes "\ const 0" and "\ const 1" + shows "(cmod (\k::nat<2^n. (-(1::nat))^(f k)))\<^sup>2 < (2::nat)^(2*n)" +proof- + have "cmod (\k::nat<2^n. (-(1::nat))^(f k)) < 2^n" + proof- + have "(\k::nat<2^n. (-(1::nat))^(f k)) < 2^n" + proof- + obtain x where f0:"x < 2^n" and f1:"f x = 1" + using assms(1) const_def f_values by auto + then have "(\k::nat<2^n. (-(1::nat))^(f k)) < (\k\{i| i:: nat. i < 2^n}-{x}. (-(1::nat))^(f k))" + proof- + have "(-(1::nat))^ f x = -1" using f1 by simp + moreover have "x\{i| i::nat. i<2^n}" using f0 by simp + moreover have "finite {i| i::nat. i<2^n}" by simp + moreover have "(\k\{i| i::nat. i<2^n}. (-(1::nat))^(f k)) < +(\k\{i| i:: nat. i<2^n}-{x}. (-(1::nat))^(f k))" + using calculation(1,2,3) sum_diff1 by (simp add: sum_diff1) + ultimately show ?thesis by (metis Collect_cong Collect_mem_eq lessThan_iff) + qed + moreover have "\ \ int (2^n - 1)" + using aux_ineq_with_card(1)[of "{i| i:: nat. i<2^n}-{x}"] f0 by simp + ultimately show ?thesis + by (meson diff_le_self less_le_trans of_nat_le_numeral_power_cancel_iff) + qed + moreover have "(\k::nat<2^n. (-(1::nat))^(f k)) > - (2^n)" + proof- + obtain x where f0:"x < 2^n" and f1:"f x = 0" + using assms(2) const_def f_values by auto + then have "(\k::nat<2^n. (-(1::nat))^(f k)) > (\k\{i| i:: nat. i < 2^n}-{x}. (-(1::nat))^(f k))" + proof- + have "(-(1::nat))^ f x = 1" using f1 by simp + moreover have "x\{i| i::nat. i<2^n}" using f0 by simp + moreover have "finite {i| i::nat. i<2^n}" by simp + moreover have "(\k\{i| i::nat. i<2^n}. (-(1::nat))^(f k)) > +(\k\{i| i:: nat. i<2^n}-{x}. (-(1::nat))^(f k))" + using calculation(1,2,3) sum_diff1 by (simp add: sum_diff1) + ultimately show ?thesis by (metis Collect_cong Collect_mem_eq lessThan_iff) + qed + moreover have "- int (2^n - 1) \ (\k\{i| i:: nat. i < 2^n}-{x}. (-(1::nat))^(f k))" + using aux_ineq_with_card(2)[of "{i| i:: nat. i<2^n}-{x}"] f0 by simp + ultimately show ?thesis + by (smt diff_le_self of_nat_1 of_nat_add of_nat_power_le_of_nat_cancel_iff one_add_one) + qed + ultimately show ?thesis + using cmod_less of_int_of_nat_eq of_nat_numeral of_nat_power by (metis (no_types, lifting)) + qed + then have "(cmod (\k::nat<2^n. (-(1::nat))^(f k)))\<^sup>2 < (2^n)\<^sup>2" + using square_less norm_ge_zero by smt + thus ?thesis + by (simp add: power_even_eq) +qed + +lemma (in jozsa) max_value_of_not_const_less_bis: + assumes "\ const 0" and "\ const 1" + shows "(cmod (\k::nat<2^n. (-(1::nat))^(f k + 1)))\<^sup>2 < (2::nat)^(2*n)" +proof- + have "cmod (\k::nat<2^n. (-(1::nat))^(f k + 1)) < 2^n" + proof- + have "(\k::nat<2^n. (-(1::nat))^(f k + 1)) < 2^n" + proof- + obtain x where f0:"x < 2^n" and f1:"f x = 0" + using assms(2) const_def f_values by auto + then have "(\k::nat<2^n. (-(1::nat))^(f k + 1)) < (\k\{i| i:: nat. i < 2^n}-{x}. (-(1::nat))^(f k + 1))" + proof- + have "(-(1::nat))^ (f x + 1) = -1" using f1 by simp + moreover have "x\{i| i::nat. i<2^n}" using f0 by simp + moreover have "finite {i| i::nat. i<2^n}" by simp + moreover have "(\k\{i| i::nat. i<2^n}. (-(1::nat))^(f k + 1)) < +(\k\{i| i:: nat. i<2^n}-{x}. (-(1::nat))^(f k + 1))" + using calculation(1,2,3) sum_diff1 by (simp add: sum_diff1) + ultimately show ?thesis by (metis Collect_cong Collect_mem_eq lessThan_iff) + qed + moreover have "\ \ int (2^n - 1)" + using aux_ineq_with_card(1)[of "{i| i:: nat. i<2^n}-{x}" "\k. f k + 1"] f0 by simp + ultimately show ?thesis + by (meson diff_le_self less_le_trans of_nat_le_numeral_power_cancel_iff) + qed + moreover have "(\k::nat<2^n. (-(1::nat))^(f k + 1)) > - (2^n)" + proof- + obtain x where f0:"x < 2^n" and f1:"f x = 1" + using assms(1) const_def f_values by auto + then have "(\k::nat<2^n. (-(1::nat))^(f k + 1)) > (\k\{i| i:: nat. i < 2^n}-{x}. (-(1::nat))^(f k + 1))" + proof- + have "(-(1::nat))^ (f x + 1) = 1" using f1 by simp + moreover have "x\{i| i::nat. i<2^n}" using f0 by simp + moreover have "finite {i| i::nat. i<2^n}" by simp + moreover have "(\k\{i| i::nat. i<2^n}. (-(1::nat))^(f k + 1)) > +(\k\{i| i:: nat. i<2^n}-{x}. (-(1::nat))^(f k + 1))" + using calculation(1,2,3) sum_diff1 by (simp add: sum_diff1) + ultimately show ?thesis by (metis Collect_cong Collect_mem_eq lessThan_iff) + qed + moreover have "- int (2^n - 1) \ (\k\{i| i:: nat. i < 2^n}-{x}. (-(1::nat))^(f k + 1))" + using aux_ineq_with_card(2)[of "{i| i:: nat. i<2^n}-{x}" "\k. f k + 1"] f0 by simp + ultimately show ?thesis + by (smt diff_le_self of_nat_1 of_nat_add of_nat_power_le_of_nat_cancel_iff one_add_one) + qed + ultimately show ?thesis + using cmod_less of_int_of_nat_eq of_nat_numeral of_nat_power by (metis (no_types, lifting)) + qed + then have "(cmod (\k::nat<2^n. (-(1::nat))^(f k + 1)))\<^sup>2 < (2^n)\<^sup>2" + using square_less norm_ge_zero by smt + thus ?thesis + by (simp add: power_even_eq) +qed + +lemma (in jozsa) f_const_has_max_value: + assumes "const 0 \ const 1" + shows "(cmod (\k<(2::nat)^n. (-1)^(f k)))\<^sup>2 = (2::nat)^(2*n)" + and "(cmod (\k<(2::nat)^n. (-1)^(f k + 1)))\<^sup>2 = (2::nat)^(2*n)" + using aux_comp_with_cmod[of n "\k. f k"] aux_comp_with_cmod[of n "\k. f k + 1"] const_def assms by auto + +lemma (in jozsa) prob0_fst_qubits_leq: + shows "(cmod (\k<(2::nat)^n. (-1)^(f k)))\<^sup>2 \ (2::nat)^(2*n)" + and "(cmod (\k<(2::nat)^n. (-1)^(f k + 1)))\<^sup>2 \ (2::nat)^(2*n)" +proof- + show "(cmod (\k<(2::nat)^n. (-1)^(f k)))\<^sup>2 \ (2::nat)^(2*n)" + proof(rule disjE) + show "(const 0 \ const 1) \ (\ const 0 \ \ const 1)" by auto + next + assume "const 0 \ const 1" + then show "(cmod (\k<(2::nat)^n. (-1)^(f k)))\<^sup>2 \ (2::nat)^(2*n)" + using f_const_has_max_value by simp + next + assume "\ const 0 \ \ const 1" + then show "(cmod (\k<(2::nat)^n. (-1)^(f k)))\<^sup>2 \ (2::nat)^(2*n)" + using max_value_of_not_const_less by simp + qed +next + show "(cmod (\k<(2::nat)^n. (-1)^(f k + 1)))\<^sup>2 \ (2::nat)^(2*n)" + proof(rule disjE) + show "(const 0 \ const 1) \ (\ const 0 \ \ const 1)" by auto + next + assume "const 0 \ const 1" + then show "(cmod (\k<(2::nat)^n. (-1)^(f k + 1)))\<^sup>2 \ (2::nat)^(2*n)" + using f_const_has_max_value by simp + next + assume "\ const 0 \ \ const 1" + then show "(cmod (\k<(2::nat)^n. (-1)^(f k + 1)))\<^sup>2 \ (2::nat)^(2*n)" + using max_value_of_not_const_less_bis by simp + qed +qed + +lemma (in jozsa) prob0_jozsa_algo_1_is_const: + assumes "prob0_fst_qubits n jozsa_algo = 1" + shows "const 0 \ const 1" +proof- + have f0: "(\j\{0,1}. (cmod(jozsa_algo $$ (j,0)))\<^sup>2) = 1" + using prob0_fst_qubits_of_jozsa_algo assms by simp + have "k < 2^n\((0 div 2) \\<^bsub>n\<^esub> k) = 0" for k::nat + using bitwise_inner_prod_with_zero by simp + then have f1: "(cmod(jozsa_algo $$ (0,0)))\<^sup>2 = (cmod(\k<(2::nat)^n. (-1)^(f k)/(sqrt(2)^n * sqrt(2)^(n+1))))\<^sup>2" + by simp + have "k < 2^n\((1 div 2) \\<^bsub>n\<^esub> k) = 0" for k::nat + using bitwise_inner_prod_with_zero by simp + moreover have "(cmod(jozsa_algo $$ (1,0)))\<^sup>2 + = (cmod (\k<(2::nat)^n. (-1)^(f k+ 1 + ((1 div 2) \\<^bsub>n\<^esub> k))/(sqrt(2)^n * sqrt(2)^(n+1))))\<^sup>2" + using \\<^sub>3_dim by simp + ultimately have f2: "(cmod(jozsa_algo $$ (1,0)))\<^sup>2 + = (cmod (\k<(2::nat)^n. (-1)^(f k + 1)/(sqrt(2)^n * sqrt(2)^(n+1))))\<^sup>2" by simp + have f3: "1 = (cmod(\k::nat<(2::nat)^n.(-1)^(f k)/(sqrt(2)^n * sqrt(2)^(n+1))))\<^sup>2 + + (cmod (\k::nat<(2::nat)^n. (-1)^(f k + 1)/(sqrt(2)^n * sqrt(2)^(n+1))))\<^sup>2" + using f0 f1 f2 by simp + also have "... = ((cmod (\k::nat<(2::nat)^n. (-1)^(f k)) ) /(sqrt(2)^n * sqrt(2)^(n+1)))\<^sup>2 + + ((cmod(\k::nat<(2::nat)^n. (-1)^(f k + 1))) /(sqrt(2)^n * sqrt(2)^(n+1)))\<^sup>2" + using aux_comp_sum_divide_cmod[of "\k. (-1)^(f k)" "(sqrt(2)^n * sqrt(2)^(n+1))" "(2::nat)^n"] + aux_comp_sum_divide_cmod[of "\k. (-1)^(f k + 1)" "(sqrt(2)^n * sqrt(2)^(n+1))" "(2::nat)^n"] + by simp + also have "... = ((cmod (\k::nat<(2::nat)^n. (-1)^(f k))))\<^sup>2 /((sqrt(2)^n * sqrt(2)^(n+1)))\<^sup>2 + + ((cmod(\k::nat<(2::nat)^n. (-1)^(f k +1))))\<^sup>2 /((sqrt(2)^n * sqrt(2)^(n+1)))\<^sup>2" + by (simp add: power_divide) + also have "... = ((cmod (\k::nat<(2::nat)^n. (-1)^(f k)) ) )\<^sup>2/(2^(2*n+1)) + + ((cmod(\k::nat<(2::nat)^n. (-1)^(f k + 1))))\<^sup>2 /(2^(2*n+1))" + by (smt left_add_twice power2_eq_square power_add power_mult_distrib real_sqrt_pow2) + also have "... = (((cmod (\k::nat<(2::nat)^n. (-1)^(f k))))\<^sup>2 + + ((cmod(\k::nat<(2::nat)^n. (-1)^(f k + 1))))\<^sup>2)/(2^(2*n+1)) " + by (simp add: add_divide_distrib) + finally have "((2::nat)^(2*n+1)) = (((cmod (\k::nat<(2::nat)^n. (-1)^(f k))))\<^sup>2 + + ((cmod(\k::nat<(2::nat)^n. (-1)^(f k + 1))))\<^sup>2)" by simp + moreover have "((2::nat)^(2*n+1)) = 2^(2*n) + 2^(2*n)" by auto + moreover have "(cmod (\k<(2::nat)^n. (-1)^(f k)))\<^sup>2 \ 2^(2*n)" + using prob0_fst_qubits_leq by simp + moreover have "(cmod (\k<(2::nat)^n. (-1)^(f k + 1)))\<^sup>2 \ 2^(2*n)" + using prob0_fst_qubits_leq by simp + ultimately have "2^(2*n) = ((cmod (\k::nat<(2::nat)^n. (-1)^(f k))))\<^sup>2" by simp + then show ?thesis + using max_value_of_not_const_less by auto +qed + +text \ +The function is balanced if and only if at least one qubit among the first n qubits is not zero. +So, if the function is balanced then the probability of measuring 0 for the first n qubits is 0. +\ + +lemma sum_union_disjoint_finite_set: + fixes C::"nat set" and g::"nat \ int" + assumes "finite C" + shows "\A B. A \ B = {} \ A \ B = C \ (\k\C. g k) = (\k\A. g k) + (\k\B. g k)" + using assms sum.union_disjoint by auto + +lemma (in jozsa) balanced_pos_and_neg_terms_cancel_out1: + assumes "is_balanced" + shows "(\k<(2::nat)^n. (-(1::nat))^(f k)) = 0" +proof- + have "\A B. A \ {i::nat. i < (2::nat)^n} \ B \ {i::nat. i < (2::nat)^n} + \ card A = ((2::nat)^(n-1)) \ card B = ((2::nat)^(n-1)) + \ (\(x::nat) \ A. f x = (0::nat)) \ (\(x::nat) \ B. f x = 1) + \ (\k<(2::nat)^n. (-(1::nat))^(f k)) = 0" + proof + fix A B::"nat set" + assume asm: "A \ {i::nat. i < (2::nat)^n} \ B \ {i::nat. i < (2::nat)^n} + \ card A = ((2::nat)^(n-1)) \ card B = ((2::nat)^(n-1)) + \ (\(x::nat) \ A. f x = (0::nat)) \ (\(x::nat) \ B. f x = 1)" + then have " A \ B = {}" and "{0..<(2::nat)^n} = A \ B" + using is_balanced_union is_balanced_inter by auto + then have "(\k\{0..<(2::nat)^n}. (-(1::nat))^(f k)) = + (\k\A. (-(1::nat))^(f k)) + + (\k\B. (-(1::nat))^(f k))" + by (metis finite_atLeastLessThan sum_union_disjoint_finite_set) + moreover have "(\k\A. (-1)^(f k)) = ((2::nat)^(n-1))" + using asm by simp + moreover have "(\k\B. (-1)^(f k)) = -((2::nat)^(n-1))" + using asm by simp + ultimately have "(\k\ {0..<(2::nat)^n}. (-(1::nat))^(f k)) = 0" by simp + then show "(\k<(2::nat)^n. (-(1::nat))^(f k)) = 0" + by (simp add: lessThan_atLeast0) + qed + then show ?thesis + using assms is_balanced_def by auto +qed + +lemma (in jozsa) balanced_pos_and_neg_terms_cancel_out2: + assumes "is_balanced" + shows "(\k<(2::nat)^n. (-(1::nat))^(f k + 1)) = 0" +proof- + have "\A B. A \ {i::nat. i < (2::nat)^n} \ B \ {i::nat. i < (2::nat)^n} + \ card A = ((2::nat)^(n-1)) \ card B = ((2::nat)^(n-1)) + \ (\(x::nat)\A. f x = (0::nat)) \ (\(x::nat)\B. f x = 1) + \ (\k<(2::nat)^n. (-(1::nat))^(f k + 1)) = 0" + proof + fix A B::"nat set" + assume asm: "A \ {i::nat. i < (2::nat)^n} \ B \ {i::nat. i < (2::nat)^n} + \ card A = ((2::nat)^(n-1)) \ card B = ((2::nat)^(n-1)) + \ (\(x::nat) \ A. f x = (0::nat)) \ (\(x::nat) \ B. f x = 1)" + have "A \ B = {}" and "{0..<(2::nat)^n} = A \ B" + using is_balanced_union is_balanced_inter asm by auto + then have "(\k\{0..<(2::nat)^n}. (-(1::nat))^(f k + 1)) = + (\k\A. (-(1::nat))^(f k + 1)) + + (\k\B. (-(1::nat))^(f k + 1))" + by (metis finite_atLeastLessThan sum_union_disjoint_finite_set) + moreover have "(\k\A. (-1)^(f k + 1)) = -((2::nat)^(n-1))" + using asm by simp + moreover have "(\k\B. (-1)^(f k + 1)) = ((2::nat)^(n-1))" + using asm by simp + ultimately have "(\k\{0..<(2::nat)^n}. (-(1::nat))^(f k + 1)) = 0 " by simp + then show "(\k<(2::nat)^n. (-(1::nat))^(f k + 1)) = 0" + by (simp add: lessThan_atLeast0) + qed + then show "(\k<(2::nat)^n. (-(1::nat))^(f k + 1)) = 0" + using assms is_balanced_def by auto +qed + +lemma (in jozsa) prob0_jozsa_algo_of_balanced: +assumes "is_balanced" + shows "prob0_fst_qubits n jozsa_algo = 0" +proof- + have "prob0_fst_qubits n jozsa_algo = (\j\{0,1}. (cmod(jozsa_algo $$ (j,0)))\<^sup>2)" + using prob0_fst_qubits_of_jozsa_algo by simp + moreover have "(cmod(jozsa_algo $$ (0,0)))\<^sup>2 = 0" + proof- + have "k < 2^n\((1 div 2) \\<^bsub>n\<^esub> k) = 0" for k::nat + using bitwise_inner_prod_with_zero by simp + then have "(cmod(jozsa_algo $$ (0,0)))\<^sup>2 = (cmod(\ k < (2::nat)^n. (-1)^(f k)/(sqrt(2)^n * sqrt(2)^(n+1))))\<^sup>2" + using \\<^sub>3_values by simp + also have "... = (cmod(\k<(2::nat)^n. (-(1::nat))^(f k))/(sqrt(2)^n * sqrt(2)^(n+1)))\<^sup>2" + using aux_comp_sum_divide_cmod[of "\k.(-(1::nat))^(f k)" "(sqrt(2)^n * sqrt(2)^(n+1))" "2^n"] + by simp + also have "... = (cmod ((0::int)/(sqrt(2)^n * sqrt(2)^(n+1))))\<^sup>2" + using balanced_pos_and_neg_terms_cancel_out1 assms by (simp add: bob_fun_axioms) + also have "... = 0" by simp + finally show ?thesis by simp + qed + moreover have "(cmod(jozsa_algo $$ (1,0)))\<^sup>2 = 0" + proof- + have "k < 2^n \ (((1::nat) div 2) \\<^bsub>n\<^esub> k) = 0" for k::nat + using bitwise_inner_prod_with_zero by auto + moreover have "(cmod(jozsa_algo $$ (1,0)))\<^sup>2 + = (cmod (\k<(2::nat)^n. (-(1::nat))^(f k + (1::nat) + ((1 div 2) \\<^bsub>n\<^esub> k))/(sqrt(2)^n * sqrt(2)^(n+1))))\<^sup>2" + using \\<^sub>3_dim by simp + ultimately have "(cmod(jozsa_algo $$ (1,0)))\<^sup>2 + = (cmod(\k<(2::nat)^n. (-(1::nat))^(f k + (1::nat))/(sqrt(2)^n * sqrt(2)^(n+1))))\<^sup>2" + by simp + also have "... = (cmod(\k<(2::nat)^n. (-(1::nat))^(f k + 1))/(sqrt(2)^n * sqrt(2)^(n+1)))\<^sup>2" + using aux_comp_sum_divide_cmod[of "\k.(-(1::nat))^(f k + 1)" "(sqrt(2)^n * sqrt(2)^(n+1))" "2^n"] + by simp + also have "... = (cmod ((0::int)/(sqrt(2)^n * sqrt(2)^(n+1))))\<^sup>2" + using balanced_pos_and_neg_terms_cancel_out2 assms by (simp add: bob_fun_axioms) + also have "... = 0" by simp + finally show ?thesis by simp + qed + ultimately have "prob0_fst_qubits n jozsa_algo = 0 + 0" by simp + then show ?thesis by simp +qed + +text \If the probability that the first n qubits are 0 is 0, then the function is balanced.\ + +lemma (in jozsa) balanced_prob0_jozsa_algo: + assumes "prob0_fst_qubits n jozsa_algo = 0" + shows "is_balanced" +proof- + have "is_const \ is_balanced" + using const_or_balanced by simp + moreover have "is_const \ \ prob0_fst_qubits n jozsa_algo = 0" + using is_const_def prob0_jozsa_algo_of_const_0 prob0_jozsa_algo_of_const_1 by simp + ultimately show ?thesis + using assms by simp +qed + +text \We prove the correctness of the algorithm.\ + +definition (in jozsa) jozsa_algo_eval:: "real" where +"jozsa_algo_eval \ prob0_fst_qubits n jozsa_algo" + +theorem (in jozsa) jozsa_algo_is_correct: + shows "jozsa_algo_eval = 1 \ is_const" + and "jozsa_algo_eval = 0 \ is_balanced" + using prob0_jozsa_algo_of_const_1 prob0_jozsa_algo_of_const_0 jozsa_algo_eval_def +prob0_jozsa_algo_1_is_const is_const_def balanced_prob0_jozsa_algo prob0_jozsa_algo_of_balanced + by auto + +end \ No newline at end of file diff --git a/thys/Isabelle_Marries_Dirac/Entanglement.thy b/thys/Isabelle_Marries_Dirac/Entanglement.thy new file mode 100755 --- /dev/null +++ b/thys/Isabelle_Marries_Dirac/Entanglement.thy @@ -0,0 +1,148 @@ +(* +Authors: + + Anthony Bordg, University of Cambridge, apdb3@cam.ac.uk; + Yijun He, University of Cambridge, yh403@cam.ac.uk +*) + +section \Quantum Entanglement\ + +theory Entanglement +imports + Quantum + More_Tensor +begin + + +subsection \The Product States and Entangled States of a 2-qubits System\ + +text \Below we add the condition that @{term v} and @{term w} are two-dimensional states, otherwise +@{term u} can always be represented by the tensor product of the 1-dimensional vector @{term 1} and +@{term u} itself.\ + +definition prod_state2:: "complex Matrix.mat \ bool" where +"prod_state2 u \ if state 2 u then \v w. state 1 v \ state 1 w \ u = v \ w else undefined" + +definition entangled2:: "complex Matrix.mat \ bool" where +"entangled2 u \ \ prod_state2 u" + +text \The Bell states are entangled states.\ + +lemma bell00_is_entangled2 [simp]: + "entangled2 |\\<^sub>0\<^sub>0\" +proof - + have "\v w. state 1 v \ state 1 w \ |\\<^sub>0\<^sub>0\ \ v \ w" + proof((rule allI)+,(rule impI)+, rule notI) + fix v w + assume a0:"state 1 v" and a1:"state 1 w" and a2:"|\\<^sub>0\<^sub>0\ = v \ w" + have "(v $$ (0,0) * w $$ (0,0)) * (v $$ (1,0) * w $$ (1,0)) = + (v $$ (0,0) * w $$ (1,0)) * (v $$ (1,0) * w $$ (0,0))" by simp + then have "(v \ w) $$ (0,0) * (v \ w) $$ (3,0) = (v \ w) $$ (1,0) * (v \ w) $$ (2,0)" + using a0 a1 by simp + then have "|\\<^sub>0\<^sub>0\ $$ (0,0) * |\\<^sub>0\<^sub>0\ $$ (3,0) = |\\<^sub>0\<^sub>0\ $$ (1,0) * |\\<^sub>0\<^sub>0\ $$ (2,0)" + using a2 by simp + then have "1/ sqrt 2 * 1/sqrt 2 = 0" by simp + thus False by simp + qed + thus ?thesis by(simp add: entangled2_def prod_state2_def) +qed + +lemma bell01_is_entangled2 [simp]: + "entangled2 |\\<^sub>0\<^sub>1\" +proof - + have "\v w. state 1 v \ state 1 w \ |\\<^sub>0\<^sub>1\ \ v \ w" + proof((rule allI)+,(rule impI)+, rule notI) + fix v w + assume a0:"state 1 v" and a1:"state 1 w" and a2:"|\\<^sub>0\<^sub>1\ = v \ w" + have "(v $$ (0,0) * w $$ (1,0)) * (v $$ (1,0) * w $$ (0,0)) = + (v $$ (0,0) * w $$ (0,0)) * (v $$ (1,0) * w $$ (1,0))" by simp + then have "(v \ w) $$ (1,0) * (v \ w) $$ (2,0) = (v \ w) $$ (0,0) * (v \ w) $$ (3,0)" + using a0 a1 by simp + then have "|\\<^sub>0\<^sub>1\ $$ (1,0) * |\\<^sub>0\<^sub>1\ $$ (2,0) = |\\<^sub>0\<^sub>1\ $$ (0,0) * |\\<^sub>0\<^sub>1\ $$ (3,0)" + using a2 by simp + then have "1/sqrt 2 * 1/sqrt 2 = 0" + using bell01_index by simp + thus False by simp + qed + thus ?thesis by(simp add: entangled2_def prod_state2_def) +qed + +lemma bell10_is_entangled2 [simp]: + "entangled2 |\\<^sub>1\<^sub>0\" +proof - + have "\v w. state 1 v \ state 1 w \ |\\<^sub>1\<^sub>0\ \ v \ w" + proof((rule allI)+,(rule impI)+, rule notI) + fix v w + assume a0:"state 1 v" and a1:"state 1 w" and a2:"|\\<^sub>1\<^sub>0\ = v \ w" + have "(v $$ (0,0) * w $$ (0,0)) * (v $$ (1,0) * w $$ (1,0)) = + (v $$ (0,0) * w $$ (1,0)) * (v $$ (1,0) * w $$ (0,0))" by simp + then have "(v \ w) $$ (0,0) * (v \ w) $$ (3,0) = (v \ w) $$ (1,0) * (v \ w) $$ (2,0)" + using a0 a1 by simp + then have "|\\<^sub>1\<^sub>0\ $$ (1,0) * |\\<^sub>1\<^sub>0\ $$ (2,0) = |\\<^sub>1\<^sub>0\ $$ (0,0) * |\\<^sub>1\<^sub>0\ $$ (3,0)" + using a2 by simp + then have "1/sqrt 2 * 1/sqrt 2 = 0" by simp + thus False by simp + qed + thus ?thesis by(simp add: entangled2_def prod_state2_def) +qed + +lemma bell11_is_entangled2 [simp]: + "entangled2 |\\<^sub>1\<^sub>1\" +proof - + have "\v w. state 1 v \ state 1 w \ |\\<^sub>1\<^sub>1\ \ v \ w" + proof((rule allI)+,(rule impI)+, rule notI) + fix v w + assume a0:"state 1 v" and a1:"state 1 w" and a2:"|\\<^sub>1\<^sub>1\ = v \ w" + have "(v $$ (0,0) * w $$ (1,0)) * (v $$ (1,0) * w $$ (0,0)) = + (v $$ (0,0) * w $$ (0,0)) * (v $$ (1,0) * w $$ (1,0))" by simp + then have "(v \ w) $$ (1,0) * (v \ w) $$ (2,0) = (v \ w) $$ (0,0) * (v \ w) $$ (3,0)" + using a0 a1 by simp + then have "|\\<^sub>1\<^sub>1\ $$ (1,0) * |\\<^sub>1\<^sub>1\ $$ (2,0) = |\\<^sub>1\<^sub>1\ $$ (0,0) * |\\<^sub>1\<^sub>1\ $$ (3,0)" + using a2 by simp + then have "1/sqrt 2 * 1/sqrt 2 = 0" + using bell_11_index by simp + thus False by simp + qed + thus ?thesis by(simp add: entangled2_def prod_state2_def) +qed + +text \ +An entangled state is a state that cannot be broken down as the tensor product of smaller states. +\ + +definition prod_state:: "nat \ complex Matrix.mat \ bool" where +"prod_state m u \ if state m u then \n p::nat.\v w. state n v \ state p w \ + n < m \ p < m \ u = v \ w else undefined" + +definition entangled:: "nat \ complex Matrix.mat \ bool" where +"entangled n v \ \ (prod_state n v)" + +(* To do: as an exercise prove the equivalence between entangled2 and (entangled 2). *) + +lemma sanity_check: + "\(entangled 2 (mat_of_cols_list 2 [[1/sqrt(2), 1/sqrt(2)]] \ mat_of_cols_list 2 [[1/sqrt(2), 1/sqrt(2)]]))" +proof - + define u where "u = mat_of_cols_list 2 [[1/sqrt(2), 1/sqrt(2)]]" + then have "state 1 u" + proof - + have "dim_col u = 1" + using u_def mat_of_cols_list_def by simp + moreover have f:"dim_row u = 2" + using u_def mat_of_cols_list_def by simp + moreover have "\Matrix.col u 0\ = 1" + proof - + have "(\i<2. (cmod (u $$ (i, 0)))\<^sup>2) = (1/sqrt 2)\<^sup>2 + (1/sqrt 2)\<^sup>2" + by(simp add: u_def cmod_def numeral_2_eq_2) + then have "\Matrix.col u 0\ = sqrt ((1/sqrt 2)\<^sup>2 + (1/sqrt 2)\<^sup>2)" + using f by(auto simp: Matrix.col_def u_def cpx_vec_length_def) + thus ?thesis by(simp add: power_divide) + qed + ultimately show ?thesis by(simp add: state_def) + qed + then have "state 2 (u \ u)" + using tensor_state by(metis one_add_one) + thus ?thesis + using entangled_def prod_state_def by(metis \state 1 u\ one_less_numeral_iff semiring_norm(76) u_def) +qed + +end \ No newline at end of file diff --git a/thys/Isabelle_Marries_Dirac/Measurement.thy b/thys/Isabelle_Marries_Dirac/Measurement.thy new file mode 100755 --- /dev/null +++ b/thys/Isabelle_Marries_Dirac/Measurement.thy @@ -0,0 +1,1122 @@ +(* +Author: + Anthony Bordg, University of Cambridge, apdb3@cam.ac.uk + Yijun He, University of Cambridge, yh403@cam.ac.uk +*) + +section \Measurement\ + +theory Measurement +imports + Quantum +begin + + +text \ +Given an element v such that @{text "state n v"}, its components @{text "v $ i"} (when v is seen as +a vector, v being a matrix column) for @{text "0 \ i < n"} have to be understood as the coefficients +of the representation of v in the basis given by the unit vectors of dimension $2^n$, unless stated otherwise. +Such a vector v is a state for a quantum system of n qubits. +In the literature on quantum computing, for $n = 1$, i.e. for a quantum system of 1 qubit, the elements +of the so-called computational basis are denoted $|0\rangle$,$|1\rangle$, and these last elements might be understood +for instance as $(1,0)$,$(0,1)$, i.e. as the zeroth and the first elements of a given basis ; for $n = 2$, +i.e. for a quantum system of 2 qubits, the elements of the computational basis are denoted $|00\rangle$, +$|01\rangle$, $|10\rangle$,$|11\rangle$, and they might be understood for instance as $(1,0,0,0)$, +$(0,1,0,0)$, $(0,0,1,0)$, $(0,0,0,1)$; and so on for higher values of $n$. +The idea behind these standard notations is that the labels on the vectors of the +computational basis are the binary expressions of the natural numbers indexing the elements +in a given ordered basis interpreting the computational basis in a specific context, another point of +view is that the order of the basis corresponds to the lexicographic order for the labels. +Those labels also represent the possible outcomes of a measurement of the $n$ qubits of the system, +while the squared modules of the corresponding coefficients represent the probabilities for those +outcomes. The fact that the vector v has to be normalized expresses precisely the fact that the squared +modules of the coefficients represent some probabilities and hence their sum should be $1$. +Note that in the case of a system with multiple qubits, i.e. $n \geq 2$, one can model the simultaneous +measurement of multiple qubits by sequential measurements of single qubits. Indeed, this last process +leads to the same probabilities for the various possible outcomes. +Given a system with n-qubits and i the index of one qubit among the $n$ qubits of the system, where +$0 \leq i \leq n-1$ (i.e. we start the indexing from $0$), we want to find the indices of the states of the +computational basis whose labels have a $1$ at the ith spot (counting from $0$). For instance, +if $n=3$ and $i=2$ then $1$,$3$,$5$,$7$ are the indices of the elements of the computational basis +with a $1$ at the 2nd spot, namely $|001\rangle$,$|011\rangle$,$|101\rangle$,$|111\rangle$. To achieve that we define the +predicate @{term "select_index"} below. +\ + +definition select_index ::"nat \ nat \ nat \ bool" where +"select_index n i j \ (i\n-1) \ (j\2^n - 1) \ (j mod 2^(n-i) \ 2^(n-1-i))" + +lemma select_index_union: + "{k| k::nat. select_index n i k} \ {k| k::nat. (k<2^n) \ \ select_index n i k} = {0..<2^n::nat}" +proof + have "{k |k. select_index n i k} \ {0..<2 ^ n}" + proof + fix x::nat assume "x \ {k |k. select_index n i k}" + then show "x \ {0..<2^n}" + using select_index_def + by (metis (no_types, lifting) atLeastLessThan_iff diff_diff_cancel diff_is_0_eq' diff_le_mono2 +le_less_linear le_numeral_extra(2) mem_Collect_eq one_le_numeral one_le_power select_index_def zero_order(1)) + qed + moreover have "{k |k. k<2 ^ n \ \ select_index n i k} \ {0..<2 ^ n}" by auto + ultimately show "{k |k. select_index n i k} \ {k |k. k<2 ^ n \ \ select_index n i k} \ {0..<2 ^ n}" by simp +next + show "{0..<2 ^ n} \ {k |k. select_index n i k} \ {k |k. k<2 ^ n \ \ select_index n i k}" by auto +qed + +lemma select_index_inter: + "{k| k::nat. select_index n i k} \ {k| k::nat. (k<2^n) \ \ select_index n i k} = {}" by auto + +lemma outcomes_sum [simp]: + fixes f :: "nat \ real" + shows + "(\j\{k| k::nat. select_index n i k}. (f j)) + + (\j\{k| k::nat. (k<2^n) \ \ select_index n i k}. (f j)) = + (\j\{0..<2^n::nat}. (f j))" +proof - + have "{k| k::nat. select_index n i k} \ {0..<2^n::nat}" + using select_index_union by blast + then have "finite {k| k::nat. select_index n i k}" + using rev_finite_subset by blast + moreover have "{k| k::nat. (k<2^n) \ \ select_index n i k} \ {0..<2^n::nat}" + using select_index_union by blast + then have "finite {k| k::nat. (k<2^n) \ \ select_index n i k}" + using rev_finite_subset by blast + ultimately have "(\j\{k| k::nat. select_index n i k}\{k| k::nat. (k<2^n) \ \ select_index n i k}. (f j)) = + (\j\{k| k::nat. select_index n i k}. (f j)) + + (\j\{k| k::nat. (k<2^n) \ \ select_index n i k}. (f j)) - + (\j\{k| k::nat. select_index n i k}\{k| k::nat. (k<2^n) \ \ select_index n i k}. (f j))" + using sum_Un by blast + then have "(\j\{0..<2^n::nat}. (f j)) = + (\j\{k| k::nat. select_index n i k}. (f j)) + + (\j\{k| k::nat. (k<2^n) \ \ select_index n i k}. (f j)) - + (\j\{}. (f j))" + using select_index_union select_index_inter by simp + thus ?thesis by simp +qed + +text \ +Given a state v of a n-qbit system, we compute the probability that a measure +of qubit i has the outcome 1. +\ + +definition prob1 ::"nat \ complex mat \ nat \ real" where +"prob1 n v i \ \j\{k| k::nat. select_index n i k}. (cmod(v $$ (j,0)))\<^sup>2" + +definition prob0 ::"nat \ complex mat \ nat \ real" where +"prob0 n v i \ \j\{k| k::nat. (k<2^n) \ \ select_index n i k}. (cmod(v $$ (j,0)))\<^sup>2" + +lemma + shows prob1_geq_zero:"prob1 n v i \ 0" and prob0_geq_zero:"prob0 n v i \ 0" +proof - + have "(\j\{k| k::nat. select_index n i k}. (cmod(v $$ (j,0)))\<^sup>2) \ + (\j\{k| k::nat. select_index n i k}. (0::real))" + by (simp add: sum_nonneg) + then have "(\j\{k| k::nat. select_index n i k}. (cmod(v $$ (j,0)))\<^sup>2) \ 0" by simp + thus "prob1 n v i \ 0" + using prob1_def by simp +next + have "(\j\{k| k::nat. (k < 2 ^ n) \ \ select_index n i k}. (cmod(v $$ (j,0)))\<^sup>2) \ + (\j\{k| k::nat. (k < 2 ^ n) \ \ select_index n i k}. (0::real))" + by (simp add: sum_nonneg) + then have "(\j\{k| k::nat. (k < 2 ^ n) \ \ select_index n i k}. (cmod(v $$ (j,0)))\<^sup>2) \ 0" by simp + thus "prob0 n v i \ 0" + using prob0_def by simp +qed + +lemma prob_sum_is_one [simp]: + assumes "state n v" + shows "prob1 n v i + prob0 n v i = 1" +proof- + have "prob1 n v i + prob0 n v i = (\j\{0..<2^n::nat}. (cmod(v $$ (j,0)))\<^sup>2)" + using prob1_def prob0_def outcomes_sum by simp + also have "\ = \col v 0\\<^sup>2" + using cpx_vec_length_def assms state_def atLeast0LessThan by fastforce + finally show ?thesis + using assms state_def by simp +qed + +lemma + assumes "state n v" + shows prob1_leq_one:"prob1 n v i \ 1" and prob0_leq_one:"prob0 n v i \ 1" + apply(metis assms le_add_same_cancel1 prob0_geq_zero prob_sum_is_one) + apply(metis assms le_add_same_cancel2 prob1_geq_zero prob_sum_is_one) + done + +lemma prob0_is_prob: + assumes "state n v" + shows "prob0 n v i \ 0 \ prob0 n v i \ 1" + by (simp add: assms prob0_geq_zero prob0_leq_one) + +lemma prob1_is_prob: + assumes "state n v" + shows "prob1 n v i \ 0 \ prob1 n v i \ 1" + by (simp add: assms prob1_geq_zero prob1_leq_one) + +text \Below we give the new state of a n-qubits system after a measurement of the ith qubit gave 0.\ + +definition post_meas0 ::"nat \ complex mat \ nat \ complex mat" where +"post_meas0 n v i \ + of_real(1/sqrt(prob0 n v i)) \\<^sub>m |vec (2^n) (\j. if \ select_index n i j then v $$ (j,0) else 0)\" + +text \ +Note that a division by 0 never occurs. Indeed, if @{text "sqrt(prob0 n v i)"} would be 0 then +@{text "prob0 n v i"} would be 0 and it would mean that the measurement of the ith qubit gave 1. +\ + +lemma post_meas0_is_state [simp]: + assumes "state n v" and "prob0 n v i \ 0" + shows "state n (post_meas0 n v i)" +proof - + have "(\j\{0..<2^n::nat}. (cmod (if \ select_index n i j then v $$ (j,0) else 0))\<^sup>2) = + (\j\{k| k::nat. select_index n i k}. (cmod (if \ select_index n i j then v $$ (j,0) else 0))\<^sup>2) + + (\j\{k| k::nat. (k<2^n) \ \ select_index n i k}. (cmod (if \ select_index n i j then v $$ (j,0) else 0))\<^sup>2)" + using outcomes_sum[of "\j. (cmod (if \ select_index n i j then v $$ (j,0) else 0))\<^sup>2" n i] by simp + moreover have "(\j\{k| k::nat. (k<2^n) \ \ select_index n i k}. (cmod (if \ select_index n i j then v $$ (j,0) else 0))\<^sup>2) = + prob0 n v i" + by(simp add: prob0_def) + ultimately have "\vec (2 ^ n) (\j. if \ select_index n i j then v $$ (j,0) else 0)\ = sqrt(prob0 n v i)" + using lessThan_atLeast0 by (simp add: cpx_vec_length_def) + moreover have "\col (complex_of_real (1/sqrt (prob0 n v i)) \\<^sub>m |vec (2^n) (\j. if \ select_index n i j then v $$ (j,0) else 0)\) 0\ = + (1/sqrt (prob0 n v i)) * \vec (2^n) (\j. if \ select_index n i j then v $$ (j,0) else 0)\" + using prob0_geq_zero smult_vec_length_bis by(metis (no_types, lifting) real_sqrt_ge_0_iff zero_le_divide_1_iff) + ultimately show ?thesis + using state_def post_meas0_def by (simp add: ket_vec_def post_meas0_def assms(2)) +qed + +text \Below we give the new state of a n-qubits system after a measurement of the ith qubit gave 1.\ + +definition post_meas1 ::"nat \ complex mat \ nat \ complex mat" where +"post_meas1 n v i \ + of_real(1/sqrt(prob1 n v i)) \\<^sub>m |vec (2^n) (\j. if select_index n i j then v $$ (j,0) else 0)\" + +text \ +Note that a division by 0 never occurs. Indeed, if @{text "sqrt(prob1 n v i)"} would be 0 then +@{text "prob1 n v i"} would be 0 and it would mean that the measurement of the ith qubit gave 0. +\ + +lemma post_meas_1_is_state [simp]: + assumes "state n v" and "prob1 n v i \ 0" + shows "state n (post_meas1 n v i)" +proof - + have "(\j\{0..<2^n::nat}. (cmod (if select_index n i j then v $$ (j,0) else 0))\<^sup>2) = + (\j\{k| k::nat. select_index n i k}. (cmod (if select_index n i j then v $$ (j,0) else 0))\<^sup>2) + + (\j\{k| k::nat. (k<2^n) \ \ select_index n i k}. (cmod (if select_index n i j then v $$ (j,0) else 0))\<^sup>2)" + using outcomes_sum[of "\j. (cmod (if select_index n i j then v $$ (j,0) else 0))\<^sup>2" n i] by simp + then have "\vec (2^n) (\j. if select_index n i j then v $$ (j,0) else 0)\ = sqrt(prob1 n v i)" + using lessThan_atLeast0 by (simp add: cpx_vec_length_def prob1_def) + moreover have "\col(complex_of_real (1/sqrt (prob1 n v i)) \\<^sub>m |vec (2^n) (\j. if select_index n i j then v $$ (j,0) else 0)\) 0\ = + (1/sqrt(prob1 n v i)) * \vec (2^n) (\j. if select_index n i j then v $$ (j,0) else 0)\" + using prob1_geq_zero smult_vec_length_bis + by (metis (no_types, lifting) real_sqrt_ge_0_iff zero_le_divide_1_iff) + ultimately have "\col(complex_of_real (1/sqrt (prob1 n v i)) \\<^sub>m |vec (2^n) (\j. if select_index n i j then v $$ (j,0) else 0)\) 0\ += (1/sqrt(prob1 n v i)) * sqrt(prob1 n v i)" by simp + thus ?thesis + using state_def post_meas1_def by (simp add: ket_vec_def post_meas1_def assms(2)) +qed + +text \ +The measurement operator below takes a number of qubits n, a state v of a n-qubits system, a number +i corresponding to the index (starting from 0) of one qubit among the n-qubits, and it computes a list +whose first (resp. second) element is the pair made of the probability that the outcome of the measurement +of the ith qubit is 0 (resp. 1) and the corresponding post-measurement state of the system. +Of course, note that i should be strictly less than n and v should be a state of dimension n, i.e. +state n v should hold". +\ + +definition meas ::"nat \ complex mat \ nat \ _list" where +"meas n v i \ [(prob0 n v i, post_meas0 n v i), (prob1 n v i, post_meas1 n v i)]" + +text \ +We want to determine the probability that the first n qubits of an n+1 qubit system are 0. +For this we need to find the indices of the states of the computational basis whose labels do +not have a 1 at spot $i=0,...,n$. +\ + +definition prob0_fst_qubits:: "nat \ complex Matrix.mat \ real" where +"prob0_fst_qubits n v \ +\j\{k| k::nat. (k<2^(n+1)) \ (\i\{0.. select_index (n+1) i k)}. (cmod(v $$ (j,0)))\<^sup>2" + +lemma select_index_div_2: + fixes n i j::"nat" + assumes "i < 2^(n+1)" and "j i div 2 mod 2^(n-j) \ 2^(n-j) \ i mod 2^(n+1-j)" + proof- + define a::nat where a0:"a = i div 2 mod 2^(n-j)" + assume "2^(n-Suc j) \ a" + then have "2*a + i mod 2 \ 2^(n-(Suc j)+1)" by simp + then have f0:"2*a + i mod 2 \ 2^(n-j)" + by (metis Suc_diff_Suc Suc_eq_plus1 assms(2)) + have "a < 2^(n-j)" using a0 by simp + then have "2*a + i mod 2 < 2*2^(n-j)" by linarith + then have "2*a + i mod 2 < 2^(n-j+1)" by simp + then have f1:"2*a + i mod 2 < 2^(n+1-j)" + by (metis Nat.add_diff_assoc2 Suc_leD Suc_leI assms(2)) + have "i = 2*(a + 2^(n-j)*(i div 2 div 2^(n-j))) + i mod 2" using a0 by simp + then have "i = 2*a + i mod 2 + 2^(n-j+1)*(i div 2 div 2^(n-j))" by simp + then have "i = 2*a + i mod 2 + 2^(n+1-j)*(i div 2 div 2^(n-j))" + by (metis Nat.add_diff_assoc2 Suc_leD Suc_leI assms(2)) + then have "i mod 2^(n+1-j) = 2*a + i mod 2" + using f1 by (metis mod_if mod_mult_self2) + then show "2^(n-j) \ i mod 2^(n+1-j)" + using f0 by simp + qed + moreover have "2^(n-j) \ i mod 2^(n+1-j) \ 2^(n-Suc j) \ i div 2 mod 2^(n-j)" + proof- + define a::nat where a0:"a = i div 2 mod 2^(n-j)" + assume a1:"2^(n-j) \ i mod 2^(n+1-j)" + have f0:"2^(n-j) = 2^(n-Suc j+1)" + by (metis Suc_diff_Suc Suc_eq_plus1 assms(2)) + have "a < 2^(n-j)" using a0 by simp + then have "2*a + i mod 2 < 2*2^(n-j)" by linarith + then have "2*a + i mod 2 < 2^(n-j+1)" by simp + then have f1:"2*a + i mod 2 < 2^(n+1-j)" + by (metis Nat.add_diff_assoc2 Suc_leD Suc_leI assms(2)) + have "i = 2*(a + 2^(n-j)*(i div 2 div 2^(n-j))) + i mod 2" using a0 by simp + then have "i = 2*a + i mod 2 + 2^(n-j+1)*(i div 2 div 2^(n-j))" by simp + then have "i = 2*a + i mod 2 + 2^(n+1-j)*(i div 2 div 2^(n-j))" + by (metis Nat.add_diff_assoc2 Suc_leD Suc_leI assms(2)) + then have "i mod 2^(n+1-j) = 2*a + i mod 2" + using f1 by (metis mod_if mod_mult_self2) + then have "2*a + i mod 2 \ 2^(n-j)" + using a1 by simp + then have "(2*a + i mod 2) div 2 \ (2^(n-j)) div 2" + using div_le_mono by blast + then show "2^(n-Suc j) \ a" by (simp add: f0) + qed + ultimately show ?thesis + using select_index_def assms by auto +qed + +lemma select_index_suc_even: + fixes n k i:: nat + assumes "k < 2^n" and "select_index n i k" + shows "select_index (Suc n) i (2*k)" +proof- + have "select_index n i k = select_index n i (2*k div 2)" by simp + moreover have "\ = select_index (Suc n) i (2*k)" + proof- + have "i < n" using assms(2) select_index_def + by (metis (no_types, hide_lams) Suc_eq_plus1 assms(1) calculation diff_diff_left diff_le_self +diff_self_eq_0 div_by_1 le_0_eq le_eq_less_or_eq less_imp_diff_less mod_div_trivial mult.left_neutral mult_eq_0_iff mult_le_mono1 not_less plus_1_eq_Suc power_0 semiring_normalization_rules(7)) + thus ?thesis + using select_index_div_2 assms(1) select_index_def by(metis Suc_1 Suc_eq_plus1 Suc_mult_less_cancel1 power_Suc) + qed + ultimately show "select_index (Suc n) i (2*k)" + using assms(2) by simp +qed + +lemma select_index_suc_odd: + fixes n k i:: nat + assumes "k \ 2^n -1" and "select_index n i k" + shows "select_index (Suc n) i (2*k+1)" +proof- + have "((2*k+1) mod 2^(Suc n - i) \ 2^(n - i)) = +(((2*k+1) div 2) mod 2^(n - i) \ 2^(n-1-i))" + proof- + have "2*k+1 < 2^(n + 1)" + using assms(1) + by (smt Suc_1 Suc_eq_plus1 Suc_le_lessD Suc_le_mono add_Suc_right distrib_left_numeral le_add_diff_inverse mult_le_mono2 nat_mult_1_right one_le_numeral one_le_power plus_1_eq_Suc power_add power_one_right) + moreover have "i < n" + using assms(2) select_index_def + by (metis (no_types, hide_lams) add_cancel_left_left add_diff_inverse_nat diff_le_self div_by_1 le_antisym less_le_trans less_one mod_div_trivial not_le power_0) + ultimately show ?thesis + using select_index_div_2[of "2*k+1" "n" i] select_index_def + by (metis Nat.le_diff_conv2 Suc_eq_plus1 Suc_leI assms(2) diff_Suc_1 less_imp_le less_power_add_imp_div_less one_le_numeral one_le_power power_one_right) + qed + moreover have "\ = (k mod 2^(n - i) \ 2^(n-1-i))" by simp + ultimately show ?thesis + proof- + have "i \ Suc n -1" using assms(2) select_index_def by auto + moreover have "2*k+1 \ 2^(Suc n)-1" + using assms(1) by (smt Suc_diff_1 Suc_eq_plus1 add_diff_cancel_right' diff_Suc_diff_eq2 diff_diff_left diff_is_0_eq diff_mult_distrib2 le_add2 mult_2 mult_Suc_right plus_1_eq_Suc pos2 power_Suc zero_less_power) + ultimately show ?thesis + using select_index_def + by (metis \(2 ^ (n - 1 - i) \ (2 * k + 1) div 2 mod 2 ^ (n - i)) = (2 ^ (n - 1 - i) \ k mod 2 ^ (n - i))\ \(2 ^ (n - i) \ (2 * k + 1) mod 2 ^ (Suc n - i)) = (2 ^ (n - 1 - i) \ (2 * k + 1) div 2 mod 2 ^ (n - i))\ assms(2) diff_Suc_1) + qed +qed + +lemma aux_range: + fixes k:: nat + assumes "k < 2^(Suc n + 1)" and "k \ 2" + shows "k = 2 \ k = 3 \ (\l. l\2 \ l\2^(n+1)-1 \ (k = 2*l \ k = 2*l + 1))" +proof(rule disjCI) + assume "\ (k = 3 \ (\l\2. l \ 2^(n + 1) - 1 \ (k = 2 * l \ k = 2 * l + 1)))" + have "k > 3 \ (\l\2. l \ 2^(n + 1) - 1 \ (k = 2 * l \ k = 2 * l + 1))" + proof + assume asm:"k > 3" + have "even k \ odd k" by simp + then obtain l where "k = 2*l \ k = 2*l+1" by (meson evenE oddE) + moreover have "l \ 2" + using asm calculation by linarith + moreover have "l \ 2^(n+1) - 1" + using assms(1) by (metis Suc_diff_1 Suc_eq_plus1 calculation(1) dvd_triv_left even_Suc_div_two less_Suc_eq_le less_power_add_imp_div_less nonzero_mult_div_cancel_left pos2 power_one_right zero_less_power zero_neq_numeral) + ultimately show "\l\2. l \ 2^(n + 1) - 1 \ (k = 2 * l \ k = 2 * l + 1)" by auto + qed + then have "k \ 2" + using \\ (k = 3 \ (\l\2. l \ 2 ^ (n + 1) - 1 \ (k = 2 * l \ k = 2 * l + 1)))\ less_Suc_eq_le by auto + thus "k = 2" + using assms(2) by simp +qed + +lemma select_index_with_1: + fixes n:: nat + assumes "n \ 1" + shows "\k. k < 2^(n+1) \ k \ 2 \ (\ik< 2^(1+1). 2 \ k \ (\i<1. select_index (1+1) i k)" + proof- + have "select_index 2 0 2 = True" + using select_index_def by simp + moreover have "select_index 2 0 3" + using select_index_def by simp + ultimately show ?thesis + by (metis Suc_leI add_Suc_shift le_eq_less_or_eq mult_2 not_less one_add_one one_plus_numeral +plus_1_eq_Suc power.simps(2) power_one_right semiring_norm(3) zero_less_one_class.zero_less_one) + qed +next + show "\n. 1 \ n \ + \k < 2^(n+1). 2 \ k \ (\i + \k < 2^(Suc n + 1). 2 \ k \ (\i 1" and IH:"\k < 2^(n+1). 2 \ k \ (\ii 2" and "k \ 2^(n + 1)-1" for k:: nat + proof- + obtain i where "i2 \ k\ \k \ 2 ^ (n + 1) - 1\ diff_zero le_imp_less_Suc pos2 zero_less_power) + then have "select_index (Suc n +1) i (2*k)" + using select_index_suc_even + by (metis One_nat_def Suc_diff_Suc add.commute diff_zero le_imp_less_Suc plus_1_eq_Suc pos2 that(2) zero_less_power) + thus ?thesis + using \i < n\ less_SucI by blast + qed + moreover have "\i 2" and "k \ 2^(n + 1)-1" for k:: nat + proof- + obtain i where "i2 \ k\ \k \ 2 ^ (n + 1) - 1\ diff_zero le_imp_less_Suc pos2 zero_less_power) + then have "select_index (Suc n +1) i (2*k+1)" + using select_index_suc_odd that(2) by simp + thus ?thesis + using \i < n\ less_SucI by blast + qed + ultimately show "\k< 2^(Suc n + 1). 2 \ k \ (\i (\i\{0.. select_index (n+1) i k)} = {0,1}" +proof(induct n) + case 0 + show "{k |k. k < 2^(0+1) \ (\i\{0..<0}. \ select_index (0+1) i k)} = {0,1}" by auto +next + case (Suc n) + show "\n. {k |k. k < 2^(n+1) \ (\i\{0.. select_index (n+1) i k)} = {0,1} \ + {k |k. k < 2^(Suc n + 1) \ (\i\{0.. select_index (Suc n + 1) i k)} = + {0, 1}" + proof- + fix n + assume IH: "{k |k. k < 2^(n+1) \ (\i\{0.. select_index (n+1) i k)} = {0,1}" + then have "{0,1} \ {k |k. k < 2^(Suc n + 1) \ (\i\{0.. select_index (Suc n + 1) i k)}" + proof- + have "k < 2^(n+1) \ k < 2^(Suc n + 1)" for k::nat by simp + moreover have "(\i\{0.. select_index (n+1) i 0) \ (\i\{0.. select_index (n+1) i 1)" + using IH by auto + then have "(\i\{0.. select_index (Suc n +1) i 0) \ (\i\{0.. select_index (Suc n +1) i 1)" + using select_index_suc_odd[of 0 "n+1"] Suc_eq_plus1 + by (smt One_nat_def Suc_1 add_Suc_shift add_diff_cancel_right' atLeastLessThan_iff diff_diff_cancel +le_eq_less_or_eq less_Suc_eq linorder_not_le mod_less nat_power_eq_Suc_0_iff select_index_def zero_less_power) + moreover have "select_index (Suc n + 1) n 0 = False" using select_index_def by simp + moreover have "select_index (Suc n + 1) n 1 = False" using select_index_def by simp + ultimately show ?thesis + by (smt One_nat_def Suc_1 Suc_eq_plus1 Suc_lessI atLeast0_lessThan_Suc empty_iff insertE +mem_Collect_eq nat.simps(1) nat_power_eq_Suc_0_iff pos2 subsetI zero_less_power) + qed + moreover have "{k |k. k < 2^(Suc n + 1) \ (\i\{0.. select_index (Suc n + 1) i k)} \ {0,1}" + proof- + have "\k<2^(Suc n +1). k \ 2 \ (\i select_index (Suc n +1) i k = False)" + using select_index_with_1[of "Suc n"] by (metis Suc_eq_plus1 add.commute le_add1) + thus ?thesis by auto + qed + ultimately show "{k |k. k<2^(Suc n + 1) \ (\i\{0.. select_index (Suc n +1) i k)} = {0,1}" by auto + qed +qed + +lemma prob0_fst_qubits_eq: + fixes n:: nat + shows "prob0_fst_qubits n v = (cmod(v $$ (0,0)))\<^sup>2 + (cmod(v $$ (1,0)))\<^sup>2" +proof- + have "prob0_fst_qubits n v = (\j\{k| k::nat. (k<2^(n+1)) \ (\i\{0.. select_index (n+1) i k)}. (cmod(v $$ (j,0)))\<^sup>2)" + using prob0_fst_qubits_def by simp + moreover have "\ = (\j\{0,1}. (cmod(v $$ (j,0)))\<^sup>2)" + using prob0_fst_qubits_index by simp + finally show ?thesis by simp +qed + +(* Below in iter_post_meas0, the first argument n corresponds to the number of qubits of the system +, and the second argument m corresponds to the number of qubits that have been measured. *) +primrec iter_post_meas0:: "nat \ nat \ complex Matrix.mat \ complex Matrix.mat" where + "iter_post_meas0 n 0 v = v" +| "iter_post_meas0 n (Suc m) v = post_meas0 n (iter_post_meas0 n m v) m" + +(* iter_prob0 outputs the probability that successive measurements of the first m qubits +(out of n qubits in the system) give m zeros. *) +definition iter_prob0:: "nat \ nat \ complex Matrix.mat \ real" where + "iter_prob0 n m v = (\i 1" + shows "iter_prob0 (Suc n) n v = prob0_fst_qubits n v" +*) + +subsection \Measurements with Bell States\ + +text \ +A Bell state is a remarkable state. Indeed, if one makes one measure, either of the first or the second +qubit, then one gets either $0$ with probability $1/2$ or $1$ with probability $1/2$. Moreover, in the case of +two successive measurements of the first and second qubit, the outcomes are correlated. +Indeed, in the case of @{text "|\\<^sub>0\<^sub>0\"} or @{text "|\\<^sub>1\<^sub>0\"} (resp. @{text "|\\<^sub>0\<^sub>1\"} or @{text "|\\<^sub>1\<^sub>1\"}) if +one measures the second qubit after a measurement of the first qubit (or the other way around) then +one gets the same outcomes (resp. opposite outcomes), i.e. for instance the probability of measuring +$0$ for the second qubit after a measure with outcome $0$ for the first qubit is $1$ (resp. $0$). +\ + +lemma prob0_bell_fst [simp]: + assumes "v = |\\<^sub>0\<^sub>0\ \ v = |\\<^sub>0\<^sub>1\ \ v = |\\<^sub>1\<^sub>0\ \ v = |\\<^sub>1\<^sub>1\" + shows "prob0 2 v 0 = 1/2" +proof - + have set_0 [simp]:"{k| k::nat. (k<4) \ \ select_index 2 0 k} = {0,1}" + using select_index_def by auto + have "v = |\\<^sub>0\<^sub>0\ \ prob0 2 v 0 = 1/2" + proof - + fix v assume asm:"v = |\\<^sub>0\<^sub>0\" + show "prob0 2 v 0 = 1/2" + proof - + have "prob0 2 v 0 = (\j\{k| k::nat. (k<4) \ \ select_index 2 0 k}. (cmod(bell00 $$ (j,0)))\<^sup>2)" + by (auto simp: prob0_def asm) + also have "\ = (\j\{0,1}. (cmod(bell00 $$ (j,0)))\<^sup>2)" + using set_0 by simp + also have "\ = (cmod(1/sqrt(2)))\<^sup>2 + (cmod(0))\<^sup>2" + by (auto simp: bell00_def ket_vec_def) + finally show ?thesis by(simp add: cmod_def power_divide) + qed + qed + moreover have "v = |\\<^sub>0\<^sub>1\ \ prob0 2 v 0 = 1/2" + proof - + fix v assume asm:"v = |\\<^sub>0\<^sub>1\" + show "prob0 2 v 0 = 1/2" + proof - + have "prob0 2 v 0 = (\j\{k| k::nat. (k<4) \ \ select_index 2 0 k}. (cmod(bell01 $$ (j,0)))\<^sup>2)" + by (auto simp: prob0_def asm) + also have "\ = (\j\{0,1}. (cmod(bell01 $$ (j,0)))\<^sup>2)" + using set_0 by simp + also have "\ = (cmod(0))\<^sup>2 + (cmod(1/sqrt(2)))\<^sup>2" + by (auto simp: bell01_def ket_vec_def) + finally show ?thesis by(simp add: cmod_def power_divide) + qed + qed + moreover have "v = |\\<^sub>1\<^sub>0\ \ prob0 2 v 0 = 1/2" + proof - + fix v assume asm:"v = |\\<^sub>1\<^sub>0\" + show "prob0 2 v 0 = 1/2" + proof - + have "prob0 2 v 0 = (\j\{k| k::nat. (k<4) \ \ select_index 2 0 k}. (cmod(bell10 $$ (j,0)))\<^sup>2)" + by (auto simp: prob0_def asm) + also have "\ = (\j\{0,1}. (cmod(bell10 $$ (j,0)))\<^sup>2)" + using set_0 by simp + also have "\ = (cmod(1/sqrt(2)))\<^sup>2 + (cmod(0))\<^sup>2" + by (auto simp: bell10_def ket_vec_def) + finally show ?thesis by(simp add: cmod_def power_divide) + qed + qed + moreover have "v = |\\<^sub>1\<^sub>1\ \ prob0 2 v 0 = 1/2" + proof - + fix v assume asm:"v = |\\<^sub>1\<^sub>1\" + show "prob0 2 v 0 = 1/2" + proof - + have "prob0 2 v 0 = (\j\{k| k::nat. (k<4) \ \ select_index 2 0 k}. (cmod(bell11 $$ (j,0)))\<^sup>2)" + by (auto simp: prob0_def asm) + also have "\ = (\j\{0,1}. (cmod(bell11 $$ (j,0)))\<^sup>2)" + using set_0 by simp + also have "\ = (cmod(0))\<^sup>2 + (cmod(1/sqrt(2)))\<^sup>2" + by (auto simp: bell11_def ket_vec_def) + finally show ?thesis by(simp add: cmod_def power_divide) + qed + qed + ultimately show ?thesis using assms by auto +qed + +lemma prob_1_bell_fst [simp]: + assumes "v = |\\<^sub>0\<^sub>0\ \ v = |\\<^sub>0\<^sub>1\ \ v = |\\<^sub>1\<^sub>0\ \ v = |\\<^sub>1\<^sub>1\" + shows "prob1 2 v 0 = 1/2" +proof - + have set_0 [simp]:"{k| k::nat. select_index 2 0 k} = {2,3}" + using select_index_def by auto + have "v = |\\<^sub>0\<^sub>0\ \ prob1 2 v 0 = 1/2" + proof - + fix v assume asm:"v = |\\<^sub>0\<^sub>0\" + show "prob1 2 v 0 = 1/2" + proof - + have "prob1 2 v 0 = (\j\{k| k::nat. select_index 2 0 k}. (cmod(bell00 $$ (j,0)))\<^sup>2)" + by (auto simp: prob1_def asm) + also have "\ = (\j\{2,3}. (cmod(bell00 $$ (j,0)))\<^sup>2)" + using set_0 by simp + also have "\ = (cmod(1/sqrt(2)))\<^sup>2 + (cmod(0))\<^sup>2" + by (auto simp: bell00_def ket_vec_def) + finally show ?thesis by(simp add: cmod_def power_divide) + qed + qed + moreover have "v = |\\<^sub>0\<^sub>1\ \ prob1 2 v 0 = 1/2" + proof - + fix v assume asm:"v = |\\<^sub>0\<^sub>1\" + show "prob1 2 v 0 = 1/2" + proof - + have "prob1 2 v 0 = (\j\{k| k::nat. select_index 2 0 k}. (cmod(bell01 $$ (j,0)))\<^sup>2)" + by (auto simp: prob1_def asm) + also have "\ = (\j\{2,3}. (cmod(bell01 $$ (j,0)))\<^sup>2)" + using set_0 by simp + also have "\ = (cmod(0))\<^sup>2 + (cmod(1/sqrt(2)))\<^sup>2" + by (auto simp: bell01_def ket_vec_def) + finally show ?thesis by(simp add: cmod_def power_divide) + qed + qed + moreover have "v = |\\<^sub>1\<^sub>0\ \ prob1 2 v 0 = 1/2" + proof - + fix v assume asm:"v = |\\<^sub>1\<^sub>0\" + show "prob1 2 v 0 = 1/2" + proof - + have "prob1 2 v 0 = (\j\{k| k::nat. select_index 2 0 k}. (cmod(bell10 $$ (j,0)))\<^sup>2)" + by (auto simp: prob1_def asm) + also have "\ = (\j\{2,3}. (cmod(bell10 $$ (j,0)))\<^sup>2)" + using set_0 by simp + also have "\ = (cmod(1/sqrt(2)))\<^sup>2 + (cmod(0))\<^sup>2" + by (auto simp: bell10_def ket_vec_def) + finally show ?thesis by(simp add: cmod_def power_divide) + qed + qed + moreover have "v = |\\<^sub>1\<^sub>1\ \ prob1 2 v 0 = 1/2" + proof - + fix v assume asm:"v = |\\<^sub>1\<^sub>1\" + show "prob1 2 v 0 = 1/2" + proof - + have "prob1 2 v 0 = (\j\{k| k::nat. select_index 2 0 k}. (cmod(bell11 $$ (j,0)))\<^sup>2)" + by (auto simp: prob1_def asm) + also have "\ = (\j\{2,3}. (cmod(bell11 $$ (j,0)))\<^sup>2)" + using set_0 by simp + also have "\ = (cmod(0))\<^sup>2 + (cmod(1/sqrt(2)))\<^sup>2" + by (auto simp: bell11_def ket_vec_def) + finally show ?thesis by(simp add: cmod_def power_divide) + qed + qed + ultimately show ?thesis using assms by auto +qed + +lemma prob0_bell_snd [simp]: + assumes "v = |\\<^sub>0\<^sub>0\ \ v = |\\<^sub>0\<^sub>1\ \ v = |\\<^sub>1\<^sub>0\ \ v = |\\<^sub>1\<^sub>1\" + shows "prob0 2 v 1 = 1/2" +proof - + have set_0 [simp]:"{k| k::nat. (k<4) \ \ select_index 2 1 k} = {0,2}" + by (auto simp: select_index_def) + (metis Suc_le_mono add_Suc add_Suc_right le_numeral_extra(3) less_antisym mod_Suc_eq mod_less + neq0_conv not_mod2_eq_Suc_0_eq_0 numeral_2_eq_2 numeral_Bit0 one_add_one one_mod_two_eq_one one_neq_zero) + have "v = |\\<^sub>0\<^sub>0\ \ prob0 2 v 1 = 1/2" + proof - + fix v assume asm:"v = |\\<^sub>0\<^sub>0\" + show "prob0 2 v 1 = 1/2" + proof - + have "prob0 2 v 1 = (\j\{k| k::nat. (k<4) \ \ select_index 2 1 k}. (cmod(bell00 $$ (j,0)))\<^sup>2)" + by (auto simp: prob0_def asm) + also have "\ = (\j\{0,2}. (cmod(bell00 $$ (j,0)))\<^sup>2)" + using set_0 by simp + also have "\ = (cmod(1/sqrt(2)))\<^sup>2 + (cmod(0))\<^sup>2" + by (auto simp: bell00_def ket_vec_def) + finally show ?thesis by(simp add: cmod_def power_divide) + qed + qed + moreover have "v = |\\<^sub>0\<^sub>1\ \ prob0 2 v 1 = 1/2" + proof - + fix v assume asm:"v = |\\<^sub>0\<^sub>1\" + show "prob0 2 v 1 = 1/2" + proof - + have "prob0 2 v 1 = (\j\{k| k::nat. (k<4) \ \ select_index 2 1 k}. (cmod(bell01 $$ (j,0)))\<^sup>2)" + by (auto simp: prob0_def asm) + also have "\ = (\j\{0,2}. (cmod(bell01 $$ (j,0)))\<^sup>2)" + using set_0 by simp + also have "\ = (cmod(0))\<^sup>2 + (cmod(1/sqrt(2)))\<^sup>2" + by (auto simp: bell01_def ket_vec_def) + finally show ?thesis by(simp add: cmod_def power_divide) + qed + qed + moreover have "v = |\\<^sub>1\<^sub>0\ \ prob0 2 v 1 = 1/2" + proof - + fix v assume asm:"v = |\\<^sub>1\<^sub>0\" + show "prob0 2 v 1 = 1/2" + proof - + have "prob0 2 v 1 = (\j\{k| k::nat. (k<4) \ \ select_index 2 1 k}. (cmod(bell10 $$ (j,0)))\<^sup>2)" + by (auto simp: prob0_def asm) + also have "\ = (\j\{0,2}. (cmod(bell10 $$ (j,0)))\<^sup>2)" + using set_0 by simp + also have "\ = (cmod(1/sqrt(2)))\<^sup>2 + (cmod(0))\<^sup>2" + by (auto simp: bell10_def ket_vec_def) + finally show ?thesis by(simp add: cmod_def power_divide) + qed + qed + moreover have "v = |\\<^sub>1\<^sub>1\ \ prob0 2 v 1 = 1/2" + proof - + fix v assume asm:"v = |\\<^sub>1\<^sub>1\" + show "prob0 2 v 1 = 1/2" + proof - + have "prob0 2 v 1 = (\j\{k| k::nat. (k<4) \ \ select_index 2 1 k}. (cmod(bell11 $$ (j,0)))\<^sup>2)" + by (auto simp: prob0_def asm) + also have "\ = (\j\{0,2}. (cmod(bell11 $$ (j,0)))\<^sup>2)" + using set_0 by simp + also have "\ = (cmod(0))\<^sup>2 + (cmod(1/sqrt(2)))\<^sup>2" + by (auto simp: bell11_def ket_vec_def) + finally show ?thesis by(simp add: cmod_def power_divide) + qed + qed + ultimately show ?thesis using assms by auto +qed + +lemma prob_1_bell_snd [simp]: + assumes "v = |\\<^sub>0\<^sub>0\ \ v = |\\<^sub>0\<^sub>1\ \ v = |\\<^sub>1\<^sub>0\ \ v = |\\<^sub>1\<^sub>1\" + shows "prob1 2 v 1 = 1/2" +proof - + have set_0:"{k| k::nat. select_index 2 1 k} = {1,3}" + by (auto simp: select_index_def) + (metis Suc_le_lessD le_SucE le_less mod2_gr_0 mod_less mod_self numeral_2_eq_2 numeral_3_eq_3) + have "v = |\\<^sub>0\<^sub>0\ \ prob1 2 v 1 = 1/2" + proof - + fix v assume asm:"v = |\\<^sub>0\<^sub>0\" + show "prob1 2 v 1 = 1/2" + proof - + have "prob1 2 v 1 = (\j\{k| k::nat. select_index 2 1 k}. (cmod(bell00 $$ (j,0)))\<^sup>2)" + by (auto simp: prob1_def asm) + also have "\ = (\j\{1,3}. (cmod(bell00 $$ (j,0)))\<^sup>2)" + using set_0 by simp + also have "\ = (cmod(1/sqrt(2)))\<^sup>2 + (cmod(0))\<^sup>2" + by (auto simp: bell00_def ket_vec_def) + finally show ?thesis by(simp add: cmod_def power_divide) + qed + qed + moreover have "v = |\\<^sub>0\<^sub>1\ \ prob1 2 v 1 = 1/2" + proof - + fix v assume asm:"v = |\\<^sub>0\<^sub>1\" + show "prob1 2 v 1 = 1/2" + proof - + have "prob1 2 v 1 = (\j\{k| k::nat. select_index 2 1 k}. (cmod(bell01 $$ (j,0)))\<^sup>2)" + by (auto simp: prob1_def asm) + also have "\ = (\j\{1,3}. (cmod(bell01 $$ (j,0)))\<^sup>2)" + using set_0 by simp + also have "\ = (cmod(0))\<^sup>2 + (cmod(1/sqrt(2)))\<^sup>2" + by (auto simp: bell01_def ket_vec_def) + finally show ?thesis by(simp add: cmod_def power_divide) + qed + qed + moreover have "v = |\\<^sub>1\<^sub>0\ \ prob1 2 v 1 = 1/2" + proof - + fix v assume asm:"v = |\\<^sub>1\<^sub>0\" + show "prob1 2 v 1 = 1/2" + proof - + have "prob1 2 v 1 = (\j\{k| k::nat. select_index 2 1 k}. (cmod(bell10 $$ (j,0)))\<^sup>2)" + by (auto simp: prob1_def asm) + also have "\ = (\j\{1,3}. (cmod(bell10 $$ (j,0)))\<^sup>2)" + using set_0 by simp + also have "\ = (cmod(1/sqrt(2)))\<^sup>2 + (cmod(0))\<^sup>2" + by (auto simp: bell10_def ket_vec_def) + finally show ?thesis by(simp add: cmod_def power_divide) + qed + qed + moreover have "v = |\\<^sub>1\<^sub>1\ \ prob1 2 v 1 = 1/2" + proof - + fix v assume asm:"v = |\\<^sub>1\<^sub>1\" + show "prob1 2 v 1 = 1/2" + proof - + have "prob1 2 v 1 = (\j\{k| k::nat. select_index 2 1 k}. (cmod(bell11 $$ (j,0)))\<^sup>2)" + by (auto simp: prob1_def asm) + also have "\ = (\j\{1,3}. (cmod(bell11 $$ (j,0)))\<^sup>2)" + using set_0 by simp + also have "\ = (cmod(0))\<^sup>2 + (cmod(1/sqrt(2)))\<^sup>2" + by (auto simp: bell11_def ket_vec_def) + finally show ?thesis by(simp add: cmod_def power_divide) + qed + qed + ultimately show ?thesis using assms by auto +qed + +lemma post_meas0_bell00_fst [simp]: + "post_meas0 2 |\\<^sub>0\<^sub>0\ 0 = |unit_vec 4 0\" +proof + fix i j::nat assume "i < dim_row |unit_vec 4 0\" and "j < dim_col |unit_vec 4 0\" + then have "i \ {0,1,2,3}" and "j = 0" + by(auto simp add: ket_vec_def) + moreover have "post_meas0 2 |\\<^sub>0\<^sub>0\ 0 $$ (0,0) = |unit_vec 4 0\ $$ (0,0)" + by(simp add: post_meas0_def unit_vec_def select_index_def ket_vec_def real_sqrt_divide) + moreover have "post_meas0 2 |\\<^sub>0\<^sub>0\ 0 $$ (1,0) = |unit_vec 4 0\ $$ (1,0)" + by(simp add: post_meas0_def unit_vec_def select_index_def bell00_def ket_vec_def real_sqrt_divide) + moreover have "post_meas0 2 |\\<^sub>0\<^sub>0\ 0 $$ (2,0) = |unit_vec 4 0\ $$ (2,0)" + by(simp add: post_meas0_def unit_vec_def select_index_def bell00_def ket_vec_def real_sqrt_divide) + moreover have "post_meas0 2 |\\<^sub>0\<^sub>0\ 0 $$ (3,0) = |unit_vec 4 0\ $$ (3,0)" + by(simp add: post_meas0_def unit_vec_def select_index_def bell00_def ket_vec_def real_sqrt_divide) + ultimately show "post_meas0 2 |\\<^sub>0\<^sub>0\ 0 $$ (i,j) = |unit_vec 4 0\ $$ (i,j)" by auto +next + show "dim_row (post_meas0 2 |\\<^sub>0\<^sub>0\ 0) = dim_row |unit_vec 4 0\" + by(auto simp add: post_meas0_def ket_vec_def) + show "dim_col (post_meas0 2 |\\<^sub>0\<^sub>0\ 0) = dim_col |unit_vec 4 0\" + by(auto simp add: post_meas0_def ket_vec_def) +qed + +lemma post_meas0_bell00_snd [simp]: + "post_meas0 2 |\\<^sub>0\<^sub>0\ 1 = |unit_vec 4 0\" +proof + fix i j::nat assume "i < dim_row |unit_vec 4 0\" and "j < dim_col |unit_vec 4 0\" + then have "i \ {0,1,2,3}" and "j = 0" + by(auto simp add: ket_vec_def) + moreover have "post_meas0 2 |\\<^sub>0\<^sub>0\ 1 $$ (0,0) = |unit_vec 4 0\ $$ (0,0)" + by(simp add: post_meas0_def unit_vec_def select_index_def bell00_def ket_vec_def real_sqrt_divide del:One_nat_def) + moreover have "post_meas0 2 |\\<^sub>0\<^sub>0\ 1 $$ (1,0) = |unit_vec 4 0\ $$ (1,0)" + by(simp add: post_meas0_def unit_vec_def select_index_def bell00_def ket_vec_def real_sqrt_divide) + moreover have "post_meas0 2 |\\<^sub>0\<^sub>0\ 1 $$ (2,0) = |unit_vec 4 0\ $$ (2,0)" + by(simp add: post_meas0_def unit_vec_def select_index_def bell00_def ket_vec_def real_sqrt_divide) + moreover have "post_meas0 2 |\\<^sub>0\<^sub>0\ 1 $$ (3,0) = |unit_vec 4 0\ $$ (3,0)" + by(simp add: post_meas0_def unit_vec_def select_index_def bell00_def ket_vec_def real_sqrt_divide) + ultimately show "post_meas0 2 |\\<^sub>0\<^sub>0\ 1 $$ (i,j) = |unit_vec 4 0\ $$ (i,j)" by auto +next + show "dim_row (post_meas0 2 |\\<^sub>0\<^sub>0\ 1) = dim_row |unit_vec 4 0\" + by(auto simp add: post_meas0_def ket_vec_def) + show "dim_col (post_meas0 2 |\\<^sub>0\<^sub>0\ 1) = dim_col |unit_vec 4 0\" + by(auto simp add: post_meas0_def ket_vec_def) +qed + +lemma post_meas0_bell01_fst [simp]: + "post_meas0 2 |\\<^sub>0\<^sub>1\ 0 = |unit_vec 4 1\" +proof + fix i j::nat assume "i < dim_row |unit_vec 4 1\" and "j < dim_col |unit_vec 4 1\" + then have "i \ {0,1,2,3}" and "j = 0" + by(auto simp add: ket_vec_def) + moreover have "post_meas0 2 |\\<^sub>0\<^sub>1\ 0 $$ (0,0) = |unit_vec 4 1\ $$ (0,0)" + by(simp add: post_meas0_def unit_vec_def select_index_def bell01_def ket_vec_def real_sqrt_divide) + moreover have "post_meas0 2 |\\<^sub>0\<^sub>1\ 0 $$ (1,0) = |unit_vec 4 1\ $$ (1,0)" + by(simp add: post_meas0_def unit_vec_def select_index_def bell01_def ket_vec_def real_sqrt_divide) + moreover have "post_meas0 2 |\\<^sub>0\<^sub>1\ 0 $$ (2,0) = |unit_vec 4 1\ $$ (2,0)" + by(simp add: post_meas0_def unit_vec_def select_index_def bell01_def ket_vec_def real_sqrt_divide) + moreover have "post_meas0 2 |\\<^sub>0\<^sub>1\ 0 $$ (3,0) = |unit_vec 4 1\ $$ (3,0)" + by(simp add: post_meas0_def unit_vec_def select_index_def bell01_def ket_vec_def real_sqrt_divide) + ultimately show "post_meas0 2 |\\<^sub>0\<^sub>1\ 0 $$ (i,j) = |unit_vec 4 1\ $$ (i,j)" by auto +next + show "dim_row (post_meas0 2 |\\<^sub>0\<^sub>1\ 0) = dim_row |unit_vec 4 1\" + by(auto simp add: post_meas0_def ket_vec_def) + show "dim_col (post_meas0 2 |\\<^sub>0\<^sub>1\ 0) = dim_col |unit_vec 4 1\" + by(auto simp add: post_meas0_def ket_vec_def) +qed + +lemma post_meas0_bell01_snd [simp]: + "post_meas0 2 |\\<^sub>0\<^sub>1\ 1 = |unit_vec 4 2\" +proof + fix i j::nat assume "i < dim_row |unit_vec 4 2\" and "j < dim_col |unit_vec 4 2\" + then have "i \ {0,1,2,3}" and "j = 0" + by(auto simp add: ket_vec_def) + moreover have "post_meas0 2 |\\<^sub>0\<^sub>1\ 1 $$ (0,0) = |unit_vec 4 2\ $$ (0,0)" + by(simp add: post_meas0_def unit_vec_def select_index_def bell01_def ket_vec_def real_sqrt_divide) + moreover have "post_meas0 2 |\\<^sub>0\<^sub>1\ 1 $$ (1,0) = |unit_vec 4 2\ $$ (1,0)" + by(simp add: post_meas0_def unit_vec_def select_index_def bell01_def ket_vec_def real_sqrt_divide) + moreover have "post_meas0 2 |\\<^sub>0\<^sub>1\ 1 $$ (2,0) = |unit_vec 4 2\ $$ (2,0)" + by(simp add: post_meas0_def unit_vec_def select_index_def bell01_def ket_vec_def real_sqrt_divide del:One_nat_def) + moreover have "post_meas0 2 |\\<^sub>0\<^sub>1\ 1 $$ (3,0) = |unit_vec 4 2\ $$ (3,0)" + by(simp add: post_meas0_def unit_vec_def select_index_def bell01_def ket_vec_def real_sqrt_divide) + ultimately show "post_meas0 2 |\\<^sub>0\<^sub>1\ 1 $$ (i,j) = |unit_vec 4 2\ $$ (i,j)" by auto +next + show "dim_row (post_meas0 2 |\\<^sub>0\<^sub>1\ 1) = dim_row |unit_vec 4 2\" + by(auto simp add: post_meas0_def ket_vec_def) + show "dim_col (post_meas0 2 |\\<^sub>0\<^sub>1\ 1) = dim_col |unit_vec 4 2\" + by(auto simp add: post_meas0_def ket_vec_def) +qed + +lemma post_meas0_bell10_fst [simp]: + "post_meas0 2 |\\<^sub>1\<^sub>0\ 0 = |unit_vec 4 0\" +proof + fix i j::nat assume "i < dim_row |unit_vec 4 0\" and "j < dim_col |unit_vec 4 0\" + then have "i \ {0,1,2,3}" and "j = 0" + by(auto simp add: ket_vec_def) + moreover have "post_meas0 2 |\\<^sub>1\<^sub>0\ 0 $$ (0,0) = |unit_vec 4 0\ $$ (0,0)" + by(simp add: post_meas0_def unit_vec_def select_index_def bell10_def ket_vec_def real_sqrt_divide) + moreover have "post_meas0 2 |\\<^sub>1\<^sub>0\ 0 $$ (1,0) = |unit_vec 4 0\ $$ (1,0)" + by(simp add: post_meas0_def unit_vec_def select_index_def bell10_def ket_vec_def real_sqrt_divide) + moreover have "post_meas0 2 |\\<^sub>1\<^sub>0\ 0 $$ (2,0) = |unit_vec 4 0\ $$ (2,0)" + by(simp add: post_meas0_def unit_vec_def select_index_def bell10_def ket_vec_def real_sqrt_divide) + moreover have "post_meas0 2 |\\<^sub>1\<^sub>0\ 0 $$ (3,0) = |unit_vec 4 0\ $$ (3,0)" + by(simp add: post_meas0_def unit_vec_def select_index_def bell10_def ket_vec_def real_sqrt_divide) + ultimately show "post_meas0 2 |\\<^sub>1\<^sub>0\ 0 $$ (i,j) = |unit_vec 4 0\ $$ (i,j)" by auto +next + show "dim_row (post_meas0 2 |\\<^sub>1\<^sub>0\ 0) = dim_row |unit_vec 4 0\" + by(auto simp add: post_meas0_def ket_vec_def) + show "dim_col (post_meas0 2 |\\<^sub>1\<^sub>0\ 0) = dim_col |unit_vec 4 0\" + by(auto simp add: post_meas0_def ket_vec_def) +qed + +lemma post_meas0_bell10_snd [simp]: + "post_meas0 2 |\\<^sub>1\<^sub>0\ 1 = |unit_vec 4 0\" +proof + fix i j::nat assume "i < dim_row |unit_vec 4 0\" and "j < dim_col |unit_vec 4 0\" + then have "i \ {0,1,2,3}" and "j = 0" + by(auto simp add: ket_vec_def) + moreover have "post_meas0 2 |\\<^sub>1\<^sub>0\ 1 $$ (0,0) = |unit_vec 4 0\ $$ (0,0)" + by(simp add: post_meas0_def unit_vec_def select_index_def bell10_def ket_vec_def real_sqrt_divide del:One_nat_def) + moreover have "post_meas0 2 |\\<^sub>1\<^sub>0\ 1 $$ (1,0) = |unit_vec 4 0\ $$ (1,0)" + by(simp add: post_meas0_def unit_vec_def select_index_def bell10_def ket_vec_def real_sqrt_divide) + moreover have "post_meas0 2 |\\<^sub>1\<^sub>0\ 1 $$ (2,0) = |unit_vec 4 0\ $$ (2,0)" + by(simp add: post_meas0_def unit_vec_def select_index_def bell10_def ket_vec_def real_sqrt_divide) + moreover have "post_meas0 2 |\\<^sub>1\<^sub>0\ 1 $$ (3,0) = |unit_vec 4 0\ $$ (3,0)" + by(simp add: post_meas0_def unit_vec_def select_index_def bell10_def ket_vec_def real_sqrt_divide) + ultimately show "post_meas0 2 |\\<^sub>1\<^sub>0\ 1 $$ (i,j) = |unit_vec 4 0\ $$ (i,j)" by auto +next + show "dim_row (post_meas0 2 |\\<^sub>1\<^sub>0\ 1) = dim_row |unit_vec 4 0\" + by(auto simp add: post_meas0_def ket_vec_def) + show "dim_col (post_meas0 2 |\\<^sub>1\<^sub>0\ 1) = dim_col |unit_vec 4 0\" + by(auto simp add: post_meas0_def ket_vec_def) +qed + +lemma post_meas0_bell11_fst [simp]: + "post_meas0 2 |\\<^sub>1\<^sub>1\ 0 = |unit_vec 4 1\" +proof + fix i j::nat assume "i < dim_row |unit_vec 4 1\" and "j < dim_col |unit_vec 4 1\" + then have "i \ {0,1,2,3}" and "j = 0" + by(auto simp add: ket_vec_def) + moreover have "post_meas0 2 |\\<^sub>1\<^sub>1\ 0 $$ (0,0) = |unit_vec 4 1\ $$ (0,0)" + by(simp add: post_meas0_def unit_vec_def select_index_def bell11_def ket_vec_def real_sqrt_divide) + moreover have "post_meas0 2 |\\<^sub>1\<^sub>1\ 0 $$ (1,0) = |unit_vec 4 1\ $$ (1,0)" + by(simp add: post_meas0_def unit_vec_def select_index_def bell11_def ket_vec_def real_sqrt_divide) + moreover have "post_meas0 2 |\\<^sub>1\<^sub>1\ 0 $$ (2,0) = |unit_vec 4 1\ $$ (2,0)" + by(simp add: post_meas0_def unit_vec_def select_index_def bell11_def ket_vec_def real_sqrt_divide) + moreover have "post_meas0 2 |\\<^sub>1\<^sub>1\ 0 $$ (3,0) = |unit_vec 4 1\ $$ (3,0)" + by(simp add: post_meas0_def unit_vec_def select_index_def bell11_def ket_vec_def real_sqrt_divide) + ultimately show "post_meas0 2 |\\<^sub>1\<^sub>1\ 0 $$ (i,j) = |unit_vec 4 1\ $$ (i,j)" by auto +next + show "dim_row (post_meas0 2 |\\<^sub>1\<^sub>1\ 0) = dim_row |unit_vec 4 1\" + by(auto simp add: post_meas0_def ket_vec_def) + show "dim_col (post_meas0 2 |\\<^sub>1\<^sub>1\ 0) = dim_col |unit_vec 4 1\" + by(auto simp add: post_meas0_def ket_vec_def) +qed + +lemma post_meas0_bell11_snd [simp]: + "post_meas0 2 |\\<^sub>1\<^sub>1\ 1 = - |unit_vec 4 2\" +proof + fix i j::nat assume "i < dim_row (- |unit_vec 4 2\)" and "j < dim_col (- |unit_vec 4 2\)" + then have "i \ {0,1,2,3}" and "j = 0" + by(auto simp add: ket_vec_def) + moreover have "post_meas0 2 |\\<^sub>1\<^sub>1\ 1 $$ (0,0) = (- |unit_vec 4 2\) $$ (0,0)" + by(simp add: post_meas0_def unit_vec_def select_index_def bell11_def ket_vec_def real_sqrt_divide) + moreover have "post_meas0 2 |\\<^sub>1\<^sub>1\ 1 $$ (1,0) = (- |unit_vec 4 2\) $$ (1,0)" + by(simp add: post_meas0_def unit_vec_def select_index_def bell11_def ket_vec_def real_sqrt_divide) + moreover have "post_meas0 2 |\\<^sub>1\<^sub>1\ 1 $$ (2,0) = (- |unit_vec 4 2\) $$ (2,0)" + by(simp add: post_meas0_def unit_vec_def select_index_def bell11_def ket_vec_def real_sqrt_divide del:One_nat_def) + moreover have "post_meas0 2 |\\<^sub>1\<^sub>1\ 1 $$ (3,0) = (- |unit_vec 4 2\) $$ (3,0)" + by(simp add: post_meas0_def unit_vec_def select_index_def bell11_def ket_vec_def real_sqrt_divide) + ultimately show "post_meas0 2 |\\<^sub>1\<^sub>1\ 1 $$ (i,j) = (- |unit_vec 4 2\) $$ (i,j)" by auto +next + show "dim_row (post_meas0 2 |\\<^sub>1\<^sub>1\ 1) = dim_row (- |unit_vec 4 2\)" + by(auto simp add: post_meas0_def ket_vec_def) + show "dim_col (post_meas0 2 |\\<^sub>1\<^sub>1\ 1) = dim_col (- |unit_vec 4 2\)" + by(auto simp add: post_meas0_def ket_vec_def) +qed + +lemma post_meas1_bell00_fst [simp]: + "post_meas1 2 |\\<^sub>0\<^sub>0\ 0 = |unit_vec 4 3\" +proof + fix i j::nat assume "i < dim_row |unit_vec 4 3\" and "j < dim_col |unit_vec 4 3\" + then have "i \ {0,1,2,3}" and "j = 0" + by(auto simp add: ket_vec_def) + moreover have "post_meas1 2 |\\<^sub>0\<^sub>0\ 0 $$ (0,0) = |unit_vec 4 3\ $$ (0,0)" + by(simp add: post_meas1_def unit_vec_def select_index_def bell00_def ket_vec_def real_sqrt_divide) + moreover have "post_meas1 2 |\\<^sub>0\<^sub>0\ 0 $$ (1,0) = |unit_vec 4 3\ $$ (1,0)" + by(simp add: post_meas1_def unit_vec_def select_index_def bell00_def ket_vec_def real_sqrt_divide) + moreover have "post_meas1 2 |\\<^sub>0\<^sub>0\ 0 $$ (2,0) = |unit_vec 4 3\ $$ (2,0)" + by(simp add: post_meas1_def unit_vec_def select_index_def bell00_def ket_vec_def real_sqrt_divide) + moreover have "post_meas1 2 |\\<^sub>0\<^sub>0\ 0 $$ (3,0) = |unit_vec 4 3\ $$ (3,0)" + by(simp add: post_meas1_def unit_vec_def select_index_def bell00_def ket_vec_def real_sqrt_divide) + ultimately show "post_meas1 2 |\\<^sub>0\<^sub>0\ 0 $$ (i,j) = |unit_vec 4 3\ $$ (i,j)" by auto +next + show "dim_row (post_meas1 2 |\\<^sub>0\<^sub>0\ 0) = dim_row |unit_vec 4 3\" + by(auto simp add: post_meas1_def ket_vec_def) + show "dim_col (post_meas1 2 |\\<^sub>0\<^sub>0\ 0) = dim_col |unit_vec 4 3\" + by(auto simp add: post_meas1_def ket_vec_def) +qed + +lemma post_meas1_bell00_snd [simp]: + "post_meas1 2 |\\<^sub>0\<^sub>0\ 1 = |unit_vec 4 3\" +proof + fix i j::nat assume "i < dim_row |unit_vec 4 3\" and "j < dim_col |unit_vec 4 3\" + then have "i \ {0,1,2,3}" and "j = 0" + by(auto simp add: ket_vec_def) + moreover have "post_meas1 2 |\\<^sub>0\<^sub>0\ 1 $$ (0,0) = |unit_vec 4 3\ $$ (0,0)" + by(simp add: post_meas1_def unit_vec_def select_index_def bell00_def ket_vec_def real_sqrt_divide) + moreover have "post_meas1 2 |\\<^sub>0\<^sub>0\ 1 $$ (1,0) = |unit_vec 4 3\ $$ (1,0)" + by(simp add: post_meas1_def unit_vec_def select_index_def bell00_def ket_vec_def real_sqrt_divide) + moreover have "post_meas1 2 |\\<^sub>0\<^sub>0\ 1 $$ (2,0) = |unit_vec 4 3\ $$ (2,0)" + by(simp add: post_meas1_def unit_vec_def select_index_def bell00_def ket_vec_def real_sqrt_divide) + moreover have "post_meas1 2 |\\<^sub>0\<^sub>0\ 1 $$ (3,0) = |unit_vec 4 3\ $$ (3,0)" + by(simp add: post_meas1_def unit_vec_def select_index_def bell00_def ket_vec_def real_sqrt_divide del: One_nat_def) + ultimately show "post_meas1 2 |\\<^sub>0\<^sub>0\ 1 $$ (i,j) = |unit_vec 4 3\ $$ (i,j)" by auto +next + show "dim_row (post_meas1 2 |\\<^sub>0\<^sub>0\ 1) = dim_row |unit_vec 4 3\" + by(auto simp add: post_meas1_def ket_vec_def) + show "dim_col (post_meas1 2 |\\<^sub>0\<^sub>0\ 1) = dim_col |unit_vec 4 3\" + by(auto simp add: post_meas1_def ket_vec_def) +qed + +lemma post_meas1_bell01_fst [simp]: + "post_meas1 2 |\\<^sub>0\<^sub>1\ 0 = |unit_vec 4 2\" +proof + fix i j::nat assume "i < dim_row |unit_vec 4 2\" and "j < dim_col |unit_vec 4 2\" + then have "i \ {0,1,2,3}" and "j = 0" + by(auto simp add: ket_vec_def) + moreover have "post_meas1 2 |\\<^sub>0\<^sub>1\ 0 $$ (0,0) = |unit_vec 4 2\ $$ (0,0)" + by(simp add: post_meas1_def unit_vec_def select_index_def bell01_def ket_vec_def real_sqrt_divide) + moreover have "post_meas1 2 |\\<^sub>0\<^sub>1\ 0 $$ (1,0) = |unit_vec 4 2\ $$ (1,0)" + by(simp add: post_meas1_def unit_vec_def select_index_def bell01_def ket_vec_def real_sqrt_divide) + moreover have "post_meas1 2 |\\<^sub>0\<^sub>1\ 0 $$ (2,0) = |unit_vec 4 2\ $$ (2,0)" + by(simp add: post_meas1_def unit_vec_def select_index_def bell01_def ket_vec_def real_sqrt_divide) + moreover have "post_meas1 2 |\\<^sub>0\<^sub>1\ 0 $$ (3,0) = |unit_vec 4 2\ $$ (3,0)" + by(simp add: post_meas1_def unit_vec_def select_index_def bell01_def ket_vec_def real_sqrt_divide) + ultimately show "post_meas1 2 |\\<^sub>0\<^sub>1\ 0 $$ (i,j) = |unit_vec 4 2\ $$ (i,j)" by auto +next + show "dim_row (post_meas1 2 |\\<^sub>0\<^sub>1\ 0) = dim_row |unit_vec 4 2\" + by(auto simp add: post_meas1_def ket_vec_def) + show "dim_col (post_meas1 2 |\\<^sub>0\<^sub>1\ 0) = dim_col |unit_vec 4 2\" + by(auto simp add: post_meas1_def ket_vec_def) +qed + +lemma post_meas1_bell01_snd [simp]: + "post_meas1 2 |\\<^sub>0\<^sub>1\ 1 = |unit_vec 4 1\" +proof + fix i j::nat assume "i < dim_row |unit_vec 4 1\" and "j < dim_col |unit_vec 4 1\" + then have "i \ {0,1,2,3}" and "j = 0" + by(auto simp add: ket_vec_def) + moreover have "post_meas1 2 |\\<^sub>0\<^sub>1\ 1 $$ (0,0) = |unit_vec 4 1\ $$ (0,0)" + by(simp add: post_meas1_def unit_vec_def select_index_def bell01_def ket_vec_def real_sqrt_divide) + moreover have "post_meas1 2 |\\<^sub>0\<^sub>1\ 1 $$ (1,0) = |unit_vec 4 1\ $$ (1,0)" + by(simp add: post_meas1_def unit_vec_def select_index_def bell01_def ket_vec_def real_sqrt_divide del: One_nat_def) + moreover have "post_meas1 2 |\\<^sub>0\<^sub>1\ 1 $$ (2,0) = |unit_vec 4 1\ $$ (2,0)" + by(simp add: post_meas1_def unit_vec_def select_index_def bell01_def ket_vec_def real_sqrt_divide) + moreover have "post_meas1 2 |\\<^sub>0\<^sub>1\ 1 $$ (3,0) = |unit_vec 4 1\ $$ (3,0)" + by(simp add: post_meas1_def unit_vec_def select_index_def bell01_def ket_vec_def real_sqrt_divide) + ultimately show "post_meas1 2 |\\<^sub>0\<^sub>1\ 1 $$ (i,j) = |unit_vec 4 1\ $$ (i,j)" by auto +next + show "dim_row (post_meas1 2 |\\<^sub>0\<^sub>1\ 1) = dim_row |unit_vec 4 1\" + by(auto simp add: post_meas1_def ket_vec_def) + show "dim_col (post_meas1 2 |\\<^sub>0\<^sub>1\ 1) = dim_col |unit_vec 4 1\" + by(auto simp add: post_meas1_def ket_vec_def) +qed + +lemma post_meas1_bell10_fst [simp]: + "post_meas1 2 |\\<^sub>1\<^sub>0\ 0 = - |unit_vec 4 3\" +proof + fix i j::nat assume "i < dim_row (- |unit_vec 4 3\)" and "j < dim_col (- |unit_vec 4 3\)" + then have "i \ {0,1,2,3}" and "j = 0" + by(auto simp add: ket_vec_def) + moreover have "post_meas1 2 |\\<^sub>1\<^sub>0\ 0 $$ (0,0) = (- |unit_vec 4 3\) $$ (0,0)" + by(simp add: post_meas1_def unit_vec_def select_index_def bell10_def ket_vec_def real_sqrt_divide) + moreover have "post_meas1 2 |\\<^sub>1\<^sub>0\ 0 $$ (1,0) = (- |unit_vec 4 3\) $$ (1,0)" + by(simp add: post_meas1_def unit_vec_def select_index_def bell10_def ket_vec_def real_sqrt_divide) + moreover have "post_meas1 2 |\\<^sub>1\<^sub>0\ 0 $$ (2,0) = (- |unit_vec 4 3\) $$ (2,0)" + by(simp add: post_meas1_def unit_vec_def select_index_def bell10_def ket_vec_def real_sqrt_divide) + moreover have "post_meas1 2 |\\<^sub>1\<^sub>0\ 0 $$ (3,0) = (- |unit_vec 4 3\) $$ (3,0)" + by(simp add: post_meas1_def unit_vec_def select_index_def bell10_def ket_vec_def real_sqrt_divide) + ultimately show "post_meas1 2 |\\<^sub>1\<^sub>0\ 0 $$ (i,j) = (- |unit_vec 4 3\) $$ (i,j)" by auto +next + show "dim_row (post_meas1 2 |\\<^sub>1\<^sub>0\ 0) = dim_row (- |unit_vec 4 3\)" + by(auto simp add: post_meas1_def ket_vec_def) + show "dim_col (post_meas1 2 |\\<^sub>1\<^sub>0\ 0) = dim_col (- |unit_vec 4 3\)" + by(auto simp add: post_meas1_def ket_vec_def) +qed + +lemma post_meas1_bell10_snd [simp]: + "post_meas1 2 |\\<^sub>1\<^sub>0\ 1 = - |unit_vec 4 3\" +proof + fix i j::nat assume "i < dim_row (- |unit_vec 4 3\)" and "j < dim_col (- |unit_vec 4 3\)" + then have "i \ {0,1,2,3}" and "j = 0" + by(auto simp add: ket_vec_def) + moreover have "post_meas1 2 |\\<^sub>1\<^sub>0\ 1 $$ (0,0) = (- |unit_vec 4 3\) $$ (0,0)" + by(simp add: post_meas1_def unit_vec_def select_index_def bell10_def ket_vec_def real_sqrt_divide) + moreover have "post_meas1 2 |\\<^sub>1\<^sub>0\ 1 $$ (1,0) = (- |unit_vec 4 3\) $$ (1,0)" + by(simp add: post_meas1_def unit_vec_def select_index_def bell10_def ket_vec_def real_sqrt_divide) + moreover have "post_meas1 2 |\\<^sub>1\<^sub>0\ 1 $$ (2,0) = (- |unit_vec 4 3\) $$ (2,0)" + by(simp add: post_meas1_def unit_vec_def select_index_def bell10_def ket_vec_def real_sqrt_divide) + moreover have "post_meas1 2 |\\<^sub>1\<^sub>0\ 1 $$ (3,0) = (- |unit_vec 4 3\) $$ (3,0)" + by(simp add: post_meas1_def unit_vec_def select_index_def bell10_def ket_vec_def real_sqrt_divide del: One_nat_def) + ultimately show "post_meas1 2 |\\<^sub>1\<^sub>0\ 1 $$ (i,j) = (- |unit_vec 4 3\) $$ (i,j)" by auto +next + show "dim_row (post_meas1 2 |\\<^sub>1\<^sub>0\ 1) = dim_row (- |unit_vec 4 3\)" + by(auto simp add: post_meas1_def ket_vec_def) + show "dim_col (post_meas1 2 |\\<^sub>1\<^sub>0\ 1) = dim_col (- |unit_vec 4 3\)" + by(auto simp add: post_meas1_def ket_vec_def) +qed + +lemma post_meas1_bell11_fst [simp]: + "post_meas1 2 |\\<^sub>1\<^sub>1\ 0 = - |unit_vec 4 2\" +proof + fix i j::nat assume "i < dim_row (- |unit_vec 4 2\)" and "j < dim_col (- |unit_vec 4 2\)" + then have "i \ {0,1,2,3}" and "j = 0" + by(auto simp add: ket_vec_def) + moreover have "post_meas1 2 |\\<^sub>1\<^sub>1\ 0 $$ (0,0) = (- |unit_vec 4 2\) $$ (0,0)" + by(simp add: post_meas1_def unit_vec_def select_index_def bell11_def ket_vec_def real_sqrt_divide) + moreover have "post_meas1 2 |\\<^sub>1\<^sub>1\ 0 $$ (1,0) = (- |unit_vec 4 2\) $$ (1,0)" + by(simp add: post_meas1_def unit_vec_def select_index_def bell11_def ket_vec_def real_sqrt_divide) + moreover have "post_meas1 2 |\\<^sub>1\<^sub>1\ 0 $$ (2,0) = (- |unit_vec 4 2\) $$ (2,0)" + by(simp add: post_meas1_def unit_vec_def select_index_def bell11_def ket_vec_def real_sqrt_divide) + moreover have "post_meas1 2 |\\<^sub>1\<^sub>1\ 0 $$ (3,0) = (- |unit_vec 4 2\) $$ (3,0)" + by(simp add: post_meas1_def unit_vec_def select_index_def bell11_def ket_vec_def real_sqrt_divide) + ultimately show "post_meas1 2 |\\<^sub>1\<^sub>1\ 0 $$ (i,j) = (- |unit_vec 4 2\) $$ (i,j)" by auto +next + show "dim_row (post_meas1 2 |\\<^sub>1\<^sub>1\ 0) = dim_row (- |unit_vec 4 2\)" + by(auto simp add: post_meas1_def ket_vec_def) + show "dim_col (post_meas1 2 |\\<^sub>1\<^sub>1\ 0) = dim_col (- |unit_vec 4 2\)" + by(auto simp add: post_meas1_def ket_vec_def) +qed + +lemma post_meas1_bell11_snd [simp]: + "post_meas1 2 |\\<^sub>1\<^sub>1\ 1 = |unit_vec 4 1\" +proof + fix i j::nat assume "i < dim_row |unit_vec 4 1\" and "j < dim_col |unit_vec 4 1\" + then have "i \ {0,1,2,3}" and "j = 0" + by(auto simp add: ket_vec_def) + moreover have "post_meas1 2 |\\<^sub>1\<^sub>1\ 1 $$ (0,0) = |unit_vec 4 1\ $$ (0,0)" + by(simp add: post_meas1_def unit_vec_def select_index_def bell11_def ket_vec_def real_sqrt_divide) + moreover have "post_meas1 2 |\\<^sub>1\<^sub>1\ 1 $$ (1,0) = |unit_vec 4 1\ $$ (1,0)" + by(simp add: post_meas1_def unit_vec_def select_index_def bell11_def ket_vec_def real_sqrt_divide del: One_nat_def) + moreover have "post_meas1 2 |\\<^sub>1\<^sub>1\ 1 $$ (2,0) = |unit_vec 4 1\ $$ (2,0)" + by(simp add: post_meas1_def unit_vec_def select_index_def bell11_def ket_vec_def real_sqrt_divide) + moreover have "post_meas1 2 |\\<^sub>1\<^sub>1\ 1 $$ (3,0) = |unit_vec 4 1\ $$ (3,0)" + by(simp add: post_meas1_def unit_vec_def select_index_def bell11_def ket_vec_def real_sqrt_divide) + ultimately show "post_meas1 2 |\\<^sub>1\<^sub>1\ 1 $$ (i,j) = |unit_vec 4 1\ $$ (i,j)" by auto +next + show "dim_row (post_meas1 2 |\\<^sub>1\<^sub>1\ 1) = dim_row |unit_vec 4 1\" + by(auto simp add: post_meas1_def ket_vec_def) + show "dim_col (post_meas1 2 |\\<^sub>1\<^sub>1\ 1) = dim_col |unit_vec 4 1\" + by(auto simp add: post_meas1_def ket_vec_def) +qed + +end \ No newline at end of file diff --git a/thys/Isabelle_Marries_Dirac/More_Tensor.thy b/thys/Isabelle_Marries_Dirac/More_Tensor.thy new file mode 100755 --- /dev/null +++ b/thys/Isabelle_Marries_Dirac/More_Tensor.thy @@ -0,0 +1,518 @@ +(* +Authors: + + Anthony Bordg, University of Cambridge, apdb3@cam.ac.uk; + Yijun He, University of Cambridge, yh403@cam.ac.uk +*) + +section \Further Results on Tensor Products\ + +theory More_Tensor +imports + Quantum + Tensor + Jordan_Normal_Form.Matrix + Basics +begin + + +lemma tensor_prod_2 [simp]: +"mult.vec_vec_Tensor (*) [x1::complex,x2] [x3, x4] = [x1 * x3, x1 * x4, x2 * x3, x2 * x4]" +proof - + have "Matrix_Tensor.mult (1::complex) (*)" + by (simp add: Matrix_Tensor.mult_def) + thus "mult.vec_vec_Tensor (*) [x1::complex,x2] [x3,x4] = [x1*x3,x1*x4,x2*x3,x2*x4]" + using mult.vec_vec_Tensor_def[of "(1::complex)" "(*)"] mult.times_def[of "(1::complex)" "(*)"] by simp +qed + +lemma list_vec [simp]: + assumes "v \ state_qbit 1" + shows "list_of_vec v = [v $ 0, v $ 1]" +proof - + have "Rep_vec v = (fst(Rep_vec v), snd(Rep_vec v))" by simp + also have "\ = (2, vec_index v)" + by (metis (mono_tags, lifting) assms dim_vec.rep_eq mem_Collect_eq power_one_right state_qbit_def vec_index.rep_eq) + moreover have "[0..<2::nat] = [0,1]" + by(simp add: upt_rec) + ultimately show ?thesis + by(simp add: list_of_vec_def) +qed + +lemma vec_tensor_prod_2 [simp]: + assumes "v \ state_qbit 1" and "w \ state_qbit 1" + shows "v \ w = vec_of_list [v $ 0 * w $ 0, v $ 0 * w $ 1, v $ 1 * w $ 0, v $ 1 * w $ 1]" +proof - + have "list_of_vec v = [v $ 0, v $ 1]" + using assms by simp + moreover have "list_of_vec w = [w $ 0, w $ 1]" + using assms by simp + ultimately show "v \ w = vec_of_list [v $ 0 * w $ 0, v $ 0 * w $ 1, v $ 1 * w $ 0, v $ 1 * w $ 1]" + by(simp add: tensor_vec_def) +qed + +lemma vec_dim_of_vec_of_list [simp]: + assumes "length l = n" + shows "dim_vec (vec_of_list l) = n" + using assms vec_of_list_def by simp + +lemma vec_tensor_prod_2_bis [simp]: + assumes "v \ state_qbit 1" and "w \ state_qbit 1" + shows "v \ w = Matrix.vec 4 (\i. if i = 0 then v $ 0 * w $ 0 else + if i = 3 then v $ 1 * w $ 1 else + if i = 1 then v $ 0 * w $ 1 else v $ 1 * w $ 0)" +proof + define u where "u = Matrix.vec 4 (\i. if i = 0 then v $ 0 * w $ 0 else + if i = 3 then v $ 1 * w $ 1 else + if i = 1 then v $ 0 * w $ 1 else v $ 1 * w $ 0)" + then show f2:"dim_vec (v \ w) = dim_vec u" + using assms by simp + show "\i. i < dim_vec u \ (v \ w) $ i = u $ i" + apply (auto simp: u_def) + using assms apply auto[3] + apply (simp add: numeral_3_eq_3) + using u_def vec_of_list_index vec_tensor_prod_2 index_is_2 + by (metis (no_types, lifting) One_nat_def assms nth_Cons_0 nth_Cons_Suc numeral_2_eq_2) +qed + +lemma index_col_mat_of_cols_list [simp]: + assumes "i < n" and "j < length l" + shows "Matrix.col (mat_of_cols_list n l) j $ i = l ! j ! i" + apply (auto simp: Matrix.col_def mat_of_cols_list_def) + using assms less_le_trans by fastforce + +lemma multTensor2 [simp]: + assumes a1:"A = Matrix.mat 2 1 (\(i,j). if i = 0 then a0 else a1)" and + a2:"B = Matrix.mat 2 1 (\(i,j). if i = 0 then b0 else b1)" + shows "mult.Tensor (*) (mat_to_cols_list A) (mat_to_cols_list B) = [[a0*b0, a0*b1, a1*b0, a1*b1]]" +proof - + have "mat_to_cols_list A = [[a0, a1]]" + by (auto simp: a1 mat_to_cols_list_def) (simp add: numeral_2_eq_2) + moreover have f2:"mat_to_cols_list B = [[b0, b1]]" + by (auto simp: a2 mat_to_cols_list_def) (simp add: numeral_2_eq_2) + ultimately have "mult.Tensor (*) (mat_to_cols_list A) (mat_to_cols_list B) = + mult.Tensor (*) [[a0,a1]] [[b0,b1]]" by simp + thus ?thesis + using mult.Tensor_def[of "(1::complex)" "(*)"] mult.times_def[of "(1::complex)" "(*)"] + by (metis (mono_tags, lifting) append_self_conv list.simps(6) mult.Tensor.simps(2) mult.vec_mat_Tensor.simps(1) +mult.vec_mat_Tensor.simps(2) plus_mult_cpx plus_mult_def tensor_prod_2) +qed + +lemma multTensor2_bis [simp]: + assumes a1:"dim_row A = 2" and a2:"dim_col A = 1" and a3:"dim_row B = 2" and a4:"dim_col B = 1" + shows "mult.Tensor (*) (mat_to_cols_list A) (mat_to_cols_list B) = +[[A $$ (0,0) * B $$ (0,0), A $$ (0,0) * B $$ (1,0), A $$ (1,0) * B $$ (0,0), A $$ (1,0) * B $$ (1,0)]]" +proof - + have "mat_to_cols_list A = [[A $$ (0,0), A $$ (1,0)]]" + by (auto simp: a1 a2 mat_to_cols_list_def) (simp add: numeral_2_eq_2) + moreover have f2:"mat_to_cols_list B = [[B $$ (0,0), B $$ (1,0)]]" + by (auto simp: a3 a4 mat_to_cols_list_def) (simp add: numeral_2_eq_2) + ultimately have "mult.Tensor (*) (mat_to_cols_list A) (mat_to_cols_list B) = + mult.Tensor (*) [[A $$ (0,0), A $$ (1,0)]] [[B $$ (0,0), B $$ (1,0)]]" by simp + thus ?thesis + using mult.Tensor_def[of "(1::complex)" "(*)"] mult.times_def[of "(1::complex)" "(*)"] + by (smt append_self_conv list.simps(6) mult.Tensor.simps(2) mult.vec_mat_Tensor.simps(1) +mult.vec_mat_Tensor.simps(2) plus_mult_cpx plus_mult_def tensor_prod_2) +qed + +lemma mat_tensor_prod_2_prelim [simp]: + assumes "state 1 v" and "state 1 w" + shows "v \ w = mat_of_cols_list 4 +[[v $$ (0,0) * w $$ (0,0), v $$ (0,0) * w $$ (1,0), v $$ (1,0) * w $$ (0,0), v $$ (1,0) * w $$ (1,0)]]" +proof + define u where "u = mat_of_cols_list 4 +[[v $$ (0,0) * w $$ (0,0), v $$ (0,0) * w $$ (1,0), v $$ (1,0) * w $$ (0,0), v $$ (1,0) * w $$ (1,0)]]" + then show f1:"dim_row (v \ w) = dim_row u" + using assms state_def mat_of_cols_list_def tensor_mat_def by simp + show f2:"dim_col (v \ w) = dim_col u" + using assms state_def mat_of_cols_list_def tensor_mat_def u_def by simp + show "\i j. i < dim_row u \ j < dim_col u \ (v \ w) $$ (i, j) = u $$ (i, j)" + using u_def tensor_mat_def assms state_def by simp +qed + +lemma mat_tensor_prod_2_col [simp]: + assumes "state 1 v" and "state 1 w" + shows "Matrix.col (v \ w) 0 = Matrix.col v 0 \ Matrix.col w 0" +proof + show f1:"dim_vec (Matrix.col (v \ w) 0) = dim_vec (Matrix.col v 0 \ Matrix.col w 0)" + using assms vec_tensor_prod_2_bis + by (smt Tensor.mat_of_cols_list_def dim_col dim_row_mat(1) dim_vec mat_tensor_prod_2_prelim state.state_to_state_qbit) +next + show "\i. i Matrix.col w 0) \ Matrix.col (v \ w) 0 $ i = (Matrix.col v 0 \ Matrix.col w 0) $ i" + proof - + have "dim_vec (Matrix.col v 0 \ Matrix.col w 0) = 4" + by (metis (no_types, lifting) assms(1) assms(2) dim_vec state.state_to_state_qbit vec_tensor_prod_2_bis) + moreover have "(Matrix.col v 0 \ Matrix.col w 0) $ 0 = v $$ (0,0) * w $$ (0,0)" + using assms vec_tensor_prod_2 state.state_to_state_qbit col_index_of_mat_col + by (smt nth_Cons_0 power_one_right state_def vec_of_list_index zero_less_numeral) + moreover have "\ = Matrix.col (v \ w) 0 $ 0" + using assms by simp + moreover have "(Matrix.col v 0 \ Matrix.col w 0) $ 1 = v $$ (0,0) * w $$ (1,0)" + using assms vec_tensor_prod_2 state.state_to_state_qbit col_index_of_mat_col + by (smt One_nat_def Suc_1 lessI nth_Cons_0 power_one_right state_def vec_index_vCons_Suc +vec_of_list_Cons vec_of_list_index zero_less_numeral) + moreover have "\ = Matrix.col (v \ w) 0 $ 1" + using assms by simp + moreover have "(Matrix.col v 0 \ Matrix.col w 0) $ 2 = v $$ (1,0) * w $$ (0,0)" + using assms vec_tensor_prod_2 state.state_to_state_qbit col_index_of_mat_col + by (smt One_nat_def Suc_1 lessI nth_Cons_0 power_one_right state_def vec_index_vCons_Suc +vec_of_list_Cons vec_of_list_index zero_less_numeral) + moreover have "\ = Matrix.col (v \ w) 0 $ 2" + using assms by simp + moreover have "(Matrix.col v 0 \ Matrix.col w 0) $ 3 = v $$ (1,0) * w $$ (1,0)" + using assms vec_tensor_prod_2 state.state_to_state_qbit col_index_of_mat_col numeral_3_eq_3 + by (smt One_nat_def Suc_1 lessI nth_Cons_0 power_one_right state_def vec_index_vCons_Suc +vec_of_list_Cons vec_of_list_index zero_less_numeral) + moreover have "\ = Matrix.col (v \ w) 0 $ 3" + using assms by simp + ultimately show "\i. i Matrix.col w 0) \ Matrix.col (v \ w) 0 $ i = (Matrix.col v 0 \ Matrix.col w 0) $ i" + using index_sl_four by auto + qed +qed + +lemma mat_tensor_prod_2 [simp]: + assumes "state 1 v" and "state 1 w" + shows "v \ w = Matrix.mat 4 1 (\(i,j). if i = 0 then v $$ (0,0) * w $$ (0,0) else + if i = 3 then v $$ (1,0) * w $$ (1,0) else + if i = 1 then v $$ (0,0) * w $$ (1,0) else + v $$ (1,0) * w $$ (0,0))" +proof + define u where "u = Matrix.mat 4 1 (\(i,j). if i = 0 then v $$ (0,0) * w $$ (0,0) else + if i = 3 then v $$ (1,0) * w $$ (1,0) else + if i = 1 then v $$ (0,0) * w $$ (1,0) else + v $$ (1,0) * w $$ (0,0))" + then show "dim_row (v \ w) = dim_row u" + using assms tensor_mat_def state_def by(simp add: Tensor.mat_of_cols_list_def) + also have "\ = 4" by (simp add: u_def) + show "dim_col (v \ w) = dim_col u" + using u_def assms tensor_mat_def state_def Tensor.mat_of_cols_list_def by simp + moreover have "\ = 1" by(simp add: u_def) + ultimately show "\i j. i < dim_row u \ j < dim_col u \ (v \ w) $$ (i, j) = u $$ (i,j)" + proof - + fix i j::nat + assume a1:"i < dim_row u" and a2:"j < dim_col u" + then have "(v \ w) $$ (i, j) = Matrix.col (v \ w) 0 $ i" + using Matrix.col_def u_def assms by simp + then have f1:"(v \ w) $$ (i, j) = (Matrix.col v 0 \ Matrix.col w 0) $ i" + using assms mat_tensor_prod_2_col by simp + have "(Matrix.col v 0 \ Matrix.col w 0) $ i = + Matrix.vec 4 (\i. if i = 0 then Matrix.col v 0 $ 0 * Matrix.col w 0 $ 0 else + if i = 3 then Matrix.col v 0 $ 1 * Matrix.col w 0 $ 1 else + if i = 1 then Matrix.col v 0 $ 0 * Matrix.col w 0 $ 1 else + Matrix.col v 0 $ 1 * Matrix.col w 0 $ 0) $ i" + using vec_tensor_prod_2_bis assms state.state_to_state_qbit by presburger + thus "(v \ w) $$ (i, j) = u $$ (i,j)" + using u_def a1 a2 assms state_def by simp + qed +qed + + +lemma mat_tensor_prod_2_bis: + assumes "state 1 v" and "state 1 w" + shows "v \ w = |Matrix.vec 4 (\i. if i = 0 then v $$ (0,0) * w $$ (0,0) else + if i = 3 then v $$ (1,0) * w $$ (1,0) else + if i = 1 then v $$ (0,0) * w $$ (1,0) else + v $$ (1,0) * w $$ (0,0))\" + using assms ket_vec_def mat_tensor_prod_2 by(simp add: mat_eq_iff) + +lemma eq_ket_vec: + fixes u v:: "complex Matrix.vec" + assumes "u = v" + shows "|u\ = |v\" + using assms by simp + +lemma mat_tensor_ket_vec: + assumes "state 1 v" and "state 1 w" + shows "v \ w = |(Matrix.col v 0) \ (Matrix.col w 0)\" +proof - + have "v \ w = |Matrix.col v 0\ \ |Matrix.col w 0\" + using assms state_def by simp + also have "\ = +|Matrix.vec 4 (\i. if i = 0 then |Matrix.col v 0\ $$ (0,0) * |Matrix.col w 0\ $$ (0,0) else + if i = 3 then |Matrix.col v 0\ $$ (1,0) * |Matrix.col w 0\ $$ (1,0) else + if i = 1 then |Matrix.col v 0\ $$ (0,0) * |Matrix.col w 0\ $$ (1,0) else + |Matrix.col v 0\ $$ (1,0) * |Matrix.col w 0\ $$ (0,0))\" + using assms mat_tensor_prod_2_bis state_col_ket_vec by simp + also have "\ = +|Matrix.vec 4 (\i. if i = 0 then v $$ (0,0) * w $$ (0,0) else + if i = 3 then v $$ (1,0) * w $$ (1,0) else + if i = 1 then v $$ (0,0) * w $$ (1,0) else + v $$ (1,0) * w $$ (0,0))\" + using assms mat_tensor_prod_2_bis calculation by auto + also have "\ = +|Matrix.vec 4 (\i. if i = 0 then Matrix.col v 0 $ 0 * Matrix.col w 0 $ 0 else + if i = 3 then Matrix.col v 0 $ 1 * Matrix.col w 0 $ 1 else + if i = 1 then Matrix.col v 0 $ 0 * Matrix.col w 0 $ 1 else + Matrix.col v 0 $ 1 * Matrix.col w 0 $ 0)\" + apply(rule eq_ket_vec) + apply (rule eq_vecI) + using col_index_of_mat_col assms state_def by auto + finally show ?thesis + using vec_tensor_prod_2_bis assms state.state_to_state_qbit by presburger +qed + +text \The property of being a state (resp. a gate) is preserved by tensor product.\ + +lemma tensor_state2 [simp]: + assumes "state 1 u" and "state 1 v" + shows "state 2 (u \ v)" +proof + show "dim_col (u \ v) = 1" + using assms dim_col_tensor_mat state.is_column by presburger + show "dim_row (u \ v) = 2\<^sup>2" + using assms dim_row_tensor_mat state.dim_row + by (metis (mono_tags, lifting) power2_eq_square power_one_right) + show "\Matrix.col (u \ v) 0\ = 1" + proof - + define l where d0:"l = [u $$ (0,0) * v $$ (0,0), u $$ (0,0) * v $$ (1,0), u $$ (1,0) * v $$ (0,0), u $$ (1,0) * v $$ (1,0)]" + then have f4:"length l = 4" by simp + also have "u \ v = mat_of_cols_list 4 +[[u $$ (0,0) * v $$ (0,0), u $$ (0,0) * v $$ (1,0), u $$ (1,0) * v $$ (0,0), u $$ (1,0) * v $$ (1,0)]]" + using assms by simp + then have "Matrix.col (u \ v) 0 = vec_of_list [u $$ (0,0) * v $$ (0,0), u $$ (0,0) * v $$ (1,0), +u $$ (1,0) * v $$ (0,0), u $$ (1,0) * v $$ (1,0)]" + by (metis One_nat_def Suc_eq_plus1 add_Suc col_mat_of_cols_list list.size(3) list.size(4) +nth_Cons_0 numeral_2_eq_2 numeral_Bit0 plus_1_eq_Suc vec_of_list_Cons zero_less_one_class.zero_less_one) + then have f5:"\Matrix.col (u \ v) 0\ = sqrt(\i<4. (cmod (l ! i))\<^sup>2)" + by (metis d0 f4 One_nat_def cpx_length_of_vec_of_list d0 vec_of_list_Cons) + also have "\ = sqrt ((cmod (u $$ (0,0) * v $$ (0,0)))\<^sup>2 + (cmod(u $$ (0,0) * v $$ (1,0)))\<^sup>2 + +(cmod(u $$ (1,0) * v $$ (0,0)))\<^sup>2 + (cmod(u $$ (1,0) * v $$ (1,0)))\<^sup>2)" + proof - + have "(\i<4. (cmod (l ! i))\<^sup>2) = (cmod (l ! 0))\<^sup>2 + (cmod (l ! 1))\<^sup>2 + (cmod (l ! 2))\<^sup>2 + +(cmod (l ! 3))\<^sup>2" + using sum_insert + by (smt One_nat_def empty_iff finite.emptyI finite.insertI insertE lessThan_0 lessThan_Suc +numeral_2_eq_2 numeral_3_eq_3 numeral_plus_one one_plus_numeral_commute plus_1_eq_Suc semiring_norm(2) +semiring_norm(8) sum.empty) + also have "\ = (cmod (u $$ (0,0) * v $$ (0,0)))\<^sup>2 + (cmod(u $$ (0,0) * v $$ (1,0)))\<^sup>2 + +(cmod(u $$ (1,0) * v $$ (0,0)))\<^sup>2 + (cmod(u $$ (1,0) * v $$ (1,0)))\<^sup>2" + using d0 by simp + finally show ?thesis by(simp add: f5) + qed + moreover have "\ = +sqrt ((cmod (u $$ (0,0)))\<^sup>2 * (cmod (v $$ (0,0)))\<^sup>2 + (cmod(u $$ (0,0)))\<^sup>2 * (cmod (v $$ (1,0)))\<^sup>2 + +(cmod(u $$ (1,0)))\<^sup>2 * (cmod (v $$ (0,0)))\<^sup>2 + (cmod(u $$ (1,0)))\<^sup>2 * (cmod(v $$ (1,0)))\<^sup>2)" + by (simp add: norm_mult power_mult_distrib) + moreover have "\ = sqrt ((((cmod(u $$ (0,0)))\<^sup>2 + (cmod(u $$ (1,0)))\<^sup>2)) * +(((cmod(v $$ (0,0)))\<^sup>2 + (cmod(v $$ (1,0)))\<^sup>2)))" + by (simp add: distrib_left mult.commute) + ultimately have f6:"\Matrix.col (u \ v) 0\\<^sup>2 = (((cmod(u $$ (0,0)))\<^sup>2 + (cmod(u $$ (1,0)))\<^sup>2)) * +(((cmod(v $$ (0,0)))\<^sup>2 + (cmod(v $$ (1,0)))\<^sup>2))" + by (simp add: f4) + also have f7:"\ = (\i< 2. (cmod (u $$ (i,0)))\<^sup>2) * (\i<2. (cmod (v $$ (i,0)))\<^sup>2)" + by (simp add: numeral_2_eq_2) + also have f8:"\ = (\i< 2.(cmod (Matrix.col u 0 $ i))\<^sup>2) * (\i<2.(cmod (Matrix.col v 0 $ i))\<^sup>2)" + using assms index_col state_def by simp + finally show ?thesis + proof - + have f1:"(\i< 2.(cmod (Matrix.col u 0 $ i))\<^sup>2) = 1" + using assms(1) state_def cpx_vec_length_def by auto + have f2:"(\i< 2.(cmod (Matrix.col v 0 $ i))\<^sup>2) = 1" + using assms(2) state_def cpx_vec_length_def by auto + thus ?thesis + using f1 f8 f5 f6 f7 + by (simp add: \sqrt (\i<4. (cmod (l ! i))\<^sup>2) = sqrt ((cmod (u $$ (0, 0) * v $$ (0, 0)))\<^sup>2 + +(cmod (u $$ (0, 0) * v $$ (1, 0)))\<^sup>2 + (cmod (u $$ (1, 0) * v $$ (0, 0)))\<^sup>2 + (cmod (u $$ (1, 0) * v $$ (1, 0)))\<^sup>2)\) + qed + qed +qed + +lemma sum_prod: + fixes f::"nat \ complex" and g::"nat \ complex" + shows "(\iiji<(a+1)*b. f (i div b) * g (i mod b)) = (\ii\{a*b..<(a+1)*b}. f (i div b) * g (i mod b))" + apply (auto simp: algebra_simps) + by (smt add.commute mult_Suc sum.lessThan_Suc sum.nat_group) + also have "\ = (\iji\{a*b..<(a+1)*b}. f (i div b) * g (i mod b))" + by (simp add: Suc.IH) + also have "\ = (\iji\{a*b..<(a+1)*b}. f (a) * g(i-a*b))" by simp + also have "\ = (\iji\{a*b..<(a+1)*b}. g(i-a*b))" + by(simp add: sum_distrib_left) + also have "\ = (\iji\{.. v)" +proof + show c1:"dim_col (u \ v) = 1" + using assms dim_col_tensor_mat state.is_column by presburger + show c2:"dim_row (u \ v) = 2^(m + n)" + using assms dim_row_tensor_mat state.dim_row by (metis power_add) + have "(\i<2^(m + n). (cmod (u $$ (i div 2 ^ n, 0) * v $$ (i mod 2 ^ n, 0)))\<^sup>2) = +(\i<2^(m + n). (cmod (u $$ (i div 2 ^ n, 0)))\<^sup>2 * (cmod (v $$ (i mod 2 ^ n, 0)))\<^sup>2)" + by (simp add: sqr_of_cmod_of_prod) + also have "\ = (\i<2^m. (cmod (u $$ (i, 0)))\<^sup>2) * (\i<2^n. (cmod (v $$ (i, 0)))\<^sup>2)" + proof- + have "\ = (\i<2^(m + n).complex_of_real((cmod (u $$ (i div 2^n,0)))\<^sup>2) * complex_of_real((cmod (v $$ (i mod 2^n,0)))\<^sup>2))" + by simp + moreover have "(\i<2^m. (cmod (u $$ (i, 0)))\<^sup>2) = (\i<2^m. complex_of_real ((cmod (u $$ (i,0)))\<^sup>2))" by simp + moreover have "(\i<2^n. (cmod (v $$ (i, 0)))\<^sup>2) = (\i<2^n. complex_of_real ((cmod (v $$ (i, 0)))\<^sup>2))" by simp + ultimately show ?thesis + using sum_prod[of "\i. (cmod (u $$ (i , 0)))\<^sup>2" "2^n" "\i. (cmod (v $$ (i , 0)))\<^sup>2" "2^m"] + by (smt of_real_eq_iff of_real_mult power_add) + qed + also have "\ = 1" + proof- + have "(\i<2^m. (cmod (u $$ (i, 0)))\<^sup>2) = 1" + using assms(1) state_def cpx_vec_length_def by auto + moreover have "(\i<2^n. (cmod (v $$ (i, 0)))\<^sup>2) = 1" + using assms(2) state_def cpx_vec_length_def by auto + ultimately show ?thesis by simp + qed + ultimately show "\Matrix.col (u \ v) 0\ = 1" + using c1 c2 assms state_def by (auto simp add: cpx_vec_length_def) +qed + +lemma dim_row_of_tensor_gate: + assumes "gate m G1" and "gate n G2" + shows "dim_row (G1 \ G2) = 2^(m+n)" + using assms dim_row_tensor_mat gate.dim_row by (simp add: power_add) + +lemma tensor_gate_sqr_mat: + assumes "gate m G1" and "gate n G2" + shows "square_mat (G1 \ G2)" + using assms gate.square_mat by simp + +lemma dim_row_of_one_mat_less_pow: + assumes "gate m G1" and "gate n G2" and "i < dim_row (1\<^sub>m(dim_col G1 * dim_col G2))" + shows "i < 2^(m+n)" + using assms gate_def by (simp add: power_add) + +lemma dim_col_of_one_mat_less_pow: + assumes "gate m G1" and "gate n G2" and "j < dim_col (1\<^sub>m(dim_col G1 * dim_col G2))" + shows "j < 2^(m+n)" + using assms gate_def by (simp add: power_add) + +lemma index_tensor_gate_unitary1: + assumes "gate m G1" and "gate n G2" and "i < dim_row (1\<^sub>m(dim_col G1 * dim_col G2))" and +"j < dim_col (1\<^sub>m(dim_col G1 * dim_col G2))" + shows "((G1 \ G2)\<^sup>\ * (G1 \ G2)) $$ (i, j) = 1\<^sub>m(dim_col G1 * dim_col G2) $$ (i, j)" +proof- + have "\k. k<2^(m+n) \ cnj((G1 \ G2) $$ (k,i)) = +cnj(G1 $$ (k div 2^n, i div 2^n)) * cnj(G2 $$ (k mod 2^n, i mod 2^n))" + using assms(1-3) by (simp add: gate_def power_add) + moreover have "\k. k<2^(m+n) \ (G1 \ G2) $$ (k,j) = + G1 $$ (k div 2^n, j div 2^n) * G2 $$ (k mod 2^n, j mod 2^n)" + using assms(1,2,4) by (simp add: gate_def power_add) + ultimately have "\k. k<2^(m+n) \ cnj((G1 \ G2) $$ (k,i)) * ((G1 \ G2) $$ (k,j)) = + cnj(G1 $$ (k div 2^n, i div 2^n)) * G1 $$ (k div 2^n, j div 2^n) * + cnj(G2 $$ (k mod 2^n, i mod 2^n)) * G2 $$ (k mod 2^n, j mod 2^n)" by simp + then have "(\k<2^(m+n). cnj((G1 \ G2) $$ (k,i)) * ((G1 \ G2) $$ (k,j))) = + (\k<2^(m+n). cnj(G1 $$ (k div 2^n, i div 2^n)) * G1 $$ (k div 2^n, j div 2^n) * + cnj(G2 $$ (k mod 2^n, i mod 2^n)) * G2 $$ (k mod 2^n, j mod 2^n))" by simp + also have "\ = + (\k<2^m. cnj(G1 $$ (k, i div 2^n)) * G1 $$ (k, j div 2^n)) * + (\k<2^n. cnj(G2 $$ (k, i mod 2^n)) * G2 $$ (k, j mod 2^n))" + using sum_prod[of "\x. cnj(G1 $$ (x, i div 2^n)) * G1 $$ (x, j div 2^n)" "2^n" +"\x. cnj(G2 $$ (x, i mod 2^n)) * G2 $$ (x, j mod 2^n)" "2^m"] + by (metis (no_types, lifting) power_add semigroup_mult_class.mult.assoc sum.cong) + also have "((G1 \ G2)\<^sup>\ * (G1 \ G2)) $$ (i, j) = (\k<2^(m+n).cnj((G1 \ G2) $$ (k,i)) * ((G1 \ G2) $$ (k,j)))" + using assms index_matrix_prod[of "i" "(G1 \ G2)\<^sup>\" "j" "(G1 \ G2)"] dagger_def +dim_row_of_tensor_gate tensor_gate_sqr_mat by simp + ultimately have "((G1 \ G2)\<^sup>\ * (G1 \ G2)) $$ (i,j) = + (\k1<2^m. cnj(G1 $$ (k1, i div 2^n)) * G1 $$ (k1, j div 2^n)) * + (\k2<2^n. cnj(G2 $$ (k2, i mod 2^n)) * G2 $$ (k2, j mod 2^n))" by simp + moreover have "(\k<2^m. cnj(G1 $$ (k, i div 2^n))* G1 $$ (k, j div 2^n)) = (G1\<^sup>\ * G1) $$ (i div 2^n, j div 2^n)" + using assms gate_def dagger_def index_matrix_prod[of "i div 2^n" "G1\<^sup>\" "j div 2^n" "G1"] + by (simp add: less_mult_imp_div_less power_add) + moreover have "\ = 1\<^sub>m(2^m) $$ (i div 2^n, j div 2^n)" + using assms(1,2) gate_def unitary_def by simp + moreover have "(\k<2^n. cnj(G2 $$ (k, i mod 2^n))* G2 $$ (k, j mod 2^n)) = (G2\<^sup>\ * G2) $$ (i mod 2^n, j mod 2^n)" + using assms(1,2) gate_def dagger_def index_matrix_prod[of "i mod 2^n" "G2\<^sup>\" "j mod 2^n" "G2"] by simp + moreover have "\ = 1\<^sub>m(2^n) $$ (i mod 2^n, j mod 2^n)" + using assms(1,2) gate_def unitary_def by simp + ultimately have "((G1 \ G2)\<^sup>\ * (G1 \ G2)) $$ (i,j) = 1\<^sub>m (2^m) $$ (i div 2^n, j div 2^n) * 1\<^sub>m (2^n) $$ (i mod 2^n, j mod 2^n)" + by simp + thus ?thesis + using assms assms(3,4) gate_def index_one_mat_div_mod[of "i" "m" "n" "j"] by(simp add: power_add) +qed + +lemma tensor_gate_unitary1 [simp]: + assumes "gate m G1" and "gate n G2" + shows "(G1 \ G2)\<^sup>\ * (G1 \ G2) = 1\<^sub>m(dim_col G1 * dim_col G2)" +proof + show "dim_row ((G1 \ G2)\<^sup>\ * (G1 \ G2)) = dim_row (1\<^sub>m(dim_col G1 * dim_col G2))" by simp + show "dim_col ((G1 \ G2)\<^sup>\ * (G1 \ G2)) = dim_col (1\<^sub>m(dim_col G1 * dim_col G2))" by simp + fix i j assume "i < dim_row (1\<^sub>m(dim_col G1 * dim_col G2))" and "j < dim_col (1\<^sub>m(dim_col G1 * dim_col G2))" + thus "((G1 \ G2)\<^sup>\ * (G1 \ G2)) $$ (i, j) = 1\<^sub>m(dim_col G1 * dim_col G2) $$ (i, j)" + using assms index_tensor_gate_unitary1 by simp +qed + +lemma index_tensor_gate_unitary2 [simp]: + assumes "gate m G1" and "gate n G2" and "i < dim_row (1\<^sub>m (dim_col G1 * dim_col G2))" and +"j < dim_col (1\<^sub>m (dim_col G1 * dim_col G2))" + shows "((G1 \ G2) * ((G1 \ G2)\<^sup>\)) $$ (i, j) = 1\<^sub>m(dim_col G1 * dim_col G2) $$ (i, j)" +proof- + have "\k. k<2^(m+n) \ (G1 \ G2) $$ (i,k) = +G1 $$ (i div 2^n, k div 2^n) * G2 $$ (i mod 2^n, k mod 2^n)" + using assms(1-3) by (simp add: gate_def power_add) + moreover have "\k. k<2^(m+n) \ cnj((G1 \ G2) $$ (j,k)) = +cnj(G1 $$ (j div 2^n, k div 2^n)) * cnj(G2 $$ (j mod 2^n, k mod 2^n))" + using assms(1,2,4) by (simp add: gate_def power_add) + ultimately have "\k. k\{..<2^(m+n)} \ (G1 \ G2) $$ (i,k) * cnj((G1 \ G2) $$ (j,k)) = + G1 $$ (i div 2^n, k div 2^n) * cnj(G1 $$ (j div 2^n, k div 2^n)) * + G2 $$ (i mod 2^n, k mod 2^n) * cnj(G2 $$ (j mod 2^n, k mod 2^n))" by simp + then have "(\k<2^(m+n). (G1 \ G2) $$ (i,k) * cnj((G1 \ G2) $$ (j,k))) = + (\k<2^(m+n). G1 $$ (i div 2^n, k div 2^n) * cnj(G1 $$ (j div 2^n, k div 2^n)) * + G2 $$ (i mod 2^n, k mod 2^n) * cnj(G2 $$ (j mod 2^n, k mod 2^n)))" by simp + also have "\ = + (\k<2^m. G1 $$ (i div 2^n, k) * cnj(G1 $$ (j div 2^n, k))) * + (\k<2^n. G2 $$ (i mod 2^n, k) * cnj(G2 $$ (j mod 2^n, k)))" + using sum_prod[of "\k. G1 $$ (i div 2^n, k) * cnj(G1 $$ (j div 2^n, k))" "2^n" + "\k. G2 $$ (i mod 2^n, k) * cnj(G2 $$ (j mod 2^n, k))" "2^m"] + by (metis (no_types, lifting) power_add semigroup_mult_class.mult.assoc sum.cong) + also have "((G1 \ G2) * ((G1 \ G2)\<^sup>\)) $$ (i, j) = (\k<2^(m+n). (G1 \ G2) $$ (i,k) * cnj((G1 \ G2) $$ (j,k)))" + using assms index_matrix_prod[of "i" "(G1 \ G2)" "j" "(G1 \ G2)\<^sup>\"] dagger_def +dim_row_of_tensor_gate tensor_gate_sqr_mat by simp + ultimately have "((G1 \ G2) * ((G1 \ G2)\<^sup>\)) $$ (i,j) = + (\k<2^m. G1 $$ (i div 2^n, k) * cnj(G1 $$ (j div 2^n, k))) * + (\k<2^n. G2 $$ (i mod 2^n, k) * cnj(G2 $$ (j mod 2^n, k)))" by simp + moreover have "(\k<2^m. G1 $$ (i div 2^n, k) * cnj(G1 $$ (j div 2^n, k))) = (G1 * (G1\<^sup>\)) $$ (i div 2^n, j div 2^n)" + using assms gate_def dagger_def index_matrix_prod[of "i div 2^n" "G1" "j div 2^n" "G1\<^sup>\"] + by (simp add: less_mult_imp_div_less power_add) + moreover have "\ = 1\<^sub>m(2^m) $$ (i div 2^n, j div 2^n)" + using assms(1,2) gate_def unitary_def by simp + moreover have "(\k<2^n. G2 $$ (i mod 2^n, k) * cnj(G2 $$ (j mod 2^n, k))) = (G2 * (G2\<^sup>\)) $$ (i mod 2^n, j mod 2^n)" + using assms(1,2) gate_def dagger_def index_matrix_prod[of "i mod 2^n" "G2" "j mod 2^n" "G2\<^sup>\"] by simp + moreover have "\ = 1\<^sub>m(2^n) $$ (i mod 2^n, j mod 2^n)" + using assms(1,2) gate_def unitary_def by simp + ultimately have "((G1 \ G2) * ((G1 \ G2)\<^sup>\)) $$ (i,j) = 1\<^sub>m(2^m) $$ (i div 2^n, j div 2^n) * 1\<^sub>m(2^n) $$ (i mod 2^n, j mod 2^n)" + by simp + thus ?thesis + using assms gate_def index_one_mat_div_mod[of "i" "m" "n" "j"] by(simp add: power_add) +qed + +lemma tensor_gate_unitary2 [simp]: + assumes "gate m G1" and "gate n G2" + shows "(G1 \ G2) * ((G1 \ G2)\<^sup>\) = 1\<^sub>m(dim_col G1 * dim_col G2)" +proof + show "dim_row ((G1 \ G2) * ((G1 \ G2)\<^sup>\)) = dim_row(1\<^sub>m (dim_col G1 * dim_col G2))" + using assms gate_def by simp + show "dim_col ((G1 \ G2) * ((G1 \ G2)\<^sup>\)) = dim_col (1\<^sub>m(dim_col G1 * dim_col G2))" + using assms gate_def by simp + fix i j assume "i < dim_row (1\<^sub>m (dim_col G1 * dim_col G2))" and "j < dim_col (1\<^sub>m (dim_col G1 * dim_col G2))" + thus "((G1 \ G2) * ((G1 \ G2)\<^sup>\)) $$ (i, j) = 1\<^sub>m(dim_col G1 * dim_col G2) $$ (i, j)" + using assms index_tensor_gate_unitary2 by simp +qed + +lemma tensor_gate [simp]: + assumes "gate m G1" and "gate n G2" + shows "gate (m + n) (G1 \ G2)" +proof + show "dim_row (G1 \ G2) = 2^(m+n)" + using assms dim_row_tensor_mat gate.dim_row by (simp add: power_add) + show "square_mat (G1 \ G2)" + using assms gate.square_mat by simp + thus "unitary (G1 \ G2)" + using assms unitary_def by simp +qed + +end \ No newline at end of file diff --git a/thys/Isabelle_Marries_Dirac/No_Cloning.thy b/thys/Isabelle_Marries_Dirac/No_Cloning.thy new file mode 100755 --- /dev/null +++ b/thys/Isabelle_Marries_Dirac/No_Cloning.thy @@ -0,0 +1,242 @@ +(* +Authors: + + Anthony Bordg, University of Cambridge, apdb3@cam.ac.uk; + Yijun He, University of Cambridge, yh403@cam.ac.uk +*) + +section \The No-Cloning Theorem\ + +theory No_Cloning +imports + Quantum + Tensor +begin + + +subsection \The Cauchy-Schwarz Inequality\ + +lemma inner_prod_expand: + assumes "dim_vec a = dim_vec b" and "dim_vec a = dim_vec c" and "dim_vec a = dim_vec d" + shows "\a + b|c + d\ = \a|c\ + \a|d\ + \b|c\ + \b|d\" + apply (simp add: inner_prod_def) + using assms sum.cong by (simp add: sum.distrib algebra_simps) + +lemma inner_prod_distrib_left: + assumes "dim_vec a = dim_vec b" + shows "\c \\<^sub>v a|b\ = cnj(c) * \a|b\" + using assms inner_prod_def by (simp add: algebra_simps mult_hom.hom_sum) + +lemma inner_prod_distrib_right: + assumes "dim_vec a = dim_vec b" + shows "\a|c \\<^sub>v b\ = c * \a|b\" + using assms by (simp add: algebra_simps mult_hom.hom_sum) + +lemma cauchy_schwarz_ineq: + assumes "dim_vec v = dim_vec w" + shows "(cmod(\v|w\))\<^sup>2 \ Re (\v|v\ * \w|w\)" +proof (cases "\v|v\ = 0") + case c0:True + then have "\i. i < dim_vec v \ v $ i = 0" + by(metis index_zero_vec(1) inner_prod_with_itself_nonneg_reals_non0) + then have "(cmod(\v|w\))\<^sup>2 = 0" by (simp add: assms inner_prod_def) + moreover have "Re (\v|v\ * \w|w\) = 0" by (simp add: c0) + ultimately show ?thesis by simp +next + case c1:False + have "dim_vec w = dim_vec (- \v|w\ / \v|v\ \\<^sub>v v)" by (simp add: assms) + then have "\w + -\v|w\/\v|v\ \\<^sub>v v|w + -\v|w\/\v|v\ \\<^sub>v v\ = \w|w\ + \w|-\v|w\/\v|v\ \\<^sub>v v\ + +\-\v|w\/\v|v\ \\<^sub>v v|w\ + \-\v|w\/\v|v\ \\<^sub>v v|-\v|w\/\v|v\ \\<^sub>v v\" + using inner_prod_expand[of "w" "-\v|w\/\v|v\ \\<^sub>v v" "w" "-\v|w\/\v|v\ \\<^sub>v v"] by auto + moreover have "\w|-\v|w\/\v|v\ \\<^sub>v v\ = -\v|w\/\v|v\ * \w|v\" + using assms inner_prod_distrib_right[of "w" "v" "-\v|w\/\v|v\"] by simp + moreover have "\-\v|w\/\v|v\ \\<^sub>v v|w\ = cnj(-\v|w\/\v|v\) * \v|w\" + using assms inner_prod_distrib_left[of "v" "w" "-\v|w\/\v|v\"] by simp + moreover have "\-\v|w\/\v|v\ \\<^sub>v v|-\v|w\/\v|v\ \\<^sub>v v\ = cnj(-\v|w\/\v|v\) * (-\v|w\/\v|v\) * \v|v\" + using inner_prod_distrib_left[of "v" "-\v|w\/\v|v\ \\<^sub>v v" "-\v|w\/\v|v\"] +inner_prod_distrib_right[of "v" "v" "-\v|w\/\v|v\"] by simp + ultimately have "\w + -\v|w\/\v|v\ \\<^sub>v v|w + -\v|w\/\v|v\ \\<^sub>v v\ = \w|w\ - cmod(\v|w\)^2 / \v|v\" + using assms inner_prod_cnj[of "w" "v"] inner_prod_cnj[of "v" "v"] complex_norm_square by simp + moreover have "Re(\w + -\v|w\/\v|v\ \\<^sub>v v|w + -\v|w\/\v|v\ \\<^sub>v v\) \ 0" + using inner_prod_with_itself_Re by blast + ultimately have "Re(\w|w\) \ cmod(\v|w\)^2/Re(\v|v\)" + using inner_prod_with_itself_real by simp + moreover have c2:"Re(\v|v\) > 0" + using inner_prod_with_itself_Re_non0 inner_prod_with_itself_eq0 c1 by auto + ultimately have "Re(\w|w\) * Re(\v|v\) \ cmod(\v|w\)^2/Re(\v|v\) * Re(\v|v\)" + using real_mult_le_cancel_iff1 by blast + thus ?thesis + using inner_prod_with_itself_Im c2 by (simp add: mult.commute) +qed + +lemma cauchy_schwarz_eq [simp]: + assumes "v = (l \\<^sub>v w)" + shows "(cmod(\v|w\))\<^sup>2 = Re (\v|v\ * \w|w\)" +proof- + have "cmod(\v|w\) = cmod(cnj(l) * \w|w\)" + using assms inner_prod_distrib_left[of "w" "w" "l"] by simp + then have "cmod(\v|w\)^2 = cmod(l)^2 * \w|w\ * \w|w\" + using complex_norm_square inner_prod_cnj[of "w" "w"] by simp + moreover have "\v|v\ = cmod(l)^2 * \w|w\" + using assms complex_norm_square inner_prod_distrib_left[of "w" "v" "l"] +inner_prod_distrib_right[of "w" "w" "l"] by simp + ultimately show ?thesis by (metis Re_complex_of_real) +qed + +lemma cauchy_schwarz_col [simp]: + assumes "dim_vec v = dim_vec w" and "(cmod(\v|w\))\<^sup>2 = Re (\v|v\ * \w|w\)" + shows "\l. v = (l \\<^sub>v w) \ w = (l \\<^sub>v v)" +proof (cases "\v|v\ = 0") + case c0:True + then have "\i. i < dim_vec v \ v $ i = 0" + by(metis index_zero_vec(1) inner_prod_with_itself_nonneg_reals_non0) + then have "v = 0 \\<^sub>v w" by (auto simp: assms) + then show ?thesis by auto +next + case c1:False + have f0:"dim_vec w = dim_vec (- \v|w\ / \v|v\ \\<^sub>v v)" by (simp add: assms(1)) + then have "\w + -\v|w\/\v|v\ \\<^sub>v v|w + -\v|w\/\v|v\ \\<^sub>v v\ = \w|w\ + \w|-\v|w\/\v|v\ \\<^sub>v v\ + +\-\v|w\/\v|v\ \\<^sub>v v|w\ + \-\v|w\/\v|v\ \\<^sub>v v|-\v|w\/\v|v\ \\<^sub>v v\" + using inner_prod_expand[of "w" "-\v|w\/\v|v\ \\<^sub>v v" "w" "-\v|w\/\v|v\ \\<^sub>v v"] by simp + moreover have "\w|-\v|w\/\v|v\ \\<^sub>v v\ = -\v|w\/\v|v\ * \w|v\" + using assms(1) inner_prod_distrib_right[of "w" "v" "-\v|w\/\v|v\"] by simp + moreover have "\-\v|w\/\v|v\ \\<^sub>v v|w\ = cnj(-\v|w\/\v|v\) * \v|w\" + using assms(1) inner_prod_distrib_left[of "v" "w" "-\v|w\/\v|v\"] by simp + moreover have "\-\v|w\/\v|v\ \\<^sub>v v|-\v|w\/\v|v\ \\<^sub>v v\ = cnj(-\v|w\/\v|v\) * (-\v|w\/\v|v\) * \v|v\" + using inner_prod_distrib_left[of "v" "-\v|w\/\v|v\ \\<^sub>v v" "-\v|w\/\v|v\"] +inner_prod_distrib_right[of "v" "v" "-\v|w\/\v|v\"] by simp + ultimately have "\w + -\v|w\/\v|v\ \\<^sub>v v|w + -\v|w\/\v|v\ \\<^sub>v v\ = \w|w\ - cmod(\v|w\)^2 / \v|v\" + using inner_prod_cnj[of "w" "v"] inner_prod_cnj[of "v" "v"] assms(1) complex_norm_square by simp + moreover have "\w|w\ = cmod(\v|w\)^2 / \v|v\" + using assms(2) inner_prod_with_itself_real by(metis Reals_mult c1 nonzero_mult_div_cancel_left of_real_Re) + ultimately have "\w + -\v|w\/\v|v\ \\<^sub>v v|w + -\v|w\/\v|v\ \\<^sub>v v\ = 0" by simp + then have "\i. i (w + -\v|w\/\v|v\ \\<^sub>v v) $ i = 0" + by (metis f0 index_add_vec(2) index_zero_vec(1) inner_prod_with_itself_nonneg_reals_non0) + then have "\i. i w $ i + -\v|w\/\v|v\ * v $ i = 0" + by (metis assms(1) f0 index_add_vec(1) index_smult_vec(1)) + then have "\i. i w $ i = \v|w\/\v|v\ * v $ i" by simp + then have "w = \v|w\/\v|v\ \\<^sub>v v" by (auto simp add: assms(1)) + thus ?thesis by auto +qed + +subsection \The No-Cloning Theorem\ + +lemma eq_from_inner_prod [simp]: + assumes "dim_vec v = dim_vec w" and "\v|w\ = 1" and "\v|v\ = 1" and "\w|w\ = 1" + shows "v = w" +proof- + have "(cmod(\v|w\))\<^sup>2 = Re (\v|v\ * \w|w\)" by (simp add: assms) + then have f0:"\l. v = (l \\<^sub>v w) \ w = (l \\<^sub>v v)" by (simp add: assms(1)) + then show ?thesis + proof (cases "\l. v = (l \\<^sub>v w)") + case True + then have "\l. v = (l \\<^sub>v w) \ \v|w\ = cnj(l) * \w|w\" + using inner_prod_distrib_left by auto + then show ?thesis by (simp add: assms(2,4)) + next + case False + then have "\l. w = (l \\<^sub>v v) \ \v|w\ = l * \v|v\" + using f0 inner_prod_distrib_right by auto + then show ?thesis by (simp add: assms(2,3)) + qed +qed + +lemma hermite_cnj_of_tensor: + shows "(A \ B)\<^sup>\ = (A\<^sup>\) \ (B\<^sup>\)" +proof + show c0:"dim_row ((A \ B)\<^sup>\) = dim_row ((A\<^sup>\) \ (B\<^sup>\))" by simp + show c1:"dim_col ((A \ B)\<^sup>\) = dim_col ((A\<^sup>\) \ (B\<^sup>\))" by simp + show "\i j. i < dim_row ((A\<^sup>\) \ (B\<^sup>\)) \ j < dim_col ((A\<^sup>\) \ (B\<^sup>\)) \ +((A \ B)\<^sup>\) $$ (i, j) = ((A\<^sup>\) \ (B\<^sup>\)) $$ (i, j)" + proof- + fix i j assume a0:"i < dim_row ((A\<^sup>\) \ (B\<^sup>\))" and a1:"j < dim_col ((A\<^sup>\) \ (B\<^sup>\))" + then have "(A \ B)\<^sup>\ $$ (i, j) = cnj((A \ B) $$ (j, i))" by (simp add: dagger_def) + also have "\ = cnj(A $$ (j div dim_row(B), i div dim_col(B)) * B $$ (j mod dim_row(B), i mod dim_col(B)))" + by (metis (mono_tags, lifting) a0 a1 c1 dim_row_tensor_mat dim_col_of_dagger dim_row_of_dagger +index_tensor_mat less_nat_zero_code mult_not_zero neq0_conv) + moreover have "((A\<^sup>\) \ (B\<^sup>\)) $$ (i, j) = +(A\<^sup>\) $$ (i div dim_col(B), j div dim_row(B)) * (B\<^sup>\) $$ (i mod dim_col(B), j mod dim_row(B))" + by (smt a0 a1 c1 dim_row_tensor_mat dim_col_of_dagger dim_row_of_dagger index_tensor_mat +less_nat_zero_code mult_eq_0_iff neq0_conv) + moreover have "(B\<^sup>\) $$ (i mod dim_col(B), j mod dim_row(B)) = cnj(B $$ (j mod dim_row(B), i mod dim_col(B)))" + proof- + have "i mod dim_col(B) < dim_col(B)" + using a0 gr_implies_not_zero mod_div_trivial by fastforce + moreover have "j mod dim_row(B) < dim_row(B)" + using a1 gr_implies_not_zero mod_div_trivial by fastforce + ultimately show ?thesis by (simp add: dagger_def) + qed + moreover have "(A\<^sup>\) $$ (i div dim_col(B), j div dim_row(B)) = cnj(A $$ (j div dim_row(B), i div dim_col(B)))" + proof- + have "i div dim_col(B) < dim_col(A)" + using a0 dagger_def by (simp add: less_mult_imp_div_less) + moreover have "j div dim_row(B) < dim_row(A)" + using a1 dagger_def by (simp add: less_mult_imp_div_less) + ultimately show ?thesis by (simp add: dagger_def) + qed + ultimately show "((A \ B)\<^sup>\) $$ (i, j) = ((A\<^sup>\) \ (B\<^sup>\)) $$ (i, j)" by simp + qed +qed + +locale quantum_machine = + fixes n:: nat and s:: "complex Matrix.vec" and U:: "complex Matrix.mat" + assumes dim_vec [simp]: "dim_vec s = 2^n" + and dim_col [simp]: "dim_col U = 2^n * 2^n" + and square [simp]: "square_mat U" and unitary [simp]: "unitary U" + +lemma inner_prod_of_unit_vec: + fixes n i:: nat + assumes "i < n" + shows "\unit_vec n i| unit_vec n i\ = 1" + by (auto simp add: inner_prod_def unit_vec_def) + (simp add: assms sum.cong[of "{0..j. cnj (if j = i then 1 else 0) * (if j = i then 1 else 0)" "\j. (if j = i then 1 else 0)"]) + +theorem (in quantum_machine) no_cloning: + assumes [simp]: "dim_vec v = 2^n" and [simp]: "dim_vec w = 2^n" and + cloning1: "\s. U * ( |v\ \ |s\) = |v\ \ |v\" and + cloning2: "\s. U * ( |w\ \ |s\) = |w\ \ |w\" and + "\v|v\ = 1" and "\w|w\ = 1" + shows "v = w \ \v|w\ = 0" +proof- + define s:: "complex Matrix.vec" where d0:"s = unit_vec (2^n) 0" + have f0:"\|v\| \ \|s\| = (( |v\ \ |s\)\<^sup>\)" + using hermite_cnj_of_tensor[of "|v\" "|s\"] bra_def dagger_def ket_vec_def by simp + moreover have f1:"( |v\ \ |v\)\<^sup>\ * ( |w\ \ |w\) = (\|v\| \ \|s\| ) * ( |w\ \ |s\)" + proof- + have "(U * ( |v\ \ |s\))\<^sup>\ = (\|v\| \ \|s\| ) * (U\<^sup>\)" + using dagger_of_prod[of "U" "|v\ \ |s\"] f0 d0 by (simp add: ket_vec_def) + then have "(U * ( |v\ \ |s\))\<^sup>\ * U * ( |w\ \ |s\) = (\|v\| \ \|s\| ) * (U\<^sup>\) * U * ( |w\ \ |s\)" by simp + moreover have "(U * ( |v\ \ |s\))\<^sup>\ * U * ( |w\ \ |s\) = (( |v\ \ |v\)\<^sup>\) * ( |w\ \ |w\)" + using assms(2-4) d0 unit_vec_def by (smt Matrix.dim_vec assoc_mult_mat carrier_mat_triv dim_row_mat(1) +dim_row_tensor_mat dim_col_of_dagger index_mult_mat(2) ket_vec_def square square_mat.elims(2)) + moreover have "(U\<^sup>\) * U = 1\<^sub>m (2^n * 2^n)" + using unitary_def dim_col unitary by simp + moreover have "(\|v\| \ \|s\| ) * (U\<^sup>\) * U = (\|v\| \ \|s\| ) * ((U\<^sup>\) * U)" + using d0 assms(1) unit_vec_def by (smt Matrix.dim_vec assoc_mult_mat carrier_mat_triv dim_row_mat(1) +dim_row_tensor_mat f0 dim_col_of_dagger dim_row_of_dagger ket_vec_def local.dim_col) + moreover have "(\|v\| \ \|s\| ) * 1\<^sub>m (2^n * 2^n) = (\|v\| \ \|s\| )" + using f0 ket_vec_def d0 by simp + ultimately show ?thesis by simp + qed + then have f2:"(\|v\| * |w\) \ (\|v\| * |w\) = (\|v\| * |w\) \ (\|s\| * |s\)" + proof- + have "\|v\| \ \|v\| = (( |v\ \ |v\)\<^sup>\)" + using hermite_cnj_of_tensor[of "|v\" "|v\"] bra_def dagger_def ket_vec_def by simp + then show ?thesis + using f1 d0 by (simp add: bra_def mult_distr_tensor ket_vec_def) + qed + then have "\v|w\ * \v|w\ = \v|w\ * \s|s\" + proof- + have "((\|v\| * |w\) \ (\|v\| * |w\)) $$ (0,0) = \v|w\ * \v|w\" + using assms inner_prod_with_times_mat[of "v" "w"] by (simp add: bra_def ket_vec_def) + moreover have "((\|v\| * |w\) \ (\|s\| * |s\)) $$ (0,0) = \v|w\ * \s|s\" + using inner_prod_with_times_mat[of "v" "w"] inner_prod_with_times_mat[of "s" "s"] by(simp add: bra_def ket_vec_def) + ultimately show ?thesis using f2 by auto + qed + then have "\v|w\ = 0 \ \v|w\ = \s|s\" by (simp add: mult_left_cancel) + moreover have "\s|s\ = 1" by(simp add: d0 inner_prod_of_unit_vec) + ultimately show ?thesis using assms(1,2,5,6) by auto +qed + +end \ No newline at end of file diff --git a/thys/Isabelle_Marries_Dirac/Quantum.thy b/thys/Isabelle_Marries_Dirac/Quantum.thy new file mode 100755 --- /dev/null +++ b/thys/Isabelle_Marries_Dirac/Quantum.thy @@ -0,0 +1,1382 @@ +(* +Authors: + + Anthony Bordg, University of Cambridge, apdb3@cam.ac.uk + Yijun He, University of Cambridge, yh403@cam.ac.uk + with contributions by Hanna Lachnitt +*) + +section \Qubits and Quantum Gates\ + +theory Quantum +imports + Jordan_Normal_Form.Matrix + "HOL-Library.Nonpos_Ints" + Basics + Binary_Nat +begin + + +subsection \Qubits\ + +text\In this theory @{text cpx} stands for @{text complex}.\ + +definition cpx_vec_length :: "complex vec \ real" ("\_\") where +"cpx_vec_length v \ sqrt(\i2)" + +lemma cpx_length_of_vec_of_list [simp]: + "\vec_of_list l\ = sqrt(\i2)" + by (auto simp: cpx_vec_length_def vec_of_list_def vec_of_list_index) + (metis (no_types, lifting) dim_vec_of_list sum.cong vec_of_list.abs_eq vec_of_list_index) + +lemma norm_vec_index_unit_vec_is_0 [simp]: + assumes "j < n" and "j \ i" + shows "cmod ((unit_vec n i) $ j) = 0" + using assms by (simp add: unit_vec_def) + +lemma norm_vec_index_unit_vec_is_1 [simp]: + assumes "j < n" and "j = i" + shows "cmod ((unit_vec n i) $ j) = 1" +proof - + have f:"(unit_vec n i) $ j = 1" + using assms by simp + thus ?thesis + by (simp add: f cmod_def) +qed + +lemma unit_cpx_vec_length [simp]: + assumes "i < n" + shows "\unit_vec n i\ = 1" +proof - + have "(\j2) = (\j = 1" + using assms by simp + finally have "sqrt (\j2) = 1" + by simp + thus ?thesis + using cpx_vec_length_def by simp +qed + +lemma smult_vec_length [simp]: + assumes "x \ 0" + shows "\complex_of_real(x) \\<^sub>v v\ = x * \v\" +proof- + have "(\i::nat.(cmod (complex_of_real x * v $ i))\<^sup>2) = (\i::nat. (cmod (v $ i))\<^sup>2 * x\<^sup>2)" + by (auto simp: norm_mult power_mult_distrib) + then have "(\i2) = + (\i2 * x\<^sup>2)" by meson + moreover have "(\i2 * x\<^sup>2) = x\<^sup>2 * (\i2)" + by (metis (no_types) mult.commute sum_distrib_right) + moreover have "sqrt(x\<^sup>2 * (\i2)) = + sqrt(x\<^sup>2) * sqrt (\i2)" + using real_sqrt_mult by blast + ultimately show ?thesis + by(simp add: cpx_vec_length_def assms) +qed + +locale state = + fixes n:: nat and v:: "complex mat" + assumes is_column [simp]: "dim_col v = 1" + and dim_row [simp]: "dim_row v = 2^n" + and is_normal [simp]: "\col v 0\ = 1" + +text\ +Below the natural number n codes for the dimension of the complex vector space whose elements of norm +1 we call states. +\ + +lemma unit_vec_of_right_length_is_state [simp]: + assumes "i < 2^n" + shows "unit_vec (2^n) i \ {v| n v::complex vec. dim_vec v = 2^n \ \v\ = 1}" +proof- + have "dim_vec (unit_vec (2^n) i) = 2^n" + by simp + moreover have "\unit_vec (2^n) i\ = 1" + using assms by simp + ultimately show ?thesis + by simp +qed + +definition state_qbit :: "nat \ complex vec set" where +"state_qbit n \ {v| v:: complex vec. dim_vec v = 2^n \ \v\ = 1}" + +lemma (in state) state_to_state_qbit [simp]: + shows "col v 0 \ state_qbit n" + using state_def state_qbit_def by simp + +subsection "The Hermitian Conjugation" + +text \The Hermitian conjugate of a complex matrix is the complex conjugate of its transpose. \ + +definition dagger :: "complex mat \ complex mat" ("_\<^sup>\") where + "M\<^sup>\ \ mat (dim_col M) (dim_row M) (\(i,j). cnj(M $$ (j,i)))" + +text \We introduce the type of complex square matrices.\ + +typedef cpx_sqr_mat = "{M | M::complex mat. square_mat M}" +proof- + have "square_mat (1\<^sub>m n)" for n + using one_mat_def by simp + thus ?thesis by blast +qed + +definition cpx_sqr_mat_to_cpx_mat :: "cpx_sqr_mat => complex mat" where +"cpx_sqr_mat_to_cpx_mat M \ Rep_cpx_sqr_mat M" + +text \ +We introduce a coercion from the type of complex square matrices to the type of complex +matrices. +\ + +declare [[coercion cpx_sqr_mat_to_cpx_mat]] + +lemma dim_row_of_dagger [simp]: + "dim_row (M\<^sup>\) = dim_col M" + using dagger_def by simp + +lemma dim_col_of_dagger [simp]: + "dim_col (M\<^sup>\) = dim_row M" + using dagger_def by simp + +lemma col_of_dagger [simp]: + assumes "j < dim_row M" + shows "col (M\<^sup>\) j = vec (dim_col M) (\i. cnj (M $$ (j,i)))" + using assms col_def dagger_def by simp + +lemma row_of_dagger [simp]: + assumes "i < dim_col M" + shows "row (M\<^sup>\) i = vec (dim_row M) (\j. cnj (M $$ (j,i)))" + using assms row_def dagger_def by simp + +lemma dagger_of_dagger_is_id: + fixes M :: "complex Matrix.mat" + shows "(M\<^sup>\)\<^sup>\ = M" +proof + show "dim_row ((M\<^sup>\)\<^sup>\) = dim_row M" by simp + show "dim_col ((M\<^sup>\)\<^sup>\) = dim_col M" by simp + fix i j assume a0:"i < dim_row M" and a1:"j < dim_col M" + then show "(M\<^sup>\)\<^sup>\ $$ (i,j) = M $$ (i,j)" + proof- + show ?thesis + using dagger_def a0 a1 by auto + qed +qed + +lemma dagger_of_sqr_is_sqr [simp]: + "square_mat ((M::cpx_sqr_mat)\<^sup>\)" +proof- + have "square_mat M" + using cpx_sqr_mat_to_cpx_mat_def Rep_cpx_sqr_mat by simp + then have "dim_row M = dim_col M" by simp + then have "dim_col (M\<^sup>\) = dim_row (M\<^sup>\)" by simp + thus "square_mat (M\<^sup>\)" by simp +qed + +lemma dagger_of_id_is_id [simp]: + "(1\<^sub>m n)\<^sup>\ = 1\<^sub>m n" + using dagger_def one_mat_def by auto + +subsection "Unitary Matrices and Quantum Gates" + +definition unitary :: "complex mat \ bool" where +"unitary M \ (M\<^sup>\) * M = 1\<^sub>m (dim_col M) \ M * (M\<^sup>\) = 1\<^sub>m (dim_row M)" + +lemma id_is_unitary [simp]: + "unitary (1\<^sub>m n)" + by (simp add: unitary_def) + +locale gate = + fixes n:: nat and A:: "complex mat" + assumes dim_row [simp]: "dim_row A = 2^n" + and square_mat [simp]: "square_mat A" + and unitary [simp]: "unitary A" + +text \ +We prove that a quantum gate is invertible and its inverse is given by its Hermitian conjugate. +\ + +lemma mat_unitary_mat [intro]: + assumes "unitary M" + shows "inverts_mat M (M\<^sup>\)" + using assms by (simp add: unitary_def inverts_mat_def) + +lemma unitary_mat_mat [intro]: + assumes "unitary M" + shows "inverts_mat (M\<^sup>\) M" + using assms by (simp add: unitary_def inverts_mat_def) + +lemma (in gate) gate_is_inv: + "invertible_mat A" + using square_mat unitary invertible_mat_def by blast + +subsection "Relations Between Complex Conjugation, Hermitian Conjugation, Transposition and Unitarity" + +notation transpose_mat ("(_\<^sup>t)") + +lemma col_tranpose [simp]: + assumes "dim_row M = n" and "i < n" + shows "col (M\<^sup>t) i = row M i" +proof + show "dim_vec (col (M\<^sup>t) i) = dim_vec (row M i)" + by (simp add: row_def col_def transpose_mat_def) +next + show "\j. j < dim_vec (row M i) \ col M\<^sup>t i $ j = row M i $ j" + using assms by (simp add: transpose_mat_def) +qed + +lemma row_transpose [simp]: + assumes "dim_col M = n" and "i < n" + shows "row (M\<^sup>t) i = col M i" + using assms by simp + +definition cpx_mat_cnj :: "complex mat \ complex mat" ("(_\<^sup>\)") where +"cpx_mat_cnj M \ mat (dim_row M) (dim_col M) (\(i,j). cnj (M $$ (i,j)))" + +lemma cpx_mat_cnj_id [simp]: + "(1\<^sub>m n)\<^sup>\ = 1\<^sub>m n" + by (auto simp: cpx_mat_cnj_def) + +lemma cpx_mat_cnj_cnj [simp]: + "(M\<^sup>\)\<^sup>\ = M" + by (auto simp: cpx_mat_cnj_def) + +lemma dim_row_of_cjn_prod [simp]: + "dim_row ((M\<^sup>\) * (N\<^sup>\)) = dim_row M" + by (simp add: cpx_mat_cnj_def) + +lemma dim_col_of_cjn_prod [simp]: + "dim_col ((M\<^sup>\) * (N\<^sup>\)) = dim_col N" + by (simp add: cpx_mat_cnj_def) + +lemma cpx_mat_cnj_prod: + assumes "dim_col M = dim_row N" + shows "(M * N)\<^sup>\ = (M\<^sup>\) * (N\<^sup>\)" +proof + show "dim_row (M * N)\<^sup>\ = dim_row ((M\<^sup>\) * (N\<^sup>\))" + by (simp add: cpx_mat_cnj_def) +next + show "dim_col ((M * N)\<^sup>\) = dim_col ((M\<^sup>\) * (N\<^sup>\))" + by (simp add: cpx_mat_cnj_def) +next + fix i j::nat + assume a1:"i < dim_row ((M\<^sup>\) * (N\<^sup>\))" and a2:"j < dim_col ((M\<^sup>\) * (N\<^sup>\))" + then have "(M * N)\<^sup>\ $$ (i,j) = cnj (\k<(dim_row N). M $$ (i,k) * N $$ (k,j))" + using assms cpx_mat_cnj_def index_mat times_mat_def scalar_prod_def row_def col_def +dim_row_of_cjn_prod dim_col_of_cjn_prod + by (smt case_prod_conv dim_col index_mult_mat(2) index_mult_mat(3) index_vec lessThan_atLeast0 + lessThan_iff sum.cong) + also have "\ = (\k<(dim_row N). cnj(M $$ (i,k)) * cnj(N $$ (k,j)))" by simp + also have "((M\<^sup>\) * (N\<^sup>\)) $$ (i,j) = + (\k<(dim_row N). cnj(M $$ (i,k)) * cnj(N $$ (k,j)))" + using assms a1 a2 cpx_mat_cnj_def index_mat times_mat_def scalar_prod_def row_def col_def + by (smt case_prod_conv dim_col dim_col_mat(1) dim_row_mat(1) index_vec lessThan_atLeast0 + lessThan_iff sum.cong) + finally show "(M * N)\<^sup>\ $$ (i, j) = ((M\<^sup>\) * (N\<^sup>\)) $$ (i, j)" by simp +qed + +lemma transpose_of_prod: + fixes M N::"complex Matrix.mat" + assumes "dim_col M = dim_row N" + shows "(M * N)\<^sup>t = N\<^sup>t * (M\<^sup>t)" +proof + fix i j::nat + assume a0: "i < dim_row (N\<^sup>t * (M\<^sup>t))" and a1: "j < dim_col (N\<^sup>t * (M\<^sup>t))" + then have "(M * N)\<^sup>t $$ (i,j) = (M * N) $$ (j,i)" by auto + also have "... = (\kt. M $$ (j,k) * N $$ (k,i))" + using assms a0 a1 by auto + also have "... = (\kt. N $$ (k,i) * M $$ (j,k))" + by (simp add: semiring_normalization_rules(7)) + also have "... = (\kt. ((N\<^sup>t) $$ (i,k)) * (M\<^sup>t) $$ (k,j))" + using assms a0 a1 by auto + finally show "((M * N)\<^sup>t) $$ (i,j) = (N\<^sup>t * (M\<^sup>t)) $$ (i,j)" + using assms a0 a1 by auto +next + show "dim_row ((M * N)\<^sup>t) = dim_row (N\<^sup>t * (M\<^sup>t))" by auto +next + show "dim_col ((M * N)\<^sup>t) = dim_col (N\<^sup>t * (M\<^sup>t))" by auto +qed + +lemma transpose_cnj_is_dagger [simp]: + "(M\<^sup>t)\<^sup>\ = (M\<^sup>\)" +proof + show f1:"dim_row ((M\<^sup>t)\<^sup>\) = dim_row (M\<^sup>\)" + by (simp add: cpx_mat_cnj_def transpose_mat_def dagger_def) +next + show f2:"dim_col ((M\<^sup>t)\<^sup>\) = dim_col (M\<^sup>\)" + by (simp add: cpx_mat_cnj_def transpose_mat_def dagger_def) +next + fix i j::nat + assume "i < dim_row M\<^sup>\" and "j < dim_col M\<^sup>\" + then show "M\<^sup>t\<^sup>\ $$ (i, j) = M\<^sup>\ $$ (i, j)" + by (simp add: cpx_mat_cnj_def transpose_mat_def dagger_def) +qed + +lemma cnj_transpose_is_dagger [simp]: + "(M\<^sup>\)\<^sup>t = (M\<^sup>\)" +proof + show "dim_row ((M\<^sup>\)\<^sup>t) = dim_row (M\<^sup>\)" + by (simp add: transpose_mat_def cpx_mat_cnj_def dagger_def) +next + show "dim_col ((M\<^sup>\)\<^sup>t) = dim_col (M\<^sup>\)" + by (simp add: transpose_mat_def cpx_mat_cnj_def dagger_def) +next + fix i j::nat + assume "i < dim_row M\<^sup>\" and "j < dim_col M\<^sup>\" + then show "M\<^sup>\\<^sup>t $$ (i, j) = M\<^sup>\ $$ (i, j)" + by (simp add: transpose_mat_def cpx_mat_cnj_def dagger_def) +qed + +lemma dagger_of_transpose_is_cnj [simp]: + "(M\<^sup>t)\<^sup>\ = (M\<^sup>\)" + by (metis transpose_transpose transpose_cnj_is_dagger) + +lemma dagger_of_prod: + fixes M N::"complex Matrix.mat" + assumes "dim_col M = dim_row N" + shows "(M * N)\<^sup>\ = N\<^sup>\ * (M\<^sup>\)" +proof- + have "(M * N)\<^sup>\ = ((M * N)\<^sup>\)\<^sup>t" by auto + also have "... = ((M\<^sup>\) * (N\<^sup>\))\<^sup>t" using assms cpx_mat_cnj_prod by auto + also have "... = (N\<^sup>\)\<^sup>t * ((M\<^sup>\)\<^sup>t)" using assms transpose_of_prod + by (metis cnj_transpose_is_dagger dim_col_of_dagger dim_row_of_dagger index_transpose_mat(2) index_transpose_mat(3)) + finally show "(M * N)\<^sup>\ = N\<^sup>\ * (M\<^sup>\)" by auto +qed + +text \The product of two quantum gates is a quantum gate.\ + +lemma prod_of_gate_is_gate: + assumes "gate n G1" and "gate n G2" + shows "gate n (G1 * G2)" +proof + show "dim_row (G1 * G2) = 2^n" using assms by (simp add: gate_def) +next + show "square_mat (G1 * G2)" + using assms gate.dim_row gate.square_mat by simp +next + show "unitary (G1 * G2)" + proof- + have "((G1 * G2)\<^sup>\) * (G1 * G2) = 1\<^sub>m (dim_col (G1 * G2))" + proof- + have f0: "G1 \ carrier_mat (2^n) (2^n) \ G2 \ carrier_mat (2^n) (2^n) + \ G1\<^sup>\ \ carrier_mat (2^n) (2^n) \ G2\<^sup>\ \ carrier_mat (2^n) (2^n) + \ G1 * G2 \ carrier_mat (2^n) (2^n)" + using assms gate.dim_row gate.square_mat by auto + have "((G1 * G2)\<^sup>\) * (G1 * G2) = ((G2\<^sup>\) * (G1\<^sup>\)) * (G1 * G2)" + using assms dagger_of_prod gate.dim_row gate.square_mat by simp + also have "... = (G2\<^sup>\) * ((G1\<^sup>\) * (G1 * G2))" + using assms f0 by auto + also have "... = (G2\<^sup>\) * (((G1\<^sup>\) * G1) * G2)" + using assms f0 f0 by auto + also have "... = (G2\<^sup>\) * ((1\<^sub>m (dim_col G1)) * G2)" + using gate.unitary[of n G1] assms unitary_def[of G1] by simp + also have "... = (G2\<^sup>\) * ((1\<^sub>m (dim_col G2)) * G2)" + using assms f0 by (metis carrier_matD(2)) + also have "... = (G2\<^sup>\) * G2" + using f0 by (metis carrier_matD(2) left_mult_one_mat) + finally show "((G1 * G2)\<^sup>\) * (G1 * G2) = 1\<^sub>m (dim_col (G1 * G2))" + using assms gate.unitary unitary_def by simp + qed + moreover have "(G1 * G2) * ((G1 * G2)\<^sup>\) = 1\<^sub>m (dim_row (G1 * G2))" + using assms calculation + by (smt carrier_matI dim_col_of_dagger dim_row_of_dagger gate.dim_row gate.square_mat index_mult_mat(2) index_mult_mat(3) + mat_mult_left_right_inverse square_mat.elims(2)) + ultimately show ?thesis using unitary_def by simp + qed +qed + +lemma left_inv_of_unitary_transpose [simp]: + assumes "unitary U" + shows "(U\<^sup>t)\<^sup>\ * (U\<^sup>t) = 1\<^sub>m(dim_row U)" +proof - + have "dim_col U = dim_row ((U\<^sup>t)\<^sup>\)" by simp + then have "(U * ((U\<^sup>t)\<^sup>\))\<^sup>\ = (U\<^sup>\) * (U\<^sup>t)" + using cpx_mat_cnj_prod cpx_mat_cnj_cnj by presburger + also have "\ = (U\<^sup>t)\<^sup>\ * (U\<^sup>t)" by simp + finally show ?thesis + using assms by (metis transpose_cnj_is_dagger cpx_mat_cnj_id unitary_def) +qed + +lemma right_inv_of_unitary_transpose [simp]: + assumes "unitary U" + shows "U\<^sup>t * ((U\<^sup>t)\<^sup>\) = 1\<^sub>m(dim_col U)" +proof - + have "dim_col ((U\<^sup>t)\<^sup>\) = dim_row U" by simp + then have "U\<^sup>t * ((U\<^sup>t)\<^sup>\) = (((U\<^sup>t)\<^sup>\ * U)\<^sup>\)" + using cpx_mat_cnj_cnj cpx_mat_cnj_prod dagger_of_transpose_is_cnj by presburger + also have "\ = (U\<^sup>\ * U)\<^sup>\" by simp + finally show ?thesis + using assms by (metis cpx_mat_cnj_id unitary_def) +qed + +lemma transpose_of_unitary_is_unitary [simp]: + assumes "unitary U" + shows "unitary (U\<^sup>t)" + using unitary_def assms left_inv_of_unitary_transpose right_inv_of_unitary_transpose by simp + + +subsection "The Inner Product" + +text \We introduce a coercion between complex vectors and (column) complex matrices.\ + +definition ket_vec :: "complex vec \ complex mat" ("|_\") where +"|v\ \ mat (dim_vec v) 1 (\(i,j). v $ i)" + +lemma ket_vec_index [simp]: + assumes "i < dim_vec v" + shows "|v\ $$ (i,0) = v $ i" + using assms ket_vec_def by simp + +lemma ket_vec_col [simp]: + "col |v\ 0 = v" + by (auto simp: col_def ket_vec_def) + +lemma smult_ket_vec [simp]: + "|x \\<^sub>v v\ = x \\<^sub>m |v\" + by (auto simp: ket_vec_def) + +lemma smult_vec_length_bis [simp]: + assumes "x \ 0" + shows "\col (complex_of_real(x) \\<^sub>m |v\) 0\ = x * \v\" + using assms smult_ket_vec smult_vec_length ket_vec_col by metis + +declare [[coercion ket_vec]] + +definition row_vec :: "complex vec \ complex mat" where +"row_vec v \ mat 1 (dim_vec v) (\(i,j). v $ j)" + +definition bra_vec :: "complex vec \ complex mat" where +"bra_vec v \ (row_vec v)\<^sup>\" + +lemma row_bra_vec [simp]: + "row (bra_vec v) 0 = vec (dim_vec v) (\i. cnj(v $ i))" + by (auto simp: row_def bra_vec_def cpx_mat_cnj_def row_vec_def) + +text \We introduce a definition called @{term "bra"} to see a vector as a column matrix.\ + +definition bra :: "complex mat \ complex mat" ("\_|") where +"\v| \ mat 1 (dim_row v) (\(i,j). cnj(v $$ (j,i)))" + +text \The relation between @{term "bra"}, @{term "bra_vec"} and @{term "ket_vec"} is given as follows.\ + +lemma bra_bra_vec [simp]: + "bra (ket_vec v) = bra_vec v" + by (auto simp: bra_def ket_vec_def bra_vec_def cpx_mat_cnj_def row_vec_def) + +lemma row_bra [simp]: + fixes v::"complex vec" + shows "row \v| 0 = vec (dim_vec v) (\i. cnj (v $ i))" by simp + +text \We introduce the inner product of two complex vectors in @{text "\\<^sup>n"}.\ + +definition inner_prod :: "complex vec \ complex vec \ complex" ("\_|_\") where +"inner_prod u v \ \ i \ {0..< dim_vec v}. cnj(u $ i) * (v $ i)" + +lemma inner_prod_with_row_bra_vec [simp]: + assumes "dim_vec u = dim_vec v" + shows "\u|v\ = row (bra_vec u) 0 \ v" + using assms inner_prod_def scalar_prod_def row_bra_vec index_vec + by (smt lessThan_atLeast0 lessThan_iff sum.cong) + +lemma inner_prod_with_row_bra_vec_col_ket_vec [simp]: + assumes "dim_vec u = dim_vec v" + shows "\u|v\ = (row \u| 0) \ (col |v\ 0)" + using assms by (simp add: inner_prod_def scalar_prod_def) + +lemma inner_prod_with_times_mat [simp]: + assumes "dim_vec u = dim_vec v" + shows "\u|v\ = (\u| * |v\) $$ (0,0)" + using assms inner_prod_with_row_bra_vec_col_ket_vec + by (simp add: inner_prod_def times_mat_def ket_vec_def bra_def) + +lemma orthogonal_unit_vec [simp]: + assumes "i < n" and "j < n" and "i \ j" + shows "\unit_vec n i|unit_vec n j\ = 0" +proof- + have "\unit_vec n i|unit_vec n j\ = unit_vec n i \ unit_vec n j" + using assms unit_vec_def inner_prod_def scalar_prod_def + by (smt complex_cnj_zero index_unit_vec(3) index_vec inner_prod_with_row_bra_vec row_bra_vec + scalar_prod_right_unit) + thus ?thesis + using assms scalar_prod_def unit_vec_def by simp +qed + +text \We prove that our inner product is linear in its second argument.\ + +lemma vec_index_is_linear [simp]: + assumes "dim_vec u = dim_vec v" and "j < dim_vec u" + shows "(k \\<^sub>v u + l \\<^sub>v v) $ j = k * (u $ j) + l * (v $ j)" + using assms vec_index_def smult_vec_def plus_vec_def by simp + +lemma inner_prod_is_linear [simp]: + fixes u::"complex vec" and v::"nat \ complex vec" and l::"nat \ complex" + assumes "\i\{0, 1}. dim_vec u = dim_vec (v i)" + shows "\u|l 0 \\<^sub>v v 0 + l 1 \\<^sub>v v 1\ = (\i\1. l i * \u|v i\)" +proof - + have f1:"dim_vec (l 0 \\<^sub>v v 0 + l 1 \\<^sub>v v 1) = dim_vec u" + using assms by simp + then have "\u|l 0 \\<^sub>v v 0 + l 1 \\<^sub>v v 1\ = (\i\{0 ..< dim_vec u}. cnj (u $ i) * ((l 0 \\<^sub>v v 0 + l 1 \\<^sub>v v 1) $ i))" + by (simp add: inner_prod_def) + also have "\ = (\i\{0 ..< dim_vec u}. cnj (u $ i) * (l 0 * v 0 $ i + l 1 * v 1 $ i))" + using assms by simp + also have "\ = l 0 * (\i\{0 ..< dim_vec u}. cnj(u $ i) * (v 0 $ i)) + l 1 * (\i\{0 ..< dim_vec u}. cnj(u $ i) * (v 1 $ i))" + by (auto simp: algebra_simps) + (simp add: sum.distrib sum_distrib_left) + also have "\ = l 0 * \u|v 0\ + l 1 * \u|v 1\" + using assms inner_prod_def by auto + finally show ?thesis by simp +qed + +lemma inner_prod_cnj: + assumes "dim_vec u = dim_vec v" + shows "\v|u\ = cnj (\u|v\)" + by (simp add: assms inner_prod_def algebra_simps) + +lemma inner_prod_with_itself_Im [simp]: + "Im (\u|u\) = 0" + using inner_prod_cnj by (metis Reals_cnj_iff complex_is_Real_iff) + +lemma inner_prod_with_itself_real [simp]: + "\u|u\ \ \" + using inner_prod_with_itself_Im by (simp add: complex_is_Real_iff) + +lemma inner_prod_with_itself_eq0 [simp]: + assumes "u = 0\<^sub>v (dim_vec u)" + shows "\u|u\ = 0" + using assms inner_prod_def zero_vec_def + by (smt atLeastLessThan_iff complex_cnj_zero index_zero_vec(1) mult_zero_left sum.neutral) + +lemma inner_prod_with_itself_Re: + "Re (\u|u\) \ 0" +proof - + have "Re (\u|u\) = (\i = (\i2 + (Im (u $ i))\<^sup>2)" + using complex_mult_cnj + by (metis (no_types, lifting) Re_complex_of_real semiring_normalization_rules(7)) + ultimately show "Re (\u|u\) \ 0" by (simp add: sum_nonneg) +qed + +lemma inner_prod_with_itself_nonneg_reals: + fixes u::"complex vec" + shows "\u|u\ \ nonneg_Reals" + using inner_prod_with_itself_real inner_prod_with_itself_Re complex_nonneg_Reals_iff +inner_prod_with_itself_Im by auto + +lemma inner_prod_with_itself_Re_non0: + assumes "u \ 0\<^sub>v (dim_vec u)" + shows "Re (\u|u\) > 0" +proof - + obtain i where a1:"i < dim_vec u" and "u $ i \ 0" + using assms zero_vec_def by (metis dim_vec eq_vecI index_zero_vec(1)) + then have f1:"Re (cnj (u $ i) * (u $ i)) > 0" + by (metis Re_complex_of_real complex_mult_cnj complex_neq_0 mult.commute) + moreover have f2:"Re (\u|u\) = (\ii 0" + using complex_mult_cnj by simp + ultimately show ?thesis + using a1 inner_prod_def lessThan_iff + by (metis (no_types, lifting) finite_lessThan sum_pos2) +qed + +lemma inner_prod_with_itself_nonneg_reals_non0: + assumes "u \ 0\<^sub>v (dim_vec u)" + shows "\u|u\ \ 0" + using assms inner_prod_with_itself_Re_non0 by fastforce + +lemma cpx_vec_length_inner_prod [simp]: + "\v\\<^sup>2 = \v|v\" +proof - + have "\v\\<^sup>2 = (\i2)" + using cpx_vec_length_def complex_of_real_def + by (metis (no_types, lifting) real_sqrt_power real_sqrt_unique sum_nonneg zero_le_power2) + also have "\ = (\iv|v\ = \v\" + using inner_prod_with_itself_Re inner_prod_with_itself_Im csqrt_of_real_nonneg cpx_vec_length_def + by (metis (no_types, lifting) Re_complex_of_real cpx_vec_length_inner_prod real_sqrt_ge_0_iff + real_sqrt_unique sum_nonneg zero_le_power2) + + +subsection "Unitary Matrices and Length-Preservation" + +subsubsection "Unitary Matrices are Length-Preserving" + +text \The bra-vector @{text "\A * v|"} is given by @{text "\v| * A\<^sup>\"}\ + +lemma dagger_of_ket_is_bra: + fixes v:: "complex vec" + shows "( |v\ )\<^sup>\ = \v|" + by (simp add: bra_def dagger_def ket_vec_def) + +lemma bra_mat_on_vec: + fixes v::"complex vec" and A::"complex mat" + assumes "dim_col A = dim_vec v" + shows "\A * v| = \v| * (A\<^sup>\)" +proof + show "dim_row \A * v| = dim_row (\v| * (A\<^sup>\))" + by (simp add: bra_def times_mat_def) +next + show "dim_col \A * v| = dim_col (\v| * (A\<^sup>\))" + by (simp add: bra_def times_mat_def) +next + fix i j::nat + assume a1:"i < dim_row (\v| * (A\<^sup>\))" and a2:"j < dim_col (\v| * (A\<^sup>\))" + then have "cnj((A * v) $$ (j,0)) = cnj (row A j \ v)" + using bra_def times_mat_def ket_vec_col ket_vec_def by simp + also have f7:"\= (\i\{0 ..< dim_vec v}. cnj(v $ i) * cnj(A $$ (j,i)))" + using row_def scalar_prod_def cnj_sum complex_cnj_mult mult.commute + by (smt assms index_vec lessThan_atLeast0 lessThan_iff sum.cong) + moreover have f8:"(row \v| 0) \ (col (A\<^sup>\) j) = + vec (dim_vec v) (\i. cnj (v $ i)) \ vec (dim_col A) (\i. cnj (A $$ (j,i)))" + using a2 by simp + ultimately have "cnj((A * v) $$ (j,0)) = (row \v| 0) \ (col (A\<^sup>\) j)" + using assms scalar_prod_def + by (smt dim_vec index_vec lessThan_atLeast0 lessThan_iff sum.cong) + then have "\A * v| $$ (0,j) = (\v| * (A\<^sup>\)) $$ (0,j)" + using bra_def times_mat_def a2 by simp + thus "\A * |v\| $$ (i, j) = (\v| * (A\<^sup>\)) $$ (i, j)" + using a1 by (simp add: times_mat_def bra_def) +qed + +lemma mat_on_ket: + fixes v:: "complex vec" and A:: "complex mat" + assumes "dim_col A = dim_vec v" + shows "A * |v\ = |col (A * v) 0\" + using assms ket_vec_def by auto + +lemma dagger_of_mat_on_ket: + fixes v:: "complex vec" and A :: "complex mat" + assumes "dim_col A = dim_vec v" + shows "(A * |v\ )\<^sup>\ = \v| * (A\<^sup>\)" + using assms by (metis bra_mat_on_vec dagger_of_ket_is_bra mat_on_ket) + +definition col_fst :: "'a mat \ 'a vec" where + "col_fst A = vec (dim_row A) (\ i. A $$ (i,0))" + +lemma col_fst_is_col [simp]: + "col_fst M = col M 0" + by (simp add: col_def col_fst_def) + +text \ +We need to declare @{term "col_fst"} as a coercion from matrices to vectors in order to see a column +matrix as a vector. +\ + +declare + [[coercion_delete ket_vec]] + [[coercion col_fst]] + +lemma unit_vec_to_col: + assumes "dim_col A = n" and "i < n" + shows "col A i = A * |unit_vec n i\" +proof + show "dim_vec (col A i) = dim_vec (A * |unit_vec n i\)" + using col_def times_mat_def by simp +next + fix j::nat + assume "j < dim_vec (col_fst (A * |unit_vec n i\))" + then show "col A i $ j = (A * |unit_vec n i\) $ j" + using assms times_mat_def ket_vec_def + by (smt col_fst_is_col dim_col dim_col_mat(1) index_col index_mult_mat(1) index_mult_mat(2) +index_row(1) ket_vec_col less_numeral_extra(1) scalar_prod_right_unit) +qed + +lemma mult_ket_vec_is_ket_vec_of_mult: + fixes A::"complex mat" and v::"complex vec" + assumes "dim_col A = dim_vec v" + shows "|A * |v\ \ = A * |v\" + using assms ket_vec_def + by (metis One_nat_def col_fst_is_col dim_col dim_col_mat(1) index_mult_mat(3) ket_vec_col less_Suc0 +mat_col_eqI) + +lemma unitary_is_sq_length_preserving [simp]: + assumes "unitary U" and "dim_vec v = dim_col U" + shows "\U * |v\\\<^sup>2 = \v\\<^sup>2" +proof - + have "\U * |v\|U * |v\ \ = (\|v\| * (U\<^sup>\) * |U * |v\\) $$ (0,0)" + using assms(2) bra_mat_on_vec + by (metis inner_prod_with_times_mat mult_ket_vec_is_ket_vec_of_mult) + then have "\U * |v\|U * |v\ \ = (\|v\| * (U\<^sup>\) * (U * |v\)) $$ (0,0)" + using assms(2) mult_ket_vec_is_ket_vec_of_mult by simp + moreover have f1:"dim_col \|v\| = dim_vec v" + using ket_vec_def bra_def by simp + moreover have "dim_row (U\<^sup>\) = dim_vec v" + using assms(2) by simp + ultimately have "\U * |v\|U * |v\ \ = (\|v\| * ((U\<^sup>\) * U) * |v\) $$ (0,0)" + using assoc_mult_mat + by(smt carrier_mat_triv dim_row_mat(1) dagger_def ket_vec_def mat_carrier times_mat_def) + then have "\U * |v\|U * |v\ \ = (\|v\| * |v\) $$ (0,0)" + using assms f1 unitary_def by simp + thus ?thesis + using cpx_vec_length_inner_prod by(metis Re_complex_of_real inner_prod_with_times_mat) +qed + +lemma col_ket_vec [simp]: + assumes "dim_col M = 1" + shows "|col M 0\ = M" + using eq_matI assms ket_vec_def by auto + +lemma state_col_ket_vec: + assumes "state 1 v" + shows "state 1 |col v 0\" + using assms by (simp add: state_def) + +lemma col_ket_vec_index [simp]: + assumes "i < dim_row v" + shows "|col v 0\ $$ (i,0) = v $$ (i,0)" + using assms ket_vec_def by (simp add: col_def) + +lemma col_index_of_mat_col [simp]: + assumes "dim_col v = 1" and "i < dim_row v" + shows "col v 0 $ i = v $$ (i,0)" + using assms by simp + +lemma unitary_is_sq_length_preserving_bis [simp]: + assumes "unitary U" and "dim_row v = dim_col U" and "dim_col v = 1" + shows "\col (U * v) 0\\<^sup>2 = \col v 0\\<^sup>2" +proof - + have "dim_vec (col v 0) = dim_col U" + using assms(2) by simp + then have "\col_fst (U * |col v 0\)\\<^sup>2 = \col v 0\\<^sup>2" + using unitary_is_sq_length_preserving[of "U" "col v 0"] assms(1) by simp + thus ?thesis + using assms(3) by simp +qed + +text \ +A unitary matrix is length-preserving, i.e. it acts on a vector to produce another vector of the +same length. +\ + +lemma unitary_is_length_preserving_bis [simp]: + fixes U::"complex mat" and v::"complex mat" + assumes "unitary U" and "dim_row v = dim_col U" and "dim_col v = 1" + shows "\col (U * v) 0\ = \col v 0\" + using assms unitary_is_sq_length_preserving_bis + by (metis cpx_vec_length_inner_prod inner_prod_csqrt of_real_hom.injectivity) + +lemma unitary_is_length_preserving [simp]: + fixes U:: "complex mat" and v:: "complex vec" + assumes "unitary U" and "dim_vec v = dim_col U" + shows "\U * |v\\ = \v\" + using assms unitary_is_sq_length_preserving + by (metis cpx_vec_length_inner_prod inner_prod_csqrt of_real_hom.injectivity) + + +subsubsection "Length-Preserving Matrices are Unitary" + +lemma inverts_mat_sym: + fixes A B:: "complex mat" + assumes "inverts_mat A B" and "dim_row B = dim_col A" and "square_mat B" + shows "inverts_mat B A" +proof- + define n where d0:"n = dim_row B" + have "A * B = 1\<^sub>m (dim_row A)" using assms(1) inverts_mat_def by auto + moreover have "dim_col B = dim_col (A * B)" using times_mat_def by simp + ultimately have "dim_col B = dim_row A" by simp + then have c0:"A \ carrier_mat n n" using assms(2,3) d0 by auto + have c1:"B \ carrier_mat n n" using assms(3) d0 by auto + have f0:"A * B = 1\<^sub>m n" using inverts_mat_def c0 c1 assms(1) by auto + have f1:"det B \ 0" + proof + assume "det B = 0" + then have "\v. v \ carrier_vec n \ v \ 0\<^sub>v n \ B *\<^sub>v v = 0\<^sub>v n" + using det_0_iff_vec_prod_zero assms(3) c1 by blast + then obtain v where d1:"v \ carrier_vec n \ v \ 0\<^sub>v n \ B *\<^sub>v v = 0\<^sub>v n" by auto + then have d2:"dim_vec v = n" by simp + have "B * |v\ = |0\<^sub>v n\" + proof + show "dim_row (B * |v\) = dim_row |0\<^sub>v n\" using ket_vec_def d0 by simp + next + show "dim_col (B * |v\) = dim_col |0\<^sub>v n\" using ket_vec_def d0 by simp + next + fix i j assume "i < dim_row |0\<^sub>v n\" and "j < dim_col |0\<^sub>v n\" + then have f2:"i < n \ j = 0" using ket_vec_def by simp + moreover have "vec (dim_row B) (($) v) = v" using d0 d1 by auto + moreover have "(B *\<^sub>v v) $ i = (\ia = 0..) $$ (i, j) = |0\<^sub>v n\ $$ (i, j)" + using ket_vec_def d0 d1 times_mat_def mult_mat_vec_def by (auto simp add: scalar_prod_def) + qed + moreover have "|v\ \ carrier_mat n 1" using d2 ket_vec_def by simp + ultimately have "(A * B) * |v\ = A * |0\<^sub>v n\" using c0 c1 by simp + then have f3:"|v\ = A * |0\<^sub>v n\" using d2 f0 ket_vec_def by auto + have "v = 0\<^sub>v n" + proof + show "dim_vec v = dim_vec (0\<^sub>v n)" using d2 by simp + next + fix i assume f4:"i < dim_vec (0\<^sub>v n)" + then have "|v\ $$ (i,0) = v $ i" using d2 ket_vec_def by simp + moreover have "(A * |0\<^sub>v n\) $$ (i, 0) = 0" + using ket_vec_def times_mat_def scalar_prod_def f4 c0 by auto + ultimately show "v $ i = 0\<^sub>v n $ i" using f3 f4 by simp + qed + then show False using d1 by simp + qed + have f5:"adj_mat B \ carrier_mat n n \ B * adj_mat B = det B \\<^sub>m 1\<^sub>m n" using c1 adj_mat by auto + then have c2:"((1/det B) \\<^sub>m adj_mat B) \ carrier_mat n n" by simp + have f6:"B * ((1/det B) \\<^sub>m adj_mat B) = 1\<^sub>m n" using c1 f1 f5 mult_smult_distrib[of "B"] by auto + then have "A = (A * B) * ((1/det B) \\<^sub>m adj_mat B)" using c0 c1 c2 by simp + then have "A = (1/det B) \\<^sub>m adj_mat B" using f0 c2 by auto + then show ?thesis using c0 c1 f6 inverts_mat_def by auto +qed + +lemma sum_of_unit_vec_length: + fixes i j n:: nat and c:: complex + assumes "i < n" and "j < n" and "i \ j" + shows "\unit_vec n i + c \\<^sub>v unit_vec n j\\<^sup>2 = 1 + cnj(c) * c" +proof- + define v where d0:"v = unit_vec n i + c \\<^sub>v unit_vec n j" + have "\kkv\\<^sup>2 = (\k = 0..\<^sub>v col A j = A * |unit_vec n i + c \\<^sub>v unit_vec n j\" +proof + show "dim_vec (col A i + c \\<^sub>v col A j) = dim_vec (col_fst (A * |unit_vec n i + c \\<^sub>v unit_vec n j\))" + using assms(1) by auto +next + fix k assume "k < dim_vec (col_fst (A * |unit_vec n i + c \\<^sub>v unit_vec n j\))" + then have f0:"k < dim_row A" using assms(1) by auto + have "(col A i + c \\<^sub>v col A j) $ k = A $$ (k, i) + c * A $$ (k, j)" + using f0 assms(1-3) by auto + moreover have "(\xxxxx\<^sub>v col A j) $ k = col_fst (A * |unit_vec n i + c \\<^sub>v unit_vec n j\) $ k" + using f0 assms(1-3) times_mat_def scalar_prod_def ket_vec_def by auto +qed + +lemma inner_prod_is_sesquilinear: + fixes u1 u2 v1 v2:: "complex vec" and c1 c2 c3 c4:: complex and n:: nat + assumes "dim_vec u1 = n" and "dim_vec u2 = n" and "dim_vec v1 = n" and "dim_vec v2 = n" + shows "\c1 \\<^sub>v u1 + c2 \\<^sub>v u2|c3 \\<^sub>v v1 + c4 \\<^sub>v v2\ = cnj (c1) * c3 * \u1|v1\ + cnj (c2) * c3 * \u2|v1\ + + cnj (c1) * c4 * \u1|v2\ + cnj (c2) * c4 * \u2|v2\" +proof- + have "\c1 \\<^sub>v u1 + c2 \\<^sub>v u2|c3 \\<^sub>v v1 + c4 \\<^sub>v v2\ = c3 * \c1 \\<^sub>v u1 + c2 \\<^sub>v u2|v1\ + c4 * \c1 \\<^sub>v u1 + c2 \\<^sub>v u2|v2\" + using inner_prod_is_linear[of "c1 \\<^sub>v u1 + c2 \\<^sub>v u2" "\i. if i = 0 then v1 else v2" + "\i. if i = 0 then c3 else c4"] assms + by simp + also have "... = c3 * cnj(\v1|c1 \\<^sub>v u1 + c2 \\<^sub>v u2\) + c4 * cnj(\v2|c1 \\<^sub>v u1 + c2 \\<^sub>v u2\)" + using assms inner_prod_cnj[of "v1" "c1 \\<^sub>v u1 + c2 \\<^sub>v u2"] inner_prod_cnj[of "v2" "c1 \\<^sub>v u1 + c2 \\<^sub>v u2"] + by simp + also have "... = c3 * cnj(c1 * \v1|u1\ + c2 * \v1|u2\) + c4 * cnj(c1 * \v2|u1\ + c2 * \v2|u2\)" + using inner_prod_is_linear[of "v1" "\i. if i = 0 then u1 else u2" "\i. if i = 0 then c1 else c2"] + inner_prod_is_linear[of "v2" "\i. if i = 0 then u1 else u2" "\i. if i = 0 then c1 else c2"] assms + by simp + also have "... = c3 * (cnj(c1) * \u1|v1\ + cnj(c2) * \u2|v1\) + + c4 * (cnj(c1) * \u1|v2\ + cnj(c2) * \u2|v2\)" + using inner_prod_cnj[of "v1" "u1"] inner_prod_cnj[of "v1" "u2"] + inner_prod_cnj[of "v2" "u1"] inner_prod_cnj[of "v2" "u2"] assms + by simp + finally show ?thesis + by (auto simp add: algebra_simps) +qed + +text \ +A length-preserving matrix is unitary. So, unitary matrices are exactly the length-preserving +matrices. +\ + +lemma length_preserving_is_unitary: + fixes U:: "complex mat" + assumes "square_mat U" and "\v::complex vec. dim_vec v = dim_col U \ \U * |v\\ = \v\" + shows "unitary U" +proof- + define n where "n = dim_col U" + then have c0:"U \ carrier_mat n n" using assms(1) by auto + then have c1:"U\<^sup>\ \ carrier_mat n n" using assms(1) dagger_def by auto + have f0:"(U\<^sup>\) * U = 1\<^sub>m (dim_col U)" + proof + show "dim_row (U\<^sup>\ * U) = dim_row (1\<^sub>m (dim_col U))" using c0 by simp + next + show "dim_col (U\<^sup>\ * U) = dim_col (1\<^sub>m (dim_col U))" using c0 by simp + next + fix i j assume "i < dim_row (1\<^sub>m (dim_col U))" and "j < dim_col (1\<^sub>m (dim_col U))" + then have a0:"i < n \ j < n" using c0 by simp + have f1:"\l. l (\kcol U l\\<^sup>2 = (\kcol U l\\<^sup>2 = \v\\<^sup>2" using c0 d1 a1 assms(2) unit_vec_to_col by simp + moreover have "\v\\<^sup>2 = 1" using d1 a1 cpx_vec_length_inner_prod by simp + ultimately show "(\k j \ (\k j" + define v1::"complex vec" where d1:"v1 = unit_vec n i + 1 \\<^sub>v unit_vec n j" + define v2::"complex vec" where d2:"v2 = unit_vec n i + \ \\<^sub>v unit_vec n j" + have "\v1\\<^sup>2 = 1 + cnj 1 * 1" using d1 a0 a2 sum_of_unit_vec_length by blast + then have "\v1\\<^sup>2 = 2" + by (metis complex_cnj_one cpx_vec_length_inner_prod mult.left_neutral of_real_eq_iff + of_real_numeral one_add_one) + then have "\U * |v1\\\<^sup>2 = 2" using c0 d1 assms(2) unit_vec_to_col by simp + moreover have "col U i + 1 \\<^sub>v col U j = U * |v1\" + using c0 d1 a0 sum_of_unit_vec_to_col by blast + moreover have "col U i + 1 \\<^sub>v col U j = col U i + col U j" by simp + ultimately have "\col U i + col U j|col U i + col U j\ = 2" + using cpx_vec_length_inner_prod by (metis of_real_numeral) + moreover have "\col U i + col U j|col U i + col U j\ = + \col U i|col U i\ + \col U j|col U i\ + \col U i|col U j\ + \col U j|col U j\" + using inner_prod_is_sesquilinear[of "col U i" "dim_row U" "col U j" "col U i" "col U j" "1" "1" "1" "1"] + by simp + ultimately have f2:"\col U j|col U i\ + \col U i|col U j\ = 0" + using c0 a0 f1 inner_prod_def lessThan_atLeast0 by simp + + have "\v2\\<^sup>2 = 1 + cnj \ * \" using a0 a2 d2 sum_of_unit_vec_length by simp + then have "\v2\\<^sup>2 = 2" + by (metis Re_complex_of_real complex_norm_square mult.commute norm_ii numeral_Bit0 + numeral_One numeral_eq_one_iff of_real_numeral one_power2) + moreover have "\U * |v2\\\<^sup>2 = \v2\\<^sup>2" using c0 d2 assms(2) unit_vec_to_col by simp + moreover have "\col U i + \ \\<^sub>v col U j|col U i + \ \\<^sub>v col U j\ = \U * |v2\\\<^sup>2" + using c0 a0 d2 sum_of_unit_vec_to_col cpx_vec_length_inner_prod by auto + moreover have "\col U i + \ \\<^sub>v col U j|col U i + \ \\<^sub>v col U j\ = + \col U i|col U i\ + (-\) * \col U j|col U i\ + \ * \col U i|col U j\ + \col U j|col U j\" + using inner_prod_is_sesquilinear[of "col U i" "dim_row U" "col U j" "col U i" "col U j" "1" "\" "1" "\"] + by simp + ultimately have "\col U j|col U i\ - \col U i|col U j\ = 0" + using c0 a0 f1 inner_prod_def lessThan_atLeast0 by auto + then show "(\k\ * U) $$ (i, j) = 1\<^sub>m (dim_col U) $$ (i, j)" + using c0 assms(1) a0 one_mat_def dagger_def by auto +qed + then have "(U\<^sup>\) * U = 1\<^sub>m n" using c0 by simp + then have "inverts_mat (U\<^sup>\) U" using c1 inverts_mat_def by auto + then have "inverts_mat U (U\<^sup>\)" using c0 c1 inverts_mat_sym by simp + then have "U * (U\<^sup>\) = 1\<^sub>m (dim_row U)" using c0 inverts_mat_def by auto + then show ?thesis using f0 unitary_def by simp +qed + +lemma inner_prod_with_unitary_mat [simp]: + assumes "unitary U" and "dim_vec u = dim_col U" and "dim_vec v = dim_col U" + shows "\U * |u\|U * |v\\ = \u|v\" +proof - + have f1:"\U * |u\|U * |v\\ = (\|u\| * (U\<^sup>\) * U * |v\) $$ (0,0)" + using assms(2-3) bra_mat_on_vec mult_ket_vec_is_ket_vec_of_mult + by (smt assoc_mult_mat carrier_mat_triv col_fst_def dim_vec dim_col_of_dagger index_mult_mat(2) + index_mult_mat(3) inner_prod_with_times_mat ket_vec_def mat_carrier) + moreover have f2:"\|u\| \ carrier_mat 1 (dim_vec v)" + using bra_def ket_vec_def assms(2-3) by simp + moreover have f3:"U\<^sup>\ \ carrier_mat (dim_col U) (dim_row U)" + using dagger_def by simp + ultimately have "\U * |u\|U * |v\\ = (\|u\| * (U\<^sup>\ * U) * |v\) $$ (0,0)" + using assms(3) assoc_mult_mat by (metis carrier_mat_triv) + also have "\ = (\|u\| * |v\) $$ (0,0)" + using assms(1) unitary_def + by (simp add: assms(2) bra_def ket_vec_def) + finally show ?thesis + using assms(2-3) inner_prod_with_times_mat by presburger +qed + +text \As a consequence we prove that columns and rows of a unitary matrix are orthonormal vectors.\ + +lemma unitary_unit_col [simp]: + assumes "unitary U" and "dim_col U = n" and "i < n" + shows "\col U i\ = 1" + using assms unit_vec_to_col unitary_is_length_preserving by simp + +lemma unitary_unit_row [simp]: + assumes "unitary U" and "dim_row U = n" and "i < n" + shows "\row U i\ = 1" +proof - + have "row U i = col (U\<^sup>t) i" + using assms(2-3) by simp + thus ?thesis + using assms transpose_of_unitary_is_unitary unitary_unit_col + by (metis index_transpose_mat(3)) +qed + +lemma orthogonal_col_of_unitary [simp]: + assumes "unitary U" and "dim_col U = n" and "i < n" and "j < n" and "i \ j" + shows "\col U i|col U j\ = 0" +proof - + have "\col U i|col U j\ = \U * |unit_vec n i\| U * |unit_vec n j\\" + using assms(2-4) unit_vec_to_col by simp + also have "\ = \unit_vec n i |unit_vec n j\" + using assms(1-2) inner_prod_with_unitary_mat index_unit_vec(3) by simp + finally show ?thesis + using assms(3-5) by simp +qed + +lemma orthogonal_row_of_unitary [simp]: + fixes U::"complex mat" + assumes "unitary U" and "dim_row U = n" and "i < n" and "j < n" and "i \ j" + shows "\row U i|row U j\ = 0" + using assms orthogonal_col_of_unitary transpose_of_unitary_is_unitary col_transpose + by (metis index_transpose_mat(3)) + + +text\ +As a consequence, we prove that a quantum gate acting on a state of a system of n qubits give +another state of that same system. +\ + +lemma gate_on_state_is_state [intro, simp]: + assumes a1:"gate n A" and a2:"state n v" + shows "state n (A * v)" +proof + show "dim_row (A * v) = 2^n" + using gate_def state_def a1 by simp +next + show "dim_col (A * v) = 1" + using state_def a2 by simp +next + have "square_mat A" + using a1 gate_def by simp + then have "dim_col A = 2^n" + using a1 gate.dim_row by simp + then have "dim_col A = dim_row v" + using a2 state.dim_row by simp + then have "\col (A * v) 0\ = \col v 0\" + using unitary_is_length_preserving_bis assms gate_def state_def by simp + thus"\col (A * v) 0\ = 1" + using a2 state.is_normal by simp +qed + + +subsection \A Few Well-known Quantum Gates\ + +text \ +Any unitary operation on n qubits can be implemented exactly by composing single qubits and +CNOT-gates (controlled-NOT gates). However, no straightforward method is known to implement these +gates in a fashion which is resistant to errors. But, the Hadamard gate, the phase gate, the +CNOT-gate and the @{text "\/8"} gate are also universal for quantum computations, i.e. any quantum circuit on +n qubits can be approximated to an arbitrary accuracy by using only these gates, and these gates can +be implemented in a fault-tolerant way. +\ + +text \We introduce a coercion from real matrices to complex matrices.\ + +definition real_to_cpx_mat:: "real mat \ complex mat" where +"real_to_cpx_mat A \ mat (dim_row A) (dim_col A) (\(i,j). A $$ (i,j))" + +text \Our first quantum gate: the identity matrix! Arguably, not a very interesting one though!\ + +definition Id :: "nat \ complex mat" where +"Id n \ 1\<^sub>m (2^n)" + +lemma id_is_gate [simp]: + "gate n (Id n)" +proof + show "dim_row (Id n) = 2^n" + using Id_def by simp +next + show "square_mat (Id n)" + using Id_def by simp +next + show "unitary (Id n)" + by (simp add: Id_def) +qed + +text \More interesting: the Pauli matrices.\ + +definition X ::"complex mat" where +"X \ mat 2 2 (\(i,j). if i=j then 0 else 1)" + +text\ +Be aware that @{text "gate n A"} means that the matrix A has dimension @{text "2^n * 2^n"}. +For instance, with this convention a 2 X 2 matrix A which is unitary satisfies @{text "gate 1 A"} + but not @{text "gate 2 A"} as one might have been expected. +\ + +lemma dagger_of_X [simp]: + "X\<^sup>\ = X" + using dagger_def by (simp add: X_def cong_mat) + +lemma X_inv [simp]: + "X * X = 1\<^sub>m 2" + apply(simp add: X_def times_mat_def one_mat_def) + apply(rule cong_mat) + by(auto simp: scalar_prod_def) + +lemma X_is_gate [simp]: + "gate 1 X" + by (simp add: gate_def unitary_def) + (simp add: X_def) + +definition Y ::"complex mat" where +"Y \ mat 2 2 (\(i,j). if i=j then 0 else (if i=0 then -\ else \))" + +lemma dagger_of_Y [simp]: + "Y\<^sup>\ = Y" + using dagger_def by (simp add: Y_def cong_mat) + +lemma Y_inv [simp]: + "Y * Y = 1\<^sub>m 2" + apply(simp add: Y_def times_mat_def one_mat_def) + apply(rule cong_mat) + by(auto simp: scalar_prod_def) + +lemma Y_is_gate [simp]: + "gate 1 Y" + by (simp add: gate_def unitary_def) + (simp add: Y_def) + +definition Z ::"complex mat" where +"Z \ mat 2 2 (\(i,j). if i\j then 0 else (if i=0 then 1 else -1))" + +lemma dagger_of_Z [simp]: + "Z\<^sup>\ = Z" + using dagger_def by (simp add: Z_def cong_mat) + +lemma Z_inv [simp]: + "Z * Z = 1\<^sub>m 2" + apply(simp add: Z_def times_mat_def one_mat_def) + apply(rule cong_mat) + by(auto simp: scalar_prod_def) + +lemma Z_is_gate [simp]: + "gate 1 Z" + by (simp add: gate_def unitary_def) + (simp add: Z_def) + +text \The Hadamard gate\ + +definition H ::"complex mat" where +"H \ 1/sqrt(2) \\<^sub>m (mat 2 2 (\(i,j). if i\j then 1 else (if i=0 then 1 else -1)))" + +lemma H_without_scalar_prod: + "H = mat 2 2 (\(i,j). if i\j then 1/sqrt(2) else (if i=0 then 1/sqrt(2) else -(1/sqrt(2))))" + using cong_mat by (auto simp: H_def) + +lemma dagger_of_H [simp]: + "H\<^sup>\ = H" + using dagger_def by (auto simp: H_def cong_mat) + +lemma H_inv [simp]: + "H * H = 1\<^sub>m 2" + apply(simp add: H_def times_mat_def one_mat_def) + apply(rule cong_mat) + by(auto simp: scalar_prod_def complex_eqI) + +lemma H_is_gate [simp]: + "gate 1 H" + by (simp add: gate_def unitary_def) + (simp add: H_def) + +lemma H_values: + fixes i j:: nat + assumes "i < dim_row H" and "j < dim_col H" and "i \ 1 \ j \ 1" + shows "H $$ (i,j) = 1/sqrt 2" +proof- + have "i < 2" + using assms(1) by (simp add: H_without_scalar_prod less_2_cases) + moreover have "j < 2" + using assms(2) by (simp add: H_without_scalar_prod less_2_cases) + ultimately show ?thesis + using assms(3) H_without_scalar_prod by(smt One_nat_def index_mat(1) less_2_cases old.prod.case) +qed + +lemma H_values_right_bottom: + fixes i j:: nat + assumes "i = 1 \ j = 1" + shows "H $$ (i,j) = - 1/sqrt 2" + using assms by (simp add: H_without_scalar_prod) + +text \The controlled-NOT gate\ + +definition CNOT ::"complex mat" where +"CNOT \ mat 4 4 + (\(i,j). if i=0 \ j=0 then 1 else + (if i=1 \ j=1 then 1 else + (if i=2 \ j=3 then 1 else + (if i=3 \ j=2 then 1 else 0))))" + +lemma dagger_of_CNOT [simp]: + "CNOT\<^sup>\ = CNOT" + using dagger_def by (simp add: CNOT_def cong_mat) + +lemma CNOT_inv [simp]: + "CNOT * CNOT = 1\<^sub>m 4" + apply(simp add: CNOT_def times_mat_def one_mat_def) + apply(rule cong_mat) + by(auto simp: scalar_prod_def) + +lemma CNOT_is_gate [simp]: + "gate 2 CNOT" + by (simp add: gate_def unitary_def) + (simp add: CNOT_def) + +text \The phase gate, also known as the S-gate\ + +definition S ::"complex mat" where +"S \ mat 2 2 (\(i,j). if i=0 \ j=0 then 1 else (if i=1 \ j=1 then \ else 0))" + +text \The @{text "\/8"} gate, also known as the T-gate\ + +definition T ::"complex mat" where +"T \ mat 2 2 (\(i,j). if i=0 \ j=0 then 1 else (if i=1 \ j=1 then exp(\*(pi/4)) else 0))" + +text \A few relations between the Hadamard gate and the Pauli matrices\ + +lemma HXH_is_Z [simp]: + "H * X * H = Z" + apply(simp add: X_def Z_def H_def times_mat_def) + apply(rule cong_mat) + by(auto simp add: scalar_prod_def complex_eqI) + +lemma HYH_is_minusY [simp]: + "H * Y * H = - Y" + apply(simp add: Y_def H_def times_mat_def) + apply(rule eq_matI) + by(auto simp add: scalar_prod_def complex_eqI) + +lemma HZH_is_X [simp]: + shows "H * Z * H = X" + apply(simp add: X_def Z_def H_def times_mat_def) + apply(rule cong_mat) + by(auto simp add: scalar_prod_def complex_eqI) + + +subsection \The Bell States\ + +text \ +We introduce below the so-called Bell states, also known as EPR pairs (EPR stands for Einstein, +Podolsky and Rosen). +\ + +definition bell00 ::"complex mat" ("|\\<^sub>0\<^sub>0\") where +"bell00 \ 1/sqrt(2) \\<^sub>m |vec 4 (\i. if i=0 \ i=3 then 1 else 0)\" + +definition bell01 ::"complex mat" ("|\\<^sub>0\<^sub>1\") where +"bell01 \ 1/sqrt(2) \\<^sub>m |vec 4 (\i. if i=1 \ i=2 then 1 else 0)\" + +definition bell10 ::"complex mat" ("|\\<^sub>1\<^sub>0\") where +"bell10 \ 1/sqrt(2) \\<^sub>m |vec 4 (\i. if i=0 then 1 else if i=3 then -1 else 0)\" + +definition bell11 ::"complex mat" ("|\\<^sub>1\<^sub>1\") where +"bell11 \ 1/sqrt(2) \\<^sub>m |vec 4 (\i. if i=1 then 1 else if i=2 then -1 else 0)\" + +lemma + shows bell00_is_state [simp]:"state 2 |\\<^sub>0\<^sub>0\" and bell01_is_state [simp]:"state 2 |\\<^sub>0\<^sub>1\" and + bell10_is_state [simp]:"state 2 |\\<^sub>1\<^sub>0\" and bell11_is_state [simp]:"state 2 |\\<^sub>1\<^sub>1\" + by (auto simp: state_def bell00_def bell01_def bell10_def bell11_def ket_vec_def) + (auto simp: cpx_vec_length_def Set_Interval.lessThan_atLeast0 cmod_def power2_eq_square) + +lemma bell00_index [simp]: + shows "|\\<^sub>0\<^sub>0\ $$ (0,0) = 1/sqrt 2" and "|\\<^sub>0\<^sub>0\ $$ (1,0) = 0" and "|\\<^sub>0\<^sub>0\ $$ (2,0) = 0" and + "|\\<^sub>0\<^sub>0\ $$ (3,0) = 1/sqrt 2" + by (auto simp: bell00_def ket_vec_def) + +lemma bell01_index [simp]: + shows "|\\<^sub>0\<^sub>1\ $$ (0,0) = 0" and "|\\<^sub>0\<^sub>1\ $$ (1,0) = 1/sqrt 2" and "|\\<^sub>0\<^sub>1\ $$ (2,0) = 1/sqrt 2" and + "|\\<^sub>0\<^sub>1\ $$ (3,0) = 0" + by (auto simp: bell01_def ket_vec_def) + +lemma bell10_index [simp]: + shows "|\\<^sub>1\<^sub>0\ $$ (0,0) = 1/sqrt 2" and "|\\<^sub>1\<^sub>0\ $$ (1,0) = 0" and "|\\<^sub>1\<^sub>0\ $$ (2,0) = 0" and + "|\\<^sub>1\<^sub>0\ $$ (3,0) = - 1/sqrt 2" + by (auto simp: bell10_def ket_vec_def) + +lemma bell_11_index [simp]: + shows "|\\<^sub>1\<^sub>1\ $$ (0,0) = 0" and "|\\<^sub>1\<^sub>1\ $$ (1,0) = 1/sqrt 2" and "|\\<^sub>1\<^sub>1\ $$ (2,0) = - 1/sqrt 2" and + "|\\<^sub>1\<^sub>1\ $$ (3,0) = 0" + by (auto simp: bell11_def ket_vec_def) + + +subsection \The Bitwise Inner Product\ + +definition bitwise_inner_prod:: "nat \ nat \ nat \ nat" where +"bitwise_inner_prod n i j = (\k\{0.. nat \ nat \ nat" ("_ \\<^bsub>_\<^esub> _") where +"bip i n j \ bitwise_inner_prod n i j" + +lemma bitwise_inner_prod_fst_el_0: + assumes "i < 2^n \ j < 2^n" + shows "(i \\<^bsub>Suc n\<^esub> j) = (i mod 2^n) \\<^bsub>n\<^esub> (j mod 2^n)" +proof- + have "bip i (Suc n) j = (\k\{0..<(Suc n)}. (bin_rep (Suc n) i) ! k * (bin_rep (Suc n) j) ! k)" + using bitwise_inner_prod_def by simp + also have "... = bin_rep (Suc n) i ! 0 * bin_rep (Suc n) j ! 0 + + (\k\{1..<(Suc n)}. bin_rep (Suc n) i ! k * bin_rep (Suc n) j ! k)" + by (simp add: sum.atLeast_Suc_lessThan) + also have "... = (\k\{1..<(Suc n)}. bin_rep (Suc n) i ! k * bin_rep (Suc n) j ! k)" + using bin_rep_index_0[of i n] bin_rep_index_0[of j n] assms by auto + also have "... = (\k\{0..k. bin_rep (Suc n) i ! k * bin_rep (Suc n) j ! k" "0" "n"] + by (metis (no_types, lifting) One_nat_def add.commute plus_1_eq_Suc sum.cong) + finally have "bip i (Suc n) j = (\k\{0..{0..n} \ bin_rep (Suc n) i ! (k+1) = bin_rep n (i mod 2^n) ! k" for k + using bin_rep_def by (simp add: bin_rep_aux_neq_nil) + moreover have "k\{0..n} \ bin_rep (Suc n) j !(k+1) = bin_rep n (j mod 2^n) ! k" for k + using bin_rep_def by (simp add: bin_rep_aux_neq_nil) + ultimately show ?thesis + using assms bin_rep_index_0 bitwise_inner_prod_def by simp +qed + +lemma bitwise_inner_prod_fst_el_is_1: + fixes n i j:: nat + assumes "i \ 2^n \ j \ 2^n" and "i < 2^(n+1) \ j < 2^(n+1)" + shows "(i \\<^bsub>(n+1)\<^esub> j) = 1 + ((i mod 2^n) \\<^bsub>n\<^esub> (j mod 2^n))" +proof- + have "bip i (Suc n) j = (\k\{0..<(Suc n)}. bin_rep (Suc n) i ! k * bin_rep (Suc n) j ! k)" + using bitwise_inner_prod_def by simp + also have "... = bin_rep (Suc n) i ! 0 * bin_rep (Suc n) j ! 0 + + (\k\{1..<(Suc n)}. bin_rep (Suc n) i ! k * bin_rep (Suc n) j ! k)" + by (simp add: sum.atLeast_Suc_lessThan) + also have "... = 1 + (\k\{1..<(Suc n)}. bin_rep (Suc n) i ! k * bin_rep (Suc n) j ! k)" + using bin_rep_index_0_geq[of n i] bin_rep_index_0_geq[of n j] assms by simp + also have "... = 1 + (\k \ {0..k. (bin_rep (Suc n) i)!k * (bin_rep (Suc n) j)!k" "0" "n"] + by (metis (no_types, lifting) One_nat_def Suc_eq_plus1 sum.cong) + finally have f0:"bip i (Suc n) j = 1 + (\k\{0..{0..n} \ bin_rep (Suc n) i ! (k+1) = bin_rep n (i mod 2^n) ! k +\ bin_rep (Suc n) j ! (k+1) = bin_rep n (j mod 2^n) ! k" for k + using bin_rep_def by(metis Suc_eq_plus1 bin_rep_aux.simps(2) bin_rep_aux_neq_nil butlast.simps(2) nth_Cons_Suc) + ultimately show ?thesis + using bitwise_inner_prod_def by simp +qed + +lemma bitwise_inner_prod_with_zero: + assumes "m < 2^n" + shows "(0 \\<^bsub>n\<^esub> m) = 0" +proof- + have "(0 \\<^bsub>n\<^esub> m) = (\j\{0..j\{0..j\{0..Quantum Prisoner's Dilemma\ + +theory Quantum_Prisoners_Dilemma +imports + More_Tensor + Measurement + Basics +begin + + +text \ +In the 2-parameter strategic space of Eisert, Wilkens and Lewenstein [EWL], Prisoner's Dilemma +ceases to pose a dilemma if quantum strategies are allowed for. Indeed, Alice and Bob both choosing +to defect is no longer a Nash equilibrium. However, a new Nash equilibrium appears which is at the +same time Pareto optimal. Moreover, there exists a quantum strategy which always gives reward if +played against any classical strategy. +Below the parameter @{text "\"} can be seen as a measure of the game's entanglement. The game behaves +classically if @{text "\"} = 0, and for the maximally entangled case (@{text "\"} = 2*$\pi$) the dilemma disappears +as pointed out above. +\ + + +subsection \The Set-Up\ + +locale prisoner = + fixes \:: "real" + assumes "\ \ pi/2" and "\ \ 0" + +abbreviation (in prisoner) J :: "complex Matrix.mat" where +"J \ mat_of_cols_list 4 [[cos(\/2), 0, 0, \*sin(\/2)], + [0, cos(\/2), -\*sin(\/2), 0], + [0, -\*sin(\/2), cos(\/2), 0], + [\*sin(\/2), 0, 0, cos(\/2)]]" + +abbreviation (in prisoner) \\<^sub>1 :: "complex Matrix.mat" where +"\\<^sub>1 \ mat_of_cols_list 4 [[cos(\/2), 0, 0, \*sin(\/2)]]" + +lemma (in prisoner) psi_one: + shows "J * |unit_vec 4 0\ = \\<^sub>1" +proof + fix i j assume a0:"i < dim_row \\<^sub>1" and a1:"j < dim_col \\<^sub>1" + then have "(J * |unit_vec 4 0\) $$ (i,j) = (\k<4. (J $$ (i,k)) * ( |unit_vec 4 0\ $$ (k,j)))" + using mat_of_cols_list_def ket_vec_def by auto + also have "... = (\k\{0,1,2,3}. (J $$ (i,k)) * ( |unit_vec 4 0\ $$ (k,j)))" + using set_4 atLeast0LessThan by simp + also have "... = \\<^sub>1 $$ (i,j)" + proof- + have "i\{0,1,2,3} \ j=0" + using a0 a1 mat_of_cols_list_def by auto + thus ?thesis + using mat_of_cols_list_def by auto + qed + finally show "(J * |unit_vec 4 0\) $$ (i,j) = \\<^sub>1 $$ (i,j)" by simp +next + show "dim_row (J * |unit_vec 4 0\) = dim_row \\<^sub>1" + using mat_of_cols_list_def by simp +next + show "dim_col (J*|unit_vec 4 0\) = dim_col \\<^sub>1" + using mat_of_cols_list_def by (simp add: ket_vec_def) +qed + +locale strategic_space_2p = prisoner + + fixes \\<^sub>A:: "real" + and \\<^sub>A:: "real" + and \\<^sub>B:: "real" + and \\<^sub>B:: "real" + assumes "0 \ \\<^sub>A \ \\<^sub>A \ pi" + and "0 \ \\<^sub>A \ \\<^sub>A \ pi/2" + and "0 \ \\<^sub>B \ \\<^sub>B \ pi" + and "0 \ \\<^sub>B \ \\<^sub>B \ pi/2" + +abbreviation (in strategic_space_2p) U\<^sub>A :: "complex Matrix.mat" where +"U\<^sub>A \ mat_of_cols_list 2 [[exp(\*\\<^sub>A)*cos(\\<^sub>A/2), -sin(\\<^sub>A/2)], + [sin(\\<^sub>A/2), exp(-\*\\<^sub>A)*cos(\\<^sub>A/2)]]" + +abbreviation (in strategic_space_2p) U\<^sub>B :: "complex Matrix.mat" where +"U\<^sub>B \ mat_of_cols_list 2 [[exp(\*\\<^sub>B)*cos(\\<^sub>B/2), -sin(\\<^sub>B/2)], + [sin(\\<^sub>B/2), exp(-\*\\<^sub>B)*cos(\\<^sub>B/2)]]" + +abbreviation (in strategic_space_2p) \\<^sub>2 :: "complex Matrix.mat" where +"\\<^sub>2 \ +mat_of_cols_list 4 [[exp(\*\\<^sub>A)*cos(\\<^sub>A/2) * exp(\*\\<^sub>B)*cos(\\<^sub>B/2) * cos(\/2) + sin(\\<^sub>A/2) * sin(\\<^sub>B/2) * \*sin(\/2), + exp(\*\\<^sub>A)*cos(\\<^sub>A/2) * -sin(\\<^sub>B/2) * cos(\/2) + sin(\\<^sub>A/2) * exp(-\*\\<^sub>B)*cos(\\<^sub>B/2) * \*sin(\/2), + -sin(\\<^sub>A/2) * exp(\*\\<^sub>B)*cos(\\<^sub>B/2) * cos(\/2) + exp(-\*\\<^sub>A)*cos(\\<^sub>A/2) * sin(\\<^sub>B/2) * \*sin(\/2), + sin(\\<^sub>A/2) * sin(\\<^sub>B/2) * cos(\/2) + exp(-\*\\<^sub>A)*cos(\\<^sub>A/2) * exp(-\*\\<^sub>B)*cos(\\<^sub>B/2) * \*sin(\/2)]]" + +abbreviation (in strategic_space_2p) U\<^sub>A\<^sub>B :: "complex Matrix.mat" where +"U\<^sub>A\<^sub>B \ +mat_of_cols_list 4 [[exp(\*\\<^sub>A)*cos(\\<^sub>A/2) * exp(\*\\<^sub>B)*cos(\\<^sub>B/2), exp(\*\\<^sub>A)*cos(\\<^sub>A/2) * -sin(\\<^sub>B/2), + -sin(\\<^sub>A/2) * exp(\*\\<^sub>B)*cos(\\<^sub>B/2), -sin(\\<^sub>A/2) * -sin(\\<^sub>B/2)], + [exp(\*\\<^sub>A)*cos(\\<^sub>A/2) * sin(\\<^sub>B/2), exp(\*\\<^sub>A)*cos(\\<^sub>A/2) * exp(-\*\\<^sub>B)*cos(\\<^sub>B/2), + -sin(\\<^sub>A/2) * sin(\\<^sub>B/2), -sin(\\<^sub>A/2) * exp(-\*\\<^sub>B)*cos(\\<^sub>B/2)], + [sin(\\<^sub>A/2) * exp(\*\\<^sub>B)*cos(\\<^sub>B/2), -sin(\\<^sub>A/2) * sin(\\<^sub>B/2), + exp(-\*\\<^sub>A)*cos(\\<^sub>A/2) * exp (\*\\<^sub>B)*cos(\\<^sub>B/2), exp(-\*\\<^sub>A)*cos(\\<^sub>A/2) * -sin(\\<^sub>B/2)], + [sin(\\<^sub>A/2) * sin(\\<^sub>B/2), sin(\\<^sub>A/2) * exp(-\*\\<^sub>B)*cos(\\<^sub>B/2), + exp(-\*\\<^sub>A)*cos(\\<^sub>A/2) * sin(\\<^sub>B/2), exp (-\*\\<^sub>A)*cos(\\<^sub>A/2) * exp(-\*\\<^sub>B)*cos(\\<^sub>B/2)]]" + +lemma (in strategic_space_2p) U\<^sub>A_tensor_U\<^sub>B: + shows "(U\<^sub>A \ U\<^sub>B) = U\<^sub>A\<^sub>B" +proof + fix i j assume a0: "iA\<^sub>B" and a1: "jA\<^sub>B" + then have "i\{0,1,2,3} \ j\{0,1,2,3}" + using mat_of_cols_list_def by auto + then show "(U\<^sub>A \ U\<^sub>B) $$ (i,j) = U\<^sub>A\<^sub>B $$ (i,j)" + using mat_of_cols_list_def by auto +next + show "dim_row (U\<^sub>A \ U\<^sub>B) = dim_row U\<^sub>A\<^sub>B" + using mat_of_cols_list_def by simp +next + show "dim_col (U\<^sub>A \ U\<^sub>B) = dim_col U\<^sub>A\<^sub>B" + using mat_of_cols_list_def by simp +qed + +lemma (in strategic_space_2p) psi_two: + shows "(U\<^sub>A \ U\<^sub>B) * \\<^sub>1 = \\<^sub>2" +proof + fix i j + assume a0:"i < dim_row \\<^sub>2" and a1:"j < dim_col \\<^sub>2" + then show "((U\<^sub>A \ U\<^sub>B) * \\<^sub>1) $$ (i,j) = \\<^sub>2 $$ (i,j)" + proof- + have "i\{0,1,2,3} \ j=0" + using a0 a1 mat_of_cols_list_def by auto + thus ?thesis + using mat_of_cols_list_def U\<^sub>A_tensor_U\<^sub>B set_4 by auto + qed +next + show "dim_row ((U\<^sub>A \ U\<^sub>B)*\\<^sub>1) = dim_row \\<^sub>2" + using mat_of_cols_list_def by simp +next + show "dim_col ((U\<^sub>A \ U\<^sub>B)*\\<^sub>1) = dim_col \\<^sub>2" + using mat_of_cols_list_def by simp +qed + +abbreviation (in prisoner) J_cnj :: "complex Matrix.mat" where +"J_cnj \ mat_of_cols_list 4 [[cos(\/2), 0, 0, -\*sin(\/2)], + [0, cos(\/2), \*sin(\/2), 0], + [0, \*sin(\/2), cos(\/2), 0], + [-\*sin(\/2), 0, 0, cos(\/2)]]" + +lemma (in prisoner) hermite_cnj_of_J [simp]: + shows "J\<^sup>\ = J_cnj" +proof + fix i j assume a0:"i < dim_row J_cnj" and a1:"j < dim_col J_cnj" + then show "J\<^sup>\ $$ (i,j) = J_cnj $$ (i,j)" + proof- + have "i\{0,1,2,3} \ j\{0,1,2,3}" + using a0 a1 mat_of_cols_list_def by auto + thus ?thesis + using mat_of_cols_list_def dagger_def by auto + qed +next + show "dim_row (J\<^sup>\) = dim_row J_cnj" + using mat_of_cols_list_def by simp +next + show "dim_col (J\<^sup>\) = dim_col J_cnj" + using mat_of_cols_list_def by simp +qed + +abbreviation (in strategic_space_2p) \\<^sub>f :: "complex Matrix.mat" where +"\\<^sub>f \ mat_of_cols_list 4 [[ +cos(\/2) * (exp(\*\\<^sub>A)*cos(\\<^sub>A/2) * exp(\*\\<^sub>B)*cos(\\<^sub>B/2) * cos(\/2) + sin(\\<^sub>A/2) * sin(\\<^sub>B/2) * \*sin(\/2)) ++ (-\*sin(\/2)) * (sin(\\<^sub>A/2) * sin(\\<^sub>B/2) * cos(\/2) + exp(-\*\\<^sub>A)*cos(\\<^sub>A/2) * exp(-\*\\<^sub>B)*cos(\\<^sub>B/2) * \*sin(\/2)), + +cos(\/2) * (exp(\*\\<^sub>A)*cos(\\<^sub>A/2) * -sin(\\<^sub>B/2) * cos(\/2) + sin(\\<^sub>A/2) * exp(-\*\\<^sub>B)*cos(\\<^sub>B/2) * \*sin(\/2)) ++ (\*sin(\/2)) * (-sin(\\<^sub>A/2) * exp(\*\\<^sub>B)*cos(\\<^sub>B/2) * cos(\/2) + exp(-\*\\<^sub>A)*cos(\\<^sub>A/2) * sin(\\<^sub>B/2) * \*sin(\/2)), + +(\*sin(\/2)) * (exp(\*\\<^sub>A)*cos(\\<^sub>A/2) * -sin(\\<^sub>B/2) * cos(\/2) + sin(\\<^sub>A/2) * exp(-\*\\<^sub>B)*cos(\\<^sub>B/2) * \*sin(\/2)) ++ cos(\/2) * (-sin(\\<^sub>A/2) * exp(\*\\<^sub>B)*cos(\\<^sub>B/2) * cos(\/2) + exp(-\*\\<^sub>A)*cos(\\<^sub>A/2) * sin(\\<^sub>B/2) * \*sin(\/2)), + +(-\*sin(\/2)) * (exp(\*\\<^sub>A)*cos(\\<^sub>A/2) * exp(\*\\<^sub>B)*cos(\\<^sub>B/2) * cos(\/2) + sin(\\<^sub>A/2) * sin(\\<^sub>B/2) * \*sin(\/2)) ++ cos(\/2) * (sin(\\<^sub>A/2) * sin(\\<^sub>B/2) * cos(\/2) + exp(-\*\\<^sub>A)*cos(\\<^sub>A/2) * exp(-\*\\<^sub>B)*cos(\\<^sub>B/2) * \*sin(\/2)) +]]" + +lemma (in strategic_space_2p) psi_f: + shows "(J\<^sup>\) * \\<^sub>2 = \\<^sub>f" +proof + fix i j assume a0:"i < dim_row \\<^sub>f" and a1:"j < dim_col \\<^sub>f" + then show "((J\<^sup>\) * \\<^sub>2) $$ (i,j) = \\<^sub>f $$ (i,j)" + proof- + have "i\{0,1,2,3} \ j=0" + using a0 a1 mat_of_cols_list_def by auto + thus ?thesis + using mat_of_cols_list_def set_4 hermite_cnj_of_J by auto + qed +next + show "dim_row ((J\<^sup>\) * \\<^sub>2) = dim_row \\<^sub>f" + using mat_of_cols_list_def by simp +next + show "dim_col ((J\<^sup>\) * \\<^sub>2) = dim_col \\<^sub>f" + using mat_of_cols_list_def by simp +qed + +lemma (in prisoner) unit_vec_4_0_ket_is_state: + shows "state 2 |unit_vec 4 0\" + using state_def cpx_vec_length_def ket_vec_def unit_vec_def by (auto simp add: set_4) + +lemma cos_sin_squared_add_cpx: + "complex_of_real (cos (\/2)) * complex_of_real (cos (\/2)) - + \*complex_of_real (sin (\/2)) * (\*complex_of_real (sin (\/2))) = 1" + apply (auto simp add: algebra_simps) + by (metis of_real_add of_real_hom.hom_one of_real_mult sin_cos_squared_add3) + +lemma sin_cos_squared_add_cpx: + "\*complex_of_real (sin (\/2)) * (\*complex_of_real (sin (\/2))) - + complex_of_real (cos (\/2)) * complex_of_real (cos (\/2)) = -1" + apply (auto simp add: algebra_simps) + by (metis of_real_add of_real_hom.hom_one of_real_mult sin_cos_squared_add3) + +lemma (in prisoner) J_cnj_times_J: + shows "J\<^sup>\ * J = 1\<^sub>m 4" +proof + fix i j assume a0:"i < dim_row (1\<^sub>m 4)" and a1:"j < dim_col (1\<^sub>m 4)" + then show "(J\<^sup>\ * J) $$ (i,j) = 1\<^sub>m 4 $$ (i,j)" + proof- + have "i\{0,1,2,3} \ j\{0,1,2,3}" + using a0 a1 mat_of_cols_list_def by auto + thus ?thesis + using mat_of_cols_list_def hermite_cnj_of_J set_4 cos_sin_squared_add_cpx by auto + qed +next + show "dim_row (J\<^sup>\ * J) = dim_row (1\<^sub>m 4)" + using mat_of_cols_list_def by simp +next + show "dim_col (J\<^sup>\ * J) = dim_col (1\<^sub>m 4)" + using mat_of_cols_list_def by simp +qed + +lemma (in prisoner) J_times_J_cnj: + shows "J * (J\<^sup>\) = 1\<^sub>m 4" +proof + fix i j assume a0:"i < dim_row (1\<^sub>m 4)" and a1:"j < dim_col (1\<^sub>m 4)" + then show "(J * (J\<^sup>\)) $$ (i,j) = 1\<^sub>m 4 $$ (i,j)" + proof- + have "i\{0,1,2,3} \ j\{0,1,2,3}" + using a0 a1 mat_of_cols_list_def by auto + thus ?thesis + using mat_of_cols_list_def hermite_cnj_of_J set_4 cos_sin_squared_add_cpx by auto + qed +next + show "dim_row (J * (J\<^sup>\)) = dim_row (1\<^sub>m 4)" + using mat_of_cols_list_def by simp +next + show "dim_col (J * (J\<^sup>\)) = dim_col (1\<^sub>m 4)" + using mat_of_cols_list_def by simp +qed + +lemma (in prisoner) J_is_gate: + shows "gate 2 J" +proof + show "dim_row J = 2\<^sup>2" + using mat_of_cols_list_def by simp + moreover show "square_mat J" + using mat_of_cols_list_def by simp + ultimately show "unitary J" + using mat_of_cols_list_def unitary_def J_cnj_times_J J_times_J_cnj by auto +qed + +lemma (in strategic_space_2p) psi_one_is_state: + shows "state 2 \\<^sub>1" +proof- + have "state 2 (J * |unit_vec 4 0\)" + using unit_vec_4_0_ket_is_state J_is_gate by auto + then show ?thesis + using psi_one by simp +qed + +abbreviation (in strategic_space_2p) U\<^sub>A_cnj :: "complex Matrix.mat" where +"U\<^sub>A_cnj \ mat_of_cols_list 2 [[(exp(-\*\\<^sub>A))*cos(\\<^sub>A/2), sin(\\<^sub>A/2)], + [-sin(\\<^sub>A/2), (exp (\*\\<^sub>A))*cos(\\<^sub>A/2)]]" + +abbreviation (in strategic_space_2p) U\<^sub>B_cnj :: "complex Matrix.mat" where +"U\<^sub>B_cnj \ mat_of_cols_list 2 [[(exp(-\*\\<^sub>B))*cos(\\<^sub>B/2), sin(\\<^sub>B/2)], + [-sin(\\<^sub>B/2), (exp(\*\\<^sub>B))*cos(\\<^sub>B/2)]]" + +lemma (in strategic_space_2p) hermite_cnj_of_U\<^sub>A: + shows "U\<^sub>A\<^sup>\ = U\<^sub>A_cnj" +proof + fix i j assume a0:"i < dim_row U\<^sub>A_cnj" and a1:"j < dim_col U\<^sub>A_cnj" + then show "U\<^sub>A\<^sup>\ $$ (i,j) = U\<^sub>A_cnj $$ (i,j)" + proof- + have "i\{0,1} \ j\{0,1}" + using a0 a1 mat_of_cols_list_def by auto + thus ?thesis + using mat_of_cols_list_def dagger_def exp_of_real_cnj exp_of_real_cnj2 by auto + qed +next + show "dim_row (U\<^sub>A\<^sup>\) = dim_row U\<^sub>A_cnj" + using mat_of_cols_list_def by simp +next + show "dim_col (U\<^sub>A\<^sup>\) = dim_col U\<^sub>A_cnj" + using mat_of_cols_list_def by simp +qed + +lemma (in strategic_space_2p) hermite_cnj_of_U\<^sub>B: + shows "U\<^sub>B\<^sup>\ = U\<^sub>B_cnj" +proof + fix i j assume a0:"i < dim_row U\<^sub>B_cnj" and a1:"j < dim_col U\<^sub>B_cnj" + then show "U\<^sub>B\<^sup>\ $$ (i,j) = U\<^sub>B_cnj $$ (i,j)" + proof- + have "i\{0,1} \ j\{0,1}" + using a0 a1 mat_of_cols_list_def by auto + thus ?thesis + using mat_of_cols_list_def dagger_def exp_of_real_cnj exp_of_real_cnj2 by auto + qed +next + show "dim_row (U\<^sub>B\<^sup>\) = dim_row U\<^sub>B_cnj" + using mat_of_cols_list_def by simp +next + show "dim_col (U\<^sub>B\<^sup>\) = dim_col U\<^sub>B_cnj" + using mat_of_cols_list_def by simp +qed + +lemma exp_sin_cos_squared_add: + fixes x y :: real + shows "exp (- (\ * x)) * cos (y) * (exp (\ * x) * cos (y)) + sin(y) * sin(y) = 1" +proof- + have "exp (- (\ * x)) * cos (y) * (exp (\ * x) * cos (y)) = cos(y) * cos(y)" + using exp_minus_inverse by (auto simp add: algebra_simps) + then show ?thesis + by (metis of_real_add of_real_hom.hom_one sin_cos_squared_add3) +qed + +lemma (in strategic_space_2p) U\<^sub>A_cnj_times_U\<^sub>A: + shows "U\<^sub>A\<^sup>\ * U\<^sub>A = 1\<^sub>m 2" +proof + fix i j assume a0:"i < dim_row (1\<^sub>m 2)" and a1:"j < dim_col (1\<^sub>m 2)" + then show "(U\<^sub>A\<^sup>\ * U\<^sub>A) $$ (i,j) = 1\<^sub>m 2 $$ (i,j)" + proof- + have "i\{0,1} \ j\{0,1}" + using a0 a1 mat_of_cols_list_def by auto + thus ?thesis + using mat_of_cols_list_def cos_sin_squared_add_cpx hermite_cnj_of_U\<^sub>A exp_sin_cos_squared_add[of "\\<^sub>A" "\\<^sub>A / 2"] + by (auto simp add: set_2 algebra_simps) + qed +next + show "dim_row (U\<^sub>A\<^sup>\ * U\<^sub>A) = dim_row (1\<^sub>m 2)" + using mat_of_cols_list_def by simp +next + show "dim_col (U\<^sub>A\<^sup>\ * U\<^sub>A) = dim_col (1\<^sub>m 2)" + using mat_of_cols_list_def by simp +qed + +lemma (in strategic_space_2p) U\<^sub>A_times_U\<^sub>A_cnj: + shows "U\<^sub>A * (U\<^sub>A\<^sup>\) = 1\<^sub>m 2" +proof + fix i j assume a0:"i < dim_row (1\<^sub>m 2)" and a1:"j < dim_col (1\<^sub>m 2)" + then show "(U\<^sub>A * (U\<^sub>A\<^sup>\)) $$ (i,j) = 1\<^sub>m 2 $$ (i,j)" + proof- + have "i\{0,1} \ j\{0,1}" + using a0 a1 mat_of_cols_list_def by auto + thus ?thesis + using mat_of_cols_list_def cos_sin_squared_add_cpx hermite_cnj_of_U\<^sub>A exp_sin_cos_squared_add[of "\\<^sub>A" "\\<^sub>A / 2"] + by (auto simp add: set_2 algebra_simps) + qed +next + show "dim_row (U\<^sub>A * (U\<^sub>A\<^sup>\)) = dim_row (1\<^sub>m 2)" + using mat_of_cols_list_def by simp +next + show "dim_col (U\<^sub>A * (U\<^sub>A\<^sup>\)) = dim_col (1\<^sub>m 2)" + using mat_of_cols_list_def by simp +qed + +lemma (in strategic_space_2p) U\<^sub>B_cnj_times_U\<^sub>B: + shows "U\<^sub>B\<^sup>\ * U\<^sub>B = 1\<^sub>m 2" +proof + fix i j assume a0:"i < dim_row (1\<^sub>m 2)" and a1:"j < dim_col (1\<^sub>m 2)" + then show "(U\<^sub>B\<^sup>\ * U\<^sub>B) $$ (i,j) = 1\<^sub>m 2 $$ (i,j)" + proof- + have "i\{0,1} \ j\{0,1}" + using a0 a1 mat_of_cols_list_def by auto + thus ?thesis + using mat_of_cols_list_def cos_sin_squared_add_cpx hermite_cnj_of_U\<^sub>B exp_sin_cos_squared_add[of "\\<^sub>B" "\\<^sub>B / 2"] + by (auto simp add: set_2 algebra_simps) + qed +next + show "dim_row (U\<^sub>B\<^sup>\ * U\<^sub>B) = dim_row (1\<^sub>m 2)" + using mat_of_cols_list_def by simp +next + show "dim_col (U\<^sub>B\<^sup>\ * U\<^sub>B) = dim_col (1\<^sub>m 2)" + using mat_of_cols_list_def by simp +qed + +lemma (in strategic_space_2p) U\<^sub>B_times_U\<^sub>B_cnj: + shows "U\<^sub>B * (U\<^sub>B\<^sup>\) = 1\<^sub>m 2" +proof + fix i j assume a0:"i < dim_row (1\<^sub>m 2)" and a1:"j < dim_col (1\<^sub>m 2)" + then show "(U\<^sub>B * (U\<^sub>B\<^sup>\)) $$ (i,j) = 1\<^sub>m 2 $$ (i,j)" + proof- + have "i\{0,1} \ j\{0,1}" + using a0 a1 mat_of_cols_list_def by auto + thus ?thesis + using mat_of_cols_list_def cos_sin_squared_add_cpx hermite_cnj_of_U\<^sub>B exp_sin_cos_squared_add[of "\\<^sub>B" "\\<^sub>B / 2"] + by (auto simp add: set_2 algebra_simps) + qed +next + show "dim_row (U\<^sub>B * (U\<^sub>B\<^sup>\)) = dim_row (1\<^sub>m 2)" + using mat_of_cols_list_def by simp +next + show "dim_col (U\<^sub>B * (U\<^sub>B\<^sup>\)) = dim_col (1\<^sub>m 2)" + using mat_of_cols_list_def by simp +qed + +lemma (in strategic_space_2p) U\<^sub>A\<^sub>_is_gate: + shows "gate 1 U\<^sub>A" +proof + show "dim_row U\<^sub>A = 2^1" + using mat_of_cols_list_def by simp + moreover show "square_mat U\<^sub>A" + using mat_of_cols_list_def by simp + ultimately show "unitary U\<^sub>A" + using mat_of_cols_list_def unitary_def U\<^sub>A_cnj_times_U\<^sub>A U\<^sub>A_times_U\<^sub>A_cnj by auto +qed + +lemma (in strategic_space_2p) U\<^sub>B_is_gate: + shows "gate 1 U\<^sub>B" +proof + show "dim_row U\<^sub>B = 2^1" + using mat_of_cols_list_def by simp + moreover show "square_mat U\<^sub>B" + using mat_of_cols_list_def by simp + ultimately show "unitary U\<^sub>B" + using mat_of_cols_list_def unitary_def U\<^sub>B_cnj_times_U\<^sub>B U\<^sub>B_times_U\<^sub>B_cnj by auto +qed + +lemma (in strategic_space_2p) U\<^sub>A\<^sub>B_is_gate: + shows "gate 2 (U\<^sub>A \ U\<^sub>B)" +proof- + have "gate (1+1) (U\<^sub>A \ U\<^sub>B)" + using U\<^sub>A\<^sub>_is_gate U\<^sub>B_is_gate tensor_gate[of "1" "U\<^sub>A" "1" "U\<^sub>B"] by auto + then show ?thesis + by (auto simp add: numeral_2_eq_2) +qed + +lemma (in strategic_space_2p) psi_two_is_state: + shows "state 2 \\<^sub>2" +proof- + have "state 2 ((U\<^sub>A \ U\<^sub>B) * \\<^sub>1)" + using psi_one_is_state U\<^sub>A\<^sub>B_is_gate by auto + then show ?thesis + using psi_two by simp +qed + +lemma (in strategic_space_2p) J_cnj_is_gate: + shows "gate 2 (J\<^sup>\)" +proof + show "dim_row (J\<^sup>\) = 2\<^sup>2" + using mat_of_cols_list_def by simp + moreover show "square_mat (J\<^sup>\)" + using mat_of_cols_list_def by simp + moreover have "(J\<^sup>\)\<^sup>\ = J" + using dagger_of_dagger_is_id by auto + ultimately show "unitary (J\<^sup>\)" + using mat_of_cols_list_def unitary_def J_cnj_times_J J_times_J_cnj by auto +qed + +lemma (in strategic_space_2p) psi_f_is_state: + shows "state 2 \\<^sub>f" +proof- + have "state 2 ((J\<^sup>\) * \\<^sub>2)" + using psi_two_is_state J_cnj_is_gate by auto + then show ?thesis + using psi_f by simp +qed + +(* equation (1) in the paper *) +lemma (in strategic_space_2p) equation_one: + shows "(J\<^sup>\) * ((U\<^sub>A \ U\<^sub>B) * (J * |unit_vec 4 0\)) = \\<^sub>f" + using psi_one psi_two psi_f by auto + +abbreviation (in strategic_space_2p) prob00 :: "complex Matrix.mat \ real" where +"prob00 v \ if state 2 v then (cmod (v $$ (0,0)))\<^sup>2 else undefined" + +abbreviation (in strategic_space_2p) prob01 :: "complex Matrix.mat \ real" where +"prob01 v \ if state 2 v then (cmod (v $$ (1,0)))\<^sup>2 else undefined" + +abbreviation (in strategic_space_2p) prob10 :: "complex Matrix.mat \ real" where +"prob10 v \ if state 2 v then (cmod (v $$ (2,0)))\<^sup>2 else undefined" + +abbreviation (in strategic_space_2p) prob11 :: "complex Matrix.mat \ real" where +"prob11 v \ if state 2 v then (cmod (v $$ (3,0)))\<^sup>2 else undefined" + +definition (in strategic_space_2p) alice_payoff :: "real" where +"alice_payoff \ 3 * (prob00 \\<^sub>f) + 1 * (prob11 \\<^sub>f) + 0 * (prob01 \\<^sub>f) + 5 * (prob10 \\<^sub>f)" + +definition (in strategic_space_2p) bob_payoff :: "real" where +"bob_payoff \ 3 * (prob00 \\<^sub>f) + 1 * (prob11 \\<^sub>f) + 5 * (prob01 \\<^sub>f) + 0 * (prob10 \\<^sub>f)" + +definition (in strategic_space_2p) is_nash_eq :: "bool" where +"is_nash_eq \ +(\tA pA. strategic_space_2p \ tA pA \\<^sub>B \\<^sub>B \ + alice_payoff \ strategic_space_2p.alice_payoff \ tA pA \\<^sub>B \\<^sub>B) +\ +(\tB pB. strategic_space_2p \ \\<^sub>A \\<^sub>A tB pB \ + bob_payoff \ strategic_space_2p.bob_payoff \ \\<^sub>A \\<^sub>A tB pB)" + +definition (in strategic_space_2p) is_pareto_opt :: "bool" where +"is_pareto_opt \ \tA pA tB pB. strategic_space_2p \ tA pA tB pB \ +((strategic_space_2p.alice_payoff \ tA pA tB pB > alice_payoff \ + strategic_space_2p.bob_payoff \ tA pA tB pB < bob_payoff) \ + (strategic_space_2p.bob_payoff \ tA pA tB pB > bob_payoff \ + strategic_space_2p.alice_payoff \ tA pA tB pB < alice_payoff))" + +lemma (in strategic_space_2p) sum_of_prob: + fixes v :: "complex Matrix.mat" + assumes "state 2 v" + shows "(prob00 v) + (prob11 v) + (prob01 v) + (prob10 v) = 1" +proof- + have "(prob00 v) + (prob11 v) + (prob01 v) + (prob10 v) = + (cmod (v $$ (0,0)))\<^sup>2 + (cmod (v $$ (1,0)))\<^sup>2 + (cmod (v $$ (2,0)))\<^sup>2 + (cmod (v $$ (3,0)))\<^sup>2" + using assms by auto + then show ?thesis + using state_def assms cpx_vec_length_def by (auto simp add: set_4) +qed + +lemma (in strategic_space_2p) sum_payoff_le_6: + fixes tA pA tB pB :: real + shows "alice_payoff + bob_payoff \ 6" +proof- + have "alice_payoff + bob_payoff = 6 * (prob00 \\<^sub>f) + 2 * (prob11 \\<^sub>f) + 5 * (prob01 \\<^sub>f) + 5 * (prob10 \\<^sub>f)" + using alice_payoff_def bob_payoff_def psi_f_is_state by auto + then have "alice_payoff + bob_payoff \ 6 * ((prob00 \\<^sub>f) + (prob11 \\<^sub>f) + (prob01 \\<^sub>f) + (prob10 \\<^sub>f))" + using psi_f_is_state by (auto simp add: algebra_simps) + moreover have "(prob00 \\<^sub>f) + (prob11 \\<^sub>f) + (prob01 \\<^sub>f) + (prob10 \\<^sub>f) = 1" + using sum_of_prob[of "\\<^sub>f"] psi_f_is_state by auto + ultimately show ?thesis + by auto +qed + +lemma (in strategic_space_2p) coop_is_pareto_opt: + assumes "alice_payoff = 3 \ bob_payoff = 3" + shows "is_pareto_opt" + using is_pareto_opt_def strategic_space_2p.sum_payoff_le_6 assms by fastforce + + +subsection \The Separable Case\ + +lemma (in strategic_space_2p) separable_case_CC: (* both player cooperate *) + assumes "\ = 0" + shows "\\<^sub>A = 0 \ \\<^sub>A = 0 \ \\<^sub>B = 0 \ \\<^sub>B = 0 \ alice_payoff = 3 \ bob_payoff = 3" + using alice_payoff_def bob_payoff_def cos_sin_squared_add_cpx psi_f_is_state by auto + +lemma (in strategic_space_2p) separable_case_DD: (* both player defect *) + assumes "\ = 0" + shows "\\<^sub>A = 0 \ \\<^sub>A = pi \ \\<^sub>B = 0 \ \\<^sub>B = pi \ alice_payoff = 1 \ bob_payoff = 1" + using alice_payoff_def bob_payoff_def cos_sin_squared_add_cpx psi_f_is_state by auto + +lemma (in strategic_space_2p) separable_case_DC: (* Alice defects, and Bob cooperates *) + assumes "\ = 0" + shows "\\<^sub>A = 0 \ \\<^sub>A = pi \ \\<^sub>B = 0 \ \\<^sub>B = 0 \ alice_payoff = 5 \ bob_payoff = 0" + using alice_payoff_def bob_payoff_def sin_cos_squared_add_cpx psi_f_is_state by auto + +lemma (in strategic_space_2p) separable_alice_payoff_D\<^sub>B: +(* Alice's payoff in the separable case given that Bob defects *) + assumes "\ = 0" and "\\<^sub>B = 0 \ \\<^sub>B = pi" + shows "alice_payoff \ 1" + using alice_payoff_def assms sin_squared_le_one psi_f_is_state by auto + +lemma (in strategic_space_2p) separable_bob_payoff_D\<^sub>A: +(* Bob's payoff in the separable case given that Alice defects *) + assumes "\ = 0" and "\\<^sub>A = 0 \ \\<^sub>A = pi" + shows "bob_payoff \ 1" + using bob_payoff_def assms sin_squared_le_one psi_f_is_state by auto + +lemma (in strategic_space_2p) separable_case_DD_alice_opt: + assumes "\ = 0" and "\\<^sub>A = 0 \ \\<^sub>A = pi \ \\<^sub>B = 0 \ \\<^sub>B = pi" + shows "\tA pA. strategic_space_2p \ tA pA \\<^sub>B \\<^sub>B \ strategic_space_2p.alice_payoff \ tA pA \\<^sub>B \\<^sub>B \ alice_payoff" +proof + fix tA pA assume "strategic_space_2p \ tA pA \\<^sub>B \\<^sub>B" + then show "strategic_space_2p.alice_payoff \ tA pA \\<^sub>B \\<^sub>B \ alice_payoff" + using separable_case_DD strategic_space_2p.separable_alice_payoff_D\<^sub>B assms by auto +qed + +lemma (in strategic_space_2p) separable_case_DD_bob_opt: + assumes "\ = 0" and "\\<^sub>A = 0 \ \\<^sub>A = pi \ \\<^sub>B = 0 \ \\<^sub>B = pi" + shows "\tB pB. strategic_space_2p \ \\<^sub>A \\<^sub>A tB pB \ strategic_space_2p.bob_payoff \ \\<^sub>A \\<^sub>A tB pB \ bob_payoff" +proof + fix tB pB assume "strategic_space_2p \ \\<^sub>A \\<^sub>A tB pB" + then show "strategic_space_2p.bob_payoff \ \\<^sub>A \\<^sub>A tB pB \ bob_payoff" + using separable_case_DD strategic_space_2p.separable_bob_payoff_D\<^sub>A assms by auto +qed + +lemma (in strategic_space_2p) separable_case_DD_is_nash_eq: + assumes "\ = 0" + shows "\\<^sub>A = 0 \ \\<^sub>A = pi \ \\<^sub>B = 0 \ \\<^sub>B = pi \ is_nash_eq" + using is_nash_eq_def separable_case_DD_alice_opt separable_case_DD_bob_opt assms by auto + +lemma (in strategic_space_2p) separable_case_CC_is_not_nash_eq: + assumes "\ = 0" + shows "\\<^sub>A = 0 \ \\<^sub>A = 0 \ \\<^sub>B = 0 \ \\<^sub>B = 0 \ \ is_nash_eq" +proof + assume asm:"\\<^sub>A = 0 \ \\<^sub>A = 0 \ \\<^sub>B = 0 \ \\<^sub>B = 0" + then have f0:"strategic_space_2p \ pi 0 \\<^sub>B \\<^sub>B" + using strategic_space_2p_def strategic_space_2p_axioms_def prisoner_def asm by (simp add: assms) + then have "strategic_space_2p.alice_payoff \ pi 0 \\<^sub>B \\<^sub>B = 5" + using strategic_space_2p.separable_case_DC assms asm by blast + moreover have "alice_payoff = 3" + using separable_case_CC assms asm by blast + ultimately have "strategic_space_2p \ pi 0 \\<^sub>B \\<^sub>B \ strategic_space_2p.alice_payoff \ pi 0 \\<^sub>B \\<^sub>B > alice_payoff" + using f0 by simp + then show "\is_nash_eq" + using is_nash_eq_def by fastforce +qed + +lemma (in strategic_space_2p) separable_case_CC_is_pareto_optimal: + assumes "\ = 0" + shows "\\<^sub>A = 0 \ \\<^sub>A = 0 \ \\<^sub>B = 0 \ \\<^sub>B = 0 \ is_pareto_opt" + using coop_is_pareto_opt separable_case_CC assms by auto + + +subsection \The Maximally Entangled Case\ + +lemma exp_to_sin: + fixes x:: real + shows "exp (\ * x) - exp (-(\ * x)) = 2 * \ * (sin x)" + using exp_of_real exp_of_real_inv by simp + +lemma exp_to_cos: + fixes x:: real + shows "exp (\ * x) + exp (-(\ * x)) = 2 * (cos x)" + using exp_of_real exp_of_real_inv by simp + +lemma cmod_real_prod_squared: + fixes x y:: real + shows "(cmod (complex_of_real x * complex_of_real y))\<^sup>2 = x\<^sup>2 * y\<^sup>2" + by (simp add: norm_mult power_mult_distrib) + +lemma quantum_payoff_simp: + fixes x y:: real + shows "3 * (cmod (complex_of_real (sin x) * complex_of_real (cos y)))\<^sup>2 + + (cmod (complex_of_real (cos x) * complex_of_real (cos y)))\<^sup>2 = + 2 * (sin x)\<^sup>2 * (cos y)\<^sup>2 + (cos y)\<^sup>2" +proof- + have "3 * (sin x)\<^sup>2 * (cos y)\<^sup>2 + (cos x)\<^sup>2 * (cos y)\<^sup>2 = + (2 * (sin x)\<^sup>2 * (cos y)\<^sup>2) + ((sin x)\<^sup>2 + (cos x)\<^sup>2) * (cos y)\<^sup>2" + by (auto simp add: algebra_simps simp del: sin_cos_squared_add2) + then show ?thesis + by (simp add: cmod_real_prod_squared power_mult_distrib) +qed + +lemma quantum_payoff_le_3: + fixes x y:: real + shows "2 * (sin x)\<^sup>2 * (cos y)\<^sup>2 + (cos y)\<^sup>2 \ 3" +proof- + have "(sin x)\<^sup>2 * (cos y)\<^sup>2 \ 1" by (simp add: sin_squared_le_one cos_squared_le_one mult_le_one) + then have "2 * (sin x)\<^sup>2 * (cos y)\<^sup>2 \ 2" by simp + moreover have "(cos y)\<^sup>2 \ 1" + using cos_squared_le_one[of "y"] by simp + ultimately show ?thesis by simp +qed + +lemma sqrt_two_squared_cpx: "complex_of_real (sqrt 2) * complex_of_real (sqrt 2) = 2" + by (metis mult_2_right numeral_Bit0 of_real_mult of_real_numeral real_sqrt_four real_sqrt_mult) + +lemma hidden_sqrt_two_squared_cpx: "complex_of_real (sqrt 2) * (complex_of_real (sqrt 2) * x) / 4 = x/2" + using sqrt_two_squared_cpx by (auto simp add: algebra_simps) + +lemma (in strategic_space_2p) max_entangled_DD: +(* both players defects in the maximally entangled case *) + assumes "\ = pi/2" + shows "\\<^sub>A = 0 \ \\<^sub>A = pi \ \\<^sub>B = 0 \ \\<^sub>B = pi \ alice_payoff = 1 \ bob_payoff = 1" + using alice_payoff_def bob_payoff_def cos_sin_squared_add_cpx psi_f_is_state + by auto + +lemma (in strategic_space_2p) max_entangled_QQ: +(* both players play the move Q in the maximally entangled case *) + assumes "\ = pi/2" + shows "\\<^sub>A = pi/2 \ \\<^sub>A = 0 \ \\<^sub>B = pi/2 \ \\<^sub>B = 0 \ alice_payoff = 3 \ bob_payoff = 3" + using alice_payoff_def bob_payoff_def sin_cos_squared_add_cpx exp_of_half_pi exp_of_minus_half_pi psi_f_is_state + by auto + +lemma (in strategic_space_2p) max_entangled_QD: +(* Alice plays the move Q, and Bob defects in the maximally entangled case *) + assumes "\ = pi/2" + shows "\\<^sub>A = pi/2 \ \\<^sub>A = 0 \ \\<^sub>B = 0 \ \\<^sub>B = pi \ alice_payoff = 5 \ bob_payoff = 0" + using alice_payoff_def bob_payoff_def cos_sin_squared_add_cpx exp_of_half_pi exp_of_minus_half_pi + psi_f_is_state sqrt_two_squared_cpx + by (auto simp add: assms algebra_simps sin_45 cos_45) + +lemma (in strategic_space_2p) max_entangled_alice_payoff_Q\<^sub>B: +(* Alice's payoff in the maximally entangled case given that Bob plays the move Q *) + assumes "\ = pi/2" + shows "\\<^sub>B = pi/2 \ \\<^sub>B = 0 \ alice_payoff \ 3" +proof + assume asm:"\\<^sub>B = pi/2 \ \\<^sub>B = 0" + have "\\<^sub>f $$ (0,0) = -(sin \\<^sub>A) * (cos (\\<^sub>A/2))" + proof- + have "\\<^sub>f $$ (0,0) = \ * (sqrt 2/2) * (sqrt 2/2) * (cos (\\<^sub>A/2)) * exp (\ * \\<^sub>A) + + \ * (sqrt 2/2) * (sqrt 2/2) * (cos (\\<^sub>A/2)) * -exp (-(\ * \\<^sub>A))" + using mat_of_cols_list_def asm assms exp_of_half_pi exp_of_minus_half_pi + by (auto simp add: sin_of_quarter_pi[of "\"] cos_of_quarter_pi[of "\"] algebra_simps) + then have "\\<^sub>f $$ (0,0) = \ * (sqrt 2/2) * (sqrt 2/2) * (cos (\\<^sub>A/2)) * (exp (\ * \\<^sub>A) - exp (-(\ * \\<^sub>A)))" + by (auto simp add: algebra_simps) + then have "\\<^sub>f $$ (0,0) = \ * (cos (\\<^sub>A/2)) * (1/2) * (exp (\ * \\<^sub>A) - exp (-(\ * \\<^sub>A)))" + using sqrt_two_squared_cpx by (auto simp add: algebra_simps) + then show ?thesis + using exp_to_sin by (simp add: algebra_simps) + qed + moreover have "\\<^sub>f $$ (1,0) = sin (\\<^sub>A/2)" + using mat_of_cols_list_def asm assms exp_of_half_pi exp_of_minus_half_pi sqrt_two_squared_cpx + by (auto simp add: sin_of_quarter_pi[of "\"] cos_of_quarter_pi[of "\"]) + moreover have "\\<^sub>f $$ (2,0) = 0" + using mat_of_cols_list_def asm assms exp_of_half_pi exp_of_minus_half_pi sqrt_two_squared_cpx + by (auto simp add: sin_of_quarter_pi[of "\"] cos_of_quarter_pi[of "\"] algebra_simps) + moreover have "\\<^sub>f $$ (3,0) = (cos \\<^sub>A) * (cos (\\<^sub>A/2))" + proof- + have "\\<^sub>f $$ (3,0) = exp (\ * \\<^sub>A) * (cos (\\<^sub>A/2)) * (sqrt 2/2) * (sqrt 2/2) + + exp (- (\ * \\<^sub>A)) * (cos (\\<^sub>A/2)) * (sqrt 2/2) * (sqrt 2/2)" + using mat_of_cols_list_def asm assms exp_of_half_pi exp_of_minus_half_pi + by (auto simp add: sin_of_quarter_pi[of "\"] cos_of_quarter_pi[of "\"] algebra_simps) + then have "\\<^sub>f $$ (3,0) = (exp (\ * \\<^sub>A) + exp (-(\ * \\<^sub>A))) * (cos (\\<^sub>A/2)) * (sqrt 2/2) * (sqrt 2/2)" + by (auto simp add: algebra_simps) + then have "\\<^sub>f $$ (3,0) = (exp (\ * \\<^sub>A) + exp (-(\ * \\<^sub>A))) * (cos (\\<^sub>A/2)) * (1/2)" + using sqrt_two_squared_cpx hidden_sqrt_two_squared_cpx by (auto simp add: algebra_simps) + then show ?thesis + using exp_to_cos by (simp add: algebra_simps) + qed + ultimately show "alice_payoff \ 3" + using alice_payoff_def psi_f_is_state quantum_payoff_simp quantum_payoff_le_3 + by auto +qed + +lemma (in strategic_space_2p) max_entangled_bob_payoff_Q\<^sub>A: +(* Bob's payoff in the maximally entangled case given that Alice plays the move Q *) + assumes "\ = pi/2" + shows "\\<^sub>A = pi/2 \ \\<^sub>A = 0 \ bob_payoff \ 3" +proof + assume asm:"\\<^sub>A = pi/2 \ \\<^sub>A = 0" + have "\\<^sub>f $$ (0,0) = -(sin \\<^sub>B) * (cos (\\<^sub>B/2))" + proof- + have "\\<^sub>f $$ (0,0) = \ * (sqrt 2/2) * (sqrt 2/2) * (cos (\\<^sub>B/2)) * exp (\ * \\<^sub>B) + + \ * (sqrt 2/2) * (sqrt 2/2) * (cos (\\<^sub>B/2)) * -exp (-(\ * \\<^sub>B))" + using mat_of_cols_list_def asm assms exp_of_half_pi exp_of_minus_half_pi + by (auto simp add: sin_of_quarter_pi[of "\"] cos_of_quarter_pi[of "\"] algebra_simps) + then have "\\<^sub>f $$ (0,0) = \ * (sqrt 2/2) * (sqrt 2/2) * (cos (\\<^sub>B/2)) * (exp (\ * \\<^sub>B) - exp (-(\ * \\<^sub>B)))" + by (auto simp add: algebra_simps) + then have "\\<^sub>f $$ (0,0) = \ * (cos (\\<^sub>B/2)) * (1/2) * (exp (\ * \\<^sub>B) - exp (-(\ * \\<^sub>B)))" + using sqrt_two_squared_cpx by (auto simp add: algebra_simps) + then show ?thesis + using exp_to_sin by (simp add: algebra_simps) + qed + moreover have "\\<^sub>f $$ (1,0) = 0" + using mat_of_cols_list_def asm assms exp_of_half_pi exp_of_minus_half_pi sqrt_two_squared_cpx + by (auto simp add: sin_of_quarter_pi[of "\"] cos_of_quarter_pi[of "\"] algebra_simps) + moreover have "\\<^sub>f $$ (2,0) = sin (\\<^sub>B/2)" + using mat_of_cols_list_def asm assms exp_of_half_pi exp_of_minus_half_pi sqrt_two_squared_cpx + by (auto simp add: sin_of_quarter_pi[of "\"] cos_of_quarter_pi[of "\"] algebra_simps) + moreover have "\\<^sub>f $$ (3,0) = (cos \\<^sub>B) * (cos (\\<^sub>B/2))" + proof- + have "\\<^sub>f $$ (3,0) = exp (\ * \\<^sub>B) * (cos (\\<^sub>B/2)) * (sqrt 2/2) * (sqrt 2/2) + + exp (- (\ * \\<^sub>B)) * (cos (\\<^sub>B/2)) * (sqrt 2/2) * (sqrt 2/2)" + using mat_of_cols_list_def asm assms exp_of_half_pi exp_of_minus_half_pi + by (auto simp add: sin_of_quarter_pi[of "\"] cos_of_quarter_pi[of "\"] algebra_simps) + then have "\\<^sub>f $$ (3,0) = (exp (\ * \\<^sub>B) + exp (-(\ * \\<^sub>B))) * (cos (\\<^sub>B/2)) * (sqrt 2/2) * (sqrt 2/2)" + by (auto simp add: algebra_simps) + then have "\\<^sub>f $$ (3,0) = (exp (\ * \\<^sub>B) + exp (-(\ * \\<^sub>B))) * (cos (\\<^sub>B/2)) * (1/2)" + using sqrt_two_squared_cpx hidden_sqrt_two_squared_cpx by (auto simp add: algebra_simps) + then show ?thesis + using exp_to_cos by (simp add: algebra_simps) + qed + ultimately show "bob_payoff \ 3" + using bob_payoff_def psi_f_is_state quantum_payoff_simp quantum_payoff_le_3 + by auto +qed + +lemma (in strategic_space_2p) max_entangled_DD_is_not_nash_eq: + assumes "\ = pi/2" + shows "\\<^sub>A = 0 \ \\<^sub>A = pi \ \\<^sub>B = 0 \ \\<^sub>B = pi \ \is_nash_eq" +proof + assume asm:"\\<^sub>A = 0 \ \\<^sub>A = pi \ \\<^sub>B = 0 \ \\<^sub>B = pi" + then have f0:"strategic_space_2p \ 0 (pi/2) \\<^sub>B \\<^sub>B" + using strategic_space_2p_def strategic_space_2p_axioms_def prisoner_def asm by (simp add: assms) + then have "strategic_space_2p.alice_payoff \ 0 (pi/2) \\<^sub>B \\<^sub>B = 5" + using strategic_space_2p.max_entangled_QD assms asm by blast + moreover have "alice_payoff = 1" + using max_entangled_DD assms asm by blast + ultimately have "strategic_space_2p \ 0 (pi/2) \\<^sub>B \\<^sub>B \ strategic_space_2p.alice_payoff \ 0 (pi/2) \\<^sub>B \\<^sub>B > alice_payoff" + using f0 by simp + then show "\is_nash_eq" + using is_nash_eq_def by fastforce +qed + +lemma (in strategic_space_2p) max_entangled_alice_opt: + assumes "\ = pi/2" and "\\<^sub>A = pi/2 \ \\<^sub>A = 0 \ \\<^sub>B = pi/2 \ \\<^sub>B = 0" + shows "\tA pA. strategic_space_2p \ tA pA \\<^sub>B \\<^sub>B \ strategic_space_2p.alice_payoff \ tA pA \\<^sub>B \\<^sub>B \ alice_payoff" +proof + fix tA pA assume "strategic_space_2p \ tA pA \\<^sub>B \\<^sub>B" + then have "strategic_space_2p.alice_payoff \ tA pA \\<^sub>B \\<^sub>B \ 3" + using strategic_space_2p.max_entangled_alice_payoff_Q\<^sub>B assms by blast + moreover have "alice_payoff = 3" + using max_entangled_QQ assms by blast + ultimately show "strategic_space_2p.alice_payoff \ tA pA \\<^sub>B \\<^sub>B \ alice_payoff" + by simp +qed + +lemma (in strategic_space_2p) max_entangled_bob_opt: + assumes "\ = pi/2" and "\\<^sub>A = pi/2 \ \\<^sub>A = 0 \ \\<^sub>B = pi/2 \ \\<^sub>B = 0" + shows "\tB pB. strategic_space_2p \ \\<^sub>A \\<^sub>A tB pB \ strategic_space_2p.bob_payoff \ \\<^sub>A \\<^sub>A tB pB \ bob_payoff" +proof + fix tB pB assume "strategic_space_2p \ \\<^sub>A \\<^sub>A tB pB" + then have "strategic_space_2p.bob_payoff \ \\<^sub>A \\<^sub>A tB pB \ 3" + using strategic_space_2p.max_entangled_bob_payoff_Q\<^sub>A assms by blast + moreover have "bob_payoff = 3" + using max_entangled_QQ assms by blast + ultimately show "strategic_space_2p.bob_payoff \ \\<^sub>A \\<^sub>A tB pB \ bob_payoff" + by simp +qed + +lemma (in strategic_space_2p) max_entangled_QQ_is_nash_eq: + assumes "\ = pi/2" + shows "\\<^sub>A = pi/2 \ \\<^sub>A = 0 \ \\<^sub>B = pi/2 \ \\<^sub>B = 0 \ is_nash_eq" + using max_entangled_alice_opt max_entangled_bob_opt is_nash_eq_def assms by blast + +lemma (in strategic_space_2p) max_entangled_QQ_is_pareto_optimal: + assumes "\ = pi/2" + shows "\\<^sub>A = pi/2 \ \\<^sub>A = 0 \ \\<^sub>B = pi/2 \ \\<^sub>B = 0 \ is_pareto_opt" + using coop_is_pareto_opt max_entangled_QQ assms by blast + + +subsection \The Unfair Strategy Case\ + +lemma half_sqrt_two_squared: "2 * (sqrt 2 / 2)\<^sup>2 = 1" + by (auto simp add: power2_eq_square) + +lemma (in strategic_space_2p) max_entangled_MD: +(* Alice plays the "miracle move", and Bob plays the classical defect move in the maximally entangled case *) + assumes "\ = pi/2" + shows "\\<^sub>A = pi/2 \ \\<^sub>A = pi/2 \ \\<^sub>B = 0 \ \\<^sub>B = pi \ alice_payoff = 3 \ bob_payoff = 1/2" +proof + assume asm:"\\<^sub>A = pi/2 \ \\<^sub>A = pi/2 \ \\<^sub>B = 0 \ \\<^sub>B = pi" + show "alice_payoff = 3 \ bob_payoff = 1/2" + using alice_payoff_def bob_payoff_def sqrt_two_squared_cpx half_sqrt_two_squared + exp_of_half_pi[of "pi/2"] exp_of_minus_half_pi[of "pi/2"] psi_f_is_state + by (auto simp add: asm assms sin_45 cos_45 algebra_simps) +qed + +lemma (in strategic_space_2p) max_entangled_MC: +(* Alice plays the "miracle move", and Bob plays the classical defect move in the maximally entangled case *) + assumes "\ = pi/2" + shows "\\<^sub>A = pi/2 \ \\<^sub>A = pi/2 \ \\<^sub>B = 0 \ \\<^sub>B = 0 \ alice_payoff = 3 \ bob_payoff = 1/2" +proof + assume asm:"\\<^sub>A = pi/2 \ \\<^sub>A = pi/2 \ \\<^sub>B = 0 \ \\<^sub>B = 0" + show "alice_payoff = 3 \ bob_payoff = 1/2" + using alice_payoff_def bob_payoff_def sqrt_two_squared_cpx half_sqrt_two_squared + exp_of_half_pi[of "pi/2"] exp_of_minus_half_pi[of "pi/2"] psi_f_is_state + by (auto simp add: asm assms sin_45 cos_45 algebra_simps) +qed + +lemma (in strategic_space_2p) max_entangled_MH: +(* Alice plays the "miracle move", and Bob plays the classical half move in the maximally entangled case *) + assumes "\ = pi/2" + shows "\\<^sub>A = pi/2 \ \\<^sub>A = pi/2 \ \\<^sub>B = 0 \ \\<^sub>B = pi/2 \ alice_payoff = 1 \ bob_payoff = 1" +proof + assume asm:"\\<^sub>A = pi/2 \ \\<^sub>A = pi/2 \ \\<^sub>B = 0 \ \\<^sub>B = pi/2" + show "alice_payoff = 1 \ bob_payoff = 1" + using alice_payoff_def bob_payoff_def sqrt_two_squared_cpx half_sqrt_two_squared + exp_of_half_pi[of "pi/2"] exp_of_minus_half_pi[of "pi/2"] psi_f_is_state + by (auto simp add: asm assms sin_45 cos_45 algebra_simps) +qed + +(* This is the definition of M in equation (9) *) +abbreviation M :: "complex Matrix.mat" where +"M \ mat_of_cols_list 2 [[\ * sqrt(2)/2, -1 * sqrt(2)/2], + [1 * sqrt(2)/2, -\ * sqrt(2)/2]]" + +lemma (in strategic_space_2p) M_correct: + assumes "\\<^sub>A = pi/2 \ \\<^sub>A = pi/2" + shows "U\<^sub>A = M" +proof + show "dim_row U\<^sub>A = dim_row M" using mat_of_cols_list_def by simp + show "dim_col U\<^sub>A = dim_col M" using mat_of_cols_list_def by simp + fix i j assume a0:"i < dim_row M" and a1:"j < dim_col M" + then show "U\<^sub>A $$ (i,j) = M $$ (i,j)" + proof- + have "i\{0,1} \ j\{0,1}" + using a0 a1 mat_of_cols_list_def by auto + thus ?thesis + using mat_of_cols_list_def exp_of_half_pi[of "pi/2"] exp_of_minus_half_pi[of "pi/2"] + by (auto simp add: assms sin_45 cos_45) + qed +qed + +lemma hidden_sqrt_two_squared_cpx2: + fixes x y :: complex + shows "(sqrt 2) * ((sqrt 2) * (x * y)) / 2 = x * y" + using sqrt_two_squared_cpx by auto + +lemma (in strategic_space_2p) unfair_strategy_no_benefit: +(* Two players' payoffs in the maximally entangled case given that Alice plays a quantum move and Bob +plays a classical move with the same \ *) + assumes "\ = pi/2" + shows "\\<^sub>A = pi/2 \ \\<^sub>B = 0 \ \\<^sub>A = \\<^sub>B \ alice_payoff = 1 \ bob_payoff = 1" +proof + assume asm:"\\<^sub>A = pi/2 \ \\<^sub>B = 0 \ \\<^sub>A = \\<^sub>B" + have "\\<^sub>f $$ (0,0) = 0" + using exp_of_half_pi[of "pi/2"] exp_of_minus_half_pi[of "pi/2"] + by (auto simp add: asm assms sin_45 cos_45 algebra_simps) + moreover have "\\<^sub>f $$ (1,0) = 0" + using exp_of_half_pi[of "pi/2"] exp_of_minus_half_pi[of "pi/2"] + by (auto simp add: asm assms sin_45 cos_45 algebra_simps) + moreover have "\\<^sub>f $$ (2,0) = 0" + using exp_of_half_pi[of "pi/2"] exp_of_minus_half_pi[of "pi/2"] + by (auto simp add: asm assms sin_45 cos_45 hidden_sqrt_two_squared_cpx2 algebra_simps) + moreover have "\\<^sub>f $$ (3,0) = 1" + using exp_of_half_pi[of "pi/2"] exp_of_minus_half_pi[of "pi/2"] cos_sin_squared_add_cpx + by (auto simp add: asm assms sin_45 cos_45 hidden_sqrt_two_squared_cpx2 algebra_simps) + ultimately show "alice_payoff = 1 \ bob_payoff = 1" + using alice_payoff_def bob_payoff_def psi_f_is_state + by auto +qed + +(* +Bibliography: + +@ARTICLE{EWL, + author = {{Eisert}, J. and {Wilkens}, M. and {Lewenstein}, M.}, + title = "{Quantum Games and Quantum Strategies}", + journal = {Physical Review Letters}, + eprint = {quant-ph/9806088}, + year = 1999, + month = oct, + volume = 83, + pages = {3077-3080}, + doi = {10.1103/PhysRevLett.83.3077}, + adsurl = {https://ui.adsabs.harvard.edu/abs/1999PhRvL..83.3077E}, + adsnote = {Provided by the SAO/NASA Astrophysics Data System} +} +*) +end \ No newline at end of file diff --git a/thys/Isabelle_Marries_Dirac/Quantum_Teleportation.thy b/thys/Isabelle_Marries_Dirac/Quantum_Teleportation.thy new file mode 100755 --- /dev/null +++ b/thys/Isabelle_Marries_Dirac/Quantum_Teleportation.thy @@ -0,0 +1,702 @@ +(* +Authors: + + Anthony Bordg, University of Cambridge, apdb3@cam.ac.uk; + Yijun He, University of Cambridge, yh403@cam.ac.uk +*) + +section \Quantum Teleportation\ + +theory Quantum_Teleportation +imports + More_Tensor + Basics + Measurement +begin + + +definition alice:: "complex Matrix.mat \ complex Matrix.mat" where +"alice \ \ (H \ Id 2) * ((CNOT \ Id 1) * (\ \ |\\<^sub>0\<^sub>0\))" + +abbreviation M1:: "complex Matrix.mat" where +"M1 \ mat_of_cols_list 8 [[1, 0, 0, 0, 0, 0, 0, 0], + [0, 1, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 0, 0, 0, 0], + [0, 0, 0, 1, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 1, 0], + [0, 0, 0, 0, 0, 0, 0, 1], + [0, 0, 0, 0, 1, 0, 0, 0], + [0, 0, 0, 0, 0, 1, 0, 0]]" + +lemma tensor_prod_of_cnot_id_1: + shows "(CNOT \ Id 1) = M1" +proof + show "dim_col (CNOT \ Id 1) = dim_col M1" + by(simp add: CNOT_def Id_def mat_of_cols_list_def) + show "dim_row (CNOT \ Id 1) = dim_row M1" + by(simp add: CNOT_def Id_def mat_of_cols_list_def) + fix i j::nat assume "i < dim_row M1" and "j < dim_col M1" + then have "i \ {0..<8} \ j \ {0..<8}" + by (auto simp add: mat_of_cols_list_def) + then show "(CNOT \ Id 1) $$ (i, j) = M1 $$ (i, j)" + by (auto simp add: Id_def CNOT_def mat_of_cols_list_def) +qed + +abbreviation M2:: "complex Matrix.mat" where +"M2 \ mat_of_cols_list 8 [[1/sqrt(2), 0, 0, 0, 1/sqrt(2), 0, 0, 0], + [0, 1/sqrt(2), 0, 0, 0, 1/sqrt(2), 0, 0], + [0, 0, 1/sqrt(2), 0, 0, 0, 1/sqrt(2), 0], + [0, 0, 0, 1/sqrt(2), 0, 0, 0, 1/sqrt(2)], + [1/sqrt(2), 0, 0, 0, -1/sqrt(2), 0, 0, 0], + [0, 1/sqrt(2), 0, 0, 0, -1/sqrt(2), 0, 0], + [0, 0, 1/sqrt(2), 0, 0, 0, -1/sqrt(2), 0], + [0, 0, 0, 1/sqrt(2), 0, 0, 0, -1/sqrt(2)]]" + +lemma tensor_prod_of_h_id_2: + shows "(H \ Id 2) = M2" +proof + show "dim_col (H \ Id 2) = dim_col M2" + by(simp add: H_def Id_def mat_of_cols_list_def) + show "dim_row (H \ Id 2) = dim_row M2" + by(simp add: H_def Id_def mat_of_cols_list_def) + fix i j::nat assume "i < dim_row M2" and "j < dim_col M2" + then have "i \ {0..<8} \ j \ {0..<8}" + by (auto simp add: mat_of_cols_list_def) + then show "(H \ Id 2) $$ (i, j) = M2 $$ (i, j)" + by (auto simp add: Id_def H_def mat_of_cols_list_def) +qed + +lemma alice_step_1_state [simp]: + assumes "state 1 \" + shows "state 3 (\ \ |\\<^sub>0\<^sub>0\)" + using assms bell00_is_state tensor_state by(metis One_nat_def Suc_1 numeral_3_eq_3 plus_1_eq_Suc) + +lemma alice_step_2_state: + assumes "state 1 \" + shows "state 3 ((CNOT \ Id 1) * (\ \ |\\<^sub>0\<^sub>0\))" +proof- + have "gate 3 (CNOT \ Id 1)" + using CNOT_is_gate id_is_gate tensor_gate by (metis numeral_plus_one semiring_norm(5)) + then show "state 3 ((CNOT \ Id 1) * (\ \ |\\<^sub>0\<^sub>0\))" using assms by simp +qed + +lemma alice_state [simp]: + assumes "state 1 \" + shows "state 3 (alice \) " +proof- + have "gate 3 (H \ Id 2)" + using tensor_gate id_is_gate H_is_gate by(metis eval_nat_numeral(3) plus_1_eq_Suc) + then show ?thesis + using assms alice_step_2_state by(simp add: alice_def) +qed + +lemma alice_step_1: + assumes "state 1 \" and "\ = \ $$ (0,0)" and "\ = \ $$ (1,0)" + shows "(\ \ |\\<^sub>0\<^sub>0\) = mat_of_cols_list 8 [[\/sqrt(2),0,0,\/sqrt(2),\/sqrt(2),0,0,\/sqrt(2)]]" +proof + define v where asm:"v = mat_of_cols_list 8 [[\/sqrt(2),0,0,\/sqrt(2),\/sqrt(2),0,0,\/sqrt(2)]]" + then show "dim_row (\ \ |\\<^sub>0\<^sub>0\) = dim_row v" + using assms(1) alice_step_1_state state.dim_row mat_of_cols_list_def by fastforce + show "dim_col (\ \ |\\<^sub>0\<^sub>0\) = dim_col v" + using assms(1) alice_step_1_state state.is_column asm mat_of_cols_list_def by fastforce + show "\i j. i < dim_row v \ j < dim_col v \ (\ \ |\\<^sub>0\<^sub>0\) $$ (i,j) = v $$ (i,j)" + proof- + fix i j assume "i < dim_row v" and "j < dim_col v" + then have "i \ {0..<8} \ j = 0" + using asm by (auto simp add: mat_of_cols_list_def) + moreover have "dim_row |\\<^sub>0\<^sub>0\ = 4" + using bell00_is_state state_def by simp + moreover have "dim_col |\\<^sub>0\<^sub>0\ = 1" + using bell00_is_state state_def by simp + ultimately show "(\ \ |\\<^sub>0\<^sub>0\) $$ (i, j) = v $$ (i,j)" + using state_def assms asm by (auto simp add: bell00_def) + qed +qed + +lemma alice_step_2: + assumes "state 1 \" and "\ = \ $$ (0,0)" and "\ = \ $$ (1,0)" + shows "(CNOT \ Id 1) * (\ \ |\\<^sub>0\<^sub>0\) = mat_of_cols_list 8 [[\/sqrt(2),0,0,\/sqrt(2),0,\/sqrt(2),\/sqrt(2),0]]" +proof + have f0:"(\ \ |\\<^sub>0\<^sub>0\) = mat_of_cols_list 8 [[\/sqrt(2),0,0,\/sqrt(2),\/sqrt(2),0,0,\/sqrt(2)]]" + using assms alice_step_1 by simp + define v where asm:"v = mat_of_cols_list 8 [[\/sqrt(2),0,0,\/sqrt(2),0,\/sqrt(2),\/sqrt(2),0]]" + then show "dim_row ((CNOT \ Id 1) * (\ \ |\\<^sub>0\<^sub>0\)) = dim_row v" + using assms(1) alice_step_2_state state.dim_row mat_of_cols_list_def by fastforce + show "dim_col ((CNOT \ Id 1) * (\ \ |\\<^sub>0\<^sub>0\)) = dim_col v" + using assms(1) alice_step_2_state state.is_column asm mat_of_cols_list_def by fastforce + show "\i j. i j ((CNOT \ Id 1) * (\ \ |\\<^sub>0\<^sub>0\)) $$ (i,j) = v $$ (i,j)" + proof- + fix i j assume "i < dim_row v" and "j < dim_col v" + then have "i \ {0..<8::nat} \ j = 0" + using asm by (auto simp add: mat_of_cols_list_def) + then have "(M1 * (\ \ |\\<^sub>0\<^sub>0\)) $$ (i,j) = v $$ (i,j)" + by (auto simp add: f0 asm mat_of_cols_list_def times_mat_def scalar_prod_def) + then show "((CNOT \ Id 1) * (\ \ |\\<^sub>0\<^sub>0\)) $$ (i,j) = v $$ (i,j)" + using tensor_prod_of_cnot_id_1 by simp + qed +qed + +lemma alice_result: + assumes "state 1 \" and "\ = \ $$ (0,0)" and "\ = \ $$ (1,0)" + shows "alice \ = mat_of_cols_list 8 [[\/2, \/2, \/2, \/2, \/2, -\/2, -\/2, \/2]]" +proof + define v where a0:"v = mat_of_cols_list 8 [[\/2, \/2, \/2, \/2, \/2, -\/2, -\/2, \/2]]" + define w where a1:"w = (CNOT \ Id 1) * (\ \ |\\<^sub>0\<^sub>0\)" + then have f0:"w = mat_of_cols_list 8 [[\/sqrt(2), 0, 0, \/sqrt(2), 0, \/sqrt(2), \/sqrt(2), 0]]" + using assms alice_step_2 by simp + show "dim_row (alice \) = dim_row v" + using assms(1) alice_state state_def a0 by (simp add: mat_of_cols_list_def) + show "dim_col (alice \) = dim_col v" + using assms(1) alice_state state_def a0 by (simp add: mat_of_cols_list_def) + show "\i j. i < dim_row v \ j < dim_col v \ alice \ $$ (i,j) = v $$ (i,j)" + proof- + fix i j assume "i < dim_row v" and "j < dim_col v" + then have "i \ {0..<8} \ j = 0" + using a0 by (auto simp add: Tensor.mat_of_cols_list_def) + then have "(M2 * w) $$ (i,j) = v $$ (i,j)" + by (auto simp add: f0 a0 mat_of_cols_list_def times_mat_def scalar_prod_def) + then show "alice \ $$ (i,j) = v $$ (i,j)" + by (simp add: tensor_prod_of_h_id_2 alice_def a1) + qed +qed + +text \ +An application of function @{term "alice"} to a state @{term "\"} of a 1-qubit system results in the following cases. +\ + +definition alice_meas:: "complex Matrix.mat \ _list" where +"alice_meas \ = [ + ((prob0 3 (alice \) 0) * (prob0 3 (post_meas0 3 (alice \) 0) 1), post_meas0 3 (post_meas0 3 (alice \) 0) 1) +, ((prob0 3 (alice \) 0) * (prob1 3 (post_meas0 3 (alice \) 0) 1), post_meas1 3 (post_meas0 3 (alice \) 0) 1) +, ((prob1 3 (alice \) 0) * (prob0 3 (post_meas1 3 (alice \) 0) 1), post_meas0 3 (post_meas1 3 (alice \) 0) 1) +, ((prob1 3 (alice \) 0) * (prob1 3 (post_meas1 3 (alice \) 0) 1), post_meas1 3 (post_meas1 3 (alice \) 0) 1) +]" + +definition alice_pos:: "complex Matrix.mat \ complex Matrix.mat \ bool" where +"alice_pos \ q \ q = mat_of_cols_list 8 [[\ $$ (0,0), \ $$ (1,0), 0, 0, 0, 0, 0, 0]] \ + q = mat_of_cols_list 8 [[0, 0, \ $$ (1,0), \ $$ (0,0), 0, 0, 0, 0]] \ + q = mat_of_cols_list 8 [[0, 0, 0, 0, \ $$ (0,0), - \ $$ (1,0), 0, 0]] \ + q = mat_of_cols_list 8 [[0, 0, 0, 0, 0, 0, - \ $$ (1,0), \ $$ (0,0)]]" + +lemma phi_vec_length: + assumes "state 1 \" + shows "cmod(\ $$ (0,0))^2 + cmod(\ $$ (Suc 0,0))^2 = 1" + using set_2 assms state_def Matrix.col_def cpx_vec_length_def by(auto simp add: atLeast0LessThan) + +lemma select_index_3_subsets [simp]: + shows "{j::nat. select_index 3 0 j} = {4,5,6,7} \ + {j::nat. j < 8 \ \ select_index 3 0 j} = {0,1,2,3} \ + {j::nat. select_index 3 1 j} = {2,3,6,7} \ + {j::nat. j < 8 \ \ select_index 3 1 j} = {0,1,4,5}" +proof- + have "{j::nat. select_index 3 0 j} = {4,5,6,7}" by (auto simp add: select_index_def) + moreover have "{j::nat. j < 8 \ \ select_index 3 0 j} = {0,1,2,3}" by(auto simp add: select_index_def) + moreover have f1:"{j::nat. select_index 3 1 j} = {2,3,6,7}" + proof + show "{j. select_index 3 1 j} \ {2,3,6,7}" + proof + fix j::nat assume "j \ {j. select_index 3 1 j}" + then have "j \ {0..<8} \ j mod 4 \ {2,3}" by (auto simp add: select_index_def) + then show "j \ {2,3,6,7}" by auto + qed + show "{2,3,6,7} \ {j. select_index 3 1 j}" by (auto simp add: select_index_def) + qed + moreover have "{j::nat. j < 8 \ \ select_index 3 1 j} = {0,1,4,5}" + proof- + have "{j::nat. j < 8 \ j \ {2,3,6,7}} = {0,1,4,5}" by auto + then show ?thesis using f1 by blast + qed + ultimately show ?thesis by simp +qed + +lemma prob_index_0_alice: + assumes "state 1 \" + shows "prob0 3 (alice \) 0 = 1/2 \ prob1 3 (alice \) 0 = 1/2" +proof + show "prob0 3 (alice \) 0 = 1/2" + using alice_result assms prob0_def alice_state + apply auto by (metis (no_types, hide_lams) One_nat_def phi_vec_length four_x_squared mult.commute +nonzero_mult_div_cancel_right times_divide_eq_right zero_neq_numeral) + then show"prob1 3 (alice \) 0 = 1/2" + using prob_sum_is_one[of "3" "alice \" "0"] alice_state[of "\"] assms by linarith +qed + +lemma post_meas0_index_0_alice: + assumes "state 1 \" and "\ = \ $$ (0,0)" and "\ = \ $$ (1,0)" + shows "post_meas0 3 (alice \) 0 = +mat_of_cols_list 8 [[\/sqrt(2), \/sqrt(2), \/sqrt(2), \/sqrt(2), 0, 0, 0, 0]]" +proof + define v where asm:"v = mat_of_cols_list 8 [[\/sqrt(2),\/sqrt(2),\/sqrt(2),\/sqrt(2),0,0,0,0]]" + then show "dim_row (post_meas0 3 (alice \) 0) = dim_row v" + using mat_of_cols_list_def post_meas0_def assms(1) alice_state ket_vec_def by simp + show "dim_col (post_meas0 3 (alice \) 0) = dim_col v" + using mat_of_cols_list_def post_meas0_def assms(1) alice_state ket_vec_def asm by simp + show "\i j. i j post_meas0 3 (alice \) 0 $$ (i,j) = v $$ (i,j)" + proof- + fix i j assume "i < dim_row v" and "j < dim_col v" + then have "i \ {0..<8} \ j = 0" + using asm set_8_atLeast0 mat_of_cols_list_def by auto + then show "post_meas0 3 (alice \) 0 $$ (i, j) = v $$ (i, j)" + using post_meas0_def assms asm mat_of_cols_list_def ket_vec_def + apply (auto simp add: prob_index_0_alice) + using assms(1) alice_result select_index_def by auto + qed +qed + +lemma post_meas1_index_0_alice: + assumes "state 1 \" and "\ = \ $$ (0,0)" and "\ = \ $$ (1,0)" + shows "post_meas1 3 (alice \) 0 = mat_of_cols_list 8 [[0,0,0,0,\/sqrt(2),-\/sqrt(2),-\/sqrt(2),\/sqrt(2)]]" +proof + define v where asm:"v = mat_of_cols_list 8 [[0,0,0,0,\/sqrt(2),-\/sqrt(2),-\/sqrt(2),\/sqrt(2)]]" + then show "dim_row (post_meas1 3 (alice \) 0) = dim_row v" + using mat_of_cols_list_def post_meas1_def assms(1) alice_state ket_vec_def by simp + show "dim_col (post_meas1 3 (alice \) 0) = dim_col v" + using mat_of_cols_list_def post_meas1_def assms(1) alice_state ket_vec_def asm by simp + show "\i j. i j post_meas1 3 (alice \) 0 $$ (i,j) = v $$ (i,j)" + proof- + fix i j assume "i < dim_row v" and "j < dim_col v" + then have "i \ {0..<8} \ j = 0" + using asm set_8_atLeast0 mat_of_cols_list_def by auto + then show "post_meas1 3 (alice \) 0 $$ (i,j) = v $$ (i,j)" + using post_meas1_def assms asm mat_of_cols_list_def ket_vec_def + apply (auto simp add: prob_index_0_alice) + using assms(1) alice_result select_index_def by auto + qed +qed + +lemma post_meas0_index_0_alice_state [simp]: + assumes "state 1 \" + shows "state 3 (post_meas0 3 (alice \) 0)" + using assms by (simp add: prob_index_0_alice) + +lemma post_meas1_index_0_alice_state [simp]: + assumes "state 1 \" + shows "state 3 (post_meas1 3 (alice \) 0)" + using assms by (simp add: prob_index_0_alice) + +lemma Alice_case [simp]: + assumes "state 1 \" and "state 3 q" and "List.member (alice_meas \) (p, q)" + shows "alice_pos \ q" +proof- + define \ \ where a0:"\ = \ $$ (0,0)" and a1:"\ = \ $$ (1,0)" + have f0:"prob0 3 (Matrix.mat 8 (Suc 0) (\(i,j). [[\ $$ (0,0)/sqrt 2, \ $$ (Suc 0,0)/sqrt 2, + \ $$ (Suc 0,0)/sqrt 2, \ $$ (0,0)/sqrt 2,0,0,0,0]]!j!i)) (Suc 0) = 1/2" + using post_meas0_index_0_alice prob0_def mat_of_cols_list_def post_meas0_index_0_alice_state +assms(1) a0 a1 select_index_3_subsets by (auto simp add: norm_divide power_divide phi_vec_length) + have f1:"prob1 3 (Matrix.mat 8 (Suc 0) (\(i,j). [[\ $$ (0,0)/sqrt 2, \ $$ (Suc 0,0)/sqrt 2, + \ $$ (Suc 0,0)/sqrt 2, \ $$ (0,0)/sqrt 2, 0, 0, 0, 0]] ! j ! i)) (Suc 0) = 1/2" + using post_meas0_index_0_alice prob1_def mat_of_cols_list_def post_meas0_index_0_alice_state +assms(1) a0 a1 select_index_3_subsets by(auto simp add: norm_divide power_divide phi_vec_length algebra_simps) + have f2:"prob0 3 (Matrix.mat 8 (Suc 0) + (\(i,j). [[0,0,0,0,\ $$ (0,0)/complex_of_real (sqrt 2),-(\ $$ (Suc 0,0)/complex_of_real (sqrt 2)), +-(\ $$ (Suc 0,0)/complex_of_real (sqrt 2)),\ $$ (0,0)/complex_of_real (sqrt 2)]] ! j ! i)) (Suc 0) = 1/2" + using post_meas1_index_0_alice prob0_def mat_of_cols_list_def post_meas1_index_0_alice_state + assms(1) a0 a1 select_index_3_subsets by(auto simp add: norm_divide power_divide phi_vec_length) + have f3:"prob1 3 (Matrix.mat 8 (Suc 0) + (\(i,j). [[0,0,0,0,\ $$ (0,0)/complex_of_real (sqrt 2),-(\ $$ (Suc 0,0)/complex_of_real (sqrt 2)), +-(\ $$ (Suc 0,0)/complex_of_real (sqrt 2)), \ $$ (0,0)/complex_of_real (sqrt 2)]] ! j ! i)) (Suc 0) = 1/2" + using post_meas1_index_0_alice prob1_def mat_of_cols_list_def post_meas1_index_0_alice_state +assms(1) a0 a1 select_index_3_subsets by(auto simp add: norm_divide power_divide phi_vec_length algebra_simps) + have "(p, q) = ((prob0 3 (alice \) 0) * (prob0 3 (post_meas0 3 (alice \) 0) 1), post_meas0 3 (post_meas0 3 (alice \) 0) 1) \ + (p, q) = ((prob0 3 (alice \) 0) * (prob1 3 (post_meas0 3 (alice \) 0) 1), post_meas1 3 (post_meas0 3 (alice \) 0) 1) \ + (p, q) = ((prob1 3 (alice \) 0) * (prob0 3 (post_meas1 3 (alice \) 0) 1), post_meas0 3 (post_meas1 3 (alice \) 0) 1) \ + (p, q) = ((prob1 3 (alice \) 0) * (prob1 3 (post_meas1 3 (alice \) 0) 1), post_meas1 3 (post_meas1 3 (alice \) 0) 1)" + using assms(3) alice_meas_def List.member_def by(smt list.distinct(1) list.exhaust list.inject member_rec(1) member_rec(2)) + then have "q = post_meas0 3 (post_meas0 3 (alice \) 0) 1 \ q = post_meas1 3 (post_meas0 3 (alice \) 0) 1 \ + q = post_meas0 3 (post_meas1 3 (alice \) 0) 1 \ q = post_meas1 3 (post_meas1 3 (alice \) 0) 1" + by auto + moreover have "post_meas0 3 (post_meas0 3 (alice \) 0) 1 = mat_of_cols_list 8 [[\,\,0,0,0,0,0,0]]" + proof + define v where asm:"v = mat_of_cols_list 8 [[\, \, 0, 0, 0, 0, 0, 0]]" + then show "dim_row (post_meas0 3 (post_meas0 3 (alice \) 0) 1) = dim_row v" + using mat_of_cols_list_def post_meas0_def ket_vec_def by simp + show "dim_col (post_meas0 3 (post_meas0 3 (alice \) 0) 1) = dim_col v" + using mat_of_cols_list_def post_meas0_def ket_vec_def asm by simp + show "\i j. i j post_meas0 3 (post_meas0 3 (alice \) 0) 1 $$ (i,j) = v $$ (i,j)" + proof- + fix i j assume "i < dim_row v" and "j < dim_col v" + then have "i \ {0..<8} \ j = 0" + using asm mat_of_cols_list_def by auto + then show "post_meas0 3 (post_meas0 3 (alice \) 0) 1 $$ (i,j) = v $$ (i,j)" + using post_meas0_index_0_alice assms(1) a0 a1 + apply (auto) + using post_meas0_def asm mat_of_cols_list_def ket_vec_def select_index_def + by (auto simp add: f0 real_sqrt_divide) + qed + qed + moreover have "post_meas1 3 (post_meas0 3 (alice \) 0) 1 = mat_of_cols_list 8 [[0,0,\,\,0,0,0,0]]" + proof + define v where asm:"v = mat_of_cols_list 8 [[0,0,\,\,0,0,0,0]]" + then show "dim_row (post_meas1 3 (post_meas0 3 (alice \) 0) 1) = dim_row v" + using mat_of_cols_list_def post_meas1_def ket_vec_def asm by auto + show "dim_col (post_meas1 3 (post_meas0 3 (alice \) 0) 1) = dim_col v" + using mat_of_cols_list_def post_meas1_def ket_vec_def asm by auto + show "\i j. i j post_meas1 3 (post_meas0 3 (alice \) 0) 1 $$ (i,j) = v $$ (i,j)" + proof- + fix i j assume "i < dim_row v" and "j < dim_col v" + then have "i \ {0..<8} \ j = 0" + using asm mat_of_cols_list_def by auto + then show "post_meas1 3 (post_meas0 3 (alice \) 0) 1 $$ (i,j) = v $$ (i,j)" + using post_meas0_index_0_alice assms(1) a0 a1 + apply (auto) + using post_meas1_def asm mat_of_cols_list_def ket_vec_def select_index_def + by (auto simp add: f1 real_sqrt_divide) + qed + qed + moreover have "post_meas0 3 (post_meas1 3 (alice \) 0) 1 = mat_of_cols_list 8 [[0,0,0,0,\,-\,0,0]]" + proof + define v where asm:"v = mat_of_cols_list 8 [[0, 0, 0, 0, \, -\, 0, 0]]" + then show "dim_row (post_meas0 3 (post_meas1 3 (alice \) 0) 1) = dim_row v" + using mat_of_cols_list_def post_meas0_def ket_vec_def by simp + show "dim_col (post_meas0 3 (post_meas1 3 (alice \) 0) 1) = dim_col v" + using mat_of_cols_list_def post_meas0_def ket_vec_def asm by simp + show "\i j. i j post_meas0 3 (post_meas1 3 (alice \) 0) 1 $$ (i,j) = v $$ (i,j)" + proof- + fix i j assume "i < dim_row v" and "j < dim_col v" + then have "i \ {0..<8} \ j = 0" + using asm mat_of_cols_list_def by auto + then show "post_meas0 3 (post_meas1 3 (alice \) 0) 1 $$ (i,j) = v $$ (i,j)" + using post_meas1_index_0_alice assms(1) a0 a1 + apply (auto) + using post_meas0_def asm mat_of_cols_list_def ket_vec_def select_index_def + by (auto simp add: f2 real_sqrt_divide) + qed + qed + moreover have "post_meas1 3 (post_meas1 3 (alice \) 0) 1 = mat_of_cols_list 8 [[0,0,0,0,0,0,-\,\]]" + proof + define v where asm:"v = mat_of_cols_list 8 [[0,0,0,0,0,0,-\,\]]" + then show "dim_row (post_meas1 3 (post_meas1 3 (alice \) 0) 1) = dim_row v" + using mat_of_cols_list_def post_meas1_def ket_vec_def by simp + show "dim_col (post_meas1 3 (post_meas1 3 (alice \) 0) 1) = dim_col v" + using mat_of_cols_list_def post_meas1_def ket_vec_def asm by simp + show "\i j. i j post_meas1 3 (post_meas1 3 (alice \) 0) 1 $$ (i,j) = v $$ (i,j)" + proof- + fix i j assume "i < dim_row v" and "j < dim_col v" + then have "i \ {0..<8} \ j = 0" + using asm mat_of_cols_list_def by auto + then show "post_meas1 3 (post_meas1 3 (alice \) 0) 1 $$ (i,j) = v $$ (i,j)" + using post_meas1_index_0_alice assms(1) a0 a1 + apply (auto) + using post_meas1_def asm mat_of_cols_list_def ket_vec_def select_index_def + by (auto simp add: f3 real_sqrt_divide) + qed + qed + ultimately show ?thesis using alice_pos_def a0 a1 by simp +qed + + +datatype bit = zero | one + +definition alice_out:: "complex Matrix.mat => complex Matrix.mat => bit \ bit" where +"alice_out \ q \ +if q = mat_of_cols_list 8 [[\ $$ (0,0), \ $$ (1,0), 0, 0, 0, 0, 0, 0]] then (zero, zero) else + if q = mat_of_cols_list 8 [[0, 0, \ $$ (1,0), \ $$ (0,0), 0, 0, 0, 0]] then (zero, one) else + if q = mat_of_cols_list 8 [[0, 0, 0, 0, \ $$ (0,0), - \ $$ (1,0), 0, 0]] then (one, zero) else + if q = mat_of_cols_list 8 [[0, 0, 0, 0, 0, 0, - \ $$ (1,0), \ $$ (0,0)]] then (one, one) else + undefined" + +definition bob:: "complex Matrix.mat => bit \ bit \ complex Matrix.mat" where +"bob q b \ +if (fst b, snd b) = (zero, zero) then q else + if (fst b, snd b) = (zero, one) then (Id 2 \ X) * q else + if (fst b, snd b) = (one, zero) then (Id 2 \ Z) * q else + if (fst b, snd b) = (one, one) then (Id 2 \ Z * X) * q else + undefined" + +lemma alice_out_unique [simp]: + assumes "state 1 \" + shows "Matrix.mat 8 (Suc 0) (\(i,j). [[0, 0, \ $$ (Suc 0, 0), \ $$ (0, 0), 0, 0, 0, 0]]!j!i) \ + Matrix.mat 8 (Suc 0) (\(i,j). [[\ $$ (0, 0), \ $$ (Suc 0, 0), 0, 0, 0, 0, 0, 0]]!j!i) \ + Matrix.mat 8 (Suc 0) (\(i,j). [[0, 0, 0, 0, \ $$ (0, 0), -\ $$ (Suc 0, 0), 0, 0]]!j!i) \ + Matrix.mat 8 (Suc 0) (\(i,j). [[\ $$ (0, 0), \ $$ (Suc 0, 0), 0, 0, 0, 0, 0, 0]]!j!i) \ + Matrix.mat 8 (Suc 0) (\(i,j). [[0, 0, 0, 0, 0, 0, -\ $$ (Suc 0, 0), \ $$ (0, 0)]]!j!i) \ + Matrix.mat 8 (Suc 0) (\(i,j). [[\ $$ (0, 0), \ $$ (Suc 0, 0), 0, 0, 0, 0, 0, 0]]!j!i) \ + Matrix.mat 8 (Suc 0) (\(i,j). [[0, 0, 0, 0, \ $$ (0, 0), -\ $$ (Suc 0, 0), 0, 0]]!j!i) \ + Matrix.mat 8 (Suc 0) (\(i,j). [[0, 0, \ $$ (Suc 0, 0), \ $$ (0, 0), 0, 0, 0, 0]]!j!i) \ + Matrix.mat 8 (Suc 0) (\(i,j). [[0, 0, 0, 0, 0, 0, -\ $$ (Suc 0, 0), \ $$ (0, 0)]]!j!i) \ + Matrix.mat 8 (Suc 0) (\(i,j). [[0, 0, \ $$ (Suc 0, 0), \ $$ (0, 0), 0, 0, 0, 0]]!j!i) \ + Matrix.mat 8 (Suc 0) (\(i,j). [[0, 0, 0, 0, 0, 0, -\ $$ (Suc 0, 0), \ $$ (0, 0)]]!j!i) \ + Matrix.mat 8 (Suc 0) (\(i,j). [[0, 0, 0, 0, \ $$ (0, 0), -\ $$ (Suc 0, 0), 0, 0]]!j!i)" +proof- + have f0:"\ $$ (0,0) \ 0 \ \ $$ (1,0) \ 0" + using assms state_def Matrix.col_def cpx_vec_length_def set_2 by(auto simp add: atLeast0LessThan) + define v1 v2 v3 v4 where d0:"v1 = Matrix.mat 8 1 (\(i,j). [[\ $$ (0,0),\ $$ (1,0),0,0,0,0,0,0]]!j!i)" + and d1:"v2 = Matrix.mat 8 1 (\(i,j). [[0,0,\ $$ (1,0), \ $$ (0,0),0,0,0,0]]!j!i)" + and d2:"v3 = Matrix.mat 8 1 (\(i,j). [[0,0,0,0,\ $$ (0,0),-\ $$ (1,0),0,0]]!j!i)" + and d3:"v4 = Matrix.mat 8 1 (\(i,j). [[0,0,0,0,0,0,-\ $$ (1,0),\ $$ (0,0)]]!j!i)" + then have "(v1 $$ (0,0) \ v2 $$ (0,0) \ v1 $$ (1,0) \ v2 $$ (1,0)) \ + (v1 $$ (0,0) \ v3 $$ (0,0) \ v1 $$ (1,0) \ v3 $$ (1,0)) \ + (v1 $$ (0,0) \ v4 $$ (0,0) \ v1 $$ (1,0) \ v4 $$ (1,0)) \ + (v2 $$ (2,0) \ v3 $$ (2,0) \ v2 $$ (3,0) \ v3 $$ (3,0)) \ + (v2 $$ (2,0) \ v4 $$ (2,0) \ v2 $$ (3,0) \ v4 $$ (3,0)) \ + (v3 $$ (4,0) \ v4 $$ (4,0) \ v3 $$ (5,0) \ v4 $$ (5,0))" using f0 by auto + then have "v1 \ v2 \ v1 \ v3 \ v1 \ v4 \ v2 \ v3 \ v2 \ v4 \ v3 \ v4" by auto + thus ?thesis by (auto simp add: d0 d1 d2 d3) +qed + +abbreviation M3:: "complex Matrix.mat" where +"M3 \ mat_of_cols_list 8 [[0, 1, 0, 0, 0, 0, 0, 0], + [1, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 1, 0, 0, 0, 0], + [0, 0, 1, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 1, 0, 0], + [0, 0, 0, 0, 1, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 1], + [0, 0, 0, 0, 0, 0, 1, 0]]" + +lemma tensor_prod_of_id_2_x: + shows "(Id 2 \ X) = M3" +proof + have f0:"gate 3 (Id 2 \ X)" + using X_is_gate tensor_gate[of "2" "Id 2" "1" "X"] by simp + then show "dim_row (Id 2 \ X) = dim_row M3" + using gate_def by (simp add: mat_of_cols_list_def) + show "dim_col (Id 2 \ X) = dim_col M3" + using f0 gate_def by (simp add: mat_of_cols_list_def) + show "\i j. i < dim_row M3 \ j < dim_col M3 \ (Id 2 \ X) $$ (i,j) = M3 $$ (i,j)" + proof- + fix i j assume "i < dim_row M3" and "j < dim_col M3" + then have "i \ {0..<8} \ j \ {0..<8}" by (auto simp add: mat_of_cols_list_def) + then show "(Id 2 \ X) $$ (i,j) = M3 $$ (i,j)" + using Id_def X_def index_tensor_mat[of "Id 2" "4" "4" "X" "2" "2" "i" "j"] gate_def X_is_gate +id_is_gate Id_def by (auto simp add: mat_of_cols_list_def X_def) + qed +qed + +abbreviation M4:: "complex Matrix.mat" where +"M4 \ mat_of_cols_list 8 [[0, -1, 0, 0, 0, 0, 0, 0], + [1, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, -1, 0, 0, 0, 0], + [0, 0, 1, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, -1, 0, 0], + [0, 0, 0, 0, 1, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, -1], + [0, 0, 0, 0, 0, 0, 1, 0]]" + +abbreviation ZX:: "complex Matrix.mat" where +"ZX \ mat_of_cols_list 2 [[0, -1], [1, 0]]" + +lemma l_inv_of_ZX: + shows "ZX\<^sup>\ * ZX = 1\<^sub>m 2" +proof + show "dim_row (ZX\<^sup>\ * ZX) = dim_row (1\<^sub>m 2)" using dagger_def mat_of_cols_list_def by simp + show "dim_col (ZX\<^sup>\ * ZX) = dim_col (1\<^sub>m 2)" using dagger_def mat_of_cols_list_def by simp + show "\i j. i < dim_row (1\<^sub>m 2) \ j < dim_col (1\<^sub>m 2) \ (ZX\<^sup>\ * ZX) $$ (i, j) = 1\<^sub>m 2 $$ (i, j)" + proof- + fix i j assume "i < dim_row (1\<^sub>m 2)" and "j < dim_col (1\<^sub>m 2)" + then have "i \ {0..<2} \ j \ {0..<2}" by auto + then show "(ZX\<^sup>\ * ZX) $$ (i, j) = 1\<^sub>m 2 $$ (i, j)" + using mat_of_cols_list_def dagger_def by (auto simp add: set_2) + qed +qed + +lemma r_inv_of_ZX: + shows "ZX * (ZX\<^sup>\) = 1\<^sub>m 2" +proof + show "dim_row (ZX * (ZX\<^sup>\)) = dim_row (1\<^sub>m 2)" using dagger_def mat_of_cols_list_def by simp + show "dim_col (ZX * (ZX\<^sup>\)) = dim_col (1\<^sub>m 2)" using dagger_def mat_of_cols_list_def by simp + show "\i j. i < dim_row (1\<^sub>m 2) \ j < dim_col (1\<^sub>m 2) \ (ZX * (ZX\<^sup>\)) $$ (i, j) = 1\<^sub>m 2 $$ (i, j)" + proof- + fix i j assume "i < dim_row (1\<^sub>m 2)" and "j < dim_col (1\<^sub>m 2)" + then have "i \ {0..<2} \ j \ {0..<2}" by auto + then show "(ZX * (ZX\<^sup>\)) $$ (i, j) = 1\<^sub>m 2 $$ (i, j)" + using mat_of_cols_list_def dagger_def by (auto simp add: set_2) + qed +qed + +lemma ZX_is_gate [simp]: + shows "gate 1 ZX" +proof + show "dim_row ZX = 2 ^ 1" using mat_of_cols_list_def by simp + show "square_mat ZX" using mat_of_cols_list_def by simp + show "unitary ZX" using unitary_def l_inv_of_ZX r_inv_of_ZX mat_of_cols_list_def by auto +qed + +lemma prod_of_ZX: + shows "Z * X = ZX" +proof + show "dim_row (Z * X) = dim_row ZX" + using Z_is_gate mat_of_cols_list_def gate_def by auto + show "dim_col (Z * X) = dim_col ZX" + using X_is_gate mat_of_cols_list_def gate_def by auto + show "\i j. i < dim_row ZX \ j < dim_col ZX \ (Z * X) $$ (i, j) = ZX $$ (i, j)" + proof- + fix i j assume "i < dim_row ZX" and "j < dim_col ZX" + then have "i \ {0..<2} \ j \ {0..<2}" by (auto simp add: mat_of_cols_list_def) + then show "(Z * X) $$ (i, j) = ZX $$ (i, j)" by (auto simp add: set_2 Z_def X_def) + qed +qed + +lemma tensor_prod_of_id_2_y: + shows "(Id 2 \ Z * X) = M4" +proof + have f0:"gate 3 (Id 2 \ Z * X)" + using prod_of_ZX ZX_is_gate tensor_gate[of "2" "Id 2" "1" "Z * X"] by simp + then show "dim_row (Id 2 \ Z * X) = dim_row M4" + using gate_def by (simp add: mat_of_cols_list_def) + show "dim_col (Id 2 \ Z * X) = dim_col M4" + using f0 gate_def by (simp add: mat_of_cols_list_def) + show "\i j. i < dim_row M4 \ j < dim_col M4 \ (Id 2 \ Z * X) $$ (i,j) = M4 $$ (i,j)" + proof- + fix i j assume "i < dim_row M4" and "j < dim_col M4" + then have "i \ {0..<8} \ j \ {0..<8}" by (auto simp add: mat_of_cols_list_def) + then have "(Id 2 \ ZX) $$ (i, j) = M4 $$ (i,j)" + using Id_def mat_of_cols_list_def index_tensor_mat[of "Id 2" "4" "4" "ZX" "2" "2" "i" "j"] + gate_def ZX_is_gate id_is_gate + by (auto simp add: mat_of_cols_list_def) + then show "(Id 2 \ Z * X) $$ (i, j) = M4 $$ (i,j)" + using prod_of_ZX by simp + qed +qed + +abbreviation M5:: "complex Matrix.mat" where +"M5 \ mat_of_cols_list 8 [[1, 0, 0, 0, 0, 0, 0, 0], + [0, -1, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 0, 0, 0, 0], + [0, 0, 0, -1, 0, 0, 0, 0], + [0, 0, 0, 0, 1, 0, 0, 0], + [0, 0, 0, 0, 0, -1, 0, 0], + [0, 0, 0, 0, 0, 0, 1, 0], + [0, 0, 0, 0, 0, 0, 0, -1]]" + +lemma tensor_prod_of_id_2_z: + shows "(Id 2 \ Z) = M5" +proof + have f0:"gate 3 (Id 2 \ Z)" + using Z_is_gate tensor_gate[of "2" "Id 2" "1" "Z"] by simp + then show "dim_row (Id 2 \ Z) = dim_row M5" + using gate_def by (simp add: mat_of_cols_list_def) + show "dim_col (Id 2 \ Z) = dim_col M5" + using f0 gate_def by (simp add: mat_of_cols_list_def) + show "\i j. i < dim_row M5 \ j < dim_col M5 \ (Id 2 \ Z) $$ (i,j) = M5 $$ (i,j)" + proof- + fix i j assume "i < dim_row M5" and "j < dim_col M5" + then have "i \ {0..<8} \ j \ {0..<8}" by (auto simp add: mat_of_cols_list_def) + then show "(Id 2 \ Z) $$ (i, j) = M5 $$ (i,j)" + using Id_def Z_def index_tensor_mat[of "Id 2" "4" "4" "Z" "2" "2" "i" "j"] gate_def Z_is_gate +id_is_gate Id_def by (auto simp add: mat_of_cols_list_def Z_def) + qed +qed + +lemma teleportation: + assumes "state 1 \" and "state 3 q" and "List.member (alice_meas \) (p, q)" + shows "\r. state 2 r \ bob q (alice_out \ q) = r \ \" +proof- + define \ \ where a0:"\ = \ $$ (0,0)" and a1:"\ = \ $$ (1,0)" + then have "q = mat_of_cols_list 8 [[\, \, 0, 0, 0, 0, 0, 0]] \ + q = mat_of_cols_list 8 [[0, 0, \, \, 0, 0, 0, 0]] \ + q = mat_of_cols_list 8 [[0, 0, 0, 0, \, -\, 0, 0]] \ + q = mat_of_cols_list 8 [[0, 0, 0, 0, 0, 0, -\, \]]" + using assms Alice_case alice_pos_def by simp + moreover have "q = mat_of_cols_list 8 [[\,\,0,0,0,0,0,0]] \ bob q (alice_out \ q) = +mat_of_cols_list 4 [[1, 0, 0, 0]] \ \" + proof + assume asm:"q = Tensor.mat_of_cols_list 8 [[\, \, 0, 0, 0, 0, 0, 0]]" + show "dim_row (bob q (alice_out \ q)) = dim_row (Tensor.mat_of_cols_list 4 [[1,0,0,0]] \ \)" + using mat_of_cols_list_def a0 a1 assms(1) state_def bob_def alice_out_def asm by simp + show "dim_col (bob q (alice_out \ q)) = dim_col (Tensor.mat_of_cols_list 4 [[1,0,0,0]] \ \)" + using mat_of_cols_list_def a0 a1 assms(1) state_def bob_def alice_out_def asm by simp + show "\i j. i < dim_row (Tensor.mat_of_cols_list 4 [[1,0,0,0]] \ \) \ + j < dim_col (Tensor.mat_of_cols_list 4 [[1,0,0,0]] \ \) \ + bob q (alice_out \ q) $$ (i, j) = (Tensor.mat_of_cols_list 4 [[1,0,0,0]] \ \) $$ (i,j)" + proof- + fix i j assume "i < dim_row (Tensor.mat_of_cols_list 4 [[1,0,0,0]] \ \)" and + "j < dim_col (Tensor.mat_of_cols_list 4 [[1,0,0,0]] \ \)" + then have "i \ {0..<8} \ j = 0" + using asm mat_of_cols_list_def assms state_def by auto + then show "bob q (alice_out \ q) $$ (i,j) = (Tensor.mat_of_cols_list 4 [[1,0,0,0]] \ \) $$ (i,j)" + using bob_def alice_out_def asm mat_of_cols_list_def a0 a1 assms state_def by auto + qed + qed + moreover have "q = mat_of_cols_list 8 [[0,0,\,\,0,0,0,0]] \ bob q (alice_out \ q) = +mat_of_cols_list 4 [[0,1,0,0]] \ \" + proof + assume asm:"q = Tensor.mat_of_cols_list 8 [[0,0,\,\,0,0,0,0]]" + show "dim_row (bob q (alice_out \ q)) = dim_row (Tensor.mat_of_cols_list 4 [[0,1,0,0]] \ \)" + using mat_of_cols_list_def a0 a1 assms(1) state_def bob_def alice_out_def asm tensor_prod_of_id_2_x by simp + show "dim_col (bob q (alice_out \ q)) = dim_col (Tensor.mat_of_cols_list 4 [[0,1,0,0]] \ \)" + using mat_of_cols_list_def a0 a1 assms(1) state_def bob_def alice_out_def asm by simp + show "\i j. i < dim_row (Tensor.mat_of_cols_list 4 [[0,1,0,0]] \ \) \ + j < dim_col (Tensor.mat_of_cols_list 4 [[0,1,0,0]] \ \) \ + bob q (alice_out \ q) $$ (i,j) = (Tensor.mat_of_cols_list 4 [[0,1,0,0]] \ \) $$ (i,j)" + proof- + fix i j assume "i < dim_row (Tensor.mat_of_cols_list 4 [[0,1,0,0]] \ \)" and + "j < dim_col (Tensor.mat_of_cols_list 4 [[0,1,0,0]] \ \)" + then have c1:"i \ {0..<8} \ j = 0" + using asm mat_of_cols_list_def assms(1) state_def by auto + then have "(M3 * (Matrix.mat 8 1 (\(i,j). [[0,0,\ $$ (1,0),\ $$ (0,0),0,0,0,0]]!j!i))) $$ (i,j) = +(Tensor.mat_of_cols_list 4 [[0,1,0,0]] \ \) $$ (i,j)" + using state_def assms(1) by(auto simp add: a0 a1 mat_of_cols_list_def times_mat_def scalar_prod_def) + then show "bob q (alice_out \ q) $$ (i,j) = (Tensor.mat_of_cols_list 4 [[0,1,0,0]] \ \) $$ (i,j)" + using bob_def alice_out_def asm c1 a0 a1 mat_of_cols_list_def tensor_prod_of_id_2_x assms(1) by simp + qed + qed + moreover have "q = mat_of_cols_list 8 [[0,0,0,0,\,-\,0,0]] \ bob q (alice_out \ q) = +mat_of_cols_list 4 [[0,0,1,0]] \ \" + proof + assume asm:"q = Tensor.mat_of_cols_list 8 [[0,0,0,0,\,-\,0,0]]" + show "dim_row (bob q (alice_out \ q)) = dim_row (Tensor.mat_of_cols_list 4 [[0,0,1,0]] \ \)" + using mat_of_cols_list_def a0 a1 assms(1) state_def bob_def alice_out_def asm tensor_prod_of_id_2_z by simp + show "dim_col (bob q (alice_out \ q)) = dim_col (Tensor.mat_of_cols_list 4 [[0,0,1,0]] \ \)" + using mat_of_cols_list_def a0 a1 assms(1) state_def bob_def alice_out_def asm by simp + show "\i j. i < dim_row (Tensor.mat_of_cols_list 4 [[0,0,1,0]] \ \) \ + j < dim_col (Tensor.mat_of_cols_list 4 [[0,0,1,0]] \ \) \ + bob q (alice_out \ q) $$ (i,j) = (Tensor.mat_of_cols_list 4 [[0,0,1,0]] \ \) $$ (i,j)" + proof- + fix i j assume "i < dim_row (Tensor.mat_of_cols_list 4 [[0,0,1,0]] \ \)" and + "j < dim_col (Tensor.mat_of_cols_list 4 [[0,0,1,0]] \ \)" + then have c1:"i \ {0..<8} \ j = 0" + using asm mat_of_cols_list_def assms state_def by auto + then have "(M5 * (Matrix.mat 8 (Suc 0) (\(i,j). [[0,0,0,0,\ $$ (0,0),-\ $$ (Suc 0,0),0,0]]!j!i))) $$ (i,j) = +(Tensor.mat_of_cols_list 4 [[0,0,1,0]] \ \) $$ (i,j)" + using state_def assms(1) by(auto simp add: a0 a1 mat_of_cols_list_def times_mat_def scalar_prod_def) + then show "bob q (alice_out \ q) $$ (i,j) = (Tensor.mat_of_cols_list 4 [[0,0,1,0]] \ \) $$ (i,j)" + using bob_def alice_out_def asm c1 a0 a1 mat_of_cols_list_def tensor_prod_of_id_2_z assms(1) by simp + qed + qed + moreover have "q = mat_of_cols_list 8 [[0, 0, 0, 0, 0, 0, -\, \]] \ bob q (alice_out \ q) = +mat_of_cols_list 4 [[0, 0, 0, 1]] \ \" + proof + assume asm:"q = Tensor.mat_of_cols_list 8 [[0, 0, 0, 0, 0, 0, -\, \]]" + show "dim_row (bob q (alice_out \ q)) = dim_row (Tensor.mat_of_cols_list 4 [[0,0,0,1]] \ \)" + using mat_of_cols_list_def a0 a1 assms(1) state_def bob_def alice_out_def asm tensor_prod_of_id_2_y by simp + show "dim_col (bob q (alice_out \ q)) = dim_col (Tensor.mat_of_cols_list 4 [[0,0,0,1]] \ \)" + using mat_of_cols_list_def a0 a1 assms(1) state_def bob_def alice_out_def asm by simp + show "\i j. i < dim_row (Tensor.mat_of_cols_list 4 [[0,0,0,1]] \ \) \ + j < dim_col (Tensor.mat_of_cols_list 4 [[0,0,0,1]] \ \) \ + bob q (alice_out \ q) $$ (i,j) = (Tensor.mat_of_cols_list 4 [[0,0,0,1]] \ \) $$ (i,j)" + proof- + fix i j assume "i < dim_row (Tensor.mat_of_cols_list 4 [[0,0,0,1]] \ \)" and + "j < dim_col (Tensor.mat_of_cols_list 4 [[0,0,0,1]] \ \)" + then have c1:"i \ {0..<8} \ j = 0" + using asm mat_of_cols_list_def assms state_def by auto + then have "(M4 * (Matrix.mat 8 (Suc 0) (\(i, j). [[0,0,0,0,0,0,-\ $$ (Suc 0,0),\ $$ (0,0)]]!j!i))) $$ (i,j) = +(Tensor.mat_of_cols_list 4 [[0,0,0,1]] \ \) $$ (i,j)" + using state_def assms(1) by(auto simp add: a0 a1 mat_of_cols_list_def times_mat_def scalar_prod_def) + then show "bob q (alice_out \ q) $$ (i,j) = (Tensor.mat_of_cols_list 4 [[0,0,0,1]] \ \) $$ (i,j)" + using bob_def alice_out_def asm c1 a0 a1 mat_of_cols_list_def tensor_prod_of_id_2_y assms(1) by simp + qed + qed + moreover have "state 2 (mat_of_cols_list 4 [[1, 0, 0, 0]])" + using state_def mat_of_cols_list_def cpx_vec_length_def lessThan_atLeast0 by simp + moreover have "state 2 (mat_of_cols_list 4 [[0, 1, 0, 0]])" + using state_def mat_of_cols_list_def cpx_vec_length_def lessThan_atLeast0 by simp + moreover have "state 2 (mat_of_cols_list 4 [[0, 0, 1, 0]])" + using state_def mat_of_cols_list_def cpx_vec_length_def lessThan_atLeast0 by simp + moreover have "state 2 (mat_of_cols_list 4 [[0, 0, 0, 1]])" + using state_def mat_of_cols_list_def cpx_vec_length_def lessThan_atLeast0 by simp + ultimately show ?thesis by auto +qed + +(* +Biblio: + +@inproceedings{Boender2015FormalizationOQ, + title={Formalization of Quantum Protocols using Coq}, + author={Jaap Boender and Florian Kamm{\"u}ller and Rajagopal Nagarajan}, + booktitle={QPL}, + year={2015} +} +*) + +end \ No newline at end of file diff --git a/thys/Isabelle_Marries_Dirac/README.md b/thys/Isabelle_Marries_Dirac/README.md new file mode 100755 --- /dev/null +++ b/thys/Isabelle_Marries_Dirac/README.md @@ -0,0 +1,9 @@ +# Isabelle_marries_Dirac +We use the proof assistant Isabelle2020 https://isabelle.in.tum.de/. + +To use the library download the Archive of Formal Proofs (https://www.isa-afp.org/download.html) or at least the following entries: +1. https://www.isa-afp.org/entries/Jordan_Normal_Form.html +2. https://www.isa-afp.org/entries/Matrix_Tensor.html +3. https://www.isa-afp.org/entries/VectorSpace.html + +To learn more about the project please visit the dedicated stream on the Isabelle Zulip chat https://isabelle.zulipchat.com/. diff --git a/thys/Isabelle_Marries_Dirac/ROOT b/thys/Isabelle_Marries_Dirac/ROOT new file mode 100755 --- /dev/null +++ b/thys/Isabelle_Marries_Dirac/ROOT @@ -0,0 +1,23 @@ +chapter AFP + +session "Isabelle_Marries_Dirac" (AFP) = "Jordan_Normal_Form" + + options [timeout=600] + sessions + Matrix_Tensor + VectorSpace + theories + Basics + Binary_Nat + Quantum + Complex_Vectors + Tensor + More_Tensor + Measurement + Entanglement + Quantum_Teleportation + Deutsch + Deutsch_Jozsa + No_Cloning + Quantum_Prisoners_Dilemma + document_files + "root.tex" diff --git a/thys/Isabelle_Marries_Dirac/Tensor.thy b/thys/Isabelle_Marries_Dirac/Tensor.thy new file mode 100755 --- /dev/null +++ b/thys/Isabelle_Marries_Dirac/Tensor.thy @@ -0,0 +1,471 @@ +(* Author: Anthony Bordg, University of Cambridge, apdb3@cam.ac.uk *) + +section \Tensor Products\ + +theory Tensor +imports + Complex_Vectors + Matrix_Tensor.Matrix_Tensor + Jordan_Normal_Form.Matrix +begin + + +text \ +There is already a formalization of tensor products in the Archive of Formal Proofs, +namely Matrix\_Tensor.thy in Tensor Product of Matrices[1] by T.V.H. Prathamesh, but it does not build +on top of the formalization of vectors and matrices given in Matrices, Jordan Normal Forms, and +Spectral Radius Theory[2] by René Thiemann and Akihisa Yamada. +In the present theory our purpose consists in giving such a formalization. Of course, we will reuse +Prathamesh's code as much as possible, and in order to achieve that we formalize some lemmas that +translate back and forth between vectors (resp. matrices) seen as lists (resp. lists of lists) and +vectors (resp. matrices) as formalized in [2]. +\ + +subsection \The Kronecker Product of Complex Vectors\ + +definition tensor_vec:: "complex Matrix.vec \ complex Matrix.vec \ complex Matrix.vec" (infixl "\" 63) +where "tensor_vec u v \ vec_of_list (mult.vec_vec_Tensor (*) (list_of_vec u) (list_of_vec v))" + +subsection \The Tensor Product of Complex Matrices\ + +text \To see a matrix in the sense of [2] as a matrix in the sense of [1], we convert it into its list +of column vectors.\ + +definition mat_to_cols_list:: "complex Matrix.mat \ complex list list" where + "mat_to_cols_list A = [[A $$ (i,j) . i <- [0..< dim_row A]] . j <- [0..< dim_col A]]" + +lemma length_mat_to_cols_list [simp]: + "length (mat_to_cols_list A) = dim_col A" + by (simp add: mat_to_cols_list_def) + +lemma length_cols_mat_to_cols_list [simp]: + assumes "j < dim_col A" + shows "length [A $$ (i,j) . i <- [0..< dim_row A]] = dim_row A" + using assms by simp + +lemma length_row_mat_to_cols_list [simp]: + assumes "i < dim_row A" + shows "length (row (mat_to_cols_list A) i) = dim_col A" + using assms by (simp add: row_def) + +lemma length_col_mat_to_cols_list [simp]: + assumes "j < dim_col A" + shows "length (col (mat_to_cols_list A) j) = dim_row A" + using assms by (simp add: col_def mat_to_cols_list_def) + +lemma mat_to_cols_list_is_not_Nil [simp]: + assumes "dim_col A > 0" + shows "mat_to_cols_list A \ []" + using assms by (simp add: mat_to_cols_list_def) + +text \Link between Matrix\_Tensor.row\_length and Matrix.dim\_row\ + +lemma row_length_mat_to_cols_list [simp]: + assumes "dim_col A > 0" + shows "mult.row_length (mat_to_cols_list A) = dim_row A" +proof - + have "mat_to_cols_list A \ []" by (simp add: assms) + then have "mult.row_length (mat_to_cols_list A) = length (hd (mat_to_cols_list A))" + using mult.row_length_def[of "1" "(*)"] + by (simp add: \\xs. Matrix_Tensor.mult 1 (*) \ mult.row_length xs \ if xs = [] then 0 else length (hd xs)\ mult.intro) + thus ?thesis by (simp add: assms mat_to_cols_list_def upt_conv_Cons) +qed + +text \@{term mat_to_cols_list} is a matrix in the sense of @{theory Matrix.Matrix_Legacy}.\ + +lemma mat_to_cols_list_is_mat [simp]: + assumes "dim_col A > 0" + shows "mat (mult.row_length (mat_to_cols_list A)) (length (mat_to_cols_list A)) (mat_to_cols_list A)" +proof - + have "Ball (set (mat_to_cols_list A)) (Matrix_Legacy.vec (mult.row_length (mat_to_cols_list A)))" + using assms row_length_mat_to_cols_list mat_to_cols_list_def Ball_def set_def vec_def by fastforce + thus ?thesis by(auto simp: mat_def) +qed + +definition mat_of_cols_list:: "nat \ complex list list \ complex Matrix.mat" where + "mat_of_cols_list nr cs = Matrix.mat nr (length cs) (\ (i,j). cs ! j ! i)" + +lemma index_mat_of_cols_list [simp]: + assumes "i < nr" and "j < length cs" + shows "mat_of_cols_list nr cs $$ (i,j) = cs ! j ! i" + by (simp add: assms mat_of_cols_list_def) + +lemma mat_to_cols_list_to_mat [simp]: + "mat_of_cols_list (dim_row A) (mat_to_cols_list A) = A" +proof + show f1:"dim_row (mat_of_cols_list (dim_row A) (mat_to_cols_list A)) = dim_row A" + by (simp add: mat_of_cols_list_def) +next + show f2:"dim_col (mat_of_cols_list (dim_row A) (mat_to_cols_list A)) = dim_col A" + by (simp add: Tensor.mat_of_cols_list_def) +next + show "\i j. i < dim_row A \ j < dim_col A \ + (mat_of_cols_list (dim_row A) (mat_to_cols_list A)) $$ (i, j) = A $$ (i, j)" + by (simp add: mat_of_cols_list_def mat_to_cols_list_def) +qed + +lemma plus_mult_cpx [simp]: + "plus_mult 1 (*) 0 (+) (a_inv cpx_rng)" + apply unfold_locales + apply (auto intro: cpx_cring_is_field simp: field_simps) +proof - + show "\x. x + \\<^bsub>cpx_rng\<^esub> x = 0" + using group.r_inv[of "cpx_rng"] cpx_cring_is_field field_def domain_def cpx_rng_def + by (metis UNIV_I cring.cring_simprules(17) ordered_semiring_record_simps(1) + ordered_semiring_record_simps(11) ordered_semiring_record_simps(12)) + show "\x. x + \\<^bsub>cpx_rng\<^esub> x = 0" + using group.r_inv[of "cpx_rng"] cpx_cring_is_field field_def domain_def cpx_rng_def + by (metis UNIV_I cring.cring_simprules(17) ordered_semiring_record_simps(1) + ordered_semiring_record_simps(11) ordered_semiring_record_simps(12)) +qed + +lemma list_to_mat_to_cols_list [simp]: + fixes l::"complex list list" + assumes "mat nr nc l" + shows "mat_to_cols_list (mat_of_cols_list nr l) = l" +proof - + have "length (mat_to_cols_list (mat_of_cols_list nr l)) = length l" + by (simp add: mat_of_cols_list_def) + moreover have f1:"\jj. j mat_to_cols_list (mat_of_cols_list nr l) ! j = l ! j" + proof + fix j + assume a:"j < length l" + then have f2:"length (mat_to_cols_list (mat_of_cols_list nr l) ! j) = length (l ! j)" + by (metis col_def mat_def vec_def mat_of_cols_list_def assms dim_col_mat(1) dim_row_mat(1) +length_col_mat_to_cols_list nth_mem) + then have "\ii complex Matrix.mat" (infixl "\" 63) where +"tensor_mat A B \ + mat_of_cols_list (dim_row A * dim_row B) (mult.Tensor (*) (mat_to_cols_list A) (mat_to_cols_list B))" + +lemma dim_row_tensor_mat [simp]: + "dim_row (A \ B) = dim_row A * dim_row B" + by (simp add: mat_of_cols_list_def tensor_mat_def) + +lemma dim_col_tensor_mat [simp]: + "dim_col (A \ B) = dim_col A * dim_col B" + using tensor_mat_def mat_of_cols_list_def mult.length_Tensor[of "1" "(*)"] + by(simp add: \\M2 M1. Matrix_Tensor.mult 1 (*) \ length (mult.Tensor (*) M1 M2) = length M1 * length M2\ mult.intro) + +lemma index_tensor_mat [simp]: + assumes a1:"dim_row A = rA" and a2:"dim_col A = cA" and a3:"dim_row B = rB" and a4:"dim_col B = cB" + and a5:"i < rA * rB" and a6:"j < cA * cB" and a7:"cA > 0" and a8:"cB > 0" + shows "(A \ B) $$ (i,j) = A $$ (i div rB, j div cB) * B $$ (i mod rB, j mod cB)" +proof - + have "(A \ B) $$ (i,j) = (mult.Tensor (*) (mat_to_cols_list A) (mat_to_cols_list B)) ! j ! i" + using assms tensor_mat_def mat_of_cols_list_def dim_col_tensor_mat by simp + moreover have f:"i < mult.row_length (mat_to_cols_list A) * mult.row_length (mat_to_cols_list B)" + by (simp add: a1 a2 a3 a4 a5 a7 a8) + moreover have "j < length (mat_to_cols_list A) * length (mat_to_cols_list B)" + by (simp add: a2 a4 a6) + moreover have "mat (mult.row_length (mat_to_cols_list A)) (length (mat_to_cols_list A)) (mat_to_cols_list A)" + using a2 a7 mat_to_cols_list_is_mat by blast + moreover have "mat (mult.row_length (mat_to_cols_list B)) (length (mat_to_cols_list B)) (mat_to_cols_list B)" + using a4 a8 mat_to_cols_list_is_mat by blast + ultimately have "(A \ B) $$ (i,j) = + (mat_to_cols_list A) ! (j div length (mat_to_cols_list B)) ! (i div mult.row_length (mat_to_cols_list B)) + * (mat_to_cols_list B) ! (j mod length (mat_to_cols_list B)) ! (i mod mult.row_length (mat_to_cols_list B))" + using mult.matrix_Tensor_elements[of "1" "(*)"] + by(simp add: \\M2 M1. mult 1 (*) \ \i j. (i j mat (mult.row_length M1) (length M1) M1 \ mat (mult.row_length M2) (length M2) M2 \ + mult.Tensor (*) M1 M2 ! j ! i = M1 ! (j div length M2) ! (i div mult.row_length M2) * M2 ! (j mod length M2) ! (i mod mult.row_length M2)\ mult.intro) + thus ?thesis + using mat_to_cols_list_def + by (metis a2 a3 a4 a6 f index_mat_of_cols_list length_mat_to_cols_list less_mult_imp_div_less +less_nat_zero_code mat_to_cols_list_to_mat mult_0_right neq0_conv row_length_mat_to_cols_list +unique_euclidean_semiring_numeral_class.pos_mod_bound) +qed + +text \To go from @{term Matrix.row} to @{term Matrix_Legacy.row}\ + +lemma Matrix_row_is_Legacy_row: + assumes "i < dim_row A" + shows "Matrix.row A i = vec_of_list (row (mat_to_cols_list A) i)" +proof + show "dim_vec (Matrix.row A i) = dim_vec (vec_of_list (row (mat_to_cols_list A) i))" + using length_mat_to_cols_list Matrix.dim_vec_of_list by (metis row_def index_row(2) length_map) +next + show "\j. j + Matrix.row A i $ j = vec_of_list (row (mat_to_cols_list A) i) $ j" + using Matrix.row_def vec_of_list_def mat_to_cols_list_def + by(smt row_def assms dim_vec_of_list index_mat_of_cols_list index_row(1) +length_mat_to_cols_list length_row_mat_to_cols_list mat_to_cols_list_to_mat nth_map vec_of_list_index) +qed + +text \To go from @{term Matrix_Legacy.row} to @{term Matrix.row}\ + +lemma Legacy_row_is_Matrix_row: + assumes "i < mult.row_length A" + shows "row A i = list_of_vec (Matrix.row (mat_of_cols_list (mult.row_length A) A) i)" +proof (rule nth_equalityI) + show "length (row A i) = length (list_of_vec (Matrix.row (mat_of_cols_list (mult.row_length A) A) i))" + using row_def length_list_of_vec by(metis mat_of_cols_list_def dim_col_mat(1) index_row(2) length_map) +next + fix j:: nat + assume "j < length (row A i)" + then show "row A i ! j = list_of_vec (Matrix.row (mat_of_cols_list (mult.row_length A) A) i) ! j" + using assms index_mat_of_cols_list + by(metis row_def mat_of_cols_list_def dim_col_mat(1) dim_row_mat(1) index_row(1) length_map list_of_vec_index nth_map) +qed + +text \To go from @{term Matrix.col} to @{term Matrix_Legacy.col}\ + +lemma Matrix_col_is_Legacy_col: + assumes "j < dim_col A" + shows "Matrix.col A j = vec_of_list (col (mat_to_cols_list A) j)" +proof + show "dim_vec (Matrix.col A j) = dim_vec (vec_of_list (col (mat_to_cols_list A) j))" + by (simp add: col_def assms mat_to_cols_list_def) +next + show "\i. i < dim_vec (vec_of_list (col (mat_to_cols_list A) j)) \ + Matrix.col A j $ i = vec_of_list (col (mat_to_cols_list A) j) $ i" + using mat_to_cols_list_def + by (metis col_def assms col_mat_of_cols_list length_col_mat_to_cols_list length_mat_to_cols_list +mat_to_cols_list_to_mat) +qed + +text \To go from @{term Matrix_Legacy.col} to @{term Matrix.col}\ + +lemma Legacy_col_is_Matrix_col: + assumes a1:"j < length A" and a2:"length (A ! j) = mult.row_length A" + shows "col A j = list_of_vec (Matrix.col (mat_of_cols_list (mult.row_length A) A) j)" +proof (rule nth_equalityI) + have "length (list_of_vec (Matrix.col (mat_of_cols_list (mult.row_length A) A) j)) = +dim_vec (Matrix.col (mat_of_cols_list (mult.row_length A) A) j)" + using length_list_of_vec by blast + also have "\ = dim_row (mat_of_cols_list (mult.row_length A) A)" + using Matrix.col_def by simp + also have f1:"\ = mult.row_length A" + by (simp add: mat_of_cols_list_def) + finally show f2:"length (col A j) = length (list_of_vec (Matrix.col (mat_of_cols_list (mult.row_length A) A) j))" + using a2 by (simp add: col_def) +next + fix i:: nat + assume "iLink between @{term plus_mult.scalar_product} and @{term Matrix.scalar_prod}\ + +lemma scalar_prod_is_Matrix_scalar_prod [simp]: + fixes u::"complex list" and v::"complex list" + assumes "length u = length v" + shows "plus_mult.scalar_product (*) 0 (+) u v = (vec_of_list u) \ (vec_of_list v)" +proof - + have f:"(vec_of_list u) \ (vec_of_list v) = (\i=0.. = sum_list (map (\(x,y). x * y) (zip u v))" + by (simp add: scalar_prod) + moreover have "\ii(x,y). x * y) (zip u v)) ! i = u ! i * v ! i" + by (simp add: assms) + ultimately have "plus_mult.scalar_product (*) 0 (+) u v = (\i=0..Link between @{term times} and @{term plus_mult.matrix_mult}\ + +lemma matrix_mult_to_times_mat: + assumes "dim_col A > 0" and "dim_col B > 0" and "dim_col (A::complex Matrix.mat) = dim_row B" + shows "A * B = mat_of_cols_list (dim_row A) (plus_mult.matrix_mult (*) 0 (+) (mat_to_cols_list A) (mat_to_cols_list B))" +proof + define M where "M = mat_of_cols_list (dim_row A) (plus_mult.matrix_mult (*) 0 (+) (mat_to_cols_list A) (mat_to_cols_list B))" + then show f1:"dim_row (A * B) = dim_row M" + by (simp add: mat_of_cols_list_def times_mat_def) + have "length (plus_mult.matrix_mult (*) 0 (+) (mat_to_cols_list A) (mat_to_cols_list B)) = dim_col B" + by (simp add: mat_multI_def) + then show f2:"dim_col (A * B) = dim_col M" + by (simp add: M_def times_mat_def mat_of_cols_list_def) + show "\i j. i < dim_row M \ j < dim_col M \ (A * B) $$ (i, j) = M $$ (i, j)" + proof - + fix i j + assume a1:"i < dim_row M" and a2:"j < dim_col M" + then have "(A * B) $$ (i,j) = Matrix.row A i \ Matrix.col B j" + using f1 f2 by simp + also have "\ = vec_of_list (row (mat_to_cols_list A) i) \ vec_of_list (col (mat_to_cols_list B) j)" + using f1 f2 a1 a2 by (simp add: Matrix_row_is_Legacy_row Matrix_col_is_Legacy_col) + also have "\ = plus_mult.scalar_product (*) 0 (+) (row (mat_to_cols_list A) i) (col (mat_to_cols_list B) j)" + using a1 a2 assms(3) f1 f2 by simp + also have "M $$ (i,j) = plus_mult.scalar_product (*) 0 (+) (row (mat_to_cols_list A) i) (col (mat_to_cols_list B) j)" + proof- + have "M $$ (i,j) = (plus_mult.matrix_mult (*) 0 (+) (mat_to_cols_list A) (mat_to_cols_list B)) ! j ! i" + using M_def f1 f2 +\length (mat_mult (mult.row_length (mat_to_cols_list A)) (mat_to_cols_list A) (mat_to_cols_list B)) = dim_col B\ a1 a2 by simp + moreover have "mat (mult.row_length (mat_to_cols_list A)) (dim_col A) (mat_to_cols_list A)" + using mat_to_cols_list_is_mat assms(1) by simp + moreover have "mat (dim_col A) (dim_col B) (mat_to_cols_list B)" + using assms(2) assms(3) mat_to_cols_list_is_mat by simp + ultimately show ?thesis + using assms(1) a1 a2 row_length_mat_to_cols_list plus_mult.matrix_index[of 1 "(*)" 0 "(+)"] plus_mult_cpx + by (smt f1 f2 index_mult_mat(2) index_mult_mat(3)) + qed + finally show "(A * B) $$ (i, j) = M $$ (i, j)" by simp + qed +qed + +lemma mat_to_cols_list_times_mat [simp]: + assumes "dim_col A = dim_row B" and "dim_col A > 0" + shows "mat_to_cols_list (A * B) = plus_mult.matrix_mult (*) 0 (+) (mat_to_cols_list A) (mat_to_cols_list B)" +proof (rule nth_equalityI) + define M where "M = plus_mult.matrix_mult (*) 0 (+) (mat_to_cols_list A) (mat_to_cols_list B)" + then show f0:"length (mat_to_cols_list (A * B)) = length M" by (simp add: mat_multI_def) + moreover have f1:"\j. j mat_to_cols_list (A * B) ! j = M ! j" + proof + fix j:: nat + assume a0:"j < length (mat_to_cols_list (A * B))" + then have "length (mat_to_cols_list (A * B) ! j) = dim_row A" + by (simp add: mat_to_cols_list_def) + then also have f2:"length (M ! j) = dim_row A" + using a0 M_def mat_multI_def[of 0 "(+)" "(*)" "dim_row A" "mat_to_cols_list A" "mat_to_cols_list B"] + row_length_mat_to_cols_list assms(2) + by (metis assms(1) f0 length_greater_0_conv length_map length_mat_to_cols_list +list_to_mat_to_cols_list mat_mult mat_to_cols_list_is_mat matrix_mult_to_times_mat) + ultimately have "length (mat_to_cols_list (A * B) ! j) = length (M ! j)" by simp + moreover have "\i. i mat_to_cols_list (A * B) ! j ! i = M ! j ! i" + proof + fix i + assume a1:"i < dim_row A" + have "mat (mult.row_length (mat_to_cols_list A)) (dim_col A) (mat_to_cols_list A)" + using mat_to_cols_list_is_mat assms(2) by simp + moreover have "mat (dim_col A) (dim_col B) (mat_to_cols_list B)" + using mat_to_cols_list_is_mat assms(1) a0 by simp + ultimately have "M ! j ! i = plus_mult.scalar_product (*) 0 (+) (row (mat_to_cols_list A) i) (col (mat_to_cols_list B) j)" + using plus_mult.matrix_index a0 a1 row_length_mat_to_cols_list assms(2) plus_mult_cpx M_def + by (metis index_mult_mat(3) length_mat_to_cols_list) + also have "\ = vec_of_list (row (mat_to_cols_list A) i) \ vec_of_list (col (mat_to_cols_list B) j)" + using a0 a1 assms(1) by simp + finally show "mat_to_cols_list (A * B) ! j ! i = M ! j ! i" + using mat_to_cols_list_def index_mult_mat(1) a0 a1 + by(simp add: Matrix_row_is_Legacy_row Matrix_col_is_Legacy_col) + qed + ultimately show "mat_to_cols_list (A * B) ! j = M ! j" by(simp add: nth_equalityI f2) + qed + fix i:: nat + assume "i < length (mat_to_cols_list (A * B))" + thus "mat_to_cols_list (A * B) ! i = M ! i" by (simp add: f1) +qed + +text \ +Finally, we prove that the tensor product of complex matrices is distributive over the +multiplication of complex matrices. +\ + +lemma mult_distr_tensor: + assumes a1:"dim_col A = dim_row B" and a2:"dim_col C = dim_row D" and a3:"dim_col A > 0" and + a4:"dim_col B > 0" and a5:"dim_col C > 0" and a6:"dim_col D > 0" + shows "(A * B) \ (C * D) = (A \ C) * (B \ D)" +proof - + define A' B' C' D' M N where "A' = mat_to_cols_list A" and "B' = mat_to_cols_list B" and + "C' = mat_to_cols_list C" and "D' = mat_to_cols_list D" and + "M = mat_of_cols_list (dim_row A * dim_row C) (mult.Tensor (*) (mat_to_cols_list A) (mat_to_cols_list C))" and + "N = mat_of_cols_list (dim_row B * dim_row D) (mult.Tensor (*) (mat_to_cols_list B) (mat_to_cols_list D))" + then have "(A \ C) * (B \ D) = M * N" + by (simp add: tensor_mat_def) + also have "\ = mat_of_cols_list (dim_row A * dim_row C) (plus_mult.matrix_mult (*) 0 (+) + (mat_to_cols_list M) (mat_to_cols_list N))" + using assms M_def N_def dim_col_tensor_mat dim_row_tensor_mat tensor_mat_def + by(simp add: matrix_mult_to_times_mat) + also have f1:"\ = mat_of_cols_list (dim_row A * dim_row C) (plus_mult.matrix_mult (*) 0 (+) + (mult.Tensor (*) A' C') (mult.Tensor (*) B' D'))" + proof - + define M' N' where "M' = mult.Tensor (*) (mat_to_cols_list A) (mat_to_cols_list C)" and + "N' = mult.Tensor (*) (mat_to_cols_list B) (mat_to_cols_list D)" + then have "mat (mult.row_length M') (length M') M'" + using M'_def mult.effective_well_defined_Tensor[of 1 "(*)"] mat_to_cols_list_is_mat a3 a5 + by (smt mult.length_Tensor mult.row_length_mat plus_mult_cpx plus_mult_def) + moreover have "mat (mult.row_length N') (length N') N'" + using N'_def mult.effective_well_defined_Tensor[of 1 "(*)"] mat_to_cols_list_is_mat a4 a6 + by (smt mult.length_Tensor mult.row_length_mat plus_mult_cpx plus_mult_def) + ultimately show ?thesis + using list_to_mat_to_cols_list M_def N_def mult.row_length_mat row_length_mat_to_cols_list + assms(3) a4 a5 a6 A'_def B'_def C'_def D'_def by(metis M'_def N'_def plus_mult_cpx plus_mult_def) + qed + also have "\ = mat_of_cols_list (dim_row A * dim_row C) (mult.Tensor (*) + (plus_mult.matrix_mult (*) 0 (+) A' B') + (plus_mult.matrix_mult (*) 0 (+) C' D'))" + proof - + have f2:"mat (mult.row_length A') (length A') A'" + using A'_def a3 mat_to_cols_list_is_mat by simp + moreover have "mat (mult.row_length B') (length B') B'" + using B'_def a4 mat_to_cols_list_is_mat by simp + moreover have "mat (mult.row_length C') (length C') C'" + using C'_def a5 mat_to_cols_list_is_mat by simp + moreover have "mat (mult.row_length D') (length D') D'" + using D'_def a6 mat_to_cols_list_is_mat by simp + moreover have "length A' = mult.row_length B'" + using A'_def B'_def a1 a4 by simp + moreover have "length C' = mult.row_length D'" + using C'_def D'_def a2 a6 by simp + moreover have "A' \ [] \ B' \ [] \ C' \ [] \ D' \ []" + using A'_def B'_def C'_def D'_def a3 a4 a5 a6 by simp + ultimately have "plus_mult.matrix_match A' B' C' D'" + using plus_mult.matrix_match_def[of 1 "(*)" 0 "(+)" "a_inv cpx_rng"] by simp + thus ?thesis + using f1 plus_mult.distributivity plus_mult_cpx by fastforce + qed + also have "\ = mat_of_cols_list (dim_row A * dim_row C) (mult.Tensor (*) + (mat_to_cols_list (A * B)) (mat_to_cols_list (C * D)))" + using A'_def B'_def C'_def D'_def a1 a2 a3 a5 by simp + finally show ?thesis by(simp add: tensor_mat_def) + qed + +lemma tensor_mat_is_assoc: + fixes A B C:: "complex Matrix.mat" + shows "A \ (B \ C) = (A \ B) \ C" +proof- + define M where d:"M = mat_of_cols_list (dim_row B * dim_row C) (mult.Tensor (*) (mat_to_cols_list B) (mat_to_cols_list C))" + then have "B \ C = M" + using tensor_mat_def by simp + moreover have "A \ (B \ C) = mat_of_cols_list (dim_row A * (dim_row B * dim_row C)) +(mult.Tensor (*) (mat_to_cols_list A) (mat_to_cols_list M))" + using tensor_mat_def d dim_row_tensor_mat by simp + moreover have "mat_to_cols_list M = mult.Tensor (*) (mat_to_cols_list B) (mat_to_cols_list C)" + using d list_to_mat_to_cols_list + by (smt calculation(1) dim_col_tensor_mat length_greater_0_conv length_mat_to_cols_list mat_to_cols_list_is_mat +mult.Tensor.simps(1) mult.Tensor_null mult.well_defined_Tensor nat_0_less_mult_iff plus_mult_cpx plus_mult_def row_length_mat_to_cols_list) + ultimately have "A \ (B \ C) = mat_of_cols_list (dim_row A * (dim_row B * dim_row C)) +(mult.Tensor (*) (mat_to_cols_list A) (mult.Tensor (*) (mat_to_cols_list B) (mat_to_cols_list C)))" by simp + moreover have "\ = mat_of_cols_list ((dim_row A * dim_row B) * dim_row C) +(mult.Tensor (*) (mult.Tensor (*) (mat_to_cols_list A) (mat_to_cols_list B)) (mat_to_cols_list C))" + using Matrix_Tensor.mult.associativity + by (smt ab_semigroup_mult_class.mult_ac(1) length_greater_0_conv length_mat_to_cols_list +mat_to_cols_list_is_mat mult.Tensor.simps(1) mult.Tensor_null plus_mult_cpx plus_mult_def) + ultimately show ?thesis + using tensor_mat_def + by (smt Tensor.mat_of_cols_list_def dim_col_mat(1) dim_col_tensor_mat dim_row_tensor_mat length_0_conv +list_to_mat_to_cols_list mat_to_cols_list_is_mat mult.well_defined_Tensor mult_is_0 neq0_conv +plus_mult_cpx plus_mult_def row_length_mat_to_cols_list) +qed + +end \ No newline at end of file diff --git a/thys/Isabelle_Marries_Dirac/document/root.bib b/thys/Isabelle_Marries_Dirac/document/root.bib new file mode 100755 --- /dev/null +++ b/thys/Isabelle_Marries_Dirac/document/root.bib @@ -0,0 +1,27 @@ +@book{MikeandIke, + author = {Nielsen, Michael A. and Chuang, Isaac L.}, + publisher = {Cambridge University Press}, + title = {Quantum Computation and Quantum Information}, + year = 2010 +} + +@ARTICLE{EWL, + author = {{Eisert}, J. and {Wilkens}, M. and {Lewenstein}, M.}, + title = "{Quantum Games and Quantum Strategies}", + journal = {Physical Review Letters}, + eprint = {quant-ph/9806088}, + year = 1999, + month = oct, + volume = 83, + pages = {3077-3080}, + doi = {10.1103/PhysRevLett.83.3077}, + adsurl = {https://ui.adsabs.harvard.edu/abs/1999PhRvL..83.3077E}, + adsnote = {Provided by the SAO/NASA Astrophysics Data System} +} + +@inproceedings{Boender2015FormalizationOQ, + title={Formalization of Quantum Protocols using Coq}, + author={Jaap Boender and Florian Kamm{\"u}ller and Rajagopal Nagarajan}, + booktitle={QPL}, + year={2015} +} diff --git a/thys/Isabelle_Marries_Dirac/document/root.tex b/thys/Isabelle_Marries_Dirac/document/root.tex new file mode 100755 --- /dev/null +++ b/thys/Isabelle_Marries_Dirac/document/root.tex @@ -0,0 +1,67 @@ +\documentclass[11pt,a4paper]{article} +\usepackage{isabelle,isabellesym} +\usepackage[utf8]{inputenc} +\usepackage[T1]{fontenc} +% further packages required for unusual symbols (see also +% isabellesym.sty), use only when needed + +\usepackage{amssymb} + %for \, \, \, \, \, \, + %\, \, \, \, \, + %\, \, \ +\usepackage{amsmath} + +%\usepackage{eurosym} + %for \ + +%\usepackage[only,bigsqcap]{stmaryrd} + %for \ + +%\usepackage{eufrak} + %for \ ... \, \ ... \ (also included in amssymb) + +%\usepackage{textcomp} + %for \, \, \, \, \, + %\ + +% this should be the last package used +\usepackage{pdfsetup} + +% urls in roman style, theory text in math-similar italics +\urlstyle{rm} +\isabellestyle{it} + +% for uniform font size +%\renewcommand{\isastyle}{\isastyleminor} + + +\begin{document} + +\title{Isabelle Marries Dirac: a Library for Quantum Computation and Quantum Information} +\author{Anthony Bordg, Hanna Lachnitt and Yijun He} +\maketitle + +\tableofcontents + +\begin{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. +\end{abstract} + + +% sane default for proof documents +\parindent 0pt\parskip 0.5ex + +% generated text of all theories +\input{session} + +% optional bibliography +\nocite{*} +\bibliographystyle{abbrv} +\bibliography{root} + +\end{document} + +%%% Local Variables: +%%% mode: latex +%%% TeX-master: t +%%% End: diff --git a/thys/ROOTS b/thys/ROOTS --- a/thys/ROOTS +++ b/thys/ROOTS @@ -1,572 +1,576 @@ ADS_Functor AI_Planning_Languages_Semantics AODV AVL-Trees AWN Abortable_Linearizable_Modules Abs_Int_ITP2012 Abstract-Hoare-Logics Abstract-Rewriting Abstract_Completeness Abstract_Soundness Adaptive_State_Counting Affine_Arithmetic Aggregation_Algebras Akra_Bazzi Algebraic_Numbers Algebraic_VCs Allen_Calculus Amicable_Numbers Amortized_Complexity AnselmGod Applicative_Lifting Approximation_Algorithms Architectural_Design_Patterns Aristotles_Assertoric_Syllogistic Arith_Prog_Rel_Primes ArrowImpossibilityGS Attack_Trees Auto2_HOL Auto2_Imperative_HOL AutoFocus-Stream Automated_Stateful_Protocol_Verification Automatic_Refinement AxiomaticCategoryTheory BDD BNF_CC BNF_Operations Banach_Steinhaus Bell_Numbers_Spivey Berlekamp_Zassenhaus Bernoulli Bertrands_Postulate Bicategory BinarySearchTree Binding_Syntax_Theory Binomial-Heaps Binomial-Queues BirdKMP Bondy Boolean_Expression_Checkers Bounded_Deducibility_Security Buchi_Complementation Budan_Fourier Buffons_Needle Buildings BytecodeLogicJmlTypes C2KA_DistributedSystems CAVA_Automata CAVA_LTL_Modelchecker CCS CISC-Kernel CRDT CYK CakeML CakeML_Codegen Call_Arity Card_Equiv_Relations Card_Multisets Card_Number_Partitions Card_Partitions Cartan_FP Case_Labeling Catalan_Numbers Category Category2 Category3 Cauchy Cayley_Hamilton Certification_Monads Chandy_Lamport Chord_Segments Circus Clean ClockSynchInst Closest_Pair_Points CofGroups Coinductive Coinductive_Languages Collections Comparison_Sort_Lower_Bound Compiling-Exceptions-Correctly Complete_Non_Orders Completeness Complex_Geometry Complx ComponentDependencies ConcurrentGC ConcurrentIMP Concurrent_Ref_Alg Concurrent_Revisions Consensus_Refined Constructive_Cryptography Constructor_Funs Containers CoreC++ Core_DOM Core_SC_DOM Count_Complex_Roots CryptHOL CryptoBasedCompositionalProperties DFS_Framework DPT-SAT-Solver DataRefinementIBP Datatype_Order_Generator Decl_Sem_Fun_PL Decreasing-Diagrams Decreasing-Diagrams-II Deep_Learning Density_Compiler Dependent_SIFUM_Refinement Dependent_SIFUM_Type_Systems Depth-First-Search Derangements Deriving Descartes_Sign_Rule Dict_Construction Differential_Dynamic_Logic Differential_Game_Logic Dijkstra_Shortest_Path Diophantine_Eqns_Lin_Hom Dirichlet_L Dirichlet_Series DiscretePricing Discrete_Summation DiskPaxos DOM_Components DynamicArchitectures Dynamic_Tables E_Transcendental Echelon_Form EdmondsKarp_Maxflow Efficient-Mergesort Elliptic_Curves_Group_Law Encodability_Process_Calculi Epistemic_Logic Ergodic_Theory Error_Function Euler_MacLaurin Euler_Partition Example-Submission Extended_Finite_State_Machine_Inference Extended_Finite_State_Machines FFT FLP FOL-Fitting FOL_Harrison FOL_Seq_Calc1 Factored_Transition_System_Bounding Falling_Factorial_Sum Farkas FeatherweightJava Featherweight_OCL Fermat3_4 FileRefinement FinFun Finger-Trees Finite_Automata_HF +Finite-Map-Extras First_Order_Terms First_Welfare_Theorem Fishburn_Impossibility Fisher_Yates Flow_Networks Floyd_Warshall Flyspeck-Tame FocusStreamsCaseStudies Forcing Formal_SSA Formula_Derivatives Fourier Free-Boolean-Algebra Free-Groups FunWithFunctions FunWithTilings Functional-Automata Functional_Ordered_Resolution_Prover Furstenberg_Topology GPU_Kernel_PL Gabow_SCC Game_Based_Crypto Gauss-Jordan-Elim-Fun Gauss_Jordan Gauss_Sums Gaussian_Integers GenClock General-Triangle Generalized_Counting_Sort Generic_Deriving Generic_Join GewirthPGCProof Girth_Chromatic GoedelGod Goedel_HFSet_Semantic Goedel_HFSet_Semanticless Goedel_Incompleteness Goodstein_Lambda GraphMarkingIBP Graph_Saturation Graph_Theory Green Groebner_Bases Groebner_Macaulay Gromov_Hyperbolicity Group-Ring-Module HOL-CSP HOLCF-Prelude HRB-Slicing Heard_Of Hello_World HereditarilyFinite Hermite Hidden_Markov_Models Higher_Order_Terms Hoare_Time HotelKeyCards Huffman Hybrid_Logic Hybrid_Multi_Lane_Spatial_Logic Hybrid_Systems_VCs HyperCTL IEEE_Floating_Point IMAP-CRDT IMO2019 IMP2 IMP2_Binary_Heap IP_Addresses Imperative_Insertion_Sort Impossible_Geometry Incompleteness Incredible_Proof_Machine Inductive_Confidentiality Inductive_Inference InfPathElimination InformationFlowSlicing InformationFlowSlicing_Inter Integration Interpreter_Optimizations Interval_Arithmetic_Word32 Iptables_Semantics Irrational_Series_Erdos_Straus Irrationality_J_Hancl Isabelle_C +Isabelle_Marries_Dirac Isabelle_Meta_Model Jacobson_Basic_Algebra Jinja JinjaThreads JiveDataStoreModel Jordan_Hoelder Jordan_Normal_Form KAD KAT_and_DRA KBPs KD_Tree Key_Agreement_Strong_Adversaries Kleene_Algebra Knuth_Bendix_Order Knot_Theory Knuth_Bendix_Order Knuth_Morris_Pratt Koenigsberg_Friendship Kruskal Kuratowski_Closure_Complement LLL_Basis_Reduction LLL_Factorization LOFT LTL LTL_Master_Theorem LTL_Normal_Form LTL_to_DRA LTL_to_GBA Lam-ml-Normalization LambdaAuth LambdaMu Lambda_Free_EPO Lambda_Free_KBOs Lambda_Free_RPOs Lambert_W Landau_Symbols Laplace_Transform Latin_Square LatticeProperties Launchbury Lazy-Lists-II Lazy_Case Lehmer Lifting_Definition_Option LightweightJava LinearQuantifierElim Linear_Inequalities Linear_Programming Linear_Recurrences Liouville_Numbers List-Index List-Infinite List_Interleaving List_Inversions List_Update LocalLexing Localization_Ring Locally-Nameless-Sigma Lowe_Ontological_Argument Lower_Semicontinuous Lp Lucas_Theorem MFMC_Countable MFODL_Monitor_Optimized MFOTL_Monitor MSO_Regex_Equivalence Markov_Models Marriage Mason_Stothers Matrices_for_ODEs Matrix Matrix_Tensor Matroids Max-Card-Matching Median_Of_Medians_Selection Menger Mersenne_Primes MiniML Minimal_SSA Minkowskis_Theorem Minsky_Machines Modal_Logics_for_NTS Modular_Assembly_Kit_Security Monad_Memo_DP Monad_Normalisation MonoBoolTranAlgebra MonoidalCategory Monomorphic_Monad MuchAdoAboutTwo Multi_Party_Computation Multirelations Myhill-Nerode Name_Carrying_Type_Inference Nash_Williams Nat-Interval-Logic Native_Word Nested_Multisets_Ordinals Network_Security_Policy_Verification Neumann_Morgenstern_Utility No_FTL_observers Nominal2 Noninterference_CSP Noninterference_Concurrent_Composition Noninterference_Generic_Unwinding Noninterference_Inductive_Unwinding Noninterference_Ipurge_Unwinding Noninterference_Sequential_Composition NormByEval Nullstellensatz Octonions OpSets Open_Induction Optics Optimal_BST Orbit_Stabiliser Order_Lattice_Props Ordered_Resolution_Prover Ordinal Ordinal_Partitions Ordinals_and_Cardinals Ordinary_Differential_Equations PAC_Checker PCF PLM POPLmark-deBruijn PSemigroupsConvolution Pairing_Heap Paraconsistency Parity_Game Partial_Function_MR Partial_Order_Reduction Password_Authentication_Protocol Pell Perfect-Number-Thm Perron_Frobenius Physical_Quantities Pi_Calculus Pi_Transcendental Planarity_Certificates Poincare_Bendixson Poincare_Disc Polynomial_Factorization Polynomial_Interpolation Polynomials Pop_Refinement Posix-Lexing Possibilistic_Noninterference Power_Sum_Polynomials Pratt_Certificate Presburger-Automata Prim_Dijkstra_Simple Prime_Distribution_Elementary Prime_Harmonic_Series Prime_Number_Theorem Priority_Queue_Braun Priority_Search_Trees Probabilistic_Noninterference Probabilistic_Prime_Tests Probabilistic_System_Zoo Probabilistic_Timed_Automata Probabilistic_While Program-Conflict-Analysis Projective_Geometry Promela Proof_Strategy_Language PropResPI Propositional_Proof_Systems Prpu_Maxflow PseudoHoops Psi_Calculi Ptolemys_Theorem QHLProver QR_Decomposition Quantales Quaternions Quick_Sort_Cost RIPEMD-160-SPARK ROBDD RSAPSS Ramsey-Infinite Random_BSTs Random_Graph_Subgraph_Threshold Randomised_BSTs Randomised_Social_Choice Rank_Nullity_Theorem Real_Impl Recursion-Addition Recursion-Theory-I Refine_Imperative_HOL Refine_Monadic RefinementReactive Regex_Equivalence Regular-Sets Regular_Algebras Relation_Algebra Relational-Incorrectness-Logic Relational_Disjoint_Set_Forests +Relational_Method +Relational_Minimum_Spanning_Trees Relational_Paths Rep_Fin_Groups Residuated_Lattices Resolution_FOL Rewriting_Z Ribbon_Proofs Robbins-Conjecture Robinson_Arithmetic Root_Balanced_Tree Routing Roy_Floyd_Warshall SATSolverVerification SC_DOM_Components SDS_Impossibility SIFPL SIFUM_Type_Systems SPARCv8 Safe_Distance Safe_OCL Saturation_Framework Saturation_Framework_Extensions Shadow_DOM Secondary_Sylow Security_Protocol_Refinement Selection_Heap_Sort SenSocialChoice Separata Separation_Algebra Separation_Logic_Imperative_HOL SequentInvertibility Shadow_SC_DOM Shivers-CFA ShortestPath Show Sigma_Commit_Crypto Signature_Groebner Simpl Simple_Firewall Simplex Skew_Heap Skip_Lists Slicing Sliding_Window_Algorithm Smith_Normal_Form Smooth_Manifolds Sort_Encodings Source_Coding_Theorem Special_Function_Bounds Splay_Tree Sqrt_Babylonian Stable_Matching Statecharts Stateful_Protocol_Composition_and_Typing Stellar_Quorums Stern_Brocot Stewart_Apollonius Stirling_Formula Stochastic_Matrices Stone_Algebras Stone_Kleene_Relation_Algebras Stone_Relation_Algebras Store_Buffer_Reduction Stream-Fusion Stream_Fusion_Code Strong_Security Sturm_Sequences Sturm_Tarski Stuttering_Equivalence Subresultants Subset_Boolean_Algebras SumSquares SuperCalc Surprise_Paradox Symmetric_Polynomials Syntax_Independent_Logic Szpilrajn TESL_Language TLA Tail_Recursive_Functions Tarskis_Geometry Taylor_Models Timed_Automata Topology TortoiseHare Transcendence_Series_Hancl_Rucki Transformer_Semantics Transition_Systems_and_Automata Transitive-Closure Transitive-Closure-II Treaps Tree-Automata Tree_Decomposition Triangle Trie Twelvefold_Way Tycon Types_Tableaus_and_Goedels_God UPF UPF_Firewall UTP Universal_Turing_Machine UpDown_Scheme Valuation VectorSpace VeriComp Verified-Prover Verified_SAT_Based_AI_Planning VerifyThis2018 VerifyThis2019 Vickrey_Clarke_Groves VolpanoSmith WHATandWHERE_Security WOOT_Strong_Eventual_Consistency WebAssembly Weight_Balanced_Trees Well_Quasi_Orders Winding_Number_Eval Word_Lib WorkerWrapper XML ZFC_in_HOL Zeta_3_Irrational Zeta_Function pGCL diff --git a/thys/Relational_Method/Anonymity.thy b/thys/Relational_Method/Anonymity.thy new file mode 100644 --- /dev/null +++ b/thys/Relational_Method/Anonymity.thy @@ -0,0 +1,591 @@ +(* Title: The Relational Method with Message Anonymity for the Verification of Cryptographic Protocols + Author: Pasquale Noce + Software Engineer at HID Global, Italy + pasquale dot noce dot lavoro at gmail dot com + pasquale dot noce at hidglobal dot com +*) + +section "Anonymity properties" + +theory Anonymity + imports Authentication +begin + +text \ +\label{Anonymity} +\ + + +proposition crypts_empty [simp]: + "crypts {} = {}" +by (rule equalityI, rule subsetI, erule crypts.induct, simp_all) + +proposition crypts_mono: + "H \ H' \ crypts H \ crypts H'" +by (rule subsetI, erule crypts.induct, auto) + +lemma crypts_union_1: + "crypts (H \ H') \ crypts H \ crypts H'" +by (rule subsetI, erule crypts.induct, auto) + +lemma crypts_union_2: + "crypts H \ crypts H' \ crypts (H \ H')" +by (rule subsetI, erule UnE, erule_tac [!] crypts.induct, auto) + +proposition crypts_union: + "crypts (H \ H') = crypts H \ crypts H'" +by (rule equalityI, rule crypts_union_1, rule crypts_union_2) + +proposition crypts_insert: + "crypts (insert X H) = crypts_msg X \ crypts H" +by (simp only: insert_def crypts_union, subst crypts_msg_def, simp) + +proposition crypts_msg_num [simp]: + "crypts_msg (Num n) = {Num n}" +by (subst crypts_msg_def, rule equalityI, rule subsetI, erule crypts.induct, simp, + rotate_tac [1-3], erule_tac [1-3] rev_mp, rule_tac [1-3] list.induct, simp_all, + blast) + +proposition crypts_msg_agent [simp]: + "crypts_msg (Agent n) = {Agent n}" +by (subst crypts_msg_def, rule equalityI, rule subsetI, erule crypts.induct, simp, + rotate_tac [1-3], erule_tac [1-3] rev_mp, rule_tac [1-3] list.induct, simp_all, + blast) + +proposition crypts_msg_pwd [simp]: + "crypts_msg (Pwd n) = {Pwd n}" +by (subst crypts_msg_def, rule equalityI, rule subsetI, erule crypts.induct, simp, + rotate_tac [1-3], erule_tac [1-3] rev_mp, rule_tac [1-3] list.induct, simp_all, + blast) + +proposition crypts_msg_key [simp]: + "crypts_msg (Key K) = {Key K}" +by (subst crypts_msg_def, rule equalityI, rule subsetI, erule crypts.induct, simp, + rotate_tac [1-3], erule_tac [1-3] rev_mp, rule_tac [1-3] list.induct, simp_all, + blast) + +proposition crypts_msg_mult [simp]: + "crypts_msg (A \ B) = {A \ B}" +by (subst crypts_msg_def, rule equalityI, rule subsetI, erule crypts.induct, simp, + rotate_tac [1-3], erule_tac [1-3] rev_mp, rule_tac [1-3] list.induct, simp_all, + blast) + +lemma crypts_hash_1: + "crypts {Hash X} \ insert (Hash X) (crypts {X})" +by (rule subsetI, erule crypts.induct, simp_all, (erule disjE, rotate_tac, erule rev_mp, + rule list.induct, simp_all, blast, (drule crypts_hash, simp)?)+) + +lemma crypts_hash_2: + "insert (Hash X) (crypts {X}) \ crypts {Hash X}" +by (rule subsetI, simp, erule disjE, blast, erule crypts.induct, simp, + subst id_apply [symmetric], subst foldr_Nil [symmetric], rule crypts_hash, simp, + blast+) + +proposition crypts_msg_hash [simp]: + "crypts_msg (Hash X) = insert (Hash X) (crypts_msg X)" +by (simp add: crypts_msg_def, rule equalityI, rule crypts_hash_1, rule crypts_hash_2) + +proposition crypts_comp: + "X \ crypts H \ Crypt K X \ crypts (Crypt K ` H)" +by (erule crypts.induct, blast, (simp only: comp_apply + [symmetric, where f = "Crypt K"] foldr_Cons [symmetric], + (erule crypts_hash | erule crypts_fst | erule crypts_snd))+) + +lemma crypts_crypt_1: + "crypts {Crypt K X} \ Crypt K ` crypts {X}" +by (rule subsetI, erule crypts.induct, simp, rotate_tac [!], erule_tac [!] rev_mp, + rule_tac [!] list.induct, auto) + +lemma crypts_crypt_2: + "Crypt K ` crypts {X} \ crypts {Crypt K X}" +by (rule subsetI, simp add: image_iff, erule bexE, drule crypts_comp, simp) + +proposition crypts_msg_crypt [simp]: + "crypts_msg (Crypt K X) = Crypt K ` crypts_msg X" +by (simp add: crypts_msg_def, rule equalityI, rule crypts_crypt_1, rule crypts_crypt_2) + +lemma crypts_mpair_1: + "crypts {\X, Y\} \ insert \X, Y\ (crypts {X} \ crypts {Y})" +by (rule subsetI, erule crypts.induct, simp_all, (erule disjE, rotate_tac, erule rev_mp, + rule list.induct, (simp+, blast)+)+) + +lemma crypts_mpair_2: + "insert \X, Y\ (crypts {X} \ crypts {Y}) \ crypts {\X, Y\}" +by (rule subsetI, simp, erule disjE, blast, erule disjE, (erule crypts.induct, simp, + subst id_apply [symmetric], subst foldr_Nil [symmetric], (rule crypts_fst [of _ X] | + rule crypts_snd), rule crypts_used, simp, blast+)+) + +proposition crypts_msg_mpair [simp]: + "crypts_msg \X, Y\ = insert \X, Y\ (crypts_msg X \ crypts_msg Y)" +by (simp add: crypts_msg_def, rule equalityI, rule crypts_mpair_1, rule crypts_mpair_2) + + +proposition foldr_crypt_size: + "size (foldr Crypt KS X) = size X + length KS" +by (induction KS, simp_all) + +proposition key_sets_empty [simp]: + "key_sets X {} = {}" +by (simp add: key_sets_def) + +proposition key_sets_mono: + "H \ H' \ key_sets X H \ key_sets X H'" +by (auto simp add: key_sets_def) + +proposition key_sets_union: + "key_sets X (H \ H') = key_sets X H \ key_sets X H'" +by (auto simp add: key_sets_def) + +proposition key_sets_insert: + "key_sets X (insert Y H) = key_sets_msg X Y \ key_sets X H" +by (simp only: insert_def key_sets_union, subst key_sets_msg_def, simp) + +proposition key_sets_msg_eq: + "key_sets_msg X X = {{}}" +by (simp add: key_sets_msg_def key_sets_def, rule equalityI, rule subsetI, simp, + erule exE, erule rev_mp, rule list.induct, simp, rule impI, erule conjE, + drule arg_cong [of _ X size], simp_all add: foldr_crypt_size) + +proposition key_sets_msg_num [simp]: + "key_sets_msg X (Num n) = (if X = Num n then {{}} else {})" +by (simp add: key_sets_msg_eq, simp add: key_sets_msg_def key_sets_def, rule impI, + rule allI, rule list.induct, simp_all) + +proposition key_sets_msg_agent [simp]: + "key_sets_msg X (Agent n) = (if X = Agent n then {{}} else {})" +by (simp add: key_sets_msg_eq, simp add: key_sets_msg_def key_sets_def, rule impI, + rule allI, rule list.induct, simp_all) + +proposition key_sets_msg_pwd [simp]: + "key_sets_msg X (Pwd n) = (if X = Pwd n then {{}} else {})" +by (simp add: key_sets_msg_eq, simp add: key_sets_msg_def key_sets_def, rule impI, + rule allI, rule list.induct, simp_all) + +proposition key_sets_msg_key [simp]: + "key_sets_msg X (Key K) = (if X = Key K then {{}} else {})" +by (simp add: key_sets_msg_eq, simp add: key_sets_msg_def key_sets_def, rule impI, + rule allI, rule list.induct, simp_all) + +proposition key_sets_msg_mult [simp]: + "key_sets_msg X (A \ B) = (if X = A \ B then {{}} else {})" +by (simp add: key_sets_msg_eq, simp add: key_sets_msg_def key_sets_def, rule impI, + rule allI, rule list.induct, simp_all) + +proposition key_sets_msg_hash [simp]: + "key_sets_msg X (Hash Y) = (if X = Hash Y then {{}} else {})" +by (simp add: key_sets_msg_eq, simp add: key_sets_msg_def key_sets_def, rule impI, + rule allI, rule list.induct, simp_all) + +lemma key_sets_crypt_1: + "X \ Crypt K Y \ + key_sets X {Crypt K Y} \ insert (InvKey K) ` key_sets X {Y}" +by (rule subsetI, simp add: key_sets_def, erule exE, rotate_tac, erule rev_mp, + rule list.induct, auto) + +lemma key_sets_crypt_2: + "insert (InvKey K) ` key_sets X {Y} \ key_sets X {Crypt K Y}" +by (rule subsetI, simp add: key_sets_def image_iff, (erule exE, erule conjE)+, + drule arg_cong [where f = "Crypt K"], simp only: comp_apply + [symmetric, of "Crypt K"] foldr_Cons [symmetric], subst conj_commute, + rule exI, rule conjI, assumption, simp) + +proposition key_sets_msg_crypt [simp]: + "key_sets_msg X (Crypt K Y) = (if X = Crypt K Y then {{}} else + insert (InvKey K) ` key_sets_msg X Y)" +by (simp add: key_sets_msg_eq, simp add: key_sets_msg_def, rule impI, + rule equalityI, erule key_sets_crypt_1 [simplified], + rule key_sets_crypt_2 [simplified]) + +proposition key_sets_msg_mpair [simp]: + "key_sets_msg X \Y, Z\ = (if X = \Y, Z\ then {{}} else {})" +by (simp add: key_sets_msg_eq, simp add: key_sets_msg_def key_sets_def, rule impI, + rule allI, rule list.induct, simp_all) + +proposition key_sets_range: + "U \ key_sets X H \ U \ range Key" +by (simp add: key_sets_def, blast) + +proposition key_sets_crypts_hash: + "key_sets (Hash X) (crypts H) \ key_sets X (crypts H)" +by (simp add: key_sets_def, blast) + +proposition key_sets_crypts_fst: + "key_sets \X, Y\ (crypts H) \ key_sets X (crypts H)" +by (simp add: key_sets_def, blast) + +proposition key_sets_crypts_snd: + "key_sets \X, Y\ (crypts H) \ key_sets Y (crypts H)" +by (simp add: key_sets_def, blast) + + +lemma log_spied_1: + "\s \ s'; + Log X \ parts (used s) \ Log X \ spied s; + Log X \ parts (used s')\ \ + Log X \ spied s'" +by (simp add: rel_def, ((erule disjE)?, ((erule exE)+)?, simp add: parts_insert, + ((subst (asm) disj_assoc [symmetric])?, erule disjE, (drule parts_dec | + drule parts_enc | drule parts_sep | drule parts_con), simp+)?)+) + +proposition log_spied [rule_format]: + "s\<^sub>0 \ s \ + Log X \ parts (used s) \ + Log X \ spied s" +by (erule rtrancl_induct, subst parts_init, simp add: Range_iff image_def, rule impI, + rule log_spied_1) + + +proposition log_dec: + "\s\<^sub>0 \ s; s' = insert (Spy, X) s \ (Spy, Crypt K X) \ s \ + (Spy, Key (InvK K)) \ s\ \ + key_sets Y (crypts {Y. Log Y = X}) \ key_sets Y (crypts (Log -` spied s))" +by (rule key_sets_mono, rule crypts_mono, rule subsetI, simp, drule parts_dec + [where Y = X], drule_tac [!] sym, simp_all, rule log_spied [simplified]) + +proposition log_sep: + "\s\<^sub>0 \ s; s' = insert (Spy, X) (insert (Spy, Y) s) \ (Spy, \X, Y\) \ s\ \ + key_sets Z (crypts {Z. Log Z = X}) \ key_sets Z (crypts (Log -` spied s)) \ + key_sets Z (crypts {Z. Log Z = Y}) \ key_sets Z (crypts (Log -` spied s))" +by (rule conjI, (rule key_sets_mono, rule crypts_mono, rule subsetI, simp, + frule parts_sep [where Z = X], drule_tac [2] parts_sep [where Z = Y], + simp_all add: parts_msg_def, blast+, drule sym, simp, + rule log_spied [simplified], assumption+)+) + + +lemma idinfo_spied_1: + "\s \ s'; + \n, X\ \ parts (used s) \ \n, X\ \ spied s; + \n, X\ \ parts (used s')\ \ + \n, X\ \ spied s'" +by (simp add: rel_def, (erule disjE, (erule exE)+, simp add: parts_insert, + ((subst (asm) disj_assoc [symmetric])?, erule disjE, (drule parts_dec | + drule parts_enc | drule parts_sep | drule parts_con), simp+)?)+, + auto simp add: parts_insert) + +proposition idinfo_spied [rule_format]: + "s\<^sub>0 \ s \ + \n, X\ \ parts (used s) \ + \n, X\ \ spied s" +by (erule rtrancl_induct, subst parts_init, simp add: Range_iff image_def, rule impI, + rule idinfo_spied_1) + + +proposition idinfo_dec: + "\s\<^sub>0 \ s; s' = insert (Spy, X) s \ (Spy, Crypt K X) \ s \ + (Spy, Key (InvK K)) \ s; \n, Y\ = X\ \ + \n, Y\ \ spied s" +by (drule parts_dec [where Y = "\n, Y\"], drule sym, simp, rule idinfo_spied) + +proposition idinfo_sep: + "\s\<^sub>0 \ s; s' = insert (Spy, X) (insert (Spy, Y) s) \ (Spy, \X, Y\) \ s; + \n, Z\ = X \ \n, Z\ = Y\ \ + \n, Z\ \ spied s" +by (drule parts_sep [where Z = "\n, Z\"], erule disjE, (drule sym, simp)+, + rule idinfo_spied) + + +lemma idinfo_msg_1: + assumes A: "s\<^sub>0 \ s" + shows "\s \ s'; \n, X\ \ spied s \ X \ spied s; \n, X\ \ spied s'\ \ + X \ spied s'" +by (simp add: rel_def, (erule disjE, (erule exE)+, simp, ((subst (asm) disj_assoc + [symmetric])?, erule disjE, (drule idinfo_dec [OF A] | drule idinfo_sep [OF A]), + simp+ | erule disjE, (simp add: image_iff)+, blast?)?)+) + +proposition idinfo_msg [rule_format]: + "s\<^sub>0 \ s \ + \n, X\ \ spied s \ + X \ spied s" +by (erule rtrancl_induct, simp, blast, rule impI, rule idinfo_msg_1) + + +proposition parts_agent: + "\s\<^sub>0 \ s; n \ bad_agent\ \ Agent n \ parts (used s)" +by (erule rtrancl_induct, subst parts_init, simp add: Range_iff image_def, simp + add: rel_def, ((erule disjE)?, (erule exE)+, simp add: parts_insert image_iff, + (rule ccontr, (drule parts_dec | drule parts_enc | drule parts_sep | + drule parts_con), simp+)?)+) + +lemma idinfo_init_1 [rule_format]: + assumes A: "s\<^sub>0 \ s" + shows "\s \ s'; n \ bad_id_password \ bad_id_pubkey \ bad_id_shakey; + \X. \n, X\ \ spied s\ \ + \n, X\ \ spied s'" +by (rule notI, simp add: rel_def, ((erule disjE)?, (erule exE)+, (blast | simp, + ((drule idinfo_dec [OF A] | drule idinfo_sep [OF A]), simp, blast | + (erule conjE)+, drule parts_agent [OF A], blast))?)+) + +proposition idinfo_init: + "\s\<^sub>0 \ s; n \ bad_id_password \ bad_id_pubkey \ bad_id_shakey\ \ + \n, X\ \ spied s" +by (induction arbitrary: X rule: rtrancl_induct, simp add: image_def, blast, + rule idinfo_init_1) + + +lemma idinfo_mpair_1 [rule_format]: + "\(s, s') \ rel_id_hash \ rel_id_crypt \ rel_id_sep \ rel_id_con; + \X Y. \n, \X, Y\\ \ spied s \ + key_sets \X, Y\ (crypts (Log -` spied s)) \ {}; + \n, \X, Y\\ \ spied s'\ \ + key_sets \X, Y\ (crypts (Log -` spied s')) \ {}" +by ((erule disjE)?, clarify?, simp add: image_iff Image_def, (drule subsetD + [OF key_sets_crypts_hash] | drule key_sets_range, blast | (drule spec)+, + drule mp, simp, simp add: ex_in_conv [symmetric], erule exE, frule subsetD + [OF key_sets_crypts_fst], drule subsetD [OF key_sets_crypts_snd])?)+ + +lemma idinfo_mpair_2 [rule_format]: + assumes A: "s\<^sub>0 \ s" + shows "\s \ s'; (s, s') \ rel_id_hash \ rel_id_crypt \ rel_id_sep \ rel_id_con; + \X Y. \n, \X, Y\\ \ spied s \ + key_sets \X, Y\ (crypts (Log -` spied s)) \ {}; + \n, \X, Y\\ \ spied s'\ \ + key_sets \X, Y\ (crypts (Log -` spied s')) \ {}" +by (simp only: rel_def Un_iff de_Morgan_disj, simp, ((erule disjE)?, (erule exE)+, + simp add: Image_def, (simp only: Collect_disj_eq crypts_union key_sets_union, simp)?, + ((subst (asm) disj_assoc [symmetric])?, erule disjE, (drule idinfo_dec [OF A] | + drule idinfo_sep [OF A]), simp+)?)+) + +proposition idinfo_mpair [rule_format]: + "s\<^sub>0 \ s \ + \n, \X, Y\\ \ spied s \ + key_sets \X, Y\ (crypts (Log -` spied s)) \ {}" +proof (induction arbitrary: X Y rule: rtrancl_induct, simp add: image_def, + rule impI) + fix s s' X Y + assume + "s\<^sub>0 \ s" and + "s \ s'" and + "\X Y. \n, \X, Y\\ \ spied s \ + key_sets \X, Y\ (crypts (Log -` spied s)) \ {}" and + "\n, \X, Y\\ \ spied s'" + thus "key_sets \X, Y\ (crypts (Log -` spied s')) \ {}" + by (cases "(s, s') \ rel_id_hash \ rel_id_crypt \ rel_id_sep \ rel_id_con", + erule_tac [2] idinfo_mpair_2, erule_tac idinfo_mpair_1, simp_all) +qed + + +proposition key_sets_pwd_empty: + "s\<^sub>0 \ s \ + key_sets (Hash (Pwd n)) (crypts (Log -` spied s)) = {} \ + key_sets \Pwd n, X\ (crypts (Log -` spied s)) = {} \ + key_sets \X, Pwd n\ (crypts (Log -` spied s)) = {}" + (is "_ \ key_sets ?X (?H s) = _ \ key_sets ?Y _ = _ \ key_sets ?Z _ = _") +proof (erule rtrancl_induct, simp add: image_iff Image_def) + fix s s' + assume + A: "s\<^sub>0 \ s" and + B: "s \ s'" and + C: "key_sets (Hash (Pwd n)) (?H s) = {} \ + key_sets \Pwd n, X\ (?H s) = {} \ + key_sets \X, Pwd n\ (?H s) = {}" + show "key_sets (Hash (Pwd n)) (?H s') = {} \ + key_sets \Pwd n, X\ (?H s') = {} \ + key_sets \X, Pwd n\ (?H s') = {}" + by (insert B C, simp add: rel_def, ((erule disjE)?, ((erule exE)+)?, simp add: + image_iff Image_def, (simp only: Collect_disj_eq crypts_union + key_sets_union, simp add: crypts_insert key_sets_insert)?, + (frule log_dec [OF A, where Y = "?X"], + frule log_dec [OF A, where Y = "?Y"], drule log_dec [OF A, where Y = "?Z"] | + frule log_sep [OF A, where Z = "?X"], frule log_sep [OF A, where Z = "?Y"], + drule log_sep [OF A, where Z = "?Z"])?)+) +qed + +proposition key_sets_pwd_seskey [rule_format]: + "s\<^sub>0 \ s \ + U \ key_sets (Pwd n) (crypts (Log -` spied s)) \ + (\SK. U = {SesKey SK} \ + ((Owner n, Crypt (SesK SK) (Pwd n)) \ s \ + (Asset n, Crypt (SesK SK) (Num 0)) \ s))" + (is "_ \ _ \ ?P s") +proof (erule rtrancl_induct, simp add: image_iff Image_def, rule impI) + fix s s' + assume + A: "s\<^sub>0 \ s" and + B: "s \ s'" and + C: "U \ key_sets (Pwd n) (crypts (Log -` spied s)) \ ?P s" and + D: "U \ key_sets (Pwd n) (crypts (Log -` spied s'))" + show "?P s'" + by (insert B C D, simp add: rel_def, ((erule disjE)?, ((erule exE)+)?, simp + add: image_iff Image_def, (simp only: Collect_disj_eq crypts_union + key_sets_union, simp add: crypts_insert key_sets_insert split: if_split_asm, + blast?)?, (erule disjE, (drule log_dec [OF A] | drule log_sep [OF A]), + (erule conjE)?, drule subsetD, simp)?)+) +qed + + +lemma pwd_anonymous_1 [rule_format]: + "\s\<^sub>0 \ s; n \ bad_id_password\ \ + \n, Pwd n\ \ spied s \ + (\SK. SesKey SK \ spied s \ + ((Owner n, Crypt (SesK SK) (Pwd n)) \ s \ + (Asset n, Crypt (SesK SK) (Num 0)) \ s))" + (is "\_; _\ \ _ \ ?P s") +proof (erule rtrancl_induct, simp add: image_def, rule impI) + fix s s' + assume + A: "s\<^sub>0 \ s" and + B: "s \ s'" and + C: "\n, Pwd n\ \ spied s \ ?P s" and + D: "\n, Pwd n\ \ spied s'" + show "?P s'" + by (insert B C D, simp add: rel_def, ((erule disjE)?, (erule exE)+, simp add: + image_iff, blast?, ((subst (asm) disj_assoc [symmetric])?, erule disjE, + (drule idinfo_dec [OF A] | drule idinfo_sep [OF A]), simp, blast+ | + insert key_sets_pwd_empty [OF A], clarsimp)?, (((erule disjE)?, erule + conjE, drule sym, simp, (drule key_sets_pwd_seskey [OF A] | drule + idinfo_mpair [OF A, simplified]), simp)+ | drule key_sets_range, blast)?)+) +qed + +theorem pwd_anonymous: + assumes + A: "s\<^sub>0 \ s" and + B: "n \ bad_id_password" and + C: "n \ bad_shakey \ (bad_pwd \ bad_prikey) \ (bad_id_pubkey \ bad_id_shak)" + shows "\n, Pwd n\ \ spied s" +proof + assume D: "\n, Pwd n\ \ spied s" + hence "n \ bad_id_password \ bad_id_pubkey \ bad_id_shakey" + by (rule contrapos_pp, rule_tac idinfo_init [OF A]) + moreover have "\SK. SesKey SK \ spied s \ + ((Owner n, Crypt (SesK SK) (Pwd n)) \ s \ + (Asset n, Crypt (SesK SK) (Num 0)) \ s)" + (is "\SK. ?P SK \ (?Q SK \ ?R SK)") + by (rule pwd_anonymous_1 [OF A B D]) + then obtain SK where "?P SK" and "?Q SK \ ?R SK" by blast + moreover { + assume "?Q SK" + hence "n \ bad_shakey \ bad_prikey" + by (rule_tac contrapos_pp [OF `?P SK`], rule_tac owner_seskey_secret [OF A]) + } + moreover { + assume "?R SK" + hence "n \ bad_shakey \ (bad_pwd \ bad_prikey)" + by (rule_tac contrapos_pp [OF `?P SK`], rule_tac asset_seskey_secret [OF A]) + } + ultimately show False + using B and C by blast +qed + + +proposition idinfo_pwd_start: + assumes + A: "s\<^sub>0 \ s" and + B: "n \ bad_agent" + shows "\s \ s'; \X. \n, X\ \ spied s' \ X \ Pwd n; + \ (\X. \n, X\ \ spied s \ X \ Pwd n)\ \ + \SK. SesKey SK \ spied s \ + ((Owner n, Crypt (SesK SK) (Pwd n)) \ s \ + (Asset n, Crypt (SesK SK) (Num 0)) \ s)" +proof (simp add: rel_def, insert parts_agent [OF A B], insert key_sets_pwd_empty + [OF A], (erule disjE, (erule exE)+, simp, erule conjE, (subst (asm) disj_assoc + [symmetric])?, (erule disjE)?, (drule idinfo_dec [OF A] | drule idinfo_sep + [OF A] | drule spec, drule mp), simp+)+, auto, rule FalseE, rule_tac [3] FalseE) + fix X U K + assume "\X. (Spy, \n, X\) \ s \ X = Pwd n" and "(Spy, \n, K\) \ s" + hence "K = Pwd n" by simp + moreover assume "U \ key_sets X (crypts (Log -` spied s))" + hence "U \ range Key" + by (rule key_sets_range) + moreover assume "K \ U" + ultimately show False by blast +next + fix X U + assume "\X. (Spy, \n, X\) \ s \ X = Pwd n" and "(Spy, \n, X\) \ s" + hence C: "X = Pwd n" by simp + moreover assume "U \ key_sets X (crypts (Log -` spied s))" + ultimately have "U \ key_sets (Pwd n) (crypts (Log -` spied s))" by simp + hence "\SK. U = {SesKey SK} \ + ((Owner n, Crypt (SesK SK) (Pwd n)) \ s \ + (Asset n, Crypt (SesK SK) (Num 0)) \ s)" + by (rule key_sets_pwd_seskey [OF A]) + moreover assume "U \ spied s" + ultimately show "\x U V. (Spy, Key (SesK (x, U, V))) \ s \ + ((Owner n, Crypt (SesK (x, U, V)) X) \ s \ + (Asset n, Crypt (SesK (x, U, V)) (Num 0)) \ s)" + using C by auto +next + fix X U K + assume "\X. (Spy, \n, X\) \ s \ X = Pwd n" and "(Spy, \n, K\) \ s" + hence "K = Pwd n" by simp + moreover assume "U \ key_sets X (crypts (Log -` spied s))" + hence "U \ range Key" + by (rule key_sets_range) + moreover assume "K \ U" + ultimately show False by blast +qed + +proposition idinfo_pwd: + "\s\<^sub>0 \ s; \X. \n, X\ \ spied s \ X \ Pwd n; + n \ bad_id_pubkey \ bad_id_shakey\ \ + \SK. SesKey SK \ spied s \ + ((Owner n, Crypt (SesK SK) (Pwd n)) \ s \ + (Asset n, Crypt (SesK SK) (Num 0)) \ s)" +by (drule rtrancl_start, assumption, simp, blast, (erule exE)+, (erule conjE)+, + frule idinfo_pwd_start [of _ n], simp+, drule r_into_rtrancl, drule rtrancl_trans, + assumption, (drule state_subset)+, blast) + + +theorem auth_prikey_anonymous: + assumes + A: "s\<^sub>0 \ s" and + B: "n \ bad_id_prikey" and + C: "n \ bad_shakey \ bad_prikey \ (bad_id_password \ bad_id_shak)" + shows "\n, Auth_PriKey n\ \ spied s" +proof + assume D: "\n, Auth_PriKey n\ \ spied s" + hence "n \ bad_id_password \ bad_id_pubkey \ bad_id_shakey" + by (rule contrapos_pp, rule_tac idinfo_init [OF A]) + moreover have "Auth_PriKey n \ spied s" + by (rule idinfo_msg [OF A D]) + hence "n \ bad_prikey" + by (rule contrapos_pp, rule_tac auth_prikey_secret [OF A]) + moreover from this have E: "n \ bad_id_pubkey" + using B by simp + moreover have "n \ bad_shakey" + proof (cases "n \ bad_id_shakey", simp) + case False + with D and E have "\SK. SesKey SK \ spied s \ + ((Owner n, Crypt (SesK SK) (Pwd n)) \ s \ + (Asset n, Crypt (SesK SK) (Num 0)) \ s)" + (is "\SK. ?P SK \ (?Q SK \ ?R SK)") + by (rule_tac idinfo_pwd [OF A], rule_tac exI [of _ "Auth_PriKey n"], simp_all) + then obtain SK where "?P SK" and "?Q SK \ ?R SK" by blast + moreover { + assume "?Q SK" + hence "n \ bad_shakey \ bad_prikey" + by (rule_tac contrapos_pp [OF `?P SK`], rule_tac owner_seskey_secret + [OF A]) + } + moreover { + assume "?R SK" + hence "n \ bad_shakey \ (bad_pwd \ bad_prikey)" + by (rule_tac contrapos_pp [OF `?P SK`], rule_tac asset_seskey_secret + [OF A]) + } + ultimately show ?thesis by blast + qed + ultimately show False + using C by blast +qed + + +theorem auth_shakey_anonymous: + assumes + A: "s\<^sub>0 \ s" and + B: "n \ bad_id_shakey" and + C: "n \ bad_shakey \ (bad_id_password \ bad_id_pubkey)" + shows "\n, Key (Auth_ShaKey n)\ \ spied s" +proof + assume D: "\n, Key (Auth_ShaKey n)\ \ spied s" + hence "n \ bad_id_password \ bad_id_pubkey \ bad_id_shakey" + by (rule contrapos_pp, rule_tac idinfo_init [OF A]) + moreover have "Key (Auth_ShaKey n) \ spied s" + by (rule idinfo_msg [OF A D]) + hence "n \ bad_shakey" + by (rule contrapos_pp, rule_tac auth_shakey_secret [OF A]) + ultimately show False + using B and C by blast +qed + + +end diff --git a/thys/Relational_Method/Authentication.thy b/thys/Relational_Method/Authentication.thy new file mode 100644 --- /dev/null +++ b/thys/Relational_Method/Authentication.thy @@ -0,0 +1,1903 @@ +(* Title: The Relational Method with Message Anonymity for the Verification of Cryptographic Protocols + Author: Pasquale Noce + Software Engineer at HID Global, Italy + pasquale dot noce dot lavoro at gmail dot com + pasquale dot noce at hidglobal dot com +*) + +section "Confidentiality and authenticity properties" + +theory Authentication + imports Definitions +begin + +text \ +\label{Authentication} +\ + + +proposition rtrancl_start [rule_format]: + "(x, y) \ r\<^sup>* \ P y \ \ P x \ + (\u v. (x, u) \ r\<^sup>* \ (u, v) \ r \ (v, y) \ r\<^sup>* \ \ P u \ P v)" + (is "_ \ _ \ _ \ (\u v. ?Q x y u v)") +proof (erule rtrancl_induct, simp, (rule impI)+) + fix y z + assume + A: "(x, y) \ r\<^sup>*" and + B: "(y, z) \ r" and + C: "P z" + assume "P y \ \ P x \(\u v. ?Q x y u v)" and "\ P x" + hence D: "P y \ (\u v. ?Q x y u v)" by simp + show "\u v. ?Q x z u v" + proof (cases "P y") + case True + with D obtain u v where "?Q x y u v" by blast + moreover from this and B have "(v, z) \ r\<^sup>*" by auto + ultimately show ?thesis by blast + next + case False + with A and B and C have "?Q x z y z" by simp + thus ?thesis by blast + qed +qed + + +proposition state_subset: + "s \ s' \ s \ s'" +by (erule rtrancl_induct, auto simp add: rel_def image_def) + +proposition spied_subset: + "s \ s' \ spied s \ spied s'" +by (rule Image_mono, erule state_subset, simp) + +proposition used_subset: + "s \ s' \ used s \ used s'" +by (rule Range_mono, rule state_subset) + +proposition asset_ii_init: + "\s\<^sub>0 \ s; (Asset n, \Num 2, PubKey A\) \ s\ \ + PriKey A \ spied s\<^sub>0" +by (drule rtrancl_start, assumption, simp add: image_def, (erule exE)+, + erule conjE, rule notI, drule spied_subset, drule subsetD, assumption, + auto simp add: rel_def) + +proposition auth_prikey_used: + "s\<^sub>0 \ s \ Auth_PriKey n \ used s" +by (drule used_subset, erule subsetD, simp add: Range_iff image_def, blast) + +proposition asset_i_used: + "s\<^sub>0 \ s \ + (Asset n, Crypt (Auth_ShaKey n) (PriKey A)) \ s \ + PriKey A \ used s" +by (erule rtrancl_induct, auto simp add: rel_def image_def) + +proposition owner_ii_used: + "s\<^sub>0 \ s \ + (Owner n, \Num 1, PubKey A\) \ s \ + PriKey A \ used s" +by (erule rtrancl_induct, auto simp add: rel_def image_def) + +proposition asset_ii_used: + "s\<^sub>0 \ s \ + (Asset n, \Num 2, PubKey A\) \ s \ + PriKey A \ used s" +by (erule rtrancl_induct, auto simp add: rel_def image_def) + +proposition owner_iii_used: + "s\<^sub>0 \ s \ + (Owner n, \Num 3, PubKey A\) \ s \ + PriKey A \ used s" +by (erule rtrancl_induct, auto simp add: rel_def image_def) + +proposition asset_iii_used: + "s\<^sub>0 \ s \ + (Asset n, \Num 4, PubKey A\) \ s \ + PriKey A \ used s" +by (erule rtrancl_induct, auto simp add: rel_def image_def) + +proposition asset_i_unique [rule_format]: + "s\<^sub>0 \ s \ + (Asset m, Crypt (Auth_ShaKey m) (PriKey A)) \ s \ + (Asset n, Crypt (Auth_ShaKey n) (PriKey A)) \ s \ + m = n" +by (erule rtrancl_induct, simp add: image_def, frule asset_i_used [of _ m A], + drule asset_i_used [of _ n A], auto simp add: rel_def) + +proposition owner_ii_unique [rule_format]: + "s\<^sub>0 \ s \ + (Owner m, \Num 1, PubKey A\) \ s \ + (Owner n, \Num 1, PubKey A\) \ s \ + m = n" +by (erule rtrancl_induct, simp add: image_def, frule owner_ii_used [of _ m A], + drule owner_ii_used [of _ n A], auto simp add: rel_def) + +proposition asset_ii_unique [rule_format]: + "s\<^sub>0 \ s \ + (Asset m, \Num 2, PubKey A\) \ s \ + (Asset n, \Num 2, PubKey A\) \ s \ + m = n" +by (erule rtrancl_induct, simp add: image_def, frule asset_ii_used [of _ m A], + drule asset_ii_used [of _ n A], auto simp add: rel_def) + +proposition auth_prikey_asset_i [rule_format]: + "s\<^sub>0 \ s \ + (Asset m, Crypt (Auth_ShaKey m) (Auth_PriKey n)) \ s \ + False" +by (erule rtrancl_induct, simp add: image_def, drule auth_prikey_used [of _ n], + auto simp add: rel_def) + +proposition auth_pubkey_owner_ii [rule_format]: + "s\<^sub>0 \ s \ + (Owner m, \Num 1, Auth_PubKey n\) \ s \ + False" +by (erule rtrancl_induct, simp add: image_def, drule auth_prikey_used [of _ n], + auto simp add: rel_def) + +proposition auth_pubkey_asset_ii [rule_format]: + "s\<^sub>0 \ s \ + (Asset m, \Num 2, Auth_PubKey n\) \ s \ + False" +by (erule rtrancl_induct, simp add: image_def, drule auth_prikey_used [of _ n], + auto simp add: rel_def) + +proposition asset_i_owner_ii [rule_format]: + "s\<^sub>0 \ s \ + (Asset m, Crypt (Auth_ShaKey m) (PriKey A)) \ s \ + (Owner n, \Num 1, PubKey A\) \ s \ + False" +by (erule rtrancl_induct, simp add: image_def, frule asset_i_used [of _ m A], + drule owner_ii_used [of _ n A], auto simp add: rel_def) + +proposition asset_i_asset_ii [rule_format]: + "s\<^sub>0 \ s \ + (Asset m, Crypt (Auth_ShaKey m) (PriKey A)) \ s \ + (Asset n, \Num 2, PubKey A\) \ s \ + False" +by (erule rtrancl_induct, simp add: image_def, frule asset_i_used [of _ m A], + drule asset_ii_used [of _ n A], auto simp add: rel_def) + +proposition asset_ii_owner_ii [rule_format]: + "s\<^sub>0 \ s \ + (Asset m, \Num 2, PubKey A\) \ s \ + (Owner n, \Num 1, PubKey A\) \ s \ + False" +by (erule rtrancl_induct, simp add: image_def, frule asset_ii_used [of _ m A], + drule owner_ii_used [of _ n A], auto simp add: rel_def) + +proposition asset_iii_owner_iii [rule_format]: + "s\<^sub>0 \ s \ + (Asset m, \Num 4, PubKey A\) \ s \ + (Owner n, \Num 3, PubKey A\) \ s \ + False" +by (erule rtrancl_induct, simp add: image_def, frule asset_iii_used [of _ m A], + drule owner_iii_used [of _ n A], auto simp add: rel_def) + +proposition asset_iv_state [rule_format]: + "s\<^sub>0 \ s \ + (Asset n, Token n (Auth_PriK n) B C SK) \ s \ + (\A D. fst (snd SK) = {A, B} \ snd (snd SK) = {C, D} \ + (Asset n, \Num 2, PubKey B\) \ s \ (Asset n, \Num 4, PubKey D\) \ s \ + Crypt (SesK SK) (PubKey D) \ used s \ (Asset n, PubKey B) \ s)" +by (erule rtrancl_induct, auto simp add: rel_def) + +proposition owner_v_state [rule_format]: + "s\<^sub>0 \ s \ + (Owner n, Crypt (SesK SK) (Pwd n)) \ s \ + (Owner n, SesKey SK) \ s \ + (\A B C. Token n A B C SK \ used s \ B \ fst (snd SK))" +by (erule rtrancl_induct, auto simp add: rel_def, blast) + +proposition asset_v_state [rule_format]: + "s\<^sub>0 \ s \ + (Asset n, Crypt (SesK SK) (Num 0)) \ s \ + (Asset n, SesKey SK) \ s \ Crypt (SesK SK) (Pwd n) \ used s" +by (erule rtrancl_induct, simp_all add: rel_def image_def, + ((erule disjE)?, (erule exE)+, simp add: Range_Un_eq)+) + +lemma owner_seskey_nonce_1: + "\s \ s'; + (Owner n, SesKey SK) \ s \ + (\S. fst SK = Some S \ Crypt (Auth_ShaKey n) (PriKey S) \ used s) \ + fst SK = None; + (Owner n, SesKey SK) \ s'\ \ + (\S. fst SK = Some S \ Crypt (Auth_ShaKey n) (PriKey S) \ used s') \ + fst SK = None" +by (simp add: rel_def, (erule disjE, (erule exE)+, simp+)+, + split if_split_asm, auto) + +proposition owner_seskey_nonce [rule_format]: + "s\<^sub>0 \ s \ + (Owner n, SesKey SK) \ s \ + (\S. fst SK = Some S \ Crypt (Auth_ShaKey n) (PriKey S) \ used s) \ + fst SK = None" +by (erule rtrancl_induct, simp add: image_def, rule impI, rule owner_seskey_nonce_1) + +proposition owner_seskey_other [rule_format]: + "s\<^sub>0 \ s \ + (Owner n, SesKey SK) \ s \ + (\A B C D. fst (snd SK) = {A, B} \ snd (snd SK) = {C, D} \ + (Owner n, \Num 1, PubKey A\) \ s \ + (Owner n, \Num 3, PubKey C\) \ s \ + (Owner n, Crypt (SesK SK) (PubKey D)) \ s)" +by (erule rtrancl_induct, auto simp add: rel_def, blast+) + +proposition asset_seskey_nonce [rule_format]: + "s\<^sub>0 \ s \ + (Asset n, SesKey SK) \ s \ + (\S. fst SK = Some S \ (Asset n, Crypt (Auth_ShaKey n) (PriKey S)) \ s)" +by (erule rtrancl_induct, auto simp add: rel_def) + +proposition asset_seskey_other [rule_format]: + "s\<^sub>0 \ s \ + (Asset n, SesKey SK) \ s \ + (\A B C D. fst (snd SK) = {A, B} \ snd (snd SK) = {C, D} \ + (Asset n, \Num 2, PubKey B\) \ s \ (Asset n, \Num 4, PubKey D\) \ s \ + (Asset n, Token n (Auth_PriK n) B C SK) \ s)" +by (erule rtrancl_induct, auto simp add: rel_def, blast) + + +declare Range_Un_eq [simp] + +proposition used_prod [simp]: + "A \ {} \ used (A \ H) = H" +by (simp add: Range_snd) + +proposition parts_idem [simp]: + "parts (parts H) = parts H" +by (rule equalityI, rule subsetI, erule parts.induct, auto) + +proposition parts_mono: + "H \ H' \ parts H \ parts H'" +by (rule subsetI, erule parts.induct, auto) + +proposition parts_msg_mono: + "X \ H \ parts_msg X \ parts H" +by (subgoal_tac "{X} \ H", subst parts_msg_def, erule parts_mono, simp) + +lemma parts_union_1: + "parts (H \ H') \ parts H \ parts H'" +by (rule subsetI, erule parts.induct, auto) + +lemma parts_union_2: + "parts H \ parts H' \ parts (H \ H')" +by (rule subsetI, erule UnE, erule_tac [!] parts.induct, auto) + +proposition parts_union [simp]: + "parts (H \ H') = parts H \ parts H'" +by (rule equalityI, rule parts_union_1, rule parts_union_2) + +proposition parts_insert: + "parts (insert X H) = parts_msg X \ parts H" +by (simp only: insert_def parts_union, subst parts_msg_def, simp) + +proposition parts_msg_num [simp]: + "parts_msg (Num n) = {Num n}" +by (subst parts_msg_def, rule equalityI, rule subsetI, erule parts.induct, auto) + +proposition parts_msg_pwd [simp]: + "parts_msg (Pwd n) = {Pwd n}" +by (subst parts_msg_def, rule equalityI, rule subsetI, erule parts.induct, auto) + +proposition parts_msg_key [simp]: + "parts_msg (Key K) = {Key K}" +by (subst parts_msg_def, rule equalityI, rule subsetI, erule parts.induct, auto) + +proposition parts_msg_mult [simp]: + "parts_msg (A \ B) = {A \ B}" +by (subst parts_msg_def, rule equalityI, rule subsetI, erule parts.induct, auto) + +proposition parts_msg_hash [simp]: + "parts_msg (Hash X) = {Hash X}" +by (subst parts_msg_def, rule equalityI, rule subsetI, erule parts.induct, auto) + +lemma parts_crypt_1: + "parts {Crypt K X} \ insert (Crypt K X) (parts {X})" +by (rule subsetI, erule parts.induct, auto) + +lemma parts_crypt_2: + "insert (Crypt K X) (parts {X}) \ parts {Crypt K X}" +by (rule subsetI, simp, erule disjE, blast, erule parts.induct, auto) + +proposition parts_msg_crypt [simp]: + "parts_msg (Crypt K X) = insert (Crypt K X) (parts_msg X)" +by (simp add: parts_msg_def, rule equalityI, rule parts_crypt_1, rule parts_crypt_2) + +lemma parts_mpair_1: + "parts {\X, Y\} \ insert \X, Y\ (parts {X} \ parts {Y})" +by (rule subsetI, erule parts.induct, auto) + +lemma parts_mpair_2: + "insert \X, Y\ (parts {X} \ parts {Y}) \ parts {\X, Y\}" +by (rule subsetI, simp, erule disjE, blast, erule disjE, erule_tac [!] parts.induct, + auto) + +proposition parts_msg_mpair [simp]: + "parts_msg \X, Y\ = insert \X, Y\ (parts_msg X \ parts_msg Y)" +by (simp add: parts_msg_def, rule equalityI, rule parts_mpair_1, rule parts_mpair_2) + +proposition parts_msg_idinfo [simp]: + "parts_msg \n, X\ = {\n, X\}" +by (subst parts_msg_def, rule equalityI, rule subsetI, erule parts.induct, auto) + +proposition parts_msg_trace [simp]: + "parts_msg (Log X) = {Log X}" +by (subst parts_msg_def, rule equalityI, rule subsetI, erule parts.induct, auto) + +proposition parts_idinfo [simp]: + "parts (IDInfo n ` H) = IDInfo n ` H" +by (rule equalityI, rule subsetI, erule parts.induct, auto) + +proposition parts_trace [simp]: + "parts (Log ` H) = Log ` H" +by (rule equalityI, rule subsetI, erule parts.induct, auto) + +proposition parts_dec: + "\s' = insert (Spy, X) s \ (Spy, Crypt K X) \ s \ (Spy, Key (InvK K)) \ s; + Y \ parts_msg X\ \ + Y \ parts (used s)" +by (subgoal_tac "X \ parts (used s)", drule parts_msg_mono [of X], auto) + +proposition parts_enc: + "\s' = insert (Spy, Crypt K X) s \ (Spy, X) \ s \ (Spy, Key K) \ s; + Y \ parts_msg X\ \ + Y \ parts (used s)" +by (subgoal_tac "X \ parts (used s)", drule parts_msg_mono [of X], auto) + +proposition parts_sep: + "\s' = insert (Spy, X) (insert (Spy, Y) s) \ (Spy, \X, Y\) \ s; + Z \ parts_msg X \ Z \ parts_msg Y\ \ + Z \ parts (used s)" +by (erule disjE, subgoal_tac "X \ parts (used s)", drule parts_msg_mono [of X], + subgoal_tac [3] "Y \ parts (used s)", drule_tac [3] parts_msg_mono [of Y], auto) + +proposition parts_con: + "\s' = insert (Spy, \X, Y\) s \ (Spy, X) \ s \ (Spy, Y) \ s; + Z \ parts_msg X \ Z \ parts_msg Y\ \ + Z \ parts (used s)" +by (erule disjE, subgoal_tac "X \ parts (used s)", drule parts_msg_mono [of X], + subgoal_tac [3] "Y \ parts (used s)", drule_tac [3] parts_msg_mono [of Y], auto) + +lemma parts_init_1: + "parts (used s\<^sub>0) \ used s\<^sub>0 \ range (Hash \ Agent) \ + range (Hash \ Auth_PubKey) \ + range (\n. \Hash (Agent n), Hash (Auth_PubKey n)\)" +by (rule subsetI, erule parts.induct, (clarify | simp add: Range_iff image_def)+) + +lemma parts_init_2: + "used s\<^sub>0 \ range (Hash \ Agent) \ range (Hash \ Auth_PubKey) \ + range (\n. \Hash (Agent n), Hash (Auth_PubKey n)\) \ parts (used s\<^sub>0)" +by (rule subsetI, auto simp add: parts_insert) + +proposition parts_init: + "parts (used s\<^sub>0) = used s\<^sub>0 \ range (Hash \ Agent) \ + range (Hash \ Auth_PubKey) \ + range (\n. \Hash (Agent n), Hash (Auth_PubKey n)\)" +by (rule equalityI, rule parts_init_1, rule parts_init_2) + + +proposition parts_crypt_prikey_start: + "\s \ s'; Crypt K (PriKey A) \ parts (used s'); + Crypt K (PriKey A) \ parts (used s)\ \ + (\n. K = Auth_ShaKey n \ + (Asset n, Crypt (Auth_ShaKey n) (PriKey A)) \ s') \ + {PriKey A, Key K} \ spied s'" +by (simp add: rel_def, erule disjE, (erule exE)+, simp add: parts_insert, blast, + (((erule disjE)?, (erule exE)+, simp add: parts_insert image_iff)+, + ((drule parts_dec | erule disjE, simp, drule parts_enc | + drule parts_sep | drule parts_con), simp+)?)+) + +proposition parts_crypt_prikey: + "\s\<^sub>0 \ s; Crypt K (PriKey A) \ parts (used s)\ \ + (\n. K = Auth_ShaKey n \ + (Asset n, Crypt (Auth_ShaKey n) (PriKey A)) \ s) \ + {PriKey A, Key K} \ spied s" +by (drule rtrancl_start, assumption, subst parts_init, simp add: Range_iff image_def, + (erule exE)+, (erule conjE)+, frule parts_crypt_prikey_start, assumption+, + (drule state_subset)+, blast) + + +proposition parts_crypt_pubkey_start: + "\s \ s'; Crypt (SesK SK) (PubKey C) \ parts (used s'); + Crypt (SesK SK) (PubKey C) \ parts (used s)\ \ + C \ snd (snd SK) \ ((\n. (Owner n, SesKey SK) \ s') \ + (\n B. (Asset n, Token n (Auth_PriK n) B C SK) \ s')) \ + SesKey SK \ spied s'" +by (simp add: rel_def, (erule disjE, (erule exE)+, simp add: parts_insert image_iff)+, + blast, erule disjE, (erule exE)+, simp add: parts_insert image_iff, blast, + (((erule disjE)?, ((erule exE)+)?, simp add: parts_insert image_iff)+, + ((drule parts_dec | drule parts_enc | drule parts_sep | drule parts_con), simp+)?)+) + +proposition parts_crypt_pubkey: + "\s\<^sub>0 \ s; Crypt (SesK SK) (PubKey C) \ parts (used s)\ \ + C \ snd (snd SK) \ ((\n. (Owner n, SesKey SK) \ s) \ + (\n B. (Asset n, Token n (Auth_PriK n) B C SK) \ s)) \ + SesKey SK \ spied s" +by (drule rtrancl_start, assumption, subst parts_init, simp add: Range_iff image_def, + (erule exE)+, (erule conjE)+, frule parts_crypt_pubkey_start, assumption+, + (drule state_subset)+, blast) + + +proposition parts_crypt_key_start: + "\s \ s'; Crypt K (Key K') \ parts (used s'); + Crypt K (Key K') \ parts (used s); K' \ range PriK \ range PubK\ \ + {Key K', Key K} \ spied s'" +by (simp add: rel_def, (((erule disjE)?, ((erule exE)+)?, simp add: parts_insert + image_iff)+, ((drule parts_dec | drule parts_enc | drule parts_sep | drule parts_con), + simp+)?)+) + +proposition parts_crypt_key: + "\s\<^sub>0 \ s; Crypt K (Key K') \ parts (used s); + K' \ range PriK \ range PubK\ \ + {Key K', Key K} \ spied s" +by (drule rtrancl_start, assumption, subst parts_init, simp add: Range_iff image_def, + (erule exE)+, (erule conjE)+, frule parts_crypt_key_start, assumption+, + (drule state_subset)+, blast) + + +proposition parts_crypt_sign_start: + "\s \ s'; Crypt (SesK SK) (Sign n A) \ parts (used s'); + Crypt (SesK SK) (Sign n A) \ parts (used s)\ \ + (Asset n, SesKey SK) \ s' \ SesKey SK \ spied s'" +by (simp add: rel_def, (((erule disjE)?, ((erule exE)+)?, simp add: parts_insert + image_iff)+, ((drule parts_dec | drule parts_enc | drule parts_sep | drule parts_con), + simp+)?)+) + +proposition parts_crypt_sign: + "\s\<^sub>0 \ s; Crypt (SesK SK) (Sign n A) \ parts (used s)\ \ + (Asset n, SesKey SK) \ s \ SesKey SK \ spied s" +by (drule rtrancl_start, assumption, subst parts_init, simp add: Range_iff image_def, + (erule exE)+, (erule conjE)+, frule parts_crypt_sign_start, assumption+, + (drule state_subset)+, blast) + + +proposition parts_crypt_pwd_start: + "\s \ s'; Crypt K (Pwd n) \ parts (used s'); + Crypt K (Pwd n) \ parts (used s)\ \ + (\SK. K = SesK SK \ (Owner n, Crypt (SesK SK) (Pwd n)) \ s') \ + {Pwd n, Key K} \ spied s'" +by (simp add: rel_def, (((erule disjE)?, ((erule exE)+)?, simp add: parts_insert + image_iff)+, ((drule parts_dec | drule parts_enc | drule parts_sep | drule parts_con), + simp+)?)+) + +proposition parts_crypt_pwd: + "\s\<^sub>0 \ s; Crypt K (Pwd n) \ parts (used s)\ \ + (\SK. K = SesK SK \ (Owner n, Crypt (SesK SK) (Pwd n)) \ s) \ + {Pwd n, Key K} \ spied s" +by (drule rtrancl_start, assumption, subst parts_init, simp add: Range_iff image_def, + (erule exE)+, (erule conjE)+, frule parts_crypt_pwd_start, assumption+, + (drule state_subset)+, blast) + + +proposition parts_crypt_num_start: + "\s \ s'; Crypt (SesK SK) (Num 0) \ parts (used s'); + Crypt (SesK SK) (Num 0) \ parts (used s)\ \ + (\n. (Asset n, Crypt (SesK SK) (Num 0)) \ s') \ SesKey SK \ spied s'" +by (simp add: rel_def, (erule disjE, (erule exE)+, simp add: parts_insert image_iff)+, + blast, (((erule disjE)?, (erule exE)+, simp add: parts_insert image_iff)+, + ((drule parts_dec | erule disjE, simp, drule parts_enc | + drule parts_sep | drule parts_con), simp+)?)+) + +proposition parts_crypt_num: + "\s\<^sub>0 \ s; Crypt (SesK SK) (Num 0) \ parts (used s)\ \ + (\n. (Asset n, Crypt (SesK SK) (Num 0)) \ s) \ SesKey SK \ spied s" +by (drule rtrancl_start, assumption, subst parts_init, simp add: Range_iff image_def, + (erule exE)+, (erule conjE)+, frule parts_crypt_num_start, assumption+, + (drule state_subset)+, blast) + + +proposition parts_crypt_mult_start: + "\s \ s'; Crypt (SesK SK) (A \ B) \ parts (used s'); + Crypt (SesK SK) (A \ B) \ parts (used s)\ \ + B \ fst (snd SK) \ (\n C. (Asset n, Token n (Auth_PriK n) B C SK) \ s') \ + {A \ B, SesKey SK} \ spied s" +by (simp add: rel_def, (erule disjE, (erule exE)+, simp add: parts_insert image_iff)+, + blast, (((erule disjE)?, (erule exE)+, simp add: parts_insert image_iff)+, + ((drule parts_dec | erule disjE, simp, drule parts_enc | + drule parts_sep | drule parts_con), simp+)?)+) + +proposition parts_crypt_mult: + "\s\<^sub>0 \ s; Crypt (SesK SK) (A \ B) \ parts (used s)\ \ + B \ fst (snd SK) \ (\n C. (Asset n, Token n (Auth_PriK n) B C SK) \ s) \ + {A \ B, SesKey SK} \ spied s" +by (drule rtrancl_start, assumption, subst parts_init, simp add: Range_iff image_def, + (erule exE)+, (erule conjE)+, frule parts_crypt_mult_start, assumption+, + drule converse_rtrancl_into_rtrancl, assumption, drule state_subset [of _ s], + drule spied_subset [of _ s], blast) + + +proposition parts_mult_start: + "\s \ s'; A \ B \ parts (used s'); A \ B \ parts (used s)\ \ + (\n SK. A = Auth_PriK n \ (Asset n, \Num 2, PubKey B\) \ s' \ + Crypt (SesK SK) (A \ B) \ parts (used s')) \ + {PriKey A, PriKey B} \ spied s'" +by (simp add: rel_def, (erule disjE, (erule exE)+, simp add: parts_insert image_iff)+, + blast, (((erule disjE)?, (erule exE)+, simp add: parts_insert image_iff)+, + ((drule parts_dec | drule parts_enc | drule parts_sep | drule parts_con), simp+)?)+) + +proposition parts_mult: + "\s\<^sub>0 \ s; A \ B \ parts (used s)\ \ + (\n. A = Auth_PriK n \ (Asset n, \Num 2, PubKey B\) \ s) \ + {PriKey A, PriKey B} \ spied s" +by (drule rtrancl_start, assumption, subst parts_init, simp add: Range_iff image_def, + (erule exE)+, (erule conjE)+, frule parts_mult_start, assumption+, + (drule state_subset)+, blast) + + +proposition parts_mpair_key_start: + "\s \ s'; \X, Y\ \ parts (used s'); \X, Y\ \ parts (used s); + X = Key K \ Y = Key K \ K \ range PubK\ \ + {X, Y} \ spied s'" +by (erule disjE, simp_all add: rel_def, + (((erule disjE)?, (erule exE)+, simp add: parts_insert image_iff)+, + ((drule parts_dec | drule parts_enc | + drule parts_sep | erule disjE, simp, drule parts_con), simp+)?)+) + +proposition parts_mpair_key: + "\s\<^sub>0 \ s; \X, Y\ \ parts (used s); + X = Key K \ Y = Key K \ K \ range PubK\ \ + {X, Y} \ spied s" +by (drule rtrancl_start, assumption, subst parts_init, simp add: Range_iff image_def, + blast, (erule exE)+, (erule conjE)+, frule parts_mpair_key_start, assumption+, + (drule state_subset)+, blast) + + +proposition parts_mpair_pwd_start: + "\s \ s'; \X, Y\ \ parts (used s'); \X, Y\ \ parts (used s); + X = Pwd n \ Y = Pwd n\ \ + {X, Y} \ spied s'" +by (erule disjE, simp_all add: rel_def, + (((erule disjE)?, (erule exE)+, simp add: parts_insert image_iff)+, + ((drule parts_dec | drule parts_enc | + drule parts_sep | erule disjE, simp, drule parts_con), simp+)?)+) + +proposition parts_mpair_pwd: + "\s\<^sub>0 \ s; \X, Y\ \ parts (used s); X = Pwd n \ Y = Pwd n\ \ + {X, Y} \ spied s" +by (drule rtrancl_start, assumption, subst parts_init, simp add: Range_iff image_def, + blast, (erule exE)+, (erule conjE)+, frule parts_mpair_pwd_start, assumption+, + (drule state_subset)+, blast) + + +proposition parts_pubkey_false_start: + assumes + A: "s\<^sub>0 \ s" and + B: "s \ s'" and + C: "Crypt (SesK SK) (PubKey C) \ parts (used s')" and + D: "Crypt (SesK SK) (PubKey C) \ parts (used s)" and + E: "\n. (Owner n, SesKey SK) \ s'" and + F: "SesKey SK \ spied s'" + shows False +proof - + have "C \ snd (snd SK) \ ((\n. (Owner n, SesKey SK) \ s') \ + (\n B. (Asset n, Token n (Auth_PriK n) B C SK) \ s')) \ + SesKey SK \ spied s'" + (is "?P C \ ((\n. ?Q n s') \ (\n B. ?R n B C s')) \ ?S s'") + by (rule parts_crypt_pubkey_start [OF B C D]) + then obtain n B where "?P C" and "?R n B C s'" + using E and F by blast + moreover have "\ ?R n B C s" + using D by blast + ultimately have "\D. Crypt (SesK SK) (PubKey D) \ used s" + (is "\D. ?U D") + using B by (auto simp add: rel_def) + then obtain D where "?U D" .. + hence "?P D \ ((\n. ?Q n s) \ (\n B. ?R n B D s)) \ ?S s" + by (rule_tac parts_crypt_pubkey [OF A], blast) + moreover have G: "s \ s'" + by (rule state_subset, insert B, simp) + have "\n. (Owner n, SesKey SK) \ s" + by (rule allI, rule notI, drule subsetD [OF G], insert E, simp) + moreover have H: "spied s \ spied s'" + by (rule Image_mono [OF G], simp) + have "SesKey SK \ spied s" + by (rule notI, drule subsetD [OF H], insert F, contradiction) + ultimately obtain n' B' where "?R n' B' D s" by blast + have "\A' D'. fst (snd SK) = {A', B'} \ snd (snd SK) = {D, D'} \ + (Asset n', \Num 2, PubKey B'\) \ s \ + (Asset n', \Num 4, PubKey D'\) \ s \ + ?U D' \ (Asset n', PubKey B') \ s" + by (rule asset_iv_state [OF A `?R n' B' D s`]) + then obtain D' where "snd (snd SK) = {D, D'}" and "?U D'" by blast + hence "Crypt (SesK SK) (PubKey C) \ parts (used s)" + using `?P C` and `?U D` by auto + thus False + using D by contradiction +qed + +proposition parts_pubkey_false: + "\s\<^sub>0 \ s; Crypt (SesK SK) (PubKey C) \ parts (used s); + \n. (Owner n, SesKey SK) \ s; SesKey SK \ spied s\ \ + False" +proof (drule rtrancl_start, assumption, subst parts_init, simp add: Range_iff image_def, + (erule exE)+, (erule conjE)+, erule parts_pubkey_false_start, assumption+, + rule allI, rule_tac [!] notI) + fix v n + assume "(Owner n, SesKey SK) \ v" and "v \ s" + hence "(Owner n, SesKey SK) \ s" + by (erule_tac rev_subsetD, rule_tac state_subset) + moreover assume "\n. (Owner n, SesKey SK) \ s" + ultimately show False by simp +next + fix v + assume "SesKey SK \ spied v" and "v \ s" + hence "SesKey SK \ spied s" + by (erule_tac rev_subsetD, rule_tac spied_subset) + moreover assume "SesKey SK \ spied s" + ultimately show False by contradiction +qed + + +proposition asset_ii_spied_start: + assumes + A: "s\<^sub>0 \ s" and + B: "s \ s'" and + C: "PriKey B \ spied s'" and + D: "PriKey B \ spied s" and + E: "(Asset n, \Num 2, PubKey B\) \ s" + shows "Auth_PriKey n \ spied s \ + (\C SK. (Asset n, Token n (Auth_PriK n) B C SK) \ s)" + (is "_ \ (\C SK. ?P n C SK s)") +proof - + have "\A. (A \ B \ spied s \ B \ A \ spied s) \ PriKey A \ spied s" + proof (insert B C D, auto simp add: rel_def, rule_tac [!] FalseE) + assume "Key (PriK B) \ used s" + moreover have "PriKey B \ used s" + by (rule asset_ii_used [OF A, THEN mp, OF E]) + ultimately show False by simp + next + fix K + assume "(Spy, Crypt K (Key (PriK B))) \ s" + hence "Crypt K (PriKey B) \ parts (used s)" by auto + hence "(\m. K = Auth_ShaKey m \ + (Asset m, Crypt (Auth_ShaKey m) (PriKey B)) \ s) \ + {PriKey B, Key K} \ spied s" + (is "(\m. _ \ ?P m) \ _") + by (rule parts_crypt_prikey [OF A]) + then obtain m where "?P m" + using D by blast + thus False + by (rule asset_i_asset_ii [OF A _ E]) + next + fix Y + assume "(Spy, \Key (PriK B), Y\) \ s" + hence "\PriKey B, Y\ \ parts (used s)" by auto + hence "{PriKey B, Y} \ spied s" + by (rule parts_mpair_key [OF A, where K = "PriK B"], simp) + thus False + using D by simp + next + fix X + assume "(Spy, \X, Key (PriK B)\) \ s" + hence "\X, PriKey B\ \ parts (used s)" by auto + hence "{X, PriKey B} \ spied s" + by (rule parts_mpair_key [OF A, where K = "PriK B"], simp add: image_def) + thus False + using D by simp + qed + then obtain A where F: "PriKey A \ spied s" and + "A \ B \ spied s \ B \ A \ spied s" + by blast + hence "A \ B \ parts (used s) \ B \ A \ parts (used s)" by blast + moreover have "B \ A \ parts (used s)" + proof + assume "B \ A \ parts (used s)" + hence "(\m. B = Auth_PriK m \ (Asset m, \Num 2, PubKey A\) \ s) \ + {PriKey B, PriKey A} \ spied s" + by (rule parts_mult [OF A]) + then obtain m where "B = Auth_PriK m" + using D by blast + hence "(Asset n, \Num 2, Auth_PubKey m\) \ s" + using E by simp + thus False + by (rule auth_pubkey_asset_ii [OF A]) + qed + ultimately have "A \ B \ parts (used s)" by simp + with A have "\u v. s\<^sub>0 \ u \ u \ v \ v \ s \ + A \ B \ parts (used u) \ A \ B \ parts (used v)" + by (rule rtrancl_start, subst parts_init, simp add: Range_iff image_def) + then obtain u v where G: "u \ v" and H: "v \ s" and + I: "A \ B \ parts (used u)" and "A \ B \ parts (used v)" + by blast + hence "(\m SK. A = Auth_PriK m \ (Asset m, \Num 2, PubKey B\) \ v \ + Crypt (SesK SK) (A \ B) \ parts (used v)) \ + {PriKey A, PriKey B} \ spied v" + by (rule_tac parts_mult_start, simp_all) + moreover have "PriKey B \ spied v" + proof + assume "PriKey B \ spied v" + hence "PriKey B \ spied s" + by (rule rev_subsetD, rule_tac spied_subset [OF H]) + thus False + using D by contradiction + qed + ultimately obtain m SK where + J: "Crypt (SesK SK) (A \ B) \ parts (used v)" and + "A = Auth_PriK m" and "(Asset m, \Num 2, PubKey B\) \ v" + by blast + moreover from this have "(Asset m, \Num 2, PubKey B\) \ s" + by (erule_tac rev_subsetD, rule_tac state_subset [OF H]) + hence "m = n" + by (rule asset_ii_unique [OF A _ E]) + ultimately have K: "Auth_PriKey n \ spied s" + using F by simp + have "Crypt (SesK SK) (A \ B) \ parts (used u)" + using I by blast + hence "B \ fst (snd SK) \ (\m C. ?P m C SK v) \ + {A \ B, SesKey SK} \ spied u" + by (rule parts_crypt_mult_start [OF G J]) + moreover have "A \ B \ spied u" + using I by blast + ultimately obtain m' C where "?P m' C SK v" by blast + hence "?P m' C SK s" + by (rule rev_subsetD, rule_tac state_subset [OF H]) + moreover from this have "\A' D. fst (snd SK) = {A', B} \ + snd (snd SK) = {C, D} \ (Asset m', \Num 2, PubKey B\) \ s \ + (Asset m', \Num 4, PubKey D\) \ s \ + Crypt (SesK SK) (PubKey D) \ used s \ (Asset m', PubKey B) \ s" + by (rule asset_iv_state [OF A]) + hence "(Asset m', \Num 2, PubKey B\) \ s" by blast + hence "m' = n" + by (rule asset_ii_unique [OF A _ E]) + ultimately show ?thesis + using K by blast +qed + +proposition asset_ii_spied: + assumes + A: "s\<^sub>0 \ s" and + B: "PriKey B \ spied s" and + C: "(Asset n, \Num 2, PubKey B\) \ s" + shows "Auth_PriKey n \ spied s \ + (\C SK. (Asset n, Token n (Auth_PriK n) B C SK) \ s)" + (is "?P s") +proof - + have "\u v. s\<^sub>0 \ u \ u \ v \ v \ s \ + (Asset n, \Num 2, PubKey B\) \ u \ (Asset n, \Num 2, PubKey B\) \ v" + using A and C by (rule rtrancl_start, auto) + then obtain u v where "v \ s" and "(Asset n, \Num 2, PubKey B\) \ u" and + D: "s\<^sub>0 \ u" and E: "u \ v" and F: "(Asset n, \Num 2, PubKey B\) \ v" + by blast + moreover from this have "PriKey B \ spied v" + by (auto simp add: rel_def) + ultimately have "\w x. v \ w \ w \ x \ x \ s \ + PriKey B \ spied w \ PriKey B \ spied x" + using B by (rule_tac rtrancl_start, simp_all) + then obtain w x where "PriKey B \ spied w" and "PriKey B \ spied x" and + G: "v \ w" and H: "w \ x" and I: "x \ s" + by blast + moreover from this have "s\<^sub>0 \ w" + using D and E by simp + moreover have "(Asset n, \Num 2, PubKey B\) \ w" + by (rule rev_subsetD [OF F], rule state_subset [OF G]) + ultimately have "?P w" + by (rule_tac asset_ii_spied_start, simp_all) + moreover have "w \ s" + using H and I by (rule_tac state_subset, simp) + ultimately show ?thesis by blast +qed + + +proposition asset_iv_unique: + assumes + A: "s\<^sub>0 \ s" and + B: "(Asset m, Token m (Auth_PriK m) B C' SK') \ s" and + C: "(Asset n, Token n (Auth_PriK n) B C SK) \ s" + (is "?P n C SK s") + shows "m = n \ C' = C \ SK' = SK" +proof (subst (2) cases_simp [of "m = n", symmetric], simp, rule conjI, rule impI, + rule ccontr) + assume D: "\ (C' = C \ SK' = SK)" and "m = n" + moreover have "\u v. s\<^sub>0 \ u \ u \ v \ v \ s \ + \ (?P m C' SK' u \ ?P n C SK u) \ ?P m C' SK' v \ ?P n C SK v" + using B and C by (rule_tac rtrancl_start [OF A], auto) + ultimately obtain u v where E: "s\<^sub>0 \ u" and F: "u \ v" and + G: "?P n C' SK' v" and H: "?P n C SK v" and + "\ ?P n C' SK' u \ \ ?P n C SK u" + by blast + moreover { + assume I: "\ ?P n C' SK' u" + hence "?P n C SK u" + by (insert D F G H, auto simp add: rel_def) + hence "\A D. fst (snd SK) = {A, B} \ snd (snd SK) = {C, D} \ + (Asset n, \Num 2, PubKey B\) \ u \ (Asset n, \Num 4, PubKey D\) \ u \ + Crypt (SesK SK) (PubKey D) \ used u \ (Asset n, PubKey B) \ u" + by (rule asset_iv_state [OF E]) + moreover have "(Asset n, PubKey B) \ u" + by (insert F G I, auto simp add: rel_def) + ultimately have False by simp + } + moreover { + assume I: "\ ?P n C SK u" + hence "?P n C' SK' u" + by (insert D F G H, auto simp add: rel_def) + hence "\A D. fst (snd SK') = {A, B} \ snd (snd SK') = {C', D} \ + (Asset n, \Num 2, PubKey B\) \ u \ (Asset n, \Num 4, PubKey D\) \ u \ + Crypt (SesK SK') (PubKey D) \ used u \ (Asset n, PubKey B) \ u" + by (rule asset_iv_state [OF E]) + moreover have "(Asset n, PubKey B) \ u" + by (insert F H I, auto simp add: rel_def) + ultimately have False by simp + } + ultimately show False by blast +next + have "\A D. fst (snd SK') = {A, B} \ snd (snd SK') = {C', D} \ + (Asset m, \Num 2, PubKey B\) \ s \ (Asset m, \Num 4, PubKey D\) \ s \ + Crypt (SesK SK') (PubKey D) \ used s \ (Asset m, PubKey B) \ s" + (is "?Q m C' SK'") + by (rule asset_iv_state [OF A B]) + hence "(Asset m, \Num 2, PubKey B\) \ s" by blast + moreover have "?Q n C SK" + by (rule asset_iv_state [OF A C]) + hence "(Asset n, \Num 2, PubKey B\) \ s" by blast + ultimately show "m = n" + by (rule asset_ii_unique [OF A]) +qed + + +theorem sigkey_secret: + "s\<^sub>0 \ s \ SigKey \ spied s" +proof (erule rtrancl_induct, simp add: image_def) + fix s s' + assume + A: "s\<^sub>0 \ s" and + B: "s \ s'" and + C: "SigKey \ spied s" + show "SigKey \ spied s'" + proof (insert B C, auto simp add: rel_def) + fix K + assume "(Spy, Crypt K SigKey) \ s" + hence "Crypt K SigKey \ parts (used s)" by blast + hence "{SigKey, Key K} \ spied s" + by (rule parts_crypt_key [OF A], simp add: image_def) + with C show False by simp + next + fix Y + assume "(Spy, \SigKey, Y\) \ s" + hence "\SigKey, Y\ \ parts (used s)" by blast + hence "{SigKey, Y} \ spied s" + by (rule parts_mpair_key [OF A, where K = "SigK"], simp) + with C show False by simp + next + fix X + assume "(Spy, \X, SigKey\) \ s" + hence "\X, SigKey\ \ parts (used s)" by blast + hence "{X, SigKey} \ spied s" + by (rule parts_mpair_key [OF A, where K = "SigK"], simp add: image_def) + with C show False by simp + qed +qed + +proposition parts_sign_start: + assumes A: "s\<^sub>0 \ s" + shows "\s \ s'; Sign n A \ parts (used s'); Sign n A \ parts (used s)\ \ + A = Auth_PriK n" +by (simp add: rel_def, (((erule disjE)?, (erule exE)+, simp add: parts_insert image_iff)+, + ((drule parts_dec | erule disjE, insert sigkey_secret [OF A], simp, drule parts_enc | + drule parts_sep | drule parts_con), simp+)?)+) + +proposition parts_sign: + "\s\<^sub>0 \ s; Sign n A \ parts (used s)\ \ + A = Auth_PriK n" +by (rule classical, drule rtrancl_start, assumption, subst parts_init, simp add: + Range_iff image_def, (erule exE)+, (erule conjE)+, drule parts_sign_start) + + +theorem auth_shakey_secret: + "\s\<^sub>0 \ s; n \ bad_shakey\ \ + Key (Auth_ShaKey n) \ spied s" +proof (erule rtrancl_induct, simp add: image_def) + fix s s' + assume + A: "s\<^sub>0 \ s" and + B: "s \ s'" and + C: "Key (Auth_ShaKey n) \ spied s" + show "Key (Auth_ShaKey n) \ spied s'" + proof (insert B C, auto simp add: rel_def) + fix K + assume "(Spy, Crypt K (Key (ShaK (Auth_ShaK n)))) \ s" + hence "Crypt K (Key (Auth_ShaKey n)) \ parts (used s)" by auto + hence "{Key (Auth_ShaKey n), Key K} \ spied s" + by (rule parts_crypt_key [OF A], simp add: image_def) + with C show False by simp + next + fix Y + assume "(Spy, \Key (ShaK (Auth_ShaK n)), Y\) \ s" + hence "\Key (Auth_ShaKey n), Y\ \ parts (used s)" by auto + hence "{Key (Auth_ShaKey n), Y} \ spied s" + by (rule parts_mpair_key [OF A, where K = "Auth_ShaKey n"], simp) + with C show False by simp + next + fix X + assume "(Spy, \X, Key (ShaK (Auth_ShaK n))\) \ s" + hence "\X, Key (Auth_ShaKey n)\ \ parts (used s)" by auto + hence "{X, Key (Auth_ShaKey n)} \ spied s" + by (rule parts_mpair_key [OF A, where K = "Auth_ShaKey n"], + simp add: image_def) + with C show False by simp + qed +qed + + +theorem auth_prikey_secret: + assumes + A: "s\<^sub>0 \ s" and + B: "n \ bad_prikey" + shows "Auth_PriKey n \ spied s" +proof + assume "Auth_PriKey n \ spied s" + moreover have "Auth_PriKey n \ spied s\<^sub>0" + using B by auto + ultimately have "\u v. s\<^sub>0 \ u \ u \ v \ v \ s \ + Auth_PriKey n \ spied u \ Auth_PriKey n \ spied v" + by (rule rtrancl_start [OF A]) + then obtain u v where C: "s\<^sub>0 \ u" and D: "u \ v" and + E: "Auth_PriKey n \ spied u" and F: "Auth_PriKey n \ spied v" + by blast + have "\B. (Auth_PriK n \ B \ spied u \ B \ Auth_PriK n \ spied u) \ + PriKey B \ spied u" + proof (insert D E F, auto simp add: rel_def, rule_tac [!] FalseE) + assume "Key (PriK (Auth_PriK n)) \ used u" + moreover have "Auth_PriKey n \ used u" + by (rule auth_prikey_used [OF C]) + ultimately show False by simp + next + fix K + assume "(Spy, Crypt K (Key (PriK (Auth_PriK n)))) \ u" + hence "Crypt K (PriKey (Auth_PriK n)) \ parts (used u)" by auto + hence "(\m. K = Auth_ShaKey m \ + (Asset m, Crypt (Auth_ShaKey m) (PriKey (Auth_PriK n))) \ u) \ + {PriKey (Auth_PriK n), Key K} \ spied u" + by (rule parts_crypt_prikey [OF C]) + then obtain m where + "(Asset m, Crypt (Auth_ShaKey m) (Auth_PriKey n)) \ u" + using E by auto + thus False + by (rule auth_prikey_asset_i [OF C]) + next + fix Y + assume "(Spy, \Key (PriK (Auth_PriK n)), Y\) \ u" + hence "\Auth_PriKey n, Y\ \ parts (used u)" by auto + hence "{Auth_PriKey n, Y} \ spied u" + by (rule parts_mpair_key [OF C, where K = "PriK (Auth_PriK n)"], simp) + thus False + using E by simp + next + fix X + assume "(Spy, \X, Key (PriK (Auth_PriK n))\) \ u" + hence "\X, Auth_PriKey n\ \ parts (used u)" by auto + hence "{X, Auth_PriKey n} \ spied u" + by (rule parts_mpair_key [OF C, where K = "PriK (Auth_PriK n)"], simp + add: image_def) + thus False + using E by simp + qed + then obtain B where G: "PriKey B \ spied u" and + "Auth_PriK n \ B \ spied u \ B \ Auth_PriK n \ spied u" + by blast + hence "Auth_PriK n \ B \ parts (used u) \ B \ Auth_PriK n \ parts (used u)" + by blast + moreover have "B \ Auth_PriK n \ parts (used u)" + proof + assume "B \ Auth_PriK n \ parts (used u)" + hence "(\m. B = Auth_PriK m \ + (Asset m, \Num 2, PubKey (Auth_PriK n)\) \ u) \ + {PriKey B, PriKey (Auth_PriK n)} \ spied u" + by (rule parts_mult [OF C]) + then obtain m where "(Asset m, \Num 2, Auth_PubKey n\) \ u" + using E by auto + thus False + by (rule auth_pubkey_asset_ii [OF C]) + qed + ultimately have "Auth_PriK n \ B \ parts (used u)" by simp + hence "(\m. Auth_PriK n = Auth_PriK m \ + (Asset m, \Num 2, PubKey B\) \ u) \ + {PriKey (Auth_PriK n), PriKey B} \ spied u" + by (rule parts_mult [OF C]) + then obtain m where "Auth_PriK n = Auth_PriK m" and + "(Asset m, \Num 2, PubKey B\) \ u" + using E by auto + moreover from this have "Auth_PriKey m \ spied u \ + (\C SK. (Asset m, Token m (Auth_PriK m) B C SK) \ u)" + by (rule_tac asset_ii_spied [OF C G]) + ultimately show False + using E by simp +qed + +proposition asset_ii_secret: + "\s\<^sub>0 \ s; n \ bad_prikey; (Asset n, \Num 2, PubKey B\) \ s\ \ + PriKey B \ spied s" +by (rule notI, frule asset_ii_spied, assumption+, drule auth_prikey_secret, simp+) + + +proposition asset_i_secret [rule_format]: + assumes + A: "s\<^sub>0 \ s" and + B: "n \ bad_shakey" + shows "(Asset n, Crypt (Auth_ShaKey n) (PriKey S)) \ s \ + PriKey S \ spied s" +proof (rule rtrancl_induct [OF A], simp add: image_def, rule impI) + fix s s' + assume + C: "s\<^sub>0 \ s" and + D: "s \ s'" and + E: "(Asset n, Crypt (Auth_ShaKey n) (PriKey S)) \ s \ + PriKey S \ spied s" and + F: "(Asset n, Crypt (Auth_ShaKey n) (PriKey S)) \ s'" + show "PriKey S \ spied s'" + proof (insert D E F, auto simp add: rel_def) + assume "(Asset n, Crypt (ShaK (Auth_ShaK n)) (Key (PriK S))) \ s" + hence "(Asset n, Crypt (Auth_ShaKey n) (PriKey S)) \ s" by simp + hence "PriKey S \ used s" + by (rule asset_i_used [OF C, THEN mp]) + moreover assume "Key (PriK S) \ used s" + ultimately show False by simp + next + fix K + assume "(Spy, Crypt K (Key (PriK S))) \ s" + hence "Crypt K (PriKey S) \ parts (used s)" by auto + hence "(\m. K = Auth_ShaKey m \ + (Asset m, Crypt (Auth_ShaKey m) (PriKey S)) \ s) \ + {PriKey S, Key K} \ spied s" + (is "(\m. ?P m \ ?Q m) \ _") + by (rule parts_crypt_prikey [OF C]) + moreover assume "(Spy, Key (PriK S)) \ s" + ultimately obtain m where G: "?P m \ ?Q m" by auto + hence "?Q m" .. + moreover assume + "(Asset n, Crypt (ShaK (Auth_ShaK n)) (Key (PriK S))) \ s" + hence "(Asset n, Crypt (Auth_ShaKey n) (PriKey S)) \ s" by simp + ultimately have "m = n" + by (rule asset_i_unique [OF C]) + moreover assume "(Spy, Key (InvK K)) \ s" + ultimately have "Key (Auth_ShaKey n) \ spied s" + using G by simp + moreover have "Key (Auth_ShaKey n) \ spied s" + by (rule auth_shakey_secret [OF C B]) + ultimately show False by contradiction + next + fix B + assume "(Spy, S \ B) \ s" + hence "S \ B \ parts (used s)" by blast + hence "(\m. S = Auth_PriK m \ (Asset m, \Num 2, PubKey B\) \ s) \ + {PriKey S, PriKey B} \ spied s" + (is "(\m. ?P m \ _) \ _") + by (rule parts_mult [OF C]) + moreover assume "(Spy, Key (PriK S)) \ s" + ultimately obtain m where "?P m" by auto + moreover assume + "(Asset n, Crypt (ShaK (Auth_ShaK n)) (Key (PriK S))) \ s" + ultimately have "(Asset n, Crypt (Auth_ShaKey n) (Auth_PriKey m)) \ s" + by simp + thus False + by (rule auth_prikey_asset_i [OF C]) + next + fix A + assume "(Spy, A \ S) \ s" + hence "A \ S \ parts (used s)" by blast + hence "(\m. A = Auth_PriK m \ (Asset m, \Num 2, PubKey S\) \ s) \ + {PriKey A, PriKey S} \ spied s" + (is "(\m. _ \ ?P m) \ _") + by (rule parts_mult [OF C]) + moreover assume "(Spy, Key (PriK S)) \ s" + ultimately obtain m where "?P m" by auto + assume "(Asset n, Crypt (ShaK (Auth_ShaK n)) (Key (PriK S))) \ s" + hence "(Asset n, Crypt (Auth_ShaKey n) (PriKey S)) \ s" by simp + thus False + by (rule asset_i_asset_ii [OF C _ `?P m`]) + next + fix Y + assume "(Spy, \Key (PriK S), Y\) \ s" + hence "\PriKey S, Y\ \ parts (used s)" by auto + hence "{PriKey S, Y} \ spied s" + by (rule parts_mpair_key [OF C, where K = "PriK S"], simp) + moreover assume "(Spy, Key (PriK S)) \ s" + ultimately show False by simp + next + fix X + assume "(Spy, \X, Key (PriK S)\) \ s" + hence "\X, PriKey S\ \ parts (used s)" by auto + hence "{X, PriKey S} \ spied s" + by (rule parts_mpair_key [OF C, where K = "PriK S"], simp add: image_def) + moreover assume "(Spy, Key (PriK S)) \ s" + ultimately show False by simp + qed +qed + +proposition owner_ii_secret [rule_format]: + "s\<^sub>0 \ s \ + (Owner n, \Num 1, PubKey A\) \ s \ + PriKey A \ spied s" +proof (erule rtrancl_induct, simp add: image_def, rule impI) + fix s s' + assume + A: "s\<^sub>0 \ s" and + B: "s \ s'" and + C: "(Owner n, \Num 1, PubKey A\) \ s \ PriKey A \ spied s" and + D: "(Owner n, \Num 1, PubKey A\) \ s'" + show "PriKey A \ spied s'" + proof (insert B C D, auto simp add: rel_def) + assume "(Owner n, \Num (Suc 0), Key (PubK A)\) \ s" + hence "(Owner n, \Num 1, PubKey A\) \ s" by simp + hence "PriKey A \ used s" + by (rule owner_ii_used [OF A, THEN mp]) + moreover assume "Key (PriK A) \ used s" + ultimately show False by simp + next + fix K + assume "(Spy, Crypt K (Key (PriK A))) \ s" + hence "Crypt K (PriKey A) \ parts (used s)" by auto + hence "(\m. K = Auth_ShaKey m \ + (Asset m, Crypt (Auth_ShaKey m) (PriKey A)) \ s) \ + {PriKey A, Key K} \ spied s" + (is "(\m. _ \ ?P m) \ _") + by (rule parts_crypt_prikey [OF A]) + moreover assume "(Spy, Key (PriK A)) \ s" + ultimately obtain m where "?P m" by auto + moreover assume "(Owner n, \Num (Suc 0), Key (PubK A)\) \ s" + hence "(Owner n, \Num 1, PubKey A\) \ s" by simp + ultimately show False + by (rule asset_i_owner_ii [OF A]) + next + fix B + assume "(Spy, A \ B) \ s" + hence "A \ B \ parts (used s)" by blast + hence "(\m. A = Auth_PriK m \ (Asset m, \Num 2, PubKey B\) \ s) \ + {PriKey A, PriKey B} \ spied s" + (is "(\m. ?P m \ _) \ _") + by (rule parts_mult [OF A]) + moreover assume "(Spy, Key (PriK A)) \ s" + ultimately obtain m where "?P m" by auto + moreover assume "(Owner n, \Num (Suc 0), Key (PubK A)\) \ s" + ultimately have "(Owner n, \Num 1, Auth_PubKey m\) \ s" by simp + thus False + by (rule auth_pubkey_owner_ii [OF A]) + next + fix B + assume "(Spy, B \ A) \ s" + hence "B \ A \ parts (used s)" by blast + hence "(\m. B = Auth_PriK m \ (Asset m, \Num 2, PubKey A\) \ s) \ + {PriKey B, PriKey A} \ spied s" + (is "(\m. _ \ ?P m) \ _") + by (rule parts_mult [OF A]) + moreover assume "(Spy, Key (PriK A)) \ s" + ultimately obtain m where "?P m" by auto + moreover assume "(Owner n, \Num (Suc 0), Key (PubK A)\) \ s" + hence "(Owner n, \Num 1, PubKey A\) \ s" by simp + ultimately show False + by (rule asset_ii_owner_ii [OF A]) + next + fix Y + assume "(Spy, \Key (PriK A), Y\) \ s" + hence "\PriKey A, Y\ \ parts (used s)" by auto + hence "{PriKey A, Y} \ spied s" + by (rule parts_mpair_key [OF A, where K = "PriK A"], simp) + moreover assume "(Spy, Key (PriK A)) \ s" + ultimately show False by simp + next + fix X + assume "(Spy, \X, Key (PriK A)\) \ s" + hence "\X, PriKey A\ \ parts (used s)" by auto + hence "{X, PriKey A} \ spied s" + by (rule parts_mpair_key [OF A, where K = "PriK A"], simp add: image_def) + moreover assume "(Spy, Key (PriK A)) \ s" + ultimately show False by simp + qed +qed + +proposition seskey_spied [rule_format]: + "s\<^sub>0 \ s \ + SesKey SK \ spied s \ + (\S A C. fst SK = Some S \ A \ fst (snd SK) \ C \ snd (snd SK) \ + {PriKey S, PriKey A, PriKey C} \ spied s)" + (is "_ \ _ \ (\S A C. ?P S A C s)") +proof (erule rtrancl_induct, simp add: image_def, rule impI) + fix s s' + assume + A: "s\<^sub>0 \ s" and + B: "s \ s'" and + C: "SesKey SK \ spied s \ (\S A C. ?P S A C s)" and + D: "SesKey SK \ spied s'" + show "\S A C. ?P S A C s'" + proof (insert B C D, auto simp add: rel_def, blast, rule_tac [!] FalseE) + fix K + assume "(Spy, Crypt K (Key (SesK SK))) \ s" + hence "Crypt K (Key (SesK SK)) \ parts (used s)" by blast + hence "{Key (SesK SK), Key K} \ spied s" + by (rule parts_crypt_key [OF A], simp add: image_def) + moreover assume "(Spy, Key (SesK SK)) \ s" + ultimately show False by simp + next + fix Y + assume "(Spy, \Key (SesK SK), Y\) \ s" + hence "\SesKey SK, Y\ \ parts (used s)" by auto + hence "{SesKey SK, Y} \ spied s" + by (rule parts_mpair_key [OF A, where K = "SesK SK"], simp) + moreover assume "(Spy, Key (SesK SK)) \ s" + ultimately show False by simp + next + fix X + assume "(Spy, \X, Key (SesK SK)\) \ s" + hence "\X, SesKey SK\ \ parts (used s)" by auto + hence "{X, SesKey SK} \ spied s" + by (rule parts_mpair_key [OF A, where K = "SesK SK"], simp add: image_def) + moreover assume "(Spy, Key (SesK SK)) \ s" + ultimately show False by simp + qed +qed + +proposition owner_seskey_shakey: + assumes + A: "s\<^sub>0 \ s" and + B: "n \ bad_shakey" and + C: "(Owner n, SesKey SK) \ s" + shows "SesKey SK \ spied s" +proof + have "(\S. fst SK = Some S \ Crypt (Auth_ShaKey n) (PriKey S) \ used s) \ + fst SK = None" + (is "(\S. ?P S) \ _") + by (rule owner_seskey_nonce [OF A C]) + moreover assume "SesKey SK \ spied s" + hence D: "\S A C. fst SK = Some S \ A \ fst (snd SK) \ + C \ snd (snd SK) \ {PriKey S, PriKey A, PriKey C} \ spied s" + by (rule seskey_spied [OF A]) + ultimately obtain S where "?P S" by auto + hence "Crypt (Auth_ShaKey n) (PriKey S) \ parts (used s)" by blast + hence "(\m. Auth_ShaKey n = Auth_ShaKey m \ + (Asset m, Crypt (Auth_ShaKey m) (PriKey S)) \ s) \ + {PriKey S, Key (Auth_ShaKey n)} \ spied s" + (is "(\m. ?Q m \ ?R m) \ _") + by (rule parts_crypt_prikey [OF A]) + moreover have "Key (Auth_ShaKey n) \ spied s" + by (rule auth_shakey_secret [OF A B]) + ultimately obtain m where "?Q m" and "?R m" by blast + hence "m \ bad_shakey" + using B by simp + hence "PriKey S \ spied s" + by (rule asset_i_secret [OF A _ `?R m`]) + moreover have "PriKey S \ spied s" + using D and `?P S` by auto + ultimately show False by contradiction +qed + +proposition owner_seskey_prikey: + assumes + A: "s\<^sub>0 \ s" and + B: "n \ bad_prikey" and + C: "(Owner m, SesKey SK) \ s" and + D: "(Asset n, \Num 2, PubKey B\) \ s" and + E: "B \ fst (snd SK)" + shows "SesKey SK \ spied s" +proof + have "\A B C D. fst (snd SK) = {A, B} \ snd (snd SK) = {C, D} \ + (Owner m, \Num 1, PubKey A\) \ s \ + (Owner m, \Num 3, PubKey C\) \ s \ + (Owner m, Crypt (SesK SK) (PubKey D)) \ s" + (is "\A B C D. ?P A B \ _ \ ?Q A \ _") + by (rule owner_seskey_other [OF A C]) + then obtain A B' where "?P A B'" and "?Q A" by blast + assume "SesKey SK \ spied s" + hence "\S A' C. fst SK = Some S \ A' \ fst (snd SK) \ C \ snd (snd SK) \ + {PriKey S, PriKey A', PriKey C} \ spied s" + (is "\S A' C. _ \ ?R A' \ _") + by (rule seskey_spied [OF A]) + then obtain A' where "A' \ fst (snd SK)" and "PriKey A' \ spied s" (is "?R A'") + by blast + hence "{A', A, B} \ {A, B'}" + using E and `?P A B'` by simp + hence "card {A', A, B} \ card {A, B'}" + by (rule_tac card_mono, simp) + also have "\ \ Suc (Suc 0)" + by (rule card_insert_le_m1, simp_all) + finally have "card {A', A, B} \ Suc (Suc 0)" . + moreover have "card {A', A, B} = Suc (card {A, B})" + proof (rule card_insert_disjoint, simp_all, rule conjI, rule_tac [!] notI) + assume "A' = A" + hence "?R A" + using `?R A'` by simp + moreover have "\ ?R A" + by (rule owner_ii_secret [OF A `?Q A`]) + ultimately show False by contradiction + next + assume "A' = B" + hence "?R B" + using `?R A'` by simp + moreover have "\ ?R B" + by (rule asset_ii_secret [OF A B D]) + ultimately show False by contradiction + qed + moreover have "card {A, B} = Suc (card {B})" + proof (rule card_insert_disjoint, simp_all, rule notI) + assume "A = B" + hence "(Asset n, \Num 2, PubKey A\) \ s" + using D by simp + thus False + by (rule asset_ii_owner_ii [OF A _ `?Q A`]) + qed + ultimately show False by simp +qed + +proposition asset_seskey_shakey: + assumes + A: "s\<^sub>0 \ s" and + B: "n \ bad_shakey" and + C: "(Asset n, SesKey SK) \ s" + shows "SesKey SK \ spied s" +proof + have "\S. fst SK = Some S \ + (Asset n, Crypt (Auth_ShaKey n) (PriKey S)) \ s" + (is "\S. ?P S \ ?Q S") + by (rule asset_seskey_nonce [OF A C]) + then obtain S where "?P S" and "?Q S" by blast + have "PriKey S \ spied s" + by (rule asset_i_secret [OF A B `?Q S`]) + moreover assume "SesKey SK \ spied s" + hence "\S A C. fst SK = Some S \ A \ fst (snd SK) \ C \ snd (snd SK) \ + {PriKey S, PriKey A, PriKey C} \ spied s" + by (rule seskey_spied [OF A]) + hence "PriKey S \ spied s" + using `?P S` by auto + ultimately show False by contradiction +qed + + +theorem owner_seskey_unique: + assumes + A: "s\<^sub>0 \ s" and + B: "(Owner m, Crypt (SesK SK) (Pwd m)) \ s" and + C: "(Owner n, Crypt (SesK SK) (Pwd n)) \ s" + shows "m = n" +proof (rule ccontr) + have D: "(Owner m, SesKey SK) \ s \ + (\A B C. Token m A B C SK \ used s \ B \ fst (snd SK))" + (is "?P m \ (\A B C. ?Q m A B C)") + by (rule owner_v_state [OF A B]) + hence "?P m" by blast + hence "\A B C D. fst (snd SK) = {A, B} \ snd (snd SK) = {C, D} \ + (Owner m, \Num 1, PubKey A\) \ s \ + (Owner m, \Num 3, PubKey C\) \ s \ + (Owner m, Crypt (SesK SK) (PubKey D)) \ s" + (is "\A B C D. ?R A B \ ?S C D \ ?T m A \ ?U m C D") + by (rule owner_seskey_other [OF A]) + then obtain A B where "?R A B" and "?T m A" by blast + have "?P n \ (\A B C. ?Q n A B C)" + by (rule owner_v_state [OF A C]) + hence "?P n" by blast + hence "\A B C D. ?R A B \ ?S C D \ ?T n A \ ?U n C D" + by (rule owner_seskey_other [OF A]) + then obtain A' B' where "?R A' B'" and "?T n A'" by blast + from D obtain A'' B'' C where "?Q m A'' B'' C" by blast + hence "Token m A'' B'' C SK \ parts (used s)" by blast + hence "Crypt (SesK SK) (A'' \ B'') \ parts (used s)" by blast + hence "B'' \ fst (snd SK) \ + (\i C'. (Asset i, Token i (Auth_PriK i) B'' C' SK) \ s) \ + {A'' \ B'', SesKey SK} \ spied s" + (is "?V B'' \ (\i C'. ?W i B'' C') \ _") + by (rule parts_crypt_mult [OF A]) + hence "\D. ?V D \ D \ {A, A'}" + proof (rule disjE, (erule_tac conjE, ((erule_tac exE)+)?)+) + fix i C' + assume "?V B''" and "?W i B'' C'" + have "\A D. ?R A B'' \ ?S C' D \ + (Asset i, \Num 2, PubKey B''\) \ s \ (Asset i, \Num 4, PubKey D\) \ s \ + Crypt (SesK SK) (PubKey D) \ used s \ (Asset i, PubKey B'') \ s" + (is "\A D. _ \ _ \ ?X i B'' \ _") + by (rule asset_iv_state [OF A `?W i B'' C'`]) + hence "?X i B''" by blast + have "B'' \ A" + proof + assume "B'' = A" + hence "?X i A" + using `?X i B''` by simp + thus False + by (rule asset_ii_owner_ii [OF A _ `?T m A`]) + qed + moreover have "B'' \ A'" + proof + assume "B'' = A'" + hence "?X i A'" + using `?X i B''` by simp + thus False + by (rule asset_ii_owner_ii [OF A _ `?T n A'`]) + qed + ultimately show ?thesis + using `?V B''` by blast + next + assume "{A'' \ B'', SesKey SK} \ spied s" + hence "SesKey SK \ spied s" by simp + hence "\S D E. fst SK = Some S \ ?V D \ E \ snd (snd SK) \ + {PriKey S, PriKey D, PriKey E} \ spied s" + by (rule seskey_spied [OF A]) + then obtain D where "?V D" and "PriKey D \ spied s" (is "?X D") + by blast + moreover have "D \ A" + proof + assume "D = A" + hence "?X A" + using `?X D` by simp + moreover have "\ ?X A" + by (rule owner_ii_secret [OF A `?T m A`]) + ultimately show False by contradiction + qed + moreover have "D \ A'" + proof + assume "D = A'" + hence "?X A'" + using `?X D` by simp + moreover have "\ ?X A'" + by (rule owner_ii_secret [OF A `?T n A'`]) + ultimately show False by contradiction + qed + ultimately show ?thesis by blast + qed + then obtain D where "?V D" and E: "D \ {A, A'}" by blast + hence "{D, A, A'} \ {A, B}" + using `?R A B` and `?R A' B'` by blast + hence "card {D, A, A'} \ card {A, B}" + by (rule_tac card_mono, simp) + also have "\ \ Suc (Suc 0)" + by (rule card_insert_le_m1, simp_all) + finally have "card {D, A, A'} \ Suc (Suc 0)" . + moreover have "card {D, A, A'} = Suc (card {A, A'})" + by (rule card_insert_disjoint [OF _ E], simp) + moreover assume "m \ n" + hence "card {A, A'} = Suc (card {A'})" + proof (rule_tac card_insert_disjoint, simp_all, erule_tac contrapos_nn) + assume "A = A'" + hence "?T n A" + using `?T n A'` by simp + thus "m = n" + by (rule owner_ii_unique [OF A `?T m A`]) + qed + ultimately show False by simp +qed + + +theorem owner_seskey_secret: + assumes + A: "s\<^sub>0 \ s" and + B: "n \ bad_shakey \ bad_prikey" and + C: "(Owner n, Crypt (SesK SK) (Pwd n)) \ s" + shows "SesKey SK \ spied s" +proof - + have "(Owner n, SesKey SK) \ s \ + (\A B C. Token n A B C SK \ used s \ B \ fst (snd SK))" + (is "?P \ (\A B C. ?Q A B C \ ?R B)") + by (rule owner_v_state [OF A C]) + then obtain A B C where "?P" and "?Q A B C" and "?R B" by blast + have "n \ bad_shakey \ n \ bad_shakey" by simp + moreover { + assume "n \ bad_shakey" + hence D: "n \ bad_prikey" + using B by simp + hence "Auth_PriKey n \ spied s" + by (rule auth_prikey_secret [OF A]) + moreover have "Sign n A \ parts (used s)" + using `?Q A B C` by blast + hence "A = Auth_PriK n" + by (rule parts_sign [OF A]) + hence "?Q (Auth_PriK n) B C" + using `?Q A B C` by simp + hence "Auth_PriK n \ B \ parts (used s)" by blast + hence "(\m. Auth_PriK n = Auth_PriK m \ + (Asset m, \Num 2, PubKey B\) \ s) \ + {PriKey (Auth_PriK n), PriKey B} \ spied s" + (is "(\m. ?S m \ ?T m) \ _") + by (rule parts_mult [OF A]) + ultimately obtain m where "?S m" and "?T m" by auto + hence "m \ bad_prikey" + using D by simp + hence ?thesis + by (rule owner_seskey_prikey [OF A _ `?P` `?T m` `?R B`]) + } + moreover { + assume "n \ bad_shakey" + hence ?thesis + by (rule owner_seskey_shakey [OF A _ `?P`]) + } + ultimately show ?thesis .. +qed + + +theorem owner_num_genuine: + assumes + A: "s\<^sub>0 \ s" and + B: "n \ bad_shakey \ bad_prikey" and + C: "(Owner n, Crypt (SesK SK) (Pwd n)) \ s" and + D: "Crypt (SesK SK) (Num 0) \ used s" + shows "(Asset n, Crypt (SesK SK) (Num 0)) \ s" +proof - + have "Crypt (SesK SK) (Num 0) \ parts (used s)" + using D .. + hence "(\m. (Asset m, Crypt (SesK SK) (Num 0)) \ s) \ + SesKey SK \ spied s" + by (rule parts_crypt_num [OF A]) + moreover have E: "SesKey SK \ spied s" + by (rule owner_seskey_secret [OF A B C]) + ultimately obtain m where "(Asset m, Crypt (SesK SK) (Num 0)) \ s" + by blast + moreover from this have "(Asset m, SesKey SK) \ s \ + Crypt (SesK SK) (Pwd m) \ used s" + by (rule asset_v_state [OF A]) + hence "Crypt (SesK SK) (Pwd m) \ parts (used s)" by blast + hence "(\SK'. SesK SK = SesK SK' \ + (Owner m, Crypt (SesK SK') (Pwd m)) \ s) \ + {Pwd m, Key (SesK SK)} \ spied s" + by (rule parts_crypt_pwd [OF A]) + hence "(Owner m, Crypt (SesK SK) (Pwd m)) \ s" + using E by simp + hence "m = n" + by (rule owner_seskey_unique [OF A _ C]) + ultimately show ?thesis by simp +qed + + +theorem owner_token_genuine: + assumes + A: "s\<^sub>0 \ s" and + B: "n \ bad_shakey \ bad_prikey" and + C: "(Owner n, \Num 3, PubKey C\) \ s" and + D: "(Owner n, Crypt (SesK SK) (Pwd n)) \ s" and + E: "Token n A B C SK \ used s" + shows "A = Auth_PriK n \ B \ fst (snd SK) \ C \ snd (snd SK) \ + (Asset n, \Num 2, PubKey B\) \ s \ (Asset n, Token n A B C SK) \ s" + (is "?P n A \ ?Q B \ ?R C \ ?S n B \ _") +proof - + have "Crypt (SesK SK) (Sign n A) \ parts (used s)" + using E by blast + hence "(Asset n, SesKey SK) \ s \ SesKey SK \ spied s" + by (rule parts_crypt_sign [OF A]) + moreover have "SesKey SK \ spied s" + by (rule owner_seskey_secret [OF A B D]) + ultimately have "(Asset n, SesKey SK) \ s" by simp + hence "\A B C D. fst (snd SK) = {A, B} \ snd (snd SK) = {C, D} \ + ?S n B \ (Asset n, \Num 4, PubKey D\) \ s \ + (Asset n, Token n (Auth_PriK n) B C SK) \ s" + (is "\A B C D. ?T A B \ ?U C D \ _ \ ?V n D \ ?W n B C") + by (rule asset_seskey_other [OF A]) + then obtain A' B' C' D where + "?T A' B'" and "?U C' D" and "?S n B'" and "?V n D" and "?W n B' C'" + by blast + have "Sign n A \ parts (used s)" + using E by blast + hence "?P n A" + by (rule parts_sign [OF A]) + have "Crypt (SesK SK) (A \ B) \ parts (used s)" + using E by blast + hence "?Q B \ (\m C''. ?W m B C'') \ {A \ B, SesKey SK} \ spied s" + by (rule parts_crypt_mult [OF A]) + moreover have F: "SesKey SK \ spied s" + by (rule owner_seskey_secret [OF A B D]) + ultimately obtain m C'' where "?Q B" and "?W m B C''" by blast + have "\A D. ?T A B \ ?U C'' D \ ?S m B \ ?V m D \ + Crypt (SesK SK) (PubKey D) \ used s \ (Asset m, PubKey B) \ s" + by (rule asset_iv_state [OF A `?W m B C''`]) + hence "?S m B" by blast + have "(Owner n, SesKey SK) \ s \ + (\A B C. Token n A B C SK \ used s \ B \ fst (snd SK))" + by (rule owner_v_state [OF A D]) + hence "(Owner n, SesKey SK) \ s" by blast + hence "\A B C D. ?T A B \ ?U C D \ + (Owner n, \Num 1, PubKey A\) \ s \ + (Owner n, \Num 3, PubKey C\) \ s \ + (Owner n, Crypt (SesK SK) (PubKey D)) \ s" + (is "\A B C D. _ \ _ \ ?X A \ _") + by (rule owner_seskey_other [OF A]) + then obtain A'' where "?Q A''" and "?X A''" by blast + have G: "B' = B" + proof (rule ccontr) + have "{A'', B', B} \ {A', B'}" + using `?T A' B'` and `?Q B` and `?Q A''` by simp + hence "card {A'', B', B} \ card {A', B'}" + by (rule_tac card_mono, simp) + also have "\ \ Suc (Suc 0)" + by (rule card_insert_le_m1, simp_all) + finally have "card {A'', B', B} \ Suc (Suc 0)" . + moreover have "A'' \ {B', B}" + proof (simp, rule conjI, rule_tac [!] notI) + assume "A'' = B'" + hence "?S n A''" + using `?S n B'` by simp + thus False + by (rule asset_ii_owner_ii [OF A _ `?X A''`]) + next + assume "A'' = B" + hence "?S m A''" + using `?S m B` by simp + thus False + by (rule asset_ii_owner_ii [OF A _ `?X A''`]) + qed + hence "card {A'', B', B} = Suc (card {B', B})" + by (rule_tac card_insert_disjoint, simp) + moreover assume "B' \ B" + hence "card {B', B} = Suc (card {B})" + by (rule_tac card_insert_disjoint, simp_all) + ultimately show False by simp + qed + hence "?S n B" + using `?S n B'` by simp + have "Crypt (SesK SK) (PubKey C) \ parts (used s)" + using E by blast + hence "?R C \ ((\n. (Owner n, SesKey SK) \ s) \ (\n B. ?W n B C)) \ + SesKey SK \ spied s" + by (rule parts_crypt_pubkey [OF A]) + hence "?R C" + using F by simp + hence "C \ {C', D}" + using `?U C' D` by simp + moreover have "C \ D" + proof + assume "C = D" + hence "?V n C" + using `?V n D` by simp + thus False + by (rule asset_iii_owner_iii [OF A _ C]) + qed + ultimately have "C = C'" by simp + hence "(Asset n, Token n A B C SK) \ s" + using G and `?P n A` and `?W n B' C'` by simp + thus ?thesis + using `?P n A` and `?Q B` and `?R C` and `?S n B` by simp +qed + + +theorem pwd_secret: + assumes + A: "s\<^sub>0 \ s" and + B: "n \ bad_pwd \ bad_shakey \ bad_prikey" + shows "Pwd n \ spied s" +proof (rule rtrancl_induct [OF A], insert B, simp add: image_def) + fix s s' + assume + C: "s\<^sub>0 \ s" and + D: "s \ s'" and + E: "Pwd n \ spied s" + show "Pwd n \ spied s'" + proof (insert D E, auto simp add: rel_def) + fix K + assume "(Spy, Crypt K (Pwd n)) \ s" + hence "Crypt K (Pwd n) \ parts (used s)" by blast + hence "(\SK. K = SesK SK \ (Owner n, Crypt (SesK SK) (Pwd n)) \ s) \ + {Pwd n, Key K} \ spied s" + (is "(\SK. ?P SK \ ?Q SK) \ _") + by (rule parts_crypt_pwd [OF C]) + then obtain SK where "?P SK" and "?Q SK" + using E by blast + have "n \ bad_shakey \ bad_prikey" + using B by simp + hence "SesKey SK \ spied s" + by (rule owner_seskey_secret [OF C _ `?Q SK`]) + moreover assume "(Spy, Key (InvK K)) \ s" + ultimately show False + using `?P SK` by simp + next + fix Y + assume "(Spy, \Pwd n, Y\) \ s" + hence "\Pwd n, Y\ \ parts (used s)" by blast + hence "{Pwd n, Y} \ spied s" + by (rule parts_mpair_pwd [OF C, where n = n], simp) + with E show False by simp + next + fix X + assume "(Spy, \X, Pwd n\) \ s" + hence "\X, Pwd n\ \ parts (used s)" by blast + hence "{X, Pwd n} \ spied s" + by (rule parts_mpair_pwd [OF C, where n = n], simp) + with E show False by simp + qed +qed + + +theorem asset_seskey_unique: + assumes + A: "s\<^sub>0 \ s" and + B: "(Asset m, Token m (Auth_PriK m) B' C' SK) \ s" and + C: "(Asset n, Token n (Auth_PriK n) B C SK) \ s" + (is "?P n B C SK s") + shows "m = n \ B' = B \ C' = C" +proof (subst (2) cases_simp [of "B' = B", symmetric], simp, rule conjI, rule impI, + insert B C, simp only:, drule asset_iv_unique [OF A], simp, simp, rule ccontr) + assume "B' \ B" + moreover have "\A D. fst (snd SK) = {A, B'} \ snd (snd SK) = {C', D} \ + (Asset m, \Num 2, PubKey B'\) \ s \ (Asset m, \Num 4, PubKey D\) \ s \ + Crypt (SesK SK) (PubKey D) \ used s \ (Asset m, PubKey B') \ s" + (is "?Q m B' C'") + by (rule asset_iv_state [OF A B]) + then obtain A where "fst (snd SK) = {A, B'}" and + "(Asset m, \Num 2, PubKey B'\) \ s" + by blast + moreover have "?Q n B C" + by (rule asset_iv_state [OF A C]) + hence "B \ fst (snd SK)" and "(Asset n, \Num 2, PubKey B\) \ s" + by auto + ultimately have D: "\A \ fst (snd SK). + \i C. (Asset i, \Num 2, PubKey A\) \ s \ ?P i A C SK s" + using B and C by auto + have "Crypt (SesK SK) (PubKey C) \ parts (used s)" + using C by blast + thus False + proof (rule parts_pubkey_false [OF A], rule_tac allI, rule_tac [!] notI) + fix i + assume "(Owner i, SesKey SK) \ s" + hence "\A B C D. fst (snd SK) = {A, B} \ snd (snd SK) = {C, D} \ + (Owner i, \Num 1, PubKey A\) \ s \ + (Owner i, \Num 3, PubKey C\) \ s \ + (Owner i, Crypt (SesK SK) (PubKey D)) \ s" + by (rule owner_seskey_other [OF A]) + then obtain A where "A \ fst (snd SK)" and + E: "(Owner i, \Num 1, PubKey A\) \ s" + by blast + then obtain j where "(Asset j, \Num 2, PubKey A\) \ s" + using D by blast + thus False + by (rule asset_ii_owner_ii [OF A _ E]) + next + assume "SesKey SK \ spied s" + hence "\S A C. fst SK = Some S \ A \ fst (snd SK) \ C \ snd (snd SK) \ + {PriKey S, PriKey A, PriKey C} \ spied s" + (is "?R s") + by (rule seskey_spied [OF A]) + moreover have "\ (\A \ fst (snd SK). PriKey A \ spied s)" + (is "\ ?S s") + proof + assume "?S s" + moreover have "\ ?S s\<^sub>0" + by (subst bex_simps, rule ballI, drule bspec [OF D], (erule exE)+, + erule conjE, rule asset_ii_init [OF A]) + ultimately have "\u v. s\<^sub>0 \ u \ u \ v \ v \ s \ \ ?S u \ ?S v" + by (rule rtrancl_start [OF A]) + then obtain u v A where E: "s\<^sub>0 \ u" and F: "u \ v" and G: "v \ s" and + H: "\ ?S u" and I: "A \ fst (snd SK)" and J: "PriKey A \ spied u" and + K: "PriKey A \ spied v" + by blast + then obtain i where "(Asset i, \Num 2, PubKey A\) \ s" + using D by blast + hence "(Asset i, \Num 2, PubKey A\) \ v" + proof (rule_tac ccontr, drule_tac rtrancl_start [OF G], simp, + (erule_tac exE)+, (erule_tac conjE)+) + fix w x + assume "w \ x" and "(Asset i, \Num 2, PubKey A\) \ w" and + "(Asset i, \Num 2, PubKey A\) \ x" + hence "PriKey A \ spied w" + by (auto simp add: rel_def) + moreover assume "v \ w" + hence "PriKey A \ spied w" + by (rule_tac rev_subsetD [OF K], rule spied_subset) + ultimately show False by contradiction + qed + hence "(Asset i, \Num 2, PubKey A\) \ u" + using F and K by (auto simp add: rel_def) + hence "Auth_PriKey i \ spied u \ (\C SK. ?P i A C SK u)" + by (rule asset_ii_spied_start [OF E F K J]) + then obtain C' SK' where L: "?P i A C' SK' u" by blast + moreover have M: "u \ s" + using F and G by simp + ultimately have "?P i A C' SK' s" + by (erule_tac rev_subsetD, rule_tac state_subset) + moreover obtain j C where "?P j A C SK s" + using D and I by blast + ultimately have "i = j \ C' = C \ SK' = SK" + by (rule asset_iv_unique [OF A]) + hence "Crypt (SesK SK) (PubKey C) \ parts (used u)" + using L by blast + thus False + proof (rule parts_pubkey_false [OF E], rule_tac allI, rule_tac [!] notI) + fix i + assume "(Owner i, SesKey SK) \ u" + hence "\A B C D. fst (snd SK) = {A, B} \ snd (snd SK) = {C, D} \ + (Owner i, \Num 1, PubKey A\) \ u \ + (Owner i, \Num 3, PubKey C\) \ u \ + (Owner i, Crypt (SesK SK) (PubKey D)) \ u" + by (rule owner_seskey_other [OF E]) + then obtain A where "A \ fst (snd SK)" and + N: "(Owner i, \Num 1, PubKey A\) \ u" + by blast + then obtain j where "(Asset j, \Num 2, PubKey A\) \ s" + using D by blast + moreover have "(Owner i, \Num 1, PubKey A\) \ s" + by (rule rev_subsetD [OF N], rule state_subset [OF M]) + ultimately show False + by (rule asset_ii_owner_ii [OF A]) + next + assume "SesKey SK \ spied u" + hence "?R u" + by (rule seskey_spied [OF E]) + thus False + using H by blast + qed + qed + ultimately show False by blast + qed +qed + + +theorem asset_seskey_secret: + assumes + A: "s\<^sub>0 \ s" and + B: "n \ bad_shakey \ (bad_pwd \ bad_prikey)" and + C: "(Asset n, Crypt (SesK SK) (Num 0)) \ s" + shows "SesKey SK \ spied s" +proof - + have D: "(Asset n, SesKey SK) \ s \ Crypt (SesK SK) (Pwd n) \ used s" + by (rule asset_v_state [OF A C]) + have "n \ bad_shakey \ n \ bad_shakey" by simp + moreover { + assume "n \ bad_shakey" + hence "Pwd n \ spied s" + using B by (rule_tac pwd_secret [OF A], simp) + moreover have "Crypt (SesK SK) (Pwd n) \ parts (used s)" + using D by blast + hence "(\SK'. SesK SK = SesK SK' \ + (Owner n, Crypt (SesK SK') (Pwd n)) \ s) \ + {Pwd n, Key (SesK SK)} \ spied s" + by (rule parts_crypt_pwd [OF A]) + ultimately have "(Owner n, Crypt (SesK SK) (Pwd n)) \ s" by simp + hence ?thesis + using B by (rule_tac owner_seskey_secret [OF A], simp_all) + } + moreover { + assume "n \ bad_shakey" + hence ?thesis + using D by (rule_tac asset_seskey_shakey [OF A], simp_all) + } + ultimately show ?thesis .. +qed + + +theorem asset_pwd_genuine: + assumes + A: "s\<^sub>0 \ s" and + B: "n \ bad_shakey \ (bad_pwd \ bad_prikey)" and + C: "(Asset n, Crypt (SesK SK) (Num 0)) \ s" + shows "(Owner n, Crypt (SesK SK) (Pwd n)) \ s" +proof - + have "(Asset n, SesKey SK) \ s \ Crypt (SesK SK) (Pwd n) \ used s" + by (rule asset_v_state [OF A C]) + hence "Crypt (SesK SK) (Pwd n) \ parts (used s)" by blast + hence "(\SK'. SesK SK = SesK SK' \ + (Owner n, Crypt (SesK SK') (Pwd n)) \ s) \ + {Pwd n, Key (SesK SK)} \ spied s" + by (rule parts_crypt_pwd [OF A]) + moreover have "SesKey SK \ spied s" + by (rule asset_seskey_secret [OF A B C]) + ultimately show ?thesis by simp +qed + + +theorem asset_token_genuine: + assumes + A: "s\<^sub>0 \ s" and + B: "n \ bad_shakey \ (bad_pwd \ bad_prikey)" and + C: "(Asset n, \Num 4, PubKey D\) \ s" and + D: "(Asset n, Crypt (SesK SK) (Num 0)) \ s" and + E: "D \ snd (snd SK)" + shows "(Owner n, Crypt (SesK SK) (PubKey D)) \ s" +proof - + have "(Owner n, Crypt (SesK SK) (Pwd n)) \ s" + by (rule asset_pwd_genuine [OF A B D]) + hence "(Owner n, SesKey SK) \ s \ + (\A B C. Token n A B C SK \ used s \ B \ fst (snd SK))" + by (rule owner_v_state [OF A]) + hence "(Owner n, SesKey SK) \ s" .. + hence "\A B C D. fst (snd SK) = {A, B} \ snd (snd SK) = {C, D} \ + (Owner n, \Num 1, PubKey A\) \ s \ + (Owner n, \Num 3, PubKey C\) \ s \ + (Owner n, Crypt (SesK SK) (PubKey D)) \ s" + (is "\A B C D. _ \ ?P C D \ _ \ ?Q C \ ?R D") + by (rule owner_seskey_other [OF A]) + then obtain C D' where "?P C D'" and "?Q C" and "?R D'" by blast + have "D \ C" + proof + assume "D = C" + hence "?Q D" + using `?Q C` by simp + thus False + by (rule asset_iii_owner_iii [OF A C]) + qed + hence "D = D'" + using E and `?P C D'` by simp + thus ?thesis + using `?R D'` by simp +qed + + +end diff --git a/thys/Relational_Method/Definitions.thy b/thys/Relational_Method/Definitions.thy new file mode 100644 --- /dev/null +++ b/thys/Relational_Method/Definitions.thy @@ -0,0 +1,869 @@ +(* Title: The Relational Method with Message Anonymity for the Verification of Cryptographic Protocols + Author: Pasquale Noce + Software Engineer at HID Global, Italy + pasquale dot noce dot lavoro at gmail dot com + pasquale dot noce at hidglobal dot com +*) + +section "The relational method and message anonymity" + +theory Definitions + imports Main +begin + +text \ +\null + +\emph{This paper is dedicated to my mother, my favourite chess opponent -- in addition to being many +other wonderful things!} +\ + + +subsection "Introduction" + +text \ +As Bertrand Russell says in the last pages of \emph{A History of Western Philosophy}, a distinctive +feature of science is that "we can make successive approximations to the truth, in which each new +stage results from an improvement, not a rejection, of what has gone before". When dealing with a +formal verification method for information processing systems, such as Paulson's inductive method +for the verification of cryptographic protocols (cf. @{cite "Paulson98"}, @{cite "Paulson20"}), a +more modest goal for this iterative improvement process, yet of significant practical importance, is +to streamline the definitions and proofs needed to model such a system and verify its properties. + +With this aim, specially when it comes to verifying protocols using public key cryptography, this +paper proposes an enhancement of the inductive method, named \emph{relational method} for reasons +clarified in what follows, and puts it into practice by verifying a sample protocol. This new method +is the result of some changes to the way how events, states, spy's capabilities, and the protocol +itself are formalized in the inductive method. Here below is a description of these changes, along +with a rationale for them. + + \<^descr>[Events.] In the inductive method, the fundamental building blocks of cryptographic protocols are +events of the form @{text "Says A B X"}, where @{text X} is a message being exchanged, @{text A} is +the agent that sends it, and @{text B} is the agent to which it is addressed. +\\However, any exchanged message can be intercepted by the spy and forwarded to any other agent, so +its intended recipient is not relevant for the protocol \emph{security} correctness -- though of +course being relevant for the protocol \emph{functional} correctness. Moreover, a legitimate agent +may also generate messages, e.g. ephemeral private keys, that she will never exchange with any other +agent. To model such an event, a datatype constructor other than @{text Says} should be used. How to +make things simpler? +\\The solution adopted in the relational method is to model events just as ordered pairs of the form +@{text "(A, X)"}, where @{text A} is an agent and @{text X} is a message. If event @{text "(A, X)"} +stands for @{text A}'s sending of @{text X} to another agent, where @{text A} is a legitimate agent, +then this event will be accompanied by event @{text "(Spy, X)"}, representing the spy's interception +of @{text X}. If event @{text "(A, X)"} rather stands for @{text A}'s generation of private message +@{text X}, e.g. an ephemeral private key, for her own exclusive use -- and if the spy has not hacked +@{text A} so as to steal her private messages as well --, then no companion event @{text "(Spy, X)"} +will occur instead. + + \<^descr>[States.] In the inductive method, the possible states of a cryptographic protocol are modeled as +event \emph{traces}, i.e. lists, and the protocol itself is formalized as a set of such traces. +Consequently, the protocol rules and security properties are expressed as formulae satisfied by any +event trace @{text evs} belonging to this set. +\\However, these formulae are such that their truth values depend only on the events contained in +@{text evs}, rather than on the actual order in which they occur -- in fact, robust protocol rules +and security properties cannot depend on the exact sequence of message exchanges in a scenario where +the spy can freely intercept and forward messages, or even generate and send her own ones. Thus, one +library function, @{const set}, and two custom recursive functions, @{text used} and @{text knows}, +are needed to convert event traces into event sets and message sets, respectively. +\\In the relational method, protocol states are simply modeled as event sets, so that the occurrence +of event @{text "(A, X)"} in state @{text s} can be expressed as the transition to the augmented +state @{term "insert (A, X) s"}. Hence, states consist of relations between agents and messages. As +a result, function @{const set} need not be used any longer, whereas functions @{text used} and +@{text spied} -- the latter one being a replacement for @{text "knows Spy"} --, which take a state +@{text s} as input, are mere abbreviations for @{term "Range s"} and @{term "s `` {Spy}"}. + + \<^descr>[Spy's capabilities.] In the inductive method, the spy's attack capabilities are formalized via +two inductively defined functions, @{text analz} and @{text synth}, used to construct the sets of +all the messages that the spy can learn -- @{text "analz (knows Spy evs)"} -- and send to legitimate +agents -- @{text "synth (analz (knows Spy evs))"} -- downstream of event trace @{text evs}. +\\Indeed, the introduction of these functions goes in the direction of decoupling the formalization +of the spy's capabilities from that of the protocol itself, consistently with the fact that what the +spy can do is independent of how the protocol works -- which only matters when it comes to verifying +protocol security. +\\In principle, this promises to provide a relevant benefit: these functions need to be defined, and +their properties to be proven, just once, whereupon such definitions and properties can be reused in +the formalization and verification of whatever protocol. +\\In practice, since both functions are of type @{text "msg set \ msg set"}, where @{text msg} is +the datatype defining all possible message formats, this benefit only applies as long as message +formats remain unchanged. However, when it comes to verifying a protocol making use of public key +cryptography, some new message format, and consequently some new related spy's capability as well, +are likely to be required. An example of this will be provided right away by the protocol considered +in this paper. +\\In the relational method, the representation of events as agent-message pairs offers a simpler way +to model the spy's capabilities, namely as supplementary protocol rules, analogous to the inductive +method's @{text Fake} rule, augmenting a state by one or more events of the form @{text "(Spy, X)"}. +In addition to eliminating the need for functions @{text analz} and @{text synth} -- which, in light +of the above considerations, does not significantly harm reusability --, this choice also abolishes +any distinction between what the spy can learn and what she can send. In fact, a state containing +event @{text "(Spy, X)"} is interpreted as one where the spy both knows message @{text X} and may +have sent it to whatever legitimate agent. Actually, this formalizes the facts that a real-world +attacker is free to send any message she has learned to any other party, and conversely to use any +message she has generated to further augment her knowledge. +\\In the inductive method, the former fact is modeled by property @{term "H \ synth H"} of function +@{text synth}, but the latter one has no formal counterpart, as in general @{term "H \ synth H"}. +This limitation on the spy's capabilities is not significant as long as the protocol makes use of +static keys only, but it is if session keys or ephemeral key pairs are generated -- as happens in +key establishment protocols, even in those using symmetric cryptography alone. In any such case, a +realistic spy must also be able to learn from anything she herself has generated, such as a nonce or +an ephemeral private key -- a result achieved without effort in the relational method. +\\An additional, nontrivial problem for the inductive method is that many protocols, including key +establishment ones, require the spy to be able to generate \emph{fresh} ephemeral messages only, as +otherwise the spy could succeed in breaking the protocol by just guessing the ephemeral messages +already generated at random by some legitimate agent -- a quite unrealistic attack pattern, provided +that such messages vary in a sufficiently wide range. At first glance, this need could be addressed +by extending the inductive definition of function @{text synth} with introduction rules of the form +@{term "Nonce n \ H \ Nonce n \ synth H"} or @{term "PriKey A \ H \ PriKey A \ synth H"}. +However, private ephemeral messages are not in general included in @{text "analz (knows Spy evs)"}, +since nonces may be encrypted with uncompromised keys when exchanged and private keys are usually +not exchanged at all, so this approach would not work. The only satisfactory alternative would be to +change the signature of function @{text synth}, e.g. by adding a second input message set @{text H'} +standing for @{text "used evs"}, or else by replacing @{text H} with event trace @{text evs} itself, +but this would render the function definition much more convoluted -- a problem easily bypassed in +the relational method. + + \<^descr>[Protocol.] In the inductive method, a cryptographic protocol consists of an inductively defined +set of event traces. This enables to prove the protocol security properties by induction using the +induction rule automatically generated as a result of such an inductive definition, i.e. by means of +\emph{rule induction}. Actually, this feature is exactly what gives the method its very name. Hence, +a consistent way to name a protocol verification method using some other form of induction would be +to replace adjective "inductive" with another one referring to that form of induction. +\\The relational method owes its name to this consideration. In this method, the introduction rules +defining \emph{protocol rules}, i.e. the possible transitions between protocol states, are replaced +with \emph{relations} between states, henceforth named \emph{protocol relations}. That is, for any +two states @{text s} and @{text s'}, there exists a transition leading from @{text s} to @{text s'} +just in case the ordered pair @{term "(s, s')"} is contained in at least one protocol relation -- +a state of affairs denoted using infix notation @{text "s \ s'"}. Then, the inductively defined set +itself is replaced with the \emph{reflexive transitive closure} of the union of protocol relations. +Namely, any state @{text s} may be reached from \emph{initial state} @{text s\<^sub>0}, viz. is a possible +protocol state, just in case pair @{term "(s\<^sub>0, s)"} lies within this reflexive transitive closure -- +a state of affairs denoted using infix notation @{text "s\<^sub>0 \ s"}. As a result, rule induction is +replaced with induction over reflexive transitive closures via rule @{thm [source] rtrancl_induct}, +which is the circumstance that originates the method name. +\\These changes provide the following important benefits. + + \<^item> Inserting and modifying the formal definition of a protocol is much more comfortable. In fact, +any change even to a single introduction rule within a monolithic inductive set definition entails a +re-evaluation of the whole definition, whereas each protocol relation will have its own stand-alone +definition, which also makes it easier to find errors. This advantage may go almost unnoticed for a +very simple protocol providing for just a few protocol rules, but gets evident in case of a complex +protocol. An example of this will be provided by the protocol considered in this paper: when looking +at the self-contained abbreviations used to define protocol relations, the reader will easily grasp +how much more convoluted an equivalent inductive set definition would have been. + + \<^item> In addition to induction via rule @{thm [source] rtrancl_induct}, a further powerful reasoning +pattern turns out to be available. It is based on the following general rule applying to reflexive +transitive closures (indeed, a rule so general and useful that it could rightfully become part of +the standard library), later on proven and assigned the name @{text rtrancl_start}: +@{prop [display] "\(x, y) \ r\<^sup>*; P y; \ P x\ \ +\u v. (x, u) \ r\<^sup>* \ (u, v) \ r \ (v, y) \ r\<^sup>* \ \ P u \ P v"} +In natural language, this rule states that for any chain of elements linked by a relation, if some +predicate is false for the first element of the chain and true for the last one, there must exist a +link in the chain where the predicate becomes true. +\\This rule can be used to prove propositions of the form @{text "\s \ s'; P s'[; Q]\ \ R s'"} for +any state @{text s} and predicate @{text P} such that @{term "\ P s"}, with an optional additional +assumption @{text Q}, without resorting to induction. Notably, \emph{regularity lemmas} have exactly +this form, where @{term "s = s\<^sub>0"}, @{term "P = (\s. X \ parts (used s))"} for some term @{text X} of +type @{text msg}, and @{text Q}, if present, puts some constraint on @{text X} or its components. +\\Such a proof consists of two steps. First, lemma @{text "\s \ s'; P s'; \ P s[; Q]\ \ R s'"} is +proven by simplification, using the definitions of protocol relations. Then, the target proposition +is proven by applying rule @{text rtrancl_start} as a destruction rule (cf. @{cite "Paulson20"}) and +proving @{term "P s'"} by assumption, @{term "\ P s"} by simplification, and the residual subgoal +by means of the previous lemma. + +In addition to the relational method, this paper is aimed at introducing still another enhancement: +besides message confidentiality and authenticity, it takes into consideration a further important +security property, \emph{message anonymity}. Being legitimate agents identified via natural numbers, +the fact that in state @{text s} the spy ignores that message @{text X\<^sub>n} is associated with agent +@{text n}, viz. @{text X\<^sub>n}'s property of being \emph{anonymous} in state @{text s}, can be expressed +as @{text "\n, X\<^sub>n\ \ spied s"}, where notation @{text "\n, X\<^sub>n\"} refers to a new constructor added to +datatype @{text msg} precisely for this purpose. + +A basic constraint upon any protocol relation augmenting the spy's knowledge with @{text "\n, X\"} +is that the spy must know message @{text X} in the current state, as it is impossible to identify +the agent associated with an unknown message. There is also an additional, more subtle constraint. +Any such protocol relation either augments a state in which the spy knows @{text "\n, C X\<^sub>1 \ X\<^sub>m\"}, +i.e. containing event @{text "(Spy, \n, C X\<^sub>1 \ X\<^sub>m\)"}, with event @{text "(Spy, \n, X\<^sub>i\)"}, where +$1 \leq i \leq m$ and @{text C} is some constructor of datatype @{text msg}, or conversely augments +a state containing event @{text "(Spy, \n, X\<^sub>i\)"} with @{text "(Spy, \n, C X\<^sub>1 \ X\<^sub>m\)"}. However, the +latter spy's inference is justified only if the compound message @{text "C X\<^sub>1 \ X\<^sub>m"} is part of a +message generated or accepted by some legitimate agent according to the protocol rules. Otherwise, +that is, if @{text "C X\<^sub>1 \ X\<^sub>m"} were just a message generated at random by the spy, her inference +would be as sound as those of most politicians and all advertisements: even if the conclusion were +true, it would be so by pure chance. + +This problem can be solved as follows. + + \<^item> A further constructor @{text Log}, taking a message as input, is added to datatype @{text msg}, +and every protocol relation modeling the generation or acceptance of a message @{text X} by some +legitimate agent must augment the current state with event @{term "(Spy, Log X)"}. +\\In this way, the set of all the messages that have been generated or accepted by some legitimate +agent in state @{text s} matches @{term "Log -` spied s"}. + + \<^item> A function @{text crypts} is defined inductively. It takes a message set @{text H} as input, and +returns the least message set @{text H'} such that @{term "H \ H'"} and for any (even empty) list +of keys @{text KS}, if the encryption of @{text "\X, Y\"}, @{text "\Y, X\"}, or @{text "Hash X"} +with @{text KS} is contained in @{text H'}, then the encryption of @{text X} with @{text KS} is +contained in @{text H'} as well. +\\In this way, the set of all the messages that are part of messages exchanged by legitimate agents, +viz. that may be mapped to agents, in state @{text s} matches @{term "crypts (Log -` spied s)"}. + + \<^item> Another function @{text key_sets} is defined, too. It takes two inputs, a message @{text X} and +a message set @{text H}, and returns the set of the sets of @{text KS}' inverse keys for any list of +keys @{text KS} such that the encryption of @{text X} with @{text KS} is included in @{text H}. +\\In this way, the fact that in state @{text s} the spy can map a compound message @{text X} to some +agent, provided that she knows all the keys in set @{text U}, can be expressed through conditions +@{term "U \ key_sets X (crypts (Log -` spied s))"} and @{term "U \ spied s"}. +\\The choice to define @{text key_sets} so as to collect the inverse keys of encryption keys, viz. +decryption ones, depends on the fact that the sample protocol verified in this paper uses symmetric +keys alone -- which match their own inverse keys -- for encryption, whereas asymmetric key pairs are +used in cryptograms only for signature generation -- so that the inverse keys are public ones. In +case of a protocol (also) using public keys for encryption, encryption keys themselves should (also) +be collected, since the corresponding decryption keys, i.e. private keys, would be unknown to the +spy by default. This would formalize the fact that encrypted messages can be mapped to agents not +only by decrypting them, but also by recomputing the cryptograms (provided that the plaintexts are +known) and checking whether they match the exchanged ones. +\ + + +subsection "A sample protocol" + +text \ +As previously mentioned, this paper tries the relational method, including message anonymity, by +applying it to the verification of a sample authentication protocol in which Password Authenticated +Connection Establishment (PACE) with Chip Authentication Mapping (cf. @{cite "ICAO15"}) is first +used by an \emph{owner} to establish a secure channel with her own \emph{asset} and authenticate it, +and then the owner sends a password (other than the PACE one) to the asset over that channel so as +to authenticate herself. This enables to achieve a reliable mutual authentication even if the PACE +key is shared by multiple owners or is weak, as happens in electronic passports. Although the PACE +mechanism is specified for use in electronic documents, nothing prevents it in principle from being +used in other kinds of smart cards or even outside of the smart card world, which is the reason why +this paper uses the generic names \emph{asset} and \emph{owner} for the card and the cardholder, +respectively. + +In more detail, this protocol provides for the following steps. In this list, messages are specified +using the same syntax that will be adopted in the formal text (for further information about PACE +with Chip Authentication Mapping, cf. @{cite "ICAO15"}). + + \<^enum> \emph{Asset n} $\rightarrow$ \emph{Owner n}: +\\\hspace*{1em}@{text "Crypt (Auth_ShaKey n) (PriKey S)"} + + \<^enum> \emph{Owner n} $\rightarrow$ \emph{Asset n}: +\\\hspace*{1em}@{text "\Num 1, PubKey A\"} + + \<^enum> \emph{Asset n} $\rightarrow$ \emph{Owner n}: +\\\hspace*{1em}@{text "\Num 2, PubKey B\"} + + \<^enum> \emph{Owner n} $\rightarrow$ \emph{Asset n}: +\\\hspace*{1em}@{text "\Num 3, PubKey C\"} + + \<^enum> \emph{Asset n} $\rightarrow$ \emph{Owner n}: +\\\hspace*{1em}@{text "\Num 4, PubKey D\"} + + \<^enum> \emph{Owner n} $\rightarrow$ \emph{Asset n}: +\\\hspace*{1em}@{text "Crypt (SesK SK) (PubKey D)"} + + \<^enum> \emph{Asset n} $\rightarrow$ \emph{Owner n}: +\\\hspace*{1em}@{text "\Crypt (SesK SK) (PubKey C),"} +\\\hspace*{1.5em}@{text "Crypt (SesK SK) (Auth_PriK n \ B),"} +\\\hspace*{1.5em}@{text "Crypt (SesK SK) (Crypt SigK"} +\\\hspace*{2em}@{text "\Hash (Agent n), Hash (Auth_PubKey n)\)\"} + + \<^enum> \emph{Owner n} $\rightarrow$ \emph{Asset n}: +\\\hspace*{1em}@{text "Crypt (SesK SK) (Pwd n)"} + + \<^enum> \emph{Asset n} $\rightarrow$ \emph{Owner n}: +\\\hspace*{1em}@{text "Crypt (SesK SK) (Num 0)"} + +Legitimate agents consist of an infinite population of assets and owners. For each natural number +@{text n}, @{text "Owner n"} is an owner and @{text "Asset n"} is her own asset, and these agents +are assigned the following authentication data. + + \<^item> @{text "Key (Auth_ShaKey n)"}: static symmetric PACE key shared by both agents. + + \<^item> @{text "Auth_PriKey n"}, @{text "Auth_PubKey n"}: static private and public keys stored on +@{text "Asset n"} and used for @{text "Asset n"}'s authentication via Chip Authentication Mapping. + + \<^item> @{text "Pwd n"}: unique password (other than the PACE one) shared by both agents and used for +@{text "Owner n"}'s authentication. + +Function @{text Pwd} is defined as a constructor of datatype @{text msg} and then is injective, +which formalizes the assumption that each asset-owner pair has a distinct password, whereas no such +constraint is put on functions @{text Auth_ShaKey}, @{text Auth_PriKey}, and @{text Auth_PubKey}, +which allows multiple asset-owner pairs to be assigned the same keys. On the other hand, function +@{text Auth_PriKey} is constrained to be such that the complement of its range is infinite. As each +protocol run requires the generation of fresh ephemeral private keys, this constraint ensures that +an unbounded number of protocol runs can be carried out. All assumptions are formalized by applying +the definitional approach, viz. without introducing any axiom, and so is this constraint, expressed +by defining function @{text Auth_PriKey} using the indefinite description operator @{text SOME}. + +The protocol starts with @{text "Asset n"} sending an ephemeral private key encrypted with the PACE +key to @{text "Owner n"}. Actually, if @{text "Asset n"} is a smart card, the protocol should rather +start with @{text "Owner n"} sending a plain request for such encrypted nonce, but this preliminary +step is omitted here as it is irrelevant for protocol security. After that, @{text "Owner n"} and +@{text "Asset n"} generate two ephemeral key pairs each and send the respective public keys to the +other party. + +Then, both parties agree on the same session key by deriving it from the ephemeral keys generated +previously (actually, two distinct session keys would be derived, one for encryption and the other +one for MAC computation, but such a level of detail is unnecessary for protocol verification). The +session key is modeled as @{text "Key (SesK SK)"}, where @{text SesK} is an apposite constructor +added to datatype @{text key} and @{term "SK = (Some S, {A, B}, {C, D})"}. The adoption of type +@{typ "nat option"} for the first component enables to represent as @{term "(None, {A, B}, {C, D})"} +the wrong session key derived from @{text "Owner n"} if @{text "PriKey S"} was encrypted using a key +other than @{text "Key (Auth_ShaKey n)"} -- which reflects the fact that the protocol goes on even +without the two parties sharing the same session key. The use of type @{typ "nat set"} for the other +two components enables the spy to compute @{text "Key (SesK SK)"} if she knows \emph{either} private +key and the other public key referenced by each set, as long as she also knows @{text "PriKey S"} -- +which reflects the fact that given two key pairs, Diffie-Hellman key agreement generates the same +shared secret independently of which of the respective private keys is used for computation. + +This session key is used by both parties to compute their authentication tokens. Both encrypt the +other party's second ephemeral public key, but @{text "Asset n"} appends two further fields: the +Encrypted Chip Authentication Data, as provided for by Chip Authentication Mapping, and an encrypted +signature of the hash values of @{text "Agent n"} and @{text "Auth_PubKey n"}. Infix notation +@{text "Auth_PriK n \ B"} refers to a constructor of datatype @{text msg} standing for plain Chip +Authentication Data, and @{text Agent} is another such constructor standing for agent identification +data. @{text "Owner n"} is expected to validate this signature by also checking @{text "Agent n"}'s +hash value against reference identification data known by other means -- otherwise, the spy would +not be forced to know @{text "Auth_PriKey n"} to masquerade as @{text "Asset n"}, since she could do +that by just knowing @{text "Auth_PriKey m"} for some other @{text m}, even if @{term "Auth_PriKey m +\ Auth_PriKey n"}. If @{text "Asset n"} is an electronic passport, the owner, i.e. the inspection +system, could get cardholder's identification data by reading her personal data on the booklet, and +such a signature could be retrieved from the chip (actually through a distinct message, but this is +irrelevant for protocol security as long as the password is sent after the signature's validation) +by reading the Document Security Object -- provided that @{text "Auth_PubKey n"} is included within +Data Group 14. + +The protocol ends with @{text "Owner n"} sending her password, encrypted with the session key, to +@{text "Asset n"}, who validates it and replies with an encrypted acknowledgment. + +Here below are some concluding remarks about the way how this sample protocol is formalized. + + \<^item> A single signature private key, unknown to the spy, is assumed to be used for all legitimate +agents. Similarly, the spy might have hacked some legitimate agent so as to steal her ephemeral +private keys as soon as they are generated, but here all legitimate agents are assumed to be out of +the spy's reach in this respect. Of course, this is just the choice of one of multiple possible +scenarios, and nothing prevents these assumptions from being dropped. + + \<^item> In the real world, a legitimate agent would use any one of her ephemeral private keys just once, +after which the key would be destroyed. On the contrary, no such constraint is enforced here, since +it turns out to be unnecessary for protocol verification. There is a single exception, required for +the proof of a unicity lemma: after @{text "Asset n"} has used @{text "PriKey B"} to compute her +authentication token, she must discard @{text "PriKey B"} so as not to use this key any longer. The +way how this requirement is expressed emphasizes once more the flexibility of the modeling of events +in the relational method: @{text "Asset n"} may use @{text "PriKey B"} in this computation only if +event @{text "(Asset n, PubKey B)"} is not yet contained in the current state @{text s}, and then +@{text s} is augmented with that event. Namely, events can also be used to model garbage collection! + + \<^item> The sets of the legitimate agents whose authentication data have been identified in advance (or +equivalently, by means other than attacking the protocol, e.g. by social engineering) by the spy are +defined consistently with the constraint that known data alone can be mapped to agents, as well as +with the definition of initial state @{text s\<^sub>0}. For instance, the set @{text bad_id_prikey} of the +agents whose Chip Authentication private keys have been identified is defined as a subset of the set +@{text bad_prikey} of the agents whose Chip Authentication private keys have been stolen. Moreover, +all the signatures included in assets' authentication tokens are assumed to be already known to the +spy in state @{text s\<^sub>0}, so that @{text bad_id_prikey} includes also any agent whose identification +data or Chip Authentication public key have been identified in advance. + + \<^item> The protocol rules augmenting the spy's knowledge with some message of the form @{text "\n, X\"} +generally require the spy to already know some other message of the same form. There is just one +exception: the spy can infer @{text "\n, Agent n\"} from @{text "Agent n"}. This expresses the fact +that the detection of identification data within a message generated or accepted by some legitimate +agent is in itself sufficient to map any known component of that message to the identified agent, +regardless of whether any data were already mapped to that agent in advance. + + \<^item> As opposed to what happens for constructors @{text "(\)"} and @{text "MPair"}, there do not +exist two protocol rules enabling the spy to infer @{text "\n, Crypt K X\"} from @{text "\n, X\"} or +@{text "\n, Key K\"} and vice versa. A single protocol rule is rather defined, which enables the spy +to infer @{text "\n, X\"} from @{text "\n, Key K\"} or vice versa, provided that @{text "Crypt K X"} +has been exchanged by some legitimate agent. In fact, the protocol provides for just one compound +message made up of cryptograms, i.e. the asset's authentication token, and all these cryptograms are +generated using the same encryption key @{text "Key (SesK SK)"}. Thus, if two such cryptograms have +plaintexts @{text X\<^sub>1}, @{text X\<^sub>2} and the spy knows @{text "\n, X\<^sub>1\"}, she can infer @{text "\n, X\<^sub>2\"} +by inferring @{text "\n, Key (SesK SK)\"}, viz. she need not know @{text "\n, Crypt (SesK SK) X\<^sub>1\"} +to do that. + +The formal content is split into the following sections. + + \<^item> Section \ref{Definitions}, \emph{Definitions}, contains all the definitions needed to formalize +the sample protocol by means of the relational method, including message anonymity. + + \<^item> Section \ref{Authentication}, \emph{Confidentiality and authenticity properties}, proves that +the following theorems hold under appropriate assumptions. + + \<^enum> Theorem @{text sigkey_secret}: the signature private key is secret. + + \<^enum> Theorem @{text auth_shakey_secret}: an asset-owner pair's PACE key is secret. + + \<^enum> Theorem @{text auth_prikey_secret}: an asset's Chip Authentication private key is secret. + + \<^enum> Theorem @{text owner_seskey_unique}: an owner's session key is unknown to other owners. + + \<^enum> Theorem @{text owner_seskey_secret}: an owner's session key is secret. + + \<^enum> Theorem @{text owner_num_genuine}: the encrypted acknowledgment received by an owner has been +sent by the respective asset. + + \<^enum> Theorem @{text owner_token_genuine}: the PACE authentication token received by an owner has +been generated by the respective asset, using her Chip Authentication private key and the same +ephemeral keys used to derive the session key. + + \<^enum> Theorem @{text pwd_secret}: an asset-owner pair's password is secret. + + \<^enum> Theorem @{text asset_seskey_unique}: an asset's session key is unknown to other assets, and +may be used by that asset to compute just one PACE authentication token. + + \<^enum> Theorem @{text asset_seskey_secret}: an asset's session key is secret. + + \<^enum> Theorem @{text asset_pwd_genuine}: the encrypted password received by an asset has been sent +by the respective owner. + + \<^enum> Theorem @{text asset_token_genuine}: the PACE authentication token received by an asset has +been generated by the respective owner, using the same ephemeral key used to derive the session key. + + Particularly, these proofs confirm that the mutual authentication between an owner and her asset +is reliable even if their PACE key is compromised, unless either their Chip Authentication private +key or their password also is -- namely, the protocol succeeds in implementing a two-factor mutual +authentication. + + \<^item> Section \ref{Anonymity}, \emph{Anonymity properties}, proves that the following theorems hold +under appropriate assumptions. + + \<^enum> Theorem @{text pwd_anonymous}: an asset-owner pair's password is anonymous. + + \<^enum> Theorem @{text auth_prikey_anonymous}: an asset's Chip Authentication private key is +anonymous. + + \<^enum> Theorem @{text auth_shakey_anonymous}: an asset-owner pair's PACE key is anonymous. + + \<^item> Section \ref{Possibility}, \emph{Possibility properties}, shows how possibility properties (cf. +@{cite "Paulson98"}) can be proven by constructing sample protocol runs, either ordinary or attack +ones. Two such properties are proven: + + \<^enum> Theorem @{text runs_unbounded}: for any possible protocol state @{text s} and any asset-owner +pair, there exists a state @{text s'} reachable from @{text s} in which a protocol run has been +completed by those agents using an ephemeral private key @{text "PriKey S"} not yet exchanged in +@{text s} -- namely, an unbounded number of protocol runs can be carried out by legitimate agents. + + \<^enum> Theorem @{text pwd_compromised}: in a scenario not satisfying the assumptions of theorem +@{text pwd_anonymous}, the spy can steal an asset-owner pair's password and even identify those +agents. + + The latter is an example of a possibility property aimed at confirming that the assumptions of a +given confidentiality, authenticity, or anonymity property are necessary for it to hold. + +For further information about the formal definitions and proofs contained in these sections, see +Isabelle documentation, particularly @{cite "Paulson20"}, @{cite "Nipkow20"}, @{cite "Krauss20"}, +and @{cite "Nipkow11"}. + +\textbf{Important note.} This sample protocol was already considered in a former paper of mine (cf. +@{cite "Noce17"}). For any purpose, that paper should be regarded as being obsolete and superseded +by the present paper. +\ + + +subsection "Definitions" + +text \ +\label{Definitions} +\ + +type_synonym agent_id = nat + +type_synonym key_id = nat + +type_synonym seskey_in = "key_id option \ key_id set \ key_id set" + +datatype agent = + Asset agent_id | + Owner agent_id | + Spy + +datatype key = + SigK | + VerK | + PriK key_id | + PubK key_id | + ShaK key_id | + SesK seskey_in + +datatype msg = + Num nat | + Agent agent_id | + Pwd agent_id | + Key key | + Mult key_id key_id (infixl "\" 70) | + Hash msg | + Crypt key msg | + MPair msg msg | + IDInfo agent_id msg | + Log msg + +syntax + "_MPair" :: "['a, args] \ 'a * 'b" ("(2\_,/ _\)") + "_IDInfo" :: "[agent_id, msg] \ msg" ("(2\_,/ _\)") +translations + "\X, Y, Z\" \ "\X, \Y, Z\\" + "\X, Y\" \ "CONST MPair X Y" + "\n, X\" \ "CONST IDInfo n X" + + +abbreviation SigKey :: "msg" where +"SigKey \ Key SigK" + +abbreviation VerKey :: "msg" where +"VerKey \ Key VerK" + +abbreviation PriKey :: "key_id \ msg" where +"PriKey \ Key \ PriK" + +abbreviation PubKey :: "key_id \ msg" where +"PubKey \ Key \ PubK" + +abbreviation ShaKey :: "key_id \ msg" where +"ShaKey \ Key \ ShaK" + +abbreviation SesKey :: "seskey_in \ msg" where +"SesKey \ Key \ SesK" + +primrec InvK :: "key \ key" where +"InvK SigK = VerK" | +"InvK VerK = SigK" | +"InvK (PriK A) = PubK A" | +"InvK (PubK A) = PriK A" | +"InvK (ShaK SK) = ShaK SK" | +"InvK (SesK SK) = SesK SK" + +abbreviation InvKey :: "key \ msg" where +"InvKey \ Key \ InvK" + + +inductive_set parts :: "msg set \ msg set" + for H :: "msg set" where + +parts_used [intro]: + "X \ H \ X \ parts H" | + +parts_crypt [intro]: + "Crypt K X \ parts H \ X \ parts H" | + +parts_fst [intro]: + "\X, Y\ \ parts H \ X \ parts H" | + +parts_snd [intro]: + "\X, Y\ \ parts H \ Y \ parts H" + + +inductive_set crypts :: "msg set \ msg set" + for H :: "msg set" where + +crypts_used [intro]: + "X \ H \ X \ crypts H" | + +crypts_hash [intro]: + "foldr Crypt KS (Hash X) \ crypts H \ foldr Crypt KS X \ crypts H" | + +crypts_fst [intro]: + "foldr Crypt KS \X, Y\ \ crypts H \ foldr Crypt KS X \ crypts H" | + +crypts_snd [intro]: + "foldr Crypt KS \X, Y\ \ crypts H \ foldr Crypt KS Y \ crypts H" + + +definition key_sets :: "msg \ msg set \ msg set set" where +"key_sets X H \ {InvKey ` set KS | KS. foldr Crypt KS X \ H}" + +definition parts_msg :: "msg \ msg set" where +"parts_msg X \ parts {X}" + +definition crypts_msg :: "msg \ msg set" where +"crypts_msg X \ crypts {X}" + +definition key_sets_msg :: "msg \ msg \ msg set set" where +"key_sets_msg X Y \ key_sets X {Y}" + +fun seskey_set :: "seskey_in \ key_id set" where +"seskey_set (Some S, U, V) = insert S (U \ V)" | +"seskey_set (None, U, V) = U \ V" + + +definition Auth_PriK :: "agent_id \ key_id" where +"Auth_PriK \ SOME f. infinite (- range f)" + +abbreviation Auth_PriKey :: "agent_id \ msg" where +"Auth_PriKey \ PriKey \ Auth_PriK" + +abbreviation Auth_PubKey :: "agent_id \ msg" where +"Auth_PubKey \ PubKey \ Auth_PriK" + +consts Auth_ShaK :: "agent_id \ key_id" + +abbreviation Auth_ShaKey :: "agent_id \ key" where +"Auth_ShaKey \ ShaK \ Auth_ShaK" + +abbreviation Sign :: "agent_id \ key_id \ msg" where +"Sign n A \ Crypt SigK \Hash (Agent n), Hash (PubKey A)\" + +abbreviation Token :: "agent_id \ key_id \ key_id \ key_id \ seskey_in \ msg" +where "Token n A B C SK \ \Crypt (SesK SK) (PubKey C), + Crypt (SesK SK) (A \ B), Crypt (SesK SK) (Sign n A)\" + + +consts bad_agent :: "agent_id set" + +consts bad_pwd :: "agent_id set" + +consts bad_shak :: "key_id set" + +consts bad_id_pwd :: "agent_id set" + +consts bad_id_prik :: "agent_id set" + +consts bad_id_pubk :: "agent_id set" + +consts bad_id_shak :: "agent_id set" + +definition bad_prik :: "key_id set" where +"bad_prik \ SOME U. U \ range Auth_PriK" + +abbreviation bad_prikey :: "agent_id set" where +"bad_prikey \ Auth_PriK -` bad_prik" + +abbreviation bad_shakey :: "agent_id set" where +"bad_shakey \ Auth_ShaK -` bad_shak" + +abbreviation bad_id_password :: "agent_id set" where +"bad_id_password \ bad_id_pwd \ bad_pwd" + +abbreviation bad_id_prikey :: "agent_id set" where +"bad_id_prikey \ (bad_agent \ bad_id_pubk \ bad_id_prik) \ bad_prikey" + +abbreviation bad_id_pubkey :: "agent_id set" where +"bad_id_pubkey \ bad_agent \ bad_id_pubk \ bad_id_prik \ bad_prikey" + +abbreviation bad_id_shakey :: "agent_id set" where +"bad_id_shakey \ bad_id_shak \ bad_shakey" + + +type_synonym event = "agent \ msg" + +type_synonym state = "event set" + +abbreviation used :: "state \ msg set" where +"used s \ Range s" + +abbreviation spied :: "state \ msg set" where +"spied s \ s `` {Spy}" + +abbreviation s\<^sub>0 :: state where +"s\<^sub>0 \ range (\n. (Asset n, Auth_PriKey n)) \ {Spy} \ insert VerKey + (range Num \ range Auth_PubKey \ range (\n. Sign n (Auth_PriK n)) \ + Agent ` bad_agent \ Pwd ` bad_pwd \ PriKey ` bad_prik \ ShaKey ` bad_shak \ + (\n. \n, Pwd n\) ` bad_id_password \ + (\n. \n, Auth_PriKey n\) ` bad_id_prikey \ + (\n. \n, Auth_PubKey n\) ` bad_id_pubkey \ + (\n. \n, Key (Auth_ShaKey n)\) ` bad_id_shakey)" + + +abbreviation rel_asset_i :: "(state \ state) set" where +"rel_asset_i \ {(s, s') | s s' n S. + s' = insert (Asset n, PriKey S) s \ + {Asset n, Spy} \ {Crypt (Auth_ShaKey n) (PriKey S)} \ + {(Spy, Log (Crypt (Auth_ShaKey n) (PriKey S)))} \ + PriKey S \ used s}" + +abbreviation rel_owner_ii :: "(state \ state) set" where +"rel_owner_ii \ {(s, s') | s s' n S A K. + s' = insert (Owner n, PriKey A) s \ + {Owner n, Spy} \ {\Num 1, PubKey A\} \ + {Spy} \ Log ` {Crypt K (PriKey S), \Num 1, PubKey A\} \ + Crypt K (PriKey S) \ used s \ + PriKey A \ used s}" + +abbreviation rel_asset_ii :: "(state \ state) set" where +"rel_asset_ii \ {(s, s') | s s' n A B. + s' = insert (Asset n, PriKey B) s \ + {Asset n, Spy} \ {\Num 2, PubKey B\} \ + {Spy} \ Log ` {\Num 1, PubKey A\, \Num 2, PubKey B\} \ + \Num 1, PubKey A\ \ used s \ + PriKey B \ used s}" + +abbreviation rel_owner_iii :: "(state \ state) set" where +"rel_owner_iii \ {(s, s') | s s' n B C. + s' = insert (Owner n, PriKey C) s \ + {Owner n, Spy} \ {\Num 3, PubKey C\} \ + {Spy} \ Log ` {\Num 2, PubKey B\, \Num 3, PubKey C\} \ + \Num 2, PubKey B\ \ used s \ + PriKey C \ used s}" + +abbreviation rel_asset_iii :: "(state \ state) set" where +"rel_asset_iii \ {(s, s') | s s' n C D. + s' = insert (Asset n, PriKey D) s \ + {Asset n, Spy} \ {\Num 4, PubKey D\} \ + {Spy} \ Log ` {\Num 3, PubKey C\, \Num 4, PubKey D\} \ + \Num 3, PubKey C\ \ used s \ + PriKey D \ used s}" + +abbreviation rel_owner_iv :: "(state \ state) set" where +"rel_owner_iv \ {(s, s') | s s' n S A B C D K SK. + s' = insert (Owner n, SesKey SK) s \ + {Owner n, Spy} \ {Crypt (SesK SK) (PubKey D)} \ + {Spy} \ Log ` {\Num 4, PubKey D\, Crypt (SesK SK) (PubKey D)} \ + {Crypt K (PriKey S), \Num 2, PubKey B\, \Num 4, PubKey D\} \ used s \ + {Owner n} \ {\Num 1, PubKey A\, \Num 3, PubKey C\} \ s \ + SK = (if K = Auth_ShaKey n then Some S else None, {A, B}, {C, D})}" + +abbreviation rel_asset_iv :: "(state \ state) set" where +"rel_asset_iv \ {(s, s') | s s' n S A B C D SK. + s' = s \ {Asset n} \ {SesKey SK, PubKey B} \ + {Asset n, Spy} \ {Token n (Auth_PriK n) B C SK} \ + {Spy} \ Log ` {Crypt (SesK SK) (PubKey D), + Token n (Auth_PriK n) B C SK} \ + {Asset n} \ {Crypt (Auth_ShaKey n) (PriKey S), + \Num 2, PubKey B\, \Num 4, PubKey D\} \ s \ + {\Num 1, PubKey A\, \Num 3, PubKey C\, + Crypt (SesK SK) (PubKey D)} \ used s \ + (Asset n, PubKey B) \ s \ + SK = (Some S, {A, B}, {C, D})}" + +abbreviation rel_owner_v :: "(state \ state) set" where +"rel_owner_v \ {(s, s') | s s' n A B C SK. + s' = s \ {Owner n, Spy} \ {Crypt (SesK SK) (Pwd n)} \ + {Spy} \ Log ` {Token n A B C SK, Crypt (SesK SK) (Pwd n)} \ + Token n A B C SK \ used s \ + (Owner n, SesKey SK) \ s \ + B \ fst (snd SK)}" + +abbreviation rel_asset_v :: "(state \ state) set" where +"rel_asset_v \ {(s, s') | s s' n SK. + s' = s \ {Asset n, Spy} \ {Crypt (SesK SK) (Num 0)} \ + {Spy} \ Log ` {Crypt (SesK SK) (Pwd n), Crypt (SesK SK) (Num 0)} \ + (Asset n, SesKey SK) \ s \ + Crypt (SesK SK) (Pwd n) \ used s}" + + +abbreviation rel_prik :: "(state \ state) set" where +"rel_prik \ {(s, s') | s s' A. + s' = insert (Spy, PriKey A) s \ + PriKey A \ used s}" + +abbreviation rel_pubk :: "(state \ state) set" where +"rel_pubk \ {(s, s') | s s' A. + s' = insert (Spy, PubKey A) s \ + PriKey A \ spied s}" + +abbreviation rel_sesk :: "(state \ state) set" where +"rel_sesk \ {(s, s') | s s' A B C D S. + s' = insert (Spy, SesKey (Some S, {A, B}, {C, D})) s \ + {PriKey S, PriKey A, PubKey B, PriKey C, PubKey D} \ spied s}" + +abbreviation rel_fact :: "(state \ state) set" where +"rel_fact \ {(s, s') | s s' A B. + s' = s \ {Spy} \ {PriKey A, PriKey B} \ + A \ B \ spied s \ + (PriKey A \ spied s \ PriKey B \ spied s)}" + +abbreviation rel_mult :: "(state \ state) set" where +"rel_mult \ {(s, s') | s s' A B. + s' = insert (Spy, A \ B) s \ + {PriKey A, PriKey B} \ spied s}" + +abbreviation rel_hash :: "(state \ state) set" where +"rel_hash \ {(s, s') | s s' X. + s' = insert (Spy, Hash X) s \ + X \ spied s}" + +abbreviation rel_dec :: "(state \ state) set" where +"rel_dec \ {(s, s') | s s' K X. + s' = insert (Spy, X) s \ + {Crypt K X, InvKey K} \ spied s}" + +abbreviation rel_enc :: "(state \ state) set" where +"rel_enc \ {(s, s') | s s' K X. + s' = insert (Spy, Crypt K X) s \ + {X, Key K} \ spied s}" + +abbreviation rel_sep :: "(state \ state) set" where +"rel_sep \ {(s, s') | s s' X Y. + s' = s \ {Spy} \ {X, Y} \ + \X, Y\ \ spied s}" + +abbreviation rel_con :: "(state \ state) set" where +"rel_con \ {(s, s') | s s' X Y. + s' = insert (Spy, \X, Y\) s \ + {X, Y} \ spied s}" + + +abbreviation rel_id_agent :: "(state \ state) set" where +"rel_id_agent \ {(s, s') | s s' n. + s' = insert (Spy, \n, Agent n\) s \ + Agent n \ spied s}" + +abbreviation rel_id_invk :: "(state \ state) set" where +"rel_id_invk \ {(s, s') | s s' n K. + s' = insert (Spy, \n, InvKey K\) s \ + {InvKey K, \n, Key K\} \ spied s}" + +abbreviation rel_id_sesk :: "(state \ state) set" where +"rel_id_sesk \ {(s, s') | s s' n A SK X U. + s' = s \ {Spy} \ {\n, PubKey A\, \n, SesKey SK\} \ + {PubKey A, SesKey SK} \ spied s \ + (\n, PubKey A\ \ spied s \ \n, SesKey SK\ \ spied s) \ + A \ seskey_set SK \ + SesKey SK \ U \ + U \ key_sets X (crypts (Log -` spied s))}" + +abbreviation rel_id_fact :: "(state \ state) set" where +"rel_id_fact \ {(s, s') | s s' n A B. + s' = s \ {Spy} \ {\n, PriKey A\, \n, PriKey B\} \ + {PriKey A, PriKey B, \n, A \ B\} \ spied s}" + +abbreviation rel_id_mult :: "(state \ state) set" where +"rel_id_mult \ {(s, s') | s s' n A B U. + s' = insert (Spy, \n, A \ B\) s \ + U \ {PriKey A, PriKey B, A \ B} \ spied s \ + (\n, PriKey A\ \ spied s \ \n, PriKey B\ \ spied s) \ + U \ key_sets (A \ B) (crypts (Log -` spied s))}" + +abbreviation rel_id_hash :: "(state \ state) set" where +"rel_id_hash \ {(s, s') | s s' n X U. + s' = s \ {Spy} \ {\n, X\, \n, Hash X\} \ + U \ {X, Hash X} \ spied s \ + (\n, X\ \ spied s \ \n, Hash X\ \ spied s) \ + U \ key_sets (Hash X) (crypts (Log -` spied s))}" + +abbreviation rel_id_crypt :: "(state \ state) set" where +"rel_id_crypt \ {(s, s') | s s' n X U. + s' = s \ {Spy} \ IDInfo n ` insert X U \ + insert X U \ spied s \ + (\n, X\ \ spied s \ (\K \ U. \n, K\ \ spied s)) \ + U \ key_sets X (crypts (Log -` spied s))}" + +abbreviation rel_id_sep :: "(state \ state) set" where +"rel_id_sep \ {(s, s') | s s' n X Y. + s' = s \ {Spy} \ {\n, X\, \n, Y\} \ + {X, Y, \n, \X, Y\\} \ spied s}" + +abbreviation rel_id_con :: "(state \ state) set" where +"rel_id_con \ {(s, s') | s s' n X Y U. + s' = insert (Spy, \n, \X, Y\\) s \ + U \ {X, Y, \X, Y\} \ spied s \ + (\n, X\ \ spied s \ \n, Y\ \ spied s) \ + U \ key_sets \X, Y\ (crypts (Log -` spied s))}" + + +definition rel :: "(state \ state) set" where +"rel \ rel_asset_i \ rel_owner_ii \ rel_asset_ii \ rel_owner_iii \ + rel_asset_iii \ rel_owner_iv \ rel_asset_iv \ rel_owner_v \ rel_asset_v \ + rel_prik \ rel_pubk \ rel_sesk \ rel_fact \ rel_mult \ rel_hash \ rel_dec \ + rel_enc \ rel_sep \ rel_con \ rel_id_agent \ rel_id_invk \ rel_id_sesk \ + rel_id_fact \ rel_id_mult \ rel_id_hash \ rel_id_crypt \ rel_id_sep \ rel_id_con" + +abbreviation in_rel :: "state \ state \ bool" (infix "\" 60) where +"s \ s' \ (s, s') \ rel" + +abbreviation in_rel_rtrancl :: "state \ state \ bool" (infix "\" 60) where +"s \ s' \ (s, s') \ rel\<^sup>*" + + +end diff --git a/thys/Relational_Method/Possibility.thy b/thys/Relational_Method/Possibility.thy new file mode 100644 --- /dev/null +++ b/thys/Relational_Method/Possibility.thy @@ -0,0 +1,990 @@ +(* Title: The Relational Method with Message Anonymity for the Verification of Cryptographic Protocols + Author: Pasquale Noce + Software Engineer at HID Global, Italy + pasquale dot noce dot lavoro at gmail dot com + pasquale dot noce at hidglobal dot com +*) + +section "Possibility properties" + +theory Possibility + imports Anonymity +begin + +text \ +\label{Possibility} +\ + + +type_synonym seskey_tuple = "key_id \ key_id \ key_id \ key_id \ key_id" + +type_synonym stage = "state \ seskey_tuple" + + +abbreviation pred_asset_i :: "agent_id \ state \ stage \ bool" where +"pred_asset_i n s x \ + \S. PriKey S \ used s \ x = (insert (Asset n, PriKey S) s \ + {Asset n, Spy} \ {Crypt (Auth_ShaKey n) (PriKey S)} \ + {(Spy, Log (Crypt (Auth_ShaKey n) (PriKey S)))}, + S, 0, 0, 0, 0)" + +definition run_asset_i :: "agent_id \ state \ stage" where +"run_asset_i n s \ SOME x. pred_asset_i n s x" + + +abbreviation pred_owner_ii :: "agent_id \ stage \ stage \ bool" where +"pred_owner_ii n x y \ case x of (s, S, _) \ + \A. PriKey A \ used s \ y = (insert (Owner n, PriKey A) s \ + {Owner n, Spy} \ {\Num 1, PubKey A\} \ + {Spy} \ Log ` {Crypt (Auth_ShaKey n) (PriKey S), \Num 1, PubKey A\}, + S, A, 0, 0, 0)" + +definition run_owner_ii :: "agent_id \ state \ stage" where +"run_owner_ii n s \ SOME x. pred_owner_ii n (run_asset_i n s) x" + + +abbreviation pred_asset_ii :: "agent_id \ stage \ stage \ bool" where +"pred_asset_ii n x y \ case x of (s, S, A, _) \ + \B. PriKey B \ used s \ y = (insert (Asset n, PriKey B) s \ + {Asset n, Spy} \ {\Num 2, PubKey B\} \ + {Spy} \ Log ` {\Num 1, PubKey A\, \Num 2, PubKey B\}, + S, A, B, 0, 0)" + +definition run_asset_ii :: "agent_id \ state \ stage" where +"run_asset_ii n s \ SOME x. pred_asset_ii n (run_owner_ii n s) x" + + +abbreviation pred_owner_iii :: "agent_id \ stage \ stage \ bool" where +"pred_owner_iii n x y \ case x of (s, S, A, B, _) \ + \C. PriKey C \ used s \ y = (insert (Owner n, PriKey C) s \ + {Owner n, Spy} \ {\Num 3, PubKey C\} \ + {Spy} \ Log ` {\Num 2, PubKey B\, \Num 3, PubKey C\}, + S, A, B, C, 0)" + +definition run_owner_iii :: "agent_id \ state \ stage" where +"run_owner_iii n s \ SOME x. pred_owner_iii n (run_asset_ii n s) x" + + +abbreviation pred_asset_iii :: "agent_id \ stage \ stage \ bool" where +"pred_asset_iii n x y \ case x of (s, S, A, B, C, _) \ + \D. PriKey D \ used s \ y = (insert (Asset n, PriKey D) s \ + {Asset n, Spy} \ {\Num 4, PubKey D\} \ + {Spy} \ Log ` {\Num 3, PubKey C\, \Num 4, PubKey D\}, + S, A, B, C, D)" + +definition run_asset_iii :: "agent_id \ state \ stage" where +"run_asset_iii n s \ SOME x. pred_asset_iii n (run_owner_iii n s) x" + + +abbreviation stage_owner_iv :: "agent_id \ stage \ stage" where +"stage_owner_iv n x \ let (s, S, A, B, C, D) = x; + SK = (Some S, {A, B}, {C, D}) in + (insert (Owner n, SesKey SK) s \ + {Owner n, Spy} \ {Crypt (SesK SK) (PubKey D)} \ + {Spy} \ Log ` {\Num 4, PubKey D\, Crypt (SesK SK) (PubKey D)}, + S, A, B, C, D)" + +definition run_owner_iv :: "agent_id \ state \ stage" where +"run_owner_iv n s \ stage_owner_iv n (run_asset_iii n s)" + + +abbreviation stage_asset_iv :: "agent_id \ stage \ stage" where +"stage_asset_iv n x \ let (s, S, A, B, C, D) = x; + SK = (Some S, {A, B}, {C, D}) in + (s \ {Asset n} \ {SesKey SK, PubKey B} \ + {Asset n, Spy} \ {Token n (Auth_PriK n) B C SK} \ + {Spy} \ Log ` {Crypt (SesK SK) (PubKey D), + Token n (Auth_PriK n) B C SK}, + S, A, B, C, D)" + +definition run_asset_iv :: "agent_id \ state \ stage" where +"run_asset_iv n s \ stage_asset_iv n (run_owner_iv n s)" + + +abbreviation stage_owner_v :: "agent_id \ stage \ stage" where +"stage_owner_v n x \ let (s, S, A, B, C, D) = x; + SK = (Some S, {A, B}, {C, D}) in + (s \ {Owner n, Spy} \ {Crypt (SesK SK) (Pwd n)} \ + {Spy} \ Log ` {Token n (Auth_PriK n) B C SK, Crypt (SesK SK) (Pwd n)}, + S, A, B, C, D)" + +definition run_owner_v :: "agent_id \ state \ stage" where +"run_owner_v n s \ stage_owner_v n (run_asset_iv n s)" + + +abbreviation stage_asset_v :: "agent_id \ stage \ stage" where +"stage_asset_v n x \ let (s, S, A, B, C, D) = x; + SK = (Some S, {A, B}, {C, D}) in + (s \ {Asset n, Spy} \ {Crypt (SesK SK) (Num 0)} \ + {Spy} \ Log ` {Crypt (SesK SK) (Pwd n), Crypt (SesK SK) (Num 0)}, + S, A, B, C, D)" + +definition run_asset_v :: "agent_id \ state \ stage" where +"run_asset_v n s \ stage_asset_v n (run_owner_v n s)" + + +lemma prikey_unused_1: + "infinite {A. PriKey A \ used s\<^sub>0}" +by (rule infinite_super [of "- range Auth_PriK"], rule subsetI, simp add: + image_def bad_prik_def, rule someI2 [of _ "{}"], simp, blast, subst Auth_PriK_def, + rule someI [of _ "\n. 0"], simp) + +lemma prikey_unused_2: + "\s \ s'; infinite {A. PriKey A \ used s}\ \ + infinite {A. PriKey A \ used s'}" +by (simp add: rel_def, ((erule disjE)?, (erule exE)+, simp add: image_iff, + (((subst conj_commute | subst Int_commute), simp add: Collect_conj_eq Collect_neg_eq + Diff_eq [symmetric])+)?, ((rule Diff_infinite_finite, rule msg.induct, simp_all, + rule key.induct, simp_all)+)?)+) + +proposition prikey_unused: + "s\<^sub>0 \ s \ \A. PriKey A \ used s" +by (subgoal_tac "infinite {A. PriKey A \ used s}", drule infinite_imp_nonempty, + simp, erule rtrancl_induct, rule prikey_unused_1, rule prikey_unused_2) + + +lemma pubkey_unused_1: + "\s \ s'; PubKey A \ parts (used s) \ PriKey A \ used s; + PubKey A \ parts (used s')\ \ + PriKey A \ used s'" +by (simp add: rel_def, ((erule disjE)?, ((erule exE)+)?, simp add: parts_insert + image_iff split: if_split_asm, ((erule conjE)+, drule RangeI, (drule parts_used, + drule parts_snd)?, simp | (subst (asm) disj_assoc [symmetric])?, erule disjE, + (drule parts_dec | drule parts_enc | drule parts_sep | drule parts_con), simp)?)+) + +proposition pubkey_unused [rule_format]: + "s\<^sub>0 \ s \ + PriKey A \ used s \ + PubKey A \ parts (used s)" +by (erule rtrancl_induct, subst parts_init, simp add: Range_iff image_def, rule impI, + erule contrapos_nn [OF _ pubkey_unused_1], blast+) + + +proposition run_asset_i_ex: + "s\<^sub>0 \ s \ pred_asset_i n s (run_asset_i n s)" +by (drule prikey_unused, erule exE, subst run_asset_i_def, rule someI_ex, blast) + +proposition run_asset_i_rel: + "s\<^sub>0 \ s \ s \ fst (run_asset_i n s)" + (is "_ \ _ \ ?t") +by (drule run_asset_i_ex [of _ n], rule r_into_rtrancl, + subgoal_tac "(s, ?t) \ rel_asset_i", simp_all add: rel_def, erule exE, auto) + +proposition run_asset_i_msg: + "s\<^sub>0 \ s \ + case run_asset_i n s of (s', S, _) \ + (Asset n, Crypt (Auth_ShaKey n) (PriKey S)) \ s'" +by (drule run_asset_i_ex [of _ n], auto) + +proposition run_asset_i_nonce: + "s\<^sub>0 \ s \ PriKey (fst (snd (run_asset_i n s))) \ used s" +by (drule run_asset_i_ex [of _ n], auto) + +proposition run_asset_i_unused: + "s\<^sub>0 \ s \ \A. PriKey A \ used (fst (run_asset_i n s))" +by (rule prikey_unused, rule rtrancl_trans, simp, rule run_asset_i_rel) + + +proposition run_owner_ii_ex: + "s\<^sub>0 \ s \ pred_owner_ii n (run_asset_i n s) (run_owner_ii n s)" +by (drule run_asset_i_unused, erule exE, subst run_owner_ii_def, rule someI_ex, + auto simp add: split_def) + +proposition run_owner_ii_rel: + "s\<^sub>0 \ s \ s \ fst (run_owner_ii n s)" + (is "_ \ _ \ ?t") +by (rule rtrancl_into_rtrancl, erule run_asset_i_rel [of _ n], frule run_asset_i_msg, + drule run_owner_ii_ex, subgoal_tac "(fst (run_asset_i n s), ?t) \ rel_owner_ii", + simp_all add: rel_def split_def, erule exE, (rule exI)+, auto) + +proposition run_owner_ii_msg: + "s\<^sub>0 \ s \ + case run_owner_ii n s of (s', S, A, _) \ + {(Asset n, Crypt (Auth_ShaKey n) (PriKey S)), + (Owner n, \Num 1, PubKey A\)} \ s'" +by (frule run_asset_i_msg [of _ n], drule run_owner_ii_ex [of _ n], auto) + +proposition run_owner_ii_nonce: + "s\<^sub>0 \ s \ PriKey (fst (snd (run_owner_ii n s))) \ used s" +by (frule run_asset_i_nonce [of _ n], drule run_owner_ii_ex [of _ n], auto) + +proposition run_owner_ii_unused: + "s\<^sub>0 \ s \ \B. PriKey B \ used (fst (run_owner_ii n s))" +by (rule prikey_unused, rule rtrancl_trans, simp, rule run_owner_ii_rel) + + +proposition run_asset_ii_ex: + "s\<^sub>0 \ s \ pred_asset_ii n (run_owner_ii n s) (run_asset_ii n s)" +by (drule run_owner_ii_unused, erule exE, subst run_asset_ii_def, rule someI_ex, + auto simp add: split_def) + +proposition run_asset_ii_rel: + "s\<^sub>0 \ s \ s \ fst (run_asset_ii n s)" + (is "_ \ _ \ ?t") +by (rule rtrancl_into_rtrancl, erule run_owner_ii_rel [of _ n], frule run_owner_ii_msg, + drule run_asset_ii_ex, subgoal_tac "(fst (run_owner_ii n s), ?t) \ rel_asset_ii", + simp_all add: rel_def split_def, erule exE, (rule exI)+, auto) + +proposition run_asset_ii_msg: + assumes A: "s\<^sub>0 \ s" + shows "case run_asset_ii n s of (s', S, A, B, _) \ + insert (Owner n, \Num 1, PubKey A\) + ({Asset n} \ {Crypt (Auth_ShaKey n) (PriKey S), + \Num 2, PubKey B\}) \ s' \ + (Asset n, PubKey B) \ s'" +by (insert run_owner_ii_msg [OF A, of n], insert run_asset_ii_ex [OF A, of n], + simp add: split_def, erule exE, simp, insert run_owner_ii_rel [OF A, of n], + drule rtrancl_trans [OF A], drule pubkey_unused, auto) + +proposition run_asset_ii_nonce: + "s\<^sub>0 \ s \ PriKey (fst (snd (run_asset_ii n s))) \ used s" +by (frule run_owner_ii_nonce [of _ n], drule run_asset_ii_ex [of _ n], auto) + +proposition run_asset_ii_unused: + "s\<^sub>0 \ s \ \C. PriKey C \ used (fst (run_asset_ii n s))" +by (rule prikey_unused, rule rtrancl_trans, simp, rule run_asset_ii_rel) + + +proposition run_owner_iii_ex: + "s\<^sub>0 \ s \ pred_owner_iii n (run_asset_ii n s) (run_owner_iii n s)" +by (drule run_asset_ii_unused, erule exE, subst run_owner_iii_def, rule someI_ex, + auto simp add: split_def) + +proposition run_owner_iii_rel: + "s\<^sub>0 \ s \ s \ fst (run_owner_iii n s)" + (is "_ \ _ \ ?t") +by (rule rtrancl_into_rtrancl, erule run_asset_ii_rel [of _ n], frule run_asset_ii_msg, + drule run_owner_iii_ex, subgoal_tac "(fst (run_asset_ii n s), ?t) \ rel_owner_iii", + simp_all add: rel_def split_def, erule exE, (rule exI)+, auto) + +proposition run_owner_iii_msg: + "s\<^sub>0 \ s \ + case run_owner_iii n s of (s', S, A, B, C, _) \ + {Asset n} \ {Crypt (Auth_ShaKey n) (PriKey S), \Num 2, PubKey B\} \ + {Owner n} \ {\Num 1, PubKey A\, \Num 3, PubKey C\} \ s' \ + (Asset n, PubKey B) \ s'" +by (frule run_asset_ii_msg [of _ n], drule run_owner_iii_ex [of _ n], auto) + +proposition run_owner_iii_nonce: + "s\<^sub>0 \ s \ PriKey (fst (snd (run_owner_iii n s))) \ used s" +by (frule run_asset_ii_nonce [of _ n], drule run_owner_iii_ex [of _ n], auto) + +proposition run_owner_iii_unused: + "s\<^sub>0 \ s \ \D. PriKey D \ used (fst (run_owner_iii n s))" +by (rule prikey_unused, rule rtrancl_trans, simp, rule run_owner_iii_rel) + + +proposition run_asset_iii_ex: + "s\<^sub>0 \ s \ pred_asset_iii n (run_owner_iii n s) (run_asset_iii n s)" +by (drule run_owner_iii_unused, erule exE, subst run_asset_iii_def, rule someI_ex, + auto simp add: split_def) + +proposition run_asset_iii_rel: + "s\<^sub>0 \ s \ s \ fst (run_asset_iii n s)" + (is "_ \ _ \ ?t") +by (rule rtrancl_into_rtrancl, erule run_owner_iii_rel [of _ n], frule run_owner_iii_msg, + drule run_asset_iii_ex, subgoal_tac "(fst (run_owner_iii n s), ?t) \ rel_asset_iii", + simp_all add: rel_def split_def, erule exE, (rule exI)+, auto) + +proposition run_asset_iii_msg: + "s\<^sub>0 \ s \ + case run_asset_iii n s of (s', S, A, B, C, D) \ + {Asset n} \ {Crypt (Auth_ShaKey n) (PriKey S), \Num 2, PubKey B\, + \Num 4, PubKey D\} \ + {Owner n} \ {\Num 1, PubKey A\, \Num 3, PubKey C\} \ s' \ + (Asset n, PubKey B) \ s'" +by (frule run_owner_iii_msg [of _ n], drule run_asset_iii_ex [of _ n], auto) + +proposition run_asset_iii_nonce: + "s\<^sub>0 \ s \ PriKey (fst (snd (run_asset_iii n s))) \ used s" +by (frule run_owner_iii_nonce [of _ n], drule run_asset_iii_ex [of _ n], auto) + + +lemma run_owner_iv_rel_1: + "\s\<^sub>0 \ s; run_asset_iii n s = (s', S, A, B, C, D)\ \ + s \ fst (run_owner_iv n s)" + (is "\_; _\ \ _ \ ?t") +by (rule rtrancl_into_rtrancl, erule run_asset_iii_rel [of _ n], drule run_asset_iii_msg + [of _ n], subgoal_tac "(s', ?t) \ rel_owner_iv", simp_all add: rel_def run_owner_iv_def + Let_def, rule exI [of _ n], rule exI [of _ S], rule exI [of _ A], rule exI [of _ B], + rule exI [of _ C], rule exI [of _ D], rule exI [of _ "Auth_ShaKey n"], auto) + +proposition run_owner_iv_rel: + "s\<^sub>0 \ s \ s \ fst (run_owner_iv n s)" +by (insert run_owner_iv_rel_1, cases "run_asset_iii n s", simp) + +proposition run_owner_iv_msg: + "s\<^sub>0 \ s \ + let (s', S, A, B, C, D) = run_owner_iv n s; + SK = (Some S, {A, B}, {C, D}) in + {Asset n} \ {Crypt (Auth_ShaKey n) (PriKey S), \Num 2, PubKey B\, + \Num 4, PubKey D\} \ + {Owner n} \ {\Num 1, PubKey A\, \Num 3, PubKey C\, SesKey SK, + Crypt (SesK SK) (PubKey D)} \ s' \ + (Asset n, PubKey B) \ s'" +by (drule run_asset_iii_msg [of _ n], simp add: run_owner_iv_def split_def Let_def) + +proposition run_owner_iv_nonce: + "s\<^sub>0 \ s \ PriKey (fst (snd (run_owner_iv n s))) \ used s" +by (drule run_asset_iii_nonce [of _ n], simp add: run_owner_iv_def split_def Let_def) + + +proposition run_asset_iv_rel: + "s\<^sub>0 \ s \ s \ fst (run_asset_iv n s)" + (is "_ \ _ \ ?t") +by (rule rtrancl_into_rtrancl, erule run_owner_iv_rel [of _ n], drule run_owner_iv_msg + [of _ n], subgoal_tac "(fst (run_owner_iv n s), ?t) \ rel_asset_iv", simp_all add: + rel_def run_asset_iv_def split_def Let_def, blast) + +proposition run_asset_iv_msg: + "s\<^sub>0 \ s \ + let (s', S, A, B, C, D) = run_asset_iv n s; SK = (Some S, {A, B}, {C, D}) in + insert (Owner n, SesKey SK) + ({Asset n} \ {SesKey SK, Token n (Auth_PriK n) B C SK}) \ s'" +by (drule run_owner_iv_msg [of _ n], simp add: run_asset_iv_def split_def Let_def) + +proposition run_asset_iv_nonce: + "s\<^sub>0 \ s \ PriKey (fst (snd (run_asset_iv n s))) \ used s" +by (drule run_owner_iv_nonce [of _ n], simp add: run_asset_iv_def split_def Let_def) + + +proposition run_owner_v_rel: + "s\<^sub>0 \ s \ s \ fst (run_owner_v n s)" + (is "_ \ _ \ ?t") +by (rule rtrancl_into_rtrancl, erule run_asset_iv_rel [of _ n], drule run_asset_iv_msg + [of _ n], subgoal_tac "(fst (run_asset_iv n s), ?t) \ rel_owner_v", simp_all add: + rel_def run_owner_v_def split_def Let_def, blast) + +proposition run_owner_v_msg: + "s\<^sub>0 \ s \ + let (s', S, A, B, C, D) = run_owner_v n s; + SK = (Some S, {A, B}, {C, D}) in + {(Asset n, SesKey SK), + (Owner n, Crypt (SesK SK) (Pwd n))} \ s'" +by (drule run_asset_iv_msg [of _ n], simp add: run_owner_v_def split_def Let_def) + +proposition run_owner_v_nonce: + "s\<^sub>0 \ s \ PriKey (fst (snd (run_owner_v n s))) \ used s" +by (drule run_asset_iv_nonce [of _ n], simp add: run_owner_v_def split_def Let_def) + + +proposition run_asset_v_rel: + "s\<^sub>0 \ s \ s \ fst (run_asset_v n s)" + (is "_ \ _ \ ?t") +by (rule rtrancl_into_rtrancl, erule run_owner_v_rel [of _ n], drule run_owner_v_msg + [of _ n], subgoal_tac "(fst (run_owner_v n s), ?t) \ rel_asset_v", simp_all add: + rel_def run_asset_v_def split_def Let_def, blast) + +proposition run_asset_v_msg: + "s\<^sub>0 \ s \ + let (s', S, A, B, C, D) = run_asset_v n s; SK = (Some S, {A, B}, {C, D}) in + {(Owner n, Crypt (SesK SK) (Pwd n)), + (Asset n, Crypt (SesK SK) (Num 0))} \ s'" +by (drule run_owner_v_msg [of _ n], simp add: run_asset_v_def split_def Let_def) + +proposition run_asset_v_nonce: + "s\<^sub>0 \ s \ PriKey (fst (snd (run_asset_v n s))) \ used s" +by (drule run_owner_v_nonce [of _ n], simp add: run_asset_v_def split_def Let_def) + + +lemma runs_unbounded_1: + "\s\<^sub>0 \ s; run_asset_v n s = (s', S, A, B, C, D)\ \ + \s' S SK. (Asset n, Crypt (Auth_ShaKey n) (PriKey S)) \ s \ + {(Owner n, Crypt (SesK SK) (Pwd n)), + (Asset n, Crypt (SesK SK) (Num 0))} \ s' \ + s \ s' \ fst SK = Some S" +by (rule exI [of _ s'], rule exI [of _ S], rule exI [of _ "(Some S, {A, B}, {C, D})"], + rule conjI, rule notI, frule run_asset_v_nonce [of _ n], frule asset_i_used [of _ n S], + simp, frule run_asset_v_rel [of _ n], drule run_asset_v_msg [of _ n], + simp add: Let_def) + +theorem runs_unbounded: + "s\<^sub>0 \ s \ \s' S SK. s \ s' \ fst SK = Some S \ + (Asset n, Crypt (Auth_ShaKey n) (PriKey S)) \ s \ + {(Owner n, Crypt (SesK SK) (Pwd n)), + (Asset n, Crypt (SesK SK) (Num 0))} \ s'" +by (insert runs_unbounded_1, cases "run_asset_v n s", blast) + + +definition pwd_spy_i :: "agent_id \ stage" where +"pwd_spy_i n \ + (insert (Spy, Crypt (Auth_ShaKey n) (Auth_PriKey n)) s\<^sub>0, + Auth_PriK n, 0, 0, 0, 0)" + +definition pwd_owner_ii :: "agent_id \ stage" where +"pwd_owner_ii n \ SOME x. pred_owner_ii n (pwd_spy_i n) x" + +definition pwd_spy_ii :: "agent_id \ stage" where +"pwd_spy_ii n \ + case pwd_owner_ii n of (s, S, A, _) \ + (insert (Spy, \Num 2, PubKey S\) s, S, A, S, 0, 0)" + +definition pwd_owner_iii :: "agent_id \ stage" where +"pwd_owner_iii n \ SOME x. pred_owner_iii n (pwd_spy_ii n) x" + +definition pwd_spy_iii :: "agent_id \ stage" where +"pwd_spy_iii n \ + case pwd_owner_iii n of (s, S, A, B, C, _) \ + (insert (Spy, \Num 4, PubKey S\) s, S, A, B, C, S)" + +definition pwd_owner_iv :: "agent_id \ stage" where +"pwd_owner_iv n \ stage_owner_iv n (pwd_spy_iii n)" + + +definition pwd_spy_sep_map :: "agent_id \ stage" where +"pwd_spy_sep_map n \ + case pwd_owner_iv n of (s, S, A, B, C, D) \ + (insert (Spy, PubKey A) s, S, A, B, C, D)" + +definition pwd_spy_sep_agr :: "agent_id \ stage" where +"pwd_spy_sep_agr n \ + case pwd_spy_sep_map n of (s, S, A, B, C, D) \ + (insert (Spy, PubKey C) s, S, A, B, C, D)" + +definition pwd_spy_sesk :: "agent_id \ stage" where +"pwd_spy_sesk n \ + let (s, S, A, B, C, D) = pwd_spy_sep_agr n; + SK = (Some S, {A, B}, {C, D}) in + (insert (Spy, SesKey SK) s, S, A, B, C, D)" + +definition pwd_spy_mult :: "agent_id \ stage" where +"pwd_spy_mult n \ + case pwd_spy_sesk n of (s, S, A, B, C, D) \ + (insert (Spy, Auth_PriK n \ B) s, S, A, B, C, D)" + +definition pwd_spy_enc_pubk :: "agent_id \ stage" where +"pwd_spy_enc_pubk n \ + let (s, S, A, B, C, D) = pwd_spy_mult n; SK = (Some S, {A, B}, {C, D}) in + (insert (Spy, Crypt (SesK SK) (PubKey C)) s, S, A, B, C, D)" + +definition pwd_spy_enc_mult :: "agent_id \ stage" where +"pwd_spy_enc_mult n \ + let (s, S, A, B, C, D) = pwd_spy_enc_pubk n; + SK = (Some S, {A, B}, {C, D}) in + (insert (Spy, Crypt (SesK SK) (Auth_PriK n \ B)) s, S, A, B, C, D)" + +definition pwd_spy_enc_sign :: "agent_id \ stage" where +"pwd_spy_enc_sign n \ + let (s, S, A, B, C, D) = pwd_spy_enc_mult n; + SK = (Some S, {A, B}, {C, D}) in + (insert (Spy, Crypt (SesK SK) (Sign n (Auth_PriK n))) s, S, A, B, C, D)" + +definition pwd_spy_con :: "agent_id \ stage" where +"pwd_spy_con n \ + let (s, S, A, B, C, D) = pwd_spy_enc_sign n; + SK = (Some S, {A, B}, {C, D}) in + (insert (Spy, \Crypt (SesK SK) (Auth_PriK n \ B), + Crypt (SesK SK) (Sign n (Auth_PriK n))\) s, S, A, B, C, D)" + +definition pwd_spy_iv :: "agent_id \ stage" where +"pwd_spy_iv n \ + let (s, S, A, B, C, D) = pwd_spy_con n; SK = (Some S, {A, B}, {C, D}) in + (insert (Spy, Token n (Auth_PriK n) B C SK) s, S, A, B, C, D)" + + +definition pwd_owner_v :: "agent_id \ stage" where +"pwd_owner_v n \ stage_owner_v n (pwd_spy_iv n)" + +definition pwd_spy_dec :: "agent_id \ stage" where +"pwd_spy_dec n \ + case pwd_owner_v n of (s, S, A, B, C, D) \ + (insert (Spy, Pwd n) s, S, A, B, C, D)" + +definition pwd_spy_id_prik :: "agent_id \ stage" where +"pwd_spy_id_prik n \ + case pwd_spy_dec n of (s, S, A, B, C, D) \ + (insert (Spy, \n, PriKey S\) s, S, A, B, C, D)" + +definition pwd_spy_id_pubk :: "agent_id \ stage" where +"pwd_spy_id_pubk n \ + case pwd_spy_id_prik n of (s, S, A, B, C, D) \ + (insert (Spy, \n, PubKey S\) s, S, A, B, C, D)" + +definition pwd_spy_id_sesk :: "agent_id \ stage" where +"pwd_spy_id_sesk n \ + let (s, S, A, B, C, D) = pwd_spy_id_pubk n; + SK = (Some S, {A, B}, {C, D}) in + (insert (Spy, \n, SesKey SK\) s, S, A, B, C, D)" + +definition pwd_spy_id_pwd :: "agent_id \ stage" where +"pwd_spy_id_pwd n \ + case pwd_spy_id_sesk n of (s, S, A, B, C, D) \ + (insert (Spy, \n, Pwd n\) s, S, A, B, C, D)" + + +proposition key_sets_crypts_subset: + "\U \ key_sets X (crypts (Log -` spied H)); H \ H'\ \ + U \ key_sets X (crypts (Log -` spied H'))" + (is "\_ \ ?A; _\ \ _") +by (rule subsetD [of ?A], rule key_sets_mono, rule crypts_mono, blast) + + +fun pwd_spy_i_state :: "agent_id \ seskey_tuple \ state" where +"pwd_spy_i_state n (S, _) = {Spy} \ ({PriKey S, PubKey S, Key (Auth_ShaKey n), + Auth_PriKey n, Sign n (Auth_PriK n), Crypt (Auth_ShaKey n) (PriKey S), + \n, Key (Auth_ShaKey n)\} \ range Num)" + +proposition pwd_spy_i_rel: + "n \ bad_prikey \ bad_id_shakey \ s\<^sub>0 \ fst (pwd_spy_i n)" + (is "_ \ _ \ ?t") +by (rule r_into_rtrancl, subgoal_tac "(s\<^sub>0, ?t) \ rel_enc", simp_all add: rel_def + pwd_spy_i_def, blast) + +proposition pwd_spy_i_msg: + "n \ bad_prikey \ bad_id_shakey \ + case pwd_spy_i n of (s, S, A, B, C, D) \ + pwd_spy_i_state n (S, A, B, C, D) \ s" +by (simp add: pwd_spy_i_def, blast) + +proposition pwd_spy_i_unused: + "n \ bad_prikey \ bad_id_shakey \ \A. PriKey A \ used (fst (pwd_spy_i n))" +by (drule pwd_spy_i_rel, rule prikey_unused) + + +fun pwd_owner_ii_state :: "agent_id \ seskey_tuple \ state" where +"pwd_owner_ii_state n (S, A, B, C, D) = + pwd_spy_i_state n (S, A, B, C, D) \ {Owner n, Spy} \ {\Num 1, PubKey A\}" + +proposition pwd_owner_ii_ex: + "n \ bad_prikey \ bad_id_shakey \ + pred_owner_ii n (pwd_spy_i n) (pwd_owner_ii n)" +by (drule pwd_spy_i_unused, erule exE, subst pwd_owner_ii_def, rule someI_ex, + auto simp add: split_def) + +proposition pwd_owner_ii_rel: + "n \ bad_prikey \ bad_id_shakey \ s\<^sub>0 \ fst (pwd_owner_ii n)" + (is "_ \ _ \ ?t") +by (rule rtrancl_into_rtrancl, erule pwd_spy_i_rel, frule pwd_spy_i_msg, + drule pwd_owner_ii_ex, subgoal_tac "(fst (pwd_spy_i n), ?t) \ rel_owner_ii", + simp_all add: rel_def split_def, erule exE, rule exI, auto) + +proposition pwd_owner_ii_msg: + "n \ bad_prikey \ bad_id_shakey \ + case pwd_owner_ii n of (s, S, A, B, C, D) \ + pwd_owner_ii_state n (S, A, B, C, D) \ s \ + {Key (Auth_ShaKey n)} \ key_sets (PriKey S) (crypts (Log -` spied s))" +by (frule pwd_spy_i_msg, drule pwd_owner_ii_ex, simp add: split_def, erule exE, + simp add: Image_def, simp only: Collect_disj_eq crypts_union key_sets_union, + simp add: crypts_insert key_sets_insert, blast) + + +fun pwd_spy_ii_state :: "agent_id \ seskey_tuple \ state" where +"pwd_spy_ii_state n (S, A, B, C, D) = + pwd_owner_ii_state n (S, A, B, C, D) \ {Spy} \ {PriKey B, + \Num 2, PubKey B\}" + +proposition pwd_spy_ii_rel: + "n \ bad_prikey \ bad_id_shakey \ s\<^sub>0 \ fst (pwd_spy_ii n)" + (is "_ \ _ \ ?t") +by (rule rtrancl_into_rtrancl, erule pwd_owner_ii_rel, drule pwd_owner_ii_msg, + subgoal_tac "(fst (pwd_owner_ii n), ?t) \ rel_con", simp_all add: rel_def + pwd_spy_ii_def split_def, blast) + +proposition pwd_spy_ii_msg: + "n \ bad_prikey \ bad_id_shakey \ + case pwd_spy_ii n of (s, S, A, B, C, D) \ + pwd_spy_ii_state n (S, A, B, C, D) \ s \ + {Key (Auth_ShaKey n)} \ key_sets (PriKey S) (crypts (Log -` spied s))" +by (drule pwd_owner_ii_msg, simp add: pwd_spy_ii_def split_def, + (erule conjE)+, ((rule conjI | erule key_sets_crypts_subset), blast)+) + +proposition pwd_spy_ii_unused: + "n \ bad_prikey \ bad_id_shakey \ \C. PriKey C \ used (fst (pwd_spy_ii n))" +by (drule pwd_spy_ii_rel, rule prikey_unused) + + +fun pwd_owner_iii_state :: "agent_id \ seskey_tuple \ state" where +"pwd_owner_iii_state n (S, A, B, C, D) = + pwd_spy_ii_state n (S, A, B, C, D) \ {Owner n, Spy} \ {\Num 3, PubKey C\}" + +proposition pwd_owner_iii_ex: + "n \ bad_prikey \ bad_id_shakey \ + pred_owner_iii n (pwd_spy_ii n) (pwd_owner_iii n)" +by (drule pwd_spy_ii_unused, erule exE, subst pwd_owner_iii_def, rule someI_ex, + auto simp add: split_def) + +proposition pwd_owner_iii_rel: + "n \ bad_prikey \ bad_id_shakey \ s\<^sub>0 \ fst (pwd_owner_iii n)" + (is "_ \ _ \ ?t") +by (rule rtrancl_into_rtrancl, erule pwd_spy_ii_rel, frule pwd_spy_ii_msg, + drule pwd_owner_iii_ex, subgoal_tac "(fst (pwd_spy_ii n), ?t) \ rel_owner_iii", + simp_all add: rel_def split_def, rule exI, rule exI, auto) + +proposition pwd_owner_iii_msg: + "n \ bad_prikey \ bad_id_shakey \ + case pwd_owner_iii n of (s, S, A, B, C, D) \ + pwd_owner_iii_state n (S, A, B, C, D) \ s \ + {Key (Auth_ShaKey n)} \ key_sets (PriKey S) (crypts (Log -` spied s))" +by (frule pwd_spy_ii_msg, drule pwd_owner_iii_ex, simp add: split_def, erule exE, + simp, (erule conjE)+, ((rule conjI | erule key_sets_crypts_subset), blast)+) + + +fun pwd_spy_iii_state :: "agent_id \ seskey_tuple \ state" where +"pwd_spy_iii_state n (S, A, B, C, D) = + pwd_owner_iii_state n (S, A, B, C, D) \ {Spy} \ {PriKey D, + \Num 4, PubKey D\}" + +proposition pwd_spy_iii_rel: + "n \ bad_prikey \ bad_id_shakey \ s\<^sub>0 \ fst (pwd_spy_iii n)" + (is "_ \ _ \ ?t") +by (rule rtrancl_into_rtrancl, erule pwd_owner_iii_rel, drule pwd_owner_iii_msg, + subgoal_tac "(fst (pwd_owner_iii n), ?t) \ rel_con", simp_all add: rel_def + pwd_spy_iii_def split_def, blast) + +proposition pwd_spy_iii_msg: + "n \ bad_prikey \ bad_id_shakey \ + case pwd_spy_iii n of (s, S, A, B, C, D) \ + pwd_spy_iii_state n (S, A, B, C, D) \ s \ + {Key (Auth_ShaKey n)} \ key_sets (PriKey S) (crypts (Log -` spied s))" +by (drule pwd_owner_iii_msg, simp add: pwd_spy_iii_def split_def, + (erule conjE)+, ((rule conjI | erule key_sets_crypts_subset), blast)+) + + +fun pwd_owner_iv_state :: "agent_id \ seskey_tuple \ state" where +"pwd_owner_iv_state n (S, A, B, C, D) = (let SK = (Some S, {A, B}, {C, D}) in + insert (Owner n, SesKey SK) (pwd_spy_iii_state n (S, A, B, C, D)))" + +lemma pwd_owner_iv_rel_1: + "\n \ bad_prikey \ bad_id_shakey; pwd_spy_iii n = (s, S, A, B, C, D)\ \ + s\<^sub>0 \ fst (pwd_owner_iv n)" + (is "\_; _\ \ _ \ ?t") +by (rule rtrancl_into_rtrancl, erule pwd_spy_iii_rel, drule pwd_spy_iii_msg, + subgoal_tac "(s, ?t) \ rel_owner_iv", simp_all add: rel_def pwd_owner_iv_def + Let_def, rule exI [of _ n], rule exI [of _ S], rule exI [of _ A], rule exI [of _ B], + rule exI [of _ C], rule exI [of _ D], rule exI [of _ "Auth_ShaKey n"], auto) + +proposition pwd_owner_iv_rel: + "n \ bad_prikey \ bad_id_shakey \ s\<^sub>0 \ fst (pwd_owner_iv n)" +by (insert pwd_owner_iv_rel_1, cases "pwd_spy_iii n", simp) + +proposition pwd_owner_iv_msg: + "n \ bad_prikey \ bad_id_shakey \ + case pwd_owner_iv n of (s, S, A, B, C, D) \ + pwd_owner_iv_state n (S, A, B, C, D) \ s \ + {Key (Auth_ShaKey n)} \ key_sets (PriKey S) (crypts (Log -` spied s))" +by (drule pwd_spy_iii_msg, simp add: pwd_owner_iv_def split_def Let_def, + (erule conjE)+, ((rule conjI | erule key_sets_crypts_subset), blast)+) + + +fun pwd_spy_sep_map_state :: "agent_id \ seskey_tuple \ state" where +"pwd_spy_sep_map_state n (S, A, B, C, D) = + insert (Spy, PubKey A) (pwd_owner_iv_state n (S, A, B, C, D))" + +proposition pwd_spy_sep_map_rel: + "n \ bad_prikey \ bad_id_shakey \ s\<^sub>0 \ fst (pwd_spy_sep_map n)" + (is "_ \ _ \ ?t") +by (rule rtrancl_into_rtrancl, erule pwd_owner_iv_rel, drule pwd_owner_iv_msg, + subgoal_tac "(fst (pwd_owner_iv n), ?t) \ rel_sep", simp_all add: rel_def + pwd_spy_sep_map_def split_def, blast) + +proposition pwd_spy_sep_map_msg: + "n \ bad_prikey \ bad_id_shakey \ + case pwd_spy_sep_map n of (s, S, A, B, C, D) \ + pwd_spy_sep_map_state n (S, A, B, C, D) \ s \ + {Key (Auth_ShaKey n)} \ key_sets (PriKey S) (crypts (Log -` spied s))" +by (drule pwd_owner_iv_msg, simp add: pwd_spy_sep_map_def split_def, + (erule conjE)+, ((rule conjI | erule key_sets_crypts_subset), blast)+) + + +fun pwd_spy_sep_agr_state :: "agent_id \ seskey_tuple \ state" where +"pwd_spy_sep_agr_state n (S, A, B, C, D) = + insert (Spy, PubKey C) (pwd_spy_sep_map_state n (S, A, B, C, D))" + +proposition pwd_spy_sep_agr_rel: + "n \ bad_prikey \ bad_id_shakey \ s\<^sub>0 \ fst (pwd_spy_sep_agr n)" + (is "_ \ _ \ ?t") +by (rule rtrancl_into_rtrancl, erule pwd_spy_sep_map_rel, drule pwd_spy_sep_map_msg, + subgoal_tac "(fst (pwd_spy_sep_map n), ?t) \ rel_sep", simp_all add: rel_def + pwd_spy_sep_agr_def split_def, blast) + +proposition pwd_spy_sep_agr_msg: + "n \ bad_prikey \ bad_id_shakey \ + case pwd_spy_sep_agr n of (s, S, A, B, C, D) \ + pwd_spy_sep_agr_state n (S, A, B, C, D) \ s \ + {Key (Auth_ShaKey n)} \ key_sets (PriKey S) (crypts (Log -` spied s))" +by (drule pwd_spy_sep_map_msg, simp add: pwd_spy_sep_agr_def split_def, + (erule conjE)+, ((rule conjI | erule key_sets_crypts_subset), blast)+) + + +fun pwd_spy_sesk_state :: "agent_id \ seskey_tuple \ state" where +"pwd_spy_sesk_state n (S, A, B, C, D) = (let SK = (Some S, {A, B}, {C, D}) in + insert (Spy, SesKey SK) (pwd_spy_sep_agr_state n (S, A, B, C, D)))" + +proposition pwd_spy_sesk_rel: + "n \ bad_prikey \ bad_id_shakey \ s\<^sub>0 \ fst (pwd_spy_sesk n)" + (is "_ \ _ \ ?t") +by (rule rtrancl_into_rtrancl, erule pwd_spy_sep_agr_rel, drule pwd_spy_sep_agr_msg, + subgoal_tac "(fst (pwd_spy_sep_agr n), ?t) \ rel_sesk", simp_all add: rel_def + pwd_spy_sesk_def split_def Let_def, blast) + +proposition pwd_spy_sesk_msg: + "n \ bad_prikey \ bad_id_shakey \ + case pwd_spy_sesk n of (s, S, A, B, C, D) \ + pwd_spy_sesk_state n (S, A, B, C, D) \ s \ + {Key (Auth_ShaKey n)} \ key_sets (PriKey S) (crypts (Log -` spied s))" +by (drule pwd_spy_sep_agr_msg, simp add: pwd_spy_sesk_def split_def Let_def, + (erule conjE)+, ((rule conjI | erule key_sets_crypts_subset), blast)+) + + +fun pwd_spy_mult_state :: "agent_id \ seskey_tuple \ state" where +"pwd_spy_mult_state n (S, A, B, C, D) = + insert (Spy, Auth_PriK n \ B) (pwd_spy_sesk_state n (S, A, B, C, D))" + +proposition pwd_spy_mult_rel: + "n \ bad_prikey \ bad_id_shakey \ s\<^sub>0 \ fst (pwd_spy_mult n)" + (is "_ \ _ \ ?t") +by (rule rtrancl_into_rtrancl, erule pwd_spy_sesk_rel, drule pwd_spy_sesk_msg, + subgoal_tac "(fst (pwd_spy_sesk n), ?t) \ rel_mult", simp_all add: rel_def + pwd_spy_mult_def split_def, blast) + +proposition pwd_spy_mult_msg: + "n \ bad_prikey \ bad_id_shakey \ + case pwd_spy_mult n of (s, S, A, B, C, D) \ + pwd_spy_mult_state n (S, A, B, C, D) \ s \ + {Key (Auth_ShaKey n)} \ key_sets (PriKey S) (crypts (Log -` spied s))" +by (drule pwd_spy_sesk_msg, simp add: pwd_spy_mult_def split_def, + (erule conjE)+, ((rule conjI | erule key_sets_crypts_subset), blast)+) + + +fun pwd_spy_enc_pubk_state :: "agent_id \ seskey_tuple \ state" where +"pwd_spy_enc_pubk_state n (S, A, B, C, D) = + (let SK = (Some S, {A, B}, {C, D}) in + insert (Spy, Crypt (SesK SK) (PubKey C)) + (pwd_spy_mult_state n (S, A, B, C, D)))" + +proposition pwd_spy_enc_pubk_rel: + "n \ bad_prikey \ bad_id_shakey \ s\<^sub>0 \ fst (pwd_spy_enc_pubk n)" + (is "_ \ _ \ ?t") +by (rule rtrancl_into_rtrancl, erule pwd_spy_mult_rel, drule pwd_spy_mult_msg, + subgoal_tac "(fst (pwd_spy_mult n), ?t) \ rel_enc", simp_all add: rel_def + pwd_spy_enc_pubk_def split_def Let_def, blast) + +proposition pwd_spy_enc_pubk_msg: + "n \ bad_prikey \ bad_id_shakey \ + case pwd_spy_enc_pubk n of (s, S, A, B, C, D) \ + pwd_spy_enc_pubk_state n (S, A, B, C, D) \ s \ + {Key (Auth_ShaKey n)} \ key_sets (PriKey S) (crypts (Log -` spied s))" +by (drule pwd_spy_mult_msg, simp add: pwd_spy_enc_pubk_def split_def Let_def, + (erule conjE)+, ((rule conjI | erule key_sets_crypts_subset), blast)+) + + +fun pwd_spy_enc_mult_state :: "agent_id \ seskey_tuple \ state" where +"pwd_spy_enc_mult_state n (S, A, B, C, D) = + (let SK = (Some S, {A, B}, {C, D}) in + insert (Spy, Crypt (SesK SK) (Auth_PriK n \ B)) + (pwd_spy_enc_pubk_state n (S, A, B, C, D)))" + +proposition pwd_spy_enc_mult_rel: + "n \ bad_prikey \ bad_id_shakey \ s\<^sub>0 \ fst (pwd_spy_enc_mult n)" + (is "_ \ _ \ ?t") +by (rule rtrancl_into_rtrancl, erule pwd_spy_enc_pubk_rel, drule pwd_spy_enc_pubk_msg, + subgoal_tac "(fst (pwd_spy_enc_pubk n), ?t) \ rel_enc", simp_all add: rel_def + pwd_spy_enc_mult_def split_def Let_def, blast) + +proposition pwd_spy_enc_mult_msg: + "n \ bad_prikey \ bad_id_shakey \ + case pwd_spy_enc_mult n of (s, S, A, B, C, D) \ + pwd_spy_enc_mult_state n (S, A, B, C, D) \ s \ + {Key (Auth_ShaKey n)} \ key_sets (PriKey S) (crypts (Log -` spied s))" +by (drule pwd_spy_enc_pubk_msg, simp add: pwd_spy_enc_mult_def split_def Let_def, + (erule conjE)+, ((rule conjI | erule key_sets_crypts_subset), blast)+) + + +fun pwd_spy_enc_sign_state :: "agent_id \ seskey_tuple \ state" where +"pwd_spy_enc_sign_state n (S, A, B, C, D) = + (let SK = (Some S, {A, B}, {C, D}) in + insert (Spy, Crypt (SesK SK) (Sign n (Auth_PriK n))) + (pwd_spy_enc_mult_state n (S, A, B, C, D)))" + +proposition pwd_spy_enc_sign_rel: + "n \ bad_prikey \ bad_id_shakey \ s\<^sub>0 \ fst (pwd_spy_enc_sign n)" + (is "_ \ _ \ ?t") +by (rule rtrancl_into_rtrancl, erule pwd_spy_enc_mult_rel, drule pwd_spy_enc_mult_msg, + subgoal_tac "(fst (pwd_spy_enc_mult n), ?t) \ rel_enc", simp_all add: rel_def + pwd_spy_enc_sign_def split_def Let_def, blast) + +proposition pwd_spy_enc_sign_msg: + "n \ bad_prikey \ bad_id_shakey \ + case pwd_spy_enc_sign n of (s, S, A, B, C, D) \ + pwd_spy_enc_sign_state n (S, A, B, C, D) \ s \ + {Key (Auth_ShaKey n)} \ key_sets (PriKey S) (crypts (Log -` spied s))" +by (drule pwd_spy_enc_mult_msg, simp add: pwd_spy_enc_sign_def split_def Let_def, + (erule conjE)+, ((rule conjI | erule key_sets_crypts_subset), blast)+) + + +fun pwd_spy_con_state :: "agent_id \ seskey_tuple \ state" where +"pwd_spy_con_state n (S, A, B, C, D) = (let SK = (Some S, {A, B}, {C, D}) in + insert (Spy, \Crypt (SesK SK) (Auth_PriK n \ B), + Crypt (SesK SK) (Sign n (Auth_PriK n))\) + (pwd_spy_enc_sign_state n (S, A, B, C, D)))" + +proposition pwd_spy_con_rel: + "n \ bad_prikey \ bad_id_shakey \ s\<^sub>0 \ fst (pwd_spy_con n)" + (is "_ \ _ \ ?t") +by (rule rtrancl_into_rtrancl, erule pwd_spy_enc_sign_rel, drule pwd_spy_enc_sign_msg, + subgoal_tac "(fst (pwd_spy_enc_sign n), ?t) \ rel_con", simp_all add: rel_def + pwd_spy_con_def split_def Let_def, blast) + +proposition pwd_spy_con_msg: + "n \ bad_prikey \ bad_id_shakey \ + case pwd_spy_con n of (s, S, A, B, C, D) \ + pwd_spy_con_state n (S, A, B, C, D) \ s \ + {Key (Auth_ShaKey n)} \ key_sets (PriKey S) (crypts (Log -` spied s))" +by (drule pwd_spy_enc_sign_msg, simp add: pwd_spy_con_def split_def Let_def, + (erule conjE)+, ((rule conjI | erule key_sets_crypts_subset), blast)+) + + +fun pwd_spy_iv_state :: "agent_id \ seskey_tuple \ state" where +"pwd_spy_iv_state n (S, A, B, C, D) = (let SK = (Some S, {A, B}, {C, D}) in + insert (Spy, Token n (Auth_PriK n) B C SK) + (pwd_spy_con_state n (S, A, B, C, D)))" + +proposition pwd_spy_iv_rel: + "n \ bad_prikey \ bad_id_shakey \ s\<^sub>0 \ fst (pwd_spy_iv n)" + (is "_ \ _ \ ?t") +by (rule rtrancl_into_rtrancl, erule pwd_spy_con_rel, drule pwd_spy_con_msg, + subgoal_tac "(fst (pwd_spy_con n), ?t) \ rel_con", simp_all add: rel_def + pwd_spy_iv_def split_def Let_def, blast) + +proposition pwd_spy_iv_msg: + "n \ bad_prikey \ bad_id_shakey \ + case pwd_spy_iv n of (s, S, A, B, C, D) \ + pwd_spy_iv_state n (S, A, B, C, D) \ s \ + {Key (Auth_ShaKey n)} \ key_sets (PriKey S) (crypts (Log -` spied s))" +by (drule pwd_spy_con_msg, simp add: pwd_spy_iv_def split_def Let_def, + (erule conjE)+, ((rule conjI | erule key_sets_crypts_subset), blast)+) + + +fun pwd_owner_v_state :: "agent_id \ seskey_tuple \ state" where +"pwd_owner_v_state n (S, A, B, C, D) = (let SK = (Some S, {A, B}, {C, D}) in + insert (Spy, Crypt (SesK SK) (Pwd n)) (pwd_spy_iv_state n (S, A, B, C, D)))" + +proposition pwd_owner_v_rel: + "n \ bad_prikey \ bad_id_shakey \ s\<^sub>0 \ fst (pwd_owner_v n)" + (is "_ \ _ \ ?t") +by (rule rtrancl_into_rtrancl, erule pwd_spy_iv_rel, drule pwd_spy_iv_msg, + subgoal_tac "(fst (pwd_spy_iv n), ?t) \ rel_owner_v", simp_all add: rel_def + pwd_owner_v_def split_def Let_def, (rule exI)+, blast) + +proposition pwd_owner_v_msg: + "n \ bad_prikey \ bad_id_shakey \ + let (s, S, A, B, C, D) = pwd_owner_v n; SK = (Some S, {A, B}, {C, D}) in + pwd_owner_v_state n (S, A, B, C, D) \ s \ + {Key (Auth_ShaKey n)} \ key_sets (PriKey S) (crypts (Log -` spied s)) \ + {SesKey SK} \ key_sets (Pwd n) (crypts (Log -` spied s))" +by (drule pwd_spy_iv_msg, simp add: pwd_owner_v_def split_def Let_def, (erule conjE)+, + (rule conjI, (erule key_sets_crypts_subset)?, blast)+, simp add: Image_def, simp + only: Collect_disj_eq crypts_union key_sets_union, simp add: crypts_insert + key_sets_insert) + + +abbreviation pwd_spy_dec_state :: "agent_id \ seskey_tuple \ state" where +"pwd_spy_dec_state n x \ insert (Spy, Pwd n) (pwd_owner_v_state n x)" + +proposition pwd_spy_dec_rel: + "n \ bad_prikey \ bad_id_shakey \ s\<^sub>0 \ fst (pwd_spy_dec n)" + (is "_ \ _ \ ?t") +by (rule rtrancl_into_rtrancl, erule pwd_owner_v_rel, drule pwd_owner_v_msg, + subgoal_tac "(fst (pwd_owner_v n), ?t) \ rel_dec", simp_all add: rel_def + pwd_spy_dec_def split_def Let_def, (rule exI)+, auto) + +proposition pwd_spy_dec_msg: + "n \ bad_prikey \ bad_id_shakey \ + let (s, S, A, B, C, D) = pwd_spy_dec n; SK = (Some S, {A, B}, {C, D}) in + pwd_spy_dec_state n (S, A, B, C, D) \ s \ + {Key (Auth_ShaKey n)} \ key_sets (PriKey S) (crypts (Log -` spied s)) \ + {SesKey SK} \ key_sets (Pwd n) (crypts (Log -` spied s))" +by (drule pwd_owner_v_msg, simp add: pwd_spy_dec_def split_def Let_def, + (erule conjE)+, ((rule conjI)?, (erule key_sets_crypts_subset)?, blast)+) + + +fun pwd_spy_id_prik_state :: "agent_id \ seskey_tuple \ state" where +"pwd_spy_id_prik_state n (S, A, B, C, D) = + insert (Spy, \n, PriKey S\) (pwd_spy_dec_state n (S, A, B, C, D))" + +proposition pwd_spy_id_prik_rel: + "n \ bad_prikey \ bad_id_shakey \ s\<^sub>0 \ fst (pwd_spy_id_prik n)" + (is "_ \ _ \ ?t") +by (rule rtrancl_into_rtrancl, erule pwd_spy_dec_rel, drule pwd_spy_dec_msg, + subgoal_tac "(fst (pwd_spy_dec n), ?t) \ rel_id_crypt", simp_all add: rel_def + pwd_spy_id_prik_def split_def Let_def, (rule exI)+, blast) + +proposition pwd_spy_id_prik_msg: + "n \ bad_prikey \ bad_id_shakey \ + let (s, S, A, B, C, D) = pwd_spy_id_prik n; + SK = (Some S, {A, B}, {C, D}) in + pwd_spy_id_prik_state n (S, A, B, C, D) \ s \ + {SesKey SK} \ key_sets (Pwd n) (crypts (Log -` spied s))" +by (drule pwd_spy_dec_msg, simp add: pwd_spy_id_prik_def split_def Let_def, + (erule conjE)+, ((rule conjI | erule key_sets_crypts_subset), blast)+) + + +fun pwd_spy_id_pubk_state :: "agent_id \ seskey_tuple \ state" where +"pwd_spy_id_pubk_state n (S, A, B, C, D) = + insert (Spy, \n, PubKey S\) (pwd_spy_id_prik_state n (S, A, B, C, D))" + +proposition pwd_spy_id_pubk_rel: + "n \ bad_prikey \ bad_id_shakey \ s\<^sub>0 \ fst (pwd_spy_id_pubk n)" + (is "_ \ _ \ ?t") +by (rule rtrancl_into_rtrancl, erule pwd_spy_id_prik_rel, drule pwd_spy_id_prik_msg, + subgoal_tac "(fst (pwd_spy_id_prik n), ?t) \ rel_id_invk", simp_all add: rel_def + pwd_spy_id_pubk_def split_def Let_def, (rule exI)+, auto) + +proposition pwd_spy_id_pubk_msg: + "n \ bad_prikey \ bad_id_shakey \ + let (s, S, A, B, C, D) = pwd_spy_id_pubk n; + SK = (Some S, {A, B}, {C, D}) in + pwd_spy_id_pubk_state n (S, A, B, C, D) \ s \ + {SesKey SK} \ key_sets (Pwd n) (crypts (Log -` spied s))" +by (drule pwd_spy_id_prik_msg, simp add: pwd_spy_id_pubk_def split_def Let_def, + (erule conjE)+, ((rule conjI | erule key_sets_crypts_subset), blast)+) + + +fun pwd_spy_id_sesk_state :: "agent_id \ seskey_tuple \ state" where +"pwd_spy_id_sesk_state n (S, A, B, C, D) = + (let SK = (Some S, {A, B}, {C, D}) in + insert (Spy, \n, SesKey SK\) (pwd_spy_id_pubk_state n (S, A, B, C, D)))" + +proposition pwd_spy_id_sesk_rel: + "n \ bad_prikey \ bad_id_shakey \ s\<^sub>0 \ fst (pwd_spy_id_sesk n)" + (is "_ \ _ \ ?t") +by (rule rtrancl_into_rtrancl, erule pwd_spy_id_pubk_rel, drule pwd_spy_id_pubk_msg, + subgoal_tac "(fst (pwd_spy_id_pubk n), ?t) \ rel_id_sesk", simp_all add: rel_def + pwd_spy_id_sesk_def split_def Let_def, rule exI, rule exI, rule exI + [of _ "Some (fst (snd (pwd_spy_id_pubk n)))"], auto) + +proposition pwd_spy_id_sesk_msg: + "n \ bad_prikey \ bad_id_shakey \ + let (s, S, A, B, C, D) = pwd_spy_id_sesk n; + SK = (Some S, {A, B}, {C, D}) in + pwd_spy_id_sesk_state n (S, A, B, C, D) \ s \ + {SesKey SK} \ key_sets (Pwd n) (crypts (Log -` spied s))" +by (drule pwd_spy_id_pubk_msg, simp add: pwd_spy_id_sesk_def split_def Let_def, + (erule conjE)+, ((rule conjI | erule key_sets_crypts_subset), blast)+) + + +abbreviation pwd_spy_id_pwd_state :: "agent_id \ seskey_tuple \ state" where +"pwd_spy_id_pwd_state n x \ insert (Spy, \n, Pwd n\) (pwd_spy_id_sesk_state n x)" + +proposition pwd_spy_id_pwd_rel: + "n \ bad_prikey \ bad_id_shakey \ s\<^sub>0 \ fst (pwd_spy_id_pwd n)" + (is "_ \ _ \ ?t") +by (rule rtrancl_into_rtrancl, erule pwd_spy_id_sesk_rel, drule pwd_spy_id_sesk_msg, + subgoal_tac "(fst (pwd_spy_id_sesk n), ?t) \ rel_id_crypt", simp_all add: rel_def + pwd_spy_id_pwd_def split_def Let_def, (rule exI)+, blast) + +proposition pwd_spy_id_pwd_msg: + "n \ bad_prikey \ bad_id_shakey \ + case pwd_spy_id_pwd n of (s, S, A, B, C, D) \ + pwd_spy_id_pwd_state n (S, A, B, C, D) \ s" +by (drule pwd_spy_id_sesk_msg, simp add: pwd_spy_id_pwd_def split_def Let_def, + blast) + + +theorem pwd_compromised: + "n \ bad_prikey \ bad_id_shakey \ \s. s\<^sub>0 \ s \ {Pwd n, \n, Pwd n\} \ spied s" +by (rule exI [of _ "fst (pwd_spy_id_pwd n)"], rule conjI, erule pwd_spy_id_pwd_rel, + drule pwd_spy_id_pwd_msg, simp add: split_def) + + +end diff --git a/thys/Relational_Method/ROOT b/thys/Relational_Method/ROOT new file mode 100644 --- /dev/null +++ b/thys/Relational_Method/ROOT @@ -0,0 +1,13 @@ +chapter AFP + +session Relational_Method (AFP) = "HOL" + + description \The Relational Method with Message Anonymity for the Verification of Cryptographic Protocols\ + options [timeout = 300] + theories + Definitions + Authentication + Anonymity + Possibility + document_files + "root.bib" + "root.tex" diff --git a/thys/Relational_Method/document/root.bib b/thys/Relational_Method/document/root.bib new file mode 100644 --- /dev/null +++ b/thys/Relational_Method/document/root.bib @@ -0,0 +1,59 @@ +@article { + Paulson98, + author = {Lawrence C. Paulson}, + title = {The Inductive Approach to Verifying Cryptographic Protocols}, + journal = {Journal of Computer Security}, + month = dec, + year = 1998 +} + +@article { + Noce17, + author = {Pasquale Noce}, + title = {Verification of a Diffie-Hellman Password-based Authentication Protocol by Extending the Inductive Method}, + journal = {Archive of Formal Proofs}, + month = jan, + year = 2017, + note = {\url{http://isa-afp.org/entries/Password_Authentication_Protocol.html}, Formal proof development}, + ISSN = {2150-914x} +} + +@manual { + ICAO15, + title = {Doc 9303 -- Machine Readable Travel Documents -- Part 11: Security Mechanisms for MRTDs}, + organization = {International Civil Aviation Organization (ICAO)}, + edition = {7th}, + year = 2015 +} + +@manual{ + Paulson20, + author = {Tobias Nipkow and Lawrence C. Paulson and Markus Wenzel}, + title = {Isabelle/HOL -- A Proof Assistant for Higher-Order Logic}, + month = apr, + year = 2020, + note = {\url{https://isabelle.in.tum.de/website-Isabelle2020/dist/Isabelle2020/doc/tutorial.pdf}} +} + +@manual{ + Nipkow20, + author = {Tobias Nipkow}, + title = {Programming and Proving in Isabelle/HOL}, + month = apr, + year = 2020, + note = {\url{https://isabelle.in.tum.de/website-Isabelle2020/dist/Isabelle2020/doc/prog-prove.pdf}} +} + +@manual{ + Krauss20, + author = {Alexander Krauss}, + title = {Defining Recursive Functions in Isabelle/HOL}, + note = {\url{https://isabelle.in.tum.de/website-Isabelle2020/dist/Isabelle2020/doc/functions.pdf}} +} + +@manual{ + Nipkow11, + author = {Tobias Nipkow}, + title = {A Tutorial Introduction to Structured Isar Proofs}, + note = {\url{https://isabelle.in.tum.de/website-Isabelle2011/dist/Isabelle2011/doc/isar-overview.pdf}} +} diff --git a/thys/Relational_Method/document/root.tex b/thys/Relational_Method/document/root.tex new file mode 100644 --- /dev/null +++ b/thys/Relational_Method/document/root.tex @@ -0,0 +1,68 @@ +\documentclass[11pt,a4paper,fleqn]{article} +\usepackage{isabelle,isabellesym} +\renewcommand{\isastyletxt}{\isastyletext} + +% further packages required for unusual symbols (see also +% isabellesym.sty), use only when needed + +%\usepackage{amssymb} + %for \, \, \, \, \, \, + %\, \, \, \, \, + %\, \, \ + +%\usepackage{eurosym} + %for \ + +%\usepackage[only,bigsqcap]{stmaryrd} + %for \ + +%\usepackage{eufrak} + %for \ ... \, \ ... \ (also included in amssymb) + +%\usepackage{textcomp} + %for \, \, \, \, \, + %\ + +% this should be the last package used +\usepackage{pdfsetup} + +% urls in roman style, theory text in math-similar italics +\urlstyle{rm} +\isabellestyle{it} + +% for uniform font size +%\renewcommand{\isastyle}{\isastyleminor} + + +\begin{document} + +\title{The Relational Method with Message Anonymity\\for the Verification of Cryptographic Protocols} +\author{Pasquale Noce\\Software Engineer at HID Global, Italy\\pasquale dot noce dot lavoro at gmail dot com\\pasquale dot noce at hidglobal dot com} +\maketitle + +\begin{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. +\end{abstract} + +\tableofcontents + +% sane default for proof documents +\parindent 0pt\parskip 0.5ex + +% generated text of all theories +\input{session} + +% bibliography +\bibliographystyle{abbrv} +\bibliography{root} + +\end{document} diff --git a/thys/Relational_Minimum_Spanning_Trees/Boruvka.thy b/thys/Relational_Minimum_Spanning_Trees/Boruvka.thy new file mode 100644 --- /dev/null +++ b/thys/Relational_Minimum_Spanning_Trees/Boruvka.thy @@ -0,0 +1,3620 @@ +(* Title: Borůvka's Minimum Spanning Tree Algorithm + Author: Nicolas Robinson-O'Brien + Maintainer: Walter Guttmann +*) + +section \Bor\r{u}vka's Minimum Spanning Tree Algorithm\ + +text \ +In this theory we prove partial correctness of Bor\r{u}vka's minimum spanning tree algorithm. +\ + +theory Boruvka + +imports + Relational_Disjoint_Set_Forests.Disjoint_Set_Forests + Kruskal + +begin + +subsection \General results\ + +text \ +The proof is carried out in $m$-$k$-Stone-Kleene relation algebras. +In this section we give results that hold more generally. +\ + +context stone_kleene_relation_algebra +begin + +definition "big_forest H d \ + equivalence H + \ d \ -H + \ univalent (H * d) + \ H \ d * d\<^sup>T \ 1 + \ (H * d)\<^sup>+ \ - H" + +definition "bf_between_points p q H d \ point p \ point q \ p \ (H * d)\<^sup>\ * H * d" + +definition "bf_between_arcs a b H d \ arc a \ arc b \ a\<^sup>T * top \ (H * d)\<^sup>\ * H * b * top" + +text \Theorem 3\ + +lemma He_eq_He_THe_star: + assumes "arc e" + and "equivalence H" + shows "H * e = H * e * (top * H * e)\<^sup>\" +proof - + let ?x = "H * e" + have 1: "H * e \ H * e * (top * H * e)\<^sup>\" + using comp_isotone star.circ_reflexive by fastforce + have "H * e * (top * H * e)\<^sup>\ = H * e * (top * e)\<^sup>\" + by (metis assms(2) preorder_idempotent surjective_var) + also have "... \ H * e * (1 \ top * (e * top)\<^sup>\ * e)" + by (metis eq_refl star.circ_mult_1) + also have "... \ H * e * (1 \ top * top * e)" + by (simp add: star.circ_left_top) + also have "... = H * e \ H * e * top * e" + by (simp add: mult.semigroup_axioms semiring.distrib_left semigroup.assoc) + finally have 2: "H * e * (top * H * e)\<^sup>\ \ H * e" + using assms arc_top_arc mult_assoc by auto + thus ?thesis + using 1 2 by simp +qed + +lemma path_through_components: + assumes "equivalence H" + and "arc e" + shows "(H * (d \ e))\<^sup>\ = (H * d)\<^sup>\ \ (H * d)\<^sup>\ * H * e * (H * d)\<^sup>\" +proof - + have "H * e * (H * d)\<^sup>\ * H * e \ H * e * top * H * e" + by (simp add: comp_isotone) + also have "... = H * e * top * e" + by (metis assms(1) preorder_idempotent surjective_var mult_assoc) + also have "... = H * e" + using assms(2) arc_top_arc mult_assoc by auto + finally have 1: "H * e * (H * d)\<^sup>\ * H * e \ H * e" + by simp + have "(H * (d \ e))\<^sup>\ = (H * d \ H * e)\<^sup>\" + by (simp add: comp_left_dist_sup) + also have "... = (H * d)\<^sup>\ \ (H * d)\<^sup>\ * H * e * (H * d)\<^sup>\" + using 1 star_separate_3 by (simp add: mult_assoc) + finally show ?thesis + by simp +qed + +lemma simplify_f: + assumes "regular p" + and "regular e" + shows "(f \ - e\<^sup>T \ - p) \ (f \ - e\<^sup>T \ p) \ (f \ - e\<^sup>T \ p)\<^sup>T \ (f \ - e\<^sup>T \ - p)\<^sup>T \ e\<^sup>T \ e = f \ f\<^sup>T \ e \ e\<^sup>T" +proof - + have "(f \ - e\<^sup>T \ - p) \ (f \ - e\<^sup>T \ p) \ (f \ - e\<^sup>T \ p)\<^sup>T \ (f \ - e\<^sup>T \ - p)\<^sup>T \ e\<^sup>T \ e + = (f \ - e\<^sup>T \ - p) \ (f \ - e\<^sup>T \ p) \ (f\<^sup>T \ - e \ p\<^sup>T) \ (f\<^sup>T \ - e \ - p\<^sup>T) \ e\<^sup>T \ e" + by (simp add: conv_complement conv_dist_inf) + also have "... = + ((f \ (f \ - e\<^sup>T \ p)) \ (- e\<^sup>T \ (f \ - e\<^sup>T \ p)) \ (- p \ (f \ - e\<^sup>T \ p))) + \ ((f\<^sup>T \ (f\<^sup>T \ - e \ - p\<^sup>T)) \ (- e \ (f\<^sup>T \ - e \ - p\<^sup>T)) \ (p\<^sup>T \ (f\<^sup>T \ - e \ - p\<^sup>T))) + \ e\<^sup>T \ e" + by (metis sup_inf_distrib2 sup_assoc) + also have "... = + ((f \ f) \ (f \ - e\<^sup>T) \ (f \ p) \ (- e\<^sup>T \ f) \ (- e\<^sup>T \ - e\<^sup>T) \ (- e\<^sup>T \ p) \ (- p \ f) \ (- p \ - e\<^sup>T) \ (- p \ p)) + \ ((f\<^sup>T \ f\<^sup>T) \ (f\<^sup>T \ - e) \ (f\<^sup>T \ - p\<^sup>T) \ (- e \ f\<^sup>T) \ (- e \ - e) \ (- e \ - p\<^sup>T) \ (p\<^sup>T \ f\<^sup>T) \ (p\<^sup>T \ - e) \ (p\<^sup>T \ - p\<^sup>T)) + \ e\<^sup>T \ e" + using sup_inf_distrib1 sup_assoc inf_assoc sup_inf_distrib1 by simp + also have "... = + ((f \ f) \ (f \ - e\<^sup>T) \ (f \ p) \ (f \ - p) \ (- e\<^sup>T \ f) \ (- e\<^sup>T \ - e\<^sup>T) \ (- e\<^sup>T \ p) \ (- e\<^sup>T \ - p) \ (- p \ p)) + \ ((f\<^sup>T \ f\<^sup>T) \ (f\<^sup>T \ - e) \ (f\<^sup>T \ - p\<^sup>T) \ (- e \ f\<^sup>T) \ (f\<^sup>T \ p\<^sup>T) \ (- e \ - e) \ (- e \ - p\<^sup>T) \ (- e \ p\<^sup>T) \ (p\<^sup>T \ - p\<^sup>T)) + \ e\<^sup>T \ e" + by (smt abel_semigroup.commute inf.abel_semigroup_axioms inf.left_commute sup.abel_semigroup_axioms) + also have "... = (f \ - e\<^sup>T \ (- p \ p)) \ (f\<^sup>T \ - e \ (p\<^sup>T \ - p\<^sup>T)) \ e\<^sup>T \ e" + by (smt inf.sup_monoid.add_assoc inf.sup_monoid.add_commute inf_sup_absorb sup.idem) + also have "... = (f \ - e\<^sup>T) \ (f\<^sup>T \ - e) \ e\<^sup>T \ e" + by (metis assms(1) conv_complement inf_top_right stone) + also have "... = (f \ e\<^sup>T) \ (- e\<^sup>T \ e\<^sup>T) \ (f\<^sup>T \ e) \ (- e \ e)" + by (metis sup.left_commute sup_assoc sup_inf_distrib2) + finally show ?thesis + by (metis abel_semigroup.commute assms(2) conv_complement inf_top_right stone sup.abel_semigroup_axioms sup_assoc) +qed + +lemma simplify_forest_components_f: + assumes "regular p" + and "regular e" + and "injective (f \ - e\<^sup>T \ - p \ (f \ - e\<^sup>T \ p)\<^sup>T \ e)" + and "injective f" + shows "forest_components ((f \ - e\<^sup>T \ - p) \ (f \ -e\<^sup>T \ p)\<^sup>T \ e) = (f \ f\<^sup>T \ e \ e\<^sup>T)\<^sup>\" +proof - + have "forest_components ((f \ - e\<^sup>T \ - p) \ (f \ -e\<^sup>T \ p)\<^sup>T \ e) = wcc ((f \ - e\<^sup>T \ - p) \ (f \ - e\<^sup>T \ p)\<^sup>T \ e)" + by (simp add: assms(3) forest_components_wcc) + also have "... = ((f \ - e\<^sup>T \ - p) \ (f \ - e\<^sup>T \ p)\<^sup>T \ e \ (f \ - e\<^sup>T \ - p)\<^sup>T \ (f \ - e\<^sup>T \ p) \ e\<^sup>T)\<^sup>\" + using conv_dist_sup sup_assoc by auto + also have "... = ((f \ - e\<^sup>T \ - p) \ (f \ - e\<^sup>T \ p) \ (f \ - e\<^sup>T \ p)\<^sup>T \ (f \ - e\<^sup>T \ - p)\<^sup>T \ e\<^sup>T \ e)\<^sup>\" + using sup_assoc sup_commute by auto + also have "... = (f \ f\<^sup>T \ e \ e\<^sup>T)\<^sup>\" + using assms(1, 2, 3, 4) simplify_f by auto + finally show ?thesis + by simp +qed + +lemma components_disj_increasing: + assumes "regular p" + and "regular e" + and "injective (f \ - e\<^sup>T \ - p \ (f \ - e\<^sup>T \ p)\<^sup>T \ e)" + and "injective f" + shows "forest_components f \ forest_components (f \ - e\<^sup>T \ - p \ (f \ - e\<^sup>T \ p)\<^sup>T \ e)" +proof - + have 1: "forest_components ((f \ - e\<^sup>T \ - p) \ (f \ -e\<^sup>T \ p)\<^sup>T \ e) = (f \ f\<^sup>T \ e \ e\<^sup>T)\<^sup>\" + using simplify_forest_components_f assms(1, 2, 3, 4) by blast + have "forest_components f = wcc f" + by (simp add: assms(4) forest_components_wcc) + also have "... \ (f \ f\<^sup>T \ e\<^sup>T \ e)\<^sup>\" + by (simp add: le_supI2 star_isotone sup_commute) + finally show ?thesis + using 1 sup.left_commute sup_commute by simp +qed + +lemma fch_equivalence: + assumes "forest h" + shows "equivalence (forest_components h)" + by (simp add: assms forest_components_equivalence) + +lemma big_forest_path_split_1: + assumes "arc a" + and "equivalence H" + shows "(H * d)\<^sup>\ * H * a * top = (H * (d \ - a))\<^sup>\ * H * a * top" +proof - + let ?H = "H" + let ?x = "?H * (d \ -a)" + let ?y = "?H * a" + let ?a = "?H * a * top" + let ?d = "?H * d" + have 1: "?d\<^sup>\ * ?a \ ?x\<^sup>\ * ?a" + proof - + have "?x\<^sup>\ *?y * ?x\<^sup>\ * ?a \ ?x\<^sup>\ * ?a * ?a" + by (smt mult_left_isotone star.circ_right_top top_right_mult_increasing mult_assoc) + also have "... = ?x\<^sup>\ * ?a * a * top" + by (metis ex231e mult_assoc) + also have "... = ?x\<^sup>\ * ?a" + by (simp add: assms(1) mult_assoc) + finally have 11: "?x\<^sup>\ *?y * ?x\<^sup>\ * ?a \ ?x\<^sup>\ * ?a" + by simp + have "?d\<^sup>\ * ?a = (?H * (d \ a) \ ?H * (d \ -a))\<^sup>\ * ?a" + proof - + have 12: "regular a" + using assms(1) arc_regular by simp + have "?H * ((d \ a) \ (d \ - a)) = ?H * (d \ top)" + using 12 by (metis inf_top_right maddux_3_11_pp) + thus ?thesis + using mult_left_dist_sup by auto + qed + also have "... \ (?y \ ?x)\<^sup>\ * ?a" + by (metis comp_inf.coreflexive_idempotent comp_isotone inf.cobounded1 inf.sup_monoid.add_commute semiring.add_mono star_isotone top.extremum) + also have "... = (?x \ ?y)\<^sup>\ * ?a" + by (simp add: sup_commute mult_assoc) + also have "... = ?x\<^sup>\ * ?a \ (?x\<^sup>\ * ?y * (?x\<^sup>\ * ?y)\<^sup>\ * ?x\<^sup>\) * ?a" + by (smt mult_right_dist_sup star.circ_sup_9 star.circ_unfold_sum mult_assoc) + also have "... \ ?x\<^sup>\ * ?a \ (?x\<^sup>\ * ?y * (top * ?y)\<^sup>\ * ?x\<^sup>\) * ?a" + proof - + have "(?x\<^sup>\ * ?y)\<^sup>\ \ (top * ?y)\<^sup>\" + by (simp add: mult_left_isotone star_isotone) + thus ?thesis + by (metis comp_inf.coreflexive_idempotent comp_inf.transitive_star eq_refl mult_left_dist_sup top.extremum mult_assoc) + qed + also have "... = ?x\<^sup>\ * ?a \ (?x\<^sup>\ * ?y * ?x\<^sup>\) * ?a" + using assms(1, 2) He_eq_He_THe_star arc_regular mult_assoc by auto + finally have 13: "(?H * d)\<^sup>\ * ?a \ ?x\<^sup>\ * ?a \ ?x\<^sup>\ * ?y * ?x\<^sup>\ * ?a" + by (simp add: mult_assoc) + have 14: "?x\<^sup>\ * ?y * ?x\<^sup>\ * ?a \ ?x\<^sup>\ * ?a" + using 11 mult_assoc by auto + thus ?thesis + using 13 14 sup.absorb1 by auto + qed + have 2: "?d\<^sup>\ * ?a \ ?x\<^sup>\ *?a" + by (simp add: comp_isotone star_isotone) + thus ?thesis + using 1 2 antisym mult_assoc by simp +qed + +lemma dTransHd_le_1: + assumes "equivalence H" + and "univalent (H * d)" + shows "d\<^sup>T * H * d \ 1" +proof - + have "d\<^sup>T * H\<^sup>T * H * d \ 1" + using assms(2) conv_dist_comp mult_assoc by auto + thus ?thesis + using assms(1) mult_assoc by (simp add: preorder_idempotent) +qed + +lemma HcompaT_le_compHaT: + assumes "equivalence H" + and "injective (a * top)" + shows "-H * a * top \ - (H * a * top)" +proof - + have "a * top * a\<^sup>T \ 1" + by (metis assms(2) conv_dist_comp symmetric_top_closed vector_top_closed mult_assoc) + hence "a * top * a\<^sup>T * H \ H" + using assms(1) comp_isotone order_trans by blast + hence "a * top * top * a\<^sup>T * H \ H" + by (simp add: vector_mult_closed) + hence "a * top * (H * a * top)\<^sup>T \ H" + by (metis assms(1) conv_dist_comp symmetric_top_closed vector_top_closed mult_assoc) + thus ?thesis + using assms(2) comp_injective_below_complement mult_assoc by auto +qed + +text \Theorem 4\ + +lemma expand_big_forest: + assumes "big_forest H d" + shows "(d\<^sup>T * H)\<^sup>\ * (H * d)\<^sup>\ = (d\<^sup>T * H)\<^sup>\ \ (H * d)\<^sup>\" +proof - + have "(H * d)\<^sup>T * H * d \ 1" + using assms big_forest_def mult_assoc by auto + hence "d\<^sup>T * H * H * d \ 1" + using assms big_forest_def conv_dist_comp by auto + thus ?thesis + by (simp add: cancel_separate_eq comp_associative) +qed + + +lemma big_forest_path_bot: + assumes "arc a" + and "a \ d" + and "big_forest H d" + shows "(d \ - a)\<^sup>T * (H * a * top) \ bot" +proof - + have 1: "d\<^sup>T * H * d \ 1" + using assms(3) big_forest_def dTransHd_le_1 by blast + hence "d * - 1 * d\<^sup>T \ - H" + using triple_schroeder_p by force + hence "d * - 1 * d\<^sup>T \ 1 \ - H" + by (simp add: le_supI2) + hence "d * d\<^sup>T \ d * - 1 * d\<^sup>T \ 1 \ - H" + by (metis assms(3) big_forest_def inf_commute regular_one_closed shunting_p le_supI) + hence "d * 1 * d\<^sup>T \ d * - 1 * d\<^sup>T \ 1 \ - H" + by simp + hence "d * (1 \ - 1) * d\<^sup>T \ 1 \ - H" + using comp_associative mult_right_dist_sup by (simp add: mult_left_dist_sup) + hence "d * top * d\<^sup>T \ 1 \ - H" + using regular_complement_top by auto + hence "d * top * a\<^sup>T \ 1 \ - H" + using assms(2) conv_isotone dual_order.trans mult_right_isotone by blast + hence "d * (a * top)\<^sup>T \ 1 \ - H" + by (simp add: comp_associative conv_dist_comp) + hence "d \ (1 \ - H) * (a * top)" + by (simp add: assms(1) shunt_bijective) + hence "d \ a * top \ - H * a * top" + by (simp add: comp_associative mult_right_dist_sup) + also have "... \ a * top \ - (H * a * top)" + using assms(1, 3) HcompaT_le_compHaT big_forest_def sup_right_isotone by auto + finally have "d \ a * top \ - (H * a * top)" + by simp + hence "d \ --( H * a * top) \ a * top" + using shunting_var_p by auto + hence 2:"d \ H * a * top \ a * top" + using inf.sup_right_isotone order.trans pp_increasing by blast + have 3:"d \ H * a * top \ top * a" + proof - + have "d \ H * a * top \ (H * a \ d * top\<^sup>T) * (top \ (H * a)\<^sup>T * d)" + by (metis dedekind inf_commute) + also have "... = d * top \ H * a * a\<^sup>T * H\<^sup>T * d" + by (simp add: conv_dist_comp inf_vector_comp mult_assoc) + also have "... \ d * top \ H * a * d\<^sup>T * H\<^sup>T * d" + using assms(2) mult_right_isotone mult_left_isotone conv_isotone inf.sup_right_isotone by auto + also have "... = d * top \ H * a * d\<^sup>T * H * d" + using assms(3) big_forest_def by auto + also have "... \ d * top \ H * a * 1" + using 1 by (metis inf.sup_right_isotone mult_right_isotone mult_assoc) + also have "... \ H * a" + by simp + also have "... \ top * a" + by (simp add: mult_left_isotone) + finally have "d \ H * a * top \ top * a" + by simp + thus ?thesis + by simp + qed + have "d \ H * a * top \ a * top \ top * a" + using 2 3 by simp + also have "... = a * top * top * a" + by (metis comp_associative comp_inf.star.circ_decompose_9 comp_inf.star_star_absorb comp_inf_covector vector_inf_comp vector_top_closed) + also have "... = a * top * a" + by (simp add: vector_mult_closed) + finally have 4:"d \ H * a * top \ a" + by (simp add: assms(1) arc_top_arc) + hence "d \ - a \ -(H * a * top)" + using assms(1) arc_regular p_shunting_swap by fastforce + hence "(d \ - a) * top \ -(H * a * top)" + using mult.semigroup_axioms p_antitone_iff schroeder_4_p semigroup.assoc by fastforce + thus ?thesis + by (simp add: schroeder_3_p) +qed + +lemma big_forest_path_split_2: + assumes "arc a" + and "a \ d" + and "big_forest H d" + shows "(H * (d \ - a))\<^sup>\ * H * a * top = (H * ((d \ - a) \ (d \ - a)\<^sup>T))\<^sup>\ * H * a * top" +proof - + let ?lhs = "(H * (d \ - a))\<^sup>\ * H * a * top" + have 1: "d\<^sup>T * H * d \ 1" + using assms(3) big_forest_def dTransHd_le_1 by blast + have 2: "H * a * top \ ?lhs" + by (metis le_iff_sup star.circ_loop_fixpoint star.circ_transitive_equal star_involutive sup_commute mult_assoc) + have "(d \ - a)\<^sup>T * (H * (d \ - a))\<^sup>\ * (H * a * top) = (d \ - a)\<^sup>T * H * (d \ - a) * (H * (d \ - a))\<^sup>\ * (H * a * top)" + proof - + have "(d \ - a)\<^sup>T * (H * (d \ - a))\<^sup>\ * (H * a * top) = (d \ - a)\<^sup>T * (1 \ H * (d \ - a) * (H * (d \ - a))\<^sup>\) * (H * a * top)" + by (simp add: star_left_unfold_equal) + also have "... = (d \ - a)\<^sup>T * H * a * top \ (d \ - a)\<^sup>T * H * (d \ - a) * (H * (d \ - a))\<^sup>\ * (H * a * top)" + by (smt mult_left_dist_sup star.circ_loop_fixpoint star.circ_mult_1 star_slide sup_commute mult_assoc) + also have "... = bot \ (d \ - a)\<^sup>T * H * (d \ - a) * (H * (d \ - a))\<^sup>\ * (H * a * top)" + by (metis assms(1, 2, 3) big_forest_path_bot mult_assoc le_bot) + thus ?thesis + by (simp add: calculation) + qed + also have "... \ d\<^sup>T * H * d * (H * (d \ - a))\<^sup>\ * (H * a * top)" + using conv_isotone inf.cobounded1 mult_isotone by auto + also have "... \ 1 * (H * (d \ - a))\<^sup>\ * (H * a * top)" + using 1 by (metis le_iff_sup mult_right_dist_sup) + finally have 3: "(d \ - a)\<^sup>T * (H * (d \ - a))\<^sup>\ * (H * a * top) \ ?lhs" + using mult_assoc by auto + hence 4: "H * (d \ - a)\<^sup>T * (H * (d \ - a))\<^sup>\ * (H * a * top) \ ?lhs" + proof - + have "H * (d \ - a)\<^sup>T * (H * (d \ - a))\<^sup>\ * (H * a * top) \ H * (H * (d \ - a))\<^sup>\ * H * a * top" + using 3 mult_right_isotone mult_assoc by auto + also have "... = H * H * ((d \ - a) * H)\<^sup>\ * H * a * top" + by (metis assms(3) big_forest_def star_slide mult_assoc preorder_idempotent) + also have "... = H * ((d \ - a) * H)\<^sup>\ * H * a * top" + using assms(3) big_forest_def preorder_idempotent by fastforce + finally show ?thesis + by (metis assms(3) big_forest_def preorder_idempotent star_slide mult_assoc) + qed + have 5: "(H * (d \ - a) \ H * (d \ - a)\<^sup>T) * (H * (d \ - a))\<^sup>\ * H * a * top \ ?lhs" + proof - + have 51: "H * (d \ - a) * (H * (d \ - a))\<^sup>\ * H * a * top \ (H * (d \ - a))\<^sup>\ * H * a * top" + using star.left_plus_below_circ mult_left_isotone by simp + have 52: "(H * (d \ - a) \ H * (d \ - a)\<^sup>T) * (H * (d \ - a))\<^sup>\ * H * a * top = H * (d \ - a) * (H * (d \ - a))\<^sup>\ * H * a * top \ H * (d \ - a)\<^sup>T * (H * (d \ - a))\<^sup>\ * H * a * top" + using mult_right_dist_sup by auto + hence "... \ (H * (d \ - a))\<^sup>\ * H * a * top \ H * (d \ - a)\<^sup>T * (H * (d \ - a))\<^sup>\ * H * a * top" + using star.left_plus_below_circ mult_left_isotone sup_left_isotone by auto + thus ?thesis + using 4 51 52 mult_assoc by auto + qed + hence "(H * (d \ - a) \ H * (d \ - a)\<^sup>T)\<^sup>\ * H * a * top \ ?lhs" + proof - + have "(H * (d \ - a) \ H * (d \ - a)\<^sup>T)\<^sup>\ * (H * (d \ - a))\<^sup>\ * H * a * top \ ?lhs" + using 5 star_left_induct_mult_iff mult_assoc by auto + thus ?thesis + using star.circ_decompose_11 star_decompose_1 by auto + qed + hence 6: "(H * ((d \ - a) \ (d \ - a)\<^sup>T))\<^sup>\ * H * a * top \ ?lhs" + using mult_left_dist_sup by auto + have 7: "(H * (d \ - a))\<^sup>\ * H * a * top \ (H * ((d \ - a) \ (d \ - a)\<^sup>T))\<^sup>\ * H * a * top" + by (simp add: mult_left_isotone semiring.distrib_left star_isotone) + thus ?thesis + using 6 7 by (simp add: mult_assoc) +qed + +end + +subsection \An operation to select components\ + +text \ +We introduce the operation \choose_component\. +\begin{itemize} +\item Axiom \component_in_v\ expresses that the result of \choose_component\ is contained in the set of vertices, $v$, we are selecting from, ignoring the weights. +\item Axiom \component_is_vector\ states that the result of \choose_component\ is a vector. +\item Axiom \component_is_regular\ states that the result of \choose_component\ is regular. +\item Axiom \component_is_connected\ states that any two vertices from the result of \choose_component\ are connected in $e$. +\item Axiom \component_single\ states that the result of \choose_component\ is closed under being connected in $e$. +\item Finally, axiom \component_not_bot_when_v_bot_bot\ expresses that the operation \choose_component\ returns a non-empty component if the input satisfies the given criteria. +\end{itemize} +\ + +class choose_component = + fixes choose_component :: "'a \ 'a \ 'a" + +class choose_component_algebra = choose_component + stone_relation_algebra + + assumes component_in_v: "choose_component e v \ --v" + assumes component_is_vector: "vector (choose_component e v)" + assumes component_is_regular: "regular (choose_component e v)" + assumes component_is_connected: "choose_component e v * (choose_component e v)\<^sup>T \ e" + assumes component_single: "choose_component e v = e * choose_component e v" + assumes component_not_bot_when_v_bot_bot: " + regular e + \ equivalence e + \ vector v + \ regular v + \ e * v = v + \ v \ bot \ choose_component e v \ bot" + +text \Theorem 1\ + +text \ +Every \m_kleene_algebra\ is an instance of \choose_component_algebra\ when the \choose_component\ operation is defined as follows: +\ + +context m_kleene_algebra +begin + +definition "choose_component_input_condition e v \ + regular e + \ equivalence e + \ vector v + \ regular v + \ e * v = v" + +definition "m_choose_component e v \ + if choose_component_input_condition e v then + e * minarc(v) * top + else + bot" + +sublocale m_choose_component_algebra: choose_component_algebra where choose_component = m_choose_component +proof + fix e v + show "m_choose_component e v \ -- v" + proof (cases "choose_component_input_condition e v") + case True + hence "m_choose_component e v = e * minarc(v) * top" + by (simp add: m_choose_component_def) + also have "... \ e * --v * top" + by (simp add: comp_isotone minarc_below) + also have "... = e * v * top" + using True choose_component_input_condition_def by auto + also have "... = v * top" + using True choose_component_input_condition_def by auto + finally show ?thesis + using True choose_component_input_condition_def by auto + next + case False + hence "m_choose_component e v = bot" + using False m_choose_component_def by auto + thus ?thesis + by simp + qed +next + fix e v + show "vector (m_choose_component e v)" + proof (cases "choose_component_input_condition e v") + case True + thus ?thesis + by (simp add: mult_assoc m_choose_component_def) + next + case False + thus ?thesis + by (simp add: m_choose_component_def) + qed +next + fix e v + show "regular (m_choose_component e v)" + using choose_component_input_condition_def minarc_regular regular_closed_star regular_mult_closed m_choose_component_def by auto +next + fix e v + show "m_choose_component e v * (m_choose_component e v)\<^sup>T \ e" + proof (cases "choose_component_input_condition e v") + case True + assume 1: "choose_component_input_condition e v" + hence "m_choose_component e v * (m_choose_component e v)\<^sup>T = e * minarc(v) * top * (e * minarc(v) * top)\<^sup>T" + by (simp add: m_choose_component_def) + also have "... = e * minarc(v) * top * top\<^sup>T * minarc(v)\<^sup>T * e\<^sup>T" + by (metis comp_associative conv_dist_comp) + also have "... = e * minarc(v) * top * top * minarc(v)\<^sup>T * e" + using 1 choose_component_input_condition_def by auto + also have "... = e * minarc(v) * top * minarc(v)\<^sup>T * e" + by (simp add: comp_associative) + also have "... \ e" + proof (cases "v = bot") + case True + thus ?thesis + by (simp add: True minarc_bot) + next + case False + assume 3: "v \ bot" + hence "e * minarc(v) * top * minarc(v)\<^sup>T \ e * 1" + using 3 minarc_arc arc_expanded comp_associative mult_right_isotone by fastforce + hence "e * minarc(v) * top * minarc(v)\<^sup>T * e \ e * 1 * e" + using mult_left_isotone by auto + also have "... = e" + using 1 choose_component_input_condition_def preorder_idempotent by auto + thus ?thesis + using calculation by auto + qed + thus ?thesis + by (simp add: calculation) + next + case False + thus ?thesis + by (simp add: m_choose_component_def) + qed +next + fix e v + show "m_choose_component e v = e * m_choose_component e v" + proof (cases "choose_component_input_condition e v") + case True + thus ?thesis + by (metis choose_component_input_condition_def preorder_idempotent m_choose_component_def mult_assoc) + next + case False + thus ?thesis + by (simp add: m_choose_component_def) + qed +next + fix e v + show "regular e \ equivalence e \ vector v \ regular v \ e * v = v \ v \ bot \ m_choose_component e v \ bot" + proof (cases "choose_component_input_condition e v") + case True + hence "m_choose_component e v \ minarc(v) * top" + by (metis choose_component_input_condition_def mult_1_left mult_left_isotone m_choose_component_def) + also have "... \ minarc(v)" + using calculation dual_order.trans top_right_mult_increasing by blast + thus ?thesis + using True bot_unique minarc_bot_iff by fastforce + next + case False + thus ?thesis + using choose_component_input_condition_def by blast + qed +qed + +end + +subsection \m-k-Stone-Kleene relation algebras\ + +text \ +$m$-$k$-Stone-Kleene relation algebras are an extension of $m$-Kleene algebras where the \choose_component\ operation has been added. +\ + +class m_kleene_algebra_choose_component = + m_kleene_algebra + + choose_component_algebra +begin + +text \ +A \selected_edge\ is a minimum-weight edge whose source is in a component, with respect to $h$, $j$ and $g$, and whose target is not in that component. +\ + +abbreviation "selected_edge h j g \ minarc (choose_component (forest_components h) j * - choose_component (forest_components h) j\<^sup>T \ g)" + +text \ +A \path\ is any sequence of edges in the forest, $f$, of the graph, $g$, backwards from the target of the \selected_edge\ to a root in $f$. +\ + +abbreviation "path f h j g \ top * selected_edge h j g * (f \ - selected_edge h j g\<^sup>T)\<^sup>T\<^sup>\" + +definition "boruvka_outer_invariant f g \ + symmetric g + \ forest f + \ f \ --g + \ regular f + \ (\w . minimum_spanning_forest w g \ f \ w \ w\<^sup>T)" + +definition "boruvka_inner_invariant j f h g d \ + boruvka_outer_invariant f g + \ g \ bot + \ vector j + \ regular j + \ boruvka_outer_invariant h g + \ forest h + \ forest_components h \ forest_components f + \ big_forest (forest_components h) d + \ d * top \ - j + \ forest_components h * j = j + \ forest_components f = (forest_components h * (d \ d\<^sup>T))\<^sup>\ * forest_components h + \ f \ f\<^sup>T = h \ h\<^sup>T \ d \ d\<^sup>T + \ (\ a b . bf_between_arcs a b (forest_components h) d \ a \ -(forest_components h) \ -- g \ b \ d + \ sum(b \ g) \ sum(a \ g)) + \ regular d" + +lemma expression_equivalent_without_e_complement: + assumes "selected_edge h j g \ - forest_components f" + shows "f \ - (selected_edge h j g)\<^sup>T \ - (path f h j g) \ (f \ - (selected_edge h j g)\<^sup>T \ (path f h j g))\<^sup>T \ (selected_edge h j g) + = f \ - (path f h j g) \ (f \ (path f h j g))\<^sup>T \ (selected_edge h j g)" +proof - + let ?p = "path f h j g" + let ?e = "selected_edge h j g" + let ?F = "forest_components f" + have 1: "?e \ - ?F" + by (simp add: assms) + have "f\<^sup>T \ ?F" + by (metis conv_dist_comp conv_involutive conv_order conv_star_commute forest_components_increasing) + hence "- ?F \ - f\<^sup>T" + using p_antitone by auto + hence "?e \ - f\<^sup>T" + using 1 dual_order.trans by blast + hence "f\<^sup>T \ - ?e" + by (simp add: p_antitone_iff) + hence "f\<^sup>T\<^sup>T \ - ?e\<^sup>T" + by (metis conv_complement conv_dist_inf inf.orderE inf.orderI) + hence "f \ - ?e\<^sup>T" + by auto + hence "f = f \ - ?e\<^sup>T" + using inf.orderE by blast + hence "f \ - ?e\<^sup>T \ - ?p \ (f \ - ?e\<^sup>T \ ?p)\<^sup>T \ ?e = f \ - ?p \ (f \ ?p)\<^sup>T \ ?e" + by auto + thus ?thesis by auto +qed + +text \Theorem 2\ + +text \ +The source of the \selected_edge\ is contained in $j$, the vector describing those vertices still to be processed in the inner loop of Bor\r{u}vka's algorithm. +\ + +lemma et_below_j: + assumes "vector j" + and "regular j" + and "j \ bot" + shows "selected_edge h j g * top \ j" +proof - + let ?e = "selected_edge h j g" + let ?c = "choose_component (forest_components h) j" + have "?e * top \ --(?c * -?c\<^sup>T \ g) * top" + using comp_isotone minarc_below by blast + also have "... = (--(?c * -?c\<^sup>T) \ --g) * top" + by simp + also have "... = (?c * -?c\<^sup>T \ --g) * top" + using component_is_regular regular_mult_closed by auto + also have "... = (?c \ -?c\<^sup>T \ --g) * top" + by (metis component_is_vector conv_complement vector_complement_closed vector_covector) + also have "... \ ?c * top" + using inf.cobounded1 mult_left_isotone order_trans by blast + also have "... \ j * top" + by (metis assms(2) comp_inf.star.circ_sup_2 comp_isotone component_in_v) + also have "... = j" + by (simp add: assms(1)) + finally show ?thesis + by simp +qed + +subsubsection \Components of forests and big forests\ + +text \ +We prove a number of properties about \big_forest\ and \forest_components\. +\ + +lemma fc_j_eq_j_inv: + assumes "forest h" + and "forest_components h * j = j" + shows "forest_components h * (j \ - choose_component (forest_components h) j) = j \ - choose_component (forest_components h) j" +proof - + let ?c = "choose_component (forest_components h) j" + let ?H = "forest_components h" + have 1:"equivalence ?H" + by (simp add: assms(1) forest_components_equivalence) + have "?H * (j \ - ?c) = ?H * j \ ?H * - ?c" + using 1 by (metis assms(2) equivalence_comp_dist_inf inf.sup_monoid.add_commute) + hence 2: "?H * (j \ - ?c) = j \ ?H * - ?c" + by (simp add: assms(2)) + have 3: "j \ - ?c \ ?H * - ?c" + using 1 by (metis assms(2) dedekind_1 dual_order.trans equivalence_comp_dist_inf inf.cobounded2) + have "?H * ?c \ ?c" + using component_single by auto + hence "?H\<^sup>T * ?c \ ?c" + using 1 by simp + hence "?H * - ?c \ - ?c" + using component_is_regular schroeder_3_p by force + hence "j \ ?H * - ?c \ j \ - ?c" + using inf.sup_right_isotone by auto + thus ?thesis + using 2 3 antisym by simp +qed + +text \Theorem 5\ + +text \ +There is a path in the \big_forest\ between edges $a$ and $b$ if and only if there is either a path in the \big_forest\ from $a$ to $b$ or one from $a$ to $c$ and one from $c$ to $b$. +\ + +lemma big_forest_path_split_disj: + assumes "equivalence H" + and "arc c" + and "regular a \ regular b \ regular c \ regular d \ regular H" + shows "bf_between_arcs a b H (d \ c) \ bf_between_arcs a b H d \ (bf_between_arcs a c H d \ bf_between_arcs c b H d)" +proof - + have 1: "bf_between_arcs a b H (d \ c) \ bf_between_arcs a b H d \ (bf_between_arcs a c H d \ bf_between_arcs c b H d)" + proof (rule impI) + assume 11: "bf_between_arcs a b H (d \ c)" + hence "a\<^sup>T * top \ (H * (d \ c))\<^sup>\ * H * b * top" + by (simp add: bf_between_arcs_def) + also have "... = ((H * d)\<^sup>\ \ (H * d)\<^sup>\ * H * c * (H * d)\<^sup>\) * H * b * top" + using assms(1, 2) path_through_components by simp + also have "... = (H * d)\<^sup>\ * H * b * top \ (H * d)\<^sup>\ * H * c * (H * d)\<^sup>\ * H * b * top" + by (simp add: mult_right_dist_sup) + finally have 12:"a\<^sup>T * top \ (H * d)\<^sup>\ * H * b * top \ (H * d)\<^sup>\ * H * c * (H * d)\<^sup>\ * H * b * top" + by simp + have 13: "a\<^sup>T * top \ (H * d)\<^sup>\ * H * b * top \ a\<^sup>T * top \ (H * d)\<^sup>\ * H * c * (H * d)\<^sup>\ * H * b * top" + proof (rule point_in_vector_sup) + show "point (a\<^sup>T * top)" + using 11 bf_between_arcs_def mult_assoc by auto + next + show "vector ((H * d)\<^sup>\ * H * b * top)" + using vector_mult_closed by simp + next + show "regular ((H * d)\<^sup>\ * H * b * top)" + using assms(3) pp_dist_comp pp_dist_star by auto + next + show "a\<^sup>T * top \ (H * d)\<^sup>\ * H * b * top \ (H * d)\<^sup>\ * H * c * (H * d)\<^sup>\ * H * b * top" + using 12 by simp + qed + thus "bf_between_arcs a b H d \ (bf_between_arcs a c H d \ bf_between_arcs c b H d)" + proof (cases "a\<^sup>T * top \ (H * d)\<^sup>\ * H * b * top") + case True + assume "a\<^sup>T * top \ (H * d)\<^sup>\ * H * b * top" + hence "bf_between_arcs a b H d" + using 11 bf_between_arcs_def by auto + thus ?thesis + by simp + next + case False + have 14: "a\<^sup>T * top \ (H * d)\<^sup>\ * H * c * (H * d)\<^sup>\ * H * b * top" + using 13 by (simp add: False) + hence 15: "a\<^sup>T * top \ (H * d)\<^sup>\ * H * c * top" + by (metis mult_right_isotone order_lesseq_imp top_greatest mult_assoc) + have "c\<^sup>T * top \ (H * d)\<^sup>\ * H * b * top" + proof (rule ccontr) + assume "\ c\<^sup>T * top \ (H * d)\<^sup>\ * H * b * top" + hence "c\<^sup>T * top \ -((H * d)\<^sup>\ * H * b * top)" + by (meson assms(2, 3) point_in_vector_or_complement regular_closed_star regular_closed_top regular_mult_closed vector_mult_closed vector_top_closed) + hence "c * (H * d)\<^sup>\ * H * b * top \ bot" + using schroeder_3_p mult_assoc by auto + thus "False" + using 13 False sup.absorb_iff1 mult_assoc by auto + qed + hence "bf_between_arcs a c H d \ bf_between_arcs c b H d" + using 11 15 assms(2) bf_between_arcs_def by auto + thus ?thesis + by simp + qed + qed + have 2: "bf_between_arcs a b H d \ (bf_between_arcs a c H d \ bf_between_arcs c b H d) \ bf_between_arcs a b H (d \ c)" + proof - + have 21: "bf_between_arcs a b H d \ bf_between_arcs a b H (d \ c)" + proof (rule impI) + assume 22:"bf_between_arcs a b H d" + hence "a\<^sup>T * top \ (H * d)\<^sup>\ * H * b * top" + using bf_between_arcs_def by blast + hence "a\<^sup>T * top \ (H * (d \ c))\<^sup>\ * H * b * top" + by (simp add: mult_left_isotone mult_right_dist_sup mult_right_isotone order.trans star_isotone star_slide) + thus "bf_between_arcs a b H (d \ c)" + using 22 bf_between_arcs_def by blast + qed + have "bf_between_arcs a c H d \ bf_between_arcs c b H d \ bf_between_arcs a b H (d \ c)" + proof (rule impI) + assume 23: "bf_between_arcs a c H d \ bf_between_arcs c b H d" + hence "a\<^sup>T * top \ (H * d)\<^sup>\ * H * c * top" + using bf_between_arcs_def by blast + also have "... \ (H * d)\<^sup>\ * H * c * c\<^sup>T * c * top" + by (metis ex231c comp_inf.star.circ_sup_2 mult_isotone mult_right_isotone mult_assoc) + also have "... \ (H * d)\<^sup>\ * H * c * c\<^sup>T * top" + by (simp add: mult_right_isotone mult_assoc) + also have "... \ (H * d)\<^sup>\ * H * c * (H * d)\<^sup>\ * H * b * top" + using 23 mult_right_isotone mult_assoc by (simp add: bf_between_arcs_def) + also have "... \ (H * d)\<^sup>\ * H * b * top \ (H * d)\<^sup>\ * H * c * (H * d)\<^sup>\ * H * b * top" + by (simp add: bf_between_arcs_def) + finally have "a\<^sup>T * top \ (H * (d \ c))\<^sup>\ * H * b * top" + using assms(1, 2) path_through_components mult_right_dist_sup by simp + thus "bf_between_arcs a b H (d \ c)" + using 23 bf_between_arcs_def by blast + qed + thus ?thesis + using 21 by auto + qed + thus ?thesis + using 1 2 by blast +qed + +lemma dT_He_eq_bot: + assumes "vector j" + and "regular j" + and "d * top \ - j" + and "forest_components h * j = j" + and "j \ bot" + shows "d\<^sup>T * forest_components h * selected_edge h j g \ bot" +proof - + let ?e = "selected_edge h j g" + let ?H = "forest_components h" + have 1: "?e * top \ j" + using assms(1, 2, 5) et_below_j by auto + have "d\<^sup>T * ?H * ?e \ (d * top)\<^sup>T * ?H * (?e * top)" + by (simp add: comp_isotone conv_isotone top_right_mult_increasing) + also have "... \ (d * top)\<^sup>T * ?H * j" + using 1 mult_right_isotone by auto + also have "... \ (- j)\<^sup>T * ?H * j" + by (simp add: assms(3) conv_isotone mult_left_isotone) + also have "... = (- j)\<^sup>T * j" + using assms(4) comp_associative by auto + also have "... = bot" + by (simp add: assms(1) conv_complement covector_vector_comp) + finally show ?thesis + using coreflexive_bot_closed le_bot by blast +qed + +lemma big_forest_d_U_e: + assumes "forest f" + and "vector j" + and "regular j" + and "forest h" + and "forest_components h \ forest_components f" + and "big_forest (forest_components h) d" + and "d * top \ - j" + and "forest_components h * j = j" + and "f \ f\<^sup>T = h \ h\<^sup>T \ d \ d\<^sup>T" + and "selected_edge h j g \ - forest_components f" + and "selected_edge h j g \ bot" + and "j \ bot" + shows "big_forest (forest_components h) (d \ selected_edge h j g)" +proof (unfold big_forest_def, intro conjI) + let ?H = "forest_components h" + let ?F = "forest_components f" + let ?e = "selected_edge h j g" + let ?d' = "d \ ?e" + show 01: "reflexive ?H" + by (simp add: assms(4) forest_components_equivalence) + show 02: "transitive ?H" + by (simp add: assms(4) forest_components_equivalence) + show 03: "symmetric ?H" + by (simp add: assms(4) forest_components_equivalence) + have 04: "equivalence ?H" + by (simp add: 01 02 03) + show 1: "?d' \ - ?H" + proof - + have "?H \ ?F" + by (simp add: assms(5)) + hence 11: "?e \ - ?H" + using assms(10) order_lesseq_imp p_antitone by blast + have "d \ - ?H" + using assms(6) big_forest_def by auto + thus ?thesis + by (simp add: 11) + qed + show "univalent (?H * ?d')" + proof - + have "(?H * ?d')\<^sup>T * (?H * ?d') = ?d'\<^sup>T * ?H\<^sup>T * ?H * ?d'" + using conv_dist_comp mult_assoc by auto + also have "... = ?d'\<^sup>T * ?H * ?H * ?d'" + by (simp add: conv_dist_comp conv_star_commute) + also have "... = ?d'\<^sup>T * ?H * ?d'" + using 01 02 by (metis preorder_idempotent mult_assoc) + finally have 21: "univalent (?H * ?d') \ ?e\<^sup>T * ?H * d \ d\<^sup>T * ?H * ?e \ ?e\<^sup>T * ?H * ?e \ d\<^sup>T * ?H * d \ 1" + using conv_dist_sup semiring.distrib_left semiring.distrib_right by auto + have 22: "?e\<^sup>T * ?H * ?e \ 1" + proof - + have 221: "?e\<^sup>T * ?H * ?e \ ?e\<^sup>T * top * ?e" + by (simp add: mult_left_isotone mult_right_isotone) + have "arc ?e" + using assms(11) minarc_arc minarc_bot_iff by blast + hence "?e\<^sup>T * top * ?e \ 1" + using arc_expanded by blast + thus ?thesis + using 221 dual_order.trans by blast + qed + have 24: "d\<^sup>T * ?H * ?e \ 1" + by (metis assms(2, 3, 7, 8, 12) dT_He_eq_bot coreflexive_bot_closed le_bot) + hence "(d\<^sup>T * ?H * ?e)\<^sup>T \ 1\<^sup>T" + using conv_isotone by blast + hence "?e\<^sup>T * ?H\<^sup>T * d\<^sup>T\<^sup>T \ 1" + by (simp add: conv_dist_comp mult_assoc) + hence 25: "?e\<^sup>T * ?H * d \ 1" + using assms(4) fch_equivalence by auto + have 8: "d\<^sup>T * ?H * d \ 1" + using 04 assms(6) dTransHd_le_1 big_forest_def by blast + thus ?thesis + using 21 22 24 25 by simp + qed + show "coreflexive (?H \ ?d' * ?d'\<^sup>T)" + proof - + have "coreflexive (?H \ ?d' * ?d'\<^sup>T) \ ?H \ (d \ ?e) * (d\<^sup>T \ ?e\<^sup>T) \ 1" + by (simp add: conv_dist_sup) + also have "... \ ?H \ (d * d\<^sup>T \ d * ?e\<^sup>T \ ?e * d\<^sup>T \ ?e * ?e\<^sup>T) \ 1" + by (metis mult_left_dist_sup mult_right_dist_sup sup.left_commute sup_commute) + finally have 1: "coreflexive (?H \ ?d' * ?d'\<^sup>T) \ ?H \ d * d\<^sup>T \ ?H \ d * ?e\<^sup>T \ ?H \ ?e * d\<^sup>T \ ?H \ ?e * ?e\<^sup>T \ 1" + by (simp add: inf_sup_distrib1) + have 31: "?H \ d * d\<^sup>T \ 1" + using assms(6) big_forest_def by blast + have 32: "?H \ ?e * d\<^sup>T \ 1" + proof - + have "?e * d\<^sup>T \ ?e * top * (d * top)\<^sup>T" + by (simp add: conv_isotone mult_isotone top_right_mult_increasing) + also have "... \ ?e * top * - j\<^sup>T" + by (metis assms(7) conv_complement conv_isotone mult_right_isotone) + also have "... \ j * - j\<^sup>T" + using assms(2, 3, 12) et_below_j mult_left_isotone by auto + also have "... \ - ?H" + using 03 by (metis assms(2, 3, 8) conv_complement conv_dist_comp equivalence_top_closed mult_left_isotone schroeder_3_p vector_top_closed) + finally have "?e * d\<^sup>T \ - ?H" + by simp + thus ?thesis + by (metis inf.coboundedI1 p_antitone_iff p_shunting_swap regular_one_closed) + qed + have 33: "?H \ d * ?e\<^sup>T \ 1" + proof - + have 331: "injective h" + by (simp add: assms(4)) + have "(?H \ ?e * d\<^sup>T)\<^sup>T \ 1" + using 32 coreflexive_conv_closed by auto + hence "?H \ (?e * d\<^sup>T)\<^sup>T \ 1" + using 331 conv_dist_inf forest_components_equivalence by auto + thus ?thesis + using conv_dist_comp by auto + qed + have 34: "?H \ ?e * ?e\<^sup>T \ 1" + proof - + have 341:"arc ?e \ arc (?e\<^sup>T)" + using assms(11) minarc_arc minarc_bot_iff by auto + have "?H \ ?e * ?e\<^sup>T \ ?e * ?e\<^sup>T" + by auto + thus ?thesis + using 341 arc_injective le_infI2 by blast + qed + thus ?thesis + using 1 31 32 33 34 by simp + qed + show 4:"(?H * (d \ ?e))\<^sup>+ \ - ?H" + proof - + have "?e \ - ?F" + by (simp add: assms(10)) + hence "?F \ - ?e" + by (simp add: p_antitone_iff) + hence "?F\<^sup>T * ?F \ - ?e" + using assms(1) fch_equivalence by fastforce + hence "?F\<^sup>T * ?F * ?F\<^sup>T \ - ?e" + by (metis assms(1) fch_equivalence forest_components_star star.circ_decompose_9) + hence 41: "?F * ?e * ?F \ - ?F" + using triple_schroeder_p by blast + hence 42:"(?F * ?F)\<^sup>\ * ?F * ?e * (?F * ?F)\<^sup>\ \ - ?F" + proof - + have 43: "?F * ?F = ?F" + using assms(1) forest_components_equivalence preorder_idempotent by auto + hence "?F * ?e * ?F = ?F * ?F * ?e * ?F" + by simp + also have "... = (?F)\<^sup>\ * ?F * ?e * (?F)\<^sup>\" + by (simp add: assms(1) forest_components_star) + also have "... = (?F * ?F)\<^sup>\ * ?F * ?e * (?F * ?F)\<^sup>\" + using 43 by simp + finally show ?thesis + using 41 by simp + qed + hence 44: "(?H * d)\<^sup>\ * ?H * ?e * (?H * d)\<^sup>\ \ - ?H" + proof - + have 45: "?H \ ?F" + by (simp add: assms(5)) + hence 46:"?H * ?e \ ?F * ?e" + by (simp add: mult_left_isotone) + have "d \ f \ f\<^sup>T" + using assms(9) sup.left_commute sup_commute by auto + also have "... \ ?F" + by (metis forest_components_increasing le_supI2 star.circ_back_loop_fixpoint star.circ_increasing sup.bounded_iff) + finally have "d \ ?F" + by simp + hence "?H * d \ ?F * ?F" + using 45 mult_isotone by auto + hence 47: "(?H * d)\<^sup>\ \ (?F * ?F)\<^sup>\" + by (simp add: star_isotone) + hence "(?H * d)\<^sup>\ * ?H * ?e * (?H * d)\<^sup>\ \ (?H * d)\<^sup>\ * ?F * ?e * (?H * d)\<^sup>\" + using 46 by (metis mult_left_isotone mult_right_isotone mult_assoc) + also have "... \ (?F * ?F)\<^sup>\ * ?F * ?e * (?F * ?F)\<^sup>\" + using 47 mult_left_isotone mult_right_isotone by (simp add: comp_isotone) + also have "... \ - ?F" + using 42 by simp + also have "... \ - ?H" + using 45 by (simp add: p_antitone) + finally show ?thesis + by simp + qed + have "(?H * (d \ ?e))\<^sup>+ = (?H * (d \ ?e))\<^sup>\ * (?H * (d \ ?e))" + using star.circ_plus_same by auto + also have "... = ((?H * d)\<^sup>\ \ (?H * d)\<^sup>\ * ?H * ?e * (?H * d)\<^sup>\) * (?H * (d \ ?e))" + using assms(4, 11) forest_components_equivalence minarc_arc minarc_bot_iff path_through_components by auto + also have "... = (?H * d)\<^sup>\ * (?H * (d \ ?e)) \ (?H * d)\<^sup>\ * ?H * ?e * (?H * d)\<^sup>\ * (?H * (d \ ?e))" + using mult_right_dist_sup by auto + also have "... = (?H * d)\<^sup>\ * (?H * d \ ?H * ?e) \ (?H * d)\<^sup>\ * ?H * ?e * (?H * d)\<^sup>\ * (?H * d \ ?H * ?e)" + by (simp add: mult_left_dist_sup) + also have "... = (?H * d)\<^sup>\ * ?H * d \ (?H * d)\<^sup>\ * ?H * ?e \ (?H * d)\<^sup>\ * ?H * ?e * (?H * d)\<^sup>\ * (?H * d \ ?H * ?e)" + using mult_left_dist_sup mult_assoc by auto + also have "... = (?H * d)\<^sup>+ \ (?H * d)\<^sup>\ * ?H * ?e \ (?H * d)\<^sup>\ * ?H * ?e * (?H * d)\<^sup>\ * (?H * d \ ?H * ?e)" + by (simp add: star.circ_plus_same mult_assoc) + also have "... = (?H * d)\<^sup>+ \ (?H * d)\<^sup>\ * ?H * ?e \ (?H * d)\<^sup>\ * ?H * ?e * (?H * d)\<^sup>\ * ?H * d \ (?H * d)\<^sup>\ * ?H * ?e * (?H * d)\<^sup>\ * ?H * ?e" + by (simp add: mult.semigroup_axioms semiring.distrib_left sup.semigroup_axioms semigroup.assoc) + also have "... \ (?H * d)\<^sup>+ \ (?H * d)\<^sup>\ * ?H * ?e \ (?H * d)\<^sup>\ * ?H * ?e * (?H * d)\<^sup>\ * ?H * d \ (?H * d)\<^sup>\ * ?H * ?e" + proof - + have "?e * (?H * d)\<^sup>\ * ?H * ?e \ ?e * top * ?e" + by (metis comp_associative comp_inf.coreflexive_idempotent comp_inf.coreflexive_transitive comp_isotone top.extremum) + also have "... \ ?e" + using assms(11) arc_top_arc minarc_arc minarc_bot_iff by auto + finally have "?e * (?H * d)\<^sup>\ * ?H * ?e \ ?e" + by simp + hence "(?H * d)\<^sup>\ * ?H * ?e * (?H * d)\<^sup>\ * ?H * ?e \ (?H * d)\<^sup>\ * ?H * ?e" + by (simp add: comp_associative comp_isotone) + thus ?thesis + using sup_right_isotone by blast + qed + also have "... = (?H * d)\<^sup>+ \ (?H * d)\<^sup>\ * ?H * ?e \ (?H * d)\<^sup>\ * ?H * ?e * (?H * d)\<^sup>\ * ?H * d" + by (smt eq_iff sup.left_commute sup.orderE sup_commute) + also have "... = (?H * d)\<^sup>+ \ (?H * d)\<^sup>\ * ?H * ?e \ (?H * d)\<^sup>\ * ?H * ?e * (?H * d)\<^sup>+" + using star.circ_plus_same mult_assoc by auto + also have "... = (?H * d)\<^sup>+ \ (?H * d)\<^sup>\ * ?H * ?e * (1 \ (?H * d)\<^sup>+)" + by (simp add: mult_left_dist_sup sup_assoc) + also have "... = (?H * d)\<^sup>+ \ (?H * d)\<^sup>\ * ?H * ?e * (?H * d)\<^sup>\" + by (simp add: star_left_unfold_equal) + also have "... \ - ?H" + using 44 assms(6) big_forest_def by auto + finally show ?thesis + by simp + qed +qed + +subsubsection \Identifying arcs\ + +text \ +The expression $d \sqcap \top e^\top H \sqcap (H d^\top)^* H a^\top \top$ identifies the edge incoming to the component that the \selected_edge\, $e$, is outgoing from and which is on the path from edge $a$ to $e$. +Here, we prove this expression is an \arc\. +\ + +lemma shows_arc_x: + assumes "big_forest H d" + and "bf_between_arcs a e H d" + and "H * d * (H * d)\<^sup>\ \ - H" + and "\ a\<^sup>T * top \ H * e * top" + and "regular a" + and "regular e" + and "regular H" + and "regular d" + shows "arc (d \ top * e\<^sup>T * H \ (H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top)" +proof - + let ?x = "d \ top * e\<^sup>T * H \ (H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top" + have 1:"regular ?x" + using assms(5, 6, 7, 8) regular_closed_star regular_conv_closed regular_mult_closed by auto + have 2: "a\<^sup>T * top * a \ 1" + using arc_expanded assms(2) bf_between_arcs_def by auto + have 3: "e * top * e\<^sup>T \ 1" + using assms(2) bf_between_arcs_def arc_expanded by blast + have 4: "top * ?x * top = top" + proof - + have "a\<^sup>T * top \ (H * d)\<^sup>\ * H * e * top" + using assms(2) bf_between_arcs_def by blast + also have "... = H * e * top \ (H * d)\<^sup>\ * H * d * H * e * top" + by (metis star.circ_loop_fixpoint star.circ_plus_same sup_commute mult_assoc) + finally have "a\<^sup>T * top \ H * e * top \ (H * d)\<^sup>\ * H * d * H * e * top" + by simp + hence "a\<^sup>T * top \ H * e * top \ a\<^sup>T * top \ (H * d)\<^sup>\ * H * d * H * e * top" + using assms(2, 6, 7) point_in_vector_sup bf_between_arcs_def regular_mult_closed vector_mult_closed by auto + hence "a\<^sup>T * top \ (H * d)\<^sup>\ * H * d * H * e * top" + using assms(4) by blast + also have "... = (H * d)\<^sup>\ * H * d * (H * e * top \ H * e * top)" + by (simp add: mult_assoc) + also have "... = (H * d)\<^sup>\ * H * (d \ (H * e * top)\<^sup>T) * H * e * top" + by (metis comp_associative covector_inf_comp_3 star.circ_left_top star.circ_top) + also have "... = (H * d)\<^sup>\ * H * (d \ top\<^sup>T * e\<^sup>T * H\<^sup>T) * H * e * top" + using conv_dist_comp mult_assoc by auto + also have "... = (H * d)\<^sup>\ * H * (d \ top * e\<^sup>T * H) * H * e * top" + using assms(1) by (simp add: big_forest_def) + finally have 2: "a\<^sup>T * top \ (H * d)\<^sup>\ * H * (d \ top * e\<^sup>T * H) * H * e * top" + by simp + hence "e * top \ ((H * d)\<^sup>\ * H * (d \ top * e\<^sup>T * H) * H)\<^sup>T * a\<^sup>T * top" + proof - + have "bijective (e * top) \ bijective (a\<^sup>T * top)" + using assms(2) bf_between_arcs_def by auto + thus ?thesis + using 2 by (metis bijective_reverse mult_assoc) + qed + also have "... = H\<^sup>T * (d \ top * e\<^sup>T * H)\<^sup>T * H\<^sup>T * (H * d)\<^sup>\\<^sup>T * a\<^sup>T * top" + by (simp add: conv_dist_comp mult_assoc) + also have "... = H * (d \ top * e\<^sup>T * H)\<^sup>T * H * (H * d)\<^sup>\\<^sup>T * a\<^sup>T * top" + using assms(1) big_forest_def by auto + also have "... = H * (d \ top * e\<^sup>T * H)\<^sup>T * H * (d\<^sup>T * H)\<^sup>\ * a\<^sup>T * top" + using assms(1) big_forest_def conv_dist_comp conv_star_commute by auto + also have "... = H * (d\<^sup>T \ H * e * top) * H * (d\<^sup>T * H)\<^sup>\ * a\<^sup>T * top" + using assms(1) conv_dist_comp big_forest_def comp_associative conv_dist_inf by auto + also have "... = H * (d\<^sup>T \ H * e * top) * (H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top" + by (simp add: comp_associative star_slide) + also have "... = H * (d\<^sup>T \ H * e * top) * ((H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top \ (H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top)" + using mult_assoc by auto + also have "... = H * (d\<^sup>T \ H * e * top \ ((H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top)\<^sup>T) * (H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top" + by (smt comp_inf_vector covector_comp_inf vector_conv_covector vector_top_closed mult_assoc) + also have "... = H * (d\<^sup>T \ (top * e\<^sup>T * H)\<^sup>T \ ((H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top)\<^sup>T) * (H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top" + using assms(1) big_forest_def conv_dist_comp mult_assoc by auto + also have "... = H * (d \ top * e\<^sup>T * H \ (H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top)\<^sup>T * (H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top" + by (simp add: conv_dist_inf) + finally have 3: "e * top \ H * ?x\<^sup>T * (H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top" + by auto + have "?x \ bot" + proof (rule ccontr) + assume "\ ?x \ bot" + hence "e * top = bot" + using 3 le_bot by auto + thus "False" + using assms(2, 4) bf_between_arcs_def mult_assoc semiring.mult_zero_right by auto + qed + thus ?thesis + using 1 using tarski by blast + qed + have 5: "?x * top * ?x\<^sup>T \ 1" + proof - + have 51: "H * (d * H)\<^sup>\ \ d * H * d\<^sup>T \ 1" + proof - + have 511: "d * (H * d)\<^sup>\ \ - H" + using assms(1, 3) big_forest_def preorder_idempotent schroeder_4_p triple_schroeder_p by fastforce + hence "(d * H)\<^sup>\ * d \ - H" + using star_slide by auto + hence "H * (d\<^sup>T * H)\<^sup>\ \ - d" + by (smt assms(1) big_forest_def conv_dist_comp conv_star_commute schroeder_4_p star_slide) + hence "H * (d * H)\<^sup>\ \ - d\<^sup>T" + using 511 by (metis assms(1) big_forest_def schroeder_5_p star_slide) + hence "H * (d * H)\<^sup>\ \ - (H * d\<^sup>T)" + by (metis assms(3) p_antitone_iff schroeder_4_p star_slide mult_assoc) + hence "H * (d * H)\<^sup>\ \ H * d\<^sup>T \ bot" + by (simp add: bot_unique pseudo_complement) + hence "H * d * (H * (d * H)\<^sup>\ \ H * d\<^sup>T) \ 1" + by (simp add: bot_unique) + hence 512: "H * d * H * (d * H)\<^sup>\ \ H * d * H * d\<^sup>T \ 1" + using univalent_comp_left_dist_inf assms(1) big_forest_def mult_assoc by fastforce + hence 513: "H * d * H * (d * H)\<^sup>\ \ d * H * d\<^sup>T \ 1" + proof - + have "d * H * d\<^sup>T \ H * d * H * d\<^sup>T" + by (metis assms(1) big_forest_def conv_dist_comp conv_involutive mult_1_right mult_left_isotone) + thus ?thesis + using 512 by (smt dual_order.trans p_antitone p_shunting_swap regular_one_closed) + qed + have "d\<^sup>T * H * d \ 1 \ - H" + using assms(1) big_forest_def dTransHd_le_1 le_supI1 by blast + hence "(- 1 \ H) * d\<^sup>T * H \ - d\<^sup>T" + by (metis assms(1) big_forest_def dTransHd_le_1 inf.sup_monoid.add_commute le_infI2 p_antitone_iff regular_one_closed schroeder_4_p mult_assoc) + hence "d * (- 1 \ H) * d\<^sup>T \ - H" + by (metis assms(1) big_forest_def conv_dist_comp schroeder_3_p triple_schroeder_p) + hence "H \ d * (- 1 \ H) * d\<^sup>T \ 1" + by (metis inf.coboundedI1 p_antitone_iff p_shunting_swap regular_one_closed) + hence "H \ d * d\<^sup>T \ H \ d * (- 1 \ H) * d\<^sup>T \ 1" + using assms(1) big_forest_def le_supI by blast + hence "H \ (d * 1 * d\<^sup>T \ d * (- 1 \ H) * d\<^sup>T) \ 1" + using comp_inf.semiring.distrib_left by auto + hence "H \ (d * (1 \ (- 1 \ H)) * d\<^sup>T) \ 1" + by (simp add: mult_left_dist_sup mult_right_dist_sup) + hence 514: "H \ d * H * d\<^sup>T \ 1" + by (metis assms(1) big_forest_def comp_inf.semiring.distrib_left inf.le_iff_sup inf.sup_monoid.add_commute inf_top_right regular_one_closed stone) + thus ?thesis + proof - + have "H \ d * H * d\<^sup>T \ H * d * H * (d * H)\<^sup>\ \ d * H * d\<^sup>T \ 1" + using 513 514 by simp + hence "d * H * d\<^sup>T \ (H \ H * d * H * (d * H)\<^sup>\) \ 1" + by (simp add: comp_inf.semiring.distrib_left inf.sup_monoid.add_commute) + hence "d * H * d\<^sup>T \ H * (1 \ d * H * (d * H)\<^sup>\) \ 1" + by (simp add: mult_left_dist_sup mult_assoc) + thus ?thesis + by (simp add: inf.sup_monoid.add_commute star_left_unfold_equal) + qed + qed + have "?x * top * ?x\<^sup>T = (d \ top * e\<^sup>T * H \ (H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top) * top * (d\<^sup>T \ H\<^sup>T * e\<^sup>T\<^sup>T * top\<^sup>T \ top\<^sup>T * a\<^sup>T\<^sup>T * H\<^sup>T * (d\<^sup>T\<^sup>T * H\<^sup>T)\<^sup>\)" + by (simp add: conv_dist_comp conv_dist_inf conv_star_commute mult_assoc) + also have "... = (d \ top * e\<^sup>T * H \ (H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top) * top * (d\<^sup>T \ H * e * top \ top * a * H * (d * H)\<^sup>\)" + using assms(1) big_forest_def by auto + also have "... = (H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top \ (d \ top * e\<^sup>T * H) * top * (d\<^sup>T \ H * e * top \ top * a * H * (d * H)\<^sup>\)" + by (metis inf_vector_comp vector_export_comp) + also have "... = (H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top \ (d \ top * e\<^sup>T * H) * top * top * (d\<^sup>T \ H * e * top \ top * a * H * (d * H)\<^sup>\)" + by (simp add: vector_mult_closed) + also have "... = (H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top \ d * ((top * e\<^sup>T * H)\<^sup>T \ top) * top * (d\<^sup>T \ H * e * top \ top * a * H * (d * H)\<^sup>\)" + by (simp add: covector_comp_inf_1 covector_mult_closed) + also have "... = (H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top \ d * ((top * e\<^sup>T * H)\<^sup>T \ (H * e * top)\<^sup>T) * d\<^sup>T \ top * a * H * (d * H)\<^sup>\" + by (smt comp_associative comp_inf.star_star_absorb comp_inf_vector conv_star_commute covector_comp_inf covector_conv_vector fc_top star.circ_top total_conv_surjective vector_conv_covector vector_inf_comp) + also have "... = (H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top \ top * a * H * (d * H)\<^sup>\ \ d * ((top * e\<^sup>T * H)\<^sup>T \ (H * e * top)\<^sup>T) * d\<^sup>T" + using inf.sup_monoid.add_assoc inf.sup_monoid.add_commute by auto + also have "... = (H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top * top * a * H * (d * H)\<^sup>\ \ d * ((top * e\<^sup>T * H)\<^sup>T \ (H * e * top)\<^sup>T) * d\<^sup>T" + by (smt comp_inf.star.circ_decompose_9 comp_inf.star_star_absorb comp_inf_covector fc_top star.circ_decompose_11 star.circ_top vector_export_comp) + also have "... = (H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top * a * H * (d * H)\<^sup>\ \ d * (H * e * top \ top * e\<^sup>T * H) * d\<^sup>T" + using assms(1) big_forest_def conv_dist_comp mult_assoc by auto + also have "... = (H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top * a * H * (d * H)\<^sup>\ \ d * H * e * top * e\<^sup>T * H * d\<^sup>T" + by (metis comp_inf_covector inf_top.left_neutral mult_assoc) + also have "... \ (H * d\<^sup>T)\<^sup>\ * (H * d)\<^sup>\ * H \ d * H * e * top * e\<^sup>T * H * d\<^sup>T" + proof - + have "(H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top * a * H * (d * H)\<^sup>\ \ (H * d\<^sup>T)\<^sup>\ * H * 1 * H * (d * H)\<^sup>\" + using 2 by (metis comp_associative comp_isotone mult_left_isotone mult_semi_associative star.circ_transitive_equal) + also have "... = (H * d\<^sup>T)\<^sup>\ * H * (d * H)\<^sup>\" + using assms(1) big_forest_def mult.semigroup_axioms preorder_idempotent semigroup.assoc by fastforce + also have "... = (H * d\<^sup>T)\<^sup>\ * (H * d)\<^sup>\ * H" + by (metis star_slide mult_assoc) + finally show ?thesis + using inf.sup_left_isotone by auto + qed + also have "... \ (H * d\<^sup>T)\<^sup>\ * (H * d)\<^sup>\ * H \ d * H * d\<^sup>T" + proof - + have "d * H * e * top * e\<^sup>T * H * d\<^sup>T \ d * H * 1 * H * d\<^sup>T" + using 3 by (metis comp_isotone idempotent_one_closed mult_left_isotone mult_sub_right_one mult_assoc) + also have "... \ d * H * d\<^sup>T" + by (metis assms(1) big_forest_def mult_left_isotone mult_one_associative mult_semi_associative preorder_idempotent) + finally show ?thesis + using inf.sup_right_isotone by auto + qed + also have "... = H * (d\<^sup>T * H)\<^sup>\ * (H * d)\<^sup>\ * H \ d * H * d\<^sup>T" + by (metis assms(1) big_forest_def comp_associative preorder_idempotent star_slide) + also have "... = H * ((d\<^sup>T * H)\<^sup>\ \ (H * d)\<^sup>\) * H \ d * H * d\<^sup>T" + by (simp add: assms(1) expand_big_forest mult.semigroup_axioms semigroup.assoc) + also have "... = (H * (d\<^sup>T * H)\<^sup>\ * H \ H * (H * d)\<^sup>\ * H) \ d * H * d\<^sup>T" + by (simp add: mult_left_dist_sup mult_right_dist_sup) + also have "... = (H * d\<^sup>T)\<^sup>\ * H \ d * H * d\<^sup>T \ H * (d * H)\<^sup>\ \ d * H * d\<^sup>T" + by (smt assms(1) big_forest_def inf_sup_distrib2 mult.semigroup_axioms preorder_idempotent star_slide semigroup.assoc) + also have "... \ (H * d\<^sup>T)\<^sup>\ * H \ d * H * d\<^sup>T \ 1" + using 51 comp_inf.semiring.add_left_mono by blast + finally have "?x * top * ?x\<^sup>T \ 1" + using 51 by (smt assms(1) big_forest_def conv_dist_comp conv_dist_inf conv_dist_sup conv_involutive conv_star_commute equivalence_one_closed mult.semigroup_axioms sup.absorb2 semigroup.assoc conv_isotone conv_order) + thus ?thesis + by simp + qed + have 6: "?x\<^sup>T * top * ?x \ 1" + proof - + have "?x\<^sup>T * top * ?x = (d\<^sup>T \ H\<^sup>T * e\<^sup>T\<^sup>T * top\<^sup>T \ top\<^sup>T * a\<^sup>T\<^sup>T * H\<^sup>T * (d\<^sup>T\<^sup>T * H\<^sup>T)\<^sup>\) * top * (d \ top * e\<^sup>T * H \ (H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top)" + by (simp add: conv_dist_comp conv_dist_inf conv_star_commute mult_assoc) + also have "... = (d\<^sup>T \ H * e * top \ top * a * H * (d * H)\<^sup>\) * top * (d \ top * e\<^sup>T * H \ (H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top)" + using assms(1) big_forest_def by auto + also have "... = H * e * top \ (d\<^sup>T \ top * a * H * (d * H)\<^sup>\) * top * (d \ top * e\<^sup>T * H \ (H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top)" + by (smt comp_associative inf.sup_monoid.add_assoc inf.sup_monoid.add_commute star.circ_left_top star.circ_top vector_inf_comp) + also have "... = H * e * top \ d\<^sup>T * ((top * a * H * (d * H)\<^sup>\)\<^sup>T \ top) * (d \ top * e\<^sup>T * H \ (H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top)" + by (simp add: covector_comp_inf_1 covector_mult_closed) + also have "... = H * e * top \ d\<^sup>T * (d * H)\<^sup>\\<^sup>T * H * a\<^sup>T * top * (d \ top * e\<^sup>T * H \ (H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top)" + using assms(1) big_forest_def comp_associative conv_dist_comp by auto + also have "... = H * e * top \ d\<^sup>T * (d * H)\<^sup>\\<^sup>T * H * a\<^sup>T * top * (d \ (H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top) \ top * e\<^sup>T * H" + by (smt comp_associative comp_inf_covector inf.sup_monoid.add_assoc inf.sup_monoid.add_commute) + also have "... = H * e * top \ d\<^sup>T * (d * H)\<^sup>\\<^sup>T * H * a\<^sup>T * (top \ ((H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top)\<^sup>T) * d \ top * e\<^sup>T * H" + by (metis comp_associative comp_inf_vector vector_conv_covector vector_top_closed) + also have "... = H * e * top \ (H * e * top)\<^sup>T \ d\<^sup>T * (d * H)\<^sup>\\<^sup>T * H * a\<^sup>T * ((H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top)\<^sup>T * d" + by (smt assms(1) big_forest_def conv_dist_comp inf.left_commute inf.sup_monoid.add_commute symmetric_top_closed mult_assoc inf_top.left_neutral) + also have "... = H * e * top * (H * e * top)\<^sup>T \ d\<^sup>T * (d * H)\<^sup>\\<^sup>T * H * a\<^sup>T * ((H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top)\<^sup>T * d" + using vector_covector vector_mult_closed by auto + also have "... = H * e * top * top\<^sup>T * e\<^sup>T * H\<^sup>T \ d\<^sup>T * (d * H)\<^sup>\\<^sup>T * H * a\<^sup>T * top\<^sup>T * a\<^sup>T\<^sup>T * H\<^sup>T * (H * d\<^sup>T)\<^sup>\\<^sup>T * d" + by (smt conv_dist_comp mult.semigroup_axioms symmetric_top_closed semigroup.assoc) + also have "... = H * e * top * top * e\<^sup>T * H \ d\<^sup>T * (H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top * a * H * (d * H)\<^sup>\ * d" + using assms(1) big_forest_def conv_dist_comp conv_star_commute by auto + also have "... = H * e * top * e\<^sup>T * H \ d\<^sup>T * (H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top * a * H * (d * H)\<^sup>\ * d" + using vector_top_closed mult_assoc by auto + also have "... \ H \ d\<^sup>T * (H * d\<^sup>T)\<^sup>\ * H * (d * H)\<^sup>\ * d" + proof - + have "H * e * top * e\<^sup>T * H \ H * 1 * H" + using 3 by (metis comp_associative mult_left_isotone mult_right_isotone) + also have "... = H" + using assms(1) big_forest_def preorder_idempotent by auto + finally have 611: "H * e * top * e\<^sup>T * H \ H" + by simp + have "d\<^sup>T * (H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top * a * H * (d * H)\<^sup>\ * d \ d\<^sup>T * (H * d\<^sup>T)\<^sup>\ * H * 1 * H * (d * H)\<^sup>\ * d" + using 2 by (metis comp_associative mult_left_isotone mult_right_isotone) + also have "... = d\<^sup>T * (H * d\<^sup>T)\<^sup>\ * H * (d * H)\<^sup>\ * d" + using assms(1) big_forest_def mult.semigroup_axioms preorder_idempotent semigroup.assoc by fastforce + finally have "d\<^sup>T * (H * d\<^sup>T)\<^sup>\ * H * a\<^sup>T * top * a * H * (d * H)\<^sup>\ * d \ d\<^sup>T * (H * d\<^sup>T)\<^sup>\ * H * (d * H)\<^sup>\ * d" + by simp + thus ?thesis + using 611 comp_inf.comp_isotone by blast + qed + also have "... = H \ (d\<^sup>T * H)\<^sup>\ * d\<^sup>T * H * d * (H * d)\<^sup>\" + using star_slide mult_assoc by auto + also have "... \ H \ (d\<^sup>T * H)\<^sup>\ * (H * d)\<^sup>\" + proof - + have "(d\<^sup>T * H)\<^sup>\ * d\<^sup>T * H * d * (H * d)\<^sup>\ \ (d\<^sup>T * H)\<^sup>\ * 1 * (H * d)\<^sup>\" + by (smt assms(1) big_forest_def conv_dist_comp mult_left_isotone mult_right_isotone preorder_idempotent mult_assoc) + also have "... = (d\<^sup>T * H)\<^sup>\ * (H * d)\<^sup>\" + by simp + finally show ?thesis + using inf.sup_right_isotone by blast + qed + also have "... = H \ ((d\<^sup>T * H)\<^sup>\ \ (H * d)\<^sup>\)" + by (simp add: assms(1) expand_big_forest) + also have "... = H \ (d\<^sup>T * H)\<^sup>\ \ H \ (H * d)\<^sup>\" + by (simp add: comp_inf.semiring.distrib_left) + also have "... = 1 \ H \ (d\<^sup>T * H)\<^sup>+ \ H \ (H * d)\<^sup>+" + proof - + have 612: "H \ (H * d)\<^sup>\ = 1 \ H \ (H * d)\<^sup>+" + using assms(1) big_forest_def reflexive_inf_star by blast + have "H \ (d\<^sup>T * H)\<^sup>\ = 1 \ H \ (d\<^sup>T * H)\<^sup>+" + using assms(1) big_forest_def reflexive_inf_star by auto + thus ?thesis + using 612 sup_assoc sup_commute by auto + qed + also have "... \ 1" + proof - + have 613: "H \ (H * d)\<^sup>+ \ 1" + by (metis assms(3) inf.coboundedI1 p_antitone_iff p_shunting_swap regular_one_closed) + hence "H \ (d\<^sup>T * H)\<^sup>+ \ 1" + by (metis assms(1) big_forest_def conv_dist_comp conv_dist_inf conv_plus_commute coreflexive_symmetric) + thus ?thesis + by (simp add: 613) + qed + finally show ?thesis + by simp + qed + have 7:"bijective (?x * top)" + using 4 5 6 arc_expanded by blast + have "bijective (?x\<^sup>T * top)" + using 4 5 6 arc_expanded by blast + thus ?thesis + using 7 by simp +qed + +text \ +To maintain that $f$ can be extended to a minimum spanning forest we identify an edge, $i = v \sqcap \overline{F}e\top \sqcap \top e^\top F$, that may be exchanged with the \selected_edge\, $e$. +Here, we show that $i$ is an \arc\. +\ + +lemma boruvka_edge_arc: + assumes "equivalence F" + and "forest v" + and "arc e" + and "regular F" + and "F \ forest_components (F \ v)" + and "regular v" + and "v * e\<^sup>T = bot" + and "e * F * e = bot" + and "e\<^sup>T \ v\<^sup>\" + and "e \ bot" + shows "arc (v \ -F * e * top \ top * e\<^sup>T * F)" +proof - + let ?i = "v \ -F * e * top \ top * e\<^sup>T * F" + have 1: "?i\<^sup>T * top * ?i \ 1" + proof - + have "?i\<^sup>T * top * ?i = (v\<^sup>T \ top * e\<^sup>T * -F \ F * e * top) * top * (v \ -F * e * top \ top * e\<^sup>T * F)" + using assms(1) conv_complement conv_dist_comp conv_dist_inf mult.semigroup_axioms semigroup.assoc by fastforce + also have "... = F * e * top \ (v\<^sup>T \ top * e\<^sup>T * -F) * top * (v \ -F * e * top) \ top * e\<^sup>T * F" + by (smt covector_comp_inf covector_mult_closed inf_vector_comp vector_export_comp vector_top_closed) + also have "... = F * e * top \ (v\<^sup>T \ top * e\<^sup>T * -F) * top * top * (v \ -F * e * top) \ top * e\<^sup>T * F" + by (simp add: comp_associative) + also have "... = F * e * top \ v\<^sup>T * (top \ (top * e\<^sup>T * -F)\<^sup>T) * top * (v \ -F * e * top) \ top * e\<^sup>T * F" + using comp_associative comp_inf_vector_1 by auto + also have "... = F * e * top \ v\<^sup>T * (top \ (top * e\<^sup>T * -F)\<^sup>T) * (top \ (-F * e * top)\<^sup>T) * v \ top * e\<^sup>T * F" + by (smt comp_inf_vector conv_dist_comp mult.semigroup_axioms symmetric_top_closed semigroup.assoc) + also have "... = F * e * top \ v\<^sup>T * (top * e\<^sup>T * -F)\<^sup>T * (-F * e * top)\<^sup>T * v \ top * e\<^sup>T * F" + by simp + also have "... = F * e * top \ v\<^sup>T * -F\<^sup>T * e\<^sup>T\<^sup>T * top\<^sup>T * top\<^sup>T * e\<^sup>T * -F\<^sup>T * v \ top * e\<^sup>T * F" + by (metis comp_associative conv_complement conv_dist_comp) + also have "... = F * e * top \ v\<^sup>T * -F * e * top * top * e\<^sup>T * -F * v \ top * e\<^sup>T * F" + by (simp add: assms(1)) + also have "... = F * e * top \ v\<^sup>T * -F * e * top \ top * e\<^sup>T * -F * v \ top * e\<^sup>T * F" + by (metis comp_associative comp_inf_covector inf.sup_monoid.add_assoc inf_top.left_neutral vector_top_closed) + also have "... = (F \ v\<^sup>T * -F) * e * top \ top * e\<^sup>T * -F * v \ top * e\<^sup>T * F" + using assms(3) injective_comp_right_dist_inf mult_assoc by auto + also have "... = (F \ v\<^sup>T * -F) * e * top \ top * e\<^sup>T * (F \ -F * v)" + using assms(3) conv_dist_comp inf.sup_monoid.add_assoc inf.sup_monoid.add_commute mult.semigroup_axioms univalent_comp_left_dist_inf semigroup.assoc by fastforce + also have "... = (F \ v\<^sup>T * -F) * e * top * top * e\<^sup>T * (F \ -F * v)" + by (metis comp_associative comp_inf_covector inf_top.left_neutral vector_top_closed) + also have "... = (F \ v\<^sup>T * -F) * e * top * e\<^sup>T * (F \ -F * v)" + by (simp add: comp_associative) + also have "... \ (F \ v\<^sup>T * -F) * (F \ -F * v)" + by (smt assms(3) conv_dist_comp mult_left_isotone shunt_bijective symmetric_top_closed top_right_mult_increasing mult_assoc) + also have "... \ (F \ v\<^sup>T * -F) * (F \ -F * v) \ F" + by (metis assms(1) inf.absorb1 inf.cobounded1 mult_isotone preorder_idempotent) + also have "... \ (F \ v\<^sup>T * -F) * (F \ -F * v) \ (F \ v)\<^sup>T\<^sup>\ * (F \ v)\<^sup>\" + using assms(5) comp_inf.mult_right_isotone by auto + also have "... \ (-F \ v\<^sup>T) * -F * -F * (-F \ v) \ (F \ v)\<^sup>T\<^sup>\ * (F \ v)\<^sup>\" + proof - + have "F \ v\<^sup>T * -F \ (v\<^sup>T \ F * -F\<^sup>T) * -F" + by (metis conv_complement dedekind_2 inf_commute) + also have "... = (v\<^sup>T \ -F\<^sup>T) * -F" + using assms(1) equivalence_comp_left_complement by simp + finally have "F \ v\<^sup>T * -F \ F \ (v\<^sup>T \ -F) * -F" + using assms(1) by auto + hence 11: "F \ v\<^sup>T * -F = F \ (-F \ v\<^sup>T) * -F" + by (metis inf.antisym_conv inf.sup_monoid.add_commute comp_left_subdist_inf inf.boundedE inf.sup_right_isotone) + hence "F\<^sup>T \ -F\<^sup>T * v\<^sup>T\<^sup>T = F\<^sup>T \ -F\<^sup>T * (-F\<^sup>T \ v\<^sup>T\<^sup>T)" + by (metis (full_types) assms(1) conv_complement conv_dist_comp conv_dist_inf) + hence 12: "F \ -F * v = F \ -F * (-F \ v)" + using assms(1) by (simp add: abel_semigroup.commute inf.abel_semigroup_axioms) + have "(F \ v\<^sup>T * -F) * (F \ -F * v) = (F \ (-F \ v\<^sup>T) * -F) * (F \ -F * (-F \ v))" + using 11 12 by auto + also have "... \ (-F \ v\<^sup>T) * -F * -F * (-F \ v)" + by (metis comp_associative comp_isotone inf.cobounded2) + finally show ?thesis + using comp_inf.mult_left_isotone by blast + qed + also have "... = ((-F \ v\<^sup>T) * -F * -F * (-F \ v) \ (F \ v)\<^sup>T * (F \ v)\<^sup>T\<^sup>\ * (F \ v)\<^sup>\) \ ((-F \ v\<^sup>T) * -F * -F * (-F \ v) \ (F \ v)\<^sup>\)" + by (metis comp_associative inf_sup_distrib1 star.circ_loop_fixpoint) + also have "... = ((-F \ v\<^sup>T) * -F * -F * (-F \ v) \ (F \ v\<^sup>T) * (F \ v)\<^sup>T\<^sup>\ * (F \ v)\<^sup>\) \ ((-F \ v\<^sup>T) * -F * -F * (-F \ v) \ (F \ v)\<^sup>\)" + using assms(1) conv_dist_inf by auto + also have "... = bot \ ((-F \ v\<^sup>T) * -F * -F * (-F \ v) \ (F \ v)\<^sup>\)" + proof - + have "(-F \ v\<^sup>T) * -F * -F * (-F \ v) \ (F \ v\<^sup>T) * (F \ v)\<^sup>T\<^sup>\ * (F \ v)\<^sup>\ \ bot" + using assms(1, 2) forests_bot_2 by (simp add: comp_associative) + thus ?thesis + using le_bot by blast + qed + also have "... = (-F \ v\<^sup>T) * -F * -F * (-F \ v) \ (1 \ (F \ v)\<^sup>\ * (F \ v))" + by (simp add: star.circ_plus_same star_left_unfold_equal) + also have "... = ((-F \ v\<^sup>T) * -F * -F * (-F \ v) \ 1) \ ((-F \ v\<^sup>T) * -F * -F * (-F \ v) \ (F \ v)\<^sup>\ * (F \ v))" + by (simp add: comp_inf.semiring.distrib_left) + also have "... \ 1 \ ((-F \ v\<^sup>T) * -F * -F * (-F \ v) \ (F \ v)\<^sup>\ * (F \ v))" + using sup_left_isotone by auto + also have "... \ 1 \ bot" + using assms(1, 2) forests_bot_3 comp_inf.semiring.add_left_mono by simp + finally show ?thesis + by simp + qed + have 2: "?i * top * ?i\<^sup>T \ 1" + proof - + have "?i * top * ?i\<^sup>T = (v \ -F * e * top \ top * e\<^sup>T * F) * top * (v\<^sup>T \ (-F * e * top)\<^sup>T \ (top * e\<^sup>T * F)\<^sup>T)" + by (simp add: conv_dist_inf) + also have "... = (v \ -F * e * top \ top * e\<^sup>T * F) * top * (v\<^sup>T \ top\<^sup>T * e\<^sup>T * -F\<^sup>T \ F\<^sup>T * e\<^sup>T\<^sup>T * top\<^sup>T)" + by (simp add: conv_complement conv_dist_comp mult_assoc) + also have "... = (v \ -F * e * top \ top * e\<^sup>T * F) * top * (v\<^sup>T \ top * e\<^sup>T * -F \ F * e * top)" + by (simp add: assms(1)) + also have "... = -F * e * top \ (v \ top * e\<^sup>T * F) * top * (v\<^sup>T \ top * e\<^sup>T * -F \ F * e * top)" + by (smt inf.left_commute inf.sup_monoid.add_assoc vector_export_comp) + also have "... = -F * e * top \ (v \ top * e\<^sup>T * F) * top * (v\<^sup>T \ F * e * top) \ top * e\<^sup>T * -F" + by (smt comp_inf_covector inf.sup_monoid.add_assoc inf.sup_monoid.add_commute mult_assoc) + also have "... = -F * e * top \ (v \ top * e\<^sup>T * F) * top * top * (v\<^sup>T \ F * e * top) \ top * e\<^sup>T * -F" + by (simp add: mult_assoc) + also have "... = -F * e * top \ v * ((top * e\<^sup>T * F)\<^sup>T \ top) * top * (v\<^sup>T \ F * e * top) \ top * e\<^sup>T * -F" + by (simp add: comp_inf_vector_1 mult.semigroup_axioms semigroup.assoc) + also have "... = -F * e * top \ v * ((top * e\<^sup>T * F)\<^sup>T \ top) * (top \ (F * e * top)\<^sup>T) * v\<^sup>T \ top * e\<^sup>T * -F" + by (smt comp_inf_vector covector_comp_inf vector_conv_covector vector_mult_closed vector_top_closed) + also have "... = -F * e * top \ v * (top * e\<^sup>T * F)\<^sup>T * (F * e * top)\<^sup>T * v\<^sup>T \ top * e\<^sup>T * -F" + by simp + also have "... = -F * e * top \ v * F\<^sup>T * e\<^sup>T\<^sup>T * top\<^sup>T * top\<^sup>T * e\<^sup>T * F\<^sup>T * v\<^sup>T \ top * e\<^sup>T * -F" + by (metis comp_associative conv_dist_comp) + also have "... = -F * e * top \ v * F * e * top * top * e\<^sup>T * F * v\<^sup>T \ top * e\<^sup>T * -F" + using assms(1) by auto + also have "... = -F * e * top \ v * F * e * top \ top * e\<^sup>T * F * v\<^sup>T \ top * e\<^sup>T * -F" + by (smt comp_associative comp_inf_covector inf.sup_monoid.add_assoc inf_top.left_neutral vector_top_closed) + also have "... = (-F \ v * F) * e * top \ top * e\<^sup>T * F * v\<^sup>T \ top * e\<^sup>T * -F" + using injective_comp_right_dist_inf assms(3) mult.semigroup_axioms semigroup.assoc by fastforce + also have "... = (-F \ v * F) * e * top \ top * e\<^sup>T * (F * v\<^sup>T \ -F)" + using injective_comp_right_dist_inf assms(3) conv_dist_comp inf.sup_monoid.add_assoc mult.semigroup_axioms univalent_comp_left_dist_inf semigroup.assoc by fastforce + also have "... = (-F \ v * F) * e * top * top * e\<^sup>T * (F * v\<^sup>T \ -F)" + by (metis inf_top_right vector_export_comp vector_top_closed) + also have "... = (-F \ v * F) * e * top * e\<^sup>T * (F * v\<^sup>T \ -F)" + by (simp add: comp_associative) + also have "... \ (-F \ v * F) * (F * v\<^sup>T \ -F)" + by (smt assms(3) conv_dist_comp mult.semigroup_axioms mult_left_isotone shunt_bijective symmetric_top_closed top_right_mult_increasing semigroup.assoc) + also have "... = (-F \ v * F) * ((v * F)\<^sup>T \ -F)" + by (simp add: assms(1) conv_dist_comp) + also have "... = (-F \ v * F) * (-F \ v * F)\<^sup>T" + using assms(1) conv_complement conv_dist_inf by (simp add: inf.sup_monoid.add_commute) + also have "... \ (-F \ v) * (F \ v)\<^sup>\ * (F \ v)\<^sup>T\<^sup>\ * (-F \ v)\<^sup>T" + proof - + let ?Fv = "F \ v" + have "-F \ v * F \ -F \ v * (F \ v)\<^sup>T\<^sup>\ * (F \ v)\<^sup>\" + using assms(5) inf.sup_right_isotone mult_right_isotone comp_associative by auto + also have "... \ -F \ v * (F \ v)\<^sup>\" + proof - + have "v * v\<^sup>T \ 1" + by (simp add: assms(2)) + hence "v * v\<^sup>T * F \ F" + using assms(1) dual_order.trans mult_left_isotone by blast + hence "v * v\<^sup>T * F\<^sup>T\<^sup>\ * F\<^sup>\ \ F" + by (metis assms(1) mult_1_right preorder_idempotent star.circ_sup_one_right_unfold star.circ_transitive_equal star_one star_simulation_right_equal mult_assoc) + hence "v * (F \ v)\<^sup>T * F\<^sup>T\<^sup>\ * F\<^sup>\ \ F" + by (meson conv_isotone dual_order.trans inf.cobounded2 inf.sup_monoid.add_commute mult_left_isotone mult_right_isotone) + hence "v * (F \ v)\<^sup>T * (F \ v)\<^sup>T\<^sup>\ * (F \ v)\<^sup>\ \ F" + by (meson conv_isotone dual_order.trans inf.cobounded2 inf.sup_monoid.add_commute mult_left_isotone mult_right_isotone comp_isotone conv_dist_inf inf.cobounded1 star_isotone) + hence "-F \ v * (F \ v)\<^sup>T * (F \ v)\<^sup>T\<^sup>\ * (F \ v)\<^sup>\ \ bot" + using eq_iff p_antitone pseudo_complement by auto + hence "(-F \ v * (F \ v)\<^sup>T * (F \ v)\<^sup>T\<^sup>\ * (F \ v)\<^sup>\) \ v * (v \ F)\<^sup>\ \ v * (v \ F)\<^sup>\" + using bot_least le_bot by fastforce + hence "(-F \ v * (v \ F)\<^sup>\) \ (v * (F \ v)\<^sup>T * (F \ v)\<^sup>T\<^sup>\ * (F \ v)\<^sup>\ \ v * (v \ F)\<^sup>\) \ v * (v \ F)\<^sup>\" + by (simp add: sup_inf_distrib2) + hence "(-F \ v * (v \ F)\<^sup>\) \ v * ((F \ v)\<^sup>T * (F \ v)\<^sup>T\<^sup>\ \ 1) * (v \ F)\<^sup>\ \ v * (v \ F)\<^sup>\" + by (simp add: inf.sup_monoid.add_commute mult.semigroup_axioms mult_left_dist_sup mult_right_dist_sup semigroup.assoc) + hence "(-F \ v * (v \ F)\<^sup>\) \ v * (F \ v)\<^sup>T\<^sup>\ * (v \ F)\<^sup>\ \ v * (v \ F)\<^sup>\" + by (simp add: star_left_unfold_equal sup_commute) + hence "-F \ v * (F \ v)\<^sup>T\<^sup>\ * (v \ F)\<^sup>\ \ v * (v \ F)\<^sup>\" + using comp_inf.mult_right_sub_dist_sup_left inf.order_lesseq_imp by blast + thus ?thesis + by (simp add: inf.sup_monoid.add_commute) + qed + also have "... \ (v \ -F * (F \ v)\<^sup>T\<^sup>\) * (F \ v)\<^sup>\" + by (metis dedekind_2 conv_star_commute inf.sup_monoid.add_commute) + also have "... \ (v \ -F * F\<^sup>T\<^sup>\) * (F \ v)\<^sup>\" + using conv_isotone inf.sup_right_isotone mult_left_isotone mult_right_isotone star_isotone by auto + also have "... = (v \ -F * F) * (F \ v)\<^sup>\" + by (metis assms(1) equivalence_comp_right_complement mult_left_one star_one star_simulation_right_equal) + also have "... = (-F \ v) * (F \ v)\<^sup>\" + using assms(1) equivalence_comp_right_complement inf.sup_monoid.add_commute by auto + finally have "-F \ v * F \ (-F \ v) * (F \ v)\<^sup>\" + by simp + hence "(-F \ v * F) * (-F \ v * F)\<^sup>T \ (-F \ v) * (F \ v)\<^sup>\ * ((-F \ v) * (F \ v)\<^sup>\)\<^sup>T" + by (simp add: comp_isotone conv_isotone) + also have "... = (-F \ v) * (F \ v)\<^sup>\ * (F \ v)\<^sup>T\<^sup>\ * (-F \ v)\<^sup>T" + by (simp add: comp_associative conv_dist_comp conv_star_commute) + finally show ?thesis + by simp + qed + also have "... \ (-F \ v) * ((F \ v\<^sup>\) \ (F \ v\<^sup>T\<^sup>\)) * (-F \ v)\<^sup>T" + proof - + have "(F \ v)\<^sup>\ * (F \ v)\<^sup>T\<^sup>\ \ F\<^sup>\ * F\<^sup>T\<^sup>\" + using fc_isotone by auto + also have "... \ F * F" + by (metis assms(1) preorder_idempotent star.circ_sup_one_left_unfold star.circ_transitive_equal star_right_induct_mult) + finally have 21: "(F \ v)\<^sup>\ * (F \ v)\<^sup>T\<^sup>\ \ F" + using assms(1) dual_order.trans by blast + have "(F \ v)\<^sup>\ * (F \ v)\<^sup>T\<^sup>\ \ v\<^sup>\ * v\<^sup>T\<^sup>\" + by (simp add: fc_isotone) + hence "(F \ v)\<^sup>\ * (F \ v)\<^sup>T\<^sup>\ \ F \ v\<^sup>\ * v\<^sup>T\<^sup>\" + using 21 by simp + also have "... = F \ (v\<^sup>\ \ v\<^sup>T\<^sup>\)" + by (simp add: assms(2) cancel_separate_eq) + finally show ?thesis + by (metis assms(4, 6) comp_associative comp_inf.semiring.distrib_left comp_isotone inf_pp_semi_commute mult_left_isotone regular_closed_inf) + qed + also have "... \ (-F \ v) * (F \ v\<^sup>T\<^sup>\) * (-F \ v)\<^sup>T \ (-F \ v) * (F \ v\<^sup>\) * (-F \ v)\<^sup>T" + by (simp add: mult_left_dist_sup mult_right_dist_sup) + also have "... \ (-F \ v) * (-F \ v)\<^sup>T \ (-F \ v) * (-F \ v)\<^sup>T" + proof - + have "(-F \ v) * (F \ v\<^sup>T\<^sup>\) \ (-F \ v) * ((F \ v)\<^sup>T\<^sup>\ * (F \ v)\<^sup>\ \ v\<^sup>T\<^sup>\)" + by (simp add: assms(5) inf.coboundedI1 mult_right_isotone) + also have "... = (-F \ v) * ((F \ v)\<^sup>T * (F \ v)\<^sup>T\<^sup>\ * (F \ v)\<^sup>\ \ v\<^sup>T\<^sup>\) \ (-F \ v) * ((F \ v)\<^sup>\ \ v\<^sup>T\<^sup>\)" + by (metis comp_associative comp_inf.mult_right_dist_sup mult_left_dist_sup star.circ_loop_fixpoint) + also have "... \ (-F \ v) * (F \ v)\<^sup>T * top \ (-F \ v) * ((F \ v)\<^sup>\ \ v\<^sup>T\<^sup>\)" + by (simp add: comp_associative comp_isotone inf.coboundedI2 inf.sup_monoid.add_commute le_supI1) + also have "... \ (-F \ v) * (F \ v)\<^sup>T * top \ (-F \ v) * (v\<^sup>\ \ v\<^sup>T\<^sup>\)" + by (smt comp_inf.mult_right_isotone comp_inf.semiring.add_mono eq_iff inf.cobounded2 inf.sup_monoid.add_commute mult_right_isotone star_isotone) + also have "... \ bot \ (-F \ v) * (v\<^sup>\ \ v\<^sup>T\<^sup>\)" + by (metis assms(1, 2) forests_bot_1 comp_associative comp_inf.semiring.add_right_mono mult_semi_associative vector_bot_closed) + also have "... \ -F \ v" + by (simp add: assms(2) acyclic_star_inf_conv) + finally have 22: "(-F \ v) * (F \ v\<^sup>T\<^sup>\) \ -F \ v" + by simp + have "((-F \ v) * (F \ v\<^sup>T\<^sup>\))\<^sup>T = (F \ v\<^sup>\) * (-F \ v)\<^sup>T" + by (simp add: assms(1) conv_dist_inf conv_star_commute conv_dist_comp) + hence "(F \ v\<^sup>\) * (-F \ v)\<^sup>T \ (-F \ v)\<^sup>T" + using 22 conv_isotone by fastforce + thus ?thesis + using 22 by (metis assms(4, 6) comp_associative comp_inf.pp_comp_semi_commute comp_inf.semiring.add_mono comp_isotone inf_pp_commute mult_left_isotone) + qed + also have "... = (-F \ v) * (-F \ v)\<^sup>T" + by simp + also have "... \ v * v\<^sup>T" + by (simp add: comp_isotone conv_isotone) + also have "... \ 1" + by (simp add: assms(2)) + thus ?thesis + using calculation dual_order.trans by blast + qed + have 3: "top * ?i * top = top" + proof - + have 31: "regular (e\<^sup>T * -F * v * F * e)" + using assms(3, 4, 6) arc_regular regular_mult_closed by auto + have 32: "bijective ((top * e\<^sup>T)\<^sup>T)" + using assms(3) by (simp add: conv_dist_comp) + have "top * ?i * top = top * (v \ -F * e * top) * ((top * e\<^sup>T * F)\<^sup>T \ top)" + by (simp add: comp_associative comp_inf_vector_1) + also have "... = (top \ (-F * e * top)\<^sup>T) * v * ((top * e\<^sup>T * F)\<^sup>T \ top)" + using comp_inf_vector conv_dist_comp by auto + also have "... = (-F * e * top)\<^sup>T * v * (top * e\<^sup>T * F)\<^sup>T" + by simp + also have "... = top\<^sup>T * e\<^sup>T * -F\<^sup>T * v * F\<^sup>T * e\<^sup>T\<^sup>T * top\<^sup>T" + by (simp add: comp_associative conv_complement conv_dist_comp) + finally have 33: "top * ?i * top = top * e\<^sup>T * -F * v * F * e * top" + by (simp add: assms(1)) + have "top * ?i * top \ bot" + proof (rule ccontr) + assume "\ top * (v \ - F * e * top \ top * e\<^sup>T * F) * top \ bot" + hence "top * e\<^sup>T * -F * v * F * e * top = bot" + using 33 by auto + hence "e\<^sup>T * -F * v * F * e = bot" + using 31 tarski comp_associative le_bot by fastforce + hence "top * (-F * v * F * e)\<^sup>T \ -(e\<^sup>T)" + by (metis comp_associative conv_complement_sub_leq conv_involutive p_bot schroeder_5_p) + hence "top * e\<^sup>T * F\<^sup>T * v\<^sup>T * -F\<^sup>T \ -(e\<^sup>T)" + by (simp add: comp_associative conv_complement conv_dist_comp) + hence "v * F * e * top * e\<^sup>T \ F" + by (metis assms(1, 4) comp_associative conv_dist_comp schroeder_3_p symmetric_top_closed) + hence "v * F * e * top * top * e\<^sup>T \ F" + by (simp add: comp_associative) + hence "v * F * e * top \ F * (top * e\<^sup>T)\<^sup>T" + using 32 by (metis shunt_bijective comp_associative conv_involutive) + hence "v * F * e * top \ F * e * top" + using comp_associative conv_dist_comp by auto + hence "v\<^sup>\ * F * e * top \ F * e * top" + using comp_associative star_left_induct_mult_iff by auto + hence "e\<^sup>T * F * e * top \ F * e * top" + by (meson assms(9) mult_left_isotone order_trans) + hence "e\<^sup>T * F * e * top * (e * top)\<^sup>T \ F" + using 32 shunt_bijective assms(3) mult_assoc by auto + hence 34: "e\<^sup>T * F * e * top * top * e\<^sup>T \ F" + by (metis conv_dist_comp mult.semigroup_axioms symmetric_top_closed semigroup.assoc) + hence "e\<^sup>T \ F" + proof - + have "e\<^sup>T \ e\<^sup>T * e * e\<^sup>T" + by (metis conv_involutive ex231c) + also have "... \ e\<^sup>T * F * e * e\<^sup>T" + using assms(1) comp_associative mult_left_isotone mult_right_isotone by fastforce + also have "... \ e\<^sup>T * F * e * top * top * e\<^sup>T" + by (simp add: mult_left_isotone top_right_mult_increasing vector_mult_closed) + finally show ?thesis + using 34 by simp + qed + hence 35: "e \ F" + using assms(1) conv_order by fastforce + have "top * (F * e)\<^sup>T \ - e" + using assms(8) comp_associative schroeder_4_p by auto + hence "top * e\<^sup>T * F \ - e" + by (simp add: assms(1) comp_associative conv_dist_comp) + hence "(top * e\<^sup>T)\<^sup>T * e \ - F" + using schroeder_3_p by auto + hence "e * top * e \ - F" + by (simp add: conv_dist_comp) + hence "e \ - F" + by (simp add: assms(3) arc_top_arc) + hence "e \ F \ - F" + using 35 inf.boundedI by blast + hence "e = bot" + using bot_unique by auto + thus "False" + using assms(10) by auto + qed + thus ?thesis + by (metis assms(3, 4, 6) arc_regular regular_closed_inf regular_closed_top regular_conv_closed regular_mult_closed semiring.mult_not_zero tarski) + qed + have "bijective (?i * top) \ bijective (?i\<^sup>T * top)" + using 1 2 3 arc_expanded by blast + thus ?thesis + by blast +qed + +subsubsection \Comparison of edge weights\ + +text \ +In this section we compare the weight of the \selected_edge\ with other edges of interest. +Theorems 8, 9, 10 and 11 are supporting lemmas. +For example, Theorem 8 is used to show that the \selected_edge\ has its source inside and its target outside the component it is chosen for. +\ + +text \Theorem 8\ + +lemma e_leq_c_c_complement_transpose_general: + assumes "e = minarc (c * -(c)\<^sup>T \ g)" + and "regular c" + shows "e \ c * -(c)\<^sup>T" +proof - + have "e \ -- (c * - c\<^sup>T \ g)" + using assms(1) minarc_below order_trans by blast + also have "... \ -- (c * - c\<^sup>T)" + using order_lesseq_imp pp_isotone_inf by blast + also have "... = c * - c\<^sup>T" + using assms(2) regular_mult_closed by auto + finally show ?thesis + by simp +qed + +text \Theorem 9\ + +lemma x_leq_c_transpose_general: + assumes "forest h" + and "vector c" + and "x\<^sup>T * top \ forest_components(h) * e * top" + and "e \ c * -c\<^sup>T" + and "c = forest_components(h) * c" + shows "x \ c\<^sup>T" +proof - + let ?H = "forest_components h" + have "x \ top * x" + using top_left_mult_increasing by blast + also have "... \ (?H * e * top)\<^sup>T" + using assms(3) conv_dist_comp conv_order by force + also have "... = top * e\<^sup>T * ?H" + using assms(1) comp_associative conv_dist_comp forest_components_equivalence by auto + also have "... \ top * (c * - c\<^sup>T)\<^sup>T * ?H" + by (simp add: assms(4) conv_isotone mult_left_isotone mult_right_isotone) + also have "... = top * (- c * c\<^sup>T) * ?H" + by (simp add: conv_complement conv_dist_comp) + also have "... \ top * c\<^sup>T * ?H" + by (metis mult_left_isotone top.extremum mult_assoc) + also have "... = c\<^sup>T * ?H" + using assms(1, 2) component_is_vector vector_conv_covector by auto + also have "... = c\<^sup>T" + by (metis assms(1, 5) fch_equivalence conv_dist_comp) + finally show ?thesis + by simp +qed + +text \Theorem 10\ + +lemma x_leq_c_complement_general: + assumes "vector c" + and "c * c\<^sup>T \ forest_components h" + and "x \ c\<^sup>T" + and "x \ -forest_components h" + shows "x \ -c" +proof - + let ?H = "forest_components h" + have "x \ - ?H \ c\<^sup>T" + using assms(3, 4) by auto + also have "... \ - c" + proof - + have "c \ c\<^sup>T \ ?H" + using assms(1, 2) vector_covector by auto + hence "-?H \ c \ c\<^sup>T \ bot" + using inf.sup_monoid.add_assoc p_antitone pseudo_complement by fastforce + thus ?thesis + using le_bot p_shunting_swap pseudo_complement by blast + qed + finally show ?thesis + by simp +qed + +text \Theorem 11\ + +lemma sum_e_below_sum_x_when_outgoing_same_component_general: + assumes "e = minarc (c * -(c)\<^sup>T \ g)" + and "regular c" + and "forest h" + and "vector c" + and "x\<^sup>T * top \ (forest_components h) * e * top" + and "c = (forest_components h) * c" + and "c * c\<^sup>T \ forest_components h" + and "x \ - forest_components h \ -- g" + and "symmetric g" + and "arc x" + and "c \ bot" + shows "sum (e \ g) \ sum (x \ g)" +proof - + let ?H = "forest_components h" + have 1:"e \ c * - c\<^sup>T" + using assms(1, 2) e_leq_c_c_complement_transpose_general by auto + have 2: "x \ c\<^sup>T" + using 1 assms(3, 4, 5, 6) x_leq_c_transpose_general by auto + hence "x \ -c" + using assms(4, 7, 8) x_leq_c_complement_general inf.boundedE by blast + hence "x \ - c \ c\<^sup>T" + using 2 by simp + hence "x \ - c * c\<^sup>T" + using assms(4) by (simp add: vector_complement_closed vector_covector) + hence "x\<^sup>T \ c\<^sup>T\<^sup>T * - c\<^sup>T" + by (metis conv_complement conv_dist_comp conv_isotone) + hence 3: "x\<^sup>T \ c * - c\<^sup>T" + by simp + hence "x \ -- g" + using assms(8) by auto + hence "x\<^sup>T \ -- g" + using assms(9) conv_complement conv_isotone by fastforce + hence "x\<^sup>T \ c * - c\<^sup>T \ -- g \ bot" + using 3 by (metis assms(10, 11) comp_inf.semiring.mult_not_zero conv_dist_comp + conv_involutive inf.orderE mult_right_zero top.extremum) + hence "x\<^sup>T \ c * - c\<^sup>T \ g \ bot" + using inf.sup_monoid.add_commute pp_inf_bot_iff by auto + hence "sum (minarc (c * - c\<^sup>T \ g) \ (c * - c\<^sup>T \ g)) \ sum (x\<^sup>T \ c * - c\<^sup>T \ g)" + using assms(10) minarc_min inf.sup_monoid.add_assoc by auto + hence "sum (e \ c * - c\<^sup>T \ g) \ sum (x\<^sup>T \ c * - c\<^sup>T \ g)" + using assms(1) inf.sup_monoid.add_assoc by auto + hence "sum (e \ g) \ sum (x\<^sup>T \ g)" + using 1 3 by (metis inf.orderE) + hence "sum (e \ g) \ sum (x \ g)" + using assms(9) sum_symmetric by auto + thus ?thesis + by simp +qed + +lemma sum_e_below_sum_x_when_outgoing_same_component: + assumes "symmetric g" + and "vector j" + and "forest h" + and "x \ - forest_components h \ -- g" + and "x\<^sup>T * top \ forest_components h * selected_edge h j g * top" + and "j \ bot" + and "arc x" + shows "sum (selected_edge h j g \ g) \ sum (x \ g)" +proof - + let ?e = "selected_edge h j g" + let ?c = "choose_component (forest_components h) j" + let ?H = "forest_components h" + show ?thesis + proof (rule sum_e_below_sum_x_when_outgoing_same_component_general) + next + show "?e = minarc (?c * - ?c\<^sup>T \ g)" + by simp + next + show "regular ?c" + using component_is_regular by auto + next + show "forest h" + by (simp add: assms(3)) + next + show "vector ?c" + by (simp add: assms(2, 6) component_is_vector) + next + show "x\<^sup>T * top \ ?H * ?e * top" + by (simp add: assms(5)) + next + show "?c = ?H * ?c" + using component_single by auto + next + show "?c * ?c\<^sup>T \ ?H" + by (simp add: component_is_connected) + next + show "x \ -?H \ -- g" + using assms(4) by auto + next + show "symmetric g" + by (simp add: assms(1)) + next + show "arc x" + by (simp add: assms(7)) + next + show "?c \ bot" + using assms(2, 5 , 6, 7) inf_bot_left le_bot minarc_bot mult_left_zero mult_right_zero by fastforce + qed +qed + +text \ +If there is a path in the \big_forest\ from an edge between components, $a$, to the \selected_edge\, $e$, then the weight of $e$ is no greater than the weight of $a$. +This is because either, +\begin{itemize} +\item the edges $a$ and $e$ are adjacent the same component so that we can use \sum_e_below_sum_x_when_outgoing_same_component\, or +\item there is at least one edge between $a$ and $e$, namely $x$, the edge incoming to the component that $e$ is outgoing from. + The path from $a$ to $e$ is split on $x$ using \big_forest_path_split_disj\. + We show that the weight of $e$ is no greater than the weight of $x$ by making use of lemma \sum_e_below_sum_x_when_outgoing_same_component\. + We define $x$ in a way that we can show that the weight of $x$ is no greater than the weight of $a$ using the invariant. + Then, it follows that the weight of $e$ is no greater than the weight of $a$ owing to transitivity. +\end{itemize} +\ + +lemma a_to_e_in_bigforest: + assumes "symmetric g" + and "f \ --g" + and "vector j" + and "forest h" + and "big_forest (forest_components h) d" + and "f \ f\<^sup>T = h \ h\<^sup>T \ d \ d\<^sup>T" + and "(\ a b . bf_between_arcs a b (forest_components h) d \ a \ -(forest_components h) \ -- g \ b \ d \ sum(b \ g) \ sum(a \ g))" + and "regular d" + and "j \ bot" + and "b = selected_edge h j g" + and "arc a" + and "bf_between_arcs a b (forest_components h) (d \ selected_edge h j g)" + and "a \ - forest_components h \ -- g" + and "regular h" + shows "sum (b \ g) \ sum (a \ g)" +proof - + let ?p = "path f h j g" + let ?e = "selected_edge h j g" + let ?F = "forest_components f" + let ?H = "forest_components h" + have "sum (b \ g) \ sum (a \ g)" + proof (cases "a\<^sup>T * top \ ?H * ?e * top") + case True + show "a\<^sup>T * top \ ?H * ?e * top \ sum (b \ g) \ sum (a \ g)" + proof- + have "sum (?e \ g) \ sum (a \ g)" + proof (rule sum_e_below_sum_x_when_outgoing_same_component) + show "symmetric g" + using assms(1) by auto + next + show "vector j" + using assms(3) by blast + next + show "forest h" + by (simp add: assms(4)) + next + show "a \ - ?H \ -- g" + using assms(13) by auto + next + show "a\<^sup>T * top \ ?H * ?e * top" + using True by auto + next + show "j \ bot" + by (simp add: assms(9)) + next + show "arc a" + by (simp add: assms(11)) + qed + thus ?thesis + using assms(10) by auto + qed + next + case False + show "\ a\<^sup>T * top \ ?H * ?e * top \ sum (b \ g) \ sum (a \ g)" + proof - + let ?d' = "d \ ?e" + let ?x = "d \ top * ?e\<^sup>T * ?H \ (?H * d\<^sup>T)\<^sup>\ * ?H * a\<^sup>T * top" + have 61: "arc (?x)" + proof (rule shows_arc_x) + show "big_forest ?H d" + by (simp add: assms(5)) + next + show "bf_between_arcs a ?e ?H d" + proof - + have 611: "bf_between_arcs a b ?H (d \ b)" + using assms(10, 12) by auto + have 616: "regular h" + using assms(14) by auto + have "regular a" + using 611 bf_between_arcs_def arc_regular by fastforce + thus ?thesis + using 616 by (smt big_forest_path_split_disj assms(4, 8, 10, 12) bf_between_arcs_def fch_equivalence minarc_regular regular_closed_star regular_conv_closed regular_mult_closed) + qed + next + show "(?H * d)\<^sup>+ \ - ?H" + using assms(5) big_forest_def by blast + next + show "\ a\<^sup>T * top \ ?H * ?e * top" + by (simp add: False) + next + show "regular a" + using assms(12) bf_between_arcs_def arc_regular by auto + next + show "regular ?e" + using minarc_regular by auto + next + show "regular ?H" + using assms(14) pp_dist_star regular_conv_closed regular_mult_closed by auto + next + show "regular d" + using assms(8) by auto + qed + have 62: "bijective (a\<^sup>T * top)" + by (simp add: assms(11)) + have 63: "bijective (?x * top)" + using 61 by simp + have 64: "?x \ (?H * d\<^sup>T)\<^sup>\ * ?H * a\<^sup>T * top" + by simp + hence "?x * top \ (?H * d\<^sup>T)\<^sup>\ * ?H * a\<^sup>T * top" + using mult_left_isotone inf_vector_comp by auto + hence "a\<^sup>T * top \ ((?H * d\<^sup>T)\<^sup>\ * ?H)\<^sup>T * ?x * top" + using 62 63 64 by (smt bijective_reverse mult_assoc) + also have "... = ?H * (d * ?H)\<^sup>\ * ?x * top" + using conv_dist_comp conv_star_commute by auto + also have "... = (?H * d)\<^sup>\ * ?H * ?x * top" + by (simp add: star_slide) + finally have "a\<^sup>T * top \ (?H * d)\<^sup>\ * ?H * ?x * top" + by simp + hence 65: "bf_between_arcs a ?x ?H d" + using 61 assms(12) bf_between_arcs_def by blast + have 66: "?x \ d" + by (simp add: inf.sup_monoid.add_assoc) + hence x_below_a: "sum (?x \ g) \ sum (a \ g)" + using 65 bf_between_arcs_def assms(7, 13) by blast + have "sum (?e \ g) \ sum (?x \ g)" + proof (rule sum_e_below_sum_x_when_outgoing_same_component) + show "symmetric g" + using assms(1) by auto + next + show "vector j" + using assms(3) by blast + next + show "forest h" + by (simp add: assms(4)) + next + show "?x \ - ?H \ -- g" + proof - + have 67: "?x \ - ?H" + using 66 assms(5) big_forest_def order_lesseq_imp by blast + have "?x \ d" + by (simp add: conv_isotone inf.sup_monoid.add_assoc) + also have "... \ f \ f\<^sup>T" + proof - + have "h \ h\<^sup>T \ d \ d\<^sup>T = f \ f\<^sup>T" + by (simp add: assms(6)) + thus ?thesis + by (metis (no_types) le_supE sup.absorb_iff2 sup.idem) + qed + also have "... \ -- g" + using assms(1, 2) conv_complement conv_isotone by fastforce + finally have "?x \ -- g" + by simp + thus ?thesis + by (simp add: 67) + qed + next + show "?x\<^sup>T * top \ ?H * ?e * top" + proof - + have "?x \ top * ?e\<^sup>T * ?H" + using inf.coboundedI1 by auto + hence "?x\<^sup>T \ ?H * ?e * top" + using conv_dist_comp conv_dist_inf conv_star_commute inf.orderI inf.sup_monoid.add_assoc inf.sup_monoid.add_commute mult_assoc by auto + hence "?x\<^sup>T * top \ ?H * ?e * top * top" + by (simp add: mult_left_isotone) + thus ?thesis + by (simp add: mult_assoc) + qed + next + show "j \ bot" + by (simp add: assms(9)) + next + show "arc (?x)" + using 61 by blast + qed + hence "sum (?e \ g) \ sum (a \ g)" + using x_below_a order.trans by blast + thus ?thesis + by (simp add: assms(10)) + qed + qed + thus ?thesis + by simp +qed + +subsubsection \Maintenance of algorithm invariants\ + +text \ +In this section, most of the work is done to maintain the invariants of the inner and outer loops of the algorithm. +In particular, we use \exists_a_w\ to maintain that $f$ can be extended to a minimum spanning forest. +\ + +lemma boruvka_exchange_spanning_inv: + assumes "forest v" + and "v\<^sup>\ * e\<^sup>T = e\<^sup>T" + and "i \ v \ top * e\<^sup>T * w\<^sup>T\<^sup>\" + and "arc i" + and "arc e" + and "v \ --g" + and "w \ --g" + and "e \ --g" + and "components g \ forest_components v" + shows "i \ (v \ -i)\<^sup>T\<^sup>\ * e\<^sup>T * top" +proof - + have 1: "(v \ -i \ -i\<^sup>T) * (v\<^sup>T \ -i \ -i\<^sup>T) \ 1" + using assms(1) comp_isotone order.trans inf.cobounded1 by blast + have 2: "bijective (i * top) \ bijective (e\<^sup>T * top)" + using assms(4, 5) mult_assoc by auto + have "i \ v * (top * e\<^sup>T * w\<^sup>T\<^sup>\)\<^sup>T" + using assms(3) covector_mult_closed covector_restrict_comp_conv order_lesseq_imp vector_top_closed by blast + also have "... \ v * w\<^sup>T\<^sup>\\<^sup>T * e\<^sup>T\<^sup>T * top\<^sup>T" + by (simp add: comp_associative conv_dist_comp) + also have "... \ v * w\<^sup>\ * e * top" + by (simp add: conv_star_commute) + also have "... = v * w\<^sup>\ * e * e\<^sup>T * e * top" + using assms(5) arc_eq_1 by (simp add: comp_associative) + also have "... \ v * w\<^sup>\ * e * e\<^sup>T * top" + by (simp add: comp_associative mult_right_isotone) + also have "... \ (--g) * (--g)\<^sup>\ * (--g) * e\<^sup>T * top" + using assms(6, 7, 8) by (simp add: comp_isotone star_isotone) + also have "... \ (--g)\<^sup>\ * e\<^sup>T * top" + by (metis comp_isotone mult_left_isotone star.circ_increasing star.circ_transitive_equal) + also have "... \ v\<^sup>T\<^sup>\ * v\<^sup>\ * e\<^sup>T * top" + by (simp add: assms(9) mult_left_isotone) + also have "... \ v\<^sup>T\<^sup>\ * e\<^sup>T * top" + by (simp add: assms(2) comp_associative) + finally have "i \ v\<^sup>T\<^sup>\ * e\<^sup>T * top" + by simp + hence "i * top \ v\<^sup>T\<^sup>\ * e\<^sup>T * top" + by (metis comp_associative mult_left_isotone vector_top_closed) + hence "e\<^sup>T * top \ v\<^sup>T\<^sup>\\<^sup>T * i * top" + using 2 by (metis bijective_reverse mult_assoc) + also have "... = v\<^sup>\ * i * top" + by (simp add: conv_star_commute) + also have "... \ (v \ -i \ -i\<^sup>T)\<^sup>\ * i * top" + proof - + have 3: "i * top \ (v \ -i \ -i\<^sup>T)\<^sup>\ * i * top" + using star.circ_loop_fixpoint sup_right_divisibility mult_assoc by auto + have "(v \ i) * (v \ -i \ -i\<^sup>T)\<^sup>\ * i * top \ i * top * i * top" + by (metis comp_isotone inf.cobounded1 inf.sup_monoid.add_commute mult_left_isotone top.extremum) + also have "... \ i * top" + by simp + finally have 4: "(v \ i) * (v \ -i \ -i\<^sup>T)\<^sup>\ * i * top \ (v \ -i \ -i\<^sup>T)\<^sup>\ * i * top" + using 3 dual_order.trans by blast + have 5: "(v \ -i \ -i\<^sup>T) * (v \ -i \ -i\<^sup>T)\<^sup>\ * i * top \ (v \ -i \ -i\<^sup>T)\<^sup>\ * i * top" + by (metis mult_left_isotone star.circ_increasing star.left_plus_circ) + have "v\<^sup>+ \ -1" + by (simp add: assms(1)) + hence "v * v \ -1" + by (metis mult_left_isotone order_trans star.circ_increasing star.circ_plus_same) + hence "v * 1 \ -v\<^sup>T" + by (simp add: schroeder_5_p) + hence "v \ -v\<^sup>T" + by simp + hence "v \ v\<^sup>T \ bot" + by (simp add: bot_unique pseudo_complement) + hence 7: "v \ i\<^sup>T \ bot" + by (metis assms(3) comp_inf.mult_right_isotone conv_dist_inf inf.boundedE inf.le_iff_sup le_bot) + hence "(v \ i\<^sup>T) * (v \ -i \ -i\<^sup>T)\<^sup>\ * i * top \ bot" + using le_bot semiring.mult_zero_left by fastforce + hence 6: "(v \ i\<^sup>T) * (v \ -i \ -i\<^sup>T)\<^sup>\ * i * top \ (v \ -i \ -i\<^sup>T)\<^sup>\ * i * top" + using bot_least le_bot by blast + have 8: "v = (v \ i) \ (v \ i\<^sup>T) \ (v \ -i \ -i\<^sup>T)" + proof - + have 81: "regular i" + by (simp add: assms(4) arc_regular) + have "(v \ i\<^sup>T) \ (v \ -i \ -i\<^sup>T) = (v \ -i)" + using 7 by (metis comp_inf.coreflexive_comp_inf_complement inf_import_p inf_p le_bot maddux_3_11_pp top.extremum) + hence "(v \ i) \ (v \ i\<^sup>T) \ (v \ -i \ -i\<^sup>T) = (v \ i) \ (v \ -i)" + by (simp add: sup.semigroup_axioms semigroup.assoc) + also have "... = v" + using 81 by (metis maddux_3_11_pp) + finally show ?thesis + by simp + qed + have "(v \ i) * (v \ -i \ -i\<^sup>T)\<^sup>\ * i * top \ (v \ i\<^sup>T) * (v \ -i \ -i\<^sup>T)\<^sup>\ * i * top \ (v \ -i \ -i\<^sup>T) * (v \ -i \ -i\<^sup>T)\<^sup>\ * i * top \ (v \ -i \ -i\<^sup>T)\<^sup>\ * i * top" + using 4 5 6 by simp + hence "((v \ i) \ (v \ i\<^sup>T) \ (v \ -i \ -i\<^sup>T)) * (v \ -i \ -i\<^sup>T)\<^sup>\ * i * top \ (v \ -i \ -i\<^sup>T)\<^sup>\ * i * top" + by (simp add: mult_right_dist_sup) + hence "v * (v \ -i \ -i\<^sup>T)\<^sup>\ * i * top \ (v \ -i \ -i\<^sup>T)\<^sup>\ * i * top" + using 8 by auto + hence "i * top \ v * (v \ -i \ -i\<^sup>T)\<^sup>\ * i * top \ (v \ -i \ -i\<^sup>T)\<^sup>\ * i * top" + using 3 by auto + hence 9:"v\<^sup>\ * (v \ -i \ -i\<^sup>T)\<^sup>\ * i * top \ (v \ -i \ -i\<^sup>T)\<^sup>\ * i * top" + by (simp add: star_left_induct_mult mult_assoc) + have "v\<^sup>\ * i * top \ v\<^sup>\ * (v \ -i \ -i\<^sup>T)\<^sup>\ * i * top" + using 3 mult_right_isotone mult_assoc by auto + thus ?thesis + using 9 order.trans by blast + qed + finally have "e\<^sup>T * top \ (v \ -i \ -i\<^sup>T)\<^sup>\ * i * top" + by simp + hence "i * top \ (v \ -i \ -i\<^sup>T)\<^sup>\\<^sup>T * e\<^sup>T * top" + using 2 by (metis bijective_reverse mult_assoc) + also have "... = (v\<^sup>T \ -i \ -i\<^sup>T)\<^sup>\ * e\<^sup>T * top" + using comp_inf.inf_vector_comp conv_complement conv_dist_inf conv_star_commute inf.sup_monoid.add_commute by auto + also have "... \ ((v \ -i \ -i\<^sup>T) \ (v\<^sup>T \ -i \ -i\<^sup>T))\<^sup>\ * e\<^sup>T * top" + by (simp add: mult_left_isotone star_isotone) + finally have "i \ ((v\<^sup>T \ -i \ -i\<^sup>T) \ (v \ -i \ -i\<^sup>T))\<^sup>\ * e\<^sup>T * top" + using dual_order.trans top_right_mult_increasing sup_commute by auto + also have "... = (v\<^sup>T \ -i \ -i\<^sup>T)\<^sup>\ * (v \ -i \ -i\<^sup>T)\<^sup>\ * e\<^sup>T * top" + using 1 cancel_separate_1 by (simp add: sup_commute) + also have "... \ (v\<^sup>T \ -i \ -i\<^sup>T)\<^sup>\ * v\<^sup>\ * e\<^sup>T * top" + by (simp add: inf_assoc mult_left_isotone mult_right_isotone star_isotone) + also have "... = (v\<^sup>T \ -i \ -i\<^sup>T)\<^sup>\ * e\<^sup>T * top" + using assms(2) mult_assoc by simp + also have "... \ (v\<^sup>T \ -i\<^sup>T)\<^sup>\ * e\<^sup>T * top" + by (metis mult_left_isotone star_isotone inf.cobounded2 inf.left_commute inf.sup_monoid.add_commute) + also have "... = (v \ -i)\<^sup>T\<^sup>\ * e\<^sup>T * top" + using conv_complement conv_dist_inf by auto + finally show ?thesis + by simp +qed + +lemma exists_a_w: + assumes "symmetric g" + and "forest f" + and "f \ --g" + and "regular f" + and "(\w . minimum_spanning_forest w g \ f \ w \ w\<^sup>T)" + and "vector j" + and "regular j" + and "forest h" + and "forest_components h \ forest_components f" + and "big_forest (forest_components h) d" + and "d * top \ - j" + and "forest_components h * j = j" + and "forest_components f = (forest_components h * (d \ d\<^sup>T))\<^sup>\ * forest_components h" + and "f \ f\<^sup>T = h \ h\<^sup>T \ d \ d\<^sup>T" + and "(\ a b . bf_between_arcs a b (forest_components h) d \ a \ -(forest_components h) \ -- g \ b \ d \ sum(b \ g) \ sum(a \ g))" + and "regular d" + and "selected_edge h j g \ - forest_components f" + and "selected_edge h j g \ bot" + and "j \ bot" + and "regular h" + and "h \ --g" + shows "\w. minimum_spanning_forest w g \ + f \ - (selected_edge h j g)\<^sup>T \ - (path f h j g) \ (f \ - (selected_edge h j g)\<^sup>T \ (path f h j g))\<^sup>T \ (selected_edge h j g) \ w \ w\<^sup>T" +proof - + let ?p = "path f h j g" + let ?e = "selected_edge h j g" + let ?f = "(f \ -?e\<^sup>T \ -?p) \ (f \ -?e\<^sup>T \ ?p)\<^sup>T \ ?e" + let ?F = "forest_components f" + let ?H = "forest_components h" + let ?ec = "choose_component (forest_components h) j * - choose_component (forest_components h) j\<^sup>T \ g" + from assms(4) obtain w where 2: "minimum_spanning_forest w g \ f \ w \ w\<^sup>T" + using assms(5) by blast + hence 3: "regular w \ regular f \ regular ?e" + by (metis assms(4) minarc_regular minimum_spanning_forest_def spanning_forest_def) + have 5: "equivalence ?F" + using assms(2) forest_components_equivalence by auto + have "?e\<^sup>T * top * ?e\<^sup>T = ?e\<^sup>T" + by (metis arc_conv_closed arc_top_arc coreflexive_bot_closed coreflexive_symmetric minarc_arc minarc_bot_iff semiring.mult_not_zero) + hence "?e\<^sup>T * top * ?e\<^sup>T \ -?F" + using 5 assms(17) conv_complement conv_isotone by fastforce + hence 6: "?e * ?F * ?e = bot" + using assms(2) le_bot triple_schroeder_p by simp + let ?q = "w \ top * ?e * w\<^sup>T\<^sup>\" + let ?v = "(w \ -(top * ?e * w\<^sup>T\<^sup>\)) \ ?q\<^sup>T" + have 7: "regular ?q" + using 3 regular_closed_star regular_conv_closed regular_mult_closed by auto + have 8: "injective ?v" + proof (rule kruskal_exchange_injective_inv_1) + show "injective w" + using 2 minimum_spanning_forest_def spanning_forest_def by blast + next + show "covector (top * ?e * w\<^sup>T\<^sup>\)" + by (simp add: covector_mult_closed) + next + show "top * ?e * w\<^sup>T\<^sup>\ * w\<^sup>T \ top * ?e * w\<^sup>T\<^sup>\" + by (simp add: mult_right_isotone star.right_plus_below_circ mult_assoc) + next + show "coreflexive ((top * ?e * w\<^sup>T\<^sup>\)\<^sup>T * (top * ?e * w\<^sup>T\<^sup>\) \ w\<^sup>T * w)" + using 2 by (metis comp_inf.semiring.mult_not_zero forest_bot kruskal_injective_inv_3 minarc_arc minarc_bot_iff minimum_spanning_forest_def semiring.mult_not_zero spanning_forest_def) + qed + have 9: "components g \ forest_components ?v" + proof (rule kruskal_exchange_spanning_inv_1) + show "injective (w \ - (top *?e * w\<^sup>T\<^sup>\) \ (w \ top * ?e * w\<^sup>T\<^sup>\)\<^sup>T)" + using 8 by simp + next + show "regular (w \ top * ?e * w\<^sup>T\<^sup>\)" + using 7 by simp + next + show "components g \ forest_components w" + using 2 minimum_spanning_forest_def spanning_forest_def by blast + qed + have 10: "spanning_forest ?v g" + proof (unfold spanning_forest_def, intro conjI) + show "injective ?v" + using 8 by auto + next + show "acyclic ?v" + proof (rule kruskal_exchange_acyclic_inv_1) + show "pd_kleene_allegory_class.acyclic w" + using 2 minimum_spanning_forest_def spanning_forest_def by blast + next + show "covector (top * ?e * w\<^sup>T\<^sup>\)" + by (simp add: covector_mult_closed) + qed + next + show "?v \ --g" + proof (rule sup_least) + show "w \ - (top * ?e * w\<^sup>T\<^sup>\) \ - - g" + using 7 inf.coboundedI1 minimum_spanning_forest_def spanning_forest_def 2 by blast + next + show "(w \ top * ?e * w\<^sup>T\<^sup>\)\<^sup>T \ - - g" + using 2 by (metis assms(1) conv_complement conv_isotone inf.coboundedI1 minimum_spanning_forest_def spanning_forest_def) + qed + next + show "components g \ forest_components ?v" + using 9 by simp + next + show "regular ?v" + using 3 regular_closed_star regular_conv_closed regular_mult_closed by auto + qed + have 11: "sum (?v \ g) = sum (w \ g)" + proof - + have "sum (?v \ g) = sum (w \ -(top * ?e * w\<^sup>T\<^sup>\) \ g) + sum (?q\<^sup>T \ g)" + using 2 by (smt conv_complement conv_top epm_8 inf_import_p inf_top_right regular_closed_top vector_top_closed minimum_spanning_forest_def spanning_forest_def sum_disjoint) + also have "... = sum (w \ -(top * ?e * w\<^sup>T\<^sup>\) \ g) + sum (?q \ g)" + by (simp add: assms(1) sum_symmetric) + also have "... = sum (((w \ -(top * ?e * w\<^sup>T\<^sup>\)) \ ?q) \ g)" + using inf_commute inf_left_commute sum_disjoint by simp + also have "... = sum (w \ g)" + using 3 7 8 maddux_3_11_pp by auto + finally show ?thesis + by simp + qed + have 12: "?v \ ?v\<^sup>T = w \ w\<^sup>T" + proof - + have "?v \ ?v\<^sup>T = (w \ -?q) \ ?q\<^sup>T \ (w\<^sup>T \ -?q\<^sup>T) \ ?q" + using conv_complement conv_dist_inf conv_dist_sup inf_import_p sup_assoc by simp + also have "... = w \ w\<^sup>T" + using 3 7 conv_complement conv_dist_inf inf_import_p maddux_3_11_pp sup_monoid.add_assoc sup_monoid.add_commute by auto + finally show ?thesis + by simp + qed + have 13: "?v * ?e\<^sup>T = bot" + proof (rule kruskal_reroot_edge) + show "injective (?e\<^sup>T * top)" + using assms(18) minarc_arc minarc_bot_iff by blast + next + show "pd_kleene_allegory_class.acyclic w" + using 2 minimum_spanning_forest_def spanning_forest_def by simp + qed + have "?v \ ?e \ ?v \ top * ?e" + using inf.sup_right_isotone top_left_mult_increasing by simp + also have "... \ ?v * (top * ?e)\<^sup>T" + using covector_restrict_comp_conv covector_mult_closed vector_top_closed by simp + finally have 14: "?v \ ?e = bot" + using 13 by (metis conv_dist_comp mult_assoc le_bot mult_left_zero) + let ?i = "?v \ (- ?F) * ?e * top \ top * ?e\<^sup>T * ?F" + let ?w = "(?v \ -?i) \ ?e" + have 15: "regular ?i" + using 3 regular_closed_star regular_conv_closed regular_mult_closed by simp + have 16: "?F \ -?i" + proof - + have 161: "bijective (?e * top)" + using assms(18) minarc_arc minarc_bot_iff by auto + have "?i \ - ?F * ?e * top" + using inf.cobounded2 inf.coboundedI1 by blast + also have "... = - (?F * ?e * top)" + using 161 comp_bijective_complement by (simp add: mult_assoc) + finally have "?i \ - (?F * ?e * top)" + by blast + hence 162: "?i \ ?F \ - (?F * ?e * top)" + using inf.coboundedI1 by blast + have "?i \ ?F \ ?F \ (top * ?e\<^sup>T * ?F)" + by (meson inf_le1 inf_le2 le_infI order_trans) + also have "... \ ?F * (top * ?e\<^sup>T * ?F)\<^sup>T" + by (simp add: covector_mult_closed covector_restrict_comp_conv) + also have "... = ?F * ?F\<^sup>T * ?e\<^sup>T\<^sup>T * top\<^sup>T" + by (simp add: conv_dist_comp mult_assoc) + also have "... = ?F * ?F * ?e * top" + by (simp add: conv_dist_comp conv_star_commute) + also have "... = ?F * ?e * top" + by (simp add: 5 preorder_idempotent) + finally have "?i \ ?F \ ?F * ?e * top" + by simp + hence "?i \ ?F \ ?F * ?e * top \ - (?F * ?e * top)" + using 162 inf.bounded_iff by blast + also have "... = bot" + by simp + finally show ?thesis + using le_bot p_antitone_iff pseudo_complement by blast + qed + have 17: "?i \ top * ?e\<^sup>T * (?F \ ?v \ -?i)\<^sup>T\<^sup>\" + proof - + have "?i \ ?v \ - ?F * ?e * top \ top * ?e\<^sup>T * (?F \ ?v)\<^sup>T\<^sup>\ * (?F \ ?v)\<^sup>\" + using 2 8 12 by (smt inf.sup_right_isotone kruskal_forest_components_inf mult_right_isotone mult_assoc) + also have "... = ?v \ - ?F * ?e * top \ top * ?e\<^sup>T * (?F \ ?v)\<^sup>T\<^sup>\ * (1 \ (?F \ ?v)\<^sup>\ * (?F \ ?v))" + using star_left_unfold_equal star.circ_right_unfold_1 by auto + also have "... = ?v \ - ?F * ?e * top \ (top * ?e\<^sup>T * (?F \ ?v)\<^sup>T\<^sup>\ \ top * ?e\<^sup>T * (?F \ ?v)\<^sup>T\<^sup>\ * (?F \ ?v)\<^sup>\ * (?F \ ?v))" + by (simp add: mult_left_dist_sup mult_assoc) + also have "... = (?v \ - ?F * ?e * top \ top * ?e\<^sup>T * (?F \ ?v)\<^sup>T\<^sup>\) \ (?v \ - ?F * ?e * top \ top * ?e\<^sup>T * (?F \ ?v)\<^sup>T\<^sup>\ * (?F \ ?v)\<^sup>\ * (?F \ ?v))" + using comp_inf.semiring.distrib_left by blast + also have "... \ top * ?e\<^sup>T * (?F \ ?v)\<^sup>T\<^sup>\ \ (?v \ - ?F * ?e * top \ top * ?e\<^sup>T * (?F \ ?v)\<^sup>T\<^sup>\ * (?F \ ?v)\<^sup>\ * (?F \ ?v))" + using comp_inf.semiring.add_right_mono inf_le2 by blast + also have "... \ top * ?e\<^sup>T * (?F \ ?v)\<^sup>T\<^sup>\ \ (?v \ - ?F * ?e * top \ top * ?e\<^sup>T * (?F\<^sup>T \ ?v\<^sup>T)\<^sup>\ * (?F \ ?v)\<^sup>\ * (?F \ ?v))" + by (simp add: conv_dist_inf) + also have "... \ top * ?e\<^sup>T * (?F \ ?v)\<^sup>T\<^sup>\ \ (?v \ - ?F * ?e * top \ top * ?e\<^sup>T * ?F\<^sup>T\<^sup>\ * ?F\<^sup>\ * (?F \ ?v))" + proof - + have "top * ?e\<^sup>T * (?F\<^sup>T \ ?v\<^sup>T)\<^sup>\ * (?F \ ?v)\<^sup>\ * (?F \ ?v) \ top * ?e\<^sup>T * ?F\<^sup>T\<^sup>\ * ?F\<^sup>\ * (?F \ ?v)" + using star_isotone by (simp add: comp_isotone) + hence "?v \ - ?F * ?e * top \ top * ?e\<^sup>T * (?F\<^sup>T \ ?v\<^sup>T)\<^sup>\ * (?F \ ?v)\<^sup>\ * (?F \ ?v) \ ?v \ - ?F * ?e * top \ top * ?e\<^sup>T * ?F\<^sup>T\<^sup>\ * ?F\<^sup>\ * (?F \ ?v)" + using inf.sup_right_isotone by blast + thus ?thesis + using sup_right_isotone by blast + qed + also have "... = top * ?e\<^sup>T * (?F \ ?v)\<^sup>T\<^sup>\ \ (?v \ - ?F * ?e * top \ top * ?e\<^sup>T * ?F\<^sup>\ * ?F\<^sup>\ * (?F \ ?v))" + using 5 by auto + also have "... = top * ?e\<^sup>T * (?F \ ?v)\<^sup>T\<^sup>\ \ (?v \ - ?F * ?e * top \ top * ?e\<^sup>T * ?F * ?F * (?F \ ?v))" + by (simp add: assms(2) forest_components_star) + also have "... = top * ?e\<^sup>T * (?F \ ?v)\<^sup>T\<^sup>\ \ (?v \ - ?F * ?e * top \ top * ?e\<^sup>T * ?F * (?F \ ?v))" + using 5 mult.semigroup_axioms preorder_idempotent semigroup.assoc by fastforce + also have "... = top * ?e\<^sup>T * (?F \ ?v)\<^sup>T\<^sup>\" + proof - + have "?e * top * ?e\<^sup>T \ 1" + using assms(18) arc_expanded minarc_arc minarc_bot_iff by auto + hence "?F * ?e * top * ?e\<^sup>T \ ?F * 1" + by (metis comp_associative comp_isotone mult_semi_associative star.circ_transitive_equal) + hence "?v * ?v\<^sup>T * ?F * ?e * top * ?e\<^sup>T \ 1 * ?F * 1" + using 8 by (smt comp_isotone mult_assoc) + hence 171: "?v * ?v\<^sup>T * ?F * ?e * top * ?e\<^sup>T \ ?F" + by simp + hence "?v * (?F \ ?v)\<^sup>T * ?F * ?e * top * ?e\<^sup>T \ ?F" + proof - + have "?v * (?F \ ?v)\<^sup>T * ?F * ?e * top * ?e\<^sup>T \ ?v * ?v\<^sup>T * ?F * ?e * top * ?e\<^sup>T" + by (simp add: conv_dist_inf mult_left_isotone mult_right_isotone) + thus ?thesis + using 171 order_trans by blast + qed + hence 172: "-?F * ((?F \ ?v)\<^sup>T * ?F * ?e * top * ?e\<^sup>T)\<^sup>T \ -?v" + by (smt schroeder_4_p comp_associative order_lesseq_imp pp_increasing) + have "-?F * ((?F \ ?v)\<^sup>T * ?F * ?e * top * ?e\<^sup>T)\<^sup>T = -?F * ?e\<^sup>T\<^sup>T * top\<^sup>T * ?e\<^sup>T * ?F\<^sup>T * (?F \ ?v)\<^sup>T\<^sup>T" + by (simp add: comp_associative conv_dist_comp) + also have "... = -?F * ?e * top * ?e\<^sup>T * ?F * (?F \ ?v)" + using 5 by auto + also have "... = -?F * ?e * top * top * ?e\<^sup>T * ?F * (?F \ ?v)" + using comp_associative by auto + also have "... = -?F * ?e * top \ top * ?e\<^sup>T * ?F * (?F \ ?v)" + by (smt comp_associative comp_inf.star.circ_decompose_9 comp_inf.star_star_absorb comp_inf_covector inf_vector_comp vector_top_closed) + finally have "-?F * ((?F \ ?v)\<^sup>T * ?F * ?e * top * ?e\<^sup>T)\<^sup>T = -?F * ?e * top \ top * ?e\<^sup>T * ?F * (?F \ ?v)" + by simp + hence "-?F * ?e * top \ top * ?e\<^sup>T * ?F * (?F \ ?v) \ -?v" + using 172 by auto + hence "?v \ -?F * ?e * top \ top * ?e\<^sup>T * ?F * (?F \ ?v) \ bot" + by (smt bot_unique inf.sup_monoid.add_commute p_shunting_swap pseudo_complement) + thus ?thesis + using le_bot sup_monoid.add_0_right by blast + qed + also have "... = top * ?e\<^sup>T * (?F \ ?v \ -?i)\<^sup>T\<^sup>\" + using 16 by (smt comp_inf.coreflexive_comp_inf_complement inf_top_right p_bot pseudo_complement top.extremum) + finally show ?thesis + by blast + qed + have 18: "?i \ top * ?e\<^sup>T * ?w\<^sup>T\<^sup>\" + proof - + have "?i \ top * ?e\<^sup>T * (?F \ ?v \ -?i)\<^sup>T\<^sup>\" + using 17 by simp + also have "... \ top * ?e\<^sup>T * (?v \ -?i)\<^sup>T\<^sup>\" + using mult_right_isotone conv_isotone star_isotone inf.cobounded2 inf.sup_monoid.add_assoc by (simp add: inf.sup_monoid.add_assoc eq_iff inf.sup_monoid.add_commute) + also have "... \ top * ?e\<^sup>T * ((?v \ -?i) \ ?e)\<^sup>T\<^sup>\" + using mult_right_isotone conv_isotone star_isotone sup_ge1 by simp + finally show ?thesis + by blast + qed + have 19: "?i \ top * ?e\<^sup>T * ?v\<^sup>T\<^sup>\" + proof - + have "?i \ top * ?e\<^sup>T * (?F \ ?v \ -?i)\<^sup>T\<^sup>\" + using 17 by simp + also have "... \ top * ?e\<^sup>T * (?v \ -?i)\<^sup>T\<^sup>\" + using mult_right_isotone conv_isotone star_isotone inf.cobounded2 inf.sup_monoid.add_assoc by (simp add: inf.sup_monoid.add_assoc eq_iff inf.sup_monoid.add_commute) + also have "... \ top * ?e\<^sup>T * (?v)\<^sup>T\<^sup>\" + using mult_right_isotone conv_isotone star_isotone by auto + finally show ?thesis + by blast + qed + have 20: "f \ f\<^sup>T \ (?v \ -?i \ -?i\<^sup>T) \ (?v\<^sup>T \ -?i \ -?i\<^sup>T)" + proof (rule kruskal_edge_between_components_2) + show "?F \ - ?i" + using 16 by simp + next + show "injective f" + by (simp add: assms(2)) + next + show "f \ f\<^sup>T \ w \ - (top * ?e * w\<^sup>T\<^sup>\) \ (w \ top * ?e * w\<^sup>T\<^sup>\)\<^sup>T \ (w \ - (top * ?e * w\<^sup>T\<^sup>\) \ (w \ top * ?e * w\<^sup>T\<^sup>\)\<^sup>T)\<^sup>T" + using 2 12 by (metis conv_dist_sup conv_involutive conv_isotone le_supI sup_commute) + qed + have "minimum_spanning_forest ?w g \ ?f \ ?w \ ?w\<^sup>T" + proof (intro conjI) + have 211: "?e\<^sup>T \ ?v\<^sup>\" + proof (rule kruskal_edge_arc_1[where g=g and h="?ec"]) + show "?e \ -- ?ec" + using minarc_below by blast + next + show "?ec \ g" + using assms(4) inf.cobounded2 by (simp add: boruvka_inner_invariant_def boruvka_outer_invariant_def conv_dist_inf) + next + show "symmetric g" + by (meson assms(1) boruvka_inner_invariant_def boruvka_outer_invariant_def) + next + show "components g \ forest_components (w \ - (top * ?e * w\<^sup>T\<^sup>\) \ (w \ top * ?e * w\<^sup>T\<^sup>\)\<^sup>T)" + using 9 by simp + next + show "(w \ - (top * ?e * w\<^sup>T\<^sup>\) \ (w \ top * ?e * w\<^sup>T\<^sup>\)\<^sup>T) * ?e\<^sup>T = bot" + using 13 by blast + qed + have 212: "arc ?i" + proof (rule boruvka_edge_arc) + show "equivalence ?F" + by (simp add: 5) + next + show "forest ?v" + using 10 spanning_forest_def by blast + next + show "arc ?e" + using assms(18) minarc_arc minarc_bot_iff by blast + next + show "regular ?F" + using 3 regular_closed_star regular_conv_closed regular_mult_closed by auto + next + show "?F \ forest_components (?F \ ?v)" + by (simp add: 12 2 8 kruskal_forest_components_inf) + next + show "regular ?v" + using 10 spanning_forest_def by blast + next + show "?v * ?e\<^sup>T = bot" + using 13 by auto + next + show "?e * ?F * ?e = bot" + by (simp add: 6) + next + show "?e\<^sup>T \ ?v\<^sup>\" + using 211 by auto + + next + show "?e \ bot" + by (simp add: assms(18)) + qed + show "minimum_spanning_forest ?w g" + proof (unfold minimum_spanning_forest_def, intro conjI) + have "(?v \ -?i) * ?e\<^sup>T \ ?v * ?e\<^sup>T" + using inf_le1 mult_left_isotone by simp + hence "(?v \ -?i) * ?e\<^sup>T = bot" + using 13 le_bot by simp + hence 221: "?e * (?v \ -?i)\<^sup>T = bot" + using conv_dist_comp conv_involutive conv_bot by force + have 222: "injective ?w" + proof (rule injective_sup) + show "injective (?v \ -?i)" + using 8 by (simp add: injective_inf_closed) + next + show "coreflexive (?e * (?v \ -?i)\<^sup>T)" + using 221 by simp + next + show "injective ?e" + by (metis arc_injective minarc_arc coreflexive_bot_closed coreflexive_injective minarc_bot_iff) + qed + show "spanning_forest ?w g" + proof (unfold spanning_forest_def, intro conjI) + show "injective ?w" + using 222 by simp + next + show "acyclic ?w" + proof (rule kruskal_exchange_acyclic_inv_2) + show "acyclic ?v" + using 10 spanning_forest_def by blast + next + show "injective ?v" + using 8 by simp + next + show "?i \?v" + using inf.coboundedI1 by simp + next + show "bijective (?i\<^sup>T * top)" + using 212 by simp + next + show "bijective (?e * top)" + using 14 212 by (smt assms(4) comp_inf.idempotent_bot_closed conv_complement minarc_arc minarc_bot_iff p_bot regular_closed_bot semiring.mult_not_zero symmetric_top_closed) + next + show "?i \ top * ?e\<^sup>T *?v\<^sup>T\<^sup>\" + using 19 by simp + next + show "?v * ?e\<^sup>T * top = bot" + using 13 by simp + qed + next + have "?w \ ?v \ ?e" + using inf_le1 sup_left_isotone by simp + also have "... \ --g \ ?e" + using 10 sup_left_isotone spanning_forest_def by blast + also have "... \ --g \ --h" + proof - + have 1: "--g \ --g \ --h" + by simp + have 2: "?e \ --g \ --h" + by (metis inf.coboundedI1 inf.sup_monoid.add_commute minarc_below order.trans p_dist_inf p_dist_sup sup.cobounded1) + thus ?thesis + using 1 2 by simp + qed + also have "... \ --g" + using assms(20, 21) by auto + finally show "?w \ --g" + by simp + next + have 223: "?i \ (?v \ -?i)\<^sup>T\<^sup>\ * ?e\<^sup>T * top" + proof (rule boruvka_exchange_spanning_inv) + show "forest ?v" + using 10 spanning_forest_def by blast + next + show "?v\<^sup>\ * ?e\<^sup>T = ?e\<^sup>T" + using 13 by (smt conv_complement conv_dist_comp conv_involutive conv_star_commute dense_pp fc_top regular_closed_top star_absorb) + next + show "?i \ ?v \ top * ?e\<^sup>T * ?w\<^sup>T\<^sup>\" + using 18 inf.sup_monoid.add_assoc by auto + next + show "arc ?i" + using 212 by blast + next + show "arc ?e" + using assms(18) minarc_arc minarc_bot_iff by auto + next + show "?v \ --g" + using 10 spanning_forest_def by blast + next + show "?w \ --g" + proof - + have 2231: "?e \ --g" + by (metis inf.boundedE minarc_below pp_dist_inf) + have "?w \ ?v \ ?e" + using inf_le1 sup_left_isotone by simp + also have "... \ --g" + using 2231 10 spanning_forest_def sup_least by blast + finally show ?thesis + by blast + qed + next + show "?e \ --g" + by (metis inf.boundedE minarc_below pp_dist_inf) + next + show "components g \ forest_components ?v" + by (simp add: 9) + qed + have "components g \ forest_components ?v" + using 10 spanning_forest_def by auto + also have "... \ forest_components ?w" + proof (rule kruskal_exchange_forest_components_inv) + next + show "injective ((?v \ -?i) \ ?e)" + using 222 by simp + next + show "regular ?i" + using 15 by simp + next + show "?e * top * ?e = ?e" + by (metis arc_top_arc minarc_arc minarc_bot_iff semiring.mult_not_zero) + next + show "?i \ top * ?e\<^sup>T * ?v\<^sup>T\<^sup>\" + using 19 by blast + next + show "?v * ?e\<^sup>T * top = bot" + using 13 by simp + next + show "injective ?v" + using 8 by simp + next + show "?i \ ?v" + by (simp add: le_infI1) + next + show "?i \ (?v \ -?i)\<^sup>T\<^sup>\ * ?e\<^sup>T * top" + using 223 by blast + qed + finally show "components g \ forest_components ?w" + by simp + next + show "regular ?w" + using 3 7 regular_conv_closed by simp + qed + next + have 224: "?e \ g \ bot" + using assms(18) inf.left_commute inf_bot_right minarc_meet_bot by fastforce + have 225: "sum (?e \ g) \ sum (?i \ g)" + proof (rule a_to_e_in_bigforest) + show "symmetric g" + using assms(1) boruvka_inner_invariant_def boruvka_outer_invariant_def by auto + next + show "j \ bot" + by (simp add: assms(19)) + next + show "f \ -- g" + by (simp add: assms(3)) + next + show "vector j" + using assms(6) boruvka_inner_invariant_def by blast + next + show "forest h" + by (simp add: assms(8)) + next + show " big_forest (forest_components h) d" + by (simp add: assms(10)) + next + show "f \ f\<^sup>T = h \ h\<^sup>T \ d \ d\<^sup>T" + by (simp add: assms(14)) + next + show "\a b. bf_between_arcs a b (?H) d \ a \ - ?H \ - - g \ b \ d \ sum (b \ g) \ sum (a \ g)" + by (simp add: assms(15)) + next + show "regular d" + using assms(16) by auto + next + show "?e = ?e" + by simp + next + show "arc ?i" + using 212 by blast + next + show "bf_between_arcs ?i ?e ?H (d \ ?e)" + proof - + have "d\<^sup>T * ?H * ?e = bot" + using assms(6, 7, 11, 12, 19) dT_He_eq_bot le_bot by blast + hence 251: "d\<^sup>T * ?H * ?e \ (?H * d)\<^sup>\ * ?H * ?e" + by simp + hence "d\<^sup>T * ?H * ?H * ?e \ (?H * d)\<^sup>\ * ?H * ?e" + by (metis assms(8) forest_components_star star.circ_decompose_9 mult_assoc) + hence "d\<^sup>T * (?H * d)\<^sup>\ * ?H * ?e \ (?H * d)\<^sup>\ * ?H * ?e" + proof - + have "d\<^sup>T * ?H * d \ 1" + using assms(10) big_forest_def dTransHd_le_1 by blast + hence "d\<^sup>T * ?H * d * (?H * d)\<^sup>\ * ?H * ?e \ (?H * d)\<^sup>\ * ?H * ?e" + by (metis mult_left_isotone star.circ_circ_mult star_involutive star_one) + hence "d\<^sup>T * ?H * ?e \ d\<^sup>T * ?H * d * (?H * d)\<^sup>\ * ?H * ?e \ (?H * d)\<^sup>\ * ?H * ?e" + using 251 by simp + hence "d\<^sup>T * (1 \ ?H * d * (?H * d)\<^sup>\) * ?H * ?e \ (?H * d)\<^sup>\ * ?H * ?e" + by (simp add: comp_associative comp_left_dist_sup semiring.distrib_right) + thus ?thesis + by (simp add: star_left_unfold_equal) + qed + hence "?H * d\<^sup>T * (?H * d)\<^sup>\ * ?H * ?e \ ?H * (?H * d)\<^sup>\ * ?H * ?e" + by (simp add: mult_right_isotone mult_assoc) + hence "?H * d\<^sup>T * (?H * d)\<^sup>\ * ?H * ?e \ ?H * ?H * (d * ?H)\<^sup>\ * ?e" + by (smt star_slide mult_assoc) + hence "?H * d\<^sup>T * (?H * d)\<^sup>\ * ?H * ?e \ ?H * (d * ?H)\<^sup>\ * ?e" + by (metis assms(8) forest_components_star star.circ_decompose_9) + hence "?H * d\<^sup>T * (?H * d)\<^sup>\ * ?H * ?e \ (?H * d)\<^sup>\ * ?H * ?e" + using star_slide by auto + hence "?H * d * (?H * d)\<^sup>\ * ?H * ?e \ ?H * d\<^sup>T * (?H * d)\<^sup>\ * ?H * ?e \ (?H * d)\<^sup>\ * ?H * ?e" + by (smt le_supI star.circ_loop_fixpoint sup.cobounded2 sup_commute mult_assoc) + hence "(?H * (d \ d\<^sup>T)) * (?H * d)\<^sup>\ * ?H * ?e \ (?H * d)\<^sup>\ * ?H * ?e" + by (simp add: semiring.distrib_left semiring.distrib_right) + hence "(?H * (d \ d\<^sup>T))\<^sup>\ * (?H * d)\<^sup>\ * ?H * ?e \ (?H * d)\<^sup>\ * ?H * ?e" + by (simp add: star_left_induct_mult mult_assoc) + hence 252: "(?H * (d \ d\<^sup>T))\<^sup>\ * ?H * ?e \ (?H * d)\<^sup>\ * ?H * ?e" + by (smt mult_left_dist_sup star.circ_transitive_equal star_slide star_sup_1 mult_assoc) + have "?i \ top * ?e\<^sup>T * ?F" + by auto + hence "?i\<^sup>T \ ?F\<^sup>T * ?e\<^sup>T\<^sup>T * top\<^sup>T" + by (simp add: conv_dist_comp conv_dist_inf mult_assoc) + hence "?i\<^sup>T * top \ ?F\<^sup>T * ?e\<^sup>T\<^sup>T * top\<^sup>T * top" + using comp_isotone by blast + also have "... = ?F\<^sup>T * ?e\<^sup>T\<^sup>T * top\<^sup>T" + by (simp add: vector_mult_closed) + also have "... = ?F * ?e\<^sup>T\<^sup>T * top\<^sup>T" + by (simp add: conv_dist_comp conv_star_commute) + also have "... = ?F * ?e * top" + by simp + also have "... = (?H * (d \ d\<^sup>T))\<^sup>\ * ?H * ?e * top" + by (simp add: assms(13)) + also have "... \ (?H * d)\<^sup>\ * ?H * ?e * top" + by (simp add: 252 comp_isotone) + also have "... \ (?H * (d \ ?e))\<^sup>\ * ?H * ?e * top" + by (simp add: comp_isotone star_isotone) + finally have "?i\<^sup>T * top \ (?H * (d \ ?e))\<^sup>\ * ?H * ?e * top" + by blast + thus ?thesis + using 212 assms(18) bf_between_arcs_def minarc_arc minarc_bot_iff by blast + qed + next + show "?i \ - ?H \ -- g" + proof - + have 241: "?i \ -?H" + using 16 assms(9) inf.order_lesseq_imp p_antitone_iff by blast + have "?i \ -- g" + using 10 inf.coboundedI1 spanning_forest_def by blast + thus ?thesis + using 241 inf_greatest by blast + qed + next + show "regular h" + using assms(20) by auto + qed + have "?v \ ?e \ -?i = bot" + using 14 by simp + hence "sum (?w \ g) = sum (?v \ -?i \ g) + sum (?e \ g)" + using sum_disjoint inf_commute inf_assoc by simp + also have "... \ sum (?v \ -?i \ g) + sum (?i \ g)" + using 224 225 sum_plus_right_isotone by simp + also have "... = sum (((?v \ -?i) \ ?i) \ g)" + using sum_disjoint inf_le2 pseudo_complement by simp + also have "... = sum ((?v \ ?i) \ (-?i \ ?i) \ g)" + by (simp add: sup_inf_distrib2) + also have "... = sum ((?v \ ?i) \ g)" + using 15 by (metis inf_top_right stone) + also have "... = sum (?v \ g)" + by (simp add: inf.sup_monoid.add_assoc) + finally have "sum (?w \ g) \ sum (?v \ g)" + by simp + thus "\u . spanning_forest u g \ sum (?w \ g) \ sum (u \ g)" + using 2 11 minimum_spanning_forest_def by auto + qed + next + have "?f \ f \ f\<^sup>T \ ?e" + by (smt conv_dist_inf inf_le1 sup_left_isotone sup_mono inf.order_lesseq_imp) + also have "... \ (?v \ -?i \ -?i\<^sup>T) \ (?v\<^sup>T \ -?i \ -?i\<^sup>T) \ ?e" + using 20 sup_left_isotone by simp + also have "... \ (?v \ -?i) \ (?v\<^sup>T \ -?i \ -?i\<^sup>T) \ ?e" + by (metis inf.cobounded1 sup_inf_distrib2) + also have "... = ?w \ (?v\<^sup>T \ -?i \ -?i\<^sup>T)" + by (simp add: sup_assoc sup_commute) + also have "... \ ?w \ (?v\<^sup>T \ -?i\<^sup>T)" + using inf.sup_right_isotone inf_assoc sup_right_isotone by simp + also have "... \ ?w \ ?w\<^sup>T" + using conv_complement conv_dist_inf conv_dist_sup sup_right_isotone by simp + finally show "?f \ ?w \ ?w\<^sup>T" + by simp + qed + thus ?thesis by auto +qed + +lemma boruvka_outer_invariant_when_e_not_bot: + assumes "boruvka_inner_invariant j f h g d" + and "j \ bot" + and "selected_edge h j g \ - forest_components f" + and "selected_edge h j g \ bot" + shows "boruvka_outer_invariant (f \ - selected_edge h j g\<^sup>T \ - path f h j g \ (f \ - selected_edge h j g\<^sup>T \ path f h j g)\<^sup>T \ selected_edge h j g) g" +proof - + let ?c = "choose_component (forest_components h) j" + let ?p = "path f h j g" + let ?F = "forest_components f" + let ?H = "forest_components h" + let ?e = "selected_edge h j g" + let ?f' = "f \ -?e\<^sup>T \ -?p \ (f \ -?e\<^sup>T \ ?p)\<^sup>T \ ?e" + let ?d' = "d \ ?e" + let ?j' = "j \ -?c" + show "boruvka_outer_invariant ?f' g" + proof (unfold boruvka_outer_invariant_def, intro conjI) + show "symmetric g" + by (meson assms(1) boruvka_inner_invariant_def boruvka_outer_invariant_def) + next + show "injective ?f'" + proof (rule kruskal_injective_inv) + show "injective (f \ - ?e\<^sup>T)" + by (meson assms(1) boruvka_inner_invariant_def boruvka_outer_invariant_def injective_inf_closed) + show "covector (?p)" + using covector_mult_closed by simp + show "?p * (f \ - ?e\<^sup>T)\<^sup>T \ ?p" + by (simp add: mult_right_isotone star.left_plus_below_circ star_plus mult_assoc) + show "?e \ ?p" + by (meson mult_left_isotone order.trans star_outer_increasing top.extremum) + show "?p * (f \ - ?e\<^sup>T)\<^sup>T \ - ?e" + proof - + have "?p * (f \ - ?e\<^sup>T)\<^sup>T \ ?p * f\<^sup>T" + by (simp add: conv_dist_inf mult_right_isotone) + also have "... \ top * ?e * (f)\<^sup>T\<^sup>\ * f\<^sup>T" + using conv_dist_inf star_isotone comp_isotone by simp + also have "... \ - ?e" + using assms(1, 4) boruvka_inner_invariant_def boruvka_outer_invariant_def kruskal_injective_inv_2 minarc_arc minarc_bot_iff by auto + finally show ?thesis . + qed + show "injective (?e)" + by (metis arc_injective coreflexive_bot_closed minarc_arc minarc_bot_iff semiring.mult_not_zero) + show "coreflexive (?p\<^sup>T * ?p \ (f \ - ?e\<^sup>T)\<^sup>T * (f \ - ?e\<^sup>T))" + proof - + have "(?p\<^sup>T * ?p \ (f \ - ?e\<^sup>T)\<^sup>T * (f \ - ?e\<^sup>T)) \ ?p\<^sup>T * ?p \ f\<^sup>T * f" + using conv_dist_inf inf.sup_right_isotone mult_isotone by simp + also have "... \ (top * ?e * f\<^sup>T\<^sup>\)\<^sup>T * (top * ?e * f\<^sup>T\<^sup>\) \ f\<^sup>T * f" + by (metis comp_associative comp_inf.coreflexive_transitive comp_inf.mult_right_isotone comp_isotone conv_isotone inf.cobounded1 inf.idem inf.sup_monoid.add_commute star_isotone top.extremum) + also have "... \ 1" + using assms(1, 4) boruvka_inner_invariant_def boruvka_outer_invariant_def kruskal_injective_inv_3 minarc_arc minarc_bot_iff by auto + finally show ?thesis + by simp + qed + qed + next + show "acyclic ?f'" + proof (rule kruskal_acyclic_inv) + show "acyclic (f \ - ?e\<^sup>T)" + proof - + have f_intersect_below: "(f \ - ?e\<^sup>T) \ f" by simp + have "acyclic f" + by (meson assms(1) boruvka_inner_invariant_def boruvka_outer_invariant_def) + thus ?thesis + using comp_isotone dual_order.trans star_isotone f_intersect_below by blast + qed + next + show "covector ?p" + by (metis comp_associative vector_top_closed) + next + show "(f \ - ?e\<^sup>T \ ?p)\<^sup>T * (f \ - ?e\<^sup>T)\<^sup>\ * ?e = bot" + proof - + have "?e \ - (f\<^sup>T\<^sup>\ * f\<^sup>\)" + by (simp add: assms(3)) + hence "?e * top * ?e \ - (f\<^sup>T\<^sup>\ * f\<^sup>\)" + by (metis arc_top_arc minarc_arc minarc_bot_iff semiring.mult_not_zero) + hence "?e\<^sup>T * top * ?e\<^sup>T \ - (f\<^sup>T\<^sup>\ * f\<^sup>\)\<^sup>T" + by (metis comp_associative conv_complement conv_dist_comp conv_isotone symmetric_top_closed) + hence "?e\<^sup>T * top * ?e\<^sup>T \ - (f\<^sup>T\<^sup>\ * f\<^sup>\)" + by (simp add: conv_dist_comp conv_star_commute) + hence "?e * (f\<^sup>T\<^sup>\ * f\<^sup>\) * ?e \ bot" + using triple_schroeder_p by auto + hence 1: "?e * f\<^sup>T\<^sup>\ * f\<^sup>\ * ?e \ bot" + using mult_assoc by auto + have 2: "(f \ - ?e\<^sup>T)\<^sup>T\<^sup>\ \ f\<^sup>T\<^sup>\" + by (simp add: conv_dist_inf star_isotone) + have "(f \ - ?e\<^sup>T \ ?p)\<^sup>T * (f \ - ?e\<^sup>T)\<^sup>\ * ?e \ (f \ ?p)\<^sup>T * (f \ - ?e\<^sup>T)\<^sup>\ * ?e" + by (simp add: comp_isotone conv_dist_inf inf.orderI inf.sup_monoid.add_assoc) + also have "... \ (f \ ?p)\<^sup>T * f\<^sup>\ * ?e" + by (simp add: comp_isotone star_isotone) + also have "... \ (f \ top * ?e * (f)\<^sup>T\<^sup>\)\<^sup>T * f\<^sup>\ * ?e" + using 2 by (metis comp_inf.comp_isotone comp_inf.coreflexive_transitive comp_isotone conv_isotone inf.idem top.extremum) + also have "... = (f\<^sup>T \ (top * ?e * f\<^sup>T\<^sup>\)\<^sup>T) * f\<^sup>\ * ?e" + by (simp add: conv_dist_inf) + also have "... \ top * (f\<^sup>T \ (top * ?e * f\<^sup>T\<^sup>\)\<^sup>T) * f\<^sup>\ * ?e" + using top_left_mult_increasing mult_assoc by auto + also have "... = (top \ top * ?e * f\<^sup>T\<^sup>\) * f\<^sup>T * f\<^sup>\ * ?e" + by (smt covector_comp_inf_1 covector_mult_closed eq_iff inf.sup_monoid.add_commute vector_top_closed) + also have "... = top * ?e * f\<^sup>T\<^sup>\ * f\<^sup>T * f\<^sup>\ * ?e" + by simp + also have "... \ top * ?e * f\<^sup>T\<^sup>\ * f\<^sup>\ * ?e" + by (smt conv_dist_comp conv_isotone conv_star_commute mult_left_isotone mult_right_isotone star.left_plus_below_circ mult_assoc) + also have "... \ bot" + using 1 covector_bot_closed le_bot mult_assoc by fastforce + finally show ?thesis + using le_bot by auto + qed + next + show "?e * (f \ - ?e\<^sup>T)\<^sup>\ * ?e = bot" + proof - + have 1: "?e \ - ?F" + by (simp add: assms(3)) + have 2: "injective f" + by (meson assms(1) boruvka_inner_invariant_def boruvka_outer_invariant_def) + have 3: "equivalence ?F" + using 2 forest_components_equivalence by simp + hence 4: "?e\<^sup>T = ?e\<^sup>T * top * ?e\<^sup>T" + by (smt arc_conv_closed arc_top_arc covector_complement_closed covector_conv_vector ex231e minarc_arc minarc_bot_iff pp_surjective regular_closed_top vector_mult_closed vector_top_closed) + also have "... \ - ?F" using 1 3 conv_isotone conv_complement calculation by fastforce + finally have 5: "?e * ?F * ?e = bot" + using 4 by (smt triple_schroeder_p le_bot pp_total regular_closed_top vector_top_closed) + have "(f \ - ?e\<^sup>T)\<^sup>\ \ f\<^sup>\" + by (simp add: star_isotone) + hence "?e * (f \ - ?e\<^sup>T)\<^sup>\ * ?e \ ?e * f\<^sup>\ * ?e" + using mult_left_isotone mult_right_isotone by blast + also have "... \ ?e * ?F * ?e" + by (metis conv_star_commute forest_components_increasing mult_left_isotone mult_right_isotone star_involutive) + also have 6: "... = bot" + using 5 by simp + finally show ?thesis using 6 le_bot by blast + qed + next + show "forest_components (f \ -?e\<^sup>T) \ - ?e" + proof - + have 1: "?e \ - ?F" + by (simp add: assms(3)) + have "f \ - ?e\<^sup>T \ f" + by simp + hence "forest_components (f \ - ?e\<^sup>T) \ ?F" + using forest_components_isotone by blast + thus ?thesis + using 1 order_lesseq_imp p_antitone_iff by blast + qed + qed + next + show "?f' \ --g" + proof - + have 1: "(f \ - ?e\<^sup>T \ - ?p) \ --g" + by (meson assms(1) boruvka_inner_invariant_def boruvka_outer_invariant_def inf.coboundedI1) + have 2: "(f \ - ?e\<^sup>T \ ?p)\<^sup>T \ --g" + proof - + have "(f \ - ?e\<^sup>T \ ?p)\<^sup>T \ f\<^sup>T" + by (simp add: conv_isotone inf.sup_monoid.add_assoc) + also have "... \ --g" + by (metis assms(1) boruvka_inner_invariant_def boruvka_outer_invariant_def conv_complement conv_isotone) + finally show ?thesis + by simp + qed + have 3: "?e \ --g" + by (metis inf.boundedE minarc_below pp_dist_inf) + show ?thesis using 1 2 3 + by simp + qed + next + show "regular ?f'" + using assms(1) boruvka_inner_invariant_def boruvka_outer_invariant_def minarc_regular regular_closed_star regular_conv_closed regular_mult_closed by auto + next + show "\w. minimum_spanning_forest w g \ ?f' \ w \ w\<^sup>T" + proof (rule exists_a_w) + show "symmetric g" + using assms(1) boruvka_inner_invariant_def boruvka_outer_invariant_def by auto + next + show "forest f" + using assms(1) boruvka_inner_invariant_def boruvka_outer_invariant_def by auto + next + show "f \ --g" + using assms(1) boruvka_inner_invariant_def boruvka_outer_invariant_def by auto + next + show "regular f" + using assms(1) boruvka_inner_invariant_def boruvka_outer_invariant_def by auto + next + show "(\w . minimum_spanning_forest w g \ f \ w \ w\<^sup>T)" + using assms(1) boruvka_inner_invariant_def boruvka_outer_invariant_def by auto + next + show "vector j" + using assms(1) boruvka_inner_invariant_def by blast + next + show "regular j" + using assms(1) boruvka_inner_invariant_def by blast + next + show "forest h" + using assms(1) boruvka_inner_invariant_def by blast + next + show "forest_components h \ forest_components f" + using assms(1) boruvka_inner_invariant_def by blast + next + show "big_forest (forest_components h) d" + using assms(1) boruvka_inner_invariant_def by blast + next + show "d * top \ - j" + using assms(1) boruvka_inner_invariant_def by blast + next + show "forest_components h * j = j" + using assms(1) boruvka_inner_invariant_def by blast + next + show "forest_components f = (forest_components h * (d \ d\<^sup>T))\<^sup>\ * forest_components h" + using assms(1) boruvka_inner_invariant_def by blast + next + show "f \ f\<^sup>T = h \ h\<^sup>T \ d \ d\<^sup>T" + using assms(1) boruvka_inner_invariant_def by blast + next + show "(\ a b . bf_between_arcs a b (forest_components h) d \ a \ -(forest_components h) \ -- g \ b \ d \ sum(b \ g) \ sum(a \ g))" + using assms(1) boruvka_inner_invariant_def by blast + next + show "regular d" + using assms(1) boruvka_inner_invariant_def by blast + next + show "selected_edge h j g \ - forest_components f" + by (simp add: assms(3)) + next + show "selected_edge h j g \ bot" + by (simp add: assms(4)) + next + show "j \ bot" + by (simp add: assms(2)) + next + show "regular h" + using assms(1) boruvka_inner_invariant_def boruvka_outer_invariant_def by auto + next + show "h \ --g" + using assms(1) boruvka_inner_invariant_def boruvka_outer_invariant_def by auto + qed + qed +qed + +lemma second_inner_invariant_when_e_not_bot: + assumes "boruvka_inner_invariant j f h g d" + and "j \ bot" + and "selected_edge h j g \ - forest_components f" + and "selected_edge h j g \ bot" + shows "boruvka_inner_invariant + (j \ - choose_component (forest_components h) j) + (f \ - selected_edge h j g\<^sup>T \ - path f h j g \ + (f \ - selected_edge h j g\<^sup>T \ path f h j g)\<^sup>T \ + selected_edge h j g) + h g (d \ selected_edge h j g)" +proof - + let ?c = "choose_component (forest_components h) j" + let ?p = "path f h j g" + let ?F = "forest_components f" + let ?H = "forest_components h" + let ?e = "selected_edge h j g" + let ?f' = "f \ -?e\<^sup>T \ -?p \ (f \ -?e\<^sup>T \ ?p)\<^sup>T \ ?e" + let ?d' = "d \ ?e" + let ?j' = "j \ -?c" + show "boruvka_inner_invariant ?j' ?f' h g ?d'" + proof (unfold boruvka_inner_invariant_def, intro conjI) + have 1: "boruvka_outer_invariant ?f' g" + using assms(1, 2, 3, 4) boruvka_outer_invariant_when_e_not_bot by blast + show "boruvka_outer_invariant ?f' g" + using assms(1, 2, 3, 4) boruvka_outer_invariant_when_e_not_bot by blast + show "g \ bot" + using assms(1) boruvka_inner_invariant_def by force + show "vector ?j'" + using assms(1, 2) boruvka_inner_invariant_def component_is_vector vector_complement_closed vector_inf_closed by simp + show "regular ?j'" + using assms(1) boruvka_inner_invariant_def by auto + show "boruvka_outer_invariant h g" + by (meson assms(1) boruvka_inner_invariant_def) + show "injective h" + by (meson assms(1) boruvka_inner_invariant_def) + show "pd_kleene_allegory_class.acyclic h" + by (meson assms(1) boruvka_inner_invariant_def) + show "?H \ forest_components ?f'" + proof - + have 2: "?F \ forest_components ?f'" + proof (rule components_disj_increasing) + show "regular ?p" + using assms(1) boruvka_inner_invariant_def boruvka_outer_invariant_def minarc_regular regular_closed_star regular_conv_closed regular_mult_closed by auto[1] + next + show "regular ?e" + using assms(1) boruvka_inner_invariant_def boruvka_outer_invariant_def minarc_regular regular_closed_star regular_conv_closed regular_mult_closed by auto[1] + next + show "injective ?f'" + using 1 boruvka_outer_invariant_def by blast + next + show "injective f" + using assms(1) boruvka_inner_invariant_def boruvka_outer_invariant_def by blast + qed + thus ?thesis + using assms(1) boruvka_inner_invariant_def dual_order.trans by blast + qed + show "big_forest ?H ?d'" + using assms(1, 2, 3, 4) big_forest_d_U_e boruvka_inner_invariant_def boruvka_outer_invariant_def by auto + next + show "?d' * top \ -?j'" + proof - + have 31: "?d' * top = d * top \ ?e * top" + by (simp add: mult_right_dist_sup) + have 32: "d * top \ -?j'" + by (meson assms(1) boruvka_inner_invariant_def inf.coboundedI1 p_antitone_iff) + have "regular (?c * - ?c\<^sup>T)" + using assms(1) boruvka_inner_invariant_def boruvka_outer_invariant_def component_is_regular regular_conv_closed regular_mult_closed by auto + hence "minarc(?c * - ?c\<^sup>T \ g) = minarc(?c \ - ?c\<^sup>T \ g)" + by (metis component_is_vector covector_comp_inf inf_top.left_neutral vector_conv_compl) + also have "... \ -- (?c \ - ?c\<^sup>T \ g)" + using minarc_below by blast + also have "... \ -- ?c" + by (simp add: inf.sup_monoid.add_assoc) + also have "... = ?c" + using component_is_regular by auto + finally have "?e \ ?c" + by simp + hence "?e * top \ ?c" + by (metis component_is_vector mult_left_isotone) + also have "... \ -j \ ?c" + by simp + also have "... = - (j \ - ?c)" + using component_is_regular by auto + finally have 33: "?e * top \ - (j \ - ?c)" + by simp + show ?thesis + using 31 32 33 by auto + qed + next + show "?H * ?j' = ?j'" + using fc_j_eq_j_inv assms(1) boruvka_inner_invariant_def by blast + next + show "forest_components ?f' = (?H * (?d' \ ?d'\<^sup>T))\<^sup>\ * ?H" + proof - + have "forest_components ?f' = (f \ f\<^sup>T \ ?e \ ?e\<^sup>T)\<^sup>\" + proof (rule simplify_forest_components_f) + show "regular ?p" + using assms(1) boruvka_inner_invariant_def boruvka_outer_invariant_def minarc_regular regular_closed_star regular_conv_closed regular_mult_closed by auto + next + show "regular ?e" + using minarc_regular by auto + next + show "injective ?f'" + using assms(1, 2, 3, 4) boruvka_outer_invariant_def boruvka_outer_invariant_when_e_not_bot by blast + next + show "injective f" + using assms(1) boruvka_inner_invariant_def boruvka_outer_invariant_def by blast + qed + also have "... = (h \ h\<^sup>T \ d \ d\<^sup>T \ ?e \ ?e\<^sup>T)\<^sup>\" + using assms(1) boruvka_inner_invariant_def by simp + also have "... = (h \ h\<^sup>T \ ?d' \ ?d'\<^sup>T)\<^sup>\" + by (smt conv_dist_sup sup_monoid.add_assoc sup_monoid.add_commute) + also have "... = ((h \ h\<^sup>T)\<^sup>\ * (?d' \ ?d'\<^sup>T))\<^sup>\ * (h \ h\<^sup>T)\<^sup>\" + by (metis star.circ_sup_9 sup_assoc) + finally show ?thesis + using assms(1) boruvka_inner_invariant_def forest_components_wcc by simp + qed + next + show "?f' \ ?f'\<^sup>T = h \ h\<^sup>T \ ?d' \ ?d'\<^sup>T" + proof - + have "?f' \ ?f'\<^sup>T = f \ - ?e\<^sup>T \ - ?p \ (f \ - ?e\<^sup>T \ ?p)\<^sup>T \ ?e \ (f \ - ?e\<^sup>T \ - ?p)\<^sup>T \ (f \ - ?e\<^sup>T \ ?p) \ ?e\<^sup>T" + by (simp add: conv_dist_sup sup_monoid.add_assoc) + also have "... = (f \ - ?e\<^sup>T \ - ?p) \ (f \ - ?e\<^sup>T \ ?p) \ (f \ - ?e\<^sup>T \ ?p)\<^sup>T \ (f \ - ?e\<^sup>T \ - ?p)\<^sup>T \ ?e\<^sup>T \ ?e" + by (simp add: sup.left_commute sup_commute) + also have "... = f \ f\<^sup>T \ ?e \ ?e\<^sup>T" + proof (rule simplify_f) + show "regular ?p" + using assms(1) boruvka_inner_invariant_def boruvka_outer_invariant_def minarc_regular regular_closed_star regular_conv_closed regular_mult_closed by auto + next + show "regular ?e" + using minarc_regular by blast + qed + also have "... = h \ h\<^sup>T \ d \ d\<^sup>T \ ?e \ ?e\<^sup>T" + using assms(1) boruvka_inner_invariant_def by auto + finally show ?thesis + by (smt conv_dist_sup sup.left_commute sup_commute) + qed + next + show "\ a b . bf_between_arcs a b ?H ?d' \ a \ - ?H \ -- g \ b \ ?d' \ sum (b \ g) \ sum (a \ g)" + proof (intro allI, rule impI, unfold bf_between_arcs_def) + fix a b + assume 1: "(arc a \ arc b \ a\<^sup>T * top \ (?H * ?d')\<^sup>\ * ?H * b * top) \ a \ - ?H \ -- g \ b \ ?d'" + thus "sum (b \ g) \ sum (a \ g)" + proof (cases "b = ?e") + case b_equals_e: True + thus ?thesis + proof (cases "a = ?e") + case True + thus ?thesis + using b_equals_e by auto + next + case a_ne_e: False + have "sum (b \ g) \ sum (a \ g)" + proof (rule a_to_e_in_bigforest) + show "symmetric g" + using assms(1) boruvka_inner_invariant_def boruvka_outer_invariant_def by auto + next + show "j \ bot" + by (simp add: assms(2)) + next + show "f \ -- g" + using assms(1) boruvka_inner_invariant_def boruvka_outer_invariant_def by auto + next + show "vector j" + using assms(1) boruvka_inner_invariant_def by blast + next + show "forest h" + using assms(1) boruvka_inner_invariant_def by blast + next + show " big_forest (forest_components h) d" + using assms(1) boruvka_inner_invariant_def by blast + next + show "f \ f\<^sup>T = h \ h\<^sup>T \ d \ d\<^sup>T" + using assms(1) boruvka_inner_invariant_def by blast + next + show "\a b. bf_between_arcs a b (?H) d \ a \ - ?H \ - - g \ b \ d \ sum (b \ g) \ sum (a \ g)" + using assms(1) boruvka_inner_invariant_def by blast + next + show "regular d" + using assms(1) boruvka_inner_invariant_def by blast + next + show "b = ?e" + using b_equals_e by simp + next + show "arc a" + using 1 by simp + next + show "bf_between_arcs a b ?H ?d'" + using 1 bf_between_arcs_def by simp + next + show "a \ - ?H \ -- g" + using 1 by simp + next + show "regular h" + using assms(1) boruvka_inner_invariant_def boruvka_outer_invariant_def by auto + qed + thus ?thesis + by simp + qed + next + case b_not_equal_e: False + hence b_below_d: "b \ d" + using 1 by (metis assms(4) different_arc_in_sup_arc minarc_arc minarc_bot_iff) + thus ?thesis + proof (cases "?e \ d") + case True + hence "bf_between_arcs a b ?H d \ b \ d" + using 1 bf_between_arcs_def sup.absorb1 by auto + thus ?thesis + using 1 assms(1) boruvka_inner_invariant_def by blast + next + case e_not_less_than_d: False + have 71:"equivalence ?H" + using assms(1) fch_equivalence boruvka_inner_invariant_def by auto + hence 72: "bf_between_arcs a b ?H ?d' \ bf_between_arcs a b ?H d \ (bf_between_arcs a ?e ?H d \ bf_between_arcs ?e b ?H d)" + proof (rule big_forest_path_split_disj) + show "arc ?e" + using assms(4) minarc_arc minarc_bot_iff by blast + next + show "regular a \ regular b \ regular ?e \ regular d \ regular ?H" + using assms(1) 1 boruvka_inner_invariant_def boruvka_outer_invariant_def arc_regular minarc_regular regular_closed_star regular_conv_closed regular_mult_closed by auto + qed + thus ?thesis + proof (cases "bf_between_arcs a b ?H d") + case True + have "bf_between_arcs a b ?H d \ b \ d" + using 1 by (metis assms(4) True b_not_equal_e minarc_arc minarc_bot_iff different_arc_in_sup_arc) + thus ?thesis + using 1 assms(1) b_below_d boruvka_inner_invariant_def by auto + next + case False + have 73:"bf_between_arcs a ?e ?H d \ bf_between_arcs ?e b ?H d" + using 1 72 False bf_between_arcs_def by blast + have 74: "?e \ --g" + by (metis inf.boundedE minarc_below pp_dist_inf) + have "?e \ - ?H" + by (meson assms(1, 3) boruvka_inner_invariant_def dual_order.trans p_antitone_iff) + hence "?e \ - ?H \ --g" + using 74 by simp + hence 75: "sum (b \ g) \ sum (?e \ g)" + using assms(1) b_below_d 73 boruvka_inner_invariant_def by blast + have 76: "bf_between_arcs a ?e ?H ?d'" + using 73 by (meson big_forest_path_split_disj assms(1) bf_between_arcs_def boruvka_inner_invariant_def boruvka_outer_invariant_def fch_equivalence arc_regular regular_closed_star regular_conv_closed regular_mult_closed) + have 77: "sum (?e \ g) \ sum (a \ g)" + proof (rule a_to_e_in_bigforest) + show "symmetric g" + using assms(1) boruvka_inner_invariant_def boruvka_outer_invariant_def by auto + next + show "j \ bot" + by (simp add: assms(2)) + next + show "f \ -- g" + using assms(1) boruvka_inner_invariant_def boruvka_outer_invariant_def by auto + next + show "vector j" + using assms(1) boruvka_inner_invariant_def by blast + next + show "forest h" + using assms(1) boruvka_inner_invariant_def by blast + next + show " big_forest (forest_components h) d" + using assms(1) boruvka_inner_invariant_def by blast + next + show "f \ f\<^sup>T = h \ h\<^sup>T \ d \ d\<^sup>T" + using assms(1) boruvka_inner_invariant_def by blast + next + show "\a b. bf_between_arcs a b (?H) d \ a \ - ?H \ - - g \ b \ d \ sum (b \ g) \ sum (a \ g)" + using assms(1) boruvka_inner_invariant_def by blast + next + show "regular d" + using assms(1) boruvka_inner_invariant_def by blast + next + show "?e = ?e" + by simp + next + show "arc a" + using 1 by simp + next + show "bf_between_arcs a ?e ?H ?d'" + by (simp add: 76) + next + show "a \ - ?H \ --g" + using 1 by simp + next + show "regular h" + using assms(1) boruvka_inner_invariant_def boruvka_outer_invariant_def by auto + qed + thus ?thesis + using 75 order.trans by blast + qed + qed + qed + qed + next + show "regular ?d'" + using assms(1) boruvka_inner_invariant_def minarc_regular by auto + qed +qed + +lemma second_inner_invariant_when_e_bot: + assumes "selected_edge h j g = bot" + and "selected_edge h j g \ - forest_components f" + and "boruvka_inner_invariant j f h g d" + shows "boruvka_inner_invariant + (j \ - choose_component (forest_components h) j) + (f \ - selected_edge h j g\<^sup>T \ - path f h j g \ + (f \ - selected_edge h j g\<^sup>T \ path f h j g)\<^sup>T \ + selected_edge h j g) + h g (d \ selected_edge h j g)" +proof - + let ?c = "choose_component (forest_components h) j" + let ?p = "path f h j g" + let ?F = "forest_components f" + let ?H = "forest_components h" + let ?e = "selected_edge h j g" + let ?f' = "f \ -?e\<^sup>T \ -?p \ (f \ -?e\<^sup>T \ ?p)\<^sup>T \ ?e" + let ?d' = "d \ ?e" + let ?j' = "j \ -?c" + show "boruvka_inner_invariant ?j' ?f' h g ?d'" + proof (unfold boruvka_inner_invariant_def, intro conjI) + next + show "boruvka_outer_invariant ?f' g" + using assms(1, 3) boruvka_inner_invariant_def by auto + next + show "g \ bot" + using assms(3) boruvka_inner_invariant_def by blast + next + show "vector ?j'" + by (metis assms(3) boruvka_inner_invariant_def component_is_vector vector_complement_closed vector_inf_closed) + next + show "regular ?j'" + using assms(3) boruvka_inner_invariant_def by auto + next + show "boruvka_outer_invariant h g" + using assms(3) boruvka_inner_invariant_def by blast + next + show "injective h" + using assms(3) boruvka_inner_invariant_def by blast + next + show "pd_kleene_allegory_class.acyclic h" + using assms(3) boruvka_inner_invariant_def by blast + next + show "?H \ forest_components ?f'" + using assms(1, 3) boruvka_inner_invariant_def by auto + next + show " big_forest ?H ?d'" + using assms(1, 3) boruvka_inner_invariant_def by auto + next + show "?d' * top \ -?j'" + by (metis assms(1, 3) boruvka_inner_invariant_def order.trans p_antitone_inf sup_monoid.add_0_right) + next + show "?H * ?j' = ?j'" + using assms(3) fc_j_eq_j_inv boruvka_inner_invariant_def by blast + next + show "forest_components ?f' = (?H * (?d' \ ?d'\<^sup>T))\<^sup>\ *?H" + using assms(1, 3) boruvka_inner_invariant_def by auto + next + show "?f' \ ?f'\<^sup>T = h \ h\<^sup>T \ ?d' \ ?d'\<^sup>T" + using assms(1, 3) boruvka_inner_invariant_def by auto + next + show "\a b. bf_between_arcs a b ?H ?d' \ a \ -?H \ --g \ b \ ?d' \ sum(b \ g) \ sum(a \ g)" + using assms(1, 3) boruvka_inner_invariant_def by auto + next + show "regular ?d'" + using assms(1, 3) boruvka_inner_invariant_def by auto + qed +qed + +subsection \Formalization and correctness proof\ + +text \ +The following result shows that Bor\r{u}vka's algorithm constructs a minimum spanning forest. +We have the same postcondition as the proof of Kruskal's minimum spanning tree algorithm. +We show only partial correctness. +\ + +theorem boruvka_mst: + "VARS f j h c e d + { symmetric g } + f := bot; + WHILE -(forest_components f) \ g \ bot + INV { boruvka_outer_invariant f g } + DO + j := top; + h := f; + d := bot; + WHILE j \ bot + INV { boruvka_inner_invariant j f h g d } + DO + c := choose_component (forest_components h) j; + e := minarc(c * -c\<^sup>T \ g); + IF e \ -(forest_components f) THEN + f := f \ -e\<^sup>T; + f := (f \ -(top * e * f\<^sup>T\<^sup>\)) \ (f \ top * e * f\<^sup>T\<^sup>\)\<^sup>T \ e; + d := d \ e + ELSE + SKIP + FI; + j := j \ -c + OD + OD + { minimum_spanning_forest f g }" +proof vcg_simp + assume 1: "symmetric g" + show "boruvka_outer_invariant bot g" + using 1 boruvka_outer_invariant_def kruskal_exists_minimal_spanning by auto +next + fix f + let ?F = "forest_components f" + assume 1: "boruvka_outer_invariant f g \ - ?F \ g \ bot" + have 2: "equivalence ?F" + using 1 boruvka_outer_invariant_def forest_components_equivalence by auto + show "boruvka_inner_invariant top f f g bot" + proof (unfold boruvka_inner_invariant_def, intro conjI) + show "boruvka_outer_invariant f g" + by (simp add: 1) + next + show "g \ bot" + using 1 by auto + next + show "surjective top" + by simp + next + show "regular top" + by simp + next + show "boruvka_outer_invariant f g" + using 1 by auto + next + show "injective f" + using 1 boruvka_outer_invariant_def by blast + next + show "pd_kleene_allegory_class.acyclic f" + using 1 boruvka_outer_invariant_def by blast + next + show "?F \ ?F" + by simp + next + show "big_forest ?F bot" + by (simp add: 2 big_forest_def) + next + show "bot * top \ - top" + by simp + next + show "times_top_class.total (?F)" + by (simp add: star.circ_right_top mult_assoc) + next + show "?F = (?F * (bot \ bot\<^sup>T))\<^sup>\ * ?F" + by (metis mult_right_zero semiring.mult_zero_left star.circ_loop_fixpoint sup_commute sup_monoid.add_0_right symmetric_bot_closed) + next + show "f \ f\<^sup>T = f \ f\<^sup>T \ bot \ bot\<^sup>T" + by simp + next + show "\ a b. bf_between_arcs a b ?F bot \ a \ - ?F \ -- g \ b \ bot \ sum (b \ g) \ sum (a \ g)" + by (metis (full_types) bf_between_arcs_def bot_unique mult_left_zero mult_right_zero top.extremum) + next + show "regular bot" + by auto + qed +next + fix f j h d + let ?c = "choose_component (forest_components h) j" + let ?p = "path f h j g" + let ?F = "forest_components f" + let ?H = "forest_components h" + let ?e = "selected_edge h j g" + let ?f' = "f \ -?e\<^sup>T \ -?p \ (f \ -?e\<^sup>T \ ?p)\<^sup>T \ ?e" + let ?d' = "d \ ?e" + let ?j' = "j \ -?c" + assume 1: "boruvka_inner_invariant j f h g d \ j \ bot" + show "(?e \ -?F \ boruvka_inner_invariant ?j' ?f' h g ?d') \ (\ ?e \ -?F \ boruvka_inner_invariant ?j' f h g d)" + proof (intro conjI) + show "?e \ -?F \ boruvka_inner_invariant ?j' ?f' h g ?d'" + proof (cases "?e = bot") + case True + thus ?thesis + using 1 second_inner_invariant_when_e_bot by simp + next + case False + thus ?thesis + using 1 second_inner_invariant_when_e_not_bot by simp + qed + next + show "\ ?e \ -?F \ boruvka_inner_invariant ?j' f h g d" + proof (rule impI, unfold boruvka_inner_invariant_def, intro conjI) + show "boruvka_outer_invariant f g" + using 1 boruvka_inner_invariant_def by blast + next + show "g \ bot" + using 1 boruvka_inner_invariant_def by blast + next + show "vector ?j'" + using 1 boruvka_inner_invariant_def component_is_vector vector_complement_closed vector_inf_closed by auto + next + show "regular ?j'" + using 1 boruvka_inner_invariant_def by auto + next + show "boruvka_outer_invariant h g" + using 1 boruvka_inner_invariant_def by auto + next + show "injective h" + using 1 boruvka_inner_invariant_def by blast + next + show "pd_kleene_allegory_class.acyclic h" + using 1 boruvka_inner_invariant_def by blast + next + show "?H \ ?F" + using 1 boruvka_inner_invariant_def by blast + next + show "big_forest ?H d" + using 1 boruvka_inner_invariant_def by blast + next + show "d * top \ -?j'" + using 1 by (meson boruvka_inner_invariant_def dual_order.trans p_antitone_inf) + next + show "?H * ?j' = ?j'" + using 1 fc_j_eq_j_inv boruvka_inner_invariant_def by blast + next + show "?F = (?H * (d \ d\<^sup>T))\<^sup>\ * ?H" + using 1 boruvka_inner_invariant_def by blast + next + show "f \ f\<^sup>T = h \ h\<^sup>T \ d \ d\<^sup>T" + using 1 boruvka_inner_invariant_def by blast + next + show "\ ?e \ -?F \ \a b. bf_between_arcs a b ?H d \ a \ -?H \ --g \ b \ d \ sum(b \ g) \ sum(a \ g)" + using 1 boruvka_inner_invariant_def by blast + next + show "\ ?e \ -?F \ regular d" + using 1 boruvka_inner_invariant_def by blast + qed + qed +next + fix f h d j + assume "boruvka_inner_invariant j f h g d \ j = bot" + thus "boruvka_outer_invariant f g" + by (meson boruvka_inner_invariant_def) +next + fix f + assume 1: "boruvka_outer_invariant f g \ - forest_components f \ g = bot" + hence 2:"spanning_forest f g" + proof (unfold spanning_forest_def, intro conjI) + show "injective f" + using 1 boruvka_outer_invariant_def by blast + next + show "acyclic f" + using 1 boruvka_outer_invariant_def by blast + next + show "f \ --g" + using 1 boruvka_outer_invariant_def by blast + next + show "components g \ forest_components f" + proof - + let ?F = "forest_components f" + have "-?F \ g \ bot" + by (simp add: 1) + hence "--g \ bot \ --?F" + using 1 shunting_p p_antitone pseudo_complement by auto + hence "--g \ ?F" + using 1 boruvka_outer_invariant_def pp_dist_comp pp_dist_star regular_conv_closed by auto + hence "(--g)\<^sup>\ \ ?F\<^sup>\" + by (simp add: star_isotone) + thus ?thesis + using 1 boruvka_outer_invariant_def forest_components_star by auto + qed + next + show "regular f" + using 1 boruvka_outer_invariant_def by auto + qed + from 1 obtain w where 3: "minimum_spanning_forest w g \ f \ w \ w\<^sup>T" + using boruvka_outer_invariant_def by blast + hence "w = w \ --g" + by (simp add: inf.absorb1 minimum_spanning_forest_def spanning_forest_def) + also have "... \ w \ components g" + by (metis inf.sup_right_isotone star.circ_increasing) + also have "... \ w \ f\<^sup>T\<^sup>\ * f\<^sup>\" + using 2 spanning_forest_def inf.sup_right_isotone by simp + also have "... \ f \ f\<^sup>T" + proof (rule cancel_separate_6[where z=w and y="w\<^sup>T"]) + show "injective w" + using 3 minimum_spanning_forest_def spanning_forest_def by simp + next + show "f\<^sup>T \ w\<^sup>T \ w" + using 3 by (metis conv_dist_inf conv_dist_sup conv_involutive inf.cobounded2 inf.orderE) + next + show "f \ w\<^sup>T \ w" + using 3 by (simp add: sup_commute) + next + show "injective w" + using 3 minimum_spanning_forest_def spanning_forest_def by simp + next + show "w \ w\<^sup>T\<^sup>\ = bot" + using 3 by (metis acyclic_star_below_complement comp_inf.mult_right_isotone inf_p le_bot minimum_spanning_forest_def spanning_forest_def) + qed + finally have 4: "w \ f \ f\<^sup>T" + by simp + have "sum (f \ g) = sum ((w \ w\<^sup>T) \ (f \ g))" + using 3 by (metis inf_absorb2 inf.assoc) + also have "... = sum (w \ (f \ g)) + sum (w\<^sup>T \ (f \ g))" + using 3 inf.commute acyclic_asymmetric sum_disjoint minimum_spanning_forest_def spanning_forest_def by simp + also have "... = sum (w \ (f \ g)) + sum (w \ (f\<^sup>T \ g\<^sup>T))" + by (metis conv_dist_inf conv_involutive sum_conv) + also have "... = sum (f \ (w \ g)) + sum (f\<^sup>T \ (w \ g))" + proof - + have 51:"f\<^sup>T \ (w \ g) = f\<^sup>T \ (w \ g\<^sup>T)" + using 1 boruvka_outer_invariant_def by auto + have 52:"f \ (w \ g) = w \ (f \ g)" + by (simp add: inf.left_commute) + thus ?thesis + using 51 52 abel_semigroup.left_commute inf.abel_semigroup_axioms by fastforce + qed + also have "... = sum ((f \ f\<^sup>T) \ (w \ g))" + using 2 acyclic_asymmetric inf.sup_monoid.add_commute sum_disjoint spanning_forest_def by simp + also have "... = sum (w \ g)" + using 4 by (metis inf_absorb2 inf.assoc) + finally show "minimum_spanning_forest f g" + using 2 3 minimum_spanning_forest_def by simp +qed + +end + +end + diff --git a/thys/Relational_Minimum_Spanning_Trees/Kruskal.thy b/thys/Relational_Minimum_Spanning_Trees/Kruskal.thy new file mode 100644 --- /dev/null +++ b/thys/Relational_Minimum_Spanning_Trees/Kruskal.thy @@ -0,0 +1,597 @@ +(* Title: Kruskal's Minimum Spanning Tree Algorithm + Author: Walter Guttmann + Maintainer: Walter Guttmann +*) + +section \Kruskal's Minimum Spanning Tree Algorithm\ + +text \ +In this theory we prove total correctness of Kruskal's minimum spanning tree algorithm. +The proof uses the following steps \cite{Guttmann2018c}. +We first establish that the algorithm terminates and constructs a spanning tree. +This is a constructive proof of the existence of a spanning tree; any spanning tree algorithm could be used for this. +We then conclude that a minimum spanning tree exists. +This is necessary to establish the invariant for the actual correctness proof, which shows that Kruskal's algorithm produces a minimum spanning tree. +\ + +theory Kruskal + +imports Aggregation_Algebras.Hoare_Logic Aggregation_Algebras.Aggregation_Algebras + +begin + +context m_kleene_algebra +begin + +definition "spanning_forest f g \ forest f \ f \ --g \ components g \ forest_components f \ regular f" +definition "minimum_spanning_forest f g \ spanning_forest f g \ (\u . spanning_forest u g \ sum (f \ g) \ sum (u \ g))" +definition "kruskal_spanning_invariant f g h \ symmetric g \ h = h\<^sup>T \ g \ --h = h \ spanning_forest f (-h \ g)" +definition "kruskal_invariant f g h \ kruskal_spanning_invariant f g h \ (\w . minimum_spanning_forest w g \ f \ w \ w\<^sup>T)" + +text \ +We first show two verification conditions which are used in both correctness proofs. +\ + +lemma kruskal_vc_1: + assumes "symmetric g" + shows "kruskal_spanning_invariant bot g g" +proof (unfold kruskal_spanning_invariant_def, intro conjI) + show "symmetric g" + using assms by simp +next + show "g = g\<^sup>T" + using assms by simp +next + show "g \ --g = g" + using inf.sup_monoid.add_commute selection_closed_id by simp +next + show "spanning_forest bot (-g \ g)" + using star.circ_transitive_equal spanning_forest_def by simp +qed + +lemma kruskal_vc_2: + assumes "kruskal_spanning_invariant f g h" + and "h \ bot" + shows "(minarc h \ -forest_components f \ kruskal_spanning_invariant ((f \ -(top * minarc h * f\<^sup>T\<^sup>\)) \ (f \ top * minarc h * f\<^sup>T\<^sup>\)\<^sup>T \ minarc h) g (h \ -minarc h \ -minarc h\<^sup>T) + \ card { x . regular x \ x \ --h \ x \ -minarc h \ x \ -minarc h\<^sup>T } < card { x . regular x \ x \ --h }) \ + (\ minarc h \ -forest_components f \ kruskal_spanning_invariant f g (h \ -minarc h \ -minarc h\<^sup>T) + \ card { x . regular x \ x \ --h \ x \ -minarc h \ x \ -minarc h\<^sup>T } < card { x . regular x \ x \ --h })" +proof - + let ?e = "minarc h" + let ?f = "(f \ -(top * ?e * f\<^sup>T\<^sup>\)) \ (f \ top * ?e * f\<^sup>T\<^sup>\)\<^sup>T \ ?e" + let ?h = "h \ -?e \ -?e\<^sup>T" + let ?F = "forest_components f" + let ?n1 = "card { x . regular x \ x \ --h }" + let ?n2 = "card { x . regular x \ x \ --h \ x \ -?e \ x \ -?e\<^sup>T }" + have 1: "regular f \ regular ?e" + by (metis assms(1) kruskal_spanning_invariant_def spanning_forest_def minarc_regular) + hence 2: "regular ?f \ regular ?F \ regular (?e\<^sup>T)" + using regular_closed_star regular_conv_closed regular_mult_closed by simp + have 3: "\ ?e \ -?e" + using assms(2) inf.orderE minarc_bot_iff by fastforce + have 4: "?n2 < ?n1" + apply (rule psubset_card_mono) + using finite_regular apply simp + using 1 3 kruskal_spanning_invariant_def minarc_below by auto + show "(?e \ -?F \ kruskal_spanning_invariant ?f g ?h \ ?n2 < ?n1) \ (\ ?e \ -?F \ kruskal_spanning_invariant f g ?h \ ?n2 < ?n1)" + proof (rule conjI) + have 5: "injective ?f" + apply (rule kruskal_injective_inv) + using assms(1) kruskal_spanning_invariant_def spanning_forest_def apply simp + apply (simp add: covector_mult_closed) + apply (simp add: comp_associative comp_isotone star.right_plus_below_circ) + apply (meson mult_left_isotone order_lesseq_imp star_outer_increasing top.extremum) + using assms(1,2) kruskal_spanning_invariant_def kruskal_injective_inv_2 minarc_arc spanning_forest_def apply simp + using assms(2) arc_injective minarc_arc apply blast + using assms(1,2) kruskal_spanning_invariant_def kruskal_injective_inv_3 minarc_arc spanning_forest_def by simp + show "?e \ -?F \ kruskal_spanning_invariant ?f g ?h \ ?n2 < ?n1" + proof + assume 6: "?e \ -?F" + have 7: "equivalence ?F" + using assms(1) kruskal_spanning_invariant_def forest_components_equivalence spanning_forest_def by simp + have "?e\<^sup>T * top * ?e\<^sup>T = ?e\<^sup>T" + using assms(2) by (simp add: arc_top_arc minarc_arc) + hence "?e\<^sup>T * top * ?e\<^sup>T \ -?F" + using 6 7 conv_complement conv_isotone by fastforce + hence 8: "?e * ?F * ?e = bot" + using le_bot triple_schroeder_p by simp + show "kruskal_spanning_invariant ?f g ?h \ ?n2 < ?n1" + proof (unfold kruskal_spanning_invariant_def, intro conjI) + show "symmetric g" + using assms(1) kruskal_spanning_invariant_def by simp + next + show "?h = ?h\<^sup>T" + using assms(1) by (simp add: conv_complement conv_dist_inf inf_commute inf_left_commute kruskal_spanning_invariant_def) + next + show "g \ --?h = ?h" + using 1 2 by (metis (hide_lams) assms(1) kruskal_spanning_invariant_def inf_assoc pp_dist_inf) + next + show "spanning_forest ?f (-?h \ g)" + proof (unfold spanning_forest_def, intro conjI) + show "injective ?f" + using 5 by simp + next + show "acyclic ?f" + apply (rule kruskal_acyclic_inv) + using assms(1) kruskal_spanning_invariant_def spanning_forest_def apply simp + apply (simp add: covector_mult_closed) + using 8 assms(1) kruskal_spanning_invariant_def spanning_forest_def kruskal_acyclic_inv_1 apply simp + using 8 apply (metis comp_associative mult_left_sub_dist_sup_left star.circ_loop_fixpoint sup_commute le_bot) + using 6 by (simp add: p_antitone_iff) + next + show "?f \ --(-?h \ g)" + apply (rule kruskal_subgraph_inv) + using assms(1) kruskal_spanning_invariant_def spanning_forest_def apply simp + using assms(1) apply (metis kruskal_spanning_invariant_def minarc_below order.trans pp_isotone_inf) + using assms(1) kruskal_spanning_invariant_def apply simp + using assms(1) kruskal_spanning_invariant_def by simp + next + show "components (-?h \ g) \ forest_components ?f" + apply (rule kruskal_spanning_inv) + using 5 apply simp + using 1 regular_closed_star regular_conv_closed regular_mult_closed apply simp + using 1 apply simp + using assms(1) kruskal_spanning_invariant_def spanning_forest_def by simp + next + show "regular ?f" + using 2 by simp + qed + next + show "?n2 < ?n1" + using 4 by simp + qed + qed + next + show "\ ?e \ -?F \ kruskal_spanning_invariant f g ?h \ ?n2 < ?n1" + proof + assume "\ ?e \ -?F" + hence 9: "?e \ ?F" + using 2 assms(2) arc_in_partition minarc_arc by fastforce + show "kruskal_spanning_invariant f g ?h \ ?n2 < ?n1" + proof (unfold kruskal_spanning_invariant_def, intro conjI) + show "symmetric g" + using assms(1) kruskal_spanning_invariant_def by simp + next + show "?h = ?h\<^sup>T" + using assms(1) by (simp add: conv_complement conv_dist_inf inf_commute inf_left_commute kruskal_spanning_invariant_def) + next + show "g \ --?h = ?h" + using 1 2 by (metis (hide_lams) assms(1) kruskal_spanning_invariant_def inf_assoc pp_dist_inf) + next + show "spanning_forest f (-?h \ g)" + proof (unfold spanning_forest_def, intro conjI) + show "injective f" + using assms(1) kruskal_spanning_invariant_def spanning_forest_def by simp + next + show "acyclic f" + using assms(1) kruskal_spanning_invariant_def spanning_forest_def by simp + next + have "f \ --(-h \ g)" + using assms(1) kruskal_spanning_invariant_def spanning_forest_def by simp + also have "... \ --(-?h \ g)" + using comp_inf.mult_right_isotone inf.sup_monoid.add_commute inf_left_commute p_antitone_inf pp_isotone by presburger + finally show "f \ --(-?h \ g)" + by simp + next + show "components (-?h \ g) \ ?F" + apply (rule kruskal_spanning_inv_1) + using 9 apply simp + using 1 apply simp + using assms(1) kruskal_spanning_invariant_def spanning_forest_def apply simp + using assms(1) kruskal_spanning_invariant_def forest_components_equivalence spanning_forest_def by simp + next + show "regular f" + using 1 by simp + qed + next + show "?n2 < ?n1" + using 4 by simp + qed + qed + qed +qed + +text \ +The following result shows that Kruskal's algorithm terminates and constructs a spanning tree. +We cannot yet show that this is a minimum spanning tree. +\ + +theorem kruskal_spanning: + "VARS e f h + [ symmetric g ] + f := bot; + h := g; + WHILE h \ bot + INV { kruskal_spanning_invariant f g h } + VAR { card { x . regular x \ x \ --h } } + DO e := minarc h; + IF e \ -forest_components f THEN + f := (f \ -(top * e * f\<^sup>T\<^sup>\)) \ (f \ top * e * f\<^sup>T\<^sup>\)\<^sup>T \ e + ELSE + SKIP + FI; + h := h \ -e \ -e\<^sup>T + OD + [ spanning_forest f g ]" + apply vcg_tc_simp + using kruskal_vc_1 apply simp + using kruskal_vc_2 apply simp + using kruskal_spanning_invariant_def by auto + +text \ +Because we have shown total correctness, we conclude that a spanning tree exists. +\ + +lemma kruskal_exists_spanning: + "symmetric g \ \f . spanning_forest f g" + using tc_extract_function kruskal_spanning by blast + +text \ +This implies that a minimum spanning tree exists, which is used in the subsequent correctness proof. +\ + +lemma kruskal_exists_minimal_spanning: + assumes "symmetric g" + shows "\f . minimum_spanning_forest f g" +proof - + let ?s = "{ f . spanning_forest f g }" + have "\m\?s . \z\?s . sum (m \ g) \ sum (z \ g)" + apply (rule finite_set_minimal) + using finite_regular spanning_forest_def apply simp + using assms kruskal_exists_spanning apply simp + using sum_linear by simp + thus ?thesis + using minimum_spanning_forest_def by simp +qed + +text \ +Kruskal's minimum spanning tree algorithm terminates and is correct. +This is the same algorithm that is used in the previous correctness proof, with the same precondition and variant, but with a different invariant and postcondition. +\ + +theorem kruskal: + "VARS e f h + [ symmetric g ] + f := bot; + h := g; + WHILE h \ bot + INV { kruskal_invariant f g h } + VAR { card { x . regular x \ x \ --h } } + DO e := minarc h; + IF e \ -forest_components f THEN + f := (f \ -(top * e * f\<^sup>T\<^sup>\)) \ (f \ top * e * f\<^sup>T\<^sup>\)\<^sup>T \ e + ELSE + SKIP + FI; + h := h \ -e \ -e\<^sup>T + OD + [ minimum_spanning_forest f g ]" +proof vcg_tc_simp + assume "symmetric g" + thus "kruskal_invariant bot g g" + using kruskal_vc_1 kruskal_exists_minimal_spanning kruskal_invariant_def by simp +next + fix f h n + let ?e = "minarc h" + let ?f = "(f \ -(top * ?e * f\<^sup>T\<^sup>\)) \ (f \ top * ?e * f\<^sup>T\<^sup>\)\<^sup>T \ ?e" + let ?h = "h \ -?e \ -?e\<^sup>T" + let ?F = "forest_components f" + let ?n1 = "card { x . regular x \ x \ --h }" + let ?n2 = "card { x . regular x \ x \ --h \ x \ -?e \ x \ -?e\<^sup>T }" + assume 1: "kruskal_invariant f g h \ h \ bot \ ?n1 = n" + from 1 obtain w where 2: "minimum_spanning_forest w g \ f \ w \ w\<^sup>T" + using kruskal_invariant_def by auto + hence 3: "regular f \ regular w \ regular ?e" + using 1 by (metis kruskal_invariant_def kruskal_spanning_invariant_def minimum_spanning_forest_def spanning_forest_def minarc_regular) + have "(?e \ -?F \ kruskal_invariant ?f g ?h \ ?n2 < ?n1) \ (\ ?e \ -?F \ kruskal_invariant f g ?h \ ?n2 < ?n1)" + proof (rule conjI) + show "?e \ -?F \ kruskal_invariant ?f g ?h \ ?n2 < ?n1" + proof + assume 4: "?e \ -?F" + have 5: "equivalence ?F" + using 1 kruskal_invariant_def kruskal_spanning_invariant_def forest_components_equivalence spanning_forest_def by simp + have "?e\<^sup>T * top * ?e\<^sup>T = ?e\<^sup>T" + using 1 by (simp add: arc_top_arc minarc_arc) + hence "?e\<^sup>T * top * ?e\<^sup>T \ -?F" + using 4 5 conv_complement conv_isotone by fastforce + hence 6: "?e * ?F * ?e = bot" + using le_bot triple_schroeder_p by simp + show "kruskal_invariant ?f g ?h \ ?n2 < ?n1" + proof (unfold kruskal_invariant_def, intro conjI) + show "kruskal_spanning_invariant ?f g ?h" + using 1 4 kruskal_vc_2 kruskal_invariant_def by simp + next + show "\w . minimum_spanning_forest w g \ ?f \ w \ w\<^sup>T" + proof + let ?p = "w \ top * ?e * w\<^sup>T\<^sup>\" + let ?v = "(w \ -(top * ?e * w\<^sup>T\<^sup>\)) \ ?p\<^sup>T" + have 7: "regular ?p" + using 3 regular_closed_star regular_conv_closed regular_mult_closed by simp + have 8: "injective ?v" + apply (rule kruskal_exchange_injective_inv_1) + using 2 minimum_spanning_forest_def spanning_forest_def apply simp + apply (simp add: covector_mult_closed) + apply (simp add: comp_associative comp_isotone star.right_plus_below_circ) + using 1 2 kruskal_injective_inv_3 minarc_arc minimum_spanning_forest_def spanning_forest_def by simp + have 9: "components g \ forest_components ?v" + apply (rule kruskal_exchange_spanning_inv_1) + using 8 apply simp + using 7 apply simp + using 2 minimum_spanning_forest_def spanning_forest_def by simp + have 10: "spanning_forest ?v g" + proof (unfold spanning_forest_def, intro conjI) + show "injective ?v" + using 8 by simp + next + show "acyclic ?v" + apply (rule kruskal_exchange_acyclic_inv_1) + using 2 minimum_spanning_forest_def spanning_forest_def apply simp + by (simp add: covector_mult_closed) + next + show "?v \ --g" + apply (rule sup_least) + using 2 inf.coboundedI1 minimum_spanning_forest_def spanning_forest_def apply simp + using 1 2 by (metis kruskal_invariant_def kruskal_spanning_invariant_def conv_complement conv_dist_inf order.trans inf.absorb2 inf.cobounded1 minimum_spanning_forest_def spanning_forest_def) + next + show "components g \ forest_components ?v" + using 9 by simp + next + show "regular ?v" + using 3 regular_closed_star regular_conv_closed regular_mult_closed by simp + qed + have 11: "sum (?v \ g) = sum (w \ g)" + proof - + have "sum (?v \ g) = sum (w \ -(top * ?e * w\<^sup>T\<^sup>\) \ g) + sum (?p\<^sup>T \ g)" + using 2 by (metis conv_complement conv_top epm_8 inf_import_p inf_top_right regular_closed_top vector_top_closed minimum_spanning_forest_def spanning_forest_def sum_disjoint) + also have "... = sum (w \ -(top * ?e * w\<^sup>T\<^sup>\) \ g) + sum (?p \ g)" + using 1 kruskal_invariant_def kruskal_spanning_invariant_def sum_symmetric by simp + also have "... = sum (((w \ -(top * ?e * w\<^sup>T\<^sup>\)) \ ?p) \ g)" + using inf_commute inf_left_commute sum_disjoint by simp + also have "... = sum (w \ g)" + using 3 7 maddux_3_11_pp by simp + finally show ?thesis + by simp + qed + have 12: "?v \ ?v\<^sup>T = w \ w\<^sup>T" + proof - + have "?v \ ?v\<^sup>T = (w \ -?p) \ ?p\<^sup>T \ (w\<^sup>T \ -?p\<^sup>T) \ ?p" + using conv_complement conv_dist_inf conv_dist_sup inf_import_p sup_assoc by simp + also have "... = w \ w\<^sup>T" + using 3 7 conv_complement conv_dist_inf inf_import_p maddux_3_11_pp sup_monoid.add_assoc sup_monoid.add_commute by simp + finally show ?thesis + by simp + qed + have 13: "?v * ?e\<^sup>T = bot" + apply (rule kruskal_reroot_edge) + using 1 apply (simp add: minarc_arc) + using 2 minimum_spanning_forest_def spanning_forest_def by simp + have "?v \ ?e \ ?v \ top * ?e" + using inf.sup_right_isotone top_left_mult_increasing by simp + also have "... \ ?v * (top * ?e)\<^sup>T" + using covector_restrict_comp_conv covector_mult_closed vector_top_closed by simp + finally have 14: "?v \ ?e = bot" + using 13 by (metis conv_dist_comp mult_assoc le_bot mult_left_zero) + let ?d = "?v \ top * ?e\<^sup>T * ?v\<^sup>T\<^sup>\ \ ?F * ?e\<^sup>T * top \ top * ?e * -?F" + let ?w = "(?v \ -?d) \ ?e" + have 15: "regular ?d" + using 3 regular_closed_star regular_conv_closed regular_mult_closed by simp + have 16: "?F \ -?d" + apply (rule kruskal_edge_between_components_1) + using 5 apply simp + using 1 conv_dist_comp minarc_arc mult_assoc by simp + have 17: "f \ f\<^sup>T \ (?v \ -?d \ -?d\<^sup>T) \ (?v\<^sup>T \ -?d \ -?d\<^sup>T)" + apply (rule kruskal_edge_between_components_2) + using 16 apply simp + using 1 kruskal_invariant_def kruskal_spanning_invariant_def spanning_forest_def apply simp + using 2 12 by (metis conv_dist_sup conv_involutive conv_isotone le_supI sup_commute) + show "minimum_spanning_forest ?w g \ ?f \ ?w \ ?w\<^sup>T" + proof (intro conjI) + have 18: "?e\<^sup>T \ ?v\<^sup>\" + apply (rule kruskal_edge_arc_1[where g=g and h=h]) + using minarc_below apply simp + using 1 apply (metis kruskal_invariant_def kruskal_spanning_invariant_def inf_le1) + using 1 kruskal_invariant_def kruskal_spanning_invariant_def apply simp + using 9 apply simp + using 13 by simp + have 19: "arc ?d" + apply (rule kruskal_edge_arc) + using 5 apply simp + using 10 spanning_forest_def apply blast + using 1 apply (simp add: minarc_arc) + using 3 apply (metis conv_complement pp_dist_star regular_mult_closed) + using 2 8 12 apply (simp add: kruskal_forest_components_inf) + using 10 spanning_forest_def apply simp + using 13 apply simp + using 6 apply simp + using 18 by simp + show "minimum_spanning_forest ?w g" + proof (unfold minimum_spanning_forest_def, intro conjI) + have "(?v \ -?d) * ?e\<^sup>T \ ?v * ?e\<^sup>T" + using inf_le1 mult_left_isotone by simp + hence "(?v \ -?d) * ?e\<^sup>T = bot" + using 13 le_bot by simp + hence 20: "?e * (?v \ -?d)\<^sup>T = bot" + using conv_dist_comp conv_involutive conv_bot by force + have 21: "injective ?w" + apply (rule injective_sup) + using 8 apply (simp add: injective_inf_closed) + using 20 apply simp + using 1 arc_injective minarc_arc by blast + show "spanning_forest ?w g" + proof (unfold spanning_forest_def, intro conjI) + show "injective ?w" + using 21 by simp + next + show "acyclic ?w" + apply (rule kruskal_exchange_acyclic_inv_2) + using 10 spanning_forest_def apply blast + using 8 apply simp + using inf.coboundedI1 apply simp + using 19 apply simp + using 1 apply (simp add: minarc_arc) + using inf.cobounded2 inf.coboundedI1 apply simp + using 13 by simp + next + have "?w \ ?v \ ?e" + using inf_le1 sup_left_isotone by simp + also have "... \ --g \ ?e" + using 10 sup_left_isotone spanning_forest_def by blast + also have "... \ --g \ --h" + by (simp add: le_supI2 minarc_below) + also have "... = --g" + using 1 by (metis kruskal_invariant_def kruskal_spanning_invariant_def pp_isotone_inf sup.orderE) + finally show "?w \ --g" + by simp + next + have 22: "?d \ (?v \ -?d)\<^sup>T\<^sup>\ * ?e\<^sup>T * top" + apply (rule kruskal_exchange_spanning_inv_2) + using 8 apply simp + using 13 apply (metis semiring.mult_not_zero star_absorb star_simulation_right_equal) + using 17 apply simp + by (simp add: inf.coboundedI1) + have "components g \ forest_components ?v" + using 10 spanning_forest_def by auto + also have "... \ forest_components ?w" + apply (rule kruskal_exchange_forest_components_inv) + using 21 apply simp + using 15 apply simp + using 1 apply (simp add: arc_top_arc minarc_arc) + apply (simp add: inf.coboundedI1) + using 13 apply simp + using 8 apply simp + apply (simp add: le_infI1) + using 22 by simp + finally show "components g \ forest_components ?w" + by simp + next + show "regular ?w" + using 3 7 regular_conv_closed by simp + qed + next + have 23: "?e \ g \ bot" + using 1 by (metis kruskal_invariant_def kruskal_spanning_invariant_def comp_inf.semiring.mult_zero_right inf.sup_monoid.add_assoc inf.sup_monoid.add_commute minarc_bot_iff minarc_meet_bot) + have "g \ -h \ (g \ -h)\<^sup>\" + using star.circ_increasing by simp + also have "... \ (--(g \ -h))\<^sup>\" + using pp_increasing star_isotone by blast + also have "... \ ?F" + using 1 kruskal_invariant_def kruskal_spanning_invariant_def inf.sup_monoid.add_commute spanning_forest_def by simp + finally have 24: "g \ -h \ ?F" + by simp + have "?d \ --g" + using 10 inf.coboundedI1 spanning_forest_def by blast + hence "?d \ --g \ -?F" + using 16 inf.boundedI p_antitone_iff by simp + also have "... = --(g \ -?F)" + by simp + also have "... \ --h" + using 24 p_shunting_swap pp_isotone by fastforce + finally have 25: "?d \ --h" + by simp + have "?d = bot \ top = bot" + using 19 by (metis mult_left_zero mult_right_zero) + hence "?d \ bot" + using 1 le_bot by auto + hence 26: "?d \ h \ bot" + using 25 by (metis inf.absorb_iff2 inf_commute pseudo_complement) + have "sum (?e \ g) = sum (?e \ --h \ g)" + by (simp add: inf.absorb1 minarc_below) + also have "... = sum (?e \ h)" + using 1 by (metis kruskal_invariant_def kruskal_spanning_invariant_def inf.left_commute inf.sup_monoid.add_commute) + also have "... \ sum (?d \ h)" + using 19 26 minarc_min by simp + also have "... = sum (?d \ (--h \ g))" + using 1 kruskal_invariant_def kruskal_spanning_invariant_def inf_commute by simp + also have "... = sum (?d \ g)" + using 25 by (simp add: inf.absorb2 inf_assoc inf_commute) + finally have 27: "sum (?e \ g) \ sum (?d \ g)" + by simp + have "?v \ ?e \ -?d = bot" + using 14 by simp + hence "sum (?w \ g) = sum (?v \ -?d \ g) + sum (?e \ g)" + using sum_disjoint inf_commute inf_assoc by simp + also have "... \ sum (?v \ -?d \ g) + sum (?d \ g)" + using 23 27 sum_plus_right_isotone by simp + also have "... = sum (((?v \ -?d) \ ?d) \ g)" + using sum_disjoint inf_le2 pseudo_complement by simp + also have "... = sum ((?v \ ?d) \ (-?d \ ?d) \ g)" + by (simp add: sup_inf_distrib2) + also have "... = sum ((?v \ ?d) \ g)" + using 15 by (metis inf_top_right stone) + also have "... = sum (?v \ g)" + by (simp add: inf.sup_monoid.add_assoc) + finally have "sum (?w \ g) \ sum (?v \ g)" + by simp + thus "\u . spanning_forest u g \ sum (?w \ g) \ sum (u \ g)" + using 2 11 minimum_spanning_forest_def by auto + qed + next + have "?f \ f \ f\<^sup>T \ ?e" + using conv_dist_inf inf_le1 sup_left_isotone sup_mono by presburger + also have "... \ (?v \ -?d \ -?d\<^sup>T) \ (?v\<^sup>T \ -?d \ -?d\<^sup>T) \ ?e" + using 17 sup_left_isotone by simp + also have "... \ (?v \ -?d) \ (?v\<^sup>T \ -?d \ -?d\<^sup>T) \ ?e" + using inf.cobounded1 sup_inf_distrib2 by presburger + also have "... = ?w \ (?v\<^sup>T \ -?d \ -?d\<^sup>T)" + by (simp add: sup_assoc sup_commute) + also have "... \ ?w \ (?v\<^sup>T \ -?d\<^sup>T)" + using inf.sup_right_isotone inf_assoc sup_right_isotone by simp + also have "... \ ?w \ ?w\<^sup>T" + using conv_complement conv_dist_inf conv_dist_sup sup_right_isotone by simp + finally show "?f \ ?w \ ?w\<^sup>T" + by simp + qed + qed + next + show "?n2 < ?n1" + using 1 kruskal_vc_2 kruskal_invariant_def by auto + qed + qed + next + show "\ ?e \ -?F \ kruskal_invariant f g ?h \ ?n2 < ?n1" + using 1 kruskal_vc_2 kruskal_invariant_def by auto + qed + thus "(?e \ -?F \ kruskal_invariant ?f g ?h \ ?n2 < n) \ (\ ?e \ -?F \ kruskal_invariant f g ?h \ ?n2 < n)" + using 1 by blast +next + fix f h + assume 28: "kruskal_invariant f g h \ h = bot" + hence 29: "spanning_forest f g" + using kruskal_invariant_def kruskal_spanning_invariant_def by auto + from 28 obtain w where 30: "minimum_spanning_forest w g \ f \ w \ w\<^sup>T" + using kruskal_invariant_def by auto + hence "w = w \ --g" + by (simp add: inf.absorb1 minimum_spanning_forest_def spanning_forest_def) + also have "... \ w \ components g" + by (metis inf.sup_right_isotone star.circ_increasing) + also have "... \ w \ f\<^sup>T\<^sup>\ * f\<^sup>\" + using 29 spanning_forest_def inf.sup_right_isotone by simp + also have "... \ f \ f\<^sup>T" + apply (rule cancel_separate_6[where z=w and y="w\<^sup>T"]) + using 30 minimum_spanning_forest_def spanning_forest_def apply simp + using 30 apply (metis conv_dist_inf conv_dist_sup conv_involutive inf.cobounded2 inf.orderE) + using 30 apply (simp add: sup_commute) + using 30 minimum_spanning_forest_def spanning_forest_def apply simp + using 30 by (metis acyclic_star_below_complement comp_inf.mult_right_isotone inf_p le_bot minimum_spanning_forest_def spanning_forest_def) + finally have 31: "w \ f \ f\<^sup>T" + by simp + have "sum (f \ g) = sum ((w \ w\<^sup>T) \ (f \ g))" + using 30 by (metis inf_absorb2 inf.assoc) + also have "... = sum (w \ (f \ g)) + sum (w\<^sup>T \ (f \ g))" + using 30 inf.commute acyclic_asymmetric sum_disjoint minimum_spanning_forest_def spanning_forest_def by simp + also have "... = sum (w \ (f \ g)) + sum (w \ (f\<^sup>T \ g\<^sup>T))" + by (metis conv_dist_inf conv_involutive sum_conv) + also have "... = sum (f \ (w \ g)) + sum (f\<^sup>T \ (w \ g))" + using 28 inf.commute inf.assoc kruskal_invariant_def kruskal_spanning_invariant_def by simp + also have "... = sum ((f \ f\<^sup>T) \ (w \ g))" + using 29 acyclic_asymmetric inf.sup_monoid.add_commute sum_disjoint spanning_forest_def by simp + also have "... = sum (w \ g)" + using 31 by (metis inf_absorb2 inf.assoc) + finally show "minimum_spanning_forest f g" + using 29 30 minimum_spanning_forest_def by simp +qed + +end + +end + diff --git a/thys/Relational_Minimum_Spanning_Trees/Prim.thy b/thys/Relational_Minimum_Spanning_Trees/Prim.thy new file mode 100644 --- /dev/null +++ b/thys/Relational_Minimum_Spanning_Trees/Prim.thy @@ -0,0 +1,479 @@ +(* Title: Prim's Minimum Spanning Tree Algorithm + Author: Walter Guttmann + Maintainer: Walter Guttmann +*) + +section \Prim's Minimum Spanning Tree Algorithm\ + +text \ +In this theory we prove total correctness of Prim's minimum spanning tree algorithm. +The proof has the same overall structure as the total-correctness proof of Kruskal's algorithm \cite{Guttmann2018c}. +The partial-correctness proof of Prim's algorithm is discussed in \cite{Guttmann2016c,Guttmann2018b}. +\ + +theory Prim + +imports Aggregation_Algebras.Hoare_Logic Aggregation_Algebras.Aggregation_Algebras + +begin + +context m_kleene_algebra +begin + +abbreviation "component g r \ r\<^sup>T * (--g)\<^sup>\" +definition "spanning_tree t g r \ forest t \ t \ (component g r)\<^sup>T * (component g r) \ --g \ component g r \ r\<^sup>T * t\<^sup>\ \ regular t" +definition "minimum_spanning_tree t g r \ spanning_tree t g r \ (\u . spanning_tree u g r \ sum (t \ g) \ sum (u \ g))" +definition "prim_precondition g r \ g = g\<^sup>T \ injective r \ vector r \ regular r" +definition "prim_spanning_invariant t v g r \ prim_precondition g r \ v\<^sup>T = r\<^sup>T * t\<^sup>\ \ spanning_tree t (v * v\<^sup>T \ g) r" +definition "prim_invariant t v g r \ prim_spanning_invariant t v g r \ (\w . minimum_spanning_tree w g r \ t \ w)" + +lemma span_tree_split: + assumes "vector r" + shows "t \ (component g r)\<^sup>T * (component g r) \ --g \ (t \ (component g r)\<^sup>T \ t \ component g r \ t \ --g)" +proof - + have "(component g r)\<^sup>T * (component g r) = (component g r)\<^sup>T \ component g r" + by (metis assms conv_involutive covector_mult_closed vector_conv_covector vector_covector) + thus ?thesis + by simp +qed + +lemma span_tree_component: + assumes "spanning_tree t g r" + shows "component g r = component t r" + using assms by (simp add: antisym mult_right_isotone star_isotone spanning_tree_def) + +text \ +We first show three verification conditions which are used in both correctness proofs. +\ + +lemma prim_vc_1: + assumes "prim_precondition g r" + shows "prim_spanning_invariant bot r g r" +proof (unfold prim_spanning_invariant_def, intro conjI) + show "prim_precondition g r" + using assms by simp +next + show "r\<^sup>T = r\<^sup>T * bot\<^sup>\" + by (simp add: star_absorb) +next + let ?ss = "r * r\<^sup>T \ g" + show "spanning_tree bot ?ss r" + proof (unfold spanning_tree_def, intro conjI) + show "injective bot" + by simp + next + show "acyclic bot" + by simp + next + show "bot \ (component ?ss r)\<^sup>T * (component ?ss r) \ --?ss" + by simp + next + have "component ?ss r \ component (r * r\<^sup>T) r" + by (simp add: mult_right_isotone star_isotone) + also have "... \ r\<^sup>T * 1\<^sup>\" + using assms by (metis inf.eq_iff p_antitone regular_one_closed star_sub_one prim_precondition_def) + also have "... = r\<^sup>T * bot\<^sup>\" + by (simp add: star.circ_zero star_one) + finally show "component ?ss r \ r\<^sup>T * bot\<^sup>\" + . + next + show "regular bot" + by simp + qed +qed + +lemma prim_vc_2: + assumes "prim_spanning_invariant t v g r" + and "v * -v\<^sup>T \ g \ bot" + shows "prim_spanning_invariant (t \ minarc (v * -v\<^sup>T \ g)) (v \ minarc (v * -v\<^sup>T \ g)\<^sup>T * top) g r \ card { x . regular x \ x \ component g r \ x \ -(v \ minarc (v * -v\<^sup>T \ g)\<^sup>T * top)\<^sup>T } < card { x . regular x \ x \ component g r \ x \ -v\<^sup>T }" +proof - + let ?vcv = "v * -v\<^sup>T \ g" + let ?e = "minarc ?vcv" + let ?t = "t \ ?e" + let ?v = "v \ ?e\<^sup>T * top" + let ?c = "component g r" + let ?g = "--g" + let ?n1 = "card { x . regular x \ x \ ?c \ x \ -v\<^sup>T }" + let ?n2 = "card { x . regular x \ x \ ?c \ x \ -?v\<^sup>T }" + have 1: "regular v \ regular (v * v\<^sup>T) \ regular (?v * ?v\<^sup>T) \ regular (top * ?e)" + using assms(1) by (metis prim_spanning_invariant_def spanning_tree_def prim_precondition_def regular_conv_closed regular_closed_star regular_mult_closed conv_involutive regular_closed_top regular_closed_sup minarc_regular) + hence 2: "t \ v * v\<^sup>T \ ?g" + using assms(1) by (metis prim_spanning_invariant_def spanning_tree_def inf_pp_commute inf.boundedE) + hence 3: "t \ v * v\<^sup>T" + by simp + have 4: "t \ ?g" + using 2 by simp + have 5: "?e \ v * -v\<^sup>T \ ?g" + using 1 by (metis minarc_below pp_dist_inf regular_mult_closed regular_closed_p) + hence 6: "?e \ v * -v\<^sup>T" + by simp + have 7: "vector v" + using assms(1) prim_spanning_invariant_def prim_precondition_def by (simp add: covector_mult_closed vector_conv_covector) + hence 8: "?e \ v" + using 6 by (metis conv_complement inf.boundedE vector_complement_closed vector_covector) + have 9: "?e * t = bot" + using 3 6 7 et(1) by blast + have 10: "?e * t\<^sup>T = bot" + using 3 6 7 et(2) by simp + have 11: "arc ?e" + using assms(2) minarc_arc by simp + have "r\<^sup>T \ r\<^sup>T * t\<^sup>\" + by (metis mult_right_isotone order_refl semiring.mult_not_zero star.circ_separate_mult_1 star_absorb) + hence 12: "r\<^sup>T \ v\<^sup>T" + using assms(1) by (simp add: prim_spanning_invariant_def) + have 13: "vector r \ injective r \ v\<^sup>T = r\<^sup>T * t\<^sup>\" + using assms(1) prim_spanning_invariant_def prim_precondition_def minimum_spanning_tree_def spanning_tree_def reachable_restrict by simp + have "g = g\<^sup>T" + using assms(1) prim_invariant_def prim_spanning_invariant_def prim_precondition_def by simp + hence 14: "?g\<^sup>T = ?g" + using conv_complement by simp + show "prim_spanning_invariant ?t ?v g r \ ?n2 < ?n1" + proof (rule conjI) + show "prim_spanning_invariant ?t ?v g r" + proof (unfold prim_spanning_invariant_def, intro conjI) + show "prim_precondition g r" + using assms(1) prim_spanning_invariant_def by simp + next + show "?v\<^sup>T = r\<^sup>T * ?t\<^sup>\" + using assms(1) 6 7 9 by (simp add: reachable_inv prim_spanning_invariant_def prim_precondition_def spanning_tree_def) + next + let ?G = "?v * ?v\<^sup>T \ g" + show "spanning_tree ?t ?G r" + proof (unfold spanning_tree_def, intro conjI) + show "injective ?t" + using assms(1) 10 11 by (simp add: injective_inv prim_spanning_invariant_def spanning_tree_def) + next + show "acyclic ?t" + using assms(1) 3 6 7 acyclic_inv prim_spanning_invariant_def spanning_tree_def by simp + next + show "?t \ (component ?G r)\<^sup>T * (component ?G r) \ --?G" + using 1 2 5 7 13 prim_subgraph_inv inf_pp_commute mst_subgraph_inv_2 by auto + next + show "component (?v * ?v\<^sup>T \ g) r \ r\<^sup>T * ?t\<^sup>\" + proof - + have 15: "r\<^sup>T * (v * v\<^sup>T \ ?g)\<^sup>\ \ r\<^sup>T * t\<^sup>\" + using assms(1) 1 by (metis prim_spanning_invariant_def spanning_tree_def inf_pp_commute) + have "component (?v * ?v\<^sup>T \ g) r = r\<^sup>T * (?v * ?v\<^sup>T \ ?g)\<^sup>\" + using 1 by simp + also have "... \ r\<^sup>T * ?t\<^sup>\" + using 2 6 7 11 12 13 14 15 by (metis span_inv) + finally show ?thesis + . + qed + next + show "regular ?t" + using assms(1) by (metis prim_spanning_invariant_def spanning_tree_def regular_closed_sup minarc_regular) + qed + qed + next + have 16: "top * ?e \ ?c" + proof - + have "top * ?e = top * ?e\<^sup>T * ?e" + using 11 by (metis arc_top_edge mult_assoc) + also have "... \ v\<^sup>T * ?e" + using 7 8 by (metis conv_dist_comp conv_isotone mult_left_isotone symmetric_top_closed) + also have "... \ v\<^sup>T * ?g" + using 5 mult_right_isotone by auto + also have "... = r\<^sup>T * t\<^sup>\ * ?g" + using 13 by simp + also have "... \ r\<^sup>T * ?g\<^sup>\ * ?g" + using 4 by (simp add: mult_left_isotone mult_right_isotone star_isotone) + also have "... \ ?c" + by (simp add: comp_associative mult_right_isotone star.right_plus_below_circ) + finally show ?thesis + by simp + qed + have 17: "top * ?e \ -v\<^sup>T" + using 6 7 by (simp add: schroeder_4_p vTeT) + have 18: "\ top * ?e \ -(top * ?e)" + by (metis assms(2) inf.orderE minarc_bot_iff conv_complement_sub_inf inf_p inf_top.left_neutral p_bot symmetric_top_closed vector_top_closed) + have 19: "-?v\<^sup>T = -v\<^sup>T \ -(top * ?e)" + by (simp add: conv_dist_comp conv_dist_sup) + hence 20: "\ top * ?e \ -?v\<^sup>T" + using 18 by simp + show "?n2 < ?n1" + apply (rule psubset_card_mono) + using finite_regular apply simp + using 1 16 17 19 20 by auto + qed +qed + +lemma prim_vc_3: + assumes "prim_spanning_invariant t v g r" + and "v * -v\<^sup>T \ g = bot" + shows "spanning_tree t g r" +proof - + let ?g = "--g" + have 1: "regular v \ regular (v * v\<^sup>T)" + using assms(1) by (metis prim_spanning_invariant_def spanning_tree_def prim_precondition_def regular_conv_closed regular_closed_star regular_mult_closed conv_involutive) + have 2: "v * -v\<^sup>T \ ?g = bot" + using assms(2) pp_inf_bot_iff pp_pp_inf_bot_iff by simp + have 3: "v\<^sup>T = r\<^sup>T * t\<^sup>\ \ vector v" + using assms(1) by (simp add: covector_mult_closed prim_invariant_def prim_spanning_invariant_def vector_conv_covector prim_precondition_def) + have 4: "t \ v * v\<^sup>T \ ?g" + using assms(1) 1 by (metis prim_spanning_invariant_def inf_pp_commute spanning_tree_def inf.boundedE) + have "r\<^sup>T * (v * v\<^sup>T \ ?g)\<^sup>\ \ r\<^sup>T * t\<^sup>\" + using assms(1) 1 by (metis prim_spanning_invariant_def inf_pp_commute spanning_tree_def) + hence 5: "component g r = v\<^sup>T" + using 1 2 3 4 by (metis span_post) + have "regular (v * v\<^sup>T)" + using assms(1) by (metis prim_spanning_invariant_def spanning_tree_def prim_precondition_def regular_conv_closed regular_closed_star regular_mult_closed conv_involutive) + hence 6: "t \ v * v\<^sup>T \ ?g" + by (metis assms(1) prim_spanning_invariant_def spanning_tree_def inf_pp_commute inf.boundedE) + show "spanning_tree t g r" + apply (unfold spanning_tree_def, intro conjI) + using assms(1) prim_spanning_invariant_def spanning_tree_def apply simp + using assms(1) prim_spanning_invariant_def spanning_tree_def apply simp + using 5 6 apply simp + using assms(1) 5 prim_spanning_invariant_def apply simp + using assms(1) prim_spanning_invariant_def spanning_tree_def by simp +qed + +text \ +The following result shows that Prim's algorithm terminates and constructs a spanning tree. +We cannot yet show that this is a minimum spanning tree. +\ + +theorem prim_spanning: + "VARS t v e + [ prim_precondition g r ] + t := bot; + v := r; + WHILE v * -v\<^sup>T \ g \ bot + INV { prim_spanning_invariant t v g r } + VAR { card { x . regular x \ x \ component g r \ -v\<^sup>T } } + DO e := minarc (v * -v\<^sup>T \ g); + t := t \ e; + v := v \ e\<^sup>T * top + OD + [ spanning_tree t g r ]" + apply vcg_tc_simp + apply (simp add: prim_vc_1) + using prim_vc_2 apply blast + using prim_vc_3 by auto + +text \ +Because we have shown total correctness, we conclude that a spanning tree exists. +\ + +lemma prim_exists_spanning: + "prim_precondition g r \ \t . spanning_tree t g r" + using tc_extract_function prim_spanning by blast + +text \ +This implies that a minimum spanning tree exists, which is used in the subsequent correctness proof. +\ + +lemma prim_exists_minimal_spanning: + assumes "prim_precondition g r" + shows "\t . minimum_spanning_tree t g r" +proof - + let ?s = "{ t . spanning_tree t g r }" + have "\m\?s . \z\?s . sum (m \ g) \ sum (z \ g)" + apply (rule finite_set_minimal) + using finite_regular spanning_tree_def apply simp + using assms prim_exists_spanning apply simp + using sum_linear by simp + thus ?thesis + using minimum_spanning_tree_def by simp +qed + +text \ +Prim's minimum spanning tree algorithm terminates and is correct. +This is the same algorithm that is used in the previous correctness proof, with the same precondition and variant, but with a different invariant and postcondition. +\ + +theorem prim: + "VARS t v e + [ prim_precondition g r \ (\w . minimum_spanning_tree w g r) ] + t := bot; + v := r; + WHILE v * -v\<^sup>T \ g \ bot + INV { prim_invariant t v g r } + VAR { card { x . regular x \ x \ component g r \ -v\<^sup>T } } + DO e := minarc (v * -v\<^sup>T \ g); + t := t \ e; + v := v \ e\<^sup>T * top + OD + [ minimum_spanning_tree t g r ]" +proof vcg_tc_simp + assume "prim_precondition g r \ (\w . minimum_spanning_tree w g r)" + thus "prim_invariant bot r g r" + using prim_invariant_def prim_vc_1 by simp +next + fix t v n + let ?vcv = "v * -v\<^sup>T \ g" + let ?vv = "v * v\<^sup>T \ g" + let ?e = "minarc ?vcv" + let ?t = "t \ ?e" + let ?v = "v \ ?e\<^sup>T * top" + let ?c = "component g r" + let ?g = "--g" + let ?n1 = "card { x . regular x \ x \ ?c \ x \ -v\<^sup>T }" + let ?n2 = "card { x . regular x \ x \ ?c \ x \ -?v\<^sup>T }" + assume 1: "prim_invariant t v g r \ ?vcv \ bot \ ?n1 = n" + hence 2: "regular v \ regular (v * v\<^sup>T)" + by (metis (no_types, hide_lams) prim_invariant_def prim_spanning_invariant_def spanning_tree_def prim_precondition_def regular_conv_closed regular_closed_star regular_mult_closed conv_involutive) + have 3: "t \ v * v\<^sup>T \ ?g" + using 1 2 by (metis (no_types, hide_lams) prim_invariant_def prim_spanning_invariant_def spanning_tree_def inf_pp_commute inf.boundedE) + hence 4: "t \ v * v\<^sup>T" + by simp + have 5: "t \ ?g" + using 3 by simp + have 6: "?e \ v * -v\<^sup>T \ ?g" + using 2 by (metis minarc_below pp_dist_inf regular_mult_closed regular_closed_p) + hence 7: "?e \ v * -v\<^sup>T" + by simp + have 8: "vector v" + using 1 prim_invariant_def prim_spanning_invariant_def prim_precondition_def by (simp add: covector_mult_closed vector_conv_covector) + have 9: "arc ?e" + using 1 minarc_arc by simp + from 1 obtain w where 10: "minimum_spanning_tree w g r \ t \ w" + by (metis prim_invariant_def) + hence 11: "vector r \ injective r \ v\<^sup>T = r\<^sup>T * t\<^sup>\ \ forest w \ t \ w \ w \ ?c\<^sup>T * ?c \ ?g \ r\<^sup>T * (?c\<^sup>T * ?c \ ?g)\<^sup>\ \ r\<^sup>T * w\<^sup>\" + using 1 2 prim_invariant_def prim_spanning_invariant_def prim_precondition_def minimum_spanning_tree_def spanning_tree_def reachable_restrict by simp + hence 12: "w * v \ v" + using predecessors_reachable reachable_restrict by auto + have 13: "g = g\<^sup>T" + using 1 prim_invariant_def prim_spanning_invariant_def prim_precondition_def by simp + hence 14: "?g\<^sup>T = ?g" + using conv_complement by simp + have "prim_invariant ?t ?v g r \ ?n2 < ?n1" + proof (unfold prim_invariant_def, intro conjI) + show "prim_spanning_invariant ?t ?v g r" + using 1 prim_invariant_def prim_vc_2 by blast + next + show "\w . minimum_spanning_tree w g r \ ?t \ w" + proof + let ?f = "w \ v * -v\<^sup>T \ top * ?e * w\<^sup>T\<^sup>\" + let ?p = "w \ -v * -v\<^sup>T \ top * ?e * w\<^sup>T\<^sup>\" + let ?fp = "w \ -v\<^sup>T \ top * ?e * w\<^sup>T\<^sup>\" + let ?w = "(w \ -?fp) \ ?p\<^sup>T \ ?e" + have 15: "regular ?f \ regular ?fp \ regular ?w" + using 2 10 by (metis regular_conv_closed regular_closed_star regular_mult_closed regular_closed_top regular_closed_inf regular_closed_sup minarc_regular minimum_spanning_tree_def spanning_tree_def) + show "minimum_spanning_tree ?w g r \ ?t \ ?w" + proof (intro conjI) + show "minimum_spanning_tree ?w g r" + proof (unfold minimum_spanning_tree_def, intro conjI) + show "spanning_tree ?w g r" + proof (unfold spanning_tree_def, intro conjI) + show "injective ?w" + using 7 8 9 11 exchange_injective by blast + next + show "acyclic ?w" + using 7 8 11 12 exchange_acyclic by blast + next + show "?w \ ?c\<^sup>T * ?c \ --g" + proof - + have 16: "w \ -?fp \ ?c\<^sup>T * ?c \ --g" + using 10 by (simp add: le_infI1 minimum_spanning_tree_def spanning_tree_def) + have "?p\<^sup>T \ w\<^sup>T" + by (simp add: conv_isotone inf.sup_monoid.add_assoc) + also have "... \ (?c\<^sup>T * ?c \ --g)\<^sup>T" + using 11 conv_order by simp + also have "... = ?c\<^sup>T * ?c \ --g" + using 2 14 conv_dist_comp conv_dist_inf by simp + finally have 17: "?p\<^sup>T \ ?c\<^sup>T * ?c \ --g" + . + have "?e \ ?c\<^sup>T * ?c \ ?g" + using 5 6 11 mst_subgraph_inv by auto + thus ?thesis + using 16 17 by simp + qed + next + show "?c \ r\<^sup>T * ?w\<^sup>\" + proof - + have "?c \ r\<^sup>T * w\<^sup>\" + using 10 minimum_spanning_tree_def spanning_tree_def by simp + also have "... \ r\<^sup>T * ?w\<^sup>\" + using 4 7 8 10 11 12 15 by (metis mst_reachable_inv) + finally show ?thesis + . + qed + next + show "regular ?w" + using 15 by simp + qed + next + have 18: "?f \ ?p = ?fp" + using 2 8 epm_1 by fastforce + have "arc (w \ --v * -v\<^sup>T \ top * ?e * w\<^sup>T\<^sup>\)" + using 5 6 8 9 11 12 reachable_restrict arc_edge by auto + hence 19: "arc ?f" + using 2 by simp + hence "?f = bot \ top = bot" + by (metis mult_left_zero mult_right_zero) + hence "?f \ bot" + using 1 le_bot by auto + hence "?f \ v * -v\<^sup>T \ ?g \ bot" + using 2 11 by (simp add: inf.absorb1 le_infI1) + hence "g \ (?f \ v * -v\<^sup>T) \ bot" + using inf_commute pp_inf_bot_iff by simp + hence 20: "?f \ ?vcv \ bot" + by (simp add: inf_assoc inf_commute) + hence 21: "?f \ g = ?f \ ?vcv" + using 2 by (simp add: inf_assoc inf_commute inf_left_commute) + have 22: "?e \ g = minarc ?vcv \ ?vcv" + using 7 by (simp add: inf.absorb2 inf.assoc inf.commute) + hence 23: "sum (?e \ g) \ sum (?f \ g)" + using 15 19 20 21 by (simp add: minarc_min) + have "?e \ bot" + using 20 comp_inf.semiring.mult_not_zero semiring.mult_not_zero by blast + hence 24: "?e \ g \ bot" + using 22 minarc_meet_bot by auto + have "sum (?w \ g) = sum (w \ -?fp \ g) + sum (?p\<^sup>T \ g) + sum (?e \ g)" + using 7 8 10 by (metis sum_disjoint_3 epm_8 epm_9 epm_10 minimum_spanning_tree_def spanning_tree_def) + also have "... = sum (((w \ -?fp) \ ?p\<^sup>T) \ g) + sum (?e \ g)" + using 11 by (metis epm_8 sum_disjoint) + also have "... \ sum (((w \ -?fp) \ ?p\<^sup>T) \ g) + sum (?f \ g)" + using 23 24 by (simp add: sum_plus_right_isotone) + also have "... = sum (w \ -?fp \ g) + sum (?p\<^sup>T \ g) + sum (?f \ g)" + using 11 by (metis epm_8 sum_disjoint) + also have "... = sum (w \ -?fp \ g) + sum (?p \ g) + sum (?f \ g)" + using 13 sum_symmetric by auto + also have "... = sum (((w \ -?fp) \ ?p \ ?f) \ g)" + using 2 8 by (metis sum_disjoint_3 epm_11 epm_12 epm_13) + also have "... = sum (w \ g)" + using 2 8 15 18 epm_2 by force + finally have "sum (?w \ g) \ sum (w \ g)" + . + thus "\u . spanning_tree u g r \ sum (?w \ g) \ sum (u \ g)" + using 10 order_lesseq_imp minimum_spanning_tree_def by auto + qed + next + show "?t \ ?w" + using 4 8 10 mst_extends_new_tree by simp + qed + qed + next + show "?n2 < ?n1" + using 1 prim_invariant_def prim_vc_2 by auto + qed + thus "prim_invariant ?t ?v g r \ ?n2 < n" + using 1 by blast +next + fix t v + let ?g = "--g" + assume 25: "prim_invariant t v g r \ v * -v\<^sup>T \ g = bot" + hence 26: "regular v" + by (metis prim_invariant_def prim_spanning_invariant_def spanning_tree_def prim_precondition_def regular_conv_closed regular_closed_star regular_mult_closed conv_involutive) + from 25 obtain w where 27: "minimum_spanning_tree w g r \ t \ w" + by (metis prim_invariant_def) + have "spanning_tree t g r" + using 25 prim_invariant_def prim_vc_3 by blast + hence "component g r = v\<^sup>T" + by (metis 25 prim_invariant_def span_tree_component prim_spanning_invariant_def spanning_tree_def) + hence 28: "w \ v * v\<^sup>T" + using 26 27 by (simp add: minimum_spanning_tree_def spanning_tree_def inf_pp_commute) + have "vector r \ injective r \ forest w" + using 25 27 by (simp add: prim_invariant_def prim_spanning_invariant_def prim_precondition_def minimum_spanning_tree_def spanning_tree_def) + hence "w = t" + using 25 27 28 prim_invariant_def prim_spanning_invariant_def mst_post by blast + thus "minimum_spanning_tree t g r" + using 27 by simp +qed + +end + +end + diff --git a/thys/Relational_Minimum_Spanning_Trees/ROOT b/thys/Relational_Minimum_Spanning_Trees/ROOT new file mode 100644 --- /dev/null +++ b/thys/Relational_Minimum_Spanning_Trees/ROOT @@ -0,0 +1,18 @@ +chapter AFP + +session Relational_Minimum_Spanning_Trees (AFP) = Aggregation_Algebras + + + options [timeout = 600] + + sessions + Relational_Disjoint_Set_Forests + + theories + Kruskal + Prim + Boruvka + + document_files + "root.tex" + "root.bib" + diff --git a/thys/Relational_Minimum_Spanning_Trees/document/root.bib b/thys/Relational_Minimum_Spanning_Trees/document/root.bib new file mode 100644 --- /dev/null +++ b/thys/Relational_Minimum_Spanning_Trees/document/root.bib @@ -0,0 +1,89 @@ +@STRING{afp = {Archive of Formal Proofs}} +@STRING{dm = {Discrete Mathematics}} +@STRING{jlamp = {Journal of Logical and Algebraic Methods in Programming}} +@STRING{lncs = {Lecture Notes in Computer Science}} +@STRING{sv = {Springer}} +@STRING{tcs = {Theoretical Computer Science}} + +@Article{Boruvka1926, + author = {Bor\r{u}vka, O.}, + title = {O jist{\'e}m probl{\'e}mu minim{\'a}ln{\'i}m}, + journal = {Pr{\'a}ce moravsk{\'e} p{\v{r}}{\'i}rodo\-v{\v{e}}deck{\'e} spole{\v{c}}nosti}, + volume = 3, + number = 3, + pages = {37--58}, + year = 1926, + note = {} +} + +@Article{GrahamHell1985, + author = {Graham, R. L. and Hell, P.}, + title = {On the History of the Minimum Spanning Tree Problem}, + journal = {Annals of the History of Computing}, + volume = 7, + number = 1, + pages = {43--57}, + year = 1985, + note = {} +} + +@InProceedings{Guttmann2016c, + author = {Guttmann, W.}, + title = {Relation-Algebraic Verification of {Prim's} Minimum Spanning Tree Algorithm}, + editor = {Sampaio, A. and Wang, F.}, + booktitle = {Theoretical Aspects of Computing -- ICTAC 2016}, + publisher = sv, + series = lncs, + volume = 9965, + pages = {51--68}, + year = 2016, + note = {} +} + +@Article{Guttmann2018a, + author = {Guttmann, W.}, + title = {Aggregation Algebras}, + journal = afp, + year = 2018, + note = {} +} + +@Article{Guttmann2018b, + author = {Guttmann, W.}, + title = {An Algebraic Framework for Minimum Spanning Tree Problems}, + journal = tcs, + volume = 744, + pages = {37--55}, + year = 2018, + note = {} +} + +@Article{Guttmann2018c, + author = {Guttmann, W.}, + title = {Verifying Minimum Spanning Tree Algorithms with {Stone} Relation Algebras}, + journal = jlamp, + volume = 101, + pages = {132--150}, + year = 2018, + note = {} +} + +@Article{NesetrilMilkovaNesetrilova2001, + author = {Ne{\v{s}}et{\v{r}}il, J. and Milkov{\'a}, E. and Ne{\v{s}}et{\v{r}}ilov{\'a}, H.}, + title = {Otakar {Bor\r{u}vka} on minimum spanning tree problem -- {Translation} of both the 1926 papers, comments, history}, + journal = dm, + volume = 233, + number = {1--3}, + pages = {3--36}, + year = 2001, + note = {} +} + +@MastersThesis{RobinsonOBrien2020, + author = {Robinson-O'Brien, N.}, + title = {A formal correctness proof of {Bor\r{u}vka's} minimum spanning tree algorithm}, + school = {University of Canterbury}, + year = 2020, + note = {\url{https://doi.org/10.26021/10196}} +} + diff --git a/thys/Relational_Minimum_Spanning_Trees/document/root.tex b/thys/Relational_Minimum_Spanning_Trees/document/root.tex new file mode 100644 --- /dev/null +++ b/thys/Relational_Minimum_Spanning_Trees/document/root.tex @@ -0,0 +1,58 @@ +\documentclass[11pt,a4paper]{article} + +\usepackage{isabelle,isabellesym} +\usepackage{amssymb,ragged2e} +\usepackage{pdfsetup} + +\isabellestyle{it} +\renewenvironment{isamarkuptext}{\par\isastyletext\begin{isapar}\justifying\color{blue}}{\end{isapar}} +\renewcommand\labelitemi{$*$} +\urlstyle{rm} + +\begin{document} + +\title{Relational Minimum Spanning Tree Algorithms} +\author{Walter Guttmann and Nicolas Robinson-O'Brien} +\maketitle + +\begin{abstract} + We verify the correctness of Prim's, Kruskal's and Bor\r{u}vka's minimum spanning tree algorithms based on algebras for aggregation and minimisation. +\end{abstract} + +\tableofcontents + +\section{Overview} + +The theories described in this document prove the correctness of Prim's, Kruskal's and Bor\r{u}vka's minimum spanning tree algorithms. +Specifications and algorithms work in Stone-Kleene relation algebras extended by operations for aggregation and minimisation. +The algorithms are implemented in a simple imperative language and their proof uses Hoare logic. +The correctness proofs are discussed in \cite{Guttmann2016c,Guttmann2018b,Guttmann2018c,RobinsonOBrien2020}. + +\subsection{Prim's and Kruskal's minimum spanning tree algorithms} + +A framework based on Stone relation algebras and Kleene algebras and extended by operations for aggregation and minimisation was presented by the first author in \cite{Guttmann2016c,Guttmann2018b} and used to formally verify the correctness of Prim's minimum spanning tree algorithm. +It was extended in \cite{Guttmann2018c} and applied to prove the correctness of Kruskal's minimum spanning tree algorithm. + +Two theories, one each for Prim's and Kruskal's algorithms, prove total correctness of these algorithms. +As case studies for the algebraic framework, these two theories combined were originally part of another AFP entry \cite{Guttmann2018a}. + +\subsection{Bor\r{u}vka's minimum spanning tree algorithm} + +Otakar Bor\r{u}vka formalised the minimum spanning tree problem and proposed a solution to it \cite{Boruvka1926}. +Bor\r{u}vka's original paper is written in Czech; translations of varying completeness can be found in \cite{GrahamHell1985,NesetrilMilkovaNesetrilova2001}. + +The theory for Bor\r{u}vka's minimum spanning tree algorithm proves partial correctness of this algorithm. +This work is based on the same algebraic framework as the proof of Kruskal's algorithm; in particular it uses many theories from the hierarchy underlying \cite{Guttmann2018a}. + +The theory for Bor\r{u}vka's algorithm formally verifies results from the second author's Master's thesis \cite{RobinsonOBrien2020}. +Certain lemmas in this theory are numbered for easy correlation to theorems from the thesis. + +\begin{flushleft} +\input{session} +\end{flushleft} + +\bibliographystyle{abbrv} +\bibliography{root} + +\end{document} + diff --git a/web/entries/Aggregation_Algebras.html b/web/entries/Aggregation_Algebras.html --- a/web/entries/Aggregation_Algebras.html +++ b/web/entries/Aggregation_Algebras.html @@ -1,199 +1,199 @@ Aggregation Algebras - Archive of Formal Proofs

 

 

 

 

 

 

Aggregation Algebras

 

- +
Title: Aggregation Algebras
Author: Walter Guttmann
Submission date: 2018-09-15
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.
BibTeX:
@article{Aggregation_Algebras-AFP,
   author  = {Walter Guttmann},
   title   = {Aggregation Algebras},
   journal = {Archive of Formal Proofs},
   month   = sep,
   year    = 2018,
   note    = {\url{http://isa-afp.org/entries/Aggregation_Algebras.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: Stone_Kleene_Relation_Algebras
Used by:Relational_Disjoint_Set_Forests
Relational_Disjoint_Set_Forests, Relational_Minimum_Spanning_Trees

\ No newline at end of file diff --git a/web/entries/Finite-Map-Extras.html b/web/entries/Finite-Map-Extras.html new file mode 100644 --- /dev/null +++ b/web/entries/Finite-Map-Extras.html @@ -0,0 +1,184 @@ + + + + +Finite Map Extras - Archive of Formal Proofs + + + + + + + + + + + + + + + + + + + + + + + + +
+

 

+ + + +

 

+

 

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

 

+

 

+
+
+

 

+

Finite + + Map + + Extras + +

+

 

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Title:Finite Map Extras
+ Author: + + Javier Díaz (javier /dot/ diaz /dot/ manzi /at/ gmail /dot/ com) +
Submission date:2020-10-12
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.
BibTeX: +
@article{Finite-Map-Extras-AFP,
+  author  = {Javier Díaz},
+  title   = {Finite Map Extras},
+  journal = {Archive of Formal Proofs},
+  month   = oct,
+  year    = 2020,
+  note    = {\url{http://isa-afp.org/entries/Finite-Map-Extras.html},
+            Formal proof development},
+  ISSN    = {2150-914x},
+}
+
License:BSD License
+ +

+ + + + + + + + + + + + + + + + + + +
+
+ + + + + + \ No newline at end of file diff --git a/web/entries/Isabelle_Marries_Dirac.html b/web/entries/Isabelle_Marries_Dirac.html new file mode 100644 --- /dev/null +++ b/web/entries/Isabelle_Marries_Dirac.html @@ -0,0 +1,210 @@ + + + + +Isabelle Marries Dirac: a Library for Quantum Computation and Quantum Information - Archive of Formal Proofs + + + + + + + + + + + + + + + + + + + + + + + + +
+

 

+ + + +

 

+

 

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

 

+

 

+
+
+

 

+

Isabelle + + Marries + + Dirac: + + a + + Library + + for + + Quantum + + Computation + + and + + Quantum + + Information + +

+

 

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Title:Isabelle Marries Dirac: a Library for Quantum Computation and Quantum Information
+ Authors: + + Anthony Bordg (apdb3 /at/ cam /dot/ ac /dot/ uk), + Hanna Lachnitt (lachnitt /at/ stanford /dot/ edu) and + Yijun He (yh403 /at/ cam /dot/ ac /dot/ uk) +
Submission date:2020-11-22
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.
BibTeX: +
@article{Isabelle_Marries_Dirac-AFP,
+  author  = {Anthony Bordg and Hanna Lachnitt and Yijun He},
+  title   = {Isabelle Marries Dirac: a Library for Quantum Computation and Quantum Information},
+  journal = {Archive of Formal Proofs},
+  month   = nov,
+  year    = 2020,
+  note    = {\url{http://isa-afp.org/entries/Isabelle_Marries_Dirac.html},
+            Formal proof development},
+  ISSN    = {2150-914x},
+}
+
License:BSD License
Depends on:Jordan_Normal_Form, Matrix_Tensor, VectorSpace
+ +

+ + + + + + + + + + + + + + + + + + +
+
+ + + + + + \ No newline at end of file diff --git a/web/entries/Jordan_Normal_Form.html b/web/entries/Jordan_Normal_Form.html --- a/web/entries/Jordan_Normal_Form.html +++ b/web/entries/Jordan_Normal_Form.html @@ -1,249 +1,249 @@ Matrices, Jordan Normal Forms, and Spectral Radius Theory - Archive of Formal Proofs

 

 

 

 

 

 

Matrices, Jordan Normal Forms, and Spectral Radius Theory

 

- +
Title: Matrices, Jordan Normal Forms, and Spectral Radius Theory
Authors: René Thiemann and Akihisa Yamada
Contributor: Alexander Bentkamp (bentkamp /at/ gmail /dot/ com)
Submission 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.

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
BibTeX:
@article{Jordan_Normal_Form-AFP,
   author  = {René Thiemann and Akihisa Yamada},
   title   = {Matrices, Jordan Normal Forms, and Spectral Radius Theory},
   journal = {Archive of Formal Proofs},
   month   = aug,
   year    = 2015,
   note    = {\url{http://isa-afp.org/entries/Jordan_Normal_Form.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: Polynomial_Factorization
Used by:Deep_Learning, Farkas, Groebner_Bases, Linear_Programming, Perron_Frobenius, QHLProver, Stochastic_Matrices, Subresultants
Deep_Learning, Farkas, Groebner_Bases, Isabelle_Marries_Dirac, Linear_Programming, Perron_Frobenius, QHLProver, Stochastic_Matrices, Subresultants

\ No newline at end of file diff --git a/web/entries/Localization_Ring.html b/web/entries/Localization_Ring.html --- a/web/entries/Localization_Ring.html +++ b/web/entries/Localization_Ring.html @@ -1,208 +1,208 @@ The Localization of a Commutative Ring - Archive of Formal Proofs

 

 

 

 

 

 

The Localization of a Commutative Ring

 

Title: The Localization of a Commutative Ring
Author: - Anthony Bordg + Anthony Bordg (apdb3 /at/ cam /dot/ ac /dot/ uk)
Submission date: 2018-06-14
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.
BibTeX:
@article{Localization_Ring-AFP,
   author  = {Anthony Bordg},
   title   = {The Localization of a Commutative Ring},
   journal = {Archive of Formal Proofs},
   month   = jun,
   year    = 2018,
   note    = {\url{http://isa-afp.org/entries/Localization_Ring.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License

\ No newline at end of file diff --git a/web/entries/Matrix_Tensor.html b/web/entries/Matrix_Tensor.html --- a/web/entries/Matrix_Tensor.html +++ b/web/entries/Matrix_Tensor.html @@ -1,227 +1,227 @@ Tensor Product of Matrices - Archive of Formal Proofs

 

 

 

 

 

 

Tensor Product of Matrices

 

- +
Title: Tensor Product of Matrices
Author: T.V.H. Prathamesh (prathamesh /at/ imsc /dot/ res /dot/ in)
Submission date: 2016-01-18
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.
BibTeX:
@article{Matrix_Tensor-AFP,
   author  = {T.V.H. Prathamesh},
   title   = {Tensor Product of Matrices},
   journal = {Archive of Formal Proofs},
   month   = jan,
   year    = 2016,
   note    = {\url{http://isa-afp.org/entries/Matrix_Tensor.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: Matrix
Used by:Knot_Theory
Isabelle_Marries_Dirac, Knot_Theory

\ No newline at end of file diff --git a/web/entries/Projective_Geometry.html b/web/entries/Projective_Geometry.html --- a/web/entries/Projective_Geometry.html +++ b/web/entries/Projective_Geometry.html @@ -1,203 +1,203 @@ Projective Geometry - Archive of Formal Proofs

 

 

 

 

 

 

Projective Geometry

 

Title: Projective Geometry
Author: - Anthony Bordg + Anthony Bordg (apdb3 /at/ cam /dot/ ac /dot/ uk)
Submission date: 2018-06-14
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.
BibTeX:
@article{Projective_Geometry-AFP,
   author  = {Anthony Bordg},
   title   = {Projective Geometry},
   journal = {Archive of Formal Proofs},
   month   = jun,
   year    = 2018,
   note    = {\url{http://isa-afp.org/entries/Projective_Geometry.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License

\ No newline at end of file diff --git a/web/entries/Relational_Disjoint_Set_Forests.html b/web/entries/Relational_Disjoint_Set_Forests.html --- a/web/entries/Relational_Disjoint_Set_Forests.html +++ b/web/entries/Relational_Disjoint_Set_Forests.html @@ -1,189 +1,191 @@ Relational Disjoint-Set Forests - Archive of Formal Proofs

 

 

 

 

 

 

Relational Disjoint-Set Forests

 

- + + +
Title: Relational Disjoint-Set Forests
Author: Walter Guttmann
Submission date: 2020-08-26
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.
BibTeX:
@article{Relational_Disjoint_Set_Forests-AFP,
   author  = {Walter Guttmann},
   title   = {Relational Disjoint-Set Forests},
   journal = {Archive of Formal Proofs},
   month   = aug,
   year    = 2020,
   note    = {\url{http://isa-afp.org/entries/Relational_Disjoint_Set_Forests.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Depends on: Aggregation_Algebras, Stone_Kleene_Relation_Algebras
Used by:Relational_Minimum_Spanning_Trees

\ No newline at end of file diff --git a/web/entries/Relational_Method.html b/web/entries/Relational_Method.html new file mode 100644 --- /dev/null +++ b/web/entries/Relational_Method.html @@ -0,0 +1,211 @@ + + + + +The Relational Method with Message Anonymity for the Verification of Cryptographic Protocols - Archive of Formal Proofs + + + + + + + + + + + + + + + + + + + + + + + + +
+

 

+ + + +

 

+

 

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

 

+

 

+
+
+

 

+

The + + Relational + + Method + + with + + Message + + Anonymity + + for + + the + + Verification + + of + + Cryptographic + + Protocols + +

+

 

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Title:The Relational Method with Message Anonymity for the Verification of Cryptographic Protocols
+ Author: + + Pasquale Noce (pasquale /dot/ noce /dot/ lavoro /at/ gmail /dot/ com) +
Submission date:2020-12-05
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.
BibTeX: +
@article{Relational_Method-AFP,
+  author  = {Pasquale Noce},
+  title   = {The Relational Method with Message Anonymity for the Verification of Cryptographic Protocols},
+  journal = {Archive of Formal Proofs},
+  month   = dec,
+  year    = 2020,
+  note    = {\url{http://isa-afp.org/entries/Relational_Method.html},
+            Formal proof development},
+  ISSN    = {2150-914x},
+}
+
License:BSD License
+ +

+ + + + + + + + + + + + + + + + + + +
+
+ + + + + + \ No newline at end of file diff --git a/web/entries/Relational_Minimum_Spanning_Trees.html b/web/entries/Relational_Minimum_Spanning_Trees.html new file mode 100644 --- /dev/null +++ b/web/entries/Relational_Minimum_Spanning_Trees.html @@ -0,0 +1,191 @@ + + + + +Relational Minimum Spanning Tree Algorithms - Archive of Formal Proofs + + + + + + + + + + + + + + + + + + + + + + + + +
+

 

+ + + +

 

+

 

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

 

+

 

+
+
+

 

+

Relational + + Minimum + + Spanning + + Tree + + Algorithms + +

+

 

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Title:Relational Minimum Spanning Tree Algorithms
+ Authors: + + Walter Guttmann and + Nicolas Robinson-O'Brien +
Submission date:2020-12-08
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.
BibTeX: +
@article{Relational_Minimum_Spanning_Trees-AFP,
+  author  = {Walter Guttmann and Nicolas Robinson-O'Brien},
+  title   = {Relational Minimum Spanning Tree Algorithms},
+  journal = {Archive of Formal Proofs},
+  month   = dec,
+  year    = 2020,
+  note    = {\url{http://isa-afp.org/entries/Relational_Minimum_Spanning_Trees.html},
+            Formal proof development},
+  ISSN    = {2150-914x},
+}
+
License:BSD License
Depends on:Aggregation_Algebras, Relational_Disjoint_Set_Forests
+ +

+ + + + + + + + + + + + + + + + + + +
+
+ + + + + + \ No newline at end of file diff --git a/web/entries/VectorSpace.html b/web/entries/VectorSpace.html --- a/web/entries/VectorSpace.html +++ b/web/entries/VectorSpace.html @@ -1,227 +1,227 @@ Vector Spaces - Archive of Formal Proofs

 

 

 

 

 

 

Vector Spaces

 

- +
Title: Vector Spaces
Author: Holden Lee (holdenl /at/ princeton /dot/ edu)
Submission date: 2014-08-29
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).
BibTeX:
@article{VectorSpace-AFP,
   author  = {Holden Lee},
   title   = {Vector Spaces},
   journal = {Archive of Formal Proofs},
   month   = aug,
   year    = 2014,
   note    = {\url{http://isa-afp.org/entries/VectorSpace.html},
             Formal proof development},
   ISSN    = {2150-914x},
 }
License: BSD License
Used by:Deep_Learning
Deep_Learning, Isabelle_Marries_Dirac

\ 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,5230 +1,5265 @@ 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.

 

 

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

 

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

 

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

 

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

 

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

 

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

 

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

 

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

 

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

 

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

 

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

 

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

 

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

 

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

 

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

 

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

 

2004
2004-12-09: File Refinement
Authors: Karen Zee and Viktor Kuncak
2004-11-19: Integration theory and random variables
Author: Stefan Richter
2004-09-28: A Mechanically Verified, Efficient, Sound and Complete Theorem Prover For First Order Logic
Author: Tom Ridge
2004-09-20: Ramsey's theorem, infinitary version
Author: Tom Ridge
2004-09-20: Completeness theorem
Authors: James Margetson and Tom Ridge
2004-07-09: Compiling Exceptions Correctly
Author: Tobias Nipkow
2004-06-24: Depth First Search
Authors: Toshiaki Nishihara and Yasuhiko Minamide
2004-05-18: Groups, Rings and Modules
Authors: Hidetsune Kobayashi, L. Chen and H. Murao
2004-04-26: Topology
Author: Stefan Friedrich
2004-04-26: Lazy Lists II
Author: Stefan Friedrich
2004-04-05: Binary Search Trees
Author: Viktor Kuncak
2004-03-30: Functional Automata
Author: Tobias Nipkow
2004-03-19: Mini ML
Authors: Wolfgang Naraschewski and Tobias Nipkow
2004-03-19: AVL Trees
Authors: Tobias Nipkow and Cornelia Pusch
\ No newline at end of file diff --git a/web/rss.xml b/web/rss.xml --- a/web/rss.xml +++ b/web/rss.xml @@ -1,618 +1,614 @@ Archive of Formal Proofs https://www.isa-afp.org The Archive of Formal Proofs is a collection of proof libraries, examples, and larger scientific developments, mechanically checked in the theorem prover Isabelle. - 07 Dec 2020 00:00:00 +0000 + 08 Dec 2020 00:00:00 +0000 + + Relational Minimum Spanning Tree Algorithms + https://www.isa-afp.org/entries/Relational_Minimum_Spanning_Trees.html + https://www.isa-afp.org/entries/Relational_Minimum_Spanning_Trees.html + Walter Guttmann, Nicolas Robinson-O'Brien + 08 Dec 2020 00:00:00 +0000 + +We verify the correctness of Prim's, Kruskal's and +Borůvka's minimum spanning tree algorithms based on algebras for +aggregation and minimisation. + Inline Caching and Unboxing Optimization for Interpreters https://www.isa-afp.org/entries/Interpreter_Optimizations.html https://www.isa-afp.org/entries/Interpreter_Optimizations.html Martin Desharnais 07 Dec 2020 00:00:00 +0000 This Isabelle/HOL formalization builds on the <em>VeriComp</em> entry of the <em>Archive of Formal Proofs</em> to provide the following contributions: <ul> <li>an operational semantics for a realistic virtual machine (Std) for dynamically typed programming languages;</li> <li>the formalization of an inline caching optimization (Inca), a proof of bisimulation with (Std), and a compilation function;</li> <li>the formalization of an unboxing optimization (Ubx), a proof of bisimulation with (Inca), and a simple compilation function.</li> </ul> This formalization was described in the CPP 2021 paper <em>Towards Efficient and Verified Virtual Machines for Dynamic Languages</em> + The Relational Method with Message Anonymity for the Verification of Cryptographic Protocols + https://www.isa-afp.org/entries/Relational_Method.html + https://www.isa-afp.org/entries/Relational_Method.html + Pasquale Noce + 05 Dec 2020 00:00:00 +0000 + +This paper introduces a new method for the formal verification of +cryptographic protocols, the relational method, derived from +Paulson's inductive method by means of some enhancements aimed at +streamlining formal definitions and proofs, specially for protocols +using public key cryptography. Moreover, this paper proposes a method +to formalize a further security property, message anonymity, in +addition to message confidentiality and authenticity. The relational +method, including message anonymity, is then applied to the +verification of a sample authentication protocol, comprising Password +Authenticated Connection Establishment (PACE) with Chip Authentication +Mapping followed by the explicit verification of an additional +password over the PACE secure channel. + + + Isabelle Marries Dirac: a Library for Quantum Computation and Quantum Information + https://www.isa-afp.org/entries/Isabelle_Marries_Dirac.html + https://www.isa-afp.org/entries/Isabelle_Marries_Dirac.html + Anthony Bordg, Hanna Lachnitt, Yijun He + 22 Nov 2020 00:00:00 +0000 + +This work is an effort to formalise some quantum algorithms and +results in quantum information theory. Formal methods being critical +for the safety and security of algorithms and protocols, we foresee +their widespread use for quantum computing in the future. We have +developed a large library for quantum computing in Isabelle based on a +matrix representation for quantum circuits, successfully formalising +the no-cloning theorem, quantum teleportation, Deutsch's +algorithm, the Deutsch-Jozsa algorithm and the quantum Prisoner's +Dilemma. + + Verified SAT-Based AI Planning https://www.isa-afp.org/entries/Verified_SAT_Based_AI_Planning.html https://www.isa-afp.org/entries/Verified_SAT_Based_AI_Planning.html Mohammad Abdulaziz, Friedrich Kurz 29 Oct 2020 00:00:00 +0000 We present an executable formally verified SAT encoding of classical AI planning that is based on the encodings by Kautz and Selman and the one by Rintanen et al. The encoding was experimentally tested and shown to be usable for reasonably sized standard AI planning benchmarks. We also use it as a reference to test a state-of-the-art SAT-based planner, showing that it sometimes falsely claims that problems have no solutions of certain lengths. The formalisation in this submission was described in an independent publication. AI Planning Languages Semantics https://www.isa-afp.org/entries/AI_Planning_Languages_Semantics.html https://www.isa-afp.org/entries/AI_Planning_Languages_Semantics.html Mohammad Abdulaziz, Peter Lammich 29 Oct 2020 00:00:00 +0000 This is an Isabelle/HOL formalisation of the semantics of the multi-valued planning tasks language that is used by the planning system Fast-Downward, the STRIPS fragment of the Planning Domain Definition Language (PDDL), and the STRIPS soundness meta-theory developed by Vladimir Lifschitz. It also contains formally verified checkers for checking the well-formedness of problems specified in either language as well the correctness of potential solutions. The formalisation in this entry was described in an earlier publication. A Sound Type System for Physical Quantities, Units, and Measurements https://www.isa-afp.org/entries/Physical_Quantities.html https://www.isa-afp.org/entries/Physical_Quantities.html Simon Foster, Burkhart Wolff 20 Oct 2020 00:00:00 +0000 The present Isabelle theory builds a formal model for both the International System of Quantities (ISQ) and the International System of Units (SI), which are both fundamental for physics and engineering. Both the ISQ and the SI are deeply integrated into Isabelle's type system. Quantities are parameterised by dimension types, which correspond to base vectors, and thus only quantities of the same dimension can be equated. Since the underlying "algebra of quantities" induces congruences on quantity and SI types, specific tactic support is developed to capture these. Our construction is validated by a test-set of known equivalences between both quantities and SI units. Moreover, the presented theory can be used for type-safe conversions between the SI system and others, like the British Imperial System (BIS). + Finite Map Extras + https://www.isa-afp.org/entries/Finite-Map-Extras.html + https://www.isa-afp.org/entries/Finite-Map-Extras.html + Javier Díaz + 12 Oct 2020 00:00:00 +0000 + +This entry includes useful syntactic sugar, new operators and functions, and +their associated lemmas for finite maps which currently are not +present in the standard Finite_Map theory. + + A Formal Model of the Safely Composable Document Object Model with Shadow Roots https://www.isa-afp.org/entries/Shadow_SC_DOM.html https://www.isa-afp.org/entries/Shadow_SC_DOM.html Achim D. Brucker, Michael Herzberg 28 Sep 2020 00:00:00 +0000 In this AFP entry, we extend our formalization of the safely composable DOM with Shadow Roots. This is a proposal for Shadow Roots with stricter safety guarantess than the standard compliant formalization (see "Shadow DOM"). Shadow Roots are a recent proposal of the web community to support a component-based development approach for client-side web applications. Shadow roots are a significant extension to the DOM standard and, as web standards are condemned to be backward compatible, such extensions often result in complex specification that may contain unwanted subtleties that can be detected by a formalization. Our Isabelle/HOL formalization is, in the sense of object-orientation, an extension of our formalization of the core DOM and enjoys the same basic properties, i.e., it is extensible, i.e., can be extended without the need of re-proving already proven properties and executable, i.e., we can generate executable code from our specification. We exploit the executability to show that our formalization complies to the official standard of the W3C, respectively, the WHATWG. A Formal Model of the Document Object Model with Shadow Roots https://www.isa-afp.org/entries/Shadow_DOM.html https://www.isa-afp.org/entries/Shadow_DOM.html Achim D. Brucker, Michael Herzberg 28 Sep 2020 00:00:00 +0000 In this AFP entry, we extend our formalization of the core DOM with Shadow Roots. Shadow roots are a recent proposal of the web community to support a component-based development approach for client-side web applications. Shadow roots are a significant extension to the DOM standard and, as web standards are condemned to be backward compatible, such extensions often result in complex specification that may contain unwanted subtleties that can be detected by a formalization. Our Isabelle/HOL formalization is, in the sense of object-orientation, an extension of our formalization of the core DOM and enjoys the same basic properties, i.e., it is extensible, i.e., can be extended without the need of re-proving already proven properties and executable, i.e., we can generate executable code from our specification. We exploit the executability to show that our formalization complies to the official standard of the W3C, respectively, the WHATWG. A Formalization of Safely Composable Web Components https://www.isa-afp.org/entries/SC_DOM_Components.html https://www.isa-afp.org/entries/SC_DOM_Components.html Achim D. Brucker, Michael Herzberg 28 Sep 2020 00:00:00 +0000 While the (safely composable) DOM with shadow trees provide the technical basis for defining web components, it does neither defines the concept of web components nor specifies the safety properties that web components should guarantee. Consequently, the standard also does not discuss how or even if the methods for modifying the DOM respect component boundaries. In AFP entry, we present a formally verified model of safely composable web components and define safety properties which ensure that different web components can only interact with each other using well-defined interfaces. Moreover, our verification of the application programming interface (API) of the DOM revealed numerous invariants that implementations of the DOM API need to preserve to ensure the integrity of components. In comparison to the strict standard compliance formalization of Web Components in the AFP entry "DOM_Components", the notion of components in this entry (based on "SC_DOM" and "Shadow_SC_DOM") provides much stronger safety guarantees. A Formalization of Web Components https://www.isa-afp.org/entries/DOM_Components.html https://www.isa-afp.org/entries/DOM_Components.html Achim D. Brucker, Michael Herzberg 28 Sep 2020 00:00:00 +0000 While the DOM with shadow trees provide the technical basis for defining web components, the DOM standard neither defines the concept of web components nor specifies the safety properties that web components should guarantee. Consequently, the standard also does not discuss how or even if the methods for modifying the DOM respect component boundaries. In AFP entry, we present a formally verified model of web components and define safety properties which ensure that different web components can only interact with each other using well-defined interfaces. Moreover, our verification of the application programming interface (API) of the DOM revealed numerous invariants that implementations of the DOM API need to preserve to ensure the integrity of components. The Safely Composable DOM https://www.isa-afp.org/entries/Core_SC_DOM.html https://www.isa-afp.org/entries/Core_SC_DOM.html Achim D. Brucker, Michael Herzberg 28 Sep 2020 00:00:00 +0000 In this AFP entry, we formalize the core of the Safely Composable Document Object Model (SC DOM). The SC DOM improve the standard DOM (as formalized in the AFP entry "Core DOM") by strengthening the tree boundaries set by shadow roots: in the SC DOM, the shadow root is a sub-class of the document class (instead of a base class). This modifications also results in changes to some API methods (e.g., getOwnerDocument) to return the nearest shadow root rather than the document root. As a result, many API methods that, when called on a node inside a shadow tree, would previously ``break out'' and return or modify nodes that are possibly outside the shadow tree, now stay within its boundaries. This change in behavior makes programs that operate on shadow trees more predictable for the developer and allows them to make more assumptions about other code accessing the DOM. Syntax-Independent Logic Infrastructure https://www.isa-afp.org/entries/Syntax_Independent_Logic.html https://www.isa-afp.org/entries/Syntax_Independent_Logic.html Andrei Popescu, Dmitriy Traytel 16 Sep 2020 00:00:00 +0000 We formalize a notion of logic whose terms and formulas are kept abstract. In particular, logical connectives, substitution, free variables, and provability are not defined, but characterized by their general properties as locale assumptions. Based on this abstract characterization, we develop further reusable reasoning infrastructure. For example, we define parallel substitution (along with proving its characterizing theorems) from single-point substitution. Similarly, we develop a natural deduction style proof system starting from the abstract Hilbert-style one. These one-time efforts benefit different concrete logics satisfying our locales' assumptions. We instantiate the syntax-independent logic infrastructure to Robinson arithmetic (also known as Q) in the AFP entry <a href="https://www.isa-afp.org/entries/Robinson_Arithmetic.html">Robinson_Arithmetic</a> and to hereditarily finite set theory in the AFP entries <a href="https://www.isa-afp.org/entries/Goedel_HFSet_Semantic.html">Goedel_HFSet_Semantic</a> and <a href="https://www.isa-afp.org/entries/Goedel_HFSet_Semanticless.html">Goedel_HFSet_Semanticless</a>, which are part of our formalization of G&ouml;del's Incompleteness Theorems described in our CADE-27 paper <a href="https://dx.doi.org/10.1007/978-3-030-29436-6_26">A Formally Verified Abstract Account of Gödel's Incompleteness Theorems</a>. Robinson Arithmetic https://www.isa-afp.org/entries/Robinson_Arithmetic.html https://www.isa-afp.org/entries/Robinson_Arithmetic.html Andrei Popescu, Dmitriy Traytel 16 Sep 2020 00:00:00 +0000 We instantiate our syntax-independent logic infrastructure developed in <a href="https://www.isa-afp.org/entries/Syntax_Independent_Logic.html">a separate AFP entry</a> to the FOL theory of Robinson arithmetic (also known as Q). The latter was formalised using Nominal Isabelle by adapting <a href="https://www.isa-afp.org/entries/Incompleteness.html">Larry Paulson’s formalization of the Hereditarily Finite Set theory</a>. An Abstract Formalization of Gödel's Incompleteness Theorems https://www.isa-afp.org/entries/Goedel_Incompleteness.html https://www.isa-afp.org/entries/Goedel_Incompleteness.html Andrei Popescu, Dmitriy Traytel 16 Sep 2020 00:00:00 +0000 We present an abstract formalization of G&ouml;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&ndash;Paulson semantics-based approach. This AFP entry is the main entry point to the results described in our CADE-27 paper <a href="https://dx.doi.org/10.1007/978-3-030-29436-6_26">A Formally Verified Abstract Account of Gödel's Incompleteness Theorems</a>. As part of our abstract formalization's validation, we instantiate our locales twice in the separate AFP entries <a href="https://www.isa-afp.org/entries/Goedel_HFSet_Semantic.html">Goedel_HFSet_Semantic</a> and <a href="https://www.isa-afp.org/entries/Goedel_HFSet_Semanticless.html">Goedel_HFSet_Semanticless</a>. From Abstract to Concrete Gödel's Incompleteness Theorems—Part II https://www.isa-afp.org/entries/Goedel_HFSet_Semanticless.html https://www.isa-afp.org/entries/Goedel_HFSet_Semanticless.html Andrei Popescu, Dmitriy Traytel 16 Sep 2020 00:00:00 +0000 We validate an abstract formulation of G&ouml;del's Second Incompleteness Theorem from a <a href="https://www.isa-afp.org/entries/Goedel_Incompleteness.html">separate AFP entry</a> by instantiating it to the case of <i>finite consistent extensions of the Hereditarily Finite (HF) Set theory</i>, 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 <a href="https://www.isa-afp.org/entries/Incompleteness.html">direct formalisation of the concrete result</a>. It strengthens Paulson's formalization of G&ouml;del's Second from that entry by <i>not</i> 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&ouml;del's Second locale. From Abstract to Concrete Gödel's Incompleteness Theorems—Part I https://www.isa-afp.org/entries/Goedel_HFSet_Semantic.html https://www.isa-afp.org/entries/Goedel_HFSet_Semantic.html Andrei Popescu, Dmitriy Traytel 16 Sep 2020 00:00:00 +0000 We validate an abstract formulation of G&ouml;del's First and Second Incompleteness Theorems from a <a href="https://www.isa-afp.org/entries/Goedel_Incompleteness.html">separate AFP entry</a> by instantiating them to the case of <i>finite sound extensions of the Hereditarily Finite (HF) Set theory</i>, 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 <a href="https://www.isa-afp.org/entries/Incompleteness.html">AFP entry by Larry Paulson</a>; our instantiation reuses the infrastructure developed in that entry. A Formal Model of Extended Finite State Machines https://www.isa-afp.org/entries/Extended_Finite_State_Machines.html https://www.isa-afp.org/entries/Extended_Finite_State_Machines.html Michael Foster, Achim D. Brucker, Ramsay G. Taylor, John Derrick 07 Sep 2020 00:00:00 +0000 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. Inference of Extended Finite State Machines https://www.isa-afp.org/entries/Extended_Finite_State_Machine_Inference.html https://www.isa-afp.org/entries/Extended_Finite_State_Machine_Inference.html Michael Foster, Achim D. Brucker, Ramsay G. Taylor, John Derrick 07 Sep 2020 00:00:00 +0000 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. Practical Algebraic Calculus Checker https://www.isa-afp.org/entries/PAC_Checker.html https://www.isa-afp.org/entries/PAC_Checker.html Mathias Fleury, Daniela Kaufmann 31 Aug 2020 00:00:00 +0000 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. Some classical results in inductive inference of recursive functions https://www.isa-afp.org/entries/Inductive_Inference.html https://www.isa-afp.org/entries/Inductive_Inference.html Frank J. Balbach 31 Aug 2020 00:00:00 +0000 <p> 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. </p> <p> 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. </p> <p> The above is based on a formalization of recursive functions heavily inspired by the <a href="https://www.isa-afp.org/entries/Universal_Turing_Machine.html">Universal Turing Machine</a> entry by Xu et al., but different in that it models partial functions with codomain <em>nat option</em>. 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 <em>s-m-n</em> theorem, Rice's theorem, and assorted fixed-point theorems (recursion theorems) by Kleene, Rogers, and Smullyan. </p> Relational Disjoint-Set Forests https://www.isa-afp.org/entries/Relational_Disjoint_Set_Forests.html https://www.isa-afp.org/entries/Relational_Disjoint_Set_Forests.html Walter Guttmann 26 Aug 2020 00:00:00 +0000 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. Extensions to the Comprehensive Framework for Saturation Theorem Proving https://www.isa-afp.org/entries/Saturation_Framework_Extensions.html https://www.isa-afp.org/entries/Saturation_Framework_Extensions.html Jasmin Blanchette, Sophie Tourret 25 Aug 2020 00:00:00 +0000 This Isabelle/HOL formalization extends the AFP entry <em>Saturation_Framework</em> with the following contributions: <ul> <li>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 <em>Ordered_Resultion_Prover</em>;</li> <li>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;</li> <li>alternative proofs of fairness (and hence saturation and ultimately refutational completeness) for the given clause procedures GC and LGC, based on invariance.</li> </ul> Putting the `K' into Bird's derivation of Knuth-Morris-Pratt string matching https://www.isa-afp.org/entries/BirdKMP.html https://www.isa-afp.org/entries/BirdKMP.html Peter Gammie 25 Aug 2020 00:00:00 +0000 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. Amicable Numbers https://www.isa-afp.org/entries/Amicable_Numbers.html https://www.isa-afp.org/entries/Amicable_Numbers.html Angeliki Koutsoukou-Argyraki 04 Aug 2020 00:00:00 +0000 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&#257;bit ibn Qurra's Rule, Euler's Rule, te Riele's Rule and Borho's Rule with breeders. Ordinal Partitions https://www.isa-afp.org/entries/Ordinal_Partitions.html https://www.isa-afp.org/entries/Ordinal_Partitions.html Lawrence C. Paulson 03 Aug 2020 00:00:00 +0000 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$. A Formal Proof of The Chandy--Lamport Distributed Snapshot Algorithm https://www.isa-afp.org/entries/Chandy_Lamport.html https://www.isa-afp.org/entries/Chandy_Lamport.html Ben Fiedler, Dmitriy Traytel 21 Jul 2020 00:00:00 +0000 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. Relational Characterisations of Paths https://www.isa-afp.org/entries/Relational_Paths.html https://www.isa-afp.org/entries/Relational_Paths.html Walter Guttmann, Peter Höfner 13 Jul 2020 00:00:00 +0000 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. A Formally Verified Checker of the Safe Distance Traffic Rules for Autonomous Vehicles https://www.isa-afp.org/entries/Safe_Distance.html https://www.isa-afp.org/entries/Safe_Distance.html Albert Rizaldi, Fabian Immler 01 Jun 2020 00:00:00 +0000 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. - - A verified algorithm for computing the Smith normal form of a matrix - https://www.isa-afp.org/entries/Smith_Normal_Form.html - https://www.isa-afp.org/entries/Smith_Normal_Form.html - Jose Divasón - 23 May 2020 00:00:00 +0000 - -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. - - - The Nash-Williams Partition Theorem - https://www.isa-afp.org/entries/Nash_Williams.html - https://www.isa-afp.org/entries/Nash_Williams.html - Lawrence C. Paulson - 16 May 2020 00:00:00 +0000 - -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ć. - - - A Formalization of Knuth–Bendix Orders - https://www.isa-afp.org/entries/Knuth_Bendix_Order.html - https://www.isa-afp.org/entries/Knuth_Bendix_Order.html - Christian Sternagel, René Thiemann - 13 May 2020 00:00:00 +0000 - -We define a generalized version of Knuth&ndash;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. - - - Irrationality Criteria for Series by Erdős and Straus - https://www.isa-afp.org/entries/Irrational_Series_Erdos_Straus.html - https://www.isa-afp.org/entries/Irrational_Series_Erdos_Straus.html - Angeliki Koutsoukou-Argyraki, Wenda Li - 12 May 2020 00:00:00 +0000 - -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 -<a href="https://projecteuclid.org/euclid.pjm/1102911140">[1]</a>. -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. - 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:570
Number of Authors:366
Number of lemmas:~158,800
Lines of Code:~2,796,200
Number of Articles:574
Number of Authors:370
Number of lemmas:~158,600
Lines of Code:~2,785,500

Most used AFP articles:

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

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

 

 

 

 

 

 

Index by Topic

 

Computer science

Artificial intelligence

Automata and formal languages

Algorithms

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

Concurrency

Data structures

Functional programming

Hardware

SPARCv8  

Machine learning

Networks

Programming languages

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

Security

Semantics

System description languages

Logic

Philosophical aspects

General logic

Computability

Set theory

Proof theory

Rewriting

Mathematics

Order

Algebra

Analysis

Probability theory

Number theory

Games and economics

Geometry

Topology

Graph theory

Combinatorics

Category theory

Physics

+ Quantum information: + Isabelle_Marries_Dirac   +

Misc

Tools

\ No newline at end of file