Average Error: 31.8 → 5.8
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 -6.85410439611574166 \cdot 10^{153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.2415409052957577 \cdot 10^{-113}:\\ \;\;\;\;\log \left(e^{\frac{x}{\mathsf{fma}\left(4, \frac{{y}^{2}}{x}, x\right)}}\right) - \frac{y \cdot 4}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{y}}\\ \mathbf{elif}\;y \le 2.5006885111970022 \cdot 10^{-302}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 6.6423911005969367 \cdot 10^{153}:\\ \;\;\;\;\log \left(e^{\frac{x}{\mathsf{fma}\left(4, \frac{{y}^{2}}{x}, x\right)}}\right) - \frac{y \cdot 4}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{y}}\\ \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 -6.85410439611574166 \cdot 10^{153}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -1.2415409052957577 \cdot 10^{-113}:\\
\;\;\;\;\log \left(e^{\frac{x}{\mathsf{fma}\left(4, \frac{{y}^{2}}{x}, x\right)}}\right) - \frac{y \cdot 4}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{y}}\\

\mathbf{elif}\;y \le 2.5006885111970022 \cdot 10^{-302}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le 6.6423911005969367 \cdot 10^{153}:\\
\;\;\;\;\log \left(e^{\frac{x}{\mathsf{fma}\left(4, \frac{{y}^{2}}{x}, x\right)}}\right) - \frac{y \cdot 4}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{y}}\\

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

\end{array}
double f(double x, double y) {
        double r629344 = x;
        double r629345 = r629344 * r629344;
        double r629346 = y;
        double r629347 = 4.0;
        double r629348 = r629346 * r629347;
        double r629349 = r629348 * r629346;
        double r629350 = r629345 - r629349;
        double r629351 = r629345 + r629349;
        double r629352 = r629350 / r629351;
        return r629352;
}

double f(double x, double y) {
        double r629353 = y;
        double r629354 = -6.854104396115742e+153;
        bool r629355 = r629353 <= r629354;
        double r629356 = -1.0;
        double r629357 = -1.2415409052957577e-113;
        bool r629358 = r629353 <= r629357;
        double r629359 = x;
        double r629360 = 4.0;
        double r629361 = 2.0;
        double r629362 = pow(r629353, r629361);
        double r629363 = r629362 / r629359;
        double r629364 = fma(r629360, r629363, r629359);
        double r629365 = r629359 / r629364;
        double r629366 = exp(r629365);
        double r629367 = log(r629366);
        double r629368 = r629353 * r629360;
        double r629369 = r629368 * r629353;
        double r629370 = fma(r629359, r629359, r629369);
        double r629371 = r629370 / r629353;
        double r629372 = r629368 / r629371;
        double r629373 = r629367 - r629372;
        double r629374 = 2.500688511197002e-302;
        bool r629375 = r629353 <= r629374;
        double r629376 = 1.0;
        double r629377 = 6.642391100596937e+153;
        bool r629378 = r629353 <= r629377;
        double r629379 = r629378 ? r629373 : r629356;
        double r629380 = r629375 ? r629376 : r629379;
        double r629381 = r629358 ? r629373 : r629380;
        double r629382 = r629355 ? r629356 : r629381;
        return r629382;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.8
Target31.4
Herbie5.8
\[\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 < -6.854104396115742e+153 or 6.642391100596937e+153 < y

    1. Initial program 64.0

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

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

    if -6.854104396115742e+153 < y < -1.2415409052957577e-113 or 2.500688511197002e-302 < y < 6.642391100596937e+153

    1. Initial program 18.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 div-sub18.9

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

      \[\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. Simplified18.6

      \[\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}}}\]
    6. Taylor expanded around 0 2.7

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

      \[\leadsto \frac{x}{\color{blue}{\mathsf{fma}\left(4, \frac{{y}^{2}}{x}, x\right)}} - \frac{y \cdot 4}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{y}}\]
    8. Using strategy rm
    9. Applied add-log-exp2.7

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

    if -1.2415409052957577e-113 < y < 2.500688511197002e-302

    1. Initial program 28.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -6.85410439611574166 \cdot 10^{153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.2415409052957577 \cdot 10^{-113}:\\ \;\;\;\;\log \left(e^{\frac{x}{\mathsf{fma}\left(4, \frac{{y}^{2}}{x}, x\right)}}\right) - \frac{y \cdot 4}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{y}}\\ \mathbf{elif}\;y \le 2.5006885111970022 \cdot 10^{-302}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 6.6423911005969367 \cdot 10^{153}:\\ \;\;\;\;\log \left(e^{\frac{x}{\mathsf{fma}\left(4, \frac{{y}^{2}}{x}, x\right)}}\right) - \frac{y \cdot 4}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{y}}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

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