How do I construct this rational expression?

28 views
Skip to first unread message

Joachim Durchholz

unread,
Mar 28, 2015, 10:28:00 AM3/28/15
to sy...@googlegroups.com
I need to update a unit test where integrate now returns something that
contains 1/(2*(s+1)).
However, when I write that subexpression, SymPy gives me 1/(2*s + 2),
which compares unequal.

What would be the best way forward?
Alternatives that I can think of:
- have integrate() do whatever SymPy does when constructing 1/(2*s + 2)
- have the unit test do it and leave integrate() as it is
- rewrite the unit test to directly construct the Expr object (how?)

James Crist

unread,
Mar 28, 2015, 11:12:23 AM3/28/15
to sy...@googlegroups.com
One way that's pretty common is to do something like:

result = whatever your testing
solution = something you type in
assert simplify(result - solution) == 0

This is better than constructing a special case form, because that form may change in the future.

Aaron Meurer

unread,
Mar 28, 2015, 4:35:32 PM3/28/15
to sy...@googlegroups.com
Except in the tests you should use a more directed, efficient
simplification function than simplify(). cancel() should be sufficient
for this case.

Aaron Meurer
> --
> 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 sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> 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/cf30c58e-2fc2-4baa-b308-fa8335b41b3f%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

Joachim Durchholz

unread,
Mar 28, 2015, 6:43:53 PM3/28/15
to sy...@googlegroups.com
Am 28.03.2015 um 21:35 schrieb Aaron Meurer:
> Except in the tests you should use a more directed, efficient
> simplification function than simplify(). cancel() should be sufficient
> for this case.

That worked, thanks.

Is there a guideline which function to select for what kind of
normalization?
(I admit I haven't read SymPy's documentation, reading it all has always
been a daunting task.)
Reply all
Reply to author
Forward
0 new messages