
(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 11 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 99.2%
*-lft-identity99.2%
associate-*l/99.2%
associate-/r/99.2%
remove-double-neg99.2%
unsub-neg99.2%
div-sub68.0%
*-lft-identity68.0%
associate-*l/68.0%
lft-mult-inverse99.2%
sub-neg99.2%
distribute-frac-neg99.2%
remove-double-neg99.2%
div-exp100.0%
Simplified100.0%
(FPCore (a b) :precision binary64 (if (<= a -9.2e-11) (/ 1.0 (+ 1.0 (exp (- a)))) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -9.2e-11) {
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 (a <= (-9.2d-11)) 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 (a <= -9.2e-11) {
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 a <= -9.2e-11: 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 (a <= -9.2e-11) 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 (a <= -9.2e-11) 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[a, -9.2e-11], 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}\;a \leq -9.2 \cdot 10^{-11}:\\
\;\;\;\;\frac{1}{1 + e^{-a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -9.20000000000000054e-11Initial program 98.8%
*-lft-identity98.8%
associate-*l/98.8%
associate-/r/98.8%
remove-double-neg98.8%
unsub-neg98.8%
div-sub1.2%
*-lft-identity1.2%
associate-*l/1.2%
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 98.8%
if -9.20000000000000054e-11 < a Initial program 99.4%
*-lft-identity99.4%
associate-*l/99.4%
associate-/r/99.4%
remove-double-neg99.4%
unsub-neg99.4%
div-sub99.4%
*-lft-identity99.4%
associate-*l/99.4%
lft-mult-inverse99.4%
sub-neg99.4%
distribute-frac-neg99.4%
remove-double-neg99.4%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 99.7%
(FPCore (a b) :precision binary64 (if (<= a -1.55e+52) (/ 1.0 (+ 2.0 (* a (+ (* a (* a -0.16666666666666666)) -1.0)))) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -1.55e+52) {
tmp = 1.0 / (2.0 + (a * ((a * (a * -0.16666666666666666)) + -1.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 (a <= (-1.55d+52)) then
tmp = 1.0d0 / (2.0d0 + (a * ((a * (a * (-0.16666666666666666d0))) + (-1.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 (a <= -1.55e+52) {
tmp = 1.0 / (2.0 + (a * ((a * (a * -0.16666666666666666)) + -1.0)));
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -1.55e+52: tmp = 1.0 / (2.0 + (a * ((a * (a * -0.16666666666666666)) + -1.0))) else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (a <= -1.55e+52) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(Float64(a * Float64(a * -0.16666666666666666)) + -1.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 (a <= -1.55e+52) tmp = 1.0 / (2.0 + (a * ((a * (a * -0.16666666666666666)) + -1.0))); else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -1.55e+52], 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[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.55 \cdot 10^{+52}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(a \cdot \left(a \cdot -0.16666666666666666\right) + -1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -1.55e52Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
remove-double-neg100.0%
unsub-neg100.0%
div-sub0.0%
*-lft-identity0.0%
associate-*l/0.0%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 89.3%
Taylor expanded in a around inf 89.3%
*-commutative89.3%
Simplified89.3%
if -1.55e52 < a Initial program 98.9%
*-lft-identity98.9%
associate-*l/98.9%
associate-/r/98.9%
remove-double-neg98.9%
unsub-neg98.9%
div-sub93.0%
*-lft-identity93.0%
associate-*l/93.0%
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 94.9%
Final simplification93.4%
(FPCore (a b) :precision binary64 (if (<= b 2.5e+87) (/ 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 <= 2.5e+87) {
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 <= 2.5d+87) 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 <= 2.5e+87) {
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 <= 2.5e+87: 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 <= 2.5e+87) 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 <= 2.5e+87) 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, 2.5e+87], 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 2.5 \cdot 10^{+87}:\\
\;\;\;\;\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 < 2.4999999999999999e87Initial program 99.5%
*-lft-identity99.5%
associate-*l/99.5%
associate-/r/99.5%
remove-double-neg99.5%
unsub-neg99.5%
div-sub67.7%
*-lft-identity67.7%
associate-*l/67.7%
lft-mult-inverse99.5%
sub-neg99.5%
distribute-frac-neg99.5%
remove-double-neg99.5%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 76.3%
Taylor expanded in a around 0 68.3%
if 2.4999999999999999e87 < b Initial program 98.2%
*-lft-identity98.2%
associate-*l/98.2%
associate-/r/98.2%
remove-double-neg98.2%
unsub-neg98.2%
div-sub69.1%
*-lft-identity69.1%
associate-*l/69.1%
lft-mult-inverse98.2%
sub-neg98.2%
distribute-frac-neg98.2%
remove-double-neg98.2%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 90.4%
*-commutative90.4%
Simplified90.4%
Final simplification73.1%
(FPCore (a b) :precision binary64 (if (<= b 6e+150) (/ 1.0 (+ 2.0 (* a (+ (* a (+ 0.5 (* a -0.16666666666666666))) -1.0)))) (/ 1.0 (+ 2.0 (* b (* b 0.5))))))
double code(double a, double b) {
double tmp;
if (b <= 6e+150) {
tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0)));
} 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 <= 6d+150) then
tmp = 1.0d0 / (2.0d0 + (a * ((a * (0.5d0 + (a * (-0.16666666666666666d0)))) + (-1.0d0))))
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 <= 6e+150) {
tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0)));
} else {
tmp = 1.0 / (2.0 + (b * (b * 0.5)));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 6e+150: tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0))) else: tmp = 1.0 / (2.0 + (b * (b * 0.5))) return tmp
function code(a, b) tmp = 0.0 if (b <= 6e+150) 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(b * 0.5)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 6e+150) tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0))); else tmp = 1.0 / (2.0 + (b * (b * 0.5))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 6e+150], 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[(b * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 6 \cdot 10^{+150}:\\
\;\;\;\;\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(b \cdot 0.5\right)}\\
\end{array}
\end{array}
if b < 6.00000000000000025e150Initial program 99.5%
*-lft-identity99.5%
associate-*l/99.5%
associate-/r/99.5%
remove-double-neg99.5%
unsub-neg99.5%
div-sub68.6%
*-lft-identity68.6%
associate-*l/68.6%
lft-mult-inverse99.5%
sub-neg99.5%
distribute-frac-neg99.5%
remove-double-neg99.5%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 73.6%
Taylor expanded in a around 0 66.0%
if 6.00000000000000025e150 < b Initial program 97.8%
*-lft-identity97.8%
associate-*l/97.8%
associate-/r/97.8%
remove-double-neg97.8%
unsub-neg97.8%
div-sub65.2%
*-lft-identity65.2%
associate-*l/65.2%
lft-mult-inverse97.8%
sub-neg97.8%
distribute-frac-neg97.8%
remove-double-neg97.8%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 98.1%
Taylor expanded in b around inf 98.1%
Final simplification71.8%
(FPCore (a b) :precision binary64 (if (<= b 5.8e+150) (/ 1.0 (+ 2.0 (* a (+ (* a (* a -0.16666666666666666)) -1.0)))) (/ 1.0 (+ 2.0 (* b (* b 0.5))))))
double code(double a, double b) {
double tmp;
if (b <= 5.8e+150) {
tmp = 1.0 / (2.0 + (a * ((a * (a * -0.16666666666666666)) + -1.0)));
} 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 <= 5.8d+150) then
tmp = 1.0d0 / (2.0d0 + (a * ((a * (a * (-0.16666666666666666d0))) + (-1.0d0))))
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 <= 5.8e+150) {
tmp = 1.0 / (2.0 + (a * ((a * (a * -0.16666666666666666)) + -1.0)));
} else {
tmp = 1.0 / (2.0 + (b * (b * 0.5)));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 5.8e+150: tmp = 1.0 / (2.0 + (a * ((a * (a * -0.16666666666666666)) + -1.0))) else: tmp = 1.0 / (2.0 + (b * (b * 0.5))) return tmp
function code(a, b) tmp = 0.0 if (b <= 5.8e+150) 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(b * 0.5)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 5.8e+150) tmp = 1.0 / (2.0 + (a * ((a * (a * -0.16666666666666666)) + -1.0))); else tmp = 1.0 / (2.0 + (b * (b * 0.5))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 5.8e+150], 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[(b * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 5.8 \cdot 10^{+150}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(a \cdot \left(a \cdot -0.16666666666666666\right) + -1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(b \cdot 0.5\right)}\\
\end{array}
\end{array}
if b < 5.80000000000000022e150Initial program 99.5%
*-lft-identity99.5%
associate-*l/99.5%
associate-/r/99.5%
remove-double-neg99.5%
unsub-neg99.5%
div-sub68.6%
*-lft-identity68.6%
associate-*l/68.6%
lft-mult-inverse99.5%
sub-neg99.5%
distribute-frac-neg99.5%
remove-double-neg99.5%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 73.6%
Taylor expanded in a around 0 66.0%
Taylor expanded in a around inf 66.0%
*-commutative66.0%
Simplified66.0%
if 5.80000000000000022e150 < b Initial program 97.8%
*-lft-identity97.8%
associate-*l/97.8%
associate-/r/97.8%
remove-double-neg97.8%
unsub-neg97.8%
div-sub65.2%
*-lft-identity65.2%
associate-*l/65.2%
lft-mult-inverse97.8%
sub-neg97.8%
distribute-frac-neg97.8%
remove-double-neg97.8%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 98.1%
Taylor expanded in b around inf 98.1%
Final simplification71.7%
(FPCore (a b) :precision binary64 (if (<= b 3e+150) (/ 1.0 (+ 2.0 (* a (+ (* a 0.5) -1.0)))) (/ 1.0 (+ 2.0 (* b (* b 0.5))))))
double code(double a, double b) {
double tmp;
if (b <= 3e+150) {
tmp = 1.0 / (2.0 + (a * ((a * 0.5) + -1.0)));
} 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 <= 3d+150) then
tmp = 1.0d0 / (2.0d0 + (a * ((a * 0.5d0) + (-1.0d0))))
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 <= 3e+150) {
tmp = 1.0 / (2.0 + (a * ((a * 0.5) + -1.0)));
} else {
tmp = 1.0 / (2.0 + (b * (b * 0.5)));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 3e+150: tmp = 1.0 / (2.0 + (a * ((a * 0.5) + -1.0))) else: tmp = 1.0 / (2.0 + (b * (b * 0.5))) return tmp
function code(a, b) tmp = 0.0 if (b <= 3e+150) 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(b * 0.5)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 3e+150) tmp = 1.0 / (2.0 + (a * ((a * 0.5) + -1.0))); else tmp = 1.0 / (2.0 + (b * (b * 0.5))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 3e+150], 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[(b * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3 \cdot 10^{+150}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(a \cdot 0.5 + -1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(b \cdot 0.5\right)}\\
\end{array}
\end{array}
if b < 3.00000000000000012e150Initial program 99.5%
*-lft-identity99.5%
associate-*l/99.5%
associate-/r/99.5%
remove-double-neg99.5%
unsub-neg99.5%
div-sub68.6%
*-lft-identity68.6%
associate-*l/68.6%
lft-mult-inverse99.5%
sub-neg99.5%
distribute-frac-neg99.5%
remove-double-neg99.5%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 73.6%
Taylor expanded in a around 0 60.7%
if 3.00000000000000012e150 < b Initial program 97.8%
*-lft-identity97.8%
associate-*l/97.8%
associate-/r/97.8%
remove-double-neg97.8%
unsub-neg97.8%
div-sub65.2%
*-lft-identity65.2%
associate-*l/65.2%
lft-mult-inverse97.8%
sub-neg97.8%
distribute-frac-neg97.8%
remove-double-neg97.8%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 98.1%
Taylor expanded in b around inf 98.1%
Final simplification67.4%
(FPCore (a b) :precision binary64 (if (<= a -8.5e+136) (/ (/ -2.0 a) a) (/ 1.0 (+ 2.0 (* b (* b 0.5))))))
double code(double a, double b) {
double tmp;
if (a <= -8.5e+136) {
tmp = (-2.0 / a) / a;
} 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 (a <= (-8.5d+136)) then
tmp = ((-2.0d0) / a) / a
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 (a <= -8.5e+136) {
tmp = (-2.0 / a) / a;
} else {
tmp = 1.0 / (2.0 + (b * (b * 0.5)));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -8.5e+136: tmp = (-2.0 / a) / a else: tmp = 1.0 / (2.0 + (b * (b * 0.5))) return tmp
function code(a, b) tmp = 0.0 if (a <= -8.5e+136) tmp = Float64(Float64(-2.0 / a) / a); 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 (a <= -8.5e+136) tmp = (-2.0 / a) / a; else tmp = 1.0 / (2.0 + (b * (b * 0.5))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -8.5e+136], N[(N[(-2.0 / a), $MachinePrecision] / a), $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}\;a \leq -8.5 \cdot 10^{+136}:\\
\;\;\;\;\frac{\frac{-2}{a}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(b \cdot 0.5\right)}\\
\end{array}
\end{array}
if a < -8.49999999999999966e136Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
remove-double-neg100.0%
unsub-neg100.0%
div-sub0.0%
*-lft-identity0.0%
associate-*l/0.0%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 6.5%
neg-mul-16.5%
unsub-neg6.5%
Simplified6.5%
Taylor expanded in a around inf 6.5%
associate-*r/6.5%
neg-mul-16.5%
distribute-neg-in6.5%
metadata-eval6.5%
associate-*r/6.5%
metadata-eval6.5%
distribute-neg-frac6.5%
metadata-eval6.5%
Simplified6.5%
Taylor expanded in a around 0 88.4%
if -8.49999999999999966e136 < a Initial program 99.0%
*-lft-identity99.0%
associate-*l/99.0%
associate-/r/99.0%
remove-double-neg99.0%
unsub-neg99.0%
div-sub84.9%
*-lft-identity84.9%
associate-*l/84.9%
lft-mult-inverse99.0%
sub-neg99.0%
distribute-frac-neg99.0%
remove-double-neg99.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 89.2%
Taylor expanded in b around 0 58.4%
Taylor expanded in b around inf 58.2%
Final simplification64.2%
(FPCore (a b) :precision binary64 (if (<= a -750000000.0) (/ (/ -2.0 a) a) (/ 1.0 (- 2.0 a))))
double code(double a, double b) {
double tmp;
if (a <= -750000000.0) {
tmp = (-2.0 / a) / a;
} 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 (a <= (-750000000.0d0)) then
tmp = ((-2.0d0) / a) / a
else
tmp = 1.0d0 / (2.0d0 - a)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -750000000.0) {
tmp = (-2.0 / a) / a;
} else {
tmp = 1.0 / (2.0 - a);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -750000000.0: tmp = (-2.0 / a) / a else: tmp = 1.0 / (2.0 - a) return tmp
function code(a, b) tmp = 0.0 if (a <= -750000000.0) tmp = Float64(Float64(-2.0 / a) / a); else tmp = Float64(1.0 / Float64(2.0 - a)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -750000000.0) tmp = (-2.0 / a) / a; else tmp = 1.0 / (2.0 - a); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -750000000.0], N[(N[(-2.0 / a), $MachinePrecision] / a), $MachinePrecision], N[(1.0 / N[(2.0 - a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -750000000:\\
\;\;\;\;\frac{\frac{-2}{a}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 - a}\\
\end{array}
\end{array}
if a < -7.5e8Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
remove-double-neg100.0%
unsub-neg100.0%
div-sub0.0%
*-lft-identity0.0%
associate-*l/0.0%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 5.5%
neg-mul-15.5%
unsub-neg5.5%
Simplified5.5%
Taylor expanded in a around inf 5.5%
associate-*r/5.5%
neg-mul-15.5%
distribute-neg-in5.5%
metadata-eval5.5%
associate-*r/5.5%
metadata-eval5.5%
distribute-neg-frac5.5%
metadata-eval5.5%
Simplified5.5%
Taylor expanded in a around 0 58.8%
if -7.5e8 < a Initial program 98.9%
*-lft-identity98.9%
associate-*l/98.9%
associate-/r/98.8%
remove-double-neg98.8%
unsub-neg98.8%
div-sub98.3%
*-lft-identity98.3%
associate-*l/98.3%
lft-mult-inverse98.9%
sub-neg98.9%
distribute-frac-neg98.9%
remove-double-neg98.9%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 51.7%
Taylor expanded in a around 0 51.2%
neg-mul-151.2%
unsub-neg51.2%
Simplified51.2%
(FPCore (a b) :precision binary64 (/ 1.0 (- 2.0 a)))
double code(double a, double b) {
return 1.0 / (2.0 - a);
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (2.0d0 - a)
end function
public static double code(double a, double b) {
return 1.0 / (2.0 - a);
}
def code(a, b): return 1.0 / (2.0 - a)
function code(a, b) return Float64(1.0 / Float64(2.0 - a)) end
function tmp = code(a, b) tmp = 1.0 / (2.0 - a); end
code[a_, b_] := N[(1.0 / N[(2.0 - a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{2 - a}
\end{array}
Initial program 99.2%
*-lft-identity99.2%
associate-*l/99.2%
associate-/r/99.2%
remove-double-neg99.2%
unsub-neg99.2%
div-sub68.0%
*-lft-identity68.0%
associate-*l/68.0%
lft-mult-inverse99.2%
sub-neg99.2%
distribute-frac-neg99.2%
remove-double-neg99.2%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 66.6%
Taylor expanded in a around 0 37.1%
neg-mul-137.1%
unsub-neg37.1%
Simplified37.1%
(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%
*-lft-identity99.2%
associate-*l/99.2%
associate-/r/99.2%
remove-double-neg99.2%
unsub-neg99.2%
div-sub68.0%
*-lft-identity68.0%
associate-*l/68.0%
lft-mult-inverse99.2%
sub-neg99.2%
distribute-frac-neg99.2%
remove-double-neg99.2%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 76.6%
Taylor expanded in b around 0 36.1%
(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 2024152
(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))))