Average Error: 31.1 → 0.0
Time: 21.0s
Precision: binary64
Cost: 14088
\[\frac{x - \sin x}{x - \tan x} \]
\[\begin{array}{l} t_0 := \frac{x - \sin x}{x - \tan x}\\ \mathbf{if}\;x \leq -0.086:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.088:\\ \;\;\;\;\left({x}^{4} \cdot \mathsf{fma}\left(0.00024107142857142857, x \cdot x, -0.009642857142857142\right) + \left(x \cdot x\right) \cdot 0.225\right) + -0.5\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
(FPCore (x) :precision binary64 (/ (- x (sin x)) (- x (tan x))))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (/ (- x (sin x)) (- x (tan x)))))
   (if (<= x -0.086)
     t_0
     (if (<= x 0.088)
       (+
        (+
         (*
          (pow x 4.0)
          (fma 0.00024107142857142857 (* x x) -0.009642857142857142))
         (* (* x x) 0.225))
        -0.5)
       t_0))))
double code(double x) {
	return (x - sin(x)) / (x - tan(x));
}
double code(double x) {
	double t_0 = (x - sin(x)) / (x - tan(x));
	double tmp;
	if (x <= -0.086) {
		tmp = t_0;
	} else if (x <= 0.088) {
		tmp = ((pow(x, 4.0) * fma(0.00024107142857142857, (x * x), -0.009642857142857142)) + ((x * x) * 0.225)) + -0.5;
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(x)
	return Float64(Float64(x - sin(x)) / Float64(x - tan(x)))
end
function code(x)
	t_0 = Float64(Float64(x - sin(x)) / Float64(x - tan(x)))
	tmp = 0.0
	if (x <= -0.086)
		tmp = t_0;
	elseif (x <= 0.088)
		tmp = Float64(Float64(Float64((x ^ 4.0) * fma(0.00024107142857142857, Float64(x * x), -0.009642857142857142)) + Float64(Float64(x * x) * 0.225)) + -0.5);
	else
		tmp = 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[(x - N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[(x - N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -0.086], t$95$0, If[LessEqual[x, 0.088], N[(N[(N[(N[Power[x, 4.0], $MachinePrecision] * N[(0.00024107142857142857 * N[(x * x), $MachinePrecision] + -0.009642857142857142), $MachinePrecision]), $MachinePrecision] + N[(N[(x * x), $MachinePrecision] * 0.225), $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision], t$95$0]]]
\frac{x - \sin x}{x - \tan x}
\begin{array}{l}
t_0 := \frac{x - \sin x}{x - \tan x}\\
\mathbf{if}\;x \leq -0.086:\\
\;\;\;\;t_0\\

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

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

Error

Derivation

  1. Split input into 2 regimes
  2. if x < -0.085999999999999993 or 0.087999999999999995 < x

    1. Initial program 0.0

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

    if -0.085999999999999993 < x < 0.087999999999999995

    1. Initial program 63.1

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

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

      \[\leadsto \color{blue}{\left(0.225 \cdot {x}^{2} + \left(-0.009642857142857142 \cdot {x}^{4} + 0.00024107142857142857 \cdot {x}^{6}\right)\right) - 0.5} \]
    4. Applied egg-rr0.0

      \[\leadsto \left(\color{blue}{\left(0 + x \cdot \left(x \cdot 0.225\right)\right)} + \left(-0.009642857142857142 \cdot {x}^{4} + 0.00024107142857142857 \cdot {x}^{6}\right)\right) - 0.5 \]
    5. Simplified0.0

      \[\leadsto \left(\color{blue}{\left(x \cdot x\right) \cdot 0.225} + \left(-0.009642857142857142 \cdot {x}^{4} + 0.00024107142857142857 \cdot {x}^{6}\right)\right) - 0.5 \]
      Proof
      (*.f64 (*.f64 x x) 9/40): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*r*_binary64 (*.f64 x (*.f64 x 9/40))): 18 points increase in error, 20 points decrease in error
      (Rewrite<= +-lft-identity_binary64 (+.f64 0 (*.f64 x (*.f64 x 9/40)))): 0 points increase in error, 0 points decrease in error
    6. Applied egg-rr0.0

      \[\leadsto \left(\left(x \cdot x\right) \cdot 0.225 + \color{blue}{\left(e^{\mathsf{log1p}\left(\mathsf{fma}\left(-0.009642857142857142, {x}^{4}, 0.00024107142857142857 \cdot {x}^{6}\right)\right)} - 1\right)}\right) - 0.5 \]
    7. Simplified0.0

      \[\leadsto \left(\left(x \cdot x\right) \cdot 0.225 + \color{blue}{{x}^{4} \cdot \mathsf{fma}\left(0.00024107142857142857, x \cdot x, -0.009642857142857142\right)}\right) - 0.5 \]
      Proof
      (*.f64 (pow.f64 x 4) (fma.f64 27/112000 (*.f64 x x) -27/2800)): 0 points increase in error, 0 points decrease in error
      (*.f64 (pow.f64 x 4) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 27/112000 (*.f64 x x)) -27/2800))): 1 points increase in error, 0 points decrease in error
      (*.f64 (pow.f64 x 4) (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 (*.f64 x x) 27/112000)) -27/2800)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= distribute-lft-out_binary64 (+.f64 (*.f64 (pow.f64 x 4) (*.f64 (*.f64 x x) 27/112000)) (*.f64 (pow.f64 x 4) -27/2800))): 0 points increase in error, 2 points decrease in error
      (+.f64 (*.f64 (pow.f64 x 4) (*.f64 (*.f64 x x) 27/112000)) (Rewrite<= *-commutative_binary64 (*.f64 -27/2800 (pow.f64 x 4)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite=> associate-*r*_binary64 (*.f64 (*.f64 (pow.f64 x 4) (*.f64 x x)) 27/112000)) (*.f64 -27/2800 (pow.f64 x 4))): 5 points increase in error, 6 points decrease in error
      (+.f64 (*.f64 (*.f64 (pow.f64 x (Rewrite<= metadata-eval (+.f64 3 1))) (*.f64 x x)) 27/112000) (*.f64 -27/2800 (pow.f64 x 4))): 0 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 (*.f64 (Rewrite<= pow-plus_binary64 (*.f64 (pow.f64 x 3) x)) (*.f64 x x)) 27/112000) (*.f64 -27/2800 (pow.f64 x 4))): 2 points increase in error, 5 points decrease in error
      (+.f64 (*.f64 (Rewrite<= associate-*r*_binary64 (*.f64 (pow.f64 x 3) (*.f64 x (*.f64 x x)))) 27/112000) (*.f64 -27/2800 (pow.f64 x 4))): 6 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 (*.f64 (pow.f64 x 3) (Rewrite<= cube-mult_binary64 (pow.f64 x 3))) 27/112000) (*.f64 -27/2800 (pow.f64 x 4))): 1 points increase in error, 2 points decrease in error
      (+.f64 (*.f64 (Rewrite=> pow-sqr_binary64 (pow.f64 x (*.f64 2 3))) 27/112000) (*.f64 -27/2800 (pow.f64 x 4))): 3 points increase in error, 8 points decrease in error
      (+.f64 (*.f64 (pow.f64 x (Rewrite=> metadata-eval 6)) 27/112000) (*.f64 -27/2800 (pow.f64 x 4))): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 27/112000 (pow.f64 x 6))) (*.f64 -27/2800 (pow.f64 x 4))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 -27/2800 (pow.f64 x 4)) (*.f64 27/112000 (pow.f64 x 6)))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-udef_binary64 (fma.f64 -27/2800 (pow.f64 x 4) (*.f64 27/112000 (pow.f64 x 6)))): 1 points increase in error, 1 points decrease in error
      (Rewrite<= expm1-log1p_binary64 (expm1.f64 (log1p.f64 (fma.f64 -27/2800 (pow.f64 x 4) (*.f64 27/112000 (pow.f64 x 6)))))): 10 points increase in error, 9 points decrease in error
      (Rewrite<= expm1-def_binary64 (-.f64 (exp.f64 (log1p.f64 (fma.f64 -27/2800 (pow.f64 x 4) (*.f64 27/112000 (pow.f64 x 6))))) 1)): 38 points increase in error, 4 points decrease in error
  3. Recombined 2 regimes into one program.
  4. Final simplification0.0

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

Alternatives

Alternative 1
Error0.0
Cost13512
\[\begin{array}{l} t_0 := \frac{x - \sin x}{x - \tan x}\\ \mathbf{if}\;x \leq -0.0195:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.028:\\ \;\;\;\;\left(x \cdot x\right) \cdot \mathsf{fma}\left(x, x \cdot -0.009642857142857142, 0.225\right) + -0.5\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error0.8
Cost7368
\[\begin{array}{l} \mathbf{if}\;x \leq -2.9:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 3:\\ \;\;\;\;\left(x \cdot x\right) \cdot \mathsf{fma}\left(x, x \cdot -0.009642857142857142, 0.225\right) + -0.5\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 3
Error0.8
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -2.6:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 2.6:\\ \;\;\;\;-0.5 + \left(x \cdot x\right) \cdot 0.225\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 4
Error1.0
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -1.58:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 1.55:\\ \;\;\;\;-0.5\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 5
Error32.2
Cost64
\[-0.5 \]

Error

Reproduce

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