From: Stavros M. <mac...@gm...> - 2024-10-27 19:45:14
|
On Sun, Oct 27, 2024 at 1:17 AM Eduardo Ochs <edu...@gm...> wrote: > In this thread from mid-august - > https://sourceforge.net/p/maxima/mailman/message/58807287/ > ...I learned that the result of factor(12345678) is not simplified > because is starts with (MTIMES SIMP FACTORED). No, you missed the point. There are lots of simplified expressions which start with *(mtimes simp factored)*: ?print(factor(x^2)) => ((MEXPT SIMP FACTORED) $X 2) In fact, the *simp* flag indicates that the expression is simplified. The result of *factor(4) *has that flag because it is declaring -- *falsely *-- that it is simplified in order to display as *2^2* and not to simplify back to *4*. Maxima simplifies everything *except* if it is within a function definition (named or unnamed): f() := 2+2 => f() := 2+2 lambda([],2+2) => lambda([],2+2) It also generally respects the *simp *flag to mean that something shouldn't be re-simplified, unless you force re-simplification. The *factored *flag is irrelevant. 3 + 2 > instead of the "2 + 3" that I was hoping for. > Maxima's internal print function prints simplified sums (but not products) in the reverse order from the internal form. Why? Because the canonical (simplified) internal form puts constants first, then orders alphabetically (in the case of symbols): :lisp (simplifya '((mlist) ((mplus) x 4 a) ((mtimes) a 4 x)) nil) => ((MLIST SIMP) ((MPLUS SIMP) 4 A X) ((MTIMES SIMP) 4 A X)) But in the case of addition, mathematical convention is that variable names from the end of the alphabet (u, v, w, x, y, z) are generally considered to be "variables", which variable names from the beginning of the alphabet (a, b, c, ...) are generally considered to be "parameters", so the displayed ordering is closer to mathematical convention. This is of course a crude heuristic, but it produces pretty good results: :lisp (displa '((mlist) ((mplus) 4 a x) ((mplus) 4 x a) ((mplus simp) a x) ((mplus simp) x a))) => [4+a+x,4+x+a,x+a,a+x] :lisp (displa '((mlist) ((mtimes) 4 a x) ((mtimes) 4 x a) ((mtimes simp) a x) ((mtimes simp) x a))) => [4*a*x,4*x*a,a*x,x*a] In particular, polynomials look right: print(x^2+a*x-b); => x^2+a*x-b even though the internal form is in a different order: ?print(x^2+a*x-b); => ((MPLUS SIMP) ((MTIMES SIMP) -1 $B) ((MTIMES SIMP) $A $X) ((MEXPT SIMP) $X 2)) Hope this helps. -s |