Average Error: 19.8 → 5.5
Time: 47.5s
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.3290708708971715 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.571247438036767 \cdot 10^{-162}:\\ \;\;\;\;\sqrt[3]{\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}} \cdot \log \left(e^{\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)\\ \mathbf{elif}\;y \le 3.2282516006894912 \cdot 10^{-220}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 1.293098316436877 \cdot 10^{-183}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;\left(\sqrt[3]{\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}}} \cdot \left(\sqrt[3]{\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}}} \cdot \sqrt[3]{\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)\right) \cdot \sqrt[3]{\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}}\\ \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.8
Target0.1
Herbie5.5
\[\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 4 regimes
  2. if y < -1.3290708708971715e+154 or 3.2282516006894912e-220 < y < 1.293098316436877e-183

    1. Initial program 57.4

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

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

    if -1.3290708708971715e+154 < y < -1.571247438036767e-162

    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.0

      \[\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}}}\]
    4. Using strategy rm
    5. Applied add-log-exp0.0

      \[\leadsto \color{blue}{\log \left(e^{\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.571247438036767e-162 < y < 3.2282516006894912e-220

    1. Initial program 29.2

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

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

    if 1.293098316436877e-183 < y

    1. Initial program 3.4

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

      \[\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}}}\]
    4. Using strategy rm
    5. Applied add-cube-cbrt3.4

      \[\leadsto \color{blue}{\left(\left(\sqrt[3]{\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}}} \cdot \sqrt[3]{\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]{\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}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification5.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3290708708971715 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.571247438036767 \cdot 10^{-162}:\\ \;\;\;\;\sqrt[3]{\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}} \cdot \log \left(e^{\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)\\ \mathbf{elif}\;y \le 3.2282516006894912 \cdot 10^{-220}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 1.293098316436877 \cdot 10^{-183}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;\left(\sqrt[3]{\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}}} \cdot \left(\sqrt[3]{\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}}} \cdot \sqrt[3]{\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)\right) \cdot \sqrt[3]{\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}}\\ \end{array}\]

Reproduce

herbie shell --seed 2019022 
(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: 46.8s)Debug log

sample60.0ms

Algorithm
intervals
Results
34.0ms256×body80valid
11.0ms256×pre80true

simplify228.0ms

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

prune9.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 19.0b

localize28.0ms

Local error

Found 2 expressions with local error:

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

rewrite10.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))

series56.0ms

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

simplify2.5s

Counts
31 → 48
Calls
31 calls:
Slowest
359.0ms
(* (- (* x x) (* y y)) (+ x y))
344.0ms
(* (- (pow x 3) (pow y 3)) (+ (pow x 3) (pow y 3)))
266.0ms
(* (- (* x x) (* y y)) (+ (pow x 3) (pow y 3)))
260.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))))
221.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))))

prune429.0ms

Pruning

6 alts after pruning (6 fresh and 0 done)

Merged error: 0.7b

localize18.0ms

Local error

Found 4 expressions with local error:

19.0b
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
19.0b
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
19.0b
(/ (* (- 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)))))

rewrite67.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
18.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
15.0ms
(* (cbrt (/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))) (cbrt (/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))))
15.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
15.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))

series320.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
179.0ms
(* (cbrt (/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))) (cbrt (/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))))
51.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
46.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
44.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))

simplify12.3s

Counts
120 → 148
Calls
120 calls:
Slowest
430.0ms
(* (- (* x x) (* y y)) (+ x y))
391.0ms
(* (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))
386.0ms
(* (- (pow x 3) (pow y 3)) (+ (pow x 3) (pow y 3)))
365.0ms
(* (- (* x x) (* y y)) (+ x y))
347.0ms
(* (- (* x x) (* y y)) (+ x y))

prune1.6s

Pruning

6 alts after pruning (6 fresh and 0 done)

Merged error: 0.7b

localize14.0ms

Local error

Found 4 expressions with local error:

19.0b
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
19.0b
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
19.0b
(/ (* (- 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)))))

rewrite37.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
11.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
9.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)))
7.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))

series271.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
173.0ms
(* (cbrt (/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))) (cbrt (/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))))
34.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.1s

Counts
120 → 148
Calls
120 calls:
Slowest
728.0ms
(* (- (* x x) (* y y)) (+ x y))
376.0ms
(* (- (* x x) (* y y)) (+ x y))
368.0ms
(* (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))
358.0ms
(* (- (pow x 3) (pow y 3)) (+ (pow x 3) (pow y 3)))
346.0ms
(* (- (* x x) (* y y)) (+ x y))

prune1.8s

Pruning

6 alts after pruning (5 fresh and 1 done)

Merged error: 0.7b

localize23.0ms

Local error

Found 4 expressions with local error:

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

rewrite34.0ms

Algorithm
rewrite-expression-head
Rules
32×associate-/l/
24×add-exp-log
24×add-cbrt-cube
16×flip-+
16×flip3-+
16×frac-times
12×flip--
12×add-cube-cbrt
12×flip3--
12×times-frac
12×*-un-lft-identity
12×associate-/r*
12×add-sqr-sqrt
associate-/r/
associate-*r/
associate-*l/
div-exp
cbrt-undiv
add-log-exp
associate-/l*
div-inv
cbrt-unprod
prod-exp
frac-2neg
clear-num
pow1
Counts
4 → 124
Calls
4 calls:
Slowest
10.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
8.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
7.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
7.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))

series174.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
53.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
50.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
36.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
35.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))

simplify10.1s

Counts
108 → 136
Calls
108 calls:
Slowest
452.0ms
(* (- (* x x) (* y y)) (+ x y))
427.0ms
(* (- (pow x 3) (pow y 3)) (+ (pow x 3) (pow y 3)))
387.0ms
(* (- (pow x 3) (pow y 3)) (+ (pow x 3) (pow y 3)))
380.0ms
(* (- (* x x) (* y y)) (+ x y))
366.0ms
(* (- (pow x 3) (pow y 3)) (+ (pow x 3) (pow y 3)))

prune1.9s

Pruning

6 alts after pruning (4 fresh and 2 done)

Merged error: 0.7b

regimes170.0ms

Accuracy

73.9% (5.1b remaining)

Error of 5.5b against oracle of 0.4b and baseline of 19.8b

bsearch125.0ms

end0.0ms

sample1.5s

Algorithm
intervals
Results
1.1s8000×body80valid
300.0ms8000×pre80true