?

Average Accuracy: 69.7% → 94.3%
Time: 13.1s
Precision: binary64
Cost: 20228

?

\[ \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}\;y \leq -3.4 \cdot 10^{+60}:\\ \;\;\;\;2 \cdot e^{0.5 \cdot \log \left(\left(-z\right) - x\right) + -0.5 \cdot \log \left(\frac{-1}{y}\right)}\\ \mathbf{elif}\;y \leq 8.6 \cdot 10^{-277}:\\ \;\;\;\;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 (<= y -3.4e+60)
   (* 2.0 (exp (+ (* 0.5 (log (- (- z) x))) (* -0.5 (log (/ -1.0 y))))))
   (if (<= y 8.6e-277)
     (* 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 (y <= -3.4e+60) {
		tmp = 2.0 * exp(((0.5 * log((-z - x))) + (-0.5 * log((-1.0 / y)))));
	} else if (y <= 8.6e-277) {
		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 (y <= -3.4e+60)
		tmp = Float64(2.0 * exp(Float64(Float64(0.5 * log(Float64(Float64(-z) - x))) + Float64(-0.5 * log(Float64(-1.0 / y))))));
	elseif (y <= 8.6e-277)
		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[y, -3.4e+60], N[(2.0 * N[Exp[N[(N[(0.5 * N[Log[N[((-z) - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(-0.5 * N[Log[N[(-1.0 / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 8.6e-277], 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}\;y \leq -3.4 \cdot 10^{+60}:\\
\;\;\;\;2 \cdot e^{0.5 \cdot \log \left(\left(-z\right) - x\right) + -0.5 \cdot \log \left(\frac{-1}{y}\right)}\\

\mathbf{elif}\;y \leq 8.6 \cdot 10^{-277}:\\
\;\;\;\;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

Original69.7%
Target82.8%
Herbie94.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 y < -3.4e60

    1. Initial program 47.5%

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

      \[\leadsto \color{blue}{2 \cdot \sqrt{x \cdot \left(y + z\right) + y \cdot z}} \]
      Step-by-step derivation

      [Start]47.5

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

      distribute-lft-out [=>]47.5

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

      \[\leadsto 2 \cdot \color{blue}{{\left({\left(\mathsf{fma}\left(x, y + z, y \cdot z\right)\right)}^{2}\right)}^{0.25}} \]
      Step-by-step derivation

      [Start]47.5

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

      pow1/2 [=>]47.5

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

      metadata-eval [<=]47.5

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

      metadata-eval [<=]47.5

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

      metadata-eval [<=]47.5

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

      pow-prod-up [<=]47.2

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

      pow-prod-down [=>]11.8

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

      pow2 [=>]11.8

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

      fma-def [=>]11.8

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

      metadata-eval [=>]11.8

      \[ 2 \cdot {\left({\left(\mathsf{fma}\left(x, y + z, y \cdot z\right)\right)}^{2}\right)}^{\color{blue}{0.25}} \]
    4. Taylor expanded in y around -inf 43.1%

      \[\leadsto 2 \cdot \color{blue}{e^{0.25 \cdot \left(\log \left({\left(-1 \cdot z + -1 \cdot x\right)}^{2}\right) + -2 \cdot \log \left(\frac{-1}{y}\right)\right)}} \]
    5. Simplified86.2%

      \[\leadsto 2 \cdot \color{blue}{e^{0.5 \cdot \log \left(\left(-z\right) - x\right) + -0.5 \cdot \log \left(\frac{-1}{y}\right)}} \]
      Step-by-step derivation

      [Start]43.1

      \[ 2 \cdot e^{0.25 \cdot \left(\log \left({\left(-1 \cdot z + -1 \cdot x\right)}^{2}\right) + -2 \cdot \log \left(\frac{-1}{y}\right)\right)} \]

      distribute-lft-in [=>]43.1

      \[ 2 \cdot e^{\color{blue}{0.25 \cdot \log \left({\left(-1 \cdot z + -1 \cdot x\right)}^{2}\right) + 0.25 \cdot \left(-2 \cdot \log \left(\frac{-1}{y}\right)\right)}} \]

      log-pow [=>]86.2

      \[ 2 \cdot e^{0.25 \cdot \color{blue}{\left(2 \cdot \log \left(-1 \cdot z + -1 \cdot x\right)\right)} + 0.25 \cdot \left(-2 \cdot \log \left(\frac{-1}{y}\right)\right)} \]

      associate-*r* [=>]86.2

      \[ 2 \cdot e^{\color{blue}{\left(0.25 \cdot 2\right) \cdot \log \left(-1 \cdot z + -1 \cdot x\right)} + 0.25 \cdot \left(-2 \cdot \log \left(\frac{-1}{y}\right)\right)} \]

      metadata-eval [=>]86.2

      \[ 2 \cdot e^{\color{blue}{0.5} \cdot \log \left(-1 \cdot z + -1 \cdot x\right) + 0.25 \cdot \left(-2 \cdot \log \left(\frac{-1}{y}\right)\right)} \]

      mul-1-neg [=>]86.2

      \[ 2 \cdot e^{0.5 \cdot \log \left(-1 \cdot z + \color{blue}{\left(-x\right)}\right) + 0.25 \cdot \left(-2 \cdot \log \left(\frac{-1}{y}\right)\right)} \]

      unsub-neg [=>]86.2

      \[ 2 \cdot e^{0.5 \cdot \log \color{blue}{\left(-1 \cdot z - x\right)} + 0.25 \cdot \left(-2 \cdot \log \left(\frac{-1}{y}\right)\right)} \]

      mul-1-neg [=>]86.2

      \[ 2 \cdot e^{0.5 \cdot \log \left(\color{blue}{\left(-z\right)} - x\right) + 0.25 \cdot \left(-2 \cdot \log \left(\frac{-1}{y}\right)\right)} \]

      associate-*r* [=>]86.2

      \[ 2 \cdot e^{0.5 \cdot \log \left(\left(-z\right) - x\right) + \color{blue}{\left(0.25 \cdot -2\right) \cdot \log \left(\frac{-1}{y}\right)}} \]

      metadata-eval [=>]86.2

      \[ 2 \cdot e^{0.5 \cdot \log \left(\left(-z\right) - x\right) + \color{blue}{-0.5} \cdot \log \left(\frac{-1}{y}\right)} \]

    if -3.4e60 < y < 8.59999999999999981e-277

    1. Initial program 80.5%

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

      \[\leadsto \color{blue}{2 \cdot \sqrt{x \cdot \left(y + z\right) + y \cdot z}} \]
      Step-by-step derivation

      [Start]80.5

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

      distribute-lft-out [=>]80.5

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

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

      [Start]80.5

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

      pow1/2 [=>]80.5

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

      fma-def [=>]80.5

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

    if 8.59999999999999981e-277 < y

    1. Initial program 71.3%

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

      \[\leadsto \color{blue}{2 \cdot \sqrt{x \cdot \left(y + z\right) + y \cdot z}} \]
      Step-by-step derivation

      [Start]71.3

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

      distribute-lft-out [=>]71.3

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

      \[\leadsto 2 \cdot \color{blue}{{\left({\left(\mathsf{fma}\left(x, y + z, y \cdot z\right)\right)}^{2}\right)}^{0.25}} \]
      Step-by-step derivation

      [Start]71.3

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

      pow1/2 [=>]71.3

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

      metadata-eval [<=]71.3

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

      metadata-eval [<=]71.3

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

      metadata-eval [<=]71.3

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

      pow-prod-up [<=]70.8

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

      pow-prod-down [=>]40.8

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

      pow2 [=>]40.8

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

      fma-def [=>]40.8

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

      metadata-eval [=>]40.8

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

      \[\leadsto 2 \cdot {\left({\color{blue}{\left(y \cdot z\right)}}^{2}\right)}^{0.25} \]
    5. Applied egg-rr41.4%

      \[\leadsto 2 \cdot \color{blue}{\left(\sqrt{z} \cdot \sqrt{y}\right)} \]
      Step-by-step derivation

      [Start]21.5

      \[ 2 \cdot {\left({\left(y \cdot z\right)}^{2}\right)}^{0.25} \]

      pow-pow [=>]31.4

      \[ 2 \cdot \color{blue}{{\left(y \cdot z\right)}^{\left(2 \cdot 0.25\right)}} \]

      metadata-eval [=>]31.4

      \[ 2 \cdot {\left(y \cdot z\right)}^{\color{blue}{0.5}} \]

      pow1/2 [<=]31.4

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

      *-commutative [=>]31.4

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

      sqrt-prod [=>]41.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -3.4 \cdot 10^{+60}:\\ \;\;\;\;2 \cdot e^{0.5 \cdot \log \left(\left(-z\right) - x\right) + -0.5 \cdot \log \left(\frac{-1}{y}\right)}\\ \mathbf{elif}\;y \leq 8.6 \cdot 10^{-277}:\\ \;\;\;\;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
Accuracy83.3%
Cost13572
\[\begin{array}{l} \mathbf{if}\;y \leq 8.6 \cdot 10^{-277}:\\ \;\;\;\;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} \]
Alternative 2
Accuracy83.1%
Cost13252
\[\begin{array}{l} \mathbf{if}\;y \leq 8.6 \cdot 10^{-277}:\\ \;\;\;\;2 \cdot \sqrt{x \cdot \left(y + z\right)}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(\sqrt{z} \cdot \sqrt{y}\right)\\ \end{array} \]
Alternative 3
Accuracy69.7%
Cost7104
\[2 \cdot \sqrt{y \cdot z + x \cdot \left(y + z\right)} \]
Alternative 4
Accuracy68.4%
Cost6980
\[\begin{array}{l} \mathbf{if}\;y \leq 6.5 \cdot 10^{-268}:\\ \;\;\;\;2 \cdot {\left(y \cdot x\right)}^{0.5}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \sqrt{z \cdot \left(y + x\right)}\\ \end{array} \]
Alternative 5
Accuracy69.3%
Cost6980
\[\begin{array}{l} \mathbf{if}\;y \leq 6.5 \cdot 10^{-268}:\\ \;\;\;\;2 \cdot \sqrt{x \cdot \left(y + z\right)}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \sqrt{z \cdot \left(y + x\right)}\\ \end{array} \]
Alternative 6
Accuracy67.4%
Cost6916
\[\begin{array}{l} \mathbf{if}\;y \leq 6.5 \cdot 10^{-268}:\\ \;\;\;\;2 \cdot {\left(y \cdot x\right)}^{0.5}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \sqrt{y \cdot z}\\ \end{array} \]
Alternative 7
Accuracy67.4%
Cost6852
\[\begin{array}{l} \mathbf{if}\;y \leq 6.5 \cdot 10^{-268}:\\ \;\;\;\;2 \cdot \sqrt{y \cdot x}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \sqrt{y \cdot z}\\ \end{array} \]
Alternative 8
Accuracy35.4%
Cost6720
\[2 \cdot \sqrt{y \cdot x} \]

Error

Reproduce?

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