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

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

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

\end{array}
double f(double x, double y) {
        double r892192 = x;
        double r892193 = r892192 * r892192;
        double r892194 = y;
        double r892195 = 4.0;
        double r892196 = r892194 * r892195;
        double r892197 = r892196 * r892194;
        double r892198 = r892193 - r892197;
        double r892199 = r892193 + r892197;
        double r892200 = r892198 / r892199;
        return r892200;
}

double f(double x, double y) {
        double r892201 = y;
        double r892202 = -3.436284107232327e+150;
        bool r892203 = r892201 <= r892202;
        double r892204 = 1.0;
        double r892205 = -1.0;
        double r892206 = r892204 / r892205;
        double r892207 = -3.839673263781281e-74;
        bool r892208 = r892201 <= r892207;
        double r892209 = x;
        double r892210 = 4.0;
        double r892211 = r892201 * r892210;
        double r892212 = r892211 * r892201;
        double r892213 = fma(r892209, r892209, r892212);
        double r892214 = r892204 / r892213;
        double r892215 = r892209 * r892209;
        double r892216 = r892215 - r892212;
        double r892217 = r892204 / r892216;
        double r892218 = r892214 / r892217;
        double r892219 = 1.4128408726374627e-110;
        bool r892220 = r892201 <= r892219;
        double r892221 = 4.5464237877594004e-26;
        bool r892222 = r892201 <= r892221;
        double r892223 = r892213 / r892216;
        double r892224 = r892204 / r892223;
        double r892225 = 2.9778125912394635e+57;
        bool r892226 = r892201 <= r892225;
        double r892227 = r892226 ? r892204 : r892206;
        double r892228 = r892222 ? r892224 : r892227;
        double r892229 = r892220 ? r892204 : r892228;
        double r892230 = r892208 ? r892218 : r892229;
        double r892231 = r892203 ? r892206 : r892230;
        return r892231;
}

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 4 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. Taylor expanded around 0 12.1

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

    if -3.436284107232327e+150 < y < -3.839673263781281e-74

    1. Initial program 15.0

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

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

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

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

      \[\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}\]

    if 1.4128408726374627e-110 < y < 4.5464237877594004e-26

    1. Initial program 16.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-num16.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. Simplified16.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}}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification14.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -3.4362841072323272 \cdot 10^{150}:\\ \;\;\;\;\frac{1}{-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{1}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x \cdot x - \left(y \cdot 4\right) \cdot y}}\\ \mathbf{elif}\;y \le 2.97781259123946345 \cdot 10^{57}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{-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))))