Average Error: 19.8 → 5.1
Time: 22.4s
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.3253272745940738 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -6.75987253138467 \cdot 10^{-155}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}\right)}^{3}}\\ \mathbf{elif}\;y \le 3.316729756021669 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{{x}^{2} - {y}^{2}}{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.1
\[\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.3253272745940738e+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.3253272745940738e+154 < y < -6.75987253138467e-155

    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-cbrt-cube37.6

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

      \[\leadsto \frac{\color{blue}{\sqrt[3]{\left(\left(\left(x - y\right) \cdot \left(x + y\right)\right) \cdot \left(\left(x - y\right) \cdot \left(x + y\right)\right)\right) \cdot \left(\left(x - y\right) \cdot \left(x + y\right)\right)}}}{\sqrt[3]{\left(\left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x + y \cdot y\right)\right) \cdot \left(x \cdot x + y \cdot y\right)}}\]
    5. Applied cbrt-undiv38.1

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

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

    if -6.75987253138467e-155 < y < 3.316729756021669e-162

    1. Initial program 28.5

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

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

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

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

      \[\leadsto \sqrt[3]{\color{blue}{{\left(\frac{\left(x - y\right) \cdot \left(y + x\right)}{x \cdot x + y \cdot y}\right)}^{3}}}\]
    7. Taylor expanded around inf 15.5

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

    if 3.316729756021669e-162 < y

    1. Initial program 0.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3253272745940738 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -6.75987253138467 \cdot 10^{-155}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}\right)}^{3}}\\ \mathbf{elif}\;y \le 3.316729756021669 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{{x}^{2} - {y}^{2}}{y \cdot y + x \cdot x}\\ \end{array}\]

Reproduce

herbie shell --seed 2019021 
(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))))