Guest User

Untitled

a guest
Mar 17th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.77 KB | None | 0 0
  1. | Some (pair bs cs)
  2. <= equiv_dec bs (rew <- [fun a => tlist B _ a] H2 in tnil) => {
  3. | inl _ =>
  4. Some (rew [fun a => tlist B a _] H1 in tnil, cs);
  5. | _ <= tlist_find_wlist (x ::: xs) ys => {
  6. | None => None;
  7. | Some (pair ys zs) =>
  8. Some (y ::: ys, zs)
  9. }
  10. };
  11. | None <= tlist_find_wlist (x ::: xs) ys => {
  12. | None => None;
  13. | Some (pair ys zs) =>
  14. Some (y ::: ys, zs)
  15. }
  16. };
  17. | _ <= tlist_find_wlist (x ::: xs) ys => {
  18. | None => None;
  19. | Some (pair ys zs) =>
  20. Some (y ::: ys, zs)
  21. }
  22. };
  23. | _ <= tlist_find_wlist (x ::: xs) ys => {
  24. | None => None;
  25. | Some (pair ys zs) =>
  26. Some (y ::: ys, zs)
  27. }
  28. }.
  29.  
  30. End WList.
  31.  
  32. Section WListProofsInj.
  33.  
  34. (* Dependending on the choice of A, this can be either
  35. Eqdep.EqdepTheory.inj_pair2 (incurs axiom)
  36. or Eqdep_dec.inj_pair2_eq_dec (when A is decidable)
  37. *)
  38. Hypothesis inj_pair2 :
  39. forall (U : Type) (P : U -> Type) (p : U) (x y : P p),
  40. (p; x) = (p; y) -> x = y.
  41.  
  42. Context {A : Type}.
  43. Context {B : A -> A -> Type}.
  44.  
  45. Context `{EqDec A}.
  46.  
  47. Hypothesis B_equiv : forall i j, crelation (B i j).
  48. Hypothesis B_equivalence : forall i j, `{Equivalence (B_equiv i j)}.
  49. Hypothesis B_equiv_dec : forall i j, EquivDec (B_equiv i j).
  50.  
  51. Import EqNotations.
  52.  
  53. Open Scope signature_scope.
  54.  
  55. Definition tequiv {i j : A} := tlist_equiv B_equiv B_equivalence (i:=i) (j:=j).
  56. Arguments tequiv /.
  57.  
  58. Ltac cleanup H0 H2 H3 IHf Heqo :=
  59. inversion H0; subst; clear H0;
  60. specialize (IHf _ _ _ _ _ Heqo);
  61. rewrite <- !tlist_app_comm_cons;
  62. try (rewrite <- !tlist_app_comm_cons in IHf);
  63. simpl in IHf |- *;
  64. unfold tlist_equiv_obligation_1;
  65. rewrite eq_dec_refl;
  66. split; auto;
  67. try reflexivity.
  68.  
  69. Lemma tlist_find_wlist_app {i l} (f : tlist B i l)
  70. {j k} (g : tlist B j k) {pre post} :
  71. tlist_find_wlist B_equiv B_equivalence B_equiv_dec g f = Some (pre, post)
  72. -> tequiv f (pre +++ g +++ post).
  73. Proof.
  74. unfold tequiv; intros.
  75. generalize dependent k.
  76. generalize dependent j.
  77. induction f; intros; simpl in H0.
  78. - destruct g.
  79. unfold tlist_find_wlist_obligation_1 in H0.
  80. destruct (eq_dec i0 i); [|discriminate].
  81. inversion H0; now subst.
  82. discriminate.
  83. - destruct g.
  84. unfold tlist_find_wlist_obligation_3 in H0.
  85. destruct (eq_dec i0 i); subst.
  86. inversion H0; now subst.
  87. unfold tlist_find_wlist_obligation_2 in H0.
  88. destruct (tlist_find_wlist _ _ _) eqn:?; [|discriminate].
  89. destruct p.
  90. inversion H0; subst.
  91. now cleanup H0 H2 H3 IHf Heqo.
  92. destruct (eq_dec i0 i); subst. {
  93. destruct (eq_dec j0 j); subst. {
  94. unfold tlist_find_wlist_obligation_7 in H0.
  95. destruct (equiv_dec _ _). {
  96. rewrite e.
  97. unfold tlist_find_wlist_obligation_9 in H0.
  98. unfold tlist_find_wlist_obligation_7 in H0.
  99. destruct (tlist_find_wlist _ _ _ g f) eqn:?. {
  100. destruct p.
  101. unfold tlist_find_wlist_obligation_5 in H0.
  102. destruct (equiv_dec _ _). {
  103. cleanup H0 H2 H3 IHf Heqo.
  104. rewrite e0 in IHf.
  105. apply IHf.
  106. }
  107. clear Heqo.
  108. unfold tlist_find_wlist_obligation_4 in H0.
  109. destruct (tlist_find_wlist _ _ _ (x0 ::: g) f) eqn:?; [|discriminate].
  110. destruct p.
  111. rewrite <- e.
  112. now cleanup H0 H2 H3 IHf Heqo.
  113. }
  114. unfold tlist_find_wlist_obligation_4 in H0.
  115. destruct (tlist_find_wlist _ _ _ (x0 ::: g) f) eqn:?; [|discriminate].
  116. destruct p.
  117. rewrite <- e.
  118. now cleanup H0 H2 H3 IHf Heqo0.
  119. }
  120. unfold tlist_find_wlist_obligation_9 in H0.
  121. unfold tlist_find_wlist_obligation_8 in H0.
  122. destruct (tlist_find_wlist _ _ _ (x0 ::: g) f) eqn:?; [|discriminate].
  123. destruct p.
  124. now cleanup H0 H2 H3 IHf Heqo.
  125. }
  126. unfold tlist_find_wlist_obligation_10 in H0.
  127. destruct (tlist_find_wlist _ _ _ (x0 ::: g) f) eqn:?; [|discriminate].
  128. destruct p.
  129. now cleanup H0 H2 H3 IHf Heqo.
  130. }
  131. unfold tlist_find_wlist_obligation_11 in H0.
  132. destruct (tlist_find_wlist _ _ _ (x0 ::: g) f) eqn:?; [|discriminate].
  133. destruct p.
  134. now cleanup H0 H2 H3 IHf Heqo.
  135. Qed.
  136.  
  137. End WListProofsInj.
  138.  
  139. Definition nat_triple (i j : nat) : Type := ((nat * nat) * nat)%type.
  140.  
  141. Definition my_list : tlist nat_triple 0 4 :=
  142. tcons 1 ((0, 1), 100)
  143. (tcons 2 ((1, 2), 200)
  144. (tcons 3 ((2, 3), 300)
  145. (tcons 4 ((3, 4), 400)
  146. tnil))).
  147.  
  148. Require Import Coq.Arith.EqNat.
  149.  
  150. Definition nat_equivb (i j : nat) (x y : nat_triple i j) : Type :=
  151. match x, y with
  152. (_, a), (_, b) => a = b
  153. end.
  154.  
  155. Program Instance nat_equivalence {i j} : Equivalence (nat_equivb i j).
  156. Next Obligation.
  157. repeat intro.
  158. destruct x; simpl; auto.
  159. Qed.
  160. Next Obligation.
  161. repeat intro.
  162. destruct x, y; simpl; auto.
  163. Qed.
  164. Next Obligation.
  165. repeat intro.
  166. destruct x, y, z; simpl in *; subst; auto.
  167. Qed.
  168.  
  169. Program Instance nat_equiv_dec {i j : nat} :
  170. EquivDec (A:=nat) (B:=nat_triple) (i:=i) (j:=j) (nat_equivb i j)
  171. (H:=@nat_equivalence i j).
  172. Next Obligation.
  173. destruct x, y.
  174. destruct (eq_dec n n0).
  175. subst.
  176. left; reflexivity.
  177. right; intro.
  178. apply n1.
  179. inversion X.
  180. reflexivity.
  181. Defined.
  182.  
  183. Example tlist_find_wlist_nat_ex1 :
  184. @tlist_find_wlist
  185. nat nat_triple PeanoNat.Nat.eq_dec nat_equivb
  186. (fun _ _ => nat_equivalence) (fun _ _ => nat_equiv_dec)
  187. 1 3 (tcons 2 ((1, 2), 200) (tcons 3 ((2, 3), 300) tnil))
  188. 0 4 my_list
  189. === Some (((0, 1, 100) ::: tnil), ((3, 4, 400) ::: tnil)).
  190. Proof. reflexivity. Qed.
Add Comment
Please, Sign In to add comment