Average Error: 21.4 → 1.2
Time: 2.2s
Precision: 64
\[\sqrt{x \cdot x + y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -9.936810330166151 \cdot 10^{81}:\\ \;\;\;\;-\left(x + \frac{1}{2} \cdot \frac{y}{x}\right)\\ \mathbf{elif}\;x \le 1.38120789165749593 \cdot 10^{75}:\\ \;\;\;\;\left|\sqrt[3]{x \cdot x + y}\right| \cdot \sqrt{\sqrt[3]{x \cdot x + y}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{2}, \frac{y}{x}, x\right)\\ \end{array}\]
\sqrt{x \cdot x + y}
\begin{array}{l}
\mathbf{if}\;x \le -9.936810330166151 \cdot 10^{81}:\\
\;\;\;\;-\left(x + \frac{1}{2} \cdot \frac{y}{x}\right)\\

\mathbf{elif}\;x \le 1.38120789165749593 \cdot 10^{75}:\\
\;\;\;\;\left|\sqrt[3]{x \cdot x + y}\right| \cdot \sqrt{\sqrt[3]{x \cdot x + y}}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{2}, \frac{y}{x}, x\right)\\

\end{array}
double f(double x, double y) {
        double r450933 = x;
        double r450934 = r450933 * r450933;
        double r450935 = y;
        double r450936 = r450934 + r450935;
        double r450937 = sqrt(r450936);
        return r450937;
}

double f(double x, double y) {
        double r450938 = x;
        double r450939 = -9.936810330166151e+81;
        bool r450940 = r450938 <= r450939;
        double r450941 = 0.5;
        double r450942 = y;
        double r450943 = r450942 / r450938;
        double r450944 = r450941 * r450943;
        double r450945 = r450938 + r450944;
        double r450946 = -r450945;
        double r450947 = 1.381207891657496e+75;
        bool r450948 = r450938 <= r450947;
        double r450949 = r450938 * r450938;
        double r450950 = r450949 + r450942;
        double r450951 = cbrt(r450950);
        double r450952 = fabs(r450951);
        double r450953 = sqrt(r450951);
        double r450954 = r450952 * r450953;
        double r450955 = fma(r450941, r450943, r450938);
        double r450956 = r450948 ? r450954 : r450955;
        double r450957 = r450940 ? r450946 : r450956;
        return r450957;
}

Error

Bits error versus x

Bits error versus y

Target

Original21.4
Target0.6
Herbie1.2
\[\begin{array}{l} \mathbf{if}\;x \lt -1.5097698010472593 \cdot 10^{153}:\\ \;\;\;\;-\left(0.5 \cdot \frac{y}{x} + x\right)\\ \mathbf{elif}\;x \lt 5.5823995511225407 \cdot 10^{57}:\\ \;\;\;\;\sqrt{x \cdot x + y}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{y}{x} + x\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if x < -9.936810330166151e+81

    1. Initial program 44.4

      \[\sqrt{x \cdot x + y}\]
    2. Taylor expanded around -inf 1.3

      \[\leadsto \color{blue}{-\left(x + \frac{1}{2} \cdot \frac{y}{x}\right)}\]

    if -9.936810330166151e+81 < x < 1.381207891657496e+75

    1. Initial program 0.0

      \[\sqrt{x \cdot x + y}\]
    2. Using strategy rm
    3. Applied add-cube-cbrt0.9

      \[\leadsto \sqrt{\color{blue}{\left(\sqrt[3]{x \cdot x + y} \cdot \sqrt[3]{x \cdot x + y}\right) \cdot \sqrt[3]{x \cdot x + y}}}\]
    4. Applied sqrt-prod0.9

      \[\leadsto \color{blue}{\sqrt{\sqrt[3]{x \cdot x + y} \cdot \sqrt[3]{x \cdot x + y}} \cdot \sqrt{\sqrt[3]{x \cdot x + y}}}\]
    5. Simplified0.9

      \[\leadsto \color{blue}{\left|\sqrt[3]{x \cdot x + y}\right|} \cdot \sqrt{\sqrt[3]{x \cdot x + y}}\]

    if 1.381207891657496e+75 < x

    1. Initial program 43.6

      \[\sqrt{x \cdot x + y}\]
    2. Taylor expanded around inf 1.7

      \[\leadsto \color{blue}{x + \frac{1}{2} \cdot \frac{y}{x}}\]
    3. Simplified1.7

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{2}, \frac{y}{x}, x\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -9.936810330166151 \cdot 10^{81}:\\ \;\;\;\;-\left(x + \frac{1}{2} \cdot \frac{y}{x}\right)\\ \mathbf{elif}\;x \le 1.38120789165749593 \cdot 10^{75}:\\ \;\;\;\;\left|\sqrt[3]{x \cdot x + y}\right| \cdot \sqrt{\sqrt[3]{x \cdot x + y}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{2}, \frac{y}{x}, x\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020083 +o rules:numerics
(FPCore (x y)
  :name "Linear.Quaternion:$clog from linear-1.19.1.3"
  :precision binary64

  :herbie-target
  (if (< x -1.5097698010472593e+153) (- (+ (* 0.5 (/ y x)) x)) (if (< x 5.582399551122541e+57) (sqrt (+ (* x x) y)) (+ (* 0.5 (/ y x)) x)))

  (sqrt (+ (* x x) y)))