Why would using together() change the solution and why would simplify() return False?

63 views
Skip to first unread message

G B

unread,
Jul 12, 2015, 8:46:32 PM7/12/15
to sy...@googlegroups.com
What would case Eq.simplify() to return False?  There isn't a lot of computation time before the result.

Also why would using together() before substituting an expression lead to a numerically different result?

I have a series of equations that I've been substituting in to each other building up a final symbolic result.  My first pass at this gave a result that looks reasonable (though I haven't proven it correct) when I convert it to a numpy function after using 
  Eq.subs(dictionary of values for symbols).simplify().n() 
and plot it.

When I took the last symbolic equation to be substituted and use Eq.together() on it before substituting to get a simpler result, the Eq.subs().simplify() returns False.  When I manipulate it differently to get it to successfully lambdify, the resulting plot is different (and appears wrong).

Thanks--

Aaron Meurer

unread,
Jul 13, 2015, 1:26:18 PM7/13/15
to sy...@googlegroups.com
On Sun, Jul 12, 2015 at 7:46 PM, G B <g.c.b....@gmail.com> wrote:
> What would case Eq.simplify() to return False? There isn't a lot of
> computation time before the result.

Can you show an example of what is doing this?

>
> Also why would using together() before substituting an expression lead to a
> numerically different result?

How different? It's possible you are changing the numerical stability
of the expression. Or it's possible there is a bug in together.

Aaron Meurer

>
> I have a series of equations that I've been substituting in to each other
> building up a final symbolic result. My first pass at this gave a result
> that looks reasonable (though I haven't proven it correct) when I convert it
> to a numpy function after using
> Eq.subs(dictionary of values for symbols).simplify().n()
> and plot it.
>
> When I took the last symbolic equation to be substituted and use
> Eq.together() on it before substituting to get a simpler result, the
> Eq.subs().simplify() returns False. When I manipulate it differently to get
> it to successfully lambdify, the resulting plot is different (and appears
> wrong).
>
> Thanks--
>
> --
> 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/1c324cfc-6bb3-4951-8cd7-22394a8c4bcd%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

G.B.

unread,
Jul 14, 2015, 1:51:50 PM7/14/15
to sy...@googlegroups.com
Hey Aaron—

Maybe the best way to capture an example is an IPython notebook?

Let me know if this doesn’t work properly…

Cheers—

Together and Simplify Tests.ipynb.json

Aaron Meurer

unread,
Jul 14, 2015, 9:05:32 PM7/14/15
to sy...@googlegroups.com
I think there is a bug. If you take the two expressions, subtract them, and call simplify(), you get a result that isn't 0. equals() also says they are different. 

simplify() returning False is also a bug.

Can you open two issues for these things? Just put some minimal code to create the expressions in the issue (i.e., just print the expressions using str()). 

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.

For more options, visit https://groups.google.com/d/optout.


> You received this message because you are subscribed to a topic in the Google Groups "sympy" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/sympy/niic3OG_vhs/unsubscribe.
> To unsubscribe from this group and all its topics, 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.

> 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 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.

G.B.

unread,
Jul 16, 2015, 1:33:54 PM7/16/15
to sy...@googlegroups.com
Will do.  If I print the expression using str(), I get:


'I_{R_2}(s) == -C_{T}*s*(-R_{1}*V_{in}(s)/(R_{1} + 1/(1/(1/(C_{T}*s + 1/(L_{R}*s + R_{2} + 1/(C_{R}*s))) + 1/(C_{L}*s)) + 1/(L_{L}*s))) + V_{in}(s) - (-R_{1}*V_{in}(s)/(R_{1} + 1/(1/(1/(C_{T}*s + 1/(L_{R}*s + R_{2} + 1/(C_{R}*s))) + 1/(C_{L}*s)) + 1/(L_{L}*s))) + V_{in}(s))/(C_{L}*s*(1/(C_{T}*s + 1/(C_{R} + L_{R} + R_{2})) + 1/(C_{L}*s)))) - (-R_{1}*V_{in}(s)/(R_{1} + 1/(1/(1/(C_{T}*s + 1/(L_{R}*s + R_{2} + 1/(C_{R}*s))) + 1/(C_{L}*s)) + 1/(L_{L}*s))) + V_{in}(s))/(1/(C_{T}*s + 1/(C_{R} + L_{R} + R_{2})) + 1/(C_{L}*s))’

Is that usable or do I need to provide another means?  Is that IPython doc preferable (or the same in straight Python form)?

Thanks—
 Greg



Aaron Meurer

unread,
Jul 16, 2015, 4:32:39 PM7/16/15
to sy...@googlegroups.com
Oh I didn't realize you had LaTeX strings in your Symbol names. It would be more useful to use srepr() then, so that it can just be copy-pasted.

Aaron Meurer

G.B.

unread,
Jul 21, 2015, 2:53:31 PM7/21/15
to sy...@googlegroups.com
It looks like srepr() doesn’t capture the real=True parameter to Symbol.

from sympy import *
s=Symbol('s')
f=Symbol('f',real=True)
SExp=Eq(s,2*pi*I*f)
srepr(SExp)

—>   "Equality(Symbol('s'), Mul(Integer(2), I, pi, Symbol('f')))"


Is this another issue to be submitted?

In the mean time, I think it’s just going to be most straight forward if I convert the iPython notebook example to .py, and attach it.  Will that work for these other issues?

Thanks—
 Greg


Aaron Meurer

unread,
Jul 21, 2015, 3:00:26 PM7/21/15
to sy...@googlegroups.com
This is already fixed in master:

In [1]: srepr(Symbol('x', real=True))
Out[1]: "Symbol('x', real=True)"

Aaron Meurer


Reply all
Reply to author
Forward
0 new messages