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
Function | Parsing Identifier | In-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 Technique | Stability | Usage |
---|---|---|
Taylor series | Stable ✅ | get_taylor_expansion() |
Maclaurin series | Stable ✅ | get_maclaurin_expansion() |
Fourier series | Unimplemented ❌ | N/A |
Structs
- See Integrate documentation for usage and examples
Enums
- SeriesExpansion is an abstraction of the series expansion created when using
Constants
- 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
- An infinit number in the complex plane with an unknown or undefined complex argument.
- Euler’s constant (sometimes called the Euler-Mascheroni constant) usually denoted as 𝛄. See this article for further information.
- Usually denoted as 𝜑, the golden ratio is defined as the positive solution to 𝜑² = 𝜑 + 1. See this article for further information
- 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.
- Usually denoted as 𝝍, the supergolden ratio is defined as the unique real solution to 𝝍³ = 𝝍² + 1. See this article for further information.
- The circle constant 𝜏 is defined as the ratio between a circle’s radius and its circumference. See this article for further information.
Traits
- Allows the usage of factorials i.e.
x!
usually defined as: - types that implement the Integrate trait can safely be integrated within the domain ℝ.
- Allows the usage of rounding methods that are more specific than rust std’s round() method.
Functions
- Returns the derivative of the passed Function.
- Special case of the polygamma function 𝛙m(z) where m=0, The integral definition of the function then changes. See article
- Returns the value of 𝜞(z) as defined by ∫t^(z-1)e^(-t)dt evaluated from 0 to ∞.
- the polygamma function 𝛙m(z) describes the relationship between 𝜞(z) and its derivatives. For instance 𝛙0(z) = 𝜞’(z)/𝜞(z). See article