Function Repository Resource:

# CountPolynomialSolutions

Count the roots to a system of polynomials

Contributed by: Daniel Lichtblau
 ResourceFunction["CountPolynomialSolutions"][polys,vars] counts the number of solutions of the polynomial system given by polys in the variables vars. ResourceFunction["CountPolynomialSolutions"][polys] counts the number of solutions in terms of the variables in polys.

## Details and Options

ResourceFunction["CountPolynomialSolutions"] counts all solutions over the complex numbers.
ResourceFunction["CountPolynomialSolutions"] counts solutions by multiplicity.
If the solution set has dimension greater than zero then ResourceFunction["CountPolynomialSolutions"] will return Infinity.
If the input has coefficients that are approximate numerical values then ResourceFunction["CountPolynomialSolutions"] will use approximate arithmetic. This can fail if precision is not sufficient for the method used.
The input for polys can be either a list of polynomials or a list of polynomial equations. In the former case the system in question is obtained by setting all polynomials to zero. The set of zeros is known as the variety defined by the polynomials.
If there are parameters then the count will be based on generic values for those parameters. For special cases the solution count might be either smaller or infinite (but never both finite and larger).
If the precision is finite and there are parameters then random values of that precision will be substituted for them before assessing the count.
If no vars are specified then the variables will be taken as Variables[polys] (so there will be no parameters in this situation). The vars list must be provided explicitly in order to have some unknowns regarded as variables.
ResourceFunction["CountPolynomialSolutions"] uses a method related to one of those used by NSolve, wherein a Gröbner basis is computed and the normal set is found.
ResourceFunction["CountPolynomialSolutions"] is typically more efficient than Solve since it does not attempt to form the solutions and also can use a (typically) more efficient term ordering.
In contrast to NSolve, ResourceFunction["CountPolynomialSolutions"] will use exact methods provided the input system is exact and WorkingPrecision is set to either Automatic (the default) or Infinity.

## Examples

### Basic Examples (3)

Count the number of solutions to a bivariate system:

 In:= Out= Compare to the number of solutions produced by Solve:

 In:= Out= Compare instead to the number of solutions produced by NSolve:

 In:= Out= ### Scope (5)

Count the solutions to a trivariate system with two polynomials of degree 3 and one of degree 4:

 In:= Out= Count the solutions to a larger system:

 In:= Out= Count the solutions to an "offset" system, wherein the polynomials are set equal to nonzero constants:

 In:= Out= Coefficients need not be rational:

 In:= Out= This is somewhat faster than explicitly solving the system:

 In:= Out= It is faster still to do the computation at modest finite precision:

 In:= Out= Coefficients can be parameters, that is, unknown values:

 In:= Out= We check that this is in fact the count for a specific set of parameter values:

 In:= Out= An overdetermined system often will have no solutions:

 In:= Out= A system of n polynomials in n variables might fail to have a finite solution set:

 In:= Out= If we allow z to be a parameter then the solution count is finite:

 In:= Out= ### Options (2)

This is a test system from an ISSAC 2001 conference paper:

 In:= It is quite slow to handle at exact precision:

 In:= Out= It can be done quite efficiently at a working precision of 200 digits:

 In:= Out= This is moreover several times faster than numerically solving the system at the same precision:

 In:= Out= A more extreme example comes from a 2009 ISSAC conference paper:

 In:= Out= NSolve on this example is 2-3 orders of magnitude slower:

 In:= Out= ### Properties and Relations (3)

The Caprasse system has 32 distinct solutions:

 In:= Out= A count by multiplicity shows a larger value:

 In:= Out= If we slightly perturb the system then Solve will find 56 distinct solutions in agreement with CountPolynomialSolutions:

 In:= Out= ### Possible Issues (4)

Inconsistent results can arise if the system (taken from this Mathematica.StackExchange post) has coefficients with low precision:

 In:= Out= We can get a different count by raising the precision:

 In:= Out= As is indicated in the StackExchange thread, there are further subtleties-- six of the eight solutions are quite large:

 In:= Out= This is because the exact system from which this was taken lives on the "discriminant variety" for systems with the same polynomial structure but having generic coefficients. Had we an exact form for the coefficients, these six would not be present (they go to infinity as the coefficients approach the discriminant variety).

One can isolate to the two expected solutions with some amount of trial and error in setting the Tolerance option of GroebnerBasis:

 In:= Out= ## Version History

• 1.0.1 – 07 August 2023
• 1.0.0 – 08 May 2023