Average Error: 32.6 → 12.9
Time: 1.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}\;x \le -3.759129799435656048380758639203459110241 \cdot 10^{141}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -6.751306280841241990574366329684766225048 \cdot 10^{-71}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\right)}^{3}}\\ \mathbf{elif}\;x \le 8.488500927325731364094840215005056497754 \cdot 10^{-70}:\\ \;\;\;\;\sqrt[3]{-1}\\ \mathbf{elif}\;x \le 5.311417125820034023983251080218725430022 \cdot 10^{136}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\right)}^{3}}\\ \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 \le -3.759129799435656048380758639203459110241 \cdot 10^{141}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le -6.751306280841241990574366329684766225048 \cdot 10^{-71}:\\
\;\;\;\;\sqrt[3]{{\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\right)}^{3}}\\

\mathbf{elif}\;x \le 8.488500927325731364094840215005056497754 \cdot 10^{-70}:\\
\;\;\;\;\sqrt[3]{-1}\\

\mathbf{elif}\;x \le 5.311417125820034023983251080218725430022 \cdot 10^{136}:\\
\;\;\;\;\sqrt[3]{{\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\right)}^{3}}\\

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

\end{array}
double f(double x, double y) {
        double r722027 = x;
        double r722028 = r722027 * r722027;
        double r722029 = y;
        double r722030 = 4.0;
        double r722031 = r722029 * r722030;
        double r722032 = r722031 * r722029;
        double r722033 = r722028 - r722032;
        double r722034 = r722028 + r722032;
        double r722035 = r722033 / r722034;
        return r722035;
}

double f(double x, double y) {
        double r722036 = x;
        double r722037 = -3.759129799435656e+141;
        bool r722038 = r722036 <= r722037;
        double r722039 = 1.0;
        double r722040 = -6.751306280841242e-71;
        bool r722041 = r722036 <= r722040;
        double r722042 = r722036 * r722036;
        double r722043 = y;
        double r722044 = 4.0;
        double r722045 = r722043 * r722044;
        double r722046 = r722045 * r722043;
        double r722047 = r722042 - r722046;
        double r722048 = fma(r722036, r722036, r722046);
        double r722049 = r722047 / r722048;
        double r722050 = 3.0;
        double r722051 = pow(r722049, r722050);
        double r722052 = cbrt(r722051);
        double r722053 = 8.488500927325731e-70;
        bool r722054 = r722036 <= r722053;
        double r722055 = -1.0;
        double r722056 = cbrt(r722055);
        double r722057 = 5.311417125820034e+136;
        bool r722058 = r722036 <= r722057;
        double r722059 = r722058 ? r722052 : r722039;
        double r722060 = r722054 ? r722056 : r722059;
        double r722061 = r722041 ? r722052 : r722060;
        double r722062 = r722038 ? r722039 : r722061;
        return r722062;
}

Error

Bits error versus x

Bits error versus y

Target

Original32.6
Target32.2
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.9743233849626781184483093056769575923681:\\ \;\;\;\;\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 x < -3.759129799435656e+141 or 5.311417125820034e+136 < x

    1. Initial program 60.2

      \[\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.1

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

    if -3.759129799435656e+141 < x < -6.751306280841242e-71 or 8.488500927325731e-70 < x < 5.311417125820034e+136

    1. Initial program 16.8

      \[\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-cbrt-cube44.0

      \[\leadsto \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{\sqrt[3]{\left(\left(x \cdot x + \left(y \cdot 4\right) \cdot y\right) \cdot \left(x \cdot x + \left(y \cdot 4\right) \cdot y\right)\right) \cdot \left(x \cdot x + \left(y \cdot 4\right) \cdot y\right)}}}\]
    4. Applied add-cbrt-cube44.5

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

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

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

    if -6.751306280841242e-71 < x < 8.488500927325731e-70

    1. Initial program 26.3

      \[\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-cbrt-cube53.6

      \[\leadsto \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{\sqrt[3]{\left(\left(x \cdot x + \left(y \cdot 4\right) \cdot y\right) \cdot \left(x \cdot x + \left(y \cdot 4\right) \cdot y\right)\right) \cdot \left(x \cdot x + \left(y \cdot 4\right) \cdot y\right)}}}\]
    4. Applied add-cbrt-cube53.7

      \[\leadsto \frac{\color{blue}{\sqrt[3]{\left(\left(x \cdot x - \left(y \cdot 4\right) \cdot y\right) \cdot \left(x \cdot x - \left(y \cdot 4\right) \cdot y\right)\right) \cdot \left(x \cdot x - \left(y \cdot 4\right) \cdot y\right)}}}{\sqrt[3]{\left(\left(x \cdot x + \left(y \cdot 4\right) \cdot y\right) \cdot \left(x \cdot x + \left(y \cdot 4\right) \cdot y\right)\right) \cdot \left(x \cdot x + \left(y \cdot 4\right) \cdot y\right)}}\]
    5. Applied cbrt-undiv53.7

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.759129799435656048380758639203459110241 \cdot 10^{141}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -6.751306280841241990574366329684766225048 \cdot 10^{-71}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\right)}^{3}}\\ \mathbf{elif}\;x \le 8.488500927325731364094840215005056497754 \cdot 10^{-70}:\\ \;\;\;\;\sqrt[3]{-1}\\ \mathbf{elif}\;x \le 5.311417125820034023983251080218725430022 \cdot 10^{136}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\right)}^{3}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

herbie shell --seed 2020002 +o rules:numerics
(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))))