Proof contracts for transcendental approximations #
These contracts state and prove accuracy claims about an approximation:
- a real function value lies in a proved enclosure;
- an executable result satisfies a proved absolute-error budget; and
- an enclosure is narrow enough that both endpoints round to the same destination value.
When both endpoints round alike, monotonicity forces the enclosed function value to round there
too. StableEnclosure.roundAt_eq_roundAt_lower proves this fact. Constructing an enclosure
requires Lean proofs of both bounds; external numerical output alone does not supply them.
IEEE exceptional-value behavior and the sign of an exact zero remain separate bit-level
obligations. roundAt is the finite real grid semantics.
ApproximationCertificateOn and CorrectlyRoundedCertificateOn restrict the finite-real
guarantees to an explicit predicate on encoded inputs. For example, a logarithm certificate can
use fun input ↦ 0 < toReal input; an exponential certificate can use a proved input range on
which the result remains finite. Membership never replaces the obligation to prove output
finiteness. Outside the domain these certificates make no claim, so exceptional-value and overflow
behavior need separate specifications. The certificates without On apply to every finite input
and are equivalent to the domain-restricted certificates with domain fun _ ↦ True.
References #
- IEEE 754-2019, Section 9.2, recommended correctly rounded operations.
- F. de Dinechin, C. Lauter, and J.-M. Muller, “Fast and correctly rounded logarithms in double-precision,” RAIRO-Theoretical Informatics and Applications 41(1), 2007.
- S. Boldo and G. Melquiond, “Flocq: A Unified Library for Proving Floating-Point Algorithms in Coq,” IEEE ARITH 2011.
A checked closed real enclosure of f x.
- lower : ℝ
Proved lower endpoint.
- upper : ℝ
Proved upper endpoint.
The lower endpoint does not exceed the exact value.
The exact value does not exceed the upper endpoint.
Instances For
Use proved executable rational endpoints in a real-valued approximation contract.
Instances For
A Taylor enclosure whose rational endpoints are computed inside FloatLib.
Instances For
A proved rational logarithm enclosure for a positive input.
Instances For
The exact function value belongs to its enclosure.
Every proved enclosure has ordered endpoints.
Any candidate lying in the same enclosure has absolute error at most its width.
This conservative bound is often sufficient for a first verified implementation. A sharper
algorithm-specific proof can populate ApproximationCertificate directly.
Build an enclosure by monotonicity from a real input interval.
Instances For
Round a proved real enclosure outward with any sound endpoint rounder.
Instances For
Sound exponential enclosure on an input interval.
Instances For
Sound hyperbolic-sine enclosure on an input interval.
Instances For
Enclose sine in [-1, 1] for every real argument.
Instances For
Enclose cosine in [-1, 1] for every real argument.
Instances For
Enclose hyperbolic tangent in [-1, 1] for every real argument.
Instances For
Sound hyperbolic-cosine enclosure on an input interval.
The upper endpoint uses the largest absolute endpoint because cosh is even and increases with
absolute value.
Instances For
Convert the existing proved logarithm interval into the common enclosure contract.
Instances For
Convert the existing proved square-root interval into the common enclosure contract.
No sign hypothesis is needed: Real.sqrt is zero on negative arguments and monotone on all of ℝ.
Instances For
A proved enclosure whose endpoints select one nearest-even destination-grid value.
The inherited enclosure bounds and the endpoint-rounding equality are all proof obligations.
Both enclosure endpoints round to the same finite-grid real value.
Instances For
A stable enclosure determines the correctly rounded real value of the exact function.
A finite encoded result backed by a stable real enclosure.
The final equality connects the stored result to the lower endpoint's rounded value. Together with stability, this proves correct nearest-even rounding of the exact function in finite real semantics.
- value : Model fmt
Encoded result returned by an implementation.
The encoded result is finite, so
toRealis its complete numerical magnitude.The implementation selected the endpoint-certified rounded real value.
Instances For
The certified encoded result has the correctly rounded real value of f x.
Whole-algorithm absolute-error contract for an executable unary approximation.
The fields require output finiteness and an error bound for every finite input.
Every advertised error budget is nonnegative.
Finite inputs in scope produce finite outputs.
- error_le (input : Model fmt) : input.isFinite = true → |(approximation input).toReal - f input.toReal| ≤ errorBudget input
The decoded result satisfies the advertised real absolute-error budget.
Instances For
Whole-algorithm correctly-rounded finite-real contract.
Both components are propositions, so the certificate adds no runtime data.
Instances For
Finite inputs in scope produce finite outputs.
At every finite input, the result equals nearest-even rounding of the exact real function.
Absolute-error contract on an explicit domain of encoded inputs.
The domain can express mathematical restrictions, such as positivity for logarithms, and the range on which finite output is promised. Budgets must be nonnegative on the domain; output finiteness and accuracy are required for every finite input in that domain. In particular, merely restricting the mathematical domain does not discharge the output-finiteness obligation.
Every budget advertised on the domain is nonnegative.
- output_finite (input : Model fmt) : input.isFinite = true → domain input → (approximation input).isFinite = true
Finite inputs in the domain produce finite outputs.
- error_le (input : Model fmt) : input.isFinite = true → domain input → |(approximation input).toReal - f input.toReal| ≤ errorBudget input
The decoded result satisfies the budget at every finite input in the domain.
Instances For
Restrict an absolute-error certificate to a smaller domain.
A whole-algorithm absolute-error certificate applies on any chosen domain.
The unrestricted domain gives the absolute-error contract for all finite inputs.
Correct nearest-even finite-real rounding on an explicit domain of encoded inputs.
Every finite input in the domain must produce a finite result with the stated rounded real
value. This does not certify overflow, exceptional values, or the sign of zero: roundAt has no
upper exponent bound, and those behaviors need separate bit-level specifications.
Instances For
Finite inputs in the certified domain produce finite outputs.
At finite inputs in the domain, the result equals rounding of the exact real function.
Restrict a correctly-rounded certificate to a smaller domain.
Assemble a domain certificate from stable enclosures certifying the implementation's results.
A whole-algorithm correctly-rounded certificate applies on any chosen domain.
The unrestricted domain gives the correct-rounding contract for all finite inputs.