Core conversion capabilities and outcomes #
A source's ExactDecoder gives its exact value. An ExactMap embeds that value into the
destination's exact domain, and a Quantizer rounds it under the policy of its context.
ConversionOutcome retains the resulting value and flags, or the reason conversion failed.
RoundingModes and ModeContext give the type of a conversion's (mode := ...) option and the
destination context each mode selects.
Conversion.Runtime has the entry points, and Conversion.Proof has their correctness theorems
and the laws for composing outcomes.
Location of an input that prevented a conversion or mixed operation.
- source : InputPosition
The sole input of a conversion.
- left : InputPosition
The left input of a binary or fused operation.
- right : InputPosition
The right input of a binary or fused operation.
- addend : InputPosition
The third input of a fused multiply-add.
- operand
(index : ℕ)
: InputPosition
A zero-based input of a user-defined exact expression.
Instances For
Instances For
Instances For
Why an explicit conversion or mixed-format operation produced no destination value.
- infinity
(position : InputPosition)
(negative : Bool)
: ConversionFailure
An infinity reached an operation that requires an ordinary finite input.
- exceptional
(position : InputPosition)
(value : Numerics.ExceptionalValue)
: ConversionFailure
An exceptional value reached an operation that requires an ordinary finite input.
- divisionByZero : ConversionFailure
Exact division was requested with a zero denominator.
- outOfRange : ConversionFailure
A finite exact result is outside a destination configured to reject overflow.
- unsupportedPolicy : ConversionFailure
The requested family-specific conversion policy is not implemented by the destination.
Instances For
Instances For
Instances For
An exact scalar computation that may reject a non-finite input or an undefined operation.
Successful expressions contain an unrounded value in the destination's exact domain. Applying
roundOnce quantizes the result once. The Except alias supports ordinary do notation and stops
at the first failure.
Instances For
Representation-independent information about a successful quantization.
Flags describe one conversion. saturated and wrapped distinguish clamping from modular
reduction, and either can also be inexact. Composing successful outcomes with bind combines
their flags with Boolean OR.
- inexact : Bool
The stored destination does not denote the exact finite input.
- overflow : Bool
The rounded result did not fit the destination's finite range. Binary destinations set this after rounding, in the IEEE 754 sense. Each quantizer documents its own rule.
- underflow : Bool
The result was tiny. Binary destinations use the IEEE 754 rule, tiny after rounding and inexact. P3109 reports a nonzero exact input below its least positive datum.
- saturated : Bool
The result was clamped to a finite endpoint.
- wrapped : Bool
The result was reduced modulo a bounded storage width.
- mappedSpecial : Bool
A source infinity or exceptional value was mapped to another value class.
- invalid : Bool
The conversion signaled invalid operation. Binary destinations raise it for a signaling NaN source, as IEEE 754 §7.2 requires.
Instances For
Instances For
Instances For
Combine the flags raised by two successful conversion steps.
Instances For
Result of an explicit conversion or destination-driven mixed operation.
- success
{α : Type u}
(value : α)
(status : ConversionStatus := { })
: ConversionOutcome α
A destination value together with conversion status.
- failure
{α : Type u}
(reason : ConversionFailure)
: ConversionOutcome α
A conversion rejected by its policy or by finite-only mixed arithmetic.
Instances For
Instances For
Instances For
Transform a successful value while preserving status and failure information.
Instances For
Continue from a successful value, accumulating status from both successful steps.
A failure short-circuits unchanged. Because ConversionOutcome.failure does not carry status,
flags from an earlier success are unavailable when a later step fails.
Instances For
Extract a successful destination value.
Instances For
Extract status from a successful conversion.
Instances For
Extract the reason for a failed conversion.
Instances For
Executable exact interpretation of a source value.
Exact is an output parameter so the source type selects its canonical executable exact domain.
For example, configured binary sources select SignedRat to retain signed zero, posit sources
select Rat, and a shared-scale block may select Vector Rat lanes.
- decode : Source → Numerics.NumericalValue Exact
Decode every source value, retaining infinity and exceptional observations.
Instances
Natural numbers enter explicit conversion as exact finite natural values.
Integers enter explicit conversion as exact finite integer values.
Rationals enter explicit conversion without an intermediate floating-point approximation.
Dyadic values enter explicit conversion with their exact significand and binary exponent.
Context-indexed quantization capability for one destination value type.
Its specification is relational, so stochastic, state-indexed and otherwise nondeterministic
mathematics stay expressible even when run chooses one executable result.
Exact is an output parameter, so a destination has one canonical mathematical input domain.
Alternative execution backends must refine that semantics and keep the domain users see. Sources
with a different exact domain reach it through an ExactMap.
Mixed addition and subtraction also consult this context before quantization. The default
operations are those of Exact, and a signed-zero domain can refine the sign of an exact
cancellation without changing its numerical value. Multiplication and division use the operations
of the exact domain.
correct relates run to spec and does not constrain these arithmetic hooks, so a family
proves separately that its hooks keep the numerical sum and difference. The generic prepared-spec
theorems compose quantization with the supplied hooks, and an arithmetic correctness result also
needs those preservation lemmas, as the binary instances supply.
What spec says is up to the family. Choosing Spec.ofFunction run makes correct reflexive and
gives no rounding property of its own. A family contract can expose denotation, coefficient or
policy predicates while keeping full output and status equality, and the generic conversion
theorems transport the clauses that the installed relation contains and no others.
- Context : Type
Family-specific context, such as rounding policy, entropy, overflow rule, or block exponent.
- run : Context Destination → Numerics.NumericalValue Exact → ConversionOutcome Destination
Executable quantizer.
- spec : Numerics.Quantization.Spec (Context Destination) (Numerics.NumericalValue Exact) (ConversionOutcome Destination)
Mathematical relation implemented by
run. - correct : spec.Implements run
The executable quantizer always chooses a result permitted by
spec. Exact addition under the destination context, including any direction-dependent zero sign.
A family overriding this operation must retain the numerical sum in its exact domain.
Exact subtraction under the destination context, including any direction-dependent zero sign.
A family overriding this operation must retain the numerical difference in its exact domain.
Instances
The canonical context used when a conversion or mixed operation names neither mode nor
context.
- defaultContext : Quantizer.Context Destination
Context selected by a conversion that names neither
modenorcontext.
Instances
The type of the mode option of conversions into Destination, with the direction used when a
call names none.
Binary destinations use IEEERoundingMode, nearest-even by default. A destination without
directed conversion falls back to RoundingModes.unit, so naming a direction for it is a type
error rather than an ignored option.
- default : Mode
The direction used when a call names no
mode.
Instances
A destination without selectable rounding directions has the single mode ().
The context type of Destination, indexed by the mode that selects its default.
Conversions take (context : ContextFor target mode := ...). The index lets the default value
find ModeContext target mode, and a caller's context of type Quantizer.Context target fits
because the two types are definitionally equal.
Instances For
The destination context that a conversion's mode option selects when it names no context.
ModeContext.canonical gives the canonical context to every destination with a
DefaultQuantizer and no rounding directions. Binary destinations install an instance for every
direction. A destination without a canonical context, such as a shared-scale block, has no
instance and needs a context argument.
- context : ContextFor Destination mode
The context that rounds in direction
mode.
Instances
A destination without rounding directions uses its canonical context for its one mode.