|
161 | 161 | [(list (or '+.f64 '+.f32) x-ex y-ex) |
162 | 162 | #:when (or (list? x-ex) (list? y-ex)) |
163 | 163 |
|
| 164 | + (define x (exacts-ref x-ex)) |
| 165 | + (define y (exacts-ref y-ex)) |
| 166 | + |
164 | 167 | (define xlog (lf-normalize (logfls-ref x-ex))) |
165 | 168 | (match-define (logfl xfl xs xe) xlog) |
166 | 169 | (define ylog (lf-normalize (logfls-ref y-ex))) |
167 | 170 | (match-define (logfl yfl ys ye) ylog) |
168 | 171 |
|
169 | | - (define cond-x (abs (/ xfl (+ xfl yfl)))) |
170 | | - (define cond-y (abs (/ yfl (+ xfl yfl)))) |
171 | 172 | (define cond-x.l (logabs (log/ xlog (log+ xlog ylog)))) |
172 | 173 | (define cond-y.l (logabs (log/ ylog (log+ xlog ylog)))) |
173 | 174 |
|
|
188 | 189 | ; nan rescue: |
189 | 190 | ; R(+-inf) + R(-+inf) = nan, but should actually |
190 | 191 | ; be inf |
191 | | - [(and (overflow? xlog) (overflow? ylog) (not (same-sign?* xfl yfl))) |
| 192 | + [(and (overflowed? xlog) (overflowed? ylog) (not (same-sign?* xfl yfl))) |
192 | 193 | (mark-erroneous! subexpr 'nan-rescue)] |
193 | 194 |
|
194 | 195 | ; inf rescue: |
195 | 196 | ; R(inf) + y = non inf value (inf rescue) |
196 | | - [(and (overflow? xlog) (<= (abs se) MAX-EXP)) (mark-erroneous! subexpr 'oflow-left)] |
197 | | - [(and (overflow? ylog) (<= (abs se) MAX-EXP)) (mark-erroneous! subexpr 'oflow-right)] |
| 197 | + [(and (overflowed? xlog) (not (overflowed? slog))) (mark-erroneous! subexpr 'oflow-left)] |
| 198 | + [(and (overflowed? ylog) (not (overflowed? slog))) (mark-erroneous! subexpr 'oflow-right)] |
198 | 199 |
|
199 | 200 | ; High condition number: |
200 | 201 | ; CN(+, x, y) = |x / x + y| |
|
231 | 232 |
|
232 | 233 | ; nan rescue: |
233 | 234 | ; inf - inf = nan but should actually get an inf |
234 | | - [(and (overflow? xlog) (overflow? ylog) (same-sign?* xfl yfl)) |
| 235 | + [(and (overflowed? xlog) (overflowed? ylog) (same-sign?* xfl yfl)) |
235 | 236 | (mark-erroneous! subexpr 'nan-rescue)] |
236 | 237 |
|
237 | 238 | ; inf rescue |
238 | 239 | ; If x or y overflow and the other arg rescues |
239 | 240 | ; it |
240 | | - [(and (overflow? xlog) (<= (abs se) MAX-EXP)) (mark-erroneous! subexpr 'oflow-left)] |
241 | | - [(and (overflow? ylog) (<= (abs se) MAX-EXP)) (mark-erroneous! subexpr 'oflow-right)] |
| 241 | + [(and (overflowed? xlog) (not (overflowed? slog))) (mark-erroneous! subexpr 'oflow-left)] |
| 242 | + [(and (overflowed? ylog) (not (overflowed? slog))) (mark-erroneous! subexpr 'oflow-right)] |
242 | 243 |
|
243 | 244 | ; High condition number: |
244 | 245 | ; CN(+, x, y) = |x / x - y| |
|
258 | 259 | (define cot-x.l (logabs (log/ 1.l (logtan xlog)))) |
259 | 260 | (define cond-no.l (log* (logabs xlog) cot-x.l)) |
260 | 261 | (cond |
261 | | - [(overflow? xlog) (mark-erroneous! subexpr 'oflow-rescue)] |
| 262 | + [(and (overflowed? xlog) (representable? slog)) (mark-erroneous! subexpr 'oflow-rescue)] |
262 | 263 |
|
263 | 264 | [(and (log> cond-no.l 100.l) (log> (logabs xlog) 100.l)) (mark-erroneous! subexpr 'sensitivity)] |
264 | 265 |
|
|
282 | 283 |
|
283 | 284 | (cond |
284 | 285 | ;[(and (bfinfinite? x) (not (bfnan? subexpr-val))) (mark-erroneous! subexpr 'oflow-rescue)] |
285 | | - [(overflow? xlog) (mark-erroneous! subexpr 'oflow-rescue)] |
| 286 | + [(and (overflowed? xlog) (representable? slog)) (mark-erroneous! subexpr 'oflow-rescue)] |
286 | 287 |
|
287 | 288 | ; [(and (bf> cond-no cond-thres) (bf> (bfabs x) cond-thres)) |
288 | 289 | ; (mark-erroneous! subexpr 'sensitivity)] |
|
317 | 318 | (define cond-no.l (log* (logabs xlog) cond-hlf.l)) |
318 | 319 |
|
319 | 320 | (cond |
320 | | - [(overflow? xlog) (mark-erroneous! subexpr 'oflow-rescue)] |
| 321 | + [(and (overflowed? xlog) (representable? slog)) (mark-erroneous! subexpr 'oflow-rescue)] |
321 | 322 | [(and (log> cond-no.l 100.l) (log> (logabs xlog) 100.l)) (mark-erroneous! subexpr 'sensitivity)] |
322 | 323 | [(and (log> cond-no.l 100.l) (log> cond-hlf.l 100.l)) (mark-erroneous! subexpr 'cancellation)] |
323 | 324 |
|
|
328 | 329 | [(list (or 'sqrt.f64 'sqrt.f32) x-ex) |
329 | 330 | #:when (list? x-ex) |
330 | 331 | (define xlog (logfls-ref x-ex)) |
| 332 | + (define x (bigfloat->flonum (exacts-ref x-ex))) |
331 | 333 | (match-define (logfl xfl xs xe) xlog) |
332 | 334 |
|
333 | 335 | (cond |
334 | | - [(and (underflow? xlog) (< (/ (abs xe) 2.0) MAX-EXP)) |
335 | | - (mark-erroneous! subexpr 'uflow-rescue)] |
336 | 336 | ;; Underflow rescue: |
| 337 | + [(and (underflowed? xlog) (not (underflowed? slog))) |
| 338 | + (mark-erroneous! subexpr 'uflow-rescue)] |
337 | 339 |
|
338 | 340 | ;; Overflow rescue: |
339 | | - [(and (overflow? xlog) (< (/ (abs xe) 2.0) MAX-EXP)) |
340 | | - (mark-erroneous! subexpr 'oflow-rescue)])] |
| 341 | + [(and (overflowed? xlog) (not (overflowed? slog))) |
| 342 | + (mark-erroneous! subexpr 'oflow-rescue)] |
| 343 | + [else #f])] |
341 | 344 |
|
342 | 345 | [(list (or 'cbrt.f64 'cbrt.f32) x-ex) |
343 | 346 | #:when (list? x-ex) |
|
348 | 351 | (cond |
349 | 352 | ;; Underflow rescue: |
350 | 353 | ;; [(and (bfzero? x) (not (bf= subexpr-val x))) (mark-erroneous! subexpr 'uflow-rescue)] |
351 | | - [(and (underflow? xlog) (< (/ (abs xe) 2.0) MAX-EXP)) |
| 354 | + [(and (underflowed? xlog) (not (underflowed? slog))) |
352 | 355 | (mark-erroneous! subexpr 'uflow-rescue)] |
353 | 356 |
|
354 | 357 | ;; Overflow rescue: |
355 | 358 | ;;[(and (bfinfinite? x) (not (bf= subexpr-val x))) (mark-erroneous! subexpr 'oflow-rescue)])] |
356 | | - [(and (overflow? xlog) (< (/ (abs xe) 2.0) MAX-EXP)) |
| 359 | + [(and (overflowed? xlog) (not (overflowed? slog))) |
357 | 360 | (mark-erroneous! subexpr 'oflow-rescue)])] |
358 | 361 |
|
359 | 362 | [(list (or '/.f64 '/.f32) x-ex y-ex) |
|
368 | 371 | (cond |
369 | 372 | ;; if the numerator underflows and the denominator: |
370 | 373 | ;; - underflows, nan could be rescued |
371 | | - [(and (underflow? xlog) (underflow? ylog)) (mark-erroneous! subexpr 'u/u)] |
| 374 | + [(and (underflowed? xlog) (underflowed? ylog) (representable? slog)) |
| 375 | + (mark-erroneous! subexpr 'u/u)] |
372 | 376 | ;; - is small enough, 0 underflow could be rescued |
373 | | - [(and (underflow? xlog) (<= (abs (- xe ye)) MAX-EXP)) (mark-erroneous! subexpr 'u/n)] |
| 377 | + [(and (underflowed? xlog) (representable? slog)) (mark-erroneous! subexpr 'u/n)] |
374 | 378 | ;; - overflows, no rescue is possible |
375 | 379 |
|
376 | 380 | ;; if the numerator overflows and the denominator: |
377 | 381 | ;; - overflows, nan could be rescued |
378 | | - [(and (overflow? xlog) (overflow? ylog)) (mark-erroneous! subexpr 'o/o)] |
| 382 | + [(and (overflowed? xlog) (overflowed? ylog) (representable? slog)) (mark-erroneous! subexpr 'o/o)] |
379 | 383 | ;; - is large enough, inf overflow can be rescued |
380 | | - [(and (overflow? xlog) (<= (abs (- xe ye)) MAX-EXP)) (mark-erroneous! subexpr 'o/n)] |
| 384 | + [(and (overflowed? xlog) (representable? slog)) (mark-erroneous! subexpr 'o/n)] |
381 | 385 | ;; - underflow, no rescue is possible |
382 | 386 |
|
383 | 387 | ;; if the numerator is normal and the denominator: |
384 | 388 | ;; - overflows, then a rescue is possible |
385 | 389 | ; [(and (bfinfinite? y) (not (bfzero? subexpr-val))) (mark-erroneous! subexpr 'n/o)] |
386 | | - [(and (overflow? ylog) (<= (abs (- xe ye)) MAX-EXP)) (mark-erroneous! subexpr 'n/o)] |
| 390 | + [(and (overflowed? ylog) (representable? slog)) (mark-erroneous! subexpr 'n/o)] |
387 | 391 | ;; - underflows, then a rescue is possible |
388 | 392 | ;; [(and (bfzero? y) (not (bfinfinite? subexpr-val))) (mark-erroneous! subexpr 'n/u)] |
389 | | - [(and (underflow? ylog) (<= (abs (- xe ye)) MAX-EXP)) (mark-erroneous! subexpr 'n/u)] |
| 393 | + [(and (underflowed? ylog) (representable? slog)) (mark-erroneous! subexpr 'n/u)] |
390 | 394 | ;; - is normal, then no rescue is possible |
391 | 395 | [else #f])] |
392 | 396 |
|
|
402 | 406 | (cond |
403 | 407 | ;; if one operand underflows and the other overflows, then nan must |
404 | 408 | ;; be rescued. |
405 | | - [(and (overflow? xlog) (underflow? ylog)) (mark-erroneous! subexpr 'o*u)] |
406 | | - [(and (underflow? xlog) (overflow? ylog)) (mark-erroneous! subexpr 'o*u)] |
| 409 | + [(and (overflowed? xlog) (underflowed? ylog) (representable? slog)) (mark-erroneous! subexpr 'o*u)] |
| 410 | + [(and (underflowed? xlog) (overflowed? ylog) (representable? slog)) (mark-erroneous! subexpr 'o*u)] |
407 | 411 |
|
408 | 412 | ;; If one operand is normal and the other overflows then, inf rescue |
409 | 413 | ;; could occur |
410 | | - [(and (or (overflow? xlog) (overflow? ylog)) (<= (abs (+ xe ye)) MAX-EXP)) |
| 414 | + [(and (or (overflowed? xlog) (overflowed? ylog)) (representable? slog)) |
411 | 415 | (mark-erroneous! subexpr 'n*o)] |
412 | | - [(and (or (underflow? xlog) (underflow? ylog)) (<= (abs (+ xe ye)) MAX-EXP)) |
| 416 | + [(and (or (underflowed? xlog) (underflowed? ylog)) (representable? slog)) |
413 | 417 | (mark-erroneous! subexpr 'n*u)] |
414 | 418 | ;; If both normal then no error |
415 | 419 | [else #f])] |
|
419 | 423 | (define x (exacts-ref x-ex)) |
420 | 424 | (define xlog (logfls-ref x-ex)) |
421 | 425 | (match-define (logfl xfl xs xe) xlog) |
422 | | - (define cond-num.l (logabs (log/ 1.l xlog))) |
423 | | - (define cond-num (abs (/ 1.0 xfl))) |
| 426 | + (define cond-num.l (logabs (log/ 1.l (logln xlog)))) |
| 427 | + (define cond-num (abs (/ 1.0 (log xfl)))) |
424 | 428 |
|
425 | 429 | (cond |
426 | 430 | ; Condition number hallucination: |
|
429 | 433 | ; [(and (bf= x 1.bf) (bfzero? subexpr-val)) #f] |
430 | 434 |
|
431 | 435 | ; overflow rescue: |
432 | | - [(overflow? xlog) (mark-erroneous! subexpr 'oflow-rescue)] |
| 436 | + [(and (overflowed? xlog) (representable? slog)) (mark-erroneous! subexpr 'oflow-rescue)] |
433 | 437 |
|
434 | 438 | ; underflow rescue: |
435 | | - [(underflow? xlog) (mark-erroneous! subexpr 'uflow-rescue)] |
| 439 | + [(and (underflowed? xlog) (representable? slog)) (mark-erroneous! subexpr 'uflow-rescue)] |
436 | 440 |
|
437 | 441 | ; High Condition Number: |
438 | 442 | ; CN(log, x) = |1 / log(x)| |
|
455 | 459 | ; Condition Number Hallucination: |
456 | 460 | ; When x is large enough (negative) that exp(x) |
457 | 461 | ; underflows, condition number is also high |
458 | | - [(and (> (abs (* xfl (fllog2 euler.0))) MAX-EXP)) #f] |
| 462 | + [(not (representable? slog)) #f] |
459 | 463 |
|
460 | 464 | ; High Condition Number: |
461 | 465 | ; CN(exp, x) = |x| |
|
502 | 506 | ;; Hallucination: |
503 | 507 | ;; if x is large enough that x^y overflows, the condition number also |
504 | 508 | ;; is very large, but the answer correctly overflows |
505 | | - [(and (> yfl 1.0) (overflow? slog)) #f] |
| 509 | + [(and (> yfl 1.0) (overflowed? slog)) #f] |
506 | 510 |
|
507 | 511 | ;[(and (bf< y -1.bf) (zero? x^y) (bfzero? subexpr-val)) #f] |
508 | | - [(and (< yfl -1.0) (overflow? slog)) #f] |
| 512 | + [(and (< yfl -1.0) (overflowed? slog)) #f] |
509 | 513 |
|
510 | 514 | ;; if x is small enough and y is large enough that x^y underflows, |
511 | 515 | ;; the condition number also gets very large, but the answer |
512 | 516 | ;; correctly underflows |
513 | 517 | ;[(and (bf> y 1.bf) (zero? x^y) (bfzero? subexpr-val)) #f] |
514 | | - [(and (> yfl 1.0) (underflow? slog)) #f] |
| 518 | + [(and (> yfl 1.0) (underflowed? slog)) #f] |
515 | 519 |
|
516 | 520 | ;[(and (bf< y -1.bf) (infinite? x^y) (bfinfinite? subexpr-val)) #f] |
517 | | - [(and (< yfl -1.0) (underflow? slog)) #f] |
| 521 | + [(and (< yfl -1.0) (underflowed? slog)) #f] |
518 | 522 |
|
519 | | - [(and (underflow? xlog) (<= se MAX-EXP)) (mark-erroneous! subexpr 'uflow-rescue)] |
| 523 | + [(and (underflowed? xlog) (representable? slog)) (mark-erroneous! subexpr 'uflow-rescue)] |
520 | 524 |
|
521 | | - [(and (overflow? xlog) (<= se MAX-EXP)) (mark-erroneous! subexpr 'oflow-rescue)] |
| 525 | + [(and (overflowed? xlog) (representable? slog)) (mark-erroneous! subexpr 'oflow-rescue)] |
522 | 526 |
|
523 | 527 | [(and (or (log> cond-x.l 100.l) (log> cond-y.l 100.l)) (not (constant? y-ex))) |
524 | 528 | (mark-erroneous! subexpr 'sensitivity)] |
|
679 | 683 | (for/list ([(pt _) (in-pcontext pcontext)]) |
680 | 684 | (define error-actual? (> (hash-ref actual-error pt) 16)) |
681 | 685 | (define error-predicted? (hash-ref predicted-error pt false)) |
| 686 | + #;(when (and error-predicted? error-actual?) |
| 687 | + (printf "true-pos ~a\n" pt)) |
682 | 688 | #;(when (and error-predicted? (not error-actual?)) |
683 | | - (eprintf "~a\n" pt)) |
| 689 | + (printf "false-pos ~a\n" pt)) |
684 | 690 | (cons error-actual? error-predicted?))) |
685 | 691 |
|
686 | 692 | (define groups (group-by identity outcomes)) |
|
0 commit comments