The home of most of the Emmy extensible generic operations. The bulk of
the others live in emmy.value
.
See the Generics
cljdocs
for a detailed discussion of how to use and extend the generic operations
defined in emmy.generic
and emmy.value
.
The home of most of the Emmy extensible generic operations. The bulk of the others live in [[emmy.value]]. See [the `Generics` cljdocs](https://cljdoc.org/d/org.mentat/emmy/CURRENT/doc/basics/generics) for a detailed discussion of how to use and extend the generic operations defined in [[emmy.generic]] and [[emmy.value]].
(*)
(* x)
(* x y)
(* x y & more)
Generic implementation of *
. Returns the product of all supplied
arguments. (*)
returns 1, the multiplicative identity.
When applied between numbers, acts like clojure.core/*
. Dispatch is open,
however, making it possible to 'multiply' types wherever the behavior is
mathematically sound.
For example:
(* 2 #emmy/complex "3 + 1i")
;;=> #emmy/complex "6 + 2i"
Generic implementation of `*`. Returns the product of all supplied arguments. `(*)` returns 1, the multiplicative identity. When applied between numbers, acts like `clojure.core/*`. Dispatch is open, however, making it possible to 'multiply' types wherever the behavior is mathematically sound. For example: ```clojure (* 2 #emmy/complex "3 + 1i") ;;=> #emmy/complex "6 + 2i" ```
(+)
(+ x)
(+ x y)
(+ x y & more)
Generic implementation of +
. Returns the sum of all supplied arguments. (+)
returns 0, the additive identity.
When applied between numbers, acts like clojure.core/+
. Dispatch is open,
however, making it possible to 'add' types wherever the behavior is
mathematically sound.
For example:
(+ [1 2 3] [2 3 4])
;;=> (up 3 5 7)
Generic implementation of `+`. Returns the sum of all supplied arguments. `(+)` returns 0, the additive identity. When applied between numbers, acts like `clojure.core/+`. Dispatch is open, however, making it possible to 'add' types wherever the behavior is mathematically sound. For example: ```clojure (+ [1 2 3] [2 3 4]) ;;=> (up 3 5 7) ```
(-)
(- x)
(- x y)
(- x y & more)
Generic implementation of -
.
If one argument is supplied, returns the negation of a
. Else returns the
difference of the first argument a
and the sum of all remaining
arguments. (-)
returns 0.
When applied between numbers, acts like clojure.core/-
. Dispatch is open,
however, making it possible to 'subtract' types wherever the behavior is
mathematically sound.
For example:
(- [1 2 3] [2 3 4])
;;=> (up -1 -1 -1)
(- [1 10])
;;=> (up -1 -10)
Generic implementation of `-`. If one argument is supplied, returns the negation of `a`. Else returns the difference of the first argument `a` and the sum of all remaining arguments. `(-)` returns 0. When applied between numbers, acts like `clojure.core/-`. Dispatch is open, however, making it possible to 'subtract' types wherever the behavior is mathematically sound. For example: ```clojure (- [1 2 3] [2 3 4]) ;;=> (up -1 -1 -1) (- [1 10]) ;;=> (up -1 -10) ```
(/)
(/ x)
(/ x y)
(/ x y & more)
Generic implementation of /
.
If one argument is supplied, returns the multiplicative inverse of a
. Else
returns the result of dividing first argument a
by the product of all
remaining arguments. (/)
returns 1, the multiplicative identity.
When applied between numbers, acts like clojure.core//
. Dispatch is open,
however, making it possible to 'divide' types wherever the behavior is
mathematically sound.
For example:
(/ [2 4 6] 2)
;;=> (up 1 2 3)
Generic implementation of `/`. If one argument is supplied, returns the multiplicative inverse of `a`. Else returns the result of dividing first argument `a` by the product of all remaining arguments. `(/)` returns 1, the multiplicative identity. When applied between numbers, acts like `clojure.core//`. Dispatch is open, however, making it possible to 'divide' types wherever the behavior is mathematically sound. For example: ```clojure (/ [2 4 6] 2) ;;=> (up 1 2 3) ```
(acos a)
generic acos.
Computes the inverse cosine of the supplied argument a
.
Defaults to atan(sqrt(1-x^2)/x)
.
generic acos. Computes the inverse cosine of the supplied argument `a`. Defaults to `atan(sqrt(1-x^2)/x)`.
(acosh a)
generic acosh.
Computes the inverse hyperbolic
cosine of the supplied
argument a
.
defaults to 2 ln(sqrt((x+1)/2) + sqrt((x-1)/2))
.
generic acosh. Computes the [inverse hyperbolic cosine](https://mathworld.wolfram.com/InverseHyperbolicCosine.html) of the supplied argument `a`. defaults to `2 ln(sqrt((x+1)/2) + sqrt((x-1)/2))`.
(acot a)
generic acot.
Computes the inverse
cotangent of the supplied
argument a
.
defaults to pi/2 - atan(x)
.
generic acot. Computes the [inverse cotangent](https://mathworld.wolfram.com/InverseCotangent.html) of the supplied argument `a`. defaults to `pi/2 - atan(x)`.
(acoth a)
generic acoth.
Computes the inverse hyperbolic
cotangent of
the supplied argument a
.
defaults to 1/2 ln((x+1)/(x-1))
.
generic acoth. Computes the [inverse hyperbolic cotangent](https://mathworld.wolfram.com/InverseHyperbolicCotangent.html) of the supplied argument `a`. defaults to `1/2 ln((x+1)/(x-1))`.
(acsc a)
generic acsc.
Computes the inverse
cosecant of the supplied
argument a
.
defaults to atan(1 / sqrt(x^2 - 1))
.
generic acsc. Computes the [inverse cosecant](https://mathworld.wolfram.com/InverseCosecant.html) of the supplied argument `a`. defaults to `atan(1 / sqrt(x^2 - 1))`.
(acsch a)
generic acsch.
Computes the inverse hyperbolic
cosecant of the
supplied argument a
.
defaults to ln((1 + sqrt(1+x^2)) / x)
.
generic acsch. Computes the [inverse hyperbolic cosecant](https://mathworld.wolfram.com/InverseHyperbolicCosecant.html) of the supplied argument `a`. defaults to `ln((1 + sqrt(1+x^2)) / x)`.
(almost-integral? x)
Returns true if x
is either:
false otherwise.
Returns true if `x` is either: - [[integral?]], - a floating point number either < [[absolute-integer-tolerance]] (if near zero) or within [[relative-integer-tolerance]] of the closest integer, false otherwise.
(asec a)
generic asec.
Computes the inverse
secant of the supplied
argument a
.
defaults to atan(sqrt(x^2 - 1))
.
generic asec. Computes the [inverse secant](https://mathworld.wolfram.com/InverseSecant.html) of the supplied argument `a`. defaults to `atan(sqrt(x^2 - 1))`.
(asech a)
generic asech.
Computes the inverse hyperbolic
secant of the
supplied argument a
.
defaults to ln((1 + sqrt(1-x^2)) / x)
.
generic asech. Computes the [inverse hyperbolic secant](https://mathworld.wolfram.com/InverseHyperbolicSecant.html) of the supplied argument `a`. defaults to `ln((1 + sqrt(1-x^2)) / x)`.
(asin a)
generic asin.
Computes the inverse sine of the supplied argument a
.
Defaults to atan(x/sqrt(1-x^2))
.
generic asin. Computes the inverse sine of the supplied argument `a`. Defaults to `atan(x/sqrt(1-x^2))`.
(asinh a)
generic asinh.
Computes the inverse hyperbolic
sine of the
supplied argument a
.
defaults to ln(x + sqrt(1 + x^2))
.
generic asinh. Computes the [inverse hyperbolic sine](https://mathworld.wolfram.com/InverseHyperbolicSine.html) of the supplied argument `a`. defaults to `ln(x + sqrt(1 + x^2))`.
(atan a)
(atan a b)
generic atan.
Computes the inverse tangent of the supplied argument a
. Given two
arguments a
and b
, returns the inverse tangent of the angle formed by the
point (b, a)
in a 2-dimensional euclidean plane.
The two-argument version is sometimes called Atan2.
generic atan. Computes the inverse tangent of the supplied argument `a`. Given two arguments `a` and `b`, returns the inverse tangent of the angle formed by the point `(b, a)` in a 2-dimensional euclidean plane. The two-argument version is sometimes called [Atan2](https://en.wikipedia.org/wiki/Atan2).
(atanh a)
generic atanh.
Computes the inverse hyperbolic
tangent of the
supplied argument a
.
defaults to 1/2 ln((1+x)/(1-x))
.
generic atanh. Computes the [inverse hyperbolic tangent](https://mathworld.wolfram.com/InverseHyperbolicTangent.html) of the supplied argument `a`. defaults to `1/2 ln((1+x)/(1-x))`.
(ceiling a)
generic ceiling.
Returns the result of rounding a
up to the next largest integer.
Extensions beyond real numbers may behave differently; see the Documentation site for more detail.
generic ceiling. Returns the result of rounding `a` up to the next largest integer. Extensions beyond real numbers may behave differently; see the [Documentation site](https://cljdoc.org/d/org.mentat/emmy/CURRENT/doc/basics/generics) for more detail.
(cos a)
generic cos.
Returns the cosine of the
supplied argument a
.
generic cos. Returns the [cosine](https://en.wikipedia.org/wiki/Sine_and_cosine) of the supplied argument `a`.
(cosh a)
generic cosh.
Computes the hyperbolic
cosine of the supplied
argument a
.
defaults to (e^x + e^{-x}) / 2
.
generic cosh. Computes the [hyperbolic cosine](https://mathworld.wolfram.com/HyperbolicCosine.html) of the supplied argument `a`. defaults to `(e^x + e^{-x}) / 2`.
(cot a)
generic cot.
Computes the trigonometric cotangent function of the supplied argument a
.
Equivalent to (invert (tan a))
, or (/ (cos a) (sin a))
.
generic cot. Computes the trigonometric cotangent function of the supplied argument `a`. Equivalent to `(invert (tan a))`, or `(/ (cos a) (sin a))`.
(coth a)
generic coth.
Computes the hyperbolic
cotangent of the supplied
argument a
.
defaults to cosh(x) / sinh(x)
.
generic coth. Computes the [hyperbolic cotangent](https://mathworld.wolfram.com/HyperbolicCotangent.html) of the supplied argument `a`. defaults to `cosh(x) / sinh(x)`.
(cross-product a b)
generic cross-product
generic cross-product
(csc a)
generic csc.
Computes the cosecant of the supplied argument a
.
Equivalent to (invert (sin a))
.
generic csc. Computes the cosecant of the supplied argument `a`. Equivalent to `(invert (sin a))`.
(csch a)
generic csch. Computes the [hyperbolic cosecant](https://mathworld.wolfram.com/HyperbolicCosecant.html) of the supplied argument `a`. defaults to `1 / sinh(x)`.
(determinant a)
generic determinant
generic determinant
(dot-product a b)
generic dot-product
generic dot-product
(exact-divide a b)
generic exact-divide.
Similar to the binary case of /
, but throws if (g/exact? <result>)
returns false.
generic exact-divide. Similar to the binary case of [[/]], but throws if `(g/exact? <result>)` returns false.
(exact-zero? n)
Returns true if the supplied argument is an exact numerical zero, false otherwise.
Returns true if the supplied argument is an exact numerical zero, false otherwise.
(exact? a)
generic exact?.
Entries that are exact are available for gcd
, among other operations.
generic exact?. Entries that are exact are available for `gcd`, among other operations.
(exp a)
generic exp.
Returns the base-e exponential of x
. Equivalent to (expt e x)
, given
some properly-defined e
symbol.
generic exp. Returns the base-e exponential of `x`. Equivalent to `(expt e x)`, given some properly-defined `e` symbol.
(exp10 a)
generic exp10.
Returns the base-10 exponential of x
. Equivalent to (expt 10 x)
.
generic exp10. Returns the base-10 exponential of `x`. Equivalent to `(expt 10 x)`.
(exp2 a)
generic exp2.
Returns the base-2 exponential of x
. Equivalent to (expt 2 x)
.
generic exp2. Returns the base-2 exponential of `x`. Equivalent to `(expt 2 x)`.
(floor a)
generic floor.
Returns the largest integer less than or equal to a
.
Extensions beyond real numbers may behave differently; see the Documentation site for more detail.
generic floor. Returns the largest integer less than or equal to `a`. Extensions beyond real numbers may behave differently; see the [Documentation site](https://cljdoc.org/d/org.mentat/emmy/CURRENT/doc/basics/generics) for more detail.
(fractional-part a)
generic fractional-part.
Returns the fractional part of the given value, defined as x - ⌊x⌋
.
For positive numbers, this is identical to (- a (integer-part a))
. For
negative a
, because floor
truncates toward negative infinity, you might
be surprised to find that fractional-part
returns the distance between a
and the next-lowest integer:
(= 0.6 (fractional-part -0.4))
generic fractional-part. Returns the fractional part of the given value, defined as `x - ⌊x⌋`. For positive numbers, this is identical to `(- a (integer-part a))`. For negative `a`, because [[floor]] truncates toward negative infinity, you might be surprised to find that [[fractional-part]] returns the distance between `a` and the next-lowest integer: ```clojure (= 0.6 (fractional-part -0.4)) ```
(freeze a)
generic freeze.
Freezing an expression means removing wrappers and other metadata from subexpressions, so that the result is basically a pure S-expression with the same structure as the input. Doing this will rob an expression of useful information for further computation; so this is intended to be done just before simplification and printing, to simplify those processes.
generic freeze. Freezing an expression means removing wrappers and other metadata from subexpressions, so that the result is basically a pure S-expression with the same structure as the input. Doing this will rob an expression of useful information for further computation; so this is intended to be done just before simplification and printing, to simplify those processes.
(gcd a b)
generic gcd.
Returns the greatest common
divisor of the two
inputs a
and b
.
generic gcd. Returns the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor) of the two inputs `a` and `b`.
(identity-like a)
generic identity-like.
Like one-like
but works for square matrices.
generic identity-like. Like `one-like` but works for square matrices.
(identity? a)
generic identity?.
Like one?
, but this is true of square identity matrices as well.
No matrix is considered one?
because its function as a multiplicative
identity depends on the shape of the other multiplicand.
generic identity?. Like `one?`, but this is true of square identity matrices as well. No matrix is considered `one?` because its function as a multiplicative identity depends on the shape of the other multiplicand.
(infinite? a)
generic infinite?.
Returns true if a
is either numerically infinite (i.e., equal to ##Inf
) or
a compound number (complex or quaterion, for example) with some infinite
component.
generic infinite?. Returns true if `a` is either numerically infinite (i.e., equal to `##Inf`) or a compound number (complex or quaterion, for example) with some infinite component.
(inner-product a b)
generic inner-product
generic inner-product
(integer-part a)
generic integer-part.
Returns the integer part of a
by removing any fractional digits.
generic integer-part. Returns the integer part of `a` by removing any fractional digits.
(invert a)
generic invert.
Returns the multiplicative inverse of a
.
Equivalent to (/ 1 a)
.
generic invert. Returns the multiplicative inverse of `a`. Equivalent to `(/ 1 a)`.
(lcm a b)
generic lcm.
Returns the least common
multiple of the two
inputs a
and b
.
generic lcm. Returns the [least common multiple](https://en.wikipedia.org/wiki/Least_common_multiple) of the two inputs `a` and `b`.
(Lie-derivative a)
generic Lie-derivative
generic Lie-derivative
(log a)
generic log.
Returns the natural logarithm of x
.
generic log. Returns the natural logarithm of `x`.
(log10 a)
generic log10.
Returns the base-10 logarithm of x
, i.e., $log_10(x)$.
generic log10. Returns the base-10 logarithm of `x`, i.e., $log_10(x)$.
(log2 a)
generic log2.
Returns the base-2 logarithm of x
, i.e., $log_2(x)$.
generic log2. Returns the base-2 logarithm of `x`, i.e., $log_2(x)$.
(make-rectangular a b)
generic make-rectangular
generic make-rectangular
(modulo a b)
generic modulo.
Returns the result of the
mathematical Modulo
operation between a
and b
(using the Knuth definition listed).
The contract satisfied by modulo
is:
(= a (+ (* b (floor (/ a b)))
(modulo a b)))
For numbers, this differs from the contract offered by remainder
because (floor (/ a b))
rounds toward negative infinity, while
the quotient
operation in the contract for remainder
rounds toward 0.
The result will be either 0
or of the same sign as the divisor b
.
generic modulo. Returns the result of the mathematical [Modulo](https://en.wikipedia.org/wiki/Modulo_operation) operation between `a` and `b` (using the Knuth definition listed). The contract satisfied by [[modulo]] is: ```clojure (= a (+ (* b (floor (/ a b))) (modulo a b))) ``` For numbers, this differs from the contract offered by [[remainder]] because `(floor (/ a b))` rounds toward negative infinity, while the [[quotient]] operation in the contract for [[remainder]] rounds toward 0. The result will be either `0` or of the same sign as the divisor `b`.
(negate a)
generic negate.
Returns the negation of a
.
Equivalent to (- (g/zero-like a) a)
.
generic negate. Returns the negation of `a`. Equivalent to `(- (g/zero-like a) a)`.
(negative? a)
generic negative?.
Returns true if the argument a
is less than (g/zero-like a)
,
false otherwise. The default implementation depends on a proper Comparable
implementation on the type.`
generic negative?. Returns true if the argument `a` is less than `(g/zero-like a)`, false otherwise. The default implementation depends on a proper Comparable implementation on the type.`
(numeric-zero? x)
Returns true
if x
is both a [[number?]] and zero?
, false otherwise.
Returns `true` if `x` is both a [[number?]] and [[zero?]], false otherwise.
(one-like a)
generic one-like.
In general, this procedure returns the multiplicative identity of the type of its argument, if it exists. For numbers this is 1.
generic one-like. In general, this procedure returns the multiplicative identity of the type of its argument, if it exists. For numbers this is 1.
(one? a)
generic one?.
Is true if x
is a multiplicative identity.
generic one?. Is true if `x` is a multiplicative identity.
(outer-product a b)
generic outer-product
generic outer-product
(partial-derivative a b)
generic partial-derivative
generic partial-derivative
(remainder a b)
generic remainder.
Returns the remainder of dividing the dividend a
by divisor b
.
The contract satisfied by remainder
is:
(= a (+ (* b (quotient a b))
(remainder a b)))
For numbers, this differs from the contract offered by modulo
because quotient
rounds toward 0, while (floor (/ a b))
rounds toward
negative infinity.
The result will be either 0
or of the same sign as the dividend a
.
generic remainder. Returns the remainder of dividing the dividend `a` by divisor `b`. The contract satisfied by [[remainder]] is: ```clojure (= a (+ (* b (quotient a b)) (remainder a b))) ``` For numbers, this differs from the contract offered by [[modulo]] because [[quotient]] rounds toward 0, while `(floor (/ a b))` rounds toward negative infinity. The result will be either `0` or of the same sign as the dividend `a`.
(sec a)
generic sec.
Computes the secant of the supplied argument a
.
Equivalent to (invert (cos a))
.
generic sec. Computes the secant of the supplied argument `a`. Equivalent to `(invert (cos a))`.
(sech a)
generic sech. Computes the [hyperbolic secant](https://mathworld.wolfram.com/HyperbolicSecant.html) of the supplied argument `a`. defaults to `1 / cosh(x)`.
(sin a)
generic sin.
Returns the sine of the
supplied argument a
.
generic sin. Returns the [sine](https://en.wikipedia.org/wiki/Sine_and_cosine) of the supplied argument `a`.
(sinc a)
generic sinc.
The unnormalized sinc function, equivalent to $\frac{\sin x}{x}$ but defined to be equal to 1 at $x = 0$.
generic sinc. The unnormalized [sinc function](https://en.wikipedia.org/wiki/Sinc_function), equivalent to $\frac{\sin x}{x}$ but defined to be equal to 1 at $x = 0$. ### References - [Wikipedia page](https://en.wikipedia.org/wiki/Sinc_function) - [Mathworld page on Sinc](https://mathworld.wolfram.com/SincFunction.html) - [Boost notes on [[sinc]] and [[sinch]]](https://www.boost.org/doc/libs/1_65_0/libs/math/doc/html/math_toolkit/sinc/sinc_overview.html)
(sinh a)
generic sinh.
Computes the hyperbolic
sine of the supplied
argument a
.
defaults to (e^x - e^{-x}) / 2
.
generic sinh. Computes the [hyperbolic sine](https://mathworld.wolfram.com/HyperbolicSine.html) of the supplied argument `a`. defaults to `(e^x - e^{-x}) / 2`.
(sinhc a)
generic sinhc.
The sinhc function, equivalent to $\frac{\sinh x}{x}$ but defined to be equal to 1 at $x = 0$.
generic sinhc. The [sinhc function](https://en.wikipedia.org/wiki/Sinhc_function), equivalent to $\frac{\sinh x}{x}$ but defined to be equal to 1 at $x = 0$. ### References - [Wikipedia page](https://en.wikipedia.org/wiki/Sinhc_function) - [Mathworld page on Sinhc](https://mathworld.wolfram.com/SinhcFunction.html)
(solve-linear a b)
generic solve-linear.
For a given a
and b
, returns x
such that a*x = b
.
Seesolve-linear-right
for a similar function that solves for a = x*b
.
generic solve-linear. For a given `a` and `b`, returns `x` such that `a*x = b`. See[[solve-linear-right]] for a similar function that solves for `a = x*b`.
(solve-linear-left a b)
Alias for solve-linear
; present for compatibility with the original
scmutils
codebase.
NOTE: In scmutils
, solve-linear-left
and solve-linear
act identically in
all cases except matrices. solve-linear-left
only accepted a column
matrix (or up structure) in the b
position, while solve-linear
accepted
either a column or row (up or down structure).
In Emmy, both functions accept either type.
Alias for [[solve-linear]]; present for compatibility with the original `scmutils` codebase. NOTE: In `scmutils`, `solve-linear-left` and `solve-linear` act identically in all cases except matrices. `solve-linear-left` only accepted a column matrix (or up structure) in the `b` position, while `solve-linear` accepted either a column or row (up or down structure). In Emmy, both functions accept either type.
(solve-linear-right a b)
generic solve-linear-right.
For a given a
and b
, returns x
such that a = x*b
.
Seesolve-linear
for a similar function that solves for a*x = b
.
generic solve-linear-right. For a given `a` and `b`, returns `x` such that `a = x*b`. See[[solve-linear]] for a similar function that solves for `a*x = b`.
(tan a)
generic tan.
Computes the trigonometric tangent function of the supplied argument a
.
Equivalent to (/ (sin a) (cos a))
.
generic tan. Computes the trigonometric tangent function of the supplied argument `a`. Equivalent to `(/ (sin a) (cos a))`.
(tanc a)
generic tanc.
tanc
is defined, by analogy with sinc
, to be equal to $\frac{\tan
x}{x}$ for nonzero $x$ and equal to 1 at $x = 0$.
generic tanc. `tanc` is defined, by analogy with [[sinc]], to be equal to $\frac{\tan x}{x}$ for nonzero $x$ and equal to 1 at $x = 0$. ### References - [Wikipedia page](https://en.wikipedia.org/wiki/Tanc_function) - [Mathworld page on Sinc](https://mathworld.wolfram.com/TancFunction.html)
(tanh a)
generic tanh.
Computes the hyperbolic
tangent of the supplied
argument a
.
defaults to sinh(x) / cosh(x)
.
generic tanh. Computes the [hyperbolic tangent](https://mathworld.wolfram.com/HyperbolicTangent.html) of the supplied argument `a`. defaults to `sinh(x) / cosh(x)`.
(tanhc a)
generic tanhc.
The tanhc function, equivalent to $\frac{\tanh x}{x}$ but defined to be equal to 1 at $x = 0$.
generic tanhc. The [tanhc function](https://en.wikipedia.org/wiki/Tanhc_function), equivalent to $\frac{\tanh x}{x}$ but defined to be equal to 1 at $x = 0$. ### References - [Wikipedia page](https://en.wikipedia.org/wiki/Tanhc_function) - [Mathworld page on Tanhc](https://mathworld.wolfram.com/TanhcFunction.html)
(zero-like a)
generic zero-like.
In general, this procedure returns the additive identity of the type of its argument, if it exists. For numbers this is 0.
generic zero-like. In general, this procedure returns the additive identity of the type of its argument, if it exists. For numbers this is 0.
(zero? a)
generic zero?.
Is true if x
is an additive identity.
generic zero?. Is true if `x` is an additive identity.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close