Re: [Maxima-bugs] [ maxima-Bugs-988701 ] incorrect matrix inversion



Greetings!  I think the problem is here (opers.lisp):

(defmfun mul2* (x y)
  
  (cond
    #+cl ((and (numberp x) (numberp y)) (f* x y))
    ((=1 x) (simplifya y nil))
	((=1 y) (simplifya x nil))
	(t (simplifya `((mtimes) ,x ,y) nil))))


You probably mean (f* x y) -> (* x y) or numberp -> fixnump.  This
code compiles to the following obviously incorrect C:

:lisp (macroexpand '(f* x y))

(THE FIXNUM (* (THE FIXNUM X) (THE FIXNUM Y)))
T

	if(!(type_of((V14))==t_fixnum||
type_of((V14))==t_bignum||
type_of((V14))==t_ratio||
type_of((V14))==t_shortfloat||
type_of((V14))==t_longfloat||
type_of((V14))==t_complex)){
	goto T93;}
	if(!(type_of((V15))==t_fixnum||
type_of((V15))==t_bignum||
type_of((V15))==t_ratio||
type_of((V15))==t_shortfloat||
type_of((V15))==t_longfloat||
type_of((V15))==t_complex)){
	goto T93;}
	base[2]= CMPmake_fixnum((long)(fix((V14)))*(fix((V15))));
	vs_top=(vs_base=base+2)+1;
	return;
	goto T93;

V15 is a float, not fixnum here.

What I don't get is why #+cl is bringing this code in.

May I also please comment that the C code being generated is very
poorly optimized.  Dr. Schelter used to have a nice sys-proclaims.lisp
file which optimized gcl function calls dramatically, but it does not
appear to be loaded in now in the recent compile process.  I haven't
yet looked into this, so that answer is likely simple.  Might I
suggest making use of gcl's automatic sys-proclaims.lisp generation
feature?  Simply do (compiler::emit-fn t);compile
once;(compiler::make-all-proclaims);(load "sys-proclaim.lisp");
compile again.

I'd be happy to submit a makefile patch if everyone agreed.

Take care,

Barton Willis <willisb@unk.edu> writes:

> I can verify that the MUL* in invert.lisp that Ray
> tracked down seems to be a trouble maker (I'm using
> gcl 2.7.0 on XP) In invert.lisp, I changed MUL* to 
> MUL. Now, invert works okay on this matrix:
> 
> (%i1) display2d : false$
> (%i2) m : matrix([1,0,0],[-.3,1,0],[0,-.3,1])$
> (%i3) m.invert(m);
> (%o3) MATRIX([1.0,0.0,0.0],[0.0,1.0,0.0],[0.0,0.0,1.0])
> (%i4) m . invert(m);
> (%o4) MATRIX([1.0,0.0,0.0],[0.0,1.0,0.0],[0.0,0.0,1.0])
> (%i5) invert(m) - m^^-1;
> RAT replaced -0.3 by -3//10 = -0.3
> RAT replaced -0.3 by -3//10 = -0.3
> (%o5) MATRIX([0.0,0,0],[0.0,0.0,0],[0.0,0.0,0.0])
> (%i6) build_info();
> 
> Maxima version: 5.9.0.9beta1
> Maxima build date: 12:41 7/13/2004
> host type: i686-pc-mingw32
> lisp-implementation-type: Kyoto Common Lisp
> lisp-implementation-version: GCL 2.7.0
> 
> After the change, My $adjoint function is
> 
> (EVAL-WHEN (COMPILE EVAL LOAD)
>  (DEFPROP $ADJOINT T TRANSLATED)
>  (ADD2LNC '$ADJOINT $PROPS)
>  (DEFMTRFUN
>   ($ADJOINT $ANY MDEFINE NIL NIL)
>   ($MAT)
>   NIL
>   ((LAMBDA
>     ($ADJ $N)
>     NIL
>     (SETQ $N ($LENGTH $MAT))
>     (SETQ $ADJ (SIMPLIFY ($IDENT $N)))
>     (COND
>      ((NOT (LIKE $N 1))
>       (DO (($I 1 (f+ 1 $I)))
>           ((> $I $N) '$DONE)
>         (DO (($J 1 (f+ 1 $J)))
>             ((> $J $N) '$DONE)
>          (MASET (MUL (POWER -1 (f+ $I $J))  ;; changed MUL* --> MUL
>                       (SIMPLIFY ($DETERMINANT (SIMPLIFY ($MINOR $MAT
>                                                                 $J
>                                                                 $I)))))
>                 $ADJ
>                 $I
>                 $J)))))
>     $ADJ)
>    '$ADJ
>    '$N)))
> 
> Could the 'eval-when' be the real trouble maker?
> 
> Barton
> 
> _______________________________________________
> Maxima mailing list
> Maxima@www.math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
> 
> 
> 

-- 
Camm Maguire			     			camm@enhanced.com
==========================================================================
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah