
(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 6 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}
(FPCore (a b eps) :precision binary64 (+ (/ 1.0 b) (- (/ 1.0 a) eps)))
double code(double a, double b, double eps) {
return (1.0 / b) + ((1.0 / a) - eps);
}
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)
end function
public static double code(double a, double b, double eps) {
return (1.0 / b) + ((1.0 / a) - eps);
}
def code(a, b, eps): return (1.0 / b) + ((1.0 / a) - eps)
function code(a, b, eps) return Float64(Float64(1.0 / b) + Float64(Float64(1.0 / a) - eps)) end
function tmp = code(a, b, eps) tmp = (1.0 / b) + ((1.0 / a) - eps); end
code[a_, b_, eps_] := N[(N[(1.0 / b), $MachinePrecision] + N[(N[(1.0 / a), $MachinePrecision] - eps), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{b} + \left(\frac{1}{a} - \varepsilon\right)
\end{array}
Initial program 7.2%
*-commutative7.2%
associate-*l/7.2%
*-commutative7.2%
expm1-def8.7%
*-commutative8.7%
associate-/r*8.7%
expm1-def14.3%
*-commutative14.3%
expm1-def49.6%
*-commutative49.6%
Simplified49.6%
Taylor expanded in a around 0 16.8%
associate--l+16.8%
cancel-sign-sub-inv16.8%
metadata-eval16.8%
associate-/l*16.8%
expm1-def65.4%
*-commutative65.4%
Simplified65.4%
Taylor expanded in b around 0 95.4%
cancel-sign-sub-inv95.4%
associate-+r+95.4%
distribute-rgt1-in95.4%
metadata-eval95.4%
metadata-eval95.4%
associate-+l+95.4%
add-sqr-sqrt44.7%
sqrt-unprod95.5%
swap-sqr95.5%
metadata-eval95.5%
metadata-eval95.5%
swap-sqr95.5%
sqrt-unprod51.4%
add-sqr-sqrt97.6%
*-commutative97.6%
+-commutative97.6%
associate-+r+97.6%
*-commutative97.6%
fma-def97.6%
Applied egg-rr97.6%
+-commutative97.6%
+-commutative97.6%
associate-+l+97.6%
fma-udef97.6%
associate-+r+97.6%
*-commutative97.6%
+-commutative97.6%
*-commutative97.6%
associate-+r+97.6%
distribute-lft-out97.6%
metadata-eval97.6%
metadata-eval97.6%
distribute-rgt-neg-in97.6%
*-rgt-identity97.6%
Simplified97.6%
Final simplification97.6%
(FPCore (a b eps) :precision binary64 (if (<= b 5e-152) (/ 1.0 b) (- (/ 1.0 a) eps)))
double code(double a, double b, double eps) {
double tmp;
if (b <= 5e-152) {
tmp = 1.0 / b;
} else {
tmp = (1.0 / a) - eps;
}
return tmp;
}
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 <= 5d-152) then
tmp = 1.0d0 / b
else
tmp = (1.0d0 / a) - eps
end if
code = tmp
end function
public static double code(double a, double b, double eps) {
double tmp;
if (b <= 5e-152) {
tmp = 1.0 / b;
} else {
tmp = (1.0 / a) - eps;
}
return tmp;
}
def code(a, b, eps): tmp = 0 if b <= 5e-152: tmp = 1.0 / b else: tmp = (1.0 / a) - eps return tmp
function code(a, b, eps) tmp = 0.0 if (b <= 5e-152) tmp = Float64(1.0 / b); else tmp = Float64(Float64(1.0 / a) - eps); end return tmp end
function tmp_2 = code(a, b, eps) tmp = 0.0; if (b <= 5e-152) tmp = 1.0 / b; else tmp = (1.0 / a) - eps; end tmp_2 = tmp; end
code[a_, b_, eps_] := If[LessEqual[b, 5e-152], N[(1.0 / b), $MachinePrecision], N[(N[(1.0 / a), $MachinePrecision] - eps), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 5 \cdot 10^{-152}:\\
\;\;\;\;\frac{1}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{a} - \varepsilon\\
\end{array}
\end{array}
if b < 4.9999999999999997e-152Initial program 4.9%
*-commutative4.9%
associate-*l/4.9%
*-commutative4.9%
expm1-def6.6%
*-commutative6.6%
associate-/r*6.6%
expm1-def12.2%
*-commutative12.2%
expm1-def37.9%
*-commutative37.9%
Simplified37.9%
Taylor expanded in b around 0 60.4%
if 4.9999999999999997e-152 < b Initial program 11.6%
*-commutative11.6%
associate-*l/11.6%
*-commutative11.6%
expm1-def12.7%
*-commutative12.7%
associate-/r*12.7%
expm1-def18.4%
*-commutative18.4%
expm1-def71.8%
*-commutative71.8%
Simplified71.8%
Taylor expanded in a around 0 25.4%
associate--l+25.4%
cancel-sign-sub-inv25.4%
metadata-eval25.4%
associate-/l*25.4%
expm1-def83.9%
*-commutative83.9%
Simplified83.9%
Taylor expanded in b around 0 93.2%
cancel-sign-sub-inv93.2%
associate-+r+93.2%
distribute-rgt1-in93.2%
metadata-eval93.2%
metadata-eval93.2%
associate-+l+93.2%
add-sqr-sqrt36.7%
sqrt-unprod93.5%
swap-sqr93.5%
metadata-eval93.5%
metadata-eval93.5%
swap-sqr93.5%
sqrt-unprod58.6%
add-sqr-sqrt94.2%
*-commutative94.2%
+-commutative94.2%
associate-+r+94.2%
*-commutative94.2%
fma-def94.2%
Applied egg-rr94.2%
+-commutative94.2%
+-commutative94.2%
associate-+l+94.2%
fma-udef94.2%
associate-+r+94.2%
*-commutative94.2%
+-commutative94.2%
*-commutative94.2%
associate-+r+94.2%
distribute-lft-out94.2%
metadata-eval94.2%
metadata-eval94.2%
distribute-rgt-neg-in94.2%
*-rgt-identity94.2%
Simplified94.2%
Taylor expanded in b around inf 69.1%
Final simplification63.4%
(FPCore (a b eps) :precision binary64 (+ (/ 1.0 b) (/ 1.0 a)))
double code(double a, double b, double eps) {
return (1.0 / b) + (1.0 / a);
}
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
public static double code(double a, double b, double eps) {
return (1.0 / b) + (1.0 / a);
}
def code(a, b, eps): return (1.0 / b) + (1.0 / a)
function code(a, b, eps) return Float64(Float64(1.0 / b) + Float64(1.0 / a)) end
function tmp = code(a, b, eps) tmp = (1.0 / b) + (1.0 / a); end
code[a_, b_, eps_] := N[(N[(1.0 / b), $MachinePrecision] + N[(1.0 / a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{b} + \frac{1}{a}
\end{array}
Initial program 7.2%
*-commutative7.2%
associate-*l/7.2%
*-commutative7.2%
expm1-def8.7%
*-commutative8.7%
associate-/r*8.7%
expm1-def14.3%
*-commutative14.3%
expm1-def49.6%
*-commutative49.6%
Simplified49.6%
Taylor expanded in eps around 0 75.9%
Taylor expanded in a around 0 94.0%
Final simplification94.0%
(FPCore (a b eps) :precision binary64 (if (<= b -1.56e+60) (- eps) (/ 1.0 a)))
double code(double a, double b, double eps) {
double tmp;
if (b <= -1.56e+60) {
tmp = -eps;
} else {
tmp = 1.0 / a;
}
return tmp;
}
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.56d+60)) then
tmp = -eps
else
tmp = 1.0d0 / a
end if
code = tmp
end function
public static double code(double a, double b, double eps) {
double tmp;
if (b <= -1.56e+60) {
tmp = -eps;
} else {
tmp = 1.0 / a;
}
return tmp;
}
def code(a, b, eps): tmp = 0 if b <= -1.56e+60: tmp = -eps else: tmp = 1.0 / a return tmp
function code(a, b, eps) tmp = 0.0 if (b <= -1.56e+60) tmp = Float64(-eps); else tmp = Float64(1.0 / a); end return tmp end
function tmp_2 = code(a, b, eps) tmp = 0.0; if (b <= -1.56e+60) tmp = -eps; else tmp = 1.0 / a; end tmp_2 = tmp; end
code[a_, b_, eps_] := If[LessEqual[b, -1.56e+60], (-eps), N[(1.0 / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.56 \cdot 10^{+60}:\\
\;\;\;\;-\varepsilon\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{a}\\
\end{array}
\end{array}
if b < -1.56000000000000009e60Initial program 15.5%
*-commutative15.5%
associate-*l/15.5%
*-commutative15.5%
expm1-def16.7%
*-commutative16.7%
associate-/r*16.7%
expm1-def22.0%
*-commutative22.0%
expm1-def63.8%
*-commutative63.8%
Simplified63.8%
Taylor expanded in a around 0 31.4%
associate--l+31.4%
cancel-sign-sub-inv31.4%
metadata-eval31.4%
associate-/l*31.4%
expm1-def85.3%
*-commutative85.3%
Simplified85.3%
Taylor expanded in b around 0 87.7%
cancel-sign-sub-inv87.7%
associate-+r+87.7%
distribute-rgt1-in87.7%
metadata-eval87.7%
metadata-eval87.7%
associate-+l+87.7%
add-sqr-sqrt45.2%
sqrt-unprod88.0%
swap-sqr88.0%
metadata-eval88.0%
metadata-eval88.0%
swap-sqr88.0%
sqrt-unprod42.5%
add-sqr-sqrt97.9%
*-commutative97.9%
+-commutative97.9%
associate-+r+97.9%
*-commutative97.9%
fma-def97.9%
Applied egg-rr97.9%
+-commutative97.9%
+-commutative97.9%
associate-+l+97.9%
fma-udef97.9%
associate-+r+97.9%
*-commutative97.9%
+-commutative97.9%
*-commutative97.9%
associate-+r+97.9%
distribute-lft-out97.9%
metadata-eval97.9%
metadata-eval97.9%
distribute-rgt-neg-in97.9%
*-rgt-identity97.9%
Simplified97.9%
Taylor expanded in eps around inf 15.5%
mul-1-neg15.5%
Simplified15.5%
if -1.56000000000000009e60 < b Initial program 5.3%
*-commutative5.3%
associate-*l/5.3%
*-commutative5.3%
expm1-def6.9%
*-commutative6.9%
associate-/r*6.9%
expm1-def12.6%
*-commutative12.6%
expm1-def46.4%
*-commutative46.4%
Simplified46.4%
Taylor expanded in a around 0 40.6%
Final simplification36.0%
(FPCore (a b eps) :precision binary64 (if (<= b 5e-152) (/ 1.0 b) (/ 1.0 a)))
double code(double a, double b, double eps) {
double tmp;
if (b <= 5e-152) {
tmp = 1.0 / b;
} else {
tmp = 1.0 / a;
}
return tmp;
}
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 <= 5d-152) then
tmp = 1.0d0 / b
else
tmp = 1.0d0 / a
end if
code = tmp
end function
public static double code(double a, double b, double eps) {
double tmp;
if (b <= 5e-152) {
tmp = 1.0 / b;
} else {
tmp = 1.0 / a;
}
return tmp;
}
def code(a, b, eps): tmp = 0 if b <= 5e-152: tmp = 1.0 / b else: tmp = 1.0 / a return tmp
function code(a, b, eps) tmp = 0.0 if (b <= 5e-152) tmp = Float64(1.0 / b); else tmp = Float64(1.0 / a); end return tmp end
function tmp_2 = code(a, b, eps) tmp = 0.0; if (b <= 5e-152) tmp = 1.0 / b; else tmp = 1.0 / a; end tmp_2 = tmp; end
code[a_, b_, eps_] := If[LessEqual[b, 5e-152], N[(1.0 / b), $MachinePrecision], N[(1.0 / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 5 \cdot 10^{-152}:\\
\;\;\;\;\frac{1}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{a}\\
\end{array}
\end{array}
if b < 4.9999999999999997e-152Initial program 4.9%
*-commutative4.9%
associate-*l/4.9%
*-commutative4.9%
expm1-def6.6%
*-commutative6.6%
associate-/r*6.6%
expm1-def12.2%
*-commutative12.2%
expm1-def37.9%
*-commutative37.9%
Simplified37.9%
Taylor expanded in b around 0 60.4%
if 4.9999999999999997e-152 < b Initial program 11.6%
*-commutative11.6%
associate-*l/11.6%
*-commutative11.6%
expm1-def12.7%
*-commutative12.7%
associate-/r*12.7%
expm1-def18.4%
*-commutative18.4%
expm1-def71.8%
*-commutative71.8%
Simplified71.8%
Taylor expanded in a around 0 65.0%
Final simplification62.0%
(FPCore (a b eps) :precision binary64 (- eps))
double code(double a, double b, double eps) {
return -eps;
}
real(8) function code(a, b, eps)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: eps
code = -eps
end function
public static double code(double a, double b, double eps) {
return -eps;
}
def code(a, b, eps): return -eps
function code(a, b, eps) return Float64(-eps) end
function tmp = code(a, b, eps) tmp = -eps; end
code[a_, b_, eps_] := (-eps)
\begin{array}{l}
\\
-\varepsilon
\end{array}
Initial program 7.2%
*-commutative7.2%
associate-*l/7.2%
*-commutative7.2%
expm1-def8.7%
*-commutative8.7%
associate-/r*8.7%
expm1-def14.3%
*-commutative14.3%
expm1-def49.6%
*-commutative49.6%
Simplified49.6%
Taylor expanded in a around 0 16.8%
associate--l+16.8%
cancel-sign-sub-inv16.8%
metadata-eval16.8%
associate-/l*16.8%
expm1-def65.4%
*-commutative65.4%
Simplified65.4%
Taylor expanded in b around 0 95.4%
cancel-sign-sub-inv95.4%
associate-+r+95.4%
distribute-rgt1-in95.4%
metadata-eval95.4%
metadata-eval95.4%
associate-+l+95.4%
add-sqr-sqrt44.7%
sqrt-unprod95.5%
swap-sqr95.5%
metadata-eval95.5%
metadata-eval95.5%
swap-sqr95.5%
sqrt-unprod51.4%
add-sqr-sqrt97.6%
*-commutative97.6%
+-commutative97.6%
associate-+r+97.6%
*-commutative97.6%
fma-def97.6%
Applied egg-rr97.6%
+-commutative97.6%
+-commutative97.6%
associate-+l+97.6%
fma-udef97.6%
associate-+r+97.6%
*-commutative97.6%
+-commutative97.6%
*-commutative97.6%
associate-+r+97.6%
distribute-lft-out97.6%
metadata-eval97.6%
metadata-eval97.6%
distribute-rgt-neg-in97.6%
*-rgt-identity97.6%
Simplified97.6%
Taylor expanded in eps around inf 6.3%
mul-1-neg6.3%
Simplified6.3%
Final simplification6.3%
(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 2023275
(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))))