cortex-js / compute-engine

An engine for symbolic manipulation and numeric evaluation of math formulas expressed with MathJSON
https://cortexjs.io
MIT License
356 stars 42 forks source link

recursive Expand #138

Closed lhotejc closed 8 months ago

lhotejc commented 8 months ago

I have the expression : const expr = ce.parse('4(x+2)^2') and I use ce.box(['Expand', expr]).evaluate().simplify().canonical... And I get : the same expr...

I think, that Expand return the same beacause it think that (x+2)^2 is not expandable ? The solution : expand (x+2)^2 and after expand 4(x^2+4x+4) to get 4x^2+16x+16 finally.

I don't see any other solution to that problem

image

arnog commented 8 months ago

The Expand function is not recursive and only applies to the top-level. In your example, the expression (x+2)^2 is at the second level, and is not expanded.

To expand recursively, use the ExpandAll function. This function is available in the next version of the Compute Engine.

lhotejc commented 8 months ago

Génial ! Merci !