Alternative 1 | |
---|---|
Error | 2.6 |
Cost | 13248 |
\[\frac{\tan x - x}{x \cdot \tan x}
\]
(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}
Results
if (-.f64 (/.f64 1 x) (/.f64 1 (tan.f64 x))) < -0.0100000000000000002
Initial program 0.4
if -0.0100000000000000002 < (-.f64 (/.f64 1 x) (/.f64 1 (tan.f64 x))) < 0.024
Initial program 10.0
Taylor expanded in x around 0 3.2
if 0.024 < (-.f64 (/.f64 1 x) (/.f64 1 (tan.f64 x)))
Initial program 1.7
Applied egg-rr1.6
Final simplification1.5
Alternative 1 | |
---|---|
Error | 2.6 |
Cost | 13248 |
Alternative 2 | |
---|---|
Error | 2.6 |
Cost | 13248 |
Alternative 3 | |
---|---|
Error | 2.8 |
Cost | 6848 |
Alternative 4 | |
---|---|
Error | 45.2 |
Cost | 6724 |
Alternative 5 | |
---|---|
Error | 51.2 |
Cost | 448 |
Alternative 6 | |
---|---|
Error | 51.2 |
Cost | 192 |
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))))