Average Error: 30.8 → 0.1
Time: 12.8s
Precision: binary64
\[\frac{x - \sin x}{x - \tan x} \]
\[\begin{array}{l} t_0 := x - \tan x\\ \mathbf{if}\;x \leq -0.005033392592531496:\\ \;\;\;\;\frac{x}{t_0} - \frac{\sin x}{t_0}\\ \mathbf{elif}\;x \leq 0.005151709527736681:\\ \;\;\;\;\mathsf{fma}\left(0.225, x \cdot x, -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x - \sin x}{t_0}\right)\right)\\ \end{array} \]
\frac{x - \sin x}{x - \tan x}
\begin{array}{l}
t_0 := x - \tan x\\
\mathbf{if}\;x \leq -0.005033392592531496:\\
\;\;\;\;\frac{x}{t_0} - \frac{\sin x}{t_0}\\

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

\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x - \sin x}{t_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))))
   (if (<= x -0.005033392592531496)
     (- (/ x t_0) (/ (sin x) t_0))
     (if (<= x 0.005151709527736681)
       (fma 0.225 (* x x) -0.5)
       (expm1 (log1p (/ (- x (sin x)) t_0)))))))
double code(double x) {
	return (x - sin(x)) / (x - tan(x));
}
double code(double x) {
	double t_0 = x - tan(x);
	double tmp;
	if (x <= -0.005033392592531496) {
		tmp = (x / t_0) - (sin(x) / t_0);
	} else if (x <= 0.005151709527736681) {
		tmp = fma(0.225, (x * x), -0.5);
	} else {
		tmp = expm1(log1p((x - sin(x)) / t_0));
	}
	return tmp;
}

Error

Bits error versus x

Derivation

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

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

    if -0.00503339259253149634 < x < 0.00515170952773668072

    1. Initial program 63.3

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

      \[\leadsto \color{blue}{0.225 \cdot {x}^{2} - 0.5} \]
    3. Simplified0.0

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

    if 0.00515170952773668072 < x

    1. Initial program 0.1

      \[\frac{x - \sin x}{x - \tan x} \]
    2. Applied expm1-log1p-u_binary640.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.005033392592531496:\\ \;\;\;\;\frac{x}{x - \tan x} - \frac{\sin x}{x - \tan x}\\ \mathbf{elif}\;x \leq 0.005151709527736681:\\ \;\;\;\;\mathsf{fma}\left(0.225, x \cdot x, -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x - \sin x}{x - \tan x}\right)\right)\\ \end{array} \]

Reproduce

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