symtegration-0.6.1: Library for symbolic integration of mathematical expressions.
CopyrightCopyright 2025 Yoo Chung
LicenseApache-2.0
Maintainerdev@chungyc.org
Safe HaskellSafe-Inferred
LanguageGHC2021

Symtegration.Polynomial.Solve

Description

This module supports deriving exact solutions to polynomial equations. It cannot derive solutions for all polynomials; it will only return those which it can.

Synopsis

Documentation

solve :: IndexedPolynomial -> Maybe [Expression] Source #

Derive the roots for the given polynomial. Only real roots are returned.

>>> map (toHaskell . simplify) <$> solve (2 * power 1 - 6)
Just ["3"]
>>> map (toHaskell . simplify) <$> solve (power 2 - 4)
Just ["2","-2"]

Returns Nothing if the function does not know how to derive the roots.

complexSolve :: IndexedPolynomial -> Maybe [Expression] Source #

Derive the roots for the given polynomial. All roots are returned, including complex roots.

>>> map (toHaskell . simplify) <$> complexSolve (2 * power 1 - 6)
Just ["3"]
>>> map (toHaskell . simplify) <$> complexSolve (power 2 + 1)
Just ["(-1) ** (1 / 2)","(-1) * (-1) ** (1 / 2)"]
>>> map (toHaskell . simplify) <$> complexSolve (power 3 + 1)
Just ["-1","(-1) * ((-1) + (-1) ** (1 / 2) * 3 ** (1 / 2)) / 2","(-1) * ((-1) + (-1) * (-1) ** (1 / 2) * 3 ** (1 / 2)) / 2"]

Returns Nothing if the function does not know how to derive the roots.