Average Error: 37.6 → 15.1
Time: 3.0m
Precision: 64
Internal Precision: 2432
\[\tan \left(x + \varepsilon\right) - \tan x\]
\[\begin{array}{l} \mathbf{if}\;\varepsilon \le -3.088211040495327 \cdot 10^{-21}:\\ \;\;\;\;\frac{\frac{\left(\left(\tan x + \tan \varepsilon\right) \cdot \cos x\right) \cdot \left(\left(\tan x + \tan \varepsilon\right) \cdot \cos x\right) - \left(\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \sin x\right) \cdot \left(\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \sin x\right)}{\left(\tan x + \tan \varepsilon\right) \cdot \cos x + \left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \sin x}}{\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \cos x}\\ \mathbf{if}\;\varepsilon \le 1.4236706257213858 \cdot 10^{-17}:\\ \;\;\;\;\varepsilon + \left({\varepsilon}^{3} \cdot {x}^{2} + {\varepsilon}^{2} \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{{\left(\tan x\right)}^{3} + {\left(\tan \varepsilon\right)}^{3}}{\left(\tan \varepsilon \cdot \tan \varepsilon - \tan x \cdot \left(\tan \varepsilon - \tan x\right)\right) \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)} - \tan x\\ \end{array}\]

Error

Bits error versus x

Bits error versus eps

Target

Original37.6
Target14.9
Herbie15.1
\[\frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)}\]

Derivation

  1. Split input into 3 regimes
  2. if eps < -3.088211040495327e-21

    1. Initial program 29.9

      \[\tan \left(x + \varepsilon\right) - \tan x\]
    2. Using strategy rm
    3. Applied tan-quot29.8

      \[\leadsto \tan \left(x + \varepsilon\right) - \color{blue}{\frac{\sin x}{\cos x}}\]
    4. Applied tan-sum1.2

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \frac{\sin x}{\cos x}\]
    5. Applied frac-sub1.3

      \[\leadsto \color{blue}{\frac{\left(\tan x + \tan \varepsilon\right) \cdot \cos x - \left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \sin x}{\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \cos x}}\]
    6. Using strategy rm
    7. Applied flip--1.4

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

    if -3.088211040495327e-21 < eps < 1.4236706257213858e-17

    1. Initial program 46.3

      \[\tan \left(x + \varepsilon\right) - \tan x\]
    2. Taylor expanded around 0 30.4

      \[\leadsto \color{blue}{\varepsilon + \left({\varepsilon}^{3} \cdot {x}^{2} + {\varepsilon}^{2} \cdot x\right)}\]

    if 1.4236706257213858e-17 < eps

    1. Initial program 29.6

      \[\tan \left(x + \varepsilon\right) - \tan x\]
    2. Using strategy rm
    3. Applied tan-sum1.0

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x\]
    4. Using strategy rm
    5. Applied flip3-+1.2

      \[\leadsto \frac{\color{blue}{\frac{{\left(\tan x\right)}^{3} + {\left(\tan \varepsilon\right)}^{3}}{\tan x \cdot \tan x + \left(\tan \varepsilon \cdot \tan \varepsilon - \tan x \cdot \tan \varepsilon\right)}}}{1 - \tan x \cdot \tan \varepsilon} - \tan x\]
    6. Applied associate-/l/1.2

      \[\leadsto \color{blue}{\frac{{\left(\tan x\right)}^{3} + {\left(\tan \varepsilon\right)}^{3}}{\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan x + \left(\tan \varepsilon \cdot \tan \varepsilon - \tan x \cdot \tan \varepsilon\right)\right)}} - \tan x\]
    7. Applied simplify1.2

      \[\leadsto \frac{{\left(\tan x\right)}^{3} + {\left(\tan \varepsilon\right)}^{3}}{\color{blue}{\left(\tan \varepsilon \cdot \tan \varepsilon - \tan x \cdot \left(\tan \varepsilon - \tan x\right)\right) \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)}} - \tan x\]
  3. Recombined 3 regimes into one program.
  4. Removed slow pow expressions.

Runtime

Time bar (total: 3.0m)Debug logProfile

herbie shell --seed '#(1063154770 1824007522 645063331 41291047 494775821 1237684644)' 
(FPCore (x eps)
  :name "2tan (problem 3.3.2)"
  :herbie-expected 28

  :herbie-target
  (/ (sin eps) (* (cos x) (cos (+ x eps))))

  (- (tan (+ x eps)) (tan x)))