Average Error: 31.2 → 0.6
Time: 11.8s
Precision: binary64
\[\frac{x - \sin x}{x - \tan x} \]
\[\begin{array}{l} \mathbf{if}\;x \leq -3367994.866451633:\\ \;\;\;\;1 + \frac{\tan x - \sin x}{x}\\ \mathbf{elif}\;x \leq 1.4775726691068876 \cdot 10^{-10}:\\ \;\;\;\;\left(x \cdot x\right) \cdot \mathsf{fma}\left(x \cdot x, -0.009642857142857142, 0.225\right) + -0.5\\ \mathbf{else}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x - \sin x}{x - \tan x}\right)\right)\\ \end{array} \]
(FPCore (x) :precision binary64 (/ (- x (sin x)) (- x (tan x))))
(FPCore (x)
 :precision binary64
 (if (<= x -3367994.866451633)
   (+ 1.0 (/ (- (tan x) (sin x)) x))
   (if (<= x 1.4775726691068876e-10)
     (+ (* (* x x) (fma (* x x) -0.009642857142857142 0.225)) -0.5)
     (expm1 (log1p (/ (- x (sin x)) (- x (tan x))))))))
double code(double x) {
	return (x - sin(x)) / (x - tan(x));
}
double code(double x) {
	double tmp;
	if (x <= -3367994.866451633) {
		tmp = 1.0 + ((tan(x) - sin(x)) / x);
	} else if (x <= 1.4775726691068876e-10) {
		tmp = ((x * x) * fma((x * x), -0.009642857142857142, 0.225)) + -0.5;
	} else {
		tmp = expm1(log1p(((x - sin(x)) / (x - tan(x)))));
	}
	return tmp;
}
function code(x)
	return Float64(Float64(x - sin(x)) / Float64(x - tan(x)))
end
function code(x)
	tmp = 0.0
	if (x <= -3367994.866451633)
		tmp = Float64(1.0 + Float64(Float64(tan(x) - sin(x)) / x));
	elseif (x <= 1.4775726691068876e-10)
		tmp = Float64(Float64(Float64(x * x) * fma(Float64(x * x), -0.009642857142857142, 0.225)) + -0.5);
	else
		tmp = expm1(log1p(Float64(Float64(x - sin(x)) / Float64(x - tan(x)))));
	end
	return tmp
end
code[x_] := N[(N[(x - N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[(x - N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := If[LessEqual[x, -3367994.866451633], N[(1.0 + N[(N[(N[Tan[x], $MachinePrecision] - N[Sin[x], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.4775726691068876e-10], N[(N[(N[(x * x), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * -0.009642857142857142 + 0.225), $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision], N[(Exp[N[Log[1 + N[(N[(x - N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[(x - N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]]]
\frac{x - \sin x}{x - \tan x}
\begin{array}{l}
\mathbf{if}\;x \leq -3367994.866451633:\\
\;\;\;\;1 + \frac{\tan x - \sin x}{x}\\

\mathbf{elif}\;x \leq 1.4775726691068876 \cdot 10^{-10}:\\
\;\;\;\;\left(x \cdot x\right) \cdot \mathsf{fma}\left(x \cdot x, -0.009642857142857142, 0.225\right) + -0.5\\

\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x - \sin x}{x - \tan x}\right)\right)\\


\end{array}

Error

Derivation

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

    1. Initial program 0.0

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

      \[\leadsto \color{blue}{\left(1 + -1 \cdot \frac{\sin x}{x}\right) - -1 \cdot \frac{\sin x}{\cos x \cdot x}} \]
    3. Simplified0.0

      \[\leadsto \color{blue}{1 + \frac{\frac{\sin x}{\cos x} - \sin x}{x}} \]
    4. Applied egg-rr0.0

      \[\leadsto 1 + \frac{\color{blue}{\tan x} - \sin x}{x} \]

    if -3367994.8664516332 < x < 1.4775726691068876e-10

    1. Initial program 62.7

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

      \[\leadsto \color{blue}{\left(0.225 \cdot {x}^{2} + -0.009642857142857142 \cdot {x}^{4}\right) - 0.5} \]
    3. Taylor expanded in x around 0 0.8

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

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

    if 1.4775726691068876e-10 < x

    1. Initial program 0.9

      \[\frac{x - \sin x}{x - \tan x} \]
    2. Applied egg-rr0.9

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

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

Reproduce

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