Average Error: 31.9 → 0.1
Time: 15.6s
Precision: binary64
\[\frac{x - \sin x}{x - \tan x} \]
\[\begin{array}{l} t_0 := x - \tan x\\ t_1 := \frac{-1}{t_0}\\ t_2 := \mathsf{fma}\left(1, \frac{x}{t_0}, \sin x \cdot t_1\right)\\ \mathbf{if}\;x \leq -0.004881470445787531:\\ \;\;\;\;t_2 + \mathsf{fma}\left(t_1, \sin x, \frac{1}{t_0} \cdot \sin x\right)\\ \mathbf{elif}\;x \leq 0.005566771948535619:\\ \;\;\;\;\mathsf{fma}\left(0.225, x \cdot x, 0.00024107142857142857 \cdot {x}^{6}\right) - 0.5\\ \mathbf{else}:\\ \;\;\;\;t_2 + \mathsf{expm1}\left(\mathsf{log1p}\left(0\right)\right)\\ \end{array} \]
\frac{x - \sin x}{x - \tan x}
\begin{array}{l}
t_0 := x - \tan x\\
t_1 := \frac{-1}{t_0}\\
t_2 := \mathsf{fma}\left(1, \frac{x}{t_0}, \sin x \cdot t_1\right)\\
\mathbf{if}\;x \leq -0.004881470445787531:\\
\;\;\;\;t_2 + \mathsf{fma}\left(t_1, \sin x, \frac{1}{t_0} \cdot \sin x\right)\\

\mathbf{elif}\;x \leq 0.005566771948535619:\\
\;\;\;\;\mathsf{fma}\left(0.225, x \cdot x, 0.00024107142857142857 \cdot {x}^{6}\right) - 0.5\\

\mathbf{else}:\\
\;\;\;\;t_2 + \mathsf{expm1}\left(\mathsf{log1p}\left(0\right)\right)\\


\end{array}
(FPCore (x) :precision binary64 (/ (- x (sin x)) (- x (tan x))))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (- x (tan x)))
        (t_1 (/ -1.0 t_0))
        (t_2 (fma 1.0 (/ x t_0) (* (sin x) t_1))))
   (if (<= x -0.004881470445787531)
     (+ t_2 (fma t_1 (sin x) (* (/ 1.0 t_0) (sin x))))
     (if (<= x 0.005566771948535619)
       (- (fma 0.225 (* x x) (* 0.00024107142857142857 (pow x 6.0))) 0.5)
       (+ t_2 (expm1 (log1p 0.0)))))))
double code(double x) {
	return (x - sin(x)) / (x - tan(x));
}
double code(double x) {
	double t_0 = x - tan(x);
	double t_1 = -1.0 / t_0;
	double t_2 = fma(1.0, (x / t_0), (sin(x) * t_1));
	double tmp;
	if (x <= -0.004881470445787531) {
		tmp = t_2 + fma(t_1, sin(x), ((1.0 / t_0) * sin(x)));
	} else if (x <= 0.005566771948535619) {
		tmp = fma(0.225, (x * x), (0.00024107142857142857 * pow(x, 6.0))) - 0.5;
	} else {
		tmp = t_2 + expm1(log1p(0.0));
	}
	return tmp;
}

Error

Bits error versus x

Derivation

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

    1. Initial program 0.1

      \[\frac{x - \sin x}{x - \tan x} \]
    2. Applied div-sub_binary640.1

      \[\leadsto \color{blue}{\frac{x}{x - \tan x} - \frac{\sin x}{x - \tan x}} \]
    3. Applied div-inv_binary640.1

      \[\leadsto \frac{x}{x - \tan x} - \color{blue}{\sin x \cdot \frac{1}{x - \tan x}} \]
    4. Applied *-un-lft-identity_binary640.1

      \[\leadsto \color{blue}{1 \cdot \frac{x}{x - \tan x}} - \sin x \cdot \frac{1}{x - \tan x} \]
    5. Applied prod-diff_binary640.1

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

    if -0.0048814704457875308 < x < 0.00556677194853561885

    1. Initial program 63.3

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

      \[\leadsto \color{blue}{\left(0.00024107142857142857 \cdot {x}^{6} + 0.225 \cdot {x}^{2}\right) - \left(0.009642857142857142 \cdot {x}^{4} + 0.5\right)} \]
    3. Simplified0.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.225, x \cdot x, 0.00024107142857142857 \cdot {x}^{6}\right) - \mathsf{fma}\left(0.009642857142857142, {x}^{4}, 0.5\right)} \]
    4. Taylor expanded in x around 0 0.1

      \[\leadsto \mathsf{fma}\left(0.225, x \cdot x, 0.00024107142857142857 \cdot {x}^{6}\right) - \color{blue}{0.5} \]

    if 0.00556677194853561885 < x

    1. Initial program 0.1

      \[\frac{x - \sin x}{x - \tan x} \]
    2. Applied div-sub_binary640.1

      \[\leadsto \color{blue}{\frac{x}{x - \tan x} - \frac{\sin x}{x - \tan x}} \]
    3. Applied div-inv_binary640.1

      \[\leadsto \frac{x}{x - \tan x} - \color{blue}{\sin x \cdot \frac{1}{x - \tan x}} \]
    4. Applied *-un-lft-identity_binary640.1

      \[\leadsto \color{blue}{1 \cdot \frac{x}{x - \tan x}} - \sin x \cdot \frac{1}{x - \tan x} \]
    5. Applied prod-diff_binary640.1

      \[\leadsto \color{blue}{\mathsf{fma}\left(1, \frac{x}{x - \tan x}, -\frac{1}{x - \tan x} \cdot \sin x\right) + \mathsf{fma}\left(-\frac{1}{x - \tan x}, \sin x, \frac{1}{x - \tan x} \cdot \sin x\right)} \]
    6. Applied expm1-log1p-u_binary640.1

      \[\leadsto \mathsf{fma}\left(1, \frac{x}{x - \tan x}, -\frac{1}{x - \tan x} \cdot \sin x\right) + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{fma}\left(-\frac{1}{x - \tan x}, \sin x, \frac{1}{x - \tan x} \cdot \sin x\right)\right)\right)} \]
    7. Simplified0.1

      \[\leadsto \mathsf{fma}\left(1, \frac{x}{x - \tan x}, -\frac{1}{x - \tan x} \cdot \sin x\right) + \mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(0\right)}\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.004881470445787531:\\ \;\;\;\;\mathsf{fma}\left(1, \frac{x}{x - \tan x}, \sin x \cdot \frac{-1}{x - \tan x}\right) + \mathsf{fma}\left(\frac{-1}{x - \tan x}, \sin x, \frac{1}{x - \tan x} \cdot \sin x\right)\\ \mathbf{elif}\;x \leq 0.005566771948535619:\\ \;\;\;\;\mathsf{fma}\left(0.225, x \cdot x, 0.00024107142857142857 \cdot {x}^{6}\right) - 0.5\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, \frac{x}{x - \tan x}, \sin x \cdot \frac{-1}{x - \tan x}\right) + \mathsf{expm1}\left(\mathsf{log1p}\left(0\right)\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022076 
(FPCore (x)
  :name "sintan (problem 3.4.5)"
  :precision binary64
  (/ (- x (sin x)) (- x (tan x))))