Copyright | Copyright 2025 Yoo Chung |
---|---|
License | Apache-2.0 |
Maintainer | dev@chungyc.org |
Safe Haskell | Safe-Inferred |
Language | GHC2021 |
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
- solve :: IndexedPolynomial -> Maybe [Expression]
- complexSolve :: IndexedPolynomial -> Maybe [Expression]
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.