pythonmathinequality

how to solve non-linear inequalities with python like 12<x*y<14 and 2x + 3y>40?


I want to solve a system of nonlinear inequality equations, Simplify as follows: 12<xy<14 and 2x + 3*y>40, is there any way to find the minimum of x using python, i konw how to solve linear inequality quations with scipy.optimize.linprog,but i can't find the way to solve non-linear inequality quations,thanks


Solution

  • Z3 is a SAT/SMT solver that could be interesting for this type of problems.

    Here is an example looking for integer solutions. Note that the given equations are unbounded for floats.

    from z3 import Optimize, Int, And
    
    opt = Optimize()
    x = Int('x')
    y = Int('y')
    opt.add(And(x * y > 12, x * y < 14))
    opt.add(2 * x + 3 * y > 40)
    opt.minimie(x)
    print(opt.check())  # prints sat
    print(opt.model())  # prints [y = 13, x = 1]