Average Error: 20.0 → 3.1
Time: 15.5s
Precision: binary64
Cost: 26572
\[ \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 := 2 \cdot e^{\log \left(\sqrt[3]{y + z} \cdot \sqrt[3]{x}\right) \cdot 1.5}\\ \mathbf{if}\;y \leq -7.2 \cdot 10^{+30}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.35 \cdot 10^{-198}:\\ \;\;\;\;2 \cdot \sqrt{z \cdot x + y \cdot \left(z + x\right)}\\ \mathbf{elif}\;y \leq 0:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(\sqrt{z} \cdot \sqrt{y}\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 (* (log (* (cbrt (+ y z)) (cbrt x))) 1.5)))))
   (if (<= y -7.2e+30)
     t_0
     (if (<= y -1.35e-198)
       (* 2.0 (sqrt (+ (* z x) (* y (+ z x)))))
       (if (<= y 0.0) t_0 (* 2.0 (* (sqrt z) (sqrt y))))))))
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((log((cbrt((y + z)) * cbrt(x))) * 1.5));
	double tmp;
	if (y <= -7.2e+30) {
		tmp = t_0;
	} else if (y <= -1.35e-198) {
		tmp = 2.0 * sqrt(((z * x) + (y * (z + x))));
	} else if (y <= 0.0) {
		tmp = t_0;
	} else {
		tmp = 2.0 * (sqrt(z) * sqrt(y));
	}
	return tmp;
}
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 = 2.0 * Math.exp((Math.log((Math.cbrt((y + z)) * Math.cbrt(x))) * 1.5));
	double tmp;
	if (y <= -7.2e+30) {
		tmp = t_0;
	} else if (y <= -1.35e-198) {
		tmp = 2.0 * Math.sqrt(((z * x) + (y * (z + x))));
	} else if (y <= 0.0) {
		tmp = t_0;
	} else {
		tmp = 2.0 * (Math.sqrt(z) * Math.sqrt(y));
	}
	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(2.0 * exp(Float64(log(Float64(cbrt(Float64(y + z)) * cbrt(x))) * 1.5)))
	tmp = 0.0
	if (y <= -7.2e+30)
		tmp = t_0;
	elseif (y <= -1.35e-198)
		tmp = Float64(2.0 * sqrt(Float64(Float64(z * x) + Float64(y * Float64(z + x)))));
	elseif (y <= 0.0)
		tmp = t_0;
	else
		tmp = Float64(2.0 * Float64(sqrt(z) * sqrt(y)));
	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[(2.0 * N[Exp[N[(N[Log[N[(N[Power[N[(y + z), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 1.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -7.2e+30], t$95$0, If[LessEqual[y, -1.35e-198], N[(2.0 * N[Sqrt[N[(N[(z * x), $MachinePrecision] + N[(y * N[(z + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 0.0], t$95$0, N[(2.0 * N[(N[Sqrt[z], $MachinePrecision] * N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z}
\begin{array}{l}
t_0 := 2 \cdot e^{\log \left(\sqrt[3]{y + z} \cdot \sqrt[3]{x}\right) \cdot 1.5}\\
\mathbf{if}\;y \leq -7.2 \cdot 10^{+30}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;y \leq 0:\\
\;\;\;\;t_0\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original20.0
Target11.7
Herbie3.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 3 regimes
  2. if y < -7.2000000000000004e30 or -1.3500000000000001e-198 < y < 0.0

    1. Initial program 38.6

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

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

      \[\leadsto 2 \cdot \color{blue}{{\left({\left(\left(y + z\right) \cdot x\right)}^{1.5}\right)}^{0.3333333333333333}} \]
    4. Applied egg-rr40.8

      \[\leadsto 2 \cdot \color{blue}{e^{\log \left(\sqrt[3]{\left(y + z\right) \cdot x}\right) \cdot 1.5}} \]
    5. Applied egg-rr6.5

      \[\leadsto 2 \cdot e^{\log \color{blue}{\left(\sqrt[3]{y + z} \cdot \sqrt[3]{x}\right)} \cdot 1.5} \]

    if -7.2000000000000004e30 < y < -1.3500000000000001e-198

    1. Initial program 1.3

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

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

    if 0.0 < y

    1. Initial program 19.8

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

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

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

      \[\leadsto 2 \cdot \color{blue}{\sqrt{y \cdot z}} \]
    5. Simplified21.3

      \[\leadsto 2 \cdot \color{blue}{\sqrt{z \cdot y}} \]
      Proof
      (sqrt.f64 (*.f64 z y)): 0 points increase in error, 0 points decrease in error
      (sqrt.f64 (Rewrite<= *-commutative_binary64 (*.f64 y z))): 0 points increase in error, 0 points decrease in error
    6. Applied egg-rr2.3

      \[\leadsto 2 \cdot \color{blue}{\left(\sqrt{z} \cdot \sqrt{y}\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification3.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -7.2 \cdot 10^{+30}:\\ \;\;\;\;2 \cdot e^{\log \left(\sqrt[3]{y + z} \cdot \sqrt[3]{x}\right) \cdot 1.5}\\ \mathbf{elif}\;y \leq -1.35 \cdot 10^{-198}:\\ \;\;\;\;2 \cdot \sqrt{z \cdot x + y \cdot \left(z + x\right)}\\ \mathbf{elif}\;y \leq 0:\\ \;\;\;\;2 \cdot e^{\log \left(\sqrt[3]{y + z} \cdot \sqrt[3]{x}\right) \cdot 1.5}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(\sqrt{z} \cdot \sqrt{y}\right)\\ \end{array} \]

Alternatives

Alternative 1
Error11.0
Cost14664
\[\begin{array}{l} t_0 := \left(z \cdot x + y \cdot x\right) + y \cdot z\\ t_1 := 2 \cdot \left(\sqrt{z} \cdot \sqrt{y}\right)\\ \mathbf{if}\;t_0 \leq 10^{-307}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{+302}:\\ \;\;\;\;2 \cdot \sqrt{z \cdot x + y \cdot \left(z + x\right)}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error20.0
Cost7108
\[\begin{array}{l} \mathbf{if}\;y \leq 0:\\ \;\;\;\;2 \cdot \sqrt{z \cdot x + y \cdot x}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \sqrt{z \cdot \left(y + x\right)}\\ \end{array} \]
Alternative 3
Error20.0
Cost7104
\[2 \cdot \sqrt{z \cdot x + y \cdot \left(z + x\right)} \]
Alternative 4
Error21.0
Cost6980
\[\begin{array}{l} \mathbf{if}\;y \leq 1.1 \cdot 10^{-254}:\\ \;\;\;\;2 \cdot \sqrt{y \cdot x}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \sqrt{z \cdot \left(y + x\right)}\\ \end{array} \]
Alternative 5
Error20.0
Cost6980
\[\begin{array}{l} \mathbf{if}\;y \leq 0:\\ \;\;\;\;2 \cdot \sqrt{\left(y + z\right) \cdot x}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \sqrt{z \cdot \left(y + x\right)}\\ \end{array} \]
Alternative 6
Error21.7
Cost6852
\[\begin{array}{l} \mathbf{if}\;y \leq -9.2 \cdot 10^{-255}:\\ \;\;\;\;2 \cdot \sqrt{y \cdot x}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \sqrt{y \cdot z}\\ \end{array} \]
Alternative 7
Error42.0
Cost6720
\[2 \cdot \sqrt{y \cdot z} \]

Error

Reproduce

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