Average Error: 38.1 → 26.2
Time: 13.6s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -18637040731758232623605069933264714596350:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 4.376373199179285827713056036389642308458 \cdot 10^{91}:\\ \;\;\;\;\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 -18637040731758232623605069933264714596350:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 4.376373199179285827713056036389642308458 \cdot 10^{91}:\\
\;\;\;\;\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 r445650 = x;
        double r445651 = r445650 * r445650;
        double r445652 = y;
        double r445653 = r445652 * r445652;
        double r445654 = r445651 + r445653;
        double r445655 = z;
        double r445656 = r445655 * r445655;
        double r445657 = r445654 + r445656;
        double r445658 = sqrt(r445657);
        return r445658;
}

double f(double x, double y, double z) {
        double r445659 = x;
        double r445660 = -1.8637040731758233e+40;
        bool r445661 = r445659 <= r445660;
        double r445662 = -r445659;
        double r445663 = 4.376373199179286e+91;
        bool r445664 = r445659 <= r445663;
        double r445665 = r445659 * r445659;
        double r445666 = y;
        double r445667 = r445666 * r445666;
        double r445668 = r445665 + r445667;
        double r445669 = z;
        double r445670 = r445669 * r445669;
        double r445671 = r445668 + r445670;
        double r445672 = sqrt(r445671);
        double r445673 = r445664 ? r445672 : r445659;
        double r445674 = r445661 ? r445662 : r445673;
        return r445674;
}

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

Original38.1
Target25.4
Herbie26.2
\[\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.8637040731758233e+40

    1. Initial program 48.9

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

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

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

    if -1.8637040731758233e+40 < x < 4.376373199179286e+91

    1. Initial program 29.6

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

    if 4.376373199179286e+91 < x

    1. Initial program 53.4

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

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

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

Reproduce

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