Average Error: 20.5 → 5.8
Time: 29.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 -4.8867027686569046 \cdot 10^{-05}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -2.567264824776326 \cdot 10^{-242}:\\ \;\;\;\;\frac{x - y}{\frac{x \cdot x + y \cdot y}{y + x}}\\ \mathbf{elif}\;y \le 1.6303931522933684 \cdot 10^{-165}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{\left(y + x\right) \cdot \left(x - y\right)}{x \cdot x + y \cdot y}\right)}^{3}}\\ \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.5
Target0.1
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 < -4.8867027686569046e-05

    1. Initial program 32.1

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Initial simplification32.1

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

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

    if -4.8867027686569046e-05 < y < -2.567264824776326e-242

    1. Initial program 10.5

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Initial simplification10.5

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

      \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{y + x}}}\]

    if -2.567264824776326e-242 < y < 1.6303931522933684e-165

    1. Initial program 29.4

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Initial simplification29.4

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

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

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

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

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

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

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

    if 1.6303931522933684e-165 < y

    1. Initial program 0.8

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Initial simplification0.8

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -4.8867027686569046 \cdot 10^{-05}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -2.567264824776326 \cdot 10^{-242}:\\ \;\;\;\;\frac{x - y}{\frac{x \cdot x + y \cdot y}{y + x}}\\ \mathbf{elif}\;y \le 1.6303931522933684 \cdot 10^{-165}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{\left(y + x\right) \cdot \left(x - y\right)}{x \cdot x + y \cdot y}\right)}^{3}}\\ \end{array}\]

Runtime

Time bar (total: 29.6s)Debug logProfile

BaselineHerbieOracleSpan%
Regimes22.05.80.521.675.3%
herbie shell --seed 2018354 
(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))))