| Alternative 1 | |
|---|---|
| Error | 0.8 |
| Cost | 13444 |
\[\begin{array}{l}
\mathbf{if}\;e^{x} \leq 0.05:\\
\;\;\;\;\frac{2}{-1 + e^{-x}} \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x} + \left(x \cdot 0.08333333333333333 + 0.5\right)\\
\end{array}
\]
(FPCore (x) :precision binary64 (/ (exp x) (- (exp x) 1.0)))
(FPCore (x)
:precision binary64
(if (<= (exp x) 0.05)
(* (/ 2.0 (+ -1.0 (exp (- x)))) -0.5)
(+
(+ (/ 1.0 x) (* x 0.08333333333333333))
(+ (* (pow x 3.0) -0.001388888888888889) 0.5))))double code(double x) {
return exp(x) / (exp(x) - 1.0);
}
double code(double x) {
double tmp;
if (exp(x) <= 0.05) {
tmp = (2.0 / (-1.0 + exp(-x))) * -0.5;
} else {
tmp = ((1.0 / x) + (x * 0.08333333333333333)) + ((pow(x, 3.0) * -0.001388888888888889) + 0.5);
}
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) :: tmp
if (exp(x) <= 0.05d0) then
tmp = (2.0d0 / ((-1.0d0) + exp(-x))) * (-0.5d0)
else
tmp = ((1.0d0 / x) + (x * 0.08333333333333333d0)) + (((x ** 3.0d0) * (-0.001388888888888889d0)) + 0.5d0)
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 tmp;
if (Math.exp(x) <= 0.05) {
tmp = (2.0 / (-1.0 + Math.exp(-x))) * -0.5;
} else {
tmp = ((1.0 / x) + (x * 0.08333333333333333)) + ((Math.pow(x, 3.0) * -0.001388888888888889) + 0.5);
}
return tmp;
}
def code(x): return math.exp(x) / (math.exp(x) - 1.0)
def code(x): tmp = 0 if math.exp(x) <= 0.05: tmp = (2.0 / (-1.0 + math.exp(-x))) * -0.5 else: tmp = ((1.0 / x) + (x * 0.08333333333333333)) + ((math.pow(x, 3.0) * -0.001388888888888889) + 0.5) return tmp
function code(x) return Float64(exp(x) / Float64(exp(x) - 1.0)) end
function code(x) tmp = 0.0 if (exp(x) <= 0.05) tmp = Float64(Float64(2.0 / Float64(-1.0 + exp(Float64(-x)))) * -0.5); else tmp = Float64(Float64(Float64(1.0 / x) + Float64(x * 0.08333333333333333)) + Float64(Float64((x ^ 3.0) * -0.001388888888888889) + 0.5)); end return tmp end
function tmp = code(x) tmp = exp(x) / (exp(x) - 1.0); end
function tmp_2 = code(x) tmp = 0.0; if (exp(x) <= 0.05) tmp = (2.0 / (-1.0 + exp(-x))) * -0.5; else tmp = ((1.0 / x) + (x * 0.08333333333333333)) + (((x ^ 3.0) * -0.001388888888888889) + 0.5); end tmp_2 = tmp; end
code[x_] := N[(N[Exp[x], $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]
code[x_] := If[LessEqual[N[Exp[x], $MachinePrecision], 0.05], N[(N[(2.0 / N[(-1.0 + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision], N[(N[(N[(1.0 / x), $MachinePrecision] + N[(x * 0.08333333333333333), $MachinePrecision]), $MachinePrecision] + N[(N[(N[Power[x, 3.0], $MachinePrecision] * -0.001388888888888889), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision]]
\frac{e^{x}}{e^{x} - 1}
\begin{array}{l}
\mathbf{if}\;e^{x} \leq 0.05:\\
\;\;\;\;\frac{2}{-1 + e^{-x}} \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{1}{x} + x \cdot 0.08333333333333333\right) + \left({x}^{3} \cdot -0.001388888888888889 + 0.5\right)\\
\end{array}
Results
| Original | 40.8 |
|---|---|
| Target | 40.4 |
| Herbie | 0.8 |
if (exp.f64 x) < 0.050000000000000003Initial program 0.0
Applied egg-rr0.0
if 0.050000000000000003 < (exp.f64 x) Initial program 61.4
Taylor expanded in x around 0 1.1
Simplified1.1
[Start]1.1 | \[ 0.5 + \left(-0.001388888888888889 \cdot {x}^{3} + \left(0.08333333333333333 \cdot x + \frac{1}{x}\right)\right)
\] |
|---|---|
rational.json-simplify-41 [<=]1.1 | \[ \color{blue}{\left(0.08333333333333333 \cdot x + \frac{1}{x}\right) + \left(0.5 + -0.001388888888888889 \cdot {x}^{3}\right)}
\] |
rational.json-simplify-1 [=>]1.1 | \[ \color{blue}{\left(\frac{1}{x} + 0.08333333333333333 \cdot x\right)} + \left(0.5 + -0.001388888888888889 \cdot {x}^{3}\right)
\] |
rational.json-simplify-2 [=>]1.1 | \[ \left(\frac{1}{x} + \color{blue}{x \cdot 0.08333333333333333}\right) + \left(0.5 + -0.001388888888888889 \cdot {x}^{3}\right)
\] |
rational.json-simplify-1 [<=]1.1 | \[ \left(\frac{1}{x} + x \cdot 0.08333333333333333\right) + \color{blue}{\left(-0.001388888888888889 \cdot {x}^{3} + 0.5\right)}
\] |
rational.json-simplify-2 [=>]1.1 | \[ \left(\frac{1}{x} + x \cdot 0.08333333333333333\right) + \left(\color{blue}{{x}^{3} \cdot -0.001388888888888889} + 0.5\right)
\] |
Final simplification0.8
| Alternative 1 | |
|---|---|
| Error | 0.8 |
| Cost | 13444 |
| Alternative 2 | |
|---|---|
| Error | 1.7 |
| Cost | 6592 |
| Alternative 3 | |
|---|---|
| Error | 10.9 |
| Cost | 1348 |
| Alternative 4 | |
|---|---|
| Error | 11.0 |
| Cost | 836 |
| Alternative 5 | |
|---|---|
| Error | 21.7 |
| Cost | 320 |
| Alternative 6 | |
|---|---|
| Error | 21.8 |
| Cost | 192 |
herbie shell --seed 2023073
(FPCore (x)
:name "expq2 (section 3.11)"
:precision binary64
:herbie-target
(/ 1.0 (- 1.0 (exp (- x))))
(/ (exp x) (- (exp x) 1.0)))