
(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 7 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 (/ (exp x) (expm1 x)))
double code(double x) {
return exp(x) / expm1(x);
}
public static double code(double x) {
return Math.exp(x) / Math.expm1(x);
}
def code(x): return math.exp(x) / math.expm1(x)
function code(x) return Float64(exp(x) / expm1(x)) end
code[x_] := N[(N[Exp[x], $MachinePrecision] / N[(Exp[x] - 1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{x}}{\mathsf{expm1}\left(x\right)}
\end{array}
Initial program 37.3%
expm1-def100.0%
Simplified100.0%
Final simplification100.0%
(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.3%
expm1-def100.0%
Simplified100.0%
Taylor expanded in x around inf 37.3%
expm1-def100.0%
*-lft-identity100.0%
metadata-eval100.0%
times-frac100.0%
neg-mul-1100.0%
associate-/l*100.0%
neg-sub0100.0%
expm1-def37.3%
associate--r-37.3%
neg-sub037.3%
+-commutative37.3%
sub-neg37.3%
div-sub3.7%
exp-neg3.7%
*-inverses37.3%
expm1-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (if (<= x -360.0) 0.0 (+ 0.5 (+ (* x 0.08333333333333333) (/ 1.0 x)))))
double code(double x) {
double tmp;
if (x <= -360.0) {
tmp = 0.0;
} else {
tmp = 0.5 + ((x * 0.08333333333333333) + (1.0 / x));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-360.0d0)) then
tmp = 0.0d0
else
tmp = 0.5d0 + ((x * 0.08333333333333333d0) + (1.0d0 / x))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -360.0) {
tmp = 0.0;
} else {
tmp = 0.5 + ((x * 0.08333333333333333) + (1.0 / x));
}
return tmp;
}
def code(x): tmp = 0 if x <= -360.0: tmp = 0.0 else: tmp = 0.5 + ((x * 0.08333333333333333) + (1.0 / x)) return tmp
function code(x) tmp = 0.0 if (x <= -360.0) tmp = 0.0; else tmp = Float64(0.5 + Float64(Float64(x * 0.08333333333333333) + Float64(1.0 / x))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -360.0) tmp = 0.0; else tmp = 0.5 + ((x * 0.08333333333333333) + (1.0 / x)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -360.0], 0.0, N[(0.5 + N[(N[(x * 0.08333333333333333), $MachinePrecision] + N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -360:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;0.5 + \left(x \cdot 0.08333333333333333 + \frac{1}{x}\right)\\
\end{array}
\end{array}
if x < -360Initial program 100.0%
expm1-def100.0%
Simplified100.0%
add-cbrt-cube100.0%
pow1/3100.0%
pow3100.0%
clear-num100.0%
inv-pow100.0%
metadata-eval100.0%
pow-pow100.0%
expm1-udef100.0%
div-sub0.0%
pow10.0%
pow10.0%
pow-div100.0%
metadata-eval100.0%
metadata-eval100.0%
rec-exp100.0%
metadata-eval100.0%
metadata-eval100.0%
Applied egg-rr100.0%
unpow1/3100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
expm1-def100.0%
Simplified100.0%
Taylor expanded in x around 0 63.0%
expm1-log1p-u63.0%
expm1-udef96.6%
log1p-udef96.6%
rem-exp-log96.6%
cbrt-div96.6%
metadata-eval96.6%
rem-cbrt-cube96.6%
Applied egg-rr96.6%
Taylor expanded in x around inf 100.0%
if -360 < x Initial program 5.6%
expm1-def100.0%
Simplified100.0%
Taylor expanded in x around 0 98.9%
Final simplification99.2%
(FPCore (x) :precision binary64 (if (<= x -2.0) 0.0 (+ 0.5 (/ 1.0 x))))
double code(double x) {
double tmp;
if (x <= -2.0) {
tmp = 0.0;
} else {
tmp = 0.5 + (1.0 / x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-2.0d0)) then
tmp = 0.0d0
else
tmp = 0.5d0 + (1.0d0 / x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -2.0) {
tmp = 0.0;
} else {
tmp = 0.5 + (1.0 / x);
}
return tmp;
}
def code(x): tmp = 0 if x <= -2.0: tmp = 0.0 else: tmp = 0.5 + (1.0 / x) return tmp
function code(x) tmp = 0.0 if (x <= -2.0) tmp = 0.0; else tmp = Float64(0.5 + Float64(1.0 / x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -2.0) tmp = 0.0; else tmp = 0.5 + (1.0 / x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -2.0], 0.0, N[(0.5 + N[(1.0 / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;0.5 + \frac{1}{x}\\
\end{array}
\end{array}
if x < -2Initial program 100.0%
expm1-def100.0%
Simplified100.0%
add-cbrt-cube100.0%
pow1/398.9%
pow398.9%
clear-num98.9%
inv-pow98.9%
metadata-eval98.9%
pow-pow98.9%
expm1-udef98.9%
div-sub0.0%
pow10.0%
pow10.0%
pow-div98.9%
metadata-eval98.9%
metadata-eval98.9%
rec-exp98.9%
metadata-eval98.9%
metadata-eval98.9%
Applied egg-rr98.9%
unpow1/3100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
expm1-def100.0%
Simplified100.0%
Taylor expanded in x around 0 62.4%
expm1-log1p-u62.4%
expm1-udef95.7%
log1p-udef95.7%
rem-exp-log95.7%
cbrt-div95.7%
metadata-eval95.7%
rem-cbrt-cube95.7%
Applied egg-rr95.7%
Taylor expanded in x around inf 98.9%
if -2 < x Initial program 5.1%
expm1-def100.0%
Simplified100.0%
Taylor expanded in x around 0 99.2%
+-commutative99.2%
Simplified99.2%
Final simplification99.1%
(FPCore (x) :precision binary64 (if (<= x -360.0) 0.0 (/ 1.0 x)))
double code(double x) {
double tmp;
if (x <= -360.0) {
tmp = 0.0;
} else {
tmp = 1.0 / x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-360.0d0)) then
tmp = 0.0d0
else
tmp = 1.0d0 / x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -360.0) {
tmp = 0.0;
} else {
tmp = 1.0 / x;
}
return tmp;
}
def code(x): tmp = 0 if x <= -360.0: tmp = 0.0 else: tmp = 1.0 / x return tmp
function code(x) tmp = 0.0 if (x <= -360.0) tmp = 0.0; else tmp = Float64(1.0 / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -360.0) tmp = 0.0; else tmp = 1.0 / x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -360.0], 0.0, N[(1.0 / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -360:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x}\\
\end{array}
\end{array}
if x < -360Initial program 100.0%
expm1-def100.0%
Simplified100.0%
add-cbrt-cube100.0%
pow1/3100.0%
pow3100.0%
clear-num100.0%
inv-pow100.0%
metadata-eval100.0%
pow-pow100.0%
expm1-udef100.0%
div-sub0.0%
pow10.0%
pow10.0%
pow-div100.0%
metadata-eval100.0%
metadata-eval100.0%
rec-exp100.0%
metadata-eval100.0%
metadata-eval100.0%
Applied egg-rr100.0%
unpow1/3100.0%
sub-neg100.0%
+-commutative100.0%
neg-sub0100.0%
associate-+l-100.0%
sub0-neg100.0%
expm1-def100.0%
Simplified100.0%
Taylor expanded in x around 0 63.0%
expm1-log1p-u63.0%
expm1-udef96.6%
log1p-udef96.6%
rem-exp-log96.6%
cbrt-div96.6%
metadata-eval96.6%
rem-cbrt-cube96.6%
Applied egg-rr96.6%
Taylor expanded in x around inf 100.0%
if -360 < x Initial program 5.6%
expm1-def100.0%
Simplified100.0%
Taylor expanded in x around 0 97.9%
Final simplification98.6%
(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.3%
expm1-def100.0%
Simplified100.0%
Taylor expanded in x around 0 66.5%
+-commutative66.5%
Simplified66.5%
Taylor expanded in x around inf 3.2%
Final simplification3.2%
(FPCore (x) :precision binary64 0.0)
double code(double x) {
return 0.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.0d0
end function
public static double code(double x) {
return 0.0;
}
def code(x): return 0.0
function code(x) return 0.0 end
function tmp = code(x) tmp = 0.0; end
code[x_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 37.3%
expm1-def100.0%
Simplified100.0%
add-cbrt-cube60.8%
pow1/344.6%
pow344.6%
clear-num44.6%
inv-pow44.6%
metadata-eval44.6%
pow-pow44.6%
expm1-udef35.9%
div-sub2.3%
pow12.3%
pow12.3%
pow-div35.9%
metadata-eval35.9%
metadata-eval35.9%
rec-exp35.9%
metadata-eval35.9%
metadata-eval35.9%
Applied egg-rr35.9%
unpow1/337.3%
sub-neg37.3%
+-commutative37.3%
neg-sub037.3%
associate-+l-37.3%
sub0-neg37.3%
expm1-def60.8%
Simplified60.8%
Taylor expanded in x around 0 47.0%
expm1-log1p-u32.0%
expm1-udef43.3%
log1p-udef43.3%
rem-exp-log58.3%
cbrt-div59.5%
metadata-eval59.5%
rem-cbrt-cube97.5%
Applied egg-rr97.5%
Taylor expanded in x around inf 35.1%
Final simplification35.1%
(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 2023330
(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)))