it.grypho.scala.leonardo.core
Members list
Type members
Classlikes
Companion holding the global precision constant.
Companion holding the global precision constant.
Attributes
- Companion
- class
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
Environment.type
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
- 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. Note this is not the exact-mode switch: whether a value is exact is carried by its own type, so the only component that has to be told is the parser, which decides what a literal becomes. That flag lives incli.Sessionbesidepretty; anEnvironment.exactfield would be read by nothing.
Attributes
- Companion
- object
- Supertypes
-
class Objecttrait Matchableclass Any
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
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.
Value parameters
- balanced
-
whether the digits are the balanced set (base 3 only)
- base
-
the radix,
2 .. 36 - 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
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
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
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 _Feedbackclass _ImpulseResponseclass _Parallelclass _Seriesclass _StepResponsetrait _ElementWiseclass _EqualityCheckclass _Equationclass MatSumclass Transposeclass _Matrixclass _Heavisidetrait _MatrixShapedtrait _Valueclass _Basedclass _Boolclass _Complexclass _MatrixValueclass _Numberclass _Rationalclass _Truthclass _Distributionclass _Variableclass _Differentiableclass _Domainclass _Singularitiesclass _Comparisonclass _Solveclass _SolveSystemtrait _Connectiveclass Andclass Impliesclass Notclass Orclass Xorclass _Defuzzifytrait _Membershipclass GaussMFclass SigMFclass Somewhatclass TrapMFclass TriMFclass Veryclass _TruthOfclass Determinantclass _EigDecompositionclass _EigenDecompositionclass _JordanDecompositionclass _LUDecompositionclass _MatrixIndextrait _MatrixOperationclass IdentityMatrixclass Inverseclass MatProductclass MatScaleclass ZeroMatrixclass _MatrixExponentialclass _QRDecompositionclass _DistributionOfclass _DistributionQueryclass _Expectationclass _Variancetrait NamedFunctionclass Acosclass Acoshclass Asinclass Asinhclass Atanclass Atanhclass Betaclass BetaIclass Binomclass Catalanclass Ciclass Cosclass Coshclass Cotclass Cothclass Cscclass Cschclass Digammaclass Eiclass Erfclass Erfcclass Expclass Factorialclass FresnelCclass FresnelSclass Gammaclass GammaPclass GammaQclass Harmonicclass Liclass Lnclass LogBaseclass LogGammaclass MultiFactorialclass Secclass Sechclass Siclass Sinclass Sinhclass Tanhclass Tgclass _Balancedclass _Functionclass _Functionalclass _ODEclass _DefIntegralclass _Derivativeclass _FourierSeriesclass _Integralclass _Laurentclass _Limitclass _Padeclass _Tabulateclass _Taylorclass _Fourierclass _InverseLaplaceclass _InverseZTransformclass _Laplaceclass _ZTransformtrait _Operationclass Powerclass Productclass Ratioclass Sumclass _Patternclass _Sequenceclass _ToBaseclass _PairStatisticclass _Regressclass _Statisticclass _Testtrait _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
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
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
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
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
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 _MatrixValueclass _Numberclass _Rationalclass _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
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
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
Materialises a Real back into the exact tier at digits decimal places.
Materialises a Real back into the exact tier at digits decimal places.
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.
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
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.