Radical

public final class Radical: Codable

A radical expression. Radical expressions are simplified by calling the objects simplify() method.

Usage

Create a new expression using integers with

The cube root of 27:

let expression = Radical(root: 27, index: 3)

Example

The square root of 27:

let expression = Radical(root: 27)
print("Your expression is \(expression.radicand) square roots of \(expression.coefficient)")
// => Your expression is 1 square roots of 27 (root 27)
expression.simplify()
print("Your expression is \(expression.radicand) square roots of \(expression.coefficient)")
// => Your expression is 3 square roots of 3 (root 27)

Imaginary Numbers

simplify() will do nothing if simplification results in an imaginary number.

  • The index of the radical expression Square root, cube root, etc.

    Declaration

    Swift

    public var index: Int
  • The number inside the root sign

    Declaration

    Swift

    public var radicand: Int
  • The number outside the root sign

    Declaration

    Swift

    public var coefficient: Int = 1
  • Create a new radical expression using only integers.

    Declaration

    Swift

    public init(root: Int, index: Int = 2)

    Parameters

    root

    The number inside the root sign

    index

    The index of the radical, defaults to square root

  • Simplify the radical

    Declaration

    Swift

    public func simplify()