2014-05-28 20:10:44 +04:00
|
|
|
module Main
|
|
|
|
|
2014-05-28 21:05:57 +04:00
|
|
|
%default total
|
|
|
|
|
|
|
|
-- An expensive function.
|
2014-05-28 20:10:44 +04:00
|
|
|
qib : Nat -> Nat
|
2014-05-29 16:40:08 +04:00
|
|
|
qib Z = 1
|
2014-05-28 21:05:57 +04:00
|
|
|
qib (S Z) = 2
|
2014-05-28 20:10:44 +04:00
|
|
|
qib (S (S n)) = qib n * qib (S n)
|
|
|
|
|
2014-05-28 21:05:57 +04:00
|
|
|
-- An equality whose size reflects the size of numbers.
|
|
|
|
data equals : Nat -> Nat -> Type where
|
|
|
|
eqZ : Z `equals` Z
|
|
|
|
eqS : m `equals` n -> S m `equals` S n
|
|
|
|
|
|
|
|
eq_refl : {n : Nat} -> n `equals` n
|
|
|
|
eq_refl {n = Z} = eqZ
|
|
|
|
eq_refl {n = S n} = eqS eq_refl
|
|
|
|
|
|
|
|
-- Here, the proof is very expensive to compute.
|
2014-05-29 16:40:08 +04:00
|
|
|
-- We add a recursive argument to prevent Idris from inlining the function.
|
2014-05-28 21:05:57 +04:00
|
|
|
f : (r, n : Nat) -> Subset Nat (\k => qib n `equals` qib k)
|
2014-09-25 22:34:35 +04:00
|
|
|
f Z n = Element n eq_refl
|
2014-05-28 21:05:57 +04:00
|
|
|
f (S r) n = f r n
|
|
|
|
|
2014-05-29 16:40:08 +04:00
|
|
|
-- A (contrived) relation, just to have something to show.
|
|
|
|
data represents : Nat -> Nat -> Type where
|
|
|
|
axiom : (n : Nat) -> qib n `represents` n
|
|
|
|
|
2014-05-28 21:05:57 +04:00
|
|
|
-- Here, the witness is very expensive to compute.
|
2014-05-29 16:40:08 +04:00
|
|
|
-- We add a recursive argument to prevent Idris from inlining the function.
|
|
|
|
g : (r, n : Nat) -> Exists (\k : Nat => k `represents` n)
|
2014-09-25 22:34:35 +04:00
|
|
|
g Z n = Evidence (qib n) (axiom n)
|
2014-05-28 21:05:57 +04:00
|
|
|
g (S r) n = g r n
|
|
|
|
|
2014-05-29 16:40:08 +04:00
|
|
|
fmt : qib n `represents` n -> String
|
|
|
|
fmt (axiom n) = "axiom " ++ show n
|
2014-05-28 20:10:44 +04:00
|
|
|
|
|
|
|
main : IO ()
|
2014-05-28 21:05:57 +04:00
|
|
|
main = do
|
2015-04-03 13:48:04 +03:00
|
|
|
n <- map (const (the Nat 10000)) (putStrLn "*oink*")
|
2014-05-29 16:40:08 +04:00
|
|
|
putStrLn . show $ getWitness (f 4 n)
|
|
|
|
putStrLn . fmt $ getProof (g 4 n)
|