signum() evaluation is too slow



Am Freitag, den 29.01.2010, 15:38 -0500 schrieb Richard Hennessy:
> Is it really necessary to factor?
>  
> (%i9) factor(x^10-1);
> (out9) (x-1)*(x+1)*(x^4-x^3+x^2-x+1)*(x^4+x^3+x^2+x+1)
> (%i10) signum(x^10-1);
> (out10) signum(x^10-1)
>  
> Can you turn this off?  Signum() does not use the result is many cases
> anyway. 
> 
> Rich
> 
>  
> On Fri, Jan 29, 2010 at 12:42 AM, Richard Fateman
> <fateman at cs.berkeley.edu> wrote:
>         
>                 
>                 What is maxima doing here that takes so long?
>         It is calling factor.
>         
>         do  :lisp (trace factor)
>         
>         
>         Why? probably looking to take out a sign from one of the
>         factors?
>         
>         RJF 

It is not the function signum which does the factoring, but the function
$sign. This function is called from the simplifying function simpsignum.

(%i28) sign(x^10000+x);
Evaluation took 5.8604 seconds (6.1778 elapsed) using 34.073 MB.
(%o28) pnz

This is the code which does it.

(defun factor-if-small (x)
  (if (< (conssize x) 51.)
      (let ($ratprint)
	(declare (special $ratprint))
	(factor x)) x))

I think the test to decide if we have a small expression is to weak.
This might be a bug, but the problem is not related to the signum
function. It is a more general problem.

Dieter Kaiser