?

Average Accuracy: 42.0% → 98.3%
Time: 20.6s
Precision: binary64
Cost: 59208

?

\[\tan \left(x + \varepsilon\right) - \tan x \]
\[\begin{array}{l} t_0 := \tan x + \tan \varepsilon\\ t_1 := \tan x \cdot \tan \varepsilon\\ t_2 := 1 - t_1\\ \mathbf{if}\;\varepsilon \leq -3.35 \cdot 10^{-9}:\\ \;\;\;\;\mathsf{fma}\left(t_0, \frac{1}{t_2}, -\tan x\right)\\ \mathbf{elif}\;\varepsilon \leq 1.65 \cdot 10^{-39}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0 \cdot \cos x + \sin x \cdot \left(t_1 + -1\right)}{t_2 \cdot \cos x}\\ \end{array} \]
(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (+ (tan x) (tan eps)))
        (t_1 (* (tan x) (tan eps)))
        (t_2 (- 1.0 t_1)))
   (if (<= eps -3.35e-9)
     (fma t_0 (/ 1.0 t_2) (- (tan x)))
     (if (<= eps 1.65e-39)
       (+ eps (* eps (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))
       (/ (+ (* t_0 (cos x)) (* (sin x) (+ t_1 -1.0))) (* t_2 (cos x)))))))
double code(double x, double eps) {
	return tan((x + eps)) - tan(x);
}
double code(double x, double eps) {
	double t_0 = tan(x) + tan(eps);
	double t_1 = tan(x) * tan(eps);
	double t_2 = 1.0 - t_1;
	double tmp;
	if (eps <= -3.35e-9) {
		tmp = fma(t_0, (1.0 / t_2), -tan(x));
	} else if (eps <= 1.65e-39) {
		tmp = eps + (eps * (pow(sin(x), 2.0) / pow(cos(x), 2.0)));
	} else {
		tmp = ((t_0 * cos(x)) + (sin(x) * (t_1 + -1.0))) / (t_2 * cos(x));
	}
	return tmp;
}
function code(x, eps)
	return Float64(tan(Float64(x + eps)) - tan(x))
end
function code(x, eps)
	t_0 = Float64(tan(x) + tan(eps))
	t_1 = Float64(tan(x) * tan(eps))
	t_2 = Float64(1.0 - t_1)
	tmp = 0.0
	if (eps <= -3.35e-9)
		tmp = fma(t_0, Float64(1.0 / t_2), Float64(-tan(x)));
	elseif (eps <= 1.65e-39)
		tmp = Float64(eps + Float64(eps * Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0))));
	else
		tmp = Float64(Float64(Float64(t_0 * cos(x)) + Float64(sin(x) * Float64(t_1 + -1.0))) / Float64(t_2 * cos(x)));
	end
	return tmp
end
code[x_, eps_] := N[(N[Tan[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]
code[x_, eps_] := Block[{t$95$0 = N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(1.0 - t$95$1), $MachinePrecision]}, If[LessEqual[eps, -3.35e-9], N[(t$95$0 * N[(1.0 / t$95$2), $MachinePrecision] + (-N[Tan[x], $MachinePrecision])), $MachinePrecision], If[LessEqual[eps, 1.65e-39], N[(eps + N[(eps * N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(t$95$0 * N[Cos[x], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[(t$95$1 + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(t$95$2 * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
t_0 := \tan x + \tan \varepsilon\\
t_1 := \tan x \cdot \tan \varepsilon\\
t_2 := 1 - t_1\\
\mathbf{if}\;\varepsilon \leq -3.35 \cdot 10^{-9}:\\
\;\;\;\;\mathsf{fma}\left(t_0, \frac{1}{t_2}, -\tan x\right)\\

\mathbf{elif}\;\varepsilon \leq 1.65 \cdot 10^{-39}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\

\mathbf{else}:\\
\;\;\;\;\frac{t_0 \cdot \cos x + \sin x \cdot \left(t_1 + -1\right)}{t_2 \cdot \cos x}\\


\end{array}

Error?

Target

Original42.0%
Target75.9%
Herbie98.3%
\[\frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)} \]

Derivation?

  1. Split input into 3 regimes
  2. if eps < -3.34999999999999981e-9

    1. Initial program 49.3%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Applied egg-rr99.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]
      Proof

      [Start]49.3

      \[ \tan \left(x + \varepsilon\right) - \tan x \]

      tan-sum [=>]99.6

      \[ \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]

      div-inv [=>]99.6

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

      fma-neg [=>]99.7

      \[ \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)} \]

    if -3.34999999999999981e-9 < eps < 1.64999999999999992e-39

    1. Initial program 24.2%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Taylor expanded in eps around 0 99.4%

      \[\leadsto \color{blue}{\varepsilon \cdot \left(1 - -1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)} \]
    3. Simplified99.5%

      \[\leadsto \color{blue}{\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}} \]
      Proof

      [Start]99.4

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

      cancel-sign-sub-inv [=>]99.4

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

      metadata-eval [=>]99.4

      \[ \varepsilon \cdot \left(1 + \color{blue}{1} \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right) \]

      *-lft-identity [=>]99.4

      \[ \varepsilon \cdot \left(1 + \color{blue}{\frac{{\sin x}^{2}}{{\cos x}^{2}}}\right) \]

      distribute-lft-in [=>]99.5

      \[ \color{blue}{\varepsilon \cdot 1 + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}} \]

      *-rgt-identity [=>]99.5

      \[ \color{blue}{\varepsilon} + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}} \]

    if 1.64999999999999992e-39 < eps

    1. Initial program 48.6%

      \[\tan \left(x + \varepsilon\right) - \tan x \]
    2. Applied egg-rr99.4%

      \[\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}} \]
      Proof

      [Start]48.6

      \[ \tan \left(x + \varepsilon\right) - \tan x \]

      tan-sum [=>]99.3

      \[ \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x \]

      tan-quot [=>]99.1

      \[ \frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \color{blue}{\frac{\sin x}{\cos x}} \]

      frac-sub [=>]99.4

      \[ \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}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \leq -3.35 \cdot 10^{-9}:\\ \;\;\;\;\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)\\ \mathbf{elif}\;\varepsilon \leq 1.65 \cdot 10^{-39}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\tan x + \tan \varepsilon\right) \cdot \cos x + \sin x \cdot \left(\tan x \cdot \tan \varepsilon + -1\right)}{\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \cos x}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy98.3%
Cost39433
\[\begin{array}{l} \mathbf{if}\;\varepsilon \leq -2.8 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 1.65 \cdot 10^{-39}\right):\\ \;\;\;\;\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)\\ \mathbf{else}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\ \end{array} \]
Alternative 2
Accuracy98.3%
Cost32969
\[\begin{array}{l} \mathbf{if}\;\varepsilon \leq -2.9 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 1.65 \cdot 10^{-39}\right):\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\ \mathbf{else}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\ \end{array} \]
Alternative 3
Accuracy98.3%
Cost32968
\[\begin{array}{l} t_0 := \tan x + \tan \varepsilon\\ t_1 := 1 - \tan x \cdot \tan \varepsilon\\ \mathbf{if}\;\varepsilon \leq -2.4 \cdot 10^{-9}:\\ \;\;\;\;t_0 \cdot \frac{1}{t_1} - \tan x\\ \mathbf{elif}\;\varepsilon \leq 1.65 \cdot 10^{-39}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{t_1} - \tan x\\ \end{array} \]
Alternative 4
Accuracy76.8%
Cost26441
\[\begin{array}{l} \mathbf{if}\;\varepsilon \leq -0.000125 \lor \neg \left(\varepsilon \leq 0.00029\right):\\ \;\;\;\;\tan \varepsilon - \tan x\\ \mathbf{else}:\\ \;\;\;\;\varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\\ \end{array} \]
Alternative 5
Accuracy76.8%
Cost26441
\[\begin{array}{l} \mathbf{if}\;\varepsilon \leq -0.00025 \lor \neg \left(\varepsilon \leq 0.00021\right):\\ \;\;\;\;\tan \varepsilon - \tan x\\ \mathbf{else}:\\ \;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\ \end{array} \]
Alternative 6
Accuracy57.7%
Cost6464
\[\tan \varepsilon \]
Alternative 7
Accuracy4.2%
Cost64
\[0 \]
Alternative 8
Accuracy30.5%
Cost64
\[\varepsilon \]

Error

Reproduce?

herbie shell --seed 2023153 
(FPCore (x eps)
  :name "2tan (problem 3.3.2)"
  :precision binary64

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

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