Average Error: 31.8 → 15.1
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}\;\left(y \cdot 4\right) \cdot y \le 5.5059358999267487 \cdot 10^{-179}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 6.0996771267235233 \cdot 10^{98}:\\ \;\;\;\;\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}\;\left(y \cdot 4\right) \cdot y \le 2.69891227082106497 \cdot 10^{230}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{{-1}^{3}}\\ \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}\;\left(y \cdot 4\right) \cdot y \le 5.5059358999267487 \cdot 10^{-179}:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 6.0996771267235233 \cdot 10^{98}:\\
\;\;\;\;\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}\;\left(y \cdot 4\right) \cdot y \le 2.69891227082106497 \cdot 10^{230}:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;\sqrt[3]{{-1}^{3}}\\

\end{array}
double f(double x, double y) {
        double r749992 = x;
        double r749993 = r749992 * r749992;
        double r749994 = y;
        double r749995 = 4.0;
        double r749996 = r749994 * r749995;
        double r749997 = r749996 * r749994;
        double r749998 = r749993 - r749997;
        double r749999 = r749993 + r749997;
        double r750000 = r749998 / r749999;
        return r750000;
}

double f(double x, double y) {
        double r750001 = y;
        double r750002 = 4.0;
        double r750003 = r750001 * r750002;
        double r750004 = r750003 * r750001;
        double r750005 = 5.505935899926749e-179;
        bool r750006 = r750004 <= r750005;
        double r750007 = 1.0;
        double r750008 = 6.099677126723523e+98;
        bool r750009 = r750004 <= r750008;
        double r750010 = x;
        double r750011 = r750010 * r750010;
        double r750012 = r750011 - r750004;
        double r750013 = fma(r750010, r750010, r750004);
        double r750014 = r750012 / r750013;
        double r750015 = 3.0;
        double r750016 = pow(r750014, r750015);
        double r750017 = cbrt(r750016);
        double r750018 = 2.698912270821065e+230;
        bool r750019 = r750004 <= r750018;
        double r750020 = -1.0;
        double r750021 = pow(r750020, r750015);
        double r750022 = cbrt(r750021);
        double r750023 = r750019 ? r750007 : r750022;
        double r750024 = r750009 ? r750017 : r750023;
        double r750025 = r750006 ? r750007 : r750024;
        return r750025;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.8
Target31.5
Herbie15.1
\[\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 3 regimes
  2. if (* (* y 4.0) y) < 5.505935899926749e-179 or 6.099677126723523e+98 < (* (* y 4.0) y) < 2.698912270821065e+230

    1. Initial program 23.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 inf 17.9

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

    if 5.505935899926749e-179 < (* (* y 4.0) y) < 6.099677126723523e+98

    1. Initial program 16.5

      \[\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-cube34.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-cube34.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-undiv34.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.5

      \[\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 2.698912270821065e+230 < (* (* y 4.0) y)

    1. Initial program 53.9

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

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

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

      \[\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. Simplified53.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(y \cdot 4\right) \cdot y \le 5.5059358999267487 \cdot 10^{-179}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 6.0996771267235233 \cdot 10^{98}:\\ \;\;\;\;\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}\;\left(y \cdot 4\right) \cdot y \le 2.69891227082106497 \cdot 10^{230}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{{-1}^{3}}\\ \end{array}\]

Reproduce

herbie shell --seed 2020018 +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))))