I'm trying to solve a simple linear inequality in Sympy but can't seem to get it to work.
Basically, I want to be able to calculate the optimal values of a when the inequality happens to be false.
import sympy
num_attractors = 4
attractor_size = 64
network_size = 256
a, s, n = sympy.symbols('a s n')
expr = a * (s + 16) <= n
if not expr.subs([(a, num_attractors), (s, attractor_size), (n, network_size)]):
# compute optimal value for a i.e., the closest integer a s.t. a <= n / (s + 16)
I have tried using solve(expr, a , sympy.Integer) and sympy.solvers.inequalities.reduce_inequalities(expr,a) but can't seem to make sense of their output.
solvesetcan be used:You can also just take the
floorof the solution to the equality (and do so symbolically):