Skip to content
Symi Docs
Swift
On this page

Algebraic transforms

Directed algebraic rewrites change the form of an expression while preserving its value on the documented domain. Each operation applies one named transformation rather than searching, so the result shape is predictable. For the search-based ladder see general simplification.

expand#

Explicit context

func expand(target: UniffiExpression) -> UniffiExpression
Calling forms

Expression method: UniffiExpression.expand

func expand() -> UniffiExpression

Expand products, integer powers, and supported algebraic forms.

partial_fractions#

Explicit context

func partialFractions(
    inputExpression: UniffiExpression,
    variable: String,
) -> UniffiExpression
Calling forms

Expression method: UniffiExpression.partialFractions

func partialFractions(variable: String) -> UniffiExpression

Decompose a rational expression into polynomial and proper-fraction terms over the named variable.

For factorization, cancellation, collection, and radical operations, use general simplification.

Algebraic form changes#

factor#

Explicit context

func factor(target: UniffiExpression) -> UniffiExpression
Calling forms

Expression method: UniffiExpression.factor

func factor() -> UniffiExpression

Polynomial factorization over the rationals (full multivariate). With gaussian=True, factor a univariate polynomial over the Gaussian integers Z[i]\mathbb{Z}[i]; this form requires exactly one free variable and raises otherwise.

collect#

Explicit context

func collect(
    inputExpression: UniffiExpression,
    generator: UniffiExpression,
) -> UniffiExpression
Calling forms

Expression method: UniffiExpression.collect

func collect(generator: UniffiExpression) -> UniffiExpression

Regroup the additive terms of expression by the numeric (integer or rational) powers of a single generator, which may be a variable or an arbitrary subexpression, writing the result as a sum of generator^k * coefficient(k) terms without expanding the coefficients. For example, collecting a*x^2 + b*x^2 + a*x - b*x + c by x yields x^2*(a + b) + x*(a - b) + c. The rewrite is exact and equality-preserving; a numeric-literal generator, or a generator that appears with only a single power, returns the input unchanged.

complete_the_square#

Explicit context

func completeTheSquare(
    inputExpression: UniffiExpression,
    variable: UniffiExpression,
) -> UniffiExpression
Calling forms

Expression method: UniffiExpression.completeTheSquare

func completeTheSquare(variable: UniffiExpression) -> UniffiExpression

Rewrite an expression that is quadratic in variable into the exact vertex form a*(variable - h)^2 + k, with h = -b/(2*a) and k = c - b^2/(4*a) built from the degree-2, degree-1 and degree-0 coefficients a, b, c of the expression collected in variable. For example, 2*x^2 - 4*x + 7 becomes 2*(x - 1)^2 + 5. The coefficients may contain other symbols freely, so the multivariate case is the per-variable quadratic slice: x^2 + 2*x*y + 3 becomes (x + y)^2 - y^2 + 3 in x. The rewrite is exact and equality-preserving, and the square is never expanded.

The input is returned unchanged whenever the rewrite does not apply: when variable is not a symbol (a kernel generator such as sin(x) is not supported in this release); when the expression is not a quadratic polynomial slice in variable — its collected powers of variable must be exactly {2}, {2, 0}, {2, 1} or {2, 1, 0} and every coefficient must be free of variable, so x^3 + x, x^(1/2) + x, x + 1 and sin(x)*x^2 + x all decline; when b = 0 and the expression is therefore already in vertex form (3*x^2 + 5); and when the leading coefficient a is not provably nonzero. A numeric a always qualifies, while a symbolic a qualifies only when the assumption context proves it nonzero — dividing by a possibly-zero leading coefficient would make the emitted form invalid on the a = 0 locus, so a*x^2 + x declines for an unrestricted a and completes when a is assumed positive.

factor_common_terms#

Explicit context

func factorCommonTerms(inputExpression: UniffiExpression) -> UniffiExpression
Calling forms

Expression method: UniffiExpression.factorCommonTerms

func factorCommonTerms() -> UniffiExpression

Pull the greatest common monomial and exact rational content out of the terms of a general — not necessarily polynomial — sum, producing a single product of a common factor and a reduced sum, without invoking full polynomial factorization. For example, 6*x*y + 9*x^2*sin(z) becomes 3*x*(2*y + 3*x*sin(z)). The numeric content is negative exactly when every term is negative (-2*x - 4*y pulls -2, while 2*x - 4*y and x^3 - 3*x pull positive content), a kernel with numeric exponents is extracted at its minimum exponent only when that minimum is positive (x + 1/x is left for cancel/together), and a kernel with a symbolic exponent is extracted whole only when the exponent is structurally identical in every term (a*x^n + b*x^n becomes x^n*(a + b)). The rewrite is exact and equality-preserving; when no nontrivial common factor exists, or the input is not a sum, the input is returned unchanged. The reduced sum is never factored further — that is factor's job.

rationalize_denominator#

Explicit context

func rationalizeDenominator(inputExpression: UniffiExpression) -> UniffiExpression
Calling forms

Expression method: UniffiExpression.rationalizeDenominator

func rationalizeDenominator() -> UniffiExpression

Rationalize a radical denominator through exact multiquadratic conjugation or extended-Euclidean inversion in one rational n-th-root extension. For example, 1 / (sqrt(3) - sqrt(2)) becomes sqrt(3) + sqrt(2), and 1 / (1 + 2^(1/3)) becomes (1 - 2^(1/3) + 2^(2/3))/3. The operation is directed and returns its input unchanged when the denominator is outside its bounded supported radical class or the exact remultiplication check fails.

collect_radicals#

Explicit context

func collectRadicals(inputExpression: UniffiExpression) -> UniffiExpression
Calling forms

Expression method: UniffiExpression.collectRadicals

func collectRadicals() -> UniffiExpression

Collect like numeric radical kernels in a top-level sum. For example, a*sqrt(2) + b*sqrt(2) + 3 becomes (a + b)*sqrt(2) + 3. At most eight distinct kernels are considered; inputs beyond that bound return unchanged.

denest_radicals#

Explicit context

func denestRadicals(inputExpression: UniffiExpression) -> UniffiExpression
Calling forms

Expression method: UniffiExpression.denestRadicals

func denestRadicals() -> UniffiExpression

Denest the bounded depth-two real-radical subset bottom-up: rational quadratic surds, up to three inner quadratic surds, and cbrt(a + b*sqrt(c)) when its exact resolvent has a rational root. For example, sqrt(3 + 2*sqrt(2)) becomes 1 + sqrt(2) and cbrt(2 + sqrt(5)) becomes (1 + sqrt(5))/2. A form outside this decidable subset, such as sqrt(1 + sqrt(2)), is returned unchanged. Every candidate is verified by exact repowering and principal-real-sign selection.

Example#

Symi documentation · Swift