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 [] = True
allEqual xs = all (== head xs) (tail xs)
allNearlyEqualWith :: Double -> [Double] -> Bool
allNearlyEqualWith _ [] = True
allNearlyEqualWith tol xs = all (nearlyEqWith tol $ head xs) (tail xs)
allNearlyEqual :: [Double] -> Bool
allNearlyEqual = allNearlyEqualWith eps
nearlyEqWith :: Double -> Double -> Double -> Bool
nearlyEqWith tol a b = tol > abs (a - b)
nearlyEq :: Double -> Double -> Bool
nearlyEq = nearlyEqWith eps
(=~=) :: Double -> Double -> Bool
(=~=) = nearlyEq
nearlyEqValListWith :: Double -> Double -> [Double] -> Bool
nearlyEqValListWith tol a = all (nearlyEqWith tol a)
nearlyEqListWith :: Double -> [Double] -> [Double] -> Bool
nearlyEqListWith tol xs ys = nearlyEqValListWith tol 0 (zipWith (-) xs ys)
nearlyEqList :: [Double] -> [Double] -> Bool
nearlyEqList = nearlyEqListWith eps
nearlyEqVecWith :: Double -> Vector R -> Vector R -> Bool
nearlyEqVecWith tol a b = nearlyEqValListWith tol 0 (toList $ a - b)
nearlyEqVec :: Vector R -> Vector R -> Bool
nearlyEqVec = nearlyEqVecWith eps
nearlyEqMatWith :: Double -> Matrix R -> Matrix R -> Bool
nearlyEqMatWith tol a b = nearlyEqValListWith tol 0 (concat . toLists $ a - b)
nearlyEqMat :: Matrix R -> Matrix R -> Bool
nearlyEqMat = nearlyEqMatWith eps