2017-08-01 15:12:59 +02:00
|
|
|
(* Properties of [FSet A] where [A] has decidable equality *)
|
|
|
|
Require Import HoTT HitTactics.
|
2017-08-01 15:41:53 +02:00
|
|
|
From fsets Require Export properties extensionality operations_decidable.
|
|
|
|
Require Export lattice.
|
2017-08-01 15:12:59 +02:00
|
|
|
|
|
|
|
(* Lemmas relating operations to the membership predicate *)
|
|
|
|
Section operations_isIn.
|
|
|
|
|
2017-08-03 12:21:34 +02:00
|
|
|
Context {A : Type} `{DecidablePaths A} `{Univalence}.
|
2017-08-01 15:12:59 +02:00
|
|
|
|
2017-08-03 12:21:34 +02:00
|
|
|
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.
|
2017-08-01 15:12:59 +02:00
|
|
|
|
2017-08-03 12:21:34 +02:00
|
|
|
Lemma empty_isIn (a : A) :
|
|
|
|
isIn_b a ∅ = false.
|
|
|
|
Proof.
|
|
|
|
reflexivity.
|
|
|
|
Defined.
|
2017-08-01 15:12:59 +02:00
|
|
|
|
2017-08-03 12:21:34 +02:00
|
|
|
Lemma L_isIn (a b : A) :
|
|
|
|
isIn a {|b|} -> a = b.
|
|
|
|
Proof.
|
|
|
|
intros. strip_truncations. assumption.
|
|
|
|
Defined.
|
2017-08-01 15:12:59 +02:00
|
|
|
|
2017-08-03 12:21:34 +02:00
|
|
|
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.
|
2017-08-01 15:12:59 +02:00
|
|
|
|
2017-08-03 12:21:34 +02:00
|
|
|
Lemma L_isIn_b_aa (a : A) :
|
|
|
|
isIn_b a {|a|} = true.
|
|
|
|
Proof.
|
|
|
|
apply L_isIn_b_true ; reflexivity.
|
|
|
|
Defined.
|
2017-08-01 15:12:59 +02:00
|
|
|
|
2017-08-03 12:21:34 +02:00
|
|
|
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 *)
|
2017-08-07 15:39:01 +02:00
|
|
|
Lemma union_isIn_b (X Y : FSet A) (a : A) :
|
2017-08-03 12:21:34 +02:00
|
|
|
isIn_b a (U 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.
|
2017-08-01 15:12:59 +02:00
|
|
|
|
2017-08-07 15:39:01 +02:00
|
|
|
Lemma comprehension_isIn_b (Y : FSet A) (ϕ : A -> Bool) (a : A) :
|
|
|
|
isIn_b a (comprehension ϕ Y) = andb (isIn_b a Y) (ϕ a).
|
2017-08-03 12:21:34 +02:00
|
|
|
Proof.
|
2017-08-07 15:39:01 +02:00
|
|
|
unfold isIn_b, dec ; simpl.
|
|
|
|
destruct (isIn_decidable a (comprehension ϕ Y)) as [t | t]
|
|
|
|
; destruct (isIn_decidable a Y) as [n | n] ; rewrite comprehension_isIn in t
|
|
|
|
; destruct (ϕ a) ; try reflexivity ; try contradiction.
|
2017-08-03 12:21:34 +02:00
|
|
|
Defined.
|
|
|
|
|
2017-08-07 15:39:01 +02:00
|
|
|
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).
|
2017-08-03 12:21:34 +02:00
|
|
|
Proof.
|
2017-08-07 15:39:01 +02:00
|
|
|
apply comprehension_isIn_b.
|
2017-08-03 12:21:34 +02:00
|
|
|
Defined.
|
2017-08-07 15:39:01 +02:00
|
|
|
|
2017-08-01 15:12:59 +02:00
|
|
|
End operations_isIn.
|
|
|
|
|
2017-08-07 15:39:01 +02:00
|
|
|
Global Opaque isIn_b.
|
|
|
|
|
2017-08-01 15:12:59 +02:00
|
|
|
(* Some suporting tactics *)
|
|
|
|
Ltac simplify_isIn :=
|
2017-08-07 15:39:01 +02:00
|
|
|
repeat (rewrite union_isIn_b
|
2017-08-03 12:49:15 +02:00
|
|
|
|| rewrite L_isIn_b_aa
|
2017-08-07 15:39:01 +02:00
|
|
|
|| rewrite intersection_isIn_b
|
|
|
|
|| rewrite comprehension_isIn_b).
|
2017-08-03 12:21:34 +02:00
|
|
|
|
2017-08-03 12:49:15 +02:00
|
|
|
Ltac toBool :=
|
|
|
|
repeat intro;
|
|
|
|
apply ext ; intros ;
|
|
|
|
simplify_isIn ; eauto with bool_lattice_hints typeclass_instances.
|
2017-08-01 15:12:59 +02:00
|
|
|
|
|
|
|
Section SetLattice.
|
|
|
|
|
|
|
|
Context {A : Type}.
|
|
|
|
Context {A_deceq : DecidablePaths A}.
|
|
|
|
Context `{Univalence}.
|
|
|
|
|
2017-08-03 12:21:34 +02:00
|
|
|
Instance fset_max : maximum (FSet A) := U.
|
|
|
|
Instance fset_min : minimum (FSet A) := intersection.
|
|
|
|
Instance fset_bot : bottom (FSet A) := E.
|
2017-08-07 15:39:01 +02:00
|
|
|
|
2017-08-03 12:21:34 +02:00
|
|
|
Instance lattice_fset : Lattice (FSet A).
|
2017-08-01 15:12:59 +02:00
|
|
|
Proof.
|
2017-08-03 12:49:15 +02:00
|
|
|
split; toBool.
|
2017-08-01 15:12:59 +02:00
|
|
|
Defined.
|
|
|
|
|
|
|
|
End SetLattice.
|
|
|
|
|
|
|
|
(* Comprehension properties *)
|
|
|
|
Section comprehension_properties.
|
|
|
|
|
|
|
|
Context {A : Type}.
|
|
|
|
Context {A_deceq : DecidablePaths A}.
|
|
|
|
Context `{Univalence}.
|
|
|
|
|
|
|
|
Lemma comprehension_or : forall ϕ ψ (x: FSet A),
|
|
|
|
comprehension (fun a => orb (ϕ a) (ψ a)) x
|
|
|
|
= U (comprehension ϕ x) (comprehension ψ x).
|
|
|
|
Proof.
|
|
|
|
toBool.
|
|
|
|
Defined.
|
|
|
|
|
|
|
|
(** comprehension properties *)
|
|
|
|
Lemma comprehension_false Y : comprehension (fun (_ : A) => false) Y = E.
|
|
|
|
Proof.
|
|
|
|
toBool.
|
2017-08-07 15:39:01 +02:00
|
|
|
Defined.
|
2017-08-01 15:12:59 +02:00
|
|
|
|
|
|
|
Lemma comprehension_all : forall (X : FSet A),
|
|
|
|
comprehension (fun a => isIn_b a X) X = X.
|
|
|
|
Proof.
|
|
|
|
toBool.
|
2017-08-07 15:39:01 +02:00
|
|
|
Defined.
|
2017-08-01 15:12:59 +02:00
|
|
|
|
|
|
|
Lemma comprehension_subset : forall ϕ (X : FSet A),
|
2017-08-03 12:21:34 +02:00
|
|
|
U (comprehension ϕ X) X = X.
|
2017-08-01 15:12:59 +02:00
|
|
|
Proof.
|
|
|
|
toBool.
|
|
|
|
Defined.
|
|
|
|
|
|
|
|
End comprehension_properties.
|
|
|
|
|
|
|
|
(* 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' ((subset Y X) * (subset X Y)) (eq_subset X Y)^-1).
|
2017-08-03 12:49:15 +02:00
|
|
|
apply decidable_prod.
|
2017-08-01 15:12:59 +02:00
|
|
|
Defined.
|
|
|
|
|
2017-08-07 15:39:01 +02:00
|
|
|
End dec_eq.
|