?

Average Error: 19.4 → 10.8
Time: 11.9s
Precision: binary64
Cost: 14212

?

\[ \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} \mathbf{if}\;\left(x \cdot y + x \cdot z\right) + y \cdot z \leq 5 \cdot 10^{+307}:\\ \;\;\;\;2 \cdot {\left(\mathsf{fma}\left(x, y + z, y \cdot z\right)\right)}^{0.5}\\ \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
 (if (<= (+ (+ (* x y) (* x z)) (* y z)) 5e+307)
   (* 2.0 (pow (fma x (+ y z) (* y z)) 0.5))
   (* 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 tmp;
	if ((((x * y) + (x * z)) + (y * z)) <= 5e+307) {
		tmp = 2.0 * pow(fma(x, (y + z), (y * z)), 0.5);
	} else {
		tmp = 2.0 * (sqrt(z) * 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)
	tmp = 0.0
	if (Float64(Float64(Float64(x * y) + Float64(x * z)) + Float64(y * z)) <= 5e+307)
		tmp = Float64(2.0 * (fma(x, Float64(y + z), Float64(y * z)) ^ 0.5));
	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_] := If[LessEqual[N[(N[(N[(x * y), $MachinePrecision] + N[(x * z), $MachinePrecision]), $MachinePrecision] + N[(y * z), $MachinePrecision]), $MachinePrecision], 5e+307], N[(2.0 * N[Power[N[(x * N[(y + z), $MachinePrecision] + N[(y * z), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision], 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}
\mathbf{if}\;\left(x \cdot y + x \cdot z\right) + y \cdot z \leq 5 \cdot 10^{+307}:\\
\;\;\;\;2 \cdot {\left(\mathsf{fma}\left(x, y + z, y \cdot z\right)\right)}^{0.5}\\

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


\end{array}

Error?

Target

Original19.4
Target11.2
Herbie10.8
\[\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 (+.f64 (+.f64 (*.f64 x y) (*.f64 x z)) (*.f64 y z)) < 5e307

    1. Initial program 2.4

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

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

      [Start]2.4

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

      distribute-lft-out [=>]2.4

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

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

    if 5e307 < (+.f64 (+.f64 (*.f64 x y) (*.f64 x z)) (*.f64 y z))

    1. Initial program 63.8

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

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

      [Start]63.8

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

      distribute-lft-out [=>]63.8

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

      \[\leadsto 2 \cdot \color{blue}{\sqrt{y \cdot z}} \]
    4. Applied egg-rr32.7

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

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

Alternatives

Alternative 1
Error10.8
Cost13892
\[\begin{array}{l} \mathbf{if}\;\left(x \cdot y + x \cdot z\right) + y \cdot z \leq 5 \cdot 10^{+307}:\\ \;\;\;\;2 \cdot \sqrt{y \cdot z + x \cdot \left(y + z\right)}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(\sqrt{z} \cdot \sqrt{y}\right)\\ \end{array} \]
Alternative 2
Error19.4
Cost7104
\[2 \cdot \sqrt{y \cdot z + x \cdot \left(y + z\right)} \]
Alternative 3
Error20.2
Cost6980
\[\begin{array}{l} \mathbf{if}\;y \leq -6.8 \cdot 10^{-281}:\\ \;\;\;\;2 \cdot \sqrt{x \cdot y}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \sqrt{z \cdot \left(x + y\right)}\\ \end{array} \]
Alternative 4
Error19.5
Cost6980
\[\begin{array}{l} \mathbf{if}\;y \leq 3.6 \cdot 10^{-308}:\\ \;\;\;\;2 \cdot \sqrt{x \cdot \left(y + z\right)}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \sqrt{z \cdot \left(x + y\right)}\\ \end{array} \]
Alternative 5
Error20.9
Cost6916
\[\begin{array}{l} \mathbf{if}\;y \leq -5 \cdot 10^{-310}:\\ \;\;\;\;2 \cdot \sqrt{x \cdot y}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot {\left(y \cdot z\right)}^{0.5}\\ \end{array} \]
Alternative 6
Error20.9
Cost6852
\[\begin{array}{l} \mathbf{if}\;y \leq -5 \cdot 10^{-310}:\\ \;\;\;\;2 \cdot \sqrt{x \cdot y}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \sqrt{y \cdot z}\\ \end{array} \]
Alternative 7
Error41.8
Cost6720
\[2 \cdot \sqrt{x \cdot y} \]

Error

Reproduce?

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