| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Polynomial
Synopsis
- data Poly
- data Poly₀
- class Zero a where
- zero :: a
- class Plus a where
- plus :: a -> a -> a
- class One a where
- one :: a
- class Times a where
- times :: a -> a -> a
- evalPoly :: (Plus a, One a, Times a) => Poly -> a -> a
- evalPoly₀ :: (Zero a, Plus a, One a, Times a) => Poly₀ -> a -> a
- countSummands :: Poly₀ -> Int
- polynomialOrder :: Poly -> Int
- class SZero k where
- class SPlus k where
- class SOne k where
- class STimes k where
- class SId k where
- class SCompose k where
- data SPoly (a :: Poly) where
- data SPoly₀ (a :: Poly₀) where
- type family EvalPoly (x :: Poly) k (arg :: k) :: k where ...
- sEvalPoly :: forall k (x :: Poly) (arg :: k). (SOne k, SPlus k, STimes k) => SPoly x -> Sing arg -> Sing (EvalPoly x k arg)
- type family EvalPoly₀ (x :: Poly₀) k (arg :: k) :: k where ...
- sEvalPoly₀ :: forall k (x :: Poly₀) (arg :: k). (SZero k, SOne k, SPlus k, STimes k) => SPoly₀ x -> Sing arg -> Sing (EvalPoly₀ x k arg)
Formal polynomials with natural-number (ℕ) coefficients
A nonzero formal polynomial with natural-number coefficient. If we write {p} for the
meaning of p :: Poly as a polynomial, the following holds:
{U}(x) = 1
{S p}(x) = 1 + {p}(x)
{T p}(x) = x * {p}(x)
In other words:
U :: Polyrepresents a constant polynomial{U}(x) = 1S p :: Polyrepresents 1 plus the polynomial{p}.T p :: Polyrepresents{p}multiplied by the parameter of the polynomial.
Any nonzero polynomial with coefficients in ℕ can be represented using Poly.
In fact, they are uniquely represented as a Poly value.
For example, 1 + x^2 + x^3 is uniquely represented as S (T (T (S (T U)))).
{S (T (T (S (T U))))}(x)
= 1 + {T (T (S (T U)))}(x)
= 1 + x * {T (S (T U))}(x)
= 1 + x * x * {S (T U)}(x)
= 1 + x * x * (1 + {T U}(x))
= 1 + x * x * (1 + x * {U}(x))
= 1 + x * x * (1 + x * 1)
= 1 + x^2 + x^3
Instances
| Show Poly Source # | |
| One Poly Source # | |
Defined in Data.Polynomial | |
| Plus Poly Source # | |
| SCompose Poly Source # | |
| SId Poly Source # | |
| SOne Poly Source # | |
| SPlus Poly Source # | |
| STimes Poly Source # | |
| Times Poly Source # | |
| Eq Poly Source # | |
| Ord Poly Source # | |
| SingKind Poly Source # | |
| SingI 'U Source # | |
Defined in Data.Polynomial | |
| SingI p => SingI ('S p :: Poly) Source # | |
Defined in Data.Polynomial | |
| SingI p => SingI ('T p :: Poly) Source # | |
Defined in Data.Polynomial | |
| type TId Poly Source # | |
Defined in Data.Polynomial | |
| type TOne Poly Source # | |
Defined in Data.Polynomial | |
| type Demote Poly Source # | |
Defined in Data.Polynomial | |
| type Sing Source # | |
Defined in Data.Polynomial | |
| type (x :: Poly) * (y :: Poly) Source # | |
Defined in Data.Polynomial | |
| type (x :: Poly) + (y :: Poly) Source # | |
Defined in Data.Polynomial | |
| type (x :: Poly) << (y :: Poly) Source # | |
Defined in Data.Polynomial | |
Instances
| Show Poly₀ Source # | |
| One Poly₀ Source # | |
Defined in Data.Polynomial | |
| Plus Poly₀ Source # | |
| SCompose Poly₀ Source # | |
| SId Poly₀ Source # | |
| SOne Poly₀ Source # | |
| SPlus Poly₀ Source # | |
| STimes Poly₀ Source # | |
| SZero Poly₀ Source # | |
| Times Poly₀ Source # | |
| Zero Poly₀ Source # | |
Defined in Data.Polynomial | |
| Eq Poly₀ Source # | |
| Ord Poly₀ Source # | |
| SingKind Poly₀ Source # | |
| SingI 'Z Source # | |
Defined in Data.Polynomial | |
| SingI p => SingI ('NZ p :: Poly₀) Source # | |
Defined in Data.Polynomial | |
| type TId Poly₀ Source # | |
| type TOne Poly₀ Source # | |
Defined in Data.Polynomial | |
| type TZero Poly₀ Source # | |
Defined in Data.Polynomial | |
| type Demote Poly₀ Source # | |
Defined in Data.Polynomial | |
| type Sing Source # | |
Defined in Data.Polynomial | |
| type (x :: Poly₀) * (y :: Poly₀) Source # | |
Defined in Data.Polynomial | |
| type (x :: Poly₀) + (y :: Poly₀) Source # | |
Defined in Data.Polynomial | |
| type (x :: Poly₀) << (y :: Poly₀) Source # | |
Defined in Data.Polynomial | |
Minimal complete definition
Nothing
Minimal complete definition
Nothing
Minimal complete definition
Nothing
Instances
| One Poly Source # | |
Defined in Data.Polynomial | |
| One Poly₀ Source # | |
Defined in Data.Polynomial | |
| One Natural Source # | |
Defined in Data.Polynomial | |
| One Int Source # | |
Defined in Data.Polynomial | |
| (Ord a, Num a) => One (Max a) Source # | max-plus algebra (assuming addition in |
Defined in Data.Polynomial | |
Minimal complete definition
Nothing
countSummands :: Poly₀ -> Int Source #
polynomialOrder :: Poly -> Int Source #
Type-level formal polynomials
sEvalPoly :: forall k (x :: Poly) (arg :: k). (SOne k, SPlus k, STimes k) => SPoly x -> Sing arg -> Sing (EvalPoly x k arg) Source #