| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Polynomial
Synopsis
- data P
- data P₀
- 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) => P -> a -> a
- evalPoly₀ :: (Zero a, Plus a, One a, Times a) => P₀ -> a -> a
- countSummands :: P₀ -> Int
- polynomialOrder :: P -> 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 SingP (a :: P) where
- data SingP₀ (a :: P₀) where
- type family EvalPoly (x :: P) k (arg :: k) :: k where ...
- sEvalPoly :: forall k (x :: P) (arg :: k). (SOne k, SPlus k, STimes k) => SingP x -> Sing arg -> Sing (EvalPoly x k arg)
- type family EvalPoly₀ (x :: P₀) k (arg :: k) :: k where ...
- sEvalPoly₀ :: forall k (x :: P₀) (arg :: k). (SZero k, SOne k, SPlus k, STimes k) => SingP₀ 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 :: P 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 :: Prepresents a constant polynomial{U}(x) = 1S p :: Prepresents 1 plus the polynomial{p}.T p :: Prepresents{p}multiplied by the parameter of the polynomial.
Any nonzero polynomial with coefficients in ℕ can be represented using P.
In fact, they are uniquely represented as a P 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
| One P Source # | |
Defined in Data.Polynomial | |
| Plus P Source # | |
| SCompose P Source # | |
| SId P Source # | |
| SOne P Source # | |
| SPlus P Source # | |
| STimes P Source # | |
| Times P Source # | |
| Show P Source # | |
| Eq P Source # | |
| Ord P Source # | |
| SingKind P Source # | |
| SingI 'U Source # | |
Defined in Data.Polynomial | |
| SingI p => SingI ('S p :: P) Source # | |
Defined in Data.Polynomial | |
| SingI p => SingI ('T p :: P) Source # | |
Defined in Data.Polynomial | |
| type TId P Source # | |
Defined in Data.Polynomial | |
| type TOne P Source # | |
Defined in Data.Polynomial | |
| type Demote P Source # | |
Defined in Data.Polynomial | |
| type Sing Source # | |
Defined in Data.Polynomial | |
| type (x :: P) * (y :: P) Source # | |
Defined in Data.Polynomial | |
| type (x :: P) + (y :: P) Source # | |
Defined in Data.Polynomial | |
| type (x :: P) << (y :: P) Source # | |
Defined in Data.Polynomial | |
Instances
| One P₀ Source # | |
Defined in Data.Polynomial | |
| Plus P₀ Source # | |
| SCompose P₀ Source # | |
| SId P₀ Source # | |
| SOne P₀ Source # | |
| SPlus P₀ Source # | |
| STimes P₀ Source # | |
| SZero P₀ Source # | |
| Times P₀ Source # | |
| Zero P₀ Source # | |
Defined in Data.Polynomial | |
| Show P₀ Source # | |
| Eq P₀ Source # | |
| Ord P₀ Source # | |
| SingKind P₀ Source # | |
| SingI 'Z Source # | |
Defined in Data.Polynomial | |
| SingI p => SingI ('NZ p :: P₀) Source # | |
Defined in Data.Polynomial | |
| type TId P₀ Source # | |
| type TOne P₀ Source # | |
Defined in Data.Polynomial | |
| type TZero P₀ Source # | |
Defined in Data.Polynomial | |
| type Demote P₀ Source # | |
Defined in Data.Polynomial | |
| type Sing Source # | |
Defined in Data.Polynomial | |
| type (x :: P₀) * (y :: P₀) Source # | |
Defined in Data.Polynomial | |
| type (x :: P₀) + (y :: P₀) Source # | |
Defined in Data.Polynomial | |
| type (x :: P₀) << (y :: P₀) Source # | |
Defined in Data.Polynomial | |
Minimal complete definition
Nothing
Minimal complete definition
Nothing
Minimal complete definition
Nothing
Instances
| One P Source # | |
Defined in Data.Polynomial | |
| One P₀ 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 :: P₀ -> Int Source #
polynomialOrder :: P -> Int Source #
Type-level formal polynomials
sEvalPoly :: forall k (x :: P) (arg :: k). (SOne k, SPlus k, STimes k) => SingP x -> Sing arg -> Sing (EvalPoly x k arg) Source #