
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
double code(double a, double b) {
return exp(a) / (exp(a) + exp(b));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = exp(a) / (exp(a) + exp(b))
end function
public static double code(double a, double b) {
return Math.exp(a) / (Math.exp(a) + Math.exp(b));
}
def code(a, b): return math.exp(a) / (math.exp(a) + math.exp(b))
function code(a, b) return Float64(exp(a) / Float64(exp(a) + exp(b))) end
function tmp = code(a, b) tmp = exp(a) / (exp(a) + exp(b)); end
code[a_, b_] := N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{a}}{e^{a} + e^{b}}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
double code(double a, double b) {
return exp(a) / (exp(a) + exp(b));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = exp(a) / (exp(a) + exp(b))
end function
public static double code(double a, double b) {
return Math.exp(a) / (Math.exp(a) + Math.exp(b));
}
def code(a, b): return math.exp(a) / (math.exp(a) + math.exp(b))
function code(a, b) return Float64(exp(a) / Float64(exp(a) + exp(b))) end
function tmp = code(a, b) tmp = exp(a) / (exp(a) + exp(b)); end
code[a_, b_] := N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{a}}{e^{a} + e^{b}}
\end{array}
(FPCore (a b) :precision binary64 (exp (- (log1p (exp (- b a))))))
double code(double a, double b) {
return exp(-log1p(exp((b - a))));
}
public static double code(double a, double b) {
return Math.exp(-Math.log1p(Math.exp((b - a))));
}
def code(a, b): return math.exp(-math.log1p(math.exp((b - a))))
function code(a, b) return exp(Float64(-log1p(exp(Float64(b - a))))) end
code[a_, b_] := N[Exp[(-N[Log[1 + N[Exp[N[(b - a), $MachinePrecision]], $MachinePrecision]], $MachinePrecision])], $MachinePrecision]
\begin{array}{l}
\\
e^{-\mathsf{log1p}\left(e^{b - a}\right)}
\end{array}
Initial program 98.4%
*-lft-identity98.4%
associate-*l/98.4%
associate-/r/98.4%
remove-double-neg98.4%
unsub-neg98.4%
div-sub67.5%
*-lft-identity67.5%
associate-*l/67.5%
lft-mult-inverse99.2%
sub-neg99.2%
distribute-frac-neg99.2%
remove-double-neg99.2%
div-exp100.0%
Simplified100.0%
div-exp99.2%
+-commutative99.2%
metadata-eval99.2%
sub-neg99.2%
add-exp-log99.2%
rec-exp99.2%
sub-neg99.2%
metadata-eval99.2%
+-commutative99.2%
log1p-define99.2%
div-exp100.0%
Applied egg-rr100.0%
(FPCore (a b) :precision binary64 (if (<= a -1.75e-13) (/ 1.0 (- (exp (- a)) -1.0)) (/ 1.0 (- (exp b) -1.0))))
double code(double a, double b) {
double tmp;
if (a <= -1.75e-13) {
tmp = 1.0 / (exp(-a) - -1.0);
} else {
tmp = 1.0 / (exp(b) - -1.0);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-1.75d-13)) then
tmp = 1.0d0 / (exp(-a) - (-1.0d0))
else
tmp = 1.0d0 / (exp(b) - (-1.0d0))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -1.75e-13) {
tmp = 1.0 / (Math.exp(-a) - -1.0);
} else {
tmp = 1.0 / (Math.exp(b) - -1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -1.75e-13: tmp = 1.0 / (math.exp(-a) - -1.0) else: tmp = 1.0 / (math.exp(b) - -1.0) return tmp
function code(a, b) tmp = 0.0 if (a <= -1.75e-13) tmp = Float64(1.0 / Float64(exp(Float64(-a)) - -1.0)); else tmp = Float64(1.0 / Float64(exp(b) - -1.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -1.75e-13) tmp = 1.0 / (exp(-a) - -1.0); else tmp = 1.0 / (exp(b) - -1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -1.75e-13], N[(1.0 / N[(N[Exp[(-a)], $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[Exp[b], $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.75 \cdot 10^{-13}:\\
\;\;\;\;\frac{1}{e^{-a} - -1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} - -1}\\
\end{array}
\end{array}
if a < -1.7500000000000001e-13Initial program 98.8%
*-lft-identity98.8%
associate-*l/98.8%
associate-/r/98.8%
+-commutative98.8%
remove-double-neg98.8%
sub-neg98.8%
div-sub6.9%
neg-mul-16.9%
*-commutative6.9%
associate-*r/6.9%
metadata-eval6.9%
distribute-neg-frac6.9%
exp-neg6.9%
distribute-rgt-neg-out6.9%
exp-neg6.9%
rgt-mult-inverse98.8%
metadata-eval98.8%
Simplified98.8%
Taylor expanded in b around 0 98.7%
rec-exp98.6%
Simplified98.6%
if -1.7500000000000001e-13 < a Initial program 98.2%
*-lft-identity98.2%
associate-*l/98.2%
associate-/r/98.2%
+-commutative98.2%
remove-double-neg98.2%
sub-neg98.2%
div-sub98.2%
neg-mul-198.2%
*-commutative98.2%
associate-*r/98.2%
metadata-eval98.2%
distribute-neg-frac98.2%
exp-neg98.2%
distribute-rgt-neg-out98.2%
exp-neg98.2%
rgt-mult-inverse99.4%
metadata-eval99.4%
Simplified99.4%
Taylor expanded in a around 0 98.7%
(FPCore (a b) :precision binary64 (if (<= a -3800.0) (/ (exp a) a) (/ 1.0 (- (exp b) -1.0))))
double code(double a, double b) {
double tmp;
if (a <= -3800.0) {
tmp = exp(a) / a;
} else {
tmp = 1.0 / (exp(b) - -1.0);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-3800.0d0)) then
tmp = exp(a) / a
else
tmp = 1.0d0 / (exp(b) - (-1.0d0))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -3800.0) {
tmp = Math.exp(a) / a;
} else {
tmp = 1.0 / (Math.exp(b) - -1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -3800.0: tmp = math.exp(a) / a else: tmp = 1.0 / (math.exp(b) - -1.0) return tmp
function code(a, b) tmp = 0.0 if (a <= -3800.0) tmp = Float64(exp(a) / a); else tmp = Float64(1.0 / Float64(exp(b) - -1.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -3800.0) tmp = exp(a) / a; else tmp = 1.0 / (exp(b) - -1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -3800.0], N[(N[Exp[a], $MachinePrecision] / a), $MachinePrecision], N[(1.0 / N[(N[Exp[b], $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -3800:\\
\;\;\;\;\frac{e^{a}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} - -1}\\
\end{array}
\end{array}
if a < -3800Initial program 98.7%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in a around inf 100.0%
if -3800 < a Initial program 98.3%
*-lft-identity98.3%
associate-*l/98.3%
associate-/r/98.3%
+-commutative98.3%
remove-double-neg98.3%
sub-neg98.3%
div-sub97.7%
neg-mul-197.7%
*-commutative97.7%
associate-*r/97.7%
metadata-eval97.7%
distribute-neg-frac97.7%
exp-neg97.7%
distribute-rgt-neg-out97.7%
exp-neg97.7%
rgt-mult-inverse99.4%
metadata-eval99.4%
Simplified99.4%
Taylor expanded in a around 0 97.2%
(FPCore (a b) :precision binary64 (if (<= a -720.0) (/ (exp a) a) (/ 1.0 (+ 2.0 (* b (+ 1.0 (* b (+ 0.5 (* b 0.16666666666666666)))))))))
double code(double a, double b) {
double tmp;
if (a <= -720.0) {
tmp = exp(a) / a;
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-720.0d0)) then
tmp = exp(a) / a
else
tmp = 1.0d0 / (2.0d0 + (b * (1.0d0 + (b * (0.5d0 + (b * 0.16666666666666666d0))))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -720.0) {
tmp = Math.exp(a) / a;
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -720.0: tmp = math.exp(a) / a else: tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))) return tmp
function code(a, b) tmp = 0.0 if (a <= -720.0) tmp = Float64(exp(a) / a); else tmp = Float64(1.0 / Float64(2.0 + Float64(b * Float64(1.0 + Float64(b * Float64(0.5 + Float64(b * 0.16666666666666666))))))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -720.0) tmp = exp(a) / a; else tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -720.0], N[(N[Exp[a], $MachinePrecision] / a), $MachinePrecision], N[(1.0 / N[(2.0 + N[(b * N[(1.0 + N[(b * N[(0.5 + N[(b * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -720:\\
\;\;\;\;\frac{e^{a}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + b \cdot \left(0.5 + b \cdot 0.16666666666666666\right)\right)}\\
\end{array}
\end{array}
if a < -720Initial program 98.8%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in a around inf 100.0%
if -720 < a Initial program 98.3%
*-lft-identity98.3%
associate-*l/98.3%
associate-/r/98.3%
+-commutative98.3%
remove-double-neg98.3%
sub-neg98.3%
div-sub98.2%
neg-mul-198.2%
*-commutative98.2%
associate-*r/98.2%
metadata-eval98.2%
distribute-neg-frac98.2%
exp-neg98.2%
distribute-rgt-neg-out98.2%
exp-neg98.2%
rgt-mult-inverse99.4%
metadata-eval99.4%
Simplified99.4%
Taylor expanded in a around 0 97.2%
Taylor expanded in b around 0 68.4%
*-commutative68.4%
Simplified68.4%
(FPCore (a b) :precision binary64 (/ 1.0 (+ (exp (- b a)) 1.0)))
double code(double a, double b) {
return 1.0 / (exp((b - a)) + 1.0);
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (exp((b - a)) + 1.0d0)
end function
public static double code(double a, double b) {
return 1.0 / (Math.exp((b - a)) + 1.0);
}
def code(a, b): return 1.0 / (math.exp((b - a)) + 1.0)
function code(a, b) return Float64(1.0 / Float64(exp(Float64(b - a)) + 1.0)) end
function tmp = code(a, b) tmp = 1.0 / (exp((b - a)) + 1.0); end
code[a_, b_] := N[(1.0 / N[(N[Exp[N[(b - a), $MachinePrecision]], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{e^{b - a} + 1}
\end{array}
Initial program 98.4%
*-lft-identity98.4%
associate-*l/98.4%
associate-/r/98.4%
remove-double-neg98.4%
unsub-neg98.4%
div-sub67.5%
*-lft-identity67.5%
associate-*l/67.5%
lft-mult-inverse99.2%
sub-neg99.2%
distribute-frac-neg99.2%
remove-double-neg99.2%
div-exp100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (if (<= b 1.36e+70) (/ 1.0 (+ 2.0 (* a (+ -1.0 (* a (+ 0.5 (* a -0.16666666666666666))))))) (/ 1.0 (+ 2.0 (* b (+ 1.0 (* b (+ 0.5 (* b 0.16666666666666666)))))))))
double code(double a, double b) {
double tmp;
if (b <= 1.36e+70) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666))))));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 1.36d+70) then
tmp = 1.0d0 / (2.0d0 + (a * ((-1.0d0) + (a * (0.5d0 + (a * (-0.16666666666666666d0)))))))
else
tmp = 1.0d0 / (2.0d0 + (b * (1.0d0 + (b * (0.5d0 + (b * 0.16666666666666666d0))))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 1.36e+70) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666))))));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.36e+70: tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666)))))) else: tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.36e+70) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(-1.0 + Float64(a * Float64(0.5 + Float64(a * -0.16666666666666666))))))); else tmp = Float64(1.0 / Float64(2.0 + Float64(b * Float64(1.0 + Float64(b * Float64(0.5 + Float64(b * 0.16666666666666666))))))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 1.36e+70) tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666)))))); else tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.36e+70], N[(1.0 / N[(2.0 + N[(a * N[(-1.0 + N[(a * N[(0.5 + N[(a * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 + N[(b * N[(1.0 + N[(b * N[(0.5 + N[(b * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.36 \cdot 10^{+70}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(-1 + a \cdot \left(0.5 + a \cdot -0.16666666666666666\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + b \cdot \left(0.5 + b \cdot 0.16666666666666666\right)\right)}\\
\end{array}
\end{array}
if b < 1.35999999999999995e70Initial program 98.5%
*-lft-identity98.5%
associate-*l/98.4%
associate-/r/98.4%
+-commutative98.4%
remove-double-neg98.4%
sub-neg98.4%
div-sub69.0%
neg-mul-169.0%
*-commutative69.0%
associate-*r/69.0%
metadata-eval69.0%
distribute-neg-frac69.0%
exp-neg69.0%
distribute-rgt-neg-out69.0%
exp-neg69.0%
rgt-mult-inverse99.4%
metadata-eval99.4%
Simplified99.4%
Taylor expanded in b around 0 78.4%
rec-exp78.4%
Simplified78.4%
Taylor expanded in a around 0 66.9%
if 1.35999999999999995e70 < b Initial program 98.3%
*-lft-identity98.3%
associate-*l/98.3%
associate-/r/98.3%
+-commutative98.3%
remove-double-neg98.3%
sub-neg98.3%
div-sub62.7%
neg-mul-162.7%
*-commutative62.7%
associate-*r/62.7%
metadata-eval62.7%
distribute-neg-frac62.7%
exp-neg62.7%
distribute-rgt-neg-out62.7%
exp-neg62.7%
rgt-mult-inverse98.3%
metadata-eval98.3%
Simplified98.3%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 92.3%
*-commutative92.3%
Simplified92.3%
Final simplification72.8%
(FPCore (a b) :precision binary64 (if (<= b 7e+147) (/ 1.0 (+ 2.0 (* a (+ -1.0 (* a (+ 0.5 (* a -0.16666666666666666))))))) (/ 1.0 (+ 2.0 (* b (+ 1.0 (* b 0.5)))))))
double code(double a, double b) {
double tmp;
if (b <= 7e+147) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666))))));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5))));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 7d+147) then
tmp = 1.0d0 / (2.0d0 + (a * ((-1.0d0) + (a * (0.5d0 + (a * (-0.16666666666666666d0)))))))
else
tmp = 1.0d0 / (2.0d0 + (b * (1.0d0 + (b * 0.5d0))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 7e+147) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666))))));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 7e+147: tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666)))))) else: tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))) return tmp
function code(a, b) tmp = 0.0 if (b <= 7e+147) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(-1.0 + Float64(a * Float64(0.5 + Float64(a * -0.16666666666666666))))))); else tmp = Float64(1.0 / Float64(2.0 + Float64(b * Float64(1.0 + Float64(b * 0.5))))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 7e+147) tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666)))))); else tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 7e+147], N[(1.0 / N[(2.0 + N[(a * N[(-1.0 + N[(a * N[(0.5 + N[(a * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 + N[(b * N[(1.0 + N[(b * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7 \cdot 10^{+147}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(-1 + a \cdot \left(0.5 + a \cdot -0.16666666666666666\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + b \cdot 0.5\right)}\\
\end{array}
\end{array}
if b < 6.99999999999999949e147Initial program 98.5%
*-lft-identity98.5%
associate-*l/98.5%
associate-/r/98.5%
+-commutative98.5%
remove-double-neg98.5%
sub-neg98.5%
div-sub67.9%
neg-mul-167.9%
*-commutative67.9%
associate-*r/67.9%
metadata-eval67.9%
distribute-neg-frac67.9%
exp-neg67.9%
distribute-rgt-neg-out67.9%
exp-neg67.9%
rgt-mult-inverse99.5%
metadata-eval99.5%
Simplified99.5%
Taylor expanded in b around 0 76.9%
rec-exp76.9%
Simplified76.9%
Taylor expanded in a around 0 64.2%
if 6.99999999999999949e147 < b Initial program 97.9%
*-lft-identity97.9%
associate-*l/97.9%
associate-/r/97.9%
+-commutative97.9%
remove-double-neg97.9%
sub-neg97.9%
div-sub66.0%
neg-mul-166.0%
*-commutative66.0%
associate-*r/66.0%
metadata-eval66.0%
distribute-neg-frac66.0%
exp-neg66.0%
distribute-rgt-neg-out66.0%
exp-neg66.0%
rgt-mult-inverse97.9%
metadata-eval97.9%
Simplified97.9%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 98.1%
*-commutative98.1%
Simplified98.1%
Final simplification70.4%
(FPCore (a b) :precision binary64 (if (<= b 7e+147) (/ 1.0 (+ 2.0 (* a (+ -1.0 (* a 0.5))))) (/ 1.0 (+ 2.0 (* b (+ 1.0 (* b 0.5)))))))
double code(double a, double b) {
double tmp;
if (b <= 7e+147) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * 0.5))));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5))));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 7d+147) then
tmp = 1.0d0 / (2.0d0 + (a * ((-1.0d0) + (a * 0.5d0))))
else
tmp = 1.0d0 / (2.0d0 + (b * (1.0d0 + (b * 0.5d0))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 7e+147) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * 0.5))));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 7e+147: tmp = 1.0 / (2.0 + (a * (-1.0 + (a * 0.5)))) else: tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))) return tmp
function code(a, b) tmp = 0.0 if (b <= 7e+147) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(-1.0 + Float64(a * 0.5))))); else tmp = Float64(1.0 / Float64(2.0 + Float64(b * Float64(1.0 + Float64(b * 0.5))))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 7e+147) tmp = 1.0 / (2.0 + (a * (-1.0 + (a * 0.5)))); else tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 7e+147], N[(1.0 / N[(2.0 + N[(a * N[(-1.0 + N[(a * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 + N[(b * N[(1.0 + N[(b * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7 \cdot 10^{+147}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(-1 + a \cdot 0.5\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + b \cdot 0.5\right)}\\
\end{array}
\end{array}
if b < 6.99999999999999949e147Initial program 98.5%
*-lft-identity98.5%
associate-*l/98.5%
associate-/r/98.5%
+-commutative98.5%
remove-double-neg98.5%
sub-neg98.5%
div-sub67.9%
neg-mul-167.9%
*-commutative67.9%
associate-*r/67.9%
metadata-eval67.9%
distribute-neg-frac67.9%
exp-neg67.9%
distribute-rgt-neg-out67.9%
exp-neg67.9%
rgt-mult-inverse99.5%
metadata-eval99.5%
Simplified99.5%
Taylor expanded in b around 0 76.9%
rec-exp76.9%
Simplified76.9%
Taylor expanded in a around 0 59.9%
if 6.99999999999999949e147 < b Initial program 97.9%
*-lft-identity97.9%
associate-*l/97.9%
associate-/r/97.9%
+-commutative97.9%
remove-double-neg97.9%
sub-neg97.9%
div-sub66.0%
neg-mul-166.0%
*-commutative66.0%
associate-*r/66.0%
metadata-eval66.0%
distribute-neg-frac66.0%
exp-neg66.0%
distribute-rgt-neg-out66.0%
exp-neg66.0%
rgt-mult-inverse97.9%
metadata-eval97.9%
Simplified97.9%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 98.1%
*-commutative98.1%
Simplified98.1%
Final simplification67.0%
(FPCore (a b) :precision binary64 (/ 1.0 (+ 2.0 (* a (+ -1.0 (* a 0.5))))))
double code(double a, double b) {
return 1.0 / (2.0 + (a * (-1.0 + (a * 0.5))));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (2.0d0 + (a * ((-1.0d0) + (a * 0.5d0))))
end function
public static double code(double a, double b) {
return 1.0 / (2.0 + (a * (-1.0 + (a * 0.5))));
}
def code(a, b): return 1.0 / (2.0 + (a * (-1.0 + (a * 0.5))))
function code(a, b) return Float64(1.0 / Float64(2.0 + Float64(a * Float64(-1.0 + Float64(a * 0.5))))) end
function tmp = code(a, b) tmp = 1.0 / (2.0 + (a * (-1.0 + (a * 0.5)))); end
code[a_, b_] := N[(1.0 / N[(2.0 + N[(a * N[(-1.0 + N[(a * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{2 + a \cdot \left(-1 + a \cdot 0.5\right)}
\end{array}
Initial program 98.4%
*-lft-identity98.4%
associate-*l/98.4%
associate-/r/98.4%
+-commutative98.4%
remove-double-neg98.4%
sub-neg98.4%
div-sub67.5%
neg-mul-167.5%
*-commutative67.5%
associate-*r/67.5%
metadata-eval67.5%
distribute-neg-frac67.5%
exp-neg67.5%
distribute-rgt-neg-out67.5%
exp-neg67.5%
rgt-mult-inverse99.2%
metadata-eval99.2%
Simplified99.2%
Taylor expanded in b around 0 69.0%
rec-exp69.0%
Simplified69.0%
Taylor expanded in a around 0 52.6%
Final simplification52.6%
(FPCore (a b) :precision binary64 (/ 1.0 (- 2.0 a)))
double code(double a, double b) {
return 1.0 / (2.0 - a);
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (2.0d0 - a)
end function
public static double code(double a, double b) {
return 1.0 / (2.0 - a);
}
def code(a, b): return 1.0 / (2.0 - a)
function code(a, b) return Float64(1.0 / Float64(2.0 - a)) end
function tmp = code(a, b) tmp = 1.0 / (2.0 - a); end
code[a_, b_] := N[(1.0 / N[(2.0 - a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{2 - a}
\end{array}
Initial program 98.4%
*-lft-identity98.4%
associate-*l/98.4%
associate-/r/98.4%
+-commutative98.4%
remove-double-neg98.4%
sub-neg98.4%
div-sub67.5%
neg-mul-167.5%
*-commutative67.5%
associate-*r/67.5%
metadata-eval67.5%
distribute-neg-frac67.5%
exp-neg67.5%
distribute-rgt-neg-out67.5%
exp-neg67.5%
rgt-mult-inverse99.2%
metadata-eval99.2%
Simplified99.2%
Taylor expanded in b around 0 69.0%
rec-exp69.0%
Simplified69.0%
Taylor expanded in a around 0 37.8%
neg-mul-137.8%
unsub-neg37.8%
Simplified37.8%
(FPCore (a b) :precision binary64 (+ 0.5 (* a 0.25)))
double code(double a, double b) {
return 0.5 + (a * 0.25);
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 0.5d0 + (a * 0.25d0)
end function
public static double code(double a, double b) {
return 0.5 + (a * 0.25);
}
def code(a, b): return 0.5 + (a * 0.25)
function code(a, b) return Float64(0.5 + Float64(a * 0.25)) end
function tmp = code(a, b) tmp = 0.5 + (a * 0.25); end
code[a_, b_] := N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 + a \cdot 0.25
\end{array}
Initial program 98.4%
*-lft-identity98.4%
associate-*l/98.4%
associate-/r/98.4%
+-commutative98.4%
remove-double-neg98.4%
sub-neg98.4%
div-sub67.5%
neg-mul-167.5%
*-commutative67.5%
associate-*r/67.5%
metadata-eval67.5%
distribute-neg-frac67.5%
exp-neg67.5%
distribute-rgt-neg-out67.5%
exp-neg67.5%
rgt-mult-inverse99.2%
metadata-eval99.2%
Simplified99.2%
Taylor expanded in b around 0 69.0%
rec-exp69.0%
Simplified69.0%
Taylor expanded in a around 0 37.3%
*-commutative37.3%
Simplified37.3%
(FPCore (a b) :precision binary64 0.5)
double code(double a, double b) {
return 0.5;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 0.5d0
end function
public static double code(double a, double b) {
return 0.5;
}
def code(a, b): return 0.5
function code(a, b) return 0.5 end
function tmp = code(a, b) tmp = 0.5; end
code[a_, b_] := 0.5
\begin{array}{l}
\\
0.5
\end{array}
Initial program 98.4%
*-lft-identity98.4%
associate-*l/98.4%
associate-/r/98.4%
+-commutative98.4%
remove-double-neg98.4%
sub-neg98.4%
div-sub67.5%
neg-mul-167.5%
*-commutative67.5%
associate-*r/67.5%
metadata-eval67.5%
distribute-neg-frac67.5%
exp-neg67.5%
distribute-rgt-neg-out67.5%
exp-neg67.5%
rgt-mult-inverse99.2%
metadata-eval99.2%
Simplified99.2%
Taylor expanded in a around 0 79.1%
Taylor expanded in b around 0 36.9%
(FPCore (a b) :precision binary64 (/ 1.0 (+ 1.0 (exp (- b a)))))
double code(double a, double b) {
return 1.0 / (1.0 + exp((b - a)));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (1.0d0 + exp((b - a)))
end function
public static double code(double a, double b) {
return 1.0 / (1.0 + Math.exp((b - a)));
}
def code(a, b): return 1.0 / (1.0 + math.exp((b - a)))
function code(a, b) return Float64(1.0 / Float64(1.0 + exp(Float64(b - a)))) end
function tmp = code(a, b) tmp = 1.0 / (1.0 + exp((b - a))); end
code[a_, b_] := N[(1.0 / N[(1.0 + N[Exp[N[(b - a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{1 + e^{b - a}}
\end{array}
herbie shell --seed 2024103
(FPCore (a b)
:name "Quotient of sum of exps"
:precision binary64
:alt
(/ 1.0 (+ 1.0 (exp (- b a))))
(/ (exp a) (+ (exp a) (exp b))))