Average Error: 37.8 → 25.3
Time: 11.0s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.136128759261515680889913503091063645066 \cdot 10^{95}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 7.747364727091017988201281938523347580094 \cdot 10^{152}:\\ \;\;\;\;\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.136128759261515680889913503091063645066 \cdot 10^{95}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 7.747364727091017988201281938523347580094 \cdot 10^{152}:\\
\;\;\;\;\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 r524492 = x;
        double r524493 = r524492 * r524492;
        double r524494 = y;
        double r524495 = r524494 * r524494;
        double r524496 = r524493 + r524495;
        double r524497 = z;
        double r524498 = r524497 * r524497;
        double r524499 = r524496 + r524498;
        double r524500 = sqrt(r524499);
        return r524500;
}

double f(double x, double y, double z) {
        double r524501 = x;
        double r524502 = -1.1361287592615157e+95;
        bool r524503 = r524501 <= r524502;
        double r524504 = -r524501;
        double r524505 = 7.747364727091018e+152;
        bool r524506 = r524501 <= r524505;
        double r524507 = r524501 * r524501;
        double r524508 = y;
        double r524509 = r524508 * r524508;
        double r524510 = r524507 + r524509;
        double r524511 = z;
        double r524512 = r524511 * r524511;
        double r524513 = r524510 + r524512;
        double r524514 = sqrt(r524513);
        double r524515 = r524506 ? r524514 : r524501;
        double r524516 = r524503 ? r524504 : r524515;
        return r524516;
}

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.5
Herbie25.3
\[\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 < -1.1361287592615157e+95

    1. Initial program 54.3

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

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

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

    if -1.1361287592615157e+95 < x < 7.747364727091018e+152

    1. Initial program 29.0

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

    if 7.747364727091018e+152 < x

    1. Initial program 63.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.136128759261515680889913503091063645066 \cdot 10^{95}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 7.747364727091017988201281938523347580094 \cdot 10^{152}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< z -6.3964793941097758e136) (- z) (if (< z 7.3202936944041821e117) (sqrt (+ (+ (* z z) (* x x)) (* y y))) z))

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