-
Notifications
You must be signed in to change notification settings - Fork 734
Description
As currently written, every math function is represented internally as a calculation tree, and the simplification process for calculation trees will crunch things down to plain numeric values as soon as possible. So, for example, a function like sqrt(4)
becomes a tree that initially has two nodes - Sqrt → 4
- and then simplification will notice that it can fully resolve that and crunch it down to just the single node 2
.
Serialization will then see that it's a single number, and then if it's a computed or used value, serialize it as "2" (or something else if it needs to clamp to the property's range), and otherwise serialize it to "calc(2)".
This seems definitely okay to do for non-root nodes, but it does feel slightly weird that the root node being simplified away results in this calc() function appearing out of nowhere. Is this okay?
The alternative is that I annotate the operator node with knowledge of whether it's the root of a tree or not, and never simplify away the root of a tree. That way calc(5 + sqrt(4))
(a Sum node containing a 5 child and a Sqrt child, the latter containing a 4 child) will collapse down to a plain 7
and serialize as "7" or "calc(7)", but a sqrt(4)
will remain as a Sqrt node and serialize back as "sqrt(4)".
It feels like this is complexity without a good motivating reason, so I don't think I want to do it. Just checking in with other people's intuitions.