Skip to content

Commit e20db47

Browse files
committed
Use HB.lock
1 parent 6f4b26a commit e20db47

File tree

1 file changed

+51
-104
lines changed

1 file changed

+51
-104
lines changed

finmap.v

Lines changed: 51 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -492,14 +492,9 @@ Definition pred_of_finset (K : choiceType)
492492
(f : finSet K) : pred K := fun k => k \in (enum_fset f).
493493
Canonical finSetPredType (K : choiceType) := PredType (@pred_of_finset K).
494494

495-
Section FinSetCanonicals.
496-
497-
Variable (K : choiceType).
498-
499-
HB.instance Definition _ := [isSub for (@enum_fset K)].
500-
HB.instance Definition _ := [Choice of {fset K} by <:].
501-
502-
End FinSetCanonicals.
495+
HB.instance Definition _ (K : choiceType) := [isSub for @enum_fset K].
496+
HB.instance Definition _ (K : choiceType) := [Choice of {fset K} by <:].
497+
HB.instance Definition _ (T : countType) := [Countable of {fset T} by <:].
503498

504499
Section FinTypeSet.
505500

@@ -516,7 +511,6 @@ Record fset_sub_type : predArgType :=
516511

517512
HB.instance Definition _ := [isSub for fsval].
518513
HB.instance Definition _ := [Choice of fset_sub_type by <:].
519-
HB.instance Definition _ (T : countType) := [Countable of {fset T} by <:].
520514

521515
Definition fset_sub_enum : seq fset_sub_type :=
522516
undup (pmap insub (enum_fset A)).
@@ -575,33 +569,32 @@ Definition set_of_fset (K : choiceType) (A : {fset K}) : {set A} :=
575569

576570
Arguments pred_of_finset : simpl never.
577571

572+
HB.lock Definition seq_fset
573+
(finset_key : unit) (K : choiceType) (s : seq K) : {fset K} :=
574+
mkFinSet (@canonical_sort_keys K s).
575+
578576
Section SeqFset.
579577

580-
Variable finset_key : unit.
581-
Definition seq_fset : forall K : choiceType, seq K -> {fset K} :=
582-
locked_with finset_key (fun K s => mkFinSet (@canonical_sort_keys K s)).
578+
Variable (finset_key : unit) (K : choiceType) (s : seq K).
583579

584-
Variable (K : choiceType) (s : seq K).
580+
Notation seq_fset := (seq_fset finset_key).
585581

586582
Lemma seq_fsetE : seq_fset s =i s.
587-
Proof. by move=> a; rewrite [seq_fset]unlock sort_keysE. Qed.
583+
Proof. by move=> a; rewrite unlock sort_keysE. Qed.
588584

589585
Lemma size_seq_fset : size (seq_fset s) = size (undup s).
590-
Proof. by rewrite [seq_fset]unlock /= size_sort_keys. Qed.
586+
Proof. by rewrite unlock /= size_sort_keys. Qed.
591587

592588
Lemma seq_fset_uniq : uniq (seq_fset s).
593-
Proof. by rewrite [seq_fset]unlock /= sort_keys_uniq. Qed.
589+
Proof. by rewrite unlock /= sort_keys_uniq. Qed.
594590

595591
Lemma seq_fset_perm : perm_eq (seq_fset s) (undup s).
596-
Proof. by rewrite [seq_fset]unlock //= sort_keys_perm. Qed.
592+
Proof. by rewrite unlock //= sort_keys_perm. Qed.
597593

598594
End SeqFset.
599595

600596
#[global] Hint Resolve keys_canonical sort_keys_uniq : core.
601597

602-
HB.instance Definition _ K := [isSub for (@enum_fset K)].
603-
HB.instance Definition _ (K : choiceType) := [Choice of {fset K} by <:].
604-
605598
Section FinPredStruct.
606599

607600
Structure finpredType (T : eqType) := FinPredType {
@@ -739,46 +732,25 @@ Canonical seq_finpredType (T : eqType) :=
739732

740733
End CanonicalFinPred.
741734

742-
Local Notation imfset_def key :=
743-
(fun (T K : choiceType) (f : T -> K) (p : finmempred T)
744-
=> seq_fset key [seq f x | x <- enum_finmem p]).
745-
Local Notation imfset2_def key :=
746-
(fun (K T1 : choiceType) (T2 : T1 -> choiceType)
747-
(f : forall x : T1, T2 x -> K)
748-
(p1 : finmempred T1) (p2 : forall x : T1, finmempred (T2 x)) =>
749-
seq_fset key [seq f x y | x <- enum_finmem p1, y <- enum_finmem (p2 x)]).
750-
751-
Module Type ImfsetSig.
752-
Parameter imfset : forall (key : unit) (T K : choiceType)
753-
(f : T -> K) (p : finmempred T), {fset K}.
754-
Parameter imfset2 : forall (key : unit) (K T1 : choiceType)
755-
(T2 : T1 -> choiceType)(f : forall x : T1, T2 x -> K)
756-
(p1 : finmempred T1) (p2 : forall x : T1, finmempred (T2 x)), {fset K}.
757-
Axiom imfsetE : forall key, imfset key = imfset_def key.
758-
Axiom imfset2E : forall key, imfset2 key = imfset2_def key.
759-
End ImfsetSig.
760-
761-
Module Imfset : ImfsetSig.
762-
Definition imfset key := imfset_def key.
763-
Definition imfset2 key := imfset2_def key.
764-
Lemma imfsetE key : imfset key = imfset_def key. Proof. by []. Qed.
765-
Lemma imfset2E key : imfset2 key = imfset2_def key. Proof. by []. Qed.
766-
End Imfset.
767-
768-
Notation imfset := Imfset.imfset.
769-
Notation imfset2 := Imfset.imfset2.
770-
Canonical imfset_unlock k := Unlockable (Imfset.imfsetE k).
771-
Canonical imfset2_unlock k := Unlockable (Imfset.imfset2E k).
735+
HB.lock Definition imfset
736+
(key : unit) (T K : choiceType) (f : T -> K) (p : finmempred T) : {fset K} :=
737+
seq_fset key [seq f x | x <- enum_finmem p].
738+
739+
HB.lock Definition imfset2
740+
(key : unit) (K T1 : choiceType) (T2 : T1 -> choiceType)
741+
(f : forall x : T1, T2 x -> K)
742+
(p1 : finmempred T1) (p2 : forall x : T1, finmempred (T2 x)) : {fset K} :=
743+
seq_fset key [seq f x y | x <- enum_finmem p1, y <- enum_finmem (p2 x)].
772744

773745
Notation "A `=` B" := (A = B :> {fset _}) (only parsing) : fset_scope.
774746
Notation "A `<>` B" := (A <> B :> {fset _}) (only parsing) : fset_scope.
775747
Notation "A `==` B" := (A == B :> {fset _}) (only parsing) : fset_scope.
776748
Notation "A `!=` B" := (A != B :> {fset _}) (only parsing) : fset_scope.
777749
Notation "A `=P` B" := (A =P B :> {fset _}) (only parsing) : fset_scope.
778750

779-
Notation "f @`[ key ] A" := (Imfset.imfset key f (mem A)) : fset_scope.
751+
Notation "f @`[ key ] A" := (imfset key f (mem A)) : fset_scope.
780752
Notation "f @2`[ key ] ( A , B )" :=
781-
(Imfset.imfset2 key f (mem A) (fun x => (mem (B x)))) : fset_scope.
753+
(imfset2 key f (mem A) (fun x => (mem (B x)))) : fset_scope.
782754

783755
Fact imfset_key : unit. Proof. exact: tt. Qed.
784756

@@ -3751,23 +3723,17 @@ Fact fsfun_subproof (f : fsfun) (k : K) (kf : k \in fmap_of_fsfun f) :
37513723
(fmap_of_fsfun f).[kf] != default k.
37523724
Proof. case:f kf => f f_stable kf; exact: (forallP f_stable [` kf]). Qed.
37533725

3754-
Definition fun_of_fsfun (f : fsfun) (k : K) :=
3755-
odflt (default k) (fmap_of_fsfun f).[? k].
37563726
End FsfunDef.
37573727

3728+
HB.lock Definition fun_of_fsfun
3729+
(K : choiceType) (V : eqType) (d : K -> V) (f : fsfun d) (k : K) : V :=
3730+
odflt (d k) (fmap_of_fsfun f).[? k].
3731+
37583732
Coercion fun_of_fsfun : fsfun >-> Funclass.
37593733

3760-
Module Type FinSuppSig.
3761-
Axiom fs : forall (K : choiceType) (V : eqType) (default : K -> V),
3762-
fsfun default -> {fset K}.
3763-
Axiom E : fs = (fun K V d f => domf (@fmap_of_fsfun K V d f)).
3764-
End FinSuppSig.
3765-
Module FinSupp : FinSuppSig.
3766-
Definition fs := (fun K V d f => domf (@fmap_of_fsfun K V d f)).
3767-
Definition E := erefl fs.
3768-
End FinSupp.
3769-
Notation finsupp := FinSupp.fs.
3770-
Canonical unlockable_finsupp := Unlockable FinSupp.E.
3734+
HB.lock Definition finsupp
3735+
(K : choiceType) (V : eqType) (d : K -> V) (f : fsfun d) : {fset K} :=
3736+
domf (@fmap_of_fsfun K V d f).
37713737

37723738
Section FSfunBasics.
37733739

@@ -3776,7 +3742,7 @@ Implicit Types (f : fsfun default) (k : K) (v : V).
37763742

37773743
Lemma mem_finsupp f k : (k \in finsupp f) = (f k != default k).
37783744
Proof.
3779-
rewrite /fun_of_fsfun [finsupp]unlock; case: fndP; rewrite ?eqxx //=.
3745+
rewrite 2!unlock; case: fndP; rewrite ?eqxx //=.
37803746
by move=> kf; rewrite fsfun_subproof.
37813747
Qed.
37823748

@@ -3799,7 +3765,7 @@ Qed.
37993765
Lemma fsfunP f f' : f =1 f' <-> f = f'.
38003766
Proof.
38013767
split=> [eq_fg|->//]; apply/val_inj/fmapP => k.
3802-
have := eq_fg k; rewrite /(f _) /(f' _) /=.
3768+
have := eq_fg k; rewrite unlock/=.
38033769
case: fndP; case: fndP => //= kf kf'; first by move->.
38043770
by move/eqP/negPn; rewrite fsfun_subproof.
38053771
by move/eqP/negPn; rewrite eq_sym fsfun_subproof.
@@ -3821,7 +3787,7 @@ Definition fsfun_of_can_ffun (T : {fset K}) (g : {ffun T -> V})
38213787
Lemma fsfun_of_can_ffunE (T : {fset K}) (g : {ffun T -> V})
38223788
(can_g : forall k : T , g k != default (val k)) k (kg : k \in T) :
38233789
(fsfun_of_can_ffun can_g) k = g.[kg].
3824-
Proof. by rewrite/fun_of_fsfun in_fnd. Qed.
3790+
Proof. by rewrite unlock in_fnd. Qed.
38253791

38263792
End FSfunBasics.
38273793

@@ -3844,57 +3810,43 @@ Notation "{ 'fsfun' 'of' x => dflt }" := {fsfun of x : _ => dflt}
38443810
Notation "{ 'fsfun' 'with' dflt }" := {fsfun of _ => dflt}
38453811
(at level 0, only parsing) : type_scope.
38463812

3847-
Module Type FsfunSig.
3848-
Section FsfunSig.
3849-
Variables (K : choiceType) (V : eqType) (default : K -> V).
3850-
3851-
Parameter of_ffun : forall (S : {fset K}), (S -> V) -> unit -> fsfun default.
3852-
Variables (S : {fset K}) (h : S -> V).
3853-
Axiom of_ffunE :forall key x, of_ffun h key x = odflt (default x) (omap h (insub x)).
3854-
3855-
End FsfunSig.
3856-
End FsfunSig.
3857-
3858-
Module Fsfun : FsfunSig.
38593813
Section FsfunOfFinfun.
38603814

3861-
Variables (K : choiceType) (V : eqType) (default : K -> V)
3862-
(S : {fset K}) (h : S -> V).
3815+
Variables (K : choiceType) (V : eqType).
3816+
Variables (S : {fset K}) (h : S -> V) (default : K -> V).
38633817

3864-
Let fmap :=
3818+
Let fmap : {fmap K -> V} :=
38653819
[fmap a : [fsetval a in {: S} | h a != default (val a)]
38663820
=> h (fincl (fset_sub_val _ _) a)].
38673821

3868-
Fact fmapP a : fmap a != default (val a).
3822+
Fact fsfun_of_ffun_subproof (a : domf fmap) : fmap a != default (val a).
38693823
Proof.
38703824
rewrite ffunE; have /in_fset_valP [a_in_S] := valP a.
38713825
by have -> : [` a_in_S] = fincl (fset_sub_val _ _) a by exact/val_inj.
38723826
Qed.
38733827

3874-
Definition of_ffun (k : unit) := fsfun_of_can_ffun fmapP.
3828+
End FsfunOfFinfun.
3829+
3830+
HB.lock Definition fsfun_of_ffun
3831+
(k : unit) (K : choiceType) (V : eqType)
3832+
(S : {fset K}) (h : S -> V) (default : K -> V) :=
3833+
fsfun_of_can_ffun (@fsfun_of_ffun_subproof K V S h default).
38753834

3876-
Lemma of_ffunE key x : of_ffun key x = odflt (default x) (omap h (insub x)).
3835+
Lemma fsfun_ffun
3836+
(k : unit) (K : choiceType) (V : eqType)
3837+
(default : K -> V) (S : {fset K}) (h : S -> V) (x : K) :
3838+
fsfun_of_ffun k h default x = odflt (default x) (omap h (insub x)).
38773839
Proof.
3878-
rewrite /fun_of_fsfun /=.
3879-
case: insubP => /= [u _ <-|xNS]; last first.
3840+
rewrite 2!unlock; case: insubP => /= [u _ <-|xNS]; last first.
38803841
case: fndP => //= kf; rewrite !ffunE /=.
38813842
by set y := (X in h X); rewrite (valP y) in xNS.
38823843
case: fndP => /= [kf|].
38833844
by rewrite ffunE; congr (h _); apply/val_inj => //.
38843845
by rewrite inE /= -topredE /= negbK => /eqP ->.
38853846
Qed.
38863847

3887-
End FsfunOfFinfun.
3888-
End Fsfun.
3889-
Canonical fsfun_of_funE K V default S h key x :=
3890-
Unlockable (@Fsfun.of_ffunE K V default S h key x).
3891-
38923848
Fact fsfun_key : unit. Proof. exact: tt. Qed.
38933849

3894-
Definition fsfun_of_ffun key (K : choiceType) (V : eqType)
3895-
(S : {fset K}) (h : S -> V) (default : K -> V) :=
3896-
(Fsfun.of_ffun default h key).
3897-
38983850
HB.instance Definition _ (K V : choiceType) (d : K -> V) :=
38993851
[Choice of fsfun d by <:].
39003852

@@ -4008,18 +3960,13 @@ Notation "[ 'fsfun' ]" := [fsfun for _]
40083960
Section FsfunTheory.
40093961
Variables (key : unit) (K : choiceType) (V : eqType) (default : K -> V).
40103962

4011-
Lemma fsfun_ffun (S : {fset K}) (h : S -> V) (x : K) :
4012-
[fsfun[key] a : S => h a | default a] x =
4013-
odflt (default x) (omap h (insub x)).
4014-
Proof. by rewrite unlock. Qed.
4015-
40163963
Lemma fsfun_fun (S : {fset K}) (h : K -> V) (x : K) :
40173964
[fsfun[key] a in S => h a | default a] x =
40183965
if x \in S then h x else (default x).
40193966
Proof. by rewrite fsfun_ffun; case: insubP => //= [u -> ->|/negPf ->]. Qed.
40203967

40213968
Lemma fsfun0E : [fsfun for default] =1 default.
4022-
Proof. by move=> x; rewrite unlock insubF ?inE. Qed.
3969+
Proof. by move=> x; rewrite fsfun_ffun insubF ?inE. Qed.
40233970

40243971
Definition fsfunE := (fsfun_fun, fsfun0E).
40253972

@@ -4034,7 +3981,7 @@ Qed.
40343981
Lemma finsupp_sub (S : {fset K}) (h : S -> V) :
40353982
finsupp [fsfun[key] a : S => h a | default a] `<=` S.
40363983
Proof.
4037-
apply/fsubsetP => a; rewrite mem_finsupp unlock /=.
3984+
apply/fsubsetP => a; rewrite mem_finsupp fsfun_ffun.
40383985
by case: insubP => //=; rewrite eqxx.
40393986
Qed.
40403987

0 commit comments

Comments
 (0)