
(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 15 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 (fma (log (+ (exp a) (exp b))) -1.0 a)))
double code(double a, double b) {
return exp(fma(log((exp(a) + exp(b))), -1.0, a));
}
function code(a, b) return exp(fma(log(Float64(exp(a) + exp(b))), -1.0, a)) end
code[a_, b_] := N[Exp[N[(N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * -1.0 + a), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{\mathsf{fma}\left(\log \left(e^{a} + e^{b}\right), -1, a\right)}
\end{array}
Initial program 98.8%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
inv-powN/A
pow-to-expN/A
lift-exp.f64N/A
prod-expN/A
lower-exp.f64N/A
lower-fma.f64N/A
lower-log.f6498.8
Applied rewrites98.8%
(FPCore (a b)
:precision binary64
(let* ((t_0 (/ (exp a) (+ (exp a) (exp b)))))
(if (<= t_0 0.002)
(/ 1.0 (fma 0.5 (* b b) b))
(if (<= t_0 0.505506018332186)
(fma b (fma 0.020833333333333332 (* b b) -0.25) 0.5)
1.0))))
double code(double a, double b) {
double t_0 = exp(a) / (exp(a) + exp(b));
double tmp;
if (t_0 <= 0.002) {
tmp = 1.0 / fma(0.5, (b * b), b);
} else if (t_0 <= 0.505506018332186) {
tmp = fma(b, fma(0.020833333333333332, (b * b), -0.25), 0.5);
} else {
tmp = 1.0;
}
return tmp;
}
function code(a, b) t_0 = Float64(exp(a) / Float64(exp(a) + exp(b))) tmp = 0.0 if (t_0 <= 0.002) tmp = Float64(1.0 / fma(0.5, Float64(b * b), b)); elseif (t_0 <= 0.505506018332186) tmp = fma(b, fma(0.020833333333333332, Float64(b * b), -0.25), 0.5); else tmp = 1.0; end return tmp end
code[a_, b_] := Block[{t$95$0 = N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.002], N[(1.0 / N[(0.5 * N[(b * b), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.505506018332186], N[(b * N[(0.020833333333333332 * N[(b * b), $MachinePrecision] + -0.25), $MachinePrecision] + 0.5), $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{e^{a}}{e^{a} + e^{b}}\\
\mathbf{if}\;t\_0 \leq 0.002:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(0.5, b \cdot b, b\right)}\\
\mathbf{elif}\;t\_0 \leq 0.505506018332186:\\
\;\;\;\;\mathsf{fma}\left(b, \mathsf{fma}\left(0.020833333333333332, b \cdot b, -0.25\right), 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) < 2e-3Initial program 100.0%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6464.9
Applied rewrites64.9%
Taylor expanded in b around 0
Applied rewrites34.0%
Taylor expanded in b around inf
Applied rewrites33.7%
if 2e-3 < (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) < 0.505506018332186Initial program 99.9%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6498.1
Applied rewrites98.1%
Taylor expanded in b around 0
Applied rewrites97.0%
if 0.505506018332186 < (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) Initial program 94.8%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
inv-powN/A
pow-to-expN/A
lift-exp.f64N/A
prod-expN/A
lower-exp.f64N/A
lower-fma.f64N/A
lower-log.f6495.0
Applied rewrites95.0%
lift-exp.f64N/A
lift-fma.f64N/A
flip-+N/A
div-invN/A
exp-prodN/A
lower-pow.f64N/A
Applied rewrites100.0%
Taylor expanded in a around inf
Applied rewrites100.0%
(FPCore (a b)
:precision binary64
(let* ((t_0 (/ (exp a) (+ (exp a) (exp b)))))
(if (<= t_0 0.002)
(/ 1.0 (* 0.5 (* b b)))
(if (<= t_0 0.505506018332186)
(fma b (fma 0.020833333333333332 (* b b) -0.25) 0.5)
1.0))))
double code(double a, double b) {
double t_0 = exp(a) / (exp(a) + exp(b));
double tmp;
if (t_0 <= 0.002) {
tmp = 1.0 / (0.5 * (b * b));
} else if (t_0 <= 0.505506018332186) {
tmp = fma(b, fma(0.020833333333333332, (b * b), -0.25), 0.5);
} else {
tmp = 1.0;
}
return tmp;
}
function code(a, b) t_0 = Float64(exp(a) / Float64(exp(a) + exp(b))) tmp = 0.0 if (t_0 <= 0.002) tmp = Float64(1.0 / Float64(0.5 * Float64(b * b))); elseif (t_0 <= 0.505506018332186) tmp = fma(b, fma(0.020833333333333332, Float64(b * b), -0.25), 0.5); else tmp = 1.0; end return tmp end
code[a_, b_] := Block[{t$95$0 = N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.002], N[(1.0 / N[(0.5 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.505506018332186], N[(b * N[(0.020833333333333332 * N[(b * b), $MachinePrecision] + -0.25), $MachinePrecision] + 0.5), $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{e^{a}}{e^{a} + e^{b}}\\
\mathbf{if}\;t\_0 \leq 0.002:\\
\;\;\;\;\frac{1}{0.5 \cdot \left(b \cdot b\right)}\\
\mathbf{elif}\;t\_0 \leq 0.505506018332186:\\
\;\;\;\;\mathsf{fma}\left(b, \mathsf{fma}\left(0.020833333333333332, b \cdot b, -0.25\right), 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) < 2e-3Initial program 100.0%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6464.9
Applied rewrites64.9%
Taylor expanded in b around 0
Applied rewrites34.0%
Taylor expanded in b around inf
Applied rewrites33.5%
if 2e-3 < (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) < 0.505506018332186Initial program 99.9%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6498.1
Applied rewrites98.1%
Taylor expanded in b around 0
Applied rewrites97.0%
if 0.505506018332186 < (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) Initial program 94.8%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
inv-powN/A
pow-to-expN/A
lift-exp.f64N/A
prod-expN/A
lower-exp.f64N/A
lower-fma.f64N/A
lower-log.f6495.0
Applied rewrites95.0%
lift-exp.f64N/A
lift-fma.f64N/A
flip-+N/A
div-invN/A
exp-prodN/A
lower-pow.f64N/A
Applied rewrites100.0%
Taylor expanded in a around inf
Applied rewrites100.0%
(FPCore (a b) :precision binary64 (if (<= (/ (exp a) (+ (exp a) (exp b))) 0.505506018332186) (/ 1.0 (/ (- 64.0 (* (* b b) (* (* b b) (* b b)))) (fma b -16.0 32.0))) 1.0))
double code(double a, double b) {
double tmp;
if ((exp(a) / (exp(a) + exp(b))) <= 0.505506018332186) {
tmp = 1.0 / ((64.0 - ((b * b) * ((b * b) * (b * b)))) / fma(b, -16.0, 32.0));
} else {
tmp = 1.0;
}
return tmp;
}
function code(a, b) tmp = 0.0 if (Float64(exp(a) / Float64(exp(a) + exp(b))) <= 0.505506018332186) tmp = Float64(1.0 / Float64(Float64(64.0 - Float64(Float64(b * b) * Float64(Float64(b * b) * Float64(b * b)))) / fma(b, -16.0, 32.0))); else tmp = 1.0; end return tmp end
code[a_, b_] := If[LessEqual[N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.505506018332186], N[(1.0 / N[(N[(64.0 - N[(N[(b * b), $MachinePrecision] * N[(N[(b * b), $MachinePrecision] * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(b * -16.0 + 32.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{e^{a}}{e^{a} + e^{b}} \leq 0.505506018332186:\\
\;\;\;\;\frac{1}{\frac{64 - \left(b \cdot b\right) \cdot \left(\left(b \cdot b\right) \cdot \left(b \cdot b\right)\right)}{\mathsf{fma}\left(b, -16, 32\right)}}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) < 0.505506018332186Initial program 100.0%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6478.7
Applied rewrites78.7%
Taylor expanded in b around 0
Applied rewrites42.6%
Applied rewrites42.4%
Taylor expanded in b around 0
Applied rewrites71.4%
if 0.505506018332186 < (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) Initial program 94.8%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
inv-powN/A
pow-to-expN/A
lift-exp.f64N/A
prod-expN/A
lower-exp.f64N/A
lower-fma.f64N/A
lower-log.f6495.0
Applied rewrites95.0%
lift-exp.f64N/A
lift-fma.f64N/A
flip-+N/A
div-invN/A
exp-prodN/A
lower-pow.f64N/A
Applied rewrites100.0%
Taylor expanded in a around inf
Applied rewrites100.0%
Final simplification77.9%
(FPCore (a b) :precision binary64 (if (<= (/ (exp a) (+ (exp a) (exp b))) 0.505506018332186) (/ 1.0 (/ (- 64.0 (* (* b b) (* (* b b) (* b b)))) 32.0)) 1.0))
double code(double a, double b) {
double tmp;
if ((exp(a) / (exp(a) + exp(b))) <= 0.505506018332186) {
tmp = 1.0 / ((64.0 - ((b * b) * ((b * b) * (b * b)))) / 32.0);
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if ((exp(a) / (exp(a) + exp(b))) <= 0.505506018332186d0) then
tmp = 1.0d0 / ((64.0d0 - ((b * b) * ((b * b) * (b * b)))) / 32.0d0)
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((Math.exp(a) / (Math.exp(a) + Math.exp(b))) <= 0.505506018332186) {
tmp = 1.0 / ((64.0 - ((b * b) * ((b * b) * (b * b)))) / 32.0);
} else {
tmp = 1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if (math.exp(a) / (math.exp(a) + math.exp(b))) <= 0.505506018332186: tmp = 1.0 / ((64.0 - ((b * b) * ((b * b) * (b * b)))) / 32.0) else: tmp = 1.0 return tmp
function code(a, b) tmp = 0.0 if (Float64(exp(a) / Float64(exp(a) + exp(b))) <= 0.505506018332186) tmp = Float64(1.0 / Float64(Float64(64.0 - Float64(Float64(b * b) * Float64(Float64(b * b) * Float64(b * b)))) / 32.0)); else tmp = 1.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((exp(a) / (exp(a) + exp(b))) <= 0.505506018332186) tmp = 1.0 / ((64.0 - ((b * b) * ((b * b) * (b * b)))) / 32.0); else tmp = 1.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.505506018332186], N[(1.0 / N[(N[(64.0 - N[(N[(b * b), $MachinePrecision] * N[(N[(b * b), $MachinePrecision] * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 32.0), $MachinePrecision]), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{e^{a}}{e^{a} + e^{b}} \leq 0.505506018332186:\\
\;\;\;\;\frac{1}{\frac{64 - \left(b \cdot b\right) \cdot \left(\left(b \cdot b\right) \cdot \left(b \cdot b\right)\right)}{32}}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) < 0.505506018332186Initial program 100.0%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6478.7
Applied rewrites78.7%
Taylor expanded in b around 0
Applied rewrites42.6%
Applied rewrites42.4%
Taylor expanded in b around 0
Applied rewrites71.0%
if 0.505506018332186 < (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) Initial program 94.8%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
inv-powN/A
pow-to-expN/A
lift-exp.f64N/A
prod-expN/A
lower-exp.f64N/A
lower-fma.f64N/A
lower-log.f6495.0
Applied rewrites95.0%
lift-exp.f64N/A
lift-fma.f64N/A
flip-+N/A
div-invN/A
exp-prodN/A
lower-pow.f64N/A
Applied rewrites100.0%
Taylor expanded in a around inf
Applied rewrites100.0%
Final simplification77.5%
(FPCore (a b) :precision binary64 (if (<= (/ (exp a) (+ (exp a) (exp b))) 0.505506018332186) (/ 1.0 (fma b (fma b (fma b 0.16666666666666666 0.5) 1.0) 2.0)) 1.0))
double code(double a, double b) {
double tmp;
if ((exp(a) / (exp(a) + exp(b))) <= 0.505506018332186) {
tmp = 1.0 / fma(b, fma(b, fma(b, 0.16666666666666666, 0.5), 1.0), 2.0);
} else {
tmp = 1.0;
}
return tmp;
}
function code(a, b) tmp = 0.0 if (Float64(exp(a) / Float64(exp(a) + exp(b))) <= 0.505506018332186) tmp = Float64(1.0 / fma(b, fma(b, fma(b, 0.16666666666666666, 0.5), 1.0), 2.0)); else tmp = 1.0; end return tmp end
code[a_, b_] := If[LessEqual[N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.505506018332186], N[(1.0 / N[(b * N[(b * N[(b * 0.16666666666666666 + 0.5), $MachinePrecision] + 1.0), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{e^{a}}{e^{a} + e^{b}} \leq 0.505506018332186:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(b, \mathsf{fma}\left(b, \mathsf{fma}\left(b, 0.16666666666666666, 0.5\right), 1\right), 2\right)}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) < 0.505506018332186Initial program 100.0%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6478.7
Applied rewrites78.7%
Taylor expanded in b around 0
Applied rewrites66.2%
if 0.505506018332186 < (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) Initial program 94.8%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
inv-powN/A
pow-to-expN/A
lift-exp.f64N/A
prod-expN/A
lower-exp.f64N/A
lower-fma.f64N/A
lower-log.f6495.0
Applied rewrites95.0%
lift-exp.f64N/A
lift-fma.f64N/A
flip-+N/A
div-invN/A
exp-prodN/A
lower-pow.f64N/A
Applied rewrites100.0%
Taylor expanded in a around inf
Applied rewrites100.0%
(FPCore (a b) :precision binary64 (if (<= (/ (exp a) (+ (exp a) (exp b))) 0.505506018332186) (/ 1.0 (fma b (fma 0.5 b 1.0) 2.0)) 1.0))
double code(double a, double b) {
double tmp;
if ((exp(a) / (exp(a) + exp(b))) <= 0.505506018332186) {
tmp = 1.0 / fma(b, fma(0.5, b, 1.0), 2.0);
} else {
tmp = 1.0;
}
return tmp;
}
function code(a, b) tmp = 0.0 if (Float64(exp(a) / Float64(exp(a) + exp(b))) <= 0.505506018332186) tmp = Float64(1.0 / fma(b, fma(0.5, b, 1.0), 2.0)); else tmp = 1.0; end return tmp end
code[a_, b_] := If[LessEqual[N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.505506018332186], N[(1.0 / N[(b * N[(0.5 * b + 1.0), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{e^{a}}{e^{a} + e^{b}} \leq 0.505506018332186:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(b, \mathsf{fma}\left(0.5, b, 1\right), 2\right)}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) < 0.505506018332186Initial program 100.0%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6478.7
Applied rewrites78.7%
Taylor expanded in b around 0
Applied rewrites59.9%
if 0.505506018332186 < (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) Initial program 94.8%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
inv-powN/A
pow-to-expN/A
lift-exp.f64N/A
prod-expN/A
lower-exp.f64N/A
lower-fma.f64N/A
lower-log.f6495.0
Applied rewrites95.0%
lift-exp.f64N/A
lift-fma.f64N/A
flip-+N/A
div-invN/A
exp-prodN/A
lower-pow.f64N/A
Applied rewrites100.0%
Taylor expanded in a around inf
Applied rewrites100.0%
(FPCore (a b) :precision binary64 (if (<= (/ (exp a) (+ (exp a) (exp b))) 0.505506018332186) (/ 1.0 (fma b (* b 0.5) 2.0)) 1.0))
double code(double a, double b) {
double tmp;
if ((exp(a) / (exp(a) + exp(b))) <= 0.505506018332186) {
tmp = 1.0 / fma(b, (b * 0.5), 2.0);
} else {
tmp = 1.0;
}
return tmp;
}
function code(a, b) tmp = 0.0 if (Float64(exp(a) / Float64(exp(a) + exp(b))) <= 0.505506018332186) tmp = Float64(1.0 / fma(b, Float64(b * 0.5), 2.0)); else tmp = 1.0; end return tmp end
code[a_, b_] := If[LessEqual[N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.505506018332186], N[(1.0 / N[(b * N[(b * 0.5), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{e^{a}}{e^{a} + e^{b}} \leq 0.505506018332186:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(b, b \cdot 0.5, 2\right)}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) < 0.505506018332186Initial program 100.0%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6478.7
Applied rewrites78.7%
Taylor expanded in b around 0
Applied rewrites59.9%
Taylor expanded in b around inf
Applied rewrites59.5%
if 0.505506018332186 < (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) Initial program 94.8%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
inv-powN/A
pow-to-expN/A
lift-exp.f64N/A
prod-expN/A
lower-exp.f64N/A
lower-fma.f64N/A
lower-log.f6495.0
Applied rewrites95.0%
lift-exp.f64N/A
lift-fma.f64N/A
flip-+N/A
div-invN/A
exp-prodN/A
lower-pow.f64N/A
Applied rewrites100.0%
Taylor expanded in a around inf
Applied rewrites100.0%
Final simplification68.7%
(FPCore (a b) :precision binary64 (if (<= (/ (exp a) (+ (exp a) (exp b))) 0.505506018332186) (/ 1.0 (+ b 2.0)) 1.0))
double code(double a, double b) {
double tmp;
if ((exp(a) / (exp(a) + exp(b))) <= 0.505506018332186) {
tmp = 1.0 / (b + 2.0);
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if ((exp(a) / (exp(a) + exp(b))) <= 0.505506018332186d0) then
tmp = 1.0d0 / (b + 2.0d0)
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((Math.exp(a) / (Math.exp(a) + Math.exp(b))) <= 0.505506018332186) {
tmp = 1.0 / (b + 2.0);
} else {
tmp = 1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if (math.exp(a) / (math.exp(a) + math.exp(b))) <= 0.505506018332186: tmp = 1.0 / (b + 2.0) else: tmp = 1.0 return tmp
function code(a, b) tmp = 0.0 if (Float64(exp(a) / Float64(exp(a) + exp(b))) <= 0.505506018332186) tmp = Float64(1.0 / Float64(b + 2.0)); else tmp = 1.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((exp(a) / (exp(a) + exp(b))) <= 0.505506018332186) tmp = 1.0 / (b + 2.0); else tmp = 1.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.505506018332186], N[(1.0 / N[(b + 2.0), $MachinePrecision]), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{e^{a}}{e^{a} + e^{b}} \leq 0.505506018332186:\\
\;\;\;\;\frac{1}{b + 2}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) < 0.505506018332186Initial program 100.0%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6478.7
Applied rewrites78.7%
Taylor expanded in b around 0
Applied rewrites42.6%
if 0.505506018332186 < (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) Initial program 94.8%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
inv-powN/A
pow-to-expN/A
lift-exp.f64N/A
prod-expN/A
lower-exp.f64N/A
lower-fma.f64N/A
lower-log.f6495.0
Applied rewrites95.0%
lift-exp.f64N/A
lift-fma.f64N/A
flip-+N/A
div-invN/A
exp-prodN/A
lower-pow.f64N/A
Applied rewrites100.0%
Taylor expanded in a around inf
Applied rewrites100.0%
Final simplification55.6%
(FPCore (a b) :precision binary64 (if (<= (/ (exp a) (+ (exp a) (exp b))) 0.505506018332186) (fma b -0.25 0.5) 1.0))
double code(double a, double b) {
double tmp;
if ((exp(a) / (exp(a) + exp(b))) <= 0.505506018332186) {
tmp = fma(b, -0.25, 0.5);
} else {
tmp = 1.0;
}
return tmp;
}
function code(a, b) tmp = 0.0 if (Float64(exp(a) / Float64(exp(a) + exp(b))) <= 0.505506018332186) tmp = fma(b, -0.25, 0.5); else tmp = 1.0; end return tmp end
code[a_, b_] := If[LessEqual[N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.505506018332186], N[(b * -0.25 + 0.5), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{e^{a}}{e^{a} + e^{b}} \leq 0.505506018332186:\\
\;\;\;\;\mathsf{fma}\left(b, -0.25, 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) < 0.505506018332186Initial program 100.0%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6478.7
Applied rewrites78.7%
Taylor expanded in b around 0
Applied rewrites41.5%
if 0.505506018332186 < (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) Initial program 94.8%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
inv-powN/A
pow-to-expN/A
lift-exp.f64N/A
prod-expN/A
lower-exp.f64N/A
lower-fma.f64N/A
lower-log.f6495.0
Applied rewrites95.0%
lift-exp.f64N/A
lift-fma.f64N/A
flip-+N/A
div-invN/A
exp-prodN/A
lower-pow.f64N/A
Applied rewrites100.0%
Taylor expanded in a around inf
Applied rewrites100.0%
(FPCore (a b) :precision binary64 (if (<= (/ (exp a) (+ (exp a) (exp b))) 0.505506018332186) 0.5 1.0))
double code(double a, double b) {
double tmp;
if ((exp(a) / (exp(a) + exp(b))) <= 0.505506018332186) {
tmp = 0.5;
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if ((exp(a) / (exp(a) + exp(b))) <= 0.505506018332186d0) then
tmp = 0.5d0
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((Math.exp(a) / (Math.exp(a) + Math.exp(b))) <= 0.505506018332186) {
tmp = 0.5;
} else {
tmp = 1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if (math.exp(a) / (math.exp(a) + math.exp(b))) <= 0.505506018332186: tmp = 0.5 else: tmp = 1.0 return tmp
function code(a, b) tmp = 0.0 if (Float64(exp(a) / Float64(exp(a) + exp(b))) <= 0.505506018332186) tmp = 0.5; else tmp = 1.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((exp(a) / (exp(a) + exp(b))) <= 0.505506018332186) tmp = 0.5; else tmp = 1.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.505506018332186], 0.5, 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{e^{a}}{e^{a} + e^{b}} \leq 0.505506018332186:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) < 0.505506018332186Initial program 100.0%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6478.7
Applied rewrites78.7%
Taylor expanded in b around 0
Applied rewrites41.5%
if 0.505506018332186 < (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) Initial program 94.8%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
inv-powN/A
pow-to-expN/A
lift-exp.f64N/A
prod-expN/A
lower-exp.f64N/A
lower-fma.f64N/A
lower-log.f6495.0
Applied rewrites95.0%
lift-exp.f64N/A
lift-fma.f64N/A
flip-+N/A
div-invN/A
exp-prodN/A
lower-pow.f64N/A
Applied rewrites100.0%
Taylor expanded in a around inf
Applied rewrites100.0%
(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}
Initial program 98.8%
(FPCore (a b) :precision binary64 (if (<= a -480000000.0) (/ (exp a) (+ 1.0 1.0)) (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
double tmp;
if (a <= -480000000.0) {
tmp = exp(a) / (1.0 + 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 <= (-480000000.0d0)) then
tmp = exp(a) / (1.0d0 + 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 <= -480000000.0) {
tmp = Math.exp(a) / (1.0 + 1.0);
} else {
tmp = 1.0 / (Math.exp(b) + 1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -480000000.0: tmp = math.exp(a) / (1.0 + 1.0) else: tmp = 1.0 / (math.exp(b) + 1.0) return tmp
function code(a, b) tmp = 0.0 if (a <= -480000000.0) tmp = Float64(exp(a) / Float64(1.0 + 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 <= -480000000.0) tmp = exp(a) / (1.0 + 1.0); else tmp = 1.0 / (exp(b) + 1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -480000000.0], N[(N[Exp[a], $MachinePrecision] / N[(1.0 + 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 -480000000:\\
\;\;\;\;\frac{e^{a}}{1 + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\
\end{array}
\end{array}
if a < -4.8e8Initial program 100.0%
Taylor expanded in b around 0
Applied rewrites100.0%
Taylor expanded in a around 0
Applied rewrites100.0%
if -4.8e8 < a Initial program 98.5%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6498.0
Applied rewrites98.0%
Final simplification98.4%
(FPCore (a b) :precision binary64 (if (<= a -3500000000.0) (* -0.0020833333333333333 (pow b 5.0)) (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
double tmp;
if (a <= -3500000000.0) {
tmp = -0.0020833333333333333 * pow(b, 5.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 <= (-3500000000.0d0)) then
tmp = (-0.0020833333333333333d0) * (b ** 5.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 <= -3500000000.0) {
tmp = -0.0020833333333333333 * Math.pow(b, 5.0);
} else {
tmp = 1.0 / (Math.exp(b) + 1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -3500000000.0: tmp = -0.0020833333333333333 * math.pow(b, 5.0) else: tmp = 1.0 / (math.exp(b) + 1.0) return tmp
function code(a, b) tmp = 0.0 if (a <= -3500000000.0) tmp = Float64(-0.0020833333333333333 * (b ^ 5.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 <= -3500000000.0) tmp = -0.0020833333333333333 * (b ^ 5.0); else tmp = 1.0 / (exp(b) + 1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -3500000000.0], N[(-0.0020833333333333333 * N[Power[b, 5.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 -3500000000:\\
\;\;\;\;-0.0020833333333333333 \cdot {b}^{5}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\
\end{array}
\end{array}
if a < -3.5e9Initial program 100.0%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6426.0
Applied rewrites26.0%
Taylor expanded in b around 0
Applied rewrites2.8%
Taylor expanded in b around inf
Applied rewrites61.2%
if -3.5e9 < a Initial program 98.5%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6498.0
Applied rewrites98.0%
Final simplification90.1%
(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.8%
Taylor expanded in a around 0
lower-/.f64N/A
lower-+.f64N/A
lower-exp.f6482.6
Applied rewrites82.6%
Taylor expanded in b around 0
Applied rewrites36.4%
(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 2024223
(FPCore (a b)
:name "Quotient of sum of exps"
:precision binary64
:alt
(! :herbie-platform default (/ 1 (+ 1 (exp (- b a)))))
(/ (exp a) (+ (exp a) (exp b))))