This transformation aims to evaluate as much numerical/boolean constants as possible.
For example:
1 + 2 * 3 - 8 // 3 + 7 ^ 3 | 11
is replaced with15
True and 1 + 1 == 2
is replaced withTrue
Note: The power operator **
is special in that the size of its result
can be much larger than the size of its operands. Because of this,
**
is only evaluated when both its operands and its result fit into
the JVM Long type (64-bits signed integer).
For example:
1 + 2 + x
is replaced with3 + x
For example:
[x, y] or 42
is replaced with[x, y]
, since the left part is truthy regardless of what specific valuesx
andy
have.
Arguments of known commutative operators are partially evaluated regardless of the order of arguments given. All of the constant arguments do not have to form a distinct subtree in this case.
For example:
x + 1 + 2
is replaced withx + 3
when it is possible to deduce thatx
is of typeint
(to ensure the commutativity of+
)
For example:
"Hello, " + "world!"
is replaced with"Hello, world!"
[x] + [y]
is replaced with[x, y]
The transformation works on any expression by recursively simplifying all of its subexpressions and then evaluating the top-level node using the results.