Average Error: 20.6 → 5.8
Time: 22.6s
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.3375011635662419 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -2.8086776667333143 \cdot 10^{-164}:\\ \;\;\;\;\sqrt[3]{\left(\left(\frac{\left(x - y\right) \cdot \left(x - y\right)}{x \cdot x + y \cdot y} \cdot \frac{\left(y + x\right) \cdot \left(y + x\right)}{x \cdot x + y \cdot y}\right) \cdot \frac{x - y}{\sqrt{x \cdot x + y \cdot y}}\right) \cdot \frac{y + x}{\sqrt{x \cdot x + y \cdot y}}}\\ \mathbf{elif}\;y \le -2.0859057630987112 \cdot 10^{-190}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 1.5094977530774565 \cdot 10^{-195}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{y + x}{\sqrt{x \cdot x + y \cdot y}}\\ \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

Original20.6
Target0.0
Herbie5.8
\[\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.3375011635662419e+154 or -2.8086776667333143e-164 < y < -2.0859057630987112e-190

    1. Initial program 59.6

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

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

    if -1.3375011635662419e+154 < y < -2.8086776667333143e-164

    1. Initial program 0.2

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

      \[\leadsto \frac{\left(x - y\right) \cdot \left(x + y\right)}{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}}\]
    4. Applied times-frac0.4

      \[\leadsto \color{blue}{\frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}}\]
    5. Using strategy rm
    6. Applied add-cbrt-cube17.3

      \[\leadsto \frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\color{blue}{\sqrt[3]{\left(\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}\right) \cdot \sqrt{x \cdot x + y \cdot y}}}}\]
    7. Applied add-cbrt-cube17.0

      \[\leadsto \frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{\color{blue}{\sqrt[3]{\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot \left(x + y\right)}}}{\sqrt[3]{\left(\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}\right) \cdot \sqrt{x \cdot x + y \cdot y}}}\]
    8. Applied cbrt-undiv17.0

      \[\leadsto \frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \color{blue}{\sqrt[3]{\frac{\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot \left(x + y\right)}{\left(\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}\right) \cdot \sqrt{x \cdot x + y \cdot y}}}}\]
    9. Applied add-cbrt-cube17.0

      \[\leadsto \color{blue}{\sqrt[3]{\left(\frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x - y}{\sqrt{x \cdot x + y \cdot y}}\right) \cdot \frac{x - y}{\sqrt{x \cdot x + y \cdot y}}}} \cdot \sqrt[3]{\frac{\left(\left(x + y\right) \cdot \left(x + y\right)\right) \cdot \left(x + y\right)}{\left(\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}\right) \cdot \sqrt{x \cdot x + y \cdot y}}}\]
    10. Applied cbrt-unprod17.0

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

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

    if -2.0859057630987112e-190 < y < 1.5094977530774565e-195

    1. Initial program 29.3

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied associate-/l*29.6

      \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x + y}}}\]
    4. Taylor expanded around inf 13.5

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

    if 1.5094977530774565e-195 < y

    1. Initial program 6.0

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt6.0

      \[\leadsto \frac{\left(x - y\right) \cdot \left(x + y\right)}{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}}\]
    4. Applied times-frac6.4

      \[\leadsto \color{blue}{\frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification5.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3375011635662419 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -2.8086776667333143 \cdot 10^{-164}:\\ \;\;\;\;\sqrt[3]{\left(\left(\frac{\left(x - y\right) \cdot \left(x - y\right)}{x \cdot x + y \cdot y} \cdot \frac{\left(y + x\right) \cdot \left(y + x\right)}{x \cdot x + y \cdot y}\right) \cdot \frac{x - y}{\sqrt{x \cdot x + y \cdot y}}\right) \cdot \frac{y + x}{\sqrt{x \cdot x + y \cdot y}}}\\ \mathbf{elif}\;y \le -2.0859057630987112 \cdot 10^{-190}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 1.5094977530774565 \cdot 10^{-195}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{y + x}{\sqrt{x \cdot x + y \cdot y}}\\ \end{array}\]

Runtime

Time bar (total: 22.6s)Debug logProfile

BaselineHerbieOracleSpan%
Regimes21.15.80.520.674.4%
herbie shell --seed 2018351 
(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))))