{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{- |
A wrapper that provides instances of Haskell 98 and NumericPrelude
numeric type classes
for types that have Haskell 98 instances.
-}
module MathObj.Wrapper.Haskell98 where

import qualified Algebra.Absolute as Absolute
import qualified Algebra.Additive as Additive
import qualified Algebra.Algebraic as Algebraic
import qualified Algebra.Field as Field
import qualified Algebra.FloatingPoint as Float
import qualified Algebra.IntegralDomain as Integral
import qualified Algebra.PrincipalIdealDomain as PID
import qualified Algebra.RealField as RealField
import qualified Algebra.RealIntegral as RealIntegral
import qualified Algebra.RealRing as RealRing
import qualified Algebra.RealTranscendental as RealTrans
import qualified Algebra.Ring as Ring
import qualified Algebra.ToInteger as ToInteger
import qualified Algebra.ToRational as ToRational
import qualified Algebra.Transcendental as Trans
import qualified Algebra.Units as Units
import qualified Algebra.ZeroTestable as ZeroTestable

import qualified Number.Ratio as Ratio

import qualified Algebra.RealRing98 as RealRing98

import Data.Ix (Ix, )

import Data.Tuple.HT (mapPair, )


{- |
This makes a type usable in the NumericPrelude framework
that was initially implemented for Haskell98 typeclasses.
E.g. if @a@ is in class 'Num',
then @T a@ is both in class 'Num' and in 'Ring.C'.

You can even lift container types.
If @Polynomial a@ is in 'Num' for all types @a@ that are in 'Num',
then @T (Polynomial (MathObj.Wrapper.NumericPrelude.T a))@
is in 'Ring.C' for all types @a@ that are in 'Ring.C'.
-}
newtype T a = Cons {T a -> a
decons :: a}
   deriving
      (Int -> T a -> ShowS
[T a] -> ShowS
T a -> String
(Int -> T a -> ShowS)
-> (T a -> String) -> ([T a] -> ShowS) -> Show (T a)
forall a. Show a => Int -> T a -> ShowS
forall a. Show a => [T a] -> ShowS
forall a. Show a => T a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [T a] -> ShowS
$cshowList :: forall a. Show a => [T a] -> ShowS
show :: T a -> String
$cshow :: forall a. Show a => T a -> String
showsPrec :: Int -> T a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> T a -> ShowS
Show, T a -> T a -> Bool
(T a -> T a -> Bool) -> (T a -> T a -> Bool) -> Eq (T a)
forall a. Eq a => T a -> T a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: T a -> T a -> Bool
$c/= :: forall a. Eq a => T a -> T a -> Bool
== :: T a -> T a -> Bool
$c== :: forall a. Eq a => T a -> T a -> Bool
Eq, Eq (T a)
Eq (T a)
-> (T a -> T a -> Ordering)
-> (T a -> T a -> Bool)
-> (T a -> T a -> Bool)
-> (T a -> T a -> Bool)
-> (T a -> T a -> Bool)
-> (T a -> T a -> T a)
-> (T a -> T a -> T a)
-> Ord (T a)
T a -> T a -> Bool
T a -> T a -> Ordering
T a -> T a -> T a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (T a)
forall a. Ord a => T a -> T a -> Bool
forall a. Ord a => T a -> T a -> Ordering
forall a. Ord a => T a -> T a -> T a
min :: T a -> T a -> T a
$cmin :: forall a. Ord a => T a -> T a -> T a
max :: T a -> T a -> T a
$cmax :: forall a. Ord a => T a -> T a -> T a
>= :: T a -> T a -> Bool
$c>= :: forall a. Ord a => T a -> T a -> Bool
> :: T a -> T a -> Bool
$c> :: forall a. Ord a => T a -> T a -> Bool
<= :: T a -> T a -> Bool
$c<= :: forall a. Ord a => T a -> T a -> Bool
< :: T a -> T a -> Bool
$c< :: forall a. Ord a => T a -> T a -> Bool
compare :: T a -> T a -> Ordering
$ccompare :: forall a. Ord a => T a -> T a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (T a)
Ord, Ord (T a)
Ord (T a)
-> ((T a, T a) -> [T a])
-> ((T a, T a) -> T a -> Int)
-> ((T a, T a) -> T a -> Int)
-> ((T a, T a) -> T a -> Bool)
-> ((T a, T a) -> Int)
-> ((T a, T a) -> Int)
-> Ix (T a)
(T a, T a) -> Int
(T a, T a) -> [T a]
(T a, T a) -> T a -> Bool
(T a, T a) -> T a -> Int
forall a.
Ord a
-> ((a, a) -> [a])
-> ((a, a) -> a -> Int)
-> ((a, a) -> a -> Int)
-> ((a, a) -> a -> Bool)
-> ((a, a) -> Int)
-> ((a, a) -> Int)
-> Ix a
forall a. Ix a => Ord (T a)
forall a. Ix a => (T a, T a) -> Int
forall a. Ix a => (T a, T a) -> [T a]
forall a. Ix a => (T a, T a) -> T a -> Bool
forall a. Ix a => (T a, T a) -> T a -> Int
unsafeRangeSize :: (T a, T a) -> Int
$cunsafeRangeSize :: forall a. Ix a => (T a, T a) -> Int
rangeSize :: (T a, T a) -> Int
$crangeSize :: forall a. Ix a => (T a, T a) -> Int
inRange :: (T a, T a) -> T a -> Bool
$cinRange :: forall a. Ix a => (T a, T a) -> T a -> Bool
unsafeIndex :: (T a, T a) -> T a -> Int
$cunsafeIndex :: forall a. Ix a => (T a, T a) -> T a -> Int
index :: (T a, T a) -> T a -> Int
$cindex :: forall a. Ix a => (T a, T a) -> T a -> Int
range :: (T a, T a) -> [T a]
$crange :: forall a. Ix a => (T a, T a) -> [T a]
$cp1Ix :: forall a. Ix a => Ord (T a)
Ix, T a
T a -> T a -> Bounded (T a)
forall a. a -> a -> Bounded a
forall a. Bounded a => T a
maxBound :: T a
$cmaxBound :: forall a. Bounded a => T a
minBound :: T a
$cminBound :: forall a. Bounded a => T a
Bounded, Int -> T a
T a -> Int
T a -> [T a]
T a -> T a
T a -> T a -> [T a]
T a -> T a -> T a -> [T a]
(T a -> T a)
-> (T a -> T a)
-> (Int -> T a)
-> (T a -> Int)
-> (T a -> [T a])
-> (T a -> T a -> [T a])
-> (T a -> T a -> [T a])
-> (T a -> T a -> T a -> [T a])
-> Enum (T a)
forall a. Enum a => Int -> T a
forall a. Enum a => T a -> Int
forall a. Enum a => T a -> [T a]
forall a. Enum a => T a -> T a
forall a. Enum a => T a -> T a -> [T a]
forall a. Enum a => T a -> T a -> T a -> [T a]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: T a -> T a -> T a -> [T a]
$cenumFromThenTo :: forall a. Enum a => T a -> T a -> T a -> [T a]
enumFromTo :: T a -> T a -> [T a]
$cenumFromTo :: forall a. Enum a => T a -> T a -> [T a]
enumFromThen :: T a -> T a -> [T a]
$cenumFromThen :: forall a. Enum a => T a -> T a -> [T a]
enumFrom :: T a -> [T a]
$cenumFrom :: forall a. Enum a => T a -> [T a]
fromEnum :: T a -> Int
$cfromEnum :: forall a. Enum a => T a -> Int
toEnum :: Int -> T a
$ctoEnum :: forall a. Enum a => Int -> T a
pred :: T a -> T a
$cpred :: forall a. Enum a => T a -> T a
succ :: T a -> T a
$csucc :: forall a. Enum a => T a -> T a
Enum,
       Integer -> T a
T a -> T a
T a -> T a -> T a
(T a -> T a -> T a)
-> (T a -> T a -> T a)
-> (T a -> T a -> T a)
-> (T a -> T a)
-> (T a -> T a)
-> (T a -> T a)
-> (Integer -> T a)
-> Num (T a)
forall a. Num a => Integer -> T a
forall a. Num a => T a -> T a
forall a. Num a => T a -> T a -> T a
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
fromInteger :: Integer -> T a
$cfromInteger :: forall a. Num a => Integer -> T a
signum :: T a -> T a
$csignum :: forall a. Num a => T a -> T a
abs :: T a -> T a
$cabs :: forall a. Num a => T a -> T a
negate :: T a -> T a
$cnegate :: forall a. Num a => T a -> T a
* :: T a -> T a -> T a
$c* :: forall a. Num a => T a -> T a -> T a
- :: T a -> T a -> T a
$c- :: forall a. Num a => T a -> T a -> T a
+ :: T a -> T a -> T a
$c+ :: forall a. Num a => T a -> T a -> T a
Num, Enum (T a)
Real (T a)
Real (T a)
-> Enum (T a)
-> (T a -> T a -> T a)
-> (T a -> T a -> T a)
-> (T a -> T a -> T a)
-> (T a -> T a -> T a)
-> (T a -> T a -> (T a, T a))
-> (T a -> T a -> (T a, T a))
-> (T a -> Integer)
-> Integral (T a)
T a -> Integer
T a -> T a -> (T a, T a)
T a -> T a -> T a
forall a. Integral a => Enum (T a)
forall a. Integral a => Real (T a)
forall a. Integral a => T a -> Integer
forall a. Integral a => T a -> T a -> (T a, T a)
forall a. Integral a => T a -> T a -> T a
forall a.
Real a
-> Enum a
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> (a, a))
-> (a -> a -> (a, a))
-> (a -> Integer)
-> Integral a
toInteger :: T a -> Integer
$ctoInteger :: forall a. Integral a => T a -> Integer
divMod :: T a -> T a -> (T a, T a)
$cdivMod :: forall a. Integral a => T a -> T a -> (T a, T a)
quotRem :: T a -> T a -> (T a, T a)
$cquotRem :: forall a. Integral a => T a -> T a -> (T a, T a)
mod :: T a -> T a -> T a
$cmod :: forall a. Integral a => T a -> T a -> T a
div :: T a -> T a -> T a
$cdiv :: forall a. Integral a => T a -> T a -> T a
rem :: T a -> T a -> T a
$crem :: forall a. Integral a => T a -> T a -> T a
quot :: T a -> T a -> T a
$cquot :: forall a. Integral a => T a -> T a -> T a
$cp2Integral :: forall a. Integral a => Enum (T a)
$cp1Integral :: forall a. Integral a => Real (T a)
Integral, Num (T a)
Num (T a)
-> (T a -> T a -> T a)
-> (T a -> T a)
-> (Rational -> T a)
-> Fractional (T a)
Rational -> T a
T a -> T a
T a -> T a -> T a
forall a. Fractional a => Num (T a)
forall a. Fractional a => Rational -> T a
forall a. Fractional a => T a -> T a
forall a. Fractional a => T a -> T a -> T a
forall a.
Num a
-> (a -> a -> a) -> (a -> a) -> (Rational -> a) -> Fractional a
fromRational :: Rational -> T a
$cfromRational :: forall a. Fractional a => Rational -> T a
recip :: T a -> T a
$crecip :: forall a. Fractional a => T a -> T a
/ :: T a -> T a -> T a
$c/ :: forall a. Fractional a => T a -> T a -> T a
$cp1Fractional :: forall a. Fractional a => Num (T a)
Fractional, Fractional (T a)
T a
Fractional (T a)
-> T a
-> (T a -> T a)
-> (T a -> T a)
-> (T a -> T a)
-> (T a -> T a -> T a)
-> (T a -> T a -> T a)
-> (T a -> T a)
-> (T a -> T a)
-> (T a -> T a)
-> (T a -> T a)
-> (T a -> T a)
-> (T a -> T a)
-> (T a -> T a)
-> (T a -> T a)
-> (T a -> T a)
-> (T a -> T a)
-> (T a -> T a)
-> (T a -> T a)
-> (T a -> T a)
-> (T a -> T a)
-> (T a -> T a)
-> (T a -> T a)
-> Floating (T a)
T a -> T a
T a -> T a -> T a
forall a. Floating a => Fractional (T a)
forall a. Floating a => T a
forall a. Floating a => T a -> T a
forall a. Floating a => T a -> T a -> T a
forall a.
Fractional a
-> a
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> Floating a
log1mexp :: T a -> T a
$clog1mexp :: forall a. Floating a => T a -> T a
log1pexp :: T a -> T a
$clog1pexp :: forall a. Floating a => T a -> T a
expm1 :: T a -> T a
$cexpm1 :: forall a. Floating a => T a -> T a
log1p :: T a -> T a
$clog1p :: forall a. Floating a => T a -> T a
atanh :: T a -> T a
$catanh :: forall a. Floating a => T a -> T a
acosh :: T a -> T a
$cacosh :: forall a. Floating a => T a -> T a
asinh :: T a -> T a
$casinh :: forall a. Floating a => T a -> T a
tanh :: T a -> T a
$ctanh :: forall a. Floating a => T a -> T a
cosh :: T a -> T a
$ccosh :: forall a. Floating a => T a -> T a
sinh :: T a -> T a
$csinh :: forall a. Floating a => T a -> T a
atan :: T a -> T a
$catan :: forall a. Floating a => T a -> T a
acos :: T a -> T a
$cacos :: forall a. Floating a => T a -> T a
asin :: T a -> T a
$casin :: forall a. Floating a => T a -> T a
tan :: T a -> T a
$ctan :: forall a. Floating a => T a -> T a
cos :: T a -> T a
$ccos :: forall a. Floating a => T a -> T a
sin :: T a -> T a
$csin :: forall a. Floating a => T a -> T a
logBase :: T a -> T a -> T a
$clogBase :: forall a. Floating a => T a -> T a -> T a
** :: T a -> T a -> T a
$c** :: forall a. Floating a => T a -> T a -> T a
sqrt :: T a -> T a
$csqrt :: forall a. Floating a => T a -> T a
log :: T a -> T a
$clog :: forall a. Floating a => T a -> T a
exp :: T a -> T a
$cexp :: forall a. Floating a => T a -> T a
pi :: T a
$cpi :: forall a. Floating a => T a
$cp1Floating :: forall a. Floating a => Fractional (T a)
Floating,
       Num (T a)
Ord (T a)
Num (T a) -> Ord (T a) -> (T a -> Rational) -> Real (T a)
T a -> Rational
forall a. Num a -> Ord a -> (a -> Rational) -> Real a
forall a. Real a => Num (T a)
forall a. Real a => Ord (T a)
forall a. Real a => T a -> Rational
toRational :: T a -> Rational
$ctoRational :: forall a. Real a => T a -> Rational
$cp2Real :: forall a. Real a => Ord (T a)
$cp1Real :: forall a. Real a => Num (T a)
Real, Fractional (T a)
Real (T a)
Real (T a)
-> Fractional (T a)
-> (forall b. Integral b => T a -> (b, T a))
-> (forall b. Integral b => T a -> b)
-> (forall b. Integral b => T a -> b)
-> (forall b. Integral b => T a -> b)
-> (forall b. Integral b => T a -> b)
-> RealFrac (T a)
T a -> b
T a -> b
T a -> b
T a -> b
T a -> (b, T a)
forall b. Integral b => T a -> b
forall b. Integral b => T a -> (b, T a)
forall a.
Real a
-> Fractional a
-> (forall b. Integral b => a -> (b, a))
-> (forall b. Integral b => a -> b)
-> (forall b. Integral b => a -> b)
-> (forall b. Integral b => a -> b)
-> (forall b. Integral b => a -> b)
-> RealFrac a
forall a. RealFrac a => Fractional (T a)
forall a. RealFrac a => Real (T a)
forall a b. (RealFrac a, Integral b) => T a -> b
forall a b. (RealFrac a, Integral b) => T a -> (b, T a)
floor :: T a -> b
$cfloor :: forall a b. (RealFrac a, Integral b) => T a -> b
ceiling :: T a -> b
$cceiling :: forall a b. (RealFrac a, Integral b) => T a -> b
round :: T a -> b
$cround :: forall a b. (RealFrac a, Integral b) => T a -> b
truncate :: T a -> b
$ctruncate :: forall a b. (RealFrac a, Integral b) => T a -> b
properFraction :: T a -> (b, T a)
$cproperFraction :: forall a b. (RealFrac a, Integral b) => T a -> (b, T a)
$cp2RealFrac :: forall a. RealFrac a => Fractional (T a)
$cp1RealFrac :: forall a. RealFrac a => Real (T a)
RealFrac, Floating (T a)
RealFrac (T a)
RealFrac (T a)
-> Floating (T a)
-> (T a -> Integer)
-> (T a -> Int)
-> (T a -> (Int, Int))
-> (T a -> (Integer, Int))
-> (Integer -> Int -> T a)
-> (T a -> Int)
-> (T a -> T a)
-> (Int -> T a -> T a)
-> (T a -> Bool)
-> (T a -> Bool)
-> (T a -> Bool)
-> (T a -> Bool)
-> (T a -> Bool)
-> (T a -> T a -> T a)
-> RealFloat (T a)
Int -> T a -> T a
Integer -> Int -> T a
T a -> Bool
T a -> Int
T a -> Integer
T a -> (Int, Int)
T a -> (Integer, Int)
T a -> T a
T a -> T a -> T a
forall a. RealFloat a => Floating (T a)
forall a. RealFloat a => RealFrac (T a)
forall a. RealFloat a => Int -> T a -> T a
forall a. RealFloat a => Integer -> Int -> T a
forall a. RealFloat a => T a -> Bool
forall a. RealFloat a => T a -> Int
forall a. RealFloat a => T a -> Integer
forall a. RealFloat a => T a -> (Int, Int)
forall a. RealFloat a => T a -> (Integer, Int)
forall a. RealFloat a => T a -> T a
forall a. RealFloat a => T a -> T a -> T a
forall a.
RealFrac a
-> Floating a
-> (a -> Integer)
-> (a -> Int)
-> (a -> (Int, Int))
-> (a -> (Integer, Int))
-> (Integer -> Int -> a)
-> (a -> Int)
-> (a -> a)
-> (Int -> a -> a)
-> (a -> Bool)
-> (a -> Bool)
-> (a -> Bool)
-> (a -> Bool)
-> (a -> Bool)
-> (a -> a -> a)
-> RealFloat a
atan2 :: T a -> T a -> T a
$catan2 :: forall a. RealFloat a => T a -> T a -> T a
isIEEE :: T a -> Bool
$cisIEEE :: forall a. RealFloat a => T a -> Bool
isNegativeZero :: T a -> Bool
$cisNegativeZero :: forall a. RealFloat a => T a -> Bool
isDenormalized :: T a -> Bool
$cisDenormalized :: forall a. RealFloat a => T a -> Bool
isInfinite :: T a -> Bool
$cisInfinite :: forall a. RealFloat a => T a -> Bool
isNaN :: T a -> Bool
$cisNaN :: forall a. RealFloat a => T a -> Bool
scaleFloat :: Int -> T a -> T a
$cscaleFloat :: forall a. RealFloat a => Int -> T a -> T a
significand :: T a -> T a
$csignificand :: forall a. RealFloat a => T a -> T a
exponent :: T a -> Int
$cexponent :: forall a. RealFloat a => T a -> Int
encodeFloat :: Integer -> Int -> T a
$cencodeFloat :: forall a. RealFloat a => Integer -> Int -> T a
decodeFloat :: T a -> (Integer, Int)
$cdecodeFloat :: forall a. RealFloat a => T a -> (Integer, Int)
floatRange :: T a -> (Int, Int)
$cfloatRange :: forall a. RealFloat a => T a -> (Int, Int)
floatDigits :: T a -> Int
$cfloatDigits :: forall a. RealFloat a => T a -> Int
floatRadix :: T a -> Integer
$cfloatRadix :: forall a. RealFloat a => T a -> Integer
$cp2RealFloat :: forall a. RealFloat a => Floating (T a)
$cp1RealFloat :: forall a. RealFloat a => RealFrac (T a)
RealFloat)


{-# INLINE lift1 #-}
lift1 :: (a -> b) -> T a -> T b
lift1 :: (a -> b) -> T a -> T b
lift1 a -> b
f (Cons a
a) = b -> T b
forall a. a -> T a
Cons (a -> b
f a
a)

{-# INLINE lift2 #-}
lift2 :: (a -> b -> c) -> T a -> T b -> T c
lift2 :: (a -> b -> c) -> T a -> T b -> T c
lift2 a -> b -> c
f (Cons a
a) (Cons b
b) = c -> T c
forall a. a -> T a
Cons (a -> b -> c
f a
a b
b)


{-# INLINE unliftF1 #-}
unliftF1 :: Functor f => (f (T a) -> f (T b)) -> f a -> f b
unliftF1 :: (f (T a) -> f (T b)) -> f a -> f b
unliftF1 f (T a) -> f (T b)
f f a
a = (T b -> b) -> f (T b) -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap T b -> b
forall a. T a -> a
decons (f (T b) -> f b) -> f (T b) -> f b
forall a b. (a -> b) -> a -> b
$ f (T a) -> f (T b)
f ((a -> T a) -> f a -> f (T a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> T a
forall a. a -> T a
Cons f a
a)

{-# INLINE unliftF2 #-}
unliftF2 :: Functor f => (f (T a) -> f (T b) -> f (T c)) -> f a -> f b -> f c
unliftF2 :: (f (T a) -> f (T b) -> f (T c)) -> f a -> f b -> f c
unliftF2 f (T a) -> f (T b) -> f (T c)
f f a
a f b
b = (T c -> c) -> f (T c) -> f c
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap T c -> c
forall a. T a -> a
decons (f (T c) -> f c) -> f (T c) -> f c
forall a b. (a -> b) -> a -> b
$ f (T a) -> f (T b) -> f (T c)
f ((a -> T a) -> f a -> f (T a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> T a
forall a. a -> T a
Cons f a
a) ((b -> T b) -> f b -> f (T b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> T b
forall a. a -> T a
Cons f b
b)


instance Functor T where
   {-# INLINE fmap #-}
   fmap :: (a -> b) -> T a -> T b
fmap a -> b
f (Cons a
a) = b -> T b
forall a. a -> T a
Cons (a -> b
f a
a)


instance Num a => Additive.C (T a) where
   zero :: T a
zero = T a
0
   + :: T a -> T a -> T a
(+) = (a -> a -> a) -> T a -> T a -> T a
forall a b c. (a -> b -> c) -> T a -> T b -> T c
lift2 a -> a -> a
forall a. Num a => a -> a -> a
(+)
   (-) = (a -> a -> a) -> T a -> T a -> T a
forall a b c. (a -> b -> c) -> T a -> T b -> T c
lift2 (-)
   negate :: T a -> T a
negate = (a -> a) -> T a -> T a
forall a b. (a -> b) -> T a -> T b
lift1 a -> a
forall a. Num a => a -> a
negate

instance (Num a) => Ring.C (T a) where
   fromInteger :: Integer -> T a
fromInteger = a -> T a
forall a. a -> T a
Cons (a -> T a) -> (Integer -> a) -> Integer -> T a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> a
forall a. Num a => Integer -> a
fromInteger
   * :: T a -> T a -> T a
(*) = (a -> a -> a) -> T a -> T a -> T a
forall a b c. (a -> b -> c) -> T a -> T b -> T c
lift2 a -> a -> a
forall a. Num a => a -> a -> a
(*)
   ^ :: T a -> Integer -> T a
(^) T a
a Integer
n = (a -> a) -> T a -> T a
forall a b. (a -> b) -> T a -> T b
lift1 (a -> Integer -> a
forall a b. (Num a, Integral b) => a -> b -> a
^Integer
n) T a
a

instance (Fractional a) => Field.C (T a) where
   fromRational' :: Rational -> T a
fromRational' Rational
r = a -> T a
forall a. a -> T a
Cons (Rational -> a
forall a. Fractional a => Rational -> a
fromRational (Rational -> Rational
forall a. Integral a => T a -> Ratio a
Ratio.toRational98 Rational
r))
   / :: T a -> T a -> T a
(/) = (a -> a -> a) -> T a -> T a -> T a
forall a b c. (a -> b -> c) -> T a -> T b -> T c
lift2 a -> a -> a
forall a. Fractional a => a -> a -> a
(/)
   recip :: T a -> T a
recip = (a -> a) -> T a -> T a
forall a b. (a -> b) -> T a -> T b
lift1 a -> a
forall a. Fractional a => a -> a
recip
   ^- :: T a -> Integer -> T a
(^-) T a
a Integer
n = (a -> a) -> T a -> T a
forall a b. (a -> b) -> T a -> T b
lift1 (a -> Integer -> a
forall a b. (Fractional a, Integral b) => a -> b -> a
^^Integer
n) T a
a

instance (Floating a) => Algebraic.C (T a) where
   sqrt :: T a -> T a
sqrt = (a -> a) -> T a -> T a
forall a b. (a -> b) -> T a -> T b
lift1 a -> a
forall a. Floating a => a -> a
sqrt
   ^/ :: T a -> Rational -> T a
(^/) T a
a Rational
r = (a -> a) -> T a -> T a
forall a b. (a -> b) -> T a -> T b
lift1 (a -> a -> a
forall a. Floating a => a -> a -> a
** Rational -> a
forall a. Fractional a => Rational -> a
fromRational (Rational -> Rational
forall a. Integral a => T a -> Ratio a
Ratio.toRational98 Rational
r)) T a
a
   root :: Integer -> T a -> T a
root Integer
n T a
a = (a -> a) -> T a -> T a
forall a b. (a -> b) -> T a -> T b
lift1 (a -> a -> a
forall a. Floating a => a -> a -> a
** a -> a
forall a. Fractional a => a -> a
recip (Integer -> a
forall a. Num a => Integer -> a
fromInteger Integer
n)) T a
a

instance (Floating a) => Trans.C (T a) where
   pi :: T a
pi      = a -> T a
forall a. a -> T a
Cons a
forall a. Floating a => a
pi
   log :: T a -> T a
log     = (a -> a) -> T a -> T a
forall a b. (a -> b) -> T a -> T b
lift1 a -> a
forall a. Floating a => a -> a
log
   exp :: T a -> T a
exp     = (a -> a) -> T a -> T a
forall a b. (a -> b) -> T a -> T b
lift1 a -> a
forall a. Floating a => a -> a
exp
   logBase :: T a -> T a -> T a
logBase = (a -> a -> a) -> T a -> T a -> T a
forall a b c. (a -> b -> c) -> T a -> T b -> T c
lift2 a -> a -> a
forall a. Floating a => a -> a -> a
logBase
   ** :: T a -> T a -> T a
(**)    = (a -> a -> a) -> T a -> T a -> T a
forall a b c. (a -> b -> c) -> T a -> T b -> T c
lift2 a -> a -> a
forall a. Floating a => a -> a -> a
(**)
   cos :: T a -> T a
cos     = (a -> a) -> T a -> T a
forall a b. (a -> b) -> T a -> T b
lift1 a -> a
forall a. Floating a => a -> a
cos
   tan :: T a -> T a
tan     = (a -> a) -> T a -> T a
forall a b. (a -> b) -> T a -> T b
lift1 a -> a
forall a. Floating a => a -> a
tan
   sin :: T a -> T a
sin     = (a -> a) -> T a -> T a
forall a b. (a -> b) -> T a -> T b
lift1 a -> a
forall a. Floating a => a -> a
sin
   acos :: T a -> T a
acos    = (a -> a) -> T a -> T a
forall a b. (a -> b) -> T a -> T b
lift1 a -> a
forall a. Floating a => a -> a
acos
   atan :: T a -> T a
atan    = (a -> a) -> T a -> T a
forall a b. (a -> b) -> T a -> T b
lift1 a -> a
forall a. Floating a => a -> a
atan
   asin :: T a -> T a
asin    = (a -> a) -> T a -> T a
forall a b. (a -> b) -> T a -> T b
lift1 a -> a
forall a. Floating a => a -> a
asin
   cosh :: T a -> T a
cosh    = (a -> a) -> T a -> T a
forall a b. (a -> b) -> T a -> T b
lift1 a -> a
forall a. Floating a => a -> a
cosh
   tanh :: T a -> T a
tanh    = (a -> a) -> T a -> T a
forall a b. (a -> b) -> T a -> T b
lift1 a -> a
forall a. Floating a => a -> a
tanh
   sinh :: T a -> T a
sinh    = (a -> a) -> T a -> T a
forall a b. (a -> b) -> T a -> T b
lift1 a -> a
forall a. Floating a => a -> a
sinh
   acosh :: T a -> T a
acosh   = (a -> a) -> T a -> T a
forall a b. (a -> b) -> T a -> T b
lift1 a -> a
forall a. Floating a => a -> a
acosh
   atanh :: T a -> T a
atanh   = (a -> a) -> T a -> T a
forall a b. (a -> b) -> T a -> T b
lift1 a -> a
forall a. Floating a => a -> a
atanh
   asinh :: T a -> T a
asinh   = (a -> a) -> T a -> T a
forall a b. (a -> b) -> T a -> T b
lift1 a -> a
forall a. Floating a => a -> a
asinh

instance (Integral a) => Integral.C (T a) where
   div :: T a -> T a -> T a
div = (a -> a -> a) -> T a -> T a -> T a
forall a b c. (a -> b -> c) -> T a -> T b -> T c
lift2 a -> a -> a
forall a. Integral a => a -> a -> a
div
   mod :: T a -> T a -> T a
mod = (a -> a -> a) -> T a -> T a -> T a
forall a b c. (a -> b -> c) -> T a -> T b -> T c
lift2 a -> a -> a
forall a. Integral a => a -> a -> a
mod
   divMod :: T a -> T a -> (T a, T a)
divMod (Cons a
a) (Cons a
b) =
      (a -> T a, a -> T a) -> (a, a) -> (T a, T a)
forall a c b d. (a -> c, b -> d) -> (a, b) -> (c, d)
mapPair (a -> T a
forall a. a -> T a
Cons, a -> T a
forall a. a -> T a
Cons) (a -> a -> (a, a)
forall a. Integral a => a -> a -> (a, a)
divMod a
a a
b)

instance (Integral a) => Units.C (T a) where
   isUnit :: T a -> Bool
isUnit = String -> T a -> Bool
forall a. String -> a
unimplemented String
"isUnit"
   stdAssociate :: T a -> T a
stdAssociate = String -> T a -> T a
forall a. String -> a
unimplemented String
"stdAssociate"
   stdUnit :: T a -> T a
stdUnit = String -> T a -> T a
forall a. String -> a
unimplemented String
"stdUnit"
   stdUnitInv :: T a -> T a
stdUnitInv = String -> T a -> T a
forall a. String -> a
unimplemented String
"stdUnitInv"

instance (Integral a) => PID.C (T a) where
   gcd :: T a -> T a -> T a
gcd = T a -> T a -> T a
forall a. Integral a => a -> a -> a
gcd
   lcm :: T a -> T a -> T a
lcm = T a -> T a -> T a
forall a. Integral a => a -> a -> a
lcm

instance (Eq a, Num a) => ZeroTestable.C (T a) where
   isZero :: T a -> Bool
isZero (Cons a
a) = a
aa -> a -> Bool
forall a. Eq a => a -> a -> Bool
==a
0

instance (Num a) => Absolute.C (T a) where
   abs :: T a -> T a
abs = T a -> T a
forall a. Num a => a -> a
abs
   signum :: T a -> T a
signum = T a -> T a
forall a. Num a => a -> a
signum

instance (RealFrac a) => RealRing.C (T a) where
   splitFraction :: T a -> (b, T a)
splitFraction (Cons a
a) =
      (Integer -> b, a -> T a) -> (Integer, a) -> (b, T a)
forall a c b d. (a -> c, b -> d) -> (a, b) -> (c, d)
mapPair (Integer -> b
forall a. C a => Integer -> a
Ring.fromInteger, a -> T a
forall a. a -> T a
Cons)
         ((Integer, a) -> (Integer, a)
forall a b. (Num a, Num b, Ord a) => (b, a) -> (b, a)
RealRing98.fixSplitFraction (a -> (Integer, a)
forall a b. (RealFrac a, Integral b) => a -> (b, a)
properFraction a
a))
   fraction :: T a -> T a
fraction (Cons a
a) =
      a -> T a
forall a. a -> T a
Cons (a -> a
forall a. Real a => a -> a
RealRing98.fixFraction (a -> a
forall a. RealFrac a => a -> a
RealRing98.signedFraction a
a))
   ceiling :: T a -> b
ceiling (Cons a
a) = Integer -> b
forall a. C a => Integer -> a
Ring.fromInteger (a -> Integer
forall a b. (RealFrac a, Integral b) => a -> b
ceiling a
a)
   floor :: T a -> b
floor (Cons a
a) = Integer -> b
forall a. C a => Integer -> a
Ring.fromInteger (a -> Integer
forall a b. (RealFrac a, Integral b) => a -> b
floor a
a)
   truncate :: T a -> b
truncate (Cons a
a) = Integer -> b
forall a. C a => Integer -> a
Ring.fromInteger (a -> Integer
forall a b. (RealFrac a, Integral b) => a -> b
truncate a
a)
   round :: T a -> b
round (Cons a
a) = Integer -> b
forall a. C a => Integer -> a
Ring.fromInteger (a -> Integer
forall a b. (RealFrac a, Integral b) => a -> b
round a
a)

instance (RealFrac a) => RealField.C (T a) where

instance (RealFloat a) => RealTrans.C (T a) where
   atan2 :: T a -> T a -> T a
atan2 = T a -> T a -> T a
forall a. RealFloat a => a -> a -> a
atan2

instance (Integral a) => RealIntegral.C (T a) where
   quot :: T a -> T a -> T a
quot = (a -> a -> a) -> T a -> T a -> T a
forall a b c. (a -> b -> c) -> T a -> T b -> T c
lift2 a -> a -> a
forall a. Integral a => a -> a -> a
quot
   rem :: T a -> T a -> T a
rem = (a -> a -> a) -> T a -> T a -> T a
forall a b c. (a -> b -> c) -> T a -> T b -> T c
lift2 a -> a -> a
forall a. Integral a => a -> a -> a
rem
   quotRem :: T a -> T a -> (T a, T a)
quotRem (Cons a
a) (Cons a
b) =
      (a -> T a, a -> T a) -> (a, a) -> (T a, T a)
forall a c b d. (a -> c, b -> d) -> (a, b) -> (c, d)
mapPair (a -> T a
forall a. a -> T a
Cons, a -> T a
forall a. a -> T a
Cons) (a -> a -> (a, a)
forall a. Integral a => a -> a -> (a, a)
quotRem a
a a
b)

instance (Integral a) => ToInteger.C (T a) where
   toInteger :: T a -> Integer
toInteger (Cons a
a) = a -> Integer
forall a. Integral a => a -> Integer
toInteger a
a

instance (Real a) => ToRational.C (T a) where
   toRational :: T a -> Rational
toRational (Cons a
a) = Rational -> Rational
forall a. C a => Rational -> a
Field.fromRational (a -> Rational
forall a. Real a => a -> Rational
toRational a
a)

instance (RealFloat a) => Float.C (T a) where
   radix :: T a -> Integer
radix = a -> Integer
forall a. RealFloat a => a -> Integer
floatRadix (a -> Integer) -> (T a -> a) -> T a -> Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. T a -> a
forall a. T a -> a
decons
   digits :: T a -> Int
digits = a -> Int
forall a. RealFloat a => a -> Int
floatDigits (a -> Int) -> (T a -> a) -> T a -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. T a -> a
forall a. T a -> a
decons
   range :: T a -> (Int, Int)
range = a -> (Int, Int)
forall a. RealFloat a => a -> (Int, Int)
floatRange (a -> (Int, Int)) -> (T a -> a) -> T a -> (Int, Int)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. T a -> a
forall a. T a -> a
decons
   decode :: T a -> (Integer, Int)
decode = a -> (Integer, Int)
forall a. RealFloat a => a -> (Integer, Int)
decodeFloat (a -> (Integer, Int)) -> (T a -> a) -> T a -> (Integer, Int)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. T a -> a
forall a. T a -> a
decons
   encode :: Integer -> Int -> T a
encode Integer
m = a -> T a
forall a. a -> T a
Cons (a -> T a) -> (Int -> a) -> Int -> T a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Int -> a
forall a. RealFloat a => Integer -> Int -> a
encodeFloat Integer
m
   exponent :: T a -> Int
exponent = a -> Int
forall a. RealFloat a => a -> Int
exponent (a -> Int) -> (T a -> a) -> T a -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. T a -> a
forall a. T a -> a
decons
   significand :: T a -> T a
significand = (a -> a) -> T a -> T a
forall a b. (a -> b) -> T a -> T b
lift1 a -> a
forall a. RealFloat a => a -> a
significand
   scale :: Int -> T a -> T a
scale = (a -> a) -> T a -> T a
forall a b. (a -> b) -> T a -> T b
lift1 ((a -> a) -> T a -> T a) -> (Int -> a -> a) -> Int -> T a -> T a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> a -> a
forall a. RealFloat a => Int -> a -> a
scaleFloat
   isNaN :: T a -> Bool
isNaN = a -> Bool
forall a. RealFloat a => a -> Bool
isNaN (a -> Bool) -> (T a -> a) -> T a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. T a -> a
forall a. T a -> a
decons
   isInfinite :: T a -> Bool
isInfinite = a -> Bool
forall a. RealFloat a => a -> Bool
isInfinite (a -> Bool) -> (T a -> a) -> T a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. T a -> a
forall a. T a -> a
decons
   isDenormalized :: T a -> Bool
isDenormalized = a -> Bool
forall a. RealFloat a => a -> Bool
isDenormalized (a -> Bool) -> (T a -> a) -> T a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. T a -> a
forall a. T a -> a
decons
   isNegativeZero :: T a -> Bool
isNegativeZero = a -> Bool
forall a. RealFloat a => a -> Bool
isNegativeZero (a -> Bool) -> (T a -> a) -> T a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. T a -> a
forall a. T a -> a
decons
   isIEEE :: T a -> Bool
isIEEE = a -> Bool
forall a. RealFloat a => a -> Bool
isIEEE (a -> Bool) -> (T a -> a) -> T a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. T a -> a
forall a. T a -> a
decons



unimplemented :: String -> a
unimplemented :: String -> a
unimplemented String
name =
   String -> a
forall a. HasCallStack => String -> a
error (String
name String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"cannot be implemented in terms of Haskell98 type classes")