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 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541
|
;; Cuong Chau <cuong.chau@arm.com>
;; January 2021
;; This book analyzes function NORMALIZE.
(in-package "RTL")
(include-book "special")
(local (arith-5-for-rtl))
(local
(in-theory (disable acl2::reduce-multiplicative-constant-<
acl2::integerp-<-constant
acl2::|(< x (/ y)) with (< 0 y)|
neg-bitn-0
acl2::simplify-products-gather-exponents-<)))
;; ======================================================================
(defundd a () (decode (opaw) (f)))
(defundd b () (decode (opbw) (f)))
(defthm nonzero-a
(implies (not (specialp))
(not (equal (a) 0)))
:hints (("Goal" :in-theory (enable specialp
a
opaw
fmtw
decode
ddecode
ndecode
expf
manf
f
classa
analyze))))
(defthm nonzero-b
(implies (not (specialp))
(not (equal (b) 0)))
:hints (("Goal" :in-theory (enable specialp
b
opbw
fmtw
decode
ddecode
ndecode
expf
manf
f
classb
analyze))))
(bvecthm bvecp-expa
(bvecp (expa) (expw (f)))
:hints (("Goal" :in-theory (enable expa f analyze))))
(defthm expa-upper-bounds
(and (implies (equal (fnum) 1)
(< (expa) *2^5*))
(implies (equal (fnum) 2)
(< (expa) *2^8*))
(implies (equal (fnum) 3)
(< (expa) *2^11*)))
:hints (("Goal"
:use bvecp-expa
:in-theory (enable f)))
:rule-classes :linear)
(bvecthm bvecp-expb
(bvecp (expb) (expw (f)))
:hints (("Goal" :in-theory (enable expb f analyze))))
(defthm expb-upper-bounds
(and (implies (equal (fnum) 1)
(< (expb) *2^5*))
(implies (equal (fnum) 2)
(< (expb) *2^8*))
(implies (equal (fnum) 3)
(< (expb) *2^11*)))
:hints (("Goal"
:use bvecp-expb
:in-theory (enable f)))
:rule-classes :linear)
(bvecthm bvecp-mana
(bvecp (mana) (sigw (f)))
:hints (("Goal" :in-theory (enable mana f analyze))))
(defthm mana-upper-bounds
(and (implies (equal (fnum) 1)
(< (mana) *2^10*))
(implies (equal (fnum) 2)
(< (mana) *2^23*))
(implies (equal (fnum) 3)
(< (mana) *2^52*)))
:hints (("Goal"
:use bvecp-mana
:in-theory (enable f)))
:rule-classes :linear)
(bvecthm bvecp-manb
(bvecp (manb) (sigw (f)))
:hints (("Goal" :in-theory (enable manb f analyze))))
(defthm manb-upper-bounds
(and (implies (equal (fnum) 1)
(< (manb) *2^10*))
(implies (equal (fnum) 2)
(< (manb) *2^23*))
(implies (equal (fnum) 3)
(< (manb) *2^52*)))
:hints (("Goal"
:use bvecp-manb
:in-theory (enable f)))
:rule-classes :linear)
(bvecthm bvecp53-siga
(bvecp (siga) 53)
:hints (("Goal" :in-theory (enable siga normalize))))
(bvecthm bvecp53-sigb
(bvecp (sigb) 53)
:hints (("Goal" :in-theory (enable sigb normalize))))
(defthm natp-expashft
(natp (expashft))
:hints (("Goal" :in-theory (enable expashft)))
:rule-classes :type-prescription)
(defthm natp-expbshft
(natp (expbshft))
:hints (("Goal" :in-theory (enable expbshft)))
:rule-classes :type-prescription)
(bvecthm bvecp13-expq-1
(bvecp (expq-1) 13)
:hints (("Goal" :in-theory (enable expq-1 normalize))))
(defthm bs-rewrite
(equal (bs) (bias (f)))
:hints (("Goal" :in-theory (enable bs f))))
(defthm natp-bias
(natp (bias (f)))
:hints (("Goal" :in-theory (enable f)))
:rule-classes :type-prescription)
(local
(def-gl-rule clz53-expo
:hyp (and (bvecp x 53) (not (equal x 0)))
:concl (equal (clz53 x) (- 52 (expo x)))
:disabledp t
:g-bindings (gl::auto-bindings
(:nat x 53))))
(local
(defthm aux-1
(implies (and (rationalp x)
(not (equal x 0)))
(and (equal (expo (* *2^29* x))
(+ 29 (expo x)))
(equal (expo (* *2^42* x))
(+ 42 (expo x)))))
:hints (("Goal"
:use ((:instance expo-shift
(n 29))
(:instance expo-shift
(n 42)))
:in-theory (disable expo-shift)))))
(local
(defthm aux-2-hp
(implies (and (< (abs x) *2^10*)
(rationalp x))
(<= (expo x) 10))
:hints (("Goal" :use (:instance expo-monotone
(y *2^10*))))
:rule-classes :linear))
(local
(defthm aux-2-sp
(implies (and (< (abs x) *2^23*)
(rationalp x))
(<= (expo x) 23))
:hints (("Goal" :use (:instance expo-monotone
(y *2^23*))))
:rule-classes :linear))
(local
(defthm aux-2-dp
(implies (and (< (abs x) *2^52*)
(rationalp x))
(<= (expo x) 52))
:hints (("Goal" :use (:instance expo-monotone
(y *2^52*))))
:rule-classes :linear))
(local
(defthm-nl aux-3
(implies (bvecp x 52)
(equal (bits (* x (expt 2 (+ 52 (- (expo x)))))
52 0)
(* x (expt 2 (+ 52 (- (expo x)))))))
:hints (("Goal"
:use (aux-2-dp
expo-upper-bound)
:in-theory (enable bvecp)))))
(defthmd spec-fields
(and (equal (signa) (sgnf (opaw) (f)))
(equal (expa) (expf (opaw) (f)))
(equal (mana) (manf (opaw) (f)))
(equal (signb) (sgnf (opbw) (f)))
(equal (expb) (expf (opbw) (f)))
(equal (manb) (manf (opbw) (f))))
:hints (("Goal"
:in-theory (enable sgnf
expf
manf
opaw
opbw
fmtw
f
signa
signb
expa
expb
mana
manb
si
bitn-bits
analyze))))
;; a
(local
(defthmd abs-a-rewrite
(implies (not (specialp))
(equal (abs (a))
(* (expt 2 (+ (si (expashft) 13) (- (bias (f))) -52))
(siga))))
:hints (("Goal"
:in-theory (e/d (specialp
a
expashft
siga
siga-1
f
opaw
fmtw
expa
expf
mana
manf
classa
decode
ddecode
ndecode
clz53-expo
cat
si
bvecp
analyze
normalize)
(acl2::|(expt x (if a b c))|
acl2::default-expt-2
acl2::default-plus-1
acl2::default-plus-2
acl2::default-times-1
acl2::default-times-2))))))
(local
(defthmd si-expashft-aux-1
(implies (and (not (specialp))
(equal x (opaw))
(equal f (f))
(equal (expf x f) 0))
(denormp x f))
:hints (("Goal" :in-theory (enable specialp
denormp
opaw
fmtw
f
classa
expf
manf
encodingp
analyze)))))
(local
(defthmd si-expashft-aux-2
(implies (and (not (specialp))
(equal x (opaw))
(equal f (f))
(not (equal (expf x f) 0)))
(normp x f))
:hints (("Goal" :in-theory (enable specialp
normp
opaw
fmtw
f
classa
expf
manf
encodingp
analyze)))))
(local
(defthmd si-expashft
(implies (not (specialp))
(equal (si (expashft) 13)
(+ (expo (a)) (bias (f)))))
:hints (("Goal"
:in-theory (enable specialp
expashft
a
si
f
opaw
fmtw
expa
mana
classa
siga-1
decode
expf
manf
clz53-expo
si-expashft-aux-1
si-expashft-aux-2
cat
bvecp
analyze
normalize)))))
(defthmd siga-rewrite
(implies (not (specialp))
(equal (siga) (* *2^52* (sig (a)))))
:hints (("Goal"
:use abs-a-rewrite
:in-theory (e/d (si-expashft
fp-abs-rewrite)
(abs)))))
;; b
(local
(defthmd abs-b-rewrite
(implies (not (specialp))
(equal (abs (b))
(* (expt 2 (+ (si (expbshft) 13) (- (bias (f))) -52))
(sigb))))
:hints (("Goal"
:in-theory (e/d (specialp
b
expbshft
sigb
sigb-1
f
opbw
fmtw
expb
expf
manb
manf
classb
decode
ddecode
ndecode
clz53-expo
cat
si
bvecp
analyze
normalize)
(acl2::|(expt x (if a b c))|
acl2::default-expt-2
acl2::default-plus-1
acl2::default-plus-2
acl2::default-times-1
acl2::default-times-2))))))
(local
(defthmd si-expbshft-aux-1
(implies (and (not (specialp))
(equal x (opbw))
(equal f (f))
(equal (expf x f) 0))
(denormp x f))
:hints (("Goal" :in-theory (enable specialp
denormp
opbw
fmtw
f
classb
expf
manf
encodingp
analyze)))))
(local
(defthmd si-expbshft-aux-2
(implies (and (not (specialp))
(equal x (opbw))
(equal f (f))
(not (equal (expf x f) 0)))
(normp x f))
:hints (("Goal" :in-theory (enable specialp
normp
opbw
fmtw
f
classb
expf
manf
encodingp
analyze)))))
(local
(defthmd si-expbshft
(implies (not (specialp))
(equal (si (expbshft) 13)
(+ (expo (b)) (bias (f)))))
:hints (("Goal"
:in-theory (enable specialp
expbshft
b
si
f
opbw
fmtw
expb
manb
classb
sigb-1
decode
expf
manf
clz53-expo
si-expbshft-aux-1
si-expbshft-aux-2
cat
bvecp
analyze
normalize)))))
(defthmd sigb-rewrite
(implies (not (specialp))
(equal (sigb) (* *2^52* (sig (b)))))
:hints (("Goal"
:use abs-b-rewrite
:in-theory (e/d (si-expbshft
fp-abs-rewrite)
(abs)))))
;; |a/b|
(local
(defthmd si-expq-1-rewrite
(equal (si (expq-1) 13)
(+ (si (expashft) 13)
(- (si (expbshft) 13))
(bias (f))))
:hints (("Goal" :in-theory (enable expq-1
expashft
expbshft
f
si
siga-1
sigb-1
normalize
bvecp)))))
(local
(defthm si-expashft-bounds
(implies (not (specialp))
(and (<= -51 (si (expashft) 13))
(< (si (expashft) 13) *2^11*)))
:hints (("Goal" :in-theory (e/d (specialp
expashft
si
siga-1
expa
mana
classa
cat
bvecp
clz53-expo
analyze)
(acl2::default-less-than-1))))
:rule-classes :linear))
(local
(defthm si-expbshft-bounds
(implies (not (specialp))
(and (<= -51 (si (expbshft) 13))
(< (si (expbshft) 13) *2^11*)))
:hints (("Goal" :in-theory (e/d (specialp
expbshft
si
sigb-1
expb
manb
classb
cat
bvecp
clz53-expo
analyze)
(acl2::default-less-than-1))))
:rule-classes :linear))
(defthm si-expq-1-bounds
(implies (not (specialp))
(and (<= -2083 (si (expq-1) 13))
(<= (si (expq-1) 13) 3121)))
:hints (("Goal" :in-theory (enable si-expq-1-rewrite f)))
:rule-classes :linear)
(local
(defthm aux-4
(implies (and (rationalp x)
(rationalp y))
(equal (abs (/ x y))
(/ (abs x) (abs y))))))
(defthmd quotient-formula
(implies (not (specialp))
(equal (abs (/ (a) (b)))
(* (expt 2 (- (si (expq-1) 13) (bias (f))))
(/ (siga) (sigb)))))
:hints (("Goal"
:in-theory (e/d (abs-a-rewrite
abs-b-rewrite
si-expq-1-rewrite)
(abs)))))
|