Thanks Aaron for pointing out the simplification section of the tutorial. Actually, collect(expr1, [x11, x12, x13]) does almost what I wanted. I still need to factor a -1 from x12( -x21x33 + x23x31). How would you do it using replace() like what I did? I also tried putting (x12*a).factor() as the value for replace but that didn't work. I had to use Mul() with evaluate = False to get it to do what I wanted.
On Wednesday, 4 November 2015 06:19:34 UTC+8, Aaron Meurer wrote: > > A good start would be the simplification section of the tutorial > http://docs.sympy.org/latest/tutorial/index.html. > > In this case, collect(expr1, [x11, x12, x13]) does what you want. > factor() only does complete factorizations (into products of terms). > This is explained in more depth in the tutorial. > > Aaron Meurer > > On Tue, Nov 3, 2015 at 2:47 PM, Hugh <[email protected] <javascript:>> > wrote: > > import sympy > > sympy.init_session() > > > > > > x11, x12, x13, x21, x22, x23, x31, x32, x33 = symbols('x_1:4(1:4)') > > > > A = Matrix(3,3,symbols('x_1:4(1:4)')) > > expr1 = A.det() > > > > expr2 = x11*(x22*x33 - x23*x32) - x12*(x21*x33 -x23*x31) + x13*(x21*x32 > - > > x22*x31) > > > > # How to get expr2 from expr1? > > > > I would like to use sympy to rewrite expressions just like how people > would > > commonly do when writing proofs or doing homework. What are the > > documentation that I must read so that I can be proficient at this? > > > > I've read the tutorial and some of the modules in the module reference > but > > feel that I have just barely touched the surface of sympy's > capabilities. > > For example, in the above code snippet, I don't know how to manipulate > expr1 > > to get expr2. I thought expr1.factor() would work but it didn't. > > > > Please advise. > > > > -- > > You received this message because you are subscribed to the Google > Groups > > "sympy" group. > > To unsubscribe from this group and stop receiving emails from it, send > an > > email to [email protected] <javascript:>. > > To post to this group, send email to [email protected] > <javascript:>. > > Visit this group at http://groups.google.com/group/sympy. > > To view this discussion on the web visit > > > https://groups.google.com/d/msgid/sympy/9cbb1995-3987-44f1-8c72-6de11e6a4013%40googlegroups.com. > > > > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sympy. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/438ac161-214e-497d-964c-87900be74dcb%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
