_Interval

it.grypho.scala.leonardo.core._Interval
See the_Interval companion object
final class _Interval extends _Value

A closed real interval [lo, hi] whose endpoints are rigorous bounds (F_0008).

The answer to the accuracy question the exact tier does not ask: what a computation's result can be, given that its inputs are only known to lie in ranges. Every operation returns an interval guaranteed to contain every value the operation can take on its operands — the containment property — by rounding each endpoint outward.

The first sibling of _Number that deliberately does NOT widen (Decision A). _Rational and _Based read as numbers through _Number's widening extractor (_Complex and _Truth are siblings that do not); an interval must not, because one read as a single Double would silently become one endpoint — the worst failure this library has. So every case _Number(x) site simply does not match an interval, and every pass without an interval rule leaves the expression symbolic by construction. Intervals are results of evaluation; they are not operands of symbolic algebra (F_0014 is that).

The endpoint type chooses the bounds (Decision B): two _Rational endpoints are an exact interval, combined exactly and bounded through spire at the working precision where an operation leaves the rationals; Double endpoints are combined in IEEE-754 and rounded outward. Mixing the two demotes, outward — float contagion, as everywhere.

Rounding, stated because it is where interval code goes wrong: + − × ÷ and the square root detect an exact Double result with error-free transformations and widen by one ulp only on an inexact side, so [1, 2] − [1, 2] is exactly [−1, 1]. A transcendental is widened by two ulps on both platforms, since ECMAScript does not specify the accuracy of Math.sin the way the JDK does — one figure everywhere, never a platform branch. A value known exactly (exp(0) = 1) is not widened.

Endpoints are finite: a half-infinite interval is declined, not handled. lo == hi collapses to the number itself. Built only through _Interval.of.

Value parameters

hi

the upper endpoint, of the same kind

lo

the lower endpoint, a _Rational or a _Number

Attributes

Companion
object
Graph
Supertypes
trait _Value
trait _Expression
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

override def children: List[_Expression]

Sub-expressions subject to recursive structural traversal. Binder positions (e.g. the differentiation variable) are excluded.

Sub-expressions subject to recursive structural traversal. Binder positions (e.g. the differentiation variable) are excluded.

Attributes

Definition Classes
def display(precision: Int): String

Renders [lo, hi] at precision decimals, rounded outward: the lower end down and the upper end up, so the displayed interval still contains the computed one. An exact endpoint that prints as a short fraction is shown as that fraction, unrounded.

Renders [lo, hi] at precision decimals, rounded outward: the lower end down and the upper end up, so the displayed interval still contains the computed one. An exact endpoint that prints as a short fraction is shown as that fraction, unrounded.

Value parameters

precision

decimal places

Attributes

override def equals(that: Any): Boolean

Compares the receiver object (this) with the argument object (that) for equivalence.

Compares the receiver object (this) with the argument object (that) for equivalence.

Any implementation of this method should be an equivalence relation:

  • It is reflexive: for any instance x of type Any, x.equals(x) should return true.
  • It is symmetric: for any instances x and y of type Any, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any instances x, y, and z of type Any if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.

If you override this method, you should verify that your implementation remains an equivalence relation. Additionally, when overriding this method it is usually necessary to override hashCode to ensure that objects which are "equal" (o1.equals(o2) returns true) hash to the same scala.Int. (o1.hashCode.equals(o2.hashCode)).

Value parameters

that

the object to compare against this object for equality.

Attributes

Returns

true if the receiver object is equivalent to the argument; false otherwise.

Definition Classes
Any
override def eval(env: Environment): Either[_Expression, _Value]

Reduces this expression in the given environment.

Reduces this expression in the given environment.

Value parameters

env

variable bindings and display precision

Attributes

Returns

Right(v) when all free variables resolved to concrete values; Left(e) when reduction is partial or impossible

Definition Classes
override def hashCode: Int

Calculates a hash code value for the object.

Calculates a hash code value for the object.

The default hashing algorithm is platform dependent.

Note that it is allowed for two objects to have identical hash codes (o1.hashCode.equals(o2.hashCode)) yet not be equal (o1.equals(o2) returns false). A degenerate implementation could always return 0. However, it is required that if two objects are equal (o1.equals(o2) returns true) that they have identical hash codes (o1.hashCode.equals(o2.hashCode)). Therefore, when overriding this method, be sure to verify that the behavior is consistent with the equals method.

Attributes

Returns

the hash code value for this object.

Definition Classes
Any
def hiDouble: Double

The upper endpoint as a Double, rounded up when it is an exact rational.

The upper endpoint as a Double, rounded up when it is an exact rational.

Attributes

def isExact: Boolean

True when both endpoints are exact rationals.

True when both endpoints are exact rationals.

Attributes

def loDouble: Double

The lower endpoint as a Double, rounded down when it is an exact rational.

The lower endpoint as a Double, rounded down when it is an exact rational.

Attributes

override def rebuild(c: List[_Expression]): _Expression

Reconstructs the same node shape with replacement sub-expressions.

Reconstructs the same node shape with replacement sub-expressions.

Value parameters

newChildren

replacements in the same order and count as children

Attributes

Definition Classes
override def toString: String

The display at Environment.DefaultPrecision, outward.

The display at Environment.DefaultPrecision, outward.

Not lossless, unlike most values' toString: parsing it back gives a wider interval, never a narrower one, so containment survives but the endpoints do not — the _Rational.toString precedent, whose decimal fallback is also a display form. :save writes the endpoints in full instead (the REPL's serializeValue); the simplify command and an _IntervalOf over interval children print this rounded form.

Attributes

Definition Classes
Any

Concrete fields

val hi: _Value
val lo: _Value

Inherited fields

lazy val freeVars: Set[String]

Cached set of free variable names; O(1) after the first access.

Cached set of free variable names; O(1) after the first access.

Attributes

Inherited from:
_Expression