Guest User

Untitled

a guest
Oct 22nd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.23 KB | None | 0 0
  1. From Equations Require Import Equations.
  2. Require Import Equations.Subterm.
  3. Require Import Lia.
  4.  
  5. Section Tests.
  6.  
  7. Variable A : Type.
  8.  
  9. Inductive forest : Type :=
  10. | emp : A -> forest
  11. | tree : list forest -> forest.
  12.  
  13. Equations fweight (f : forest) : nat :=
  14. {
  15. fweight emp := 1;
  16. fweight (tree l) := 1 + lweight l
  17. }
  18. where lweight (l : list forest) : nat :=
  19. {
  20. lweight nil := 1;
  21. lweight (cons f l') := fweight f + lweight l'
  22. }.
  23.  
  24.  
  25. Fail Equations flatten (f : forest) : list A :=
  26. {
  27. flatten f by rec (fweight f) lt :=
  28. flatten emp := nil;
  29. flatten (tree l) := lflatten l
  30. }
  31. where lflatten (l : list forest) : list A :=
  32. {
  33. lflatten nil := nil;
  34. lflatten (cons f l') := flatten f ++ lflatten l'
  35. }.
  36. (* The command has indeed failed with message: *)
  37. (* The variable lflatten was not found in the current environment. *)
  38.  
  39. Inductive tail_of {A} : list A -> list A -> Prop :=
  40. | t_refl : forall l, tail_of l l
  41. | t_cons : forall x l1 l2, tail_of l1 l2 -> tail_of l1 (cons x l2).
  42. Hint Constructors tail_of.
  43.  
  44. Lemma tail_of_decons : forall {A} {x : A} {l1 l2},
  45. tail_of (cons x l1) l2 ->
  46. tail_of l1 l2.
  47. Proof.
  48. intros. remember (cons x l1) as l.
  49. revert Heql. revert l1.
  50. induction H; intros; subst; auto.
  51. Qed.
  52.  
  53. Lemma fweight_neq_0 : forall f, fweight f <> 0.
  54. Proof.
  55. intros.
  56. destruct f.
  57. Fail funelim (fweight (emp a)).
  58.  
  59. Restart.
  60.  
  61. intros. destruct f; simp fweight; lia.
  62. Qed.
  63.  
  64. Lemma lweight_neq_0 : forall l, lweight l <> 0.
  65. Proof.
  66. intros. destruct l; simpl.
  67. lia.
  68. pose proof (fweight_neq_0 f). lia.
  69. Qed.
  70.  
  71. Lemma tail_of_fweight : forall l1 l2,
  72. tail_of l1 l2 ->
  73. lweight l1 <= lweight l2.
  74. Proof.
  75. induction 1; simp lweight; try lia.
  76. simpl. pose proof (fweight_neq_0 x).
  77. lia.
  78. Qed.
  79.  
  80. Equations flatten (f : forest) : list A :=
  81. {
  82. flatten f by rec (fweight f) lt :=
  83. flatten emp := nil;
  84. flatten (tree l) :=
  85. let fix func (fs : list forest) (t : tail_of fs l) : list A :=
  86. match fs as fs0 return tail_of fs0 l -> list A with
  87. | nil => fun _ => nil
  88. | cons f fs' =>
  89. fun t' => app (flatten f) (func fs' (tail_of_decons t'))
  90. end t in
  91. func l (t_refl _)
  92. }.
  93. Next Obligation.
  94. apply tail_of_fweight in t'.
  95. simpl in t'.
  96. pose proof (lweight_neq_0 fs').
  97. simp fweight. lia.
  98. Fail Qed.
  99.  
  100. (* flatten_obligation_1 is defined *)
  101. (* No more obligations remaining *)
  102. (* The command has indeed failed with message: *)
  103. (* Recursive definition of func is ill-formed. *)
  104. (* In environment *)
  105. (* A : Type *)
  106. (* f : forest *)
  107. (* hypspack := {| pr1 := f; pr2 := () |} : sigma forest (fun _ : forest => ()) *)
  108. (* pack := fweight f : nat *)
  109. (* hypspack0 : sigma forest (fun _ : forest => ()) *)
  110. (* _tmp := fweight (pr1 hypspack0) : nat *)
  111. (* H : sigma forest (fun _ : forest => ()) *)
  112. (* X : *)
  113. (* forall y : sigma forest (fun _ : forest => ()), *)
  114. (* MR lt (fun hypspack : sigma forest (fun _ : forest => ()) => fweight (pr1 hypspack)) y H -> list A *)
  115. (* f0 : forest *)
  116. (* H0 : () *)
  117. (* flatten : *)
  118. (* forall y : sigma forest (fun _ : forest => ()), *)
  119. (* fweight (pr1 y) < fweight (pr1 {| pr1 := f0; pr2 := H0 |}) -> list A *)
  120. (* flatten0 := fun f : forest => flatten {| pr1 := f; pr2 := () |} : *)
  121. (* forall f : forest, fweight (pr1 {| pr1 := f; pr2 := () |}) < fweight f0 -> list A *)
  122. (* f1 : forest *)
  123. (* flatten1 : forall f : forest, fweight f < fweight f1 -> list A *)
  124. (* l : list forest *)
  125. (* flatten2 : forall f : forest, fweight f < fweight (tree l) -> list A *)
  126. (* func : forall fs : list forest, tail_of fs l -> list A *)
  127. (* fs : list forest *)
  128. (* t : tail_of fs l *)
  129. (* f2 : forest *)
  130. (* fs' : list forest *)
  131. (* t' : tail_of (f2 :: fs') l *)
  132. (* Recursive call to func has not enough arguments. *)
  133. (* Recursive definition is: *)
  134. (* "fun (fs : list forest) (t : tail_of fs l) => *)
  135. (* match fs as fs0 return (tail_of fs0 l -> list A) with *)
  136. (* | []%list => fun _ : tail_of [] l => []%list *)
  137. (* | (f :: fs')%list => *)
  138. (* fun t' : tail_of (f :: fs') l => *)
  139. (* (flatten_comp_proj f (flatten2 f (flatten_obligation_1 l flatten2 func fs t f fs' t')) ++ *)
  140. (* func fs' (tail_of_decons t'))%list *)
  141. (* end t". *)
  142.  
  143. End Tests.
Add Comment
Please, Sign In to add comment