Average Error: 37.5 → 25.4
Time: 2.7s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.5533831897781973 \cdot 10^{149}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 8.4296792906958425 \cdot 10^{116}:\\ \;\;\;\;\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 -1.5533831897781973 \cdot 10^{149}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 8.4296792906958425 \cdot 10^{116}:\\
\;\;\;\;\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 r524147 = x;
        double r524148 = r524147 * r524147;
        double r524149 = y;
        double r524150 = r524149 * r524149;
        double r524151 = r524148 + r524150;
        double r524152 = z;
        double r524153 = r524152 * r524152;
        double r524154 = r524151 + r524153;
        double r524155 = sqrt(r524154);
        return r524155;
}

double f(double x, double y, double z) {
        double r524156 = x;
        double r524157 = -1.5533831897781973e+149;
        bool r524158 = r524156 <= r524157;
        double r524159 = -1.0;
        double r524160 = r524159 * r524156;
        double r524161 = 8.429679290695843e+116;
        bool r524162 = r524156 <= r524161;
        double r524163 = r524156 * r524156;
        double r524164 = y;
        double r524165 = r524164 * r524164;
        double r524166 = r524163 + r524165;
        double r524167 = z;
        double r524168 = r524167 * r524167;
        double r524169 = r524166 + r524168;
        double r524170 = sqrt(r524169);
        double r524171 = r524162 ? r524170 : r524156;
        double r524172 = r524158 ? r524160 : r524171;
        return r524172;
}

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.5
Target25.0
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 < -1.5533831897781973e+149

    1. Initial program 62.6

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

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

    if -1.5533831897781973e+149 < x < 8.429679290695843e+116

    1. Initial program 29.3

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

    if 8.429679290695843e+116 < x

    1. Initial program 56.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.5533831897781973 \cdot 10^{149}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 8.4296792906958425 \cdot 10^{116}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

herbie shell --seed 2020035 
(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))))