Average Error: 20.6 → 15.9
Time: 44.5s
Precision: 64
\[\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}\;\cos \left(y - \frac{t \cdot z}{3}\right) \le 0.9997953791044875693216908985050395131111:\\ \;\;\;\;\left(\cos \left(\mathsf{fma}\left(\frac{-t}{3}, z, z \cdot \frac{t}{3}\right)\right) \cdot \left(\cos y \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(\frac{-t}{3} \cdot z\right)\right)\right) - \sin y \cdot \sin \left(\frac{-t}{3} \cdot z\right)\right) - \sin \left(\mathsf{fma}\left(\frac{-t}{3}, z, z \cdot \frac{t}{3}\right)\right) \cdot \sin \left(\mathsf{fma}\left(1, y, \frac{-t}{3} \cdot z\right)\right)\right) \cdot \left(\sqrt{x} \cdot 2\right) - \frac{a}{3 \cdot b}\\ \mathbf{else}:\\ \;\;\;\;\left(\sqrt{x} \cdot 2\right) \cdot \mathsf{fma}\left(\frac{-1}{2}, y \cdot y, 1\right) - \frac{a}{3 \cdot b}\\ \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}\;\cos \left(y - \frac{t \cdot z}{3}\right) \le 0.9997953791044875693216908985050395131111:\\
\;\;\;\;\left(\cos \left(\mathsf{fma}\left(\frac{-t}{3}, z, z \cdot \frac{t}{3}\right)\right) \cdot \left(\cos y \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(\frac{-t}{3} \cdot z\right)\right)\right) - \sin y \cdot \sin \left(\frac{-t}{3} \cdot z\right)\right) - \sin \left(\mathsf{fma}\left(\frac{-t}{3}, z, z \cdot \frac{t}{3}\right)\right) \cdot \sin \left(\mathsf{fma}\left(1, y, \frac{-t}{3} \cdot z\right)\right)\right) \cdot \left(\sqrt{x} \cdot 2\right) - \frac{a}{3 \cdot b}\\

\mathbf{else}:\\
\;\;\;\;\left(\sqrt{x} \cdot 2\right) \cdot \mathsf{fma}\left(\frac{-1}{2}, y \cdot y, 1\right) - \frac{a}{3 \cdot b}\\

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r34254888 = 2.0;
        double r34254889 = x;
        double r34254890 = sqrt(r34254889);
        double r34254891 = r34254888 * r34254890;
        double r34254892 = y;
        double r34254893 = z;
        double r34254894 = t;
        double r34254895 = r34254893 * r34254894;
        double r34254896 = 3.0;
        double r34254897 = r34254895 / r34254896;
        double r34254898 = r34254892 - r34254897;
        double r34254899 = cos(r34254898);
        double r34254900 = r34254891 * r34254899;
        double r34254901 = a;
        double r34254902 = b;
        double r34254903 = r34254902 * r34254896;
        double r34254904 = r34254901 / r34254903;
        double r34254905 = r34254900 - r34254904;
        return r34254905;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r34254906 = y;
        double r34254907 = t;
        double r34254908 = z;
        double r34254909 = r34254907 * r34254908;
        double r34254910 = 3.0;
        double r34254911 = r34254909 / r34254910;
        double r34254912 = r34254906 - r34254911;
        double r34254913 = cos(r34254912);
        double r34254914 = 0.9997953791044876;
        bool r34254915 = r34254913 <= r34254914;
        double r34254916 = -r34254907;
        double r34254917 = r34254916 / r34254910;
        double r34254918 = r34254907 / r34254910;
        double r34254919 = r34254908 * r34254918;
        double r34254920 = fma(r34254917, r34254908, r34254919);
        double r34254921 = cos(r34254920);
        double r34254922 = cos(r34254906);
        double r34254923 = r34254917 * r34254908;
        double r34254924 = cos(r34254923);
        double r34254925 = log1p(r34254924);
        double r34254926 = expm1(r34254925);
        double r34254927 = r34254922 * r34254926;
        double r34254928 = sin(r34254906);
        double r34254929 = sin(r34254923);
        double r34254930 = r34254928 * r34254929;
        double r34254931 = r34254927 - r34254930;
        double r34254932 = r34254921 * r34254931;
        double r34254933 = sin(r34254920);
        double r34254934 = 1.0;
        double r34254935 = fma(r34254934, r34254906, r34254923);
        double r34254936 = sin(r34254935);
        double r34254937 = r34254933 * r34254936;
        double r34254938 = r34254932 - r34254937;
        double r34254939 = x;
        double r34254940 = sqrt(r34254939);
        double r34254941 = 2.0;
        double r34254942 = r34254940 * r34254941;
        double r34254943 = r34254938 * r34254942;
        double r34254944 = a;
        double r34254945 = b;
        double r34254946 = r34254910 * r34254945;
        double r34254947 = r34254944 / r34254946;
        double r34254948 = r34254943 - r34254947;
        double r34254949 = -0.5;
        double r34254950 = r34254906 * r34254906;
        double r34254951 = fma(r34254949, r34254950, r34254934);
        double r34254952 = r34254942 * r34254951;
        double r34254953 = r34254952 - r34254947;
        double r34254954 = r34254915 ? r34254948 : r34254953;
        return r34254954;
}

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.6
Target18.7
Herbie15.9
\[\begin{array}{l} \mathbf{if}\;z \lt -1.379333748723514136852843173740882251575 \cdot 10^{129}:\\ \;\;\;\;\left(2 \cdot \sqrt{x}\right) \cdot \cos \left(\frac{1}{y} - \frac{\frac{0.3333333333333333148296162562473909929395}{z}}{t}\right) - \frac{\frac{a}{3}}{b}\\ \mathbf{elif}\;z \lt 3.516290613555987147199887107423758623887 \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.3333333333333333148296162562473909929395}{z}}{t}\right) \cdot \left(2 \cdot \sqrt{x}\right) - \frac{\frac{a}{b}}{3}\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if (cos (- y (/ (* z t) 3.0))) < 0.9997953791044876

    1. Initial program 20.5

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

      \[\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}\]
    4. Applied times-frac20.5

      \[\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}\]
    5. Applied *-un-lft-identity20.5

      \[\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}\]
    6. Applied prod-diff20.5

      \[\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}\]
    7. Applied cos-sum17.4

      \[\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}\]
    8. Using strategy rm
    9. Applied fma-udef17.4

      \[\leadsto \left(2 \cdot \sqrt{x}\right) \cdot \left(\cos \color{blue}{\left(1 \cdot y + \left(-\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}\]
    10. Applied cos-sum16.5

      \[\leadsto \left(2 \cdot \sqrt{x}\right) \cdot \left(\color{blue}{\left(\cos \left(1 \cdot y\right) \cdot \cos \left(-\frac{t}{3} \cdot \frac{z}{1}\right) - \sin \left(1 \cdot y\right) \cdot \sin \left(-\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}\]
    11. Using strategy rm
    12. Applied expm1-log1p-u16.5

      \[\leadsto \left(2 \cdot \sqrt{x}\right) \cdot \left(\left(\cos \left(1 \cdot y\right) \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(-\frac{t}{3} \cdot \frac{z}{1}\right)\right)\right)} - \sin \left(1 \cdot y\right) \cdot \sin \left(-\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 0.9997953791044876 < (cos (- y (/ (* z t) 3.0)))

    1. Initial program 20.7

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

      \[\leadsto \left(2 \cdot \sqrt{x}\right) \cdot \color{blue}{\left(1 - \frac{1}{2} \cdot {y}^{2}\right)} - \frac{a}{b \cdot 3}\]
    3. Simplified14.8

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

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

Reproduce

herbie shell --seed 2019169 +o rules:numerics
(FPCore (x y z t a b)
  :name "Diagrams.Solve.Polynomial:cubForm  from diagrams-solve-0.1, K"

  :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))))