| Alternative 1 | |
|---|---|
| Error | 1.6 |
| Cost | 6592 |
\[\frac{e^{x}}{x}
\]
(FPCore (x) :precision binary64 (/ (exp x) (- (exp x) 1.0)))
(FPCore (x)
:precision binary64
(let* ((t_0 (/ (exp x) (- (exp x) 1.0))))
(if (<= t_0 2.0)
t_0
(+
(/ 1.0 x)
(+
(* (pow x 3.0) -0.001388888888888889)
(+ 0.5 (* x 0.08333333333333333)))))))double code(double x) {
return exp(x) / (exp(x) - 1.0);
}
double code(double x) {
double t_0 = exp(x) / (exp(x) - 1.0);
double tmp;
if (t_0 <= 2.0) {
tmp = t_0;
} else {
tmp = (1.0 / x) + ((pow(x, 3.0) * -0.001388888888888889) + (0.5 + (x * 0.08333333333333333)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp(x) / (exp(x) - 1.0d0)
end function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = exp(x) / (exp(x) - 1.0d0)
if (t_0 <= 2.0d0) then
tmp = t_0
else
tmp = (1.0d0 / x) + (((x ** 3.0d0) * (-0.001388888888888889d0)) + (0.5d0 + (x * 0.08333333333333333d0)))
end if
code = tmp
end function
public static double code(double x) {
return Math.exp(x) / (Math.exp(x) - 1.0);
}
public static double code(double x) {
double t_0 = Math.exp(x) / (Math.exp(x) - 1.0);
double tmp;
if (t_0 <= 2.0) {
tmp = t_0;
} else {
tmp = (1.0 / x) + ((Math.pow(x, 3.0) * -0.001388888888888889) + (0.5 + (x * 0.08333333333333333)));
}
return tmp;
}
def code(x): return math.exp(x) / (math.exp(x) - 1.0)
def code(x): t_0 = math.exp(x) / (math.exp(x) - 1.0) tmp = 0 if t_0 <= 2.0: tmp = t_0 else: tmp = (1.0 / x) + ((math.pow(x, 3.0) * -0.001388888888888889) + (0.5 + (x * 0.08333333333333333))) return tmp
function code(x) return Float64(exp(x) / Float64(exp(x) - 1.0)) end
function code(x) t_0 = Float64(exp(x) / Float64(exp(x) - 1.0)) tmp = 0.0 if (t_0 <= 2.0) tmp = t_0; else tmp = Float64(Float64(1.0 / x) + Float64(Float64((x ^ 3.0) * -0.001388888888888889) + Float64(0.5 + Float64(x * 0.08333333333333333)))); end return tmp end
function tmp = code(x) tmp = exp(x) / (exp(x) - 1.0); end
function tmp_2 = code(x) t_0 = exp(x) / (exp(x) - 1.0); tmp = 0.0; if (t_0 <= 2.0) tmp = t_0; else tmp = (1.0 / x) + (((x ^ 3.0) * -0.001388888888888889) + (0.5 + (x * 0.08333333333333333))); end tmp_2 = tmp; end
code[x_] := N[(N[Exp[x], $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]
code[x_] := Block[{t$95$0 = N[(N[Exp[x], $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2.0], t$95$0, N[(N[(1.0 / x), $MachinePrecision] + N[(N[(N[Power[x, 3.0], $MachinePrecision] * -0.001388888888888889), $MachinePrecision] + N[(0.5 + N[(x * 0.08333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{e^{x}}{e^{x} - 1}
\begin{array}{l}
t_0 := \frac{e^{x}}{e^{x} - 1}\\
\mathbf{if}\;t_0 \leq 2:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x} + \left({x}^{3} \cdot -0.001388888888888889 + \left(0.5 + x \cdot 0.08333333333333333\right)\right)\\
\end{array}
Results
| Original | 40.7 |
|---|---|
| Target | 40.3 |
| Herbie | 0.9 |
if (/.f64 (exp.f64 x) (-.f64 (exp.f64 x) 1)) < 2Initial program 1.2
if 2 < (/.f64 (exp.f64 x) (-.f64 (exp.f64 x) 1)) Initial program 62.9
Taylor expanded in x around 0 0.7
Simplified0.7
[Start]0.7 | \[ 0.5 + \left(-0.001388888888888889 \cdot {x}^{3} + \left(0.08333333333333333 \cdot x + \frac{1}{x}\right)\right)
\] |
|---|---|
rational.json-simplify-41 [=>]0.7 | \[ 0.5 + \color{blue}{\left(0.08333333333333333 \cdot x + \left(\frac{1}{x} + -0.001388888888888889 \cdot {x}^{3}\right)\right)}
\] |
rational.json-simplify-41 [<=]0.7 | \[ \color{blue}{\left(\frac{1}{x} + -0.001388888888888889 \cdot {x}^{3}\right) + \left(0.5 + 0.08333333333333333 \cdot x\right)}
\] |
rational.json-simplify-1 [=>]0.7 | \[ \color{blue}{\left(0.5 + 0.08333333333333333 \cdot x\right) + \left(\frac{1}{x} + -0.001388888888888889 \cdot {x}^{3}\right)}
\] |
rational.json-simplify-41 [=>]0.7 | \[ \color{blue}{\frac{1}{x} + \left(-0.001388888888888889 \cdot {x}^{3} + \left(0.5 + 0.08333333333333333 \cdot x\right)\right)}
\] |
rational.json-simplify-2 [=>]0.7 | \[ \frac{1}{x} + \left(\color{blue}{{x}^{3} \cdot -0.001388888888888889} + \left(0.5 + 0.08333333333333333 \cdot x\right)\right)
\] |
rational.json-simplify-2 [=>]0.7 | \[ \frac{1}{x} + \left({x}^{3} \cdot -0.001388888888888889 + \left(0.5 + \color{blue}{x \cdot 0.08333333333333333}\right)\right)
\] |
Final simplification0.9
| Alternative 1 | |
|---|---|
| Error | 1.6 |
| Cost | 6592 |
| Alternative 2 | |
|---|---|
| Error | 12.9 |
| Cost | 2500 |
| Alternative 3 | |
|---|---|
| Error | 12.8 |
| Cost | 2372 |
| Alternative 4 | |
|---|---|
| Error | 61.8 |
| Cost | 192 |
| Alternative 5 | |
|---|---|
| Error | 21.9 |
| Cost | 192 |
| Alternative 6 | |
|---|---|
| Error | 61.8 |
| Cost | 64 |
herbie shell --seed 2023077
(FPCore (x)
:name "expq2 (section 3.11)"
:precision binary64
:herbie-target
(/ 1.0 (- 1.0 (exp (- x))))
(/ (exp x) (- (exp x) 1.0)))