Average Error: 20.5 → 17.0
Time: 19.7s
Precision: binary64
Cost: 60488
\[ \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 := \frac{a}{b \cdot 3}\\ t_2 := \mathsf{fma}\left(z \cdot -0.3333333333333333, t, z \cdot \left(t \cdot 0.3333333333333333\right)\right)\\ t_3 := 2 \cdot \sqrt{x}\\ t_4 := \mathsf{fma}\left(t, z \cdot -0.3333333333333333, y\right)\\ \mathbf{if}\;t \leq 2.5078771355750503 \cdot 10^{-196}:\\ \;\;\;\;t_3 \cdot \cos y - t_1\\ \mathbf{elif}\;t \leq 2.0893490202273234 \cdot 10^{+165}:\\ \;\;\;\;t_3 \cdot \left(\cos t_4 \cdot \cos t_2 - \sin t_4 \cdot \sin t_2\right) - t_1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{{\cos y}^{2} \cdot \left(x \cdot 4\right)} - t_1\\ \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 (/ a (* b 3.0)))
        (t_2 (fma (* z -0.3333333333333333) t (* z (* t 0.3333333333333333))))
        (t_3 (* 2.0 (sqrt x)))
        (t_4 (fma t (* z -0.3333333333333333) y)))
   (if (<= t 2.5078771355750503e-196)
     (- (* t_3 (cos y)) t_1)
     (if (<= t 2.0893490202273234e+165)
       (- (* t_3 (- (* (cos t_4) (cos t_2)) (* (sin t_4) (sin t_2)))) t_1)
       (- (sqrt (* (pow (cos y) 2.0) (* x 4.0))) t_1)))))
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 = a / (b * 3.0);
	double t_2 = fma((z * -0.3333333333333333), t, (z * (t * 0.3333333333333333)));
	double t_3 = 2.0 * sqrt(x);
	double t_4 = fma(t, (z * -0.3333333333333333), y);
	double tmp;
	if (t <= 2.5078771355750503e-196) {
		tmp = (t_3 * cos(y)) - t_1;
	} else if (t <= 2.0893490202273234e+165) {
		tmp = (t_3 * ((cos(t_4) * cos(t_2)) - (sin(t_4) * sin(t_2)))) - t_1;
	} else {
		tmp = sqrt((pow(cos(y), 2.0) * (x * 4.0))) - t_1;
	}
	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(a / Float64(b * 3.0))
	t_2 = fma(Float64(z * -0.3333333333333333), t, Float64(z * Float64(t * 0.3333333333333333)))
	t_3 = Float64(2.0 * sqrt(x))
	t_4 = fma(t, Float64(z * -0.3333333333333333), y)
	tmp = 0.0
	if (t <= 2.5078771355750503e-196)
		tmp = Float64(Float64(t_3 * cos(y)) - t_1);
	elseif (t <= 2.0893490202273234e+165)
		tmp = Float64(Float64(t_3 * Float64(Float64(cos(t_4) * cos(t_2)) - Float64(sin(t_4) * sin(t_2)))) - t_1);
	else
		tmp = Float64(sqrt(Float64((cos(y) ^ 2.0) * Float64(x * 4.0))) - t_1);
	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[(a / N[(b * 3.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(z * -0.3333333333333333), $MachinePrecision] * t + N[(z * N[(t * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(2.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(t * N[(z * -0.3333333333333333), $MachinePrecision] + y), $MachinePrecision]}, If[LessEqual[t, 2.5078771355750503e-196], N[(N[(t$95$3 * N[Cos[y], $MachinePrecision]), $MachinePrecision] - t$95$1), $MachinePrecision], If[LessEqual[t, 2.0893490202273234e+165], N[(N[(t$95$3 * N[(N[(N[Cos[t$95$4], $MachinePrecision] * N[Cos[t$95$2], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[t$95$4], $MachinePrecision] * N[Sin[t$95$2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t$95$1), $MachinePrecision], N[(N[Sqrt[N[(N[Power[N[Cos[y], $MachinePrecision], 2.0], $MachinePrecision] * N[(x * 4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - t$95$1), $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 := \frac{a}{b \cdot 3}\\
t_2 := \mathsf{fma}\left(z \cdot -0.3333333333333333, t, z \cdot \left(t \cdot 0.3333333333333333\right)\right)\\
t_3 := 2 \cdot \sqrt{x}\\
t_4 := \mathsf{fma}\left(t, z \cdot -0.3333333333333333, y\right)\\
\mathbf{if}\;t \leq 2.5078771355750503 \cdot 10^{-196}:\\
\;\;\;\;t_3 \cdot \cos y - t_1\\

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

\mathbf{else}:\\
\;\;\;\;\sqrt{{\cos y}^{2} \cdot \left(x \cdot 4\right)} - t_1\\


\end{array}

Error

Target

Original20.5
Target18.3
Herbie17.0
\[\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 t < 2.5078771355750503e-196

    1. Initial program 15.6

      \[\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 13.2

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

    if 2.5078771355750503e-196 < t < 2.08934902022732337e165

    1. Initial program 14.6

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

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

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

    if 2.08934902022732337e165 < t

    1. Initial program 39.6

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

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

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

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

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

Alternatives

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

Error

Reproduce

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