rtoy / maxima

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

declare symmetric changes indices in assignment #788

Open rtoy opened 4 months ago

rtoy commented 4 months ago

Imported from SourceForge on 2024-07-03 11:27:12 Created by robert_dodier on 2020-12-13 19:39:30 Original: https://sourceforge.net/p/maxima/bugs/3688


Quoted from bug report #3664. Making a separate report here since this is a separate topic.

Dan Hayes writes:

(n:3,kill(cm,m,mg), m[1]:ident(2),declare(mg,symmetric),mg:ident(3),for i thru 3 do cm[i]:zeromatrix(3,3),m[1][2,2]:-1,for i:2 thru 3 do
m[i]:zeromatrix(2,2),m[2][1,2]:1,m[3][2,1]:1,for i thru 3 do for j:i+1 thru 3 do( t:m[i].m[j]-m[j].m[i],disp([i,j,t])),cm[1][2,2]:2
,cm[2][1,2]:-2,cm[1][3,3]:-2,cm[3][1,3]:2,cm[2][3,1]:1,cm[3][2,1]:-1,for i thru 3 do(mg[i,i]:sum((cm[i].cm[i])[k,k],k,1,3),for j:i+1
thru 3 do(mg[i,j]:sum((cm[i].cm[j])[k,k],k,1,3),mg[j,i]:mg[i,j]) ),determinant(mg))

the determinant(mg) should be -128 but i get 0 here because it gives mg[3,2] wrongly as 0 as if the command mg[j,i]:mg[i,j] was not there which i should not have to put in anyway since i declared it symmetric but leaving it out did not work either now when i take out the declare(mg,symmetric) then it does give the correct -128.

rtoy commented 4 months ago

Imported from SourceForge on 2024-07-03 11:27:13 Created by robert_dodier on 2020-12-13 19:43:41 Original: https://sourceforge.net/p/maxima/bugs/3688/#1e27


rtoy commented 4 months ago

Imported from SourceForge on 2024-07-03 11:27:17 Created by robert_dodier on 2020-12-13 19:43:41 Original: https://sourceforge.net/p/maxima/bugs/3688/#46be


The problem here is that the left-hand side of an assignment is simplified, which is needed, e.g., when making an assignment such as x[k + 1]: 123 since arithmetic such as k + 1 is implemented by simplification, and declare(mg, symmetric) causes mg[j, i] to simplify to mg[i, j]. So the assignment is just mg[i, j]: mg[i, j]. One can see that in more detail via :lisp (trace mset).

I'm going to make this "won't fix" since we can't avoid simplification of the left-hand side in an assignment, and the simplification mg[j, i] --> mg[i, j] is the expected effect of declare(mg, symmetric).