Average Error: 20.4 → 16.4
Time: 26.5s
Precision: binary64
Cost: 46984
\[ \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 := 2 \cdot \sqrt{x}\\ \mathbf{if}\;z \cdot t \leq -2 \cdot 10^{+216}:\\ \;\;\;\;t_2 - t_1\\ \mathbf{elif}\;z \cdot t \leq 10^{+277}:\\ \;\;\;\;t_2 \cdot \left(\cos y \cdot \cos \left({\left(\sqrt[3]{z \cdot \left(t \cdot -0.3333333333333333\right)}\right)}^{3}\right) - \sin y \cdot \sin \left(\left(z \cdot t\right) \cdot -0.3333333333333333\right)\right) - t_1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\left(x \cdot 4\right) \cdot {\cos y}^{2}} - 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 (* 2.0 (sqrt x))))
   (if (<= (* z t) -2e+216)
     (- t_2 t_1)
     (if (<= (* z t) 1e+277)
       (-
        (*
         t_2
         (-
          (* (cos y) (cos (pow (cbrt (* z (* t -0.3333333333333333))) 3.0)))
          (* (sin y) (sin (* (* z t) -0.3333333333333333)))))
        t_1)
       (- (sqrt (* (* x 4.0) (pow (cos y) 2.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 = 2.0 * sqrt(x);
	double tmp;
	if ((z * t) <= -2e+216) {
		tmp = t_2 - t_1;
	} else if ((z * t) <= 1e+277) {
		tmp = (t_2 * ((cos(y) * cos(pow(cbrt((z * (t * -0.3333333333333333))), 3.0))) - (sin(y) * sin(((z * t) * -0.3333333333333333))))) - t_1;
	} else {
		tmp = sqrt(((x * 4.0) * pow(cos(y), 2.0))) - t_1;
	}
	return tmp;
}
public static double code(double x, double y, double z, double t, double a, double b) {
	return ((2.0 * Math.sqrt(x)) * Math.cos((y - ((z * t) / 3.0)))) - (a / (b * 3.0));
}
public static double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = a / (b * 3.0);
	double t_2 = 2.0 * Math.sqrt(x);
	double tmp;
	if ((z * t) <= -2e+216) {
		tmp = t_2 - t_1;
	} else if ((z * t) <= 1e+277) {
		tmp = (t_2 * ((Math.cos(y) * Math.cos(Math.pow(Math.cbrt((z * (t * -0.3333333333333333))), 3.0))) - (Math.sin(y) * Math.sin(((z * t) * -0.3333333333333333))))) - t_1;
	} else {
		tmp = Math.sqrt(((x * 4.0) * Math.pow(Math.cos(y), 2.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 = Float64(2.0 * sqrt(x))
	tmp = 0.0
	if (Float64(z * t) <= -2e+216)
		tmp = Float64(t_2 - t_1);
	elseif (Float64(z * t) <= 1e+277)
		tmp = Float64(Float64(t_2 * Float64(Float64(cos(y) * cos((cbrt(Float64(z * Float64(t * -0.3333333333333333))) ^ 3.0))) - Float64(sin(y) * sin(Float64(Float64(z * t) * -0.3333333333333333))))) - t_1);
	else
		tmp = Float64(sqrt(Float64(Float64(x * 4.0) * (cos(y) ^ 2.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[(2.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z * t), $MachinePrecision], -2e+216], N[(t$95$2 - t$95$1), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 1e+277], N[(N[(t$95$2 * N[(N[(N[Cos[y], $MachinePrecision] * N[Cos[N[Power[N[Power[N[(z * N[(t * -0.3333333333333333), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], 3.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * N[Sin[N[(N[(z * t), $MachinePrecision] * -0.3333333333333333), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t$95$1), $MachinePrecision], N[(N[Sqrt[N[(N[(x * 4.0), $MachinePrecision] * N[Power[N[Cos[y], $MachinePrecision], 2.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 := 2 \cdot \sqrt{x}\\
\mathbf{if}\;z \cdot t \leq -2 \cdot 10^{+216}:\\
\;\;\;\;t_2 - t_1\\

\mathbf{elif}\;z \cdot t \leq 10^{+277}:\\
\;\;\;\;t_2 \cdot \left(\cos y \cdot \cos \left({\left(\sqrt[3]{z \cdot \left(t \cdot -0.3333333333333333\right)}\right)}^{3}\right) - \sin y \cdot \sin \left(\left(z \cdot t\right) \cdot -0.3333333333333333\right)\right) - t_1\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original20.4
Target18.7
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) < -2e216

    1. Initial program 51.9

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

      \[\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. Simplified51.8

      \[\leadsto \left(2 \cdot \sqrt{x}\right) \cdot \color{blue}{\cos \left(z \cdot \left(0.3333333333333333 \cdot t\right)\right)} - \frac{a}{b \cdot 3} \]
      Proof
      (cos.f64 (*.f64 z (*.f64 1/3 t))): 0 points increase in error, 0 points decrease in error
      (cos.f64 (Rewrite<= *-commutative_binary64 (*.f64 (*.f64 1/3 t) z))): 0 points increase in error, 0 points decrease in error
      (cos.f64 (Rewrite<= associate-*r*_binary64 (*.f64 1/3 (*.f64 t z)))): 17 points increase in error, 19 points decrease in error
      (Rewrite<= cos-neg_binary64 (cos.f64 (neg.f64 (*.f64 1/3 (*.f64 t z))))): 0 points increase in error, 0 points decrease in error
    4. Taylor expanded in z around 0 34.2

      \[\leadsto \color{blue}{2 \cdot \sqrt{x}} - \frac{a}{b \cdot 3} \]

    if -2e216 < (*.f64 z t) < 1e277

    1. Initial program 13.1

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

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

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

    if 1e277 < (*.f64 z t)

    1. Initial program 58.4

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

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

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

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

Alternatives

Alternative 1
Error16.3
Cost34120
\[\begin{array}{l} t_1 := \frac{a}{b \cdot 3}\\ t_2 := 2 \cdot \sqrt{x}\\ t_3 := t_2 - t_1\\ \mathbf{if}\;z \cdot t \leq -2 \cdot 10^{+199}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \cdot t \leq 2 \cdot 10^{+168}:\\ \;\;\;\;t_2 \cdot \left(\cos y \cdot \cos \left(t \cdot \left(z \cdot -0.3333333333333333\right)\right) - \sin y \cdot \sin \left(\left(z \cdot t\right) \cdot -0.3333333333333333\right)\right) - t_1\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 2
Error20.2
Cost13896
\[\begin{array}{l} t_1 := \frac{a}{b \cdot 3}\\ t_2 := 2 \cdot \sqrt{x} - t_1\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{-90}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 4 \cdot 10^{-65}:\\ \;\;\;\;\sqrt{x} \cdot \left(2 \cdot \cos y\right)\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error17.2
Cost13504
\[\left(2 \cdot \sqrt{x}\right) \cdot \cos y + \frac{a \cdot -0.3333333333333333}{b} \]
Alternative 4
Error17.2
Cost13504
\[\left(2 \cdot \sqrt{x}\right) \cdot \cos y - \frac{a}{b \cdot 3} \]
Alternative 5
Error25.2
Cost6976
\[2 \cdot \sqrt{x} - \frac{a}{b \cdot 3} \]
Alternative 6
Error36.3
Cost320
\[\frac{a}{\frac{b}{-0.3333333333333333}} \]
Alternative 7
Error36.3
Cost320
\[\frac{a \cdot -0.3333333333333333}{b} \]
Alternative 8
Error36.4
Cost320
\[-0.3333333333333333 \cdot \frac{a}{b} \]

Error

Reproduce

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