
(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 98.8%
*-lft-identity98.8%
associate-*l/98.8%
associate-/r/98.8%
remove-double-neg98.8%
unsub-neg98.8%
div-sub74.2%
*-lft-identity74.2%
associate-*l/74.2%
lft-mult-inverse99.6%
sub-neg99.6%
distribute-frac-neg99.6%
remove-double-neg99.6%
div-exp100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (if (<= a -0.053) (/ 1.0 (+ 1.0 (exp (- a)))) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -0.053) {
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 <= (-0.053d0)) 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 <= -0.053) {
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 <= -0.053: 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 <= -0.053) 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 <= -0.053) 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, -0.053], 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 -0.053:\\
\;\;\;\;\frac{1}{1 + e^{-a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -0.0529999999999999985Initial program 98.5%
*-lft-identity98.5%
associate-*l/98.5%
associate-/r/98.4%
remove-double-neg98.4%
unsub-neg98.4%
div-sub1.5%
*-lft-identity1.5%
associate-*l/1.5%
lft-mult-inverse98.4%
sub-neg98.4%
distribute-frac-neg98.4%
remove-double-neg98.4%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
if -0.0529999999999999985 < a Initial program 98.9%
*-lft-identity98.9%
associate-*l/98.9%
associate-/r/98.9%
remove-double-neg98.9%
unsub-neg98.9%
div-sub98.9%
*-lft-identity98.9%
associate-*l/98.9%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 98.2%
Final simplification98.7%
(FPCore (a b) :precision binary64 (if (<= a -9.5e+102) (/ 1.0 (+ 2.0 (* a (+ (* a (+ 0.5 (* a -0.16666666666666666))) -1.0)))) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -9.5e+102) {
tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (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 <= (-9.5d+102)) then
tmp = 1.0d0 / (2.0d0 + (a * ((a * (0.5d0 + (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 <= -9.5e+102) {
tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0)));
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -9.5e+102: tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (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 <= -9.5e+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(1.0 + exp(b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -9.5e+102) tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0))); else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -9.5e+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[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -9.5 \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}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -9.4999999999999992e102Initial program 97.4%
*-lft-identity97.4%
associate-*l/97.4%
associate-/r/97.4%
remove-double-neg97.4%
unsub-neg97.4%
div-sub0.0%
*-lft-identity0.0%
associate-*l/0.0%
lft-mult-inverse97.4%
sub-neg97.4%
distribute-frac-neg97.4%
remove-double-neg97.4%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 100.0%
if -9.4999999999999992e102 < a Initial program 99.1%
*-lft-identity99.1%
associate-*l/99.1%
associate-/r/99.1%
remove-double-neg99.1%
unsub-neg99.1%
div-sub87.5%
*-lft-identity87.5%
associate-*l/87.5%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 92.3%
Final simplification93.4%
(FPCore (a b)
:precision binary64
(let* ((t_0 (* b (* b 0.16666666666666666))))
(if (<= b 2.8e+77)
(/ 1.0 (+ 2.0 (* a (+ (* a (+ 0.5 (* a -0.16666666666666666))) -1.0))))
(if (<= b 1e+103)
(/
1.0
(+
2.0
(*
b
(+
1.0
(/ (- (* (* b 0.5) (* b 0.5)) (* t_0 t_0)) (- (* b 0.5) t_0))))))
(/
1.0
(+ 2.0 (* b (+ 1.0 (* b (+ 0.5 (* b 0.16666666666666666)))))))))))
double code(double a, double b) {
double t_0 = b * (b * 0.16666666666666666);
double tmp;
if (b <= 2.8e+77) {
tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0)));
} else if (b <= 1e+103) {
tmp = 1.0 / (2.0 + (b * (1.0 + ((((b * 0.5) * (b * 0.5)) - (t_0 * t_0)) / ((b * 0.5) - t_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) :: t_0
real(8) :: tmp
t_0 = b * (b * 0.16666666666666666d0)
if (b <= 2.8d+77) then
tmp = 1.0d0 / (2.0d0 + (a * ((a * (0.5d0 + (a * (-0.16666666666666666d0)))) + (-1.0d0))))
else if (b <= 1d+103) then
tmp = 1.0d0 / (2.0d0 + (b * (1.0d0 + ((((b * 0.5d0) * (b * 0.5d0)) - (t_0 * t_0)) / ((b * 0.5d0) - t_0)))))
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 t_0 = b * (b * 0.16666666666666666);
double tmp;
if (b <= 2.8e+77) {
tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0)));
} else if (b <= 1e+103) {
tmp = 1.0 / (2.0 + (b * (1.0 + ((((b * 0.5) * (b * 0.5)) - (t_0 * t_0)) / ((b * 0.5) - t_0)))));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
}
return tmp;
}
def code(a, b): t_0 = b * (b * 0.16666666666666666) tmp = 0 if b <= 2.8e+77: tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0))) elif b <= 1e+103: tmp = 1.0 / (2.0 + (b * (1.0 + ((((b * 0.5) * (b * 0.5)) - (t_0 * t_0)) / ((b * 0.5) - t_0))))) else: tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))) return tmp
function code(a, b) t_0 = Float64(b * Float64(b * 0.16666666666666666)) tmp = 0.0 if (b <= 2.8e+77) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(Float64(a * Float64(0.5 + Float64(a * -0.16666666666666666))) + -1.0)))); elseif (b <= 1e+103) tmp = Float64(1.0 / Float64(2.0 + Float64(b * Float64(1.0 + Float64(Float64(Float64(Float64(b * 0.5) * Float64(b * 0.5)) - Float64(t_0 * t_0)) / Float64(Float64(b * 0.5) - t_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) t_0 = b * (b * 0.16666666666666666); tmp = 0.0; if (b <= 2.8e+77) tmp = 1.0 / (2.0 + (a * ((a * (0.5 + (a * -0.16666666666666666))) + -1.0))); elseif (b <= 1e+103) tmp = 1.0 / (2.0 + (b * (1.0 + ((((b * 0.5) * (b * 0.5)) - (t_0 * t_0)) / ((b * 0.5) - t_0))))); else tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))); end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(b * N[(b * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 2.8e+77], 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], If[LessEqual[b, 1e+103], N[(1.0 / N[(2.0 + N[(b * N[(1.0 + N[(N[(N[(N[(b * 0.5), $MachinePrecision] * N[(b * 0.5), $MachinePrecision]), $MachinePrecision] - N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision] / N[(N[(b * 0.5), $MachinePrecision] - t$95$0), $MachinePrecision]), $MachinePrecision]), $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}
t_0 := b \cdot \left(b \cdot 0.16666666666666666\right)\\
\mathbf{if}\;b \leq 2.8 \cdot 10^{+77}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(a \cdot \left(0.5 + a \cdot -0.16666666666666666\right) + -1\right)}\\
\mathbf{elif}\;b \leq 10^{+103}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + \frac{\left(b \cdot 0.5\right) \cdot \left(b \cdot 0.5\right) - t\_0 \cdot t\_0}{b \cdot 0.5 - t\_0}\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.8e77Initial program 98.5%
*-lft-identity98.5%
associate-*l/98.5%
associate-/r/98.5%
remove-double-neg98.5%
unsub-neg98.5%
div-sub76.8%
*-lft-identity76.8%
associate-*l/76.8%
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 71.9%
Taylor expanded in a around 0 64.5%
if 2.8e77 < b < 1e103Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
remove-double-neg100.0%
unsub-neg100.0%
div-sub42.9%
*-lft-identity42.9%
associate-*l/42.9%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 8.6%
*-commutative8.6%
Simplified8.6%
distribute-lft-in8.6%
flip-+100.0%
Applied egg-rr100.0%
if 1e103 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
remove-double-neg100.0%
unsub-neg100.0%
div-sub67.4%
*-lft-identity67.4%
associate-*l/67.4%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
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 simplification71.9%
(FPCore (a b) :precision binary64 (if (<= b 3.6e+153) (/ 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 <= 3.6e+153) {
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 <= 3.6d+153) 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 <= 3.6e+153) {
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 <= 3.6e+153: 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 <= 3.6e+153) 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 <= 3.6e+153) 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, 3.6e+153], 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 3.6 \cdot 10^{+153}:\\
\;\;\;\;\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 < 3.6000000000000001e153Initial program 98.6%
*-lft-identity98.6%
associate-*l/98.6%
associate-/r/98.6%
remove-double-neg98.6%
unsub-neg98.6%
div-sub76.5%
*-lft-identity76.5%
associate-*l/76.5%
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 68.5%
Taylor expanded in a around 0 60.9%
if 3.6000000000000001e153 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
remove-double-neg100.0%
unsub-neg100.0%
div-sub60.0%
*-lft-identity60.0%
associate-*l/60.0%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
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 simplification66.2%
(FPCore (a b) :precision binary64 (if (<= b 1e+103) (/ 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 <= 1e+103) {
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 <= 1d+103) 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 <= 1e+103) {
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 <= 1e+103: 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 <= 1e+103) 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 <= 1e+103) 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, 1e+103], 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 10^{+103}:\\
\;\;\;\;\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 < 1e103Initial program 98.6%
*-lft-identity98.6%
associate-*l/98.6%
associate-/r/98.6%
remove-double-neg98.6%
unsub-neg98.6%
div-sub75.7%
*-lft-identity75.7%
associate-*l/75.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 71.5%
Taylor expanded in a around 0 63.4%
if 1e103 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
remove-double-neg100.0%
unsub-neg100.0%
div-sub67.4%
*-lft-identity67.4%
associate-*l/67.4%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
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 simplification70.0%
(FPCore (a b) :precision binary64 (if (<= b 2.7e+153) (/ 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 <= 2.7e+153) {
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 <= 2.7d+153) 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 <= 2.7e+153) {
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 <= 2.7e+153: 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 <= 2.7e+153) 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 <= 2.7e+153) 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, 2.7e+153], 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 2.7 \cdot 10^{+153}:\\
\;\;\;\;\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 < 2.7000000000000001e153Initial program 98.6%
*-lft-identity98.6%
associate-*l/98.6%
associate-/r/98.6%
remove-double-neg98.6%
unsub-neg98.6%
div-sub76.5%
*-lft-identity76.5%
associate-*l/76.5%
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 68.5%
Taylor expanded in a around 0 55.0%
if 2.7000000000000001e153 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
remove-double-neg100.0%
unsub-neg100.0%
div-sub60.0%
*-lft-identity60.0%
associate-*l/60.0%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
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 simplification61.2%
(FPCore (a b) :precision binary64 (/ 1.0 (+ 2.0 (* a (- (* a 0.5) -1.0)))))
double code(double a, double b) {
return 1.0 / (2.0 + (a * ((a * 0.5) - -1.0)));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (2.0d0 + (a * ((a * 0.5d0) - (-1.0d0))))
end function
public static double code(double a, double b) {
return 1.0 / (2.0 + (a * ((a * 0.5) - -1.0)));
}
def code(a, b): return 1.0 / (2.0 + (a * ((a * 0.5) - -1.0)))
function code(a, b) return Float64(1.0 / Float64(2.0 + Float64(a * Float64(Float64(a * 0.5) - -1.0)))) end
function tmp = code(a, b) tmp = 1.0 / (2.0 + (a * ((a * 0.5) - -1.0))); end
code[a_, b_] := N[(1.0 / N[(2.0 + N[(a * N[(N[(a * 0.5), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{2 + a \cdot \left(a \cdot 0.5 - -1\right)}
\end{array}
Initial program 98.8%
*-lft-identity98.8%
associate-*l/98.8%
associate-/r/98.8%
remove-double-neg98.8%
unsub-neg98.8%
div-sub74.2%
*-lft-identity74.2%
associate-*l/74.2%
lft-mult-inverse99.6%
sub-neg99.6%
distribute-frac-neg99.6%
remove-double-neg99.6%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 64.9%
Taylor expanded in a around 0 49.1%
sub-neg49.1%
distribute-rgt-in49.1%
*-commutative49.1%
metadata-eval49.1%
Applied egg-rr49.1%
mul-1-neg49.1%
unsub-neg49.1%
add-sqr-sqrt19.8%
sqrt-unprod39.3%
sqr-neg39.3%
mul-1-neg39.3%
mul-1-neg39.3%
sqrt-unprod28.9%
add-sqr-sqrt48.4%
distribute-rgt-out--48.4%
*-commutative48.4%
Applied egg-rr48.4%
Final simplification48.4%
(FPCore (a b) :precision binary64 (/ 1.0 (+ 2.0 (* a (+ (* a 0.5) -1.0)))))
double code(double a, double b) {
return 1.0 / (2.0 + (a * ((a * 0.5) + -1.0)));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (2.0d0 + (a * ((a * 0.5d0) + (-1.0d0))))
end function
public static double code(double a, double b) {
return 1.0 / (2.0 + (a * ((a * 0.5) + -1.0)));
}
def code(a, b): return 1.0 / (2.0 + (a * ((a * 0.5) + -1.0)))
function code(a, b) return Float64(1.0 / Float64(2.0 + Float64(a * Float64(Float64(a * 0.5) + -1.0)))) end
function tmp = code(a, b) tmp = 1.0 / (2.0 + (a * ((a * 0.5) + -1.0))); end
code[a_, b_] := N[(1.0 / N[(2.0 + N[(a * N[(N[(a * 0.5), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{2 + a \cdot \left(a \cdot 0.5 + -1\right)}
\end{array}
Initial program 98.8%
*-lft-identity98.8%
associate-*l/98.8%
associate-/r/98.8%
remove-double-neg98.8%
unsub-neg98.8%
div-sub74.2%
*-lft-identity74.2%
associate-*l/74.2%
lft-mult-inverse99.6%
sub-neg99.6%
distribute-frac-neg99.6%
remove-double-neg99.6%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 64.9%
Taylor expanded in a around 0 49.1%
Final simplification49.1%
(FPCore (a b) :precision binary64 (+ 0.5 (* a 0.25)))
double code(double a, double b) {
return 0.5 + (a * 0.25);
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 0.5d0 + (a * 0.25d0)
end function
public static double code(double a, double b) {
return 0.5 + (a * 0.25);
}
def code(a, b): return 0.5 + (a * 0.25)
function code(a, b) return Float64(0.5 + Float64(a * 0.25)) end
function tmp = code(a, b) tmp = 0.5 + (a * 0.25); end
code[a_, b_] := N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 + a \cdot 0.25
\end{array}
Initial program 98.8%
*-lft-identity98.8%
associate-*l/98.8%
associate-/r/98.8%
remove-double-neg98.8%
unsub-neg98.8%
div-sub74.2%
*-lft-identity74.2%
associate-*l/74.2%
lft-mult-inverse99.6%
sub-neg99.6%
distribute-frac-neg99.6%
remove-double-neg99.6%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 64.9%
Taylor expanded in a around 0 39.5%
Final simplification39.5%
(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 98.8%
*-lft-identity98.8%
associate-*l/98.8%
associate-/r/98.8%
remove-double-neg98.8%
unsub-neg98.8%
div-sub74.2%
*-lft-identity74.2%
associate-*l/74.2%
lft-mult-inverse99.6%
sub-neg99.6%
distribute-frac-neg99.6%
remove-double-neg99.6%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 64.9%
Taylor expanded in a around 0 39.9%
mul-1-neg39.9%
unsub-neg39.9%
Simplified39.9%
Final simplification39.9%
(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%
*-lft-identity98.8%
associate-*l/98.8%
associate-/r/98.8%
remove-double-neg98.8%
unsub-neg98.8%
div-sub74.2%
*-lft-identity74.2%
associate-*l/74.2%
lft-mult-inverse99.6%
sub-neg99.6%
distribute-frac-neg99.6%
remove-double-neg99.6%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 64.9%
Taylor expanded in a around 0 39.0%
Final simplification39.0%
(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 2024085
(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))))