
(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 7 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 (* x a)))
double code(double a, double x) {
return expm1((x * a));
}
public static double code(double a, double x) {
return Math.expm1((x * a));
}
def code(a, x): return math.expm1((x * a))
function code(a, x) return expm1(Float64(x * a)) end
code[a_, x_] := N[(Exp[N[(x * a), $MachinePrecision]] - 1), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{expm1}\left(x \cdot a\right)
\end{array}
Initial program 55.1%
lift--.f64N/A
lift-exp.f64N/A
lower-expm1.f64100.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
(FPCore (a x)
:precision binary64
(if (<= (- (exp (* a x)) 1.0) -1.0)
(- (pow (fma (* x (fma x a -1.0)) a 1.0) -1.0) 1.0)
(*
(fma
(*
(fma (fma (* 0.041666666666666664 x) a 0.16666666666666666) (* x a) 0.5)
x)
a
1.0)
(* x a))))
double code(double a, double x) {
double tmp;
if ((exp((a * x)) - 1.0) <= -1.0) {
tmp = pow(fma((x * fma(x, a, -1.0)), a, 1.0), -1.0) - 1.0;
} else {
tmp = fma((fma(fma((0.041666666666666664 * x), a, 0.16666666666666666), (x * a), 0.5) * x), a, 1.0) * (x * a);
}
return tmp;
}
function code(a, x) tmp = 0.0 if (Float64(exp(Float64(a * x)) - 1.0) <= -1.0) tmp = Float64((fma(Float64(x * fma(x, a, -1.0)), a, 1.0) ^ -1.0) - 1.0); else tmp = Float64(fma(Float64(fma(fma(Float64(0.041666666666666664 * x), a, 0.16666666666666666), Float64(x * a), 0.5) * x), a, 1.0) * Float64(x * a)); end return tmp end
code[a_, x_] := If[LessEqual[N[(N[Exp[N[(a * x), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision], -1.0], N[(N[Power[N[(N[(x * N[(x * a + -1.0), $MachinePrecision]), $MachinePrecision] * a + 1.0), $MachinePrecision], -1.0], $MachinePrecision] - 1.0), $MachinePrecision], N[(N[(N[(N[(N[(N[(0.041666666666666664 * x), $MachinePrecision] * a + 0.16666666666666666), $MachinePrecision] * N[(x * a), $MachinePrecision] + 0.5), $MachinePrecision] * x), $MachinePrecision] * a + 1.0), $MachinePrecision] * N[(x * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{a \cdot x} - 1 \leq -1:\\
\;\;\;\;{\left(\mathsf{fma}\left(x \cdot \mathsf{fma}\left(x, a, -1\right), a, 1\right)\right)}^{-1} - 1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.041666666666666664 \cdot x, a, 0.16666666666666666\right), x \cdot a, 0.5\right) \cdot x, a, 1\right) \cdot \left(x \cdot a\right)\\
\end{array}
\end{array}
if (-.f64 (exp.f64 (*.f64 a x)) #s(literal 1 binary64)) < -1Initial program 100.0%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f645.2
Applied rewrites5.2%
Applied rewrites5.2%
Taylor expanded in a around 0
Applied rewrites98.0%
if -1 < (-.f64 (exp.f64 (*.f64 a x)) #s(literal 1 binary64)) Initial program 33.9%
Taylor expanded in a around 0
Applied rewrites100.0%
Final simplification99.3%
(FPCore (a x) :precision binary64 (if (<= (- (exp (* a x)) 1.0) -1.0) (- (pow (fma (* x (fma x a -1.0)) a 1.0) -1.0) 1.0) (* a (fma (* (* (fma a (* x 0.16666666666666666) 0.5) a) x) x x))))
double code(double a, double x) {
double tmp;
if ((exp((a * x)) - 1.0) <= -1.0) {
tmp = pow(fma((x * fma(x, a, -1.0)), a, 1.0), -1.0) - 1.0;
} else {
tmp = a * fma(((fma(a, (x * 0.16666666666666666), 0.5) * a) * x), x, x);
}
return tmp;
}
function code(a, x) tmp = 0.0 if (Float64(exp(Float64(a * x)) - 1.0) <= -1.0) tmp = Float64((fma(Float64(x * fma(x, a, -1.0)), a, 1.0) ^ -1.0) - 1.0); else tmp = Float64(a * fma(Float64(Float64(fma(a, Float64(x * 0.16666666666666666), 0.5) * a) * x), x, x)); end return tmp end
code[a_, x_] := If[LessEqual[N[(N[Exp[N[(a * x), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision], -1.0], N[(N[Power[N[(N[(x * N[(x * a + -1.0), $MachinePrecision]), $MachinePrecision] * a + 1.0), $MachinePrecision], -1.0], $MachinePrecision] - 1.0), $MachinePrecision], N[(a * N[(N[(N[(N[(a * N[(x * 0.16666666666666666), $MachinePrecision] + 0.5), $MachinePrecision] * a), $MachinePrecision] * x), $MachinePrecision] * x + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{a \cdot x} - 1 \leq -1:\\
\;\;\;\;{\left(\mathsf{fma}\left(x \cdot \mathsf{fma}\left(x, a, -1\right), a, 1\right)\right)}^{-1} - 1\\
\mathbf{else}:\\
\;\;\;\;a \cdot \mathsf{fma}\left(\left(\mathsf{fma}\left(a, x \cdot 0.16666666666666666, 0.5\right) \cdot a\right) \cdot x, x, x\right)\\
\end{array}
\end{array}
if (-.f64 (exp.f64 (*.f64 a x)) #s(literal 1 binary64)) < -1Initial program 100.0%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f645.2
Applied rewrites5.2%
Applied rewrites5.2%
Taylor expanded in a around 0
Applied rewrites98.0%
if -1 < (-.f64 (exp.f64 (*.f64 a x)) #s(literal 1 binary64)) Initial program 33.9%
Taylor expanded in a around 0
Applied rewrites99.8%
Applied rewrites99.8%
Applied rewrites99.8%
Final simplification99.2%
(FPCore (a x) :precision binary64 (if (<= (* a x) -50.0) (- (pow (fma (* x (fma x a -1.0)) a 1.0) -1.0) 1.0) (* (fma (* (* a x) a) 0.5 a) x)))
double code(double a, double x) {
double tmp;
if ((a * x) <= -50.0) {
tmp = pow(fma((x * fma(x, a, -1.0)), a, 1.0), -1.0) - 1.0;
} else {
tmp = fma(((a * x) * a), 0.5, a) * x;
}
return tmp;
}
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -50.0) tmp = Float64((fma(Float64(x * fma(x, a, -1.0)), a, 1.0) ^ -1.0) - 1.0); else tmp = Float64(fma(Float64(Float64(a * x) * a), 0.5, a) * x); end return tmp end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -50.0], N[(N[Power[N[(N[(x * N[(x * a + -1.0), $MachinePrecision]), $MachinePrecision] * a + 1.0), $MachinePrecision], -1.0], $MachinePrecision] - 1.0), $MachinePrecision], N[(N[(N[(N[(a * x), $MachinePrecision] * a), $MachinePrecision] * 0.5 + a), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -50:\\
\;\;\;\;{\left(\mathsf{fma}\left(x \cdot \mathsf{fma}\left(x, a, -1\right), a, 1\right)\right)}^{-1} - 1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(a \cdot x\right) \cdot a, 0.5, a\right) \cdot x\\
\end{array}
\end{array}
if (*.f64 a x) < -50Initial program 100.0%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f645.2
Applied rewrites5.2%
Applied rewrites5.2%
Taylor expanded in a around 0
Applied rewrites98.0%
if -50 < (*.f64 a x) Initial program 33.9%
Taylor expanded in a around 0
distribute-lft-inN/A
associate-*r*N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
distribute-rgt1-inN/A
*-commutativeN/A
associate-*r*N/A
distribute-rgt1-inN/A
associate-*r*N/A
associate-*l*N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites92.2%
Applied rewrites99.4%
Final simplification98.9%
(FPCore (a x) :precision binary64 (if (<= (* a x) -50.0) (- (pow (- 1.0 (* x a)) -1.0) 1.0) (* (fma (* (* a x) a) 0.5 a) x)))
double code(double a, double x) {
double tmp;
if ((a * x) <= -50.0) {
tmp = pow((1.0 - (x * a)), -1.0) - 1.0;
} else {
tmp = fma(((a * x) * a), 0.5, a) * x;
}
return tmp;
}
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -50.0) tmp = Float64((Float64(1.0 - Float64(x * a)) ^ -1.0) - 1.0); else tmp = Float64(fma(Float64(Float64(a * x) * a), 0.5, a) * x); end return tmp end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -50.0], N[(N[Power[N[(1.0 - N[(x * a), $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision] - 1.0), $MachinePrecision], N[(N[(N[(N[(a * x), $MachinePrecision] * a), $MachinePrecision] * 0.5 + a), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -50:\\
\;\;\;\;{\left(1 - x \cdot a\right)}^{-1} - 1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(a \cdot x\right) \cdot a, 0.5, a\right) \cdot x\\
\end{array}
\end{array}
if (*.f64 a x) < -50Initial program 100.0%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f645.2
Applied rewrites5.2%
Applied rewrites5.2%
Taylor expanded in a around 0
Applied rewrites96.0%
if -50 < (*.f64 a x) Initial program 33.9%
Taylor expanded in a around 0
distribute-lft-inN/A
associate-*r*N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
distribute-rgt1-inN/A
*-commutativeN/A
associate-*r*N/A
distribute-rgt1-inN/A
associate-*r*N/A
associate-*l*N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites92.2%
Applied rewrites99.4%
Final simplification98.3%
(FPCore (a x) :precision binary64 (* x a))
double code(double a, double x) {
return x * a;
}
real(8) function code(a, x)
real(8), intent (in) :: a
real(8), intent (in) :: x
code = x * a
end function
public static double code(double a, double x) {
return x * a;
}
def code(a, x): return x * a
function code(a, x) return Float64(x * a) end
function tmp = code(a, x) tmp = x * a; end
code[a_, x_] := N[(x * a), $MachinePrecision]
\begin{array}{l}
\\
x \cdot a
\end{array}
Initial program 55.1%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f6468.2
Applied rewrites68.2%
(FPCore (a x) :precision binary64 (- 1.0 1.0))
double code(double a, double x) {
return 1.0 - 1.0;
}
real(8) function code(a, x)
real(8), intent (in) :: a
real(8), intent (in) :: x
code = 1.0d0 - 1.0d0
end function
public static double code(double a, double x) {
return 1.0 - 1.0;
}
def code(a, x): return 1.0 - 1.0
function code(a, x) return Float64(1.0 - 1.0) end
function tmp = code(a, x) tmp = 1.0 - 1.0; end
code[a_, x_] := N[(1.0 - 1.0), $MachinePrecision]
\begin{array}{l}
\\
1 - 1
\end{array}
Initial program 55.1%
Taylor expanded in a around 0
Applied rewrites22.0%
(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 2024324
(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))