@Aaron - Will do. In general my point was that here is a case where we want to write down X*Y in one way potentially but act on the syntax in two different ways. We want to build two different mechanisms to consume the expression X+Y
1. Return an unevaluated but simplified Matrix Expr 2. Return a fully evaluated ImmutableMatrix In our current design we have to make a single choice. It'd be nice if we could plug in either these two choices in a systematic way. It would also be nice if we could chain them. For example we might want to simplify the X+X into 2*X before turning it into an ImmutableMatrix. @Krastanov - you bring up a good point that it would be nice if ImmutableMatrix(X*Y) worked. I think that users are more likely to try this before looking for and finding .as_explicit() On Sun, Mar 11, 2012 at 3:27 PM, Aaron Meurer <[email protected]> wrote: > On Sun, Mar 11, 2012 at 3:55 PM, Matthew Rocklin <[email protected]> > wrote: > > Right i**2 is a MatrixExpr. At some point someone suggested that we have > > unevaluated dense matrix expressions. This choice was made to satisfy > that > > desire. We can change things around though. > > > > In [1]: X = ImmutableMatrix(3,3, range(9)) > > In [4]: Y = ImmutableMatrix(ones(3, 3)) > > > > In [6]: X*Y > > Out[6]: > > ⎡0 1 2⎤⋅⎡1 1 1⎤ > > ⎢ ⎥ ⎢ ⎥ > > ⎢3 4 5⎥ ⎢1 1 1⎥ > > ⎢ ⎥ ⎢ ⎥ > > ⎣6 7 8⎦ ⎣1 1 1⎦ > > > > In [7]: (X*Y)[0,0] # indexing works > > Out[7]: 3 > > > > In [8]: (X*Y).as_explicit() > > Out[8]: > > ⎡3 3 3 ⎤ > > ⎢ ⎥ > > ⎢12 12 12⎥ > > ⎢ ⎥ > > ⎣21 21 21⎦ > > > > This isn't necessarily the way that things should be done though. One > could > > imagine a number of alternatives. This conversation ties in well to the > > container vs. canonicalizer idea happening in this thread. > > I added stub sections for MatrixExpr and ImmutableMatrix at > https://github.com/sympy/sympy/wiki/canonicalization. It would be > great if you could write some stuff there, as I really don't have a > good idea of what it should be able to do. > > Aaron Meurer > > > > > -Matt > > > > On Sun, Mar 11, 2012 at 1:18 PM, [email protected] > > <[email protected]> wrote: > >> > >> Actually one can use as_explicit. I did not saw it in the > >> documentations, only when I checked the code I found about it. > >> > >> On 11 March 2012 21:14, [email protected] > >> <[email protected]> wrote: > >> > n [8]: i = ImmutableMatrix(eye(3)) > >> > > >> > In [9]: i**2 > >> > Out[9]: > >> > > >> > 2 > >> > ⎡1 0 0⎤ > >> > ⎢ ⎥ > >> > ⎢0 1 0⎥ > >> > ⎢ ⎥ > >> > ⎣0 0 1⎦ > >> > > >> > In [10]: _.doit() > >> > TypeError > >> > > >> > Casting to Matrix does not work either. How to actually calculate the > >> > product with Immutable matrices? > >> > >> -- > >> You received this message because you are subscribed to the Google > Groups > >> "sympy" group. > >> To post to this group, send email to [email protected]. > >> To unsubscribe from this group, send email to > >> [email protected]. > >> For more options, visit this group at > >> http://groups.google.com/group/sympy?hl=en. > >> > > > > -- > > You received this message because you are subscribed to the Google Groups > > "sympy" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]. > > For more options, visit this group at > > http://groups.google.com/group/sympy?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/sympy?hl=en. > > -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
