Average Error: 20.7 → 16.4
Time: 12.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} \mathbf{if}\;z \cdot t \leq -1.5924942241623108 \cdot 10^{+206}:\\ \;\;\;\;\mathsf{fma}\left(-0.3333333333333333, \frac{a}{b}, 2 \cdot \left(\cos y \cdot \sqrt{x}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_1 := 2 \cdot \sqrt{x}\\ \mathbf{if}\;z \cdot t \leq 2.7279406500333466 \cdot 10^{+142}:\\ \;\;\;\;\mathsf{fma}\left(a, \frac{-0.3333333333333333}{b}, t_1 \cdot \left(\cos y \cdot \cos \left(\left(z \cdot t\right) \cdot 0.3333333333333333\right) - \sin y \cdot \sin \left(z \cdot \left(t \cdot -0.3333333333333333\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a, \frac{-0.3333333333333333}{b}, t_1\right)\\ \end{array}\\ \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}
\mathbf{if}\;z \cdot t \leq -1.5924942241623108 \cdot 10^{+206}:\\
\;\;\;\;\mathsf{fma}\left(-0.3333333333333333, \frac{a}{b}, 2 \cdot \left(\cos y \cdot \sqrt{x}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_1 := 2 \cdot \sqrt{x}\\
\mathbf{if}\;z \cdot t \leq 2.7279406500333466 \cdot 10^{+142}:\\
\;\;\;\;\mathsf{fma}\left(a, \frac{-0.3333333333333333}{b}, t_1 \cdot \left(\cos y \cdot \cos \left(\left(z \cdot t\right) \cdot 0.3333333333333333\right) - \sin y \cdot \sin \left(z \cdot \left(t \cdot -0.3333333333333333\right)\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, \frac{-0.3333333333333333}{b}, t_1\right)\\


\end{array}\\


\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
 (if (<= (* z t) -1.5924942241623108e+206)
   (fma -0.3333333333333333 (/ a b) (* 2.0 (* (cos y) (sqrt x))))
   (let* ((t_1 (* 2.0 (sqrt x))))
     (if (<= (* z t) 2.7279406500333466e+142)
       (fma
        a
        (/ -0.3333333333333333 b)
        (*
         t_1
         (-
          (* (cos y) (cos (* (* z t) 0.3333333333333333)))
          (* (sin y) (sin (* z (* t -0.3333333333333333)))))))
       (fma a (/ -0.3333333333333333 b) 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 tmp;
	if ((z * t) <= -1.5924942241623108e+206) {
		tmp = fma(-0.3333333333333333, (a / b), (2.0 * (cos(y) * sqrt(x))));
	} else {
		double t_1 = 2.0 * sqrt(x);
		double tmp_1;
		if ((z * t) <= 2.7279406500333466e+142) {
			tmp_1 = fma(a, (-0.3333333333333333 / b), (t_1 * ((cos(y) * cos((z * t) * 0.3333333333333333)) - (sin(y) * sin(z * (t * -0.3333333333333333))))));
		} else {
			tmp_1 = fma(a, (-0.3333333333333333 / b), t_1);
		}
		tmp = tmp_1;
	}
	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.7
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) < -1.59249422416231081e206

    1. Initial program 50.7

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

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

      \[\leadsto \mathsf{fma}\left(a, \frac{-0.3333333333333333}{b}, \left(2 \cdot \sqrt{x}\right) \cdot \color{blue}{\cos y}\right) \]
    4. Applied div-inv_binary6434.7

      \[\leadsto \mathsf{fma}\left(a, \color{blue}{-0.3333333333333333 \cdot \frac{1}{b}}, \left(2 \cdot \sqrt{x}\right) \cdot \cos y\right) \]
    5. Taylor expanded in a around 0 34.7

      \[\leadsto \color{blue}{2 \cdot \left(\cos y \cdot \sqrt{x}\right) - 0.3333333333333333 \cdot \frac{a}{b}} \]
    6. Simplified34.7

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

    if -1.59249422416231081e206 < (*.f64 z t) < 2.7279406500333466e142

    1. Initial program 11.0

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

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

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

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

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

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

    if 2.7279406500333466e142 < (*.f64 z t)

    1. Initial program 46.9

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

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

      \[\leadsto \mathsf{fma}\left(a, \frac{-0.3333333333333333}{b}, \left(2 \cdot \sqrt{x}\right) \cdot \color{blue}{\cos y}\right) \]
    4. Taylor expanded in y around 0 32.5

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

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

Reproduce

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