Average Error: 19.7 → 5.7
Time: 12.7s
Precision: 64
\[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 -1.3691694056010857 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.2013518175407308 \cdot 10^{-161}:\\ \;\;\;\;\log \left(e^{\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}}\right)\\ \mathbf{elif}\;y \le 2.9860065638011237 \cdot 10^{-218}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 1.2966442305400266 \cdot 10^{-202}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;\frac{y + x}{\sqrt{y \cdot y + x \cdot x}} \cdot \frac{x - y}{\sqrt{y \cdot y + x \cdot x}}\\ \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 -1.3691694056010857 \cdot 10^{+154}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -1.2013518175407308 \cdot 10^{-161}:\\
\;\;\;\;\log \left(e^{\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}}\right)\\

\mathbf{elif}\;y \le 2.9860065638011237 \cdot 10^{-218}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le 1.2966442305400266 \cdot 10^{-202}:\\
\;\;\;\;-1\\

\mathbf{else}:\\
\;\;\;\;\frac{y + x}{\sqrt{y \cdot y + x \cdot x}} \cdot \frac{x - y}{\sqrt{y \cdot y + x \cdot x}}\\

\end{array}
double f(double x, double y) {
        double r3825801 = x;
        double r3825802 = y;
        double r3825803 = r3825801 - r3825802;
        double r3825804 = r3825801 + r3825802;
        double r3825805 = r3825803 * r3825804;
        double r3825806 = r3825801 * r3825801;
        double r3825807 = r3825802 * r3825802;
        double r3825808 = r3825806 + r3825807;
        double r3825809 = r3825805 / r3825808;
        return r3825809;
}

double f(double x, double y) {
        double r3825810 = y;
        double r3825811 = -1.3691694056010857e+154;
        bool r3825812 = r3825810 <= r3825811;
        double r3825813 = -1.0;
        double r3825814 = -1.2013518175407308e-161;
        bool r3825815 = r3825810 <= r3825814;
        double r3825816 = x;
        double r3825817 = r3825816 - r3825810;
        double r3825818 = r3825810 + r3825816;
        double r3825819 = r3825817 * r3825818;
        double r3825820 = r3825810 * r3825810;
        double r3825821 = r3825816 * r3825816;
        double r3825822 = r3825820 + r3825821;
        double r3825823 = r3825819 / r3825822;
        double r3825824 = exp(r3825823);
        double r3825825 = log(r3825824);
        double r3825826 = 2.9860065638011237e-218;
        bool r3825827 = r3825810 <= r3825826;
        double r3825828 = 1.0;
        double r3825829 = 1.2966442305400266e-202;
        bool r3825830 = r3825810 <= r3825829;
        double r3825831 = sqrt(r3825822);
        double r3825832 = r3825818 / r3825831;
        double r3825833 = r3825817 / r3825831;
        double r3825834 = r3825832 * r3825833;
        double r3825835 = r3825830 ? r3825813 : r3825834;
        double r3825836 = r3825827 ? r3825828 : r3825835;
        double r3825837 = r3825815 ? r3825825 : r3825836;
        double r3825838 = r3825812 ? r3825813 : r3825837;
        return r3825838;
}

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.7
Target0.0
Herbie5.7
\[\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.3691694056010857e+154 or 2.9860065638011237e-218 < y < 1.2966442305400266e-202

    1. Initial program 60.1

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

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

    if -1.3691694056010857e+154 < y < -1.2013518175407308e-161

    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.3

      \[\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.3

      \[\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(e^{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}}\right)}\]

    if -1.2013518175407308e-161 < y < 2.9860065638011237e-218

    1. Initial program 28.8

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

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

    if 1.2966442305400266e-202 < y

    1. Initial program 6.3

      \[\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.3

      \[\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.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}}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification5.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3691694056010857 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.2013518175407308 \cdot 10^{-161}:\\ \;\;\;\;\log \left(e^{\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}}\right)\\ \mathbf{elif}\;y \le 2.9860065638011237 \cdot 10^{-218}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 1.2966442305400266 \cdot 10^{-202}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;\frac{y + x}{\sqrt{y \cdot y + x \cdot x}} \cdot \frac{x - y}{\sqrt{y \cdot y + x \cdot x}}\\ \end{array}\]

Reproduce

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