How to use Symtegration

Installation

For using the Symtegration library locally, clone the source repository, build, and install it.

$ git clone git@github.com:symtegration/symtegration.git
$ cd symtegration
$ stack build
$ stack install

You can then use Symtegration in GHCi or local Haskell projects. If you use Cabal instead of Stack, then you can run cabal build and cabal install, instead.

To use as a library in a Haskell Stack project, at the following to the extra-deps field in stack.yaml, and add symtegration as a dependency to the appropriate build targets.

extra-deps:
- git: https://github.com/symtegration/symtegration
  commit: '8cee55fbf0ac86565996e2d0209dac56e348bd6a'

See the module documentation for more details as to how to use the library.

GHCi

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. Mathematical expressions are entered as normal Haskell expressions, where symbols can be entered as strings when the OverloadedStrings extension is enabled.

>>> :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)

IHaskell

Symtegration can also be used in IHaskell to do symbolic integration. Its use can be seen in an example IHaskell notebook, which you try out by running on mybinder.org.