| Alternative 1 | |
|---|---|
| Accuracy | 97.3% |
| Cost | 13504 |
\[{x}^{3} \cdot -0.3333333333333333 + \left(x + {x}^{5} \cdot 0.13333333333333333\right)
\]
(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)) (* 0.016666666666666666 (pow x 5.0)))) (+ 2.0 (+ (* x x) (* 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)) + (0.016666666666666666 * pow(x, 5.0)))) / (2.0 + ((x * x) + (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)) + (0.016666666666666666d0 * (x ** 5.0d0)))) / (2.0d0 + ((x * x) + (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)) + (0.016666666666666666 * Math.pow(x, 5.0)))) / (2.0 + ((x * x) + (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)) + (0.016666666666666666 * math.pow(x, 5.0)))) / (2.0 + ((x * x) + (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(Float64(0.3333333333333333 * (x ^ 3.0)) + Float64(0.016666666666666666 * (x ^ 5.0)))) / Float64(2.0 + Float64(Float64(x * x) + 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)) + (0.016666666666666666 * (x ^ 5.0)))) / (2.0 + ((x * x) + (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[(N[(0.3333333333333333 * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision] + N[(0.016666666666666666 * N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(2.0 + N[(N[(x * x), $MachinePrecision] + 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 + \left(0.3333333333333333 \cdot {x}^{3} + 0.016666666666666666 \cdot {x}^{5}\right)}{2 + \left(x \cdot x + 0.08333333333333333 \cdot {x}^{4}\right)}
Results
Initial program 9.2%
Taylor expanded in x around 0 8.1%
Simplified8.1%
[Start]8.1 | \[ \frac{e^{x} - e^{-x}}{2 + \left({x}^{2} + 0.08333333333333333 \cdot {x}^{4}\right)}
\] |
|---|---|
unpow2 [=>]8.1 | \[ \frac{e^{x} - e^{-x}}{2 + \left(\color{blue}{x \cdot x} + 0.08333333333333333 \cdot {x}^{4}\right)}
\] |
Taylor expanded in x around 0 97.4%
Final simplification97.4%
| Alternative 1 | |
|---|---|
| Accuracy | 97.3% |
| Cost | 13504 |
| Alternative 2 | |
|---|---|
| Accuracy | 97.2% |
| Cost | 960 |
| Alternative 3 | |
|---|---|
| Accuracy | 97.2% |
| Cost | 960 |
| Alternative 4 | |
|---|---|
| Accuracy | 96.7% |
| Cost | 576 |
| Alternative 5 | |
|---|---|
| Accuracy | 6.8% |
| Cost | 196 |
| Alternative 6 | |
|---|---|
| Accuracy | 7.8% |
| Cost | 196 |
| Alternative 7 | |
|---|---|
| Accuracy | 5.0% |
| Cost | 64 |
| Alternative 8 | |
|---|---|
| Accuracy | 96.7% |
| Cost | 64 |
herbie shell --seed 2023137
(FPCore (x)
:name "Hyperbolic tangent"
:precision binary64
(/ (- (exp x) (exp (- x))) (+ (exp x) (exp (- x)))))