Average Error: 37.7 → 25.3
Time: 5.2s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.906782791664629779020140146460695676759 \cdot 10^{124}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 3.063475397831882310945125787731954626151 \cdot 10^{109}:\\ \;\;\;\;\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.906782791664629779020140146460695676759 \cdot 10^{124}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 3.063475397831882310945125787731954626151 \cdot 10^{109}:\\
\;\;\;\;\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 r421652 = x;
        double r421653 = r421652 * r421652;
        double r421654 = y;
        double r421655 = r421654 * r421654;
        double r421656 = r421653 + r421655;
        double r421657 = z;
        double r421658 = r421657 * r421657;
        double r421659 = r421656 + r421658;
        double r421660 = sqrt(r421659);
        return r421660;
}

double f(double x, double y, double z) {
        double r421661 = x;
        double r421662 = -1.9067827916646298e+124;
        bool r421663 = r421661 <= r421662;
        double r421664 = -1.0;
        double r421665 = r421664 * r421661;
        double r421666 = 3.0634753978318823e+109;
        bool r421667 = r421661 <= r421666;
        double r421668 = r421661 * r421661;
        double r421669 = y;
        double r421670 = r421669 * r421669;
        double r421671 = r421668 + r421670;
        double r421672 = z;
        double r421673 = r421672 * r421672;
        double r421674 = r421671 + r421673;
        double r421675 = sqrt(r421674);
        double r421676 = r421667 ? r421675 : r421661;
        double r421677 = r421663 ? r421665 : r421676;
        return r421677;
}

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.7
Target25.7
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.9067827916646298e+124

    1. Initial program 58.2

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

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

    if -1.9067827916646298e+124 < x < 3.0634753978318823e+109

    1. Initial program 29.0

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

    if 3.0634753978318823e+109 < x

    1. Initial program 56.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.906782791664629779020140146460695676759 \cdot 10^{124}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 3.063475397831882310945125787731954626151 \cdot 10^{109}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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