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 r314534 = x;
        double r314535 = r314534 * r314534;
        double r314536 = y;
        double r314537 = 4.0;
        double r314538 = r314536 * r314537;
        double r314539 = r314538 * r314536;
        double r314540 = r314535 - r314539;
        double r314541 = r314535 + r314539;
        double r314542 = r314540 / r314541;
        return r314542;
}

double f(double x, double y) {
        double r314543 = y;
        double r314544 = 4.0;
        double r314545 = r314543 * r314544;
        double r314546 = r314545 * r314543;
        double r314547 = 0.0;
        bool r314548 = r314546 <= r314547;
        double r314549 = 1.0;
        double r314550 = 2.139875022389607e-246;
        bool r314551 = r314546 <= r314550;
        double r314552 = x;
        double r314553 = r314543 * r314545;
        double r314554 = -r314553;
        double r314555 = fma(r314552, r314552, r314554);
        double r314556 = fma(r314552, r314552, r314546);
        double r314557 = r314555 / r314556;
        double r314558 = exp(r314557);
        double r314559 = log(r314558);
        double r314560 = 1.2562717583378653e-105;
        bool r314561 = r314546 <= r314560;
        double r314562 = 1.0689823296404604e+291;
        bool r314563 = r314546 <= r314562;
        double r314564 = -1.0;
        double r314565 = r314563 ? r314559 : r314564;
        double r314566 = r314561 ? r314549 : r314565;
        double r314567 = r314551 ? r314559 : r314566;
        double r314568 = r314548 ? r314549 : r314567;
        return r314568;
}

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. Taylor expanded around inf 12.7

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

    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))))