Does it make sense to limit Sympy's infinity?
Question:
I have a problem with inequality math with the following problem. with x on
The result I want is like this this
my code
from sympy import *
x = symbols('x', real=True)
init_printing(use_unicode=True)
ekpr = Rational(1, 2)*x + 3 <= Rational(1, 5)*x
Hp = solve(ekpr, x)
sol = (Hp).as_set() & Range(-oo,oo)
sol
And I’m struggling to get the result I want, to be able to add -15, -14 to infinity sympy. until this is the last code of my struggle, but it still fails too.
Interval(x = -15, x = -14).as_relational(sol)
So that the results are as I want like this .
Thank you, any help will be highly appreciated
Answers:
Hp
is your solution which extends from -10 to negative infinity. You wish to constrain this to the integers in [-15, 0]
. You have nearly done this in what you have shown:
>>> Hp.as_set() & Range(-15,1) # [-15, 1) = [-15, 0]
{-15, -14, ..., -10}
Alternatively, you could give the range as the domain for solveset
:
>>> solveset(ekpr, x, Range(-15,1))
{-15, -14, ..., -10}
I have a problem with inequality math with the following problem. with x on
The result I want is like this this
my code
from sympy import *
x = symbols('x', real=True)
init_printing(use_unicode=True)
ekpr = Rational(1, 2)*x + 3 <= Rational(1, 5)*x
Hp = solve(ekpr, x)
sol = (Hp).as_set() & Range(-oo,oo)
sol
And I’m struggling to get the result I want, to be able to add -15, -14 to infinity sympy. until this is the last code of my struggle, but it still fails too.
Interval(x = -15, x = -14).as_relational(sol)
So that the results are as I want like this .
Thank you, any help will be highly appreciated
Hp
is your solution which extends from -10 to negative infinity. You wish to constrain this to the integers in [-15, 0]
. You have nearly done this in what you have shown:
>>> Hp.as_set() & Range(-15,1) # [-15, 1) = [-15, 0]
{-15, -14, ..., -10}
Alternatively, you could give the range as the domain for solveset
:
>>> solveset(ekpr, x, Range(-15,1))
{-15, -14, ..., -10}