Average Error: 31.8 → 14.1
Time: 2.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}\;y \le -3.4362841072323272 \cdot 10^{150}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -3.8396732637812812 \cdot 10^{-74}:\\ \;\;\;\;\frac{\frac{1}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}{\frac{1}{x \cdot x - \left(y \cdot 4\right) \cdot y}}\\ \mathbf{elif}\;y \le 1.41284087263746274 \cdot 10^{-110}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 4.54642378775940041 \cdot 10^{-26}:\\ \;\;\;\;\frac{\frac{1}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}{\frac{1}{x \cdot x - \left(y \cdot 4\right) \cdot y}}\\ \mathbf{elif}\;y \le 2.97781259123946345 \cdot 10^{57}:\\ \;\;\;\;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}\;y \le -3.4362841072323272 \cdot 10^{150}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;y \le 1.41284087263746274 \cdot 10^{-110}:\\
\;\;\;\;1\\

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

\mathbf{elif}\;y \le 2.97781259123946345 \cdot 10^{57}:\\
\;\;\;\;1\\

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

\end{array}
double f(double x, double y) {
        double r732911 = x;
        double r732912 = r732911 * r732911;
        double r732913 = y;
        double r732914 = 4.0;
        double r732915 = r732913 * r732914;
        double r732916 = r732915 * r732913;
        double r732917 = r732912 - r732916;
        double r732918 = r732912 + r732916;
        double r732919 = r732917 / r732918;
        return r732919;
}

double f(double x, double y) {
        double r732920 = y;
        double r732921 = -3.436284107232327e+150;
        bool r732922 = r732920 <= r732921;
        double r732923 = -1.0;
        double r732924 = -3.839673263781281e-74;
        bool r732925 = r732920 <= r732924;
        double r732926 = 1.0;
        double r732927 = x;
        double r732928 = 4.0;
        double r732929 = r732920 * r732928;
        double r732930 = r732929 * r732920;
        double r732931 = fma(r732927, r732927, r732930);
        double r732932 = r732926 / r732931;
        double r732933 = r732927 * r732927;
        double r732934 = r732933 - r732930;
        double r732935 = r732926 / r732934;
        double r732936 = r732932 / r732935;
        double r732937 = 1.4128408726374627e-110;
        bool r732938 = r732920 <= r732937;
        double r732939 = 4.5464237877594004e-26;
        bool r732940 = r732920 <= r732939;
        double r732941 = 2.9778125912394635e+57;
        bool r732942 = r732920 <= r732941;
        double r732943 = r732942 ? r732926 : r732923;
        double r732944 = r732940 ? r732936 : r732943;
        double r732945 = r732938 ? r732926 : r732944;
        double r732946 = r732925 ? r732936 : r732945;
        double r732947 = r732922 ? r732923 : r732946;
        return r732947;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.8
Target31.5
Herbie14.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 < -3.436284107232327e+150 or 2.9778125912394635e+57 < y

    1. Initial program 51.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 clear-num51.9

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

      \[\leadsto \frac{1}{\color{blue}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x \cdot x - \left(y \cdot 4\right) \cdot y}}}\]
    5. Using strategy rm
    6. Applied div-inv52.0

      \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right) \cdot \frac{1}{x \cdot x - \left(y \cdot 4\right) \cdot y}}}\]
    7. Applied associate-/r*51.9

      \[\leadsto \color{blue}{\frac{\frac{1}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}{\frac{1}{x \cdot x - \left(y \cdot 4\right) \cdot y}}}\]
    8. Taylor expanded around 0 12.1

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

    if -3.436284107232327e+150 < y < -3.839673263781281e-74 or 1.4128408726374627e-110 < y < 4.5464237877594004e-26

    1. Initial program 15.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 clear-num15.5

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

      \[\leadsto \frac{1}{\color{blue}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x \cdot x - \left(y \cdot 4\right) \cdot y}}}\]
    5. Using strategy rm
    6. Applied div-inv15.6

      \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right) \cdot \frac{1}{x \cdot x - \left(y \cdot 4\right) \cdot y}}}\]
    7. Applied associate-/r*15.5

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

    if -3.839673263781281e-74 < y < 1.4128408726374627e-110 or 4.5464237877594004e-26 < y < 2.9778125912394635e+57

    1. Initial program 24.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 14.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -3.4362841072323272 \cdot 10^{150}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -3.8396732637812812 \cdot 10^{-74}:\\ \;\;\;\;\frac{\frac{1}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}{\frac{1}{x \cdot x - \left(y \cdot 4\right) \cdot y}}\\ \mathbf{elif}\;y \le 1.41284087263746274 \cdot 10^{-110}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 4.54642378775940041 \cdot 10^{-26}:\\ \;\;\;\;\frac{\frac{1}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}{\frac{1}{x \cdot x - \left(y \cdot 4\right) \cdot y}}\\ \mathbf{elif}\;y \le 2.97781259123946345 \cdot 10^{57}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

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