Average Error: 32.0 → 0.3
Time: 19.5s
Precision: binary64
Cost: 39752
\[\frac{x - \sin x}{x - \tan x} \]
\[\begin{array}{l} t_0 := \tan x - x\\ \mathbf{if}\;x \leq -130842.887112563:\\ \;\;\;\;\frac{1}{\frac{t_0}{\sin x - x}}\\ \mathbf{elif}\;x \leq 4.357524670288106 \cdot 10^{-5}:\\ \;\;\;\;x \cdot \left(x \cdot 0.225\right) + -0.5\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{\sin x}{{\tan x}^{2} - x \cdot x}, x + \tan x, \frac{-x}{t_0}\right)\\ \end{array} \]
(FPCore (x) :precision binary64 (/ (- x (sin x)) (- x (tan x))))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (- (tan x) x)))
   (if (<= x -130842.887112563)
     (/ 1.0 (/ t_0 (- (sin x) x)))
     (if (<= x 4.357524670288106e-5)
       (+ (* x (* x 0.225)) -0.5)
       (fma
        (/ (sin x) (- (pow (tan x) 2.0) (* x x)))
        (+ x (tan x))
        (/ (- 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 <= -130842.887112563) {
		tmp = 1.0 / (t_0 / (sin(x) - x));
	} else if (x <= 4.357524670288106e-5) {
		tmp = (x * (x * 0.225)) + -0.5;
	} else {
		tmp = fma((sin(x) / (pow(tan(x), 2.0) - (x * x))), (x + tan(x)), (-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 <= -130842.887112563)
		tmp = Float64(1.0 / Float64(t_0 / Float64(sin(x) - x)));
	elseif (x <= 4.357524670288106e-5)
		tmp = Float64(Float64(x * Float64(x * 0.225)) + -0.5);
	else
		tmp = fma(Float64(sin(x) / Float64((tan(x) ^ 2.0) - Float64(x * x))), Float64(x + tan(x)), Float64(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, -130842.887112563], N[(1.0 / N[(t$95$0 / N[(N[Sin[x], $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 4.357524670288106e-5], N[(N[(x * N[(x * 0.225), $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision], N[(N[(N[Sin[x], $MachinePrecision] / N[(N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision] - N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(x + N[Tan[x], $MachinePrecision]), $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 -130842.887112563:\\
\;\;\;\;\frac{1}{\frac{t_0}{\sin x - x}}\\

\mathbf{elif}\;x \leq 4.357524670288106 \cdot 10^{-5}:\\
\;\;\;\;x \cdot \left(x \cdot 0.225\right) + -0.5\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\sin x}{{\tan x}^{2} - x \cdot x}, x + \tan x, \frac{-x}{t_0}\right)\\


\end{array}

Error

Derivation

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

    1. Initial program 0.0

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

      \[\leadsto \color{blue}{\frac{\sin x - x}{\tan x - x}} \]
      Proof
      (/.f64 (-.f64 (sin.f64 x) x) (-.f64 (tan.f64 x) x)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= *-lft-identity_binary64 (*.f64 1 (/.f64 (-.f64 (sin.f64 x) x) (-.f64 (tan.f64 x) x)))): 0 points increase in error, 0 points decrease in error
      (*.f64 (Rewrite<= metadata-eval (/.f64 -1 -1)) (/.f64 (-.f64 (sin.f64 x) x) (-.f64 (tan.f64 x) x))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= times-frac_binary64 (/.f64 (*.f64 -1 (-.f64 (sin.f64 x) x)) (*.f64 -1 (-.f64 (tan.f64 x) x)))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 (-.f64 (sin.f64 x) x))) (*.f64 -1 (-.f64 (tan.f64 x) x))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= sub0-neg_binary64 (-.f64 0 (-.f64 (sin.f64 x) x))) (*.f64 -1 (-.f64 (tan.f64 x) x))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 0 (sin.f64 x)) x)) (*.f64 -1 (-.f64 (tan.f64 x) x))): 0 points increase in error, 0 points decrease in error
      (/.f64 (+.f64 (Rewrite<= neg-sub0_binary64 (neg.f64 (sin.f64 x))) x) (*.f64 -1 (-.f64 (tan.f64 x) x))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= +-commutative_binary64 (+.f64 x (neg.f64 (sin.f64 x)))) (*.f64 -1 (-.f64 (tan.f64 x) x))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= sub-neg_binary64 (-.f64 x (sin.f64 x))) (*.f64 -1 (-.f64 (tan.f64 x) x))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 x (sin.f64 x)) (Rewrite<= neg-mul-1_binary64 (neg.f64 (-.f64 (tan.f64 x) x)))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 x (sin.f64 x)) (Rewrite<= sub0-neg_binary64 (-.f64 0 (-.f64 (tan.f64 x) x)))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 x (sin.f64 x)) (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 0 (tan.f64 x)) x))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 x (sin.f64 x)) (+.f64 (Rewrite<= neg-sub0_binary64 (neg.f64 (tan.f64 x))) x)): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 x (sin.f64 x)) (Rewrite<= +-commutative_binary64 (+.f64 x (neg.f64 (tan.f64 x))))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 x (sin.f64 x)) (Rewrite<= sub-neg_binary64 (-.f64 x (tan.f64 x)))): 0 points increase in error, 0 points decrease in error
    3. Applied egg-rr0.0

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

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

    if -130842.887112562996 < x < 4.35752467028810601e-5

    1. Initial program 63.0

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

      \[\leadsto \color{blue}{\frac{\sin x - x}{\tan x - x}} \]
      Proof
      (/.f64 (-.f64 (sin.f64 x) x) (-.f64 (tan.f64 x) x)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= *-lft-identity_binary64 (*.f64 1 (/.f64 (-.f64 (sin.f64 x) x) (-.f64 (tan.f64 x) x)))): 0 points increase in error, 0 points decrease in error
      (*.f64 (Rewrite<= metadata-eval (/.f64 -1 -1)) (/.f64 (-.f64 (sin.f64 x) x) (-.f64 (tan.f64 x) x))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= times-frac_binary64 (/.f64 (*.f64 -1 (-.f64 (sin.f64 x) x)) (*.f64 -1 (-.f64 (tan.f64 x) x)))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 (-.f64 (sin.f64 x) x))) (*.f64 -1 (-.f64 (tan.f64 x) x))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= sub0-neg_binary64 (-.f64 0 (-.f64 (sin.f64 x) x))) (*.f64 -1 (-.f64 (tan.f64 x) x))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 0 (sin.f64 x)) x)) (*.f64 -1 (-.f64 (tan.f64 x) x))): 0 points increase in error, 0 points decrease in error
      (/.f64 (+.f64 (Rewrite<= neg-sub0_binary64 (neg.f64 (sin.f64 x))) x) (*.f64 -1 (-.f64 (tan.f64 x) x))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= +-commutative_binary64 (+.f64 x (neg.f64 (sin.f64 x)))) (*.f64 -1 (-.f64 (tan.f64 x) x))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= sub-neg_binary64 (-.f64 x (sin.f64 x))) (*.f64 -1 (-.f64 (tan.f64 x) x))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 x (sin.f64 x)) (Rewrite<= neg-mul-1_binary64 (neg.f64 (-.f64 (tan.f64 x) x)))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 x (sin.f64 x)) (Rewrite<= sub0-neg_binary64 (-.f64 0 (-.f64 (tan.f64 x) x)))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 x (sin.f64 x)) (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 0 (tan.f64 x)) x))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 x (sin.f64 x)) (+.f64 (Rewrite<= neg-sub0_binary64 (neg.f64 (tan.f64 x))) x)): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 x (sin.f64 x)) (Rewrite<= +-commutative_binary64 (+.f64 x (neg.f64 (tan.f64 x))))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 x (sin.f64 x)) (Rewrite<= sub-neg_binary64 (-.f64 x (tan.f64 x)))): 0 points increase in error, 0 points decrease in error
    3. Taylor expanded in x around 0 0.5

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, x \cdot 0.225, -0.5\right)} \]
      Proof
      (fma.f64 x (*.f64 x 9/40) -1/2): 0 points increase in error, 0 points decrease in error
      (fma.f64 x (*.f64 x 9/40) (Rewrite<= metadata-eval (neg.f64 1/2))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-neg_binary64 (-.f64 (*.f64 x (*.f64 x 9/40)) 1/2)): 0 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 x x) 9/40)) 1/2): 20 points increase in error, 6 points decrease in error
      (-.f64 (*.f64 (Rewrite<= unpow2_binary64 (pow.f64 x 2)) 9/40) 1/2): 1 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite<= *-commutative_binary64 (*.f64 9/40 (pow.f64 x 2))) 1/2): 0 points increase in error, 0 points decrease in error
    5. Applied egg-rr0.5

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

    if 4.35752467028810601e-5 < x

    1. Initial program 0.2

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

      \[\leadsto \color{blue}{\frac{\sin x - x}{\tan x - x}} \]
      Proof
      (/.f64 (-.f64 (sin.f64 x) x) (-.f64 (tan.f64 x) x)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= *-lft-identity_binary64 (*.f64 1 (/.f64 (-.f64 (sin.f64 x) x) (-.f64 (tan.f64 x) x)))): 0 points increase in error, 0 points decrease in error
      (*.f64 (Rewrite<= metadata-eval (/.f64 -1 -1)) (/.f64 (-.f64 (sin.f64 x) x) (-.f64 (tan.f64 x) x))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= times-frac_binary64 (/.f64 (*.f64 -1 (-.f64 (sin.f64 x) x)) (*.f64 -1 (-.f64 (tan.f64 x) x)))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 (-.f64 (sin.f64 x) x))) (*.f64 -1 (-.f64 (tan.f64 x) x))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= sub0-neg_binary64 (-.f64 0 (-.f64 (sin.f64 x) x))) (*.f64 -1 (-.f64 (tan.f64 x) x))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 0 (sin.f64 x)) x)) (*.f64 -1 (-.f64 (tan.f64 x) x))): 0 points increase in error, 0 points decrease in error
      (/.f64 (+.f64 (Rewrite<= neg-sub0_binary64 (neg.f64 (sin.f64 x))) x) (*.f64 -1 (-.f64 (tan.f64 x) x))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= +-commutative_binary64 (+.f64 x (neg.f64 (sin.f64 x)))) (*.f64 -1 (-.f64 (tan.f64 x) x))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= sub-neg_binary64 (-.f64 x (sin.f64 x))) (*.f64 -1 (-.f64 (tan.f64 x) x))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 x (sin.f64 x)) (Rewrite<= neg-mul-1_binary64 (neg.f64 (-.f64 (tan.f64 x) x)))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 x (sin.f64 x)) (Rewrite<= sub0-neg_binary64 (-.f64 0 (-.f64 (tan.f64 x) x)))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 x (sin.f64 x)) (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 0 (tan.f64 x)) x))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 x (sin.f64 x)) (+.f64 (Rewrite<= neg-sub0_binary64 (neg.f64 (tan.f64 x))) x)): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 x (sin.f64 x)) (Rewrite<= +-commutative_binary64 (+.f64 x (neg.f64 (tan.f64 x))))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 x (sin.f64 x)) (Rewrite<= sub-neg_binary64 (-.f64 x (tan.f64 x)))): 0 points increase in error, 0 points decrease in error
    3. Applied egg-rr0.4

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

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

Alternatives

Alternative 1
Error0.3
Cost26632
\[\begin{array}{l} t_0 := \sin x - x\\ \mathbf{if}\;x \leq -130842.887112563:\\ \;\;\;\;\frac{1}{\frac{\tan x - x}{t_0}}\\ \mathbf{elif}\;x \leq 4.357524670288106 \cdot 10^{-5}:\\ \;\;\;\;x \cdot \left(x \cdot 0.225\right) + -0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{\mathsf{fma}\left(\sin x, \frac{1}{\cos x}, -x\right)}{t_0}}\\ \end{array} \]
Alternative 2
Error0.3
Cost13640
\[\begin{array}{l} t_0 := \frac{1}{\frac{\tan x - x}{\sin x - x}}\\ \mathbf{if}\;x \leq -130842.887112563:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4.357524670288106 \cdot 10^{-5}:\\ \;\;\;\;x \cdot \left(x \cdot 0.225\right) + -0.5\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error0.5
Cost13512
\[\begin{array}{l} t_0 := 1 + \frac{\tan x - \sin x}{x}\\ \mathbf{if}\;x \leq -130842.887112563:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.5362484084229574:\\ \;\;\;\;x \cdot \left(x \cdot 0.225\right) + -0.5\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error0.3
Cost13512
\[\begin{array}{l} t_0 := \frac{\sin x - x}{\tan x - x}\\ \mathbf{if}\;x \leq -130842.887112563:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4.357524670288106 \cdot 10^{-5}:\\ \;\;\;\;x \cdot \left(x \cdot 0.225\right) + -0.5\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error0.8
Cost7176
\[\begin{array}{l} t_0 := \tan x - x\\ \mathbf{if}\;x \leq -130842.887112563:\\ \;\;\;\;\frac{-x}{t_0}\\ \mathbf{elif}\;x \leq 0.5362484084229574:\\ \;\;\;\;x \cdot \left(x \cdot 0.225\right) + -0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{t_0}{-x}}\\ \end{array} \]
Alternative 6
Error0.8
Cost7048
\[\begin{array}{l} t_0 := \frac{-x}{\tan x - x}\\ \mathbf{if}\;x \leq -130842.887112563:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.5362484084229574:\\ \;\;\;\;x \cdot \left(x \cdot 0.225\right) + -0.5\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error0.8
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -130842.887112563:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 0.5362484084229574:\\ \;\;\;\;x \cdot \left(x \cdot 0.225\right) + -0.5\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 8
Error1.0
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -130842.887112563:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 0.5362484084229574:\\ \;\;\;\;-0.5\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 9
Error32.6
Cost64
\[1 \]

Error

Reproduce

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