Simplification of constant-only Add-instances, but including radicals, using Sage and sympy

50 Views Asked by At

I'm in the process of developing simple functions that generate constants for various filters of various orders, such as Butterworth. For example, the result of Butterworth(2) would be:

s^2 + sqrt(2)*s + 1

(Darn the administrators for not choosing to support MathJax!)

I'm trying to simplify the generated coefficients. The example I'm having trouble with is a little more complicated than the example I'll present here. But the example here will get the point across.

Suppose I have the expression:

sqrt(2) * sqrt( sqrt(2) + 2 ) + 2 * sqrt( sqrt(2) + 2) )

Then using:

simplify( sqrt(2) * sqrt( sqrt(2) + 2 ) + 2 * sqrt( sqrt(2) + 2) ) )

Produces:

(sqrt(2) + 2)**(3/2)

Which is perfect for me.

But when I try something like:

simplify( 1 + sqrt(2) * sqrt( sqrt(2) + 2 ) + 2 * sqrt( sqrt(2) + 2) ) )

Then I get:

1 + sqrt(2) * sqrt( sqrt(2) + 2 ) + 2 * sqrt( sqrt(2) + 2) )

When I'd rather get:

1 + (sqrt(2) + 2)**(3/2)

Other than muddling through, using simplify() on all of the various combinations of 2 or more terms in an Add-instance to see what I get, and then prioritizing the better of them using some algorithm (as yet not well-conceived) I develop over time, my question is this:

Is there an existing function call that will recognize that:

1+sqrt(2)*sqrt(sqrt(2)+2)+2*sqrt(sqrt(2)+2)) = 1+(sqrt(2)+2)**(3/2)

I have other interests with simplification of constants that include radicals as well as rational values. But getting this far would be a big help.

[Since I'm only working with constants here (I use Poly() to gain access to the coefficients), this may be more of a Sage issue than sympy. But I'm not well-versed enough into these tools to know better. If an answer requires some explanation about the conceptual differences, feel free to inform me about it. Just FYI.]

Thanks in advance.

0

There are 0 best solutions below