Average Error: 31.5 → 12.9
Time: 4.9s
Precision: 64
\[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;\left(y \cdot 4\right) \cdot y \le 0.0:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.13987502238960696 \cdot 10^{-246}:\\ \;\;\;\;\log \left(e^{\frac{\mathsf{fma}\left(x, x, -y \cdot \left(y \cdot 4\right)\right)}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\right)\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.2562717583378653 \cdot 10^{-105}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.0689823296404604 \cdot 10^{291}:\\ \;\;\;\;\log \left(e^{\frac{\mathsf{fma}\left(x, x, -y \cdot \left(y \cdot 4\right)\right)}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]
\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\begin{array}{l}
\mathbf{if}\;\left(y \cdot 4\right) \cdot y \le 0.0:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.13987502238960696 \cdot 10^{-246}:\\
\;\;\;\;\log \left(e^{\frac{\mathsf{fma}\left(x, x, -y \cdot \left(y \cdot 4\right)\right)}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\right)\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.2562717583378653 \cdot 10^{-105}:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.0689823296404604 \cdot 10^{291}:\\
\;\;\;\;\log \left(e^{\frac{\mathsf{fma}\left(x, x, -y \cdot \left(y \cdot 4\right)\right)}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\right)\\

\mathbf{else}:\\
\;\;\;\;-1\\

\end{array}
double f(double x, double y) {
        double r839274 = x;
        double r839275 = r839274 * r839274;
        double r839276 = y;
        double r839277 = 4.0;
        double r839278 = r839276 * r839277;
        double r839279 = r839278 * r839276;
        double r839280 = r839275 - r839279;
        double r839281 = r839275 + r839279;
        double r839282 = r839280 / r839281;
        return r839282;
}

double f(double x, double y) {
        double r839283 = y;
        double r839284 = 4.0;
        double r839285 = r839283 * r839284;
        double r839286 = r839285 * r839283;
        double r839287 = 0.0;
        bool r839288 = r839286 <= r839287;
        double r839289 = 1.0;
        double r839290 = 2.139875022389607e-246;
        bool r839291 = r839286 <= r839290;
        double r839292 = x;
        double r839293 = r839283 * r839285;
        double r839294 = -r839293;
        double r839295 = fma(r839292, r839292, r839294);
        double r839296 = fma(r839292, r839292, r839286);
        double r839297 = r839295 / r839296;
        double r839298 = exp(r839297);
        double r839299 = log(r839298);
        double r839300 = 1.2562717583378653e-105;
        bool r839301 = r839286 <= r839300;
        double r839302 = 1.0689823296404604e+291;
        bool r839303 = r839286 <= r839302;
        double r839304 = -1.0;
        double r839305 = r839303 ? r839299 : r839304;
        double r839306 = r839301 ? r839289 : r839305;
        double r839307 = r839291 ? r839299 : r839306;
        double r839308 = r839288 ? r839289 : r839307;
        return r839308;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.5
Target31.2
Herbie12.9
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \lt 0.974323384962678118:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot y\right) \cdot 4} - \frac{\left(y \cdot y\right) \cdot 4}{x \cdot x + \left(y \cdot y\right) \cdot 4}\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{x}{\sqrt{x \cdot x + \left(y \cdot y\right) \cdot 4}}\right)}^{2} - \frac{\left(y \cdot y\right) \cdot 4}{x \cdot x + \left(y \cdot y\right) \cdot 4}\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if (* (* y 4.0) y) < 0.0 or 2.139875022389607e-246 < (* (* y 4.0) y) < 1.2562717583378653e-105

    1. Initial program 25.7

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

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

      \[\leadsto \log \color{blue}{\left(e^{\frac{\mathsf{fma}\left(x, x, -y \cdot \left(y \cdot 4\right)\right)}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\right)}\]
    5. Taylor expanded around inf 12.7

      \[\leadsto \log \color{blue}{e}\]

    if 0.0 < (* (* y 4.0) y) < 2.139875022389607e-246 or 1.2562717583378653e-105 < (* (* y 4.0) y) < 1.0689823296404604e+291

    1. Initial program 15.5

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

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

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

    if 1.0689823296404604e+291 < (* (* y 4.0) y)

    1. Initial program 61.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(y \cdot 4\right) \cdot y \le 0.0:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.13987502238960696 \cdot 10^{-246}:\\ \;\;\;\;\log \left(e^{\frac{\mathsf{fma}\left(x, x, -y \cdot \left(y \cdot 4\right)\right)}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\right)\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.2562717583378653 \cdot 10^{-105}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.0689823296404604 \cdot 10^{291}:\\ \;\;\;\;\log \left(e^{\frac{\mathsf{fma}\left(x, x, -y \cdot \left(y \cdot 4\right)\right)}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\right)\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

herbie shell --seed 2020042 +o rules:numerics
(FPCore (x y)
  :name "Diagrams.TwoD.Arc:arcBetween from diagrams-lib-1.3.0.3"
  :precision binary64

  :herbie-target
  (if (< (/ (- (* x x) (* (* y 4) y)) (+ (* x x) (* (* y 4) y))) 0.9743233849626781) (- (/ (* x x) (+ (* x x) (* (* y y) 4))) (/ (* (* y y) 4) (+ (* x x) (* (* y y) 4)))) (- (pow (/ x (sqrt (+ (* x x) (* (* y y) 4)))) 2) (/ (* (* y y) 4) (+ (* x x) (* (* y y) 4)))))

  (/ (- (* x x) (* (* y 4) y)) (+ (* x x) (* (* y 4) y))))