{-# LANGUAGE ExplicitNamespaces, DataKinds, FlexibleInstances, TypeFamilies,
TypeOperators, ConstraintKinds, ScopedTypeVariables,
FlexibleContexts, UndecidableInstances, CPP #-}
#if __GLASGOW_HASKELL__ >= 711
{-# OPTIONS_GHC -Wno-redundant-constraints #-}
#endif
module Data.Metrology.Poly (
zero, (|+|), (|-|), qSum, qNegate,
(|*|), (|/|),
(*|), (|*), (/|), (|/),
(|^), (|^^), qNthRoot,
qSq, qCube, qSqrt, qCubeRoot,
qCompare, (|<|), (|>|), (|<=|), (|>=|), (|==|), (|/=|),
qApprox, qNapprox,
numIn, (#), quOf, (%), showIn,
unity, redim, convert,
defaultLCSU, constant,
(:*)(..), (:/)(..), (:^)(..), (:@)(..),
UnitPrefix(..),
type (%*), type (%/), type (%^),
Qu, MkQu_D, MkQu_DLN, MkQu_U, MkQu_ULN,
Dimension,
Unit(type BaseUnit, type DimOfUnit, conversionRatio),
Canonical,
Dimensionless(..), Number(..), Count, quantity,
MkLCSU, LCSU(DefaultLCSU), DefaultUnitOfDim,
CompatibleUnit, CompatibleDim, ConvertibleLCSUs_D,
DefaultConvertibleLCSU_D, DefaultConvertibleLCSU_U,
MultDimFactors, MultUnitFactors, UnitOfDimFactors,
Z(..), Succ, Pred, type (#+), type (#-), type (#*), type (#/), Negate,
One, Two, Three, Four, Five, MOne, MTwo, MThree, MFour, MFive,
sZero, sOne, sTwo, sThree, sFour, sFive,
sMOne, sMTwo, sMThree, sMFour, sMFive,
sSucc, sPred, sNegate,
pZero, pOne, pTwo, pThree, pFour, pFive,
pMOne, pMTwo, pMThree, pMFour, pMFive,
pSucc, pPred,
module Data.Metrology.Internal
) where
import Data.Metrology.Z
import Data.Metrology.Qu
import Data.Metrology.Dimensions
import Data.Metrology.Factor
import Data.Metrology.Units
import Data.Metrology.Combinators
import Data.Metrology.LCSU
import Data.Metrology.Validity
import Data.Metrology.Internal
import Data.Foldable as F
import Data.Proxy
numIn :: forall unit dim lcsu n.
( ValidDLU dim lcsu unit
, Fractional n )
=> Qu dim lcsu n -> unit -> n
numIn :: Qu dim lcsu n -> unit -> n
numIn (Qu n
val) unit
u
= n
val n -> n -> n
forall a. Num a => a -> a -> a
* Rational -> n
forall a. Fractional a => Rational -> a
fromRational
(Proxy (LookupList dim lcsu) -> Rational
forall (units :: [Factor *]).
UnitFactor units =>
Proxy units -> Rational
canonicalConvRatioSpec (Proxy (LookupList dim lcsu)
forall k (t :: k). Proxy t
Proxy :: Proxy (LookupList dim lcsu))
Rational -> Rational -> Rational
forall a. Fractional a => a -> a -> a
/ unit -> Rational
forall unit. Unit unit => unit -> Rational
canonicalConvRatio unit
u)
infix 5 #
(#) :: ( ValidDLU dim lcsu unit
, Fractional n )
=> Qu dim lcsu n -> unit -> n
# :: Qu dim lcsu n -> unit -> n
(#) = Qu dim lcsu n -> unit -> n
forall unit (dim :: [Factor *]) (lcsu :: LCSU *) n.
(ValidDLU dim lcsu unit, Fractional n) =>
Qu dim lcsu n -> unit -> n
numIn
quOf :: forall unit dim lcsu n.
( ValidDLU dim lcsu unit
, Fractional n )
=> n -> unit -> Qu dim lcsu n
quOf :: n -> unit -> Qu dim lcsu n
quOf n
d unit
u
= n -> Qu dim lcsu n
forall (a :: [Factor *]) (lcsu :: LCSU *) n. n -> Qu a lcsu n
Qu (n
d n -> n -> n
forall a. Num a => a -> a -> a
* Rational -> n
forall a. Fractional a => Rational -> a
fromRational
(unit -> Rational
forall unit. Unit unit => unit -> Rational
canonicalConvRatio unit
u
Rational -> Rational -> Rational
forall a. Fractional a => a -> a -> a
/ Proxy (LookupList dim lcsu) -> Rational
forall (units :: [Factor *]).
UnitFactor units =>
Proxy units -> Rational
canonicalConvRatioSpec (Proxy (LookupList dim lcsu)
forall k (t :: k). Proxy t
Proxy :: Proxy (LookupList dim lcsu))))
infix 5 %
(%) :: ( ValidDLU dim lcsu unit
, Fractional n )
=> n -> unit -> Qu dim lcsu n
% :: n -> unit -> Qu dim lcsu n
(%) = n -> unit -> Qu dim lcsu n
forall unit (dim :: [Factor *]) (lcsu :: LCSU *) n.
(ValidDLU dim lcsu unit, Fractional n) =>
n -> unit -> Qu dim lcsu n
quOf
infix 1 `showIn`
showIn :: ( ValidDLU dim lcsu unit
, Fractional n
, Show unit
, Show n )
=> Qu dim lcsu n -> unit -> String
showIn :: Qu dim lcsu n -> unit -> String
showIn Qu dim lcsu n
x unit
u = n -> String
forall a. Show a => a -> String
show (Qu dim lcsu n
x Qu dim lcsu n -> unit -> n
forall (dim :: [Factor *]) (lcsu :: LCSU *) unit n.
(ValidDLU dim lcsu unit, Fractional n) =>
Qu dim lcsu n -> unit -> n
# unit
u) String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" " String -> String -> String
forall a. [a] -> [a] -> [a]
++ unit -> String
forall a. Show a => a -> String
show unit
u
convert :: forall d l1 l2 n.
( ConvertibleLCSUs d l1 l2
, Fractional n )
=> Qu d l1 n -> Qu d l2 n
convert :: Qu d l1 n -> Qu d l2 n
convert (Qu n
x) = n -> Qu d l2 n
forall (a :: [Factor *]) (lcsu :: LCSU *) n. n -> Qu a lcsu n
Qu (n -> Qu d l2 n) -> n -> Qu d l2 n
forall a b. (a -> b) -> a -> b
$ n
x n -> n -> n
forall a. Num a => a -> a -> a
* Rational -> n
forall a. Fractional a => Rational -> a
fromRational (
Proxy (LookupList d l1) -> Rational
forall (units :: [Factor *]).
UnitFactor units =>
Proxy units -> Rational
canonicalConvRatioSpec (Proxy (LookupList d l1)
forall k (t :: k). Proxy t
Proxy :: Proxy (LookupList d l1))
Rational -> Rational -> Rational
forall a. Fractional a => a -> a -> a
/ Proxy (LookupList d l2) -> Rational
forall (units :: [Factor *]).
UnitFactor units =>
Proxy units -> Rational
canonicalConvRatioSpec (Proxy (LookupList d l2)
forall k (t :: k). Proxy t
Proxy :: Proxy (LookupList d l2)))
constant :: ( d @~ e
, ConvertibleLCSUs e DefaultLCSU l
, Fractional n )
=> Qu d DefaultLCSU n -> Qu e l n
constant :: Qu d 'DefaultLCSU n -> Qu e l n
constant = Qu e 'DefaultLCSU n -> Qu e l n
forall (d :: [Factor *]) (l1 :: LCSU *) (l2 :: LCSU *) n.
(ConvertibleLCSUs d l1 l2, Fractional n) =>
Qu d l1 n -> Qu d l2 n
convert (Qu e 'DefaultLCSU n -> Qu e l n)
-> (Qu d 'DefaultLCSU n -> Qu e 'DefaultLCSU n)
-> Qu d 'DefaultLCSU n
-> Qu e l n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Qu d 'DefaultLCSU n -> Qu e 'DefaultLCSU n
forall (d :: [Factor *]) (e :: [Factor *]) (l :: LCSU *) n.
(d @~ e) =>
Qu d l n -> Qu e l n
redim
zero :: Num n => Qu dimspec l n
zero :: Qu dimspec l n
zero = n -> Qu dimspec l n
forall (a :: [Factor *]) (lcsu :: LCSU *) n. n -> Qu a lcsu n
Qu n
0
infixl 6 |+|
(|+|) :: (d1 @~ d2, Num n) => Qu d1 l n -> Qu d2 l n -> Qu d1 l n
(Qu n
a) |+| :: Qu d1 l n -> Qu d2 l n -> Qu d1 l n
|+| (Qu n
b) = n -> Qu d1 l n
forall (a :: [Factor *]) (lcsu :: LCSU *) n. n -> Qu a lcsu n
Qu (n
a n -> n -> n
forall a. Num a => a -> a -> a
+ n
b)
infixl 6 |-|
(|-|) :: (d1 @~ d2, Num n) => Qu d1 l n -> Qu d2 l n -> Qu d1 l n
(Qu n
a) |-| :: Qu d1 l n -> Qu d2 l n -> Qu d1 l n
|-| (Qu n
b) = n -> Qu d1 l n
forall (a :: [Factor *]) (lcsu :: LCSU *) n. n -> Qu a lcsu n
Qu (n
a n -> n -> n
forall a. Num a => a -> a -> a
- n
b)
qSum :: (Foldable f, Num n) => f (Qu d l n) -> Qu d l n
qSum :: f (Qu d l n) -> Qu d l n
qSum = (Qu d l n -> Qu d l n -> Qu d l n)
-> Qu d l n -> f (Qu d l n) -> Qu d l n
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
F.foldr Qu d l n -> Qu d l n -> Qu d l n
forall (d1 :: [Factor *]) (d2 :: [Factor *]) n (l :: LCSU *).
(d1 @~ d2, Num n) =>
Qu d1 l n -> Qu d2 l n -> Qu d1 l n
(|+|) Qu d l n
forall n (dimspec :: [Factor *]) (l :: LCSU *).
Num n =>
Qu dimspec l n
zero
qNegate :: Num n => Qu d l n -> Qu d l n
qNegate :: Qu d l n -> Qu d l n
qNegate (Qu n
x) = n -> Qu d l n
forall (a :: [Factor *]) (lcsu :: LCSU *) n. n -> Qu a lcsu n
Qu (n -> n
forall a. Num a => a -> a
negate n
x)
infixl 7 *| , |* , |/
(*|) :: Num n => n -> Qu b l n -> Qu b l n
n
a *| :: n -> Qu b l n -> Qu b l n
*| (Qu n
b) = n -> Qu b l n
forall (a :: [Factor *]) (lcsu :: LCSU *) n. n -> Qu a lcsu n
Qu (n
a n -> n -> n
forall a. Num a => a -> a -> a
* n
b)
(|*) :: Num n => Qu a l n -> n -> Qu a l n
(Qu n
a) |* :: Qu a l n -> n -> Qu a l n
|* n
b = n -> Qu a l n
forall (a :: [Factor *]) (lcsu :: LCSU *) n. n -> Qu a lcsu n
Qu (n
a n -> n -> n
forall a. Num a => a -> a -> a
* n
b)
(|/) :: Fractional n => Qu a l n -> n -> Qu a l n
(Qu n
a) |/ :: Qu a l n -> n -> Qu a l n
|/ n
b = n -> Qu a l n
forall (a :: [Factor *]) (lcsu :: LCSU *) n. n -> Qu a lcsu n
Qu (n
a n -> n -> n
forall a. Fractional a => a -> a -> a
/ n
b)