7 | applicativeNum : Num a => Applicative f => Num (f a)
8 | applicativeNum = MkNum
9 | (\xs, ys => [| xs + ys |])
10 | (\xs, ys => [| xs * ys |])
11 | (\n => pure (fromInteger n))
20 | Num a => Num b => Num (a, b) where
21 | (lFst, lSnd) + (rFst, rSnd) = (lFst + rFst, lSnd + rSnd)
22 | (lFst, lSnd) * (rFst, rSnd) = (lFst * rFst, lSnd * rSnd)
23 | fromInteger x = (fromInteger x, fromInteger x)
26 | Num a => Num b => Num (DPair a (const b)) where
27 | (
lFst ** lSnd)
* (
rFst ** rSnd)
= (
lFst * rFst ** lSnd * rSnd)
28 | (
lFst ** lSnd)
+ (
rFst ** rSnd)
= (
lFst + rFst ** lSnd + rSnd)
29 | fromInteger x = (
fromInteger x ** fromInteger x)
33 | depFunNum : {k : Fin n -> Type} ->
34 | {ss : (i : Fin n) -> Num (k i)} ->
35 | Num ((i : Fin n) -> k i)
37 | (\s, t => \i => s i + t i)
38 | (\f, g => \i => f i * g i)
39 | (\n => \i => fromInteger n)
45 | applicativeNeg : Neg a => Applicative f => Neg (f a)
46 | applicativeNeg = MkNeg @{applicativeNum}
47 | (\fa => [| negate fa |])
48 | (\fx, fy => [| fx - fy |])
56 | Neg a => Neg b => Neg (a, b) where
57 | negate (lFst, lSnd) = (negate lFst, negate lSnd)
58 | (lFst, lSnd) - (rFst, rSnd) = (lFst - rFst, lSnd - rSnd)
61 | Neg a => Neg b => Neg (DPair a (const b)) where
62 | negate (
fst ** snd)
= (
negate fst ** negate snd)
63 | (
fst ** snd)
- (
rFst ** rSnd)
= (
fst - rFst ** snd - rSnd)
67 | depFunNeg : {k : Fin n -> Type} ->
68 | {ss : (i : Fin n) -> Neg (k i)} ->
69 | Neg ((i : Fin n) -> k i)
71 | (\s => \i => negate (s i))
72 | (\f, g => \i => f i - g i)
77 | applicativeAbs : Abs a => Applicative f => Abs (f a)
78 | applicativeAbs = MkAbs @{applicativeNum}
79 | (\fa => [| abs fa |])
86 | Abs a => Abs b => Abs (a, b) where
87 | abs (lFst, lSnd) = (abs lFst, abs lSnd)
90 | Abs a => Abs b => Abs (DPair a (const b)) where
91 | abs (
fst ** snd)
= (
abs fst ** abs snd)
93 | namespace FromDouble
96 | applicativeFromDouble : FromDouble a => Applicative f => FromDouble (f a)
97 | applicativeFromDouble = MkFromDouble (pure . fromDouble)
100 | FromDouble Unit where
104 | FromDouble a => FromDouble b => FromDouble (a, b) where
105 | fromDouble x = (fromDouble x, fromDouble x)
108 | FromDouble a => FromDouble b => FromDouble (DPair a (const b)) where
109 | fromDouble x = (
fromDouble x ** fromDouble x)
113 | depFunFromDouble : {k : Fin n -> Type} ->
114 | {ss : (i : Fin n) -> FromDouble (k i)} ->
115 | FromDouble ((i : Fin n) -> k i)
116 | depFunFromDouble = MkFromDouble
117 | (\s => \i => fromDouble s)
119 | namespace Fractional
122 | applicativeFractional : Fractional a => Applicative f => Fractional (f a)
123 | applicativeFractional = MkFractional @{applicativeNum}
124 | (\fx, fy => [| fx / fy |])
125 | (\x => [| recip x |])
128 | Fractional Unit where
132 | Fractional a => Fractional b => Fractional (a, b) where
133 | (lFst, lSnd) / (rFst, rSnd) = (lFst / rFst, lSnd / rSnd)
136 | Fractional a => Fractional b => Fractional (DPair a (const b)) where
137 | (
fst ** snd)
/ (
rFst ** rSnd)
= (
fst / rFst ** snd / rSnd)
148 | interface Num a => Exp a where
158 | minusInfinity = cast "-inf.0"
162 | applicativeExp : Exp a => Applicative f => Exp (f a)
163 | applicativeExp = MkExp @{applicativeNum}
164 | (\fa => [| exp fa |])
165 | (\fa => [| log fa |])
166 | (pure minusInfinity)
170 | interface Num a => Sqrt a where
176 | sqrt = Prelude.sqrt
180 | applicativeSqrt : Sqrt a => Applicative f => Sqrt (f a)
181 | applicativeSqrt = MkSqrt @{applicativeNum} (\fa => [| sqrt fa |])
188 | Sqrt a => Sqrt b => Sqrt (a, b) where
189 | sqrt (lFst, lSnd) = (sqrt lFst, sqrt lSnd)
192 | Sqrt a => Sqrt b => Sqrt (DPair a (const b)) where
193 | sqrt (
fst ** snd)
= (
sqrt fst ** sqrt snd)