Aaron, thanks, that's definitely the right idea, but doesn't work, probably 
because of simplification. Here's an example:


What I really want is a k3/k1 term in the denominator that can be 
substituted. Any way to achieve this?

On Thursday, November 10, 2016 at 3:54:30 PM UTC-5, Aaron Meurer wrote:
>
> 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] <javascript:>> 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] <javascript:>. 
> > To post to this group, send email to [email protected] 
> <javascript:>. 
> > 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/0a39376d-d426-4489-9ac2-656f68390844%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to