Average Error: 18.5 → 5.1
Time: 13.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 e^{0.5 \cdot \left(\log \left(-\left(y + z\right)\right) - \log \left(\frac{-1}{x}\right)\right)}\\ \mathbf{if}\;y \leq -1.7253211663182805 \cdot 10^{+23}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.1343957496177142 \cdot 10^{-192}:\\ \;\;\;\;2 \cdot {\left(\left(y + z\right) \cdot x\right)}^{0.5}\\ \mathbf{elif}\;y \leq -2.7214926907983235 \cdot 10^{-253}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.0208539709101426 \cdot 10^{+93}:\\ \;\;\;\;2 \cdot \sqrt{\mathsf{fma}\left(y, x, z \cdot \left(y + x\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot e^{0.5 \cdot \left(\log \left(y + x\right) - \log \left(\frac{1}{z}\right)\right)}\\ \end{array} \]
2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z}
\begin{array}{l}
t_0 := 2 \cdot e^{0.5 \cdot \left(\log \left(-\left(y + z\right)\right) - \log \left(\frac{-1}{x}\right)\right)}\\
\mathbf{if}\;y \leq -1.7253211663182805 \cdot 10^{+23}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq -1.1343957496177142 \cdot 10^{-192}:\\
\;\;\;\;2 \cdot {\left(\left(y + z\right) \cdot x\right)}^{0.5}\\

\mathbf{elif}\;y \leq -2.7214926907983235 \cdot 10^{-253}:\\
\;\;\;\;t_0\\

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

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


\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 (exp (* 0.5 (- (log (- (+ y z))) (log (/ -1.0 x))))))))
   (if (<= y -1.7253211663182805e+23)
     t_0
     (if (<= y -1.1343957496177142e-192)
       (* 2.0 (pow (* (+ y z) x) 0.5))
       (if (<= y -2.7214926907983235e-253)
         t_0
         (if (<= y 1.0208539709101426e+93)
           (* 2.0 (sqrt (fma y x (* z (+ y x)))))
           (* 2.0 (exp (* 0.5 (- (log (+ y x)) (log (/ 1.0 z))))))))))))
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 * exp(0.5 * (log(-(y + z)) - log(-1.0 / x)));
	double tmp;
	if (y <= -1.7253211663182805e+23) {
		tmp = t_0;
	} else if (y <= -1.1343957496177142e-192) {
		tmp = 2.0 * pow(((y + z) * x), 0.5);
	} else if (y <= -2.7214926907983235e-253) {
		tmp = t_0;
	} else if (y <= 1.0208539709101426e+93) {
		tmp = 2.0 * sqrt(fma(y, x, (z * (y + x))));
	} else {
		tmp = 2.0 * exp(0.5 * (log(y + x) - log(1.0 / z)));
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original18.5
Target10.8
Herbie5.1
\[\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 4 regimes
  2. if y < -1.7253211663182805e23 or -1.1343957496177142e-192 < y < -2.7214926907983235e-253

    1. Initial program 34.7

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

      \[\leadsto \color{blue}{2 \cdot \sqrt{\mathsf{fma}\left(x, y + z, y \cdot z\right)}} \]
    3. Applied pow1/2_binary6434.4

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

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

    if -1.7253211663182805e23 < y < -1.1343957496177142e-192

    1. Initial program 0.8

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

      \[\leadsto \color{blue}{2 \cdot \sqrt{\mathsf{fma}\left(x, y + z, y \cdot z\right)}} \]
    3. Applied pow1/2_binary640.8

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

      \[\leadsto 2 \cdot {\color{blue}{\left(\left(y + z\right) \cdot x\right)}}^{0.5} \]
    5. Simplified0.9

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

    if -2.7214926907983235e-253 < y < 1.020853970910143e93

    1. Initial program 6.1

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

      \[\leadsto \color{blue}{2 \cdot \sqrt{\mathsf{fma}\left(x, y + z, y \cdot z\right)}} \]
    3. Taylor expanded in x around 0 6.1

      \[\leadsto 2 \cdot \sqrt{\color{blue}{y \cdot x + \left(y \cdot z + z \cdot x\right)}} \]
    4. Simplified6.1

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

    if 1.020853970910143e93 < y

    1. Initial program 51.1

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

      \[\leadsto \color{blue}{2 \cdot \sqrt{\mathsf{fma}\left(x, y + z, y \cdot z\right)}} \]
    3. Applied pow1/2_binary6450.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.7253211663182805 \cdot 10^{+23}:\\ \;\;\;\;2 \cdot e^{0.5 \cdot \left(\log \left(-\left(y + z\right)\right) - \log \left(\frac{-1}{x}\right)\right)}\\ \mathbf{elif}\;y \leq -1.1343957496177142 \cdot 10^{-192}:\\ \;\;\;\;2 \cdot {\left(\left(y + z\right) \cdot x\right)}^{0.5}\\ \mathbf{elif}\;y \leq -2.7214926907983235 \cdot 10^{-253}:\\ \;\;\;\;2 \cdot e^{0.5 \cdot \left(\log \left(-\left(y + z\right)\right) - \log \left(\frac{-1}{x}\right)\right)}\\ \mathbf{elif}\;y \leq 1.0208539709101426 \cdot 10^{+93}:\\ \;\;\;\;2 \cdot \sqrt{\mathsf{fma}\left(y, x, z \cdot \left(y + x\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot e^{0.5 \cdot \left(\log \left(y + x\right) - \log \left(\frac{1}{z}\right)\right)}\\ \end{array} \]

Reproduce

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