Nat.agda 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. module Nat where
  2. data Rel (A : Set) : Set1 where
  3. rel : (A -> A -> Set) -> Rel A
  4. _is_than_ : {A : Set} -> A -> Rel A -> A -> Set
  5. x is rel f than y = f x y
  6. data Acc {A : Set} (less : Rel A) (x : A) : Set where
  7. acc : ((y : A) -> x is less than y -> Acc less y) -> Acc less x
  8. data WO {A : Set} (less : Rel A) : Set where
  9. wo : ((x : A) -> Acc less x) -> WO less
  10. data False : Set where
  11. data True : Set where
  12. tt : True
  13. data Nat : Set where
  14. Z : Nat
  15. S : Nat -> Nat
  16. data ∏ {A : Set} (f : A -> Set) : Set where
  17. ∏I : ((z : A) -> f z) -> ∏ f
  18. ltNat : Nat -> Nat -> Set
  19. ltNat Z Z = False
  20. ltNat Z (S n) = True
  21. ltNat (S m) (S n) = ltNat m n
  22. ltNat (S m) Z = False
  23. ltNatRel : Rel Nat
  24. ltNatRel = rel ltNat
  25. postulate woltNat : WO ltNatRel
  26. idN : Nat -> Nat
  27. idN x = x
  28. id : {A : Set} -> A -> A
  29. id x = x
  30. down1 : Nat -> Nat
  31. down1 Z = Z
  32. down1 (S n) = down1 n
  33. -- measure down1 = (woNat, id)
  34. -- For a function f : (x:A) -> B(x)
  35. -- f(p) = ... f(x1) ... f(x2)
  36. -- measure_set : Set
  37. -- measure_rel : Rel measure_set
  38. -- measure_ord : WO measure_rel
  39. -- measure_fun : A -> measure_set
  40. -- For j-th call of f in i-th clause of f:
  41. -- measure_i_j_hint : xj is measure_rel than p
  42. data Measure : Set1 where
  43. μ : {M : Set} -> {rel : Rel M} -> (ord : WO rel) -> Measure
  44. {-
  45. down1_measure_set : Set
  46. down1_measure_set = Nat
  47. down1_measure_rel : Rel down1_measure_set
  48. down1_measure_rel = ltNatRel
  49. down1_measure_ord : WO measure_rel
  50. down1_measure_ord = woltNat
  51. -}
  52. down1-measure : Measure
  53. down1-measure = μ woltNat
  54. down1-2-1-hint : (n : Nat) -> n is ltNatRel than (S n)
  55. down1-2-1-hint Z = tt
  56. down1-2-1-hint (S n) = down1-2-1-hint n
  57. {-
  58. down2 : Nat -> Nat
  59. down2 Z = Z
  60. down2 (S n) = down2 (idN n)
  61. down3 : Nat -> Nat
  62. down3 Z = Z
  63. down3 (S n) = down3 (id n)
  64. plus : Nat -> Nat -> Nat
  65. plus Z n = n
  66. plus (S m) n = S(plus m n)
  67. -}