SizedNatAnnotated.agda 653 B

12345678910111213141516171819202122
  1. {-# OPTIONS --sized-types --show-implicit #-}
  2. module Termination.Sized.SizedNatAnnotated where
  3. open import Size
  4. data Nat : {i : Size} -> Set where
  5. zero : {i : Size} -> Nat {↑ i}
  6. suc : {i : Size} -> Nat {i} -> Nat {↑ i}
  7. -- subtraction is non size increasing
  8. sub : {i : Size} -> Nat {i} -> Nat {∞} -> Nat {i}
  9. sub .{↑ i} (zero {i}) n = zero {i}
  10. sub .{↑ i} (suc {i} m) zero = suc {i} m
  11. sub .{↑ i} (suc {i} m) (suc n) = sub {i} m n
  12. -- div' m n computes ceiling(m/(n+1))
  13. div' : {i : Size} -> Nat {i} -> Nat -> Nat {i}
  14. div' .{↑ i} (zero {i}) n = zero {i}
  15. div' .{↑ i} (suc {i} m) n = suc {i} (div' {i} (sub {i} m n) n)