
(FPCore (x) :precision binary64 (- (exp x) 1.0))
double code(double x) {
return exp(x) - 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp(x) - 1.0d0
end function
public static double code(double x) {
return Math.exp(x) - 1.0;
}
def code(x): return math.exp(x) - 1.0
function code(x) return Float64(exp(x) - 1.0) end
function tmp = code(x) tmp = exp(x) - 1.0; end
code[x_] := N[(N[Exp[x], $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}
\\
e^{x} - 1
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (exp x) 1.0))
double code(double x) {
return exp(x) - 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp(x) - 1.0d0
end function
public static double code(double x) {
return Math.exp(x) - 1.0;
}
def code(x): return math.exp(x) - 1.0
function code(x) return Float64(exp(x) - 1.0) end
function tmp = code(x) tmp = exp(x) - 1.0; end
code[x_] := N[(N[Exp[x], $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}
\\
e^{x} - 1
\end{array}
(FPCore (x) :precision binary64 (expm1 x))
double code(double x) {
return expm1(x);
}
public static double code(double x) {
return Math.expm1(x);
}
def code(x): return math.expm1(x)
function code(x) return expm1(x) end
code[x_] := N[(Exp[x] - 1), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{expm1}\left(x\right)
\end{array}
Initial program 8.8%
expm1-define100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (/ 1.0 (- (+ (* x 0.08333333333333333) (/ 1.0 x)) 0.5)))
double code(double x) {
return 1.0 / (((x * 0.08333333333333333) + (1.0 / x)) - 0.5);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (((x * 0.08333333333333333d0) + (1.0d0 / x)) - 0.5d0)
end function
public static double code(double x) {
return 1.0 / (((x * 0.08333333333333333) + (1.0 / x)) - 0.5);
}
def code(x): return 1.0 / (((x * 0.08333333333333333) + (1.0 / x)) - 0.5)
function code(x) return Float64(1.0 / Float64(Float64(Float64(x * 0.08333333333333333) + Float64(1.0 / x)) - 0.5)) end
function tmp = code(x) tmp = 1.0 / (((x * 0.08333333333333333) + (1.0 / x)) - 0.5); end
code[x_] := N[(1.0 / N[(N[(N[(x * 0.08333333333333333), $MachinePrecision] + N[(1.0 / x), $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\left(x \cdot 0.08333333333333333 + \frac{1}{x}\right) - 0.5}
\end{array}
Initial program 8.8%
expm1-define100.0%
Simplified100.0%
expm1-undefine8.8%
flip3--8.8%
clear-num8.8%
pow28.8%
metadata-eval8.8%
*-rgt-identity8.8%
+-commutative8.8%
metadata-eval8.8%
pow38.8%
sub-neg8.8%
pow38.8%
pow-exp9.0%
metadata-eval9.0%
Applied egg-rr9.0%
Taylor expanded in x around 0 99.2%
Final simplification99.2%
(FPCore (x) :precision binary64 (/ 1.0 (- (/ 1.0 x) 0.5)))
double code(double x) {
return 1.0 / ((1.0 / x) - 0.5);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / ((1.0d0 / x) - 0.5d0)
end function
public static double code(double x) {
return 1.0 / ((1.0 / x) - 0.5);
}
def code(x): return 1.0 / ((1.0 / x) - 0.5)
function code(x) return Float64(1.0 / Float64(Float64(1.0 / x) - 0.5)) end
function tmp = code(x) tmp = 1.0 / ((1.0 / x) - 0.5); end
code[x_] := N[(1.0 / N[(N[(1.0 / x), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{1}{x} - 0.5}
\end{array}
Initial program 8.8%
expm1-define100.0%
Simplified100.0%
expm1-undefine8.8%
flip3--8.8%
clear-num8.8%
pow28.8%
metadata-eval8.8%
*-rgt-identity8.8%
+-commutative8.8%
metadata-eval8.8%
pow38.8%
sub-neg8.8%
pow38.8%
pow-exp9.0%
metadata-eval9.0%
Applied egg-rr9.0%
Taylor expanded in x around 0 98.6%
Final simplification98.6%
(FPCore (x) :precision binary64 x)
double code(double x) {
return x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = x
end function
public static double code(double x) {
return x;
}
def code(x): return x
function code(x) return x end
function tmp = code(x) tmp = x; end
code[x_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 8.8%
expm1-define100.0%
Simplified100.0%
Taylor expanded in x around 0 97.6%
Final simplification97.6%
(FPCore (x) :precision binary64 (expm1 x))
double code(double x) {
return expm1(x);
}
public static double code(double x) {
return Math.expm1(x);
}
def code(x): return math.expm1(x)
function code(x) return expm1(x) end
code[x_] := N[(Exp[x] - 1), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{expm1}\left(x\right)
\end{array}
herbie shell --seed 2024044
(FPCore (x)
:name "expm1 (example 3.7)"
:precision binary64
:pre (<= (fabs x) 1.0)
:alt
(expm1 x)
(- (exp x) 1.0))