|
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 (bool-endpoint and-fn (ival-lo x) (ival-lo y)) |
218 | | - (bool-endpoint 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) |
224 | 221 | (define args-bf (map endpoint-val args)) |
225 | 222 | (define-values (result exact?) (bf-return-exact? op args-bf)) |
226 | 223 | (endpoint result (and (andmap endpoint-immovable? args) exact?))) |
227 | 224 |
|
228 | | -(define (bool-endpoint op . endpoints) |
229 | | - (endpoint (apply op (map endpoint-val endpoints)) (andmap endpoint-immovable? endpoints))) |
230 | | - |
231 | 225 | (define (epunary! out mpfr-fun! a-endpoint rnd) |
232 | 226 | (match-define (endpoint a a!) a-endpoint) |
233 | 227 | (mpfr-set-prec! out (bf-precision)) |
|
396 | 390 | (ormap ival-err as))) |
397 | 391 |
|
398 | 392 | (define (ival-not x) |
399 | | - (ival (bool-endpoint not (ival-hi x)) (bool-endpoint 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)) |
400 | 395 |
|
401 | 396 | (define* ival-asin (compose (monotonic-mpfr mpfr-asin!) (clamp -1.bf 1.bf))) |
402 | 397 | (define* ival-acos (compose (comonotonic-mpfr mpfr-acos!) (clamp -1.bf 1.bf))) |
|
449 | 444 | (define* ival-erfc (comonotonic-mpfr mpfr-erfc!)) |
450 | 445 |
|
451 | 446 | (define (ival-cmp x y) |
452 | | - (define can-< (bool-endpoint bflt? (ival-lo x) (ival-hi y))) |
453 | | - (define must-< (bool-endpoint bflt? (ival-hi x) (ival-lo y))) |
454 | | - (define can-> (bool-endpoint bfgt? (ival-hi x) (ival-lo y))) |
455 | | - (define must-> (bool-endpoint 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!))) |
456 | 453 | (values can-< must-< can-> must->)) |
457 | 454 |
|
458 | 455 | (define (ival-<2 x y) |
|
461 | 458 |
|
462 | 459 | (define (ival-<=2 x y) |
463 | 460 | (define-values (c< m< c> m>) (ival-cmp x y)) |
464 | | - (ival (bool-endpoint not c>) |
465 | | - (bool-endpoint not m>) |
| 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>!) |
466 | 465 | (or (ival-err? x) (ival-err? y)) |
467 | 466 | (or (ival-err x) (ival-err y)))) |
468 | 467 |
|
|
472 | 471 |
|
473 | 472 | (define (ival->=2 x y) |
474 | 473 | (define-values (c< m< c> m>) (ival-cmp x y)) |
475 | | - (ival (bool-endpoint not c<) |
476 | | - (bool-endpoint not m<) |
| 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<!) |
477 | 478 | (or (ival-err? x) (ival-err? y)) |
478 | 479 | (or (ival-err x) (ival-err y)))) |
479 | 480 |
|
480 | 481 | (define (ival-==2 x y) |
481 | 482 | (define-values (c< m< c> m>) (ival-cmp x y)) |
482 | | - (define not-c< (bool-endpoint not c<)) |
483 | | - (define not-c> (bool-endpoint not c>)) |
484 | | - (define not-m< (bool-endpoint not m<)) |
485 | | - (define not-m> (bool-endpoint not m>)) |
486 | | - (ival (bool-endpoint and-fn not-c< not-c>) |
487 | | - (bool-endpoint and-fn not-m< 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>!)) |
488 | 489 | (or (ival-err? x) (ival-err? y)) |
489 | 490 | (or (ival-err x) (ival-err y)))) |
490 | 491 |
|
|
504 | 505 |
|
505 | 506 | (define (ival-!=2 x y) |
506 | 507 | (define-values (c< m< c> m>) (ival-cmp x y)) |
507 | | - (ival (bool-endpoint or-fn m< m>) |
508 | | - (bool-endpoint 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>!)) |
509 | 514 | (or (ival-err? x) (ival-err? y)) |
510 | 515 | (or (ival-err x) (ival-err y)))) |
511 | 516 |
|
|
0 commit comments