TorchLean API

FloatLib.Floats.Formats.BinaryInterchange.Configured.Real

Real values of configured binary values #

toReal? reads a configured binary value as the real number it denotes, through its proof model, and returns none for NaNs and infinities, which have no real value. toReal is the total version, which maps them to zero as Model.toReal does.

The theorems toReal_add through toReal_sqrt state the IEEE rounding contract on the configured carrier: a finite result of x + y, x - y, x * y, x / y, or sqrt x is the nearest-even rounding Model.roundAt of the exact real result. abs_toReal_add_sub_le and its siblings turn that into an absolute error of at most half an ulp, Model.epsilonAt format. They need an IEEE descriptor, finite operands, a finite result (square root always has one), a nonzero divisor for division, a nonnegative operand for square root, and, like toModel_hAdd, the instance argument that the selected capability computes the configured model operation. Instance search proves that argument for every capability the library declares.

noncomputable def FloatLib.Floats.ExecFloat.Binary.toReal? {format : Formats.BinaryInterchange.FloatFormat} {plan : Formats.BinaryInterchange.Configured.StoragePlan format} {code : Type} [ModelCodec plan (Formats.BinaryInterchange.Model format) code] (value : Binary format.expWidth format.fracWidth format.encoding format.exponentBias ⋯ ⋯ ⋯ ⋯ plan code) :

Exact real value of a finite configured binary value, or none for a NaN or an infinity.

Instances For
    noncomputable def FloatLib.Floats.ExecFloat.Binary.toReal {format : Formats.BinaryInterchange.FloatFormat} {plan : Formats.BinaryInterchange.Configured.StoragePlan format} {code : Type} [ModelCodec plan (Formats.BinaryInterchange.Model format) code] (value : Binary format.expWidth format.fracWidth format.encoding format.exponentBias ⋯ ⋯ ⋯ ⋯ plan code) :

    Real value of a configured binary value. A NaN or an infinity, which has no real value, gives zero. Theorems about it carry finiteness hypotheses, and toReal? is the partial version.

    Instances For
      @[simp]

      The optional real value is absent exactly for the values that are not finite.

      theorem FloatLib.Floats.ExecFloat.Binary.toReal_of_toRat?_eq_some {format : Formats.BinaryInterchange.FloatFormat} {plan : Formats.BinaryInterchange.Configured.StoragePlan format} {code : Type} [ModelCodec plan (Formats.BinaryInterchange.Model format) code] {value : Binary format.expWidth format.fracWidth format.encoding format.exponentBias ⋯ ⋯ ⋯ ⋯ plan code} {q : ℚ} (hvalue : value.toRat? = some q) :
      value.toReal = ↑q

      A value whose exact rational value is q has real value q.

      theorem FloatLib.Floats.ExecFloat.Binary.toReal?_eq_some_toReal {format : Formats.BinaryInterchange.FloatFormat} {plan : Formats.BinaryInterchange.Configured.StoragePlan format} {code : Type} [ModelCodec plan (Formats.BinaryInterchange.Model format) code] {value : Binary format.expWidth format.fracWidth format.encoding format.exponentBias ⋯ ⋯ ⋯ ⋯ plan code} (hvalue : value.isFinite = true) :
      value.toReal? = some value.toReal

      A finite value's optional real value is its real value.

      theorem FloatLib.Floats.ExecFloat.Binary.toReal_add {format : Formats.BinaryInterchange.FloatFormat} {plan : Formats.BinaryInterchange.Configured.StoragePlan format} {code : Type} [ModelCodec plan (Formats.BinaryInterchange.Model format) code] [Backend.PolicyFor (Formats.BinaryInterchange.Configured.Family format code plan)] {left right : Binary format.expWidth format.fracWidth format.encoding format.exponentBias ⋯ ⋯ ⋯ ⋯ plan code} [cap : Add (Formats.BinaryInterchange.Configured.Family format code plan)] [Capability.HasSpec cap Formats.BinaryInterchange.Configured.Spec.add] (hformat : format.isIEEE = true) (hleft : left.isFinite = true) (hright : right.isFinite = true) (hresult : (left + right).isFinite = true) :

      A finite configured sum is the nearest-even rounding of the exact real sum.

      theorem FloatLib.Floats.ExecFloat.Binary.toReal_sub {format : Formats.BinaryInterchange.FloatFormat} {plan : Formats.BinaryInterchange.Configured.StoragePlan format} {code : Type} [ModelCodec plan (Formats.BinaryInterchange.Model format) code] [Backend.PolicyFor (Formats.BinaryInterchange.Configured.Family format code plan)] {left right : Binary format.expWidth format.fracWidth format.encoding format.exponentBias ⋯ ⋯ ⋯ ⋯ plan code} [cap : Sub (Formats.BinaryInterchange.Configured.Family format code plan)] [Capability.HasSpec cap Formats.BinaryInterchange.Configured.Spec.sub] (hformat : format.isIEEE = true) (hleft : left.isFinite = true) (hright : right.isFinite = true) (hresult : (left - right).isFinite = true) :

      A finite configured difference is the nearest-even rounding of the exact real difference.

      theorem FloatLib.Floats.ExecFloat.Binary.toReal_mul {format : Formats.BinaryInterchange.FloatFormat} {plan : Formats.BinaryInterchange.Configured.StoragePlan format} {code : Type} [ModelCodec plan (Formats.BinaryInterchange.Model format) code] [Backend.PolicyFor (Formats.BinaryInterchange.Configured.Family format code plan)] {left right : Binary format.expWidth format.fracWidth format.encoding format.exponentBias ⋯ ⋯ ⋯ ⋯ plan code} [cap : Mul (Formats.BinaryInterchange.Configured.Family format code plan)] [Capability.HasSpec cap Formats.BinaryInterchange.Configured.Spec.mul] (hformat : format.isIEEE = true) (hleft : left.isFinite = true) (hright : right.isFinite = true) (hresult : (left * right).isFinite = true) :

      A finite configured product is the nearest-even rounding of the exact real product.

      theorem FloatLib.Floats.ExecFloat.Binary.toReal_div {format : Formats.BinaryInterchange.FloatFormat} {plan : Formats.BinaryInterchange.Configured.StoragePlan format} {code : Type} [ModelCodec plan (Formats.BinaryInterchange.Model format) code] [Backend.PolicyFor (Formats.BinaryInterchange.Configured.Family format code plan)] {left right : Binary format.expWidth format.fracWidth format.encoding format.exponentBias ⋯ ⋯ ⋯ ⋯ plan code} [cap : Div (Formats.BinaryInterchange.Configured.Family format code plan)] [Capability.HasSpec cap Formats.BinaryInterchange.Configured.Spec.div] (hformat : format.isIEEE = true) (hleft : left.isFinite = true) (hright : right.isFinite = true) (hzero : right.isZero = false) (hresult : (left / right).isFinite = true) :

      A finite configured quotient by a nonzero divisor is the nearest-even rounding of the exact real quotient.

      The configured square root of a finite zero or positive value is the nearest-even rounding of the exact real square root. The result is always finite.

      A finite configured sum is within half an ulp of the exact real sum.

      A finite configured difference is within half an ulp of the exact real difference.

      A finite configured product is within half an ulp of the exact real product.

      theorem FloatLib.Floats.ExecFloat.Binary.abs_toReal_div_sub_le {format : Formats.BinaryInterchange.FloatFormat} {plan : Formats.BinaryInterchange.Configured.StoragePlan format} {code : Type} [ModelCodec plan (Formats.BinaryInterchange.Model format) code] [Backend.PolicyFor (Formats.BinaryInterchange.Configured.Family format code plan)] {left right : Binary format.expWidth format.fracWidth format.encoding format.exponentBias ⋯ ⋯ ⋯ ⋯ plan code} [cap : Div (Formats.BinaryInterchange.Configured.Family format code plan)] [Capability.HasSpec cap Formats.BinaryInterchange.Configured.Spec.div] (hformat : format.isIEEE = true) (hleft : left.isFinite = true) (hright : right.isFinite = true) (hzero : right.isZero = false) (hresult : (left / right).isFinite = true) :
      |(left / right).toReal - left.toReal / right.toReal| ≤ Formats.BinaryInterchange.Model.epsilonAt format (left.toReal / right.toReal)

      A finite configured quotient by a nonzero divisor is within half an ulp of the exact real quotient.

      The configured square root of a finite zero or positive value is within half an ulp of the exact real square root.