
(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 4 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, b, and eps should be sorted in increasing order before calling this function. (FPCore (a b eps) :precision binary64 (/ (+ (/ b a) 1.0) b))
assert(a < b && b < eps);
double code(double a, double b, double eps) {
return ((b / a) + 1.0) / b;
}
NOTE: a, b, and eps 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 = ((b / a) + 1.0d0) / b
end function
assert a < b && b < eps;
public static double code(double a, double b, double eps) {
return ((b / a) + 1.0) / b;
}
[a, b, eps] = sort([a, b, eps]) def code(a, b, eps): return ((b / a) + 1.0) / b
a, b, eps = sort([a, b, eps]) function code(a, b, eps) return Float64(Float64(Float64(b / a) + 1.0) / b) end
a, b, eps = num2cell(sort([a, b, eps])){:}
function tmp = code(a, b, eps)
tmp = ((b / a) + 1.0) / b;
end
NOTE: a, b, and eps should be sorted in increasing order before calling this function. code[a_, b_, eps_] := N[(N[(N[(b / a), $MachinePrecision] + 1.0), $MachinePrecision] / b), $MachinePrecision]
\begin{array}{l}
[a, b, eps] = \mathsf{sort}([a, b, eps])\\
\\
\frac{\frac{b}{a} + 1}{b}
\end{array}
Initial program 0.0%
Taylor expanded in b around 0
lower-/.f64N/A
Applied rewrites45.3%
Taylor expanded in eps around 0
Applied rewrites99.7%
NOTE: a, b, and eps should be sorted in increasing order before calling this function. (FPCore (a b eps) :precision binary64 (if (<= b 2.1e-196) (/ 1.0 b) (if (<= b 2.5e-140) (/ 1.0 a) (/ (+ b a) (* b a)))))
assert(a < b && b < eps);
double code(double a, double b, double eps) {
double tmp;
if (b <= 2.1e-196) {
tmp = 1.0 / b;
} else if (b <= 2.5e-140) {
tmp = 1.0 / a;
} else {
tmp = (b + a) / (b * a);
}
return tmp;
}
NOTE: a, b, and eps 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 <= 2.1d-196) then
tmp = 1.0d0 / b
else if (b <= 2.5d-140) then
tmp = 1.0d0 / a
else
tmp = (b + a) / (b * a)
end if
code = tmp
end function
assert a < b && b < eps;
public static double code(double a, double b, double eps) {
double tmp;
if (b <= 2.1e-196) {
tmp = 1.0 / b;
} else if (b <= 2.5e-140) {
tmp = 1.0 / a;
} else {
tmp = (b + a) / (b * a);
}
return tmp;
}
[a, b, eps] = sort([a, b, eps]) def code(a, b, eps): tmp = 0 if b <= 2.1e-196: tmp = 1.0 / b elif b <= 2.5e-140: tmp = 1.0 / a else: tmp = (b + a) / (b * a) return tmp
a, b, eps = sort([a, b, eps]) function code(a, b, eps) tmp = 0.0 if (b <= 2.1e-196) tmp = Float64(1.0 / b); elseif (b <= 2.5e-140) tmp = Float64(1.0 / a); else tmp = Float64(Float64(b + a) / Float64(b * a)); end return tmp end
a, b, eps = num2cell(sort([a, b, eps])){:}
function tmp_2 = code(a, b, eps)
tmp = 0.0;
if (b <= 2.1e-196)
tmp = 1.0 / b;
elseif (b <= 2.5e-140)
tmp = 1.0 / a;
else
tmp = (b + a) / (b * a);
end
tmp_2 = tmp;
end
NOTE: a, b, and eps should be sorted in increasing order before calling this function. code[a_, b_, eps_] := If[LessEqual[b, 2.1e-196], N[(1.0 / b), $MachinePrecision], If[LessEqual[b, 2.5e-140], N[(1.0 / a), $MachinePrecision], N[(N[(b + a), $MachinePrecision] / N[(b * a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[a, b, eps] = \mathsf{sort}([a, b, eps])\\
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.1 \cdot 10^{-196}:\\
\;\;\;\;\frac{1}{b}\\
\mathbf{elif}\;b \leq 2.5 \cdot 10^{-140}:\\
\;\;\;\;\frac{1}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a}{b \cdot a}\\
\end{array}
\end{array}
if b < 2.09999999999999988e-196Initial program 0.0%
Taylor expanded in b around 0
lower-/.f6461.1
Applied rewrites61.1%
if 2.09999999999999988e-196 < b < 2.50000000000000007e-140Initial program 0.0%
Taylor expanded in a around 0
lower-/.f6447.3
Applied rewrites47.3%
if 2.50000000000000007e-140 < b Initial program 0.0%
Taylor expanded in eps around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f6486.1
Applied rewrites86.1%
NOTE: a, b, and eps should be sorted in increasing order before calling this function. (FPCore (a b eps) :precision binary64 (if (<= b 2.1e-196) (/ 1.0 b) (/ 1.0 a)))
assert(a < b && b < eps);
double code(double a, double b, double eps) {
double tmp;
if (b <= 2.1e-196) {
tmp = 1.0 / b;
} else {
tmp = 1.0 / a;
}
return tmp;
}
NOTE: a, b, and eps 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 <= 2.1d-196) then
tmp = 1.0d0 / b
else
tmp = 1.0d0 / a
end if
code = tmp
end function
assert a < b && b < eps;
public static double code(double a, double b, double eps) {
double tmp;
if (b <= 2.1e-196) {
tmp = 1.0 / b;
} else {
tmp = 1.0 / a;
}
return tmp;
}
[a, b, eps] = sort([a, b, eps]) def code(a, b, eps): tmp = 0 if b <= 2.1e-196: tmp = 1.0 / b else: tmp = 1.0 / a return tmp
a, b, eps = sort([a, b, eps]) function code(a, b, eps) tmp = 0.0 if (b <= 2.1e-196) tmp = Float64(1.0 / b); else tmp = Float64(1.0 / a); end return tmp end
a, b, eps = num2cell(sort([a, b, eps])){:}
function tmp_2 = code(a, b, eps)
tmp = 0.0;
if (b <= 2.1e-196)
tmp = 1.0 / b;
else
tmp = 1.0 / a;
end
tmp_2 = tmp;
end
NOTE: a, b, and eps should be sorted in increasing order before calling this function. code[a_, b_, eps_] := If[LessEqual[b, 2.1e-196], N[(1.0 / b), $MachinePrecision], N[(1.0 / a), $MachinePrecision]]
\begin{array}{l}
[a, b, eps] = \mathsf{sort}([a, b, eps])\\
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.1 \cdot 10^{-196}:\\
\;\;\;\;\frac{1}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{a}\\
\end{array}
\end{array}
if b < 2.09999999999999988e-196Initial program 0.0%
Taylor expanded in b around 0
lower-/.f6461.1
Applied rewrites61.1%
if 2.09999999999999988e-196 < b Initial program 0.0%
Taylor expanded in a around 0
lower-/.f6464.8
Applied rewrites64.8%
NOTE: a, b, and eps should be sorted in increasing order before calling this function. (FPCore (a b eps) :precision binary64 (/ 1.0 a))
assert(a < b && b < eps);
double code(double a, double b, double eps) {
return 1.0 / a;
}
NOTE: a, b, and eps 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 && b < eps;
public static double code(double a, double b, double eps) {
return 1.0 / a;
}
[a, b, eps] = sort([a, b, eps]) def code(a, b, eps): return 1.0 / a
a, b, eps = sort([a, b, eps]) function code(a, b, eps) return Float64(1.0 / a) end
a, b, eps = num2cell(sort([a, b, eps])){:}
function tmp = code(a, b, eps)
tmp = 1.0 / a;
end
NOTE: a, b, and eps should be sorted in increasing order before calling this function. code[a_, b_, eps_] := N[(1.0 / a), $MachinePrecision]
\begin{array}{l}
[a, b, eps] = \mathsf{sort}([a, b, eps])\\
\\
\frac{1}{a}
\end{array}
Initial program 0.0%
Taylor expanded in a around 0
lower-/.f6446.7
Applied rewrites46.7%
(FPCore (a b eps) :precision binary64 (+ (/ 1.0 a) (/ 1.0 b)))
double code(double a, double b, double eps) {
return (1.0 / a) + (1.0 / b);
}
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
public static double code(double a, double b, double eps) {
return (1.0 / a) + (1.0 / b);
}
def code(a, b, eps): return (1.0 / a) + (1.0 / b)
function code(a, b, eps) return Float64(Float64(1.0 / a) + Float64(1.0 / b)) end
function tmp = code(a, b, eps) tmp = (1.0 / a) + (1.0 / b); end
code[a_, b_, eps_] := N[(N[(1.0 / a), $MachinePrecision] + N[(1.0 / b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{a} + \frac{1}{b}
\end{array}
herbie shell --seed 2024235
(FPCore (a b eps)
:name "expq3 (problem 3.4.2)"
:precision binary64
:pre (and (and (<= (fabs a) 710.0) (<= (fabs b) 710.0)) (and (<= (* 1e-27 (fmin (fabs a) (fabs b))) eps) (<= eps (fmin (fabs a) (fabs b)))))
:alt
(! :herbie-platform default (+ (/ 1 a) (/ 1 b)))
(/ (* eps (- (exp (* (+ a b) eps)) 1.0)) (* (- (exp (* a eps)) 1.0) (- (exp (* b eps)) 1.0))))