Skip to content

Commit 9d4ce82

Browse files
hivertCohenCyril
andauthored
Added lemmas about uniq, injectivity and index to seq (math-comp#1514)
Co-authored-by: Cyril Cohen <cohen@crans.org>
1 parent 43f75bb commit 9d4ce82

2 files changed

Lines changed: 32 additions & 6 deletions

File tree

boot/seq.v

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2848,14 +2848,30 @@ case/subseqP=> m sz_m ->; apply/subseqP.
28482848
by exists m; rewrite ?size_map ?map_mask.
28492849
Qed.
28502850

2851-
Lemma nth_index_map s x0 x :
2852-
{in s &, injective f} -> x \in s -> nth x0 s (index (f x) (map f s)) = x.
2851+
Lemma index_map_in s x :
2852+
{in s &, injective f} -> x \in s -> index (f x) (map f s) = index x s.
28532853
Proof.
2854-
elim: s => //= y s IHs inj_f s_x; rewrite (inj_in_eq inj_f) ?mem_head //.
2855-
move: s_x; rewrite inE; have [-> // | _] := eqVneq; apply: IHs.
2856-
by apply: sub_in2 inj_f => z; apply: predU1r.
2854+
move=> f_inj x_in_s; rewrite /index find_map.
2855+
by apply: eq_in_find => y /= y_s; rewrite (inj_in_eq f_inj).
28572856
Qed.
28582857

2858+
Lemma index_map_inW s x : {in s, injective f} -> index (f x) (map f s) = index x s.
2859+
Proof.
2860+
move=> fI; have [/index_map_in-> // _ _ _ _ /fI-> //|xs] := boolP (x \in s).
2861+
rewrite !memNindex ?size_map//; apply/mapP => -[y ys].
2862+
by move=> /esym/fI -/(_ ys) yx; rewrite -yx ys in xs.
2863+
Qed.
2864+
2865+
Lemma uniq_map_inj_in s : uniq (map f s) -> {in s &, injective f}.
2866+
Proof.
2867+
move=> f_uniq x y /(nthP x)[i ilt <-] /(nthP x)[j jlt <-].
2868+
by rewrite -!(nth_map _ (f x))// => /uniqP /[!(inE, size_map)] ->.
2869+
Qed.
2870+
2871+
Lemma nth_index_map s x0 x :
2872+
{in s &, injective f} -> x \in s -> nth x0 s (index (f x) (map f s)) = x.
2873+
Proof. by move=> f_inj x_in_s; rewrite index_map_in// nth_index. Qed.
2874+
28592875
Lemma perm_map s t : perm_eq s t -> perm_eq (map f s) (map f t).
28602876
Proof. by move/permP=> Est; apply/permP=> a; rewrite !count_map Est. Qed.
28612877

@@ -2871,7 +2887,7 @@ Lemma mem_map s x : (f x \in map f s) = (x \in s).
28712887
Proof. by apply/mapP/idP=> [[y Hy /Hf->] //|]; exists x. Qed.
28722888

28732889
Lemma index_map s x : index (f x) (map f s) = index x s.
2874-
Proof. by rewrite /index; elim: s => //= y s IHs; rewrite (inj_eq Hf) IHs. Qed.
2890+
Proof. by apply: index_map_inW; apply: in1W. Qed.
28752891

28762892
Lemma map_inj_uniq s : uniq (map f s) = uniq s.
28772893
Proof. by apply: map_inj_in_uniq; apply: in2W. Qed.
@@ -3122,6 +3138,13 @@ case: s => [|x s /IH<-]; first by rewrite leqn0 => /eqP->.
31223138
by rewrite -add1n iotaDl -map_comp.
31233139
Qed.
31243140

3141+
Lemma take_mkseq f n i : take i (mkseq f n) = mkseq f (minn i n).
3142+
Proof. by rewrite /mkseq -map_take take_iota. Qed.
3143+
3144+
Lemma drop_mkseq f n i :
3145+
drop i (mkseq f n) = mkseq (fun k => f (i + k)) (n - i).
3146+
Proof. by rewrite /mkseq -map_drop drop_iota addnC iotaDl -map_comp. Qed.
3147+
31253148
End MakeSeq.
31263149

31273150
Section MakeEqSeq.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- in `boot/seq.v`
2+
+ added lemmas `take_mkseq`, `drop_mkseq`, `index_map_in`, `index_map_inW`, and `uniq_map_inj_in`
3+
([#1514](https://github.com/math-comp/math-comp/pull/1514)).

0 commit comments

Comments
 (0)