module Symtegration.Symbolic.Simplify (simplify, tidy, simplifyForVariable) where
import Data.Text (Text)
import Symtegration.Symbolic
import Symtegration.Symbolic.Simplify.AlgebraicRingOrder qualified as AlgebraicRingOrder
import Symtegration.Symbolic.Simplify.Fraction qualified as Fraction
import Symtegration.Symbolic.Simplify.NumericFolding qualified as NumericFolding
import Symtegration.Symbolic.Simplify.SymbolicFolding qualified as SymbolicFolding
import Symtegration.Symbolic.Simplify.Tidy
simplify :: Expression -> Expression
simplify :: Expression -> Expression
simplify = Text -> Expression -> Expression
simplifyForVariable Text
""
simplifyForVariable ::
Text ->
Expression ->
Expression
simplifyForVariable :: Text -> Expression -> Expression
simplifyForVariable Text
v Expression
e
| Expression
e Expression -> Expression -> Bool
forall a. Eq a => a -> a -> Bool
== Expression
e' = Expression
e
| Bool
otherwise = Text -> Expression -> Expression
simplifyForVariable Text
v Expression
e'
where
e' :: Expression
e' = Expression -> Expression
f Expression
e
f :: Expression -> Expression
f = Expression -> Expression
Fraction.simplify (Expression -> Expression)
-> (Expression -> Expression) -> Expression -> Expression
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Expression -> Expression
NumericFolding.simplify (Expression -> Expression)
-> (Expression -> Expression) -> Expression -> Expression
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Expression -> Expression
SymbolicFolding.simplify (Expression -> Expression)
-> (Expression -> Expression) -> Expression -> Expression
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Expression -> Expression
AlgebraicRingOrder.order Text
v