I like that. I am glad to write a patch if this is the desired behavior of simplify. Does there need to be a check for whether or not something is a fraction first? Is checking for denom == 1 the best way to do that?
In [146]: a,b = x2_tf_ds.as_numer_denom() In [147]: a Out[147]: Gc*k In [148]: b Out[148]: Gc*k + k*m1*s**2 + k*m2*s**2 + m1*m2*s**4 In [149]: b.as_numer_denom() Out[149]: (Gc*k + k*m1*s**2 + k*m2*s**2 + m1*m2*s**4, 1) Ryan On Mon, Jun 8, 2009 at 12:45 PM, Aaron S. Meurer <asmeu...@gmail.com> wrote: > > You might look into could_extract_minus_sign: > >>> sympify('-Gc*k/(-Gc*k - k*m1*s**2 - k*m2*s**2 - > m1*m2*s**4)').could_extract_minus_sign() > True > >>> sympify('Gc*k/(-Gc*k - k*m1*s**2 - k*m2*s**2 - > m1*m2*s**4)').could_extract_minus_sign() > False > > Perhaps simplify() should do > > if expr.could_extract_minus_sign(): > n, d = expr.as_numer_denom() > expr = sympify(-1)*n/(sympify(-1)*d) > > or some similar. > > > Aaron Meurer > On Jun 8, 2009, at 11:36 AM, Ryan Krauss wrote: > > > So, I have yet another simplification question. What is the correct > > way to factor a minus one out of this: > > > > In [108]: type(x2_tf_ds) > > Out[108]: <class 'sympy.core.mul.Mul'> > > > > In [109]: x2_tf_ds > > Out[109]: -Gc*k/(-Gc*k - k*m1*s**2 - k*m2*s**2 - m1*m2*s**4) > > > > This didn't work: > > In [110]: sympy.simplify(x2_tf_ds) > > Out[110]: -Gc*k/(-Gc*k - k*m1*s**2 - k*m2*s**2 - m1*m2*s**4) > > > > This works, and is fine with me. But I wonder if there is a better > > way: > > In [111]: a,b = x2_tf_ds.as_numer_denom() > > > > In [112]: -a/-b > > Out[112]: Gc*k/(Gc*k + k*m1*s**2 + k*m2*s**2 + m1*m2*s**4) > > > > > > Thanks, > > > > Ryan > > > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sympy@googlegroups.com To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sympy?hl=en -~----------~----~----~----~------~----~------~--~---