This is a Haskell library intended to support symbolic integration of mathematical expressions.
It offers the following:
-
Symbolic integration of mathematical expressions.
-
Integration of polynomials.
-
Integration of trigonometric functions.
-
Integration of exponential and logarithmic functions.
-
Integration by substitution.
-
-
Symbolic representation of mathematical expressions.
-
Utility functions to make it easier to read the mathematical expressions. For example, deriving equivalent Haskell code for a mathematical expression, and rudimentary support to simplify the symbolic representation.
Mathematical expressions with either numeric coefficients or symbolic coefficients can be integrated. For example:
>>> import Symtegration
>>> toHaskell <$> integrate "x" (4 * "x" ** 3 + 1)
Just "x + (x ** 4)"
>>> toHaskell <$> integrate "z" ("x" * "z" + "y")
Just "y * z + x * (1 / 2) * (z ** 2)"
Concrete numbers can also be computed from these integrals. For example:
>>> import Symtegration
>>> let (Just p) = integrate "x" (4 * "x" ** 3 + 1)
>>> fractionalEvaluate p (\case "x" -> Just (3 / 7 :: Rational))
Just (1110 % 2401)
See the module documentation for details.
With Symtegration, symbolic integration can be done within GHCi.
When executing GHCi within the Symtegration project, it is best
to load only the Symtegration
module to avoid name collisions,
so start GHCi without loading any modules.
$ stack ghci --no-load
Within GHCi, explicitly load the Symtegration
module.
You can then proceed to symbolically integrate mathematical expressions
and compute approximate or exact values from these integrals.
>>> :load Symtegration
>>> toHaskell <$> integrate "x" ("a" * "x" ** 4 + "x" + "b")
Just "b * x + (1 / 2) * (x ** 2) + a * ((x ** 5) / 5)"
>>>
>>> let (Just p) = integrate "x" ("x" ** 2)
>>> evaluate p (\case "x" -> Just 1)
Just 0.3333333333333333
>>>
>>> fractionalEvaluate p (\case "x" -> Just (1 :: Rational))
Just (1 % 3)
See CHANGELOG.md
for what has changed.
Be nice; see CODE_OF_CONDUCT.md
for details.
See SECURITY.md
for details.
See CONTRIBUTING.md
for details.
Apache 2.0; see LICENSE
for details.