
(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 8 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 48.8%
accelerator-lowering-expm1.f64N/A
*-lowering-*.f64100.0
Applied egg-rr100.0%
(FPCore (a x)
:precision binary64
(if (<= (* a x) -10.0)
-1.0
(*
a
(fma
(*
(* a x)
(fma (* a x) (fma x (* a 0.041666666666666664) 0.16666666666666666) 0.5))
x
x))))
double code(double a, double x) {
double tmp;
if ((a * x) <= -10.0) {
tmp = -1.0;
} else {
tmp = a * fma(((a * x) * fma((a * x), fma(x, (a * 0.041666666666666664), 0.16666666666666666), 0.5)), x, x);
}
return tmp;
}
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -10.0) tmp = -1.0; else tmp = Float64(a * fma(Float64(Float64(a * x) * fma(Float64(a * x), fma(x, Float64(a * 0.041666666666666664), 0.16666666666666666), 0.5)), x, x)); end return tmp end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -10.0], -1.0, N[(a * N[(N[(N[(a * x), $MachinePrecision] * N[(N[(a * x), $MachinePrecision] * N[(x * N[(a * 0.041666666666666664), $MachinePrecision] + 0.16666666666666666), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision] * x + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -10:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;a \cdot \mathsf{fma}\left(\left(a \cdot x\right) \cdot \mathsf{fma}\left(a \cdot x, \mathsf{fma}\left(x, a \cdot 0.041666666666666664, 0.16666666666666666\right), 0.5\right), x, x\right)\\
\end{array}
\end{array}
if (*.f64 a x) < -10Initial program 100.0%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f641.5
Simplified1.5%
Taylor expanded in a around inf
associate-*r*N/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6410.2
Simplified10.2%
Taylor expanded in x around 0
Simplified99.3%
if -10 < (*.f64 a x) Initial program 27.9%
Taylor expanded in a around 0
Simplified92.0%
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
associate-*l*N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64100.0
Applied egg-rr100.0%
Final simplification99.8%
(FPCore (a x) :precision binary64 (if (<= (* a x) -10.0) -1.0 (* a (fma (* a x) (* x (fma (* a x) 0.16666666666666666 0.5)) x))))
double code(double a, double x) {
double tmp;
if ((a * x) <= -10.0) {
tmp = -1.0;
} else {
tmp = a * fma((a * x), (x * fma((a * x), 0.16666666666666666, 0.5)), x);
}
return tmp;
}
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -10.0) tmp = -1.0; else tmp = Float64(a * fma(Float64(a * x), Float64(x * fma(Float64(a * x), 0.16666666666666666, 0.5)), x)); end return tmp end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -10.0], -1.0, N[(a * N[(N[(a * x), $MachinePrecision] * N[(x * N[(N[(a * x), $MachinePrecision] * 0.16666666666666666 + 0.5), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -10:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;a \cdot \mathsf{fma}\left(a \cdot x, x \cdot \mathsf{fma}\left(a \cdot x, 0.16666666666666666, 0.5\right), x\right)\\
\end{array}
\end{array}
if (*.f64 a x) < -10Initial program 100.0%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f641.5
Simplified1.5%
Taylor expanded in a around inf
associate-*r*N/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6410.2
Simplified10.2%
Taylor expanded in x around 0
Simplified99.3%
if -10 < (*.f64 a x) Initial program 27.9%
Taylor expanded in a around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
Simplified26.6%
associate--l+N/A
metadata-evalN/A
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f64N/A
associate-*r*N/A
associate-*l*N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6499.8
Applied egg-rr99.8%
Final simplification99.6%
(FPCore (a x) :precision binary64 (if (<= (* a x) -10.0) -1.0 (fma x a (* a (* 0.5 (* x (* a x)))))))
double code(double a, double x) {
double tmp;
if ((a * x) <= -10.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) <= -10.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], -10.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 -10:\\
\;\;\;\;-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) < -10Initial program 100.0%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f641.5
Simplified1.5%
Taylor expanded in a around inf
associate-*r*N/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6410.2
Simplified10.2%
Taylor expanded in x around 0
Simplified99.3%
if -10 < (*.f64 a x) Initial program 27.9%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6426.5
Simplified26.5%
associate--l+N/A
metadata-evalN/A
+-rgt-identityN/A
+-commutativeN/A
distribute-rgt-inN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f6499.4
Applied egg-rr99.4%
(FPCore (a x) :precision binary64 (if (<= (* a x) -10.0) -1.0 (* a (fma 0.5 (* x (* a x)) x))))
double code(double a, double x) {
double tmp;
if ((a * x) <= -10.0) {
tmp = -1.0;
} else {
tmp = a * fma(0.5, (x * (a * x)), x);
}
return tmp;
}
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -10.0) tmp = -1.0; else tmp = Float64(a * fma(0.5, Float64(x * Float64(a * x)), x)); end return tmp end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -10.0], -1.0, N[(a * N[(0.5 * N[(x * N[(a * x), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -10:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;a \cdot \mathsf{fma}\left(0.5, x \cdot \left(a \cdot x\right), x\right)\\
\end{array}
\end{array}
if (*.f64 a x) < -10Initial program 100.0%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f641.5
Simplified1.5%
Taylor expanded in a around inf
associate-*r*N/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6410.2
Simplified10.2%
Taylor expanded in x around 0
Simplified99.3%
if -10 < (*.f64 a x) Initial program 27.9%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6426.5
Simplified26.5%
associate--l+N/A
metadata-evalN/A
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f6499.4
Applied egg-rr99.4%
Final simplification99.3%
(FPCore (a x) :precision binary64 (if (<= (* a x) -10.0) -1.0 (* a x)))
double code(double a, double x) {
double tmp;
if ((a * x) <= -10.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) <= (-10.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) <= -10.0) {
tmp = -1.0;
} else {
tmp = a * x;
}
return tmp;
}
def code(a, x): tmp = 0 if (a * x) <= -10.0: tmp = -1.0 else: tmp = a * x return tmp
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -10.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) <= -10.0) tmp = -1.0; else tmp = a * x; end tmp_2 = tmp; end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -10.0], -1.0, N[(a * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -10:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;a \cdot x\\
\end{array}
\end{array}
if (*.f64 a x) < -10Initial program 100.0%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f641.5
Simplified1.5%
Taylor expanded in a around inf
associate-*r*N/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6410.2
Simplified10.2%
Taylor expanded in x around 0
Simplified99.3%
if -10 < (*.f64 a x) Initial program 27.9%
Taylor expanded in a around 0
*-lowering-*.f6497.9
Simplified97.9%
(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 63.1%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f643.9
Simplified3.9%
Taylor expanded in a around inf
associate-*r*N/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f648.3
Simplified8.3%
Taylor expanded in x around 0
Simplified61.6%
if -1.10000000000000004e-154 < (*.f64 a x) Initial program 35.1%
Taylor expanded in a around 0
Simplified32.7%
metadata-eval32.7
Applied egg-rr32.7%
(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 48.8%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6419.3
Simplified19.3%
Taylor expanded in a around inf
associate-*r*N/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f645.4
Simplified5.4%
Taylor expanded in x around 0
Simplified31.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 2024199
(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))