teamnote default

This commit is contained in:
2026-06-03 09:20:51 +09:00
commit f50ed902fe
65 changed files with 6033 additions and 0 deletions

13
source/Math/CRT.cpp Normal file
View File

@@ -0,0 +1,13 @@
pll crt(pll p, pll q) {
if(p.fi > q.fi) swap(p, q);
auto [a, A] = p;
auto [b, B] = q;
ll g = gcd(A, B);
if((b-a)%g != 0) return {-1, -1};
ll i = A, j = B, k = b-a;
i/=g; j/=g; k/=g;
auto [x, y] = diophantos(i, j);
return {(ll)((a+(lll)A*k*x)%(A*B/g)), A*B/g};
}

View File

@@ -0,0 +1,12 @@
pll diophantos(ll a, ll b) {
assert(a>0 and b>=0);
if(b == 0) return {1, 0};
auto [y, x] = diophantos(b, a%b); y = y-(a/b)*x;
if(x < 0 or x >= b) {
ll t = x/b;
if(x%b < 0) t--;
x -= b*t; y += a*t;
}
return {x, y};
}

61
source/Math/FFTConv.cpp Normal file
View File

@@ -0,0 +1,61 @@
using cpx = complex<double>;
using vcpx = vector<cpx>;
void fft(vcpx &a, bool inv = false) {
int n = a.size(), j = 0; assert((n&-n) == n);
for(int i=1; i<n; i++) {
int bit = (n >> 1);
while(j >= bit) {
j -= bit; bit >>= 1;
}
j += bit; if(i < j) swap(a[i], a[j]);
}
vcpx roots(n/2);
prec c = 2 * pi * (inv ? -1 : 1);
for(int i=0; i<n/2; i++)
roots[i] = cpx(cosl(c * i / n), sinl(c * i / n));
for(int i=2, step = n/i; i<=n; i<<=1, step = n/i)
for(int j=0; j<n; j+=i) for(int k=0; k<i/2; k++) {
cpx u = a[j+k], v = a[j+k+i/2]*roots[step*k];
a[j+k] = u+v;
a[j+k+i/2] = u-v;
}
if(inv) for(int i=0; i<n; i++) a[i] /= n;
}
ll mod = 1e9+7;
vl conv(const vl& AA,const vl& BB) {
const ll G = 1<<15;
int n = AA.size()+BB.size()-1;
int m = 1; while(m < n) m<<=1;
int a = AA.size(), b = BB.size();
vcpx A(m), B(m), C(m), D(m);
fors(i, 0, a-1) A[i] = cpx(AA[i]/G, AA[i]%G);
fors(i, 0, b-1) B[i] = cpx(BB[i]/G, BB[i]%G);
fft(A); fft(B);
fors(i, 0, m-1) {
int j = i?m-i:0;
cpx A1 = (A[i]+conj(A[j]))*cpx(0.5, 0);
cpx A2 = (A[i]-conj(A[j]))*cpx(0, -0.5);
cpx B1 = (B[i]+conj(B[j]))*cpx(0.5, 0);
cpx B2 = (B[i]-conj(B[j]))*cpx(0, -0.5);
C[i] = A1*B1 + A2*B2*cpx(0, 1);
D[i] = A2*B1 + A1*B2*cpx(0, 1);
}
fft(C, true); fft(D, true);
vl ret(m); ll G1 = G%mod, G2 = (lll)G*G%mod;
fors(i, 0, m-1) {
ll p = ll(C[i].real()+0.5);
ll q = ll(D[i].real()+0.5) + ll(D[i].imag()+0.5);
ll r = ll(C[i].imag()+0.5);
p %= mod; q %= mod; r %= mod;
ret[i] = (((lll)p*G2)%mod+((lll)q*G1)%mod+r%mod)%mod;
}
ret.resize(n);
return ret;
}

7
source/Math/FloorSum.cpp Normal file
View File

@@ -0,0 +1,7 @@
ll floor_sum(ll a, ll b, ll c, ll n)
{
if(a == 0) return b/c*n;
if(a>=c or b>=c) return n*(n-1)/2 * (a/c) + n * (b/c) + floor_sum(a%c, b%c, c, n);
ll m = (a*(n-1)+b)/c;
return m*n - floor_sum(c, c-b+a-1, a, m);
}

12
source/Math/Harmonic.cpp Normal file
View File

@@ -0,0 +1,12 @@
ll harmonic(ll n) {
ll ans = 0;
for(ll i = 1; i <= n; i = n/(n/i)+ 1) {
//for j \in [i, n/(n/i)] : n/j == n/i
ans += n/i * (n/(n/i) - i + 1);
// \sum_{i=1}^n {f(n/i)}
// ans += f(n/i) * (n/(n/i) - i + 1)
}
return ans;
}

View File

@@ -0,0 +1,26 @@
ll pow(ll a, ll b, ll mod) {
ll ret = 1;
for(int st=0; (1LL<<st) <= b; st++) {
if((1LL<<st) & b) ret=(lll)ret*a%mod;
a=(lll)a*a%mod;
}
return ret;
}
bool miller(ll n, ll a) {
if(n == a) return true;
ll x = n-1;
if(pow(a, x, n) != 1) return false;
while(x%2==0) {
x/=2;
ll t = pow(a, x, n);
if(t!=1 and t!=n-1) return false;
if(t==n-1) return true;
}
return true;
}
bool is_p(ll n) {
if(n<=2) return n==2;
vi D = {2, 3, 5, 7, 11, 13, 17, 23, 29, 31, 37};
for(auto i:D) if(!miller(n, i)) return false;
return true;
}

81
source/Math/NTT.cpp Normal file
View File

@@ -0,0 +1,81 @@
namespace GMS {
template<ll mod>
ll pow(ll a, ll b) {
a %= mod;
ll ret = 1;
while(b != 0) {
if(b&1) ret = ret*a%mod;
a = a*a%mod; b>>=1;
}
return ret;
}
template<ll mod, ll w>
void ntt(vector<ll> &a, bool inv = false) {
static_assert(mod <= (ll)2e9, "mod should be less than 2e9");
int n = a.size(), j = 0;
assert((n & -n) == n && (mod-1)%n == 0);
for(int i=1; i<n; i++) {
int bit = (n >> 1);
while(j >= bit) {
j -= bit;
bit >>= 1;
}
j += bit;
if(i < j) swap(a[i], a[j]);
}
static vector<ll> root[30], iroot[30];
for(int st=1; (1<<st) <= n; st++) {
if(root[st].empty()) {
ll t = pow<mod>(w, (mod-1)/(1<<st));
root[st].pb(1);
for(int i=1; i<(1<<(st-1)); i++)
root[st].pb(root[st].back()*t%mod);
}
if(iroot[st].empty()) {
ll t = pow<mod>(w, (mod-1)/(1<<st));
t = pow<mod>(t, mod-2);
iroot[st].pb(1);
for(int i=1; i<(1<<(st-1)); i++)
iroot[st].pb(iroot[st].back()*t%mod);
}
}
vector<ll>* r = (inv?root:iroot);
for(int st = 1; (1<<st) <= n; st++) {
int i = 1<<st; //int step = n / i;
for(int j=0; j<n; j+=i) {
for(int k=0; k<i/2; k++) {
ll u = a[j+k], v = a[j+k+i/2] * r[st][k]%mod;
a[j+k] = (u+v)%mod;
a[j+k+i/2] = (mod+u-v)%mod;
}
}
}
if(inv) {
ll in = pow<mod>(n, mod-2);
for(int i=0; i<n; i++) a[i] = a[i]*in%mod;
}
}
template<ll mod, ll w>
vl conv(vl A, vl B) {
int n = A.size(), m = B.size();
int t = 1; while(t < n+m-1) t*=2;
A.resize(t); B.resize(t);
ntt<mod, w>(A); ntt<mod, w>(B);
fors(i, 0, t-1) A[i] = A[i]*B[i]%mod;
ntt<mod, w>(A, true);
A.resize(n+m-1);
return A;
}
} // namespace GMS

22
source/Math/PolladRho.cpp Normal file
View File

@@ -0,0 +1,22 @@
void fact(ll n, vl& ret) {
if(n == 1) return;
else if(n%2 == 0) ret.pb(2), fact(n/2, ret);
else if(is_p(n)) ret.pb(n);
else {
ll a, b, c, g = n;
auto f = [&c, &n](ll x)->ll{return (c+(lll)x*x)%n;};
do {
if(g == n) a=b=rand()%(n-2)+2, c=rand()%20+1;
a=f(a); b=f(f(b));
g = gcd(a-b, n);
} while(g == 1);
fact(g, ret); fact(n/g, ret);
}
}
vl po_rho(ll n) {
vl ret;
fact(n, ret);
sort(all(ret));
return ret;
}

149
source/Math/Polynomial.cpp Normal file
View File

@@ -0,0 +1,149 @@
namespace GMS {
template<ll mod, ll w>
struct Qring : public vl {
using poly = Qring<mod, w>;
Qring() : vl(1, 0) {}
Qring(ll c) : vl(1, c%mod) {}
Qring(ll c, int n) : vl(n, c%mod) {}
Qring(const vl& cp) : vl(cp) {for(auto &i:*this) i%=mod;}
ll& operator[](ll idx) {
if((unsigned)idx < size()) return vl::operator[](idx);
this->resize(idx+1); return vl::operator[](idx);
}
ll operator[](ll idx) const {
if((unsigned)idx < size()) return vl::operator[](idx);
return 0LL;
}
void adjust() { while(size() > 1 and back() == 0) pop_back(); }
void adjust(int n){resize(n, 0);}
ll operator()(ll x) {
x %= mod; ll ret = 0;
for(auto it=rbegin(); it!=rend(); it++)
ret = (ret*x+*it)%mod;
return ret;
}
friend poly operator%(const poly& A, int B){ // remainder by x^B
poly ret(A); ret.resize(B, 0);
return ret;
}
friend poly operator+(const poly& A, const poly& B) {
int n = max(A.size(), B.size()); poly ret(0, n);
fors(i, 0, n-1) ret[i] = A[i]+B[i];
for(auto&i:ret) if(i >= mod) i -= mod;
return ret.adjust(), ret;
}
friend poly operator-(const poly& A) {
int n = A.size(); poly ret(0, n);
fors(i, 0, n-1) ret[i] = A[i]?mod-A[i]:0;
return ret;
}
friend poly operator-(const poly& A, const poly& B) {
int n = max(A.size(), B.size());
poly ret(0, n);
fors(i, 0, n-1) ret[i] = (mod+A[i]-B[i])%mod;
return ret.adjust(), ret;
}
friend poly operator*(ll x, const poly& B) {
poly ret(B); x %= mod;
for(auto &i : ret) i = (i*x)%mod;
return ret.adjust(), ret;
}
friend poly operator*(const poly& A, const poly& B) {
poly ret = conv<mod, w>(A, B);
// ACL : poly ret = atcoder::convolution<mod>(A, B);
return ret.adjust(), ret;
}
friend poly inv(const poly& A, int t) { assert(A[0] != 0);
poly g = pow<mod>(A[0], mod-2); int st=1;
while(st < t){st*=2; g = (-A%st*g%st+2)*g%st;}
return g.adjust(t), g;
}
friend poly diff(const poly& A) {
int n = A.size(); poly ret(0, n-1);
fors(i, 0, n-2) ret[i] = (i+1)*A[i+1]%mod;
return ret;
}
friend poly inte(const poly& A) {
static vector<ll> inv(1, 1);
int n = A.size(); poly ret(0, n+1);
inv.resize(max((int)inv.size(), n+1));
forr(i, n) if(inv[i] == 0) inv[i] = pow<mod>(i, mod-2);
forr(i, n) ret[i] = inv[i]*A[i-1]%mod;
return ret;
}
friend poly log(const poly& A, int t) { assert(A[0] == 1);
return inte(diff(A) * inv(A, t)%t)%t;
}
friend poly exp(const poly& A, int t) { assert(A[0] == 0);
poly g = 1; int st = 1;
while(st < t) {st*=2; g = (A%st-log(g, st)+1)*g%st;}
return g.adjust(), g;
}
friend poly pow(const poly& A, ll b, ll t) {
poly ret(A); ret.adjust();
if(ret.size() == 1) {
ret[0] = pow<mod>(ret[0], b);
return ret.adjust(t), ret;
}
ll idx = 0; while(ret[idx] == 0) idx++;
if((__int128_t) idx * b >= t) return poly(0, t);
ll c = ret[idx]; ll ic = pow<mod>(ret[idx], mod-2); poly g;
int n = ret.size();
fors(i, idx, n-1) g[i-idx] = ret[i]*ic%mod;
g.resize(t-idx*b);
g = exp(b * log(g, t-idx*b), t-idx*b);
c = pow<mod>(c, b);
ret = poly(0, t); fors(i, idx*b, t-1) ret[i] = g[i-idx*b] * c % mod;
return ret;
}
//Only just Polynomial, not Qring
void rev() { reverse(begin(), end()); }
friend poly div_quot(poly F, poly G) {
F.adjust(); G.adjust();
ll df = F.size(), dg = G.size();
if(df < dg) return poly(0);
F.rev(); G.rev();
F = F%(df-dg+1)*inv(G, df-dg+1)%(df-dg+1); F.rev();
return F;
}
friend poly div_rem(poly F, poly G) {return F-G*div_quot(F, G);}
friend poly shift(const poly& F, ll c) {
ll n = F.size(); c %= mod;
poly A(0, n); ll fac = 1;
fors(i, 0, n-1) A[i] = F[i]*fac%mod, fac = fac*(i+1)%mod;
A.rev();
poly C(1, n); fors(i, 1, n-1) C[i] = C[i-1]*c%mod;
ll facc = fac = pow<mod>(fac, mod-2)*n%mod;
fore(i, n-1, 0) C[i] = C[i]*fac%mod, fac = fac*i%mod;
poly B = C*A; B.resize(n); B.rev();
fore(i, n-1, 0) B[i] = B[i]*facc%mod, facc = facc*i%mod;
return B;
}
friend void calcG(vector<poly>& G, int i, int l, int r, const vl& p) {
if(l == r){ll g = p[l]?mod-p[l]:0; G[i] = vl({g, 1}); return;}
int mid = (l+r)/2;
calcG(G, i*2, l, mid, p); calcG(G, i*2+1, mid+1, r, p);
G[i] = G[i*2]*G[i*2+1];
}
friend void eval(const vector<poly>& G, int i, int l, int r, poly&& F, vl& ret) {
if(l == r){ret[l] = F[0];return;}
int mid=(l+r)/2;
eval(G, i*2, l, mid, div_rem(F, G[i*2]), ret);
eval(G, i*2+1, mid+1, r, div_rem(F, G[i*2+1]), ret);
}
friend vl multipoint_eval(const poly& A, const vl& B) {
int m = B.size();
vector<poly> G(4*m); calcG(G, 1, 0, m-1, B);
vl ret(m, 0); eval(G, 1, 0, m-1, div_rem(A, G[1]), ret);
return ret;
}
};
} // namespace GMS

View File

@@ -0,0 +1,23 @@
ll primary_root(ll p) {
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<ll> distrib(1, p-1);
//distrib(gen);
vl g = po_rho(p-1);
while(true) {
ll c = distrib(gen);
bool ok = true; ll u = p-1;
ll b = 1;
for(auto i:g) {
if(i != b) u = p-1;
ll x = pow(c, u/i, p);
if(x == 1) ok = false;
u /= i; b = i;
}
if(ok) return c;
}
}

View File

@@ -0,0 +1,56 @@
vector<ll> euler(1000003, -1), primes;
//Generate primes and also calculate the euler number
void genprime() {
for(ll i = 2;i<=1000002;i++) {
if(euler[i]==-1) {
primes.push_back(i);
euler[i] = i-1;
for(ll j = 2*i; j<=1000002; j+=i) {
if(euler[j]==-1)euler[j] = j;
euler[j] = (euler[j]/i)*(i-1);
}
}
}
}
//Calculates x raised to the power of p % m
ll powll(ll x, ll p, ll m = 1ll<<62)
// Mod inverse
ll inverse(ll x, ll m)
//finds (n!)_p
ll ff(ll n, ll p, ll q)
{
ll x = 1, y = powll(p, q);
for(ll i = 2; i<=n;i++) if(i%p)
x = (x*i)%y;
return x%y;
}
//Generalized Lucas Theorem calculates nCm mod p^q
ll lucas_pow_comb(ll n, ll m, ll p, ll q) {
ll r = n-m, x = powll(p, q);
ll e0 = 0, eq = 0;
ll mul = (p==2&&q>=3)? 1: -1;
ll cr = r, cm = m, carry = 0, cnt = 0;
while(cr||cm||carry) {
cnt++;
int rr = cr%p, rm = cm%p;
if(rr + rm + carry >= p) {
e0++;
if(cnt>=q)eq++;
}
carry = (carry+rr+rm)/p;
cr/=p; cm/=p;
}
mul = powll(p, e0)*powll(mul, eq);
ll ret = (mul % x + x) % x;
ll temp = 1;
for(ll i = 0;;i++)//This is THE line that calculates the formula {
ret = ((ret*ff((n/temp)%x, p, q)%x)%x*(inverse(ff((m/temp)%x, p, q), x)%x*inverse(ff((r/temp)%x, p, q), x)%x)%x)%x;
if(temp>n/p && temp>m/p && temp>r/p)
break;
temp = temp*p;
}
return (ret%x+x)%x;
}

167
source/Math/math.tex Normal file
View File

@@ -0,0 +1,167 @@
% Written by Anders Sjoqvist and Ulf Lundstrom, 2009
% The main sources are: tinyKACTL, Beta and Wikipedia
\subsection{Equations}
\[ax^2+bx+c=0 \Rightarrow x = \frac{-b\pm\sqrt{b^2-4ac}}{2a}\]
The extremum is given by $x = -b/2a$.
\[\begin{aligned}ax+by=e\\cx+dy=f\end{aligned}
\Rightarrow
\begin{aligned}x=\dfrac{ed-bf}{ad-bc}\\y=\dfrac{af-ec}{ad-bc}\end{aligned}\]
In general, given an equation $Ax = b$, the solution to a variable $x_i$ is given by
\[x_i = \frac{\det A_i'}{\det A} \]
where $A_i'$ is $A$ with the $i$'th column replaced by $b$.
\subsection{Inequality}
For positive $a$, $b$, $c$, $d$ with $\frac{a}{b} < \frac{c}{d}$, $\frac{a}{b} < \frac{a+c}{b+d} < \frac{c}{d}$ hold.
Also, for positive $a$, $b$, $c$, $d$, $\min(\frac{a}{b}, \frac{c}{d}) \leqslant \frac{a+c}{b+d} \leqslant max(\frac{a}{b}, \frac{c}{d})$.
e.g., for two sets of disjoint vertices $A$, $B$ of $G$,
\begin{align*}
\min \left( \frac{E(G[A])}{V(G[A])}, \frac{E(G[B])}{V(G[B])} \right) & \leqslant
\frac{E(G[A\cup B])}{V(G[A\cup B])} = \frac{E(G[A]) + E(G[B])}{V(G[A]) + V(G[B])} \\&
\leqslant \max \left( \frac{E(G[A])}{V(G[A])}, \frac{E(G[B])}{V(G[B])} \right)
\end{align*}
(therefore, the average degree of the disjoint set is larger when we divide them.)
\subsection{Recurrences}
If $a_n = c_1 a_{n-1} + \dots + c_k a_{n-k}$, and $r_1, \dots, r_k$ are distinct roots of $x^k - c_1 x^{k-1} - \dots - c_k$, there are $d_1, \dots, d_k$ s.t.
\[a_n = d_1r_1^n + \dots + d_kr_k^n. \]
Non-distinct roots $r$ become polynomial factors, e.g. $a_n = (d_1n + d_2)r^n$.
% \subsection{Trigonometry}
% \begin{align*}
% \sin(v+w)&{}=\sin v\cos w+\cos v\sin w\\
% \cos(v+w)&{}=\cos v\cos w-\sin v\sin w\\
% \tan(v+w)&{}=\dfrac{\tan v+\tan w}{1-\tan v\tan w}\\
% \sin v+\sin w&{}=2\sin\dfrac{v+w}{2}\cos\dfrac{v-w}{2}\\
% \cos v+\cos w&{}=2\cos\dfrac{v+w}{2}\cos\dfrac{v-w}{2}\\
% (V+W)\tan(v-w)/2&{}=(V-W)\tan(v+w)/2
% \end{align*}
% where $V, W$ are lengths of sides opposite angles $v, w$.
% \begin{align*}
% a\cos x+b\sin x&=r\cos(x-\phi)\\
% a\sin x+b\cos x&=r\sin(x+\phi)
% \end{align*}
% where $r=\sqrt{a^2+b^2}, \phi=\operatorname{atan2}(b,a)$.
\subsection{Geometry}
\subsubsection{Triangles}
Side lengths: $a,b,c$
Semiperimeter: $p=\dfrac{a+b+c}{2}$
Area: $A=\sqrt{p(p-a)(p-b)(p-c)}$
Circumradius: $R=\dfrac{abc}{4A}$
Inradius: $r=\dfrac{A}{p}$
Length of the median (divides the triangle into two equal area triangles): $m_a=\tfrac{1}{2}\sqrt{2b^2+2c^2-a^2}$
Length of the bisector (divides angles into two): $s_a=\sqrt{bc\left[1-\left(\dfrac{a}{b+c}\right)^2\right]}$
Law of sines: $\dfrac{\sin\alpha}{a}=\dfrac{\sin\beta}{b}=\dfrac{\sin\gamma}{c}=\dfrac{1}{2R}$
Law of cosines: $a^2=b^2+c^2-2bc\cos\alpha$
Law of tangents: $\dfrac{a+b}{a-b}=\dfrac{\tan\dfrac{\alpha+\beta}{2}}{\tan\dfrac{\alpha-\beta}{2}}$
\subsubsection{Quadrilaterals}
With side lengths $a,b,c,d$, diagonals $e, f$, diagonals angle $\theta$, area $A$ and
magic flux $F=b^2+d^2-a^2-c^2$:
\[ 4A = 2ef \cdot \sin\theta = F\tan\theta = \sqrt{4e^2f^2-F^2} \]
For cyclic quadrilaterals the sum of opposite angles is $180^\circ$,
$ef = ac + bd$, and $A = \sqrt{(p-a)(p-b)(p-c)(p-d)}$.
% \subsubsection{Spherical coordinates}
% \begin{center}
% \includegraphics[width=25mm]{source/Math/sphericalCoordinates.pdf}
% \end{center}
% \[\begin{array}{cc}
% x = r\sin\theta\cos\phi & r = \sqrt{x^2+y^2+z^2}\\
% y = r\sin\theta\sin\phi & \theta = \textrm{acos}(z/\sqrt{x^2+y^2+z^2})\\
% z = r\cos\theta & \phi = \textrm{atan2}(y,x)
% \end{array}\]
\subsection{Derivatives/Integrals}
\begin{align*}
\dfrac{d}{dx}\arcsin x = \dfrac{1}{\sqrt{1-x^2}} &&& \dfrac{d}{dx}\arccos x = -\dfrac{1}{\sqrt{1-x^2}} \\
\dfrac{d}{dx}\tan x = 1+\tan^2 x &&& \dfrac{d}{dx}\arctan x = \dfrac{1}{1+x^2} \\
\int\tan ax = -\dfrac{\ln|\cos ax|}{a} &&& \int x\sin ax = \dfrac{\sin ax-ax \cos ax}{a^2} \\
\int e^{-x^2} = \frac{\sqrt \pi}{2} \text{erf}(x) &&& \int xe^{ax}dx = \frac{e^{ax}}{a^2}(ax-1)
\end{align*}
Integration by parts:
\[\int_a^bf(x)g(x)dx = [F(x)g(x)]_a^b-\int_a^bF(x)g'(x)dx\]
\subsection{Sums}
\[ c^a + c^{a+1} + \dots + c^{b} = \frac{c^{b+1} - c^a}{c-1}, c \neq 1 \]
\begin{align*}
1 + 2 + 3 + \dots + n &= \frac{n(n+1)}{2} \\
1^2 + 2^2 + 3^2 + \dots + n^2 &= \frac{n(2n+1)(n+1)}{6} \\
1^3 + 2^3 + 3^3 + \dots + n^3 &= \frac{n^2(n+1)^2}{4} \\
1^4 + 2^4 + 3^4 + \dots + n^4 &= \frac{n(n+1)(2n+1)(3n^2 + 3n - 1)}{30} \\
\end{align*}
\subsection{Series}
$$e^x = 1+x+\frac{x^2}{2!}+\frac{x^3}{3!}+\dots,\,(-\infty<x<\infty)$$
$$\ln(1+x) = x-\frac{x^2}{2}+\frac{x^3}{3}-\frac{x^4}{4}+\dots,\,(-1<x\leq1)$$
$$\sqrt{1+x} = 1+\frac{x}{2}-\frac{x^2}{8}+\frac{2x^3}{32}-\frac{5x^4}{128}+\dots,\,(-1\leq x\leq1)$$
$$\sin x = x-\frac{x^3}{3!}+\frac{x^5}{5!}-\frac{x^7}{7!}+\dots,\,(-\infty<x<\infty)$$
$$\cos x = 1-\frac{x^2}{2!}+\frac{x^4}{4!}-\frac{x^6}{6!}+\dots,\,(-\infty<x<\infty)$$
\subsection{Probability theory}
Let $X$ be a discrete random variable with probability $p_X(x)$ of assuming the value $x$. It will then have an expected value (mean) $\mu=\mathbb{E}(X)=\sum_xxp_X(x)$ and variance $\sigma^2=V(X)=\mathbb{E}(X^2)-(\mathbb{E}(X))^2=\sum_x(x-\mathbb{E}(X))^2p_X(x)$ where $\sigma$ is the standard deviation. If $X$ is instead continuous it will have a probability density function $f_X(x)$ and the sums above will instead be integrals with $p_X(x)$ replaced by $f_X(x)$.
Expectation is linear:
\[\mathbb{E}(aX+bY) = a\mathbb{E}(X)+b\mathbb{E}(Y)\]
For independent $X$ and $Y$, \[V(aX+bY) = a^2V(X)+b^2V(Y).\]
\subsubsection{Binomial distribution}
The number of successes in $n$ independent yes/no experiments, each which yields success with probability $p$ is $\textrm{Bin}(n,p),\,n=1,2,\dots,\, 0\leq p\leq1$.
\[p(k)=\binom{n}{k}p^k(1-p)^{n-k}\]
\[\mu = np,\,\sigma^2=np(1-p)\]
$\textrm{Bin}(n,p)$ is approximately $\textrm{Po}(np)$ for small $p$.
\subsubsection{First success distribution}
The number of trials needed to get the first success in independent yes/no experiments, each which yields success with probability $p$ is $\textrm{Fs}(p),\,0\leq p\leq1$.
\[p(k)=p(1-p)^{k-1},\,k=1,2,\dots\]
\[\mu = \frac1p,\,\sigma^2=\frac{1-p}{p^2}\]
\subsubsection{Poisson distribution}
The number of events occurring in a fixed period of time $t$ if these events occur with a known average rate $\kappa$ and independently of the time since the last event is $\textrm{Po}(\lambda),\,\lambda=t\kappa$.
\[p(k)=e^{-\lambda}\frac{\lambda^k}{k!}, k=0,1,2,\dots\]
\[\mu=\lambda,\,\sigma^2=\lambda\]
% \subsubsection{Uniform distribution}
% If the probability density function is constant between $a$ and $b$ and 0 elsewhere it is $\textrm{U}(a,b),\,a<b$.
% \[f(x) = \left\{
% \begin{array}{cl}
% \frac{1}{b-a} & a<x<b\\
% 0 & \textrm{otherwise}
% \end{array}\right.\]
% \[\mu=\frac{a+b}{2},\,\sigma^2=\frac{(b-a)^2}{12}\]
\subsubsection{Exponential distribution}
The time between events in a Poisson process is $\textrm{Exp}(\lambda),\,\lambda>0$.
\[f(x) = \left\{
\begin{array}{cl}
\lambda e^{-\lambda x} & x\geq0\\
0 & x<0
\end{array}\right.\]
\[\mu=\frac{1}{\lambda},\,\sigma^2=\frac{1}{\lambda^2}\]
% \subsubsection{Normal distribution}
% Most real random values with mean $\mu$ and variance $\sigma^2$ are well described by $\mathcal{N}(\mu,\sigma^2),\,\sigma>0$.
% \[ f(x) = \frac{1}{\sqrt{2\pi\sigma^2}}e^{-\frac{(x-\mu)^2}{2\sigma^2}} \]
% If $X_1 \sim \mathcal{N}(\mu_1,\sigma_1^2)$ and $X_2 \sim \mathcal{N}(\mu_2,\sigma_2^2)$ then
% \[ aX_1 + bX_2 + c \sim \mathcal{N}(\mu_1+\mu_2+c,a^2\sigma_1^2+b^2\sigma_2^2) \]

File diff suppressed because it is too large Load Diff