Skip to content

Commit 88bbafa

Browse files
authored
Merge pull request #140 from herbie-fp/fix-tricks
Several missing tricks entries; hope this is faster
2 parents fbf859b + 6cf3b4c commit 88bbafa

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

eval/tricks.rkt

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@
8585
; Output: '( '(upper-ampl-bound lower-ampl-bound) ...) with len(srcs) number of elements
8686
(define (get-bounds op z srcs)
8787
(case (object-name op)
88+
[(ival-neg ival-neg!)
89+
; Γ[*]'x = 1
90+
; ↑ampl[*]'x = 0
91+
; ↓ampl[*]'x = 0
92+
(define x (first srcs))
93+
(list (cons 0 0))] ; bounds per x
94+
8895
[(ival-mult ival-mult!)
8996
; Γ[*]'x = 1
9097
; ↑ampl[*]'x = logspan(y)
@@ -111,7 +118,7 @@
111118
(list (cons (logspan y) 0) ; bounds per x
112119
(cons (+ (logspan x) (* 2 (logspan y))) 0))] ; bounds per y
113120

114-
[(ival-sqrt ival-cbrt)
121+
[(ival-sqrt ival-cbrt ival-sqrt! ival-cbrt!)
115122
; Γ[sqrt]'x = 0.5
116123
; ↑ampl[sqrt]'x = logspan(x)/2 - 1
117124
; ↓ampl[sqrt]'x = 0
@@ -180,7 +187,7 @@
180187
y-slack)
181188
0)))] ; bounds per y
182189

183-
[(ival-exp ival-exp2)
190+
[(ival-exp ival-exp2 ival-exp! ival-exp2!)
184191
; Γ[exp & exp2]'x = |x| & |x*ln(2)|
185192
; ↑ampl[exp & exp2]'x = maxlog(x) + logspan(z)
186193
; ↓ampl[exp & exp2]'x = minlog(x)
@@ -224,7 +231,7 @@
224231
(- (- 2) (maxlog z #:less-slack #t))))
225232
(list (cons (+ (- (maxlog x) (minlog z)) (min (maxlog x) 0)) 0)))]
226233

227-
[(ival-sinh)
234+
[(ival-sinh ival-sinh!)
228235
; Γ[sinh]'x = |x * cosh(x) / sinh(x)|
229236
; ↑ampl[sinh]'x = maxlog(x) + logspan(z) - min(minlog(x), 0)
230237
; ↓ampl[sinh]'x = max(0, minlog(x))
@@ -234,7 +241,7 @@
234241
(max 0 (minlog x #:less-slack #t))))
235242
(list (cons (- (+ (maxlog x) (logspan z)) (min (minlog x) 0)) 0)))]
236243

237-
[(ival-cosh)
244+
[(ival-cosh ival-cosh!)
238245
; Γ[cosh]'x = |x * sinh(x) / cosh(x)|
239246
; ↑ampl[cosh]'x = maxlog(x) + logspan(z) + min(maxlog(x), 0)
240247
; ↓ampl[cosh]'x = max(0, minlog(x) - 1)
@@ -244,7 +251,7 @@
244251
(max 0 (- (minlog x #:less-slack #t) 1))))
245252
(list (cons (+ (maxlog x) (logspan z) (min (maxlog x) 0)) 0)))]
246253

247-
[(ival-log ival-log2 ival-log10)
254+
[(ival-log ival-log2 ival-log10 ival-log! ival-log2! ival-log10!)
248255
; Γ[log & log2 & log10]'x = |1 / ln(x)| & |ln(2) / ln(x)| & |ln(10) / ln(x)|
249256
; ↑ampl[log & log2 & log10]'x = logspan(x) - minlog(z) + 1
250257
; ↓ampl[log & log2 & log10]'x = - maxlog(z)
@@ -253,7 +260,7 @@
253260
(list (cons (+ (- (logspan x) (minlog z)) 1) (- (maxlog z #:less-slack #t))))
254261
(list (cons (+ (- (logspan x) (minlog z)) 1) 0)))]
255262

256-
[(ival-asin)
263+
[(ival-asin ival-asin!)
257264
; Γ[asin]'x = |x / (sqrt(1-x^2) * arcsin(x))|
258265
; ↑ampl[asin]'x = | slack, if maxlog(z) > 1
259266
; | 1 else
@@ -263,7 +270,7 @@
263270
(cons (get-slack) 0) ; assumes that log[1-x^2]/2 is equal to slack
264271
(cons 1 0)))]
265272

266-
[(ival-acos)
273+
[(ival-acos ival-acos!)
267274
; Γ[acos]'x = |-x / (sqrt(1-x^2) * arccos(x))|
268275
; ↑ampl[acos]'x = | slack, if maxlog(x) >= 0
269276
; | 0 else
@@ -273,7 +280,7 @@
273280
(cons (get-slack) 0) ; assumes that log[1-x^2]/2 is equal to slack
274281
(cons 0 0)))]
275282

276-
[(ival-atan)
283+
[(ival-atan ival-atan!)
277284
; Γ[atan]'x = | x / ((1+x^2) * arctan(x))|
278285
; ↑ampl[atan]'x = - min(|minlog(x)|, |maxlog(x)|) - minlog(z) + logspan(x)
279286
; ↓ampl[atan]'x = - max(|minlog(x)|, |maxlog(x)|) - maxlog(z) - 2
@@ -306,7 +313,7 @@
306313
(cons (+ (- (maxlog x) (minlog z)) slack) 0))] ; bounds per y
307314

308315
; Currently log1p has a very poor approximation
309-
[(ival-log1p)
316+
[(ival-log1p ival-log1p!)
310317
; Γ[log1p]'x ~ |x * log1p(x) / (1+x)|
311318
; ↑ampl[log1p]'x = | maxlog(x) - minlog(z) + slack, if x is negative
312319
; | maxlog(x) - minlog(z), else
@@ -320,7 +327,7 @@
320327
(cons (- (maxlog x) (minlog z)) 0)))]
321328

322329
; Currently expm1 has a very poor solution for negative values
323-
[(ival-expm1)
330+
[(ival-expm1 ival-expm1!)
324331
; Γ[expm1]'x = |x * e^x / expm1|
325332
; ↑ampl[expm1]'x = max(1 + maxlog(x), 1 + maxlog(x) - minlog(z))
326333
; ↓ampl[expm1]'x = 0
@@ -344,14 +351,14 @@
344351
(cons (- (+ (maxlog x) (maxlog y)) (* 2 (min (minlog x) (minlog y))) (minlog z))
345352
0)))]
346353

347-
[(ival-tanh)
354+
[(ival-tanh ival-tanh!)
348355
; Γ[tanh]'x = |x / (sinh(x) * cosh(x))|
349356
; ↑ampl[tanh]'x = logspan(z) + logspan(x)
350357
; ↓ampl[tanh]'x = 0
351358
(define x (first srcs))
352359
(list (cons (+ (logspan z) (logspan x)) 0))]
353360

354-
[(ival-atanh)
361+
[(ival-atanh ival-atanh!)
355362
; Γ[atanh]'x = |x / (log(1-x^2) * atanh(x))|
356363
; ↑ampl[atanh]'x = | 1, if x < 0.5
357364
; | slack
@@ -361,7 +368,7 @@
361368
(cons (get-slack) 0)
362369
(cons 1 0)))]
363370

364-
[(ival-acosh)
371+
[(ival-acosh ival-acosh!)
365372
; Γ[acosh]'x = |x / (sqrt(x-1) * sqrt(x+1) * acosh)|
366373
; ↑ampl[acosh]'x = | -minlog(z) + slack, if minlog(z) < 2
367374
; | 0
@@ -399,14 +406,21 @@
399406
(define n (cdr srcs)) ; n is already a floor(log(n))
400407
(list (cons (- (maxlog x) n (- (max (abs (maxlog z)) (abs (minlog z)))) -3) 0))]
401408

409+
; TODO
410+
[(ival-asinh ival-asinh!) (list (cons (get-slack) 0))]
411+
412+
; TODO
413+
[(ival-hypot ival-hypot!) (list (cons (get-slack) 0) (cons (get-slack) 0))]
414+
402415
; TODO
403416
; ↑ampl[...] = slack
404417
; ↓ampl[...] = 0
405-
[(ival-erfc ival-erf ival-lgamma ival-tgamma ival-asinh ival-logb) (list (cons (get-slack) 0))]
418+
[(ival-erfc ival-erf ival-erfc! ival-erf! ival-lgamma ival-tgamma ival-logb)
419+
(list (cons (get-slack) 0))]
406420

407421
; TODO
408422
; ↑ampl[...] = slack
409423
; ↓ampl[...] = 0
410-
[(ival-ceil ival-floor ival-rint ival-round ival-trunc) (list (cons (get-slack) 0))]
424+
[(ival-ceil ival-floor ival-rint ival-rint! ival-round ival-trunc) (list (cons (get-slack) 0))]
411425

412426
[else (map (λ (_) (cons 0 0)) srcs)])) ; exponents for arguments

0 commit comments

Comments
 (0)