(* Properties of [FSet A] where [A] has decidable equality *) Require Import HoTT HitTactics. From fsets Require Export properties extensionality operations_decidable. Require Export lattice. (* Lemmas relating operations to the membership predicate *) Section operations_isIn. Context {A : Type} `{DecidablePaths A} `{Univalence}. Lemma ext : forall (S T : FSet A), (forall a, isIn_b a S = isIn_b a T) -> S = T. Proof. intros X Y H2. apply fset_ext. intro a. specialize (H2 a). unfold isIn_b, dec in H2. destruct (isIn_decidable a X) ; destruct (isIn_decidable a Y). - apply path_iff_hprop ; intro ; assumption. - contradiction (true_ne_false). - contradiction (true_ne_false) ; apply H2^. - apply path_iff_hprop ; intro ; contradiction. Defined. Lemma empty_isIn (a : A) : isIn_b a ∅ = false. Proof. reflexivity. Defined. Lemma L_isIn (a b : A) : a ∈ {|b|} -> a = b. Proof. intros. strip_truncations. assumption. Defined. Lemma L_isIn_b_true (a b : A) (p : a = b) : isIn_b a {|b|} = true. Proof. unfold isIn_b, dec. destruct (isIn_decidable a {|b|}) as [n | n] . - reflexivity. - simpl in n. contradiction (n (tr p)). Defined. Lemma L_isIn_b_aa (a : A) : isIn_b a {|a|} = true. Proof. apply L_isIn_b_true ; reflexivity. Defined. Lemma L_isIn_b_false (a b : A) (p : a <> b) : isIn_b a {|b|} = false. Proof. unfold isIn_b, dec. destruct (isIn_decidable a {|b|}). - simpl in t. strip_truncations. contradiction. - reflexivity. Defined. (* Union and membership *) Lemma union_isIn_b (X Y : FSet A) (a : A) : isIn_b a (X ∪ Y) = orb (isIn_b a X) (isIn_b a Y). Proof. unfold isIn_b ; unfold dec. simpl. destruct (isIn_decidable a X) ; destruct (isIn_decidable a Y) ; reflexivity. Defined. Lemma comprehension_isIn_b (Y : FSet A) (ϕ : A -> Bool) (a : A) : isIn_b a {|Y & ϕ|} = andb (isIn_b a Y) (ϕ a). Proof. unfold isIn_b, dec ; simpl. destruct (isIn_decidable a {|Y & ϕ|}) as [t | t] ; destruct (isIn_decidable a Y) as [n | n] ; rewrite comprehension_isIn in t ; destruct (ϕ a) ; try reflexivity ; try contradiction. Defined. Lemma intersection_isIn_b (X Y: FSet A) (a : A) : isIn_b a (intersection X Y) = andb (isIn_b a X) (isIn_b a Y). Proof. apply comprehension_isIn_b. Defined. End operations_isIn. (* Some suporting tactics *) Ltac simplify_isIn_b := repeat (rewrite union_isIn_b || rewrite L_isIn_b_aa || rewrite intersection_isIn_b || rewrite comprehension_isIn_b). Ltac toBool := repeat intro; apply ext ; intros ; simplify_isIn_b ; eauto with bool_lattice_hints typeclass_instances. Section SetLattice. Context {A : Type}. Context {A_deceq : DecidablePaths A}. Context `{Univalence}. Instance fset_max : maximum (FSet A). Proof. intros x y. apply (x ∪ y). Defined. Instance fset_min : minimum (FSet A). Proof. intros x y. apply (intersection x y). Defined. Instance fset_bot : bottom (FSet A). Proof. unfold bottom. apply ∅. Defined. Instance lattice_fset : Lattice (FSet A). Proof. split; toBool. Defined. End SetLattice. (* With extensionality we can prove decidable equality *) Section dec_eq. Context (A : Type) `{DecidablePaths A} `{Univalence}. Instance fsets_dec_eq : DecidablePaths (FSet A). Proof. intros X Y. apply (decidable_equiv' ((Y ⊆ X) * (X ⊆ Y)) (eq_subset X Y)^-1). apply decidable_prod. Defined. End dec_eq.