Built with Alectryon, running Coq+SerAPI v8.10.0+0.7.0. Coq sources are in this panel; goals and messages will appear in the other. Bubbles () indicate interactive fragments: hover for details, tap to reveal contents. Use Ctrl+↑ Ctrl+↓ to navigate, Ctrl+🖱️ to focus.
(************************************************************************) (* * The Coq Proof Assistant / The Coq Development Team *) (* v * INRIA, CNRS and contributors - Copyright 1999-2018 *) (* <O___,, * (see CREDITS file for the list of authors) *) (* \VV/ **************************************************************) (* // * This file is distributed under the terms of the *) (* * GNU Lesser General Public License Version 2.1 *) (* * (see LICENSE file for the text of the license) *) (************************************************************************) (* G. Huet 1-9-95 *) Require Import Permut Setoid. Require Plus. (* comm. and ass. of plus *) Set Implicit Arguments. Section multiset_defs. Variable A : Type. Variable eqA : A -> A -> Prop. Hypothesis eqA_equiv : Equivalence eqA. Hypothesis Aeq_dec : forall x y:A, {eqA x y} + {~ eqA x y}. Inductive multiset : Type := Bag : (A -> nat) -> multiset. Definition EmptyBag := Bag (fun a:A => 0). Definition SingletonBag (a:A) := Bag (fun a':A => match Aeq_dec a a' with | left _ => 1 | right _ => 0 end). Definition multiplicity (m:multiset) (a:A) : nat := let (f) := m in f a.
multiset equality
Definition meq (m1 m2:multiset) := forall a:A, multiplicity m1 a = multiplicity m2 a.A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x : multiset, meq x xdestruct x; unfold meq; reflexivity. Qed.A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x : multiset, meq x xA:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x y z : multiset, meq x y -> meq y z -> meq x zA:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x y z : multiset, meq x y -> meq y z -> meq x zA:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x y z : multiset, (forall a : A, multiplicity x a = multiplicity y a) -> (forall a : A, multiplicity y a = multiplicity z a) -> forall a : A, multiplicity x a = multiplicity z aintros; rewrite H; auto. Qed.A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}n, n0, n1:A -> nat(forall a : A, multiplicity (Bag n) a = multiplicity (Bag n0) a) -> (forall a : A, multiplicity (Bag n0) a = multiplicity (Bag n1) a) -> forall a : A, multiplicity (Bag n) a = multiplicity (Bag n1) aA:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x y : multiset, meq x y -> meq y xA:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x y : multiset, meq x y -> meq y xdestruct x; destruct y; auto. Qed.A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x y : multiset, (forall a : A, multiplicity x a = multiplicity y a) -> forall a : A, multiplicity y a = multiplicity x a
multiset union
Definition munion (m1 m2:multiset) := Bag (fun a:A => multiplicity m1 a + multiplicity m2 a).A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x : multiset, meq x (munion EmptyBag x)unfold meq; unfold munion; simpl; auto. Qed.A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x : multiset, meq x (munion EmptyBag x)A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x : multiset, meq x (munion x EmptyBag)unfold meq; unfold munion; simpl; auto. Qed.A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x : multiset, meq x (munion x EmptyBag)A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x y : multiset, meq (munion x y) (munion y x)A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x y : multiset, meq (munion x y) (munion y x)destruct x; destruct y; auto with arith. Qed.A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall (x y : multiset) (a : A), multiplicity x a + multiplicity y a = multiplicity y a + multiplicity x aA:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x y z : multiset, meq (munion (munion x y) z) (munion x (munion y z))A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x y z : multiset, meq (munion (munion x y) z) (munion x (munion y z))destruct x; destruct y; destruct z; auto with arith. Qed.A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall (x y z : multiset) (a : A), (let (f) := x in f a) + (let (f) := y in f a) + (let (f) := z in f a) = (let (f) := x in f a) + ((let (f) := y in f a) + (let (f) := z in f a))A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x y z : multiset, meq x y -> meq (munion x z) (munion y z)A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x y z : multiset, meq x y -> meq (munion x z) (munion y z)A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x y z : multiset, (forall a : A, (let (f) := x in f a) = (let (f) := y in f a)) -> forall a : A, (let (f) := x in f a) + (let (f) := z in f a) = (let (f) := y in f a) + (let (f) := z in f a)intros; elim H; auto with arith. Qed.A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}n, n0, n1:A -> nat(forall a : A, n a = n0 a) -> forall a : A, n a + n1 a = n0 a + n1 aA:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x y z : multiset, meq x y -> meq (munion z x) (munion z y)A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x y z : multiset, meq x y -> meq (munion z x) (munion z y)A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x y z : multiset, (forall a : A, (let (f) := x in f a) = (let (f) := y in f a)) -> forall a : A, (let (f) := z in f a) + (let (f) := x in f a) = (let (f) := z in f a) + (let (f) := y in f a)intros; elim H; auto. Qed.A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}n, n0, n1:A -> nat(forall a : A, n a = n0 a) -> forall a : A, n1 a + n a = n1 a + n0 a
Here we should make multiset an abstract datatype, by hiding Bag,
munion, multiplicity; all further properties are proved abstractly
A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x y z : multiset, meq (munion x (munion y z)) (munion z (munion x y))A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x y z : multiset, meq (munion x (munion y z)) (munion z (munion x y))A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x0 y0 : A, {eqA x0 y0} + {~ eqA x0 y0}x, y, z:multisetforall x0 y0 : multiset, meq (munion x0 y0) (munion y0 x0)A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x0 y0 : A, {eqA x0 y0} + {~ eqA x0 y0}x, y, z:multisetforall x0 y0 z0 : multiset, meq (munion (munion x0 y0) z0) (munion x0 (munion y0 z0))A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x0 y0 : A, {eqA x0 y0} + {~ eqA x0 y0}x, y, z:multisetforall x0 y0 z0 : multiset, meq x0 y0 -> meq y0 z0 -> meq x0 z0A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x0 y0 : A, {eqA x0 y0} + {~ eqA x0 y0}x, y, z:multisetforall x0 y0 : multiset, meq x0 y0 -> meq y0 x0A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x0 y0 : A, {eqA x0 y0} + {~ eqA x0 y0}x, y, z:multisetmultisetA:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x0 y0 : A, {eqA x0 y0} + {~ eqA x0 y0}x, y, z:multisetforall x0 y0 z0 : multiset, meq (munion (munion x0 y0) z0) (munion x0 (munion y0 z0))A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x0 y0 : A, {eqA x0 y0} + {~ eqA x0 y0}x, y, z:multisetforall x0 y0 z0 : multiset, meq x0 y0 -> meq y0 z0 -> meq x0 z0A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x0 y0 : A, {eqA x0 y0} + {~ eqA x0 y0}x, y, z:multisetforall x0 y0 : multiset, meq x0 y0 -> meq y0 x0A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x0 y0 : A, {eqA x0 y0} + {~ eqA x0 y0}x, y, z:multisetmultisetA:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x0 y0 : A, {eqA x0 y0} + {~ eqA x0 y0}x, y, z:multisetforall x0 y0 z0 : multiset, meq x0 y0 -> meq y0 z0 -> meq x0 z0A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x0 y0 : A, {eqA x0 y0} + {~ eqA x0 y0}x, y, z:multisetforall x0 y0 : multiset, meq x0 y0 -> meq y0 x0A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x0 y0 : A, {eqA x0 y0} + {~ eqA x0 y0}x, y, z:multisetmultisetA:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x0 y0 : A, {eqA x0 y0} + {~ eqA x0 y0}x, y, z:multisetforall x0 y0 : multiset, meq x0 y0 -> meq y0 x0A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x0 y0 : A, {eqA x0 y0} + {~ eqA x0 y0}x, y, z:multisetmultisettrivial. Qed.A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x0 y0 : A, {eqA x0 y0} + {~ eqA x0 y0}x, y, z:multisetmultisetA:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x y z t : multiset, meq x y -> meq z t -> meq (munion x z) (munion y t)A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x y z t : multiset, meq x y -> meq z t -> meq (munion x z) (munion y t)exact meq_trans. Qed.A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x0 y0 : A, {eqA x0 y0} + {~ eqA x0 y0}x, y, z, t:multisetH:meq x yH0:meq z tforall x0 y0 z0 : multiset, meq x0 y0 -> meq y0 z0 -> meq x0 z0A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x y z : multiset, meq (munion x (munion y z)) (munion y (munion x z))A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x y z : multiset, meq (munion x (munion y z)) (munion y (munion x z))exact meq_trans. Qed.A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x0 y0 : A, {eqA x0 y0} + {~ eqA x0 y0}x, y, z:multisetforall x0 y0 z0 : multiset, meq x0 y0 -> meq y0 z0 -> meq x0 z0A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x y z t : multiset, meq (munion x (munion (munion y z) t)) (munion (munion y (munion x t)) z)A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x y z t : multiset, meq (munion x (munion (munion y z) t)) (munion (munion y (munion x t)) z)exact meq_trans. Qed.A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x0 y0 : A, {eqA x0 y0} + {~ eqA x0 y0}x, y, z, t:multisetforall x0 y0 z0 : multiset, meq x0 y0 -> meq y0 z0 -> meq x0 z0A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x y z t : multiset, meq (munion x (munion (munion y z) t)) (munion (munion y (munion x z)) t)A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x y z t : multiset, meq (munion x (munion (munion y z) t)) (munion (munion y (munion x z)) t)A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x0 y0 : A, {eqA x0 y0} + {~ eqA x0 y0}x, y, z, t:multisetmeq (munion x (munion (munion y z) t)) (munion (munion x (munion y z)) t)A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x0 y0 : A, {eqA x0 y0} + {~ eqA x0 y0}x, y, z, t:multisetmeq (munion (munion x (munion y z)) t) (munion (munion y (munion x z)) t)apply meq_left; apply munion_perm_left. Qed.A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x0 y0 : A, {eqA x0 y0} + {~ eqA x0 y0}x, y, z, t:multisetmeq (munion (munion x (munion y z)) t) (munion (munion y (munion x z)) t)
specific for treesort
A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x y z t u : multiset, meq u (munion y z) -> meq (munion x (munion u t)) (munion (munion y (munion x t)) z)A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x y z t u : multiset, meq u (munion y z) -> meq (munion x (munion u t)) (munion (munion y (munion x t)) z)A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x0 y0 : A, {eqA x0 y0} + {~ eqA x0 y0}x, y, z, t, u:multisetH:meq u (munion y z)meq (munion x (munion u t)) (munion x (munion (munion y z) t))A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x0 y0 : A, {eqA x0 y0} + {~ eqA x0 y0}x, y, z, t, u:multisetH:meq u (munion y z)meq (munion x (munion (munion y z) t)) (munion (munion y (munion x t)) z)apply multiset_twist1. Qed.A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x0 y0 : A, {eqA x0 y0} + {~ eqA x0 y0}x, y, z, t, u:multisetH:meq u (munion y z)meq (munion x (munion (munion y z) t)) (munion (munion y (munion x t)) z)A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x y z t u : multiset, meq u (munion y z) -> meq (munion x (munion u t)) (munion (munion y (munion x z)) t)A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall x y z t u : multiset, meq u (munion y z) -> meq (munion x (munion u t)) (munion (munion y (munion x z)) t)A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x0 y0 : A, {eqA x0 y0} + {~ eqA x0 y0}x, y, z, t, u:multisetH:meq u (munion y z)meq (munion x (munion u t)) (munion x (munion (munion y z) t))A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x0 y0 : A, {eqA x0 y0} + {~ eqA x0 y0}x, y, z, t, u:multisetH:meq u (munion y z)meq (munion x (munion (munion y z) t)) (munion (munion y (munion x z)) t)apply multiset_twist2. Qed.A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x0 y0 : A, {eqA x0 y0} + {~ eqA x0 y0}x, y, z, t, u:multisetH:meq u (munion y z)meq (munion x (munion (munion y z) t)) (munion (munion y (munion x z)) t)
SingletonBag
A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall a a' : A, eqA a a' -> meq (SingletonBag a) (SingletonBag a')A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}forall a a' : A, eqA a a' -> meq (SingletonBag a) (SingletonBag a')destruct (Aeq_dec a a0) as [Ha|Ha]; rewrite H in Ha; decide (Aeq_dec a' a0) with Ha; reflexivity. Qed. (*i theory of minter to do similarly Require Min. (* multiset intersection *) Definition minter := [m1,m2:multiset] (Bag [a:A](min (multiplicity m1 a)(multiplicity m2 a))). i*) End multiset_defs. Unset Implicit Arguments. Hint Unfold meq multiplicity: datatypes. Hint Resolve munion_empty_right munion_comm munion_ass meq_left meq_right munion_empty_left: datatypes. Hint Immediate meq_sym: datatypes.A:TypeeqA:A -> A -> PropeqA_equiv:Equivalence eqAAeq_dec:forall x y : A, {eqA x y} + {~ eqA x y}a, a':AH:eqA a a'a0:A(if Aeq_dec a a0 then 1 else 0) = (if Aeq_dec a' a0 then 1 else 0)