it.grypho.scala.leonardo.core
Members list
Type members
Classlikes
The named mathematical constants (F_0289).
The named mathematical constants (F_0289).
pi and e were folded to numbers by the parser until F_0289; eulergamma and goldenratio are new. gamma and phi stay free variable names (phi is the spherical coordinate, and a released name cannot be reclaimed without breaking saved scripts), so the two new constants are spelled out, with the Greek glyphs accepted as aliases — the ASCII name is what is printed and saved.
Value parameters
- glyph
-
a Greek alias the grammar also reads, if any
- keyword
-
the word the grammar reads and
toStringwrites - value
-
the constant as a
Double
Attributes
- Supertypes
-
trait Enumtrait Serializabletrait Producttrait Equalstrait Keywordedclass Objecttrait Matchableclass AnyShow all
Immutable variable-binding context shared across all domains.
Immutable variable-binding context shared across all domains.
Bindings map names to fully-reduced _Values (a number, a matrix, a boolean) — never to a symbolic expression. Kept in core because eval takes one, and core must not depend on any domain.
withBinding returns a new Environment; the original is unchanged (structural sharing).
Value parameters
- exactMode
-
the session's exact mode (F_0273, the owner's decision): when set, every constant a pass invents is built exact, whatever its input contains (
_Rational.containsExactIn). Whether a value is exact is still carried by its own type; this reaches the passes that work on letters alone —derive(atan(x), x)has no exact value to read a tier from, so until then it built1.0/(1.0 + x^2.0)underexact on. Defaults tofalse, under which every path is byte-identical. - limits
-
the work and size budgets every call evaluated here runs under (Limits, F_0124); each defaults to the value the library has always used. A library caller raises one with withLimit; the REPL and the browser keep the defaults.
- precision
-
decimal places used when rendering numbers
- semantics
-
the t-norm / t-conorm pair the logic connectives evaluate with; defaults to LogicSemantics.MinMax. Like
symmetricLogicthis is a knob oneval, not a separate node hierarchy. - symmetricLogic
-
when
true, the digits{-1, 0, 1}are read as the symmetric ternary spelling of{false, unknown, true}in logical connective positions, and truth values render in that alphabet. This is an encoding toggle, not a semantics: the min–max rule table is untouched and the two alphabets are related by the affine mapt = (s + 1) / 2(seecore._Truth.fromSymmetric). Defaults tofalse, thefalse/unknown/truespelling. - workingPrecision
-
decimal digits an irrational is approximated to before exact arithmetic continues. Read by
evalwherever a _Rational meets an operation that is not closed over the rationals. Not the exact-mode switch: that is exactMode.
Attributes
- Companion
- object
- Supertypes
-
class Objecttrait Matchableclass Any
Companion holding the global precision constant.
Companion holding the global precision constant.
Attributes
- Companion
- class
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
Environment.type
When a _Rational reduces itself to lowest terms.
When a _Rational reduces itself to lowest terms.
The policy changes representation only, never value: 2/6 and 1/3 are the same rational, and _Rational.equals compares by cross-multiplication precisely so that the choice stays invisible to callers. What it does change is cost — gcd is the expensive step of rational arithmetic, while skipping it roughly doubles operand size per operation — which is why it is a measured decision rather than a guess.
Selected per call site rather than through Environment, following the simplifyLogic(e, symmetric, semantics) precedent: nothing in this tier goes through eval yet, so an environment field would be unread. It moves into Environment with the tier-1 AST integration, alongside the working precision.
Attributes
- Supertypes
-
trait Enumtrait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
A kind whose cases are spelled by a word at the prompt — a distribution family, a test, a method slot word (F_0148).
A kind whose cases are spelled by a word at the prompt — a distribution family, a test, a method slot word (F_0148).
Seventeen kind enums spelled that word three ways — a val word on the case, a companion keyword(k), a fnName — and only three offered the reverse lookup. Each now mixes this in with a concrete keyword, so one question ("what does the user type for this?") has one spelling, and Keyworded.byKeyword answers the reverse for all of them. A trait, not an abstract member on a shared base: the enums are sealed, and mixing a trait in adds an interface rather than an obligation (the MiMa rule NamedFunction follows).
Attributes
- Companion
- object
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
enum DiscretisationMethodenum RiccatiKindenum StructureKindenum ConstantKindenum DefuzzMethodenum MinimalKindenum NormalKindenum Subspaceenum OdeMethodenum MinimizeMethodenum NlpMethodenum DistKindenum Queryenum ReduceKindenum SeqKindenum Alternativeenum PairStatKindenum StatKindenum TestKindShow all
One configurable work or size budget (F_0124): a cap on how much one call may compute before it declines rather than answer.
One configurable work or size budget (F_0124): a cap on how much one call may compute before it declines rather than answer.
A budget, never a tolerance. Each bounds time or memory: a basis's size, an iteration count, a problem's dimension. None decides what counts as numerically zero, so raising one can only let a slow case finish, never make an answer less certain: every answer it guards is still certified by its own method. The tolerances stay fixed and relative; the one a caller legitimately sets, the certificate's, comes from Environment.precision.
The default is the value the library has always used, measured for the browser REPL where a frozen tab cannot be interrupted (the inventory is in DesignNotes.md, F_0124). A library caller with time to spare raises it through Environment.withLimit. Each case is named after the published constant it backs (optimize.MaxQpVariables is Limit.MaxQpVariables.default), so the two cannot disagree.
Value parameters
- default
-
the value used unless an Environment overrides it
Attributes
- Supertypes
-
trait Enumtrait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
The budgets an evaluation runs under (F_0124): each Limit's default, unless overridden.
The budgets an evaluation runs under (F_0124): each Limit's default, unless overridden.
Carried by Environment, so every node reaches it through eval and every library function through its env. Not a case class, on purpose: a record with a field per budget could not gain one without a binary break, while a new Limit case is additive.
Attributes
- Companion
- object
- Supertypes
-
class Objecttrait Matchableclass Any
The truth-functional semantics selecting the t-norm / t-conorm pair used by the logic connectives.
The truth-functional semantics selecting the t-norm / t-conorm pair used by the logic connectives.
All three agree with classical logic on the crisp values {0, 1} and differ only on graded degrees, and all three share the strong negation 1 - a. Every one has 0 as the annihilator of its t-norm and 1 as the annihilator of its t-conorm, which is why the connective short-circuits are sound under each.
A parameterization of eval, never separate packages and never separate nodes.
Attributes
- Supertypes
-
trait Enumtrait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
An integer that remembers the base it is written in.
An integer that remembers the base it is written in.
The fourth sibling of _Number, after _Complex, _Truth and _Rational, and built to the same pattern: a private constructor behind a smart factory, and a value that is read as a number through _Number's widening extractor so no existing case _Number(x) site has to learn about it.
Why the base lives on the value. A base conversion that returns bare digits is only a decomposition: [[15, 15]] is indistinguishable from a matrix typed by hand, and the caller has to remember the base to reassemble it. Putting the base on the value is what makes A := 0xFF still be FF when it is printed an hour later.
The tag is shallow, deliberately. 0xFF + 1 prints 256 in decimal, because Sum.eval reads both operands as numbers and builds a plain _Number. Carrying the base through arithmetic would require deciding whose base wins in 0xFF + 0b1011, and there is no defensible answer — so the base survives display and storage, which is what a base is for, and arithmetic falls back to decimal.
In exact mode the value is exact too (F_0323, LT L_0080): a literal parsed or a tobase taken under exact on carries its integer, _Rational.containsExact reports it, and the operators read it through _Based.unwrapExact -- so 0b1010 + 0b0110 is the exact 16, not 16.0 with a note, and :save groups the value under exact on. Outside exact mode nothing changes. A fourth field on a case class with a private constructor is additive: in Scala 3 unapply returns the instance and copy is private with the constructor.
Value parameters
- balanced
-
whether the digits are the balanced set (base 3 only)
- base
-
the radix,
2 .. 36 - exact
-
the integer when the value is exact (F_0323), else
None - value
-
the integer value, held as a
Doublelike every other numeric tier
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait _Valuetrait _Expressionclass Objecttrait Matchableclass AnyShow all
Concrete boolean value — the result of a fully-reduced relation.
Concrete boolean value — the result of a fully-reduced relation.
Value parameters
- b
-
the truth value
Attributes
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait _Valuetrait _Expressionclass Objecttrait Matchableclass AnyShow all
Concrete complex value re + im·i where im ≠ 0.
Concrete complex value re + im·i where im ≠ 0.
The imaginary part is never exactly 0 — the _Complex.of factory guarantees this invariant by collapsing to _Number in that case. Construction through of is the only public route; pattern matching _Complex(re, im) remains available.
Like _Number, a _Complex never rounds in eval; rounding is a display concern handled by toString / display(p). A rounded-away imaginary part causes the value to print as a plain real (e.g. exp(i·π) → "-1.0"); a pure imaginary value prints as "bi" / "i" / "-i"; the full form is "(a + bi)".
Value parameters
- im
-
imaginary part; guaranteed non-zero by the _Complex.of factory
- re
-
real part
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait _Valuetrait _Expressionclass Objecttrait Matchableclass AnyShow all
Companion for the concrete complex value _Complex; holds the smart factory and all arithmetic on _Value operands.
Companion for the concrete complex value _Complex; holds the smart factory and all arithmetic on _Value operands.
Arithmetic returns Option[_Value] — None signals a non-finite or undefined result (e.g. log 0, 0 ^ negative) so the caller stays symbolic, mirroring the "domain errors stay symbolic" contract of the real path.
_Complex.of collapses a zero imaginary part back to a plain _Number, so every existing _Number(x) pattern match across the codebase keeps firing on real results — only a genuinely non-real value ever becomes a _Complex. Binary operations promote _Number operands to (x, 0) via _Complex.parts.
Attributes
A named constant kept as a symbol (F_0289), so a formula, a definition and :save say pi rather than 3.14159.
A named constant kept as a symbol (F_0289), so a formula, a definition and :save say pi rather than 3.14159.
Outside exact mode it evaluates to its Double, so every value computed outside exact mode is what it was when the parser folded the constant. In exact mode it stays symbolic — pi/2 is pi/2, and the functions answer exactly where a rule knows the value (sin(pi/6) is 1/2) — except goldenratio, which is algebraic and so evaluates to the exact surd 1/2 + √5/2. Where a number is needed and no rule applies, evalNumeric reads every constant at the working precision, as the parser's rational reading did.
An _Expression, not a _Value: nothing widens it to a Double by accident, and an exact computation can keep it. It has no free variables, so it is a constant to every pass.
Value parameters
- exact
-
whether it was read in exact mode, which makes it symbolic even where the environment does not say exact mode (a library caller's exact parse)
- kind
-
which constant
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait _Expressionclass Objecttrait Matchableclass AnyShow all
Marker trait for expression nodes whose children may receive per-element algorithm passes (derive, simplify, expand, integrate).
Marker trait for expression nodes whose children may receive per-element algorithm passes (derive, simplify, expand, integrate).
An algorithm may distribute over children and rebuild the same shape only when this trait is present and the distribution is mathematically valid for all such algorithms. Linear containers qualify; product-like nodes that require product rules must not be marked. Lives in core so domain packages can opt in without creating a cross-domain import.
Attributes
- Supertypes
- Known subtypes
Base trait of every expression tree node, shared across all domains.
Base trait of every expression tree node, shared across all domains.
The dual-evaluation contract: eval returns Right when the expression fully reduces to a concrete _Value; Left when some variable is still free and the node is returned in its most-reduced symbolic form.
children / rebuild enable generic structural traversal so algorithms that visit every node type (Substitute, Analysis, …) do not need to match each case explicitly. Binder positions (e.g. the differentiation variable) are excluded from children; rebuild carries them through unchanged.
freeVars is cached per instance — computed once from children, then O(1). New node types inherit a correct default automatically.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
class _Ackerclass _Arxclass _Arx2Ssclass _Arx2Tfclass _ArxRegressorsclass _C2dclass _Dlsimclass _Feedbackclass _ImpulseResponseclass _IsStableclass _Linearizeclass _MpcMatricesclass _Parallelclass _Riccaticlass _Routhclass _Seriesclass _StepResponseclass _Structureclass _TfPolesclass _TfZerosclass _Constanttrait _ElementWiseclass _EqualityCheckclass _Equationclass MatSumclass Transposeclass _Matrixclass _Heavisidetrait _MatrixProductShapedclass MatProducttrait _MatrixShapedtrait _MatrixSumShapedtrait _Valueclass _Basedclass _Boolclass _Complexclass _Intervalclass _MatrixValueclass _Numberclass _Rationalclass _Surdclass _Truthclass _Distributionclass _Variableclass _Differentiableclass _Domainclass _Singularitiesclass _Comparisonclass _Solveclass _SolveSystemtrait _Connectiveclass Andclass Iffclass Impliesclass Notclass Orclass Xorclass _Defuzzifyclass _DefuzzifyByclass _Equivalenttrait _Membershipclass GaussMFclass SigMFclass Somewhatclass TrapMFclass TriMFclass Veryclass _TruthOfclass _MinimalFormclass _NormalFormclass Determinantclass _Condclass _Dotclass _EigDecompositionclass _EigenDecompositionclass _JordanDecompositionclass _LUDecompositionclass _MatrixIndextrait _MatrixOperationclass IdentityMatrixclass Inverseclass MatScaleclass ZeroMatrixclass _BlkDiagclass _Choleskyclass _Crossclass _HCatclass _Kronclass _MatrixExponentialclass _Onesclass _PInvclass _RepMatclass _Sizeclass _SubMatrixclass _VCatclass _Normclass _NullSpaceclass _QRDecompositionclass _Rankclass _Rationalizeclass _SizeAlongclass _Svdclass _Traceclass _ODESystemclass _OdeSolveclass _OdeStepclass _Convexclass _CurveFitclass _KKTclass _LPclass _Lagrangeclass _LsqFitclass _Minimizeclass _NSolveclass _Nlpclass _QPclass _Stationaryclass _Bayesclass _DistributionOfclass _DistributionQueryclass _Drawclass _Expectationclass _Posteriorclass _Prbsclass _Variancetrait NamedFunctionclass Absclass Acosclass Acoshclass Asinclass Asinhclass Atanclass Atanhclass Betaclass BetaIclass Binomclass Catalanclass Ceilclass Ciclass Cosclass Coshclass Cotclass Cothclass Cscclass Cschclass Digammaclass Eiclass Erfclass Erfcclass Expclass Factorialclass Floorclass FresnelCclass FresnelSclass Gammaclass GammaPclass GammaQclass Harmonicclass Liclass Lnclass LogBaseclass LogGammaclass Modclass MultiFactorialclass Roundclass Secclass Sechclass Siclass Sinclass Sinhclass Tanhclass Tgclass _Clampclass _Extremeclass _Joinclass _Softplusclass _Balancedclass _Functionclass _Functionalclass _ODEclass _DefIntegralclass _Derivativeclass _FourierSeriesclass _Integralclass _Laurentclass _Limitclass _Padeclass _Reductionclass _Tabulateclass _Taylorclass _Fourierclass _FourierCausalclass _InverseLaplaceclass _InverseZTransformclass _Laplaceclass _ZTransformclass _IntervalOftrait _Operationclass Powerclass Productclass Ratioclass Sumclass _Patternclass _Sequenceclass _ToBaseclass _Anovaclass _BinCountsclass _ChiSqTableclass _PairStatisticclass _PropTestclass _Quantileclass _Regressclass _RidgeRegressclass _Rlsclass _Sortclass _Statisticclass _TTestclass _Testclass _VarTestclass _WeightedRegressclass _Convclass _Dfttrait _VectorOperatorclass _Curlclass _Divclass _Gradclass _Hessianclass _Jacobianclass _LaplacianShow all
Heaviside unit step function: step(t) = 1 when t ≥ 0, 0 otherwise.
Heaviside unit step function: step(t) = 1 when t ≥ 0, 0 otherwise.
Evaluates to a concrete _Number when its argument reduces to a _Number; otherwise stays symbolic so transform rules can pattern-match on it. Not _ElementWise: derive / simplify / expand / integrate do not automatically distribute through step.
Value parameters
- arg
-
the argument expression
Attributes
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait _Expressionclass Objecttrait Matchableclass AnyShow all
A closed real interval [lo, hi] whose endpoints are rigorous bounds (F_0008).
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
_Rationalor a_Number
Attributes
- Companion
- object
- Supertypes
Shape trait for a matrix product node left · right, exposing its two operands in order.
Shape trait for a matrix product node left · right, exposing its two operands in order.
Lets a package below matrix recognise a matrix product structurally without importing matrix — the _MatrixShaped precedent. ode reads a linear system A·y through it (F_0006): a literal coefficient builds matrix.MatProduct, and ode imports only core and scalar. Recognising the node by class name instead would keep compiling after a rename and silently stop matching. The operand order is the product's and is load-bearing, since a matrix product does not commute.
Attributes
- Supertypes
- Known subtypes
-
class MatProduct
Marker trait for a symbolic matrix node whose children are its cells in row-major order and whose rebuild preserves the rows × cols shape.
Marker trait for a symbolic matrix node whose children are its cells in row-major order and whose rebuild preserves the rows × cols shape.
Lets core and scalar algorithms distribute a scalar function element-wise over a symbolic matrix argument (exp(A), sin(A), … over a matrix with free-variable cells) without importing the matrix package — they see only this marker and the generic children / rebuild. Narrower than _ElementWise on purpose: only the matrix literal opts in. The dense counterpart (_MatrixValue) is handled numerically and is not marked.
Attributes
- Supertypes
- Known subtypes
-
class _Matrix
Shape trait for a matrix sum node left + right, exposing its two operands.
Shape trait for a matrix sum node left + right, exposing its two operands.
The counterpart of _MatrixProductShaped, for the same reason: ode recognises the affine system A·y + b written with a literal matrix, which builds matrix.MatSum.
Attributes
- Supertypes
- Known subtypes
-
class MatSum
Companion for the dense concrete matrix value _MatrixValue.
Companion for the dense concrete matrix value _MatrixValue.
Attributes
- Companion
- class
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
_MatrixValue.type
Dense, fully-reduced matrix value: a row-major Array[Double], not n² _Number nodes.
Dense, fully-reduced matrix value: a row-major Array[Double], not n² _Number nodes.
The concrete counterpart of the symbolic matrix node (matrix._Matrix), exactly as _Number is the concrete counterpart of a scalar expression. Lives in core so Environment can bind matrix values without core depending on any domain.
Immutability: the public factory (_MatrixValue$.apply) takes a defensive copy and the storage is private — kernels build results on arrays they own, skipping the copy.
multiply parallelises over independent row blocks above a work-volume threshold; writes are disjoint and require no locking.
Value parameters
- cols
-
number of columns; must be positive
- rows
-
number of rows; must be positive
Attributes
- Companion
- object
- Supertypes
Concrete real scalar value.
Concrete real scalar value.
Rounding is a display concern only: toString and display round for output; eval propagates the stored Double as-is. ±∞ serialises as "inf" / "-inf" for round-trip safety through the parser.
Value parameters
- d
-
the exact double-precision value
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait _Valuetrait _Expressionclass Objecttrait Matchableclass AnyShow all
An exact rational number, held as an unreduced BigInt pair with the sign in the numerator and a strictly positive denominator.
An exact rational number, held as an unreduced BigInt pair with the sign in the numerator and a strictly positive denominator.
A sibling _Value of _Number, exactly as _Complex and _Truth are — _Number is not replaced and not widened, so every existing _Number(x) pattern match keeps firing unchanged and the Double path stays byte-identical. A _Rational only ever enters an expression through the parser's exact mode; see Environment for the working precision that bounds it.
The promotion lattice (the Int → Double analogy logic.asTruth already uses): rational ⊕ rational is exact, rational ⊕ number is a _Number — float contagion. Contagion is deliberate and it is the asymmetric choice: absorbing the _Number into the rational would be perfectly lossless, since every finite Double is a dyadic rational, but it would launder representation error into an exact-looking value. Once a value is inexact it should stay visibly inexact. The contagion needs no code of its own: _Complex.parts reads a _Rational as a Double, so the existing complex kernels produce it for free.
Why a private BigInt pair rather than spire's Rational. spire normalises to lowest terms on every construction, which would have settled GcdPolicy at GcdPolicy.Eager by fiat and made the gcd-policy benchmark unrunnable. spire remains the intended engine for irrationals (Real / Algebraic); the rational representation stays in-house.
Equality is by value, not by representation: 2/6 == 1/3 holds under every policy. hashCode therefore has to reduce, which means a GcdPolicy.Lazy rational used as a hash key pays the gcd it was avoiding.
Value parameters
- den
-
the denominator, always strictly positive
- num
-
the numerator, carrying the sign
Attributes
- Companion
- object
- Supertypes
-
trait Ordered[_Rational]trait Comparable[_Rational]trait _Valuetrait _Expressionclass Objecttrait Matchableclass AnyShow all
An exact real a + b·√d (F_0231): a, b rational, d a positive integer that is not a perfect square, b != 0.
An exact real a + b·√d (F_0231): a, b rational, d a positive integer that is not a perfect square, b != 0.
The sixth sibling of _Number, after _Complex, _Truth, _Rational, _Based and _Interval, and like _Rational it widens: case _Number(x) reads it as the real number it is, so a site that knows nothing of surds computes in Double -- float contagion, the safe direction -- while exactness is opt-in. Built only through _Surd.of.
Why one radical, not the field of all square roots: a + b√d is closed under + − × ÷ over a fixed d and covers every quadratic root and every 2-norm; √2 + √3 leaves it, and leaves the exact set the way every irrational always did.
Equality without a canonical radicand: a + b√d = a' + b'√d' iff a = a', b and b' share a sign, and b²d = b'²d' -- all exact, no factoring. hashCode hashes exactly those.
Value parameters
- a
-
the rational part
- b
-
the coefficient of the radical, never zero
- d
-
the radicand, a positive non-square integer
Attributes
- Companion
- object
- Supertypes
Companion for _Surd: the factory, the exact field arithmetic, and the readers.
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
A graded truth value: a degree strictly between false and true.
A graded truth value: a degree strictly between false and true.
The degree is never exactly 0.0 or 1.0 — the _Truth.of factory guarantees this invariant by collapsing to _Bool in those cases, so _Truth and _Bool together carry the full [0, 1] interval without overlapping. Construction through of is the only public route; pattern matching _Truth(d) remains available.
In three-valued (Kleene) logic the only reachable degree is 0.5, the named constant _Truth.Unknown, which prints and parses as unknown. The [0, 1] carrier is already in place for the fuzzy tier; degrees other than 0.5 print as plain numbers and do not round-trip through the parser yet (there is no grammar literal for them).
Like _Number, a _Truth never rounds in eval; rounding is a display concern handled by toString / display(p).
Value parameters
- d
-
the truth degree, guaranteed to lie strictly inside
(0, 1)by _Truth.of
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait _Valuetrait _Expressionclass Objecttrait Matchableclass AnyShow all
Companion for the graded truth value _Truth; holds the smart factory and the named unknown constant.
Companion for the graded truth value _Truth; holds the smart factory and the named unknown constant.
_Truth.of collapses the crisp endpoints 0.0 / 1.0 back to _Bool(false) / _Bool(true), so every existing _Bool(b) pattern match across the codebase keeps firing on crisp results — only a genuinely intermediate degree ever becomes a _Truth. This mirrors _Complex.of's collapse of a zero imaginary part back to _Number.
Attributes
Marker trait for a fully-reduced, concrete result — a number, a matrix, or a boolean — as opposed to a symbolic atom (free variable) that is not yet concrete.
Marker trait for a fully-reduced, concrete result — a number, a matrix, or a boolean — as opposed to a symbolic atom (free variable) that is not yet concrete.
Attributes
- Supertypes
- Known subtypes
-
class _Basedclass _Boolclass _Complexclass _Intervalclass _MatrixValueclass _Numberclass _Rationalclass _Surdclass _Truthclass _DistributionShow all
A free variable: a symbolic atom that is not yet a concrete value.
A free variable: a symbolic atom that is not yet a concrete value.
eval returns Right only when variable is bound to a _Value in the environment; otherwise it stays Left(this).
Value parameters
- variable
-
the variable name
Attributes
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait _Expressionclass Objecttrait Matchableclass AnyShow all
Value members
Concrete methods
Whether a named constant occurs in e.
Whether a named constant occurs in e.
Value parameters
- e
-
the expression
Attributes
- Returns
-
true when
eholds a _Constant
e as an exact rational at digits decimal places.
e as an exact rational at digits decimal places.
Value parameters
- digits
-
the working precision in decimal digits
Attributes
The Euler–Mascheroni constant γ as an exact rational at digits decimal places (F_0289).
The Euler–Mascheroni constant γ as an exact rational at digits decimal places (F_0289).
spire has no γ, so it is computed by the Brent–McMillan algorithm in fixed point: with A₀ = −ln n, B₀ = 1, Bₖ = Bₖ₋₁·n²/k², Aₖ = (Aₖ₋₁·n²/k + Bₖ)/k, γ ≈ ΣAₖ/ΣBₖ with an error near π·e^(−4n), so n is chosen from the digits asked and the sums run until the terms vanish in the guard digits.
Value parameters
- digits
-
the working precision in decimal digits
Attributes
e evaluated where a number is needed (F_0289): as eval, and when that leaves a closed expression holding a named constant, evaluated again with every constant read at the working precision — what the parser's rational reading of pi gave every computation before.
e evaluated where a number is needed (F_0289): as eval, and when that leaves a closed expression holding a named constant, evaluated again with every constant read at the working precision — what the parser's rational reading of pi gave every computation before.
Value parameters
- e
-
the expression
- env
-
the environment
Attributes
- Returns
-
the evaluation
A positive rational raised to a rational power, at digits decimal places.
A positive rational raised to a rational power, at digits decimal places.
b^e = exp(e · ln b) in spire's terms; the base must be positive, since a negative one with a fractional exponent is the complex case and belongs to the caller's fallback.
Value parameters
- b
-
the base, which must be strictly positive
- digits
-
the working precision in decimal digits
- e
-
the exponent
Attributes
- Returns
-
the power at that precision, or
Nonewhen the base is not positive
The square root of a non-negative rational, at digits decimal places.
The square root of a non-negative rational, at digits decimal places.
Uses Real rather than spire's Algebraic, although an earlier plan suggested the latter for polynomial roots. Algebraic's advantage is a decidable sign and comparison — and the only place this is used, the quadratic solver, has already established the sign by comparing the discriminant against zero in exact rational arithmetic, so there is nothing left for that decidability to buy.
Value parameters
- digits
-
the working precision in decimal digits
- r
-
the radicand, which must be non-negative
Attributes
- Returns
-
the root at that precision, or
Nonefor a negative radicand
e with every named constant replaced by its reading in env (F_0289).
e with every named constant replaced by its reading in env (F_0289).
Value parameters
- e
-
the expression
- env
-
the environment, which decides the tier and the working precision
Attributes
- Returns
-
the expression with no constant left
Materialises a Real back into the exact tier at digits decimal places, and never fewer than digits significant digits for a nonzero value (F_0271, the owner's Decision 3).
Materialises a Real back into the exact tier at digits decimal places, and never fewer than digits significant digits for a nonzero value (F_0271, the owner's Decision 3).
Computes at digits +GuardDigits and then takes the best rational with denominator at most 10^digits, which is the same bounded-denominator step the rest of the tier uses — so the result carries the working precision and no more, and its operands stay small. A value below one gets as many more places as it lies decades below one: by decimal places alone exp(-100) read as 0 and exp(-60) kept one digit, the units rule in the exact tier's own definition of precision. The magnitude is found by reading at doubling precision until the value shows, up to MaxReadingDecades; a value still invisible there reads at the decimal places, as before. An exact Real is read as itself.
Value parameters
- digits
-
the working precision in decimal digits
- x
-
the computed value
Attributes
- Returns
-
the exact approximation, or
Noneif the value could not be evaluated
pi as an exact rational at digits decimal places.
pi as an exact rational at digits decimal places.
Genuinely digits correct places, where tier 1 could offer at most fifteen: the constant is now computed rather than read off a Double.
Value parameters
- digits
-
the working precision in decimal digits
Attributes
Concrete fields
Extra digits computed and then discarded, to absorb the rounding of the final re-approximation and of the arithmetic immediately around it.
Extra digits computed and then discarded, to absorb the rounding of the final re-approximation and of the arithmetic immediately around it.
Without guard digits the last place of a result would be unreliable exactly when a user raised the precision to inspect it.
Attributes
The deepest expression the library accepts or builds (F_0078): parsed input deeper than this is refused, and a symbolic sum/product or an expand that would build one declines.
The deepest expression the library accepts or builds (F_0078): parsed input deeper than this is refused, and a symbolic sum/product or an expand that would build one declines.
What overflows is tree depth, and a long sum IS a deep tree — x1 + … + xN is an N-deep left spine, so the recursive walkers descend N frames. Parser.MaxDepth counts nesting only, so it never saw a flat chain. The shallowest platform decides (the Parser.MaxDepth rule): measured on Node with fresh variables at every size, simplify survives a 250-deep chain and overflows at 300, derive at 350; the JVM's default stack takes simplify to 600 and fails at 800 — with a StackOverflowError that ends the REPL session. Eval, toString, expand and the LaTeX renderer all survive 1000. Measure with fresh names: simplify and derive are memoised, and a chain that extends a shorter one already walked hits the cache part-way down, which is how an earlier figure of "500 survives" came about. F_0086 (walkers that do not recurse down a spine) is what would let this rise.
Attributes
How many decades below one a reading looks for a small nonzero value before it settles for the decimal places alone (F_0271).
How many decades below one a reading looks for a small nonzero value before it settles for the decimal places alone (F_0271).
A Real that is exactly zero reads as zero at every precision, so the search needs an end; the trivial zeros of the kernels (sin(0), ln(1)) never reach it, being built as exact Reals. The cost of an invisible value is a reading at digits + 500 places; 500 reaches exp(-1150), and the cap is what bounds the time of a value below it, which reads 0.
Attributes
Extensions
Extensions
Collapses an eval result back to a plain _Expression. Used when rebuilding a symbolic node from partially-reduced operands.
Collapses an eval result back to a plain _Expression. Used when rebuilding a symbolic node from partially-reduced operands.