| Alternative 1 | |
|---|---|
| Error | 0.7 |
| Cost | 7040 |
\[\frac{x + \left(x + 0.3333333333333333 \cdot {x}^{3}\right)}{2}
\]
(FPCore (x) :precision binary64 (/ (- (exp x) (exp (- x))) 2.0))
(FPCore (x) :precision binary64 (/ (+ (* 2.0 x) (* 0.3333333333333333 (pow x 3.0))) 2.0))
double code(double x) {
return (exp(x) - exp(-x)) / 2.0;
}
double code(double x) {
return ((2.0 * x) + (0.3333333333333333 * pow(x, 3.0))) / 2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (exp(x) - exp(-x)) / 2.0d0
end function
real(8) function code(x)
real(8), intent (in) :: x
code = ((2.0d0 * x) + (0.3333333333333333d0 * (x ** 3.0d0))) / 2.0d0
end function
public static double code(double x) {
return (Math.exp(x) - Math.exp(-x)) / 2.0;
}
public static double code(double x) {
return ((2.0 * x) + (0.3333333333333333 * Math.pow(x, 3.0))) / 2.0;
}
def code(x): return (math.exp(x) - math.exp(-x)) / 2.0
def code(x): return ((2.0 * x) + (0.3333333333333333 * math.pow(x, 3.0))) / 2.0
function code(x) return Float64(Float64(exp(x) - exp(Float64(-x))) / 2.0) end
function code(x) return Float64(Float64(Float64(2.0 * x) + Float64(0.3333333333333333 * (x ^ 3.0))) / 2.0) end
function tmp = code(x) tmp = (exp(x) - exp(-x)) / 2.0; end
function tmp = code(x) tmp = ((2.0 * x) + (0.3333333333333333 * (x ^ 3.0))) / 2.0; end
code[x_] := N[(N[(N[Exp[x], $MachinePrecision] - N[Exp[(-x)], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
code[x_] := N[(N[(N[(2.0 * x), $MachinePrecision] + N[(0.3333333333333333 * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\frac{e^{x} - e^{-x}}{2}
\frac{2 \cdot x + 0.3333333333333333 \cdot {x}^{3}}{2}
Results
Initial program 57.9
Taylor expanded in x around 0 0.7
Final simplification0.7
| Alternative 1 | |
|---|---|
| Error | 0.7 |
| Cost | 7040 |
| Alternative 2 | |
|---|---|
| Error | 1.1 |
| Cost | 320 |
| Alternative 3 | |
|---|---|
| Error | 52.0 |
| Cost | 192 |
herbie shell --seed 2023092
(FPCore (x)
:name "Hyperbolic sine"
:precision binary64
(/ (- (exp x) (exp (- x))) 2.0))