_substitute :: [( Algebraic, Rational)] -> Algebraic -> Rational
{- ^ an internal function to apply a list of substitution rules to given
     variables

   >>> _substitute [(Alg "x1",2%1)] Alg "x1"
   2%1
   >>> _substitute [(Alg "x2",2%1)] Alg "x1"
   Alg "x2" -}

_substitute sRule (Alg v)
                   | '%' ∈ v = read v :: Rational
                   | otherwise = assert (length _sRule == 1) (snd (head _sRule))
                   where _sRule = filter (isSubstitute (Alg v)) sRule


_substitute :: [( Algebraic, Rational)] -> Algebraic -> Rational
_substitute sRule (Alg v)
                   | '%' ∈ v = read v :: Rational
                   | otherwise = assert (length _sRule == 1) (snd (head _sRule))
                   where _sRule = filter (isSubstitute (Alg v)) sRule
_substitute sRule (Alg v)
                   | '%' ∈ v = read v :: Rational
                   | otherwise = assert (length _sRule == 1) (snd (head _sRule))
                   where _sRule = filter (isSubstitute (Alg v)) sRule