
(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 (if (<= (exp a) 0.01) (/ (exp a) (+ (exp a) 1.0)) (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.01) {
tmp = exp(a) / (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 (exp(a) <= 0.01d0) then
tmp = exp(a) / (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 (Math.exp(a) <= 0.01) {
tmp = Math.exp(a) / (Math.exp(a) + 1.0);
} else {
tmp = 1.0 / (Math.exp(b) + 1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(a) <= 0.01: tmp = math.exp(a) / (math.exp(a) + 1.0) else: tmp = 1.0 / (math.exp(b) + 1.0) return tmp
function code(a, b) tmp = 0.0 if (exp(a) <= 0.01) tmp = Float64(exp(a) / Float64(exp(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 (exp(a) <= 0.01) tmp = exp(a) / (exp(a) + 1.0); else tmp = 1.0 / (exp(b) + 1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.01], N[(N[Exp[a], $MachinePrecision] / 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}\;e^{a} \leq 0.01:\\
\;\;\;\;\frac{e^{a}}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.0100000000000000002Initial program 100.0%
Taylor expanded in b around 0 100.0%
if 0.0100000000000000002 < (exp.f64 a) Initial program 98.9%
Taylor expanded in a around 0 99.0%
Final simplification99.2%
(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 99.2%
Final simplification99.2%
(FPCore (a b)
:precision binary64
(if (<= a -700.0)
(/ (exp a) a)
(if (or (<= a -3.3e-144) (not (<= a -6.8e-201)))
(/ 1.0 (+ 2.0 (+ b (* (* b b) 0.5))))
(* -0.020833333333333332 (pow a 3.0)))))
double code(double a, double b) {
double tmp;
if (a <= -700.0) {
tmp = exp(a) / a;
} else if ((a <= -3.3e-144) || !(a <= -6.8e-201)) {
tmp = 1.0 / (2.0 + (b + ((b * b) * 0.5)));
} else {
tmp = -0.020833333333333332 * pow(a, 3.0);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-700.0d0)) then
tmp = exp(a) / a
else if ((a <= (-3.3d-144)) .or. (.not. (a <= (-6.8d-201)))) then
tmp = 1.0d0 / (2.0d0 + (b + ((b * b) * 0.5d0)))
else
tmp = (-0.020833333333333332d0) * (a ** 3.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -700.0) {
tmp = Math.exp(a) / a;
} else if ((a <= -3.3e-144) || !(a <= -6.8e-201)) {
tmp = 1.0 / (2.0 + (b + ((b * b) * 0.5)));
} else {
tmp = -0.020833333333333332 * Math.pow(a, 3.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -700.0: tmp = math.exp(a) / a elif (a <= -3.3e-144) or not (a <= -6.8e-201): tmp = 1.0 / (2.0 + (b + ((b * b) * 0.5))) else: tmp = -0.020833333333333332 * math.pow(a, 3.0) return tmp
function code(a, b) tmp = 0.0 if (a <= -700.0) tmp = Float64(exp(a) / a); elseif ((a <= -3.3e-144) || !(a <= -6.8e-201)) tmp = Float64(1.0 / Float64(2.0 + Float64(b + Float64(Float64(b * b) * 0.5)))); else tmp = Float64(-0.020833333333333332 * (a ^ 3.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -700.0) tmp = exp(a) / a; elseif ((a <= -3.3e-144) || ~((a <= -6.8e-201))) tmp = 1.0 / (2.0 + (b + ((b * b) * 0.5))); else tmp = -0.020833333333333332 * (a ^ 3.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -700.0], N[(N[Exp[a], $MachinePrecision] / a), $MachinePrecision], If[Or[LessEqual[a, -3.3e-144], N[Not[LessEqual[a, -6.8e-201]], $MachinePrecision]], N[(1.0 / N[(2.0 + N[(b + N[(N[(b * b), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-0.020833333333333332 * N[Power[a, 3.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -700:\\
\;\;\;\;\frac{e^{a}}{a}\\
\mathbf{elif}\;a \leq -3.3 \cdot 10^{-144} \lor \neg \left(a \leq -6.8 \cdot 10^{-201}\right):\\
\;\;\;\;\frac{1}{2 + \left(b + \left(b \cdot b\right) \cdot 0.5\right)}\\
\mathbf{else}:\\
\;\;\;\;-0.020833333333333332 \cdot {a}^{3}\\
\end{array}
\end{array}
if a < -700Initial program 100.0%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in a around inf 100.0%
if -700 < a < -3.29999999999999995e-144 or -6.7999999999999997e-201 < a Initial program 98.9%
Taylor expanded in a around 0 98.0%
Taylor expanded in b around 0 53.5%
*-commutative53.5%
unpow253.5%
Simplified53.5%
if -3.29999999999999995e-144 < a < -6.7999999999999997e-201Initial program 100.0%
Taylor expanded in b around 0 7.4%
Taylor expanded in a around 0 7.4%
Taylor expanded in a around inf 73.6%
Final simplification66.2%
(FPCore (a b) :precision binary64 (if (<= a -3300.0) (/ (exp a) a) (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
double tmp;
if (a <= -3300.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 <= (-3300.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 <= -3300.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 <= -3300.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 <= -3300.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 <= -3300.0) tmp = exp(a) / a; else tmp = 1.0 / (exp(b) + 1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -3300.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 -3300:\\
\;\;\;\;\frac{e^{a}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\
\end{array}
\end{array}
if a < -3300Initial program 100.0%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in a around inf 100.0%
if -3300 < a Initial program 98.9%
Taylor expanded in a around 0 98.1%
Final simplification98.6%
(FPCore (a b) :precision binary64 (if (<= a -700.0) (/ (exp a) a) (/ 1.0 (+ 2.0 (+ b (* (* b b) 0.5))))))
double code(double a, double b) {
double tmp;
if (a <= -700.0) {
tmp = exp(a) / a;
} else {
tmp = 1.0 / (2.0 + (b + ((b * 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 (a <= (-700.0d0)) then
tmp = exp(a) / a
else
tmp = 1.0d0 / (2.0d0 + (b + ((b * b) * 0.5d0)))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -700.0) {
tmp = Math.exp(a) / a;
} else {
tmp = 1.0 / (2.0 + (b + ((b * b) * 0.5)));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -700.0: tmp = math.exp(a) / a else: tmp = 1.0 / (2.0 + (b + ((b * b) * 0.5))) return tmp
function code(a, b) tmp = 0.0 if (a <= -700.0) tmp = Float64(exp(a) / a); else tmp = Float64(1.0 / Float64(2.0 + Float64(b + Float64(Float64(b * b) * 0.5)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -700.0) tmp = exp(a) / a; else tmp = 1.0 / (2.0 + (b + ((b * b) * 0.5))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -700.0], N[(N[Exp[a], $MachinePrecision] / a), $MachinePrecision], N[(1.0 / N[(2.0 + N[(b + N[(N[(b * b), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -700:\\
\;\;\;\;\frac{e^{a}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + \left(b + \left(b \cdot b\right) \cdot 0.5\right)}\\
\end{array}
\end{array}
if a < -700Initial program 100.0%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in a around inf 100.0%
if -700 < a Initial program 98.9%
Taylor expanded in a around 0 98.1%
Taylor expanded in b around 0 52.2%
*-commutative52.2%
unpow252.2%
Simplified52.2%
Final simplification64.4%
(FPCore (a b) :precision binary64 (if (<= b 7.5e-114) (+ 0.5 (* a 0.25)) (/ 1.0 (+ 2.0 (+ b (* (* b b) 0.5))))))
double code(double a, double b) {
double tmp;
if (b <= 7.5e-114) {
tmp = 0.5 + (a * 0.25);
} else {
tmp = 1.0 / (2.0 + (b + ((b * 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 <= 7.5d-114) then
tmp = 0.5d0 + (a * 0.25d0)
else
tmp = 1.0d0 / (2.0d0 + (b + ((b * b) * 0.5d0)))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 7.5e-114) {
tmp = 0.5 + (a * 0.25);
} else {
tmp = 1.0 / (2.0 + (b + ((b * b) * 0.5)));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 7.5e-114: tmp = 0.5 + (a * 0.25) else: tmp = 1.0 / (2.0 + (b + ((b * b) * 0.5))) return tmp
function code(a, b) tmp = 0.0 if (b <= 7.5e-114) tmp = Float64(0.5 + Float64(a * 0.25)); else tmp = Float64(1.0 / Float64(2.0 + Float64(b + Float64(Float64(b * b) * 0.5)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 7.5e-114) tmp = 0.5 + (a * 0.25); else tmp = 1.0 / (2.0 + (b + ((b * b) * 0.5))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 7.5e-114], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 + N[(b + N[(N[(b * b), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7.5 \cdot 10^{-114}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + \left(b + \left(b \cdot b\right) \cdot 0.5\right)}\\
\end{array}
\end{array}
if b < 7.5000000000000002e-114Initial program 99.4%
Taylor expanded in b around 0 68.4%
Taylor expanded in a around 0 47.0%
if 7.5000000000000002e-114 < b Initial program 98.8%
Taylor expanded in a around 0 93.4%
Taylor expanded in b around 0 55.2%
*-commutative55.2%
unpow255.2%
Simplified55.2%
Final simplification49.7%
(FPCore (a b) :precision binary64 (if (<= b 1.1e-114) (+ 0.5 (* a 0.25)) (/ 1.0 (+ 2.0 (* b (* b 0.5))))))
double code(double a, double b) {
double tmp;
if (b <= 1.1e-114) {
tmp = 0.5 + (a * 0.25);
} else {
tmp = 1.0 / (2.0 + (b * (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 <= 1.1d-114) then
tmp = 0.5d0 + (a * 0.25d0)
else
tmp = 1.0d0 / (2.0d0 + (b * (b * 0.5d0)))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 1.1e-114) {
tmp = 0.5 + (a * 0.25);
} else {
tmp = 1.0 / (2.0 + (b * (b * 0.5)));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.1e-114: tmp = 0.5 + (a * 0.25) else: tmp = 1.0 / (2.0 + (b * (b * 0.5))) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.1e-114) tmp = Float64(0.5 + Float64(a * 0.25)); else tmp = Float64(1.0 / Float64(2.0 + Float64(b * Float64(b * 0.5)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 1.1e-114) tmp = 0.5 + (a * 0.25); else tmp = 1.0 / (2.0 + (b * (b * 0.5))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.1e-114], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 + N[(b * N[(b * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.1 \cdot 10^{-114}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(b \cdot 0.5\right)}\\
\end{array}
\end{array}
if b < 1.10000000000000006e-114Initial program 99.4%
Taylor expanded in b around 0 68.4%
Taylor expanded in a around 0 47.0%
if 1.10000000000000006e-114 < b Initial program 98.8%
Taylor expanded in a around 0 93.4%
Taylor expanded in b around 0 55.2%
*-commutative55.2%
unpow255.2%
Simplified55.2%
Taylor expanded in b around inf 55.2%
unpow255.2%
*-commutative55.2%
associate-*r*55.2%
*-commutative55.2%
Simplified55.2%
Final simplification49.7%
(FPCore (a b) :precision binary64 (if (<= b 1.4) (+ 0.5 (* a 0.25)) (/ 2.0 (* b b))))
double code(double a, double b) {
double tmp;
if (b <= 1.4) {
tmp = 0.5 + (a * 0.25);
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 1.4d0) then
tmp = 0.5d0 + (a * 0.25d0)
else
tmp = 2.0d0 / (b * b)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 1.4) {
tmp = 0.5 + (a * 0.25);
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.4: tmp = 0.5 + (a * 0.25) else: tmp = 2.0 / (b * b) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.4) tmp = Float64(0.5 + Float64(a * 0.25)); else tmp = Float64(2.0 / Float64(b * b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 1.4) tmp = 0.5 + (a * 0.25); else tmp = 2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.4], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision], N[(2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.4:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{b \cdot b}\\
\end{array}
\end{array}
if b < 1.3999999999999999Initial program 99.4%
Taylor expanded in b around 0 70.7%
Taylor expanded in a around 0 47.9%
if 1.3999999999999999 < b Initial program 98.6%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 54.2%
*-commutative54.2%
unpow254.2%
Simplified54.2%
Taylor expanded in b around inf 54.2%
unpow254.2%
Simplified54.2%
Final simplification49.7%
(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 99.2%
Taylor expanded in b around 0 61.3%
Taylor expanded in a around 0 35.6%
Final simplification35.6%
(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 b around 0 61.3%
Taylor expanded in a around 0 35.4%
Final simplification35.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 2023181
(FPCore (a b)
:name "Quotient of sum of exps"
:precision binary64
:herbie-target
(/ 1.0 (+ 1.0 (exp (- b a))))
(/ (exp a) (+ (exp a) (exp b))))