I have no special ideas to propose except to start with the examples in this discussion. Maybe different working methods can be shown.
2014-06-06 14:23 GMT+02:00 Andrei Berceanu <andreiberce...@gmail.com>: > I agree, this could be helpful to many people. But first let's make sure > we iron out all the bugs. > And then I suppose one could re-write the expressions in a more > user-friendly form? > What do you propose, Chris? > > > On Friday, June 6, 2014 2:16:15 PM UTC+2, Christophe Bal wrote: > >> Hello. >> >> All the receipts in this dicussion look very interesting.Maybe all of >> this ones could be put in the official documentation. >> >> >> Christophe BAL >> >> >> 2014-06-06 13:34 GMT+02:00 Andrei Berceanu <andreib...@gmail.com>: >> >>> The unflatten_mul function factorized the 2, but not the g, i.e. it >>> returns >>> >>> 2(g*|psi1|**2 + g*|psi2|**2) >>> >>> instead of >>> >>> 2g*(|psi1|**2 + |psi2|**2) >>> >>> >>> On Friday, June 6, 2014 1:07:26 PM UTC+2, F. B. wrote: >>> >>>> >>>> >>>> On Friday, June 6, 2014 12:22:14 PM UTC+2, Andrei Berceanu wrote: >>>>> >>>>> Tnx! >>>>> I think there is an error in the line (unbalanced paranthesis): >>>>> >>>>> return node.xreplace ({e: S.One, conjugate(e): S.One})*abs(e)**2) >>>>> >>>>> >>>> Yes, sorry, just remove the last parenthesis. >>>> >>>> >>>> >>>>> Also, do you know how I can force the factorization of the 2*g to get >>>>> 2*g(|psi1|**2 + |psi2|**2)? >>>>> >>>>> >>>> Try this one: >>>> >>>> import collections >>>> >>>> def unflatten_mul(node): >>>> d = collections.defaultdict(lambda: []) >>>> new_args = [] >>>> for arg in node.args: >>>> if arg.args and arg.args[0].is_Number: >>>> d[arg.args[0]].append(arg.func(*arg.args[1:])) >>>> continue >>>> new_args.append(arg) >>>> print d >>>> for key, item in d.items(): >>>> new_args.append(Mul(key, Add(*item), evaluate=False)) >>>> return node.func(*new_args, evaluate=False) >>>> >>>> >>>> apply this function on *expr*, it should work. >>>> >>> -- >>> 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 sympy+un...@googlegroups.com. >>> To post to this group, send email to sy...@googlegroups.com. >>> >>> 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/4fd95b6b-043a-4bc5-8767-e9be9d83d9aa%40googlegroups.com >>> <https://groups.google.com/d/msgid/sympy/4fd95b6b-043a-4bc5-8767-e9be9d83d9aa%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >>> 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 sympy+unsubscr...@googlegroups.com. > To post to this group, send email to sympy@googlegroups.com. > 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/1fd9343c-c5ba-4000-b64c-1d825da0aad8%40googlegroups.com > <https://groups.google.com/d/msgid/sympy/1fd9343c-c5ba-4000-b64c-1d825da0aad8%40googlegroups.com?utm_medium=email&utm_source=footer> > . > > 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 sympy+unsubscr...@googlegroups.com. To post to this group, send email to sympy@googlegroups.com. 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/CAAb4jGkM28eQ%3DjY7S8RheO8UEHMe5E6%3DmKr2kj%2B6vGDrGktSTg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.