
(FPCore (a b eps) :precision binary64 (/ (* eps (- (exp (* (+ a b) eps)) 1.0)) (* (- (exp (* a eps)) 1.0) (- (exp (* b eps)) 1.0))))
double code(double a, double b, double eps) {
return (eps * (exp(((a + b) * eps)) - 1.0)) / ((exp((a * eps)) - 1.0) * (exp((b * eps)) - 1.0));
}
real(8) function code(a, b, eps)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: eps
code = (eps * (exp(((a + b) * eps)) - 1.0d0)) / ((exp((a * eps)) - 1.0d0) * (exp((b * eps)) - 1.0d0))
end function
public static double code(double a, double b, double eps) {
return (eps * (Math.exp(((a + b) * eps)) - 1.0)) / ((Math.exp((a * eps)) - 1.0) * (Math.exp((b * eps)) - 1.0));
}
def code(a, b, eps): return (eps * (math.exp(((a + b) * eps)) - 1.0)) / ((math.exp((a * eps)) - 1.0) * (math.exp((b * eps)) - 1.0))
function code(a, b, eps) return Float64(Float64(eps * Float64(exp(Float64(Float64(a + b) * eps)) - 1.0)) / Float64(Float64(exp(Float64(a * eps)) - 1.0) * Float64(exp(Float64(b * eps)) - 1.0))) end
function tmp = code(a, b, eps) tmp = (eps * (exp(((a + b) * eps)) - 1.0)) / ((exp((a * eps)) - 1.0) * (exp((b * eps)) - 1.0)); end
code[a_, b_, eps_] := N[(N[(eps * N[(N[Exp[N[(N[(a + b), $MachinePrecision] * eps), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / N[(N[(N[Exp[N[(a * eps), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision] * N[(N[Exp[N[(b * eps), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\varepsilon \cdot \left(e^{\left(a + b\right) \cdot \varepsilon} - 1\right)}{\left(e^{a \cdot \varepsilon} - 1\right) \cdot \left(e^{b \cdot \varepsilon} - 1\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b eps) :precision binary64 (/ (* eps (- (exp (* (+ a b) eps)) 1.0)) (* (- (exp (* a eps)) 1.0) (- (exp (* b eps)) 1.0))))
double code(double a, double b, double eps) {
return (eps * (exp(((a + b) * eps)) - 1.0)) / ((exp((a * eps)) - 1.0) * (exp((b * eps)) - 1.0));
}
real(8) function code(a, b, eps)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: eps
code = (eps * (exp(((a + b) * eps)) - 1.0d0)) / ((exp((a * eps)) - 1.0d0) * (exp((b * eps)) - 1.0d0))
end function
public static double code(double a, double b, double eps) {
return (eps * (Math.exp(((a + b) * eps)) - 1.0)) / ((Math.exp((a * eps)) - 1.0) * (Math.exp((b * eps)) - 1.0));
}
def code(a, b, eps): return (eps * (math.exp(((a + b) * eps)) - 1.0)) / ((math.exp((a * eps)) - 1.0) * (math.exp((b * eps)) - 1.0))
function code(a, b, eps) return Float64(Float64(eps * Float64(exp(Float64(Float64(a + b) * eps)) - 1.0)) / Float64(Float64(exp(Float64(a * eps)) - 1.0) * Float64(exp(Float64(b * eps)) - 1.0))) end
function tmp = code(a, b, eps) tmp = (eps * (exp(((a + b) * eps)) - 1.0)) / ((exp((a * eps)) - 1.0) * (exp((b * eps)) - 1.0)); end
code[a_, b_, eps_] := N[(N[(eps * N[(N[Exp[N[(N[(a + b), $MachinePrecision] * eps), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / N[(N[(N[Exp[N[(a * eps), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision] * N[(N[Exp[N[(b * eps), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\varepsilon \cdot \left(e^{\left(a + b\right) \cdot \varepsilon} - 1\right)}{\left(e^{a \cdot \varepsilon} - 1\right) \cdot \left(e^{b \cdot \varepsilon} - 1\right)}
\end{array}
NOTE: a and b should be sorted in increasing order before calling this function.
(FPCore (a b eps)
:precision binary64
(let* ((t_0 (* eps (+ a b)))
(t_1
(/
(* eps (+ (exp t_0) -1.0))
(* (+ (exp (* eps a)) -1.0) (+ (exp (* eps b)) -1.0)))))
(if (<= t_1 (- INFINITY))
(/ 1.0 a)
(if (<= t_1 0.01)
(* (/ eps (expm1 (* eps a))) (/ (expm1 t_0) (expm1 (* eps b))))
(+ (/ 1.0 a) (/ 1.0 b))))))assert(a < b);
double code(double a, double b, double eps) {
double t_0 = eps * (a + b);
double t_1 = (eps * (exp(t_0) + -1.0)) / ((exp((eps * a)) + -1.0) * (exp((eps * b)) + -1.0));
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = 1.0 / a;
} else if (t_1 <= 0.01) {
tmp = (eps / expm1((eps * a))) * (expm1(t_0) / expm1((eps * b)));
} else {
tmp = (1.0 / a) + (1.0 / b);
}
return tmp;
}
assert a < b;
public static double code(double a, double b, double eps) {
double t_0 = eps * (a + b);
double t_1 = (eps * (Math.exp(t_0) + -1.0)) / ((Math.exp((eps * a)) + -1.0) * (Math.exp((eps * b)) + -1.0));
double tmp;
if (t_1 <= -Double.POSITIVE_INFINITY) {
tmp = 1.0 / a;
} else if (t_1 <= 0.01) {
tmp = (eps / Math.expm1((eps * a))) * (Math.expm1(t_0) / Math.expm1((eps * b)));
} else {
tmp = (1.0 / a) + (1.0 / b);
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b, eps): t_0 = eps * (a + b) t_1 = (eps * (math.exp(t_0) + -1.0)) / ((math.exp((eps * a)) + -1.0) * (math.exp((eps * b)) + -1.0)) tmp = 0 if t_1 <= -math.inf: tmp = 1.0 / a elif t_1 <= 0.01: tmp = (eps / math.expm1((eps * a))) * (math.expm1(t_0) / math.expm1((eps * b))) else: tmp = (1.0 / a) + (1.0 / b) return tmp
a, b = sort([a, b]) function code(a, b, eps) t_0 = Float64(eps * Float64(a + b)) t_1 = Float64(Float64(eps * Float64(exp(t_0) + -1.0)) / Float64(Float64(exp(Float64(eps * a)) + -1.0) * Float64(exp(Float64(eps * b)) + -1.0))) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = Float64(1.0 / a); elseif (t_1 <= 0.01) tmp = Float64(Float64(eps / expm1(Float64(eps * a))) * Float64(expm1(t_0) / expm1(Float64(eps * b)))); else tmp = Float64(Float64(1.0 / a) + Float64(1.0 / b)); end return tmp end
NOTE: a and b should be sorted in increasing order before calling this function.
code[a_, b_, eps_] := Block[{t$95$0 = N[(eps * N[(a + b), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(eps * N[(N[Exp[t$95$0], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] / N[(N[(N[Exp[N[(eps * a), $MachinePrecision]], $MachinePrecision] + -1.0), $MachinePrecision] * N[(N[Exp[N[(eps * b), $MachinePrecision]], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(1.0 / a), $MachinePrecision], If[LessEqual[t$95$1, 0.01], N[(N[(eps / N[(Exp[N[(eps * a), $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision] * N[(N[(Exp[t$95$0] - 1), $MachinePrecision] / N[(Exp[N[(eps * b), $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / a), $MachinePrecision] + N[(1.0 / b), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
t_0 := \varepsilon \cdot \left(a + b\right)\\
t_1 := \frac{\varepsilon \cdot \left(e^{t_0} + -1\right)}{\left(e^{\varepsilon \cdot a} + -1\right) \cdot \left(e^{\varepsilon \cdot b} + -1\right)}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;\frac{1}{a}\\
\mathbf{elif}\;t_1 \leq 0.01:\\
\;\;\;\;\frac{\varepsilon}{\mathsf{expm1}\left(\varepsilon \cdot a\right)} \cdot \frac{\mathsf{expm1}\left(t_0\right)}{\mathsf{expm1}\left(\varepsilon \cdot b\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{a} + \frac{1}{b}\\
\end{array}
\end{array}
if (/.f64 (*.f64 eps (-.f64 (exp.f64 (*.f64 (+.f64 a b) eps)) 1)) (*.f64 (-.f64 (exp.f64 (*.f64 a eps)) 1) (-.f64 (exp.f64 (*.f64 b eps)) 1))) < -inf.0Initial program 2.6%
*-commutative2.6%
*-commutative2.6%
associate-*l/2.6%
*-commutative2.6%
expm1-def2.6%
*-commutative2.6%
*-commutative2.6%
expm1-def42.3%
*-commutative42.3%
expm1-def69.7%
*-commutative69.7%
Simplified69.7%
Taylor expanded in a around 0 46.9%
if -inf.0 < (/.f64 (*.f64 eps (-.f64 (exp.f64 (*.f64 (+.f64 a b) eps)) 1)) (*.f64 (-.f64 (exp.f64 (*.f64 a eps)) 1) (-.f64 (exp.f64 (*.f64 b eps)) 1))) < 0.0100000000000000002Initial program 92.9%
times-frac92.9%
expm1-def98.9%
*-commutative98.9%
expm1-def99.0%
*-commutative99.0%
expm1-def99.8%
*-commutative99.8%
Simplified99.8%
if 0.0100000000000000002 < (/.f64 (*.f64 eps (-.f64 (exp.f64 (*.f64 (+.f64 a b) eps)) 1)) (*.f64 (-.f64 (exp.f64 (*.f64 a eps)) 1) (-.f64 (exp.f64 (*.f64 b eps)) 1))) Initial program 0.5%
*-commutative0.5%
*-commutative0.5%
associate-*l/0.5%
*-commutative0.5%
expm1-def2.4%
*-commutative2.4%
*-commutative2.4%
expm1-def9.4%
*-commutative9.4%
expm1-def35.2%
*-commutative35.2%
Simplified35.2%
Taylor expanded in eps around 0 73.4%
Taylor expanded in a around 0 100.0%
Final simplification95.4%
NOTE: a and b should be sorted in increasing order before calling this function.
(FPCore (a b eps)
:precision binary64
(if (<= a 1.56e+44)
(+ (/ 1.0 a) (/ 1.0 b))
(*
eps
(/ (expm1 (* eps (+ a b))) (* (expm1 (* eps a)) (expm1 (* eps b)))))))assert(a < b);
double code(double a, double b, double eps) {
double tmp;
if (a <= 1.56e+44) {
tmp = (1.0 / a) + (1.0 / b);
} else {
tmp = eps * (expm1((eps * (a + b))) / (expm1((eps * a)) * expm1((eps * b))));
}
return tmp;
}
assert a < b;
public static double code(double a, double b, double eps) {
double tmp;
if (a <= 1.56e+44) {
tmp = (1.0 / a) + (1.0 / b);
} else {
tmp = eps * (Math.expm1((eps * (a + b))) / (Math.expm1((eps * a)) * Math.expm1((eps * b))));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b, eps): tmp = 0 if a <= 1.56e+44: tmp = (1.0 / a) + (1.0 / b) else: tmp = eps * (math.expm1((eps * (a + b))) / (math.expm1((eps * a)) * math.expm1((eps * b)))) return tmp
a, b = sort([a, b]) function code(a, b, eps) tmp = 0.0 if (a <= 1.56e+44) tmp = Float64(Float64(1.0 / a) + Float64(1.0 / b)); else tmp = Float64(eps * Float64(expm1(Float64(eps * Float64(a + b))) / Float64(expm1(Float64(eps * a)) * expm1(Float64(eps * b))))); end return tmp end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_, eps_] := If[LessEqual[a, 1.56e+44], N[(N[(1.0 / a), $MachinePrecision] + N[(1.0 / b), $MachinePrecision]), $MachinePrecision], N[(eps * N[(N[(Exp[N[(eps * N[(a + b), $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision] / N[(N[(Exp[N[(eps * a), $MachinePrecision]] - 1), $MachinePrecision] * N[(Exp[N[(eps * b), $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.56 \cdot 10^{+44}:\\
\;\;\;\;\frac{1}{a} + \frac{1}{b}\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \frac{\mathsf{expm1}\left(\varepsilon \cdot \left(a + b\right)\right)}{\mathsf{expm1}\left(\varepsilon \cdot a\right) \cdot \mathsf{expm1}\left(\varepsilon \cdot b\right)}\\
\end{array}
\end{array}
if a < 1.56e44Initial program 3.6%
*-commutative3.6%
*-commutative3.6%
associate-*l/3.6%
*-commutative3.6%
expm1-def5.5%
*-commutative5.5%
*-commutative5.5%
expm1-def14.7%
*-commutative14.7%
expm1-def36.9%
*-commutative36.9%
Simplified36.9%
Taylor expanded in eps around 0 73.4%
Taylor expanded in a around 0 97.3%
if 1.56e44 < a Initial program 22.7%
*-commutative22.7%
*-commutative22.7%
associate-*l/22.7%
*-commutative22.7%
expm1-def23.3%
*-commutative23.3%
*-commutative23.3%
expm1-def35.8%
*-commutative35.8%
expm1-def72.3%
*-commutative72.3%
Simplified72.3%
Final simplification93.6%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b eps) :precision binary64 (if (<= a 3.1e+19) (+ (/ 1.0 a) (/ 1.0 b)) (* (/ eps (expm1 (* eps a))) (/ (+ a b) b))))
assert(a < b);
double code(double a, double b, double eps) {
double tmp;
if (a <= 3.1e+19) {
tmp = (1.0 / a) + (1.0 / b);
} else {
tmp = (eps / expm1((eps * a))) * ((a + b) / b);
}
return tmp;
}
assert a < b;
public static double code(double a, double b, double eps) {
double tmp;
if (a <= 3.1e+19) {
tmp = (1.0 / a) + (1.0 / b);
} else {
tmp = (eps / Math.expm1((eps * a))) * ((a + b) / b);
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b, eps): tmp = 0 if a <= 3.1e+19: tmp = (1.0 / a) + (1.0 / b) else: tmp = (eps / math.expm1((eps * a))) * ((a + b) / b) return tmp
a, b = sort([a, b]) function code(a, b, eps) tmp = 0.0 if (a <= 3.1e+19) tmp = Float64(Float64(1.0 / a) + Float64(1.0 / b)); else tmp = Float64(Float64(eps / expm1(Float64(eps * a))) * Float64(Float64(a + b) / b)); end return tmp end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_, eps_] := If[LessEqual[a, 3.1e+19], N[(N[(1.0 / a), $MachinePrecision] + N[(1.0 / b), $MachinePrecision]), $MachinePrecision], N[(N[(eps / N[(Exp[N[(eps * a), $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision] * N[(N[(a + b), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq 3.1 \cdot 10^{+19}:\\
\;\;\;\;\frac{1}{a} + \frac{1}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{\mathsf{expm1}\left(\varepsilon \cdot a\right)} \cdot \frac{a + b}{b}\\
\end{array}
\end{array}
if a < 3.1e19Initial program 3.7%
*-commutative3.7%
*-commutative3.7%
associate-*l/3.7%
*-commutative3.7%
expm1-def5.5%
*-commutative5.5%
*-commutative5.5%
expm1-def14.5%
*-commutative14.5%
expm1-def36.2%
*-commutative36.2%
Simplified36.2%
Taylor expanded in eps around 0 72.9%
Taylor expanded in a around 0 97.2%
if 3.1e19 < a Initial program 20.6%
times-frac20.6%
expm1-def34.1%
*-commutative34.1%
expm1-def34.5%
*-commutative34.5%
expm1-def77.4%
*-commutative77.4%
Simplified77.4%
Taylor expanded in eps around 0 56.2%
Final simplification90.5%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b eps) :precision binary64 (if (<= a 3.5e+19) (+ (/ 1.0 a) (/ 1.0 b)) (/ eps (expm1 (* eps a)))))
assert(a < b);
double code(double a, double b, double eps) {
double tmp;
if (a <= 3.5e+19) {
tmp = (1.0 / a) + (1.0 / b);
} else {
tmp = eps / expm1((eps * a));
}
return tmp;
}
assert a < b;
public static double code(double a, double b, double eps) {
double tmp;
if (a <= 3.5e+19) {
tmp = (1.0 / a) + (1.0 / b);
} else {
tmp = eps / Math.expm1((eps * a));
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b, eps): tmp = 0 if a <= 3.5e+19: tmp = (1.0 / a) + (1.0 / b) else: tmp = eps / math.expm1((eps * a)) return tmp
a, b = sort([a, b]) function code(a, b, eps) tmp = 0.0 if (a <= 3.5e+19) tmp = Float64(Float64(1.0 / a) + Float64(1.0 / b)); else tmp = Float64(eps / expm1(Float64(eps * a))); end return tmp end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_, eps_] := If[LessEqual[a, 3.5e+19], N[(N[(1.0 / a), $MachinePrecision] + N[(1.0 / b), $MachinePrecision]), $MachinePrecision], N[(eps / N[(Exp[N[(eps * a), $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq 3.5 \cdot 10^{+19}:\\
\;\;\;\;\frac{1}{a} + \frac{1}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{\mathsf{expm1}\left(\varepsilon \cdot a\right)}\\
\end{array}
\end{array}
if a < 3.5e19Initial program 3.7%
*-commutative3.7%
*-commutative3.7%
associate-*l/3.7%
*-commutative3.7%
expm1-def5.5%
*-commutative5.5%
*-commutative5.5%
expm1-def14.5%
*-commutative14.5%
expm1-def36.2%
*-commutative36.2%
Simplified36.2%
Taylor expanded in eps around 0 72.9%
Taylor expanded in a around 0 97.2%
if 3.5e19 < a Initial program 20.6%
times-frac20.6%
expm1-def34.1%
*-commutative34.1%
expm1-def34.5%
*-commutative34.5%
expm1-def77.4%
*-commutative77.4%
Simplified77.4%
Taylor expanded in a around 0 44.8%
Final simplification88.6%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b eps) :precision binary64 (+ (/ 1.0 a) (/ 1.0 b)))
assert(a < b);
double code(double a, double b, double eps) {
return (1.0 / a) + (1.0 / b);
}
NOTE: a and b should be sorted in increasing order before calling this function.
real(8) function code(a, b, eps)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: eps
code = (1.0d0 / a) + (1.0d0 / b)
end function
assert a < b;
public static double code(double a, double b, double eps) {
return (1.0 / a) + (1.0 / b);
}
[a, b] = sort([a, b]) def code(a, b, eps): return (1.0 / a) + (1.0 / b)
a, b = sort([a, b]) function code(a, b, eps) return Float64(Float64(1.0 / a) + Float64(1.0 / b)) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b, eps)
tmp = (1.0 / a) + (1.0 / b);
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_, eps_] := N[(N[(1.0 / a), $MachinePrecision] + N[(1.0 / b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{1}{a} + \frac{1}{b}
\end{array}
Initial program 6.5%
*-commutative6.5%
*-commutative6.5%
associate-*l/6.5%
*-commutative6.5%
expm1-def8.1%
*-commutative8.1%
*-commutative8.1%
expm1-def17.8%
*-commutative17.8%
expm1-def42.2%
*-commutative42.2%
Simplified42.2%
Taylor expanded in eps around 0 71.7%
Taylor expanded in a around 0 94.8%
Final simplification94.8%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b eps) :precision binary64 (if (<= a -1.3e-156) (/ 1.0 b) (/ 1.0 a)))
assert(a < b);
double code(double a, double b, double eps) {
double tmp;
if (a <= -1.3e-156) {
tmp = 1.0 / b;
} else {
tmp = 1.0 / a;
}
return tmp;
}
NOTE: a and b should be sorted in increasing order before calling this function.
real(8) function code(a, b, eps)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: eps
real(8) :: tmp
if (a <= (-1.3d-156)) then
tmp = 1.0d0 / b
else
tmp = 1.0d0 / a
end if
code = tmp
end function
assert a < b;
public static double code(double a, double b, double eps) {
double tmp;
if (a <= -1.3e-156) {
tmp = 1.0 / b;
} else {
tmp = 1.0 / a;
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b, eps): tmp = 0 if a <= -1.3e-156: tmp = 1.0 / b else: tmp = 1.0 / a return tmp
a, b = sort([a, b]) function code(a, b, eps) tmp = 0.0 if (a <= -1.3e-156) tmp = Float64(1.0 / b); else tmp = Float64(1.0 / a); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b, eps)
tmp = 0.0;
if (a <= -1.3e-156)
tmp = 1.0 / b;
else
tmp = 1.0 / a;
end
tmp_2 = tmp;
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_, eps_] := If[LessEqual[a, -1.3e-156], N[(1.0 / b), $MachinePrecision], N[(1.0 / a), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.3 \cdot 10^{-156}:\\
\;\;\;\;\frac{1}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{a}\\
\end{array}
\end{array}
if a < -1.3e-156Initial program 8.3%
*-commutative8.3%
*-commutative8.3%
associate-*l/8.3%
*-commutative8.3%
expm1-def9.8%
*-commutative9.8%
*-commutative9.8%
expm1-def22.2%
*-commutative22.2%
expm1-def59.7%
*-commutative59.7%
Simplified59.7%
Taylor expanded in b around 0 56.6%
if -1.3e-156 < a Initial program 5.5%
*-commutative5.5%
*-commutative5.5%
associate-*l/5.5%
*-commutative5.5%
expm1-def7.2%
*-commutative7.2%
*-commutative7.2%
expm1-def15.6%
*-commutative15.6%
expm1-def33.3%
*-commutative33.3%
Simplified33.3%
Taylor expanded in a around 0 61.8%
Final simplification60.1%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b eps) :precision binary64 (/ 1.0 a))
assert(a < b);
double code(double a, double b, double eps) {
return 1.0 / a;
}
NOTE: a and b should be sorted in increasing order before calling this function.
real(8) function code(a, b, eps)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: eps
code = 1.0d0 / a
end function
assert a < b;
public static double code(double a, double b, double eps) {
return 1.0 / a;
}
[a, b] = sort([a, b]) def code(a, b, eps): return 1.0 / a
a, b = sort([a, b]) function code(a, b, eps) return Float64(1.0 / a) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b, eps)
tmp = 1.0 / a;
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_, eps_] := N[(1.0 / a), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{1}{a}
\end{array}
Initial program 6.5%
*-commutative6.5%
*-commutative6.5%
associate-*l/6.5%
*-commutative6.5%
expm1-def8.1%
*-commutative8.1%
*-commutative8.1%
expm1-def17.8%
*-commutative17.8%
expm1-def42.2%
*-commutative42.2%
Simplified42.2%
Taylor expanded in a around 0 53.7%
Final simplification53.7%
(FPCore (a b eps) :precision binary64 (/ (+ a b) (* a b)))
double code(double a, double b, double eps) {
return (a + b) / (a * b);
}
real(8) function code(a, b, eps)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: eps
code = (a + b) / (a * b)
end function
public static double code(double a, double b, double eps) {
return (a + b) / (a * b);
}
def code(a, b, eps): return (a + b) / (a * b)
function code(a, b, eps) return Float64(Float64(a + b) / Float64(a * b)) end
function tmp = code(a, b, eps) tmp = (a + b) / (a * b); end
code[a_, b_, eps_] := N[(N[(a + b), $MachinePrecision] / N[(a * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a + b}{a \cdot b}
\end{array}
herbie shell --seed 2023305
(FPCore (a b eps)
:name "expq3 (problem 3.4.2)"
:precision binary64
:pre (and (< -1.0 eps) (< eps 1.0))
:herbie-target
(/ (+ a b) (* a b))
(/ (* eps (- (exp (* (+ a b) eps)) 1.0)) (* (- (exp (* a eps)) 1.0) (- (exp (* b eps)) 1.0))))