
(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 50.6%
accelerator-lowering-expm1.f64N/A
*-lowering-*.f64100.0%
Simplified100.0%
(FPCore (a x)
:precision binary64
(if (<= (* a x) -1000.0)
-1.0
(*
a
(*
x
(+
1.0
(*
a
(*
x
(+
0.5
(*
(* a x)
(+ 0.16666666666666666 (* (* a x) 0.041666666666666664)))))))))))
double code(double a, double x) {
double tmp;
if ((a * x) <= -1000.0) {
tmp = -1.0;
} else {
tmp = a * (x * (1.0 + (a * (x * (0.5 + ((a * x) * (0.16666666666666666 + ((a * x) * 0.041666666666666664))))))));
}
return tmp;
}
real(8) function code(a, x)
real(8), intent (in) :: a
real(8), intent (in) :: x
real(8) :: tmp
if ((a * x) <= (-1000.0d0)) then
tmp = -1.0d0
else
tmp = a * (x * (1.0d0 + (a * (x * (0.5d0 + ((a * x) * (0.16666666666666666d0 + ((a * x) * 0.041666666666666664d0))))))))
end if
code = tmp
end function
public static double code(double a, double x) {
double tmp;
if ((a * x) <= -1000.0) {
tmp = -1.0;
} else {
tmp = a * (x * (1.0 + (a * (x * (0.5 + ((a * x) * (0.16666666666666666 + ((a * x) * 0.041666666666666664))))))));
}
return tmp;
}
def code(a, x): tmp = 0 if (a * x) <= -1000.0: tmp = -1.0 else: tmp = a * (x * (1.0 + (a * (x * (0.5 + ((a * x) * (0.16666666666666666 + ((a * x) * 0.041666666666666664)))))))) return tmp
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -1000.0) tmp = -1.0; else tmp = Float64(a * Float64(x * Float64(1.0 + Float64(a * Float64(x * Float64(0.5 + Float64(Float64(a * x) * Float64(0.16666666666666666 + Float64(Float64(a * x) * 0.041666666666666664))))))))); end return tmp end
function tmp_2 = code(a, x) tmp = 0.0; if ((a * x) <= -1000.0) tmp = -1.0; else tmp = a * (x * (1.0 + (a * (x * (0.5 + ((a * x) * (0.16666666666666666 + ((a * x) * 0.041666666666666664)))))))); end tmp_2 = tmp; end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -1000.0], -1.0, N[(a * N[(x * N[(1.0 + N[(a * N[(x * N[(0.5 + N[(N[(a * x), $MachinePrecision] * N[(0.16666666666666666 + N[(N[(a * x), $MachinePrecision] * 0.041666666666666664), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -1000:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;a \cdot \left(x \cdot \left(1 + a \cdot \left(x \cdot \left(0.5 + \left(a \cdot x\right) \cdot \left(0.16666666666666666 + \left(a \cdot x\right) \cdot 0.041666666666666664\right)\right)\right)\right)\right)\\
\end{array}
\end{array}
if (*.f64 a x) < -1e3Initial program 100.0%
Taylor expanded in a around 0
+-commutativeN/A
+-lowering-+.f64N/A
*-lowering-*.f644.9%
Simplified4.9%
flip3-+N/A
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
metadata-evalN/A
*-rgt-identityN/A
--lowering--.f64N/A
*-lowering-*.f64N/A
metadata-evalN/A
+-commutativeN/A
+-lowering-+.f64N/A
cube-multN/A
*-lowering-*.f64N/A
Applied egg-rr2.1%
Taylor expanded in a around 0
mul-1-negN/A
unsub-negN/A
--lowering--.f64N/A
*-lowering-*.f6498.8%
Simplified98.8%
Taylor expanded in a around inf
Simplified100.0%
if -1e3 < (*.f64 a x) Initial program 26.5%
accelerator-lowering-expm1.f64N/A
*-lowering-*.f64100.0%
Simplified100.0%
Taylor expanded in a around 0
Simplified99.1%
(FPCore (a x) :precision binary64 (if (<= (* a x) -1000.0) -1.0 (* (* a x) (+ 1.0 (* (* a x) (+ 0.5 (* x (* a 0.16666666666666666))))))))
double code(double a, double x) {
double tmp;
if ((a * x) <= -1000.0) {
tmp = -1.0;
} else {
tmp = (a * x) * (1.0 + ((a * x) * (0.5 + (x * (a * 0.16666666666666666)))));
}
return tmp;
}
real(8) function code(a, x)
real(8), intent (in) :: a
real(8), intent (in) :: x
real(8) :: tmp
if ((a * x) <= (-1000.0d0)) then
tmp = -1.0d0
else
tmp = (a * x) * (1.0d0 + ((a * x) * (0.5d0 + (x * (a * 0.16666666666666666d0)))))
end if
code = tmp
end function
public static double code(double a, double x) {
double tmp;
if ((a * x) <= -1000.0) {
tmp = -1.0;
} else {
tmp = (a * x) * (1.0 + ((a * x) * (0.5 + (x * (a * 0.16666666666666666)))));
}
return tmp;
}
def code(a, x): tmp = 0 if (a * x) <= -1000.0: tmp = -1.0 else: tmp = (a * x) * (1.0 + ((a * x) * (0.5 + (x * (a * 0.16666666666666666))))) return tmp
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -1000.0) tmp = -1.0; else tmp = Float64(Float64(a * x) * Float64(1.0 + Float64(Float64(a * x) * Float64(0.5 + Float64(x * Float64(a * 0.16666666666666666)))))); end return tmp end
function tmp_2 = code(a, x) tmp = 0.0; if ((a * x) <= -1000.0) tmp = -1.0; else tmp = (a * x) * (1.0 + ((a * x) * (0.5 + (x * (a * 0.16666666666666666))))); end tmp_2 = tmp; end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -1000.0], -1.0, N[(N[(a * x), $MachinePrecision] * N[(1.0 + N[(N[(a * x), $MachinePrecision] * N[(0.5 + N[(x * N[(a * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -1000:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;\left(a \cdot x\right) \cdot \left(1 + \left(a \cdot x\right) \cdot \left(0.5 + x \cdot \left(a \cdot 0.16666666666666666\right)\right)\right)\\
\end{array}
\end{array}
if (*.f64 a x) < -1e3Initial program 100.0%
Taylor expanded in a around 0
+-commutativeN/A
+-lowering-+.f64N/A
*-lowering-*.f644.9%
Simplified4.9%
flip3-+N/A
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
metadata-evalN/A
*-rgt-identityN/A
--lowering--.f64N/A
*-lowering-*.f64N/A
metadata-evalN/A
+-commutativeN/A
+-lowering-+.f64N/A
cube-multN/A
*-lowering-*.f64N/A
Applied egg-rr2.1%
Taylor expanded in a around 0
mul-1-negN/A
unsub-negN/A
--lowering--.f64N/A
*-lowering-*.f6498.8%
Simplified98.8%
Taylor expanded in a around inf
Simplified100.0%
if -1e3 < (*.f64 a x) Initial program 26.5%
accelerator-lowering-expm1.f64N/A
*-lowering-*.f64100.0%
Simplified100.0%
Taylor expanded in a around 0
+-commutativeN/A
distribute-lft-inN/A
associate-+l+N/A
associate-*r*N/A
associate-*r*N/A
unpow3N/A
unpow2N/A
associate-*r*N/A
associate-*r*N/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
distribute-lft1-inN/A
distribute-rgt-outN/A
Simplified99.1%
(FPCore (a x) :precision binary64 (if (<= (* a x) -1000.0) -1.0 (* a (* x (+ 1.0 (* (* a x) 0.5))))))
double code(double a, double x) {
double tmp;
if ((a * x) <= -1000.0) {
tmp = -1.0;
} else {
tmp = a * (x * (1.0 + ((a * 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) <= (-1000.0d0)) then
tmp = -1.0d0
else
tmp = a * (x * (1.0d0 + ((a * x) * 0.5d0)))
end if
code = tmp
end function
public static double code(double a, double x) {
double tmp;
if ((a * x) <= -1000.0) {
tmp = -1.0;
} else {
tmp = a * (x * (1.0 + ((a * x) * 0.5)));
}
return tmp;
}
def code(a, x): tmp = 0 if (a * x) <= -1000.0: tmp = -1.0 else: tmp = a * (x * (1.0 + ((a * x) * 0.5))) return tmp
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -1000.0) tmp = -1.0; else tmp = Float64(a * Float64(x * Float64(1.0 + Float64(Float64(a * x) * 0.5)))); end return tmp end
function tmp_2 = code(a, x) tmp = 0.0; if ((a * x) <= -1000.0) tmp = -1.0; else tmp = a * (x * (1.0 + ((a * x) * 0.5))); end tmp_2 = tmp; end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -1000.0], -1.0, N[(a * N[(x * N[(1.0 + N[(N[(a * x), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -1000:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;a \cdot \left(x \cdot \left(1 + \left(a \cdot x\right) \cdot 0.5\right)\right)\\
\end{array}
\end{array}
if (*.f64 a x) < -1e3Initial program 100.0%
Taylor expanded in a around 0
+-commutativeN/A
+-lowering-+.f64N/A
*-lowering-*.f644.9%
Simplified4.9%
flip3-+N/A
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
metadata-evalN/A
*-rgt-identityN/A
--lowering--.f64N/A
*-lowering-*.f64N/A
metadata-evalN/A
+-commutativeN/A
+-lowering-+.f64N/A
cube-multN/A
*-lowering-*.f64N/A
Applied egg-rr2.1%
Taylor expanded in a around 0
mul-1-negN/A
unsub-negN/A
--lowering--.f64N/A
*-lowering-*.f6498.8%
Simplified98.8%
Taylor expanded in a around inf
Simplified100.0%
if -1e3 < (*.f64 a x) Initial program 26.5%
accelerator-lowering-expm1.f64N/A
*-lowering-*.f64100.0%
Simplified100.0%
Taylor expanded in a around 0
+-commutativeN/A
distribute-lft-inN/A
associate-+l+N/A
associate-*r*N/A
associate-*r*N/A
unpow3N/A
unpow2N/A
associate-*r*N/A
associate-*r*N/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
distribute-lft1-inN/A
distribute-rgt-outN/A
Simplified99.1%
+-commutativeN/A
distribute-rgt-inN/A
associate-+l+N/A
*-commutativeN/A
+-lowering-+.f64N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
associate-*r*N/A
*-commutativeN/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f6499.1%
Applied egg-rr99.1%
Taylor expanded in a around 0
*-commutativeN/A
associate-*r*N/A
+-commutativeN/A
*-lowering-*.f64N/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
unpow2N/A
associate-*r*N/A
associate-*r*N/A
*-lft-identityN/A
distribute-rgt-outN/A
+-commutativeN/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6499.0%
Simplified99.0%
Final simplification99.4%
(FPCore (a x) :precision binary64 (if (<= (* a x) -1000.0) -1.0 (* a x)))
double code(double a, double x) {
double tmp;
if ((a * x) <= -1000.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) <= (-1000.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) <= -1000.0) {
tmp = -1.0;
} else {
tmp = a * x;
}
return tmp;
}
def code(a, x): tmp = 0 if (a * x) <= -1000.0: tmp = -1.0 else: tmp = a * x return tmp
function code(a, x) tmp = 0.0 if (Float64(a * x) <= -1000.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) <= -1000.0) tmp = -1.0; else tmp = a * x; end tmp_2 = tmp; end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -1000.0], -1.0, N[(a * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -1000:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;a \cdot x\\
\end{array}
\end{array}
if (*.f64 a x) < -1e3Initial program 100.0%
Taylor expanded in a around 0
+-commutativeN/A
+-lowering-+.f64N/A
*-lowering-*.f644.9%
Simplified4.9%
flip3-+N/A
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
metadata-evalN/A
*-rgt-identityN/A
--lowering--.f64N/A
*-lowering-*.f64N/A
metadata-evalN/A
+-commutativeN/A
+-lowering-+.f64N/A
cube-multN/A
*-lowering-*.f64N/A
Applied egg-rr2.1%
Taylor expanded in a around 0
mul-1-negN/A
unsub-negN/A
--lowering--.f64N/A
*-lowering-*.f6498.8%
Simplified98.8%
Taylor expanded in a around inf
Simplified100.0%
if -1e3 < (*.f64 a x) Initial program 26.5%
accelerator-lowering-expm1.f64N/A
*-lowering-*.f64100.0%
Simplified100.0%
Taylor expanded in a around 0
*-lowering-*.f6498.5%
Simplified98.5%
(FPCore (a x) :precision binary64 (if (<= a -5.6e-95) -1.0 0.0))
double code(double a, double x) {
double tmp;
if (a <= -5.6e-95) {
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 <= (-5.6d-95)) 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 <= -5.6e-95) {
tmp = -1.0;
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, x): tmp = 0 if a <= -5.6e-95: tmp = -1.0 else: tmp = 0.0 return tmp
function code(a, x) tmp = 0.0 if (a <= -5.6e-95) tmp = -1.0; else tmp = 0.0; end return tmp end
function tmp_2 = code(a, x) tmp = 0.0; if (a <= -5.6e-95) tmp = -1.0; else tmp = 0.0; end tmp_2 = tmp; end
code[a_, x_] := If[LessEqual[a, -5.6e-95], -1.0, 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -5.6 \cdot 10^{-95}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if a < -5.5999999999999998e-95Initial program 62.6%
Taylor expanded in a around 0
+-commutativeN/A
+-lowering-+.f64N/A
*-lowering-*.f647.7%
Simplified7.7%
flip3-+N/A
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
metadata-evalN/A
*-rgt-identityN/A
--lowering--.f64N/A
*-lowering-*.f64N/A
metadata-evalN/A
+-commutativeN/A
+-lowering-+.f64N/A
cube-multN/A
*-lowering-*.f64N/A
Applied egg-rr6.2%
Taylor expanded in a around 0
mul-1-negN/A
unsub-negN/A
--lowering--.f64N/A
*-lowering-*.f6460.2%
Simplified60.2%
Taylor expanded in a around inf
Simplified58.2%
if -5.5999999999999998e-95 < a Initial program 46.2%
Taylor expanded in a around 0
Simplified21.7%
metadata-eval21.7%
Applied egg-rr21.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 50.6%
Taylor expanded in a around 0
+-commutativeN/A
+-lowering-+.f64N/A
*-lowering-*.f6418.8%
Simplified18.8%
flip3-+N/A
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
metadata-evalN/A
*-rgt-identityN/A
--lowering--.f64N/A
*-lowering-*.f64N/A
metadata-evalN/A
+-commutativeN/A
+-lowering-+.f64N/A
cube-multN/A
*-lowering-*.f64N/A
Applied egg-rr17.8%
Taylor expanded in a around 0
mul-1-negN/A
unsub-negN/A
--lowering--.f64N/A
*-lowering-*.f6449.5%
Simplified49.5%
Taylor expanded in a around inf
Simplified35.3%
(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 2024191
(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))