
(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 6 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.6%
sub-neg37.6%
+-commutative37.6%
rgt-mult-inverse4.8%
exp-neg4.8%
distribute-rgt-neg-out4.8%
*-rgt-identity4.8%
distribute-lft-in4.9%
neg-sub04.9%
associate-+l-4.9%
neg-sub05.2%
associate-/r*5.2%
*-rgt-identity5.2%
associate-*r/5.2%
rgt-mult-inverse38.0%
distribute-frac-neg238.0%
distribute-neg-frac38.0%
metadata-eval38.0%
expm1-define100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (- (* x (- -0.08333333333333333)) (+ -0.5 (/ -1.0 x))))
double code(double x) {
return (x * -(-0.08333333333333333)) - (-0.5 + (-1.0 / x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * -(-0.08333333333333333d0)) - ((-0.5d0) + ((-1.0d0) / x))
end function
public static double code(double x) {
return (x * -(-0.08333333333333333)) - (-0.5 + (-1.0 / x));
}
def code(x): return (x * -(-0.08333333333333333)) - (-0.5 + (-1.0 / x))
function code(x) return Float64(Float64(x * Float64(-(-0.08333333333333333))) - Float64(-0.5 + Float64(-1.0 / x))) end
function tmp = code(x) tmp = (x * -(-0.08333333333333333)) - (-0.5 + (-1.0 / x)); end
code[x_] := N[(N[(x * (--0.08333333333333333)), $MachinePrecision] - N[(-0.5 + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(--0.08333333333333333\right) - \left(-0.5 + \frac{-1}{x}\right)
\end{array}
Initial program 37.6%
sub-neg37.6%
+-commutative37.6%
rgt-mult-inverse4.8%
exp-neg4.8%
distribute-rgt-neg-out4.8%
*-rgt-identity4.8%
distribute-lft-in4.9%
neg-sub04.9%
associate-+l-4.9%
neg-sub05.2%
associate-/r*5.2%
*-rgt-identity5.2%
associate-*r/5.2%
rgt-mult-inverse38.0%
distribute-frac-neg238.0%
distribute-neg-frac38.0%
metadata-eval38.0%
expm1-define100.0%
Simplified100.0%
Taylor expanded in x around 0 66.9%
*-commutative66.9%
Simplified66.9%
Taylor expanded in x around -inf 34.4%
Taylor expanded in x around -inf 34.2%
mul-1-neg34.2%
distribute-rgt-in34.3%
distribute-neg-in34.3%
distribute-lft-neg-in34.3%
metadata-eval34.3%
*-commutative34.3%
*-commutative34.3%
distribute-rgt-in34.3%
unpow234.3%
associate-/r*34.4%
*-rgt-identity34.4%
associate-*r/34.3%
distribute-rgt-in34.3%
distribute-rgt-in34.3%
associate-*r*66.8%
rgt-mult-inverse67.0%
*-lft-identity67.0%
Simplified67.0%
Final simplification67.0%
(FPCore (x) :precision binary64 (+ (/ 1.0 x) 0.5))
double code(double x) {
return (1.0 / x) + 0.5;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / x) + 0.5d0
end function
public static double code(double x) {
return (1.0 / x) + 0.5;
}
def code(x): return (1.0 / x) + 0.5
function code(x) return Float64(Float64(1.0 / x) + 0.5) end
function tmp = code(x) tmp = (1.0 / x) + 0.5; end
code[x_] := N[(N[(1.0 / x), $MachinePrecision] + 0.5), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x} + 0.5
\end{array}
Initial program 37.6%
sub-neg37.6%
+-commutative37.6%
rgt-mult-inverse4.8%
exp-neg4.8%
distribute-rgt-neg-out4.8%
*-rgt-identity4.8%
distribute-lft-in4.9%
neg-sub04.9%
associate-+l-4.9%
neg-sub05.2%
associate-/r*5.2%
*-rgt-identity5.2%
associate-*r/5.2%
rgt-mult-inverse38.0%
distribute-frac-neg238.0%
distribute-neg-frac38.0%
metadata-eval38.0%
expm1-define100.0%
Simplified100.0%
Taylor expanded in x around 0 66.9%
*-commutative66.9%
Simplified66.9%
Taylor expanded in x around 0 66.9%
+-commutative66.9%
*-commutative66.9%
fma-undefine66.9%
*-lft-identity66.9%
associate-*l/66.9%
fma-undefine66.9%
distribute-rgt-in66.9%
associate-*r*66.9%
*-commutative66.9%
associate-*l*66.9%
lft-mult-inverse66.9%
metadata-eval66.9%
*-lft-identity66.9%
+-commutative66.9%
Simplified66.9%
Final simplification66.9%
(FPCore (x) :precision binary64 (* x 0.08333333333333333))
double code(double x) {
return x * 0.08333333333333333;
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * 0.08333333333333333d0
end function
public static double code(double x) {
return x * 0.08333333333333333;
}
def code(x): return x * 0.08333333333333333
function code(x) return Float64(x * 0.08333333333333333) end
function tmp = code(x) tmp = x * 0.08333333333333333; end
code[x_] := N[(x * 0.08333333333333333), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.08333333333333333
\end{array}
Initial program 37.6%
sub-neg37.6%
+-commutative37.6%
rgt-mult-inverse4.8%
exp-neg4.8%
distribute-rgt-neg-out4.8%
*-rgt-identity4.8%
distribute-lft-in4.9%
neg-sub04.9%
associate-+l-4.9%
neg-sub05.2%
associate-/r*5.2%
*-rgt-identity5.2%
associate-*r/5.2%
rgt-mult-inverse38.0%
distribute-frac-neg238.0%
distribute-neg-frac38.0%
metadata-eval38.0%
expm1-define100.0%
Simplified100.0%
Taylor expanded in x around 0 66.9%
*-commutative66.9%
Simplified66.9%
Taylor expanded in x around inf 3.4%
*-commutative3.4%
Simplified3.4%
Final simplification3.4%
(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.6%
sub-neg37.6%
+-commutative37.6%
rgt-mult-inverse4.8%
exp-neg4.8%
distribute-rgt-neg-out4.8%
*-rgt-identity4.8%
distribute-lft-in4.9%
neg-sub04.9%
associate-+l-4.9%
neg-sub05.2%
associate-/r*5.2%
*-rgt-identity5.2%
associate-*r/5.2%
rgt-mult-inverse38.0%
distribute-frac-neg238.0%
distribute-neg-frac38.0%
metadata-eval38.0%
expm1-define100.0%
Simplified100.0%
Taylor expanded in x around 0 66.9%
Final simplification66.9%
(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.6%
sub-neg37.6%
+-commutative37.6%
rgt-mult-inverse4.8%
exp-neg4.8%
distribute-rgt-neg-out4.8%
*-rgt-identity4.8%
distribute-lft-in4.9%
neg-sub04.9%
associate-+l-4.9%
neg-sub05.2%
associate-/r*5.2%
*-rgt-identity5.2%
associate-*r/5.2%
rgt-mult-inverse38.0%
distribute-frac-neg238.0%
distribute-neg-frac38.0%
metadata-eval38.0%
expm1-define100.0%
Simplified100.0%
Taylor expanded in x around 0 66.9%
*-commutative66.9%
Simplified66.9%
Taylor expanded in x around inf 3.1%
Final simplification3.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 2024074
(FPCore (x)
:name "expq2 (section 3.11)"
:precision binary64
:pre (> 710.0 x)
:alt
(/ (- 1.0) (expm1 (- x)))
(/ (exp x) (- (exp x) 1.0)))