Expressions » Histórico » Revisión 1
Revisión 1/2
| Siguiente »
Federico Vera, 2018-06-10 00:41
Expressions¶
All the expressions that are used in mrft
are backed by exp4j
, so basically it will handle all the expressions exp4j
does plus a couple of additions.
Expressions should be written in infix notation
, arguments of functions must be surrounded by parentheses and separated by commas; so basically you should write them in the natural way.
Operators¶
There are three basic sets of operators available:
Arithmetic¶
All of the arithmetic operators are included and available: +
, -
, *
, /
and of course %
(modulo).
Comparison¶
Aside from the arithmetic operators several comparison operators are included: <
, <=
, >
, >=
, !=
and ==
. Please note that since exp4j
itself has no concept of boolean
, the results given by all of the comparison operators will be 1.0
if true
and 0.0
if false
. Let it be noted that due to rounding, equality operators use a radix in which they consider numbers to be "equal", that is:
Let a
and b
be two real numbers, a == b
will evaluate to true
if and only if the distance between a
and b
(dist(a, b) := abs(a - b)
) is less or equal than 1e-12
(0.000000000001
) and false
otherwise.
Boolean¶
As with comparison operators, boolean operators will consider false
every value equal to zero (0 ± 0.000000000001
), and true
every other value. But they are warrantied to return 1.0
for true
and 0.0
for false
. The available operators are: &
(and), |
(or), ¬
(not).
Precedence¶
For those who don't know, precedence of operators refers to which of the operators will be evaluated first when left alone. I won't bother you with numbers, the order of evaluation is as follows:
FIRST-> * / % - + > >= < <= ¬ & | == != <-LAST
----- --- --------- - - - -----
^^^ The dashes indicate groups with the same precedence
When operators have the same precedence they will be evaluated from left to right.
Note: as in primary school (and beyond) you can always alter the precedence of operators with the use of parentheses.
Functions¶
There are quite a few functions available, basically all the ones in Java Math, and a couple of additions.
I'll just name them, I'm assuming everyone reading this over the Internet, has Google access to find the ones that don't actually know.
Trigonometric¶
Please note that all of the trigonometric functions work in radian: sin
, cos
, tan
, asin
, acos
, atan
, sinh
, cosh
, tanh
and sinc
.
Boolean¶
- No arguments:
false
,true
- One argument:
not
- Two arguments:
and
,or
,xor
,nand
,nor
,xnor
,equals
(this one is not exactly boolean) - Three arguments:
if
which is used like thisif(boolean_exp, val_if_true, val_if_false)
that means thatif(0 < 1, 5, 10) -> 5
Misc¶
abs
, log
, log10
, log2
, log1p
, ceil
, floor
, sqrt
, cbrt
, pow
, exp
, expm1
, signum
.
Random (noise)¶
There are 4 random (non deterministic) functions available:
- No arguments:
-
rand
: random uniformly distributed number between0.0
(inclusive) and1.0
(exclusive). -
gaussian
: random gaussianly distributed number with average0.0
and variance1.0
-
- Two arguments:
-
rand2(start, end)
: random uniformly distributed number betweenstart
(inclusive) andend
(exclusive). -
gaussian2(avg, var)
: random gaussianly distributed number with averageavg
and variancevar
-
Constants¶
There are two constants implemented as functions (for reasons I will not discuss here), which are pi
and e
.
Actualizado por Federico Vera hace más de 6 años · 1 revisiones
Volver al inicio