
(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 55.4%
lift-*.f64N/A
lower-expm1.f64100.0
Applied egg-rr100.0%
(FPCore (a x) :precision binary64 (if (<= a -1.1e+251) (+ (* a (* 0.5 (* a (* x x)))) -1.0) (fma x a (* (* a x) (* a (* x (fma x (* a 0.16666666666666666) 0.5)))))))
double code(double a, double x) {
double tmp;
if (a <= -1.1e+251) {
tmp = (a * (0.5 * (a * (x * x)))) + -1.0;
} else {
tmp = fma(x, a, ((a * x) * (a * (x * fma(x, (a * 0.16666666666666666), 0.5)))));
}
return tmp;
}
function code(a, x) tmp = 0.0 if (a <= -1.1e+251) tmp = Float64(Float64(a * Float64(0.5 * Float64(a * Float64(x * x)))) + -1.0); else tmp = fma(x, a, Float64(Float64(a * x) * Float64(a * Float64(x * fma(x, Float64(a * 0.16666666666666666), 0.5))))); end return tmp end
code[a_, x_] := If[LessEqual[a, -1.1e+251], N[(N[(a * N[(0.5 * N[(a * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(x * a + N[(N[(a * x), $MachinePrecision] * N[(a * N[(x * N[(x * N[(a * 0.16666666666666666), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.1 \cdot 10^{+251}:\\
\;\;\;\;a \cdot \left(0.5 \cdot \left(a \cdot \left(x \cdot x\right)\right)\right) + -1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, a, \left(a \cdot x\right) \cdot \left(a \cdot \left(x \cdot \mathsf{fma}\left(x, a \cdot 0.16666666666666666, 0.5\right)\right)\right)\right)\\
\end{array}
\end{array}
if a < -1.1e251Initial program 100.0%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f642.9
Simplified2.9%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-*.f640.8
Applied egg-rr0.8%
Taylor expanded in a around inf
*-commutativeN/A
unpow2N/A
associate-*l*N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6435.7
Simplified35.7%
if -1.1e251 < a Initial program 52.2%
lift-*.f64N/A
lower-expm1.f64100.0
Applied egg-rr100.0%
Taylor expanded in a around 0
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
Simplified64.9%
lift-*.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-*.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lift-*.f64N/A
associate-*l*N/A
Applied egg-rr69.2%
Final simplification67.0%
(FPCore (a x) :precision binary64 (if (<= a -1.1e+251) (+ (* a (* 0.5 (* a (* x x)))) -1.0) (* a (fma (* (* a x) (fma x (* a 0.16666666666666666) 0.5)) x x))))
double code(double a, double x) {
double tmp;
if (a <= -1.1e+251) {
tmp = (a * (0.5 * (a * (x * x)))) + -1.0;
} else {
tmp = a * fma(((a * x) * fma(x, (a * 0.16666666666666666), 0.5)), x, x);
}
return tmp;
}
function code(a, x) tmp = 0.0 if (a <= -1.1e+251) tmp = Float64(Float64(a * Float64(0.5 * Float64(a * Float64(x * x)))) + -1.0); else tmp = Float64(a * fma(Float64(Float64(a * x) * fma(x, Float64(a * 0.16666666666666666), 0.5)), x, x)); end return tmp end
code[a_, x_] := If[LessEqual[a, -1.1e+251], N[(N[(a * N[(0.5 * N[(a * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(a * N[(N[(N[(a * x), $MachinePrecision] * N[(x * N[(a * 0.16666666666666666), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision] * x + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.1 \cdot 10^{+251}:\\
\;\;\;\;a \cdot \left(0.5 \cdot \left(a \cdot \left(x \cdot x\right)\right)\right) + -1\\
\mathbf{else}:\\
\;\;\;\;a \cdot \mathsf{fma}\left(\left(a \cdot x\right) \cdot \mathsf{fma}\left(x, a \cdot 0.16666666666666666, 0.5\right), x, x\right)\\
\end{array}
\end{array}
if a < -1.1e251Initial program 100.0%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f642.9
Simplified2.9%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-*.f640.8
Applied egg-rr0.8%
Taylor expanded in a around inf
*-commutativeN/A
unpow2N/A
associate-*l*N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6435.7
Simplified35.7%
if -1.1e251 < a Initial program 52.2%
lift-*.f64N/A
lower-expm1.f64100.0
Applied egg-rr100.0%
Taylor expanded in a around 0
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
Simplified64.9%
lift-*.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6469.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f6469.2
Applied egg-rr69.2%
Final simplification67.0%
(FPCore (a x) :precision binary64 (if (<= a -5.8e+250) (+ (* a (* 0.5 (* a (* x x)))) -1.0) (* a x)))
double code(double a, double x) {
double tmp;
if (a <= -5.8e+250) {
tmp = (a * (0.5 * (a * (x * x)))) + -1.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 <= (-5.8d+250)) then
tmp = (a * (0.5d0 * (a * (x * x)))) + (-1.0d0)
else
tmp = a * x
end if
code = tmp
end function
public static double code(double a, double x) {
double tmp;
if (a <= -5.8e+250) {
tmp = (a * (0.5 * (a * (x * x)))) + -1.0;
} else {
tmp = a * x;
}
return tmp;
}
def code(a, x): tmp = 0 if a <= -5.8e+250: tmp = (a * (0.5 * (a * (x * x)))) + -1.0 else: tmp = a * x return tmp
function code(a, x) tmp = 0.0 if (a <= -5.8e+250) tmp = Float64(Float64(a * Float64(0.5 * Float64(a * Float64(x * x)))) + -1.0); else tmp = Float64(a * x); end return tmp end
function tmp_2 = code(a, x) tmp = 0.0; if (a <= -5.8e+250) tmp = (a * (0.5 * (a * (x * x)))) + -1.0; else tmp = a * x; end tmp_2 = tmp; end
code[a_, x_] := If[LessEqual[a, -5.8e+250], N[(N[(a * N[(0.5 * N[(a * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(a * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -5.8 \cdot 10^{+250}:\\
\;\;\;\;a \cdot \left(0.5 \cdot \left(a \cdot \left(x \cdot x\right)\right)\right) + -1\\
\mathbf{else}:\\
\;\;\;\;a \cdot x\\
\end{array}
\end{array}
if a < -5.80000000000000018e250Initial program 100.0%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f642.9
Simplified2.9%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-*.f640.8
Applied egg-rr0.8%
Taylor expanded in a around inf
*-commutativeN/A
unpow2N/A
associate-*l*N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6435.7
Simplified35.7%
if -5.80000000000000018e250 < a Initial program 52.2%
Taylor expanded in a around 0
lower-*.f6468.7
Simplified68.7%
Final simplification66.5%
(FPCore (a x) :precision binary64 (* a x))
double code(double a, double x) {
return a * x;
}
real(8) function code(a, x)
real(8), intent (in) :: a
real(8), intent (in) :: x
code = a * x
end function
public static double code(double a, double x) {
return a * x;
}
def code(a, x): return a * x
function code(a, x) return Float64(a * x) end
function tmp = code(a, x) tmp = a * x; end
code[a_, x_] := N[(a * x), $MachinePrecision]
\begin{array}{l}
\\
a \cdot x
\end{array}
Initial program 55.4%
Taylor expanded in a around 0
lower-*.f6464.5
Simplified64.5%
(FPCore (a x) :precision binary64 0.0)
double code(double a, double x) {
return 0.0;
}
real(8) function code(a, x)
real(8), intent (in) :: a
real(8), intent (in) :: x
code = 0.0d0
end function
public static double code(double a, double x) {
return 0.0;
}
def code(a, x): return 0.0
function code(a, x) return 0.0 end
function tmp = code(a, x) tmp = 0.0; end
code[a_, x_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 55.4%
Taylor expanded in a around 0
Simplified18.8%
metadata-eval18.8
Applied egg-rr18.8%
(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 2024215
(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))