rtoy / maxima

A Clone of Maxima's repo
Other
0 stars 0 forks source link

(q*M)^^-1 doesn't expand out #2502

Open rtoy opened 3 months ago

rtoy commented 3 months ago

Imported from SourceForge on 2024-07-06 10:05:47 Created by macrakis on 2022-02-20 15:01:25 Original: https://sourceforge.net/p/maxima/bugs/3944


matrix([1,1],[a,1])^^-1,detout;

[  1   - 1 ]
[          ]
[ - a   1  ]
------------
   1 - a

%^^-1;

 [  1   - 1 ]
 [          ]
 [ - a   1  ]  <- 1>
(------------)
    1 - a

Contrast

matrix([1,1],[-1,1])^^-1,detout; 

[ 1  - 1 ]
[        ]
[ 1   1  ]
----------
   2

%^^-1;

[  1   1 ]
[        ]
[ - 1  1 ]

I thought that the problem is that detout returns a pseudo-simplified (non-canonically simplified) expression. But in fact this happens even with correctly simplified expressions:

declare(A,nonscalar)$
(q*A)^^-1 => (q*A)^^-1
>>> should be A^^-1/q

but

(2*A)^^-1 => A^^-1 / 2

I don't believe this behavior is controlled by a **dot**xxx setting, but I may be mistaken.

Maxima 5.45.1 SBCL 2.0.0 Windows

rtoy commented 3 months ago

Imported from SourceForge on 2024-07-06 10:05:48 Created by robert_dodier on 2022-02-21 07:38:01 Original: https://sourceforge.net/p/maxima/bugs/3944/#d5b5


Looking at the code (SIMPNCEXPT in src/mdot.lisp), I see that behavior is governed by SIMPNCT-SC-OR-CONSTP in lines 280--281. A constant factor is pulled out if dotconstrules is nonnull, and a scalar factor is pulled out if dotscrules is nonnull; see SIMPNCT-CONSTANTP and SIMPNCT-ASSUMESCALARP, respectively.

The default value of dotconstrules is true, so literal or declared constants are pulled out. The default value of dotscrules is false, so scalars are not pulled out. However, changing to the other value (false or true) changes the behavior as expected. Also, assumescalar: all causes undeclared symbols to be treated as scalars, as expected.

At this point I think the code is working as expected, and it's just a matter of mentioning ^^ in the documentation for dotconstrules, dotscrules, and assumescalar. Likewise those flags should be mentioned in the documentation for ^^.

rtoy commented 3 months ago

Imported from SourceForge on 2024-07-06 10:05:52 Created by robert_dodier on 2022-02-21 07:38:59 Original: https://sourceforge.net/p/maxima/bugs/3944/#6f84


rtoy commented 3 months ago

Imported from SourceForge on 2024-07-06 10:05:55 Created by macrakis on 2022-02-21 13:52:18 Original: https://sourceforge.net/p/maxima/bugs/3944/#cfdd


Thanks for looking in to this. Indeed, dotscrules:true$ assumescalar:all takes care of this case. However, according to the documentation of assumescalar, an undeclared symbol which is an argument to a commutative operator like * is assumed scalar, so this should work:

declare(A,nonscalar)$
dotscrules:true$
(q*A)^^-1  =>  (A*q)^^-1   <<< ???

Although the doc for assumescalar only mentions explicit lists and matrices, not symbols declared nonscalar as the other argument, the fact that it works in the all case suggests that it should work in the true case as well.

PS I had actually tested all the dotxxx variables... though not assumescalar.