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



Dieter Kaiser 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.
>   
If you don't mind, I think we should use Stavros' define-compiler-macro
to implement this.  I can make this change.

And it makes it much easier to try out Richard Fateman's patch for CL
rationals if we decide to do that.

This also gives a nice abstraction if the internals ever change.
> 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))
>   
I think we should choose one.  My personal preference is a function
1//2, but the macro is ok too.  (For smart compilers, the function can
be constant folded directly into the code.  For less smart compilers, we
can add a define-compiler-macro to do the constant folding for us.  Or
just use the macro.)

There are other constants like this sprinkled all over the code for
-1/2, 3/2 and probably lots more that I don't remember.

Ray