Average Error: 37.8 → 25.4
Time: 1.2s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.69404716956149714 \cdot 10^{135}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 7.6875795344769699 \cdot 10^{110}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]
\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}
\begin{array}{l}
\mathbf{if}\;x \le -3.69404716956149714 \cdot 10^{135}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 7.6875795344769699 \cdot 10^{110}:\\
\;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\

\mathbf{else}:\\
\;\;\;\;x\\

\end{array}
double f(double x, double y, double z) {
        double r597223 = x;
        double r597224 = r597223 * r597223;
        double r597225 = y;
        double r597226 = r597225 * r597225;
        double r597227 = r597224 + r597226;
        double r597228 = z;
        double r597229 = r597228 * r597228;
        double r597230 = r597227 + r597229;
        double r597231 = sqrt(r597230);
        return r597231;
}

double f(double x, double y, double z) {
        double r597232 = x;
        double r597233 = -3.694047169561497e+135;
        bool r597234 = r597232 <= r597233;
        double r597235 = -1.0;
        double r597236 = r597235 * r597232;
        double r597237 = 7.68757953447697e+110;
        bool r597238 = r597232 <= r597237;
        double r597239 = r597232 * r597232;
        double r597240 = y;
        double r597241 = r597240 * r597240;
        double r597242 = r597239 + r597241;
        double r597243 = z;
        double r597244 = r597243 * r597243;
        double r597245 = r597242 + r597244;
        double r597246 = sqrt(r597245);
        double r597247 = r597238 ? r597246 : r597232;
        double r597248 = r597234 ? r597236 : r597247;
        return r597248;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original37.8
Target25.7
Herbie25.4
\[\begin{array}{l} \mathbf{if}\;z \lt -6.3964793941097758 \cdot 10^{136}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \lt 7.3202936944041821 \cdot 10^{117}:\\ \;\;\;\;\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if x < -3.694047169561497e+135

    1. Initial program 60.2

      \[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
    2. Taylor expanded around -inf 15.8

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

    if -3.694047169561497e+135 < x < 7.68757953447697e+110

    1. Initial program 29.0

      \[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]

    if 7.68757953447697e+110 < x

    1. Initial program 56.9

      \[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
    2. Taylor expanded around inf 17.8

      \[\leadsto \color{blue}{x}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification25.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.69404716956149714 \cdot 10^{135}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 7.6875795344769699 \cdot 10^{110}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

herbie shell --seed 2020039 
(FPCore (x y z)
  :name "FRP.Yampa.Vector3:vector3Rho from Yampa-0.10.2"
  :precision binary64

  :herbie-target
  (if (< z -6.396479394109776e+136) (- z) (if (< z 7.320293694404182e+117) (sqrt (+ (+ (* z z) (* x x)) (* y y))) z))

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