Liking cljdoc? Tell your friends :D

sicmutils.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 [[sicmutils.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 [[sicmutils.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, ie, 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), ie, 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 & {:keys [x0]})

Returns a PowerSeries representing the Taylor series expansion of f at the value supplied via the keyword argument :x0. :x0 defaults to 0.

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

NOTE: The argument of the returned PowerSeries is interepreted as dx, some delta around the supplied point 0. This differs from the traditional Taylor series definition, where the returned series would align mostly closely with (function-> f :x0 <x0>) when called with x0 as an argument. We do this because it's not possible to create a PowerSeries instance with the that bakes in the x - x0 shift.

NOTE: this function takes derivatives internally, so if you pass a function make sure you require sicmutils.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.

Returns a [[PowerSeries]] representing the [Taylor
series](https://en.wikipedia.org/wiki/Taylor_series) expansion of `f` at the
value supplied via the keyword argument `:x0`. `:x0` defaults to 0.

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

NOTE: The argument of the returned [[PowerSeries]] is interepreted as `dx`,
some delta around the supplied point `0`. This differs from the
traditional [Taylor series](https://en.wikipedia.org/wiki/Taylor_series)
definition, where the returned series would align mostly closely
with `(function-> f :x0 <x0>)` when called with `x0` as an argument. We do
this because it's not possible to create a [[PowerSeries]] instance with the
that bakes in the `x - x0` shift.

NOTE: this function takes derivatives internally, so if you pass a function
make sure you require [[sicmutils.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.
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

PowerSeriescljs

source

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

Seriescljs

source

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