Guest User

Untitled

a guest
Oct 19th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.47 KB | None | 0 0
  1. Require Import List.
  2. Require Import Wf.
  3. Require Import Relations.
  4.  
  5. Import ListNotations.
  6.  
  7. Section TD2_wf.
  8.  
  9.  
  10.  
  11. (* Hypothesis (A_dec : forall x y : A, {x = y} + {x <> y}).
  12. Variable R : A -> A -> Prop.
  13. Variable l: list A.
  14. Variable l': list A.*)
  15.  
  16.  
  17. Inductive suffix_spec (A:Set) : list A -> list A -> Prop :=
  18. | suffix_nil : forall (l:list A), suffix_spec A l l
  19. | suffix_cons : forall (s l:list A) (a:A), suffix_spec A s l-> suffix_spec A s (a::l).
  20.  
  21. Hint Constructors suffix_spec : suffix.
  22.  
  23.  
  24. Section demo_suffix.
  25. Variable A : Set.
  26. Variable a b c : A.
  27.  
  28. Goal suffix_spec A [] [].
  29. auto with suffix.
  30. Qed.
  31.  
  32. Goal suffix_spec A [] [a; b].
  33. auto with suffix.
  34. Qed.
  35.  
  36. Goal suffix_spec A [b; c] [a; b; c].
  37. auto with suffix.
  38. Qed.
  39. End demo_suffix.
  40.  
  41. Lemma suffix_app_l : forall (X: Set) (xs ys: list X),
  42. suffix_spec X xs ys -> exists ws, ys = ws ++ xs.
  43. Proof.
  44. intros X xs ys; induction ys as [|y ys IHys]; intros H; inversion_clear H as [| ? ? ? Hxsys ]; [exists []| exists []| ]; trivial.
  45. apply IHys in Hxsys as [zs Hzs].
  46. exists (y::zs).
  47. rewrite Hzs.
  48. trivial.
  49. Qed.
  50.  
  51. Lemma suffix_app_r : forall (X: Set) (ws ys: list X), suffix_spec X ys (ws ++ ys) .
  52. Proof.
  53. intros.
  54. induction ws; simpl; auto with suffix.
  55. Qed.
  56.  
  57.  
  58. Lemma suffix_nil_implies_nil : forall (A: Set) (xs : list A), suffix_spec A xs [] -> xs = [].
  59. Proof.
  60. induction xs.
  61. auto with suffix.
  62. intros H; inversion H.
  63. Qed.
  64.  
  65. Lemma suffix_app_nil : forall (X: Set) (xs: list X), suffix_spec X [] xs .
  66. Proof.
  67. intros. induction xs; auto with suffix.
  68. Qed.
  69.  
  70.  
  71. Theorem suffix_app : forall (X: Set) (xs ys: list X), suffix_spec X xs ys <-> exists ws, ys = ws ++ xs.
  72. Proof.
  73. intros X xs ys.
  74. split.
  75. - apply suffix_app_l.
  76. - intros [ws H].
  77. rewrite H.
  78. apply suffix_app_r.
  79. Qed.
  80.  
  81. Hint Resolve suffix_nil_implies_nil suffix_app_l suffix_app_r suffix_app_nil : suffix.
  82.  
  83. Lemma suffix_strict_or_same : forall (A:Set) (xs:list A) (ys:list A) (y:A),
  84. suffix_spec A xs (y::ys) -> (suffix_spec A xs ys \/ xs = y::ys).
  85. Proof.
  86. intros.
  87. inversion_clear H; auto.
  88. Qed.
  89.  
  90. Theorem suffix_spec_antisymmetric : forall (A:Set), antisymmetric (list A) (suffix_spec A).
  91. Proof.
  92. unfold antisymmetric.
  93. intros A xs ys Hxy Hyx.
  94. apply (suffix_app_l A) in Hxy; destruct Hxy as [ws Hxy].
  95. apply (suffix_app_l A) in Hyx; destruct Hyx as [ws' Hyx].
  96. rewrite Hxy in Hyx.
  97. assert (xs = [] ++ xs); auto.
  98. rewrite H in Hyx at 1.
  99. rewrite app_assoc in Hyx.
  100. apply app_inv_tail in Hyx.
  101. symmetry in Hyx.
  102. apply app_eq_nil in Hyx.
  103. destruct Hyx.
  104. rewrite H1 in Hxy.
  105. auto.
  106. Qed.
  107.  
  108. Theorem suffix_spec_refl : forall (A:Set), reflexive (list A) (suffix_spec A).
  109. Proof.
  110. unfold reflexive.
  111. auto with suffix.
  112. Qed.
  113.  
  114. Theorem suffix_spec_trans : forall (A:Set), transitive (list A) (suffix_spec A).
  115. Proof.
  116. unfold transitive.
  117. intros A xs ys zs Hxy Hyz.
  118. apply (suffix_app_l A) in Hxy; destruct Hxy as [ws Hxy].
  119. apply (suffix_app_l A) in Hyz; destruct Hyz as [ws' Hyz].
  120. rewrite Hxy in Hyz.
  121. rewrite app_assoc in Hyz.
  122. rewrite Hyz.
  123. apply suffix_app_r.
  124. Qed.
  125.  
  126. Definition suffix (A:Set) (xs:list A) (ys:list A) := suffix_spec A xs ys /\ xs <> ys.
  127.  
  128. Theorem suffix_strict_trans : forall (A:Set), transitive (list A) (suffix A).
  129. Proof.
  130. unfold transitive.
  131. intros A xs ys zs [Hxy Hxyneq] [Hyz Hyzneq].
  132. unfold suffix in *.
  133. split.
  134. - exact (suffix_spec_trans A xs ys zs Hxy Hyz).
  135. - unfold not. intros.
  136. rewrite <- H in Hyz.
  137. assert (xs = ys).
  138. apply suffix_spec_antisymmetric; assumption.
  139. contradiction.
  140. Qed.
  141.  
  142. Lemma strict_acc_lemma: forall (A:Set) (ns xs:list A), suffix A xs ns -> Acc (suffix A) xs.
  143. Proof.
  144. induction ns.
  145. - intros. destruct H.
  146. apply suffix_nil_implies_nil in H.
  147. contradiction.
  148. - intros ys Hys. apply Acc_intro. intros zs Hzs.
  149. apply IHns.
  150.  
  151. destruct Hys.
  152. destruct Hzs.
  153. split.
  154. apply suffix_spec_trans with (ys); auto.
  155. inversion H.
  156. rewrite H4 in H0. exfalso. apply H0; auto. assumption.
  157. unfold not. intros.
  158. destruct (suffix_strict_or_same A ys ns a) ; auto.
  159. rewrite <- H3 in H4.
  160. apply H2.
  161. apply (suffix_spec_antisymmetric A zs ys H1 H4).
  162. Defined.
  163.  
  164. Lemma cons_neq : forall (A:Set) (x:A) xs, xs <> x::xs.
  165. Proof.
  166. induction xs as [|x' xs IHxs]; intro H.
  167. - apply (nil_cons H).
  168. - injection H; intros.
  169. rewrite H1 in H0.
  170. apply (IHxs H0).
  171. Qed.
  172.  
  173. Theorem suffix_wf (A:Set): well_founded (suffix A).
  174. Proof.
  175. unfold well_founded.
  176. intro xs. induction xs as [|x xs].
  177. - apply Acc_intro. intros.
  178. destruct H.
  179. apply suffix_nil_implies_nil in H.
  180. contradiction.
  181. - intros. apply (strict_acc_lemma A (x::x::xs)).
  182. split ; auto with suffix. intro. injection H. intros.
  183. apply (cons_neq A x xs). trivial.
  184. Defined.
Add Comment
Please, Sign In to add comment