Average Error: 37.6 → 25.6
Time: 4.7s
Precision: binary64
Cost: 7746
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;y \leq -2.604223501683959 \cdot 10^{+40}:\\ \;\;\;\;-y\\ \mathbf{elif}\;y \leq 6.450989484237564 \cdot 10^{+111}:\\ \;\;\;\;\sqrt{z \cdot z + \left(x \cdot x + y \cdot y\right)}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array}\]
\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}
\begin{array}{l}
\mathbf{if}\;y \leq -2.604223501683959 \cdot 10^{+40}:\\
\;\;\;\;-y\\

\mathbf{elif}\;y \leq 6.450989484237564 \cdot 10^{+111}:\\
\;\;\;\;\sqrt{z \cdot z + \left(x \cdot x + y \cdot y\right)}\\

\mathbf{else}:\\
\;\;\;\;y\\

\end{array}
(FPCore (x y z) :precision binary64 (sqrt (+ (+ (* x x) (* y y)) (* z z))))
(FPCore (x y z)
 :precision binary64
 (if (<= y -2.604223501683959e+40)
   (- y)
   (if (<= y 6.450989484237564e+111)
     (sqrt (+ (* z z) (+ (* x x) (* y y))))
     y)))
double code(double x, double y, double z) {
	return sqrt(((x * x) + (y * y)) + (z * z));
}
double code(double x, double y, double z) {
	double tmp;
	if (y <= -2.604223501683959e+40) {
		tmp = -y;
	} else if (y <= 6.450989484237564e+111) {
		tmp = sqrt((z * z) + ((x * x) + (y * y)));
	} else {
		tmp = y;
	}
	return tmp;
}

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.4
Herbie25.6
\[\begin{array}{l} \mathbf{if}\;z < -6.396479394109776 \cdot 10^{+136}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z < 7.320293694404182 \cdot 10^{+117}:\\ \;\;\;\;\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array}\]

Alternatives

Alternative 1
Error37.8
Cost27072
\[\sqrt{\sqrt{z \cdot z + \left(x \cdot x + y \cdot y\right)}} \cdot \sqrt{\sqrt{z \cdot z + \left(x \cdot x + y \cdot y\right)}}\]
Alternative 2
Error55.4
Cost21120
\[\frac{\sqrt{\left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x + y \cdot y\right) - {z}^{4}}}{\sqrt{\left(x \cdot x + y \cdot y\right) - z \cdot z}}\]
Alternative 3
Error37.8
Cost19968
\[{\left(\sqrt{\sqrt{z \cdot z + \left(x \cdot x + y \cdot y\right)}}\right)}^{2}\]
Alternative 4
Error37.6
Cost7104
\[\sqrt{z \cdot z + \left(x \cdot x + y \cdot y\right)}\]
Alternative 5
Error46.0
Cost6848
\[\sqrt{x \cdot x + z \cdot z}\]
Alternative 6
Error45.7
Cost6848
\[\sqrt{y \cdot y + z \cdot z}\]
Alternative 7
Error55.0
Cost960
\[z + 0.5 \cdot \left(\frac{x \cdot x}{z} + \frac{y \cdot y}{z}\right)\]
Alternative 8
Error54.1
Cost960
\[\left(\frac{z \cdot z}{y} + \frac{x \cdot x}{y}\right) \cdot -0.5 - y\]
Alternative 9
Error52.1
Cost128
\[-z\]
Alternative 10
Error51.8
Cost128
\[-y\]
Alternative 11
Error52.2
Cost128
\[-x\]
Alternative 12
Error52.8
Cost64
\[z\]
Alternative 13
Error51.9
Cost64
\[y\]
Alternative 14
Error52.0
Cost64
\[x\]
Alternative 15
Error60.8
Cost64
\[1\]
Alternative 16
Error62.5
Cost64
\[0\]
Alternative 17
Error63.3
Cost64
\[-1\]

Error

Derivation

  1. Split input into 3 regimes
  2. if y < -2.6042235016839591e40

    1. Initial program 47.4

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

      \[\leadsto \color{blue}{-1 \cdot y}\]
    3. Simplified21.3

      \[\leadsto \color{blue}{-y}\]
    4. Simplified21.3

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

    if -2.6042235016839591e40 < y < 6.45098948423756438e111

    1. Initial program 29.4

      \[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
    2. Simplified29.4

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

    if 6.45098948423756438e111 < y

    1. Initial program 57.3

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

      \[\leadsto \color{blue}{y}\]
    3. Simplified15.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.604223501683959 \cdot 10^{+40}:\\ \;\;\;\;-y\\ \mathbf{elif}\;y \leq 6.450989484237564 \cdot 10^{+111}:\\ \;\;\;\;\sqrt{z \cdot z + \left(x \cdot x + y \cdot y\right)}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array}\]

Reproduce

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