SymPy expressions are immutable. You have to create a new expression.
I would recommend something like
def mul_and_div_factor(expr, factor):
n, d = expr.as_numer_denom()
return (n*factor)/(d*factor)
Aaron Meurer
On Thu, Nov 10, 2016 at 7:40 AM, Scott Calabrese Barton
<[email protected]> wrote:
> Hi, I wonder if there is an easy way to multiply the numerator and
> denominator of a rational expression by the same factor. I'd like to do this
> to group terms so that I can make a substitution.
>
> I tried making a function to do this:
>
> def tb(exp,factor):
> if exp.func==Mul and exp.args[-1].func==Pow \
> and exp.args[-1].args[-1]==-1:
> e=exp*factor
> denom=e.args[-1].args[0] * factor
> e.args[-1].args[0] = denom
>
> return e
>
>
>
> Unfortunately it doesn't work because of immutable tuples.
>
>
> --
> 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 https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/773995c5-ed93-42cd-a480-2e59bb9f4974%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 https://groups.google.com/group/sympy.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/CAKgW%3D6%2B%3D6-2iyHR36bBhQAhK%2BE0KOEmzcGVVp4uvt6TVA0mFCw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.