Average Error: 31.6 → 13.4
Time: 10.1s
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 \cdot \left(y \cdot 4\right) \le 7.027808530107358188452156248527074599726 \cdot 10^{-286}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \le 3.69166379221494303097062696142672714528 \cdot 10^{-13}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}\right)\right)\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \le 1.792267162890288236819749793630475002654 \cdot 10^{85}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \le 8.170638210533042102915317867916107400746 \cdot 10^{248}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}\right)\right)\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \le 1.496258465901378664026516368495157364812 \cdot 10^{262}:\\ \;\;\;\;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 \cdot \left(y \cdot 4\right) \le 7.027808530107358188452156248527074599726 \cdot 10^{-286}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \cdot \left(y \cdot 4\right) \le 3.69166379221494303097062696142672714528 \cdot 10^{-13}:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}\right)\right)\\

\mathbf{elif}\;y \cdot \left(y \cdot 4\right) \le 1.792267162890288236819749793630475002654 \cdot 10^{85}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \cdot \left(y \cdot 4\right) \le 8.170638210533042102915317867916107400746 \cdot 10^{248}:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}\right)\right)\\

\mathbf{elif}\;y \cdot \left(y \cdot 4\right) \le 1.496258465901378664026516368495157364812 \cdot 10^{262}:\\
\;\;\;\;1\\

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

\end{array}
double f(double x, double y) {
        double r31215464 = x;
        double r31215465 = r31215464 * r31215464;
        double r31215466 = y;
        double r31215467 = 4.0;
        double r31215468 = r31215466 * r31215467;
        double r31215469 = r31215468 * r31215466;
        double r31215470 = r31215465 - r31215469;
        double r31215471 = r31215465 + r31215469;
        double r31215472 = r31215470 / r31215471;
        return r31215472;
}

double f(double x, double y) {
        double r31215473 = y;
        double r31215474 = 4.0;
        double r31215475 = r31215473 * r31215474;
        double r31215476 = r31215473 * r31215475;
        double r31215477 = 7.027808530107358e-286;
        bool r31215478 = r31215476 <= r31215477;
        double r31215479 = 1.0;
        double r31215480 = 3.691663792214943e-13;
        bool r31215481 = r31215476 <= r31215480;
        double r31215482 = x;
        double r31215483 = r31215482 * r31215482;
        double r31215484 = r31215483 - r31215476;
        double r31215485 = fma(r31215482, r31215482, r31215476);
        double r31215486 = r31215484 / r31215485;
        double r31215487 = expm1(r31215486);
        double r31215488 = log1p(r31215487);
        double r31215489 = 1.7922671628902882e+85;
        bool r31215490 = r31215476 <= r31215489;
        double r31215491 = 8.170638210533042e+248;
        bool r31215492 = r31215476 <= r31215491;
        double r31215493 = 1.4962584659013787e+262;
        bool r31215494 = r31215476 <= r31215493;
        double r31215495 = -1.0;
        double r31215496 = r31215494 ? r31215479 : r31215495;
        double r31215497 = r31215492 ? r31215488 : r31215496;
        double r31215498 = r31215490 ? r31215479 : r31215497;
        double r31215499 = r31215481 ? r31215488 : r31215498;
        double r31215500 = r31215478 ? r31215479 : r31215499;
        return r31215500;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.6
Target31.3
Herbie13.4
\[\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 (* (* y 4.0) y) < 7.027808530107358e-286 or 3.691663792214943e-13 < (* (* y 4.0) y) < 1.7922671628902882e+85 or 8.170638210533042e+248 < (* (* y 4.0) y) < 1.4962584659013787e+262

    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. Taylor expanded around inf 15.0

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

    if 7.027808530107358e-286 < (* (* y 4.0) y) < 3.691663792214943e-13 or 1.7922671628902882e+85 < (* (* y 4.0) y) < 8.170638210533042e+248

    1. Initial program 15.2

      \[\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 fma-def15.2

      \[\leadsto \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    4. Using strategy rm
    5. Applied log1p-expm1-u15.2

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

    if 1.4962584659013787e+262 < (* (* y 4.0) y)

    1. Initial program 57.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot \left(y \cdot 4\right) \le 7.027808530107358188452156248527074599726 \cdot 10^{-286}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \le 3.69166379221494303097062696142672714528 \cdot 10^{-13}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}\right)\right)\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \le 1.792267162890288236819749793630475002654 \cdot 10^{85}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \le 8.170638210533042102915317867916107400746 \cdot 10^{248}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}\right)\right)\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \le 1.496258465901378664026516368495157364812 \cdot 10^{262}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

herbie shell --seed 2019192 +o rules:numerics
(FPCore (x y)
  :name "Diagrams.TwoD.Arc:arcBetween from diagrams-lib-1.3.0.3"

  :herbie-target
  (if (< (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))) 0.9743233849626781) (- (/ (* x x) (+ (* x x) (* (* y y) 4.0))) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))) (- (pow (/ x (sqrt (+ (* x x) (* (* y y) 4.0)))) 2.0) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))))

  (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))))