# mscroggs/Equation forked from glenflet/Equation

Switch branches/tags
Nothing to show
Fetching contributors…
Cannot retrieve contributors at this time
154 lines (112 sloc) 6.91 KB

# Functions, Operators & Constants

The Following Functions, Operators and Constants are defined and useable in Expression Strings.

Note

All names are case-senitive

## Constants

Constants are basicaly unchanging global variabes, an used to define special values

pi 1.0 Pi (\pi)
e 1.0 Euler's number (\mathrm{e})
Inf 1.0 Infinity (\infty)
NaN 1.0 Not a Number
h 1.1 Plancks Constant (h) [1]
hbar 1.1 Reduced Plancks Constant (\hbar) [1]
m_e 1.1 Electron Mass (m_{\rm e}) [1]
m_p 1.1 Proton Mass (m_{\rm p}) [1]
m_n 1.1 Neturon Mass (m_{\rm n}) [1]
c 1.1 Speed of Light (c) [1]
N_A 1.1 Avogardo's Number (N_{\rm A}) [1]
mu_0 1.1 Magnetic Constant (\mu_0) [1]
eps_0 1.1 Electric Constant (\varepsilon_0) [1]
k 1.1 Boltzmann Constant (k_\mathrm{b}) [1]
G 1.1 Gravitational Constant (G) [1]
g 1.1 Standard Accleration due to gravity (\mathrm{g}) [1]
q 1.1 Elementary Charge (\mathit{e}) [1]
R 1.1 Ideal Gas Constant (R) [1]
sigma 1.1 Stefan-Boltzmann Constant (\sigma) [1]
Rb 1.1 Rydberg Constant (R_\infty) [1]
 [1] (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) Requires scipy to use these constants

## Operators

Operators are special function maped to a symbol, that will appear between the operands rather than as a name folloed by a comma seperated list of operands.

Operators have a Precedence this indicate the Priotiy with which they are applied i.e. low Precedence valued operators will be evaluated before higher valued ones.

Note

Values of the same Precedence are evaluated left to right

Symbol Operation Syntax Precedence Display
+ Added A to B A + B 3 \left(A + B\right)
- Subtract B from A A - B 3 \left(A - B\right)
* Mutlipy A by B A * B 2 \left(A \times B\right)
/ Divide A by B A / B 2 \frac{A}{B}
% Reminder of A Divided by B A % B 2 \left(A \bmod B\right)
^ Raise A to the B'th power A ^ B 1 A^{B}
& Logical AND of A and B A & B 4 \left(A \land B\right)
| Logical OR of A and B A | B 4 \left(A \lor B\right)
<\> Logical XOR of A and B A <\> B 4 \left(A \oplus B\right)
! Logical NOT of A !A UNARY \neg A
== Test if A is equal to B A == B 5 \left(A = B\right)
~ Test if A is similar to B A ~ B 5 \left(A \sim B\right) [2]
!= Test if A isn't equal to B A != B 5 \left(A \neq B\right)
!~ Test if A isn't similar to B A !~ B 5 \left(A \nsim B\right) [2]
< Test if A is less than to B A < B 5 \left(A < B\right)
> Test if A is more than to B A > B 5 \left(A > B\right)
<= Test if A is less than or equal to B A < B 5 \left(A \leq B\right)
>= Test if A is more than or equal to B A > B 5 \left(A \geq B\right)
<~ Test if A is less than or similar to B A < B 5 \left(A \lesssim B\right) [2]
>~ Test if A is more than or similar to B A > B 5 \left(A \gtrsim B\right) [2]
 [2] (1, 2, 3, 4) Check it values are very close rather then just equal, i.e. 1 is similar to 1.000001 but not equal (see :ref:similar-module)

## Functions

These as normal functions a name followed by a list of parameters

Name Operation Syntax Display
abs Absolute value of A abs(A) \left|A\right|
sin Sine value of A sin(A) \sin\left(A\right)
cos Cosine value of A cos(A) \cos\left(A\right)
tan Tangent value of A tan(A) \tan\left(A\right)
re Real Compoent of A re(A) \Re\left(A\right)
im Imagery Compoent of A im(A) \Im\left(A\right)
sqrt Square root of A sqrt(A) \sqrt{A}
log Logarithm of A log(A) \log{A}

## Examples

The Following are some example expressions demonstrating the Precedence order and display formating

sin(x*(y+z))
sin((x * (y + z)))

\sin\left(\left(x \times \left(y + z\right)\right)\right)

(a+b)/(c+d)
((a + b) / (c + d))

\frac{\left(a + b\right)}{\left(c + d\right)}

a+b/c+d*e^f
((a + (b / c)) + (d * (e ^ f)))

\left(\left(a + \frac{b}{c}\right) + \left(d \times e^{f}\right)\right)

a^b/c^d
((a ^ b) / (c ^ d))

\frac{a^{b}}{c^{d}}

a*b/c*d
(((a * b) / c) * d)

\left(\frac{\left(a \times b\right)}{c} \times d\right)

a*b/(c*d)
((a * b) / (c * d))

\frac{\left(a \times b\right)}{\left(c \times d\right)}