An open discussion on improvements to 'simplifyConstant' #2845
Replies: 1 comment 3 replies
-
Thanks for collecting and sharing these examples,
This example is probably caused by mathjs trying to evaluate addition with a string by converting the string into a numeric value, and not by concatenating them as strings. If you do It indeed feels like |
Beta Was this translation helpful? Give feedback.
-
As discussed in various repo past discussions (#2817) and PR's (such as #2827), function
simplifyConstant
has some remaining limitations in both default and non-commutative contexts.In default contexts, a current known issue is regarding the simplification of multi-arg. associative exprs. involving
string
constants, such that constant op. evaluation remains incomplete for these. For example:More remarkably, within non-commutative contexts, there are currently an extra quantity of similar incomplete expr. simplification examples, such as:
In all of the above non-commutative scenarios, these expressions are constituted by constant sub-expressions which include commutative operations (addition, multiplication) and their inverse operations.
These exprs. simplify as expected when passed directly to
simplify
, due to the benefit of standard simplify rule application.Simplification occurs as expected here because the expr. benefits from 'flattening' of non-commutative ops. (e.g. via rules including
n / n1 -> n * n1 ^ (-1)
andn - n1 -> n + -n1
).Technically, for these cases then, it appears that the limitation ofsimplifyConstant
is its inability to flatten these commutative-op. inverse operations, and therefore simplify these entire expressions as a single, flattened (associative) expression able to benefit from the evaluation of constant sub-expressions within (such as2-2
withina + 2 - 2
).This open discussion acts as a place to discuss ideas on how to approach these scenarios; notably in no particular hurry!
Beta Was this translation helpful? Give feedback.
All reactions