From: Robert D. <rob...@gm...> - 2023-08-16 04:55:52
|
On Tue, Aug 15, 2023 at 6:34 PM Jamie Jones <jj...@zo...> wrote: > If it were possible to copy all of the rules for x^(1/3) to cbrt(x) and > then add one more rule to cbrt(x) to deal with negative real values, > that would be perfect. But maybe it is not feasible to do it that way? Hmm, okay, well, I don't think there is a really neat way to achieve that. The built-in rules aren't implemented the same way as tellsimp / tellsimpafter rules -- it's not possible to separate them out and copy them. Instead built-in rules are implemented by a Lisp function which implements all the rules in code. Here's the closest I've gotten to it. This replaces root(a, b) with a^b, simplifies a^b, then replaces any resulting c^d with root(c, d). Then I define a rule for root(x, 1/3) that handles the special case x is a number and x < 0. I can't guarantee this works -- I only tried a few examples to see if it works well enough to write about it here. An earlier version caused Maxima to crash with a stack overflow -- that's not out of the question in this version too. (%i2) to_lisp (); Type (to-maxima) to restart, ($quit) to quit Maxima. MAXIMA> (defun simp-root (x y z) (declare (ignore y)) (let ((e (simplifya (maxima-substitute 'mexpt '$root x) z))) (let ($simp) (maxima-substitute '$root 'mexpt e)))) SIMP-ROOT MAXIMA> (setf (get '$root 'operators) 'simp-root) SIMP-ROOT MAXIMA> (to-maxima) Returning to Maxima (%o2) true (%i3) domain: 'complex $ (%i4) m1pbranch: true $ (%i5) root (-8, 1/3); 1 1 1 (%o5) 2 (- + (-) root(3, -) %i) 2 2 2 (%i6) matchdeclare (xx, lambda ([e], numberp(e) and e < 0)) $ (%i7) simp: false; (%o7) false (%i8) tellsimp (root (xx, 1/3), - root (- xx, 1/3)); (%o8) [rootrule1, simp-root] (%i9) simp: true; (%o9) true (%i10) root (-8, 1/3); (%o10) - 2 (%i11) root (x, 1/n); (%o11) root(x, root(n, - 1)) (%i12) subst (x = -8, %); (%o12) root(- 8, root(n, - 1)) (%i13) subst (n = 3, %); (%o13) - 2 Hmm, I see I should have said root(x, 3) = x^(1/3), or else called it something else ... anyway that's something that can be fixed. As you can see, it takes some pretty obscure Lisp programming to get it working. Maxima has a fair amount of support for new simplification rules, but working with the built-in rules requires Lisp programming. Hope this helps, Robert |