Average Error: 37.8 → 25.5
Time: 7.4s
Precision: binary64
Cost: 7746
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;z \leq -4.488947755092404 \cdot 10^{+128}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 3.9888983964713314 \cdot 10^{+60}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array}\]
\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}
\begin{array}{l}
\mathbf{if}\;z \leq -4.488947755092404 \cdot 10^{+128}:\\
\;\;\;\;-z\\

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

\mathbf{else}:\\
\;\;\;\;z\\

\end{array}
(FPCore (x y z) :precision binary64 (sqrt (+ (+ (* x x) (* y y)) (* z z))))
(FPCore (x y z)
 :precision binary64
 (if (<= z -4.488947755092404e+128)
   (- z)
   (if (<= z 3.9888983964713314e+60)
     (sqrt (+ (+ (* x x) (* y y)) (* z z)))
     z)))
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 (z <= -4.488947755092404e+128) {
		tmp = -z;
	} else if (z <= 3.9888983964713314e+60) {
		tmp = sqrt(((x * x) + (y * y)) + (z * z));
	} else {
		tmp = z;
	}
	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.8
Target25.1
Herbie25.5
\[\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
Error28.9
Cost7811
\[\begin{array}{l} \mathbf{if}\;z \leq -9.605147171149148 \cdot 10^{+125}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq -2.0053498903303235 \cdot 10^{-54}:\\ \;\;\;\;\sqrt{x \cdot x + z \cdot z}\\ \mathbf{elif}\;z \leq 3.924969607937373 \cdot 10^{-54}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array}\]
Alternative 2
Error30.3
Cost7490
\[\begin{array}{l} \mathbf{if}\;z \leq -1.3722124681143297 \cdot 10^{-08}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 4.972173623440741 \cdot 10^{-55}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;z \leq 9.121051616478697 \cdot 10^{+45}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 1.8714558560145953 \cdot 10^{+56}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 1.3270625385352505 \cdot 10^{+103}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array}\]
Alternative 3
Error36.9
Cost4237
\[\begin{array}{l} \mathbf{if}\;z \leq -3.242442730210987 \cdot 10^{-38}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq -3.15728364052437 \cdot 10^{-151}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -5.59135491821388 \cdot 10^{-165}:\\ \;\;\;\;-y\\ \mathbf{elif}\;z \leq -1.9719397252834922 \cdot 10^{-253}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq 4.667908854129587 \cdot 10^{-302}:\\ \;\;\;\;x + 0.5 \cdot \left(\frac{z \cdot z}{x} + \frac{y \cdot y}{x}\right)\\ \mathbf{elif}\;z \leq 7.366192176249098 \cdot 10^{-295}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq 1.1148972220753654 \cdot 10^{-251}:\\ \;\;\;\;-y\\ \mathbf{elif}\;z \leq 1.2545824004578874 \cdot 10^{-238}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 2.304809989723087 \cdot 10^{-232}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 8.72782298761248 \cdot 10^{-56}:\\ \;\;\;\;-y\\ \mathbf{elif}\;z \leq 1.1995838869215986 \cdot 10^{+45}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 1.6249162523000812 \cdot 10^{+62}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 1.914489363399924 \cdot 10^{+102}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array}\]
Alternative 4
Error36.2
Cost2375
\[\begin{array}{l} \mathbf{if}\;z \leq -3.0972918864632994 \cdot 10^{-38}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq -3.803174774874433 \cdot 10^{-152}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -3.710561020036677 \cdot 10^{-166}:\\ \;\;\;\;-y\\ \mathbf{elif}\;z \leq -5.939447749900448 \cdot 10^{-252}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq 2.845999638125896 \cdot 10^{-301}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 2.631032794434887 \cdot 10^{-293}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq 7.708158259094176 \cdot 10^{-55}:\\ \;\;\;\;-y\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array}\]
Alternative 5
Error36.9
Cost2953
\[\begin{array}{l} \mathbf{if}\;z \leq -8.764735511337867 \cdot 10^{-40}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq -5.0156735314691095 \cdot 10^{-151}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -7.213598741186633 \cdot 10^{-169}:\\ \;\;\;\;-y\\ \mathbf{elif}\;z \leq -9.583503801657816 \cdot 10^{-240}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 1.4071564533574446 \cdot 10^{-292}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 2.0094051567064338 \cdot 10^{-54}:\\ \;\;\;\;-y\\ \mathbf{elif}\;z \leq 2.755993599020533 \cdot 10^{+45}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 6.033133859087058 \cdot 10^{+63}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 1.914489363399924 \cdot 10^{+102}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array}\]
Alternative 6
Error36.9
Cost706
\[\begin{array}{l} \mathbf{if}\;z \leq -1.1331570714098637 \cdot 10^{-50}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 7.5331716743775265 \cdot 10^{-81}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array}\]
Alternative 7
Error44.9
Cost2632
\[\begin{array}{l} \mathbf{if}\;z \leq -3.82205946405465:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq -2.4256580704478053 \cdot 10^{-174}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -4.2035523502443245 \cdot 10^{-240}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 1.7750825613497865 \cdot 10^{-238}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.9217162317999586 \cdot 10^{-84}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 9.121051616478697 \cdot 10^{+45}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 3.7771068876195965 \cdot 10^{+60}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 1.914489363399924 \cdot 10^{+102}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array}\]
Alternative 8
Error45.0
Cost385
\[\begin{array}{l} \mathbf{if}\;z \leq 3.380560913491828 \cdot 10^{-79}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array}\]
Alternative 9
Error51.3
Cost385
\[\begin{array}{l} \mathbf{if}\;z \leq 2.5665030622105744 \cdot 10^{-220}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array}\]
Alternative 10
Error60.8
Cost64
\[1\]

Error

Derivation

  1. Split input into 3 regimes
  2. if z < -4.48894775509240362e128

    1. Initial program 58.6

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

      \[\leadsto \color{blue}{-1 \cdot z}\]
    3. Simplified15.3

      \[\leadsto \color{blue}{-z}\]
    4. Simplified15.3

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

    if -4.48894775509240362e128 < z < 3.9888983964713314e60

    1. Initial program 29.3

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

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

    if 3.9888983964713314e60 < z

    1. Initial program 50.5

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

      \[\leadsto \color{blue}{z}\]
    3. Simplified20.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -4.488947755092404 \cdot 10^{+128}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 3.9888983964713314 \cdot 10^{+60}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array}\]

Reproduce

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