Average Error: 19.7 → 10.5
Time: 12.6s
Precision: binary64
Cost: 14921
\[ \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 := \left(x \cdot y + x \cdot z\right) + y \cdot z\\ \mathbf{if}\;t_0 \leq 5 \cdot 10^{-324} \lor \neg \left(t_0 \leq 10^{+305}\right):\\ \;\;\;\;2 \cdot \left(\sqrt{z} \cdot \sqrt{y}\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \sqrt{\mathsf{fma}\left(x, y, z \cdot \left(x + y\right)\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) (* x z)) (* y z))))
   (if (or (<= t_0 5e-324) (not (<= t_0 1e+305)))
     (* 2.0 (* (sqrt z) (sqrt y)))
     (* 2.0 (sqrt (fma x y (* z (+ x 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 = ((x * y) + (x * z)) + (y * z);
	double tmp;
	if ((t_0 <= 5e-324) || !(t_0 <= 1e+305)) {
		tmp = 2.0 * (sqrt(z) * sqrt(y));
	} else {
		tmp = 2.0 * sqrt(fma(x, y, (z * (x + 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(Float64(Float64(x * y) + Float64(x * z)) + Float64(y * z))
	tmp = 0.0
	if ((t_0 <= 5e-324) || !(t_0 <= 1e+305))
		tmp = Float64(2.0 * Float64(sqrt(z) * sqrt(y)));
	else
		tmp = Float64(2.0 * sqrt(fma(x, y, Float64(z * Float64(x + 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[(N[(N[(x * y), $MachinePrecision] + N[(x * z), $MachinePrecision]), $MachinePrecision] + N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, 5e-324], N[Not[LessEqual[t$95$0, 1e+305]], $MachinePrecision]], N[(2.0 * N[(N[Sqrt[z], $MachinePrecision] * N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 * N[Sqrt[N[(x * y + N[(z * N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z}
\begin{array}{l}
t_0 := \left(x \cdot y + x \cdot z\right) + y \cdot z\\
\mathbf{if}\;t_0 \leq 5 \cdot 10^{-324} \lor \neg \left(t_0 \leq 10^{+305}\right):\\
\;\;\;\;2 \cdot \left(\sqrt{z} \cdot \sqrt{y}\right)\\

\mathbf{else}:\\
\;\;\;\;2 \cdot \sqrt{\mathsf{fma}\left(x, y, z \cdot \left(x + y\right)\right)}\\


\end{array}

Error

Target

Original19.7
Target11.5
Herbie10.5
\[\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)) < 4.94066e-324 or 9.9999999999999994e304 < (+.f64 (+.f64 (*.f64 x y) (*.f64 x z)) (*.f64 y z))

    1. Initial program 62.9

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

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

      [Start]62.9

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

      associate-+l+ [=>]62.9

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

      fma-def [=>]62.9

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

      distribute-rgt-out [=>]62.9

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

      \[\leadsto 2 \cdot \color{blue}{{\left({\left(\mathsf{fma}\left(x, y, z \cdot \left(x + y\right)\right)\right)}^{1.5}\right)}^{0.3333333333333333}} \]
    4. Simplified63.7

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

      [Start]63.7

      \[ 2 \cdot {\left({\left(\mathsf{fma}\left(x, y, z \cdot \left(x + y\right)\right)\right)}^{1.5}\right)}^{0.3333333333333333} \]

      unpow1/3 [=>]63.7

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

      fma-def [<=]63.7

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

      distribute-lft-in [=>]63.7

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

      *-commutative [<=]63.7

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

      associate-+r+ [=>]63.7

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

      *-commutative [<=]63.7

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

      distribute-lft-in [<=]63.7

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

      *-commutative [<=]63.7

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

      fma-def [=>]63.7

      \[ 2 \cdot \sqrt[3]{{\color{blue}{\left(\mathsf{fma}\left(y + z, x, y \cdot z\right)\right)}}^{1.5}} \]
    5. Taylor expanded in x around 0 62.8

      \[\leadsto 2 \cdot \color{blue}{\sqrt{y \cdot z}} \]
    6. Simplified62.8

      \[\leadsto 2 \cdot \color{blue}{\sqrt{z \cdot y}} \]
      Proof

      [Start]62.8

      \[ 2 \cdot \sqrt{y \cdot z} \]

      *-commutative [=>]62.8

      \[ 2 \cdot \sqrt{\color{blue}{z \cdot y}} \]
    7. Applied egg-rr33.1

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

    if 4.94066e-324 < (+.f64 (+.f64 (*.f64 x y) (*.f64 x z)) (*.f64 y z)) < 9.9999999999999994e304

    1. Initial program 0.3

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

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

      [Start]0.3

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

      associate-+l+ [=>]0.3

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

      fma-def [=>]0.3

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

      distribute-rgt-out [=>]0.3

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

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

Alternatives

Alternative 1
Error10.5
Cost14665
\[\begin{array}{l} t_0 := \left(x \cdot y + x \cdot z\right) + y \cdot z\\ \mathbf{if}\;t_0 \leq 5 \cdot 10^{-324} \lor \neg \left(t_0 \leq 10^{+305}\right):\\ \;\;\;\;2 \cdot \left(\sqrt{z} \cdot \sqrt{y}\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \sqrt{y \cdot z + x \cdot \left(y + z\right)}\\ \end{array} \]
Alternative 2
Error19.7
Cost7104
\[2 \cdot \sqrt{y \cdot z + x \cdot \left(y + z\right)} \]
Alternative 3
Error21.0
Cost6980
\[\begin{array}{l} \mathbf{if}\;y \leq -7.4 \cdot 10^{-246}:\\ \;\;\;\;2 \cdot \sqrt{x \cdot y}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \sqrt{z \cdot \left(x + y\right)}\\ \end{array} \]
Alternative 4
Error20.3
Cost6980
\[\begin{array}{l} \mathbf{if}\;y \leq -4 \cdot 10^{-245}:\\ \;\;\;\;2 \cdot \sqrt{x \cdot \left(y + z\right)}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \sqrt{z \cdot \left(x + y\right)}\\ \end{array} \]
Alternative 5
Error21.2
Cost6852
\[\begin{array}{l} \mathbf{if}\;y \leq -2 \cdot 10^{-310}:\\ \;\;\;\;2 \cdot \sqrt{x \cdot y}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \sqrt{y \cdot z}\\ \end{array} \]
Alternative 6
Error41.3
Cost6720
\[2 \cdot \sqrt{x \cdot y} \]

Error

Reproduce

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