?

Average Error: 20.3 → 11.3
Time: 1.8min
Precision: binary64
Cost: 33480

?

\[2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z} \]
\[\begin{array}{l} t_0 := \mathsf{fma}\left(y, x, z \cdot \left(x + y\right)\right)\\ t_1 := t_0 \ne 0\\ t_2 := \sqrt{t_0}\\ \mathbf{if}\;z \leq -1.36 \cdot 10^{+111}:\\ \;\;\;\;2 \cdot \begin{array}{l} \mathbf{if}\;t_1:\\ \;\;\;\;\frac{1}{{\left(e^{-0.5}\right)}^{\left(\log \left(\left(-y\right) - x\right) - \log \left(\frac{-1}{z}\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array}\\ \mathbf{elif}\;z \leq 6 \cdot 10^{+37}:\\ \;\;\;\;2 \cdot \sqrt{\left(y + z\right) \cdot x + y \cdot z}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \begin{array}{l} \mathbf{if}\;t_1:\\ \;\;\;\;\frac{1}{e^{-0.5 \cdot \left(-1 \cdot \log \left(\frac{1}{z}\right) + \log \left(y + x\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array}\\ \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 (fma y x (* z (+ x y)))) (t_1 (!= t_0 0.0)) (t_2 (sqrt t_0)))
   (if (<= z -1.36e+111)
     (*
      2.0
      (if t_1
        (/ 1.0 (pow (exp -0.5) (- (log (- (- y) x)) (log (/ -1.0 z)))))
        t_2))
     (if (<= z 6e+37)
       (* 2.0 (sqrt (+ (* (+ y z) x) (* y z))))
       (*
        2.0
        (if t_1
          (/ 1.0 (exp (* -0.5 (+ (* -1.0 (log (/ 1.0 z))) (log (+ y x))))))
          t_2))))))
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 = fma(y, x, (z * (x + y)));
	int t_1 = t_0 != 0.0;
	double t_2 = sqrt(t_0);
	double tmp_1;
	if (z <= -1.36e+111) {
		double tmp_2;
		if (t_1) {
			tmp_2 = 1.0 / pow(exp(-0.5), (log((-y - x)) - log((-1.0 / z))));
		} else {
			tmp_2 = t_2;
		}
		tmp_1 = 2.0 * tmp_2;
	} else if (z <= 6e+37) {
		tmp_1 = 2.0 * sqrt((((y + z) * x) + (y * z)));
	} else {
		double tmp_3;
		if (t_1) {
			tmp_3 = 1.0 / exp((-0.5 * ((-1.0 * log((1.0 / z))) + log((y + x)))));
		} else {
			tmp_3 = t_2;
		}
		tmp_1 = 2.0 * tmp_3;
	}
	return tmp_1;
}
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 = fma(y, x, Float64(z * Float64(x + y)))
	t_1 = t_0 != 0.0
	t_2 = sqrt(t_0)
	tmp_1 = 0.0
	if (z <= -1.36e+111)
		tmp_2 = 0.0
		if (t_1)
			tmp_2 = Float64(1.0 / (exp(-0.5) ^ Float64(log(Float64(Float64(-y) - x)) - log(Float64(-1.0 / z)))));
		else
			tmp_2 = t_2;
		end
		tmp_1 = Float64(2.0 * tmp_2);
	elseif (z <= 6e+37)
		tmp_1 = Float64(2.0 * sqrt(Float64(Float64(Float64(y + z) * x) + Float64(y * z))));
	else
		tmp_3 = 0.0
		if (t_1)
			tmp_3 = Float64(1.0 / exp(Float64(-0.5 * Float64(Float64(-1.0 * log(Float64(1.0 / z))) + log(Float64(y + x))))));
		else
			tmp_3 = t_2;
		end
		tmp_1 = Float64(2.0 * tmp_3);
	end
	return tmp_1
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[(y * x + N[(z * N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = Unequal[t$95$0, 0.0]}, Block[{t$95$2 = N[Sqrt[t$95$0], $MachinePrecision]}, If[LessEqual[z, -1.36e+111], N[(2.0 * If[t$95$1, N[(1.0 / N[Power[N[Exp[-0.5], $MachinePrecision], N[(N[Log[N[((-y) - x), $MachinePrecision]], $MachinePrecision] - N[Log[N[(-1.0 / z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], t$95$2]), $MachinePrecision], If[LessEqual[z, 6e+37], N[(2.0 * N[Sqrt[N[(N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision] + N[(y * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(2.0 * If[t$95$1, N[(1.0 / N[Exp[N[(-0.5 * N[(N[(-1.0 * N[Log[N[(1.0 / z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[Log[N[(y + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], t$95$2]), $MachinePrecision]]]]]]
2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z}
\begin{array}{l}
t_0 := \mathsf{fma}\left(y, x, z \cdot \left(x + y\right)\right)\\
t_1 := t_0 \ne 0\\
t_2 := \sqrt{t_0}\\
\mathbf{if}\;z \leq -1.36 \cdot 10^{+111}:\\
\;\;\;\;2 \cdot \begin{array}{l}
\mathbf{if}\;t_1:\\
\;\;\;\;\frac{1}{{\left(e^{-0.5}\right)}^{\left(\log \left(\left(-y\right) - x\right) - \log \left(\frac{-1}{z}\right)\right)}}\\

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}\\

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

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

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}\\


\end{array}

Error?

Target

Original20.3
Target19.3
Herbie11.3
\[\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 z < -1.3600000000000001e111

    1. Initial program 36.9

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

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

      \[\leadsto 2 \cdot \color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;\mathsf{fma}\left(y, x, z \cdot \left(x + y\right)\right) \ne 0:\\ \;\;\;\;\frac{1}{{\left(\mathsf{fma}\left(y, x, z \cdot \left(x + y\right)\right)\right)}^{-0.5}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(y, x, z \cdot \left(x + y\right)\right)}\\ } \end{array}} \]
    4. Taylor expanded in z around -inf 8.2

      \[\leadsto 2 \cdot \begin{array}{l} \mathbf{if}\;\mathsf{fma}\left(y, x, z \cdot \left(x + y\right)\right) \ne 0:\\ \;\;\;\;\frac{1}{\color{blue}{e^{-0.5 \cdot \left(\log \left(-1 \cdot \left(y + x\right)\right) + -1 \cdot \log \left(\frac{-1}{z}\right)\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(y, x, z \cdot \left(x + y\right)\right)}\\ \end{array} \]
    5. Simplified8.2

      \[\leadsto 2 \cdot \begin{array}{l} \mathbf{if}\;\mathsf{fma}\left(y, x, z \cdot \left(x + y\right)\right) \ne 0:\\ \;\;\;\;\frac{1}{\color{blue}{{\left(e^{-0.5}\right)}^{\left(\log \left(\left(-y\right) - x\right) - \log \left(\frac{-1}{z}\right)\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(y, x, z \cdot \left(x + y\right)\right)}\\ \end{array} \]
      Proof

    if -1.3600000000000001e111 < z < 6.00000000000000043e37

    1. Initial program 12.5

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

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

    if 6.00000000000000043e37 < z

    1. Initial program 30.5

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

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

      \[\leadsto 2 \cdot \color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;\mathsf{fma}\left(y, x, z \cdot \left(x + y\right)\right) \ne 0:\\ \;\;\;\;\frac{1}{{\left(\mathsf{fma}\left(y, x, z \cdot \left(x + y\right)\right)\right)}^{-0.5}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(y, x, z \cdot \left(x + y\right)\right)}\\ } \end{array}} \]
    4. Taylor expanded in z around inf 10.4

      \[\leadsto 2 \cdot \begin{array}{l} \mathbf{if}\;\mathsf{fma}\left(y, x, z \cdot \left(x + y\right)\right) \ne 0:\\ \;\;\;\;\frac{1}{\color{blue}{e^{-0.5 \cdot \left(-1 \cdot \log \left(\frac{1}{z}\right) + \log \left(y + x\right)\right)}}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(y, x, z \cdot \left(x + y\right)\right)}\\ \end{array} \]
  3. Recombined 3 regimes into one program.

Alternatives

Alternative 1
Error11.4
Cost27340
\[\begin{array}{l} t_0 := \mathsf{fma}\left(y, x, z \cdot \left(x + y\right)\right)\\ t_1 := t_0 \ne 0\\ t_2 := \sqrt{t_0}\\ \mathbf{if}\;z \leq -5.9 \cdot 10^{+113}:\\ \;\;\;\;2 \cdot \begin{array}{l} \mathbf{if}\;t_1:\\ \;\;\;\;\frac{1}{e^{-0.5 \cdot \left(\log \left(-1 \cdot \left(y + x\right)\right) + -1 \cdot \log \left(\frac{-1}{z}\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array}\\ \mathbf{elif}\;z \leq 1.12 \cdot 10^{+38}:\\ \;\;\;\;2 \cdot \sqrt{\left(y + z\right) \cdot x + y \cdot z}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \begin{array}{l} \mathbf{if}\;t_1:\\ \;\;\;\;\frac{1}{e^{-0.5 \cdot \left(-1 \cdot \log \left(\frac{1}{z}\right) + \log \left(y + x\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array}\\ \end{array} \]
Alternative 2
Error14.9
Cost27272
\[\begin{array}{l} \mathbf{if}\;\left(x \cdot y + x \cdot z\right) + y \cdot z \leq 10^{+308}:\\ \;\;\;\;2 \cdot \sqrt{\left(y + z\right) \cdot x + y \cdot z}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \begin{array}{l} \mathbf{if}\;z \cdot x \ne 0:\\ \;\;\;\;\frac{1}{{\left(e^{-0.5}\right)}^{\left(\log \left(y + z\right) + \log x\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(y, x, z \cdot \left(x + y\right)\right)}\\ \end{array}\\ \end{array} \]
Alternative 3
Error14.9
Cost21192
\[\begin{array}{l} \mathbf{if}\;\left(x \cdot y + x \cdot z\right) + y \cdot z \leq 10^{+308}:\\ \;\;\;\;2 \cdot \sqrt{\left(y + z\right) \cdot x + y \cdot z}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \begin{array}{l} \mathbf{if}\;z \cdot x \ne 0:\\ \;\;\;\;\frac{1}{e^{-0.5 \cdot \left(\log \left(y + z\right) + -1 \cdot \log \left(\frac{1}{x}\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(y, x, z \cdot \left(x + y\right)\right)}\\ \end{array}\\ \end{array} \]
Alternative 4
Error40.2
Cost7380
\[\begin{array}{l} t_0 := 2 \cdot \sqrt{z \cdot x}\\ t_1 := 2 \cdot \sqrt{y \cdot x}\\ \mathbf{if}\;x \leq -1.45 \cdot 10^{+71}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -9.5 \cdot 10^{+42}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.25 \cdot 10^{-93}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4 \cdot 10^{-96}:\\ \;\;\;\;2 \cdot \sqrt{z \cdot y}\\ \mathbf{elif}\;x \leq 1.9 \cdot 10^{+183}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error28.5
Cost7376
\[\begin{array}{l} t_0 := 2 \cdot \sqrt{z \cdot x}\\ t_1 := 2 \cdot \sqrt{y \cdot \left(z + x\right)}\\ \mathbf{if}\;y \leq -1.15 \cdot 10^{-105}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 5 \cdot 10^{-186}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 7.2 \cdot 10^{-146}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.6 \cdot 10^{-96}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error26.9
Cost7112
\[\begin{array}{l} t_0 := 2 \cdot \sqrt{y \cdot \left(z + x\right)}\\ \mathbf{if}\;y \leq -150000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 4.8 \cdot 10^{-68}:\\ \;\;\;\;2 \cdot \sqrt{\left(y + x\right) \cdot z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error25.7
Cost7112
\[\begin{array}{l} t_0 := 2 \cdot \sqrt{\left(z + y\right) \cdot x}\\ \mathbf{if}\;x \leq -7.5 \cdot 10^{-79}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 5.5 \cdot 10^{-73}:\\ \;\;\;\;2 \cdot \sqrt{\left(y + x\right) \cdot z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error20.3
Cost7104
\[2 \cdot \sqrt{\left(y + z\right) \cdot x + y \cdot z} \]
Alternative 9
Error40.8
Cost6984
\[\begin{array}{l} t_0 := 2 \cdot \sqrt{y \cdot x}\\ \mathbf{if}\;y \leq -11000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 5.7 \cdot 10^{-68}:\\ \;\;\;\;2 \cdot \sqrt{z \cdot x}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 10
Error48.3
Cost6720
\[2 \cdot \sqrt{y \cdot x} \]

Error

Reproduce?

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