finite-polynomial
Safe HaskellNone
LanguageHaskell2010

Data.Polynomial

Synopsis

Formal polynomials with natural-number (ℕ) coefficients

data Poly Source #

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 :: Poly represents a constant polynomial {U}(x) = 1
  • S p :: Poly represents 1 plus the polynomial {p}.
  • T p :: Poly represents {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

Constructors

U 
S Poly 
T Poly 

Instances

Instances details
Show Poly Source # 
Instance details

Defined in Data.Polynomial

Methods

showsPrec :: Int -> Poly -> ShowS #

show :: Poly -> String #

showList :: [Poly] -> ShowS #

One Poly Source # 
Instance details

Defined in Data.Polynomial

Methods

one :: Poly Source #

Plus Poly Source # 
Instance details

Defined in Data.Polynomial

Methods

plus :: Poly -> Poly -> Poly Source #

SCompose Poly Source # 
Instance details

Defined in Data.Polynomial

Associated Types

type (x :: Poly) << (y :: Poly) 
Instance details

Defined in Data.Polynomial

type (x :: Poly) << (y :: Poly)

Methods

(%<<) :: forall (x :: Poly) (y :: Poly). Sing x -> Sing y -> Sing (x << y) Source #

SId Poly Source # 
Instance details

Defined in Data.Polynomial

Associated Types

type TId Poly 
Instance details

Defined in Data.Polynomial

type TId Poly = 'S 'U

Methods

sId :: Sing (TId Poly) Source #

SOne Poly Source # 
Instance details

Defined in Data.Polynomial

Associated Types

type TOne Poly 
Instance details

Defined in Data.Polynomial

type TOne Poly = 'U

Methods

sOne :: Sing (TOne Poly) Source #

SPlus Poly Source # 
Instance details

Defined in Data.Polynomial

Associated Types

type (x :: Poly) + (y :: Poly) 
Instance details

Defined in Data.Polynomial

type (x :: Poly) + (y :: Poly)

Methods

(%+) :: forall (x :: Poly) (y :: Poly). Sing x -> Sing y -> Sing (x + y) Source #

STimes Poly Source # 
Instance details

Defined in Data.Polynomial

Associated Types

type (x :: Poly) * (y :: Poly) 
Instance details

Defined in Data.Polynomial

type (x :: Poly) * (y :: Poly)

Methods

(%*) :: forall (x :: Poly) (y :: Poly). Sing x -> Sing y -> Sing (x * y) Source #

Times Poly Source # 
Instance details

Defined in Data.Polynomial

Methods

times :: Poly -> Poly -> Poly Source #

Eq Poly Source # 
Instance details

Defined in Data.Polynomial

Methods

(==) :: Poly -> Poly -> Bool #

(/=) :: Poly -> Poly -> Bool #

Ord Poly Source # 
Instance details

Defined in Data.Polynomial

Methods

compare :: Poly -> Poly -> Ordering #

(<) :: Poly -> Poly -> Bool #

(<=) :: Poly -> Poly -> Bool #

(>) :: Poly -> Poly -> Bool #

(>=) :: Poly -> Poly -> Bool #

max :: Poly -> Poly -> Poly #

min :: Poly -> Poly -> Poly #

SingKind Poly Source # 
Instance details

Defined in Data.Polynomial

Associated Types

type Demote Poly 
Instance details

Defined in Data.Polynomial

Methods

fromSing :: forall (a :: Poly). Sing a -> Demote Poly #

toSing :: Demote Poly -> SomeSing Poly #

SingI 'U Source # 
Instance details

Defined in Data.Polynomial

Methods

sing :: Sing 'U #

SingI p => SingI ('S p :: Poly) Source # 
Instance details

Defined in Data.Polynomial

Methods

sing :: Sing ('S p) #

SingI p => SingI ('T p :: Poly) Source # 
Instance details

Defined in Data.Polynomial

Methods

sing :: Sing ('T p) #

type TId Poly Source # 
Instance details

Defined in Data.Polynomial

type TId Poly = 'S 'U
type TOne Poly Source # 
Instance details

Defined in Data.Polynomial

type TOne Poly = 'U
type Demote Poly Source # 
Instance details

Defined in Data.Polynomial

type Sing Source # 
Instance details

Defined in Data.Polynomial

type Sing = SPoly
type (x :: Poly) * (y :: Poly) Source # 
Instance details

Defined in Data.Polynomial

type (x :: Poly) * (y :: Poly)
type (x :: Poly) + (y :: Poly) Source # 
Instance details

Defined in Data.Polynomial

type (x :: Poly) + (y :: Poly)
type (x :: Poly) << (y :: Poly) Source # 
Instance details

Defined in Data.Polynomial

type (x :: Poly) << (y :: Poly)

data Poly₀ Source #

Poly₀ is either zero or a Poly.

{Z}(x) = 0
{NZ p}(x) = {p}(x)

Constructors

Z 
NZ Poly 

Instances

Instances details
Show Poly₀ Source # 
Instance details

Defined in Data.Polynomial

One Poly₀ Source # 
Instance details

Defined in Data.Polynomial

Methods

one :: Poly₀ Source #

Plus Poly₀ Source # 
Instance details

Defined in Data.Polynomial

SCompose Poly₀ Source # 
Instance details

Defined in Data.Polynomial

Associated Types

type (x :: Poly₀) << (y :: Poly₀) 
Instance details

Defined in Data.Polynomial

type (x :: Poly₀) << (y :: Poly₀)

Methods

(%<<) :: forall (x :: Poly₀) (y :: Poly₀). Sing x -> Sing y -> Sing (x << y) Source #

SId Poly₀ Source # 
Instance details

Defined in Data.Polynomial

Associated Types

type TId Poly₀ 
Instance details

Defined in Data.Polynomial

type TId Poly₀ = 'NZ ('S 'U)

Methods

sId :: Sing (TId Poly₀) Source #

SOne Poly₀ Source # 
Instance details

Defined in Data.Polynomial

Associated Types

type TOne Poly₀ 
Instance details

Defined in Data.Polynomial

type TOne Poly₀ = 'NZ 'U
SPlus Poly₀ Source # 
Instance details

Defined in Data.Polynomial

Associated Types

type (x :: Poly₀) + (y :: Poly₀) 
Instance details

Defined in Data.Polynomial

type (x :: Poly₀) + (y :: Poly₀)

Methods

(%+) :: forall (x :: Poly₀) (y :: Poly₀). Sing x -> Sing y -> Sing (x + y) Source #

STimes Poly₀ Source # 
Instance details

Defined in Data.Polynomial

Associated Types

type (x :: Poly₀) * (y :: Poly₀) 
Instance details

Defined in Data.Polynomial

type (x :: Poly₀) * (y :: Poly₀)

Methods

(%*) :: forall (x :: Poly₀) (y :: Poly₀). Sing x -> Sing y -> Sing (x * y) Source #

SZero Poly₀ Source # 
Instance details

Defined in Data.Polynomial

Associated Types

type TZero Poly₀ 
Instance details

Defined in Data.Polynomial

type TZero Poly₀ = 'Z
Times Poly₀ Source # 
Instance details

Defined in Data.Polynomial

Zero Poly₀ Source # 
Instance details

Defined in Data.Polynomial

Methods

zero :: Poly₀ Source #

Eq Poly₀ Source # 
Instance details

Defined in Data.Polynomial

Methods

(==) :: Poly₀ -> Poly₀ -> Bool #

(/=) :: Poly₀ -> Poly₀ -> Bool #

Ord Poly₀ Source # 
Instance details

Defined in Data.Polynomial

SingKind Poly₀ Source # 
Instance details

Defined in Data.Polynomial

Associated Types

type Demote Poly₀ 
Instance details

Defined in Data.Polynomial

Methods

fromSing :: forall (a :: Poly₀). Sing a -> Demote Poly₀ #

toSing :: Demote Poly₀ -> SomeSing Poly₀ #

SingI 'Z Source # 
Instance details

Defined in Data.Polynomial

Methods

sing :: Sing 'Z #

SingI p => SingI ('NZ p :: Poly₀) Source # 
Instance details

Defined in Data.Polynomial

Methods

sing :: Sing ('NZ p) #

type TId Poly₀ Source # 
Instance details

Defined in Data.Polynomial

type TId Poly₀ = 'NZ ('S 'U)
type TOne Poly₀ Source # 
Instance details

Defined in Data.Polynomial

type TOne Poly₀ = 'NZ 'U
type TZero Poly₀ Source # 
Instance details

Defined in Data.Polynomial

type TZero Poly₀ = 'Z
type Demote Poly₀ Source # 
Instance details

Defined in Data.Polynomial

type Sing Source # 
Instance details

Defined in Data.Polynomial

type Sing = SPoly₀
type (x :: Poly₀) * (y :: Poly₀) Source # 
Instance details

Defined in Data.Polynomial

type (x :: Poly₀) * (y :: Poly₀)
type (x :: Poly₀) + (y :: Poly₀) Source # 
Instance details

Defined in Data.Polynomial

type (x :: Poly₀) + (y :: Poly₀)
type (x :: Poly₀) << (y :: Poly₀) Source # 
Instance details

Defined in Data.Polynomial

type (x :: Poly₀) << (y :: Poly₀)

class Zero a where Source #

Minimal complete definition

Nothing

Methods

zero :: a Source #

default zero :: Num a => a Source #

Instances

Instances details
Zero Poly₀ Source # 
Instance details

Defined in Data.Polynomial

Methods

zero :: Poly₀ Source #

Zero Natural Source # 
Instance details

Defined in Data.Polynomial

Methods

zero :: Natural Source #

Zero Int Source # 
Instance details

Defined in Data.Polynomial

Methods

zero :: Int Source #

(Bounded a, Ord a) => Zero (Max a) Source # 
Instance details

Defined in Data.Polynomial

Methods

zero :: Max a Source #

class Plus a where Source #

Minimal complete definition

Nothing

Methods

plus :: a -> a -> a Source #

default plus :: Num a => a -> a -> a Source #

Instances

Instances details
Plus Poly Source # 
Instance details

Defined in Data.Polynomial

Methods

plus :: Poly -> Poly -> Poly Source #

Plus Poly₀ Source # 
Instance details

Defined in Data.Polynomial

Plus Natural Source # 
Instance details

Defined in Data.Polynomial

Plus Int Source # 
Instance details

Defined in Data.Polynomial

Methods

plus :: Int -> Int -> Int Source #

Ord a => Plus (Max a) Source #

max-plus algebra (assuming addition in Num preserves order)

Instance details

Defined in Data.Polynomial

Methods

plus :: Max a -> Max a -> Max a Source #

class One a where Source #

Minimal complete definition

Nothing

Methods

one :: a Source #

default one :: Num a => a Source #

Instances

Instances details
One Poly Source # 
Instance details

Defined in Data.Polynomial

Methods

one :: Poly Source #

One Poly₀ Source # 
Instance details

Defined in Data.Polynomial

Methods

one :: Poly₀ Source #

One Natural Source # 
Instance details

Defined in Data.Polynomial

Methods

one :: Natural Source #

One Int Source # 
Instance details

Defined in Data.Polynomial

Methods

one :: Int Source #

(Ord a, Num a) => One (Max a) Source #

max-plus algebra (assuming addition in Num preserves order)

Instance details

Defined in Data.Polynomial

Methods

one :: Max a Source #

class Times a where Source #

Minimal complete definition

Nothing

Methods

times :: a -> a -> a Source #

default times :: Num a => a -> a -> a Source #

Instances

Instances details
Times Poly Source # 
Instance details

Defined in Data.Polynomial

Methods

times :: Poly -> Poly -> Poly Source #

Times Poly₀ Source # 
Instance details

Defined in Data.Polynomial

Times Natural Source # 
Instance details

Defined in Data.Polynomial

Times Int Source # 
Instance details

Defined in Data.Polynomial

Methods

times :: Int -> Int -> Int Source #

(Ord a, Num a) => Times (Max a) Source #

max-plus algebra

Instance details

Defined in Data.Polynomial

Methods

times :: Max a -> Max a -> Max a Source #

evalPoly :: (Plus a, One a, Times a) => Poly -> a -> a Source #

evalPoly₀ :: (Zero a, Plus a, One a, Times a) => Poly₀ -> a -> a Source #

Type-level formal polynomials

class SZero k where Source #

Associated Types

type TZero k :: k Source #

Methods

sZero :: Sing (TZero k) Source #

Instances

Instances details
SZero Poly₀ Source # 
Instance details

Defined in Data.Polynomial

Associated Types

type TZero Poly₀ 
Instance details

Defined in Data.Polynomial

type TZero Poly₀ = 'Z

class SPlus k where Source #

Associated Types

type (x :: k) + (y :: k) :: k infixl 6 Source #

Methods

(%+) :: forall (x :: k) (y :: k). Sing x -> Sing y -> Sing (x + y) infixl 6 Source #

Instances

Instances details
SPlus Poly Source # 
Instance details

Defined in Data.Polynomial

Associated Types

type (x :: Poly) + (y :: Poly) 
Instance details

Defined in Data.Polynomial

type (x :: Poly) + (y :: Poly)

Methods

(%+) :: forall (x :: Poly) (y :: Poly). Sing x -> Sing y -> Sing (x + y) Source #

SPlus Poly₀ Source # 
Instance details

Defined in Data.Polynomial

Associated Types

type (x :: Poly₀) + (y :: Poly₀) 
Instance details

Defined in Data.Polynomial

type (x :: Poly₀) + (y :: Poly₀)

Methods

(%+) :: forall (x :: Poly₀) (y :: Poly₀). Sing x -> Sing y -> Sing (x + y) Source #

class SOne k where Source #

Associated Types

type TOne k :: k Source #

Methods

sOne :: Sing (TOne k) Source #

Instances

Instances details
SOne Poly Source # 
Instance details

Defined in Data.Polynomial

Associated Types

type TOne Poly 
Instance details

Defined in Data.Polynomial

type TOne Poly = 'U

Methods

sOne :: Sing (TOne Poly) Source #

SOne Poly₀ Source # 
Instance details

Defined in Data.Polynomial

Associated Types

type TOne Poly₀ 
Instance details

Defined in Data.Polynomial

type TOne Poly₀ = 'NZ 'U

class STimes k where Source #

Associated Types

type (x :: k) * (y :: k) :: k infixl 7 Source #

Methods

(%*) :: forall (x :: k) (y :: k). Sing x -> Sing y -> Sing (x * y) infixl 7 Source #

Instances

Instances details
STimes Poly Source # 
Instance details

Defined in Data.Polynomial

Associated Types

type (x :: Poly) * (y :: Poly) 
Instance details

Defined in Data.Polynomial

type (x :: Poly) * (y :: Poly)

Methods

(%*) :: forall (x :: Poly) (y :: Poly). Sing x -> Sing y -> Sing (x * y) Source #

STimes Poly₀ Source # 
Instance details

Defined in Data.Polynomial

Associated Types

type (x :: Poly₀) * (y :: Poly₀) 
Instance details

Defined in Data.Polynomial

type (x :: Poly₀) * (y :: Poly₀)

Methods

(%*) :: forall (x :: Poly₀) (y :: Poly₀). Sing x -> Sing y -> Sing (x * y) Source #

class SId k where Source #

Associated Types

type TId k :: k Source #

Methods

sId :: Sing (TId k) Source #

Instances

Instances details
SId Poly Source # 
Instance details

Defined in Data.Polynomial

Associated Types

type TId Poly 
Instance details

Defined in Data.Polynomial

type TId Poly = 'S 'U

Methods

sId :: Sing (TId Poly) Source #

SId Poly₀ Source # 
Instance details

Defined in Data.Polynomial

Associated Types

type TId Poly₀ 
Instance details

Defined in Data.Polynomial

type TId Poly₀ = 'NZ ('S 'U)

Methods

sId :: Sing (TId Poly₀) Source #

class SCompose k where Source #

Associated Types

type (x :: k) << (y :: k) :: k infixl 8 Source #

Methods

(%<<) :: forall (x :: k) (y :: k). Sing x -> Sing y -> Sing (x << y) infixl 8 Source #

Instances

Instances details
SCompose Poly Source # 
Instance details

Defined in Data.Polynomial

Associated Types

type (x :: Poly) << (y :: Poly) 
Instance details

Defined in Data.Polynomial

type (x :: Poly) << (y :: Poly)

Methods

(%<<) :: forall (x :: Poly) (y :: Poly). Sing x -> Sing y -> Sing (x << y) Source #

SCompose Poly₀ Source # 
Instance details

Defined in Data.Polynomial

Associated Types

type (x :: Poly₀) << (y :: Poly₀) 
Instance details

Defined in Data.Polynomial

type (x :: Poly₀) << (y :: Poly₀)

Methods

(%<<) :: forall (x :: Poly₀) (y :: Poly₀). Sing x -> Sing y -> Sing (x << y) Source #

data SPoly (a :: Poly) where Source #

Constructors

SingU :: SPoly 'U 
SingS :: forall (p :: Poly). SPoly p -> SPoly ('S p) 
SingT :: forall (p :: Poly). SPoly p -> SPoly ('T p) 

Instances

Instances details
Show (SPoly p) Source # 
Instance details

Defined in Data.Polynomial

Methods

showsPrec :: Int -> SPoly p -> ShowS #

show :: SPoly p -> String #

showList :: [SPoly p] -> ShowS #

data SPoly₀ (a :: Poly₀) where Source #

Constructors

SingZ :: SPoly₀ 'Z 
SingNZ :: forall (p :: Poly). SPoly p -> SPoly₀ ('NZ p) 

Instances

Instances details
Show (SPoly₀ p) Source # 
Instance details

Defined in Data.Polynomial

Methods

showsPrec :: Int -> SPoly₀ p -> ShowS #

show :: SPoly₀ p -> String #

showList :: [SPoly₀ p] -> ShowS #

type family EvalPoly (x :: Poly) k (arg :: k) :: k where ... Source #

Equations

EvalPoly 'U k (_1 :: k) = TOne k 
EvalPoly ('S p) k (arg :: k) = TOne k + EvalPoly p k arg 
EvalPoly ('T p) k (arg :: k) = arg * EvalPoly p k arg 

sEvalPoly :: forall k (x :: Poly) (arg :: k). (SOne k, SPlus k, STimes k) => SPoly x -> Sing arg -> Sing (EvalPoly x k arg) Source #

type family EvalPoly₀ (x :: Poly₀) k (arg :: k) :: k where ... Source #

Equations

EvalPoly₀ 'Z k (_1 :: k) = TZero k 
EvalPoly₀ ('NZ p) k (arg :: k) = EvalPoly p k arg 

sEvalPoly₀ :: forall k (x :: Poly₀) (arg :: k). (SZero k, SOne k, SPlus k, STimes k) => SPoly₀ x -> Sing arg -> Sing (EvalPoly₀ x k arg) Source #