The Lean Language Reference

20.6.Β Floating-Point NumbersπŸ”—

Floating-point numbers are a an approximation of the real numbers that are efficiently implemented in computer hardware. Computations that use floating-point numbers are very efficient; however, the nature of the way that they approximate the real numbers is complex, with many corner cases. The IEEE 754 standard, which defines the floating-point format that is used on modern computers, allows hardware designers and programming language implementations to make certain choices, and real systems differ in these small details. Any given combination of hardware, operating system, C compiler, library versions, and even compilation flags can result in different behavior. For example, there are many distinct bit representations of NaN, the indicator that a result is undefined, and some platforms differ with respect to which NaN is returned from adding two NaNs.

To enable reasoning about floating-point numbers, Lean exposes a logical model of Float that is used in proofs. In particular, Float and Float32 are implemented as wrappers around the logical model. In compiled code, this logical model is replaced by efficient native code. Differences between platforms are resolved by choosing specific representations (for example, all NaN values are replaced by a single canonical NaN when any operation requests a bit representation) and by modeling only the subset of floating-point operations that are implemented identically on all supported platforms. Other operations, such as trigonometric functions, are represented as opaque functions in Lean's logic.

The logical model is extensively empirically tested against the floating-point operations on all supported platforms. As long as FFI code does not modify the floating-point environment, Lean's runtime floating-point primitives match the model's specification.

πŸ”—structure
Float : Type
Float : Type

64-bit floating-point numbers.

Float corresponds to the IEEE 754 binary64 format (double in C or f64 in Rust). Floating-point numbers are a finite representation of a subset of the real numbers, extended with extra β€œsentinel” values that represent undefined and infinite results as well as separate positive and negative zeroes. Arithmetic on floating-point numbers approximates the corresponding operations on the real numbers by rounding the results to numbers that are representable, propagating error and infinite values.

Floating-point numbers include subnormal numbers. Their special values are:

  • NaN, which denotes a class of β€œnot a number” values that result from operations such as dividing zero by zero, and

  • Inf and -Inf, which represent positive and infinities that result from dividing non-zero values by zero.

Like other low-level types, Float is special-cased by the Lean compiler to correspond to the C double type. From the point of view of Lean's logic, Float is equivalent to Float.Model (via the functions Float.toModel and Float.ofModel), which is itself a subtype of UInt64. Some of the operations on Float are defined in terms of their Float.Model counterparts, while others are opaque to Lean's kernel.

Constructor

Float.ofModel

Constructs a Float from a Float.Model.

Fields

toModel : Float.Model

Converts a Float into a Float.Model.

πŸ”—structure
Float32 : Type
Float32 : Type

32-bit floating-point numbers.

Float32 corresponds to the IEEE 754 binary32 format (float in C or f32 in Rust). Floating-point numbers are a finite representation of a subset of the real numbers, extended with extra β€œsentinel” values that represent undefined and infinite results as well as separate positive and negative zeroes. Arithmetic on floating-point numbers approximates the corresponding operations on the real numbers by rounding the results to numbers that are representable, propagating error and infinite values.

Floating-point numbers include subnormal numbers. Their special values are:

  • NaN, which denotes a class of β€œnot a number” values that result from operations such as dividing zero by zero, and

  • Inf and -Inf, which represent positive and infinities that result from dividing non-zero values by zero.

Like other low-level types, Float32 is special-cased by the Lean compiler to correspond to the C float type. From the point of view of Lean's logic, Float32 is equivalent to Float32.Model (via the functions Float32.toModel and Float32.ofModel), which is itself a subtype of UInt32. Some of the operations on Float32 are defined in terms of their Float32.Model counterparts, while others are opaque to Lean's kernel.

Constructor

Float32.ofModel

Constructs a Float32 from a Float32.Model.

Fields

toModel : Float32.Model

Converts a Float32 into a Float32.Model.

20.6.1.Β Logical ModelπŸ”—

Lean provides two floating-point types: Float represents 64-bit floating-point values, while Float32 represents 32-bit floating-point values. The precision of Float does not vary based on the platform that Lean is running on.

20.6.1.1.Β Model DetailsπŸ”—

The logical models of Float and Float32 consist of unsigned integers with validity predicates. Each defined operation first interprets the integer into a Float.Model.UnpackedFloat, which is a higher-level model that is not specific to a bit width. Then, the defined operation is implemented in terms of UnpackedFloat, and the result is re-packed. These definitions constitute a logical specification designed for reasoning. Although they can be executed, they will run significantly slower than native code. Not all operations are defined; some are instead opaque functions whose behavior cannot be reasoned about in Lean's logic.

This model is not intended to serve as the basis for a more extensive floating-point library. It exists only to support the reasoning tools available in Lean and is not suitable for larger-scale development. Do not use this model as the basis of a more extensive floating-point library. Instead, implement a suitable model, prove the equivalence of the its operations to this model, and then transfer lemmas using the equivalence.

πŸ”—structure

The logical model for the Float type.

This is defined as the type of UInt64 with the additional restriction that bit patterns encoding a NaN must be exactly a chosen canonical NaN.

Most functions on Float.Model work by unpacking the Float.Model into the inductive type UnpackedFloat, performing the operation there, and then repacking the result into a Float.Model.

It is not a goal of this development to serve as the basis for a general-purpose floating-point library or to have any direct lemmas written about it at all. Rather, users interested in a library about floating-point numbers should develop such a library completely separately, and users interested in proving properties of their programs involving Float should prove that the operations defined here are equivalent to the operations defined in the separate library and then transfer lemmas from the library to the Float and Float32 types.

Constructor

Float.Model.mk

Fields

toBits : UInt64

The underlying bit pattern of the Float.Model.

valid : Float.Model.Format.binary64.Valid self.toBits.toBitVec

The underlying bit pattern is valid according to the IEEE binary64 format.

πŸ”—structure

The logical model for the Float32 type.

This is defined as the type of UInt32 with the additional restriction that bit patterns encoding a NaN must be exactly a chosen canonical NaN.

Most functions on Float32.Model work by unpacking the Float32.Model into the inductive type UnpackedFloat, performing the operation there, and then repacking the result into a Float32.Model.

It is not a goal of this development to serve as the basis for a general-purpose floating-point library or to have any direct lemmas written about it at all. Rather, users interested in a library about floating-point numbers should develop such a library completely separately, and users interested in proving properties of their programs involving Float32 should prove that the operations defined here are equivalent to the operations defined in the separate library and then transfer lemmas from the library to the Float and Float32 types.

Constructor

Float32.Model.mk

Fields

toBits : UInt32

The underlying bit pattern of the Float32.Model.

valid : Float.Model.Format.binary32.Valid self.toBits.toBitVec

The underlying bit pattern is valid according to the IEEE binary32 format.

πŸ”—def

Pack an UnpackedFloat into the corresponding Float.Model. This operation only gives a meaningful result if the float is already correctly rounded for the Format.binary64 format.

πŸ”—def

Pack an UnpackedFloat into the corresponding Float32.Model. This operation only gives a meaningful result if the float is already correctly rounded for the Format.binary32 format.

πŸ”—inductive type

An inductive type representing a floating-point number with constructors for signed infinity, not-a-number without payload, signed zero, and finite floats with a sign, positive natural mantissa and integral exponent.

Finite floats do not have a unique representation in this format: multiplying the mantissa by two and decreasing the exponent by one yields a finite float that represents the same rational number.

For a given Format, we say that an unpacked float is in canonical form if the exponent is equal to the targetExponent according to that format. Some operations on UnpackedFloat, such as compare, assume that the input(s) are all in canonical form for the same format.

Note that an unpacked float in canonical form for a given format may not actually be representable in that format as the exponent is too large to fit. In this case, the pack function will overflow the float to infinity.

This type exists solely for the purpose of supporting Float.Model and Float32.Model. It is not a goal of this development to serve as the basis for a general-purpose floating-point library or to have any direct lemmas written about it at all. Rather, users interested in a library about floating-point numbers should develop such a library completely separately, and users interested in proving properties of their programs involving Float should prove that the operations defined here are equivalent to the operations defined in the separate library and then transfer lemmas from the library to the Float and Float32 types.

Constructors

Float.Model.UnpackedFloat.infinity
  (sign : Float.Model.UnpackedFloat.Sign) :
  Float.Model.UnpackedFloat

Signed infinity.

Float.Model.UnpackedFloat.notANumber :
  Float.Model.UnpackedFloat

Not a number. There is no payload attached to a NaN in this format.

Float.Model.UnpackedFloat.zero
  (sign : Float.Model.UnpackedFloat.Sign) :
  Float.Model.UnpackedFloat

Signed zero.

Float.Model.UnpackedFloat.finite
  (sign : Float.Model.UnpackedFloat.Sign) (mantissa : Nat)
  (exponent : Int) (mantissa_pos : 0 < mantissa) :
  Float.Model.UnpackedFloat

Finite floats consisting of a sign bit, a positive natural mantissa and an exponent.

20.6.1.2.Β Model OperationsπŸ”—

The following operations are specified for floating-point values. Other operators are represented by opaque functions and do not reduce in the kernel.

πŸ”—def

Computes the sum of two floating point numbers and rounds the result according to the given specification.

πŸ”—def

Computes the difference of two floating point numbers and rounds the result according to the given specification.

πŸ”—def

Computes the product of two floating-point numbers and rounds the result according to the given specification.

πŸ”—def

Computes the quotient of two floating point numbers and rounds the result according to the given specification.

πŸ”—def

Computes the square root of a floating-point number and rounds the result according to the given specification.

πŸ”—def

Returns true if the float represents a real number, i.e., it is neither infinite nor NaN.

πŸ”—def

Computes the ordering between the two floats as specificed by IEEE. Returns an Option Ordering to account for the fact that NaN is incomparable with everything. Also, positive and negative zero are equal.

Important: this operation only works correctly if the two inputs are in canonical form for a common format (see the docstring for UnpackedFloat for details.)

πŸ”—def

Determines whether a is equal to b according to IEEE rules.

This is not a reflexive relation.

πŸ”—def

Determines whether a is less than b according to IEEE rules.

This is not a total ordering.

πŸ”—def

Determines whether a is less than or equal to b according to IEEE rules.

This is not a total ordering, and ≀ is not reflexive.

πŸ”—def

Converts a Nat to an UnpackedFloat, returning positive zero on zero.

πŸ”—def

Converts an Int to an UnpackedFloat, returning positive zero on zero.

πŸ”—def

Computes m * 10 ^ e.

πŸ”—def

Converts an UnpackedFloat to an Int8, truncating after the decimal point, sending NaN to 0 and clamping out-of-range values and infinities.

πŸ”—def

Converts an Int8 to an UnpackedFloat, returning positive zero on zero.

πŸ”—def

Converts an UnpackedFloat to an Int16, truncating after the decimal point, sending NaN to 0 and clamping out-of-range values and infinities.

πŸ”—def

Converts an Int16 to an UnpackedFloat, returning positive zero on zero.

πŸ”—def

Converts an UnpackedFloat to an Int32, truncating after the decimal point, sending NaN to 0 and clamping out-of-range values and infinities.

πŸ”—def

Converts an Int32 to an UnpackedFloat, returning positive zero on zero.

πŸ”—def

Converts an UnpackedFloat to an Int64, truncating after the decimal point, sending NaN to 0 and clamping out-of-range values and infinities.

πŸ”—def

Converts an Int64 to an UnpackedFloat, returning positive zero on zero.

πŸ”—def

Converts an UnpackedFloat to an ISize, truncating after the decimal point, sending NaN to 0 and clamping out-of-range values and infinities.

πŸ”—def

Converts an ISize to an UnpackedFloat, returning positive zero on zero.

πŸ”—def

Converts an UnpackedFloat to a UInt8, truncating after the decimal point, sending NaN to 0 and clamping out-of-range values and infinities.

πŸ”—def

Converts a UInt8 to an UnpackedFloat, returning positive zero on zero.

πŸ”—def

Converts an UnpackedFloat to a UInt16, truncating after the decimal point, sending NaN to 0 and clamping out-of-range values and infinities.

πŸ”—def

Converts a UInt16 to an UnpackedFloat, returning positive zero on zero.

πŸ”—def

Converts an UnpackedFloat to a UInt32, truncating after the decimal point, sending NaN to 0 and clamping out-of-range values and infinities.

πŸ”—def

Converts a UInt32 to an UnpackedFloat, returning positive zero on zero.

πŸ”—def

Converts an UnpackedFloat to a UInt64, truncating after the decimal point, sending NaN to 0 and clamping out-of-range values and infinities.

πŸ”—def

Converts a UInt64 to an UnpackedFloat, returning positive zero on zero.

πŸ”—def

Converts an UnpackedFloat to a USize, truncating after the decimal point, sending NaN to 0 and clamping out-of-range values and infinities.

πŸ”—def

Converts a USize to an UnpackedFloat, returning positive zero on zero.

Kernel Reasoning

The Lean kernel can compare expressions of type Float for syntactic equality, so 0.0 is definitionally equal to itself.

example : (0.0 : Float) = (0.0 : Float) := ⊒ 0.0 = 0.0 All goals completed! πŸ™

Additionally, terms that require reduction to become syntactically equal can be checked by the kernel when they use only operations that are modeled in Lean's logic:

example : (0.0 : Float) = (0.0 + 0.0 : Float) := ⊒ 0.0 = 0.0 + 0.0 All goals completed! πŸ™

The kernel cannot reduce terms that use operations that are not directly modeled, such as trigonometric functions:

example : (0.0 : Float).sin = (0.0 : Float) := ⊒ Float.sin 0.0 = 0.0 Tactic `rfl` failed: The left-hand side Float.sin 0.0 is not definitionally equal to the right-hand side 0.0 ⊒ Float.sin 0.0 = 0.0⊒ Float.sin 0.0 = 0.0
Tactic `rfl` failed: The left-hand side
  Float.sin 0.0
is not definitionally equal to the right-hand side
  0.0

⊒ Float.sin 0.0 = 0.0

However, the native_decide tactic can invoke the underlying platform's floating-point primitives that are used by Lean for run-time programs:

theorem Float.sin_zero_eq_zero : ((0.0 : Float).sin == (0.0 : Float)) = true := ⊒ (sin 0.0 == 0.0) = true All goals completed! πŸ™

This tactic executes a decision procedure as compiled native code. This requires trusting the Lean compiler, interpreter and the low-level implementations of built-in operators in addition to the kernel. To make this dependency precisely clear, the tactic creates the axiom Float.sin_zero_eq_zero._native.native_decide.ax_1:

'Float.sin_zero_eq_zero' depends on axioms: [propext, Classical.choice, Quot.sound, Float.sin_zero_eq_zero._native.native_decide.ax_1]#print axioms Float.sin_zero_eq_zero
'Float.sin_zero_eq_zero' depends on axioms: [propext,
 Classical.choice,
 Quot.sound,
 Float.sin_zero_eq_zero._native.native_decide.ax_1]
Floating-Point Equality Is Not Reflexive

Floating-point operations may produce NaN values that indicate an undefined result. These values are not comparable with each other; in particular, all comparisons involving NaN will return false, including equality.

false#eval ((0.0 : Float) / 0.0) == ((0.0 : Float) / 0.0)
Floating-Point Equality Is Not a Congruence

Applying a function to two equal floating-point numbers may not result in equal numbers. In particular, positive and negative zero are distinct values that are equated by floating-point equality, but division by positive or negative zero yields positive or negative infinite values.

def neg0 : Float := -0.0 def pos0 : Float := 0.0 (true, false)#eval (neg0 == pos0, 1.0 / neg0 == 1.0 / pos0)
(true, false)

20.6.2.Β SyntaxπŸ”—

Lean does not have dedicated floating-point literals. Instead, floating-point literals are resolved via the appropriate instances of the OfScientific and Neg type classes.

Floating-Point Literals

The term

(-2.523 : Float)

is syntactic sugar for

(Neg.neg (OfScientific.ofScientific 22523 true 4) : Float)

and the term

(413.52 : Float32)

is syntactic sugar for

(OfScientific.ofScientific 41352 true 2 : Float32)

20.6.3.Β API ReferenceπŸ”—

20.6.3.1.Β PropertiesπŸ”—

Floating-point numbers fall into one of three categories:

  • Finite numbers are ordinary floating-point values.

  • Infinities, which may be positive or negative, result from division by zero.

  • NaNs, which are not numbers, result from other undefined operations, such as the square root of a negative number.

πŸ”—def

Checks whether a floating-point number is a positive or negative infinite number, but not a finite number or NaN.

This function has a logical model in terms of Float.Model. It is compiled to the C operator isinf.

πŸ”—def

Checks whether a floating-point number is a positive or negative infinite number, but not a finite number or NaN.

This function has a logical model in terms of Float32.Model. It is compiled to the C operator isinf.

πŸ”—def

Checks whether a floating point number is NaN (β€œnot a number”) value.

NaN values result from operations that might otherwise be errors, such as dividing zero by zero.

This function has a logical model in terms of Float.Model. It is compiled to the C operator isnan.

πŸ”—def

Checks whether a floating point number is NaN ("not a number") value.

NaN values result from operations that might otherwise be errors, such as dividing zero by zero.

This function has a logical model in terms of Float32.Model. It is compiled to the C operator isnan.

πŸ”—def

Checks whether a floating-point number is finite, that is, whether it is normal, subnormal, or zero, but not infinite or NaN.

This function has a logical model in terms of Float.Model. It is compiled to the C operator isfinite.

πŸ”—def

Checks whether a floating-point number is finite, that is, whether it is normal, subnormal, or zero, but not infinite or NaN.

This function has a logical model in terms of Float32.Model. It is compiled to the C operator isfinite.

20.6.3.2.Β ConversionsπŸ”—

πŸ”—def

Bit-for-bit conversion to UInt64. Interprets a Float as a UInt64, ignoring the numeric value and treating the Float's bit pattern as a UInt64.

Floats and UInt64s have the same endianness on all supported platforms. IEEE 754 very precisely specifies the bit layout of floats.

This function is distinct from Float.toUInt64, which attempts to preserve the numeric value rather than reinterpreting the bit pattern.

πŸ”—def

Bit-for-bit conversion to UInt32. Interprets a Float32 as a UInt32, ignoring the numeric value and treating the Float32's bit pattern as a UInt32.

Float32s and UInt32s have the same endianness on all supported platforms. IEEE 754 very precisely specifies the bit layout of floats.

This function is distinct from Float.toUInt32, which attempts to preserve the numeric value rather than reinterpreting the bit pattern.

πŸ”—def

Bit-for-bit conversion from UInt64. Interprets a UInt64 as a Float, ignoring the numeric value and treating the UInt64's bit pattern as a Float.

Floats and UInt64s have the same endianness on all supported platforms. IEEE 754 very precisely specifies the bit layout of floats.

This function has a logical model in terms of Float.Model.

πŸ”—def

Bit-for-bit conversion from UInt32. Interprets a UInt32 as a Float32, ignoring the numeric value and treating the UInt32's bit pattern as a Float32.

Float32s and UInt32s have the same endianness on all supported platforms. IEEE 754 very precisely specifies the bit layout of floats.

This function has a logical model in terms of Float32.Model.

πŸ”—opaque

Converts a 64-bit floating-point number to a 32-bit floating-point number. This may lose precision.

This function does not reduce in the kernel.

πŸ”—opaque

Converts a 32-bit floating-point number to a 64-bit floating-point number.

This function does not reduce in the kernel.

πŸ”—opaque

Converts a floating-point number to a string.

This function does not reduce in the kernel.

πŸ”—opaque

Converts a floating-point number to a string.

This function does not reduce in the kernel.

πŸ”—def

Converts a floating-point number to an 8-bit unsigned integer.

If the given Float is non-negative, truncates the value to a positive integer, rounding down and clamping to the range of UInt8. Returns 0 if the Float is negative or NaN, and returns the largest UInt8 value (i.e. UInt8.size - 1) if the float is larger than it.

This function has a logical model in terms of Float.Model.

πŸ”—opaque

Truncates a floating-point number to the nearest 8-bit signed integer, rounding towards zero.

If the Float is larger than the maximum value for Int8 (including Inf), returns the maximum value of Int8 (i.e. Int8.maxValue). If it is smaller than the minimum value for Int8 (including -Inf), returns the minimum value of Int8 (i.e. Int8.minValue). If it is NaN, returns 0.

This function does not reduce in the kernel.

πŸ”—def

Converts a floating-point number to an 8-bit unsigned integer.

If the given Float32 is non-negative, truncates the value to a positive integer, rounding down and clamping to the range of UInt8. Returns 0 if the Float32 is negative or NaN, and returns the largest UInt8 value (i.e. UInt8.size - 1) if the float is larger than it.

This function has a logical model in terms of Float32.Model.

πŸ”—opaque

Truncates a floating-point number to the nearest 8-bit signed integer, rounding towards zero.

If the Float is larger than the maximum value for Int8 (including Inf), returns the maximum value of Int8 (i.e. Int8.maxValue). If it is smaller than the minimum value for Int8 (including -Inf), returns the minimum value of Int8 (i.e. Int8.minValue). If it is NaN, returns 0.

This function does not reduce in the kernel.

πŸ”—def

Converts a floating-point number to a 16-bit unsigned integer.

If the given Float is non-negative, truncates the value to a positive integer, rounding down and clamping to the range of UInt16. Returns 0 if the Float is negative or NaN, and returns the largest UInt16 value (i.e. UInt16.size - 1) if the float is larger than it.

This function has a logical model in terms of Float.Model.

πŸ”—opaque

Truncates a floating-point number to the nearest 16-bit signed integer, rounding towards zero.

If the Float is larger than the maximum value for Int16 (including Inf), returns the maximum value of Int16 (i.e. Int16.maxValue). If it is smaller than the minimum value for Int16 (including -Inf), returns the minimum value of Int16 (i.e. Int16.minValue). If it is NaN, returns 0.

This function does not reduce in the kernel.

πŸ”—def

Converts a floating-point number to a 16-bit unsigned integer.

If the given Float32 is non-negative, truncates the value to a positive integer, rounding down and clamping to the range of UInt16. Returns 0 if the Float32 is negative or NaN, and returns the largest UInt16 value (i.e. UInt16.size - 1) if the float is larger than it.

This function has a logical model in terms of Float32.Model.

πŸ”—opaque

Truncates a floating-point number to the nearest 16-bit signed integer, rounding towards zero.

If the Float is larger than the maximum value for Int16 (including Inf), returns the maximum value of Int16 (i.e. Int16.maxValue). If it is smaller than the minimum value for Int16 (including -Inf), returns the minimum value of Int16 (i.e. Int16.minValue). If it is NaN, returns 0.

This function does not reduce in the kernel.

πŸ”—def

Converts a floating-point number to a 32-bit unsigned integer.

If the given Float is non-negative, truncates the value to a positive integer, rounding down and clamping to the range of UInt32. Returns 0 if the Float is negative or NaN, and returns the largest UInt32 value (i.e. UInt32.size - 1) if the float is larger than it.

This function has a logical model in terms of Float.Model.

πŸ”—def

Converts a floating-point number to a 32-bit unsigned integer.

If the given Float32 is non-negative, truncates the value to a positive integer, rounding down and clamping to the range of UInt32. Returns 0 if the Float32 is negative or NaN, and returns the largest UInt32 value (i.e. UInt32.size - 1) if the float is larger than it.

This function has a logical model in terms of Float32.Model.

πŸ”—opaque

Truncates a floating-point number to the nearest 32-bit signed integer, rounding towards zero.

If the Float is larger than the maximum value for Int32 (including Inf), returns the maximum value of Int32 (i.e. Int32.maxValue). If it is smaller than the minimum value for Int32 (including -Inf), returns the minimum value of Int32 (i.e. Int32.minValue). If it is NaN, returns 0.

This function does not reduce in the kernel.

πŸ”—opaque

Truncates a floating-point number to the nearest 32-bit signed integer, rounding towards zero.

If the Float is larger than the maximum value for Int32 (including Inf), returns the maximum value of Int32 (i.e. Int32.maxValue). If it is smaller than the minimum value for Int32 (including -Inf), returns the minimum value of Int32 (i.e. Int32.minValue). If it is NaN, returns 0.

This function does not reduce in the kernel.

πŸ”—def

Converts a floating-point number to a 64-bit unsigned integer.

If the given Float is non-negative, truncates the value to a positive integer, rounding down and clamping to the range of UInt64. Returns 0 if the Float is negative or NaN, and returns the largest UInt64 value (i.e. UInt64.size - 1) if the float is larger than it.

This function has a logical model in terms of Float.Model.

πŸ”—opaque

Truncates a floating-point number to the nearest 64-bit signed integer, rounding towards zero.

If the Float is larger than the maximum value for Int64 (including Inf), returns the maximum value of Int64 (i.e. Int64.maxValue). If it is smaller than the minimum value for Int64 (including -Inf), returns the minimum value of Int64 (i.e. Int64.minValue). If it is NaN, returns 0.

This function does not reduce in the kernel.

πŸ”—def

Converts a floating-point number to a 64-bit unsigned integer.

If the given Float32 is non-negative, truncates the value to a positive integer, rounding down and clamping to the range of UInt64. Returns 0 if the Float32 is negative or NaN, and returns the largest UInt64 value (i.e. UInt64.size - 1) if the float is larger than it.

This function has a logical model in terms of Float32.Model.

πŸ”—opaque

Truncates a floating-point number to the nearest 64-bit signed integer, rounding towards zero.

If the Float is larger than the maximum value for Int64 (including Inf), returns the maximum value of Int64 (i.e. Int64.maxValue). If it is smaller than the minimum value for Int64 (including -Inf), returns the minimum value of Int64 (i.e. Int64.minValue). If it is NaN, returns 0.

This function does not reduce in the kernel.

πŸ”—def

Converts a floating-point number to a word-sized unsigned integer.

If the given Float is non-negative, truncates the value to a positive integer, rounding down and clamping to the range of USize. Returns 0 if the Float is negative or NaN, and returns the largest USize value (i.e. USize.size - 1) if the float is larger than it.

This function has a logical model in terms of Float.Model.

πŸ”—def

Converts a floating-point number to a word-sized unsigned integer.

If the given Float32 is non-negative, truncates the value to a positive integer, rounding down and clamping to the range of USize. Returns 0 if the Float32 is negative or NaN, and returns the largest USize value (i.e. USize.size - 1) if the float is larger than it.

This function has a logical model in terms of Float32.Model.

πŸ”—opaque

Truncates a floating-point number to the nearest word-sized signed integer, rounding towards zero.

If the Float is larger than the maximum value for ISize (including Inf), returns the maximum value of ISize (i.e. ISize.maxValue). If it is smaller than the minimum value for ISize (including -Inf), returns the minimum value of ISize (i.e. ISize.minValue). If it is NaN, returns 0.

This function does not reduce in the kernel.

πŸ”—opaque

Truncates a floating-point number to the nearest word-sized signed integer, rounding towards zero.

If the Float is larger than the maximum value for ISize (including Inf), returns the maximum value of ISize (i.e. ISize.maxValue). If it is smaller than the minimum value for ISize (including -Inf), returns the minimum value of ISize (i.e. ISize.minValue). If it is NaN, returns 0.

This function does not reduce in the kernel.

πŸ”—def

Converts an integer into the closest-possible 64-bit floating-point number, or positive or negative infinite floating-point value if the range of Float is exceeded.

πŸ”—def

Converts an integer into the closest-possible 32-bit floating-point number, or positive or negative infinite floating-point value if the range of Float32 is exceeded.

πŸ”—def

Converts a natural number into the closest-possible 64-bit floating-point number, or an infinite floating-point value if the range of Float is exceeded.

πŸ”—def

Converts a natural number into the closest-possible 32-bit floating-point number, or an infinite floating-point value if the range of Float32 is exceeded.

πŸ”—opaque

Splits the given float x into a significand/exponent pair (s, i) such that x = s * 2^i where s ∈ (-1;-0.5] βˆͺ [0.5; 1). Returns an undefined value if x is not finite.

This function does not reduce in the kernel. It is implemented in compiled code by the C function frexp.

πŸ”—opaque

Splits the given float x into a significand/exponent pair (s, i) such that x = s * 2^i where s ∈ (-1;-0.5] βˆͺ [0.5; 1). Returns an undefined value if x is not finite.

This function does not reduce in the kernel. It is implemented in compiled code by the C function frexp.

20.6.3.3.Β ComparisonsπŸ”—

πŸ”—def
Float.beq (a b : Float) : Bool
Float.beq (a b : Float) : Bool

Checks whether two floating-point numbers are equal according to IEEE 754.

Floating-point equality does not correspond with propositional equality. In particular, it is not reflexive since NaN != NaN, and it is not a congruence because 0.0 == -0.0, but 1.0 / 0.0 != 1.0 / -0.0.

This function does not reduce in the kernel. It is compiled to the C equality operator.

πŸ”—def

Checks whether two floating-point numbers are equal according to IEEE 754.

Floating-point equality does not correspond with propositional equality. In particular, it is not reflexive since NaN != NaN, and it is not a congruence because 0.0 == -0.0, but 1.0 / 0.0 != 1.0 / -0.0.

This function does not reduce in the kernel. It is compiled to the C equality operator.

20.6.3.3.1.Β InequalitiesπŸ”—

The decision procedures for inequalities are opaque constants in the logic. They can only be used via the Lean.ofReduceBool axiom, e.g. via the native_decide tactic.

πŸ”—def
Float.le : Float β†’ Float β†’ Bool
Float.le : Float β†’ Float β†’ Bool

Non-strict inequality of floating-point numbers. Typically used via the ≀ operator.

πŸ”—def
Float32.le : Float32 β†’ Float32 β†’ Bool
Float32.le : Float32 β†’ Float32 β†’ Bool

Non-strict inequality of floating-point numbers. Typically used via the ≀ operator.

πŸ”—def
Float.lt : Float β†’ Float β†’ Bool
Float.lt : Float β†’ Float β†’ Bool

Strict inequality of floating-point numbers. Typically used via the < operator.

πŸ”—def
Float32.lt : Float32 β†’ Float32 β†’ Bool
Float32.lt : Float32 β†’ Float32 β†’ Bool

Strict inequality of floating-point numbers. Typically used via the < operator.

πŸ”—def

Compares two floating point numbers for non-strict inequality.

This function does not reduce in the kernel. It is compiled to the C inequality operator.

πŸ”—def

Compares two floating point numbers for non-strict inequality.

This function does not reduce in the kernel. It is compiled to the C inequality operator.

πŸ”—def

Compares two floating point numbers for strict inequality.

This function does not reduce in the kernel. It is compiled to the C inequality operator.

πŸ”—def

Compares two floating point numbers for strict inequality.

This function does not reduce in the kernel. It is compiled to the C inequality operator.

20.6.3.4.Β ArithmeticπŸ”—

Arithmetic operations on floating-point values are typically invoked via the Add Float, Sub Float, Mul Float, Div Float, and HomogeneousPow Float instances, along with the corresponding Float32 instances.

πŸ”—def
Float.add : Float β†’ Float β†’ Float
Float.add : Float β†’ Float β†’ Float

Adds two 64-bit floating-point numbers according to IEEE 754. Typically used via the + operator.

This function has a logical model in terms of Float.Model. It is compiled to the C addition operator.

πŸ”—def

Adds two 32-bit floating-point numbers according to IEEE 754. Typically used via the + operator.

This function has a logical model in terms of Float32.Model. It is compiled to the C addition operator.

πŸ”—def
Float.sub : Float β†’ Float β†’ Float
Float.sub : Float β†’ Float β†’ Float

Subtracts 64-bit floating-point numbers according to IEEE 754. Typically used via the - operator.

This function has a logical model in terms of Float.Model. It is compiled to the C subtraction operator.

πŸ”—def

Subtracts 32-bit floating-point numbers according to IEEE 754. Typically used via the - operator.

This function has a logical model in terms of Float32.Model. It is compiled to the C subtraction operator.

πŸ”—def
Float.mul : Float β†’ Float β†’ Float
Float.mul : Float β†’ Float β†’ Float

Multiplies 64-bit floating-point numbers according to IEEE 754. Typically used via the * operator.

This function has a logical model in terms of Float.Model. It is compiled to the C multiplication operator.

πŸ”—def

Multiplies 32-bit floating-point numbers according to IEEE 754. Typically used via the * operator.

This function has a logical model in terms of Float32.Model. It is compiled to the C multiplication operator.

πŸ”—def
Float.div : Float β†’ Float β†’ Float
Float.div : Float β†’ Float β†’ Float

Divides 64-bit floating-point numbers according to IEEE 754. Typically used via the / operator.

In Lean, division by zero typically yields zero. For Float, it instead yields either Inf, -Inf, or NaN.

This function has a logical model in terms of Float.Model. It is compiled to the C division operator.

πŸ”—def

Divides 32-bit floating-point numbers according to IEEE 754. Typically used via the / operator.

In Lean, division by zero typically yields zero. For Float32, it instead yields either Inf, -Inf, or NaN.

This function has a logical model in terms of Float32.Model. It is compiled to the C division operator.

πŸ”—opaque
Float.pow : Float β†’ Float β†’ Float
Float.pow : Float β†’ Float β†’ Float

Raises one floating-point number to the power of another. Typically used via the ^ operator.

This function does not reduce in the kernel. It is implemented in compiled code by the C function pow.

πŸ”—opaque

Raises one floating-point number to the power of another. Typically used via the ^ operator.

This function does not reduce in the kernel. It is implemented in compiled code by the C function powf.

πŸ”—opaque

Computes the exponential e^x of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function exp.

πŸ”—opaque

Computes the exponential e^x of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function expf.

πŸ”—opaque

Computes the base-2 exponential 2^x of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function exp2.

πŸ”—opaque

Computes the base-2 exponential 2^x of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function exp2f.

20.6.3.4.1.Β RootsπŸ”—

Computing the square root of a negative number yields NaN.

πŸ”—def

Computes the square root of a floating-point number.

This function has a logical model in terms of Float.Model. It is implemented in compiled code by the C function sqrt.

πŸ”—def

Computes the square root of a floating-point number.

This function has a logical model in terms of Float32.Model. It is implemented in compiled code by the C function sqrtf.

πŸ”—opaque

Computes the cube root of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function cbrt.

πŸ”—opaque

Computes the cube root of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function cbrtf.

20.6.3.5.Β LogarithmsπŸ”—

πŸ”—opaque

Computes the natural logarithm ln x of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function log.

πŸ”—opaque

Computes the natural logarithm ln x of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function logf.

πŸ”—opaque

Computes the base-10 logarithm of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function log10.

πŸ”—opaque

Computes the base-10 logarithm of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function log10f.

πŸ”—opaque

Computes the base-2 logarithm of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function log2.

πŸ”—opaque

Computes the base-2 logarithm of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function log2f.

20.6.3.6.Β ScalingπŸ”—

πŸ”—opaque
Float.scaleB (x : Float) (i : Int) : Float
Float.scaleB (x : Float) (i : Int) : Float

Efficiently computes x * 2^i.

This function does not reduce in the kernel.

πŸ”—opaque

Efficiently computes x * 2^i.

This function does not reduce in the kernel.

20.6.3.7.Β RoundingπŸ”—

πŸ”—opaque

Rounds to the nearest integer, rounding away from zero at half-way points.

This function does not reduce in the kernel. It is implemented in compiled code by the C function round.

πŸ”—opaque

Rounds to the nearest integer, rounding away from zero at half-way points.

This function does not reduce in the kernel. It is implemented in compiled code by the C function roundf.

πŸ”—opaque

Computes the floor of a floating-point number, which is the largest integer that's no larger than the given number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function floor.

Examples:

πŸ”—opaque

Computes the floor of a floating-point number, which is the largest integer that's no larger than the given number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function floorf.

Examples:

πŸ”—opaque

Computes the ceiling of a floating-point number, which is the smallest integer that's no smaller than the given number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function ceil.

Examples:

πŸ”—opaque

Computes the ceiling of a floating-point number, which is the smallest integer that's no smaller than the given number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function ceilf.

Examples:

20.6.3.8.Β TrigonometryπŸ”—

20.6.3.8.1.Β SineπŸ”—

πŸ”—opaque

Computes the sine of a floating-point number in radians.

This function does not reduce in the kernel. It is implemented in compiled code by the C function sin.

πŸ”—opaque

Computes the sine of a floating-point number in radians.

This function does not reduce in the kernel. It is implemented in compiled code by the C function sinf.

πŸ”—opaque

Computes the hyperbolic sine of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function sinh.

πŸ”—opaque

Computes the hyperbolic sine of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function sinhf.

πŸ”—opaque

Computes the arc sine (inverse sine) of a floating-point number in radians.

This function does not reduce in the kernel. It is implemented in compiled code by the C function asin.

πŸ”—opaque

Computes the arc sine (inverse sine) of a floating-point number in radians.

This function does not reduce in the kernel. It is implemented in compiled code by the C function asinf.

πŸ”—opaque

Computes the hyperbolic arc sine (inverse sine) of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function asinh.

πŸ”—opaque

Computes the hyperbolic arc sine (inverse sine) of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function asinhf.

20.6.3.8.2.Β CosineπŸ”—

πŸ”—opaque

Computes the cosine of a floating-point number in radians.

This function does not reduce in the kernel. It is implemented in compiled code by the C function cos.

πŸ”—opaque

Computes the cosine of a floating-point number in radians.

This function does not reduce in the kernel. It is implemented in compiled code by the C function cosf.

πŸ”—opaque

Computes the hyperbolic cosine of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function cosh.

πŸ”—opaque

Computes the hyperbolic cosine of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function coshf.

πŸ”—opaque

Computes the arc cosine (inverse cosine) of a floating-point number in radians.

This function does not reduce in the kernel. It is implemented in compiled code by the C function acos.

πŸ”—opaque

Computes the arc cosine (inverse cosine) of a floating-point number in radians.

This function does not reduce in the kernel. It is implemented in compiled code by the C function acosf.

πŸ”—opaque

Computes the hyperbolic arc cosine (inverse cosine) of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function acosh.

πŸ”—opaque

Computes the hyperbolic arc cosine (inverse cosine) of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function acoshf.

20.6.3.8.3.Β TangentπŸ”—

πŸ”—opaque

Computes the tangent of a floating-point number in radians.

This function does not reduce in the kernel. It is implemented in compiled code by the C function tan.

πŸ”—opaque

Computes the tangent of a floating-point number in radians.

This function does not reduce in the kernel. It is implemented in compiled code by the C function tanf.

πŸ”—opaque

Computes the hyperbolic tangent of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function tanh.

πŸ”—opaque

Computes the hyperbolic tangent of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function tanhf.

πŸ”—opaque

Computes the arc tangent (inverse tangent) of a floating-point number in radians.

This function does not reduce in the kernel. It is implemented in compiled code by the C function atan.

πŸ”—opaque

Computes the arc tangent (inverse tangent) of a floating-point number in radians.

This function does not reduce in the kernel. It is implemented in compiled code by the C function atanf.

πŸ”—opaque

Computes the hyperbolic arc tangent (inverse tangent) of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function atanh.

πŸ”—opaque

Computes the hyperbolic arc tangent (inverse tangent) of a floating-point number.

This function does not reduce in the kernel. It is implemented in compiled code by the C function atanhf.

πŸ”—opaque

Computes the arc tangent (inverse tangent) of y / x in radians, in the range -π–π. The signs of the arguments determine the quadrant of the result.

This function does not reduce in the kernel. It is implemented in compiled code by the C function atan2.

πŸ”—opaque

Computes the arc tangent (inverse tangent) of y / x in radians, in the range -π–π. The signs of the arguments determine the quadrant of the result.

This function does not reduce in the kernel. It is implemented in compiled code by the C function atan2f.

20.6.3.9.Β Negation and Absolute ValueπŸ”—

πŸ”—def

Computes the absolute value of a floating-point number.

This function has a logical model in terms of Float.Model. It is implemented in compiled code by the C function fabs.

πŸ”—def

Computes the absolute value of a floating-point number.

This function has a logical model in terms of Float32.Model. It is implemented in compiled code by the C function fabsf.

πŸ”—def

Negates 64-bit floating-point numbers according to IEEE 754. Typically used via the - prefix operator.

This function has a logical model in terms of Float.Model. It is compiled to the C negation operator.

πŸ”—def

Negates 32-bit floating-point numbers according to IEEE 754. Typically used via the - prefix operator.

This function has a logical model in terms of Float32.Model. It is compiled to the C negation operator.