Average Error: 31.8 → 12.9
Time: 2.3s
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}\;x \cdot x \le 9.283965764610774 \cdot 10^{-276}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 2.44021913495856318 \cdot 10^{-149}:\\ \;\;\;\;\left(\sqrt[3]{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}} \cdot \sqrt[3]{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right) \cdot \sqrt[3]{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\\ \mathbf{elif}\;x \cdot x \le 3.32968557572447191 \cdot 10^{-82}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 4.2506266048630395 \cdot 10^{263}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \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}\;x \cdot x \le 9.283965764610774 \cdot 10^{-276}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \cdot x \le 2.44021913495856318 \cdot 10^{-149}:\\
\;\;\;\;\left(\sqrt[3]{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}} \cdot \sqrt[3]{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right) \cdot \sqrt[3]{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\\

\mathbf{elif}\;x \cdot x \le 3.32968557572447191 \cdot 10^{-82}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \cdot x \le 4.2506266048630395 \cdot 10^{263}:\\
\;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r660584 = x;
        double r660585 = r660584 * r660584;
        double r660586 = y;
        double r660587 = 4.0;
        double r660588 = r660586 * r660587;
        double r660589 = r660588 * r660586;
        double r660590 = r660585 - r660589;
        double r660591 = r660585 + r660589;
        double r660592 = r660590 / r660591;
        return r660592;
}

double f(double x, double y) {
        double r660593 = x;
        double r660594 = r660593 * r660593;
        double r660595 = 9.283965764610774e-276;
        bool r660596 = r660594 <= r660595;
        double r660597 = -1.0;
        double r660598 = 2.440219134958563e-149;
        bool r660599 = r660594 <= r660598;
        double r660600 = y;
        double r660601 = 4.0;
        double r660602 = r660600 * r660601;
        double r660603 = r660602 * r660600;
        double r660604 = r660594 - r660603;
        double r660605 = r660594 + r660603;
        double r660606 = r660604 / r660605;
        double r660607 = cbrt(r660606);
        double r660608 = r660607 * r660607;
        double r660609 = r660608 * r660607;
        double r660610 = 3.329685575724472e-82;
        bool r660611 = r660594 <= r660610;
        double r660612 = 4.2506266048630395e+263;
        bool r660613 = r660594 <= r660612;
        double r660614 = 1.0;
        double r660615 = r660613 ? r660606 : r660614;
        double r660616 = r660611 ? r660597 : r660615;
        double r660617 = r660599 ? r660609 : r660616;
        double r660618 = r660596 ? r660597 : r660617;
        return r660618;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original31.8
Target31.5
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 4 regimes
  2. if (* x x) < 9.283965764610774e-276 or 2.440219134958563e-149 < (* x x) < 3.329685575724472e-82

    1. Initial program 27.8

      \[\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 12.0

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

    if 9.283965764610774e-276 < (* x x) < 2.440219134958563e-149

    1. Initial program 16.4

      \[\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-cube-cbrt16.4

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

    if 3.329685575724472e-82 < (* x x) < 4.2506266048630395e+263

    1. Initial program 15.9

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

    if 4.2506266048630395e+263 < (* x x)

    1. Initial program 58.0

      \[\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 9.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \le 9.283965764610774 \cdot 10^{-276}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 2.44021913495856318 \cdot 10^{-149}:\\ \;\;\;\;\left(\sqrt[3]{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}} \cdot \sqrt[3]{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right) \cdot \sqrt[3]{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\\ \mathbf{elif}\;x \cdot x \le 3.32968557572447191 \cdot 10^{-82}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 4.2506266048630395 \cdot 10^{263}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

herbie shell --seed 2020062 
(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))))