Does it make sense to limit Sympy's infinity?

Question:

I have a problem with inequality math with the following problem. with x variable on

the picture

The result I want is like this this image

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

the output is like this picture

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

Thank you, any help will be highly appreciated

Asked By: Fahrizal

||

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}
Answered By: smichr
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.