Sympy solver exclude result

32 Views Asked by At

I would like to know if it is possible with Sympy to solve simple equation of this kind not especially this one:

sol = solve(x**2)

but with conditions like for example :

  • sol[0] < n (n is a real number )
  • sol[0] != n
  • m < sol[0] < n (m is a real number too)

And if i can put the same condition for

Product( k, (k, 1, 3) ).doit()

And other if it is possible.

Thanks.

Read documentation for hours and found nothing.

Look on stackoverflow and else where on the internet

And i am kind of not an expert so i found those and was not sure if it answer my question because i did not understand what they say:

1

There are 1 best solutions below

0
smichr On

Your question is too vague to answer well. Is it a univariate expression you are trying to solve? Do you expect a closed form solution? You can use solveset and give it the domain in which to search for a solution,

>>> from sympy import *
>>> from sympy.abc import x,n
>>> solveset(x**2-1, x, Interval(0,3))
{1}
>>> solveset(x**2-1, x, (x<3).as_set())
{-1, 1}

I don't know what you want to try to do with the Product, but

>>> Product( k, (k, 1, 3) ).doit() < n
6 < n
>>> Product( k, (k, 1, 3) ).doit() < 1
False