Average Error: 20.1 → 14.6
Time: 18.9s
Precision: binary64
\[[z, t]=\mathsf{sort}([z, t])\]
\[\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 := 2 \cdot \sqrt{x}\\ t_2 := \frac{a}{b \cdot 3}\\ \mathbf{if}\;z \cdot t \leq -3.452797738024159 \cdot 10^{+293}:\\ \;\;\;\;t_1 - t_2\\ \mathbf{elif}\;z \cdot t \leq 1.8955791869966008 \cdot 10^{+233}:\\ \;\;\;\;\begin{array}{l} t_3 := z \cdot \frac{t}{3}\\ t_4 := \mathsf{fma}\left(1, y, -t_3\right)\\ t_5 := \mathsf{fma}\left(-\frac{t}{3}, z, t_3\right)\\ t_1 \cdot \left(\cos t_4 \cdot \cos t_5 - \sin t_4 \cdot \sin t_5\right) - t_2 \end{array}\\ \mathbf{else}:\\ \;\;\;\;t_1 \cdot \mathsf{expm1}\left(\mathsf{fma}\left(y, y \cdot -0.25, \log 2\right)\right) - t_2\\ \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 := 2 \cdot \sqrt{x}\\
t_2 := \frac{a}{b \cdot 3}\\
\mathbf{if}\;z \cdot t \leq -3.452797738024159 \cdot 10^{+293}:\\
\;\;\;\;t_1 - t_2\\

\mathbf{elif}\;z \cdot t \leq 1.8955791869966008 \cdot 10^{+233}:\\
\;\;\;\;\begin{array}{l}
t_3 := z \cdot \frac{t}{3}\\
t_4 := \mathsf{fma}\left(1, y, -t_3\right)\\
t_5 := \mathsf{fma}\left(-\frac{t}{3}, z, t_3\right)\\
t_1 \cdot \left(\cos t_4 \cdot \cos t_5 - \sin t_4 \cdot \sin t_5\right) - t_2
\end{array}\\

\mathbf{else}:\\
\;\;\;\;t_1 \cdot \mathsf{expm1}\left(\mathsf{fma}\left(y, y \cdot -0.25, \log 2\right)\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 (* 2.0 (sqrt x))) (t_2 (/ a (* b 3.0))))
   (if (<= (* z t) -3.452797738024159e+293)
     (- t_1 t_2)
     (if (<= (* z t) 1.8955791869966008e+233)
       (let* ((t_3 (* z (/ t 3.0)))
              (t_4 (fma 1.0 y (- t_3)))
              (t_5 (fma (- (/ t 3.0)) z t_3)))
         (- (* t_1 (- (* (cos t_4) (cos t_5)) (* (sin t_4) (sin t_5)))) t_2))
       (- (* t_1 (expm1 (fma y (* y -0.25) (log 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 = 2.0 * sqrt(x);
	double t_2 = a / (b * 3.0);
	double tmp;
	if ((z * t) <= -3.452797738024159e+293) {
		tmp = t_1 - t_2;
	} else if ((z * t) <= 1.8955791869966008e+233) {
		double t_3 = z * (t / 3.0);
		double t_4 = fma(1.0, y, -t_3);
		double t_5 = fma(-(t / 3.0), z, t_3);
		tmp = (t_1 * ((cos(t_4) * cos(t_5)) - (sin(t_4) * sin(t_5)))) - t_2;
	} else {
		tmp = (t_1 * expm1(fma(y, (y * -0.25), log(2.0)))) - t_2;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Bits error versus b

Target

Original20.1
Target18.4
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) < -3.45279773802415878e293

    1. Initial program 61.8

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

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

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

    if -3.45279773802415878e293 < (*.f64 z t) < 1.8955791869966008e233

    1. Initial program 13.2

      \[\left(2 \cdot \sqrt{x}\right) \cdot \cos \left(y - \frac{z \cdot t}{3}\right) - \frac{a}{b \cdot 3} \]
    2. Applied *-un-lft-identity_binary6413.2

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

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

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

      \[\leadsto \left(2 \cdot \sqrt{x}\right) \cdot \cos \color{blue}{\left(\mathsf{fma}\left(1, y, -\frac{t}{3} \cdot \frac{z}{1}\right) + \mathsf{fma}\left(-\frac{t}{3}, \frac{z}{1}, \frac{t}{3} \cdot \frac{z}{1}\right)\right)} - \frac{a}{b \cdot 3} \]
    6. Applied cos-sum_binary6411.0

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

    if 1.8955791869966008e233 < (*.f64 z t)

    1. Initial program 53.5

      \[\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.9

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

      \[\leadsto \left(2 \cdot \sqrt{x}\right) \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos y\right)\right)} - \frac{a}{b \cdot 3} \]
    4. Taylor expanded in y around 0 32.9

      \[\leadsto \left(2 \cdot \sqrt{x}\right) \cdot \mathsf{expm1}\left(\color{blue}{\log 2 - 0.25 \cdot {y}^{2}}\right) - \frac{a}{b \cdot 3} \]
    5. Simplified32.9

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

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

Reproduce

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