Average Error: 20.2 → 4.9
Time: 3.4s
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 -1.6756213551274553 \cdot 10^{151}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.78621350836968853 \cdot 10^{-162}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{y \cdot y + x \cdot x}\\ \mathbf{elif}\;y \le 5.3431862292807695 \cdot 10^{-166}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\log \left({e}^{\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 -1.6756213551274553 \cdot 10^{151}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -1.78621350836968853 \cdot 10^{-162}:\\
\;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{y \cdot y + x \cdot x}\\

\mathbf{elif}\;y \le 5.3431862292807695 \cdot 10^{-166}:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;\log \left({e}^{\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 r120687 = x;
        double r120688 = y;
        double r120689 = r120687 - r120688;
        double r120690 = r120687 + r120688;
        double r120691 = r120689 * r120690;
        double r120692 = r120687 * r120687;
        double r120693 = r120688 * r120688;
        double r120694 = r120692 + r120693;
        double r120695 = r120691 / r120694;
        return r120695;
}

double f(double x, double y) {
        double r120696 = y;
        double r120697 = -1.6756213551274553e+151;
        bool r120698 = r120696 <= r120697;
        double r120699 = -1.0;
        double r120700 = -1.7862135083696885e-162;
        bool r120701 = r120696 <= r120700;
        double r120702 = x;
        double r120703 = r120702 - r120696;
        double r120704 = r120702 + r120696;
        double r120705 = r120703 * r120704;
        double r120706 = r120696 * r120696;
        double r120707 = r120702 * r120702;
        double r120708 = r120706 + r120707;
        double r120709 = r120705 / r120708;
        double r120710 = 5.3431862292807695e-166;
        bool r120711 = r120696 <= r120710;
        double r120712 = 1.0;
        double r120713 = exp(1.0);
        double r120714 = r120707 + r120706;
        double r120715 = r120705 / r120714;
        double r120716 = pow(r120713, r120715);
        double r120717 = log(r120716);
        double r120718 = r120711 ? r120712 : r120717;
        double r120719 = r120701 ? r120709 : r120718;
        double r120720 = r120698 ? r120699 : r120719;
        return r120720;
}

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.2
Target0.1
Herbie4.9
\[\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.6756213551274553e+151

    1. Initial program 62.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.6756213551274553e+151 < y < -1.7862135083696885e-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 +-commutative0.0

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

    if -1.7862135083696885e-162 < y < 5.3431862292807695e-166

    1. Initial program 30.3

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

      \[\leadsto \color{blue}{\log \left(e^{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}}\right)}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity30.3

      \[\leadsto \log \left(e^{\color{blue}{1 \cdot \frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}}}\right)\]
    6. Applied exp-prod30.3

      \[\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)}\]
    7. Simplified30.3

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

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

    if 5.3431862292807695e-166 < y

    1. Initial program 0.5

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied add-log-exp0.5

      \[\leadsto \color{blue}{\log \left(e^{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}}\right)}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity0.5

      \[\leadsto \log \left(e^{\color{blue}{1 \cdot \frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}}}\right)\]
    6. Applied exp-prod0.5

      \[\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)}\]
    7. Simplified0.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.6756213551274553 \cdot 10^{151}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.78621350836968853 \cdot 10^{-162}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{y \cdot y + x \cdot x}\\ \mathbf{elif}\;y \le 5.3431862292807695 \cdot 10^{-166}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\log \left({e}^{\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 2020034 
(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))))