module ELynx.Tools.Equality
(
allEqual,
allNearlyEqualWith,
allNearlyEqual,
nearlyEqWith,
eps,
nearlyEq,
(=~=),
nearlyEqListWith,
nearlyEqList,
nearlyEqVecWith,
nearlyEqVec,
nearlyEqMatWith,
nearlyEqMat,
)
where
import ELynx.Tools.Definitions
import Numeric.LinearAlgebra
allEqual :: Eq a => [a] -> Bool
allEqual :: forall a. Eq a => [a] -> Bool
allEqual [] = Bool
True
allEqual [a]
xs = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (forall a. Eq a => a -> a -> Bool
== forall a. [a] -> a
head [a]
xs) (forall a. [a] -> [a]
tail [a]
xs)
allNearlyEqualWith :: Double -> [Double] -> Bool
allNearlyEqualWith :: Double -> [Double] -> Bool
allNearlyEqualWith Double
_ [] = Bool
True
allNearlyEqualWith Double
tol [Double]
xs = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (Double -> Double -> Double -> Bool
nearlyEqWith Double
tol forall a b. (a -> b) -> a -> b
$ forall a. [a] -> a
head [Double]
xs) (forall a. [a] -> [a]
tail [Double]
xs)
allNearlyEqual :: [Double] -> Bool
allNearlyEqual :: [Double] -> Bool
allNearlyEqual = Double -> [Double] -> Bool
allNearlyEqualWith Double
eps
nearlyEqWith :: Double -> Double -> Double -> Bool
nearlyEqWith :: Double -> Double -> Double -> Bool
nearlyEqWith Double
tol Double
a Double
b = Double
tol forall a. Ord a => a -> a -> Bool
> forall a. Num a => a -> a
abs (Double
a forall a. Num a => a -> a -> a
- Double
b)
nearlyEq :: Double -> Double -> Bool
nearlyEq :: Double -> Double -> Bool
nearlyEq = Double -> Double -> Double -> Bool
nearlyEqWith Double
eps
(=~=) :: Double -> Double -> Bool
=~= :: Double -> Double -> Bool
(=~=) = Double -> Double -> Bool
nearlyEq
nearlyEqValListWith :: Double -> Double -> [Double] -> Bool
nearlyEqValListWith :: Double -> Double -> [Double] -> Bool
nearlyEqValListWith Double
tol Double
a = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (Double -> Double -> Double -> Bool
nearlyEqWith Double
tol Double
a)
nearlyEqListWith :: Double -> [Double] -> [Double] -> Bool
nearlyEqListWith :: Double -> [Double] -> [Double] -> Bool
nearlyEqListWith Double
tol [Double]
xs [Double]
ys = Double -> Double -> [Double] -> Bool
nearlyEqValListWith Double
tol Double
0 (forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (-) [Double]
xs [Double]
ys)
nearlyEqList :: [Double] -> [Double] -> Bool
nearlyEqList :: [Double] -> [Double] -> Bool
nearlyEqList = Double -> [Double] -> [Double] -> Bool
nearlyEqListWith Double
eps
nearlyEqVecWith :: Double -> Vector R -> Vector R -> Bool
nearlyEqVecWith :: Double -> Vector Double -> Vector Double -> Bool
nearlyEqVecWith Double
tol Vector Double
a Vector Double
b = Double -> Double -> [Double] -> Bool
nearlyEqValListWith Double
tol Double
0 (forall a. Storable a => Vector a -> [a]
toList forall a b. (a -> b) -> a -> b
$ Vector Double
a forall a. Num a => a -> a -> a
- Vector Double
b)
nearlyEqVec :: Vector R -> Vector R -> Bool
nearlyEqVec :: Vector Double -> Vector Double -> Bool
nearlyEqVec = Double -> Vector Double -> Vector Double -> Bool
nearlyEqVecWith Double
eps
nearlyEqMatWith :: Double -> Matrix R -> Matrix R -> Bool
nearlyEqMatWith :: Double -> Matrix Double -> Matrix Double -> Bool
nearlyEqMatWith Double
tol Matrix Double
a Matrix Double
b = Double -> Double -> [Double] -> Bool
nearlyEqValListWith Double
tol Double
0 (forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. Element t => Matrix t -> [[t]]
toLists forall a b. (a -> b) -> a -> b
$ Matrix Double
a forall a. Num a => a -> a -> a
- Matrix Double
b)
nearlyEqMat :: Matrix R -> Matrix R -> Bool
nearlyEqMat :: Matrix Double -> Matrix Double -> Bool
nearlyEqMat = Double -> Matrix Double -> Matrix Double -> Bool
nearlyEqMatWith Double
eps