
(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 8 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))))
(if (<=
(/
(* eps (+ (exp t_0) -1.0))
(* (+ (exp (* eps a)) -1.0) (+ (exp (* eps b)) -1.0)))
2e-55)
(* (expm1 t_0) (/ (/ eps (expm1 (* eps b))) (expm1 (* eps a))))
(+ (/ 1.0 b) (/ 1.0 a)))))assert(a < b);
double code(double a, double b, double eps) {
double t_0 = eps * (a + b);
double tmp;
if (((eps * (exp(t_0) + -1.0)) / ((exp((eps * a)) + -1.0) * (exp((eps * b)) + -1.0))) <= 2e-55) {
tmp = expm1(t_0) * ((eps / expm1((eps * b))) / expm1((eps * a)));
} else {
tmp = (1.0 / b) + (1.0 / a);
}
return tmp;
}
assert a < b;
public static double code(double a, double b, double eps) {
double t_0 = eps * (a + b);
double tmp;
if (((eps * (Math.exp(t_0) + -1.0)) / ((Math.exp((eps * a)) + -1.0) * (Math.exp((eps * b)) + -1.0))) <= 2e-55) {
tmp = Math.expm1(t_0) * ((eps / Math.expm1((eps * b))) / Math.expm1((eps * a)));
} else {
tmp = (1.0 / b) + (1.0 / a);
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b, eps): t_0 = eps * (a + b) tmp = 0 if ((eps * (math.exp(t_0) + -1.0)) / ((math.exp((eps * a)) + -1.0) * (math.exp((eps * b)) + -1.0))) <= 2e-55: tmp = math.expm1(t_0) * ((eps / math.expm1((eps * b))) / math.expm1((eps * a))) else: tmp = (1.0 / b) + (1.0 / a) return tmp
a, b = sort([a, b]) function code(a, b, eps) t_0 = Float64(eps * Float64(a + b)) tmp = 0.0 if (Float64(Float64(eps * Float64(exp(t_0) + -1.0)) / Float64(Float64(exp(Float64(eps * a)) + -1.0) * Float64(exp(Float64(eps * b)) + -1.0))) <= 2e-55) tmp = Float64(expm1(t_0) * Float64(Float64(eps / expm1(Float64(eps * b))) / expm1(Float64(eps * a)))); else tmp = Float64(Float64(1.0 / b) + Float64(1.0 / a)); 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]}, If[LessEqual[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], 2e-55], N[(N[(Exp[t$95$0] - 1), $MachinePrecision] * N[(N[(eps / N[(Exp[N[(eps * b), $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision] / N[(Exp[N[(eps * a), $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / b), $MachinePrecision] + N[(1.0 / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
t_0 := \varepsilon \cdot \left(a + b\right)\\
\mathbf{if}\;\frac{\varepsilon \cdot \left(e^{t_0} + -1\right)}{\left(e^{\varepsilon \cdot a} + -1\right) \cdot \left(e^{\varepsilon \cdot b} + -1\right)} \leq 2 \cdot 10^{-55}:\\
\;\;\;\;\mathsf{expm1}\left(t_0\right) \cdot \frac{\frac{\varepsilon}{\mathsf{expm1}\left(\varepsilon \cdot b\right)}}{\mathsf{expm1}\left(\varepsilon \cdot a\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{b} + \frac{1}{a}\\
\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))) < 1.99999999999999999e-55Initial program 43.4%
*-commutative43.4%
associate-*l/43.4%
*-commutative43.4%
expm1-def43.4%
*-commutative43.4%
associate-/r*43.4%
expm1-def66.7%
*-commutative66.7%
expm1-def96.1%
*-commutative96.1%
Simplified96.1%
if 1.99999999999999999e-55 < (/.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.4%
*-commutative0.4%
associate-*l/0.4%
*-commutative0.4%
expm1-def2.4%
*-commutative2.4%
associate-/r*2.4%
expm1-def9.1%
*-commutative9.1%
expm1-def44.3%
*-commutative44.3%
Simplified44.3%
Taylor expanded in eps around 0 80.6%
Taylor expanded in a around 0 100.0%
Final simplification99.3%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b eps) :precision binary64 (if (<= eps 7e-123) (- (+ (/ 1.0 b) (/ 1.0 a)) (* eps 0.5)) (* (/ eps (expm1 (* eps b))) (/ (+ a b) a))))
assert(a < b);
double code(double a, double b, double eps) {
double tmp;
if (eps <= 7e-123) {
tmp = ((1.0 / b) + (1.0 / a)) - (eps * 0.5);
} else {
tmp = (eps / expm1((eps * b))) * ((a + b) / a);
}
return tmp;
}
assert a < b;
public static double code(double a, double b, double eps) {
double tmp;
if (eps <= 7e-123) {
tmp = ((1.0 / b) + (1.0 / a)) - (eps * 0.5);
} else {
tmp = (eps / Math.expm1((eps * b))) * ((a + b) / a);
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b, eps): tmp = 0 if eps <= 7e-123: tmp = ((1.0 / b) + (1.0 / a)) - (eps * 0.5) else: tmp = (eps / math.expm1((eps * b))) * ((a + b) / a) return tmp
a, b = sort([a, b]) function code(a, b, eps) tmp = 0.0 if (eps <= 7e-123) tmp = Float64(Float64(Float64(1.0 / b) + Float64(1.0 / a)) - Float64(eps * 0.5)); else tmp = Float64(Float64(eps / expm1(Float64(eps * b))) * Float64(Float64(a + b) / 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[eps, 7e-123], N[(N[(N[(1.0 / b), $MachinePrecision] + N[(1.0 / a), $MachinePrecision]), $MachinePrecision] - N[(eps * 0.5), $MachinePrecision]), $MachinePrecision], N[(N[(eps / N[(Exp[N[(eps * b), $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision] * N[(N[(a + b), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq 7 \cdot 10^{-123}:\\
\;\;\;\;\left(\frac{1}{b} + \frac{1}{a}\right) - \varepsilon \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{\mathsf{expm1}\left(\varepsilon \cdot b\right)} \cdot \frac{a + b}{a}\\
\end{array}
\end{array}
if eps < 6.9999999999999997e-123Initial program 4.5%
*-commutative4.5%
times-frac4.5%
+-commutative4.5%
expm1-def12.4%
*-commutative12.4%
expm1-def14.0%
+-commutative14.0%
*-commutative14.0%
expm1-def53.2%
*-commutative53.2%
Simplified53.2%
Taylor expanded in eps around 0 54.7%
Taylor expanded in b around 0 96.6%
if 6.9999999999999997e-123 < eps Initial program 24.3%
*-commutative24.3%
times-frac24.3%
+-commutative24.3%
expm1-def42.9%
*-commutative42.9%
expm1-def43.6%
+-commutative43.6%
*-commutative43.6%
expm1-def88.9%
*-commutative88.9%
Simplified88.9%
Taylor expanded in eps around 0 70.3%
Final simplification91.8%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b eps) :precision binary64 (- (+ (/ 1.0 b) (/ 1.0 a)) (* eps 0.5)))
assert(a < b);
double code(double a, double b, double eps) {
return ((1.0 / b) + (1.0 / a)) - (eps * 0.5);
}
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 / b) + (1.0d0 / a)) - (eps * 0.5d0)
end function
assert a < b;
public static double code(double a, double b, double eps) {
return ((1.0 / b) + (1.0 / a)) - (eps * 0.5);
}
[a, b] = sort([a, b]) def code(a, b, eps): return ((1.0 / b) + (1.0 / a)) - (eps * 0.5)
a, b = sort([a, b]) function code(a, b, eps) return Float64(Float64(Float64(1.0 / b) + Float64(1.0 / a)) - Float64(eps * 0.5)) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b, eps)
tmp = ((1.0 / b) + (1.0 / a)) - (eps * 0.5);
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_, eps_] := N[(N[(N[(1.0 / b), $MachinePrecision] + N[(1.0 / a), $MachinePrecision]), $MachinePrecision] - N[(eps * 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\left(\frac{1}{b} + \frac{1}{a}\right) - \varepsilon \cdot 0.5
\end{array}
Initial program 8.1%
*-commutative8.1%
times-frac8.1%
+-commutative8.1%
expm1-def18.0%
*-commutative18.0%
expm1-def19.4%
+-commutative19.4%
*-commutative19.4%
expm1-def59.7%
*-commutative59.7%
Simplified59.7%
Taylor expanded in eps around 0 57.5%
Taylor expanded in b around 0 93.3%
Final simplification93.3%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b eps) :precision binary64 (if (<= b 1.2e-28) (/ 1.0 b) (+ (/ 1.0 a) (* eps -0.5))))
assert(a < b);
double code(double a, double b, double eps) {
double tmp;
if (b <= 1.2e-28) {
tmp = 1.0 / b;
} else {
tmp = (1.0 / a) + (eps * -0.5);
}
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 (b <= 1.2d-28) then
tmp = 1.0d0 / b
else
tmp = (1.0d0 / a) + (eps * (-0.5d0))
end if
code = tmp
end function
assert a < b;
public static double code(double a, double b, double eps) {
double tmp;
if (b <= 1.2e-28) {
tmp = 1.0 / b;
} else {
tmp = (1.0 / a) + (eps * -0.5);
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b, eps): tmp = 0 if b <= 1.2e-28: tmp = 1.0 / b else: tmp = (1.0 / a) + (eps * -0.5) return tmp
a, b = sort([a, b]) function code(a, b, eps) tmp = 0.0 if (b <= 1.2e-28) tmp = Float64(1.0 / b); else tmp = Float64(Float64(1.0 / a) + Float64(eps * -0.5)); end return tmp end
a, b = num2cell(sort([a, b])){:}
function tmp_2 = code(a, b, eps)
tmp = 0.0;
if (b <= 1.2e-28)
tmp = 1.0 / b;
else
tmp = (1.0 / a) + (eps * -0.5);
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[b, 1.2e-28], N[(1.0 / b), $MachinePrecision], N[(N[(1.0 / a), $MachinePrecision] + N[(eps * -0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.2 \cdot 10^{-28}:\\
\;\;\;\;\frac{1}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{a} + \varepsilon \cdot -0.5\\
\end{array}
\end{array}
if b < 1.2000000000000001e-28Initial program 6.8%
*-commutative6.8%
associate-*l/6.8%
*-commutative6.8%
expm1-def8.5%
*-commutative8.5%
associate-/r*8.5%
expm1-def18.3%
*-commutative18.3%
expm1-def47.3%
*-commutative47.3%
Simplified47.3%
Taylor expanded in b around 0 52.6%
if 1.2000000000000001e-28 < b Initial program 11.9%
*-commutative11.9%
associate-*l/11.9%
*-commutative11.9%
expm1-def13.4%
*-commutative13.4%
associate-/r*13.4%
expm1-def22.6%
*-commutative22.6%
expm1-def70.8%
*-commutative70.8%
Simplified70.8%
Taylor expanded in a around 0 47.5%
Taylor expanded in eps around 0 71.5%
Final simplification57.6%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b eps) :precision binary64 (+ (/ 1.0 b) (/ 1.0 a)))
assert(a < b);
double code(double a, double b, double eps) {
return (1.0 / b) + (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 / b) + (1.0d0 / a)
end function
assert a < b;
public static double code(double a, double b, double eps) {
return (1.0 / b) + (1.0 / a);
}
[a, b] = sort([a, b]) def code(a, b, eps): return (1.0 / b) + (1.0 / a)
a, b = sort([a, b]) function code(a, b, eps) return Float64(Float64(1.0 / b) + Float64(1.0 / a)) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b, eps)
tmp = (1.0 / b) + (1.0 / a);
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_, eps_] := N[(N[(1.0 / b), $MachinePrecision] + N[(1.0 / a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{1}{b} + \frac{1}{a}
\end{array}
Initial program 8.1%
*-commutative8.1%
associate-*l/8.1%
*-commutative8.1%
expm1-def9.8%
*-commutative9.8%
associate-/r*9.8%
expm1-def19.4%
*-commutative19.4%
expm1-def53.6%
*-commutative53.6%
Simplified53.6%
Taylor expanded in eps around 0 79.3%
Taylor expanded in a around 0 93.0%
Final simplification93.0%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b eps) :precision binary64 (if (<= b 1.8e-25) (/ 1.0 b) (/ 1.0 a)))
assert(a < b);
double code(double a, double b, double eps) {
double tmp;
if (b <= 1.8e-25) {
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 (b <= 1.8d-25) 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 (b <= 1.8e-25) {
tmp = 1.0 / b;
} else {
tmp = 1.0 / a;
}
return tmp;
}
[a, b] = sort([a, b]) def code(a, b, eps): tmp = 0 if b <= 1.8e-25: 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 (b <= 1.8e-25) 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 (b <= 1.8e-25)
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[b, 1.8e-25], N[(1.0 / b), $MachinePrecision], N[(1.0 / a), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.8 \cdot 10^{-25}:\\
\;\;\;\;\frac{1}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{a}\\
\end{array}
\end{array}
if b < 1.8e-25Initial program 6.8%
*-commutative6.8%
associate-*l/6.8%
*-commutative6.8%
expm1-def8.5%
*-commutative8.5%
associate-/r*8.5%
expm1-def18.3%
*-commutative18.3%
expm1-def47.3%
*-commutative47.3%
Simplified47.3%
Taylor expanded in b around 0 52.6%
if 1.8e-25 < b Initial program 11.9%
*-commutative11.9%
associate-*l/11.9%
*-commutative11.9%
expm1-def13.4%
*-commutative13.4%
associate-/r*13.4%
expm1-def22.6%
*-commutative22.6%
expm1-def70.8%
*-commutative70.8%
Simplified70.8%
Taylor expanded in a around 0 71.0%
Final simplification57.5%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b eps) :precision binary64 (* eps -0.5))
assert(a < b);
double code(double a, double b, double eps) {
return eps * -0.5;
}
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 = eps * (-0.5d0)
end function
assert a < b;
public static double code(double a, double b, double eps) {
return eps * -0.5;
}
[a, b] = sort([a, b]) def code(a, b, eps): return eps * -0.5
a, b = sort([a, b]) function code(a, b, eps) return Float64(eps * -0.5) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b, eps)
tmp = eps * -0.5;
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_, eps_] := N[(eps * -0.5), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\varepsilon \cdot -0.5
\end{array}
Initial program 8.1%
*-commutative8.1%
times-frac8.1%
+-commutative8.1%
expm1-def18.0%
*-commutative18.0%
expm1-def19.4%
+-commutative19.4%
*-commutative19.4%
expm1-def59.7%
*-commutative59.7%
Simplified59.7%
Taylor expanded in eps around 0 57.5%
Taylor expanded in b around 0 93.3%
Taylor expanded in eps around inf 3.1%
*-commutative3.1%
Simplified3.1%
Final simplification3.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 8.1%
*-commutative8.1%
associate-*l/8.1%
*-commutative8.1%
expm1-def9.8%
*-commutative9.8%
associate-/r*9.8%
expm1-def19.4%
*-commutative19.4%
expm1-def53.6%
*-commutative53.6%
Simplified53.6%
Taylor expanded in a around 0 50.5%
Final simplification50.5%
(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 2023273
(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))))