This is the only module you should need to import
It maps the Expression Class from Equation.core.Expression
Its recomended you use the code:
from Equation import Expression
...
to import the Expression Class, as this is the only Class/Function you should use.
Expression or Equation Object
This is a object that respresents an equation string in a manner that allows for it to be evaluated
Expression objects support combining with the standard arithmetic operators to create new Expression objects, they may also be combined with numerical constant, and strings containg a valid Expression.
>>> from Equation import Expression
>>> fn = Expression("x")
>>> fn += 2
>>> fn
(x + 2)
>>> fn **=3
>>> fn
((x + 2) ^ 3)
>>> fn -= "z"
>>> fn
(((x + 2) ^ 3) - z)
>>> fn(1,2)
25
Parameters: |
|
---|
Evaluates the Expression object using the variables passed, where preset arguments will act as the defualt value for said arguments.
Parameters: |
|
---|---|
Returns: | Result of Expression Evaluation |
Raises TypeError: | |
For Invalid number of arguments, or arguments given multiple values, as with normal python functions |
Get the preset variable var, from the Expression Object
Set the preset variable var to the value value
Removes the preset variable var from the Expression Object
Returns: | True if fn has a variable var |
---|
Returns: | True if fn dosen’t have a variable var |
---|
Iterates over all variables var in fn
Generates a Printable version of the Expression
Returns: | Latex String respresation of the Expression, suitable for rendering the equation |
---|
Generates a String that correctrly respresents the equation
Returns: | Convert the Expression to a String that passed to the constructor, will constuct an identical equation object (in terms of sequence of tokens, and token type/value) |
---|
Show RPN tokens
This will print out the internal token list (RPN) of the expression one token perline.
Provides support for similar type comparsion, and allows the tolerance to be changed
Comparsions work by detriming if the following is true
If it is true the \(A\) and \(B\) are considered to be equal
This module only needs to be imported if you need to change the tolerance for similarlity tests, otherwise you just need to use the similarlity operators in your expression
>>> from Equation import Expression
>>> fn = Expression("x ~ y")
>>> fn(1,1.1)
False
>>> fn(1,1.00001)
True
>>> fn(1,1.001)
False
>>> from Equation.similar import set_tol
>>> set_tol(1e-2)
>>> fn(1,1.1)
False
>>> fn(1,1.00001)
True
>>> fn(1,1.001)
True
By default the tolerance is \(10^{-5}\) Hence 1.001 isn’t condisered similar to 1, but by changing the tolerance to \(10^{-2}\), 1.001 is condisered similar to 1
Set Error Tolerance
Set the tolerance for detriming if two numbers are simliar, i.e \(\left|\frac{a}{b}\right| = 1 \pm tolerance\)
Parameters: | value (float) – The Value to set the tolerance to show be very small as it respresents the percentage of acceptable error in detriming if two values are the same. |
---|