Search code examples
sympy

sympy nonlinsolve returns EmptySet


I'm wondering why nonlinsolve doesn't report the known value of a when that is the only variable I request a solution to:

a,b,c = symbols('a, b, c', real=True, positive=True)
eq1 = a - 1
eq2 = a - (b+c)

>>> nonlinsolve([eq1, eq2], [a])
EmptySet
>>> nonlinsolve([eq1, eq2], [a, b, c])
{(1, 1-c, c)}

How does one make sense of this?


Solution

  • The other answer is good but let me clarify a bit more:

    If a is specified as the unknown then b and c are symbolic parameters and the system is generically (for almost all possible values of b and c) unsatisfiable which is why the empty set is returned.

    Let's make the system simpler by removing one of the symbols:

    In [7]: a,b,c = symbols('a, b, c', real=True, positive=True)
    
    In [8]: nonlinsolve([a - 1, a - c], [a])
    Out[8]: ∅
    

    To see why this gives the empty set let's consider what we would get for different values of c:

    In [9]: nonlinsolve([a - 1, a - 2], [a])
    Out[9]: ∅
    
    In [10]: nonlinsolve([a - 1, a - 3], [a])
    Out[10]: ∅
    
    In [11]: nonlinsolve([a - 1, a - sqrt(2)], [a])
    Out[11]: ∅
    
    In [11]: nonlinsolve([a - 1, a - 0.99], [a])
    Out[11]: ∅
    

    Having seen the above cases is it surprising that:

    In [13]: nonlinsolve([a - 1, a - c], [a])
    Out[13]: ∅
    

    This is the correct answer for almost all possible values of c. There does exist a single value of c for which the equations can be satisfied but that is a degenerate case. The result returned by nonlinsolve is generically valid for almost all values of the symbolic parameters.

    You might wonder why nonlinsolve cannot figure out that c = 1 would make the system satisfiable but if c is not an unknown then it is not for nonlinsolve to presume that it has any particular value. Imagine say that the symbol c represents the speed of light and so its value is not something that nonlinsolve can freely choose to make the equations satisfiable.

    The empty set is the correct result here because you have presented a symbolically parametrised system that is generically unsatisfiable.