[Maxima] [Maxima-commits] CVS: maxima/src gamma.lisp,1.44,1.45

Stavros Macrakis macrakis at alum.mit.edu
Wed Nov 18 15:15:54 CST 2009


I think the clean, general way to do this is to make DIV into a macro
in mopers.lisp. This takes zero function calls at runtime and every
user of div gets the improvement.  Something like this:

mopers.lisp:
(define-compiler-macro div (a b)
  (if (and (integerp a) (integerp b))
      `'((rat simp) ,(numerator (/ a b)) ,(denominator (/ a b)))
      `(div2 ,a ,b)))

opers.lisp:
(defmfun div2 (x y)
  (if (=1 x)
      (inv y)
      (mul x (inv y))))

On Wed, Nov 18, 2009 at 2:41 PM, Dieter Kaiser <drdieterkaiser at web.de> wrote:
> Am Mittwoch, den 18.11.2009, 09:34 -0500 schrieb Raymond Toy:
>> Wouldn't it have been better to modify div so that div of two integers
>> automatically returned a simplified rat expression?  Then every user of
>> div gets this fix.
>
> First, I have changed (div 1 2) --> ((rat simp) 1 2) because I think
> this is the most simple and efficient way to represent a constant
> rational. Most code of Maxima does it this way too. I have implemented
> rational constants with DIV at a time I did not know much about the way
> Maxima simplifies expressions.
>
> The function DIV needs a lot of function calls to get the same result.
>
> Furthermore, I think that it is not a good idea to modify the function
> DIV. DIV is a general shortcut to call the simplifier, but we do not
> need to call the simplifier for a constant expression.
>
> We have some more ways in Maxima to get the rational constant ((rat
> simp) 1 2). These macros and variables are defined in Maxima core:
>
> (defvar 1//2 '((rat simp) 1 2))
> (defmacro 1//2 () ''((rat simp) 1 2))   ;1/2
> (defmacro half () ''((rat simp) 1 2))   ;1/2
> (defmvar 1//2 '((rat simp) 1 2))
>
> Dieter Kaiser
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>



More information about the Maxima mailing list