Average Error: 32.0 → 12.6
Time: 6.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 -1.15431295039553488213566106957485115951 \cdot 10^{123}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -1.049461047373995695414776940334688667457 \cdot 10^{-90}:\\ \;\;\;\;\frac{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\sqrt{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}}{\sqrt{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\\ \mathbf{elif}\;x \le 5.481288829847034474742950694868171684444 \cdot 10^{-119}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 7.251238886375513779793874451315946152856 \cdot 10^{-42}:\\ \;\;\;\;\frac{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\sqrt{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}}{\sqrt{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\\ \mathbf{elif}\;x \le 2.637073173922210812467059604102814773796 \cdot 10^{-4}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 4.73515077677864244964006142406283884833 \cdot 10^{127}:\\ \;\;\;\;\frac{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\sqrt{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}}{\sqrt{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\\ \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 -1.15431295039553488213566106957485115951 \cdot 10^{123}:\\
\;\;\;\;1\\

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

\mathbf{elif}\;x \le 5.481288829847034474742950694868171684444 \cdot 10^{-119}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;x \le 2.637073173922210812467059604102814773796 \cdot 10^{-4}:\\
\;\;\;\;-1\\

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

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

\end{array}
double f(double x, double y) {
        double r511295 = x;
        double r511296 = r511295 * r511295;
        double r511297 = y;
        double r511298 = 4.0;
        double r511299 = r511297 * r511298;
        double r511300 = r511299 * r511297;
        double r511301 = r511296 - r511300;
        double r511302 = r511296 + r511300;
        double r511303 = r511301 / r511302;
        return r511303;
}

double f(double x, double y) {
        double r511304 = x;
        double r511305 = -1.1543129503955349e+123;
        bool r511306 = r511304 <= r511305;
        double r511307 = 1.0;
        double r511308 = -1.0494610473739957e-90;
        bool r511309 = r511304 <= r511308;
        double r511310 = r511304 * r511304;
        double r511311 = y;
        double r511312 = 4.0;
        double r511313 = r511311 * r511312;
        double r511314 = r511313 * r511311;
        double r511315 = r511310 - r511314;
        double r511316 = fma(r511304, r511304, r511314);
        double r511317 = sqrt(r511316);
        double r511318 = r511315 / r511317;
        double r511319 = r511318 / r511317;
        double r511320 = 5.481288829847034e-119;
        bool r511321 = r511304 <= r511320;
        double r511322 = -1.0;
        double r511323 = 7.251238886375514e-42;
        bool r511324 = r511304 <= r511323;
        double r511325 = 0.0002637073173922211;
        bool r511326 = r511304 <= r511325;
        double r511327 = 4.735150776778642e+127;
        bool r511328 = r511304 <= r511327;
        double r511329 = r511328 ? r511319 : r511307;
        double r511330 = r511326 ? r511322 : r511329;
        double r511331 = r511324 ? r511319 : r511330;
        double r511332 = r511321 ? r511322 : r511331;
        double r511333 = r511309 ? r511319 : r511332;
        double r511334 = r511306 ? r511307 : r511333;
        return r511334;
}

Error

Bits error versus x

Bits error versus y

Target

Original32.0
Target31.8
Herbie12.6
\[\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 < -1.1543129503955349e+123 or 4.735150776778642e+127 < x

    1. Initial program 56.5

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Simplified56.5

      \[\leadsto \color{blue}{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    3. Taylor expanded around inf 9.8

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

    if -1.1543129503955349e+123 < x < -1.0494610473739957e-90 or 5.481288829847034e-119 < x < 7.251238886375514e-42 or 0.0002637073173922211 < x < 4.735150776778642e+127

    1. Initial program 15.7

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

      \[\leadsto \color{blue}{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt15.7

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

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

    if -1.0494610473739957e-90 < x < 5.481288829847034e-119 or 7.251238886375514e-42 < x < 0.0002637073173922211

    1. Initial program 26.5

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Simplified26.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.15431295039553488213566106957485115951 \cdot 10^{123}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -1.049461047373995695414776940334688667457 \cdot 10^{-90}:\\ \;\;\;\;\frac{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\sqrt{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}}{\sqrt{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\\ \mathbf{elif}\;x \le 5.481288829847034474742950694868171684444 \cdot 10^{-119}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 7.251238886375513779793874451315946152856 \cdot 10^{-42}:\\ \;\;\;\;\frac{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\sqrt{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}}{\sqrt{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\\ \mathbf{elif}\;x \le 2.637073173922210812467059604102814773796 \cdot 10^{-4}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 4.73515077677864244964006142406283884833 \cdot 10^{127}:\\ \;\;\;\;\frac{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\sqrt{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}}{\sqrt{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

herbie shell --seed 2019212 +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.974323384962678118) (- (/ (* 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))))