# ?

Average Error: 2.8 → 1.5
Time: 11.1s
Precision: binary64
Cost: 34184

# ?

$0.01 \leq x \land x \leq 1000$
$\frac{1}{x} - \frac{1}{\tan x}$
$\begin{array}{l} t_0 := \frac{1}{x} - \frac{1}{\tan x}\\ \mathbf{if}\;t_0 \leq -0.01:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 0.024:\\ \;\;\;\;x \cdot 0.3333333333333333 + \left(0.0021164021164021165 \cdot {x}^{5} + \left(0.022222222222222223 \cdot {x}^{3} + 0.00021164021164021165 \cdot {x}^{7}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\tan x - x}{x}}{\tan x}\\ \end{array}$
(FPCore (x) :precision binary64 (- (/ 1.0 x) (/ 1.0 (tan x))))
(FPCore (x)
:precision binary64
(let* ((t_0 (- (/ 1.0 x) (/ 1.0 (tan x)))))
(if (<= t_0 -0.01)
t_0
(if (<= t_0 0.024)
(+
(* x 0.3333333333333333)
(+
(* 0.0021164021164021165 (pow x 5.0))
(+
(* 0.022222222222222223 (pow x 3.0))
(* 0.00021164021164021165 (pow x 7.0)))))
(/ (/ (- (tan x) x) x) (tan x))))))
double code(double x) {
return (1.0 / x) - (1.0 / tan(x));
}

double code(double x) {
double t_0 = (1.0 / x) - (1.0 / tan(x));
double tmp;
if (t_0 <= -0.01) {
tmp = t_0;
} else if (t_0 <= 0.024) {
tmp = (x * 0.3333333333333333) + ((0.0021164021164021165 * pow(x, 5.0)) + ((0.022222222222222223 * pow(x, 3.0)) + (0.00021164021164021165 * pow(x, 7.0))));
} else {
tmp = ((tan(x) - x) / x) / tan(x);
}
return tmp;
}

real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / x) - (1.0d0 / tan(x))
end function

real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = (1.0d0 / x) - (1.0d0 / tan(x))
if (t_0 <= (-0.01d0)) then
tmp = t_0
else if (t_0 <= 0.024d0) then
tmp = (x * 0.3333333333333333d0) + ((0.0021164021164021165d0 * (x ** 5.0d0)) + ((0.022222222222222223d0 * (x ** 3.0d0)) + (0.00021164021164021165d0 * (x ** 7.0d0))))
else
tmp = ((tan(x) - x) / x) / tan(x)
end if
code = tmp
end function

public static double code(double x) {
return (1.0 / x) - (1.0 / Math.tan(x));
}

public static double code(double x) {
double t_0 = (1.0 / x) - (1.0 / Math.tan(x));
double tmp;
if (t_0 <= -0.01) {
tmp = t_0;
} else if (t_0 <= 0.024) {
tmp = (x * 0.3333333333333333) + ((0.0021164021164021165 * Math.pow(x, 5.0)) + ((0.022222222222222223 * Math.pow(x, 3.0)) + (0.00021164021164021165 * Math.pow(x, 7.0))));
} else {
tmp = ((Math.tan(x) - x) / x) / Math.tan(x);
}
return tmp;
}

def code(x):
return (1.0 / x) - (1.0 / math.tan(x))

def code(x):
t_0 = (1.0 / x) - (1.0 / math.tan(x))
tmp = 0
if t_0 <= -0.01:
tmp = t_0
elif t_0 <= 0.024:
tmp = (x * 0.3333333333333333) + ((0.0021164021164021165 * math.pow(x, 5.0)) + ((0.022222222222222223 * math.pow(x, 3.0)) + (0.00021164021164021165 * math.pow(x, 7.0))))
else:
tmp = ((math.tan(x) - x) / x) / math.tan(x)
return tmp

function code(x)
return Float64(Float64(1.0 / x) - Float64(1.0 / tan(x)))
end

function code(x)
t_0 = Float64(Float64(1.0 / x) - Float64(1.0 / tan(x)))
tmp = 0.0
if (t_0 <= -0.01)
tmp = t_0;
elseif (t_0 <= 0.024)
tmp = Float64(Float64(x * 0.3333333333333333) + Float64(Float64(0.0021164021164021165 * (x ^ 5.0)) + Float64(Float64(0.022222222222222223 * (x ^ 3.0)) + Float64(0.00021164021164021165 * (x ^ 7.0)))));
else
tmp = Float64(Float64(Float64(tan(x) - x) / x) / tan(x));
end
return tmp
end

function tmp = code(x)
tmp = (1.0 / x) - (1.0 / tan(x));
end

function tmp_2 = code(x)
t_0 = (1.0 / x) - (1.0 / tan(x));
tmp = 0.0;
if (t_0 <= -0.01)
tmp = t_0;
elseif (t_0 <= 0.024)
tmp = (x * 0.3333333333333333) + ((0.0021164021164021165 * (x ^ 5.0)) + ((0.022222222222222223 * (x ^ 3.0)) + (0.00021164021164021165 * (x ^ 7.0))));
else
tmp = ((tan(x) - x) / x) / tan(x);
end
tmp_2 = tmp;
end

code[x_] := N[(N[(1.0 / x), $MachinePrecision] - N[(1.0 / N[Tan[x],$MachinePrecision]), $MachinePrecision]),$MachinePrecision]

code[x_] := Block[{t$95$0 = N[(N[(1.0 / x), $MachinePrecision] - N[(1.0 / N[Tan[x],$MachinePrecision]), $MachinePrecision]),$MachinePrecision]}, If[LessEqual[t$95$0, -0.01], t$95$0, If[LessEqual[t$95$0, 0.024], N[(N[(x * 0.3333333333333333), $MachinePrecision] + N[(N[(0.0021164021164021165 * N[Power[x, 5.0],$MachinePrecision]), $MachinePrecision] + N[(N[(0.022222222222222223 * N[Power[x, 3.0],$MachinePrecision]), $MachinePrecision] + N[(0.00021164021164021165 * N[Power[x, 7.0],$MachinePrecision]), $MachinePrecision]),$MachinePrecision]), $MachinePrecision]),$MachinePrecision], N[(N[(N[(N[Tan[x], $MachinePrecision] - x),$MachinePrecision] / x), $MachinePrecision] / N[Tan[x],$MachinePrecision]), \$MachinePrecision]]]]

\frac{1}{x} - \frac{1}{\tan x}

\begin{array}{l}
t_0 := \frac{1}{x} - \frac{1}{\tan x}\\
\mathbf{if}\;t_0 \leq -0.01:\\
\;\;\;\;t_0\\

\mathbf{elif}\;t_0 \leq 0.024:\\
\;\;\;\;x \cdot 0.3333333333333333 + \left(0.0021164021164021165 \cdot {x}^{5} + \left(0.022222222222222223 \cdot {x}^{3} + 0.00021164021164021165 \cdot {x}^{7}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{\tan x - x}{x}}{\tan x}\\

\end{array}


# Try it out?

Results

 In Out
Enter valid numbers for all inputs

# Derivation?

1. Split input into 3 regimes
2. ## if (-.f64 (/.f64 1 x) (/.f64 1 (tan.f64 x))) < -0.0100000000000000002

1. Initial program 0.4

$\frac{1}{x} - \frac{1}{\tan x}$

## if -0.0100000000000000002 < (-.f64 (/.f64 1 x) (/.f64 1 (tan.f64 x))) < 0.024

1. Initial program 10.0

$\frac{1}{x} - \frac{1}{\tan x}$
2. Taylor expanded in x around 0 3.2

$\leadsto \color{blue}{0.3333333333333333 \cdot x + \left(0.0021164021164021165 \cdot {x}^{5} + \left(0.022222222222222223 \cdot {x}^{3} + 0.00021164021164021165 \cdot {x}^{7}\right)\right)}$

## if 0.024 < (-.f64 (/.f64 1 x) (/.f64 1 (tan.f64 x)))

1. Initial program 1.7

$\frac{1}{x} - \frac{1}{\tan x}$
2. Applied egg-rr1.6

$\leadsto \color{blue}{\frac{\frac{\tan x - x}{x}}{\tan x}}$
3. Recombined 3 regimes into one program.
4. Final simplification1.5

$\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{x} - \frac{1}{\tan x} \leq -0.01:\\ \;\;\;\;\frac{1}{x} - \frac{1}{\tan x}\\ \mathbf{elif}\;\frac{1}{x} - \frac{1}{\tan x} \leq 0.024:\\ \;\;\;\;x \cdot 0.3333333333333333 + \left(0.0021164021164021165 \cdot {x}^{5} + \left(0.022222222222222223 \cdot {x}^{3} + 0.00021164021164021165 \cdot {x}^{7}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\tan x - x}{x}}{\tan x}\\ \end{array}$

# Alternatives

Alternative 1
Error2.6
Cost13248
$\frac{\tan x - x}{x \cdot \tan x}$
Alternative 2
Error2.6
Cost13248
$\frac{\frac{\tan x - x}{x}}{\tan x}$
Alternative 3
Error2.8
Cost6848
$\frac{1}{x} - \frac{1}{\tan x}$
Alternative 4
Error45.2
Cost6724
$\begin{array}{l} \mathbf{if}\;x \leq 2.2:\\ \;\;\;\;\left(1 + x \cdot 0.3333333333333333\right) + -1\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{\tan x}\\ \end{array}$
Alternative 5
Error51.2
Cost448
$\left(1 + x \cdot 0.3333333333333333\right) + -1$
Alternative 6
Error51.2
Cost192
$x \cdot 0.3333333333333333$

# Reproduce?

herbie shell --seed 1
(FPCore (x)
:name "1/x - 1/tan(x)"
:precision binary64
:pre (and (<= 0.01 x) (<= x 1000.0))
(- (/ 1.0 x) (/ 1.0 (tan x))))