Average Error: 27.9 → 2.6
Time: 15.5s
Precision: 64
Internal Precision: 128
\[\frac{\cos \left(2 \cdot x\right)}{{cos}^{2} \cdot \left(\left(x \cdot {sin}^{2}\right) \cdot x\right)}\]
\[\begin{array}{l} \mathbf{if}\;sin \le -7.477021423829115 \cdot 10^{-308}:\\ \;\;\;\;\frac{\left(\sin x + \cos x\right) \cdot \left(\cos x - \sin x\right)}{\left(sin \cdot \left(x \cdot cos\right)\right) \cdot \left(sin \cdot \left(x \cdot cos\right)\right)}\\ \mathbf{elif}\;sin \le 9.850296288943132 \cdot 10^{-242}:\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{\left(\left(x \cdot sin\right) \cdot cos\right) \cdot \left(\left(x \cdot sin\right) \cdot cos\right)}\\ \mathbf{elif}\;sin \le 1.5441177336945428 \cdot 10^{+181}:\\ \;\;\;\;\frac{(\left(\cos x\right) \cdot \left(\cos x\right) + \left(-\log \left(e^{\sin x \cdot \sin x}\right)\right))_*}{\left(sin \cdot \left(x \cdot cos\right)\right) \cdot \left(sin \cdot \left(x \cdot cos\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{\left(\left(x \cdot sin\right) \cdot cos\right) \cdot \left(\left(x \cdot sin\right) \cdot cos\right)}\\ \end{array}\]

Error

Bits error versus x

Bits error versus cos

Bits error versus sin

Derivation

  1. Split input into 3 regimes
  2. if sin < -7.477021423829115e-308

    1. Initial program 27.2

      \[\frac{\cos \left(2 \cdot x\right)}{{cos}^{2} \cdot \left(\left(x \cdot {sin}^{2}\right) \cdot x\right)}\]
    2. Simplified3.0

      \[\leadsto \color{blue}{\frac{\cos \left(2 \cdot x\right)}{\left(sin \cdot \left(x \cdot cos\right)\right) \cdot \left(sin \cdot \left(x \cdot cos\right)\right)}}\]
    3. Using strategy rm
    4. Applied cos-23.0

      \[\leadsto \frac{\color{blue}{\cos x \cdot \cos x - \sin x \cdot \sin x}}{\left(sin \cdot \left(x \cdot cos\right)\right) \cdot \left(sin \cdot \left(x \cdot cos\right)\right)}\]
    5. Using strategy rm
    6. Applied fma-neg3.0

      \[\leadsto \frac{\color{blue}{(\left(\cos x\right) \cdot \left(\cos x\right) + \left(-\sin x \cdot \sin x\right))_*}}{\left(sin \cdot \left(x \cdot cos\right)\right) \cdot \left(sin \cdot \left(x \cdot cos\right)\right)}\]
    7. Taylor expanded around -inf 3.0

      \[\leadsto \frac{\color{blue}{{\left(\cos x\right)}^{2} - {\left(\sin x\right)}^{2}}}{\left(sin \cdot \left(x \cdot cos\right)\right) \cdot \left(sin \cdot \left(x \cdot cos\right)\right)}\]
    8. Simplified3.0

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

    if -7.477021423829115e-308 < sin < 9.850296288943132e-242 or 1.5441177336945428e+181 < sin

    1. Initial program 30.9

      \[\frac{\cos \left(2 \cdot x\right)}{{cos}^{2} \cdot \left(\left(x \cdot {sin}^{2}\right) \cdot x\right)}\]
    2. Simplified6.6

      \[\leadsto \color{blue}{\frac{\cos \left(2 \cdot x\right)}{\left(sin \cdot \left(x \cdot cos\right)\right) \cdot \left(sin \cdot \left(x \cdot cos\right)\right)}}\]
    3. Taylor expanded around -inf 34.2

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{x}^{2} \cdot \left({cos}^{2} \cdot {sin}^{2}\right)}}\]
    4. Simplified3.3

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

    if 9.850296288943132e-242 < sin < 1.5441177336945428e+181

    1. Initial program 27.4

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

      \[\leadsto \color{blue}{\frac{\cos \left(2 \cdot x\right)}{\left(sin \cdot \left(x \cdot cos\right)\right) \cdot \left(sin \cdot \left(x \cdot cos\right)\right)}}\]
    3. Using strategy rm
    4. Applied cos-21.6

      \[\leadsto \frac{\color{blue}{\cos x \cdot \cos x - \sin x \cdot \sin x}}{\left(sin \cdot \left(x \cdot cos\right)\right) \cdot \left(sin \cdot \left(x \cdot cos\right)\right)}\]
    5. Using strategy rm
    6. Applied fma-neg1.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;sin \le -7.477021423829115 \cdot 10^{-308}:\\ \;\;\;\;\frac{\left(\sin x + \cos x\right) \cdot \left(\cos x - \sin x\right)}{\left(sin \cdot \left(x \cdot cos\right)\right) \cdot \left(sin \cdot \left(x \cdot cos\right)\right)}\\ \mathbf{elif}\;sin \le 9.850296288943132 \cdot 10^{-242}:\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{\left(\left(x \cdot sin\right) \cdot cos\right) \cdot \left(\left(x \cdot sin\right) \cdot cos\right)}\\ \mathbf{elif}\;sin \le 1.5441177336945428 \cdot 10^{+181}:\\ \;\;\;\;\frac{(\left(\cos x\right) \cdot \left(\cos x\right) + \left(-\log \left(e^{\sin x \cdot \sin x}\right)\right))_*}{\left(sin \cdot \left(x \cdot cos\right)\right) \cdot \left(sin \cdot \left(x \cdot cos\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{\left(\left(x \cdot sin\right) \cdot cos\right) \cdot \left(\left(x \cdot sin\right) \cdot cos\right)}\\ \end{array}\]

Reproduce

herbie shell --seed 2019053 +o rules:numerics
(FPCore (x cos sin)
  :name "cos(2*x)/(cos^2(x)*sin^2(x))"
  (/ (cos (* 2 x)) (* (pow cos 2) (* (* x (pow sin 2)) x))))