Skip to content

Commit b349978

Browse files
fix: improve new Float content based on feedback from Julia (#875)
1 parent d7ff436 commit b349978

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

Manual/BasicTypes/Float.lean

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,41 @@ tag := "Float"
2525

2626
Floating-point numbers are a an approximation of the real numbers that are efficiently implemented in computer hardware.
2727
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.
28-
The IEEE 754 standard, which defines the floating-point format that is used on modern computers, allows hardware designers to make certain choices, and real systems differ in these small details.
28+
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.
29+
Any given combination of hardware, operating system, C compiler, library versions, and even compilation flags can result in different behavior.
2930
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 `NaN`s.
3031

3132
To enable reasoning about floating-point numbers, Lean exposes a logical model of {name}`Float` that is used in proofs.
33+
In particular, {name}`Float` and {name}`Float32` are implemented as wrappers around the logical model.
3234
In compiled code, this logical model is replaced by efficient native code.
3335
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.
3436
Other operations, such as trigonometric functions, are represented as opaque functions in Lean's logic.
3537

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

41+
{docstring Float}
42+
43+
{docstring Float32}
3944

4045
# Logical Model
4146

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

45-
{docstring Float}
46-
47-
{docstring Float32}
48-
4950
## Model Details
5051

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

5759
This model is not intended to serve as the basis for a more extensive floating-point library.
5860
It exists only to support the reasoning tools available in Lean and is not suitable for larger-scale development.
59-
To implement 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.
61+
Do not use this model as the basis of a more extensive floating-point library.
62+
Instead, implement a suitable model, prove the equivalence of the its operations to this model, and then transfer lemmas using the equivalence.
6063

6164
{docstring Float.Model}
6265

0 commit comments

Comments
 (0)