Average Error: 37.6 → 25.0
Time: 8.7s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -8.65689218952316206016746897628479098224 \cdot 10^{102}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 4.471707363468376084214192176846928336007 \cdot 10^{118}:\\ \;\;\;\;\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 -8.65689218952316206016746897628479098224 \cdot 10^{102}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 4.471707363468376084214192176846928336007 \cdot 10^{118}:\\
\;\;\;\;\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 r41968760 = x;
        double r41968761 = r41968760 * r41968760;
        double r41968762 = y;
        double r41968763 = r41968762 * r41968762;
        double r41968764 = r41968761 + r41968763;
        double r41968765 = z;
        double r41968766 = r41968765 * r41968765;
        double r41968767 = r41968764 + r41968766;
        double r41968768 = sqrt(r41968767);
        return r41968768;
}

double f(double x, double y, double z) {
        double r41968769 = x;
        double r41968770 = -8.656892189523162e+102;
        bool r41968771 = r41968769 <= r41968770;
        double r41968772 = -r41968769;
        double r41968773 = 4.471707363468376e+118;
        bool r41968774 = r41968769 <= r41968773;
        double r41968775 = z;
        double r41968776 = r41968775 * r41968775;
        double r41968777 = y;
        double r41968778 = r41968777 * r41968777;
        double r41968779 = r41968769 * r41968769;
        double r41968780 = r41968778 + r41968779;
        double r41968781 = r41968776 + r41968780;
        double r41968782 = sqrt(r41968781);
        double r41968783 = r41968774 ? r41968782 : r41968769;
        double r41968784 = r41968771 ? r41968772 : r41968783;
        return r41968784;
}

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.6
Target25.3
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 < -8.656892189523162e+102

    1. Initial program 55.3

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

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

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

    if -8.656892189523162e+102 < x < 4.471707363468376e+118

    1. Initial program 28.5

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

    if 4.471707363468376e+118 < x

    1. Initial program 57.1

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

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

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

Reproduce

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