| Alternative 1 | |
|---|---|
| Error | 1.9 |
| Cost | 13632 |
\[\frac{2 \cdot x + 0.3333333333333333 \cdot {x}^{3}}{2 + {x}^{2}}
\]
(FPCore (x) :precision binary64 (/ (- (exp x) (exp (- x))) (+ (exp x) (exp (- x)))))
(FPCore (x) :precision binary64 (/ (+ (* 2.0 x) (* 0.3333333333333333 (pow x 3.0))) (+ (pow x 2.0) (+ 2.0 (* 0.08333333333333333 (pow x 4.0))))))
double code(double x) {
return (exp(x) - exp(-x)) / (exp(x) + exp(-x));
}
double code(double x) {
return ((2.0 * x) + (0.3333333333333333 * pow(x, 3.0))) / (pow(x, 2.0) + (2.0 + (0.08333333333333333 * pow(x, 4.0))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (exp(x) - exp(-x)) / (exp(x) + exp(-x))
end function
real(8) function code(x)
real(8), intent (in) :: x
code = ((2.0d0 * x) + (0.3333333333333333d0 * (x ** 3.0d0))) / ((x ** 2.0d0) + (2.0d0 + (0.08333333333333333d0 * (x ** 4.0d0))))
end function
public static double code(double x) {
return (Math.exp(x) - Math.exp(-x)) / (Math.exp(x) + Math.exp(-x));
}
public static double code(double x) {
return ((2.0 * x) + (0.3333333333333333 * Math.pow(x, 3.0))) / (Math.pow(x, 2.0) + (2.0 + (0.08333333333333333 * Math.pow(x, 4.0))));
}
def code(x): return (math.exp(x) - math.exp(-x)) / (math.exp(x) + math.exp(-x))
def code(x): return ((2.0 * x) + (0.3333333333333333 * math.pow(x, 3.0))) / (math.pow(x, 2.0) + (2.0 + (0.08333333333333333 * math.pow(x, 4.0))))
function code(x) return Float64(Float64(exp(x) - exp(Float64(-x))) / Float64(exp(x) + exp(Float64(-x)))) end
function code(x) return Float64(Float64(Float64(2.0 * x) + Float64(0.3333333333333333 * (x ^ 3.0))) / Float64((x ^ 2.0) + Float64(2.0 + Float64(0.08333333333333333 * (x ^ 4.0))))) end
function tmp = code(x) tmp = (exp(x) - exp(-x)) / (exp(x) + exp(-x)); end
function tmp = code(x) tmp = ((2.0 * x) + (0.3333333333333333 * (x ^ 3.0))) / ((x ^ 2.0) + (2.0 + (0.08333333333333333 * (x ^ 4.0)))); end
code[x_] := N[(N[(N[Exp[x], $MachinePrecision] - N[Exp[(-x)], $MachinePrecision]), $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := N[(N[(N[(2.0 * x), $MachinePrecision] + N[(0.3333333333333333 * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Power[x, 2.0], $MachinePrecision] + N[(2.0 + N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}
\frac{2 \cdot x + 0.3333333333333333 \cdot {x}^{3}}{{x}^{2} + \left(2 + 0.08333333333333333 \cdot {x}^{4}\right)}
Results
Initial program 58.0
Taylor expanded in x around 0 2.0
Taylor expanded in x around 0 1.9
Simplified1.9
[Start]1.9 | \[ \frac{2 \cdot x + 0.3333333333333333 \cdot {x}^{3}}{2 + \left({x}^{2} + 0.08333333333333333 \cdot {x}^{4}\right)}
\] |
|---|---|
rational.json-simplify-41 [=>]1.9 | \[ \frac{2 \cdot x + 0.3333333333333333 \cdot {x}^{3}}{\color{blue}{{x}^{2} + \left(0.08333333333333333 \cdot {x}^{4} + 2\right)}}
\] |
rational.json-simplify-1 [=>]1.9 | \[ \frac{2 \cdot x + 0.3333333333333333 \cdot {x}^{3}}{{x}^{2} + \color{blue}{\left(2 + 0.08333333333333333 \cdot {x}^{4}\right)}}
\] |
Final simplification1.9
| Alternative 1 | |
|---|---|
| Error | 1.9 |
| Cost | 13632 |
| Alternative 2 | |
|---|---|
| Error | 1.9 |
| Cost | 13504 |
| Alternative 3 | |
|---|---|
| Error | 2.1 |
| Cost | 6784 |
| Alternative 4 | |
|---|---|
| Error | 2.3 |
| Cost | 64 |
herbie shell --seed 2023067
(FPCore (x)
:name "Hyperbolic tangent"
:precision binary64
(/ (- (exp x) (exp (- x))) (+ (exp x) (exp (- x)))))