herbie-fp / herbie

Optimize floating-point expressions for accuracy
https://herbie.uwplse.org
Other
774 stars 33 forks source link

Local error tree for if expressions #1045

Open zaneenders opened 2 weeks ago

zaneenders commented 2 weeks ago

This is a write of an issue in batch mode for cleanup-localize and zane-true-error giving all nans.

// clipped from testAPI.mjs
const localError7 = await (await fetch(makeEndpoint("/api/localerror"), {
  method: 'POST', body: JSON.stringify({
    formula: FPCoreFormula3, sample: [[[2e269], ignoredValue]], seed: 5
  })
})).json()

adding to localize.rkt

(for ([spec (in-list compare-specs)])  ; line 286
  (eprintf "compare-spec: ~a\n" spec))
(eprintf "pt*: ~a\n" pt*) ; line 310
(eprintf "deltas: ~a\n" deltas) : 312

Which gives the following output:

Local error Job local-error started:
  8ef7bf18e333e70b6b3e0347b5eee4e42ddb1549 (if (<= (- (sqrt (+ x 1.0)) (sqrt x)) 0.05) (* 0.5 (sqrt (/ 1.0 x))) (fma (fma (- 0.125) x 0.5) x (- 1.0 (sqrt x))))...
compare-spec: (fabs (- (if (<= (- (sqrt (+ x 1)) (sqrt x)) 3602879701896397/72057594037927936) (* 1/2 (sqrt (/ 1 x))) (+ (* (+ (* (neg 1/8) x) 1/2) x) (- 1 (sqrt x)))) -exact-for-0))
compare-spec: 0
compare-spec: (fabs (- (- (sqrt (+ x 1)) (sqrt x)) -exact-for-2))
compare-spec: (fabs (- (sqrt (+ x 1)) -exact-for-3))
compare-spec: (fabs (- (+ x 1) -exact-for-4))
compare-spec: (fabs (- x -exact-for-5))
compare-spec: 0
compare-spec: (fabs (- (sqrt x) -exact-for-7))
compare-spec: 0
compare-spec: (fabs (- (* 1/2 (sqrt (/ 1 x))) -exact-for-9))
compare-spec: 0
compare-spec: (fabs (- (sqrt (/ 1 x)) -exact-for-11))
compare-spec: (fabs (- (/ 1 x) -exact-for-12))
compare-spec: (fabs (- (+ (* (+ (* (neg 1/8) x) 1/2) x) (- 1 (sqrt x))) -exact-for-13))
compare-spec: (fabs (- (+ (* (neg 1/8) x) 1/2) -exact-for-14))
compare-spec: (fabs (- (neg 1/8) -exact-for-15))
compare-spec: 0
compare-spec: (fabs (- (- 1 (sqrt x)) -exact-for-17))
pt*: (2e+269 1.1180339887498948e-135 #t 0.0 4.4721359549995795e+134 2e+269 2e+269 1.0 4.4721359549995795e+134 0.05 1.1180339887498948e-135 0.5 2.2360679774997897e-135 5e-270 0.0 -2.5e+268 -0.125 0.125 -4.4721359549995795e+134)
deltas: #(+nan.0 +nan.0 +nan.0 +nan.0 +nan.0 +nan.0 +nan.0 +nan.0 +nan.0 +nan.0 +nan.0 +nan.0 +nan.0 +nan.0 +nan.0 +nan.0 +nan.0 +nan.0)

One test for this could be on line 233 of testApi.mjs

checkLocalErrorNode(localError7.tree, [0, 0],
  '-', '61.2', '0.0', '1.1180339887498948e-135', '1.1180339887498948e-135', '61.16647760559045')
zaneenders commented 2 weeks ago

Here is a trimmed-down version of testApi.mjs. Renamed to .txt because of Git hub upload restrictions. testApi.txt

pavpanchekha commented 1 week ago

Not surprised if this is fixed by herbie-fp/rival#83 or #1050.