PiMath API
    Preparing search index...

    Class Root

    A real root factor · ⁿ√radical, where the factor and the radical are Fractions and the index n is a strictly positive integer (2 by default). Built from a string ("3sqrt(5)", "root(3)(10)"), a number or a fraction. Root is strict: a malformed input throws a ParseError.

    new Root("sqrt(12)").reduce().display // "2sqrt(3)"
    

    Implements

    Index
    • get index(): number

      Index of the root: 2 for a square root, 3 for a cube root...

      Returns number

    • set index(value: number): void

      Parameters

      • value: number

      Returns void

      if value is not a strictly positive integer.

    • get value(): number

      Numeric value of the root. Returns NaN for an even root of a negative radical (not real); an odd root of a negative is real and negative.

      Returns number

    • get withoutSign(): this

      Display option (chainable, returns this): remove the forced leading '+'.

      Returns this

    • get withSign(): this

      Display option (chainable, returns this): force a leading '+' on a positive factor.

      Returns this

    • Copy the mathematical state of another instance into this (display state is NOT transferred — the receiver keeps its own formatting). Entry point used when constructing/parsing from a same-type input. Distinct from clone. Classes without a real implementation throw NotImplementedError.

      Parameters

      Returns this

    • True when both roots have the same real value, compared exactly (no floating point): sqrt(8) equals 2sqrt(2). An even root of a negative radical is not real and equals nothing.

      Parameters

      Returns boolean

    • True when the value is a rational number once reduced (sqrt(9), root(3)(-8)), false for sqrt(2).

      Returns boolean

    • Router: inspect the input type and delegate to the matching builder. A same-type (Root) input goes through copy(); every other form has its own from*** / #fromScalar. Construction logic is never inlined here.

      Parameters

      Returns this

      if a string/number input is malformed.

    • Raise the root to a power. Computed on a clone and committed only on success, so a rejected pow leaves the receiver intact (atomicity).

      Parameters

      • value: number

      Returns this

      (via Fraction.pow) for a fractional power of a negative factor or radical.

    • Put the root in simplified form: no root in the denominator, and the greatest perfect power extracted from the radical (sqrt(12) becomes 2sqrt(3)). For an odd index, the sign always ends up on the factor and the radical becomes positive (root(3)(-40) becomes -2root(3)(5)). For an even index, a negative radical is left unchanged.

      Returns this

      new Root("sqrt(12)").reduce().tex // "2 \sqrt{ 3 }"
      
    • Take the value-th root of this root (e.g. sqrt of sqrt). Computed on a clone and committed only on success (atomicity).

      Parameters

      • value: number

      Returns this

      if value is not a strictly positive integer.

    • Build a new Root by delegating a string to the sqrt / root parser, or to the scalar builder for a plain fraction string.

      Parameters

      • value: string

      Returns Root

      if the string is a malformed radical or fraction.