arithmetic/semantics.lisp
Internal canonical representation shared by dimensions and exact units.
A canonical product of symbolic base dimensions raised to rational powers.
Return a canonical dimension from NIL, one base symbol, or factor pairs.
Each factor pair has the form (BASE EXPONENT), where EXPONENT is rational.
A named linear unit with a dimension, canonical basis, scale, and kind.
Return the semantic definition of unit name, or signal undefined-unit.
A canonical product of defined named units.
Return a canonical unit expression from NIL, a defined unit, or factors.
Every symbolic factor must have a semantic unit definition. Exact unit identity remains visible here; conversions are requested separately.
Return the physical dimension implied by unit's definitions.
Return unit's scale relative to its canonical basis.
Return unit expressed only in canonical basis units.
Return the numerical factor converting source values into target values.
One node in the semantic hierarchy of kinds sharing physical dimensions.
Return the inspectable definition of quantity kind name.
Define name as one inspectable value behind an EQL-specialized function.
Whether kind is ancestor or reaches it through declared parent kinds.
The affine role of a value: a location, a non-negative amount from a true zero, or a signed difference between two of either.
Non-negativity is a declared fact about the named quantity, never derived from an equation: a defining equation captures dimension, not sign domain. It makes the quantity's default character :absolute and lets a later interpretation promise a non-negative amount. No lowering emits a check for it.
A domain quantity name, its unit kind, homogeneous components, and the affine character its specifications take unless a use site says otherwise.
Return the inspectable definition of quantity name, or NIL.
Define quantity name and any homogeneous components as members of kind.
non-negative-p declares a non-negative amount and defaults its character to
:ABSOLUTE. character may state :POINT, :ABSOLUTE, or :DIFFERENCE explicitly.
Components inherit both.
Return the kind constraint of one named unit, or NIL for a compound unit.
Define name as a semantic linear unit through an inspectable EQL method.
The roots are intentionally small: application domains add named quantities beneath these kinds without teaching the arithmetic core their vocabulary.
A compact ISQ/SI-inspired seed vocabulary. More units extend the same open protocol; an unknown spelling is an error rather than an anonymous factor.
Canonical quantity names are useful at generic boundaries; applications normally add narrower names (opacity, texture coordinates, world distance) beneath the same kinds.
The semantic meaning of a value, separate from its machine representation.
Whether specification is an affine point; kept as the historical spelling.
Whether specification's named definition declares a non-negative amount.
Only a named absolute can promise this; anonymous derived results never do.
Choose a specification character from an explicit character, the historical
affine-p spelling, or the named definition's default.
The definition supplies the default. An explicit :affine-p NIL says
only "not a point": a declared absolute stays absolute, a declared
point becomes a difference of that quantity.
Whether specification is linear, unitless, and optionally of tensor-order.
Copy source, replacing only the explicitly supplied semantic fields.
character is the general control; the historical :affine-p keyword still
sets or clears the point character.
One quantity occupying selected positions of a composite representation.
Semantic quantities packed into disjoint positions of one representation.
A fixed product repeated through flat storage at a physical lane stride.
The inherited extent and projections describe one stride period so existing projection tools continue to inspect an element. ELEMENT-LAYOUT retains the unpadded product definition; no runtime element object is implied.
Repeat element-layout through flat storage, optionally with lane padding.
Return the quantity exactly occupying positions in layout, or NIL.
Return the ordered homogeneous components declared for quantity-name.
Derive the quantity selected from a homogeneous represented quantity.
Selecting every position in order preserves the whole. A single component of an anonymous quantity remains anonymous. A named quantity must explicitly publish ordered component names; no default silently calls one axis the whole.
The affine table over point, absolute, and difference. A point is a location; an absolute is an amount from a true zero, forming a cone; a difference is signed. Adding a difference to an absolute keeps the zero anchor, so the result stays absolute; subtracting two absolutes yields a signed difference, and only an explicit interpretation recovers an absolute from it.
Products and quotients of two absolutes remain absolute; any signed factor makes the result a difference. Points never enter these operations.
A bare number is a pure scale factor and preserves the other operand's character, so twice an amount is still an amount.
Give a compatible anonymous derived specification an explicit meaning.
This is a semantic interpretation, never a numerical unit conversion. An
already named quantity may only retain its name; anonymous derived results may
acquire one when their dimension, exact unit, and tensor order agree with
interpretation. Character must agree too, with one deliberate exception: a
signed difference may be interpreted as an absolute. That is the explicit
promotion the affine algebra otherwise never performs — the author asserts
the amount is non-negative, and no lowering checks it (#PLRP3A). Points
never cross to or from the other characters here.
Return source expressed in target-unit and its required numeric factor.
The operation preserves semantic name, dimension, tensor order, and affine character. It is a linear unit conversion, not a semantic interpretation.
Derive the semantic result of applying operator to quantity operands.
Negating an amount is never an amount. The source leaves open whether it errors or demotes to a difference; luv errors, so the demotion is a visible mark (subtract from zero, or interpret) rather than a silent character change.
Portable numerical operators extend the same open semantic protocol as Common Lisp arithmetic. Execution backends remain responsible for their representations and implementations; these methods state only the lawful quantity relationship.
Internal canonical representation shared by dimensions and exact units.
A canonical product of symbolic base dimensions raised to rational powers.
(dimension)(factor)Logical disjunction of tests and raw truth values.
Logical conjunction of tests and raw truth values.
(factors)(&optional designator)Return a canonical dimension from NIL, one base symbol, or factor pairs. Each factor pair has the form (BASE EXPONENT), where EXPONENT is rational.
((call tool-call) stream)Test whether two compatible scalars are equal.
(left right)(left right)(product exponent)Multiplication and scalar scaling.
(left right)(dimension)(left right)(dimension exponent)(numerator denominator)A named linear unit with a dimension, canonical basis, scale, and kind.
(name)Return the semantic definition of unit NAME, or signal UNDEFINED-UNIT.
A canonical product of defined named units.
(factors)(&optional designator)Return a canonical unit expression from NIL, a defined unit, or factors. Every symbolic factor must have a semantic unit definition. Exact unit identity remains visible here; conversions are requested separately.
One top-level defining form of a source file.
(left right)(unit)(function unit initial-value)Raise a dimensionless value to a dimensionless power.
(left right)(unit exponent)(source target)Convert a quantity to a compatible unit.
Division of two represented quantities.
(numerator denominator)One node in the semantic hierarchy of kinds sharing physical dimensions.
(name)Return the inspectable definition of quantity kind NAME.
(function name value-form)(name dimension parent)Logical negation of one test or raw truth value.
(name &key dimension parent)(kind ancestor)()The affine role of a value: a location, a non-negative amount from a true zero, or a signed difference between two of either.
A domain quantity name, its unit kind, homogeneous components, and the affine character its specifications take unless a use site says otherwise.
(name kind &key components non-negative-p (character nil character-supplied-p))(name &key kind components non-negative-p
(character nil character-supplied-p))Define quantity NAME and any homogeneous COMPONENTS as members of KIND. NON-NEGATIVE-P declares a non-negative amount and defaults its character to :ABSOLUTE. CHARACTER may state :POINT, :ABSOLUTE, or :DIFFERENCE explicitly. Components inherit both.
(quantity-name unit unit-dimension)Construct a meaningful literal.
(name &key (dimension nil dimension-supplied-p) unit
(tensor-order 0)
(affine-p nil affine-p-supplied-p)
(character nil character-supplied-p))(name &key (dimension nil dimension-supplied-p)
(reference nil reference-supplied-p)
(magnitude 1) identity-p quantity-kind)(name &rest options)The semantic meaning of a value, separate from its machine representation.
(specification)(specification)(specification)(specification)Whether SPECIFICATION's named definition declares a non-negative amount. Only a named absolute can promise this; anonymous derived results never do.
(name character character-supplied-p affine-p affine-p-supplied-p)Choose a specification character from an explicit CHARACTER, the historical AFFINE-P spelling, or the named definition's default.
(left right)(specification &optional tensor-order)(source &key
(name (quantity-specification-name source))
(dimension (quantity-specification-dimension source))
(unit (quantity-specification-unit source))
(tensor-order (quantity-specification-tensor-order source))
(character (quantity-specification-character source)
character-supplied-p)
(affine-p nil affine-p-supplied-p))Copy SOURCE, replacing only the explicitly supplied semantic fields. CHARACTER is the general control; the historical :AFFINE-P keyword still sets or clears the point character.
One quantity occupying selected positions of a composite representation.
(positions specification)Semantic quantities packed into disjoint positions of one representation.
A fixed product repeated through flat storage at a physical lane stride. The inherited extent and projections describe one stride period so existing projection tools continue to inspect an element. ELEMENT-LAYOUT retains the unpadded product definition; no runtime element object is implied.
(extent projections)Test whether one compatible scalar is less than another.
(element-layout &key stride)Test whether one compatible scalar is at least another.
How the children of a list are arranged.
(left right)(layout positions)(quantity-name)(specification positions extent)Derive the quantity selected from a homogeneous represented quantity. Selecting every position in order preserves the whole. A single component of an anonymous quantity remains anonymous. A named quantity must explicitly publish ordered component names; no default silently calls one axis the whole.
(left right)(dimension unit tensor-order)(specification)(operator left right)Addition over compatible quantities.
Subtraction or unary negation.
(operator left right)(left right)Products and quotients of two absolutes remain absolute; any signed factor makes the result a difference. Points never enter these operations.
(operator left right)(operator left right)(derived interpretation)Give a compatible anonymous DERIVED specification an explicit meaning. This is a semantic interpretation, never a numerical unit conversion. An already named quantity may only retain its name; anonymous derived results may acquire one when their dimension, exact unit, and tensor order agree with INTERPRETATION. …
Name a compatible derived quantity.
(source target-unit)Return SOURCE expressed in TARGET-UNIT and its required numeric factor. The operation preserves semantic name, dimension, tensor order, and affine character. It is a linear unit conversion, not a semantic interpretation.
(operator &rest operands)Derive the semantic result of applying OPERATOR to quantity OPERANDS.
(operator operands pair-function &optional (minimum 1))The inner product of two vectors.
The minimum of compatible quantities.
The maximum of compatible quantities.
Constrain a quantity between compatible bounds.
Compare compatible quantities and produce dimensionless values.
Interpolate compatible quantities by a scalar amount.
Produce dimensionless progress across compatible edges.
Normalize a dimensionless vector.
Three positions on the source's runtime machinery, taken so that #LNRY72 does not silently import mp-units' cost model into a zero-cost lowering: – Non-negativity is a compile-time fact by default. A non-negative specifier participates in the character algebra — it decides what an absolute may become, and it is what…
Semantic arithmetic independent of any one execution backend.
Specifications are compile-time boundary objects. Runtime scalar and vector lanes remain ordinary unboxed data; an arithmetic graph, field operation, or shader compiler asks this protocol whether its operations are meaningful before choosing a backend representation.