Average Error: 30.7 → 0.6
Time: 50.9s
Precision: 64
\[\frac{1}{{x}^{2}} - \frac{1 + \cos x}{\left(2 \cdot x\right) \cdot \sin x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.05201430939629755:\\ \;\;\;\;\frac{\frac{\frac{1}{2}}{x} \cdot \left(-1 - \cos x\right)}{\sin x} - \frac{\frac{-1}{x}}{x}\\ \mathbf{elif}\;x \le 0.09809591180606583:\\ \;\;\;\;\left(\frac{1}{12} + \left(x \cdot x\right) \cdot \frac{1}{720}\right) + \frac{1}{30240} \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{\sin x \cdot \sin x}{-1 + \cos x}}{x \cdot 2}}{\sin x} - \frac{\frac{-1}{x}}{x}\\ \end{array}\]
\frac{1}{{x}^{2}} - \frac{1 + \cos x}{\left(2 \cdot x\right) \cdot \sin x}
\begin{array}{l}
\mathbf{if}\;x \le -0.05201430939629755:\\
\;\;\;\;\frac{\frac{\frac{1}{2}}{x} \cdot \left(-1 - \cos x\right)}{\sin x} - \frac{\frac{-1}{x}}{x}\\

\mathbf{elif}\;x \le 0.09809591180606583:\\
\;\;\;\;\left(\frac{1}{12} + \left(x \cdot x\right) \cdot \frac{1}{720}\right) + \frac{1}{30240} \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)\\

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

\end{array}
double f(double x) {
        double r14302144 = 1.0;
        double r14302145 = x;
        double r14302146 = 2.0;
        double r14302147 = pow(r14302145, r14302146);
        double r14302148 = r14302144 / r14302147;
        double r14302149 = cos(r14302145);
        double r14302150 = r14302144 + r14302149;
        double r14302151 = r14302146 * r14302145;
        double r14302152 = sin(r14302145);
        double r14302153 = r14302151 * r14302152;
        double r14302154 = r14302150 / r14302153;
        double r14302155 = r14302148 - r14302154;
        return r14302155;
}

double f(double x) {
        double r14302156 = x;
        double r14302157 = -0.05201430939629755;
        bool r14302158 = r14302156 <= r14302157;
        double r14302159 = 0.5;
        double r14302160 = r14302159 / r14302156;
        double r14302161 = -1.0;
        double r14302162 = cos(r14302156);
        double r14302163 = r14302161 - r14302162;
        double r14302164 = r14302160 * r14302163;
        double r14302165 = sin(r14302156);
        double r14302166 = r14302164 / r14302165;
        double r14302167 = r14302161 / r14302156;
        double r14302168 = r14302167 / r14302156;
        double r14302169 = r14302166 - r14302168;
        double r14302170 = 0.09809591180606583;
        bool r14302171 = r14302156 <= r14302170;
        double r14302172 = 0.08333333333333333;
        double r14302173 = r14302156 * r14302156;
        double r14302174 = 0.001388888888888889;
        double r14302175 = r14302173 * r14302174;
        double r14302176 = r14302172 + r14302175;
        double r14302177 = 3.306878306878307e-05;
        double r14302178 = r14302173 * r14302173;
        double r14302179 = r14302177 * r14302178;
        double r14302180 = r14302176 + r14302179;
        double r14302181 = r14302165 * r14302165;
        double r14302182 = r14302161 + r14302162;
        double r14302183 = r14302181 / r14302182;
        double r14302184 = 2.0;
        double r14302185 = r14302156 * r14302184;
        double r14302186 = r14302183 / r14302185;
        double r14302187 = r14302186 / r14302165;
        double r14302188 = r14302187 - r14302168;
        double r14302189 = r14302171 ? r14302180 : r14302188;
        double r14302190 = r14302158 ? r14302169 : r14302189;
        return r14302190;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

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

    1. Initial program 1.2

      \[\frac{1}{{x}^{2}} - \frac{1 + \cos x}{\left(2 \cdot x\right) \cdot \sin x}\]
    2. Simplified1.2

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

      \[\leadsto \frac{\color{blue}{\left(-1 - \cos x\right) \cdot \frac{1}{2 \cdot x}}}{\sin x} - \frac{\frac{-1}{x}}{x}\]
    5. Simplified1.1

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

    if -0.05201430939629755 < x < 0.09809591180606583

    1. Initial program 61.2

      \[\frac{1}{{x}^{2}} - \frac{1 + \cos x}{\left(2 \cdot x\right) \cdot \sin x}\]
    2. Simplified61.2

      \[\leadsto \color{blue}{\frac{\frac{-1 - \cos x}{2 \cdot x}}{\sin x} - \frac{\frac{-1}{x}}{x}}\]
    3. Taylor expanded around 0 0.0

      \[\leadsto \color{blue}{\frac{1}{720} \cdot {x}^{2} + \left(\frac{1}{30240} \cdot {x}^{4} + \frac{1}{12}\right)}\]
    4. Simplified0.0

      \[\leadsto \color{blue}{\frac{1}{30240} \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right) + \left(\frac{1}{720} \cdot \left(x \cdot x\right) + \frac{1}{12}\right)}\]

    if 0.09809591180606583 < x

    1. Initial program 1.0

      \[\frac{1}{{x}^{2}} - \frac{1 + \cos x}{\left(2 \cdot x\right) \cdot \sin x}\]
    2. Simplified1.0

      \[\leadsto \color{blue}{\frac{\frac{-1 - \cos x}{2 \cdot x}}{\sin x} - \frac{\frac{-1}{x}}{x}}\]
    3. Using strategy rm
    4. Applied flip--1.4

      \[\leadsto \frac{\frac{\color{blue}{\frac{-1 \cdot -1 - \cos x \cdot \cos x}{-1 + \cos x}}}{2 \cdot x}}{\sin x} - \frac{\frac{-1}{x}}{x}\]
    5. Simplified1.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.05201430939629755:\\ \;\;\;\;\frac{\frac{\frac{1}{2}}{x} \cdot \left(-1 - \cos x\right)}{\sin x} - \frac{\frac{-1}{x}}{x}\\ \mathbf{elif}\;x \le 0.09809591180606583:\\ \;\;\;\;\left(\frac{1}{12} + \left(x \cdot x\right) \cdot \frac{1}{720}\right) + \frac{1}{30240} \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{\sin x \cdot \sin x}{-1 + \cos x}}{x \cdot 2}}{\sin x} - \frac{\frac{-1}{x}}{x}\\ \end{array}\]

Reproduce

herbie shell --seed 1 
(FPCore (x)
  :name "1/x^2-(1+cos(x))/(2*x*sin(x))"
  (- (/ 1 (pow x 2)) (/ (+ 1 (cos x)) (* (* 2 x) (sin x)))))