Average Error: 38.1 → 27.9
Time: 14.2s
Precision: binary64
Cost: 8516
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;z \leq -4.141643309014705 \cdot 10^{+78}:\\ \;\;\;\;-z \cdot \sqrt{0.3333333333333333}\\ \mathbf{elif}\;z \leq -8.300032789610983 \cdot 10^{-40}:\\ \;\;\;\;\sqrt{0.3333333333333333 \cdot \left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right)}\\ \mathbf{elif}\;z \leq -4.7941203005386077 \cdot 10^{-116}:\\ \;\;\;\;-\sqrt{0.3333333333333333} \cdot y\\ \mathbf{elif}\;z \leq 2.5554730149638786 \cdot 10^{+79}:\\ \;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;z \leq -4.141643309014705 \cdot 10^{+78}:\\
\;\;\;\;-z \cdot \sqrt{0.3333333333333333}\\

\mathbf{elif}\;z \leq -8.300032789610983 \cdot 10^{-40}:\\
\;\;\;\;\sqrt{0.3333333333333333 \cdot \left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right)}\\

\mathbf{elif}\;z \leq -4.7941203005386077 \cdot 10^{-116}:\\
\;\;\;\;-\sqrt{0.3333333333333333} \cdot y\\

\mathbf{elif}\;z \leq 2.5554730149638786 \cdot 10^{+79}:\\
\;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\

\mathbf{else}:\\
\;\;\;\;z \cdot \sqrt{0.3333333333333333}\\

\end{array}
(FPCore (x y z)
 :precision binary64
 (sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) 3.0)))
(FPCore (x y z)
 :precision binary64
 (if (<= z -4.141643309014705e+78)
   (- (* z (sqrt 0.3333333333333333)))
   (if (<= z -8.300032789610983e-40)
     (sqrt (* 0.3333333333333333 (+ (+ (* x x) (* y y)) (* z z))))
     (if (<= z -4.7941203005386077e-116)
       (- (* (sqrt 0.3333333333333333) y))
       (if (<= z 2.5554730149638786e+79)
         (sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) 3.0))
         (* z (sqrt 0.3333333333333333)))))))
double code(double x, double y, double z) {
	return sqrt((((x * x) + (y * y)) + (z * z)) / 3.0);
}
double code(double x, double y, double z) {
	double tmp;
	if (z <= -4.141643309014705e+78) {
		tmp = -(z * sqrt(0.3333333333333333));
	} else if (z <= -8.300032789610983e-40) {
		tmp = sqrt(0.3333333333333333 * (((x * x) + (y * y)) + (z * z)));
	} else if (z <= -4.7941203005386077e-116) {
		tmp = -(sqrt(0.3333333333333333) * y);
	} else if (z <= 2.5554730149638786e+79) {
		tmp = sqrt((((x * x) + (y * y)) + (z * z)) / 3.0);
	} else {
		tmp = z * sqrt(0.3333333333333333);
	}
	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

Original38.1
Target26.1
Herbie27.9
\[\begin{array}{l} \mathbf{if}\;z < -6.396479394109776 \cdot 10^{+136}:\\ \;\;\;\;\frac{-z}{\sqrt{3}}\\ \mathbf{elif}\;z < 7.320293694404182 \cdot 10^{+117}:\\ \;\;\;\;\frac{\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot z\\ \end{array}\]

Alternatives

Alternative 1
Error28.0
Cost8516
\[\begin{array}{l} \mathbf{if}\;z \leq -5.733118926859368 \cdot 10^{+78}:\\ \;\;\;\;-z \cdot \sqrt{0.3333333333333333}\\ \mathbf{elif}\;z \leq -8.300032789610983 \cdot 10^{-40}:\\ \;\;\;\;\sqrt{0.3333333333333333 \cdot \left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right)}\\ \mathbf{elif}\;z \leq -4.7121669910270733 \cdot 10^{-116}:\\ \;\;\;\;-\sqrt{0.3333333333333333} \cdot y\\ \mathbf{elif}\;z \leq 3.164424535879085 \cdot 10^{+78}:\\ \;\;\;\;\sqrt{0.3333333333333333 \cdot \left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right)}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array}\]
Alternative 2
Error31.0
Cost8902
\[\begin{array}{l} \mathbf{if}\;z \leq -4.141643309014705 \cdot 10^{+78}:\\ \;\;\;\;-z \cdot \sqrt{0.3333333333333333}\\ \mathbf{elif}\;z \leq -8.300032789610983 \cdot 10^{-40}:\\ \;\;\;\;\sqrt{\frac{y \cdot y + z \cdot z}{3}}\\ \mathbf{elif}\;z \leq -4.403329961458749 \cdot 10^{-143}:\\ \;\;\;\;-\sqrt{0.3333333333333333} \cdot y\\ \mathbf{elif}\;z \leq -5.766573950802635 \cdot 10^{-164}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot x\\ \mathbf{elif}\;z \leq 2.5054104478274364 \cdot 10^{-73}:\\ \;\;\;\;\sqrt{0.3333333333333333 \cdot \left(x \cdot x + y \cdot y\right)}\\ \mathbf{elif}\;z \leq 1.742305704916751 \cdot 10^{+143}:\\ \;\;\;\;\sqrt{\frac{y \cdot y + z \cdot z}{3}}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array}\]
Alternative 3
Error35.2
Cost10507
\[\begin{array}{l} \mathbf{if}\;z \leq -8.882095954060614 \cdot 10^{+76}:\\ \;\;\;\;-z \cdot \sqrt{0.3333333333333333}\\ \mathbf{elif}\;z \leq -8.300032789610983 \cdot 10^{-40}:\\ \;\;\;\;\sqrt{\frac{y \cdot y + z \cdot z}{3}}\\ \mathbf{elif}\;z \leq -3.042057554341231 \cdot 10^{-148}:\\ \;\;\;\;-\sqrt{0.3333333333333333} \cdot y\\ \mathbf{elif}\;z \leq -5.902042453924911 \cdot 10^{-164}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot x\\ \mathbf{elif}\;z \leq -1.754728965313165 \cdot 10^{-199}:\\ \;\;\;\;\sqrt{0.3333333333333333 \cdot \left(x \cdot x\right)}\\ \mathbf{elif}\;z \leq -5.961450697293597 \cdot 10^{-207}:\\ \;\;\;\;-\sqrt{0.3333333333333333} \cdot y\\ \mathbf{elif}\;z \leq -5.719689495239871 \cdot 10^{-235}:\\ \;\;\;\;-\sqrt{0.3333333333333333} \cdot x\\ \mathbf{elif}\;z \leq -1.0758450883855827 \cdot 10^{-237}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot x\\ \mathbf{elif}\;z \leq -2.004681726860074 \cdot 10^{-297}:\\ \;\;\;\;\sqrt{\frac{y \cdot y}{3}}\\ \mathbf{elif}\;z \leq 1.2473236554611331 \cdot 10^{-159}:\\ \;\;\;\;-\sqrt{0.3333333333333333} \cdot x\\ \mathbf{elif}\;z \leq 1.9462594388646717 \cdot 10^{+143}:\\ \;\;\;\;\sqrt{\frac{y \cdot y + z \cdot z}{3}}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array}\]
Alternative 4
Error37.7
Cost8518
\[\begin{array}{l} \mathbf{if}\;z \leq -2.7942998010870872 \cdot 10^{-64}:\\ \;\;\;\;-z \cdot \sqrt{0.3333333333333333}\\ \mathbf{elif}\;z \leq -8.775767864782322 \cdot 10^{-209}:\\ \;\;\;\;-\sqrt{0.3333333333333333} \cdot y\\ \mathbf{elif}\;z \leq -3.49613143149423 \cdot 10^{-249}:\\ \;\;\;\;-\sqrt{0.3333333333333333} \cdot x\\ \mathbf{elif}\;z \leq -9.594926573884682 \cdot 10^{-293}:\\ \;\;\;\;-\sqrt{0.3333333333333333} \cdot y\\ \mathbf{elif}\;z \leq 6.21827164455149 \cdot 10^{-294}:\\ \;\;\;\;\sqrt{0.3333333333333333 \cdot \left(x \cdot x\right)}\\ \mathbf{elif}\;z \leq 2.2779363488421198 \cdot 10^{-141}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot y\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array}\]
Alternative 5
Error37.6
Cost8582
\[\begin{array}{l} \mathbf{if}\;z \leq -3.342105884761498 \cdot 10^{-64}:\\ \;\;\;\;-z \cdot \sqrt{0.3333333333333333}\\ \mathbf{elif}\;z \leq -2.3828285817679075 \cdot 10^{-209}:\\ \;\;\;\;-\sqrt{0.3333333333333333} \cdot y\\ \mathbf{elif}\;z \leq -3.292643234551737 \cdot 10^{-246}:\\ \;\;\;\;-\sqrt{0.3333333333333333} \cdot x\\ \mathbf{elif}\;z \leq -1.0101425956584445 \cdot 10^{-287}:\\ \;\;\;\;-\sqrt{0.3333333333333333} \cdot y\\ \mathbf{elif}\;z \leq 1.6221764531716504 \cdot 10^{-134}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot y\\ \mathbf{elif}\;z \leq 8.05124811188657 \cdot 10^{-107}:\\ \;\;\;\;-\sqrt{0.3333333333333333} \cdot y\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array}\]
Alternative 6
Error37.4
Cost8197
\[\begin{array}{l} \mathbf{if}\;z \leq -1.0016670434099076 \cdot 10^{-64}:\\ \;\;\;\;-z \cdot \sqrt{0.3333333333333333}\\ \mathbf{elif}\;z \leq -9.799368542025818 \cdot 10^{-218}:\\ \;\;\;\;-\sqrt{0.3333333333333333} \cdot y\\ \mathbf{elif}\;z \leq 3.4395376153951726 \cdot 10^{-253}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot y\\ \mathbf{elif}\;z \leq 4.8425621232338526 \cdot 10^{-194}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot x\\ \mathbf{elif}\;z \leq 2.9179411951703685 \cdot 10^{-97}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot y\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array}\]
Alternative 7
Error37.3
Cost7234
\[\begin{array}{l} \mathbf{if}\;z \leq -1.861654217953978 \cdot 10^{-76}:\\ \;\;\;\;-z \cdot \sqrt{0.3333333333333333}\\ \mathbf{elif}\;z \leq 1.4098157811235658 \cdot 10^{-95}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot y\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array}\]
Alternative 8
Error44.5
Cost7555
\[\begin{array}{l} \mathbf{if}\;x \leq -3.520257602063463 \cdot 10^{-15}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot y\\ \mathbf{elif}\;x \leq -3.175525454867484 \cdot 10^{-239}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \mathbf{elif}\;x \leq 1.0221392823644404 \cdot 10^{-101}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot y\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot x\\ \end{array}\]
Alternative 9
Error44.5
Cost6913
\[\begin{array}{l} \mathbf{if}\;z \leq 2.2220638076624937 \cdot 10^{-95}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot y\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array}\]
Alternative 10
Error50.9
Cost6913
\[\begin{array}{l} \mathbf{if}\;z \leq 1.2208880481808786 \cdot 10^{-193}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array}\]
Alternative 11
Error60.8
Cost64
\[1\]

Error

Derivation

  1. Split input into 5 regimes
  2. if z < -4.1416433090147048e78

    1. Initial program 52.1

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

      \[\leadsto \color{blue}{-1 \cdot \left(\sqrt{0.3333333333333333} \cdot z\right)}\]
    3. Simplified20.1

      \[\leadsto \color{blue}{-z \cdot \sqrt{0.3333333333333333}}\]
    4. Simplified20.1

      \[\leadsto \color{blue}{-z \cdot \sqrt{0.3333333333333333}}\]

    if -4.1416433090147048e78 < z < -8.3000327896109825e-40

    1. Initial program 29.0

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Using strategy rm
    3. Applied div-inv_binary64_2394529.0

      \[\leadsto \sqrt{\color{blue}{\left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right) \cdot \frac{1}{3}}}\]
    4. Simplified29.0

      \[\leadsto \sqrt{\left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right) \cdot \color{blue}{0.3333333333333333}}\]
    5. Simplified29.0

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

    if -8.3000327896109825e-40 < z < -4.79412030053860766e-116

    1. Initial program 26.3

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

      \[\leadsto \color{blue}{-1 \cdot \left(\sqrt{0.3333333333333333} \cdot y\right)}\]
    3. Simplified50.7

      \[\leadsto \color{blue}{-y \cdot \sqrt{0.3333333333333333}}\]
    4. Simplified50.7

      \[\leadsto \color{blue}{-y \cdot \sqrt{0.3333333333333333}}\]

    if -4.79412030053860766e-116 < z < 2.5554730149638786e79

    1. Initial program 30.5

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

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

    if 2.5554730149638786e79 < z

    1. Initial program 52.2

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

      \[\leadsto \color{blue}{\sqrt{0.3333333333333333} \cdot z}\]
    3. Simplified20.9

      \[\leadsto \color{blue}{z \cdot \sqrt{0.3333333333333333}}\]
    4. Simplified20.9

      \[\leadsto \color{blue}{z \cdot \sqrt{0.3333333333333333}}\]
  3. Recombined 5 regimes into one program.
  4. Final simplification27.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -4.141643309014705 \cdot 10^{+78}:\\ \;\;\;\;-z \cdot \sqrt{0.3333333333333333}\\ \mathbf{elif}\;z \leq -8.300032789610983 \cdot 10^{-40}:\\ \;\;\;\;\sqrt{0.3333333333333333 \cdot \left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right)}\\ \mathbf{elif}\;z \leq -4.7941203005386077 \cdot 10^{-116}:\\ \;\;\;\;-\sqrt{0.3333333333333333} \cdot y\\ \mathbf{elif}\;z \leq 2.5554730149638786 \cdot 10^{+79}:\\ \;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array}\]

Reproduce

herbie shell --seed 2021044 
(FPCore (x y z)
  :name "Data.Array.Repa.Algorithms.Pixel:doubleRmsOfRGB8 from repa-algorithms-3.4.0.1"
  :precision binary64

  :herbie-target
  (if (< z -6.396479394109776e+136) (/ (- z) (sqrt 3.0)) (if (< z 7.320293694404182e+117) (/ (sqrt (+ (+ (* z z) (* x x)) (* y y))) (sqrt 3.0)) (* (sqrt 0.3333333333333333) z)))

  (sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) 3.0)))