Average Error: 30.3 → 12.0
Time: 35.7s
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 r28257490 = x;
        double r28257491 = r28257490 * r28257490;
        double r28257492 = y;
        double r28257493 = 4.0;
        double r28257494 = r28257492 * r28257493;
        double r28257495 = r28257494 * r28257492;
        double r28257496 = r28257491 - r28257495;
        double r28257497 = r28257491 + r28257495;
        double r28257498 = r28257496 / r28257497;
        return r28257498;
}

double f(double x, double y) {
        double r28257499 = y;
        double r28257500 = -6.641800154736106e+153;
        bool r28257501 = r28257499 <= r28257500;
        double r28257502 = -1.0;
        double r28257503 = -2.981255488591297e-134;
        bool r28257504 = r28257499 <= r28257503;
        double r28257505 = x;
        double r28257506 = r28257505 * r28257505;
        double r28257507 = 4.0;
        double r28257508 = r28257499 * r28257507;
        double r28257509 = r28257508 * r28257499;
        double r28257510 = r28257506 + r28257509;
        double r28257511 = r28257506 / r28257510;
        double r28257512 = sqrt(r28257511);
        double r28257513 = r28257512 * r28257512;
        double r28257514 = r28257509 / r28257510;
        double r28257515 = r28257513 - r28257514;
        double r28257516 = 2.0369408682057436e-95;
        bool r28257517 = r28257499 <= r28257516;
        double r28257518 = 1.0;
        double r28257519 = 1.6131348038947783e+108;
        bool r28257520 = r28257499 <= r28257519;
        double r28257521 = r28257520 ? r28257515 : r28257502;
        double r28257522 = r28257517 ? r28257518 : r28257521;
        double r28257523 = r28257504 ? r28257515 : r28257522;
        double r28257524 = r28257501 ? r28257502 : r28257523;
        return r28257524;
}

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