Average Error: 30.4 → 0.6
Time: 22.5s
Precision: 64
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.02364773704659709624431584984449727926403:\\ \;\;\;\;\frac{\sqrt{e^{\log \left(1 - \cos x\right)}}}{\sin x} \cdot \sqrt{1 - \cos x}\\ \mathbf{elif}\;x \le 0.02077111946200701705911306760299339657649:\\ \;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\log \left(e^{{1}^{3} - {\left(\cos x\right)}^{3}}\right)}{\sin x \cdot \left(\cos x \cdot \left(1 + \cos x\right) + 1 \cdot 1\right)}\\ \end{array}\]
\frac{1 - \cos x}{\sin x}
\begin{array}{l}
\mathbf{if}\;x \le -0.02364773704659709624431584984449727926403:\\
\;\;\;\;\frac{\sqrt{e^{\log \left(1 - \cos x\right)}}}{\sin x} \cdot \sqrt{1 - \cos x}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{\log \left(e^{{1}^{3} - {\left(\cos x\right)}^{3}}\right)}{\sin x \cdot \left(\cos x \cdot \left(1 + \cos x\right) + 1 \cdot 1\right)}\\

\end{array}
double f(double x) {
        double r64474 = 1.0;
        double r64475 = x;
        double r64476 = cos(r64475);
        double r64477 = r64474 - r64476;
        double r64478 = sin(r64475);
        double r64479 = r64477 / r64478;
        return r64479;
}

double f(double x) {
        double r64480 = x;
        double r64481 = -0.023647737046597096;
        bool r64482 = r64480 <= r64481;
        double r64483 = 1.0;
        double r64484 = cos(r64480);
        double r64485 = r64483 - r64484;
        double r64486 = log(r64485);
        double r64487 = exp(r64486);
        double r64488 = sqrt(r64487);
        double r64489 = sin(r64480);
        double r64490 = r64488 / r64489;
        double r64491 = sqrt(r64485);
        double r64492 = r64490 * r64491;
        double r64493 = 0.020771119462007017;
        bool r64494 = r64480 <= r64493;
        double r64495 = 0.041666666666666664;
        double r64496 = 3.0;
        double r64497 = pow(r64480, r64496);
        double r64498 = r64495 * r64497;
        double r64499 = 0.004166666666666667;
        double r64500 = 5.0;
        double r64501 = pow(r64480, r64500);
        double r64502 = r64499 * r64501;
        double r64503 = 0.5;
        double r64504 = r64503 * r64480;
        double r64505 = r64502 + r64504;
        double r64506 = r64498 + r64505;
        double r64507 = pow(r64483, r64496);
        double r64508 = pow(r64484, r64496);
        double r64509 = r64507 - r64508;
        double r64510 = exp(r64509);
        double r64511 = log(r64510);
        double r64512 = r64483 + r64484;
        double r64513 = r64484 * r64512;
        double r64514 = r64483 * r64483;
        double r64515 = r64513 + r64514;
        double r64516 = r64489 * r64515;
        double r64517 = r64511 / r64516;
        double r64518 = r64494 ? r64506 : r64517;
        double r64519 = r64482 ? r64492 : r64518;
        return r64519;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Split input into 3 regimes
  2. if x < -0.023647737046597096

    1. Initial program 0.9

      \[\frac{1 - \cos x}{\sin x}\]
    2. Using strategy rm
    3. Applied add-log-exp1.0

      \[\leadsto \color{blue}{\log \left(e^{\frac{1 - \cos x}{\sin x}}\right)}\]
    4. Using strategy rm
    5. Applied add-exp-log1.1

      \[\leadsto \log \left(e^{\frac{\color{blue}{e^{\log \left(1 - \cos x\right)}}}{\sin x}}\right)\]
    6. Using strategy rm
    7. Applied *-un-lft-identity1.1

      \[\leadsto \log \left(e^{\frac{e^{\log \left(1 - \cos x\right)}}{\color{blue}{1 \cdot \sin x}}}\right)\]
    8. Applied add-sqr-sqrt1.2

      \[\leadsto \log \left(e^{\frac{\color{blue}{\sqrt{e^{\log \left(1 - \cos x\right)}} \cdot \sqrt{e^{\log \left(1 - \cos x\right)}}}}{1 \cdot \sin x}}\right)\]
    9. Applied times-frac1.3

      \[\leadsto \log \left(e^{\color{blue}{\frac{\sqrt{e^{\log \left(1 - \cos x\right)}}}{1} \cdot \frac{\sqrt{e^{\log \left(1 - \cos x\right)}}}{\sin x}}}\right)\]
    10. Applied exp-prod1.3

      \[\leadsto \log \color{blue}{\left({\left(e^{\frac{\sqrt{e^{\log \left(1 - \cos x\right)}}}{1}}\right)}^{\left(\frac{\sqrt{e^{\log \left(1 - \cos x\right)}}}{\sin x}\right)}\right)}\]
    11. Applied log-pow1.2

      \[\leadsto \color{blue}{\frac{\sqrt{e^{\log \left(1 - \cos x\right)}}}{\sin x} \cdot \log \left(e^{\frac{\sqrt{e^{\log \left(1 - \cos x\right)}}}{1}}\right)}\]
    12. Simplified1.1

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

    if -0.023647737046597096 < x < 0.020771119462007017

    1. Initial program 60.0

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

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

    if 0.020771119462007017 < x

    1. Initial program 0.9

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

      \[\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/1.1

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

      \[\leadsto \frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\sin x \cdot \left(\cos x \cdot \left(1 + \cos x\right) + 1 \cdot 1\right)}}\]
    6. Using strategy rm
    7. Applied add-log-exp1.1

      \[\leadsto \frac{{1}^{3} - \color{blue}{\log \left(e^{{\left(\cos x\right)}^{3}}\right)}}{\sin x \cdot \left(\cos x \cdot \left(1 + \cos x\right) + 1 \cdot 1\right)}\]
    8. Applied add-log-exp1.1

      \[\leadsto \frac{\color{blue}{\log \left(e^{{1}^{3}}\right)} - \log \left(e^{{\left(\cos x\right)}^{3}}\right)}{\sin x \cdot \left(\cos x \cdot \left(1 + \cos x\right) + 1 \cdot 1\right)}\]
    9. Applied diff-log1.2

      \[\leadsto \frac{\color{blue}{\log \left(\frac{e^{{1}^{3}}}{e^{{\left(\cos x\right)}^{3}}}\right)}}{\sin x \cdot \left(\cos x \cdot \left(1 + \cos x\right) + 1 \cdot 1\right)}\]
    10. Simplified1.1

      \[\leadsto \frac{\log \color{blue}{\left(e^{{1}^{3} - {\left(\cos x\right)}^{3}}\right)}}{\sin x \cdot \left(\cos x \cdot \left(1 + \cos x\right) + 1 \cdot 1\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.6

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

Reproduce

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

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

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