
(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 (exp (- (log1p (exp (- b a))))))
double code(double a, double b) {
return exp(-log1p(exp((b - a))));
}
public static double code(double a, double b) {
return Math.exp(-Math.log1p(Math.exp((b - a))));
}
def code(a, b): return math.exp(-math.log1p(math.exp((b - a))))
function code(a, b) return exp(Float64(-log1p(exp(Float64(b - a))))) end
code[a_, b_] := N[Exp[(-N[Log[1 + N[Exp[N[(b - a), $MachinePrecision]], $MachinePrecision]], $MachinePrecision])], $MachinePrecision]
\begin{array}{l}
\\
e^{-\mathsf{log1p}\left(e^{b - a}\right)}
\end{array}
Initial program 98.0%
*-lft-identity98.0%
associate-*l/98.0%
associate-/r/98.0%
metadata-eval98.0%
*-rgt-identity98.0%
associate-*r/98.0%
exp-neg98.0%
distribute-neg-frac98.0%
distribute-frac-neg298.0%
distribute-lft-neg-out98.0%
+-commutative98.0%
distribute-neg-in98.0%
sub-neg98.0%
*-commutative98.0%
sub-neg98.0%
distribute-neg-in98.0%
+-commutative98.0%
Simplified99.2%
add-exp-log99.2%
log-div0.0%
sub-neg0.0%
metadata-eval0.0%
distribute-neg-in0.0%
div-exp0.0%
log-div100.0%
metadata-eval100.0%
frac-2neg100.0%
div-exp99.2%
log-rec99.2%
log1p-define99.2%
div-exp100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (if (<= a -88000000.0) (/ (exp a) (+ a 2.0)) (if (<= a 1.75e-15) (/ 1.0 (+ 1.0 (exp b))) (/ 1.0 (+ 1.0 (exp (- a)))))))
double code(double a, double b) {
double tmp;
if (a <= -88000000.0) {
tmp = exp(a) / (a + 2.0);
} else if (a <= 1.75e-15) {
tmp = 1.0 / (1.0 + exp(b));
} else {
tmp = 1.0 / (1.0 + exp(-a));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-88000000.0d0)) then
tmp = exp(a) / (a + 2.0d0)
else if (a <= 1.75d-15) then
tmp = 1.0d0 / (1.0d0 + exp(b))
else
tmp = 1.0d0 / (1.0d0 + exp(-a))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -88000000.0) {
tmp = Math.exp(a) / (a + 2.0);
} else if (a <= 1.75e-15) {
tmp = 1.0 / (1.0 + Math.exp(b));
} else {
tmp = 1.0 / (1.0 + Math.exp(-a));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -88000000.0: tmp = math.exp(a) / (a + 2.0) elif a <= 1.75e-15: tmp = 1.0 / (1.0 + math.exp(b)) else: tmp = 1.0 / (1.0 + math.exp(-a)) return tmp
function code(a, b) tmp = 0.0 if (a <= -88000000.0) tmp = Float64(exp(a) / Float64(a + 2.0)); elseif (a <= 1.75e-15) tmp = Float64(1.0 / Float64(1.0 + exp(b))); else tmp = Float64(1.0 / Float64(1.0 + exp(Float64(-a)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -88000000.0) tmp = exp(a) / (a + 2.0); elseif (a <= 1.75e-15) tmp = 1.0 / (1.0 + exp(b)); else tmp = 1.0 / (1.0 + exp(-a)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -88000000.0], N[(N[Exp[a], $MachinePrecision] / N[(a + 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 1.75e-15], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[(-a)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -88000000:\\
\;\;\;\;\frac{e^{a}}{a + 2}\\
\mathbf{elif}\;a \leq 1.75 \cdot 10^{-15}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{-a}}\\
\end{array}
\end{array}
if a < -8.8e7Initial program 98.4%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 100.0%
+-commutative100.0%
Simplified100.0%
if -8.8e7 < a < 1.75e-15Initial program 99.4%
*-lft-identity99.4%
associate-*l/99.4%
associate-/r/99.4%
metadata-eval99.4%
*-rgt-identity99.4%
associate-*r/99.4%
exp-neg99.4%
distribute-neg-frac99.4%
distribute-frac-neg299.4%
distribute-lft-neg-out99.4%
+-commutative99.4%
distribute-neg-in99.4%
sub-neg99.4%
*-commutative99.4%
sub-neg99.4%
distribute-neg-in99.4%
+-commutative99.4%
Simplified99.4%
Taylor expanded in a around 0 99.2%
if 1.75e-15 < a Initial program 66.7%
*-lft-identity66.7%
associate-*l/66.7%
associate-/r/66.7%
metadata-eval66.7%
*-rgt-identity66.7%
associate-*r/66.7%
exp-neg66.5%
distribute-neg-frac66.5%
distribute-frac-neg266.5%
distribute-lft-neg-out66.5%
+-commutative66.5%
distribute-neg-in66.5%
sub-neg66.5%
*-commutative66.5%
sub-neg66.5%
distribute-neg-in66.5%
+-commutative66.5%
Simplified99.8%
Taylor expanded in b around 0 99.8%
rec-exp99.8%
Simplified99.8%
Final simplification99.5%
(FPCore (a b) :precision binary64 (if (<= a -3.3e+95) (/ 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 <= -3.3e+95) {
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 <= (-3.3d+95)) 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 <= -3.3e+95) {
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 <= -3.3e+95: 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 <= -3.3e+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(1.0 + exp(b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -3.3e+95) 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, -3.3e+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[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -3.3 \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}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -3.2999999999999998e95Initial 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 98.1%
if -3.2999999999999998e95 < a Initial program 97.6%
*-lft-identity97.6%
associate-*l/97.6%
associate-/r/97.5%
metadata-eval97.5%
*-rgt-identity97.5%
associate-*r/97.5%
exp-neg97.6%
distribute-neg-frac97.6%
distribute-frac-neg297.6%
distribute-lft-neg-out97.6%
+-commutative97.6%
distribute-neg-in97.6%
sub-neg97.6%
*-commutative97.6%
sub-neg97.6%
distribute-neg-in97.6%
+-commutative97.6%
Simplified99.0%
Taylor expanded in a around 0 92.1%
Final simplification93.2%
(FPCore (a b) :precision binary64 (if (<= a -88000000.0) (/ (exp a) (+ a 2.0)) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -88000000.0) {
tmp = exp(a) / (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 (a <= (-88000000.0d0)) then
tmp = exp(a) / (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 (a <= -88000000.0) {
tmp = Math.exp(a) / (a + 2.0);
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -88000000.0: tmp = math.exp(a) / (a + 2.0) else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (a <= -88000000.0) tmp = Float64(exp(a) / Float64(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 (a <= -88000000.0) tmp = exp(a) / (a + 2.0); else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -88000000.0], N[(N[Exp[a], $MachinePrecision] / N[(a + 2.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -88000000:\\
\;\;\;\;\frac{e^{a}}{a + 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -8.8e7Initial program 98.4%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 100.0%
+-commutative100.0%
Simplified100.0%
if -8.8e7 < a Initial program 97.9%
*-lft-identity97.9%
associate-*l/97.9%
associate-/r/97.9%
metadata-eval97.9%
*-rgt-identity97.9%
associate-*r/97.9%
exp-neg97.9%
distribute-neg-frac97.9%
distribute-frac-neg297.9%
distribute-lft-neg-out97.9%
+-commutative97.9%
distribute-neg-in97.9%
sub-neg97.9%
*-commutative97.9%
sub-neg97.9%
distribute-neg-in97.9%
+-commutative97.9%
Simplified99.4%
Taylor expanded in a around 0 97.0%
Final simplification97.7%
(FPCore (a b) :precision binary64 (/ 1.0 (+ (exp (- b a)) 1.0)))
double code(double a, double b) {
return 1.0 / (exp((b - a)) + 1.0);
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (exp((b - a)) + 1.0d0)
end function
public static double code(double a, double b) {
return 1.0 / (Math.exp((b - a)) + 1.0);
}
def code(a, b): return 1.0 / (math.exp((b - a)) + 1.0)
function code(a, b) return Float64(1.0 / Float64(exp(Float64(b - a)) + 1.0)) end
function tmp = code(a, b) tmp = 1.0 / (exp((b - a)) + 1.0); end
code[a_, b_] := N[(1.0 / N[(N[Exp[N[(b - a), $MachinePrecision]], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{e^{b - a} + 1}
\end{array}
Initial program 98.0%
*-lft-identity98.0%
associate-*l/98.0%
associate-/r/98.0%
remove-double-neg98.0%
unsub-neg98.0%
div-sub73.0%
*-lft-identity73.0%
associate-*l/73.0%
lft-mult-inverse99.2%
sub-neg99.2%
distribute-frac-neg99.2%
remove-double-neg99.2%
div-exp100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (if (<= b 1.4e+154) (/ 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 <= 1.4e+154) {
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 <= 1.4d+154) 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 <= 1.4e+154) {
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 <= 1.4e+154: 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 <= 1.4e+154) 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 <= 1.4e+154) 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, 1.4e+154], 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 1.4 \cdot 10^{+154}:\\
\;\;\;\;\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 < 1.4e154Initial program 97.8%
*-lft-identity97.8%
associate-*l/97.8%
associate-/r/97.8%
metadata-eval97.8%
*-rgt-identity97.8%
associate-*r/97.8%
exp-neg97.8%
distribute-neg-frac97.8%
distribute-frac-neg297.8%
distribute-lft-neg-out97.8%
+-commutative97.8%
distribute-neg-in97.8%
sub-neg97.8%
*-commutative97.8%
sub-neg97.8%
distribute-neg-in97.8%
+-commutative97.8%
Simplified99.1%
Taylor expanded in b around 0 74.5%
rec-exp74.5%
Simplified74.5%
Taylor expanded in a around 0 66.0%
if 1.4e154 < 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 simplification69.6%
(FPCore (a b) :precision binary64 (if (<= b 1.05e+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 <= 1.05e+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 <= 1.05d+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 <= 1.05e+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 <= 1.05e+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 <= 1.05e+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 <= 1.05e+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, 1.05e+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 1.05 \cdot 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 < 1.0500000000000001e103Initial program 97.7%
*-lft-identity97.7%
associate-*l/97.7%
associate-/r/97.7%
metadata-eval97.7%
*-rgt-identity97.7%
associate-*r/97.7%
exp-neg97.7%
distribute-neg-frac97.7%
distribute-frac-neg297.7%
distribute-lft-neg-out97.7%
+-commutative97.7%
distribute-neg-in97.7%
sub-neg97.7%
*-commutative97.7%
sub-neg97.7%
distribute-neg-in97.7%
+-commutative97.7%
Simplified99.0%
Taylor expanded in b around 0 76.3%
rec-exp76.3%
Simplified76.3%
Taylor expanded in a around 0 67.8%
if 1.0500000000000001e103 < 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 simplification72.6%
(FPCore (a b) :precision binary64 (if (<= b 4.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 <= 4.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 <= 4.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 <= 4.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 <= 4.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 <= 4.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 <= 4.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, 4.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 4.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 < 4.69999999999999968e153Initial program 97.8%
*-lft-identity97.8%
associate-*l/97.8%
associate-/r/97.8%
metadata-eval97.8%
*-rgt-identity97.8%
associate-*r/97.8%
exp-neg97.8%
distribute-neg-frac97.8%
distribute-frac-neg297.8%
distribute-lft-neg-out97.8%
+-commutative97.8%
distribute-neg-in97.8%
sub-neg97.8%
*-commutative97.8%
sub-neg97.8%
distribute-neg-in97.8%
+-commutative97.8%
Simplified99.1%
Taylor expanded in b around 0 74.5%
rec-exp74.5%
Simplified74.5%
Taylor expanded in a around 0 62.7%
if 4.69999999999999968e153 < 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 simplification66.6%
(FPCore (a b) :precision binary64 (if (<= b 1e+154) (/ 1.0 (+ 2.0 (- (* a (* a 0.5)) a))) (/ 1.0 (+ 2.0 (* b (+ 1.0 (* b 0.5)))))))
double code(double a, double b) {
double tmp;
if (b <= 1e+154) {
tmp = 1.0 / (2.0 + ((a * (a * 0.5)) - a));
} 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 <= 1d+154) then
tmp = 1.0d0 / (2.0d0 + ((a * (a * 0.5d0)) - a))
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 <= 1e+154) {
tmp = 1.0 / (2.0 + ((a * (a * 0.5)) - a));
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1e+154: tmp = 1.0 / (2.0 + ((a * (a * 0.5)) - a)) else: tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))) return tmp
function code(a, b) tmp = 0.0 if (b <= 1e+154) tmp = Float64(1.0 / Float64(2.0 + Float64(Float64(a * Float64(a * 0.5)) - a))); 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 <= 1e+154) tmp = 1.0 / (2.0 + ((a * (a * 0.5)) - a)); else tmp = 1.0 / (2.0 + (b * (1.0 + (b * 0.5)))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1e+154], N[(1.0 / N[(2.0 + N[(N[(a * N[(a * 0.5), $MachinePrecision]), $MachinePrecision] - a), $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 10^{+154}:\\
\;\;\;\;\frac{1}{2 + \left(a \cdot \left(a \cdot 0.5\right) - a\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + b \cdot 0.5\right)}\\
\end{array}
\end{array}
if b < 1.00000000000000004e154Initial program 97.8%
*-lft-identity97.8%
associate-*l/97.8%
associate-/r/97.8%
metadata-eval97.8%
*-rgt-identity97.8%
associate-*r/97.8%
exp-neg97.8%
distribute-neg-frac97.8%
distribute-frac-neg297.8%
distribute-lft-neg-out97.8%
+-commutative97.8%
distribute-neg-in97.8%
sub-neg97.8%
*-commutative97.8%
sub-neg97.8%
distribute-neg-in97.8%
+-commutative97.8%
Simplified99.1%
Taylor expanded in b around 0 74.5%
rec-exp74.5%
Simplified74.5%
Taylor expanded in a around 0 62.7%
sub-neg62.7%
metadata-eval62.7%
distribute-rgt-in62.7%
*-commutative62.7%
neg-mul-162.7%
Applied egg-rr62.7%
if 1.00000000000000004e154 < 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 simplification66.6%
(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.0%
*-lft-identity98.0%
associate-*l/98.0%
associate-/r/98.0%
metadata-eval98.0%
*-rgt-identity98.0%
associate-*r/98.0%
exp-neg98.0%
distribute-neg-frac98.0%
distribute-frac-neg298.0%
distribute-lft-neg-out98.0%
+-commutative98.0%
distribute-neg-in98.0%
sub-neg98.0%
*-commutative98.0%
sub-neg98.0%
distribute-neg-in98.0%
+-commutative98.0%
Simplified99.2%
Taylor expanded in b around 0 70.4%
rec-exp70.4%
Simplified70.4%
Taylor expanded in a around 0 58.7%
Final simplification58.7%
(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.0%
*-lft-identity98.0%
associate-*l/98.0%
associate-/r/98.0%
metadata-eval98.0%
*-rgt-identity98.0%
associate-*r/98.0%
exp-neg98.0%
distribute-neg-frac98.0%
distribute-frac-neg298.0%
distribute-lft-neg-out98.0%
+-commutative98.0%
distribute-neg-in98.0%
sub-neg98.0%
*-commutative98.0%
sub-neg98.0%
distribute-neg-in98.0%
+-commutative98.0%
Simplified99.2%
Taylor expanded in b around 0 70.4%
rec-exp70.4%
Simplified70.4%
Taylor expanded in a around 0 43.5%
*-commutative43.5%
Simplified43.5%
Final simplification43.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.0%
*-lft-identity98.0%
associate-*l/98.0%
associate-/r/98.0%
metadata-eval98.0%
*-rgt-identity98.0%
associate-*r/98.0%
exp-neg98.0%
distribute-neg-frac98.0%
distribute-frac-neg298.0%
distribute-lft-neg-out98.0%
+-commutative98.0%
distribute-neg-in98.0%
sub-neg98.0%
*-commutative98.0%
sub-neg98.0%
distribute-neg-in98.0%
+-commutative98.0%
Simplified99.2%
Taylor expanded in b around 0 70.4%
rec-exp70.4%
Simplified70.4%
Taylor expanded in a around 0 44.2%
neg-mul-144.2%
unsub-neg44.2%
Simplified44.2%
Final simplification44.2%
(FPCore (a b) :precision binary64 0.5)
double code(double a, double b) {
return 0.5;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 0.5d0
end function
public static double code(double a, double b) {
return 0.5;
}
def code(a, b): return 0.5
function code(a, b) return 0.5 end
function tmp = code(a, b) tmp = 0.5; end
code[a_, b_] := 0.5
\begin{array}{l}
\\
0.5
\end{array}
Initial program 98.0%
*-lft-identity98.0%
associate-*l/98.0%
associate-/r/98.0%
metadata-eval98.0%
*-rgt-identity98.0%
associate-*r/98.0%
exp-neg98.0%
distribute-neg-frac98.0%
distribute-frac-neg298.0%
distribute-lft-neg-out98.0%
+-commutative98.0%
distribute-neg-in98.0%
sub-neg98.0%
*-commutative98.0%
sub-neg98.0%
distribute-neg-in98.0%
+-commutative98.0%
Simplified99.2%
Taylor expanded in a around 0 80.7%
Taylor expanded in b around 0 43.3%
Final simplification43.3%
(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 2024095
(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))))