Commit 2b8d69bc authored by Simon Spies's avatar Simon Spies

seqZ: move definition and use different length lemma

parent 3887c4f7
Pipeline #18000 canceled with stage
......@@ -1465,68 +1465,6 @@ Proof.
rewrite lookup_seq by done. intuition congruence.
Qed.
(** ** Properties of the [seqZ] function *)
Section seqZ.
Implicit Types (m n : Z) (i j: nat).
Local Open Scope Z.
Lemma seqZ_nil m n: n 0 seqZ m n = [].
Proof. intros H; destruct n; simpl; eauto; lia. Qed.
Lemma seqZ_cons m n: n > 0 seqZ m n = m :: seqZ (m + 1) (n - 1).
Proof.
intros H. unfold seqZ.
replace (Z.to_nat n) with (S (Z.to_nat (n - 1))) by
(rewrite <-Z2Nat.inj_succ; [f_equal|]; lia).
simpl; f_equal; try lia.
erewrite <-fmap_seq, map_map, map_ext; eauto.
intros; lia.
Qed.
Lemma seqZ_length m n: length (seqZ m n) = Z.to_nat n.
Proof.
unfold seqZ; by rewrite map_length, seq_length.
Qed.
Lemma seqZ_fmap m m' n: Z.add m <$> seqZ m' n = seqZ (m + m') n.
Proof.
assert (0 n n < 0) as [H|H] by lia.
- revert m'. pattern n. eapply natlike_ind; auto; clear n H.
intros n H1 IH j. rewrite seqZ_cons; try lia.
symmetry. rewrite seqZ_cons; try lia.
replace (Z.succ n - 1) with n by lia.
simpl; rewrite IH.
f_equal; try lia; f_equal; lia.
- rewrite !seqZ_nil; auto; lia.
Qed.
Lemma seqZ_lookup m n i: i < n seqZ m n !! i = Some (m + i).
Proof.
assert (0 n n < 0) as [H|H] by lia.
- revert m i. pattern n. eapply natlike_ind; auto; clear n H.
intros; lia.
intros n H1 IH. intros j [|i] ?; rewrite seqZ_cons. 2, 4: lia.
simpl; f_equal; lia. replace (Z.succ n - 1) with n by lia.
simpl; rewrite IH; f_equal; lia.
- rewrite !seqZ_nil; auto; lia.
Qed.
Lemma seqZ_lookup_ge m n i: n i seqZ m n !! i = None.
Proof.
assert (0 n n < 0) as [H|H] by lia.
- revert m i. pattern n. eapply natlike_ind; auto; clear n H.
intros n H1 IH. intros j [|i] ?; rewrite seqZ_cons. 2, 4: lia.
simpl; f_equal; lia. replace (Z.succ n - 1) with n by lia.
simpl; rewrite IH; f_equal; lia.
- rewrite !seqZ_nil; auto; lia.
Qed.
Lemma seqZ_lookup_inv m n i m' : seqZ m n !! i = Some m' m' = m + i i < n.
Proof.
destruct (Z_le_gt_dec n i); [by rewrite seqZ_lookup_ge|].
rewrite seqZ_lookup by lia. intuition; [congruence|lia].
Qed.
End seqZ.
(** ** Properties of the [Permutation] predicate *)
Lemma Permutation_nil l : l ≡ₚ [] l = [].
......@@ -3403,6 +3341,70 @@ Section mapM.
Proof. eauto using mapM_fmap_Forall2_Some_inv, Forall2_true, mapM_length. Qed.
End mapM.
(** ** Properties of the [seqZ] function *)
Section seqZ.
Implicit Types (m n : Z) (i j: nat).
Local Open Scope Z.
Lemma seqZ_nil m n: n 0 seqZ m n = [].
Proof. intros H; destruct n; simpl; eauto; lia. Qed.
Lemma seqZ_cons m n: n > 0 seqZ m n = m :: seqZ (m + 1) (n - 1).
Proof.
intros H. unfold seqZ.
replace (Z.to_nat n) with (S (Z.to_nat (n - 1))) by
(rewrite <-Z2Nat.inj_succ; [f_equal|]; lia).
simpl; f_equal; try lia.
erewrite <-fmap_seq, map_map, map_ext; eauto.
intros; lia.
Qed.
Lemma seqZ_length m n: length (seqZ m n) = Z.to_nat n.
Proof.
unfold seqZ; by rewrite fmap_length, seq_length.
Qed.
Lemma seqZ_fmap m m' n: Z.add m <$> seqZ m' n = seqZ (m + m') n.
Proof.
assert (0 n n < 0) as [H|H] by lia.
- revert m'. pattern n. eapply natlike_ind; auto; clear n H.
intros n H1 IH j. rewrite seqZ_cons; try lia.
symmetry. rewrite seqZ_cons; try lia.
replace (Z.succ n - 1) with n by lia.
simpl; rewrite IH.
f_equal; try lia; f_equal; lia.
- rewrite !seqZ_nil; auto; lia.
Qed.
Lemma seqZ_lookup m n i: i < n seqZ m n !! i = Some (m + i).
Proof.
assert (0 n n < 0) as [H|H] by lia.
- revert m i. pattern n. eapply natlike_ind; auto; clear n H.
intros; lia.
intros n H1 IH. intros j [|i] ?; rewrite seqZ_cons. 2, 4: lia.
simpl; f_equal; lia. replace (Z.succ n - 1) with n by lia.
simpl; rewrite IH; f_equal; lia.
- rewrite !seqZ_nil; auto; lia.
Qed.
Lemma seqZ_lookup_ge m n i: n i seqZ m n !! i = None.
Proof.
assert (0 n n < 0) as [H|H] by lia.
- revert m i. pattern n. eapply natlike_ind; auto; clear n H.
intros n H1 IH. intros j [|i] ?; rewrite seqZ_cons. 2, 4: lia.
simpl; f_equal; lia. replace (Z.succ n - 1) with n by lia.
simpl; rewrite IH; f_equal; lia.
- rewrite !seqZ_nil; auto; lia.
Qed.
Lemma seqZ_lookup_inv m n i m' : seqZ m n !! i = Some m' m' = m + i i < n.
Proof.
destruct (Z_le_gt_dec n i); [by rewrite seqZ_lookup_ge|].
rewrite seqZ_lookup by lia. intuition; [congruence|lia].
Qed.
End seqZ.
(** ** Properties of the [permutations] function *)
Section permutations.
Context {A : Type}.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment