Can sympy solve (1. - (x ** n)) ** (1/n) = y , and similar?

42 views
Skip to first unread message

Stuart Reynolds

unread,
Mar 8, 2019, 12:25:58 PM3/8/19
to sympy
Dear Sympy users,

I'm new to sympy and interested in using it for function design.
I'm curious about what types of things I should be able to expected sympy.solve to solve. In particular, trying to solve:
(1. - (x ** 2)) ** (1. / 2) = 1/2
seems to fail for me:


import sympy
x, one, two = sympy.symbols("x 1 2")

# Equation of circle: y=sqrt(1 - x^2)
# What x is gives 1/2?
f = (one - (x ** two)) ** (one / two)

# Asking sympy to find the analytics solution:
print sympy.solveset(sympy.Eq(f, one/two), x, domain=sympy.Reals)
# ValueError: x**w where w is irrational is not defined for negative x



This equation as a solution:
print sympy.lambdify([], f.subs({x:0.865}))() # 0.501 --- seems pretty close


Did I ask it wrong or is it a limitation of the solver?

Thanks,
- Stuart

Vishesh Mangla

unread,
Mar 8, 2019, 12:27:41 PM3/8/19
to sy...@googlegroups.com

 

Can you solve it manually?

Sent from Mail for Windows 10

--
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 https://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/7926e18a-0051-440f-be17-4d7e427861c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

 

Oscar Benjamin

unread,
Mar 8, 2019, 12:57:12 PM3/8/19
to sympy
On Fri, 8 Mar 2019 at 17:25, Stuart Reynolds <stuart....@gmail.com> wrote:
>
> Dear Sympy users,
>
> I'm new to sympy and interested in using it for function design.
> I'm curious about what types of things I should be able to expected sympy.solve to solve. In particular, trying to solve:
> (1. - (x ** 2)) ** (1. / 2) = 1/2
> seems to fail for me:

You can solve it like this using rational or floats:

In [9]: solve(Eq((1-(x**2))**(S(1)/2), S(1)/2), x)

Out[9]:

⎡-√3 √3⎤

⎢────, ──⎥

⎣ 2 2 ⎦


In [10]: solve(Eq((1.0-(x**2))**0.5, 0.5), x)

Out[10]: [-0.866025403784439, 0.866025403784439]

Stuart Reynolds

unread,
Mar 8, 2019, 1:16:53 PM3/8/19
to sy...@googlegroups.com
Ahh -- thank you. I was using solveset. Should have used solve.

--
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 https://groups.google.com/group/sympy.

Aaron Meurer

unread,
Mar 9, 2019, 3:48:26 PM3/9/19
to sy...@googlegroups.com
solveset should be able to solve equations like this. If it can't,
please open an issue for it. For me it works just fine for
solveset(Eq((1-(x**2))**(S(1)/2), S(1)/2), x). It does have problems
with the general symbolic solveset(Eq((1-(x**n))**(S(1)/n), y), x)
because of domain and assumptions issues.

>>> solveset(Eq((1-x**n)**(1/n), y), x)
ConditionSet(x, Eq(-y + (1 - x**n)**(1/n), 0), Complexes(Reals x Reals, False))
>>> solveset(Eq((1-x**n)**(1/n), y), x, Reals)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "./sympy/solvers/solveset.py", line 1696, in solveset
return solveset(f.xreplace({symbol: r}), r, domain
File "./sympy/solvers/solveset.py", line 1714, in solveset
return _solveset(f, symbol, domain, _check=True)
File "./sympy/solvers/solveset.py", line 916, in _solveset
result = solver(Add(f.lhs, - f.rhs, evaluate=False), symbol, domain)
File "./sympy/solvers/solveset.py", line 883, in <lambda>
solver = lambda f, x, domain=domain: _solveset(f, x, domain)
File "./sympy/solvers/solveset.py", line 931, in _solveset
lhs, rhs_s = inverter(f, 0, symbol)
File "./sympy/solvers/solveset.py", line 884, in <lambda>
inverter = lambda f, rhs, symbol: _invert(f, rhs, symbol, domain)
File "./sympy/solvers/solveset.py", line 156, in _invert
x1, s = _invert_real(f_x, FiniteSet(y), x)
File "./sympy/solvers/solveset.py", line 202, in _invert_real
return _invert_real(h, imageset(Lambda(n, n - g), g_ys), symbol)
File "./sympy/solvers/solveset.py", line 237, in _invert_real
raise ValueError("x**w where w is irrational is not "
ValueError: x**w where w is irrational is not defined for negative x
>>> solve(Eq((1-x**n)**(1/n), y), x)
[(1 - y**n)**(1/n)]

I don't know if this can be improved.

Aaron Meurer
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAAy-kdkVyuvWiUt1ArXpZhJPDtWn4hswdC6wXfpGn--fwVRNfw%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages