PiMath API
    Preparing search index...

    Class Solution

    An equation / polynomial root as an exact decomposed value: a rational part (#fraction) plus a radical part (#root).

    Invariant (maintained by the producers, not enforced by the type): #fraction carries every rational part, and #root is either zero or a genuinely irrational radical — never a perfect-power radical that would reduce to a rational. EquationSolver / fromQuadratic only build a radical on the non-square-discriminant branch, so a non-zero #root always accompanies a truly irrational value.

    The tex / display composition relies on this: it runs the two-part (numerator ± radical)/denominator layout only when both parts are non-zero, i.e. on a real irrational. It does not re-simplify a manually built perfect-power radical (e.g. #fraction = 1, #root = √4), which would render as the unsimplified 1 +2 — an incoherent state the producers never create.

    Implements

    Index
    • get count(): number

      Multiplicity of the root (always >= 1; defaults to 1). A double root reports 2, etc.

      Returns number

    • get display(): string

      ASCII rendering. Mirrors tex (override precedence, then #compose). Returns null only when explicitly overridden to null via set display.

      Returns string

    • set display(value: string | null): void

      ASCIIMath rendering of the current state (terminal output, not chainable).

      Parameters

      • value: string | null

      Returns void

    • get exact(): boolean

      Whether the value is faithfully exact: true for an exact rational or a quadratic irrational carried by an index-2 Root, false for a floating (Cardan / bisection) approximation. Never mark a float value exact.

      Returns boolean

    • get tex(): string

      LaTeX rendering. An explicit override (set tex) takes precedence; otherwise the value is composed from its parts: the fraction or the radical alone in the simple cases, else (numerator ± radical)/denominator. With withDigits, the decimal value.

      Returns string

    • set tex(value: string | null): void

      LaTeX rendering of the current state (terminal output, not chainable).

      Parameters

      • value: string | null

      Returns void

    • get variable(): string

      Variable the solution belongs to (x by default). The setter accepts a single lowercase letter.

      Returns string

      when setting anything else.

    • set variable(value: string | undefined): void

      Parameters

      • value: string | undefined

      Returns void

    • Copy the math state of another Solution into this (parts are cloned). Display overrides are not transferred, and any stale #display/#tex on this is dropped so the getters recompute from the new state.

      Parameters

      Returns this

    • True when both the rational part and the radical part are zero.

      Returns boolean

    • Reduce the radical and rational parts to their canonical form, in place, and return this. Deliberate exception to the clone-and-commit atomicity convention: Root.reduce / Fraction.reduce are total (never throw), so the receiver cannot be left half-mutated.

      Returns this

    • Flag the solution as exact (default) or approximate.

      Parameters

      • value: boolean = true

      Returns this

    • Show the numeric value as a decimal with digits digits, whatever the exact form (a radical included: (1+sqrt(2))/2 becomes 1.21). null goes back to the exact form. Takes precedence over a tex / display override.

      Parameters

      • digits: number | null

      Returns this

      if digits is neither null nor an integer from 0 to 100.

    • Parse a string representation of a solution. Three strict forms:

      • Pure rational : 2/5, -3, 1.23
      • Pure radical : sqrt(5), -2sqrt(3), sqrt(5)/3, 2sqrt(3)/5
      • Combined : (-1+sqrt(5))/2, (3-2sqrt(7))/4

      Parameters

      • value: string

      Returns Solution

      if the string matches none of the supported forms.