
(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) (exp a)))))
double code(double a, double b) {
return -1.0 / (-1.0 - (exp(b) / exp(a)));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (-1.0d0) / ((-1.0d0) - (exp(b) / exp(a)))
end function
public static double code(double a, double b) {
return -1.0 / (-1.0 - (Math.exp(b) / Math.exp(a)));
}
def code(a, b): return -1.0 / (-1.0 - (math.exp(b) / math.exp(a)))
function code(a, b) return Float64(-1.0 / Float64(-1.0 - Float64(exp(b) / exp(a)))) end
function tmp = code(a, b) tmp = -1.0 / (-1.0 - (exp(b) / exp(a))); end
code[a_, b_] := N[(-1.0 / N[(-1.0 - N[(N[Exp[b], $MachinePrecision] / N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{-1 - \frac{e^{b}}{e^{a}}}
\end{array}
Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
metadata-eval100.0%
*-rgt-identity100.0%
associate-*r/100.0%
exp-neg100.0%
distribute-neg-frac100.0%
distribute-frac-neg2100.0%
distribute-lft-neg-out100.0%
+-commutative100.0%
distribute-neg-in100.0%
sub-neg100.0%
*-commutative100.0%
sub-neg100.0%
distribute-neg-in100.0%
+-commutative100.0%
Simplified100.0%
(FPCore (a b) :precision binary64 (if (<= a -880.0) (/ 1.0 (+ 1.0 (exp (- a)))) (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
double tmp;
if (a <= -880.0) {
tmp = 1.0 / (1.0 + exp(-a));
} else {
tmp = 1.0 / (exp(b) + 1.0);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-880.0d0)) then
tmp = 1.0d0 / (1.0d0 + exp(-a))
else
tmp = 1.0d0 / (exp(b) + 1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -880.0) {
tmp = 1.0 / (1.0 + Math.exp(-a));
} else {
tmp = 1.0 / (Math.exp(b) + 1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -880.0: tmp = 1.0 / (1.0 + math.exp(-a)) else: tmp = 1.0 / (math.exp(b) + 1.0) return tmp
function code(a, b) tmp = 0.0 if (a <= -880.0) tmp = Float64(1.0 / Float64(1.0 + exp(Float64(-a)))); else tmp = Float64(1.0 / Float64(exp(b) + 1.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -880.0) tmp = 1.0 / (1.0 + exp(-a)); else tmp = 1.0 / (exp(b) + 1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -880.0], N[(1.0 / N[(1.0 + N[Exp[(-a)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -880:\\
\;\;\;\;\frac{1}{1 + e^{-a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\
\end{array}
\end{array}
if a < -880Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
metadata-eval100.0%
*-rgt-identity100.0%
associate-*r/100.0%
exp-neg100.0%
distribute-neg-frac100.0%
distribute-frac-neg2100.0%
distribute-lft-neg-out100.0%
+-commutative100.0%
distribute-neg-in100.0%
sub-neg100.0%
*-commutative100.0%
sub-neg100.0%
distribute-neg-in100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
rec-exp100.0%
Simplified100.0%
if -880 < a Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
metadata-eval100.0%
*-rgt-identity100.0%
associate-*r/100.0%
exp-neg100.0%
distribute-neg-frac100.0%
distribute-frac-neg2100.0%
distribute-lft-neg-out100.0%
+-commutative100.0%
distribute-neg-in100.0%
sub-neg100.0%
*-commutative100.0%
sub-neg100.0%
distribute-neg-in100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in a around 0 99.2%
Final simplification99.4%
(FPCore (a b) :precision binary64 (if (<= a -3.1e+95) (/ 1.0 (+ 2.0 (* a (+ -1.0 (* a (* a -0.16666666666666666)))))) (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
double tmp;
if (a <= -3.1e+95) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (a * -0.16666666666666666)))));
} else {
tmp = 1.0 / (exp(b) + 1.0);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-3.1d+95)) then
tmp = 1.0d0 / (2.0d0 + (a * ((-1.0d0) + (a * (a * (-0.16666666666666666d0))))))
else
tmp = 1.0d0 / (exp(b) + 1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -3.1e+95) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (a * -0.16666666666666666)))));
} else {
tmp = 1.0 / (Math.exp(b) + 1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -3.1e+95: tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (a * -0.16666666666666666))))) else: tmp = 1.0 / (math.exp(b) + 1.0) return tmp
function code(a, b) tmp = 0.0 if (a <= -3.1e+95) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(-1.0 + Float64(a * Float64(a * -0.16666666666666666)))))); else tmp = Float64(1.0 / Float64(exp(b) + 1.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -3.1e+95) tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (a * -0.16666666666666666))))); else tmp = 1.0 / (exp(b) + 1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -3.1e+95], N[(1.0 / N[(2.0 + N[(a * N[(-1.0 + N[(a * N[(a * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -3.1 \cdot 10^{+95}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(-1 + a \cdot \left(a \cdot -0.16666666666666666\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\
\end{array}
\end{array}
if a < -3.1000000000000003e95Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
metadata-eval100.0%
*-rgt-identity100.0%
associate-*r/100.0%
exp-neg100.0%
distribute-neg-frac100.0%
distribute-frac-neg2100.0%
distribute-lft-neg-out100.0%
+-commutative100.0%
distribute-neg-in100.0%
sub-neg100.0%
*-commutative100.0%
sub-neg100.0%
distribute-neg-in100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
rec-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 91.2%
Taylor expanded in a around inf 91.2%
*-commutative91.2%
Simplified91.2%
if -3.1000000000000003e95 < a Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
metadata-eval100.0%
*-rgt-identity100.0%
associate-*r/100.0%
exp-neg100.0%
distribute-neg-frac100.0%
distribute-frac-neg2100.0%
distribute-lft-neg-out100.0%
+-commutative100.0%
distribute-neg-in100.0%
sub-neg100.0%
*-commutative100.0%
sub-neg100.0%
distribute-neg-in100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in a around 0 95.5%
Final simplification94.6%
(FPCore (a b) :precision binary64 (/ 1.0 (+ 1.0 (exp (- b a)))))
double code(double a, double b) {
return 1.0 / (1.0 + exp((b - a)));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (1.0d0 + exp((b - a)))
end function
public static double code(double a, double b) {
return 1.0 / (1.0 + Math.exp((b - a)));
}
def code(a, b): return 1.0 / (1.0 + math.exp((b - a)))
function code(a, b) return Float64(1.0 / Float64(1.0 + exp(Float64(b - a)))) end
function tmp = code(a, b) tmp = 1.0 / (1.0 + exp((b - a))); end
code[a_, b_] := N[(1.0 / N[(1.0 + N[Exp[N[(b - a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{1 + e^{b - a}}
\end{array}
Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
remove-double-neg100.0%
unsub-neg100.0%
div-sub76.2%
*-lft-identity76.2%
associate-*l/76.2%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
div-exp100.0%
Simplified100.0%
(FPCore (a b)
:precision binary64
(let* ((t_0 (* b (* b 0.16666666666666666))))
(if (<= b 2.8e+77)
(/ 1.0 (+ 2.0 (* a (+ -1.0 (* a (+ 0.5 (* a -0.16666666666666666)))))))
(if (<= b 2e+154)
(/
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)))))))))
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 * (-1.0 + (a * (0.5 + (a * -0.16666666666666666))))));
} else if (b <= 2e+154) {
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))));
}
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 * ((-1.0d0) + (a * (0.5d0 + (a * (-0.16666666666666666d0)))))))
else if (b <= 2d+154) 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))))
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 * (-1.0 + (a * (0.5 + (a * -0.16666666666666666))))));
} else if (b <= 2e+154) {
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))));
}
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 * (-1.0 + (a * (0.5 + (a * -0.16666666666666666)))))) elif b <= 2e+154: 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)))) 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(-1.0 + Float64(a * Float64(0.5 + Float64(a * -0.16666666666666666))))))); elseif (b <= 2e+154) 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 * 0.5))))); 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 * (-1.0 + (a * (0.5 + (a * -0.16666666666666666)))))); elseif (b <= 2e+154) 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)))); 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[(-1.0 + N[(a * N[(0.5 + N[(a * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2e+154], 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 * 0.5), $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(-1 + a \cdot \left(0.5 + a \cdot -0.16666666666666666\right)\right)}\\
\mathbf{elif}\;b \leq 2 \cdot 10^{+154}:\\
\;\;\;\;\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 0.5\right)}\\
\end{array}
\end{array}
if b < 2.8e77Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
metadata-eval100.0%
*-rgt-identity100.0%
associate-*r/100.0%
exp-neg100.0%
distribute-neg-frac100.0%
distribute-frac-neg2100.0%
distribute-lft-neg-out100.0%
+-commutative100.0%
distribute-neg-in100.0%
sub-neg100.0%
*-commutative100.0%
sub-neg100.0%
distribute-neg-in100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in b around 0 72.4%
rec-exp72.4%
Simplified72.4%
Taylor expanded in a around 0 65.9%
if 2.8e77 < b < 2.00000000000000007e154Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
metadata-eval100.0%
*-rgt-identity100.0%
associate-*r/100.0%
exp-neg100.0%
distribute-neg-frac100.0%
distribute-frac-neg2100.0%
distribute-lft-neg-out100.0%
+-commutative100.0%
distribute-neg-in100.0%
sub-neg100.0%
*-commutative100.0%
sub-neg100.0%
distribute-neg-in100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 64.2%
*-commutative64.2%
Simplified64.2%
distribute-lft-in64.2%
flip-+100.0%
Applied egg-rr100.0%
if 2.00000000000000007e154 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
metadata-eval100.0%
*-rgt-identity100.0%
associate-*r/100.0%
exp-neg100.0%
distribute-neg-frac100.0%
distribute-frac-neg2100.0%
distribute-lft-neg-out100.0%
+-commutative100.0%
distribute-neg-in100.0%
sub-neg100.0%
*-commutative100.0%
sub-neg100.0%
distribute-neg-in100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 100.0%
*-commutative100.0%
Simplified100.0%
Final simplification74.3%
(FPCore (a b) :precision binary64 (if (<= b 2.45e+99) (/ 1.0 (+ 2.0 (* a (+ -1.0 (* a (+ 0.5 (* a -0.16666666666666666))))))) (/ 1.0 (+ 2.0 (* b (+ 1.0 (* b (+ 0.5 (* b 0.16666666666666666)))))))))
double code(double a, double b) {
double tmp;
if (b <= 2.45e+99) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666))))));
} 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.45d+99) then
tmp = 1.0d0 / (2.0d0 + (a * ((-1.0d0) + (a * (0.5d0 + (a * (-0.16666666666666666d0)))))))
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.45e+99) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666))))));
} 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.45e+99: tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666)))))) 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.45e+99) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(-1.0 + Float64(a * Float64(0.5 + Float64(a * -0.16666666666666666))))))); 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.45e+99) tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666)))))); 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.45e+99], N[(1.0 / N[(2.0 + N[(a * N[(-1.0 + N[(a * N[(0.5 + N[(a * -0.16666666666666666), $MachinePrecision]), $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}
\mathbf{if}\;b \leq 2.45 \cdot 10^{+99}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(-1 + a \cdot \left(0.5 + a \cdot -0.16666666666666666\right)\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.4499999999999998e99Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
metadata-eval100.0%
*-rgt-identity100.0%
associate-*r/100.0%
exp-neg100.0%
distribute-neg-frac100.0%
distribute-frac-neg2100.0%
distribute-lft-neg-out100.0%
+-commutative100.0%
distribute-neg-in100.0%
sub-neg100.0%
*-commutative100.0%
sub-neg100.0%
distribute-neg-in100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in b around 0 70.7%
rec-exp70.6%
Simplified70.6%
Taylor expanded in a around 0 64.3%
if 2.4499999999999998e99 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
metadata-eval100.0%
*-rgt-identity100.0%
associate-*r/100.0%
exp-neg100.0%
distribute-neg-frac100.0%
distribute-frac-neg2100.0%
distribute-lft-neg-out100.0%
+-commutative100.0%
distribute-neg-in100.0%
sub-neg100.0%
*-commutative100.0%
sub-neg100.0%
distribute-neg-in100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 98.4%
*-commutative98.4%
Simplified98.4%
Final simplification71.6%
(FPCore (a b) :precision binary64 (if (<= b 2.2e+127) (/ 1.0 (+ 2.0 (* a (+ -1.0 (* a (+ 0.5 (* a -0.16666666666666666))))))) (/ 1.0 (+ 2.0 (* b (+ 1.0 (* b 0.5)))))))
double code(double a, double b) {
double tmp;
if (b <= 2.2e+127) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666))))));
} 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.2d+127) then
tmp = 1.0d0 / (2.0d0 + (a * ((-1.0d0) + (a * (0.5d0 + (a * (-0.16666666666666666d0)))))))
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.2e+127) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666))))));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 2.2e+127: tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666)))))) else: tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))) return tmp
function code(a, b) tmp = 0.0 if (b <= 2.2e+127) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(-1.0 + Float64(a * Float64(0.5 + Float64(a * -0.16666666666666666))))))); 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.2e+127) tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (0.5 + (a * -0.16666666666666666)))))); else tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 2.2e+127], N[(1.0 / N[(2.0 + N[(a * N[(-1.0 + N[(a * N[(0.5 + N[(a * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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.2 \cdot 10^{+127}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(-1 + a \cdot \left(0.5 + a \cdot -0.16666666666666666\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + b \cdot 0.5\right)}\\
\end{array}
\end{array}
if b < 2.2000000000000002e127Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
metadata-eval100.0%
*-rgt-identity100.0%
associate-*r/100.0%
exp-neg100.0%
distribute-neg-frac100.0%
distribute-frac-neg2100.0%
distribute-lft-neg-out100.0%
+-commutative100.0%
distribute-neg-in100.0%
sub-neg100.0%
*-commutative100.0%
sub-neg100.0%
distribute-neg-in100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in b around 0 69.8%
rec-exp69.8%
Simplified69.8%
Taylor expanded in a around 0 63.7%
if 2.2000000000000002e127 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
metadata-eval100.0%
*-rgt-identity100.0%
associate-*r/100.0%
exp-neg100.0%
distribute-neg-frac100.0%
distribute-frac-neg2100.0%
distribute-lft-neg-out100.0%
+-commutative100.0%
distribute-neg-in100.0%
sub-neg100.0%
*-commutative100.0%
sub-neg100.0%
distribute-neg-in100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 85.0%
*-commutative85.0%
Simplified85.0%
Final simplification67.7%
(FPCore (a b) :precision binary64 (if (<= b 9.5e+128) (/ 1.0 (+ 2.0 (* a (+ -1.0 (* a (* a -0.16666666666666666)))))) (/ 1.0 (+ 2.0 (* b (+ 1.0 (* b 0.5)))))))
double code(double a, double b) {
double tmp;
if (b <= 9.5e+128) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (a * -0.16666666666666666)))));
} 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 <= 9.5d+128) then
tmp = 1.0d0 / (2.0d0 + (a * ((-1.0d0) + (a * (a * (-0.16666666666666666d0))))))
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 <= 9.5e+128) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (a * -0.16666666666666666)))));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 9.5e+128: tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (a * -0.16666666666666666))))) else: tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))) return tmp
function code(a, b) tmp = 0.0 if (b <= 9.5e+128) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(-1.0 + Float64(a * Float64(a * -0.16666666666666666)))))); 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 <= 9.5e+128) tmp = 1.0 / (2.0 + (a * (-1.0 + (a * (a * -0.16666666666666666))))); else tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 9.5e+128], N[(1.0 / N[(2.0 + N[(a * N[(-1.0 + N[(a * N[(a * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $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 9.5 \cdot 10^{+128}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(-1 + a \cdot \left(a \cdot -0.16666666666666666\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + b \cdot 0.5\right)}\\
\end{array}
\end{array}
if b < 9.50000000000000014e128Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
metadata-eval100.0%
*-rgt-identity100.0%
associate-*r/100.0%
exp-neg100.0%
distribute-neg-frac100.0%
distribute-frac-neg2100.0%
distribute-lft-neg-out100.0%
+-commutative100.0%
distribute-neg-in100.0%
sub-neg100.0%
*-commutative100.0%
sub-neg100.0%
distribute-neg-in100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in b around 0 69.8%
rec-exp69.8%
Simplified69.8%
Taylor expanded in a around 0 63.7%
Taylor expanded in a around inf 63.4%
*-commutative63.4%
Simplified63.4%
if 9.50000000000000014e128 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
metadata-eval100.0%
*-rgt-identity100.0%
associate-*r/100.0%
exp-neg100.0%
distribute-neg-frac100.0%
distribute-frac-neg2100.0%
distribute-lft-neg-out100.0%
+-commutative100.0%
distribute-neg-in100.0%
sub-neg100.0%
*-commutative100.0%
sub-neg100.0%
distribute-neg-in100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 85.0%
*-commutative85.0%
Simplified85.0%
Final simplification67.5%
(FPCore (a b) :precision binary64 (if (<= b 1.2e+128) (/ 1.0 (+ 2.0 (* a (+ -1.0 (* a 0.5))))) (/ 1.0 (+ 2.0 (* b (+ 1.0 (* b 0.5)))))))
double code(double a, double b) {
double tmp;
if (b <= 1.2e+128) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * 0.5))));
} 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 <= 1.2d+128) then
tmp = 1.0d0 / (2.0d0 + (a * ((-1.0d0) + (a * 0.5d0))))
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 <= 1.2e+128) {
tmp = 1.0 / (2.0 + (a * (-1.0 + (a * 0.5))));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.2e+128: tmp = 1.0 / (2.0 + (a * (-1.0 + (a * 0.5)))) else: tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.2e+128) tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(-1.0 + Float64(a * 0.5))))); 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 <= 1.2e+128) tmp = 1.0 / (2.0 + (a * (-1.0 + (a * 0.5)))); else tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.2e+128], N[(1.0 / N[(2.0 + N[(a * N[(-1.0 + N[(a * 0.5), $MachinePrecision]), $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 1.2 \cdot 10^{+128}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(-1 + a \cdot 0.5\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + b \cdot 0.5\right)}\\
\end{array}
\end{array}
if b < 1.2000000000000001e128Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
metadata-eval100.0%
*-rgt-identity100.0%
associate-*r/100.0%
exp-neg100.0%
distribute-neg-frac100.0%
distribute-frac-neg2100.0%
distribute-lft-neg-out100.0%
+-commutative100.0%
distribute-neg-in100.0%
sub-neg100.0%
*-commutative100.0%
sub-neg100.0%
distribute-neg-in100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in b around 0 69.8%
rec-exp69.8%
Simplified69.8%
Taylor expanded in a around 0 59.1%
if 1.2000000000000001e128 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
metadata-eval100.0%
*-rgt-identity100.0%
associate-*r/100.0%
exp-neg100.0%
distribute-neg-frac100.0%
distribute-frac-neg2100.0%
distribute-lft-neg-out100.0%
+-commutative100.0%
distribute-neg-in100.0%
sub-neg100.0%
*-commutative100.0%
sub-neg100.0%
distribute-neg-in100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 85.0%
*-commutative85.0%
Simplified85.0%
Final simplification64.0%
(FPCore (a b) :precision binary64 (/ 1.0 (+ 2.0 (* a (+ -1.0 (* a 0.5))))))
double code(double a, double b) {
return 1.0 / (2.0 + (a * (-1.0 + (a * 0.5))));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (2.0d0 + (a * ((-1.0d0) + (a * 0.5d0))))
end function
public static double code(double a, double b) {
return 1.0 / (2.0 + (a * (-1.0 + (a * 0.5))));
}
def code(a, b): return 1.0 / (2.0 + (a * (-1.0 + (a * 0.5))))
function code(a, b) return Float64(1.0 / Float64(2.0 + Float64(a * Float64(-1.0 + Float64(a * 0.5))))) end
function tmp = code(a, b) tmp = 1.0 / (2.0 + (a * (-1.0 + (a * 0.5)))); end
code[a_, b_] := N[(1.0 / N[(2.0 + N[(a * N[(-1.0 + N[(a * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{2 + a \cdot \left(-1 + a \cdot 0.5\right)}
\end{array}
Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
metadata-eval100.0%
*-rgt-identity100.0%
associate-*r/100.0%
exp-neg100.0%
distribute-neg-frac100.0%
distribute-frac-neg2100.0%
distribute-lft-neg-out100.0%
+-commutative100.0%
distribute-neg-in100.0%
sub-neg100.0%
*-commutative100.0%
sub-neg100.0%
distribute-neg-in100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in b around 0 61.4%
rec-exp61.4%
Simplified61.4%
Taylor expanded in a around 0 51.7%
Final simplification51.7%
(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 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
metadata-eval100.0%
*-rgt-identity100.0%
associate-*r/100.0%
exp-neg100.0%
distribute-neg-frac100.0%
distribute-frac-neg2100.0%
distribute-lft-neg-out100.0%
+-commutative100.0%
distribute-neg-in100.0%
sub-neg100.0%
*-commutative100.0%
sub-neg100.0%
distribute-neg-in100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in b around 0 61.4%
rec-exp61.4%
Simplified61.4%
Taylor expanded in a around 0 38.6%
neg-mul-138.6%
unsub-neg38.6%
Simplified38.6%
(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 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
metadata-eval100.0%
*-rgt-identity100.0%
associate-*r/100.0%
exp-neg100.0%
distribute-neg-frac100.0%
distribute-frac-neg2100.0%
distribute-lft-neg-out100.0%
+-commutative100.0%
distribute-neg-in100.0%
sub-neg100.0%
*-commutative100.0%
sub-neg100.0%
distribute-neg-in100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in b around 0 61.4%
rec-exp61.4%
Simplified61.4%
Taylor expanded in a around 0 37.9%
*-commutative37.9%
Simplified37.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 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
metadata-eval100.0%
*-rgt-identity100.0%
associate-*r/100.0%
exp-neg100.0%
distribute-neg-frac100.0%
distribute-frac-neg2100.0%
distribute-lft-neg-out100.0%
+-commutative100.0%
distribute-neg-in100.0%
sub-neg100.0%
*-commutative100.0%
sub-neg100.0%
distribute-neg-in100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in a around 0 85.4%
Taylor expanded in b around 0 37.6%
(FPCore (a b) :precision binary64 (/ 1.0 (+ 1.0 (exp (- b a)))))
double code(double a, double b) {
return 1.0 / (1.0 + exp((b - a)));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (1.0d0 + exp((b - a)))
end function
public static double code(double a, double b) {
return 1.0 / (1.0 + Math.exp((b - a)));
}
def code(a, b): return 1.0 / (1.0 + math.exp((b - a)))
function code(a, b) return Float64(1.0 / Float64(1.0 + exp(Float64(b - a)))) end
function tmp = code(a, b) tmp = 1.0 / (1.0 + exp((b - a))); end
code[a_, b_] := N[(1.0 / N[(1.0 + N[Exp[N[(b - a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{1 + e^{b - a}}
\end{array}
herbie shell --seed 2024172
(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))))