Expressions » Histórico » Versión 1
Federico Vera, 2018-06-10 00:41
1 | 1 | Federico Vera | # Expressions |
---|---|---|---|
2 | 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. |
||
3 | |||
4 | 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. |
||
5 | |||
6 | ## Operators |
||
7 | There are three basic sets of operators available: |
||
8 | |||
9 | ### Arithmetic |
||
10 | All of the arithmetic operators are included and available: `+`, `-`, `*`, `/` and of course `%` (modulo). |
||
11 | |||
12 | ### Comparison |
||
13 | 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: |
||
14 | |||
15 | 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. |
||
16 | |||
17 | ### Boolean |
||
18 | 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). |
||
19 | |||
20 | ### Precedence |
||
21 | 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: |
||
22 | ``` |
||
23 | FIRST-> * / % - + > >= < <= ¬ & | == != <-LAST |
||
24 | ----- --- --------- - - - ----- |
||
25 | ^^^ The dashes indicate groups with the same precedence |
||
26 | ``` |
||
27 | When operators have the same precedence they will be evaluated from left to right. |
||
28 | |||
29 | ***Note:*** as in primary school (and beyond) you can always alter the precedence of operators with the use of parentheses. |
||
30 | |||
31 | ## Functions |
||
32 | |||
33 | There are quite a few functions available, basically all the ones in [Java Math](https://docs.oracle.com/javase/7/docs/api/java/lang/Math.html), and a couple of additions. |
||
34 | |||
35 | 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. |
||
36 | |||
37 | ### Trigonometric |
||
38 | Please note that all of the trigonometric functions work in radian: `sin`, `cos`, `tan`, `asin`, `acos`, `atan`, `sinh`, `cosh`, `tanh` and `sinc`. |
||
39 | |||
40 | ### Boolean |
||
41 | - No arguments: `false`, `true` |
||
42 | - One argument: `not` |
||
43 | - Two arguments:`and`, `or`, `xor`, `nand`, `nor`, `xnor`, `equals` (this one is not exactly boolean) |
||
44 | - Three arguments: `if` which is used like this `if(boolean_exp, val_if_true, val_if_false)` that means that `if(0 < 1, 5, 10) -> 5` |
||
45 | |||
46 | ### Misc |
||
47 | `abs`, `log`, `log10`, `log2`, `log1p`, `ceil`, `floor`, `sqrt`, `cbrt`, `pow`, `exp`, `expm1`, `signum`. |
||
48 | |||
49 | ### Random (noise) |
||
50 | |||
51 | There are 4 random (non deterministic) functions available: |
||
52 | - No arguments: |
||
53 | - `rand`: random uniformly distributed number between `0.0` (inclusive) and `1.0` (exclusive). |
||
54 | - `gaussian`: random gaussianly distributed number with average `0.0` and variance `1.0` |
||
55 | - Two arguments: |
||
56 | - `rand2(start, end)`: random uniformly distributed number between `start` (inclusive) and `end` (exclusive). |
||
57 | - `gaussian2(avg, var)`: random gaussianly distributed number with average `avg` and variance `var` |
||
58 | |||
59 | ### Constants |
||
60 | There are two constants implemented as functions (for reasons I will not discuss here), which are `pi` and `e`. |