?

Average Error: 20.1 → 15.7
Time: 28.9s
Precision: binary64
Cost: 40392

?

\[\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{t}{\frac{3}{z}}\\ t_2 := \frac{a}{b \cdot 3}\\ t_3 := 2 \cdot \sqrt{x}\\ \mathbf{if}\;z \cdot t \leq -1 \cdot 10^{+18}:\\ \;\;\;\;t_3 \cdot \cos y - t_2\\ \mathbf{elif}\;z \cdot t \leq 10^{+147}:\\ \;\;\;\;2 \cdot \left(\sqrt{x} \cdot \mathsf{fma}\left(\cos t_1, \cos y, \sin y \cdot \sin t_1\right)\right) - t_2\\ \mathbf{else}:\\ \;\;\;\;t_3 \cdot \mathsf{log1p}\left(\sqrt{{\left(\mathsf{expm1}\left(\cos y\right)\right)}^{2}}\right) - 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 (/ t (/ 3.0 z))) (t_2 (/ a (* b 3.0))) (t_3 (* 2.0 (sqrt x))))
   (if (<= (* z t) -1e+18)
     (- (* t_3 (cos y)) t_2)
     (if (<= (* z t) 1e+147)
       (-
        (* 2.0 (* (sqrt x) (fma (cos t_1) (cos y) (* (sin y) (sin t_1)))))
        t_2)
       (- (* t_3 (log1p (sqrt (pow (expm1 (cos y)) 2.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 = t / (3.0 / z);
	double t_2 = a / (b * 3.0);
	double t_3 = 2.0 * sqrt(x);
	double tmp;
	if ((z * t) <= -1e+18) {
		tmp = (t_3 * cos(y)) - t_2;
	} else if ((z * t) <= 1e+147) {
		tmp = (2.0 * (sqrt(x) * fma(cos(t_1), cos(y), (sin(y) * sin(t_1))))) - t_2;
	} else {
		tmp = (t_3 * log1p(sqrt(pow(expm1(cos(y)), 2.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(t / Float64(3.0 / z))
	t_2 = Float64(a / Float64(b * 3.0))
	t_3 = Float64(2.0 * sqrt(x))
	tmp = 0.0
	if (Float64(z * t) <= -1e+18)
		tmp = Float64(Float64(t_3 * cos(y)) - t_2);
	elseif (Float64(z * t) <= 1e+147)
		tmp = Float64(Float64(2.0 * Float64(sqrt(x) * fma(cos(t_1), cos(y), Float64(sin(y) * sin(t_1))))) - t_2);
	else
		tmp = Float64(Float64(t_3 * log1p(sqrt((expm1(cos(y)) ^ 2.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[(t / N[(3.0 / z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(a / N[(b * 3.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(2.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z * t), $MachinePrecision], -1e+18], N[(N[(t$95$3 * N[Cos[y], $MachinePrecision]), $MachinePrecision] - t$95$2), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 1e+147], N[(N[(2.0 * N[(N[Sqrt[x], $MachinePrecision] * N[(N[Cos[t$95$1], $MachinePrecision] * N[Cos[y], $MachinePrecision] + N[(N[Sin[y], $MachinePrecision] * N[Sin[t$95$1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t$95$2), $MachinePrecision], N[(N[(t$95$3 * N[Log[1 + N[Sqrt[N[Power[N[(Exp[N[Cos[y], $MachinePrecision]] - 1), $MachinePrecision], 2.0], $MachinePrecision]], $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 := \frac{t}{\frac{3}{z}}\\
t_2 := \frac{a}{b \cdot 3}\\
t_3 := 2 \cdot \sqrt{x}\\
\mathbf{if}\;z \cdot t \leq -1 \cdot 10^{+18}:\\
\;\;\;\;t_3 \cdot \cos y - t_2\\

\mathbf{elif}\;z \cdot t \leq 10^{+147}:\\
\;\;\;\;2 \cdot \left(\sqrt{x} \cdot \mathsf{fma}\left(\cos t_1, \cos y, \sin y \cdot \sin t_1\right)\right) - t_2\\

\mathbf{else}:\\
\;\;\;\;t_3 \cdot \mathsf{log1p}\left(\sqrt{{\left(\mathsf{expm1}\left(\cos y\right)\right)}^{2}}\right) - t_2\\


\end{array}

Error?

Target

Original20.1
Target18.0
Herbie15.7
\[\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) < -1e18

    1. Initial program 41.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 32.3

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

    if -1e18 < (*.f64 z t) < 9.9999999999999998e146

    1. Initial program 6.2

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

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

      [Start]6.2

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

      associate-*l* [=>]6.2

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

      associate-/l* [=>]6.2

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

      *-commutative [=>]6.2

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

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

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

      [Start]5.6

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

      *-commutative [=>]5.6

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

      cos-neg [<=]5.6

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

      distribute-lft-neg-in [=>]5.6

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

      *-commutative [=>]5.6

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

      associate-*l* [<=]5.6

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

      distribute-lft-neg-in [<=]5.6

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

      distribute-lft-neg-in [<=]5.6

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

      *-commutative [=>]5.6

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

      associate-*r* [<=]5.6

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

      fma-def [=>]5.6

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

    if 9.9999999999999998e146 < (*.f64 z t)

    1. Initial program 47.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 33.3

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

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

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

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

Alternatives

Alternative 1
Error15.7
Cost39688
\[\begin{array}{l} t_1 := \frac{-t}{\frac{3}{z}}\\ t_2 := \frac{a}{b \cdot 3}\\ t_3 := 2 \cdot \sqrt{x}\\ \mathbf{if}\;z \cdot t \leq -1 \cdot 10^{+18}:\\ \;\;\;\;t_3 \cdot \cos y - t_2\\ \mathbf{elif}\;z \cdot t \leq 10^{+147}:\\ \;\;\;\;t_3 \cdot \left(\cos y \cdot \cos t_1 - \sin y \cdot \sin t_1\right) - t_2\\ \mathbf{else}:\\ \;\;\;\;t_3 \cdot \mathsf{log1p}\left(\sqrt{{\left(\mathsf{expm1}\left(\cos y\right)\right)}^{2}}\right) - t_2\\ \end{array} \]
Alternative 2
Error16.1
Cost34312
\[\begin{array}{l} t_1 := 2 \cdot \sqrt{x}\\ t_2 := y - \frac{z \cdot t}{3}\\ t_3 := \frac{a}{b \cdot 3}\\ \mathbf{if}\;t_2 \leq -2 \cdot 10^{+304}:\\ \;\;\;\;t_1 \cdot \left|\cos y\right| - t_3\\ \mathbf{elif}\;t_2 \leq 2 \cdot 10^{+161}:\\ \;\;\;\;t_1 \cdot \cos \left(y - \frac{\sqrt[3]{z}}{\frac{\frac{3}{t}}{{\left(\sqrt[3]{z}\right)}^{2}}}\right) - t_3\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, \sqrt{x} \cdot \cos y, \frac{\frac{a}{-3}}{b}\right)\\ \end{array} \]
Alternative 3
Error15.6
Cost34248
\[\begin{array}{l} t_1 := \frac{-t}{\frac{3}{z}}\\ t_2 := \frac{a}{b \cdot 3}\\ t_3 := 2 \cdot \sqrt{x}\\ \mathbf{if}\;z \cdot t \leq -1 \cdot 10^{+18}:\\ \;\;\;\;t_3 \cdot \cos y - t_2\\ \mathbf{elif}\;z \cdot t \leq 10^{+147}:\\ \;\;\;\;t_3 \cdot \left(\cos y \cdot \cos t_1 - \sin y \cdot \sin t_1\right) - t_2\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, \sqrt{x}, \frac{\frac{a}{-3}}{b}\right)\\ \end{array} \]
Alternative 4
Error15.6
Cost34120
\[\begin{array}{l} t_1 := \frac{a}{b \cdot 3}\\ t_2 := 2 \cdot \sqrt{x}\\ \mathbf{if}\;z \cdot t \leq -1 \cdot 10^{+18}:\\ \;\;\;\;t_2 \cdot \cos y - t_1\\ \mathbf{elif}\;z \cdot t \leq 10^{+147}:\\ \;\;\;\;t_2 \cdot \left(\cos y \cdot \cos \left(t \cdot \frac{z}{3}\right) - \sin y \cdot \sin \left(t \cdot \left(z \cdot -0.3333333333333333\right)\right)\right) - t_1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, \sqrt{x}, \frac{\frac{a}{-3}}{b}\right)\\ \end{array} \]
Alternative 5
Error16.4
Cost19776
\[\mathsf{fma}\left(2, \sqrt{x} \cdot \cos y, \frac{\frac{a}{-3}}{b}\right) \]
Alternative 6
Error19.4
Cost14025
\[\begin{array}{l} t_1 := \frac{a}{b \cdot 3}\\ \mathbf{if}\;t_1 \leq -4 \cdot 10^{-96} \lor \neg \left(t_1 \leq 2 \cdot 10^{-120}\right):\\ \;\;\;\;\mathsf{fma}\left(2, \sqrt{x}, \frac{\frac{a}{-3}}{b}\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x} \cdot \left(2 \cdot \cos y\right)\\ \end{array} \]
Alternative 7
Error19.5
Cost13896
\[\begin{array}{l} t_1 := \frac{a}{b \cdot 3}\\ t_2 := 2 \cdot \sqrt{x}\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{-117}:\\ \;\;\;\;t_2 + \frac{\frac{a}{b}}{-3}\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{-120}:\\ \;\;\;\;\sqrt{x} \cdot \left(2 \cdot \cos y\right)\\ \mathbf{else}:\\ \;\;\;\;t_2 - t_1\\ \end{array} \]
Alternative 8
Error16.5
Cost13504
\[\frac{-0.3333333333333333}{\frac{b}{a}} + 2 \cdot \left(\sqrt{x} \cdot \cos y\right) \]
Alternative 9
Error16.5
Cost13504
\[\left(2 \cdot \sqrt{x}\right) \cdot \cos y + a \cdot \frac{-0.3333333333333333}{b} \]
Alternative 10
Error16.4
Cost13504
\[\left(2 \cdot \sqrt{x}\right) \cdot \cos y - \frac{a}{b \cdot 3} \]
Alternative 11
Error16.4
Cost13504
\[\left(2 \cdot \sqrt{x}\right) \cdot \cos y + \frac{\frac{a}{b}}{-3} \]
Alternative 12
Error24.8
Cost6976
\[2 \cdot \sqrt{x} - \frac{a}{b \cdot 3} \]
Alternative 13
Error24.9
Cost6976
\[2 \cdot \sqrt{x} + \frac{\frac{a}{b}}{-3} \]
Alternative 14
Error35.8
Cost320
\[-0.3333333333333333 \cdot \frac{a}{b} \]
Alternative 15
Error35.8
Cost320
\[\frac{a}{\frac{b}{-0.3333333333333333}} \]
Alternative 16
Error35.7
Cost320
\[\frac{\frac{a}{-3}}{b} \]

Error

Reproduce?

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