Average Error: 31.0 → 0.2
Time: 11.7s
Precision: binary64
\[\frac{x - \sin x}{x - \tan x} \]
\[\begin{array}{l} \mathbf{if}\;x \leq -0.09740715512336516:\\ \;\;\;\;\frac{x - \sin x}{x - \tan x}\\ \mathbf{elif}\;x \leq 4.99533306627316:\\ \;\;\;\;\mathsf{fma}\left(0.225, x \cdot x, 0.00024107142857142857 \cdot {x}^{6}\right) - \mathsf{fma}\left(0.009642857142857142, {x}^{4}, 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;0 + \left(\frac{\tan x}{x} + \left(1 - \frac{\sin x}{x}\right)\right)\\ \end{array} \]
\frac{x - \sin x}{x - \tan x}
\begin{array}{l}
\mathbf{if}\;x \leq -0.09740715512336516:\\
\;\;\;\;\frac{x - \sin x}{x - \tan x}\\

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

\mathbf{else}:\\
\;\;\;\;0 + \left(\frac{\tan x}{x} + \left(1 - \frac{\sin x}{x}\right)\right)\\


\end{array}
(FPCore (x) :precision binary64 (/ (- x (sin x)) (- x (tan x))))
(FPCore (x)
 :precision binary64
 (if (<= x -0.09740715512336516)
   (/ (- x (sin x)) (- x (tan x)))
   (if (<= x 4.99533306627316)
     (-
      (fma 0.225 (* x x) (* 0.00024107142857142857 (pow x 6.0)))
      (fma 0.009642857142857142 (pow x 4.0) 0.5))
     (+ 0.0 (+ (/ (tan x) x) (- 1.0 (/ (sin x) x)))))))
double code(double x) {
	return (x - sin(x)) / (x - tan(x));
}
double code(double x) {
	double tmp;
	if (x <= -0.09740715512336516) {
		tmp = (x - sin(x)) / (x - tan(x));
	} else if (x <= 4.99533306627316) {
		tmp = fma(0.225, (x * x), (0.00024107142857142857 * pow(x, 6.0))) - fma(0.009642857142857142, pow(x, 4.0), 0.5);
	} else {
		tmp = 0.0 + ((tan(x) / x) + (1.0 - (sin(x) / x)));
	}
	return tmp;
}

Error

Bits error versus x

Derivation

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

    1. Initial program 0.0

      \[\frac{x - \sin x}{x - \tan x} \]

    if -0.0974071551233651606 < x < 4.9953330662731599

    1. Initial program 62.9

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

      \[\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.1

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

    if 4.9953330662731599 < x

    1. Initial program 0.0

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

      \[\leadsto \color{blue}{\left(\frac{\sin x}{\cos x \cdot x} + 1\right) - \frac{\sin x}{x}} \]
    3. Applied egg-rr0.5

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

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

Reproduce

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