Average Error: 37.3 → 25.0
Time: 6.1s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -5.245129204403200253740971551147040838799 \cdot 10^{130}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.035831751923693585671752188644252048192 \cdot 10^{141}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]
\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}
\begin{array}{l}
\mathbf{if}\;x \le -5.245129204403200253740971551147040838799 \cdot 10^{130}:\\
\;\;\;\;-x\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r31092826 = x;
        double r31092827 = r31092826 * r31092826;
        double r31092828 = y;
        double r31092829 = r31092828 * r31092828;
        double r31092830 = r31092827 + r31092829;
        double r31092831 = z;
        double r31092832 = r31092831 * r31092831;
        double r31092833 = r31092830 + r31092832;
        double r31092834 = sqrt(r31092833);
        return r31092834;
}

double f(double x, double y, double z) {
        double r31092835 = x;
        double r31092836 = -5.2451292044032e+130;
        bool r31092837 = r31092835 <= r31092836;
        double r31092838 = -r31092835;
        double r31092839 = 1.0358317519236936e+141;
        bool r31092840 = r31092835 <= r31092839;
        double r31092841 = z;
        double r31092842 = r31092841 * r31092841;
        double r31092843 = y;
        double r31092844 = r31092843 * r31092843;
        double r31092845 = r31092835 * r31092835;
        double r31092846 = r31092844 + r31092845;
        double r31092847 = r31092842 + r31092846;
        double r31092848 = sqrt(r31092847);
        double r31092849 = r31092840 ? r31092848 : r31092835;
        double r31092850 = r31092837 ? r31092838 : r31092849;
        return r31092850;
}

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.3
Target25.0
Herbie25.0
\[\begin{array}{l} \mathbf{if}\;z \lt -6.396479394109775845820908799933348003545 \cdot 10^{136}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \lt 7.320293694404182125923160810847974073098 \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 < -5.2451292044032e+130

    1. Initial program 58.6

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

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

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

    if -5.2451292044032e+130 < x < 1.0358317519236936e+141

    1. Initial program 28.7

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

    if 1.0358317519236936e+141 < x

    1. Initial program 61.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -5.245129204403200253740971551147040838799 \cdot 10^{130}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.035831751923693585671752188644252048192 \cdot 10^{141}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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

  :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))))