
(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 x))) (+ (pow (exp 2.0) (* 0.5 (* a x))) 1.0)))
double code(double a, double x) {
return expm1((a * (x + x))) / (pow(exp(2.0), (0.5 * (a * x))) + 1.0);
}
public static double code(double a, double x) {
return Math.expm1((a * (x + x))) / (Math.pow(Math.exp(2.0), (0.5 * (a * x))) + 1.0);
}
def code(a, x): return math.expm1((a * (x + x))) / (math.pow(math.exp(2.0), (0.5 * (a * x))) + 1.0)
function code(a, x) return Float64(expm1(Float64(a * Float64(x + x))) / Float64((exp(2.0) ^ Float64(0.5 * Float64(a * x))) + 1.0)) end
code[a_, x_] := N[(N[(Exp[N[(a * N[(x + x), $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision] / N[(N[Power[N[Exp[2.0], $MachinePrecision], N[(0.5 * N[(a * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{{\left(e^{2}\right)}^{\left(0.5 \cdot \left(a \cdot x\right)\right)} + 1}
\end{array}
Initial program 50.6%
lift-*.f64N/A
lift-exp.f64N/A
flip--N/A
lower-/.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
prod-expN/A
metadata-evalN/A
lower-expm1.f64N/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-outN/A
lower-*.f64N/A
lower-+.f64N/A
lower-+.f64100.0
Applied rewrites100.0%
exp-prodN/A
sqr-powN/A
pow2N/A
lower-pow.f64N/A
pow-expN/A
lower-exp.f64N/A
lower-*.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f64100.0
Applied rewrites100.0%
lift-*.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
unpow1N/A
metadata-evalN/A
metadata-evalN/A
unpow1N/A
lift-exp.f64N/A
pow-expN/A
*-commutativeN/A
exp-prodN/A
lower-pow.f64N/A
lower-exp.f64100.0
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.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}
Initial program 50.6%
lift-*.f64N/A
lower-expm1.f64100.0
Applied rewrites100.0%
(FPCore (a x)
:precision binary64
(if (<= (* a x) -20000.0)
(+ (/ -1.0 (fma a x -1.0)) -1.0)
(fma
(* a (* a x))
(*
x
(fma a (* x (fma a (* x 0.041666666666666664) 0.16666666666666666)) 0.5))
(* a x))))
double code(double a, double x) {
double tmp;
if ((a * x) <= -20000.0) {
tmp = (-1.0 / fma(a, x, -1.0)) + -1.0;
} else {
tmp = fma((a * (a * x)), (x * fma(a, (x * fma(a, (x * 0.041666666666666664), 0.16666666666666666)), 0.5)), (a * x));
}
return tmp;
}
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -20000.0) tmp = Float64(Float64(-1.0 / fma(a, x, -1.0)) + -1.0); else tmp = fma(Float64(a * Float64(a * x)), Float64(x * fma(a, Float64(x * fma(a, Float64(x * 0.041666666666666664), 0.16666666666666666)), 0.5)), Float64(a * x)); end return tmp end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -20000.0], N[(N[(-1.0 / N[(a * x + -1.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(a * N[(a * x), $MachinePrecision]), $MachinePrecision] * N[(x * N[(a * N[(x * N[(a * N[(x * 0.041666666666666664), $MachinePrecision] + 0.16666666666666666), $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision] + N[(a * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -20000:\\
\;\;\;\;\frac{-1}{\mathsf{fma}\left(a, x, -1\right)} + -1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a \cdot \left(a \cdot x\right), x \cdot \mathsf{fma}\left(a, x \cdot \mathsf{fma}\left(a, x \cdot 0.041666666666666664, 0.16666666666666666\right), 0.5\right), a \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 a x) < -2e4Initial program 100.0%
Taylor expanded in a around 0
+-commutativeN/A
lower-fma.f645.1
Applied rewrites5.1%
lift-*.f64N/A
flip-+N/A
lower-/.f64N/A
metadata-evalN/A
sub-negN/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lift-*.f64N/A
lift-*.f64N/A
lower-fma.f64N/A
metadata-evalN/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
metadata-eval8.5
Applied rewrites8.5%
Taylor expanded in a around 0
Applied rewrites98.4%
if -2e4 < (*.f64 a x) Initial program 25.7%
Taylor expanded in a around 0
Applied rewrites90.6%
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-inN/A
lift-*.f64N/A
Applied rewrites99.1%
Final simplification98.9%
(FPCore (a x)
:precision binary64
(if (<= (* a x) -20000.0)
(+ (/ -1.0 (fma a x -1.0)) -1.0)
(*
a
(fma
(*
(* a x)
(fma a (* x (fma a (* x 0.041666666666666664) 0.16666666666666666)) 0.5))
x
x))))
double code(double a, double x) {
double tmp;
if ((a * x) <= -20000.0) {
tmp = (-1.0 / fma(a, x, -1.0)) + -1.0;
} else {
tmp = a * fma(((a * x) * fma(a, (x * fma(a, (x * 0.041666666666666664), 0.16666666666666666)), 0.5)), x, x);
}
return tmp;
}
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -20000.0) tmp = Float64(Float64(-1.0 / fma(a, x, -1.0)) + -1.0); else tmp = Float64(a * fma(Float64(Float64(a * x) * fma(a, Float64(x * fma(a, Float64(x * 0.041666666666666664), 0.16666666666666666)), 0.5)), x, x)); end return tmp end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -20000.0], N[(N[(-1.0 / N[(a * x + -1.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(a * N[(N[(N[(a * x), $MachinePrecision] * N[(a * N[(x * N[(a * N[(x * 0.041666666666666664), $MachinePrecision] + 0.16666666666666666), $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision] * x + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -20000:\\
\;\;\;\;\frac{-1}{\mathsf{fma}\left(a, x, -1\right)} + -1\\
\mathbf{else}:\\
\;\;\;\;a \cdot \mathsf{fma}\left(\left(a \cdot x\right) \cdot \mathsf{fma}\left(a, x \cdot \mathsf{fma}\left(a, x \cdot 0.041666666666666664, 0.16666666666666666\right), 0.5\right), x, x\right)\\
\end{array}
\end{array}
if (*.f64 a x) < -2e4Initial program 100.0%
Taylor expanded in a around 0
+-commutativeN/A
lower-fma.f645.1
Applied rewrites5.1%
lift-*.f64N/A
flip-+N/A
lower-/.f64N/A
metadata-evalN/A
sub-negN/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lift-*.f64N/A
lift-*.f64N/A
lower-fma.f64N/A
metadata-evalN/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
metadata-eval8.5
Applied rewrites8.5%
Taylor expanded in a around 0
Applied rewrites98.4%
if -2e4 < (*.f64 a x) Initial program 25.7%
Taylor expanded in a around 0
Applied rewrites90.6%
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-*.f64N/A
Applied rewrites99.1%
Final simplification98.9%
(FPCore (a x) :precision binary64 (if (<= (* a x) -20000.0) (+ (/ -1.0 (fma a x -1.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) <= -20000.0) {
tmp = (-1.0 / fma(a, x, -1.0)) + -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) <= -20000.0) tmp = Float64(Float64(-1.0 / fma(a, x, -1.0)) + -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], -20000.0], N[(N[(-1.0 / N[(a * x + -1.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], 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 -20000:\\
\;\;\;\;\frac{-1}{\mathsf{fma}\left(a, x, -1\right)} + -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) < -2e4Initial program 100.0%
Taylor expanded in a around 0
+-commutativeN/A
lower-fma.f645.1
Applied rewrites5.1%
lift-*.f64N/A
flip-+N/A
lower-/.f64N/A
metadata-evalN/A
sub-negN/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lift-*.f64N/A
lift-*.f64N/A
lower-fma.f64N/A
metadata-evalN/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
metadata-eval8.5
Applied rewrites8.5%
Taylor expanded in a around 0
Applied rewrites98.4%
if -2e4 < (*.f64 a x) Initial program 25.7%
Taylor expanded in a around 0
lower-*.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
lower-fma.f64N/A
Applied rewrites90.6%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6499.1
Applied rewrites99.1%
Final simplification98.9%
(FPCore (a x) :precision binary64 (if (<= (* a x) -20000.0) (+ (/ -1.0 (fma a x -1.0)) -1.0) (* a (fma x (* a (* x 0.5)) x))))
double code(double a, double x) {
double tmp;
if ((a * x) <= -20000.0) {
tmp = (-1.0 / fma(a, x, -1.0)) + -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) <= -20000.0) tmp = Float64(Float64(-1.0 / fma(a, x, -1.0)) + -1.0); else tmp = Float64(a * fma(x, Float64(a * Float64(x * 0.5)), x)); end return tmp end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -20000.0], N[(N[(-1.0 / N[(a * x + -1.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(a * N[(x * N[(a * N[(x * 0.5), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -20000:\\
\;\;\;\;\frac{-1}{\mathsf{fma}\left(a, x, -1\right)} + -1\\
\mathbf{else}:\\
\;\;\;\;a \cdot \mathsf{fma}\left(x, a \cdot \left(x \cdot 0.5\right), x\right)\\
\end{array}
\end{array}
if (*.f64 a x) < -2e4Initial program 100.0%
Taylor expanded in a around 0
+-commutativeN/A
lower-fma.f645.1
Applied rewrites5.1%
lift-*.f64N/A
flip-+N/A
lower-/.f64N/A
metadata-evalN/A
sub-negN/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lift-*.f64N/A
lift-*.f64N/A
lower-fma.f64N/A
metadata-evalN/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
metadata-eval8.5
Applied rewrites8.5%
Taylor expanded in a around 0
Applied rewrites98.4%
if -2e4 < (*.f64 a x) Initial program 25.7%
lift-*.f64N/A
lift-exp.f64N/A
flip--N/A
lower-/.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
prod-expN/A
metadata-evalN/A
lower-expm1.f64N/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-outN/A
lower-*.f64N/A
lower-+.f64N/A
lower-+.f6499.9
Applied rewrites99.9%
exp-prodN/A
sqr-powN/A
pow2N/A
lower-pow.f64N/A
pow-expN/A
lower-exp.f64N/A
lower-*.f64N/A
div-invN/A
metadata-evalN/A
lower-*.f6499.9
Applied rewrites99.9%
Taylor expanded in a around 0
distribute-rgt-inN/A
*-commutativeN/A
cancel-sign-sub-invN/A
metadata-evalN/A
distribute-rgt1-inN/A
metadata-evalN/A
associate-*r*N/A
*-commutativeN/A
distribute-rgt-inN/A
distribute-lft-inN/A
*-commutativeN/A
associate-*r*N/A
distribute-lft-outN/A
lower-*.f64N/A
+-commutativeN/A
Applied rewrites99.0%
Final simplification98.8%
(FPCore (a x) :precision binary64 (if (<= (* a x) -20000.0) (+ (/ -1.0 (fma a x -1.0)) -1.0) (* a x)))
double code(double a, double x) {
double tmp;
if ((a * x) <= -20000.0) {
tmp = (-1.0 / fma(a, x, -1.0)) + -1.0;
} else {
tmp = a * x;
}
return tmp;
}
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -20000.0) tmp = Float64(Float64(-1.0 / fma(a, x, -1.0)) + -1.0); else tmp = Float64(a * x); end return tmp end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -20000.0], N[(N[(-1.0 / N[(a * x + -1.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(a * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -20000:\\
\;\;\;\;\frac{-1}{\mathsf{fma}\left(a, x, -1\right)} + -1\\
\mathbf{else}:\\
\;\;\;\;a \cdot x\\
\end{array}
\end{array}
if (*.f64 a x) < -2e4Initial program 100.0%
Taylor expanded in a around 0
+-commutativeN/A
lower-fma.f645.1
Applied rewrites5.1%
lift-*.f64N/A
flip-+N/A
lower-/.f64N/A
metadata-evalN/A
sub-negN/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lift-*.f64N/A
lift-*.f64N/A
lower-fma.f64N/A
metadata-evalN/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
metadata-eval8.5
Applied rewrites8.5%
Taylor expanded in a around 0
Applied rewrites98.4%
if -2e4 < (*.f64 a x) Initial program 25.7%
Taylor expanded in a around 0
lower-*.f6498.7
Applied rewrites98.7%
Final simplification98.6%
(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 50.6%
Taylor expanded in a around 0
lower-*.f6467.2
Applied rewrites67.2%
(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 50.6%
Taylor expanded in a around 0
Applied rewrites17.0%
metadata-eval17.0
Applied rewrites17.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 2024219
(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))