Crate number_diff

Source
Expand description

§Overview

§Number Diff - An all-purpose tool for calculus

§Functions

Number Diff is built around a calculus-like function, that is, a function that takes an f64 as an argument, returning an f64 according to some specific rule. In the current state of the crate, functions are limited to ƒ: ℝ ⟶ ℝ (have a look at the supported functions for which functions can be used).
There are plans to expand to ƒ: ℂ ⟶ ℂ in the not so distant future.

§Usage

Functions are represented by the Function struct. The Function struct can be created by either parsing a string or combining functions using standard operations. A Function instance can then be used with the call(x) method (or when using the nightly feature, Function instances can be called directly).

Check out some examples!

§Supported functions

FunctionParsing IdentifierIn-code Function
sin“sin(_)”sin()
cos“cos(_)”cos()
tan“tan(_)”tan()
sec“sec(_)”sec()
csc“csc(_)”csc()
cot“cot(_)”cot()
asin“asin(_)”asin()
acos“acos(_)”acos()
atan“atan(_)”atan()
sinh“sinh(_)”sinh()
cosh“cosh(_)”cosh()
tanh“tanh(_)”tanh()
natural log“ln(_)”ln()
absolute value“abs(_)”abs()
square root“sqrt(_)”sqrt()
factorial“_!”factorial()
addition“_ + _ “+
subtraction“_ - _”-
multiplication“_ * _”*
division“_ / _”/
contant“1”, “-12”, “3.14”, etc.f64
independent variable“x”Function::default()

Note that “_” in the table above refers to any other function of the ones provided above. Note also that the operations (+, -, *, /) cannot be applied to each other. Attempting to apply an operation to another operation will make the parser return a Parsing Error.

§Derivatives

All of the supported functions are smooth functions which in turn means that once initialized, a Function is guaranteed to be a smooth function and so are all of its derivatives.

Derivatives are calculated analytically. The provided derivative function will always be the the exact derivative of the original function (although not always in simplest form).

Note that in its current state, differentiating might in some rare cases return NaN for certain input values where simplification fails to avoid a division by zero.

Function instances can be differentiated using the differentiate() method or using the derivative_of() function.

§Integrals

Integration is stable for the most part. With a standard precision of 1000, integration uses Simpson’s rule in order to find an approximate value of the integral.

For usage examples, check out the integration documentation!

Note that while integrating over an interval (including the bounds of integration) inside of which the value of the specified function is undefined, the resulting value might be NaN.

Also, integrating over an interval (including the bounds of integration) inside of which the value of the specified function is infinit, the resulting value might be inf even though the integral should converge.

§Series Expansions

See this article for an explanation of series expansions.

§Current stability of series expansions
Expansion TechniqueStabilityUsage
Taylor seriesStable ✅get_taylor_expansion()
Maclaurin seriesStable ✅get_maclaurin_expansion()
Fourier seriesUnimplemented ❌N/A

Structs§

Function
Integral
See Integrate documentation for usage and examples

Enums§

Elementary
Error
SeriesExpansion
SeriesExpansion is an abstraction of the series expansion created when using

Constants§

BERNSTEINS_CONSTANT
Usually denoted as β, Bernstein’s constant is defined as the limit lim(n➝ ∞)2nE₂ₙ(f) where Eₙ(f)is the error to the best uniform approximation to a real funciton f(x) on the interval [-1, 1] by real polynomials of no more than degree n. See this article for further information
COMPLEX_INFINITY
An infinit number in the complex plane with an unknown or undefined complex argument.
EULER_MASCHERONI
Euler’s constant (sometimes called the Euler-Mascheroni constant) usually denoted as 𝛄. See this article for further information.
GOLDEN_RATIO
Usually denoted as 𝜑, the golden ratio is defined as the positive solution to 𝜑² = 𝜑 + 1. See this article for further information
SILVER_RATIO
Usually denoted as 𝛿ₛ the silver ratio is the limiting factor of the Pell numbers and is defined as 1+√2. See this article for further information.
SUPERGOLDEN_RATIO
Usually denoted as 𝝍, the supergolden ratio is defined as the unique real solution to 𝝍³ = 𝝍² + 1. See this article for further information.
TAU
The circle constant 𝜏 is defined as the ratio between a circle’s radius and its circumference. See this article for further information.

Traits§

Factorial
Allows the usage of factorials i.e. x! usually defined as:
Integrate
types that implement the Integrate trait can safely be integrated within the domain ℝ.
Round
Allows the usage of rounding methods that are more specific than rust std’s round() method.

Functions§

abs
Creates a Function equal to the absolute value of the passed Function
acos
Creates a Function equal to the arccosine of the passed Function
asin
Creates a Function equal to the arcsine of the passed Function
atan
Creates a Function equal to the arctangent of the passed Function
cos
Creates a Function equal to the cosine of the passed Function
cosh
Creates a Function equal to the hyperbolic cosine of the passed Function
cot
Creates a Function equal to the cotangent of the passed Function
csc
Creates a Function equal to the cosecant of the passed Function
derivative_of
Returns the derivative of the passed Function.
digamma_function
Special case of the polygamma function 𝛙m(z) where m=0, The integral definition of the function then changes. See article
factorial
Creates a Function equal to the factorial of the passed Function
gamma_function
Returns the value of 𝜞(z) as defined by ∫t^(z-1)e^(-t)dt evaluated from 0 to ∞.
ln
Creates a Function equal to the natural logarithm (base e) of the passed Function
nth_root
Creates a Function equal to the nth root of the passed Function
polygamma_function
the polygamma function 𝛙m(z) describes the relationship between 𝜞(z) and its derivatives. For instance 𝛙0(z) = 𝜞’(z)/𝜞(z). See article
sec
Creates a Function equal to the secant of the passed Function
sin
Creates a Function equal to the sine of the passed Function
sinh
Creates a Function equal to the hyperbolic sine of the passed Function
sqrt
Creates a Function equal to the square root of the passed Function
tan
Creates a Function equal to the tangent of the passed Function
tanh
Creates a Function equal to the hyperbolic tangent of the passed Function