
(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 (/ 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}
Initial program 97.6%
*-lft-identity97.6%
associate-*l/97.6%
associate-/r/97.6%
remove-double-neg97.6%
unsub-neg97.6%
div-sub74.6%
*-lft-identity74.6%
associate-*l/74.6%
lft-mult-inverse98.4%
sub-neg98.4%
distribute-frac-neg98.4%
remove-double-neg98.4%
div-exp100.0%
Simplified100.0%
(FPCore (a b) :precision binary64 (if (<= (exp a) 0.9999998) (/ 1.0 (+ 1.0 (exp (- a)))) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.9999998) {
tmp = 1.0 / (1.0 + exp(-a));
} else {
tmp = 1.0 / (1.0 + exp(b));
}
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.9999998d0) then
tmp = 1.0d0 / (1.0d0 + exp(-a))
else
tmp = 1.0d0 / (1.0d0 + exp(b))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 0.9999998) {
tmp = 1.0 / (1.0 + Math.exp(-a));
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(a) <= 0.9999998: tmp = 1.0 / (1.0 + math.exp(-a)) else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (exp(a) <= 0.9999998) tmp = Float64(1.0 / Float64(1.0 + exp(Float64(-a)))); else tmp = Float64(1.0 / Float64(1.0 + exp(b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (exp(a) <= 0.9999998) tmp = 1.0 / (1.0 + exp(-a)); else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.9999998], N[(1.0 / N[(1.0 + N[Exp[(-a)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0.9999998:\\
\;\;\;\;\frac{1}{1 + e^{-a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.999999799999999994Initial program 96.9%
*-lft-identity96.9%
associate-*l/96.9%
associate-/r/96.9%
remove-double-neg96.9%
unsub-neg96.9%
div-sub8.9%
*-lft-identity8.9%
associate-*l/8.9%
lft-mult-inverse96.9%
sub-neg96.9%
distribute-frac-neg96.9%
remove-double-neg96.9%
div-exp99.9%
Simplified99.9%
Taylor expanded in b around 0 99.9%
if 0.999999799999999994 < (exp.f64 a) Initial program 97.9%
*-lft-identity97.9%
associate-*l/97.9%
associate-/r/97.9%
remove-double-neg97.9%
unsub-neg97.9%
div-sub97.9%
*-lft-identity97.9%
associate-*l/97.9%
lft-mult-inverse98.9%
sub-neg98.9%
distribute-frac-neg98.9%
remove-double-neg98.9%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 97.7%
(FPCore (a b) :precision binary64 (if (<= (exp a) 5e-15) (exp a) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 5e-15) {
tmp = exp(a);
} else {
tmp = 1.0 / (1.0 + exp(b));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (exp(a) <= 5d-15) then
tmp = exp(a)
else
tmp = 1.0d0 / (1.0d0 + exp(b))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 5e-15) {
tmp = Math.exp(a);
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(a) <= 5e-15: tmp = math.exp(a) else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (exp(a) <= 5e-15) tmp = exp(a); else tmp = Float64(1.0 / Float64(1.0 + exp(b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (exp(a) <= 5e-15) tmp = exp(a); else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 5e-15], N[Exp[a], $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 5 \cdot 10^{-15}:\\
\;\;\;\;e^{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if (exp.f64 a) < 4.99999999999999999e-15Initial program 96.7%
Taylor expanded in b around 0 100.0%
rem-exp-log100.0%
log1p-undefine100.0%
div-exp99.9%
Simplified99.9%
Taylor expanded in a around inf 99.9%
if 4.99999999999999999e-15 < (exp.f64 a) Initial program 97.9%
*-lft-identity97.9%
associate-*l/97.9%
associate-/r/97.9%
remove-double-neg97.9%
unsub-neg97.9%
div-sub97.9%
*-lft-identity97.9%
associate-*l/97.9%
lft-mult-inverse98.9%
sub-neg98.9%
distribute-frac-neg98.9%
remove-double-neg98.9%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 96.2%
(FPCore (a b)
:precision binary64
(if (<= b -100000.0)
1.0
(if (<= b 3.8e+102)
(/ 1.0 (+ 2.0 (* a (+ (* a (+ 0.5 (* a -0.16666666666666666))) -1.0))))
(/ 1.0 (+ 2.0 (* b (+ 1.0 (* b (+ 0.5 (* b 0.16666666666666666))))))))))
double code(double a, double b) {
double tmp;
if (b <= -100000.0) {
tmp = 1.0;
} else if (b <= 3.8e+102) {
tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0)));
} 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 <= (-100000.0d0)) then
tmp = 1.0d0
else if (b <= 3.8d+102) then
tmp = 1.0d0 / (2.0d0 + (a * ((a * (0.5d0 + (a * (-0.16666666666666666d0)))) + (-1.0d0))))
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 <= -100000.0) {
tmp = 1.0;
} else if (b <= 3.8e+102) {
tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0)));
} 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 <= -100000.0: tmp = 1.0 elif b <= 3.8e+102: tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0))) 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 <= -100000.0) tmp = 1.0; elseif (b <= 3.8e+102) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(Float64(a * Float64(0.5 + Float64(a * -0.16666666666666666))) + -1.0)))); 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 <= -100000.0) tmp = 1.0; elseif (b <= 3.8e+102) tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0))); 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, -100000.0], 1.0, If[LessEqual[b, 3.8e+102], N[(1.0 / N[(2.0 + N[(a * N[(N[(a * N[(0.5 + N[(a * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $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 -100000:\\
\;\;\;\;1\\
\mathbf{elif}\;b \leq 3.8 \cdot 10^{+102}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(a \cdot \left(0.5 + a \cdot -0.16666666666666666\right) + -1\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 < -1e5Initial program 100.0%
Taylor expanded in b around 0 19.0%
rem-exp-log19.0%
log1p-undefine19.0%
div-exp19.0%
Simplified19.0%
Taylor expanded in a around inf 95.9%
Taylor expanded in a around 0 100.0%
if -1e5 < b < 3.79999999999999979e102Initial program 97.0%
*-lft-identity97.0%
associate-*l/97.0%
associate-/r/97.0%
remove-double-neg97.0%
unsub-neg97.0%
div-sub69.8%
*-lft-identity69.8%
associate-*l/69.8%
lft-mult-inverse98.2%
sub-neg98.2%
distribute-frac-neg98.2%
remove-double-neg98.2%
div-exp99.9%
Simplified99.9%
Taylor expanded in b around 0 86.5%
Taylor expanded in a around 0 75.6%
if 3.79999999999999979e102 < b Initial program 97.2%
*-lft-identity97.2%
associate-*l/97.2%
associate-/r/97.2%
remove-double-neg97.2%
unsub-neg97.2%
div-sub61.1%
*-lft-identity61.1%
associate-*l/61.1%
lft-mult-inverse97.2%
sub-neg97.2%
distribute-frac-neg97.2%
remove-double-neg97.2%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 100.0%
*-commutative100.0%
Simplified100.0%
Final simplification83.9%
(FPCore (a b)
:precision binary64
(if (<= b -7200.0)
1.0
(if (<= b 2.4e+129)
(/ 1.0 (+ 2.0 (* a (+ (* a (+ 0.5 (* a -0.16666666666666666))) -1.0))))
(/ 1.0 (+ 2.0 (* b (+ 1.0 (* b 0.5))))))))
double code(double a, double b) {
double tmp;
if (b <= -7200.0) {
tmp = 1.0;
} else if (b <= 2.4e+129) {
tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0)));
} 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 <= (-7200.0d0)) then
tmp = 1.0d0
else if (b <= 2.4d+129) then
tmp = 1.0d0 / (2.0d0 + (a * ((a * (0.5d0 + (a * (-0.16666666666666666d0)))) + (-1.0d0))))
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 <= -7200.0) {
tmp = 1.0;
} else if (b <= 2.4e+129) {
tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0)));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -7200.0: tmp = 1.0 elif b <= 2.4e+129: tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0))) else: tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))) return tmp
function code(a, b) tmp = 0.0 if (b <= -7200.0) tmp = 1.0; elseif (b <= 2.4e+129) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(Float64(a * Float64(0.5 + Float64(a * -0.16666666666666666))) + -1.0)))); 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 <= -7200.0) tmp = 1.0; elseif (b <= 2.4e+129) tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0))); else tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -7200.0], 1.0, If[LessEqual[b, 2.4e+129], N[(1.0 / N[(2.0 + N[(a * N[(N[(a * N[(0.5 + N[(a * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $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 -7200:\\
\;\;\;\;1\\
\mathbf{elif}\;b \leq 2.4 \cdot 10^{+129}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(a \cdot \left(0.5 + a \cdot -0.16666666666666666\right) + -1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + b \cdot 0.5\right)}\\
\end{array}
\end{array}
if b < -7200Initial program 100.0%
Taylor expanded in b around 0 19.0%
rem-exp-log19.0%
log1p-undefine19.0%
div-exp19.0%
Simplified19.0%
Taylor expanded in a around inf 95.9%
Taylor expanded in a around 0 100.0%
if -7200 < b < 2.3999999999999999e129Initial program 97.1%
*-lft-identity97.1%
associate-*l/97.1%
associate-/r/97.1%
remove-double-neg97.1%
unsub-neg97.1%
div-sub69.8%
*-lft-identity69.8%
associate-*l/69.8%
lft-mult-inverse98.2%
sub-neg98.2%
distribute-frac-neg98.2%
remove-double-neg98.2%
div-exp99.9%
Simplified99.9%
Taylor expanded in b around 0 84.3%
Taylor expanded in a around 0 73.8%
if 2.3999999999999999e129 < b Initial program 96.6%
*-lft-identity96.6%
associate-*l/96.6%
associate-/r/96.6%
remove-double-neg96.6%
unsub-neg96.6%
div-sub58.6%
*-lft-identity58.6%
associate-*l/58.6%
lft-mult-inverse96.6%
sub-neg96.6%
distribute-frac-neg96.6%
remove-double-neg96.6%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 81.2%
*-commutative81.2%
Simplified81.2%
Final simplification79.9%
(FPCore (a b)
:precision binary64
(if (<= b -7200.0)
1.0
(if (<= b 4.2e+129)
(/ 1.0 (+ 2.0 (* a (+ (* a (* a -0.16666666666666666)) -1.0))))
(/ 1.0 (+ 2.0 (* b (+ 1.0 (* b 0.5))))))))
double code(double a, double b) {
double tmp;
if (b <= -7200.0) {
tmp = 1.0;
} else if (b <= 4.2e+129) {
tmp = 1.0 / (2.0 + (a * ((a * (a * -0.16666666666666666)) + -1.0)));
} 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 <= (-7200.0d0)) then
tmp = 1.0d0
else if (b <= 4.2d+129) then
tmp = 1.0d0 / (2.0d0 + (a * ((a * (a * (-0.16666666666666666d0))) + (-1.0d0))))
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 <= -7200.0) {
tmp = 1.0;
} else if (b <= 4.2e+129) {
tmp = 1.0 / (2.0 + (a * ((a * (a * -0.16666666666666666)) + -1.0)));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -7200.0: tmp = 1.0 elif b <= 4.2e+129: tmp = 1.0 / (2.0 + (a * ((a * (a * -0.16666666666666666)) + -1.0))) else: tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))) return tmp
function code(a, b) tmp = 0.0 if (b <= -7200.0) tmp = 1.0; elseif (b <= 4.2e+129) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(Float64(a * Float64(a * -0.16666666666666666)) + -1.0)))); 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 <= -7200.0) tmp = 1.0; elseif (b <= 4.2e+129) tmp = 1.0 / (2.0 + (a * ((a * (a * -0.16666666666666666)) + -1.0))); else tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -7200.0], 1.0, If[LessEqual[b, 4.2e+129], N[(1.0 / N[(2.0 + N[(a * N[(N[(a * N[(a * -0.16666666666666666), $MachinePrecision]), $MachinePrecision] + -1.0), $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 -7200:\\
\;\;\;\;1\\
\mathbf{elif}\;b \leq 4.2 \cdot 10^{+129}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(a \cdot \left(a \cdot -0.16666666666666666\right) + -1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + b \cdot 0.5\right)}\\
\end{array}
\end{array}
if b < -7200Initial program 100.0%
Taylor expanded in b around 0 19.0%
rem-exp-log19.0%
log1p-undefine19.0%
div-exp19.0%
Simplified19.0%
Taylor expanded in a around inf 95.9%
Taylor expanded in a around 0 100.0%
if -7200 < b < 4.19999999999999993e129Initial program 97.1%
*-lft-identity97.1%
associate-*l/97.1%
associate-/r/97.1%
remove-double-neg97.1%
unsub-neg97.1%
div-sub69.8%
*-lft-identity69.8%
associate-*l/69.8%
lft-mult-inverse98.2%
sub-neg98.2%
distribute-frac-neg98.2%
remove-double-neg98.2%
div-exp99.9%
Simplified99.9%
Taylor expanded in b around 0 84.3%
Taylor expanded in a around 0 73.8%
Taylor expanded in a around inf 72.8%
*-commutative72.8%
Simplified72.8%
if 4.19999999999999993e129 < b Initial program 96.6%
*-lft-identity96.6%
associate-*l/96.6%
associate-/r/96.6%
remove-double-neg96.6%
unsub-neg96.6%
div-sub58.6%
*-lft-identity58.6%
associate-*l/58.6%
lft-mult-inverse96.6%
sub-neg96.6%
distribute-frac-neg96.6%
remove-double-neg96.6%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 81.2%
*-commutative81.2%
Simplified81.2%
Final simplification79.2%
(FPCore (a b)
:precision binary64
(if (<= b -7200.0)
1.0
(if (<= b 3.2e+129)
(/ 1.0 (+ 2.0 (* a (+ (* a 0.5) -1.0))))
(/ 1.0 (+ 2.0 (* b (+ 1.0 (* b 0.5))))))))
double code(double a, double b) {
double tmp;
if (b <= -7200.0) {
tmp = 1.0;
} else if (b <= 3.2e+129) {
tmp = 1.0 / (2.0 + (a * ((a * 0.5) + -1.0)));
} 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 <= (-7200.0d0)) then
tmp = 1.0d0
else if (b <= 3.2d+129) then
tmp = 1.0d0 / (2.0d0 + (a * ((a * 0.5d0) + (-1.0d0))))
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 <= -7200.0) {
tmp = 1.0;
} else if (b <= 3.2e+129) {
tmp = 1.0 / (2.0 + (a * ((a * 0.5) + -1.0)));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -7200.0: tmp = 1.0 elif b <= 3.2e+129: tmp = 1.0 / (2.0 + (a * ((a * 0.5) + -1.0))) else: tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))) return tmp
function code(a, b) tmp = 0.0 if (b <= -7200.0) tmp = 1.0; elseif (b <= 3.2e+129) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(Float64(a * 0.5) + -1.0)))); 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 <= -7200.0) tmp = 1.0; elseif (b <= 3.2e+129) tmp = 1.0 / (2.0 + (a * ((a * 0.5) + -1.0))); else tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -7200.0], 1.0, If[LessEqual[b, 3.2e+129], N[(1.0 / N[(2.0 + N[(a * N[(N[(a * 0.5), $MachinePrecision] + -1.0), $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 -7200:\\
\;\;\;\;1\\
\mathbf{elif}\;b \leq 3.2 \cdot 10^{+129}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(a \cdot 0.5 + -1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + b \cdot 0.5\right)}\\
\end{array}
\end{array}
if b < -7200Initial program 100.0%
Taylor expanded in b around 0 19.0%
rem-exp-log19.0%
log1p-undefine19.0%
div-exp19.0%
Simplified19.0%
Taylor expanded in a around inf 95.9%
Taylor expanded in a around 0 100.0%
if -7200 < b < 3.2000000000000002e129Initial program 97.1%
*-lft-identity97.1%
associate-*l/97.1%
associate-/r/97.1%
remove-double-neg97.1%
unsub-neg97.1%
div-sub69.8%
*-lft-identity69.8%
associate-*l/69.8%
lft-mult-inverse98.2%
sub-neg98.2%
distribute-frac-neg98.2%
remove-double-neg98.2%
div-exp99.9%
Simplified99.9%
Taylor expanded in b around 0 84.3%
Taylor expanded in a around 0 69.3%
if 3.2000000000000002e129 < b Initial program 96.6%
*-lft-identity96.6%
associate-*l/96.6%
associate-/r/96.6%
remove-double-neg96.6%
unsub-neg96.6%
div-sub58.6%
*-lft-identity58.6%
associate-*l/58.6%
lft-mult-inverse96.6%
sub-neg96.6%
distribute-frac-neg96.6%
remove-double-neg96.6%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 81.2%
*-commutative81.2%
Simplified81.2%
Final simplification76.7%
(FPCore (a b) :precision binary64 (if (<= b -7200.0) 1.0 (/ 1.0 (+ 2.0 (* a (+ (* a 0.5) -1.0))))))
double code(double a, double b) {
double tmp;
if (b <= -7200.0) {
tmp = 1.0;
} else {
tmp = 1.0 / (2.0 + (a * ((a * 0.5) + -1.0)));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= (-7200.0d0)) then
tmp = 1.0d0
else
tmp = 1.0d0 / (2.0d0 + (a * ((a * 0.5d0) + (-1.0d0))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -7200.0) {
tmp = 1.0;
} else {
tmp = 1.0 / (2.0 + (a * ((a * 0.5) + -1.0)));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -7200.0: tmp = 1.0 else: tmp = 1.0 / (2.0 + (a * ((a * 0.5) + -1.0))) return tmp
function code(a, b) tmp = 0.0 if (b <= -7200.0) tmp = 1.0; else tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(Float64(a * 0.5) + -1.0)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -7200.0) tmp = 1.0; else tmp = 1.0 / (2.0 + (a * ((a * 0.5) + -1.0))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -7200.0], 1.0, N[(1.0 / N[(2.0 + N[(a * N[(N[(a * 0.5), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7200:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(a \cdot 0.5 + -1\right)}\\
\end{array}
\end{array}
if b < -7200Initial program 100.0%
Taylor expanded in b around 0 19.0%
rem-exp-log19.0%
log1p-undefine19.0%
div-exp19.0%
Simplified19.0%
Taylor expanded in a around inf 95.9%
Taylor expanded in a around 0 100.0%
if -7200 < b Initial program 97.0%
*-lft-identity97.0%
associate-*l/97.0%
associate-/r/97.0%
remove-double-neg97.0%
unsub-neg97.0%
div-sub68.2%
*-lft-identity68.2%
associate-*l/68.2%
lft-mult-inverse98.0%
sub-neg98.0%
distribute-frac-neg98.0%
remove-double-neg98.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 78.0%
Taylor expanded in a around 0 61.4%
Final simplification69.1%
(FPCore (a b) :precision binary64 (if (<= b -7200.0) 1.0 (/ 1.0 (- 2.0 a))))
double code(double a, double b) {
double tmp;
if (b <= -7200.0) {
tmp = 1.0;
} else {
tmp = 1.0 / (2.0 - a);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= (-7200.0d0)) then
tmp = 1.0d0
else
tmp = 1.0d0 / (2.0d0 - a)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -7200.0) {
tmp = 1.0;
} else {
tmp = 1.0 / (2.0 - a);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -7200.0: tmp = 1.0 else: tmp = 1.0 / (2.0 - a) return tmp
function code(a, b) tmp = 0.0 if (b <= -7200.0) tmp = 1.0; else tmp = Float64(1.0 / Float64(2.0 - a)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -7200.0) tmp = 1.0; else tmp = 1.0 / (2.0 - a); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -7200.0], 1.0, N[(1.0 / N[(2.0 - a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7200:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 - a}\\
\end{array}
\end{array}
if b < -7200Initial program 100.0%
Taylor expanded in b around 0 19.0%
rem-exp-log19.0%
log1p-undefine19.0%
div-exp19.0%
Simplified19.0%
Taylor expanded in a around inf 95.9%
Taylor expanded in a around 0 100.0%
if -7200 < b Initial program 97.0%
*-lft-identity97.0%
associate-*l/97.0%
associate-/r/97.0%
remove-double-neg97.0%
unsub-neg97.0%
div-sub68.2%
*-lft-identity68.2%
associate-*l/68.2%
lft-mult-inverse98.0%
sub-neg98.0%
distribute-frac-neg98.0%
remove-double-neg98.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 78.0%
Taylor expanded in a around 0 46.5%
neg-mul-146.5%
unsub-neg46.5%
Simplified46.5%
(FPCore (a b) :precision binary64 (if (<= b -0.82) 1.0 (+ 0.5 (* a 0.25))))
double code(double a, double b) {
double tmp;
if (b <= -0.82) {
tmp = 1.0;
} else {
tmp = 0.5 + (a * 0.25);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= (-0.82d0)) then
tmp = 1.0d0
else
tmp = 0.5d0 + (a * 0.25d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -0.82) {
tmp = 1.0;
} else {
tmp = 0.5 + (a * 0.25);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -0.82: tmp = 1.0 else: tmp = 0.5 + (a * 0.25) return tmp
function code(a, b) tmp = 0.0 if (b <= -0.82) tmp = 1.0; else tmp = Float64(0.5 + Float64(a * 0.25)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -0.82) tmp = 1.0; else tmp = 0.5 + (a * 0.25); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -0.82], 1.0, N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.82:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\end{array}
\end{array}
if b < -0.819999999999999951Initial program 96.2%
Taylor expanded in b around 0 22.1%
rem-exp-log22.1%
log1p-undefine22.1%
div-exp22.1%
Simplified22.1%
Taylor expanded in a around inf 96.0%
Taylor expanded in a around 0 96.3%
if -0.819999999999999951 < b Initial program 98.0%
*-lft-identity98.0%
associate-*l/98.0%
associate-/r/98.0%
remove-double-neg98.0%
unsub-neg98.0%
div-sub68.9%
*-lft-identity68.9%
associate-*l/68.9%
lft-mult-inverse99.0%
sub-neg99.0%
distribute-frac-neg99.0%
remove-double-neg99.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 77.8%
Taylor expanded in a around 0 46.6%
*-commutative46.6%
Simplified46.6%
(FPCore (a b) :precision binary64 (if (<= b -7200.0) 1.0 0.5))
double code(double a, double b) {
double tmp;
if (b <= -7200.0) {
tmp = 1.0;
} else {
tmp = 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 <= (-7200.0d0)) then
tmp = 1.0d0
else
tmp = 0.5d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -7200.0) {
tmp = 1.0;
} else {
tmp = 0.5;
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -7200.0: tmp = 1.0 else: tmp = 0.5 return tmp
function code(a, b) tmp = 0.0 if (b <= -7200.0) tmp = 1.0; else tmp = 0.5; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -7200.0) tmp = 1.0; else tmp = 0.5; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -7200.0], 1.0, 0.5]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7200:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if b < -7200Initial program 100.0%
Taylor expanded in b around 0 19.0%
rem-exp-log19.0%
log1p-undefine19.0%
div-exp19.0%
Simplified19.0%
Taylor expanded in a around inf 95.9%
Taylor expanded in a around 0 100.0%
if -7200 < b Initial program 97.0%
*-lft-identity97.0%
associate-*l/97.0%
associate-/r/97.0%
remove-double-neg97.0%
unsub-neg97.0%
div-sub68.2%
*-lft-identity68.2%
associate-*l/68.2%
lft-mult-inverse98.0%
sub-neg98.0%
distribute-frac-neg98.0%
remove-double-neg98.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 76.5%
Taylor expanded in b around 0 45.2%
(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 97.6%
*-lft-identity97.6%
associate-*l/97.6%
associate-/r/97.6%
remove-double-neg97.6%
unsub-neg97.6%
div-sub74.6%
*-lft-identity74.6%
associate-*l/74.6%
lft-mult-inverse98.4%
sub-neg98.4%
distribute-frac-neg98.4%
remove-double-neg98.4%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 81.2%
Taylor expanded in b around 0 39.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 2024157
(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))))