Average Error: 19.9 → 5.3
Time: 26.0s
Precision: 64
Internal Precision: 128
\[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;y \le -1.357340002977744 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.787951934820732 \cdot 10^{-159} \lor \neg \left(y \le 7.233557195507802 \cdot 10^{-162}\right):\\ \;\;\;\;\left(\sqrt[3]{\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}} \cdot \sqrt[3]{\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}}\right) \cdot \sqrt[3]{\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original19.9
Target0.0
Herbie5.3
\[\begin{array}{l} \mathbf{if}\;0.5 \lt \left|\frac{x}{y}\right| \lt 2:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{2}{1 + \frac{x}{y} \cdot \frac{x}{y}}\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if y < -1.357340002977744e+154

    1. Initial program 63.6

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Taylor expanded around 0 0

      \[\leadsto \color{blue}{-1}\]

    if -1.357340002977744e+154 < y < -1.787951934820732e-159 or 7.233557195507802e-162 < y

    1. Initial program 0.0

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied add-cube-cbrt0.1

      \[\leadsto \color{blue}{\left(\sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}} \cdot \sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}}\right) \cdot \sqrt[3]{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}}}\]

    if -1.787951934820732e-159 < y < 7.233557195507802e-162

    1. Initial program 29.9

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Taylor expanded around -inf 16.5

      \[\leadsto \color{blue}{1}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification5.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.357340002977744 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.787951934820732 \cdot 10^{-159} \lor \neg \left(y \le 7.233557195507802 \cdot 10^{-162}\right):\\ \;\;\;\;\left(\sqrt[3]{\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}} \cdot \sqrt[3]{\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}}\right) \cdot \sqrt[3]{\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

herbie shell --seed 2019010 
(FPCore (x y)
  :name "Kahan p9 Example"
  :pre (and (< 0 x 1) (< y 1))

  :herbie-target
  (if (< 0.5 (fabs (/ x y)) 2) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) (- 1 (/ 2 (+ 1 (* (/ x y) (/ x y))))))

  (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))

Details

Time bar (total: 25.5s)Debug log

sample47.0ms

Algorithm
intervals

simplify291.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
291.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))

prune5.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 19.5b

localize19.0ms

Local error

Found 2 expressions with local error:

19.5b
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
0.0b
(+ (* x x) (* y y))

rewrite11.0ms

Algorithm
rewrite-expression-head
Rules
associate-/l/
add-exp-log
add-cbrt-cube
flip-+
flip3-+
add-log-exp
add-cube-cbrt
*-un-lft-identity
frac-times
add-sqr-sqrt
flip--
flip3--
times-frac
associate-/r*
associate-/r/
associate-*r/
associate-*l/
div-exp
cbrt-undiv
pow1
associate-/l*
div-inv
cbrt-unprod
prod-exp
frac-2neg
sum-log
clear-num
+-commutative
Counts
2 → 42
Calls
2 calls:
Slowest
8.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
2.0ms
(+ (* x x) (* y y))

series52.0ms

Counts
2 → 6
Calls
2 calls:
Slowest
37.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
14.0ms
(+ (* x x) (* y y))

simplify3.2s

Counts
31 → 48
Calls
31 calls:
Slowest
550.0ms
(- (log (* (- x y) (+ x y))) (log (+ (* x x) (* y y))))
457.0ms
(* (- (* x x) (* y y)) (+ x y))
313.0ms
(* (- (pow x 3) (pow y 3)) (+ (pow x 3) (pow y 3)))
288.0ms
(/ (* (* (* (- x y) (- x y)) (- x y)) (* (* (+ x y) (+ x y)) (+ x y))) (* (* (+ (* x x) (* y y)) (+ (* x x) (* y y))) (+ (* x x) (* y y))))
282.0ms
(* (- (* x x) (* y y)) (+ (pow x 3) (pow y 3)))

prune408.0ms

Pruning

5 alts after pruning (5 fresh and 0 done)

Merged error: 0.5b

localize1.0ms

Local error

Found 0 expressions with local error:

rewrite0.0ms

Algorithm
rewrite-expression-head
Rules
Counts
0 → 0
Calls
0 calls:
Slowest

series0.0ms

Counts
0 → 0
Calls
0 calls:
Slowest

simplify0.0ms

Counts
0 → 0
Calls
0 calls:
Slowest

prune16.0ms

Pruning

5 alts after pruning (4 fresh and 1 done)

Merged error: 0.5b

localize9.0ms

Local error

Found 4 expressions with local error:

19.5b
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
19.5b
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
19.5b
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
0.0b
(* (cbrt (/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))) (cbrt (/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))))

rewrite49.0ms

Algorithm
rewrite-expression-head
Rules
24×associate-/l/
21×add-exp-log
19×add-cbrt-cube
18×cbrt-prod
16×add-cube-cbrt
16×*-un-lft-identity
16×add-sqr-sqrt
15×times-frac
14×flip-+
14×flip3-+
13×frac-times
12×associate-*l*
12×associate-*r*
10×associate-/r/
flip--
flip3--
associate-/r*
pow1
associate-*r/
associate-*l/
div-exp
cbrt-undiv
div-inv
add-log-exp
cbrt-unprod
prod-exp
pow1/3
cbrt-div
associate-/l*
frac-2neg
clear-num
pow-prod-up
pow-prod-down
*-commutative
pow-plus
pow2
Counts
4 → 136
Calls
4 calls:
Slowest
17.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
14.0ms
(* (cbrt (/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))) (cbrt (/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))))
8.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
8.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))

series303.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
182.0ms
(* (cbrt (/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))) (cbrt (/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))))
56.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
33.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
32.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))

simplify13.5s

Counts
120 → 148
Calls
120 calls:
Slowest
467.0ms
(* (- (* x x) (* y y)) (+ x y))
401.0ms
(* (- (* x x) (* y y)) (+ x y))
396.0ms
(* (- (pow x 3) (pow y 3)) (+ (pow x 3) (pow y 3)))
364.0ms
(* (- (pow x 3) (pow y 3)) (+ (pow x 3) (pow y 3)))
357.0ms
(* (- (pow x 3) (pow y 3)) (+ (pow x 3) (pow y 3)))

prune1.6s

Pruning

5 alts after pruning (3 fresh and 2 done)

Merged error: 0.5b

localize15.0ms

Local error

Found 4 expressions with local error:

19.3b
(/ (* (- x y) (+ x y)) (sqrt (+ (* x x) (* y y))))
19.2b
(sqrt (+ (* x x) (* y y)))
19.2b
(sqrt (+ (* x x) (* y y)))
0.0b
(+ (* x x) (* y y))

rewrite30.0ms

Algorithm
rewrite-expression-head
Rules
12×sqrt-prod
12×add-sqr-sqrt
10×add-cube-cbrt
10×*-un-lft-identity
add-exp-log
add-cbrt-cube
associate-/l/
flip-+
flip3-+
add-log-exp
sqrt-div
times-frac
associate-/r*
pow1
frac-times
flip--
flip3--
associate-/r/
associate-*r/
associate-*l/
div-exp
pow1/2
rem-sqrt-square
cbrt-undiv
associate-/l*
div-inv
cbrt-unprod
prod-exp
frac-2neg
sum-log
clear-num
+-commutative
Counts
4 → 76
Calls
4 calls:
Slowest
16.0ms
(/ (* (- x y) (+ x y)) (sqrt (+ (* x x) (* y y))))
4.0ms
(+ (* x x) (* y y))
4.0ms
(sqrt (+ (* x x) (* y y)))
4.0ms
(sqrt (+ (* x x) (* y y)))

series113.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
62.0ms
(/ (* (- x y) (+ x y)) (sqrt (+ (* x x) (* y y))))
19.0ms
(sqrt (+ (* x x) (* y y)))
18.0ms
(sqrt (+ (* x x) (* y y)))
14.0ms
(+ (* x x) (* y y))

simplify3.1s

Counts
58 → 88
Calls
58 calls:
Slowest
429.0ms
(* (- (pow x 3) (pow y 3)) (+ (pow x 3) (pow y 3)))
387.0ms
(* (- (* x x) (* y y)) (+ x y))
239.0ms
(* (- (* x x) (* y y)) (+ (pow x 3) (pow y 3)))
199.0ms
(/ (* (* (* (- x y) (- x y)) (- x y)) (* (* (+ x y) (+ x y)) (+ x y))) (* (* (sqrt (+ (* x x) (* y y))) (sqrt (+ (* x x) (* y y)))) (sqrt (+ (* x x) (* y y)))))
187.0ms
(* (- (pow x 3) (pow y 3)) (+ x y))

prune837.0ms

Pruning

5 alts after pruning (2 fresh and 3 done)

Merged error: 0.5b

regimes163.0ms

Accuracy

76.9% (4.8b remaining)

Error of 5.3b against oracle of 0.5b and baseline of 21.4b

bsearch158.0ms

end0.0ms

sample1.6s

Algorithm
intervals