Average Error: 19.9 → 4.6
Time: 8.8s
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 -9.821782313314639955086003839853747327964 \cdot 10^{153}:\\ \;\;\;\;\log \left(e^{-1}\right)\\ \mathbf{elif}\;y \le \frac{-4907405930329829}{2.53266331108459042877954581524118722596 \cdot 10^{176}}:\\ \;\;\;\;\log \left({\left(e^{1}\right)}^{\left(\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\right)}\right)\\ \mathbf{elif}\;y \le \frac{7408587307615215}{4.052261297735344686047273304385899561536 \cdot 10^{177}}:\\ \;\;\;\;\log \left({\left(e^{1}\right)}^{1}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left({\left(e^{1}\right)}^{\left(\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\right)}\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 -9.821782313314639955086003839853747327964 \cdot 10^{153}:\\
\;\;\;\;\log \left(e^{-1}\right)\\

\mathbf{elif}\;y \le \frac{-4907405930329829}{2.53266331108459042877954581524118722596 \cdot 10^{176}}:\\
\;\;\;\;\log \left({\left(e^{1}\right)}^{\left(\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\right)}\right)\\

\mathbf{elif}\;y \le \frac{7408587307615215}{4.052261297735344686047273304385899561536 \cdot 10^{177}}:\\
\;\;\;\;\log \left({\left(e^{1}\right)}^{1}\right)\\

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

\end{array}
double f(double x, double y) {
        double r72855 = x;
        double r72856 = y;
        double r72857 = r72855 - r72856;
        double r72858 = r72855 + r72856;
        double r72859 = r72857 * r72858;
        double r72860 = r72855 * r72855;
        double r72861 = r72856 * r72856;
        double r72862 = r72860 + r72861;
        double r72863 = r72859 / r72862;
        return r72863;
}

double f(double x, double y) {
        double r72864 = y;
        double r72865 = -9.82178231331464e+153;
        bool r72866 = r72864 <= r72865;
        double r72867 = -1.0;
        double r72868 = exp(r72867);
        double r72869 = log(r72868);
        double r72870 = -4907405930329829.0;
        double r72871 = 2.5326633110845904e+176;
        double r72872 = r72870 / r72871;
        bool r72873 = r72864 <= r72872;
        double r72874 = 1.0;
        double r72875 = exp(r72874);
        double r72876 = x;
        double r72877 = r72876 - r72864;
        double r72878 = r72876 + r72864;
        double r72879 = r72877 * r72878;
        double r72880 = r72876 * r72876;
        double r72881 = r72864 * r72864;
        double r72882 = r72880 + r72881;
        double r72883 = r72879 / r72882;
        double r72884 = pow(r72875, r72883);
        double r72885 = log(r72884);
        double r72886 = 7408587307615215.0;
        double r72887 = 4.052261297735345e+177;
        double r72888 = r72886 / r72887;
        bool r72889 = r72864 <= r72888;
        double r72890 = pow(r72875, r72874);
        double r72891 = log(r72890);
        double r72892 = r72889 ? r72891 : r72885;
        double r72893 = r72873 ? r72885 : r72892;
        double r72894 = r72866 ? r72869 : r72893;
        return r72894;
}

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.9
Target0.1
Herbie4.6
\[\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 3 regimes
  2. if y < -9.82178231331464e+153

    1. Initial program 63.9

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

      \[\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-frac61.9

      \[\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-log-exp61.9

      \[\leadsto \color{blue}{\log \left(e^{\frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}}\right)}\]
    7. Simplified63.9

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

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

    if -9.82178231331464e+153 < y < -1.937646393364571e-161 or 1.8282600166370302e-162 < y

    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-sqr-sqrt0.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-frac0.5

      \[\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-log-exp0.5

      \[\leadsto \color{blue}{\log \left(e^{\frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}}\right)}\]
    7. Simplified0.0

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

    if -1.937646393364571e-161 < y < 1.8282600166370302e-162

    1. Initial program 29.7

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

      \[\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-frac30.2

      \[\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-log-exp30.2

      \[\leadsto \color{blue}{\log \left(e^{\frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}}\right)}\]
    7. Simplified29.7

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

      \[\leadsto \log \left({\left(e^{1}\right)}^{\color{blue}{1}}\right)\]
  3. Recombined 3 regimes into one program.
  4. Final simplification4.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -9.821782313314639955086003839853747327964 \cdot 10^{153}:\\ \;\;\;\;\log \left(e^{-1}\right)\\ \mathbf{elif}\;y \le \frac{-4907405930329829}{2.53266331108459042877954581524118722596 \cdot 10^{176}}:\\ \;\;\;\;\log \left({\left(e^{1}\right)}^{\left(\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\right)}\right)\\ \mathbf{elif}\;y \le \frac{7408587307615215}{4.052261297735344686047273304385899561536 \cdot 10^{177}}:\\ \;\;\;\;\log \left({\left(e^{1}\right)}^{1}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left({\left(e^{1}\right)}^{\left(\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\right)}\right)\\ \end{array}\]

Reproduce

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