Questions on simplification context #2817
Replies: 4 comments 4 replies
-
It is interesting, isn't it? I am sure that in the case of example 1, I am simply lacking in mathematical comprehension; and by now I think that I have figured out why the current functioning is correct and that to permit its simplification in absence of commutativity would be mathematically invalid. // The original example was '(2b) * (3b)', but to take a look at a simpler version first..
// '2b * 2': also not simplified in absence of commutativity of multiplication and addition
'= 2b * 2'
'= (2 * b) * 2'
' = (b + b) * 2'
// ^ We are saying that '(b + b) * 2' cannot be simplified when commutativity (namely,
// for multiplication) is not assumed.
// Does the property of commutativity then imply that:
'= 2 * (b + b)'
// .. is an acceptable operation, whilst '(b + b) * 2' is not? So, the absence of the law must mean
' (b + b) * 2 !== 2 * (b + b) '
// Which is a strange thing, because, at least according to mathjs, in the absence of commutativity:
'2 * 2 === 2 * 2 === 4'
// and even:
'a * a === a^2'
// ^ Ah, but that applies in those cases because the left operand and right
// operand are 'identical'? (e.g. the 'a' has the same 'identity' in the case of
// 'a * a' and so it can simplify to a^2?)
// Pfft.. but what is that saying of '(b + b)' / '2b'. That 'b' is not identical to 'b'?
// That '(b + b)' multiplied by itself (which is almost the same opening example
// of '2b * 3b'), cannot be simplified in the absence of commutativity?
'= (b + b) * (b + b)
'= 2b * 2b'
// Ah.. but '2b * 2b' *is* simplified (by mathjs, to '(2*b)^2'), whilst '3b * 2b' *is not*
// And so, if you really think about it, does the *absence* of the property of
// commutativity simply attribute special properties to variables/symbols in a symbol
// expression?... Such that:
'= b * b -> b ^ 2'
// Is accepted in the absence of commutativity (of multiplication), *but*:
'2b * 2b -> (b + b) * (b + b)')
// or
'2b * 2b -> (b + b) * (b + b + b)'
// is not accepted
// indeed almost as if variables are attributed mystical properties,, (but only when they are
// multiplied by a (real?) number??)
// and you can end up in some strange places thinking about this! I invite your thoughts on this. On a lighter note, I believe that the second and third examples ' b * 2 * 2 * 2 -> LHS' // (2)
`b * b * b -> b^2 * b' // (3) are incorrect/bugs, in any case. |
Beta Was this translation helpful? Give feedback.
-
Thanks for your inputs Samuel. I'm not sure if I follow what you mean. When you configure Do you see concrete opportunities to improve the |
Beta Was this translation helpful? Give feedback.
-
I agree that there is no reason not to simplify b * 2 * 2 * 2 to b * 8 even without commutativity, so yes that is a shortcoming of the current set of rules. Similarly b * b * b = b^3 would be perfectly valid without commutativity, so it would be great to improve the rules so that happens. Basically, when commutativity is off for an operation, simplify will not perform any operations which require swapping the order of two operands. So for example it cannot convert between 2 * b and b * 2. But ideally it will still find and use simplifications that don't require any such swaps, but you have found some cases in which it currently falls short of this ideal. As far as I am concerned, you could file those two as a bug. |
Beta Was this translation helpful? Give feedback.
-
Hi Jos and Glen, I believe that in the case of the first example, I had worked myself into a confusion resulting from considering terms such as For example, it does seem to evoke questions around the topic of operator commutativity (and other properties) - 'are these properties only defined for a subset of operations for an operator, and if so, is the property (of commutativity) in fact not a property of binary operators but of operations?' <- (clearly it is the case that commutativity is not 'relevant' or affective for some operations since numeric expressions remain simplifiable.). Furthermore, it simply raises interesting questions about which algebraic entities are assumed to be taking the place of variables/symbols in such cases (indeed, I know that matricies may be a possible candidate here for a start). And shall I then open an issue to cover examples 2 & 3? |
Beta Was this translation helpful? Give feedback.
-
Hello,
Firstly, I have entitled this discussion in a more general manner such as to keep the discussion open around the topic to which it pertains (I hope you don't mind).
I have been following the progression of this module for quite some time, particularly in the area of simplification/the 'simplify' function. (thank you by the way, to whomever concerned, for the ongoing developments that have occurred here). Consequently, I have also become familiar with the default simplify rule-list, particularly with regards to its ordering of rules.
I did have a question or two though, which I am anticipating may evoke simple answers.
When simplifying an expr. with addition and multiplication set to have a non-commutative context (but let's say associativity remains), the following simplify as expected (default ruleset assumed):
However, there are a number of operations which possibly do not simplify as one would expect for this context:
For example (1), unless there is something I am missing with regards to the mathematical properties of the multiplication operator (distributivity, maybe?), it seems that this should be simplifying to
6b^2
.(I say this, because for the case of addition, similar operations simplify fine, such as
3*a + 3*a -> 6 * a
as given in the opening expected-output examples)It seems as if, for the addition op., constant-symbol node pairs are understood as single 'units', whilst in the case of multiplication, this is not so?
For reference, here is the debug-output for a call to simplify on (1) with default-context:
And with a non-commutative context for addition and multiplication:
Example (2)
b * 2 * 2 * 2 -> LHS
is a different 'issue'. I believe that this should simplify tob * 8
. Commutativity is concerned with theordering
of operands, and considering that the context is still associative, the independent '2 * 2 * 2' expression should successfully evaluate?^ Having spent quite a lot of time debugging and examining with the
simplify
function, I am aware here that this expr. remains un-simplified due to maths working with left-heavy binary node trees.., with that said, would the simplification procedure not benefit from an additional pass of the simplification-loop with the flatten-unflatten process flattening and unflattening to a right-heavy tree? (in the case that commutativity is disabled for at least one of its usual operators, but associativity remains).And finally for example (3), similar to (1), I do not see a reason why this should not simplify further?
Best wishes, and hope to hear your thoughts!
Beta Was this translation helpful? Give feedback.
All reactions