
(FPCore (a x) :precision binary64 (- (exp (* a x)) 1.0))
double code(double a, double x) {
return exp((a * x)) - 1.0;
}
real(8) function code(a, x)
real(8), intent (in) :: a
real(8), intent (in) :: x
code = exp((a * x)) - 1.0d0
end function
public static double code(double a, double x) {
return Math.exp((a * x)) - 1.0;
}
def code(a, x): return math.exp((a * x)) - 1.0
function code(a, x) return Float64(exp(Float64(a * x)) - 1.0) end
function tmp = code(a, x) tmp = exp((a * x)) - 1.0; end
code[a_, x_] := N[(N[Exp[N[(a * x), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}
\\
e^{a \cdot x} - 1
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a x) :precision binary64 (- (exp (* a x)) 1.0))
double code(double a, double x) {
return exp((a * x)) - 1.0;
}
real(8) function code(a, x)
real(8), intent (in) :: a
real(8), intent (in) :: x
code = exp((a * x)) - 1.0d0
end function
public static double code(double a, double x) {
return Math.exp((a * x)) - 1.0;
}
def code(a, x): return math.exp((a * x)) - 1.0
function code(a, x) return Float64(exp(Float64(a * x)) - 1.0) end
function tmp = code(a, x) tmp = exp((a * x)) - 1.0; end
code[a_, x_] := N[(N[Exp[N[(a * x), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}
\\
e^{a \cdot x} - 1
\end{array}
(FPCore (a x) :precision binary64 (expm1 (* a x)))
double code(double a, double x) {
return expm1((a * x));
}
public static double code(double a, double x) {
return Math.expm1((a * x));
}
def code(a, x): return math.expm1((a * x))
function code(a, x) return expm1(Float64(a * x)) end
code[a_, x_] := N[(Exp[N[(a * x), $MachinePrecision]] - 1), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{expm1}\left(a \cdot x\right)
\end{array}
Initial program 54.2%
expm1-defineN/A
expm1-lowering-expm1.f64N/A
*-lowering-*.f64100.0%
Simplified100.0%
(FPCore (a x) :precision binary64 (* x (/ 1.0 (+ (* x (+ (/ a a) -1.5)) (/ 1.0 a)))))
double code(double a, double x) {
return x * (1.0 / ((x * ((a / a) + -1.5)) + (1.0 / a)));
}
real(8) function code(a, x)
real(8), intent (in) :: a
real(8), intent (in) :: x
code = x * (1.0d0 / ((x * ((a / a) + (-1.5d0))) + (1.0d0 / a)))
end function
public static double code(double a, double x) {
return x * (1.0 / ((x * ((a / a) + -1.5)) + (1.0 / a)));
}
def code(a, x): return x * (1.0 / ((x * ((a / a) + -1.5)) + (1.0 / a)))
function code(a, x) return Float64(x * Float64(1.0 / Float64(Float64(x * Float64(Float64(a / a) + -1.5)) + Float64(1.0 / a)))) end
function tmp = code(a, x) tmp = x * (1.0 / ((x * ((a / a) + -1.5)) + (1.0 / a))); end
code[a_, x_] := N[(x * N[(1.0 / N[(N[(x * N[(N[(a / a), $MachinePrecision] + -1.5), $MachinePrecision]), $MachinePrecision] + N[(1.0 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \frac{1}{x \cdot \left(\frac{a}{a} + -1.5\right) + \frac{1}{a}}
\end{array}
Initial program 54.2%
expm1-defineN/A
expm1-lowering-expm1.f64N/A
*-lowering-*.f64100.0%
Simplified100.0%
sub-negN/A
flip3-+N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
sub-negN/A
metadata-evalN/A
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
Applied egg-rr99.1%
Taylor expanded in x around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
sub-negN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
distribute-rgt-out--N/A
metadata-evalN/A
*-lowering-*.f64N/A
metadata-evalN/A
/-lowering-/.f6471.2%
Simplified71.2%
associate-/r/N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
associate-*r/N/A
/-lowering-/.f64N/A
*-commutativeN/A
associate-*r*N/A
metadata-evalN/A
*-lowering-*.f64N/A
/-lowering-/.f6471.9%
Applied egg-rr71.9%
Final simplification71.9%
(FPCore (a x) :precision binary64 (if (<= (* a x) -500.0) (+ -2.0 (/ -4.0 (* a x))) (* a x)))
double code(double a, double x) {
double tmp;
if ((a * x) <= -500.0) {
tmp = -2.0 + (-4.0 / (a * x));
} else {
tmp = a * x;
}
return tmp;
}
real(8) function code(a, x)
real(8), intent (in) :: a
real(8), intent (in) :: x
real(8) :: tmp
if ((a * x) <= (-500.0d0)) then
tmp = (-2.0d0) + ((-4.0d0) / (a * x))
else
tmp = a * x
end if
code = tmp
end function
public static double code(double a, double x) {
double tmp;
if ((a * x) <= -500.0) {
tmp = -2.0 + (-4.0 / (a * x));
} else {
tmp = a * x;
}
return tmp;
}
def code(a, x): tmp = 0 if (a * x) <= -500.0: tmp = -2.0 + (-4.0 / (a * x)) else: tmp = a * x return tmp
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -500.0) tmp = Float64(-2.0 + Float64(-4.0 / Float64(a * x))); else tmp = Float64(a * x); end return tmp end
function tmp_2 = code(a, x) tmp = 0.0; if ((a * x) <= -500.0) tmp = -2.0 + (-4.0 / (a * x)); else tmp = a * x; end tmp_2 = tmp; end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -500.0], N[(-2.0 + N[(-4.0 / N[(a * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(a * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -500:\\
\;\;\;\;-2 + \frac{-4}{a \cdot x}\\
\mathbf{else}:\\
\;\;\;\;a \cdot x\\
\end{array}
\end{array}
if (*.f64 a x) < -500Initial program 100.0%
expm1-defineN/A
expm1-lowering-expm1.f64N/A
*-lowering-*.f64100.0%
Simplified100.0%
sub-negN/A
flip3-+N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
sub-negN/A
metadata-evalN/A
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
Applied egg-rr100.0%
Taylor expanded in x around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
sub-negN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
distribute-rgt-out--N/A
metadata-evalN/A
*-lowering-*.f64N/A
metadata-evalN/A
/-lowering-/.f6418.8%
Simplified18.8%
Taylor expanded in x around inf
mul-1-negN/A
distribute-neg-inN/A
+-lowering-+.f64N/A
metadata-evalN/A
mul-1-negN/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
metadata-evalN/A
metadata-evalN/A
/-lowering-/.f64N/A
metadata-evalN/A
*-lowering-*.f6418.8%
Simplified18.8%
if -500 < (*.f64 a x) Initial program 31.0%
expm1-defineN/A
expm1-lowering-expm1.f64N/A
*-lowering-*.f64100.0%
Simplified100.0%
Taylor expanded in a around 0
*-lowering-*.f6498.6%
Simplified98.6%
(FPCore (a x) :precision binary64 (if (<= (* a x) -2.0) -2.0 (* a x)))
double code(double a, double x) {
double tmp;
if ((a * x) <= -2.0) {
tmp = -2.0;
} else {
tmp = a * x;
}
return tmp;
}
real(8) function code(a, x)
real(8), intent (in) :: a
real(8), intent (in) :: x
real(8) :: tmp
if ((a * x) <= (-2.0d0)) then
tmp = -2.0d0
else
tmp = a * x
end if
code = tmp
end function
public static double code(double a, double x) {
double tmp;
if ((a * x) <= -2.0) {
tmp = -2.0;
} else {
tmp = a * x;
}
return tmp;
}
def code(a, x): tmp = 0 if (a * x) <= -2.0: tmp = -2.0 else: tmp = a * x return tmp
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -2.0) tmp = -2.0; else tmp = Float64(a * x); end return tmp end
function tmp_2 = code(a, x) tmp = 0.0; if ((a * x) <= -2.0) tmp = -2.0; else tmp = a * x; end tmp_2 = tmp; end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -2.0], -2.0, N[(a * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -2:\\
\;\;\;\;-2\\
\mathbf{else}:\\
\;\;\;\;a \cdot x\\
\end{array}
\end{array}
if (*.f64 a x) < -2Initial program 100.0%
expm1-defineN/A
expm1-lowering-expm1.f64N/A
*-lowering-*.f64100.0%
Simplified100.0%
sub-negN/A
flip3-+N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
sub-negN/A
metadata-evalN/A
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
Applied egg-rr100.0%
Taylor expanded in x around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
sub-negN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
distribute-rgt-out--N/A
metadata-evalN/A
*-lowering-*.f64N/A
metadata-evalN/A
/-lowering-/.f6418.8%
Simplified18.8%
Taylor expanded in x around inf
Simplified18.8%
if -2 < (*.f64 a x) Initial program 31.0%
expm1-defineN/A
expm1-lowering-expm1.f64N/A
*-lowering-*.f64100.0%
Simplified100.0%
Taylor expanded in a around 0
*-lowering-*.f6498.6%
Simplified98.6%
(FPCore (a x) :precision binary64 (/ 1.0 (+ (/ 1.0 (* a x)) -0.5)))
double code(double a, double x) {
return 1.0 / ((1.0 / (a * x)) + -0.5);
}
real(8) function code(a, x)
real(8), intent (in) :: a
real(8), intent (in) :: x
code = 1.0d0 / ((1.0d0 / (a * x)) + (-0.5d0))
end function
public static double code(double a, double x) {
return 1.0 / ((1.0 / (a * x)) + -0.5);
}
def code(a, x): return 1.0 / ((1.0 / (a * x)) + -0.5)
function code(a, x) return Float64(1.0 / Float64(Float64(1.0 / Float64(a * x)) + -0.5)) end
function tmp = code(a, x) tmp = 1.0 / ((1.0 / (a * x)) + -0.5); end
code[a_, x_] := N[(1.0 / N[(N[(1.0 / N[(a * x), $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{1}{a \cdot x} + -0.5}
\end{array}
Initial program 54.2%
expm1-defineN/A
expm1-lowering-expm1.f64N/A
*-lowering-*.f64100.0%
Simplified100.0%
sub-negN/A
flip3-+N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
sub-negN/A
metadata-evalN/A
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
Applied egg-rr99.1%
Taylor expanded in x around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
sub-negN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
distribute-rgt-out--N/A
metadata-evalN/A
*-lowering-*.f64N/A
metadata-evalN/A
/-lowering-/.f6471.2%
Simplified71.2%
Taylor expanded in x around inf
sub-negN/A
metadata-evalN/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f6471.3%
Simplified71.3%
(FPCore (a x) :precision binary64 -2.0)
double code(double a, double x) {
return -2.0;
}
real(8) function code(a, x)
real(8), intent (in) :: a
real(8), intent (in) :: x
code = -2.0d0
end function
public static double code(double a, double x) {
return -2.0;
}
def code(a, x): return -2.0
function code(a, x) return -2.0 end
function tmp = code(a, x) tmp = -2.0; end
code[a_, x_] := -2.0
\begin{array}{l}
\\
-2
\end{array}
Initial program 54.2%
expm1-defineN/A
expm1-lowering-expm1.f64N/A
*-lowering-*.f64100.0%
Simplified100.0%
sub-negN/A
flip3-+N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
sub-negN/A
metadata-evalN/A
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
Applied egg-rr99.1%
Taylor expanded in x around 0
/-lowering-/.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
sub-negN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
distribute-rgt-out--N/A
metadata-evalN/A
*-lowering-*.f64N/A
metadata-evalN/A
/-lowering-/.f6471.2%
Simplified71.2%
Taylor expanded in x around inf
Simplified8.7%
(FPCore (a x) :precision binary64 (expm1 (* a x)))
double code(double a, double x) {
return expm1((a * x));
}
public static double code(double a, double x) {
return Math.expm1((a * x));
}
def code(a, x): return math.expm1((a * x))
function code(a, x) return expm1(Float64(a * x)) end
code[a_, x_] := N[(Exp[N[(a * x), $MachinePrecision]] - 1), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{expm1}\left(a \cdot x\right)
\end{array}
herbie shell --seed 2024161
(FPCore (a x)
:name "expax (section 3.5)"
:precision binary64
:pre (> 710.0 (* a x))
:alt
(! :herbie-platform default (expm1 (* a x)))
(- (exp (* a x)) 1.0))