| 1 |
From Coq Require Import RelationClasses Relation_Definitions Morphisms. |
| 2 |
Require Import Crypto.Util.Telescope.Core. |
| 3 |
|
| 4 |
Module Export Telescope. |
| 5 |
Definition flattenT_R_lift {X : Type} {t : Telescope} (P : forall A, relation A -> Prop) |
| 6 |
(R : relation X) |
| 7 |
(H : P _ R) |
| 8 |
(H_forall : forall A T (R' : forall a : A, relation (T a)), |
| 9 |
(forall a : A, P _ (R' a)) |
| 10 |
-> P _ (forall_relation R')) |
| 11 |
: P _ (@flattenT_R_relation X R t). |
| 12 |
Proof. |
| 13 |
repeat intro; induction t; simpl in *. |
| 14 |
{ assumption. } |
| 15 |
{ eauto with nocore. } |
| 16 |
Defined. |
| 17 |
|
| 18 |
Global Instance flattenT_R_Reflexive {t X R} {_ : @Reflexive X R} |
| 19 |
: Reflexive (@flattenT_R_relation X R t). |
| 20 |
Proof. |
| 21 |
refine (flattenT_R_lift (@Reflexive) R _ _). |
| 22 |
lazy; eauto with nocore. |
| 23 |
Defined. |
| 24 |
|
| 25 |
Global Instance flattenT_R_Symmetric {t X R} {_ : @Symmetric X R} |
| 26 |
: Symmetric (@flattenT_R_relation X R t). |
| 27 |
Proof. |
| 28 |
refine (flattenT_R_lift (@Symmetric) R _ _). |
| 29 |
lazy; eauto with nocore. |
| 30 |
Defined. |
| 31 |
|
| 32 |
Global Instance flattenT_R_Transitive {t X R} {_ : @Transitive X R} |
| 33 |
: Transitive (@flattenT_R_relation X R t). |
| 34 |
Proof. |
| 35 |
refine (flattenT_R_lift (@Transitive) R _ _). |
| 36 |
lazy; eauto with nocore. |
| 37 |
Defined. |
| 38 |
|
| 39 |
Global Instance flattenT_R_relation_flip_impl_Proper {t X R} |
| 40 |
{H : Proper (Basics.flip R ==> R ==> Basics.flip Basics.impl) |
| 41 |
R} |
| 42 |
: Proper (Basics.flip (flattenT_R_relation R) ==> flattenT_R_relation R ==> Basics.flip Basics.impl) |
| 43 |
(@flattenT_R_relation X R t). |
| 44 |
Proof. |
| 45 |
refine (@flattenT_R_lift X t (fun A R => Proper (Basics.flip R ==> R ==> Basics.flip Basics.impl) R) _ H _). |
| 46 |
unfold Proper, respectful, Basics.flip, Basics.impl, forall_relation in *; intros. |
| 47 |
eauto with nocore. |
| 48 |
Defined. |
| 49 |
|
| 50 |
Global Instance flattenT_eq_Reflexive {t : Telescope} {X : Type} |
| 51 |
: Reflexive (@flattenT_eq X t) |
| 52 |
:= flattenT_R_Reflexive. |
| 53 |
|
| 54 |
Global Instance flattenT_eq_Symmetric {t : Telescope} {X : Type} |
| 55 |
: Symmetric (@flattenT_eq X t) |
| 56 |
:= flattenT_R_Symmetric. |
| 57 |
|
| 58 |
Global Instance flattenT_eq_Transitive {t : Telescope} {X : Type} |
| 59 |
: Transitive (@flattenT_eq X t) |
| 60 |
:= flattenT_R_Transitive. |
| 61 |
|
| 62 |
Global Instance flatten_forall_eq_relation_Reflexive {t P} |
| 63 |
: Reflexive (@flatten_forall_eq_relation t P). |
| 64 |
Proof. |
| 65 |
hnf; induction t; simpl; unfold forall_relation; [ reflexivity | eauto with nocore ]. |
| 66 |
Defined. |
| 67 |
|
| 68 |
Global Instance flatten_forall_eq_relation_Symmetric {t P} |
| 69 |
: Symmetric (@flatten_forall_eq_relation t P). |
| 70 |
Proof. |
| 71 |
hnf; induction t; simpl; unfold forall_relation; [ symmetry; assumption | eauto with nocore ]. |
| 72 |
Defined. |
| 73 |
|
| 74 |
Global Instance flatten_forall_eq_relation_Transitive {t P} |
| 75 |
: Transitive (@flatten_forall_eq_relation t P). |
| 76 |
Proof. |
| 77 |
hnf; induction t; simpl; unfold forall_relation; [ etransitivity; eassumption | eauto with nocore ]. |
| 78 |
Defined. |
| 79 |
|
| 80 |
Global Instance flatten_forall_eq_Reflexive {t P} |
| 81 |
: Reflexive (@flatten_forall_eq t P) |
| 82 |
:= flatten_forall_eq_relation_Reflexive. |
| 83 |
|
| 84 |
Global Instance flatten_forall_eq_Symmetric {t P} |
| 85 |
: Symmetric (@flatten_forall_eq t P) |
| 86 |
:= flatten_forall_eq_relation_Symmetric. |
| 87 |
|
| 88 |
Global Instance flatten_forall_eq_Transitive {t P} |
| 89 |
: Transitive (@flatten_forall_eq t P) |
| 90 |
:= flatten_forall_eq_relation_Transitive. |
| 91 |
|
| 92 |
Global Instance flatten_forall_eq_relation_with_assumption_Reflexive {t P Q} |
| 93 |
: Reflexive (@flatten_forall_eq_relation_with_assumption t P Q). |
| 94 |
Proof. |
| 95 |
hnf; induction t; simpl; unfold forall_relation; [ reflexivity | eauto with nocore ]. |
| 96 |
Defined. |
| 97 |
|
| 98 |
Global Instance flatten_forall_eq_relation_with_assumption_Symmetric {t P Q} |
| 99 |
: Symmetric (@flatten_forall_eq_relation_with_assumption t P Q). |
| 100 |
Proof. |
| 101 |
hnf; induction t; simpl; unfold forall_relation; [ symmetry; eauto with nocore | eauto with nocore ]. |
| 102 |
Defined. |
| 103 |
|
| 104 |
Global Instance flatten_forall_eq_relation_with_assumption_Transitive {t P Q} |
| 105 |
: Transitive (@flatten_forall_eq_relation_with_assumption t P Q). |
| 106 |
Proof. |
| 107 |
hnf; induction t; simpl; unfold forall_relation; [ etransitivity; eauto with nocore | eauto with nocore ]. |
| 108 |
Defined. |
| 109 |
|
| 110 |
Global Instance flatten_forall_eq_with_assumption_Reflexive {t P Q} |
| 111 |
: Reflexive (@flatten_forall_eq_with_assumption t P Q) |
| 112 |
:= flatten_forall_eq_relation_with_assumption_Reflexive. |
| 113 |
|
| 114 |
Global Instance flatten_forall_eq_with_assumption_Symmetric {t P Q} |
| 115 |
: Symmetric (@flatten_forall_eq_with_assumption t P Q) |
| 116 |
:= flatten_forall_eq_relation_with_assumption_Symmetric. |
| 117 |
|
| 118 |
Global Instance flatten_forall_eq_with_assumption_Transitive {t P Q} |
| 119 |
: Transitive (@flatten_forall_eq_with_assumption t P Q) |
| 120 |
:= flatten_forall_eq_relation_with_assumption_Transitive. |
| 121 |
|
| 122 |
Lemma flatten_append_forall_Proper {B P Q} |
| 123 |
: forall f g, |
| 124 |
@flatten_forall_eq B P f g |
| 125 |
-> @flatten_append_forall B P Q f |
| 126 |
-> @flatten_append_forall B P Q g. |
| 127 |
Proof. |
| 128 |
induction B; simpl in *; eauto with nocore. |
| 129 |
intros; subst; assumption. |
| 130 |
Defined. |
| 131 |
|
| 132 |
Global Instance flattenT_unapply_Proper {t X} |
| 133 |
: Proper (pointwise_relation _ eq ==> flattenT_eq) |
| 134 |
(@flattenT_unapply t X). |
| 135 |
Proof. |
| 136 |
repeat intro; unfold pointwise_relation in *; induction t as [|?? IHt]; simpl in *; |
| 137 |
auto with nocore. |
| 138 |
Defined. |
| 139 |
|
| 140 |
Global Instance flattenT_apply_Proper {t X} |
| 141 |
: Proper (flattenT_eq ==> pointwise_relation _ eq) |
| 142 |
(@flattenT_apply t X). |
| 143 |
Proof. |
| 144 |
repeat intro; unfold pointwise_relation in *; induction t as [|?? IHt]; simpl in *; |
| 145 |
auto with nocore. |
| 146 |
Defined. |
| 147 |
|
| 148 |
Global Instance flatten_forall_unapply_Proper {t P} |
| 149 |
: Proper (forall_relation (fun _ => eq) ==> flatten_forall_eq) |
| 150 |
(@flatten_forall_unapply t P). |
| 151 |
Proof. |
| 152 |
repeat intro; unfold forall_relation in *; induction t as [|?? IHt]; simpl in *; |
| 153 |
auto with nocore. |
| 154 |
Defined. |
| 155 |
|
| 156 |
Global Instance flatten_forall_apply_Proper {t P} |
| 157 |
: Proper (flatten_forall_eq ==> forall_relation (fun _ => eq)) |
| 158 |
(@flatten_forall_apply t P). |
| 159 |
Proof. |
| 160 |
repeat intro; unfold forall_relation in *; induction t as [|?? IHt]; simpl in *; |
| 161 |
auto with nocore. |
| 162 |
Defined. |
| 163 |
|
| 164 |
Global Instance flatten_forall_eq_rect_Proper {t P Q H} |
| 165 |
: Proper (flatten_forall_eq ==> flatten_forall_eq) |
| 166 |
(@flatten_forall_eq_rect t P Q H). |
| 167 |
Proof. |
| 168 |
repeat intro; unfold forall_relation in *; induction t as [|?? IHt]; simpl in *; |
| 169 |
auto with nocore; |
| 170 |
subst; simpl; reflexivity. |
| 171 |
Defined. |
| 172 |
End Telescope. |