Average Error: 19.8 → 5.2
Time: 8.1s
Precision: binary64
\[[x, y, z] = \mathsf{sort}([x, y, z]) \\]
\[2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z} \]
\[\begin{array}{l} t_0 := 2 \cdot {\left(e^{0.25 \cdot \left(\log \left(-\left(y + z\right)\right) - \log \left(\frac{-1}{x}\right)\right)}\right)}^{2}\\ \mathbf{if}\;y \leq -3.5016519017157693 \cdot 10^{+22}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -5.029427106894932 \cdot 10^{-174}:\\ \;\;\;\;2 \cdot \sqrt{\mathsf{fma}\left(y \cdot x, 1, z \cdot x\right) + y \cdot z}\\ \mathbf{elif}\;y \leq 2.0611617972601002 \cdot 10^{-268}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;2 \cdot {\left(e^{0.25 \cdot \left(\log \left(y + x\right) - \log \left(\frac{1}{z}\right)\right)}\right)}^{2}\\ \end{array} \]
2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z}
\begin{array}{l}
t_0 := 2 \cdot {\left(e^{0.25 \cdot \left(\log \left(-\left(y + z\right)\right) - \log \left(\frac{-1}{x}\right)\right)}\right)}^{2}\\
\mathbf{if}\;y \leq -3.5016519017157693 \cdot 10^{+22}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq -5.029427106894932 \cdot 10^{-174}:\\
\;\;\;\;2 \cdot \sqrt{\mathsf{fma}\left(y \cdot x, 1, z \cdot x\right) + y \cdot z}\\

\mathbf{elif}\;y \leq 2.0611617972601002 \cdot 10^{-268}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;2 \cdot {\left(e^{0.25 \cdot \left(\log \left(y + x\right) - \log \left(\frac{1}{z}\right)\right)}\right)}^{2}\\


\end{array}
(FPCore (x y z)
 :precision binary64
 (* 2.0 (sqrt (+ (+ (* x y) (* x z)) (* y z)))))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0
         (*
          2.0
          (pow (exp (* 0.25 (- (log (- (+ y z))) (log (/ -1.0 x))))) 2.0))))
   (if (<= y -3.5016519017157693e+22)
     t_0
     (if (<= y -5.029427106894932e-174)
       (* 2.0 (sqrt (+ (fma (* y x) 1.0 (* z x)) (* y z))))
       (if (<= y 2.0611617972601002e-268)
         t_0
         (*
          2.0
          (pow (exp (* 0.25 (- (log (+ y x)) (log (/ 1.0 z))))) 2.0)))))))
double code(double x, double y, double z) {
	return 2.0 * sqrt((((x * y) + (x * z)) + (y * z)));
}
double code(double x, double y, double z) {
	double t_0 = 2.0 * pow(exp((0.25 * (log(-(y + z)) - log((-1.0 / x))))), 2.0);
	double tmp;
	if (y <= -3.5016519017157693e+22) {
		tmp = t_0;
	} else if (y <= -5.029427106894932e-174) {
		tmp = 2.0 * sqrt((fma((y * x), 1.0, (z * x)) + (y * z)));
	} else if (y <= 2.0611617972601002e-268) {
		tmp = t_0;
	} else {
		tmp = 2.0 * pow(exp((0.25 * (log((y + x)) - log((1.0 / z))))), 2.0);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original19.8
Target11.7
Herbie5.2
\[\begin{array}{l} \mathbf{if}\;z < 7.636950090573675 \cdot 10^{+176}:\\ \;\;\;\;2 \cdot \sqrt{\left(x + y\right) \cdot z + x \cdot y}\\ \mathbf{else}:\\ \;\;\;\;\left(\left(0.25 \cdot \left(\left({y}^{-0.75} \cdot \left({z}^{-0.75} \cdot x\right)\right) \cdot \left(y + z\right)\right) + {z}^{0.25} \cdot {y}^{0.25}\right) \cdot \left(0.25 \cdot \left(\left({y}^{-0.75} \cdot \left({z}^{-0.75} \cdot x\right)\right) \cdot \left(y + z\right)\right) + {z}^{0.25} \cdot {y}^{0.25}\right)\right) \cdot 2\\ \end{array} \]

Derivation

  1. Split input into 3 regimes
  2. if y < -3.5016519017157693e22 or -5.0294271068949322e-174 < y < 2.06116179726010015e-268

    1. Initial program 34.7

      \[2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z} \]
    2. Applied egg-rr34.8

      \[\leadsto 2 \cdot \color{blue}{{\left({\left(\mathsf{fma}\left(x, y + z, y \cdot z\right)\right)}^{0.25}\right)}^{2}} \]
    3. Taylor expanded in x around -inf 7.4

      \[\leadsto 2 \cdot {\color{blue}{\left(e^{0.25 \cdot \left(\log \left(-\left(y + z\right)\right) - \log \left(\frac{-1}{x}\right)\right)}\right)}}^{2} \]

    if -3.5016519017157693e22 < y < -5.0294271068949322e-174

    1. Initial program 0.6

      \[2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z} \]
    2. Applied egg-rr0.6

      \[\leadsto 2 \cdot \sqrt{\color{blue}{\mathsf{fma}\left(x \cdot y, 1, x \cdot z\right)} + y \cdot z} \]

    if 2.06116179726010015e-268 < y

    1. Initial program 19.4

      \[2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z} \]
    2. Applied egg-rr19.6

      \[\leadsto 2 \cdot \color{blue}{{\left({\left(\mathsf{fma}\left(x, y + z, y \cdot z\right)\right)}^{0.25}\right)}^{2}} \]
    3. Taylor expanded in z around inf 5.9

      \[\leadsto 2 \cdot {\color{blue}{\left(e^{0.25 \cdot \left(\log \left(y + x\right) - \log \left(\frac{1}{z}\right)\right)}\right)}}^{2} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification5.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -3.5016519017157693 \cdot 10^{+22}:\\ \;\;\;\;2 \cdot {\left(e^{0.25 \cdot \left(\log \left(-\left(y + z\right)\right) - \log \left(\frac{-1}{x}\right)\right)}\right)}^{2}\\ \mathbf{elif}\;y \leq -5.029427106894932 \cdot 10^{-174}:\\ \;\;\;\;2 \cdot \sqrt{\mathsf{fma}\left(y \cdot x, 1, z \cdot x\right) + y \cdot z}\\ \mathbf{elif}\;y \leq 2.0611617972601002 \cdot 10^{-268}:\\ \;\;\;\;2 \cdot {\left(e^{0.25 \cdot \left(\log \left(-\left(y + z\right)\right) - \log \left(\frac{-1}{x}\right)\right)}\right)}^{2}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot {\left(e^{0.25 \cdot \left(\log \left(y + x\right) - \log \left(\frac{1}{z}\right)\right)}\right)}^{2}\\ \end{array} \]

Reproduce

herbie shell --seed 2022129 
(FPCore (x y z)
  :name "Diagrams.TwoD.Apollonian:descartes from diagrams-contrib-1.3.0.5"
  :precision binary64

  :herbie-target
  (if (< z 7.636950090573675e+176) (* 2.0 (sqrt (+ (* (+ x y) z) (* x y)))) (* (* (+ (* 0.25 (* (* (pow y -0.75) (* (pow z -0.75) x)) (+ y z))) (* (pow z 0.25) (pow y 0.25))) (+ (* 0.25 (* (* (pow y -0.75) (* (pow z -0.75) x)) (+ y z))) (* (pow z 0.25) (pow y 0.25)))) 2.0))

  (* 2.0 (sqrt (+ (+ (* x y) (* x z)) (* y z)))))