aboutsummaryrefslogtreecommitdiff
path: root/mathcomp
diff options
context:
space:
mode:
authorCyril Cohen2017-11-21 15:31:46 +0100
committerGitHub2017-11-21 15:31:46 +0100
commit82739c704bef2234dce643cbdd0b5be5a79b755b (patch)
treee2f58846fcadc29f934a15b81257060218761a3c /mathcomp
parent1b2011402ac3fb6d7b28e8eb3178a70a6d1b3d14 (diff)
parent8f62332b4b05eb796a72439d4b01b1f1ca8c44d7 (diff)
Merge pull request #115 from strub/uniqP
Reflection lemmas for `seq.uniq`
Diffstat (limited to 'mathcomp')
-rw-r--r--mathcomp/ssreflect/seq.v29
1 files changed, 29 insertions, 0 deletions
diff --git a/mathcomp/ssreflect/seq.v b/mathcomp/ssreflect/seq.v
index 9ff9f61..5ec8ee2 100644
--- a/mathcomp/ssreflect/seq.v
+++ b/mathcomp/ssreflect/seq.v
@@ -1319,6 +1319,35 @@ elim: v i => [|n v IHv] [|i] //=; first by rewrite size_ncons /= addn1.
by rewrite IHv; apply: fun_if.
Qed.
+Section uniqP.
+Variable T : eqType.
+Implicit Type s : seq T.
+
+Lemma uniqP x0 s :
+ reflect {in [pred i | i < size s] &, injective (nth x0 s)} (uniq s).
+Proof.
+apply: (iffP idP) => [uq_s i j lei lej /eqP|].
++ by rewrite nth_uniq // => /eqP.
+elim: s => //= x s ih inj_nth; rewrite ih ?andbT; last first.
++ by move=> i j lei lej /(inj_nth i.+1 j.+1 lei lej) [].
+apply/negP=> /(nthP x0) [i lti xE].
+by have := (inj_nth 0 i.+1 (ltn0Sn _) lti (esym xE)).
+Qed.
+
+Lemma uniqPn x0 s :
+ reflect (exists i j, [&& i < size s, j < size s,
+ i != j & nth x0 s i == nth x0 s j])
+ (~~ uniq s).
+Proof.
+apply: (iffP idP) => [|[i] [j] /and4P[lei lej /eqP ne_ij eq_nth]]; last first.
++ by apply/negP=> /uniqP /(_ _ _ lei lej (eqP eq_nth)).
+elim: s => //= x s ih /nandP[]; last first.
++ by case/ih=> [i] [j] {ih}ih; exists i.+1, j.+1.
+rewrite negbK => /(nthP x0) [j ltj <-].
+by exists 0, j.+1 => /=; rewrite eqxx andbT.
+Qed.
+End uniqP.
+
(* Equality up to permutation *)
Section PermSeq.