From: Robert D. <rob...@gm...> - 2022-07-06 15:09:30
|
On Tue, Jul 5, 2022 at 7:44 PM Joel Scott <joe...@uq...> wrote: > Just wondering if there is a way to force maxima not to simplify, specifically, can I make x*x stay as that rather than be simplified to x^2 (lack of exponentials in javascript). Great question, exporting Maxima to other systems is an important topic. Instead of suppressing the simplification x*x --> x^2 (it turns out that turning off just that one identity is more or less impossible), try to output Math.pow(x, 2) instead. Here's a way to rewrite an expression with Math.pow. subst ("**" = lambda ([a, b], Math.pow (a, b)), myexpr); e.g. myexpr: expand ((x - a*y)^3); mynewexpr: subst ("**" = lambda ([a, b], Math.pow (a, b)), myexpr); output: (-3*Math . pow(x,2)*a*y)+3*Math . pow(a,2)*Math . pow(y,2)*x -Math . pow(a,3)*Math . pow(y,3)+Math . pow(x,3) Note that Maxima wants to display "." with a space on either side -- I believe this has no effect on JS interpretation of the expression. It is possible to suppress the extra spaces, but let's let it go for now. To print that expression in a format which is interpretable as JS, try the function f90, which outputs Fortran 90 code. For math expressions, I believe that's acceptable as JS as well. load (f90); f90_output_line_length_max:1000000; f90 (mynewexpr); output: (-3*Math . pow(x,2)*a*y)+3*Math . pow(a,2)*Math . pow(y,2)*x-Math . pow(a,3)*Math . pow(y,3)+Math . pow(x,3) That's printed to the console. If you want to capture it to a file or output stream, see with_stdout. There are various problems to solve when working with going back and forth from Maxima to another system -- if you say more about what you're trying to do, we can probably give some specific advice. best, Robert Dodier |