Skip to content

Commit 2d1dbcb

Browse files
committed
Inline away bool-endpoint
1 parent 89bc895 commit 2d1dbcb

File tree

1 file changed

+34
-29
lines changed

1 file changed

+34
-29
lines changed

ops/core.rkt

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,6 @@
138138
(define (mk-ival x)
139139
(mk-big-ival x x))
140140

141-
(define (and-fn . as)
142-
(andmap identity as))
143-
(define (or-fn . as)
144-
(ormap identity as))
145-
146141
(define (ival-pi)
147142
(define-values (lo hi) (make-endpoint-pair))
148143
(mpfr-const-pi! lo 'down)
@@ -214,20 +209,19 @@
214209
(or (ival-err? x) (ival-err? y))
215210
(and (ival-err x) (ival-err y)))]
216211
[(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))]))
221218

222219
;; This function computes and propagates the immovable? flag for endpoints
223220
(define (epfn op . args)
224221
(define args-bf (map endpoint-val args))
225222
(define-values (result exact?) (bf-return-exact? op args-bf))
226223
(endpoint result (and (andmap endpoint-immovable? args) exact?)))
227224

228-
(define (bool-endpoint op . endpoints)
229-
(endpoint (apply op (map endpoint-val endpoints)) (andmap endpoint-immovable? endpoints)))
230-
231225
(define (epunary! out mpfr-fun! a-endpoint rnd)
232226
(match-define (endpoint a a!) a-endpoint)
233227
(mpfr-set-prec! out (bf-precision))
@@ -396,7 +390,8 @@
396390
(ormap ival-err as)))
397391

398392
(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))
400395

401396
(define* ival-asin (compose (monotonic-mpfr mpfr-asin!) (clamp -1.bf 1.bf)))
402397
(define* ival-acos (compose (comonotonic-mpfr mpfr-acos!) (clamp -1.bf 1.bf)))
@@ -449,10 +444,12 @@
449444
(define* ival-erfc (comonotonic-mpfr mpfr-erfc!))
450445

451446
(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!)))
456453
(values can-< must-< can-> must->))
457454

458455
(define (ival-<2 x y)
@@ -461,8 +458,10 @@
461458

462459
(define (ival-<=2 x y)
463460
(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>!)
466465
(or (ival-err? x) (ival-err? y))
467466
(or (ival-err x) (ival-err y))))
468467

@@ -472,19 +471,21 @@
472471

473472
(define (ival->=2 x y)
474473
(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<!)
477478
(or (ival-err? x) (ival-err? y))
478479
(or (ival-err x) (ival-err y))))
479480

480481
(define (ival-==2 x y)
481482
(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>!))
488489
(or (ival-err? x) (ival-err? y))
489490
(or (ival-err x) (ival-err y))))
490491

@@ -504,8 +505,12 @@
504505

505506
(define (ival-!=2 x y)
506507
(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>!))
509514
(or (ival-err? x) (ival-err? y))
510515
(or (ival-err x) (ival-err y))))
511516

0 commit comments

Comments
 (0)