Average Error: 20.3 → 5.4
Time: 1.1m
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.1564294007415584 \cdot 10^{+23}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -4.9781449920664 \cdot 10^{-177}:\\ \;\;\;\;\log \left(e^{\frac{x - y}{\frac{x \cdot x + y \cdot y}{y + x}}}\right)\\ \mathbf{elif}\;y \le 1.0919689144745608 \cdot 10^{-199}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{\frac{x - y}{\frac{x \cdot x + y \cdot y}{y + x}}}\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.1564294007415584 \cdot 10^{+23}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;y \le 1.0919689144745608 \cdot 10^{-199}:\\
\;\;\;\;1\\

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

\end{array}
double f(double x, double y) {
        double r14399147 = x;
        double r14399148 = y;
        double r14399149 = r14399147 - r14399148;
        double r14399150 = r14399147 + r14399148;
        double r14399151 = r14399149 * r14399150;
        double r14399152 = r14399147 * r14399147;
        double r14399153 = r14399148 * r14399148;
        double r14399154 = r14399152 + r14399153;
        double r14399155 = r14399151 / r14399154;
        return r14399155;
}

double f(double x, double y) {
        double r14399156 = y;
        double r14399157 = -1.1564294007415584e+23;
        bool r14399158 = r14399156 <= r14399157;
        double r14399159 = -1.0;
        double r14399160 = -4.9781449920664e-177;
        bool r14399161 = r14399156 <= r14399160;
        double r14399162 = x;
        double r14399163 = r14399162 - r14399156;
        double r14399164 = r14399162 * r14399162;
        double r14399165 = r14399156 * r14399156;
        double r14399166 = r14399164 + r14399165;
        double r14399167 = r14399156 + r14399162;
        double r14399168 = r14399166 / r14399167;
        double r14399169 = r14399163 / r14399168;
        double r14399170 = exp(r14399169);
        double r14399171 = log(r14399170);
        double r14399172 = 1.0919689144745608e-199;
        bool r14399173 = r14399156 <= r14399172;
        double r14399174 = 1.0;
        double r14399175 = r14399173 ? r14399174 : r14399171;
        double r14399176 = r14399161 ? r14399171 : r14399175;
        double r14399177 = r14399158 ? r14399159 : r14399176;
        return r14399177;
}

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.3
Target0.1
Herbie5.4
\[\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 < -1.1564294007415584e+23

    1. Initial program 35.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-exp35.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 associate-/l*34.5

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

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

    if -1.1564294007415584e+23 < y < -4.9781449920664e-177 or 1.0919689144745608e-199 < y

    1. Initial program 4.2

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

      \[\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 associate-/l*4.7

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

    if -4.9781449920664e-177 < y < 1.0919689144745608e-199

    1. Initial program 30.0

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

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

      \[\leadsto \color{blue}{1}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification5.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.1564294007415584 \cdot 10^{+23}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -4.9781449920664 \cdot 10^{-177}:\\ \;\;\;\;\log \left(e^{\frac{x - y}{\frac{x \cdot x + y \cdot y}{y + x}}}\right)\\ \mathbf{elif}\;y \le 1.0919689144745608 \cdot 10^{-199}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{\frac{x - y}{\frac{x \cdot x + y \cdot y}{y + x}}}\right)\\ \end{array}\]

Reproduce

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