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



On 8/12/2012 4:49 AM, Barton Willis 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
>
This organization seems unnecessarily clumsy.  Among other things, 
flonum-eval looks in a hash table
to seem if there is a numerical-evaluation program for %sin, even before 
checking to
see if the argument is a number.   It then extracts the real and 
imaginary parts
even if the number is real.

A better organization, in my opinion,  would be some kind of dispatch on 
type.
e.g.
(defun simp-%sin( arg ...)
...

(setf q (maxima-type arg))  ;; figure out what types there are...
(case q
   ((float ...)
    (integer ...)
    (rational ...)
    (bfloat ...)
    (complex ...)
    (taylor ...)
(array ...)
(list   ... ( here goes everything else that looks for multiples of pi etc))
(t (other  illegal? args))

even better:

in a data directed or object-oriented approach we would
instead define a helper function..

(defmethod simp-%sin1 ((a single-float)) ...)
(defmethod simp-%sin1 ((a bfloat)) ...)

making it possible to add cases without editing the program, e.g.
(defmethod simp-%sin1 ((a interval) ...)  ;; new types
(defmethod simp-%sin1 ((a (eql '$inf)) ...)  ;; "eql" methods for 
particular values


I believe this could be done entirely piecemeal.  e.g. change simp-%sin  
and nothing
else need be changed.

Whether this defmethod stuff is faster or not depends on the quality of 
the implementation
of the Common Lisp Object System (CLOS) .

I personally would like to see this so that
(defmethod simp-%sin1 ((a mpfr) ...)    ;; use the mpfr bigfloat library
can be just dropped in to Maxima.

I would like to encourage (again) the SBCL people to consider an interface
to MPFR (and also, I guess, make SBCL work for Windows "100%").
Or the other Lisp support teams.  (I gather GCL can't do foreign functions).
Doing this for Allegro is shown in 
http://www.cs.berkeley.edu/~fateman/generic
   see the files mpfr.lisp and ga.
RJF