Skip to content

Commit fbf859b

Browse files
authored
Merge pull request #124 from herbie-fp/codex/split-epfn-into-two-functions
Split epfn helper into unary and binary variants
2 parents 2537d2a + 27b8b34 commit fbf859b

File tree

3 files changed

+36
-32
lines changed

3 files changed

+36
-32
lines changed

ops/core.rkt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
mk-big-ival
1515
new-ival
1616
ival-maybe
17-
epfn
17+
epunary
18+
epbinary
1819
split-ival
1920
ival-max-prec
2021
ival-exact-neg
@@ -247,11 +248,14 @@
247248
(or xerr? yerr?)
248249
(and xerr yerr))]))
249250

250-
;; This function computes and propagates the immovable? flag for endpoints
251-
(define (epfn op . args)
252-
(define args-bf (map endpoint-val args))
253-
(define-values (result exact?) (bf-return-exact? op args-bf))
254-
(endpoint result (and (andmap endpoint-immovable? args) exact?)))
251+
;; These functions compute and propagate the immovable? flag for endpoints
252+
(define (epunary op arg)
253+
(define-values (result exact?) (bf-return-exact? op (list (endpoint-val arg))))
254+
(endpoint result (and (endpoint-immovable? arg) exact?)))
255+
256+
(define (epbinary op arg0 arg1)
257+
(define-values (result exact?) (bf-return-exact? op (list (endpoint-val arg0) (endpoint-val arg1))))
258+
(endpoint result (and (endpoint-immovable? arg0) (endpoint-immovable? arg1) exact?)))
255259

256260
(define (epunary! out mpfr-fun! a-endpoint rnd)
257261
(match-define (endpoint a a!) a-endpoint)
@@ -296,11 +300,11 @@
296300

297301
(define ((monotonic bffn) x)
298302
(match-define (ival lo hi err? err) x)
299-
(ival (rnd 'down epfn bffn lo) (rnd 'up epfn bffn hi) err? err))
303+
(ival (rnd 'down epunary bffn lo) (rnd 'up epunary bffn hi) err? err))
300304

301305
(define ((comonotonic bffn) x)
302306
(match-define (ival lo hi err? err) x)
303-
(ival (rnd 'down epfn bffn hi) (rnd 'up epfn bffn lo) err? err))
307+
(ival (rnd 'down epunary bffn hi) (rnd 'up epunary bffn lo) err? err))
304308

305309
(define ((close-enough->ival bffn) x)
306310
(match-define (ival (endpoint lo lo!) (endpoint hi hi!) err? err) x)
@@ -677,8 +681,8 @@
677681
(define err? (or (ival-err? y) xerr?))
678682
(define err (or (ival-err y) xerr))
679683
(match* (can-neg can-pos)
680-
[(#t #t) (ival (rnd 'down epfn bfneg xhi) (rnd 'up epfn bfcopy xhi) err? err)]
681-
[(#t #f) (ival (rnd 'down epfn bfneg xhi) (rnd 'up epfn bfneg xlo) err? err)]
684+
[(#t #t) (ival (rnd 'down epunary bfneg xhi) (rnd 'up epunary bfcopy xhi) err? err)]
685+
[(#t #f) (ival (rnd 'down epunary bfneg xhi) (rnd 'up epunary bfneg xlo) err? err)]
682686
[(#f #t) (ival xlo xhi err? err)]
683687
[(#f #f)
684688
(unless (ival-err y)

ops/gamma.rkt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
; Purely decreasing
4545
[(bflt? (endpoint-val hi) xmin) ((comonotonic->ival fn) i)]
4646
[else
47-
(ival-union (ival (endpoint ymin #f) (rnd 'up epfn fn lo) err? err)
48-
(ival (endpoint ymin #f) (rnd 'up epfn fn hi) err? err))]))
47+
(ival-union (ival (endpoint ymin #f) (rnd 'up epunary fn lo) err? err)
48+
(ival (endpoint ymin #f) (rnd 'up epunary fn hi) err? err))]))
4949

5050
; Optimized version of `ival-lgamma-basin` for positive values, adds a cache
5151
(define lgamma-pos-xmin #f)

ops/trig.rkt

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@
4242
[1 ((comonotonic->ival (curry bfcosu n)) x)]
4343
[else
4444
(ival (rnd 'down
45-
epfn
45+
epbinary
4646
bfmin2
47-
(epfn (curry bfcosu n) (ival-lo x))
48-
(epfn (curry bfcosu n) (ival-hi x)))
47+
(epunary (curry bfcosu n) (ival-lo x))
48+
(epunary (curry bfcosu n) (ival-hi x)))
4949
(endpoint 1.bf #f)
5050
(ival-err? x)
5151
(ival-err x))])]
@@ -59,18 +59,18 @@
5959
[(and (bf=? (bfsub b a) 1.bf) (bfeven? a))
6060
(ival (endpoint -1.bf #f)
6161
(rnd 'up
62-
epfn
62+
epbinary
6363
bfmax2
64-
(epfn (curry bfcosu n) (ival-lo x))
65-
(epfn (curry bfcosu n) (ival-hi x)))
64+
(epunary (curry bfcosu n) (ival-lo x))
65+
(epunary (curry bfcosu n) (ival-hi x)))
6666
(ival-err? x)
6767
(ival-err x))]
6868
[(and (bf=? (bfsub b a) 1.bf) (bfodd? a))
6969
(ival (rnd 'down
70-
epfn
70+
epbinary
7171
bfmin2
72-
(epfn (curry bfcosu n) (ival-lo x))
73-
(epfn (curry bfcosu n) (ival-hi x)))
72+
(epunary (curry bfcosu n) (ival-lo x))
73+
(epunary (curry bfcosu n) (ival-hi x)))
7474
(endpoint 1.bf #f)
7575
(ival-err? x)
7676
(ival-err x))]
@@ -86,7 +86,7 @@
8686
[-1 ((monotonic->ival bfcos) x)]
8787
[1 ((comonotonic->ival bfcos) x)]
8888
[else
89-
(ival (rnd 'down epfn bfmin2 (epfn bfcos (ival-lo x)) (epfn bfcos (ival-hi x)))
89+
(ival (rnd 'down epbinary bfmin2 (epunary bfcos (ival-lo x)) (epunary bfcos (ival-hi x)))
9090
(endpoint 1.bf #f)
9191
(ival-err? x)
9292
(ival-err x))])]
@@ -99,11 +99,11 @@
9999
[(and (bf=? a b) (bfodd? a)) ((monotonic->ival bfcos) x)]
100100
[(and (bf=? (bfsub b a) 1.bf) (bfeven? a))
101101
(ival (endpoint -1.bf #f)
102-
(rnd 'up epfn bfmax2 (epfn bfcos (ival-lo x)) (epfn bfcos (ival-hi x)))
102+
(rnd 'up epbinary bfmax2 (epunary bfcos (ival-lo x)) (epunary bfcos (ival-hi x)))
103103
(ival-err? x)
104104
(ival-err x))]
105105
[(and (bf=? (bfsub b a) 1.bf) (bfodd? a))
106-
(ival (rnd 'down epfn bfmin2 (epfn bfcos (ival-lo x)) (epfn bfcos (ival-hi x)))
106+
(ival (rnd 'down epbinary bfmin2 (epunary bfcos (ival-lo x)) (epunary bfcos (ival-hi x)))
107107
(endpoint 1.bf #f)
108108
(ival-err? x)
109109
(ival-err x))]
@@ -126,18 +126,18 @@
126126
[(and (bf=? (bfsub b a) 1.bf) (bfodd? a))
127127
(ival (endpoint -1.bf #f)
128128
(rnd 'up
129-
epfn
129+
epbinary
130130
bfmax2
131-
(epfn (curry bfsinu n) (ival-lo x))
132-
(epfn (curry bfsinu n) (ival-hi x)))
131+
(epunary (curry bfsinu n) (ival-lo x))
132+
(epunary (curry bfsinu n) (ival-hi x)))
133133
(ival-err? x)
134134
(ival-err x))]
135135
[(and (bf=? (bfsub b a) 1.bf) (bfeven? a))
136136
(ival (rnd 'down
137-
epfn
137+
epbinary
138138
bfmin2
139-
(epfn (curry bfsinu n) (ival-lo x))
140-
(epfn (curry bfsinu n) (ival-hi x)))
139+
(epunary (curry bfsinu n) (ival-lo x))
140+
(epunary (curry bfsinu n) (ival-hi x)))
141141
(endpoint 1.bf #f)
142142
(ival-err? x)
143143
(ival-err x))]
@@ -159,11 +159,11 @@
159159
[(and (bf=? a b) (bfeven? a)) ((monotonic->ival bfsin) x)]
160160
[(and (bf=? (bfsub b a) 1.bf) (bfodd? a))
161161
(ival (endpoint -1.bf #f)
162-
(rnd 'up epfn bfmax2 (epfn bfsin (ival-lo x)) (epfn bfsin (ival-hi x)))
162+
(rnd 'up epbinary bfmax2 (epunary bfsin (ival-lo x)) (epunary bfsin (ival-hi x)))
163163
(ival-err? x)
164164
(ival-err x))]
165165
[(and (bf=? (bfsub b a) 1.bf) (bfeven? a))
166-
(ival (rnd 'down epfn bfmin2 (epfn bfsin (ival-lo x)) (epfn bfsin (ival-hi x)))
166+
(ival (rnd 'down epbinary bfmin2 (epunary bfsin (ival-lo x)) (epunary bfsin (ival-hi x)))
167167
(endpoint 1.bf #f)
168168
(ival-err? x)
169169
(ival-err x))]

0 commit comments

Comments
 (0)