Average Error: 19.8 → 10.7
Time: 31.3s
Precision: binary64
Cost: 20808
\[2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z} \]
\[\begin{array}{l} t_0 := \left(y + x\right) \cdot z\\ t_1 := t_0 \ne 0\\ t_2 := \sqrt{t_0}\\ \mathbf{if}\;z \leq -6.1 \cdot 10^{+26}:\\ \;\;\;\;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 8.8 \cdot 10^{+104}:\\ \;\;\;\;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(\log \left(y + x\right) + \log z\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 (* (+ y x) z)) (t_1 (!= t_0 0.0)) (t_2 (sqrt t_0)))
   (if (<= z -6.1e+26)
     (*
      2.0
      (if t_1
        (/
         1.0
         (exp (* -0.5 (+ (log (* -1.0 (+ y x))) (* -1.0 (log (/ -1.0 z)))))))
        t_2))
     (if (<= z 8.8e+104)
       (* 2.0 (sqrt (+ (* (+ y z) x) (* y z))))
       (*
        2.0
        (if t_1 (/ 1.0 (exp (* -0.5 (+ (log (+ y x)) (log z))))) 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 = (y + x) * z;
	int t_1 = t_0 != 0.0;
	double t_2 = sqrt(t_0);
	double tmp_1;
	if (z <= -6.1e+26) {
		double tmp_2;
		if (t_1) {
			tmp_2 = 1.0 / exp((-0.5 * (log((-1.0 * (y + x))) + (-1.0 * log((-1.0 / z))))));
		} else {
			tmp_2 = t_2;
		}
		tmp_1 = 2.0 * tmp_2;
	} else if (z <= 8.8e+104) {
		tmp_1 = 2.0 * sqrt((((y + z) * x) + (y * z)));
	} else {
		double tmp_3;
		if (t_1) {
			tmp_3 = 1.0 / exp((-0.5 * (log((y + x)) + log(z))));
		} else {
			tmp_3 = t_2;
		}
		tmp_1 = 2.0 * tmp_3;
	}
	return tmp_1;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = 2.0d0 * sqrt((((x * y) + (x * z)) + (y * z)))
end function
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    logical :: t_1
    real(8) :: t_2
    real(8) :: tmp
    real(8) :: tmp_1
    real(8) :: tmp_2
    real(8) :: tmp_3
    t_0 = (y + x) * z
    t_1 = t_0 /= 0.0d0
    t_2 = sqrt(t_0)
    if (z <= (-6.1d+26)) then
        if (t_1) then
            tmp_2 = 1.0d0 / exp(((-0.5d0) * (log(((-1.0d0) * (y + x))) + ((-1.0d0) * log(((-1.0d0) / z))))))
        else
            tmp_2 = t_2
        end if
        tmp_1 = 2.0d0 * tmp_2
    else if (z <= 8.8d+104) then
        tmp_1 = 2.0d0 * sqrt((((y + z) * x) + (y * z)))
    else
        if (t_1) then
            tmp_3 = 1.0d0 / exp(((-0.5d0) * (log((y + x)) + log(z))))
        else
            tmp_3 = t_2
        end if
        tmp_1 = 2.0d0 * tmp_3
    end if
    code = tmp_1
end function
public static double code(double x, double y, double z) {
	return 2.0 * Math.sqrt((((x * y) + (x * z)) + (y * z)));
}
public static double code(double x, double y, double z) {
	double t_0 = (y + x) * z;
	boolean t_1 = t_0 != 0.0;
	double t_2 = Math.sqrt(t_0);
	double tmp_1;
	if (z <= -6.1e+26) {
		double tmp_2;
		if (t_1) {
			tmp_2 = 1.0 / Math.exp((-0.5 * (Math.log((-1.0 * (y + x))) + (-1.0 * Math.log((-1.0 / z))))));
		} else {
			tmp_2 = t_2;
		}
		tmp_1 = 2.0 * tmp_2;
	} else if (z <= 8.8e+104) {
		tmp_1 = 2.0 * Math.sqrt((((y + z) * x) + (y * z)));
	} else {
		double tmp_3;
		if (t_1) {
			tmp_3 = 1.0 / Math.exp((-0.5 * (Math.log((y + x)) + Math.log(z))));
		} else {
			tmp_3 = t_2;
		}
		tmp_1 = 2.0 * tmp_3;
	}
	return tmp_1;
}
def code(x, y, z):
	return 2.0 * math.sqrt((((x * y) + (x * z)) + (y * z)))
def code(x, y, z):
	t_0 = (y + x) * z
	t_1 = t_0 != 0.0
	t_2 = math.sqrt(t_0)
	tmp_1 = 0
	if z <= -6.1e+26:
		tmp_2 = 0
		if t_1:
			tmp_2 = 1.0 / math.exp((-0.5 * (math.log((-1.0 * (y + x))) + (-1.0 * math.log((-1.0 / z))))))
		else:
			tmp_2 = t_2
		tmp_1 = 2.0 * tmp_2
	elif z <= 8.8e+104:
		tmp_1 = 2.0 * math.sqrt((((y + z) * x) + (y * z)))
	else:
		tmp_3 = 0
		if t_1:
			tmp_3 = 1.0 / math.exp((-0.5 * (math.log((y + x)) + math.log(z))))
		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 = Float64(Float64(y + x) * z)
	t_1 = t_0 != 0.0
	t_2 = sqrt(t_0)
	tmp_1 = 0.0
	if (z <= -6.1e+26)
		tmp_2 = 0.0
		if (t_1)
			tmp_2 = Float64(1.0 / exp(Float64(-0.5 * Float64(log(Float64(-1.0 * Float64(y + x))) + Float64(-1.0 * log(Float64(-1.0 / z)))))));
		else
			tmp_2 = t_2;
		end
		tmp_1 = Float64(2.0 * tmp_2);
	elseif (z <= 8.8e+104)
		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(log(Float64(y + x)) + log(z)))));
		else
			tmp_3 = t_2;
		end
		tmp_1 = Float64(2.0 * tmp_3);
	end
	return tmp_1
end
function tmp = code(x, y, z)
	tmp = 2.0 * sqrt((((x * y) + (x * z)) + (y * z)));
end
function tmp_5 = code(x, y, z)
	t_0 = (y + x) * z;
	t_1 = t_0 ~= 0.0;
	t_2 = sqrt(t_0);
	tmp_2 = 0.0;
	if (z <= -6.1e+26)
		tmp_3 = 0.0;
		if (t_1)
			tmp_3 = 1.0 / exp((-0.5 * (log((-1.0 * (y + x))) + (-1.0 * log((-1.0 / z))))));
		else
			tmp_3 = t_2;
		end
		tmp_2 = 2.0 * tmp_3;
	elseif (z <= 8.8e+104)
		tmp_2 = 2.0 * sqrt((((y + z) * x) + (y * z)));
	else
		tmp_4 = 0.0;
		if (t_1)
			tmp_4 = 1.0 / exp((-0.5 * (log((y + x)) + log(z))));
		else
			tmp_4 = t_2;
		end
		tmp_2 = 2.0 * tmp_4;
	end
	tmp_5 = tmp_2;
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[(N[(y + x), $MachinePrecision] * z), $MachinePrecision]}, Block[{t$95$1 = Unequal[t$95$0, 0.0]}, Block[{t$95$2 = N[Sqrt[t$95$0], $MachinePrecision]}, If[LessEqual[z, -6.1e+26], N[(2.0 * If[t$95$1, N[(1.0 / N[Exp[N[(-0.5 * N[(N[Log[N[(-1.0 * N[(y + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + N[(-1.0 * N[Log[N[(-1.0 / z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], t$95$2]), $MachinePrecision], If[LessEqual[z, 8.8e+104], 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[Log[N[(y + x), $MachinePrecision]], $MachinePrecision] + N[Log[z], $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 := \left(y + x\right) \cdot z\\
t_1 := t_0 \ne 0\\
t_2 := \sqrt{t_0}\\
\mathbf{if}\;z \leq -6.1 \cdot 10^{+26}:\\
\;\;\;\;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 8.8 \cdot 10^{+104}:\\
\;\;\;\;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(\log \left(y + x\right) + \log z\right)}}\\

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


\end{array}\\


\end{array}

Error

Target

Original19.8
Target19.0
Herbie10.7
\[\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 < -6.1000000000000003e26

    1. Initial program 30.8

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

      \[\leadsto 2 \cdot \sqrt{\color{blue}{\left(y + x\right) \cdot z}} \]
    3. Applied egg-rr31.7

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

      \[\leadsto 2 \cdot \begin{array}{l} \mathbf{if}\;\left(y + x\right) \cdot z \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{\left(y + x\right) \cdot z}\\ \end{array} \]

    if -6.1000000000000003e26 < z < 8.80000000000000002e104

    1. Initial program 11.5

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

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

    if 8.80000000000000002e104 < z

    1. Initial program 35.3

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

      \[\leadsto 2 \cdot \sqrt{\color{blue}{\left(y + x\right) \cdot z}} \]
    3. Applied egg-rr35.4

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

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

Alternatives

Alternative 1
Error14.8
Cost21064
\[\begin{array}{l} t_0 := \left(y + x\right) \cdot z\\ \mathbf{if}\;\left(x \cdot y + x \cdot z\right) + y \cdot z \leq 4 \cdot 10^{+302}:\\ \;\;\;\;2 \cdot \sqrt{\left(y + z\right) \cdot x + y \cdot z}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \begin{array}{l} \mathbf{if}\;t_0 \ne 0:\\ \;\;\;\;\frac{1}{e^{-0.5 \cdot \left(\log \left(y + x\right) + \log z\right)}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{t_0}\\ \end{array}\\ \end{array} \]
Alternative 2
Error14.8
Cost21000
\[\begin{array}{l} t_0 := \left(y + x\right) \cdot z\\ \mathbf{if}\;\left(x \cdot y + x \cdot z\right) + y \cdot z \leq 4 \cdot 10^{+302}:\\ \;\;\;\;2 \cdot \sqrt{\left(y + z\right) \cdot x + y \cdot z}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \begin{array}{l} \mathbf{if}\;t_0 \ne 0:\\ \;\;\;\;e^{--0.5 \cdot \left(\log z + \log \left(y + x\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{t_0}\\ \end{array}\\ \end{array} \]
Alternative 3
Error15.4
Cost20680
\[\begin{array}{l} t_0 := \left(y + x\right) \cdot z\\ t_1 := t_0 \ne 0\\ t_2 := \sqrt{t_0}\\ \mathbf{if}\;z \leq -1.05 \cdot 10^{+103}:\\ \;\;\;\;2 \cdot \begin{array}{l} \mathbf{if}\;t_1:\\ \;\;\;\;\frac{1}{e^{-0.5 \cdot \left(-1 \cdot \log \left(\frac{-1}{y}\right) + \log \left(-1 \cdot z\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array}\\ \mathbf{elif}\;z \leq 8.2 \cdot 10^{+105}:\\ \;\;\;\;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(\log \left(y + x\right) + \log z\right)}}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array}\\ \end{array} \]
Alternative 4
Error40.3
Cost7512
\[\begin{array}{l} t_0 := 2 \cdot \sqrt{z \cdot x}\\ t_1 := 2 \cdot \sqrt{y \cdot x}\\ t_2 := 2 \cdot \sqrt{y \cdot z}\\ \mathbf{if}\;x \leq -1.62 \cdot 10^{-78}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.9 \cdot 10^{-116}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 2.1 \cdot 10^{-58}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.3 \cdot 10^{-7}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 4.5 \cdot 10^{+104}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.5 \cdot 10^{+293}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error26.1
Cost7376
\[\begin{array}{l} t_0 := 2 \cdot \sqrt{y \cdot \left(z + x\right)}\\ t_1 := 2 \cdot \sqrt{\left(y + x\right) \cdot z}\\ \mathbf{if}\;z \leq -1.55 \cdot 10^{-80}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 4.8 \cdot 10^{-145}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 6 \cdot 10^{-59}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 4 \cdot 10^{-15}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error25.8
Cost7372
\[\begin{array}{l} t_0 := 2 \cdot \sqrt{\left(y + z\right) \cdot x}\\ \mathbf{if}\;x \leq -5.1 \cdot 10^{-76}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 3.8 \cdot 10^{-144}:\\ \;\;\;\;2 \cdot \sqrt{y \cdot \left(z + x\right)}\\ \mathbf{elif}\;x \leq 1.1 \cdot 10^{-7}:\\ \;\;\;\;2 \cdot \sqrt{z \cdot y + z \cdot x}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error25.9
Cost7244
\[\begin{array}{l} t_0 := 2 \cdot \sqrt{\left(y + z\right) \cdot x}\\ \mathbf{if}\;x \leq -1.04 \cdot 10^{-78}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 6 \cdot 10^{-146}:\\ \;\;\;\;2 \cdot \sqrt{y \cdot \left(z + x\right)}\\ \mathbf{elif}\;x \leq 3.3 \cdot 10^{-6}:\\ \;\;\;\;2 \cdot \sqrt{\left(y + x\right) \cdot z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error27.8
Cost7112
\[\begin{array}{l} t_0 := 2 \cdot \sqrt{y \cdot \left(z + x\right)}\\ \mathbf{if}\;y \leq -5.7 \cdot 10^{-130}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.95 \cdot 10^{-125}:\\ \;\;\;\;2 \cdot \sqrt{z \cdot x}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 9
Error19.8
Cost7104
\[2 \cdot \sqrt{\left(y + z\right) \cdot x + y \cdot z} \]
Alternative 10
Error40.8
Cost6984
\[\begin{array}{l} t_0 := 2 \cdot \sqrt{y \cdot x}\\ \mathbf{if}\;x \leq -1.45 \cdot 10^{-8}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 7.2 \cdot 10^{-6}:\\ \;\;\;\;2 \cdot \sqrt{y \cdot z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 11
Error48.3
Cost6720
\[2 \cdot \sqrt{y \cdot x} \]

Error

Reproduce

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