Average Error: 37.5 → 25.4
Time: 16.6s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -4.839580010133738883814333111888121327705 \cdot 10^{89}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.537188568549186890366688724633159259389 \cdot 10^{101}:\\ \;\;\;\;\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 -4.839580010133738883814333111888121327705 \cdot 10^{89}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 1.537188568549186890366688724633159259389 \cdot 10^{101}:\\
\;\;\;\;\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 r451569 = x;
        double r451570 = r451569 * r451569;
        double r451571 = y;
        double r451572 = r451571 * r451571;
        double r451573 = r451570 + r451572;
        double r451574 = z;
        double r451575 = r451574 * r451574;
        double r451576 = r451573 + r451575;
        double r451577 = sqrt(r451576);
        return r451577;
}

double f(double x, double y, double z) {
        double r451578 = x;
        double r451579 = -4.839580010133739e+89;
        bool r451580 = r451578 <= r451579;
        double r451581 = -r451578;
        double r451582 = 1.537188568549187e+101;
        bool r451583 = r451578 <= r451582;
        double r451584 = r451578 * r451578;
        double r451585 = y;
        double r451586 = r451585 * r451585;
        double r451587 = r451584 + r451586;
        double r451588 = z;
        double r451589 = r451588 * r451588;
        double r451590 = r451587 + r451589;
        double r451591 = sqrt(r451590);
        double r451592 = r451583 ? r451591 : r451578;
        double r451593 = r451580 ? r451581 : r451592;
        return r451593;
}

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.3
Herbie25.4
\[\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 < -4.839580010133739e+89

    1. Initial program 52.1

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

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

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

    if -4.839580010133739e+89 < x < 1.537188568549187e+101

    1. Initial program 29.0

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

    if 1.537188568549187e+101 < x

    1. Initial program 55.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -4.839580010133738883814333111888121327705 \cdot 10^{89}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.537188568549186890366688724633159259389 \cdot 10^{101}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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