Average Error: 20.1 → 16.0
Time: 5.1s
Precision: binary64
\[ \begin{array}{c}[x, y, z] = \mathsf{sort}([x, y, z])\\ \end{array} \]
\[2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z} \]
\[\begin{array}{l} t_0 := x \cdot \left(y + z\right)\\ \mathbf{if}\;x \leq 9.6 \cdot 10^{-306}:\\ \;\;\;\;2 \cdot \left|\sqrt{\mathsf{fma}\left(y, z, t_0\right)}\right|\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \mathsf{hypot}\left(\sqrt{t_0}, \sqrt{y} \cdot \sqrt{z}\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 (* x (+ y z))))
   (if (<= x 9.6e-306)
     (* 2.0 (fabs (sqrt (fma y z t_0))))
     (* 2.0 (hypot (sqrt t_0) (* (sqrt y) (sqrt 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 = x * (y + z);
	double tmp;
	if (x <= 9.6e-306) {
		tmp = 2.0 * fabs(sqrt(fma(y, z, t_0)));
	} else {
		tmp = 2.0 * hypot(sqrt(t_0), (sqrt(y) * sqrt(z)));
	}
	return tmp;
}
function code(x, y, z)
	return Float64(2.0 * sqrt(Float64(Float64(Float64(x * y) + Float64(x * z)) + Float64(y * z))))
end
function code(x, y, z)
	t_0 = Float64(x * Float64(y + z))
	tmp = 0.0
	if (x <= 9.6e-306)
		tmp = Float64(2.0 * abs(sqrt(fma(y, z, t_0))));
	else
		tmp = Float64(2.0 * hypot(sqrt(t_0), Float64(sqrt(y) * sqrt(z))));
	end
	return tmp
end
code[x_, y_, z_] := N[(2.0 * N[Sqrt[N[(N[(N[(x * y), $MachinePrecision] + N[(x * z), $MachinePrecision]), $MachinePrecision] + N[(y * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 9.6e-306], N[(2.0 * N[Abs[N[Sqrt[N[(y * z + t$95$0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(2.0 * N[Sqrt[N[Sqrt[t$95$0], $MachinePrecision] ^ 2 + N[(N[Sqrt[y], $MachinePrecision] * N[Sqrt[z], $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]]]
2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z}
\begin{array}{l}
t_0 := x \cdot \left(y + z\right)\\
\mathbf{if}\;x \leq 9.6 \cdot 10^{-306}:\\
\;\;\;\;2 \cdot \left|\sqrt{\mathsf{fma}\left(y, z, t_0\right)}\right|\\

\mathbf{else}:\\
\;\;\;\;2 \cdot \mathsf{hypot}\left(\sqrt{t_0}, \sqrt{y} \cdot \sqrt{z}\right)\\


\end{array}

Error

Target

Original20.1
Target11.3
Herbie16.0
\[\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 2 regimes
  2. if x < 9.5999999999999998e-306

    1. Initial program 19.7

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

      \[\leadsto 2 \cdot \color{blue}{\sqrt[3]{{\left(\mathsf{fma}\left(y, z, x \cdot \left(y + z\right)\right)\right)}^{1.5}}} \]
    3. Applied egg-rr19.7

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

    if 9.5999999999999998e-306 < x

    1. Initial program 21.4

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

      \[\leadsto 2 \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\sqrt{z}, \sqrt{z} \cdot y, x \cdot \left(y + z\right)\right)}} \]
    3. Applied egg-rr4.9

      \[\leadsto 2 \cdot \color{blue}{\mathsf{hypot}\left(\sqrt{x \cdot \left(z + y\right)}, \sqrt{y} \cdot \sqrt{z}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification16.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 9.6 \cdot 10^{-306}:\\ \;\;\;\;2 \cdot \left|\sqrt{\mathsf{fma}\left(y, z, x \cdot \left(y + z\right)\right)}\right|\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \mathsf{hypot}\left(\sqrt{x \cdot \left(y + z\right)}, \sqrt{y} \cdot \sqrt{z}\right)\\ \end{array} \]

Reproduce

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