circuits-diff
Safe HaskellNone
LanguageGHC2024

Circuit.Diff.Jet

Description

Jets via truncated Taylor series.

A Jet is a finite tower of Taylor coefficients

c0 + c1*h + c2*h^2 + ... + cn*h^n

around a primal point. Elementary functions act coefficient-wise via the usual dual-number recurrences, so a NumHask-polymorphic function f :: (ExpField a, TrigField a) => a -> a applied to variable n a returns the first n+1 Taylor coefficients of f at a.

This is the "iterated" direction of Diff: where Diff carries one pullback, a jet carries the whole truncated tower. The two interoperate through 'jetFromDiff, which seeds the tower from a first-order pullback.

Synopsis

Jet type

newtype Jet a Source #

Truncated Taylor series stored as coefficients [c0, c1, ..., cn] representing c0 + c1*h + c2*h^2 + ... + cn*h^n.

Constructors

Jet 

Fields

Instances

Instances details
Eq a => Eq (Jet a) Source # 
Instance details

Defined in Circuit.Diff.Jet

Methods

(==) :: Jet a -> Jet a -> Bool #

(/=) :: Jet a -> Jet a -> Bool #

Show a => Show (Jet a) Source # 
Instance details

Defined in Circuit.Diff.Jet

Methods

showsPrec :: Int -> Jet a -> ShowS #

show :: Jet a -> String #

showList :: [Jet a] -> ShowS #

Additive a => Additive (Jet a) Source # 
Instance details

Defined in Circuit.Diff.Jet

Methods

(+) :: Jet a -> Jet a -> Jet a #

zero :: Jet a #

Subtractive a => Subtractive (Jet a) Source # 
Instance details

Defined in Circuit.Diff.Jet

Methods

negate :: Jet a -> Jet a #

(-) :: Jet a -> Jet a -> Jet a #

(Subtractive a, Divisive a, ExpField a, FromInteger a) => ExpField (Jet a) Source # 
Instance details

Defined in Circuit.Diff.Jet

Methods

exp :: Jet a -> Jet a #

log :: Jet a -> Jet a #

(**) :: Jet a -> Jet a -> Jet a #

logBase :: Jet a -> Jet a -> Jet a #

sqrt :: Jet a -> Jet a #

(Subtractive a, Divisive a, ExpField a, TrigField a, FromInteger a) => TrigField (Jet a) Source # 
Instance details

Defined in Circuit.Diff.Jet

Methods

pi :: Jet a #

sin :: Jet a -> Jet a #

cos :: Jet a -> Jet a #

tan :: Jet a -> Jet a #

asin :: Jet a -> Jet a #

acos :: Jet a -> Jet a #

atan :: Jet a -> Jet a #

atan2 :: Jet a -> Jet a -> Jet a #

sinh :: Jet a -> Jet a #

cosh :: Jet a -> Jet a #

tanh :: Jet a -> Jet a #

asinh :: Jet a -> Jet a #

acosh :: Jet a -> Jet a #

atanh :: Jet a -> Jet a #

(Additive a, Subtractive a, Multiplicative a, Divisive a) => Divisive (Jet a) Source # 
Instance details

Defined in Circuit.Diff.Jet

Methods

recip :: Jet a -> Jet a #

(/) :: Jet a -> Jet a -> Jet a #

(Additive a, Multiplicative a) => Multiplicative (Jet a) Source # 
Instance details

Defined in Circuit.Diff.Jet

Methods

(*) :: Jet a -> Jet a -> Jet a #

one :: Jet a #

FromInteger a => FromInteger (Jet a) Source # 
Instance details

Defined in Circuit.Diff.Jet

Methods

fromInteger :: Integer -> Jet a #

jetOrder :: Jet a -> Int Source #

Highest power of h present.

Construction

variable :: (Additive a, Multiplicative a) => Int -> a -> Jet a Source #

Build a jet of order n representing the input variable a + h.

constant :: Additive a => Int -> a -> Jet a Source #

Build a constant jet of order n.

fromDiff :: forall {k} a (p :: k). Multiplicative a => Diff p a a -> a -> Jet a Source #

Seed a first-order jet from a Diff first derivative.

Higher derivatives are not recovered from a bare Diff; use taylor with a NumHask-polymorphic function for automatic higher-order towers.

Coefficient views

taylorDers :: (Additive a, Multiplicative a, FromInteger a) => Jet a -> [a] Source #

Convert Taylor coefficients to raw derivatives.

taylorDers (Jet [c0, c1, c2]) = [c0, 1!*c1, 2!*c2]

taylor :: (ExpField a, FromInteger a) => (Jet a -> Jet a) -> Int -> a -> [a] Source #

Apply a jet-level function at a point and return the raw derivatives [f(a), f'(a), f''(a), ..., f^(n)(a)].

Series operations

differentiate :: (Multiplicative a, FromInteger a) => Jet a -> Jet a Source #

Term-by-term differentiation of a Taylor series.

differentiate (Jet [c0, c1, c2, c3]) = Jet [c1, 2*c2, 3*c3]

integrate :: (Divisive a, FromInteger a) => a -> Jet a -> Jet a Source #

Term-by-term integration with supplied constant.

integrate c0 (Jet [d0, d1, d2]) = Jet [c0, d0, d1/2, d2/3]

scale :: Multiplicative a => a -> Jet a -> Jet a Source #

Scale every coefficient by a scalar.

resize :: Additive a => Int -> Jet a -> Jet a Source #

Truncate / pad to the given order.