@@ -97,7 +97,7 @@ Elpi mlock Definition fperm_one {T} : {fperm T} :=
9797 @FPerm T [fsfun] (@fperm_one_subproof T).
9898Notation "1" := fperm_one : fperm_scope.
9999
100- Section BuildAndRenaming .
100+ Section InverseTheory .
101101Variable T : choiceType.
102102Implicit Types (s : {fperm T}) (x : T) (X Y : {fset T}) (f : T -> T).
103103
@@ -113,17 +113,31 @@ move=> /eqP e; apply/eqP/fpermP=> x; rewrite fperm1; case: (finsuppP s) => //.
113113by rewrite e in_fset0.
114114Qed .
115115
116- Definition fperm_def (X : {fset T}) (f : T -> T) x :=
116+ End InverseTheory.
117+
118+ Definition fperm_def {T} (X : {fset T}) (f : T -> T) (x : T) :=
117119 let Y1 : {fset T} := [fset f x | x in X] `\` X in
118120 let Y2 : {fset T} := X `\` [fset f x | x in X] in
119121 if x \in Y1 then nth x Y2 (index x Y1) else f x.
120122
121- Definition fperm X f :=
122- odflt 1 (insub [fsfun x in (X `|` f @` X) => fperm_def X f x]).
123+ Elpi mlock Definition fperm_keyed (key : unit) {T} X f :=
124+ odflt 1 (insub [fsfun x in (X `|` f @` X) => @fperm_def T X f x]).
125+
126+ Arguments fperm_keyed key {T} X f.
127+
128+ Fact default_key : unit. Proof . by []. Qed .
129+ Notation fperm := (@fperm_keyed default_key).
130+
131+ Section BuildAndRename.
132+ Variable T : choiceType.
133+ Implicit Types (s : {fperm T}) (x : T) (X Y : {fset T}) (f : T -> T).
134+
135+ Lemma fperm_default_key k : @fperm_keyed k = @fperm.
136+ Proof . by rewrite !unlock. Qed .
123137
124- Lemma fpermE f X : {in X &, injective f} -> {in X, fperm X f =1 f}.
138+ Lemma fpermE k f X : {in X &, injective f} -> {in X, fperm_keyed k X f =1 f}.
125139Proof .
126- move=> /card_in_imfsetP inj; rewrite /fperm insubT /=; last first.
140+ move=> /card_in_imfsetP inj; rewrite unlock insubT /=; last first.
127141 by move=> _ x x_X; rewrite fsfunE in_fsetU /fperm_def /= in_fsetD x_X.
128142set D := X `|` _; apply/fsinjectivebP; exists D; rewrite ?finsupp_sub //.
129143rewrite /fperm_def; set Y1 := f @` X `\` X; set Y2 := X `\` f @` X.
@@ -151,23 +165,27 @@ rewrite !fsfunE x_D y_D; case: ifPn => x_Y1; case: ifPn => y_Y1.
151165- by apply: (card_in_imfsetP _ _ inj); rewrite nY1_X.
152166Qed .
153167
154- Lemma finsupp_fperm f X : finsupp (fperm X f) `<=` X `|` f @` X.
168+ Lemma finsupp_fperm k f X : finsupp (fperm_keyed k X f) `<=` X `|` f @` X.
155169Proof .
156- rewrite /fperm; case: insubP => /= [g _ ->|_]; first exact: finsupp_sub.
170+ rewrite fperm_keyed.unlock; case: insubP => /= [g _ ->|_].
171+ exact: finsupp_sub.
157172by rewrite finsupp1 fsub0set.
158173Qed .
159174
160- Lemma fpermEst f X x : f @` X = X -> fperm X f x = if x \in X then f x else x.
175+ Lemma fpermEst k f X x : f @` X = X ->
176+ fperm_keyed k X f x = if x \in X then f x else x.
161177Proof .
162178move=> st; case: ifPn=> /= [|x_nin].
163179 by apply/fpermE/card_in_imfsetP/eqP; rewrite st.
164- suff: x \notin finsupp (fperm X f) by case: finsuppP.
180+ suff: x \notin finsupp (fperm_keyed k X f) by case: finsuppP.
165181apply: contra x_nin; apply/fsubsetP.
166182by rewrite -{2}[X]fsetUid -{3}st finsupp_fperm.
167183Qed .
168184
185+ Fact rename_key : unit. Proof . by []. Qed .
186+
169187Definition fperm_rename (X Y : {fset T}) : {fperm T} :=
170- fperm X (fun x => nth x Y (index x X)).
188+ @fperm_keyed rename_key T X (fun x => nth x Y (index x X)).
171189
172190Lemma fperm_renameP X Y :
173191 let s := fperm_rename X Y in
@@ -185,11 +203,19 @@ have im_f: f @` X = Y.
185203 by rewrite mem_nth // size_X index_mem.
186204 by rewrite /f nthK ?fset_uniq //= ?inE ?size_X ?index_mem // nth_index.
187205 by case/imfsetP: y_in => x /= x_in ->; rewrite mem_nth // -size_X index_mem.
188- rewrite -im_f; split; first by rewrite finsupp_fperm.
206+ rewrite -im_f; split; first by rewrite finsupp_fperm.
189207by apply: eq_in_imfset; apply: fpermE.
190208Qed .
191209
192- End BuildAndRenaming.
210+ End BuildAndRename.
211+
212+ Elpi mlock Definition fperm_mul {T} (s1 s2 : {fperm T}) :=
213+ fperm (finsupp s1 `|` finsupp s2) (s1 \o s2).
214+ Infix "*" := fperm_mul : fperm_scope.
215+
216+ Elpi mlock Definition fperm_exp {T} (s : {fperm T}) n :=
217+ iter n (fperm_mul s) 1.
218+ Infix "^+" := fperm_exp : fperm_scope.
193219
194220Section InverseSubDef.
195221Variable T : choiceType.
@@ -209,24 +235,13 @@ apply/fsetP=> x; apply/(sameP idP)/(iffP idP).
209235by case/imfsetP=> [y Py -> {x}]; case: pickP => /=.
210236Qed .
211237
212- Fact fperm_mul_key : unit. exact: tt. Qed .
213-
214238End InverseSubDef.
215239
216- Elpi mlock Definition fperm_mul {T} (s1 s2 : {fperm T}) :=
217- fperm (finsupp s1 `|` finsupp s2) (s1 \o s2).
218- Infix "*" := fperm_mul : fperm_scope.
219-
220240Elpi mlock Definition fperm_inv {T} (s : {fperm T}) :=
221241 fperm (finsupp s) (fun x => oapp val x [pick y : finsupp s | x == s (val y)]).
222242Notation "x ^-1" := (fperm_inv x) : fperm_scope.
223243
224- Elpi mlock Definition fperm_exp {T} (s : {fperm T}) n :=
225- iter n (fperm_mul s) 1.
226- Infix "^+" := fperm_exp : fperm_scope.
227-
228-
229- Section Inverse.
244+ Section InverseTheory.
230245Variable T : choiceType.
231246Implicit Types (x : T) (X Y : {fset T}).
232247Variable (s : {fperm T}).
259274Lemma fperm_finsuppV x : (s^-1 x \in finsupp s) = (x \in finsupp s).
260275Proof . by rewrite -{1}finsupp_inv fperm_finsupp finsupp_inv. Qed .
261276
262- End Inverse .
277+ End InverseTheory .
263278
264- Section Multiplication .
279+ Section Operations .
265280Variable T : choiceType.
266281Implicit Types (s : {fperm T}) (x : T) (X Y : {fset T}).
267282Local Notation "1" := (1 : {fperm T}).
@@ -379,7 +394,8 @@ case/imfsetP=> [w /fset2P [->|->] ->] /=; rewrite eqxx ?fset22 //.
379394case: ifP=> ?; by [apply fset21|apply fset22].
380395Qed .
381396
382- Definition fperm2 x y := fperm [fset x; y] (fperm2_def x y).
397+ Fact fperm2_key : unit. Proof . by []. Qed .
398+ Definition fperm2 x y := fperm_keyed fperm2_key [fset x; y] (fperm2_def x y).
383399
384400Lemma fperm2E x y : fperm2 x y =1 [fun z => z with x |-> y, y |-> x].
385401Proof .
@@ -529,11 +545,9 @@ elim: n => /= [|n IH]; rewrite ?fperm_exp0 ?finsupp1 // fperm_expSl.
529545by rewrite (fsubset_trans (finsupp_mul _ _)) // fsubUset fsubset_refl /=.
530546Qed .
531547
532- End Multiplication.
533-
534- Prenex Implicits fperm_inv fperm_mul fperm2.
535-
548+ End Operations.
536549
550+ Prenex Implicits fperm2.
537551
538552Section Extend.
539553
0 commit comments