
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
double code(double a, double b) {
return exp(a) / (exp(a) + exp(b));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = exp(a) / (exp(a) + exp(b))
end function
public static double code(double a, double b) {
return Math.exp(a) / (Math.exp(a) + Math.exp(b));
}
def code(a, b): return math.exp(a) / (math.exp(a) + math.exp(b))
function code(a, b) return Float64(exp(a) / Float64(exp(a) + exp(b))) end
function tmp = code(a, b) tmp = exp(a) / (exp(a) + exp(b)); end
code[a_, b_] := N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{a}}{e^{a} + e^{b}}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
double code(double a, double b) {
return exp(a) / (exp(a) + exp(b));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = exp(a) / (exp(a) + exp(b))
end function
public static double code(double a, double b) {
return Math.exp(a) / (Math.exp(a) + Math.exp(b));
}
def code(a, b): return math.exp(a) / (math.exp(a) + math.exp(b))
function code(a, b) return Float64(exp(a) / Float64(exp(a) + exp(b))) end
function tmp = code(a, b) tmp = exp(a) / (exp(a) + exp(b)); end
code[a_, b_] := N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{a}}{e^{a} + e^{b}}
\end{array}
(FPCore (a b) :precision binary64 (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.8%
*-lft-identity98.8%
associate-*l/98.8%
associate-/r/98.8%
remove-double-neg98.8%
unsub-neg98.8%
div-sub73.4%
*-lft-identity73.4%
associate-*l/73.4%
lft-mult-inverse99.2%
sub-neg99.2%
distribute-frac-neg99.2%
remove-double-neg99.2%
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 (<= a -7.6e-7) (/ 1.0 (+ 1.0 (exp (- a)))) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -7.6e-7) {
tmp = 1.0 / (1.0 + exp(-a));
} else {
tmp = 1.0 / (1.0 + exp(b));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-7.6d-7)) then
tmp = 1.0d0 / (1.0d0 + exp(-a))
else
tmp = 1.0d0 / (1.0d0 + exp(b))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -7.6e-7) {
tmp = 1.0 / (1.0 + Math.exp(-a));
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -7.6e-7: tmp = 1.0 / (1.0 + math.exp(-a)) else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (a <= -7.6e-7) tmp = Float64(1.0 / Float64(1.0 + exp(Float64(-a)))); else tmp = Float64(1.0 / Float64(1.0 + exp(b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -7.6e-7) tmp = 1.0 / (1.0 + exp(-a)); else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -7.6e-7], N[(1.0 / N[(1.0 + N[Exp[(-a)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -7.6 \cdot 10^{-7}:\\
\;\;\;\;\frac{1}{1 + e^{-a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -7.60000000000000029e-7Initial program 97.1%
*-lft-identity97.1%
associate-*l/97.1%
associate-/r/97.1%
remove-double-neg97.1%
unsub-neg97.1%
div-sub4.3%
*-lft-identity4.3%
associate-*l/4.3%
lft-mult-inverse97.1%
sub-neg97.1%
distribute-frac-neg97.1%
remove-double-neg97.1%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 97.4%
if -7.60000000000000029e-7 < a Initial program 99.4%
*-lft-identity99.4%
associate-*l/99.4%
associate-/r/99.4%
remove-double-neg99.4%
unsub-neg99.4%
div-sub99.4%
*-lft-identity99.4%
associate-*l/99.4%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 99.1%
(FPCore (a b) :precision binary64 (if (<= a -1.45e+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 <= -1.45e+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 <= (-1.45d+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 <= -1.45e+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 <= -1.45e+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 <= -1.45e+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 <= -1.45e+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, -1.45e+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 -1.45 \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 < -1.45000000000000007e95Initial program 97.4%
*-lft-identity97.4%
associate-*l/97.4%
associate-/r/97.4%
remove-double-neg97.4%
unsub-neg97.4%
div-sub0.0%
*-lft-identity0.0%
associate-*l/0.0%
lft-mult-inverse97.4%
sub-neg97.4%
distribute-frac-neg97.4%
remove-double-neg97.4%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 95.4%
if -1.45000000000000007e95 < a Initial program 99.0%
*-lft-identity99.0%
associate-*l/99.0%
associate-/r/99.0%
remove-double-neg99.0%
unsub-neg99.0%
div-sub86.6%
*-lft-identity86.6%
associate-*l/86.6%
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 91.5%
Final simplification92.1%
(FPCore (a b)
:precision binary64
(if (<= b -10.5)
(+ 1.0 (exp b))
(if (<= b 6.2e+45)
(/ 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 <= -10.5) {
tmp = 1.0 + exp(b);
} else if (b <= 6.2e+45) {
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 <= (-10.5d0)) then
tmp = 1.0d0 + exp(b)
else if (b <= 6.2d+45) 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 <= -10.5) {
tmp = 1.0 + Math.exp(b);
} else if (b <= 6.2e+45) {
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 <= -10.5: tmp = 1.0 + math.exp(b) elif b <= 6.2e+45: 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 <= -10.5) tmp = Float64(1.0 + exp(b)); elseif (b <= 6.2e+45) 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 <= -10.5) tmp = 1.0 + exp(b); elseif (b <= 6.2e+45) 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, -10.5], N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 6.2e+45], N[(1.0 / N[(2.0 + N[(a * N[(N[(a * N[(0.5 + N[(a * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 + N[(b * N[(1.0 + N[(b * N[(0.5 + N[(b * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -10.5:\\
\;\;\;\;1 + e^{b}\\
\mathbf{elif}\;b \leq 6.2 \cdot 10^{+45}:\\
\;\;\;\;\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 < -10.5Initial program 93.0%
*-lft-identity93.0%
associate-*l/93.0%
associate-/r/93.0%
remove-double-neg93.0%
unsub-neg93.0%
div-sub93.0%
*-lft-identity93.0%
associate-*l/93.0%
lft-mult-inverse95.3%
sub-neg95.3%
distribute-frac-neg95.3%
remove-double-neg95.3%
div-exp100.0%
Simplified100.0%
add-exp-log100.0%
log-rec100.0%
log1p-define100.0%
Applied egg-rr100.0%
Taylor expanded in a around 0 97.7%
log1p-define97.7%
Simplified97.7%
add-sqr-sqrt95.4%
sqrt-unprod96.5%
sqr-neg96.5%
sqrt-unprod96.5%
add-sqr-sqrt96.5%
log1p-undefine96.5%
rem-exp-log96.5%
+-commutative96.5%
Applied egg-rr96.5%
if -10.5 < b < 6.19999999999999975e45Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/99.9%
remove-double-neg99.9%
unsub-neg99.9%
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 95.7%
Taylor expanded in a around 0 81.5%
if 6.19999999999999975e45 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
remove-double-neg100.0%
unsub-neg100.0%
div-sub74.3%
*-lft-identity74.3%
associate-*l/74.3%
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 85.2%
*-commutative85.2%
Simplified85.2%
Final simplification85.0%
(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.8%
*-lft-identity98.8%
associate-*l/98.8%
associate-/r/98.8%
remove-double-neg98.8%
unsub-neg98.8%
div-sub73.4%
*-lft-identity73.4%
associate-*l/73.4%
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 5.5e+45) (/ 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 <= 5.5e+45) {
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 <= 5.5d+45) 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 <= 5.5e+45) {
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 <= 5.5e+45: 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 <= 5.5e+45) 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 <= 5.5e+45) 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, 5.5e+45], 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 5.5 \cdot 10^{+45}:\\
\;\;\;\;\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 < 5.5000000000000001e45Initial program 98.3%
*-lft-identity98.3%
associate-*l/98.3%
associate-/r/98.3%
remove-double-neg98.3%
unsub-neg98.3%
div-sub73.1%
*-lft-identity73.1%
associate-*l/73.1%
lft-mult-inverse98.9%
sub-neg98.9%
distribute-frac-neg98.9%
remove-double-neg98.9%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 78.7%
Taylor expanded in a around 0 67.3%
if 5.5000000000000001e45 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
remove-double-neg100.0%
unsub-neg100.0%
div-sub74.3%
*-lft-identity74.3%
associate-*l/74.3%
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 85.2%
*-commutative85.2%
Simplified85.2%
Final simplification72.2%
(FPCore (a b) :precision binary64 (if (<= b 1.1e+104) (/ 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.1e+104) {
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.1d+104) 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.1e+104) {
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.1e+104: 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.1e+104) 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.1e+104) 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.1e+104], 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.1 \cdot 10^{+104}:\\
\;\;\;\;\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.1e104Initial program 98.4%
*-lft-identity98.4%
associate-*l/98.4%
associate-/r/98.4%
remove-double-neg98.4%
unsub-neg98.4%
div-sub72.7%
*-lft-identity72.7%
associate-*l/72.7%
lft-mult-inverse99.0%
sub-neg99.0%
distribute-frac-neg99.0%
remove-double-neg99.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 76.1%
Taylor expanded in a around 0 63.9%
if 1.1e104 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
remove-double-neg100.0%
unsub-neg100.0%
div-sub75.9%
*-lft-identity75.9%
associate-*l/75.9%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 79.2%
*-commutative79.2%
Simplified79.2%
Final simplification67.4%
(FPCore (a b) :precision binary64 (if (<= b 1.15e+104) (/ 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 <= 1.15e+104) {
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 <= 1.15d+104) 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 <= 1.15e+104) {
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 <= 1.15e+104: 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 <= 1.15e+104) 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 <= 1.15e+104) 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, 1.15e+104], 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 1.15 \cdot 10^{+104}:\\
\;\;\;\;\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 < 1.14999999999999992e104Initial program 98.4%
*-lft-identity98.4%
associate-*l/98.4%
associate-/r/98.4%
remove-double-neg98.4%
unsub-neg98.4%
div-sub72.7%
*-lft-identity72.7%
associate-*l/72.7%
lft-mult-inverse99.0%
sub-neg99.0%
distribute-frac-neg99.0%
remove-double-neg99.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 76.1%
Taylor expanded in a around 0 59.6%
if 1.14999999999999992e104 < b Initial program 100.0%
*-lft-identity100.0%
associate-*l/100.0%
associate-/r/100.0%
remove-double-neg100.0%
unsub-neg100.0%
div-sub75.9%
*-lft-identity75.9%
associate-*l/75.9%
lft-mult-inverse100.0%
sub-neg100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 79.2%
*-commutative79.2%
Simplified79.2%
Final simplification64.0%
(FPCore (a b) :precision binary64 (/ 1.0 (+ 2.0 (* a (+ (* a 0.5) -1.0)))))
double code(double a, double b) {
return 1.0 / (2.0 + (a * ((a * 0.5) + -1.0)));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (2.0d0 + (a * ((a * 0.5d0) + (-1.0d0))))
end function
public static double code(double a, double b) {
return 1.0 / (2.0 + (a * ((a * 0.5) + -1.0)));
}
def code(a, b): return 1.0 / (2.0 + (a * ((a * 0.5) + -1.0)))
function code(a, b) return Float64(1.0 / Float64(2.0 + Float64(a * Float64(Float64(a * 0.5) + -1.0)))) end
function tmp = code(a, b) tmp = 1.0 / (2.0 + (a * ((a * 0.5) + -1.0))); end
code[a_, b_] := N[(1.0 / N[(2.0 + N[(a * N[(N[(a * 0.5), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{2 + a \cdot \left(a \cdot 0.5 + -1\right)}
\end{array}
Initial program 98.8%
*-lft-identity98.8%
associate-*l/98.8%
associate-/r/98.8%
remove-double-neg98.8%
unsub-neg98.8%
div-sub73.4%
*-lft-identity73.4%
associate-*l/73.4%
lft-mult-inverse99.2%
sub-neg99.2%
distribute-frac-neg99.2%
remove-double-neg99.2%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 64.8%
Taylor expanded in a around 0 49.1%
Final simplification49.1%
(FPCore (a b) :precision binary64 (/ 1.0 (- 2.0 a)))
double code(double a, double b) {
return 1.0 / (2.0 - a);
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (2.0d0 - a)
end function
public static double code(double a, double b) {
return 1.0 / (2.0 - a);
}
def code(a, b): return 1.0 / (2.0 - a)
function code(a, b) return Float64(1.0 / Float64(2.0 - a)) end
function tmp = code(a, b) tmp = 1.0 / (2.0 - a); end
code[a_, b_] := N[(1.0 / N[(2.0 - a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{2 - a}
\end{array}
Initial program 98.8%
*-lft-identity98.8%
associate-*l/98.8%
associate-/r/98.8%
remove-double-neg98.8%
unsub-neg98.8%
div-sub73.4%
*-lft-identity73.4%
associate-*l/73.4%
lft-mult-inverse99.2%
sub-neg99.2%
distribute-frac-neg99.2%
remove-double-neg99.2%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 64.8%
Taylor expanded in a around 0 39.2%
neg-mul-139.2%
unsub-neg39.2%
Simplified39.2%
(FPCore (a b) :precision binary64 (+ 0.5 (* a 0.25)))
double code(double a, double b) {
return 0.5 + (a * 0.25);
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 0.5d0 + (a * 0.25d0)
end function
public static double code(double a, double b) {
return 0.5 + (a * 0.25);
}
def code(a, b): return 0.5 + (a * 0.25)
function code(a, b) return Float64(0.5 + Float64(a * 0.25)) end
function tmp = code(a, b) tmp = 0.5 + (a * 0.25); end
code[a_, b_] := N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 + a \cdot 0.25
\end{array}
Initial program 98.8%
*-lft-identity98.8%
associate-*l/98.8%
associate-/r/98.8%
remove-double-neg98.8%
unsub-neg98.8%
div-sub73.4%
*-lft-identity73.4%
associate-*l/73.4%
lft-mult-inverse99.2%
sub-neg99.2%
distribute-frac-neg99.2%
remove-double-neg99.2%
div-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 64.8%
Taylor expanded in a around 0 38.7%
*-commutative38.7%
Simplified38.7%
(FPCore (a b) :precision binary64 0.5)
double code(double a, double b) {
return 0.5;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 0.5d0
end function
public static double code(double a, double b) {
return 0.5;
}
def code(a, b): return 0.5
function code(a, b) return 0.5 end
function tmp = code(a, b) tmp = 0.5; end
code[a_, b_] := 0.5
\begin{array}{l}
\\
0.5
\end{array}
Initial program 98.8%
*-lft-identity98.8%
associate-*l/98.8%
associate-/r/98.8%
remove-double-neg98.8%
unsub-neg98.8%
div-sub73.4%
*-lft-identity73.4%
associate-*l/73.4%
lft-mult-inverse99.2%
sub-neg99.2%
distribute-frac-neg99.2%
remove-double-neg99.2%
div-exp100.0%
Simplified100.0%
Taylor expanded in a around 0 81.8%
Taylor expanded in b around 0 38.5%
(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 2024106
(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))))