Average Error: 20.5 → 5.0
Time: 5.1s
Precision: 64
\[0.0 \lt x \lt 1 \land y \lt 1\]
\[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;y \le -5.375278492253273374474910915175481103343 \cdot 10^{150}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le \frac{-8857542091609865}{1.013065324433836171511818326096474890384 \cdot 10^{177}}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}\\ \mathbf{elif}\;y \le \frac{544484586544869}{1.425762693006936005825366126781341039029 \cdot 10^{191}}:\\ \;\;\;\;\log \left(e^{1}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{\frac{\left(x - y\right) \cdot x + \left(x - y\right) \cdot y}{x \cdot x + y \cdot y}}\right)\\ \end{array}\]
\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}
\begin{array}{l}
\mathbf{if}\;y \le -5.375278492253273374474910915175481103343 \cdot 10^{150}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le \frac{-8857542091609865}{1.013065324433836171511818326096474890384 \cdot 10^{177}}:\\
\;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}\\

\mathbf{elif}\;y \le \frac{544484586544869}{1.425762693006936005825366126781341039029 \cdot 10^{191}}:\\
\;\;\;\;\log \left(e^{1}\right)\\

\mathbf{else}:\\
\;\;\;\;\log \left(e^{\frac{\left(x - y\right) \cdot x + \left(x - y\right) \cdot y}{x \cdot x + y \cdot y}}\right)\\

\end{array}
double f(double x, double y) {
        double r74858 = x;
        double r74859 = y;
        double r74860 = r74858 - r74859;
        double r74861 = r74858 + r74859;
        double r74862 = r74860 * r74861;
        double r74863 = r74858 * r74858;
        double r74864 = r74859 * r74859;
        double r74865 = r74863 + r74864;
        double r74866 = r74862 / r74865;
        return r74866;
}

double f(double x, double y) {
        double r74867 = y;
        double r74868 = -5.3752784922532734e+150;
        bool r74869 = r74867 <= r74868;
        double r74870 = -1.0;
        double r74871 = -8857542091609865.0;
        double r74872 = 1.0130653244338362e+177;
        double r74873 = r74871 / r74872;
        bool r74874 = r74867 <= r74873;
        double r74875 = 1.0;
        double r74876 = x;
        double r74877 = r74876 * r74876;
        double r74878 = r74867 * r74867;
        double r74879 = r74877 + r74878;
        double r74880 = r74876 - r74867;
        double r74881 = r74876 + r74867;
        double r74882 = r74880 * r74881;
        double r74883 = r74879 / r74882;
        double r74884 = r74875 / r74883;
        double r74885 = 544484586544869.0;
        double r74886 = 1.425762693006936e+191;
        double r74887 = r74885 / r74886;
        bool r74888 = r74867 <= r74887;
        double r74889 = exp(r74875);
        double r74890 = log(r74889);
        double r74891 = r74880 * r74876;
        double r74892 = r74880 * r74867;
        double r74893 = r74891 + r74892;
        double r74894 = r74893 / r74879;
        double r74895 = exp(r74894);
        double r74896 = log(r74895);
        double r74897 = r74888 ? r74890 : r74896;
        double r74898 = r74874 ? r74884 : r74897;
        double r74899 = r74869 ? r74870 : r74898;
        return r74899;
}

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.0
Herbie5.0
\[\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 < -5.3752784922532734e+150

    1. Initial program 62.7

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied clear-num62.7

      \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}}\]
    4. Taylor expanded around 0 0

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

    if -5.3752784922532734e+150 < y < -8.743307936790759e-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 clear-num0.1

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

    if -8.743307936790759e-162 < y < 3.81890050297606e-177

    1. Initial program 30.1

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied distribute-lft-in30.1

      \[\leadsto \frac{\color{blue}{\left(x - y\right) \cdot x + \left(x - y\right) \cdot y}}{x \cdot x + y \cdot y}\]
    4. Using strategy rm
    5. Applied add-log-exp30.1

      \[\leadsto \color{blue}{\log \left(e^{\frac{\left(x - y\right) \cdot x + \left(x - y\right) \cdot y}{x \cdot x + y \cdot y}}\right)}\]
    6. Taylor expanded around inf 14.8

      \[\leadsto \log \left(e^{\color{blue}{1}}\right)\]

    if 3.81890050297606e-177 < y

    1. Initial program 3.0

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied distribute-lft-in3.0

      \[\leadsto \frac{\color{blue}{\left(x - y\right) \cdot x + \left(x - y\right) \cdot y}}{x \cdot x + y \cdot y}\]
    4. Using strategy rm
    5. Applied add-log-exp3.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -5.375278492253273374474910915175481103343 \cdot 10^{150}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le \frac{-8857542091609865}{1.013065324433836171511818326096474890384 \cdot 10^{177}}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}\\ \mathbf{elif}\;y \le \frac{544484586544869}{1.425762693006936005825366126781341039029 \cdot 10^{191}}:\\ \;\;\;\;\log \left(e^{1}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{\frac{\left(x - y\right) \cdot x + \left(x - y\right) \cdot y}{x \cdot x + y \cdot y}}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019304 
(FPCore (x y)
  :name "Kahan p9 Example"
  :precision binary64
  :pre (and (< 0.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))))