-
Notifications
You must be signed in to change notification settings - Fork 1
/
lecture4.v
224 lines (153 loc) · 7.15 KB
/
lecture4.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
(******************************************************************************)
(* *)
(* LECTURE : Floating-point numbers and formal proof *)
(* Laurent.Thery@inria.fr 12/06/2016 *)
(* *)
(******************************************************************************)
(*
we present the notion of ulp and the concrete IEEE 754 format
*)
Require Import Psatz ZArith Reals SpecFloat.
From Flocq Require Import FTZ Core Operations BinarySingleNaN Binary Bits.
Open Scope R_scope.
Section Lecture4.
(* Variables for our examples *)
Variable vx vy : R.
(* Basis *)
Variable r : radix.
(* Translating funtion for the exponent *)
Variable phi : Z -> Z.
Hypothesis vPhi : Valid_exp phi.
(* Rounding function *)
Variable rnd : R -> Z.
Hypothesis vRound : Valid_rnd rnd.
(* Choice function *)
Variable choice : Z -> bool.
Check ulp r phi vx.
Eval lazy beta delta [ulp] in ulp r phi vx.
Eval lazy beta delta [ulp cexp] in ulp r phi vx.
Check ulp_neq_0.
(*
Prove that if phi is monotone so is ulp
Fact ex1 x y :
x <> 0 -> Monotone_exp phi -> Rabs x <= Rabs y -> ulp r phi x <= ulp r phi y.
Hints:
Check mag_le_abs.
Check bpow_le.
*)
Check round_UP_DN_ulp.
Check round_UP_DN_ulp r phi vx.
(*
Reprove round_UP_DN_ulp
Fact ext2 x :
~ generic_format r phi x ->
round r phi Zceil x = round r phi Zfloor x + ulp r phi x.
Hints:
Check scaled_mantissa_mult_bpow.
Check Zceil_floor_neq.
Check Ztrunc_IZR.
*)
Check error_lt_ulp.
(*
Reprove error_lt_ulp :
Fact ext3 x : x <> 0 -> Rabs (round r phi rnd x - x) < ulp r phi x.
Hints :
Check round_DN_UP_lt.
Check round_DN_or_UP.
Check round_UP_DN_ulp.
*)
Check error_le_half_ulp.
(*
Reprove error_le_half_ulp :
Fact ext4 x :
Rabs (round r phi (Znearest choice) x - x) <= / 2 * ulp r phi x.
Hints:
Check round_N_pt.
Check generic_format_round.
Check round_DN_UP_lt.
Check round_DN_or_UP.
Check round_UP_DN_ulp.
*)
(* The IEEE 754 norm *)
(* Simple precision *)
Check binary32.
(* Addition *)
Check b32_plus.
(* Rounding mode *)
Print mode.
(* Double precision *)
Check binary64.
(* Addition *)
Check b64_plus.
(* Two instances of a generic construct *)
Print binary32.
Print binary64.
Check binary_float.
(* Generic float *)
(* Variables for the precision and the exponent range *)
Variable vp ve : Z.
(* A float : a sign, a mantissa, an exponent *)
Variable s : bool.
Variable m : positive.
Variable e : Z.
Variable H : bounded vp ve m e = true.
Let f := B754_finite vp ve s m e H.
Check f.
Check is_finite vp ve.
Compute is_finite vp ve f.
(* Checking bound *)
Eval lazy beta zeta iota delta [bounded] in
(bounded vp ve m e).
(* Test on the mantissa *)
Check canonical_canonical_mantissa vp ve s m e.
Print canonical.
Print cexp.
(* Infinity *)
(* + inf *)
Let p_inf := B754_infinity vp ve false.
Check p_inf.
(* - inf *)
Let n_inf := B754_infinity vp ve true.
Check n_inf.
(* Zero *)
(* + zero *)
Let p_z := B754_zero vp ve false.
Check p_z.
(* - zero *)
Let n_z := B754_zero vp ve false.
Check n_z.
(* Nan *)
(* Pay load for Nan *)
Variable pl : positive.
Check nan_pl vp pl.
Eval lazy beta delta [nan_pl] in nan_pl vp pl.
Variable plT : nan_pl vp pl = true.
Let na := B754_nan vp ve s pl plT.
Check is_nan vp ve.
Compute is_nan vp ve.
(* From binary to R *)
Check B2R vp ve f.
Eval lazy beta iota zeta delta [B2R f] in B2R vp ve f.
Eval lazy beta iota zeta delta [B2R f cond_Zopp] in B2R vp ve f.
(* Opposite *)
Check Bopp vp ve.
Eval lazy beta delta [Bopp] in Bopp vp ve.
(* Instantiation for single precision *)
Print b32_opp.
(* Involutive *)
Check Bopp_involutive vp ve.
(* Value *)
Check B2R_Bopp vp ve.
(* Translating rounding modes *)
Check round_mode.
Print round_mode.
(* Addition *)
Check Bplus vp ve.
Eval lazy beta delta [Bplus] in Bplus vp ve.
(* Instantiation for single precision *)
Print b32_plus.
Print binop_nan_pl32.
Search Bplus.
(* Involutive *)
Check Bplus_correct vp ve.
End Lecture4.