
(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 57.1%
expm1-def99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (a x) :precision binary64 (if (<= (* a x) 5e-11) (* a x) (* a (+ x (* a (* x (* x 0.5)))))))
double code(double a, double x) {
double tmp;
if ((a * x) <= 5e-11) {
tmp = a * x;
} else {
tmp = a * (x + (a * (x * (x * 0.5))));
}
return tmp;
}
real(8) function code(a, x)
real(8), intent (in) :: a
real(8), intent (in) :: x
real(8) :: tmp
if ((a * x) <= 5d-11) then
tmp = a * x
else
tmp = a * (x + (a * (x * (x * 0.5d0))))
end if
code = tmp
end function
public static double code(double a, double x) {
double tmp;
if ((a * x) <= 5e-11) {
tmp = a * x;
} else {
tmp = a * (x + (a * (x * (x * 0.5))));
}
return tmp;
}
def code(a, x): tmp = 0 if (a * x) <= 5e-11: tmp = a * x else: tmp = a * (x + (a * (x * (x * 0.5)))) return tmp
function code(a, x) tmp = 0.0 if (Float64(a * x) <= 5e-11) tmp = Float64(a * x); else tmp = Float64(a * Float64(x + Float64(a * Float64(x * Float64(x * 0.5))))); end return tmp end
function tmp_2 = code(a, x) tmp = 0.0; if ((a * x) <= 5e-11) tmp = a * x; else tmp = a * (x + (a * (x * (x * 0.5)))); end tmp_2 = tmp; end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], 5e-11], N[(a * x), $MachinePrecision], N[(a * N[(x + N[(a * N[(x * N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq 5 \cdot 10^{-11}:\\
\;\;\;\;a \cdot x\\
\mathbf{else}:\\
\;\;\;\;a \cdot \left(x + a \cdot \left(x \cdot \left(x \cdot 0.5\right)\right)\right)\\
\end{array}
\end{array}
if (*.f64 a x) < 5.00000000000000018e-11Initial program 33.6%
expm1-def100.0%
Simplified100.0%
Taylor expanded in a around 0 97.4%
if 5.00000000000000018e-11 < (*.f64 a x) Initial program 99.2%
expm1-def99.9%
Simplified99.9%
Taylor expanded in a around 0 66.6%
*-commutative66.6%
associate-*l*66.6%
unpow266.6%
associate-*l*68.6%
distribute-lft-out68.6%
unpow268.6%
associate-*l*68.6%
Simplified68.6%
Final simplification87.0%
(FPCore (a x) :precision binary64 (if (<= a 5.8e-229) (+ (* a x) (* x (* (* a x) (* a 0.5)))) (* a (+ x (* a (* x (* x 0.5)))))))
double code(double a, double x) {
double tmp;
if (a <= 5.8e-229) {
tmp = (a * x) + (x * ((a * x) * (a * 0.5)));
} else {
tmp = a * (x + (a * (x * (x * 0.5))));
}
return tmp;
}
real(8) function code(a, x)
real(8), intent (in) :: a
real(8), intent (in) :: x
real(8) :: tmp
if (a <= 5.8d-229) then
tmp = (a * x) + (x * ((a * x) * (a * 0.5d0)))
else
tmp = a * (x + (a * (x * (x * 0.5d0))))
end if
code = tmp
end function
public static double code(double a, double x) {
double tmp;
if (a <= 5.8e-229) {
tmp = (a * x) + (x * ((a * x) * (a * 0.5)));
} else {
tmp = a * (x + (a * (x * (x * 0.5))));
}
return tmp;
}
def code(a, x): tmp = 0 if a <= 5.8e-229: tmp = (a * x) + (x * ((a * x) * (a * 0.5))) else: tmp = a * (x + (a * (x * (x * 0.5)))) return tmp
function code(a, x) tmp = 0.0 if (a <= 5.8e-229) tmp = Float64(Float64(a * x) + Float64(x * Float64(Float64(a * x) * Float64(a * 0.5)))); else tmp = Float64(a * Float64(x + Float64(a * Float64(x * Float64(x * 0.5))))); end return tmp end
function tmp_2 = code(a, x) tmp = 0.0; if (a <= 5.8e-229) tmp = (a * x) + (x * ((a * x) * (a * 0.5))); else tmp = a * (x + (a * (x * (x * 0.5)))); end tmp_2 = tmp; end
code[a_, x_] := If[LessEqual[a, 5.8e-229], N[(N[(a * x), $MachinePrecision] + N[(x * N[(N[(a * x), $MachinePrecision] * N[(a * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(a * N[(x + N[(a * N[(x * N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 5.8 \cdot 10^{-229}:\\
\;\;\;\;a \cdot x + x \cdot \left(\left(a \cdot x\right) \cdot \left(a \cdot 0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;a \cdot \left(x + a \cdot \left(x \cdot \left(x \cdot 0.5\right)\right)\right)\\
\end{array}
\end{array}
if a < 5.7999999999999999e-229Initial program 58.1%
expm1-def100.0%
Simplified100.0%
Taylor expanded in a around 0 78.9%
+-commutative78.9%
associate-*r*78.9%
unpow278.9%
associate-*r*83.9%
distribute-rgt-out83.9%
*-commutative83.9%
*-commutative83.9%
unpow283.9%
associate-*l*83.9%
Simplified83.9%
+-commutative83.9%
distribute-lft-in83.9%
associate-*r*86.7%
*-commutative86.7%
*-commutative86.7%
Applied egg-rr86.7%
if 5.7999999999999999e-229 < a Initial program 55.8%
expm1-def99.9%
Simplified99.9%
Taylor expanded in a around 0 80.6%
*-commutative80.6%
associate-*l*80.6%
unpow280.6%
associate-*l*85.7%
distribute-lft-out85.7%
unpow285.7%
associate-*l*85.7%
Simplified85.7%
Final simplification86.3%
(FPCore (a x) :precision binary64 (if (<= (* a x) 4e+24) (* a x) (* 0.5 (* (* a a) (* x x)))))
double code(double a, double x) {
double tmp;
if ((a * x) <= 4e+24) {
tmp = a * x;
} else {
tmp = 0.5 * ((a * a) * (x * 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+24) then
tmp = a * x
else
tmp = 0.5d0 * ((a * a) * (x * x))
end if
code = tmp
end function
public static double code(double a, double x) {
double tmp;
if ((a * x) <= 4e+24) {
tmp = a * x;
} else {
tmp = 0.5 * ((a * a) * (x * x));
}
return tmp;
}
def code(a, x): tmp = 0 if (a * x) <= 4e+24: tmp = a * x else: tmp = 0.5 * ((a * a) * (x * x)) return tmp
function code(a, x) tmp = 0.0 if (Float64(a * x) <= 4e+24) tmp = Float64(a * x); else tmp = Float64(0.5 * Float64(Float64(a * a) * Float64(x * x))); end return tmp end
function tmp_2 = code(a, x) tmp = 0.0; if ((a * x) <= 4e+24) tmp = a * x; else tmp = 0.5 * ((a * a) * (x * x)); end tmp_2 = tmp; end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], 4e+24], N[(a * x), $MachinePrecision], N[(0.5 * N[(N[(a * a), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq 4 \cdot 10^{+24}:\\
\;\;\;\;a \cdot x\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\left(a \cdot a\right) \cdot \left(x \cdot x\right)\right)\\
\end{array}
\end{array}
if (*.f64 a x) < 3.9999999999999999e24Initial program 38.7%
expm1-def99.9%
Simplified99.9%
Taylor expanded in a around 0 90.1%
if 3.9999999999999999e24 < (*.f64 a x) Initial program 100.0%
expm1-def100.0%
Simplified100.0%
Taylor expanded in a around 0 77.1%
+-commutative77.1%
associate-*r*77.1%
unpow277.1%
associate-*r*76.6%
distribute-rgt-out76.6%
*-commutative76.6%
*-commutative76.6%
unpow276.6%
associate-*l*76.6%
Simplified76.6%
Taylor expanded in x around inf 77.1%
unpow277.1%
unpow277.1%
Simplified77.1%
Final simplification86.2%
(FPCore (a x) :precision binary64 (if (<= a 2.05e-227) (* x (* a (+ (* a (* x 0.5)) 1.0))) (* a (+ x (* a (* x (* x 0.5)))))))
double code(double a, double x) {
double tmp;
if (a <= 2.05e-227) {
tmp = x * (a * ((a * (x * 0.5)) + 1.0));
} else {
tmp = a * (x + (a * (x * (x * 0.5))));
}
return tmp;
}
real(8) function code(a, x)
real(8), intent (in) :: a
real(8), intent (in) :: x
real(8) :: tmp
if (a <= 2.05d-227) then
tmp = x * (a * ((a * (x * 0.5d0)) + 1.0d0))
else
tmp = a * (x + (a * (x * (x * 0.5d0))))
end if
code = tmp
end function
public static double code(double a, double x) {
double tmp;
if (a <= 2.05e-227) {
tmp = x * (a * ((a * (x * 0.5)) + 1.0));
} else {
tmp = a * (x + (a * (x * (x * 0.5))));
}
return tmp;
}
def code(a, x): tmp = 0 if a <= 2.05e-227: tmp = x * (a * ((a * (x * 0.5)) + 1.0)) else: tmp = a * (x + (a * (x * (x * 0.5)))) return tmp
function code(a, x) tmp = 0.0 if (a <= 2.05e-227) tmp = Float64(x * Float64(a * Float64(Float64(a * Float64(x * 0.5)) + 1.0))); else tmp = Float64(a * Float64(x + Float64(a * Float64(x * Float64(x * 0.5))))); end return tmp end
function tmp_2 = code(a, x) tmp = 0.0; if (a <= 2.05e-227) tmp = x * (a * ((a * (x * 0.5)) + 1.0)); else tmp = a * (x + (a * (x * (x * 0.5)))); end tmp_2 = tmp; end
code[a_, x_] := If[LessEqual[a, 2.05e-227], N[(x * N[(a * N[(N[(a * N[(x * 0.5), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(a * N[(x + N[(a * N[(x * N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2.05 \cdot 10^{-227}:\\
\;\;\;\;x \cdot \left(a \cdot \left(a \cdot \left(x \cdot 0.5\right) + 1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;a \cdot \left(x + a \cdot \left(x \cdot \left(x \cdot 0.5\right)\right)\right)\\
\end{array}
\end{array}
if a < 2.05000000000000005e-227Initial program 57.7%
expm1-def100.0%
Simplified100.0%
Taylor expanded in a around 0 79.0%
+-commutative79.0%
associate-*r*79.0%
unpow279.0%
associate-*r*84.0%
distribute-rgt-out84.0%
*-commutative84.0%
*-commutative84.0%
unpow284.0%
associate-*l*84.0%
Simplified84.0%
Taylor expanded in x around 0 84.0%
unpow284.0%
associate-*r*86.8%
*-commutative86.8%
*-commutative86.8%
*-commutative86.8%
associate-*r*86.8%
associate-*l*86.8%
Simplified86.8%
*-commutative86.8%
distribute-rgt1-in86.8%
Applied egg-rr86.8%
if 2.05000000000000005e-227 < a Initial program 56.3%
expm1-def99.9%
Simplified99.9%
Taylor expanded in a around 0 80.4%
*-commutative80.4%
associate-*l*80.4%
unpow280.4%
associate-*l*85.6%
distribute-lft-out85.6%
unpow285.6%
associate-*l*85.6%
Simplified85.6%
Final simplification86.3%
(FPCore (a x) :precision binary64 (if (<= a 4e-228) (* x (+ a (* a (* a (* x 0.5))))) (* a (+ x (* a (* x (* x 0.5)))))))
double code(double a, double x) {
double tmp;
if (a <= 4e-228) {
tmp = x * (a + (a * (a * (x * 0.5))));
} else {
tmp = a * (x + (a * (x * (x * 0.5))));
}
return tmp;
}
real(8) function code(a, x)
real(8), intent (in) :: a
real(8), intent (in) :: x
real(8) :: tmp
if (a <= 4d-228) then
tmp = x * (a + (a * (a * (x * 0.5d0))))
else
tmp = a * (x + (a * (x * (x * 0.5d0))))
end if
code = tmp
end function
public static double code(double a, double x) {
double tmp;
if (a <= 4e-228) {
tmp = x * (a + (a * (a * (x * 0.5))));
} else {
tmp = a * (x + (a * (x * (x * 0.5))));
}
return tmp;
}
def code(a, x): tmp = 0 if a <= 4e-228: tmp = x * (a + (a * (a * (x * 0.5)))) else: tmp = a * (x + (a * (x * (x * 0.5)))) return tmp
function code(a, x) tmp = 0.0 if (a <= 4e-228) tmp = Float64(x * Float64(a + Float64(a * Float64(a * Float64(x * 0.5))))); else tmp = Float64(a * Float64(x + Float64(a * Float64(x * Float64(x * 0.5))))); end return tmp end
function tmp_2 = code(a, x) tmp = 0.0; if (a <= 4e-228) tmp = x * (a + (a * (a * (x * 0.5)))); else tmp = a * (x + (a * (x * (x * 0.5)))); end tmp_2 = tmp; end
code[a_, x_] := If[LessEqual[a, 4e-228], N[(x * N[(a + N[(a * N[(a * N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(a * N[(x + N[(a * N[(x * N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 4 \cdot 10^{-228}:\\
\;\;\;\;x \cdot \left(a + a \cdot \left(a \cdot \left(x \cdot 0.5\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;a \cdot \left(x + a \cdot \left(x \cdot \left(x \cdot 0.5\right)\right)\right)\\
\end{array}
\end{array}
if a < 4.00000000000000013e-228Initial program 57.7%
expm1-def100.0%
Simplified100.0%
Taylor expanded in a around 0 79.0%
+-commutative79.0%
associate-*r*79.0%
unpow279.0%
associate-*r*84.0%
distribute-rgt-out84.0%
*-commutative84.0%
*-commutative84.0%
unpow284.0%
associate-*l*84.0%
Simplified84.0%
Taylor expanded in x around 0 84.0%
unpow284.0%
associate-*r*86.8%
*-commutative86.8%
*-commutative86.8%
*-commutative86.8%
associate-*r*86.8%
associate-*l*86.8%
Simplified86.8%
if 4.00000000000000013e-228 < a Initial program 56.3%
expm1-def99.9%
Simplified99.9%
Taylor expanded in a around 0 80.4%
*-commutative80.4%
associate-*l*80.4%
unpow280.4%
associate-*l*85.6%
distribute-lft-out85.6%
unpow285.6%
associate-*l*85.6%
Simplified85.6%
Final simplification86.3%
(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 57.1%
expm1-def99.9%
Simplified99.9%
Taylor expanded in a around 0 72.1%
Final simplification72.1%
(FPCore (a x) :precision binary64 (if (< (fabs (* a x)) 0.1) (* (* a x) (+ 1.0 (+ (/ (* a x) 2.0) (/ (pow (* a x) 2.0) 6.0)))) (- (exp (* a x)) 1.0)))
double code(double a, double x) {
double tmp;
if (fabs((a * x)) < 0.1) {
tmp = (a * x) * (1.0 + (((a * x) / 2.0) + (pow((a * x), 2.0) / 6.0)));
} else {
tmp = exp((a * x)) - 1.0;
}
return tmp;
}
real(8) function code(a, x)
real(8), intent (in) :: a
real(8), intent (in) :: x
real(8) :: tmp
if (abs((a * x)) < 0.1d0) then
tmp = (a * x) * (1.0d0 + (((a * x) / 2.0d0) + (((a * x) ** 2.0d0) / 6.0d0)))
else
tmp = exp((a * x)) - 1.0d0
end if
code = tmp
end function
public static double code(double a, double x) {
double tmp;
if (Math.abs((a * x)) < 0.1) {
tmp = (a * x) * (1.0 + (((a * x) / 2.0) + (Math.pow((a * x), 2.0) / 6.0)));
} else {
tmp = Math.exp((a * x)) - 1.0;
}
return tmp;
}
def code(a, x): tmp = 0 if math.fabs((a * x)) < 0.1: tmp = (a * x) * (1.0 + (((a * x) / 2.0) + (math.pow((a * x), 2.0) / 6.0))) else: tmp = math.exp((a * x)) - 1.0 return tmp
function code(a, x) tmp = 0.0 if (abs(Float64(a * x)) < 0.1) tmp = Float64(Float64(a * x) * Float64(1.0 + Float64(Float64(Float64(a * x) / 2.0) + Float64((Float64(a * x) ^ 2.0) / 6.0)))); else tmp = Float64(exp(Float64(a * x)) - 1.0); end return tmp end
function tmp_2 = code(a, x) tmp = 0.0; if (abs((a * x)) < 0.1) tmp = (a * x) * (1.0 + (((a * x) / 2.0) + (((a * x) ^ 2.0) / 6.0))); else tmp = exp((a * x)) - 1.0; end tmp_2 = tmp; end
code[a_, x_] := If[Less[N[Abs[N[(a * x), $MachinePrecision]], $MachinePrecision], 0.1], N[(N[(a * x), $MachinePrecision] * N[(1.0 + N[(N[(N[(a * x), $MachinePrecision] / 2.0), $MachinePrecision] + N[(N[Power[N[(a * x), $MachinePrecision], 2.0], $MachinePrecision] / 6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Exp[N[(a * x), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|a \cdot x\right| < 0.1:\\
\;\;\;\;\left(a \cdot x\right) \cdot \left(1 + \left(\frac{a \cdot x}{2} + \frac{{\left(a \cdot x\right)}^{2}}{6}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;e^{a \cdot x} - 1\\
\end{array}
\end{array}
herbie shell --seed 2023278
(FPCore (a x)
:name "expax (section 3.5)"
:precision binary64
:herbie-target
(if (< (fabs (* a x)) 0.1) (* (* a x) (+ 1.0 (+ (/ (* a x) 2.0) (/ (pow (* a x) 2.0) 6.0)))) (- (exp (* a x)) 1.0))
(- (exp (* a x)) 1.0))