Repository navigation
Add Lean-core mul and div rounding theorems for unpacked format words - #3
Merged
Merged
Conversation
`toReal_ofModel_mul_finite_eq_roundAt` and `toReal_ofModel_div_finite_eq_roundAt` carry `roundWithAccuracy` and `divCore` premises that no lemma discharged, so they could not be applied to `Float` or `Float32` values directly. A new module, Arithmetic/LeanModel/MulDiv, proves them for format words: - `toReal_ofModel_mul_toModel_eq_roundAt` and `toReal_ofModel_div_toModel_eq_roundAt`: for a conventional IEEE descriptor and a finite result, Lean core's unpacked `mul` and `div` of the values unpacked from two format words have the same nearest-even real semantics as `Model.mul` and `Model.div`. Division also needs a finite divisor; the finite result gives the other operand conditions. - `toReal_ofModel_div_finite_eq_roundAt_of_isFinite`: the existing division theorem without its two `divCore` premises. A zero provisional quotient, as for the least positive subnormal over 1.5, is rounded from its sign, selected exponent and remainder accuracy. - `le_targetExponent_totalExponent_iff`, `add_le_targetExponent_totalExponent_mul`, `le_targetExponent_totalExponent_of_toModel_eq_finite` and `divCore_exponent_le_targetExponent`: the `roundWithAccuracy` precondition holds for finite nonzero values unpacked from format words, for their products, and for every `divCore` result on nonzero mantissas. - `toReal_ofModel_roundWithAccuracy_zero_eq_roundAt`: the zero-mantissa case that `toReal_ofModel_roundWithAccuracy_eq_roundAt` excludes. - `isFinite_toModel` and `isFinite_ofModel_notANumber`: for a conventional IEEE descriptor, Lean core's finiteness test agrees with `isFinite`, and packing Lean's NaN is not finite. The multiplication theorem for arbitrary unpacked operands keeps its exponent premise, which such operands need not satisfy. `accuracyRepresents_accuracyOfFraction` in Arithmetic/LeanModel becomes public so the new module can reuse it, and Semantics imports the module. Chapter 18 of the guide describes the theorems with a kernel-checked example, and NativeModel gains three boundary regressions covered by the axiom audit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2.
Adds the format-word forms of the Lean-core
mulanddivrounding theorems offered in #2. A user ofFloatorFloat32can now apply them with only a finite result (and a finite divisor for division), without proving theroundWithAccuracyanddivCorepremises oftoReal_ofModel_mul_finite_eq_roundAtandtoReal_ofModel_div_finite_eq_roundAt. No existing statement or proof changes.toReal_ofModel_mul_toModel_eq_roundAtandtoReal_ofModel_div_toModel_eq_roundAt(new module Arithmetic/LeanModel/MulDiv, beside LeanModel/AddSub): for a conventional IEEE descriptor and a finite result, Lean core's unpackedmulanddivof the values unpacked from two format words have the same independent nearest-even real semantics asModel.mulandModel.div. Division also needs a finite divisor; the finite result already gives finite factors, a finite dividend and a nonzero divisor.toReal_ofModel_div_finite_eq_roundAt_of_isFinite: the existing division theorem without its twodivCorepremises. A zero provisional quotient, as for the least positive subnormal over1.5, is rounded from its sign, selected exponent and remainder accuracy.le_targetExponent_totalExponent_iff,add_le_targetExponent_totalExponent_mul,le_targetExponent_totalExponent_of_toModel_eq_finiteanddivCore_exponent_le_targetExponent: theroundWithAccuracyprecondition holds exactly when the exponent is at or below the minimum exponent or the mantissa has at least as many bits as the precision, so it holds for finite nonzero values unpacked from format words, for their products, and for everydivCoreresult on nonzero mantissas.toReal_ofModel_roundWithAccuracy_zero_eq_roundAt: the zero-mantissa case thattoReal_ofModel_roundWithAccuracy_eq_roundAtexcludes.isFinite_toModelandisFinite_ofModel_notANumber: for a conventional IEEE descriptor, Lean core's finiteness test agrees withisFinite, and packing Lean's NaN is not finite.The multiplication theorem for arbitrary unpacked operands keeps its exponent premise: two operands
.finite .positive 1 0have exact product1, but Lean's result packs to the least subnormal.accuracyRepresents_accuracyOfFractionin Arithmetic/LeanModel losesprivateso the new module can reuse it, and Semantics imports the module. Chapter 18 of the guide gains one paragraph with a kernel-checked example, and Conformance/BinaryInterchange/NativeModel gains three boundary regressions (a zero provisional quotient with either sign, and a subnormal product at a tie) with entries in the axiom audit.Checked on top of 79b69ef with
tests/verify.sh: the publication privacy check, version pins, build (4,183 jobs), tests including the axiom audit, lint, and the architecture, public API docs and trust surface checks all pass. The optional Arb check was not run.site/build.shpasses in strict mode (21 chapters), and the CI workflow passed on my fork at this commit: https://github.com/rbeauchamp/FloatLib/actions/runs/37551566050. I also ran the kernel replay and had the documentation reviewed against the statements.The proofs were developed with AI assistance and are checked by Lean's kernel.