| Copyright | Copyright 2025 Yoo Chung |
|---|---|
| License | Apache-2.0 |
| Maintainer | dev@chungyc.org |
| Safe Haskell | Safe-Inferred |
| Language | GHC2021 |
Symtegration.Polynomial.Rational
Description
Provides a representation for rational functions, which are functions of ratios for two polynomials. Note that these are not functions of rational numbers.
Synopsis
- data Function a
- fromPolynomial :: (Polynomial p e c, Num (p e c)) => p e c -> Function (p e c)
- fromPolynomials :: (Polynomial p e c, Eq (p e c), Num (p e c), Fractional c) => p e c -> p e c -> Function (p e c)
- toPolynomial :: (Polynomial p e c, Eq (p e c), Num (p e c), Fractional c) => Function (p e c) -> Maybe (p e c)
- pattern Function :: a -> a -> Function a
Documentation
Represents a rational function.
Values can be constructed with fromPolynomial and fromPolynomials,
while the numerator and denominator can be obtained by pattern matching with Function.
Internally, common factors will be canceled out and the denominator will be monic.
>>>fromPolynomial $ power 1 :: Function IndexedPolynomialFunction (x) (1)>>>fromPolynomials (power 2 + 1) (power 3 + 1) :: Function IndexedPolynomialFunction (x^2 + 1) (x^3 + 1)>>>let (Function p q) = fromPolynomials (power 2) (power 1 + 1) :: Function IndexedPolynomial>>>(p, q)(x^2,x + 1)>>>fromPolynomials (4 * power 2 - 4) (2 * power 1 - 2 :: IndexedPolynomial)Function (2x + 2) (1)
The type is an instance of the Fractional type class, so values can be added,
subtracted, multiplied, and divided. Their values can also be given as
integer literals as well.
>>>let p = fromPolynomials (power 2 + 1) (power 3 + 1) :: Function IndexedPolynomial>>>let q = fromPolynomials (power 1) (power 2 - 1) :: Function IndexedPolynomial>>>p + qFunction (2x^3 + (-2)x^2 + 2x + (-1)) (x^4 + (-1)x^3 + x + (-1))>>>p * qFunction (x^3 + x) (x^5 + (-1)x^3 + x^2 + (-1))>>>0 :: Function IndexedPolynomialFunction (0) (1)>>>5 :: Function IndexedPolynomialFunction (5) (1)
One could import this module with an alias so that Rational.Function can be
used as the name of the type for rational functions.
>>>import Symtegration.Polynomial.Rational as Rational>>>fromPolynomials (power 1) (power 2 + 1) :: Rational.Function IndexedPolynomialFunction (x) (x^2 + 1)
Instances
fromPolynomial :: (Polynomial p e c, Num (p e c)) => p e c -> Function (p e c) Source #
Returns an equivalent rational function from a given polynomial.
>>>fromPolynomial (power 2 + 1 :: IndexedPolynomial)Function (x^2 + 1) (1)
Arguments
| :: (Polynomial p e c, Eq (p e c), Num (p e c), Fractional c) | |
| => p e c | Numerator \(a\). |
| -> p e c | Denominator \(d\). |
| -> Function (p e c) | Rational function \(\frac{a}{d}\). |
Returns a rational function with the ratio of two polynomials.
>>>fromPolynomials (power 1) (power 2 + 1 :: IndexedPolynomial)Function (x) (x^2 + 1)
toPolynomial :: (Polynomial p e c, Eq (p e c), Num (p e c), Fractional c) => Function (p e c) -> Maybe (p e c) Source #
Returns an equivalent polynomial from a rational function if possible.
It returns the numerator if the denominator is a constant.
>>>toPolynomial $ fromPolynomials (2 * power 1 + 2) (2 :: IndexedPolynomial)Just x + 1
It returns nothing if the rational function is not equivalent to a polynomial.
>>>toPolynomial $ fromPolynomials 1 (power 1 :: IndexedPolynomial)Nothing
pattern Function :: a -> a -> Function a Source #
Pattern synonym for matching the numerator and denominator of a rational function. This would be equivalent to a data constructor, except it cannot be used for constructing a rational function.
>>>let (Function p q) = fromPolynomials (power 2) (power 1 + 1) :: Function IndexedPolynomial>>>px^2>>>qx + 1