
(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 10 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 (/ 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 99.2%
lift-/.f64N/A
clear-numN/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
div-addN/A
*-inversesN/A
lower-+.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
div-expN/A
lower-exp.f64N/A
lower--.f6499.9
Applied rewrites99.9%
(FPCore (a b) :precision binary64 (if (<= (/ (exp a) (+ (exp a) (exp b))) 0.6) (/ 1.0 (fma (fma (fma 0.16666666666666666 b 0.5) b 1.0) b 2.0)) 0.5))
double code(double a, double b) {
double tmp;
if ((exp(a) / (exp(a) + exp(b))) <= 0.6) {
tmp = 1.0 / fma(fma(fma(0.16666666666666666, b, 0.5), b, 1.0), b, 2.0);
} else {
tmp = 0.5;
}
return tmp;
}
function code(a, b) tmp = 0.0 if (Float64(exp(a) / Float64(exp(a) + exp(b))) <= 0.6) tmp = Float64(1.0 / fma(fma(fma(0.16666666666666666, b, 0.5), b, 1.0), b, 2.0)); else tmp = 0.5; 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.6], N[(1.0 / N[(N[(N[(0.16666666666666666 * b + 0.5), $MachinePrecision] * b + 1.0), $MachinePrecision] * b + 2.0), $MachinePrecision]), $MachinePrecision], 0.5]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{e^{a}}{e^{a} + e^{b}} \leq 0.6:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, b, 0.5\right), b, 1\right), b, 2\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) < 0.599999999999999978Initial program 99.9%
Taylor expanded in a around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f6474.5
Applied rewrites74.5%
Taylor expanded in b around 0
Applied rewrites63.5%
if 0.599999999999999978 < (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) Initial program 95.8%
Taylor expanded in a around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f6496.6
Applied rewrites96.6%
Taylor expanded in b around 0
Applied rewrites18.8%
(FPCore (a b) :precision binary64 (if (<= (/ (exp a) (+ (exp a) (exp b))) 0.6) (/ 1.0 (fma (fma 0.5 b 1.0) b 2.0)) 0.5))
double code(double a, double b) {
double tmp;
if ((exp(a) / (exp(a) + exp(b))) <= 0.6) {
tmp = 1.0 / fma(fma(0.5, b, 1.0), b, 2.0);
} else {
tmp = 0.5;
}
return tmp;
}
function code(a, b) tmp = 0.0 if (Float64(exp(a) / Float64(exp(a) + exp(b))) <= 0.6) tmp = Float64(1.0 / fma(fma(0.5, b, 1.0), b, 2.0)); else tmp = 0.5; 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.6], N[(1.0 / N[(N[(0.5 * b + 1.0), $MachinePrecision] * b + 2.0), $MachinePrecision]), $MachinePrecision], 0.5]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{e^{a}}{e^{a} + e^{b}} \leq 0.6:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(0.5, b, 1\right), b, 2\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) < 0.599999999999999978Initial program 99.9%
Taylor expanded in a around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f6474.5
Applied rewrites74.5%
Taylor expanded in b around 0
Applied rewrites60.0%
if 0.599999999999999978 < (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) Initial program 95.8%
Taylor expanded in a around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f6496.6
Applied rewrites96.6%
Taylor expanded in b around 0
Applied rewrites18.8%
(FPCore (a b) :precision binary64 (if (<= (/ (exp a) (+ (exp a) (exp b))) 0.4998) (/ 1.0 (fma (* 0.5 b) b 2.0)) 0.5))
double code(double a, double b) {
double tmp;
if ((exp(a) / (exp(a) + exp(b))) <= 0.4998) {
tmp = 1.0 / fma((0.5 * b), b, 2.0);
} else {
tmp = 0.5;
}
return tmp;
}
function code(a, b) tmp = 0.0 if (Float64(exp(a) / Float64(exp(a) + exp(b))) <= 0.4998) tmp = Float64(1.0 / fma(Float64(0.5 * b), b, 2.0)); else tmp = 0.5; 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.4998], N[(1.0 / N[(N[(0.5 * b), $MachinePrecision] * b + 2.0), $MachinePrecision]), $MachinePrecision], 0.5]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{e^{a}}{e^{a} + e^{b}} \leq 0.4998:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(0.5 \cdot b, b, 2\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) < 0.49980000000000002Initial program 100.0%
Taylor expanded in a around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f6459.7
Applied rewrites59.7%
Taylor expanded in b around 0
Applied rewrites35.9%
Taylor expanded in b around inf
Applied rewrites35.5%
if 0.49980000000000002 < (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) Initial program 98.4%
Taylor expanded in a around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f6497.1
Applied rewrites97.1%
Taylor expanded in b around 0
Applied rewrites67.3%
(FPCore (a b)
:precision binary64
(let* ((t_0 (/ 1.0 (+ (exp b) 1.0))))
(if (<= (exp b) 0.9999999)
t_0
(if (<= (exp b) 1.00000000002) (/ 1.0 (+ (exp (- a)) 1.0)) t_0))))
double code(double a, double b) {
double t_0 = 1.0 / (exp(b) + 1.0);
double tmp;
if (exp(b) <= 0.9999999) {
tmp = t_0;
} else if (exp(b) <= 1.00000000002) {
tmp = 1.0 / (exp(-a) + 1.0);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: t_0
real(8) :: tmp
t_0 = 1.0d0 / (exp(b) + 1.0d0)
if (exp(b) <= 0.9999999d0) then
tmp = t_0
else if (exp(b) <= 1.00000000002d0) then
tmp = 1.0d0 / (exp(-a) + 1.0d0)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b) {
double t_0 = 1.0 / (Math.exp(b) + 1.0);
double tmp;
if (Math.exp(b) <= 0.9999999) {
tmp = t_0;
} else if (Math.exp(b) <= 1.00000000002) {
tmp = 1.0 / (Math.exp(-a) + 1.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b): t_0 = 1.0 / (math.exp(b) + 1.0) tmp = 0 if math.exp(b) <= 0.9999999: tmp = t_0 elif math.exp(b) <= 1.00000000002: tmp = 1.0 / (math.exp(-a) + 1.0) else: tmp = t_0 return tmp
function code(a, b) t_0 = Float64(1.0 / Float64(exp(b) + 1.0)) tmp = 0.0 if (exp(b) <= 0.9999999) tmp = t_0; elseif (exp(b) <= 1.00000000002) tmp = Float64(1.0 / Float64(exp(Float64(-a)) + 1.0)); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b) t_0 = 1.0 / (exp(b) + 1.0); tmp = 0.0; if (exp(b) <= 0.9999999) tmp = t_0; elseif (exp(b) <= 1.00000000002) tmp = 1.0 / (exp(-a) + 1.0); else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(1.0 / N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Exp[b], $MachinePrecision], 0.9999999], t$95$0, If[LessEqual[N[Exp[b], $MachinePrecision], 1.00000000002], N[(1.0 / N[(N[Exp[(-a)], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{e^{b} + 1}\\
\mathbf{if}\;e^{b} \leq 0.9999999:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;e^{b} \leq 1.00000000002:\\
\;\;\;\;\frac{1}{e^{-a} + 1}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (exp.f64 b) < 0.999999900000000053 or 1.00000000002 < (exp.f64 b) Initial program 99.1%
Taylor expanded in a around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f6499.6
Applied rewrites99.6%
if 0.999999900000000053 < (exp.f64 b) < 1.00000000002Initial program 99.2%
lift-/.f64N/A
clear-numN/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
div-addN/A
*-inversesN/A
lower-+.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
div-expN/A
lower-exp.f64N/A
lower--.f6499.9
Applied rewrites99.9%
Taylor expanded in a around inf
neg-mul-1N/A
lower-neg.f6499.6
Applied rewrites99.6%
(FPCore (a b)
:precision binary64
(if (<= a -9.6e+41)
(/
1.0
(fma
(+ b 1.0)
(fma (fma (fma -0.16666666666666666 a 0.5) a -1.0) a 1.0)
1.0))
(if (<= a -880000000.0)
(* (pow b 3.0) 0.020833333333333332)
(/ 1.0 (+ (exp b) 1.0)))))
double code(double a, double b) {
double tmp;
if (a <= -9.6e+41) {
tmp = 1.0 / fma((b + 1.0), fma(fma(fma(-0.16666666666666666, a, 0.5), a, -1.0), a, 1.0), 1.0);
} else if (a <= -880000000.0) {
tmp = pow(b, 3.0) * 0.020833333333333332;
} else {
tmp = 1.0 / (exp(b) + 1.0);
}
return tmp;
}
function code(a, b) tmp = 0.0 if (a <= -9.6e+41) tmp = Float64(1.0 / fma(Float64(b + 1.0), fma(fma(fma(-0.16666666666666666, a, 0.5), a, -1.0), a, 1.0), 1.0)); elseif (a <= -880000000.0) tmp = Float64((b ^ 3.0) * 0.020833333333333332); else tmp = Float64(1.0 / Float64(exp(b) + 1.0)); end return tmp end
code[a_, b_] := If[LessEqual[a, -9.6e+41], N[(1.0 / N[(N[(b + 1.0), $MachinePrecision] * N[(N[(N[(-0.16666666666666666 * a + 0.5), $MachinePrecision] * a + -1.0), $MachinePrecision] * a + 1.0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, -880000000.0], N[(N[Power[b, 3.0], $MachinePrecision] * 0.020833333333333332), $MachinePrecision], N[(1.0 / N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -9.6 \cdot 10^{+41}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(b + 1, \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, a, 0.5\right), a, -1\right), a, 1\right), 1\right)}\\
\mathbf{elif}\;a \leq -880000000:\\
\;\;\;\;{b}^{3} \cdot 0.020833333333333332\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\
\end{array}
\end{array}
if a < -9.6000000000000007e41Initial program 100.0%
lift-/.f64N/A
clear-numN/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
div-addN/A
*-inversesN/A
lower-+.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
div-expN/A
lower-exp.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
+-commutativeN/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-fma.f64N/A
lower-+.f64N/A
neg-mul-1N/A
lower-exp.f64N/A
neg-mul-1N/A
lower-neg.f64100.0
Applied rewrites100.0%
Taylor expanded in a around 0
Applied rewrites88.3%
if -9.6000000000000007e41 < a < -8.8e8Initial program 100.0%
Taylor expanded in a around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f6419.3
Applied rewrites19.3%
Taylor expanded in b around 0
Applied rewrites2.9%
Taylor expanded in b around inf
Applied rewrites67.7%
if -8.8e8 < a Initial program 98.8%
Taylor expanded in a around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f6497.1
Applied rewrites97.1%
Final simplification93.5%
(FPCore (a b)
:precision binary64
(if (<= b -2300.0)
0.5
(if (<= b 9.2e+102)
(/
1.0
(fma
(+ b 1.0)
(fma (fma (fma -0.16666666666666666 a 0.5) a -1.0) a 1.0)
1.0))
(/ 1.0 (fma (fma (fma 0.16666666666666666 b 0.5) b 1.0) b 2.0)))))
double code(double a, double b) {
double tmp;
if (b <= -2300.0) {
tmp = 0.5;
} else if (b <= 9.2e+102) {
tmp = 1.0 / fma((b + 1.0), fma(fma(fma(-0.16666666666666666, a, 0.5), a, -1.0), a, 1.0), 1.0);
} else {
tmp = 1.0 / fma(fma(fma(0.16666666666666666, b, 0.5), b, 1.0), b, 2.0);
}
return tmp;
}
function code(a, b) tmp = 0.0 if (b <= -2300.0) tmp = 0.5; elseif (b <= 9.2e+102) tmp = Float64(1.0 / fma(Float64(b + 1.0), fma(fma(fma(-0.16666666666666666, a, 0.5), a, -1.0), a, 1.0), 1.0)); else tmp = Float64(1.0 / fma(fma(fma(0.16666666666666666, b, 0.5), b, 1.0), b, 2.0)); end return tmp end
code[a_, b_] := If[LessEqual[b, -2300.0], 0.5, If[LessEqual[b, 9.2e+102], N[(1.0 / N[(N[(b + 1.0), $MachinePrecision] * N[(N[(N[(-0.16666666666666666 * a + 0.5), $MachinePrecision] * a + -1.0), $MachinePrecision] * a + 1.0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(N[(0.16666666666666666 * b + 0.5), $MachinePrecision] * b + 1.0), $MachinePrecision] * b + 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2300:\\
\;\;\;\;0.5\\
\mathbf{elif}\;b \leq 9.2 \cdot 10^{+102}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(b + 1, \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, a, 0.5\right), a, -1\right), a, 1\right), 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, b, 0.5\right), b, 1\right), b, 2\right)}\\
\end{array}
\end{array}
if b < -2300Initial program 97.8%
Taylor expanded in a around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
Applied rewrites18.8%
if -2300 < b < 9.1999999999999995e102Initial program 99.3%
lift-/.f64N/A
clear-numN/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
div-addN/A
*-inversesN/A
lower-+.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
div-expN/A
lower-exp.f64N/A
lower--.f6499.9
Applied rewrites99.9%
Taylor expanded in b around 0
+-commutativeN/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-fma.f64N/A
lower-+.f64N/A
neg-mul-1N/A
lower-exp.f64N/A
neg-mul-1N/A
lower-neg.f6490.6
Applied rewrites90.6%
Taylor expanded in a around 0
Applied rewrites77.2%
if 9.1999999999999995e102 < b Initial program 100.0%
Taylor expanded in a around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
Applied rewrites100.0%
Final simplification71.0%
(FPCore (a b)
:precision binary64
(if (<= b -2300.0)
0.5
(if (<= b 5.2e+102)
(/ 1.0 (fma (+ b 1.0) (fma (fma 0.5 a -1.0) a 1.0) 1.0))
(/ 1.0 (fma (fma (fma 0.16666666666666666 b 0.5) b 1.0) b 2.0)))))
double code(double a, double b) {
double tmp;
if (b <= -2300.0) {
tmp = 0.5;
} else if (b <= 5.2e+102) {
tmp = 1.0 / fma((b + 1.0), fma(fma(0.5, a, -1.0), a, 1.0), 1.0);
} else {
tmp = 1.0 / fma(fma(fma(0.16666666666666666, b, 0.5), b, 1.0), b, 2.0);
}
return tmp;
}
function code(a, b) tmp = 0.0 if (b <= -2300.0) tmp = 0.5; elseif (b <= 5.2e+102) tmp = Float64(1.0 / fma(Float64(b + 1.0), fma(fma(0.5, a, -1.0), a, 1.0), 1.0)); else tmp = Float64(1.0 / fma(fma(fma(0.16666666666666666, b, 0.5), b, 1.0), b, 2.0)); end return tmp end
code[a_, b_] := If[LessEqual[b, -2300.0], 0.5, If[LessEqual[b, 5.2e+102], N[(1.0 / N[(N[(b + 1.0), $MachinePrecision] * N[(N[(0.5 * a + -1.0), $MachinePrecision] * a + 1.0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(N[(0.16666666666666666 * b + 0.5), $MachinePrecision] * b + 1.0), $MachinePrecision] * b + 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2300:\\
\;\;\;\;0.5\\
\mathbf{elif}\;b \leq 5.2 \cdot 10^{+102}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(b + 1, \mathsf{fma}\left(\mathsf{fma}\left(0.5, a, -1\right), a, 1\right), 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, b, 0.5\right), b, 1\right), b, 2\right)}\\
\end{array}
\end{array}
if b < -2300Initial program 97.8%
Taylor expanded in a around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
Applied rewrites18.8%
if -2300 < b < 5.20000000000000013e102Initial program 99.3%
lift-/.f64N/A
clear-numN/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
div-addN/A
*-inversesN/A
lower-+.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
div-expN/A
lower-exp.f64N/A
lower--.f6499.9
Applied rewrites99.9%
Taylor expanded in b around 0
+-commutativeN/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-fma.f64N/A
lower-+.f64N/A
neg-mul-1N/A
lower-exp.f64N/A
neg-mul-1N/A
lower-neg.f6490.6
Applied rewrites90.6%
Taylor expanded in a around 0
Applied rewrites70.9%
if 5.20000000000000013e102 < b Initial program 100.0%
Taylor expanded in a around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
Applied rewrites100.0%
Final simplification67.0%
(FPCore (a b)
:precision binary64
(if (<= b -1.4)
0.5
(if (<= b 2.5e+118)
(/ 1.0 (fma (+ b 1.0) (- 1.0 a) 1.0))
(/ 1.0 (fma (fma 0.5 b 1.0) b 2.0)))))
double code(double a, double b) {
double tmp;
if (b <= -1.4) {
tmp = 0.5;
} else if (b <= 2.5e+118) {
tmp = 1.0 / fma((b + 1.0), (1.0 - a), 1.0);
} else {
tmp = 1.0 / fma(fma(0.5, b, 1.0), b, 2.0);
}
return tmp;
}
function code(a, b) tmp = 0.0 if (b <= -1.4) tmp = 0.5; elseif (b <= 2.5e+118) tmp = Float64(1.0 / fma(Float64(b + 1.0), Float64(1.0 - a), 1.0)); else tmp = Float64(1.0 / fma(fma(0.5, b, 1.0), b, 2.0)); end return tmp end
code[a_, b_] := If[LessEqual[b, -1.4], 0.5, If[LessEqual[b, 2.5e+118], N[(1.0 / N[(N[(b + 1.0), $MachinePrecision] * N[(1.0 - a), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(0.5 * b + 1.0), $MachinePrecision] * b + 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.4:\\
\;\;\;\;0.5\\
\mathbf{elif}\;b \leq 2.5 \cdot 10^{+118}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(b + 1, 1 - a, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(0.5, b, 1\right), b, 2\right)}\\
\end{array}
\end{array}
if b < -1.3999999999999999Initial program 97.8%
Taylor expanded in a around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
Applied rewrites18.8%
if -1.3999999999999999 < b < 2.49999999999999986e118Initial program 99.3%
lift-/.f64N/A
clear-numN/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
div-addN/A
*-inversesN/A
lower-+.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
div-expN/A
lower-exp.f64N/A
lower--.f6499.9
Applied rewrites99.9%
Taylor expanded in b around 0
+-commutativeN/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-fma.f64N/A
lower-+.f64N/A
neg-mul-1N/A
lower-exp.f64N/A
neg-mul-1N/A
lower-neg.f6489.6
Applied rewrites89.6%
Taylor expanded in a around 0
Applied rewrites53.9%
if 2.49999999999999986e118 < b Initial program 100.0%
Taylor expanded in a around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
Applied rewrites93.8%
Final simplification54.5%
(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 99.2%
Taylor expanded in a around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f6478.7
Applied rewrites78.7%
Taylor expanded in b around 0
Applied rewrites35.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 2024312
(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))))