Average Error: 31.5 → 14.1
Time: 2.9s
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 -5.810291952691062 \cdot 10^{115}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(1\right)\right)\\ \mathbf{elif}\;x \le -2.9463808085280802 \cdot 10^{-149}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\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}}\right)\right)\\ \mathbf{elif}\;x \le 9.05045019517546565 \cdot 10^{-190}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 1.3661811917011361 \cdot 10^{-63}:\\ \;\;\;\;\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}\;x \le 4.9502099980031536 \cdot 10^{39}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(1\right)\right)\\ \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 -5.810291952691062 \cdot 10^{115}:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(1\right)\right)\\

\mathbf{elif}\;x \le -2.9463808085280802 \cdot 10^{-149}:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\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}}\right)\right)\\

\mathbf{elif}\;x \le 9.05045019517546565 \cdot 10^{-190}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le 1.3661811917011361 \cdot 10^{-63}:\\
\;\;\;\;\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}\;x \le 4.9502099980031536 \cdot 10^{39}:\\
\;\;\;\;-1\\

\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(1\right)\right)\\

\end{array}
double f(double x, double y) {
        double r739122 = x;
        double r739123 = r739122 * r739122;
        double r739124 = y;
        double r739125 = 4.0;
        double r739126 = r739124 * r739125;
        double r739127 = r739126 * r739124;
        double r739128 = r739123 - r739127;
        double r739129 = r739123 + r739127;
        double r739130 = r739128 / r739129;
        return r739130;
}

double f(double x, double y) {
        double r739131 = x;
        double r739132 = -5.810291952691062e+115;
        bool r739133 = r739131 <= r739132;
        double r739134 = 1.0;
        double r739135 = expm1(r739134);
        double r739136 = log1p(r739135);
        double r739137 = -2.9463808085280802e-149;
        bool r739138 = r739131 <= r739137;
        double r739139 = y;
        double r739140 = 4.0;
        double r739141 = r739139 * r739140;
        double r739142 = r739141 * r739139;
        double r739143 = fma(r739131, r739131, r739142);
        double r739144 = r739131 * r739131;
        double r739145 = r739144 - r739142;
        double r739146 = r739143 / r739145;
        double r739147 = r739134 / r739146;
        double r739148 = expm1(r739147);
        double r739149 = log1p(r739148);
        double r739150 = 9.050450195175466e-190;
        bool r739151 = r739131 <= r739150;
        double r739152 = -1.0;
        double r739153 = 1.366181191701136e-63;
        bool r739154 = r739131 <= r739153;
        double r739155 = 4.9502099980031536e+39;
        bool r739156 = r739131 <= r739155;
        double r739157 = r739156 ? r739152 : r739136;
        double r739158 = r739154 ? r739147 : r739157;
        double r739159 = r739151 ? r739152 : r739158;
        double r739160 = r739138 ? r739149 : r739159;
        double r739161 = r739133 ? r739136 : r739160;
        return r739161;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.5
Target31.3
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 x < -5.810291952691062e+115 or 4.9502099980031536e+39 < x

    1. Initial program 48.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-num48.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. Simplified48.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 log1p-expm1-u48.0

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\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}}\right)\right)}\]
    7. Taylor expanded around inf 12.1

      \[\leadsto \mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1}{\color{blue}{1}}\right)\right)\]

    if -5.810291952691062e+115 < x < -2.9463808085280802e-149

    1. Initial program 16.4

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

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

      \[\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 log1p-expm1-u16.4

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\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}}\right)\right)}\]

    if -2.9463808085280802e-149 < x < 9.050450195175466e-190 or 1.366181191701136e-63 < x < 4.9502099980031536e+39

    1. Initial program 26.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 13.3

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

    if 9.050450195175466e-190 < x < 1.366181191701136e-63

    1. Initial program 19.3

      \[\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-num19.3

      \[\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. Simplified19.3

      \[\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}\;x \le -5.810291952691062 \cdot 10^{115}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(1\right)\right)\\ \mathbf{elif}\;x \le -2.9463808085280802 \cdot 10^{-149}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\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}}\right)\right)\\ \mathbf{elif}\;x \le 9.05045019517546565 \cdot 10^{-190}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 1.3661811917011361 \cdot 10^{-63}:\\ \;\;\;\;\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}\;x \le 4.9502099980031536 \cdot 10^{39}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(1\right)\right)\\ \end{array}\]

Reproduce

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