Skip to content

Commit 7101c9d

Browse files
committed
Several missing tricks entries; hope this is faster
1 parent fc97a4b commit 7101c9d

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

eval/tricks.rkt

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@
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+
95+
8896
[(ival-mult ival-mult!)
8997
; Γ[*]'x = 1
9098
; ↑ampl[*]'x = logspan(y)
@@ -111,7 +119,7 @@
111119
(list (cons (logspan y) 0) ; bounds per x
112120
(cons (+ (logspan x) (* 2 (logspan y))) 0))] ; bounds per y
113121

114-
[(ival-sqrt ival-cbrt)
122+
[(ival-sqrt ival-cbrt ival-sqrt! ival-cbrt!)
115123
; Γ[sqrt]'x = 0.5
116124
; ↑ampl[sqrt]'x = logspan(x)/2 - 1
117125
; ↓ampl[sqrt]'x = 0
@@ -180,7 +188,7 @@
180188
y-slack)
181189
0)))] ; bounds per y
182190

183-
[(ival-exp ival-exp2)
191+
[(ival-exp ival-exp2 ival-exp! ival-exp2!)
184192
; Γ[exp & exp2]'x = |x| & |x*ln(2)|
185193
; ↑ampl[exp & exp2]'x = maxlog(x) + logspan(z)
186194
; ↓ampl[exp & exp2]'x = minlog(x)
@@ -224,7 +232,7 @@
224232
(- (- 2) (maxlog z #:less-slack #t))))
225233
(list (cons (+ (- (maxlog x) (minlog z)) (min (maxlog x) 0)) 0)))]
226234

227-
[(ival-sinh)
235+
[(ival-sinh ival-sinh!)
228236
; Γ[sinh]'x = |x * cosh(x) / sinh(x)|
229237
; ↑ampl[sinh]'x = maxlog(x) + logspan(z) - min(minlog(x), 0)
230238
; ↓ampl[sinh]'x = max(0, minlog(x))
@@ -234,7 +242,7 @@
234242
(max 0 (minlog x #:less-slack #t))))
235243
(list (cons (- (+ (maxlog x) (logspan z)) (min (minlog x) 0)) 0)))]
236244

237-
[(ival-cosh)
245+
[(ival-cosh ival-cosh!)
238246
; Γ[cosh]'x = |x * sinh(x) / cosh(x)|
239247
; ↑ampl[cosh]'x = maxlog(x) + logspan(z) + min(maxlog(x), 0)
240248
; ↓ampl[cosh]'x = max(0, minlog(x) - 1)
@@ -244,7 +252,7 @@
244252
(max 0 (- (minlog x #:less-slack #t) 1))))
245253
(list (cons (+ (maxlog x) (logspan z) (min (maxlog x) 0)) 0)))]
246254

247-
[(ival-log ival-log2 ival-log10)
255+
[(ival-log ival-log2 ival-log10 ival-log! ival-log2! ival-log10!)
248256
; Γ[log & log2 & log10]'x = |1 / ln(x)| & |ln(2) / ln(x)| & |ln(10) / ln(x)|
249257
; ↑ampl[log & log2 & log10]'x = logspan(x) - minlog(z) + 1
250258
; ↓ampl[log & log2 & log10]'x = - maxlog(z)
@@ -253,7 +261,7 @@
253261
(list (cons (+ (- (logspan x) (minlog z)) 1) (- (maxlog z #:less-slack #t))))
254262
(list (cons (+ (- (logspan x) (minlog z)) 1) 0)))]
255263

256-
[(ival-asin)
264+
[(ival-asin ival-asin!)
257265
; Γ[asin]'x = |x / (sqrt(1-x^2) * arcsin(x))|
258266
; ↑ampl[asin]'x = | slack, if maxlog(z) > 1
259267
; | 1 else
@@ -263,7 +271,7 @@
263271
(cons (get-slack) 0) ; assumes that log[1-x^2]/2 is equal to slack
264272
(cons 1 0)))]
265273

266-
[(ival-acos)
274+
[(ival-acos ival-acos!)
267275
; Γ[acos]'x = |-x / (sqrt(1-x^2) * arccos(x))|
268276
; ↑ampl[acos]'x = | slack, if maxlog(x) >= 0
269277
; | 0 else
@@ -273,7 +281,7 @@
273281
(cons (get-slack) 0) ; assumes that log[1-x^2]/2 is equal to slack
274282
(cons 0 0)))]
275283

276-
[(ival-atan)
284+
[(ival-atan ival-atan!)
277285
; Γ[atan]'x = | x / ((1+x^2) * arctan(x))|
278286
; ↑ampl[atan]'x = - min(|minlog(x)|, |maxlog(x)|) - minlog(z) + logspan(x)
279287
; ↓ampl[atan]'x = - max(|minlog(x)|, |maxlog(x)|) - maxlog(z) - 2
@@ -306,7 +314,7 @@
306314
(cons (+ (- (maxlog x) (minlog z)) slack) 0))] ; bounds per y
307315

308316
; Currently log1p has a very poor approximation
309-
[(ival-log1p)
317+
[(ival-log1p ival-log1p!)
310318
; Γ[log1p]'x ~ |x * log1p(x) / (1+x)|
311319
; ↑ampl[log1p]'x = | maxlog(x) - minlog(z) + slack, if x is negative
312320
; | maxlog(x) - minlog(z), else
@@ -320,7 +328,7 @@
320328
(cons (- (maxlog x) (minlog z)) 0)))]
321329

322330
; Currently expm1 has a very poor solution for negative values
323-
[(ival-expm1)
331+
[(ival-expm1 ival-expm1!)
324332
; Γ[expm1]'x = |x * e^x / expm1|
325333
; ↑ampl[expm1]'x = max(1 + maxlog(x), 1 + maxlog(x) - minlog(z))
326334
; ↓ampl[expm1]'x = 0
@@ -344,14 +352,14 @@
344352
(cons (- (+ (maxlog x) (maxlog y)) (* 2 (min (minlog x) (minlog y))) (minlog z))
345353
0)))]
346354

347-
[(ival-tanh)
355+
[(ival-tanh ival-tanh!)
348356
; Γ[tanh]'x = |x / (sinh(x) * cosh(x))|
349357
; ↑ampl[tanh]'x = logspan(z) + logspan(x)
350358
; ↓ampl[tanh]'x = 0
351359
(define x (first srcs))
352360
(list (cons (+ (logspan z) (logspan x)) 0))]
353361

354-
[(ival-atanh)
362+
[(ival-atanh ival-atanh!)
355363
; Γ[atanh]'x = |x / (log(1-x^2) * atanh(x))|
356364
; ↑ampl[atanh]'x = | 1, if x < 0.5
357365
; | slack
@@ -361,7 +369,7 @@
361369
(cons (get-slack) 0)
362370
(cons 1 0)))]
363371

364-
[(ival-acosh)
372+
[(ival-acosh ival-acosh!)
365373
; Γ[acosh]'x = |x / (sqrt(x-1) * sqrt(x+1) * acosh)|
366374
; ↑ampl[acosh]'x = | -minlog(z) + slack, if minlog(z) < 2
367375
; | 0
@@ -399,14 +407,17 @@
399407
(define n (cdr srcs)) ; n is already a floor(log(n))
400408
(list (cons (- (maxlog x) n (- (max (abs (maxlog z)) (abs (minlog z)))) -3) 0))]
401409

410+
; TODO
411+
; hypot
412+
402413
; TODO
403414
; ↑ampl[...] = slack
404415
; ↓ampl[...] = 0
405-
[(ival-erfc ival-erf ival-lgamma ival-tgamma ival-asinh ival-logb) (list (cons (get-slack) 0))]
416+
[(ival-erfc ival-erf ival-erfc! ival-erf! ival-lgamma ival-tgamma ival-asinh ival-asinh! ival-logb) (list (cons (get-slack) 0))]
406417

407418
; TODO
408419
; ↑ampl[...] = slack
409420
; ↓ampl[...] = 0
410-
[(ival-ceil ival-floor ival-rint ival-round ival-trunc) (list (cons (get-slack) 0))]
421+
[(ival-ceil ival-floor ival-rint ival-rint! ival-round ival-trunc) (list (cons (get-slack) 0))]
411422

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

0 commit comments

Comments
 (0)