| 1 |
(** Some constants that return their first argument, and hold an equal second argument. *) |
| 2 |
Require Import Crypto.Util.Tuple. |
| 3 |
Definition id_with_alt {A} (value : A) (value_for_alt : A) : A |
| 4 |
:= value. |
| 5 |
Definition id_with_alt_proof {A} (value : A) (value_for_alt : A) |
| 6 |
{pf : value = value_for_alt} |
| 7 |
: A |
| 8 |
:= id_with_alt value value_for_alt. |
| 9 |
|
| 10 |
Section tuple. |
| 11 |
Context {A : Type}. |
| 12 |
|
| 13 |
Fixpoint id_tuple'_with_alt {n} |
| 14 |
: forall (value value_for_alt : tuple' A n), |
| 15 |
tuple' A n |
| 16 |
:= match n return forall value value_for_alt : tuple' A n, tuple' A n with |
| 17 |
| O => id_with_alt |
| 18 |
| S n' => fun (value value_for_alt : tuple' A n' * A) |
| 19 |
=> (@id_tuple'_with_alt n' (fst value) (fst value_for_alt), |
| 20 |
@id_with_alt A (snd value) (snd value_for_alt)) |
| 21 |
end. |
| 22 |
|
| 23 |
Fixpoint id_tuple'_with_alt_proof {n} |
| 24 |
: forall (value value_for_alt : tuple' A n) {pf : value = value_for_alt}, |
| 25 |
tuple' A n |
| 26 |
:= match n return forall value value_for_alt : tuple' A n, _ -> tuple' A n with |
| 27 |
| O => id_with_alt_proof |
| 28 |
| S n' => fun (value value_for_alt : tuple' A n' * A) (pf : value = value_for_alt) |
| 29 |
=> (@id_tuple'_with_alt_proof n' (fst value) (fst value_for_alt) |
| 30 |
(f_equal (@fst _ _) pf), |
| 31 |
@id_with_alt_proof A (snd value) (snd value_for_alt) |
| 32 |
(f_equal (@snd _ _) pf)) |
| 33 |
end. |
| 34 |
End tuple. |
| 35 |
Definition id_tuple_with_alt {A n} |
| 36 |
: forall (value value_for_alt : tuple A n), tuple A n |
| 37 |
:= match n with |
| 38 |
| O => id_with_alt |
| 39 |
| S n' => id_tuple'_with_alt |
| 40 |
end. |
| 41 |
Definition id_tuple_with_alt_proof {A n} |
| 42 |
: forall (value value_for_alt : tuple A n) {pf : value = value_for_alt}, |
| 43 |
tuple A n |
| 44 |
:= match n with |
| 45 |
| O => id_with_alt_proof |
| 46 |
| S n' => id_tuple'_with_alt_proof |
| 47 |
end. |
| 48 |
|
| 49 |
Lemma unfold_id_with_alt {A} value value' |
| 50 |
: @id_with_alt A value value' = value. |
| 51 |
Proof. reflexivity. Qed. |
| 52 |
Lemma unfold_id_with_alt_proof {A} value value' pf |
| 53 |
: @id_with_alt_proof A value value' pf = value. |
| 54 |
Proof. reflexivity. Qed. |
| 55 |
Local Ltac t_ind n := |
| 56 |
let IHn := fresh "IHn" in |
| 57 |
induction n as [|n IHn]; cbn [id_tuple'_with_alt id_tuple'_with_alt_proof]; |
| 58 |
first [ rewrite unfold_id_with_alt | rewrite unfold_id_with_alt_proof ]; |
| 59 |
[ reflexivity |
| 60 |
| rewrite IHn, <- surjective_pairing; reflexivity ]. |
| 61 |
Lemma unfold_id_tuple'_with_alt {A n} value value' |
| 62 |
: @id_tuple'_with_alt A n value value' = value. |
| 63 |
Proof. t_ind n. Qed. |
| 64 |
Lemma unfold_id_tuple'_with_alt_proof {A n} value value' pf |
| 65 |
: @id_tuple'_with_alt_proof A n value value' pf = value. |
| 66 |
Proof. t_ind n. Qed. |
| 67 |
Lemma unfold_id_tuple_with_alt {A n} value value' |
| 68 |
: @id_tuple_with_alt A n value value' = value. |
| 69 |
Proof. |
| 70 |
destruct n; cbn [id_tuple_with_alt]; |
| 71 |
[ apply unfold_id_with_alt | apply unfold_id_tuple'_with_alt ]. |
| 72 |
Qed. |
| 73 |
Lemma unfold_id_tuple_with_alt_proof {A n} value value' pf |
| 74 |
: @id_tuple_with_alt_proof A n value value' pf = value. |
| 75 |
Proof. |
| 76 |
destruct n; cbn [id_tuple_with_alt_proof]; |
| 77 |
[ apply unfold_id_with_alt_proof | apply unfold_id_tuple'_with_alt_proof ]. |
| 78 |
Qed. |