Average Error: 19.8 → 5.4
Time: 5.2s
Precision: binary64
\[ \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 {\left(e^{0.25 \cdot \left(\log \left(\left(-z\right) - y\right) - \log \left(\frac{-1}{x}\right)\right)}\right)}^{2}\\ \mathbf{if}\;y \leq -1.9 \cdot 10^{+102}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -2.2 \cdot 10^{-194}:\\ \;\;\;\;2 \cdot \left|\sqrt{\mathsf{fma}\left(x, y, {\left(\sqrt[3]{z \cdot \left(y + x\right)}\right)}^{3}\right)}\right|\\ \mathbf{elif}\;y \leq 4.4 \cdot 10^{-297}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.6 \cdot 10^{-173}:\\ \;\;\;\;2 \cdot {\left(e^{0.25 \cdot \left(\log \left(y + x\right) - \log \left(\frac{1}{z}\right)\right)}\right)}^{2}\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{+73}:\\ \;\;\;\;2 \cdot \left|\sqrt{\mathsf{fma}\left(z, y + x, y \cdot x\right)}\right|\\ \mathbf{else}:\\ \;\;\;\;2 \cdot {\left(e^{0.25 \cdot \left(\log \left(z + x\right) - \log \left(\frac{1}{y}\right)\right)}\right)}^{2}\\ \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
          (pow (exp (* 0.25 (- (log (- (- z) y)) (log (/ -1.0 x))))) 2.0))))
   (if (<= y -1.9e+102)
     t_0
     (if (<= y -2.2e-194)
       (* 2.0 (fabs (sqrt (fma x y (pow (cbrt (* z (+ y x))) 3.0)))))
       (if (<= y 4.4e-297)
         t_0
         (if (<= y 1.6e-173)
           (* 2.0 (pow (exp (* 0.25 (- (log (+ y x)) (log (/ 1.0 z))))) 2.0))
           (if (<= y 5.5e+73)
             (* 2.0 (fabs (sqrt (fma z (+ y x) (* y x)))))
             (*
              2.0
              (pow
               (exp (* 0.25 (- (log (+ z x)) (log (/ 1.0 y)))))
               2.0)))))))))
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 * pow(exp((0.25 * (log((-z - y)) - log((-1.0 / x))))), 2.0);
	double tmp;
	if (y <= -1.9e+102) {
		tmp = t_0;
	} else if (y <= -2.2e-194) {
		tmp = 2.0 * fabs(sqrt(fma(x, y, pow(cbrt((z * (y + x))), 3.0))));
	} else if (y <= 4.4e-297) {
		tmp = t_0;
	} else if (y <= 1.6e-173) {
		tmp = 2.0 * pow(exp((0.25 * (log((y + x)) - log((1.0 / z))))), 2.0);
	} else if (y <= 5.5e+73) {
		tmp = 2.0 * fabs(sqrt(fma(z, (y + x), (y * x))));
	} else {
		tmp = 2.0 * pow(exp((0.25 * (log((z + x)) - log((1.0 / y))))), 2.0);
	}
	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(0.25 * Float64(log(Float64(Float64(-z) - y)) - log(Float64(-1.0 / x))))) ^ 2.0))
	tmp = 0.0
	if (y <= -1.9e+102)
		tmp = t_0;
	elseif (y <= -2.2e-194)
		tmp = Float64(2.0 * abs(sqrt(fma(x, y, (cbrt(Float64(z * Float64(y + x))) ^ 3.0)))));
	elseif (y <= 4.4e-297)
		tmp = t_0;
	elseif (y <= 1.6e-173)
		tmp = Float64(2.0 * (exp(Float64(0.25 * Float64(log(Float64(y + x)) - log(Float64(1.0 / z))))) ^ 2.0));
	elseif (y <= 5.5e+73)
		tmp = Float64(2.0 * abs(sqrt(fma(z, Float64(y + x), Float64(y * x)))));
	else
		tmp = Float64(2.0 * (exp(Float64(0.25 * Float64(log(Float64(z + x)) - log(Float64(1.0 / y))))) ^ 2.0));
	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[Power[N[Exp[N[(0.25 * N[(N[Log[N[((-z) - y), $MachinePrecision]], $MachinePrecision] - N[Log[N[(-1.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.9e+102], t$95$0, If[LessEqual[y, -2.2e-194], N[(2.0 * N[Abs[N[Sqrt[N[(x * y + N[Power[N[Power[N[(z * N[(y + x), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4.4e-297], t$95$0, If[LessEqual[y, 1.6e-173], N[(2.0 * N[Power[N[Exp[N[(0.25 * N[(N[Log[N[(y + x), $MachinePrecision]], $MachinePrecision] - N[Log[N[(1.0 / z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 5.5e+73], N[(2.0 * N[Abs[N[Sqrt[N[(z * N[(y + x), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(2.0 * N[Power[N[Exp[N[(0.25 * N[(N[Log[N[(z + x), $MachinePrecision]], $MachinePrecision] - N[Log[N[(1.0 / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]]]]]]
2 \cdot \sqrt{\left(x \cdot y + x \cdot z\right) + y \cdot z}
\begin{array}{l}
t_0 := 2 \cdot {\left(e^{0.25 \cdot \left(\log \left(\left(-z\right) - y\right) - \log \left(\frac{-1}{x}\right)\right)}\right)}^{2}\\
\mathbf{if}\;y \leq -1.9 \cdot 10^{+102}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq -2.2 \cdot 10^{-194}:\\
\;\;\;\;2 \cdot \left|\sqrt{\mathsf{fma}\left(x, y, {\left(\sqrt[3]{z \cdot \left(y + x\right)}\right)}^{3}\right)}\right|\\

\mathbf{elif}\;y \leq 4.4 \cdot 10^{-297}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq 1.6 \cdot 10^{-173}:\\
\;\;\;\;2 \cdot {\left(e^{0.25 \cdot \left(\log \left(y + x\right) - \log \left(\frac{1}{z}\right)\right)}\right)}^{2}\\

\mathbf{elif}\;y \leq 5.5 \cdot 10^{+73}:\\
\;\;\;\;2 \cdot \left|\sqrt{\mathsf{fma}\left(z, y + x, y \cdot x\right)}\right|\\

\mathbf{else}:\\
\;\;\;\;2 \cdot {\left(e^{0.25 \cdot \left(\log \left(z + x\right) - \log \left(\frac{1}{y}\right)\right)}\right)}^{2}\\


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original19.8
Target11.7
Herbie5.4
\[\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 5 regimes
  2. if y < -1.89999999999999989e102 or -2.2000000000000001e-194 < y < 4.3999999999999997e-297

    1. Initial program 46.9

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

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

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

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

    if -1.89999999999999989e102 < y < -2.2000000000000001e-194

    1. Initial program 5.6

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

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

      \[\leadsto 2 \cdot \color{blue}{{\left({\left(\mathsf{fma}\left(x, y, z \cdot \left(x + y\right)\right)\right)}^{0.25}\right)}^{2}} \]
    4. Applied egg-rr5.6

      \[\leadsto 2 \cdot \color{blue}{\left|\sqrt{\mathsf{fma}\left(x, y, z \cdot \left(x + y\right)\right)}\right|} \]
    5. Applied egg-rr5.6

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

    if 4.3999999999999997e-297 < y < 1.6e-173

    1. Initial program 12.0

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

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

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

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

    if 1.6e-173 < y < 5.5000000000000003e73

    1. Initial program 2.9

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

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

      \[\leadsto 2 \cdot \color{blue}{{\left({\left(\mathsf{fma}\left(x, y, z \cdot \left(x + y\right)\right)\right)}^{0.25}\right)}^{2}} \]
    4. Applied egg-rr2.9

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

      \[\leadsto 2 \cdot \left|\sqrt{\color{blue}{\left(y + z\right) \cdot x + y \cdot z}}\right| \]
    6. Simplified2.9

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

    if 5.5000000000000003e73 < y

    1. Initial program 51.6

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

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

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

      \[\leadsto 2 \cdot {\color{blue}{\left(e^{0.25 \cdot \left(-1 \cdot \log \left(\frac{1}{y}\right) + \log \left(z + x\right)\right)}\right)}}^{2} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification5.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.9 \cdot 10^{+102}:\\ \;\;\;\;2 \cdot {\left(e^{0.25 \cdot \left(\log \left(\left(-z\right) - y\right) - \log \left(\frac{-1}{x}\right)\right)}\right)}^{2}\\ \mathbf{elif}\;y \leq -2.2 \cdot 10^{-194}:\\ \;\;\;\;2 \cdot \left|\sqrt{\mathsf{fma}\left(x, y, {\left(\sqrt[3]{z \cdot \left(y + x\right)}\right)}^{3}\right)}\right|\\ \mathbf{elif}\;y \leq 4.4 \cdot 10^{-297}:\\ \;\;\;\;2 \cdot {\left(e^{0.25 \cdot \left(\log \left(\left(-z\right) - y\right) - \log \left(\frac{-1}{x}\right)\right)}\right)}^{2}\\ \mathbf{elif}\;y \leq 1.6 \cdot 10^{-173}:\\ \;\;\;\;2 \cdot {\left(e^{0.25 \cdot \left(\log \left(y + x\right) - \log \left(\frac{1}{z}\right)\right)}\right)}^{2}\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{+73}:\\ \;\;\;\;2 \cdot \left|\sqrt{\mathsf{fma}\left(z, y + x, y \cdot x\right)}\right|\\ \mathbf{else}:\\ \;\;\;\;2 \cdot {\left(e^{0.25 \cdot \left(\log \left(z + x\right) - \log \left(\frac{1}{y}\right)\right)}\right)}^{2}\\ \end{array} \]

Reproduce

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