module ELynx.Tools.Equality
(
allEqual
, nearlyEqWith
, eps
, nearlyEq
, (=~=)
, nearlyEqListWith
, nearlyEqList
, nearlyEqVecWith
, nearlyEqVec
, nearlyEqMatWith
, nearlyEqMat
) where
import Numeric.LinearAlgebra
import ELynx.Tools.Definitions
allEqual :: Eq a => [a] -> Bool
allEqual [] = True
allEqual xs = all (== head xs) (tail xs)
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