Average Error: 31.9 → 15.7
Time: 3.2s
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.9547679581202103 \cdot 10^{27}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -7.8905969189111263 \cdot 10^{-23}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -3.246960260390424 \cdot 10^{-67}:\\ \;\;\;\;\frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \frac{y \cdot 4}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{y}}\\ \mathbf{elif}\;x \le -4.3884605229815477 \cdot 10^{-101}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -3.49297723193740726 \cdot 10^{-162}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)\right)\\ \mathbf{elif}\;x \le 1.9844193705891298 \cdot 10^{-132}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 9.97051040847491787 \cdot 10^{-75}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)\right)\\ \mathbf{elif}\;x \le 3.09444041521077753 \cdot 10^{89}:\\ \;\;\;\;-1\\ \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.9547679581202103 \cdot 10^{27}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le -7.8905969189111263 \cdot 10^{-23}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le -3.246960260390424 \cdot 10^{-67}:\\
\;\;\;\;\frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \frac{y \cdot 4}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{y}}\\

\mathbf{elif}\;x \le -4.3884605229815477 \cdot 10^{-101}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le -3.49297723193740726 \cdot 10^{-162}:\\
\;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)\right)\\

\mathbf{elif}\;x \le 1.9844193705891298 \cdot 10^{-132}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le 9.97051040847491787 \cdot 10^{-75}:\\
\;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)\right)\\

\mathbf{elif}\;x \le 3.09444041521077753 \cdot 10^{89}:\\
\;\;\;\;-1\\

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

\end{array}
double f(double x, double y) {
        double r607901 = x;
        double r607902 = r607901 * r607901;
        double r607903 = y;
        double r607904 = 4.0;
        double r607905 = r607903 * r607904;
        double r607906 = r607905 * r607903;
        double r607907 = r607902 - r607906;
        double r607908 = r607902 + r607906;
        double r607909 = r607907 / r607908;
        return r607909;
}

double f(double x, double y) {
        double r607910 = x;
        double r607911 = -3.9547679581202103e+27;
        bool r607912 = r607910 <= r607911;
        double r607913 = 1.0;
        double r607914 = -7.890596918911126e-23;
        bool r607915 = r607910 <= r607914;
        double r607916 = -1.0;
        double r607917 = -3.2469602603904245e-67;
        bool r607918 = r607910 <= r607917;
        double r607919 = y;
        double r607920 = 4.0;
        double r607921 = r607919 * r607920;
        double r607922 = r607921 * r607919;
        double r607923 = fma(r607910, r607910, r607922);
        double r607924 = r607923 / r607910;
        double r607925 = r607910 / r607924;
        double r607926 = r607923 / r607919;
        double r607927 = r607921 / r607926;
        double r607928 = r607925 - r607927;
        double r607929 = -4.388460522981548e-101;
        bool r607930 = r607910 <= r607929;
        double r607931 = -3.4929772319374073e-162;
        bool r607932 = r607910 <= r607931;
        double r607933 = r607910 * r607910;
        double r607934 = r607933 - r607922;
        double r607935 = r607933 + r607922;
        double r607936 = r607934 / r607935;
        double r607937 = log1p(r607936);
        double r607938 = expm1(r607937);
        double r607939 = 1.98441937058913e-132;
        bool r607940 = r607910 <= r607939;
        double r607941 = 9.970510408474918e-75;
        bool r607942 = r607910 <= r607941;
        double r607943 = 3.0944404152107775e+89;
        bool r607944 = r607910 <= r607943;
        double r607945 = r607944 ? r607916 : r607913;
        double r607946 = r607942 ? r607938 : r607945;
        double r607947 = r607940 ? r607916 : r607946;
        double r607948 = r607932 ? r607938 : r607947;
        double r607949 = r607930 ? r607916 : r607948;
        double r607950 = r607918 ? r607928 : r607949;
        double r607951 = r607915 ? r607916 : r607950;
        double r607952 = r607912 ? r607913 : r607951;
        return r607952;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.9
Target31.6
Herbie15.7
\[\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 < -3.9547679581202103e+27 or 3.0944404152107775e+89 < x

    1. Initial program 46.6

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

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

    if -3.9547679581202103e+27 < x < -7.890596918911126e-23 or -3.2469602603904245e-67 < x < -4.388460522981548e-101 or -3.4929772319374073e-162 < x < 1.98441937058913e-132 or 9.970510408474918e-75 < x < 3.0944404152107775e+89

    1. Initial program 23.9

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

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

    if -7.890596918911126e-23 < x < -3.2469602603904245e-67

    1. Initial program 15.1

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

      \[\leadsto \color{blue}{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\]
    4. Simplified15.2

      \[\leadsto \color{blue}{\frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}}} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    5. Simplified14.7

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

    if -4.388460522981548e-101 < x < -3.4929772319374073e-162 or 1.98441937058913e-132 < x < 9.970510408474918e-75

    1. Initial program 13.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 expm1-log1p-u13.4

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)\right)}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification15.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.9547679581202103 \cdot 10^{27}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -7.8905969189111263 \cdot 10^{-23}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -3.246960260390424 \cdot 10^{-67}:\\ \;\;\;\;\frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \frac{y \cdot 4}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{y}}\\ \mathbf{elif}\;x \le -4.3884605229815477 \cdot 10^{-101}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -3.49297723193740726 \cdot 10^{-162}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)\right)\\ \mathbf{elif}\;x \le 1.9844193705891298 \cdot 10^{-132}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 9.97051040847491787 \cdot 10^{-75}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)\right)\\ \mathbf{elif}\;x \le 3.09444041521077753 \cdot 10^{89}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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