Average Error: 21.0 → 15.4
Time: 22.5s
Precision: binary64
Cost: 61000
\[ \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 := \mathsf{fma}\left(t \cdot 0.3333333333333333, -z, y\right)\\ t_2 := \frac{a}{b \cdot 3}\\ t_3 := \mathsf{fma}\left(-z, t \cdot 0.3333333333333333, z \cdot \left(t \cdot 0.3333333333333333\right)\right)\\ t_4 := 2 \cdot \sqrt{x}\\ \mathbf{if}\;z \cdot t \leq -5 \cdot 10^{+234}:\\ \;\;\;\;t_4 \cdot \mathsf{expm1}\left(\mathsf{fma}\left(t \cdot t, z \cdot \left(z \cdot -0.027777777777777776\right), \log 2\right)\right) - t_2\\ \mathbf{elif}\;z \cdot t \leq 10^{+234}:\\ \;\;\;\;t_4 \cdot \left(\cos t_1 \cdot \cos t_3 - \sin t_1 \cdot \sin t_3\right) - t_2\\ \mathbf{else}:\\ \;\;\;\;t_4 - t_2\\ \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 (fma (* t 0.3333333333333333) (- z) y))
        (t_2 (/ a (* b 3.0)))
        (t_3
         (fma (- z) (* t 0.3333333333333333) (* z (* t 0.3333333333333333))))
        (t_4 (* 2.0 (sqrt x))))
   (if (<= (* z t) -5e+234)
     (-
      (* t_4 (expm1 (fma (* t t) (* z (* z -0.027777777777777776)) (log 2.0))))
      t_2)
     (if (<= (* z t) 1e+234)
       (- (* t_4 (- (* (cos t_1) (cos t_3)) (* (sin t_1) (sin t_3)))) t_2)
       (- t_4 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 = fma((t * 0.3333333333333333), -z, y);
	double t_2 = a / (b * 3.0);
	double t_3 = fma(-z, (t * 0.3333333333333333), (z * (t * 0.3333333333333333)));
	double t_4 = 2.0 * sqrt(x);
	double tmp;
	if ((z * t) <= -5e+234) {
		tmp = (t_4 * expm1(fma((t * t), (z * (z * -0.027777777777777776)), log(2.0)))) - t_2;
	} else if ((z * t) <= 1e+234) {
		tmp = (t_4 * ((cos(t_1) * cos(t_3)) - (sin(t_1) * sin(t_3)))) - t_2;
	} else {
		tmp = t_4 - 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 = fma(Float64(t * 0.3333333333333333), Float64(-z), y)
	t_2 = Float64(a / Float64(b * 3.0))
	t_3 = fma(Float64(-z), Float64(t * 0.3333333333333333), Float64(z * Float64(t * 0.3333333333333333)))
	t_4 = Float64(2.0 * sqrt(x))
	tmp = 0.0
	if (Float64(z * t) <= -5e+234)
		tmp = Float64(Float64(t_4 * expm1(fma(Float64(t * t), Float64(z * Float64(z * -0.027777777777777776)), log(2.0)))) - t_2);
	elseif (Float64(z * t) <= 1e+234)
		tmp = Float64(Float64(t_4 * Float64(Float64(cos(t_1) * cos(t_3)) - Float64(sin(t_1) * sin(t_3)))) - t_2);
	else
		tmp = Float64(t_4 - 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[(N[(t * 0.3333333333333333), $MachinePrecision] * (-z) + y), $MachinePrecision]}, Block[{t$95$2 = N[(a / N[(b * 3.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[((-z) * N[(t * 0.3333333333333333), $MachinePrecision] + N[(z * N[(t * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(2.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z * t), $MachinePrecision], -5e+234], N[(N[(t$95$4 * N[(Exp[N[(N[(t * t), $MachinePrecision] * N[(z * N[(z * -0.027777777777777776), $MachinePrecision]), $MachinePrecision] + N[Log[2.0], $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision] - t$95$2), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 1e+234], N[(N[(t$95$4 * N[(N[(N[Cos[t$95$1], $MachinePrecision] * N[Cos[t$95$3], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[t$95$1], $MachinePrecision] * N[Sin[t$95$3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t$95$2), $MachinePrecision], N[(t$95$4 - 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 := \mathsf{fma}\left(t \cdot 0.3333333333333333, -z, y\right)\\
t_2 := \frac{a}{b \cdot 3}\\
t_3 := \mathsf{fma}\left(-z, t \cdot 0.3333333333333333, z \cdot \left(t \cdot 0.3333333333333333\right)\right)\\
t_4 := 2 \cdot \sqrt{x}\\
\mathbf{if}\;z \cdot t \leq -5 \cdot 10^{+234}:\\
\;\;\;\;t_4 \cdot \mathsf{expm1}\left(\mathsf{fma}\left(t \cdot t, z \cdot \left(z \cdot -0.027777777777777776\right), \log 2\right)\right) - t_2\\

\mathbf{elif}\;z \cdot t \leq 10^{+234}:\\
\;\;\;\;t_4 \cdot \left(\cos t_1 \cdot \cos t_3 - \sin t_1 \cdot \sin t_3\right) - t_2\\

\mathbf{else}:\\
\;\;\;\;t_4 - t_2\\


\end{array}

Error

Target

Original21.0
Target19.1
Herbie15.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) < -5.0000000000000003e234

    1. Initial program 53.2

      \[\left(2 \cdot \sqrt{x}\right) \cdot \cos \left(y - \frac{z \cdot t}{3}\right) - \frac{a}{b \cdot 3} \]
    2. Taylor expanded in y around 0 53.2

      \[\leadsto \left(2 \cdot \sqrt{x}\right) \cdot \color{blue}{\cos \left(-0.3333333333333333 \cdot \left(t \cdot z\right)\right)} - \frac{a}{b \cdot 3} \]
    3. Simplified53.0

      \[\leadsto \left(2 \cdot \sqrt{x}\right) \cdot \color{blue}{\cos \left(t \cdot \left(0.3333333333333333 \cdot z\right)\right)} - \frac{a}{b \cdot 3} \]
    4. Applied egg-rr53.2

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

      \[\leadsto \left(2 \cdot \sqrt{x}\right) \cdot \mathsf{expm1}\left(\color{blue}{-0.027777777777777776 \cdot \left({t}^{2} \cdot {z}^{2}\right) + \log 2}\right) - \frac{a}{b \cdot 3} \]
    6. Simplified34.2

      \[\leadsto \left(2 \cdot \sqrt{x}\right) \cdot \mathsf{expm1}\left(\color{blue}{\mathsf{fma}\left(t \cdot t, z \cdot \left(z \cdot -0.027777777777777776\right), \log 2\right)}\right) - \frac{a}{b \cdot 3} \]

    if -5.0000000000000003e234 < (*.f64 z t) < 1.00000000000000002e234

    1. Initial program 13.0

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

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

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

    if 1.00000000000000002e234 < (*.f64 z t)

    1. Initial program 54.0

      \[\left(2 \cdot \sqrt{x}\right) \cdot \cos \left(y - \frac{z \cdot t}{3}\right) - \frac{a}{b \cdot 3} \]
    2. Taylor expanded in z around 0 34.4

      \[\leadsto \color{blue}{2 \cdot \left(\cos y \cdot \sqrt{x}\right)} - \frac{a}{b \cdot 3} \]
    3. Simplified34.4

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

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

      \[\leadsto \sqrt{x} \cdot \left(2 \cdot \sqrt[3]{\color{blue}{\cos y \cdot {\cos y}^{2}}}\right) - \frac{a}{b \cdot 3} \]
    6. Taylor expanded in y around 0 34.1

      \[\leadsto \color{blue}{2 \cdot \sqrt{x}} - \frac{a}{b \cdot 3} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification15.4

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

Alternatives

Alternative 1
Error17.5
Cost13504
\[\sqrt{x} \cdot \left(2 \cdot \cos y\right) + a \cdot \frac{-0.3333333333333333}{b} \]
Alternative 2
Error17.5
Cost13504
\[\sqrt{x} \cdot \left(2 \cdot \cos y\right) - \frac{a}{b \cdot 3} \]
Alternative 3
Error25.4
Cost6976
\[2 \cdot \sqrt{x} - \frac{a}{b \cdot 3} \]
Alternative 4
Error36.4
Cost320
\[a \cdot \frac{-0.3333333333333333}{b} \]
Alternative 5
Error36.4
Cost320
\[\frac{a \cdot -0.3333333333333333}{b} \]

Error

Reproduce

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