Average Error: 20.8 → 16.4
Time: 10.7s
Precision: binary64
\[ \begin{array}{c}[z, t] = \mathsf{sort}([z, t])\\ \end{array} \]
\[\left(2 \cdot \sqrt{x}\right) \cdot \cos \left(y - \frac{z \cdot t}{3}\right) - \frac{a}{b \cdot 3} \]
\[\begin{array}{l} t_1 := z \cdot \left(t \cdot -0.3333333333333333\right)\\ t_2 := \frac{a}{b \cdot -3}\\ \mathbf{if}\;z \cdot t \leq -1.286527903633024 \cdot 10^{+267}:\\ \;\;\;\;\mathsf{fma}\left(2, \sqrt{x} \cdot {\left(\sqrt[3]{\cos y}\right)}^{3}, t_2\right)\\ \mathbf{elif}\;z \cdot t \leq 1.4496128962660704 \cdot 10^{+174}:\\ \;\;\;\;\mathsf{fma}\left(2, \sqrt{x} \cdot \left(\cos y \cdot \cos t_1 - \sin t_1 \cdot \sin y\right), a \cdot \frac{-0.3333333333333333}{b}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, \sqrt{x} \cdot \mathsf{log1p}\left(\sqrt[3]{{\left(\mathsf{expm1}\left(\cos y\right)\right)}^{3}}\right), t_2\right)\\ \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (- (* (* 2.0 (sqrt x)) (cos (- y (/ (* z t) 3.0)))) (/ a (* b 3.0))))
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (* z (* t -0.3333333333333333))) (t_2 (/ a (* b -3.0))))
   (if (<= (* z t) -1.286527903633024e+267)
     (fma 2.0 (* (sqrt x) (pow (cbrt (cos y)) 3.0)) t_2)
     (if (<= (* z t) 1.4496128962660704e+174)
       (fma
        2.0
        (* (sqrt x) (- (* (cos y) (cos t_1)) (* (sin t_1) (sin y))))
        (* a (/ -0.3333333333333333 b)))
       (fma 2.0 (* (sqrt x) (log1p (cbrt (pow (expm1 (cos y)) 3.0)))) t_2)))))
double code(double x, double y, double z, double t, double a, double b) {
	return ((2.0 * sqrt(x)) * cos((y - ((z * t) / 3.0)))) - (a / (b * 3.0));
}
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = z * (t * -0.3333333333333333);
	double t_2 = a / (b * -3.0);
	double tmp;
	if ((z * t) <= -1.286527903633024e+267) {
		tmp = fma(2.0, (sqrt(x) * pow(cbrt(cos(y)), 3.0)), t_2);
	} else if ((z * t) <= 1.4496128962660704e+174) {
		tmp = fma(2.0, (sqrt(x) * ((cos(y) * cos(t_1)) - (sin(t_1) * sin(y)))), (a * (-0.3333333333333333 / b)));
	} else {
		tmp = fma(2.0, (sqrt(x) * log1p(cbrt(pow(expm1(cos(y)), 3.0)))), t_2);
	}
	return tmp;
}
function code(x, y, z, t, a, b)
	return Float64(Float64(Float64(2.0 * sqrt(x)) * cos(Float64(y - Float64(Float64(z * t) / 3.0)))) - Float64(a / Float64(b * 3.0)))
end
function code(x, y, z, t, a, b)
	t_1 = Float64(z * Float64(t * -0.3333333333333333))
	t_2 = Float64(a / Float64(b * -3.0))
	tmp = 0.0
	if (Float64(z * t) <= -1.286527903633024e+267)
		tmp = fma(2.0, Float64(sqrt(x) * (cbrt(cos(y)) ^ 3.0)), t_2);
	elseif (Float64(z * t) <= 1.4496128962660704e+174)
		tmp = fma(2.0, Float64(sqrt(x) * Float64(Float64(cos(y) * cos(t_1)) - Float64(sin(t_1) * sin(y)))), Float64(a * Float64(-0.3333333333333333 / b)));
	else
		tmp = fma(2.0, Float64(sqrt(x) * log1p(cbrt((expm1(cos(y)) ^ 3.0)))), t_2);
	end
	return tmp
end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(2.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(y - N[(N[(z * t), $MachinePrecision] / 3.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(a / N[(b * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(z * N[(t * -0.3333333333333333), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(a / N[(b * -3.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z * t), $MachinePrecision], -1.286527903633024e+267], N[(2.0 * N[(N[Sqrt[x], $MachinePrecision] * N[Power[N[Power[N[Cos[y], $MachinePrecision], 1/3], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 1.4496128962660704e+174], N[(2.0 * N[(N[Sqrt[x], $MachinePrecision] * N[(N[(N[Cos[y], $MachinePrecision] * N[Cos[t$95$1], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[t$95$1], $MachinePrecision] * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(a * N[(-0.3333333333333333 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 * N[(N[Sqrt[x], $MachinePrecision] * N[Log[1 + N[Power[N[Power[N[(Exp[N[Cos[y], $MachinePrecision]] - 1), $MachinePrecision], 3.0], $MachinePrecision], 1/3], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision]]]]]
\left(2 \cdot \sqrt{x}\right) \cdot \cos \left(y - \frac{z \cdot t}{3}\right) - \frac{a}{b \cdot 3}
\begin{array}{l}
t_1 := z \cdot \left(t \cdot -0.3333333333333333\right)\\
t_2 := \frac{a}{b \cdot -3}\\
\mathbf{if}\;z \cdot t \leq -1.286527903633024 \cdot 10^{+267}:\\
\;\;\;\;\mathsf{fma}\left(2, \sqrt{x} \cdot {\left(\sqrt[3]{\cos y}\right)}^{3}, t_2\right)\\

\mathbf{elif}\;z \cdot t \leq 1.4496128962660704 \cdot 10^{+174}:\\
\;\;\;\;\mathsf{fma}\left(2, \sqrt{x} \cdot \left(\cos y \cdot \cos t_1 - \sin t_1 \cdot \sin y\right), a \cdot \frac{-0.3333333333333333}{b}\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, \sqrt{x} \cdot \mathsf{log1p}\left(\sqrt[3]{{\left(\mathsf{expm1}\left(\cos y\right)\right)}^{3}}\right), t_2\right)\\


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Bits error versus b

Target

Original20.8
Target19.0
Herbie16.4
\[\begin{array}{l} \mathbf{if}\;z < -1.3793337487235141 \cdot 10^{+129}:\\ \;\;\;\;\left(2 \cdot \sqrt{x}\right) \cdot \cos \left(\frac{1}{y} - \frac{\frac{0.3333333333333333}{z}}{t}\right) - \frac{\frac{a}{3}}{b}\\ \mathbf{elif}\;z < 3.516290613555987 \cdot 10^{+106}:\\ \;\;\;\;\left(\sqrt{x} \cdot 2\right) \cdot \cos \left(y - \frac{t}{3} \cdot z\right) - \frac{\frac{a}{3}}{b}\\ \mathbf{else}:\\ \;\;\;\;\cos \left(y - \frac{\frac{0.3333333333333333}{z}}{t}\right) \cdot \left(2 \cdot \sqrt{x}\right) - \frac{\frac{a}{b}}{3}\\ \end{array} \]

Derivation

  1. Split input into 3 regimes
  2. if (*.f64 z t) < -1.286527903633024e267

    1. Initial program 58.0

      \[\left(2 \cdot \sqrt{x}\right) \cdot \cos \left(y - \frac{z \cdot t}{3}\right) - \frac{a}{b \cdot 3} \]
    2. Simplified57.7

      \[\leadsto \color{blue}{\mathsf{fma}\left(2, \sqrt{x} \cdot \cos \left(\mathsf{fma}\left(z, t \cdot -0.3333333333333333, y\right)\right), a \cdot \frac{-0.3333333333333333}{b}\right)} \]
    3. Taylor expanded in z around 0 34.6

      \[\leadsto \mathsf{fma}\left(2, \sqrt{x} \cdot \color{blue}{\cos y}, a \cdot \frac{-0.3333333333333333}{b}\right) \]
    4. Applied egg-rr34.6

      \[\leadsto \mathsf{fma}\left(2, \sqrt{x} \cdot \cos y, \color{blue}{\frac{a}{b \cdot -3}}\right) \]
    5. Applied egg-rr34.6

      \[\leadsto \mathsf{fma}\left(2, \sqrt{x} \cdot \color{blue}{{\left(\sqrt[3]{\cos y}\right)}^{3}}, \frac{a}{b \cdot -3}\right) \]

    if -1.286527903633024e267 < (*.f64 z t) < 1.44961289626607041e174

    1. Initial program 12.7

      \[\left(2 \cdot \sqrt{x}\right) \cdot \cos \left(y - \frac{z \cdot t}{3}\right) - \frac{a}{b \cdot 3} \]
    2. Simplified12.8

      \[\leadsto \color{blue}{\mathsf{fma}\left(2, \sqrt{x} \cdot \cos \left(\mathsf{fma}\left(z, t \cdot -0.3333333333333333, y\right)\right), a \cdot \frac{-0.3333333333333333}{b}\right)} \]
    3. Applied egg-rr12.1

      \[\leadsto \mathsf{fma}\left(2, \sqrt{x} \cdot \color{blue}{\left(\cos \left(z \cdot \left(t \cdot -0.3333333333333333\right)\right) \cdot \cos y - \sin \left(z \cdot \left(t \cdot -0.3333333333333333\right)\right) \cdot \sin y\right)}, a \cdot \frac{-0.3333333333333333}{b}\right) \]

    if 1.44961289626607041e174 < (*.f64 z t)

    1. Initial program 49.1

      \[\left(2 \cdot \sqrt{x}\right) \cdot \cos \left(y - \frac{z \cdot t}{3}\right) - \frac{a}{b \cdot 3} \]
    2. Simplified49.2

      \[\leadsto \color{blue}{\mathsf{fma}\left(2, \sqrt{x} \cdot \cos \left(\mathsf{fma}\left(z, t \cdot -0.3333333333333333, y\right)\right), a \cdot \frac{-0.3333333333333333}{b}\right)} \]
    3. Taylor expanded in z around 0 32.2

      \[\leadsto \mathsf{fma}\left(2, \sqrt{x} \cdot \color{blue}{\cos y}, a \cdot \frac{-0.3333333333333333}{b}\right) \]
    4. Applied egg-rr32.2

      \[\leadsto \mathsf{fma}\left(2, \sqrt{x} \cdot \cos y, \color{blue}{\frac{a}{b \cdot -3}}\right) \]
    5. Applied egg-rr32.2

      \[\leadsto \mathsf{fma}\left(2, \sqrt{x} \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\cos y\right)\right)}, \frac{a}{b \cdot -3}\right) \]
    6. Applied egg-rr32.2

      \[\leadsto \mathsf{fma}\left(2, \sqrt{x} \cdot \mathsf{log1p}\left(\color{blue}{\sqrt[3]{{\left(\mathsf{expm1}\left(\cos y\right)\right)}^{3}}}\right), \frac{a}{b \cdot -3}\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification16.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \cdot t \leq -1.286527903633024 \cdot 10^{+267}:\\ \;\;\;\;\mathsf{fma}\left(2, \sqrt{x} \cdot {\left(\sqrt[3]{\cos y}\right)}^{3}, \frac{a}{b \cdot -3}\right)\\ \mathbf{elif}\;z \cdot t \leq 1.4496128962660704 \cdot 10^{+174}:\\ \;\;\;\;\mathsf{fma}\left(2, \sqrt{x} \cdot \left(\cos y \cdot \cos \left(z \cdot \left(t \cdot -0.3333333333333333\right)\right) - \sin \left(z \cdot \left(t \cdot -0.3333333333333333\right)\right) \cdot \sin y\right), a \cdot \frac{-0.3333333333333333}{b}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, \sqrt{x} \cdot \mathsf{log1p}\left(\sqrt[3]{{\left(\mathsf{expm1}\left(\cos y\right)\right)}^{3}}\right), \frac{a}{b \cdot -3}\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022150 
(FPCore (x y z t a b)
  :name "Diagrams.Solve.Polynomial:cubForm  from diagrams-solve-0.1, K"
  :precision binary64

  :herbie-target
  (if (< z -1.3793337487235141e+129) (- (* (* 2.0 (sqrt x)) (cos (- (/ 1.0 y) (/ (/ 0.3333333333333333 z) t)))) (/ (/ a 3.0) b)) (if (< z 3.516290613555987e+106) (- (* (* (sqrt x) 2.0) (cos (- y (* (/ t 3.0) z)))) (/ (/ a 3.0) b)) (- (* (cos (- y (/ (/ 0.3333333333333333 z) t))) (* 2.0 (sqrt x))) (/ (/ a b) 3.0))))

  (- (* (* 2.0 (sqrt x)) (cos (- y (/ (* z t) 3.0)))) (/ a (* b 3.0))))