Advertisement
Guest User

Untitled

a guest
Mar 1st, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 3.05 KB | None | 0 0
  1. Require Import Coq.Program.Tactics.
  2.  
  3. Inductive A :=
  4.   | init : A
  5.   | ofB : B -> A
  6.   | op : A -> A
  7. with B :=
  8.   | ofA : A -> B
  9.   | liftedOp : B -> B
  10. .
  11.  
  12. Notation "'liftedOp b" := (ofA (op (ofB b))) (at level 0).
  13.  
  14. Fixpoint sizeA a :=
  15.   match a with
  16.   | init => 1
  17.   | ofB b => 1 + sizeB b
  18.   | op a' => 1 + sizeA a'
  19.   end
  20. with sizeB b :=
  21.   match b with
  22.   | ofA a => 1 + sizeA a
  23.   | liftedOp b' => (* 1 + sizeB ('liftedOp b) = *) 4 + sizeB b'
  24.   end
  25. .
  26.  
  27. Lemma sizeOk : forall b, sizeB ('liftedOp b) < sizeB (liftedOp b).
  28. firstorder.
  29. Qed.
  30.  
  31. (*
  32. Fixpoint fA (a : A) : unit
  33. with fB (b : B) : unit.
  34. - pose (a' := a).
  35.   destruct a.
  36.   + exact tt.
  37.   + exact (fB b).
  38.   + exact (fA a).
  39. - pose (b' := b).
  40.   destruct b.
  41.   + exact (fA a).
  42.   + exact (fB ('liftedOp b)).
  43. (* Error:
  44. Error:
  45. Recursive definition of fB is ill-formed.
  46. In environment
  47. fA : A -> unit
  48. fB : B -> unit
  49. b : B
  50. b0 : B
  51. Recursive call to fB has principal argument equal to "'liftedOp (b0)" instead
  52. of "b0".
  53. Recursive definition is:
  54. "fun b : B =>
  55.  let b' := b in
  56.  match b as b0 return (let b'0 := b0 in unit) with
  57.  | ofA a => let b'0 := ofA a in fA a
  58.  | liftedOp b0 => let b'0 := liftedOp b0 in fB 'liftedOp (b0)
  59.  end".
  60. *)
  61. Defined.
  62. *)
  63.  
  64.  
  65.  
  66. (*
  67. (* Error: Only structural decreasing is supported for a non-Program Fixpoint *)
  68. Fixpoint fA (a : A) {measure (sizeA a)} : unit
  69. with fB (b : B) {measure (sizeB b)} : unit.
  70. - pose (a' := a).
  71.   destruct a.
  72.   + exact tt.
  73.   + exact (fB b).
  74.   + exact (fA a).
  75. - pose (b' := b).
  76.   destruct b.
  77.   + exact (fA a).
  78.   + exact (fB ('liftedOp b)).
  79. Defined.
  80. *)
  81.  
  82.  
  83.  
  84. (*
  85. Program Fixpoint fA (a : A) : unit := _
  86. with fB (b : B) : unit := _.
  87. Obligation 1 of fA.
  88. - pose (a' := a).
  89.   destruct a.
  90.   + exact tt.
  91.   (* Error: The reference fB was not found in the current environment. *)
  92.   + exact (fB b).
  93.   + exact (fA a).
  94. Obligation 1 of fB.
  95. - pose (b' := b).
  96.   destruct b.
  97.   + exact (fA a).
  98.   + exact (fB ('liftedOp b)).
  99. Defined.
  100. *)
  101.  
  102.  
  103.  
  104. (*
  105. (* Error: Well-founded fixpoints not allowed in mutually recursive blocks *)
  106. Program Fixpoint fA (a : A) {measure (sizeA a)} : unit := _
  107. with fB (b : B) {measure (sizeB b)} : unit := _.
  108. Obligation 1 of fA.
  109. - pose (a' := a).
  110.   destruct a.
  111.   + exact tt.
  112.   + exact (fB b).
  113.   + exact (fA a).
  114. Obligation 1 of fB.
  115. - pose (b' := b).
  116.   destruct b.
  117.   + exact (fA a).
  118.   + exact (fB ('liftedOp b)).
  119. Defined.
  120. *)
  121.  
  122.  
  123.  
  124.  
  125.  
  126. (* Of course, I can just give the size as an argument and then it works.
  127. But this is already annoying in this case and in the general case,
  128. I'd need the "size" to be a tree (with the same arities as the arities
  129. of my constructors)... *)
  130.  
  131. Fixpoint fA (a : A) {sa} {Hsa : sa = sizeA a} : unit
  132. with fB (b : B) {sb} {Hsb : sb = sizeB b} : unit.
  133. - pose (a' := a).
  134.   destruct a; destruct sa; try discriminate; simpl in Hsa; injection Hsa as Hsa'.
  135.   + exact tt.
  136.   + exact (fB b sa Hsa').
  137.   + exact (fA a sa Hsa').
  138. - pose (b' := b).
  139.   destruct b; destruct sb; try discriminate; simpl in Hsb; injection Hsb as Hsb'.
  140.   + exact (fA a sb Hsb').
  141.   + exact (fB ('liftedOp b) sb Hsb').
  142. Defined.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement