Average Error: 31.5 → 12.7
Time: 8.6s
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}\;\left(y \cdot 4\right) \cdot y \le 3.414623317947593663745953537661023590748 \cdot 10^{-192}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 3.810003643719863336668138253262668476651 \cdot 10^{67}:\\ \;\;\;\;\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.756338886358467686795570653182400240677 \cdot 10^{115}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 9.415768721852470917873482124314739876564 \cdot 10^{215}:\\ \;\;\;\;\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot y}{\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}\;\left(y \cdot 4\right) \cdot y \le 3.414623317947593663745953537661023590748 \cdot 10^{-192}:\\
\;\;\;\;1\\

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

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

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 9.415768721852470917873482124314739876564 \cdot 10^{215}:\\
\;\;\;\;\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot y}{\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 r368402 = x;
        double r368403 = r368402 * r368402;
        double r368404 = y;
        double r368405 = 4.0;
        double r368406 = r368404 * r368405;
        double r368407 = r368406 * r368404;
        double r368408 = r368403 - r368407;
        double r368409 = r368403 + r368407;
        double r368410 = r368408 / r368409;
        return r368410;
}

double f(double x, double y) {
        double r368411 = y;
        double r368412 = 4.0;
        double r368413 = r368411 * r368412;
        double r368414 = r368413 * r368411;
        double r368415 = 3.4146233179475937e-192;
        bool r368416 = r368414 <= r368415;
        double r368417 = 1.0;
        double r368418 = 3.8100036437198633e+67;
        bool r368419 = r368414 <= r368418;
        double r368420 = x;
        double r368421 = r368420 * r368420;
        double r368422 = fma(r368420, r368420, r368414);
        double r368423 = r368421 / r368422;
        double r368424 = r368414 / r368422;
        double r368425 = r368423 - r368424;
        double r368426 = 1.7563388863584677e+115;
        bool r368427 = r368414 <= r368426;
        double r368428 = 9.415768721852471e+215;
        bool r368429 = r368414 <= r368428;
        double r368430 = -1.0;
        double r368431 = r368429 ? r368425 : r368430;
        double r368432 = r368427 ? r368417 : r368431;
        double r368433 = r368419 ? r368425 : r368432;
        double r368434 = r368416 ? r368417 : r368433;
        return r368434;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.5
Target31.2
Herbie12.7
\[\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) < 3.4146233179475937e-192 or 3.8100036437198633e+67 < (* (* y 4.0) y) < 1.7563388863584677e+115

    1. Initial program 26.4

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

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

    if 3.4146233179475937e-192 < (* (* y 4.0) y) < 3.8100036437198633e+67 or 1.7563388863584677e+115 < (* (* y 4.0) y) < 9.415768721852471e+215

    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 div-sub15.0

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

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

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

    if 9.415768721852471e+215 < (* (* y 4.0) y)

    1. Initial program 52.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 0 10.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(y \cdot 4\right) \cdot y \le 3.414623317947593663745953537661023590748 \cdot 10^{-192}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 3.810003643719863336668138253262668476651 \cdot 10^{67}:\\ \;\;\;\;\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.756338886358467686795570653182400240677 \cdot 10^{115}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 9.415768721852470917873482124314739876564 \cdot 10^{215}:\\ \;\;\;\;\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

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