
(FPCore (k1 dx) :precision binary64 (/ (- (exp (* k1 dx)) 1.0) k1))
double code(double k1, double dx) {
return (exp((k1 * dx)) - 1.0) / k1;
}
real(8) function code(k1, dx)
real(8), intent (in) :: k1
real(8), intent (in) :: dx
code = (exp((k1 * dx)) - 1.0d0) / k1
end function
public static double code(double k1, double dx) {
return (Math.exp((k1 * dx)) - 1.0) / k1;
}
def code(k1, dx): return (math.exp((k1 * dx)) - 1.0) / k1
function code(k1, dx) return Float64(Float64(exp(Float64(k1 * dx)) - 1.0) / k1) end
function tmp = code(k1, dx) tmp = (exp((k1 * dx)) - 1.0) / k1; end
code[k1_, dx_] := N[(N[(N[Exp[N[(k1 * dx), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision] / k1), $MachinePrecision]
\frac{e^{k1 \cdot dx} - 1}{k1}
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (k1 dx) :precision binary64 (/ (- (exp (* k1 dx)) 1.0) k1))
double code(double k1, double dx) {
return (exp((k1 * dx)) - 1.0) / k1;
}
real(8) function code(k1, dx)
real(8), intent (in) :: k1
real(8), intent (in) :: dx
code = (exp((k1 * dx)) - 1.0d0) / k1
end function
public static double code(double k1, double dx) {
return (Math.exp((k1 * dx)) - 1.0) / k1;
}
def code(k1, dx): return (math.exp((k1 * dx)) - 1.0) / k1
function code(k1, dx) return Float64(Float64(exp(Float64(k1 * dx)) - 1.0) / k1) end
function tmp = code(k1, dx) tmp = (exp((k1 * dx)) - 1.0) / k1; end
code[k1_, dx_] := N[(N[(N[Exp[N[(k1 * dx), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision] / k1), $MachinePrecision]
\frac{e^{k1 \cdot dx} - 1}{k1}
(FPCore (k1 dx) :precision binary64 (if (<= (/ (- (exp (* k1 dx)) 1.0) k1) 0.0) dx (/ (expm1 (* dx k1)) k1)))
double code(double k1, double dx) {
double tmp;
if (((exp((k1 * dx)) - 1.0) / k1) <= 0.0) {
tmp = dx;
} else {
tmp = expm1((dx * k1)) / k1;
}
return tmp;
}
public static double code(double k1, double dx) {
double tmp;
if (((Math.exp((k1 * dx)) - 1.0) / k1) <= 0.0) {
tmp = dx;
} else {
tmp = Math.expm1((dx * k1)) / k1;
}
return tmp;
}
def code(k1, dx): tmp = 0 if ((math.exp((k1 * dx)) - 1.0) / k1) <= 0.0: tmp = dx else: tmp = math.expm1((dx * k1)) / k1 return tmp
function code(k1, dx) tmp = 0.0 if (Float64(Float64(exp(Float64(k1 * dx)) - 1.0) / k1) <= 0.0) tmp = dx; else tmp = Float64(expm1(Float64(dx * k1)) / k1); end return tmp end
code[k1_, dx_] := If[LessEqual[N[(N[(N[Exp[N[(k1 * dx), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision] / k1), $MachinePrecision], 0.0], dx, N[(N[(Exp[N[(dx * k1), $MachinePrecision]] - 1), $MachinePrecision] / k1), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\frac{e^{k1 \cdot dx} - 1}{k1} \leq 0:\\
\;\;\;\;dx\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{expm1}\left(dx \cdot k1\right)}{k1}\\
\end{array}
if (/.f64 (-.f64 (exp.f64 (*.f64 k1 dx)) #s(literal 1 binary64)) k1) < 0.0Initial program 32.0%
Taylor expanded in k1 around 0
Applied rewrites73.9%
if 0.0 < (/.f64 (-.f64 (exp.f64 (*.f64 k1 dx)) #s(literal 1 binary64)) k1) Initial program 32.0%
lift--.f64N/A
lift-exp.f64N/A
lower-expm1.f6479.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6479.2%
Applied rewrites79.2%
(FPCore (k1 dx) :precision binary64 (/ 1.0 (fma -0.5 k1 (/ 1.0 dx))))
double code(double k1, double dx) {
return 1.0 / fma(-0.5, k1, (1.0 / dx));
}
function code(k1, dx) return Float64(1.0 / fma(-0.5, k1, Float64(1.0 / dx))) end
code[k1_, dx_] := N[(1.0 / N[(-0.5 * k1 + N[(1.0 / dx), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{1}{\mathsf{fma}\left(-0.5, k1, \frac{1}{dx}\right)}
Initial program 32.0%
Taylor expanded in k1 around 0
Applied rewrites5.3%
Taylor expanded in k1 around 0
lower-*.f6453.1%
Applied rewrites53.1%
lift-/.f64N/A
div-flipN/A
lower-unsound-/.f64N/A
lower-unsound-/.f6453.0%
Applied rewrites53.0%
Taylor expanded in k1 around 0
lower-fma.f64N/A
lower-/.f6475.7%
Applied rewrites75.7%
(FPCore (k1 dx) :precision binary64 dx)
double code(double k1, double dx) {
return dx;
}
real(8) function code(k1, dx)
real(8), intent (in) :: k1
real(8), intent (in) :: dx
code = dx
end function
public static double code(double k1, double dx) {
return dx;
}
def code(k1, dx): return dx
function code(k1, dx) return dx end
function tmp = code(k1, dx) tmp = dx; end
code[k1_, dx_] := dx
dx
Initial program 32.0%
Taylor expanded in k1 around 0
Applied rewrites73.9%
herbie shell --seed 1
(FPCore (k1 dx)
:name "(exp(k1*dx) - 1)/k1"
:precision binary64
:pre (and (and (<= -1.79e+308 k1) (<= k1 1.79e+308)) (and (<= 0.0 dx) (<= dx 1000000000.0)))
(/ (- (exp (* k1 dx)) 1.0) k1))