
(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 13 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.3%
*-lft-identity97.3%
associate-*l/97.2%
associate-/r/97.2%
remove-double-neg97.2%
unsub-neg97.2%
div-sub73.8%
*-lft-identity73.8%
associate-*l/73.8%
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.999999) (/ 1.0 (+ 1.0 (exp (- a)))) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.999999) {
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.999999d0) 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.999999) {
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.999999: 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.999999) 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.999999) 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.999999], 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.999999:\\
\;\;\;\;\frac{1}{1 + e^{-a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.999998999999999971Initial program 97.0%
*-lft-identity97.0%
associate-*l/96.9%
associate-/r/96.9%
remove-double-neg96.9%
unsub-neg96.9%
div-sub6.0%
*-lft-identity6.0%
associate-*l/6.0%
lft-mult-inverse96.9%
sub-neg96.9%
distribute-frac-neg96.9%
remove-double-neg96.9%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 97.9%
if 0.999998999999999971 < (exp.f64 a) Initial program 97.4%
*-lft-identity97.4%
associate-*l/97.4%
associate-/r/97.3%
remove-double-neg97.3%
unsub-neg97.3%
div-sub97.3%
*-lft-identity97.3%
associate-*l/97.3%
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 98.7%
(FPCore (a b) :precision binary64 (if (<= (exp a) 0.0) (/ (exp a) 2.0) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.0) {
tmp = exp(a) / 2.0;
} 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.0d0) then
tmp = exp(a) / 2.0d0
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.0) {
tmp = Math.exp(a) / 2.0;
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(a) <= 0.0: tmp = math.exp(a) / 2.0 else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (exp(a) <= 0.0) tmp = Float64(exp(a) / 2.0); 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.0) tmp = exp(a) / 2.0; else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.0], N[(N[Exp[a], $MachinePrecision] / 2.0), $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:\\
\;\;\;\;\frac{e^{a}}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.0Initial program 96.8%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
if 0.0 < (exp.f64 a) Initial program 97.4%
*-lft-identity97.4%
associate-*l/97.4%
associate-/r/97.4%
remove-double-neg97.4%
unsub-neg97.4%
div-sub97.4%
*-lft-identity97.4%
associate-*l/97.4%
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.8%
(FPCore (a b)
:precision binary64
(if (<= b -27000.0)
1.0
(if (<= b 2.3e+98)
(/ (exp a) 2.0)
(/ 1.0 (+ 2.0 (* b (+ 1.0 (* b (+ 0.5 (* b 0.16666666666666666))))))))))
double code(double a, double b) {
double tmp;
if (b <= -27000.0) {
tmp = 1.0;
} else if (b <= 2.3e+98) {
tmp = exp(a) / 2.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 <= (-27000.0d0)) then
tmp = 1.0d0
else if (b <= 2.3d+98) then
tmp = exp(a) / 2.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 <= -27000.0) {
tmp = 1.0;
} else if (b <= 2.3e+98) {
tmp = Math.exp(a) / 2.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 <= -27000.0: tmp = 1.0 elif b <= 2.3e+98: tmp = math.exp(a) / 2.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 <= -27000.0) tmp = 1.0; elseif (b <= 2.3e+98) tmp = Float64(exp(a) / 2.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 <= -27000.0) tmp = 1.0; elseif (b <= 2.3e+98) tmp = exp(a) / 2.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, -27000.0], 1.0, If[LessEqual[b, 2.3e+98], N[(N[Exp[a], $MachinePrecision] / 2.0), $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 -27000:\\
\;\;\;\;1\\
\mathbf{elif}\;b \leq 2.3 \cdot 10^{+98}:\\
\;\;\;\;\frac{e^{a}}{2}\\
\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 < -27000Initial program 97.9%
Taylor expanded in b around 0 18.1%
Taylor expanded in a around 0 18.1%
+-commutative18.1%
Simplified18.1%
Taylor expanded in a around 0 19.4%
Taylor expanded in a around inf 100.0%
if -27000 < b < 2.30000000000000013e98Initial program 97.5%
Taylor expanded in b around 0 84.5%
Taylor expanded in a around 0 84.0%
+-commutative84.0%
Simplified84.0%
Taylor expanded in a around 0 83.2%
if 2.30000000000000013e98 < b Initial program 95.7%
*-lft-identity95.7%
associate-*l/95.7%
associate-/r/95.7%
remove-double-neg95.7%
unsub-neg95.7%
div-sub69.6%
*-lft-identity69.6%
associate-*l/69.6%
lft-mult-inverse95.7%
sub-neg95.7%
distribute-frac-neg95.7%
remove-double-neg95.7%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 98.0%
*-commutative98.0%
Simplified98.0%
(FPCore (a b)
:precision binary64
(if (<= b -27000.0)
1.0
(if (<= b 1.1e+95)
(/ 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 <= -27000.0) {
tmp = 1.0;
} else if (b <= 1.1e+95) {
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 <= (-27000.0d0)) then
tmp = 1.0d0
else if (b <= 1.1d+95) 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 <= -27000.0) {
tmp = 1.0;
} else if (b <= 1.1e+95) {
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 <= -27000.0: tmp = 1.0 elif b <= 1.1e+95: 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 <= -27000.0) tmp = 1.0; elseif (b <= 1.1e+95) 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 <= -27000.0) tmp = 1.0; elseif (b <= 1.1e+95) 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, -27000.0], 1.0, If[LessEqual[b, 1.1e+95], 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 -27000:\\
\;\;\;\;1\\
\mathbf{elif}\;b \leq 1.1 \cdot 10^{+95}:\\
\;\;\;\;\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 < -27000Initial program 97.9%
Taylor expanded in b around 0 18.1%
Taylor expanded in a around 0 18.1%
+-commutative18.1%
Simplified18.1%
Taylor expanded in a around 0 19.4%
Taylor expanded in a around inf 100.0%
if -27000 < b < 1.0999999999999999e95Initial program 97.5%
*-lft-identity97.5%
associate-*l/97.5%
associate-/r/97.5%
remove-double-neg97.5%
unsub-neg97.5%
div-sub68.5%
*-lft-identity68.5%
associate-*l/68.5%
lft-mult-inverse98.7%
sub-neg98.7%
distribute-frac-neg98.7%
remove-double-neg98.7%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 85.6%
Taylor expanded in a around 0 72.8%
if 1.0999999999999999e95 < b Initial program 95.7%
*-lft-identity95.7%
associate-*l/95.7%
associate-/r/95.7%
remove-double-neg95.7%
unsub-neg95.7%
div-sub68.1%
*-lft-identity68.1%
associate-*l/68.1%
lft-mult-inverse95.7%
sub-neg95.7%
distribute-frac-neg95.7%
remove-double-neg95.7%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 96.2%
*-commutative96.2%
Simplified96.2%
Final simplification82.1%
(FPCore (a b)
:precision binary64
(if (<= b -27000.0)
1.0
(if (<= b 2.05e+141)
(/ 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 <= -27000.0) {
tmp = 1.0;
} else if (b <= 2.05e+141) {
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 <= (-27000.0d0)) then
tmp = 1.0d0
else if (b <= 2.05d+141) 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 <= -27000.0) {
tmp = 1.0;
} else if (b <= 2.05e+141) {
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 <= -27000.0: tmp = 1.0 elif b <= 2.05e+141: 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 <= -27000.0) tmp = 1.0; elseif (b <= 2.05e+141) 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 <= -27000.0) tmp = 1.0; elseif (b <= 2.05e+141) 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, -27000.0], 1.0, If[LessEqual[b, 2.05e+141], 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 -27000:\\
\;\;\;\;1\\
\mathbf{elif}\;b \leq 2.05 \cdot 10^{+141}:\\
\;\;\;\;\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 < -27000Initial program 97.9%
Taylor expanded in b around 0 18.1%
Taylor expanded in a around 0 18.1%
+-commutative18.1%
Simplified18.1%
Taylor expanded in a around 0 19.4%
Taylor expanded in a around inf 100.0%
if -27000 < b < 2.05000000000000011e141Initial program 97.6%
*-lft-identity97.6%
associate-*l/97.6%
associate-/r/97.6%
remove-double-neg97.6%
unsub-neg97.6%
div-sub67.8%
*-lft-identity67.8%
associate-*l/67.8%
lft-mult-inverse98.8%
sub-neg98.8%
distribute-frac-neg98.8%
remove-double-neg98.8%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 84.4%
Taylor expanded in a around 0 70.9%
if 2.05000000000000011e141 < b Initial program 95.1%
*-lft-identity95.1%
associate-*l/95.1%
associate-/r/95.1%
remove-double-neg95.1%
unsub-neg95.1%
div-sub70.7%
*-lft-identity70.7%
associate-*l/70.7%
lft-mult-inverse95.1%
sub-neg95.1%
distribute-frac-neg95.1%
remove-double-neg95.1%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 95.6%
*-commutative95.6%
Simplified95.6%
Final simplification80.2%
(FPCore (a b)
:precision binary64
(if (<= b -27000.0)
1.0
(if (<= b 1.9e+141)
(/ 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 <= -27000.0) {
tmp = 1.0;
} else if (b <= 1.9e+141) {
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 <= (-27000.0d0)) then
tmp = 1.0d0
else if (b <= 1.9d+141) 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 <= -27000.0) {
tmp = 1.0;
} else if (b <= 1.9e+141) {
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 <= -27000.0: tmp = 1.0 elif b <= 1.9e+141: 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 <= -27000.0) tmp = 1.0; elseif (b <= 1.9e+141) 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 <= -27000.0) tmp = 1.0; elseif (b <= 1.9e+141) 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, -27000.0], 1.0, If[LessEqual[b, 1.9e+141], 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 -27000:\\
\;\;\;\;1\\
\mathbf{elif}\;b \leq 1.9 \cdot 10^{+141}:\\
\;\;\;\;\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 < -27000Initial program 97.9%
Taylor expanded in b around 0 18.1%
Taylor expanded in a around 0 18.1%
+-commutative18.1%
Simplified18.1%
Taylor expanded in a around 0 19.4%
Taylor expanded in a around inf 100.0%
if -27000 < b < 1.89999999999999988e141Initial program 97.6%
*-lft-identity97.6%
associate-*l/97.6%
associate-/r/97.6%
remove-double-neg97.6%
unsub-neg97.6%
div-sub67.8%
*-lft-identity67.8%
associate-*l/67.8%
lft-mult-inverse98.8%
sub-neg98.8%
distribute-frac-neg98.8%
remove-double-neg98.8%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 84.4%
Taylor expanded in a around 0 64.7%
if 1.89999999999999988e141 < b Initial program 95.1%
*-lft-identity95.1%
associate-*l/95.1%
associate-/r/95.1%
remove-double-neg95.1%
unsub-neg95.1%
div-sub70.7%
*-lft-identity70.7%
associate-*l/70.7%
lft-mult-inverse95.1%
sub-neg95.1%
distribute-frac-neg95.1%
remove-double-neg95.1%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 95.6%
*-commutative95.6%
Simplified95.6%
Final simplification76.1%
(FPCore (a b) :precision binary64 (if (<= b -27000.0) 1.0 (/ 1.0 (+ 2.0 (* a (+ (* a 0.5) -1.0))))))
double code(double a, double b) {
double tmp;
if (b <= -27000.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 <= (-27000.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 <= -27000.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 <= -27000.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 <= -27000.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 <= -27000.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, -27000.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 -27000:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(a \cdot 0.5 + -1\right)}\\
\end{array}
\end{array}
if b < -27000Initial program 97.9%
Taylor expanded in b around 0 18.1%
Taylor expanded in a around 0 18.1%
+-commutative18.1%
Simplified18.1%
Taylor expanded in a around 0 19.4%
Taylor expanded in a around inf 100.0%
if -27000 < b Initial program 97.1%
*-lft-identity97.1%
associate-*l/97.1%
associate-/r/97.1%
remove-double-neg97.1%
unsub-neg97.1%
div-sub68.4%
*-lft-identity68.4%
associate-*l/68.4%
lft-mult-inverse98.1%
sub-neg98.1%
distribute-frac-neg98.1%
remove-double-neg98.1%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 73.1%
Taylor expanded in a around 0 54.1%
Final simplification62.5%
(FPCore (a b) :precision binary64 (if (<= b -27000.0) 1.0 (/ 1.0 (+ 2.0 (* a (* a 0.5))))))
double code(double a, double b) {
double tmp;
if (b <= -27000.0) {
tmp = 1.0;
} else {
tmp = 1.0 / (2.0 + (a * (a * 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 <= (-27000.0d0)) then
tmp = 1.0d0
else
tmp = 1.0d0 / (2.0d0 + (a * (a * 0.5d0)))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -27000.0) {
tmp = 1.0;
} else {
tmp = 1.0 / (2.0 + (a * (a * 0.5)));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -27000.0: tmp = 1.0 else: tmp = 1.0 / (2.0 + (a * (a * 0.5))) return tmp
function code(a, b) tmp = 0.0 if (b <= -27000.0) tmp = 1.0; else tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(a * 0.5)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -27000.0) tmp = 1.0; else tmp = 1.0 / (2.0 + (a * (a * 0.5))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -27000.0], 1.0, N[(1.0 / N[(2.0 + N[(a * N[(a * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -27000:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(a \cdot 0.5\right)}\\
\end{array}
\end{array}
if b < -27000Initial program 97.9%
Taylor expanded in b around 0 18.1%
Taylor expanded in a around 0 18.1%
+-commutative18.1%
Simplified18.1%
Taylor expanded in a around 0 19.4%
Taylor expanded in a around inf 100.0%
if -27000 < b Initial program 97.1%
*-lft-identity97.1%
associate-*l/97.1%
associate-/r/97.1%
remove-double-neg97.1%
unsub-neg97.1%
div-sub68.4%
*-lft-identity68.4%
associate-*l/68.4%
lft-mult-inverse98.1%
sub-neg98.1%
distribute-frac-neg98.1%
remove-double-neg98.1%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 73.1%
Taylor expanded in a around 0 54.1%
Taylor expanded in a around inf 53.1%
Final simplification61.7%
(FPCore (a b) :precision binary64 (if (<= b -27000.0) 1.0 (/ 1.0 (+ b 2.0))))
double code(double a, double b) {
double tmp;
if (b <= -27000.0) {
tmp = 1.0;
} else {
tmp = 1.0 / (b + 2.0);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= (-27000.0d0)) then
tmp = 1.0d0
else
tmp = 1.0d0 / (b + 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -27000.0) {
tmp = 1.0;
} else {
tmp = 1.0 / (b + 2.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -27000.0: tmp = 1.0 else: tmp = 1.0 / (b + 2.0) return tmp
function code(a, b) tmp = 0.0 if (b <= -27000.0) tmp = 1.0; else tmp = Float64(1.0 / Float64(b + 2.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -27000.0) tmp = 1.0; else tmp = 1.0 / (b + 2.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -27000.0], 1.0, N[(1.0 / N[(b + 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -27000:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{b + 2}\\
\end{array}
\end{array}
if b < -27000Initial program 97.9%
Taylor expanded in b around 0 18.1%
Taylor expanded in a around 0 18.1%
+-commutative18.1%
Simplified18.1%
Taylor expanded in a around 0 19.4%
Taylor expanded in a around inf 100.0%
if -27000 < b Initial program 97.1%
*-lft-identity97.1%
associate-*l/97.1%
associate-/r/97.1%
remove-double-neg97.1%
unsub-neg97.1%
div-sub68.4%
*-lft-identity68.4%
associate-*l/68.4%
lft-mult-inverse98.1%
sub-neg98.1%
distribute-frac-neg98.1%
remove-double-neg98.1%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 76.7%
Taylor expanded in b around 0 43.8%
+-commutative43.8%
Simplified43.8%
(FPCore (a b) :precision binary64 (if (<= b -9.8e-11) 1.0 (+ 0.5 (* a 0.25))))
double code(double a, double b) {
double tmp;
if (b <= -9.8e-11) {
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 <= (-9.8d-11)) 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 <= -9.8e-11) {
tmp = 1.0;
} else {
tmp = 0.5 + (a * 0.25);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -9.8e-11: tmp = 1.0 else: tmp = 0.5 + (a * 0.25) return tmp
function code(a, b) tmp = 0.0 if (b <= -9.8e-11) 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 <= -9.8e-11) tmp = 1.0; else tmp = 0.5 + (a * 0.25); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -9.8e-11], 1.0, N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9.8 \cdot 10^{-11}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\end{array}
\end{array}
if b < -9.7999999999999998e-11Initial program 94.0%
Taylor expanded in b around 0 23.0%
Taylor expanded in a around 0 23.0%
+-commutative23.0%
Simplified23.0%
Taylor expanded in a around 0 18.4%
Taylor expanded in a around inf 94.2%
if -9.7999999999999998e-11 < b Initial program 98.0%
*-lft-identity98.0%
associate-*l/98.0%
associate-/r/98.0%
remove-double-neg98.0%
unsub-neg98.0%
div-sub69.4%
*-lft-identity69.4%
associate-*l/69.4%
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 72.7%
Taylor expanded in a around 0 43.9%
*-commutative43.9%
Simplified43.9%
(FPCore (a b) :precision binary64 (if (<= b -27000.0) 1.0 0.5))
double code(double a, double b) {
double tmp;
if (b <= -27000.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 <= (-27000.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 <= -27000.0) {
tmp = 1.0;
} else {
tmp = 0.5;
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -27000.0: tmp = 1.0 else: tmp = 0.5 return tmp
function code(a, b) tmp = 0.0 if (b <= -27000.0) tmp = 1.0; else tmp = 0.5; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -27000.0) tmp = 1.0; else tmp = 0.5; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -27000.0], 1.0, 0.5]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -27000:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if b < -27000Initial program 97.9%
Taylor expanded in b around 0 18.1%
Taylor expanded in a around 0 18.1%
+-commutative18.1%
Simplified18.1%
Taylor expanded in a around 0 19.4%
Taylor expanded in a around inf 100.0%
if -27000 < b Initial program 97.1%
*-lft-identity97.1%
associate-*l/97.1%
associate-/r/97.1%
remove-double-neg97.1%
unsub-neg97.1%
div-sub68.4%
*-lft-identity68.4%
associate-*l/68.4%
lft-mult-inverse98.1%
sub-neg98.1%
distribute-frac-neg98.1%
remove-double-neg98.1%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 76.7%
Taylor expanded in b around 0 42.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 97.3%
*-lft-identity97.3%
associate-*l/97.2%
associate-/r/97.2%
remove-double-neg97.2%
unsub-neg97.2%
div-sub73.8%
*-lft-identity73.8%
associate-*l/73.8%
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 80.9%
Taylor expanded in b around 0 38.2%
(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 2024110
(FPCore (a b)
:name "Quotient of sum of exps"
:precision binary64
:alt
(/ 1.0 (+ 1.0 (exp (- b a))))
(/ (exp a) (+ (exp a) (exp b))))