Liking cljdoc? Tell your friends :D

emmy.series

This namespace contains an implementation of two data types:

  • [[Series]], which represents a generic infinite series of arbitrary values, and
  • [[PowerSeries]], a series that represents a power series in a single variable; in other words, a series where the nth entry is interpreted as the coefficient of $x^n$:
$$[a b c d ...] == $a + bx + cx^2 + dx^3 + ...$$

Many of the functions below draw on the [[emmy.series.impl]] namespace, which implements many of these operations on bare Clojure sequences.

The implementation follows Doug McIlroy's beautiful paper, "Power Series, Power Serious".

Doug also has a 10-line version in Haskell on his website.

This namespace contains an implementation of two data types:

- [[Series]], which represents a generic infinite series of arbitrary values, and
- [[PowerSeries]], a series that represents a power series in a single
variable; in other words, a series where the nth entry is interpreted as
the coefficient of $x^n$:

```
$$[a b c d ...] == $a + bx + cx^2 + dx^3 + ...$$
```

Many of the functions below draw on the [[emmy.series.impl]] namespace,
which implements many of these operations on bare Clojure sequences.

The implementation follows Doug McIlroy's beautiful paper, ["Power Series,
Power
Serious"](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.333.3156&rep=rep1&type=pdf).

Doug also has a 10-line version in Haskell on [his
website](https://www.cs.dartmouth.edu/~doug/powser.html).
raw docstring

->functionclj/s

(->function s)

Accepts a [[Series]] or [[PowerSeries]] and coerces the input to a [[PowerSeries]] without any application. Returns the coerced [[PowerSeries]] instance.

Supplying a non-series will throw.

Accepts a [[Series]] or [[PowerSeries]] and coerces the input to
a [[PowerSeries]] without any application. Returns the coerced [[PowerSeries]]
instance.

Supplying a non-series will throw.
sourceraw docstring

acos-seriesclj/s

source

acot-seriesclj/s

source

arg-scaleclj/s

(arg-scale s factors)

Given a univariate [[PowerSeries]] and a singleton sequence of factors, returns a new [[PowerSeries]] that scales its argument by (first factor) on application.

Given a [[Series]], recursively applies arg-scale to each element, making this ONLY appropriate in its current form for a [[Series]] of [[PowerSeries]] instances.

Given a univariate [[PowerSeries]] and a singleton sequence of `factors`,
returns a new [[PowerSeries]] that scales its argument by `(first factor)` on
application.

Given a [[Series]], recursively applies [[arg-scale]] to each element, making
this ONLY appropriate in its current form for a [[Series]] of [[PowerSeries]]
instances.
sourceraw docstring

arg-shiftclj/s

(arg-shift s shifts)

Given a univariate [[PowerSeries]] and a singleton sequence of shifts, returns a function that, when applied, returns a value equivalent to calling the original s with its argument shifted by (first shifts).

NOTE: arg-shift can't return a [[PowerSeries]] instance because the implementation of compose does not currently allow a constant element in the right-hand series.

Given a [[Series]], recursively applies arg-shift to each element, making this ONLY appropriate in its current form for a [[Series]] of [[PowerSeries]] instances. Returns a [[Series]] of functions.

Given a univariate [[PowerSeries]] and a singleton sequence of `shifts`,
returns a function that, when applied, returns a value equivalent to calling
the original `s` with its argument shifted by `(first shifts)`.

NOTE: [[arg-shift]] can't return a [[PowerSeries]] instance because the
implementation of [[compose]] does not currently allow a constant element in
the right-hand series.

Given a [[Series]], recursively applies [[arg-shift]] to each element, making
this ONLY appropriate in its current form for a [[Series]] of [[PowerSeries]]
instances. Returns a [[Series]] of functions.
sourceraw docstring

asin-seriesclj/s

source

asinh-seriesclj/s

source

atan-seriesclj/s

source

atanh-seriesclj/s

source

bell-seriesclj/s

source

binomial-seriesclj/s

(binomial-series alpha)

Returns a [[PowerSeries]] instance representing a Binomial series, i.e., the taylor series of the function $f$ given by

$$f(x) = (1 + x)^\alpha$$
Returns a [[PowerSeries]] instance representing a
[Binomial series](https://en.wikipedia.org/wiki/Binomial_series), i.e., the
taylor series of the function $f$ given by

```
$$f(x) = (1 + x)^\alpha$$
```
sourceraw docstring

catalan-seriesclj/s

source

composeclj/s

(compose s t)

Returns a new [[PowerSeries]] $U$ that represents the composition of the two input power series $S$ and $T$, where $U$ evaluates like:

$$U(x) = S(T(x))$$
Returns a new [[PowerSeries]] $U$ that represents the composition of the two
input power series $S$ and $T$, where $U$ evaluates like:

```
$$U(x) = S(T(x))$$
```
sourceraw docstring

constantclj/s

(constant c)
(constant c kind)

Returns a [[PowerSeries]] representing the supplied constant term.

Optionally, pass kind of either ::series or ::power-series to specify the type of series returned.

Returns a [[PowerSeries]] representing the supplied constant term.

Optionally, pass `kind` of either `::series` or `::power-series` to specify
the type of series returned.
sourceraw docstring

cos-seriesclj/s

source

cosh-seriesclj/s

source

exp-seriesclj/s

source

fib-seriesclj/s

source

fmapclj/s

(fmap f s)

Returns a new series generated by applying the supplied f to each element in the input series s. The returned series will be the same type as the input series, either [[Series]] or [[PowerSeries]].

NOTE scmutils calls this series:elementwise.

Returns a new series generated by applying the supplied `f` to each element in
the input series `s`. The returned series will be the same type as the input
series, either [[Series]] or [[PowerSeries]].

NOTE scmutils calls this `series:elementwise`.
sourceraw docstring

function->clj/s

(function-> f)
(function-> f & xs)

Returns a [[PowerSeries]] representing the Taylor series expansion of f at the point specified by xs. Multiple arguments are allowed. If no arguments xs are supplied, the expansion point defaults to 0.

The expansion at 0 is also called a 'Maclaurin series'.

NOTE: this function takes derivatives internally, so if you pass a function make sure you require emmy.calculus.derivative to install the derivative implementation for functions. If you pass some other callable, differentiable function-like thing, like a polynomial, this is not necessary.

NOTE: The typical definition of a Taylor series of f expanded around some point x is

$$T(p) = f(x) + \frac{f'(x)}{1!}(p-x) + \frac{f''(x)}{2!} (p-x)^2 + \ldots,$$

where p is the evaluation point. When (= p x), all derivatives of the Taylor series expansion of f will exactly match the derivatives of f itself.

The Taylor series returned here (call it $T'$) is actually a function of dx, where

$$T'(dx) = T(x+dx) = f(x) + \frac{f'(x)}{1!}(dx) + \frac{f''(x)}{2!} (dx)^2 + \ldots.$$

Returns a [[PowerSeries]] representing the [Taylor
series](https://en.wikipedia.org/wiki/Taylor_series) expansion of `f` at the
point specified by `xs`. Multiple arguments are allowed. If no arguments `xs`
are supplied, the expansion point defaults to 0.

The expansion at 0 is also called a 'Maclaurin series'.

NOTE: this function takes derivatives internally, so if you pass a function
make sure you require [[emmy.calculus.derivative]] to install the
derivative implementation for functions. If you pass some other callable,
differentiable function-like thing, like a polynomial, this is not necessary.

NOTE: The typical definition of a Taylor series of `f` expanded around some
point `x` is

$$T(p) = f(x) + \frac{f'(x)}{1!}(p-x) + \frac{f''(x)}{2!} (p-x)^2 + \ldots,$$

where `p` is the evaluation point. When `(= p x)`, all derivatives of the
Taylor series expansion of `f` will exactly match the derivatives of `f`
itself.

The Taylor series returned here (call it $T'$) is actually a function of `dx`,
where

$$T'(dx) = T(x+dx) = f(x) + \frac{f'(x)}{1!}(dx) + \frac{f''(x)}{2!} (dx)^2 + \ldots.$$
sourceraw docstring

generateclj/s

(generate f)
(generate f kind)

Returns a [[PowerSeries]] generated by (f i) for i in 0, 1, ...

Optionally, pass kind of either ::series or ::power-series to specify the type of series returned.

Returns a [[PowerSeries]] generated by `(f i)` for `i` in `0, 1, ...`

Optionally, pass `kind` of either `::series` or `::power-series` to specify
the type of series returned.
sourceraw docstring

harmonic-seriesclj/s

source

identityclj/s

[[PowerSeries]] instance representing the identity function.

[[PowerSeries]] instance representing the identity function.
sourceraw docstring

inflateclj/s

(inflate s n)

Accepts an input series s and an exponent n, and expands the series in the nth power of its argument. Every term i maps to position i*n, with zeros padded in the new missing slots.

For example:

(inflate identity 3)
;; => (series 0 0 0 1)

(take 6 (inflate (generate inc) 3))
;; => (1 0 2 0 3 0)

NOTE this operation makes sense as described for a [[PowerSeries]], where each entry represents the coefficient of some power of x; functionally it still works with [[Series]] objects.

Accepts an input series `s` and an exponent `n`, and expands the series in the
`n`th power of its argument. Every term `i` maps to position `i*n`, with zeros
padded in the new missing slots.

For example:

```clojure
(inflate identity 3)
;; => (series 0 0 0 1)

(take 6 (inflate (generate inc) 3))
;; => (1 0 2 0 3 0)
```

NOTE this operation makes sense as described for a [[PowerSeries]], where each
entry represents the coefficient of some power of `x`; functionally it still
works with [[Series]] objects.
sourceraw docstring

integralclj/s

(integral s)
(integral s constant)

Returns a [[PowerSeries]] $U$ that represents the definite integral of the input power series $S$ with constant term $c$:

$$U = c + \int_0^{\infty} S$$
Returns a [[PowerSeries]] $U$ that represents the definite integral of the
input power series $S$ with constant term $c$:

```
$$U = c + \int_0^{\infty} S$$
```
sourceraw docstring

log1+x-seriesclj/s

source

log1-x-seriesclj/s

source

oneclj/s

[[PowerSeries]] instance representing the constant 1.

[[PowerSeries]] instance representing the constant 1.
sourceraw docstring

partial-sumsclj/s

(partial-sums s)

Returns a series (of the same type as the input) of partial sums of the terms in the supplied series s.

Returns a series (of the same type as the input) of partial sums of the terms
in the supplied series `s`.
sourceraw docstring

power-seriesclj/s

(power-series & prefix)

Return a [[PowerSeries]] starting with the supplied values. The remainder of the series will be filled with the zero-value corresponding to the first of the given values.

If you have a sequence already, prefer power-series*.

Return a [[PowerSeries]] starting with the supplied values. The remainder of
the series will be filled with the zero-value corresponding to the first of
the given values.

If you have a sequence already, prefer [[power-series*]].
sourceraw docstring

power-series*clj/s

(power-series* prefix)

Given a sequence, returns a new [[PowerSeries]] object that wraps that sequence (potentially padding its tail with zeros if it's finite).

Given a sequence, returns a new [[PowerSeries]] object that wraps that
sequence (potentially padding its tail with zeros if it's finite).
sourceraw docstring

power-series?clj/s

(power-series? s)

Returns true if s is specifically a [[PowerSeries]], false otherwise.

Returns true if `s` is specifically a [[PowerSeries]], false otherwise.
sourceraw docstring

revertclj/s

(revert s)

Returns a new [[PowerSeries]] $U$ that represents the compositional inverse (the 'reversion') of the input power series $S$, satisfying:

$$S(U(x)) = x$$
Returns a new [[PowerSeries]] $U$ that represents the compositional inverse (the
'reversion') of the input power series $S$, satisfying:

```
$$S(U(x)) = x$$
```
sourceraw docstring

sec-seriesclj/s

source

seriesclj/s

(series & prefix)

Return a [[Series]] starting with the supplied values. The remainder of the series will be filled with the zero-value corresponding to the first of the given values.

If you have a sequence already, prefer series*.

Return a [[Series]] starting with the supplied values. The remainder of the
series will be filled with the zero-value corresponding to the first of the
given values.

If you have a sequence already, prefer [[series*]].
sourceraw docstring

series*clj/s

(series* prefix)

Given a sequence, returns a new [[Series]] object that wraps that sequence (potentially padding its tail with zeros if it's finite).

Given a sequence, returns a new [[Series]] object that wraps that
sequence (potentially padding its tail with zeros if it's finite).
sourceraw docstring

series?clj/s

(series? s)

Returns true if s is either a [[Series]] or a [[PowerSeries]], false otherwise.

Returns true if `s` is either a [[Series]] or a [[PowerSeries]], false
otherwise.
sourceraw docstring

sin-seriesclj/s

source

sinh-seriesclj/s

source

sumclj/s

(sum s n)

Returns the sum of all elements in the input series s up to order n (inclusive). For example:

(sum (series 1 1 1 1 1 1 1) 3)
;; => 4

NOTE that sum sums the first n + 1 terms, since a series starts with an order 0 term.

Returns the sum of all elements in the input series `s` up to order
`n` (inclusive). For example:

```clojure
(sum (series 1 1 1 1 1 1 1) 3)
;; => 4
```

NOTE that [[sum]] sums the first `n + 1` terms, since a series starts with an
order 0 term.
sourceraw docstring

tan-seriesclj/s

source

tanh-seriesclj/s

source

valueclj/s

(value s xs)

Returns the value of the supplied [[Series]] or [[PowerSeries]] applied to xs.

If a [[PowerSeries]] is supplied, xs (despite its name) must be a single value. Returns a [[Series]] generated by multiplying each ith term in s by $x^i$, where $x$ is the xs argument.

If a [[Series]] s is supplied:

Assumes that s is a series of applicables of arity equal to the count of xs. If, in fact, s is a series of series-valued applicables, then the result will be a sort of layered sum of the values.

Concretely, suppose that s has the form:

[x => [A1 A2 A3...], x => [B1 B2 B3...], x => [C1 C2 C3...], ...]

Then, this series applied to x will yield the new series:

[A1 (+ A2 B1) (+ A3 B2 C1) ...]

The way to think about this is, that if a power series has some other series as the coefficient of the $x^n$ term, the series must shift by $n$ positions before being added into the final total.

Returns the value of the supplied [[Series]] or [[PowerSeries]] applied to `xs`.

If a [[PowerSeries]] is supplied, `xs` (despite its name) must be a single
value. Returns a [[Series]] generated by multiplying each `i`th term in `s` by
$x^i$, where $x$ is the `xs` argument.

If a [[Series]] `s` is supplied:

Assumes that `s` is a series of applicables of arity equal to the count of
`xs`. If, in fact, `s` is a series of series-valued applicables, then the
result will be a sort of layered sum of the values.

Concretely, suppose that `s` has the form:

```
[x => [A1 A2 A3...], x => [B1 B2 B3...], x => [C1 C2 C3...], ...]
```

Then, this series applied to x will yield the new series:

```
[A1 (+ A2 B1) (+ A3 B2 C1) ...]
```

The way to think about this is, that if a power series has some other series
as the coefficient of the $x^n$ term, the series must shift by $n$ positions
before being added into the final total.
sourceraw docstring

xpowclj/s

(xpow n)

Returns a [[PowerSeries]] instance representing $x^n$.

Returns a [[PowerSeries]] instance representing $x^n$.
sourceraw docstring

zeroclj/s

[[PowerSeries]] instance representing the constant 0.

[[PowerSeries]] instance representing the constant 0.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close