property list hack, profiling, compiler optimization, looking at code



Grepping shows many instances where the code calls $realpart and $imagpart
instead of just calling trisplit, including in functions meqp-by-csign,
many functions in ellipt.lisp, expintegral.lisp, gamma.lisp, trigi.lisp,
etc.

But the only cases that might actually matter (since those are generally
rare special functions) are meqp and the trigonometric functions.

Strangely, trigi has a very nice, efficient syntactic *check* for complex
numbers (complex-number-p), but then goes through $realpart/imagpart to
actually extract the real/imag part.  Why not extract the value at the same
time?

--------------------

In the special functions, there is a common idiom in many of these cases,

     (complex ($float ($realpart z)) ($float ($imagpart z)))

which should probably be a standard function, something like this:

(defun float-complex-expression-to-lisp-complex (z)
     (let* (($numer t) ($float t) (split (trisplit z)))
           (complex ($float (car split)) ($float (cdr split)))))

I am not sure whether the call to ($float...) is necessary given the
current semantics of $float and $numer.

Actually, we can do even better.  Often the code looks like (if
(complex-float-numerical-eval-p z) ...($realpart z)...($imagpart z)) -- but
complex-float-numerical-eval-p itself calls $realpart/imagpart!

But that's not all!  The code actually often looks like
   (cond ...
         ((complex-float-numerical-eval-p z)...)
         ((complex-bigfloat-numerical-eval-p z) ...)
         etc.)
where *each clause* calls $realpart/imagpart again.

                  -s

On Sun, Aug 12, 2012 at 2:03 PM, Stavros Macrakis <macrakis at alum.mit.edu>wrote:

> That is, replace
>
>    (let ((x ($realpart z)) (y ($imagpart z)))
>
> with
>
>     (let* ((ri (trisplit z)) (x (car ri)) (y (cdr ri)))...
>
> in both functions.
>
>              -s
>
>
>
> On Sun, Aug 12, 2012 at 1:25 PM, Stavros Macrakis <macrakis at alum.mit.edu>wrote:
>
>> Well, one easy improvement to (big-)flonum-eval is to call trisplit
>> directly instead of calling it twice via realpart/imagpart.
>>
>> trisplit returns the cons of the realpart and the imagpart in a single
>> calculation.  trisplit = top-level real/imaginary split.
>>
>> I suppose trisplit should be rewritten to use multiple-value-return
>> (which didn't exist when it was written) to avoid 1 cons.
>>
>>               -s
>>
>> On Sun, Aug 12, 2012 at 7:49 AM, Barton Willis <willisb at unk.edu> wrote:
>>
>>> ________________________________________
>>>
>>> >Looks like there are a bunch of places to make this program run faster.
>>> >zerop1 is near the top.  risplit  (real-imaginary-split ???) is there
>>> too.
>>>
>>> The trig simplification code calls both flonum-eval  and big-float-eval.
>>> Both of these functions call
>>> $imagpart and $realpart. And both $imagpart and $realpart call risplit :(
>>>
>>> Fortunately for pure symbolic cases, such as cos(x), flonum-eval and
>>> big-float-eval bail out with out calling
>>> risplit.
>>>
>>>
>>> --bw
>>>
>>> _______________________________________________
>>> Maxima mailing list
>>> Maxima at math.utexas.edu
>>> http://www.math.utexas.edu/mailman/listinfo/maxima
>>>
>>
>>
>