Answers whether both Algebraics are the same number.
Normal forms decide the answer exactly. No approximation is consulted.
Algebraicthe Algebraic to compare withReturns true when the numbers are equal.
Exact irrational numbers such as square roots: arithmetic, comparison, rounding and printing.
Taught on: Numbers.
namespace Algebraic for Algebraicon Algebraic
Answers whether both Algebraics are the same number.
Normal forms decide the answer exactly. No approximation is consulted.
Algebraicthe Algebraic to compare withReturns true when the numbers are equal.
on Algebraic
Orders the Algebraic against another Algebraic.
The comparison is symbolic, so it is exact.
Algebraicthe Algebraic to order againstReturns Ordering#Less, Ordering#Equal or Ordering#Greater.
on Algebraic
Answers the Algebraic as a String, in the exact symbolic form or in the named format.
The form is √2, 3·√2 or 1 + √2 when no format is named, and #Fraction names that same form. The #Decimal format writes the expansion, to at most 80 digits, which is the cap a Rational writes a non-terminating expansion at. A count of places writes exactly that many digits after the point.
Answers the Algebraic as a String, in the exact symbolic form: √2, 3·√2 or 1 + √2.
One radical has one printed form, with one exception. Normalisation divides out square factors up to 65536, so a radicand p²·q with both primes above that is printed as written. The equal p·√q prints in the normalised form.
Answers the Algebraic as a decimal, or in the exact symbolic form, in the named format.
The #Decimal format rounds the expansion at the eightieth digit and writes it. An irrational expansion never ends, so the cap is always reached. Trailing zeros the rounding leaves are dropped, as they are for any Rational. The #Percent format writes one hundred times that same reading, taken two digits deeper so that eighty still stand after the point. The #Scientific format writes eighty digits after the point of the mantissa, and the power of ten after an e. The reading is taken at the eightieth digit of the mantissa, wherever the value falls. A value below one is read deeper than eighty places. The #Fraction format writes the symbolic form, since no ratio of two Integers is this number.
Returns the String representation of the Algebraic.
Answers the Algebraic as a decimal with exactly that many places.
The digits are padded with zeroes where the rounded value is shorter. The last digit kept is rounded in the named direction, and #Nearest is what a call that names none is given. A count below one rounds to a whole number, and no point is written. The #Percent format takes the count the same way, on one hundred times the value. The #Scientific format counts the digits of the mantissa after the point, at every magnitude. The value is read as many digits past the count as its own power of ten falls below zero. The #Fraction format ignores both the count and the direction, and writes the symbolic form.
Integerhow many digits to write after the pointReturns the String representation of the Algebraic.
on Algebraic · provided by Equatable
Answers whether the values differ.
Algebraicthe value to compare withReturns true when the values differ.
on Algebraic
Answers the exact sum of the Algebraic and a number.
Two Algebraics over the same radical stay in the slice. Their radical parts can also cancel, which leaves a Rational. Two roots of different numbers have no sum in this slice, and the answer is empty. The defaultingTo: entry answers the given value in place of empty.
Answers the exact sum of the Algebraic and an Integer.
An Integer shifts the rational part and leaves the radical in place, so the sum is again an Algebraic.
Integerthe Integer to addReturns the exact sum.
Answers the exact sum of the Algebraic and a Rational.
A Rational shifts the rational part and leaves the radical in place, so the sum is again an Algebraic.
Rationalthe Rational to addReturns the exact sum.
Answers the exact sum of the two Algebraics.
Over the same radical the sum stays in the slice, and can collapse to a Rational. Over different radicals the sum falls outside what an Algebraic holds, and the answer is empty.
Algebraicthe Algebraic to addReturns the sum, or nothing when the radicals differ.
Answers the exact sum of the two Algebraics.
Over different radicals there is no sum, and the answer is the given value.
Algebraicthe Algebraic to addRational | Algebraicthe value to answer with when there is no sumReturns the sum, or the given value in its place.
on Algebraic
Answers the exact difference of the Algebraic and a number.
Subtracting an equal radical part leaves a Rational. Two roots of different numbers have no difference in this slice, and the answer is empty. The defaultingTo: entry answers the given value in place of empty.
Answers the exact difference of the Algebraic and an Integer.
An Integer shifts the rational part and leaves the radical in place, so the difference is again an Algebraic.
Integerthe Integer to subtractReturns the exact difference.
Answers the exact difference of the Algebraic and a Rational.
A Rational shifts the rational part and leaves the radical in place, so the difference is again an Algebraic.
Rationalthe Rational to subtractReturns the exact difference.
Answers the exact difference of the two Algebraics.
Over the same radical the difference stays in the slice, and can collapse to a Rational. Over different radicals there is no difference, and the answer is empty.
Algebraicthe Algebraic to subtractReturns the difference, or nothing when the radicals differ.
Answers the exact difference of the two Algebraics.
Over different radicals there is no difference, and the answer is the given value.
Algebraicthe Algebraic to subtractRational | Algebraicthe value to answer with when there is no differenceReturns the difference, or the given value in its place.
on Algebraic
Answers the exact product of the Algebraic and a number.
A radical times itself turns rational: √2 · √2 is 2. Multiplying by zero answers zero. Multiplying by a NonZeroInteger or a NonZeroRational keeps the radical, so those entries answer an Algebraic. The defaultingTo: entry answers the given value in place of empty.
Answers the exact product of the Algebraic and an Integer.
An Integer scales both parts and leaves the radical in place. A zero factor collapses the product to the Rational zero.
Integerthe Integer to multiply withReturns the exact product, an Algebraic or a Rational.
Answers the exact product of the Algebraic and a Rational.
A Rational scales both parts and leaves the radical in place. A zero factor collapses the product to the Rational zero.
Rationalthe Rational to multiply withReturns the exact product, an Algebraic or a Rational.
Answers the exact product of the two Algebraics.
Over the same radical the product stays exact: √2 · √2 is 2. Two pure radicals combine across radicals: √2 · √3 is √6. Anything else is empty.
Algebraicthe Algebraic to multiply withReturns the product, or nothing when there is none.
Answers the exact product of the two Algebraics.
Where there is no product, the answer is the given value.
Algebraicthe Algebraic to multiply withRational | Algebraicthe value to answer with when there is no productReturns the product, or the given value in its place.
Answers the exact product of the Algebraic and a factor proven not to be zero.
A non-zero Integer scales both parts and leaves the radical in place. The answer is again an Algebraic rather than a Union.
Returns the exact product.
Answers the exact product of the Algebraic and a Rational factor proven not to be zero.
A Rational that is not zero scales both parts and leaves the radical in place. The answer is again an Algebraic rather than a Union.
Returns the exact product.
on Algebraic
Answers the exact quotient of the Algebraic and a number.
Dividing by an Integer or a Rational is empty only for zero. Dividing by a NonZeroInteger or a NonZeroRational can not fail, because those divisors are proven. Dividing by an Algebraic multiplies by its reciprocal, which the conjugate always gives. That quotient is empty wherever the matching product is empty. The defaultingTo: entries answer the given value in place of empty.
Answers the exact quotient of the Algebraic and an Integer.
A divisor that is not zero scales both parts and leaves the radical in place. A zero divisor answers empty.
Integerthe divisorReturns the exact quotient, or nothing when the divisor is zero.
Answers the exact quotient of the Algebraic and a Rational.
A divisor that is not zero scales both parts and leaves the radical in place. A zero divisor answers empty.
Rationalthe divisorReturns the exact quotient, or nothing when the divisor is zero.
Answers the exact quotient of the two Algebraics.
The divisor's conjugate gives its reciprocal, and the quotient is that product. It is empty wherever the matching product is empty.
Algebraicthe divisorReturns the quotient, or nothing when there is none.
Answers the exact quotient of the Algebraic and an Integer.
A zero divisor answers the given value.
Integerthe divisorAlgebraicthe value to answer with when there is no quotientReturns the quotient, or the given value in its place.
Answers the exact quotient of the Algebraic and a Rational.
A zero divisor answers the given value.
Rationalthe divisorAlgebraicthe value to answer with when there is no quotientReturns the quotient, or the given value in its place.
Answers the exact quotient of the two Algebraics.
Where there is no quotient, the answer is the given value.
Algebraicthe divisorRational | Algebraicthe value to answer with when there is no quotientReturns the quotient, or the given value in its place.
Answers the exact quotient of the Algebraic and a divisor proven not to be zero.
The division can not fail, so the answer is the quotient itself rather than an Optional.
Returns the exact quotient.
Answers the exact quotient of the Algebraic and a Rational divisor proven not to be zero.
The division can not fail, so the answer is the quotient itself rather than an Optional.
Returns the exact quotient.
on Algebraic
Answers the Algebraic raised to the given power, exactly.
The slice is closed under Integer powers, so every power is exact. A power can cancel the radical, so 2::squareRoot() squared is the Rational 2. A negative exponent answers the power of the reciprocal, which always exists, since an Algebraic is never zero. A zero exponent answers 1.
Integerthe exponentReturns the exact power, an Algebraic or a Rational.
on Algebraic · provided by Comparable
Answers whether the value is strictly below another.
Algebraicthe value to compare withReturns true when the value is below the given one.
on Algebraic · provided by Comparable
Answers whether the value is below another, or equal to it.
Algebraicthe value to compare withReturns true when the value is below the given one or equal to it.
on Algebraic · provided by Comparable
Answers whether the value is strictly above another.
Algebraicthe value to compare withReturns true when the value is above the given one.
on Algebraic · provided by Comparable
Answers whether the value is above another, or equal to it.
Algebraicthe value to compare withReturns true when the value is above the given one or equal to it.
on Algebraic · provided by Orderable
Answers whether the value lies between the two given ones, both included.
The two bounds name the same range in either order: 7::isBetween(10, and 1) is true, and 15::isBetween(10, and 1) is false.
Algebraicone bound of the range, includedAlgebraicthe other bound of the range, includedReturns true when the value is within the bounds.
on Algebraic · provided by Orderable
Answers the value, pulled into the given bounds.
The answer is the lower bound when the value is below it. It is the upper bound when the value is above it, and the value itself otherwise. The two bounds name the same range in either order: 7::clamp(between 10, and 1) is 7, and 15::clamp(between 10, and 1) is 10.
Algebraicone bound of the rangeAlgebraicthe other bound of the rangeReturns the clamped value.
on Algebraic
Answers whether the Algebraic is above zero.
The sign of a + b·√d is exactly decidable. No approximation is consulted.
on Algebraic
Answers whether the Algebraic is below zero.
The sign of a + b·√d is exactly decidable. No approximation is consulted.
on Algebraic
Answers whether the Algebraic is exactly zero.
An Algebraic carries a radical with a coefficient that is not zero, so the answer is always false.
on Algebraic
Answers whether the Algebraic is a whole number.
An Algebraic is irrational, so it is never whole and the answer is always false.
on Algebraic
Answers the Algebraic without its sign, which is its distance from zero.
The sign of a + b·√d is exactly decidable. No approximation is consulted.
on Algebraic
Answers the Algebraic with its sign flipped.
Negating an irrational leaves it irrational, so the answer is again an Algebraic.
on Algebraic
Answers the Algebraic as a Rational on a decimal grid of the given width.
Five places answer the value rounded to hundred-thousandths, so 2::squareRoot() over five places answers 141421/100000. This Method is where a Program asks for digits in place of the exact value. The answer is exact all the same: it is the step of that grid the value rounds to. A width of no places answers a whole number, as a Rational.
Returns the value on the grid the width names.
on Algebraic
Answers the Algebraic rounded in the named direction.
The direction is #Nearest when a call names none. An irrational is never exactly halfway between two steps, so #Nearest and #NearestEven answer alike here. The other directions answer the floor for #Down, the ceiling for #Up, and the step towards zero for #TowardZero. Naming a count of places rounds to a decimal grid of that width instead, and answers a Rational.
Answers the Algebraic as an Integer, rounded in the named direction.
Returns the rounded Integer.
Answers the Algebraic rounded to a decimal grid of the given width.
Two places round to hundredths. The answer is what approximate(toPlaces:toward:) answers, and a count below one rounds to a whole number. The entry stands here so that a Number receiver reaches round at every width, whichever kind it holds.
Integerhow many decimal places to keepReturns the rounded Rational.
on Algebraic
Answers the power of ten at or below the Algebraic's distance from zero.
This is the exponent the #Scientific format writes after the e. A value between one and ten answers zero, and a value between a tenth and one answers minus one. The enclosure widens until it falls inside one such power of ten. That always happens: an Algebraic is irrational, so it is never a power of ten itself.
Returns the exponent of the power of ten the value falls on.