
(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 14 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 99.6%
*-lft-identity99.6%
associate-*l/99.6%
associate-/r/99.6%
remove-double-neg99.6%
unsub-neg99.6%
div-sub70.7%
*-lft-identity70.7%
associate-*l/70.7%
lft-mult-inverse99.6%
sub-neg99.6%
distribute-frac-neg99.6%
remove-double-neg99.6%
div-exp100.0%
Simplified100.0%
add-exp-log100.0%
log-rec100.0%
log1p-define100.0%
Applied egg-rr100.0%
(FPCore (a b) :precision binary64 (if (<= (exp a) 0.0) (/ (exp a) 2.0) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.0) {
tmp = exp(a) / 2.0;
} else {
tmp = 1.0 / (1.0 + exp(b));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (exp(a) <= 0.0d0) then
tmp = exp(a) / 2.0d0
else
tmp = 1.0d0 / (1.0d0 + exp(b))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 0.0) {
tmp = Math.exp(a) / 2.0;
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(a) <= 0.0: tmp = math.exp(a) / 2.0 else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (exp(a) <= 0.0) tmp = Float64(exp(a) / 2.0); else tmp = Float64(1.0 / Float64(1.0 + exp(b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (exp(a) <= 0.0) tmp = exp(a) / 2.0; else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.0], N[(N[Exp[a], $MachinePrecision] / 2.0), $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0:\\
\;\;\;\;\frac{e^{a}}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.0Initial program 98.7%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
if 0.0 < (exp.f64 a) Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
remove-double-neg100.0%
unsub-neg100.0%
div-sub100.0%
*-lft-identity100.0%
associate-*l/100.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 98.2%
(FPCore (a b)
:precision binary64
(if (<= b -390000000.0)
1.0
(if (<= b 1.2e+93)
(/ (exp a) 2.0)
(/ 1.0 (+ 2.0 (* b (+ 1.0 (* b (+ 0.5 (* b 0.16666666666666666))))))))))
double code(double a, double b) {
double tmp;
if (b <= -390000000.0) {
tmp = 1.0;
} else if (b <= 1.2e+93) {
tmp = exp(a) / 2.0;
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= (-390000000.0d0)) then
tmp = 1.0d0
else if (b <= 1.2d+93) then
tmp = exp(a) / 2.0d0
else
tmp = 1.0d0 / (2.0d0 + (b * (1.0d0 + (b * (0.5d0 + (b * 0.16666666666666666d0))))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -390000000.0) {
tmp = 1.0;
} else if (b <= 1.2e+93) {
tmp = Math.exp(a) / 2.0;
} else {
tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666))))));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -390000000.0: tmp = 1.0 elif b <= 1.2e+93: tmp = math.exp(a) / 2.0 else: tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))) return tmp
function code(a, b) tmp = 0.0 if (b <= -390000000.0) tmp = 1.0; elseif (b <= 1.2e+93) tmp = Float64(exp(a) / 2.0); else tmp = Float64(1.0 / Float64(2.0 + Float64(b * Float64(1.0 + Float64(b * Float64(0.5 + Float64(b * 0.16666666666666666))))))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -390000000.0) tmp = 1.0; elseif (b <= 1.2e+93) tmp = exp(a) / 2.0; else tmp = 1.0 / (2.0 + (b * (1.0 + (b * (0.5 + (b * 0.16666666666666666)))))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -390000000.0], 1.0, If[LessEqual[b, 1.2e+93], N[(N[Exp[a], $MachinePrecision] / 2.0), $MachinePrecision], N[(1.0 / N[(2.0 + N[(b * N[(1.0 + N[(b * N[(0.5 + N[(b * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -390000000:\\
\;\;\;\;1\\
\mathbf{elif}\;b \leq 1.2 \cdot 10^{+93}:\\
\;\;\;\;\frac{e^{a}}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + b \cdot \left(1 + b \cdot \left(0.5 + b \cdot 0.16666666666666666\right)\right)}\\
\end{array}
\end{array}
if b < -3.9e8Initial program 100.0%
Taylor expanded in b around 0 18.6%
Taylor expanded in a around 0 18.1%
+-commutative18.1%
Simplified18.1%
Taylor expanded in a around 0 19.1%
Taylor expanded in a around inf 100.0%
if -3.9e8 < b < 1.20000000000000005e93Initial program 99.4%
Taylor expanded in b around 0 85.8%
Taylor expanded in a around 0 84.3%
+-commutative84.3%
Simplified84.3%
Taylor expanded in a around 0 84.0%
if 1.20000000000000005e93 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
remove-double-neg100.0%
unsub-neg100.0%
div-sub62.5%
*-lft-identity62.5%
associate-*l/62.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 100.0%
Taylor expanded in b around 0 94.3%
*-commutative94.3%
Simplified94.3%
(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 99.6%
*-lft-identity99.6%
associate-*l/99.6%
associate-/r/99.6%
remove-double-neg99.6%
unsub-neg99.6%
div-sub70.7%
*-lft-identity70.7%
associate-*l/70.7%
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 (<= b -390000000.0)
1.0
(if (<= b 1.2e+93)
(/ 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 <= -390000000.0) {
tmp = 1.0;
} else if (b <= 1.2e+93) {
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 <= (-390000000.0d0)) then
tmp = 1.0d0
else if (b <= 1.2d+93) 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 <= -390000000.0) {
tmp = 1.0;
} else if (b <= 1.2e+93) {
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 <= -390000000.0: tmp = 1.0 elif b <= 1.2e+93: 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 <= -390000000.0) tmp = 1.0; elseif (b <= 1.2e+93) 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 <= -390000000.0) tmp = 1.0; elseif (b <= 1.2e+93) 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, -390000000.0], 1.0, If[LessEqual[b, 1.2e+93], 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 -390000000:\\
\;\;\;\;1\\
\mathbf{elif}\;b \leq 1.2 \cdot 10^{+93}:\\
\;\;\;\;\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 < -3.9e8Initial program 100.0%
Taylor expanded in b around 0 18.6%
Taylor expanded in a around 0 18.1%
+-commutative18.1%
Simplified18.1%
Taylor expanded in a around 0 19.1%
Taylor expanded in a around inf 100.0%
if -3.9e8 < b < 1.20000000000000005e93Initial program 99.4%
*-lft-identity99.4%
associate-*l/99.4%
associate-/r/99.4%
remove-double-neg99.4%
unsub-neg99.4%
div-sub68.0%
*-lft-identity68.0%
associate-*l/68.0%
lft-mult-inverse99.4%
sub-neg99.4%
distribute-frac-neg99.4%
remove-double-neg99.4%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 85.8%
Taylor expanded in a around 0 75.3%
if 1.20000000000000005e93 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
remove-double-neg100.0%
unsub-neg100.0%
div-sub62.5%
*-lft-identity62.5%
associate-*l/62.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 100.0%
Taylor expanded in b around 0 94.3%
*-commutative94.3%
Simplified94.3%
Final simplification81.8%
(FPCore (a b)
:precision binary64
(if (<= b -390000000.0)
1.0
(if (<= b 1.6e+128)
(/ 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 <= -390000000.0) {
tmp = 1.0;
} else if (b <= 1.6e+128) {
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 <= (-390000000.0d0)) then
tmp = 1.0d0
else if (b <= 1.6d+128) 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 <= -390000000.0) {
tmp = 1.0;
} else if (b <= 1.6e+128) {
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 <= -390000000.0: tmp = 1.0 elif b <= 1.6e+128: 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 <= -390000000.0) tmp = 1.0; elseif (b <= 1.6e+128) 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 <= -390000000.0) tmp = 1.0; elseif (b <= 1.6e+128) 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, -390000000.0], 1.0, If[LessEqual[b, 1.6e+128], 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 -390000000:\\
\;\;\;\;1\\
\mathbf{elif}\;b \leq 1.6 \cdot 10^{+128}:\\
\;\;\;\;\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.9e8Initial program 100.0%
Taylor expanded in b around 0 18.6%
Taylor expanded in a around 0 18.1%
+-commutative18.1%
Simplified18.1%
Taylor expanded in a around 0 19.1%
Taylor expanded in a around inf 100.0%
if -3.9e8 < b < 1.59999999999999993e128Initial program 99.5%
*-lft-identity99.5%
associate-*l/99.5%
associate-/r/99.4%
remove-double-neg99.4%
unsub-neg99.4%
div-sub68.1%
*-lft-identity68.1%
associate-*l/68.1%
lft-mult-inverse99.4%
sub-neg99.4%
distribute-frac-neg99.4%
remove-double-neg99.4%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 82.9%
Taylor expanded in a around 0 72.5%
if 1.59999999999999993e128 < 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.5%
*-lft-identity60.5%
associate-*l/60.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 100.0%
Taylor expanded in b around 0 93.0%
*-commutative93.0%
Simplified93.0%
Final simplification78.8%
(FPCore (a b)
:precision binary64
(if (<= b -390000000.0)
1.0
(if (<= b 1.65e+128)
(/ 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 <= -390000000.0) {
tmp = 1.0;
} else if (b <= 1.65e+128) {
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 <= (-390000000.0d0)) then
tmp = 1.0d0
else if (b <= 1.65d+128) 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 <= -390000000.0) {
tmp = 1.0;
} else if (b <= 1.65e+128) {
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 <= -390000000.0: tmp = 1.0 elif b <= 1.65e+128: 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 <= -390000000.0) tmp = 1.0; elseif (b <= 1.65e+128) 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 <= -390000000.0) tmp = 1.0; elseif (b <= 1.65e+128) 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, -390000000.0], 1.0, If[LessEqual[b, 1.65e+128], 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 -390000000:\\
\;\;\;\;1\\
\mathbf{elif}\;b \leq 1.65 \cdot 10^{+128}:\\
\;\;\;\;\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 < -3.9e8Initial program 100.0%
Taylor expanded in b around 0 18.6%
Taylor expanded in a around 0 18.1%
+-commutative18.1%
Simplified18.1%
Taylor expanded in a around 0 19.1%
Taylor expanded in a around inf 100.0%
if -3.9e8 < b < 1.65e128Initial program 99.5%
*-lft-identity99.5%
associate-*l/99.5%
associate-/r/99.4%
remove-double-neg99.4%
unsub-neg99.4%
div-sub68.1%
*-lft-identity68.1%
associate-*l/68.1%
lft-mult-inverse99.4%
sub-neg99.4%
distribute-frac-neg99.4%
remove-double-neg99.4%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 82.9%
Taylor expanded in a around 0 66.3%
if 1.65e128 < 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.5%
*-lft-identity60.5%
associate-*l/60.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 100.0%
Taylor expanded in b around 0 93.0%
*-commutative93.0%
Simplified93.0%
Final simplification74.2%
(FPCore (a b) :precision binary64 (if (<= b -390000000.0) 1.0 (/ 1.0 (+ 2.0 (* a (+ (* a 0.5) -1.0))))))
double code(double a, double b) {
double tmp;
if (b <= -390000000.0) {
tmp = 1.0;
} else {
tmp = 1.0 / (2.0 + (a * ((a * 0.5) + -1.0)));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= (-390000000.0d0)) then
tmp = 1.0d0
else
tmp = 1.0d0 / (2.0d0 + (a * ((a * 0.5d0) + (-1.0d0))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -390000000.0) {
tmp = 1.0;
} else {
tmp = 1.0 / (2.0 + (a * ((a * 0.5) + -1.0)));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -390000000.0: tmp = 1.0 else: tmp = 1.0 / (2.0 + (a * ((a * 0.5) + -1.0))) return tmp
function code(a, b) tmp = 0.0 if (b <= -390000000.0) tmp = 1.0; else tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(Float64(a * 0.5) + -1.0)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -390000000.0) tmp = 1.0; else tmp = 1.0 / (2.0 + (a * ((a * 0.5) + -1.0))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -390000000.0], 1.0, N[(1.0 / N[(2.0 + N[(a * N[(N[(a * 0.5), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -390000000:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(a \cdot 0.5 + -1\right)}\\
\end{array}
\end{array}
if b < -3.9e8Initial program 100.0%
Taylor expanded in b around 0 18.6%
Taylor expanded in a around 0 18.1%
+-commutative18.1%
Simplified18.1%
Taylor expanded in a around 0 19.1%
Taylor expanded in a around inf 100.0%
if -3.9e8 < b Initial program 99.6%
*-lft-identity99.6%
associate-*l/99.6%
associate-/r/99.5%
remove-double-neg99.5%
unsub-neg99.5%
div-sub66.8%
*-lft-identity66.8%
associate-*l/66.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 75.9%
Taylor expanded in a around 0 60.0%
Final simplification64.7%
(FPCore (a b) :precision binary64 (if (<= b -390000000.0) 1.0 (/ 1.0 (+ 2.0 (* a (* a 0.5))))))
double code(double a, double b) {
double tmp;
if (b <= -390000000.0) {
tmp = 1.0;
} else {
tmp = 1.0 / (2.0 + (a * (a * 0.5)));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= (-390000000.0d0)) then
tmp = 1.0d0
else
tmp = 1.0d0 / (2.0d0 + (a * (a * 0.5d0)))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -390000000.0) {
tmp = 1.0;
} else {
tmp = 1.0 / (2.0 + (a * (a * 0.5)));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -390000000.0: tmp = 1.0 else: tmp = 1.0 / (2.0 + (a * (a * 0.5))) return tmp
function code(a, b) tmp = 0.0 if (b <= -390000000.0) tmp = 1.0; else tmp = Float64(1.0 / Float64(2.0 + Float64(a * Float64(a * 0.5)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -390000000.0) tmp = 1.0; else tmp = 1.0 / (2.0 + (a * (a * 0.5))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -390000000.0], 1.0, N[(1.0 / N[(2.0 + N[(a * N[(a * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -390000000:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 + a \cdot \left(a \cdot 0.5\right)}\\
\end{array}
\end{array}
if b < -3.9e8Initial program 100.0%
Taylor expanded in b around 0 18.6%
Taylor expanded in a around 0 18.1%
+-commutative18.1%
Simplified18.1%
Taylor expanded in a around 0 19.1%
Taylor expanded in a around inf 100.0%
if -3.9e8 < b Initial program 99.6%
*-lft-identity99.6%
associate-*l/99.6%
associate-/r/99.5%
remove-double-neg99.5%
unsub-neg99.5%
div-sub66.8%
*-lft-identity66.8%
associate-*l/66.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 75.9%
Taylor expanded in a around 0 60.0%
Taylor expanded in a around inf 59.4%
Final simplification64.2%
(FPCore (a b) :precision binary64 (if (<= b -390000000.0) 1.0 (/ 1.0 (- 2.0 a))))
double code(double a, double b) {
double tmp;
if (b <= -390000000.0) {
tmp = 1.0;
} else {
tmp = 1.0 / (2.0 - a);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= (-390000000.0d0)) then
tmp = 1.0d0
else
tmp = 1.0d0 / (2.0d0 - a)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -390000000.0) {
tmp = 1.0;
} else {
tmp = 1.0 / (2.0 - a);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -390000000.0: tmp = 1.0 else: tmp = 1.0 / (2.0 - a) return tmp
function code(a, b) tmp = 0.0 if (b <= -390000000.0) tmp = 1.0; else tmp = Float64(1.0 / Float64(2.0 - a)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -390000000.0) tmp = 1.0; else tmp = 1.0 / (2.0 - a); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -390000000.0], 1.0, N[(1.0 / N[(2.0 - a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -390000000:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 - a}\\
\end{array}
\end{array}
if b < -3.9e8Initial program 100.0%
Taylor expanded in b around 0 18.6%
Taylor expanded in a around 0 18.1%
+-commutative18.1%
Simplified18.1%
Taylor expanded in a around 0 19.1%
Taylor expanded in a around inf 100.0%
if -3.9e8 < b Initial program 99.6%
*-lft-identity99.6%
associate-*l/99.6%
associate-/r/99.5%
remove-double-neg99.5%
unsub-neg99.5%
div-sub66.8%
*-lft-identity66.8%
associate-*l/66.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 75.9%
Taylor expanded in a around 0 43.6%
neg-mul-143.6%
unsub-neg43.6%
Simplified43.6%
(FPCore (a b) :precision binary64 (if (<= b -390000000.0) 1.0 (/ 1.0 (+ b 2.0))))
double code(double a, double b) {
double tmp;
if (b <= -390000000.0) {
tmp = 1.0;
} else {
tmp = 1.0 / (b + 2.0);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= (-390000000.0d0)) then
tmp = 1.0d0
else
tmp = 1.0d0 / (b + 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -390000000.0) {
tmp = 1.0;
} else {
tmp = 1.0 / (b + 2.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -390000000.0: tmp = 1.0 else: tmp = 1.0 / (b + 2.0) return tmp
function code(a, b) tmp = 0.0 if (b <= -390000000.0) tmp = 1.0; else tmp = Float64(1.0 / Float64(b + 2.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -390000000.0) tmp = 1.0; else tmp = 1.0 / (b + 2.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -390000000.0], 1.0, N[(1.0 / N[(b + 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -390000000:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{b + 2}\\
\end{array}
\end{array}
if b < -3.9e8Initial program 100.0%
Taylor expanded in b around 0 18.6%
Taylor expanded in a around 0 18.1%
+-commutative18.1%
Simplified18.1%
Taylor expanded in a around 0 19.1%
Taylor expanded in a around inf 100.0%
if -3.9e8 < b Initial program 99.6%
*-lft-identity99.6%
associate-*l/99.6%
associate-/r/99.5%
remove-double-neg99.5%
unsub-neg99.5%
div-sub66.8%
*-lft-identity66.8%
associate-*l/66.8%
lft-mult-inverse99.5%
sub-neg99.5%
distribute-frac-neg99.5%
remove-double-neg99.5%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 77.1%
Taylor expanded in b around 0 43.6%
+-commutative43.6%
Simplified43.6%
(FPCore (a b) :precision binary64 (if (<= b -1.0) 1.0 (+ 0.5 (* a 0.25))))
double code(double a, double b) {
double tmp;
if (b <= -1.0) {
tmp = 1.0;
} else {
tmp = 0.5 + (a * 0.25);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= (-1.0d0)) then
tmp = 1.0d0
else
tmp = 0.5d0 + (a * 0.25d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -1.0) {
tmp = 1.0;
} else {
tmp = 0.5 + (a * 0.25);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -1.0: tmp = 1.0 else: tmp = 0.5 + (a * 0.25) return tmp
function code(a, b) tmp = 0.0 if (b <= -1.0) tmp = 1.0; else tmp = Float64(0.5 + Float64(a * 0.25)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -1.0) tmp = 1.0; else tmp = 0.5 + (a * 0.25); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -1.0], 1.0, N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\end{array}
\end{array}
if b < -1Initial program 96.8%
Taylor expanded in b around 0 21.2%
Taylor expanded in a around 0 20.8%
+-commutative20.8%
Simplified20.8%
Taylor expanded in a around 0 18.6%
Taylor expanded in a around inf 96.9%
if -1 < 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.1%
*-lft-identity67.1%
associate-*l/67.1%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 75.8%
Taylor expanded in a around 0 42.7%
*-commutative42.7%
Simplified42.7%
(FPCore (a b) :precision binary64 (if (<= b -390000000.0) 1.0 0.5))
double code(double a, double b) {
double tmp;
if (b <= -390000000.0) {
tmp = 1.0;
} else {
tmp = 0.5;
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= (-390000000.0d0)) then
tmp = 1.0d0
else
tmp = 0.5d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -390000000.0) {
tmp = 1.0;
} else {
tmp = 0.5;
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -390000000.0: tmp = 1.0 else: tmp = 0.5 return tmp
function code(a, b) tmp = 0.0 if (b <= -390000000.0) tmp = 1.0; else tmp = 0.5; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -390000000.0) tmp = 1.0; else tmp = 0.5; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -390000000.0], 1.0, 0.5]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -390000000:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if b < -3.9e8Initial program 100.0%
Taylor expanded in b around 0 18.6%
Taylor expanded in a around 0 18.1%
+-commutative18.1%
Simplified18.1%
Taylor expanded in a around 0 19.1%
Taylor expanded in a around inf 100.0%
if -3.9e8 < b Initial program 99.6%
*-lft-identity99.6%
associate-*l/99.6%
associate-/r/99.5%
remove-double-neg99.5%
unsub-neg99.5%
div-sub66.8%
*-lft-identity66.8%
associate-*l/66.8%
lft-mult-inverse99.5%
sub-neg99.5%
distribute-frac-neg99.5%
remove-double-neg99.5%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 77.1%
Taylor expanded in b around 0 42.4%
(FPCore (a b) :precision binary64 0.5)
double code(double a, double b) {
return 0.5;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 0.5d0
end function
public static double code(double a, double b) {
return 0.5;
}
def code(a, b): return 0.5
function code(a, b) return 0.5 end
function tmp = code(a, b) tmp = 0.5; end
code[a_, b_] := 0.5
\begin{array}{l}
\\
0.5
\end{array}
Initial program 99.6%
*-lft-identity99.6%
associate-*l/99.6%
associate-/r/99.6%
remove-double-neg99.6%
unsub-neg99.6%
div-sub70.7%
*-lft-identity70.7%
associate-*l/70.7%
lft-mult-inverse99.6%
sub-neg99.6%
distribute-frac-neg99.6%
remove-double-neg99.6%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 79.8%
Taylor expanded in b around 0 39.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 2024149
(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))))