Complete.agda 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. module Data.Real.Complete where
  2. import Prelude
  3. import Data.Real.Gauge
  4. import Data.Rational
  5. open Prelude
  6. open Data.Real.Gauge
  7. open Data.Rational
  8. Complete : Set -> Set
  9. Complete A = Gauge -> A
  10. unit : {A : Set} -> A -> Complete A
  11. unit x ε = x
  12. join : {A : Set} -> Complete (Complete A) -> Complete A
  13. join f ε = f ε2 ε2
  14. where
  15. ε2 = ε / fromNat 2
  16. infixr 10 _==>_
  17. data _==>_ (A B : Set) : Set where
  18. uniformCts : (Gauge -> Gauge) -> (A -> B) -> A ==> B
  19. modulus : {A B : Set} -> (A ==> B) -> Gauge -> Gauge
  20. modulus (uniformCts μ _) = μ
  21. forgetUniformCts : {A B : Set} -> (A ==> B) -> A -> B
  22. forgetUniformCts (uniformCts _ f) = f
  23. mapC : {A B : Set} -> (A ==> B) -> Complete A -> Complete B
  24. mapC (uniformCts μ f) x ε = f (x (μ ε))
  25. bind : {A B : Set} -> (A ==> Complete B) -> Complete A -> Complete B
  26. bind f x = join $ mapC f x
  27. mapC2 : {A B C : Set} -> (A ==> B ==> C) -> Complete A -> Complete B -> Complete C
  28. mapC2 f x y ε = mapC ≈fx y ε2
  29. where
  30. ε2 = ε / fromNat 2
  31. ≈fx = mapC f x ε2
  32. _○_ : {A B C : Set} -> (B ==> C) -> (A ==> B) -> A ==> C
  33. f ○ g = uniformCts μ h
  34. where
  35. μ = modulus f ∘ modulus g
  36. h = forgetUniformCts f ∘ forgetUniformCts g
  37. constCts : {A B : Set} -> A -> B ==> A
  38. constCts a = uniformCts (const $ fromNat 1) (const a)