For 8 + 8/(1+p), apart() will give this form.

In general, it likely depends on the expression which function will do
this. You can use the count method to count how many times a variable
appears in an expression

In [65]: (8 + 8/(1+x)).count(x)
Out[65]: 1

In [66]: (8*(x + 3)/(x + 2)).count(x)
Out[66]: 2

You could use the measure option to simplify to tell it to minimize this:

In [67]: simplify(8 + 8/(1+x), measure=lambda i: i.count(x))
Out[67]:
      8
8 + ─────
    x + 1

You could also write your own function that tries various functions
and returns the result with the fewest occurrences of the variables.

Aaron Meurer


On Wed, May 18, 2016 at 5:49 PM, Timothy Wright <[email protected]> wrote:
> Hi
>
> I am using factor() to reduce the equation '8 + 8/(1+p)'
>
> I get 8*(p + 3)/(p + 2) because factor() must return a product.  But I want
> a reduction that minimizes the number of each variable in the equation.  In
> this case, my input referenced p once, running factor gives me a product
> that has two references to p.
>
> I need to generalize this to very long equations with 5 independent
> variables.  I am replacing the use of mathematica with sympy, mathematica
> seems to be able to reduce the equation in this way
>
> I have looked at cancel(), simplify(), apart(), expand(), all don't do what
> I want.
>
> After reviewing the email history, I don't think this can be done out of the
> box.  But there could be a way to write my own reducer to do this?
>
> Is this correct?  I want to check if I am on the right path.
>
> Thanks
>
> Tim
>
> --
> 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/43f8ff85-9b85-43ad-942b-90722d86a506%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%3D6KFJbN758LPPBoxe7Kjzfp5Xx0iYigTVt4Oky5UhWtJCg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to