Average Error: 30.3 → 12.0
Time: 14.4s
Precision: 64
\[\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;y \le -6.641800154736106 \cdot 10^{+153}:\\ \;\;\;\;-1.0\\ \mathbf{elif}\;y \le -2.981255488591297 \cdot 10^{-134}:\\ \;\;\;\;\sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}} \cdot \sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}} - \frac{\left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\\ \mathbf{elif}\;y \le 2.0369408682057436 \cdot 10^{-95}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 1.6131348038947783 \cdot 10^{+108}:\\ \;\;\;\;\sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}} \cdot \sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}} - \frac{\left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\\ \mathbf{else}:\\ \;\;\;\;-1.0\\ \end{array}\]
\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}
\begin{array}{l}
\mathbf{if}\;y \le -6.641800154736106 \cdot 10^{+153}:\\
\;\;\;\;-1.0\\

\mathbf{elif}\;y \le -2.981255488591297 \cdot 10^{-134}:\\
\;\;\;\;\sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}} \cdot \sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}} - \frac{\left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\\

\mathbf{elif}\;y \le 2.0369408682057436 \cdot 10^{-95}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le 1.6131348038947783 \cdot 10^{+108}:\\
\;\;\;\;\sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}} \cdot \sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}} - \frac{\left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r20386500 = x;
        double r20386501 = r20386500 * r20386500;
        double r20386502 = y;
        double r20386503 = 4.0;
        double r20386504 = r20386502 * r20386503;
        double r20386505 = r20386504 * r20386502;
        double r20386506 = r20386501 - r20386505;
        double r20386507 = r20386501 + r20386505;
        double r20386508 = r20386506 / r20386507;
        return r20386508;
}

double f(double x, double y) {
        double r20386509 = y;
        double r20386510 = -6.641800154736106e+153;
        bool r20386511 = r20386509 <= r20386510;
        double r20386512 = -1.0;
        double r20386513 = -2.981255488591297e-134;
        bool r20386514 = r20386509 <= r20386513;
        double r20386515 = x;
        double r20386516 = r20386515 * r20386515;
        double r20386517 = 4.0;
        double r20386518 = r20386509 * r20386517;
        double r20386519 = r20386518 * r20386509;
        double r20386520 = r20386516 + r20386519;
        double r20386521 = r20386516 / r20386520;
        double r20386522 = sqrt(r20386521);
        double r20386523 = r20386522 * r20386522;
        double r20386524 = r20386519 / r20386520;
        double r20386525 = r20386523 - r20386524;
        double r20386526 = 2.0369408682057436e-95;
        bool r20386527 = r20386509 <= r20386526;
        double r20386528 = 1.0;
        double r20386529 = 1.6131348038947783e+108;
        bool r20386530 = r20386509 <= r20386529;
        double r20386531 = r20386530 ? r20386525 : r20386512;
        double r20386532 = r20386527 ? r20386528 : r20386531;
        double r20386533 = r20386514 ? r20386525 : r20386532;
        double r20386534 = r20386511 ? r20386512 : r20386533;
        return r20386534;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original30.3
Target30.5
Herbie12.0
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y} \lt 0.9743233849626781:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot y\right) \cdot 4.0} - \frac{\left(y \cdot y\right) \cdot 4.0}{x \cdot x + \left(y \cdot y\right) \cdot 4.0}\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{x}{\sqrt{x \cdot x + \left(y \cdot y\right) \cdot 4.0}}\right)}^{2} - \frac{\left(y \cdot y\right) \cdot 4.0}{x \cdot x + \left(y \cdot y\right) \cdot 4.0}\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if y < -6.641800154736106e+153 or 1.6131348038947783e+108 < y

    1. Initial program 57.3

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

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

    if -6.641800154736106e+153 < y < -2.981255488591297e-134 or 2.0369408682057436e-95 < y < 1.6131348038947783e+108

    1. Initial program 15.1

      \[\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\]
    2. Using strategy rm
    3. Applied div-sub15.1

      \[\leadsto \color{blue}{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4.0\right) \cdot y} - \frac{\left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}}\]
    4. Using strategy rm
    5. Applied add-sqr-sqrt15.1

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

    if -2.981255488591297e-134 < y < 2.0369408682057436e-95

    1. Initial program 25.3

      \[\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\]
    2. Taylor expanded around inf 10.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -6.641800154736106 \cdot 10^{+153}:\\ \;\;\;\;-1.0\\ \mathbf{elif}\;y \le -2.981255488591297 \cdot 10^{-134}:\\ \;\;\;\;\sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}} \cdot \sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}} - \frac{\left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\\ \mathbf{elif}\;y \le 2.0369408682057436 \cdot 10^{-95}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 1.6131348038947783 \cdot 10^{+108}:\\ \;\;\;\;\sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}} \cdot \sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}} - \frac{\left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\\ \mathbf{else}:\\ \;\;\;\;-1.0\\ \end{array}\]

Reproduce

herbie shell --seed 2019158 +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) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))))

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