
(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 9 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 53.1%
accelerator-lowering-expm1.f64N/A
*-lowering-*.f64100.0
Applied egg-rr100.0%
(FPCore (a x) :precision binary64 (if (<= (* a x) -5.0) -1.0 (* a (fma (* (* a x) (fma a (* x 0.16666666666666666) 0.5)) x x))))
double code(double a, double x) {
double tmp;
if ((a * x) <= -5.0) {
tmp = -1.0;
} else {
tmp = a * fma(((a * x) * fma(a, (x * 0.16666666666666666), 0.5)), x, x);
}
return tmp;
}
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -5.0) tmp = -1.0; else tmp = Float64(a * fma(Float64(Float64(a * x) * fma(a, Float64(x * 0.16666666666666666), 0.5)), x, x)); end return tmp end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -5.0], -1.0, N[(a * N[(N[(N[(a * x), $MachinePrecision] * N[(a * N[(x * 0.16666666666666666), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision] * x + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -5:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;a \cdot \mathsf{fma}\left(\left(a \cdot x\right) \cdot \mathsf{fma}\left(a, x \cdot 0.16666666666666666, 0.5\right), x, x\right)\\
\end{array}
\end{array}
if (*.f64 a x) < -5Initial program 100.0%
Taylor expanded in a around 0
+-commutativeN/A
accelerator-lowering-fma.f645.3
Simplified5.3%
flip-+N/A
/-lowering-/.f64N/A
metadata-evalN/A
sub-negN/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
metadata-evalN/A
sub-negN/A
accelerator-lowering-fma.f64N/A
metadata-eval9.1
Applied egg-rr9.1%
Taylor expanded in a around 0
Simplified96.1%
Taylor expanded in a around inf
Simplified98.8%
if -5 < (*.f64 a x) Initial program 28.6%
Taylor expanded in a around 0
*-lowering-*.f64N/A
+-commutativeN/A
+-commutativeN/A
associate-*r*N/A
cube-multN/A
unpow2N/A
associate-*r*N/A
distribute-rgt-outN/A
associate-*r*N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
Simplified93.0%
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6499.8
Applied egg-rr99.8%
Final simplification99.5%
(FPCore (a x) :precision binary64 (if (<= (* a x) -5.0) -1.0 (fma x a (* a (* 0.5 (* x (* a x)))))))
double code(double a, double x) {
double tmp;
if ((a * x) <= -5.0) {
tmp = -1.0;
} else {
tmp = fma(x, a, (a * (0.5 * (x * (a * x)))));
}
return tmp;
}
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -5.0) tmp = -1.0; else tmp = fma(x, a, Float64(a * Float64(0.5 * Float64(x * Float64(a * x))))); end return tmp end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -5.0], -1.0, N[(x * a + N[(a * N[(0.5 * N[(x * N[(a * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -5:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, a, a \cdot \left(0.5 \cdot \left(x \cdot \left(a \cdot x\right)\right)\right)\right)\\
\end{array}
\end{array}
if (*.f64 a x) < -5Initial program 100.0%
Taylor expanded in a around 0
+-commutativeN/A
accelerator-lowering-fma.f645.3
Simplified5.3%
flip-+N/A
/-lowering-/.f64N/A
metadata-evalN/A
sub-negN/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
metadata-evalN/A
sub-negN/A
accelerator-lowering-fma.f64N/A
metadata-eval9.1
Applied egg-rr9.1%
Taylor expanded in a around 0
Simplified96.1%
Taylor expanded in a around inf
Simplified98.8%
if -5 < (*.f64 a x) Initial program 28.6%
Taylor expanded in a around 0
*-lowering-*.f64N/A
+-commutativeN/A
+-commutativeN/A
associate-*r*N/A
cube-multN/A
unpow2N/A
associate-*r*N/A
distribute-rgt-outN/A
associate-*r*N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
Simplified93.0%
Taylor expanded in a around 0
Simplified92.9%
+-commutativeN/A
distribute-rgt-inN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f6499.7
Applied egg-rr99.7%
Final simplification99.4%
(FPCore (a x) :precision binary64 (if (<= (* a x) -5.0) -1.0 (* x (fma (* a (* x 0.5)) a a))))
double code(double a, double x) {
double tmp;
if ((a * x) <= -5.0) {
tmp = -1.0;
} else {
tmp = x * fma((a * (x * 0.5)), a, a);
}
return tmp;
}
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -5.0) tmp = -1.0; else tmp = Float64(x * fma(Float64(a * Float64(x * 0.5)), a, a)); end return tmp end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -5.0], -1.0, N[(x * N[(N[(a * N[(x * 0.5), $MachinePrecision]), $MachinePrecision] * a + a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -5:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;x \cdot \mathsf{fma}\left(a \cdot \left(x \cdot 0.5\right), a, a\right)\\
\end{array}
\end{array}
if (*.f64 a x) < -5Initial program 100.0%
Taylor expanded in a around 0
+-commutativeN/A
accelerator-lowering-fma.f645.3
Simplified5.3%
flip-+N/A
/-lowering-/.f64N/A
metadata-evalN/A
sub-negN/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
metadata-evalN/A
sub-negN/A
accelerator-lowering-fma.f64N/A
metadata-eval9.1
Applied egg-rr9.1%
Taylor expanded in a around 0
Simplified96.1%
Taylor expanded in a around inf
Simplified98.8%
if -5 < (*.f64 a x) Initial program 28.6%
accelerator-lowering-expm1.f64N/A
*-lowering-*.f64100.0
Applied egg-rr100.0%
+-rgt-identityN/A
metadata-evalN/A
associate--l+N/A
flip--N/A
clear-numN/A
/-lowering-/.f64N/A
clear-numN/A
flip--N/A
associate--l+N/A
metadata-evalN/A
+-rgt-identityN/A
/-lowering-/.f64N/A
*-lowering-*.f6499.0
Applied egg-rr99.0%
Taylor expanded in a around 0
distribute-rgt-inN/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
unpow2N/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
associate-*l*N/A
distribute-rgt-inN/A
*-lowering-*.f64N/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6493.1
Simplified93.1%
associate-*r*N/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6499.7
Applied egg-rr99.7%
Final simplification99.4%
(FPCore (a x) :precision binary64 (if (<= (* a x) -5.0) -1.0 (* a (fma (* x (* a x)) 0.5 x))))
double code(double a, double x) {
double tmp;
if ((a * x) <= -5.0) {
tmp = -1.0;
} else {
tmp = a * fma((x * (a * x)), 0.5, x);
}
return tmp;
}
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -5.0) tmp = -1.0; else tmp = Float64(a * fma(Float64(x * Float64(a * x)), 0.5, x)); end return tmp end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -5.0], -1.0, N[(a * N[(N[(x * N[(a * x), $MachinePrecision]), $MachinePrecision] * 0.5 + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -5:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;a \cdot \mathsf{fma}\left(x \cdot \left(a \cdot x\right), 0.5, x\right)\\
\end{array}
\end{array}
if (*.f64 a x) < -5Initial program 100.0%
Taylor expanded in a around 0
+-commutativeN/A
accelerator-lowering-fma.f645.3
Simplified5.3%
flip-+N/A
/-lowering-/.f64N/A
metadata-evalN/A
sub-negN/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
metadata-evalN/A
sub-negN/A
accelerator-lowering-fma.f64N/A
metadata-eval9.1
Applied egg-rr9.1%
Taylor expanded in a around 0
Simplified96.1%
Taylor expanded in a around inf
Simplified98.8%
if -5 < (*.f64 a x) Initial program 28.6%
Taylor expanded in a around 0
*-lowering-*.f64N/A
+-commutativeN/A
+-commutativeN/A
associate-*r*N/A
cube-multN/A
unpow2N/A
associate-*r*N/A
distribute-rgt-outN/A
associate-*r*N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
Simplified93.0%
Taylor expanded in a around 0
Simplified92.9%
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f6499.7
Applied egg-rr99.7%
Final simplification99.4%
(FPCore (a x) :precision binary64 (if (<= (* a x) -5.0) -1.0 (* x (fma a (* a x) a))))
double code(double a, double x) {
double tmp;
if ((a * x) <= -5.0) {
tmp = -1.0;
} else {
tmp = x * fma(a, (a * x), a);
}
return tmp;
}
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -5.0) tmp = -1.0; else tmp = Float64(x * fma(a, Float64(a * x), a)); end return tmp end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -5.0], -1.0, N[(x * N[(a * N[(a * x), $MachinePrecision] + a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -5:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;x \cdot \mathsf{fma}\left(a, a \cdot x, a\right)\\
\end{array}
\end{array}
if (*.f64 a x) < -5Initial program 100.0%
Taylor expanded in a around 0
+-commutativeN/A
accelerator-lowering-fma.f645.3
Simplified5.3%
flip-+N/A
/-lowering-/.f64N/A
metadata-evalN/A
sub-negN/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
metadata-evalN/A
sub-negN/A
accelerator-lowering-fma.f64N/A
metadata-eval9.1
Applied egg-rr9.1%
Taylor expanded in a around 0
Simplified96.1%
Taylor expanded in a around inf
Simplified98.8%
if -5 < (*.f64 a x) Initial program 28.6%
Taylor expanded in a around 0
+-commutativeN/A
accelerator-lowering-fma.f6428.3
Simplified28.3%
flip-+N/A
/-lowering-/.f64N/A
metadata-evalN/A
sub-negN/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
metadata-evalN/A
sub-negN/A
accelerator-lowering-fma.f64N/A
metadata-eval27.7
Applied egg-rr27.7%
Taylor expanded in a around 0
Simplified28.2%
Taylor expanded in a around 0
distribute-lft-inN/A
associate-*r*N/A
unpow2N/A
unpow2N/A
associate-*r*N/A
distribute-rgt-inN/A
*-lowering-*.f64N/A
+-commutativeN/A
unpow2N/A
associate-*l*N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6498.6
Simplified98.6%
(FPCore (a x) :precision binary64 (if (<= (* a x) -5.0) -1.0 (* a x)))
double code(double a, double x) {
double tmp;
if ((a * x) <= -5.0) {
tmp = -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 * x) <= (-5.0d0)) then
tmp = -1.0d0
else
tmp = a * x
end if
code = tmp
end function
public static double code(double a, double x) {
double tmp;
if ((a * x) <= -5.0) {
tmp = -1.0;
} else {
tmp = a * x;
}
return tmp;
}
def code(a, x): tmp = 0 if (a * x) <= -5.0: tmp = -1.0 else: tmp = a * x return tmp
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -5.0) tmp = -1.0; else tmp = Float64(a * x); end return tmp end
function tmp_2 = code(a, x) tmp = 0.0; if ((a * x) <= -5.0) tmp = -1.0; else tmp = a * x; end tmp_2 = tmp; end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -5.0], -1.0, N[(a * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -5:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;a \cdot x\\
\end{array}
\end{array}
if (*.f64 a x) < -5Initial program 100.0%
Taylor expanded in a around 0
+-commutativeN/A
accelerator-lowering-fma.f645.3
Simplified5.3%
flip-+N/A
/-lowering-/.f64N/A
metadata-evalN/A
sub-negN/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
metadata-evalN/A
sub-negN/A
accelerator-lowering-fma.f64N/A
metadata-eval9.1
Applied egg-rr9.1%
Taylor expanded in a around 0
Simplified96.1%
Taylor expanded in a around inf
Simplified98.8%
if -5 < (*.f64 a x) Initial program 28.6%
Taylor expanded in a around 0
*-lowering-*.f6498.6
Simplified98.6%
(FPCore (a x) :precision binary64 (if (<= (* a x) -1.1e-154) -1.0 0.0))
double code(double a, double x) {
double tmp;
if ((a * x) <= -1.1e-154) {
tmp = -1.0;
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(a, x)
real(8), intent (in) :: a
real(8), intent (in) :: x
real(8) :: tmp
if ((a * x) <= (-1.1d-154)) then
tmp = -1.0d0
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double a, double x) {
double tmp;
if ((a * x) <= -1.1e-154) {
tmp = -1.0;
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, x): tmp = 0 if (a * x) <= -1.1e-154: tmp = -1.0 else: tmp = 0.0 return tmp
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -1.1e-154) tmp = -1.0; else tmp = 0.0; end return tmp end
function tmp_2 = code(a, x) tmp = 0.0; if ((a * x) <= -1.1e-154) tmp = -1.0; else tmp = 0.0; end tmp_2 = tmp; end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -1.1e-154], -1.0, 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -1.1 \cdot 10^{-154}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if (*.f64 a x) < -1.10000000000000004e-154Initial program 74.4%
Taylor expanded in a around 0
+-commutativeN/A
accelerator-lowering-fma.f646.2
Simplified6.2%
flip-+N/A
/-lowering-/.f64N/A
metadata-evalN/A
sub-negN/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
metadata-evalN/A
sub-negN/A
accelerator-lowering-fma.f64N/A
metadata-eval8.6
Applied egg-rr8.6%
Taylor expanded in a around 0
Simplified71.1%
Taylor expanded in a around inf
Simplified72.7%
if -1.10000000000000004e-154 < (*.f64 a x) Initial program 33.4%
Taylor expanded in a around 0
Simplified32.3%
metadata-eval32.3
Applied egg-rr32.3%
(FPCore (a x) :precision binary64 -1.0)
double code(double a, double x) {
return -1.0;
}
real(8) function code(a, x)
real(8), intent (in) :: a
real(8), intent (in) :: x
code = -1.0d0
end function
public static double code(double a, double x) {
return -1.0;
}
def code(a, x): return -1.0
function code(a, x) return -1.0 end
function tmp = code(a, x) tmp = -1.0; end
code[a_, x_] := -1.0
\begin{array}{l}
\\
-1
\end{array}
Initial program 53.1%
Taylor expanded in a around 0
+-commutativeN/A
accelerator-lowering-fma.f6420.4
Simplified20.4%
flip-+N/A
/-lowering-/.f64N/A
metadata-evalN/A
sub-negN/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
metadata-evalN/A
sub-negN/A
accelerator-lowering-fma.f64N/A
metadata-eval21.3
Applied egg-rr21.3%
Taylor expanded in a around 0
Simplified51.5%
Taylor expanded in a around inf
Simplified36.4%
(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 2024198
(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))