| Alternative 1 | |
|---|---|
| Error | 0.3 |
| Cost | 6852 |
\[\begin{array}{l}
\mathbf{if}\;x \leq -0.00185:\\
\;\;\;\;\frac{e^{x} - 1}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{2}{x}}{\frac{2}{x} + \left(x \cdot 0.16666666666666666 + -1\right)}\\
\end{array}
\]
(FPCore (x) :precision binary64 (/ (- (exp x) 1.0) x))
(FPCore (x)
:precision binary64
(if (<= x -0.0195)
(/ (- (exp x) 1.0) x)
(/
(/ 1.0 x)
(+
(/ 1.0 x)
(+
(* x 0.08333333333333333)
(+ (* (pow x 3.0) -0.001388888888888889) -0.5))))))double code(double x) {
return (exp(x) - 1.0) / x;
}
double code(double x) {
double tmp;
if (x <= -0.0195) {
tmp = (exp(x) - 1.0) / x;
} else {
tmp = (1.0 / x) / ((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) - 1.0d0) / x
end function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-0.0195d0)) then
tmp = (exp(x) - 1.0d0) / x
else
tmp = (1.0d0 / x) / ((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) - 1.0) / x;
}
public static double code(double x) {
double tmp;
if (x <= -0.0195) {
tmp = (Math.exp(x) - 1.0) / x;
} else {
tmp = (1.0 / x) / ((1.0 / x) + ((x * 0.08333333333333333) + ((Math.pow(x, 3.0) * -0.001388888888888889) + -0.5)));
}
return tmp;
}
def code(x): return (math.exp(x) - 1.0) / x
def code(x): tmp = 0 if x <= -0.0195: tmp = (math.exp(x) - 1.0) / x else: tmp = (1.0 / x) / ((1.0 / x) + ((x * 0.08333333333333333) + ((math.pow(x, 3.0) * -0.001388888888888889) + -0.5))) return tmp
function code(x) return Float64(Float64(exp(x) - 1.0) / x) end
function code(x) tmp = 0.0 if (x <= -0.0195) tmp = Float64(Float64(exp(x) - 1.0) / x); else tmp = Float64(Float64(1.0 / x) / Float64(Float64(1.0 / x) + Float64(Float64(x * 0.08333333333333333) + Float64(Float64((x ^ 3.0) * -0.001388888888888889) + -0.5)))); end return tmp end
function tmp = code(x) tmp = (exp(x) - 1.0) / x; end
function tmp_2 = code(x) tmp = 0.0; if (x <= -0.0195) tmp = (exp(x) - 1.0) / x; else tmp = (1.0 / x) / ((1.0 / x) + ((x * 0.08333333333333333) + (((x ^ 3.0) * -0.001388888888888889) + -0.5))); end tmp_2 = tmp; end
code[x_] := N[(N[(N[Exp[x], $MachinePrecision] - 1.0), $MachinePrecision] / x), $MachinePrecision]
code[x_] := If[LessEqual[x, -0.0195], N[(N[(N[Exp[x], $MachinePrecision] - 1.0), $MachinePrecision] / x), $MachinePrecision], N[(N[(1.0 / x), $MachinePrecision] / N[(N[(1.0 / x), $MachinePrecision] + N[(N[(x * 0.08333333333333333), $MachinePrecision] + N[(N[(N[Power[x, 3.0], $MachinePrecision] * -0.001388888888888889), $MachinePrecision] + -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{e^{x} - 1}{x}
\begin{array}{l}
\mathbf{if}\;x \leq -0.0195:\\
\;\;\;\;\frac{e^{x} - 1}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{x}}{\frac{1}{x} + \left(x \cdot 0.08333333333333333 + \left({x}^{3} \cdot -0.001388888888888889 + -0.5\right)\right)}\\
\end{array}
Results
| Original | 39.8 |
|---|---|
| Target | 40.2 |
| Herbie | 0.2 |
if x < -0.0195Initial program 0.0
if -0.0195 < x Initial program 59.9
Applied egg-rr59.9
Taylor expanded in x around 0 0.5
Simplified0.5
[Start]0.5 | \[ \frac{1}{\left(-0.001388888888888889 \cdot {x}^{3} + \left(0.08333333333333333 \cdot x + \frac{1}{x}\right)\right) - 0.5} \cdot \frac{1}{x}
\] |
|---|---|
rational.json-simplify-1 [=>]0.5 | \[ \frac{1}{\color{blue}{\left(\left(0.08333333333333333 \cdot x + \frac{1}{x}\right) + -0.001388888888888889 \cdot {x}^{3}\right)} - 0.5} \cdot \frac{1}{x}
\] |
rational.json-simplify-1 [=>]0.5 | \[ \frac{1}{\left(\color{blue}{\left(\frac{1}{x} + 0.08333333333333333 \cdot x\right)} + -0.001388888888888889 \cdot {x}^{3}\right) - 0.5} \cdot \frac{1}{x}
\] |
rational.json-simplify-2 [=>]0.5 | \[ \frac{1}{\left(\left(\frac{1}{x} + \color{blue}{x \cdot 0.08333333333333333}\right) + -0.001388888888888889 \cdot {x}^{3}\right) - 0.5} \cdot \frac{1}{x}
\] |
rational.json-simplify-2 [=>]0.5 | \[ \frac{1}{\left(\left(\frac{1}{x} + x \cdot 0.08333333333333333\right) + \color{blue}{{x}^{3} \cdot -0.001388888888888889}\right) - 0.5} \cdot \frac{1}{x}
\] |
Applied egg-rr0.4
Final simplification0.2
| Alternative 1 | |
|---|---|
| Error | 0.3 |
| Cost | 6852 |
| Alternative 2 | |
|---|---|
| Error | 17.9 |
| Cost | 452 |
| Alternative 3 | |
|---|---|
| Error | 18.0 |
| Cost | 384 |
| Alternative 4 | |
|---|---|
| Error | 18.4 |
| Cost | 324 |
| Alternative 5 | |
|---|---|
| Error | 21.3 |
| Cost | 64 |
herbie shell --seed 2023068
(FPCore (x)
:name "Kahan's exp quotient"
:precision binary64
:herbie-target
(if (and (< x 1.0) (> x -1.0)) (/ (- (exp x) 1.0) (log (exp x))) (/ (- (exp x) 1.0) x))
(/ (- (exp x) 1.0) x))