Average Error: 20.0 → 15.3
Time: 1.7m
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.9999896787288287125505803487612865865231:\\ \;\;\;\;\left(\sqrt{x} \cdot 2\right) \cdot \left(\left(\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(-z \cdot \frac{t}{3}\right)\right)\right)\right)\right) \cdot \cos y - \sin y \cdot \sin \left(-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(\sqrt{x} \cdot 2\right) \cdot \mathsf{fma}\left(\frac{-1}{2}, y \cdot y, 1\right) - \frac{a}{b \cdot 3}\\ \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.9999896787288287125505803487612865865231:\\
\;\;\;\;\left(\sqrt{x} \cdot 2\right) \cdot \left(\left(\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(-z \cdot \frac{t}{3}\right)\right)\right)\right)\right) \cdot \cos y - \sin y \cdot \sin \left(-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(\sqrt{x} \cdot 2\right) \cdot \mathsf{fma}\left(\frac{-1}{2}, y \cdot y, 1\right) - \frac{a}{b \cdot 3}\\

\end{array}
double f(double x, double y, double z, double t, double a, double b) {
        double r32392650 = 2.0;
        double r32392651 = x;
        double r32392652 = sqrt(r32392651);
        double r32392653 = r32392650 * r32392652;
        double r32392654 = y;
        double r32392655 = z;
        double r32392656 = t;
        double r32392657 = r32392655 * r32392656;
        double r32392658 = 3.0;
        double r32392659 = r32392657 / r32392658;
        double r32392660 = r32392654 - r32392659;
        double r32392661 = cos(r32392660);
        double r32392662 = r32392653 * r32392661;
        double r32392663 = a;
        double r32392664 = b;
        double r32392665 = r32392664 * r32392658;
        double r32392666 = r32392663 / r32392665;
        double r32392667 = r32392662 - r32392666;
        return r32392667;
}

double f(double x, double y, double z, double t, double a, double b) {
        double r32392668 = y;
        double r32392669 = t;
        double r32392670 = z;
        double r32392671 = r32392669 * r32392670;
        double r32392672 = 3.0;
        double r32392673 = r32392671 / r32392672;
        double r32392674 = r32392668 - r32392673;
        double r32392675 = cos(r32392674);
        double r32392676 = 0.9999896787288287;
        bool r32392677 = r32392675 <= r32392676;
        double r32392678 = x;
        double r32392679 = sqrt(r32392678);
        double r32392680 = 2.0;
        double r32392681 = r32392679 * r32392680;
        double r32392682 = r32392669 / r32392672;
        double r32392683 = r32392670 * r32392682;
        double r32392684 = -r32392683;
        double r32392685 = cos(r32392684);
        double r32392686 = expm1(r32392685);
        double r32392687 = log1p(r32392686);
        double r32392688 = log1p(r32392687);
        double r32392689 = expm1(r32392688);
        double r32392690 = cos(r32392668);
        double r32392691 = r32392689 * r32392690;
        double r32392692 = sin(r32392668);
        double r32392693 = sin(r32392684);
        double r32392694 = r32392692 * r32392693;
        double r32392695 = r32392691 - r32392694;
        double r32392696 = -r32392669;
        double r32392697 = r32392696 / r32392672;
        double r32392698 = fma(r32392697, r32392670, r32392683);
        double r32392699 = cos(r32392698);
        double r32392700 = r32392695 * r32392699;
        double r32392701 = 1.0;
        double r32392702 = fma(r32392701, r32392668, r32392684);
        double r32392703 = sin(r32392702);
        double r32392704 = sin(r32392698);
        double r32392705 = r32392703 * r32392704;
        double r32392706 = r32392700 - r32392705;
        double r32392707 = r32392681 * r32392706;
        double r32392708 = a;
        double r32392709 = b;
        double r32392710 = r32392709 * r32392672;
        double r32392711 = r32392708 / r32392710;
        double r32392712 = r32392707 - r32392711;
        double r32392713 = -0.5;
        double r32392714 = r32392668 * r32392668;
        double r32392715 = fma(r32392713, r32392714, r32392701);
        double r32392716 = r32392681 * r32392715;
        double r32392717 = r32392716 - r32392711;
        double r32392718 = r32392677 ? r32392712 : r32392717;
        return r32392718;
}

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.0
Target18.0
Herbie15.3
\[\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.9999896787288287

    1. Initial program 19.2

      \[\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-identity19.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}\]
    4. Applied times-frac19.2

      \[\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-identity19.2

      \[\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-diff19.2

      \[\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-sum16.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-udef16.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-sum15.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-u15.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}\]
    13. Using strategy rm
    14. Applied log1p-expm1-u15.5

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

    1. Initial program 21.2

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

      \[\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. Simplified15.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(y - \frac{t \cdot z}{3}\right) \le 0.9999896787288287125505803487612865865231:\\ \;\;\;\;\left(\sqrt{x} \cdot 2\right) \cdot \left(\left(\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(-z \cdot \frac{t}{3}\right)\right)\right)\right)\right) \cdot \cos y - \sin y \cdot \sin \left(-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(\sqrt{x} \cdot 2\right) \cdot \mathsf{fma}\left(\frac{-1}{2}, y \cdot y, 1\right) - \frac{a}{b \cdot 3}\\ \end{array}\]

Reproduce

herbie shell --seed 2019168 +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))))