
(FPCore (x) :precision binary64 (/ (exp x) (- (exp x) 1.0)))
double code(double x) {
return exp(x) / (exp(x) - 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp(x) / (exp(x) - 1.0d0)
end function
public static double code(double x) {
return Math.exp(x) / (Math.exp(x) - 1.0);
}
def code(x): return math.exp(x) / (math.exp(x) - 1.0)
function code(x) return Float64(exp(x) / Float64(exp(x) - 1.0)) end
function tmp = code(x) tmp = exp(x) / (exp(x) - 1.0); end
code[x_] := N[(N[Exp[x], $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{x}}{e^{x} - 1}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (/ (exp x) (- (exp x) 1.0)))
double code(double x) {
return exp(x) / (exp(x) - 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp(x) / (exp(x) - 1.0d0)
end function
public static double code(double x) {
return Math.exp(x) / (Math.exp(x) - 1.0);
}
def code(x): return math.exp(x) / (math.exp(x) - 1.0)
function code(x) return Float64(exp(x) / Float64(exp(x) - 1.0)) end
function tmp = code(x) tmp = exp(x) / (exp(x) - 1.0); end
code[x_] := N[(N[Exp[x], $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{x}}{e^{x} - 1}
\end{array}
(FPCore (x) :precision binary64 (/ -1.0 (expm1 (- x))))
double code(double x) {
return -1.0 / expm1(-x);
}
public static double code(double x) {
return -1.0 / Math.expm1(-x);
}
def code(x): return -1.0 / math.expm1(-x)
function code(x) return Float64(-1.0 / expm1(Float64(-x))) end
code[x_] := N[(-1.0 / N[(Exp[(-x)] - 1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{\mathsf{expm1}\left(-x\right)}
\end{array}
Initial program 37.9%
expm1-def100.0%
Simplified100.0%
add-sqr-sqrt67.3%
pow1/267.3%
clear-num67.3%
inv-pow67.3%
metadata-eval67.3%
pow-pow67.4%
expm1-udef37.0%
div-sub3.4%
pow13.4%
pow13.4%
pow-div37.0%
metadata-eval37.0%
metadata-eval37.0%
rec-exp37.0%
metadata-eval37.0%
metadata-eval37.0%
pow1/237.0%
clear-num37.0%
inv-pow37.0%
metadata-eval37.0%
Applied egg-rr37.1%
pow-sqr37.9%
metadata-eval37.9%
unpow-137.9%
Simplified37.9%
Taylor expanded in x around -inf 37.9%
sub-neg37.9%
neg-mul-137.9%
+-commutative37.9%
neg-sub037.9%
associate-+l-37.9%
sub0-neg37.9%
expm1-def100.0%
Simplified100.0%
Taylor expanded in x around inf 37.9%
expm1-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (/ (exp x) x))
double code(double x) {
return exp(x) / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp(x) / x
end function
public static double code(double x) {
return Math.exp(x) / x;
}
def code(x): return math.exp(x) / x
function code(x) return Float64(exp(x) / x) end
function tmp = code(x) tmp = exp(x) / x; end
code[x_] := N[(N[Exp[x], $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{x}}{x}
\end{array}
Initial program 37.9%
Taylor expanded in x around 0 98.3%
Final simplification98.3%
(FPCore (x) :precision binary64 (/ 1.0 x))
double code(double x) {
return 1.0 / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / x
end function
public static double code(double x) {
return 1.0 / x;
}
def code(x): return 1.0 / x
function code(x) return Float64(1.0 / x) end
function tmp = code(x) tmp = 1.0 / x; end
code[x_] := N[(1.0 / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x}
\end{array}
Initial program 37.9%
expm1-def100.0%
Simplified100.0%
Taylor expanded in x around 0 66.5%
Final simplification66.5%
(FPCore (x) :precision binary64 0.5)
double code(double x) {
return 0.5;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.5d0
end function
public static double code(double x) {
return 0.5;
}
def code(x): return 0.5
function code(x) return 0.5 end
function tmp = code(x) tmp = 0.5; end
code[x_] := 0.5
\begin{array}{l}
\\
0.5
\end{array}
Initial program 37.9%
expm1-def100.0%
Simplified100.0%
Taylor expanded in x around 0 66.5%
+-commutative66.5%
Simplified66.5%
Taylor expanded in x around inf 3.3%
Final simplification3.3%
(FPCore (x) :precision binary64 4.5)
double code(double x) {
return 4.5;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 4.5d0
end function
public static double code(double x) {
return 4.5;
}
def code(x): return 4.5
function code(x) return 4.5 end
function tmp = code(x) tmp = 4.5; end
code[x_] := 4.5
\begin{array}{l}
\\
4.5
\end{array}
Initial program 37.9%
expm1-def100.0%
Simplified100.0%
add-sqr-sqrt67.3%
pow1/267.3%
clear-num67.3%
inv-pow67.3%
metadata-eval67.3%
pow-pow67.4%
expm1-udef37.0%
div-sub3.4%
pow13.4%
pow13.4%
pow-div37.0%
metadata-eval37.0%
metadata-eval37.0%
rec-exp37.0%
metadata-eval37.0%
metadata-eval37.0%
pow1/237.0%
clear-num37.0%
inv-pow37.0%
metadata-eval37.0%
Applied egg-rr37.1%
pow-sqr37.9%
metadata-eval37.9%
unpow-137.9%
Simplified37.9%
Applied egg-rr3.4%
Final simplification3.4%
(FPCore (x) :precision binary64 (/ (- 1.0) (expm1 (- x))))
double code(double x) {
return -1.0 / expm1(-x);
}
public static double code(double x) {
return -1.0 / Math.expm1(-x);
}
def code(x): return -1.0 / math.expm1(-x)
function code(x) return Float64(Float64(-1.0) / expm1(Float64(-x))) end
code[x_] := N[((-1.0) / N[(Exp[(-x)] - 1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{\mathsf{expm1}\left(-x\right)}
\end{array}
herbie shell --seed 2023306
(FPCore (x)
:name "expq2 (section 3.11)"
:precision binary64
:pre (> 715.0 x)
:herbie-target
(/ (- 1.0) (expm1 (- x)))
(/ (exp x) (- (exp x) 1.0)))