| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 192 |
\[\frac{x}{3}
\]
(FPCore (x) :precision binary64 (- (/ 1.0 x) (/ 1.0 (tan x))))
(FPCore (x)
:precision binary64
(/
x
(/
(+
(fma 0.0004938271604938272 (pow x 4.0) 0.1111111111111111)
(* (* x x) -0.007407407407407408))
(fma 1.0973936899862826e-5 (pow x 6.0) 0.037037037037037035))))double code(double x) {
return (1.0 / x) - (1.0 / tan(x));
}
double code(double x) {
return x / ((fma(0.0004938271604938272, pow(x, 4.0), 0.1111111111111111) + ((x * x) * -0.007407407407407408)) / fma(1.0973936899862826e-5, pow(x, 6.0), 0.037037037037037035));
}
function code(x) return Float64(Float64(1.0 / x) - Float64(1.0 / tan(x))) end
function code(x) return Float64(x / Float64(Float64(fma(0.0004938271604938272, (x ^ 4.0), 0.1111111111111111) + Float64(Float64(x * x) * -0.007407407407407408)) / fma(1.0973936899862826e-5, (x ^ 6.0), 0.037037037037037035))) end
code[x_] := N[(N[(1.0 / x), $MachinePrecision] - N[(1.0 / N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := N[(x / N[(N[(N[(0.0004938271604938272 * N[Power[x, 4.0], $MachinePrecision] + 0.1111111111111111), $MachinePrecision] + N[(N[(x * x), $MachinePrecision] * -0.007407407407407408), $MachinePrecision]), $MachinePrecision] / N[(1.0973936899862826e-5 * N[Power[x, 6.0], $MachinePrecision] + 0.037037037037037035), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{1}{x} - \frac{1}{\tan x}
\frac{x}{\frac{\mathsf{fma}\left(0.0004938271604938272, {x}^{4}, 0.1111111111111111\right) + \left(x \cdot x\right) \cdot -0.007407407407407408}{\mathsf{fma}\left(1.0973936899862826 \cdot 10^{-5}, {x}^{6}, 0.037037037037037035\right)}}
| Original | 59.9 |
|---|---|
| Target | 0.1 |
| Herbie | 0.1 |
Initial program 59.9
Simplified59.9
Taylor expanded in x around 0 0.4
Simplified0.4
Applied egg-rr0.4
Applied egg-rr0.1
Final simplification0.1
| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 192 |

herbie shell --seed 2022300
(FPCore (x)
:name "invcot (example 3.9)"
:precision binary64
:pre (and (< -0.026 x) (< x 0.026))
:herbie-target
(if (< (fabs x) 0.026) (* (/ x 3.0) (+ 1.0 (/ (* x x) 15.0))) (- (/ 1.0 x) (/ 1.0 (tan x))))
(- (/ 1.0 x) (/ 1.0 (tan x))))