
(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 (* 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.9%
lift--.f64N/A
lift-exp.f64N/A
lower-expm1.f64100.0
Applied rewrites100.0%
(FPCore (a x)
:precision binary64
(if (<= (* a x) -2e+101)
(/ 1.0 -0.5)
(if (<= (* a x) -4e+18)
(+ (* a (* a (* x (* x 0.5)))) -1.0)
(* a (fma (* x (* a 0.5)) x x)))))
double code(double a, double x) {
double tmp;
if ((a * x) <= -2e+101) {
tmp = 1.0 / -0.5;
} else if ((a * x) <= -4e+18) {
tmp = (a * (a * (x * (x * 0.5)))) + -1.0;
} else {
tmp = a * fma((x * (a * 0.5)), x, x);
}
return tmp;
}
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -2e+101) tmp = Float64(1.0 / -0.5); elseif (Float64(a * x) <= -4e+18) tmp = Float64(Float64(a * Float64(a * Float64(x * Float64(x * 0.5)))) + -1.0); else tmp = Float64(a * fma(Float64(x * Float64(a * 0.5)), x, x)); end return tmp end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -2e+101], N[(1.0 / -0.5), $MachinePrecision], If[LessEqual[N[(a * x), $MachinePrecision], -4e+18], N[(N[(a * N[(a * N[(x * N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(a * N[(N[(x * N[(a * 0.5), $MachinePrecision]), $MachinePrecision] * x + x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -2 \cdot 10^{+101}:\\
\;\;\;\;\frac{1}{-0.5}\\
\mathbf{elif}\;a \cdot x \leq -4 \cdot 10^{+18}:\\
\;\;\;\;a \cdot \left(a \cdot \left(x \cdot \left(x \cdot 0.5\right)\right)\right) + -1\\
\mathbf{else}:\\
\;\;\;\;a \cdot \mathsf{fma}\left(x \cdot \left(a \cdot 0.5\right), x, x\right)\\
\end{array}
\end{array}
if (*.f64 a x) < -2e101Initial program 100.0%
lift--.f64N/A
flip3--N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip3--N/A
lift--.f64N/A
lower-/.f64100.0
lift--.f64N/A
lift-exp.f64N/A
lower-expm1.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6418.8
Applied rewrites18.8%
Taylor expanded in x around inf
Applied rewrites18.8%
if -2e101 < (*.f64 a x) < -4e18Initial 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.0
Applied rewrites2.0%
Taylor expanded in a around inf
Applied rewrites19.7%
if -4e18 < (*.f64 a x) Initial program 29.4%
lift--.f64N/A
flip3--N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip3--N/A
lift--.f64N/A
lower-/.f6429.4
lift--.f64N/A
lift-exp.f64N/A
lower-expm1.f6499.1
Applied rewrites99.1%
Taylor expanded in a around 0
+-commutativeN/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6492.9
Applied rewrites92.9%
Applied rewrites98.4%
Final simplification76.4%
(FPCore (a x) :precision binary64 (if (<= a -2.5e+237) (+ (* a (* a (* x (* x 0.5)))) -1.0) (/ 1.0 (+ -0.5 (/ 1.0 (* a x))))))
double code(double a, double x) {
double tmp;
if (a <= -2.5e+237) {
tmp = (a * (a * (x * (x * 0.5)))) + -1.0;
} else {
tmp = 1.0 / (-0.5 + (1.0 / (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 <= (-2.5d+237)) then
tmp = (a * (a * (x * (x * 0.5d0)))) + (-1.0d0)
else
tmp = 1.0d0 / ((-0.5d0) + (1.0d0 / (a * x)))
end if
code = tmp
end function
public static double code(double a, double x) {
double tmp;
if (a <= -2.5e+237) {
tmp = (a * (a * (x * (x * 0.5)))) + -1.0;
} else {
tmp = 1.0 / (-0.5 + (1.0 / (a * x)));
}
return tmp;
}
def code(a, x): tmp = 0 if a <= -2.5e+237: tmp = (a * (a * (x * (x * 0.5)))) + -1.0 else: tmp = 1.0 / (-0.5 + (1.0 / (a * x))) return tmp
function code(a, x) tmp = 0.0 if (a <= -2.5e+237) tmp = Float64(Float64(a * Float64(a * Float64(x * Float64(x * 0.5)))) + -1.0); else tmp = Float64(1.0 / Float64(-0.5 + Float64(1.0 / Float64(a * x)))); end return tmp end
function tmp_2 = code(a, x) tmp = 0.0; if (a <= -2.5e+237) tmp = (a * (a * (x * (x * 0.5)))) + -1.0; else tmp = 1.0 / (-0.5 + (1.0 / (a * x))); end tmp_2 = tmp; end
code[a_, x_] := If[LessEqual[a, -2.5e+237], N[(N[(a * N[(a * N[(x * N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(1.0 / N[(-0.5 + N[(1.0 / N[(a * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -2.5 \cdot 10^{+237}:\\
\;\;\;\;a \cdot \left(a \cdot \left(x \cdot \left(x \cdot 0.5\right)\right)\right) + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{-0.5 + \frac{1}{a \cdot x}}\\
\end{array}
\end{array}
if a < -2.5000000000000001e237Initial program 90.3%
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-*.f645.8
Applied rewrites5.8%
Taylor expanded in a around inf
Applied rewrites42.8%
if -2.5000000000000001e237 < a Initial program 47.3%
lift--.f64N/A
flip3--N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip3--N/A
lift--.f64N/A
lower-/.f6447.3
lift--.f64N/A
lift-exp.f64N/A
lower-expm1.f6499.3
Applied rewrites99.3%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6477.4
Applied rewrites77.4%
Taylor expanded in x around inf
Applied rewrites77.6%
Final simplification76.3%
(FPCore (a x) :precision binary64 (if (<= (* a x) -4e+18) (/ 1.0 -0.5) (* a (fma (* x (* a 0.5)) x x))))
double code(double a, double x) {
double tmp;
if ((a * x) <= -4e+18) {
tmp = 1.0 / -0.5;
} else {
tmp = a * fma((x * (a * 0.5)), x, x);
}
return tmp;
}
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -4e+18) tmp = Float64(1.0 / -0.5); else tmp = Float64(a * fma(Float64(x * Float64(a * 0.5)), x, x)); end return tmp end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -4e+18], N[(1.0 / -0.5), $MachinePrecision], N[(a * N[(N[(x * N[(a * 0.5), $MachinePrecision]), $MachinePrecision] * x + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -4 \cdot 10^{+18}:\\
\;\;\;\;\frac{1}{-0.5}\\
\mathbf{else}:\\
\;\;\;\;a \cdot \mathsf{fma}\left(x \cdot \left(a \cdot 0.5\right), x, x\right)\\
\end{array}
\end{array}
if (*.f64 a x) < -4e18Initial program 100.0%
lift--.f64N/A
flip3--N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip3--N/A
lift--.f64N/A
lower-/.f64100.0
lift--.f64N/A
lift-exp.f64N/A
lower-expm1.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6418.8
Applied rewrites18.8%
Taylor expanded in x around inf
Applied rewrites18.8%
if -4e18 < (*.f64 a x) Initial program 29.4%
lift--.f64N/A
flip3--N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip3--N/A
lift--.f64N/A
lower-/.f6429.4
lift--.f64N/A
lift-exp.f64N/A
lower-expm1.f6499.1
Applied rewrites99.1%
Taylor expanded in a around 0
+-commutativeN/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6492.9
Applied rewrites92.9%
Applied rewrites98.4%
Final simplification76.3%
(FPCore (a x) :precision binary64 (if (<= (* a x) -4e+18) (/ 1.0 -0.5) (* a x)))
double code(double a, double x) {
double tmp;
if ((a * x) <= -4e+18) {
tmp = 1.0 / -0.5;
} 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) <= (-4d+18)) then
tmp = 1.0d0 / (-0.5d0)
else
tmp = a * x
end if
code = tmp
end function
public static double code(double a, double x) {
double tmp;
if ((a * x) <= -4e+18) {
tmp = 1.0 / -0.5;
} else {
tmp = a * x;
}
return tmp;
}
def code(a, x): tmp = 0 if (a * x) <= -4e+18: tmp = 1.0 / -0.5 else: tmp = a * x return tmp
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -4e+18) tmp = Float64(1.0 / -0.5); else tmp = Float64(a * x); end return tmp end
function tmp_2 = code(a, x) tmp = 0.0; if ((a * x) <= -4e+18) tmp = 1.0 / -0.5; else tmp = a * x; end tmp_2 = tmp; end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -4e+18], N[(1.0 / -0.5), $MachinePrecision], N[(a * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -4 \cdot 10^{+18}:\\
\;\;\;\;\frac{1}{-0.5}\\
\mathbf{else}:\\
\;\;\;\;a \cdot x\\
\end{array}
\end{array}
if (*.f64 a x) < -4e18Initial program 100.0%
lift--.f64N/A
flip3--N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip3--N/A
lift--.f64N/A
lower-/.f64100.0
lift--.f64N/A
lift-exp.f64N/A
lower-expm1.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6418.8
Applied rewrites18.8%
Taylor expanded in x around inf
Applied rewrites18.8%
if -4e18 < (*.f64 a x) Initial program 29.4%
Taylor expanded in a around 0
lower-*.f6497.7
Applied rewrites97.7%
(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 48.9%
Taylor expanded in a around 0
lower-*.f6471.9
Applied rewrites71.9%
(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 48.9%
Taylor expanded in a around 0
Applied rewrites19.9%
Final simplification19.9%
(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 2024238
(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))