_Surd

it.grypho.scala.leonardo.core._Surd
See the_Surd companion class
object _Surd

Companion for _Surd: the factory, the exact field arithmetic, and the readers.

Every operation answers Option: None means the result is not a quadratic surd over the same radical (√2 + √3, a fractional power of a surd), and the caller leaves the exact set the way it always has, through spire's Real to a working-precision rational (_Surd.approximateOp). A surd is therefore never less exact than the rational that stood in its place before F_0231.

Attributes

Companion
class
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
_Surd.type

Members list

Value members

Concrete methods

def add(x: _Value, y: _Value): Option[_Value]

x + y, exactly, when both share a radical.

x + y, exactly, when both share a radical.

Attributes

def approximateOp(x: _Value, y: _Value, digits: Int)(op: (Real, Real) => Real): Option[_Rational]

op on two exact values outside the surd field, the way the exact tier always left it: through Real, back to a rational at digits.

op on two exact values outside the surd field, the way the exact tier always left it: through Real, back to a rational at digits.

Attributes

Returns

the approximation, or None when either value is not exact

def combine(x: _Value, y: _Value, digits: Int)(exact: (_Value, _Value) => Option[_Value], real: (Real, Real) => Real): Option[_Value]

A binary operation on two exact values: the exact field operation when it applies, else approximateOp -- so an operand pair outside one radical is answered exactly as before.

A binary operation on two exact values: the exact field operation when it applies, else approximateOp -- so an operand pair outside one radical is answered exactly as before.

Value parameters

digits

the working precision of the approximation

exact

the field operation, None outside one radical

real

the same operation on Reals

x

the left operand

y

the right operand

Attributes

Returns

the result, or None when it is undefined (a division by zero)

def compareExact(x: _Value, y: _Value): Option[Int]

The order of two exact values, decided exactly: by the sign of the difference over one radical, else by reading the difference at growing precision, which ends because two exact values that are not combinable are not equal.

The order of two exact values, decided exactly: by the sign of the difference over one radical, else by reading the difference at growing precision, which ends because two exact values that are not combinable are not equal.

Attributes

Returns

-1, 0 or 1, or None when either is not exact

def divide(x: _Value, y: _Value): Option[_Value]

x / y, by the conjugate: x·(a₂ − b₂√d) / (a₂² − b₂²d). The denominator vanishes only for y = 0, since d is not a perfect square.

x / y, by the conjugate: x·(a₂ − b₂√d) / (a₂² − b₂²d). The denominator vanishes only for y = 0, since d is not a perfect square.

Attributes

Returns

the quotient, or None for a zero divisor or radicals that do not combine

def exactOf(v: _Expression, digits: Int): Option[_Rational]

An exact value as a rational at digits places: a rational as itself, a surd as the working-precision approximation it stood for before F_0231. What every computation that needs a rational reads a surd through, so none demotes it to Double.

An exact value as a rational at digits places: a rational as itself, a surd as the working-precision approximation it stood for before F_0231. What every computation that needs a rational reads a surd through, so none demotes it to Double.

Value parameters

digits

the working precision

v

the value

Attributes

Returns

the rational, or None for a value that is not exact

def involves(x: _Value, y: _Value): Boolean

Whether x and y are both exact and at least one is a surd: the gate on the operator arms, which keep their faster rational-rational arm first.

Whether x and y are both exact and at least one is a surd: the gate on the operator arms, which keep their faster rational-rational arm first.

Attributes

def isExact(v: _Expression): Boolean

Whether v is exact in the sense of this type: a rational or a surd.

Whether v is exact in the sense of this type: a rational or a surd.

Attributes

def multiply(x: _Value, y: _Value): Option[_Value]

x · y = (a₁a₂ + b₁b₂d) + (a₁b₂ + a₂b₁)√d, exactly, when both share a radical.

x · y = (a₁a₂ + b₁b₂d) + (a₁b₂ + a₂b₁)√d, exactly, when both share a radical.

Attributes

def negate(x: _Value): Option[_Value]

-x.

-x.

Attributes

def of(a: _Rational, b: _Rational, d: BigInt): Option[_Value]

a + b·√d as the simplest exact value it equals: the rational a when b = 0 or d = 0, the rational a + b·r when d = r², else a surd with the small square factors of d moved into b.

a + b·√d as the simplest exact value it equals: the rational a when b = 0 or d = 0, the rational a + b·r when d = r², else a surd with the small square factors of d moved into b.

Value parameters

a

the rational part

b

the coefficient of the radical

d

the radicand

Attributes

Returns

the value, or None for a negative radicand (the complex case, not this type's)

def pow(x: _Value, k: Int, maxBits: Long): Option[_Value]

x^k for an integer k, held to maxBits before any product is formed (the _Rational.pow rule): the estimate is the largest part's bit length times |k|.

x^k for an integer k, held to maxBits before any product is formed (the _Rational.pow rule): the estimate is the largest part's bit length times |k|.

Attributes

Returns

the power, or None past the budget or for a negative power of zero

def signum(x: _Value): Option[Int]

The sign of an exact value, decided exactly: when a and b disagree, by comparing a² with b²d, which cannot tie since d is not a perfect square.

The sign of an exact value, decided exactly: when a and b disagree, by comparing a² with b²d, which cannot tie since d is not a perfect square.

Attributes

Returns

-1, 0 or 1, or None for a value of another kind

def sqrtOf(r: _Rational): Option[_Value]

The exact square root of a non-negative rational: √(p/q) = √(p·q)/q.

The exact square root of a non-negative rational: √(p/q) = √(p·q)/q.

Value parameters

r

the radicand

Attributes

Returns

a rational for a perfect square, a surd otherwise, None when r < 0

def subtract(x: _Value, y: _Value): Option[_Value]

x − y, exactly, when both share a radical.

x − y, exactly, when both share a radical.

Attributes

def toReal(x: _Value): Option[Real]

The value as spire's Real, losing nothing.

The value as spire's Real, losing nothing.

Attributes