
(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 9 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 (<= a -4e+18) (exp a) (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
double tmp;
if (a <= -4e+18) {
tmp = exp(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 <= (-4d+18)) then
tmp = exp(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 <= -4e+18) {
tmp = Math.exp(a);
} else {
tmp = 1.0 / (Math.exp(b) + 1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -4e+18: tmp = math.exp(a) else: tmp = 1.0 / (math.exp(b) + 1.0) return tmp
function code(a, b) tmp = 0.0 if (a <= -4e+18) tmp = exp(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 <= -4e+18) tmp = exp(a); else tmp = 1.0 / (exp(b) + 1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -4e+18], N[Exp[a], $MachinePrecision], N[(1.0 / N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -4 \cdot 10^{+18}:\\
\;\;\;\;e^{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\
\end{array}
\end{array}
if a < -4e18Initial program 100.0%
add-cbrt-cube100.0%
pow1/3100.0%
pow-to-exp100.0%
pow3100.0%
log-pow100.0%
log-div100.0%
add-log-exp100.0%
Applied egg-rr100.0%
Taylor expanded in a around inf 100.0%
if -4e18 < a Initial program 98.4%
Taylor expanded in a around 0 98.9%
Final simplification99.2%
(FPCore (a b) :precision binary64 (exp (- a (log (+ (exp a) (exp b))))))
double code(double a, double b) {
return exp((a - log((exp(a) + exp(b)))));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = exp((a - log((exp(a) + exp(b)))))
end function
public static double code(double a, double b) {
return Math.exp((a - Math.log((Math.exp(a) + Math.exp(b)))));
}
def code(a, b): return math.exp((a - math.log((math.exp(a) + math.exp(b)))))
function code(a, b) return exp(Float64(a - log(Float64(exp(a) + exp(b))))) end
function tmp = code(a, b) tmp = exp((a - log((exp(a) + exp(b))))); end
code[a_, b_] := N[Exp[N[(a - N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{a - \log \left(e^{a} + e^{b}\right)}
\end{array}
Initial program 98.8%
add-exp-log98.8%
div-exp98.9%
Applied egg-rr98.9%
Final simplification98.9%
(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%
Final simplification98.8%
(FPCore (a b)
:precision binary64
(let* ((t_0 (+ 0.5 (* a 0.25))))
(if (<= b -2.15e-7)
(exp a)
(if (<= b -1.9e-143)
t_0
(if (<= b -1.6e-188)
(exp a)
(if (<= b 9e-164)
0.5
(if (<= b 3.1e-146) (exp a) (if (<= b 2.3e-22) t_0 0.0))))))))
double code(double a, double b) {
double t_0 = 0.5 + (a * 0.25);
double tmp;
if (b <= -2.15e-7) {
tmp = exp(a);
} else if (b <= -1.9e-143) {
tmp = t_0;
} else if (b <= -1.6e-188) {
tmp = exp(a);
} else if (b <= 9e-164) {
tmp = 0.5;
} else if (b <= 3.1e-146) {
tmp = exp(a);
} else if (b <= 2.3e-22) {
tmp = t_0;
} else {
tmp = 0.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 = 0.5d0 + (a * 0.25d0)
if (b <= (-2.15d-7)) then
tmp = exp(a)
else if (b <= (-1.9d-143)) then
tmp = t_0
else if (b <= (-1.6d-188)) then
tmp = exp(a)
else if (b <= 9d-164) then
tmp = 0.5d0
else if (b <= 3.1d-146) then
tmp = exp(a)
else if (b <= 2.3d-22) then
tmp = t_0
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double t_0 = 0.5 + (a * 0.25);
double tmp;
if (b <= -2.15e-7) {
tmp = Math.exp(a);
} else if (b <= -1.9e-143) {
tmp = t_0;
} else if (b <= -1.6e-188) {
tmp = Math.exp(a);
} else if (b <= 9e-164) {
tmp = 0.5;
} else if (b <= 3.1e-146) {
tmp = Math.exp(a);
} else if (b <= 2.3e-22) {
tmp = t_0;
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b): t_0 = 0.5 + (a * 0.25) tmp = 0 if b <= -2.15e-7: tmp = math.exp(a) elif b <= -1.9e-143: tmp = t_0 elif b <= -1.6e-188: tmp = math.exp(a) elif b <= 9e-164: tmp = 0.5 elif b <= 3.1e-146: tmp = math.exp(a) elif b <= 2.3e-22: tmp = t_0 else: tmp = 0.0 return tmp
function code(a, b) t_0 = Float64(0.5 + Float64(a * 0.25)) tmp = 0.0 if (b <= -2.15e-7) tmp = exp(a); elseif (b <= -1.9e-143) tmp = t_0; elseif (b <= -1.6e-188) tmp = exp(a); elseif (b <= 9e-164) tmp = 0.5; elseif (b <= 3.1e-146) tmp = exp(a); elseif (b <= 2.3e-22) tmp = t_0; else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b) t_0 = 0.5 + (a * 0.25); tmp = 0.0; if (b <= -2.15e-7) tmp = exp(a); elseif (b <= -1.9e-143) tmp = t_0; elseif (b <= -1.6e-188) tmp = exp(a); elseif (b <= 9e-164) tmp = 0.5; elseif (b <= 3.1e-146) tmp = exp(a); elseif (b <= 2.3e-22) tmp = t_0; else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -2.15e-7], N[Exp[a], $MachinePrecision], If[LessEqual[b, -1.9e-143], t$95$0, If[LessEqual[b, -1.6e-188], N[Exp[a], $MachinePrecision], If[LessEqual[b, 9e-164], 0.5, If[LessEqual[b, 3.1e-146], N[Exp[a], $MachinePrecision], If[LessEqual[b, 2.3e-22], t$95$0, 0.0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 + a \cdot 0.25\\
\mathbf{if}\;b \leq -2.15 \cdot 10^{-7}:\\
\;\;\;\;e^{a}\\
\mathbf{elif}\;b \leq -1.9 \cdot 10^{-143}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq -1.6 \cdot 10^{-188}:\\
\;\;\;\;e^{a}\\
\mathbf{elif}\;b \leq 9 \cdot 10^{-164}:\\
\;\;\;\;0.5\\
\mathbf{elif}\;b \leq 3.1 \cdot 10^{-146}:\\
\;\;\;\;e^{a}\\
\mathbf{elif}\;b \leq 2.3 \cdot 10^{-22}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < -2.1500000000000001e-7 or -1.89999999999999991e-143 < b < -1.60000000000000011e-188 or 8.9999999999999995e-164 < b < 3.0999999999999998e-146Initial program 97.4%
add-cbrt-cube97.3%
pow1/397.4%
pow-to-exp97.3%
pow397.3%
log-pow97.3%
log-div97.3%
add-log-exp97.4%
Applied egg-rr97.4%
Taylor expanded in a around inf 91.4%
if -2.1500000000000001e-7 < b < -1.89999999999999991e-143 or 3.0999999999999998e-146 < b < 2.2999999999999998e-22Initial program 98.1%
Taylor expanded in b around 0 98.1%
Taylor expanded in a around 0 80.4%
*-commutative80.4%
Simplified80.4%
if -1.60000000000000011e-188 < b < 8.9999999999999995e-164Initial program 100.0%
Taylor expanded in a around 0 71.8%
Taylor expanded in b around 0 71.8%
if 2.2999999999999998e-22 < b Initial program 100.0%
Taylor expanded in a around 0 93.1%
Taylor expanded in b around 0 6.9%
+-commutative6.9%
Simplified6.9%
add-log-exp86.5%
Applied egg-rr86.5%
Taylor expanded in b around inf 97.2%
Final simplification86.5%
(FPCore (a b)
:precision binary64
(if (<= a -9.2e-32)
(exp a)
(if (<= a 1.7e-180)
(/ 1.0 (+ (+ b 2.0) (* 0.5 (* b b))))
(if (<= a 5.8e-125) (exp a) (if (<= a 4.3e-95) 0.5 (exp a))))))
double code(double a, double b) {
double tmp;
if (a <= -9.2e-32) {
tmp = exp(a);
} else if (a <= 1.7e-180) {
tmp = 1.0 / ((b + 2.0) + (0.5 * (b * b)));
} else if (a <= 5.8e-125) {
tmp = exp(a);
} else if (a <= 4.3e-95) {
tmp = 0.5;
} else {
tmp = exp(a);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-9.2d-32)) then
tmp = exp(a)
else if (a <= 1.7d-180) then
tmp = 1.0d0 / ((b + 2.0d0) + (0.5d0 * (b * b)))
else if (a <= 5.8d-125) then
tmp = exp(a)
else if (a <= 4.3d-95) then
tmp = 0.5d0
else
tmp = exp(a)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -9.2e-32) {
tmp = Math.exp(a);
} else if (a <= 1.7e-180) {
tmp = 1.0 / ((b + 2.0) + (0.5 * (b * b)));
} else if (a <= 5.8e-125) {
tmp = Math.exp(a);
} else if (a <= 4.3e-95) {
tmp = 0.5;
} else {
tmp = Math.exp(a);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -9.2e-32: tmp = math.exp(a) elif a <= 1.7e-180: tmp = 1.0 / ((b + 2.0) + (0.5 * (b * b))) elif a <= 5.8e-125: tmp = math.exp(a) elif a <= 4.3e-95: tmp = 0.5 else: tmp = math.exp(a) return tmp
function code(a, b) tmp = 0.0 if (a <= -9.2e-32) tmp = exp(a); elseif (a <= 1.7e-180) tmp = Float64(1.0 / Float64(Float64(b + 2.0) + Float64(0.5 * Float64(b * b)))); elseif (a <= 5.8e-125) tmp = exp(a); elseif (a <= 4.3e-95) tmp = 0.5; else tmp = exp(a); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -9.2e-32) tmp = exp(a); elseif (a <= 1.7e-180) tmp = 1.0 / ((b + 2.0) + (0.5 * (b * b))); elseif (a <= 5.8e-125) tmp = exp(a); elseif (a <= 4.3e-95) tmp = 0.5; else tmp = exp(a); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -9.2e-32], N[Exp[a], $MachinePrecision], If[LessEqual[a, 1.7e-180], N[(1.0 / N[(N[(b + 2.0), $MachinePrecision] + N[(0.5 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 5.8e-125], N[Exp[a], $MachinePrecision], If[LessEqual[a, 4.3e-95], 0.5, N[Exp[a], $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -9.2 \cdot 10^{-32}:\\
\;\;\;\;e^{a}\\
\mathbf{elif}\;a \leq 1.7 \cdot 10^{-180}:\\
\;\;\;\;\frac{1}{\left(b + 2\right) + 0.5 \cdot \left(b \cdot b\right)}\\
\mathbf{elif}\;a \leq 5.8 \cdot 10^{-125}:\\
\;\;\;\;e^{a}\\
\mathbf{elif}\;a \leq 4.3 \cdot 10^{-95}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;e^{a}\\
\end{array}
\end{array}
if a < -9.2000000000000002e-32 or 1.69999999999999991e-180 < a < 5.8000000000000004e-125 or 4.29999999999999997e-95 < a Initial program 97.5%
add-cbrt-cube97.3%
pow1/397.5%
pow-to-exp97.3%
pow397.3%
log-pow97.3%
log-div97.3%
add-log-exp97.4%
Applied egg-rr97.4%
Taylor expanded in a around inf 82.4%
if -9.2000000000000002e-32 < a < 1.69999999999999991e-180Initial program 100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 68.9%
associate-+r+68.9%
+-commutative68.9%
unpow268.9%
Simplified68.9%
if 5.8000000000000004e-125 < a < 4.29999999999999997e-95Initial program 100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 81.9%
Final simplification75.7%
(FPCore (a b) :precision binary64 (if (<= b -2.0) 0.5 (/ 1.0 (+ (+ b 2.0) (* 0.5 (* b b))))))
double code(double a, double b) {
double tmp;
if (b <= -2.0) {
tmp = 0.5;
} else {
tmp = 1.0 / ((b + 2.0) + (0.5 * (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 <= (-2.0d0)) then
tmp = 0.5d0
else
tmp = 1.0d0 / ((b + 2.0d0) + (0.5d0 * (b * b)))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -2.0) {
tmp = 0.5;
} else {
tmp = 1.0 / ((b + 2.0) + (0.5 * (b * b)));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -2.0: tmp = 0.5 else: tmp = 1.0 / ((b + 2.0) + (0.5 * (b * b))) return tmp
function code(a, b) tmp = 0.0 if (b <= -2.0) tmp = 0.5; else tmp = Float64(1.0 / Float64(Float64(b + 2.0) + Float64(0.5 * Float64(b * b)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -2.0) tmp = 0.5; else tmp = 1.0 / ((b + 2.0) + (0.5 * (b * b))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -2.0], 0.5, N[(1.0 / N[(N[(b + 2.0), $MachinePrecision] + N[(0.5 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(b + 2\right) + 0.5 \cdot \left(b \cdot b\right)}\\
\end{array}
\end{array}
if b < -2Initial program 96.7%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 18.8%
if -2 < b Initial program 99.5%
Taylor expanded in a around 0 77.6%
Taylor expanded in b around 0 62.9%
associate-+r+62.9%
+-commutative62.9%
unpow262.9%
Simplified62.9%
Final simplification52.6%
(FPCore (a b) :precision binary64 (if (<= b 1.25) 0.5 (/ 1.0 (+ b (* b (* b 0.5))))))
double code(double a, double b) {
double tmp;
if (b <= 1.25) {
tmp = 0.5;
} else {
tmp = 1.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 <= 1.25d0) then
tmp = 0.5d0
else
tmp = 1.0d0 / (b + (b * (b * 0.5d0)))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 1.25) {
tmp = 0.5;
} else {
tmp = 1.0 / (b + (b * (b * 0.5)));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.25: tmp = 0.5 else: tmp = 1.0 / (b + (b * (b * 0.5))) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.25) tmp = 0.5; else tmp = Float64(1.0 / Float64(b + Float64(b * Float64(b * 0.5)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 1.25) tmp = 0.5; else tmp = 1.0 / (b + (b * (b * 0.5))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.25], 0.5, N[(1.0 / N[(b + N[(b * N[(b * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.25:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{b + b \cdot \left(b \cdot 0.5\right)}\\
\end{array}
\end{array}
if b < 1.25Initial program 98.4%
Taylor expanded in a around 0 77.3%
Taylor expanded in b around 0 51.6%
if 1.25 < b Initial program 100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 55.1%
associate-+r+55.1%
+-commutative55.1%
unpow255.1%
Simplified55.1%
Taylor expanded in b around inf 55.1%
unpow255.1%
*-commutative55.1%
associate-*r*55.1%
Simplified55.1%
Final simplification52.4%
(FPCore (a b) :precision binary64 (if (<= b 2.0) 0.5 (/ 2.0 (* b b))))
double code(double a, double b) {
double tmp;
if (b <= 2.0) {
tmp = 0.5;
} 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 <= 2.0d0) then
tmp = 0.5d0
else
tmp = 2.0d0 / (b * b)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 2.0) {
tmp = 0.5;
} else {
tmp = 2.0 / (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 2.0: tmp = 0.5 else: tmp = 2.0 / (b * b) return tmp
function code(a, b) tmp = 0.0 if (b <= 2.0) tmp = 0.5; else tmp = Float64(2.0 / Float64(b * b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 2.0) tmp = 0.5; else tmp = 2.0 / (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 2.0], 0.5, N[(2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{b \cdot b}\\
\end{array}
\end{array}
if b < 2Initial program 98.4%
Taylor expanded in a around 0 77.3%
Taylor expanded in b around 0 51.6%
if 2 < b Initial program 100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 55.1%
associate-+r+55.1%
+-commutative55.1%
unpow255.1%
Simplified55.1%
Taylor expanded in b around inf 55.1%
unpow255.1%
Simplified55.1%
Final simplification52.4%
(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 82.9%
Taylor expanded in b around 0 39.6%
Final simplification39.6%
(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 2023174
(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))))