TorchLean API

FloatLib.Floats.Formats.P3109.Arithmetic.Proof

Mathematical semantics of P3109 rational arithmetic #

Finite arithmetic is exact rational arithmetic, and rational embedding into the reals preserves the complete expression. The algebraic results describe arithmetic before rounding. The decoding theorems connect the public executable operations to one report projection of that exact result.

Exact closed addition is commutative, including exceptional operands.

Exact closed multiplication is commutative, including zero times infinity.

theorem FloatLib.Floats.Formats.P3109.Arithmetic.add_assoc (left middle right : Numerics.NumericalValue ) :
add (add left middle) right = add left (add middle right)

Exact closed addition is associative; opposite infinities remain indeterminate.

@[simp]

Subtracting a finite datum from itself gives the unique exact zero.

@[simp]

Zero denominators are NaN, even for infinite numerators.

@[simp]

Every finite numerator divided by either infinity gives the unique zero.

Finite nonzero division cancels before any destination rounding.

@[simp]

Finite fused multiply-add retains the whole rational expression.

theorem FloatLib.Floats.Formats.P3109.Arithmetic.faa_eq_add_add (left middle right : Numerics.NumericalValue ) :
faa left middle right = add left (add middle right)

Fused add-add is independent of the grouping of the exact additions.

Rational addition embeds as addition in the reals.

Rational subtraction embeds as subtraction in the reals.

Rational multiplication embeds as multiplication in the reals.

Nonzero rational division embeds as division in the reals.

FMA computes the real expression with no rounded intermediate product.

theorem FloatLib.Floats.ExecFloat.P3109.decode_unaryTo {source : Formats.P3109.Format} (destination : Formats.P3109.Format) (policy : Formats.P3109.ProjectionPolicy) (operation : Numerics.NumericalValue Numerics.NumericalValue ) (value : P3109 source) :
Formats.P3109.Format.SameDatum (unaryTo destination policy operation value).decode (destination.projectRatValue policy (operation value.toClosedRat))

The executable unary operation decodes to one projection of its exact closed result.

theorem FloatLib.Floats.ExecFloat.P3109.decode_binaryTo {leftFormat rightFormat : Formats.P3109.Format} (destination : Formats.P3109.Format) (policy : Formats.P3109.ProjectionPolicy) (operation : Numerics.NumericalValue Numerics.NumericalValue Numerics.NumericalValue ) (left : P3109 leftFormat) (right : P3109 rightFormat) :
Formats.P3109.Format.SameDatum (binaryTo destination policy operation left right).decode (destination.projectRatValue policy (operation left.toClosedRat right.toClosedRat))

The executable binary operation decodes to one projection of its exact closed result.

theorem FloatLib.Floats.ExecFloat.P3109.decode_ternaryTo {leftFormat rightFormat thirdFormat : Formats.P3109.Format} (destination : Formats.P3109.Format) (policy : Formats.P3109.ProjectionPolicy) (operation : Numerics.NumericalValue Numerics.NumericalValue Numerics.NumericalValue Numerics.NumericalValue ) (left : P3109 leftFormat) (right : P3109 rightFormat) (third : P3109 thirdFormat) :
Formats.P3109.Format.SameDatum (ternaryTo destination policy operation left right third).decode (destination.projectRatValue policy (operation left.toClosedRat right.toClosedRat third.toClosedRat))

The executable fused operation decodes to one projection of the whole exact expression.

theorem FloatLib.Floats.ExecFloat.P3109.decode_fmaTo_finite {leftFormat rightFormat thirdFormat : Formats.P3109.Format} (destination : Formats.P3109.Format) (policy : Formats.P3109.ProjectionPolicy) (left : P3109 leftFormat) (right : P3109 rightFormat) (addend : P3109 thirdFormat) (x y z : ) (hleft : left.toClosedRat = Numerics.NumericalValue.finite x) (hright : right.toClosedRat = Numerics.NumericalValue.finite y) (haddend : addend.toClosedRat = Numerics.NumericalValue.finite z) :
Formats.P3109.Format.SameDatum (fmaTo destination policy left right addend).decode (destination.projectRatValue policy (Numerics.NumericalValue.finite (x * y + z)))

Finite FMA is one projection of the exact rational product plus addend.