https://github.com/symtegration/symtegration
Haskell library for symbolic integration.
https://github.com/symtegration/symtegration
haskell mathematics symbolic-integration
Last synced: 3 months ago
JSON representation
Haskell library for symbolic integration.
- Host: GitHub
- URL: https://github.com/symtegration/symtegration
- Owner: symtegration
- License: apache-2.0
- Created: 2024-12-06T19:13:42.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-04-01T21:18:14.000Z (4 months ago)
- Last Synced: 2025-04-01T22:24:53.059Z (4 months ago)
- Topics: haskell, mathematics, symbolic-integration
- Language: Haskell
- Homepage: https://symtegration.dev
- Size: 706 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: docs/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: docs/CODE_OF_CONDUCT.md
- Security: docs/SECURITY.md
Awesome Lists containing this project
README
# Symtegration
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 of ratios of two polynomials.
* Integration by substitution.
* Integration by parts.
* 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 some support for simplifying symbolic representations.[](https://github.com/symtegration/symtegration/actions/workflows/build.yaml)
[](https://www.bestpractices.dev/projects/9864)
[](https://scorecard.dev/viewer/?uri=github.com/symtegration/symtegration)
[](https://codecov.io/gh/symtegration/symtegration)## Integration
Mathematical expressions with either numeric coefficients or symbolic coefficients
can be integrated. For example:```haskell
>>> import Symtegration
>>> toHaskell <$> integrate "x" (4 * "x" ** 3 + 1)
Just "x + x ** 4"
>>> toHaskell <$> integrate "z" ("x" * "z" + "y")
Just "y * z + 1 / 2 * x * z ** 2"
```Concrete numbers can also be computed from these integrals. For example:
```haskell
>>> import Symtegration
>>> let (Just p) = integrate "x" (4 * "x" ** 3 + 1)
>>> fractionalEvaluate p (\case "x" -> Just (3 / 7 :: Rational))
Just (1110 % 2401)
```### Symbolic integration in 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.```shell
$ 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.```haskell
>>> :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)
```[GHCi]: https://downloads.haskell.org/ghc/latest/docs/users_guide/ghci.html
### Symbolic integration in IHaskell
Symtegration can also be used in [IHaskell] to do symbolic integration.
Its use can be seen in an [example IHaskell notebook],
which you can try out by [running on mybinder.org].[IHaskell]: https://github.com/IHaskell/IHaskell
[example IHaskell notebook]: https://github.com/chungyc/haskell-notebooks/blob/main/Symtegration.ipynb
[running on mybinder.org]: https://mybinder.org/v2/gh/chungyc/haskell-notebooks/HEAD?labpath=Symtegration.ipynb## Project information
### Changes
See [`CHANGELOG.md`] for what has changed.
[`CHANGELOG.md`]: CHANGELOG.md
### Code of conduct
Be nice; see [`CODE_OF_CONDUCT.md`] for details.
[`CODE_OF_CONDUCT.md`]: docs/CODE_OF_CONDUCT.md
### Security policy
See [`SECURITY.md`] for details.
[`SECURITY.md`]: docs/SECURITY.md
### Contributing
See [`CONTRIBUTING.md`] for details.
[`CONTRIBUTING.md`]: docs/CONTRIBUTING.md
### License
Apache 2.0; see [`LICENSE`] for details.
[`LICENSE`]: LICENSE