|
138 | 138 | (define (mk-ival x) |
139 | 139 | (mk-big-ival x x)) |
140 | 140 |
|
141 | | -(define (and-fn . as) |
142 | | - (andmap identity as)) |
143 | | -(define (or-fn . as) |
144 | | - (ormap identity as)) |
145 | | - |
146 | 141 | (define (ival-pi) |
147 | 142 | (define-values (lo hi) (make-endpoint-pair)) |
148 | 143 | (mpfr-const-pi! lo 'down) |
|
214 | 209 | (or (ival-err? x) (ival-err? y)) |
215 | 210 | (and (ival-err x) (ival-err y)))] |
216 | 211 | [(boolean? (ival-lo-val x)) |
217 | | - (ival (epfn and-fn (ival-lo x) (ival-lo y)) |
218 | | - (epfn or-fn (ival-hi x) (ival-hi y)) |
219 | | - (or (ival-err? x) (ival-err? y)) |
220 | | - (and (ival-err x) (ival-err y)))])) |
| 212 | + (match-define (ival (endpoint xlo xlo!) (endpoint xhi xhi!) xerr? xerr) x) |
| 213 | + (match-define (ival (endpoint ylo ylo!) (endpoint yhi yhi!) yerr? yerr) y) |
| 214 | + (ival (endpoint (and xlo ylo) (and xlo! ylo!)) |
| 215 | + (endpoint (or xhi yhi) (and xhi! yhi!)) |
| 216 | + (or xerr? yerr?) |
| 217 | + (and xerr yerr))])) |
221 | 218 |
|
222 | 219 | ;; This function computes and propagates the immovable? flag for endpoints |
223 | 220 | (define (epfn op . args) |
|
393 | 390 | (ormap ival-err as))) |
394 | 391 |
|
395 | 392 | (define (ival-not x) |
396 | | - (ival (epfn not (ival-hi x)) (epfn not (ival-lo x)) (ival-err? x) (ival-err x))) |
| 393 | + (match-define (ival (endpoint xlo xlo!) (endpoint xhi xhi!) xerr? xerr) x) |
| 394 | + (ival (endpoint (not xhi) xhi!) (endpoint (not xlo) xlo!) xerr? xerr)) |
397 | 395 |
|
398 | 396 | (define* ival-asin (compose (monotonic-mpfr mpfr-asin!) (clamp -1.bf 1.bf))) |
399 | 397 | (define* ival-acos (compose (comonotonic-mpfr mpfr-acos!) (clamp -1.bf 1.bf))) |
|
446 | 444 | (define* ival-erfc (comonotonic-mpfr mpfr-erfc!)) |
447 | 445 |
|
448 | 446 | (define (ival-cmp x y) |
449 | | - (define can-< (epfn bflt? (ival-lo x) (ival-hi y))) |
450 | | - (define must-< (epfn bflt? (ival-hi x) (ival-lo y))) |
451 | | - (define can-> (epfn bfgt? (ival-hi x) (ival-lo y))) |
452 | | - (define must-> (epfn bfgt? (ival-lo x) (ival-hi y))) |
| 447 | + (match-define (ival (endpoint xlo xlo!) (endpoint xhi xhi!) _ _) x) |
| 448 | + (match-define (ival (endpoint ylo ylo!) (endpoint yhi yhi!) _ _) y) |
| 449 | + (define can-< (endpoint (bflt? xlo yhi) (and xlo! yhi!))) |
| 450 | + (define must-< (endpoint (bflt? xhi ylo) (and xhi! ylo!))) |
| 451 | + (define can-> (endpoint (bfgt? xhi ylo) (and xhi! ylo!))) |
| 452 | + (define must-> (endpoint (bfgt? xlo yhi) (and xlo! yhi!))) |
453 | 453 | (values can-< must-< can-> must->)) |
454 | 454 |
|
455 | 455 | (define (ival-<2 x y) |
|
458 | 458 |
|
459 | 459 | (define (ival-<=2 x y) |
460 | 460 | (define-values (c< m< c> m>) (ival-cmp x y)) |
461 | | - (ival (epfn not c>) (epfn not m>) (or (ival-err? x) (ival-err? y)) (or (ival-err x) (ival-err y)))) |
| 461 | + (match-define (endpoint c>-val c>!) c>) |
| 462 | + (match-define (endpoint m>-val m>!) m>) |
| 463 | + (ival (endpoint (not c>-val) c>!) |
| 464 | + (endpoint (not m>-val) m>!) |
| 465 | + (or (ival-err? x) (ival-err? y)) |
| 466 | + (or (ival-err x) (ival-err y)))) |
462 | 467 |
|
463 | 468 | (define (ival->2 x y) |
464 | 469 | (define-values (c< m< c> m>) (ival-cmp x y)) |
465 | 470 | (ival m> c> (or (ival-err? x) (ival-err? y)) (or (ival-err x) (ival-err y)))) |
466 | 471 |
|
467 | 472 | (define (ival->=2 x y) |
468 | 473 | (define-values (c< m< c> m>) (ival-cmp x y)) |
469 | | - (ival (epfn not c<) (epfn not m<) (or (ival-err? x) (ival-err? y)) (or (ival-err x) (ival-err y)))) |
| 474 | + (match-define (endpoint c<-val c<!) c<) |
| 475 | + (match-define (endpoint m<-val m<!) m<) |
| 476 | + (ival (endpoint (not c<-val) c<!) |
| 477 | + (endpoint (not m<-val) m<!) |
| 478 | + (or (ival-err? x) (ival-err? y)) |
| 479 | + (or (ival-err x) (ival-err y)))) |
470 | 480 |
|
471 | 481 | (define (ival-==2 x y) |
472 | 482 | (define-values (c< m< c> m>) (ival-cmp x y)) |
473 | | - (ival (epfn and-fn (epfn not c<) (epfn not c>)) |
474 | | - (epfn and-fn (epfn not m<) (epfn not m>)) |
| 483 | + (match-define (endpoint c<-val c<!) c<) |
| 484 | + (match-define (endpoint c>-val c>!) c>) |
| 485 | + (match-define (endpoint m<-val m<!) m<) |
| 486 | + (match-define (endpoint m>-val m>!) m>) |
| 487 | + (ival (endpoint (and (not c<-val) (not c>-val)) (and c<! c>!)) |
| 488 | + (endpoint (and (not m<-val) (not m>-val)) (and m<! m>!)) |
475 | 489 | (or (ival-err? x) (ival-err? y)) |
476 | 490 | (or (ival-err x) (ival-err y)))) |
477 | 491 |
|
|
491 | 505 |
|
492 | 506 | (define (ival-!=2 x y) |
493 | 507 | (define-values (c< m< c> m>) (ival-cmp x y)) |
494 | | - (ival (epfn or-fn m< m>) |
495 | | - (epfn or-fn c< c>) |
| 508 | + (match-define (endpoint m<-val m<!) m<) |
| 509 | + (match-define (endpoint m>-val m>!) m>) |
| 510 | + (match-define (endpoint c<-val c<!) c<) |
| 511 | + (match-define (endpoint c>-val c>!) c>) |
| 512 | + (ival (endpoint (or m<-val m>-val) (and m<! m>!)) |
| 513 | + (endpoint (or c<-val c>-val) (and c<! c>!)) |
496 | 514 | (or (ival-err? x) (ival-err? y)) |
497 | 515 | (or (ival-err x) (ival-err y)))) |
498 | 516 |
|
|
0 commit comments