Average Error: 31.7 → 0.1
Time: 27.3s
Precision: binary64
Cost: 26436
\[\frac{x - \sin x}{x - \tan x} \]
\[\begin{array}{l} t_0 := \tan x - x\\ \mathbf{if}\;x \leq -0.0054:\\ \;\;\;\;\mathsf{fma}\left(\sin x, \frac{1}{t_0}, \frac{x}{x - \tan x}\right)\\ \mathbf{elif}\;x \leq 0.0058:\\ \;\;\;\;\left(0.225 \cdot x\right) \cdot x - 0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin x}{t_0} - \frac{x}{t_0}\\ \end{array} \]
(FPCore (x) :precision binary64 (/ (- x (sin x)) (- x (tan x))))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (- (tan x) x)))
   (if (<= x -0.0054)
     (fma (sin x) (/ 1.0 t_0) (/ x (- x (tan x))))
     (if (<= x 0.0058)
       (- (* (* 0.225 x) x) 0.5)
       (- (/ (sin x) t_0) (/ x t_0))))))
double code(double x) {
	return (x - sin(x)) / (x - tan(x));
}
double code(double x) {
	double t_0 = tan(x) - x;
	double tmp;
	if (x <= -0.0054) {
		tmp = fma(sin(x), (1.0 / t_0), (x / (x - tan(x))));
	} else if (x <= 0.0058) {
		tmp = ((0.225 * x) * x) - 0.5;
	} else {
		tmp = (sin(x) / t_0) - (x / t_0);
	}
	return tmp;
}
function code(x)
	return Float64(Float64(x - sin(x)) / Float64(x - tan(x)))
end
function code(x)
	t_0 = Float64(tan(x) - x)
	tmp = 0.0
	if (x <= -0.0054)
		tmp = fma(sin(x), Float64(1.0 / t_0), Float64(x / Float64(x - tan(x))));
	elseif (x <= 0.0058)
		tmp = Float64(Float64(Float64(0.225 * x) * x) - 0.5);
	else
		tmp = Float64(Float64(sin(x) / t_0) - Float64(x / t_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[(N[Tan[x], $MachinePrecision] - x), $MachinePrecision]}, If[LessEqual[x, -0.0054], N[(N[Sin[x], $MachinePrecision] * N[(1.0 / t$95$0), $MachinePrecision] + N[(x / N[(x - N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.0058], N[(N[(N[(0.225 * x), $MachinePrecision] * x), $MachinePrecision] - 0.5), $MachinePrecision], N[(N[(N[Sin[x], $MachinePrecision] / t$95$0), $MachinePrecision] - N[(x / t$95$0), $MachinePrecision]), $MachinePrecision]]]]
\frac{x - \sin x}{x - \tan x}
\begin{array}{l}
t_0 := \tan x - x\\
\mathbf{if}\;x \leq -0.0054:\\
\;\;\;\;\mathsf{fma}\left(\sin x, \frac{1}{t_0}, \frac{x}{x - \tan x}\right)\\

\mathbf{elif}\;x \leq 0.0058:\\
\;\;\;\;\left(0.225 \cdot x\right) \cdot x - 0.5\\

\mathbf{else}:\\
\;\;\;\;\frac{\sin x}{t_0} - \frac{x}{t_0}\\


\end{array}

Error

Derivation

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

    1. Initial program 0.1

      \[\frac{x - \sin x}{x - \tan x} \]
    2. Simplified0.1

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

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

    if -0.0054000000000000003 < x < 0.0058

    1. Initial program 63.4

      \[\frac{x - \sin x}{x - \tan x} \]
    2. Simplified63.4

      \[\leadsto \color{blue}{\frac{\sin x - x}{\tan x - x}} \]
      Proof
    3. Taylor expanded in x around 0 0.0

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.225, x \cdot x, -0.5\right)} \]
      Proof
    5. Applied egg-rr0.0

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

    if 0.0058 < x

    1. Initial program 0.1

      \[\frac{x - \sin x}{x - \tan x} \]
    2. Simplified0.1

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

      \[\leadsto \color{blue}{\frac{\sin x}{\tan x - x} - \frac{x}{\tan x - x}} \]
  3. Recombined 3 regimes into one program.

Alternatives

Alternative 1
Error0.1
Cost20168
\[\begin{array}{l} t_0 := \tan x - x\\ t_1 := \frac{\sin x}{t_0} - \frac{x}{t_0}\\ \mathbf{if}\;x \leq -0.0049:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 0.0058:\\ \;\;\;\;\left(0.225 \cdot x\right) \cdot x - 0.5\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error0.1
Cost13512
\[\begin{array}{l} t_0 := \frac{x - \sin x}{x - \tan x}\\ \mathbf{if}\;x \leq -0.004:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.0054:\\ \;\;\;\;\left(0.225 \cdot x\right) \cdot x - 0.5\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error0.8
Cost6984
\[\begin{array}{l} \mathbf{if}\;x \leq -2.6:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 2.3:\\ \;\;\;\;\left(0.225 \cdot x\right) \cdot x - 0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{x - \tan x}\\ \end{array} \]
Alternative 4
Error0.8
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -2.6:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 2.6:\\ \;\;\;\;\left(0.225 \cdot x\right) \cdot x - 0.5\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 5
Error0.9
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -1.58:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 1.6:\\ \;\;\;\;-0.5\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 6
Error31.7
Cost64
\[-0.5 \]

Error

Reproduce

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