[ maxima-Bugs-609464 ] 1+%e,numer and %e^%e,numer



Dieter Kaiser wrote:
> Hello Richard,
>
> I have thought about the problem of the extra test in simplifya, but I have
> found no other solution. (I have not tried to find a complete new concept to
> handle the constants. You know I have not your experience.)
>   

Here's a way..

Attach to the setting of the flags $%enumer and $numer some additional 
operation.
We already provide for this.

For example, setting $fpprec  to some value calls a program fpprec1  
because
(get '$fpprec 'assign)  has value fpprec1.  {setting fpprec causes 
recalculation of numerical values of e, pi, and how-many-binary-digits 
to carry.
Maybe some other stuff too).


The program mset  in mlisp.lisp  checks for this  assign  property.


so if we do this:

(setf (get '%enumer 'assign) '%enumerprog)

(defun %enumerprog (place value)  ;; %enumer:true  will bind place to 
$%enumer,  value to true
   ;; check for legal value
   ;; if  value is t or nil   (true or false in maxima ...)

  ;; if %enumer is true, and %numer is true, replace the simplifier by

  (setf (symbol-function 'simplifya) (symbol-function 'simplifya-enumer))
;; if %enumer is false
  (setf (symbol-function 'simplifya) (symbol-function 
'simplifya-regular-version)


We need 2 versions of simplifya,  one that assumes %enumer  is true, 
without testing it.
and one that assume %enumer is false without testing it.

In fact we can have 4 versions of simplifya   for all settings of numer 
and %enumer.

This will slow down the operation of setting %enumer..  That's not a 
problem.

This idea can be used in other places too, though the prominence of 
simplifya suggests a better payoff.

(Here's another place:  instead of checking modulus for non-nil in the 
coefficient routines, switch them
out when $modulus is set.)

What do you think of this?  Stavros? Robert?

RJF






> Because we don't do the numerical evaluation for the symbol $%e in meval1, we
> have to check again every symbol in simplifya to get the desired consistent
> results. Perhaps the order of the tests can be optimized. I have chosen:
>
> (defmfun simplifya (x y)
>   (cond ((and $numer $%enumer (atom x) (eq x '$%e))
>          (setq x %e-val))
>         ...
>
> When we add at last the following code to the function simpcheck every function
> will simplify accordingly too:
>
> (defmfun simpcheck (e flag)
>   (cond ((specrepp e) (specdisrep e)) 
>         (flag e) 
>          ;; Set $%enumer to allow numerical simplification
>         (t (let (($%enumer $numer)) (simplifya e nil)))))
>
> We will get numerical results for sin(%e), gamma(%e), ... when $numer is TRUE,
> but no numerical evaluation for $%e in expressions like sin(%e^x).
>
> In one of my last postings I have reported a wrong change. The change has to be
> added to the function pls and not plusin (I have tried both places):
>
> (defun pls (x out)
>   (prog (fm plusflag)
>      (if (mtimesp x) (setq x (testtneg x)))
>      (when (and $numer (atom x) (eq x '$%e))
>        ;; Numercical value for $%e when $numer is TRUE
>        (setq x %e-val))
>      ...
>
> With the four changes to the simplifier the numerical evaluation and
> simplification of $%e is consistent and works for the user like the other
> constants %i, %pi, ... Even nested expressions like %e^(%e^(2*x+1)) will work
> fine. The testsuite and the share_testsuite will have no problems. Only one test
> changes: gamma(%e),numer; will simplify to a numerical result.
>
> The only way of doing this faster and without a change to the simplifier I have
> found is to cut out the flag %enumer, but then %e^x will simplify to 2,17...^x.
>
> So, should we implement the changes to the simplifier?
>
> Dieter Kaiser
>
>
> -----Urspr?ngliche Nachricht-----
> Von: Richard Fateman [mailto:fateman at cs.berkeley.edu] 
> Gesendet: Montag, 18. Mai 2009 07:07
> An: Dieter Kaiser
> Cc: maxima at math.utexas.edu
> Betreff: Re: [Maxima] [ maxima-Bugs-609464 ] 1+%e,numer and %e^%e,numer
>
> Can these patches be put somewhere else?  You are checking the setting  
> of $numer and $enumer   an enormous number of times.
> At least once for every atom in every expression that is ever simplified..
>
> I think that this should be done in a different way, if at all possible.
>
> for example,
>
> have two core simplifiers.  One for $numer=true   and another where 
> $numer = nil.  Then it doesn't have to be checked everywhere.
>
> RJF
>
>