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

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

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


\end{array}

Error

Target

Original20.3
Target18.2
Herbie14.6
\[\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.00000000000000033e259

    1. Initial program 56.3

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

      \[\leadsto \color{blue}{2 \cdot \left(\sqrt{x} \cdot \cos \left(y - \frac{z \cdot t}{3}\right)\right) - \frac{\frac{a}{b}}{3}} \]
      Proof
      (-.f64 (*.f64 2 (*.f64 (sqrt.f64 x) (cos.f64 (-.f64 y (/.f64 (*.f64 z t) 3))))) (/.f64 (/.f64 a b) 3)): 0 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 2 (sqrt.f64 x)) (cos.f64 (-.f64 y (/.f64 (*.f64 z t) 3))))) (/.f64 (/.f64 a b) 3)): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 (*.f64 2 (sqrt.f64 x)) (cos.f64 (-.f64 y (/.f64 (*.f64 z t) 3)))) (Rewrite<= associate-/r*_binary64 (/.f64 a (*.f64 b 3)))): 19 points increase in error, 18 points decrease in error
    3. Taylor expanded in z around 0 32.6

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

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

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

    if -5.00000000000000033e259 < (*.f64 z t) < 1.00000000000000006e258

    1. Initial program 13.4

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

      \[\leadsto \color{blue}{2 \cdot \left(\sqrt{x} \cdot \cos \left(y - \frac{z}{3} \cdot t\right)\right) - \frac{a}{3 \cdot b}} \]
      Proof
      (-.f64 (*.f64 2 (*.f64 (sqrt.f64 x) (cos.f64 (-.f64 y (*.f64 (/.f64 z 3) t))))) (/.f64 a (*.f64 3 b))): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 2 (*.f64 (sqrt.f64 x) (cos.f64 (-.f64 y (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 z t) 3)))))) (/.f64 a (*.f64 3 b))): 8 points increase in error, 8 points decrease in error
      (-.f64 (*.f64 2 (Rewrite<= remove-double-neg_binary64 (neg.f64 (neg.f64 (*.f64 (sqrt.f64 x) (cos.f64 (-.f64 y (/.f64 (*.f64 z t) 3)))))))) (/.f64 a (*.f64 3 b))): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 2 (neg.f64 (neg.f64 (*.f64 (sqrt.f64 x) (cos.f64 (-.f64 y (/.f64 (*.f64 z t) 3))))))) (/.f64 a (Rewrite<= *-commutative_binary64 (*.f64 b 3)))): 0 points increase in error, 0 points decrease in error
      (Rewrite=> fma-neg_binary64 (fma.f64 2 (neg.f64 (neg.f64 (*.f64 (sqrt.f64 x) (cos.f64 (-.f64 y (/.f64 (*.f64 z t) 3)))))) (neg.f64 (/.f64 a (*.f64 b 3))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 2 (Rewrite=> remove-double-neg_binary64 (*.f64 (sqrt.f64 x) (cos.f64 (-.f64 y (/.f64 (*.f64 z t) 3))))) (neg.f64 (/.f64 a (*.f64 b 3)))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-neg_binary64 (-.f64 (*.f64 2 (*.f64 (sqrt.f64 x) (cos.f64 (-.f64 y (/.f64 (*.f64 z t) 3))))) (/.f64 a (*.f64 b 3)))): 0 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 2 (sqrt.f64 x)) (cos.f64 (-.f64 y (/.f64 (*.f64 z t) 3))))) (/.f64 a (*.f64 b 3))): 0 points increase in error, 0 points decrease in error
    3. Applied egg-rr13.5

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

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

    if 1.00000000000000006e258 < (*.f64 z t)

    1. Initial program 56.3

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

      \[\leadsto \color{blue}{2 \cdot \left(\sqrt{x} \cdot \cos \left(y - \frac{z}{3} \cdot t\right)\right) - \frac{a}{3 \cdot b}} \]
      Proof
      (-.f64 (*.f64 2 (*.f64 (sqrt.f64 x) (cos.f64 (-.f64 y (*.f64 (/.f64 z 3) t))))) (/.f64 a (*.f64 3 b))): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 2 (*.f64 (sqrt.f64 x) (cos.f64 (-.f64 y (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 z t) 3)))))) (/.f64 a (*.f64 3 b))): 8 points increase in error, 8 points decrease in error
      (-.f64 (*.f64 2 (Rewrite<= remove-double-neg_binary64 (neg.f64 (neg.f64 (*.f64 (sqrt.f64 x) (cos.f64 (-.f64 y (/.f64 (*.f64 z t) 3)))))))) (/.f64 a (*.f64 3 b))): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 2 (neg.f64 (neg.f64 (*.f64 (sqrt.f64 x) (cos.f64 (-.f64 y (/.f64 (*.f64 z t) 3))))))) (/.f64 a (Rewrite<= *-commutative_binary64 (*.f64 b 3)))): 0 points increase in error, 0 points decrease in error
      (Rewrite=> fma-neg_binary64 (fma.f64 2 (neg.f64 (neg.f64 (*.f64 (sqrt.f64 x) (cos.f64 (-.f64 y (/.f64 (*.f64 z t) 3)))))) (neg.f64 (/.f64 a (*.f64 b 3))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 2 (Rewrite=> remove-double-neg_binary64 (*.f64 (sqrt.f64 x) (cos.f64 (-.f64 y (/.f64 (*.f64 z t) 3))))) (neg.f64 (/.f64 a (*.f64 b 3)))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-neg_binary64 (-.f64 (*.f64 2 (*.f64 (sqrt.f64 x) (cos.f64 (-.f64 y (/.f64 (*.f64 z t) 3))))) (/.f64 a (*.f64 b 3)))): 0 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 2 (sqrt.f64 x)) (cos.f64 (-.f64 y (/.f64 (*.f64 z t) 3))))) (/.f64 a (*.f64 b 3))): 0 points increase in error, 0 points decrease in error
    3. Taylor expanded in z around 0 31.6

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

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

Alternatives

Alternative 1
Error14.8
Cost61256
\[\begin{array}{l} t_1 := \mathsf{fma}\left(t, z \cdot -0.3333333333333333, y\right)\\ t_2 := y - \frac{z \cdot t}{3}\\ t_3 := \frac{a}{3 \cdot b}\\ t_4 := \mathsf{fma}\left(z \cdot -0.3333333333333333, t, t \cdot \left(z \cdot 0.3333333333333333\right)\right)\\ \mathbf{if}\;t_2 \leq -5 \cdot 10^{+270}:\\ \;\;\;\;2 \cdot \left(\sqrt{x} \cdot {\left(\sqrt[3]{\cos y}\right)}^{3}\right) - t_3\\ \mathbf{elif}\;t_2 \leq 5 \cdot 10^{+222}:\\ \;\;\;\;2 \cdot \left(\sqrt{x} \cdot \left(\cos t_1 \cdot \cos t_4 - \sin t_1 \cdot \sin t_4\right)\right) - t_3\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(\sqrt{x} \cdot \cos y\right) - \frac{\frac{a}{b}}{3}\\ \end{array} \]
Alternative 2
Error15.2
Cost60872
\[\begin{array}{l} t_1 := \mathsf{fma}\left(-z, t \cdot 0.3333333333333333, y\right)\\ t_2 := \frac{\frac{a}{b}}{3}\\ t_3 := \mathsf{fma}\left(t \cdot -0.3333333333333333, z, \left(z \cdot t\right) \cdot 0.3333333333333333\right)\\ \mathbf{if}\;z \cdot t \leq -5 \cdot 10^{+259}:\\ \;\;\;\;2 \cdot {\left({x}^{0.16666666666666666}\right)}^{3} - t_2\\ \mathbf{elif}\;z \cdot t \leq 4 \cdot 10^{+299}:\\ \;\;\;\;2 \cdot \left(\sqrt{x} \cdot \left(\cos t_1 \cdot \cos t_3 - \sin t_1 \cdot \sin t_3\right)\right) - \frac{a}{3 \cdot b}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot {\left(\left(1 + \sqrt[3]{\sqrt{x} \cdot \cos y}\right) + -1\right)}^{3} - t_2\\ \end{array} \]
Alternative 3
Error16.7
Cost13504
\[2 \cdot \left(\sqrt{x} \cdot \cos y\right) - \frac{a}{3 \cdot b} \]
Alternative 4
Error16.7
Cost13504
\[2 \cdot \left(\sqrt{x} \cdot \cos y\right) - \frac{\frac{a}{b}}{3} \]
Alternative 5
Error24.1
Cost13384
\[\begin{array}{l} t_1 := 2 \cdot \sqrt{x}\\ \mathbf{if}\;a \leq -1.95 \cdot 10^{-250}:\\ \;\;\;\;t_1 - \frac{\frac{a}{b}}{3}\\ \mathbf{elif}\;a \leq 7.8 \cdot 10^{-251}:\\ \;\;\;\;\sqrt{x} \cdot \left(2 \cdot \cos y\right)\\ \mathbf{else}:\\ \;\;\;\;t_1 - \frac{a}{3 \cdot b}\\ \end{array} \]
Alternative 6
Error25.0
Cost6976
\[2 \cdot \sqrt{x} + \frac{a}{b} \cdot -0.3333333333333333 \]
Alternative 7
Error24.9
Cost6976
\[2 \cdot \sqrt{x} - \frac{a}{3 \cdot b} \]
Alternative 8
Error24.9
Cost6976
\[2 \cdot \sqrt{x} - \frac{\frac{a}{b}}{3} \]
Alternative 9
Error35.8
Cost320
\[\frac{a}{b} \cdot -0.3333333333333333 \]
Alternative 10
Error35.7
Cost320
\[\frac{-0.3333333333333333}{\frac{b}{a}} \]
Alternative 11
Error35.7
Cost320
\[\frac{a}{b \cdot -3} \]
Alternative 12
Error35.7
Cost320
\[\frac{\frac{a}{-3}}{b} \]

Error

Reproduce

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