Average Error: 30.3 → 0.8
Time: 17.1s
Precision: 64
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.03354068643238588415256273833620070945472:\\ \;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right) \cdot \sin x}\\ \mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 0.00130404089207647086966213034742168019875:\\ \;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\sin x \cdot \frac{1}{1 - \cos x}}\\ \end{array}\]
\frac{1 - \cos x}{\sin x}
\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.03354068643238588415256273833620070945472:\\
\;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right) \cdot \sin x}\\

\mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 0.00130404089207647086966213034742168019875:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin x \cdot \frac{1}{1 - \cos x}}\\

\end{array}
double f(double x) {
        double r57903 = 1.0;
        double r57904 = x;
        double r57905 = cos(r57904);
        double r57906 = r57903 - r57905;
        double r57907 = sin(r57904);
        double r57908 = r57906 / r57907;
        return r57908;
}

double f(double x) {
        double r57909 = 1.0;
        double r57910 = x;
        double r57911 = cos(r57910);
        double r57912 = r57909 - r57911;
        double r57913 = sin(r57910);
        double r57914 = r57912 / r57913;
        double r57915 = -0.033540686432385884;
        bool r57916 = r57914 <= r57915;
        double r57917 = 3.0;
        double r57918 = pow(r57909, r57917);
        double r57919 = pow(r57911, r57917);
        double r57920 = r57918 - r57919;
        double r57921 = r57911 + r57909;
        double r57922 = r57911 * r57921;
        double r57923 = r57909 * r57909;
        double r57924 = r57922 + r57923;
        double r57925 = r57924 * r57913;
        double r57926 = r57920 / r57925;
        double r57927 = 0.0013040408920764709;
        bool r57928 = r57914 <= r57927;
        double r57929 = 0.041666666666666664;
        double r57930 = pow(r57910, r57917);
        double r57931 = r57929 * r57930;
        double r57932 = 0.004166666666666667;
        double r57933 = 5.0;
        double r57934 = pow(r57910, r57933);
        double r57935 = r57932 * r57934;
        double r57936 = 0.5;
        double r57937 = r57936 * r57910;
        double r57938 = r57935 + r57937;
        double r57939 = r57931 + r57938;
        double r57940 = 1.0;
        double r57941 = r57940 / r57912;
        double r57942 = r57913 * r57941;
        double r57943 = r57940 / r57942;
        double r57944 = r57928 ? r57939 : r57943;
        double r57945 = r57916 ? r57926 : r57944;
        return r57945;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original30.3
Target0.0
Herbie0.8
\[\tan \left(\frac{x}{2}\right)\]

Derivation

  1. Split input into 3 regimes
  2. if (/ (- 1.0 (cos x)) (sin x)) < -0.033540686432385884

    1. Initial program 0.7

      \[\frac{1 - \cos x}{\sin x}\]
    2. Using strategy rm
    3. Applied flip3--0.9

      \[\leadsto \frac{\color{blue}{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}}}{\sin x}\]
    4. Applied associate-/l/0.9

      \[\leadsto \color{blue}{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\sin x \cdot \left(1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)\right)}}\]
    5. Simplified0.9

      \[\leadsto \frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right) \cdot \sin x}}\]

    if -0.033540686432385884 < (/ (- 1.0 (cos x)) (sin x)) < 0.0013040408920764709

    1. Initial program 59.3

      \[\frac{1 - \cos x}{\sin x}\]
    2. Taylor expanded around 0 0.7

      \[\leadsto \color{blue}{\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)}\]

    if 0.0013040408920764709 < (/ (- 1.0 (cos x)) (sin x))

    1. Initial program 1.0

      \[\frac{1 - \cos x}{\sin x}\]
    2. Using strategy rm
    3. Applied clear-num1.1

      \[\leadsto \color{blue}{\frac{1}{\frac{\sin x}{1 - \cos x}}}\]
    4. Using strategy rm
    5. Applied div-inv1.1

      \[\leadsto \frac{1}{\color{blue}{\sin x \cdot \frac{1}{1 - \cos x}}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.03354068643238588415256273833620070945472:\\ \;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right) \cdot \sin x}\\ \mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 0.00130404089207647086966213034742168019875:\\ \;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\sin x \cdot \frac{1}{1 - \cos x}}\\ \end{array}\]

Reproduce

herbie shell --seed 2019294 
(FPCore (x)
  :name "tanhf (example 3.4)"
  :precision binary64
  :herbie-expected 2

  :herbie-target
  (tan (/ x 2))

  (/ (- 1 (cos x)) (sin x)))