Average Error: 30.3 → 12.0
Time: 11.0s
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 r31317406 = x;
        double r31317407 = r31317406 * r31317406;
        double r31317408 = y;
        double r31317409 = 4.0;
        double r31317410 = r31317408 * r31317409;
        double r31317411 = r31317410 * r31317408;
        double r31317412 = r31317407 - r31317411;
        double r31317413 = r31317407 + r31317411;
        double r31317414 = r31317412 / r31317413;
        return r31317414;
}

double f(double x, double y) {
        double r31317415 = y;
        double r31317416 = -6.641800154736106e+153;
        bool r31317417 = r31317415 <= r31317416;
        double r31317418 = -1.0;
        double r31317419 = -2.981255488591297e-134;
        bool r31317420 = r31317415 <= r31317419;
        double r31317421 = x;
        double r31317422 = r31317421 * r31317421;
        double r31317423 = 4.0;
        double r31317424 = r31317415 * r31317423;
        double r31317425 = r31317424 * r31317415;
        double r31317426 = r31317422 + r31317425;
        double r31317427 = r31317422 / r31317426;
        double r31317428 = sqrt(r31317427);
        double r31317429 = r31317428 * r31317428;
        double r31317430 = r31317425 / r31317426;
        double r31317431 = r31317429 - r31317430;
        double r31317432 = 2.0369408682057436e-95;
        bool r31317433 = r31317415 <= r31317432;
        double r31317434 = 1.0;
        double r31317435 = 1.6131348038947783e+108;
        bool r31317436 = r31317415 <= r31317435;
        double r31317437 = r31317436 ? r31317431 : r31317418;
        double r31317438 = r31317433 ? r31317434 : r31317437;
        double r31317439 = r31317420 ? r31317431 : r31317438;
        double r31317440 = r31317417 ? r31317418 : r31317439;
        return r31317440;
}

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