Average Error: 37.7 → 26.1
Time: 1.8s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.133106536034299358163277062984298277828 \cdot 10^{138}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -2.026191906036317463463308639688967933522 \cdot 10^{-260}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;x \le 8.497132416662690300417761690267080472766 \cdot 10^{-293}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \le 1.00508350929880118874711876138723648734 \cdot 10^{127}:\\ \;\;\;\;\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 -2.133106536034299358163277062984298277828 \cdot 10^{138}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le -2.026191906036317463463308639688967933522 \cdot 10^{-260}:\\
\;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\

\mathbf{elif}\;x \le 8.497132416662690300417761690267080472766 \cdot 10^{-293}:\\
\;\;\;\;z\\

\mathbf{elif}\;x \le 1.00508350929880118874711876138723648734 \cdot 10^{127}:\\
\;\;\;\;\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 r301788 = x;
        double r301789 = r301788 * r301788;
        double r301790 = y;
        double r301791 = r301790 * r301790;
        double r301792 = r301789 + r301791;
        double r301793 = z;
        double r301794 = r301793 * r301793;
        double r301795 = r301792 + r301794;
        double r301796 = sqrt(r301795);
        return r301796;
}

double f(double x, double y, double z) {
        double r301797 = x;
        double r301798 = -2.1331065360342994e+138;
        bool r301799 = r301797 <= r301798;
        double r301800 = -1.0;
        double r301801 = r301800 * r301797;
        double r301802 = -2.0261919060363175e-260;
        bool r301803 = r301797 <= r301802;
        double r301804 = r301797 * r301797;
        double r301805 = y;
        double r301806 = r301805 * r301805;
        double r301807 = r301804 + r301806;
        double r301808 = z;
        double r301809 = r301808 * r301808;
        double r301810 = r301807 + r301809;
        double r301811 = sqrt(r301810);
        double r301812 = 8.49713241666269e-293;
        bool r301813 = r301797 <= r301812;
        double r301814 = 1.0050835092988012e+127;
        bool r301815 = r301797 <= r301814;
        double r301816 = r301815 ? r301811 : r301797;
        double r301817 = r301813 ? r301808 : r301816;
        double r301818 = r301803 ? r301811 : r301817;
        double r301819 = r301799 ? r301801 : r301818;
        return r301819;
}

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.1
Herbie26.1
\[\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 4 regimes
  2. if x < -2.1331065360342994e+138

    1. Initial program 61.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 -2.1331065360342994e+138 < x < -2.0261919060363175e-260 or 8.49713241666269e-293 < x < 1.0050835092988012e+127

    1. Initial program 28.8

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

    if -2.0261919060363175e-260 < x < 8.49713241666269e-293

    1. Initial program 29.7

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

      \[\leadsto \color{blue}{z}\]

    if 1.0050835092988012e+127 < x

    1. Initial program 58.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.133106536034299358163277062984298277828 \cdot 10^{138}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -2.026191906036317463463308639688967933522 \cdot 10^{-260}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;x \le 8.497132416662690300417761690267080472766 \cdot 10^{-293}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \le 1.00508350929880118874711876138723648734 \cdot 10^{127}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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