diff options
| author | Oliver Nash | 2019-09-03 20:38:52 +0100 |
|---|---|---|
| committer | Oliver Nash | 2019-09-03 20:38:52 +0100 |
| commit | 3d5eec61f7d150f3ac2d6e7785a6e6d31fe0c690 (patch) | |
| tree | b078931e6059c3f39f32b62ff5fd6cb223ed3a0c /theories/Lists | |
| parent | fef9016bd3ca6544f0110bdbf8dbe6ca24120450 (diff) | |
Add lemmas directly relating List.nth and List.nth_error
Diffstat (limited to 'theories/Lists')
| -rw-r--r-- | theories/Lists/List.v | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/theories/Lists/List.v b/theories/Lists/List.v index 88c47b9744..38723e291f 100644 --- a/theories/Lists/List.v +++ b/theories/Lists/List.v @@ -536,6 +536,26 @@ Section Elts. simpl in *. apply IHn. auto with arith. Qed. + (** Results directly relating [nth] and [nth_error] *) + + Lemma nth_error_nth : forall (l : list A) (n : nat) (x d : A), + nth_error l n = Some x -> nth n l d = x. + Proof. + intros l n x d H. + apply nth_error_split in H. destruct H as [l1 [l2 [H H']]]. + subst. rewrite app_nth2; [|auto]. + rewrite Nat.sub_diag. reflexivity. + Qed. + + Lemma nth_error_nth' : forall (l : list A) (n : nat) (d : A), + n < length l -> nth_error l n = Some (nth n l d). + Proof. + intros l n d H. + apply nth_split with (d:=d) in H. destruct H as [l1 [l2 [H H']]]. + subst. rewrite H. rewrite nth_error_app2; [|auto]. + rewrite app_nth2; [| auto]. repeat (rewrite Nat.sub_diag). reflexivity. + Qed. + (*****************) (** ** Remove *) (*****************) |
