Average Error: 32.0 → 13.4
Time: 5.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}\;y \le -7.0569493698564062 \cdot 10^{143}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.8443598935192776 \cdot 10^{-96}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\\ \mathbf{elif}\;y \le 1.233109040969588 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 3.41639119234388889 \cdot 10^{22}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\\ \mathbf{elif}\;y \le 1.04248377311991221 \cdot 10^{44}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 1.9431365563396376 \cdot 10^{50}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\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}\;y \le -7.0569493698564062 \cdot 10^{143}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -1.8443598935192776 \cdot 10^{-96}:\\
\;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\\

\mathbf{elif}\;y \le 1.233109040969588 \cdot 10^{-162}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le 3.41639119234388889 \cdot 10^{22}:\\
\;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\\

\mathbf{elif}\;y \le 1.04248377311991221 \cdot 10^{44}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le 1.9431365563396376 \cdot 10^{50}:\\
\;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\\

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

\end{array}
double f(double x, double y) {
        double r394285 = x;
        double r394286 = r394285 * r394285;
        double r394287 = y;
        double r394288 = 4.0;
        double r394289 = r394287 * r394288;
        double r394290 = r394289 * r394287;
        double r394291 = r394286 - r394290;
        double r394292 = r394286 + r394290;
        double r394293 = r394291 / r394292;
        return r394293;
}

double f(double x, double y) {
        double r394294 = y;
        double r394295 = -7.056949369856406e+143;
        bool r394296 = r394294 <= r394295;
        double r394297 = -1.0;
        double r394298 = -1.8443598935192776e-96;
        bool r394299 = r394294 <= r394298;
        double r394300 = x;
        double r394301 = r394300 * r394300;
        double r394302 = 4.0;
        double r394303 = r394294 * r394302;
        double r394304 = r394303 * r394294;
        double r394305 = r394301 - r394304;
        double r394306 = fma(r394300, r394300, r394304);
        double r394307 = r394305 / r394306;
        double r394308 = 1.2331090409695878e-162;
        bool r394309 = r394294 <= r394308;
        double r394310 = 1.0;
        double r394311 = 3.416391192343889e+22;
        bool r394312 = r394294 <= r394311;
        double r394313 = 1.0424837731199122e+44;
        bool r394314 = r394294 <= r394313;
        double r394315 = 1.9431365563396376e+50;
        bool r394316 = r394294 <= r394315;
        double r394317 = r394316 ? r394307 : r394297;
        double r394318 = r394314 ? r394310 : r394317;
        double r394319 = r394312 ? r394307 : r394318;
        double r394320 = r394309 ? r394310 : r394319;
        double r394321 = r394299 ? r394307 : r394320;
        double r394322 = r394296 ? r394297 : r394321;
        return r394322;
}

Error

Bits error versus x

Bits error versus y

Target

Original32.0
Target31.7
Herbie13.4
\[\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 < -7.056949369856406e+143 or 1.9431365563396376e+50 < y

    1. Initial program 51.9

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Simplified51.9

      \[\leadsto \color{blue}{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    3. Taylor expanded around 0 12.1

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

    if -7.056949369856406e+143 < y < -1.8443598935192776e-96 or 1.2331090409695878e-162 < y < 3.416391192343889e+22 or 1.0424837731199122e+44 < y < 1.9431365563396376e+50

    1. Initial program 16.0

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Simplified16.0

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

    if -1.8443598935192776e-96 < y < 1.2331090409695878e-162 or 3.416391192343889e+22 < y < 1.0424837731199122e+44

    1. Initial program 28.1

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Simplified28.1

      \[\leadsto \color{blue}{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    3. Taylor expanded around inf 11.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -7.0569493698564062 \cdot 10^{143}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.8443598935192776 \cdot 10^{-96}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\\ \mathbf{elif}\;y \le 1.233109040969588 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 3.41639119234388889 \cdot 10^{22}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\\ \mathbf{elif}\;y \le 1.04248377311991221 \cdot 10^{44}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 1.9431365563396376 \cdot 10^{50}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

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

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

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