Skip to content
Symi Docs
Swift
On this page

Polynomial queries

These take ordinary expressions plus a variable name; the named variable becomes the main polynomial variable and every other free variable rides along symbolically in the coefficients. An expression that is not polynomial in the variable (a transcendental call of it, a non-integer power of it) makes the query decline — None for degree, an error for the others.

degree#

Explicit context

func degree(
    inputExpression: UniffiExpression,
    variable: String,
) -> UInt64?

Degree in variable. None when the expression is not polynomial in variable or is identically zero (the zero polynomial has no degree under the core convention).

leading_coefficient#

Explicit context

func leadingCoefficient(
    inputExpression: UniffiExpression,
    variable: String,
) -> UniffiExpression

Coefficient of the highest power of variable; may contain the other free variables. Errors on non-polynomial or zero input.

coefficient#

Explicit context

func coefficient(
    inputExpression: UniffiExpression,
    variable: String,
    power: UInt64,
) -> UniffiExpression

Coefficient of variable^power; integer 0 when the term is absent. Errors on non-polynomial input.

polynomial_gcd#

Explicit context

func polynomialGcd(
    left: UniffiExpression,
    right: UniffiExpression,
    variable: String,
) -> UniffiExpression

Greatest common divisor of the two expressions as polynomials in variable (primitive, with the core's sign normalisation). Errors when either input is not polynomial in variable.

resultant#

Explicit context

func resultant(
    left: UniffiExpression,
    right: UniffiExpression,
    variable: String,
) -> UniffiExpression

Resultant with respect to variable; zero exactly when the two polynomials share a root (over the algebraic closure). Errors on non-polynomial input.

isolate_real_roots#

Explicit context

func isolateRealRoots(
    inputExpression: UniffiExpression,
    variable: String,
) -> [UniffiIsolatingInterval]

One (lower, upper) rational isolating interval per distinct real root, sorted ascending; a collapsed pair (r, r) marks an exact rational root. Requires a non-zero univariate polynomial with rational coefficients. Notes: WASM returns IsolatingInterval objects with lower/upper getters.

isolating_interval (WASM result class)#

lower#

UniffiIsolatingInterval method

func lower() -> UniffiExpression

Lower endpoint of the isolating interval.

upper#

UniffiIsolatingInterval method

func upper() -> UniffiExpression

Upper endpoint of the isolating interval.

Gröbner bases and ideals#

These operate over the polynomial ring Q[variables]\mathbb{Q}[\text{variables}]. Generators are passed as an expression list; the ring variables are named by a string list; the monomial order is named by a string ("lexicographic" / "lex", "degree_lexicographic" / "deglex", or "degree_reverse_lexicographic" / "degrevlex", the computational default). Any generator that is not a polynomial over Q\mathbb{Q} in the named variables — a transcendental call, a non-integer power, an unnamed symbol, or an irrational coefficient — makes the operation decline cleanly (Python None, WASM null); it never returns a wrong or partial answer. Within Q[variables]\mathbb{Q}[\text{variables}] the results are exact and complete: a returned basis is the canonical reduced Gröbner basis, membership is a genuine decision, and elimination is exact by the Elimination Theorem.

Performance. The basis is computed by F4 (Faugère's batched Macaulay-matrix reduction), with a signature-based engine (F5 / GVW) available internally; the reference Buchberger algorithm is retained as the differential oracle these are checked against. The choice of engine is an internal acceleration only: the result is identical to the reference Buchberger basis for every input, and the monomial-order argument and the whole binding surface are unchanged. These entry points simply run faster — there is no new method to call.

groebner_basis#

Explicit context

func groebnerBasis(
    generators: [UniffiExpression],
    variables: [String],
    order: UniffiMonomialOrdering,
) -> [UniffiExpression]?

The canonical reduced Gröbner basis of the ideal <generators> under the named monomial order — monic, autoreduced, and sorted, so it is unique for the (ideal, order) pair. None when any generator is outside Q[variables]\mathbb{Q}[\text{variables}].

ideal_membership#

Explicit context

func idealMembership(
    element: UniffiExpression,
    generators: [UniffiExpression],
    variables: [String],
    order: UniffiMonomialOrdering,
) -> Bool?

Whether element lies in the ideal <generators>, decided by reducing it to its normal form modulo the Gröbner basis (zero exactly when it is a member). The verdict is independent of the order. None when the element or a generator is outside Q[variables]\mathbb{Q}[\text{variables}].

ideal_sum#

Explicit context

func idealSum(
    generatorsLeft: [UniffiExpression],
    generatorsRight: [UniffiExpression],
    variables: [String],
    order: UniffiMonomialOrdering,
) -> [UniffiExpression]?

A Gröbner basis of the ideal sum I + J, the ideal generated by the two generator lists together. None on a non-Q[variables]\mathbb{Q}[\text{variables}] generator.

ideal_product#

Explicit context

func idealProduct(
    generatorsLeft: [UniffiExpression],
    generatorsRight: [UniffiExpression],
    variables: [String],
    order: UniffiMonomialOrdering,
) -> [UniffiExpression]?

A Gröbner basis of the ideal product IJI J, generated by all pairwise products of the two generator lists. None on a non-Q[variables]\mathbb{Q}[\text{variables}] generator.

ideal_intersection#

Explicit context

func idealIntersection(
    generatorsLeft: [UniffiExpression],
    generatorsRight: [UniffiExpression],
    variables: [String],
    order: UniffiMonomialOrdering,
) -> [UniffiExpression]?

A generating set of the ideal intersection I∩JI \cap J, computed by the standard tag-variable elimination construction tI+(1−t)Jt I + (1-t) J. None on a non-Q[variables]\mathbb{Q}[\text{variables}] generator.

elimination_ideal#

Explicit context

func eliminationIdeal(
    generators: [UniffiExpression],
    variables: [String],
    eliminate: [String],
) -> [UniffiExpression]?

A Gröbner basis of the elimination ideal ⟨generators⁡⟩∩Q[surviving variables]\langle\operatorname{generators}\rangle \cap \mathbb{Q}[\text{surviving variables}], projecting away the variables named in eliminate via the Elimination Theorem (a block order ranks the eliminated variables high and the generators free of them are kept). Exact: it neither drops nor introduces components. None on a non-Q[variables]\mathbb{Q}[\text{variables}] generator. Example: eliminating t from {x−t2,y−t3}\{x - t^2, y - t^3\} returns the twisted-cubic implicit equation y2−x3y^2 - x^3.

Order change and implicitisation#

These consume a Gröbner basis rather than compute one from scratch. The order change runs the standard FGLM algorithm; implicitisation is parameter elimination with the rational-parametrisation saturation wired in.

change_monomial_order#

Explicit context

func changeMonomialOrder(
    basis: [UniffiExpression],
    variables: [String],
    sourceOrder: UniffiMonomialOrdering,
    targetOrder: UniffiMonomialOrdering,
) -> [UniffiExpression]?

Convert a Gröbner basis of a zero-dimensional ideal from source_order to target_order by FGLM (Faugère–Gianni–Lazard–Mora) — linear algebra in the finite-dimensional quotient ring Q[variables]/I\mathbb{Q}[\text{variables}]/I, far cheaper than computing the target basis directly (the msolve route to a lexicographic basis is a cheap degrevlex basis followed by this conversion). The result is the canonical reduced Gröbner basis under target_order, identical to a direct groebner_basis call. None when the ideal is positive-dimensional (the quotient ring is infinite-dimensional, so FGLM does not apply) or any generator is outside Q[variables]\mathbb{Q}[\text{variables}].

implicitize#

Explicit context

func implicitize(
    coordinates: [String],
    parameters: [String],
    parametricExpressions: [UniffiExpression],
) -> [UniffiExpression]?

The implicit ideal of a parametric curve or surface xi=fi(parameters⁡)x_i = f_i(\operatorname{parameters}) (the i-th coordinate paired with the i-th parametric expression), returned as a generator list over Q[coordinates]\mathbb{Q}[\text{coordinates}] — the elimination of the parameters (Cox–Little–O'Shea ch. 3). A polynomial parametrisation eliminates the parameters directly; a rational one fi=pi/qif_i = p_i/q_i clears denominators and saturates by the denominator product through a fresh tag variable, so the eliminant is the true implicit equation rather than a multiple carrying spurious components. None when a parametric expression is outside Q(parameters⁡)\mathbb{Q}(\operatorname{parameters}) or there are no parameters. Examples: {x=t2,y=t3}\{x = t^2, y = t^3\} returns y2−x3y^2 - x^3; {x=(1−t2)/(1+t2),y=2t/(1+t2)}\{x = (1 - t^2)/(1 + t^2), y = 2t/(1 + t^2)\} returns x2+y2−1x^2 + y^2 - 1.

Example#

Additional API#

cylindrical_algebraic_decomposition#

Explicit context

func cylindricalAlgebraicDecomposition(
    expressions: [UniffiExpression],
    variables: [String],
    equationalConstraints: [UInt64],
) -> UniffiCylindricalAlgebraicDecomposition

Construct the CAD of the polynomials in the given variable order x1,…,xnx_1,\ldots,x_n; projection eliminates xnx_n first).

plain_text#

Expression method

func plainText() -> String

The canonical plain-text form of this expression.

Symi documentation · Swift