symtegration-0.4.0: Library for symbolic integration of mathematical expressions.
CopyrightCopyright 2024 Yoo Chung
LicenseApache-2.0
Maintainerdev@chungyc.org
Safe HaskellNone
LanguageGHC2021

Symtegration.Symbolic.Simplify

Description

Supports the simplification of the symbolic representation for a mathematical expression. This is aimed towards making it easier to find common factors for the purpose of integration. It requires the specification of which symbol represents the variable.

Synopsis

Documentation

simplify :: Expression -> Expression Source #

Simplifies symbolic representations of mathematical expressions.

All addition and multiplication will be associated to the left. The simplification is done with an eye towards making it easier to find common factors.

>>> toHaskell $ simplify $ 4 - "x" + "a" * "x" ** 3 + 2 * "x" - 3
"1 + x + a * x ** 3"

tidy :: Expression -> Expression Source #

Tidies up expressions for nicer output.

Assumes that other simplifications have been applied first. In fact, it may undo changes that made other simplifications easier.

What is tidied up

Expand

This section shows examples of what this function tidies up.

>>> toHaskell $ tidy $ "x" + negate "y"
"x - y"
>>> toHaskell $ tidy $ "x" + Number (-2) * "y"
"x - 2 * y"
>>> toHaskell $ tidy $ Number (-1) / Number 2
"negate (1 / 2)"
>>> toHaskell $ tidy $ Number (-1) * "x"
"negate x"
>>> toHaskell $ tidy $ (-"x") * "y"
"negate (x * y)"
>>> toHaskell $ tidy $ "x" * (-"y")
"negate (x * y)"
>>> toHaskell $ tidy $ (-"x") * (-"y")
"x * y"
>>> toHaskell $ tidy $ "x" + ((-"y") + "z")
"x - y + z"

simplifyForVariable Source #

Arguments

:: Text

Symbol for the variable.

-> Expression

Expression to be simplified.

-> Expression

Simplified expression.

Simplifies symbolic representations of mathematical expressions with special consideration for a particular variable.

All addition and multiplication will be associated to the left. Terms with higher orders of the variable will appear later. The simplification is done with an eye towards making it easier to find common factors.

>>> toHaskell $ simplifyForVariable "x" $ 1 + "a" * "x" ** 3 + "x"
"1 + x + a * x ** 3"
>>> toHaskell $ simplifyForVariable "x" $ "a" ** 143 + "x" + "b" ** 2
"a ** 143 + b ** 2 + x"
>>> toHaskell $ simplifyForVariable "x" $ "a" * "x" + "x" + "b ** 2" + "x" ** 2
"b ** 2 + x + a * x + x ** 2"