I'm not sure this is necessarily the best way to do it, but I found that combining as_ordered_factors() and as_base_exp() seems to do the trick.
If anyone is curious, here is a pull request that implements this optimization (among other things): https://bitbucket.org/yt_analysis/yt/pull-requests/1782/refactor-base-units-transformation-to/diff#comment-None On Sun, Oct 4, 2015 at 5:32 PM, Nathan Goldbaum <[email protected]> wrote: > Hi all, > > During a performance pass on some code that makes heavy use of sympy > symbol objects, I noticed expr.as_coeff_exponent() showing up in my > profiles. I'm using this function to multiplicatively factor a Symbol > object representing physical dimensions. Given a symbol x/y, I'm looking > for a way to compute that this is equivalent to x**1 * y**-1 > > Here x and y are members of a "base" set of Symbols I know all other > symbols must be composed through various multiplicative factors. > > I'm curious if there is a more performant way to implement this function, > given that I know I'm passing it instances of `Mul`. > > Thanks for your help! > > -Nathan > > -- > You received this message because you are subscribed to a topic in the > Google Groups "sympy" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/sympy/hKtATeALRYU/unsubscribe. > To unsubscribe from this group and all its topics, 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/f85cb699-747f-41f4-a386-64a39fde2d0b%40googlegroups.com > <https://groups.google.com/d/msgid/sympy/f85cb699-747f-41f4-a386-64a39fde2d0b%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 [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/CAJXewOnbmZi8PKxbD1FSBz6T8Yr8yMB74NUu4F7V%2Bto6e6g%2B%2BQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
