Average Error: 31.6 → 0.0
Time: 13.0s
Precision: binary64
\[\frac{x - \sin x}{x - \tan x} \]
\[\begin{array}{l} t_0 := x - \tan x\\ t_1 := \frac{x}{t_0}\\ t_2 := \frac{\sin x}{t_0}\\ \mathbf{if}\;x \leq -0.035:\\ \;\;\;\;\mathsf{fma}\left({t_1}^{3} - {t_2}^{3}, \frac{1}{\mathsf{fma}\left(t_2, \frac{1}{t_0} \cdot \left(x + \sin x\right), {t_1}^{2}\right)}, \mathsf{fma}\left(\frac{-1}{t_0}, \sin x, t_2\right)\right)\\ \mathbf{elif}\;x \leq 0.0305:\\ \;\;\;\;\left(-0.009642857142857142 \cdot {x}^{4} + 0.225 \cdot {x}^{2}\right) + -0.5\\ \mathbf{else}:\\ \;\;\;\;{\log \left(1 + \mathsf{expm1}\left(\frac{t_0}{x - \sin x}\right)\right)}^{-1}\\ \end{array} \]
(FPCore (x) :precision binary64 (/ (- x (sin x)) (- x (tan x))))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (- x (tan x))) (t_1 (/ x t_0)) (t_2 (/ (sin x) t_0)))
   (if (<= x -0.035)
     (fma
      (- (pow t_1 3.0) (pow t_2 3.0))
      (/ 1.0 (fma t_2 (* (/ 1.0 t_0) (+ x (sin x))) (pow t_1 2.0)))
      (fma (/ -1.0 t_0) (sin x) t_2))
     (if (<= x 0.0305)
       (+ (+ (* -0.009642857142857142 (pow x 4.0)) (* 0.225 (pow x 2.0))) -0.5)
       (pow (log (+ 1.0 (expm1 (/ t_0 (- x (sin x)))))) -1.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 = x / t_0;
	double t_2 = sin(x) / t_0;
	double tmp;
	if (x <= -0.035) {
		tmp = fma((pow(t_1, 3.0) - pow(t_2, 3.0)), (1.0 / fma(t_2, ((1.0 / t_0) * (x + sin(x))), pow(t_1, 2.0))), fma((-1.0 / t_0), sin(x), t_2));
	} else if (x <= 0.0305) {
		tmp = ((-0.009642857142857142 * pow(x, 4.0)) + (0.225 * pow(x, 2.0))) + -0.5;
	} else {
		tmp = pow(log((1.0 + expm1((t_0 / (x - sin(x)))))), -1.0);
	}
	return tmp;
}
function code(x)
	return Float64(Float64(x - sin(x)) / Float64(x - tan(x)))
end
function code(x)
	t_0 = Float64(x - tan(x))
	t_1 = Float64(x / t_0)
	t_2 = Float64(sin(x) / t_0)
	tmp = 0.0
	if (x <= -0.035)
		tmp = fma(Float64((t_1 ^ 3.0) - (t_2 ^ 3.0)), Float64(1.0 / fma(t_2, Float64(Float64(1.0 / t_0) * Float64(x + sin(x))), (t_1 ^ 2.0))), fma(Float64(-1.0 / t_0), sin(x), t_2));
	elseif (x <= 0.0305)
		tmp = Float64(Float64(Float64(-0.009642857142857142 * (x ^ 4.0)) + Float64(0.225 * (x ^ 2.0))) + -0.5);
	else
		tmp = log(Float64(1.0 + expm1(Float64(t_0 / Float64(x - sin(x)))))) ^ -1.0;
	end
	return tmp
end
code[x_] := N[(N[(x - N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[(x - N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := Block[{t$95$0 = N[(x - N[Tan[x], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x / t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(N[Sin[x], $MachinePrecision] / t$95$0), $MachinePrecision]}, If[LessEqual[x, -0.035], N[(N[(N[Power[t$95$1, 3.0], $MachinePrecision] - N[Power[t$95$2, 3.0], $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(t$95$2 * N[(N[(1.0 / t$95$0), $MachinePrecision] * N[(x + N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Power[t$95$1, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(-1.0 / t$95$0), $MachinePrecision] * N[Sin[x], $MachinePrecision] + t$95$2), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.0305], N[(N[(N[(-0.009642857142857142 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + N[(0.225 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision], N[Power[N[Log[N[(1.0 + N[(Exp[N[(t$95$0 / N[(x - N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], -1.0], $MachinePrecision]]]]]]
\frac{x - \sin x}{x - \tan x}
\begin{array}{l}
t_0 := x - \tan x\\
t_1 := \frac{x}{t_0}\\
t_2 := \frac{\sin x}{t_0}\\
\mathbf{if}\;x \leq -0.035:\\
\;\;\;\;\mathsf{fma}\left({t_1}^{3} - {t_2}^{3}, \frac{1}{\mathsf{fma}\left(t_2, \frac{1}{t_0} \cdot \left(x + \sin x\right), {t_1}^{2}\right)}, \mathsf{fma}\left(\frac{-1}{t_0}, \sin x, t_2\right)\right)\\

\mathbf{elif}\;x \leq 0.0305:\\
\;\;\;\;\left(-0.009642857142857142 \cdot {x}^{4} + 0.225 \cdot {x}^{2}\right) + -0.5\\

\mathbf{else}:\\
\;\;\;\;{\log \left(1 + \mathsf{expm1}\left(\frac{t_0}{x - \sin x}\right)\right)}^{-1}\\


\end{array}

Error

Bits error versus x

Derivation

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

    1. Initial program 0.1

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

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

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

    if -0.035000000000000003 < x < 0.030499999999999999

    1. Initial program 63.1

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

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

    if 0.030499999999999999 < x

    1. Initial program 0.0

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

      \[\leadsto \color{blue}{{\left(\frac{x - \tan x}{x - \sin x}\right)}^{-1}} \]
    3. Applied egg-rr0.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.035:\\ \;\;\;\;\mathsf{fma}\left({\left(\frac{x}{x - \tan x}\right)}^{3} - {\left(\frac{\sin x}{x - \tan x}\right)}^{3}, \frac{1}{\mathsf{fma}\left(\frac{\sin x}{x - \tan x}, \frac{1}{x - \tan x} \cdot \left(x + \sin x\right), {\left(\frac{x}{x - \tan x}\right)}^{2}\right)}, \mathsf{fma}\left(\frac{-1}{x - \tan x}, \sin x, \frac{\sin x}{x - \tan x}\right)\right)\\ \mathbf{elif}\;x \leq 0.0305:\\ \;\;\;\;\left(-0.009642857142857142 \cdot {x}^{4} + 0.225 \cdot {x}^{2}\right) + -0.5\\ \mathbf{else}:\\ \;\;\;\;{\log \left(1 + \mathsf{expm1}\left(\frac{x - \tan x}{x - \sin x}\right)\right)}^{-1}\\ \end{array} \]

Reproduce

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